billion-context-omp 0.2.7 → 0.2.8

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
@@ -748,12 +748,6 @@ function renderMessage(message, map, countTokens, strategy, snapshot = null) {
748
748
  if (!cleanText) return { ...message, text: prefix };
749
749
  return { ...message, text: prefix + cleanText };
750
750
  }
751
- function renderVisibleRefs(messages, state, countTokens = (text) => Math.ceil(text.length / 4), strategy = "all") {
752
- const map = state.messageRefs;
753
- return messages.map(
754
- (message) => renderMessage(message, map, countTokens, strategy)
755
- );
756
- }
757
751
  function renderWithSnapshot(messages, state, countTokens = (text) => Math.ceil(text.length / 4), strategy = "all") {
758
752
  const map = state.messageRefs;
759
753
  const snapshot = { ...state.tokenSnapshot ?? {} };
@@ -3693,15 +3687,77 @@ function payloadToCore(payload, fmt2) {
3693
3687
  function coreToPayloadMessages(msgs, fmt2, cacheControls) {
3694
3688
  return fmt2 === "anthropic" ? coreToAnthropic(msgs, cacheControls) : coreToOpenai(msgs);
3695
3689
  }
3696
- function applyWireTagContract(msgs, state) {
3690
+ var ANTHROPIC_CODEC_BLOCKS = /* @__PURE__ */ new Set(["text", "tool_use", "tool_result", "thinking", "image"]);
3691
+ var OPENAI_CODEC_ROLES = /* @__PURE__ */ new Set(["system", "developer", "user", "assistant", "tool"]);
3692
+ function payloadRepresentable(payload, fmt2) {
3693
+ const messages = payload.messages;
3694
+ if (!Array.isArray(messages)) return { ok: false, reason: "messages not an array" };
3695
+ for (const message of messages) {
3696
+ if (message === null || typeof message !== "object") return { ok: false, reason: "message not an object" };
3697
+ const bad = fmt2 === "anthropic" ? unrepresentableAnthropicMessage(message) : unrepresentableOpenaiMessage(message);
3698
+ if (bad) return { ok: false, reason: bad };
3699
+ }
3700
+ return { ok: true };
3701
+ }
3702
+ function unrepresentableAnthropicMessage(message) {
3703
+ const content = message.content;
3704
+ if (content == null || typeof content === "string") return null;
3705
+ if (!Array.isArray(content)) return "content neither string nor block array";
3706
+ for (const block of content) {
3707
+ const type5 = block?.type;
3708
+ if (typeof type5 !== "string" || !ANTHROPIC_CODEC_BLOCKS.has(type5)) {
3709
+ return `anthropic block type ${JSON.stringify(type5) ?? "missing"}`;
3710
+ }
3711
+ if (type5 === "tool_result") {
3712
+ const inner = block.content;
3713
+ if (Array.isArray(inner) && inner.some((c) => c?.type !== "text")) {
3714
+ return "tool_result content carries non-text parts (images are flattened away)";
3715
+ }
3716
+ }
3717
+ if (type5 === "thinking" && block.cache_control != null) {
3718
+ return "cache_control on a thinking block is not re-attached";
3719
+ }
3720
+ }
3721
+ return null;
3722
+ }
3723
+ function unrepresentableOpenaiMessage(message) {
3724
+ const role = message.role;
3725
+ if (typeof role !== "string" || !OPENAI_CODEC_ROLES.has(role)) {
3726
+ return `openai role ${JSON.stringify(role) ?? "missing"}`;
3727
+ }
3728
+ const content = message.content;
3729
+ if (content == null || typeof content === "string") return null;
3730
+ if (!Array.isArray(content)) return "content neither string nor part array";
3731
+ let dataImages = 0;
3732
+ for (const part of content) {
3733
+ if (typeof part === "string") continue;
3734
+ const type5 = part?.type;
3735
+ if (type5 === "text") continue;
3736
+ if (type5 === "image_url" && role === "user") {
3737
+ const url = part?.image_url?.url;
3738
+ if (typeof url !== "string" || !url.startsWith("data:")) return "image_url without a data: URL is dropped";
3739
+ if (++dataImages > 1) return "second image_url in one message is dropped";
3740
+ continue;
3741
+ }
3742
+ return `openai content part type ${JSON.stringify(type5) ?? "missing"}`;
3743
+ }
3744
+ return null;
3745
+ }
3746
+ var renderRefsAll = createRenderRefsNode("all");
3747
+ function applyWireTagContract(msgs, state, scope) {
3748
+ const stripAssistantTags = (m) => m.contentType === "text" && m.role === "assistant" ? { ...m, text: stripRefTag(m.text ?? "") } : m;
3697
3749
  const toolResults = msgs.filter((m) => m.contentType === "tool-result");
3698
- const taggedTools = toolResults.length > 0 ? renderVisibleRefs(toolResults, state, defaultCountTokens, "all") : [];
3699
- const bySource = new Map(toolResults.map((m, i) => [m, taggedTools[i]]));
3700
- return msgs.map((m) => {
3701
- if (m.contentType === "tool-result") return bySource.get(m) ?? m;
3702
- if (m.contentType === "text" && m.role === "assistant") return { ...m, text: stripRefTag(m.text ?? "") };
3703
- return m;
3704
- });
3750
+ if (toolResults.length === 0) return msgs.map(stripAssistantTags);
3751
+ const names = toolCallNames(msgs);
3752
+ const named = toolResults.map((m) => m.toolName ? m : { ...m, toolName: names.get(m.toolCallId ?? "") ?? "tool" });
3753
+ const io = renderRefsAll.run(
3754
+ { messages: named, state, effects: {} },
3755
+ { config: scope.config, tokenCount: scope.tokenCount, countTokens: defaultCountTokens }
3756
+ );
3757
+ if (io.state !== state) state.tokenSnapshot = io.state.tokenSnapshot;
3758
+ const tagged = io.messages;
3759
+ const bySource = new Map(toolResults.map((m, i) => [m, tagged[i]]));
3760
+ return msgs.map((m) => m.contentType === "tool-result" ? bySource.get(m) ?? m : stripAssistantTags(m));
3705
3761
  }
3706
3762
  function coreIdentity(msg) {
3707
3763
  return JSON.stringify({
@@ -4793,7 +4849,7 @@ function renderMessage2(message, map, countTokens, strategy) {
4793
4849
  if (!cleanText) return { ...message, text: prefix };
4794
4850
  return { ...message, text: prefix + cleanText };
4795
4851
  }
4796
- function renderVisibleRefs2(messages, state, countTokens = (text) => Math.ceil(text.length / 4), strategy = "all") {
4852
+ function renderVisibleRefs(messages, state, countTokens = (text) => Math.ceil(text.length / 4), strategy = "all") {
4797
4853
  const map = state.messageRefs;
4798
4854
  return messages.map(
4799
4855
  (message) => renderMessage2(message, map, countTokens, strategy)
@@ -4805,7 +4861,7 @@ function createRenderRefsNode2(strategy) {
4805
4861
  run(io, ctx) {
4806
4862
  return {
4807
4863
  ...io,
4808
- messages: renderVisibleRefs2(io.messages, io.state, ctx.countTokens, strategy)
4864
+ messages: renderVisibleRefs(io.messages, io.state, ctx.countTokens, strategy)
4809
4865
  };
4810
4866
  }
4811
4867
  };
@@ -5416,7 +5472,7 @@ async function statusReport(runtime, ctx) {
5416
5472
  const coveredIds = collectCoveredMessageIds(state);
5417
5473
  const sentTokens = estimateTokens(coreMessages, coveredIds) + systemPromptTokens;
5418
5474
  const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: sentTokens });
5419
- const versionStr = "0.2.7" ? `billion-context-omp@${"0.2.7"}` : void 0;
5475
+ const versionStr = "0.2.8" ? `billion-context-omp@${"0.2.8"}` : void 0;
5420
5476
  return buildStatusPanel({
5421
5477
  version: versionStr,
5422
5478
  tokenCount: sessionTokens,
@@ -5710,7 +5766,7 @@ async function checkForUpdate(autoUpdate, notify) {
5710
5766
  const data = await res.json();
5711
5767
  const latest = data.version;
5712
5768
  if (!latest) return;
5713
- const current = runtimeVersion ?? "0.2.7";
5769
+ const current = runtimeVersion ?? "0.2.8";
5714
5770
  const hasUpdate = isNewer(latest, current);
5715
5771
  debug.event("update-check", {
5716
5772
  current,
@@ -5985,9 +6041,9 @@ var index_default = createAcpExtension();
5985
6041
  function wireSessionLifecycle(pi, runtime) {
5986
6042
  pi.on("session_start", async (_event, ctx) => {
5987
6043
  const sid = ctx.sessionManager.getSessionId();
5988
- logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.2.7" : null });
6044
+ logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.2.8" : null });
5989
6045
  const selfPath = import.meta.url;
5990
- const conflict = stampAndDetect(selfPath, true ? "0.2.7" : null);
6046
+ const conflict = stampAndDetect(selfPath, true ? "0.2.8" : null);
5991
6047
  if (conflict) {
5992
6048
  logWarn("instance", { event: "dual-instance", self: selfPath, other: conflict.path, otherPid: conflict.pid, otherVersion: conflict.version });
5993
6049
  try {
@@ -6174,6 +6230,12 @@ function wireProviderTransform(pi, runtime) {
6174
6230
  debug.event("provider-transform-unknown-format", { sid });
6175
6231
  return void 0;
6176
6232
  }
6233
+ const representable = payloadRepresentable(payload, fmt2);
6234
+ if (!representable.ok) {
6235
+ logInfo("provider-transform", { sid, fmt: fmt2, event: "unrepresentable", reason: representable.reason });
6236
+ debug.event("provider-transform-unrepresentable", { sid, fmt: fmt2, reason: representable.reason });
6237
+ return void 0;
6238
+ }
6177
6239
  try {
6178
6240
  const { msgs, cacheControls } = payloadToCore(payload, fmt2);
6179
6241
  if (msgs.length === 0) return void 0;
@@ -6256,7 +6318,8 @@ async function transformStreamCore(ctx, runtime, wireMsgs, fmt2) {
6256
6318
  });
6257
6319
  const coreOut = applyWireTagContract(
6258
6320
  turn.messages.filter((m) => !m.id.startsWith("acp_summary_")),
6259
- turn.state
6321
+ turn.state,
6322
+ { config, tokenCount }
6260
6323
  );
6261
6324
  let nudgeInjected = false;
6262
6325
  if (turn.nudge?.shouldInject) {