@dudousxd/nestjs-agent-core 0.19.0 → 0.21.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/README.md +3 -1
- package/dist/guardrails/index.d.cts +1 -1
- package/dist/guardrails/index.d.ts +1 -1
- package/dist/index.cjs +622 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +151 -5
- package/dist/index.d.ts +151 -5
- package/dist/index.js +609 -42
- package/dist/index.js.map +1 -1
- package/dist/{tool-Q2rmGeaG.d.cts → tool-CwXibnce.d.cts} +164 -3
- package/dist/{tool-Q2rmGeaG.d.ts → tool-CwXibnce.d.ts} +164 -3
- package/package.json +1 -1
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,
|
|
2
|
-
export {
|
|
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-CwXibnce.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 ELICITATION_INPUT_TYPES, _ as ElicitationInput, $ as ElicitationInputType, a0 as ElicitationOption, a1 as ElicitationOutcome, a2 as ElicitationQuestion, a3 as ElicitationReply, a4 as ElicitationResult, a5 as HistoryPolicyContext, a6 as HistorySelection, a7 as HistorySummary, a8 as IncrementalGating, a9 as InvokeWithTransientRetryOptions, aa as MAX_ASK_QUESTIONS, ab as MessageRole, ac as OutputRejectedError, ad as OutputVerdict, ae as ProcessorFailedError, af as PromptContext, ag as QuotaView, ah as ToolCallApprovalStatus, ai as ToolCatalogEntry, aj as ToolConfirmation, ak as ToolPresentation, al as ToolPresentationTone, am as ToolResultField, an as ToolResultView, ao as ToolStepCtx, ap as ToolTransientRetryNumbers, aq as ToolTransientRetryOptions, ar as askInputSchema, as as askToolDefinition, at as decodeStreamEvent, au as encodeStreamEvent, av as invokeWithTransientRetry, aw as isTransientToolError, ax as isTypedQuestion, ay as normalizeElicitationReply, az as questionOptions, aA as readElicitationInput, aB as readElicitationQuestions, aC as renderElicitationAnswers, aD as resolveElicitation, aE as resolveToolTransientRetryNumbers, aF as settleElicitation, aG as validateElicitationAnswer, aH as validateElicitationValue } from './tool-CwXibnce.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,26 @@ 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>;
|
|
492
|
+
/**
|
|
493
|
+
* OPTIONAL: the input a call was recorded with, or `null` when the call is unknown. Read by the
|
|
494
|
+
* answer route to check a reply against the questions it answers (a typed question's rules, a
|
|
495
|
+
* `required` one left empty) before it is signalled. Absent → answers are checked for shape only,
|
|
496
|
+
* and the loop drops what it cannot settle.
|
|
497
|
+
*/
|
|
498
|
+
toolCallInput?(toolCallId: string): Promise<unknown>;
|
|
460
499
|
/**
|
|
461
500
|
* OPTIONAL: of `mediaIds`, the ones a message that still exists — in a thread owned by
|
|
462
501
|
* `actorRef` — still carries as an attachment. The inverse of
|
|
@@ -1146,15 +1185,105 @@ interface AttachmentStagingStore {
|
|
|
1146
1185
|
* approvals inbox renders read-only.
|
|
1147
1186
|
*/
|
|
1148
1187
|
interface AgentApprovalPort {
|
|
1188
|
+
/**
|
|
1189
|
+
* `remember` approves later calls of the same tool in the same thread; `decidedVia` names the
|
|
1190
|
+
* surface the decision came through (`'console'`, `'slack'`, …) and is persisted with the call.
|
|
1191
|
+
*/
|
|
1149
1192
|
approve(toolCallId: string, opts?: {
|
|
1150
1193
|
executedByRef?: string;
|
|
1194
|
+
remember?: boolean;
|
|
1195
|
+
decidedVia?: string;
|
|
1151
1196
|
}): Promise<void>;
|
|
1152
1197
|
reject(toolCallId: string, opts?: {
|
|
1153
1198
|
executedByRef?: string;
|
|
1154
1199
|
reason?: string;
|
|
1200
|
+
decidedVia?: string;
|
|
1155
1201
|
}): Promise<void>;
|
|
1156
1202
|
}
|
|
1157
1203
|
|
|
1204
|
+
/** The approver that means "the person the run is acting for" — the thread's own actor. */
|
|
1205
|
+
declare const REQUESTER_APPROVER = "requester";
|
|
1206
|
+
/** The tool a requirement is asked about. `spec` is absent where this process cannot resolve it. */
|
|
1207
|
+
interface ApprovalToolRef {
|
|
1208
|
+
name: string;
|
|
1209
|
+
kind: ToolKind;
|
|
1210
|
+
spec?: ToolSpec;
|
|
1211
|
+
}
|
|
1212
|
+
/** Where the call is being made. */
|
|
1213
|
+
interface ApprovalThreadRef {
|
|
1214
|
+
threadId: string;
|
|
1215
|
+
runId: string;
|
|
1216
|
+
agentName?: string;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* What an action tool call needs before it runs.
|
|
1220
|
+
*
|
|
1221
|
+
* - `required: false` → the call runs without asking anyone (it is still recorded as an action).
|
|
1222
|
+
* - `approver` → who may decide: {@link REQUESTER_APPROVER} (the thread's own actor — the default)
|
|
1223
|
+
* or any other string, which the default {@link ApprovalPolicy.canDecide} reads as a ROLE the
|
|
1224
|
+
* decider must hold. Streamed on `approval-requested` and persisted on the call.
|
|
1225
|
+
* - `ttlMs` → how long the request stays open. When it lapses the call settles `expired` and the
|
|
1226
|
+
* model is told nobody approved it. Absent → it waits indefinitely.
|
|
1227
|
+
*/
|
|
1228
|
+
interface ApprovalRequirement {
|
|
1229
|
+
required: boolean;
|
|
1230
|
+
approver: string;
|
|
1231
|
+
ttlMs?: number;
|
|
1232
|
+
}
|
|
1233
|
+
/** A decision about to be taken on a call, as {@link ApprovalPolicy.canDecide} sees it. */
|
|
1234
|
+
interface ApprovalDecisionRef {
|
|
1235
|
+
toolCallId: string;
|
|
1236
|
+
/** The approver recorded on the call when it was put to a person. */
|
|
1237
|
+
approver: string;
|
|
1238
|
+
/** The actorRef the run is acting for — the owner of the call's thread. */
|
|
1239
|
+
requesterRef: string;
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Who has to approve an action tool call, and for how long the request stays open.
|
|
1243
|
+
*
|
|
1244
|
+
* Consulted by the LOOP once per `action` call, inside the call's `persist:toolcall` checkpoint — so
|
|
1245
|
+
* a durable run reads the answer back on every replay instead of re-deciding it against a policy
|
|
1246
|
+
* that may have changed while it was parked. Only `action` calls are asked about: a policy cannot
|
|
1247
|
+
* put a `read` behind an approval, and an `ask` (a question set) is always the requester's.
|
|
1248
|
+
*/
|
|
1249
|
+
interface ApprovalPolicy {
|
|
1250
|
+
requirementFor(tool: ApprovalToolRef, actor: Actor, thread: ApprovalThreadRef): ApprovalRequirement | Promise<ApprovalRequirement>;
|
|
1251
|
+
/**
|
|
1252
|
+
* May `actor` settle this call? Checked by the approve/reject routes before a decision is
|
|
1253
|
+
* signalled. Absent → {@link defaultCanDecide}: the requester approver means the thread's own
|
|
1254
|
+
* actor, anything else is a role the actor must hold. Plug an authz Gate here for abilities.
|
|
1255
|
+
*/
|
|
1256
|
+
canDecide?(actor: Actor, decision: ApprovalDecisionRef): boolean | Promise<boolean>;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* The behaviour the lib always had: every `action` call waits on the person who asked, with no
|
|
1260
|
+
* expiry.
|
|
1261
|
+
*/
|
|
1262
|
+
declare class DefaultApprovalPolicy implements ApprovalPolicy {
|
|
1263
|
+
requirementFor(tool: ApprovalToolRef): ApprovalRequirement;
|
|
1264
|
+
}
|
|
1265
|
+
/** The default decider rule — see {@link ApprovalPolicy.canDecide}. */
|
|
1266
|
+
declare function defaultCanDecide(actor: Actor, decision: ApprovalDecisionRef): boolean;
|
|
1267
|
+
/** Resolve whether `actor` may decide, through the policy's own rule when it has one. */
|
|
1268
|
+
declare function mayDecideApproval(policy: ApprovalPolicy | undefined, actor: Actor, decision: ApprovalDecisionRef): Promise<boolean>;
|
|
1269
|
+
/** The columns a store keeps for one call's approval, however it names them. */
|
|
1270
|
+
interface ToolCallApprovalColumns {
|
|
1271
|
+
toolCallId: string;
|
|
1272
|
+
status: ToolCallStatus;
|
|
1273
|
+
approver: string | null | undefined;
|
|
1274
|
+
expiresAt: string | Date | null | undefined;
|
|
1275
|
+
remember: boolean | null | undefined;
|
|
1276
|
+
executedByRef: string | null | undefined;
|
|
1277
|
+
decidedVia: string | null | undefined;
|
|
1278
|
+
error: string | null | undefined;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Read a tool-call row back as the {@link ToolCallApproval} a thread carries, or `null` for a call
|
|
1282
|
+
* no policy put to anyone (no approver recorded). Shared by every store so they agree on the
|
|
1283
|
+
* status mapping: a call that ran — or ran and failed — after a decision was APPROVED.
|
|
1284
|
+
*/
|
|
1285
|
+
declare function toolCallApprovalFromRow(row: ToolCallApprovalColumns): ToolCallApproval | null;
|
|
1286
|
+
|
|
1158
1287
|
/**
|
|
1159
1288
|
* The pure aggregation core shared by every {@link import('../spi/governance-queries.js').AgentGovernanceQueries}
|
|
1160
1289
|
* adapter (MikroORM, Drizzle, in-memory). An adapter's only job is the DB-specific row fetch; the
|
|
@@ -2470,6 +2599,11 @@ interface AgentLoopDeps<TOutput = unknown> {
|
|
|
2470
2599
|
store: AgentStore;
|
|
2471
2600
|
registry: ToolRegistry;
|
|
2472
2601
|
rolesPolicy: RolesPolicy;
|
|
2602
|
+
/**
|
|
2603
|
+
* Who has to approve an `action` call, and for how long the request stays open. Undefined →
|
|
2604
|
+
* {@link DefaultApprovalPolicy}: the requester, with no expiry — the behaviour before the SPI.
|
|
2605
|
+
*/
|
|
2606
|
+
approvalPolicy?: ApprovalPolicy;
|
|
2473
2607
|
quota?: QuotaStore;
|
|
2474
2608
|
/**
|
|
2475
2609
|
* Fallback accounting label when the provider's turn result doesn't report a `modelId`.
|
|
@@ -2702,8 +2836,18 @@ interface AgentLoopHooks {
|
|
|
2702
2836
|
runId: string;
|
|
2703
2837
|
/** A writer for this run's live token stream (data plane). */
|
|
2704
2838
|
openSink(): SinkWriter | Promise<SinkWriter>;
|
|
2705
|
-
/**
|
|
2706
|
-
|
|
2839
|
+
/**
|
|
2840
|
+
* HITL gate for an action tool. Inline resolves a pending promise; durable awaits a signal.
|
|
2841
|
+
*
|
|
2842
|
+
* `opts.timeoutMs` is the request's time to live, from the turn's `ApprovalPolicy`. When it
|
|
2843
|
+
* elapses with no decision the runner resolves `{ approved: false, expired: true }` — it must not
|
|
2844
|
+
* throw — and the loop settles the call `expired`. The value comes out of the call's
|
|
2845
|
+
* `persist:toolcall` checkpoint, so it is the same on every replay; a durable runner hands it to
|
|
2846
|
+
* its own timed wait (whose deadline the runtime journals), an inline one arms a timer.
|
|
2847
|
+
*/
|
|
2848
|
+
awaitApproval(call: ToolCallRequest, ctx: AiToolCtx, opts?: {
|
|
2849
|
+
timeoutMs?: number;
|
|
2850
|
+
}): Promise<Decision>;
|
|
2707
2851
|
/**
|
|
2708
2852
|
* Park the run on a question set and resolve with what the human sent back. The SAME wait
|
|
2709
2853
|
* `awaitApproval` is — the durable runner maps both to `ctx.waitForSignal` on
|
|
@@ -2896,6 +3040,8 @@ declare function withAskTool({ tools, ask, }: {
|
|
|
2896
3040
|
tools: ToolDefinition[];
|
|
2897
3041
|
ask: boolean | undefined;
|
|
2898
3042
|
}): ToolDefinition[];
|
|
3043
|
+
/** The reason an expired call is denied with — on the row, the stream frame and the result. */
|
|
3044
|
+
declare const APPROVAL_EXPIRED_REASON = "approval expired";
|
|
2899
3045
|
/**
|
|
2900
3046
|
* Stored as the reason when someone declines without giving one. It is a placeholder, not something
|
|
2901
3047
|
* a person said, so every reader has to filter it out — which is why it is exported rather than
|
|
@@ -3147,4 +3293,4 @@ type AgentDiagnosticKey = `agent:${AgentDiagnosticEvent}`;
|
|
|
3147
3293
|
*/
|
|
3148
3294
|
declare function agentDiagnosticKey(event: AgentDiagnosticEvent): AgentDiagnosticKey;
|
|
3149
3295
|
|
|
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 };
|
|
3296
|
+
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,
|
|
2
|
-
export {
|
|
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-CwXibnce.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 ELICITATION_INPUT_TYPES, _ as ElicitationInput, $ as ElicitationInputType, a0 as ElicitationOption, a1 as ElicitationOutcome, a2 as ElicitationQuestion, a3 as ElicitationReply, a4 as ElicitationResult, a5 as HistoryPolicyContext, a6 as HistorySelection, a7 as HistorySummary, a8 as IncrementalGating, a9 as InvokeWithTransientRetryOptions, aa as MAX_ASK_QUESTIONS, ab as MessageRole, ac as OutputRejectedError, ad as OutputVerdict, ae as ProcessorFailedError, af as PromptContext, ag as QuotaView, ah as ToolCallApprovalStatus, ai as ToolCatalogEntry, aj as ToolConfirmation, ak as ToolPresentation, al as ToolPresentationTone, am as ToolResultField, an as ToolResultView, ao as ToolStepCtx, ap as ToolTransientRetryNumbers, aq as ToolTransientRetryOptions, ar as askInputSchema, as as askToolDefinition, at as decodeStreamEvent, au as encodeStreamEvent, av as invokeWithTransientRetry, aw as isTransientToolError, ax as isTypedQuestion, ay as normalizeElicitationReply, az as questionOptions, aA as readElicitationInput, aB as readElicitationQuestions, aC as renderElicitationAnswers, aD as resolveElicitation, aE as resolveToolTransientRetryNumbers, aF as settleElicitation, aG as validateElicitationAnswer, aH as validateElicitationValue } from './tool-CwXibnce.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,26 @@ 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>;
|
|
492
|
+
/**
|
|
493
|
+
* OPTIONAL: the input a call was recorded with, or `null` when the call is unknown. Read by the
|
|
494
|
+
* answer route to check a reply against the questions it answers (a typed question's rules, a
|
|
495
|
+
* `required` one left empty) before it is signalled. Absent → answers are checked for shape only,
|
|
496
|
+
* and the loop drops what it cannot settle.
|
|
497
|
+
*/
|
|
498
|
+
toolCallInput?(toolCallId: string): Promise<unknown>;
|
|
460
499
|
/**
|
|
461
500
|
* OPTIONAL: of `mediaIds`, the ones a message that still exists — in a thread owned by
|
|
462
501
|
* `actorRef` — still carries as an attachment. The inverse of
|
|
@@ -1146,15 +1185,105 @@ interface AttachmentStagingStore {
|
|
|
1146
1185
|
* approvals inbox renders read-only.
|
|
1147
1186
|
*/
|
|
1148
1187
|
interface AgentApprovalPort {
|
|
1188
|
+
/**
|
|
1189
|
+
* `remember` approves later calls of the same tool in the same thread; `decidedVia` names the
|
|
1190
|
+
* surface the decision came through (`'console'`, `'slack'`, …) and is persisted with the call.
|
|
1191
|
+
*/
|
|
1149
1192
|
approve(toolCallId: string, opts?: {
|
|
1150
1193
|
executedByRef?: string;
|
|
1194
|
+
remember?: boolean;
|
|
1195
|
+
decidedVia?: string;
|
|
1151
1196
|
}): Promise<void>;
|
|
1152
1197
|
reject(toolCallId: string, opts?: {
|
|
1153
1198
|
executedByRef?: string;
|
|
1154
1199
|
reason?: string;
|
|
1200
|
+
decidedVia?: string;
|
|
1155
1201
|
}): Promise<void>;
|
|
1156
1202
|
}
|
|
1157
1203
|
|
|
1204
|
+
/** The approver that means "the person the run is acting for" — the thread's own actor. */
|
|
1205
|
+
declare const REQUESTER_APPROVER = "requester";
|
|
1206
|
+
/** The tool a requirement is asked about. `spec` is absent where this process cannot resolve it. */
|
|
1207
|
+
interface ApprovalToolRef {
|
|
1208
|
+
name: string;
|
|
1209
|
+
kind: ToolKind;
|
|
1210
|
+
spec?: ToolSpec;
|
|
1211
|
+
}
|
|
1212
|
+
/** Where the call is being made. */
|
|
1213
|
+
interface ApprovalThreadRef {
|
|
1214
|
+
threadId: string;
|
|
1215
|
+
runId: string;
|
|
1216
|
+
agentName?: string;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* What an action tool call needs before it runs.
|
|
1220
|
+
*
|
|
1221
|
+
* - `required: false` → the call runs without asking anyone (it is still recorded as an action).
|
|
1222
|
+
* - `approver` → who may decide: {@link REQUESTER_APPROVER} (the thread's own actor — the default)
|
|
1223
|
+
* or any other string, which the default {@link ApprovalPolicy.canDecide} reads as a ROLE the
|
|
1224
|
+
* decider must hold. Streamed on `approval-requested` and persisted on the call.
|
|
1225
|
+
* - `ttlMs` → how long the request stays open. When it lapses the call settles `expired` and the
|
|
1226
|
+
* model is told nobody approved it. Absent → it waits indefinitely.
|
|
1227
|
+
*/
|
|
1228
|
+
interface ApprovalRequirement {
|
|
1229
|
+
required: boolean;
|
|
1230
|
+
approver: string;
|
|
1231
|
+
ttlMs?: number;
|
|
1232
|
+
}
|
|
1233
|
+
/** A decision about to be taken on a call, as {@link ApprovalPolicy.canDecide} sees it. */
|
|
1234
|
+
interface ApprovalDecisionRef {
|
|
1235
|
+
toolCallId: string;
|
|
1236
|
+
/** The approver recorded on the call when it was put to a person. */
|
|
1237
|
+
approver: string;
|
|
1238
|
+
/** The actorRef the run is acting for — the owner of the call's thread. */
|
|
1239
|
+
requesterRef: string;
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Who has to approve an action tool call, and for how long the request stays open.
|
|
1243
|
+
*
|
|
1244
|
+
* Consulted by the LOOP once per `action` call, inside the call's `persist:toolcall` checkpoint — so
|
|
1245
|
+
* a durable run reads the answer back on every replay instead of re-deciding it against a policy
|
|
1246
|
+
* that may have changed while it was parked. Only `action` calls are asked about: a policy cannot
|
|
1247
|
+
* put a `read` behind an approval, and an `ask` (a question set) is always the requester's.
|
|
1248
|
+
*/
|
|
1249
|
+
interface ApprovalPolicy {
|
|
1250
|
+
requirementFor(tool: ApprovalToolRef, actor: Actor, thread: ApprovalThreadRef): ApprovalRequirement | Promise<ApprovalRequirement>;
|
|
1251
|
+
/**
|
|
1252
|
+
* May `actor` settle this call? Checked by the approve/reject routes before a decision is
|
|
1253
|
+
* signalled. Absent → {@link defaultCanDecide}: the requester approver means the thread's own
|
|
1254
|
+
* actor, anything else is a role the actor must hold. Plug an authz Gate here for abilities.
|
|
1255
|
+
*/
|
|
1256
|
+
canDecide?(actor: Actor, decision: ApprovalDecisionRef): boolean | Promise<boolean>;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* The behaviour the lib always had: every `action` call waits on the person who asked, with no
|
|
1260
|
+
* expiry.
|
|
1261
|
+
*/
|
|
1262
|
+
declare class DefaultApprovalPolicy implements ApprovalPolicy {
|
|
1263
|
+
requirementFor(tool: ApprovalToolRef): ApprovalRequirement;
|
|
1264
|
+
}
|
|
1265
|
+
/** The default decider rule — see {@link ApprovalPolicy.canDecide}. */
|
|
1266
|
+
declare function defaultCanDecide(actor: Actor, decision: ApprovalDecisionRef): boolean;
|
|
1267
|
+
/** Resolve whether `actor` may decide, through the policy's own rule when it has one. */
|
|
1268
|
+
declare function mayDecideApproval(policy: ApprovalPolicy | undefined, actor: Actor, decision: ApprovalDecisionRef): Promise<boolean>;
|
|
1269
|
+
/** The columns a store keeps for one call's approval, however it names them. */
|
|
1270
|
+
interface ToolCallApprovalColumns {
|
|
1271
|
+
toolCallId: string;
|
|
1272
|
+
status: ToolCallStatus;
|
|
1273
|
+
approver: string | null | undefined;
|
|
1274
|
+
expiresAt: string | Date | null | undefined;
|
|
1275
|
+
remember: boolean | null | undefined;
|
|
1276
|
+
executedByRef: string | null | undefined;
|
|
1277
|
+
decidedVia: string | null | undefined;
|
|
1278
|
+
error: string | null | undefined;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Read a tool-call row back as the {@link ToolCallApproval} a thread carries, or `null` for a call
|
|
1282
|
+
* no policy put to anyone (no approver recorded). Shared by every store so they agree on the
|
|
1283
|
+
* status mapping: a call that ran — or ran and failed — after a decision was APPROVED.
|
|
1284
|
+
*/
|
|
1285
|
+
declare function toolCallApprovalFromRow(row: ToolCallApprovalColumns): ToolCallApproval | null;
|
|
1286
|
+
|
|
1158
1287
|
/**
|
|
1159
1288
|
* The pure aggregation core shared by every {@link import('../spi/governance-queries.js').AgentGovernanceQueries}
|
|
1160
1289
|
* adapter (MikroORM, Drizzle, in-memory). An adapter's only job is the DB-specific row fetch; the
|
|
@@ -2470,6 +2599,11 @@ interface AgentLoopDeps<TOutput = unknown> {
|
|
|
2470
2599
|
store: AgentStore;
|
|
2471
2600
|
registry: ToolRegistry;
|
|
2472
2601
|
rolesPolicy: RolesPolicy;
|
|
2602
|
+
/**
|
|
2603
|
+
* Who has to approve an `action` call, and for how long the request stays open. Undefined →
|
|
2604
|
+
* {@link DefaultApprovalPolicy}: the requester, with no expiry — the behaviour before the SPI.
|
|
2605
|
+
*/
|
|
2606
|
+
approvalPolicy?: ApprovalPolicy;
|
|
2473
2607
|
quota?: QuotaStore;
|
|
2474
2608
|
/**
|
|
2475
2609
|
* Fallback accounting label when the provider's turn result doesn't report a `modelId`.
|
|
@@ -2702,8 +2836,18 @@ interface AgentLoopHooks {
|
|
|
2702
2836
|
runId: string;
|
|
2703
2837
|
/** A writer for this run's live token stream (data plane). */
|
|
2704
2838
|
openSink(): SinkWriter | Promise<SinkWriter>;
|
|
2705
|
-
/**
|
|
2706
|
-
|
|
2839
|
+
/**
|
|
2840
|
+
* HITL gate for an action tool. Inline resolves a pending promise; durable awaits a signal.
|
|
2841
|
+
*
|
|
2842
|
+
* `opts.timeoutMs` is the request's time to live, from the turn's `ApprovalPolicy`. When it
|
|
2843
|
+
* elapses with no decision the runner resolves `{ approved: false, expired: true }` — it must not
|
|
2844
|
+
* throw — and the loop settles the call `expired`. The value comes out of the call's
|
|
2845
|
+
* `persist:toolcall` checkpoint, so it is the same on every replay; a durable runner hands it to
|
|
2846
|
+
* its own timed wait (whose deadline the runtime journals), an inline one arms a timer.
|
|
2847
|
+
*/
|
|
2848
|
+
awaitApproval(call: ToolCallRequest, ctx: AiToolCtx, opts?: {
|
|
2849
|
+
timeoutMs?: number;
|
|
2850
|
+
}): Promise<Decision>;
|
|
2707
2851
|
/**
|
|
2708
2852
|
* Park the run on a question set and resolve with what the human sent back. The SAME wait
|
|
2709
2853
|
* `awaitApproval` is — the durable runner maps both to `ctx.waitForSignal` on
|
|
@@ -2896,6 +3040,8 @@ declare function withAskTool({ tools, ask, }: {
|
|
|
2896
3040
|
tools: ToolDefinition[];
|
|
2897
3041
|
ask: boolean | undefined;
|
|
2898
3042
|
}): ToolDefinition[];
|
|
3043
|
+
/** The reason an expired call is denied with — on the row, the stream frame and the result. */
|
|
3044
|
+
declare const APPROVAL_EXPIRED_REASON = "approval expired";
|
|
2899
3045
|
/**
|
|
2900
3046
|
* Stored as the reason when someone declines without giving one. It is a placeholder, not something
|
|
2901
3047
|
* a person said, so every reader has to filter it out — which is why it is exported rather than
|
|
@@ -3147,4 +3293,4 @@ type AgentDiagnosticKey = `agent:${AgentDiagnosticEvent}`;
|
|
|
3147
3293
|
*/
|
|
3148
3294
|
declare function agentDiagnosticKey(event: AgentDiagnosticEvent): AgentDiagnosticKey;
|
|
3149
3295
|
|
|
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 };
|
|
3296
|
+
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 };
|