@paymanai/payman-typescript-ask-sdk 1.2.11 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -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 SessionParams = {
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
- /** API endpoint for streaming (default: /api/workflows/ask/stream) */
141
+ /** Default: /api/workflows/ask/stream */
147
142
  streamEndpoint?: string;
148
- /** API endpoint for resolving RAG image URLs (default: /api/playground/ask/resolve-image-urls) */
143
+ /** Derived from streamEndpoint when omitted. */
149
144
  resolveImagesEndpoint?: string;
145
+ /** Default: "stage". Davis overrides to "workflowStage". */
146
+ stageQueryParam?: string;
150
147
  };
151
- type ChatConfig = {
152
- /** API configuration - required for the library to make calls */
148
+ type BaseChatConfig = {
153
149
  api: APIConfig;
154
- /** Workflow name */
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
- /** User ID for chatStore and activeStreamStore — required for context store messages management. Set to undefined on logout to clear stored messages. */
157
- userId?: string;
158
- /** Workflow version */
159
- workflowVersion?: number;
160
- /** Stage/Environment */
161
- stage?: WorkflowStage;
162
- /** Query param name for stage (default: "stage"). Use e.g. "workflowStage" if the API expects that name. */
163
- stageQueryParam?: string;
164
- /** Session params */
165
- sessionParams?: SessionParams;
166
- /** Custom placeholder text */
167
- placeholder?: string;
168
- /** Empty state text */
169
- emptyStateText?: string;
170
- /** Show icon in empty state */
171
- showEmptyStateIcon?: boolean;
172
- /** Show agent name */
173
- showAgentName?: boolean;
174
- /** Agent name */
175
- agentName?: string;
176
- /** Show avatars for user and assistant messages */
177
- showAvatars?: boolean;
178
- /** Show user avatar only (overrides showAvatars for user messages) */
179
- showUserAvatar?: boolean;
180
- /** Show assistant avatar only (overrides showAvatars for assistant messages) */
181
- showAssistantAvatar?: boolean;
182
- /** Show execution steps section with "Completed in X.Xs" */
183
- showExecutionSteps?: boolean;
184
- /** Show animated dot indicator during streaming */
185
- showStreamingDot?: boolean;
186
- /** Custom text format for streaming steps button. Use {count} for step count. Default: "View progress ({count} steps)" */
187
- streamingStepsText?: string;
188
- /** Custom text format for completed steps button. Use {count} for step count, {time} for elapsed time. Default: "Completed in {time}s ({count} steps)" */
189
- completedStepsText?: string;
190
- /** Input style variant: "rounded" (yaak style) or "flat" (paygent-central style). Default: "rounded" */
191
- inputStyle?: "rounded" | "flat";
192
- /** Layout style: "centered" (durango style) or "full-width" (default). Default: "full-width" */
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: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
255
+ declare function useChatV2(config: BaseChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
276
256
 
277
257
  interface SpeechRecognitionEvent extends Event {
278
258
  results: SpeechRecognitionResultList;
@@ -389,14 +369,62 @@ type UserActionResponse = {
389
369
  /**
390
370
  * Submit a user action (e.g. OTP verification)
391
371
  */
392
- declare function submitUserAction(config: ChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
372
+ declare function submitUserAction(config: BaseChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
393
373
  /**
394
374
  * Cancel / reject a user action
395
375
  */
396
- declare function cancelUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
376
+ declare function cancelUserAction(config: BaseChatConfig, userActionId: string): Promise<UserActionResponse>;
397
377
  /**
398
378
  * Resend a user action (e.g. request a new OTP)
399
379
  */
400
- declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
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;
401
429
 
402
- export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatReturn, 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, cancelUserAction, createInitialV2State, generateId, processStreamEventV2, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useChatV2, useVoice, workingPhaseDetailForDisplay };
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 SessionParams = {
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
- /** API endpoint for streaming (default: /api/workflows/ask/stream) */
141
+ /** Default: /api/workflows/ask/stream */
147
142
  streamEndpoint?: string;
148
- /** API endpoint for resolving RAG image URLs (default: /api/playground/ask/resolve-image-urls) */
143
+ /** Derived from streamEndpoint when omitted. */
149
144
  resolveImagesEndpoint?: string;
145
+ /** Default: "stage". Davis overrides to "workflowStage". */
146
+ stageQueryParam?: string;
150
147
  };
151
- type ChatConfig = {
152
- /** API configuration - required for the library to make calls */
148
+ type BaseChatConfig = {
153
149
  api: APIConfig;
154
- /** Workflow name */
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
- /** User ID for chatStore and activeStreamStore — required for context store messages management. Set to undefined on logout to clear stored messages. */
157
- userId?: string;
158
- /** Workflow version */
159
- workflowVersion?: number;
160
- /** Stage/Environment */
161
- stage?: WorkflowStage;
162
- /** Query param name for stage (default: "stage"). Use e.g. "workflowStage" if the API expects that name. */
163
- stageQueryParam?: string;
164
- /** Session params */
165
- sessionParams?: SessionParams;
166
- /** Custom placeholder text */
167
- placeholder?: string;
168
- /** Empty state text */
169
- emptyStateText?: string;
170
- /** Show icon in empty state */
171
- showEmptyStateIcon?: boolean;
172
- /** Show agent name */
173
- showAgentName?: boolean;
174
- /** Agent name */
175
- agentName?: string;
176
- /** Show avatars for user and assistant messages */
177
- showAvatars?: boolean;
178
- /** Show user avatar only (overrides showAvatars for user messages) */
179
- showUserAvatar?: boolean;
180
- /** Show assistant avatar only (overrides showAvatars for assistant messages) */
181
- showAssistantAvatar?: boolean;
182
- /** Show execution steps section with "Completed in X.Xs" */
183
- showExecutionSteps?: boolean;
184
- /** Show animated dot indicator during streaming */
185
- showStreamingDot?: boolean;
186
- /** Custom text format for streaming steps button. Use {count} for step count. Default: "View progress ({count} steps)" */
187
- streamingStepsText?: string;
188
- /** Custom text format for completed steps button. Use {count} for step count, {time} for elapsed time. Default: "Completed in {time}s ({count} steps)" */
189
- completedStepsText?: string;
190
- /** Input style variant: "rounded" (yaak style) or "flat" (paygent-central style). Default: "rounded" */
191
- inputStyle?: "rounded" | "flat";
192
- /** Layout style: "centered" (durango style) or "full-width" (default). Default: "full-width" */
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: ChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
255
+ declare function useChatV2(config: BaseChatConfig, callbacks?: ChatCallbacks): UseChatV2Return;
276
256
 
277
257
  interface SpeechRecognitionEvent extends Event {
278
258
  results: SpeechRecognitionResultList;
@@ -389,14 +369,62 @@ type UserActionResponse = {
389
369
  /**
390
370
  * Submit a user action (e.g. OTP verification)
391
371
  */
392
- declare function submitUserAction(config: ChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
372
+ declare function submitUserAction(config: BaseChatConfig, userActionId: string, data?: Record<string, unknown>): Promise<UserActionResponse>;
393
373
  /**
394
374
  * Cancel / reject a user action
395
375
  */
396
- declare function cancelUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
376
+ declare function cancelUserAction(config: BaseChatConfig, userActionId: string): Promise<UserActionResponse>;
397
377
  /**
398
378
  * Resend a user action (e.g. request a new OTP)
399
379
  */
400
- declare function resendUserAction(config: ChatConfig, userActionId: string): Promise<UserActionResponse>;
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;
401
429
 
402
- export { type APIConfig, type ChatCallbacks, type ChatConfig, type ChunkDisplay, type MessageDisplay, type MessageRole, type SessionParams, type StreamEvent, type StreamOptions, type StreamProgress, type StreamingStep, type UseChatReturn, 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, cancelUserAction, createInitialV2State, generateId, processStreamEventV2, resendUserAction, streamWorkflowEvents, submitUserAction, useChat, useChatV2, useVoice, workingPhaseDetailForDisplay };
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 };