Skip to content

Commit

Permalink
feat(ai-sdk): Adapters support (attachment, feedback, speech, threadM…
Browse files Browse the repository at this point in the history
…anager) (#1037)

* feat(ai-sdk): Adapters support (attachment, feedback, speech, threadManager)

* add changesets
  • Loading branch information
Yonom authored Oct 21, 2024
1 parent fadb2ec commit b38165d
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-countries-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

feat: export useAttachmentRuntime, useAttachment, FeedbackAdapter
6 changes: 6 additions & 0 deletions .changeset/small-avocados-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@assistant-ui/react-ai-sdk": patch
"@assistant-ui/react": patch
---

feat(ai-sdk): Adapters support (attachment, feedback, speech, threadManager)
3 changes: 3 additions & 0 deletions packages/react-ai-sdk/src/rsc/VercelRSCAdapter.tsx
Original file line number Diff line number Diff line change
@@ -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<T> = {
convertMessage: (message: T) => VercelRSCMessage;
Expand All @@ -15,6 +16,8 @@ type VercelRSCAdapterBase<T> = {
onReload?: ((parentId: string | null) => Promise<void>) | undefined;
convertMessage?: ((message: T) => VercelRSCMessage) | undefined;

adapters?: ExternalStoreAdapter["adapters"] | undefined;

/**
* @deprecated Use `onNew` instead. This will be removed in 0.6.0.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/react-ai-sdk/src/rsc/useVercelRSCRuntime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const useVercelRSCRuntime = <T extends WeakKey>(
adapter.convertMessage ?? ((m) => m as VercelRSCMessage),
m,
),
adapters: adapter.adapters,
unstable_capabilities: {
copy: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExternalStoreAdapter["adapters"], "attachments"> | undefined;
};

export const useVercelUseAssistantRuntime = (
assistantHelpers: ReturnType<typeof useAssistant>,
adapter: VercelUseChatAdapter = {},
) => {
const messages = useExternalMessageConverter({
callback: convertMessage,
Expand All @@ -31,6 +37,7 @@ export const useVercelUseAssistantRuntime = (
},
adapters: {
attachments: vercelAttachmentAdapter,
...adapter.adapters,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExternalStoreAdapter["adapters"], "attachments"> | undefined;
};

export const useVercelUseChatRuntime = (
chatHelpers: ReturnType<typeof useChat>,
adapter: VercelUseChatAdapter = {},
) => {
const messages = useExternalMessageConverter({
callback: convertMessage,
Expand Down Expand Up @@ -54,6 +60,7 @@ export const useVercelUseChatRuntime = (
},
adapters: {
attachments: vercelAttachmentAdapter,
...adapter.adapters,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ type ExternalStoreAdapterBase<T> = {
| ((options: AddToolResultOptions) => Promise<void> | void)
| undefined;
convertMessage?: ExternalStoreMessageConverter<T> | 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;
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/runtimes/feedback/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { type FeedbackAdapter } from "./FeedbackAdapter";
1 change: 1 addition & 0 deletions packages/react/src/runtimes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./external-store";
export * from "./dangerous-in-browser";
export * from "./speech";
export * from "./attachment";
export * from "./feedback";

0 comments on commit b38165d

Please sign in to comment.