@qlairoslabs/acp-client 0.11.0 → 0.12.0
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.
- package/CHANGELOG-consumer-fixes.md +55 -0
- package/CHANGELOG-operation-lifecycle.md +64 -0
- package/CONSUMER_GUIDE.md +311 -17
- package/MIGRATION-0.10-to-0.12.md +189 -0
- package/README.md +6 -3
- package/package.json +5 -2
- package/src/adapters.ts +3 -1
- package/src/agent/adoption/checkpoint-floor.ts +47 -0
- package/src/agent/adoption/index.ts +3 -1
- package/src/agent/adoption/replay.ts +15 -0
- package/src/agent/config.ts +4 -0
- package/src/agent/conversation-manager.ts +223 -153
- package/src/agent/error-record-writer.ts +77 -0
- package/src/agent/persisted-lifecycle.ts +152 -35
- package/src/agent/record-capture.ts +18 -18
- package/src/agent-adapter-registry.ts +2 -0
- package/src/agent-client.ts +9 -3
- package/src/agent-conversation-contracts.ts +6 -0
- package/src/agent-conversation-owner.ts +31 -6
- package/src/agent-conversation-presentation.ts +12 -1
- package/src/agent-conversation-queue.ts +3 -2
- package/src/agent-session.ts +537 -96
- package/src/agent.ts +46 -23
- package/src/audit/config.ts +4 -0
- package/src/audit/projection.ts +3 -0
- package/src/checkpointing/contracts.ts +28 -3
- package/src/checkpointing/persistence/sqlite-repository.ts +36 -8
- package/src/checkpointing/recovery.ts +9 -2
- package/src/checkpointing/strategy.ts +27 -2
- package/src/client.ts +120 -30
- package/src/controller.ts +116 -7
- package/src/degraded/pty-client.ts +25 -1
- package/src/identity/checkpoint-backed.ts +2 -2
- package/src/index.ts +17 -0
- package/src/internal-inference/config.ts +7 -0
- package/src/internal-inference/contracts.ts +3 -0
- package/src/internal-inference/coordination/handles.ts +11 -2
- package/src/internal-inference/coordination/manager.ts +20 -3
- package/src/internal-inference/index.ts +2 -0
- package/src/internal-inference/persistence/records.ts +3 -1
- package/src/internal-inference/persistence/sqlite-repository.ts +4 -1
- package/src/internal-inference/runtime/disposable-session-env.ts +84 -0
- package/src/internal-inference/runtime/harness-runtime.ts +19 -2
- package/src/media/acp.ts +118 -0
- package/src/media/capture.ts +15 -0
- package/src/media/content.ts +142 -0
- package/src/media/files.ts +28 -0
- package/src/media/parts.ts +145 -0
- package/src/media/pending.ts +51 -0
- package/src/media/redact.ts +14 -0
- package/src/media/store.ts +127 -0
- package/src/metering/provider.ts +8 -1
- package/src/operations/activity-tracker.ts +31 -0
- package/src/operations/contracts.ts +63 -0
- package/src/operations/errors.ts +31 -0
- package/src/operations/index.ts +6 -0
- package/src/operations/stale-policy.ts +51 -0
- package/src/operations/supervisor.ts +209 -0
- package/src/operations/timers.ts +12 -0
- package/src/out-of-band-messages.ts +49 -32
- package/src/persistence/audit-runtime.ts +14 -2
- package/src/persistence/backend.ts +108 -12
- package/src/persistence/error-records.ts +27 -0
- package/src/persistence/index.ts +8 -0
- package/src/persistence/presentation.ts +9 -1
- package/src/persistence/projection.ts +20 -0
- package/src/persistence/records.ts +45 -6
- package/src/persistence/sqlite-backend.ts +207 -16
- package/src/persistence/sqlite-conversation-records.ts +31 -4
- package/src/persistence/sqlite-files.ts +95 -0
- package/src/persistence/sqlite-media-store.ts +67 -0
- package/src/persistence/sqlite-schema.ts +146 -13
- package/src/persistence/state-runtime.ts +2 -0
- package/src/persistence/timeline-reconcile.ts +21 -4
- package/src/persistence/transcript-reader.ts +11 -4
- package/src/persistence/transcript-runtime.ts +105 -12
- package/src/repl/repl.ts +1 -1
- package/src/response.ts +40 -8
- package/src/steering/combine.ts +11 -4
- package/src/steering/contracts.ts +14 -4
- package/src/steering/controller.ts +96 -21
- package/src/steering/index.ts +1 -0
- package/src/transport/acp-transport.ts +18 -7
- package/src/types.ts +7 -0
- package/src/updates.ts +4 -4
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { AgentConversationId, AgentSessionId } from "../agent-ids.ts";
|
|
2
|
+
import type { CancelOutcome, CancelReason } from "../operations/contracts.ts";
|
|
2
3
|
import type { OperationMeteringRecord } from "../metering/record.ts";
|
|
3
4
|
import type { AgentSessionMeteringState } from "../metering/state.ts";
|
|
4
5
|
import type { InternalInferenceRepository } from "../internal-inference/persistence/repository.ts";
|
|
5
6
|
import type { ConversationRecoveryCheckpointRepository } from "../checkpointing/contracts.ts";
|
|
7
|
+
import type { ConversationTimelineItem } from "./timeline-reconcile.ts";
|
|
8
|
+
import type { SharedFilesPersistence } from "../media/files.ts";
|
|
9
|
+
import type { MediaCaptureLevel } from "../media/capture.ts";
|
|
10
|
+
import type { MediaStore } from "../media/store.ts";
|
|
11
|
+
import type { MediaKind } from "../media/parts.ts";
|
|
12
|
+
import { contentText } from "../media/content.ts";
|
|
6
13
|
|
|
7
14
|
export type PersistenceJsonPrimitive = string | number | boolean | null;
|
|
8
15
|
export type PersistenceJsonValue =
|
|
@@ -34,6 +41,7 @@ export const CONVERSATION_RECORD_KINDS = [
|
|
|
34
41
|
"activity",
|
|
35
42
|
"metering",
|
|
36
43
|
"error",
|
|
44
|
+
"cancellation",
|
|
37
45
|
] as const;
|
|
38
46
|
|
|
39
47
|
export type ConversationRecordKind = (typeof CONVERSATION_RECORD_KINDS)[number];
|
|
@@ -47,11 +55,31 @@ export interface ConversationRecordEnvelope<K extends ConversationRecordKind = C
|
|
|
47
55
|
readonly kind: K;
|
|
48
56
|
/** ISO-8601 instant supplied by the producer and preserved verbatim. */
|
|
49
57
|
readonly timestamp: string;
|
|
50
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* The library operation the record was written in: a turn, an internal inference or recap, a
|
|
60
|
+
* setting change, a mode change, a handoff. Every record of one operation shares it. Absent on
|
|
61
|
+
* records written outside an operation (for example protocol lines while connecting).
|
|
62
|
+
*/
|
|
63
|
+
readonly operationId?: string;
|
|
64
|
+
/** Legacy envelope metadata. Older records carried the operation id here (`{"operationId": …}`). */
|
|
51
65
|
readonly metadata?: string;
|
|
52
66
|
}
|
|
53
67
|
|
|
68
|
+
export interface PersistedMediaBlock {
|
|
69
|
+
readonly type: "media";
|
|
70
|
+
readonly kind: MediaKind;
|
|
71
|
+
readonly mode: "copy" | "link";
|
|
72
|
+
readonly ref?: string;
|
|
73
|
+
readonly uri?: string;
|
|
74
|
+
readonly name?: string;
|
|
75
|
+
readonly mimeType: string;
|
|
76
|
+
readonly size?: number;
|
|
77
|
+
readonly sha256?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
54
80
|
export type PersistedContentBlock =
|
|
81
|
+
| PersistedMediaBlock
|
|
82
|
+
| { readonly type: "pasted"; readonly text: string; readonly name?: string }
|
|
55
83
|
| { readonly type: "text"; readonly text: string }
|
|
56
84
|
| {
|
|
57
85
|
readonly type: "image";
|
|
@@ -167,9 +195,12 @@ export type ConversationErrorRecoverability =
|
|
|
167
195
|
|
|
168
196
|
/** Allow-listed provider detail, retained only at raw capture. */
|
|
169
197
|
export interface ConversationErrorDetails {
|
|
198
|
+
readonly phase?: "no_response" | "incomplete_response";
|
|
170
199
|
readonly providerCode?: string | number;
|
|
171
200
|
readonly rpcCode?: number;
|
|
172
201
|
readonly service?: string;
|
|
202
|
+
/** The provider's name for the error class (OpenCode: `APIError`). A label, not a message. */
|
|
203
|
+
readonly errorName?: string;
|
|
173
204
|
readonly exitCode?: number;
|
|
174
205
|
readonly signal?: string;
|
|
175
206
|
readonly transportState?: string;
|
|
@@ -189,6 +220,21 @@ export interface ErrorRecord extends ConversationRecordEnvelope<"error"> {
|
|
|
189
220
|
readonly details?: ConversationErrorDetails;
|
|
190
221
|
}
|
|
191
222
|
|
|
223
|
+
/**
|
|
224
|
+
* A running operation was cancelled, whatever the mechanism (an ACP `session/cancel`, killing a
|
|
225
|
+
* screen-scraped harness). One cancellation has two revisions under its `cancellationId`:
|
|
226
|
+
* `requested` (when, and why) and `resolved` (how it ended). Its `operationId` is the cancelled
|
|
227
|
+
* operation's.
|
|
228
|
+
*/
|
|
229
|
+
export interface CancellationRecord extends ConversationRecordEnvelope<"cancellation"> {
|
|
230
|
+
readonly cancellationId: string;
|
|
231
|
+
readonly state: "requested" | "resolved";
|
|
232
|
+
/** `steer`: a message sent mid-turn; `interrupt`: Stop; `stalled`: the stale policy; `stop`: shutdown. */
|
|
233
|
+
readonly reason: CancelReason;
|
|
234
|
+
/** On `resolved` only. `too_late`: the operation finished on its own before the cancel took effect. */
|
|
235
|
+
readonly outcome?: CancelOutcome;
|
|
236
|
+
}
|
|
237
|
+
|
|
192
238
|
export type ConversationRecord =
|
|
193
239
|
| MessageRecord
|
|
194
240
|
| ToolCallRecord
|
|
@@ -200,7 +246,8 @@ export type ConversationRecord =
|
|
|
200
246
|
| ThinkingRecord
|
|
201
247
|
| ActivityRecord
|
|
202
248
|
| MeteringReferenceRecord
|
|
203
|
-
| ErrorRecord
|
|
249
|
+
| ErrorRecord
|
|
250
|
+
| CancellationRecord;
|
|
204
251
|
|
|
205
252
|
type WithoutSequence<T> = T extends ConversationRecord ? Omit<T, "sequence"> : never;
|
|
206
253
|
export type NewConversationRecord = WithoutSequence<ConversationRecord>;
|
|
@@ -219,6 +266,7 @@ type NonProtocolRecordKind = Exclude<ConversationRecordKind, "protocol">;
|
|
|
219
266
|
export type ConversationRecordCaptureConfig = Readonly<
|
|
220
267
|
Partial<Record<NonProtocolRecordKind, RecordCaptureLevel>> & {
|
|
221
268
|
readonly protocol?: ProtocolRecordCapture;
|
|
269
|
+
readonly media?: MediaCaptureLevel;
|
|
222
270
|
}
|
|
223
271
|
>;
|
|
224
272
|
export type ResolvedProtocolRecordCapturePolicy = Readonly<{
|
|
@@ -229,6 +277,7 @@ export type ResolvedProtocolRecordCapturePolicy = Readonly<{
|
|
|
229
277
|
export type ConversationRecordCapturePolicy = Readonly<
|
|
230
278
|
Record<NonProtocolRecordKind, RecordCaptureLevel> & {
|
|
231
279
|
readonly protocol: ResolvedProtocolRecordCapturePolicy;
|
|
280
|
+
readonly media: MediaCaptureLevel;
|
|
232
281
|
}
|
|
233
282
|
>;
|
|
234
283
|
|
|
@@ -240,6 +289,7 @@ const DEFAULT_PROTOCOL_RECORD_CAPTURE: ResolvedProtocolRecordCapturePolicy = Obj
|
|
|
240
289
|
|
|
241
290
|
export const DEFAULT_CONVERSATION_RECORD_CAPTURE: ConversationRecordCapturePolicy = Object.freeze({
|
|
242
291
|
message: "content",
|
|
292
|
+
media: "content",
|
|
243
293
|
tool_call: "metadata",
|
|
244
294
|
permission: "metadata",
|
|
245
295
|
configuration: "metadata",
|
|
@@ -250,6 +300,7 @@ export const DEFAULT_CONVERSATION_RECORD_CAPTURE: ConversationRecordCapturePolic
|
|
|
250
300
|
activity: "metadata",
|
|
251
301
|
metering: "metadata",
|
|
252
302
|
error: "content",
|
|
303
|
+
cancellation: "metadata",
|
|
253
304
|
});
|
|
254
305
|
|
|
255
306
|
export interface AgentPersistenceIdentity {
|
|
@@ -320,6 +371,8 @@ export interface ConversationPreviewPage {
|
|
|
320
371
|
|
|
321
372
|
export interface RecordListOptions {
|
|
322
373
|
readonly kinds?: readonly ConversationRecordKind[];
|
|
374
|
+
/** Only the records of this operation (a turn's `operationId`, for example). */
|
|
375
|
+
readonly operationId?: string;
|
|
323
376
|
readonly afterSequence?: number;
|
|
324
377
|
readonly throughSequence?: number;
|
|
325
378
|
readonly limit?: number;
|
|
@@ -334,14 +387,47 @@ export interface ConversationRecordPage {
|
|
|
334
387
|
/** Newest matching records at a fixed conversation-sequence snapshot, oldest-first within each page. */
|
|
335
388
|
export interface RecentRecordPageOptions {
|
|
336
389
|
readonly kinds?: readonly ConversationRecordKind[];
|
|
390
|
+
/**
|
|
391
|
+
* Without `agentMessages`, the records per page (default 50, at most 500). With it, the most a
|
|
392
|
+
* page holds (records, or items when folded; default 2000, at most 10000): a page that reaches it
|
|
393
|
+
* ends early with `truncated`.
|
|
394
|
+
*/
|
|
337
395
|
readonly limit?: number;
|
|
338
396
|
readonly olderCursor?: string;
|
|
397
|
+
/**
|
|
398
|
+
* Page by agent messages: each page holds this many agent messages and the activity that led to
|
|
399
|
+
* each. A record goes to the page where its item's first revision falls, so a page holds every
|
|
400
|
+
* revision of its items and none of another page's.
|
|
401
|
+
*/
|
|
402
|
+
readonly agentMessages?: number;
|
|
403
|
+
/** `summary` leaves out tool calls' input and output; `records.get(recordId)` returns them. */
|
|
404
|
+
readonly detail?: "full" | "summary";
|
|
405
|
+
/** `true` returns timeline items instead of records. */
|
|
406
|
+
readonly fold?: false;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface RecentItemPageOptions extends Omit<RecentRecordPageOptions, "fold"> {
|
|
410
|
+
readonly fold: true;
|
|
339
411
|
}
|
|
340
412
|
|
|
341
413
|
export interface RecentRecordPage {
|
|
342
414
|
readonly records: readonly ConversationRecord[];
|
|
343
415
|
readonly snapshotSequence: number;
|
|
344
416
|
readonly olderCursor?: string;
|
|
417
|
+
/** The page reached `limit` before its last agent message; the next page continues from there. */
|
|
418
|
+
readonly truncated?: true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Recent history as timeline items, merged as `reconcileConversationTimeline` does. With
|
|
423
|
+
* `detail: "summary"` an item keeps two revisions, its first and its merged current, so it still
|
|
424
|
+
* reconciles with later records.
|
|
425
|
+
*/
|
|
426
|
+
export interface RecentItemPage {
|
|
427
|
+
readonly items: readonly ConversationTimelineItem[];
|
|
428
|
+
readonly snapshotSequence: number;
|
|
429
|
+
readonly olderCursor?: string;
|
|
430
|
+
readonly truncated?: true;
|
|
345
431
|
}
|
|
346
432
|
|
|
347
433
|
export interface MessageListOptions {
|
|
@@ -524,6 +610,10 @@ export interface ConversationRecordPersistence {
|
|
|
524
610
|
*/
|
|
525
611
|
deleteForConversation?(agentConversationId: AgentConversationId): Promise<number>;
|
|
526
612
|
/** Optional efficient newest-first history API. Use list(afterSequence) for live catch-up. */
|
|
613
|
+
listRecent?(
|
|
614
|
+
agentConversationId: AgentConversationId,
|
|
615
|
+
options: RecentItemPageOptions,
|
|
616
|
+
): Promise<RecentItemPage>;
|
|
527
617
|
listRecent?(
|
|
528
618
|
agentConversationId: AgentConversationId,
|
|
529
619
|
options?: RecentRecordPageOptions,
|
|
@@ -681,7 +771,15 @@ export interface PersistenceCapabilities {
|
|
|
681
771
|
readonly metering: boolean;
|
|
682
772
|
}
|
|
683
773
|
|
|
774
|
+
export interface OutOfBandDeliveryPersistence {
|
|
775
|
+
get(owner: AgentConversationId, providerContext: string): Promise<number>;
|
|
776
|
+
advance(owner: AgentConversationId, providerContext: string, throughSequence: number): Promise<void>;
|
|
777
|
+
}
|
|
778
|
+
|
|
684
779
|
export interface PersistenceScope {
|
|
780
|
+
readonly files?: SharedFilesPersistence;
|
|
781
|
+
readonly outOfBandDelivery?: OutOfBandDeliveryPersistence;
|
|
782
|
+
readonly media?: MediaStore;
|
|
685
783
|
readonly conversations: ConversationPersistence;
|
|
686
784
|
readonly records: ConversationRecordPersistence;
|
|
687
785
|
readonly messages: ConversationMessagePersistence;
|
|
@@ -783,6 +881,13 @@ export function resolveConversationRecordCapture(
|
|
|
783
881
|
): ConversationRecordCapturePolicy {
|
|
784
882
|
const resolved: Record<string, unknown> = { ...DEFAULT_CONVERSATION_RECORD_CAPTURE };
|
|
785
883
|
for (const [kind, value] of Object.entries(override)) {
|
|
884
|
+
if (kind === "media") {
|
|
885
|
+
if (!["none", "metadata", "content"].includes(String(value))) {
|
|
886
|
+
throw new Error(`invalid media capture level: ${String(value)}`);
|
|
887
|
+
}
|
|
888
|
+
resolved.media = value;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
786
891
|
if (!isConversationRecordKind(kind)) throw new Error(`unknown record capture kind: ${kind}`);
|
|
787
892
|
if (kind === "protocol") {
|
|
788
893
|
resolved.protocol = resolveProtocolRecordCapture(value as ProtocolRecordCapture);
|
|
@@ -883,20 +988,11 @@ export function searchableText(record: ConversationRecord): string {
|
|
|
883
988
|
case "error":
|
|
884
989
|
// Errors are operational history, not searchable conversation content; v1 keeps them
|
|
885
990
|
// out of full-text search.
|
|
991
|
+
case "cancellation":
|
|
886
992
|
return "";
|
|
887
993
|
}
|
|
888
994
|
}
|
|
889
995
|
|
|
890
|
-
function contentText(content: PersistedContent | undefined): string {
|
|
891
|
-
if (typeof content === "string") return content;
|
|
892
|
-
if (!content) return "";
|
|
893
|
-
return content.map((block) => {
|
|
894
|
-
if (block.type === "text") return block.text;
|
|
895
|
-
if (block.type === "image") return block.alt ?? "";
|
|
896
|
-
if (block.type === "resource") return [block.title, block.text, block.uri].filter(Boolean).join("\n");
|
|
897
|
-
return jsonText(block.value);
|
|
898
|
-
}).filter(Boolean).join("\n");
|
|
899
|
-
}
|
|
900
996
|
|
|
901
997
|
function jsonText(value: PersistenceJsonValue | undefined): string {
|
|
902
998
|
return value === undefined ? "" : JSON.stringify(value);
|
|
@@ -13,6 +13,7 @@ export const CONVERSATION_ERROR_CODES = Object.freeze([
|
|
|
13
13
|
"connection_lost",
|
|
14
14
|
"prompt_interrupted",
|
|
15
15
|
"recovery_failed",
|
|
16
|
+
"stalled",
|
|
16
17
|
"unknown",
|
|
17
18
|
] as const);
|
|
18
19
|
|
|
@@ -52,9 +53,11 @@ export function sanitizeConversationErrorMessage(value: unknown): string | undef
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export interface ConversationErrorDetailInput {
|
|
56
|
+
readonly phase?: unknown;
|
|
55
57
|
readonly providerCode?: unknown;
|
|
56
58
|
readonly rpcCode?: unknown;
|
|
57
59
|
readonly service?: unknown;
|
|
60
|
+
readonly errorName?: unknown;
|
|
58
61
|
readonly exitCode?: unknown;
|
|
59
62
|
readonly signal?: unknown;
|
|
60
63
|
readonly transportState?: unknown;
|
|
@@ -73,13 +76,16 @@ export function buildConversationErrorDetails(
|
|
|
73
76
|
const providerCode = allowCode(input.providerCode);
|
|
74
77
|
const rpcCode = allowInteger(input.rpcCode);
|
|
75
78
|
const service = allowLabel(input.service);
|
|
79
|
+
const errorName = allowLabel(input.errorName);
|
|
76
80
|
const exitCode = allowInteger(input.exitCode);
|
|
77
81
|
const signal = allowLabel(input.signal);
|
|
78
82
|
const transportState = allowLabel(input.transportState);
|
|
79
83
|
const details: ConversationErrorDetails = Object.freeze({
|
|
84
|
+
...(input.phase === "no_response" || input.phase === "incomplete_response" ? { phase: input.phase } : {}),
|
|
80
85
|
...(providerCode === undefined ? {} : { providerCode }),
|
|
81
86
|
...(rpcCode === undefined ? {} : { rpcCode }),
|
|
82
87
|
...(service === undefined ? {} : { service }),
|
|
88
|
+
...(errorName === undefined ? {} : { errorName }),
|
|
83
89
|
...(exitCode === undefined ? {} : { exitCode }),
|
|
84
90
|
...(signal === undefined ? {} : { signal }),
|
|
85
91
|
...(transportState === undefined ? {} : { transportState }),
|
|
@@ -102,3 +108,24 @@ function allowLabel(value: unknown): string | undefined {
|
|
|
102
108
|
if (!trimmed) return undefined;
|
|
103
109
|
return trimmed.slice(0, MAX_ERROR_DETAIL_CHARS);
|
|
104
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Allow-listed machine-readable detail from a thrown ACP error, when it exposes any: the JSON-RPC code
|
|
114
|
+
* (standard, so the same for every harness, if coarse) and, from `data`, the labels harnesses are known to
|
|
115
|
+
* send. `data` itself is never copied; see `buildConversationErrorDetails`.
|
|
116
|
+
*/
|
|
117
|
+
export function conversationErrorDetailsFromError(error: unknown): ConversationErrorDetails | undefined {
|
|
118
|
+
const value = typeof error === "object" && error !== null
|
|
119
|
+
? error as { code?: unknown; data?: unknown }
|
|
120
|
+
: null;
|
|
121
|
+
const data = typeof value?.data === "object" && value.data !== null
|
|
122
|
+
? value.data as Record<string, unknown>
|
|
123
|
+
: undefined;
|
|
124
|
+
return buildConversationErrorDetails({
|
|
125
|
+
rpcCode: typeof value?.code === "number" ? value.code : undefined,
|
|
126
|
+
phase: data?.phase,
|
|
127
|
+
service: data?.service,
|
|
128
|
+
errorName: data?.errorName,
|
|
129
|
+
providerCode: data?.providerCode,
|
|
130
|
+
});
|
|
131
|
+
}
|
package/src/persistence/index.ts
CHANGED
|
@@ -73,6 +73,8 @@ export type {
|
|
|
73
73
|
ParticipantRef,
|
|
74
74
|
PersistedContent,
|
|
75
75
|
PersistedContentBlock,
|
|
76
|
+
PersistedMediaBlock,
|
|
77
|
+
OutOfBandDeliveryPersistence,
|
|
76
78
|
PersistedIdentitySnapshot,
|
|
77
79
|
PersistedAgentMeteringState,
|
|
78
80
|
PersistedConversationMeteringState,
|
|
@@ -91,6 +93,8 @@ export type {
|
|
|
91
93
|
ProviderSessionRecord,
|
|
92
94
|
RecordCaptureLevel,
|
|
93
95
|
RecordListOptions,
|
|
96
|
+
RecentItemPage,
|
|
97
|
+
RecentItemPageOptions,
|
|
94
98
|
RecentRecordPage,
|
|
95
99
|
RecentRecordPageOptions,
|
|
96
100
|
SearchMatch,
|
|
@@ -111,3 +115,7 @@ export {
|
|
|
111
115
|
} from "./sqlite-backend.ts";
|
|
112
116
|
export type { SqliteAgentPersistenceConfig } from "./sqlite-backend.ts";
|
|
113
117
|
export { SQLITE_AGENT_SCHEMA_VERSION } from "./sqlite-schema.ts";
|
|
118
|
+
|
|
119
|
+
export type { MediaStore, MediaInfo, StoredMedia } from "../media/store.ts";
|
|
120
|
+
|
|
121
|
+
export type { SharedFile, SharedFilePage, SharedFileQuery, SharedFilesPersistence } from "../media/files.ts";
|
|
@@ -19,7 +19,11 @@ interface TranscriptPresentationItemBase {
|
|
|
19
19
|
readonly revision: number;
|
|
20
20
|
/** Physical transcript sequence containing this revision. */
|
|
21
21
|
readonly recordSequence: number;
|
|
22
|
-
/** Unix epoch milliseconds
|
|
22
|
+
/** Unix epoch milliseconds when the item's first revision was written: when it began. */
|
|
23
|
+
readonly startedAt: number;
|
|
24
|
+
/** Unix epoch milliseconds when this revision, the item's latest, was written. */
|
|
25
|
+
readonly updatedAt: number;
|
|
26
|
+
/** @deprecated The same value as `updatedAt`; show `startedAt` as the item's time. */
|
|
23
27
|
readonly timestamp: number;
|
|
24
28
|
readonly operationId: string;
|
|
25
29
|
readonly transcriptId: string;
|
|
@@ -56,8 +60,10 @@ export type TranscriptPresentationItem =
|
|
|
56
60
|
| TranscriptPresentationReasoning
|
|
57
61
|
| TranscriptPresentationActivity;
|
|
58
62
|
|
|
63
|
+
/** `startedAt` is the first revision's time; it defaults to this record's, right for a first revision. */
|
|
59
64
|
export function presentationItemFromRecord(
|
|
60
65
|
record: TranscriptPresentationRecord,
|
|
66
|
+
startedAt: number = record.ts,
|
|
61
67
|
): TranscriptPresentationItem | null {
|
|
62
68
|
const presentation = record.presentation;
|
|
63
69
|
if (!presentation) return null;
|
|
@@ -66,6 +72,8 @@ export function presentationItemFromRecord(
|
|
|
66
72
|
position: presentation.position,
|
|
67
73
|
revision: presentation.revision,
|
|
68
74
|
recordSequence: record.seq,
|
|
75
|
+
startedAt,
|
|
76
|
+
updatedAt: record.ts,
|
|
69
77
|
timestamp: record.ts,
|
|
70
78
|
operationId: record.operationId,
|
|
71
79
|
transcriptId: record.transcriptId,
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
TranscriptEnvelope,
|
|
22
22
|
TranscriptLifecycleRecord,
|
|
23
23
|
TranscriptTransitionRecord,
|
|
24
|
+
TranscriptCancellationRecord,
|
|
24
25
|
TranscriptPresentationMetadata,
|
|
25
26
|
InternalSessionDescriptor,
|
|
26
27
|
InternalSessionHistoryEntry,
|
|
@@ -124,6 +125,14 @@ export type NormalizedPersistenceEvent =
|
|
|
124
125
|
readonly outcome?: string;
|
|
125
126
|
readonly fullDetails?: JsonValue;
|
|
126
127
|
}
|
|
128
|
+
| {
|
|
129
|
+
readonly kind: "cancellation";
|
|
130
|
+
readonly operationId: string;
|
|
131
|
+
readonly cancellationId: string;
|
|
132
|
+
readonly event: "requested" | "resolved";
|
|
133
|
+
readonly reason: TranscriptCancellationRecord["reason"];
|
|
134
|
+
readonly outcome?: TranscriptCancellationRecord["outcome"];
|
|
135
|
+
}
|
|
127
136
|
| {
|
|
128
137
|
readonly kind: "transition";
|
|
129
138
|
readonly transitionId: string;
|
|
@@ -205,6 +214,11 @@ export function projectTranscriptEvent(
|
|
|
205
214
|
const projected = configurationData(event, context.policy.configuration);
|
|
206
215
|
return projected ? { ...base, t: "configuration", ...projected } : null;
|
|
207
216
|
}
|
|
217
|
+
case "cancellation":
|
|
218
|
+
return {
|
|
219
|
+
...base, t: "cancellation", operationId: event.operationId, cancellationId: event.cancellationId,
|
|
220
|
+
event: event.event, reason: event.reason, ...(event.outcome === undefined ? {} : { outcome: event.outcome }),
|
|
221
|
+
};
|
|
208
222
|
case "permission": {
|
|
209
223
|
if (context.policy.permissions === "none") return null;
|
|
210
224
|
return {
|
|
@@ -259,6 +273,12 @@ export function projectAuditEvent(
|
|
|
259
273
|
case "protocol_metadata":
|
|
260
274
|
case "raw_protocol":
|
|
261
275
|
return null;
|
|
276
|
+
case "cancellation":
|
|
277
|
+
return {
|
|
278
|
+
...base, t: "cancellation", operationId: event.operationId, cancellationId: event.cancellationId,
|
|
279
|
+
event: event.event, reason: event.reason,
|
|
280
|
+
...(event.outcome === undefined ? {} : { outcome: event.outcome }),
|
|
281
|
+
};
|
|
262
282
|
case "reasoning":
|
|
263
283
|
if (context.policy.reasoning === "none") return null;
|
|
264
284
|
return { ...base, t: "reasoning", reasoningId: event.reasoningId, reasoningRevision: event.reasoningRevision, operationId: event.operationId, text: event.text, status: event.status };
|
|
@@ -20,6 +20,12 @@ import {
|
|
|
20
20
|
type SessionConfigurationCheckpoint,
|
|
21
21
|
type TransitionKind,
|
|
22
22
|
} from "./checkpoint.ts";
|
|
23
|
+
import {
|
|
24
|
+
CANCEL_OUTCOMES,
|
|
25
|
+
CANCEL_REASONS,
|
|
26
|
+
type CancelOutcome,
|
|
27
|
+
type CancelReason,
|
|
28
|
+
} from "../operations/contracts.ts";
|
|
23
29
|
import {
|
|
24
30
|
canonicalizeJson,
|
|
25
31
|
isPersistedMachineCode,
|
|
@@ -107,7 +113,8 @@ export type TranscriptRecordType =
|
|
|
107
113
|
| "metering_reference"
|
|
108
114
|
| "lifecycle"
|
|
109
115
|
| "protocol"
|
|
110
|
-
| "raw"
|
|
116
|
+
| "raw"
|
|
117
|
+
| "cancellation";
|
|
111
118
|
|
|
112
119
|
export interface TranscriptEnvelope {
|
|
113
120
|
readonly v: 2;
|
|
@@ -220,6 +227,16 @@ export interface TranscriptPermissionRecord extends TranscriptEnvelope {
|
|
|
220
227
|
readonly details?: JsonValue;
|
|
221
228
|
}
|
|
222
229
|
|
|
230
|
+
/** A running operation was cancelled: `requested` (why), then `resolved` (how it ended). */
|
|
231
|
+
export interface TranscriptCancellationRecord extends TranscriptEnvelope {
|
|
232
|
+
readonly t: "cancellation";
|
|
233
|
+
readonly operationId: string;
|
|
234
|
+
readonly cancellationId: string;
|
|
235
|
+
readonly event: "requested" | "resolved";
|
|
236
|
+
readonly reason: CancelReason;
|
|
237
|
+
readonly outcome?: CancelOutcome;
|
|
238
|
+
}
|
|
239
|
+
|
|
223
240
|
export interface TranscriptTransitionRecord extends TranscriptEnvelope {
|
|
224
241
|
readonly t: "transition";
|
|
225
242
|
readonly transitionId: string;
|
|
@@ -290,7 +307,8 @@ export type KnownTranscriptRecord =
|
|
|
290
307
|
| TranscriptMeteringReferenceRecord
|
|
291
308
|
| TranscriptLifecycleRecord
|
|
292
309
|
| TranscriptProtocolMetadataRecord
|
|
293
|
-
| TranscriptRawRecord
|
|
310
|
+
| TranscriptRawRecord
|
|
311
|
+
| TranscriptCancellationRecord;
|
|
294
312
|
|
|
295
313
|
export interface UnknownTranscriptRecord {
|
|
296
314
|
readonly v: number;
|
|
@@ -312,7 +330,8 @@ export type AuditLogRecordType =
|
|
|
312
330
|
| "permission"
|
|
313
331
|
| "transition"
|
|
314
332
|
| "metering_reference"
|
|
315
|
-
| "lifecycle"
|
|
333
|
+
| "lifecycle"
|
|
334
|
+
| "cancellation";
|
|
316
335
|
|
|
317
336
|
export interface AuditLogEnvelope {
|
|
318
337
|
readonly v: 1;
|
|
@@ -411,6 +430,16 @@ export interface AuditLogLifecycleRecord extends AuditLogEnvelope {
|
|
|
411
430
|
readonly detail?: JsonValue;
|
|
412
431
|
}
|
|
413
432
|
|
|
433
|
+
/** The audit copy of a transcript cancellation record. */
|
|
434
|
+
export interface AuditLogCancellationRecord extends AuditLogEnvelope {
|
|
435
|
+
readonly t: "cancellation";
|
|
436
|
+
readonly operationId: string;
|
|
437
|
+
readonly cancellationId: string;
|
|
438
|
+
readonly event: "requested" | "resolved";
|
|
439
|
+
readonly reason: CancelReason;
|
|
440
|
+
readonly outcome?: CancelOutcome;
|
|
441
|
+
}
|
|
442
|
+
|
|
414
443
|
export type KnownAuditLogRecord =
|
|
415
444
|
| AuditLogHeaderRecord
|
|
416
445
|
| AuditLogOperationRecord
|
|
@@ -420,7 +449,8 @@ export type KnownAuditLogRecord =
|
|
|
420
449
|
| AuditLogPermissionRecord
|
|
421
450
|
| AuditLogTransitionRecord
|
|
422
451
|
| AuditLogMeteringReferenceRecord
|
|
423
|
-
| AuditLogLifecycleRecord
|
|
452
|
+
| AuditLogLifecycleRecord
|
|
453
|
+
| AuditLogCancellationRecord;
|
|
424
454
|
|
|
425
455
|
export interface UnknownAuditLogRecord {
|
|
426
456
|
readonly v: number;
|
|
@@ -471,11 +501,11 @@ export function validateAuditLogRecord(
|
|
|
471
501
|
const TRANSCRIPT_TYPES = new Set<string>([
|
|
472
502
|
"header", "checkpoint", "operation", "message", "reasoning", "activity",
|
|
473
503
|
"configuration", "permission", "transition", "metering_reference", "lifecycle",
|
|
474
|
-
"protocol", "raw",
|
|
504
|
+
"protocol", "raw", "cancellation",
|
|
475
505
|
]);
|
|
476
506
|
const AUDIT_TYPES = new Set<string>([
|
|
477
507
|
"header", "operation", "reasoning", "activity", "configuration", "permission",
|
|
478
|
-
"transition", "metering_reference", "lifecycle",
|
|
508
|
+
"transition", "metering_reference", "lifecycle", "cancellation",
|
|
479
509
|
]);
|
|
480
510
|
|
|
481
511
|
function validateEnvelope(
|
|
@@ -577,6 +607,15 @@ function validateRecognizedRecord(
|
|
|
577
607
|
case "transition":
|
|
578
608
|
validateTransition(record, sink);
|
|
579
609
|
return;
|
|
610
|
+
case "cancellation":
|
|
611
|
+
requiredOperationId(record);
|
|
612
|
+
nonblank(record.cancellationId, "cancellationId");
|
|
613
|
+
oneOf(record.event, ["requested", "resolved"], "cancellation.event");
|
|
614
|
+
oneOf(record.reason, CANCEL_REASONS, "cancellation.reason");
|
|
615
|
+
if (record.outcome !== undefined) {
|
|
616
|
+
oneOf(record.outcome, CANCEL_OUTCOMES, "cancellation.outcome");
|
|
617
|
+
}
|
|
618
|
+
return;
|
|
580
619
|
case "metering_reference":
|
|
581
620
|
requiredOperationId(record);
|
|
582
621
|
nonblank(record.meteringRecordId, "meteringRecordId");
|