@eddyskywalker/dsh-chatgpt-subscription 0.75.0 → 0.75.2
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 +43 -0
- package/README.md +14 -9
- package/lib/client.js +36 -23
- package/lib/client.js.map +1 -1
- package/lib/index.js +641 -124
- package/lib/tool-result-pruner.js +1 -1
- package/lib/types/client/antigravity-acp/AntigravityAcpSection.d.ts.map +1 -1
- package/lib/types/client/antigravity-acp/locales.d.ts +6 -12
- package/lib/types/client/antigravity-acp/locales.d.ts.map +1 -1
- package/lib/types/client/kimi-code/KimiCodeSection.d.ts.map +1 -1
- package/lib/types/client/locales-ru/antigravity-acp.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/entry-progress-updates.d.ts +1 -1
- package/lib/types/entry-tool-result-pruner.d.ts +1 -1
- package/lib/types/host/antigravity-acp/adapter.d.ts +17 -0
- package/lib/types/host/antigravity-acp/adapter.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/auth-cache.d.ts +11 -2
- package/lib/types/host/antigravity-acp/auth-cache.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/binary.d.ts +68 -0
- package/lib/types/host/antigravity-acp/binary.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/catalog.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/errors.d.ts +10 -0
- package/lib/types/host/antigravity-acp/errors.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/history.d.ts +26 -0
- package/lib/types/host/antigravity-acp/history.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/login.d.ts +22 -6
- package/lib/types/host/antigravity-acp/login.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/mcp-bridge.d.ts +9 -2
- package/lib/types/host/antigravity-acp/mcp-bridge.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/routes.d.ts +23 -4
- package/lib/types/host/antigravity-acp/routes.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/subagent.d.ts +32 -0
- package/lib/types/host/antigravity-acp/subagent.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/types.d.ts +15 -0
- package/lib/types/host/antigravity-acp/types.d.ts.map +1 -1
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/mapper.d.ts +13 -0
- package/lib/types/host/kimi-code/mapper.d.ts.map +1 -1
- package/lib/types/host/kimi-code/routes.d.ts.map +1 -1
- package/lib/types/host/kimi-code/session-cache-state.d.ts +10 -0
- package/lib/types/host/kimi-code/session-cache-state.d.ts.map +1 -1
- package/lib/types/index.d.ts +4 -4
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/kimi-code-contracts.d.ts +10 -2
- package/lib/types/shared/kimi-code-contracts.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -817,7 +817,7 @@ const ROUTE_PREFIX$5 = "/api/dsh-chatgpt-subscription";
|
|
|
817
817
|
* `test/responses-client.test.ts` asserts the two agree, so a release that
|
|
818
818
|
* forgets this constant fails the suite instead of shipping quietly.
|
|
819
819
|
*/
|
|
820
|
-
const PLUGIN_VERSION = "0.75.
|
|
820
|
+
const PLUGIN_VERSION = "0.75.2";
|
|
821
821
|
const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
|
|
822
822
|
const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
|
|
823
823
|
const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
|
|
@@ -24903,7 +24903,6 @@ var McpBridge = class {
|
|
|
24903
24903
|
descriptor;
|
|
24904
24904
|
token = randomBytes(32).toString("base64url");
|
|
24905
24905
|
exposed;
|
|
24906
|
-
withdrawn = /* @__PURE__ */ new Map();
|
|
24907
24906
|
parked = /* @__PURE__ */ new Map();
|
|
24908
24907
|
waiters = /* @__PURE__ */ new Set();
|
|
24909
24908
|
closed = false;
|
|
@@ -24946,7 +24945,15 @@ var McpBridge = class {
|
|
|
24946
24945
|
this.parked.clear();
|
|
24947
24946
|
return calls;
|
|
24948
24947
|
}
|
|
24949
|
-
/**
|
|
24948
|
+
/**
|
|
24949
|
+
* How many calls the harness has not picked up yet.
|
|
24950
|
+
*
|
|
24951
|
+
* Deliberately the *parked* set - calls the agent has made that the harness has
|
|
24952
|
+
* not taken yet - and not the responses still held open. The cap exists to stop
|
|
24953
|
+
* a runaway agent from piling up calls nobody has picked up; a call the harness
|
|
24954
|
+
* already took is one it answers by the next generation, and counting those as
|
|
24955
|
+
* well would fire the cap during a legitimate multi-step round.
|
|
24956
|
+
*/
|
|
24950
24957
|
get pendingCount() {
|
|
24951
24958
|
return this.parked.size;
|
|
24952
24959
|
}
|
|
@@ -25095,7 +25102,7 @@ var McpBridge = class {
|
|
|
25095
25102
|
async handleToolCall(id, params, response) {
|
|
25096
25103
|
const record = typeof params === "object" && params !== null && !Array.isArray(params) ? params : {};
|
|
25097
25104
|
const exposedName = typeof record.name === "string" ? record.name : "";
|
|
25098
|
-
const tool = this.exposed.find((entry) => entry.exposedName === exposedName)
|
|
25105
|
+
const tool = this.exposed.find((entry) => entry.exposedName === exposedName);
|
|
25099
25106
|
if (tool === void 0) {
|
|
25100
25107
|
respond(response, 200, jsonRpcResult(id, {
|
|
25101
25108
|
content: [{
|
|
@@ -25253,6 +25260,16 @@ const ACP_ERROR_CODES = {
|
|
|
25253
25260
|
ACP_DISCONNECTED: "The Antigravity agent process ended mid-turn. Retry to reconnect.",
|
|
25254
25261
|
/** A JSON-RPC error the line has no specific handling for. */
|
|
25255
25262
|
ACP_RPC_ERROR: "The Antigravity ACP server returned a JSON-RPC error.",
|
|
25263
|
+
/**
|
|
25264
|
+
* The service declined the account or the request itself - a quota wall, a
|
|
25265
|
+
* policy block, a verification challenge, a rate limit.
|
|
25266
|
+
*
|
|
25267
|
+
* Kept apart from {@link ACP_RPC_ERROR} because the two want opposite
|
|
25268
|
+
* treatment: a transport fault is worth another attempt, while putting the same
|
|
25269
|
+
* account in front of the same wall two more times is how a strict policy turns
|
|
25270
|
+
* one failure into a pattern.
|
|
25271
|
+
*/
|
|
25272
|
+
ACP_UPSTREAM_BLOCKED: "The Antigravity service declined this account or request (quota, policy or verification). Retrying here will not change the answer - resolve it in the official client first.",
|
|
25256
25273
|
/** The server rejected the request parameters or the model id. */
|
|
25257
25274
|
ACP_INVALID_PARAMS: "The Antigravity ACP server rejected the request parameters or the model id.",
|
|
25258
25275
|
/** The server does not implement the method this client called. */
|
|
@@ -25326,13 +25343,29 @@ const ACP_MAX_INLINE_IMAGE_BYTES = 12 * 1024 * 1024;
|
|
|
25326
25343
|
*/
|
|
25327
25344
|
const REPLAY_ANCHOR_INSTRUCTION = [
|
|
25328
25345
|
"[history boundary]",
|
|
25329
|
-
"Everything above this line is
|
|
25330
|
-
"
|
|
25346
|
+
"Everything above this line is archived conversation or a copy of the active request; none of it is a new task.",
|
|
25347
|
+
"Plugin recall, time snapshots and other synthetic context are not the current human request.",
|
|
25348
|
+
"When a [current human request] section follows, its quoted text is the request for this turn.",
|
|
25331
25349
|
"Do not re-run, re-answer or re-dispatch work an earlier message already asked for; completed requests are completed.",
|
|
25332
25350
|
"A short reference such as \"do that\" or \"go with A\" points at the assistant message immediately before it.",
|
|
25333
25351
|
"Model names, providers and routing mentioned in older turns describe the turn they ran on, not the one you are answering now."
|
|
25334
25352
|
].join(" ");
|
|
25335
25353
|
/**
|
|
25354
|
+
* Heading of the oldest request copy in a replay, placed right after the
|
|
25355
|
+
* instructions so the task is readable before any history is.
|
|
25356
|
+
*/
|
|
25357
|
+
const ACTIVE_REQUEST_HEADING = "[active request for this turn]";
|
|
25358
|
+
/** Heading of the newest request copy - the one this turn answers. */
|
|
25359
|
+
const CURRENT_REQUEST_HEADING = "[current human request]";
|
|
25360
|
+
/** Heading of the bounded plain-text archive a compacted replay carries. */
|
|
25361
|
+
const REPLAY_ARCHIVE_HEADING = "[archived conversation - context only]";
|
|
25362
|
+
/** Characters of older conversation a compacted replay keeps. */
|
|
25363
|
+
const REPLAY_ARCHIVE_CHARS = 6e4;
|
|
25364
|
+
/** Per-message ceiling inside that archive. */
|
|
25365
|
+
const REPLAY_MESSAGE_CHARS = 12e3;
|
|
25366
|
+
/** Ceiling for one copy of the request the replay answers. */
|
|
25367
|
+
const REPLAY_REQUEST_CHARS = 3e4;
|
|
25368
|
+
/**
|
|
25336
25369
|
* Build the prompt for one generation.
|
|
25337
25370
|
*
|
|
25338
25371
|
* @param options - Normalized request options.
|
|
@@ -25343,22 +25376,8 @@ const REPLAY_ANCHOR_INSTRUCTION = [
|
|
|
25343
25376
|
function buildPrompt(options, images, fromMessage) {
|
|
25344
25377
|
const messages = options.messages;
|
|
25345
25378
|
const start = Math.max(0, Math.min(fromMessage, messages.length));
|
|
25346
|
-
const blocks = [];
|
|
25347
|
-
let inlineBytes = 0;
|
|
25348
|
-
for (let index = start; index < messages.length; index += 1) {
|
|
25349
|
-
const message = messages[index];
|
|
25350
|
-
if (message === void 0) continue;
|
|
25351
|
-
appendMessage(blocks, message, images, (bytes) => {
|
|
25352
|
-
inlineBytes += bytes;
|
|
25353
|
-
return inlineBytes <= ACP_MAX_INLINE_IMAGE_BYTES;
|
|
25354
|
-
});
|
|
25355
|
-
}
|
|
25356
|
-
if (start === 0 && messages.some((message) => message.role === "assistant")) blocks.push({
|
|
25357
|
-
type: "text",
|
|
25358
|
-
text: REPLAY_ANCHOR_INSTRUCTION
|
|
25359
|
-
});
|
|
25360
25379
|
return {
|
|
25361
|
-
blocks,
|
|
25380
|
+
blocks: start === 0 && messages.some((message) => message.role === "assistant") ? replayBlocks(messages, images) : renderMessages(messages, messageRange(messages.length, start), images),
|
|
25362
25381
|
coveredMessages: messages.length,
|
|
25363
25382
|
fingerprint: fingerprintMessages(messages, 0, messages.length)
|
|
25364
25383
|
};
|
|
@@ -25429,6 +25448,208 @@ function canContinue(messages, covered, fingerprint) {
|
|
|
25429
25448
|
if (covered <= 0 || covered >= messages.length) return false;
|
|
25430
25449
|
return fingerprintMessages(messages, 0, covered) === fingerprint;
|
|
25431
25450
|
}
|
|
25451
|
+
/** Indices of the messages a replay carries, with superseded instruction copies dropped. */
|
|
25452
|
+
function keptIndices(messages) {
|
|
25453
|
+
const newest = {
|
|
25454
|
+
system: -1,
|
|
25455
|
+
developer: -1
|
|
25456
|
+
};
|
|
25457
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
25458
|
+
const role = messages[index]?.role;
|
|
25459
|
+
if (role === "system" || role === "developer") newest[role] = index;
|
|
25460
|
+
}
|
|
25461
|
+
const kept = [];
|
|
25462
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
25463
|
+
const role = messages[index]?.role;
|
|
25464
|
+
if (role === "system" && index !== newest.system) continue;
|
|
25465
|
+
if (role === "developer" && index !== newest.developer) continue;
|
|
25466
|
+
kept.push(index);
|
|
25467
|
+
}
|
|
25468
|
+
return kept;
|
|
25469
|
+
}
|
|
25470
|
+
/** Ascending indices of one message range. */
|
|
25471
|
+
function messageRange(length, from) {
|
|
25472
|
+
const indices = [];
|
|
25473
|
+
for (let index = from; index < length; index += 1) indices.push(index);
|
|
25474
|
+
return indices;
|
|
25475
|
+
}
|
|
25476
|
+
/** Render the given messages as prompt blocks, sharing one inline-image budget. */
|
|
25477
|
+
function renderMessages(messages, indices, images) {
|
|
25478
|
+
const blocks = [];
|
|
25479
|
+
let inlineBytes = 0;
|
|
25480
|
+
const admitImage = (bytes) => {
|
|
25481
|
+
inlineBytes += bytes;
|
|
25482
|
+
return inlineBytes <= ACP_MAX_INLINE_IMAGE_BYTES;
|
|
25483
|
+
};
|
|
25484
|
+
for (const index of indices) {
|
|
25485
|
+
const message = messages[index];
|
|
25486
|
+
if (message === void 0) continue;
|
|
25487
|
+
appendMessage(blocks, message, images, admitImage);
|
|
25488
|
+
}
|
|
25489
|
+
return blocks;
|
|
25490
|
+
}
|
|
25491
|
+
/**
|
|
25492
|
+
* Whether this `user` message was injected by something other than a human.
|
|
25493
|
+
*
|
|
25494
|
+
* A message without a source kind is treated as human: older harness generations
|
|
25495
|
+
* do not stamp one, and mistaking the real request for synthetic context is worse
|
|
25496
|
+
* than the reverse.
|
|
25497
|
+
*/
|
|
25498
|
+
function isSyntheticUserMessage(message) {
|
|
25499
|
+
if (message.role !== "user") return false;
|
|
25500
|
+
const kind = message.source?.kind;
|
|
25501
|
+
return typeof kind === "string" && kind !== "user";
|
|
25502
|
+
}
|
|
25503
|
+
/** Index of the newest message a human actually wrote. */
|
|
25504
|
+
function lastHumanRequestIndex(messages) {
|
|
25505
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
25506
|
+
const message = messages[index];
|
|
25507
|
+
if (message === void 0 || message.role !== "user") continue;
|
|
25508
|
+
if (isSyntheticUserMessage(message)) continue;
|
|
25509
|
+
return index;
|
|
25510
|
+
}
|
|
25511
|
+
}
|
|
25512
|
+
/** The text one message contributes to a request quote or to the archive. */
|
|
25513
|
+
function plainTextOf$1(message) {
|
|
25514
|
+
const parts = [];
|
|
25515
|
+
for (const block of message.content) {
|
|
25516
|
+
if (block.type === "text") {
|
|
25517
|
+
if (block.text.trim() !== "") parts.push(block.text);
|
|
25518
|
+
continue;
|
|
25519
|
+
}
|
|
25520
|
+
if (block.type === "file") {
|
|
25521
|
+
const name = block.attachment.name ?? "attachment";
|
|
25522
|
+
parts.push(`[file attached: ${name}]`);
|
|
25523
|
+
}
|
|
25524
|
+
}
|
|
25525
|
+
return parts.join("\n").trim();
|
|
25526
|
+
}
|
|
25527
|
+
/** Rough rendered size of a message set; only used to pick the replay shape. */
|
|
25528
|
+
function estimateReplayChars(messages, indices) {
|
|
25529
|
+
let total = 0;
|
|
25530
|
+
for (const index of indices) {
|
|
25531
|
+
const message = messages[index];
|
|
25532
|
+
if (message === void 0) continue;
|
|
25533
|
+
for (const block of message.content) if (block.type === "text") total += block.text.length;
|
|
25534
|
+
else if (block.type === "tool-call") total += block.name.length + Math.min(block.arguments.length, 4096) + 16;
|
|
25535
|
+
else if (block.type === "tool-result") {
|
|
25536
|
+
const body = block.content.map(renderResultBlock).join("\n");
|
|
25537
|
+
total += Math.min(body.length, 8192) + 24;
|
|
25538
|
+
} else if (block.type === "image") total += 256;
|
|
25539
|
+
else if (block.type === "file") total += 64;
|
|
25540
|
+
total += 8;
|
|
25541
|
+
}
|
|
25542
|
+
return total;
|
|
25543
|
+
}
|
|
25544
|
+
/** One headed copy of the request, or nothing when the request has no text. */
|
|
25545
|
+
function requestBlock(heading, text) {
|
|
25546
|
+
return text === "" ? void 0 : {
|
|
25547
|
+
type: "text",
|
|
25548
|
+
text: `${heading}\n${text}`
|
|
25549
|
+
};
|
|
25550
|
+
}
|
|
25551
|
+
/** Whether a message belongs in the compacted archive. */
|
|
25552
|
+
function isArchivable(message) {
|
|
25553
|
+
if (message === void 0) return false;
|
|
25554
|
+
if (message.role !== "user" && message.role !== "assistant") return false;
|
|
25555
|
+
if (isSyntheticUserMessage(message)) return false;
|
|
25556
|
+
return plainTextOf$1(message) !== "";
|
|
25557
|
+
}
|
|
25558
|
+
/**
|
|
25559
|
+
* Plain-text archive entries, newest first until the budget is spent.
|
|
25560
|
+
*
|
|
25561
|
+
* Tool calls, tool results, reasoning and images stay out: they are what made the
|
|
25562
|
+
* replay unreadable, and an agent that needs their detail can read the workspace.
|
|
25563
|
+
*/
|
|
25564
|
+
function boundedArchive(messages, indices) {
|
|
25565
|
+
const entries = [];
|
|
25566
|
+
let budget = REPLAY_ARCHIVE_CHARS;
|
|
25567
|
+
let omitted = 0;
|
|
25568
|
+
for (let position = indices.length - 1; position >= 0; position -= 1) {
|
|
25569
|
+
const message = messages[indices[position] ?? -1];
|
|
25570
|
+
if (message === void 0) continue;
|
|
25571
|
+
const text = truncate(plainTextOf$1(message), REPLAY_MESSAGE_CHARS);
|
|
25572
|
+
if (text.length > budget) {
|
|
25573
|
+
omitted += 1;
|
|
25574
|
+
continue;
|
|
25575
|
+
}
|
|
25576
|
+
budget -= text.length;
|
|
25577
|
+
entries.push(`[${message.role}]\n${text}`);
|
|
25578
|
+
}
|
|
25579
|
+
return {
|
|
25580
|
+
entries: entries.reverse(),
|
|
25581
|
+
omitted
|
|
25582
|
+
};
|
|
25583
|
+
}
|
|
25584
|
+
/** The request's own images and files, which the archive does not carry. */
|
|
25585
|
+
function requestAttachments(message, images) {
|
|
25586
|
+
const blocks = [];
|
|
25587
|
+
let inlineBytes = 0;
|
|
25588
|
+
const admitImage = (bytes) => {
|
|
25589
|
+
inlineBytes += bytes;
|
|
25590
|
+
return inlineBytes <= ACP_MAX_INLINE_IMAGE_BYTES;
|
|
25591
|
+
};
|
|
25592
|
+
for (const block of message.content) {
|
|
25593
|
+
if (block.type !== "image" && block.type !== "file") continue;
|
|
25594
|
+
const rendered = renderBlock(block, images, admitImage);
|
|
25595
|
+
if (rendered === void 0) continue;
|
|
25596
|
+
blocks.push(typeof rendered === "string" ? {
|
|
25597
|
+
type: "text",
|
|
25598
|
+
text: rendered
|
|
25599
|
+
} : rendered);
|
|
25600
|
+
}
|
|
25601
|
+
return blocks;
|
|
25602
|
+
}
|
|
25603
|
+
/** Blocks for a replay of the whole history. */
|
|
25604
|
+
function replayBlocks(messages, images) {
|
|
25605
|
+
const kept = keptIndices(messages);
|
|
25606
|
+
const requestIndex = lastHumanRequestIndex(messages);
|
|
25607
|
+
const requestMessage = requestIndex === void 0 ? void 0 : messages[requestIndex];
|
|
25608
|
+
const request = requestMessage === void 0 ? "" : truncate(plainTextOf$1(requestMessage), REPLAY_REQUEST_CHARS);
|
|
25609
|
+
if (estimateReplayChars(messages, kept) <= 2e5) {
|
|
25610
|
+
const blocks = renderMessages(messages, kept, images);
|
|
25611
|
+
blocks.push({
|
|
25612
|
+
type: "text",
|
|
25613
|
+
text: REPLAY_ANCHOR_INSTRUCTION
|
|
25614
|
+
});
|
|
25615
|
+
const current = requestBlock(CURRENT_REQUEST_HEADING, request);
|
|
25616
|
+
if (current !== void 0) blocks.push(current);
|
|
25617
|
+
return blocks;
|
|
25618
|
+
}
|
|
25619
|
+
return compactReplayBlocks(messages, kept, requestIndex, requestMessage, request, images);
|
|
25620
|
+
}
|
|
25621
|
+
/** Blocks for a replay too large to send verbatim. */
|
|
25622
|
+
function compactReplayBlocks(messages, kept, requestIndex, requestMessage, request, images) {
|
|
25623
|
+
const blocks = [];
|
|
25624
|
+
const instructions = kept.filter((index) => {
|
|
25625
|
+
const role = messages[index]?.role;
|
|
25626
|
+
return role === "system" || role === "developer";
|
|
25627
|
+
});
|
|
25628
|
+
blocks.push(...renderMessages(messages, instructions, images));
|
|
25629
|
+
const active = requestBlock(ACTIVE_REQUEST_HEADING, request);
|
|
25630
|
+
if (active !== void 0) blocks.push(active);
|
|
25631
|
+
const archive = boundedArchive(messages, kept.filter((index) => (requestIndex === void 0 || index < requestIndex) && isArchivable(messages[index])));
|
|
25632
|
+
blocks.push({
|
|
25633
|
+
type: "text",
|
|
25634
|
+
text: [
|
|
25635
|
+
REPLAY_ARCHIVE_HEADING,
|
|
25636
|
+
`${archive.entries.length} earlier messages kept, ${archive.omitted} dropped for length.`,
|
|
25637
|
+
"Earlier tool calls, tool results, images and synthetic context are not replayed; re-read the workspace if an older turn needs their detail."
|
|
25638
|
+
].join("\n")
|
|
25639
|
+
});
|
|
25640
|
+
for (const entry of archive.entries) blocks.push({
|
|
25641
|
+
type: "text",
|
|
25642
|
+
text: entry
|
|
25643
|
+
});
|
|
25644
|
+
blocks.push({
|
|
25645
|
+
type: "text",
|
|
25646
|
+
text: REPLAY_ANCHOR_INSTRUCTION
|
|
25647
|
+
});
|
|
25648
|
+
const current = requestBlock(CURRENT_REQUEST_HEADING, request);
|
|
25649
|
+
if (current !== void 0) blocks.push(current);
|
|
25650
|
+
if (requestMessage !== void 0) blocks.push(...requestAttachments(requestMessage, images));
|
|
25651
|
+
return blocks;
|
|
25652
|
+
}
|
|
25432
25653
|
/** Render one message into prompt blocks. */
|
|
25433
25654
|
function appendMessage(blocks, message, images, admitImage) {
|
|
25434
25655
|
const textParts = [];
|
|
@@ -25491,6 +25712,11 @@ function decorate(message, text) {
|
|
|
25491
25712
|
if (message.role === "assistant") return `[assistant]\n${text}`;
|
|
25492
25713
|
return text;
|
|
25493
25714
|
}
|
|
25715
|
+
/** Durable id of the attachment behind one block, or an empty string. */
|
|
25716
|
+
function attachmentIdOf$1(block) {
|
|
25717
|
+
const attachment = block.attachment;
|
|
25718
|
+
return typeof attachment?.attachmentId === "string" ? attachment.attachmentId : "";
|
|
25719
|
+
}
|
|
25494
25720
|
/** Canonical text for one block, used only for the fingerprint. */
|
|
25495
25721
|
function canonicalBlock(block) {
|
|
25496
25722
|
switch (block.type) {
|
|
@@ -25498,8 +25724,8 @@ function canonicalBlock(block) {
|
|
|
25498
25724
|
case "reasoning": return `reasoning:${block.text}`;
|
|
25499
25725
|
case "tool-call": return `call:${block.name}:${block.arguments}`;
|
|
25500
25726
|
case "tool-result": return `result:${block.toolCallId}:${block.isError === true ? "1" : "0"}`;
|
|
25501
|
-
case "image": return `image:${block
|
|
25502
|
-
case "file": return `file:${block
|
|
25727
|
+
case "image": return `image:${attachmentIdOf$1(block)}`;
|
|
25728
|
+
case "file": return `file:${attachmentIdOf$1(block)}`;
|
|
25503
25729
|
default: return block.type;
|
|
25504
25730
|
}
|
|
25505
25731
|
}
|
|
@@ -25537,6 +25763,30 @@ function isEffort(value) {
|
|
|
25537
25763
|
return EFFORT_ORDER$2.includes(value);
|
|
25538
25764
|
}
|
|
25539
25765
|
/**
|
|
25766
|
+
* Which sign-in method to hand the agent when it asks for one.
|
|
25767
|
+
*
|
|
25768
|
+
* The server publishes whatever method list the installed CLI supports, and the
|
|
25769
|
+
* order below is the line's preference: the personal OAuth flow first, then the
|
|
25770
|
+
* terminal flow, then a business account, then the API-key forms. This lives
|
|
25771
|
+
* here - not beside one call site - because two call sites ask the same question:
|
|
25772
|
+
* a main-model session (`adapter.openSession`) and the catalogue read
|
|
25773
|
+
* (`catalog.readCatalogFrom`). They used to disagree, one of them hard-coding
|
|
25774
|
+
* `oauth-personal` and getting a method the server never offered.
|
|
25775
|
+
*
|
|
25776
|
+
* @param authMethods - The ids the server announced in `initialize`.
|
|
25777
|
+
* @returns The method id to request.
|
|
25778
|
+
*/
|
|
25779
|
+
function preferAuthMethod(authMethods) {
|
|
25780
|
+
for (const candidate of [
|
|
25781
|
+
"oauth-personal",
|
|
25782
|
+
"terminal-login",
|
|
25783
|
+
"oauth-business",
|
|
25784
|
+
"gemini-api-key",
|
|
25785
|
+
"agent-platform"
|
|
25786
|
+
]) if (authMethods.includes(candidate)) return candidate;
|
|
25787
|
+
return authMethods[0] ?? "oauth-personal";
|
|
25788
|
+
}
|
|
25789
|
+
/**
|
|
25540
25790
|
* Collapse the server's tier-suffixed model ids into one selectable model each.
|
|
25541
25791
|
*
|
|
25542
25792
|
* The server publishes two different lists that describe the same catalog:
|
|
@@ -25810,6 +26060,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25810
26060
|
for (const entry of [...this.dormant.values()]) await this.closeDormant(entry);
|
|
25811
26061
|
for (const turn of [...this.live.values()]) {
|
|
25812
26062
|
if (this.live.get(turn.dshSessionId) === turn) this.live.delete(turn.dshSessionId);
|
|
26063
|
+
turn.closed = true;
|
|
25813
26064
|
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
25814
26065
|
turn.queue.close();
|
|
25815
26066
|
this.cancelTurn(turn);
|
|
@@ -25839,10 +26090,12 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25839
26090
|
const settings = await this.options.settings.read();
|
|
25840
26091
|
const images = await resolveRequestImages$1(options, this.options.attachments, signal).catch(() => NO_RESOLVED_IMAGES$3);
|
|
25841
26092
|
const effort = options.reasoningEffort === void 0 ? settings.defaultReasoningEffort ?? void 0 : String(options.reasoningEffort);
|
|
25842
|
-
const live = this.live.get(dshSessionId);
|
|
25843
|
-
if (live !== void 0 && live.model === options.model && live.effort === effort && canContinue(options.messages, live.covered, live.fingerprint)) return this.continueTurn(live, options, images, signal, activity);
|
|
25844
|
-
if (live !== void 0) await this.closeTurn(live);
|
|
25845
26093
|
const auxiliary = options.purpose !== void 0;
|
|
26094
|
+
if (!auxiliary) {
|
|
26095
|
+
const live = this.live.get(dshSessionId);
|
|
26096
|
+
if (live !== void 0 && live.model === options.model && live.effort === effort && canContinue(options.messages, live.covered, live.fingerprint)) return this.continueTurn(live, options, images, signal, activity);
|
|
26097
|
+
if (live !== void 0) await this.closeTurn(live);
|
|
26098
|
+
}
|
|
25846
26099
|
const dormant = auxiliary ? void 0 : this.dormant.get(dshSessionId);
|
|
25847
26100
|
if (dormant !== void 0) if (this.usableDormant(dormant, options)) {
|
|
25848
26101
|
const resumed = await this.resumeDormant(dormant, options, settings, effort, images, signal, activity);
|
|
@@ -25857,6 +26110,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25857
26110
|
this.activeTurns += 1;
|
|
25858
26111
|
const queue = new UpdateQueue();
|
|
25859
26112
|
const bridge = new McpBridge(options.tools ?? []);
|
|
26113
|
+
const binding = {};
|
|
25860
26114
|
let client;
|
|
25861
26115
|
let reusedSessions = 0;
|
|
25862
26116
|
try {
|
|
@@ -25865,10 +26119,11 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25865
26119
|
if (warm !== void 0) {
|
|
25866
26120
|
client = warm.client;
|
|
25867
26121
|
reusedSessions = warm.sessions;
|
|
25868
|
-
this.attachHandlers(client, queue, activity);
|
|
25869
|
-
} else client = this.spawn(launch, queue, activity);
|
|
26122
|
+
this.attachHandlers(client, queue, activity, binding);
|
|
26123
|
+
} else client = this.spawn(launch, queue, activity, binding);
|
|
25870
26124
|
const descriptor = await bridge.start();
|
|
25871
26125
|
const sessionId = await this.openSession(client, options, [descriptor], settings);
|
|
26126
|
+
binding.acpSessionId = sessionId;
|
|
25872
26127
|
await this.applyModelAndEffort(client, sessionId, options.model, effort);
|
|
25873
26128
|
const prompt = buildPrompt(options, images, 0);
|
|
25874
26129
|
if ((options.tools ?? []).length > 0) prompt.blocks.unshift({
|
|
@@ -25893,9 +26148,10 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25893
26148
|
awaitingHarness: false,
|
|
25894
26149
|
sessionsUsed: reusedSessions + 1,
|
|
25895
26150
|
tools: fingerprintTools(options.tools),
|
|
25896
|
-
parkable
|
|
26151
|
+
parkable,
|
|
26152
|
+
closed: false
|
|
25897
26153
|
};
|
|
25898
|
-
this.live.set(dshSessionId, turn);
|
|
26154
|
+
if (parkable) this.live.set(dshSessionId, turn);
|
|
25899
26155
|
this.sendPrompt(turn, prompt.blocks);
|
|
25900
26156
|
return this.pump(turn, signal, activity);
|
|
25901
26157
|
} catch (error) {
|
|
@@ -26119,12 +26375,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26119
26375
|
}
|
|
26120
26376
|
} finally {
|
|
26121
26377
|
if (!finished) await this.closeTurn(turn);
|
|
26122
|
-
else if (!turn.awaitingHarness
|
|
26123
|
-
this.live.delete(turn.dshSessionId);
|
|
26124
|
-
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
26125
|
-
if (turn.parkable) await this.park(turn);
|
|
26126
|
-
else await this.release(turn);
|
|
26127
|
-
}
|
|
26378
|
+
else if (!turn.awaitingHarness) await this.finishTurn(turn, true);
|
|
26128
26379
|
}
|
|
26129
26380
|
}
|
|
26130
26381
|
/**
|
|
@@ -26147,9 +26398,10 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26147
26398
|
if ((typeof toolCall?.name === "string" ? toolCall.name : "").startsWith(`mcp_dsh-bridge_`)) return answer();
|
|
26148
26399
|
return (await this.options.settings.read()).permissionPolicy === "allow" ? answer() : void 0;
|
|
26149
26400
|
}
|
|
26150
|
-
spawn(launch, queue, activity) {
|
|
26401
|
+
spawn(launch, queue, activity, binding) {
|
|
26151
26402
|
const handlers = {
|
|
26152
|
-
onSessionUpdate: (
|
|
26403
|
+
onSessionUpdate: (sessionId, update) => {
|
|
26404
|
+
if (!ownsSession(binding, sessionId)) return;
|
|
26153
26405
|
queue.push(update);
|
|
26154
26406
|
activity.pulse();
|
|
26155
26407
|
},
|
|
@@ -26260,19 +26512,17 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26260
26512
|
sessionId: turn.acpSessionId,
|
|
26261
26513
|
prompt: blocks
|
|
26262
26514
|
}));
|
|
26263
|
-
const
|
|
26515
|
+
const rawUsage = asRecord$19(result?.usage);
|
|
26516
|
+
const usage = rawUsage === void 0 ? void 0 : readUsage(rawUsage);
|
|
26264
26517
|
turn.settled = {
|
|
26265
26518
|
stopReason: typeof result?.stopReason === "string" ? result.stopReason : "end_turn",
|
|
26266
|
-
...usage === void 0 ? {} : { usage
|
|
26519
|
+
...usage === void 0 ? {} : { usage }
|
|
26520
|
+
};
|
|
26521
|
+
if (usage !== void 0) this.lastUsage = {
|
|
26522
|
+
...usage,
|
|
26523
|
+
at: this.now(),
|
|
26524
|
+
durationMs: this.now() - startedAt
|
|
26267
26525
|
};
|
|
26268
|
-
if (usage !== void 0) {
|
|
26269
|
-
const read = readUsage(usage);
|
|
26270
|
-
if (read !== void 0) this.lastUsage = {
|
|
26271
|
-
...read,
|
|
26272
|
-
at: this.now(),
|
|
26273
|
-
durationMs: this.now() - startedAt
|
|
26274
|
-
};
|
|
26275
|
-
}
|
|
26276
26526
|
} catch (error) {
|
|
26277
26527
|
turn.settled = { error: asError(error) };
|
|
26278
26528
|
} finally {
|
|
@@ -26288,11 +26538,36 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26288
26538
|
* agent's own start-up wait on the next message.
|
|
26289
26539
|
*/
|
|
26290
26540
|
async closeTurn(turn) {
|
|
26291
|
-
if (
|
|
26292
|
-
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
26541
|
+
if (turn.closed) return;
|
|
26293
26542
|
turn.queue.close();
|
|
26294
26543
|
this.cancelTurn(turn);
|
|
26295
|
-
await this.
|
|
26544
|
+
await this.finishTurn(turn, false);
|
|
26545
|
+
}
|
|
26546
|
+
/**
|
|
26547
|
+
* Account for one turn exactly once, then hand its process back.
|
|
26548
|
+
*
|
|
26549
|
+
* Every ending goes through here: a completed stream parks the conversation, an
|
|
26550
|
+
* abandoned one releases the process, and a turn whose live entry was replaced
|
|
26551
|
+
* releases it too - it no longer owns this session's conversation, so parking it
|
|
26552
|
+
* would replace the parked one with a transcript nobody is talking to.
|
|
26553
|
+
*
|
|
26554
|
+
* The `closed` flag is what makes this safe to call from a second path: the pump
|
|
26555
|
+
* finishing after a cancellation, and a cancellation arriving after the pump
|
|
26556
|
+
* finished, both used to be able to decrement `activeTurns` or release a process
|
|
26557
|
+
* twice.
|
|
26558
|
+
*
|
|
26559
|
+
* @param turn - The turn being ended.
|
|
26560
|
+
* @param parkAllowed - Whether a conversation may be left parked behind it.
|
|
26561
|
+
*/
|
|
26562
|
+
async finishTurn(turn, parkAllowed) {
|
|
26563
|
+
if (turn.closed) return;
|
|
26564
|
+
turn.closed = true;
|
|
26565
|
+
const owned = this.live.get(turn.dshSessionId) === turn;
|
|
26566
|
+
if (owned) this.live.delete(turn.dshSessionId);
|
|
26567
|
+
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
26568
|
+
turn.queue.close();
|
|
26569
|
+
if (parkAllowed && turn.parkable && owned) await this.park(turn);
|
|
26570
|
+
else await this.release(turn);
|
|
26296
26571
|
}
|
|
26297
26572
|
/**
|
|
26298
26573
|
* Ask the agent to stop the prompt this turn left running.
|
|
@@ -26343,7 +26618,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26343
26618
|
const queue = new UpdateQueue();
|
|
26344
26619
|
try {
|
|
26345
26620
|
if (entry.model !== options.model || entry.effort !== effort) await this.applyModelAndEffort(entry.client, entry.acpSessionId, options.model, effort);
|
|
26346
|
-
this.attachHandlers(entry.client, queue, activity);
|
|
26621
|
+
this.attachHandlers(entry.client, queue, activity, { acpSessionId: entry.acpSessionId });
|
|
26347
26622
|
const prompt = buildPrompt(options, images, entry.covered);
|
|
26348
26623
|
const turn = {
|
|
26349
26624
|
dshSessionId: entry.dshSessionId,
|
|
@@ -26363,7 +26638,8 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26363
26638
|
awaitingHarness: false,
|
|
26364
26639
|
sessionsUsed: entry.sessionsUsed,
|
|
26365
26640
|
tools: entry.tools,
|
|
26366
|
-
parkable: true
|
|
26641
|
+
parkable: true,
|
|
26642
|
+
closed: false
|
|
26367
26643
|
};
|
|
26368
26644
|
this.live.set(turn.dshSessionId, turn);
|
|
26369
26645
|
this.activeTurns += 1;
|
|
@@ -26464,9 +26740,10 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
26464
26740
|
}
|
|
26465
26741
|
}
|
|
26466
26742
|
/** Re-install per-turn handlers on a reused client. */
|
|
26467
|
-
attachHandlers(client, queue, activity) {
|
|
26743
|
+
attachHandlers(client, queue, activity, binding) {
|
|
26468
26744
|
client.rebind({
|
|
26469
|
-
onSessionUpdate: (
|
|
26745
|
+
onSessionUpdate: (sessionId, update) => {
|
|
26746
|
+
if (!ownsSession(binding, sessionId)) return;
|
|
26470
26747
|
queue.push(update);
|
|
26471
26748
|
activity.pulse();
|
|
26472
26749
|
},
|
|
@@ -26705,16 +26982,6 @@ function needsAuth(error, authMethods) {
|
|
|
26705
26982
|
const message = error instanceof Error ? error.message : String(error);
|
|
26706
26983
|
return /authentication required/i.test(message) && authMethods.length > 0;
|
|
26707
26984
|
}
|
|
26708
|
-
function preferAuthMethod(authMethods) {
|
|
26709
|
-
for (const candidate of [
|
|
26710
|
-
"oauth-personal",
|
|
26711
|
-
"terminal-login",
|
|
26712
|
-
"oauth-business",
|
|
26713
|
-
"gemini-api-key",
|
|
26714
|
-
"agent-platform"
|
|
26715
|
-
]) if (authMethods.includes(candidate)) return candidate;
|
|
26716
|
-
return authMethods[0] ?? "oauth-personal";
|
|
26717
|
-
}
|
|
26718
26985
|
function readUsage(raw) {
|
|
26719
26986
|
const input = numberField(raw.inputTokens);
|
|
26720
26987
|
const output = numberField(raw.outputTokens);
|
|
@@ -26729,6 +26996,15 @@ function readUsage(raw) {
|
|
|
26729
26996
|
...numberField(raw.totalTokens) === void 0 ? {} : { totalTokens: numberField(raw.totalTokens) }
|
|
26730
26997
|
};
|
|
26731
26998
|
}
|
|
26999
|
+
/**
|
|
27000
|
+
* Text that means the *service* declined the account rather than the agent failing.
|
|
27001
|
+
*
|
|
27002
|
+
* ACP carries upstream failures inside a JSON-RPC error message, so the sentence
|
|
27003
|
+
* is the only place that distinction survives. The list is deliberately about
|
|
27004
|
+
* what a user can act on - a quota, a policy or verification block, a rate limit -
|
|
27005
|
+
* and a match is reported as {@link ACP_UPSTREAM_BLOCKED}, which is not retried.
|
|
27006
|
+
*/
|
|
27007
|
+
const UPSTREAM_DECLINED = /\b(?:429|403)\b|rate.?limit|too many requests|quota|resource[_ ]exhausted|terms of service|\btos\b|violat|valid(?:ation)?[_ ]required|permission[_ ]denied|account[_ ](?:disabled|suspended)|policy[_ ]violation|verification|verify your|unusual activity|risk|suspended|forbidden/i;
|
|
26732
27008
|
function numberField(value) {
|
|
26733
27009
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
26734
27010
|
}
|
|
@@ -26767,12 +27043,43 @@ function settleReason(stopReason) {
|
|
|
26767
27043
|
};
|
|
26768
27044
|
}
|
|
26769
27045
|
}
|
|
27046
|
+
/**
|
|
27047
|
+
* Whether one `session/update` frame belongs to the turn reading right now.
|
|
27048
|
+
*
|
|
27049
|
+
* A reused process can still be flushing the conversation it ran before: the
|
|
27050
|
+
* `session/cancel` that ended it is a notification, not a barrier, and the process
|
|
27051
|
+
* is handed back to the pool without waiting for its prompt to settle. Those late
|
|
27052
|
+
* frames carry the old session id, and appending them would put another
|
|
27053
|
+
* conversation's text into this answer.
|
|
27054
|
+
*
|
|
27055
|
+
* The id decides whenever it is present. Two cases look similar and are not:
|
|
27056
|
+
*
|
|
27057
|
+
* - A frame that carries *no* id keeps the previous behaviour, because a server
|
|
27058
|
+
* that never repeats the id in a notification must still work - the id has
|
|
27059
|
+
* always been part of the ACP envelope rather than something this line added.
|
|
27060
|
+
* - A frame that names a session while this turn has not created one yet is a
|
|
27061
|
+
* leftover by construction: a warm process is checked out and rewired *before*
|
|
27062
|
+
* `session/new` answers, so anything addressed in that window can only belong
|
|
27063
|
+
* to the conversation it was running before. Keeping it "because we have no id
|
|
27064
|
+
* yet" was the hole in the first version of this filter.
|
|
27065
|
+
*
|
|
27066
|
+
* @param binding - The session this turn owns, once it exists.
|
|
27067
|
+
* @param sessionId - The id the frame carries, empty when it carried none.
|
|
27068
|
+
* @returns whether the frame belongs to this turn.
|
|
27069
|
+
*/
|
|
27070
|
+
function ownsSession(binding, sessionId) {
|
|
27071
|
+
if (sessionId === "") return true;
|
|
27072
|
+
if (binding.acpSessionId === void 0) return false;
|
|
27073
|
+
return sessionId === binding.acpSessionId;
|
|
27074
|
+
}
|
|
26770
27075
|
function asLlmError(error) {
|
|
26771
27076
|
if (error instanceof LlmError) return error;
|
|
27077
|
+
if (error instanceof Error && error.name === "AbortError") return new LlmError("The Antigravity ACP turn was cancelled.", "ABORTED");
|
|
26772
27078
|
if (error instanceof AcpError) {
|
|
26773
|
-
if (error.code === -32e3) return acpError("ACP_AUTH_REQUIRED");
|
|
27079
|
+
if (error.code === -32e3 || /authentication required/i.test(error.message)) return acpError("ACP_AUTH_REQUIRED");
|
|
26774
27080
|
if (error.code === -32602) return acpError("ACP_INVALID_PARAMS");
|
|
26775
27081
|
if (error.code === -32601) return acpError("ACP_METHOD_UNSUPPORTED");
|
|
27082
|
+
if (UPSTREAM_DECLINED.test(error.message)) return acpError("ACP_UPSTREAM_BLOCKED", error.message);
|
|
26776
27083
|
return acpError("ACP_RPC_ERROR", error.message);
|
|
26777
27084
|
}
|
|
26778
27085
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -27021,7 +27328,7 @@ async function readCatalogFrom(client, signal) {
|
|
|
27021
27328
|
version: "1.0.0"
|
|
27022
27329
|
}
|
|
27023
27330
|
}, signal));
|
|
27024
|
-
const authMethods = Array.isArray(init?.authMethods) ? init.authMethods : [];
|
|
27331
|
+
const authMethods = Array.isArray(init?.authMethods) ? init.authMethods.map((entry) => String(entry.id ?? "")).filter((id) => id !== "") : [];
|
|
27025
27332
|
const create = async () => {
|
|
27026
27333
|
const value = asRecord$18(await client.request("session/new", {
|
|
27027
27334
|
cwd: process.cwd(),
|
|
@@ -27036,7 +27343,7 @@ async function readCatalogFrom(client, signal) {
|
|
|
27036
27343
|
} catch (error) {
|
|
27037
27344
|
const message = error instanceof Error ? error.message : String(error);
|
|
27038
27345
|
if (!/authentication required/i.test(message) || authMethods.length === 0) throw error;
|
|
27039
|
-
await client.request("authenticate", { methodId:
|
|
27346
|
+
await client.request("authenticate", { methodId: preferAuthMethod(authMethods) }, signal);
|
|
27040
27347
|
session = await create();
|
|
27041
27348
|
}
|
|
27042
27349
|
const availableModels = readAvailableModels(asRecord$18(session.models)?.availableModels ?? session.availableModels);
|
|
@@ -27191,6 +27498,8 @@ const ACP_BINARY_RELEASES = {
|
|
|
27191
27498
|
executable: "agy_acp_server.par"
|
|
27192
27499
|
}
|
|
27193
27500
|
};
|
|
27501
|
+
/** How long a resolved executable is reused before the disk is read again. */
|
|
27502
|
+
const BINARY_CACHE_TTL_MS = 5 * 6e4;
|
|
27194
27503
|
/** Candidate paths the local CLI may live at, most specific first. */
|
|
27195
27504
|
function localCliCandidates(home, platform) {
|
|
27196
27505
|
return (platform === "win32" ? [
|
|
@@ -27266,6 +27575,11 @@ async function resolveAcpBinary(configured, options = {}) {
|
|
|
27266
27575
|
},
|
|
27267
27576
|
diagnostics: { tried }
|
|
27268
27577
|
};
|
|
27578
|
+
if (options.download === false) return { diagnostics: {
|
|
27579
|
+
tried,
|
|
27580
|
+
deferred: true,
|
|
27581
|
+
error: "No Antigravity CLI (agy) is installed yet. This line downloads the official ACP server the first time you start a turn, run the self-check, or press refresh."
|
|
27582
|
+
} };
|
|
27269
27583
|
try {
|
|
27270
27584
|
return {
|
|
27271
27585
|
binary: {
|
|
@@ -27283,6 +27597,78 @@ async function resolveAcpBinary(configured, options = {}) {
|
|
|
27283
27597
|
}
|
|
27284
27598
|
}
|
|
27285
27599
|
/**
|
|
27600
|
+
* A cached answer to "which executable may this line run?".
|
|
27601
|
+
*
|
|
27602
|
+
* Resolution touches the disk once per candidate and spawns `agy --version` to
|
|
27603
|
+
* prove the file answers, which is not something a page render should do. The
|
|
27604
|
+
* answer is therefore reused for a few minutes; a change of `binaryPath` and the
|
|
27605
|
+
* refresh click invalidate or force it.
|
|
27606
|
+
*
|
|
27607
|
+
* A cached *passive* answer is never served to an active caller: if the reading
|
|
27608
|
+
* was taken without permission to download and found nothing, a turn asking the
|
|
27609
|
+
* same question must still be allowed to fetch the release.
|
|
27610
|
+
*/
|
|
27611
|
+
var AcpBinaryCache = class {
|
|
27612
|
+
resolve;
|
|
27613
|
+
now;
|
|
27614
|
+
ttlMs;
|
|
27615
|
+
value;
|
|
27616
|
+
fetchedAt = 0;
|
|
27617
|
+
withDownload = false;
|
|
27618
|
+
inflight;
|
|
27619
|
+
/** Whether the in-flight read is allowed to install. */
|
|
27620
|
+
inflightDownload = false;
|
|
27621
|
+
/**
|
|
27622
|
+
* @param resolve - Reads the real answer; called at most once per window.
|
|
27623
|
+
* @param now - Clock seam.
|
|
27624
|
+
* @param ttlMs - How long one answer stays valid.
|
|
27625
|
+
*/
|
|
27626
|
+
constructor(resolve, now = Date.now, ttlMs = BINARY_CACHE_TTL_MS) {
|
|
27627
|
+
this.resolve = resolve;
|
|
27628
|
+
this.now = now;
|
|
27629
|
+
this.ttlMs = ttlMs;
|
|
27630
|
+
}
|
|
27631
|
+
/** The cached answer, when one is still valid. */
|
|
27632
|
+
peek() {
|
|
27633
|
+
if (this.value === void 0) return void 0;
|
|
27634
|
+
return this.now() - this.fetchedAt < this.ttlMs ? this.value : void 0;
|
|
27635
|
+
}
|
|
27636
|
+
/**
|
|
27637
|
+
* Read the resolution, reusing a valid answer or one in-flight read.
|
|
27638
|
+
*
|
|
27639
|
+
* @param options - `force` re-reads the disk; `download` allows fetching a release.
|
|
27640
|
+
* @returns The executable (when one was found) and what was tried.
|
|
27641
|
+
*/
|
|
27642
|
+
async read(options = {}) {
|
|
27643
|
+
if (options.force !== true) {
|
|
27644
|
+
const cached = this.peek();
|
|
27645
|
+
if (cached !== void 0 && (options.download !== true || this.withDownload || cached.binary !== void 0)) return cached;
|
|
27646
|
+
}
|
|
27647
|
+
const download = options.download !== false;
|
|
27648
|
+
if (this.inflight !== void 0) {
|
|
27649
|
+
if (!(download && !this.inflightDownload)) return this.inflight;
|
|
27650
|
+
await this.inflight.catch(() => void 0);
|
|
27651
|
+
}
|
|
27652
|
+
const promise = this.resolve({ download }).then((value) => {
|
|
27653
|
+
this.value = value;
|
|
27654
|
+
this.fetchedAt = this.now();
|
|
27655
|
+
this.withDownload = download;
|
|
27656
|
+
return value;
|
|
27657
|
+
}).finally(() => {
|
|
27658
|
+
if (this.inflight === promise) this.inflight = void 0;
|
|
27659
|
+
});
|
|
27660
|
+
this.inflight = promise;
|
|
27661
|
+
this.inflightDownload = download;
|
|
27662
|
+
return promise;
|
|
27663
|
+
}
|
|
27664
|
+
/** Forget the answer, e.g. because the configured path just changed. */
|
|
27665
|
+
invalidate() {
|
|
27666
|
+
this.value = void 0;
|
|
27667
|
+
this.fetchedAt = 0;
|
|
27668
|
+
this.withDownload = false;
|
|
27669
|
+
}
|
|
27670
|
+
};
|
|
27671
|
+
/**
|
|
27286
27672
|
* Download and extract one release.
|
|
27287
27673
|
*
|
|
27288
27674
|
* The archive is fetched whole (bounded), hashed, and only then extracted; an
|
|
@@ -27413,24 +27799,41 @@ function findEndOfCentralDirectory(bytes) {
|
|
|
27413
27799
|
*
|
|
27414
27800
|
* @module dsh-chatgpt-subscription/host/antigravity-acp/login
|
|
27415
27801
|
*/
|
|
27802
|
+
/** How long the login launcher may run before it is considered detached. */
|
|
27803
|
+
const LOGIN_LAUNCH_BUDGET_MS = 1e4;
|
|
27804
|
+
/**
|
|
27805
|
+
* How long a launcher is watched for a start-up failure before it is left alone.
|
|
27806
|
+
*
|
|
27807
|
+
* A successful sign-in keeps the process alive until the browser callback lands,
|
|
27808
|
+
* so this may not wait for the exit: it only has to catch the failures that
|
|
27809
|
+
* happen before the CLI ever gets going - an executable that cannot be spawned,
|
|
27810
|
+
* or a command line the CLI rejects.
|
|
27811
|
+
*/
|
|
27812
|
+
const LOGIN_FAILURE_WINDOW_MS = 1e3;
|
|
27813
|
+
/** Most stderr kept for that failure sentence; a login banner is not a diagnostic. */
|
|
27814
|
+
const LOGIN_STDERR_CAP = 2e3;
|
|
27416
27815
|
/**
|
|
27417
27816
|
* Start the official sign-in.
|
|
27418
27817
|
*
|
|
27419
|
-
* The process is spawned detached
|
|
27420
|
-
*
|
|
27421
|
-
*
|
|
27422
|
-
*
|
|
27818
|
+
* The process is spawned detached: on a desktop it opens the browser and exits
|
|
27819
|
+
* once the callback lands, on a headless host it prints the URL it would have
|
|
27820
|
+
* opened. Either way this call never waits for the user.
|
|
27821
|
+
*
|
|
27822
|
+
* What it *does* wait for is the failure that happens before the CLI gets going.
|
|
27823
|
+
* The command line is `agy acp --login`, and a rejected command line, a
|
|
27824
|
+
* misconfigured path or a binary that cannot be spawned all exit (or error)
|
|
27825
|
+
* within milliseconds - and the previous version reported "sign-in started" for
|
|
27826
|
+
* every one of them while discarding the only sentence that explained it. The
|
|
27827
|
+
* launcher is therefore watched for {@link LOGIN_FAILURE_WINDOW_MS}: a spawn
|
|
27828
|
+
* error, or a non-zero exit that left stderr behind, is returned as the reason.
|
|
27423
27829
|
*
|
|
27424
27830
|
* @param launch - The resolved executable.
|
|
27425
|
-
* @returns whether a process was started.
|
|
27831
|
+
* @returns whether a process was started, and why it was not.
|
|
27426
27832
|
*/
|
|
27427
27833
|
function startLogin(launch) {
|
|
27834
|
+
let child;
|
|
27428
27835
|
try {
|
|
27429
|
-
|
|
27430
|
-
...launch.args.slice(0, -1),
|
|
27431
|
-
"acp",
|
|
27432
|
-
"--login"
|
|
27433
|
-
], {
|
|
27836
|
+
child = spawn(launch.command, [...launch.args, "--login"], {
|
|
27434
27837
|
detached: true,
|
|
27435
27838
|
stdio: [
|
|
27436
27839
|
"ignore",
|
|
@@ -27439,15 +27842,57 @@ function startLogin(launch) {
|
|
|
27439
27842
|
],
|
|
27440
27843
|
windowsHide: true
|
|
27441
27844
|
});
|
|
27442
|
-
child.stderr?.resume();
|
|
27443
|
-
child.unref();
|
|
27444
|
-
return { started: true };
|
|
27445
27845
|
} catch (error) {
|
|
27446
|
-
return {
|
|
27846
|
+
return Promise.resolve({
|
|
27447
27847
|
started: false,
|
|
27448
27848
|
error: error instanceof Error ? error.message : String(error)
|
|
27449
|
-
};
|
|
27849
|
+
});
|
|
27450
27850
|
}
|
|
27851
|
+
return watchLauncher(child);
|
|
27852
|
+
}
|
|
27853
|
+
/**
|
|
27854
|
+
* Watch one launcher through its start-up window.
|
|
27855
|
+
*
|
|
27856
|
+
* @param child - The detached sign-in process.
|
|
27857
|
+
* @returns whether it started, and the CLI's own explanation when it did not.
|
|
27858
|
+
*/
|
|
27859
|
+
function watchLauncher(child) {
|
|
27860
|
+
let stderr = "";
|
|
27861
|
+
child.stderr?.setEncoding("utf8");
|
|
27862
|
+
child.stderr?.on("data", (chunk) => {
|
|
27863
|
+
if (stderr.length < LOGIN_STDERR_CAP) stderr += chunk.slice(0, LOGIN_STDERR_CAP - stderr.length);
|
|
27864
|
+
});
|
|
27865
|
+
child.unref();
|
|
27866
|
+
return new Promise((resolve) => {
|
|
27867
|
+
let settled = false;
|
|
27868
|
+
const settle = (result) => {
|
|
27869
|
+
if (settled) return;
|
|
27870
|
+
settled = true;
|
|
27871
|
+
clearTimeout(windowTimer);
|
|
27872
|
+
clearTimeout(detachTimer);
|
|
27873
|
+
resolve(result);
|
|
27874
|
+
};
|
|
27875
|
+
const detail = () => stderr.trim().split(/\r?\n/u).filter((line) => line !== "").slice(-3).join(" ");
|
|
27876
|
+
const failed = (reason) => ({
|
|
27877
|
+
started: false,
|
|
27878
|
+
error: detail() === "" ? reason : reason + ": " + detail()
|
|
27879
|
+
});
|
|
27880
|
+
const windowTimer = setTimeout(() => settle({ started: true }), LOGIN_FAILURE_WINDOW_MS);
|
|
27881
|
+
windowTimer.unref?.();
|
|
27882
|
+
const detachTimer = setTimeout(() => {
|
|
27883
|
+
child.stderr?.removeAllListeners("data");
|
|
27884
|
+
child.removeAllListeners();
|
|
27885
|
+
}, LOGIN_LAUNCH_BUDGET_MS);
|
|
27886
|
+
detachTimer.unref?.();
|
|
27887
|
+
child.once("error", (error) => settle(failed(error.message)));
|
|
27888
|
+
child.once("exit", (code, signal) => {
|
|
27889
|
+
if (code === 0 || signal !== null) {
|
|
27890
|
+
settle({ started: true });
|
|
27891
|
+
return;
|
|
27892
|
+
}
|
|
27893
|
+
settle(failed(`The Antigravity CLI exited with code ${String(code ?? "null")} before sign-in began.`));
|
|
27894
|
+
});
|
|
27895
|
+
});
|
|
27451
27896
|
}
|
|
27452
27897
|
/**
|
|
27453
27898
|
* Ask the agent whether it currently holds usable credentials.
|
|
@@ -27540,20 +27985,27 @@ const MAX_BODY_BYTES$8 = 64 * 1024;
|
|
|
27540
27985
|
* host restarted twice in an afternoon still shows a current list.
|
|
27541
27986
|
*/
|
|
27542
27987
|
const CATALOG_FRESHNESS_MS = 1440 * 60 * 1e3;
|
|
27543
|
-
/**
|
|
27544
|
-
|
|
27988
|
+
/**
|
|
27989
|
+
* Build the status payload the card renders.
|
|
27990
|
+
*
|
|
27991
|
+
* @param options - The line's live state and actions.
|
|
27992
|
+
* @param read - `fresh` when this read is a user action rather than a poll.
|
|
27993
|
+
* @returns The status the card renders.
|
|
27994
|
+
*/
|
|
27995
|
+
async function readStatus(options, read = {}) {
|
|
27996
|
+
const fresh = read.fresh === true;
|
|
27545
27997
|
const settings = await options.settings.read();
|
|
27546
27998
|
if (!settings.enabled) return disabledStatus(settings);
|
|
27547
|
-
const resolved = await options.resolveBinary().catch(() => ({ error: "The executable could not be resolved." }));
|
|
27999
|
+
const resolved = await options.resolveBinary({ fresh }).catch(() => ({ error: "The executable could not be resolved." }));
|
|
27548
28000
|
const catalog = await options.catalog.rehydrate();
|
|
27549
|
-
const auth = resolved.binary === void 0 ? { authenticated: false } : await options.auth().catch(() => ({ authenticated: false }));
|
|
28001
|
+
const auth = resolved.binary === void 0 ? { authenticated: false } : await options.auth({ force: fresh }).catch(() => ({ authenticated: false }));
|
|
27550
28002
|
const models = catalog?.models ?? [];
|
|
27551
28003
|
const conflict = options.conflict();
|
|
27552
28004
|
return {
|
|
27553
28005
|
enabled: settings.enabled,
|
|
27554
28006
|
binary: resolved.binary === void 0 ? {
|
|
27555
28007
|
kind: "missing",
|
|
27556
|
-
...resolved.error === void 0 ? {} : { error: missingBinaryMessage(resolved.error) }
|
|
28008
|
+
...resolved.error === void 0 ? {} : { error: resolved.deferred === true ? resolved.error : missingBinaryMessage(resolved.error) }
|
|
27557
28009
|
} : {
|
|
27558
28010
|
kind: resolved.binary.kind,
|
|
27559
28011
|
path: resolved.binary.path,
|
|
@@ -27637,11 +28089,12 @@ function registerAntigravityAcpRoutes(ctx, options) {
|
|
|
27637
28089
|
if (!sameSettings(await options.settings.read(), await options.settings.update(update))) ctx.emit?.("llm/adapters-updated");
|
|
27638
28090
|
if (update.binaryPath !== void 0) {
|
|
27639
28091
|
options.catalog.invalidate();
|
|
28092
|
+
options.invalidateBinary?.();
|
|
27640
28093
|
await options.catalog.read({ force: true }).catch(() => void 0);
|
|
27641
28094
|
}
|
|
27642
28095
|
return sendJson$10(response, 200, {
|
|
27643
28096
|
ok: true,
|
|
27644
|
-
value: await readStatus(options)
|
|
28097
|
+
value: await readStatus(options, { fresh: true })
|
|
27645
28098
|
});
|
|
27646
28099
|
}
|
|
27647
28100
|
if (path === "login/start") {
|
|
@@ -27664,7 +28117,7 @@ function registerAntigravityAcpRoutes(ctx, options) {
|
|
|
27664
28117
|
if (method !== "GET") return sendMethodNotAllowed$9(response);
|
|
27665
28118
|
return sendJson$10(response, 200, {
|
|
27666
28119
|
ok: true,
|
|
27667
|
-
value: await options.auth()
|
|
28120
|
+
value: await options.auth({ force: true })
|
|
27668
28121
|
});
|
|
27669
28122
|
}
|
|
27670
28123
|
if (path === "logout") {
|
|
@@ -27710,6 +28163,7 @@ function registerAntigravityAcpRoutes(ctx, options) {
|
|
|
27710
28163
|
ok: false,
|
|
27711
28164
|
error: "Cross-origin request rejected."
|
|
27712
28165
|
});
|
|
28166
|
+
options.invalidateBinary?.();
|
|
27713
28167
|
const refreshed = await options.catalog.read({ force: true }).catch(() => void 0);
|
|
27714
28168
|
await options.auth({ force: true }).catch(() => void 0);
|
|
27715
28169
|
if (refreshed === void 0) return sendJson$10(response, 502, {
|
|
@@ -27718,7 +28172,7 @@ function registerAntigravityAcpRoutes(ctx, options) {
|
|
|
27718
28172
|
});
|
|
27719
28173
|
return sendJson$10(response, 200, {
|
|
27720
28174
|
ok: true,
|
|
27721
|
-
value: await readStatus(options)
|
|
28175
|
+
value: await readStatus(options, { fresh: true })
|
|
27722
28176
|
});
|
|
27723
28177
|
}
|
|
27724
28178
|
return sendJson$10(response, 404, {
|
|
@@ -27806,8 +28260,17 @@ async function readRequestJson$10(request) {
|
|
|
27806
28260
|
}
|
|
27807
28261
|
//#endregion
|
|
27808
28262
|
//#region src/host/antigravity-acp/auth-cache.ts
|
|
27809
|
-
/**
|
|
27810
|
-
|
|
28263
|
+
/**
|
|
28264
|
+
* How long one probe answers for.
|
|
28265
|
+
*
|
|
28266
|
+
* Ten minutes, not one. A probe is a whole `agy` process plus a `session/new`
|
|
28267
|
+
* against Google, and the card, the hub overview and the composer badge each poll
|
|
28268
|
+
* this route - at a one-minute window that was a process launch per minute for a
|
|
28269
|
+
* question whose answer changes only when the user signs in or out. Those two
|
|
28270
|
+
* events are exactly what invalidates the cache (`login/start`, `login/status`,
|
|
28271
|
+
* the refresh click), so the window does not delay a real state change.
|
|
28272
|
+
*/
|
|
28273
|
+
const AUTH_CACHE_TTL_MS = 10 * 6e4;
|
|
27811
28274
|
/** The cache itself. */
|
|
27812
28275
|
var AcpAuthCache = class {
|
|
27813
28276
|
probe;
|
|
@@ -27987,10 +28450,12 @@ function registerAntigravityAcpSubagent(ctx, options) {
|
|
|
27987
28450
|
* working directory, and that is all.
|
|
27988
28451
|
*/
|
|
27989
28452
|
function createProvider(options) {
|
|
28453
|
+
const cap = options.maxActiveRuns ?? 4;
|
|
28454
|
+
let active = 0;
|
|
27990
28455
|
return {
|
|
27991
28456
|
name: SUBAGENT_PROVIDER_NAME,
|
|
27992
28457
|
capabilities: {
|
|
27993
|
-
agentOptions:
|
|
28458
|
+
agentOptions: true,
|
|
27994
28459
|
agentPreset: false,
|
|
27995
28460
|
outputSchema: false,
|
|
27996
28461
|
depthLimit: false
|
|
@@ -27999,27 +28464,44 @@ function createProvider(options) {
|
|
|
27999
28464
|
async start(request) {
|
|
28000
28465
|
const settings = await options.settings.read();
|
|
28001
28466
|
if (!settings.enabled) throw new LlmError$1("The Antigravity (ACP) line is switched off. Enable it in the subscription overview before delegating to it.", "ACP_DISABLED");
|
|
28002
|
-
|
|
28003
|
-
|
|
28004
|
-
let
|
|
28005
|
-
const
|
|
28006
|
-
|
|
28007
|
-
|
|
28008
|
-
|
|
28009
|
-
dispose: async () => {
|
|
28010
|
-
if (settled) return;
|
|
28011
|
-
settled = true;
|
|
28012
|
-
running.settle({
|
|
28013
|
-
output: running.output(),
|
|
28014
|
-
stopReason: "aborted"
|
|
28015
|
-
});
|
|
28016
|
-
await running.client.dispose().catch(() => void 0);
|
|
28017
|
-
}
|
|
28467
|
+
if (active >= cap) throw acpError("ACP_SESSION_LIMIT", `${active} delegated runs are already in flight (limit ${cap}).`);
|
|
28468
|
+
active += 1;
|
|
28469
|
+
let released = false;
|
|
28470
|
+
const release = () => {
|
|
28471
|
+
if (released) return;
|
|
28472
|
+
released = true;
|
|
28473
|
+
active = Math.max(0, active - 1);
|
|
28018
28474
|
};
|
|
28475
|
+
try {
|
|
28476
|
+
const launch = await options.resolveLaunch();
|
|
28477
|
+
const task = promptText(request.prompt);
|
|
28478
|
+
let settled = false;
|
|
28479
|
+
const running = startRun(launch, request.cwd, task, settings.permissionPolicy, options, request);
|
|
28480
|
+
running.result.then(release, release);
|
|
28481
|
+
return {
|
|
28482
|
+
id: SUBAGENT_PROVIDER_NAME,
|
|
28483
|
+
result: running.result,
|
|
28484
|
+
dispose: async () => {
|
|
28485
|
+
if (settled) return;
|
|
28486
|
+
settled = true;
|
|
28487
|
+
running.settle({
|
|
28488
|
+
output: running.output(),
|
|
28489
|
+
stopReason: "aborted"
|
|
28490
|
+
});
|
|
28491
|
+
await running.client.dispose().catch(() => void 0);
|
|
28492
|
+
}
|
|
28493
|
+
};
|
|
28494
|
+
} catch (error) {
|
|
28495
|
+
release();
|
|
28496
|
+
throw error;
|
|
28497
|
+
}
|
|
28019
28498
|
}
|
|
28020
28499
|
};
|
|
28021
28500
|
}
|
|
28022
|
-
function startRun(launch, cwd, task, permissionPolicy, options,
|
|
28501
|
+
function startRun(launch, cwd, task, permissionPolicy, options, request) {
|
|
28502
|
+
const signal = request.signal;
|
|
28503
|
+
const model = textField(request.agentOptions?.model);
|
|
28504
|
+
const effort = textField(request.agentOptions?.reasoningEffort);
|
|
28023
28505
|
let settle = () => void 0;
|
|
28024
28506
|
const result = new Promise((resolve) => {
|
|
28025
28507
|
settle = resolve;
|
|
@@ -28087,6 +28569,16 @@ function startRun(launch, cwd, task, permissionPolicy, options, signal) {
|
|
|
28087
28569
|
}));
|
|
28088
28570
|
const sessionId = typeof session?.sessionId === "string" ? session.sessionId : void 0;
|
|
28089
28571
|
if (sessionId === void 0) throw new Error("Antigravity ACP did not return a session id.");
|
|
28572
|
+
if (model !== void 0) await client.request("session/set_config_option", {
|
|
28573
|
+
sessionId,
|
|
28574
|
+
configId: "model",
|
|
28575
|
+
value: model
|
|
28576
|
+
});
|
|
28577
|
+
if (effort !== void 0) await client.request("session/set_config_option", {
|
|
28578
|
+
sessionId,
|
|
28579
|
+
configId: "thought_level",
|
|
28580
|
+
value: effort
|
|
28581
|
+
}).catch(() => void 0);
|
|
28090
28582
|
const answer = asRecord$16(await withTimeout$11(client.request("session/prompt", {
|
|
28091
28583
|
sessionId,
|
|
28092
28584
|
prompt: [{
|
|
@@ -28124,6 +28616,10 @@ function startRun(launch, cwd, task, permissionPolicy, options, signal) {
|
|
|
28124
28616
|
output
|
|
28125
28617
|
};
|
|
28126
28618
|
}
|
|
28619
|
+
/** A non-empty string, or undefined; the host's own values are untrusted input here. */
|
|
28620
|
+
function textField(value) {
|
|
28621
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
28622
|
+
}
|
|
28127
28623
|
/** Flatten the prompt blocks a caller supplied into the one text the agent gets. */
|
|
28128
28624
|
function promptText(prompt) {
|
|
28129
28625
|
const parts = [];
|
|
@@ -37006,7 +37502,8 @@ const EMPTY_CACHE_STATS = {
|
|
|
37006
37502
|
outputTokens: 0,
|
|
37007
37503
|
cacheWriteTokens: 0,
|
|
37008
37504
|
cacheWrite5mTokens: 0,
|
|
37009
|
-
cacheWrite1hTokens: 0
|
|
37505
|
+
cacheWrite1hTokens: 0,
|
|
37506
|
+
cacheWriteReported: false
|
|
37010
37507
|
};
|
|
37011
37508
|
/** Record one request's usage into its own session's totals. */
|
|
37012
37509
|
function recordCacheStats(state, sessionId, accountId) {
|
|
@@ -37021,7 +37518,8 @@ function recordCacheStats(state, sessionId, accountId) {
|
|
|
37021
37518
|
outputTokens: previous.outputTokens + state.outputTokens,
|
|
37022
37519
|
cacheWriteTokens: previous.cacheWriteTokens + state.cacheWriteTokens,
|
|
37023
37520
|
cacheWrite5mTokens: previous.cacheWrite5mTokens + state.cacheWrite5mTokens,
|
|
37024
|
-
cacheWrite1hTokens: previous.cacheWrite1hTokens + state.cacheWrite1hTokens
|
|
37521
|
+
cacheWrite1hTokens: previous.cacheWrite1hTokens + state.cacheWrite1hTokens,
|
|
37522
|
+
cacheWriteReported: previous.cacheWriteReported || state.cacheWriteReported
|
|
37025
37523
|
});
|
|
37026
37524
|
}
|
|
37027
37525
|
/** Add one entry into an accumulator. */
|
|
@@ -37033,6 +37531,7 @@ function accumulate(totals, stats) {
|
|
|
37033
37531
|
totals.cacheWriteTokens += stats.cacheWriteTokens;
|
|
37034
37532
|
totals.cacheWrite5mTokens += stats.cacheWrite5mTokens;
|
|
37035
37533
|
totals.cacheWrite1hTokens += stats.cacheWrite1hTokens;
|
|
37534
|
+
totals.cacheWriteReported = totals.cacheWriteReported || stats.cacheWriteReported;
|
|
37036
37535
|
}
|
|
37037
37536
|
/**
|
|
37038
37537
|
* Totals for one account's share of a session, one whole session, or every
|
|
@@ -37409,6 +37908,7 @@ function normalizeRecord$2(value) {
|
|
|
37409
37908
|
const lastRequestImageBytes = nonNegative(value.lastRequestImageBytes);
|
|
37410
37909
|
const lastDroppedImages = nonNegative(value.lastDroppedImages);
|
|
37411
37910
|
const recentRequests = normalizeRecentRequests(value.recentRequests);
|
|
37911
|
+
const cacheWriteReported = value.cacheWriteReported === true ? true : void 0;
|
|
37412
37912
|
return {
|
|
37413
37913
|
lastActiveAt,
|
|
37414
37914
|
updatedAt,
|
|
@@ -37420,6 +37920,7 @@ function normalizeRecord$2(value) {
|
|
|
37420
37920
|
cacheWriteTokens: count$1(value.cacheWriteTokens),
|
|
37421
37921
|
cacheWrite5mTokens: count$1(value.cacheWrite5mTokens),
|
|
37422
37922
|
cacheWrite1hTokens: count$1(value.cacheWrite1hTokens),
|
|
37923
|
+
...cacheWriteReported === void 0 ? {} : { cacheWriteReported },
|
|
37423
37924
|
...drift === void 0 ? {} : { lastDrift: drift },
|
|
37424
37925
|
...firstRequestCachedTokens === void 0 ? {} : { firstRequestCachedTokens },
|
|
37425
37926
|
...firstRequestPromptTokens === void 0 ? {} : { firstRequestPromptTokens },
|
|
@@ -38855,6 +39356,7 @@ function noteSessionCacheState(sessionId, state, successful, requestDiagnostic)
|
|
|
38855
39356
|
...priorRecord?.firstRequestCachedTokens === void 0 ? {} : { firstRequestCachedTokens: priorRecord.firstRequestCachedTokens },
|
|
38856
39357
|
...priorRecord?.firstRequestPromptTokens === void 0 ? {} : { firstRequestPromptTokens: priorRecord.firstRequestPromptTokens }
|
|
38857
39358
|
};
|
|
39359
|
+
const cacheWriteReported = stats.cacheWriteReported || priorRecord?.cacheWriteReported === true;
|
|
38858
39360
|
sessionCacheState.write(sessionId, {
|
|
38859
39361
|
lastActiveAt: now,
|
|
38860
39362
|
totalTokens: state.cacheReadTokens + state.inputTokens + state.cacheWriteTokens,
|
|
@@ -38865,6 +39367,7 @@ function noteSessionCacheState(sessionId, state, successful, requestDiagnostic)
|
|
|
38865
39367
|
cacheWriteTokens: stats.cacheWriteTokens,
|
|
38866
39368
|
cacheWrite5mTokens: stats.cacheWrite5mTokens,
|
|
38867
39369
|
cacheWrite1hTokens: stats.cacheWrite1hTokens,
|
|
39370
|
+
...cacheWriteReported ? { cacheWriteReported: true } : {},
|
|
38868
39371
|
lastRequestCachedTokens: state.cacheReadTokens,
|
|
38869
39372
|
lastRequestFreshTokens: state.inputTokens,
|
|
38870
39373
|
...accountObservation,
|
|
@@ -40196,15 +40699,16 @@ function cacheStatsOrNull(sessionId) {
|
|
|
40196
40699
|
const opening = openingInheritanceOf(sessionId);
|
|
40197
40700
|
const continuation = continuationOf(sessionId);
|
|
40198
40701
|
const lastRequest = lastRequestDiagnosticOf(sessionId);
|
|
40702
|
+
const { cacheWriteReported, ...totals } = stats;
|
|
40199
40703
|
return {
|
|
40200
|
-
...
|
|
40704
|
+
...totals,
|
|
40201
40705
|
...lastDrift === void 0 ? {} : { lastDrift },
|
|
40202
40706
|
...warmup === void 0 ? {} : { warmup },
|
|
40203
40707
|
...opening === void 0 ? {} : { opening },
|
|
40204
40708
|
...continuation === void 0 ? {} : { continuation },
|
|
40205
40709
|
...lastRequest === void 0 ? {} : { lastRequest },
|
|
40206
40710
|
imageBudget: imageBudgetOf(sessionId),
|
|
40207
|
-
cacheWriteTokens: stats.cacheWriteTokens,
|
|
40711
|
+
cacheWriteTokens: cacheWriteReported ? stats.cacheWriteTokens : null,
|
|
40208
40712
|
cacheWrite5mTokens: stats.cacheWrite5mTokens,
|
|
40209
40713
|
cacheWrite1hTokens: stats.cacheWrite1hTokens
|
|
40210
40714
|
};
|
|
@@ -40255,7 +40759,7 @@ function durableCacheStats(sessionId) {
|
|
|
40255
40759
|
freshTokens: durable.freshTokens,
|
|
40256
40760
|
outputTokens: durable.outputTokens,
|
|
40257
40761
|
hitRatio: hitRatioOf(durable.cachedTokens, durable.freshTokens),
|
|
40258
|
-
cacheWriteTokens: durable.cacheWriteTokens,
|
|
40762
|
+
cacheWriteTokens: durable.cacheWriteReported === true ? durable.cacheWriteTokens : null,
|
|
40259
40763
|
cacheWrite5mTokens: durable.cacheWrite5mTokens,
|
|
40260
40764
|
cacheWrite1hTokens: durable.cacheWrite1hTokens,
|
|
40261
40765
|
...lastDrift === void 0 ? {} : { lastDrift },
|
|
@@ -105101,7 +105605,7 @@ const Config = z$1.object({
|
|
|
105101
105605
|
z$1.const("zh"),
|
|
105102
105606
|
z$1.const("en"),
|
|
105103
105607
|
z$1.const("ru")
|
|
105104
|
-
]).default("auto").volatile().description("进展更新的输出语言:auto 跟随对话语言,zh 中文,en
|
|
105608
|
+
]).default("auto").volatile().description("进展更新的输出语言:auto 跟随对话语言,zh 中文,en 英文,ru 俄文。"),
|
|
105105
105609
|
planModePipeline: z$1.boolean().default(true).volatile().description("启用计划模式管线:允许调度模式在澄清访谈收敛后用 enter_plan_mode 进入计划模式,放弃规划时用 leave_plan_mode 退出。"),
|
|
105106
105610
|
dispatchExecutionGuard: z$1.boolean().default(true).volatile().description("启用调度执行守卫:在执行期拦截子代理越权调用主控专用工具,并拦截等待子代理期间的纯 sleep 空等命令;不修改工具声明面,零损耗保护 Kimi 缓存。"),
|
|
105107
105611
|
toolRunawayGuard: z$1.boolean().default(true).volatile().description("启用工具失控治理:对零增量病态信号(同名同参重复、同一工具连续同族报错、后台任务无变化轮询)分级提醒;Kimi 保留第 12 次同参强停,其他线路只提醒。"),
|
|
@@ -105377,8 +105881,11 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
105377
105881
|
attachments: ctx.attachments
|
|
105378
105882
|
}, ollamaAccountPool);
|
|
105379
105883
|
const antigravityAcpSettings = new AntigravityAcpSettingsStore();
|
|
105884
|
+
const antigravityAcpBinary = new AcpBinaryCache(async (options) => {
|
|
105885
|
+
return resolveAcpBinary((await antigravityAcpSettings.read()).binaryPath, { download: options.download !== false });
|
|
105886
|
+
});
|
|
105380
105887
|
const resolveAntigravityLaunch = async () => {
|
|
105381
|
-
const resolved = await
|
|
105888
|
+
const resolved = await antigravityAcpBinary.read({ download: true });
|
|
105382
105889
|
if (resolved.binary === void 0) throw new Error(resolved.diagnostics.error ?? "No usable Antigravity CLI (agy) was found.");
|
|
105383
105890
|
return {
|
|
105384
105891
|
command: resolved.binary.path,
|
|
@@ -105404,7 +105911,15 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
105404
105911
|
attachments: ctx.attachments
|
|
105405
105912
|
});
|
|
105406
105913
|
antigravityAcpCatalog.rehydrate().catch(() => void 0);
|
|
105407
|
-
const antigravityAcpAuth = new AcpAuthCache(() => probeAuthWithLaunch(
|
|
105914
|
+
const antigravityAcpAuth = new AcpAuthCache(() => probeAuthWithLaunch(async () => {
|
|
105915
|
+
const resolved = await antigravityAcpBinary.read({ download: false });
|
|
105916
|
+
if (resolved.binary === void 0) throw new Error(resolved.diagnostics.error ?? "No usable Antigravity CLI (agy) was found.");
|
|
105917
|
+
return {
|
|
105918
|
+
command: resolved.binary.path,
|
|
105919
|
+
args: ["acp", "--disable-telemetry"],
|
|
105920
|
+
version: resolved.binary.version
|
|
105921
|
+
};
|
|
105922
|
+
}));
|
|
105408
105923
|
const kimiCodeClaim = claimProviderRoute(ctx, {
|
|
105409
105924
|
providerId: PROVIDER_ID$9,
|
|
105410
105925
|
label: PROVIDER_NAME$8,
|
|
@@ -105437,16 +105952,18 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
105437
105952
|
const disposeAntigravityAcpRoutes = registerAntigravityAcpRoutes(ctx, {
|
|
105438
105953
|
settings: antigravityAcpSettings,
|
|
105439
105954
|
catalog: antigravityAcpCatalog,
|
|
105440
|
-
resolveBinary: async () => {
|
|
105441
|
-
const resolved = await
|
|
105955
|
+
resolveBinary: async (options) => {
|
|
105956
|
+
const resolved = await antigravityAcpBinary.read({ download: options?.fresh === true });
|
|
105442
105957
|
return {
|
|
105443
105958
|
binary: resolved.binary,
|
|
105444
|
-
error: resolved.diagnostics.error
|
|
105959
|
+
error: resolved.diagnostics.error,
|
|
105960
|
+
deferred: resolved.diagnostics.deferred === true
|
|
105445
105961
|
};
|
|
105446
105962
|
},
|
|
105963
|
+
invalidateBinary: () => antigravityAcpBinary.invalidate(),
|
|
105447
105964
|
login: async () => {
|
|
105448
105965
|
try {
|
|
105449
|
-
const started = startLogin(await resolveAntigravityLaunch());
|
|
105966
|
+
const started = await startLogin(await resolveAntigravityLaunch());
|
|
105450
105967
|
antigravityAcpAuth.invalidate();
|
|
105451
105968
|
return started;
|
|
105452
105969
|
} catch (error) {
|
|
@@ -105461,7 +105978,7 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
105461
105978
|
occupancy: () => antigravityAcpAdapter.occupancy(),
|
|
105462
105979
|
runDoctor: () => runDoctor({
|
|
105463
105980
|
resolveBinary: async () => {
|
|
105464
|
-
const resolved = await
|
|
105981
|
+
const resolved = await antigravityAcpBinary.read({ download: true });
|
|
105465
105982
|
return resolved.binary === void 0 ? { error: resolved.diagnostics.error } : {
|
|
105466
105983
|
path: resolved.binary.path,
|
|
105467
105984
|
version: resolved.binary.version,
|