@dudousxd/nestjs-agent-core 0.19.0 → 0.20.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as ModelMessage, a as ToolDefinition, b as ToolCallRequest, c as MessageUsage, d as AgentUiComponent, A as Actor, e as ThreadSummary, f as ThreadDetail, S as StoredMessage, g as ToolResult, h as MessageAttachment, i as ToolCallStatus, U as UsagePurpose, j as ToolSpec, Q as QuotaState, k as AgentRunInput, H as HumanReply, T as ToolHandler, l as HistoryPolicy, O as OutputProcessor, P as ProcessorContext, I as InputProcessor, m as ProcessedPrompt, n as ModelAnswer, o as PageContext, p as AgentDefinition, q as AgentDelegation, D as DetachedDelivery, r as AiToolCtx, s as PromptBuilder, t as PromptContributor, u as ToolTransientRetrySetting, v as AgentIntake, w as Decision, E as ElicitationRequest, L as LlmStepEnvelope, x as ToolStepEnvelope } from './tool-Q2rmGeaG.cjs';
2
- export { y as ASK_TOOL_DESCRIPTION, z as ASK_TOOL_NAME, B as AgentApprovalRequest, C as AgentCatalogEntry, F as AgentHistoryWindow, G as AgentStreamEvent, J as AskToolInput, K as DEFAULT_INCREMENTAL_LOOKBACK_CHARS, N as DEFAULT_INTAKE_PREAMBLE, R as DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS, V as DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS, W as ElicitationOption, X as ElicitationOutcome, Y as ElicitationQuestion, Z as ElicitationReply, _ as ElicitationResult, $ as HistoryPolicyContext, a0 as HistorySelection, a1 as HistorySummary, a2 as IncrementalGating, a3 as InvokeWithTransientRetryOptions, a4 as MAX_ASK_QUESTIONS, a5 as MessageRole, a6 as OutputRejectedError, a7 as OutputVerdict, a8 as ProcessorFailedError, a9 as PromptContext, aa as QuotaView, ab as ToolCatalogEntry, ac as ToolConfirmation, ad as ToolKind, ae as ToolPresentation, af as ToolPresentationTone, ag as ToolResultField, ah as ToolResultView, ai as ToolStepCtx, aj as ToolTransientRetryNumbers, ak as ToolTransientRetryOptions, al as askInputSchema, am as askToolDefinition, an as decodeStreamEvent, ao as encodeStreamEvent, ap as invokeWithTransientRetry, aq as isTransientToolError, ar as normalizeElicitationReply, as as renderElicitationAnswers, at as resolveElicitation, au as resolveToolTransientRetryNumbers, av as settleElicitation } from './tool-Q2rmGeaG.cjs';
1
+ import { M as ModelMessage, a as ToolDefinition, b as ToolCallRequest, c as MessageUsage, d as AgentUiComponent, A as Actor, e as ThreadSummary, f as ThreadDetail, S as StoredMessage, g as ToolResult, h as MessageAttachment, i as ToolCallStatus, U as UsagePurpose, j as ToolSpec, Q as QuotaState, k as AgentRunInput, H as HumanReply, l as ToolKind, m as ToolCallApproval, T as ToolHandler, n as HistoryPolicy, O as OutputProcessor, P as ProcessorContext, I as InputProcessor, o as ProcessedPrompt, p as ModelAnswer, q as PageContext, r as AgentDefinition, s as AgentDelegation, D as DetachedDelivery, t as AiToolCtx, u as PromptBuilder, v as PromptContributor, w as ToolTransientRetrySetting, x as AgentIntake, y as Decision, E as ElicitationRequest, L as LlmStepEnvelope, z as ToolStepEnvelope } from './tool-B2Dq9ZwF.cjs';
2
+ export { B as ASK_TOOL_DESCRIPTION, C as ASK_TOOL_NAME, F as AgentApprovalRequest, G as AgentApprovalSettlement, J as AgentCatalogEntry, K as AgentHistoryWindow, N as AgentStreamEvent, R as AskToolInput, V as DEFAULT_INCREMENTAL_LOOKBACK_CHARS, W as DEFAULT_INTAKE_PREAMBLE, X as DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS, Y as DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS, Z as ElicitationOption, _ as ElicitationOutcome, $ as ElicitationQuestion, a0 as ElicitationReply, a1 as ElicitationResult, a2 as HistoryPolicyContext, a3 as HistorySelection, a4 as HistorySummary, a5 as IncrementalGating, a6 as InvokeWithTransientRetryOptions, a7 as MAX_ASK_QUESTIONS, a8 as MessageRole, a9 as OutputRejectedError, aa as OutputVerdict, ab as ProcessorFailedError, ac as PromptContext, ad as QuotaView, ae as ToolCallApprovalStatus, af as ToolCatalogEntry, ag as ToolConfirmation, ah as ToolPresentation, ai as ToolPresentationTone, aj as ToolResultField, ak as ToolResultView, al as ToolStepCtx, am as ToolTransientRetryNumbers, an as ToolTransientRetryOptions, ao as askInputSchema, ap as askToolDefinition, aq as decodeStreamEvent, ar as encodeStreamEvent, as as invokeWithTransientRetry, at as isTransientToolError, au as normalizeElicitationReply, av as renderElicitationAnswers, aw as resolveElicitation, ax as resolveToolTransientRetryNumbers, ay as settleElicitation } from './tool-B2Dq9ZwF.cjs';
3
3
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  import { ChannelRegistry } from '@dudousxd/nestjs-diagnostics';
5
5
 
@@ -284,6 +284,14 @@ interface RecordToolCallInput {
284
284
  * synthetic tool calls) can omit it; the store persists it as `null` when absent.
285
285
  */
286
286
  runId?: string;
287
+ /**
288
+ * Who has to approve this call (`'requester'` or a role), from the turn's `ApprovalPolicy`. Set on
289
+ * an action call that was put to a person — or approved by a remembered decision — and never
290
+ * otherwise; persisted as `null` when absent.
291
+ */
292
+ approver?: string;
293
+ /** ISO-8601 instant the approval request lapses. Absent → it never does. */
294
+ expiresAt?: string;
287
295
  }
288
296
  interface UpdateToolCallInput {
289
297
  toolCallId: string;
@@ -292,6 +300,17 @@ interface UpdateToolCallInput {
292
300
  error?: string;
293
301
  executionMs?: number;
294
302
  executedByRef?: string;
303
+ /** The approval asked for later calls of this tool in this thread to run without asking. */
304
+ remember?: boolean;
305
+ /** The surface the decision came through. See {@link import('../types.js').Decision.decidedVia}. */
306
+ decidedVia?: string;
307
+ }
308
+ /** What the approve/reject routes need to know about a call before they signal a decision on it. */
309
+ interface ToolCallApprovalState {
310
+ status: ToolCallStatus;
311
+ /** `null` for a call no policy put to anyone (an `ask`, or a row written before approvers existed). */
312
+ approver: string | null;
313
+ expiresAt: string | null;
295
314
  }
296
315
  /** Patch applied by {@link AgentStore.updateThread}. An omitted key leaves that field untouched. */
297
316
  interface UpdateThreadInput {
@@ -457,6 +476,19 @@ interface AgentStore {
457
476
  truncateFrom(threadId: string, messageId: string): Promise<void>;
458
477
  recordToolCall(input: RecordToolCallInput): Promise<void>;
459
478
  updateToolCall(input: UpdateToolCallInput): Promise<void>;
479
+ /**
480
+ * OPTIONAL: the names of the tools whose approval someone asked to REMEMBER in this thread — an
481
+ * approved call persisted with `remember: true`. The loop approves a later call of one of them
482
+ * without asking, inside that call's own `persist:toolcall` checkpoint. Absent → nothing is ever
483
+ * remembered, and every call asks.
484
+ */
485
+ rememberedApprovals?(threadId: string): Promise<string[]>;
486
+ /**
487
+ * OPTIONAL: a call's approval state, or `null` when the call is unknown. Read by the approve/reject
488
+ * routes to enforce the recorded approver and refuse a decision on a request that already
489
+ * expired. Absent → every call is treated as the requester's, with no expiry (the old behaviour).
490
+ */
491
+ toolCallApproval?(toolCallId: string): Promise<ToolCallApprovalState | null>;
460
492
  /**
461
493
  * OPTIONAL: of `mediaIds`, the ones a message that still exists — in a thread owned by
462
494
  * `actorRef` — still carries as an attachment. The inverse of
@@ -1146,15 +1178,105 @@ interface AttachmentStagingStore {
1146
1178
  * approvals inbox renders read-only.
1147
1179
  */
1148
1180
  interface AgentApprovalPort {
1181
+ /**
1182
+ * `remember` approves later calls of the same tool in the same thread; `decidedVia` names the
1183
+ * surface the decision came through (`'console'`, `'slack'`, …) and is persisted with the call.
1184
+ */
1149
1185
  approve(toolCallId: string, opts?: {
1150
1186
  executedByRef?: string;
1187
+ remember?: boolean;
1188
+ decidedVia?: string;
1151
1189
  }): Promise<void>;
1152
1190
  reject(toolCallId: string, opts?: {
1153
1191
  executedByRef?: string;
1154
1192
  reason?: string;
1193
+ decidedVia?: string;
1155
1194
  }): Promise<void>;
1156
1195
  }
1157
1196
 
1197
+ /** The approver that means "the person the run is acting for" — the thread's own actor. */
1198
+ declare const REQUESTER_APPROVER = "requester";
1199
+ /** The tool a requirement is asked about. `spec` is absent where this process cannot resolve it. */
1200
+ interface ApprovalToolRef {
1201
+ name: string;
1202
+ kind: ToolKind;
1203
+ spec?: ToolSpec;
1204
+ }
1205
+ /** Where the call is being made. */
1206
+ interface ApprovalThreadRef {
1207
+ threadId: string;
1208
+ runId: string;
1209
+ agentName?: string;
1210
+ }
1211
+ /**
1212
+ * What an action tool call needs before it runs.
1213
+ *
1214
+ * - `required: false` → the call runs without asking anyone (it is still recorded as an action).
1215
+ * - `approver` → who may decide: {@link REQUESTER_APPROVER} (the thread's own actor — the default)
1216
+ * or any other string, which the default {@link ApprovalPolicy.canDecide} reads as a ROLE the
1217
+ * decider must hold. Streamed on `approval-requested` and persisted on the call.
1218
+ * - `ttlMs` → how long the request stays open. When it lapses the call settles `expired` and the
1219
+ * model is told nobody approved it. Absent → it waits indefinitely.
1220
+ */
1221
+ interface ApprovalRequirement {
1222
+ required: boolean;
1223
+ approver: string;
1224
+ ttlMs?: number;
1225
+ }
1226
+ /** A decision about to be taken on a call, as {@link ApprovalPolicy.canDecide} sees it. */
1227
+ interface ApprovalDecisionRef {
1228
+ toolCallId: string;
1229
+ /** The approver recorded on the call when it was put to a person. */
1230
+ approver: string;
1231
+ /** The actorRef the run is acting for — the owner of the call's thread. */
1232
+ requesterRef: string;
1233
+ }
1234
+ /**
1235
+ * Who has to approve an action tool call, and for how long the request stays open.
1236
+ *
1237
+ * Consulted by the LOOP once per `action` call, inside the call's `persist:toolcall` checkpoint — so
1238
+ * a durable run reads the answer back on every replay instead of re-deciding it against a policy
1239
+ * that may have changed while it was parked. Only `action` calls are asked about: a policy cannot
1240
+ * put a `read` behind an approval, and an `ask` (a question set) is always the requester's.
1241
+ */
1242
+ interface ApprovalPolicy {
1243
+ requirementFor(tool: ApprovalToolRef, actor: Actor, thread: ApprovalThreadRef): ApprovalRequirement | Promise<ApprovalRequirement>;
1244
+ /**
1245
+ * May `actor` settle this call? Checked by the approve/reject routes before a decision is
1246
+ * signalled. Absent → {@link defaultCanDecide}: the requester approver means the thread's own
1247
+ * actor, anything else is a role the actor must hold. Plug an authz Gate here for abilities.
1248
+ */
1249
+ canDecide?(actor: Actor, decision: ApprovalDecisionRef): boolean | Promise<boolean>;
1250
+ }
1251
+ /**
1252
+ * The behaviour the lib always had: every `action` call waits on the person who asked, with no
1253
+ * expiry.
1254
+ */
1255
+ declare class DefaultApprovalPolicy implements ApprovalPolicy {
1256
+ requirementFor(tool: ApprovalToolRef): ApprovalRequirement;
1257
+ }
1258
+ /** The default decider rule — see {@link ApprovalPolicy.canDecide}. */
1259
+ declare function defaultCanDecide(actor: Actor, decision: ApprovalDecisionRef): boolean;
1260
+ /** Resolve whether `actor` may decide, through the policy's own rule when it has one. */
1261
+ declare function mayDecideApproval(policy: ApprovalPolicy | undefined, actor: Actor, decision: ApprovalDecisionRef): Promise<boolean>;
1262
+ /** The columns a store keeps for one call's approval, however it names them. */
1263
+ interface ToolCallApprovalColumns {
1264
+ toolCallId: string;
1265
+ status: ToolCallStatus;
1266
+ approver: string | null | undefined;
1267
+ expiresAt: string | Date | null | undefined;
1268
+ remember: boolean | null | undefined;
1269
+ executedByRef: string | null | undefined;
1270
+ decidedVia: string | null | undefined;
1271
+ error: string | null | undefined;
1272
+ }
1273
+ /**
1274
+ * Read a tool-call row back as the {@link ToolCallApproval} a thread carries, or `null` for a call
1275
+ * no policy put to anyone (no approver recorded). Shared by every store so they agree on the
1276
+ * status mapping: a call that ran — or ran and failed — after a decision was APPROVED.
1277
+ */
1278
+ declare function toolCallApprovalFromRow(row: ToolCallApprovalColumns): ToolCallApproval | null;
1279
+
1158
1280
  /**
1159
1281
  * The pure aggregation core shared by every {@link import('../spi/governance-queries.js').AgentGovernanceQueries}
1160
1282
  * adapter (MikroORM, Drizzle, in-memory). An adapter's only job is the DB-specific row fetch; the
@@ -2470,6 +2592,11 @@ interface AgentLoopDeps<TOutput = unknown> {
2470
2592
  store: AgentStore;
2471
2593
  registry: ToolRegistry;
2472
2594
  rolesPolicy: RolesPolicy;
2595
+ /**
2596
+ * Who has to approve an `action` call, and for how long the request stays open. Undefined →
2597
+ * {@link DefaultApprovalPolicy}: the requester, with no expiry — the behaviour before the SPI.
2598
+ */
2599
+ approvalPolicy?: ApprovalPolicy;
2473
2600
  quota?: QuotaStore;
2474
2601
  /**
2475
2602
  * Fallback accounting label when the provider's turn result doesn't report a `modelId`.
@@ -2702,8 +2829,18 @@ interface AgentLoopHooks {
2702
2829
  runId: string;
2703
2830
  /** A writer for this run's live token stream (data plane). */
2704
2831
  openSink(): SinkWriter | Promise<SinkWriter>;
2705
- /** HITL gate for an action tool. Inline resolves a pending promise; durable awaits a signal. */
2706
- awaitApproval(call: ToolCallRequest, ctx: AiToolCtx): Promise<Decision>;
2832
+ /**
2833
+ * HITL gate for an action tool. Inline resolves a pending promise; durable awaits a signal.
2834
+ *
2835
+ * `opts.timeoutMs` is the request's time to live, from the turn's `ApprovalPolicy`. When it
2836
+ * elapses with no decision the runner resolves `{ approved: false, expired: true }` — it must not
2837
+ * throw — and the loop settles the call `expired`. The value comes out of the call's
2838
+ * `persist:toolcall` checkpoint, so it is the same on every replay; a durable runner hands it to
2839
+ * its own timed wait (whose deadline the runtime journals), an inline one arms a timer.
2840
+ */
2841
+ awaitApproval(call: ToolCallRequest, ctx: AiToolCtx, opts?: {
2842
+ timeoutMs?: number;
2843
+ }): Promise<Decision>;
2707
2844
  /**
2708
2845
  * Park the run on a question set and resolve with what the human sent back. The SAME wait
2709
2846
  * `awaitApproval` is — the durable runner maps both to `ctx.waitForSignal` on
@@ -2896,6 +3033,8 @@ declare function withAskTool({ tools, ask, }: {
2896
3033
  tools: ToolDefinition[];
2897
3034
  ask: boolean | undefined;
2898
3035
  }): ToolDefinition[];
3036
+ /** The reason an expired call is denied with — on the row, the stream frame and the result. */
3037
+ declare const APPROVAL_EXPIRED_REASON = "approval expired";
2899
3038
  /**
2900
3039
  * Stored as the reason when someone declines without giving one. It is a placeholder, not something
2901
3040
  * a person said, so every reader has to filter it out — which is why it is exported rather than
@@ -3147,4 +3286,4 @@ type AgentDiagnosticKey = `agent:${AgentDiagnosticEvent}`;
3147
3286
  */
3148
3287
  declare function agentDiagnosticKey(event: AgentDiagnosticEvent): AgentDiagnosticKey;
3149
3288
 
3150
- export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DIAGNOSTIC_EVENTS, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MEMORY, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_SKILLS, AGENT_SKILL_SOURCES, AGENT_SPAN_EVENTS, AGENT_STORE, AGENT_TOOL_REGISTRY, Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentApprovalPort, AgentDefinition, type AgentDelegated, AgentDelegation, type AgentDiagnosticEvent, type AgentDiagnosticKey, type AgentFollowUpsSpan, type AgentGovernanceQueries, AgentIntake, type AgentLlmTurnSpan, type AgentLoopDeps, type AgentLoopHooks, type AgentLoopResult, type AgentMemoryResolved, type AgentMemoryWritten, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrievalSpan, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentSkillsResolved, type AgentSpanEvent, type AgentStore, AgentStreamError, type AgentStructuredOutputSpan, type AgentToolCallEvent, type AgentToolExecutionSpan, type AgentToolRetry, AgentUiComponent, AiToolCtx, type AppendMessageInput, type ApprovalWhere, type AttachmentRef, type AttachmentStagingStore, type BufferedModelTurnResult, type BuildMemoryBlockInput, type CostUsage, type CreateThreadInput, type CurrentModelPrice, DEFAULT_HISTORY_SUMMARY_INSTRUCTION, DEFAULT_MAX_FACT_CHARS, DEFAULT_MAX_MEMORIES, DEFAULT_MAX_SKILLS, DEFAULT_REFUSAL_REASON, DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION, Decision, DefaultRolesPolicy, type DetachedDelegationOutcome, type DetachedDelegationReceipt, DetachedDelivery, type DetailThreadRef, ElicitationRequest, type EmbeddingProvider, type ForgetMemoryInput, type FrameBuffer, GLOBAL_SCOPE, type GovernancePage, type GovernancePageQuery, type GovernanceRange, type GovernanceRunDetail, type GovernanceThreadDetail, type GovernanceThreadDetailQuery, type GovernanceUsageInput, HistoryPolicy, HumanReply, type IncrementalGate, InputProcessor, type ListMemoriesInput, type ListSkillsInput, type ListStagedAttachmentsInput, LlmStepEnvelope, type LoadSkillInput, type MemoryAuthor, type MemoryConfig, type MemoryDigest, type MemoryDigestEntry, type MemoryFact, type MemoryForgetRequest, type MemoryOrigin, type MemoryProvider, type MemoryRecord, type MemoryVerdict, type MemoryWriteOutcome, type MemoryWriteRequest, MessageAttachment, MessageUsage, ModelAnswer, ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type ObservedTurnFrames, type OfferMemoriesInput, type OutputGateMode, type OutputGateResult, OutputProcessor, type OverriddenMemory, PageContext, type Passage, type PendingApprovalRow, ProcessedPrompt, ProcessorContext, PromptBuilder, PromptContributor, QuotaExceededError, QuotaState, type QuotaStore, REMEMBER_TOOL_DESCRIPTION, REMEMBER_TOOL_NAME, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RememberToolInput, type RerankOptions, type Reranker, type ResolveAttachmentInput, type ResolveMemoryDigestInput, type ResolvedDelegation, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, RunCancelledError, type RunErrorBreakdownRow, type RunMetrics, type RunToolCallRow, type RunTrendPoint, type RunWhere, SKILL_TOOL_DESCRIPTION, SKILL_TOOL_NAME, type ScopeContext, type ScopeResolver, type SearchMemoriesInput, type SettledTask, type SinkWriter, type Skill, type SkillAuthor, type SkillCatalogEntry, type SkillContext, type SkillLoadOutcome, type SkillOffer, type SkillProvider, type SkillSummary, type SkillToolInput, type SkillWriteRequest, type SkillWriteVerdict, type SkillsConfig, type StageAttachmentInput, type StagedAttachment, type StoreMemoryInput, StoredMessage, type StreamError, type StructuredOutcome, StructuredOutputError, THREAD_DETAIL_CONTENT_CHARS, type ThreadActivityRow, ThreadDetail, type ThreadMessageRow, type ThreadMeta, type ThreadSpendRow, ThreadSummary, type ThreadTurnPage, type ThreadTurnQuery, type ThreadTurnReader, type ThreadUsageRollup, type ThreadWhere, type TokenStreamSink, type ToolCallActivityRow, ToolCallRequest, ToolCallStatus, type ToolCallWhere, ToolDefinition, ToolDisabledError, ToolForbiddenError, ToolHandler, ToolInputInvalidError, type ToolKindDeps, ToolNotFoundError, ToolRegistry, ToolResult, ToolSpec, type ToolStatRow, ToolStepEnvelope, ToolTransientRetrySetting, type TurnFrameSummary, type UpdateThreadInput, type UpdateToolCallInput, UsagePurpose, type UsageTrendPoint, type WindowHistoryOptions, type WithMemoryToolInput, type WriteMemoryInput, actorScope, agentDiagnosticKey, agentFailureCode, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, buildMemoryBlock, buildSkillsBlock, canActorUseTool, compositeSkillProvider, createFrameBuffer, createIncrementalGate, dayBoundsUtc, defaultScopeResolver, detachedDelivered, detachedStarted, detachedUnsettled, estimateCost, estimateMessageTokens, extractJson, filterToolsByAllowList, filterToolsByCanUse, filterToolsByEnabled, filterToolsByRole, gateFollowUps, gateTail, isControlFlowSignal, isReplayIntegrityError, isToolEnabled, loadSkill, memoryForgetVerdict, memoryWriteVerdict, normalizeDelegation, observeTurnFrames, offerMemories, offerSkills, publishAgentDelegated, publishAgentMemoryResolved, publishAgentMemoryWritten, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentSkillsResolved, publishAgentToolCall, publishAgentToolRetry, releaseGatedFrames, rememberInputSchema, rememberToolDefinition, repairInstruction, resolveGateLookback, resolveMemoryDigest, resolveOutputGateMode, resolveSkillCatalog, rollupThreadUsage, runAgentLoop, runInputProcessors, runOutputProcessors, seedModelPrices, settleAll, settleUnsettledDelegation, skillInputSchema, skillToolDefinition, skillWriteVerdict, stampToolKinds, staticSkillProvider, summarizeWithModel, tenantScope, traceLlmTurn, traceToolExecution, truncateDetailContent, validateStructured, windowHistory, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, writeMemory };
3289
+ export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DIAGNOSTIC_EVENTS, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MEMORY, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_SKILLS, AGENT_SKILL_SOURCES, AGENT_SPAN_EVENTS, AGENT_STORE, AGENT_TOOL_REGISTRY, APPROVAL_EXPIRED_REASON, Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentApprovalPort, AgentDefinition, type AgentDelegated, AgentDelegation, type AgentDiagnosticEvent, type AgentDiagnosticKey, type AgentFollowUpsSpan, type AgentGovernanceQueries, AgentIntake, type AgentLlmTurnSpan, type AgentLoopDeps, type AgentLoopHooks, type AgentLoopResult, type AgentMemoryResolved, type AgentMemoryWritten, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrievalSpan, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentSkillsResolved, type AgentSpanEvent, type AgentStore, AgentStreamError, type AgentStructuredOutputSpan, type AgentToolCallEvent, type AgentToolExecutionSpan, type AgentToolRetry, AgentUiComponent, AiToolCtx, type AppendMessageInput, type ApprovalDecisionRef, type ApprovalPolicy, type ApprovalRequirement, type ApprovalThreadRef, type ApprovalToolRef, type ApprovalWhere, type AttachmentRef, type AttachmentStagingStore, type BufferedModelTurnResult, type BuildMemoryBlockInput, type CostUsage, type CreateThreadInput, type CurrentModelPrice, DEFAULT_HISTORY_SUMMARY_INSTRUCTION, DEFAULT_MAX_FACT_CHARS, DEFAULT_MAX_MEMORIES, DEFAULT_MAX_SKILLS, DEFAULT_REFUSAL_REASON, DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION, Decision, DefaultApprovalPolicy, DefaultRolesPolicy, type DetachedDelegationOutcome, type DetachedDelegationReceipt, DetachedDelivery, type DetailThreadRef, ElicitationRequest, type EmbeddingProvider, type ForgetMemoryInput, type FrameBuffer, GLOBAL_SCOPE, type GovernancePage, type GovernancePageQuery, type GovernanceRange, type GovernanceRunDetail, type GovernanceThreadDetail, type GovernanceThreadDetailQuery, type GovernanceUsageInput, HistoryPolicy, HumanReply, type IncrementalGate, InputProcessor, type ListMemoriesInput, type ListSkillsInput, type ListStagedAttachmentsInput, LlmStepEnvelope, type LoadSkillInput, type MemoryAuthor, type MemoryConfig, type MemoryDigest, type MemoryDigestEntry, type MemoryFact, type MemoryForgetRequest, type MemoryOrigin, type MemoryProvider, type MemoryRecord, type MemoryVerdict, type MemoryWriteOutcome, type MemoryWriteRequest, MessageAttachment, MessageUsage, ModelAnswer, ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type ObservedTurnFrames, type OfferMemoriesInput, type OutputGateMode, type OutputGateResult, OutputProcessor, type OverriddenMemory, PageContext, type Passage, type PendingApprovalRow, ProcessedPrompt, ProcessorContext, PromptBuilder, PromptContributor, QuotaExceededError, QuotaState, type QuotaStore, REMEMBER_TOOL_DESCRIPTION, REMEMBER_TOOL_NAME, REQUESTER_APPROVER, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RememberToolInput, type RerankOptions, type Reranker, type ResolveAttachmentInput, type ResolveMemoryDigestInput, type ResolvedDelegation, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, RunCancelledError, type RunErrorBreakdownRow, type RunMetrics, type RunToolCallRow, type RunTrendPoint, type RunWhere, SKILL_TOOL_DESCRIPTION, SKILL_TOOL_NAME, type ScopeContext, type ScopeResolver, type SearchMemoriesInput, type SettledTask, type SinkWriter, type Skill, type SkillAuthor, type SkillCatalogEntry, type SkillContext, type SkillLoadOutcome, type SkillOffer, type SkillProvider, type SkillSummary, type SkillToolInput, type SkillWriteRequest, type SkillWriteVerdict, type SkillsConfig, type StageAttachmentInput, type StagedAttachment, type StoreMemoryInput, StoredMessage, type StreamError, type StructuredOutcome, StructuredOutputError, THREAD_DETAIL_CONTENT_CHARS, type ThreadActivityRow, ThreadDetail, type ThreadMessageRow, type ThreadMeta, type ThreadSpendRow, ThreadSummary, type ThreadTurnPage, type ThreadTurnQuery, type ThreadTurnReader, type ThreadUsageRollup, type ThreadWhere, type TokenStreamSink, type ToolCallActivityRow, ToolCallApproval, type ToolCallApprovalColumns, type ToolCallApprovalState, ToolCallRequest, ToolCallStatus, type ToolCallWhere, ToolDefinition, ToolDisabledError, ToolForbiddenError, ToolHandler, ToolInputInvalidError, ToolKind, type ToolKindDeps, ToolNotFoundError, ToolRegistry, ToolResult, ToolSpec, type ToolStatRow, ToolStepEnvelope, ToolTransientRetrySetting, type TurnFrameSummary, type UpdateThreadInput, type UpdateToolCallInput, UsagePurpose, type UsageTrendPoint, type WindowHistoryOptions, type WithMemoryToolInput, type WriteMemoryInput, actorScope, agentDiagnosticKey, agentFailureCode, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, buildMemoryBlock, buildSkillsBlock, canActorUseTool, compositeSkillProvider, createFrameBuffer, createIncrementalGate, dayBoundsUtc, defaultCanDecide, defaultScopeResolver, detachedDelivered, detachedStarted, detachedUnsettled, estimateCost, estimateMessageTokens, extractJson, filterToolsByAllowList, filterToolsByCanUse, filterToolsByEnabled, filterToolsByRole, gateFollowUps, gateTail, isControlFlowSignal, isReplayIntegrityError, isToolEnabled, loadSkill, mayDecideApproval, memoryForgetVerdict, memoryWriteVerdict, normalizeDelegation, observeTurnFrames, offerMemories, offerSkills, publishAgentDelegated, publishAgentMemoryResolved, publishAgentMemoryWritten, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentSkillsResolved, publishAgentToolCall, publishAgentToolRetry, releaseGatedFrames, rememberInputSchema, rememberToolDefinition, repairInstruction, resolveGateLookback, resolveMemoryDigest, resolveOutputGateMode, resolveSkillCatalog, rollupThreadUsage, runAgentLoop, runInputProcessors, runOutputProcessors, seedModelPrices, settleAll, settleUnsettledDelegation, skillInputSchema, skillToolDefinition, skillWriteVerdict, stampToolKinds, staticSkillProvider, summarizeWithModel, tenantScope, toolCallApprovalFromRow, traceLlmTurn, traceToolExecution, truncateDetailContent, validateStructured, windowHistory, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, writeMemory };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as ModelMessage, a as ToolDefinition, b as ToolCallRequest, c as MessageUsage, d as AgentUiComponent, A as Actor, e as ThreadSummary, f as ThreadDetail, S as StoredMessage, g as ToolResult, h as MessageAttachment, i as ToolCallStatus, U as UsagePurpose, j as ToolSpec, Q as QuotaState, k as AgentRunInput, H as HumanReply, T as ToolHandler, l as HistoryPolicy, O as OutputProcessor, P as ProcessorContext, I as InputProcessor, m as ProcessedPrompt, n as ModelAnswer, o as PageContext, p as AgentDefinition, q as AgentDelegation, D as DetachedDelivery, r as AiToolCtx, s as PromptBuilder, t as PromptContributor, u as ToolTransientRetrySetting, v as AgentIntake, w as Decision, E as ElicitationRequest, L as LlmStepEnvelope, x as ToolStepEnvelope } from './tool-Q2rmGeaG.js';
2
- export { y as ASK_TOOL_DESCRIPTION, z as ASK_TOOL_NAME, B as AgentApprovalRequest, C as AgentCatalogEntry, F as AgentHistoryWindow, G as AgentStreamEvent, J as AskToolInput, K as DEFAULT_INCREMENTAL_LOOKBACK_CHARS, N as DEFAULT_INTAKE_PREAMBLE, R as DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS, V as DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS, W as ElicitationOption, X as ElicitationOutcome, Y as ElicitationQuestion, Z as ElicitationReply, _ as ElicitationResult, $ as HistoryPolicyContext, a0 as HistorySelection, a1 as HistorySummary, a2 as IncrementalGating, a3 as InvokeWithTransientRetryOptions, a4 as MAX_ASK_QUESTIONS, a5 as MessageRole, a6 as OutputRejectedError, a7 as OutputVerdict, a8 as ProcessorFailedError, a9 as PromptContext, aa as QuotaView, ab as ToolCatalogEntry, ac as ToolConfirmation, ad as ToolKind, ae as ToolPresentation, af as ToolPresentationTone, ag as ToolResultField, ah as ToolResultView, ai as ToolStepCtx, aj as ToolTransientRetryNumbers, ak as ToolTransientRetryOptions, al as askInputSchema, am as askToolDefinition, an as decodeStreamEvent, ao as encodeStreamEvent, ap as invokeWithTransientRetry, aq as isTransientToolError, ar as normalizeElicitationReply, as as renderElicitationAnswers, at as resolveElicitation, au as resolveToolTransientRetryNumbers, av as settleElicitation } from './tool-Q2rmGeaG.js';
1
+ import { M as ModelMessage, a as ToolDefinition, b as ToolCallRequest, c as MessageUsage, d as AgentUiComponent, A as Actor, e as ThreadSummary, f as ThreadDetail, S as StoredMessage, g as ToolResult, h as MessageAttachment, i as ToolCallStatus, U as UsagePurpose, j as ToolSpec, Q as QuotaState, k as AgentRunInput, H as HumanReply, l as ToolKind, m as ToolCallApproval, T as ToolHandler, n as HistoryPolicy, O as OutputProcessor, P as ProcessorContext, I as InputProcessor, o as ProcessedPrompt, p as ModelAnswer, q as PageContext, r as AgentDefinition, s as AgentDelegation, D as DetachedDelivery, t as AiToolCtx, u as PromptBuilder, v as PromptContributor, w as ToolTransientRetrySetting, x as AgentIntake, y as Decision, E as ElicitationRequest, L as LlmStepEnvelope, z as ToolStepEnvelope } from './tool-B2Dq9ZwF.js';
2
+ export { B as ASK_TOOL_DESCRIPTION, C as ASK_TOOL_NAME, F as AgentApprovalRequest, G as AgentApprovalSettlement, J as AgentCatalogEntry, K as AgentHistoryWindow, N as AgentStreamEvent, R as AskToolInput, V as DEFAULT_INCREMENTAL_LOOKBACK_CHARS, W as DEFAULT_INTAKE_PREAMBLE, X as DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS, Y as DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS, Z as ElicitationOption, _ as ElicitationOutcome, $ as ElicitationQuestion, a0 as ElicitationReply, a1 as ElicitationResult, a2 as HistoryPolicyContext, a3 as HistorySelection, a4 as HistorySummary, a5 as IncrementalGating, a6 as InvokeWithTransientRetryOptions, a7 as MAX_ASK_QUESTIONS, a8 as MessageRole, a9 as OutputRejectedError, aa as OutputVerdict, ab as ProcessorFailedError, ac as PromptContext, ad as QuotaView, ae as ToolCallApprovalStatus, af as ToolCatalogEntry, ag as ToolConfirmation, ah as ToolPresentation, ai as ToolPresentationTone, aj as ToolResultField, ak as ToolResultView, al as ToolStepCtx, am as ToolTransientRetryNumbers, an as ToolTransientRetryOptions, ao as askInputSchema, ap as askToolDefinition, aq as decodeStreamEvent, ar as encodeStreamEvent, as as invokeWithTransientRetry, at as isTransientToolError, au as normalizeElicitationReply, av as renderElicitationAnswers, aw as resolveElicitation, ax as resolveToolTransientRetryNumbers, ay as settleElicitation } from './tool-B2Dq9ZwF.js';
3
3
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
4
  import { ChannelRegistry } from '@dudousxd/nestjs-diagnostics';
5
5
 
@@ -284,6 +284,14 @@ interface RecordToolCallInput {
284
284
  * synthetic tool calls) can omit it; the store persists it as `null` when absent.
285
285
  */
286
286
  runId?: string;
287
+ /**
288
+ * Who has to approve this call (`'requester'` or a role), from the turn's `ApprovalPolicy`. Set on
289
+ * an action call that was put to a person — or approved by a remembered decision — and never
290
+ * otherwise; persisted as `null` when absent.
291
+ */
292
+ approver?: string;
293
+ /** ISO-8601 instant the approval request lapses. Absent → it never does. */
294
+ expiresAt?: string;
287
295
  }
288
296
  interface UpdateToolCallInput {
289
297
  toolCallId: string;
@@ -292,6 +300,17 @@ interface UpdateToolCallInput {
292
300
  error?: string;
293
301
  executionMs?: number;
294
302
  executedByRef?: string;
303
+ /** The approval asked for later calls of this tool in this thread to run without asking. */
304
+ remember?: boolean;
305
+ /** The surface the decision came through. See {@link import('../types.js').Decision.decidedVia}. */
306
+ decidedVia?: string;
307
+ }
308
+ /** What the approve/reject routes need to know about a call before they signal a decision on it. */
309
+ interface ToolCallApprovalState {
310
+ status: ToolCallStatus;
311
+ /** `null` for a call no policy put to anyone (an `ask`, or a row written before approvers existed). */
312
+ approver: string | null;
313
+ expiresAt: string | null;
295
314
  }
296
315
  /** Patch applied by {@link AgentStore.updateThread}. An omitted key leaves that field untouched. */
297
316
  interface UpdateThreadInput {
@@ -457,6 +476,19 @@ interface AgentStore {
457
476
  truncateFrom(threadId: string, messageId: string): Promise<void>;
458
477
  recordToolCall(input: RecordToolCallInput): Promise<void>;
459
478
  updateToolCall(input: UpdateToolCallInput): Promise<void>;
479
+ /**
480
+ * OPTIONAL: the names of the tools whose approval someone asked to REMEMBER in this thread — an
481
+ * approved call persisted with `remember: true`. The loop approves a later call of one of them
482
+ * without asking, inside that call's own `persist:toolcall` checkpoint. Absent → nothing is ever
483
+ * remembered, and every call asks.
484
+ */
485
+ rememberedApprovals?(threadId: string): Promise<string[]>;
486
+ /**
487
+ * OPTIONAL: a call's approval state, or `null` when the call is unknown. Read by the approve/reject
488
+ * routes to enforce the recorded approver and refuse a decision on a request that already
489
+ * expired. Absent → every call is treated as the requester's, with no expiry (the old behaviour).
490
+ */
491
+ toolCallApproval?(toolCallId: string): Promise<ToolCallApprovalState | null>;
460
492
  /**
461
493
  * OPTIONAL: of `mediaIds`, the ones a message that still exists — in a thread owned by
462
494
  * `actorRef` — still carries as an attachment. The inverse of
@@ -1146,15 +1178,105 @@ interface AttachmentStagingStore {
1146
1178
  * approvals inbox renders read-only.
1147
1179
  */
1148
1180
  interface AgentApprovalPort {
1181
+ /**
1182
+ * `remember` approves later calls of the same tool in the same thread; `decidedVia` names the
1183
+ * surface the decision came through (`'console'`, `'slack'`, …) and is persisted with the call.
1184
+ */
1149
1185
  approve(toolCallId: string, opts?: {
1150
1186
  executedByRef?: string;
1187
+ remember?: boolean;
1188
+ decidedVia?: string;
1151
1189
  }): Promise<void>;
1152
1190
  reject(toolCallId: string, opts?: {
1153
1191
  executedByRef?: string;
1154
1192
  reason?: string;
1193
+ decidedVia?: string;
1155
1194
  }): Promise<void>;
1156
1195
  }
1157
1196
 
1197
+ /** The approver that means "the person the run is acting for" — the thread's own actor. */
1198
+ declare const REQUESTER_APPROVER = "requester";
1199
+ /** The tool a requirement is asked about. `spec` is absent where this process cannot resolve it. */
1200
+ interface ApprovalToolRef {
1201
+ name: string;
1202
+ kind: ToolKind;
1203
+ spec?: ToolSpec;
1204
+ }
1205
+ /** Where the call is being made. */
1206
+ interface ApprovalThreadRef {
1207
+ threadId: string;
1208
+ runId: string;
1209
+ agentName?: string;
1210
+ }
1211
+ /**
1212
+ * What an action tool call needs before it runs.
1213
+ *
1214
+ * - `required: false` → the call runs without asking anyone (it is still recorded as an action).
1215
+ * - `approver` → who may decide: {@link REQUESTER_APPROVER} (the thread's own actor — the default)
1216
+ * or any other string, which the default {@link ApprovalPolicy.canDecide} reads as a ROLE the
1217
+ * decider must hold. Streamed on `approval-requested` and persisted on the call.
1218
+ * - `ttlMs` → how long the request stays open. When it lapses the call settles `expired` and the
1219
+ * model is told nobody approved it. Absent → it waits indefinitely.
1220
+ */
1221
+ interface ApprovalRequirement {
1222
+ required: boolean;
1223
+ approver: string;
1224
+ ttlMs?: number;
1225
+ }
1226
+ /** A decision about to be taken on a call, as {@link ApprovalPolicy.canDecide} sees it. */
1227
+ interface ApprovalDecisionRef {
1228
+ toolCallId: string;
1229
+ /** The approver recorded on the call when it was put to a person. */
1230
+ approver: string;
1231
+ /** The actorRef the run is acting for — the owner of the call's thread. */
1232
+ requesterRef: string;
1233
+ }
1234
+ /**
1235
+ * Who has to approve an action tool call, and for how long the request stays open.
1236
+ *
1237
+ * Consulted by the LOOP once per `action` call, inside the call's `persist:toolcall` checkpoint — so
1238
+ * a durable run reads the answer back on every replay instead of re-deciding it against a policy
1239
+ * that may have changed while it was parked. Only `action` calls are asked about: a policy cannot
1240
+ * put a `read` behind an approval, and an `ask` (a question set) is always the requester's.
1241
+ */
1242
+ interface ApprovalPolicy {
1243
+ requirementFor(tool: ApprovalToolRef, actor: Actor, thread: ApprovalThreadRef): ApprovalRequirement | Promise<ApprovalRequirement>;
1244
+ /**
1245
+ * May `actor` settle this call? Checked by the approve/reject routes before a decision is
1246
+ * signalled. Absent → {@link defaultCanDecide}: the requester approver means the thread's own
1247
+ * actor, anything else is a role the actor must hold. Plug an authz Gate here for abilities.
1248
+ */
1249
+ canDecide?(actor: Actor, decision: ApprovalDecisionRef): boolean | Promise<boolean>;
1250
+ }
1251
+ /**
1252
+ * The behaviour the lib always had: every `action` call waits on the person who asked, with no
1253
+ * expiry.
1254
+ */
1255
+ declare class DefaultApprovalPolicy implements ApprovalPolicy {
1256
+ requirementFor(tool: ApprovalToolRef): ApprovalRequirement;
1257
+ }
1258
+ /** The default decider rule — see {@link ApprovalPolicy.canDecide}. */
1259
+ declare function defaultCanDecide(actor: Actor, decision: ApprovalDecisionRef): boolean;
1260
+ /** Resolve whether `actor` may decide, through the policy's own rule when it has one. */
1261
+ declare function mayDecideApproval(policy: ApprovalPolicy | undefined, actor: Actor, decision: ApprovalDecisionRef): Promise<boolean>;
1262
+ /** The columns a store keeps for one call's approval, however it names them. */
1263
+ interface ToolCallApprovalColumns {
1264
+ toolCallId: string;
1265
+ status: ToolCallStatus;
1266
+ approver: string | null | undefined;
1267
+ expiresAt: string | Date | null | undefined;
1268
+ remember: boolean | null | undefined;
1269
+ executedByRef: string | null | undefined;
1270
+ decidedVia: string | null | undefined;
1271
+ error: string | null | undefined;
1272
+ }
1273
+ /**
1274
+ * Read a tool-call row back as the {@link ToolCallApproval} a thread carries, or `null` for a call
1275
+ * no policy put to anyone (no approver recorded). Shared by every store so they agree on the
1276
+ * status mapping: a call that ran — or ran and failed — after a decision was APPROVED.
1277
+ */
1278
+ declare function toolCallApprovalFromRow(row: ToolCallApprovalColumns): ToolCallApproval | null;
1279
+
1158
1280
  /**
1159
1281
  * The pure aggregation core shared by every {@link import('../spi/governance-queries.js').AgentGovernanceQueries}
1160
1282
  * adapter (MikroORM, Drizzle, in-memory). An adapter's only job is the DB-specific row fetch; the
@@ -2470,6 +2592,11 @@ interface AgentLoopDeps<TOutput = unknown> {
2470
2592
  store: AgentStore;
2471
2593
  registry: ToolRegistry;
2472
2594
  rolesPolicy: RolesPolicy;
2595
+ /**
2596
+ * Who has to approve an `action` call, and for how long the request stays open. Undefined →
2597
+ * {@link DefaultApprovalPolicy}: the requester, with no expiry — the behaviour before the SPI.
2598
+ */
2599
+ approvalPolicy?: ApprovalPolicy;
2473
2600
  quota?: QuotaStore;
2474
2601
  /**
2475
2602
  * Fallback accounting label when the provider's turn result doesn't report a `modelId`.
@@ -2702,8 +2829,18 @@ interface AgentLoopHooks {
2702
2829
  runId: string;
2703
2830
  /** A writer for this run's live token stream (data plane). */
2704
2831
  openSink(): SinkWriter | Promise<SinkWriter>;
2705
- /** HITL gate for an action tool. Inline resolves a pending promise; durable awaits a signal. */
2706
- awaitApproval(call: ToolCallRequest, ctx: AiToolCtx): Promise<Decision>;
2832
+ /**
2833
+ * HITL gate for an action tool. Inline resolves a pending promise; durable awaits a signal.
2834
+ *
2835
+ * `opts.timeoutMs` is the request's time to live, from the turn's `ApprovalPolicy`. When it
2836
+ * elapses with no decision the runner resolves `{ approved: false, expired: true }` — it must not
2837
+ * throw — and the loop settles the call `expired`. The value comes out of the call's
2838
+ * `persist:toolcall` checkpoint, so it is the same on every replay; a durable runner hands it to
2839
+ * its own timed wait (whose deadline the runtime journals), an inline one arms a timer.
2840
+ */
2841
+ awaitApproval(call: ToolCallRequest, ctx: AiToolCtx, opts?: {
2842
+ timeoutMs?: number;
2843
+ }): Promise<Decision>;
2707
2844
  /**
2708
2845
  * Park the run on a question set and resolve with what the human sent back. The SAME wait
2709
2846
  * `awaitApproval` is — the durable runner maps both to `ctx.waitForSignal` on
@@ -2896,6 +3033,8 @@ declare function withAskTool({ tools, ask, }: {
2896
3033
  tools: ToolDefinition[];
2897
3034
  ask: boolean | undefined;
2898
3035
  }): ToolDefinition[];
3036
+ /** The reason an expired call is denied with — on the row, the stream frame and the result. */
3037
+ declare const APPROVAL_EXPIRED_REASON = "approval expired";
2899
3038
  /**
2900
3039
  * Stored as the reason when someone declines without giving one. It is a placeholder, not something
2901
3040
  * a person said, so every reader has to filter it out — which is why it is exported rather than
@@ -3147,4 +3286,4 @@ type AgentDiagnosticKey = `agent:${AgentDiagnosticEvent}`;
3147
3286
  */
3148
3287
  declare function agentDiagnosticKey(event: AgentDiagnosticEvent): AgentDiagnosticKey;
3149
3288
 
3150
- export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DIAGNOSTIC_EVENTS, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MEMORY, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_SKILLS, AGENT_SKILL_SOURCES, AGENT_SPAN_EVENTS, AGENT_STORE, AGENT_TOOL_REGISTRY, Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentApprovalPort, AgentDefinition, type AgentDelegated, AgentDelegation, type AgentDiagnosticEvent, type AgentDiagnosticKey, type AgentFollowUpsSpan, type AgentGovernanceQueries, AgentIntake, type AgentLlmTurnSpan, type AgentLoopDeps, type AgentLoopHooks, type AgentLoopResult, type AgentMemoryResolved, type AgentMemoryWritten, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrievalSpan, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentSkillsResolved, type AgentSpanEvent, type AgentStore, AgentStreamError, type AgentStructuredOutputSpan, type AgentToolCallEvent, type AgentToolExecutionSpan, type AgentToolRetry, AgentUiComponent, AiToolCtx, type AppendMessageInput, type ApprovalWhere, type AttachmentRef, type AttachmentStagingStore, type BufferedModelTurnResult, type BuildMemoryBlockInput, type CostUsage, type CreateThreadInput, type CurrentModelPrice, DEFAULT_HISTORY_SUMMARY_INSTRUCTION, DEFAULT_MAX_FACT_CHARS, DEFAULT_MAX_MEMORIES, DEFAULT_MAX_SKILLS, DEFAULT_REFUSAL_REASON, DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION, Decision, DefaultRolesPolicy, type DetachedDelegationOutcome, type DetachedDelegationReceipt, DetachedDelivery, type DetailThreadRef, ElicitationRequest, type EmbeddingProvider, type ForgetMemoryInput, type FrameBuffer, GLOBAL_SCOPE, type GovernancePage, type GovernancePageQuery, type GovernanceRange, type GovernanceRunDetail, type GovernanceThreadDetail, type GovernanceThreadDetailQuery, type GovernanceUsageInput, HistoryPolicy, HumanReply, type IncrementalGate, InputProcessor, type ListMemoriesInput, type ListSkillsInput, type ListStagedAttachmentsInput, LlmStepEnvelope, type LoadSkillInput, type MemoryAuthor, type MemoryConfig, type MemoryDigest, type MemoryDigestEntry, type MemoryFact, type MemoryForgetRequest, type MemoryOrigin, type MemoryProvider, type MemoryRecord, type MemoryVerdict, type MemoryWriteOutcome, type MemoryWriteRequest, MessageAttachment, MessageUsage, ModelAnswer, ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type ObservedTurnFrames, type OfferMemoriesInput, type OutputGateMode, type OutputGateResult, OutputProcessor, type OverriddenMemory, PageContext, type Passage, type PendingApprovalRow, ProcessedPrompt, ProcessorContext, PromptBuilder, PromptContributor, QuotaExceededError, QuotaState, type QuotaStore, REMEMBER_TOOL_DESCRIPTION, REMEMBER_TOOL_NAME, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RememberToolInput, type RerankOptions, type Reranker, type ResolveAttachmentInput, type ResolveMemoryDigestInput, type ResolvedDelegation, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, RunCancelledError, type RunErrorBreakdownRow, type RunMetrics, type RunToolCallRow, type RunTrendPoint, type RunWhere, SKILL_TOOL_DESCRIPTION, SKILL_TOOL_NAME, type ScopeContext, type ScopeResolver, type SearchMemoriesInput, type SettledTask, type SinkWriter, type Skill, type SkillAuthor, type SkillCatalogEntry, type SkillContext, type SkillLoadOutcome, type SkillOffer, type SkillProvider, type SkillSummary, type SkillToolInput, type SkillWriteRequest, type SkillWriteVerdict, type SkillsConfig, type StageAttachmentInput, type StagedAttachment, type StoreMemoryInput, StoredMessage, type StreamError, type StructuredOutcome, StructuredOutputError, THREAD_DETAIL_CONTENT_CHARS, type ThreadActivityRow, ThreadDetail, type ThreadMessageRow, type ThreadMeta, type ThreadSpendRow, ThreadSummary, type ThreadTurnPage, type ThreadTurnQuery, type ThreadTurnReader, type ThreadUsageRollup, type ThreadWhere, type TokenStreamSink, type ToolCallActivityRow, ToolCallRequest, ToolCallStatus, type ToolCallWhere, ToolDefinition, ToolDisabledError, ToolForbiddenError, ToolHandler, ToolInputInvalidError, type ToolKindDeps, ToolNotFoundError, ToolRegistry, ToolResult, ToolSpec, type ToolStatRow, ToolStepEnvelope, ToolTransientRetrySetting, type TurnFrameSummary, type UpdateThreadInput, type UpdateToolCallInput, UsagePurpose, type UsageTrendPoint, type WindowHistoryOptions, type WithMemoryToolInput, type WriteMemoryInput, actorScope, agentDiagnosticKey, agentFailureCode, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, buildMemoryBlock, buildSkillsBlock, canActorUseTool, compositeSkillProvider, createFrameBuffer, createIncrementalGate, dayBoundsUtc, defaultScopeResolver, detachedDelivered, detachedStarted, detachedUnsettled, estimateCost, estimateMessageTokens, extractJson, filterToolsByAllowList, filterToolsByCanUse, filterToolsByEnabled, filterToolsByRole, gateFollowUps, gateTail, isControlFlowSignal, isReplayIntegrityError, isToolEnabled, loadSkill, memoryForgetVerdict, memoryWriteVerdict, normalizeDelegation, observeTurnFrames, offerMemories, offerSkills, publishAgentDelegated, publishAgentMemoryResolved, publishAgentMemoryWritten, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentSkillsResolved, publishAgentToolCall, publishAgentToolRetry, releaseGatedFrames, rememberInputSchema, rememberToolDefinition, repairInstruction, resolveGateLookback, resolveMemoryDigest, resolveOutputGateMode, resolveSkillCatalog, rollupThreadUsage, runAgentLoop, runInputProcessors, runOutputProcessors, seedModelPrices, settleAll, settleUnsettledDelegation, skillInputSchema, skillToolDefinition, skillWriteVerdict, stampToolKinds, staticSkillProvider, summarizeWithModel, tenantScope, traceLlmTurn, traceToolExecution, truncateDetailContent, validateStructured, windowHistory, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, writeMemory };
3289
+ export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DIAGNOSTIC_EVENTS, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MEMORY, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_SKILLS, AGENT_SKILL_SOURCES, AGENT_SPAN_EVENTS, AGENT_STORE, AGENT_TOOL_REGISTRY, APPROVAL_EXPIRED_REASON, Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentApprovalPort, AgentDefinition, type AgentDelegated, AgentDelegation, type AgentDiagnosticEvent, type AgentDiagnosticKey, type AgentFollowUpsSpan, type AgentGovernanceQueries, AgentIntake, type AgentLlmTurnSpan, type AgentLoopDeps, type AgentLoopHooks, type AgentLoopResult, type AgentMemoryResolved, type AgentMemoryWritten, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrievalSpan, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentSkillsResolved, type AgentSpanEvent, type AgentStore, AgentStreamError, type AgentStructuredOutputSpan, type AgentToolCallEvent, type AgentToolExecutionSpan, type AgentToolRetry, AgentUiComponent, AiToolCtx, type AppendMessageInput, type ApprovalDecisionRef, type ApprovalPolicy, type ApprovalRequirement, type ApprovalThreadRef, type ApprovalToolRef, type ApprovalWhere, type AttachmentRef, type AttachmentStagingStore, type BufferedModelTurnResult, type BuildMemoryBlockInput, type CostUsage, type CreateThreadInput, type CurrentModelPrice, DEFAULT_HISTORY_SUMMARY_INSTRUCTION, DEFAULT_MAX_FACT_CHARS, DEFAULT_MAX_MEMORIES, DEFAULT_MAX_SKILLS, DEFAULT_REFUSAL_REASON, DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION, Decision, DefaultApprovalPolicy, DefaultRolesPolicy, type DetachedDelegationOutcome, type DetachedDelegationReceipt, DetachedDelivery, type DetailThreadRef, ElicitationRequest, type EmbeddingProvider, type ForgetMemoryInput, type FrameBuffer, GLOBAL_SCOPE, type GovernancePage, type GovernancePageQuery, type GovernanceRange, type GovernanceRunDetail, type GovernanceThreadDetail, type GovernanceThreadDetailQuery, type GovernanceUsageInput, HistoryPolicy, HumanReply, type IncrementalGate, InputProcessor, type ListMemoriesInput, type ListSkillsInput, type ListStagedAttachmentsInput, LlmStepEnvelope, type LoadSkillInput, type MemoryAuthor, type MemoryConfig, type MemoryDigest, type MemoryDigestEntry, type MemoryFact, type MemoryForgetRequest, type MemoryOrigin, type MemoryProvider, type MemoryRecord, type MemoryVerdict, type MemoryWriteOutcome, type MemoryWriteRequest, MessageAttachment, MessageUsage, ModelAnswer, ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type ObservedTurnFrames, type OfferMemoriesInput, type OutputGateMode, type OutputGateResult, OutputProcessor, type OverriddenMemory, PageContext, type Passage, type PendingApprovalRow, ProcessedPrompt, ProcessorContext, PromptBuilder, PromptContributor, QuotaExceededError, QuotaState, type QuotaStore, REMEMBER_TOOL_DESCRIPTION, REMEMBER_TOOL_NAME, REQUESTER_APPROVER, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RememberToolInput, type RerankOptions, type Reranker, type ResolveAttachmentInput, type ResolveMemoryDigestInput, type ResolvedDelegation, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, RunCancelledError, type RunErrorBreakdownRow, type RunMetrics, type RunToolCallRow, type RunTrendPoint, type RunWhere, SKILL_TOOL_DESCRIPTION, SKILL_TOOL_NAME, type ScopeContext, type ScopeResolver, type SearchMemoriesInput, type SettledTask, type SinkWriter, type Skill, type SkillAuthor, type SkillCatalogEntry, type SkillContext, type SkillLoadOutcome, type SkillOffer, type SkillProvider, type SkillSummary, type SkillToolInput, type SkillWriteRequest, type SkillWriteVerdict, type SkillsConfig, type StageAttachmentInput, type StagedAttachment, type StoreMemoryInput, StoredMessage, type StreamError, type StructuredOutcome, StructuredOutputError, THREAD_DETAIL_CONTENT_CHARS, type ThreadActivityRow, ThreadDetail, type ThreadMessageRow, type ThreadMeta, type ThreadSpendRow, ThreadSummary, type ThreadTurnPage, type ThreadTurnQuery, type ThreadTurnReader, type ThreadUsageRollup, type ThreadWhere, type TokenStreamSink, type ToolCallActivityRow, ToolCallApproval, type ToolCallApprovalColumns, type ToolCallApprovalState, ToolCallRequest, ToolCallStatus, type ToolCallWhere, ToolDefinition, ToolDisabledError, ToolForbiddenError, ToolHandler, ToolInputInvalidError, ToolKind, type ToolKindDeps, ToolNotFoundError, ToolRegistry, ToolResult, ToolSpec, type ToolStatRow, ToolStepEnvelope, ToolTransientRetrySetting, type TurnFrameSummary, type UpdateThreadInput, type UpdateToolCallInput, UsagePurpose, type UsageTrendPoint, type WindowHistoryOptions, type WithMemoryToolInput, type WriteMemoryInput, actorScope, agentDiagnosticKey, agentFailureCode, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, buildMemoryBlock, buildSkillsBlock, canActorUseTool, compositeSkillProvider, createFrameBuffer, createIncrementalGate, dayBoundsUtc, defaultCanDecide, defaultScopeResolver, detachedDelivered, detachedStarted, detachedUnsettled, estimateCost, estimateMessageTokens, extractJson, filterToolsByAllowList, filterToolsByCanUse, filterToolsByEnabled, filterToolsByRole, gateFollowUps, gateTail, isControlFlowSignal, isReplayIntegrityError, isToolEnabled, loadSkill, mayDecideApproval, memoryForgetVerdict, memoryWriteVerdict, normalizeDelegation, observeTurnFrames, offerMemories, offerSkills, publishAgentDelegated, publishAgentMemoryResolved, publishAgentMemoryWritten, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentSkillsResolved, publishAgentToolCall, publishAgentToolRetry, releaseGatedFrames, rememberInputSchema, rememberToolDefinition, repairInstruction, resolveGateLookback, resolveMemoryDigest, resolveOutputGateMode, resolveSkillCatalog, rollupThreadUsage, runAgentLoop, runInputProcessors, runOutputProcessors, seedModelPrices, settleAll, settleUnsettledDelegation, skillInputSchema, skillToolDefinition, skillWriteVerdict, stampToolKinds, staticSkillProvider, summarizeWithModel, tenantScope, toolCallApprovalFromRow, traceLlmTurn, traceToolExecution, truncateDetailContent, validateStructured, windowHistory, withAskTool, withMemoryTool, withSkillTool, withToolTimeout, withTurnFrames, writeMemory };