Refresh AI model setup (#13171)

Instead of initializing model at start time we do it at run time to be
able to swap model provider more easily.

Also introduce a third driver for openai-compatible providers, which
among other allows for local models with Ollama
This commit is contained in:
Félix Malfait
2025-07-11 13:09:54 +02:00
committed by GitHub
parent fd13bb0258
commit 0a93468b95
32 changed files with 566 additions and 417 deletions

View File

@ -1,3 +1,4 @@
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { useRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentStateV2';
import { useState } from 'react';
import { useRecoilState } from 'recoil';
@ -22,6 +23,7 @@ interface OptimisticMessage extends AgentChatMessage {
export const useAgentChat = (agentId: string) => {
const apolloClient = useApolloClient();
const { enqueueErrorSnackBar } = useSnackBar();
const [agentChatMessages, setAgentChatMessages] = useRecoilComponentStateV2(
agentChatMessagesComponentState,
@ -112,6 +114,11 @@ export const useAgentChat = (agentId: string) => {
}));
scrollToBottom();
},
onError: (message: string) => {
enqueueErrorSnackBar({
message,
});
},
});
},
},

View File

@ -1,12 +1,13 @@
export type AgentStreamingEvent = {
type: 'text-delta' | 'tool-call';
type: 'text-delta' | 'tool-call' | 'error';
message: string;
};
export type AgentStreamingParserCallbacks = {
onTextDelta?: (message: string) => void;
onToolCall?: (message: string) => void;
onError?: (error: Error, rawLine: string) => void;
onError?: (message: string) => void;
onParseError?: (error: Error, rawLine: string) => void;
};
export const parseAgentStreamingChunk = (
@ -27,6 +28,9 @@ export const parseAgentStreamingChunk = (
case 'tool-call':
callbacks.onToolCall?.(event.message);
break;
case 'error':
callbacks.onError?.(event.message);
break;
}
} catch (error) {
// eslint-disable-next-line no-console
@ -36,7 +40,7 @@ export const parseAgentStreamingChunk = (
error instanceof Error
? error
: new Error(`Unknown parsing error: ${String(error)}`);
callbacks.onError?.(errorMessage, line);
callbacks.onParseError?.(errorMessage, line);
}
}
}