feat: Add AI Error Debugging using OpenAI (#8805)

This commit is contained in:
Alex Grozav
2024-03-13 16:48:00 +02:00
committed by GitHub
parent e3dd353ea7
commit 948c383999
26 changed files with 1838 additions and 362 deletions

View 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);
});
});
});

View 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 };
});