@abelxiaoxing/cadence 2.0.34 → 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.
- package/README.md +3 -0
- package/docs/conversation-mode.md +19 -0
- package/package.json +2 -1
- package/src/cadence-instructions.ts +1 -0
- package/src/image-content.mjs +120 -0
- package/src/native-build.ts +1 -1
- package/src/sdk-worker.mjs +52 -0
- package/src/service/contracts/core.ts +1 -0
- package/src/service/contracts/models.ts +3 -0
- package/src/service/contracts/workbench.ts +168 -3
- package/src/service-cli.mjs +6 -1
- package/src/service-host.mjs +686 -96
- package/src/worker-public.mjs +6 -1
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +19 -17
- package/web/dist/manifest.json +7 -7
package/README.md
CHANGED
|
@@ -51,6 +51,9 @@ The port and token live in `~/.pi/agent/cadence/.env`; anyone with the token can
|
|
|
51
51
|
5. Follow actual progress and local merge results in the conversation; open any subagent's full context from the lower-left **Subagents** dock.
|
|
52
52
|
Refresh and completion keep Cadence on; **Exit Cadence** only exits the mode, while **Cancel workflow — request stop** requests cancellation.
|
|
53
53
|
|
|
54
|
+
The browser also accepts images by file selection, paste or drag-and-drop, with previews and retained history.
|
|
55
|
+
Choose a vision-capable model; see [image input](docs/conversation-mode.md#images-in-the-webui).
|
|
56
|
+
|
|
54
57
|
### In the terminal
|
|
55
58
|
|
|
56
59
|
Enter `/cadence <goal>` once in any trusted project's Pi conversation.
|
|
@@ -32,6 +32,25 @@ Opening a different conversation does not enable Cadence there.
|
|
|
32
32
|
Restore never replays a command or automatically resumes an interrupted queue.
|
|
33
33
|
When an observation reply is lost, ask for status; do not infer that the action was absent.
|
|
34
34
|
|
|
35
|
+
## Images in the WebUI
|
|
36
|
+
|
|
37
|
+
Use **Add images**, paste a screenshot, or drop image files onto the composer.
|
|
38
|
+
Preview and remove images before Send; a message can contain images without text.
|
|
39
|
+
PNG, JPEG and WebP are supported; the composer shows the current count and size limits.
|
|
40
|
+
Choose a model whose catalog supports image input.
|
|
41
|
+
An incompatible model refuses the message rather than dropping its images.
|
|
42
|
+
Ordinary and Cadence conversations use the same image input.
|
|
43
|
+
Images alongside an approval phrase are a discussion message, not plan approval.
|
|
44
|
+
|
|
45
|
+
Selecting images is local to the tab and does not upload or start execution.
|
|
46
|
+
Only Send uploads them, bound to that exact conversation, branch, model and message; navigating away abandons an unsent continuation, never an admitted turn.
|
|
47
|
+
Unsent pictures are not saved in browser storage and disappear on refresh; the text draft remains.
|
|
48
|
+
After Pi records a sent image, it appears in the conversation history and remains viewable after refresh (including retained reads when the project owner is stopped).
|
|
49
|
+
Click a history thumbnail to open it at full size.
|
|
50
|
+
Unsupported or over-limit media from existing Pi sessions remains omitted; unavailable images show a notice without changing their session files.
|
|
51
|
+
Images are private conversation content, not public download links.
|
|
52
|
+
Text redaction does not sanitize words or secrets inside pixels: inspect screenshots before sending them to a model.
|
|
53
|
+
|
|
35
54
|
## Models and project knowledge
|
|
36
55
|
|
|
37
56
|
The first native use defaults to the current Pi provider/model/API/thinking selection.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abelxiaoxing/cadence",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.35",
|
|
4
4
|
"description": "Conversation-driven Pi workspace: persistent native and WebUI workflows, explicit plan approval, checks and local delivery.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"THIRD_PARTY_NOTICES.md",
|
|
70
70
|
"licenses",
|
|
71
71
|
"src/session-entries.mjs",
|
|
72
|
+
"src/image-content.mjs",
|
|
72
73
|
"src/session-sharing.ts",
|
|
73
74
|
"src/conversation-resources.mjs",
|
|
74
75
|
"src/service/contracts/workbench.ts",
|
|
@@ -4,4 +4,5 @@ You are the sole user-facing coordinator. Continue normal conversation, not a ta
|
|
|
4
4
|
For each new goal: inspect relevant project evidence through cadence_research (up to two independent readonly subagents); read existing AGENTS/docs/.cadence/project.md before proposing conventions. Reuse still-current findings; do not rescan the entire repository or spawn agents merely to fill slots. Aggregate questions yourself. Investigate discoverable facts and ask focused, frequent questions only for unresolved product/technical decisions. Preserve confirmed decisions across turns. Diagnosis/research alone never imply implementation.
|
|
5
5
|
Once material decisions and acceptance criteria are aligned, use cadence_plan with a readable design, explicit non-goals/decisions, exact file scopes, a finite dependency DAG, real verification commands, worktree prerequisites and a bounded repair budget. Independent writes may run concurrently; shared files need a single owner or dependency. Investigate local tool/dependency prerequisites BEFORE finalizing: isolated worktrees do not inherit ignored node_modules. Setup commands require inclusion in the final approval; never silently install/download/copy dependencies or credentials. local-merge needs an existing Git branch and commit identity; working-copy is explicit direct editing without Git mutation and is serialized.
|
|
6
6
|
Present the returned complete plan and invite a single clear execution approval (the user can type 按计划实施). cadence_start binds the exact displayed plan and obtains fresh user consent; never interpret a vague acknowledgement as approval. No further confirmations are needed for the approved bounded pipeline. No push, publication, deployment, recursive delegation or scope expansion. If a material decision changes, revise the plan and seek fresh approval.
|
|
7
|
+
For a follow-up to previously accepted work, inspect cadence_status and retained outcomes before proposing a new run or applying clean-start prerequisites. Known partial outputs from that run are not unexplained user edits. Preserve them and the original failed/unknown result; diagnose the actual failed stage. Never replay the run or claim its checks passed; any new implementation still needs a fresh exact-plan approval.
|
|
7
8
|
During accepted work answer questions, report actual retained progress, and let the service execute. cadence_cancel is explicit cancellation, not navigation/exit. Never claim a worker's prose is a passing check or automatic review is human review. Failed/unknown/blocked outcomes are not success. A completed goal leaves Cadence ON and ready for the next goal; do not require /cadence again. Unrelated discussion is still ordinary conversation within this mode, not implicit permission to start another implementation. Tools operate on the host; this is not a sandbox.`;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IMAGE_COUNT } from "./worker-public.mjs";
|
|
2
|
+
/** Shared image ceilings. Upload chunks and history parts fit existing control replies;
|
|
3
|
+
* image bytes never enlarge the public worker request or become prompt text. */
|
|
4
|
+
export const IMAGE_LIMITS = Object.freeze({
|
|
5
|
+
count: IMAGE_COUNT,
|
|
6
|
+
bytes: 4 * 1024 * 1024,
|
|
7
|
+
totalBytes: 8 * 1024 * 1024,
|
|
8
|
+
chunkChars: 256 * 1024,
|
|
9
|
+
stagedBytes: 64 * 1024 * 1024,
|
|
10
|
+
stagedCount: 64,
|
|
11
|
+
idleMs: 10 * 60 * 1000,
|
|
12
|
+
pixels: 32 * 1024 * 1024,
|
|
13
|
+
dimension: 16384,
|
|
14
|
+
wireBytes: 12 * 1024 * 1024,
|
|
15
|
+
});
|
|
16
|
+
export const IMAGE_TYPES = Object.freeze([
|
|
17
|
+
"image/png",
|
|
18
|
+
"image/jpeg",
|
|
19
|
+
"image/webp",
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export function decodeImageBase64(data, maxBytes = IMAGE_LIMITS.bytes) {
|
|
23
|
+
if (
|
|
24
|
+
typeof data !== "string" ||
|
|
25
|
+
!data.length ||
|
|
26
|
+
data.length % 4 ||
|
|
27
|
+
data.length > 4 * Math.ceil(maxBytes / 3) ||
|
|
28
|
+
!/^[A-Za-z0-9+/]*={0,2}$/.test(data)
|
|
29
|
+
)
|
|
30
|
+
throw new Error("Invalid image encoding");
|
|
31
|
+
const raw = atob(data);
|
|
32
|
+
if (raw.length > maxBytes) throw new Error("Image is too large");
|
|
33
|
+
const bytes = new Uint8Array(raw.length);
|
|
34
|
+
for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Bounded header validation, not an image transcoder. No SVG/HTML or remote URLs. */
|
|
39
|
+
export function validateImageBytes(bytes, mimeType) {
|
|
40
|
+
if (
|
|
41
|
+
!IMAGE_TYPES.includes(mimeType) ||
|
|
42
|
+
!bytes.length ||
|
|
43
|
+
bytes.length > IMAGE_LIMITS.bytes
|
|
44
|
+
)
|
|
45
|
+
throw new Error("Unsupported image or size");
|
|
46
|
+
const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
47
|
+
const ascii = (at, value) =>
|
|
48
|
+
[...value].every((c, i) => bytes[at + i] === c.charCodeAt(0));
|
|
49
|
+
let width = 0,
|
|
50
|
+
height = 0;
|
|
51
|
+
if (
|
|
52
|
+
mimeType === "image/png" &&
|
|
53
|
+
bytes.length >= 33 &&
|
|
54
|
+
bytes[0] === 137 &&
|
|
55
|
+
ascii(1, "PNG\r\n\u001a\n") &&
|
|
56
|
+
v.getUint32(8) === 13 &&
|
|
57
|
+
ascii(12, "IHDR")
|
|
58
|
+
) {
|
|
59
|
+
width = v.getUint32(16);
|
|
60
|
+
height = v.getUint32(20);
|
|
61
|
+
} else if (
|
|
62
|
+
mimeType === "image/jpeg" &&
|
|
63
|
+
bytes[0] === 255 &&
|
|
64
|
+
bytes[1] === 216
|
|
65
|
+
) {
|
|
66
|
+
for (let p = 2; p + 3 < bytes.length; ) {
|
|
67
|
+
if (bytes[p++] !== 255) break;
|
|
68
|
+
while (bytes[p] === 255) p++;
|
|
69
|
+
const marker = bytes[p++];
|
|
70
|
+
if (marker === 217 || marker === 218) break;
|
|
71
|
+
if (marker === 1 || (marker >= 208 && marker <= 215)) continue;
|
|
72
|
+
if (p + 2 > bytes.length) break;
|
|
73
|
+
const length = v.getUint16(p);
|
|
74
|
+
if (length < 2 || p + length > bytes.length) break;
|
|
75
|
+
if (
|
|
76
|
+
[
|
|
77
|
+
192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207,
|
|
78
|
+
].includes(marker) &&
|
|
79
|
+
length >= 8
|
|
80
|
+
) {
|
|
81
|
+
height = v.getUint16(p + 3);
|
|
82
|
+
width = v.getUint16(p + 5);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
p += length;
|
|
86
|
+
}
|
|
87
|
+
} else if (
|
|
88
|
+
mimeType === "image/webp" &&
|
|
89
|
+
bytes.length >= 30 &&
|
|
90
|
+
ascii(0, "RIFF") &&
|
|
91
|
+
ascii(8, "WEBP") &&
|
|
92
|
+
v.getUint32(4, true) + 8 === bytes.length
|
|
93
|
+
) {
|
|
94
|
+
if (ascii(12, "VP8X")) {
|
|
95
|
+
width = 1 + bytes[24] + (bytes[25] << 8) + (bytes[26] << 16);
|
|
96
|
+
height = 1 + bytes[27] + (bytes[28] << 8) + (bytes[29] << 16);
|
|
97
|
+
} else if (
|
|
98
|
+
ascii(12, "VP8 ") &&
|
|
99
|
+
bytes[23] === 157 &&
|
|
100
|
+
bytes[24] === 1 &&
|
|
101
|
+
bytes[25] === 42
|
|
102
|
+
) {
|
|
103
|
+
width = v.getUint16(26, true) & 16383;
|
|
104
|
+
height = v.getUint16(28, true) & 16383;
|
|
105
|
+
} else if (ascii(12, "VP8L") && bytes[20] === 47) {
|
|
106
|
+
const bits = v.getUint32(21, true);
|
|
107
|
+
width = 1 + (bits & 16383);
|
|
108
|
+
height = 1 + ((bits >>> 14) & 16383);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (
|
|
112
|
+
!width ||
|
|
113
|
+
!height ||
|
|
114
|
+
width > IMAGE_LIMITS.dimension ||
|
|
115
|
+
height > IMAGE_LIMITS.dimension ||
|
|
116
|
+
width * height > IMAGE_LIMITS.pixels
|
|
117
|
+
)
|
|
118
|
+
throw new Error("Invalid image dimensions or header");
|
|
119
|
+
return { width, height };
|
|
120
|
+
}
|
package/src/native-build.ts
CHANGED
package/src/sdk-worker.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import {
|
|
5
5
|
closeSync,
|
|
6
6
|
constants,
|
|
7
|
+
createReadStream,
|
|
7
8
|
fstatSync,
|
|
8
9
|
openSync,
|
|
9
10
|
readFileSync,
|
|
@@ -26,6 +27,11 @@ import {
|
|
|
26
27
|
} from "@earendil-works/pi-coding-agent";
|
|
27
28
|
import { conversationResources } from "./conversation-resources.mjs";
|
|
28
29
|
import { coordinatorTools } from "./coordinator-tools.mjs";
|
|
30
|
+
import {
|
|
31
|
+
decodeImageBase64,
|
|
32
|
+
IMAGE_LIMITS,
|
|
33
|
+
validateImageBytes,
|
|
34
|
+
} from "./image-content.mjs";
|
|
29
35
|
import { researchClock, researchTools } from "./research-tools.mjs";
|
|
30
36
|
import {
|
|
31
37
|
BROWSER_COMMAND_ENTRY,
|
|
@@ -271,6 +277,7 @@ try {
|
|
|
271
277
|
: closed(envelope.conversation, [
|
|
272
278
|
"session",
|
|
273
279
|
"agentDir",
|
|
280
|
+
...(Object.hasOwn(envelope.conversation, "images") ? ["images"] : []),
|
|
274
281
|
...(Object.hasOwn(envelope.conversation, "coordinator")
|
|
275
282
|
? ["coordinator"]
|
|
276
283
|
: []),
|
|
@@ -652,6 +659,50 @@ try {
|
|
|
652
659
|
});
|
|
653
660
|
await capture.context(publicRequest, session.systemPrompt);
|
|
654
661
|
stage = "prompt";
|
|
662
|
+
let images;
|
|
663
|
+
if (Boolean(publicRequest.imageCount) !== Boolean(conversation?.images))
|
|
664
|
+
throw new Error("Missing image channel");
|
|
665
|
+
if (conversation?.images !== undefined) {
|
|
666
|
+
const descriptor = closed(conversation.images, ["bytes", "sha256"]);
|
|
667
|
+
if (
|
|
668
|
+
!Number.isSafeInteger(descriptor.bytes) ||
|
|
669
|
+
descriptor.bytes < 1 ||
|
|
670
|
+
descriptor.bytes > IMAGE_LIMITS.wireBytes ||
|
|
671
|
+
!/^[a-f0-9]{64}$/.test(descriptor.sha256) ||
|
|
672
|
+
!model.input?.includes("image")
|
|
673
|
+
)
|
|
674
|
+
throw new Error("Invalid image context");
|
|
675
|
+
const chunks = [];
|
|
676
|
+
let size = 0;
|
|
677
|
+
for await (const chunk of createReadStream(null, { fd: 3 })) {
|
|
678
|
+
size += chunk.length;
|
|
679
|
+
if (size > descriptor.bytes)
|
|
680
|
+
throw new Error("Image payload exceeds bound");
|
|
681
|
+
chunks.push(chunk);
|
|
682
|
+
}
|
|
683
|
+
const bytes = Buffer.concat(chunks);
|
|
684
|
+
if (
|
|
685
|
+
size !== descriptor.bytes ||
|
|
686
|
+
createHash("sha256").update(bytes).digest("hex") !== descriptor.sha256
|
|
687
|
+
)
|
|
688
|
+
throw new Error("Incomplete image payload");
|
|
689
|
+
images = JSON.parse(bytes.toString("utf8"));
|
|
690
|
+
if (
|
|
691
|
+
!Array.isArray(images) ||
|
|
692
|
+
!images.length ||
|
|
693
|
+
images.length !== publicRequest.imageCount
|
|
694
|
+
)
|
|
695
|
+
throw new Error("Invalid images");
|
|
696
|
+
let total = 0;
|
|
697
|
+
for (const image of images) {
|
|
698
|
+
closed(image, ["type", "data", "mimeType"]);
|
|
699
|
+
if (image.type !== "image") throw new Error("Invalid image");
|
|
700
|
+
const decoded = decodeImageBase64(image.data);
|
|
701
|
+
validateImageBytes(decoded, image.mimeType);
|
|
702
|
+
total += decoded.length;
|
|
703
|
+
}
|
|
704
|
+
if (total > IMAGE_LIMITS.totalBytes) throw new Error("Images exceed bound");
|
|
705
|
+
}
|
|
655
706
|
const suppliedPrompt = [
|
|
656
707
|
publicRequest.context,
|
|
657
708
|
...(!conversation && kind !== "code"
|
|
@@ -668,6 +719,7 @@ try {
|
|
|
668
719
|
.filter(Boolean)
|
|
669
720
|
.join("\n\n");
|
|
670
721
|
await session.prompt(suppliedPrompt, {
|
|
722
|
+
...(images ? { images } : {}),
|
|
671
723
|
expandPromptTemplates: false,
|
|
672
724
|
preflightResult: (accepted) => {
|
|
673
725
|
preflight = accepted ? "accepted" : "rejected";
|
|
@@ -77,6 +77,7 @@ export interface ModelChoiceState {
|
|
|
77
77
|
selected: ModelSelection | null;
|
|
78
78
|
}
|
|
79
79
|
export interface ModelCandidate {
|
|
80
|
+
images?: boolean;
|
|
80
81
|
provider: string;
|
|
81
82
|
model: string;
|
|
82
83
|
api: ModelSelection["api"] | null;
|
|
@@ -141,8 +142,10 @@ export function decodeModelCandidate(value: unknown): ModelCandidate {
|
|
|
141
142
|
"api",
|
|
142
143
|
"thinking",
|
|
143
144
|
"eligibility",
|
|
145
|
+
...(Object.hasOwn(value ?? {}, "images") ? ["images"] : []),
|
|
144
146
|
]);
|
|
145
147
|
const candidate: ModelCandidate = {
|
|
148
|
+
...(o.images === undefined ? {} : { images: bool(o.images) }),
|
|
146
149
|
provider: text(o.provider, 128, true),
|
|
147
150
|
model: text(o.model, 256, true),
|
|
148
151
|
api: nullable(o.api, (v) => oneOf(v, modelApis)),
|
|
@@ -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
|
|
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
|
|
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, [
|
|
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) };
|
package/src/service-cli.mjs
CHANGED
|
@@ -6311,7 +6311,12 @@ async function release(spec = "latest", npmRun = npm) {
|
|
|
6311
6311
|
if (result.status !== 0)
|
|
6312
6312
|
return;
|
|
6313
6313
|
try {
|
|
6314
|
-
|
|
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"]);
|