diff --git a/.changeset/calm-countries-argue.md b/.changeset/calm-countries-argue.md new file mode 100644 index 000000000..34ef08cb0 --- /dev/null +++ b/.changeset/calm-countries-argue.md @@ -0,0 +1,5 @@ +--- +"@assistant-ui/react": patch +--- + +feat: export useAttachmentRuntime, useAttachment, FeedbackAdapter diff --git a/.changeset/small-avocados-unite.md b/.changeset/small-avocados-unite.md new file mode 100644 index 000000000..362051f50 --- /dev/null +++ b/.changeset/small-avocados-unite.md @@ -0,0 +1,6 @@ +--- +"@assistant-ui/react-ai-sdk": patch +"@assistant-ui/react": patch +--- + +feat(ai-sdk): Adapters support (attachment, feedback, speech, threadManager) diff --git a/packages/react-ai-sdk/src/rsc/VercelRSCAdapter.tsx b/packages/react-ai-sdk/src/rsc/VercelRSCAdapter.tsx index 4da56665d..61026e37d 100644 --- a/packages/react-ai-sdk/src/rsc/VercelRSCAdapter.tsx +++ b/packages/react-ai-sdk/src/rsc/VercelRSCAdapter.tsx @@ -1,6 +1,7 @@ "use client"; import type { AppendMessage } from "@assistant-ui/react"; import type { VercelRSCMessage } from "./VercelRSCMessage"; +import { ExternalStoreAdapter } from "@assistant-ui/react"; type RSCMessageConverter = { convertMessage: (message: T) => VercelRSCMessage; @@ -15,6 +16,8 @@ type VercelRSCAdapterBase = { onReload?: ((parentId: string | null) => Promise) | undefined; convertMessage?: ((message: T) => VercelRSCMessage) | undefined; + adapters?: ExternalStoreAdapter["adapters"] | undefined; + /** * @deprecated Use `onNew` instead. This will be removed in 0.6.0. */ diff --git a/packages/react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx b/packages/react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx index fa0172a2f..d83738d80 100644 --- a/packages/react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx +++ b/packages/react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx @@ -39,6 +39,7 @@ export const useVercelRSCRuntime = ( adapter.convertMessage ?? ((m) => m as VercelRSCMessage), m, ), + adapters: adapter.adapters, unstable_capabilities: { copy: false, }, diff --git a/packages/react-ai-sdk/src/ui/use-assistant/useVercelUseAssistantRuntime.tsx b/packages/react-ai-sdk/src/ui/use-assistant/useVercelUseAssistantRuntime.tsx index efc538e24..868b8db51 100644 --- a/packages/react-ai-sdk/src/ui/use-assistant/useVercelUseAssistantRuntime.tsx +++ b/packages/react-ai-sdk/src/ui/use-assistant/useVercelUseAssistantRuntime.tsx @@ -7,9 +7,15 @@ import { convertMessage } from "../utils/convertMessage"; import { useInputSync } from "../utils/useInputSync"; import { toCreateMessage } from "../utils/toCreateMessage"; import { vercelAttachmentAdapter } from "../utils/vercelAttachmentAdapter"; +import { ExternalStoreAdapter } from "@assistant-ui/react"; + +export type VercelUseChatAdapter = { + adapters?: Omit | undefined; +}; export const useVercelUseAssistantRuntime = ( assistantHelpers: ReturnType, + adapter: VercelUseChatAdapter = {}, ) => { const messages = useExternalMessageConverter({ callback: convertMessage, @@ -31,6 +37,7 @@ export const useVercelUseAssistantRuntime = ( }, adapters: { attachments: vercelAttachmentAdapter, + ...adapter.adapters, }, }); diff --git a/packages/react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx b/packages/react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx index da322e553..bac687065 100644 --- a/packages/react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx +++ b/packages/react-ai-sdk/src/ui/use-chat/useVercelUseChatRuntime.tsx @@ -9,9 +9,15 @@ import { sliceMessagesUntil } from "../utils/sliceMessagesUntil"; import { toCreateMessage } from "../utils/toCreateMessage"; import { vercelAttachmentAdapter } from "../utils/vercelAttachmentAdapter"; import { getVercelAIMessages } from "../getVercelAIMessages"; +import { ExternalStoreAdapter } from "@assistant-ui/react"; + +export type VercelUseChatAdapter = { + adapters?: Omit | undefined; +}; export const useVercelUseChatRuntime = ( chatHelpers: ReturnType, + adapter: VercelUseChatAdapter = {}, ) => { const messages = useExternalMessageConverter({ callback: convertMessage, @@ -54,6 +60,7 @@ export const useVercelUseChatRuntime = ( }, adapters: { attachments: vercelAttachmentAdapter, + ...adapter.adapters, }, }); diff --git a/packages/react/src/runtimes/external-store/ExternalStoreAdapter.tsx b/packages/react/src/runtimes/external-store/ExternalStoreAdapter.tsx index 78e6ee720..f2f744b0b 100644 --- a/packages/react/src/runtimes/external-store/ExternalStoreAdapter.tsx +++ b/packages/react/src/runtimes/external-store/ExternalStoreAdapter.tsx @@ -60,12 +60,14 @@ type ExternalStoreAdapterBase = { | ((options: AddToolResultOptions) => Promise | void) | undefined; convertMessage?: ExternalStoreMessageConverter | undefined; - adapters?: { - attachments?: AttachmentAdapter | undefined; - speech?: SpeechSynthesisAdapter | undefined; - feedback?: FeedbackAdapter | undefined; - threadManager?: ExternalStoreThreadManagerAdapter | undefined; - }; + adapters?: + | { + attachments?: AttachmentAdapter | undefined; + speech?: SpeechSynthesisAdapter | undefined; + feedback?: FeedbackAdapter | undefined; + threadManager?: ExternalStoreThreadManagerAdapter | undefined; + } + | undefined; unstable_capabilities?: | { copy?: boolean | undefined; diff --git a/packages/react/src/runtimes/feedback/index.ts b/packages/react/src/runtimes/feedback/index.ts new file mode 100644 index 000000000..245f0bf1c --- /dev/null +++ b/packages/react/src/runtimes/feedback/index.ts @@ -0,0 +1 @@ +export { type FeedbackAdapter } from "./FeedbackAdapter"; diff --git a/packages/react/src/runtimes/index.ts b/packages/react/src/runtimes/index.ts index 580cdf9ec..87dfe3cd8 100644 --- a/packages/react/src/runtimes/index.ts +++ b/packages/react/src/runtimes/index.ts @@ -5,3 +5,4 @@ export * from "./external-store"; export * from "./dangerous-in-browser"; export * from "./speech"; export * from "./attachment"; +export * from "./feedback";