Add createStreamFn for CORS proxy support

- createStreamFn(proxyUrl?) returns a sync streamFn that applies proxy
- Example reads proxy settings once when creating Agent
- Matches old ProviderTransport behavior
This commit is contained in:
Mario Zechner 2025-12-28 11:37:42 +01:00
parent e49e787322
commit e0be2e650d
3 changed files with 28 additions and 1 deletions

View file

@ -8,6 +8,7 @@ import {
ChatPanel,
CustomProvidersStore,
createJavaScriptReplTool,
createStreamFn,
IndexedDBStorageBackend,
// PersistentStorageDialog, // TODO: Fix - currently broken
ProviderKeysStore,
@ -160,6 +161,10 @@ const createAgent = async (initialState?: Partial<AgentState>) => {
agentUnsubscribe();
}
// Read proxy settings for streamFn
const proxyEnabled = await storage.settings.get<boolean>("proxy.enabled");
const proxyUrl = proxyEnabled ? (await storage.settings.get<string>("proxy.url")) || undefined : undefined;
agent = new Agent({
initialState: initialState || {
systemPrompt: `You are a helpful AI assistant with access to various tools.
@ -181,6 +186,8 @@ Feel free to use these tools when needed to provide accurate and helpful respons
const key = await storage.providerKeys.get(provider);
return key ?? undefined;
},
// Use streamFn with CORS proxy support
streamFn: createStreamFn(proxyUrl),
});
agentUnsubscribe = agent.subscribe((event: any) => {