toolroll 0.9.116 → 0.9.117
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/CHANGELOG.md +36 -0
- package/README.md +43 -26
- package/dist/acp-agents.js +14 -1
- package/dist/acp-client.js +19 -1
- package/dist/agent-change-check.js +60 -0
- package/dist/agent-change-schema.js +19 -0
- package/dist/agent-detect.js +11 -1
- package/dist/agent-fence.js +39 -10
- package/dist/agent-network-request.js +108 -0
- package/dist/agent-requests.js +105 -0
- package/dist/approval-summary.js +3 -3
- package/dist/backup.js +17 -1
- package/dist/batch-checks.js +81 -18
- package/dist/browser/terminal.js +41 -41
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +36 -36
- package/dist/builder.js +3 -1
- package/dist/candidate-materialize.js +119 -0
- package/dist/central-enrollment-contract.js +156 -0
- package/dist/central-recovery-stage.js +329 -0
- package/dist/chat-actions.js +101 -2
- package/dist/chat-channel.js +40 -0
- package/dist/check-only-standing.js +13 -0
- package/dist/check-only.js +25 -13
- package/dist/check-recovery-hold.js +199 -0
- package/dist/check-recovery-index-schema.js +3 -0
- package/dist/check-screenshots.js +83 -0
- package/dist/cli.js +125 -6
- package/dist/codex-limits.js +4 -0
- package/dist/connect-cli.js +257 -11
- package/dist/contracts/chat-actions.js +4 -0
- package/dist/contracts/console-api.js +14 -3
- package/dist/contracts/engine-api.js +331 -2
- package/dist/contracts/lead-tools.js +56 -2
- package/dist/contracts/provider.js +1 -1
- package/dist/contracts/route.js +1 -1
- package/dist/contracts/terminal-connection.js +50 -0
- package/dist/converse.js +80 -4
- package/dist/device-pair.js +280 -0
- package/dist/direct-chat-artifacts.js +347 -0
- package/dist/direct-chat-catalog.js +311 -0
- package/dist/direct-chat-fence.js +96 -0
- package/dist/direct-chat-git.js +343 -0
- package/dist/direct-chat-laptop.js +19 -0
- package/dist/direct-chat-schema.js +181 -0
- package/dist/direct-chat-ship.js +861 -0
- package/dist/direct-chat-workspace.js +389 -0
- package/dist/direct-chat.js +2107 -0
- package/dist/doctor.js +1 -1
- package/dist/easy-start.js +18 -0
- package/dist/egress.js +25 -4
- package/dist/engine-chat.js +454 -0
- package/dist/engine-reads.js +141 -13
- package/dist/exec.js +4 -3
- package/dist/flexible-agents.js +8 -16
- package/dist/flexible-session.js +91 -47
- package/dist/flexible-ship.js +87 -7
- package/dist/flexible-start.js +4 -1
- package/dist/flexible-thread.js +2 -3
- package/dist/flexible-turns.js +26 -5
- package/dist/flow-triggers.js +13 -4
- package/dist/flows-ui.js +54 -20
- package/dist/handoff-cli.js +630 -0
- package/dist/invoke.js +55 -13
- package/dist/lead-contract.js +5 -4
- package/dist/lead-doors.js +80 -1
- package/dist/lead-progress.js +9 -0
- package/dist/lead-tools.js +681 -10
- package/dist/lead.js +37 -9
- package/dist/live-bus.js +11 -0
- package/dist/live-terminal.js +132 -12
- package/dist/local-handoff.js +363 -0
- package/dist/local-owner-acts.js +264 -2
- package/dist/local-owner.js +16 -1
- package/dist/multiplayer-handoff.js +528 -0
- package/dist/multiplayer-presence.js +471 -0
- package/dist/names.js +17 -4
- package/dist/needs-you.js +10 -0
- package/dist/operate.js +280 -19
- package/dist/policy.js +2 -2
- package/dist/project-delete-ui.js +18 -11
- package/dist/project-delete.js +65 -4
- package/dist/project-tools.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/provider-connection.js +2 -0
- package/dist/provider-home.js +251 -8
- package/dist/provider.js +3 -2
- package/dist/publish.js +119 -64
- package/dist/pull-request-flow.js +35 -14
- package/dist/read-executor-worker.js +1 -1
- package/dist/read-executor.js +95 -1
- package/dist/restore-retirement.js +152 -0
- package/dist/result-follow-ups.js +116 -37
- package/dist/route-change.js +44 -4
- package/dist/scope.js +62 -5
- package/dist/serve.js +49 -5
- package/dist/server/chat.js +94 -13
- package/dist/server/direct-chat.js +583 -0
- package/dist/server/engine-api.js +219 -21
- package/dist/server/flows.js +43 -10
- package/dist/server/found-repos.js +25 -0
- package/dist/server/guards.js +20 -6
- package/dist/server/live.js +81 -23
- package/dist/server/pages.js +67 -13
- package/dist/server/people-tokens.js +47 -6
- package/dist/server/remote.js +29 -0
- package/dist/server/render-results.js +6 -2
- package/dist/server/render-settings.js +4 -2
- package/dist/server/render-tasks.js +18 -17
- package/dist/server/route-table.js +69 -2
- package/dist/server/settings.js +22 -7
- package/dist/server/task-views.js +15 -3
- package/dist/server/tasks.js +39 -2
- package/dist/server/terminals.js +185 -11
- package/dist/settings-proofs.js +1 -1
- package/dist/store.js +499 -56
- package/dist/subscription-chat.js +33 -6
- package/dist/subscription-usage.js +233 -0
- package/dist/task-live.js +2 -1
- package/dist/teardown-git.js +34 -4
- package/dist/terminal-connection.js +159 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-contract.js +1 -1
- package/dist/tui-launch.js +32 -1
- package/dist/workspace-identity-schema.js +21 -0
- package/package.json +3 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { chatCardSchema } from "./chat-card.js";
|
|
3
4
|
import { parseContract } from "./contract.js";
|
|
4
5
|
export const ENGINE_API_VERSION = 1;
|
|
5
6
|
const version = z.literal(ENGINE_API_VERSION);
|
|
@@ -124,6 +125,10 @@ export const workRowsSchema = z.object({
|
|
|
124
125
|
next: z.string().nullable(),
|
|
125
126
|
room: z.literal("workspace"),
|
|
126
127
|
spend: z.object({ todayUsd: z.number(), planPercent: z.number().int().nullable() }).nullable(),
|
|
128
|
+
limits: z.array(z.object({
|
|
129
|
+
provider: z.string(), plan: z.string().nullable(), window: z.string(), usedPercent: z.number(),
|
|
130
|
+
reached: z.boolean(), resetsAt: z.string().nullable(), observedAt: z.string(),
|
|
131
|
+
})).nullable(),
|
|
127
132
|
});
|
|
128
133
|
export const stepCardSchema = z.object({
|
|
129
134
|
key: z.enum(["plan", "approve", "build", "checks", "review", "ready"]),
|
|
@@ -155,6 +160,8 @@ export const stepCardsSchema = z.object({
|
|
|
155
160
|
chain: z.enum(["plan-first", "just-code"]),
|
|
156
161
|
headline: z.string().nullable(),
|
|
157
162
|
liveRun: z.number().int().nullable(),
|
|
163
|
+
latestRun: z.number().int().nullable(),
|
|
164
|
+
models: z.array(z.object({ phase: z.string(), provider: z.string(), model: z.string(), chosen: z.enum(["recommended", "override", "pinned"]) })).nullable(),
|
|
158
165
|
cards: z.array(stepCardSchema).nullable(),
|
|
159
166
|
review: z.object({ run: z.number().int(), receipt: z.string().regex(/^[0-9a-f]{64}$/), source: z.string(),
|
|
160
167
|
accept: z.object({ owed: z.enum(["person-check", "exception"]).nullable(), blockers: z.array(z.string()), needs: z.string().nullable() }),
|
|
@@ -171,6 +178,10 @@ export const stepCardsSchema = z.object({
|
|
|
171
178
|
plan: z.object({ source: z.string().regex(/^[0-9a-f]{64}$/) }).nullable(),
|
|
172
179
|
planQueued: z.boolean(),
|
|
173
180
|
approval: z.object({ by: z.string(), you: z.boolean(), automatic: z.boolean() }).nullable(),
|
|
181
|
+
scopeDigest: z.string().nullable(),
|
|
182
|
+
agentChoices: z.object({ plan: z.array(z.object({ provider: z.string(), model: z.string() })), build: z.array(z.object({ provider: z.string(), model: z.string() })) }).nullable(),
|
|
183
|
+
pendingAgentChange: z.object({ phase: z.enum(["plan", "build"]), provider: z.string(), model: z.string(), when: z.enum(["next-run", "restart"]), by: z.string(), at: z.string(),
|
|
184
|
+
problem: z.string().nullable() }).nullable(),
|
|
174
185
|
room: z.string(),
|
|
175
186
|
});
|
|
176
187
|
export const approvalCardSchema = z.object({
|
|
@@ -259,10 +270,10 @@ export const modelsReadSchema = z.object({
|
|
|
259
270
|
export const termStateSchema = z.object({
|
|
260
271
|
available: z.boolean(),
|
|
261
272
|
problem: z.string().nullable(),
|
|
262
|
-
programs: z.array(z.enum(["claude", "codex", "shell"])),
|
|
273
|
+
programs: z.array(z.enum(["claude", "codex", "antigravity", "shell"])),
|
|
263
274
|
projects: z.array(z.object({ path: z.string(), name: z.string() })),
|
|
264
275
|
sessions: z.array(z.object({
|
|
265
|
-
id: z.string().regex(/^[0-9a-f]{32}$/), repo: z.string(), project: z.string(), program: z.enum(["claude", "codex", "shell"]), branch: z.string(),
|
|
276
|
+
id: z.string().regex(/^[0-9a-f]{32}$/), repo: z.string(), project: z.string(), program: z.enum(["claude", "codex", "antigravity", "shell"]), branch: z.string(),
|
|
266
277
|
startedAt: iso, endedAt: iso.nullable(), exit: z.object({ code: z.number().int().nullable(), signal: z.number().int().nullable() }).nullable(),
|
|
267
278
|
cleanup: z.enum(["clean", "uncertain"]).nullable(), task: z.string().nullable(), run: z.number().int().nullable(),
|
|
268
279
|
})),
|
|
@@ -271,6 +282,312 @@ export const termStartedSchema = z.discriminatedUnion("ok", [
|
|
|
271
282
|
z.object({ ok: z.literal(true), id: z.string().regex(/^[0-9a-f]{32}$/) }),
|
|
272
283
|
z.object({ ok: z.literal(false), error: z.string() }),
|
|
273
284
|
]);
|
|
285
|
+
const leadLinkSchema = z.object({
|
|
286
|
+
label: z.string(),
|
|
287
|
+
href: z.string(),
|
|
288
|
+
task: z.string().nullable(),
|
|
289
|
+
tab: z.enum(["live", "steps", "diff"]).nullable(),
|
|
290
|
+
});
|
|
291
|
+
const leadCardPrimarySchema = z.discriminatedUnion("kind", [
|
|
292
|
+
z.object({ kind: z.literal("confirm"), label: z.string(), irreversible: z.boolean(), native: z.boolean() }),
|
|
293
|
+
z.object({ kind: z.literal("link"), label: z.string(), href: z.string(), task: z.string().nullable(), tab: z.enum(["live", "steps", "diff"]).nullable() }),
|
|
294
|
+
]);
|
|
295
|
+
export const leadChatCardSchema = z.object({
|
|
296
|
+
id: z.number().int(),
|
|
297
|
+
kind: z.string(),
|
|
298
|
+
label: z.string(),
|
|
299
|
+
state: z.enum(["pending", "confirmed", "refused", "dismissed", "expired"]),
|
|
300
|
+
data: z.boolean(),
|
|
301
|
+
lines: z.array(z.string()),
|
|
302
|
+
card: chatCardSchema.nullable(),
|
|
303
|
+
said: z.string().nullable(),
|
|
304
|
+
note: z.string().nullable(),
|
|
305
|
+
primary: leadCardPrimarySchema.nullable(),
|
|
306
|
+
dismissable: z.boolean(),
|
|
307
|
+
links: z.array(leadLinkSchema),
|
|
308
|
+
});
|
|
309
|
+
const leadAskSchema = z.object({
|
|
310
|
+
turn: z.number().int(),
|
|
311
|
+
question: z.string(),
|
|
312
|
+
options: z.array(z.string()),
|
|
313
|
+
open: z.boolean(),
|
|
314
|
+
stale: z.boolean(),
|
|
315
|
+
});
|
|
316
|
+
const leadMessageSchema = z.object({
|
|
317
|
+
id: z.number().int(),
|
|
318
|
+
role: z.enum(["operator", "assistant"]),
|
|
319
|
+
text: z.string(),
|
|
320
|
+
activity: z.string().nullable(),
|
|
321
|
+
createdAt: iso,
|
|
322
|
+
cards: z.array(leadChatCardSchema),
|
|
323
|
+
ask: leadAskSchema.nullable(),
|
|
324
|
+
});
|
|
325
|
+
const leadQueuedSchema = z.object({
|
|
326
|
+
id: z.number().int(),
|
|
327
|
+
text: z.string(),
|
|
328
|
+
status: z.enum(["queued", "starting", "cancelled", "failed", "uncertain"]),
|
|
329
|
+
detail: z.string().nullable(),
|
|
330
|
+
});
|
|
331
|
+
export const leadChatSchema = z.object({
|
|
332
|
+
version,
|
|
333
|
+
room: z.string(),
|
|
334
|
+
session: z.number().int().nullable(),
|
|
335
|
+
leadName: z.string(),
|
|
336
|
+
canSend: z.boolean(),
|
|
337
|
+
problem: z.string().nullable(),
|
|
338
|
+
project: z.string().nullable(),
|
|
339
|
+
busy: z.boolean(),
|
|
340
|
+
pendingProposals: z.number().int(),
|
|
341
|
+
queued: z.array(leadQueuedSchema),
|
|
342
|
+
messages: z.array(leadMessageSchema),
|
|
343
|
+
});
|
|
344
|
+
const automationTriggerSchema = z.object({
|
|
345
|
+
id: z.number().int(),
|
|
346
|
+
kind: z.string(),
|
|
347
|
+
words: z.string(),
|
|
348
|
+
state: z.enum(["active", "paused"]),
|
|
349
|
+
nextAt: iso.nullable(),
|
|
350
|
+
lastAt: iso.nullable(),
|
|
351
|
+
lastOutcome: z.string().max(200).nullable(),
|
|
352
|
+
failures: z.number().int(),
|
|
353
|
+
canPress: z.boolean(),
|
|
354
|
+
canCheck: z.boolean(),
|
|
355
|
+
label: z.string().nullable(),
|
|
356
|
+
questions: z.array(z.string()).nullable(),
|
|
357
|
+
resumeRunsNow: z.boolean(),
|
|
358
|
+
});
|
|
359
|
+
export const automationsSchema = z.object({
|
|
360
|
+
version,
|
|
361
|
+
canAct: z.boolean(),
|
|
362
|
+
automations: z.array(z.object({
|
|
363
|
+
id: z.number().int(),
|
|
364
|
+
name: z.string(),
|
|
365
|
+
project: z.string().nullable(),
|
|
366
|
+
group: z.enum(["needs", "running", "on", "paused"]),
|
|
367
|
+
starts: z.string(),
|
|
368
|
+
nextAt: iso.nullable(),
|
|
369
|
+
waiting: z.number().int(),
|
|
370
|
+
inProgress: z.number().int(),
|
|
371
|
+
trouble: z.string().nullable(),
|
|
372
|
+
triggers: z.array(automationTriggerSchema),
|
|
373
|
+
})),
|
|
374
|
+
});
|
|
375
|
+
const namedPathSchema = z.object({ name: z.string(), path: z.string() });
|
|
376
|
+
export const projectsSchema = z.object({
|
|
377
|
+
version,
|
|
378
|
+
canAdd: z.boolean(),
|
|
379
|
+
projects: z.array(namedPathSchema),
|
|
380
|
+
found: z.array(namedPathSchema).max(40),
|
|
381
|
+
});
|
|
382
|
+
export const directChatProviderSchema = z.enum(["claude", "codex", "gemini"]);
|
|
383
|
+
export const directChatPostureSchema = z.object({
|
|
384
|
+
summary: z.string(),
|
|
385
|
+
detail: z.string(),
|
|
386
|
+
sandboxed: z.boolean(),
|
|
387
|
+
});
|
|
388
|
+
export const directChatToolSchema = z.object({
|
|
389
|
+
id: z.string(),
|
|
390
|
+
ordinal: z.number().int(),
|
|
391
|
+
name: z.string(),
|
|
392
|
+
detail: z.string(),
|
|
393
|
+
status: z.enum(["running", "done", "error"]),
|
|
394
|
+
updatedAt: iso,
|
|
395
|
+
});
|
|
396
|
+
export const directChatArtifactSchema = z.object({
|
|
397
|
+
id: hex32,
|
|
398
|
+
kind: z.enum(["output", "attachment"]),
|
|
399
|
+
filename: z.string(),
|
|
400
|
+
mimeType: z.string(),
|
|
401
|
+
byteSize: z.number().int(),
|
|
402
|
+
url: z.string(),
|
|
403
|
+
sourcePath: z.string().nullable(),
|
|
404
|
+
createdAt: iso,
|
|
405
|
+
});
|
|
406
|
+
export const directChatShipSummarySchema = z.object({
|
|
407
|
+
id: hex32,
|
|
408
|
+
seq: z.number().int(),
|
|
409
|
+
mode: z.enum(["ship", "keep-branch"]),
|
|
410
|
+
branch: z.string(),
|
|
411
|
+
candidateSha: z.string(),
|
|
412
|
+
state: z.enum(["kept", "imported", "armed", "completed", "merging", "merged", "cancelled", "failed"]),
|
|
413
|
+
taskId: z.string().nullable(),
|
|
414
|
+
prUrl: z.string().nullable(),
|
|
415
|
+
detail: z.string().nullable(),
|
|
416
|
+
createdAt: iso,
|
|
417
|
+
stateAt: iso,
|
|
418
|
+
});
|
|
419
|
+
export const directChatUsageSchema = z.object({
|
|
420
|
+
inputTokens: z.number().int(),
|
|
421
|
+
outputTokens: z.number().int(),
|
|
422
|
+
cacheReadTokens: z.number().int(),
|
|
423
|
+
cacheCreationTokens: z.number().int(),
|
|
424
|
+
thinkingTokens: z.number().int(),
|
|
425
|
+
contextTokens: z.number().int(),
|
|
426
|
+
contextWindow: z.number().int().nullable(),
|
|
427
|
+
costUsd: z.number().nullable(),
|
|
428
|
+
});
|
|
429
|
+
export const directChatModelOptionSchema = z.object({
|
|
430
|
+
provider: directChatProviderSchema,
|
|
431
|
+
id: z.string(),
|
|
432
|
+
label: z.string(),
|
|
433
|
+
efforts: z.array(z.string()),
|
|
434
|
+
defaultEffort: z.string().nullable(),
|
|
435
|
+
contextWindow: z.number().int().nullable(),
|
|
436
|
+
});
|
|
437
|
+
export const directChatTurnSchema = z.object({
|
|
438
|
+
id: hex32,
|
|
439
|
+
seq: z.number().int(),
|
|
440
|
+
userPrompt: z.string(),
|
|
441
|
+
switchedFromProvider: directChatProviderSchema.nullable(),
|
|
442
|
+
status: z.enum(["running", "completed", "stopped", "failed", "interrupted"]),
|
|
443
|
+
assistantText: z.string(),
|
|
444
|
+
errorText: z.string().nullable(),
|
|
445
|
+
createdAt: iso,
|
|
446
|
+
finishedAt: iso.nullable(),
|
|
447
|
+
usage: directChatUsageSchema.nullable(),
|
|
448
|
+
tools: z.array(directChatToolSchema),
|
|
449
|
+
artifacts: z.array(directChatArtifactSchema),
|
|
450
|
+
});
|
|
451
|
+
export const directChatSummarySchema = z.object({
|
|
452
|
+
id: hex32,
|
|
453
|
+
title: z.string(),
|
|
454
|
+
project: z.string(),
|
|
455
|
+
branch: z.string(),
|
|
456
|
+
provider: directChatProviderSchema,
|
|
457
|
+
modelId: z.string(),
|
|
458
|
+
effort: z.string().nullable(),
|
|
459
|
+
posture: directChatPostureSchema,
|
|
460
|
+
running: z.boolean(),
|
|
461
|
+
lastStatus: z.enum(["running", "completed", "stopped", "failed", "interrupted"]).nullable(),
|
|
462
|
+
changedFilesCount: z.number().int(),
|
|
463
|
+
mainDirtyFiles: z.array(z.string()),
|
|
464
|
+
usage: directChatUsageSchema.nullable(),
|
|
465
|
+
createdAt: iso,
|
|
466
|
+
updatedAt: iso,
|
|
467
|
+
});
|
|
468
|
+
export const directChatsListSchema = z.object({
|
|
469
|
+
version,
|
|
470
|
+
available: z.boolean(),
|
|
471
|
+
problem: z.string().nullable(),
|
|
472
|
+
backgroundOn: z.boolean(),
|
|
473
|
+
models: z.array(directChatModelOptionSchema),
|
|
474
|
+
threads: z.array(directChatSummarySchema),
|
|
475
|
+
});
|
|
476
|
+
export const directChatDetailSchema = z.object({
|
|
477
|
+
version,
|
|
478
|
+
room: z.string(),
|
|
479
|
+
thread: directChatSummarySchema,
|
|
480
|
+
turns: z.array(directChatTurnSchema),
|
|
481
|
+
attachments: z.array(directChatArtifactSchema),
|
|
482
|
+
ships: z.array(directChatShipSummarySchema),
|
|
483
|
+
diff: z.object({
|
|
484
|
+
changedFiles: z.array(z.string()),
|
|
485
|
+
diffText: z.string(),
|
|
486
|
+
dirty: z.boolean(),
|
|
487
|
+
}),
|
|
488
|
+
});
|
|
489
|
+
export const directChatShipPreviewSchema = z.object({
|
|
490
|
+
version,
|
|
491
|
+
threadId: hex32,
|
|
492
|
+
mode: z.enum(["ship", "keep-branch"]),
|
|
493
|
+
canAutoMerge: z.boolean(),
|
|
494
|
+
autoMergeReason: z.string().nullable(),
|
|
495
|
+
termsDigest: hex32,
|
|
496
|
+
title: z.string(),
|
|
497
|
+
goal: z.string(),
|
|
498
|
+
baseSha: z.string(),
|
|
499
|
+
branch: z.string(),
|
|
500
|
+
changedFiles: z.array(z.string()),
|
|
501
|
+
checkCommand: z.string().nullable(),
|
|
502
|
+
githubRepo: z.string().nullable(),
|
|
503
|
+
githubBase: z.string().nullable(),
|
|
504
|
+
mergeSummary: z.string(),
|
|
505
|
+
});
|
|
506
|
+
export const directChatShippedSchema = z.discriminatedUnion("ok", [
|
|
507
|
+
z.object({
|
|
508
|
+
ok: z.literal(true),
|
|
509
|
+
ship: directChatShipSummarySchema,
|
|
510
|
+
said: z.string(),
|
|
511
|
+
}),
|
|
512
|
+
z.object({ ok: z.literal(false), error: z.string(), code: z.string().optional() }),
|
|
513
|
+
]);
|
|
514
|
+
export const directChatAttachedSchema = z.discriminatedUnion("ok", [
|
|
515
|
+
z.object({
|
|
516
|
+
ok: z.literal(true),
|
|
517
|
+
artifact: directChatArtifactSchema,
|
|
518
|
+
cloneRelativePath: z.string().nullable(),
|
|
519
|
+
}),
|
|
520
|
+
z.object({ ok: z.literal(false), error: z.string() }),
|
|
521
|
+
]);
|
|
522
|
+
export const directChatStartedSchema = z.discriminatedUnion("ok", [
|
|
523
|
+
z.object({ ok: z.literal(true), threadId: hex32, turnId: hex32, room: z.string() }),
|
|
524
|
+
z.object({ ok: z.literal(false), error: z.string(), code: z.string().optional() }),
|
|
525
|
+
]);
|
|
526
|
+
export const directChatMutatedSchema = z.discriminatedUnion("ok", [
|
|
527
|
+
z.object({ ok: z.literal(true), said: z.string() }),
|
|
528
|
+
z.object({ ok: z.literal(false), error: z.string(), code: z.string().optional() }),
|
|
529
|
+
]);
|
|
530
|
+
export const taskResultReportItemSchema = z.object({
|
|
531
|
+
title: z.string(),
|
|
532
|
+
why: z.string(),
|
|
533
|
+
url: z.string(),
|
|
534
|
+
image: z.string().nullable(),
|
|
535
|
+
});
|
|
536
|
+
export const taskResultReportFollowUpSchema = z.object({
|
|
537
|
+
title: z.string(),
|
|
538
|
+
goal: z.string(),
|
|
539
|
+
});
|
|
540
|
+
export const taskResultReportShotSchema = z.object({
|
|
541
|
+
file: z.string(),
|
|
542
|
+
caption: z.string(),
|
|
543
|
+
url: z.string(),
|
|
544
|
+
artifactUrl: z.string().nullable(),
|
|
545
|
+
problem: z.string().nullable(),
|
|
546
|
+
});
|
|
547
|
+
export const taskResultReportSchema = z.discriminatedUnion("ok", [
|
|
548
|
+
z.object({
|
|
549
|
+
ok: z.literal(true),
|
|
550
|
+
title: z.string(),
|
|
551
|
+
summary: z.string(),
|
|
552
|
+
document: z.string(),
|
|
553
|
+
truncated: z.boolean(),
|
|
554
|
+
items: z.array(taskResultReportItemSchema),
|
|
555
|
+
followUps: z.array(taskResultReportFollowUpSchema),
|
|
556
|
+
shots: z.array(taskResultReportShotSchema),
|
|
557
|
+
}),
|
|
558
|
+
z.object({
|
|
559
|
+
ok: z.literal(false),
|
|
560
|
+
problem: z.string(),
|
|
561
|
+
}),
|
|
562
|
+
]);
|
|
563
|
+
export const taskResultHandoffSchema = z.object({
|
|
564
|
+
conclusion: z.string(),
|
|
565
|
+
changes: z.array(z.string()),
|
|
566
|
+
verification: z.array(z.string()),
|
|
567
|
+
followUps: z.array(z.string()),
|
|
568
|
+
decisions: z.array(z.string()),
|
|
569
|
+
assumptions: z.array(z.string()),
|
|
570
|
+
notDone: z.array(z.string()),
|
|
571
|
+
risks: z.array(z.string()),
|
|
572
|
+
});
|
|
573
|
+
export const taskResultScreenshotSchema = z.object({
|
|
574
|
+
caption: z.string(),
|
|
575
|
+
path: z.string(),
|
|
576
|
+
url: z.string(),
|
|
577
|
+
});
|
|
578
|
+
export const taskResultSchema = z.object({
|
|
579
|
+
version,
|
|
580
|
+
task: z.string(),
|
|
581
|
+
deliverable: z.enum(["code", "report"]),
|
|
582
|
+
run: z.number().int().nullable(),
|
|
583
|
+
role: z.string().nullable(),
|
|
584
|
+
outcome: z.string().nullable(),
|
|
585
|
+
verdict: z.string().nullable(),
|
|
586
|
+
summary: z.string().nullable(),
|
|
587
|
+
report: taskResultReportSchema.nullable(),
|
|
588
|
+
handoff: taskResultHandoffSchema.nullable(),
|
|
589
|
+
screenshots: z.array(taskResultScreenshotSchema),
|
|
590
|
+
});
|
|
274
591
|
export const linkRedemptionSchema = z.object({
|
|
275
592
|
version,
|
|
276
593
|
account: z.string(),
|
|
@@ -278,6 +595,7 @@ export const linkRedemptionSchema = z.object({
|
|
|
278
595
|
csrf: z.string().regex(/^[0-9a-f]{64}$/),
|
|
279
596
|
key: z.string().regex(/^[0-9a-f]{64}$/),
|
|
280
597
|
epoch: z.string(),
|
|
598
|
+
passwordSet: z.boolean().optional(),
|
|
281
599
|
});
|
|
282
600
|
export const linkRedemptionRequestSchema = z.strictObject({ code: z.string().regex(/^[A-Za-z0-9_-]{43}$/) });
|
|
283
601
|
export const ENGINE_REQUESTS = {
|
|
@@ -295,13 +613,24 @@ export const ENGINE_RESPONSES = {
|
|
|
295
613
|
resultDiff: { route: "GET /t/<task>/diff", schema: resultDiffSchema },
|
|
296
614
|
resultDiffFile: { route: "GET /t/<task>/diff?run=&file=", schema: resultDiffFileSchema },
|
|
297
615
|
resultDiffContext: { route: "GET /t/<task>/diff?run=&file=&from=&count=", schema: resultDiffContextSchema },
|
|
616
|
+
taskResult: { route: "GET /t/<task>/result", schema: taskResultSchema },
|
|
298
617
|
linkRedemption: { route: "POST /login/once", schema: linkRedemptionSchema },
|
|
299
618
|
refusal: { route: "every engine route's refusal", schema: engineRefusalSchema },
|
|
300
619
|
hello: { route: "GET /engine/hello", schema: helloSchema },
|
|
301
620
|
agents: { route: "GET /engine/agents", schema: agentsReadSchema },
|
|
302
621
|
models: { route: "GET /engine/models", schema: modelsReadSchema },
|
|
622
|
+
leadChat: { route: "GET /engine/chat", schema: leadChatSchema },
|
|
623
|
+
automations: { route: "GET /engine/automations", schema: automationsSchema },
|
|
624
|
+
projects: { route: "GET /engine/projects", schema: projectsSchema },
|
|
303
625
|
termState: { route: "GET /term/state", schema: termStateSchema },
|
|
304
626
|
termStarted: { route: "POST /term/start, /term/agent/sign-in, /term/agent/install", schema: termStartedSchema },
|
|
627
|
+
directChatsList: { route: "GET /engine/direct-chats", schema: directChatsListSchema },
|
|
628
|
+
directChatDetail: { route: "GET /engine/direct-chats/<id>", schema: directChatDetailSchema },
|
|
629
|
+
directChatStarted: { route: "POST /engine/direct-chats, /engine/direct-chats/<id>/messages", schema: directChatStartedSchema },
|
|
630
|
+
directChatMutated: { route: "POST /engine/direct-chats/<id>/{stop,model,delete,apply-main-edits,ship-cancel}", schema: directChatMutatedSchema },
|
|
631
|
+
directChatShipPreview: { route: "POST /engine/direct-chats/<id>/ship-preview", schema: directChatShipPreviewSchema },
|
|
632
|
+
directChatShipped: { route: "POST /engine/direct-chats/<id>/ship", schema: directChatShippedSchema },
|
|
633
|
+
directChatAttached: { route: "POST /engine/direct-chats/<id>/attachments", schema: directChatAttachedSchema },
|
|
305
634
|
};
|
|
306
635
|
const toStderr = (route, issues) => process.stderr.write(`engine api: ${route} disagrees with its contract: ${issues.slice(0, 5).map(one => `${one.path} ${one.kind}`).join("; ")}\n`);
|
|
307
636
|
export function checkEngineResponse(name, payload, report = toStderr) {
|
|
@@ -33,14 +33,15 @@ export const acceptance = z.array(acceptanceCriterionSchema).min(1).max(ACCEPTAN
|
|
|
33
33
|
const note = z.string().max(LIMITS.note, { error: issue => overBy(LIMITS.note, issue.input) }).describe(`At most ${LIMITS.note} characters; longer is refused with its length, not cut.`);
|
|
34
34
|
export const CODE_MAP_VIEWS = ["overview", "area", "file", "search"];
|
|
35
35
|
const VIEW_THEME_NAME = /^[a-z][a-z0-9-]{0,31}$/;
|
|
36
|
-
export const VIEW_ROLES = ["paper", "ink", "muted", "line", "selection", "selection-ink", "ground", "raised", "fill"];
|
|
36
|
+
export const VIEW_ROLES = ["paper", "ink", "muted", "line", "selection", "selection-ink", "ground", "raised", "fill", "chat-bubble", "chat-bubble-ink"];
|
|
37
37
|
const viewHex = z.string().regex(/^#[0-9a-fA-F]{6}$/);
|
|
38
38
|
const viewColors = z.strictObject({
|
|
39
39
|
paper: viewHex.optional(), ink: viewHex.optional(), muted: viewHex.optional(), line: viewHex.optional(), selection: viewHex.optional(),
|
|
40
40
|
"selection-ink": viewHex.optional(), ground: viewHex.optional(), raised: viewHex.optional(), fill: viewHex.optional(),
|
|
41
|
+
"chat-bubble": viewHex.optional(), "chat-bubble-ink": viewHex.optional(),
|
|
41
42
|
});
|
|
42
43
|
export const LISTED_TASK_STATES = ["queued", "running", "done", "failed", "cancelled"];
|
|
43
|
-
const ACTION_OPERATIONS = Object.keys(CHAT_ACTIONS).filter(one => !one.startsWith("flow_") && !one.startsWith("subagent_") && one !== "task_start");
|
|
44
|
+
const ACTION_OPERATIONS = Object.keys(CHAT_ACTIONS).filter(one => !one.startsWith("flow_") && !one.startsWith("subagent_") && !one.startsWith("direct_chat_") && one !== "task_start");
|
|
44
45
|
const cardProps = z.strictObject({
|
|
45
46
|
source: z.enum(CARD_SOURCES).optional(), chart: z.enum(CARD_CHART_TYPES).optional(), columns: z.array(z.string().max(40)).max(CARD_LIMITS.columns).optional(), facts: z.array(z.string().max(40)).max(CARD_LIMITS.facts).optional(),
|
|
46
47
|
repo: repoId.optional(), state: z.enum(CARD_TASK_STATES).optional(), limit: z.int().min(1).max(CARD_LIMITS.rows).optional(), flow: id.optional(), days: z.int().min(1).max(90).optional(),
|
|
@@ -175,6 +176,51 @@ export const LEAD_TOOL_INPUTS = {
|
|
|
175
176
|
show_costs: z.boolean().optional(),
|
|
176
177
|
notifications: z.strictObject({ asks: z.boolean().optional(), finished: z.boolean().optional(), failed: z.boolean().optional() }).optional(),
|
|
177
178
|
}),
|
|
179
|
+
list_direct_chats: z.strictObject({
|
|
180
|
+
repo: repoId.optional(),
|
|
181
|
+
include_archived: z.boolean().optional(),
|
|
182
|
+
limit: z.int().min(1).max(40).optional(),
|
|
183
|
+
}),
|
|
184
|
+
get_direct_chat: z.strictObject({
|
|
185
|
+
chat: z.string().min(1).max(80),
|
|
186
|
+
limit: z.int().min(1).max(30).optional(),
|
|
187
|
+
}),
|
|
188
|
+
get_direct_chat_diff: z.strictObject({
|
|
189
|
+
chat: z.string().min(1).max(80),
|
|
190
|
+
max_patch_chars: z.int().min(200).max(20_000).optional(),
|
|
191
|
+
}),
|
|
192
|
+
manage_direct_chat: z.strictObject({
|
|
193
|
+
chat: z.string().min(1).max(80),
|
|
194
|
+
operation: z.enum(["stop", "archive", "unarchive", "set_model", "rename"]),
|
|
195
|
+
provider: z.enum(["claude", "codex", "gemini"]).optional(),
|
|
196
|
+
model: z.string().min(1).max(120).optional(),
|
|
197
|
+
effort: z.enum(["low", "medium", "high", "xhigh", "max", "ultra"]).nullable().optional(),
|
|
198
|
+
title: z.string().min(1).max(160).optional(),
|
|
199
|
+
}),
|
|
200
|
+
get_usage_limits: z.strictObject({}),
|
|
201
|
+
get_recent_updates: z.strictObject({
|
|
202
|
+
repo: repoId.optional(),
|
|
203
|
+
since: text("recapSince").optional(),
|
|
204
|
+
hours: z.int().min(1).max(168).optional(),
|
|
205
|
+
}),
|
|
206
|
+
propose_direct_chat: z.strictObject({
|
|
207
|
+
operation: z.enum(["start", "reply", "promote", "ship"]),
|
|
208
|
+
repo: repoId.optional(),
|
|
209
|
+
chat: z.string().min(1).max(80).optional(),
|
|
210
|
+
prompt: note.optional(),
|
|
211
|
+
provider: z.enum(["claude", "codex", "gemini"]).optional(),
|
|
212
|
+
model: z.string().min(1).max(120).optional(),
|
|
213
|
+
effort: z.enum(["low", "medium", "high", "xhigh", "max", "ultra"]).nullable().optional(),
|
|
214
|
+
mode: z.enum(["ship", "keep-branch"]).optional(),
|
|
215
|
+
title: text("taskTitle").optional(),
|
|
216
|
+
goal: scopeText.optional(),
|
|
217
|
+
planning: z.enum(["auto", "required", "skip"]).optional(),
|
|
218
|
+
}),
|
|
219
|
+
propose_report_followups: z.strictObject({
|
|
220
|
+
task: taskRef,
|
|
221
|
+
indices: z.array(z.int().min(1).max(20)).min(1).max(5).optional(),
|
|
222
|
+
planning: z.enum(["auto", "required", "skip"]).optional(),
|
|
223
|
+
}),
|
|
178
224
|
};
|
|
179
225
|
export const LEAD_TOOL_READ_INPUTS = {
|
|
180
226
|
...LEAD_TOOL_INPUTS,
|
|
@@ -285,6 +331,14 @@ export const LEAD_TOOL_OUTPUTS = {
|
|
|
285
331
|
propose_cancel: proposed("cancel", { task: str }),
|
|
286
332
|
toolroll_view_read: z.looseObject({ settings: z.looseObject({}), allowed: z.looseObject({}), roles: list, themes: z.looseObject({}), guide: str }),
|
|
287
333
|
toolroll_view_set: z.looseObject({ changed: z.array(str), said: str }),
|
|
334
|
+
list_direct_chats: z.looseObject({ chats: rows({ chat: str, title: str, provider: str, model: str, running: z.boolean() }), total: int }),
|
|
335
|
+
get_direct_chat: z.looseObject({ chat: str, title: str, provider: str, model: str, running: z.boolean(), turns: list }),
|
|
336
|
+
get_direct_chat_diff: z.looseObject({ chat: str, title: str, branch: str, running: z.boolean(), changedFiles: z.array(str), dirty: z.boolean(), canShip: z.boolean(), canAutoMerge: z.boolean(), recommendedMode: str }),
|
|
337
|
+
manage_direct_chat: z.looseObject({ chat: str, operation: str, said: str }),
|
|
338
|
+
get_usage_limits: z.looseObject({ summary: nullable(str), windows: list, budgets: list }),
|
|
339
|
+
get_recent_updates: z.looseObject({ since: str, headline: str, tasksReady: list, tasksCompleted: list, tasksFailed: list, directChatsUpdated: list, openDecisions: list }),
|
|
340
|
+
propose_direct_chat: cardDrafted,
|
|
341
|
+
propose_report_followups: z.looseObject({ task: str, reportTitle: str, drafted: rows({ index: int, proposal: int, title: str }), awaiting: str }),
|
|
288
342
|
};
|
|
289
343
|
export function reportToolOutput(surface, tool, schema, body) {
|
|
290
344
|
const read = parseContract(schema, body);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export const PROVIDER_ID_VALUES = ["claude", "codex", "openrouter", "gemini", "opencode", "cursor", "cline", "qwen", "goose"];
|
|
2
|
+
export const PROVIDER_ID_VALUES = ["claude", "codex", "openrouter", "gemini", "opencode", "cursor", "cline", "qwen", "goose", "antigravity"];
|
|
3
3
|
export const providerIdSchema = z.enum(PROVIDER_ID_VALUES);
|
|
4
4
|
export const MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
5
5
|
export const modelIdSchema = z.string().regex(MODEL_ID);
|
package/dist/contracts/route.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EVIDENCE_KINDS } from "./acceptance-terms.js";
|
|
|
3
3
|
import { limited, parseContract, versioned } from "./contract.js";
|
|
4
4
|
import { selectionSchema } from "./route-results.js";
|
|
5
5
|
export const ROUTE_PHASES = ["plan", "build", "repair", "review"];
|
|
6
|
-
export const ROUTE_PROVIDERS = ["claude", "codex", "openrouter", "gemini", "opencode", "cursor", "cline", "qwen", "goose"];
|
|
6
|
+
export const ROUTE_PROVIDERS = ["claude", "codex", "openrouter", "gemini", "opencode", "cursor", "cline", "qwen", "goose", "antigravity"];
|
|
7
7
|
export const MODEL_ID_SHAPE = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
8
8
|
export const RISKS = ["routine", "elevated", "high"];
|
|
9
9
|
export const TASK_SIZE_WORDS = ["small", "medium", "large"];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { RECOVERY_GENERATION_PATTERN, WORKSPACE_ID_PATTERN } from "../workspace-identity-schema.js";
|
|
3
|
+
export const TERMINAL_CONNECTION_PROTOCOL = 1;
|
|
4
|
+
export const REMOTE_TUI_COMMANDS = [
|
|
5
|
+
"task add",
|
|
6
|
+
"task steer",
|
|
7
|
+
"task complete",
|
|
8
|
+
"task revise",
|
|
9
|
+
"task assign",
|
|
10
|
+
"task stop",
|
|
11
|
+
"task resume",
|
|
12
|
+
"task hold",
|
|
13
|
+
"task unhold",
|
|
14
|
+
"task requeue",
|
|
15
|
+
];
|
|
16
|
+
const printable = z.string().refine(value => [...value].length >= 1 && [...value].length <= 200
|
|
17
|
+
&& !/[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u202a-\u202e\u2060\u2066-\u2069\ufeff\ud800-\udfff]/u.test(value));
|
|
18
|
+
const canonicalDate = z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/)
|
|
19
|
+
.refine(value => Number.isFinite(Date.parse(value)) && new Date(value).toISOString() === value);
|
|
20
|
+
export const terminalConnectionSchema = z.strictObject({
|
|
21
|
+
protocol: z.literal(TERMINAL_CONNECTION_PROTOCOL),
|
|
22
|
+
workspace: z.strictObject({ id: z.string().regex(WORKSPACE_ID_PATTERN), recoveryGeneration: z.string().regex(RECOVERY_GENERATION_PATTERN), label: printable }),
|
|
23
|
+
principal: z.strictObject({ account: printable, role: z.enum(["viewer", "approver"]), access: z.enum(["read", "act"]), expiresAt: canonicalDate }),
|
|
24
|
+
engine: z.strictObject({ version: z.literal(1), contract: z.string().regex(/^[0-9a-f]{64}$/) }),
|
|
25
|
+
capabilities: z.strictObject({
|
|
26
|
+
workRows: z.boolean(), stepCards: z.boolean(), resultDiff: z.boolean(), runLiveWindow: z.boolean(),
|
|
27
|
+
leadChat: z.boolean(), liveStream: z.boolean(),
|
|
28
|
+
commands: z.array(z.enum(REMOTE_TUI_COMMANDS)), approval: z.literal("browser"),
|
|
29
|
+
providerSetup: z.literal(false), localCode: z.boolean(), localExecution: z.literal(false), interactive: z.literal(false),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
export const TERMINAL_CONNECTION_ERRORS = [
|
|
33
|
+
"request",
|
|
34
|
+
"unauthenticated",
|
|
35
|
+
"credential-purpose",
|
|
36
|
+
"workspace-mismatch",
|
|
37
|
+
"recovery-changed",
|
|
38
|
+
"workspace-unavailable",
|
|
39
|
+
"contract-unavailable",
|
|
40
|
+
];
|
|
41
|
+
export const terminalConnectionRefusalSchema = z.strictObject({
|
|
42
|
+
protocol: z.literal(TERMINAL_CONNECTION_PROTOCOL),
|
|
43
|
+
error: z.enum(TERMINAL_CONNECTION_ERRORS),
|
|
44
|
+
});
|
|
45
|
+
export const DISABLED_TERMINAL_CAPABILITIES = Object.freeze({
|
|
46
|
+
workRows: false, stepCards: false, resultDiff: false, runLiveWindow: false,
|
|
47
|
+
leadChat: false, liveStream: false,
|
|
48
|
+
commands: [], approval: "browser",
|
|
49
|
+
providerSetup: false, localCode: false, localExecution: false, interactive: false,
|
|
50
|
+
});
|
package/dist/converse.js
CHANGED
|
@@ -306,6 +306,58 @@ export function settleWithCache(price, answer) {
|
|
|
306
306
|
return plain * price.inMicrousd + write * Math.ceil(price.inMicrousd * CACHE_WRITE_RATIO) + read * Math.ceil(price.inMicrousd * CACHE_READ_RATIO)
|
|
307
307
|
+ answer.tokensOut * price.outMicrousd;
|
|
308
308
|
}
|
|
309
|
+
const LEAD_IMAGE_MEDIA_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
310
|
+
export const LEAD_MAX_IMAGES_PER_MESSAGE = 4;
|
|
311
|
+
const LEAD_MAX_IMAGE_BYTES = 4 * 1024 * 1024;
|
|
312
|
+
function imageMagicMatches(mediaType, bytes) {
|
|
313
|
+
if (bytes.length < 12)
|
|
314
|
+
return false;
|
|
315
|
+
if (mediaType === "image/png")
|
|
316
|
+
return bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47;
|
|
317
|
+
if (mediaType === "image/jpeg")
|
|
318
|
+
return bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff;
|
|
319
|
+
if (mediaType === "image/gif")
|
|
320
|
+
return bytes.subarray(0, 6).toString("ascii") === "GIF89a" || bytes.subarray(0, 6).toString("ascii") === "GIF87a";
|
|
321
|
+
if (mediaType === "image/webp")
|
|
322
|
+
return bytes.subarray(0, 4).toString("ascii") === "RIFF" && bytes.subarray(8, 12).toString("ascii") === "WEBP";
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
export function parseLeadImagesField(raw) {
|
|
326
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
327
|
+
return [];
|
|
328
|
+
let parsed;
|
|
329
|
+
try {
|
|
330
|
+
parsed = JSON.parse(raw);
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
if (!Array.isArray(parsed))
|
|
336
|
+
return [];
|
|
337
|
+
const out = [];
|
|
338
|
+
for (const item of parsed.slice(0, LEAD_MAX_IMAGES_PER_MESSAGE)) {
|
|
339
|
+
if (typeof item !== "object" || item === null || Array.isArray(item))
|
|
340
|
+
continue;
|
|
341
|
+
const rec = item;
|
|
342
|
+
const mediaType = rec["mediaType"];
|
|
343
|
+
const dataBase64 = rec["dataBase64"];
|
|
344
|
+
if (typeof mediaType !== "string" || !LEAD_IMAGE_MEDIA_TYPES.has(mediaType))
|
|
345
|
+
continue;
|
|
346
|
+
if (typeof dataBase64 !== "string" || dataBase64.length === 0 || dataBase64.length > Math.ceil(LEAD_MAX_IMAGE_BYTES * 1.4))
|
|
347
|
+
continue;
|
|
348
|
+
if (!/^[A-Za-z0-9+/=\s]+$/.test(dataBase64))
|
|
349
|
+
continue;
|
|
350
|
+
const cleanB64 = dataBase64.replace(/\s+/g, "");
|
|
351
|
+
const bytes = Buffer.from(cleanB64, "base64");
|
|
352
|
+
if (bytes.length === 0 || bytes.length > LEAD_MAX_IMAGE_BYTES)
|
|
353
|
+
continue;
|
|
354
|
+
if (!imageMagicMatches(mediaType, bytes))
|
|
355
|
+
continue;
|
|
356
|
+
const filename = typeof rec["filename"] === "string" ? rec["filename"].trim().slice(0, 120) : undefined;
|
|
357
|
+
out.push({ mediaType: mediaType, dataBase64: cleanB64, ...(filename ? { filename } : {}) });
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
309
361
|
export function parseLeadProviderWrapper(provider, bytes) {
|
|
310
362
|
const parsed = strictJsonParse(bytes, WRAPPER_CAP_BYTES, 14);
|
|
311
363
|
if (!parsed.ok)
|
|
@@ -440,8 +492,20 @@ export function composeLeadRequest(args) {
|
|
|
440
492
|
const cached = args.cache !== undefined;
|
|
441
493
|
const messages = [{ role: "user", content: cached ? [{ type: "text", text: opener, ...ephemeral }] : opener }];
|
|
442
494
|
for (const one of args.history) {
|
|
443
|
-
if (one.role === "operator")
|
|
444
|
-
|
|
495
|
+
if (one.role === "operator") {
|
|
496
|
+
if (one.images !== undefined && one.images.length > 0) {
|
|
497
|
+
messages.push({
|
|
498
|
+
role: "user",
|
|
499
|
+
content: [
|
|
500
|
+
...one.images.map(img => ({ type: "image", source: { type: "base64", media_type: img.mediaType, data: img.dataBase64 } })),
|
|
501
|
+
{ type: "text", text: one.text },
|
|
502
|
+
],
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
messages.push({ role: "user", content: one.text });
|
|
507
|
+
}
|
|
508
|
+
}
|
|
445
509
|
else if (one.role === "assistant") {
|
|
446
510
|
const blocks = [];
|
|
447
511
|
if (one.text !== "")
|
|
@@ -468,8 +532,20 @@ export function composeLeadRequest(args) {
|
|
|
468
532
|
}
|
|
469
533
|
const messages = [{ role: "system", content: args.system }, { role: "user", content: opener }];
|
|
470
534
|
for (const one of args.history) {
|
|
471
|
-
if (one.role === "operator")
|
|
472
|
-
|
|
535
|
+
if (one.role === "operator") {
|
|
536
|
+
if (one.images !== undefined && one.images.length > 0) {
|
|
537
|
+
messages.push({
|
|
538
|
+
role: "user",
|
|
539
|
+
content: [
|
|
540
|
+
...one.images.map(img => ({ type: "image_url", image_url: { url: `data:${img.mediaType};base64,${img.dataBase64}` } })),
|
|
541
|
+
{ type: "text", text: one.text },
|
|
542
|
+
],
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
messages.push({ role: "user", content: one.text });
|
|
547
|
+
}
|
|
548
|
+
}
|
|
473
549
|
else if (one.role === "assistant") {
|
|
474
550
|
messages.push({
|
|
475
551
|
role: "assistant",
|