@fungi.computer/shiitake 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/README.md +155 -34
  2. package/dist/agent-control.d.ts +78 -11
  3. package/dist/agent-control.js +273 -70
  4. package/dist/client-entry.d.ts +15 -8
  5. package/dist/client-entry.js +7 -5
  6. package/dist/client-wire.d.ts +24 -8
  7. package/dist/client-wire.js +53 -11
  8. package/dist/client.d.ts +56 -11
  9. package/dist/client.js +1 -1
  10. package/dist/cloudflare.d.ts +42 -23
  11. package/dist/cloudflare.js +76 -54
  12. package/dist/cold-sessions.d.ts +28 -0
  13. package/dist/cold-sessions.js +1 -0
  14. package/dist/delegation.d.ts +214 -0
  15. package/dist/delegation.js +319 -0
  16. package/dist/effect.d.ts +1 -1
  17. package/dist/errors.d.ts +2 -2
  18. package/dist/errors.js +2 -2
  19. package/dist/extension-contract.d.ts +10 -2
  20. package/dist/extensions.d.ts +6 -2
  21. package/dist/fleet.d.ts +52 -34
  22. package/dist/fleet.js +101 -63
  23. package/dist/hosted.js +1 -0
  24. package/dist/http-routes.d.ts +106 -22
  25. package/dist/http-routes.js +18 -1
  26. package/dist/index.d.ts +3 -2
  27. package/dist/internal/accepted-run-executor.d.ts +5 -0
  28. package/dist/internal/accepted-run-executor.js +10 -4
  29. package/dist/internal/admission-door.d.ts +3 -0
  30. package/dist/internal/admission-door.js +12 -2
  31. package/dist/internal/client-boundary.js +7 -1
  32. package/dist/internal/compaction/compaction-slot.d.ts +36 -0
  33. package/dist/internal/compaction/compaction-slot.js +41 -0
  34. package/dist/internal/compaction/compaction.d.ts +7 -4
  35. package/dist/internal/compaction/compaction.js +59 -30
  36. package/dist/internal/compaction/session-compaction.d.ts +8 -16
  37. package/dist/internal/compaction/session-compaction.js +358 -119
  38. package/dist/internal/compaction/settings.js +5 -0
  39. package/dist/internal/compaction/utils.d.ts +19 -16
  40. package/dist/internal/compaction/utils.js +30 -84
  41. package/dist/internal/contracts.d.ts +40 -13
  42. package/dist/internal/coordinator.js +28 -10
  43. package/dist/internal/effect-client.d.ts +4 -2
  44. package/dist/internal/effect-client.js +29 -0
  45. package/dist/internal/effect-contracts.d.ts +17 -4
  46. package/dist/internal/extension-runtime.d.ts +5 -0
  47. package/dist/internal/extension-runtime.js +184 -89
  48. package/dist/internal/host-meta.d.ts +7 -0
  49. package/dist/internal/model-acquisition.js +7 -1
  50. package/dist/internal/model-preference.d.ts +2 -0
  51. package/dist/internal/model-preference.js +2 -1
  52. package/dist/internal/promise-facade.js +4 -16
  53. package/dist/internal/run-failure-reason.d.ts +10 -0
  54. package/dist/internal/run-failure-reason.js +19 -0
  55. package/dist/internal/run-scope.d.ts +4 -1
  56. package/dist/internal/run-scope.js +38 -5
  57. package/dist/internal/runtime-coordinator.d.ts +2 -1
  58. package/dist/internal/runtime-coordinator.js +65 -4
  59. package/dist/internal/runtime-core.js +1 -0
  60. package/dist/internal/runtime-reconciliation.js +42 -6
  61. package/dist/internal/session-context.d.ts +1 -2
  62. package/dist/internal/session-context.js +8 -30
  63. package/dist/internal/session-status.d.ts +2 -1
  64. package/dist/internal/session-status.js +4 -1
  65. package/dist/internal/woodstock/client-projection.d.ts +6 -5
  66. package/dist/internal/woodstock/client-projection.js +79 -53
  67. package/dist/internal/woodstock/cold-sessions.d.ts +4 -0
  68. package/dist/internal/woodstock/cold-sessions.js +90 -0
  69. package/dist/internal/woodstock/extension-store.d.ts +2 -0
  70. package/dist/internal/woodstock/extension-store.js +4 -0
  71. package/dist/internal/woodstock/fleet-store.d.ts +3 -3
  72. package/dist/internal/woodstock/fleet-store.js +16 -11
  73. package/dist/internal/woodstock/index.d.ts +11 -3
  74. package/dist/internal/woodstock/index.js +33 -14
  75. package/dist/internal/woodstock/progress.d.ts +14 -1
  76. package/dist/internal/woodstock/progress.js +97 -19
  77. package/dist/internal/woodstock/run-recovery.js +6 -4
  78. package/dist/internal/woodstock/session-attention.d.ts +1 -1
  79. package/dist/internal/woodstock/session-attention.js +2 -2
  80. package/dist/internal/woodstock/session-entry.d.ts +109 -42
  81. package/dist/internal/woodstock/session-entry.js +63 -20
  82. package/dist/internal/woodstock/session-inbox.js +2 -0
  83. package/dist/internal/woodstock/session-store.d.ts +104 -24
  84. package/dist/internal/woodstock/session-store.js +937 -246
  85. package/dist/internal/woodstock/storage-admission.d.ts +8 -8
  86. package/dist/internal/woodstock/storage-admission.js +8 -34
  87. package/dist/internal/woodstock/storage-conformance.d.ts +15 -0
  88. package/dist/internal/woodstock/storage-conformance.js +489 -0
  89. package/dist/model-preference.d.ts +2 -2
  90. package/dist/model-preference.js +2 -2
  91. package/dist/node.js +1 -1
  92. package/dist/remote-client.js +8 -1
  93. package/dist/session-attention.d.ts +8 -1
  94. package/dist/session-attention.js +6 -1
  95. package/dist/testing.js +1 -0
  96. package/docs/api/README.md +18 -16
  97. package/docs/api/agent-control.md +172 -2
  98. package/docs/api/client-entry.md +26 -10
  99. package/docs/api/client.md +153 -37
  100. package/docs/api/cloudflare.md +76 -23
  101. package/docs/api/delegation.md +485 -0
  102. package/docs/api/effect.md +20 -2
  103. package/docs/api/extensions.md +21 -9
  104. package/docs/api/fleet.md +149 -122
  105. package/docs/api/http.md +4 -1
  106. package/docs/api/index.md +116 -20
  107. package/docs/api/internal/woodstock/storage-conformance.md +81 -0
  108. package/docs/api/model-preference.md +17 -0
  109. package/docs/api/testing.md +16 -4
  110. package/package.json +26 -14
  111. package/dist/internal/browser-sessions.d.ts +0 -31
  112. package/dist/internal/browser-sessions.js +0 -173
@@ -38,13 +38,36 @@ is an ordinary outcome, never an error.
38
38
 
39
39
  ---
40
40
 
41
+ ### UnknownRequest
42
+
43
+ ```ts
44
+ type UnknownRequest = Readonly<{
45
+ status: "unknown";
46
+ }>;
47
+ ```
48
+
49
+ No command has been admitted under this request key in the addressed Session.
50
+
51
+ ---
52
+
41
53
  ### CancelResult
42
54
 
43
55
  ```ts
44
- type CancelResult = Accepted | TooLate;
56
+ type CancelResult = Accepted | TooLate | UnknownRequest;
57
+ ```
58
+
59
+ Outcome of one cancel command or request-based recall.
60
+
61
+ ---
62
+
63
+ ### WithdrawResult
64
+
65
+ ```ts
66
+ type WithdrawResult = Accepted | UnknownRequest;
45
67
  ```
46
68
 
47
- Outcome of one cancel command.
69
+ Atomic admission resolution: accepted work is kept; an unknown key is fenced
70
+ forever.
48
71
 
49
72
  ---
50
73
 
@@ -212,11 +235,39 @@ Optional controls for the Promise-friendly text sender.
212
235
 
213
236
  ---
214
237
 
238
+ ### ModelMessage
239
+
240
+ ```ts
241
+ type ModelMessage =
242
+ | Exclude<
243
+ Message,
244
+ {
245
+ role: "toolResult";
246
+ }
247
+ >
248
+ | Omit<
249
+ Extract<
250
+ Message,
251
+ {
252
+ role: "toolResult";
253
+ }
254
+ >,
255
+ "details"
256
+ >;
257
+ ```
258
+
259
+ Model-facing Pi content. Application tool display payloads belong to the
260
+ surrounding entry's `data`, never to a message sent back to a provider.
261
+
262
+ ---
263
+
215
264
  ### SessionMessage
216
265
 
217
266
  ```ts
218
267
  type SessionMessage = Readonly<{
268
+ requestId?: string;
219
269
  meta?: Json;
270
+ data?: Json;
220
271
  origin?: Readonly<{
221
272
  extensionId: string;
222
273
  correlation: string | null;
@@ -224,11 +275,11 @@ type SessionMessage = Readonly<{
224
275
  id: string;
225
276
  sequence: number;
226
277
  commandId: string | null;
227
- value: Message;
278
+ value: ModelMessage;
228
279
  }>;
229
280
  ```
230
281
 
231
- One exact completed Pi message on the selected Session lineage.
282
+ One completed model message and its separate application payload.
232
283
 
233
284
  ---
234
285
 
@@ -368,6 +419,22 @@ Generic Agent-scope extension controls.
368
419
 
369
420
  ---
370
421
 
422
+ ### SessionToolOutput
423
+
424
+ ```ts
425
+ type SessionToolOutput = Readonly<{
426
+ toolCallId: string;
427
+ revision: number;
428
+ tail: string;
429
+ droppedBytes: number;
430
+ totalBytes: number;
431
+ }>;
432
+ ```
433
+
434
+ Process-local running tool tail; never a durable Session fact.
435
+
436
+ ---
437
+
371
438
  ### SessionProgress
372
439
 
373
440
  ```ts
@@ -389,6 +456,7 @@ Process-local assistant progress; never a durable Session fact.
389
456
 
390
457
  ```ts
391
458
  type SessionPendingPrompt = Readonly<{
459
+ requestId: string;
392
460
  meta?: SessionMessage["meta"];
393
461
  origin?: SessionMessage["origin"];
394
462
  commandId: string;
@@ -454,14 +522,17 @@ type SessionCompactionNotice = Readonly<{
454
522
  sequence: number;
455
523
  at: number;
456
524
  trigger: SessionCompactionTrigger;
457
- result: "nothing_to_compact" | "failed";
525
+ result: "nothing_to_compact" | "failed" | "stale" | "insufficient";
458
526
  diagnostic: string | null;
459
527
  }>;
460
528
  ```
461
529
 
462
530
  A compaction that changed nothing: a manual request with nothing to summarize
463
- yet, or a compaction that failed. Automatic failures are never silent; each one
464
- is a notice at its own place in the timeline.
531
+ yet, a compaction that failed, or a finished background summary dropped
532
+ unplaced: stale because the context had moved past its head, or insufficient
533
+ because placing it would have left the context over the limit. Automatic
534
+ failures are never silent; each one is a notice at its own place in the
535
+ timeline.
465
536
 
466
537
  ---
467
538
 
@@ -495,6 +566,7 @@ type SessionSnapshot = Readonly<{
495
566
  pending: SessionPendingPrompts;
496
567
  activity: SessionActivity;
497
568
  progress: SessionProgress | null;
569
+ toolOutput: readonly SessionToolOutput[];
498
570
  extensions: SessionExtensionSlots;
499
571
  attention: readonly SessionAttention[];
500
572
  context?: SessionContext;
@@ -509,6 +581,11 @@ Bounded Session baseline at one opaque owner cursor.
509
581
 
510
582
  ```ts
511
583
  type SessionFrame =
584
+ | Readonly<{
585
+ kind: "tool_output";
586
+ toolOutput: readonly SessionToolOutput[];
587
+ activity: SessionActivity;
588
+ }>
512
589
  | Readonly<{
513
590
  kind: "update";
514
591
  delivery: "replay" | "live";
@@ -598,9 +675,11 @@ Race-safe baseline plus live changes resource.
598
675
  type ShiitakeSession = Readonly<{
599
676
  address: string;
600
677
  command: SessionCommandHandler;
678
+ withdraw: (requestId) => Promise<WithdrawResult>;
601
679
  abort: () => Promise<void>;
602
680
  send: (text, options?) => Promise<Accepted>;
603
681
  cancel: (input) => Promise<CancelResult>;
682
+ latestPending: () => Promise<SessionPendingPrompt | null>;
604
683
  extension: (extensionId) => SessionExtensionControls;
605
684
  modelPreference: Readonly<{
606
685
  read: () => Promise<ModelPreference | null>;
@@ -813,36 +892,6 @@ One Agent bound to one extension contract.
813
892
 
814
893
  ---
815
894
 
816
- ### OperatorCommand
817
-
818
- ```ts
819
- type OperatorCommand = Extract<
820
- SessionCommand,
821
- Readonly<{
822
- type: "operator";
823
- }>
824
- >;
825
- ```
826
-
827
- Public command that records one operator or party line without a run.
828
-
829
- ---
830
-
831
- ### TitleCommand
832
-
833
- ```ts
834
- type TitleCommand = Extract<
835
- SessionCommand,
836
- Readonly<{
837
- type: "title";
838
- }>
839
- >;
840
- ```
841
-
842
- Public command that sets or clears the user's Session title.
843
-
844
- ---
845
-
846
895
  ### ShiitakeClientOptions
847
896
 
848
897
  ```ts
@@ -877,6 +926,26 @@ Decode a durable command acceptance value at an RPC boundary.
877
926
 
878
927
  ## Functions
879
928
 
929
+ ### parseWithdrawResult()
930
+
931
+ ```ts
932
+ function parseWithdrawResult(value): WithdrawResult;
933
+ ```
934
+
935
+ Decode the owner's atomic request resolution.
936
+
937
+ #### Parameters
938
+
939
+ | Parameter | Type |
940
+ | --------- | -------- |
941
+ | `value` | `string` |
942
+
943
+ #### Returns
944
+
945
+ [`WithdrawResult`](#withdrawresult)
946
+
947
+ ---
948
+
880
949
  ### parseAccepted()
881
950
 
882
951
  ```ts
@@ -917,6 +986,41 @@ Parse one serialized cancel outcome: accepted, or too late.
917
986
 
918
987
  ---
919
988
 
989
+ ### parseLatestPendingPrompt()
990
+
991
+ ```ts
992
+ function parseLatestPendingPrompt(value): Readonly<{
993
+ requestId: string;
994
+ meta?: Json;
995
+ origin?: Readonly<{
996
+ extensionId: string;
997
+ correlation: string | null;
998
+ }>;
999
+ commandId: string;
1000
+ text: string;
1001
+ images?: readonly object[];
1002
+ delivery: PromptDelivery;
1003
+ }> | null;
1004
+ ```
1005
+
1006
+ Decode the host-authorized newest pending lookup, including an empty result.
1007
+
1008
+ #### Parameters
1009
+
1010
+ | Parameter | Type |
1011
+ | --------- | -------- |
1012
+ | `value` | `string` |
1013
+
1014
+ #### Returns
1015
+
1016
+ \| `Readonly`\<\{ `requestId`: `string`; `meta?`: [`Json`](extensions.md#json);
1017
+ `origin?`: `Readonly`\<\{ `extensionId`: `string`; `correlation`: `string` \|
1018
+ `null`; \}\>; `commandId`: `string`; `text`: `string`; `images?`: readonly
1019
+ `object`[]; `delivery`: [`PromptDelivery`](index.md#promptdelivery); \}\> \|
1020
+ `null`
1021
+
1022
+ ---
1023
+
920
1024
  ### parseShiitakeError()
921
1025
 
922
1026
  ```ts
@@ -1089,6 +1193,12 @@ Re-exports [ForkCommand](index.md#forkcommand)
1089
1193
 
1090
1194
  ---
1091
1195
 
1196
+ ### OperatorCommand
1197
+
1198
+ Re-exports [OperatorCommand](index.md#operatorcommand)
1199
+
1200
+ ---
1201
+
1092
1202
  ### PromptCommand
1093
1203
 
1094
1204
  Re-exports [PromptCommand](index.md#promptcommand)
@@ -1107,6 +1217,12 @@ Re-exports [SessionCommand](index.md#sessioncommand)
1107
1217
 
1108
1218
  ---
1109
1219
 
1220
+ ### TitleCommand
1221
+
1222
+ Re-exports [TitleCommand](index.md#titlecommand)
1223
+
1224
+ ---
1225
+
1110
1226
  ### ModelPreference
1111
1227
 
1112
1228
  Re-exports [ModelPreference](index.md#modelpreference)
@@ -78,6 +78,24 @@ Close owned resources before storage erasure; a cold owner has none.
78
78
 
79
79
  `Promise`\<`void`\>
80
80
 
81
+ ##### hasStoredSession()
82
+
83
+ ```ts
84
+ hasStoredSession(sessionId): Promise<boolean>;
85
+ ```
86
+
87
+ Indexed owner-local existence check; corrupt stored Sessions remain unavailable.
88
+
89
+ ###### Parameters
90
+
91
+ | Parameter | Type |
92
+ | ----------- | -------- |
93
+ | `sessionId` | `string` |
94
+
95
+ ###### Returns
96
+
97
+ `Promise`\<`boolean`\>
98
+
81
99
  ##### readInboxChanges()
82
100
 
83
101
  ```ts
@@ -109,6 +127,36 @@ Bounded strict-after read of this Agent's changed inbox rows.
109
127
  `sessionId`: `string`; `deleted`: `true`; \}\>)[]; `through`: `number`;
110
128
  `latest`: `number`; \}\>\>
111
129
 
130
+ ##### readColdSessions()
131
+
132
+ ```ts
133
+ readColdSessions(request): Promise<Readonly<{
134
+ sessions: readonly Readonly<{
135
+ sessionId: string;
136
+ bytes: number;
137
+ lastActivityAt: number;
138
+ idle: boolean;
139
+ }>[];
140
+ next?: string;
141
+ }>>;
142
+ ```
143
+
144
+ One bounded, read-only page of Sessions with stored bytes, last activity and an
145
+ idle flag, coldest first. The store keeper's only view of cold Sessions; it
146
+ carries no SQL, transaction or write.
147
+
148
+ ###### Parameters
149
+
150
+ | Parameter | Type |
151
+ | --------- | ----------------------------------------------------------- |
152
+ | `request` | [`ColdSessionPageRequest`](index.md#coldsessionpagerequest) |
153
+
154
+ ###### Returns
155
+
156
+ `Promise`\<`Readonly`\<\{ `sessions`: readonly `Readonly`\<\{ `sessionId`:
157
+ `string`; `bytes`: `number`; `lastActivityAt`: `number`; `idle`: `boolean`;
158
+ \}\>[]; `next?`: `string`; \}\>\>
159
+
112
160
  ##### readInboxRevision()
113
161
 
114
162
  ```ts
@@ -251,7 +299,7 @@ DurableObject.alarm;
251
299
  fetch(request): Promise<Response>;
252
300
  ```
253
301
 
254
- Route an authenticated client request through the owner.
302
+ Route an authenticated client request through the host's routes, then the owner.
255
303
 
256
304
  ###### Parameters
257
305
 
@@ -279,6 +327,9 @@ type CloudflareShiitakeState = Readonly<{
279
327
  Pick<DurableObjectStorage, "getAlarm" | "setAlarm" | "deleteAlarm"> &
280
328
  object;
281
329
  waitUntil: (task) => void;
330
+ id?: Readonly<{
331
+ toString: () => string;
332
+ }>;
282
333
  }>;
283
334
  ```
284
335
 
@@ -353,14 +404,13 @@ type CloudflareShiitakeOptions = Readonly<{
353
404
  model: ModelSource;
354
405
  instructions: InstructionSource;
355
406
  tools?: readonly [] | CloudflareShiitakeTools;
356
- storageBudget?: StorageBudget;
407
+ storagePressure?: StoragePressureCheck;
357
408
  compaction?: CompactionOptions;
358
409
  extensions: ExtensionRosterV0;
359
410
  initialize?: (agent) => Promise<void>;
360
411
  hostWork?: readonly CloudflareHostWork[];
361
412
  hostJobs?: CloudflareHostJobs;
362
413
  mailRoom?: BirdDogEffect;
363
- browser?: (sessionId) => BrowserHost;
364
414
  acp?: (agent) => Promise<CloudflareShiitakeAcpServer>;
365
415
  }>;
366
416
  ```
@@ -382,10 +432,6 @@ type CloudflareShiitake = ShiitakeOwnerAgent &
382
432
  alarm: () => Promise<void>;
383
433
  activeSessions: () => Promise<readonly string[]>;
384
434
  abortActive: () => Promise<void>;
385
- browser: Readonly<{
386
- fetch: (request) => Promise<Response>;
387
- clear: () => Promise<void>;
388
- }>;
389
435
  }>;
390
436
  ```
391
437
 
@@ -393,19 +439,6 @@ Cloudflare host lifecycle; alarm forwarding stays outside the neutral client.
393
439
 
394
440
  ---
395
441
 
396
- ### BrowserHost
397
-
398
- ```ts
399
- type BrowserHost = Readonly<{
400
- modules: readonly ModuleRegistration[];
401
- fetch: (request) => Promise<Response>;
402
- }>;
403
- ```
404
-
405
- The maintained browser transport and its Session-bound tool descriptors.
406
-
407
- ---
408
-
409
442
  ### SessionInboxChanges
410
443
 
411
444
  ```ts
@@ -459,16 +492,18 @@ delivers grants.
459
492
  ### makeCloudflareShiitake()
460
493
 
461
494
  ```ts
462
- function makeCloudflareShiitake(state, options): Promise<CloudflareShiitake>;
495
+ function makeCloudflareShiitake(unnamed, options): Promise<CloudflareShiitake>;
463
496
  ```
464
497
 
465
- Construct Shiitake over one Durable Object's SQLite and lifetime.
498
+ Open Shiitake over one Durable Object's storage. It resolves once the runtime is
499
+ started and `initialize` has run; if `initialize` throws, the runtime is closed
500
+ and the error is rethrown.
466
501
 
467
502
  #### Parameters
468
503
 
469
504
  | Parameter | Type |
470
505
  | --------- | --------------------------------------------------------- |
471
- | `state` | [`CloudflareShiitakeState`](#cloudflareshiitakestate) |
506
+ | `unnamed` | [`CloudflareShiitakeState`](#cloudflareshiitakestate) |
472
507
  | `options` | [`CloudflareShiitakeOptions`](#cloudflareshiitakeoptions) |
473
508
 
474
509
  #### Returns
@@ -477,6 +512,24 @@ Construct Shiitake over one Durable Object's SQLite and lifetime.
477
512
 
478
513
  ## References
479
514
 
515
+ ### ColdSessionPage
516
+
517
+ Re-exports [ColdSessionPage](index.md#coldsessionpage)
518
+
519
+ ---
520
+
521
+ ### ColdSessionPageRequest
522
+
523
+ Re-exports [ColdSessionPageRequest](index.md#coldsessionpagerequest)
524
+
525
+ ---
526
+
527
+ ### ColdSessionRow
528
+
529
+ Re-exports [ColdSessionRow](index.md#coldsessionrow)
530
+
531
+ ---
532
+
480
533
  ### GrantsDelivery
481
534
 
482
535
  Re-exports [GrantsDelivery](index.md#grantsdelivery)