@paymanai/payman-typescript-ask-sdk 1.2.10 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +141 -108
- package/dist/index.d.ts +141 -108
- package/dist/index.js +551 -1189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +549 -1190
- package/dist/index.mjs.map +1 -1
- package/dist/index.native.js +553 -1191
- package/dist/index.native.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
1
|
type VoiceState = "idle" | "listening" | "processing" | "error";
|
|
4
2
|
type VoiceConfig = {
|
|
5
3
|
/** Language for speech recognition (default: "en-US") */
|
|
@@ -120,146 +118,116 @@ type MessageDisplay = {
|
|
|
120
118
|
steps?: StreamingStep[];
|
|
121
119
|
isCancelled?: boolean;
|
|
122
120
|
currentExecutingStepId?: string;
|
|
123
|
-
/** Result of user action (OTP approval/rejection) */
|
|
124
121
|
userActionResult?: UserActionResult;
|
|
125
|
-
/** Current thinking block text (live, resets per block) */
|
|
126
122
|
activeThinkingText?: string;
|
|
127
|
-
/** All thinking accumulated across blocks (for post-stream display) */
|
|
128
123
|
allThinkingText?: string;
|
|
129
|
-
/** Pre-formatted thinking text built from steps + allThinkingText (v2 streaming format, matches demo) */
|
|
130
124
|
formattedThinkingText?: string;
|
|
131
|
-
/** True while RAG image URLs are being resolved after the final response is shown */
|
|
132
125
|
isResolvingImages?: boolean;
|
|
126
|
+
/** History row loaded via loadSession(). Renderers skip streaming/step UI. */
|
|
127
|
+
isHistorical?: boolean;
|
|
133
128
|
};
|
|
134
|
-
type
|
|
129
|
+
type SessionOwner = {
|
|
130
|
+
/** Sent as sessionOwnerId in the request body. */
|
|
135
131
|
id?: string;
|
|
132
|
+
/** Sent as sessionOwnerLabel in the request body. */
|
|
136
133
|
name?: string;
|
|
134
|
+
/** Sent as sessionAttributes in the request body. */
|
|
137
135
|
attributes?: Record<string, string>;
|
|
138
136
|
};
|
|
139
137
|
type APIConfig = {
|
|
140
|
-
/** Base API URL */
|
|
141
138
|
baseUrl: string;
|
|
142
|
-
/** Auth token */
|
|
143
139
|
authToken?: string;
|
|
144
|
-
/** Custom headers */
|
|
145
140
|
headers?: Record<string, string>;
|
|
146
|
-
/**
|
|
141
|
+
/** Default: /api/workflows/ask/stream */
|
|
147
142
|
streamEndpoint?: string;
|
|
148
|
-
/**
|
|
143
|
+
/** Derived from streamEndpoint when omitted. */
|
|
149
144
|
resolveImagesEndpoint?: string;
|
|
145
|
+
/** Default: "stage". Davis overrides to "workflowStage". */
|
|
146
|
+
stageQueryParam?: string;
|
|
150
147
|
};
|
|
151
|
-
type
|
|
152
|
-
/** API configuration - required for the library to make calls */
|
|
148
|
+
type BaseChatConfig = {
|
|
153
149
|
api: APIConfig;
|
|
154
|
-
|
|
150
|
+
workflow: {
|
|
151
|
+
/** Workflow uuid. Required when ui.sessionHistory is enabled. Contributes to the state-scope key. */
|
|
152
|
+
id?: string;
|
|
153
|
+
name: string;
|
|
154
|
+
version?: number;
|
|
155
|
+
stage?: WorkflowStage;
|
|
156
|
+
};
|
|
157
|
+
session?: {
|
|
158
|
+
/** Client-side chatStore scoping (not sent to API). Clear on logout. */
|
|
159
|
+
userId?: string;
|
|
160
|
+
owner?: SessionOwner;
|
|
161
|
+
/** Default true. */
|
|
162
|
+
autoGenerateId?: boolean;
|
|
163
|
+
initialId?: string;
|
|
164
|
+
initialMessages?: MessageDisplay[];
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
type SessionSummary = {
|
|
168
|
+
userId: string;
|
|
169
|
+
userLabel: string;
|
|
170
|
+
sessionId: string;
|
|
171
|
+
workflowId: string;
|
|
155
172
|
workflowName: string;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
layout?: "centered" | "full-width";
|
|
194
|
-
/** Show timestamps on messages */
|
|
195
|
-
showTimestamps?: boolean;
|
|
196
|
-
/** Enable animations */
|
|
197
|
-
animated?: boolean;
|
|
198
|
-
/** Disable input */
|
|
199
|
-
disableInput?: boolean;
|
|
200
|
-
/** Has permission to ask */
|
|
201
|
-
hasAskPermission?: boolean;
|
|
202
|
-
/** Auto-generate session ID */
|
|
203
|
-
autoGenerateSessionId?: boolean;
|
|
204
|
-
/** Disable the entire chat and show disabled state */
|
|
205
|
-
isChatDisabled?: boolean;
|
|
206
|
-
/** Custom component to render when chat is disabled. If not provided, default disabled UI will be shown */
|
|
207
|
-
disabledComponent?: React.ReactNode;
|
|
208
|
-
/** Pre-populate the chat with messages (e.g. loaded conversation history) */
|
|
209
|
-
initialMessages?: MessageDisplay[];
|
|
210
|
-
/** Resume an existing session by providing its ID */
|
|
211
|
-
initialSessionId?: string;
|
|
173
|
+
workflowVersion: number;
|
|
174
|
+
lastMessageAt: string;
|
|
175
|
+
messageCount: number;
|
|
176
|
+
sessionTitle: string;
|
|
177
|
+
};
|
|
178
|
+
type ConversationEntry = {
|
|
179
|
+
query: string;
|
|
180
|
+
response: string;
|
|
181
|
+
userId: string;
|
|
182
|
+
userLabel: string;
|
|
183
|
+
executionId: string;
|
|
184
|
+
createdAt: string;
|
|
185
|
+
inputTokens?: number;
|
|
186
|
+
outputTokens?: number;
|
|
187
|
+
totalTokens?: number;
|
|
188
|
+
};
|
|
189
|
+
type PageInfo = {
|
|
190
|
+
page: number;
|
|
191
|
+
size: number;
|
|
192
|
+
totalElements: number;
|
|
193
|
+
totalPages: number;
|
|
194
|
+
first: boolean;
|
|
195
|
+
last: boolean;
|
|
196
|
+
hasNext: boolean;
|
|
197
|
+
hasPrevious: boolean;
|
|
198
|
+
};
|
|
199
|
+
type SessionListResponse = {
|
|
200
|
+
success: boolean;
|
|
201
|
+
message: string;
|
|
202
|
+
data: SessionSummary[];
|
|
203
|
+
pageInfo: PageInfo;
|
|
204
|
+
};
|
|
205
|
+
type ConversationListResponse = {
|
|
206
|
+
success: boolean;
|
|
207
|
+
message: string;
|
|
208
|
+
data: ConversationEntry[];
|
|
209
|
+
pageInfo: PageInfo;
|
|
212
210
|
};
|
|
213
211
|
type ChatCallbacks = {
|
|
214
|
-
/** Called when a message is sent (before API call) */
|
|
215
212
|
onMessageSent?: (message: string) => void;
|
|
216
|
-
/** Called when streaming starts */
|
|
217
213
|
onStreamStart?: () => void;
|
|
218
|
-
/** Called when streaming completes */
|
|
219
214
|
onStreamComplete?: (message: MessageDisplay) => void;
|
|
220
|
-
/** Called when an error occurs */
|
|
221
215
|
onError?: (error: Error) => void;
|
|
222
|
-
/** Called when execution trace is clicked - provides data instead of UI */
|
|
223
216
|
onExecutionTraceClick?: (data: {
|
|
224
217
|
message: MessageDisplay;
|
|
225
218
|
tracingData?: unknown;
|
|
226
219
|
executionId?: string;
|
|
227
220
|
}) => void;
|
|
228
|
-
/** Called when session ID changes */
|
|
229
221
|
onSessionIdChange?: (sessionId: string) => void;
|
|
230
|
-
/** Called when a user action (e.g. OTP) is required */
|
|
231
222
|
onUserActionRequired?: (request: UserActionRequest) => void;
|
|
232
|
-
/** Called on user action events (SUCCESS, INVALID, EXPIRED, REJECTED, RESENT, FAILED) */
|
|
233
223
|
onUserActionEvent?: (eventType: string, message: string) => void;
|
|
234
224
|
};
|
|
235
225
|
|
|
236
|
-
type UseChatReturn = {
|
|
237
|
-
messages: MessageDisplay[];
|
|
238
|
-
sendMessage: (userMessage: string) => Promise<void>;
|
|
239
|
-
clearMessages: () => void;
|
|
240
|
-
/** Prepend older messages to the top of the list (e.g. loaded from history pagination) */
|
|
241
|
-
prependMessages: (messages: MessageDisplay[]) => void;
|
|
242
|
-
cancelStream: () => void;
|
|
243
|
-
resetSession: () => void;
|
|
244
|
-
getSessionId: () => string | undefined;
|
|
245
|
-
getMessages: () => MessageDisplay[];
|
|
246
|
-
isWaitingForResponse: boolean;
|
|
247
|
-
sessionId: string | undefined;
|
|
248
|
-
/** User action (OTP) state — always present, inert when workflow has no user actions */
|
|
249
|
-
userActionState: UserActionState;
|
|
250
|
-
/** Submit OTP for approval */
|
|
251
|
-
approveUserAction: (otp: string) => Promise<void>;
|
|
252
|
-
/** Reject / cancel a user action */
|
|
253
|
-
rejectUserAction: () => Promise<void>;
|
|
254
|
-
/** Resend OTP code */
|
|
255
|
-
resendOtp: () => Promise<void>;
|
|
256
|
-
};
|
|
257
|
-
declare function useChat(config: ChatConfig, callbacks?: ChatCallbacks): UseChatReturn;
|
|
258
|
-
|
|
259
226
|
type UseChatV2Return = {
|
|
260
227
|
messages: MessageDisplay[];
|
|
261
228
|
sendMessage: (userMessage: string) => Promise<void>;
|
|
262
229
|
clearMessages: () => void;
|
|
230
|
+
/** Prepend older messages (e.g. loaded from history pagination). */
|
|
263
231
|
prependMessages: (messages: MessageDisplay[]) => void;
|
|
264
232
|
cancelStream: () => void;
|
|
265
233
|
resetSession: () => void;
|
|
@@ -271,8 +239,20 @@ type UseChatV2Return = {
|
|
|
271
239
|
approveUserAction: (otp: string) => Promise<void>;
|
|
272
240
|
rejectUserAction: () => Promise<void>;
|
|
273
241
|
resendOtp: () => Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Replace the active chat with a prior session's conversation history.
|
|
244
|
+
* Cancels any in-flight stream, clears current messages, fetches page 0 of
|
|
245
|
+
* conversations for `sessionId`, and renders them as historical rows.
|
|
246
|
+
*/
|
|
247
|
+
loadSession: (sessionId: string) => Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* The session id whose conversation history is currently being fetched
|
|
250
|
+
* via `loadSession`. `undefined` while idle. Use to render an activity
|
|
251
|
+
* indicator in the messages area / on the matching sidebar row.
|
|
252
|
+
*/
|
|
253
|
+
loadingSessionId: string | undefined;
|
|
274
254
|
};
|
|
275
|
-
declare function useChatV2(config:
|
|
255
|
+
declare function useChatV2(config: BaseChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
|
|
276
256
|
|
|
277
257
|
interface SpeechRecognitionEvent extends Event {
|
|
278
258
|
results: SpeechRecognitionResultList;
|
|
@@ -357,6 +337,11 @@ declare function streamWorkflowEvents(url: string, body: Record<string, unknown>
|
|
|
357
337
|
*/
|
|
358
338
|
declare function buildFormattedThinking(steps: StreamingStep[] | undefined, allThinkingText: string): string;
|
|
359
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Orchestrator completion often includes "Identified N task(s) to execute", which is redundant in the UI.
|
|
342
|
+
*/
|
|
343
|
+
declare function workingPhaseDetailForDisplay(raw: string): string;
|
|
344
|
+
|
|
360
345
|
type V2EventProcessorState = {
|
|
361
346
|
formattedThinkingText: string;
|
|
362
347
|
finalResponse: string;
|
|
@@ -384,14 +369,62 @@ type UserActionResponse = {
|
|
|
384
369
|
/**
|
|
385
370
|
* Submit a user action (e.g. OTP verification)
|
|
386
371
|
*/
|
|
387
|
-
declare function submitUserAction(config:
|
|
372
|
+
declare function submitUserAction(config: BaseChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
|
|
388
373
|
/**
|
|
389
374
|
* Cancel / reject a user action
|
|
390
375
|
*/
|
|
391
|
-
declare function cancelUserAction(config:
|
|
376
|
+
declare function cancelUserAction(config: BaseChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
392
377
|
/**
|
|
393
378
|
* Resend a user action (e.g. request a new OTP)
|
|
394
379
|
*/
|
|
395
|
-
declare function resendUserAction(config:
|
|
380
|
+
declare function resendUserAction(config: BaseChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
381
|
+
|
|
382
|
+
type ListSessionsOptions = {
|
|
383
|
+
page?: number;
|
|
384
|
+
size?: number;
|
|
385
|
+
signal?: AbortSignal;
|
|
386
|
+
};
|
|
387
|
+
type ListConversationsOptions = {
|
|
388
|
+
sessionId: string;
|
|
389
|
+
page?: number;
|
|
390
|
+
size?: number;
|
|
391
|
+
signal?: AbortSignal;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* List the recent sessions for the current `session.owner.id` within a workflow.
|
|
395
|
+
*
|
|
396
|
+
* Two variants, selected by auth mode:
|
|
397
|
+
*
|
|
398
|
+
* 1. Authenticated user (api.authToken present, or any auth mode that isn't
|
|
399
|
+
* yaak-api-key playground):
|
|
400
|
+
* GET {baseUrl}/api/workflow-users/{ownerId}/sessions
|
|
401
|
+
* ?workflowId={workflow.id}&{stageParam}={stage}&page=&size=
|
|
402
|
+
*
|
|
403
|
+
* 2. Playground / yaak-api-key (no authToken, yaak-api-key header present):
|
|
404
|
+
* GET {baseUrl}/api/workflows/ask/sessions
|
|
405
|
+
* ?workflowUserId={ownerId}&workflowName={workflow.name}&{stageParam}={stage}&page=&size=
|
|
406
|
+
*/
|
|
407
|
+
declare function listSessions(config: BaseChatConfig, opts?: ListSessionsOptions): Promise<SessionListResponse>;
|
|
408
|
+
/**
|
|
409
|
+
* List the conversation history for a single session.
|
|
410
|
+
*
|
|
411
|
+
* Two variants, selected by auth mode (mirrors `listSessions`):
|
|
412
|
+
*
|
|
413
|
+
* 1. Authenticated user (api.authToken present, or no yaak-api-key header):
|
|
414
|
+
* GET {baseUrl}/api/workflow-users/{ownerId}/conversations
|
|
415
|
+
* ?sessionId={sessionId}&{stageParam}={stage}&page=&size=
|
|
416
|
+
*
|
|
417
|
+
* 2. Playground / yaak-api-key (no authToken, x-yaak-api-key header present):
|
|
418
|
+
* GET {baseUrl}/api/workflows/ask/conversations
|
|
419
|
+
* ?workflowUserId={ownerId}&workflowName={workflow.name}&sessionId={sessionId}
|
|
420
|
+
* &{stageParam}={stage}&page=&size=
|
|
421
|
+
*/
|
|
422
|
+
declare function listConversations(config: BaseChatConfig, opts: ListConversationsOptions): Promise<ConversationListResponse>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Composite scope key for chatStore / activeStreamStore.
|
|
426
|
+
* Same (userId, workflow id, version, stage) → same state across unmount/remount.
|
|
427
|
+
*/
|
|
428
|
+
declare function buildScopeKey(config: BaseChatConfig): string;
|
|
396
429
|
|
|
397
|
-
export { type APIConfig, type
|
|
430
|
+
export { type APIConfig, type BaseChatConfig, type ChatCallbacks, type ChunkDisplay, type ConversationEntry, type ConversationListResponse, type MessageDisplay, type MessageRole, type PageInfo, type SessionListResponse, type SessionOwner, type SessionSummary, 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, type WorkflowStage, buildFormattedThinking, buildScopeKey, cancelUserAction, createInitialV2State, generateId, listConversations, listSessions, processStreamEventV2, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice, workingPhaseDetailForDisplay };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
1
|
type VoiceState = "idle" | "listening" | "processing" | "error";
|
|
4
2
|
type VoiceConfig = {
|
|
5
3
|
/** Language for speech recognition (default: "en-US") */
|
|
@@ -120,146 +118,116 @@ type MessageDisplay = {
|
|
|
120
118
|
steps?: StreamingStep[];
|
|
121
119
|
isCancelled?: boolean;
|
|
122
120
|
currentExecutingStepId?: string;
|
|
123
|
-
/** Result of user action (OTP approval/rejection) */
|
|
124
121
|
userActionResult?: UserActionResult;
|
|
125
|
-
/** Current thinking block text (live, resets per block) */
|
|
126
122
|
activeThinkingText?: string;
|
|
127
|
-
/** All thinking accumulated across blocks (for post-stream display) */
|
|
128
123
|
allThinkingText?: string;
|
|
129
|
-
/** Pre-formatted thinking text built from steps + allThinkingText (v2 streaming format, matches demo) */
|
|
130
124
|
formattedThinkingText?: string;
|
|
131
|
-
/** True while RAG image URLs are being resolved after the final response is shown */
|
|
132
125
|
isResolvingImages?: boolean;
|
|
126
|
+
/** History row loaded via loadSession(). Renderers skip streaming/step UI. */
|
|
127
|
+
isHistorical?: boolean;
|
|
133
128
|
};
|
|
134
|
-
type
|
|
129
|
+
type SessionOwner = {
|
|
130
|
+
/** Sent as sessionOwnerId in the request body. */
|
|
135
131
|
id?: string;
|
|
132
|
+
/** Sent as sessionOwnerLabel in the request body. */
|
|
136
133
|
name?: string;
|
|
134
|
+
/** Sent as sessionAttributes in the request body. */
|
|
137
135
|
attributes?: Record<string, string>;
|
|
138
136
|
};
|
|
139
137
|
type APIConfig = {
|
|
140
|
-
/** Base API URL */
|
|
141
138
|
baseUrl: string;
|
|
142
|
-
/** Auth token */
|
|
143
139
|
authToken?: string;
|
|
144
|
-
/** Custom headers */
|
|
145
140
|
headers?: Record<string, string>;
|
|
146
|
-
/**
|
|
141
|
+
/** Default: /api/workflows/ask/stream */
|
|
147
142
|
streamEndpoint?: string;
|
|
148
|
-
/**
|
|
143
|
+
/** Derived from streamEndpoint when omitted. */
|
|
149
144
|
resolveImagesEndpoint?: string;
|
|
145
|
+
/** Default: "stage". Davis overrides to "workflowStage". */
|
|
146
|
+
stageQueryParam?: string;
|
|
150
147
|
};
|
|
151
|
-
type
|
|
152
|
-
/** API configuration - required for the library to make calls */
|
|
148
|
+
type BaseChatConfig = {
|
|
153
149
|
api: APIConfig;
|
|
154
|
-
|
|
150
|
+
workflow: {
|
|
151
|
+
/** Workflow uuid. Required when ui.sessionHistory is enabled. Contributes to the state-scope key. */
|
|
152
|
+
id?: string;
|
|
153
|
+
name: string;
|
|
154
|
+
version?: number;
|
|
155
|
+
stage?: WorkflowStage;
|
|
156
|
+
};
|
|
157
|
+
session?: {
|
|
158
|
+
/** Client-side chatStore scoping (not sent to API). Clear on logout. */
|
|
159
|
+
userId?: string;
|
|
160
|
+
owner?: SessionOwner;
|
|
161
|
+
/** Default true. */
|
|
162
|
+
autoGenerateId?: boolean;
|
|
163
|
+
initialId?: string;
|
|
164
|
+
initialMessages?: MessageDisplay[];
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
type SessionSummary = {
|
|
168
|
+
userId: string;
|
|
169
|
+
userLabel: string;
|
|
170
|
+
sessionId: string;
|
|
171
|
+
workflowId: string;
|
|
155
172
|
workflowName: string;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
layout?: "centered" | "full-width";
|
|
194
|
-
/** Show timestamps on messages */
|
|
195
|
-
showTimestamps?: boolean;
|
|
196
|
-
/** Enable animations */
|
|
197
|
-
animated?: boolean;
|
|
198
|
-
/** Disable input */
|
|
199
|
-
disableInput?: boolean;
|
|
200
|
-
/** Has permission to ask */
|
|
201
|
-
hasAskPermission?: boolean;
|
|
202
|
-
/** Auto-generate session ID */
|
|
203
|
-
autoGenerateSessionId?: boolean;
|
|
204
|
-
/** Disable the entire chat and show disabled state */
|
|
205
|
-
isChatDisabled?: boolean;
|
|
206
|
-
/** Custom component to render when chat is disabled. If not provided, default disabled UI will be shown */
|
|
207
|
-
disabledComponent?: React.ReactNode;
|
|
208
|
-
/** Pre-populate the chat with messages (e.g. loaded conversation history) */
|
|
209
|
-
initialMessages?: MessageDisplay[];
|
|
210
|
-
/** Resume an existing session by providing its ID */
|
|
211
|
-
initialSessionId?: string;
|
|
173
|
+
workflowVersion: number;
|
|
174
|
+
lastMessageAt: string;
|
|
175
|
+
messageCount: number;
|
|
176
|
+
sessionTitle: string;
|
|
177
|
+
};
|
|
178
|
+
type ConversationEntry = {
|
|
179
|
+
query: string;
|
|
180
|
+
response: string;
|
|
181
|
+
userId: string;
|
|
182
|
+
userLabel: string;
|
|
183
|
+
executionId: string;
|
|
184
|
+
createdAt: string;
|
|
185
|
+
inputTokens?: number;
|
|
186
|
+
outputTokens?: number;
|
|
187
|
+
totalTokens?: number;
|
|
188
|
+
};
|
|
189
|
+
type PageInfo = {
|
|
190
|
+
page: number;
|
|
191
|
+
size: number;
|
|
192
|
+
totalElements: number;
|
|
193
|
+
totalPages: number;
|
|
194
|
+
first: boolean;
|
|
195
|
+
last: boolean;
|
|
196
|
+
hasNext: boolean;
|
|
197
|
+
hasPrevious: boolean;
|
|
198
|
+
};
|
|
199
|
+
type SessionListResponse = {
|
|
200
|
+
success: boolean;
|
|
201
|
+
message: string;
|
|
202
|
+
data: SessionSummary[];
|
|
203
|
+
pageInfo: PageInfo;
|
|
204
|
+
};
|
|
205
|
+
type ConversationListResponse = {
|
|
206
|
+
success: boolean;
|
|
207
|
+
message: string;
|
|
208
|
+
data: ConversationEntry[];
|
|
209
|
+
pageInfo: PageInfo;
|
|
212
210
|
};
|
|
213
211
|
type ChatCallbacks = {
|
|
214
|
-
/** Called when a message is sent (before API call) */
|
|
215
212
|
onMessageSent?: (message: string) => void;
|
|
216
|
-
/** Called when streaming starts */
|
|
217
213
|
onStreamStart?: () => void;
|
|
218
|
-
/** Called when streaming completes */
|
|
219
214
|
onStreamComplete?: (message: MessageDisplay) => void;
|
|
220
|
-
/** Called when an error occurs */
|
|
221
215
|
onError?: (error: Error) => void;
|
|
222
|
-
/** Called when execution trace is clicked - provides data instead of UI */
|
|
223
216
|
onExecutionTraceClick?: (data: {
|
|
224
217
|
message: MessageDisplay;
|
|
225
218
|
tracingData?: unknown;
|
|
226
219
|
executionId?: string;
|
|
227
220
|
}) => void;
|
|
228
|
-
/** Called when session ID changes */
|
|
229
221
|
onSessionIdChange?: (sessionId: string) => void;
|
|
230
|
-
/** Called when a user action (e.g. OTP) is required */
|
|
231
222
|
onUserActionRequired?: (request: UserActionRequest) => void;
|
|
232
|
-
/** Called on user action events (SUCCESS, INVALID, EXPIRED, REJECTED, RESENT, FAILED) */
|
|
233
223
|
onUserActionEvent?: (eventType: string, message: string) => void;
|
|
234
224
|
};
|
|
235
225
|
|
|
236
|
-
type UseChatReturn = {
|
|
237
|
-
messages: MessageDisplay[];
|
|
238
|
-
sendMessage: (userMessage: string) => Promise<void>;
|
|
239
|
-
clearMessages: () => void;
|
|
240
|
-
/** Prepend older messages to the top of the list (e.g. loaded from history pagination) */
|
|
241
|
-
prependMessages: (messages: MessageDisplay[]) => void;
|
|
242
|
-
cancelStream: () => void;
|
|
243
|
-
resetSession: () => void;
|
|
244
|
-
getSessionId: () => string | undefined;
|
|
245
|
-
getMessages: () => MessageDisplay[];
|
|
246
|
-
isWaitingForResponse: boolean;
|
|
247
|
-
sessionId: string | undefined;
|
|
248
|
-
/** User action (OTP) state — always present, inert when workflow has no user actions */
|
|
249
|
-
userActionState: UserActionState;
|
|
250
|
-
/** Submit OTP for approval */
|
|
251
|
-
approveUserAction: (otp: string) => Promise<void>;
|
|
252
|
-
/** Reject / cancel a user action */
|
|
253
|
-
rejectUserAction: () => Promise<void>;
|
|
254
|
-
/** Resend OTP code */
|
|
255
|
-
resendOtp: () => Promise<void>;
|
|
256
|
-
};
|
|
257
|
-
declare function useChat(config: ChatConfig, callbacks?: ChatCallbacks): UseChatReturn;
|
|
258
|
-
|
|
259
226
|
type UseChatV2Return = {
|
|
260
227
|
messages: MessageDisplay[];
|
|
261
228
|
sendMessage: (userMessage: string) => Promise<void>;
|
|
262
229
|
clearMessages: () => void;
|
|
230
|
+
/** Prepend older messages (e.g. loaded from history pagination). */
|
|
263
231
|
prependMessages: (messages: MessageDisplay[]) => void;
|
|
264
232
|
cancelStream: () => void;
|
|
265
233
|
resetSession: () => void;
|
|
@@ -271,8 +239,20 @@ type UseChatV2Return = {
|
|
|
271
239
|
approveUserAction: (otp: string) => Promise<void>;
|
|
272
240
|
rejectUserAction: () => Promise<void>;
|
|
273
241
|
resendOtp: () => Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Replace the active chat with a prior session's conversation history.
|
|
244
|
+
* Cancels any in-flight stream, clears current messages, fetches page 0 of
|
|
245
|
+
* conversations for `sessionId`, and renders them as historical rows.
|
|
246
|
+
*/
|
|
247
|
+
loadSession: (sessionId: string) => Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* The session id whose conversation history is currently being fetched
|
|
250
|
+
* via `loadSession`. `undefined` while idle. Use to render an activity
|
|
251
|
+
* indicator in the messages area / on the matching sidebar row.
|
|
252
|
+
*/
|
|
253
|
+
loadingSessionId: string | undefined;
|
|
274
254
|
};
|
|
275
|
-
declare function useChatV2(config:
|
|
255
|
+
declare function useChatV2(config: BaseChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
|
|
276
256
|
|
|
277
257
|
interface SpeechRecognitionEvent extends Event {
|
|
278
258
|
results: SpeechRecognitionResultList;
|
|
@@ -357,6 +337,11 @@ declare function streamWorkflowEvents(url: string, body: Record<string, unknown>
|
|
|
357
337
|
*/
|
|
358
338
|
declare function buildFormattedThinking(steps: StreamingStep[] | undefined, allThinkingText: string): string;
|
|
359
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Orchestrator completion often includes "Identified N task(s) to execute", which is redundant in the UI.
|
|
342
|
+
*/
|
|
343
|
+
declare function workingPhaseDetailForDisplay(raw: string): string;
|
|
344
|
+
|
|
360
345
|
type V2EventProcessorState = {
|
|
361
346
|
formattedThinkingText: string;
|
|
362
347
|
finalResponse: string;
|
|
@@ -384,14 +369,62 @@ type UserActionResponse = {
|
|
|
384
369
|
/**
|
|
385
370
|
* Submit a user action (e.g. OTP verification)
|
|
386
371
|
*/
|
|
387
|
-
declare function submitUserAction(config:
|
|
372
|
+
declare function submitUserAction(config: BaseChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
|
|
388
373
|
/**
|
|
389
374
|
* Cancel / reject a user action
|
|
390
375
|
*/
|
|
391
|
-
declare function cancelUserAction(config:
|
|
376
|
+
declare function cancelUserAction(config: BaseChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
392
377
|
/**
|
|
393
378
|
* Resend a user action (e.g. request a new OTP)
|
|
394
379
|
*/
|
|
395
|
-
declare function resendUserAction(config:
|
|
380
|
+
declare function resendUserAction(config: BaseChatConfig, userActionId: string): Promise<UserActionResponse>;
|
|
381
|
+
|
|
382
|
+
type ListSessionsOptions = {
|
|
383
|
+
page?: number;
|
|
384
|
+
size?: number;
|
|
385
|
+
signal?: AbortSignal;
|
|
386
|
+
};
|
|
387
|
+
type ListConversationsOptions = {
|
|
388
|
+
sessionId: string;
|
|
389
|
+
page?: number;
|
|
390
|
+
size?: number;
|
|
391
|
+
signal?: AbortSignal;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* List the recent sessions for the current `session.owner.id` within a workflow.
|
|
395
|
+
*
|
|
396
|
+
* Two variants, selected by auth mode:
|
|
397
|
+
*
|
|
398
|
+
* 1. Authenticated user (api.authToken present, or any auth mode that isn't
|
|
399
|
+
* yaak-api-key playground):
|
|
400
|
+
* GET {baseUrl}/api/workflow-users/{ownerId}/sessions
|
|
401
|
+
* ?workflowId={workflow.id}&{stageParam}={stage}&page=&size=
|
|
402
|
+
*
|
|
403
|
+
* 2. Playground / yaak-api-key (no authToken, yaak-api-key header present):
|
|
404
|
+
* GET {baseUrl}/api/workflows/ask/sessions
|
|
405
|
+
* ?workflowUserId={ownerId}&workflowName={workflow.name}&{stageParam}={stage}&page=&size=
|
|
406
|
+
*/
|
|
407
|
+
declare function listSessions(config: BaseChatConfig, opts?: ListSessionsOptions): Promise<SessionListResponse>;
|
|
408
|
+
/**
|
|
409
|
+
* List the conversation history for a single session.
|
|
410
|
+
*
|
|
411
|
+
* Two variants, selected by auth mode (mirrors `listSessions`):
|
|
412
|
+
*
|
|
413
|
+
* 1. Authenticated user (api.authToken present, or no yaak-api-key header):
|
|
414
|
+
* GET {baseUrl}/api/workflow-users/{ownerId}/conversations
|
|
415
|
+
* ?sessionId={sessionId}&{stageParam}={stage}&page=&size=
|
|
416
|
+
*
|
|
417
|
+
* 2. Playground / yaak-api-key (no authToken, x-yaak-api-key header present):
|
|
418
|
+
* GET {baseUrl}/api/workflows/ask/conversations
|
|
419
|
+
* ?workflowUserId={ownerId}&workflowName={workflow.name}&sessionId={sessionId}
|
|
420
|
+
* &{stageParam}={stage}&page=&size=
|
|
421
|
+
*/
|
|
422
|
+
declare function listConversations(config: BaseChatConfig, opts: ListConversationsOptions): Promise<ConversationListResponse>;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Composite scope key for chatStore / activeStreamStore.
|
|
426
|
+
* Same (userId, workflow id, version, stage) → same state across unmount/remount.
|
|
427
|
+
*/
|
|
428
|
+
declare function buildScopeKey(config: BaseChatConfig): string;
|
|
396
429
|
|
|
397
|
-
export { type APIConfig, type
|
|
430
|
+
export { type APIConfig, type BaseChatConfig, type ChatCallbacks, type ChunkDisplay, type ConversationEntry, type ConversationListResponse, type MessageDisplay, type MessageRole, type PageInfo, type SessionListResponse, type SessionOwner, type SessionSummary, 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, type WorkflowStage, buildFormattedThinking, buildScopeKey, cancelUserAction, createInitialV2State, generateId, listConversations, listSessions, processStreamEventV2, resendUserAction, streamWorkflowEvents, submitUserAction, useChatV2, useVoice, workingPhaseDetailForDisplay };
|