@reinsjs/core 0.7.0 → 0.8.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @reinsjs/core
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 54fed37: Sockets can now see the current tool batch. `TurnContext.batch` (`ToolBatch`) lists the batch's tool calls, the results logged so far (in `beforeTool`, only those of earlier calls), the ids left waiting for approval, a client result or a paused sub-agent, and `resumed` when the batch is one a previous run left unfinished. It is one object updated in place during the turn. core also exports `ToolResultEvent` and `toolBatchOf(timeline, pending)`, which locates the batch of leftover calls. **`batch` is a required field**: a host that builds `TurnContext` objects itself (for example in socket unit tests) or runs its own copy of `runLoop` must fill it.
8
+
9
+ brain adds two opt-in sockets. `haltOnFailure({ counts?, applies? })` holds back the later calls of a batch once an earlier one failed or is still waiting: each gets an error result naming that call, and nothing runs. Register it first. `stopAfter({ tools })` ends the run (`done`) at the end of a turn in which the model successfully called one of `tools`, when nothing else in the batch failed or is pending. A batch resumed after an approval also ends the run, unless the resumed run brought new user input. Register it after `handoff()` and before `compact()` / `budget()`.
10
+
11
+ adapter-tanstack-ai fills `ctx.batch`. Because the engine checks a whole batch before running any of it, `beforeTool` sees no results from the same batch and `held` stays empty. A resumed batch gets no `onTurnEnd` on this path.
12
+
3
13
  ## 0.7.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -78,7 +78,7 @@ A tool can also *be* another agent: return `subagentPause(...)` from `execute` a
78
78
 
79
79
  ## Sockets
80
80
 
81
- A `Socket` is the seam brain modules use — five hooks (`beforeModel`, `afterModel`, `beforeTool`, `afterTool`, `onTurnEnd`) plus two static contributions (`tools`, `systemPrompt`, resolved once per run so prompt caches stay warm). Anything a socket wants the model to see is emitted as an event and lands in the log first; nothing is injected around the log.
81
+ A `Socket` is the seam brain modules use — five hooks (`beforeModel`, `afterModel`, `beforeTool`, `afterTool`, `onTurnEnd`) plus two static contributions (`tools`, `systemPrompt`, resolved once per run so prompt caches stay warm). Anything a socket wants the model to see is emitted as an event and lands in the log first; nothing is injected around the log. Every hook gets `ctx.batch`: the tool calls of the current batch, the results logged so far (in `beforeTool`, only those of earlier calls), the ids left waiting for approval / a client result / a paused sub-agent, and `resumed` when the batch is one a previous run left unfinished. It is one object updated in place during the turn — copy what you need instead of keeping a reference. A batch is one contiguous stretch of model output (`toolBatchOf`).
82
82
 
83
83
  ## Guarantees worth knowing
84
84
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as EventLog, a as Event, b as EventSchemaRegistry, B as BlobStore, M as MemoryStore, c as EventDraft, T as TokenUsage, C as ContentPart, d as Trust, L as Lowering, e as ModelRef, f as LoweringCapabilities, g as CoreEventOf, h as ToolResultPayload, i as LoweringDelta, j as LandingRecord, k as LoweredRequest, l as ErrorPayload, A as ApprovalRequestPayload, m as ToolCallPayload, n as ToolSpec, o as CoreEventDraft, p as BudgetUsagePayload, q as BlobMeta, R as ReadOptions, r as RunLease, S as Stores } from './types-DrzC9Mfc.js';
2
- export { s as Actor, t as AnyEvent, u as ApprovalDecisionPayload, v as BoundModel, w as CORE_SCHEMAS, x as CompactionPayload, y as CoreEvent, z as CoreEventPayloads, D as CoreEventType, F as CreateEventInput, G as DEFAULT_TRUST, H as EventBase, I as EventSchema, J as ExtEvent, K as HandoffPayload, N as ImagePart, O as LandingSpec, P as LossKind, Q as LossMatrix, U as LoweringOutcome, V as LoweringStreamContext, W as MemoryOpPayload, X as ModelTextPayload, Y as ModelThinkingPayload, Z as Provenance, _ as RunPausedPayload, $ as RunResumedPayload, a0 as SchemaError, a1 as SchemaErrorCode, a2 as SkillSource, a3 as SystemNotePayload, a4 as TextPart, a5 as ToRequestInput, a6 as ToolReferencePart, a7 as ToolsBoundPayload, a8 as Upcaster, a9 as UserMessagePayload, aa as contextOverheadOf, ab as contextTokensOf, ac as createCoreEvent, ad as createCoreRegistry, ae as createEvent, af as lossesOf, ag as renderToolReference } from './types-DrzC9Mfc.js';
1
+ import { E as Event, a as EventSchemaRegistry, b as EventLog, B as BlobStore, M as MemoryStore, c as EventDraft, T as TokenUsage, C as ContentPart, d as Trust, L as Lowering, e as ModelRef, f as LoweringCapabilities, g as CoreEventOf, h as ToolResultPayload, i as LoweringDelta, j as LandingRecord, k as LoweredRequest, l as ErrorPayload, A as ApprovalRequestPayload, m as ToolCallPayload, n as ToolSpec, o as CoreEventDraft, p as BudgetUsagePayload, q as BlobMeta, R as ReadOptions, r as RunLease, S as Stores } from './types-DkOLu2fW.js';
2
+ export { s as Actor, t as AnyEvent, u as ApprovalDecisionPayload, v as BoundModel, w as CORE_SCHEMAS, x as CompactionPayload, y as CoreEvent, z as CoreEventPayloads, D as CoreEventType, F as CreateEventInput, G as DEFAULT_TRUST, H as EventBase, I as EventSchema, J as ExtEvent, K as HandoffPayload, N as ImagePart, O as LandingSpec, P as LossKind, Q as LossMatrix, U as LoweringOutcome, V as LoweringStreamContext, W as MemoryOpPayload, X as ModelTextPayload, Y as ModelThinkingPayload, Z as Provenance, _ as RunPausedPayload, $ as RunResumedPayload, a0 as SchemaError, a1 as SchemaErrorCode, a2 as SkillSource, a3 as SystemNotePayload, a4 as TextPart, a5 as ToRequestInput, a6 as ToolReferencePart, a7 as ToolsBoundPayload, a8 as Upcaster, a9 as UserMessagePayload, aa as contextOverheadOf, ab as contextTokensOf, ac as createCoreEvent, ad as createCoreRegistry, ae as createEvent, af as lossesOf, ag as renderToolReference } from './types-DkOLu2fW.js';
3
3
 
4
4
  /**
5
5
  * UUID v7 生成(RFC 9562):前 48 位为 Unix 毫秒时间戳,字典序即时间序。
@@ -9,58 +9,6 @@ export { s as Actor, t as AnyEvent, u as ApprovalDecisionPayload, v as BoundMode
9
9
  */
10
10
  declare function uuidv7(now?: number): string;
11
11
 
12
- interface ForkOptions {
13
- fromSessionId: string;
14
- /** 复制 [1, atSeq],含 */
15
- atSeq: number;
16
- /** 缺省 uuidv7 */
17
- toSessionId?: string;
18
- }
19
- declare function forkSession(log: EventLog, opts: ForkOptions): Promise<{
20
- toSessionId: string;
21
- }>;
22
-
23
- interface RetryOptions {
24
- /** 最多尝试几次(含第一次)。缺省 3;1 = 不重试 */
25
- maxAttempts?: number;
26
- /** 首次重试前等多久(毫秒),之后每次翻倍。缺省 1000 */
27
- baseDelayMs?: number;
28
- /** 单次等待上限(毫秒)。缺省 8000 */
29
- maxDelayMs?: number;
30
- /** 覆盖瞬断判定:返回 true 表示值得重试。缺省见 isTransientFailure */
31
- isTransient?: (failure: ModelCallFailure) => boolean;
32
- /** 测试注入:等待实现。缺省 setTimeout,且被 signal 中止时提前结束 */
33
- sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
34
- }
35
- /** 一次模型调用失败的两种形态:降级层抛了异常,或流正常收尾但 stopReason = error */
36
- type ModelCallFailure = {
37
- kind: "thrown";
38
- error: unknown;
39
- } | {
40
- kind: "outcome";
41
- message: string;
42
- };
43
- declare const DEFAULT_RETRY_MAX_ATTEMPTS = 3;
44
- declare const DEFAULT_RETRY_BASE_DELAY_MS = 1000;
45
- declare const DEFAULT_RETRY_MAX_DELAY_MS = 8000;
46
- /**
47
- * 从错误文案里提取 HTTP 状态码:开头的三位数字(SDK 格式 "<status> <body>"),或 "status (code) 503" / "HTTP 503" 写法。
48
- * 只认 100~599,不在这两个位置上的数字不算(正文里提到 "429" 不是状态码)
49
- */
50
- declare function statusFromMessage(message: string): number | undefined;
51
- declare function isTransientFailure(failure: ModelCallFailure): boolean;
52
- /** 第 attempt 次失败后等多久:base × 2^(attempt−1),封顶 maxDelay。不加抖动,保证可测、可回放 */
53
- declare function backoffDelayMs(attempt: number, opts?: Pick<RetryOptions, "baseDelayMs" | "maxDelayMs">): number;
54
- /** 缺省等待:setTimeout;signal 中止就立刻返回(由调用方检查 aborted 再决定怎么收尾) */
55
- declare function defaultSleep(ms: number, signal?: AbortSignal): Promise<void>;
56
- interface ResolvedRetry {
57
- maxAttempts: number;
58
- delayFor: (attempt: number) => number;
59
- isTransient: (failure: ModelCallFailure) => boolean;
60
- sleep: (ms: number, signal?: AbortSignal) => Promise<void>;
61
- }
62
- declare function resolveRetry(opts?: RetryOptions): ResolvedRetry;
63
-
64
12
  /**
65
13
  * 投影(技术方案 §8):输入完整时间线,输出模型本轮应看到的事件。
66
14
  *
@@ -145,6 +93,47 @@ interface ProjectionResult {
145
93
  stats: ProjectionStats;
146
94
  }
147
95
 
96
+ interface RetryOptions {
97
+ /** 最多尝试几次(含第一次)。缺省 3;1 = 不重试 */
98
+ maxAttempts?: number;
99
+ /** 首次重试前等多久(毫秒),之后每次翻倍。缺省 1000 */
100
+ baseDelayMs?: number;
101
+ /** 单次等待上限(毫秒)。缺省 8000 */
102
+ maxDelayMs?: number;
103
+ /** 覆盖瞬断判定:返回 true 表示值得重试。缺省见 isTransientFailure */
104
+ isTransient?: (failure: ModelCallFailure) => boolean;
105
+ /** 测试注入:等待实现。缺省 setTimeout,且被 signal 中止时提前结束 */
106
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
107
+ }
108
+ /** 一次模型调用失败的两种形态:降级层抛了异常,或流正常收尾但 stopReason = error */
109
+ type ModelCallFailure = {
110
+ kind: "thrown";
111
+ error: unknown;
112
+ } | {
113
+ kind: "outcome";
114
+ message: string;
115
+ };
116
+ declare const DEFAULT_RETRY_MAX_ATTEMPTS = 3;
117
+ declare const DEFAULT_RETRY_BASE_DELAY_MS = 1000;
118
+ declare const DEFAULT_RETRY_MAX_DELAY_MS = 8000;
119
+ /**
120
+ * 从错误文案里提取 HTTP 状态码:开头的三位数字(SDK 格式 "<status> <body>"),或 "status (code) 503" / "HTTP 503" 写法。
121
+ * 只认 100~599,不在这两个位置上的数字不算(正文里提到 "429" 不是状态码)
122
+ */
123
+ declare function statusFromMessage(message: string): number | undefined;
124
+ declare function isTransientFailure(failure: ModelCallFailure): boolean;
125
+ /** 第 attempt 次失败后等多久:base × 2^(attempt−1),封顶 maxDelay。不加抖动,保证可测、可回放 */
126
+ declare function backoffDelayMs(attempt: number, opts?: Pick<RetryOptions, "baseDelayMs" | "maxDelayMs">): number;
127
+ /** 缺省等待:setTimeout;signal 中止就立刻返回(由调用方检查 aborted 再决定怎么收尾) */
128
+ declare function defaultSleep(ms: number, signal?: AbortSignal): Promise<void>;
129
+ interface ResolvedRetry {
130
+ maxAttempts: number;
131
+ delayFor: (attempt: number) => number;
132
+ isTransient: (failure: ModelCallFailure) => boolean;
133
+ sleep: (ms: number, signal?: AbortSignal) => Promise<void>;
134
+ }
135
+ declare function resolveRetry(opts?: RetryOptions): ResolvedRetry;
136
+
148
137
  /**
149
138
  * 循环与插座的类型(技术方案 §6、§7、§10)。
150
139
  *
@@ -235,6 +224,7 @@ interface Tool<TInput = unknown> {
235
224
  };
236
225
  }
237
226
  type ToolCallEvent = CoreEventOf<"core.tool_call">;
227
+ type ToolResultEvent = CoreEventOf<"core.tool_result">;
238
228
  type ToolResultDraft = EventDraft<"core.tool_result", ToolResultPayload>;
239
229
  /** beforeModel 的返回:改投影、增删工具、换系统提示;缺省字段表示不改 */
240
230
  interface BeforeModelPatch {
@@ -321,9 +311,31 @@ interface TurnContext {
321
311
  lastUsage?: TokenUsage;
322
312
  };
323
313
  signal?: AbortSignal;
314
+ /**
315
+ * 本批工具调用的活动(2026-11-02,OnSet 建议 9 / 10):模型这次发了哪些调用、已落了哪些结果、哪些被挂起、是不是补跑。
316
+ * 同一个对象在本轮内由循环随落随更——beforeTool 处理第 k 个调用时只看得见它之前落下的结果;不要拿快照比较
317
+ */
318
+ batch: ToolBatch;
324
319
  /** 草稿:无 id / seq / at / sessionId,循环补齐后 append。beforeModel 期间 emit 的本轮即可见 */
325
320
  emit(draft: EventDraft): void;
326
321
  }
322
+ /**
323
+ * "一批" = 一段连续模型输出里的 tool_call(与 replay 切轮 `isModelOutput` 同口径,模型不可见的运维事件不切段),
324
+ * 定位规则只有一份:`toolBatchOf`。Socket 只读;循环(runLoop、TanStack 适配器)负责填。
325
+ */
326
+ interface ToolBatch {
327
+ /** 本批调用,按执行顺序。模型输出前(beforeModel)为空;补跑时是遗留调用所在那批的全部 tool_call */
328
+ readonly calls: readonly ToolCallEvent[];
329
+ /**
330
+ * 本批已落日志的 tool_result(afterTool 替换之后、真正落日志的那条),按落下顺序。
331
+ * 补跑时预置上次已落的(含宿主经 input 回填的客户端工具结果)
332
+ */
333
+ readonly results: readonly ToolResultEvent[];
334
+ /** 本批已处理但被挂起、没落结果的 toolCallId(等审批 / 等客户端回填 / 子代理暂停)。TanStack 路径恒为空(defer 让整批暂停) */
335
+ readonly held: readonly string[];
336
+ /** 本批是续跑补齐上次遗留的调用(没有新的模型输出) */
337
+ readonly resumed: boolean;
338
+ }
327
339
  /**
328
340
  * 静态贡献的运行环境(B6):run 起步时给每个 Socket 看一次,让它按"有哪些存储、给谁跑"决定带不带工具与规则。
329
341
  * 只暴露跨请求不变或整个 run 不变的东西;每轮变化的信息(视图、预算)走 TurnContext。
@@ -534,6 +546,36 @@ interface LoopConfig {
534
546
  newId?: (at: number) => string;
535
547
  }
536
548
 
549
+ /**
550
+ * 工具批的定位(2026-11-02,OnSet 建议 9 / 10)。
551
+ *
552
+ * "一批" = 一段连续模型输出里的 tool_call。与 replay 切轮(`isModelOutput`)同口径,另外跳过模型不可见的运维事件
553
+ * (budget_usage、approval_request、run_paused…)——它们可能夹在同一次输出中间(TanStack 的 onUsage 早于输出收尾时),
554
+ * 与 lowering-fetch IR"运维事件不打断 assistant 分组"同一条规矩。runLoop 与 TanStack 适配器补跑时都调它(真源索引)。
555
+ */
556
+
557
+ /**
558
+ * 遗留调用所在的那批:以第一条 pending 为锚,前后扩到不属于同一段的事件为止,收其中的 tool_call;
559
+ * 并按时间线顺序收这些调用已落的 tool_result(上次 run 已执行的、宿主经 input 回填的)。
560
+ * pending 跨多批(fork、混用两种循环才会出现)时只取第一批——其余 pending 照样会被执行,只是不在 `calls` 里。
561
+ * 纯函数;`pending` 为空返回空批
562
+ */
563
+ declare function toolBatchOf(timeline: readonly Event[], pending: readonly ToolCallEvent[]): {
564
+ calls: ToolCallEvent[];
565
+ results: ToolResultEvent[];
566
+ };
567
+
568
+ interface ForkOptions {
569
+ fromSessionId: string;
570
+ /** 复制 [1, atSeq],含 */
571
+ atSeq: number;
572
+ /** 缺省 uuidv7 */
573
+ toSessionId?: string;
574
+ }
575
+ declare function forkSession(log: EventLog, opts: ForkOptions): Promise<{
576
+ toSessionId: string;
577
+ }>;
578
+
537
579
  /**
538
580
  * runLoop:reins 的默认循环(技术方案 §2、§6、§7)。
539
581
  *
@@ -1199,6 +1241,6 @@ declare function readTimeline(log: EventLog, sessionId: string, opts: ReadTimeli
1199
1241
  */
1200
1242
 
1201
1243
  /** 库版本,与 packages/core/package.json 的 version 同步(发布前 `pnpm check:dist` 会核对) */
1202
- declare const REINS_VERSION = "0.7.0";
1244
+ declare const REINS_VERSION = "0.8.0";
1203
1245
 
1204
- export { type ApprovalDecisionInput, ApprovalRequestPayload, type ApprovalRequestSpec, BUILTIN_APPROVAL_POLICY, type BeforeModelPatch, type BeforeToolDecision, 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, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, type DecodedToolArguments, type DefaultChainOptions, type ErrorEventPayload, ErrorPayload, Event, EventDraft, EventLog, EventSchemaRegistry, type FoldOptions, type FoldedToolResult, type FoldedToolResultOptions, type ForkOptions, type HandoffIntent, INPUT_DRAFT_TYPES, InMemoryBlobStore, InMemoryEventLog, InMemoryMemoryStore, InMemoryRunLease, type Interruption, LandingRecord, type LoopConfig, LoweredRequest, Lowering, LoweringCapabilities, LoweringDelta, LoweringError, type LoweringErrorCode, type MarkedContent, type MaybePromise, MemoryStore, type ModelCallFailure, ModelRef, type PauseReason, type Principal, type ProjectOptions, type ProjectionBudget, type ProjectionContext, type ProjectionResult, type ProjectionStats, type ProjectionStep, type ProjectionStepStats, type ProjectionStrategy, REINS_VERSION, ReadOptions, type ReadTimelineOptions, type RenderManifestOptions, type ReplayOptions, type ReplayResult, type ReplayedTurn, type ResolvedContributions, type ResolvedRetry, type RetryOptions, RunLease, type RunResult, RunStateError, type RunStateErrorCode, type SerializedRunState, type SessionInfo, type Socket, type SocketSetup, type StaticContribution, StoreError, type StoreErrorCode, Stores, type SubagentInterruption, type SubagentPause, type SubagentPauseDetail, type ThresholdSummarizer, type TokenEstimator, TokenUsage, type Tool, type ToolCallEvent, ToolCallPayload, type ToolContext, type ToolNamesDiff, type ToolResult, type ToolResultDraft, ToolResultPayload, type ToolSide, ToolSpec, type ToolsBoundEvent, Trust, type TurnContext, type TurnDecision, UNTRUSTED_CLOSE_TAG, UNTRUSTED_TAG, type VisibilityFilterOptions, assertRunStateShape, backoffDelayMs, budgetTruncate, computeConfigHash, computePendingDigest, covers, decodeToolArgumentsText, defaultProjectionChain, defaultSleep, defaultThresholdSummary, deferredToolSpecOf, defineTool, diffToolNames, digestArgs, errorMessageOf, escapeUntrustedText, estimateBudgetOf, estimateTextTokens, estimateTotal, foldCompactions, foldedToolResults, forkSession, inputDrafts, isCompaction, isContentPart, isModelOutput, isPinNote, isSubagentPause, isTransientFailure, keptBy, lastToolsBound, markUntrusted, markUntrustedText, memoryStore, needsUntrustedMark, normalizeToolOutput, pendingToolCalls, project, readEvents, readTimeline, reinjectPins, renderFoldedToolResults, renderToolChangeNote, replayTurns, resolveRetry, resolveSocketContributions, roughTokenEstimate, runLoop, serializeRunState, signRunState, splitTurns, statusFromMessage, subagentPause, supersededIds, toolCallArgumentsMeta, toolResultTrust, toolSpecOf, toolsBoundDrafts, untrustedOpenTag, untrustedSourceOf, unwrapToolArguments, uuidv7, validateResume, verifyRunState, visibilityFilter };
1246
+ export { type ApprovalDecisionInput, ApprovalRequestPayload, type ApprovalRequestSpec, BUILTIN_APPROVAL_POLICY, type BeforeModelPatch, type BeforeToolDecision, 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, DEFAULT_RETRY_BASE_DELAY_MS, DEFAULT_RETRY_MAX_ATTEMPTS, DEFAULT_RETRY_MAX_DELAY_MS, type DecodedToolArguments, type DefaultChainOptions, type ErrorEventPayload, ErrorPayload, Event, EventDraft, EventLog, EventSchemaRegistry, type FoldOptions, type FoldedToolResult, type FoldedToolResultOptions, type ForkOptions, type HandoffIntent, INPUT_DRAFT_TYPES, InMemoryBlobStore, InMemoryEventLog, InMemoryMemoryStore, InMemoryRunLease, type Interruption, LandingRecord, type LoopConfig, LoweredRequest, Lowering, LoweringCapabilities, LoweringDelta, LoweringError, type LoweringErrorCode, type MarkedContent, type MaybePromise, MemoryStore, type ModelCallFailure, ModelRef, type PauseReason, type Principal, type ProjectOptions, type ProjectionBudget, type ProjectionContext, type ProjectionResult, type ProjectionStats, type ProjectionStep, type ProjectionStepStats, type ProjectionStrategy, REINS_VERSION, ReadOptions, type ReadTimelineOptions, type RenderManifestOptions, type ReplayOptions, type ReplayResult, type ReplayedTurn, type ResolvedContributions, type ResolvedRetry, type RetryOptions, RunLease, type RunResult, RunStateError, type RunStateErrorCode, type SerializedRunState, type SessionInfo, type Socket, type SocketSetup, type StaticContribution, StoreError, type StoreErrorCode, Stores, type SubagentInterruption, type SubagentPause, type SubagentPauseDetail, type ThresholdSummarizer, type TokenEstimator, TokenUsage, type Tool, type ToolBatch, type ToolCallEvent, ToolCallPayload, type ToolContext, type ToolNamesDiff, type ToolResult, type ToolResultDraft, type ToolResultEvent, ToolResultPayload, type ToolSide, ToolSpec, type ToolsBoundEvent, Trust, type TurnContext, type TurnDecision, UNTRUSTED_CLOSE_TAG, UNTRUSTED_TAG, type VisibilityFilterOptions, assertRunStateShape, backoffDelayMs, budgetTruncate, computeConfigHash, computePendingDigest, covers, decodeToolArgumentsText, defaultProjectionChain, defaultSleep, defaultThresholdSummary, deferredToolSpecOf, defineTool, diffToolNames, digestArgs, errorMessageOf, escapeUntrustedText, estimateBudgetOf, estimateTextTokens, estimateTotal, foldCompactions, foldedToolResults, forkSession, inputDrafts, isCompaction, isContentPart, isModelOutput, isPinNote, isSubagentPause, isTransientFailure, keptBy, lastToolsBound, markUntrusted, markUntrustedText, memoryStore, needsUntrustedMark, normalizeToolOutput, pendingToolCalls, project, readEvents, readTimeline, reinjectPins, renderFoldedToolResults, renderToolChangeNote, replayTurns, resolveRetry, resolveSocketContributions, roughTokenEstimate, runLoop, serializeRunState, signRunState, splitTurns, statusFromMessage, subagentPause, supersededIds, toolBatchOf, toolCallArgumentsMeta, toolResultTrust, toolSpecOf, toolsBoundDrafts, untrustedOpenTag, untrustedSourceOf, unwrapToolArguments, uuidv7, validateResume, verifyRunState, visibilityFilter };