@reinsjs/core 0.12.0 → 0.13.0
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 +8 -0
- package/README.md +1 -1
- package/dist/index.d.ts +26 -3
- package/dist/index.js +31 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @reinsjs/core
|
|
2
2
|
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fba2410: "The outcome is unknown" results now end with the time the call started: ` This call started at <ISO UTC with milliseconds>.`, taken from the call's `core.tool_started` event. With identical parameters, the model can only tell what this call created from an earlier object by its creation time, and it had no anchor for that. The time is added only when the tool is known and not replayable (its `tool_started` is written before `execute`); "may have partly taken effect" and "not executed" texts are unchanged.
|
|
8
|
+
|
|
9
|
+
`OUTCOME_UNKNOWN_TEXT` remains an exact prefix of the landed text: compare with `startsWith`, not `===`. New exports: `outcomeUnknownText(tool, at)`, `withStartedAt(text, at)` and `toolStartedAt(timeline)`.
|
|
10
|
+
|
|
3
11
|
## 0.12.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ const deploy = defineTool<{ env: "staging" | "prod" }>({
|
|
|
114
114
|
|
|
115
115
|
`validate` runs before the approval check so the approver sees exactly the input that will execute. Tools without `execute` (or with `side: "client"`) pause the run until the host appends the `tool_result`. Tool output is `untrusted` by default and is wrapped in `<untrusted source="tool:…">` when lowered to the model. A tool may declare `resultTrust: "system"` to opt its **successful** results out of that wrapper — reserve it for content the host itself authored (this is how `@reinsjs/brain`'s `skill_read` works); error results and thrown exceptions stay `untrusted` regardless, and the same rule applies to client-tool results the host appends.
|
|
116
116
|
|
|
117
|
-
**Interrupted writes are not replayed.** A tool that is not replayable — by default any tool not declared `risk: "low"`; override with `replayable: true | false` — gets a model-invisible `core.tool_started` event right before `execute`. If the process dies mid-call (or a signal-aware tool is cut off by an abort), resuming does not run it again: the call is closed with "the outcome is unknown, check the current state before retrying", and the model decides whether to look first. Read-only tools are simply re-run. Declare `risk: "low"` on tools that only read; `replayable: true` on writes that are idempotent.
|
|
117
|
+
**Interrupted writes are not replayed.** A tool that is not replayable — by default any tool not declared `risk: "low"`; override with `replayable: true | false` — gets a model-invisible `core.tool_started` event right before `execute`. If the process dies mid-call (or a signal-aware tool is cut off by an abort), resuming does not run it again: the call is closed with "the outcome is unknown, check the current state before retrying", followed by the time the call started (`This call started at 2026-11-08T16:08:02.123Z.`, from the `core.tool_started` event), and the model decides whether to look first. The time lets the model tell the object this call created from an earlier one with the same parameters; make your read tools report timestamps in an unambiguous form (UTC ISO is safest). The exported text constants are exact prefixes of what lands — compare with `startsWith`, not `===`. Read-only tools are simply re-run. Declare `risk: "low"` on tools that only read; `replayable: true` on writes that are idempotent.
|
|
118
118
|
|
|
119
119
|
A tool can also *be* another agent: return `subagentPause(...)` from `execute` and the run pauses with `Interruption { kind: "subagent" }`, carrying the child session's own interruptions and state. `@reinsjs/agent` ships `asTool(agent, opts)` on top of this.
|
|
120
120
|
|
package/dist/index.d.ts
CHANGED
|
@@ -190,7 +190,8 @@ declare function resolveSocketContributions(cfg: ContributionConfig): Promise<Re
|
|
|
190
190
|
* - `RunStop` / `isStopReason`:停止是中止的一种原因。宿主 `controller.abort(new RunStop())`,循环在暂停时把 pending 收尾成
|
|
191
191
|
* "没执行"等结果,下一个 run 直接问模型;其它中止原因(丢租约、断线)照旧留 pending、恢复时补跑。
|
|
192
192
|
* - `isReplayable`:调用开始动手后中断了,能不能再跑一遍。缺省口径与 approval 的 byRisk 一致:只有 `risk: "low"` 的算可重放。
|
|
193
|
-
* - `startedToolCallIds`:时间线里已经开始动手的调用(`core.tool_started
|
|
193
|
+
* - `startedToolCallIds` / `toolStartedAt`:时间线里已经开始动手的调用(`core.tool_started`)及其开始时间。
|
|
194
|
+
* - `outcomeUnknownText` / `withStartedAt`:"结果未知"缀上调用开始时间(2026-11-09,AdRate 建议 10)。
|
|
194
195
|
*
|
|
195
196
|
* 模型可见的文案在 2026-11-05 用 DeepSeek 与 Claude 实测过(spikes/stop-and-interrupt;"中断"口径两句同日 DeepSeek 补测),改字前先复跑。
|
|
196
197
|
*/
|
|
@@ -240,6 +241,28 @@ declare function isStopped(signal: AbortSignal | undefined): boolean;
|
|
|
240
241
|
declare function isReplayable(tool: Tool): boolean;
|
|
241
242
|
/** 时间线里已经开始动手(有 `core.tool_started`)的 toolCallId */
|
|
242
243
|
declare function startedToolCallIds(timeline: Iterable<Event>): Set<string>;
|
|
244
|
+
/**
|
|
245
|
+
* 时间线里已经开始动手的调用 → 其 `core.tool_started` 的 `at`(循环时钟,毫秒);同一调用若有多条 started,取第一条。
|
|
246
|
+
* 注意:只有不可重放的调用 started 写在 execute 之前、`at` 才是开始时间;可重放的(子代理)是返回 subagentPause 后补写的,
|
|
247
|
+
* `at` 是暂停时刻。拿它当开始时间对外说只能经 `outcomeUnknownText`
|
|
248
|
+
*/
|
|
249
|
+
declare function toolStartedAt(timeline: Iterable<Event>): Map<string, number>;
|
|
250
|
+
/**
|
|
251
|
+
* 给收尾文案句末缀上调用开始时间(AdRate 建议 10)。纯拼接,不判断 `at` 是不是真的开始时间——那是 `outcomeUnknownText` 的事。
|
|
252
|
+
*
|
|
253
|
+
* 缀在句末:常量仍是实际文案的逐字前缀,宿主按 `startsWith` 判断不受影响。时间用 `toISOString()` 原样(UTC、毫秒);
|
|
254
|
+
* `at` 缺失或超出 Date 可表示范围时原样返回——没有锚点就不编一个,也不能因此让收尾抛错
|
|
255
|
+
*/
|
|
256
|
+
declare function withStartedAt(text: string, at: number | undefined): string;
|
|
257
|
+
/**
|
|
258
|
+
* "结果未知"的完整文案(真源索引):runLoop 三处与 TanStack 适配器两处只经这里。
|
|
259
|
+
*
|
|
260
|
+
* 模型"先查再定"时要在查回的业务对象里认出哪条是这次调用产生的;参数相同的旧对象只能靠创建时间区分,而模型看不到事件的 `at`。
|
|
261
|
+
* 只在工具已知且不可重放时缀时间:这时 started 写在 execute 之前,`at` 才是开始时间。工具不在表里时 started 可能是子代理
|
|
262
|
+
* 暂停后补写的(`at` 是暂停时刻,比它建出的对象还晚),说错的锚点会让模型把这次建出的对象当成旧的、再做一遍,宁可不给。
|
|
263
|
+
* 同理"做了一半"两句(只落给可重放的调用)不缀
|
|
264
|
+
*/
|
|
265
|
+
declare function outcomeUnknownText(tool: Tool | undefined, startedAt: number | undefined): string;
|
|
243
266
|
|
|
244
267
|
/**
|
|
245
268
|
* 子代理即工具(§10.1)的暂停标记:`asTool` 这类工具跑的子 run 暂停时,`execute` 返回 `subagentPause(detail)` 而不是结果,
|
|
@@ -801,6 +824,6 @@ declare function readTimeline(log: EventLog, sessionId: string, opts: ReadTimeli
|
|
|
801
824
|
*/
|
|
802
825
|
|
|
803
826
|
/** 库版本,与 packages/core/package.json 的 version 同步(发布前 `pnpm check:dist` 会核对) */
|
|
804
|
-
declare const REINS_VERSION = "0.
|
|
827
|
+
declare const REINS_VERSION = "0.13.0";
|
|
805
828
|
|
|
806
|
-
export { 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, LoopConfig, LoweringError, type LoweringErrorCode, type MarkedContent, MemoryStore, ModelRef, OUTCOME_UNKNOWN_TEXT, type ProjectOptions, ProjectionBudget, ProjectionContext, ProjectionResult, ProjectionStats, ProjectionStrategy, REINS_VERSION, ReadOptions, type ReadTimelineOptions, type RenderManifestOptions, type ReplayOptions, type ReplayResult, type ReplayedTurn, type ResolvedContributions, RunLease, RunResult, RunStateError, type RunStateErrorCode, 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, budgetTruncate, computeConfigHash, computeModelDigest, computePendingDigest, computePendingToolsDigest, covers, decodeToolArgumentsText, defaultProjectionChain, defaultThresholdSummary, deferredToolSpecOf, defineTool, diffToolNames, digestArgs, errorMessageOf, escapeUntrustedText, estimateBudgetOf, estimateTextTokens, estimateTotal, foldCompactions, foldedToolResults, forkSession, inputDrafts, isCompaction, isContentPart, isModelOutput, isPinNote, isReplayable, isStopReason, isStopped, isSubagentPause, keptBy, lastToolsBound, markUntrusted, markUntrustedText, memoryStore, needsUntrustedMark, normalizeToolOutput, pausedStateOf, pendingToolCalls, project, readEvents, readTimeline, reinjectPins, renderFoldedToolResults, renderToolChangeNote, replayTurns, resolveSocketContributions, roughTokenEstimate, runLoop, serializeRunState, signRunState, splitTurns, startedToolCallIds, stopTextsOf, subagentPause, supersededIds, toolBatchOf, toolCallArgumentsMeta, toolResultTrust, toolSpecOf, toolsBoundDrafts, untrustedOpenTag, untrustedSourceOf, unwrapToolArguments, uuidv7, validateResume, verifyRunState, visibilityFilter };
|
|
829
|
+
export { 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, LoopConfig, LoweringError, type LoweringErrorCode, type MarkedContent, MemoryStore, ModelRef, OUTCOME_UNKNOWN_TEXT, type ProjectOptions, ProjectionBudget, ProjectionContext, ProjectionResult, ProjectionStats, ProjectionStrategy, REINS_VERSION, ReadOptions, type ReadTimelineOptions, type RenderManifestOptions, type ReplayOptions, type ReplayResult, type ReplayedTurn, type ResolvedContributions, RunLease, RunResult, RunStateError, type RunStateErrorCode, 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, budgetTruncate, computeConfigHash, computeModelDigest, computePendingDigest, computePendingToolsDigest, covers, decodeToolArgumentsText, defaultProjectionChain, defaultThresholdSummary, deferredToolSpecOf, defineTool, diffToolNames, digestArgs, errorMessageOf, escapeUntrustedText, estimateBudgetOf, estimateTextTokens, estimateTotal, foldCompactions, foldedToolResults, forkSession, inputDrafts, isCompaction, isContentPart, isModelOutput, isPinNote, isReplayable, isStopReason, isStopped, isSubagentPause, keptBy, lastToolsBound, markUntrusted, markUntrustedText, memoryStore, needsUntrustedMark, normalizeToolOutput, outcomeUnknownText, pausedStateOf, pendingToolCalls, project, readEvents, readTimeline, reinjectPins, renderFoldedToolResults, renderToolChangeNote, replayTurns, resolveSocketContributions, roughTokenEstimate, runLoop, 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
|
@@ -661,13 +661,26 @@ function isReplayable(tool) {
|
|
|
661
661
|
return tool.replayable ?? tool.risk === "low";
|
|
662
662
|
}
|
|
663
663
|
function startedToolCallIds(timeline) {
|
|
664
|
-
|
|
664
|
+
return new Set(toolStartedAt(timeline).keys());
|
|
665
|
+
}
|
|
666
|
+
function toolStartedAt(timeline) {
|
|
667
|
+
const started = /* @__PURE__ */ new Map();
|
|
665
668
|
for (const raw of timeline) {
|
|
666
669
|
const e = raw;
|
|
667
|
-
if (e.type === "core.tool_started"
|
|
670
|
+
if (e.type === "core.tool_started" && !started.has(e.payload.toolCallId))
|
|
671
|
+
started.set(e.payload.toolCallId, e.at);
|
|
668
672
|
}
|
|
669
673
|
return started;
|
|
670
674
|
}
|
|
675
|
+
function withStartedAt(text, at) {
|
|
676
|
+
if (at === void 0) return text;
|
|
677
|
+
const date = new Date(at);
|
|
678
|
+
if (Number.isNaN(date.getTime())) return text;
|
|
679
|
+
return `${text} This call started at ${date.toISOString()}.`;
|
|
680
|
+
}
|
|
681
|
+
function outcomeUnknownText(tool, startedAt) {
|
|
682
|
+
return tool !== void 0 && !isReplayable(tool) ? withStartedAt(OUTCOME_UNKNOWN_TEXT, startedAt) : OUTCOME_UNKNOWN_TEXT;
|
|
683
|
+
}
|
|
671
684
|
|
|
672
685
|
// src/loop/retry.ts
|
|
673
686
|
var DEFAULT_RETRY_MAX_ATTEMPTS = 3;
|
|
@@ -1280,12 +1293,13 @@ async function* runLoop(cfg) {
|
|
|
1280
1293
|
const timeline = await readTimeline(log, sessionId, { registry });
|
|
1281
1294
|
const pending = pendingToolCalls(timeline);
|
|
1282
1295
|
if (pending.length === 0) return [];
|
|
1283
|
-
const started =
|
|
1296
|
+
const started = toolStartedAt(timeline);
|
|
1284
1297
|
return append(
|
|
1285
1298
|
pending.map((call) => {
|
|
1286
1299
|
const { toolCallId, name } = call.payload;
|
|
1287
1300
|
const tool = baseTools.find((t) => t.name === name);
|
|
1288
|
-
const
|
|
1301
|
+
const startedAt2 = started.get(toolCallId);
|
|
1302
|
+
const text = startedAt2 === void 0 ? texts.notExecuted : tool !== void 0 && isReplayable(tool) ? texts.inProgress : outcomeUnknownText(tool, startedAt2);
|
|
1289
1303
|
return {
|
|
1290
1304
|
type: "core.tool_result",
|
|
1291
1305
|
actor: "tool",
|
|
@@ -1778,7 +1792,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1778
1792
|
};
|
|
1779
1793
|
const decisions = /* @__PURE__ */ new Map();
|
|
1780
1794
|
const requested = /* @__PURE__ */ new Set();
|
|
1781
|
-
const started =
|
|
1795
|
+
const started = toolStartedAt(timeline);
|
|
1782
1796
|
for (const raw of timeline) {
|
|
1783
1797
|
const e = raw;
|
|
1784
1798
|
if (e.type === "core.approval_decision") decisions.set(e.payload.toolCallId, e.payload);
|
|
@@ -1800,7 +1814,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1800
1814
|
payload: { toolCallId, name, content: [{ type: "text", text }], isError: true }
|
|
1801
1815
|
});
|
|
1802
1816
|
if (started.has(toolCallId) && (tool === void 0 || !isReplayable(tool))) {
|
|
1803
|
-
yield* await settle(errorResult(
|
|
1817
|
+
yield* await settle(errorResult(outcomeUnknownText(tool, started.get(toolCallId))));
|
|
1804
1818
|
continue;
|
|
1805
1819
|
}
|
|
1806
1820
|
const decided = decisions.get(toolCallId);
|
|
@@ -1879,11 +1893,14 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1879
1893
|
const replayable = isReplayable(tool);
|
|
1880
1894
|
const markStarted = async function* () {
|
|
1881
1895
|
if (started.has(toolCallId)) return;
|
|
1882
|
-
started.add(toolCallId);
|
|
1883
1896
|
yield* await flush();
|
|
1884
|
-
|
|
1897
|
+
const [ev] = await append([
|
|
1885
1898
|
{ type: "core.tool_started", actor: "system", parentId: call.id, payload: { toolCallId } }
|
|
1886
1899
|
]);
|
|
1900
|
+
if (ev) {
|
|
1901
|
+
started.set(toolCallId, ev.at);
|
|
1902
|
+
yield ev;
|
|
1903
|
+
}
|
|
1887
1904
|
};
|
|
1888
1905
|
if (!replayable) yield* markStarted();
|
|
1889
1906
|
let result;
|
|
@@ -1909,7 +1926,7 @@ async function* executeToolCalls(ctx, calls, timeline, deps) {
|
|
|
1909
1926
|
};
|
|
1910
1927
|
} catch (err) {
|
|
1911
1928
|
result = errorResult(
|
|
1912
|
-
!replayable && cfg.signal?.aborted ?
|
|
1929
|
+
!replayable && cfg.signal?.aborted ? outcomeUnknownText(tool, started.get(toolCallId)) : `Tool execution failed: ${errorMessageOf(err)}`
|
|
1913
1930
|
);
|
|
1914
1931
|
}
|
|
1915
1932
|
for (const s of sockets) {
|
|
@@ -2194,7 +2211,7 @@ function memoryStore() {
|
|
|
2194
2211
|
}
|
|
2195
2212
|
|
|
2196
2213
|
// src/index.ts
|
|
2197
|
-
var REINS_VERSION = "0.
|
|
2214
|
+
var REINS_VERSION = "0.13.0";
|
|
2198
2215
|
export {
|
|
2199
2216
|
BUILTIN_APPROVAL_POLICY,
|
|
2200
2217
|
CORE_SCHEMAS,
|
|
@@ -2273,6 +2290,7 @@ export {
|
|
|
2273
2290
|
memoryStore,
|
|
2274
2291
|
needsUntrustedMark,
|
|
2275
2292
|
normalizeToolOutput,
|
|
2293
|
+
outcomeUnknownText,
|
|
2276
2294
|
pausedStateOf,
|
|
2277
2295
|
pendingToolCalls,
|
|
2278
2296
|
project,
|
|
@@ -2299,6 +2317,7 @@ export {
|
|
|
2299
2317
|
toolCallArgumentsMeta,
|
|
2300
2318
|
toolResultTrust,
|
|
2301
2319
|
toolSpecOf,
|
|
2320
|
+
toolStartedAt,
|
|
2302
2321
|
toolsBoundDrafts,
|
|
2303
2322
|
untrustedOpenTag,
|
|
2304
2323
|
untrustedSourceOf,
|
|
@@ -2306,6 +2325,7 @@ export {
|
|
|
2306
2325
|
uuidv7,
|
|
2307
2326
|
validateResume,
|
|
2308
2327
|
verifyRunState,
|
|
2309
|
-
visibilityFilter
|
|
2328
|
+
visibilityFilter,
|
|
2329
|
+
withStartedAt
|
|
2310
2330
|
};
|
|
2311
2331
|
//# sourceMappingURL=index.js.map
|