@dudousxd/nestjs-agent-core 0.20.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.
@@ -1,5 +1,74 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
+ /**
4
+ * Typed answers for a question set: a question that asks for a number, a date, an email or a
5
+ * sentence instead of offering options to pick.
6
+ *
7
+ * Answers stay `string[]` on the wire whatever the type — the signal that carries them, the row that
8
+ * records them and the model that reads them back all see strings — so this module fixes ONE
9
+ * canonical string per type and validates against it:
10
+ *
11
+ * | `type` | canonical value |
12
+ * |------------|----------------------------------------------|
13
+ * | `text` | the text |
14
+ * | `textarea` | the text (newlines kept) |
15
+ * | `number` | a finite decimal, e.g. `"42"`, `"-1.5"` |
16
+ * | `boolean` | `"true"` or `"false"` |
17
+ * | `date` | `YYYY-MM-DD` |
18
+ * | `email` | an address with one `@` and a dotted domain |
19
+ * | `url` | an absolute `http:`/`https:` URL |
20
+ * | `select` | one of the question's `options[].value` |
21
+ *
22
+ * Pure and dependency-free, so the loop (which filters what it settles on), the HTTP surface (which
23
+ * refuses what it cannot settle) and a client (which says so before sending) all agree.
24
+ */
25
+
26
+ declare const ELICITATION_INPUT_TYPES: readonly ["text", "textarea", "number", "boolean", "date", "email", "url", "select"];
27
+ type ElicitationInputType = (typeof ELICITATION_INPUT_TYPES)[number];
28
+ /** How a question takes its answer when it is not (only) a pick from `options`. */
29
+ interface ElicitationInput {
30
+ type: ElicitationInputType;
31
+ /** Hint shown in an empty field. Advisory. */
32
+ placeholder?: string;
33
+ /** Submitting without a value is refused. Skipping the whole set is still allowed. */
34
+ required?: boolean;
35
+ /**
36
+ * Lower bound: the smallest number for `number`, the shortest length for `text`/`textarea`, the
37
+ * earliest `YYYY-MM-DD` for `date`. Ignored for the other types.
38
+ */
39
+ min?: number | string;
40
+ /** Upper bound, read like {@link min}. */
41
+ max?: number | string;
42
+ /** A regular expression the WHOLE value must match (`text`, `textarea`, `email`, `url`). */
43
+ pattern?: string;
44
+ }
45
+ /** The question's options, or none — `options` may be omitted on a typed question. */
46
+ declare function questionOptions(question: ElicitationQuestion): ElicitationOption[];
47
+ /** A question answered by a typed value rather than by picking one of its options. */
48
+ declare function isTypedQuestion(question: ElicitationQuestion): boolean;
49
+ /**
50
+ * Why `value` is not an acceptable answer to `question`, or `null` when it is. Checks ONE value;
51
+ * {@link validateElicitationAnswer} checks the list (required, single choice).
52
+ */
53
+ declare function validateElicitationValue(question: ElicitationQuestion, value: string): string | null;
54
+ /**
55
+ * Why `values` is not an acceptable answer to `question`, or `null` when it is: a `required`
56
+ * question left empty, more than one value for a single-choice question, or any value
57
+ * {@link validateElicitationValue} refuses. An empty string counts as no value.
58
+ */
59
+ declare function validateElicitationAnswer(question: ElicitationQuestion, values: readonly string[]): string | null;
60
+ /**
61
+ * Read an {@link ElicitationInput} from untrusted JSON, or `undefined` when it is not one. Unknown
62
+ * keys are dropped; a malformed optional field is dropped rather than failing the input.
63
+ */
64
+ declare function readElicitationInput(raw: unknown): ElicitationInput | undefined;
65
+ /**
66
+ * The questions a parked call carries, read leniently from its recorded input (`{ questions }` —
67
+ * what both an intake and an `ask` persist). Used where a reply is checked against the questions it
68
+ * answers; a question that cannot be read is left out rather than failing the rest.
69
+ */
70
+ declare function readElicitationQuestions(input: unknown): ElicitationQuestion[];
71
+
3
72
  /**
4
73
  * Asking the USER a structured question, and waiting for the answer.
5
74
  *
@@ -27,7 +96,19 @@ interface ElicitationQuestion {
27
96
  /** Unique within its request; the key answers come back under. */
28
97
  id: string;
29
98
  prompt: string;
30
- options: ElicitationOption[];
99
+ /** A line of help under the prompt. */
100
+ description?: string;
101
+ /**
102
+ * The choices. Required unless {@link input} asks for a typed value — then optional, and a UI may
103
+ * offer them as suggestions. An `input` of type `select` still picks from these.
104
+ */
105
+ options?: ElicitationOption[];
106
+ /**
107
+ * Ask for a typed value (a number, a date, a sentence…) instead of — or, for `select`, on top of —
108
+ * a pick from `options`. The answer is still a `string[]`, in the type's canonical form; see
109
+ * `elicitation-input.ts`.
110
+ */
111
+ input?: ElicitationInput;
31
112
  /** More than one option may be chosen. Omit → single choice. */
32
113
  multiple?: boolean;
33
114
  /**
@@ -1385,4 +1466,4 @@ interface ToolHandler<I = unknown> {
1385
1466
  canUse?(actor: Actor): boolean | Promise<boolean>;
1386
1467
  }
1387
1468
 
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 };
1469
+ export { type ElicitationInputType 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, ELICITATION_INPUT_TYPES as Z, type ElicitationInput as _, type ToolDefinition as a, type ElicitationOption as a0, type ElicitationOutcome as a1, type ElicitationQuestion as a2, type ElicitationReply as a3, type ElicitationResult as a4, type HistoryPolicyContext as a5, type HistorySelection as a6, type HistorySummary as a7, type IncrementalGating as a8, type InvokeWithTransientRetryOptions as a9, readElicitationInput as aA, readElicitationQuestions as aB, renderElicitationAnswers as aC, resolveElicitation as aD, resolveToolTransientRetryNumbers as aE, settleElicitation as aF, validateElicitationAnswer as aG, validateElicitationValue as aH, MAX_ASK_QUESTIONS as aa, type MessageRole as ab, OutputRejectedError as ac, type OutputVerdict as ad, ProcessorFailedError as ae, type PromptContext as af, type QuotaView as ag, type ToolCallApprovalStatus as ah, type ToolCatalogEntry as ai, type ToolConfirmation as aj, type ToolPresentation as ak, type ToolPresentationTone as al, type ToolResultField as am, type ToolResultView as an, type ToolStepCtx as ao, type ToolTransientRetryNumbers as ap, type ToolTransientRetryOptions as aq, askInputSchema as ar, askToolDefinition as as, decodeStreamEvent as at, encodeStreamEvent as au, invokeWithTransientRetry as av, isTransientToolError as aw, isTypedQuestion as ax, normalizeElicitationReply as ay, questionOptions as az, 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 };
@@ -1,5 +1,74 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
+ /**
4
+ * Typed answers for a question set: a question that asks for a number, a date, an email or a
5
+ * sentence instead of offering options to pick.
6
+ *
7
+ * Answers stay `string[]` on the wire whatever the type — the signal that carries them, the row that
8
+ * records them and the model that reads them back all see strings — so this module fixes ONE
9
+ * canonical string per type and validates against it:
10
+ *
11
+ * | `type` | canonical value |
12
+ * |------------|----------------------------------------------|
13
+ * | `text` | the text |
14
+ * | `textarea` | the text (newlines kept) |
15
+ * | `number` | a finite decimal, e.g. `"42"`, `"-1.5"` |
16
+ * | `boolean` | `"true"` or `"false"` |
17
+ * | `date` | `YYYY-MM-DD` |
18
+ * | `email` | an address with one `@` and a dotted domain |
19
+ * | `url` | an absolute `http:`/`https:` URL |
20
+ * | `select` | one of the question's `options[].value` |
21
+ *
22
+ * Pure and dependency-free, so the loop (which filters what it settles on), the HTTP surface (which
23
+ * refuses what it cannot settle) and a client (which says so before sending) all agree.
24
+ */
25
+
26
+ declare const ELICITATION_INPUT_TYPES: readonly ["text", "textarea", "number", "boolean", "date", "email", "url", "select"];
27
+ type ElicitationInputType = (typeof ELICITATION_INPUT_TYPES)[number];
28
+ /** How a question takes its answer when it is not (only) a pick from `options`. */
29
+ interface ElicitationInput {
30
+ type: ElicitationInputType;
31
+ /** Hint shown in an empty field. Advisory. */
32
+ placeholder?: string;
33
+ /** Submitting without a value is refused. Skipping the whole set is still allowed. */
34
+ required?: boolean;
35
+ /**
36
+ * Lower bound: the smallest number for `number`, the shortest length for `text`/`textarea`, the
37
+ * earliest `YYYY-MM-DD` for `date`. Ignored for the other types.
38
+ */
39
+ min?: number | string;
40
+ /** Upper bound, read like {@link min}. */
41
+ max?: number | string;
42
+ /** A regular expression the WHOLE value must match (`text`, `textarea`, `email`, `url`). */
43
+ pattern?: string;
44
+ }
45
+ /** The question's options, or none — `options` may be omitted on a typed question. */
46
+ declare function questionOptions(question: ElicitationQuestion): ElicitationOption[];
47
+ /** A question answered by a typed value rather than by picking one of its options. */
48
+ declare function isTypedQuestion(question: ElicitationQuestion): boolean;
49
+ /**
50
+ * Why `value` is not an acceptable answer to `question`, or `null` when it is. Checks ONE value;
51
+ * {@link validateElicitationAnswer} checks the list (required, single choice).
52
+ */
53
+ declare function validateElicitationValue(question: ElicitationQuestion, value: string): string | null;
54
+ /**
55
+ * Why `values` is not an acceptable answer to `question`, or `null` when it is: a `required`
56
+ * question left empty, more than one value for a single-choice question, or any value
57
+ * {@link validateElicitationValue} refuses. An empty string counts as no value.
58
+ */
59
+ declare function validateElicitationAnswer(question: ElicitationQuestion, values: readonly string[]): string | null;
60
+ /**
61
+ * Read an {@link ElicitationInput} from untrusted JSON, or `undefined` when it is not one. Unknown
62
+ * keys are dropped; a malformed optional field is dropped rather than failing the input.
63
+ */
64
+ declare function readElicitationInput(raw: unknown): ElicitationInput | undefined;
65
+ /**
66
+ * The questions a parked call carries, read leniently from its recorded input (`{ questions }` —
67
+ * what both an intake and an `ask` persist). Used where a reply is checked against the questions it
68
+ * answers; a question that cannot be read is left out rather than failing the rest.
69
+ */
70
+ declare function readElicitationQuestions(input: unknown): ElicitationQuestion[];
71
+
3
72
  /**
4
73
  * Asking the USER a structured question, and waiting for the answer.
5
74
  *
@@ -27,7 +96,19 @@ interface ElicitationQuestion {
27
96
  /** Unique within its request; the key answers come back under. */
28
97
  id: string;
29
98
  prompt: string;
30
- options: ElicitationOption[];
99
+ /** A line of help under the prompt. */
100
+ description?: string;
101
+ /**
102
+ * The choices. Required unless {@link input} asks for a typed value — then optional, and a UI may
103
+ * offer them as suggestions. An `input` of type `select` still picks from these.
104
+ */
105
+ options?: ElicitationOption[];
106
+ /**
107
+ * Ask for a typed value (a number, a date, a sentence…) instead of — or, for `select`, on top of —
108
+ * a pick from `options`. The answer is still a `string[]`, in the type's canonical form; see
109
+ * `elicitation-input.ts`.
110
+ */
111
+ input?: ElicitationInput;
31
112
  /** More than one option may be chosen. Omit → single choice. */
32
113
  multiple?: boolean;
33
114
  /**
@@ -1385,4 +1466,4 @@ interface ToolHandler<I = unknown> {
1385
1466
  canUse?(actor: Actor): boolean | Promise<boolean>;
1386
1467
  }
1387
1468
 
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 };
1469
+ export { type ElicitationInputType 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, ELICITATION_INPUT_TYPES as Z, type ElicitationInput as _, type ToolDefinition as a, type ElicitationOption as a0, type ElicitationOutcome as a1, type ElicitationQuestion as a2, type ElicitationReply as a3, type ElicitationResult as a4, type HistoryPolicyContext as a5, type HistorySelection as a6, type HistorySummary as a7, type IncrementalGating as a8, type InvokeWithTransientRetryOptions as a9, readElicitationInput as aA, readElicitationQuestions as aB, renderElicitationAnswers as aC, resolveElicitation as aD, resolveToolTransientRetryNumbers as aE, settleElicitation as aF, validateElicitationAnswer as aG, validateElicitationValue as aH, MAX_ASK_QUESTIONS as aa, type MessageRole as ab, OutputRejectedError as ac, type OutputVerdict as ad, ProcessorFailedError as ae, type PromptContext as af, type QuotaView as ag, type ToolCallApprovalStatus as ah, type ToolCatalogEntry as ai, type ToolConfirmation as aj, type ToolPresentation as ak, type ToolPresentationTone as al, type ToolResultField as am, type ToolResultView as an, type ToolStepCtx as ao, type ToolTransientRetryNumbers as ap, type ToolTransientRetryOptions as aq, askInputSchema as ar, askToolDefinition as as, decodeStreamEvent as at, encodeStreamEvent as au, invokeWithTransientRetry as av, isTransientToolError as aw, isTypedQuestion as ax, normalizeElicitationReply as ay, questionOptions as az, 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.20.0",
3
+ "version": "0.21.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/DavideCarvalho/nestjs-agent.git",