@meetsmore-oss/use-ai-client 1.13.1 → 1.14.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.ts CHANGED
@@ -359,6 +359,7 @@ declare class UseAIClient {
359
359
  private _tools;
360
360
  private _messages;
361
361
  private _state;
362
+ private _currentRunId;
362
363
  private _availableAgents;
363
364
  private _defaultAgent;
364
365
  private _selectedAgent;
@@ -419,6 +420,53 @@ declare class UseAIClient {
419
420
  * @param state - Optional updated state to send back to the AI
420
421
  */
421
422
  sendToolResponse(toolCallId: string, result: unknown, state?: unknown): void;
423
+ /**
424
+ * Aborts the in-flight run, if any.
425
+ * Sends an `abort_run` message to the server which cancels the AI stream
426
+ * and rejects any pending tool/approval waits. The server then emits
427
+ * `RUN_ERROR` with `ErrorCode.ABORTED`, which the client handles by
428
+ * persisting the partial response.
429
+ *
430
+ * No-op when no run is in flight.
431
+ */
432
+ abortRun(): void;
433
+ /**
434
+ * Flushes the final in-progress step into `_messages` when a run terminates.
435
+ *
436
+ * Only two terminations reach here. Truncation (maxOutputTokens / finish
437
+ * reason 'length') and tool-execution errors never do — the server absorbs
438
+ * them: truncation continues via a fallback step and ends as a normal
439
+ * RUN_FINISHED, and tool errors come back as tool_results that keep the run
440
+ * going. So the dispatch is binary:
441
+ * - `aborted: false` (RUN_FINISHED): every tool-call step was already flushed
442
+ * at STEP_FINISHED, so the in-progress step is always text-only.
443
+ * - `aborted: true` (RUN_ERROR / ABORTED): the run may have been cut
444
+ * mid-tool-call or mid-reasoning, so extra repair is needed.
445
+ *
446
+ * After this returns, `currentMessageContent` and `currentReasoningBlocks`
447
+ * remain readable for the persistence helper. The next RUN_STARTED clears them.
448
+ */
449
+ finalizeRun(opts: {
450
+ aborted: boolean;
451
+ }): void;
452
+ /**
453
+ * Normal completion (RUN_FINISHED). The in-progress step is text-only —
454
+ * tool-call steps were already flushed at STEP_FINISHED — so just push the
455
+ * trailing assistant text with its reasoning.
456
+ */
457
+ private finalizeCompletedRun;
458
+ /**
459
+ * User-initiated abort (RUN_ERROR / ABORTED).
460
+ *
461
+ * Drops the in-progress step's reasoning blocks. A block gets its encrypted
462
+ * signature on REASONING_ENCRYPTED_VALUE, which arrives after
463
+ * REASONING_MESSAGE_END — so a mid-stream abort can leave signature-less
464
+ * blocks. Persisting those would corrupt the next turn. Reasoning from
465
+ * already-completed prior steps lives on STEP_FINISHED-flushed assistant
466
+ * messages and is untouched. Aborted-step messages therefore never carry
467
+ * reasoningParts.
468
+ */
469
+ private finalizeAbortedRun;
422
470
  /**
423
471
  * Sends a tool approval response back to the server.
424
472
  *
@@ -467,6 +515,10 @@ declare class UseAIClient {
467
515
  * Gets the current accumulated message content (useful during streaming).
468
516
  */
469
517
  get currentMessageContent(): string;
518
+ /**
519
+ * Gets the runId of the in-flight run, or null when no run is active.
520
+ */
521
+ get currentRunId(): string | null;
470
522
  /**
471
523
  * Gets the current reasoning blocks collected during the current run.
472
524
  */
@@ -720,7 +772,7 @@ type ChatMetadata = Record<string, unknown>;
720
772
  * Display mode for chat messages.
721
773
  * Determines the visual styling of the message bubble.
722
774
  */
723
- type MessageDisplayMode = 'default' | 'error';
775
+ type MessageDisplayMode = 'default' | 'error' | 'info';
724
776
  /**
725
777
  * Text content part for persisted messages.
726
778
  */
@@ -1175,6 +1227,10 @@ declare const defaultStrings: {
1175
1227
  /** Error for unknown/unexpected errors */
1176
1228
  UNKNOWN_ERROR: string;
1177
1229
  };
1230
+ notices: {
1231
+ /** Shown as a separate bubble after the user aborts generation */
1232
+ aborted: string;
1233
+ };
1178
1234
  thinking: {
1179
1235
  /** Label shown while thinking is in progress */
1180
1236
  inProgress: string;
@@ -1243,6 +1299,8 @@ declare const defaultTheme: {
1243
1299
  activeBackground: string;
1244
1300
  /** Disabled button background */
1245
1301
  buttonDisabledBackground: string;
1302
+ /** Stop (abort) button background — neutral so it doesn't read as a primary action */
1303
+ stopButtonBackground: string;
1246
1304
  /** Primary text color */
1247
1305
  textColor: string;
1248
1306
  /** Secondary/muted text color */
@@ -1397,6 +1455,11 @@ interface UseAIContextValue {
1397
1455
  agents: AgentContextValue;
1398
1456
  /** Command management */
1399
1457
  commands: CommandContextValue;
1458
+ /**
1459
+ * Aborts the in-flight run, if any. Persists the partial response and
1460
+ * leaves the conversation in a state where the user can send a follow-up.
1461
+ */
1462
+ abortRun: () => void;
1400
1463
  }
1401
1464
  /**
1402
1465
  * Props for custom floating button component.
@@ -1421,6 +1484,11 @@ interface ChatPanelProps {
1421
1484
  onClose: () => void;
1422
1485
  /** Callback when a message is sent */
1423
1486
  onSendMessage: (message: string) => void;
1487
+ /**
1488
+ * Aborts the in-flight run. No-op when no run is active.
1489
+ * Use this to wire a "stop" button while `loading` is true.
1490
+ */
1491
+ onAbort: () => void;
1424
1492
  /** Array of messages in the conversation */
1425
1493
  messages: PersistedMessage[];
1426
1494
  /** Whether the AI is currently processing */
@@ -1645,6 +1713,13 @@ type Message = PersistedMessage;
1645
1713
  */
1646
1714
  interface UseAIChatPanelProps {
1647
1715
  onSendMessage: (message: string, attachments?: FileAttachment[]) => void;
1716
+ /**
1717
+ * Aborts the in-flight run. When provided and `loading` is true (and no
1718
+ * tool is currently executing), the send button switches to a "stop"
1719
+ * button that calls this. Without `onAbort` the button stays disabled
1720
+ * during loading.
1721
+ */
1722
+ onAbort?: () => void;
1648
1723
  messages: Message[];
1649
1724
  loading: boolean;
1650
1725
  connected: boolean;
@@ -1711,7 +1786,7 @@ interface UseAIChatPanelProps {
1711
1786
  * Chat panel content - fills its container.
1712
1787
  * Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
1713
1788
  */
1714
- declare function UseAIChatPanel({ onSendMessage, messages, loading, connected, streamingText, streamingReasoning, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, submitMode, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
1789
+ declare function UseAIChatPanel({ onSendMessage, onAbort, messages, loading, connected, streamingText, streamingReasoning, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, submitMode, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
1715
1790
 
1716
1791
  /**
1717
1792
  * Props for the floating chat wrapper.
@@ -2206,7 +2281,7 @@ interface UseChatManagementReturn {
2206
2281
  * the turn are persisted before the final assistant message, preserving the
2207
2282
  * complete tool call context for conversation history.
2208
2283
  */
2209
- saveAIResponse: (content: string, displayMode?: 'default' | 'error', traceId?: string, turnMessages?: PersistedMessage[], reasoningParts?: ReasoningPart[]) => Promise<void>;
2284
+ saveAIResponse: (content: string, displayMode?: MessageDisplayMode, traceId?: string, turnMessages?: PersistedMessage[], reasoningParts?: ReasoningPart[]) => Promise<void>;
2210
2285
  /** Reloads messages from storage for the given chat ID */
2211
2286
  reloadMessages: (chatId: string) => Promise<void>;
2212
2287
  /** Get the current chat object. Metadata is frozen to prevent accidental mutation. */
@@ -2368,7 +2443,7 @@ interface UseServerEventsOptions {
2368
2443
  /** Tool system for executing tools and looking up tool metadata */
2369
2444
  toolSystem: UseToolSystemReturn;
2370
2445
  /** Saves an AI response to chat storage */
2371
- saveAIResponse: (content: string, displayMode?: 'default' | 'error', traceId?: string, turnMessages?: PersistedMessage[], reasoningParts?: ReasoningPart[]) => Promise<void>;
2446
+ saveAIResponse: (content: string, displayMode?: MessageDisplayMode, traceId?: string, turnMessages?: PersistedMessage[], reasoningParts?: ReasoningPart[]) => Promise<void>;
2372
2447
  /** UI strings for error messages and tool execution fallbacks */
2373
2448
  strings: UseAIStrings;
2374
2449
  }