UNPKG

assistant-cloud

Version:

Cloud integration for assistant-ui

59 lines 2.19 kB
import { ReadonlyJSONObject } from "assistant-stream/utils"; //#region src/FormattedCloudPersistence.d.ts /** * Format adapter shape — structurally identical to the MessageFormatAdapter * in @assistant-ui/react, but defined here to avoid cross-package type moves. * TypeScript's structural typing ensures these are interchangeable. */ type MessageFormatAdapter<TMessage, TStorageFormat> = { format: string; encode(item: { parentId: string | null; message: TMessage; }): TStorageFormat; decode(stored: { id: string; parent_id: string | null; format: string; content: TStorageFormat; }): { parentId: string | null; message: TMessage; }; getId(message: TMessage): string; }; /** * Wraps a CloudMessagePersistence instance with format-aware encode/decode. * * This centralizes the pattern used by both: * - useCloudChat (standalone AI SDK hook) * - AssistantCloudThreadHistoryAdapter.withFormat() (assistant-ui runtime) * * The persistence parameter is typed structurally (not by class) so callers * don't need to import CloudMessagePersistence directly. */ declare const createFormattedPersistence: <TMessage, TStorageFormat>(persistence: { append: (threadId: string, messageId: string, parentId: string | null, format: string, content: ReadonlyJSONObject) => Promise<void>; load: (threadId: string, format?: string) => Promise<any[]>; isPersisted: (messageId: string) => boolean; update?: (threadId: string, messageId: string, format: string, content: ReadonlyJSONObject) => Promise<void>; }, adapter: MessageFormatAdapter<TMessage, TStorageFormat>) => { append: (threadId: string, item: { parentId: string | null; message: TMessage; }) => Promise<void>; update: ((threadId: string, item: { parentId: string | null; message: TMessage; }, messageId: string) => Promise<void>) | undefined; load: (threadId: string) => Promise<{ messages: { parentId: string | null; message: TMessage; }[]; }>; isPersisted: (messageId: string) => boolean; }; //#endregion export { MessageFormatAdapter, createFormattedPersistence }; //# sourceMappingURL=FormattedCloudPersistence.d.ts.map