@paymanai/payman-typescript-ask-sdk 4.0.9 → 4.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -72,19 +72,86 @@ type MessageRole = "user" | "assistant" | "system";
72
72
  type StreamProgress = "started" | "processing" | "completed" | "error";
73
73
  /** Stage values accepted by the k2 playground API. */
74
74
  type AgentStage = "DEVELOPMENT" | "QA" | "PROD";
75
- type UserActionType = "PAYMENT_APPROVAL" | "PAYEE_APPROVAL";
75
+ /**
76
+ * Which UI a user-action prompt renders. Derived from the event's
77
+ * `action` (the MCP elicitation kind) with a schema-based fallback.
78
+ */
79
+ type UserActionKind = "form" | "verification" | "notification";
80
+ /** Lifecycle hint for a prompt (chiefly verification retries/resends). */
81
+ type UserActionSubAction = "NewRequest" | "RequestResent" | "SubmissionInvalid";
82
+ /** Input mode for a verification code. */
83
+ type VerificationType = "NUMERIC_CODE" | "ALPHANUMERIC_CODE";
84
+ /** A single titled option for a `oneOf` single-select field. */
85
+ type JsonSchemaOption = {
86
+ const: string;
87
+ title?: string;
88
+ };
89
+ /**
90
+ * One field in a `requestedSchema.properties` map. This models the
91
+ * documented flat JSON-Schema subset the server emits today. It is
92
+ * standard JSON Schema, so unknown keywords are tolerated (ignored)
93
+ * and an unknown `type` degrades to a text input on the UI side.
94
+ */
95
+ type JsonSchemaField = {
96
+ type?: "string" | "number" | "integer" | "boolean" | (string & {});
97
+ title?: string;
98
+ description?: string;
99
+ default?: unknown;
100
+ oneOf?: JsonSchemaOption[];
101
+ minimum?: number;
102
+ maximum?: number;
103
+ minLength?: number;
104
+ maxLength?: number;
105
+ [key: string]: unknown;
106
+ };
107
+ /** The restricted JSON Schema describing a form to render. */
108
+ type RequestedSchema = {
109
+ type?: string;
110
+ properties?: Record<string, JsonSchemaField>;
111
+ required?: string[];
112
+ [key: string]: unknown;
113
+ };
114
+ /**
115
+ * A user-action prompt the agent raised mid-stream, built from the
116
+ * top-level fields of a `USER_ACTION_REQUIRED` event.
117
+ */
76
118
  type UserActionRequest = {
77
119
  userActionId: string;
78
- userActionType?: UserActionType;
79
- message: string;
80
- requestedSchema: Record<string, unknown>;
120
+ /** Classified prompt kind (drives which renderer the UI uses). */
121
+ kind: UserActionKind;
122
+ /** Raw MCP elicitation `action` string as sent by the server. */
123
+ rawAction?: string;
124
+ subAction?: UserActionSubAction | (string & {});
125
+ verificationType?: VerificationType;
126
+ expirySeconds?: number;
127
+ message?: string;
128
+ requestedSchema?: RequestedSchema;
81
129
  metadata?: Record<string, string>;
130
+ /** Correlation ids used to group/supersede prompts. */
131
+ toolCallId?: string;
132
+ executionId?: string;
133
+ sessionId?: string;
134
+ };
135
+ /** Resolution status of a single active prompt. */
136
+ type UserActionStatus = "pending" | "submitting" | "expired" | "stale";
137
+ /** An active prompt slot: the request plus its live resolution status. */
138
+ type ActiveUserAction = UserActionRequest & {
139
+ status: UserActionStatus;
140
+ };
141
+ /** A one-way notification surfaced to the user (`USER_NOTIFICATION`). */
142
+ type UserNotification = {
143
+ id: string;
144
+ message: string;
82
145
  };
83
- type UserActionResult = "approved" | "rejected";
146
+ /**
147
+ * Public user-action state exposed by the chat hook. `prompts` is an
148
+ * ordered, keyed collection (one slot per `toolCallId`, falling back to
149
+ * `userActionId`) — typically 0–1 entries for serial runs, more when the
150
+ * engine elicits from parallel tool calls.
151
+ */
84
152
  type UserActionState = {
85
- request: UserActionRequest | null;
86
- result: UserActionResult | null;
87
- clearOtpTrigger: number;
153
+ prompts: ActiveUserAction[];
154
+ notifications: UserNotification[];
88
155
  };
89
156
  type StreamingStep = {
90
157
  id: string;
@@ -137,8 +204,6 @@ type MessageDisplay = {
137
204
  steps?: StreamingStep[];
138
205
  isCancelled?: boolean;
139
206
  currentExecutingStepId?: string;
140
- /** Result of user action (OTP approval/rejection) */
141
- userActionResult?: UserActionResult;
142
207
  /** Current thinking block text (live, resets per block) */
143
208
  activeThinkingText?: string;
144
209
  /** All thinking accumulated across blocks (for post-stream display) */
@@ -264,10 +329,14 @@ type ChatCallbacks = {
264
329
  }) => void;
265
330
  /** Called when session ID changes */
266
331
  onSessionIdChange?: (sessionId: string) => void;
267
- /** Called when a user action (e.g. OTP) is required */
332
+ /**
333
+ * Called when the agent raises a user-action prompt
334
+ * (`USER_ACTION_REQUIRED`). Fires for both new prompts and
335
+ * supersedes (a retry/resend that replaces an existing slot).
336
+ */
268
337
  onUserActionRequired?: (request: UserActionRequest) => void;
269
- /** Called on user action events (SUCCESS, INVALID, EXPIRED, REJECTED, RESENT, FAILED) */
270
- onUserActionEvent?: (eventType: string, message: string) => void;
338
+ /** Called when the agent pushes a one-way notification (`USER_NOTIFICATION`). */
339
+ onUserNotification?: (notification: UserNotification) => void;
271
340
  /**
272
341
  * Fires whenever the current streaming "status message" changes —
273
342
  * the user-facing label for whatever stage is running right now
@@ -336,10 +405,19 @@ type UseChatV2Return = {
336
405
  getMessages: () => MessageDisplay[];
337
406
  isWaitingForResponse: boolean;
338
407
  sessionId: string | undefined;
408
+ /** Active user-action prompts + one-way notifications for this chat. */
339
409
  userActionState: UserActionState;
340
- approveUserAction: (otp: string) => Promise<void>;
341
- rejectUserAction: () => Promise<void>;
342
- resendOtp: () => Promise<void>;
410
+ /**
411
+ * Submit a prompt's form payload. `content` keys should match the
412
+ * prompt's `requestedSchema.properties` (e.g. `{ otp: "123456" }`).
413
+ */
414
+ submitUserAction: (userActionId: string, content: Record<string, unknown>) => Promise<void>;
415
+ /** Cancel / decline a prompt. */
416
+ cancelUserAction: (userActionId: string) => Promise<void>;
417
+ /** Ask the agent to re-send a prompt (e.g. resend a verification code). */
418
+ resendUserAction: (userActionId: string) => Promise<void>;
419
+ /** Dismiss a one-way notification from local state. */
420
+ dismissNotification: (id: string) => void;
343
421
  };
344
422
  declare function useChatV2(config: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
345
423
 
@@ -422,13 +500,20 @@ type StreamEvent = {
422
500
  * "Thinking…" panel rather than the chat bubble.
423
501
  */
424
502
  text?: string;
425
- userActionRequest?: {
426
- userActionId: string;
427
- userActionType?: string;
428
- message: string;
429
- requestedSchema: Record<string, unknown>;
430
- metadata?: Record<string, string>;
431
- };
503
+ /**
504
+ * User-action / elicitation fields, carried at the TOP LEVEL of a
505
+ * `USER_ACTION_REQUIRED` event (and `userActionId`/`message` on
506
+ * `USER_NOTIFICATION`). The MCP `_meta.action` kind is forwarded
507
+ * here as `action`; `requestedSchema` is standard JSON Schema.
508
+ */
509
+ userActionId?: string;
510
+ action?: string;
511
+ subAction?: string;
512
+ verificationType?: string;
513
+ expirySeconds?: number;
514
+ requestedSchema?: Record<string, unknown>;
515
+ metadata?: Record<string, string>;
516
+ toolCallId?: string;
432
517
  [key: string]: unknown;
433
518
  };
434
519
  type StreamOptions = {
@@ -453,6 +538,12 @@ declare function streamWorkflowEvents(url: string, body: Record<string, unknown>
453
538
  */
454
539
  declare function buildFormattedThinking(steps: StreamingStep[] | undefined, allThinkingText: string): string;
455
540
 
541
+ /**
542
+ * Classify a `USER_ACTION_REQUIRED` event into a render kind. Primary
543
+ * discriminator is the MCP elicitation `action`; we fall back to the
544
+ * schema shape so unknown/legacy `action` tags still route correctly.
545
+ */
546
+ declare function classifyUserActionKind(action: string | undefined, schema: RequestedSchema | undefined): UserActionKind;
456
547
  type V2EventProcessorState = {
457
548
  formattedThinkingText: string;
458
549
  finalResponse: string;
@@ -462,9 +553,22 @@ type V2EventProcessorState = {
462
553
  executionId?: string;
463
554
  hasError: boolean;
464
555
  errorMessage: string;
465
- userActionRequest?: UserActionRequest;
466
- userActionPending: boolean;
467
- userActionResult?: UserActionResult;
556
+ /**
557
+ * Active user-action prompts, an ordered collection keyed by
558
+ * `toolCallId` (fallback `userActionId`). Usually 0–1 for serial
559
+ * runs; multiple when parallel tool calls each elicit.
560
+ */
561
+ userActions: ActiveUserAction[];
562
+ /** One-way notifications surfaced this run (`USER_NOTIFICATION`). */
563
+ notifications: UserNotification[];
564
+ /**
565
+ * Transient: the prompt upserted by the most recent
566
+ * `USER_ACTION_REQUIRED` event, so the stream manager can fire
567
+ * `onUserActionRequired` for exactly that prompt. Reset each event.
568
+ */
569
+ lastUserAction?: UserActionRequest;
570
+ /** Transient: the notification pushed by the most recent event. */
571
+ lastNotification?: UserNotification;
468
572
  finalData?: unknown;
469
573
  steps: StreamingStep[];
470
574
  stepCounter: number;
@@ -475,14 +579,75 @@ type V2EventProcessorState = {
475
579
  declare function createInitialV2State(): V2EventProcessorState;
476
580
  declare function processStreamEventV2(rawEvent: StreamEvent, state: V2EventProcessorState): V2EventProcessorState;
477
581
 
582
+ /** The widget kinds the renderer knows how to draw. */
583
+ type FieldWidget = "text" | "integer" | "decimal" | "boolean" | "select";
584
+ /**
585
+ * Classify a schema field into a widget kind. `oneOf` always wins
586
+ * (titled single-select), then `type`. Anything unrecognized — or a
587
+ * missing type — degrades to a plain text input.
588
+ */
589
+ declare function classifyField(field: JsonSchemaField | undefined): FieldWidget;
590
+ /**
591
+ * Fields we can't render as a flat primitive (nested objects, arrays,
592
+ * tuple/composite schemas). The renderer should skip these rather than
593
+ * attempt a best-effort input. `oneOf` is NOT considered unsupported —
594
+ * it's our single-select shape.
595
+ */
596
+ declare function isNestedOrUnsupported(field: JsonSchemaField | undefined): boolean;
597
+ /** Normalize a field's `oneOf` into a clean option list (drops malformed entries). */
598
+ declare function getOptions(field: JsonSchemaField | undefined): JsonSchemaOption[];
599
+ /** Is `key` required per the schema's `required` array? */
600
+ declare function isRequired(schema: RequestedSchema | undefined, key: string): boolean;
601
+ /**
602
+ * Coerce a raw widget value into the JSON type the schema declares, so
603
+ * the submitted `content` round-trips cleanly. Empty/blank values become
604
+ * `undefined` (the field is simply omitted from the payload). The server
605
+ * is tolerant of strings, but matching types keeps things clean.
606
+ */
607
+ declare function coerceValue(field: JsonSchemaField | undefined, raw: unknown): unknown;
608
+ /** Pre-fill value for a field's widget, from `default` (typed loosely for inputs). */
609
+ declare function defaultValueFor(field: JsonSchemaField | undefined): unknown;
610
+ /**
611
+ * Validate a single field's coerced value. Returns an error string or
612
+ * `null` when valid. Only the documented keywords are enforced; unknown
613
+ * keywords are ignored.
614
+ */
615
+ declare function validateField(field: JsonSchemaField | undefined, value: unknown, required: boolean): string | null;
616
+ /** Ordered list of renderable [key, field] pairs (skips unsupported fields). */
617
+ declare function renderableFields(schema: RequestedSchema | undefined): Array<[string, JsonSchemaField]>;
618
+ /**
619
+ * Validate a full form. `values` is the raw widget-value map (pre-coercion).
620
+ * Returns a `{ key: error }` map (empty when the form is valid).
621
+ */
622
+ declare function validateForm(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, string>;
623
+ /**
624
+ * Build the schema-typed `content` object to POST on submit. Only fields
625
+ * present in the schema are included; blank/undefined values are omitted.
626
+ */
627
+ declare function buildContent(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, unknown>;
628
+
478
629
  type UserActionResponse = {
479
630
  success: boolean;
480
631
  message: string;
481
632
  };
482
633
  /**
483
- * Submit a user action (e.g. OTP verification)
634
+ * Thrown when a resolution endpoint returns `404`
635
+ * (`user_action_not_found`): the prompt already resolved, expired, or
636
+ * the id is unknown. Callers should treat the prompt as no longer
637
+ * actionable — stop any countdown and clear the form — rather than
638
+ * surfacing this as a hard error.
639
+ */
640
+ declare class UserActionStaleError extends Error {
641
+ readonly userActionId: string;
642
+ constructor(userActionId: string, message?: string);
643
+ }
644
+ /**
645
+ * Submit a user action. `content` is the schema-typed form payload sent
646
+ * straight through to the agent (its keys should match the prompt's
647
+ * `requestedSchema.properties`) — e.g. `{ otp: "123456" }` for a
648
+ * verification prompt or `{ amount: 50, confirm: true }` for a form.
484
649
  */
485
- declare function submitUserAction(config: ChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
650
+ declare function submitUserAction(config: ChatConfig, userActionId: string, content?: Record<string, unknown>): Promise<UserActionResponse>;
486
651
  /**
487
652
  * Cancel / reject a user action
488
653
  */
@@ -492,4 +657,6 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
492
657
  */
493
658
  declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
494
659
 
495
- export { type APIConfig, type AgentStage, type AnalysisMode, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageFeedbackState, type MessageRole, type SendMessageOptions, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatV2Return, type UseVoiceReturn, type UserActionRequest, type UserActionResult, type UserActionState, type UserActionType, type V2EventProcessorState, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, buildFormattedThinking, cancelUserAction, createInitialV2State, generateId, processStreamEventV2, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice };
660
+ declare function migrateActiveStream(oldUserId: string, newUserId: string): void;
661
+
662
+ export { type APIConfig, type ActiveUserAction, type AgentStage, type AnalysisMode, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type FieldWidget, type JsonSchemaField, type JsonSchemaOption, type MessageDisplay, type MessageFeedbackState, type MessageRole, type RequestedSchema, type SendMessageOptions, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatV2Return, type UseVoiceReturn, type UserActionKind, type UserActionRequest, UserActionStaleError, type UserActionState, type UserActionStatus, type UserActionSubAction, type UserNotification, type V2EventProcessorState, type VerificationType, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, buildContent, buildFormattedThinking, cancelUserAction, classifyField, classifyUserActionKind, coerceValue, createInitialV2State, defaultValueFor, generateId, getOptions, isNestedOrUnsupported, isRequired, migrateActiveStream, processStreamEventV2, renderableFields, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice, validateField, validateForm };
package/dist/index.d.ts CHANGED
@@ -72,19 +72,86 @@ type MessageRole = "user" | "assistant" | "system";
72
72
  type StreamProgress = "started" | "processing" | "completed" | "error";
73
73
  /** Stage values accepted by the k2 playground API. */
74
74
  type AgentStage = "DEVELOPMENT" | "QA" | "PROD";
75
- type UserActionType = "PAYMENT_APPROVAL" | "PAYEE_APPROVAL";
75
+ /**
76
+ * Which UI a user-action prompt renders. Derived from the event's
77
+ * `action` (the MCP elicitation kind) with a schema-based fallback.
78
+ */
79
+ type UserActionKind = "form" | "verification" | "notification";
80
+ /** Lifecycle hint for a prompt (chiefly verification retries/resends). */
81
+ type UserActionSubAction = "NewRequest" | "RequestResent" | "SubmissionInvalid";
82
+ /** Input mode for a verification code. */
83
+ type VerificationType = "NUMERIC_CODE" | "ALPHANUMERIC_CODE";
84
+ /** A single titled option for a `oneOf` single-select field. */
85
+ type JsonSchemaOption = {
86
+ const: string;
87
+ title?: string;
88
+ };
89
+ /**
90
+ * One field in a `requestedSchema.properties` map. This models the
91
+ * documented flat JSON-Schema subset the server emits today. It is
92
+ * standard JSON Schema, so unknown keywords are tolerated (ignored)
93
+ * and an unknown `type` degrades to a text input on the UI side.
94
+ */
95
+ type JsonSchemaField = {
96
+ type?: "string" | "number" | "integer" | "boolean" | (string & {});
97
+ title?: string;
98
+ description?: string;
99
+ default?: unknown;
100
+ oneOf?: JsonSchemaOption[];
101
+ minimum?: number;
102
+ maximum?: number;
103
+ minLength?: number;
104
+ maxLength?: number;
105
+ [key: string]: unknown;
106
+ };
107
+ /** The restricted JSON Schema describing a form to render. */
108
+ type RequestedSchema = {
109
+ type?: string;
110
+ properties?: Record<string, JsonSchemaField>;
111
+ required?: string[];
112
+ [key: string]: unknown;
113
+ };
114
+ /**
115
+ * A user-action prompt the agent raised mid-stream, built from the
116
+ * top-level fields of a `USER_ACTION_REQUIRED` event.
117
+ */
76
118
  type UserActionRequest = {
77
119
  userActionId: string;
78
- userActionType?: UserActionType;
79
- message: string;
80
- requestedSchema: Record<string, unknown>;
120
+ /** Classified prompt kind (drives which renderer the UI uses). */
121
+ kind: UserActionKind;
122
+ /** Raw MCP elicitation `action` string as sent by the server. */
123
+ rawAction?: string;
124
+ subAction?: UserActionSubAction | (string & {});
125
+ verificationType?: VerificationType;
126
+ expirySeconds?: number;
127
+ message?: string;
128
+ requestedSchema?: RequestedSchema;
81
129
  metadata?: Record<string, string>;
130
+ /** Correlation ids used to group/supersede prompts. */
131
+ toolCallId?: string;
132
+ executionId?: string;
133
+ sessionId?: string;
134
+ };
135
+ /** Resolution status of a single active prompt. */
136
+ type UserActionStatus = "pending" | "submitting" | "expired" | "stale";
137
+ /** An active prompt slot: the request plus its live resolution status. */
138
+ type ActiveUserAction = UserActionRequest & {
139
+ status: UserActionStatus;
140
+ };
141
+ /** A one-way notification surfaced to the user (`USER_NOTIFICATION`). */
142
+ type UserNotification = {
143
+ id: string;
144
+ message: string;
82
145
  };
83
- type UserActionResult = "approved" | "rejected";
146
+ /**
147
+ * Public user-action state exposed by the chat hook. `prompts` is an
148
+ * ordered, keyed collection (one slot per `toolCallId`, falling back to
149
+ * `userActionId`) — typically 0–1 entries for serial runs, more when the
150
+ * engine elicits from parallel tool calls.
151
+ */
84
152
  type UserActionState = {
85
- request: UserActionRequest | null;
86
- result: UserActionResult | null;
87
- clearOtpTrigger: number;
153
+ prompts: ActiveUserAction[];
154
+ notifications: UserNotification[];
88
155
  };
89
156
  type StreamingStep = {
90
157
  id: string;
@@ -137,8 +204,6 @@ type MessageDisplay = {
137
204
  steps?: StreamingStep[];
138
205
  isCancelled?: boolean;
139
206
  currentExecutingStepId?: string;
140
- /** Result of user action (OTP approval/rejection) */
141
- userActionResult?: UserActionResult;
142
207
  /** Current thinking block text (live, resets per block) */
143
208
  activeThinkingText?: string;
144
209
  /** All thinking accumulated across blocks (for post-stream display) */
@@ -264,10 +329,14 @@ type ChatCallbacks = {
264
329
  }) => void;
265
330
  /** Called when session ID changes */
266
331
  onSessionIdChange?: (sessionId: string) => void;
267
- /** Called when a user action (e.g. OTP) is required */
332
+ /**
333
+ * Called when the agent raises a user-action prompt
334
+ * (`USER_ACTION_REQUIRED`). Fires for both new prompts and
335
+ * supersedes (a retry/resend that replaces an existing slot).
336
+ */
268
337
  onUserActionRequired?: (request: UserActionRequest) => void;
269
- /** Called on user action events (SUCCESS, INVALID, EXPIRED, REJECTED, RESENT, FAILED) */
270
- onUserActionEvent?: (eventType: string, message: string) => void;
338
+ /** Called when the agent pushes a one-way notification (`USER_NOTIFICATION`). */
339
+ onUserNotification?: (notification: UserNotification) => void;
271
340
  /**
272
341
  * Fires whenever the current streaming "status message" changes —
273
342
  * the user-facing label for whatever stage is running right now
@@ -336,10 +405,19 @@ type UseChatV2Return = {
336
405
  getMessages: () => MessageDisplay[];
337
406
  isWaitingForResponse: boolean;
338
407
  sessionId: string | undefined;
408
+ /** Active user-action prompts + one-way notifications for this chat. */
339
409
  userActionState: UserActionState;
340
- approveUserAction: (otp: string) => Promise<void>;
341
- rejectUserAction: () => Promise<void>;
342
- resendOtp: () => Promise<void>;
410
+ /**
411
+ * Submit a prompt's form payload. `content` keys should match the
412
+ * prompt's `requestedSchema.properties` (e.g. `{ otp: "123456" }`).
413
+ */
414
+ submitUserAction: (userActionId: string, content: Record<string, unknown>) => Promise<void>;
415
+ /** Cancel / decline a prompt. */
416
+ cancelUserAction: (userActionId: string) => Promise<void>;
417
+ /** Ask the agent to re-send a prompt (e.g. resend a verification code). */
418
+ resendUserAction: (userActionId: string) => Promise<void>;
419
+ /** Dismiss a one-way notification from local state. */
420
+ dismissNotification: (id: string) => void;
343
421
  };
344
422
  declare function useChatV2(config: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
345
423
 
@@ -422,13 +500,20 @@ type StreamEvent = {
422
500
  * "Thinking…" panel rather than the chat bubble.
423
501
  */
424
502
  text?: string;
425
- userActionRequest?: {
426
- userActionId: string;
427
- userActionType?: string;
428
- message: string;
429
- requestedSchema: Record<string, unknown>;
430
- metadata?: Record<string, string>;
431
- };
503
+ /**
504
+ * User-action / elicitation fields, carried at the TOP LEVEL of a
505
+ * `USER_ACTION_REQUIRED` event (and `userActionId`/`message` on
506
+ * `USER_NOTIFICATION`). The MCP `_meta.action` kind is forwarded
507
+ * here as `action`; `requestedSchema` is standard JSON Schema.
508
+ */
509
+ userActionId?: string;
510
+ action?: string;
511
+ subAction?: string;
512
+ verificationType?: string;
513
+ expirySeconds?: number;
514
+ requestedSchema?: Record<string, unknown>;
515
+ metadata?: Record<string, string>;
516
+ toolCallId?: string;
432
517
  [key: string]: unknown;
433
518
  };
434
519
  type StreamOptions = {
@@ -453,6 +538,12 @@ declare function streamWorkflowEvents(url: string, body: Record<string, unknown>
453
538
  */
454
539
  declare function buildFormattedThinking(steps: StreamingStep[] | undefined, allThinkingText: string): string;
455
540
 
541
+ /**
542
+ * Classify a `USER_ACTION_REQUIRED` event into a render kind. Primary
543
+ * discriminator is the MCP elicitation `action`; we fall back to the
544
+ * schema shape so unknown/legacy `action` tags still route correctly.
545
+ */
546
+ declare function classifyUserActionKind(action: string | undefined, schema: RequestedSchema | undefined): UserActionKind;
456
547
  type V2EventProcessorState = {
457
548
  formattedThinkingText: string;
458
549
  finalResponse: string;
@@ -462,9 +553,22 @@ type V2EventProcessorState = {
462
553
  executionId?: string;
463
554
  hasError: boolean;
464
555
  errorMessage: string;
465
- userActionRequest?: UserActionRequest;
466
- userActionPending: boolean;
467
- userActionResult?: UserActionResult;
556
+ /**
557
+ * Active user-action prompts, an ordered collection keyed by
558
+ * `toolCallId` (fallback `userActionId`). Usually 0–1 for serial
559
+ * runs; multiple when parallel tool calls each elicit.
560
+ */
561
+ userActions: ActiveUserAction[];
562
+ /** One-way notifications surfaced this run (`USER_NOTIFICATION`). */
563
+ notifications: UserNotification[];
564
+ /**
565
+ * Transient: the prompt upserted by the most recent
566
+ * `USER_ACTION_REQUIRED` event, so the stream manager can fire
567
+ * `onUserActionRequired` for exactly that prompt. Reset each event.
568
+ */
569
+ lastUserAction?: UserActionRequest;
570
+ /** Transient: the notification pushed by the most recent event. */
571
+ lastNotification?: UserNotification;
468
572
  finalData?: unknown;
469
573
  steps: StreamingStep[];
470
574
  stepCounter: number;
@@ -475,14 +579,75 @@ type V2EventProcessorState = {
475
579
  declare function createInitialV2State(): V2EventProcessorState;
476
580
  declare function processStreamEventV2(rawEvent: StreamEvent, state: V2EventProcessorState): V2EventProcessorState;
477
581
 
582
+ /** The widget kinds the renderer knows how to draw. */
583
+ type FieldWidget = "text" | "integer" | "decimal" | "boolean" | "select";
584
+ /**
585
+ * Classify a schema field into a widget kind. `oneOf` always wins
586
+ * (titled single-select), then `type`. Anything unrecognized — or a
587
+ * missing type — degrades to a plain text input.
588
+ */
589
+ declare function classifyField(field: JsonSchemaField | undefined): FieldWidget;
590
+ /**
591
+ * Fields we can't render as a flat primitive (nested objects, arrays,
592
+ * tuple/composite schemas). The renderer should skip these rather than
593
+ * attempt a best-effort input. `oneOf` is NOT considered unsupported —
594
+ * it's our single-select shape.
595
+ */
596
+ declare function isNestedOrUnsupported(field: JsonSchemaField | undefined): boolean;
597
+ /** Normalize a field's `oneOf` into a clean option list (drops malformed entries). */
598
+ declare function getOptions(field: JsonSchemaField | undefined): JsonSchemaOption[];
599
+ /** Is `key` required per the schema's `required` array? */
600
+ declare function isRequired(schema: RequestedSchema | undefined, key: string): boolean;
601
+ /**
602
+ * Coerce a raw widget value into the JSON type the schema declares, so
603
+ * the submitted `content` round-trips cleanly. Empty/blank values become
604
+ * `undefined` (the field is simply omitted from the payload). The server
605
+ * is tolerant of strings, but matching types keeps things clean.
606
+ */
607
+ declare function coerceValue(field: JsonSchemaField | undefined, raw: unknown): unknown;
608
+ /** Pre-fill value for a field's widget, from `default` (typed loosely for inputs). */
609
+ declare function defaultValueFor(field: JsonSchemaField | undefined): unknown;
610
+ /**
611
+ * Validate a single field's coerced value. Returns an error string or
612
+ * `null` when valid. Only the documented keywords are enforced; unknown
613
+ * keywords are ignored.
614
+ */
615
+ declare function validateField(field: JsonSchemaField | undefined, value: unknown, required: boolean): string | null;
616
+ /** Ordered list of renderable [key, field] pairs (skips unsupported fields). */
617
+ declare function renderableFields(schema: RequestedSchema | undefined): Array<[string, JsonSchemaField]>;
618
+ /**
619
+ * Validate a full form. `values` is the raw widget-value map (pre-coercion).
620
+ * Returns a `{ key: error }` map (empty when the form is valid).
621
+ */
622
+ declare function validateForm(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, string>;
623
+ /**
624
+ * Build the schema-typed `content` object to POST on submit. Only fields
625
+ * present in the schema are included; blank/undefined values are omitted.
626
+ */
627
+ declare function buildContent(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, unknown>;
628
+
478
629
  type UserActionResponse = {
479
630
  success: boolean;
480
631
  message: string;
481
632
  };
482
633
  /**
483
- * Submit a user action (e.g. OTP verification)
634
+ * Thrown when a resolution endpoint returns `404`
635
+ * (`user_action_not_found`): the prompt already resolved, expired, or
636
+ * the id is unknown. Callers should treat the prompt as no longer
637
+ * actionable — stop any countdown and clear the form — rather than
638
+ * surfacing this as a hard error.
639
+ */
640
+ declare class UserActionStaleError extends Error {
641
+ readonly userActionId: string;
642
+ constructor(userActionId: string, message?: string);
643
+ }
644
+ /**
645
+ * Submit a user action. `content` is the schema-typed form payload sent
646
+ * straight through to the agent (its keys should match the prompt's
647
+ * `requestedSchema.properties`) — e.g. `{ otp: "123456" }` for a
648
+ * verification prompt or `{ amount: 50, confirm: true }` for a form.
484
649
  */
485
- declare function submitUserAction(config: ChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
650
+ declare function submitUserAction(config: ChatConfig, userActionId: string, content?: Record<string, unknown>): Promise<UserActionResponse>;
486
651
  /**
487
652
  * Cancel / reject a user action
488
653
  */
@@ -492,4 +657,6 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
492
657
  */
493
658
  declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
494
659
 
495
- export { type APIConfig, type AgentStage, type AnalysisMode, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageFeedbackState, type MessageRole, type SendMessageOptions, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatV2Return, type UseVoiceReturn, type UserActionRequest, type UserActionResult, type UserActionState, type UserActionType, type V2EventProcessorState, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, buildFormattedThinking, cancelUserAction, createInitialV2State, generateId, processStreamEventV2, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice };
660
+ declare function migrateActiveStream(oldUserId: string, newUserId: string): void;
661
+
662
+ export { type APIConfig, type ActiveUserAction, type AgentStage, type AnalysisMode, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type FieldWidget, type JsonSchemaField, type JsonSchemaOption, type MessageDisplay, type MessageFeedbackState, type MessageRole, type RequestedSchema, type SendMessageOptions, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatV2Return, type UseVoiceReturn, type UserActionKind, type UserActionRequest, UserActionStaleError, type UserActionState, type UserActionStatus, type UserActionSubAction, type UserNotification, type V2EventProcessorState, type VerificationType, type VoiceCallbacks, type VoiceConfig, type VoicePermissions, type VoiceResult, type VoiceState, buildContent, buildFormattedThinking, cancelUserAction, classifyField, classifyUserActionKind, coerceValue, createInitialV2State, defaultValueFor, generateId, getOptions, isNestedOrUnsupported, isRequired, migrateActiveStream, processStreamEventV2, renderableFields, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice, validateField, validateForm };