assistant-cloud
Version:
Cloud integration for assistant-ui
62 lines • 2.68 kB
TypeScript
import type { ReadonlyJSONObject } from "assistant-stream/utils";
import type { CloudMessageRunPhase } from "./CloudMessagePersistence.js";
/**
* 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.
*/
export 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 with a MessageFormatAdapter's encode and
* decode. The persistence parameter is typed structurally, so a caller does
* not need to import the class.
*
* `append` and `update` take an optional run phase that is passed through to
* the persistence: `running` opens (on append) or renews (on update) the
* message's run lease, and an end reason makes the write the lease's final
* write and ends it, the same as for `aui/v0` messages.
*/
export declare const createFormattedPersistence: <TMessage, TStorageFormat>(persistence: {
append: (threadId: string, messageId: string, parentId: string | null, format: string, content: ReadonlyJSONObject, run?: CloudMessageRunPhase) => Promise<void>;
load: (threadId: string, format?: string) => Promise<any[]>;
isPersisted: (messageId: string) => boolean;
update?: (threadId: string, messageId: string, format: string, content: ReadonlyJSONObject, run?: CloudMessageRunPhase) => Promise<void>;
delete?: (threadId: string, messageIds: string[]) => Promise<void>;
}, adapter: MessageFormatAdapter<TMessage, TStorageFormat>) => {
append: (threadId: string, item: {
parentId: string | null;
message: TMessage;
}, run?: CloudMessageRunPhase) => Promise<void>;
update: ((threadId: string, item: {
parentId: string | null;
message: TMessage;
}, messageId: string, run?: CloudMessageRunPhase) => Promise<void>) | undefined;
delete: ((threadId: string, items: {
parentId: string | null;
message: TMessage;
}[]) => Promise<void>) | undefined;
load: (threadId: string) => Promise<{
messages: {
parentId: string | null;
message: TMessage;
}[];
}>;
isPersisted: (messageId: string) => boolean;
};
//# sourceMappingURL=FormattedCloudPersistence.d.ts.map