@fungi.computer/shiitake 0.4.0 → 0.6.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 (68) hide show
  1. package/README.md +1 -10
  2. package/dist/agent-control.d.ts +98 -5
  3. package/dist/agent-control.js +111 -8
  4. package/dist/client-entry.d.ts +20 -0
  5. package/dist/client-entry.js +5 -0
  6. package/dist/client-visitor.d.ts +31 -0
  7. package/dist/client-visitor.js +226 -0
  8. package/dist/client-wire.d.ts +5 -0
  9. package/dist/client-wire.js +6 -0
  10. package/dist/client.d.ts +4 -3
  11. package/dist/client.js +1 -0
  12. package/dist/delegation.d.ts +100 -77
  13. package/dist/delegation.js +73 -23
  14. package/dist/effect.d.ts +25 -0
  15. package/dist/effect.js +14 -1
  16. package/dist/extensions.d.ts +21 -2
  17. package/dist/extensions.js +1 -1
  18. package/dist/fleet.d.ts +22 -2
  19. package/dist/fleet.js +127 -36
  20. package/dist/hosted.js +3 -0
  21. package/dist/http-routes.d.ts +11 -0
  22. package/dist/internal/accepted-run-executor.js +2 -1
  23. package/dist/internal/admission-door.d.ts +5 -0
  24. package/dist/internal/admission-door.js +34 -3
  25. package/dist/internal/contracts.d.ts +14 -1
  26. package/dist/internal/coordinator.js +8 -2
  27. package/dist/internal/effect-client.js +1 -1
  28. package/dist/internal/effect-contracts.d.ts +4 -2
  29. package/dist/internal/extension-command-registry.d.ts +2 -1
  30. package/dist/internal/extension-command-registry.js +3 -1
  31. package/dist/internal/extension-runtime.d.ts +3 -1
  32. package/dist/internal/extension-runtime.js +13 -5
  33. package/dist/internal/model-acquisition.js +2 -0
  34. package/dist/internal/observation-kernel.d.ts +2 -0
  35. package/dist/internal/observation-kernel.js +17 -6
  36. package/dist/internal/run-scope.d.ts +14 -0
  37. package/dist/internal/run-scope.js +32 -9
  38. package/dist/internal/runtime-coordinator.js +8 -1
  39. package/dist/internal/runtime-reconciliation.js +119 -24
  40. package/dist/internal/woodstock/agent-reply.d.ts +5 -0
  41. package/dist/internal/woodstock/agent-reply.js +3 -0
  42. package/dist/internal/woodstock/client-projection.js +9 -1
  43. package/dist/internal/woodstock/fleet-store.d.ts +1 -0
  44. package/dist/internal/woodstock/fleet-store.js +28 -1
  45. package/dist/internal/woodstock/index.d.ts +4 -0
  46. package/dist/internal/woodstock/index.js +7 -0
  47. package/dist/internal/woodstock/session-delegator.d.ts +12 -0
  48. package/dist/internal/woodstock/session-delegator.js +44 -0
  49. package/dist/internal/woodstock/session-entry.d.ts +12 -2
  50. package/dist/internal/woodstock/session-store.d.ts +2 -0
  51. package/dist/internal/woodstock/session-store.js +20 -0
  52. package/dist/internal/woodstock/work-senders.d.ts +32 -0
  53. package/dist/internal/woodstock/work-senders.js +70 -0
  54. package/dist/remote-client.js +7 -2
  55. package/dist/server-visitor-stream.d.ts +13 -0
  56. package/dist/server-visitor-stream.js +115 -0
  57. package/dist/session-attention.d.ts +30 -0
  58. package/dist/session-attention.js +14 -0
  59. package/docs/api/agent-control.md +209 -13
  60. package/docs/api/client-entry.md +3 -0
  61. package/docs/api/client.md +136 -1
  62. package/docs/api/cloudflare.md +7 -1
  63. package/docs/api/delegation.md +234 -61
  64. package/docs/api/effect.md +16 -6
  65. package/docs/api/extensions.md +65 -4
  66. package/docs/api/fleet.md +69 -16
  67. package/docs/api/index.md +6 -4
  68. package/package.json +10 -6
@@ -75,8 +75,9 @@ readonly reason:
75
75
  ### AgentCreateRefused
76
76
 
77
77
  A host's refusal of an Agent creating an Agent: the creator asked to give the
78
- created Agent more than it holds, or the host cannot tell which Agent is
79
- creating. It reaches the caller as an `agents.create` failure.
78
+ created Agent more than it holds, the host cannot tell which Agent is creating,
79
+ or the request id belongs to another creating Agent or Session. It reaches the
80
+ caller as an `agents.create` failure.
80
81
 
81
82
  #### Extends
82
83
 
@@ -92,10 +93,10 @@ new AgentCreateRefused(reason, message): AgentCreateRefused;
92
93
 
93
94
  ###### Parameters
94
95
 
95
- | Parameter | Type |
96
- | --------- | ------------------------------------- |
97
- | `reason` | `"exceeds_creator"` \| `"no_creator"` |
98
- | `message` | `string` |
96
+ | Parameter | Type |
97
+ | --------- | ------------------------------------------------------------- |
98
+ | `reason` | `"exceeds_creator"` \| `"no_creator"` \| `"request_conflict"` |
99
+ | `message` | `string` |
99
100
 
100
101
  ###### Returns
101
102
 
@@ -124,11 +125,62 @@ Error.name;
124
125
  ##### reason
125
126
 
126
127
  ```ts
127
- readonly reason: "exceeds_creator" | "no_creator";
128
+ readonly reason: "exceeds_creator" | "no_creator" | "request_conflict";
128
129
  ```
129
130
 
130
131
  ## Type Aliases
131
132
 
133
+ ### AgentControlAnswerInput
134
+
135
+ ```ts
136
+ type AgentControlAnswerInput = Readonly<{
137
+ agentId: string;
138
+ sessionId: string;
139
+ askId: string;
140
+ requestId: string;
141
+ answers: MyceliumJsonValue;
142
+ }>;
143
+ ```
144
+
145
+ Sender-authenticated submission for one child Session's routed Ask.
146
+
147
+ ---
148
+
149
+ ### AgentControlEscalateInput
150
+
151
+ ```ts
152
+ type AgentControlEscalateInput = Readonly<{
153
+ agentId: string;
154
+ sessionId: string;
155
+ itemId: string;
156
+ note?: string;
157
+ }>;
158
+ ```
159
+
160
+ Sender-authenticated escalation of one item a child Session left waiting.
161
+
162
+ ---
163
+
164
+ ### AgentControlAnswerOutput
165
+
166
+ ```ts
167
+ type AgentControlAnswerOutput = z.infer<typeof answerOutput>;
168
+ ```
169
+
170
+ Typed outcome of a sender's answer to a child Ask.
171
+
172
+ ---
173
+
174
+ ### AgentControlEscalateOutput
175
+
176
+ ```ts
177
+ type AgentControlEscalateOutput = z.infer<typeof escalateOutput>;
178
+ ```
179
+
180
+ Typed outcome of a sender's escalation of a child's item.
181
+
182
+ ---
183
+
132
184
  ### ArchiveRefusalReason
133
185
 
134
186
  ```ts
@@ -173,10 +225,16 @@ One host-offered model usable as an Agent's create or setModel choice.
173
225
  ```ts
174
226
  type AgentDelegationInput = Readonly<{
175
227
  agentId: string;
176
- sessionId: string;
177
228
  text: string;
178
229
  requestId: string;
179
- delivery: "steer" | "followUp";
230
+ }> &
231
+ | Readonly<{
232
+ sessionId: string;
233
+ delivery: "steer";
234
+ }>
235
+ | Readonly<{
236
+ sessionId?: string;
237
+ delivery: "followUp";
180
238
  }>;
181
239
  ```
182
240
 
@@ -226,6 +284,16 @@ type AgentControlDirectory = Readonly<{
226
284
  invocation?,
227
285
  ) => Promise<Accepted | Held>;
228
286
  recall?: (input, sourceSessionId, signal) => Promise<CancelResult>;
287
+ answer?: (
288
+ input,
289
+ senderSessionId,
290
+ signal,
291
+ ) => Promise<AgentControlAnswerOutput>;
292
+ escalate?: (
293
+ input,
294
+ senderSessionId,
295
+ signal,
296
+ ) => Promise<AgentControlEscalateOutput>;
229
297
  create?: (input, signal) => Promise<AgentControlAgent>;
230
298
  setModel?: (input, signal) => Promise<void>;
231
299
  archive?: (input, signal) => Promise<void>;
@@ -248,6 +316,126 @@ Host-owned discovery and per-operation access to ordinary Agents.
248
316
 
249
317
  ## Variables
250
318
 
319
+ ### answerOutput
320
+
321
+ ```ts
322
+ const answerOutput: ZodDiscriminatedUnion<
323
+ [
324
+ ZodObject<
325
+ {
326
+ status: ZodLiteral<"answered">;
327
+ via: ZodEnum<{
328
+ in_turn: "in_turn";
329
+ follow_up: "follow_up";
330
+ }>;
331
+ commandId: ZodExactOptional<ZodString>;
332
+ },
333
+ $strict
334
+ >,
335
+ ZodObject<
336
+ {
337
+ status: ZodLiteral<"not_found">;
338
+ },
339
+ $strict
340
+ >,
341
+ ZodObject<
342
+ {
343
+ status: ZodLiteral<"closed">;
344
+ reason: ZodEnum<{
345
+ cancelled: "cancelled";
346
+ undeliverable: "undeliverable";
347
+ answered: "answered";
348
+ declined: "declined";
349
+ withdrawn: "withdrawn";
350
+ expired: "expired";
351
+ }>;
352
+ },
353
+ $strict
354
+ >,
355
+ ZodObject<
356
+ {
357
+ status: ZodLiteral<"refused">;
358
+ reason: ZodEnum<{
359
+ not_sender: "not_sender";
360
+ no_provenance: "no_provenance";
361
+ }>;
362
+ },
363
+ $strict
364
+ >,
365
+ ZodObject<
366
+ {
367
+ status: ZodLiteral<"unavailable">;
368
+ reason: ZodLiteral<"unsupported">;
369
+ },
370
+ $strict
371
+ >,
372
+ ],
373
+ "status"
374
+ >;
375
+ ```
376
+
377
+ Typed outcome of a sender's answer to a child Ask.
378
+
379
+ ---
380
+
381
+ ### escalateOutput
382
+
383
+ ```ts
384
+ const escalateOutput: ZodDiscriminatedUnion<
385
+ [
386
+ ZodObject<
387
+ {
388
+ status: ZodLiteral<"escalated">;
389
+ to: ZodLiteral<"person">;
390
+ },
391
+ $strict
392
+ >,
393
+ ZodObject<
394
+ {
395
+ status: ZodLiteral<"not_found">;
396
+ },
397
+ $strict
398
+ >,
399
+ ZodObject<
400
+ {
401
+ status: ZodLiteral<"closed">;
402
+ reason: ZodEnum<{
403
+ cancelled: "cancelled";
404
+ undeliverable: "undeliverable";
405
+ answered: "answered";
406
+ declined: "declined";
407
+ withdrawn: "withdrawn";
408
+ expired: "expired";
409
+ }>;
410
+ },
411
+ $strict
412
+ >,
413
+ ZodObject<
414
+ {
415
+ status: ZodLiteral<"refused">;
416
+ reason: ZodEnum<{
417
+ not_sender: "not_sender";
418
+ no_provenance: "no_provenance";
419
+ }>;
420
+ },
421
+ $strict
422
+ >,
423
+ ZodObject<
424
+ {
425
+ status: ZodLiteral<"unavailable">;
426
+ reason: ZodLiteral<"unsupported">;
427
+ },
428
+ $strict
429
+ >,
430
+ ],
431
+ "status"
432
+ >;
433
+ ```
434
+
435
+ Typed outcome of a sender's escalation of a child's item.
436
+
437
+ ---
438
+
251
439
  ### archiveRefusalReasons
252
440
 
253
441
  ```ts
@@ -279,10 +467,16 @@ function waitForAgentSettlement(
279
467
  ): Promise<
280
468
  Readonly<{
281
469
  acceptedSender: string | null;
470
+ delegator: string | null;
282
471
  terminal: SessionTerminal;
283
472
  content: string;
284
473
  usage: readonly Pick<AssistantMessage, "model" | "provider" | "usage">[];
285
474
  toolCalls: number;
475
+ waitingOnYou: readonly Readonly<{
476
+ itemId: string;
477
+ kind: string;
478
+ summary: string;
479
+ }>[];
286
480
  }>
287
481
  >;
288
482
  ```
@@ -301,10 +495,12 @@ Await one exact durable terminal without opening a transcript observation.
301
495
 
302
496
  #### Returns
303
497
 
304
- `Promise`\<`Readonly`\<\{ `acceptedSender`: `string` \| `null`; `terminal`:
305
- [`SessionTerminal`](client.md#sessionterminal); `content`: `string`; `usage`:
306
- readonly `Pick`\<`AssistantMessage`, `"model"` \| `"provider"` \| `"usage"`\>[];
307
- `toolCalls`: `number`; \}\>\>
498
+ `Promise`\<`Readonly`\<\{ `acceptedSender`: `string` \| `null`; `delegator`:
499
+ `string` \| `null`; `terminal`: [`SessionTerminal`](client.md#sessionterminal);
500
+ `content`: `string`; `usage`: readonly `Pick`\<`AssistantMessage`, `"model"` \|
501
+ `"provider"` \| `"usage"`\>[]; `toolCalls`: `number`; `waitingOnYou`: readonly
502
+ `Readonly`\<\{ `itemId`: `string`; `kind`: `string`; `summary`: `string`;
503
+ \}\>[]; \}\>\>
308
504
 
309
505
  ---
310
506
 
@@ -172,6 +172,7 @@ const clientTimelineCellSchemaV1: Struct<{
172
172
  id: String;
173
173
  label: String;
174
174
  input: optional<$Record<..., ...>>;
175
+ awaiting: optionalKey<Literal<...>>;
175
176
  }>>>;
176
177
  }>>;
177
178
  }>;
@@ -222,6 +223,7 @@ const clientContributionSchemaV1: Struct<{
222
223
  id: String;
223
224
  label: String;
224
225
  input: optional<$Record<..., ...>>;
226
+ awaiting: optionalKey<Literal<...>>;
225
227
  }>>>;
226
228
  inspection: optionalKey<Struct<{
227
229
  commandId: String;
@@ -261,6 +263,7 @@ const clientContributionSchemaV1: Struct<{
261
263
  id: String;
262
264
  label: String;
263
265
  input: optional<$Record<String, Codec<Json, Json, never, never>>>;
266
+ awaiting: optionalKey<Literal<"question">>;
264
267
  }>;
265
268
  }>>;
266
269
  }>;
@@ -10,12 +10,57 @@
10
10
 
11
11
  ## Type Aliases
12
12
 
13
+ ### ParticipantPolicy
14
+
15
+ ```ts
16
+ type ParticipantPolicy = Readonly<{
17
+ turnIsCurrent: (sessionId, commandId) => boolean;
18
+ deliverAgentReply: (sessionId, commandId, reply) => boolean;
19
+ }>;
20
+ ```
21
+
22
+ The host decides which Agent work may be delivered to this participant.
23
+
24
+ ---
25
+
26
+ ### VisitorView
27
+
28
+ ```ts
29
+ type VisitorView = Readonly<{
30
+ status: "idle" | "working";
31
+ lines: readonly Readonly<{
32
+ id: string;
33
+ from: "visitor" | "agent" | "operator";
34
+ text: string;
35
+ }>[];
36
+ progress: string | null;
37
+ }>;
38
+ ```
39
+
40
+ What a visitor may see of their own conversation Session.
41
+
42
+ ---
43
+
44
+ ### VisitorPendingPrompt
45
+
46
+ ```ts
47
+ type VisitorPendingPrompt = Pick<
48
+ SessionPendingPrompt,
49
+ "commandId" | "requestId" | "text" | "delivery" | "images"
50
+ >;
51
+ ```
52
+
53
+ Public pending facts exclude the host's private metadata and admission origin.
54
+
55
+ ---
56
+
13
57
  ### Accepted
14
58
 
15
59
  ```ts
16
60
  type Accepted = Readonly<{
17
61
  status: "accepted";
18
62
  commandId: string;
63
+ sessionId?: string;
19
64
  }>;
20
65
  ```
21
66
 
@@ -115,6 +160,7 @@ type SessionCommandHandler = {
115
160
  Readonly<{
116
161
  status: "accepted";
117
162
  commandId: string;
163
+ sessionId?: string;
118
164
  }>
119
165
  >;
120
166
  (input): Promise<CancelResult>;
@@ -142,6 +188,7 @@ Execute one retained type-discriminated Session command.
142
188
  (input): Promise<Readonly<{
143
189
  status: "accepted";
144
190
  commandId: string;
191
+ sessionId?: string;
145
192
  }>>;
146
193
  ```
147
194
 
@@ -155,7 +202,8 @@ Accept a prompt or a compaction request as queued Session work.
155
202
 
156
203
  ##### Returns
157
204
 
158
- `Promise`\<`Readonly`\<\{ `status`: `"accepted"`; `commandId`: `string`; \}\>\>
205
+ `Promise`\<`Readonly`\<\{ `status`: `"accepted"`; `commandId`: `string`;
206
+ `sessionId?`: `string`; \}\>\>
159
207
 
160
208
  #### Call Signature
161
209
 
@@ -978,6 +1026,93 @@ A delegated send is accepted by its owner or held in durable mail custody.
978
1026
 
979
1027
  ## Functions
980
1028
 
1029
+ ### participantSnapshot()
1030
+
1031
+ ```ts
1032
+ function participantSnapshot(snapshot, owner): SessionSnapshot;
1033
+ ```
1034
+
1035
+ Filter participant delivery only; the holder's stored Session is unchanged.
1036
+
1037
+ #### Parameters
1038
+
1039
+ | Parameter | Type |
1040
+ | ---------- | ----------------------------------------- |
1041
+ | `snapshot` | [`SessionSnapshot`](#sessionsnapshot) |
1042
+ | `owner` | [`ParticipantPolicy`](#participantpolicy) |
1043
+
1044
+ #### Returns
1045
+
1046
+ [`SessionSnapshot`](#sessionsnapshot)
1047
+
1048
+ ---
1049
+
1050
+ ### visitorPendingPrompt()
1051
+
1052
+ ```ts
1053
+ function visitorPendingPrompt(prompt, visitorId): VisitorPendingPrompt;
1054
+ ```
1055
+
1056
+ Project one owner-selected prompt without exposing host identity or correlation
1057
+ metadata.
1058
+
1059
+ #### Parameters
1060
+
1061
+ | Parameter | Type |
1062
+ | ----------- | ----------------------------------------------- |
1063
+ | `prompt` | [`SessionPendingPrompt`](#sessionpendingprompt) |
1064
+ | `visitorId` | `string` |
1065
+
1066
+ #### Returns
1067
+
1068
+ [`VisitorPendingPrompt`](#visitorpendingprompt)
1069
+
1070
+ ---
1071
+
1072
+ ### visitorSnapshot()
1073
+
1074
+ ```ts
1075
+ function visitorSnapshot(snapshot, visitorId): SessionSnapshot;
1076
+ ```
1077
+
1078
+ Visitor-scoped Session facts use the visitor's public address, never the
1079
+ internal Session ID.
1080
+
1081
+ #### Parameters
1082
+
1083
+ | Parameter | Type |
1084
+ | ----------- | ------------------------------------- |
1085
+ | `snapshot` | [`SessionSnapshot`](#sessionsnapshot) |
1086
+ | `visitorId` | `string` |
1087
+
1088
+ #### Returns
1089
+
1090
+ [`SessionSnapshot`](#sessionsnapshot)
1091
+
1092
+ ---
1093
+
1094
+ ### visitorView()
1095
+
1096
+ ```ts
1097
+ function visitorView(snapshot, visitorId): VisitorView;
1098
+ ```
1099
+
1100
+ Project only this visitor's host-attributed prompts, their replies, and explicit
1101
+ operator replies.
1102
+
1103
+ #### Parameters
1104
+
1105
+ | Parameter | Type |
1106
+ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1107
+ | `snapshot` | \| `Readonly`\<\{ `sessionId`: `string`; `cursor`: `string` \| `null`; `hasMore`: `boolean`; `oldestCursor?`: `string` \| `null`; `messages`: readonly `Readonly`\<\{ `requestId?`: `string`; `meta?`: [`Json`](extensions.md#json); `data?`: [`Json`](extensions.md#json); `origin?`: `Readonly`\<\{ `extensionId`: `string`; `correlation`: `string` \| `null`; \}\>; `id`: `string`; `sequence`: `number`; `commandId`: `string` \| `null`; `value`: [`ModelMessage`](#modelmessage); \}\>[]; `terminals`: readonly `Readonly`\<\{ `commandId`: `string`; `outcome`: `"completed"` \| `"failed"` \| `"cancelled"` \| `"interrupted"`; `sequence`: `number`; `diagnostic`: `string` \| `null`; `meta?`: [`Json`](extensions.md#json); \}\>[]; `compactions?`: readonly `Readonly`\<\{ `id`: `string`; `sequence`: `number`; `at`: `number`; `tokensBefore`: `number`; `tokensAfter`: `number` \| `null`; `trigger`: [`SessionCompactionTrigger`](#sessioncompactiontrigger) \| `null`; \}\>[]; `compactionNotices?`: readonly `Readonly`\<\{ `id`: `string`; `sequence`: `number`; `at`: `number`; `trigger`: [`SessionCompactionTrigger`](#sessioncompactiontrigger); `result`: `"failed"` \| `"nothing_to_compact"` \| `"stale"` \| `"insufficient"`; `diagnostic`: `string` \| `null`; \}\>[]; `sandboxFailures?`: readonly `object`[]; `pending`: [`SessionPendingPrompts`](#sessionpendingprompts); `activity`: [`SessionActivity`](#sessionactivity); `progress`: \| `Readonly`\<\{ `messageId`: `string`; `revision`: `number`; `text`: `string`; `thinking`: `string`; `textTruncated`: `boolean`; `thinkingTruncated`: `boolean`; \}\> \| `null`; `toolOutput`: readonly `Readonly`\<\{ `toolCallId`: `string`; `revision`: `number`; `tail`: `string`; `droppedBytes`: `number`; `totalBytes`: `number`; \}\>[]; `extensions`: [`SessionExtensionSlots`](#sessionextensionslots); `attention`: readonly `object`[]; `context?`: `Readonly`\<\{ `tokens`: `number`; `window`: `number` \| `null`; \}\>; \}\> \| `null` |
1108
+ | `visitorId` | `string` |
1109
+
1110
+ #### Returns
1111
+
1112
+ [`VisitorView`](#visitorview)
1113
+
1114
+ ---
1115
+
981
1116
  ### parseDelegationReceipt()
982
1117
 
983
1118
  ```ts
@@ -428,7 +428,13 @@ type CloudflareShiitake = ShiitakeOwnerAgent &
428
428
  sessionId,
429
429
  commandId,
430
430
  ) => Promise<CommandSettlement | undefined>;
431
- acceptMail: (mail, meta?, reply?) => Promise<Accepted>;
431
+ acceptMail: (
432
+ mail,
433
+ meta?,
434
+ reply?,
435
+ stageAcceptedNotice?,
436
+ sessionGrantDelivery?,
437
+ ) => Promise<Accepted>;
432
438
  alarm: () => Promise<void>;
433
439
  activeSessions: () => Promise<readonly string[]>;
434
440
  abortActive: () => Promise<void>;