UNPKG

assistant-cloud

Version:

Cloud integration for assistant-ui

62 lines 2.42 kB
import { CloudMessage } from "./AssistantCloudThreadMessages.js"; import { AssistantCloud } from "./AssistantCloud.js"; import { ReadonlyJSONObject } from "assistant-stream/utils"; //#region src/CloudMessagePersistence.d.ts /** * Shared persistence logic for cloud message storage. * * Handles ID mapping (local → remote) and parent_id chaining for both: * - AssistantCloudThreadHistoryAdapter (assistant-ui runtime) * - useCloudChat (standalone AI SDK hook) * * The promise-based ID resolution handles concurrent appends — if message B's * parent is message A, and A is still being created, we await A's promise * to get its remote ID before creating B. */ declare class CloudMessagePersistence { private idMapping; private getCloud; constructor(cloud: AssistantCloud); constructor(getCloud: () => AssistantCloud); /** * Persist a message to the cloud. * * @param threadId - Remote thread ID * @param messageId - Local message ID (used for tracking) * @param parentId - Local parent message ID (or null for first message) * @param format - Message format (e.g., "aui/v0", "ai-sdk/v6") * @param content - Message content (format-specific) */ append(threadId: string, messageId: string, parentId: string | null, format: string, content: ReadonlyJSONObject): Promise<void>; /** * Update an already-persisted message in the cloud. */ update(threadId: string, messageId: string, _format: string, content: ReadonlyJSONObject): Promise<void>; /** * Check if a message has been persisted (or is currently being persisted). */ isPersisted(messageId: string): boolean; /** * Get the remote ID for a local message ID (resolved). * Returns undefined if not persisted. */ getRemoteId(messageId: string): Promise<string | undefined>; /** * Load messages from the cloud and populate the ID mapping. * * The ID mapping is populated so that `isPersisted()` returns true for * loaded messages, preventing re-persistence of already-stored messages. * * @param threadId - Remote thread ID * @param format - Optional format filter * @returns Array of cloud messages */ load(threadId: string, format?: string): Promise<CloudMessage[]>; /** * Reset the ID mapping (call when switching threads). */ reset(): void; } //#endregion export { CloudMessagePersistence }; //# sourceMappingURL=CloudMessagePersistence.d.ts.map