clisponsor 1.0.9 → 1.0.11
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/bin/clisponsor.mjs +24 -5
- package/package.json +1 -1
package/bin/clisponsor.mjs
CHANGED
|
@@ -407,11 +407,12 @@ function agentHookSource(client, options = {}) {
|
|
|
407
407
|
return `#!/usr/bin/env node
|
|
408
408
|
import fs from "node:fs";
|
|
409
409
|
import crypto from "node:crypto";
|
|
410
|
-
const cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
|
|
411
410
|
const event = process.argv[2] || "BeforeAgent";
|
|
412
411
|
const outputMode = ${JSON.stringify(outputMode)};
|
|
413
412
|
const placements = { SessionStart: "StartSession", PreInvocation: "StartTurn", BeforeAgent: "StartTurn", UserPromptSubmit: "StartTurn", PreToolUse: "StartTurn", AfterAgent: "EndTurn", PostInvocation: "EndTurn", Stop: "EndTurn", StartTurn: "StartTurn" };
|
|
414
|
-
|
|
413
|
+
function writeNoop() {
|
|
414
|
+
if (outputMode === "antigravity") console.log(JSON.stringify({}));
|
|
415
|
+
}
|
|
415
416
|
function sponsoredLine(line) {
|
|
416
417
|
return "[Sponsored] " + line;
|
|
417
418
|
}
|
|
@@ -427,11 +428,26 @@ let hookInput = {};
|
|
|
427
428
|
try {
|
|
428
429
|
hookInput = hookInputRaw.trim() ? JSON.parse(hookInputRaw) : {};
|
|
429
430
|
} catch {}
|
|
431
|
+
let cfg = {};
|
|
432
|
+
try {
|
|
433
|
+
cfg = JSON.parse(fs.readFileSync(${JSON.stringify(CONFIG_PATH)}, "utf8"));
|
|
434
|
+
} catch {
|
|
435
|
+
writeNoop();
|
|
436
|
+
process.exit(0);
|
|
437
|
+
}
|
|
438
|
+
const serveBaseUrl = cfg.serveBaseUrl || cfg.apiBaseUrl;
|
|
430
439
|
try {
|
|
431
|
-
if (
|
|
440
|
+
if (outputMode === "antigravity" && event !== "PreInvocation") {
|
|
441
|
+
writeNoop();
|
|
442
|
+
process.exit(0);
|
|
443
|
+
}
|
|
444
|
+
if (!serveBaseUrl || !cfg.userId || !cfg.deviceCode || !cfg.deviceSecret) {
|
|
445
|
+
writeNoop();
|
|
446
|
+
process.exit(0);
|
|
447
|
+
}
|
|
432
448
|
if (outputMode === "antigravity") {
|
|
433
449
|
if (event === "PreInvocation" && Number(hookInput.invocationNum || 1) > 1) {
|
|
434
|
-
|
|
450
|
+
writeNoop();
|
|
435
451
|
process.exit(0);
|
|
436
452
|
}
|
|
437
453
|
}
|
|
@@ -450,13 +466,16 @@ try {
|
|
|
450
466
|
const ad = await res.json();
|
|
451
467
|
if (outputMode === "antigravity") {
|
|
452
468
|
const payload = {};
|
|
453
|
-
if (ad.display_line) payload.injectSteps = [{
|
|
469
|
+
if (ad.display_line) payload.injectSteps = [{ userMessage: sponsoredLine(ad.display_line) }];
|
|
454
470
|
console.log(JSON.stringify(payload));
|
|
455
471
|
} else if (ad.display_line) {
|
|
456
472
|
console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
|
|
457
473
|
}
|
|
474
|
+
} else {
|
|
475
|
+
writeNoop();
|
|
458
476
|
}
|
|
459
477
|
} catch {
|
|
478
|
+
writeNoop();
|
|
460
479
|
process.exit(0);
|
|
461
480
|
}
|
|
462
481
|
`;
|