billion-context-pi 0.1.40 → 0.1.41
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 +30 -12
- package/dist/index.js.map +1 -1
- package/dist/tag-tokens.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2828,6 +2828,19 @@ function clamp(v, lo, hi) {
|
|
|
2828
2828
|
return v < lo ? lo : v > hi ? hi : v;
|
|
2829
2829
|
}
|
|
2830
2830
|
|
|
2831
|
+
// src/tag-tokens.ts
|
|
2832
|
+
function formatTokens3(tokens) {
|
|
2833
|
+
if (tokens < 1e3) return String(tokens);
|
|
2834
|
+
if (tokens < 1e4) return `${(tokens / 1e3).toFixed(1)}K`;
|
|
2835
|
+
return `${Math.round(tokens / 1e3)}K`;
|
|
2836
|
+
}
|
|
2837
|
+
function stableTagTokens(text) {
|
|
2838
|
+
return formatTokens3(defaultCountTokens(text));
|
|
2839
|
+
}
|
|
2840
|
+
function rewriteTagTokens(tag, body) {
|
|
2841
|
+
return tag.replace(/tokens="[^"]*"/, `tokens="${stableTagTokens(body)}"`);
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2831
2844
|
// src/messages.ts
|
|
2832
2845
|
var REF_TAG_SOURCE = "(?:<acp\\s[^>]*>m\\d{5}</acp>|\\[m\\d{1,5}\\])";
|
|
2833
2846
|
var REF_TAG = new RegExp(`^${REF_TAG_SOURCE}\\s?\\n?`);
|
|
@@ -3037,6 +3050,7 @@ function reconstructToolCallMessage(original, firstCore, survivingCallIds) {
|
|
|
3037
3050
|
return true;
|
|
3038
3051
|
});
|
|
3039
3052
|
const peeled = peelRefTagBlocks(filtered);
|
|
3053
|
+
const stableTag = rewriteTagTokens(tag, coreBodyOf(firstCore.text ?? "", tag));
|
|
3040
3054
|
const lastTextIdx = [...peeled].reverse().findIndex((b) => b.type === "text");
|
|
3041
3055
|
if (lastTextIdx >= 0) {
|
|
3042
3056
|
const idx = peeled.length - 1 - lastTextIdx;
|
|
@@ -3044,10 +3058,16 @@ function reconstructToolCallMessage(original, firstCore, survivingCallIds) {
|
|
|
3044
3058
|
const baseText = lastBlock.text ?? "";
|
|
3045
3059
|
peeled[idx] = { ...lastBlock, text: baseText.length > 0 ? `${baseText}
|
|
3046
3060
|
|
|
3047
|
-
${
|
|
3061
|
+
${stableTag}` : stableTag };
|
|
3048
3062
|
return { ...original, content: peeled };
|
|
3049
3063
|
}
|
|
3050
|
-
return { ...original, content: [{ type: "text", text:
|
|
3064
|
+
return { ...original, content: [{ type: "text", text: stableTag }, ...peeled] };
|
|
3065
|
+
}
|
|
3066
|
+
function coreBodyOf(coreText, tag) {
|
|
3067
|
+
const tagCore = tag.replace(/\s+$/, "");
|
|
3068
|
+
let bodyStart = tagCore.length;
|
|
3069
|
+
if (coreText.charAt(bodyStart) === "\n") bodyStart += 1;
|
|
3070
|
+
return coreText.slice(bodyStart);
|
|
3051
3071
|
}
|
|
3052
3072
|
function patchRefTag(original, core) {
|
|
3053
3073
|
const match = core.text ? core.text.match(REF_TAG) : null;
|
|
@@ -3055,15 +3075,13 @@ function patchRefTag(original, core) {
|
|
|
3055
3075
|
if (!tag) return original;
|
|
3056
3076
|
const base = original;
|
|
3057
3077
|
if (base.role === "assistant") return original;
|
|
3058
|
-
const
|
|
3059
|
-
let bodyStart = tagCore.length;
|
|
3060
|
-
if (core.text && core.text.charAt(bodyStart) === "\n") bodyStart += 1;
|
|
3061
|
-
const coreBody = core.text ? core.text.slice(bodyStart) : "";
|
|
3078
|
+
const coreBody = coreBodyOf(core.text ?? "", tag);
|
|
3062
3079
|
const originalBody = extractText(base.content);
|
|
3063
3080
|
const trimEnd = (s) => s.replace(/\s+$/, "");
|
|
3064
3081
|
if (coreBody && trimEnd(coreBody) !== trimEnd(originalBody)) {
|
|
3065
|
-
return rebuildBodyFromCore(original, coreBody, tag);
|
|
3082
|
+
return rebuildBodyFromCore(original, coreBody, rewriteTagTokens(tag, coreBody));
|
|
3066
3083
|
}
|
|
3084
|
+
const stableTag = rewriteTagTokens(tag, originalBody);
|
|
3067
3085
|
const rawBlocks = Array.isArray(base.content) ? base.content : typeof base.content === "string" ? [{ type: "text", text: base.content }] : [];
|
|
3068
3086
|
const peeled = peelRefTagBlocks(rawBlocks);
|
|
3069
3087
|
const newBlocks = [...peeled];
|
|
@@ -3074,7 +3092,7 @@ function patchRefTag(original, core) {
|
|
|
3074
3092
|
const baseText = b.text.replace(/\n*$/, "");
|
|
3075
3093
|
newBlocks[i] = { ...b, text: `${baseText}
|
|
3076
3094
|
|
|
3077
|
-
${
|
|
3095
|
+
${stableTag}` };
|
|
3078
3096
|
injected = true;
|
|
3079
3097
|
break;
|
|
3080
3098
|
}
|
|
@@ -3084,7 +3102,7 @@ ${tag}` };
|
|
|
3084
3102
|
}
|
|
3085
3103
|
return {
|
|
3086
3104
|
...original,
|
|
3087
|
-
content: [...peeled, { type: "text", text:
|
|
3105
|
+
content: [...peeled, { type: "text", text: stableTag }]
|
|
3088
3106
|
};
|
|
3089
3107
|
}
|
|
3090
3108
|
function rebuildBodyFromCore(original, coreBody, tag) {
|
|
@@ -10088,7 +10106,7 @@ async function statusReport(runtime, ctx) {
|
|
|
10088
10106
|
const modelId = ctx.model?.id ?? "default";
|
|
10089
10107
|
const sentTokens = estimateTokens(coreMessages, coveredIds) + systemPromptTokens;
|
|
10090
10108
|
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: calibrateTokens(sentTokens, runtime.density.densityFor(modelId)) });
|
|
10091
|
-
const versionStr = "0.1.
|
|
10109
|
+
const versionStr = "0.1.41" ? `billion-context-pi@${"0.1.41"}` : void 0;
|
|
10092
10110
|
let text = buildStatusPanel({
|
|
10093
10111
|
version: versionStr,
|
|
10094
10112
|
tokenCount: sessionTokens,
|
|
@@ -10410,7 +10428,7 @@ async function checkForUpdate(autoUpdate, notify) {
|
|
|
10410
10428
|
const data = await res.json();
|
|
10411
10429
|
const latest = data.version;
|
|
10412
10430
|
if (!latest) return;
|
|
10413
|
-
const current = runtimeVersion ?? "0.1.
|
|
10431
|
+
const current = runtimeVersion ?? "0.1.41";
|
|
10414
10432
|
const hasUpdate = isNewer(latest, current);
|
|
10415
10433
|
debug.event("update-check", {
|
|
10416
10434
|
current,
|
|
@@ -10607,7 +10625,7 @@ function wireSessionLifecycle(pi, runtime) {
|
|
|
10607
10625
|
const sid = ctx.sessionManager.getSessionId();
|
|
10608
10626
|
runtime.clearSessionTracking(sid);
|
|
10609
10627
|
const modelInfo = ctx.model;
|
|
10610
|
-
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.
|
|
10628
|
+
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.41" : null, model: modelInfo?.id ?? null, modelApi: modelInfo?.api ?? null, contextWindow: modelInfo?.contextWindow ?? null });
|
|
10611
10629
|
try {
|
|
10612
10630
|
await runtime.reloadConfig(ctx.cwd);
|
|
10613
10631
|
setDelegateDisplayUsage(resolveDelegate(runtime.adapter).displayUsage);
|