diff --git a/.changeset/late-timers-yell.md b/.changeset/late-timers-yell.md new file mode 100644 index 000000000..4ddb59a9e --- /dev/null +++ b/.changeset/late-timers-yell.md @@ -0,0 +1,5 @@ +--- +"@assistant-ui/react": patch +--- + +fix: useDangerousInBrowserRuntime correct options forwarding diff --git a/packages/react/src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts b/packages/react/src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts index e06949b20..c18f78a35 100644 --- a/packages/react/src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts +++ b/packages/react/src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts @@ -4,14 +4,16 @@ import { DangerousInBrowserAdapter, DangerousInBrowserAdapterOptions, } from "./DangerousInBrowserAdapter"; +import { splitLocalRuntimeOptions } from "../local/LocalRuntimeOptions"; export type DangerousInBrowserRuntimeOptions = DangerousInBrowserAdapterOptions & LocalRuntimeOptions; -export const useDangerousInBrowserRuntime = ({ - initialMessages, - ...options -}: DangerousInBrowserRuntimeOptions) => { - const [adapter] = useState(() => new DangerousInBrowserAdapter(options)); - return useLocalRuntime(adapter, { initialMessages }); +export const useDangerousInBrowserRuntime = ( + options: DangerousInBrowserRuntimeOptions, +) => { + const { localRuntimeOptions, otherOptions } = + splitLocalRuntimeOptions(options); + const [adapter] = useState(() => new DangerousInBrowserAdapter(otherOptions)); + return useLocalRuntime(adapter, localRuntimeOptions); }; diff --git a/packages/react/src/runtimes/edge/useEdgeRuntime.ts b/packages/react/src/runtimes/edge/useEdgeRuntime.ts index 78f3741ec..7e717d1ce 100644 --- a/packages/react/src/runtimes/edge/useEdgeRuntime.ts +++ b/packages/react/src/runtimes/edge/useEdgeRuntime.ts @@ -1,19 +1,13 @@ import { LocalRuntimeOptions, useLocalRuntime } from ".."; import { useState } from "react"; import { EdgeChatAdapterOptions, EdgeChatAdapter } from "./EdgeChatAdapter"; +import { splitLocalRuntimeOptions } from "../local/LocalRuntimeOptions"; export type EdgeRuntimeOptions = EdgeChatAdapterOptions & LocalRuntimeOptions; -export const useEdgeRuntime = ({ - initialMessages, - maxToolRoundtrips, - adapters, - ...options -}: EdgeRuntimeOptions) => { - const [adapter] = useState(() => new EdgeChatAdapter(options)); - return useLocalRuntime(adapter, { - initialMessages, - maxToolRoundtrips, - adapters, - }); +export const useEdgeRuntime = (options: EdgeRuntimeOptions) => { + const { localRuntimeOptions, otherOptions } = + splitLocalRuntimeOptions(options); + const [adapter] = useState(() => new EdgeChatAdapter(otherOptions)); + return useLocalRuntime(adapter, localRuntimeOptions); }; diff --git a/packages/react/src/runtimes/local/LocalRuntimeOptions.tsx b/packages/react/src/runtimes/local/LocalRuntimeOptions.tsx index 90ca9aae3..a695418f9 100644 --- a/packages/react/src/runtimes/local/LocalRuntimeOptions.tsx +++ b/packages/react/src/runtimes/local/LocalRuntimeOptions.tsx @@ -14,3 +14,13 @@ export type LocalRuntimeOptions = { } | undefined; }; + +export const splitLocalRuntimeOptions = ( + options: T, +) => { + const { initialMessages, maxToolRoundtrips, adapters, ...rest } = options; + return { + localRuntimeOptions: { initialMessages, maxToolRoundtrips, adapters }, + otherOptions: rest, + }; +};