@abelxiaoxing/cadence 2.0.33 → 2.0.35

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.
@@ -1,3 +1,4 @@
1
+ import { IMAGE_LIMITS, IMAGE_TYPES } from "../../image-content.mjs";
1
2
  /** Finite, authenticated workbench API. Ordinary chat is not task admission. */
2
3
  import {
3
4
  bool,
@@ -12,7 +13,22 @@ import {
12
13
  oneOf,
13
14
  text,
14
15
  } from "./core.ts";
15
- import { type ChoiceVersion, decodeChoiceVersion } from "./models.ts";
16
+ import { decodeModelSelector, type ModelSelector } from "./domain.ts";
17
+ import {
18
+ type ChoiceVersion,
19
+ type ConversationContext,
20
+ type ConversationLocation,
21
+ decodeChoiceVersion,
22
+ decodeConversationContext,
23
+ decodeConversationLocation,
24
+ decodeExecutionContext,
25
+ decodeModelCatalog,
26
+ decodeModelChoiceState,
27
+ decodeSessionId,
28
+ type ExecutionContext,
29
+ type ModelCatalog,
30
+ type ModelChoiceState,
31
+ } from "./models.ts";
16
32
 
17
33
  import {
18
34
  decodeWorkflowProposal,
@@ -60,13 +76,7 @@ export function decodeCadenceConversation(v: unknown): CadenceConversation {
60
76
  ...(degraded ? { notice: text(o.notice, 1024, true) } : {}),
61
77
  };
62
78
  }
63
- /** A conversation's identity: the Pi session id shared with the terminal. */
64
- export function decodeSessionId(v: unknown): string {
65
- const s = text(v, 128, true);
66
- if (!/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(s))
67
- throw new ContractError("invalid");
68
- return s;
69
- }
79
+ export { decodeSessionId } from "./models.ts";
70
80
  /** One entry of a Pi session (eight hex characters when Pi writes it). */
71
81
  export function decodeEntryId(v: unknown): string {
72
82
  const s = text(v, 64, true);
@@ -79,6 +89,19 @@ export interface WorkflowLink {
79
89
  conversationId: string;
80
90
  }
81
91
  export type WorkbenchRead =
92
+ | {
93
+ kind: "conversation-image";
94
+ live?: true;
95
+ id: string;
96
+ leaf: string | null;
97
+ entry: string;
98
+ index: number;
99
+ offset: number;
100
+ }
101
+ | {
102
+ kind: "conversation-context" | "conversation-models";
103
+ location: ConversationLocation;
104
+ }
82
105
  | { kind: "cadence-conversation"; id: string }
83
106
  | { kind: "workflow-active" }
84
107
  | { kind: "workflow-history"; after: string | null; scan?: string }
@@ -87,7 +110,6 @@ export type WorkbenchRead =
87
110
  | { kind: "workflow"; id: string }
88
111
  | { kind: "conversation-active" }
89
112
  | { kind: "conversations"; after?: ChatCursor | null }
90
- | { kind: "task-origin"; taskId: string }
91
113
  | {
92
114
  kind: "conversation";
93
115
  id: string;
@@ -113,26 +135,57 @@ export type WorkbenchRead =
113
135
  part: number;
114
136
  }
115
137
  | { kind: "conversation-tree"; id: string; leaf: string | null }
116
- | { kind: "conversation-legacy" }
117
- | { kind: "files"; path: string }
118
- | { kind: "file"; path: string }
138
+ | { kind: "files"; path: string; location?: ConversationLocation }
139
+ | { kind: "file"; path: string; location?: ConversationLocation }
119
140
  | { kind: "directories"; path: string }
120
141
  | { kind: "projects" };
142
+ /** Maximum UTF-8 bytes of one explicit conversation Send. */
143
+ export const CONVERSATION_SEND_BYTES = 16 * 1024;
144
+ export type ImageSend = Extract<
145
+ WorkbenchCommand,
146
+ { kind: "send" | "cadence-send" }
147
+ >;
121
148
  export type WorkbenchCommand =
149
+ | {
150
+ kind: "image-upload";
151
+ commandId: string;
152
+ imageId: string;
153
+ send: ImageSend;
154
+ mimeType: string;
155
+ size: number;
156
+ offset: number;
157
+ data: string;
158
+ }
159
+ | {
160
+ kind: "conversation-model";
161
+ commandId: string;
162
+ location: ConversationLocation;
163
+ expected: ChoiceVersion;
164
+ choice: ModelSelector;
165
+ }
122
166
  | {
123
167
  kind: "cadence-exit";
168
+ location?: ConversationLocation;
124
169
  commandId: string;
125
170
  conversationId: string;
126
171
  head: string | null;
127
172
  revision: number;
128
173
  }
129
- | { kind: "restore-model"; commandId: string; epoch: string }
174
+ | {
175
+ kind: "restore-model";
176
+ commandId: string;
177
+ epoch: string;
178
+ location?: ConversationLocation;
179
+ expected?: ChoiceVersion;
180
+ choice?: ModelSelector;
181
+ }
130
182
  | {
131
183
  kind: "cadence-send";
132
184
  commandId: string;
133
185
  conversationId: string;
134
186
  head: string | null;
135
187
  text: string;
188
+ images?: string[];
136
189
  model: ChoiceVersion;
137
190
  revision: number;
138
191
  intent: "message" | "enter" | "exit";
@@ -167,6 +220,7 @@ export type WorkbenchCommand =
167
220
  conversationId: string;
168
221
  head: string | null;
169
222
  text: string;
223
+ images?: string[];
170
224
  model: ChoiceVersion;
171
225
  }
172
226
  | {
@@ -176,8 +230,7 @@ export type WorkbenchCommand =
176
230
  turnId: string;
177
231
  epoch: string;
178
232
  }
179
- | { kind: "open-project"; commandId: string; path: string; epoch: string }
180
- | { kind: "conversation-migrate"; commandId: string };
233
+ | { kind: "open-project"; commandId: string; path: string; epoch: string };
181
234
  export type ChatStatus =
182
235
  | "queued"
183
236
  | "running"
@@ -186,7 +239,15 @@ export type ChatStatus =
186
239
  | "canceled"
187
240
  | "timeout"
188
241
  | "unknown";
242
+ export interface ChatImage {
243
+ live?: true;
244
+ /** Pi entry ID, or the admitted command ID until Pi flushes its user entry. */
245
+ entry: string;
246
+ index: number;
247
+ mimeType: string;
248
+ }
189
249
  export interface ChatItem {
250
+ images?: ChatImage[];
190
251
  id: string;
191
252
  role: "user" | "assistant" | "tool";
192
253
  text: string;
@@ -195,6 +256,7 @@ export interface ChatItem {
195
256
  error: boolean;
196
257
  }
197
258
  export interface ChatTurn {
259
+ execution?: ExecutionContext;
198
260
  id: string;
199
261
  epoch: string;
200
262
  status: ChatStatus;
@@ -210,6 +272,7 @@ export interface ChatTurn {
210
272
  * arguments or output and keeps at most `STEP_TEXT_BYTES` of message text;
211
273
  * the full item is read per step with `conversation-step`, one part at a time. */
212
274
  export interface ChatStep {
275
+ images?: ChatImage[];
213
276
  id: string;
214
277
  role: ChatItem["role"];
215
278
  /** User or assistant text, a prefix of it when `clipped`; empty for tools. */
@@ -224,6 +287,7 @@ export interface ChatStep {
224
287
  }
225
288
  /** One turn of a conversation branch: a user message and what followed it. */
226
289
  export interface ChatTurnHeader {
290
+ execution?: ExecutionContext;
227
291
  /** The user message's session entry id; a browser command id while Pi has not
228
292
  * written that message yet. */
229
293
  id: string;
@@ -313,6 +377,7 @@ export function chatStep(
313
377
  id: item.id,
314
378
  role: item.role,
315
379
  text,
380
+ ...(item.images?.length ? { images: item.images } : {}),
316
381
  clipped: !tool && (more || text !== item.text),
317
382
  name: item.name,
318
383
  target: tool ? clipText(toolTarget(item.args), TARGET_BYTES) : "",
@@ -348,6 +413,16 @@ export interface FileEntry {
348
413
  directory: boolean;
349
414
  }
350
415
  export type WorkbenchResult =
416
+ | { kind: "image-upload"; commandId: string; imageId: string; offset: number }
417
+ | {
418
+ kind: "conversation-image";
419
+ mimeType: string;
420
+ data: string;
421
+ next: number | null;
422
+ }
423
+ | { kind: "conversation-context"; context: ConversationContext }
424
+ | { kind: "conversation-models"; catalog: ModelCatalog }
425
+ | { kind: "conversation-model"; commandId: string; choice: ModelChoiceState }
351
426
  | { kind: "workflow-history-progress"; after: string | null; scan: string }
352
427
  | {
353
428
  kind: "workflow-history";
@@ -376,7 +451,6 @@ export type WorkbenchResult =
376
451
  proposal: WorkflowProposal;
377
452
  }
378
453
  | { kind: "workflow"; commandId: string | null; response: WorkflowResponse }
379
- | { kind: "task-origin"; taskId: string; conversationId: string | null }
380
454
  | { kind: "conversation-active"; entries: ChatSummary[] }
381
455
  | { kind: "conversations"; entries: ChatSummary[]; next: ChatCursor | null }
382
456
  | {
@@ -392,6 +466,8 @@ export type WorkbenchResult =
392
466
  /** Workflows the terminal started in this session. */
393
467
  runs: string[];
394
468
  attempt: ChatAttempt | null;
469
+ /** Accepted browser commands, not inferred from session entry changes. */
470
+ commands?: string[];
395
471
  }
396
472
  | {
397
473
  kind: "conversation-tree";
@@ -399,13 +475,6 @@ export type WorkbenchResult =
399
475
  nodes: ChatTreeNode[];
400
476
  truncated: boolean;
401
477
  }
402
- | { kind: "conversation-legacy"; pending: number }
403
- | {
404
- kind: "conversation-migrated";
405
- commandId: string;
406
- migrated: number;
407
- skipped: number;
408
- }
409
478
  | {
410
479
  kind: "conversation-turn";
411
480
  conversationId: string;
@@ -459,6 +528,11 @@ const statuses = [
459
528
  export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
460
529
  const kind = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
461
530
  switch (kind) {
531
+ case "conversation-context":
532
+ case "conversation-models": {
533
+ const o = closed(v, ["kind", "location"]);
534
+ return { kind, location: decodeConversationLocation(o.location) };
535
+ }
462
536
  case "conversation-turn": {
463
537
  const o = closed(v, ["kind", "id", "leaf", "ordinal", "before"]);
464
538
  return {
@@ -469,6 +543,36 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
469
543
  before: nullable(o.before, (b) => integer(b, 0)),
470
544
  };
471
545
  }
546
+ case "conversation-image": {
547
+ const o = closed(v, [
548
+ "kind",
549
+ "id",
550
+ "leaf",
551
+ "entry",
552
+ "index",
553
+ "offset",
554
+ ...(Object.hasOwn(v ?? {}, "live") ? ["live"] : []),
555
+ ]);
556
+ const offset = integer(
557
+ o.offset,
558
+ 0,
559
+ 4 * Math.ceil(IMAGE_LIMITS.bytes / 3),
560
+ );
561
+ if (
562
+ offset % IMAGE_LIMITS.chunkChars ||
563
+ (o.live !== undefined && o.live !== true)
564
+ )
565
+ throw new ContractError("invalid");
566
+ return {
567
+ kind,
568
+ id: decodeSessionId(o.id),
569
+ leaf: nullable(o.leaf, decodeEntryId),
570
+ ...(o.live === undefined ? {} : { live: true as const }),
571
+ entry: decodeEntryId(o.entry),
572
+ index: integer(o.index, 0, 1024),
573
+ offset,
574
+ };
575
+ }
472
576
  case "conversation-step": {
473
577
  const o = closed(v, ["kind", "id", "leaf", "turnId", "step", "part"]);
474
578
  return {
@@ -522,14 +626,9 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
522
626
  };
523
627
  }
524
628
  case "conversation-active":
525
- case "conversation-legacy":
526
629
  case "projects":
527
630
  closed(v, ["kind"]);
528
631
  return { kind };
529
- case "task-origin": {
530
- const o = closed(v, ["kind", "taskId"]);
531
- return { kind, taskId: decodeId(o.taskId) };
532
- }
533
632
  case "conversation": {
534
633
  const o = closed(v, ["kind", "id", "leaf", "known"]);
535
634
  return {
@@ -540,26 +639,74 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
540
639
  };
541
640
  }
542
641
  default: {
543
- const o = closed(v, ["kind", "path"]);
642
+ const scoped =
643
+ (kind === "file" || kind === "files") &&
644
+ Object.hasOwn(v ?? {}, "location");
645
+ const o = closed(v, ["kind", "path", ...(scoped ? ["location"] : [])]);
544
646
  return {
545
647
  kind: oneOf(o.kind, ["files", "file", "directories"]),
546
648
  path: text(o.path, 4096),
649
+ ...(scoped ? { location: decodeConversationLocation(o.location) } : {}),
547
650
  };
548
651
  }
549
652
  }
550
653
  }
551
654
  export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
552
655
  const kind = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
656
+ if (kind === "conversation-model") {
657
+ const o = closed(v, [
658
+ "kind",
659
+ "commandId",
660
+ "location",
661
+ "expected",
662
+ "choice",
663
+ ]);
664
+ return {
665
+ kind,
666
+ commandId: decodeId(o.commandId),
667
+ location: decodeConversationLocation(o.location),
668
+ expected: decodeChoiceVersion(o.expected),
669
+ choice: decodeModelSelector(o.choice),
670
+ };
671
+ }
553
672
  if (kind === "restore-model" || kind === "workflow-cancel") {
554
673
  const o = closed(
555
674
  v,
556
675
  kind === "restore-model"
557
- ? ["kind", "commandId", "epoch"]
676
+ ? [
677
+ "kind",
678
+ "commandId",
679
+ "epoch",
680
+ ...(Object.hasOwn(v ?? {}, "location") ? ["location"] : []),
681
+ ...(Object.hasOwn(v ?? {}, "expected") ||
682
+ Object.hasOwn(v ?? {}, "choice")
683
+ ? ["expected", "choice"]
684
+ : []),
685
+ ]
558
686
  : ["kind", "commandId", "epoch", "runId"],
559
687
  );
688
+ if (
689
+ (o.expected !== undefined || o.choice !== undefined) &&
690
+ o.location === undefined
691
+ )
692
+ throw new ContractError("invalid");
693
+ const restored =
694
+ Object.hasOwn(v ?? {}, "expected") || Object.hasOwn(v ?? {}, "choice");
560
695
  const base = { commandId: decodeId(o.commandId), epoch: decodeId(o.epoch) };
561
696
  return kind === "restore-model"
562
- ? { kind, ...base }
697
+ ? {
698
+ kind,
699
+ ...base,
700
+ ...(o.location === undefined
701
+ ? {}
702
+ : { location: decodeConversationLocation(o.location) }),
703
+ ...(restored
704
+ ? {
705
+ expected: decodeChoiceVersion(o.expected),
706
+ choice: decodeModelSelector(o.choice),
707
+ }
708
+ : {}),
709
+ }
563
710
  : { kind, ...base, runId: decodeId(o.runId) };
564
711
  }
565
712
  if (kind === "cadence-exit") {
@@ -569,15 +716,54 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
569
716
  "conversationId",
570
717
  "head",
571
718
  "revision",
719
+ ...(Object.hasOwn(v ?? {}, "location") ? ["location"] : []),
572
720
  ]);
573
721
  return {
574
722
  kind,
723
+ ...(o.location === undefined
724
+ ? {}
725
+ : { location: decodeConversationLocation(o.location) }),
575
726
  commandId: decodeId(o.commandId),
576
727
  conversationId: decodeSessionId(o.conversationId),
577
728
  head: nullable(o.head, decodeEntryId),
578
729
  revision: integer(o.revision, 0),
579
730
  };
580
731
  }
732
+ if (kind === "image-upload") {
733
+ const o = closed(v, [
734
+ "kind",
735
+ "commandId",
736
+ "imageId",
737
+ "send",
738
+ "mimeType",
739
+ "size",
740
+ "offset",
741
+ "data",
742
+ ]);
743
+ if (
744
+ !["send", "cadence-send"].includes(
745
+ Object.getOwnPropertyDescriptor(o.send ?? {}, "kind")?.value,
746
+ )
747
+ )
748
+ throw new ContractError("invalid");
749
+ const send = decodeWorkbenchCommand(o.send);
750
+ if (
751
+ (send.kind !== "send" && send.kind !== "cadence-send") ||
752
+ send.images?.length ||
753
+ (send.kind === "cadence-send" && send.intent === "exit")
754
+ )
755
+ throw new ContractError("invalid");
756
+ return {
757
+ kind,
758
+ commandId: decodeId(o.commandId),
759
+ imageId: decodeId(o.imageId),
760
+ send,
761
+ mimeType: oneOf(o.mimeType, IMAGE_TYPES),
762
+ size: integer(o.size, 1, IMAGE_LIMITS.bytes),
763
+ offset: integer(o.offset, 0, 4 * Math.ceil(IMAGE_LIMITS.bytes / 3)),
764
+ data: text(o.data, IMAGE_LIMITS.chunkChars, true),
765
+ };
766
+ }
581
767
  if (kind === "cadence-send") {
582
768
  const o = closed(v, [
583
769
  "kind",
@@ -585,6 +771,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
585
771
  "conversationId",
586
772
  "head",
587
773
  "text",
774
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
588
775
  "model",
589
776
  "revision",
590
777
  "intent",
@@ -594,7 +781,10 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
594
781
  commandId: decodeId(o.commandId),
595
782
  conversationId: decodeSessionId(o.conversationId),
596
783
  head: nullable(o.head, decodeEntryId),
597
- text: text(o.text, 16384, true),
784
+ text: text(o.text, CONVERSATION_SEND_BYTES),
785
+ ...(o.images === undefined
786
+ ? {}
787
+ : { images: list(o.images, IMAGE_LIMITS.count, decodeId) }),
598
788
  model: decodeChoiceVersion(o.model),
599
789
  revision: integer(o.revision, 0),
600
790
  intent: oneOf(o.intent, ["message", "enter", "exit"]),
@@ -638,6 +828,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
638
828
  "conversationId",
639
829
  "head",
640
830
  "text",
831
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
641
832
  "model",
642
833
  ]);
643
834
  return {
@@ -645,7 +836,10 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
645
836
  commandId: decodeId(o.commandId),
646
837
  conversationId: decodeSessionId(o.conversationId),
647
838
  head: nullable(o.head, decodeEntryId),
648
- text: text(o.text, 16 * 1024, true),
839
+ text: text(o.text, CONVERSATION_SEND_BYTES),
840
+ ...(o.images === undefined
841
+ ? {}
842
+ : { images: list(o.images, IMAGE_LIMITS.count, decodeId) }),
649
843
  model: decodeChoiceVersion(o.model),
650
844
  };
651
845
  }
@@ -665,10 +859,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
665
859
  epoch: decodeId(o.epoch),
666
860
  };
667
861
  }
668
- if (kind === "conversation-migrate") {
669
- const o = closed(v, ["kind", "commandId"]);
670
- return { kind, commandId: decodeId(o.commandId) };
671
- }
862
+
672
863
  const o = closed(v, ["kind", "commandId", "path", "epoch"]);
673
864
  return {
674
865
  kind: oneOf(o.kind, ["open-project"]),
@@ -688,12 +879,16 @@ export function decodeChatTurn(v: unknown): ChatTurn {
688
879
  ...keys,
689
880
  ...(current ? ["omitted"] : []),
690
881
  ...(paged ? ["transcript"] : []),
882
+ ...(Object.hasOwn(v ?? {}, "execution") ? ["execution"] : []),
691
883
  ]);
692
884
  const transcript = paged ? closed(o.transcript, ["pages"]) : null;
693
885
  const omitted = current
694
886
  ? closed(o.omitted, ["thinking", "media", "other"])
695
887
  : null;
696
888
  return {
889
+ ...(o.execution === undefined
890
+ ? {}
891
+ : { execution: decodeExecutionContext(o.execution) }),
697
892
  id: decodeId(o.id),
698
893
  epoch: decodeId(o.epoch),
699
894
  status: oneOf(o.status, statuses),
@@ -709,9 +904,36 @@ export function decodeChatTurn(v: unknown): ChatTurn {
709
904
  items: list(o.items, 256, decodeChatItem),
710
905
  };
711
906
  }
907
+ function decodeChatImages(v: unknown): ChatImage[] {
908
+ return list(v, IMAGE_LIMITS.count, (value) => {
909
+ const o = closed(value, [
910
+ "entry",
911
+ "index",
912
+ "mimeType",
913
+ ...(Object.hasOwn(value ?? {}, "live") ? ["live"] : []),
914
+ ]);
915
+ if (o.live !== undefined && o.live !== true)
916
+ throw new ContractError("invalid");
917
+ return {
918
+ ...(o.live === undefined ? {} : { live: true as const }),
919
+ entry: decodeEntryId(o.entry),
920
+ index: integer(o.index, 0, 1024),
921
+ mimeType: oneOf(o.mimeType, IMAGE_TYPES),
922
+ };
923
+ });
924
+ }
712
925
  export function decodeChatItem(v: unknown): ChatItem {
713
- const i = closed(v, ["id", "role", "text", "name", "args", "error"]);
926
+ const i = closed(v, [
927
+ "id",
928
+ "role",
929
+ "text",
930
+ "name",
931
+ "args",
932
+ "error",
933
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
934
+ ]);
714
935
  return {
936
+ ...(i.images === undefined ? {} : { images: decodeChatImages(i.images) }),
715
937
  id: text(i.id, 160, true),
716
938
  role: oneOf(i.role, ["user", "assistant", "tool"]),
717
939
  text: text(i.text, 256 * 1024),
@@ -726,12 +948,14 @@ function decodeChatStep(v: unknown): ChatStep {
726
948
  "role",
727
949
  "text",
728
950
  "clipped",
951
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
729
952
  "name",
730
953
  "target",
731
954
  "error",
732
955
  "parts",
733
956
  ]);
734
957
  const step = {
958
+ ...(o.images === undefined ? {} : { images: decodeChatImages(o.images) }),
735
959
  id: text(o.id, 160, true),
736
960
  role: oneOf(o.role, ["user", "assistant", "tool"]),
737
961
  text: text(o.text, STEP_TEXT_BYTES),
@@ -753,12 +977,16 @@ function decodeChatTurnHeader(v: unknown): ChatTurnHeader {
753
977
  "omitted",
754
978
  "steps",
755
979
  "stable",
980
+ ...(Object.hasOwn(v ?? {}, "execution") ? ["execution"] : []),
756
981
  "entry",
757
982
  "at",
758
983
  ]);
759
984
  const omitted = closed(o.omitted, ["thinking", "media", "other"]);
760
985
  const steps = integer(o.steps, 0);
761
986
  return {
987
+ ...(o.execution === undefined
988
+ ? {}
989
+ : { execution: decodeExecutionContext(o.execution) }),
762
990
  id: decodeEntryId(o.id),
763
991
  entry: nullable(o.entry, decodeEntryId),
764
992
  at: integer(o.at, 0),
@@ -828,6 +1056,42 @@ function decodeChatTreeNode(v: unknown): ChatTreeNode {
828
1056
  export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
829
1057
  canonicalJson(v, 512 * 1024);
830
1058
  const k = Object.getOwnPropertyDescriptor(v ?? {}, "kind")?.value;
1059
+ if (k === "image-upload") {
1060
+ const o = closed(v, ["kind", "commandId", "imageId", "offset"]);
1061
+ return {
1062
+ kind: k,
1063
+ commandId: decodeId(o.commandId),
1064
+ imageId: decodeId(o.imageId),
1065
+ offset: integer(o.offset, 0, 4 * Math.ceil(IMAGE_LIMITS.bytes / 3)),
1066
+ };
1067
+ }
1068
+ if (k === "conversation-image") {
1069
+ const o = closed(v, ["kind", "mimeType", "data", "next"]);
1070
+ return {
1071
+ kind: k,
1072
+ mimeType: oneOf(o.mimeType, IMAGE_TYPES),
1073
+ data: text(o.data, IMAGE_LIMITS.chunkChars, true),
1074
+ next: nullable(o.next, (n) =>
1075
+ integer(n, 0, 4 * Math.ceil(IMAGE_LIMITS.bytes / 3)),
1076
+ ),
1077
+ };
1078
+ }
1079
+ if (k === "conversation-context") {
1080
+ const o = closed(v, ["kind", "context"]);
1081
+ return { kind: k, context: decodeConversationContext(o.context) };
1082
+ }
1083
+ if (k === "conversation-models") {
1084
+ const o = closed(v, ["kind", "catalog"]);
1085
+ return { kind: k, catalog: decodeModelCatalog(o.catalog) };
1086
+ }
1087
+ if (k === "conversation-model") {
1088
+ const o = closed(v, ["kind", "commandId", "choice"]);
1089
+ return {
1090
+ kind: k,
1091
+ commandId: decodeId(o.commandId),
1092
+ choice: decodeModelChoiceState(o.choice),
1093
+ };
1094
+ }
831
1095
  if (k === "workflow-transcript") {
832
1096
  const o = closed(v, ["kind", "runId", "stepId", "turn"]);
833
1097
  return {
@@ -915,14 +1179,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
915
1179
  response: decodeWorkflowResponse(o.response),
916
1180
  };
917
1181
  }
918
- if (kind === "task-origin") {
919
- const o = closed(v, ["kind", "taskId", "conversationId"]);
920
- return {
921
- kind,
922
- taskId: decodeId(o.taskId),
923
- conversationId: nullable(o.conversationId, decodeSessionId),
924
- };
925
- }
1182
+
926
1183
  if (kind === "conversation-active") {
927
1184
  const o = closed(v, ["kind", "entries"]);
928
1185
  return { kind, entries: list(o.entries, 8, decodeChatSummary) };
@@ -945,12 +1202,16 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
945
1202
  "branches",
946
1203
  "runs",
947
1204
  "attempt",
1205
+ ...(Object.hasOwn(v ?? {}, "commands") ? ["commands"] : []),
948
1206
  ]);
949
1207
  const summary = nullable(o.summary, decodeChatSummary),
950
1208
  turns = integer(o.turns, 0);
951
1209
  if (!summary && turns) throw new ContractError("invalid");
952
1210
  return {
953
1211
  kind,
1212
+ ...(o.commands === undefined
1213
+ ? {}
1214
+ : { commands: list(o.commands, 64, decodeId) }),
954
1215
  summary,
955
1216
  leaf: nullable(o.leaf, decodeEntryId),
956
1217
  continues: bool(o.continues),
@@ -969,19 +1230,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
969
1230
  truncated: bool(o.truncated),
970
1231
  };
971
1232
  }
972
- if (kind === "conversation-legacy") {
973
- const o = closed(v, ["kind", "pending"]);
974
- return { kind, pending: integer(o.pending, 0) };
975
- }
976
- if (kind === "conversation-migrated") {
977
- const o = closed(v, ["kind", "commandId", "migrated", "skipped"]);
978
- return {
979
- kind,
980
- commandId: decodeId(o.commandId),
981
- migrated: integer(o.migrated, 0),
982
- skipped: integer(o.skipped, 0),
983
- };
984
- }
1233
+
985
1234
  if (kind === "conversation-turn") {
986
1235
  const o = closed(v, [
987
1236
  "kind",