@eddyskywalker/dsh-chatgpt-subscription 0.74.1 → 0.75.1
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 +41 -1
- package/README.md +15 -10
- package/lib/client.js +14 -5
- package/lib/client.js.map +1 -1
- package/lib/index.js +776 -62
- 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 +12 -0
- 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.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/routes.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/subagent.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/host/timeline-cache-guard.d.ts +64 -0
- package/lib/types/host/timeline-cache-guard.d.ts.map +1 -0
- package/lib/types/host/tool-result-pruner-guard.d.ts.map +1 -1
- package/lib/types/index.d.ts +20 -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.
|
|
820
|
+
const PLUGIN_VERSION = "0.75.1";
|
|
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`;
|
|
@@ -25326,13 +25326,29 @@ const ACP_MAX_INLINE_IMAGE_BYTES = 12 * 1024 * 1024;
|
|
|
25326
25326
|
*/
|
|
25327
25327
|
const REPLAY_ANCHOR_INSTRUCTION = [
|
|
25328
25328
|
"[history boundary]",
|
|
25329
|
-
"Everything above this line is
|
|
25330
|
-
"
|
|
25329
|
+
"Everything above this line is archived conversation or a copy of the active request; none of it is a new task.",
|
|
25330
|
+
"Plugin recall, time snapshots and other synthetic context are not the current human request.",
|
|
25331
|
+
"When a [current human request] section follows, its quoted text is the request for this turn.",
|
|
25331
25332
|
"Do not re-run, re-answer or re-dispatch work an earlier message already asked for; completed requests are completed.",
|
|
25332
25333
|
"A short reference such as \"do that\" or \"go with A\" points at the assistant message immediately before it.",
|
|
25333
25334
|
"Model names, providers and routing mentioned in older turns describe the turn they ran on, not the one you are answering now."
|
|
25334
25335
|
].join(" ");
|
|
25335
25336
|
/**
|
|
25337
|
+
* Heading of the oldest request copy in a replay, placed right after the
|
|
25338
|
+
* instructions so the task is readable before any history is.
|
|
25339
|
+
*/
|
|
25340
|
+
const ACTIVE_REQUEST_HEADING = "[active request for this turn]";
|
|
25341
|
+
/** Heading of the newest request copy - the one this turn answers. */
|
|
25342
|
+
const CURRENT_REQUEST_HEADING = "[current human request]";
|
|
25343
|
+
/** Heading of the bounded plain-text archive a compacted replay carries. */
|
|
25344
|
+
const REPLAY_ARCHIVE_HEADING = "[archived conversation - context only]";
|
|
25345
|
+
/** Characters of older conversation a compacted replay keeps. */
|
|
25346
|
+
const REPLAY_ARCHIVE_CHARS = 6e4;
|
|
25347
|
+
/** Per-message ceiling inside that archive. */
|
|
25348
|
+
const REPLAY_MESSAGE_CHARS = 12e3;
|
|
25349
|
+
/** Ceiling for one copy of the request the replay answers. */
|
|
25350
|
+
const REPLAY_REQUEST_CHARS = 3e4;
|
|
25351
|
+
/**
|
|
25336
25352
|
* Build the prompt for one generation.
|
|
25337
25353
|
*
|
|
25338
25354
|
* @param options - Normalized request options.
|
|
@@ -25343,22 +25359,8 @@ const REPLAY_ANCHOR_INSTRUCTION = [
|
|
|
25343
25359
|
function buildPrompt(options, images, fromMessage) {
|
|
25344
25360
|
const messages = options.messages;
|
|
25345
25361
|
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
25362
|
return {
|
|
25361
|
-
blocks,
|
|
25363
|
+
blocks: start === 0 && messages.some((message) => message.role === "assistant") ? replayBlocks(messages, images) : renderMessages(messages, messageRange(messages.length, start), images),
|
|
25362
25364
|
coveredMessages: messages.length,
|
|
25363
25365
|
fingerprint: fingerprintMessages(messages, 0, messages.length)
|
|
25364
25366
|
};
|
|
@@ -25429,6 +25431,208 @@ function canContinue(messages, covered, fingerprint) {
|
|
|
25429
25431
|
if (covered <= 0 || covered >= messages.length) return false;
|
|
25430
25432
|
return fingerprintMessages(messages, 0, covered) === fingerprint;
|
|
25431
25433
|
}
|
|
25434
|
+
/** Indices of the messages a replay carries, with superseded instruction copies dropped. */
|
|
25435
|
+
function keptIndices(messages) {
|
|
25436
|
+
const newest = {
|
|
25437
|
+
system: -1,
|
|
25438
|
+
developer: -1
|
|
25439
|
+
};
|
|
25440
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
25441
|
+
const role = messages[index]?.role;
|
|
25442
|
+
if (role === "system" || role === "developer") newest[role] = index;
|
|
25443
|
+
}
|
|
25444
|
+
const kept = [];
|
|
25445
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
25446
|
+
const role = messages[index]?.role;
|
|
25447
|
+
if (role === "system" && index !== newest.system) continue;
|
|
25448
|
+
if (role === "developer" && index !== newest.developer) continue;
|
|
25449
|
+
kept.push(index);
|
|
25450
|
+
}
|
|
25451
|
+
return kept;
|
|
25452
|
+
}
|
|
25453
|
+
/** Ascending indices of one message range. */
|
|
25454
|
+
function messageRange(length, from) {
|
|
25455
|
+
const indices = [];
|
|
25456
|
+
for (let index = from; index < length; index += 1) indices.push(index);
|
|
25457
|
+
return indices;
|
|
25458
|
+
}
|
|
25459
|
+
/** Render the given messages as prompt blocks, sharing one inline-image budget. */
|
|
25460
|
+
function renderMessages(messages, indices, images) {
|
|
25461
|
+
const blocks = [];
|
|
25462
|
+
let inlineBytes = 0;
|
|
25463
|
+
const admitImage = (bytes) => {
|
|
25464
|
+
inlineBytes += bytes;
|
|
25465
|
+
return inlineBytes <= ACP_MAX_INLINE_IMAGE_BYTES;
|
|
25466
|
+
};
|
|
25467
|
+
for (const index of indices) {
|
|
25468
|
+
const message = messages[index];
|
|
25469
|
+
if (message === void 0) continue;
|
|
25470
|
+
appendMessage(blocks, message, images, admitImage);
|
|
25471
|
+
}
|
|
25472
|
+
return blocks;
|
|
25473
|
+
}
|
|
25474
|
+
/**
|
|
25475
|
+
* Whether this `user` message was injected by something other than a human.
|
|
25476
|
+
*
|
|
25477
|
+
* A message without a source kind is treated as human: older harness generations
|
|
25478
|
+
* do not stamp one, and mistaking the real request for synthetic context is worse
|
|
25479
|
+
* than the reverse.
|
|
25480
|
+
*/
|
|
25481
|
+
function isSyntheticUserMessage(message) {
|
|
25482
|
+
if (message.role !== "user") return false;
|
|
25483
|
+
const kind = message.source?.kind;
|
|
25484
|
+
return typeof kind === "string" && kind !== "user";
|
|
25485
|
+
}
|
|
25486
|
+
/** Index of the newest message a human actually wrote. */
|
|
25487
|
+
function lastHumanRequestIndex(messages) {
|
|
25488
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
25489
|
+
const message = messages[index];
|
|
25490
|
+
if (message === void 0 || message.role !== "user") continue;
|
|
25491
|
+
if (isSyntheticUserMessage(message)) continue;
|
|
25492
|
+
return index;
|
|
25493
|
+
}
|
|
25494
|
+
}
|
|
25495
|
+
/** The text one message contributes to a request quote or to the archive. */
|
|
25496
|
+
function plainTextOf$1(message) {
|
|
25497
|
+
const parts = [];
|
|
25498
|
+
for (const block of message.content) {
|
|
25499
|
+
if (block.type === "text") {
|
|
25500
|
+
if (block.text.trim() !== "") parts.push(block.text);
|
|
25501
|
+
continue;
|
|
25502
|
+
}
|
|
25503
|
+
if (block.type === "file") {
|
|
25504
|
+
const name = block.attachment.name ?? "attachment";
|
|
25505
|
+
parts.push(`[file attached: ${name}]`);
|
|
25506
|
+
}
|
|
25507
|
+
}
|
|
25508
|
+
return parts.join("\n").trim();
|
|
25509
|
+
}
|
|
25510
|
+
/** Rough rendered size of a message set; only used to pick the replay shape. */
|
|
25511
|
+
function estimateReplayChars(messages, indices) {
|
|
25512
|
+
let total = 0;
|
|
25513
|
+
for (const index of indices) {
|
|
25514
|
+
const message = messages[index];
|
|
25515
|
+
if (message === void 0) continue;
|
|
25516
|
+
for (const block of message.content) if (block.type === "text") total += block.text.length;
|
|
25517
|
+
else if (block.type === "tool-call") total += block.name.length + Math.min(block.arguments.length, 4096) + 16;
|
|
25518
|
+
else if (block.type === "tool-result") {
|
|
25519
|
+
const body = block.content.map(renderResultBlock).join("\n");
|
|
25520
|
+
total += Math.min(body.length, 8192) + 24;
|
|
25521
|
+
} else if (block.type === "image") total += 256;
|
|
25522
|
+
else if (block.type === "file") total += 64;
|
|
25523
|
+
total += 8;
|
|
25524
|
+
}
|
|
25525
|
+
return total;
|
|
25526
|
+
}
|
|
25527
|
+
/** One headed copy of the request, or nothing when the request has no text. */
|
|
25528
|
+
function requestBlock(heading, text) {
|
|
25529
|
+
return text === "" ? void 0 : {
|
|
25530
|
+
type: "text",
|
|
25531
|
+
text: `${heading}\n${text}`
|
|
25532
|
+
};
|
|
25533
|
+
}
|
|
25534
|
+
/** Whether a message belongs in the compacted archive. */
|
|
25535
|
+
function isArchivable(message) {
|
|
25536
|
+
if (message === void 0) return false;
|
|
25537
|
+
if (message.role !== "user" && message.role !== "assistant") return false;
|
|
25538
|
+
if (isSyntheticUserMessage(message)) return false;
|
|
25539
|
+
return plainTextOf$1(message) !== "";
|
|
25540
|
+
}
|
|
25541
|
+
/**
|
|
25542
|
+
* Plain-text archive entries, newest first until the budget is spent.
|
|
25543
|
+
*
|
|
25544
|
+
* Tool calls, tool results, reasoning and images stay out: they are what made the
|
|
25545
|
+
* replay unreadable, and an agent that needs their detail can read the workspace.
|
|
25546
|
+
*/
|
|
25547
|
+
function boundedArchive(messages, indices) {
|
|
25548
|
+
const entries = [];
|
|
25549
|
+
let budget = REPLAY_ARCHIVE_CHARS;
|
|
25550
|
+
let omitted = 0;
|
|
25551
|
+
for (let position = indices.length - 1; position >= 0; position -= 1) {
|
|
25552
|
+
const message = messages[indices[position] ?? -1];
|
|
25553
|
+
if (message === void 0) continue;
|
|
25554
|
+
const text = truncate(plainTextOf$1(message), REPLAY_MESSAGE_CHARS);
|
|
25555
|
+
if (text.length > budget) {
|
|
25556
|
+
omitted += 1;
|
|
25557
|
+
continue;
|
|
25558
|
+
}
|
|
25559
|
+
budget -= text.length;
|
|
25560
|
+
entries.push(`[${message.role}]\n${text}`);
|
|
25561
|
+
}
|
|
25562
|
+
return {
|
|
25563
|
+
entries: entries.reverse(),
|
|
25564
|
+
omitted
|
|
25565
|
+
};
|
|
25566
|
+
}
|
|
25567
|
+
/** The request's own images and files, which the archive does not carry. */
|
|
25568
|
+
function requestAttachments(message, images) {
|
|
25569
|
+
const blocks = [];
|
|
25570
|
+
let inlineBytes = 0;
|
|
25571
|
+
const admitImage = (bytes) => {
|
|
25572
|
+
inlineBytes += bytes;
|
|
25573
|
+
return inlineBytes <= ACP_MAX_INLINE_IMAGE_BYTES;
|
|
25574
|
+
};
|
|
25575
|
+
for (const block of message.content) {
|
|
25576
|
+
if (block.type !== "image" && block.type !== "file") continue;
|
|
25577
|
+
const rendered = renderBlock(block, images, admitImage);
|
|
25578
|
+
if (rendered === void 0) continue;
|
|
25579
|
+
blocks.push(typeof rendered === "string" ? {
|
|
25580
|
+
type: "text",
|
|
25581
|
+
text: rendered
|
|
25582
|
+
} : rendered);
|
|
25583
|
+
}
|
|
25584
|
+
return blocks;
|
|
25585
|
+
}
|
|
25586
|
+
/** Blocks for a replay of the whole history. */
|
|
25587
|
+
function replayBlocks(messages, images) {
|
|
25588
|
+
const kept = keptIndices(messages);
|
|
25589
|
+
const requestIndex = lastHumanRequestIndex(messages);
|
|
25590
|
+
const requestMessage = requestIndex === void 0 ? void 0 : messages[requestIndex];
|
|
25591
|
+
const request = requestMessage === void 0 ? "" : truncate(plainTextOf$1(requestMessage), REPLAY_REQUEST_CHARS);
|
|
25592
|
+
if (estimateReplayChars(messages, kept) <= 2e5) {
|
|
25593
|
+
const blocks = renderMessages(messages, kept, images);
|
|
25594
|
+
blocks.push({
|
|
25595
|
+
type: "text",
|
|
25596
|
+
text: REPLAY_ANCHOR_INSTRUCTION
|
|
25597
|
+
});
|
|
25598
|
+
const current = requestBlock(CURRENT_REQUEST_HEADING, request);
|
|
25599
|
+
if (current !== void 0) blocks.push(current);
|
|
25600
|
+
return blocks;
|
|
25601
|
+
}
|
|
25602
|
+
return compactReplayBlocks(messages, kept, requestIndex, requestMessage, request, images);
|
|
25603
|
+
}
|
|
25604
|
+
/** Blocks for a replay too large to send verbatim. */
|
|
25605
|
+
function compactReplayBlocks(messages, kept, requestIndex, requestMessage, request, images) {
|
|
25606
|
+
const blocks = [];
|
|
25607
|
+
const instructions = kept.filter((index) => {
|
|
25608
|
+
const role = messages[index]?.role;
|
|
25609
|
+
return role === "system" || role === "developer";
|
|
25610
|
+
});
|
|
25611
|
+
blocks.push(...renderMessages(messages, instructions, images));
|
|
25612
|
+
const active = requestBlock(ACTIVE_REQUEST_HEADING, request);
|
|
25613
|
+
if (active !== void 0) blocks.push(active);
|
|
25614
|
+
const archive = boundedArchive(messages, kept.filter((index) => (requestIndex === void 0 || index < requestIndex) && isArchivable(messages[index])));
|
|
25615
|
+
blocks.push({
|
|
25616
|
+
type: "text",
|
|
25617
|
+
text: [
|
|
25618
|
+
REPLAY_ARCHIVE_HEADING,
|
|
25619
|
+
`${archive.entries.length} earlier messages kept, ${archive.omitted} dropped for length.`,
|
|
25620
|
+
"Earlier tool calls, tool results, images and synthetic context are not replayed; re-read the workspace if an older turn needs their detail."
|
|
25621
|
+
].join("\n")
|
|
25622
|
+
});
|
|
25623
|
+
for (const entry of archive.entries) blocks.push({
|
|
25624
|
+
type: "text",
|
|
25625
|
+
text: entry
|
|
25626
|
+
});
|
|
25627
|
+
blocks.push({
|
|
25628
|
+
type: "text",
|
|
25629
|
+
text: REPLAY_ANCHOR_INSTRUCTION
|
|
25630
|
+
});
|
|
25631
|
+
const current = requestBlock(CURRENT_REQUEST_HEADING, request);
|
|
25632
|
+
if (current !== void 0) blocks.push(current);
|
|
25633
|
+
if (requestMessage !== void 0) blocks.push(...requestAttachments(requestMessage, images));
|
|
25634
|
+
return blocks;
|
|
25635
|
+
}
|
|
25432
25636
|
/** Render one message into prompt blocks. */
|
|
25433
25637
|
function appendMessage(blocks, message, images, admitImage) {
|
|
25434
25638
|
const textParts = [];
|
|
@@ -25491,6 +25695,11 @@ function decorate(message, text) {
|
|
|
25491
25695
|
if (message.role === "assistant") return `[assistant]\n${text}`;
|
|
25492
25696
|
return text;
|
|
25493
25697
|
}
|
|
25698
|
+
/** Durable id of the attachment behind one block, or an empty string. */
|
|
25699
|
+
function attachmentIdOf$1(block) {
|
|
25700
|
+
const attachment = block.attachment;
|
|
25701
|
+
return typeof attachment?.attachmentId === "string" ? attachment.attachmentId : "";
|
|
25702
|
+
}
|
|
25494
25703
|
/** Canonical text for one block, used only for the fingerprint. */
|
|
25495
25704
|
function canonicalBlock(block) {
|
|
25496
25705
|
switch (block.type) {
|
|
@@ -25498,8 +25707,8 @@ function canonicalBlock(block) {
|
|
|
25498
25707
|
case "reasoning": return `reasoning:${block.text}`;
|
|
25499
25708
|
case "tool-call": return `call:${block.name}:${block.arguments}`;
|
|
25500
25709
|
case "tool-result": return `result:${block.toolCallId}:${block.isError === true ? "1" : "0"}`;
|
|
25501
|
-
case "image": return `image:${block
|
|
25502
|
-
case "file": return `file:${block
|
|
25710
|
+
case "image": return `image:${attachmentIdOf$1(block)}`;
|
|
25711
|
+
case "file": return `file:${attachmentIdOf$1(block)}`;
|
|
25503
25712
|
default: return block.type;
|
|
25504
25713
|
}
|
|
25505
25714
|
}
|
|
@@ -25788,9 +25997,9 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25788
25997
|
return this.lastOccupancy;
|
|
25789
25998
|
}
|
|
25790
25999
|
async listModels(provider) {
|
|
25791
|
-
const view = await this.options.loadCatalog().catch(() => void 0);
|
|
25792
26000
|
const settings = await this.options.settings.read();
|
|
25793
26001
|
if (!settings.enabled) return [];
|
|
26002
|
+
const view = await this.options.loadCatalog().catch(() => void 0);
|
|
25794
26003
|
return this.visibleModels(view?.models ?? [], settings).map((model) => toModelInfo(provider, model));
|
|
25795
26004
|
}
|
|
25796
26005
|
async resolveModel(provider, model, signal) {
|
|
@@ -27543,6 +27752,7 @@ const CATALOG_FRESHNESS_MS = 1440 * 60 * 1e3;
|
|
|
27543
27752
|
/** Build the status payload the card renders. */
|
|
27544
27753
|
async function readStatus(options) {
|
|
27545
27754
|
const settings = await options.settings.read();
|
|
27755
|
+
if (!settings.enabled) return disabledStatus(settings);
|
|
27546
27756
|
const resolved = await options.resolveBinary().catch(() => ({ error: "The executable could not be resolved." }));
|
|
27547
27757
|
const catalog = await options.catalog.rehydrate();
|
|
27548
27758
|
const auth = resolved.binary === void 0 ? { authenticated: false } : await options.auth().catch(() => ({ authenticated: false }));
|
|
@@ -27571,6 +27781,32 @@ async function readStatus(options) {
|
|
|
27571
27781
|
};
|
|
27572
27782
|
}
|
|
27573
27783
|
/**
|
|
27784
|
+
* The whole status payload for a line the user switched off.
|
|
27785
|
+
*
|
|
27786
|
+
* Deliberately answered without touching the agent: the executable is not
|
|
27787
|
+
* resolved, the sign-in is not probed and the catalogue snapshot is not read, so
|
|
27788
|
+
* a disabled line costs nothing but one file read. The model rows are kept as an
|
|
27789
|
+
* empty list rather than the cached catalogue on purpose - a card that still
|
|
27790
|
+
* lists models while the line is off reads as "available but hidden", which is
|
|
27791
|
+
* exactly the claim the switch is meant to make false.
|
|
27792
|
+
*
|
|
27793
|
+
* @param settings - The line's stored preferences.
|
|
27794
|
+
* @returns A status with nothing running and the switch reported as off.
|
|
27795
|
+
*/
|
|
27796
|
+
function disabledStatus(settings) {
|
|
27797
|
+
return {
|
|
27798
|
+
enabled: false,
|
|
27799
|
+
binary: { kind: "missing" },
|
|
27800
|
+
auth: { authenticated: false },
|
|
27801
|
+
models: [],
|
|
27802
|
+
enabledModelIds: settings.enabledModelIds,
|
|
27803
|
+
defaultReasoningEffort: settings.defaultReasoningEffort,
|
|
27804
|
+
permissionPolicy: settings.permissionPolicy,
|
|
27805
|
+
nativeToolPolicy: settings.nativeToolPolicy,
|
|
27806
|
+
catalogSynced: false
|
|
27807
|
+
};
|
|
27808
|
+
}
|
|
27809
|
+
/**
|
|
27574
27810
|
* Mount every route of this line.
|
|
27575
27811
|
*
|
|
27576
27812
|
* @param ctx - Plugin context owning the web server.
|
|
@@ -27970,8 +28206,9 @@ function createProvider(options) {
|
|
|
27970
28206
|
},
|
|
27971
28207
|
inheritsParentContext: false,
|
|
27972
28208
|
async start(request) {
|
|
27973
|
-
const launch = await options.resolveLaunch();
|
|
27974
28209
|
const settings = await options.settings.read();
|
|
28210
|
+
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");
|
|
28211
|
+
const launch = await options.resolveLaunch();
|
|
27975
28212
|
const task = promptText(request.prompt);
|
|
27976
28213
|
let settled = false;
|
|
27977
28214
|
const running = startRun(launch, request.cwd, task, settings.permissionPolicy, options, request.signal);
|
|
@@ -36778,6 +37015,7 @@ function prefixFingerprints(options) {
|
|
|
36778
37015
|
*/
|
|
36779
37016
|
function trackPrefixStability(options) {
|
|
36780
37017
|
if (isSideChannelTitleRequest(options)) return "stable";
|
|
37018
|
+
if (isAuxiliaryRequest(options)) return "stable";
|
|
36781
37019
|
const { systemPromptHash, toolsHash } = prefixFingerprints(options);
|
|
36782
37020
|
const cacheKey = promptCacheKey(options) ?? null;
|
|
36783
37021
|
const scope = cacheScopeKey(options.sessionId);
|
|
@@ -36804,7 +37042,7 @@ const driftCauses = /* @__PURE__ */ new Map();
|
|
|
36804
37042
|
* prompt or on its (absent) tool list.
|
|
36805
37043
|
*/
|
|
36806
37044
|
function recordDriftCause(cause, sessionId, options) {
|
|
36807
|
-
if (options !== void 0 && isSideChannelTitleRequest(options)) return;
|
|
37045
|
+
if (options !== void 0 && (isSideChannelTitleRequest(options) || isAuxiliaryRequest(options))) return;
|
|
36808
37046
|
rememberScoped(driftCauses, cacheScopeKey(sessionId), cause);
|
|
36809
37047
|
}
|
|
36810
37048
|
/**
|
|
@@ -36977,7 +37215,8 @@ const EMPTY_CACHE_STATS = {
|
|
|
36977
37215
|
outputTokens: 0,
|
|
36978
37216
|
cacheWriteTokens: 0,
|
|
36979
37217
|
cacheWrite5mTokens: 0,
|
|
36980
|
-
cacheWrite1hTokens: 0
|
|
37218
|
+
cacheWrite1hTokens: 0,
|
|
37219
|
+
cacheWriteReported: false
|
|
36981
37220
|
};
|
|
36982
37221
|
/** Record one request's usage into its own session's totals. */
|
|
36983
37222
|
function recordCacheStats(state, sessionId, accountId) {
|
|
@@ -36992,7 +37231,8 @@ function recordCacheStats(state, sessionId, accountId) {
|
|
|
36992
37231
|
outputTokens: previous.outputTokens + state.outputTokens,
|
|
36993
37232
|
cacheWriteTokens: previous.cacheWriteTokens + state.cacheWriteTokens,
|
|
36994
37233
|
cacheWrite5mTokens: previous.cacheWrite5mTokens + state.cacheWrite5mTokens,
|
|
36995
|
-
cacheWrite1hTokens: previous.cacheWrite1hTokens + state.cacheWrite1hTokens
|
|
37234
|
+
cacheWrite1hTokens: previous.cacheWrite1hTokens + state.cacheWrite1hTokens,
|
|
37235
|
+
cacheWriteReported: previous.cacheWriteReported || state.cacheWriteReported
|
|
36996
37236
|
});
|
|
36997
37237
|
}
|
|
36998
37238
|
/** Add one entry into an accumulator. */
|
|
@@ -37004,6 +37244,7 @@ function accumulate(totals, stats) {
|
|
|
37004
37244
|
totals.cacheWriteTokens += stats.cacheWriteTokens;
|
|
37005
37245
|
totals.cacheWrite5mTokens += stats.cacheWrite5mTokens;
|
|
37006
37246
|
totals.cacheWrite1hTokens += stats.cacheWrite1hTokens;
|
|
37247
|
+
totals.cacheWriteReported = totals.cacheWriteReported || stats.cacheWriteReported;
|
|
37007
37248
|
}
|
|
37008
37249
|
/**
|
|
37009
37250
|
* Totals for one account's share of a session, one whole session, or every
|
|
@@ -37380,6 +37621,7 @@ function normalizeRecord$2(value) {
|
|
|
37380
37621
|
const lastRequestImageBytes = nonNegative(value.lastRequestImageBytes);
|
|
37381
37622
|
const lastDroppedImages = nonNegative(value.lastDroppedImages);
|
|
37382
37623
|
const recentRequests = normalizeRecentRequests(value.recentRequests);
|
|
37624
|
+
const cacheWriteReported = value.cacheWriteReported === true ? true : void 0;
|
|
37383
37625
|
return {
|
|
37384
37626
|
lastActiveAt,
|
|
37385
37627
|
updatedAt,
|
|
@@ -37391,6 +37633,7 @@ function normalizeRecord$2(value) {
|
|
|
37391
37633
|
cacheWriteTokens: count$1(value.cacheWriteTokens),
|
|
37392
37634
|
cacheWrite5mTokens: count$1(value.cacheWrite5mTokens),
|
|
37393
37635
|
cacheWrite1hTokens: count$1(value.cacheWrite1hTokens),
|
|
37636
|
+
...cacheWriteReported === void 0 ? {} : { cacheWriteReported },
|
|
37394
37637
|
...drift === void 0 ? {} : { lastDrift: drift },
|
|
37395
37638
|
...firstRequestCachedTokens === void 0 ? {} : { firstRequestCachedTokens },
|
|
37396
37639
|
...firstRequestPromptTokens === void 0 ? {} : { firstRequestPromptTokens },
|
|
@@ -38826,6 +39069,7 @@ function noteSessionCacheState(sessionId, state, successful, requestDiagnostic)
|
|
|
38826
39069
|
...priorRecord?.firstRequestCachedTokens === void 0 ? {} : { firstRequestCachedTokens: priorRecord.firstRequestCachedTokens },
|
|
38827
39070
|
...priorRecord?.firstRequestPromptTokens === void 0 ? {} : { firstRequestPromptTokens: priorRecord.firstRequestPromptTokens }
|
|
38828
39071
|
};
|
|
39072
|
+
const cacheWriteReported = stats.cacheWriteReported || priorRecord?.cacheWriteReported === true;
|
|
38829
39073
|
sessionCacheState.write(sessionId, {
|
|
38830
39074
|
lastActiveAt: now,
|
|
38831
39075
|
totalTokens: state.cacheReadTokens + state.inputTokens + state.cacheWriteTokens,
|
|
@@ -38836,6 +39080,7 @@ function noteSessionCacheState(sessionId, state, successful, requestDiagnostic)
|
|
|
38836
39080
|
cacheWriteTokens: stats.cacheWriteTokens,
|
|
38837
39081
|
cacheWrite5mTokens: stats.cacheWrite5mTokens,
|
|
38838
39082
|
cacheWrite1hTokens: stats.cacheWrite1hTokens,
|
|
39083
|
+
...cacheWriteReported ? { cacheWriteReported: true } : {},
|
|
38839
39084
|
lastRequestCachedTokens: state.cacheReadTokens,
|
|
38840
39085
|
lastRequestFreshTokens: state.inputTokens,
|
|
38841
39086
|
...accountObservation,
|
|
@@ -39140,7 +39385,8 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
39140
39385
|
async *requestStream(options, signal, activity) {
|
|
39141
39386
|
const fetchFn = this.options.fetchFn ?? fetch;
|
|
39142
39387
|
const normalized = normalizeGenerateOptions(options);
|
|
39143
|
-
const
|
|
39388
|
+
const titleSideChannel = isSideChannelTitleRequest(normalized);
|
|
39389
|
+
const sideChannel = titleSideChannel || isAuxiliaryRequest(normalized);
|
|
39144
39390
|
const sessionKey = typeof options.sessionId === "string" ? options.sessionId.trim() : "";
|
|
39145
39391
|
const retrySignal = options.signal;
|
|
39146
39392
|
const sameAccountRetryId = sideChannel || retrySignal === void 0 ? void 0 : sameAccountRetryBySignal.get(retrySignal);
|
|
@@ -39296,7 +39542,7 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
39296
39542
|
let sentImageReferenceKeys;
|
|
39297
39543
|
const pool = this.accountPool;
|
|
39298
39544
|
const tried = /* @__PURE__ */ new Set();
|
|
39299
|
-
const cacheAffinity =
|
|
39545
|
+
const cacheAffinity = titleSideChannel ? void 0 : await this.cacheAffinityHint(pool, requestOptions);
|
|
39300
39546
|
const affinity = sameAccountRetryId === void 0 ? cacheAffinity : { preferAccountIds: [.../* @__PURE__ */ new Set([sameAccountRetryId, ...cacheAffinity?.preferAccountIds ?? []])] };
|
|
39301
39547
|
let servedByAccountId;
|
|
39302
39548
|
let response;
|
|
@@ -39483,7 +39729,7 @@ var KimiCodeAdapter = class extends LlmAdapter {
|
|
|
39483
39729
|
state.accountId = servedByAccountId;
|
|
39484
39730
|
diagnosticState = state;
|
|
39485
39731
|
applyCacheWriteTiers(state, response.headers);
|
|
39486
|
-
if (!
|
|
39732
|
+
if (!titleSideChannel) markSessionActive(requestOptions.sessionId);
|
|
39487
39733
|
let buffer = "";
|
|
39488
39734
|
/**
|
|
39489
39735
|
* Set the moment ANY chunk reaches the caller, and never cleared.
|
|
@@ -40166,15 +40412,16 @@ function cacheStatsOrNull(sessionId) {
|
|
|
40166
40412
|
const opening = openingInheritanceOf(sessionId);
|
|
40167
40413
|
const continuation = continuationOf(sessionId);
|
|
40168
40414
|
const lastRequest = lastRequestDiagnosticOf(sessionId);
|
|
40415
|
+
const { cacheWriteReported, ...totals } = stats;
|
|
40169
40416
|
return {
|
|
40170
|
-
...
|
|
40417
|
+
...totals,
|
|
40171
40418
|
...lastDrift === void 0 ? {} : { lastDrift },
|
|
40172
40419
|
...warmup === void 0 ? {} : { warmup },
|
|
40173
40420
|
...opening === void 0 ? {} : { opening },
|
|
40174
40421
|
...continuation === void 0 ? {} : { continuation },
|
|
40175
40422
|
...lastRequest === void 0 ? {} : { lastRequest },
|
|
40176
40423
|
imageBudget: imageBudgetOf(sessionId),
|
|
40177
|
-
cacheWriteTokens: stats.cacheWriteTokens,
|
|
40424
|
+
cacheWriteTokens: cacheWriteReported ? stats.cacheWriteTokens : null,
|
|
40178
40425
|
cacheWrite5mTokens: stats.cacheWrite5mTokens,
|
|
40179
40426
|
cacheWrite1hTokens: stats.cacheWrite1hTokens
|
|
40180
40427
|
};
|
|
@@ -40225,7 +40472,7 @@ function durableCacheStats(sessionId) {
|
|
|
40225
40472
|
freshTokens: durable.freshTokens,
|
|
40226
40473
|
outputTokens: durable.outputTokens,
|
|
40227
40474
|
hitRatio: hitRatioOf(durable.cachedTokens, durable.freshTokens),
|
|
40228
|
-
cacheWriteTokens: durable.cacheWriteTokens,
|
|
40475
|
+
cacheWriteTokens: durable.cacheWriteReported === true ? durable.cacheWriteTokens : null,
|
|
40229
40476
|
cacheWrite5mTokens: durable.cacheWrite5mTokens,
|
|
40230
40477
|
cacheWrite1hTokens: durable.cacheWrite1hTokens,
|
|
40231
40478
|
...lastDrift === void 0 ? {} : { lastDrift },
|
|
@@ -87934,6 +88181,13 @@ function installCompactionPrompt(ctx) {
|
|
|
87934
88181
|
*
|
|
87935
88182
|
* @module @eddyskywalker/dsh-chatgpt-subscription/host/tool-result-pruner-guard
|
|
87936
88183
|
*/
|
|
88184
|
+
/**
|
|
88185
|
+
* 扫过多少次事件之后仍然一个修剪器都没包上,就点名一次。
|
|
88186
|
+
*
|
|
88187
|
+
* 只数「有事件、但一次都没成功」的轮次:装得太早的部署会在第一两步里补上,
|
|
88188
|
+
* 连着几步还包不上就不是时序问题,而是实例真的不在守卫看得见的位置。
|
|
88189
|
+
*/
|
|
88190
|
+
const INERT_WARN_AFTER_EVENTS = 3;
|
|
87937
88191
|
/** 会先跑一遍扫描的宿主事件(全部是 Cordis 瀑布事件,监听器必须转交 `next()`)。 */
|
|
87938
88192
|
const GUARDED_EVENTS$1 = [
|
|
87939
88193
|
"agent/pre-step",
|
|
@@ -87962,6 +88216,27 @@ function installToolResultPrunerGuard(ctx, options = {}) {
|
|
|
87962
88216
|
/** 事件监听的 disposer。 */
|
|
87963
88217
|
const disposers = [];
|
|
87964
88218
|
let disposed = false;
|
|
88219
|
+
/** 已经包上的实例数(含直接调用 `wrapPruner` 的外部调用)。 */
|
|
88220
|
+
let wrappedCount = 0;
|
|
88221
|
+
/** 已经跑过的事件轮次。 */
|
|
88222
|
+
let eventRounds = 0;
|
|
88223
|
+
/** 空转点名只报一次。 */
|
|
88224
|
+
let inertWarned = false;
|
|
88225
|
+
/**
|
|
88226
|
+
* 连跑几轮事件仍然一个实例都没包上时,点名一次。
|
|
88227
|
+
*
|
|
88228
|
+
* 这个守卫是纯旁路:包不上时它什么都不做、也不报错,于是部署里「修剪器在
|
|
88229
|
+
* 另一层 realm、守卫根本看不见」会静默退化成「kimi-code 的历史工具结果被修剪,
|
|
88230
|
+
* 前缀缓存每轮重建」。一条 warn 是唯一能把这种静默退化变成可诊断事实的通道。
|
|
88231
|
+
*/
|
|
88232
|
+
const warnIfInert = () => {
|
|
88233
|
+
if (inertWarned || wrappedCount > 0) return;
|
|
88234
|
+
if (eventRounds < INERT_WARN_AFTER_EVENTS) return;
|
|
88235
|
+
inertWarned = true;
|
|
88236
|
+
try {
|
|
88237
|
+
host?.logger?.warn?.("[dsh-chatgpt-subscription] tool result pruner guard has wrapped no pruner after " + eventRounds + " agent events; prefix-cache pruning skip is inert on this deployment");
|
|
88238
|
+
} catch {}
|
|
88239
|
+
};
|
|
87965
88240
|
/**
|
|
87966
88241
|
* 把一个修剪器实例的 `pruneSession` 包上 provider 短路。
|
|
87967
88242
|
*
|
|
@@ -87988,6 +88263,7 @@ function installToolResultPrunerGuard(ctx, options = {}) {
|
|
|
87988
88263
|
if (!installMethod$4(target, replacement)) return false;
|
|
87989
88264
|
markPatched$4(patchedMethods, target.holder, target.name);
|
|
87990
88265
|
alreadyWrapped.add(pruner);
|
|
88266
|
+
wrappedCount += 1;
|
|
87991
88267
|
restores.push(() => {
|
|
87992
88268
|
restoreMethod$4(target);
|
|
87993
88269
|
});
|
|
@@ -88073,6 +88349,7 @@ function installToolResultPrunerGuard(ctx, options = {}) {
|
|
|
88073
88349
|
*/
|
|
88074
88350
|
const handleAgentEvent = (...args) => {
|
|
88075
88351
|
const next = args.length > 0 && typeof args[args.length - 1] === "function" ? args[args.length - 1] : void 0;
|
|
88352
|
+
eventRounds += 1;
|
|
88076
88353
|
try {
|
|
88077
88354
|
scanAndWrap();
|
|
88078
88355
|
const agentCtx = findAgentContext$1(args);
|
|
@@ -88081,10 +88358,11 @@ function installToolResultPrunerGuard(ctx, options = {}) {
|
|
|
88081
88358
|
wrapServiceFrom(agentCtx, PRUNER_SERVICE_NAME);
|
|
88082
88359
|
}
|
|
88083
88360
|
} catch {}
|
|
88361
|
+
warnIfInert();
|
|
88084
88362
|
return next === void 0 ? void 0 : next();
|
|
88085
88363
|
};
|
|
88086
88364
|
for (const event of GUARDED_EVENTS$1) {
|
|
88087
|
-
const disposer = subscribe$
|
|
88365
|
+
const disposer = subscribe$5(host, event, handleAgentEvent);
|
|
88088
88366
|
if (disposer !== void 0) disposers.push(disposer);
|
|
88089
88367
|
}
|
|
88090
88368
|
scanAndWrap();
|
|
@@ -88114,7 +88392,7 @@ function installToolResultPrunerGuard(ctx, options = {}) {
|
|
|
88114
88392
|
* @param listener - 回调。
|
|
88115
88393
|
* @returns 移除监听器的 disposer;宿主不支持事件时为 `undefined`。
|
|
88116
88394
|
*/
|
|
88117
|
-
function subscribe$
|
|
88395
|
+
function subscribe$5(host, event, listener) {
|
|
88118
88396
|
const on = host?.on;
|
|
88119
88397
|
if (typeof on !== "function") return void 0;
|
|
88120
88398
|
for (const options of [
|
|
@@ -88291,7 +88569,7 @@ function markPatched$4(patched, holder, name) {
|
|
|
88291
88569
|
//#endregion
|
|
88292
88570
|
//#region src/host/plan-mode-cache-guard.ts
|
|
88293
88571
|
/** 没有 scope 的装配(会话标题之类)用的桶键。 */
|
|
88294
|
-
const GLOBAL_KEY$
|
|
88572
|
+
const GLOBAL_KEY$3 = Object.freeze({});
|
|
88295
88573
|
/**
|
|
88296
88574
|
* 读一个可选服务。
|
|
88297
88575
|
* @param ctx - 宿主上下文。
|
|
@@ -88312,8 +88590,8 @@ function serviceOf$2(ctx, service) {
|
|
|
88312
88590
|
* @param value - scope / agent。
|
|
88313
88591
|
* @returns WeakMap 键。
|
|
88314
88592
|
*/
|
|
88315
|
-
function bucketOf$
|
|
88316
|
-
return typeof value === "object" && value !== null ? value : GLOBAL_KEY$
|
|
88593
|
+
function bucketOf$2(value) {
|
|
88594
|
+
return typeof value === "object" && value !== null ? value : GLOBAL_KEY$3;
|
|
88317
88595
|
}
|
|
88318
88596
|
/**
|
|
88319
88597
|
* 订阅一个事件。
|
|
@@ -88323,7 +88601,7 @@ function bucketOf$1(value) {
|
|
|
88323
88601
|
* @param options - cordis 订阅选项;省略时按两参数订阅。
|
|
88324
88602
|
* @returns 解绑函数或 undefined。
|
|
88325
88603
|
*/
|
|
88326
|
-
function subscribe$
|
|
88604
|
+
function subscribe$4(ctx, event, listener, options) {
|
|
88327
88605
|
const on = ctx?.on;
|
|
88328
88606
|
if (typeof on !== "function") return void 0;
|
|
88329
88607
|
if (options !== void 0) try {
|
|
@@ -88379,7 +88657,7 @@ function installPlanModeCacheGuard(ctx) {
|
|
|
88379
88657
|
}
|
|
88380
88658
|
kept.push(section);
|
|
88381
88659
|
}
|
|
88382
|
-
const state = stateOf(bucketOf$
|
|
88660
|
+
const state = stateOf(bucketOf$2(context?.scope ?? context?.agent));
|
|
88383
88661
|
if (policy !== void 0) if (policy.trim() === "") {
|
|
88384
88662
|
state.pending = void 0;
|
|
88385
88663
|
state.delivered = false;
|
|
@@ -88398,7 +88676,7 @@ function installPlanModeCacheGuard(ctx) {
|
|
|
88398
88676
|
if (decision === void 0 || decision.kind === "reject") return decision;
|
|
88399
88677
|
if (payload?.signal?.aborted === true) return decision;
|
|
88400
88678
|
const agent = payload?.agent;
|
|
88401
|
-
const key = bucketOf$
|
|
88679
|
+
const key = bucketOf$2(agent ?? void 0);
|
|
88402
88680
|
const state = states.get(key);
|
|
88403
88681
|
if (state === void 0) return decision;
|
|
88404
88682
|
if (state.delivered) if (planActiveOf(ctx, agent?.session) === false) state.delivered = false;
|
|
@@ -88413,8 +88691,8 @@ function installPlanModeCacheGuard(ctx) {
|
|
|
88413
88691
|
messages: [...messages, createPlanNotice(text, void 0, "Plan mode guidance")]
|
|
88414
88692
|
};
|
|
88415
88693
|
};
|
|
88416
|
-
const offAssemble = subscribe$
|
|
88417
|
-
const offPreStep = subscribe$
|
|
88694
|
+
const offAssemble = subscribe$4(ctx, "system-prompt/assemble", onAssemble);
|
|
88695
|
+
const offPreStep = subscribe$4(ctx, "agent/pre-step", onPreStep);
|
|
88418
88696
|
if (offAssemble !== void 0) restores.push(() => {
|
|
88419
88697
|
offAssemble();
|
|
88420
88698
|
});
|
|
@@ -88447,7 +88725,7 @@ function installPlanModeCacheGuard(ctx) {
|
|
|
88447
88725
|
restoreMethod$3(target);
|
|
88448
88726
|
});
|
|
88449
88727
|
if (typeof tools.get === "function") try {
|
|
88450
|
-
if (tools.get("exit_plan_mode") !== void 0) logWarn$
|
|
88728
|
+
if (tools.get("exit_plan_mode") !== void 0) logWarn$2(ctx, "[dsh-chatgpt-subscription] plan-mode cache guard was installed after exit_plan_mode was already registered; this session keeps the conditional admission");
|
|
88451
88729
|
} catch {}
|
|
88452
88730
|
};
|
|
88453
88731
|
const tools = serviceOf$2(ctx, "tools");
|
|
@@ -88523,7 +88801,7 @@ function planActiveOfAgent(ctx, agent) {
|
|
|
88523
88801
|
* @param ctx - 宿主上下文。
|
|
88524
88802
|
* @param message - 正文。
|
|
88525
88803
|
*/
|
|
88526
|
-
function logWarn$
|
|
88804
|
+
function logWarn$2(ctx, message) {
|
|
88527
88805
|
const logger = ctx?.logger;
|
|
88528
88806
|
try {
|
|
88529
88807
|
logger?.warn(message);
|
|
@@ -88626,17 +88904,56 @@ function markPatched$3(patched, holder, name) {
|
|
|
88626
88904
|
if (names === void 0) patched.set(holder, /* @__PURE__ */ new Set([name]));
|
|
88627
88905
|
else names.add(name);
|
|
88628
88906
|
}
|
|
88907
|
+
//#endregion
|
|
88908
|
+
//#region src/host/ptc-sdk-cache-guard.ts
|
|
88909
|
+
/**
|
|
88910
|
+
* 「PTC SDK 段前缀缓存守卫」——把 `tools:sdk` 段按会话冻结下来。
|
|
88911
|
+
*
|
|
88912
|
+
* ## 为什么需要它
|
|
88913
|
+
*
|
|
88914
|
+
* PTC 模式下模型看到的不是逐个工具 schema,而是 system prompt 里的一段
|
|
88915
|
+
* `tools:sdk`(TypeScript / Python 的 SDK 声明)。这段正文由工具注册表在
|
|
88916
|
+
* **装配那一刻**现算:`tools.definitions(scope, toolSet)`。
|
|
88917
|
+
*
|
|
88918
|
+
* 带 `when` 条件的工具(按步骤准入)会让 `toolSet` 逐步变化:这一步准入了
|
|
88919
|
+
* `exit_plan_mode`,下一步又没准入,于是 `tools:sdk` 段逐步重写。system prompt
|
|
88920
|
+
* 一旦被改写,前缀缓存从改写处起全部作废——在 Kimi Code、MiniMax Code 这种按
|
|
88921
|
+
* 前缀缓存计费的线路上,一次抖动就是几万 token 的全价重建。
|
|
88922
|
+
*
|
|
88923
|
+
* ## 做什么、不做什么
|
|
88924
|
+
*
|
|
88925
|
+
* 1. 包住 `tools.definitions(scope, toolSet)`:受保护 provider 下忽略步骤级
|
|
88926
|
+
* `toolSet`,一律取未过滤的 `definitions(scope, undefined)`。
|
|
88927
|
+
* 2. **不碰** `tools.executable(name, scope, toolSet)`:执行期的步骤准入闸门
|
|
88928
|
+
* 原样保留,`when` 为假时调用该工具照样失败(`UNKNOWN_TOOL`)。工具「看得见」
|
|
88929
|
+
* 与「叫得动」被刻意拆开:看得见是为了缓存稳定,叫得动仍由步骤准入说话。
|
|
88930
|
+
* 3. 监听 `system-prompt/assemble` 瀑布,把首个非空 `tools:sdk` 正文按会话缓存;
|
|
88931
|
+
* 只要未过滤工具集的名字与数量没变(工具注册/注销是唯一的合法变更来源),
|
|
88932
|
+
* 后续每一步都复用同一份字节。
|
|
88933
|
+
*
|
|
88934
|
+
* ## 跨代兼容
|
|
88935
|
+
*
|
|
88936
|
+
* `definitions(scope, toolSet)` 只在较新的工具层里存在。没有它的那一代
|
|
88937
|
+
* (`schemas(scope)` 形态)本守卫什么也不包:那一代的工具表本来就是逐步稳定的,
|
|
88938
|
+
* 缓存不会抖动,守卫无事可做。因此这里全程结构探测,不 import 任何工具层类型。
|
|
88939
|
+
*
|
|
88940
|
+
* @module @eddyskywalker/dsh-chatgpt-subscription/host/ptc-sdk-cache-guard
|
|
88941
|
+
*/
|
|
88942
|
+
/** 受保护的 provider:Kimi Code 线路。 */
|
|
88943
|
+
const KIMI_CODE_PROVIDER = "kimi-code";
|
|
88944
|
+
/** 受保护的 provider:MiniMax Code 线路。 */
|
|
88945
|
+
const MINIMAX_CODE_PROVIDER = "minimax-code";
|
|
88629
88946
|
/**
|
|
88630
88947
|
* 默认受保护的 provider 名单。
|
|
88631
88948
|
*
|
|
88632
88949
|
* `kimi-code` 与 `minimax-code` 都按前缀缓存计费:`tools:sdk` 段一旦被改写,
|
|
88633
88950
|
* 前缀缓存从改写处起全部作废,所以这两条线路默认都要冻结 SDK 段。
|
|
88634
88951
|
*/
|
|
88635
|
-
const DEFAULT_PTC_SDK_CACHE_PROVIDERS = Object.freeze([
|
|
88952
|
+
const DEFAULT_PTC_SDK_CACHE_PROVIDERS = Object.freeze([KIMI_CODE_PROVIDER, MINIMAX_CODE_PROVIDER]);
|
|
88636
88953
|
/** PTC 生成的 SDK 段名。 */
|
|
88637
88954
|
const PTC_SDK_SECTION_NAME = "tools:sdk";
|
|
88638
88955
|
/** 没有 scope 的装配(会话标题之类)用的桶键。 */
|
|
88639
|
-
const GLOBAL_KEY$
|
|
88956
|
+
const GLOBAL_KEY$2 = Object.freeze({});
|
|
88640
88957
|
/**
|
|
88641
88958
|
* 读一个装配 scope 的 provider。
|
|
88642
88959
|
*
|
|
@@ -88730,7 +89047,7 @@ function installPtcSdkCacheGuard(ctx, options = {}) {
|
|
|
88730
89047
|
* @param scope - 装配 scope。
|
|
88731
89048
|
* @returns WeakMap 键。
|
|
88732
89049
|
*/
|
|
88733
|
-
const bucketOf = (scope) => typeof scope === "object" && scope !== null ? scope : GLOBAL_KEY$
|
|
89050
|
+
const bucketOf = (scope) => typeof scope === "object" && scope !== null ? scope : GLOBAL_KEY$2;
|
|
88734
89051
|
/**
|
|
88735
89052
|
* 算未过滤工具集的名字指纹。
|
|
88736
89053
|
*
|
|
@@ -88820,7 +89137,7 @@ function installPtcSdkCacheGuard(ctx, options = {}) {
|
|
|
88820
89137
|
});
|
|
88821
89138
|
return result;
|
|
88822
89139
|
};
|
|
88823
|
-
const offAssemble = subscribe$
|
|
89140
|
+
const offAssemble = subscribe$3(host, "system-prompt/assemble", onAssemble);
|
|
88824
89141
|
if (offAssemble !== void 0) disposers.push(offAssemble);
|
|
88825
89142
|
const initialTools = serviceOf$1(host, "tools");
|
|
88826
89143
|
if (initialTools !== void 0) {
|
|
@@ -88877,7 +89194,7 @@ function serviceOf$1(ctx, service) {
|
|
|
88877
89194
|
* @param listener - 回调。
|
|
88878
89195
|
* @returns 移除监听器的 disposer;宿主不支持事件时为 `undefined`。
|
|
88879
89196
|
*/
|
|
88880
|
-
function subscribe$
|
|
89197
|
+
function subscribe$3(host, event, listener) {
|
|
88881
89198
|
const on = host?.["on"];
|
|
88882
89199
|
if (typeof on !== "function") return void 0;
|
|
88883
89200
|
for (const options of [
|
|
@@ -89294,14 +89611,14 @@ function resolveTeamPolicyCacheGuardEnabled(config) {
|
|
|
89294
89611
|
return config?.teamPolicyCacheGuard !== false;
|
|
89295
89612
|
}
|
|
89296
89613
|
/** 没有 scope 的装配(会话标题之类)用的桶键。 */
|
|
89297
|
-
const GLOBAL_KEY = Object.freeze({});
|
|
89614
|
+
const GLOBAL_KEY$1 = Object.freeze({});
|
|
89298
89615
|
/**
|
|
89299
89616
|
* 桶键:agent 对象本身,或全局桶。
|
|
89300
89617
|
* @param value - scope / agent。
|
|
89301
89618
|
* @returns WeakMap 键。
|
|
89302
89619
|
*/
|
|
89303
|
-
function bucketOf(value) {
|
|
89304
|
-
return typeof value === "object" && value !== null ? value : GLOBAL_KEY;
|
|
89620
|
+
function bucketOf$1(value) {
|
|
89621
|
+
return typeof value === "object" && value !== null ? value : GLOBAL_KEY$1;
|
|
89305
89622
|
}
|
|
89306
89623
|
/**
|
|
89307
89624
|
* 订阅一个事件。
|
|
@@ -89310,7 +89627,7 @@ function bucketOf(value) {
|
|
|
89310
89627
|
* @param listener - 监听器。
|
|
89311
89628
|
* @returns 解绑函数或 undefined。
|
|
89312
89629
|
*/
|
|
89313
|
-
function subscribe$
|
|
89630
|
+
function subscribe$2(ctx, event, listener) {
|
|
89314
89631
|
const on = ctx?.on;
|
|
89315
89632
|
if (typeof on !== "function") return void 0;
|
|
89316
89633
|
try {
|
|
@@ -89324,7 +89641,7 @@ function subscribe$1(ctx, event, listener) {
|
|
|
89324
89641
|
* @param ctx - 宿主上下文。
|
|
89325
89642
|
* @param message - 正文。
|
|
89326
89643
|
*/
|
|
89327
|
-
function logWarn(ctx, message) {
|
|
89644
|
+
function logWarn$1(ctx, message) {
|
|
89328
89645
|
try {
|
|
89329
89646
|
ctx?.logger?.warn(message);
|
|
89330
89647
|
} catch {}
|
|
@@ -89402,11 +89719,11 @@ function installTeamPolicyCacheGuard(ctx, options = {}) {
|
|
|
89402
89719
|
if (policy === void 0) {
|
|
89403
89720
|
if (!stats.seen && !stats.warned) {
|
|
89404
89721
|
stats.warned = true;
|
|
89405
|
-
logWarn(ctx, `[dsh-chatgpt-subscription] team policy cache guard is enabled but no "${TEAM_POLICY_SECTION}" section has appeared; the guard is inert on this deployment`);
|
|
89722
|
+
logWarn$1(ctx, `[dsh-chatgpt-subscription] team policy cache guard is enabled but no "${TEAM_POLICY_SECTION}" section has appeared; the guard is inert on this deployment`);
|
|
89406
89723
|
}
|
|
89407
89724
|
return result;
|
|
89408
89725
|
}
|
|
89409
|
-
const state = stateOf(bucketOf(context?.scope ?? context?.agent));
|
|
89726
|
+
const state = stateOf(bucketOf$1(context?.scope ?? context?.agent));
|
|
89410
89727
|
if (policy.trim() === "") {
|
|
89411
89728
|
if (state.delivered) state.revoked = true;
|
|
89412
89729
|
state.delivered = false;
|
|
@@ -89427,7 +89744,7 @@ function installTeamPolicyCacheGuard(ctx, options = {}) {
|
|
|
89427
89744
|
if (closed || decision === void 0 || decision.kind === "reject") return decision;
|
|
89428
89745
|
if (payload?.signal?.aborted === true) return decision;
|
|
89429
89746
|
if (!enabled()) return decision;
|
|
89430
|
-
const state = states.get(bucketOf(payload?.agent ?? void 0));
|
|
89747
|
+
const state = states.get(bucketOf$1(payload?.agent ?? void 0));
|
|
89431
89748
|
if (state === void 0) return decision;
|
|
89432
89749
|
const messages = Array.isArray(decision.messages) ? decision.messages : [];
|
|
89433
89750
|
if (!state.delivered) {
|
|
@@ -89451,8 +89768,8 @@ function installTeamPolicyCacheGuard(ctx, options = {}) {
|
|
|
89451
89768
|
}
|
|
89452
89769
|
return decision;
|
|
89453
89770
|
};
|
|
89454
|
-
const offAssemble = subscribe$
|
|
89455
|
-
const offPreStep = subscribe$
|
|
89771
|
+
const offAssemble = subscribe$2(ctx, "system-prompt/assemble", onAssemble);
|
|
89772
|
+
const offPreStep = subscribe$2(ctx, "agent/pre-step", onPreStep);
|
|
89456
89773
|
if (offAssemble !== void 0) restores.push(() => {
|
|
89457
89774
|
offAssemble();
|
|
89458
89775
|
});
|
|
@@ -89936,7 +90253,7 @@ function installCompactionPolicyGuard(ctx, options = {}) {
|
|
|
89936
90253
|
return next === void 0 ? void 0 : next();
|
|
89937
90254
|
};
|
|
89938
90255
|
for (const event of GUARDED_EVENTS) {
|
|
89939
|
-
const disposer = subscribe(host, event, handleAgentEvent);
|
|
90256
|
+
const disposer = subscribe$1(host, event, handleAgentEvent);
|
|
89940
90257
|
if (disposer !== void 0) disposers.push(disposer);
|
|
89941
90258
|
}
|
|
89942
90259
|
scanAndPatch();
|
|
@@ -90003,7 +90320,7 @@ function readContext(value) {
|
|
|
90003
90320
|
* @param listener - 回调。
|
|
90004
90321
|
* @returns 移除监听器的 disposer;宿主不支持事件时为 `undefined`。
|
|
90005
90322
|
*/
|
|
90006
|
-
function subscribe(host, event, listener) {
|
|
90323
|
+
function subscribe$1(host, event, listener) {
|
|
90007
90324
|
const on = host?.["on"];
|
|
90008
90325
|
if (typeof on !== "function") return void 0;
|
|
90009
90326
|
for (const options of [
|
|
@@ -90133,6 +90450,391 @@ function markPatched(patched, holder, name) {
|
|
|
90133
90450
|
if (names === void 0) patched.set(holder, /* @__PURE__ */ new Set([name]));
|
|
90134
90451
|
else names.add(name);
|
|
90135
90452
|
}
|
|
90453
|
+
//#endregion
|
|
90454
|
+
//#region src/host/timeline-cache-guard.ts
|
|
90455
|
+
/**
|
|
90456
|
+
* 「Timeline 规划段前缀缓存守卫」—— 把实验性 Timeline 插件随 volatile 设置变化的
|
|
90457
|
+
* 那段 system prompt 冻结下来,变更改为尾部投递一次。
|
|
90458
|
+
*
|
|
90459
|
+
* ## 为什么需要它
|
|
90460
|
+
*
|
|
90461
|
+
* `@deepseek-ai/dsh-timeline` 用 `systemPrompt.section()` 注册 `timeline:planning`
|
|
90462
|
+
* 段,而那段正文的来源里包含**会话中途会变的值**:
|
|
90463
|
+
*
|
|
90464
|
+
* - `taskLanguageInstruction(config.language, config.uiLanguage)` —— 显示语言由
|
|
90465
|
+
* Host 读 `settings` 的 locale 偏好,并且会被**任意已认证浏览器**通过 RPC
|
|
90466
|
+
* `timeline/locale` 改写(timeline 的 `index.ts` 把 `browserLanguage` 记下来后
|
|
90467
|
+
* 交给 `liveConfig` 的读取器)。同一场对话换个语言的浏览器打开,系统提示就变。
|
|
90468
|
+
*
|
|
90469
|
+
* 本仓库的 Kimi Code 线路按内容前缀计费,而它**没有**声明
|
|
90470
|
+
* `systemPromptUpdate: 'in-history'`(system prompt 只能作为请求头送出)。因此
|
|
90471
|
+
* `SystemPromptProjection` 一旦看到渲染文本变化,走的就是 `replace` 节点 0——
|
|
90472
|
+
* 整段前缀作废,一次全价重建。参见 `packages/core/agent-loop/src/runtime-context.ts`。
|
|
90473
|
+
*
|
|
90474
|
+
* `timeline_tasks` 的工具描述同理:timeline 用 `Object.defineProperty` 把
|
|
90475
|
+
* `config.taskPrompt` 挂在 description 的 getter 上,改一次写作提示词就等于改工具
|
|
90476
|
+
* 表,`tools` 数组随之变化。这条线路虽然有 `toolUpdate: 'in-history'`,但那个模式
|
|
90477
|
+
* 只覆盖工具的**增删**,不覆盖既有工具的描述改写。
|
|
90478
|
+
*
|
|
90479
|
+
* ## 三条动作(与 `team-policy-cache-guard` / `plan-mode-cache-guard` 同一套)
|
|
90480
|
+
*
|
|
90481
|
+
* 1. `system-prompt/assemble` 瀑布:把首次出现的 `timeline:planning` 正文按 scope
|
|
90482
|
+
* 记下来,之后一律返回这份冻结副本。system 段从此逐字节恒定。
|
|
90483
|
+
* 2. 冻结值与当次装配到的正文不一致时,记一份「待投递」;下一步 `agent/pre-step`
|
|
90484
|
+
* 把它作为**尾部用户消息**投一次。末尾追加不改变已发前缀,指引没有丢,只是从
|
|
90485
|
+
* 最前面的 system 段搬到了末尾。
|
|
90486
|
+
* 3. `tools.definitions` 包装:把 `timeline_tasks` 的定义替换成首次见到的那份描述,
|
|
90487
|
+
* 工具表不随写作提示词变化。
|
|
90488
|
+
*
|
|
90489
|
+
* ## 冻结的是「首次见到的那一份」,不是抄来的副本
|
|
90490
|
+
*
|
|
90491
|
+
* 投递的正文永远是装配时从官方段里捕获到的原文,本包不落任何 timeline 的文案副
|
|
90492
|
+
* 本。harness 改措辞不会让这里过期。代价是它依赖段名 `timeline:planning`:启用后
|
|
90493
|
+
* 若从未观察到该段(没装 timeline、或 timeline 改了段名),守卫记一条 warn 点名,
|
|
90494
|
+
* 而不是安静地什么都不做。
|
|
90495
|
+
*
|
|
90496
|
+
* ## 默认开启,且只对按前缀计费的线路生效
|
|
90497
|
+
*
|
|
90498
|
+
* 与会话状态无关的纯旁路:不增加任何工具声明面,只在真正出现该段时才动手。开关由
|
|
90499
|
+
* `timelineCacheGuard` 控制,每次装配/每步重读活引用。
|
|
90500
|
+
*
|
|
90501
|
+
* @module @eddyskywalker/dsh-chatgpt-subscription/host/timeline-cache-guard
|
|
90502
|
+
*/
|
|
90503
|
+
/** Timeline 的规划指引段名。 */
|
|
90504
|
+
const TIMELINE_SECTION = "timeline:planning";
|
|
90505
|
+
/** Timeline 的任务更新工具名;它的描述随 `taskPrompt` 变。 */
|
|
90506
|
+
const TIMELINE_TASK_TOOL = "timeline_tasks";
|
|
90507
|
+
/**
|
|
90508
|
+
* 默认受保护的 provider 名单。
|
|
90509
|
+
*
|
|
90510
|
+
* `kimi-code` 与 `minimax-code` 都按前缀缓存计费,而且都没有声明
|
|
90511
|
+
* `systemPromptUpdate: 'in-history'`:系统段一改就是整段重建。
|
|
90512
|
+
*/
|
|
90513
|
+
const DEFAULT_TIMELINE_CACHE_PROVIDERS = Object.freeze([KIMI_CODE_PROVIDER, MINIMAX_CODE_PROVIDER]);
|
|
90514
|
+
/** 尾部通知的来源 kind(本包自有)。 */
|
|
90515
|
+
const TIMELINE_NOTICE_SOURCE_KIND = "timeline-cache-notice";
|
|
90516
|
+
/**
|
|
90517
|
+
* 从插件配置里读开关。
|
|
90518
|
+
* @param config - 插件配置(结构化:只读一个键)。
|
|
90519
|
+
* @returns 是否启用本守卫;未声明时按开启处理(宿主 schema 的默认值)。
|
|
90520
|
+
*/
|
|
90521
|
+
function resolveTimelineCacheGuardEnabled(config) {
|
|
90522
|
+
return config?.timelineCacheGuard !== false;
|
|
90523
|
+
}
|
|
90524
|
+
/** 没有 scope 的装配(会话标题之类)用的桶键。 */
|
|
90525
|
+
const GLOBAL_KEY = Object.freeze({});
|
|
90526
|
+
/**
|
|
90527
|
+
* 桶键:agent 对象本身,或全局桶。
|
|
90528
|
+
* @param value - scope / agent。
|
|
90529
|
+
* @returns WeakMap 键。
|
|
90530
|
+
*/
|
|
90531
|
+
function bucketOf(value) {
|
|
90532
|
+
return typeof value === "object" && value !== null ? value : GLOBAL_KEY;
|
|
90533
|
+
}
|
|
90534
|
+
/**
|
|
90535
|
+
* 订阅一个事件。
|
|
90536
|
+
* @param ctx - 宿主上下文。
|
|
90537
|
+
* @param event - 事件名。
|
|
90538
|
+
* @param listener - 监听器。
|
|
90539
|
+
* @returns 解绑函数或 undefined。
|
|
90540
|
+
*/
|
|
90541
|
+
function subscribe(ctx, event, listener) {
|
|
90542
|
+
const on = ctx?.on;
|
|
90543
|
+
if (typeof on !== "function") return void 0;
|
|
90544
|
+
try {
|
|
90545
|
+
return on.call(ctx, event, listener);
|
|
90546
|
+
} catch {
|
|
90547
|
+
return;
|
|
90548
|
+
}
|
|
90549
|
+
}
|
|
90550
|
+
/**
|
|
90551
|
+
* 记一条警告。
|
|
90552
|
+
* @param ctx - 宿主上下文。
|
|
90553
|
+
* @param message - 正文。
|
|
90554
|
+
*/
|
|
90555
|
+
function logWarn(ctx, message) {
|
|
90556
|
+
try {
|
|
90557
|
+
ctx?.logger?.warn(message);
|
|
90558
|
+
} catch {}
|
|
90559
|
+
}
|
|
90560
|
+
/**
|
|
90561
|
+
* 造一条尾部通知消息。
|
|
90562
|
+
* @param text - 正文。
|
|
90563
|
+
* @param summary - 卡片上显示的一句摘要。
|
|
90564
|
+
* @returns 用户角色的通知消息。
|
|
90565
|
+
*/
|
|
90566
|
+
function createNotice(text, summary) {
|
|
90567
|
+
return createUserMessage({
|
|
90568
|
+
content: [{
|
|
90569
|
+
type: "text",
|
|
90570
|
+
text
|
|
90571
|
+
}],
|
|
90572
|
+
source: {
|
|
90573
|
+
kind: TIMELINE_NOTICE_SOURCE_KIND,
|
|
90574
|
+
form: "notice",
|
|
90575
|
+
summary
|
|
90576
|
+
}
|
|
90577
|
+
});
|
|
90578
|
+
}
|
|
90579
|
+
/**
|
|
90580
|
+
* 新正文的尾部投递正文。
|
|
90581
|
+
*
|
|
90582
|
+
* 完整重放一遍段文本,而不是只投一条「语言变了」:模型需要的是新的写作要求本身,
|
|
90583
|
+
* 而它已经在**旧**要求下工作了很久,只说一句「变了」等于让它自己猜变了什么。
|
|
90584
|
+
* @param text - 冻结之后出现的新段文本。
|
|
90585
|
+
* @returns 通知正文。
|
|
90586
|
+
*/
|
|
90587
|
+
function timelineGuidanceUpdateText(text) {
|
|
90588
|
+
return "Timeline planning guidance was updated. It replaces any earlier Timeline planning instruction you were given; follow this version from now on.\n\n" + text;
|
|
90589
|
+
}
|
|
90590
|
+
/**
|
|
90591
|
+
* 装一台「Timeline 规划段前缀缓存守卫」。
|
|
90592
|
+
*
|
|
90593
|
+
* 幂等性留给调用方:同一个 ctx 装两次会得到两条监听器,宿主入口应当只装一次。
|
|
90594
|
+
* @param ctx - 宿主上下文(结构化:老代 ctx 也认)。
|
|
90595
|
+
* @param options - 开关与线路名单。
|
|
90596
|
+
* @returns 句柄,dispose 摘掉全部挂载。
|
|
90597
|
+
*/
|
|
90598
|
+
function installTimelineCacheGuard(ctx, options = {}) {
|
|
90599
|
+
const providers = new Set(options.providers ?? DEFAULT_TIMELINE_CACHE_PROVIDERS);
|
|
90600
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
90601
|
+
const stats = {
|
|
90602
|
+
seen: false,
|
|
90603
|
+
warned: false,
|
|
90604
|
+
warnedTools: false
|
|
90605
|
+
};
|
|
90606
|
+
const restores = [];
|
|
90607
|
+
const alreadyWrapped = /* @__PURE__ */ new WeakSet();
|
|
90608
|
+
const patchedMethods = /* @__PURE__ */ new WeakMap();
|
|
90609
|
+
let disposed = false;
|
|
90610
|
+
const enabled = () => {
|
|
90611
|
+
const read = options.enabled;
|
|
90612
|
+
if (read === void 0) return true;
|
|
90613
|
+
try {
|
|
90614
|
+
return read() === true;
|
|
90615
|
+
} catch {
|
|
90616
|
+
return false;
|
|
90617
|
+
}
|
|
90618
|
+
};
|
|
90619
|
+
const stateOf = (key) => {
|
|
90620
|
+
let state = states.get(key);
|
|
90621
|
+
if (state === void 0) {
|
|
90622
|
+
state = {
|
|
90623
|
+
frozen: "",
|
|
90624
|
+
pending: void 0
|
|
90625
|
+
};
|
|
90626
|
+
states.set(key, state);
|
|
90627
|
+
}
|
|
90628
|
+
return state;
|
|
90629
|
+
};
|
|
90630
|
+
const onAssemble = async (_assembly, context, next) => {
|
|
90631
|
+
const result = await next();
|
|
90632
|
+
if (disposed || !enabled()) return result;
|
|
90633
|
+
const scope = context?.scope ?? context?.agent;
|
|
90634
|
+
const provider = readScopeProvider(scope);
|
|
90635
|
+
if (provider === void 0 || !providers.has(provider)) return result;
|
|
90636
|
+
const sections = Array.isArray(result?.sections) ? result.sections : void 0;
|
|
90637
|
+
if (sections === void 0) return result;
|
|
90638
|
+
const index = sections.findIndex((section) => section?.name === TIMELINE_SECTION);
|
|
90639
|
+
if (index < 0) {
|
|
90640
|
+
if (!stats.seen && !stats.warned) {
|
|
90641
|
+
stats.warned = true;
|
|
90642
|
+
logWarn(ctx, "[dsh-chatgpt-subscription] timeline cache guard is enabled but no \"timeline:planning\" section has appeared; the guard is inert on this deployment");
|
|
90643
|
+
}
|
|
90644
|
+
return result;
|
|
90645
|
+
}
|
|
90646
|
+
stats.seen = true;
|
|
90647
|
+
const current = sections[index];
|
|
90648
|
+
const text = typeof current?.text === "string" ? current.text : "";
|
|
90649
|
+
if (text === "") return result;
|
|
90650
|
+
const state = stateOf(bucketOf(scope));
|
|
90651
|
+
if (state.frozen === "") {
|
|
90652
|
+
state.frozen = text;
|
|
90653
|
+
state.pending = void 0;
|
|
90654
|
+
return result;
|
|
90655
|
+
}
|
|
90656
|
+
if (text !== state.frozen) state.pending = text;
|
|
90657
|
+
if (text === state.frozen) return result;
|
|
90658
|
+
const frozenSections = sections.map((section, position) => position === index ? {
|
|
90659
|
+
...section,
|
|
90660
|
+
text: state.frozen
|
|
90661
|
+
} : section);
|
|
90662
|
+
return {
|
|
90663
|
+
...result,
|
|
90664
|
+
sections: frozenSections
|
|
90665
|
+
};
|
|
90666
|
+
};
|
|
90667
|
+
const onPreStep = async (payload, next) => {
|
|
90668
|
+
const decision = await next();
|
|
90669
|
+
if (disposed || decision === void 0 || decision.kind === "reject") return decision;
|
|
90670
|
+
if (payload?.signal?.aborted === true) return decision;
|
|
90671
|
+
if (!enabled()) return decision;
|
|
90672
|
+
const state = states.get(bucketOf(payload?.agent));
|
|
90673
|
+
const text = state?.pending;
|
|
90674
|
+
if (state === void 0 || text === void 0) return decision;
|
|
90675
|
+
state.pending = void 0;
|
|
90676
|
+
const messages = Array.isArray(decision.messages) ? decision.messages : [];
|
|
90677
|
+
return {
|
|
90678
|
+
...decision,
|
|
90679
|
+
messages: [...messages, createNotice(timelineGuidanceUpdateText(text), "Timeline guidance updated")]
|
|
90680
|
+
};
|
|
90681
|
+
};
|
|
90682
|
+
/**
|
|
90683
|
+
* 冻结下来的工具描述,**按装配 scope 分桶**。
|
|
90684
|
+
*
|
|
90685
|
+
* 只记「每个 scope 第一次见到的那个值」:timeline 的 description 是 getter,每次
|
|
90686
|
+
* 读都反映当时的 `taskPrompt`,所以比较基准必须是字符串快照,不能是函数引用。
|
|
90687
|
+
*
|
|
90688
|
+
* 按 scope 而不是按进程:同一个宿主可以同时跑两个部署(npm 拷贝与仓库 link),
|
|
90689
|
+
* 两者的 taskPrompt 合法地不同;进程级单例会让后一个部署拿到前一个的文案,
|
|
90690
|
+
* 表现成「换了提示词却没生效」而不是任何可诊断的错误。
|
|
90691
|
+
*/
|
|
90692
|
+
const frozenToolDescriptions = /* @__PURE__ */ new WeakMap();
|
|
90693
|
+
/** 取一个 scope 的描述快照表,按需创建。 */
|
|
90694
|
+
const descriptionsOf = (scope) => {
|
|
90695
|
+
const bucket = bucketOf(scope);
|
|
90696
|
+
let table = frozenToolDescriptions.get(bucket);
|
|
90697
|
+
if (table === void 0) {
|
|
90698
|
+
table = /* @__PURE__ */ new Map();
|
|
90699
|
+
frozenToolDescriptions.set(bucket, table);
|
|
90700
|
+
}
|
|
90701
|
+
return table;
|
|
90702
|
+
};
|
|
90703
|
+
const freezeDefinitions = (scope, list) => {
|
|
90704
|
+
const table = descriptionsOf(scope);
|
|
90705
|
+
let changed = false;
|
|
90706
|
+
const frozen = list.map((entry) => {
|
|
90707
|
+
if (typeof entry !== "object" || entry === null) return entry;
|
|
90708
|
+
const definition = entry;
|
|
90709
|
+
if (definition.name !== "timeline_tasks") return entry;
|
|
90710
|
+
const description = definition.description;
|
|
90711
|
+
if (typeof description !== "string") return entry;
|
|
90712
|
+
const seen = table.get(TIMELINE_TASK_TOOL);
|
|
90713
|
+
if (seen === void 0) {
|
|
90714
|
+
table.set(TIMELINE_TASK_TOOL, description);
|
|
90715
|
+
return entry;
|
|
90716
|
+
}
|
|
90717
|
+
if (seen === description) return entry;
|
|
90718
|
+
changed = true;
|
|
90719
|
+
return {
|
|
90720
|
+
...entry,
|
|
90721
|
+
description: seen
|
|
90722
|
+
};
|
|
90723
|
+
});
|
|
90724
|
+
return changed ? frozen : list;
|
|
90725
|
+
};
|
|
90726
|
+
/**
|
|
90727
|
+
* 方法的真实宿主:Cordis 的 `Service` 代理读属性时会把方法**绑定到读取它的那一层
|
|
90728
|
+
* 作用域**,所以 `const original = tools.definitions` 拿到的是已经绑好的函数,
|
|
90729
|
+
* 再 `original.call(tools, …)` 会把根作用域塞回每一个子作用域。真正要包的是原型上
|
|
90730
|
+
* 那份未绑定的实现(与 `ptc-sdk-cache-guard.ts` 同一套处理)。
|
|
90731
|
+
* @param service - 候选服务实例。
|
|
90732
|
+
* @returns 目标;方法不存在时 undefined。
|
|
90733
|
+
*/
|
|
90734
|
+
const resolveMethodTarget = (service) => {
|
|
90735
|
+
if (typeof service !== "object" || service === null) return void 0;
|
|
90736
|
+
const own = service;
|
|
90737
|
+
if (Object.prototype.hasOwnProperty.call(own, "definitions")) {
|
|
90738
|
+
const original = own["definitions"];
|
|
90739
|
+
if (typeof original !== "function") return void 0;
|
|
90740
|
+
return {
|
|
90741
|
+
holder: own,
|
|
90742
|
+
name: "definitions",
|
|
90743
|
+
original,
|
|
90744
|
+
descriptor: Object.getOwnPropertyDescriptor(own, "definitions")
|
|
90745
|
+
};
|
|
90746
|
+
}
|
|
90747
|
+
const proto = Object.getPrototypeOf(service);
|
|
90748
|
+
if (proto === null || proto === Object.prototype || proto === Function.prototype) return;
|
|
90749
|
+
const original = proto["definitions"];
|
|
90750
|
+
if (typeof original !== "function") return void 0;
|
|
90751
|
+
return {
|
|
90752
|
+
holder: proto,
|
|
90753
|
+
name: "definitions",
|
|
90754
|
+
original,
|
|
90755
|
+
descriptor: Object.getOwnPropertyDescriptor(proto, "definitions")
|
|
90756
|
+
};
|
|
90757
|
+
};
|
|
90758
|
+
const wrapToolsService = (tools) => {
|
|
90759
|
+
if (disposed || typeof tools !== "object" || tools === null) return false;
|
|
90760
|
+
if (alreadyWrapped.has(tools)) return false;
|
|
90761
|
+
const target = resolveMethodTarget(tools);
|
|
90762
|
+
if (target === void 0) {
|
|
90763
|
+
if (!stats.warnedTools) {
|
|
90764
|
+
stats.warnedTools = true;
|
|
90765
|
+
logWarn(ctx, "[dsh-chatgpt-subscription] timeline cache guard cannot freeze the task tool description: this tool registry exposes no definitions()");
|
|
90766
|
+
}
|
|
90767
|
+
return false;
|
|
90768
|
+
}
|
|
90769
|
+
if (patchedMethods.get(target.holder)?.has(target.name) === true) {
|
|
90770
|
+
alreadyWrapped.add(tools);
|
|
90771
|
+
return false;
|
|
90772
|
+
}
|
|
90773
|
+
const original = target.original;
|
|
90774
|
+
const replacement = function(scope, toolSet) {
|
|
90775
|
+
const receiver = this ?? tools;
|
|
90776
|
+
const list = original.call(receiver, scope, toolSet);
|
|
90777
|
+
if (!Array.isArray(list) || disposed || !enabled()) return list;
|
|
90778
|
+
const provider = readScopeProvider(scope);
|
|
90779
|
+
if (provider === void 0 || !providers.has(provider)) return list;
|
|
90780
|
+
return freezeDefinitions(scope, list);
|
|
90781
|
+
};
|
|
90782
|
+
try {
|
|
90783
|
+
Object.defineProperty(target.holder, target.name, {
|
|
90784
|
+
value: replacement,
|
|
90785
|
+
configurable: true,
|
|
90786
|
+
writable: true,
|
|
90787
|
+
enumerable: target.descriptor?.enumerable ?? false
|
|
90788
|
+
});
|
|
90789
|
+
} catch {
|
|
90790
|
+
return false;
|
|
90791
|
+
}
|
|
90792
|
+
const names = patchedMethods.get(target.holder) ?? /* @__PURE__ */ new Set();
|
|
90793
|
+
names.add(target.name);
|
|
90794
|
+
patchedMethods.set(target.holder, names);
|
|
90795
|
+
alreadyWrapped.add(tools);
|
|
90796
|
+
restores.push(() => {
|
|
90797
|
+
try {
|
|
90798
|
+
if (target.descriptor === void 0) Reflect.deleteProperty(target.holder, target.name);
|
|
90799
|
+
else Object.defineProperty(target.holder, target.name, target.descriptor);
|
|
90800
|
+
} catch {}
|
|
90801
|
+
});
|
|
90802
|
+
return true;
|
|
90803
|
+
};
|
|
90804
|
+
const wrapServiceFrom = (target) => {
|
|
90805
|
+
if (typeof target !== "object" || target === null) return false;
|
|
90806
|
+
const get = target.get;
|
|
90807
|
+
if (typeof get !== "function") return false;
|
|
90808
|
+
try {
|
|
90809
|
+
return wrapToolsService(get.call(target, "tools"));
|
|
90810
|
+
} catch {
|
|
90811
|
+
return false;
|
|
90812
|
+
}
|
|
90813
|
+
};
|
|
90814
|
+
wrapServiceFrom(ctx);
|
|
90815
|
+
const inject = ctx?.inject;
|
|
90816
|
+
if (typeof inject === "function") try {
|
|
90817
|
+
inject.call(ctx, ["tools"], (scope) => {
|
|
90818
|
+
if (disposed) return;
|
|
90819
|
+
wrapServiceFrom(scope);
|
|
90820
|
+
});
|
|
90821
|
+
} catch {}
|
|
90822
|
+
const offAssemble = subscribe(ctx, "system-prompt/assemble", onAssemble);
|
|
90823
|
+
const offPreStep = subscribe(ctx, "agent/pre-step", onPreStep);
|
|
90824
|
+
if (offAssemble !== void 0) restores.push(() => {
|
|
90825
|
+
offAssemble();
|
|
90826
|
+
});
|
|
90827
|
+
if (offPreStep !== void 0) restores.push(() => {
|
|
90828
|
+
offPreStep();
|
|
90829
|
+
});
|
|
90830
|
+
return { dispose() {
|
|
90831
|
+
if (disposed) return;
|
|
90832
|
+
disposed = true;
|
|
90833
|
+
for (const restore of restores.splice(0)) try {
|
|
90834
|
+
restore();
|
|
90835
|
+
} catch {}
|
|
90836
|
+
} };
|
|
90837
|
+
}
|
|
90136
90838
|
const ID_SCHEMA = z.string().min(1).max(64).regex(/^[A-Za-z0-9._:-]+$/);
|
|
90137
90839
|
const TASK_REFERENCE_SCHEMA = z.string().min(1).max(160);
|
|
90138
90840
|
const BOUNDARY_SCHEMA = z.string().min(1).max(120);
|
|
@@ -104616,12 +105318,13 @@ const Config = z$1.object({
|
|
|
104616
105318
|
z$1.const("zh"),
|
|
104617
105319
|
z$1.const("en"),
|
|
104618
105320
|
z$1.const("ru")
|
|
104619
|
-
]).default("auto").volatile().description("进展更新的输出语言:auto 跟随对话语言,zh 中文,en
|
|
105321
|
+
]).default("auto").volatile().description("进展更新的输出语言:auto 跟随对话语言,zh 中文,en 英文,ru 俄文。"),
|
|
104620
105322
|
planModePipeline: z$1.boolean().default(true).volatile().description("启用计划模式管线:允许调度模式在澄清访谈收敛后用 enter_plan_mode 进入计划模式,放弃规划时用 leave_plan_mode 退出。"),
|
|
104621
105323
|
dispatchExecutionGuard: z$1.boolean().default(true).volatile().description("启用调度执行守卫:在执行期拦截子代理越权调用主控专用工具,并拦截等待子代理期间的纯 sleep 空等命令;不修改工具声明面,零损耗保护 Kimi 缓存。"),
|
|
104622
105324
|
toolRunawayGuard: z$1.boolean().default(true).volatile().description("启用工具失控治理:对零增量病态信号(同名同参重复、同一工具连续同族报错、后台任务无变化轮询)分级提醒;Kimi 保留第 12 次同参强停,其他线路只提醒。"),
|
|
104623
105325
|
mediaTools: z$1.boolean().default(true).volatile().description("注册图片/视频工具:Codex 生图、Kimi 视频挂载、MiniMax 视频生成与理解;默认开启。修改后重载插件或重启 DSH,Kimi 既有会话在工具表变化后会重建一次前缀缓存。"),
|
|
104624
105326
|
teamPolicyCacheGuard: z$1.boolean().default(true).volatile().description("把内置 Agent Teams 的 team:policy 段从 system prompt 摘掉,改为开关切换时以尾部用户消息投递一次,避免中途开团队协作时刷掉整段前缀缓存;默认开启。"),
|
|
105327
|
+
timelineCacheGuard: z$1.boolean().default(true).volatile().description("冻结实验性 Timeline 插件的规划段与任务工具描述,变更改为尾部用户消息投递,避免中途改语言/写作提示词时刷掉 Kimi/MiniMax 的整段前缀缓存;默认开启。"),
|
|
104625
105328
|
cacheWarmup: z$1.boolean().default(true).volatile().description(CACHE_WARMUP_SETTING_DESCRIPTION),
|
|
104626
105329
|
cacheWarmupProviders: z$1.array(z$1.string()).default(CONTROLLED_PROVIDERS).volatile().description("允许产生新结果预览的线路;默认覆盖全部受控线路,空数组表示关闭所有新投影。"),
|
|
104627
105330
|
cacheWarmupRetrieval: z$1.boolean().default(true).volatile().description(CACHE_WARMUP_RETRIEVAL_SETTING_DESCRIPTION),
|
|
@@ -104702,6 +105405,10 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
104702
105405
|
const guard = installTeamPolicyCacheGuard(ctx, { enabled: () => resolveTeamPolicyCacheGuardEnabled(pluginConfig) });
|
|
104703
105406
|
return () => guard.dispose();
|
|
104704
105407
|
}, "dsh-chatgpt-subscription: team policy cache guard");
|
|
105408
|
+
ctx.effect(() => {
|
|
105409
|
+
const guard = installTimelineCacheGuard(ctx, { enabled: () => resolveTimelineCacheGuardEnabled(pluginConfig) });
|
|
105410
|
+
return () => guard.dispose();
|
|
105411
|
+
}, "dsh-chatgpt-subscription: timeline cache guard");
|
|
104705
105412
|
ctx.effect(() => {
|
|
104706
105413
|
const guard = installCompactionPolicyGuard(ctx);
|
|
104707
105414
|
return () => guard.dispose();
|
|
@@ -105386,12 +106093,19 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
105386
106093
|
canToggle: true,
|
|
105387
106094
|
read: async () => {
|
|
105388
106095
|
const current = await antigravityAcpSettings.read();
|
|
106096
|
+
if (!current.enabled) return {
|
|
106097
|
+
enabled: false,
|
|
106098
|
+
accountCount: 0,
|
|
106099
|
+
authenticated: false,
|
|
106100
|
+
enabledModelCount: null,
|
|
106101
|
+
totalModelCount: null
|
|
106102
|
+
};
|
|
105389
106103
|
const catalog = await antigravityAcpCatalog.rehydrate();
|
|
105390
106104
|
const total = catalog === void 0 ? null : catalogTotal(catalog.models.length);
|
|
105391
106105
|
const selected = current.enabledModelIds === null ? total : current.enabledModelIds.length;
|
|
105392
106106
|
const auth = await antigravityAcpAuth.read();
|
|
105393
106107
|
return {
|
|
105394
|
-
enabled:
|
|
106108
|
+
enabled: true,
|
|
105395
106109
|
accountCount: auth.authenticated ? 1 : 0,
|
|
105396
106110
|
authenticated: auth.authenticated,
|
|
105397
106111
|
enabledModelCount: total === null || selected === null ? null : Math.min(selected, total),
|