@sorbetai/context 0.0.0-stage → 0.1.0-alpha.17

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,3129 @@
1
+ import * as s from "@earendil-works/pi-schema";
2
+ import * as _sorbetai_schema35 from "@sorbetai/schema";
3
+ import { JsonValue, JsonValueSchema } from "@sorbetai/schema";
4
+
5
+ //#region src/xml.d.ts
6
+ /** Valid XML element and attribute name for state, event and extension vocabulary. */
7
+ declare const NamedStateNameSchema: s.Schema<string>;
8
+ /** A model-visible XML fragment. Names come from trusted producers, never from parsed input. */
9
+ type ContextXmlElement = {
10
+ kind: 'text';
11
+ name: string;
12
+ attributes?: Record<string, string | number>;
13
+ text: string;
14
+ } | {
15
+ kind: 'container';
16
+ name: string;
17
+ attributes?: Record<string, string | number>;
18
+ children: ContextXmlElement[];
19
+ };
20
+ declare const ContextXmlElementSchema: s.Schema<ContextXmlElement>;
21
+ //#endregion
22
+ //#region src/tools/contracts.d.ts
23
+ /** The model-visible declaration; execution bindings remain owned by Runtime. */
24
+ interface ToolDeclaration {
25
+ name: string;
26
+ description: string;
27
+ parameters: object;
28
+ }
29
+ declare const ToolDeclarationSchema: s.Schema<ToolDeclaration>;
30
+ declare const ToolStateSnapshotSchema: s.Schema<{
31
+ revision: number;
32
+ definitions: ToolDeclaration[];
33
+ delivery: {
34
+ kind: "unchanged";
35
+ } | {
36
+ kind: "restoration";
37
+ afterMessageCount: 0;
38
+ } | {
39
+ kind: "transition";
40
+ afterMessageCount: number;
41
+ added: string[];
42
+ removed: string[];
43
+ };
44
+ }>;
45
+ type ToolStateSnapshot = s.Static<typeof ToolStateSnapshotSchema>;
46
+ //#endregion
47
+ //#region src/snapshot/contracts.d.ts
48
+ declare const CONTEXT_SNAPSHOT_SCHEMA_VERSION = 1;
49
+ declare const CONTEXT_ASSEMBLER_VERSION = "sorbet-context-assembler-v1";
50
+ declare const CONTEXT_RENDERER_VERSION = "sorbet-context-renderer-v4";
51
+ declare const ContextAssemblyEvidenceSchema: s.Schema<{
52
+ assemblerVersion: "sorbet-context-assembler-v1";
53
+ rendererVersion: "sorbet-context-renderer-v4" | "sorbet-context-renderer-v1" | "sorbet-context-renderer-v2" | "sorbet-context-renderer-v3";
54
+ }>;
55
+ declare const NamedStateDeliverySchema: s.Schema<{
56
+ kind: "restoration";
57
+ afterMessageCount: 0;
58
+ } | {
59
+ kind: "transition";
60
+ afterMessageCount: number;
61
+ previousRevision?: number | undefined;
62
+ } | {
63
+ kind: "unchanged";
64
+ }>;
65
+ declare const NamedStateSnapshotSchema: s.Schema<{
66
+ present: true;
67
+ value: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null;
68
+ stateName: string;
69
+ revision: number;
70
+ delivery: {
71
+ kind: "restoration";
72
+ afterMessageCount: 0;
73
+ } | {
74
+ kind: "transition";
75
+ afterMessageCount: number;
76
+ previousRevision?: number | undefined;
77
+ } | {
78
+ kind: "unchanged";
79
+ };
80
+ itemKey?: string | undefined;
81
+ } | {
82
+ present: false;
83
+ stateName: string;
84
+ revision: number;
85
+ delivery: {
86
+ kind: "restoration";
87
+ afterMessageCount: 0;
88
+ } | {
89
+ kind: "transition";
90
+ afterMessageCount: number;
91
+ previousRevision?: number | undefined;
92
+ } | {
93
+ kind: "unchanged";
94
+ };
95
+ itemKey?: string | undefined;
96
+ }>;
97
+ declare const PrefixSnapshotSchema: s.Schema<{
98
+ revision: number;
99
+ inheritedSources: ({
100
+ lifecycle: "session";
101
+ kind: "instructions";
102
+ channel: "system" | "developer" | "agents";
103
+ content: string;
104
+ sourceId: string;
105
+ provenance: {
106
+ origin: "file" | "runtime" | "host" | "journal";
107
+ label: string;
108
+ location?: string | undefined;
109
+ };
110
+ } | {
111
+ lifecycle: "session";
112
+ kind: "extension";
113
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
114
+ name: string;
115
+ content: string;
116
+ sourceId: string;
117
+ provenance: {
118
+ origin: "file" | "runtime" | "host" | "journal";
119
+ label: string;
120
+ location?: string | undefined;
121
+ };
122
+ } | {
123
+ lifecycle: "session";
124
+ kind: "workspace";
125
+ root: string;
126
+ sourceId: string;
127
+ provenance: {
128
+ origin: "file" | "runtime" | "host" | "journal";
129
+ label: string;
130
+ location?: string | undefined;
131
+ };
132
+ })[];
133
+ sources: ({
134
+ lifecycle: "session";
135
+ kind: "instructions";
136
+ channel: "system" | "developer" | "agents";
137
+ content: string;
138
+ sourceId: string;
139
+ provenance: {
140
+ origin: "file" | "runtime" | "host" | "journal";
141
+ label: string;
142
+ location?: string | undefined;
143
+ };
144
+ } | {
145
+ lifecycle: "session";
146
+ kind: "extension";
147
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
148
+ name: string;
149
+ content: string;
150
+ sourceId: string;
151
+ provenance: {
152
+ origin: "file" | "runtime" | "host" | "journal";
153
+ label: string;
154
+ location?: string | undefined;
155
+ };
156
+ } | {
157
+ lifecycle: "session";
158
+ kind: "workspace";
159
+ root: string;
160
+ sourceId: string;
161
+ provenance: {
162
+ origin: "file" | "runtime" | "host" | "journal";
163
+ label: string;
164
+ location?: string | undefined;
165
+ };
166
+ })[];
167
+ systemPrompt: string;
168
+ }>;
169
+ declare const TurnMaterialSnapshotSchema: s.Schema<{
170
+ scopeId: string;
171
+ sources: ({
172
+ lifecycle: "turn";
173
+ kind: "instructions";
174
+ channel: "developer" | "agents";
175
+ content: string;
176
+ sourceId: string;
177
+ provenance: {
178
+ origin: "file" | "runtime" | "host" | "journal";
179
+ label: string;
180
+ location?: string | undefined;
181
+ };
182
+ } | {
183
+ lifecycle: "turn";
184
+ kind: "extension";
185
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
186
+ name: string;
187
+ content: string;
188
+ sourceId: string;
189
+ provenance: {
190
+ origin: "file" | "runtime" | "host" | "journal";
191
+ label: string;
192
+ location?: string | undefined;
193
+ };
194
+ } | {
195
+ lifecycle: "turn";
196
+ kind: "document";
197
+ name: string;
198
+ mediaType: string;
199
+ content: string;
200
+ sourceId: string;
201
+ provenance: {
202
+ origin: "file" | "runtime" | "host" | "journal";
203
+ label: string;
204
+ location?: string | undefined;
205
+ };
206
+ } | {
207
+ lifecycle: "turn";
208
+ kind: "event";
209
+ event: {
210
+ kind: "text";
211
+ name: string;
212
+ attributes?: Record<string, string | number>;
213
+ text: string;
214
+ } | {
215
+ kind: "container";
216
+ name: string;
217
+ attributes?: Record<string, string | number>;
218
+ children: ContextXmlElement[];
219
+ };
220
+ sourceId: string;
221
+ provenance: {
222
+ origin: "file" | "runtime" | "host" | "journal";
223
+ label: string;
224
+ location?: string | undefined;
225
+ };
226
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
227
+ })[];
228
+ delivery: {
229
+ kind: "append";
230
+ afterMessageCount: number;
231
+ } | {
232
+ kind: "unchanged";
233
+ };
234
+ }>;
235
+ declare const RequestMaterialSnapshotSchema: s.Schema<{
236
+ scopeId: string;
237
+ sources: {
238
+ content: string;
239
+ retention: "request" | "epoch";
240
+ sourceId: string;
241
+ provenance: {
242
+ origin: "file" | "runtime" | "host" | "journal";
243
+ label: string;
244
+ location?: string | undefined;
245
+ };
246
+ placement?: "before-conversation" | undefined;
247
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
248
+ }[];
249
+ afterMessageCount: number;
250
+ modelView?: {
251
+ throughSequence: number;
252
+ history: {
253
+ runId: string;
254
+ messageId: string;
255
+ }[];
256
+ reclaimBefore?: {
257
+ runId: string;
258
+ messageId: string;
259
+ } | undefined;
260
+ stateOrigins?: {
261
+ stateName: string;
262
+ revision: number;
263
+ }[] | undefined;
264
+ } | undefined;
265
+ replacementConversation?: ({
266
+ role: "system";
267
+ content: string | {
268
+ type: "text";
269
+ text: string;
270
+ textSignature?: string | undefined;
271
+ }[];
272
+ timestamp: number;
273
+ sections?: Record<string, string | null> | undefined;
274
+ toolsAdded?: ToolDeclaration[] | undefined;
275
+ toolsRemoved?: {
276
+ name: string;
277
+ }[] | undefined;
278
+ } | {
279
+ role: "user";
280
+ content: string | ({
281
+ type: "text";
282
+ text: string;
283
+ textSignature?: string | undefined;
284
+ } | {
285
+ type: "image";
286
+ data: string;
287
+ mimeType: string;
288
+ })[];
289
+ timestamp: number;
290
+ } | {
291
+ role: "assistant";
292
+ content: ({
293
+ type: "text";
294
+ text: string;
295
+ textSignature?: string | undefined;
296
+ } | {
297
+ type: "thinking";
298
+ thinking: string;
299
+ thinkingSignature?: string | undefined;
300
+ redacted?: boolean | undefined;
301
+ } | {
302
+ type: "toolCall";
303
+ id: string;
304
+ name: string;
305
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
306
+ thoughtSignature?: string | undefined;
307
+ argumentsError?: string | undefined;
308
+ })[];
309
+ api: string;
310
+ provider: string;
311
+ model: string;
312
+ usage: {
313
+ input: number;
314
+ output: number;
315
+ cacheRead: number;
316
+ cacheWrite: number;
317
+ totalTokens: number;
318
+ cost: {
319
+ input: number;
320
+ output: number;
321
+ cacheRead: number;
322
+ cacheWrite: number;
323
+ total: number;
324
+ totalFromProvider?: boolean | undefined;
325
+ };
326
+ cacheWrite1h?: number | undefined;
327
+ reasoning?: number | undefined;
328
+ };
329
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
330
+ timestamp: number;
331
+ responseModel?: string | undefined;
332
+ responseId?: string | undefined;
333
+ diagnostics?: {
334
+ type: string;
335
+ timestamp: number;
336
+ error?: {
337
+ message: string;
338
+ name?: string | undefined;
339
+ stack?: string | undefined;
340
+ code?: string | number | undefined;
341
+ } | undefined;
342
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
343
+ }[] | undefined;
344
+ deferred?: {
345
+ provider: string;
346
+ modelId: string;
347
+ api: string;
348
+ id: string;
349
+ expiresAt?: number | undefined;
350
+ pollAfterMs?: number | undefined;
351
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
352
+ } | undefined;
353
+ errorMessage?: string | undefined;
354
+ rawStopReason?: string | undefined;
355
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
356
+ providerThinkingLevel?: string | undefined;
357
+ endTurn?: boolean | undefined;
358
+ durationMs?: number | undefined;
359
+ } | {
360
+ role: "toolResult";
361
+ toolCallId: string;
362
+ toolName: string;
363
+ content: ({
364
+ type: "text";
365
+ text: string;
366
+ textSignature?: string | undefined;
367
+ } | {
368
+ type: "image";
369
+ data: string;
370
+ mimeType: string;
371
+ })[];
372
+ isError: boolean;
373
+ timestamp: number;
374
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
375
+ usage?: {
376
+ input: number;
377
+ output: number;
378
+ cacheRead: number;
379
+ cacheWrite: number;
380
+ totalTokens: number;
381
+ cost: {
382
+ input: number;
383
+ output: number;
384
+ cacheRead: number;
385
+ cacheWrite: number;
386
+ total: number;
387
+ totalFromProvider?: boolean | undefined;
388
+ };
389
+ cacheWrite1h?: number | undefined;
390
+ reasoning?: number | undefined;
391
+ } | undefined;
392
+ durationMs?: number | undefined;
393
+ })[] | undefined;
394
+ }>;
395
+ type RequestMaterialSnapshot = s.Static<typeof RequestMaterialSnapshotSchema>;
396
+ declare const CompileContextInputSchema: s.Schema<{
397
+ contextEpoch: number;
398
+ prefixRevision: number;
399
+ inheritedSources: ({
400
+ lifecycle: "session";
401
+ kind: "instructions";
402
+ channel: "system" | "developer" | "agents";
403
+ content: string;
404
+ sourceId: string;
405
+ provenance: {
406
+ origin: "file" | "runtime" | "host" | "journal";
407
+ label: string;
408
+ location?: string | undefined;
409
+ };
410
+ } | {
411
+ lifecycle: "session";
412
+ kind: "extension";
413
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
414
+ name: string;
415
+ content: string;
416
+ sourceId: string;
417
+ provenance: {
418
+ origin: "file" | "runtime" | "host" | "journal";
419
+ label: string;
420
+ location?: string | undefined;
421
+ };
422
+ } | {
423
+ lifecycle: "session";
424
+ kind: "workspace";
425
+ root: string;
426
+ sourceId: string;
427
+ provenance: {
428
+ origin: "file" | "runtime" | "host" | "journal";
429
+ label: string;
430
+ location?: string | undefined;
431
+ };
432
+ })[];
433
+ prefixSources: ({
434
+ lifecycle: "session";
435
+ kind: "instructions";
436
+ channel: "system" | "developer" | "agents";
437
+ content: string;
438
+ sourceId: string;
439
+ provenance: {
440
+ origin: "file" | "runtime" | "host" | "journal";
441
+ label: string;
442
+ location?: string | undefined;
443
+ };
444
+ } | {
445
+ lifecycle: "session";
446
+ kind: "extension";
447
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
448
+ name: string;
449
+ content: string;
450
+ sourceId: string;
451
+ provenance: {
452
+ origin: "file" | "runtime" | "host" | "journal";
453
+ label: string;
454
+ location?: string | undefined;
455
+ };
456
+ } | {
457
+ lifecycle: "session";
458
+ kind: "workspace";
459
+ root: string;
460
+ sourceId: string;
461
+ provenance: {
462
+ origin: "file" | "runtime" | "host" | "journal";
463
+ label: string;
464
+ location?: string | undefined;
465
+ };
466
+ })[];
467
+ namedStates: ({
468
+ present: true;
469
+ value: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null;
470
+ stateName: string;
471
+ revision: number;
472
+ delivery: {
473
+ kind: "restoration";
474
+ afterMessageCount: 0;
475
+ } | {
476
+ kind: "transition";
477
+ afterMessageCount: number;
478
+ previousRevision?: number | undefined;
479
+ } | {
480
+ kind: "unchanged";
481
+ };
482
+ itemKey?: string | undefined;
483
+ } | {
484
+ present: false;
485
+ stateName: string;
486
+ revision: number;
487
+ delivery: {
488
+ kind: "restoration";
489
+ afterMessageCount: 0;
490
+ } | {
491
+ kind: "transition";
492
+ afterMessageCount: number;
493
+ previousRevision?: number | undefined;
494
+ } | {
495
+ kind: "unchanged";
496
+ };
497
+ itemKey?: string | undefined;
498
+ })[];
499
+ turnMaterial: {
500
+ scopeId: string;
501
+ sources: ({
502
+ lifecycle: "turn";
503
+ kind: "instructions";
504
+ channel: "developer" | "agents";
505
+ content: string;
506
+ sourceId: string;
507
+ provenance: {
508
+ origin: "file" | "runtime" | "host" | "journal";
509
+ label: string;
510
+ location?: string | undefined;
511
+ };
512
+ } | {
513
+ lifecycle: "turn";
514
+ kind: "extension";
515
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
516
+ name: string;
517
+ content: string;
518
+ sourceId: string;
519
+ provenance: {
520
+ origin: "file" | "runtime" | "host" | "journal";
521
+ label: string;
522
+ location?: string | undefined;
523
+ };
524
+ } | {
525
+ lifecycle: "turn";
526
+ kind: "document";
527
+ name: string;
528
+ mediaType: string;
529
+ content: string;
530
+ sourceId: string;
531
+ provenance: {
532
+ origin: "file" | "runtime" | "host" | "journal";
533
+ label: string;
534
+ location?: string | undefined;
535
+ };
536
+ } | {
537
+ lifecycle: "turn";
538
+ kind: "event";
539
+ event: {
540
+ kind: "text";
541
+ name: string;
542
+ attributes?: Record<string, string | number>;
543
+ text: string;
544
+ } | {
545
+ kind: "container";
546
+ name: string;
547
+ attributes?: Record<string, string | number>;
548
+ children: ContextXmlElement[];
549
+ };
550
+ sourceId: string;
551
+ provenance: {
552
+ origin: "file" | "runtime" | "host" | "journal";
553
+ label: string;
554
+ location?: string | undefined;
555
+ };
556
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
557
+ })[];
558
+ delivery: {
559
+ kind: "append";
560
+ afterMessageCount: number;
561
+ } | {
562
+ kind: "unchanged";
563
+ };
564
+ };
565
+ tools?: {
566
+ revision: number;
567
+ definitions: ToolDeclaration[];
568
+ delivery: {
569
+ kind: "unchanged";
570
+ } | {
571
+ kind: "restoration";
572
+ afterMessageCount: 0;
573
+ } | {
574
+ kind: "transition";
575
+ afterMessageCount: number;
576
+ added: string[];
577
+ removed: string[];
578
+ };
579
+ } | undefined;
580
+ requestMaterial?: {
581
+ scopeId: string;
582
+ sources: {
583
+ content: string;
584
+ retention: "request" | "epoch";
585
+ sourceId: string;
586
+ provenance: {
587
+ origin: "file" | "runtime" | "host" | "journal";
588
+ label: string;
589
+ location?: string | undefined;
590
+ };
591
+ placement?: "before-conversation" | undefined;
592
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
593
+ }[];
594
+ afterMessageCount: number;
595
+ modelView?: {
596
+ throughSequence: number;
597
+ history: {
598
+ runId: string;
599
+ messageId: string;
600
+ }[];
601
+ reclaimBefore?: {
602
+ runId: string;
603
+ messageId: string;
604
+ } | undefined;
605
+ stateOrigins?: {
606
+ stateName: string;
607
+ revision: number;
608
+ }[] | undefined;
609
+ } | undefined;
610
+ replacementConversation?: ({
611
+ role: "system";
612
+ content: string | {
613
+ type: "text";
614
+ text: string;
615
+ textSignature?: string | undefined;
616
+ }[];
617
+ timestamp: number;
618
+ sections?: Record<string, string | null> | undefined;
619
+ toolsAdded?: ToolDeclaration[] | undefined;
620
+ toolsRemoved?: {
621
+ name: string;
622
+ }[] | undefined;
623
+ } | {
624
+ role: "user";
625
+ content: string | ({
626
+ type: "text";
627
+ text: string;
628
+ textSignature?: string | undefined;
629
+ } | {
630
+ type: "image";
631
+ data: string;
632
+ mimeType: string;
633
+ })[];
634
+ timestamp: number;
635
+ } | {
636
+ role: "assistant";
637
+ content: ({
638
+ type: "text";
639
+ text: string;
640
+ textSignature?: string | undefined;
641
+ } | {
642
+ type: "thinking";
643
+ thinking: string;
644
+ thinkingSignature?: string | undefined;
645
+ redacted?: boolean | undefined;
646
+ } | {
647
+ type: "toolCall";
648
+ id: string;
649
+ name: string;
650
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
651
+ thoughtSignature?: string | undefined;
652
+ argumentsError?: string | undefined;
653
+ })[];
654
+ api: string;
655
+ provider: string;
656
+ model: string;
657
+ usage: {
658
+ input: number;
659
+ output: number;
660
+ cacheRead: number;
661
+ cacheWrite: number;
662
+ totalTokens: number;
663
+ cost: {
664
+ input: number;
665
+ output: number;
666
+ cacheRead: number;
667
+ cacheWrite: number;
668
+ total: number;
669
+ totalFromProvider?: boolean | undefined;
670
+ };
671
+ cacheWrite1h?: number | undefined;
672
+ reasoning?: number | undefined;
673
+ };
674
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
675
+ timestamp: number;
676
+ responseModel?: string | undefined;
677
+ responseId?: string | undefined;
678
+ diagnostics?: {
679
+ type: string;
680
+ timestamp: number;
681
+ error?: {
682
+ message: string;
683
+ name?: string | undefined;
684
+ stack?: string | undefined;
685
+ code?: string | number | undefined;
686
+ } | undefined;
687
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
688
+ }[] | undefined;
689
+ deferred?: {
690
+ provider: string;
691
+ modelId: string;
692
+ api: string;
693
+ id: string;
694
+ expiresAt?: number | undefined;
695
+ pollAfterMs?: number | undefined;
696
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
697
+ } | undefined;
698
+ errorMessage?: string | undefined;
699
+ rawStopReason?: string | undefined;
700
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
701
+ providerThinkingLevel?: string | undefined;
702
+ endTurn?: boolean | undefined;
703
+ durationMs?: number | undefined;
704
+ } | {
705
+ role: "toolResult";
706
+ toolCallId: string;
707
+ toolName: string;
708
+ content: ({
709
+ type: "text";
710
+ text: string;
711
+ textSignature?: string | undefined;
712
+ } | {
713
+ type: "image";
714
+ data: string;
715
+ mimeType: string;
716
+ })[];
717
+ isError: boolean;
718
+ timestamp: number;
719
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
720
+ usage?: {
721
+ input: number;
722
+ output: number;
723
+ cacheRead: number;
724
+ cacheWrite: number;
725
+ totalTokens: number;
726
+ cost: {
727
+ input: number;
728
+ output: number;
729
+ cacheRead: number;
730
+ cacheWrite: number;
731
+ total: number;
732
+ totalFromProvider?: boolean | undefined;
733
+ };
734
+ cacheWrite1h?: number | undefined;
735
+ reasoning?: number | undefined;
736
+ } | undefined;
737
+ durationMs?: number | undefined;
738
+ })[] | undefined;
739
+ } | undefined;
740
+ }>;
741
+ /** Exact Context-owner evidence captured for one logical model call. */
742
+ declare const ContextSnapshotSchema: s.Schema<{
743
+ schemaVersion: 1;
744
+ preparedAt: string;
745
+ contextEpoch: number;
746
+ prefix: {
747
+ revision: number;
748
+ inheritedSources: ({
749
+ lifecycle: "session";
750
+ kind: "instructions";
751
+ channel: "system" | "developer" | "agents";
752
+ content: string;
753
+ sourceId: string;
754
+ provenance: {
755
+ origin: "file" | "runtime" | "host" | "journal";
756
+ label: string;
757
+ location?: string | undefined;
758
+ };
759
+ } | {
760
+ lifecycle: "session";
761
+ kind: "extension";
762
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
763
+ name: string;
764
+ content: string;
765
+ sourceId: string;
766
+ provenance: {
767
+ origin: "file" | "runtime" | "host" | "journal";
768
+ label: string;
769
+ location?: string | undefined;
770
+ };
771
+ } | {
772
+ lifecycle: "session";
773
+ kind: "workspace";
774
+ root: string;
775
+ sourceId: string;
776
+ provenance: {
777
+ origin: "file" | "runtime" | "host" | "journal";
778
+ label: string;
779
+ location?: string | undefined;
780
+ };
781
+ })[];
782
+ sources: ({
783
+ lifecycle: "session";
784
+ kind: "instructions";
785
+ channel: "system" | "developer" | "agents";
786
+ content: string;
787
+ sourceId: string;
788
+ provenance: {
789
+ origin: "file" | "runtime" | "host" | "journal";
790
+ label: string;
791
+ location?: string | undefined;
792
+ };
793
+ } | {
794
+ lifecycle: "session";
795
+ kind: "extension";
796
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
797
+ name: string;
798
+ content: string;
799
+ sourceId: string;
800
+ provenance: {
801
+ origin: "file" | "runtime" | "host" | "journal";
802
+ label: string;
803
+ location?: string | undefined;
804
+ };
805
+ } | {
806
+ lifecycle: "session";
807
+ kind: "workspace";
808
+ root: string;
809
+ sourceId: string;
810
+ provenance: {
811
+ origin: "file" | "runtime" | "host" | "journal";
812
+ label: string;
813
+ location?: string | undefined;
814
+ };
815
+ })[];
816
+ systemPrompt: string;
817
+ };
818
+ namedStates: ({
819
+ present: true;
820
+ value: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null;
821
+ stateName: string;
822
+ revision: number;
823
+ delivery: {
824
+ kind: "restoration";
825
+ afterMessageCount: 0;
826
+ } | {
827
+ kind: "transition";
828
+ afterMessageCount: number;
829
+ previousRevision?: number | undefined;
830
+ } | {
831
+ kind: "unchanged";
832
+ };
833
+ itemKey?: string | undefined;
834
+ } | {
835
+ present: false;
836
+ stateName: string;
837
+ revision: number;
838
+ delivery: {
839
+ kind: "restoration";
840
+ afterMessageCount: 0;
841
+ } | {
842
+ kind: "transition";
843
+ afterMessageCount: number;
844
+ previousRevision?: number | undefined;
845
+ } | {
846
+ kind: "unchanged";
847
+ };
848
+ itemKey?: string | undefined;
849
+ })[];
850
+ turnMaterial: {
851
+ scopeId: string;
852
+ sources: ({
853
+ lifecycle: "turn";
854
+ kind: "instructions";
855
+ channel: "developer" | "agents";
856
+ content: string;
857
+ sourceId: string;
858
+ provenance: {
859
+ origin: "file" | "runtime" | "host" | "journal";
860
+ label: string;
861
+ location?: string | undefined;
862
+ };
863
+ } | {
864
+ lifecycle: "turn";
865
+ kind: "extension";
866
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
867
+ name: string;
868
+ content: string;
869
+ sourceId: string;
870
+ provenance: {
871
+ origin: "file" | "runtime" | "host" | "journal";
872
+ label: string;
873
+ location?: string | undefined;
874
+ };
875
+ } | {
876
+ lifecycle: "turn";
877
+ kind: "document";
878
+ name: string;
879
+ mediaType: string;
880
+ content: string;
881
+ sourceId: string;
882
+ provenance: {
883
+ origin: "file" | "runtime" | "host" | "journal";
884
+ label: string;
885
+ location?: string | undefined;
886
+ };
887
+ } | {
888
+ lifecycle: "turn";
889
+ kind: "event";
890
+ event: {
891
+ kind: "text";
892
+ name: string;
893
+ attributes?: Record<string, string | number>;
894
+ text: string;
895
+ } | {
896
+ kind: "container";
897
+ name: string;
898
+ attributes?: Record<string, string | number>;
899
+ children: ContextXmlElement[];
900
+ };
901
+ sourceId: string;
902
+ provenance: {
903
+ origin: "file" | "runtime" | "host" | "journal";
904
+ label: string;
905
+ location?: string | undefined;
906
+ };
907
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
908
+ })[];
909
+ delivery: {
910
+ kind: "append";
911
+ afterMessageCount: number;
912
+ } | {
913
+ kind: "unchanged";
914
+ };
915
+ };
916
+ modelInput: {
917
+ systemPrompt: string;
918
+ stateMessages: {
919
+ role: "user";
920
+ content: string;
921
+ }[];
922
+ turnMessages: {
923
+ role: "user";
924
+ content: string;
925
+ }[];
926
+ requestMessages?: {
927
+ role: "user";
928
+ content: string;
929
+ }[] | undefined;
930
+ };
931
+ evidence: {
932
+ assemblerVersion: "sorbet-context-assembler-v1";
933
+ rendererVersion: "sorbet-context-renderer-v4" | "sorbet-context-renderer-v1" | "sorbet-context-renderer-v2" | "sorbet-context-renderer-v3";
934
+ };
935
+ tools?: {
936
+ revision: number;
937
+ definitions: ToolDeclaration[];
938
+ delivery: {
939
+ kind: "unchanged";
940
+ } | {
941
+ kind: "restoration";
942
+ afterMessageCount: 0;
943
+ } | {
944
+ kind: "transition";
945
+ afterMessageCount: number;
946
+ added: string[];
947
+ removed: string[];
948
+ };
949
+ } | undefined;
950
+ requestMaterial?: {
951
+ scopeId: string;
952
+ sources: {
953
+ content: string;
954
+ retention: "request" | "epoch";
955
+ sourceId: string;
956
+ provenance: {
957
+ origin: "file" | "runtime" | "host" | "journal";
958
+ label: string;
959
+ location?: string | undefined;
960
+ };
961
+ placement?: "before-conversation" | undefined;
962
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
963
+ }[];
964
+ afterMessageCount: number;
965
+ modelView?: {
966
+ throughSequence: number;
967
+ history: {
968
+ runId: string;
969
+ messageId: string;
970
+ }[];
971
+ reclaimBefore?: {
972
+ runId: string;
973
+ messageId: string;
974
+ } | undefined;
975
+ stateOrigins?: {
976
+ stateName: string;
977
+ revision: number;
978
+ }[] | undefined;
979
+ } | undefined;
980
+ replacementConversation?: ({
981
+ role: "system";
982
+ content: string | {
983
+ type: "text";
984
+ text: string;
985
+ textSignature?: string | undefined;
986
+ }[];
987
+ timestamp: number;
988
+ sections?: Record<string, string | null> | undefined;
989
+ toolsAdded?: ToolDeclaration[] | undefined;
990
+ toolsRemoved?: {
991
+ name: string;
992
+ }[] | undefined;
993
+ } | {
994
+ role: "user";
995
+ content: string | ({
996
+ type: "text";
997
+ text: string;
998
+ textSignature?: string | undefined;
999
+ } | {
1000
+ type: "image";
1001
+ data: string;
1002
+ mimeType: string;
1003
+ })[];
1004
+ timestamp: number;
1005
+ } | {
1006
+ role: "assistant";
1007
+ content: ({
1008
+ type: "text";
1009
+ text: string;
1010
+ textSignature?: string | undefined;
1011
+ } | {
1012
+ type: "thinking";
1013
+ thinking: string;
1014
+ thinkingSignature?: string | undefined;
1015
+ redacted?: boolean | undefined;
1016
+ } | {
1017
+ type: "toolCall";
1018
+ id: string;
1019
+ name: string;
1020
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
1021
+ thoughtSignature?: string | undefined;
1022
+ argumentsError?: string | undefined;
1023
+ })[];
1024
+ api: string;
1025
+ provider: string;
1026
+ model: string;
1027
+ usage: {
1028
+ input: number;
1029
+ output: number;
1030
+ cacheRead: number;
1031
+ cacheWrite: number;
1032
+ totalTokens: number;
1033
+ cost: {
1034
+ input: number;
1035
+ output: number;
1036
+ cacheRead: number;
1037
+ cacheWrite: number;
1038
+ total: number;
1039
+ totalFromProvider?: boolean | undefined;
1040
+ };
1041
+ cacheWrite1h?: number | undefined;
1042
+ reasoning?: number | undefined;
1043
+ };
1044
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
1045
+ timestamp: number;
1046
+ responseModel?: string | undefined;
1047
+ responseId?: string | undefined;
1048
+ diagnostics?: {
1049
+ type: string;
1050
+ timestamp: number;
1051
+ error?: {
1052
+ message: string;
1053
+ name?: string | undefined;
1054
+ stack?: string | undefined;
1055
+ code?: string | number | undefined;
1056
+ } | undefined;
1057
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
1058
+ }[] | undefined;
1059
+ deferred?: {
1060
+ provider: string;
1061
+ modelId: string;
1062
+ api: string;
1063
+ id: string;
1064
+ expiresAt?: number | undefined;
1065
+ pollAfterMs?: number | undefined;
1066
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1067
+ } | undefined;
1068
+ errorMessage?: string | undefined;
1069
+ rawStopReason?: string | undefined;
1070
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
1071
+ providerThinkingLevel?: string | undefined;
1072
+ endTurn?: boolean | undefined;
1073
+ durationMs?: number | undefined;
1074
+ } | {
1075
+ role: "toolResult";
1076
+ toolCallId: string;
1077
+ toolName: string;
1078
+ content: ({
1079
+ type: "text";
1080
+ text: string;
1081
+ textSignature?: string | undefined;
1082
+ } | {
1083
+ type: "image";
1084
+ data: string;
1085
+ mimeType: string;
1086
+ })[];
1087
+ isError: boolean;
1088
+ timestamp: number;
1089
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1090
+ usage?: {
1091
+ input: number;
1092
+ output: number;
1093
+ cacheRead: number;
1094
+ cacheWrite: number;
1095
+ totalTokens: number;
1096
+ cost: {
1097
+ input: number;
1098
+ output: number;
1099
+ cacheRead: number;
1100
+ cacheWrite: number;
1101
+ total: number;
1102
+ totalFromProvider?: boolean | undefined;
1103
+ };
1104
+ cacheWrite1h?: number | undefined;
1105
+ reasoning?: number | undefined;
1106
+ } | undefined;
1107
+ durationMs?: number | undefined;
1108
+ })[] | undefined;
1109
+ } | undefined;
1110
+ }>;
1111
+ type ContextAssemblyEvidence = s.Static<typeof ContextAssemblyEvidenceSchema>;
1112
+ type NamedStateDelivery = s.Static<typeof NamedStateDeliverySchema>;
1113
+ type NamedStateSnapshot = s.Static<typeof NamedStateSnapshotSchema>;
1114
+ type PrefixSnapshot = s.Static<typeof PrefixSnapshotSchema>;
1115
+ type TurnMaterialSnapshot = s.Static<typeof TurnMaterialSnapshotSchema>;
1116
+ type CompileContextInput = s.Static<typeof CompileContextInputSchema>;
1117
+ type ContextSnapshot = s.Static<typeof ContextSnapshotSchema>;
1118
+ //#endregion
1119
+ //#region src/compiler.d.ts
1120
+ interface ContextCompilerOptions {
1121
+ readonly now?: () => Date;
1122
+ }
1123
+ interface CompileContextOptions {
1124
+ readonly previousPrefix?: ContextSnapshot['prefix'];
1125
+ /** Owner-rendered element for every state that emits a frame in this request. */
1126
+ readonly elements?: ReadonlyMap<string, ContextXmlElement>;
1127
+ }
1128
+ /** Turns typed owner values into immutable request evidence without assigning revisions. */
1129
+ declare class ContextCompiler {
1130
+ #private;
1131
+ constructor(options?: ContextCompilerOptions);
1132
+ compile(parsed: CompileContextInput, options?: CompileContextOptions): ContextSnapshot;
1133
+ }
1134
+ //#endregion
1135
+ //#region src/state/contracts.d.ts
1136
+ declare const NamedStateReadResultSchema: s.Schema<{
1137
+ present: true;
1138
+ value: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null;
1139
+ element: {
1140
+ kind: "text";
1141
+ name: string;
1142
+ attributes?: Record<string, string | number>;
1143
+ text: string;
1144
+ } | {
1145
+ kind: "container";
1146
+ name: string;
1147
+ attributes?: Record<string, string | number>;
1148
+ children: ContextXmlElement[];
1149
+ };
1150
+ } | {
1151
+ present: false;
1152
+ }>;
1153
+ interface NamedStateReadInput {
1154
+ readonly signal?: AbortSignal;
1155
+ }
1156
+ /**
1157
+ * Supplies the complete current value and the element the model reads. ContextManager owns
1158
+ * revisions, delivery timing and XML serialization; it never guesses how a value should look.
1159
+ */
1160
+ interface NamedStateOwner<Name extends string = string, Schema extends s.Schema = s.Schema> {
1161
+ readonly stateName: Name;
1162
+ readonly schema: Schema;
1163
+ /**
1164
+ * The schema validates and revisions compare `value`. `element` is the complete current frame
1165
+ * body, named after the state, with attributes, text or children chosen by the owner.
1166
+ */
1167
+ read(input: NamedStateReadInput): Promise<{
1168
+ readonly present: true;
1169
+ readonly value: s.Static<Schema>;
1170
+ readonly element: ContextXmlElement;
1171
+ } | {
1172
+ readonly present: false;
1173
+ }>;
1174
+ }
1175
+ /**
1176
+ * Captures an owned JSON representation with `JSON.stringify` field semantics. Owner,
1177
+ * Hook and Tool values cross this boundary before schema validation, so callers receive
1178
+ * a copy instead of retaining author state.
1179
+ */
1180
+ declare function captureJsonValue(input: unknown): JsonValue;
1181
+ /** Read-only JSON view for projections that must not mutate recorded evidence. */
1182
+ type ReadonlyJsonValue = string | number | boolean | null | readonly ReadonlyJsonValue[] | {
1183
+ readonly [key: string]: ReadonlyJsonValue;
1184
+ };
1185
+ type NamedStateReadResult = s.Static<typeof NamedStateReadResultSchema>;
1186
+ //#endregion
1187
+ //#region src/history.d.ts
1188
+ declare const ContextMessageReferenceProperties: {
1189
+ runId: s.Schema<string>;
1190
+ messageId: s.Schema<string>;
1191
+ };
1192
+ declare const ContextMessageReferenceSchema: s.Schema<{
1193
+ runId: string;
1194
+ messageId: string;
1195
+ }>;
1196
+ interface ContextHistoryMessage {
1197
+ readonly reference: Readonly<s.Static<typeof ContextMessageReferenceSchema>>;
1198
+ /** Canonical evidence may be an Effect/Run terminal when no transcript result was committed. */
1199
+ readonly sourceFactId?: string;
1200
+ readonly role: 'user' | 'assistant' | 'toolResult';
1201
+ readonly text?: string;
1202
+ readonly message: ReadonlyJsonValue;
1203
+ }
1204
+ interface ContextHistoryUnit {
1205
+ readonly unitId: string;
1206
+ readonly messages: readonly ContextHistoryMessage[];
1207
+ }
1208
+ interface ContextHistorySnapshot {
1209
+ readonly throughSequence: number;
1210
+ readonly units: readonly ContextHistoryUnit[];
1211
+ /** Completed active prefix, including consumed user inputs; the latest assistant and later inputs stay protected. */
1212
+ readonly active?: {
1213
+ readonly units: readonly ContextHistoryUnit[];
1214
+ readonly reclaimBefore: Readonly<s.Static<typeof ContextMessageReferenceSchema>>;
1215
+ };
1216
+ }
1217
+ interface ContextHistorySelectionScope {
1218
+ readonly sessionId: string;
1219
+ readonly runId: string;
1220
+ readonly requestScopeId: string;
1221
+ }
1222
+ /** Filters the previous selector's complete units; preparation Hooks may replace the resulting view. */
1223
+ type ContextHistorySelector = (input: Readonly<ContextHistorySelectionScope & {
1224
+ history: ContextHistorySnapshot;
1225
+ signal: AbortSignal;
1226
+ }>) => readonly ContextHistoryUnit[] | Promise<readonly ContextHistoryUnit[]>;
1227
+ //#endregion
1228
+ //#region src/model-view.d.ts
1229
+ /** Experimental chronological history selection; the consumer retains the active execution. */
1230
+ declare const ContextModelViewSchema: s.Schema<{
1231
+ throughSequence: number;
1232
+ history: {
1233
+ runId: string;
1234
+ messageId: string;
1235
+ }[];
1236
+ reclaimBefore?: {
1237
+ runId: string;
1238
+ messageId: string;
1239
+ } | undefined;
1240
+ stateOrigins?: {
1241
+ stateName: string;
1242
+ revision: number;
1243
+ }[] | undefined;
1244
+ }>;
1245
+ type ContextModelView = s.Static<typeof ContextModelViewSchema>;
1246
+ //#endregion
1247
+ //#region src/preparation.d.ts
1248
+ declare const DraftSchema: s.Schema<{
1249
+ sources: ({
1250
+ lifecycle: "session";
1251
+ kind: "instructions";
1252
+ channel: "system" | "developer" | "agents";
1253
+ content: string;
1254
+ sourceId: string;
1255
+ provenance: {
1256
+ origin: "file" | "runtime" | "host" | "journal";
1257
+ label: string;
1258
+ location?: string | undefined;
1259
+ };
1260
+ } | {
1261
+ lifecycle: "session";
1262
+ kind: "extension";
1263
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
1264
+ name: string;
1265
+ content: string;
1266
+ sourceId: string;
1267
+ provenance: {
1268
+ origin: "file" | "runtime" | "host" | "journal";
1269
+ label: string;
1270
+ location?: string | undefined;
1271
+ };
1272
+ } | {
1273
+ lifecycle: "session";
1274
+ kind: "workspace";
1275
+ root: string;
1276
+ sourceId: string;
1277
+ provenance: {
1278
+ origin: "file" | "runtime" | "host" | "journal";
1279
+ label: string;
1280
+ location?: string | undefined;
1281
+ };
1282
+ } | {
1283
+ lifecycle: "turn";
1284
+ kind: "instructions";
1285
+ channel: "developer" | "agents";
1286
+ content: string;
1287
+ sourceId: string;
1288
+ provenance: {
1289
+ origin: "file" | "runtime" | "host" | "journal";
1290
+ label: string;
1291
+ location?: string | undefined;
1292
+ };
1293
+ } | {
1294
+ lifecycle: "turn";
1295
+ kind: "extension";
1296
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
1297
+ name: string;
1298
+ content: string;
1299
+ sourceId: string;
1300
+ provenance: {
1301
+ origin: "file" | "runtime" | "host" | "journal";
1302
+ label: string;
1303
+ location?: string | undefined;
1304
+ };
1305
+ } | {
1306
+ lifecycle: "turn";
1307
+ kind: "document";
1308
+ name: string;
1309
+ mediaType: string;
1310
+ content: string;
1311
+ sourceId: string;
1312
+ provenance: {
1313
+ origin: "file" | "runtime" | "host" | "journal";
1314
+ label: string;
1315
+ location?: string | undefined;
1316
+ };
1317
+ } | {
1318
+ lifecycle: "turn";
1319
+ kind: "event";
1320
+ event: {
1321
+ kind: "text";
1322
+ name: string;
1323
+ attributes?: Record<string, string | number>;
1324
+ text: string;
1325
+ } | {
1326
+ kind: "container";
1327
+ name: string;
1328
+ attributes?: Record<string, string | number>;
1329
+ children: ContextXmlElement[];
1330
+ };
1331
+ sourceId: string;
1332
+ provenance: {
1333
+ origin: "file" | "runtime" | "host" | "journal";
1334
+ label: string;
1335
+ location?: string | undefined;
1336
+ };
1337
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1338
+ })[];
1339
+ requestSources: {
1340
+ content: string;
1341
+ retention: "request" | "epoch";
1342
+ sourceId: string;
1343
+ provenance: {
1344
+ origin: "file" | "runtime" | "host" | "journal";
1345
+ label: string;
1346
+ location?: string | undefined;
1347
+ };
1348
+ placement?: "before-conversation" | undefined;
1349
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1350
+ }[];
1351
+ states: {
1352
+ stateName: string;
1353
+ state: {
1354
+ present: true;
1355
+ value: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null;
1356
+ element: {
1357
+ kind: "text";
1358
+ name: string;
1359
+ attributes?: Record<string, string | number>;
1360
+ text: string;
1361
+ } | {
1362
+ kind: "container";
1363
+ name: string;
1364
+ attributes?: Record<string, string | number>;
1365
+ children: ContextXmlElement[];
1366
+ };
1367
+ } | {
1368
+ present: false;
1369
+ };
1370
+ }[];
1371
+ modelView?: {
1372
+ throughSequence: number;
1373
+ history: {
1374
+ runId: string;
1375
+ messageId: string;
1376
+ }[];
1377
+ reclaimBefore?: {
1378
+ runId: string;
1379
+ messageId: string;
1380
+ } | undefined;
1381
+ stateOrigins?: {
1382
+ stateName: string;
1383
+ revision: number;
1384
+ }[] | undefined;
1385
+ } | undefined;
1386
+ toolNames?: string[] | undefined;
1387
+ conversation?: ({
1388
+ role: "system";
1389
+ content: string | {
1390
+ type: "text";
1391
+ text: string;
1392
+ textSignature?: string | undefined;
1393
+ }[];
1394
+ timestamp: number;
1395
+ sections?: Record<string, string | null> | undefined;
1396
+ toolsAdded?: ToolDeclaration[] | undefined;
1397
+ toolsRemoved?: {
1398
+ name: string;
1399
+ }[] | undefined;
1400
+ } | {
1401
+ role: "user";
1402
+ content: string | ({
1403
+ type: "text";
1404
+ text: string;
1405
+ textSignature?: string | undefined;
1406
+ } | {
1407
+ type: "image";
1408
+ data: string;
1409
+ mimeType: string;
1410
+ })[];
1411
+ timestamp: number;
1412
+ } | {
1413
+ role: "assistant";
1414
+ content: ({
1415
+ type: "text";
1416
+ text: string;
1417
+ textSignature?: string | undefined;
1418
+ } | {
1419
+ type: "thinking";
1420
+ thinking: string;
1421
+ thinkingSignature?: string | undefined;
1422
+ redacted?: boolean | undefined;
1423
+ } | {
1424
+ type: "toolCall";
1425
+ id: string;
1426
+ name: string;
1427
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
1428
+ thoughtSignature?: string | undefined;
1429
+ argumentsError?: string | undefined;
1430
+ })[];
1431
+ api: string;
1432
+ provider: string;
1433
+ model: string;
1434
+ usage: {
1435
+ input: number;
1436
+ output: number;
1437
+ cacheRead: number;
1438
+ cacheWrite: number;
1439
+ totalTokens: number;
1440
+ cost: {
1441
+ input: number;
1442
+ output: number;
1443
+ cacheRead: number;
1444
+ cacheWrite: number;
1445
+ total: number;
1446
+ totalFromProvider?: boolean | undefined;
1447
+ };
1448
+ cacheWrite1h?: number | undefined;
1449
+ reasoning?: number | undefined;
1450
+ };
1451
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
1452
+ timestamp: number;
1453
+ responseModel?: string | undefined;
1454
+ responseId?: string | undefined;
1455
+ diagnostics?: {
1456
+ type: string;
1457
+ timestamp: number;
1458
+ error?: {
1459
+ message: string;
1460
+ name?: string | undefined;
1461
+ stack?: string | undefined;
1462
+ code?: string | number | undefined;
1463
+ } | undefined;
1464
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
1465
+ }[] | undefined;
1466
+ deferred?: {
1467
+ provider: string;
1468
+ modelId: string;
1469
+ api: string;
1470
+ id: string;
1471
+ expiresAt?: number | undefined;
1472
+ pollAfterMs?: number | undefined;
1473
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1474
+ } | undefined;
1475
+ errorMessage?: string | undefined;
1476
+ rawStopReason?: string | undefined;
1477
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
1478
+ providerThinkingLevel?: string | undefined;
1479
+ endTurn?: boolean | undefined;
1480
+ durationMs?: number | undefined;
1481
+ } | {
1482
+ role: "toolResult";
1483
+ toolCallId: string;
1484
+ toolName: string;
1485
+ content: ({
1486
+ type: "text";
1487
+ text: string;
1488
+ textSignature?: string | undefined;
1489
+ } | {
1490
+ type: "image";
1491
+ data: string;
1492
+ mimeType: string;
1493
+ })[];
1494
+ isError: boolean;
1495
+ timestamp: number;
1496
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1497
+ usage?: {
1498
+ input: number;
1499
+ output: number;
1500
+ cacheRead: number;
1501
+ cacheWrite: number;
1502
+ totalTokens: number;
1503
+ cost: {
1504
+ input: number;
1505
+ output: number;
1506
+ cacheRead: number;
1507
+ cacheWrite: number;
1508
+ total: number;
1509
+ totalFromProvider?: boolean | undefined;
1510
+ };
1511
+ cacheWrite1h?: number | undefined;
1512
+ reasoning?: number | undefined;
1513
+ } | undefined;
1514
+ durationMs?: number | undefined;
1515
+ })[] | undefined;
1516
+ replacementConversation?: ({
1517
+ role: "system";
1518
+ content: string | {
1519
+ type: "text";
1520
+ text: string;
1521
+ textSignature?: string | undefined;
1522
+ }[];
1523
+ timestamp: number;
1524
+ sections?: Record<string, string | null> | undefined;
1525
+ toolsAdded?: ToolDeclaration[] | undefined;
1526
+ toolsRemoved?: {
1527
+ name: string;
1528
+ }[] | undefined;
1529
+ } | {
1530
+ role: "user";
1531
+ content: string | ({
1532
+ type: "text";
1533
+ text: string;
1534
+ textSignature?: string | undefined;
1535
+ } | {
1536
+ type: "image";
1537
+ data: string;
1538
+ mimeType: string;
1539
+ })[];
1540
+ timestamp: number;
1541
+ } | {
1542
+ role: "assistant";
1543
+ content: ({
1544
+ type: "text";
1545
+ text: string;
1546
+ textSignature?: string | undefined;
1547
+ } | {
1548
+ type: "thinking";
1549
+ thinking: string;
1550
+ thinkingSignature?: string | undefined;
1551
+ redacted?: boolean | undefined;
1552
+ } | {
1553
+ type: "toolCall";
1554
+ id: string;
1555
+ name: string;
1556
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
1557
+ thoughtSignature?: string | undefined;
1558
+ argumentsError?: string | undefined;
1559
+ })[];
1560
+ api: string;
1561
+ provider: string;
1562
+ model: string;
1563
+ usage: {
1564
+ input: number;
1565
+ output: number;
1566
+ cacheRead: number;
1567
+ cacheWrite: number;
1568
+ totalTokens: number;
1569
+ cost: {
1570
+ input: number;
1571
+ output: number;
1572
+ cacheRead: number;
1573
+ cacheWrite: number;
1574
+ total: number;
1575
+ totalFromProvider?: boolean | undefined;
1576
+ };
1577
+ cacheWrite1h?: number | undefined;
1578
+ reasoning?: number | undefined;
1579
+ };
1580
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
1581
+ timestamp: number;
1582
+ responseModel?: string | undefined;
1583
+ responseId?: string | undefined;
1584
+ diagnostics?: {
1585
+ type: string;
1586
+ timestamp: number;
1587
+ error?: {
1588
+ message: string;
1589
+ name?: string | undefined;
1590
+ stack?: string | undefined;
1591
+ code?: string | number | undefined;
1592
+ } | undefined;
1593
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
1594
+ }[] | undefined;
1595
+ deferred?: {
1596
+ provider: string;
1597
+ modelId: string;
1598
+ api: string;
1599
+ id: string;
1600
+ expiresAt?: number | undefined;
1601
+ pollAfterMs?: number | undefined;
1602
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1603
+ } | undefined;
1604
+ errorMessage?: string | undefined;
1605
+ rawStopReason?: string | undefined;
1606
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
1607
+ providerThinkingLevel?: string | undefined;
1608
+ endTurn?: boolean | undefined;
1609
+ durationMs?: number | undefined;
1610
+ } | {
1611
+ role: "toolResult";
1612
+ toolCallId: string;
1613
+ toolName: string;
1614
+ content: ({
1615
+ type: "text";
1616
+ text: string;
1617
+ textSignature?: string | undefined;
1618
+ } | {
1619
+ type: "image";
1620
+ data: string;
1621
+ mimeType: string;
1622
+ })[];
1623
+ isError: boolean;
1624
+ timestamp: number;
1625
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1626
+ usage?: {
1627
+ input: number;
1628
+ output: number;
1629
+ cacheRead: number;
1630
+ cacheWrite: number;
1631
+ totalTokens: number;
1632
+ cost: {
1633
+ input: number;
1634
+ output: number;
1635
+ cacheRead: number;
1636
+ cacheWrite: number;
1637
+ total: number;
1638
+ totalFromProvider?: boolean | undefined;
1639
+ };
1640
+ cacheWrite1h?: number | undefined;
1641
+ reasoning?: number | undefined;
1642
+ } | undefined;
1643
+ durationMs?: number | undefined;
1644
+ })[] | undefined;
1645
+ }>;
1646
+ declare const ContextPreparationResultSchema: s.Schema<{
1647
+ decision: "continue";
1648
+ draft: {
1649
+ sources: ({
1650
+ lifecycle: "session";
1651
+ kind: "instructions";
1652
+ channel: "system" | "developer" | "agents";
1653
+ content: string;
1654
+ sourceId: string;
1655
+ provenance: {
1656
+ origin: "file" | "runtime" | "host" | "journal";
1657
+ label: string;
1658
+ location?: string | undefined;
1659
+ };
1660
+ } | {
1661
+ lifecycle: "session";
1662
+ kind: "extension";
1663
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
1664
+ name: string;
1665
+ content: string;
1666
+ sourceId: string;
1667
+ provenance: {
1668
+ origin: "file" | "runtime" | "host" | "journal";
1669
+ label: string;
1670
+ location?: string | undefined;
1671
+ };
1672
+ } | {
1673
+ lifecycle: "session";
1674
+ kind: "workspace";
1675
+ root: string;
1676
+ sourceId: string;
1677
+ provenance: {
1678
+ origin: "file" | "runtime" | "host" | "journal";
1679
+ label: string;
1680
+ location?: string | undefined;
1681
+ };
1682
+ } | {
1683
+ lifecycle: "turn";
1684
+ kind: "instructions";
1685
+ channel: "developer" | "agents";
1686
+ content: string;
1687
+ sourceId: string;
1688
+ provenance: {
1689
+ origin: "file" | "runtime" | "host" | "journal";
1690
+ label: string;
1691
+ location?: string | undefined;
1692
+ };
1693
+ } | {
1694
+ lifecycle: "turn";
1695
+ kind: "extension";
1696
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
1697
+ name: string;
1698
+ content: string;
1699
+ sourceId: string;
1700
+ provenance: {
1701
+ origin: "file" | "runtime" | "host" | "journal";
1702
+ label: string;
1703
+ location?: string | undefined;
1704
+ };
1705
+ } | {
1706
+ lifecycle: "turn";
1707
+ kind: "document";
1708
+ name: string;
1709
+ mediaType: string;
1710
+ content: string;
1711
+ sourceId: string;
1712
+ provenance: {
1713
+ origin: "file" | "runtime" | "host" | "journal";
1714
+ label: string;
1715
+ location?: string | undefined;
1716
+ };
1717
+ } | {
1718
+ lifecycle: "turn";
1719
+ kind: "event";
1720
+ event: {
1721
+ kind: "text";
1722
+ name: string;
1723
+ attributes?: Record<string, string | number>;
1724
+ text: string;
1725
+ } | {
1726
+ kind: "container";
1727
+ name: string;
1728
+ attributes?: Record<string, string | number>;
1729
+ children: ContextXmlElement[];
1730
+ };
1731
+ sourceId: string;
1732
+ provenance: {
1733
+ origin: "file" | "runtime" | "host" | "journal";
1734
+ label: string;
1735
+ location?: string | undefined;
1736
+ };
1737
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1738
+ })[];
1739
+ requestSources: {
1740
+ content: string;
1741
+ retention: "request" | "epoch";
1742
+ sourceId: string;
1743
+ provenance: {
1744
+ origin: "file" | "runtime" | "host" | "journal";
1745
+ label: string;
1746
+ location?: string | undefined;
1747
+ };
1748
+ placement?: "before-conversation" | undefined;
1749
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1750
+ }[];
1751
+ states: {
1752
+ stateName: string;
1753
+ state: {
1754
+ present: true;
1755
+ value: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null;
1756
+ element: {
1757
+ kind: "text";
1758
+ name: string;
1759
+ attributes?: Record<string, string | number>;
1760
+ text: string;
1761
+ } | {
1762
+ kind: "container";
1763
+ name: string;
1764
+ attributes?: Record<string, string | number>;
1765
+ children: ContextXmlElement[];
1766
+ };
1767
+ } | {
1768
+ present: false;
1769
+ };
1770
+ }[];
1771
+ modelView?: {
1772
+ throughSequence: number;
1773
+ history: {
1774
+ runId: string;
1775
+ messageId: string;
1776
+ }[];
1777
+ reclaimBefore?: {
1778
+ runId: string;
1779
+ messageId: string;
1780
+ } | undefined;
1781
+ stateOrigins?: {
1782
+ stateName: string;
1783
+ revision: number;
1784
+ }[] | undefined;
1785
+ } | undefined;
1786
+ toolNames?: string[] | undefined;
1787
+ conversation?: ({
1788
+ role: "system";
1789
+ content: string | {
1790
+ type: "text";
1791
+ text: string;
1792
+ textSignature?: string | undefined;
1793
+ }[];
1794
+ timestamp: number;
1795
+ sections?: Record<string, string | null> | undefined;
1796
+ toolsAdded?: ToolDeclaration[] | undefined;
1797
+ toolsRemoved?: {
1798
+ name: string;
1799
+ }[] | undefined;
1800
+ } | {
1801
+ role: "user";
1802
+ content: string | ({
1803
+ type: "text";
1804
+ text: string;
1805
+ textSignature?: string | undefined;
1806
+ } | {
1807
+ type: "image";
1808
+ data: string;
1809
+ mimeType: string;
1810
+ })[];
1811
+ timestamp: number;
1812
+ } | {
1813
+ role: "assistant";
1814
+ content: ({
1815
+ type: "text";
1816
+ text: string;
1817
+ textSignature?: string | undefined;
1818
+ } | {
1819
+ type: "thinking";
1820
+ thinking: string;
1821
+ thinkingSignature?: string | undefined;
1822
+ redacted?: boolean | undefined;
1823
+ } | {
1824
+ type: "toolCall";
1825
+ id: string;
1826
+ name: string;
1827
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
1828
+ thoughtSignature?: string | undefined;
1829
+ argumentsError?: string | undefined;
1830
+ })[];
1831
+ api: string;
1832
+ provider: string;
1833
+ model: string;
1834
+ usage: {
1835
+ input: number;
1836
+ output: number;
1837
+ cacheRead: number;
1838
+ cacheWrite: number;
1839
+ totalTokens: number;
1840
+ cost: {
1841
+ input: number;
1842
+ output: number;
1843
+ cacheRead: number;
1844
+ cacheWrite: number;
1845
+ total: number;
1846
+ totalFromProvider?: boolean | undefined;
1847
+ };
1848
+ cacheWrite1h?: number | undefined;
1849
+ reasoning?: number | undefined;
1850
+ };
1851
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
1852
+ timestamp: number;
1853
+ responseModel?: string | undefined;
1854
+ responseId?: string | undefined;
1855
+ diagnostics?: {
1856
+ type: string;
1857
+ timestamp: number;
1858
+ error?: {
1859
+ message: string;
1860
+ name?: string | undefined;
1861
+ stack?: string | undefined;
1862
+ code?: string | number | undefined;
1863
+ } | undefined;
1864
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
1865
+ }[] | undefined;
1866
+ deferred?: {
1867
+ provider: string;
1868
+ modelId: string;
1869
+ api: string;
1870
+ id: string;
1871
+ expiresAt?: number | undefined;
1872
+ pollAfterMs?: number | undefined;
1873
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1874
+ } | undefined;
1875
+ errorMessage?: string | undefined;
1876
+ rawStopReason?: string | undefined;
1877
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
1878
+ providerThinkingLevel?: string | undefined;
1879
+ endTurn?: boolean | undefined;
1880
+ durationMs?: number | undefined;
1881
+ } | {
1882
+ role: "toolResult";
1883
+ toolCallId: string;
1884
+ toolName: string;
1885
+ content: ({
1886
+ type: "text";
1887
+ text: string;
1888
+ textSignature?: string | undefined;
1889
+ } | {
1890
+ type: "image";
1891
+ data: string;
1892
+ mimeType: string;
1893
+ })[];
1894
+ isError: boolean;
1895
+ timestamp: number;
1896
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
1897
+ usage?: {
1898
+ input: number;
1899
+ output: number;
1900
+ cacheRead: number;
1901
+ cacheWrite: number;
1902
+ totalTokens: number;
1903
+ cost: {
1904
+ input: number;
1905
+ output: number;
1906
+ cacheRead: number;
1907
+ cacheWrite: number;
1908
+ total: number;
1909
+ totalFromProvider?: boolean | undefined;
1910
+ };
1911
+ cacheWrite1h?: number | undefined;
1912
+ reasoning?: number | undefined;
1913
+ } | undefined;
1914
+ durationMs?: number | undefined;
1915
+ })[] | undefined;
1916
+ replacementConversation?: ({
1917
+ role: "system";
1918
+ content: string | {
1919
+ type: "text";
1920
+ text: string;
1921
+ textSignature?: string | undefined;
1922
+ }[];
1923
+ timestamp: number;
1924
+ sections?: Record<string, string | null> | undefined;
1925
+ toolsAdded?: ToolDeclaration[] | undefined;
1926
+ toolsRemoved?: {
1927
+ name: string;
1928
+ }[] | undefined;
1929
+ } | {
1930
+ role: "user";
1931
+ content: string | ({
1932
+ type: "text";
1933
+ text: string;
1934
+ textSignature?: string | undefined;
1935
+ } | {
1936
+ type: "image";
1937
+ data: string;
1938
+ mimeType: string;
1939
+ })[];
1940
+ timestamp: number;
1941
+ } | {
1942
+ role: "assistant";
1943
+ content: ({
1944
+ type: "text";
1945
+ text: string;
1946
+ textSignature?: string | undefined;
1947
+ } | {
1948
+ type: "thinking";
1949
+ thinking: string;
1950
+ thinkingSignature?: string | undefined;
1951
+ redacted?: boolean | undefined;
1952
+ } | {
1953
+ type: "toolCall";
1954
+ id: string;
1955
+ name: string;
1956
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
1957
+ thoughtSignature?: string | undefined;
1958
+ argumentsError?: string | undefined;
1959
+ })[];
1960
+ api: string;
1961
+ provider: string;
1962
+ model: string;
1963
+ usage: {
1964
+ input: number;
1965
+ output: number;
1966
+ cacheRead: number;
1967
+ cacheWrite: number;
1968
+ totalTokens: number;
1969
+ cost: {
1970
+ input: number;
1971
+ output: number;
1972
+ cacheRead: number;
1973
+ cacheWrite: number;
1974
+ total: number;
1975
+ totalFromProvider?: boolean | undefined;
1976
+ };
1977
+ cacheWrite1h?: number | undefined;
1978
+ reasoning?: number | undefined;
1979
+ };
1980
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
1981
+ timestamp: number;
1982
+ responseModel?: string | undefined;
1983
+ responseId?: string | undefined;
1984
+ diagnostics?: {
1985
+ type: string;
1986
+ timestamp: number;
1987
+ error?: {
1988
+ message: string;
1989
+ name?: string | undefined;
1990
+ stack?: string | undefined;
1991
+ code?: string | number | undefined;
1992
+ } | undefined;
1993
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
1994
+ }[] | undefined;
1995
+ deferred?: {
1996
+ provider: string;
1997
+ modelId: string;
1998
+ api: string;
1999
+ id: string;
2000
+ expiresAt?: number | undefined;
2001
+ pollAfterMs?: number | undefined;
2002
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2003
+ } | undefined;
2004
+ errorMessage?: string | undefined;
2005
+ rawStopReason?: string | undefined;
2006
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
2007
+ providerThinkingLevel?: string | undefined;
2008
+ endTurn?: boolean | undefined;
2009
+ durationMs?: number | undefined;
2010
+ } | {
2011
+ role: "toolResult";
2012
+ toolCallId: string;
2013
+ toolName: string;
2014
+ content: ({
2015
+ type: "text";
2016
+ text: string;
2017
+ textSignature?: string | undefined;
2018
+ } | {
2019
+ type: "image";
2020
+ data: string;
2021
+ mimeType: string;
2022
+ })[];
2023
+ isError: boolean;
2024
+ timestamp: number;
2025
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2026
+ usage?: {
2027
+ input: number;
2028
+ output: number;
2029
+ cacheRead: number;
2030
+ cacheWrite: number;
2031
+ totalTokens: number;
2032
+ cost: {
2033
+ input: number;
2034
+ output: number;
2035
+ cacheRead: number;
2036
+ cacheWrite: number;
2037
+ total: number;
2038
+ totalFromProvider?: boolean | undefined;
2039
+ };
2040
+ cacheWrite1h?: number | undefined;
2041
+ reasoning?: number | undefined;
2042
+ } | undefined;
2043
+ durationMs?: number | undefined;
2044
+ })[] | undefined;
2045
+ };
2046
+ } | {
2047
+ decision: "reject";
2048
+ reason: string;
2049
+ }>;
2050
+ type ContextPreparationDraft = s.Static<typeof DraftSchema>;
2051
+ type ContextPreparationResult = s.Static<typeof ContextPreparationResultSchema>;
2052
+ interface ContextPreparationScope {
2053
+ readonly turnScopeId: string;
2054
+ /** Required by the caller when Hooks propose request material; stable across physical retries. */
2055
+ readonly requestScopeId?: string;
2056
+ readonly signal?: AbortSignal;
2057
+ }
2058
+ /** Ordered by registration. This continuation prepares data; it never commits or executes. */
2059
+ interface ContextPreparationHook {
2060
+ readonly hookId: string;
2061
+ around(draft: ContextPreparationDraft, scope: ContextPreparationScope, next: (draft: ContextPreparationDraft) => Promise<ContextPreparationResult>): Promise<ContextPreparationResult>;
2062
+ }
2063
+ declare class ContextPreparationRejectedError extends Error {
2064
+ readonly reason: string;
2065
+ readonly code = "context_preparation_rejected";
2066
+ constructor(reason: string);
2067
+ }
2068
+ /** Runs preparation only; callers retain ownership of owner-schema validation, revision and adoption. */
2069
+ declare function runContextPreparation(hooks: readonly ContextPreparationHook[], draft: ContextPreparationDraft, scope: ContextPreparationScope): Promise<ContextPreparationResult>;
2070
+ //#endregion
2071
+ //#region src/model-input/contracts.d.ts
2072
+ declare const ModelContextMessageSchema: s.Schema<{
2073
+ role: "user";
2074
+ content: string;
2075
+ }>;
2076
+ declare const ModelInputSchema: s.Schema<{
2077
+ systemPrompt: string;
2078
+ stateMessages: {
2079
+ role: "user";
2080
+ content: string;
2081
+ }[];
2082
+ turnMessages: {
2083
+ role: "user";
2084
+ content: string;
2085
+ }[];
2086
+ requestMessages?: {
2087
+ role: "user";
2088
+ content: string;
2089
+ }[] | undefined;
2090
+ }>;
2091
+ type ModelContextMessage = s.Static<typeof ModelContextMessageSchema>;
2092
+ type ModelInput = s.Static<typeof ModelInputSchema>;
2093
+ /** Serializable dispatch settings, pinned with a physical request and reused after interruption. */
2094
+ declare const ModelRequestSettingsSchema: s.Schema<{
2095
+ temperature?: number | undefined;
2096
+ maxOutputTokens?: number | undefined;
2097
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
2098
+ }>;
2099
+ type ModelRequestSettings = s.Static<typeof ModelRequestSettingsSchema>;
2100
+ //#endregion
2101
+ //#region src/messages.d.ts
2102
+ declare const TextContentSchema: s.Schema<{
2103
+ type: "text";
2104
+ text: string;
2105
+ textSignature?: string | undefined;
2106
+ }>;
2107
+ declare const ImageContentSchema: s.Schema<{
2108
+ type: "image";
2109
+ data: string;
2110
+ mimeType: string;
2111
+ }>;
2112
+ declare const ThinkingContentSchema: s.Schema<{
2113
+ type: "thinking";
2114
+ thinking: string;
2115
+ thinkingSignature?: string | undefined;
2116
+ redacted?: boolean | undefined;
2117
+ }>;
2118
+ declare const ToolCallProperties: {
2119
+ type: s.Schema<"toolCall">;
2120
+ id: s.Schema<string>;
2121
+ name: s.Schema<string>;
2122
+ arguments: s.Schema<Record<string, _sorbetai_schema35.JsonValue>>;
2123
+ thoughtSignature: s.Optional<s.Schema<string>>;
2124
+ /**
2125
+ * Pi sets this when the model's complete arguments text was not a JSON object; `arguments`
2126
+ * is then `{}`. Such a call is never executed.
2127
+ */
2128
+ argumentsError: s.Optional<s.Schema<string>>;
2129
+ };
2130
+ declare const ToolCallSchema: s.Schema<{
2131
+ type: "toolCall";
2132
+ id: string;
2133
+ name: string;
2134
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
2135
+ thoughtSignature?: string | undefined;
2136
+ argumentsError?: string | undefined;
2137
+ }>;
2138
+ declare const UsageSchema: s.Schema<{
2139
+ input: number;
2140
+ output: number;
2141
+ cacheRead: number;
2142
+ cacheWrite: number;
2143
+ totalTokens: number;
2144
+ cost: {
2145
+ input: number;
2146
+ output: number;
2147
+ cacheRead: number;
2148
+ cacheWrite: number;
2149
+ total: number;
2150
+ totalFromProvider?: boolean | undefined;
2151
+ };
2152
+ cacheWrite1h?: number | undefined;
2153
+ reasoning?: number | undefined;
2154
+ }>;
2155
+ declare const UserMessageProperties: {
2156
+ role: s.Schema<"user">;
2157
+ content: s.Schema<string | ({
2158
+ type: "text";
2159
+ text: string;
2160
+ textSignature?: string | undefined;
2161
+ } | {
2162
+ type: "image";
2163
+ data: string;
2164
+ mimeType: string;
2165
+ })[]>;
2166
+ timestamp: s.Schema<number>;
2167
+ };
2168
+ declare const UserMessageSchema: s.Schema<{
2169
+ role: "user";
2170
+ content: string | ({
2171
+ type: "text";
2172
+ text: string;
2173
+ textSignature?: string | undefined;
2174
+ } | {
2175
+ type: "image";
2176
+ data: string;
2177
+ mimeType: string;
2178
+ })[];
2179
+ timestamp: number;
2180
+ }>;
2181
+ declare const AssistantMessageSchema: s.Schema<{
2182
+ role: "assistant";
2183
+ content: ({
2184
+ type: "text";
2185
+ text: string;
2186
+ textSignature?: string | undefined;
2187
+ } | {
2188
+ type: "thinking";
2189
+ thinking: string;
2190
+ thinkingSignature?: string | undefined;
2191
+ redacted?: boolean | undefined;
2192
+ } | {
2193
+ type: "toolCall";
2194
+ id: string;
2195
+ name: string;
2196
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
2197
+ thoughtSignature?: string | undefined;
2198
+ argumentsError?: string | undefined;
2199
+ })[];
2200
+ api: string;
2201
+ provider: string;
2202
+ model: string;
2203
+ usage: {
2204
+ input: number;
2205
+ output: number;
2206
+ cacheRead: number;
2207
+ cacheWrite: number;
2208
+ totalTokens: number;
2209
+ cost: {
2210
+ input: number;
2211
+ output: number;
2212
+ cacheRead: number;
2213
+ cacheWrite: number;
2214
+ total: number;
2215
+ totalFromProvider?: boolean | undefined;
2216
+ };
2217
+ cacheWrite1h?: number | undefined;
2218
+ reasoning?: number | undefined;
2219
+ };
2220
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
2221
+ timestamp: number;
2222
+ responseModel?: string | undefined;
2223
+ responseId?: string | undefined;
2224
+ diagnostics?: {
2225
+ type: string;
2226
+ timestamp: number;
2227
+ error?: {
2228
+ message: string;
2229
+ name?: string | undefined;
2230
+ stack?: string | undefined;
2231
+ code?: string | number | undefined;
2232
+ } | undefined;
2233
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
2234
+ }[] | undefined;
2235
+ deferred?: {
2236
+ provider: string;
2237
+ modelId: string;
2238
+ api: string;
2239
+ id: string;
2240
+ expiresAt?: number | undefined;
2241
+ pollAfterMs?: number | undefined;
2242
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2243
+ } | undefined;
2244
+ errorMessage?: string | undefined;
2245
+ rawStopReason?: string | undefined;
2246
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
2247
+ providerThinkingLevel?: string | undefined;
2248
+ endTurn?: boolean | undefined;
2249
+ durationMs?: number | undefined;
2250
+ }>;
2251
+ declare const ToolResultMessageSchema: s.Schema<{
2252
+ role: "toolResult";
2253
+ toolCallId: string;
2254
+ toolName: string;
2255
+ content: ({
2256
+ type: "text";
2257
+ text: string;
2258
+ textSignature?: string | undefined;
2259
+ } | {
2260
+ type: "image";
2261
+ data: string;
2262
+ mimeType: string;
2263
+ })[];
2264
+ isError: boolean;
2265
+ timestamp: number;
2266
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2267
+ usage?: {
2268
+ input: number;
2269
+ output: number;
2270
+ cacheRead: number;
2271
+ cacheWrite: number;
2272
+ totalTokens: number;
2273
+ cost: {
2274
+ input: number;
2275
+ output: number;
2276
+ cacheRead: number;
2277
+ cacheWrite: number;
2278
+ total: number;
2279
+ totalFromProvider?: boolean | undefined;
2280
+ };
2281
+ cacheWrite1h?: number | undefined;
2282
+ reasoning?: number | undefined;
2283
+ } | undefined;
2284
+ durationMs?: number | undefined;
2285
+ }>;
2286
+ declare const SystemMessageSchema: s.Schema<{
2287
+ role: "system";
2288
+ content: string | {
2289
+ type: "text";
2290
+ text: string;
2291
+ textSignature?: string | undefined;
2292
+ }[];
2293
+ timestamp: number;
2294
+ sections?: Record<string, string | null> | undefined;
2295
+ toolsAdded?: ToolDeclaration[] | undefined;
2296
+ toolsRemoved?: {
2297
+ name: string;
2298
+ }[] | undefined;
2299
+ }>;
2300
+ declare const MessageSchema: s.Schema<{
2301
+ role: "system";
2302
+ content: string | {
2303
+ type: "text";
2304
+ text: string;
2305
+ textSignature?: string | undefined;
2306
+ }[];
2307
+ timestamp: number;
2308
+ sections?: Record<string, string | null> | undefined;
2309
+ toolsAdded?: ToolDeclaration[] | undefined;
2310
+ toolsRemoved?: {
2311
+ name: string;
2312
+ }[] | undefined;
2313
+ } | {
2314
+ role: "user";
2315
+ content: string | ({
2316
+ type: "text";
2317
+ text: string;
2318
+ textSignature?: string | undefined;
2319
+ } | {
2320
+ type: "image";
2321
+ data: string;
2322
+ mimeType: string;
2323
+ })[];
2324
+ timestamp: number;
2325
+ } | {
2326
+ role: "assistant";
2327
+ content: ({
2328
+ type: "text";
2329
+ text: string;
2330
+ textSignature?: string | undefined;
2331
+ } | {
2332
+ type: "thinking";
2333
+ thinking: string;
2334
+ thinkingSignature?: string | undefined;
2335
+ redacted?: boolean | undefined;
2336
+ } | {
2337
+ type: "toolCall";
2338
+ id: string;
2339
+ name: string;
2340
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
2341
+ thoughtSignature?: string | undefined;
2342
+ argumentsError?: string | undefined;
2343
+ })[];
2344
+ api: string;
2345
+ provider: string;
2346
+ model: string;
2347
+ usage: {
2348
+ input: number;
2349
+ output: number;
2350
+ cacheRead: number;
2351
+ cacheWrite: number;
2352
+ totalTokens: number;
2353
+ cost: {
2354
+ input: number;
2355
+ output: number;
2356
+ cacheRead: number;
2357
+ cacheWrite: number;
2358
+ total: number;
2359
+ totalFromProvider?: boolean | undefined;
2360
+ };
2361
+ cacheWrite1h?: number | undefined;
2362
+ reasoning?: number | undefined;
2363
+ };
2364
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
2365
+ timestamp: number;
2366
+ responseModel?: string | undefined;
2367
+ responseId?: string | undefined;
2368
+ diagnostics?: {
2369
+ type: string;
2370
+ timestamp: number;
2371
+ error?: {
2372
+ message: string;
2373
+ name?: string | undefined;
2374
+ stack?: string | undefined;
2375
+ code?: string | number | undefined;
2376
+ } | undefined;
2377
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
2378
+ }[] | undefined;
2379
+ deferred?: {
2380
+ provider: string;
2381
+ modelId: string;
2382
+ api: string;
2383
+ id: string;
2384
+ expiresAt?: number | undefined;
2385
+ pollAfterMs?: number | undefined;
2386
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2387
+ } | undefined;
2388
+ errorMessage?: string | undefined;
2389
+ rawStopReason?: string | undefined;
2390
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
2391
+ providerThinkingLevel?: string | undefined;
2392
+ endTurn?: boolean | undefined;
2393
+ durationMs?: number | undefined;
2394
+ } | {
2395
+ role: "toolResult";
2396
+ toolCallId: string;
2397
+ toolName: string;
2398
+ content: ({
2399
+ type: "text";
2400
+ text: string;
2401
+ textSignature?: string | undefined;
2402
+ } | {
2403
+ type: "image";
2404
+ data: string;
2405
+ mimeType: string;
2406
+ })[];
2407
+ isError: boolean;
2408
+ timestamp: number;
2409
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2410
+ usage?: {
2411
+ input: number;
2412
+ output: number;
2413
+ cacheRead: number;
2414
+ cacheWrite: number;
2415
+ totalTokens: number;
2416
+ cost: {
2417
+ input: number;
2418
+ output: number;
2419
+ cacheRead: number;
2420
+ cacheWrite: number;
2421
+ total: number;
2422
+ totalFromProvider?: boolean | undefined;
2423
+ };
2424
+ cacheWrite1h?: number | undefined;
2425
+ reasoning?: number | undefined;
2426
+ } | undefined;
2427
+ durationMs?: number | undefined;
2428
+ }>;
2429
+ type TextContent = s.Static<typeof TextContentSchema>;
2430
+ type ImageContent = s.Static<typeof ImageContentSchema>;
2431
+ type ThinkingContent = s.Static<typeof ThinkingContentSchema>;
2432
+ type ToolCall = s.Static<typeof ToolCallSchema>;
2433
+ type Usage = s.Static<typeof UsageSchema>;
2434
+ type UserMessage = s.Static<typeof UserMessageSchema>;
2435
+ type AssistantMessage = s.Static<typeof AssistantMessageSchema>;
2436
+ type ToolResultMessage = s.Static<typeof ToolResultMessageSchema>;
2437
+ type Message = s.Static<typeof MessageSchema>;
2438
+ type SystemMessage = s.Static<typeof SystemMessageSchema>;
2439
+ declare const ModelContextSchema: s.Schema<{
2440
+ messages: ({
2441
+ role: "system";
2442
+ content: string | {
2443
+ type: "text";
2444
+ text: string;
2445
+ textSignature?: string | undefined;
2446
+ }[];
2447
+ timestamp: number;
2448
+ sections?: Record<string, string | null> | undefined;
2449
+ toolsAdded?: ToolDeclaration[] | undefined;
2450
+ toolsRemoved?: {
2451
+ name: string;
2452
+ }[] | undefined;
2453
+ } | {
2454
+ role: "user";
2455
+ content: string | ({
2456
+ type: "text";
2457
+ text: string;
2458
+ textSignature?: string | undefined;
2459
+ } | {
2460
+ type: "image";
2461
+ data: string;
2462
+ mimeType: string;
2463
+ })[];
2464
+ timestamp: number;
2465
+ } | {
2466
+ role: "assistant";
2467
+ content: ({
2468
+ type: "text";
2469
+ text: string;
2470
+ textSignature?: string | undefined;
2471
+ } | {
2472
+ type: "thinking";
2473
+ thinking: string;
2474
+ thinkingSignature?: string | undefined;
2475
+ redacted?: boolean | undefined;
2476
+ } | {
2477
+ type: "toolCall";
2478
+ id: string;
2479
+ name: string;
2480
+ arguments: Record<string, _sorbetai_schema35.JsonValue>;
2481
+ thoughtSignature?: string | undefined;
2482
+ argumentsError?: string | undefined;
2483
+ })[];
2484
+ api: string;
2485
+ provider: string;
2486
+ model: string;
2487
+ usage: {
2488
+ input: number;
2489
+ output: number;
2490
+ cacheRead: number;
2491
+ cacheWrite: number;
2492
+ totalTokens: number;
2493
+ cost: {
2494
+ input: number;
2495
+ output: number;
2496
+ cacheRead: number;
2497
+ cacheWrite: number;
2498
+ total: number;
2499
+ totalFromProvider?: boolean | undefined;
2500
+ };
2501
+ cacheWrite1h?: number | undefined;
2502
+ reasoning?: number | undefined;
2503
+ };
2504
+ stopReason: "error" | "pending" | "stop" | "length" | "toolUse" | "aborted" | "deferred";
2505
+ timestamp: number;
2506
+ responseModel?: string | undefined;
2507
+ responseId?: string | undefined;
2508
+ diagnostics?: {
2509
+ type: string;
2510
+ timestamp: number;
2511
+ error?: {
2512
+ message: string;
2513
+ name?: string | undefined;
2514
+ stack?: string | undefined;
2515
+ code?: string | number | undefined;
2516
+ } | undefined;
2517
+ details?: Record<string, _sorbetai_schema35.JsonValue> | undefined;
2518
+ }[] | undefined;
2519
+ deferred?: {
2520
+ provider: string;
2521
+ modelId: string;
2522
+ api: string;
2523
+ id: string;
2524
+ expiresAt?: number | undefined;
2525
+ pollAfterMs?: number | undefined;
2526
+ data?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2527
+ } | undefined;
2528
+ errorMessage?: string | undefined;
2529
+ rawStopReason?: string | undefined;
2530
+ thinkingLevel?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | undefined;
2531
+ providerThinkingLevel?: string | undefined;
2532
+ endTurn?: boolean | undefined;
2533
+ durationMs?: number | undefined;
2534
+ } | {
2535
+ role: "toolResult";
2536
+ toolCallId: string;
2537
+ toolName: string;
2538
+ content: ({
2539
+ type: "text";
2540
+ text: string;
2541
+ textSignature?: string | undefined;
2542
+ } | {
2543
+ type: "image";
2544
+ data: string;
2545
+ mimeType: string;
2546
+ })[];
2547
+ isError: boolean;
2548
+ timestamp: number;
2549
+ details?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2550
+ usage?: {
2551
+ input: number;
2552
+ output: number;
2553
+ cacheRead: number;
2554
+ cacheWrite: number;
2555
+ totalTokens: number;
2556
+ cost: {
2557
+ input: number;
2558
+ output: number;
2559
+ cacheRead: number;
2560
+ cacheWrite: number;
2561
+ total: number;
2562
+ totalFromProvider?: boolean | undefined;
2563
+ };
2564
+ cacheWrite1h?: number | undefined;
2565
+ reasoning?: number | undefined;
2566
+ } | undefined;
2567
+ durationMs?: number | undefined;
2568
+ })[];
2569
+ systemPrompt?: string | undefined;
2570
+ tools?: ToolDeclaration[] | undefined;
2571
+ }>;
2572
+ type ModelContext = s.Static<typeof ModelContextSchema>;
2573
+ //#endregion
2574
+ //#region src/source/contracts.d.ts
2575
+ declare const ContextProvenanceSchema: s.Schema<{
2576
+ origin: "file" | "runtime" | "host" | "journal";
2577
+ label: string;
2578
+ location?: string | undefined;
2579
+ }>;
2580
+ /** Material proposed for one logical call; retention controls later model visibility, not storage. */
2581
+ declare const RequestContextSourceSchema: s.Schema<{
2582
+ content: string;
2583
+ retention: "request" | "epoch";
2584
+ sourceId: string;
2585
+ provenance: {
2586
+ origin: "file" | "runtime" | "host" | "journal";
2587
+ label: string;
2588
+ location?: string | undefined;
2589
+ };
2590
+ placement?: "before-conversation" | undefined;
2591
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2592
+ }>;
2593
+ type RequestContextSource = s.Static<typeof RequestContextSourceSchema>;
2594
+ declare const SessionInstructionsContextSourceSchema: s.Schema<{
2595
+ lifecycle: "session";
2596
+ kind: "instructions";
2597
+ channel: "system" | "developer" | "agents";
2598
+ content: string;
2599
+ sourceId: string;
2600
+ provenance: {
2601
+ origin: "file" | "runtime" | "host" | "journal";
2602
+ label: string;
2603
+ location?: string | undefined;
2604
+ };
2605
+ }>;
2606
+ declare const TurnInstructionsContextSourceSchema: s.Schema<{
2607
+ lifecycle: "turn";
2608
+ kind: "instructions";
2609
+ channel: "developer" | "agents";
2610
+ content: string;
2611
+ sourceId: string;
2612
+ provenance: {
2613
+ origin: "file" | "runtime" | "host" | "journal";
2614
+ label: string;
2615
+ location?: string | undefined;
2616
+ };
2617
+ }>;
2618
+ declare const InstructionsContextSourceSchema: s.Schema<{
2619
+ lifecycle: "session";
2620
+ kind: "instructions";
2621
+ channel: "system" | "developer" | "agents";
2622
+ content: string;
2623
+ sourceId: string;
2624
+ provenance: {
2625
+ origin: "file" | "runtime" | "host" | "journal";
2626
+ label: string;
2627
+ location?: string | undefined;
2628
+ };
2629
+ } | {
2630
+ lifecycle: "turn";
2631
+ kind: "instructions";
2632
+ channel: "developer" | "agents";
2633
+ content: string;
2634
+ sourceId: string;
2635
+ provenance: {
2636
+ origin: "file" | "runtime" | "host" | "journal";
2637
+ label: string;
2638
+ location?: string | undefined;
2639
+ };
2640
+ }>;
2641
+ declare const SessionExtensionContextSourceSchema: s.Schema<{
2642
+ lifecycle: "session";
2643
+ kind: "extension";
2644
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2645
+ name: string;
2646
+ content: string;
2647
+ sourceId: string;
2648
+ provenance: {
2649
+ origin: "file" | "runtime" | "host" | "journal";
2650
+ label: string;
2651
+ location?: string | undefined;
2652
+ };
2653
+ }>;
2654
+ declare const TurnExtensionContextSourceSchema: s.Schema<{
2655
+ lifecycle: "turn";
2656
+ kind: "extension";
2657
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2658
+ name: string;
2659
+ content: string;
2660
+ sourceId: string;
2661
+ provenance: {
2662
+ origin: "file" | "runtime" | "host" | "journal";
2663
+ label: string;
2664
+ location?: string | undefined;
2665
+ };
2666
+ }>;
2667
+ declare const ExtensionContextSourceSchema: s.Schema<{
2668
+ lifecycle: "session";
2669
+ kind: "extension";
2670
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2671
+ name: string;
2672
+ content: string;
2673
+ sourceId: string;
2674
+ provenance: {
2675
+ origin: "file" | "runtime" | "host" | "journal";
2676
+ label: string;
2677
+ location?: string | undefined;
2678
+ };
2679
+ } | {
2680
+ lifecycle: "turn";
2681
+ kind: "extension";
2682
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2683
+ name: string;
2684
+ content: string;
2685
+ sourceId: string;
2686
+ provenance: {
2687
+ origin: "file" | "runtime" | "host" | "journal";
2688
+ label: string;
2689
+ location?: string | undefined;
2690
+ };
2691
+ }>;
2692
+ /** Identifies the fixed root directory for a Session-bound Workspace. */
2693
+ declare const WorkspaceContextSourceSchema: s.Schema<{
2694
+ lifecycle: "session";
2695
+ kind: "workspace";
2696
+ root: string;
2697
+ sourceId: string;
2698
+ provenance: {
2699
+ origin: "file" | "runtime" | "host" | "journal";
2700
+ label: string;
2701
+ location?: string | undefined;
2702
+ };
2703
+ }>;
2704
+ /** Documents are material for one admitted turn, never mutable named state or fixed prefix. */
2705
+ declare const DocumentContextSourceSchema: s.Schema<{
2706
+ lifecycle: "turn";
2707
+ kind: "document";
2708
+ name: string;
2709
+ mediaType: string;
2710
+ content: string;
2711
+ sourceId: string;
2712
+ provenance: {
2713
+ origin: "file" | "runtime" | "host" | "journal";
2714
+ label: string;
2715
+ location?: string | undefined;
2716
+ };
2717
+ }>;
2718
+ /** A one-shot structured event rendered as its exact XML tree for one turn. */
2719
+ declare const EventContextSourceSchema: s.Schema<{
2720
+ lifecycle: "turn";
2721
+ kind: "event";
2722
+ event: {
2723
+ kind: "text";
2724
+ name: string;
2725
+ attributes?: Record<string, string | number>;
2726
+ text: string;
2727
+ } | {
2728
+ kind: "container";
2729
+ name: string;
2730
+ attributes?: Record<string, string | number>;
2731
+ children: ContextXmlElement[];
2732
+ };
2733
+ sourceId: string;
2734
+ provenance: {
2735
+ origin: "file" | "runtime" | "host" | "journal";
2736
+ label: string;
2737
+ location?: string | undefined;
2738
+ };
2739
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2740
+ }>;
2741
+ declare const PrefixContextSourceSchema: s.Schema<{
2742
+ lifecycle: "session";
2743
+ kind: "instructions";
2744
+ channel: "system" | "developer" | "agents";
2745
+ content: string;
2746
+ sourceId: string;
2747
+ provenance: {
2748
+ origin: "file" | "runtime" | "host" | "journal";
2749
+ label: string;
2750
+ location?: string | undefined;
2751
+ };
2752
+ } | {
2753
+ lifecycle: "session";
2754
+ kind: "extension";
2755
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2756
+ name: string;
2757
+ content: string;
2758
+ sourceId: string;
2759
+ provenance: {
2760
+ origin: "file" | "runtime" | "host" | "journal";
2761
+ label: string;
2762
+ location?: string | undefined;
2763
+ };
2764
+ } | {
2765
+ lifecycle: "session";
2766
+ kind: "workspace";
2767
+ root: string;
2768
+ sourceId: string;
2769
+ provenance: {
2770
+ origin: "file" | "runtime" | "host" | "journal";
2771
+ label: string;
2772
+ location?: string | undefined;
2773
+ };
2774
+ }>;
2775
+ declare const TurnContextSourceSchema: s.Schema<{
2776
+ lifecycle: "turn";
2777
+ kind: "instructions";
2778
+ channel: "developer" | "agents";
2779
+ content: string;
2780
+ sourceId: string;
2781
+ provenance: {
2782
+ origin: "file" | "runtime" | "host" | "journal";
2783
+ label: string;
2784
+ location?: string | undefined;
2785
+ };
2786
+ } | {
2787
+ lifecycle: "turn";
2788
+ kind: "extension";
2789
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2790
+ name: string;
2791
+ content: string;
2792
+ sourceId: string;
2793
+ provenance: {
2794
+ origin: "file" | "runtime" | "host" | "journal";
2795
+ label: string;
2796
+ location?: string | undefined;
2797
+ };
2798
+ } | {
2799
+ lifecycle: "turn";
2800
+ kind: "document";
2801
+ name: string;
2802
+ mediaType: string;
2803
+ content: string;
2804
+ sourceId: string;
2805
+ provenance: {
2806
+ origin: "file" | "runtime" | "host" | "journal";
2807
+ label: string;
2808
+ location?: string | undefined;
2809
+ };
2810
+ } | {
2811
+ lifecycle: "turn";
2812
+ kind: "event";
2813
+ event: {
2814
+ kind: "text";
2815
+ name: string;
2816
+ attributes?: Record<string, string | number>;
2817
+ text: string;
2818
+ } | {
2819
+ kind: "container";
2820
+ name: string;
2821
+ attributes?: Record<string, string | number>;
2822
+ children: ContextXmlElement[];
2823
+ };
2824
+ sourceId: string;
2825
+ provenance: {
2826
+ origin: "file" | "runtime" | "host" | "journal";
2827
+ label: string;
2828
+ location?: string | undefined;
2829
+ };
2830
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2831
+ }>;
2832
+ declare const ContextSourceSchema: s.Schema<{
2833
+ lifecycle: "session";
2834
+ kind: "instructions";
2835
+ channel: "system" | "developer" | "agents";
2836
+ content: string;
2837
+ sourceId: string;
2838
+ provenance: {
2839
+ origin: "file" | "runtime" | "host" | "journal";
2840
+ label: string;
2841
+ location?: string | undefined;
2842
+ };
2843
+ } | {
2844
+ lifecycle: "session";
2845
+ kind: "extension";
2846
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2847
+ name: string;
2848
+ content: string;
2849
+ sourceId: string;
2850
+ provenance: {
2851
+ origin: "file" | "runtime" | "host" | "journal";
2852
+ label: string;
2853
+ location?: string | undefined;
2854
+ };
2855
+ } | {
2856
+ lifecycle: "session";
2857
+ kind: "workspace";
2858
+ root: string;
2859
+ sourceId: string;
2860
+ provenance: {
2861
+ origin: "file" | "runtime" | "host" | "journal";
2862
+ label: string;
2863
+ location?: string | undefined;
2864
+ };
2865
+ } | {
2866
+ lifecycle: "turn";
2867
+ kind: "instructions";
2868
+ channel: "developer" | "agents";
2869
+ content: string;
2870
+ sourceId: string;
2871
+ provenance: {
2872
+ origin: "file" | "runtime" | "host" | "journal";
2873
+ label: string;
2874
+ location?: string | undefined;
2875
+ };
2876
+ } | {
2877
+ lifecycle: "turn";
2878
+ kind: "extension";
2879
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2880
+ name: string;
2881
+ content: string;
2882
+ sourceId: string;
2883
+ provenance: {
2884
+ origin: "file" | "runtime" | "host" | "journal";
2885
+ label: string;
2886
+ location?: string | undefined;
2887
+ };
2888
+ } | {
2889
+ lifecycle: "turn";
2890
+ kind: "document";
2891
+ name: string;
2892
+ mediaType: string;
2893
+ content: string;
2894
+ sourceId: string;
2895
+ provenance: {
2896
+ origin: "file" | "runtime" | "host" | "journal";
2897
+ label: string;
2898
+ location?: string | undefined;
2899
+ };
2900
+ } | {
2901
+ lifecycle: "turn";
2902
+ kind: "event";
2903
+ event: {
2904
+ kind: "text";
2905
+ name: string;
2906
+ attributes?: Record<string, string | number>;
2907
+ text: string;
2908
+ } | {
2909
+ kind: "container";
2910
+ name: string;
2911
+ attributes?: Record<string, string | number>;
2912
+ children: ContextXmlElement[];
2913
+ };
2914
+ sourceId: string;
2915
+ provenance: {
2916
+ origin: "file" | "runtime" | "host" | "journal";
2917
+ label: string;
2918
+ location?: string | undefined;
2919
+ };
2920
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
2921
+ }>;
2922
+ declare const ContextSourcesSchema: s.Schema<({
2923
+ lifecycle: "session";
2924
+ kind: "instructions";
2925
+ channel: "system" | "developer" | "agents";
2926
+ content: string;
2927
+ sourceId: string;
2928
+ provenance: {
2929
+ origin: "file" | "runtime" | "host" | "journal";
2930
+ label: string;
2931
+ location?: string | undefined;
2932
+ };
2933
+ } | {
2934
+ lifecycle: "session";
2935
+ kind: "extension";
2936
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2937
+ name: string;
2938
+ content: string;
2939
+ sourceId: string;
2940
+ provenance: {
2941
+ origin: "file" | "runtime" | "host" | "journal";
2942
+ label: string;
2943
+ location?: string | undefined;
2944
+ };
2945
+ } | {
2946
+ lifecycle: "session";
2947
+ kind: "workspace";
2948
+ root: string;
2949
+ sourceId: string;
2950
+ provenance: {
2951
+ origin: "file" | "runtime" | "host" | "journal";
2952
+ label: string;
2953
+ location?: string | undefined;
2954
+ };
2955
+ } | {
2956
+ lifecycle: "turn";
2957
+ kind: "instructions";
2958
+ channel: "developer" | "agents";
2959
+ content: string;
2960
+ sourceId: string;
2961
+ provenance: {
2962
+ origin: "file" | "runtime" | "host" | "journal";
2963
+ label: string;
2964
+ location?: string | undefined;
2965
+ };
2966
+ } | {
2967
+ lifecycle: "turn";
2968
+ kind: "extension";
2969
+ extensionKind: "extension" | "skill" | "plugin" | "app" | "memory";
2970
+ name: string;
2971
+ content: string;
2972
+ sourceId: string;
2973
+ provenance: {
2974
+ origin: "file" | "runtime" | "host" | "journal";
2975
+ label: string;
2976
+ location?: string | undefined;
2977
+ };
2978
+ } | {
2979
+ lifecycle: "turn";
2980
+ kind: "document";
2981
+ name: string;
2982
+ mediaType: string;
2983
+ content: string;
2984
+ sourceId: string;
2985
+ provenance: {
2986
+ origin: "file" | "runtime" | "host" | "journal";
2987
+ label: string;
2988
+ location?: string | undefined;
2989
+ };
2990
+ } | {
2991
+ lifecycle: "turn";
2992
+ kind: "event";
2993
+ event: {
2994
+ kind: "text";
2995
+ name: string;
2996
+ attributes?: Record<string, string | number>;
2997
+ text: string;
2998
+ } | {
2999
+ kind: "container";
3000
+ name: string;
3001
+ attributes?: Record<string, string | number>;
3002
+ children: ContextXmlElement[];
3003
+ };
3004
+ sourceId: string;
3005
+ provenance: {
3006
+ origin: "file" | "runtime" | "host" | "journal";
3007
+ label: string;
3008
+ location?: string | undefined;
3009
+ };
3010
+ metadata?: string | number | boolean | _sorbetai_schema35.JsonArray | _sorbetai_schema35.JsonObject | null | undefined;
3011
+ })[]>;
3012
+ type ContextProvenance = s.Static<typeof ContextProvenanceSchema>;
3013
+ type InstructionsContextSource = s.Static<typeof InstructionsContextSourceSchema>;
3014
+ type ExtensionContextSource = s.Static<typeof ExtensionContextSourceSchema>;
3015
+ type WorkspaceContextSource = s.Static<typeof WorkspaceContextSourceSchema>;
3016
+ type DocumentContextSource = s.Static<typeof DocumentContextSourceSchema>;
3017
+ type EventContextSource = s.Static<typeof EventContextSourceSchema>;
3018
+ type PrefixContextSource = s.Static<typeof PrefixContextSourceSchema>;
3019
+ type TurnContextSource = s.Static<typeof TurnContextSourceSchema>;
3020
+ type ContextSource = s.Static<typeof ContextSourceSchema>;
3021
+ interface PrefixContextContributionInput {
3022
+ readonly signal?: AbortSignal;
3023
+ }
3024
+ /**
3025
+ * Supplies current fixed definitions before each logical model call. Returned
3026
+ * sources are rendered only into the replaceable prefix and must remain stable
3027
+ * unless their underlying definition changes.
3028
+ */
3029
+ interface PrefixContextContributor {
3030
+ readonly contributorId: string;
3031
+ /** Places this contributor's sources ahead of configured session sources. */
3032
+ readonly placement?: 'before-configured-sources';
3033
+ contribute(input: PrefixContextContributionInput): Promise<readonly PrefixContextSource[]>;
3034
+ }
3035
+ //#endregion
3036
+ //#region src/manager.d.ts
3037
+ interface ContextManagerOptions {
3038
+ readonly compiler?: ContextCompiler;
3039
+ /** Captured in registration order; invoked only when preparing a new logical request. */
3040
+ readonly preparationHooks?: readonly ContextPreparationHook[];
3041
+ }
3042
+ interface PrepareContextInput {
3043
+ /** Captured before reads, nested inside constructor Hooks; never invoked by restore. */
3044
+ readonly preparationHooks?: readonly ContextPreparationHook[];
3045
+ readonly inheritedSources?: readonly PrefixContextSource[];
3046
+ readonly sources?: readonly ContextSource[];
3047
+ readonly prefixContributors?: readonly PrefixContextContributor[];
3048
+ readonly stateOwners: readonly NamedStateOwner[];
3049
+ /** Complete desired model-visible catalog, captured before dynamic Context reads. */
3050
+ readonly tools?: readonly ToolDeclaration[];
3051
+ /** Stable identity of the admitted turn whose material is being prepared. */
3052
+ readonly turnScopeId: string;
3053
+ /** Sorbet logical model-call identity, allocated before preparation and never reused after commit. */
3054
+ readonly requestScopeId?: string;
3055
+ readonly requestSources?: readonly RequestContextSource[];
3056
+ /** Effective conversation supplied to preparation hooks. */
3057
+ readonly conversation?: readonly Message[];
3058
+ /** Runtime validates references and applies this request-local view before dispatch. */
3059
+ readonly modelView?: ContextModelView;
3060
+ /** Provides the initial model view to the ordered preparation Hooks. */
3061
+ readonly historySelection?: {
3062
+ readonly history: ContextHistorySnapshot;
3063
+ select(history: ContextHistorySnapshot, signal?: AbortSignal): Promise<ContextModelView | undefined>;
3064
+ };
3065
+ /** Raw conversation boundary before which a new frame must not move. */
3066
+ readonly afterMessageCount?: number;
3067
+ readonly signal?: AbortSignal;
3068
+ }
3069
+ interface ContextFramePlacement {
3070
+ readonly frameId: string;
3071
+ readonly contextEpoch: number;
3072
+ readonly afterMessageCount: number;
3073
+ readonly preparedAt: string;
3074
+ readonly placement?: RequestContextSource['placement'];
3075
+ }
3076
+ type ContextTransitionFrame = ContextFramePlacement & ({
3077
+ readonly kind: 'tools';
3078
+ readonly tools: ToolStateSnapshot;
3079
+ } | {
3080
+ readonly kind: 'named-state' | 'turn-material' | 'request-material';
3081
+ readonly stateName?: string;
3082
+ readonly stateRevision?: number;
3083
+ readonly message: ModelContextMessage;
3084
+ });
3085
+ /**
3086
+ * Owns committed prefix and per-name state revisions. Preparation is pure;
3087
+ * Runtime advances this owner only after the matching model.requested is durable.
3088
+ */
3089
+ declare class ContextManager {
3090
+ #private;
3091
+ constructor(options?: ContextManagerOptions);
3092
+ prepare(input: PrepareContextInput): Promise<ContextSnapshot>;
3093
+ /** Adopt the prepared value after its request fact is durable. Calls are serialized by the owner. */
3094
+ commit(snapshot: ContextSnapshot): void;
3095
+ restore(snapshots: readonly ContextSnapshot[], contextEpoch: number): void;
3096
+ frames(pending?: ContextSnapshot): readonly ContextTransitionFrame[];
3097
+ }
3098
+ /** Rebuilds retained frames, plus request-only material when its logical scope is selected. */
3099
+ declare function contextTransitionFrames(inputs: readonly ContextSnapshot[], contextEpoch: number, requestScopeId?: string): readonly ContextTransitionFrame[];
3100
+ //#endregion
3101
+ //#region src/prefix-layout.d.ts
3102
+ interface PrefixSourceFootprint {
3103
+ readonly sourceId: string;
3104
+ readonly kind: string;
3105
+ readonly provenance: ContextProvenance;
3106
+ readonly inherited: boolean;
3107
+ /** Non-overlapping UTF-16 offsets in the already-rendered immutable prefix. */
3108
+ readonly fromCharacter: number;
3109
+ readonly throughCharacter: number;
3110
+ }
3111
+ type PrefixSourceLayout = {
3112
+ readonly quality: 'measured';
3113
+ readonly sources: readonly PrefixSourceFootprint[];
3114
+ } | {
3115
+ readonly quality: 'unavailable';
3116
+ readonly reason: 'renderer_layout_mismatch';
3117
+ };
3118
+ /** Inspects v1's rendered prefix without rendering sources or interpreting their text again. */
3119
+ declare function inspectPrefixSourceLayout(prefix: PrefixSnapshot): PrefixSourceLayout;
3120
+ //#endregion
3121
+ //#region src/transitions.d.ts
3122
+ /** Projects declared request placement and immutable conversation boundaries. */
3123
+ declare function projectContextTransitions<T>(conversation: readonly T[], frames: readonly ContextTransitionFrame[]): (T | SystemMessage | UserMessage)[];
3124
+ declare function contextFrameMessage(frame: ContextTransitionFrame): SystemMessage | UserMessage;
3125
+ /** Applies Context frame boundaries to any conversation-aligned projection. */
3126
+ declare function projectContextTransitionValues<T>(conversation: readonly T[], frames: readonly ContextTransitionFrame[], conversationValue: (value: T) => T, frameValue: (frame: ContextTransitionFrame) => T): T[];
3127
+ //#endregion
3128
+ export { type AssistantMessage, AssistantMessageSchema, CONTEXT_ASSEMBLER_VERSION, CONTEXT_RENDERER_VERSION, CONTEXT_SNAPSHOT_SCHEMA_VERSION, type CompileContextInput, CompileContextInputSchema, type ContextAssemblyEvidence, ContextAssemblyEvidenceSchema, ContextCompiler, type ContextCompilerOptions, type ContextHistoryMessage, type ContextHistorySelectionScope, type ContextHistorySelector, type ContextHistorySnapshot, type ContextHistoryUnit, ContextManager, type ContextManagerOptions, ContextMessageReferenceProperties, ContextMessageReferenceSchema, type ContextModelView, ContextModelViewSchema, type ContextPreparationDraft, type ContextPreparationHook, ContextPreparationRejectedError, type ContextPreparationResult, ContextPreparationResultSchema, type ContextPreparationScope, type ContextProvenance, ContextProvenanceSchema, type ContextSnapshot, ContextSnapshotSchema, type ContextSource, ContextSourceSchema, ContextSourcesSchema, type ContextTransitionFrame, type ContextXmlElement, ContextXmlElementSchema, type DocumentContextSource, DocumentContextSourceSchema, type EventContextSource, EventContextSourceSchema, type ExtensionContextSource, ExtensionContextSourceSchema, type ImageContent, ImageContentSchema, type InstructionsContextSource, InstructionsContextSourceSchema, type JsonValue, JsonValueSchema, type Message, MessageSchema, type ModelContext, type ModelContextMessage, ModelContextMessageSchema, ModelContextSchema, type ModelInput, ModelInputSchema, type ModelRequestSettings, ModelRequestSettingsSchema, type NamedStateDelivery, NamedStateDeliverySchema, NamedStateNameSchema, type NamedStateOwner, type NamedStateReadInput, type NamedStateReadResult, NamedStateReadResultSchema, type NamedStateSnapshot, NamedStateSnapshotSchema, type PrefixContextContributionInput, type PrefixContextContributor, type PrefixContextSource, PrefixContextSourceSchema, type PrefixSnapshot, PrefixSnapshotSchema, type PrefixSourceFootprint, type PrefixSourceLayout, type PrepareContextInput, type ReadonlyJsonValue, type RequestContextSource, RequestContextSourceSchema, type RequestMaterialSnapshot, RequestMaterialSnapshotSchema, SessionExtensionContextSourceSchema, SessionInstructionsContextSourceSchema, type SystemMessage, SystemMessageSchema, type TextContent, TextContentSchema, type ThinkingContent, ThinkingContentSchema, type ToolCall, ToolCallProperties, ToolCallSchema, type ToolDeclaration, ToolDeclarationSchema, type ToolResultMessage, ToolResultMessageSchema, type ToolStateSnapshot, ToolStateSnapshotSchema, type TurnContextSource, TurnContextSourceSchema, TurnExtensionContextSourceSchema, TurnInstructionsContextSourceSchema, type TurnMaterialSnapshot, TurnMaterialSnapshotSchema, type Usage, UsageSchema, type UserMessage, UserMessageProperties, UserMessageSchema, type WorkspaceContextSource, WorkspaceContextSourceSchema, captureJsonValue, contextFrameMessage, contextTransitionFrames, inspectPrefixSourceLayout, projectContextTransitionValues, projectContextTransitions, runContextPreparation };
3129
+ //# sourceMappingURL=index.d.ts.map