Skip to content

Commit

Permalink
fix: useDangerousInBrowserRuntime correct options forwarding (#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Oct 4, 2024
1 parent 8175cfc commit d0db602
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-timers-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

fix: useDangerousInBrowserRuntime correct options forwarding
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
18 changes: 6 additions & 12 deletions packages/react/src/runtimes/edge/useEdgeRuntime.ts
Original file line number Diff line number Diff line change
@@ -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);
};
10 changes: 10 additions & 0 deletions packages/react/src/runtimes/local/LocalRuntimeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ export type LocalRuntimeOptions = {
}
| undefined;
};

export const splitLocalRuntimeOptions = <T extends LocalRuntimeOptions>(
options: T,
) => {
const { initialMessages, maxToolRoundtrips, adapters, ...rest } = options;
return {
localRuntimeOptions: { initialMessages, maxToolRoundtrips, adapters },
otherOptions: rest,
};
};

0 comments on commit d0db602

Please sign in to comment.