@eddyskywalker/dsh-chatgpt-subscription 0.98.1 → 0.99.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 +1 -1
- package/lib/client.js +478 -499
- package/lib/client.js.map +1 -1
- package/lib/index.js +617 -42
- package/lib/types/client/common/AccountPoolSection.d.ts +2 -0
- package/lib/types/client/common/AccountPoolSection.d.ts.map +1 -1
- package/lib/types/client/common/styles.d.ts.map +1 -1
- package/lib/types/client/features/advisor/locales.d.ts +1 -1
- package/lib/types/client/locales-ru/alibaba-token-plan.d.ts.map +1 -1
- package/lib/types/client/locales-ru/antigravity-acp.d.ts.map +1 -1
- package/lib/types/client/locales-ru/grok.d.ts.map +1 -1
- package/lib/types/client/locales-ru/longcat.d.ts.map +1 -1
- package/lib/types/client/locales-ru/opencode-zen.d.ts.map +1 -1
- package/lib/types/client/locales-ru/qianfan-token-plan.d.ts.map +1 -1
- package/lib/types/client/locales-ru/tencent-tokenhub.d.ts.map +1 -1
- package/lib/types/client/locales-ru/volcengine-ark.d.ts.map +1 -1
- package/lib/types/client/providers/alibaba-token-plan/AtpSection.d.ts.map +1 -1
- package/lib/types/client/providers/alibaba-token-plan/locales.d.ts +5 -7
- package/lib/types/client/providers/alibaba-token-plan/locales.d.ts.map +1 -1
- package/lib/types/client/providers/antigravity-acp/AntigravityAcpSection.d.ts.map +1 -1
- package/lib/types/client/providers/antigravity-acp/api.d.ts +2 -0
- package/lib/types/client/providers/antigravity-acp/api.d.ts.map +1 -1
- package/lib/types/client/providers/antigravity-acp/locales.d.ts +78 -60
- package/lib/types/client/providers/antigravity-acp/locales.d.ts.map +1 -1
- package/lib/types/client/providers/claude/locales.d.ts +24 -24
- package/lib/types/client/providers/claude-api/ClaudeApiSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/locales.d.ts +5 -7
- package/lib/types/client/providers/claude-api/locales.d.ts.map +1 -1
- package/lib/types/client/providers/cline-pass/locales.d.ts +6 -6
- package/lib/types/client/providers/codex-chatgpt/locales.d.ts +14 -14
- package/lib/types/client/providers/command-code/locales.d.ts +3 -3
- package/lib/types/client/providers/copilot/CopilotSection.d.ts.map +1 -1
- package/lib/types/client/providers/glm-coding-plan/locales.d.ts +12 -12
- package/lib/types/client/providers/grok/GrokSection.d.ts.map +1 -1
- package/lib/types/client/providers/grok/locales.d.ts +1 -3
- package/lib/types/client/providers/grok/locales.d.ts.map +1 -1
- package/lib/types/client/providers/grok/styles.d.ts.map +1 -1
- package/lib/types/client/providers/kimi-code/locales.d.ts +12 -12
- package/lib/types/client/providers/kimi-code/styles.d.ts.map +1 -1
- package/lib/types/client/providers/longcat/LongcatSection.d.ts.map +1 -1
- package/lib/types/client/providers/longcat/locales.d.ts +1 -3
- package/lib/types/client/providers/longcat/locales.d.ts.map +1 -1
- package/lib/types/client/providers/minimax-code/locales.d.ts +9 -9
- package/lib/types/client/providers/opencode-zen/OpenCodeZenSection.d.ts.map +1 -1
- package/lib/types/client/providers/opencode-zen/locales.d.ts +3 -5
- package/lib/types/client/providers/opencode-zen/locales.d.ts.map +1 -1
- package/lib/types/client/providers/opendesign/locales.d.ts +24 -24
- package/lib/types/client/providers/qianfan-token-plan/QianfanSection.d.ts.map +1 -1
- package/lib/types/client/providers/qianfan-token-plan/locales.d.ts +11 -7
- package/lib/types/client/providers/qianfan-token-plan/locales.d.ts.map +1 -1
- package/lib/types/client/providers/qianwen-token-plan/QianwenTokenPlanSection.d.ts.map +1 -1
- package/lib/types/client/providers/qianwen-token-plan/locales.d.ts +3 -5
- package/lib/types/client/providers/qianwen-token-plan/locales.d.ts.map +1 -1
- package/lib/types/client/providers/relayone/RelayOneSection.d.ts.map +1 -1
- package/lib/types/client/providers/relayone/locales.d.ts +3 -5
- package/lib/types/client/providers/relayone/locales.d.ts.map +1 -1
- package/lib/types/client/providers/step-code/locales.d.ts +24 -24
- package/lib/types/client/providers/tencent-tokenhub/TokenHubSection.d.ts.map +1 -1
- package/lib/types/client/providers/tencent-tokenhub/locales.d.ts +7 -9
- package/lib/types/client/providers/tencent-tokenhub/locales.d.ts.map +1 -1
- package/lib/types/client/providers/volcengine-ark/ArkSection.d.ts.map +1 -1
- package/lib/types/client/providers/volcengine-ark/locales.d.ts +5 -7
- package/lib/types/client/providers/volcengine-ark/locales.d.ts.map +1 -1
- package/lib/types/client/providers/workbuddy/locales.d.ts +30 -30
- package/lib/types/client/providers/xiaomi-mimo/MimoSection.d.ts.map +1 -1
- package/lib/types/client/providers/xiaomi-mimo/locales.d.ts +3 -5
- package/lib/types/client/providers/xiaomi-mimo/locales.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/host/common/i18n/en.d.ts.map +1 -1
- package/lib/types/host/common/i18n/ru.d.ts.map +1 -1
- package/lib/types/host/common/i18n/zh.d.ts +1 -0
- package/lib/types/host/common/i18n/zh.d.ts.map +1 -1
- package/lib/types/host/providers/antigravity-acp/acp-client.d.ts +18 -0
- package/lib/types/host/providers/antigravity-acp/acp-client.d.ts.map +1 -1
- package/lib/types/host/providers/antigravity-acp/adapter.d.ts +47 -5
- package/lib/types/host/providers/antigravity-acp/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/antigravity-acp/binary.d.ts +2 -2
- package/lib/types/host/providers/antigravity-acp/cooldown.d.ts +35 -0
- package/lib/types/host/providers/antigravity-acp/cooldown.d.ts.map +1 -0
- package/lib/types/host/providers/antigravity-acp/history.d.ts +17 -0
- package/lib/types/host/providers/antigravity-acp/history.d.ts.map +1 -1
- package/lib/types/host/providers/antigravity-acp/login.d.ts +22 -0
- package/lib/types/host/providers/antigravity-acp/login.d.ts.map +1 -1
- package/lib/types/host/providers/antigravity-acp/routes.d.ts +5 -0
- package/lib/types/host/providers/antigravity-acp/routes.d.ts.map +1 -1
- package/lib/types/host/providers/antigravity-acp/session-state.d.ts +73 -0
- package/lib/types/host/providers/antigravity-acp/session-state.d.ts.map +1 -0
- package/lib/types/host/providers/antigravity-acp/settings.d.ts +3 -4
- package/lib/types/host/providers/antigravity-acp/settings.d.ts.map +1 -1
- package/lib/types/host/providers/copilot/routes.d.ts.map +1 -1
- package/lib/types/host/providers/qianfan-token-plan/mapper.d.ts.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/antigravity-acp-contracts.d.ts +3 -3
- package/lib/types/shared/qianfan-token-plan-contracts.d.ts +4 -3
- package/lib/types/shared/qianfan-token-plan-contracts.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -296,6 +296,7 @@ const en = {
|
|
|
296
296
|
"antigravityAcp.notSignedIn": "Antigravity is not signed in. Start the sign-in from this card, or run agy acp --login in a terminal.",
|
|
297
297
|
"antigravityAcp.noBinary": "No usable Antigravity CLI (agy) was found and the official ACP server has not been downloaded.",
|
|
298
298
|
"antigravityAcp.nativeTool": "[Antigravity ran its own tool outside DSH permissions: {call}]\n",
|
|
299
|
+
"antigravityAcp.nativeToolDenied": "[Antigravity requested its own tool; this call will be denied and the turn continues. Use the tools DSH provides: {call}]\n",
|
|
299
300
|
"provider.qianwen-token-plan": "Qwen Token Plan",
|
|
300
301
|
"provider.copilot": "GitHub Copilot",
|
|
301
302
|
"provider.volcengine-ark": "Volcengine Ark",
|
|
@@ -478,6 +479,7 @@ const ru = {
|
|
|
478
479
|
"antigravityAcp.notSignedIn": "Вход в Antigravity не выполнен. Начните его на этой карточке или выполните agy acp --login в терминале.",
|
|
479
480
|
"antigravityAcp.noBinary": "Рабочий Antigravity CLI (agy) не найден, и официальный ACP-сервер ещё не загружен.",
|
|
480
481
|
"antigravityAcp.nativeTool": "[Antigravity использовал собственный инструмент в обход разрешений DSH: {call}]\n",
|
|
482
|
+
"antigravityAcp.nativeToolDenied": "[Antigravity запросил свой инструмент; этот вызов будет отклонён, а ход продолжится. Используйте инструменты DSH: {call}]\n",
|
|
481
483
|
"provider.qianwen-token-plan": "Qwen Token Plan",
|
|
482
484
|
"provider.copilot": "GitHub Copilot (подписка)",
|
|
483
485
|
"provider.volcengine-ark": "Volcengine Ark (Арк)",
|
|
@@ -669,6 +671,7 @@ const zh = {
|
|
|
669
671
|
"antigravityAcp.notSignedIn": "还没有登录 Antigravity:请在设置页发起登录,或在终端执行 agy acp --login。",
|
|
670
672
|
"antigravityAcp.noBinary": "未找到可用的 Antigravity CLI(agy),且官方 ACP 服务端尚未下载。",
|
|
671
673
|
"antigravityAcp.nativeTool": "[Antigravity 使用了它自带的工具,这次调用没有经过 DSH 权限:{call}]\n",
|
|
674
|
+
"antigravityAcp.nativeToolDenied": "[Antigravity 请求使用它自带的工具,本次调用将被拒绝且对话继续;请改用 DSH 提供的工具:{call}]\n",
|
|
672
675
|
"provider.qianwen-token-plan": "Qwen Token Plan(千问)",
|
|
673
676
|
"provider.copilot": "GitHub Copilot(订阅)",
|
|
674
677
|
"provider.volcengine-ark": "火山方舟(Ark 套餐)",
|
|
@@ -888,7 +891,7 @@ const ROUTE_PREFIX$6 = "/api/dsh-chatgpt-subscription";
|
|
|
888
891
|
* `test/responses-client.test.ts` asserts the two agree, so a release that
|
|
889
892
|
* forgets this constant fails the suite instead of shipping quietly.
|
|
890
893
|
*/
|
|
891
|
-
const PLUGIN_VERSION = "0.
|
|
894
|
+
const PLUGIN_VERSION = "0.99.0";
|
|
892
895
|
const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
|
|
893
896
|
const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
|
|
894
897
|
const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
|
|
@@ -26860,6 +26863,10 @@ var AcpClient = class {
|
|
|
26860
26863
|
closed = false;
|
|
26861
26864
|
stderrTail = "";
|
|
26862
26865
|
handlers;
|
|
26866
|
+
/** Whether the last initialize result advertised `sessionCapabilities.close`. */
|
|
26867
|
+
sessionClose = false;
|
|
26868
|
+
/** Whether the last initialize result advertised `sessionCapabilities.resume`. */
|
|
26869
|
+
sessionResume = false;
|
|
26863
26870
|
disposeEofGraceMs;
|
|
26864
26871
|
disposeGraceMs;
|
|
26865
26872
|
temp;
|
|
@@ -26920,6 +26927,28 @@ var AcpClient = class {
|
|
|
26920
26927
|
return !this.closed;
|
|
26921
26928
|
}
|
|
26922
26929
|
/**
|
|
26930
|
+
* Remember the capabilities an `initialize` result advertised.
|
|
26931
|
+
*
|
|
26932
|
+
* ACP requires clients to check a session capability before using its method;
|
|
26933
|
+
* a warm process reused across turns therefore keeps this bit alongside the
|
|
26934
|
+
* connection rather than letting each turn guess from the server version.
|
|
26935
|
+
*
|
|
26936
|
+
* @param value - The raw `initialize` result.
|
|
26937
|
+
*/
|
|
26938
|
+
noteAgentCapabilities(value) {
|
|
26939
|
+
const capabilities = value?.agentCapabilities?.sessionCapabilities;
|
|
26940
|
+
this.sessionClose = capabilities?.close !== void 0;
|
|
26941
|
+
this.sessionResume = capabilities?.resume !== void 0;
|
|
26942
|
+
}
|
|
26943
|
+
/** Whether this connection may be asked to close a session explicitly. */
|
|
26944
|
+
get supportsSessionClose() {
|
|
26945
|
+
return this.sessionClose;
|
|
26946
|
+
}
|
|
26947
|
+
/** Whether this connection may reconnect to an existing session without replay. */
|
|
26948
|
+
get supportsSessionResume() {
|
|
26949
|
+
return this.sessionResume;
|
|
26950
|
+
}
|
|
26951
|
+
/**
|
|
26923
26952
|
* Replace the handlers for the next turn.
|
|
26924
26953
|
*
|
|
26925
26954
|
* A warm process outlives the turn that started it, and every turn owns its own
|
|
@@ -27615,6 +27644,16 @@ const REPLAY_MESSAGE_CHARS = 12e3;
|
|
|
27615
27644
|
/** Ceiling for one copy of the request the replay answers. */
|
|
27616
27645
|
const REPLAY_REQUEST_CHARS = 3e4;
|
|
27617
27646
|
/**
|
|
27647
|
+
* UTF-8 byte budget for the text blocks in one ACP prompt.
|
|
27648
|
+
*
|
|
27649
|
+
* The official server silently drops the tail of an oversized prompt at about
|
|
27650
|
+
* 192 KB, so the client keeps a margin below that line. Inline image bytes are
|
|
27651
|
+
* governed by ACP's separate image ceiling and are not counted here.
|
|
27652
|
+
*/
|
|
27653
|
+
const ACP_MAX_PROMPT_TEXT_BYTES = 18e4;
|
|
27654
|
+
/** Notice used when an old prompt block has to be shortened. */
|
|
27655
|
+
const PROMPT_TRUNCATION_MARKER = "\n…[truncated to fit the Antigravity request budget]…\n";
|
|
27656
|
+
/**
|
|
27618
27657
|
* Build the prompt for one generation.
|
|
27619
27658
|
*
|
|
27620
27659
|
* @param options - Normalized request options.
|
|
@@ -27626,12 +27665,94 @@ function buildPrompt(options, images, fromMessage) {
|
|
|
27626
27665
|
const messages = options.messages;
|
|
27627
27666
|
const start = Math.max(0, Math.min(fromMessage, messages.length));
|
|
27628
27667
|
return {
|
|
27629
|
-
blocks: start === 0 && messages.some((message) => message.role === "assistant") ? replayBlocks(messages, images) : renderMessages(messages, messageRange(messages.length, start), images),
|
|
27668
|
+
blocks: capPromptTextBytes(start === 0 && messages.some((message) => message.role === "assistant") ? replayBlocks(messages, images) : renderMessages(messages, messageRange(messages.length, start), images)),
|
|
27630
27669
|
coveredMessages: messages.length,
|
|
27631
27670
|
fingerprint: fingerprintMessages(messages, 0, messages.length)
|
|
27632
27671
|
};
|
|
27633
27672
|
}
|
|
27634
27673
|
/**
|
|
27674
|
+
* Keep the UTF-8 text budget below the official server's silent cut-off.
|
|
27675
|
+
*
|
|
27676
|
+
* The first block and the request tail are protected while older middle blocks
|
|
27677
|
+
* are discarded. If a protected block is still too large, it is shortened from
|
|
27678
|
+
* the middle so the newest request remains identifiable. Images are left alone:
|
|
27679
|
+
* ACP has a separate image ceiling for them.
|
|
27680
|
+
*/
|
|
27681
|
+
function capPromptTextBytes(blocks, maxBytes = ACP_MAX_PROMPT_TEXT_BYTES) {
|
|
27682
|
+
const next = blocks.map((block) => block.type === "text" ? { ...block } : block);
|
|
27683
|
+
let total = promptTextBytes(next);
|
|
27684
|
+
if (total <= maxBytes) return next;
|
|
27685
|
+
let protectedFrom = next.length - 1;
|
|
27686
|
+
for (let index = next.length - 1; index >= 0; index -= 1) {
|
|
27687
|
+
const block = next[index];
|
|
27688
|
+
if (block?.type !== "text") continue;
|
|
27689
|
+
if (block.text.includes("[current human request]") || block.text === REPLAY_ANCHOR_INSTRUCTION) {
|
|
27690
|
+
protectedFrom = index;
|
|
27691
|
+
break;
|
|
27692
|
+
}
|
|
27693
|
+
}
|
|
27694
|
+
const keep = next.map(() => true);
|
|
27695
|
+
for (let index = 1; index < protectedFrom && total > maxBytes; index += 1) {
|
|
27696
|
+
const block = next[index];
|
|
27697
|
+
if (block?.type !== "text") continue;
|
|
27698
|
+
total -= promptBlockBytes(block);
|
|
27699
|
+
keep[index] = false;
|
|
27700
|
+
}
|
|
27701
|
+
let result = next.filter((_, index) => keep[index]);
|
|
27702
|
+
total = promptTextBytes(result);
|
|
27703
|
+
while (total > maxBytes) {
|
|
27704
|
+
let largestIndex = -1;
|
|
27705
|
+
let largestBytes = -1;
|
|
27706
|
+
for (let index = 0; index < result.length; index += 1) {
|
|
27707
|
+
const block = result[index];
|
|
27708
|
+
if (block?.type !== "text") continue;
|
|
27709
|
+
const bytes = promptBlockBytes(block);
|
|
27710
|
+
if (bytes > largestBytes) {
|
|
27711
|
+
largestBytes = bytes;
|
|
27712
|
+
largestIndex = index;
|
|
27713
|
+
}
|
|
27714
|
+
}
|
|
27715
|
+
if (largestIndex < 0) break;
|
|
27716
|
+
const block = result[largestIndex];
|
|
27717
|
+
if (block?.type !== "text") break;
|
|
27718
|
+
const target = Math.max(0, largestBytes - (total - maxBytes));
|
|
27719
|
+
block.text = truncateUtf8(block.text, target);
|
|
27720
|
+
total = promptTextBytes(result);
|
|
27721
|
+
}
|
|
27722
|
+
result = result.filter((block) => block.type !== "text" || block.text !== "");
|
|
27723
|
+
return result;
|
|
27724
|
+
}
|
|
27725
|
+
function promptTextBytes(blocks) {
|
|
27726
|
+
let total = 0;
|
|
27727
|
+
for (const block of blocks) {
|
|
27728
|
+
if (block.type !== "text") continue;
|
|
27729
|
+
total += promptBlockBytes(block);
|
|
27730
|
+
}
|
|
27731
|
+
return total;
|
|
27732
|
+
}
|
|
27733
|
+
function promptBlockBytes(block) {
|
|
27734
|
+
return Buffer.byteLength(JSON.stringify(block), "utf8");
|
|
27735
|
+
}
|
|
27736
|
+
/** Shorten one UTF-8 string from the middle without crossing the byte budget. */
|
|
27737
|
+
function truncateUtf8(text, maxBytes) {
|
|
27738
|
+
if (maxBytes <= 0) return "";
|
|
27739
|
+
const bytes = Buffer.from(text, "utf8");
|
|
27740
|
+
if (bytes.length <= maxBytes) return text;
|
|
27741
|
+
const markerBytes = Buffer.byteLength(PROMPT_TRUNCATION_MARKER, "utf8");
|
|
27742
|
+
if (maxBytes <= markerBytes) return "";
|
|
27743
|
+
let body = maxBytes - markerBytes;
|
|
27744
|
+
let result = "";
|
|
27745
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
27746
|
+
const head = Math.floor(body * .6);
|
|
27747
|
+
const tail = Math.max(0, body - head);
|
|
27748
|
+
result = `${bytes.subarray(0, head).toString("utf8")}${PROMPT_TRUNCATION_MARKER}${bytes.subarray(bytes.length - tail).toString("utf8")}`;
|
|
27749
|
+
const over = Buffer.byteLength(result, "utf8") - maxBytes;
|
|
27750
|
+
if (over <= 0) return result;
|
|
27751
|
+
body = Math.max(0, body - Math.max(16, over));
|
|
27752
|
+
}
|
|
27753
|
+
return "";
|
|
27754
|
+
}
|
|
27755
|
+
/**
|
|
27635
27756
|
* Digest over a message range.
|
|
27636
27757
|
*
|
|
27637
27758
|
* Only the parts the model can see take part: role, block type and payload. Ids
|
|
@@ -28336,9 +28457,20 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28336
28457
|
stream(options) {
|
|
28337
28458
|
return wrapStreamWithWatchdog((watchdogSignal, activity) => this.runAsIterable(options, watchdogSignal, activity), options.signal, ACP_STREAM_IDLE_TIMEOUT_MS, STREAM_IDLE_TIMEOUT_CODE$6, PROVIDER_NAME$23, ACP_FIRST_OUTPUT_TIMEOUT_MS);
|
|
28338
28459
|
}
|
|
28460
|
+
/**
|
|
28461
|
+
* Drop every parked conversation without interrupting a live answer.
|
|
28462
|
+
*
|
|
28463
|
+
* Used after an account change or sign-out: the old ACP session must not be
|
|
28464
|
+
* reused by the next message. In-flight turns finish but are no longer
|
|
28465
|
+
* parkable, so they cannot write a fresh pointer behind the reset.
|
|
28466
|
+
*/
|
|
28467
|
+
async forgetConversations() {
|
|
28468
|
+
for (const entry of [...this.dormant.values()]) await this.closeDormant(entry);
|
|
28469
|
+
for (const turn of this.live.values()) turn.parkable = false;
|
|
28470
|
+
}
|
|
28339
28471
|
/** Close every process this adapter owns. */
|
|
28340
28472
|
async dispose() {
|
|
28341
|
-
for (const entry of [...this.dormant.values()]) await this.closeDormant(entry);
|
|
28473
|
+
for (const entry of [...this.dormant.values()]) await this.closeDormant(entry, true);
|
|
28342
28474
|
for (const turn of [...this.live.values()]) {
|
|
28343
28475
|
if (this.live.get(turn.dshSessionId) === turn) this.live.delete(turn.dshSessionId);
|
|
28344
28476
|
turn.closed = true;
|
|
@@ -28362,7 +28494,17 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28362
28494
|
* not as an empty answer.
|
|
28363
28495
|
*/
|
|
28364
28496
|
async *runAsIterable(options, signal, activity) {
|
|
28365
|
-
|
|
28497
|
+
const cooldown = this.options.cooldown;
|
|
28498
|
+
if (cooldown !== void 0) {
|
|
28499
|
+
const remaining = await cooldown.remaining().catch(() => 0);
|
|
28500
|
+
if (remaining > 0) throw acpError("ACP_UPSTREAM_BLOCKED", `A previous upstream refusal is cooling down for another ${Math.ceil(remaining / 1e3)}s.`);
|
|
28501
|
+
}
|
|
28502
|
+
try {
|
|
28503
|
+
yield* await this.run(options, signal, activity);
|
|
28504
|
+
} catch (error) {
|
|
28505
|
+
if (isUpstreamBlocked(error)) await cooldown?.block().catch(() => void 0);
|
|
28506
|
+
throw error;
|
|
28507
|
+
}
|
|
28366
28508
|
}
|
|
28367
28509
|
async run(rawOptions, signal, activity) {
|
|
28368
28510
|
const options = this.effortMemory.follow(normalizeGenerateOptions(rawOptions));
|
|
@@ -28378,10 +28520,17 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28378
28520
|
if (live !== void 0) await this.closeTurn(live);
|
|
28379
28521
|
}
|
|
28380
28522
|
const dormant = auxiliary ? void 0 : this.dormant.get(dshSessionId);
|
|
28523
|
+
let dormantAttemptFailed = false;
|
|
28381
28524
|
if (dormant !== void 0) if (this.usableDormant(dormant, options)) {
|
|
28382
28525
|
const resumed = await this.resumeDormant(dormant, options, settings, effort, images, signal, activity);
|
|
28383
28526
|
if (resumed !== void 0) return resumed;
|
|
28527
|
+
dormantAttemptFailed = true;
|
|
28384
28528
|
} else await this.closeDormant(dormant);
|
|
28529
|
+
const persisted = auxiliary || dormantAttemptFailed ? void 0 : await this.options.sessionState?.read(dshSessionId).catch(() => void 0);
|
|
28530
|
+
if (persisted !== void 0) if (this.usablePersisted(persisted, options)) {
|
|
28531
|
+
const resumed = await this.resumePersisted(persisted, dshSessionId, options, settings, effort, images, signal, activity);
|
|
28532
|
+
if (resumed !== void 0) return resumed;
|
|
28533
|
+
} else await this.options.sessionState?.delete(dshSessionId).catch(() => void 0);
|
|
28385
28534
|
return this.startTurn(dshSessionId, options, settings, images, effort, signal, activity, !auxiliary);
|
|
28386
28535
|
}
|
|
28387
28536
|
/** Start a fresh ACP session for one generation and stream its answer. */
|
|
@@ -28442,7 +28591,95 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28442
28591
|
throw asLlmError(error);
|
|
28443
28592
|
}
|
|
28444
28593
|
}
|
|
28445
|
-
/**
|
|
28594
|
+
/** Whether a durable pointer still describes this conversation. */
|
|
28595
|
+
usablePersisted(entry, options) {
|
|
28596
|
+
if (entry.cwd !== this.cwd()) return false;
|
|
28597
|
+
if (entry.tools !== fingerprintTools(options.tools)) return false;
|
|
28598
|
+
return canContinue(options.messages, entry.covered, entry.fingerprint);
|
|
28599
|
+
}
|
|
28600
|
+
/**
|
|
28601
|
+
* Reconnect to a session that outlived the process which created it.
|
|
28602
|
+
*
|
|
28603
|
+
* Officially this is `session/resume`: the server restores the conversation
|
|
28604
|
+
* without replaying it, then the new bridge is attached and only the delta is
|
|
28605
|
+
* sent. Any failure falls back to a cold session; the stale pointer is removed
|
|
28606
|
+
* so the next turn does not retry a conversation the server no longer has.
|
|
28607
|
+
*/
|
|
28608
|
+
async resumePersisted(entry, dshSessionId, options, settings, effort, images, signal, activity) {
|
|
28609
|
+
const limit = this.options.maxActiveTurns ?? 4;
|
|
28610
|
+
if (this.activeTurns >= limit) return void 0;
|
|
28611
|
+
this.activeTurns += 1;
|
|
28612
|
+
const queue = new UpdateQueue();
|
|
28613
|
+
const bridge = new McpBridge(options.tools ?? []);
|
|
28614
|
+
const binding = {};
|
|
28615
|
+
let client;
|
|
28616
|
+
try {
|
|
28617
|
+
const launch = await this.options.resolveLaunch();
|
|
28618
|
+
client = this.spawn(launch, queue, activity, binding);
|
|
28619
|
+
const descriptor = await bridge.start();
|
|
28620
|
+
const init = asRecord$19(await client.request("initialize", {
|
|
28621
|
+
protocolVersion: 1,
|
|
28622
|
+
clientCapabilities: {
|
|
28623
|
+
fs: {
|
|
28624
|
+
readTextFile: false,
|
|
28625
|
+
writeTextFile: false
|
|
28626
|
+
},
|
|
28627
|
+
terminal: false
|
|
28628
|
+
},
|
|
28629
|
+
clientInfo: {
|
|
28630
|
+
name: "dsh-chatgpt-subscription",
|
|
28631
|
+
version: "1.0.0"
|
|
28632
|
+
}
|
|
28633
|
+
}, signal));
|
|
28634
|
+
client.noteAgentCapabilities?.(init);
|
|
28635
|
+
if (client.supportsSessionResume !== true) throw new Error("The Antigravity ACP server does not advertise session resume.");
|
|
28636
|
+
const result = asRecord$19(await client.request("session/resume", {
|
|
28637
|
+
sessionId: entry.acpSessionId,
|
|
28638
|
+
cwd: this.cwd(),
|
|
28639
|
+
mcpServers: [descriptor]
|
|
28640
|
+
}, signal));
|
|
28641
|
+
const sessionId = typeof result?.sessionId === "string" ? result.sessionId : entry.acpSessionId;
|
|
28642
|
+
binding.acpSessionId = sessionId;
|
|
28643
|
+
await this.applyModelAndEffort(client, sessionId, options.model, effort);
|
|
28644
|
+
const prompt = buildPrompt(options, images, entry.covered);
|
|
28645
|
+
if ((options.tools ?? []).length > 0) prompt.blocks.unshift({
|
|
28646
|
+
type: "text",
|
|
28647
|
+
text: BRIDGE_ONLY_INSTRUCTION
|
|
28648
|
+
});
|
|
28649
|
+
const turn = {
|
|
28650
|
+
dshSessionId,
|
|
28651
|
+
client,
|
|
28652
|
+
bridge,
|
|
28653
|
+
acpSessionId: sessionId,
|
|
28654
|
+
covered: prompt.coveredMessages,
|
|
28655
|
+
fingerprint: prompt.fingerprint,
|
|
28656
|
+
model: options.model,
|
|
28657
|
+
effort,
|
|
28658
|
+
queue,
|
|
28659
|
+
settled: void 0,
|
|
28660
|
+
surfaced: /* @__PURE__ */ new Set(),
|
|
28661
|
+
notedNative: /* @__PURE__ */ new Set(),
|
|
28662
|
+
nativeToolPolicy: settings.nativeToolPolicy,
|
|
28663
|
+
startedAt: this.now(),
|
|
28664
|
+
awaitingHarness: false,
|
|
28665
|
+
sessionsUsed: 1,
|
|
28666
|
+
tools: fingerprintTools(options.tools),
|
|
28667
|
+
parkable: true,
|
|
28668
|
+
closed: false
|
|
28669
|
+
};
|
|
28670
|
+
this.live.set(dshSessionId, turn);
|
|
28671
|
+
this.sendPrompt(turn, prompt.blocks);
|
|
28672
|
+
return this.pump(turn, signal, activity);
|
|
28673
|
+
} catch {
|
|
28674
|
+
this.activeTurns = Math.max(0, this.activeTurns - 1);
|
|
28675
|
+
await bridge.close().catch(() => void 0);
|
|
28676
|
+
await client?.dispose().catch(() => void 0);
|
|
28677
|
+
await this.options.sessionState?.delete(dshSessionId).catch(() => void 0);
|
|
28678
|
+
return;
|
|
28679
|
+
}
|
|
28680
|
+
}
|
|
28681
|
+
/**
|
|
28682
|
+
* Continue the live turn after the harness executed its tools. */
|
|
28446
28683
|
continueTurn(turn, options, images, signal, activity) {
|
|
28447
28684
|
const results = collectToolResults(options.messages.slice(turn.covered), images);
|
|
28448
28685
|
for (const callId of [...turn.surfaced]) {
|
|
@@ -28565,10 +28802,9 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28565
28802
|
if (type === "tool_call" || type === "tool_call_update") {
|
|
28566
28803
|
const native = readNativeToolCall(update);
|
|
28567
28804
|
if (native !== void 0) {
|
|
28568
|
-
if (turn.nativeToolPolicy === "cancel") throw acpError("ACP_NATIVE_TOOLS_UNSUPPORTED", `Tool: ${native.name}.`);
|
|
28569
28805
|
if (type === "tool_call" && !turn.notedNative.has(native.callId)) {
|
|
28570
28806
|
turn.notedNative.add(native.callId);
|
|
28571
|
-
const note = nativeToolNote(native, readNativeToolArguments(update));
|
|
28807
|
+
const note = turn.nativeToolPolicy === "cancel" ? nativeToolDeniedNote(native, readNativeToolArguments(update)) : nativeToolNote(native, readNativeToolArguments(update));
|
|
28572
28808
|
if (textIndex === void 0) {
|
|
28573
28809
|
textIndex = nextIndex;
|
|
28574
28810
|
nextIndex += 1;
|
|
@@ -28678,9 +28914,12 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28678
28914
|
async answerPermission(params) {
|
|
28679
28915
|
const options = readPermissionOptions(params);
|
|
28680
28916
|
const answer = () => options.find((option) => option.kind === "allow_once")?.optionId ?? options.find((option) => option.kind === "allow_always")?.optionId;
|
|
28917
|
+
const deny = () => options.find((option) => option.kind === "reject_once")?.optionId ?? options.find((option) => option.kind === "reject_always")?.optionId;
|
|
28681
28918
|
const toolCall = asRecord$19(params.toolCall);
|
|
28682
28919
|
if ((typeof toolCall?.name === "string" ? toolCall.name : "").startsWith(`mcp_dsh-bridge_`)) return answer();
|
|
28683
|
-
|
|
28920
|
+
const settings = await this.options.settings.read();
|
|
28921
|
+
if (settings.nativeToolPolicy === "cancel") return deny();
|
|
28922
|
+
return settings.permissionPolicy === "allow" ? answer() : deny();
|
|
28684
28923
|
}
|
|
28685
28924
|
spawn(launch, queue, activity, binding) {
|
|
28686
28925
|
const handlers = {
|
|
@@ -28727,6 +28966,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28727
28966
|
version: "1.0.0"
|
|
28728
28967
|
}
|
|
28729
28968
|
}, options.signal));
|
|
28969
|
+
client.noteAgentCapabilities?.(init);
|
|
28730
28970
|
const authMethods = Array.isArray(init?.authMethods) ? init.authMethods.map((entry) => String(entry.id ?? "")).filter((id) => id !== "") : [];
|
|
28731
28971
|
const create = async () => {
|
|
28732
28972
|
const result = asRecord$19(await client.request("session/new", {
|
|
@@ -28949,6 +29189,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28949
29189
|
*/
|
|
28950
29190
|
async park(turn) {
|
|
28951
29191
|
turn.queue.close();
|
|
29192
|
+
await this.rememberSession(turn);
|
|
28952
29193
|
const limit = this.options.dormantSessionLimit ?? 2;
|
|
28953
29194
|
if (limit <= 0 || !turn.client.alive) {
|
|
28954
29195
|
await this.release(turn);
|
|
@@ -28970,7 +29211,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28970
29211
|
timer: void 0
|
|
28971
29212
|
};
|
|
28972
29213
|
const timer = setTimeout(() => {
|
|
28973
|
-
this.closeDormant(entry);
|
|
29214
|
+
this.closeDormant(entry, true);
|
|
28974
29215
|
}, this.options.dormantSessionTimeoutMs ?? 3e5);
|
|
28975
29216
|
timer.unref?.();
|
|
28976
29217
|
entry.timer = timer;
|
|
@@ -28978,21 +29219,44 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
28978
29219
|
while (this.dormant.size > limit) {
|
|
28979
29220
|
const oldest = this.dormant.values().next().value;
|
|
28980
29221
|
if (oldest === void 0) break;
|
|
28981
|
-
await this.closeDormant(oldest);
|
|
29222
|
+
await this.closeDormant(oldest, true);
|
|
28982
29223
|
}
|
|
28983
29224
|
}
|
|
28984
29225
|
/**
|
|
29226
|
+
* Remember the completed conversation for the next host process.
|
|
29227
|
+
*
|
|
29228
|
+
* Only a parkable turn is stored: auxiliary title/compaction requests carry a
|
|
29229
|
+
* different history and must never replace the user's conversation pointer.
|
|
29230
|
+
*/
|
|
29231
|
+
async rememberSession(turn) {
|
|
29232
|
+
if (!turn.parkable || turn.client.supportsSessionResume !== true) return;
|
|
29233
|
+
await this.options.sessionState?.write(turn.dshSessionId, {
|
|
29234
|
+
acpSessionId: turn.acpSessionId,
|
|
29235
|
+
cwd: this.cwd(),
|
|
29236
|
+
covered: turn.covered,
|
|
29237
|
+
fingerprint: turn.fingerprint,
|
|
29238
|
+
tools: turn.tools,
|
|
29239
|
+
model: turn.model,
|
|
29240
|
+
...turn.effort === void 0 ? {} : { effort: turn.effort }
|
|
29241
|
+
}).catch(() => void 0);
|
|
29242
|
+
}
|
|
29243
|
+
/**
|
|
28985
29244
|
* Drop a parked session and hand its process back to the pool.
|
|
28986
29245
|
*
|
|
28987
|
-
* The conversation
|
|
28988
|
-
*
|
|
28989
|
-
*
|
|
28990
|
-
*
|
|
29246
|
+
* The conversation is closed with `session/close` when the agent advertises
|
|
29247
|
+
* that capability, then its process is pooled or disposed. The optional request
|
|
29248
|
+
* is bounded so an older or wedged server cannot hold a protocol slot open; the
|
|
29249
|
+
* next turn opens a fresh conversation on the same warm process. `preserve` is
|
|
29250
|
+
* used only by adapter shutdown, where the durable pointer must outlive this
|
|
28991
29251
|
* process.
|
|
28992
29252
|
*/
|
|
28993
|
-
async closeDormant(entry) {
|
|
29253
|
+
async closeDormant(entry, preserve = false) {
|
|
28994
29254
|
if (this.dormant.get(entry.dshSessionId) === entry) this.dormant.delete(entry.dshSessionId);
|
|
28995
29255
|
if (entry.timer !== void 0) clearTimeout(entry.timer);
|
|
29256
|
+
if (!preserve) {
|
|
29257
|
+
await this.closeAcpSession(entry.client, entry.acpSessionId);
|
|
29258
|
+
await this.options.sessionState?.delete(entry.dshSessionId).catch(() => void 0);
|
|
29259
|
+
}
|
|
28996
29260
|
await this.release({
|
|
28997
29261
|
client: entry.client,
|
|
28998
29262
|
bridge: entry.bridge,
|
|
@@ -29000,6 +29264,24 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
29000
29264
|
});
|
|
29001
29265
|
}
|
|
29002
29266
|
/**
|
|
29267
|
+
* Release one ACP session before its process is pooled or disposed.
|
|
29268
|
+
*
|
|
29269
|
+
* Official servers advertise `sessionCapabilities.close`; older ones do not,
|
|
29270
|
+
* and the ACP specification forbids calling the method without that bit. The
|
|
29271
|
+
* short abort keeps a wedged optional request from occupying a protocol slot.
|
|
29272
|
+
*/
|
|
29273
|
+
async closeAcpSession(client, acpSessionId) {
|
|
29274
|
+
if (!client.alive || !client.supportsSessionClose) return;
|
|
29275
|
+
const abort = new AbortController();
|
|
29276
|
+
const timer = setTimeout(() => abort.abort(), 2e3);
|
|
29277
|
+
timer.unref?.();
|
|
29278
|
+
try {
|
|
29279
|
+
await client.request("session/close", { sessionId: acpSessionId }, abort.signal);
|
|
29280
|
+
} catch {} finally {
|
|
29281
|
+
clearTimeout(timer);
|
|
29282
|
+
}
|
|
29283
|
+
}
|
|
29284
|
+
/**
|
|
29003
29285
|
* Take one warm process out of the pool.
|
|
29004
29286
|
*
|
|
29005
29287
|
* A process that has opened its session budget is disposed here rather than
|
|
@@ -29201,6 +29483,10 @@ function readNativeToolCall(update) {
|
|
|
29201
29483
|
function nativeToolNote(native, args) {
|
|
29202
29484
|
return t("antigravityAcp.nativeTool", { call: args === "" ? native.name : `${native.name} ${args}` });
|
|
29203
29485
|
}
|
|
29486
|
+
/** One visible note for a native call this client will reject, without ending the turn. */
|
|
29487
|
+
function nativeToolDeniedNote(native, args) {
|
|
29488
|
+
return t("antigravityAcp.nativeToolDenied", { call: args === "" ? native.name : `${native.name} ${args}` });
|
|
29489
|
+
}
|
|
29204
29490
|
/**
|
|
29205
29491
|
* The raw argument text one native call was reported with.
|
|
29206
29492
|
*
|
|
@@ -29355,6 +29641,9 @@ function ownsSession(binding, sessionId) {
|
|
|
29355
29641
|
if (binding.acpSessionId === void 0) return false;
|
|
29356
29642
|
return sessionId === binding.acpSessionId;
|
|
29357
29643
|
}
|
|
29644
|
+
function isUpstreamBlocked(error) {
|
|
29645
|
+
return typeof error === "object" && error !== null && error.code === "ACP_UPSTREAM_BLOCKED";
|
|
29646
|
+
}
|
|
29358
29647
|
function asLlmError(error) {
|
|
29359
29648
|
if (error instanceof LlmError) return error;
|
|
29360
29649
|
if (error instanceof Error && error.name === "AbortError") return new LlmError("The Antigravity ACP turn was cancelled.", "ABORTED");
|
|
@@ -29415,7 +29704,7 @@ function defaultAntigravityAcpSettings() {
|
|
|
29415
29704
|
enabledModelIds: null,
|
|
29416
29705
|
defaultReasoningEffort: null,
|
|
29417
29706
|
permissionPolicy: "allow",
|
|
29418
|
-
nativeToolPolicy: "
|
|
29707
|
+
nativeToolPolicy: "cancel",
|
|
29419
29708
|
binaryPath: null
|
|
29420
29709
|
};
|
|
29421
29710
|
}
|
|
@@ -29441,7 +29730,7 @@ function parseAntigravityAcpSettings(value) {
|
|
|
29441
29730
|
enabledModelIds,
|
|
29442
29731
|
defaultReasoningEffort: typeof record.defaultReasoningEffort === "string" ? record.defaultReasoningEffort : null,
|
|
29443
29732
|
permissionPolicy: record.permissionPolicy === "reject" ? "reject" : "allow",
|
|
29444
|
-
nativeToolPolicy: record.nativeToolPolicy === "
|
|
29733
|
+
nativeToolPolicy: record.nativeToolPolicy === "allow" ? "allow" : "cancel",
|
|
29445
29734
|
binaryPath: typeof record.binaryPath === "string" && record.binaryPath !== "" ? record.binaryPath : null,
|
|
29446
29735
|
...typeof record.lastTurnAt === "number" && Number.isFinite(record.lastTurnAt) ? { lastTurnAt: record.lastTurnAt } : {}
|
|
29447
29736
|
};
|
|
@@ -29508,6 +29797,202 @@ var AntigravityAcpSettingsStore = class {
|
|
|
29508
29797
|
return next;
|
|
29509
29798
|
}
|
|
29510
29799
|
};
|
|
29800
|
+
/** Where the durable session pointers live. */
|
|
29801
|
+
function antigravityAcpSessionStatePath() {
|
|
29802
|
+
return path.join(dshHomeDir(), "storages", "antigravity-acp-sessions.json");
|
|
29803
|
+
}
|
|
29804
|
+
/**
|
|
29805
|
+
* File-backed session pointers.
|
|
29806
|
+
*
|
|
29807
|
+
* Writes are serialized so two completed turns cannot lose each other's update,
|
|
29808
|
+
* and each replacement is atomic. Expired or corrupt entries are ignored rather
|
|
29809
|
+
* than becoming a reason to fail a generation.
|
|
29810
|
+
*/
|
|
29811
|
+
var AntigravityAcpSessionStateStore = class {
|
|
29812
|
+
filePath;
|
|
29813
|
+
now;
|
|
29814
|
+
cache = null;
|
|
29815
|
+
loading = null;
|
|
29816
|
+
writes = Promise.resolve();
|
|
29817
|
+
constructor(filePath = antigravityAcpSessionStatePath(), now = Date.now) {
|
|
29818
|
+
this.filePath = filePath;
|
|
29819
|
+
this.now = now;
|
|
29820
|
+
}
|
|
29821
|
+
async read(dshSessionId) {
|
|
29822
|
+
const ref = (await this.all())[dshSessionId];
|
|
29823
|
+
if (ref === void 0) return void 0;
|
|
29824
|
+
if (this.now() - ref.updatedAt > 6048e5) {
|
|
29825
|
+
this.delete(dshSessionId).catch(() => void 0);
|
|
29826
|
+
return;
|
|
29827
|
+
}
|
|
29828
|
+
return ref;
|
|
29829
|
+
}
|
|
29830
|
+
async write(dshSessionId, ref) {
|
|
29831
|
+
await this.enqueue(async () => {
|
|
29832
|
+
const sessions = await this.all();
|
|
29833
|
+
sessions[dshSessionId] = {
|
|
29834
|
+
...ref,
|
|
29835
|
+
updatedAt: this.now()
|
|
29836
|
+
};
|
|
29837
|
+
this.prune(sessions);
|
|
29838
|
+
await this.persist(sessions);
|
|
29839
|
+
});
|
|
29840
|
+
}
|
|
29841
|
+
async delete(dshSessionId) {
|
|
29842
|
+
await this.enqueue(async () => {
|
|
29843
|
+
const sessions = await this.all();
|
|
29844
|
+
if (sessions[dshSessionId] === void 0) return;
|
|
29845
|
+
delete sessions[dshSessionId];
|
|
29846
|
+
await this.persist(sessions);
|
|
29847
|
+
});
|
|
29848
|
+
}
|
|
29849
|
+
async clear() {
|
|
29850
|
+
await this.enqueue(async () => {
|
|
29851
|
+
await this.persist(Object.create(null));
|
|
29852
|
+
});
|
|
29853
|
+
}
|
|
29854
|
+
async enqueue(work) {
|
|
29855
|
+
const next = this.writes.then(work, work);
|
|
29856
|
+
this.writes = next.catch(() => void 0);
|
|
29857
|
+
return next;
|
|
29858
|
+
}
|
|
29859
|
+
async all() {
|
|
29860
|
+
if (this.cache !== null) return this.cache;
|
|
29861
|
+
if (this.loading !== null) return this.loading;
|
|
29862
|
+
this.loading = this.load().finally(() => {
|
|
29863
|
+
this.loading = null;
|
|
29864
|
+
});
|
|
29865
|
+
return this.loading;
|
|
29866
|
+
}
|
|
29867
|
+
async load() {
|
|
29868
|
+
const sessions = Object.create(null);
|
|
29869
|
+
try {
|
|
29870
|
+
const parsed = JSON.parse(await fs.readFile(this.filePath, "utf8"));
|
|
29871
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return sessions;
|
|
29872
|
+
const root = parsed;
|
|
29873
|
+
if (root.version !== 1) return sessions;
|
|
29874
|
+
const stored = root.sessions;
|
|
29875
|
+
if (typeof stored !== "object" || stored === null || Array.isArray(stored)) return sessions;
|
|
29876
|
+
for (const [dshSessionId, value] of Object.entries(stored)) {
|
|
29877
|
+
const ref = parseRef(value, this.now());
|
|
29878
|
+
if (ref !== void 0) sessions[dshSessionId] = ref;
|
|
29879
|
+
}
|
|
29880
|
+
} catch {}
|
|
29881
|
+
this.cache = sessions;
|
|
29882
|
+
return sessions;
|
|
29883
|
+
}
|
|
29884
|
+
async persist(sessions) {
|
|
29885
|
+
await fs.mkdir(path.dirname(this.filePath), { recursive: true });
|
|
29886
|
+
const temp = `${this.filePath}.tmp.${process.pid}.${this.now()}`;
|
|
29887
|
+
const body = JSON.stringify({
|
|
29888
|
+
version: 1,
|
|
29889
|
+
sessions
|
|
29890
|
+
}, null, 2);
|
|
29891
|
+
await fs.writeFile(temp, body, "utf8");
|
|
29892
|
+
await fs.rename(temp, this.filePath);
|
|
29893
|
+
this.cache = sessions;
|
|
29894
|
+
}
|
|
29895
|
+
prune(sessions) {
|
|
29896
|
+
const entries = Object.entries(sessions);
|
|
29897
|
+
if (entries.length <= 64) return;
|
|
29898
|
+
entries.sort((left, right) => left[1].updatedAt - right[1].updatedAt).slice(0, entries.length - 64).forEach(([dshSessionId]) => {
|
|
29899
|
+
delete sessions[dshSessionId];
|
|
29900
|
+
});
|
|
29901
|
+
}
|
|
29902
|
+
};
|
|
29903
|
+
function parseRef(value, now) {
|
|
29904
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
29905
|
+
const record = value;
|
|
29906
|
+
if (typeof record.acpSessionId !== "string" || record.acpSessionId === "") return void 0;
|
|
29907
|
+
if (typeof record.cwd !== "string" || record.cwd === "") return void 0;
|
|
29908
|
+
if (typeof record.covered !== "number" || !Number.isInteger(record.covered) || record.covered < 0) return void 0;
|
|
29909
|
+
if (typeof record.fingerprint !== "string" || record.fingerprint === "") return void 0;
|
|
29910
|
+
if (typeof record.tools !== "string" || record.tools === "") return void 0;
|
|
29911
|
+
if (typeof record.model !== "string" || record.model === "") return void 0;
|
|
29912
|
+
if (typeof record.updatedAt !== "number" || !Number.isFinite(record.updatedAt)) return void 0;
|
|
29913
|
+
if (now - record.updatedAt > 6048e5) return void 0;
|
|
29914
|
+
return {
|
|
29915
|
+
acpSessionId: record.acpSessionId,
|
|
29916
|
+
cwd: record.cwd,
|
|
29917
|
+
covered: record.covered,
|
|
29918
|
+
fingerprint: record.fingerprint,
|
|
29919
|
+
tools: record.tools,
|
|
29920
|
+
model: record.model,
|
|
29921
|
+
...typeof record.effort === "string" && record.effort !== "" ? { effort: record.effort } : {},
|
|
29922
|
+
updatedAt: record.updatedAt
|
|
29923
|
+
};
|
|
29924
|
+
}
|
|
29925
|
+
//#endregion
|
|
29926
|
+
//#region src/host/providers/antigravity-acp/cooldown.ts
|
|
29927
|
+
/**
|
|
29928
|
+
* A short, durable cooldown after an upstream account/rate refusal.
|
|
29929
|
+
*
|
|
29930
|
+
* The point is not to retry sooner or smarter; it is to stop a user (or an
|
|
29931
|
+
* automated client) from putting the same account in front of the same wall
|
|
29932
|
+
* repeatedly. The marker is local, opaque, and contains no credentials.
|
|
29933
|
+
*
|
|
29934
|
+
* @module dsh-chatgpt-subscription/host/antigravity-acp/cooldown
|
|
29935
|
+
*/
|
|
29936
|
+
/** How long an upstream refusal suppresses new prompts. */
|
|
29937
|
+
const UPSTREAM_COOLDOWN_MS = 6e4;
|
|
29938
|
+
/** Where the cooldown marker lives. */
|
|
29939
|
+
function antigravityAcpCooldownPath() {
|
|
29940
|
+
return path.join(dshHomeDir(), "storages", "antigravity-acp-upstream-cooldown.json");
|
|
29941
|
+
}
|
|
29942
|
+
/** File-backed cooldown shared by host restarts. */
|
|
29943
|
+
var AntigravityAcpUpstreamCooldownStore = class {
|
|
29944
|
+
filePath;
|
|
29945
|
+
now;
|
|
29946
|
+
blockedUntil;
|
|
29947
|
+
loading = null;
|
|
29948
|
+
writes = Promise.resolve();
|
|
29949
|
+
constructor(filePath = antigravityAcpCooldownPath(), now = Date.now) {
|
|
29950
|
+
this.filePath = filePath;
|
|
29951
|
+
this.now = now;
|
|
29952
|
+
}
|
|
29953
|
+
async remaining() {
|
|
29954
|
+
const until = await this.read();
|
|
29955
|
+
return until === void 0 ? 0 : Math.max(0, until - this.now());
|
|
29956
|
+
}
|
|
29957
|
+
async block() {
|
|
29958
|
+
const until = this.now() + UPSTREAM_COOLDOWN_MS;
|
|
29959
|
+
this.blockedUntil = until;
|
|
29960
|
+
await this.enqueue(async () => {
|
|
29961
|
+
await fs.mkdir(path.dirname(this.filePath), { recursive: true });
|
|
29962
|
+
const temp = `${this.filePath}.tmp.${process.pid}.${this.now()}`;
|
|
29963
|
+
await fs.writeFile(temp, JSON.stringify({
|
|
29964
|
+
version: 1,
|
|
29965
|
+
blockedUntil: until
|
|
29966
|
+
}), "utf8");
|
|
29967
|
+
await fs.rename(temp, this.filePath);
|
|
29968
|
+
});
|
|
29969
|
+
}
|
|
29970
|
+
async read() {
|
|
29971
|
+
if (this.blockedUntil !== void 0) return this.blockedUntil;
|
|
29972
|
+
if (this.loading !== null) return this.loading;
|
|
29973
|
+
this.loading = this.load().finally(() => {
|
|
29974
|
+
this.loading = null;
|
|
29975
|
+
});
|
|
29976
|
+
return this.loading;
|
|
29977
|
+
}
|
|
29978
|
+
async load() {
|
|
29979
|
+
try {
|
|
29980
|
+
const parsed = JSON.parse(await fs.readFile(this.filePath, "utf8"));
|
|
29981
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
29982
|
+
const value = parsed.blockedUntil;
|
|
29983
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
29984
|
+
this.blockedUntil = value;
|
|
29985
|
+
return value;
|
|
29986
|
+
} catch {
|
|
29987
|
+
return;
|
|
29988
|
+
}
|
|
29989
|
+
}
|
|
29990
|
+
async enqueue(work) {
|
|
29991
|
+
const next = this.writes.then(work, work);
|
|
29992
|
+
this.writes = next.catch(() => void 0);
|
|
29993
|
+
return next;
|
|
29994
|
+
}
|
|
29995
|
+
};
|
|
29511
29996
|
/** Budget for one catalogue read; a hung agent must not hold the picker. */
|
|
29512
29997
|
const CATALOG_TIMEOUT_MS = 2e4;
|
|
29513
29998
|
/** The reader, with the cache it maintains. */
|
|
@@ -29732,47 +30217,47 @@ function asRecord$18(value) {
|
|
|
29732
30217
|
* The registry entry this build was verified against.
|
|
29733
30218
|
*
|
|
29734
30219
|
* Source: `https://github.com/agentclientprotocol/registry` →
|
|
29735
|
-
* `antigravity-acp/agent.json`,
|
|
30220
|
+
* `antigravity-acp/agent.json`, latest entry checked against the official Registry.
|
|
29736
30221
|
* the archive is fetched from `dl.google.com` at install time and is never
|
|
29737
30222
|
* redistributed with this package.
|
|
29738
30223
|
*/
|
|
29739
|
-
const ACP_BINARY_VERSION = "1.5.
|
|
30224
|
+
const ACP_BINARY_VERSION = "1.5.2";
|
|
29740
30225
|
/** Platform archives, keyed by `process.platform` + `process.arch`. */
|
|
29741
30226
|
const ACP_BINARY_RELEASES = {
|
|
29742
30227
|
"win32-x64": {
|
|
29743
30228
|
version: ACP_BINARY_VERSION,
|
|
29744
|
-
url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.
|
|
29745
|
-
sha256: "
|
|
30229
|
+
url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.2-windows-x86_64.zip",
|
|
30230
|
+
sha256: "5cbadd4f4df698572473d8890fc26ec2dc1724501f06e3a963941daec2bd21d6",
|
|
29746
30231
|
executable: "agy_acp_server.exe"
|
|
29747
30232
|
},
|
|
29748
30233
|
"win32-arm64": {
|
|
29749
30234
|
version: ACP_BINARY_VERSION,
|
|
29750
|
-
url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.
|
|
29751
|
-
sha256: "
|
|
30235
|
+
url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.2-windows-arm64.zip",
|
|
30236
|
+
sha256: "8a4b2ea8df2ffefae33309348752e9119d21a6d36090c0eb48631c2e8f5781ab",
|
|
29752
30237
|
executable: "agy_acp_server.exe"
|
|
29753
30238
|
},
|
|
29754
30239
|
"darwin-arm64": {
|
|
29755
30240
|
version: ACP_BINARY_VERSION,
|
|
29756
|
-
url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.
|
|
29757
|
-
sha256: "
|
|
30241
|
+
url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.2-darwin-arm64.zip",
|
|
30242
|
+
sha256: "123a16d5c40a8ac99e20f01a62b68dd860fd96b1c528dfb8eaa37ca8733d4845",
|
|
29758
30243
|
executable: "agy_acp_server.par"
|
|
29759
30244
|
},
|
|
29760
30245
|
"darwin-x64": {
|
|
29761
30246
|
version: ACP_BINARY_VERSION,
|
|
29762
|
-
url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.
|
|
29763
|
-
sha256: "
|
|
30247
|
+
url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.2-darwin-x86_64.zip",
|
|
30248
|
+
sha256: "92addb5580577b5356d35484d72d1a113d9c5312ad766bcb304983aa8e3fbb06",
|
|
29764
30249
|
executable: "agy_acp_server.par"
|
|
29765
30250
|
},
|
|
29766
30251
|
"linux-x64": {
|
|
29767
30252
|
version: ACP_BINARY_VERSION,
|
|
29768
|
-
url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.
|
|
29769
|
-
sha256: "
|
|
30253
|
+
url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.2-linux-x86_64.zip",
|
|
30254
|
+
sha256: "99dd8612450805011619d7b8447ce374c289e00549d8557f36790e1dd6256852",
|
|
29770
30255
|
executable: "agy_acp_server.par"
|
|
29771
30256
|
},
|
|
29772
30257
|
"linux-arm64": {
|
|
29773
30258
|
version: ACP_BINARY_VERSION,
|
|
29774
|
-
url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.
|
|
29775
|
-
sha256: "
|
|
30259
|
+
url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.2-linux-arm64.zip",
|
|
30260
|
+
sha256: "e729e05ef54ef0763e48900032466b47fa7c9939cde257f93ba49410ab577acb",
|
|
29776
30261
|
executable: "agy_acp_server.par"
|
|
29777
30262
|
}
|
|
29778
30263
|
};
|
|
@@ -30109,6 +30594,8 @@ const LOGIN_FAILURE_WINDOW_MS = 1e3;
|
|
|
30109
30594
|
const LOGIN_STDERR_CAP = 2e3;
|
|
30110
30595
|
/** Budget for one auth probe. */
|
|
30111
30596
|
const AUTH_PROBE_BUDGET_MS = 3e4;
|
|
30597
|
+
/** Budget for the official ACP logout request. */
|
|
30598
|
+
const LOGOUT_BUDGET_MS = 15e3;
|
|
30112
30599
|
/**
|
|
30113
30600
|
* Start the official sign-in.
|
|
30114
30601
|
*
|
|
@@ -30159,6 +30646,61 @@ async function startLogin(launch) {
|
|
|
30159
30646
|
};
|
|
30160
30647
|
}
|
|
30161
30648
|
}
|
|
30649
|
+
/**
|
|
30650
|
+
* End the official sign-in through the ACP `logout` method.
|
|
30651
|
+
*
|
|
30652
|
+
* The ACP specification allows this only after the agent advertises
|
|
30653
|
+
* `agentCapabilities.auth.logout`; older servers simply keep the terminal
|
|
30654
|
+
* instruction on the card. As with sign-in, the official process owns the
|
|
30655
|
+
* credential store and performs the erase itself.
|
|
30656
|
+
*
|
|
30657
|
+
* @param launch - The resolved executable.
|
|
30658
|
+
* @param createClient - Test seam for the ACP connection.
|
|
30659
|
+
* @returns whether the agent confirmed sign-out, and why it did not.
|
|
30660
|
+
*/
|
|
30661
|
+
async function logout(launch, createClient) {
|
|
30662
|
+
let client;
|
|
30663
|
+
try {
|
|
30664
|
+
client = createClient?.(launch) ?? new AcpClient({
|
|
30665
|
+
command: launch.command,
|
|
30666
|
+
args: launch.args,
|
|
30667
|
+
cwd: process.cwd()
|
|
30668
|
+
});
|
|
30669
|
+
if (asRecord$17(asRecord$17(asRecord$17(await client.request("initialize", {
|
|
30670
|
+
protocolVersion: 1,
|
|
30671
|
+
clientCapabilities: {
|
|
30672
|
+
fs: {
|
|
30673
|
+
readTextFile: false,
|
|
30674
|
+
writeTextFile: false
|
|
30675
|
+
},
|
|
30676
|
+
terminal: false
|
|
30677
|
+
},
|
|
30678
|
+
clientInfo: {
|
|
30679
|
+
name: "dsh-chatgpt-subscription",
|
|
30680
|
+
version: "1.0.0"
|
|
30681
|
+
}
|
|
30682
|
+
}))?.agentCapabilities)?.auth)?.logout === void 0) return {
|
|
30683
|
+
ok: false,
|
|
30684
|
+
error: "This Antigravity ACP server does not advertise ACP sign-out. Run `agy` and use /logout there."
|
|
30685
|
+
};
|
|
30686
|
+
const abort = new AbortController();
|
|
30687
|
+
const timer = setTimeout(() => abort.abort(), LOGOUT_BUDGET_MS);
|
|
30688
|
+
timer.unref?.();
|
|
30689
|
+
try {
|
|
30690
|
+
await client.request("logout", {}, abort.signal);
|
|
30691
|
+
return { ok: true };
|
|
30692
|
+
} finally {
|
|
30693
|
+
clearTimeout(timer);
|
|
30694
|
+
}
|
|
30695
|
+
} catch (error) {
|
|
30696
|
+
return {
|
|
30697
|
+
ok: false,
|
|
30698
|
+
error: error instanceof Error ? error.message : String(error)
|
|
30699
|
+
};
|
|
30700
|
+
} finally {
|
|
30701
|
+
await client?.dispose().catch(() => void 0);
|
|
30702
|
+
}
|
|
30703
|
+
}
|
|
30162
30704
|
async function startProtocolLogin(client, methodId) {
|
|
30163
30705
|
const completion = client.request("authenticate", { methodId }).then(() => ({ started: true }), (error) => ({
|
|
30164
30706
|
started: false,
|
|
@@ -30476,9 +31018,15 @@ function registerAntigravityAcpRoutes(ctx, options) {
|
|
|
30476
31018
|
ok: false,
|
|
30477
31019
|
error: "Cross-origin request rejected."
|
|
30478
31020
|
});
|
|
30479
|
-
|
|
31021
|
+
const result = await options.logout();
|
|
31022
|
+
if (!result.ok) return sendJson$23(response, 400, {
|
|
30480
31023
|
ok: false,
|
|
30481
|
-
error: "Sign-out
|
|
31024
|
+
error: result.error ?? "Sign-out could not be completed."
|
|
31025
|
+
});
|
|
31026
|
+
options.catalog.invalidate();
|
|
31027
|
+
return sendJson$23(response, 200, {
|
|
31028
|
+
ok: true,
|
|
31029
|
+
value: await readStatus(options, { fresh: true })
|
|
30482
31030
|
});
|
|
30483
31031
|
}
|
|
30484
31032
|
if (path === "usage") {
|
|
@@ -38601,7 +39149,7 @@ function registerCopilotRoutes(ctx, options) {
|
|
|
38601
39149
|
login.cancel();
|
|
38602
39150
|
return sendJson$21(response, 200, {
|
|
38603
39151
|
ok: true,
|
|
38604
|
-
value:
|
|
39152
|
+
value: await statusOf()
|
|
38605
39153
|
});
|
|
38606
39154
|
}
|
|
38607
39155
|
if (path === "settings") {
|
|
@@ -38618,11 +39166,11 @@ function registerCopilotRoutes(ctx, options) {
|
|
|
38618
39166
|
if (typeof body.defaultReasoningEffort === "string" || body.defaultReasoningEffort === null) patch.defaultReasoningEffort = body.defaultReasoningEffort;
|
|
38619
39167
|
if (typeof body.selectedAccountId === "string" || body.selectedAccountId === null) patch.selectedAccountId = body.selectedAccountId;
|
|
38620
39168
|
if (typeof body.contextWindowOverrides === "object" && body.contextWindowOverrides !== null) patch.contextWindowOverrides = body.contextWindowOverrides;
|
|
38621
|
-
|
|
39169
|
+
await settings.update(patch);
|
|
38622
39170
|
ctx.emit?.("llm/adapters-updated");
|
|
38623
39171
|
return sendJson$21(response, 200, {
|
|
38624
39172
|
ok: true,
|
|
38625
|
-
value:
|
|
39173
|
+
value: await statusOf()
|
|
38626
39174
|
});
|
|
38627
39175
|
}
|
|
38628
39176
|
if (path === "accounts") {
|
|
@@ -38650,7 +39198,7 @@ function registerCopilotRoutes(ctx, options) {
|
|
|
38650
39198
|
await accountAction(action, accountId);
|
|
38651
39199
|
return sendJson$21(response, 200, {
|
|
38652
39200
|
ok: true,
|
|
38653
|
-
value:
|
|
39201
|
+
value: await statusOf()
|
|
38654
39202
|
});
|
|
38655
39203
|
}
|
|
38656
39204
|
if (path === "accounts/refresh") {
|
|
@@ -43385,9 +43933,15 @@ const QIANFAN_DEPLOYMENT_IDS = ["personal", "team"];
|
|
|
43385
43933
|
function isQianfanDeploymentId(value) {
|
|
43386
43934
|
return value === "personal" || value === "team";
|
|
43387
43935
|
}
|
|
43388
|
-
const QIANFAN_REASONING_EFFORTS = [
|
|
43936
|
+
const QIANFAN_REASONING_EFFORTS = [
|
|
43937
|
+
"none",
|
|
43938
|
+
"low",
|
|
43939
|
+
"medium",
|
|
43940
|
+
"high",
|
|
43941
|
+
"max"
|
|
43942
|
+
];
|
|
43389
43943
|
function isQianfanReasoningEffort(value) {
|
|
43390
|
-
return value === "none" || value === "high";
|
|
43944
|
+
return value === "none" || value === "low" || value === "medium" || value === "high" || value === "max";
|
|
43391
43945
|
}
|
|
43392
43946
|
const QIANFAN_IMAGE_DETAILS = [
|
|
43393
43947
|
"low",
|
|
@@ -43889,7 +44443,7 @@ function buildQianfanChatRequest(options, images = NO_RESOLVED_IMAGES$3, setting
|
|
|
43889
44443
|
});
|
|
43890
44444
|
}
|
|
43891
44445
|
const requested = typeof options.reasoningEffort === "string" && options.reasoningEffort.trim() !== "" ? options.reasoningEffort.trim() : settings.defaultReasoningEffort;
|
|
43892
|
-
const effort = requested !== null && (requested
|
|
44446
|
+
const effort = requested !== null && isQianfanReasoningEffort(requested) ? requested : null;
|
|
43893
44447
|
const thinkingSent = effort !== null && entry.reasoningEfforts.length > 0;
|
|
43894
44448
|
return {
|
|
43895
44449
|
body: {
|
|
@@ -44536,7 +45090,7 @@ function parseSettingsPatch$9(body) {
|
|
|
44536
45090
|
patch.contextWindowOverrides = overrides;
|
|
44537
45091
|
}
|
|
44538
45092
|
if (body.defaultReasoningEffort !== void 0) {
|
|
44539
|
-
if (body.defaultReasoningEffort !== null && !isQianfanReasoningEffort(body.defaultReasoningEffort)) throw new Error("defaultReasoningEffort must be none, high or null");
|
|
45093
|
+
if (body.defaultReasoningEffort !== null && !isQianfanReasoningEffort(body.defaultReasoningEffort)) throw new Error("defaultReasoningEffort must be none, low, medium, high, max or null");
|
|
44540
45094
|
patch.defaultReasoningEffort = body.defaultReasoningEffort;
|
|
44541
45095
|
}
|
|
44542
45096
|
if (body.imageDetail !== void 0) {
|
|
@@ -141148,6 +141702,8 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
141148
141702
|
attachments: ctx.attachments
|
|
141149
141703
|
}, ollamaAccountPool);
|
|
141150
141704
|
const antigravityAcpSettings = new AntigravityAcpSettingsStore();
|
|
141705
|
+
const antigravityAcpSessionState = new AntigravityAcpSessionStateStore();
|
|
141706
|
+
const antigravityAcpCooldown = new AntigravityAcpUpstreamCooldownStore();
|
|
141151
141707
|
const antigravityAcpBinary = new AcpBinaryCache(async (options) => {
|
|
141152
141708
|
return resolveAcpBinary((await antigravityAcpSettings.read()).binaryPath, { download: options.download !== false });
|
|
141153
141709
|
});
|
|
@@ -141175,7 +141731,9 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
141175
141731
|
synced: !read.fromSnapshot
|
|
141176
141732
|
};
|
|
141177
141733
|
},
|
|
141178
|
-
attachments: ctx.attachments
|
|
141734
|
+
attachments: ctx.attachments,
|
|
141735
|
+
sessionState: antigravityAcpSessionState,
|
|
141736
|
+
cooldown: antigravityAcpCooldown
|
|
141179
141737
|
});
|
|
141180
141738
|
antigravityAcpCatalog.rehydrate().catch(() => void 0);
|
|
141181
141739
|
const antigravityAcpAuth = new AcpAuthCache(() => probeAuthWithLaunch(async () => {
|
|
@@ -141240,6 +141798,23 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
141240
141798
|
};
|
|
141241
141799
|
}
|
|
141242
141800
|
},
|
|
141801
|
+
logout: async () => {
|
|
141802
|
+
try {
|
|
141803
|
+
const result = await logout(await resolveAntigravityLaunch());
|
|
141804
|
+
if (result.ok) {
|
|
141805
|
+
antigravityAcpAuth.invalidate();
|
|
141806
|
+
antigravityAcpCatalog.invalidate();
|
|
141807
|
+
await antigravityAcpAdapter.forgetConversations().catch(() => void 0);
|
|
141808
|
+
await antigravityAcpSessionState.clear().catch(() => void 0);
|
|
141809
|
+
}
|
|
141810
|
+
return result;
|
|
141811
|
+
} catch (error) {
|
|
141812
|
+
return {
|
|
141813
|
+
ok: false,
|
|
141814
|
+
error: error instanceof Error ? error.message : String(error)
|
|
141815
|
+
};
|
|
141816
|
+
}
|
|
141817
|
+
},
|
|
141243
141818
|
auth: (options) => antigravityAcpAuth.read(options),
|
|
141244
141819
|
usage: () => antigravityAcpAdapter.usage(),
|
|
141245
141820
|
occupancy: () => antigravityAcpAdapter.occupancy(),
|