feat: Add AI Error Debugging using OpenAI (#8805)
This commit is contained in:
55
packages/editor-ui/src/stores/ai.store.spec.ts
Normal file
55
packages/editor-ui/src/stores/ai.store.spec.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import { useAIStore } from '@/stores/ai.store';
|
||||
import * as aiApi from '@/api/ai';
|
||||
|
||||
vi.mock('@/api/ai', () => ({
|
||||
debugError: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/stores/n8nRoot.store', () => ({
|
||||
useRootStore: () => ({
|
||||
getRestApiContext: {
|
||||
/* Mocked context */
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@/stores/settings.store', () => ({
|
||||
useSettingsStore: () => ({
|
||||
settings: {
|
||||
ai: {
|
||||
errorDebugging: false, // Default mock value
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('useAIStore', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
describe('isErrorDebuggingEnabled', () => {
|
||||
it('reflects error debugging setting from settingsStore', () => {
|
||||
const aiStore = useAIStore();
|
||||
expect(aiStore.isErrorDebuggingEnabled).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('debugError()', () => {
|
||||
it('calls aiApi.debugError with correct parameters and returns expected result', async () => {
|
||||
const mockResult = { message: 'This is an example' };
|
||||
const aiStore = useAIStore();
|
||||
const payload = {
|
||||
error: new Error('Test error'),
|
||||
};
|
||||
|
||||
vi.mocked(aiApi.debugError).mockResolvedValue(mockResult);
|
||||
|
||||
const result = await aiStore.debugError(payload);
|
||||
|
||||
expect(aiApi.debugError).toHaveBeenCalledWith({}, payload);
|
||||
expect(result).toEqual(mockResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
19
packages/editor-ui/src/stores/ai.store.ts
Normal file
19
packages/editor-ui/src/stores/ai.store.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import * as aiApi from '@/api/ai';
|
||||
import type { DebugErrorPayload } from '@/api/ai';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export const useAIStore = defineStore('ai', () => {
|
||||
const rootStore = useRootStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
const isErrorDebuggingEnabled = computed(() => settingsStore.settings.ai.errorDebugging);
|
||||
|
||||
async function debugError(payload: DebugErrorPayload) {
|
||||
return await aiApi.debugError(rootStore.getRestApiContext, payload);
|
||||
}
|
||||
|
||||
return { isErrorDebuggingEnabled, debugError };
|
||||
});
|
||||
Reference in New Issue
Block a user