From 5d43e55620f4e11840136e738dc1e0ae34b859a9 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Sat, 26 Oct 2024 11:26:37 -0700 Subject: [PATCH] fix: properly pass initialMessages to LocalRuntime (#1090) Co-Authored-By: igo --- apps/docs/app/(home)/page.tsx | 11 +++++++++++ packages/react-ai-sdk/package.json | 2 +- packages/react-hook-form/package.json | 2 +- packages/react-langgraph/package.json | 2 +- packages/react-markdown/package.json | 2 +- packages/react-playground/package.json | 2 +- packages/react-syntax-highlighter/package.json | 2 +- packages/react-trieve/package.json | 2 +- packages/react/CHANGELOG.md | 6 ++++++ packages/react/package.json | 2 +- .../react/src/runtimes/local/LocalRuntimeCore.tsx | 2 +- packages/react/src/runtimes/local/useLocalRuntime.tsx | 4 ++-- 12 files changed, 28 insertions(+), 11 deletions(-) diff --git a/apps/docs/app/(home)/page.tsx b/apps/docs/app/(home)/page.tsx index 2e0d5fe00..be5f88f6a 100644 --- a/apps/docs/app/(home)/page.tsx +++ b/apps/docs/app/(home)/page.tsx @@ -138,6 +138,17 @@ export type AssistantProps = { const MyRuntimeProvider = ({ children }: { children: React.ReactNode }) => { const runtime = useEdgeRuntime({ api: "/api/chat", + initialMessages: [ + { + role: "system", + content: [{ type: "text", text: "You are weather assistant" }], + }, + { + role: "user", + content: [{ type: "text", text: "What's the weather in Paris?" }], + }, + { role: "assistant", content: [{ type: "text", text: "It's sunny." }] }, + ], adapters: { attachments: new CompositeAttachmentAdapter([ new SimpleImageAttachmentAdapter(), diff --git a/packages/react-ai-sdk/package.json b/packages/react-ai-sdk/package.json index 202e60225..9a520c0bf 100644 --- a/packages/react-ai-sdk/package.json +++ b/packages/react-ai-sdk/package.json @@ -34,7 +34,7 @@ "zustand": "^5.0.0" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@types/react": "*", "react": "^18 || ^19" }, diff --git a/packages/react-hook-form/package.json b/packages/react-hook-form/package.json index c6e5622ac..48d21b02a 100644 --- a/packages/react-hook-form/package.json +++ b/packages/react-hook-form/package.json @@ -30,7 +30,7 @@ "zod": "^3.23.8" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@types/react": "*", "react": "^18 || ^19", "react-hook-form": "^7" diff --git a/packages/react-langgraph/package.json b/packages/react-langgraph/package.json index aca5d470a..fa47b5fdd 100644 --- a/packages/react-langgraph/package.json +++ b/packages/react-langgraph/package.json @@ -30,7 +30,7 @@ "zod": "^3.23.8" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@types/react": "*", "react": "^18 || ^19" }, diff --git a/packages/react-markdown/package.json b/packages/react-markdown/package.json index f0b8e6fec..827181779 100644 --- a/packages/react-markdown/package.json +++ b/packages/react-markdown/package.json @@ -41,7 +41,7 @@ "react-markdown": "^9.0.1" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@types/react": "*", "react": "^18 || ^19", "tailwindcss": "^3.4.4" diff --git a/packages/react-playground/package.json b/packages/react-playground/package.json index cfb78d76f..8588a8fb8 100644 --- a/packages/react-playground/package.json +++ b/packages/react-playground/package.json @@ -47,7 +47,7 @@ "zustand": "^5.0.0" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@types/react": "*", "react": "^18 || ^19", "tailwindcss": "^3.4.4" diff --git a/packages/react-syntax-highlighter/package.json b/packages/react-syntax-highlighter/package.json index 4cb41023b..4df296fad 100644 --- a/packages/react-syntax-highlighter/package.json +++ b/packages/react-syntax-highlighter/package.json @@ -27,7 +27,7 @@ "build": "tsup src/index.ts --format cjs,esm --dts --sourcemap --clean" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@assistant-ui/react-markdown": "^0.2.25", "@types/react": "*", "@types/react-syntax-highlighter": "*", diff --git a/packages/react-trieve/package.json b/packages/react-trieve/package.json index c457127ac..bb99be5cd 100644 --- a/packages/react-trieve/package.json +++ b/packages/react-trieve/package.json @@ -46,7 +46,7 @@ "unist-util-visit": "^5.0.0" }, "peerDependencies": { - "@assistant-ui/react": "^0.5.95", + "@assistant-ui/react": "^0.5.96", "@assistant-ui/react-markdown": "^0.2.25", "trieve-ts-sdk": "^0.0.13", "@types/react": "*", diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 9ef0a44c4..0a26ddf38 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,11 @@ # @assistant-ui/react +## 0.5.96 + +### Patch Changes + +- fix: properly pass initialMessages to LocalRuntime + ## 0.5.95 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index ac6f86950..b3fd5f773 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -29,7 +29,7 @@ "conversational-ui", "conversational-ai" ], - "version": "0.5.95", + "version": "0.5.96", "license": "MIT", "exports": { ".": { diff --git a/packages/react/src/runtimes/local/LocalRuntimeCore.tsx b/packages/react/src/runtimes/local/LocalRuntimeCore.tsx index e7f278fd9..84cb2e274 100644 --- a/packages/react/src/runtimes/local/LocalRuntimeCore.tsx +++ b/packages/react/src/runtimes/local/LocalRuntimeCore.tsx @@ -25,7 +25,7 @@ export class LocalRuntimeCore extends BaseAssistantRuntimeCore { constructor( options: LocalRuntimeOptionsBase, - initialMessages?: CoreMessage[], + initialMessages: readonly CoreMessage[] | undefined, ) { super(); diff --git a/packages/react/src/runtimes/local/useLocalRuntime.tsx b/packages/react/src/runtimes/local/useLocalRuntime.tsx index cce203fa6..99390ee8f 100644 --- a/packages/react/src/runtimes/local/useLocalRuntime.tsx +++ b/packages/react/src/runtimes/local/useLocalRuntime.tsx @@ -37,7 +37,7 @@ class LocalRuntimeImpl extends AssistantRuntimeImpl implements LocalRuntime { export const useLocalRuntime = ( adapter: ChatModelAdapter, - options: LocalRuntimeOptions = {}, + { initialMessages, ...options }: LocalRuntimeOptions = {}, ) => { const opt = { ...options, @@ -47,7 +47,7 @@ export const useLocalRuntime = ( }, }; - const [runtime] = useState(() => new LocalRuntimeCore(opt)); + const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages)); useEffect(() => { runtime.setOptions(opt);