clisponsor 1.0.7 → 1.0.9
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 +15 -5
- 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"];
|
|
19
19
|
|
|
20
20
|
function argValue(name) {
|
|
21
21
|
const prefix = `${name}=`;
|
|
@@ -422,11 +422,21 @@ 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
|
+
}
|
|
428
438
|
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)} } };
|
|
439
|
+
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
440
|
const res = await fetch(serveBaseUrl + "/v1/ads/serve", {
|
|
431
441
|
method: "POST",
|
|
432
442
|
headers: {
|
|
@@ -439,8 +449,8 @@ try {
|
|
|
439
449
|
if (res.ok) {
|
|
440
450
|
const ad = await res.json();
|
|
441
451
|
if (outputMode === "antigravity") {
|
|
442
|
-
const payload = {
|
|
443
|
-
if (ad.display_line) payload.
|
|
452
|
+
const payload = {};
|
|
453
|
+
if (ad.display_line) payload.injectSteps = [{ ephemeralMessage: sponsoredLine(ad.display_line) }];
|
|
444
454
|
console.log(JSON.stringify(payload));
|
|
445
455
|
} else if (ad.display_line) {
|
|
446
456
|
console.log(JSON.stringify({ systemMessage: sponsoredLine(ad.display_line) }));
|