diff --git a/examples/with-react-hook-form/app/layout.tsx b/examples/with-react-hook-form/app/layout.tsx index 98dbeed9a..f10f2bcb5 100644 --- a/examples/with-react-hook-form/app/layout.tsx +++ b/examples/with-react-hook-form/app/layout.tsx @@ -14,7 +14,7 @@ export default function RootLayout({ return ( - + {children} diff --git a/examples/with-vercel-ai-rsc/app/page.tsx b/examples/with-vercel-ai-rsc/app/page.tsx index 6b6eb75cc..9b148a026 100644 --- a/examples/with-vercel-ai-rsc/app/page.tsx +++ b/examples/with-vercel-ai-rsc/app/page.tsx @@ -13,7 +13,7 @@ import { useVercelRSCRuntime } from "@assistant-ui/react-ai-sdk"; export default function Home() { return ( -
+
diff --git a/packages/react/src/runtimes/edge/EdgeChatAdapter.ts b/packages/react/src/runtimes/edge/EdgeChatAdapter.ts index 82146b7da..f2df7c8ae 100644 --- a/packages/react/src/runtimes/edge/EdgeChatAdapter.ts +++ b/packages/react/src/runtimes/edge/EdgeChatAdapter.ts @@ -46,9 +46,7 @@ export class EdgeChatAdapter implements ChatModelAdapter { body: JSON.stringify({ system: config.system, messages: toCoreMessages(messages), - tools: toLanguageModelTools( - config.tools, - ) as EdgeRuntimeRequestOptions["tools"], + tools: config.tools ? toLanguageModelTools(config.tools) : [], ...config.callSettings, ...config.config, } satisfies EdgeRuntimeRequestOptions), diff --git a/packages/react/src/runtimes/edge/converters/fromLanguageModelTools.ts b/packages/react/src/runtimes/edge/converters/fromLanguageModelTools.ts new file mode 100644 index 000000000..0f297a379 --- /dev/null +++ b/packages/react/src/runtimes/edge/converters/fromLanguageModelTools.ts @@ -0,0 +1,16 @@ +import { LanguageModelV1FunctionTool } from "@ai-sdk/provider"; +import { Tool } from "../../../types/ModelConfigTypes"; + +export const fromLanguageModelTools = ( + tools: LanguageModelV1FunctionTool[], +): Record> => { + return Object.fromEntries( + tools.map((tool) => [ + tool.name, + { + description: tool.description, + parameters: tool.parameters, + }, + ]), + ); +}; diff --git a/packages/react/src/runtimes/edge/converters/index.ts b/packages/react/src/runtimes/edge/converters/index.ts new file mode 100644 index 000000000..eb1b1e04d --- /dev/null +++ b/packages/react/src/runtimes/edge/converters/index.ts @@ -0,0 +1,4 @@ +export { toLanguageModelMessages } from "./toLanguageModelMessages"; +export { fromLanguageModelMessages } from "./fromLanguageModelMessages"; +export { fromCoreMessages } from "./fromCoreMessage"; +export { fromLanguageModelTools } from "./fromLanguageModelTools"; diff --git a/packages/react/src/runtimes/edge/converters/toLanguageModelTools.ts b/packages/react/src/runtimes/edge/converters/toLanguageModelTools.ts index 5e5cdd510..2956ac033 100644 --- a/packages/react/src/runtimes/edge/converters/toLanguageModelTools.ts +++ b/packages/react/src/runtimes/edge/converters/toLanguageModelTools.ts @@ -5,9 +5,8 @@ import zodToJsonSchema from "zod-to-json-schema"; import { Tool } from "../../../types/ModelConfigTypes"; export const toLanguageModelTools = ( - tools: Record> | undefined, + tools: Record>, ): LanguageModelV1FunctionTool[] => { - if (!tools) return []; return Object.entries(tools).map(([name, tool]) => ({ type: "function", name, diff --git a/packages/react/src/runtimes/edge/index.ts b/packages/react/src/runtimes/edge/index.ts index 337749c1b..5af5b62ba 100644 --- a/packages/react/src/runtimes/edge/index.ts +++ b/packages/react/src/runtimes/edge/index.ts @@ -1,6 +1,5 @@ +export * from "./converters"; + export { useEdgeRuntime, type EdgeRuntimeOptions } from "./useEdgeRuntime"; export { EdgeChatAdapter } from "./EdgeChatAdapter"; - -export { toLanguageModelMessages } from "./converters/toLanguageModelMessages"; -export { fromLanguageModelMessages } from "./converters/fromLanguageModelMessages"; -export { fromCoreMessages } from "./converters/fromCoreMessage"; +export type { EdgeRuntimeRequestOptions } from "./EdgeRuntimeRequestOptions";