histoire
Version:
A fast story book powered by Vite
70 lines • 3.6 kB
TypeScript
import type { UiAgentPlanDecision, UiAgentPlanEntry, UiAgentStep, UiAgentThreadBase, UiAiThread, UiCommentAttachment, UiCommentSessionOptions } from '@histoire/shared';
import type { AiThreadDraftInput } from '../ai-threads/validate.js';
import type { ThreadFileCodec } from './file.js';
/** Agent replies retain their normal ACP file/permission authority. */
export interface CommentAgentReply {
/** Plain-text final reply. */
text: string;
/** Agent-reported project edits. */
changes?: {
file: string;
added: number;
removed: number;
}[];
/** Agent tool calls and thinking spans, settled. */
steps?: UiAgentStep[];
/** Last agent-reported plan. */
plan?: UiAgentPlanEntry[];
/** Plan approval answers given during the reply. */
decisions?: UiAgentPlanDecision[];
}
/** Comment dispatcher starts one independent agent session for each comment. */
export type CommentAgentRunner<T extends UiAgentThreadBase = UiAiThread> = (comment: T, working: () => Promise<void>) => Promise<CommentAgentReply>;
/** Client-writable fields every conversation draft carries. */
export interface ThreadDraftBase {
/** Opaque UUID. */
id: string;
/** Uploaded files referenced by the first message. */
attachments?: UiCommentAttachment[];
}
/**
* Status of a comment no agent is working on: `replied` when the latest message is a
* successful agent answer, otherwise `draft` (unsent user reply, failure, or no reply yet).
* @param comment Persisted comment.
*/
export declare function idleStatus(comment: UiAgentThreadBase): 'draft' | 'replied';
/**
* Lazy persisted CRUD and ordered agent delivery, independent of browser transport.
* Defaults store AI threads; `codec` and `validateDraft` adapt it to other conversations.
*/
export declare function createCommentsStore<T extends UiAgentThreadBase = UiAiThread, D extends ThreadDraftBase = AiThreadDraftInput>(options: {
/** Captured project root. */
root: string;
/** Trusted configured relative path. */
file: string;
/** Disabled stores perform no filesystem access. */
enabled: boolean;
/** Publication callback, shared by all dev clients. */
changed?: (comments: T[]) => void;
/** Persisted record format; AI threads by default. */
codec?: ThreadFileCodec<T>;
/** Project client-writable fields (server-derived fields may be added here). */
validateDraft?: (value: unknown) => D;
}): {
list: () => Promise<T[]>;
/** A new dev generation cannot inherit an agent process from persisted lifecycle. */
recover(): Promise<void>;
/** Create/update user fields while retaining server-owned lifecycle and thread. */
upsert(value: D): Promise<void>;
/** Remove only the explicitly named persisted annotation. */
remove(id: string): Promise<void>;
/** Resolve/reopen preserves history and never restarts agent work. */
resolve(id: string, resolved: boolean): Promise<void>;
/** Replies reopen resolved threads and enter the same independent conversation on its next send. */
reply(id: string, body: string, attachments?: UiCommentAttachment[]): Promise<void>;
/** Ordered bulk delivery shares no agent session or positional identity between comments; `sessionOptions` persist on each comment. */
send(ids: readonly string[], agentId: string, runner: CommentAgentRunner<T>, sessionOptions?: UiCommentSessionOptions): Promise<void>;
/** Stop admissions before channel/ACP cleanup observes pending delivery. */
close(): Promise<void>;
};
//# sourceMappingURL=store.d.ts.map