@fungi.computer/shiitake 0.5.0 → 0.7.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 (88) hide show
  1. package/README.md +59 -21
  2. package/dist/agent-control.d.ts +94 -2
  3. package/dist/agent-control.js +147 -26
  4. package/dist/client-entry.d.ts +20 -0
  5. package/dist/client-entry.js +5 -0
  6. package/dist/client-visitor.d.ts +33 -0
  7. package/dist/client-visitor.js +231 -0
  8. package/dist/client-wire.d.ts +9 -0
  9. package/dist/client-wire.js +24 -3
  10. package/dist/client.d.ts +27 -6
  11. package/dist/client.js +23 -0
  12. package/dist/cloudflare.d.ts +20 -0
  13. package/dist/cloudflare.js +4 -1
  14. package/dist/delegation.d.ts +79 -53
  15. package/dist/delegation.js +26 -21
  16. package/dist/effect.d.ts +26 -1
  17. package/dist/effect.js +14 -1
  18. package/dist/errors.d.ts +2 -2
  19. package/dist/errors.js +2 -0
  20. package/dist/extensions.d.ts +22 -3
  21. package/dist/extensions.js +1 -1
  22. package/dist/fleet.d.ts +25 -2
  23. package/dist/fleet.js +108 -24
  24. package/dist/hosted.js +3 -0
  25. package/dist/http-routes.d.ts +23 -9
  26. package/dist/http.d.ts +1 -0
  27. package/dist/http.js +1 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/internal/accepted-run-executor.js +2 -1
  30. package/dist/internal/admission-door.d.ts +6 -1
  31. package/dist/internal/admission-door.js +33 -3
  32. package/dist/internal/contracts.d.ts +19 -1
  33. package/dist/internal/coordinator.js +115 -52
  34. package/dist/internal/effect-client.js +1 -1
  35. package/dist/internal/effect-contracts.d.ts +9 -2
  36. package/dist/internal/extension-command-registry.d.ts +2 -1
  37. package/dist/internal/extension-command-registry.js +3 -1
  38. package/dist/internal/extension-runtime.d.ts +3 -1
  39. package/dist/internal/extension-runtime.js +18 -8
  40. package/dist/internal/model-acquisition.js +2 -0
  41. package/dist/internal/observation-kernel.d.ts +2 -0
  42. package/dist/internal/observation-kernel.js +17 -6
  43. package/dist/internal/promise-facade.js +2 -0
  44. package/dist/internal/run-scope.d.ts +14 -0
  45. package/dist/internal/run-scope.js +58 -15
  46. package/dist/internal/runtime-coordinator.d.ts +14 -0
  47. package/dist/internal/runtime-coordinator.js +60 -11
  48. package/dist/internal/runtime-core.d.ts +3 -0
  49. package/dist/internal/runtime-core.js +1 -0
  50. package/dist/internal/runtime-reconciliation.js +123 -25
  51. package/dist/internal/session-context.d.ts +5 -5
  52. package/dist/internal/session-context.js +80 -83
  53. package/dist/internal/session-status.d.ts +2 -2
  54. package/dist/internal/session-status.js +5 -3
  55. package/dist/internal/woodstock/agent-reply.d.ts +5 -0
  56. package/dist/internal/woodstock/agent-reply.js +3 -0
  57. package/dist/internal/woodstock/client-projection.js +13 -11
  58. package/dist/internal/woodstock/fleet-store.d.ts +3 -2
  59. package/dist/internal/woodstock/fleet-store.js +24 -4
  60. package/dist/internal/woodstock/index.d.ts +7 -3
  61. package/dist/internal/woodstock/index.js +23 -6
  62. package/dist/internal/woodstock/progress.d.ts +11 -1
  63. package/dist/internal/woodstock/progress.js +126 -25
  64. package/dist/internal/woodstock/session-delegator.d.ts +13 -0
  65. package/dist/internal/woodstock/session-delegator.js +44 -0
  66. package/dist/internal/woodstock/session-entry.d.ts +12 -2
  67. package/dist/internal/woodstock/session-store.d.ts +16 -2
  68. package/dist/internal/woodstock/session-store.js +349 -66
  69. package/dist/internal/woodstock/work-senders.d.ts +32 -0
  70. package/dist/internal/woodstock/work-senders.js +70 -0
  71. package/dist/node.js +11 -2
  72. package/dist/remote-client.js +7 -2
  73. package/dist/server-visitor-stream.d.ts +13 -0
  74. package/dist/server-visitor-stream.js +124 -0
  75. package/dist/session-attention.d.ts +30 -0
  76. package/dist/session-attention.js +14 -0
  77. package/docs/api/agent-control.md +212 -15
  78. package/docs/api/client-entry.md +3 -0
  79. package/docs/api/client.md +209 -5
  80. package/docs/api/cloudflare.md +23 -1
  81. package/docs/api/delegation.md +284 -77
  82. package/docs/api/effect.md +100 -12
  83. package/docs/api/extensions.md +73 -12
  84. package/docs/api/fleet.md +138 -25
  85. package/docs/api/http.md +28 -0
  86. package/docs/api/index.md +43 -17
  87. package/docs/api/testing.md +9 -7
  88. package/package.json +10 -6
@@ -19,7 +19,12 @@ type ShiitakeEffectHost = Readonly<{
19
19
  commandId,
20
20
  ) => Effect.Effect<CommandSettlement | undefined, ShiitakeError>;
21
21
  agent: ShiitakeEffectOwner;
22
- acceptMail: (mail, meta?, reply?) => Effect.Effect<Accepted, ShiitakeError>;
22
+ acceptMail: (
23
+ mail,
24
+ meta?,
25
+ reply?,
26
+ stageAcceptedNotice?,
27
+ ) => Effect.Effect<Accepted, ShiitakeError>;
23
28
  }>;
24
29
  ```
25
30
 
@@ -36,6 +41,7 @@ type ModelAcquisitionEffect = Readonly<{
36
41
  retryAfterMs?: (message) => number | undefined;
37
42
  retryable: (message) => boolean;
38
43
  failureReason?: (message) => string | undefined;
44
+ rejection?: (message) => ProviderRejection | undefined;
39
45
  providerError?: (message) => string | undefined;
40
46
  release: Effect.Effect<void, ShiitakeError>;
41
47
  }>;
@@ -114,6 +120,9 @@ type ShiitakeEffectOptions = Readonly<{
114
120
  meta?: HostMetaOptions;
115
121
  store: SqliteOwner;
116
122
  storagePressure?: StoragePressureCheck;
123
+ admission?: Readonly<{
124
+ assertOpen: () => void;
125
+ }>;
117
126
  compaction?: CompactionOptions;
118
127
  hostJobs?: Readonly<{
119
128
  lane: string;
@@ -157,6 +166,7 @@ type ShiitakeEffectCommandHandler = {
157
166
  Readonly<{
158
167
  status: "accepted";
159
168
  commandId: string;
169
+ sessionId?: string;
160
170
  }>,
161
171
  ShiitakeError
162
172
  >;
@@ -187,6 +197,7 @@ Effect-native addressable Session handle.
187
197
  (input): Effect<Readonly<{
188
198
  status: "accepted";
189
199
  commandId: string;
200
+ sessionId?: string;
190
201
  }>, ShiitakeError>;
191
202
  ```
192
203
 
@@ -200,8 +211,8 @@ Accept one durable prompt command.
200
211
 
201
212
  ##### Returns
202
213
 
203
- `Effect`\<`Readonly`\<\{ `status`: `"accepted"`; `commandId`: `string`; \}\>,
204
- [`ShiitakeError`](index.md#shiitakeerror)\>
214
+ `Effect`\<`Readonly`\<\{ `status`: `"accepted"`; `commandId`: `string`;
215
+ `sessionId?`: `string`; \}\>, [`ShiitakeError`](index.md#shiitakeerror)\>
205
216
 
206
217
  #### Call Signature
207
218
 
@@ -340,7 +351,7 @@ Effect-native addressable Session handle.
340
351
 
341
352
  ```ts
342
353
  type ShiitakeEffectSessionExtension = Readonly<{
343
- call: (command, input) => Effect.Effect<Json, ShiitakeError>;
354
+ call: (command, input, caller?) => Effect.Effect<Json, ShiitakeError>;
344
355
  }>;
345
356
  ```
346
357
 
@@ -482,16 +493,23 @@ function openHost(options, mailRoom): Effect<Readonly<{
482
493
  readSettlement: (sessionId, commandId) => Effect<
483
494
  | Readonly<{
484
495
  acceptedSender: string | null;
496
+ delegator: string | null;
485
497
  terminal: SessionTerminal;
486
498
  content: string;
487
499
  usage: readonly Pick<AssistantMessage, ... | ... | ...>[];
488
500
  toolCalls: number;
501
+ waitingOnYou: readonly Readonly<{
502
+ itemId: ...;
503
+ kind: ...;
504
+ summary: ...;
505
+ }>[];
489
506
  }>
490
507
  | undefined, ShiitakeError>;
491
508
  agent: ShiitakeEffectOwner;
492
- acceptMail: (mail, meta?, reply?) => Effect<Readonly<{
509
+ acceptMail: (mail, meta?, reply?, stageAcceptedNotice?) => Effect<Readonly<{
493
510
  status: "accepted";
494
511
  commandId: string;
512
+ sessionId?: string;
495
513
  }>, ShiitakeError>;
496
514
  }>, ShiitakeError>;
497
515
  ```
@@ -508,13 +526,16 @@ Open the Effect-native host composition with addressed mail.
508
526
  #### Returns
509
527
 
510
528
  `Effect`\<`Readonly`\<\{ `readSettlement`: (`sessionId`, `commandId`) =>
511
- `Effect`\< \| `Readonly`\<\{ `acceptedSender`: `string` \| `null`; `terminal`:
512
- [`SessionTerminal`](client.md#sessionterminal); `content`: `string`; `usage`:
513
- readonly `Pick`\<`AssistantMessage`, ... \| ... \| ...\>[]; `toolCalls`:
514
- `number`; \}\> \| `undefined`, [`ShiitakeError`](index.md#shiitakeerror)\>;
515
- `agent`: [`ShiitakeEffectOwner`](#shiitakeeffectowner); `acceptMail`: (`mail`,
516
- `meta?`, `reply?`) => `Effect`\<`Readonly`\<\{ `status`: `"accepted"`;
517
- `commandId`: `string`; \}\>, [`ShiitakeError`](index.md#shiitakeerror)\>; \}\>,
529
+ `Effect`\< \| `Readonly`\<\{ `acceptedSender`: `string` \| `null`; `delegator`:
530
+ `string` \| `null`; `terminal`: [`SessionTerminal`](client.md#sessionterminal);
531
+ `content`: `string`; `usage`: readonly `Pick`\<`AssistantMessage`, ... \| ... \|
532
+ ...\>[]; `toolCalls`: `number`; `waitingOnYou`: readonly `Readonly`\<\{
533
+ `itemId`: ...; `kind`: ...; `summary`: ...; \}\>[]; \}\> \| `undefined`,
534
+ [`ShiitakeError`](index.md#shiitakeerror)\>; `agent`:
535
+ [`ShiitakeEffectOwner`](#shiitakeeffectowner); `acceptMail`: (`mail`, `meta?`,
536
+ `reply?`, `stageAcceptedNotice?`) => `Effect`\<`Readonly`\<\{ `status`:
537
+ `"accepted"`; `commandId`: `string`; `sessionId?`: `string`; \}\>,
538
+ [`ShiitakeError`](index.md#shiitakeerror)\>; \}\>,
518
539
  [`ShiitakeError`](index.md#shiitakeerror)\>
519
540
 
520
541
  ---
@@ -552,6 +573,67 @@ for it. An unreadable Session is its own `unavailable` row.
552
573
  [`StoredSessionSummaryRow`](#storedsessionsummaryrow)[]; `next`: `string` \|
553
574
  `undefined`; \}\>, [`ShiitakeError`](index.md#shiitakeerror), `never`\>
554
575
 
576
+ ---
577
+
578
+ ### readStoredSessionStates()
579
+
580
+ ```ts
581
+ function readStoredSessionStates(
582
+ owner,
583
+ after?,
584
+ ): Effect<
585
+ Readonly<{
586
+ sessions: readonly SessionSummaryRow[];
587
+ next: string | undefined;
588
+ }>,
589
+ ShiitakeError,
590
+ never
591
+ >;
592
+ ```
593
+
594
+ One page of saved conversations with their stored run state (needs_you, running,
595
+ errored, done), in tier then newest-activity order, read from the store alone:
596
+ no Agent runtime starts. The state is as the runtime last wrote it, so it can
597
+ lag work a stopped runtime left behind.
598
+
599
+ #### Parameters
600
+
601
+ | Parameter | Type |
602
+ | --------- | ------------------------------------- |
603
+ | `owner` | [`SqliteOwner`](index.md#sqliteowner) |
604
+ | `after?` | `string` |
605
+
606
+ #### Returns
607
+
608
+ `Effect`\<`Readonly`\<\{ `sessions`: readonly
609
+ [`SessionSummaryRow`](client.md#sessionsummaryrow)[]; `next`: `string` \|
610
+ `undefined`; \}\>, [`ShiitakeError`](index.md#shiitakeerror), `never`\>
611
+
612
+ ---
613
+
614
+ ### readStoredAttention()
615
+
616
+ ```ts
617
+ function readStoredAttention(
618
+ owner,
619
+ sessionId,
620
+ ): Effect<readonly object[], ShiitakeError, never>;
621
+ ```
622
+
623
+ One saved conversation's open attention items, read from the store alone.
624
+
625
+ #### Parameters
626
+
627
+ | Parameter | Type |
628
+ | ----------- | ------------------------------------- |
629
+ | `owner` | [`SqliteOwner`](index.md#sqliteowner) |
630
+ | `sessionId` | `string` |
631
+
632
+ #### Returns
633
+
634
+ `Effect`\<readonly `object`[], [`ShiitakeError`](index.md#shiitakeerror),
635
+ `never`\>
636
+
555
637
  ## References
556
638
 
557
639
  ### AbortCommand
@@ -650,6 +732,12 @@ Re-exports [SessionProgress](client.md#sessionprogress)
650
732
 
651
733
  ---
652
734
 
735
+ ### SessionProgressDelta
736
+
737
+ Re-exports [SessionProgressDelta](client.md#sessionprogressdelta)
738
+
739
+ ---
740
+
653
741
  ### SessionToolOutput
654
742
 
655
743
  Re-exports [SessionToolOutput](client.md#sessiontooloutput)
@@ -162,7 +162,7 @@ The door refused an extension admission.
162
162
  #### Extends
163
163
 
164
164
  - `YieldableError`\<`this`\> & `object` & `Readonly`\<\{ `reason`: `"closed"` \|
165
- `"conflict"` \| `"invalid"`; `message`: `string`; \}\>
165
+ `"conflict"` \| `"invalid"` \| `"archived"`; `message`: `string`; \}\>
166
166
 
167
167
  #### Constructors
168
168
 
@@ -174,11 +174,11 @@ new AdmissionError(args): AdmissionError;
174
174
 
175
175
  ###### Parameters
176
176
 
177
- | Parameter | Type |
178
- | -------------- | ------------------------------------------------------------------------------- |
179
- | `args` | \{ `reason`: `"closed"` \| `"conflict"` \| `"invalid"`; `message`: `string`; \} |
180
- | `args.reason` | `"closed"` \| `"conflict"` \| `"invalid"` |
181
- | `args.message` | `string` |
177
+ | Parameter | Type |
178
+ | -------------- | ----------------------------------------------------------------------------------------------- |
179
+ | `args` | \{ `reason`: `"closed"` \| `"conflict"` \| `"invalid"` \| `"archived"`; `message`: `string`; \} |
180
+ | `args.reason` | `"closed"` \| `"conflict"` \| `"invalid"` \| `"archived"` |
181
+ | `args.message` | `string` |
182
182
 
183
183
  ###### Returns
184
184
 
@@ -188,7 +188,7 @@ new AdmissionError(args): AdmissionError;
188
188
 
189
189
  ```ts
190
190
  Data.TaggedError("AdmissionError")<{
191
- reason: "invalid" | "conflict" | "closed";
191
+ reason: "invalid" | "conflict" | "closed" | "archived";
192
192
  message: string;
193
193
  }>.constructor
194
194
  ```
@@ -198,7 +198,7 @@ Data.TaggedError("AdmissionError")<{
198
198
  ##### reason
199
199
 
200
200
  ```ts
201
- readonly reason: "closed" | "conflict" | "invalid";
201
+ readonly reason: "closed" | "conflict" | "invalid" | "archived";
202
202
  ```
203
203
 
204
204
  ###### Inherited from
@@ -1081,6 +1081,7 @@ type SendInputV0 = Readonly<{
1081
1081
  }>;
1082
1082
  when: "now" | "idle";
1083
1083
  correlation?: string;
1084
+ continuesWorkId?: string;
1084
1085
  }>;
1085
1086
  ```
1086
1087
 
@@ -1160,6 +1161,19 @@ session: string;
1160
1161
 
1161
1162
  ---
1162
1163
 
1164
+ ### ExtensionCommandCallerV0
1165
+
1166
+ ```ts
1167
+ type ExtensionCommandCallerV0 = Readonly<{
1168
+ agentId: string;
1169
+ sessionId: string;
1170
+ }>;
1171
+ ```
1172
+
1173
+ Host-authenticated caller context; never decoded from command JSON or HTTP.
1174
+
1175
+ ---
1176
+
1163
1177
  ### CommandHandlersV0
1164
1178
 
1165
1179
  ```ts
@@ -1168,6 +1182,7 @@ type CommandHandlersV0<C> = {
1168
1182
  call: Readonly<{
1169
1183
  sessionId: CommandSessionIdsV0[C[K]["scope"]];
1170
1184
  input: C[K]["input"]["Type"];
1185
+ caller?: ExtensionCommandCallerV0;
1171
1186
  }>,
1172
1187
  ) =>
1173
1188
  | C[K]["output"]["Type"]
@@ -1197,6 +1212,9 @@ type AttentionV0 = Readonly<{
1197
1212
  sessionId,
1198
1213
  item,
1199
1214
  ) => Effect.Effect<void, ExtensionStateError, ExtensionTx>;
1215
+ awaitsPerson: (
1216
+ sessionId,
1217
+ ) => Effect.Effect<boolean, ExtensionStateError, ExtensionRead>;
1200
1218
  clear: (
1201
1219
  sessionId,
1202
1220
  id,
@@ -1227,11 +1245,19 @@ type ExtensionContextV0<S, Config, D> = Readonly<{
1227
1245
  hasPendingSteer: (
1228
1246
  run,
1229
1247
  ) => Effect.Effect<boolean, ExtensionStateError, ExtensionRead>;
1248
+ workSender: (
1249
+ run,
1250
+ ) => Effect.Effect<
1251
+ AttentionRecipient | null,
1252
+ ExtensionStateError,
1253
+ ExtensionRead
1254
+ >;
1230
1255
  hasSuccessfulToolResult: (
1231
1256
  run,
1232
1257
  toolCallId,
1233
1258
  ) => Effect.Effect<boolean, ExtensionStateError, ExtensionRead>;
1234
1259
  observe: (sessionId) => Effect.Effect<void, never, ExtensionTx>;
1260
+ isObserved: (sessionId) => boolean;
1235
1261
  transact: <A, E>(body) => Effect.Effect<A, E | ExtensionStop | ShiitakeError>;
1236
1262
  }>;
1237
1263
  ```
@@ -1722,9 +1748,9 @@ A parsed invocation retains its typed handler until the transaction runs.
1722
1748
 
1723
1749
  #### Parameters
1724
1750
 
1725
- | Parameter | Type |
1726
- | --------- | ------------------------------------------------------------------------------ |
1727
- | `frame` | `Readonly`\<\{ `sessionId`: `string` \| `null`; `input`: [`Json`](#json); \}\> |
1751
+ | Parameter | Type |
1752
+ | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
1753
+ | `frame` | `Readonly`\<\{ `sessionId`: `string` \| `null`; `input`: [`Json`](#json); `caller?`: [`ExtensionCommandCallerV0`](#extensioncommandcallerv0); \}\> |
1728
1754
 
1729
1755
  #### Returns
1730
1756
 
@@ -1854,6 +1880,16 @@ Public state-update shape: infer the return _before_ rejecting async results.
1854
1880
 
1855
1881
  ---
1856
1882
 
1883
+ ### AttentionRecipient
1884
+
1885
+ ```ts
1886
+ type AttentionRecipient = typeof AttentionRecipientSchema.Type;
1887
+ ```
1888
+
1889
+ Decoded Agent Session an attention item waits on.
1890
+
1891
+ ---
1892
+
1857
1893
  ### AttentionItem
1858
1894
 
1859
1895
  ```ts
@@ -1894,6 +1930,22 @@ ASCII extension identity shared by the host definition and its clients.
1894
1930
 
1895
1931
  ---
1896
1932
 
1933
+ ### AttentionRecipientSchema
1934
+
1935
+ ```ts
1936
+ const AttentionRecipientSchema: Struct<{
1937
+ agentId: NonEmptyString;
1938
+ sessionId: NonEmptyString;
1939
+ name: NonEmptyString;
1940
+ }>;
1941
+ ```
1942
+
1943
+ The Agent Session that sent the work an item belongs to. The host derives it
1944
+ from the accepted mail; it is the only party the item waits on until it is
1945
+ escalated.
1946
+
1947
+ ---
1948
+
1897
1949
  ### AttentionItemSchema
1898
1950
 
1899
1951
  ```ts
@@ -1904,11 +1956,20 @@ const AttentionItemSchema: Struct<{
1904
1956
  since: Int;
1905
1957
  expiresAt: optional<Int>;
1906
1958
  inbox: optional<Literal<false>>;
1959
+ waitingOn: optional<
1960
+ Struct<{
1961
+ agentId: NonEmptyString;
1962
+ sessionId: NonEmptyString;
1963
+ name: NonEmptyString;
1964
+ }>
1965
+ >;
1907
1966
  }>;
1908
1967
  ```
1909
1968
 
1910
1969
  An extension-owned request for human attention; expiry is owned by its timer.
1911
- Items marked `inbox: false` remain visible without changing the inbox state.
1970
+ Items marked `inbox: false` remain visible without changing the inbox state. An
1971
+ item with `waitingOn` waits on that Agent first and is never a person's inbox
1972
+ item until it is escalated past every Agent.
1912
1973
 
1913
1974
  ## Functions
1914
1975