mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 15:02:32 +00:00
Allow async streamFn for dynamic proxy settings
- StreamFn type now allows returning Promise - agent-loop awaits streamFn result - createStreamFn takes getProxyUrl callback, reads settings on each call
This commit is contained in:
parent
e0be2e650d
commit
92898f486b
4 changed files with 16 additions and 11 deletions
|
|
@ -114,13 +114,16 @@ export function isCorsError(error: unknown): boolean {
|
|||
|
||||
/**
|
||||
* Create a streamFn that applies CORS proxy when needed.
|
||||
* Reads proxy settings from storage on each call.
|
||||
*
|
||||
* @param proxyUrl - CORS proxy URL, or undefined to disable
|
||||
* @param getProxyUrl - Async function to get current proxy URL (or undefined if disabled)
|
||||
* @returns A streamFn compatible with Agent's streamFn option
|
||||
*/
|
||||
export function createStreamFn(proxyUrl?: string) {
|
||||
return (model: Model<any>, context: Context, options?: SimpleStreamOptions) => {
|
||||
export function createStreamFn(getProxyUrl: () => Promise<string | undefined>) {
|
||||
return async (model: Model<any>, context: Context, options?: SimpleStreamOptions) => {
|
||||
const apiKey = options?.apiKey;
|
||||
const proxyUrl = await getProxyUrl();
|
||||
|
||||
if (!apiKey || !proxyUrl) {
|
||||
return streamSimple(model, context, options);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue