@abelxiaoxing/cadence 2.0.34 → 2.0.36

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,
@@ -88,6 +89,15 @@ export interface WorkflowLink {
88
89
  conversationId: string;
89
90
  }
90
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
+ }
91
101
  | {
92
102
  kind: "conversation-context" | "conversation-models";
93
103
  location: ConversationLocation;
@@ -131,7 +141,21 @@ export type WorkbenchRead =
131
141
  | { kind: "projects" };
132
142
  /** Maximum UTF-8 bytes of one explicit conversation Send. */
133
143
  export const CONVERSATION_SEND_BYTES = 16 * 1024;
144
+ export type ImageSend = Extract<
145
+ WorkbenchCommand,
146
+ { kind: "send" | "cadence-send" }
147
+ >;
134
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
+ }
135
159
  | {
136
160
  kind: "conversation-model";
137
161
  commandId: string;
@@ -161,6 +185,7 @@ export type WorkbenchCommand =
161
185
  conversationId: string;
162
186
  head: string | null;
163
187
  text: string;
188
+ images?: string[];
164
189
  model: ChoiceVersion;
165
190
  revision: number;
166
191
  intent: "message" | "enter" | "exit";
@@ -195,6 +220,7 @@ export type WorkbenchCommand =
195
220
  conversationId: string;
196
221
  head: string | null;
197
222
  text: string;
223
+ images?: string[];
198
224
  model: ChoiceVersion;
199
225
  }
200
226
  | {
@@ -213,7 +239,15 @@ export type ChatStatus =
213
239
  | "canceled"
214
240
  | "timeout"
215
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
+ }
216
249
  export interface ChatItem {
250
+ images?: ChatImage[];
217
251
  id: string;
218
252
  role: "user" | "assistant" | "tool";
219
253
  text: string;
@@ -238,6 +272,7 @@ export interface ChatTurn {
238
272
  * arguments or output and keeps at most `STEP_TEXT_BYTES` of message text;
239
273
  * the full item is read per step with `conversation-step`, one part at a time. */
240
274
  export interface ChatStep {
275
+ images?: ChatImage[];
241
276
  id: string;
242
277
  role: ChatItem["role"];
243
278
  /** User or assistant text, a prefix of it when `clipped`; empty for tools. */
@@ -342,6 +377,7 @@ export function chatStep(
342
377
  id: item.id,
343
378
  role: item.role,
344
379
  text,
380
+ ...(item.images?.length ? { images: item.images } : {}),
345
381
  clipped: !tool && (more || text !== item.text),
346
382
  name: item.name,
347
383
  target: tool ? clipText(toolTarget(item.args), TARGET_BYTES) : "",
@@ -377,6 +413,13 @@ export interface FileEntry {
377
413
  directory: boolean;
378
414
  }
379
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
+ }
380
423
  | { kind: "conversation-context"; context: ConversationContext }
381
424
  | { kind: "conversation-models"; catalog: ModelCatalog }
382
425
  | { kind: "conversation-model"; commandId: string; choice: ModelChoiceState }
@@ -500,6 +543,36 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
500
543
  before: nullable(o.before, (b) => integer(b, 0)),
501
544
  };
502
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
+ }
503
576
  case "conversation-step": {
504
577
  const o = closed(v, ["kind", "id", "leaf", "turnId", "step", "part"]);
505
578
  return {
@@ -656,6 +729,41 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
656
729
  revision: integer(o.revision, 0),
657
730
  };
658
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
+ }
659
767
  if (kind === "cadence-send") {
660
768
  const o = closed(v, [
661
769
  "kind",
@@ -663,6 +771,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
663
771
  "conversationId",
664
772
  "head",
665
773
  "text",
774
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
666
775
  "model",
667
776
  "revision",
668
777
  "intent",
@@ -672,7 +781,10 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
672
781
  commandId: decodeId(o.commandId),
673
782
  conversationId: decodeSessionId(o.conversationId),
674
783
  head: nullable(o.head, decodeEntryId),
675
- text: text(o.text, CONVERSATION_SEND_BYTES, true),
784
+ text: text(o.text, CONVERSATION_SEND_BYTES),
785
+ ...(o.images === undefined
786
+ ? {}
787
+ : { images: list(o.images, IMAGE_LIMITS.count, decodeId) }),
676
788
  model: decodeChoiceVersion(o.model),
677
789
  revision: integer(o.revision, 0),
678
790
  intent: oneOf(o.intent, ["message", "enter", "exit"]),
@@ -716,6 +828,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
716
828
  "conversationId",
717
829
  "head",
718
830
  "text",
831
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
719
832
  "model",
720
833
  ]);
721
834
  return {
@@ -723,7 +836,10 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
723
836
  commandId: decodeId(o.commandId),
724
837
  conversationId: decodeSessionId(o.conversationId),
725
838
  head: nullable(o.head, decodeEntryId),
726
- text: text(o.text, CONVERSATION_SEND_BYTES, true),
839
+ text: text(o.text, CONVERSATION_SEND_BYTES),
840
+ ...(o.images === undefined
841
+ ? {}
842
+ : { images: list(o.images, IMAGE_LIMITS.count, decodeId) }),
727
843
  model: decodeChoiceVersion(o.model),
728
844
  };
729
845
  }
@@ -788,9 +904,36 @@ export function decodeChatTurn(v: unknown): ChatTurn {
788
904
  items: list(o.items, 256, decodeChatItem),
789
905
  };
790
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
+ }
791
925
  export function decodeChatItem(v: unknown): ChatItem {
792
- 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
+ ]);
793
935
  return {
936
+ ...(i.images === undefined ? {} : { images: decodeChatImages(i.images) }),
794
937
  id: text(i.id, 160, true),
795
938
  role: oneOf(i.role, ["user", "assistant", "tool"]),
796
939
  text: text(i.text, 256 * 1024),
@@ -805,12 +948,14 @@ function decodeChatStep(v: unknown): ChatStep {
805
948
  "role",
806
949
  "text",
807
950
  "clipped",
951
+ ...(Object.hasOwn(v ?? {}, "images") ? ["images"] : []),
808
952
  "name",
809
953
  "target",
810
954
  "error",
811
955
  "parts",
812
956
  ]);
813
957
  const step = {
958
+ ...(o.images === undefined ? {} : { images: decodeChatImages(o.images) }),
814
959
  id: text(o.id, 160, true),
815
960
  role: oneOf(o.role, ["user", "assistant", "tool"]),
816
961
  text: text(o.text, STEP_TEXT_BYTES),
@@ -911,6 +1056,26 @@ function decodeChatTreeNode(v: unknown): ChatTreeNode {
911
1056
  export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
912
1057
  canonicalJson(v, 512 * 1024);
913
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
+ }
914
1079
  if (k === "conversation-context") {
915
1080
  const o = closed(v, ["kind", "context"]);
916
1081
  return { kind: k, context: decodeConversationContext(o.context) };
@@ -6311,7 +6311,12 @@ async function release(spec = "latest", npmRun = npm) {
6311
6311
  if (result.status !== 0)
6312
6312
  return;
6313
6313
  try {
6314
- const value = JSON.parse(result.stdout);
6314
+ let value = JSON.parse(result.stdout);
6315
+ if (Array.isArray(value)) {
6316
+ if (value.length !== 1)
6317
+ return;
6318
+ value = value[0];
6319
+ }
6315
6320
  if (typeof value === "string")
6316
6321
  return { version: decodeVersion(value), deprecated: false };
6317
6322
  const o = closed(value, ["version", "deprecated"]);