@arnilo/prism-server 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,149 @@
1
+ import { type AgentEventRecord, type AgentIdentity, type AgentRunResult, type AgentSession, type JsonObject, type Message, type OwnershipScope, type PersistencePage, type RunOptions, type SecretRedactor, type SessionRecord } from "@arnilo/prism";
2
+ import type { PersistenceLifecycleStore } from "@arnilo/prism";
3
+ import type { PrismRequestHandler, PrismServerAuthorization } from "./types.js";
4
+ /** Phase 9 freeze: thread page 50/200; replay page 100/500; cursor 4/16 KiB; title 256 B/2 KiB;
5
+ * request id 256 B/2 KiB; active branches 16/64; export 8/32 MiB and 100/500 pages; body 64 KiB/1 MiB. */
6
+ export declare const DEFAULT_CONVERSATION_THREAD_PAGE_LIMIT = 50;
7
+ export declare const HARD_CONVERSATION_THREAD_PAGE_LIMIT = 200;
8
+ export declare const DEFAULT_CONVERSATION_REPLAY_PAGE_LIMIT = 100;
9
+ export declare const HARD_CONVERSATION_REPLAY_PAGE_LIMIT = 500;
10
+ export declare const DEFAULT_CONVERSATION_CURSOR_BYTES: number;
11
+ export declare const HARD_CONVERSATION_CURSOR_BYTES: number;
12
+ export declare const DEFAULT_CONVERSATION_TITLE_BYTES = 256;
13
+ export declare const HARD_CONVERSATION_TITLE_BYTES: number;
14
+ export declare const DEFAULT_CONVERSATION_REQUEST_ID_BYTES = 256;
15
+ export declare const HARD_CONVERSATION_REQUEST_ID_BYTES: number;
16
+ export declare const DEFAULT_CONVERSATION_MAX_ACTIVE_BRANCHES = 16;
17
+ export declare const HARD_CONVERSATION_MAX_ACTIVE_BRANCHES = 64;
18
+ export declare const DEFAULT_CONVERSATION_EXPORT_BYTES: number;
19
+ export declare const HARD_CONVERSATION_EXPORT_BYTES: number;
20
+ export declare const DEFAULT_CONVERSATION_EXPORT_PAGES = 100;
21
+ export declare const HARD_CONVERSATION_EXPORT_PAGES = 500;
22
+ export declare const DEFAULT_CONVERSATION_REQUEST_BYTES: number;
23
+ export declare const HARD_CONVERSATION_REQUEST_BYTES: number;
24
+ export interface ConversationLimits {
25
+ readonly threadPageLimit?: number;
26
+ readonly replayPageLimit?: number;
27
+ readonly cursorBytes?: number;
28
+ readonly titleBytes?: number;
29
+ readonly requestIdBytes?: number;
30
+ readonly maxActiveBranches?: number;
31
+ readonly exportBytes?: number;
32
+ readonly exportPages?: number;
33
+ readonly maxRequestBytes?: number;
34
+ }
35
+ export interface ResolvedConversationLimits {
36
+ readonly threadPageLimit: number;
37
+ readonly replayPageLimit: number;
38
+ readonly cursorBytes: number;
39
+ readonly titleBytes: number;
40
+ readonly requestIdBytes: number;
41
+ readonly maxActiveBranches: number;
42
+ readonly exportBytes: number;
43
+ readonly exportPages: number;
44
+ readonly maxRequestBytes: number;
45
+ }
46
+ export declare function resolveConversationLimits(input?: ConversationLimits): ResolvedConversationLimits;
47
+ /** Narrow persistence seam. sqlite/postgres adapters implement it; stores without
48
+ * `appendSession` cannot host conversations (fail-closed at factory time). */
49
+ export interface ConversationServiceStore {
50
+ querySessions(query: import("@arnilo/prism").SessionQuery): Promise<PersistencePage<SessionRecord>>;
51
+ queryEvents(query: import("@arnilo/prism").AgentEventQuery): Promise<PersistencePage<AgentEventRecord>>;
52
+ /** Required at factory time; optional in the type so persistence unions stay assignable. */
53
+ appendSession?(record: SessionRecord): Promise<void>;
54
+ readonly lifecycle?: Pick<PersistenceLifecycleStore, "applyRetention">;
55
+ }
56
+ export interface ConversationSessionFactoryInput {
57
+ readonly thread: import("@arnilo/prism").ConversationThread;
58
+ readonly ownership: OwnershipScope;
59
+ /** Recorded branch leaf to continue from; undefined continues the session's current tip. */
60
+ readonly leafId?: string;
61
+ readonly signal?: AbortSignal;
62
+ }
63
+ export interface CreateConversationServiceOptions {
64
+ /** Binds an agent session to the thread (host owns agent, store, and leaf checkout). */
65
+ readonly sessionFactory: (input: ConversationSessionFactoryInput) => AgentSession | Promise<AgentSession>;
66
+ /** Required: replay/export only serve redacted ledger rows, and `continue` runs with this redactor. */
67
+ readonly redactor: SecretRedactor;
68
+ readonly runOptions?: Omit<RunOptions, "ownership" | "identity" | "signal" | "redactor" | "idempotencyKey">;
69
+ readonly limits?: ConversationLimits;
70
+ }
71
+ export interface ConversationServiceInput {
72
+ readonly ownership: OwnershipScope;
73
+ readonly identity?: AgentIdentity;
74
+ readonly signal?: AbortSignal;
75
+ }
76
+ export interface ConversationCreateInput extends ConversationServiceInput {
77
+ /** Explicit thread id makes create idempotent (get-or-create). Generated when omitted. */
78
+ readonly id?: string;
79
+ readonly title?: string;
80
+ readonly requestId?: string;
81
+ readonly metadata?: JsonObject;
82
+ }
83
+ export interface ConversationListInput extends ConversationServiceInput {
84
+ readonly cursor?: string;
85
+ readonly limit?: number;
86
+ }
87
+ export interface ConversationRefInput extends ConversationServiceInput {
88
+ readonly threadId: string;
89
+ }
90
+ export interface ConversationContinueInput extends ConversationRefInput {
91
+ readonly message: string | Message | readonly Message[];
92
+ /** Client request id; flows into session append idempotency so duplicate continues deduplicate. */
93
+ readonly requestId?: string;
94
+ /** Must be a branch ref recorded by `branch()`; undefined continues the current tip. */
95
+ readonly leafId?: string;
96
+ }
97
+ export interface ConversationBranchInput extends ConversationRefInput {
98
+ readonly leafId: string;
99
+ }
100
+ export interface ConversationExportInput extends ConversationRefInput {
101
+ readonly cursor?: string;
102
+ }
103
+ export interface ConversationReplayInput extends ConversationRefInput {
104
+ readonly cursor?: string;
105
+ readonly limit?: number;
106
+ }
107
+ export interface ConversationReplayPage {
108
+ readonly records: readonly AgentEventRecord[];
109
+ readonly nextCursor?: string;
110
+ readonly terminal: boolean;
111
+ }
112
+ export interface ConversationExportPage {
113
+ readonly thread: import("@arnilo/prism").ConversationThread;
114
+ readonly events: readonly AgentEventRecord[];
115
+ readonly nextCursor?: string;
116
+ readonly truncated: boolean;
117
+ }
118
+ export interface ConversationService {
119
+ create(input: ConversationCreateInput): Promise<import("@arnilo/prism").ConversationThread>;
120
+ list(input: ConversationListInput): Promise<PersistencePage<import("@arnilo/prism").ConversationThread>>;
121
+ get(input: ConversationRefInput): Promise<import("@arnilo/prism").ConversationThread>;
122
+ continue(input: ConversationContinueInput): Promise<AgentRunResult>;
123
+ branch(input: ConversationBranchInput): Promise<import("@arnilo/prism").ConversationThread>;
124
+ archive(input: ConversationRefInput): Promise<import("@arnilo/prism").ConversationThread>;
125
+ export(input: ConversationExportInput): Promise<ConversationExportPage>;
126
+ delete(input: ConversationRefInput): Promise<{
127
+ readonly deleted: boolean;
128
+ readonly held: boolean;
129
+ }>;
130
+ replay(input: ConversationReplayInput): Promise<ConversationReplayPage>;
131
+ }
132
+ export declare function createConversationService(store: ConversationServiceStore, options: CreateConversationServiceOptions): ConversationService;
133
+ export type ConversationOperation = "conversation.create" | "conversation.list" | "conversation.get" | "conversation.continue" | "conversation.branch" | "conversation.archive" | "conversation.export" | "conversation.delete" | "conversation.replay";
134
+ export interface ConversationAuthorizationInput {
135
+ readonly request: Request;
136
+ readonly operation: ConversationOperation;
137
+ readonly threadId?: string;
138
+ readonly signal: AbortSignal;
139
+ }
140
+ export type ConversationAuthorizer = (input: ConversationAuthorizationInput) => false | PrismServerAuthorization | Promise<false | PrismServerAuthorization>;
141
+ export interface CreateConversationHandlerOptions {
142
+ readonly service: ConversationService;
143
+ readonly authorize: ConversationAuthorizer;
144
+ readonly basePath?: string;
145
+ readonly redactor?: SecretRedactor;
146
+ readonly limits?: ConversationLimits;
147
+ }
148
+ /** Framework-free HTTP adapter for one mounted conversation service (default base `/prism/conversations`). */
149
+ export declare function createConversationHandler(options: CreateConversationHandlerOptions): PrismRequestHandler;