@paymanai/payman-typescript-ask-sdk 4.0.8 → 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 +202 -29
- package/dist/index.d.ts +202 -29
- package/dist/index.js +392 -292
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +380 -293
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +392 -292
- 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;
|
|
82
134
|
};
|
|
83
|
-
|
|
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;
|
|
145
|
+
};
|
|
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;
|
|
@@ -112,6 +179,7 @@ type ChunkDisplay = {
|
|
|
112
179
|
similarityScore?: number;
|
|
113
180
|
rrfScore?: number;
|
|
114
181
|
};
|
|
182
|
+
type MessageFeedbackState = "up" | "down";
|
|
115
183
|
type MessageDisplay = {
|
|
116
184
|
id: string;
|
|
117
185
|
sessionId?: string;
|
|
@@ -123,6 +191,11 @@ type MessageDisplay = {
|
|
|
123
191
|
chunks?: ChunkDisplay[];
|
|
124
192
|
tracingData?: unknown;
|
|
125
193
|
executionId?: string;
|
|
194
|
+
/**
|
|
195
|
+
* Existing end-user feedback for this assistant response. Hydrated from
|
|
196
|
+
* execution history so clients can render the selected thumb as active.
|
|
197
|
+
*/
|
|
198
|
+
feedback?: MessageFeedbackState | null;
|
|
126
199
|
isStreaming?: boolean;
|
|
127
200
|
streamingContent?: string;
|
|
128
201
|
currentWorker?: string;
|
|
@@ -131,8 +204,6 @@ type MessageDisplay = {
|
|
|
131
204
|
steps?: StreamingStep[];
|
|
132
205
|
isCancelled?: boolean;
|
|
133
206
|
currentExecutingStepId?: string;
|
|
134
|
-
/** Result of user action (OTP approval/rejection) */
|
|
135
|
-
userActionResult?: UserActionResult;
|
|
136
207
|
/** Current thinking block text (live, resets per block) */
|
|
137
208
|
activeThinkingText?: string;
|
|
138
209
|
/** All thinking accumulated across blocks (for post-stream display) */
|
|
@@ -258,10 +329,14 @@ type ChatCallbacks = {
|
|
|
258
329
|
}) => void;
|
|
259
330
|
/** Called when session ID changes */
|
|
260
331
|
onSessionIdChange?: (sessionId: string) => void;
|
|
261
|
-
/**
|
|
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
|
+
*/
|
|
262
337
|
onUserActionRequired?: (request: UserActionRequest) => void;
|
|
263
|
-
/** Called
|
|
264
|
-
|
|
338
|
+
/** Called when the agent pushes a one-way notification (`USER_NOTIFICATION`). */
|
|
339
|
+
onUserNotification?: (notification: UserNotification) => void;
|
|
265
340
|
/**
|
|
266
341
|
* Fires whenever the current streaming "status message" changes —
|
|
267
342
|
* the user-facing label for whatever stage is running right now
|
|
@@ -330,10 +405,19 @@ type UseChatV2Return = {
|
|
|
330
405
|
getMessages: () => MessageDisplay[];
|
|
331
406
|
isWaitingForResponse: boolean;
|
|
332
407
|
sessionId: string | undefined;
|
|
408
|
+
/** Active user-action prompts + one-way notifications for this chat. */
|
|
333
409
|
userActionState: UserActionState;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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;
|
|
337
421
|
};
|
|
338
422
|
declare function useChatV2(config: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
|
|
339
423
|
|
|
@@ -416,13 +500,20 @@ type StreamEvent = {
|
|
|
416
500
|
* "Thinking…" panel rather than the chat bubble.
|
|
417
501
|
*/
|
|
418
502
|
text?: string;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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;
|
|
426
517
|
[key: string]: unknown;
|
|
427
518
|
};
|
|
428
519
|
type StreamOptions = {
|
|
@@ -447,6 +538,12 @@ declare function streamWorkflowEvents(url: string, body: Record<string, unknown>
|
|
|
447
538
|
*/
|
|
448
539
|
declare function buildFormattedThinking(steps: StreamingStep[] | undefined, allThinkingText: string): string;
|
|
449
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;
|
|
450
547
|
type V2EventProcessorState = {
|
|
451
548
|
formattedThinkingText: string;
|
|
452
549
|
finalResponse: string;
|
|
@@ -456,9 +553,22 @@ type V2EventProcessorState = {
|
|
|
456
553
|
executionId?: string;
|
|
457
554
|
hasError: boolean;
|
|
458
555
|
errorMessage: string;
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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;
|
|
462
572
|
finalData?: unknown;
|
|
463
573
|
steps: StreamingStep[];
|
|
464
574
|
stepCounter: number;
|
|
@@ -469,14 +579,75 @@ type V2EventProcessorState = {
|
|
|
469
579
|
declare function createInitialV2State(): V2EventProcessorState;
|
|
470
580
|
declare function processStreamEventV2(rawEvent: StreamEvent, state: V2EventProcessorState): V2EventProcessorState;
|
|
471
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
|
+
|
|
472
629
|
type UserActionResponse = {
|
|
473
630
|
success: boolean;
|
|
474
631
|
message: string;
|
|
475
632
|
};
|
|
476
633
|
/**
|
|
477
|
-
*
|
|
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.
|
|
478
649
|
*/
|
|
479
|
-
declare function submitUserAction(config: ChatConfig, userActionId: string,
|
|
650
|
+
declare function submitUserAction(config: ChatConfig, userActionId: string, content?: Record<string, unknown>): Promise<UserActionResponse>;
|
|
480
651
|
/**
|
|
481
652
|
* Cancel / reject a user action
|
|
482
653
|
*/
|
|
@@ -486,4 +657,6 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
|
|
|
486
657
|
*/
|
|
487
658
|
declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
488
659
|
|
|
489
|
-
|
|
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
|
-
|
|
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;
|
|
82
134
|
};
|
|
83
|
-
|
|
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;
|
|
145
|
+
};
|
|
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;
|
|
@@ -112,6 +179,7 @@ type ChunkDisplay = {
|
|
|
112
179
|
similarityScore?: number;
|
|
113
180
|
rrfScore?: number;
|
|
114
181
|
};
|
|
182
|
+
type MessageFeedbackState = "up" | "down";
|
|
115
183
|
type MessageDisplay = {
|
|
116
184
|
id: string;
|
|
117
185
|
sessionId?: string;
|
|
@@ -123,6 +191,11 @@ type MessageDisplay = {
|
|
|
123
191
|
chunks?: ChunkDisplay[];
|
|
124
192
|
tracingData?: unknown;
|
|
125
193
|
executionId?: string;
|
|
194
|
+
/**
|
|
195
|
+
* Existing end-user feedback for this assistant response. Hydrated from
|
|
196
|
+
* execution history so clients can render the selected thumb as active.
|
|
197
|
+
*/
|
|
198
|
+
feedback?: MessageFeedbackState | null;
|
|
126
199
|
isStreaming?: boolean;
|
|
127
200
|
streamingContent?: string;
|
|
128
201
|
currentWorker?: string;
|
|
@@ -131,8 +204,6 @@ type MessageDisplay = {
|
|
|
131
204
|
steps?: StreamingStep[];
|
|
132
205
|
isCancelled?: boolean;
|
|
133
206
|
currentExecutingStepId?: string;
|
|
134
|
-
/** Result of user action (OTP approval/rejection) */
|
|
135
|
-
userActionResult?: UserActionResult;
|
|
136
207
|
/** Current thinking block text (live, resets per block) */
|
|
137
208
|
activeThinkingText?: string;
|
|
138
209
|
/** All thinking accumulated across blocks (for post-stream display) */
|
|
@@ -258,10 +329,14 @@ type ChatCallbacks = {
|
|
|
258
329
|
}) => void;
|
|
259
330
|
/** Called when session ID changes */
|
|
260
331
|
onSessionIdChange?: (sessionId: string) => void;
|
|
261
|
-
/**
|
|
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
|
+
*/
|
|
262
337
|
onUserActionRequired?: (request: UserActionRequest) => void;
|
|
263
|
-
/** Called
|
|
264
|
-
|
|
338
|
+
/** Called when the agent pushes a one-way notification (`USER_NOTIFICATION`). */
|
|
339
|
+
onUserNotification?: (notification: UserNotification) => void;
|
|
265
340
|
/**
|
|
266
341
|
* Fires whenever the current streaming "status message" changes —
|
|
267
342
|
* the user-facing label for whatever stage is running right now
|
|
@@ -330,10 +405,19 @@ type UseChatV2Return = {
|
|
|
330
405
|
getMessages: () => MessageDisplay[];
|
|
331
406
|
isWaitingForResponse: boolean;
|
|
332
407
|
sessionId: string | undefined;
|
|
408
|
+
/** Active user-action prompts + one-way notifications for this chat. */
|
|
333
409
|
userActionState: UserActionState;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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;
|
|
337
421
|
};
|
|
338
422
|
declare function useChatV2(config: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
|
|
339
423
|
|
|
@@ -416,13 +500,20 @@ type StreamEvent = {
|
|
|
416
500
|
* "Thinking…" panel rather than the chat bubble.
|
|
417
501
|
*/
|
|
418
502
|
text?: string;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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;
|
|
426
517
|
[key: string]: unknown;
|
|
427
518
|
};
|
|
428
519
|
type StreamOptions = {
|
|
@@ -447,6 +538,12 @@ declare function streamWorkflowEvents(url: string, body: Record<string, unknown>
|
|
|
447
538
|
*/
|
|
448
539
|
declare function buildFormattedThinking(steps: StreamingStep[] | undefined, allThinkingText: string): string;
|
|
449
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;
|
|
450
547
|
type V2EventProcessorState = {
|
|
451
548
|
formattedThinkingText: string;
|
|
452
549
|
finalResponse: string;
|
|
@@ -456,9 +553,22 @@ type V2EventProcessorState = {
|
|
|
456
553
|
executionId?: string;
|
|
457
554
|
hasError: boolean;
|
|
458
555
|
errorMessage: string;
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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;
|
|
462
572
|
finalData?: unknown;
|
|
463
573
|
steps: StreamingStep[];
|
|
464
574
|
stepCounter: number;
|
|
@@ -469,14 +579,75 @@ type V2EventProcessorState = {
|
|
|
469
579
|
declare function createInitialV2State(): V2EventProcessorState;
|
|
470
580
|
declare function processStreamEventV2(rawEvent: StreamEvent, state: V2EventProcessorState): V2EventProcessorState;
|
|
471
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
|
+
|
|
472
629
|
type UserActionResponse = {
|
|
473
630
|
success: boolean;
|
|
474
631
|
message: string;
|
|
475
632
|
};
|
|
476
633
|
/**
|
|
477
|
-
*
|
|
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.
|
|
478
649
|
*/
|
|
479
|
-
declare function submitUserAction(config: ChatConfig, userActionId: string,
|
|
650
|
+
declare function submitUserAction(config: ChatConfig, userActionId: string, content?: Record<string, unknown>): Promise<UserActionResponse>;
|
|
480
651
|
/**
|
|
481
652
|
* Cancel / reject a user action
|
|
482
653
|
*/
|
|
@@ -486,4 +657,6 @@ declare function cancelUserAction(config: ChatConfig, userActionId: string): Pro
|
|
|
486
657
|
*/
|
|
487
658
|
declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
488
659
|
|
|
489
|
-
|
|
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 };
|