clisponsor 1.0.7 → 1.0.8
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 +17 -3
- package/package.json +1 -1
package/bin/clisponsor.mjs
CHANGED
|
@@ -15,7 +15,7 @@ const DEFAULT_SERVE_BASE_URL =
|
|
|
15
15
|
const DEFAULT_BACKEND_BASE_URL = process.env.CLISPONSOR_BACKEND_BASE_URL || "https://backend.clisponsor.com";
|
|
16
16
|
const HOOK_VERSION = "1.0.0";
|
|
17
17
|
const NETWORK_TIMEOUT_MS = 3000;
|
|
18
|
-
const ANTIGRAVITY_EVENTS = ["PreInvocation", "
|
|
18
|
+
const ANTIGRAVITY_EVENTS = ["PreInvocation", "Stop"];
|
|
19
19
|
|
|
20
20
|
function argValue(name) {
|
|
21
21
|
const prefix = `${name}=`;
|
|
@@ -422,11 +422,25 @@ function readStdin() {
|
|
|
422
422
|
process.stdin.on("end", () => resolve(data));
|
|
423
423
|
});
|
|
424
424
|
}
|
|
425
|
-
await readStdin();
|
|
425
|
+
const hookInputRaw = await readStdin();
|
|
426
|
+
let hookInput = {};
|
|
427
|
+
try {
|
|
428
|
+
hookInput = hookInputRaw.trim() ? JSON.parse(hookInputRaw) : {};
|
|
429
|
+
} catch {}
|
|
426
430
|
try {
|
|
427
431
|
if (!serveBaseUrl || !cfg.userId || !cfg.deviceCode || !cfg.deviceSecret) process.exit(0);
|
|
432
|
+
if (outputMode === "antigravity") {
|
|
433
|
+
if (event === "PreInvocation" && Number(hookInput.invocationNum || 1) > 1) {
|
|
434
|
+
console.log(JSON.stringify({}));
|
|
435
|
+
process.exit(0);
|
|
436
|
+
}
|
|
437
|
+
if (event === "Stop" && hookInput.fullyIdle === false) {
|
|
438
|
+
console.log(JSON.stringify({ decision: "allow" }));
|
|
439
|
+
process.exit(0);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
428
442
|
const placement = placements[event] || event;
|
|
429
|
-
const body = { user_id: cfg.userId, device_code: cfg.deviceCode, client: ${JSON.stringify(client)}, hook_event: event, placement, idempotency_key: crypto.randomUUID(), metadata: { hookVersion: ${JSON.stringify(HOOK_VERSION)} } };
|
|
443
|
+
const body = { user_id: cfg.userId, device_code: cfg.deviceCode, client: ${JSON.stringify(client)}, hook_event: event, placement, idempotency_key: crypto.randomUUID(), metadata: { hookVersion: ${JSON.stringify(HOOK_VERSION)}, antigravity: outputMode === "antigravity" ? { invocationNum: hookInput.invocationNum, initialNumSteps: hookInput.initialNumSteps, executionNum: hookInput.executionNum, terminationReason: hookInput.terminationReason, fullyIdle: hookInput.fullyIdle } : undefined } };
|
|
430
444
|
const res = await fetch(serveBaseUrl + "/v1/ads/serve", {
|
|
431
445
|
method: "POST",
|
|
432
446
|
headers: {
|