billion-context 0.1.141 → 0.1.142

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/dist/index.js CHANGED
@@ -71419,24 +71419,20 @@ function withSearchContextConversationDescription(tools) {
71419
71419
  return copy;
71420
71420
  });
71421
71421
  }
71422
- function handlePluginManifest(res) {
71422
+ function handlePluginManifest(res, config) {
71423
+ const absorbOn = absorbEnabled(config);
71424
+ const rulesOn = rulesEnabled(config);
71423
71425
  res.writeHead(200, { "content-type": "application/json" });
71424
71426
  res.end(JSON.stringify({
71425
71427
  ok: true,
71426
71428
  protocolVersion: PLUGIN_PROTOCOL_VERSION,
71427
71429
  proxy: "billion-context",
71428
71430
  version: VERSION2,
71429
- // Absorb and acp_rule are advertised alongside the four ACP tools.
71430
- // Both are host-registered opt-in (not in the kernel's
71431
- // ACP_TOOL_NAMES), so the manifest must list them explicitly.
71432
- // Per-session enablement is enforced at execution (isProxyToolFor /
71433
- // executeProxyTool), not here — the manifest has no request context to
71434
- // know which route will win.
71435
- toolNames: [...ACP_TOOL_NAMES, ABSORB_TOOL_NAME, RULE_TOOL_NAME],
71431
+ toolNames: [...ACP_TOOL_NAMES, ...absorbOn ? [ABSORB_TOOL_NAME] : [], ...rulesOn ? [RULE_TOOL_NAME] : []],
71436
71432
  tools: {
71437
- anthropic: withSearchContextConversationDescription([...BILI_ACP_TOOLS_ANTHROPIC, ABSORB_TOOL, RULE_TOOL].map(withConversationIdParam)),
71438
- openai: withSearchContextConversationDescription([...BILI_ACP_TOOLS_OPENAI, ABSORB_TOOL_OPENAI, RULE_TOOL_OPENAI].map(withConversationIdParam)),
71439
- responses: withSearchContextConversationDescription([...BILI_ACP_TOOLS_RESPONSES, ABSORB_TOOL_RESPONSES, RULE_TOOL_RESPONSES].map(withConversationIdParam))
71433
+ anthropic: withSearchContextConversationDescription([...BILI_ACP_TOOLS_ANTHROPIC, ...absorbOn ? [ABSORB_TOOL] : [], ...rulesOn ? [RULE_TOOL] : []].map(withConversationIdParam)),
71434
+ openai: withSearchContextConversationDescription([...BILI_ACP_TOOLS_OPENAI, ...absorbOn ? [ABSORB_TOOL_OPENAI] : [], ...rulesOn ? [RULE_TOOL_OPENAI] : []].map(withConversationIdParam)),
71435
+ responses: withSearchContextConversationDescription([...BILI_ACP_TOOLS_RESPONSES, ...absorbOn ? [ABSORB_TOOL_RESPONSES] : [], ...rulesOn ? [RULE_TOOL_RESPONSES] : []].map(withConversationIdParam))
71440
71436
  },
71441
71437
  headers: { agent: PLUGIN_AGENT_HEADER, conversation: PLUGIN_CONVERSATION_HEADER, contextWindow: PLUGIN_CONTEXT_WINDOW_HEADER, maxOutput: PLUGIN_MAX_OUTPUT_HEADER, model: PLUGIN_MODEL_HEADER, instructionsMutable: PLUGIN_INSTRUCTIONS_MUTABLE_HEADER },
71442
71438
  toolEndpoint: "/__bili/plugin/tool",
@@ -71464,6 +71460,13 @@ function resolveConversation(conversationId2) {
71464
71460
  }
71465
71461
  return { session, entry };
71466
71462
  }
71463
+ function disabledOptionalToolNote(tool, session, config) {
71464
+ const absorbName = effectiveAbsorbConfig(session, config)?.toolName ?? ABSORB_TOOL_NAME;
71465
+ if (tool === absorbName) return `${tool} is not enabled on this bili proxy (compress.absorb.enabled is not true) \u2014 nothing was absorbed.`;
71466
+ if (tool === RULE_TOOL_NAME) return `${tool} is not enabled on this bili proxy (compress.rules.enabled is not true) \u2014 nothing was recorded.`;
71467
+ if (!ccrEnabled(session) && tool === retrieveToolName(session)) return `${tool} is not enabled on this bili proxy (compress.ccr.enabled is not true) \u2014 nothing was retrieved.`;
71468
+ return void 0;
71469
+ }
71467
71470
  function handlePluginStatus(conversationId2, res, deps, fallbackLatest = false) {
71468
71471
  const { session: resolvedSession, entry } = resolveConversation(conversationId2);
71469
71472
  let session = resolvedSession;
@@ -71581,6 +71584,13 @@ async function handlePluginTool(payload, res, deps) {
71581
71584
  return;
71582
71585
  }
71583
71586
  if (!isProxyToolFor(tool, session, deps.config)) {
71587
+ const note = disabledOptionalToolNote(tool, session, deps.config);
71588
+ if (note !== void 0) {
71589
+ deps.log("info", `[${session.id}] [plugin] ${tool} called but disabled \u2014 replied with explanation`);
71590
+ res.writeHead(200, { "content-type": "application/json" });
71591
+ res.end(JSON.stringify({ ok: true, result: note }));
71592
+ return;
71593
+ }
71584
71594
  const allowed = [...ACP_TOOL_NAMES];
71585
71595
  const absorb = effectiveAbsorbConfig(session, deps.config);
71586
71596
  if (absorb?.enabled === true) allowed.push(absorb.toolName ?? ABSORB_TOOL_NAME);
@@ -73077,13 +73087,48 @@ function artifactSeedHit(body) {
73077
73087
  return tagSeed || toolSeed;
73078
73088
  }
73079
73089
  function detectAcpArtifacts(body, parsed) {
73080
- if (body.includes("<acp ") && ACP_TAG_RE.test(body.toString("utf8"))) return "tags";
73090
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
73091
+ const encoded = JSON.stringify(historyTextOf(parsed));
73092
+ if (encoded.includes("<acp ") && ACP_TAG_RE.test(encoded)) return "tags";
73093
+ } else if (body.includes("<acp ") && ACP_TAG_RE.test(body.toString("utf8"))) {
73094
+ return "tags";
73095
+ }
73081
73096
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
73082
73097
  const names = historyToolCallNames(parsed);
73083
73098
  if (names.has("acp_status") && names.has("search_context")) return "tool-history";
73084
73099
  }
73085
73100
  return null;
73086
73101
  }
73102
+ function historyTextOf(parsed) {
73103
+ const parts = [];
73104
+ const container = Array.isArray(parsed.messages) ? parsed.messages : Array.isArray(parsed.input) ? parsed.input : Array.isArray(parsed.contents) ? parsed.contents : null;
73105
+ if (container) {
73106
+ for (const item of container) collectHistoryText(item, parts);
73107
+ }
73108
+ return parts.join("\n");
73109
+ }
73110
+ function collectHistoryText(item, out) {
73111
+ if (!item || typeof item !== "object" || Array.isArray(item)) return;
73112
+ const it2 = item;
73113
+ if (it2.role === "system" || it2.role === "developer") return;
73114
+ const content = it2.content;
73115
+ if (typeof content === "string") out.push(content);
73116
+ else if (Array.isArray(content)) {
73117
+ for (const block of content) {
73118
+ if (block && typeof block === "object" && !Array.isArray(block) && typeof block.text === "string") {
73119
+ out.push(block.text);
73120
+ }
73121
+ }
73122
+ }
73123
+ const parts = it2.parts;
73124
+ if (Array.isArray(parts)) {
73125
+ for (const part of parts) {
73126
+ if (part && typeof part === "object" && !Array.isArray(part) && typeof part.text === "string") {
73127
+ out.push(part.text);
73128
+ }
73129
+ }
73130
+ }
73131
+ }
73087
73132
  function historyToolCallNames(parsed) {
73088
73133
  const names = /* @__PURE__ */ new Set();
73089
73134
  const container = Array.isArray(parsed.messages) ? parsed.messages : Array.isArray(parsed.input) ? parsed.input : Array.isArray(parsed.contents) ? parsed.contents : null;
@@ -73604,7 +73649,7 @@ async function handle(req, res, opts, core, config, log2, instanceId, instanceSt
73604
73649
  }
73605
73650
  return;
73606
73651
  }
73607
- if (req.method === "GET" && req.url === "/__bili/plugin/manifest") return handlePluginManifest(res);
73652
+ if (req.method === "GET" && req.url === "/__bili/plugin/manifest") return handlePluginManifest(res, config);
73608
73653
  if (req.method === "GET" && req.url?.startsWith("/__bili/plugin/status")) {
73609
73654
  const query = req.url.slice(req.url.indexOf("?") + 1);
73610
73655
  const params = new URLSearchParams(query);
@@ -73946,7 +73991,8 @@ ${bodyBuffer.toString("utf8")}`);
73946
73991
  const sessionId = anonAffinity ? anonAffinity.sessionId : conversation;
73947
73992
  if (artifactSeed) {
73948
73993
  const artifactKind = detectAcpArtifacts(bodyBuffer, parsed);
73949
- if (artifactKind !== null && !hasProcessedState(sessionId, { protocol })) {
73994
+ const pluginAnnounced = pluginAgentHeader(req.headers) !== void 0;
73995
+ if (artifactKind !== null && !pluginAnnounced && !hasProcessedState(sessionId, { protocol })) {
73950
73996
  if (!warnedChainSessions.has(sessionId)) {
73951
73997
  warnedChainSessions.add(sessionId);
73952
73998
  if (warnedChainSessions.size > WARNED_CHAIN_SESSION_CAP) {