@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.
@@ -323,6 +323,25 @@ interface AgentApprovalRequest {
323
323
  /** Why this call needs a person, in words for that person. */
324
324
  reason?: string;
325
325
  }
326
+ /**
327
+ * How an approval settled — the other half of {@link AgentApprovalRequest}, under the same `id`.
328
+ * Metadata again: the call's own outcome still arrives as `tool-output` (approved and ran),
329
+ * `tool-output-error` (approved and failed) or `tool-output-denied` (rejected or expired).
330
+ */
331
+ interface AgentApprovalSettlement {
332
+ id: string;
333
+ status: 'approved' | 'rejected' | 'expired';
334
+ /** Repeated from the request, for a call approved without one being streamed (a remembered approval). */
335
+ approver?: string;
336
+ /** Opaque ref of who decided. Absent on an expiry. */
337
+ decidedBy?: string;
338
+ /** The surface the decision came through: `'web'`, `'slack'`, `'remembered'`, … */
339
+ decidedVia?: string;
340
+ /** The approval also covers later calls of this tool in this thread. */
341
+ remember?: boolean;
342
+ /** What the person said when declining. */
343
+ reason?: string;
344
+ }
326
345
  type AgentStreamEvent = {
327
346
  kind: 'step-start';
328
347
  }
@@ -414,6 +433,14 @@ type AgentStreamEvent = {
414
433
  | ({
415
434
  kind: 'approval-requested';
416
435
  } & AgentApprovalRequest)
436
+ /**
437
+ * A parked action call was decided (or lapsed). Optional, like `approval-requested`: it adds WHO
438
+ * decided, THROUGH WHAT and whether the approval is REMEMBERED; the outcome itself rides the
439
+ * call's own output frame. See {@link AgentApprovalSettlement}.
440
+ */
441
+ | ({
442
+ kind: 'approval-settled';
443
+ } & AgentApprovalSettlement)
417
444
  /**
418
445
  * Server-pushed generative UI, positioned in the message where it arrives. Not tied to a tool
419
446
  * call. See {@link AgentUiComponent}.
@@ -738,6 +765,12 @@ interface ToolResult {
738
765
  * tool's outcome on; this flag is what everything else reads.
739
766
  */
740
767
  denied?: true;
768
+ /**
769
+ * The approval request lapsed before anyone decided, so the tool never ran. Always set together
770
+ * with {@link denied}: an expiry IS a refusal to every consumer that only knows that much, and this
771
+ * flag is for the ones that tell "nobody answered" from "someone said no".
772
+ */
773
+ expired?: true;
741
774
  id: string;
742
775
  name: string;
743
776
  output: unknown;
@@ -817,6 +850,22 @@ interface Decision {
817
850
  * (the chat flow).
818
851
  */
819
852
  executedByRef?: string;
853
+ /**
854
+ * Approve later calls of the SAME tool in the SAME thread without asking again. Read only on an
855
+ * approval; the loop answers it through {@link import('./spi/agent-store.js').AgentStore.rememberedApprovals}.
856
+ */
857
+ remember?: boolean;
858
+ /**
859
+ * The surface the decision came through — `'web'`, `'slack'`, `'console'`, anything the caller
860
+ * names. Provenance only: persisted with the call, never authorized against.
861
+ */
862
+ decidedVia?: string;
863
+ /**
864
+ * Nobody decided before the request lapsed. Set by the RUNNER when the approval wait times out
865
+ * (see `AgentLoopHooks.awaitApproval`'s `timeoutMs`), never by a person — the HTTP surface does not
866
+ * accept it. Read as a denial the model is told expired.
867
+ */
868
+ expired?: true;
820
869
  }
821
870
  type MessageRole = 'user' | 'assistant' | 'system';
822
871
  /**
@@ -1044,13 +1093,44 @@ interface StoredMessage {
1044
1093
  * props for each `id` — a reloaded thread replays them as `data-ui` parts.
1045
1094
  */
1046
1095
  ui?: AgentUiComponent[];
1096
+ /**
1097
+ * The approval record of every call on this message that was put to a person under an
1098
+ * {@link import('./spi/approval-policy.js').ApprovalPolicy} — who had to decide, until when, and how
1099
+ * it settled. Read off the tool-call rows by the store; absent when no call on the message asked
1100
+ * for one, or on a store that does not record approvals.
1101
+ */
1102
+ approvals?: ToolCallApproval[];
1047
1103
  createdAt: string;
1048
1104
  }
1105
+ /**
1106
+ * How one approval stands. `pending` → still parked; `approved` → someone said yes (or a remembered
1107
+ * approval did); `rejected` → someone said no; `expired` → nobody answered before `expiresAt`.
1108
+ */
1109
+ type ToolCallApprovalStatus = 'pending' | 'approved' | 'rejected' | 'expired';
1110
+ /** The persisted approval metadata of one action tool call. See {@link StoredMessage.approvals}. */
1111
+ interface ToolCallApproval {
1112
+ toolCallId: string;
1113
+ /** Who may decide: `'requester'` (the thread's own actor) or a role name. */
1114
+ approver: string;
1115
+ /** ISO-8601 instant the request lapses; absent → it never does. */
1116
+ expiresAt?: string;
1117
+ status: ToolCallApprovalStatus;
1118
+ /** The decision asked for later calls of this tool in this thread to be approved automatically. */
1119
+ remember?: boolean;
1120
+ /** Opaque ref of who decided. Absent while pending and on an expiry. */
1121
+ decidedBy?: string;
1122
+ /** The surface the decision came through (`'web'`, `'slack'`, `'remembered'`, …). */
1123
+ decidedVia?: string;
1124
+ /** What the person said when declining. */
1125
+ reason?: string;
1126
+ }
1049
1127
  interface ThreadDetail extends ThreadSummary {
1050
1128
  messages: StoredMessage[];
1051
1129
  activeStreamId?: string;
1052
1130
  }
1053
- type ToolCallStatus = 'auto_executed' | 'pending_approval' | 'executed' | 'rejected' | 'failed';
1131
+ type ToolCallStatus = 'auto_executed' | 'pending_approval' | 'executed' | 'rejected' | 'failed'
1132
+ /** An approval request lapsed before anyone decided; the tool never ran. */
1133
+ | 'expired';
1054
1134
  /**
1055
1135
  * Serializable input for a dispatched model-turn step. Carries only data — the serving worker
1056
1136
  * re-resolves the model/sink/registry from its own DI via AGENT_DEPS_FACTORY.forAgent(agentName).
@@ -1305,4 +1385,4 @@ interface ToolHandler<I = unknown> {
1305
1385
  canUse?(actor: Actor): boolean | Promise<boolean>;
1306
1386
  }
1307
1387
 
1308
- export { type HistoryPolicyContext as $, type Actor as A, type AgentApprovalRequest as B, type AgentCatalogEntry as C, type DetachedDelivery as D, type ElicitationRequest as E, type AgentHistoryWindow as F, type AgentStreamEvent as G, type HumanReply as H, type InputProcessor as I, type AskToolInput as J, DEFAULT_INCREMENTAL_LOOKBACK_CHARS as K, type LlmStepEnvelope as L, type ModelMessage as M, DEFAULT_INTAKE_PREAMBLE as N, type OutputProcessor as O, type ProcessorContext as P, type QuotaState as Q, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as R, type StoredMessage as S, type ToolHandler as T, type UsagePurpose as U, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as V, type ElicitationOption as W, type ElicitationOutcome as X, type ElicitationQuestion as Y, type ElicitationReply as Z, type ElicitationResult as _, type ToolDefinition as a, type HistorySelection as a0, type HistorySummary as a1, type IncrementalGating as a2, type InvokeWithTransientRetryOptions as a3, MAX_ASK_QUESTIONS as a4, type MessageRole as a5, OutputRejectedError as a6, type OutputVerdict as a7, ProcessorFailedError as a8, type PromptContext as a9, type QuotaView as aa, type ToolCatalogEntry as ab, type ToolConfirmation as ac, type ToolKind as ad, type ToolPresentation as ae, type ToolPresentationTone as af, type ToolResultField as ag, type ToolResultView as ah, type ToolStepCtx as ai, type ToolTransientRetryNumbers as aj, type ToolTransientRetryOptions as ak, askInputSchema as al, askToolDefinition as am, decodeStreamEvent as an, encodeStreamEvent as ao, invokeWithTransientRetry as ap, isTransientToolError as aq, normalizeElicitationReply as ar, renderElicitationAnswers as as, resolveElicitation as at, resolveToolTransientRetryNumbers as au, settleElicitation as av, type ToolCallRequest as b, type MessageUsage as c, type AgentUiComponent as d, type ThreadSummary as e, type ThreadDetail as f, type ToolResult as g, type MessageAttachment as h, type ToolCallStatus as i, type ToolSpec as j, type AgentRunInput as k, type HistoryPolicy as l, type ProcessedPrompt as m, type ModelAnswer as n, type PageContext as o, type AgentDefinition as p, type AgentDelegation as q, type AiToolCtx as r, type PromptBuilder as s, type PromptContributor as t, type ToolTransientRetrySetting as u, type AgentIntake as v, type Decision as w, type ToolStepEnvelope as x, ASK_TOOL_DESCRIPTION as y, ASK_TOOL_NAME as z };
1388
+ export { type ElicitationQuestion as $, type Actor as A, ASK_TOOL_DESCRIPTION as B, ASK_TOOL_NAME as C, type DetachedDelivery as D, type ElicitationRequest as E, type AgentApprovalRequest as F, type AgentApprovalSettlement as G, type HumanReply as H, type InputProcessor as I, type AgentCatalogEntry as J, type AgentHistoryWindow as K, type LlmStepEnvelope as L, type ModelMessage as M, type AgentStreamEvent as N, type OutputProcessor as O, type ProcessorContext as P, type QuotaState as Q, type AskToolInput as R, type StoredMessage as S, type ToolHandler as T, type UsagePurpose as U, DEFAULT_INCREMENTAL_LOOKBACK_CHARS as V, DEFAULT_INTAKE_PREAMBLE as W, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as X, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as Y, type ElicitationOption as Z, type ElicitationOutcome as _, type ToolDefinition as a, type ElicitationReply as a0, type ElicitationResult as a1, type HistoryPolicyContext as a2, type HistorySelection as a3, type HistorySummary as a4, type IncrementalGating as a5, type InvokeWithTransientRetryOptions as a6, MAX_ASK_QUESTIONS as a7, type MessageRole as a8, OutputRejectedError as a9, type OutputVerdict as aa, ProcessorFailedError as ab, type PromptContext as ac, type QuotaView as ad, type ToolCallApprovalStatus as ae, type ToolCatalogEntry as af, type ToolConfirmation as ag, type ToolPresentation as ah, type ToolPresentationTone as ai, type ToolResultField as aj, type ToolResultView as ak, type ToolStepCtx as al, type ToolTransientRetryNumbers as am, type ToolTransientRetryOptions as an, askInputSchema as ao, askToolDefinition as ap, decodeStreamEvent as aq, encodeStreamEvent as ar, invokeWithTransientRetry as as, isTransientToolError as at, normalizeElicitationReply as au, renderElicitationAnswers as av, resolveElicitation as aw, resolveToolTransientRetryNumbers as ax, settleElicitation as ay, type ToolCallRequest as b, type MessageUsage as c, type AgentUiComponent as d, type ThreadSummary as e, type ThreadDetail as f, type ToolResult as g, type MessageAttachment as h, type ToolCallStatus as i, type ToolSpec as j, type AgentRunInput as k, type ToolKind as l, type ToolCallApproval as m, type HistoryPolicy as n, type ProcessedPrompt as o, type ModelAnswer as p, type PageContext as q, type AgentDefinition as r, type AgentDelegation as s, type AiToolCtx as t, type PromptBuilder as u, type PromptContributor as v, type ToolTransientRetrySetting as w, type AgentIntake as x, type Decision as y, type ToolStepEnvelope as z };
@@ -323,6 +323,25 @@ interface AgentApprovalRequest {
323
323
  /** Why this call needs a person, in words for that person. */
324
324
  reason?: string;
325
325
  }
326
+ /**
327
+ * How an approval settled — the other half of {@link AgentApprovalRequest}, under the same `id`.
328
+ * Metadata again: the call's own outcome still arrives as `tool-output` (approved and ran),
329
+ * `tool-output-error` (approved and failed) or `tool-output-denied` (rejected or expired).
330
+ */
331
+ interface AgentApprovalSettlement {
332
+ id: string;
333
+ status: 'approved' | 'rejected' | 'expired';
334
+ /** Repeated from the request, for a call approved without one being streamed (a remembered approval). */
335
+ approver?: string;
336
+ /** Opaque ref of who decided. Absent on an expiry. */
337
+ decidedBy?: string;
338
+ /** The surface the decision came through: `'web'`, `'slack'`, `'remembered'`, … */
339
+ decidedVia?: string;
340
+ /** The approval also covers later calls of this tool in this thread. */
341
+ remember?: boolean;
342
+ /** What the person said when declining. */
343
+ reason?: string;
344
+ }
326
345
  type AgentStreamEvent = {
327
346
  kind: 'step-start';
328
347
  }
@@ -414,6 +433,14 @@ type AgentStreamEvent = {
414
433
  | ({
415
434
  kind: 'approval-requested';
416
435
  } & AgentApprovalRequest)
436
+ /**
437
+ * A parked action call was decided (or lapsed). Optional, like `approval-requested`: it adds WHO
438
+ * decided, THROUGH WHAT and whether the approval is REMEMBERED; the outcome itself rides the
439
+ * call's own output frame. See {@link AgentApprovalSettlement}.
440
+ */
441
+ | ({
442
+ kind: 'approval-settled';
443
+ } & AgentApprovalSettlement)
417
444
  /**
418
445
  * Server-pushed generative UI, positioned in the message where it arrives. Not tied to a tool
419
446
  * call. See {@link AgentUiComponent}.
@@ -738,6 +765,12 @@ interface ToolResult {
738
765
  * tool's outcome on; this flag is what everything else reads.
739
766
  */
740
767
  denied?: true;
768
+ /**
769
+ * The approval request lapsed before anyone decided, so the tool never ran. Always set together
770
+ * with {@link denied}: an expiry IS a refusal to every consumer that only knows that much, and this
771
+ * flag is for the ones that tell "nobody answered" from "someone said no".
772
+ */
773
+ expired?: true;
741
774
  id: string;
742
775
  name: string;
743
776
  output: unknown;
@@ -817,6 +850,22 @@ interface Decision {
817
850
  * (the chat flow).
818
851
  */
819
852
  executedByRef?: string;
853
+ /**
854
+ * Approve later calls of the SAME tool in the SAME thread without asking again. Read only on an
855
+ * approval; the loop answers it through {@link import('./spi/agent-store.js').AgentStore.rememberedApprovals}.
856
+ */
857
+ remember?: boolean;
858
+ /**
859
+ * The surface the decision came through — `'web'`, `'slack'`, `'console'`, anything the caller
860
+ * names. Provenance only: persisted with the call, never authorized against.
861
+ */
862
+ decidedVia?: string;
863
+ /**
864
+ * Nobody decided before the request lapsed. Set by the RUNNER when the approval wait times out
865
+ * (see `AgentLoopHooks.awaitApproval`'s `timeoutMs`), never by a person — the HTTP surface does not
866
+ * accept it. Read as a denial the model is told expired.
867
+ */
868
+ expired?: true;
820
869
  }
821
870
  type MessageRole = 'user' | 'assistant' | 'system';
822
871
  /**
@@ -1044,13 +1093,44 @@ interface StoredMessage {
1044
1093
  * props for each `id` — a reloaded thread replays them as `data-ui` parts.
1045
1094
  */
1046
1095
  ui?: AgentUiComponent[];
1096
+ /**
1097
+ * The approval record of every call on this message that was put to a person under an
1098
+ * {@link import('./spi/approval-policy.js').ApprovalPolicy} — who had to decide, until when, and how
1099
+ * it settled. Read off the tool-call rows by the store; absent when no call on the message asked
1100
+ * for one, or on a store that does not record approvals.
1101
+ */
1102
+ approvals?: ToolCallApproval[];
1047
1103
  createdAt: string;
1048
1104
  }
1105
+ /**
1106
+ * How one approval stands. `pending` → still parked; `approved` → someone said yes (or a remembered
1107
+ * approval did); `rejected` → someone said no; `expired` → nobody answered before `expiresAt`.
1108
+ */
1109
+ type ToolCallApprovalStatus = 'pending' | 'approved' | 'rejected' | 'expired';
1110
+ /** The persisted approval metadata of one action tool call. See {@link StoredMessage.approvals}. */
1111
+ interface ToolCallApproval {
1112
+ toolCallId: string;
1113
+ /** Who may decide: `'requester'` (the thread's own actor) or a role name. */
1114
+ approver: string;
1115
+ /** ISO-8601 instant the request lapses; absent → it never does. */
1116
+ expiresAt?: string;
1117
+ status: ToolCallApprovalStatus;
1118
+ /** The decision asked for later calls of this tool in this thread to be approved automatically. */
1119
+ remember?: boolean;
1120
+ /** Opaque ref of who decided. Absent while pending and on an expiry. */
1121
+ decidedBy?: string;
1122
+ /** The surface the decision came through (`'web'`, `'slack'`, `'remembered'`, …). */
1123
+ decidedVia?: string;
1124
+ /** What the person said when declining. */
1125
+ reason?: string;
1126
+ }
1049
1127
  interface ThreadDetail extends ThreadSummary {
1050
1128
  messages: StoredMessage[];
1051
1129
  activeStreamId?: string;
1052
1130
  }
1053
- type ToolCallStatus = 'auto_executed' | 'pending_approval' | 'executed' | 'rejected' | 'failed';
1131
+ type ToolCallStatus = 'auto_executed' | 'pending_approval' | 'executed' | 'rejected' | 'failed'
1132
+ /** An approval request lapsed before anyone decided; the tool never ran. */
1133
+ | 'expired';
1054
1134
  /**
1055
1135
  * Serializable input for a dispatched model-turn step. Carries only data — the serving worker
1056
1136
  * re-resolves the model/sink/registry from its own DI via AGENT_DEPS_FACTORY.forAgent(agentName).
@@ -1305,4 +1385,4 @@ interface ToolHandler<I = unknown> {
1305
1385
  canUse?(actor: Actor): boolean | Promise<boolean>;
1306
1386
  }
1307
1387
 
1308
- export { type HistoryPolicyContext as $, type Actor as A, type AgentApprovalRequest as B, type AgentCatalogEntry as C, type DetachedDelivery as D, type ElicitationRequest as E, type AgentHistoryWindow as F, type AgentStreamEvent as G, type HumanReply as H, type InputProcessor as I, type AskToolInput as J, DEFAULT_INCREMENTAL_LOOKBACK_CHARS as K, type LlmStepEnvelope as L, type ModelMessage as M, DEFAULT_INTAKE_PREAMBLE as N, type OutputProcessor as O, type ProcessorContext as P, type QuotaState as Q, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as R, type StoredMessage as S, type ToolHandler as T, type UsagePurpose as U, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as V, type ElicitationOption as W, type ElicitationOutcome as X, type ElicitationQuestion as Y, type ElicitationReply as Z, type ElicitationResult as _, type ToolDefinition as a, type HistorySelection as a0, type HistorySummary as a1, type IncrementalGating as a2, type InvokeWithTransientRetryOptions as a3, MAX_ASK_QUESTIONS as a4, type MessageRole as a5, OutputRejectedError as a6, type OutputVerdict as a7, ProcessorFailedError as a8, type PromptContext as a9, type QuotaView as aa, type ToolCatalogEntry as ab, type ToolConfirmation as ac, type ToolKind as ad, type ToolPresentation as ae, type ToolPresentationTone as af, type ToolResultField as ag, type ToolResultView as ah, type ToolStepCtx as ai, type ToolTransientRetryNumbers as aj, type ToolTransientRetryOptions as ak, askInputSchema as al, askToolDefinition as am, decodeStreamEvent as an, encodeStreamEvent as ao, invokeWithTransientRetry as ap, isTransientToolError as aq, normalizeElicitationReply as ar, renderElicitationAnswers as as, resolveElicitation as at, resolveToolTransientRetryNumbers as au, settleElicitation as av, type ToolCallRequest as b, type MessageUsage as c, type AgentUiComponent as d, type ThreadSummary as e, type ThreadDetail as f, type ToolResult as g, type MessageAttachment as h, type ToolCallStatus as i, type ToolSpec as j, type AgentRunInput as k, type HistoryPolicy as l, type ProcessedPrompt as m, type ModelAnswer as n, type PageContext as o, type AgentDefinition as p, type AgentDelegation as q, type AiToolCtx as r, type PromptBuilder as s, type PromptContributor as t, type ToolTransientRetrySetting as u, type AgentIntake as v, type Decision as w, type ToolStepEnvelope as x, ASK_TOOL_DESCRIPTION as y, ASK_TOOL_NAME as z };
1388
+ export { type ElicitationQuestion as $, type Actor as A, ASK_TOOL_DESCRIPTION as B, ASK_TOOL_NAME as C, type DetachedDelivery as D, type ElicitationRequest as E, type AgentApprovalRequest as F, type AgentApprovalSettlement as G, type HumanReply as H, type InputProcessor as I, type AgentCatalogEntry as J, type AgentHistoryWindow as K, type LlmStepEnvelope as L, type ModelMessage as M, type AgentStreamEvent as N, type OutputProcessor as O, type ProcessorContext as P, type QuotaState as Q, type AskToolInput as R, type StoredMessage as S, type ToolHandler as T, type UsagePurpose as U, DEFAULT_INCREMENTAL_LOOKBACK_CHARS as V, DEFAULT_INTAKE_PREAMBLE as W, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as X, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as Y, type ElicitationOption as Z, type ElicitationOutcome as _, type ToolDefinition as a, type ElicitationReply as a0, type ElicitationResult as a1, type HistoryPolicyContext as a2, type HistorySelection as a3, type HistorySummary as a4, type IncrementalGating as a5, type InvokeWithTransientRetryOptions as a6, MAX_ASK_QUESTIONS as a7, type MessageRole as a8, OutputRejectedError as a9, type OutputVerdict as aa, ProcessorFailedError as ab, type PromptContext as ac, type QuotaView as ad, type ToolCallApprovalStatus as ae, type ToolCatalogEntry as af, type ToolConfirmation as ag, type ToolPresentation as ah, type ToolPresentationTone as ai, type ToolResultField as aj, type ToolResultView as ak, type ToolStepCtx as al, type ToolTransientRetryNumbers as am, type ToolTransientRetryOptions as an, askInputSchema as ao, askToolDefinition as ap, decodeStreamEvent as aq, encodeStreamEvent as ar, invokeWithTransientRetry as as, isTransientToolError as at, normalizeElicitationReply as au, renderElicitationAnswers as av, resolveElicitation as aw, resolveToolTransientRetryNumbers as ax, settleElicitation as ay, type ToolCallRequest as b, type MessageUsage as c, type AgentUiComponent as d, type ThreadSummary as e, type ThreadDetail as f, type ToolResult as g, type MessageAttachment as h, type ToolCallStatus as i, type ToolSpec as j, type AgentRunInput as k, type ToolKind as l, type ToolCallApproval as m, type HistoryPolicy as n, type ProcessedPrompt as o, type ModelAnswer as p, type PageContext as q, type AgentDefinition as r, type AgentDelegation as s, type AiToolCtx as t, type PromptBuilder as u, type PromptContributor as v, type ToolTransientRetrySetting as w, type AgentIntake as x, type Decision as y, type ToolStepEnvelope as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-agent-core",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/DavideCarvalho/nestjs-agent.git",