@reinsjs/core 0.14.0 → 0.14.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 +6 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +89 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @reinsjs/core
|
|
2
2
|
|
|
3
|
+
## 0.14.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 831a50a: Tool-change note: when more than 20 tools are added or removed at once (for example an MCP server's credentials expire), that side now lists 20 names and a total instead of every name. Names that appeared earlier in the session (called, referenced, or mentioned in model-visible text) are listed first. `meta.toolsChanged` still records the full diff, and notes with 20 or fewer changes per side are unchanged.
|
|
8
|
+
|
|
3
9
|
## 0.14.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -441,8 +441,14 @@ declare function diffToolNames(previous: readonly string[], next: readonly strin
|
|
|
441
441
|
/**
|
|
442
442
|
* 给模型看的变化说明(英文,进模型上下文)。只列名字:说明在工具表里,重复一遍既费 token 又可能与工具表不一致;
|
|
443
443
|
* 被移除的工具明说"不能再调用",模型才不会按记忆去调一个已经不存在的工具。
|
|
444
|
+
*
|
|
445
|
+
* 一侧超过 `TOOL_CHANGE_LIST_MAX` 件(MCP 凭据过期 / 恢复会一次增删几百件,AdRate 建议 15)只列这么多个、报总数。
|
|
446
|
+
* `tiers` 是优先档,前档先列、档内按字母序;不在任何档的按字母序补足,让模型看得出是哪一类工具变了。
|
|
447
|
+
* `toolsBoundDrafts` 传 [调用过的, 只在文本里出现过的](见 `toolMentionTiers`):往期工具表不进历史,
|
|
448
|
+
* 模型只可能凭记忆去调这些。说明写进日志后每次请求都回放,几百个名字会常驻上下文;
|
|
449
|
+
* 完整增删照旧记在 `meta.toolsChanged` 与 tools_bound,压缩的只是这句话。
|
|
444
450
|
*/
|
|
445
|
-
declare function renderToolChangeNote(diff: ToolNamesDiff): string;
|
|
451
|
+
declare function renderToolChangeNote(diff: ToolNamesDiff, tiers?: readonly ReadonlySet<string>[]): string;
|
|
446
452
|
/**
|
|
447
453
|
* 起步要 append 的草稿:一条 tools_bound,工具表与上一条相比有增删且 `announce` 为真时再加一条 system_note。
|
|
448
454
|
* 顺序固定:快照在前、说明在后 —— 说明是从快照比对得出的,日志里的因果也该这么排。
|
|
@@ -925,6 +931,6 @@ declare function readTimeline(log: EventLog, sessionId: string, opts: ReadTimeli
|
|
|
925
931
|
*/
|
|
926
932
|
|
|
927
933
|
/** 库版本,与 packages/core/package.json 的 version 同步(发布前 `pnpm check:dist` 会核对) */
|
|
928
|
-
declare const REINS_VERSION = "0.14.
|
|
934
|
+
declare const REINS_VERSION = "0.14.1";
|
|
929
935
|
|
|
930
936
|
export { AwaitingCall, BUILTIN_APPROVAL_POLICY, BlobMeta, BlobStore, type BudgetTruncateOptions, BudgetUsagePayload, type CompactionEvent, ContentPart, type ContributionConfig, CoreEventDraft, CoreEventOf, DEFAULT_CUT_TO_RATIO, DEFAULT_MAX_TURNS, DEFAULT_MODEL_INVISIBLE_TYPES, DEFAULT_RESERVE_RATIO, type DecodedToolArguments, type DefaultChainOptions, Event, EventDraft, EventLog, EventSchemaRegistry, type FoldOptions, type FoldedToolResult, type FoldedToolResultOptions, type ForkOptions, INPUT_DRAFT_TYPES, INTERRUPTED_IN_PROGRESS_TEXT, INTERRUPTED_NOT_EXECUTED_TEXT, InMemoryBlobStore, InMemoryEventLog, InMemoryMemoryStore, InMemoryRunLease, Interruption, LoopConfig, LoweringError, type LoweringErrorCode, type MarkedContent, MemoryStore, ModelRef, OUTCOME_UNKNOWN_TEXT, PauseReason, type ProjectOptions, ProjectionBudget, ProjectionContext, ProjectionResult, ProjectionStats, ProjectionStrategy, REINS_VERSION, RUN_MARKER_TYPES, ReadOptions, type ReadTimelineOptions, type RenderManifestOptions, type ReplayOptions, type ReplayResult, type ReplayedTurn, type ResolvedContributions, RunLease, RunResult, RunStateError, type RunStateErrorCode, type RunStatus, RunStop, STOPPED_IN_PROGRESS_TEXT, STOPPED_NOTE, STOPPED_NOT_EXECUTED_TEXT, SerializedRunState, type StopTexts, StoreError, type StoreErrorCode, Stores, SubagentInterruption, type SubagentPause, type SubagentPauseDetail, type ThresholdSummarizer, TokenEstimator, Tool, ToolCallEvent, type ToolNamesDiff, ToolResult, ToolResultEvent, ToolSpec, type ToolsBoundEvent, Trust, UNTRUSTED_CLOSE_TAG, UNTRUSTED_TAG, type VisibilityFilterOptions, assertRunStateShape, awaitingOf, budgetTruncate, computeConfigHash, computeModelDigest, computePendingDigest, computePendingToolsDigest, covers, decodeToolArgumentsText, defaultProjectionChain, defaultThresholdSummary, deferredToolSpecOf, defineTool, diffToolNames, digestArgs, errorMessageOf, escapeUntrustedText, estimateBudgetOf, estimateTextTokens, estimateTotal, foldCompactions, foldedToolResults, forkSession, inputDrafts, isClientTool, isCompaction, isContentPart, isModelOutput, isPinNote, isReplayable, isStopReason, isStopped, isSubagentPause, keptBy, lastRunMarker, lastToolsBound, markUntrusted, markUntrustedText, memoryStore, needsUntrustedMark, normalizeToolOutput, outcomeUnknownText, pausedStateOf, pendingToolCalls, project, readEvents, readTimeline, reinjectPins, renderFoldedToolResults, renderToolChangeNote, replayTurns, resolveSocketContributions, roughTokenEstimate, runLoop, runStatusOf, serializeRunState, signRunState, splitTurns, startedToolCallIds, stopTextsOf, subagentPause, supersededIds, toolBatchOf, toolCallArgumentsMeta, toolResultTrust, toolSpecOf, toolStartedAt, toolsBoundDrafts, untrustedOpenTag, untrustedSourceOf, unwrapToolArguments, uuidv7, validateResume, verifyRunState, visibilityFilter, withStartedAt };
|
package/dist/index.js
CHANGED
|
@@ -1228,13 +1228,95 @@ function diffToolNames(previous, next) {
|
|
|
1228
1228
|
if (added.length === 0 && removed.length === 0) return void 0;
|
|
1229
1229
|
return { added, removed };
|
|
1230
1230
|
}
|
|
1231
|
-
|
|
1231
|
+
var TOOL_CHANGE_LIST_MAX = 20;
|
|
1232
|
+
function renderToolChangeNote(diff, tiers = []) {
|
|
1232
1233
|
const lines = ["Your available tools changed since the previous run."];
|
|
1233
|
-
|
|
1234
|
-
if (
|
|
1235
|
-
lines.push(`
|
|
1234
|
+
const { added, removed } = diff;
|
|
1235
|
+
if (added.length > TOOL_CHANGE_LIST_MAX)
|
|
1236
|
+
lines.push(`Added ${added.length} tools, including ${sampleNames(added, tiers)}.`);
|
|
1237
|
+
else if (added.length > 0) lines.push(`Added: ${added.join(", ")}.`);
|
|
1238
|
+
if (removed.length > TOOL_CHANGE_LIST_MAX)
|
|
1239
|
+
lines.push(
|
|
1240
|
+
`Removed ${removed.length} tools (no longer callable, even if earlier turns used them), including ${sampleNames(removed, tiers)}.`
|
|
1241
|
+
);
|
|
1242
|
+
else if (removed.length > 0)
|
|
1243
|
+
lines.push(`Removed (no longer callable, even if earlier turns used them): ${removed.join(", ")}.`);
|
|
1236
1244
|
return lines.join(" ");
|
|
1237
1245
|
}
|
|
1246
|
+
function sampleNames(names, tiers) {
|
|
1247
|
+
const rank = (n) => {
|
|
1248
|
+
const i = tiers.findIndex((t) => t.has(n));
|
|
1249
|
+
return i < 0 ? tiers.length : i;
|
|
1250
|
+
};
|
|
1251
|
+
const picked = names.map((n, i) => ({ n, i, r: rank(n) })).sort((a, b) => a.r - b.r || a.i - b.i).slice(0, TOOL_CHANGE_LIST_MAX).map((x) => x.n);
|
|
1252
|
+
return `${picked.join(", ")}, and ${names.length - picked.length} more`;
|
|
1253
|
+
}
|
|
1254
|
+
function toolMentionTiers(timeline, candidates) {
|
|
1255
|
+
const wanted = new Set(candidates);
|
|
1256
|
+
const called = /* @__PURE__ */ new Set();
|
|
1257
|
+
const mentioned = /* @__PURE__ */ new Set();
|
|
1258
|
+
const call = (name) => {
|
|
1259
|
+
if (wanted.has(name)) called.add(name);
|
|
1260
|
+
};
|
|
1261
|
+
const scan = (text) => {
|
|
1262
|
+
TOOL_WORD_RE.lastIndex = 0;
|
|
1263
|
+
for (let m = TOOL_WORD_RE.exec(text); m !== null; m = TOOL_WORD_RE.exec(text))
|
|
1264
|
+
if (wanted.has(m[0])) mentioned.add(m[0]);
|
|
1265
|
+
};
|
|
1266
|
+
const scanValue = (v) => {
|
|
1267
|
+
if (typeof v === "string") scan(v);
|
|
1268
|
+
else if (Array.isArray(v)) for (const x of v) scanValue(x);
|
|
1269
|
+
else if (typeof v === "object" && v !== null) for (const x of Object.values(v)) scanValue(x);
|
|
1270
|
+
};
|
|
1271
|
+
const scanParts = (parts) => {
|
|
1272
|
+
for (const part of parts) {
|
|
1273
|
+
if (part.type === "text") scan(part.text);
|
|
1274
|
+
else if (part.type === "tool_reference") call(part.name);
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
for (const e of timeline) {
|
|
1278
|
+
switch (e.type) {
|
|
1279
|
+
case "core.user_message":
|
|
1280
|
+
scanParts(e.payload.content);
|
|
1281
|
+
break;
|
|
1282
|
+
case "core.model_text":
|
|
1283
|
+
scan(e.payload.text);
|
|
1284
|
+
break;
|
|
1285
|
+
case "core.model_thinking":
|
|
1286
|
+
scan(e.payload.text);
|
|
1287
|
+
break;
|
|
1288
|
+
case "core.compaction":
|
|
1289
|
+
scan(e.payload.summary);
|
|
1290
|
+
break;
|
|
1291
|
+
case "core.system_note": {
|
|
1292
|
+
const p = e.payload;
|
|
1293
|
+
if (p.meta?.toolsChanged === void 0) scan(p.text);
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
case "core.tool_call": {
|
|
1297
|
+
const p = e.payload;
|
|
1298
|
+
call(p.name);
|
|
1299
|
+
if (typeof p.args === "string") {
|
|
1300
|
+
try {
|
|
1301
|
+
scanValue(JSON.parse(p.args));
|
|
1302
|
+
} catch {
|
|
1303
|
+
scan(p.args);
|
|
1304
|
+
}
|
|
1305
|
+
} else scanValue(p.args);
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1308
|
+
case "core.tool_result": {
|
|
1309
|
+
const p = e.payload;
|
|
1310
|
+
call(p.name);
|
|
1311
|
+
scanParts(p.content);
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
for (const n of called) mentioned.delete(n);
|
|
1317
|
+
return [called, mentioned];
|
|
1318
|
+
}
|
|
1319
|
+
var TOOL_WORD_RE = /[A-Za-z0-9_-]+/g;
|
|
1238
1320
|
function toolsBoundDrafts(input) {
|
|
1239
1321
|
const toolNames = [...input.toolNames].sort();
|
|
1240
1322
|
const drafts = [
|
|
@@ -1252,10 +1334,11 @@ function toolsBoundDrafts(input) {
|
|
|
1252
1334
|
if (!input.announce || previous === void 0) return drafts;
|
|
1253
1335
|
const diff = diffToolNames(previous.payload.toolNames, toolNames);
|
|
1254
1336
|
if (!diff) return drafts;
|
|
1337
|
+
const tiers = diff.added.length > TOOL_CHANGE_LIST_MAX || diff.removed.length > TOOL_CHANGE_LIST_MAX ? toolMentionTiers(input.timeline, [...diff.added, ...diff.removed]) : [];
|
|
1255
1338
|
drafts.push({
|
|
1256
1339
|
type: "core.system_note",
|
|
1257
1340
|
actor: "host",
|
|
1258
|
-
payload: { kind: "host", text: renderToolChangeNote(diff), meta: { toolsChanged: diff } }
|
|
1341
|
+
payload: { kind: "host", text: renderToolChangeNote(diff, tiers), meta: { toolsChanged: diff } }
|
|
1259
1342
|
});
|
|
1260
1343
|
return drafts;
|
|
1261
1344
|
}
|
|
@@ -2343,7 +2426,7 @@ function memoryStore() {
|
|
|
2343
2426
|
}
|
|
2344
2427
|
|
|
2345
2428
|
// src/index.ts
|
|
2346
|
-
var REINS_VERSION = "0.14.
|
|
2429
|
+
var REINS_VERSION = "0.14.1";
|
|
2347
2430
|
export {
|
|
2348
2431
|
BUILTIN_APPROVAL_POLICY,
|
|
2349
2432
|
CORE_SCHEMAS,
|