@reinsjs/core 0.14.1 → 0.15.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 +6 -0
- package/README.md +1 -0
- package/dist/{core-BhmO9N-j.d.ts → core-iqk8S_mU.d.ts} +24 -3
- package/dist/index.d.ts +77 -5
- package/dist/index.js +74 -7
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @reinsjs/core
|
|
2
2
|
|
|
3
|
+
## 0.15.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f8a3550: Pause codes: a socket’s `onTurnEnd` may now return `{ pause: { reason, code, note } }`. The `code` (your own identifier such as `acme.credits_exhausted`, format `PAUSE_CODE_RE`) and the note are written into `core.run_paused`, the code is on the live `Interruption` and on `RunStatus.paused.code`, so a later request or another process can tell why a run paused. reins never branches on it and it is not part of the resume state. The loop’s own `maxTurns` pause carries `reins.max_turns`. A code that does not match the format is dropped: the run still pauses, and a model-invisible `core.error` (category `input`, `detail.phase: "onTurnEnd"`) is logged before the `core.run_paused`. A `reason` other than `"budget"` / `"host"` is handled the same way and pauses with `host`. New exports: `PAUSE_CODE_RE`, `isPauseCode`, `MAX_TURNS_PAUSE_CODE`, `resolveSocketPause`, `pauseDetailOf`. Note: `core.run_paused` now also records the `note` of loop-originated pauses (aborts, user stop, `maxTurns`), so code that compares that payload for exact equality sees a new optional field.
|
|
8
|
+
|
|
3
9
|
## 0.14.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -137,6 +137,7 @@ A `Socket` is the seam brain modules use — five hooks (`beforeModel`, `afterMo
|
|
|
137
137
|
- **Bounded retry only on zero output.** A transient failure (network, 5xx, 429 — decided from the status code first, keywords only as a fallback) is retried up to 3 times, but never after a partial response has been appended: the log must not contain two half answers.
|
|
138
138
|
- **Rollback caveat (0.10).** Sessions that contain a `core.tool_started` event cannot be read by `@reinsjs/core` 0.9 or earlier (unknown event types are rejected).
|
|
139
139
|
- **Every run is bracketed (0.14).** `runLoop` starts each run with a model-invisible `core.tools_bound` (`marksEnd: true`) and ends it with exactly one end marker: `core.run_paused` for a pause (now with `awaiting` — the calls waiting on an approval, a client tool or a sub-agent — and `stopped` for a user stop), or `core.run_ended` with `status: "done" | "handoff" | "error"`. A `core.error` the loop retries past, or one from a throwing `pullInput`, gets no `run_ended`. `runStatusOf({ held, lastMarker })` turns a lease flag and `lastRunMarker(timeline)` into running / paused / done / handoff / error / interrupted / idle / unknown; `@reinsjs/store-pg` has `pgRunStates` for a whole session list in one statement. Sessions containing `core.run_ended` cannot be read by 0.13 or earlier: upgrade every instance together and do not roll back.
|
|
140
|
+
- **Pause codes (0.15).** A socket's `pause` may carry a `code` — your own short identifier such as `acme.credits_exhausted` — next to `reason` and `note`. It is written into `core.run_paused` together with the note and comes back as `RunStatus.paused.code`, so another request or process can tell why the run paused without guessing. reins never branches on it and it is not part of the resume state. Format: `PAUSE_CODE_RE` (lowercase letters, digits, `_ . : -`, starting with a letter or digit, at most 64 characters); a code that does not match is dropped — the run still pauses, and a model-invisible `core.error` (category `input`, `detail.phase: "onTurnEnd"`, no `run_ended` after it) is logged just before the `core.run_paused`. The same happens when `reason` is anything but `"budget"` or `"host"`: the run pauses with `host`. Put your own reasons in `code`. The `reins.` prefix is used by built-in sources: `reins.max_turns` (the loop's `maxTurns` limit), `reins.budget` and `reins.compact_stalled` (from `@reinsjs/brain`). Aborts and user stops carry no code. A paused sub-agent's code stays in the child session — look it up through `awaiting[].childSessionId`.
|
|
140
141
|
- **Deterministic given the log.** Time and ids are injected (`now`, `newId`), so a recorded session replays byte-for-byte in tests.
|
|
141
142
|
|
|
142
143
|
## Documentation
|
|
@@ -714,9 +714,16 @@ interface HandoffIntent {
|
|
|
714
714
|
}
|
|
715
715
|
type TurnDecision = "continue" | "stop" | {
|
|
716
716
|
handoff: HandoffIntent;
|
|
717
|
-
}
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* 暂停。`code` 是可选的原因码(2026-11-23,AdRate 建议 16):随 `note` 写进 `core.run_paused`,`runStatusOf` 带出,
|
|
720
|
+
* 事后分得清是谁、为什么停的。只是标注,库不按它做分支;格式见 `PAUSE_CODE_RE`,不合规的码被丢掉并记一条非终结 `core.error`,照常暂停。
|
|
721
|
+
* `reins.` 前缀留给内置来源,宿主用自己的前缀
|
|
722
|
+
*/
|
|
723
|
+
| {
|
|
718
724
|
pause: {
|
|
719
725
|
reason: "budget" | "host";
|
|
726
|
+
code?: string;
|
|
720
727
|
note?: string;
|
|
721
728
|
};
|
|
722
729
|
};
|
|
@@ -851,12 +858,16 @@ type Interruption = {
|
|
|
851
858
|
kind: "client_tool";
|
|
852
859
|
toolCallId: string;
|
|
853
860
|
call: ToolCallPayload;
|
|
854
|
-
}
|
|
861
|
+
}
|
|
862
|
+
/** `code`:Socket 给的原因码,或内置来源的 `reins.*`(见 pause-code.ts);宿主中止、用户停止不带 */
|
|
863
|
+
| {
|
|
855
864
|
kind: "budget";
|
|
856
865
|
note: string;
|
|
866
|
+
code?: string;
|
|
857
867
|
} | {
|
|
858
868
|
kind: "host";
|
|
859
869
|
note: string;
|
|
870
|
+
code?: string;
|
|
860
871
|
} | SubagentInterruption;
|
|
861
872
|
/**
|
|
862
873
|
* 子代理即工具(§10.1,`asTool`)的暂停冒泡:工具里跑的子 run 暂停了,父 run 不落这条 tool_result(调用留作 pending),
|
|
@@ -1190,6 +1201,16 @@ interface BudgetUsagePayload {
|
|
|
1190
1201
|
}
|
|
1191
1202
|
interface RunPausedPayload {
|
|
1192
1203
|
reason: "approval" | "budget" | "host";
|
|
1204
|
+
/**
|
|
1205
|
+
* 这次暂停的原因码(2026-11-23,AdRate 建议 16):Socket 暂停时给的,或内置来源的 `reins.*`(轮数兜底、budget、compact)。
|
|
1206
|
+
* 只是标注,库不按它做任何分支;格式见 `PAUSE_CODE_RE`。宿主中止、用户停止、审批 / 客户端工具 / 子代理的暂停不带。
|
|
1207
|
+
* 可选字段,不升版本
|
|
1208
|
+
*/
|
|
1209
|
+
code?: string;
|
|
1210
|
+
/**
|
|
1211
|
+
* 给人看的说明,与本次 `Interruption.note` 是同一句(budget / host 那条)。排查用,不进 `RunStatus`。可选字段,不升版本
|
|
1212
|
+
*/
|
|
1213
|
+
note?: string;
|
|
1193
1214
|
/** 序列化 run 状态的外部引用(宿主 KV 键、URL 参数等),可选 */
|
|
1194
1215
|
stateRef?: string;
|
|
1195
1216
|
/**
|
|
@@ -1303,4 +1324,4 @@ type ExtEvent = Event<`ext.${string}`, unknown>;
|
|
|
1303
1324
|
/** 日志里可能出现的任何事件 */
|
|
1304
1325
|
type AnyEvent = CoreEvent | ExtEvent;
|
|
1305
1326
|
|
|
1306
|
-
export {
|
|
1327
|
+
export { DEFAULT_RETRY_MAX_DELAY_MS as $, type AwaitingCall as A, type BudgetUsagePayload as B, type ContentPart as C, type ApprovalDecisionInput as D, type Event as E, type ApprovalDecisionPayload as F, type ApprovalRequestPayload as G, type ApprovalRequestSpec as H, type Interruption as I, type AudioPart as J, type BeforeModelPatch as K, type LoopConfig as L, type ModelRef as M, type BeforeToolDecision as N, type BoundModel as O, type PauseReason as P, CORE_SCHEMAS as Q, type RunResult as R, type SerializedRunState as S, type ToolCallEvent as T, type CompactionPayload as U, type CoreEvent as V, type CoreEventPayloads as W, type CoreEventType as X, type CreateEventInput as Y, DEFAULT_RETRY_BASE_DELAY_MS as Z, DEFAULT_RETRY_MAX_ATTEMPTS as _, type ToolResultEvent as a, createEvent as a$, DEFAULT_TRUST as a0, type ErrorEventPayload as a1, type EventBase as a2, type EventSchema as a3, type ExtEvent as a4, type HandoffIntent as a5, type HandoffPayload as a6, type ImagePart as a7, type LandingRecord as a8, type LandingSpec as a9, type SkillSource as aA, type Socket as aB, type SocketSetup as aC, type StaticContribution as aD, type SystemNotePayload as aE, type TextPart as aF, type ToRequestInput as aG, type TokenUsage as aH, type ToolBatch as aI, type ToolCallPayload as aJ, type ToolContext as aK, type ToolReferencePart as aL, type ToolResultDraft as aM, type ToolResultPayload as aN, type ToolSide as aO, type ToolStartedPayload as aP, type ToolsBoundPayload as aQ, type TurnContext as aR, type TurnDecision as aS, type Upcaster as aT, type UserMessagePayload as aU, type VideoPart as aV, backoffDelayMs as aW, contextOverheadOf as aX, contextTokensOf as aY, createCoreEvent as aZ, createCoreRegistry as a_, type LossKind as aa, type LossMatrix as ab, type LoweredRequest as ac, type Lowering as ad, type LoweringCapabilities as ae, type LoweringDelta as af, type LoweringOutcome as ag, type LoweringStreamContext as ah, type MaybePromise as ai, type MemoryOpPayload as aj, type ModelCallFailure as ak, type ModelTextPayload as al, type ModelThinkingPayload as am, type Principal as an, type ProjectionStep as ao, type ProjectionStepStats as ap, type Provenance as aq, type PullInputContext as ar, type ResolvedRetry as as, type RetryOptions as at, type RunEndedPayload as au, type RunPausedPayload as av, type RunResumedPayload as aw, SchemaError as ax, type SchemaErrorCode as ay, type SessionInfo as az, type EventLog as b, defaultSleep as b0, isTransientFailure as b1, lossesOf as b2, renderToolReference as b3, resolveRetry as b4, statusFromMessage as b5, type ErrorPayload as c, type EventDraft as d, type Tool as e, EventSchemaRegistry as f, type SubagentInterruption as g, type ToolSpec as h, type ToolResult as i, type Trust as j, type CoreEventOf as k, type CoreEventDraft as l, type ProjectionBudget as m, type ProjectionStrategy as n, type ProjectionContext as o, type TokenEstimator as p, type ProjectionResult as q, type ProjectionStats as r, type BlobStore as s, type BlobMeta as t, type ReadOptions as u, type MemoryStore as v, type RunLease as w, type Stores as x, type Actor as y, type AnyEvent as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as Event, T as ToolCallEvent, a as ToolResultEvent, b as EventLog, L as LoopConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { E as Event, T as ToolCallEvent, a as ToolResultEvent, b as EventLog, I as Interruption, c as ErrorPayload, L as LoopConfig, d as EventDraft, R as RunResult, P as PauseReason, A as AwaitingCall, e as Tool, f as EventSchemaRegistry, S as SerializedRunState, M as ModelRef, g as SubagentInterruption, h as ToolSpec, C as ContentPart, i as ToolResult, j as Trust, k as CoreEventOf, l as CoreEventDraft, m as ProjectionBudget, n as ProjectionStrategy, o as ProjectionContext, p as TokenEstimator, q as ProjectionResult, r as ProjectionStats, B as BudgetUsagePayload, s as BlobStore, t as BlobMeta, u as ReadOptions, v as MemoryStore, w as RunLease, x as Stores } from './core-iqk8S_mU.js';
|
|
2
|
+
export { y as Actor, z as AnyEvent, D as ApprovalDecisionInput, F as ApprovalDecisionPayload, G as ApprovalRequestPayload, H as ApprovalRequestSpec, J as AudioPart, K as BeforeModelPatch, N as BeforeToolDecision, O as BoundModel, Q as CORE_SCHEMAS, U as CompactionPayload, V as CoreEvent, W as CoreEventPayloads, X as CoreEventType, Y as CreateEventInput, Z as DEFAULT_RETRY_BASE_DELAY_MS, _ as DEFAULT_RETRY_MAX_ATTEMPTS, $ as DEFAULT_RETRY_MAX_DELAY_MS, a0 as DEFAULT_TRUST, a1 as ErrorEventPayload, a2 as EventBase, a3 as EventSchema, a4 as ExtEvent, a5 as HandoffIntent, a6 as HandoffPayload, a7 as ImagePart, a8 as LandingRecord, a9 as LandingSpec, aa as LossKind, ab as LossMatrix, ac as LoweredRequest, ad as Lowering, ae as LoweringCapabilities, af as LoweringDelta, ag as LoweringOutcome, ah as LoweringStreamContext, ai as MaybePromise, aj as MemoryOpPayload, ak as ModelCallFailure, al as ModelTextPayload, am as ModelThinkingPayload, an as Principal, ao as ProjectionStep, ap as ProjectionStepStats, aq as Provenance, ar as PullInputContext, as as ResolvedRetry, at as RetryOptions, au as RunEndedPayload, av as RunPausedPayload, aw as RunResumedPayload, ax as SchemaError, ay as SchemaErrorCode, az as SessionInfo, aA as SkillSource, aB as Socket, aC as SocketSetup, aD as StaticContribution, aE as SystemNotePayload, aF as TextPart, aG as ToRequestInput, aH as TokenUsage, aI as ToolBatch, aJ as ToolCallPayload, aK as ToolContext, aL as ToolReferencePart, aM as ToolResultDraft, aN as ToolResultPayload, aO as ToolSide, aP as ToolStartedPayload, aQ as ToolsBoundPayload, aR as TurnContext, aS as TurnDecision, aT as Upcaster, aU as UserMessagePayload, aV as VideoPart, aW as backoffDelayMs, aX as contextOverheadOf, aY as contextTokensOf, aZ as createCoreEvent, a_ as createCoreRegistry, a$ as createEvent, b0 as defaultSleep, b1 as isTransientFailure, b2 as lossesOf, b3 as renderToolReference, b4 as resolveRetry, b5 as statusFromMessage } from './core-iqk8S_mU.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* UUID v7 生成(RFC 9562):前 48 位为 Unix 毫秒时间戳,字典序即时间序。
|
|
@@ -39,6 +39,70 @@ declare function forkSession(log: EventLog, opts: ForkOptions): Promise<{
|
|
|
39
39
|
toSessionId: string;
|
|
40
40
|
}>;
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* 暂停原因码(2026-11-23,AdRate 建议 16)。
|
|
44
|
+
*
|
|
45
|
+
* `reason` 是三选一的闭集(approval / budget / host),事后只凭它分不清"是谁、为什么停的":积分用完、预算触顶、
|
|
46
|
+
* 连续整理失败落库后都是 budget。Socket 暂停时可以再带一个原因码 `code`,随 `note` 一起写进 `core.run_paused`,
|
|
47
|
+
* `runStatusOf` 带出 `code`——另一个请求、另一个进程、列表轮询都读得到暂停那一刻的原因(宪法二)。
|
|
48
|
+
*
|
|
49
|
+
* `code` 只是标注:库不解释它、不按它做任何分支,也不进续跑状态与签名。`reins.` 前缀留给内置来源
|
|
50
|
+
* (循环的 `MAX_TURNS_PAUSE_CODE`、brain 的 budget / compact),靠约定不靠校验——循环分不出一个 Socket 是内置的还是宿主的;
|
|
51
|
+
* 宿主用自己的前缀(如 `acme.credits_exhausted`)。
|
|
52
|
+
*
|
|
53
|
+
* 标注写错不能改变结局:Socket 要求暂停就一定暂停(那是边界动作,也只有暂停才带续跑凭据)。意见里不合规的地方
|
|
54
|
+
* 被改正(码丢掉、reason 退成 host),改正处记一条模型不可见的非终结 `core.error`——不静默,也不把受控暂停变成 error。
|
|
55
|
+
*
|
|
56
|
+
* 这里是口径的唯一一处(真源索引):格式判定 `isPauseCode` 写入与读取共用;Socket 的暂停意见怎么变成一条中断
|
|
57
|
+
* (`resolveSocketPause`)、中断怎么变成 `run_paused` 里的字段(`pauseDetailOf`),runLoop 与 TanStack 适配器调同一对函数。
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 原因码的格式:小写字母或数字开头,其后小写字母 / 数字 / `_` `.` `:` `-`,总长 1~64。
|
|
62
|
+
* 收这么紧是为了让它在下游能直接当标识符用(前端文案键、日志字段、switch 的 case),而不是一句自由文本。
|
|
63
|
+
* 只许收紧不许放宽:读侧对不合规的码判 unknown,放宽之后老版本的读者会把带新码的会话整个判成 unknown(连 awaiting 一起丢),
|
|
64
|
+
* 真要放宽得按"所有实例一起升级、不回滚"对待
|
|
65
|
+
*/
|
|
66
|
+
declare const PAUSE_CODE_RE: RegExp;
|
|
67
|
+
/** 写入(循环校验 Socket 给的码)与读取(`runStatusOf` 的形状守卫)共用的格式判定 */
|
|
68
|
+
declare function isPauseCode(x: unknown): x is string;
|
|
69
|
+
/** 循环自带的轮数兜底(`LoopConfig.maxTurns`)触顶时的原因码 */
|
|
70
|
+
declare const MAX_TURNS_PAUSE_CODE = "reins.max_turns";
|
|
71
|
+
/** Socket 暂停产生的中断:budget / host 两种,可带原因码 */
|
|
72
|
+
type SocketPauseInterruption = Extract<Interruption, {
|
|
73
|
+
kind: "budget" | "host";
|
|
74
|
+
}>;
|
|
75
|
+
interface SocketPauseResolution {
|
|
76
|
+
/** 按这条中断暂停:`kind` 即暂停原因 */
|
|
77
|
+
interruption: SocketPauseInterruption;
|
|
78
|
+
/**
|
|
79
|
+
* 意见里有不合规、已被改正的地方时给出:调用方在暂停之前把它记成一条非终结的 `core.error`(模型不可见)。
|
|
80
|
+
* 全合规时没有这个字段
|
|
81
|
+
*/
|
|
82
|
+
error?: ErrorPayload;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Socket 的暂停意见 → 一条中断:补上缺省 note,校验 reason 与 code。永不抛错、永远给得出一条可暂停的中断:
|
|
86
|
+
* - `reason` 不是 budget / host(JS 宿主想自定义原因时最容易这么写)→ 按 host 暂停。照原样写进 `run_paused` 的话
|
|
87
|
+
* `runStatusOf` 只能判 unknown,自定义原因该放进 `code`;
|
|
88
|
+
* - `code` 不满足 `isPauseCode` → 丢掉,不合规的码不进时间线。
|
|
89
|
+
* 入参按 unknown 对待:类型挡得住 TS 宿主,挡不住 JS 宿主与运行时算出来的码
|
|
90
|
+
*/
|
|
91
|
+
declare function resolveSocketPause(pause: {
|
|
92
|
+
reason: unknown;
|
|
93
|
+
code?: unknown;
|
|
94
|
+
note?: string;
|
|
95
|
+
}): SocketPauseResolution;
|
|
96
|
+
/**
|
|
97
|
+
* 一次暂停的中断列表 → 写进 `core.run_paused` 的原因码与说明:取 budget / host 那一条(一次暂停里至多一条)。
|
|
98
|
+
* 审批 / 客户端工具 / 子代理的暂停没有这一条,返回空对象——它们等的是谁已经在 `awaiting` 里;
|
|
99
|
+
* 子代理自己的原因码不上浮,按 `awaiting[].childSessionId` 查子会话
|
|
100
|
+
*/
|
|
101
|
+
declare function pauseDetailOf(interruptions: readonly Interruption[]): {
|
|
102
|
+
code?: string;
|
|
103
|
+
note?: string;
|
|
104
|
+
};
|
|
105
|
+
|
|
42
106
|
/**
|
|
43
107
|
* runLoop:reins 的默认循环(技术方案 §2、§6、§7)。
|
|
44
108
|
*
|
|
@@ -161,6 +225,11 @@ type RunStatus = {
|
|
|
161
225
|
stopped: boolean;
|
|
162
226
|
/** 老版本写的 run_paused 不带,为 undefined */
|
|
163
227
|
awaiting: AwaitingCall[] | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* 暂停原因码(AdRate 建议 16):Socket 暂停时给的,或内置来源的 `reins.*`。没给码的暂停(宿主中止、用户停止、
|
|
230
|
+
* 审批 / 客户端工具 / 子代理)与老版本写的事件没有这个字段。给人看的 `note` 只在事件里,不进这里
|
|
231
|
+
*/
|
|
232
|
+
code?: string;
|
|
164
233
|
};
|
|
165
234
|
/**
|
|
166
235
|
* 纯函数:租约 + 最后一条 run 标记 → 运行状态(真源索引)。
|
|
@@ -579,7 +648,10 @@ declare function estimateBudgetOf(budget: ProjectionBudget): number;
|
|
|
579
648
|
/**
|
|
580
649
|
* 默认对模型不可见的运维事件。它们服务于宿主与审计,对模型没有信息量或已由别的事件承载:
|
|
581
650
|
* - approval_*:审批结果由 B7 以 tool_result(isError) 告知模型
|
|
582
|
-
* - run_paused / run_resumed
|
|
651
|
+
* - run_paused / run_resumed:run 的起止记录,只给宿主判状态与续跑用;没有模块把它转述给模型
|
|
652
|
+
* (宿主想让模型知道上次为什么停,自己按 run_paused 的原因码写一条 system_note)
|
|
653
|
+
* - budget_usage:用量记录,感知模块把要点提炼进 system_note
|
|
654
|
+
* - memory_op:记忆读写的审计记录,模型已从工具结果得知
|
|
583
655
|
* - handoff:交接后当前会话结束,新会话首条 user 消息承载 triggerMessage
|
|
584
656
|
* - error:provider 级错误由循环层处理;工具错误已在 tool_result.isError
|
|
585
657
|
* - tools_bound:每次 run 起步的工具表快照(P1);工具表本身在请求里,增删由循环以 system_note(kind=host) 告知模型
|
|
@@ -931,6 +1003,6 @@ declare function readTimeline(log: EventLog, sessionId: string, opts: ReadTimeli
|
|
|
931
1003
|
*/
|
|
932
1004
|
|
|
933
1005
|
/** 库版本,与 packages/core/package.json 的 version 同步(发布前 `pnpm check:dist` 会核对) */
|
|
934
|
-
declare const REINS_VERSION = "0.
|
|
1006
|
+
declare const REINS_VERSION = "0.15.0";
|
|
935
1007
|
|
|
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 };
|
|
1008
|
+
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, ErrorPayload, 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, MAX_TURNS_PAUSE_CODE, type MarkedContent, MemoryStore, ModelRef, OUTCOME_UNKNOWN_TEXT, PAUSE_CODE_RE, 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 SocketPauseInterruption, type SocketPauseResolution, 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, isPauseCode, isPinNote, isReplayable, isStopReason, isStopped, isSubagentPause, keptBy, lastRunMarker, lastToolsBound, markUntrusted, markUntrustedText, memoryStore, needsUntrustedMark, normalizeToolOutput, outcomeUnknownText, pauseDetailOf, pausedStateOf, pendingToolCalls, project, readEvents, readTimeline, reinjectPins, renderFoldedToolResults, renderToolChangeNote, replayTurns, resolveSocketContributions, resolveSocketPause, 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
|
@@ -616,6 +616,56 @@ async function forkSession(log, opts) {
|
|
|
616
616
|
return { toSessionId };
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
+
// src/loop/pause-code.ts
|
|
620
|
+
var PAUSE_CODE_RE = /^[a-z0-9][a-z0-9_.:-]{0,63}$/;
|
|
621
|
+
function isPauseCode(x) {
|
|
622
|
+
return typeof x === "string" && PAUSE_CODE_RE.test(x);
|
|
623
|
+
}
|
|
624
|
+
var MAX_TURNS_PAUSE_CODE = "reins.max_turns";
|
|
625
|
+
function describeValue(value) {
|
|
626
|
+
if (typeof value !== "string") return value === null ? "null" : typeof value;
|
|
627
|
+
return JSON.stringify(value.length > 80 ? `${value.slice(0, 80)}\u2026` : value);
|
|
628
|
+
}
|
|
629
|
+
function resolveSocketPause(pause) {
|
|
630
|
+
const problems = [];
|
|
631
|
+
let kind;
|
|
632
|
+
if (pause.reason === "budget" || pause.reason === "host") {
|
|
633
|
+
kind = pause.reason;
|
|
634
|
+
} else {
|
|
635
|
+
kind = "host";
|
|
636
|
+
problems.push(
|
|
637
|
+
`pause.reason must be "budget" or "host", got ${describeValue(pause.reason)}; paused with reason "host" instead.`
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
let code;
|
|
641
|
+
if (isPauseCode(pause.code)) {
|
|
642
|
+
code = pause.code;
|
|
643
|
+
} else if (pause.code !== void 0) {
|
|
644
|
+
problems.push(
|
|
645
|
+
`pause.code must match ${PAUSE_CODE_RE.source}, got ${describeValue(pause.code)}; the code was dropped.`
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
const note = pause.note ?? `a socket requested a pause (${kind})`;
|
|
649
|
+
const interruption = { kind, note, ...code !== void 0 ? { code } : {} };
|
|
650
|
+
if (problems.length === 0) return { interruption };
|
|
651
|
+
return {
|
|
652
|
+
interruption,
|
|
653
|
+
error: {
|
|
654
|
+
category: "input",
|
|
655
|
+
message: problems.join(" "),
|
|
656
|
+
retryable: false,
|
|
657
|
+
detail: { phase: "onTurnEnd" }
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function pauseDetailOf(interruptions) {
|
|
662
|
+
for (const i of interruptions) {
|
|
663
|
+
if (i.kind !== "budget" && i.kind !== "host") continue;
|
|
664
|
+
return { ...i.code !== void 0 ? { code: i.code } : {}, note: i.note };
|
|
665
|
+
}
|
|
666
|
+
return {};
|
|
667
|
+
}
|
|
668
|
+
|
|
619
669
|
// src/lowering/errors.ts
|
|
620
670
|
var LoweringError = class extends Error {
|
|
621
671
|
constructor(code, message, context = {}) {
|
|
@@ -945,13 +995,15 @@ function runStatusOf(input) {
|
|
|
945
995
|
if (p.stopped !== void 0 && p.stopped !== true) return { state: "unknown" };
|
|
946
996
|
if (p.awaiting !== void 0 && !(Array.isArray(p.awaiting) && p.awaiting.every(isAwaitingCall)))
|
|
947
997
|
return { state: "unknown" };
|
|
998
|
+
if (p.code !== void 0 && !isPauseCode(p.code)) return { state: "unknown" };
|
|
948
999
|
return {
|
|
949
1000
|
state: "paused",
|
|
950
1001
|
seq,
|
|
951
1002
|
endedAt: at,
|
|
952
1003
|
reason: p.reason,
|
|
953
1004
|
stopped: p.stopped === true,
|
|
954
|
-
awaiting: p.awaiting
|
|
1005
|
+
awaiting: p.awaiting,
|
|
1006
|
+
...p.code !== void 0 ? { code: p.code } : {}
|
|
955
1007
|
};
|
|
956
1008
|
}
|
|
957
1009
|
case "core.run_ended": {
|
|
@@ -1527,7 +1579,15 @@ async function* runLoop(cfg) {
|
|
|
1527
1579
|
{
|
|
1528
1580
|
type: "core.run_paused",
|
|
1529
1581
|
actor: "system",
|
|
1530
|
-
|
|
1582
|
+
// 原因码与说明随暂停落库(AdRate 建议 16):取本次中断里 budget / host 那条,口径只走 pauseDetailOf。
|
|
1583
|
+
// 用户停止时 interruptions 已换成停止那条,Socket 给的码随之不写
|
|
1584
|
+
payload: {
|
|
1585
|
+
reason,
|
|
1586
|
+
state,
|
|
1587
|
+
awaiting,
|
|
1588
|
+
...texts ? { stopped: true } : {},
|
|
1589
|
+
...pauseDetailOf(interruptions)
|
|
1590
|
+
}
|
|
1531
1591
|
}
|
|
1532
1592
|
])
|
|
1533
1593
|
];
|
|
@@ -1746,7 +1806,7 @@ async function* runLoop(cfg) {
|
|
|
1746
1806
|
}
|
|
1747
1807
|
if (turns >= maxTurns) {
|
|
1748
1808
|
const note = `reached the per-run turn limit of ${maxTurns}`;
|
|
1749
|
-
const { events, result } = await pause("budget", [{ kind: "budget", note }]);
|
|
1809
|
+
const { events, result } = await pause("budget", [{ kind: "budget", note, code: MAX_TURNS_PAUSE_CODE }]);
|
|
1750
1810
|
yield* events;
|
|
1751
1811
|
return result;
|
|
1752
1812
|
}
|
|
@@ -1930,9 +1990,11 @@ async function* runLoop(cfg) {
|
|
|
1930
1990
|
return { status: "done", sessionId, lastSeq };
|
|
1931
1991
|
}
|
|
1932
1992
|
if ("pause" in decision) {
|
|
1933
|
-
const
|
|
1934
|
-
|
|
1935
|
-
|
|
1993
|
+
const { interruption, error } = resolveSocketPause(decision.pause);
|
|
1994
|
+
if (error !== void 0) {
|
|
1995
|
+
yield* await append([{ type: "core.error", actor: "system", payload: error }]);
|
|
1996
|
+
}
|
|
1997
|
+
const { events, result } = await pause(interruption.kind, [interruption]);
|
|
1936
1998
|
yield* events;
|
|
1937
1999
|
return result;
|
|
1938
2000
|
}
|
|
@@ -2426,7 +2488,7 @@ function memoryStore() {
|
|
|
2426
2488
|
}
|
|
2427
2489
|
|
|
2428
2490
|
// src/index.ts
|
|
2429
|
-
var REINS_VERSION = "0.
|
|
2491
|
+
var REINS_VERSION = "0.15.0";
|
|
2430
2492
|
export {
|
|
2431
2493
|
BUILTIN_APPROVAL_POLICY,
|
|
2432
2494
|
CORE_SCHEMAS,
|
|
@@ -2447,7 +2509,9 @@ export {
|
|
|
2447
2509
|
InMemoryMemoryStore,
|
|
2448
2510
|
InMemoryRunLease,
|
|
2449
2511
|
LoweringError,
|
|
2512
|
+
MAX_TURNS_PAUSE_CODE,
|
|
2450
2513
|
OUTCOME_UNKNOWN_TEXT,
|
|
2514
|
+
PAUSE_CODE_RE,
|
|
2451
2515
|
REINS_VERSION,
|
|
2452
2516
|
RUN_MARKER_TYPES,
|
|
2453
2517
|
RunStateError,
|
|
@@ -2494,6 +2558,7 @@ export {
|
|
|
2494
2558
|
isCompaction,
|
|
2495
2559
|
isContentPart,
|
|
2496
2560
|
isModelOutput,
|
|
2561
|
+
isPauseCode,
|
|
2497
2562
|
isPinNote,
|
|
2498
2563
|
isReplayable,
|
|
2499
2564
|
isStopReason,
|
|
@@ -2510,6 +2575,7 @@ export {
|
|
|
2510
2575
|
needsUntrustedMark,
|
|
2511
2576
|
normalizeToolOutput,
|
|
2512
2577
|
outcomeUnknownText,
|
|
2578
|
+
pauseDetailOf,
|
|
2513
2579
|
pausedStateOf,
|
|
2514
2580
|
pendingToolCalls,
|
|
2515
2581
|
project,
|
|
@@ -2522,6 +2588,7 @@ export {
|
|
|
2522
2588
|
replayTurns,
|
|
2523
2589
|
resolveRetry,
|
|
2524
2590
|
resolveSocketContributions,
|
|
2591
|
+
resolveSocketPause,
|
|
2525
2592
|
roughTokenEstimate,
|
|
2526
2593
|
runLoop,
|
|
2527
2594
|
runStatusOf,
|