@aibridge/driver-agy 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +269 -62
- package/package.json +2 -2
- package/src/agy.test.ts +23 -1
- package/src/agy.ts +16 -0
- package/src/generateImage.test.ts +3 -1
- package/src/generateImage.ts +1 -1
- package/src/index.ts +6 -1
- package/src/run.test.ts +595 -92
- package/src/run.ts +362 -72
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @aibridge/driver-agy
|
|
2
2
|
|
|
3
3
|
Driver for the Antigravity (`agy`) CLI. It builds print-mode commands, checks
|
|
4
|
-
availability, runs delegated tasks, captures
|
|
5
|
-
windows.
|
|
4
|
+
availability, runs delegated tasks, captures their answers, and reads quota
|
|
5
|
+
windows. Delegation `run()` uses `--output-format stream-json` when agy is ≥ 1.2.3; image generation does not.
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
import { probe, run, fetchAgyQuota } from '@aibridge/driver-agy';
|
package/dist/index.d.mts
CHANGED
|
@@ -20,6 +20,8 @@ interface AgyPrintArgs {
|
|
|
20
20
|
* Assemble the `agy -p …` argv.
|
|
21
21
|
*/
|
|
22
22
|
declare function buildAgyPrintArgs(prompt: string, opts: AgyPrintArgs): string[];
|
|
23
|
+
declare const MIN_AGY_STREAM_JSON: readonly [number, number, number];
|
|
24
|
+
declare function agySupportsStreamJson(versionLine: string | null): boolean;
|
|
23
25
|
//#endregion
|
|
24
26
|
//#region src/agyQuota.d.ts
|
|
25
27
|
/**
|
|
@@ -143,6 +145,7 @@ interface DelegationTask {
|
|
|
143
145
|
readonly onStdout?: (chunk: string) => void;
|
|
144
146
|
readonly onStderr?: (chunk: string) => void;
|
|
145
147
|
readonly onSpawn?: (pid: number) => void;
|
|
148
|
+
readonly onActivity?: () => void;
|
|
146
149
|
}
|
|
147
150
|
type DelegationResult = {
|
|
148
151
|
readonly ok: true;
|
|
@@ -156,4 +159,4 @@ type DelegationResult = {
|
|
|
156
159
|
};
|
|
157
160
|
declare function run(task: DelegationTask, exec?: typeof runCaptured): Promise<DelegationResult>;
|
|
158
161
|
//#endregion
|
|
159
|
-
export { AGY_CANONICAL_TO_NATIVE, type AgyModelQuota, type AgyPrintArgs, type AgyQuotaBucket, type AgyQuotaGroup, type AgyQuotaSnapshot, type Availability, type DelegationResult, type DelegationTask, type ImageGenRequest, type ImageResult, agyTokenPath, buildAgyPrintArgs, fetchAgyQuota, findModelQuota, generateImage, parseModels, parseQuotaGroups, probe, run };
|
|
162
|
+
export { AGY_CANONICAL_TO_NATIVE, type AgyModelQuota, type AgyPrintArgs, type AgyQuotaBucket, type AgyQuotaGroup, type AgyQuotaSnapshot, type Availability, type DelegationResult, type DelegationTask, type ImageGenRequest, type ImageResult, MIN_AGY_STREAM_JSON, agySupportsStreamJson, agyTokenPath, buildAgyPrintArgs, fetchAgyQuota, findModelQuota, generateImage, parseModels, parseQuotaGroups, probe, run };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AuthExpiredError, isNotFound, probeVersion, runCaptured, semverGte, stripAnsi } from "@aibridge/proc";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
4
|
-
import { AuthExpiredError, isNotFound, runCaptured, stripAnsi } from "@aibridge/proc";
|
|
5
5
|
//#region src/agy.ts
|
|
6
6
|
/**
|
|
7
7
|
* Assemble the `agy -p …` argv.
|
|
@@ -19,6 +19,22 @@ function buildAgyPrintArgs(prompt, opts) {
|
|
|
19
19
|
for (const dir of opts.addDirs ?? []) args.push("--add-dir", dir);
|
|
20
20
|
return args;
|
|
21
21
|
}
|
|
22
|
+
const MIN_AGY_STREAM_JSON = [
|
|
23
|
+
1,
|
|
24
|
+
2,
|
|
25
|
+
3
|
|
26
|
+
];
|
|
27
|
+
const STRICT_AGY_VERSION_RE = /^(?:agy(?: version)?\s+)?(\d+)\.(\d+)\.(\d+)(?:\s.*)?$/i;
|
|
28
|
+
function agySupportsStreamJson(versionLine) {
|
|
29
|
+
if (!versionLine) return false;
|
|
30
|
+
const m = versionLine.trim().match(STRICT_AGY_VERSION_RE);
|
|
31
|
+
if (!m) return false;
|
|
32
|
+
return semverGte([
|
|
33
|
+
Number(m[1]),
|
|
34
|
+
Number(m[2]),
|
|
35
|
+
Number(m[3])
|
|
36
|
+
], MIN_AGY_STREAM_JSON);
|
|
37
|
+
}
|
|
22
38
|
//#endregion
|
|
23
39
|
//#region src/registry.ts
|
|
24
40
|
const AGY_CANONICAL_TO_NATIVE = {
|
|
@@ -247,7 +263,7 @@ async function generateImage(req, exec = runCaptured) {
|
|
|
247
263
|
let instruction;
|
|
248
264
|
if (req.imagePaths.length > 0) {
|
|
249
265
|
const refs = req.imagePaths.map((p) => JSON.stringify(p)).join(", ");
|
|
250
|
-
instruction = `Call the generate_image tool once with ImageName="aibridge-render", Prompt=${JSON.stringify(req.prompt)}, and ImagePaths=[${refs}]. Change only what the instruction asks, using the references for subject/identity.${req.aspectRatio ? ` Pass AspectRatio='${req.aspectRatio}'
|
|
266
|
+
instruction = `Call the generate_image tool once with ImageName="aibridge-render", Prompt=${JSON.stringify(req.prompt)}, and ImagePaths=[${refs}]. Change only what the instruction asks, using the references for subject/identity.${req.aspectRatio ? ` Pass AspectRatio='${req.aspectRatio}'.` : ""} After the tool returns, print ONLY the absolute filesystem path of the saved image on a single line. No other text.`;
|
|
251
267
|
} else instruction = `Call the generate_image tool once with ImageName="aibridge-render" and Prompt=${JSON.stringify(req.prompt)}.${req.aspectRatio ? ` Pass AspectRatio='${req.aspectRatio}'.` : ""} After the tool returns, print ONLY the absolute filesystem path of the saved image on a single line. No other text.`;
|
|
252
268
|
const beforePaths = brainImagePaths();
|
|
253
269
|
let result;
|
|
@@ -362,79 +378,270 @@ function mtime(path) {
|
|
|
362
378
|
//#endregion
|
|
363
379
|
//#region src/run.ts
|
|
364
380
|
const NOISE_RE = /^Shell cwd was reset[^\n]*$/gm;
|
|
381
|
+
const MESSAGE_STREAM_ARGS = ["--output-format", "stream-json"];
|
|
382
|
+
const RAW_FALLBACK_MAX_CHARS = 8192;
|
|
383
|
+
const READABLE_LOG_FLUSH_CHARS = 4096;
|
|
384
|
+
const AGY_PRINT_TIMEOUT_RE = /^\[agy\] print timeout after \S+ with turn in progress; returning partial output\s*$/i;
|
|
385
|
+
const TOOL_SUMMARY_MAX = 200;
|
|
365
386
|
function clean(s) {
|
|
366
387
|
return stripAnsi(s).replace(NOISE_RE, "").trim();
|
|
367
388
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
389
|
+
function classifyLine(line) {
|
|
390
|
+
const trimmed = line.trim();
|
|
391
|
+
if (trimmed.length === 0) return { kind: "blank" };
|
|
392
|
+
if (!trimmed.startsWith("{")) return {
|
|
393
|
+
kind: "raw",
|
|
394
|
+
line
|
|
395
|
+
};
|
|
396
|
+
let parsed;
|
|
397
|
+
try {
|
|
398
|
+
parsed = JSON.parse(trimmed);
|
|
399
|
+
} catch {
|
|
400
|
+
return {
|
|
401
|
+
kind: "raw",
|
|
402
|
+
line
|
|
403
|
+
};
|
|
378
404
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
405
|
+
if (typeof parsed !== "object" || parsed === null || !("event" in parsed) || typeof parsed.event !== "string") return {
|
|
406
|
+
kind: "raw",
|
|
407
|
+
line
|
|
408
|
+
};
|
|
409
|
+
const event = parsed.event;
|
|
410
|
+
if (event === "init") return { kind: "init" };
|
|
411
|
+
if (event === "step_update") {
|
|
412
|
+
const stepUpdate = parsed.step_update;
|
|
413
|
+
if (typeof stepUpdate === "object" && stepUpdate !== null) {
|
|
414
|
+
const su = stepUpdate;
|
|
415
|
+
return {
|
|
416
|
+
kind: "step",
|
|
417
|
+
state: typeof su.state === "string" ? su.state : void 0,
|
|
418
|
+
stepType: typeof su.step_type === "string" ? su.step_type : void 0,
|
|
419
|
+
textDelta: typeof su.text_delta === "string" ? su.text_delta : void 0,
|
|
420
|
+
toolName: typeof su.tool_name === "string" ? su.tool_name : void 0,
|
|
421
|
+
toolInfo: su.tool_info
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
return {
|
|
425
|
+
kind: "step",
|
|
426
|
+
state: void 0,
|
|
427
|
+
stepType: void 0,
|
|
428
|
+
textDelta: void 0,
|
|
429
|
+
toolName: void 0,
|
|
430
|
+
toolInfo: void 0
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
if (event === "result") {
|
|
434
|
+
const res = parsed.result;
|
|
435
|
+
if (typeof res === "object" && res !== null) {
|
|
436
|
+
const r = res;
|
|
437
|
+
return {
|
|
438
|
+
kind: "result",
|
|
439
|
+
status: typeof r.status === "string" ? r.status : void 0,
|
|
440
|
+
response: typeof r.response === "string" ? r.response : void 0,
|
|
441
|
+
error: typeof r.error === "string" ? r.error : void 0
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
return {
|
|
445
|
+
kind: "result",
|
|
446
|
+
status: void 0,
|
|
447
|
+
response: void 0,
|
|
448
|
+
error: void 0
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
return { kind: "frame" };
|
|
452
|
+
}
|
|
453
|
+
function formatToolSummary(toolInfo) {
|
|
454
|
+
if (typeof toolInfo !== "object" || toolInfo === null) return null;
|
|
455
|
+
const obj = toolInfo;
|
|
456
|
+
const raw = typeof obj.summary === "string" ? obj.summary : typeof obj.message === "string" ? obj.message : null;
|
|
457
|
+
if (!raw) return null;
|
|
458
|
+
const firstLine = raw.split("\n")[0]?.trim();
|
|
459
|
+
if (!firstLine) return null;
|
|
460
|
+
return firstLine.slice(0, TOOL_SUMMARY_MAX);
|
|
461
|
+
}
|
|
462
|
+
function logForwarder(onStdout, onActivity) {
|
|
463
|
+
let pending = "";
|
|
464
|
+
let readableBuffer = "";
|
|
465
|
+
let loggedAgentText = "";
|
|
466
|
+
let sawProtocol = false;
|
|
467
|
+
let resultStatus = null;
|
|
468
|
+
let resultResponse = null;
|
|
469
|
+
let resultError = null;
|
|
470
|
+
let rawFallback = "";
|
|
471
|
+
let rawTruncated = false;
|
|
472
|
+
const flushReadable = () => {
|
|
473
|
+
if (readableBuffer.length === 0) return;
|
|
474
|
+
const toSend = readableBuffer.endsWith("\n") ? readableBuffer : `${readableBuffer}\n`;
|
|
475
|
+
readableBuffer = "";
|
|
476
|
+
onStdout?.(toSend);
|
|
477
|
+
};
|
|
478
|
+
const emit = (rawLine) => {
|
|
479
|
+
const classified = classifyLine(stripAnsi(rawLine));
|
|
480
|
+
if (classified.kind === "blank") return;
|
|
481
|
+
if (classified.kind === "init" || classified.kind === "frame") {
|
|
482
|
+
sawProtocol = true;
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (classified.kind === "step") {
|
|
486
|
+
sawProtocol = true;
|
|
487
|
+
if (classified.stepType === "agent_response" && classified.textDelta) {
|
|
488
|
+
loggedAgentText += classified.textDelta;
|
|
489
|
+
readableBuffer += classified.textDelta;
|
|
490
|
+
if (readableBuffer.includes("\n") || readableBuffer.length >= READABLE_LOG_FLUSH_CHARS) flushReadable();
|
|
491
|
+
}
|
|
492
|
+
if (classified.state === "DONE" && classified.stepType === "agent_response") {
|
|
493
|
+
if (readableBuffer.length > 0 && !readableBuffer.endsWith("\n")) readableBuffer += "\n";
|
|
494
|
+
flushReadable();
|
|
495
|
+
}
|
|
496
|
+
if (classified.toolName) {
|
|
497
|
+
flushReadable();
|
|
498
|
+
if (classified.state === "ACTIVE") onStdout?.(`tool ${classified.toolName}\n`);
|
|
499
|
+
else if (classified.state === "DONE") {
|
|
500
|
+
const summary = formatToolSummary(classified.toolInfo);
|
|
501
|
+
if (summary) onStdout?.(`tool ${classified.toolName} done: ${summary}\n`);
|
|
502
|
+
else onStdout?.(`tool ${classified.toolName} done\n`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (classified.kind === "result") {
|
|
508
|
+
sawProtocol = true;
|
|
509
|
+
resultStatus = classified.status ?? null;
|
|
510
|
+
resultResponse = classified.response ?? null;
|
|
511
|
+
resultError = classified.error ?? null;
|
|
512
|
+
flushReadable();
|
|
513
|
+
if (classified.response && classified.response.length > 0) {
|
|
514
|
+
const cleanResp = clean(classified.response);
|
|
515
|
+
const cleanLogged = clean(loggedAgentText);
|
|
516
|
+
if (cleanResp.length > 0 && !cleanLogged.endsWith(cleanResp)) {
|
|
517
|
+
readableBuffer += classified.response;
|
|
518
|
+
flushReadable();
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (classified.kind === "raw") {
|
|
524
|
+
flushReadable();
|
|
525
|
+
onStdout?.(`${rawLine}\n`);
|
|
526
|
+
if (!sawProtocol) {
|
|
527
|
+
if (!rawTruncated) {
|
|
528
|
+
const candidate = `${rawLine}\n`;
|
|
529
|
+
if (rawFallback.length + candidate.length > RAW_FALLBACK_MAX_CHARS) rawTruncated = true;
|
|
530
|
+
else rawFallback += candidate;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
return {
|
|
536
|
+
onChunk: (chunk) => {
|
|
537
|
+
onActivity?.();
|
|
538
|
+
pending += chunk;
|
|
539
|
+
for (let nl = pending.indexOf("\n"); nl !== -1; nl = pending.indexOf("\n")) {
|
|
540
|
+
emit(pending.slice(0, nl));
|
|
541
|
+
pending = pending.slice(nl + 1);
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
flush: () => {
|
|
545
|
+
if (pending.length > 0) {
|
|
546
|
+
const line = pending;
|
|
547
|
+
pending = "";
|
|
548
|
+
emit(line);
|
|
549
|
+
}
|
|
550
|
+
flushReadable();
|
|
551
|
+
},
|
|
552
|
+
snapshot: () => ({
|
|
553
|
+
sawProtocol,
|
|
554
|
+
text: resultResponse && resultResponse.length > 0 ? resultResponse : null,
|
|
555
|
+
resultStatus,
|
|
556
|
+
resultError,
|
|
557
|
+
rawFallback,
|
|
558
|
+
rawTruncated
|
|
559
|
+
})
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
async function run(task, exec = runCaptured) {
|
|
563
|
+
const addDirs = task.tools ? [task.cwd] : void 0;
|
|
564
|
+
let result;
|
|
565
|
+
let useStreamJson = false;
|
|
566
|
+
let forwarder;
|
|
385
567
|
try {
|
|
386
|
-
|
|
387
|
-
|
|
568
|
+
const version = await probeVersion("agy", exec);
|
|
569
|
+
useStreamJson = agySupportsStreamJson(version);
|
|
570
|
+
if (!useStreamJson) task.onStderr?.(`aibridge: agy version ${version ?? "unavailable"} does not support stream-json (requires >= 1.2.3); using text compatibility mode.\n`);
|
|
571
|
+
const args = [...buildAgyPrintArgs(task.prompt, {
|
|
572
|
+
model: task.backendModel,
|
|
573
|
+
printTimeoutSec: task.timeoutSec,
|
|
574
|
+
skipPermissions: task.tools,
|
|
575
|
+
addDirs
|
|
576
|
+
}), ...useStreamJson ? MESSAGE_STREAM_ARGS : []];
|
|
577
|
+
if (useStreamJson) {
|
|
578
|
+
forwarder = logForwarder(task.onStdout, task.onActivity);
|
|
388
579
|
result = await exec("agy", args, {
|
|
389
580
|
cwd: task.cwd,
|
|
390
581
|
timeoutMs: (task.timeoutSec + 20) * 1e3,
|
|
391
|
-
|
|
582
|
+
captureStdout: false,
|
|
583
|
+
onStdout: forwarder.onChunk,
|
|
392
584
|
onStderr: task.onStderr,
|
|
393
585
|
onSpawn: task.onSpawn
|
|
394
586
|
});
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
if (result.timedOut) return {
|
|
410
|
-
ok: false,
|
|
411
|
-
kind: "timeout",
|
|
412
|
-
message: `aibridge: agy timed out after ~${task.timeoutSec + 20}s; raise --timeout.`,
|
|
413
|
-
exitCode: result.code
|
|
414
|
-
};
|
|
415
|
-
let response = "";
|
|
416
|
-
if (answerPath && existsSync(answerPath)) {
|
|
417
|
-
response = clean(readFileSync(answerPath, "utf8"));
|
|
418
|
-
if (response.length > 0) task.onStdout?.(`\n--- final answer ---\n${response}\n`);
|
|
419
|
-
}
|
|
420
|
-
if (response.length === 0) response = clean(result.stdout);
|
|
421
|
-
if (result.code !== 0 || response.length === 0) return {
|
|
587
|
+
} else result = await exec("agy", args, {
|
|
588
|
+
cwd: task.cwd,
|
|
589
|
+
timeoutMs: (task.timeoutSec + 20) * 1e3,
|
|
590
|
+
onStdout: (chunk) => {
|
|
591
|
+
task.onActivity?.();
|
|
592
|
+
task.onStdout?.(chunk);
|
|
593
|
+
},
|
|
594
|
+
onStderr: task.onStderr,
|
|
595
|
+
onSpawn: task.onSpawn
|
|
596
|
+
});
|
|
597
|
+
} catch (err) {
|
|
598
|
+
if (isNotFound(err)) return {
|
|
422
599
|
ok: false,
|
|
423
|
-
kind: "
|
|
424
|
-
message: `aibridge: agy
|
|
425
|
-
exitCode:
|
|
600
|
+
kind: "not-found",
|
|
601
|
+
message: `aibridge: "agy" not found on PATH. ${INSTALL_HINT}`,
|
|
602
|
+
exitCode: null
|
|
426
603
|
};
|
|
427
604
|
return {
|
|
428
|
-
ok:
|
|
429
|
-
|
|
430
|
-
|
|
605
|
+
ok: false,
|
|
606
|
+
kind: "spawn",
|
|
607
|
+
message: `aibridge: failed to run agy: ${err.message}`,
|
|
608
|
+
exitCode: null
|
|
431
609
|
};
|
|
432
|
-
} finally {
|
|
433
|
-
if (tempDir) rmSync(tempDir, {
|
|
434
|
-
recursive: true,
|
|
435
|
-
force: true
|
|
436
|
-
});
|
|
437
610
|
}
|
|
611
|
+
forwarder?.flush();
|
|
612
|
+
if (result.timedOut) return {
|
|
613
|
+
ok: false,
|
|
614
|
+
kind: "timeout",
|
|
615
|
+
message: `aibridge: agy timed out after ~${task.timeoutSec + 20}s; raise --timeout.`,
|
|
616
|
+
exitCode: result.code
|
|
617
|
+
};
|
|
618
|
+
const stderrLines = stripAnsi(result.stderr).split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
619
|
+
const lastStderrLine = stderrLines[stderrLines.length - 1] ?? "";
|
|
620
|
+
if (result.code === 0 && AGY_PRINT_TIMEOUT_RE.test(lastStderrLine)) return {
|
|
621
|
+
ok: false,
|
|
622
|
+
kind: "timeout",
|
|
623
|
+
message: `aibridge: agy timed out after ~${task.timeoutSec}s; raise --timeout.`,
|
|
624
|
+
exitCode: result.code
|
|
625
|
+
};
|
|
626
|
+
const snap = useStreamJson && forwarder ? forwarder.snapshot() : void 0;
|
|
627
|
+
const resolvedAnswer = snap ? clean(snap.text ?? (snap.sawProtocol || snap.rawTruncated ? "" : snap.rawFallback)) : clean(result.stdout);
|
|
628
|
+
if (snap && !snap.sawProtocol && snap.rawTruncated && resolvedAnswer.length === 0) return {
|
|
629
|
+
ok: false,
|
|
630
|
+
kind: "no-answer",
|
|
631
|
+
message: `aibridge: agy returned more than ${RAW_FALLBACK_MAX_CHARS} characters without a recognized stream protocol; see the run log.`,
|
|
632
|
+
exitCode: result.code
|
|
633
|
+
};
|
|
634
|
+
if (snap?.resultStatus === "ERROR" || result.code !== 0 || resolvedAnswer.length === 0) return {
|
|
635
|
+
ok: false,
|
|
636
|
+
kind: "no-answer",
|
|
637
|
+
message: `aibridge: agy returned no usable answer (${clean(snap?.resultError || result.stderr) || `exit code ${result.code}`}).`,
|
|
638
|
+
exitCode: result.code
|
|
639
|
+
};
|
|
640
|
+
return {
|
|
641
|
+
ok: true,
|
|
642
|
+
response: resolvedAnswer,
|
|
643
|
+
exitCode: result.code ?? 0
|
|
644
|
+
};
|
|
438
645
|
}
|
|
439
646
|
//#endregion
|
|
440
|
-
export { AGY_CANONICAL_TO_NATIVE, agyTokenPath, buildAgyPrintArgs, fetchAgyQuota, findModelQuota, generateImage, parseModels, parseQuotaGroups, probe, run };
|
|
647
|
+
export { AGY_CANONICAL_TO_NATIVE, MIN_AGY_STREAM_JSON, agySupportsStreamJson, agyTokenPath, buildAgyPrintArgs, fetchAgyQuota, findModelQuota, generateImage, parseModels, parseQuotaGroups, probe, run };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aibridge/driver-agy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Antigravity (agy) CLI driver for aibridge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@aibridge/proc": "0.9.
|
|
35
|
+
"@aibridge/proc": "0.9.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"tsdown": "0.22.14"
|
package/src/agy.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { buildAgyPrintArgs } from './agy.ts';
|
|
2
|
+
import { agySupportsStreamJson, buildAgyPrintArgs } from './agy.ts';
|
|
3
3
|
|
|
4
4
|
describe('buildAgyPrintArgs', () => {
|
|
5
5
|
it('assembles default agy args', () => {
|
|
@@ -39,3 +39,25 @@ describe('buildAgyPrintArgs', () => {
|
|
|
39
39
|
]);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
describe('agySupportsStreamJson', () => {
|
|
44
|
+
it('accepts versions >= 1.2.3 with supported prefix shapes', () => {
|
|
45
|
+
expect(agySupportsStreamJson('agy 1.2.3')).toBe(true);
|
|
46
|
+
expect(agySupportsStreamJson('agy version 1.2.3')).toBe(true);
|
|
47
|
+
expect(agySupportsStreamJson('1.2.3')).toBe(true);
|
|
48
|
+
expect(agySupportsStreamJson('1.3.0')).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('rejects versions < 1.2.3', () => {
|
|
52
|
+
expect(agySupportsStreamJson('1.2.2')).toBe(false);
|
|
53
|
+
expect(agySupportsStreamJson('1.1.8')).toBe(false);
|
|
54
|
+
expect(agySupportsStreamJson('agy version 1.0.0')).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('rejects null, invalid strings, prereleases, and embedded build strings', () => {
|
|
58
|
+
expect(agySupportsStreamJson(null)).toBe(false);
|
|
59
|
+
expect(agySupportsStreamJson('not-a-version')).toBe(false);
|
|
60
|
+
expect(agySupportsStreamJson('1.2.3-rc.1')).toBe(false);
|
|
61
|
+
expect(agySupportsStreamJson('agy build 2026.09.15 version 1.2.2')).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
package/src/agy.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { semverGte } from '@aibridge/proc';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Helper for building Antigravity CLI (`agy`) print arguments.
|
|
3
5
|
*
|
|
@@ -32,3 +34,17 @@ export function buildAgyPrintArgs(prompt: string, opts: AgyPrintArgs): string[]
|
|
|
32
34
|
|
|
33
35
|
return args;
|
|
34
36
|
}
|
|
37
|
+
|
|
38
|
+
export const MIN_AGY_STREAM_JSON: readonly [number, number, number] = [1, 2, 3];
|
|
39
|
+
|
|
40
|
+
const STRICT_AGY_VERSION_RE = /^(?:agy(?: version)?\s+)?(\d+)\.(\d+)\.(\d+)(?:\s.*)?$/i;
|
|
41
|
+
|
|
42
|
+
export function agySupportsStreamJson(versionLine: string | null): boolean {
|
|
43
|
+
if (!versionLine) return false;
|
|
44
|
+
const m = versionLine.trim().match(STRICT_AGY_VERSION_RE);
|
|
45
|
+
if (!m) return false;
|
|
46
|
+
const major = Number(m[1]);
|
|
47
|
+
const minor = Number(m[2]);
|
|
48
|
+
const patch = Number(m[3]);
|
|
49
|
+
return semverGte([major, minor, patch], MIN_AGY_STREAM_JSON);
|
|
50
|
+
}
|
|
@@ -26,7 +26,7 @@ describe('generateImage', () => {
|
|
|
26
26
|
return {
|
|
27
27
|
code: 0,
|
|
28
28
|
signal: null,
|
|
29
|
-
stdout: 'agy
|
|
29
|
+
stdout: 'agy 1.2.3\n',
|
|
30
30
|
stderr: '',
|
|
31
31
|
timedOut: false,
|
|
32
32
|
};
|
|
@@ -47,6 +47,8 @@ describe('generateImage', () => {
|
|
|
47
47
|
expect(capturedArgs).toContain('--model');
|
|
48
48
|
expect(capturedArgs).toContain('gemini-3.7-flash-high');
|
|
49
49
|
expect(capturedArgs).toContain('--dangerously-skip-permissions');
|
|
50
|
+
expect(capturedArgs).not.toContain('--output-format');
|
|
51
|
+
expect(capturedArgs).not.toContain('stream-json');
|
|
50
52
|
|
|
51
53
|
const promptIdx = capturedArgs.indexOf('-p');
|
|
52
54
|
expect(promptIdx).toBeGreaterThan(-1);
|
package/src/generateImage.ts
CHANGED
|
@@ -40,7 +40,7 @@ export async function generateImage(
|
|
|
40
40
|
instruction =
|
|
41
41
|
`Call the generate_image tool once with ImageName="aibridge-render", Prompt=${JSON.stringify(req.prompt)}, and ImagePaths=[${refs}]. ` +
|
|
42
42
|
`Change only what the instruction asks, using the references for subject/identity.` +
|
|
43
|
-
`${req.aspectRatio ? ` Pass AspectRatio='${req.aspectRatio}'
|
|
43
|
+
`${req.aspectRatio ? ` Pass AspectRatio='${req.aspectRatio}'.` : ''}` +
|
|
44
44
|
` After the tool returns, print ONLY the absolute filesystem path of the saved image on a single line. No other text.`;
|
|
45
45
|
} else {
|
|
46
46
|
instruction =
|
package/src/index.ts
CHANGED