@paymanai/payman-typescript-ask-sdk 4.0.9 → 4.0.13
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 +194 -47
- package/dist/index.d.ts +194 -47
- package/dist/index.js +506 -654
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +494 -654
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +509 -657
- package/dist/index.native.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
clearOtpTrigger: number;
|
|
153
|
+
prompts: ActiveUserAction[];
|
|
154
|
+
notifications: UserNotification[];
|
|
88
155
|
};
|
|
89
156
|
type StreamingStep = {
|
|
90
157
|
id: string;
|
|
@@ -131,20 +198,11 @@ type MessageDisplay = {
|
|
|
131
198
|
feedback?: MessageFeedbackState | null;
|
|
132
199
|
isStreaming?: boolean;
|
|
133
200
|
streamingContent?: string;
|
|
134
|
-
currentWorker?: string;
|
|
135
201
|
currentMessage?: string;
|
|
136
202
|
streamProgress?: StreamProgress;
|
|
137
203
|
steps?: StreamingStep[];
|
|
138
204
|
isCancelled?: boolean;
|
|
139
205
|
currentExecutingStepId?: string;
|
|
140
|
-
/** Result of user action (OTP approval/rejection) */
|
|
141
|
-
userActionResult?: UserActionResult;
|
|
142
|
-
/** Current thinking block text (live, resets per block) */
|
|
143
|
-
activeThinkingText?: string;
|
|
144
|
-
/** All thinking accumulated across blocks (for post-stream display) */
|
|
145
|
-
allThinkingText?: string;
|
|
146
|
-
/** Pre-formatted thinking text built from steps + allThinkingText (v2 streaming format, matches demo) */
|
|
147
|
-
formattedThinkingText?: string;
|
|
148
206
|
/** True while RAG image URLs are being resolved after the final response is shown */
|
|
149
207
|
isResolvingImages?: boolean;
|
|
150
208
|
/**
|
|
@@ -264,10 +322,14 @@ type ChatCallbacks = {
|
|
|
264
322
|
}) => void;
|
|
265
323
|
/** Called when session ID changes */
|
|
266
324
|
onSessionIdChange?: (sessionId: string) => void;
|
|
267
|
-
/**
|
|
325
|
+
/**
|
|
326
|
+
* Called when the agent raises a user-action prompt
|
|
327
|
+
* (`USER_ACTION_REQUIRED`). Fires for both new prompts and
|
|
328
|
+
* supersedes (a retry/resend that replaces an existing slot).
|
|
329
|
+
*/
|
|
268
330
|
onUserActionRequired?: (request: UserActionRequest) => void;
|
|
269
|
-
/** Called
|
|
270
|
-
|
|
331
|
+
/** Called when the agent pushes a one-way notification (`USER_NOTIFICATION`). */
|
|
332
|
+
onUserNotification?: (notification: UserNotification) => void;
|
|
271
333
|
/**
|
|
272
334
|
* Fires whenever the current streaming "status message" changes —
|
|
273
335
|
* the user-facing label for whatever stage is running right now
|
|
@@ -336,10 +398,19 @@ type UseChatV2Return = {
|
|
|
336
398
|
getMessages: () => MessageDisplay[];
|
|
337
399
|
isWaitingForResponse: boolean;
|
|
338
400
|
sessionId: string | undefined;
|
|
401
|
+
/** Active user-action prompts + one-way notifications for this chat. */
|
|
339
402
|
userActionState: UserActionState;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Submit a prompt's form payload. `content` keys should match the
|
|
405
|
+
* prompt's `requestedSchema.properties` (e.g. `{ otp: "123456" }`).
|
|
406
|
+
*/
|
|
407
|
+
submitUserAction: (userActionId: string, content: Record<string, unknown>) => Promise<void>;
|
|
408
|
+
/** Cancel / decline a prompt. */
|
|
409
|
+
cancelUserAction: (userActionId: string) => Promise<void>;
|
|
410
|
+
/** Ask the agent to re-send a prompt (e.g. resend a verification code). */
|
|
411
|
+
resendUserAction: (userActionId: string) => Promise<void>;
|
|
412
|
+
/** Dismiss a one-way notification from local state. */
|
|
413
|
+
dismissNotification: (id: string) => void;
|
|
343
414
|
};
|
|
344
415
|
declare function useChatV2(config: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
|
|
345
416
|
|
|
@@ -422,13 +493,20 @@ type StreamEvent = {
|
|
|
422
493
|
* "Thinking…" panel rather than the chat bubble.
|
|
423
494
|
*/
|
|
424
495
|
text?: string;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
496
|
+
/**
|
|
497
|
+
* User-action / elicitation fields, carried at the TOP LEVEL of a
|
|
498
|
+
* `USER_ACTION_REQUIRED` event (and `userActionId`/`message` on
|
|
499
|
+
* `USER_NOTIFICATION`). The MCP `_meta.action` kind is forwarded
|
|
500
|
+
* here as `action`; `requestedSchema` is standard JSON Schema.
|
|
501
|
+
*/
|
|
502
|
+
userActionId?: string;
|
|
503
|
+
action?: string;
|
|
504
|
+
subAction?: string;
|
|
505
|
+
verificationType?: string;
|
|
506
|
+
expirySeconds?: number;
|
|
507
|
+
requestedSchema?: Record<string, unknown>;
|
|
508
|
+
metadata?: Record<string, string>;
|
|
509
|
+
toolCallId?: string;
|
|
432
510
|
[key: string]: unknown;
|
|
433
511
|
};
|
|
434
512
|
type StreamOptions = {
|
|
@@ -443,28 +521,34 @@ type StreamOptions = {
|
|
|
443
521
|
declare function streamWorkflowEvents(url: string, body: Record<string, unknown>, headers: Record<string, string>, options?: StreamOptions): Promise<void>;
|
|
444
522
|
|
|
445
523
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* The SDK's `allThinkingText` only contains raw `INTENT_THINKING_CONT`
|
|
451
|
-
* deltas — no phase headers. This function reconstructs the full format
|
|
452
|
-
* from the steps array, which stores every event the SDK processes.
|
|
524
|
+
* Classify a `USER_ACTION_REQUIRED` event into a render kind. Primary
|
|
525
|
+
* discriminator is the MCP elicitation `action`; we fall back to the
|
|
526
|
+
* schema shape so unknown/legacy `action` tags still route correctly.
|
|
453
527
|
*/
|
|
454
|
-
declare function
|
|
455
|
-
|
|
528
|
+
declare function classifyUserActionKind(action: string | undefined, schema: RequestedSchema | undefined): UserActionKind;
|
|
456
529
|
type V2EventProcessorState = {
|
|
457
|
-
formattedThinkingText: string;
|
|
458
530
|
finalResponse: string;
|
|
459
|
-
currentWorker: string;
|
|
460
531
|
lastEventType: string;
|
|
461
532
|
sessionId?: string;
|
|
462
533
|
executionId?: string;
|
|
463
534
|
hasError: boolean;
|
|
464
535
|
errorMessage: string;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
536
|
+
/**
|
|
537
|
+
* Active user-action prompts, an ordered collection keyed by
|
|
538
|
+
* `toolCallId` (fallback `userActionId`). Usually 0–1 for serial
|
|
539
|
+
* runs; multiple when parallel tool calls each elicit.
|
|
540
|
+
*/
|
|
541
|
+
userActions: ActiveUserAction[];
|
|
542
|
+
/** One-way notifications surfaced this run (`USER_NOTIFICATION`). */
|
|
543
|
+
notifications: UserNotification[];
|
|
544
|
+
/**
|
|
545
|
+
* Transient: the prompt upserted by the most recent
|
|
546
|
+
* `USER_ACTION_REQUIRED` event, so the stream manager can fire
|
|
547
|
+
* `onUserActionRequired` for exactly that prompt. Reset each event.
|
|
548
|
+
*/
|
|
549
|
+
lastUserAction?: UserActionRequest;
|
|
550
|
+
/** Transient: the notification pushed by the most recent event. */
|
|
551
|
+
lastNotification?: UserNotification;
|
|
468
552
|
finalData?: unknown;
|
|
469
553
|
steps: StreamingStep[];
|
|
470
554
|
stepCounter: number;
|
|
@@ -475,14 +559,75 @@ type V2EventProcessorState = {
|
|
|
475
559
|
declare function createInitialV2State(): V2EventProcessorState;
|
|
476
560
|
declare function processStreamEventV2(rawEvent: StreamEvent, state: V2EventProcessorState): V2EventProcessorState;
|
|
477
561
|
|
|
562
|
+
/** The widget kinds the renderer knows how to draw. */
|
|
563
|
+
type FieldWidget = "text" | "integer" | "decimal" | "boolean" | "select";
|
|
564
|
+
/**
|
|
565
|
+
* Classify a schema field into a widget kind. `oneOf` always wins
|
|
566
|
+
* (titled single-select), then `type`. Anything unrecognized — or a
|
|
567
|
+
* missing type — degrades to a plain text input.
|
|
568
|
+
*/
|
|
569
|
+
declare function classifyField(field: JsonSchemaField | undefined): FieldWidget;
|
|
570
|
+
/**
|
|
571
|
+
* Fields we can't render as a flat primitive (nested objects, arrays,
|
|
572
|
+
* tuple/composite schemas). The renderer should skip these rather than
|
|
573
|
+
* attempt a best-effort input. `oneOf` is NOT considered unsupported —
|
|
574
|
+
* it's our single-select shape.
|
|
575
|
+
*/
|
|
576
|
+
declare function isNestedOrUnsupported(field: JsonSchemaField | undefined): boolean;
|
|
577
|
+
/** Normalize a field's `oneOf` into a clean option list (drops malformed entries). */
|
|
578
|
+
declare function getOptions(field: JsonSchemaField | undefined): JsonSchemaOption[];
|
|
579
|
+
/** Is `key` required per the schema's `required` array? */
|
|
580
|
+
declare function isRequired(schema: RequestedSchema | undefined, key: string): boolean;
|
|
581
|
+
/**
|
|
582
|
+
* Coerce a raw widget value into the JSON type the schema declares, so
|
|
583
|
+
* the submitted `content` round-trips cleanly. Empty/blank values become
|
|
584
|
+
* `undefined` (the field is simply omitted from the payload). The server
|
|
585
|
+
* is tolerant of strings, but matching types keeps things clean.
|
|
586
|
+
*/
|
|
587
|
+
declare function coerceValue(field: JsonSchemaField | undefined, raw: unknown): unknown;
|
|
588
|
+
/** Pre-fill value for a field's widget, from `default` (typed loosely for inputs). */
|
|
589
|
+
declare function defaultValueFor(field: JsonSchemaField | undefined): unknown;
|
|
590
|
+
/**
|
|
591
|
+
* Validate a single field's coerced value. Returns an error string or
|
|
592
|
+
* `null` when valid. Only the documented keywords are enforced; unknown
|
|
593
|
+
* keywords are ignored.
|
|
594
|
+
*/
|
|
595
|
+
declare function validateField(field: JsonSchemaField | undefined, value: unknown, required: boolean): string | null;
|
|
596
|
+
/** Ordered list of renderable [key, field] pairs (skips unsupported fields). */
|
|
597
|
+
declare function renderableFields(schema: RequestedSchema | undefined): Array<[string, JsonSchemaField]>;
|
|
598
|
+
/**
|
|
599
|
+
* Validate a full form. `values` is the raw widget-value map (pre-coercion).
|
|
600
|
+
* Returns a `{ key: error }` map (empty when the form is valid).
|
|
601
|
+
*/
|
|
602
|
+
declare function validateForm(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, string>;
|
|
603
|
+
/**
|
|
604
|
+
* Build the schema-typed `content` object to POST on submit. Only fields
|
|
605
|
+
* present in the schema are included; blank/undefined values are omitted.
|
|
606
|
+
*/
|
|
607
|
+
declare function buildContent(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, unknown>;
|
|
608
|
+
|
|
478
609
|
type UserActionResponse = {
|
|
479
610
|
success: boolean;
|
|
480
611
|
message: string;
|
|
481
612
|
};
|
|
482
613
|
/**
|
|
483
|
-
*
|
|
614
|
+
* Thrown when a resolution endpoint returns `404`
|
|
615
|
+
* (`user_action_not_found`): the prompt already resolved, expired, or
|
|
616
|
+
* the id is unknown. Callers should treat the prompt as no longer
|
|
617
|
+
* actionable — stop any countdown and clear the form — rather than
|
|
618
|
+
* surfacing this as a hard error.
|
|
619
|
+
*/
|
|
620
|
+
declare class UserActionStaleError extends Error {
|
|
621
|
+
readonly userActionId: string;
|
|
622
|
+
constructor(userActionId: string, message?: string);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Submit a user action. `content` is the schema-typed form payload sent
|
|
626
|
+
* straight through to the agent (its keys should match the prompt's
|
|
627
|
+
* `requestedSchema.properties`) — e.g. `{ otp: "123456" }` for a
|
|
628
|
+
* verification prompt or `{ amount: 50, confirm: true }` for a form.
|
|
484
629
|
*/
|
|
485
|
-
declare function submitUserAction(config: ChatConfig, userActionId: string,
|
|
630
|
+
declare function submitUserAction(config: ChatConfig, userActionId: string, content?: Record<string, unknown>): Promise<UserActionResponse>;
|
|
486
631
|
/**
|
|
487
632
|
* Cancel / reject a user action
|
|
488
633
|
*/
|
|
@@ -492,4 +637,6 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
|
|
|
492
637
|
*/
|
|
493
638
|
declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
494
639
|
|
|
495
|
-
|
|
640
|
+
declare function migrateActiveStream(oldUserId: string, newUserId: string): void;
|
|
641
|
+
|
|
642
|
+
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, 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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
clearOtpTrigger: number;
|
|
153
|
+
prompts: ActiveUserAction[];
|
|
154
|
+
notifications: UserNotification[];
|
|
88
155
|
};
|
|
89
156
|
type StreamingStep = {
|
|
90
157
|
id: string;
|
|
@@ -131,20 +198,11 @@ type MessageDisplay = {
|
|
|
131
198
|
feedback?: MessageFeedbackState | null;
|
|
132
199
|
isStreaming?: boolean;
|
|
133
200
|
streamingContent?: string;
|
|
134
|
-
currentWorker?: string;
|
|
135
201
|
currentMessage?: string;
|
|
136
202
|
streamProgress?: StreamProgress;
|
|
137
203
|
steps?: StreamingStep[];
|
|
138
204
|
isCancelled?: boolean;
|
|
139
205
|
currentExecutingStepId?: string;
|
|
140
|
-
/** Result of user action (OTP approval/rejection) */
|
|
141
|
-
userActionResult?: UserActionResult;
|
|
142
|
-
/** Current thinking block text (live, resets per block) */
|
|
143
|
-
activeThinkingText?: string;
|
|
144
|
-
/** All thinking accumulated across blocks (for post-stream display) */
|
|
145
|
-
allThinkingText?: string;
|
|
146
|
-
/** Pre-formatted thinking text built from steps + allThinkingText (v2 streaming format, matches demo) */
|
|
147
|
-
formattedThinkingText?: string;
|
|
148
206
|
/** True while RAG image URLs are being resolved after the final response is shown */
|
|
149
207
|
isResolvingImages?: boolean;
|
|
150
208
|
/**
|
|
@@ -264,10 +322,14 @@ type ChatCallbacks = {
|
|
|
264
322
|
}) => void;
|
|
265
323
|
/** Called when session ID changes */
|
|
266
324
|
onSessionIdChange?: (sessionId: string) => void;
|
|
267
|
-
/**
|
|
325
|
+
/**
|
|
326
|
+
* Called when the agent raises a user-action prompt
|
|
327
|
+
* (`USER_ACTION_REQUIRED`). Fires for both new prompts and
|
|
328
|
+
* supersedes (a retry/resend that replaces an existing slot).
|
|
329
|
+
*/
|
|
268
330
|
onUserActionRequired?: (request: UserActionRequest) => void;
|
|
269
|
-
/** Called
|
|
270
|
-
|
|
331
|
+
/** Called when the agent pushes a one-way notification (`USER_NOTIFICATION`). */
|
|
332
|
+
onUserNotification?: (notification: UserNotification) => void;
|
|
271
333
|
/**
|
|
272
334
|
* Fires whenever the current streaming "status message" changes —
|
|
273
335
|
* the user-facing label for whatever stage is running right now
|
|
@@ -336,10 +398,19 @@ type UseChatV2Return = {
|
|
|
336
398
|
getMessages: () => MessageDisplay[];
|
|
337
399
|
isWaitingForResponse: boolean;
|
|
338
400
|
sessionId: string | undefined;
|
|
401
|
+
/** Active user-action prompts + one-way notifications for this chat. */
|
|
339
402
|
userActionState: UserActionState;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Submit a prompt's form payload. `content` keys should match the
|
|
405
|
+
* prompt's `requestedSchema.properties` (e.g. `{ otp: "123456" }`).
|
|
406
|
+
*/
|
|
407
|
+
submitUserAction: (userActionId: string, content: Record<string, unknown>) => Promise<void>;
|
|
408
|
+
/** Cancel / decline a prompt. */
|
|
409
|
+
cancelUserAction: (userActionId: string) => Promise<void>;
|
|
410
|
+
/** Ask the agent to re-send a prompt (e.g. resend a verification code). */
|
|
411
|
+
resendUserAction: (userActionId: string) => Promise<void>;
|
|
412
|
+
/** Dismiss a one-way notification from local state. */
|
|
413
|
+
dismissNotification: (id: string) => void;
|
|
343
414
|
};
|
|
344
415
|
declare function useChatV2(config: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
|
|
345
416
|
|
|
@@ -422,13 +493,20 @@ type StreamEvent = {
|
|
|
422
493
|
* "Thinking…" panel rather than the chat bubble.
|
|
423
494
|
*/
|
|
424
495
|
text?: string;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
496
|
+
/**
|
|
497
|
+
* User-action / elicitation fields, carried at the TOP LEVEL of a
|
|
498
|
+
* `USER_ACTION_REQUIRED` event (and `userActionId`/`message` on
|
|
499
|
+
* `USER_NOTIFICATION`). The MCP `_meta.action` kind is forwarded
|
|
500
|
+
* here as `action`; `requestedSchema` is standard JSON Schema.
|
|
501
|
+
*/
|
|
502
|
+
userActionId?: string;
|
|
503
|
+
action?: string;
|
|
504
|
+
subAction?: string;
|
|
505
|
+
verificationType?: string;
|
|
506
|
+
expirySeconds?: number;
|
|
507
|
+
requestedSchema?: Record<string, unknown>;
|
|
508
|
+
metadata?: Record<string, string>;
|
|
509
|
+
toolCallId?: string;
|
|
432
510
|
[key: string]: unknown;
|
|
433
511
|
};
|
|
434
512
|
type StreamOptions = {
|
|
@@ -443,28 +521,34 @@ type StreamOptions = {
|
|
|
443
521
|
declare function streamWorkflowEvents(url: string, body: Record<string, unknown>, headers: Record<string, string>, options?: StreamOptions): Promise<void>;
|
|
444
522
|
|
|
445
523
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* The SDK's `allThinkingText` only contains raw `INTENT_THINKING_CONT`
|
|
451
|
-
* deltas — no phase headers. This function reconstructs the full format
|
|
452
|
-
* from the steps array, which stores every event the SDK processes.
|
|
524
|
+
* Classify a `USER_ACTION_REQUIRED` event into a render kind. Primary
|
|
525
|
+
* discriminator is the MCP elicitation `action`; we fall back to the
|
|
526
|
+
* schema shape so unknown/legacy `action` tags still route correctly.
|
|
453
527
|
*/
|
|
454
|
-
declare function
|
|
455
|
-
|
|
528
|
+
declare function classifyUserActionKind(action: string | undefined, schema: RequestedSchema | undefined): UserActionKind;
|
|
456
529
|
type V2EventProcessorState = {
|
|
457
|
-
formattedThinkingText: string;
|
|
458
530
|
finalResponse: string;
|
|
459
|
-
currentWorker: string;
|
|
460
531
|
lastEventType: string;
|
|
461
532
|
sessionId?: string;
|
|
462
533
|
executionId?: string;
|
|
463
534
|
hasError: boolean;
|
|
464
535
|
errorMessage: string;
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
536
|
+
/**
|
|
537
|
+
* Active user-action prompts, an ordered collection keyed by
|
|
538
|
+
* `toolCallId` (fallback `userActionId`). Usually 0–1 for serial
|
|
539
|
+
* runs; multiple when parallel tool calls each elicit.
|
|
540
|
+
*/
|
|
541
|
+
userActions: ActiveUserAction[];
|
|
542
|
+
/** One-way notifications surfaced this run (`USER_NOTIFICATION`). */
|
|
543
|
+
notifications: UserNotification[];
|
|
544
|
+
/**
|
|
545
|
+
* Transient: the prompt upserted by the most recent
|
|
546
|
+
* `USER_ACTION_REQUIRED` event, so the stream manager can fire
|
|
547
|
+
* `onUserActionRequired` for exactly that prompt. Reset each event.
|
|
548
|
+
*/
|
|
549
|
+
lastUserAction?: UserActionRequest;
|
|
550
|
+
/** Transient: the notification pushed by the most recent event. */
|
|
551
|
+
lastNotification?: UserNotification;
|
|
468
552
|
finalData?: unknown;
|
|
469
553
|
steps: StreamingStep[];
|
|
470
554
|
stepCounter: number;
|
|
@@ -475,14 +559,75 @@ type V2EventProcessorState = {
|
|
|
475
559
|
declare function createInitialV2State(): V2EventProcessorState;
|
|
476
560
|
declare function processStreamEventV2(rawEvent: StreamEvent, state: V2EventProcessorState): V2EventProcessorState;
|
|
477
561
|
|
|
562
|
+
/** The widget kinds the renderer knows how to draw. */
|
|
563
|
+
type FieldWidget = "text" | "integer" | "decimal" | "boolean" | "select";
|
|
564
|
+
/**
|
|
565
|
+
* Classify a schema field into a widget kind. `oneOf` always wins
|
|
566
|
+
* (titled single-select), then `type`. Anything unrecognized — or a
|
|
567
|
+
* missing type — degrades to a plain text input.
|
|
568
|
+
*/
|
|
569
|
+
declare function classifyField(field: JsonSchemaField | undefined): FieldWidget;
|
|
570
|
+
/**
|
|
571
|
+
* Fields we can't render as a flat primitive (nested objects, arrays,
|
|
572
|
+
* tuple/composite schemas). The renderer should skip these rather than
|
|
573
|
+
* attempt a best-effort input. `oneOf` is NOT considered unsupported —
|
|
574
|
+
* it's our single-select shape.
|
|
575
|
+
*/
|
|
576
|
+
declare function isNestedOrUnsupported(field: JsonSchemaField | undefined): boolean;
|
|
577
|
+
/** Normalize a field's `oneOf` into a clean option list (drops malformed entries). */
|
|
578
|
+
declare function getOptions(field: JsonSchemaField | undefined): JsonSchemaOption[];
|
|
579
|
+
/** Is `key` required per the schema's `required` array? */
|
|
580
|
+
declare function isRequired(schema: RequestedSchema | undefined, key: string): boolean;
|
|
581
|
+
/**
|
|
582
|
+
* Coerce a raw widget value into the JSON type the schema declares, so
|
|
583
|
+
* the submitted `content` round-trips cleanly. Empty/blank values become
|
|
584
|
+
* `undefined` (the field is simply omitted from the payload). The server
|
|
585
|
+
* is tolerant of strings, but matching types keeps things clean.
|
|
586
|
+
*/
|
|
587
|
+
declare function coerceValue(field: JsonSchemaField | undefined, raw: unknown): unknown;
|
|
588
|
+
/** Pre-fill value for a field's widget, from `default` (typed loosely for inputs). */
|
|
589
|
+
declare function defaultValueFor(field: JsonSchemaField | undefined): unknown;
|
|
590
|
+
/**
|
|
591
|
+
* Validate a single field's coerced value. Returns an error string or
|
|
592
|
+
* `null` when valid. Only the documented keywords are enforced; unknown
|
|
593
|
+
* keywords are ignored.
|
|
594
|
+
*/
|
|
595
|
+
declare function validateField(field: JsonSchemaField | undefined, value: unknown, required: boolean): string | null;
|
|
596
|
+
/** Ordered list of renderable [key, field] pairs (skips unsupported fields). */
|
|
597
|
+
declare function renderableFields(schema: RequestedSchema | undefined): Array<[string, JsonSchemaField]>;
|
|
598
|
+
/**
|
|
599
|
+
* Validate a full form. `values` is the raw widget-value map (pre-coercion).
|
|
600
|
+
* Returns a `{ key: error }` map (empty when the form is valid).
|
|
601
|
+
*/
|
|
602
|
+
declare function validateForm(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, string>;
|
|
603
|
+
/**
|
|
604
|
+
* Build the schema-typed `content` object to POST on submit. Only fields
|
|
605
|
+
* present in the schema are included; blank/undefined values are omitted.
|
|
606
|
+
*/
|
|
607
|
+
declare function buildContent(schema: RequestedSchema | undefined, values: Record<string, unknown>): Record<string, unknown>;
|
|
608
|
+
|
|
478
609
|
type UserActionResponse = {
|
|
479
610
|
success: boolean;
|
|
480
611
|
message: string;
|
|
481
612
|
};
|
|
482
613
|
/**
|
|
483
|
-
*
|
|
614
|
+
* Thrown when a resolution endpoint returns `404`
|
|
615
|
+
* (`user_action_not_found`): the prompt already resolved, expired, or
|
|
616
|
+
* the id is unknown. Callers should treat the prompt as no longer
|
|
617
|
+
* actionable — stop any countdown and clear the form — rather than
|
|
618
|
+
* surfacing this as a hard error.
|
|
619
|
+
*/
|
|
620
|
+
declare class UserActionStaleError extends Error {
|
|
621
|
+
readonly userActionId: string;
|
|
622
|
+
constructor(userActionId: string, message?: string);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Submit a user action. `content` is the schema-typed form payload sent
|
|
626
|
+
* straight through to the agent (its keys should match the prompt's
|
|
627
|
+
* `requestedSchema.properties`) — e.g. `{ otp: "123456" }` for a
|
|
628
|
+
* verification prompt or `{ amount: 50, confirm: true }` for a form.
|
|
484
629
|
*/
|
|
485
|
-
declare function submitUserAction(config: ChatConfig, userActionId: string,
|
|
630
|
+
declare function submitUserAction(config: ChatConfig, userActionId: string, content?: Record<string, unknown>): Promise<UserActionResponse>;
|
|
486
631
|
/**
|
|
487
632
|
* Cancel / reject a user action
|
|
488
633
|
*/
|
|
@@ -492,4 +637,6 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
|
|
|
492
637
|
*/
|
|
493
638
|
declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
494
639
|
|
|
495
|
-
|
|
640
|
+
declare function migrateActiveStream(oldUserId: string, newUserId: string): void;
|
|
641
|
+
|
|
642
|
+
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, cancelUserAction, classifyField, classifyUserActionKind, coerceValue, createInitialV2State, defaultValueFor, generateId, getOptions, isNestedOrUnsupported, isRequired, migrateActiveStream, processStreamEventV2, renderableFields, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice, validateField, validateForm };
|