@dudousxd/nestjs-agent-core 0.40.0 → 0.42.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.
Files changed (36) hide show
  1. package/README.md +7 -0
  2. package/dist/ag-ui/index.cjs +46 -10
  3. package/dist/ag-ui/index.cjs.map +1 -1
  4. package/dist/ag-ui/index.d.cts +9 -3
  5. package/dist/ag-ui/index.d.ts +9 -3
  6. package/dist/ag-ui/index.js +46 -10
  7. package/dist/ag-ui/index.js.map +1 -1
  8. package/dist/{catalog-CrzetM3_.d.cts → catalog-BKS3Yxo6.d.cts} +2 -0
  9. package/dist/{catalog-CrzetM3_.d.ts → catalog-BKS3Yxo6.d.ts} +2 -0
  10. package/dist/genui/builtins.cjs.map +1 -1
  11. package/dist/genui/builtins.d.cts +1 -1
  12. package/dist/genui/builtins.d.ts +1 -1
  13. package/dist/genui/builtins.js.map +1 -1
  14. package/dist/genui/index.cjs +660 -68
  15. package/dist/genui/index.cjs.map +1 -1
  16. package/dist/genui/index.d.cts +5 -5
  17. package/dist/genui/index.d.ts +5 -5
  18. package/dist/genui/index.js +654 -68
  19. package/dist/genui/index.js.map +1 -1
  20. package/dist/guardrails/index.cjs +3 -1
  21. package/dist/guardrails/index.cjs.map +1 -1
  22. package/dist/guardrails/index.d.cts +5 -4
  23. package/dist/guardrails/index.d.ts +5 -4
  24. package/dist/guardrails/index.js +3 -1
  25. package/dist/guardrails/index.js.map +1 -1
  26. package/dist/index.cjs +1164 -421
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +124 -13
  29. package/dist/index.d.ts +124 -13
  30. package/dist/index.js +1156 -421
  31. package/dist/index.js.map +1 -1
  32. package/dist/{processors-BR3nICcp.d.ts → processors-BKILjME5.d.ts} +1 -1
  33. package/dist/{processors-B7nfbU6E.d.cts → processors-DpHBqRuE.d.cts} +1 -1
  34. package/dist/{stream-events-M0jc7lSW.d.cts → stream-events-C-pj3bVY.d.cts} +92 -4
  35. package/dist/{stream-events-DAmes2Of.d.ts → stream-events-D92SgfRk.d.ts} +92 -4
  36. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { M as ModelMessage, a as Actor, e as ToolCallRequest } from './stream-events-DAmes2Of.js';
1
+ import { M as ModelMessage, a as Actor, r as ToolCallRequest } from './stream-events-D92SgfRk.js';
2
2
 
3
3
  /**
4
4
  * The two seams that see a turn's traffic to and from the model: an {@link InputProcessor} rewrites
@@ -1,4 +1,4 @@
1
- import { M as ModelMessage, a as Actor, e as ToolCallRequest } from './stream-events-M0jc7lSW.cjs';
1
+ import { M as ModelMessage, a as Actor, r as ToolCallRequest } from './stream-events-C-pj3bVY.cjs';
2
2
 
3
3
  /**
4
4
  * The two seams that see a turn's traffic to and from the model: an {@link InputProcessor} rewrites
@@ -1,5 +1,5 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { a as Catalog } from './catalog-CrzetM3_.cjs';
2
+ import { a as Catalog, C as ComponentDefinition, J as JsonSchema, d as CatalogOptions } from './catalog-BKS3Yxo6.cjs';
3
3
 
4
4
  /**
5
5
  * Typed answers for a question set: a question that asks for a number, a date, an email or a
@@ -531,6 +531,11 @@ interface CreateThreadInput {
531
531
  id?: string;
532
532
  /** The persona the thread's turns run under when a send names none. See {@link ThreadSummary.persona}. */
533
533
  persona?: string;
534
+ /**
535
+ * The agent the send that creates the thread names (already resolved: an explicit pick, else the
536
+ * default). A store that keeps an agent per thread starts it there; others ignore it.
537
+ */
538
+ agentName?: string;
534
539
  }
535
540
  interface AppendMessageInput {
536
541
  actionProposalOutcome?: ActionProposalOutcome;
@@ -919,6 +924,8 @@ interface QueuedMessage {
919
924
  model?: string;
920
925
  pageContext?: PageContext;
921
926
  uiCapabilities?: UiCapabilities;
927
+ /** The send's {@link AgentRunInput.hostContext}, carried to the turn it starts. Never on the wire view. */
928
+ hostContext?: AgentHostContext;
922
929
  /**
923
930
  * Queued by an interrupt (`POST chat { mode: 'interrupt' }`): the running turn was cancelled to
924
931
  * make room for it, so the cancel starts it instead of pausing the queue.
@@ -958,6 +965,7 @@ interface EnqueueMessageInput {
958
965
  model?: string;
959
966
  pageContext?: PageContext;
960
967
  uiCapabilities?: UiCapabilities;
968
+ hostContext?: AgentHostContext;
961
969
  interrupt?: boolean;
962
970
  /** `'tail'` (default) runs it after everything already waiting; `'head'` runs it next. */
963
971
  at?: 'tail' | 'head';
@@ -1122,12 +1130,78 @@ interface AgentHistoryWindow {
1122
1130
  summarize?: boolean;
1123
1131
  }
1124
1132
 
1133
+ /** Plain, durable data. Renderer functions and binary attachments never enter a UI frame. */
1134
+ interface ComponentPresentation<P = Record<string, unknown>> {
1135
+ component: string;
1136
+ props: P;
1137
+ version: number;
1138
+ fallbackText: string;
1139
+ }
1140
+ interface ComponentFactory<Input, Output = Input> {
1141
+ (props: Input): Promise<ComponentPresentation<Output>>;
1142
+ readonly definition: ComponentDefinition<Output>;
1143
+ }
1144
+ /** Reject values JSON would silently discard/coerce, and detach from caller-owned objects. */
1145
+ declare function snapshotComponentPresentation<T>(value: T): T;
1146
+ declare function createComponent<S extends StandardSchemaV1>(definition: Omit<ComponentDefinition<StandardSchemaV1.InferOutput<S>>, 'props'> & {
1147
+ props: S;
1148
+ }, options?: CatalogOptions): ComponentFactory<StandardSchemaV1.InferInput<S>, StandardSchemaV1.InferOutput<S>>;
1149
+ declare function createComponent<P = Record<string, unknown>>(definition: ComponentDefinition<P>, options?: CatalogOptions): ComponentFactory<P>;
1150
+ type ComponentRenderer<P = Record<string, unknown>, Context = unknown> = (props: P, context?: Context) => unknown | Promise<unknown>;
1151
+ interface ComponentManifest {
1152
+ name: string;
1153
+ title: string;
1154
+ description: string;
1155
+ version: number;
1156
+ props?: JsonSchema;
1157
+ }
1158
+ interface ComponentRegistry<Context = unknown> {
1159
+ readonly catalog: Catalog;
1160
+ readonly manifest: readonly ComponentManifest[];
1161
+ register<P>(definition: ComponentDefinition<P>, renderers: Record<string, ComponentRenderer<P, Context>>): this;
1162
+ /** Revalidate against the app's authoritative definition and regenerate trusted fallback text. */
1163
+ prepare(presentation: ComponentPresentation): Promise<ComponentPresentation>;
1164
+ render(presentation: ComponentPresentation, channel: string, context?: Context): Promise<unknown>;
1165
+ }
1166
+ /** A registry is owned by one app/tenant; registering never mutates a shared singleton. */
1167
+ declare function createComponentRegistry<Context = unknown>(options?: CatalogOptions): ComponentRegistry<Context>;
1168
+ type TableCell = string | number | boolean | null;
1169
+ interface TableProps {
1170
+ title?: string;
1171
+ columns: {
1172
+ key: string;
1173
+ label: string;
1174
+ align?: 'left' | 'right' | 'center';
1175
+ format?: 'text' | 'number' | 'currency' | 'percent' | 'date' | 'link';
1176
+ }[];
1177
+ rows: Record<string, TableCell>[];
1178
+ }
1179
+ interface ChartProps {
1180
+ type: 'bar' | 'line';
1181
+ title?: string;
1182
+ xKey: string;
1183
+ series: {
1184
+ key: string;
1185
+ label?: string;
1186
+ }[];
1187
+ data: Record<string, TableCell>[];
1188
+ unit?: string;
1189
+ }
1190
+ declare const table: ComponentFactory<TableProps, TableProps>;
1191
+ declare const chart: ComponentFactory<ChartProps, ChartProps>;
1192
+ /** Prepare all JSON emissions before any sink receives a partial batch. Factories validate schemas. */
1193
+ declare function validatePresentationBatch(presentations: ComponentPresentation<object> | readonly ComponentPresentation<object>[]): ComponentPresentation[];
1194
+
1125
1195
  /**
1126
1196
  * Per-invocation context handed to a tool handler. Host-supplied bits are optional. Identity lives
1127
1197
  * on {@link AiToolCtx.actor} — read `ctx.actor.id` / `ctx.actor.tenantRef` (single source of truth;
1128
1198
  * no denormalized copies).
1129
1199
  */
1130
1200
  interface AiToolCtx {
1201
+ /** Reports presentation failures separately from successful domain execution. */
1202
+ onPresentationError?(error: unknown, details: {
1203
+ toolName: string;
1204
+ }): void | Promise<void>;
1131
1205
  uiCapabilities?: UiCapabilities;
1132
1206
  actor: Actor;
1133
1207
  threadId: string;
@@ -1198,6 +1272,8 @@ type ToolPreflightResult<O = unknown> = {
1198
1272
  /** A tool implementation. `I` is the input parsed by its registered Standard Schema. */
1199
1273
  interface ToolHandler<I = unknown, O = unknown> {
1200
1274
  execute(input: I, ctx: AiToolCtx): Promise<O>;
1275
+ /** Optional UI derived from successful domain output; errors never fail the domain action. */
1276
+ present?(output: O, ctx: AiToolCtx): ComponentPresentation<object> | readonly ComponentPresentation<object>[] | undefined | Promise<ComponentPresentation<object> | readonly ComponentPresentation<object>[] | undefined>;
1201
1277
  /** Read-only action check. Runs after authorization and validation, before approval and again
1202
1278
  * immediately before execution. Confirmation strings are resolved, never templates. */
1203
1279
  preflight?(input: I, ctx: AiToolCtx, options: ToolPreflightOptions): ToolPreflightResult<O> | Promise<ToolPreflightResult<O>>;
@@ -1437,8 +1513,9 @@ interface ToolSpec {
1437
1513
  enabled?: boolean | (() => boolean | Promise<boolean>);
1438
1514
  /**
1439
1515
  * An authorization ability name (e.g. 'cache.purge'). Consumed by an ability-aware RolesPolicy
1440
- * such as the `@dudousxd/nestjs-agent-authz` Gate adapter. Apps that don't use authz ignore it
1441
- * and rely on `roles` instead — both live on the same SPI, so neither is required.
1516
+ * such as the `@dudousxd/nestjs-agent-authz` Gate adapter. A policy that can't evaluate one (the
1517
+ * role-based default) refuses a tool that names an `ability` and no `roles` — fail closed rather
1518
+ * than open; a tool naming both falls back to its `roles` there.
1442
1519
  */
1443
1520
  ability?: string;
1444
1521
  }
@@ -1713,6 +1790,10 @@ type PromptBuilder = (ctx: PromptContext) => string | Promise<string>;
1713
1790
  */
1714
1791
  type PromptContributor = (ctx: PromptContext) => string | null | Promise<string | null>;
1715
1792
  /** Everything needed to run one agent turn. */
1793
+ /** See {@link AgentRunInput.hostContext}. JSON only. */
1794
+ type AgentHostContext = {
1795
+ readonly [key: string]: unknown;
1796
+ };
1716
1797
  interface AgentRunInput {
1717
1798
  threadId: string;
1718
1799
  actor: Actor;
@@ -1779,6 +1860,13 @@ interface AgentRunInput {
1779
1860
  * label when the provider reports none. Omitted → the provider's default.
1780
1861
  */
1781
1862
  model?: string;
1863
+ /**
1864
+ * What the HOST knows about this turn that the library does not model — where it came from, where
1865
+ * its answer goes, on whose behalf (e.g. `{ source: 'slack', delivery: { channel, ts } }`). Plain
1866
+ * JSON: it travels through the queue and the durable journal untouched, and reaches the runner's
1867
+ * hooks (an engine's host callbacks) as it was sent. Never shown to the model or to clients.
1868
+ */
1869
+ hostContext?: AgentHostContext;
1782
1870
  }
1783
1871
  /**
1784
1872
  * A named agent: its prompt, the tools it may use, and who it can hand off to. This is the
@@ -2575,4 +2663,4 @@ type AgentStreamErrorCode = 'quota_exceeded' | 'output_rejected' | 'structured_o
2575
2663
  /** A model call ended without producing anything. */
2576
2664
  | 'model_no_output' | 'run_failed';
2577
2665
 
2578
- export { type ToolCallStatus as $, type AgentStreamEvent as A, type ToolTransientRetrySetting as B, type AgentIntake as C, type DetachedDelivery as D, type Decision as E, type ElicitationRequest as F, type ToolStepEnvelope as G, type HumanReply as H, type ClaimActionProposal as I, type ActionProposal as J, type ActionProposalStore as K, type LlmStepEnvelope as L, type ModelMessage as M, type ActionProposalStoreOptions as N, type CreateActionProposal as O, type PreparedUiEmission as P, type QuotaState as Q, type CreateActionProposalResult as R, type ActionProposalScope as S, type ToolSpec as T, type UiCapabilities as U, type ListActionProposals as V, type ActionProposalDecisionCommand as W, type ExtendActionProposalLease as X, type SettleActionProposal as Y, type ActionProposalOutcome as Z, type ActionProposalOutcomeLease as _, type Actor as a, type MessageFeedbackValue as a$, type ChatQueueStore as a0, type ActionProposalOutcomeStore as a1, type CreateThreadInput as a2, type ThreadSummary as a3, type ThreadDetail as a4, type ToolCallApprovalState as a5, type UpdateThreadInput as a6, type RecordRunStartInput as a7, type EnqueueMessageInput as a8, type QueuedMessage as a9, type AgentHistoryWindow as aA, type AgentStreamErrorCode as aB, type ApprovalDecisionRef as aC, type ApprovalRequirement as aD, type ApprovalThreadRef as aE, type ApprovalToolRef as aF, type AskToolInput as aG, type ChatQueueState as aH, type ClaimedActionApproval as aI, DEFAULT_INTAKE_PREAMBLE as aJ, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as aK, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as aL, DefaultApprovalPolicy as aM, ELICITATION_INPUT_TYPES as aN, type ElicitationInput as aO, type ElicitationInputType as aP, type ElicitationOption as aQ, type ElicitationOutcome as aR, type ElicitationQuestion as aS, type ElicitationReply as aT, type ElicitationResult as aU, type EmitUiOptions as aV, type HistoryPolicyContext as aW, type HistorySelection as aX, type HistorySummary as aY, type InvokeWithTransientRetryOptions as aZ, MAX_ASK_QUESTIONS as a_, type QueuedMessagePatch as aa, type QueuePause as ab, type AppendMessageInput as ac, type StoredMessage as ad, type ToolResult as ae, type MessageFeedback as af, type RecordToolCallInput as ag, type ToolCallOutcome as ah, type UpdateToolCallInput as ai, type RecordUsageInput as aj, type ToolConfirmation as ak, type ActionProposalDecision as al, type ActionProposalSupersessionStore as am, ALL_AGENTS as an, ASK_TOOL_DESCRIPTION as ao, ASK_TOOL_NAME as ap, type ActionProposalDecisionAudit as aq, type ActionProposalExecution as ar, type ActionProposalExecutionContext as as, type ActionProposalLease as at, type ActionProposalOutcomeDelivery as au, type AgentApprovalRequest as av, type AgentApprovalSettlement as aw, type AgentAttachmentConfig as ax, type AgentCatalogEntry as ay, type AgentClientConfig as az, type ToolHandler as b, type MessageRole as b0, type PersonaRef as b1, type PromptContext as b2, type QueuePauseReason as b3, type QueuedMessageView as b4, type QuotaView as b5, REQUESTER_APPROVER as b6, RUN_ENDED_BEFORE_TOOL_CALL as b7, type RecordRunEndInput as b8, type ResolveActionProposalApprovalInput as b9, isChatQueueStore as bA, isTransientToolError as bB, isTypedQuestion as bC, mayDecideApproval as bD, normalizeElicitationReply as bE, questionOptions as bF, queuedMessageView as bG, readElicitationInput as bH, readElicitationQuestions as bI, releaseThreadRun as bJ, renderElicitationAnswers as bK, resolveActionProposalApproval as bL, resolveElicitation as bM, resolveToolTransientRetryNumbers as bN, settleDanglingToolCalls as bO, settleElicitation as bP, toolCallApprovalFromRow as bQ, validateElicitationAnswer as bR, validateElicitationValue as bS, type ThreadTurnPage as ba, type ThreadTurnQuery as bb, type ThreadTurnReader as bc, type ToolCallApproval as bd, type ToolCallApprovalColumns as be, type ToolCallApprovalStatus as bf, type ToolCatalogEntry as bg, type ToolDescription as bh, type ToolKind as bi, type ToolPreflightOptions as bj, type ToolPresentationTone as bk, type ToolResultField as bl, type ToolResultView as bm, type ToolStepCtx as bn, type ToolTransientRetryNumbers as bo, type ToolTransientRetryOptions as bp, type TurnPersona as bq, UNFINISHED_TOOL_CALL as br, type UsagePurpose as bs, askInputSchema as bt, askToolDefinition as bu, danglingToolCallIds as bv, decodeStreamEvent as bw, defaultCanDecide as bx, encodeStreamEvent as by, invokeWithTransientRetry as bz, type ToolPresentation as c, type ToolDefinition as d, type ToolCallRequest as e, type MessageUsage as f, type AgentUiComponent as g, type AiToolCtx as h, type AgentRunInput as i, type MessageAttachment as j, type ActionProposalMutationResult as k, type AgentDefinition as l, type Persona as m, negotiateCatalog as n, type PersonaCatalogEntry as o, prepareUiEmission as p, type HistoryPolicy as q, type PageContext as r, type AgentStore as s, type AgentDelegation as t, type ToolDescribeScope as u, validateUiCapabilities as v, type ToolPreflightResult as w, type ApprovalPolicy as x, type PromptBuilder as y, type PromptContributor as z };
2666
+ export { type Decision as $, type AgentStreamEvent as A, type ActionProposalMutationResult as B, type ChartProps as C, type ActionProposal as D, type ActionProposalExecution as E, type ActionProposalOutcomeDelivery as F, type AgentDefinition as G, type HumanReply as H, type Persona as I, type PersonaCatalogEntry as J, type HistoryPolicy as K, type PageContext as L, type ModelMessage as M, type AgentStore as N, type AgentDelegation as O, type PreparedUiEmission as P, type QuotaState as Q, type DetachedDelivery as R, type ToolDescribeScope as S, type ToolSpec as T, type UiCapabilities as U, type ToolPreflightResult as V, type ApprovalPolicy as W, type PromptBuilder as X, type PromptContributor as Y, type ToolTransientRetrySetting as Z, type AgentIntake as _, type Actor as a, DefaultApprovalPolicy as a$, type ElicitationRequest as a0, type LlmStepEnvelope as a1, type ToolStepEnvelope as a2, type ClaimActionProposal as a3, type ActionProposalStore as a4, type ActionProposalStoreOptions as a5, type CreateActionProposal as a6, type CreateActionProposalResult as a7, type ActionProposalScope as a8, type ListActionProposals as a9, type ToolConfirmation as aA, type ActionProposalDecision as aB, type ActionProposalSupersessionStore as aC, ALL_AGENTS as aD, ASK_TOOL_DESCRIPTION as aE, ASK_TOOL_NAME as aF, type ActionProposalDecisionAudit as aG, type ActionProposalExecutionContext as aH, type ActionProposalLease as aI, type AgentApprovalRequest as aJ, type AgentApprovalSettlement as aK, type AgentAttachmentConfig as aL, type AgentCatalogEntry as aM, type AgentClientConfig as aN, type AgentHistoryWindow as aO, type AgentHostContext as aP, type AgentStreamErrorCode as aQ, type ApprovalDecisionRef as aR, type ApprovalRequirement as aS, type ApprovalThreadRef as aT, type ApprovalToolRef as aU, type AskToolInput as aV, type ChatQueueState as aW, type ClaimedActionApproval as aX, DEFAULT_INTAKE_PREAMBLE as aY, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as aZ, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as a_, type ActionProposalDecisionCommand as aa, type ExtendActionProposalLease as ab, type SettleActionProposal as ac, type ActionProposalOutcome as ad, type ActionProposalOutcomeLease as ae, type ToolCallStatus as af, type ChatQueueStore as ag, type ActionProposalOutcomeStore as ah, type CreateThreadInput as ai, type ThreadSummary as aj, type ThreadDetail as ak, type ToolCallApprovalState as al, type UpdateThreadInput as am, type RecordRunStartInput as an, type EnqueueMessageInput as ao, type QueuedMessage as ap, type QueuedMessagePatch as aq, type QueuePause as ar, type AppendMessageInput as as, type StoredMessage as at, type ToolResult as au, type MessageFeedback as av, type RecordToolCallInput as aw, type ToolCallOutcome as ax, type UpdateToolCallInput as ay, type RecordUsageInput as az, type ToolHandler as b, resolveElicitation as b$, ELICITATION_INPUT_TYPES as b0, type ElicitationInput as b1, type ElicitationInputType as b2, type ElicitationOption as b3, type ElicitationOutcome as b4, type ElicitationQuestion as b5, type ElicitationReply as b6, type ElicitationResult as b7, type EmitUiOptions as b8, type HistoryPolicyContext as b9, type ToolResultField as bA, type ToolResultView as bB, type ToolStepCtx as bC, type ToolTransientRetryNumbers as bD, type ToolTransientRetryOptions as bE, type TurnPersona as bF, UNFINISHED_TOOL_CALL as bG, type UsagePurpose as bH, askInputSchema as bI, askToolDefinition as bJ, danglingToolCallIds as bK, decodeStreamEvent as bL, defaultCanDecide as bM, encodeStreamEvent as bN, invokeWithTransientRetry as bO, isChatQueueStore as bP, isTransientToolError as bQ, isTypedQuestion as bR, mayDecideApproval as bS, normalizeElicitationReply as bT, questionOptions as bU, queuedMessageView as bV, readElicitationInput as bW, readElicitationQuestions as bX, releaseThreadRun as bY, renderElicitationAnswers as bZ, resolveActionProposalApproval as b_, type HistorySelection as ba, type HistorySummary as bb, type InvokeWithTransientRetryOptions as bc, MAX_ASK_QUESTIONS as bd, type MessageFeedbackValue as be, type MessageRole as bf, type PersonaRef as bg, type PromptContext as bh, type QueuePauseReason as bi, type QueuedMessageView as bj, type QuotaView as bk, REQUESTER_APPROVER as bl, RUN_ENDED_BEFORE_TOOL_CALL as bm, type RecordRunEndInput as bn, type ResolveActionProposalApprovalInput as bo, type ThreadTurnPage as bp, type ThreadTurnQuery as bq, type ThreadTurnReader as br, type ToolCallApproval as bs, type ToolCallApprovalColumns as bt, type ToolCallApprovalStatus as bu, type ToolCatalogEntry as bv, type ToolDescription as bw, type ToolKind as bx, type ToolPreflightOptions as by, type ToolPresentationTone as bz, type ToolPresentation as c, resolveToolTransientRetryNumbers as c0, settleDanglingToolCalls as c1, settleElicitation as c2, toolCallApprovalFromRow as c3, validateElicitationAnswer as c4, validateElicitationValue as c5, type ComponentFactory as d, type ComponentManifest as e, type ComponentPresentation as f, type ComponentRegistry as g, type ComponentRenderer as h, type TableCell as i, type TableProps as j, chart as k, createComponent as l, createComponentRegistry as m, negotiateCatalog as n, validateUiCapabilities as o, prepareUiEmission as p, type ToolDefinition as q, type ToolCallRequest as r, snapshotComponentPresentation as s, table as t, type MessageUsage as u, validatePresentationBatch as v, type AgentUiComponent as w, type AiToolCtx as x, type AgentRunInput as y, type MessageAttachment as z };
@@ -1,5 +1,5 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { a as Catalog } from './catalog-CrzetM3_.js';
2
+ import { a as Catalog, C as ComponentDefinition, J as JsonSchema, d as CatalogOptions } from './catalog-BKS3Yxo6.js';
3
3
 
4
4
  /**
5
5
  * Typed answers for a question set: a question that asks for a number, a date, an email or a
@@ -531,6 +531,11 @@ interface CreateThreadInput {
531
531
  id?: string;
532
532
  /** The persona the thread's turns run under when a send names none. See {@link ThreadSummary.persona}. */
533
533
  persona?: string;
534
+ /**
535
+ * The agent the send that creates the thread names (already resolved: an explicit pick, else the
536
+ * default). A store that keeps an agent per thread starts it there; others ignore it.
537
+ */
538
+ agentName?: string;
534
539
  }
535
540
  interface AppendMessageInput {
536
541
  actionProposalOutcome?: ActionProposalOutcome;
@@ -919,6 +924,8 @@ interface QueuedMessage {
919
924
  model?: string;
920
925
  pageContext?: PageContext;
921
926
  uiCapabilities?: UiCapabilities;
927
+ /** The send's {@link AgentRunInput.hostContext}, carried to the turn it starts. Never on the wire view. */
928
+ hostContext?: AgentHostContext;
922
929
  /**
923
930
  * Queued by an interrupt (`POST chat { mode: 'interrupt' }`): the running turn was cancelled to
924
931
  * make room for it, so the cancel starts it instead of pausing the queue.
@@ -958,6 +965,7 @@ interface EnqueueMessageInput {
958
965
  model?: string;
959
966
  pageContext?: PageContext;
960
967
  uiCapabilities?: UiCapabilities;
968
+ hostContext?: AgentHostContext;
961
969
  interrupt?: boolean;
962
970
  /** `'tail'` (default) runs it after everything already waiting; `'head'` runs it next. */
963
971
  at?: 'tail' | 'head';
@@ -1122,12 +1130,78 @@ interface AgentHistoryWindow {
1122
1130
  summarize?: boolean;
1123
1131
  }
1124
1132
 
1133
+ /** Plain, durable data. Renderer functions and binary attachments never enter a UI frame. */
1134
+ interface ComponentPresentation<P = Record<string, unknown>> {
1135
+ component: string;
1136
+ props: P;
1137
+ version: number;
1138
+ fallbackText: string;
1139
+ }
1140
+ interface ComponentFactory<Input, Output = Input> {
1141
+ (props: Input): Promise<ComponentPresentation<Output>>;
1142
+ readonly definition: ComponentDefinition<Output>;
1143
+ }
1144
+ /** Reject values JSON would silently discard/coerce, and detach from caller-owned objects. */
1145
+ declare function snapshotComponentPresentation<T>(value: T): T;
1146
+ declare function createComponent<S extends StandardSchemaV1>(definition: Omit<ComponentDefinition<StandardSchemaV1.InferOutput<S>>, 'props'> & {
1147
+ props: S;
1148
+ }, options?: CatalogOptions): ComponentFactory<StandardSchemaV1.InferInput<S>, StandardSchemaV1.InferOutput<S>>;
1149
+ declare function createComponent<P = Record<string, unknown>>(definition: ComponentDefinition<P>, options?: CatalogOptions): ComponentFactory<P>;
1150
+ type ComponentRenderer<P = Record<string, unknown>, Context = unknown> = (props: P, context?: Context) => unknown | Promise<unknown>;
1151
+ interface ComponentManifest {
1152
+ name: string;
1153
+ title: string;
1154
+ description: string;
1155
+ version: number;
1156
+ props?: JsonSchema;
1157
+ }
1158
+ interface ComponentRegistry<Context = unknown> {
1159
+ readonly catalog: Catalog;
1160
+ readonly manifest: readonly ComponentManifest[];
1161
+ register<P>(definition: ComponentDefinition<P>, renderers: Record<string, ComponentRenderer<P, Context>>): this;
1162
+ /** Revalidate against the app's authoritative definition and regenerate trusted fallback text. */
1163
+ prepare(presentation: ComponentPresentation): Promise<ComponentPresentation>;
1164
+ render(presentation: ComponentPresentation, channel: string, context?: Context): Promise<unknown>;
1165
+ }
1166
+ /** A registry is owned by one app/tenant; registering never mutates a shared singleton. */
1167
+ declare function createComponentRegistry<Context = unknown>(options?: CatalogOptions): ComponentRegistry<Context>;
1168
+ type TableCell = string | number | boolean | null;
1169
+ interface TableProps {
1170
+ title?: string;
1171
+ columns: {
1172
+ key: string;
1173
+ label: string;
1174
+ align?: 'left' | 'right' | 'center';
1175
+ format?: 'text' | 'number' | 'currency' | 'percent' | 'date' | 'link';
1176
+ }[];
1177
+ rows: Record<string, TableCell>[];
1178
+ }
1179
+ interface ChartProps {
1180
+ type: 'bar' | 'line';
1181
+ title?: string;
1182
+ xKey: string;
1183
+ series: {
1184
+ key: string;
1185
+ label?: string;
1186
+ }[];
1187
+ data: Record<string, TableCell>[];
1188
+ unit?: string;
1189
+ }
1190
+ declare const table: ComponentFactory<TableProps, TableProps>;
1191
+ declare const chart: ComponentFactory<ChartProps, ChartProps>;
1192
+ /** Prepare all JSON emissions before any sink receives a partial batch. Factories validate schemas. */
1193
+ declare function validatePresentationBatch(presentations: ComponentPresentation<object> | readonly ComponentPresentation<object>[]): ComponentPresentation[];
1194
+
1125
1195
  /**
1126
1196
  * Per-invocation context handed to a tool handler. Host-supplied bits are optional. Identity lives
1127
1197
  * on {@link AiToolCtx.actor} — read `ctx.actor.id` / `ctx.actor.tenantRef` (single source of truth;
1128
1198
  * no denormalized copies).
1129
1199
  */
1130
1200
  interface AiToolCtx {
1201
+ /** Reports presentation failures separately from successful domain execution. */
1202
+ onPresentationError?(error: unknown, details: {
1203
+ toolName: string;
1204
+ }): void | Promise<void>;
1131
1205
  uiCapabilities?: UiCapabilities;
1132
1206
  actor: Actor;
1133
1207
  threadId: string;
@@ -1198,6 +1272,8 @@ type ToolPreflightResult<O = unknown> = {
1198
1272
  /** A tool implementation. `I` is the input parsed by its registered Standard Schema. */
1199
1273
  interface ToolHandler<I = unknown, O = unknown> {
1200
1274
  execute(input: I, ctx: AiToolCtx): Promise<O>;
1275
+ /** Optional UI derived from successful domain output; errors never fail the domain action. */
1276
+ present?(output: O, ctx: AiToolCtx): ComponentPresentation<object> | readonly ComponentPresentation<object>[] | undefined | Promise<ComponentPresentation<object> | readonly ComponentPresentation<object>[] | undefined>;
1201
1277
  /** Read-only action check. Runs after authorization and validation, before approval and again
1202
1278
  * immediately before execution. Confirmation strings are resolved, never templates. */
1203
1279
  preflight?(input: I, ctx: AiToolCtx, options: ToolPreflightOptions): ToolPreflightResult<O> | Promise<ToolPreflightResult<O>>;
@@ -1437,8 +1513,9 @@ interface ToolSpec {
1437
1513
  enabled?: boolean | (() => boolean | Promise<boolean>);
1438
1514
  /**
1439
1515
  * An authorization ability name (e.g. 'cache.purge'). Consumed by an ability-aware RolesPolicy
1440
- * such as the `@dudousxd/nestjs-agent-authz` Gate adapter. Apps that don't use authz ignore it
1441
- * and rely on `roles` instead — both live on the same SPI, so neither is required.
1516
+ * such as the `@dudousxd/nestjs-agent-authz` Gate adapter. A policy that can't evaluate one (the
1517
+ * role-based default) refuses a tool that names an `ability` and no `roles` — fail closed rather
1518
+ * than open; a tool naming both falls back to its `roles` there.
1442
1519
  */
1443
1520
  ability?: string;
1444
1521
  }
@@ -1713,6 +1790,10 @@ type PromptBuilder = (ctx: PromptContext) => string | Promise<string>;
1713
1790
  */
1714
1791
  type PromptContributor = (ctx: PromptContext) => string | null | Promise<string | null>;
1715
1792
  /** Everything needed to run one agent turn. */
1793
+ /** See {@link AgentRunInput.hostContext}. JSON only. */
1794
+ type AgentHostContext = {
1795
+ readonly [key: string]: unknown;
1796
+ };
1716
1797
  interface AgentRunInput {
1717
1798
  threadId: string;
1718
1799
  actor: Actor;
@@ -1779,6 +1860,13 @@ interface AgentRunInput {
1779
1860
  * label when the provider reports none. Omitted → the provider's default.
1780
1861
  */
1781
1862
  model?: string;
1863
+ /**
1864
+ * What the HOST knows about this turn that the library does not model — where it came from, where
1865
+ * its answer goes, on whose behalf (e.g. `{ source: 'slack', delivery: { channel, ts } }`). Plain
1866
+ * JSON: it travels through the queue and the durable journal untouched, and reaches the runner's
1867
+ * hooks (an engine's host callbacks) as it was sent. Never shown to the model or to clients.
1868
+ */
1869
+ hostContext?: AgentHostContext;
1782
1870
  }
1783
1871
  /**
1784
1872
  * A named agent: its prompt, the tools it may use, and who it can hand off to. This is the
@@ -2575,4 +2663,4 @@ type AgentStreamErrorCode = 'quota_exceeded' | 'output_rejected' | 'structured_o
2575
2663
  /** A model call ended without producing anything. */
2576
2664
  | 'model_no_output' | 'run_failed';
2577
2665
 
2578
- export { type ToolCallStatus as $, type AgentStreamEvent as A, type ToolTransientRetrySetting as B, type AgentIntake as C, type DetachedDelivery as D, type Decision as E, type ElicitationRequest as F, type ToolStepEnvelope as G, type HumanReply as H, type ClaimActionProposal as I, type ActionProposal as J, type ActionProposalStore as K, type LlmStepEnvelope as L, type ModelMessage as M, type ActionProposalStoreOptions as N, type CreateActionProposal as O, type PreparedUiEmission as P, type QuotaState as Q, type CreateActionProposalResult as R, type ActionProposalScope as S, type ToolSpec as T, type UiCapabilities as U, type ListActionProposals as V, type ActionProposalDecisionCommand as W, type ExtendActionProposalLease as X, type SettleActionProposal as Y, type ActionProposalOutcome as Z, type ActionProposalOutcomeLease as _, type Actor as a, type MessageFeedbackValue as a$, type ChatQueueStore as a0, type ActionProposalOutcomeStore as a1, type CreateThreadInput as a2, type ThreadSummary as a3, type ThreadDetail as a4, type ToolCallApprovalState as a5, type UpdateThreadInput as a6, type RecordRunStartInput as a7, type EnqueueMessageInput as a8, type QueuedMessage as a9, type AgentHistoryWindow as aA, type AgentStreamErrorCode as aB, type ApprovalDecisionRef as aC, type ApprovalRequirement as aD, type ApprovalThreadRef as aE, type ApprovalToolRef as aF, type AskToolInput as aG, type ChatQueueState as aH, type ClaimedActionApproval as aI, DEFAULT_INTAKE_PREAMBLE as aJ, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as aK, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as aL, DefaultApprovalPolicy as aM, ELICITATION_INPUT_TYPES as aN, type ElicitationInput as aO, type ElicitationInputType as aP, type ElicitationOption as aQ, type ElicitationOutcome as aR, type ElicitationQuestion as aS, type ElicitationReply as aT, type ElicitationResult as aU, type EmitUiOptions as aV, type HistoryPolicyContext as aW, type HistorySelection as aX, type HistorySummary as aY, type InvokeWithTransientRetryOptions as aZ, MAX_ASK_QUESTIONS as a_, type QueuedMessagePatch as aa, type QueuePause as ab, type AppendMessageInput as ac, type StoredMessage as ad, type ToolResult as ae, type MessageFeedback as af, type RecordToolCallInput as ag, type ToolCallOutcome as ah, type UpdateToolCallInput as ai, type RecordUsageInput as aj, type ToolConfirmation as ak, type ActionProposalDecision as al, type ActionProposalSupersessionStore as am, ALL_AGENTS as an, ASK_TOOL_DESCRIPTION as ao, ASK_TOOL_NAME as ap, type ActionProposalDecisionAudit as aq, type ActionProposalExecution as ar, type ActionProposalExecutionContext as as, type ActionProposalLease as at, type ActionProposalOutcomeDelivery as au, type AgentApprovalRequest as av, type AgentApprovalSettlement as aw, type AgentAttachmentConfig as ax, type AgentCatalogEntry as ay, type AgentClientConfig as az, type ToolHandler as b, type MessageRole as b0, type PersonaRef as b1, type PromptContext as b2, type QueuePauseReason as b3, type QueuedMessageView as b4, type QuotaView as b5, REQUESTER_APPROVER as b6, RUN_ENDED_BEFORE_TOOL_CALL as b7, type RecordRunEndInput as b8, type ResolveActionProposalApprovalInput as b9, isChatQueueStore as bA, isTransientToolError as bB, isTypedQuestion as bC, mayDecideApproval as bD, normalizeElicitationReply as bE, questionOptions as bF, queuedMessageView as bG, readElicitationInput as bH, readElicitationQuestions as bI, releaseThreadRun as bJ, renderElicitationAnswers as bK, resolveActionProposalApproval as bL, resolveElicitation as bM, resolveToolTransientRetryNumbers as bN, settleDanglingToolCalls as bO, settleElicitation as bP, toolCallApprovalFromRow as bQ, validateElicitationAnswer as bR, validateElicitationValue as bS, type ThreadTurnPage as ba, type ThreadTurnQuery as bb, type ThreadTurnReader as bc, type ToolCallApproval as bd, type ToolCallApprovalColumns as be, type ToolCallApprovalStatus as bf, type ToolCatalogEntry as bg, type ToolDescription as bh, type ToolKind as bi, type ToolPreflightOptions as bj, type ToolPresentationTone as bk, type ToolResultField as bl, type ToolResultView as bm, type ToolStepCtx as bn, type ToolTransientRetryNumbers as bo, type ToolTransientRetryOptions as bp, type TurnPersona as bq, UNFINISHED_TOOL_CALL as br, type UsagePurpose as bs, askInputSchema as bt, askToolDefinition as bu, danglingToolCallIds as bv, decodeStreamEvent as bw, defaultCanDecide as bx, encodeStreamEvent as by, invokeWithTransientRetry as bz, type ToolPresentation as c, type ToolDefinition as d, type ToolCallRequest as e, type MessageUsage as f, type AgentUiComponent as g, type AiToolCtx as h, type AgentRunInput as i, type MessageAttachment as j, type ActionProposalMutationResult as k, type AgentDefinition as l, type Persona as m, negotiateCatalog as n, type PersonaCatalogEntry as o, prepareUiEmission as p, type HistoryPolicy as q, type PageContext as r, type AgentStore as s, type AgentDelegation as t, type ToolDescribeScope as u, validateUiCapabilities as v, type ToolPreflightResult as w, type ApprovalPolicy as x, type PromptBuilder as y, type PromptContributor as z };
2666
+ export { type Decision as $, type AgentStreamEvent as A, type ActionProposalMutationResult as B, type ChartProps as C, type ActionProposal as D, type ActionProposalExecution as E, type ActionProposalOutcomeDelivery as F, type AgentDefinition as G, type HumanReply as H, type Persona as I, type PersonaCatalogEntry as J, type HistoryPolicy as K, type PageContext as L, type ModelMessage as M, type AgentStore as N, type AgentDelegation as O, type PreparedUiEmission as P, type QuotaState as Q, type DetachedDelivery as R, type ToolDescribeScope as S, type ToolSpec as T, type UiCapabilities as U, type ToolPreflightResult as V, type ApprovalPolicy as W, type PromptBuilder as X, type PromptContributor as Y, type ToolTransientRetrySetting as Z, type AgentIntake as _, type Actor as a, DefaultApprovalPolicy as a$, type ElicitationRequest as a0, type LlmStepEnvelope as a1, type ToolStepEnvelope as a2, type ClaimActionProposal as a3, type ActionProposalStore as a4, type ActionProposalStoreOptions as a5, type CreateActionProposal as a6, type CreateActionProposalResult as a7, type ActionProposalScope as a8, type ListActionProposals as a9, type ToolConfirmation as aA, type ActionProposalDecision as aB, type ActionProposalSupersessionStore as aC, ALL_AGENTS as aD, ASK_TOOL_DESCRIPTION as aE, ASK_TOOL_NAME as aF, type ActionProposalDecisionAudit as aG, type ActionProposalExecutionContext as aH, type ActionProposalLease as aI, type AgentApprovalRequest as aJ, type AgentApprovalSettlement as aK, type AgentAttachmentConfig as aL, type AgentCatalogEntry as aM, type AgentClientConfig as aN, type AgentHistoryWindow as aO, type AgentHostContext as aP, type AgentStreamErrorCode as aQ, type ApprovalDecisionRef as aR, type ApprovalRequirement as aS, type ApprovalThreadRef as aT, type ApprovalToolRef as aU, type AskToolInput as aV, type ChatQueueState as aW, type ClaimedActionApproval as aX, DEFAULT_INTAKE_PREAMBLE as aY, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as aZ, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as a_, type ActionProposalDecisionCommand as aa, type ExtendActionProposalLease as ab, type SettleActionProposal as ac, type ActionProposalOutcome as ad, type ActionProposalOutcomeLease as ae, type ToolCallStatus as af, type ChatQueueStore as ag, type ActionProposalOutcomeStore as ah, type CreateThreadInput as ai, type ThreadSummary as aj, type ThreadDetail as ak, type ToolCallApprovalState as al, type UpdateThreadInput as am, type RecordRunStartInput as an, type EnqueueMessageInput as ao, type QueuedMessage as ap, type QueuedMessagePatch as aq, type QueuePause as ar, type AppendMessageInput as as, type StoredMessage as at, type ToolResult as au, type MessageFeedback as av, type RecordToolCallInput as aw, type ToolCallOutcome as ax, type UpdateToolCallInput as ay, type RecordUsageInput as az, type ToolHandler as b, resolveElicitation as b$, ELICITATION_INPUT_TYPES as b0, type ElicitationInput as b1, type ElicitationInputType as b2, type ElicitationOption as b3, type ElicitationOutcome as b4, type ElicitationQuestion as b5, type ElicitationReply as b6, type ElicitationResult as b7, type EmitUiOptions as b8, type HistoryPolicyContext as b9, type ToolResultField as bA, type ToolResultView as bB, type ToolStepCtx as bC, type ToolTransientRetryNumbers as bD, type ToolTransientRetryOptions as bE, type TurnPersona as bF, UNFINISHED_TOOL_CALL as bG, type UsagePurpose as bH, askInputSchema as bI, askToolDefinition as bJ, danglingToolCallIds as bK, decodeStreamEvent as bL, defaultCanDecide as bM, encodeStreamEvent as bN, invokeWithTransientRetry as bO, isChatQueueStore as bP, isTransientToolError as bQ, isTypedQuestion as bR, mayDecideApproval as bS, normalizeElicitationReply as bT, questionOptions as bU, queuedMessageView as bV, readElicitationInput as bW, readElicitationQuestions as bX, releaseThreadRun as bY, renderElicitationAnswers as bZ, resolveActionProposalApproval as b_, type HistorySelection as ba, type HistorySummary as bb, type InvokeWithTransientRetryOptions as bc, MAX_ASK_QUESTIONS as bd, type MessageFeedbackValue as be, type MessageRole as bf, type PersonaRef as bg, type PromptContext as bh, type QueuePauseReason as bi, type QueuedMessageView as bj, type QuotaView as bk, REQUESTER_APPROVER as bl, RUN_ENDED_BEFORE_TOOL_CALL as bm, type RecordRunEndInput as bn, type ResolveActionProposalApprovalInput as bo, type ThreadTurnPage as bp, type ThreadTurnQuery as bq, type ThreadTurnReader as br, type ToolCallApproval as bs, type ToolCallApprovalColumns as bt, type ToolCallApprovalStatus as bu, type ToolCatalogEntry as bv, type ToolDescription as bw, type ToolKind as bx, type ToolPreflightOptions as by, type ToolPresentationTone as bz, type ToolPresentation as c, resolveToolTransientRetryNumbers as c0, settleDanglingToolCalls as c1, settleElicitation as c2, toolCallApprovalFromRow as c3, validateElicitationAnswer as c4, validateElicitationValue as c5, type ComponentFactory as d, type ComponentManifest as e, type ComponentPresentation as f, type ComponentRegistry as g, type ComponentRenderer as h, type TableCell as i, type TableProps as j, chart as k, createComponent as l, createComponentRegistry as m, negotiateCatalog as n, validateUiCapabilities as o, prepareUiEmission as p, type ToolDefinition as q, type ToolCallRequest as r, snapshotComponentPresentation as s, table as t, type MessageUsage as u, validatePresentationBatch as v, type AgentUiComponent as w, type AiToolCtx as x, type AgentRunInput as y, type MessageAttachment as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-agent-core",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/DavideCarvalho/nestjs-agent.git",