@meetsmore-oss/use-ai-client 1.12.1 → 1.13.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/bundled.js CHANGED
@@ -1371,6 +1371,8 @@ var defaultStrings = {
1371
1371
  API_OVERLOADED: "The AI service is currently experiencing high demand. Please try again in a moment.",
1372
1372
  /** Error when rate limited */
1373
1373
  RATE_LIMITED: "Too many requests. Please wait a moment before trying again.",
1374
+ /** Error when the connection was lost while a response was being generated */
1375
+ CONNECTION_LOST: "The connection was lost. Please send your message again.",
1374
1376
  /** Error for unknown/unexpected errors */
1375
1377
  UNKNOWN_ERROR: "An unexpected error occurred. Please try again."
1376
1378
  },
@@ -1631,6 +1633,17 @@ function mergeAssistantMessagesForDisplay(messages) {
1631
1633
  return result;
1632
1634
  }
1633
1635
 
1636
+ // src/utils/keyboard.ts
1637
+ function shouldSubmitOnEnter(e, mode) {
1638
+ if (e.key !== "Enter" || e.nativeEvent.isComposing || e.keyCode === 229) {
1639
+ return false;
1640
+ }
1641
+ if (mode === "enter") {
1642
+ return !e.shiftKey;
1643
+ }
1644
+ return e.metaKey || e.ctrlKey;
1645
+ }
1646
+
1634
1647
  // ../../node_modules/.bun/react-markdown@8.0.7+32264e8fb3466d46/node_modules/react-markdown/lib/uri-transformer.js
1635
1648
  var protocols = ["http", "https", "mailto", "tel"];
1636
1649
  function uriTransformer(uri) {
@@ -14678,7 +14691,8 @@ function UseAIChatPanel({
14678
14691
  onFeedback,
14679
14692
  pendingApprovals = [],
14680
14693
  onApproveToolCall,
14681
- onRejectToolCall
14694
+ onRejectToolCall,
14695
+ submitMode = "enter"
14682
14696
  }) {
14683
14697
  const strings = useStrings();
14684
14698
  const theme = useTheme();
@@ -14753,7 +14767,7 @@ function UseAIChatPanel({
14753
14767
  if (slashCommands.handleKeyDown(e)) {
14754
14768
  return;
14755
14769
  }
14756
- if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && !(e.keyCode === 229)) {
14770
+ if (shouldSubmitOnEnter(e, submitMode)) {
14757
14771
  e.preventDefault();
14758
14772
  handleSend();
14759
14773
  }
@@ -15773,9 +15787,10 @@ function useChatUIContext() {
15773
15787
  }
15774
15788
  return context;
15775
15789
  }
15776
- function UseAIChat({ floating = false }) {
15790
+ function UseAIChat({ floating = false, submitMode }) {
15777
15791
  const ctx = useChatUIContext();
15778
15792
  const chatPanelProps = {
15793
+ submitMode: submitMode ?? ctx.submitMode,
15779
15794
  onSendMessage: ctx.sendMessage,
15780
15795
  messages: ctx.messages,
15781
15796
  loading: ctx.loading,
@@ -23647,6 +23662,7 @@ var ErrorCode;
23647
23662
  ((ErrorCode2) => {
23648
23663
  ErrorCode2["API_OVERLOADED"] = "API_OVERLOADED";
23649
23664
  ErrorCode2["RATE_LIMITED"] = "RATE_LIMITED";
23665
+ ErrorCode2["CONNECTION_LOST"] = "CONNECTION_LOST";
23650
23666
  ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
23651
23667
  })(ErrorCode ||= {});
23652
23668
  var TOOL_APPROVAL_REQUEST = "TOOL_APPROVAL_REQUEST";
@@ -23663,9 +23679,12 @@ var UseAIClient = class {
23663
23679
  }
23664
23680
  socket = null;
23665
23681
  eventHandlers = /* @__PURE__ */ new Map();
23666
- reconnectAttempts = 0;
23667
- maxReconnectAttempts = 5;
23682
+ // Reconnect indefinitely so clients recover after extended outages (mobile
23683
+ // app backgrounded long enough for server pingTimeout, airplane mode, etc.).
23684
+ // Socket.IO applies exponential backoff capped at reconnectionDelayMax,
23685
+ // so steady-state retry frequency is ~one attempt per 10s.
23668
23686
  reconnectDelay = 1e3;
23687
+ reconnectDelayMax = 1e4;
23669
23688
  // Session state
23670
23689
  _threadId = null;
23671
23690
  _tools = [];
@@ -23703,14 +23722,14 @@ var UseAIClient = class {
23703
23722
  this.socket = lookup2(this.serverUrl, {
23704
23723
  transports: ["polling", "websocket"],
23705
23724
  reconnection: true,
23706
- reconnectionAttempts: this.maxReconnectAttempts,
23725
+ reconnectionAttempts: Infinity,
23707
23726
  reconnectionDelay: this.reconnectDelay,
23727
+ reconnectionDelayMax: this.reconnectDelayMax,
23708
23728
  withCredentials: true
23709
23729
  });
23710
23730
  this.socket.on("connect", () => {
23711
23731
  console.log("[UseAI] Connected to server");
23712
23732
  console.log("[UseAI] Transport:", this.socket?.io?.engine?.transport?.name);
23713
- this.reconnectAttempts = 0;
23714
23733
  const engine = this.socket?.io?.engine;
23715
23734
  if (engine) {
23716
23735
  engine.on("upgrade", (transport) => {
@@ -23880,6 +23899,7 @@ var UseAIClient = class {
23880
23899
  this._currentAssistantMessage = null;
23881
23900
  this._currentAssistantToolCalls = [];
23882
23901
  this._pendingToolResults = [];
23902
+ this._currentReasoningBlockText = "";
23883
23903
  }
23884
23904
  }
23885
23905
  this.eventHandlers.forEach((handler) => handler(event));
@@ -39298,6 +39318,8 @@ function useServerEvents({
39298
39318
  const [streamingText, setStreamingText] = useState13("");
39299
39319
  const [streamingReasoning, setStreamingReasoning] = useState13("");
39300
39320
  const streamingChatIdRef = useRef10(null);
39321
+ const loadingRef = useRef10(loading);
39322
+ loadingRef.current = loading;
39301
39323
  const messageCountAtRunStartRef = useRef10(0);
39302
39324
  const hasTextFromPriorStepRef = useRef10(false);
39303
39325
  const [executingToolRaw, setExecutingTool] = useState13(null);
@@ -39393,6 +39415,17 @@ function useServerEvents({
39393
39415
  setLoading(false);
39394
39416
  }
39395
39417
  }, []);
39418
+ const handleDisconnect = useCallback11(() => {
39419
+ if (!loadingRef.current) return;
39420
+ const strs = stringsRef.current;
39421
+ const message = strs.errors[ErrorCode.CONNECTION_LOST] || strs.errors[ErrorCode.UNKNOWN_ERROR];
39422
+ saveAIResponseRef.current(message, "error");
39423
+ setStreamingText("");
39424
+ setStreamingReasoning("");
39425
+ streamingChatIdRef.current = null;
39426
+ setExecutingTool(null);
39427
+ setLoading(false);
39428
+ }, []);
39396
39429
  const executingTool = executingToolRaw ? {
39397
39430
  displayText: executingToolRaw.title ?? executingToolFallbackRef.current ?? strings.toolExecution.fallbackMessages[0]
39398
39431
  } : null;
@@ -39404,7 +39437,8 @@ function useServerEvents({
39404
39437
  executingTool,
39405
39438
  streamingChatIdRef,
39406
39439
  streamingReasoning,
39407
- handleServerEvent
39440
+ handleServerEvent,
39441
+ handleDisconnect
39408
39442
  };
39409
39443
  }
39410
39444
 
@@ -39570,7 +39604,8 @@ function UseAIProvider({
39570
39604
  theme: customTheme,
39571
39605
  strings: customStrings,
39572
39606
  visibleAgentIds,
39573
- onOpenChange
39607
+ onOpenChange,
39608
+ submitMode = "enter"
39574
39609
  }) {
39575
39610
  const fileUploadConfig = fileUploadConfigProp === false ? void 0 : fileUploadConfigProp ?? DEFAULT_FILE_UPLOAD_CONFIG;
39576
39611
  const theme = { ...defaultTheme, ...customTheme };
@@ -39629,12 +39664,17 @@ function UseAIProvider({
39629
39664
  } = useCommandManagement({ repository: commandRepository });
39630
39665
  const handleServerEventRef = useRef12(serverEvents.handleServerEvent);
39631
39666
  handleServerEventRef.current = serverEvents.handleServerEvent;
39667
+ const handleDisconnectRef = useRef12(serverEvents.handleDisconnect);
39668
+ handleDisconnectRef.current = serverEvents.handleDisconnect;
39632
39669
  useEffect11(() => {
39633
39670
  console.log("[UseAIProvider] Initializing client with serverUrl:", serverUrl);
39634
39671
  const client = new UseAIClient(serverUrl);
39635
39672
  const unsubscribeConnection = client.onConnectionStateChange((isConnected) => {
39636
39673
  console.log("[UseAIProvider] Connection state changed:", isConnected);
39637
39674
  setConnected(isConnected);
39675
+ if (!isConnected) {
39676
+ handleDisconnectRef.current();
39677
+ }
39638
39678
  });
39639
39679
  console.log("[UseAIProvider] Connecting...");
39640
39680
  client.connect();
@@ -39822,7 +39862,8 @@ function UseAIProvider({
39822
39862
  feedback: {
39823
39863
  enabled: feedback.enabled,
39824
39864
  submit: feedback.submitFeedback
39825
- }
39865
+ },
39866
+ submitMode
39826
39867
  };
39827
39868
  const isUIDisabled = CustomButton === null || CustomChat === null;
39828
39869
  const ButtonComponent = isUIDisabled ? null : CustomButton || UseAIFloatingButton;
@@ -39855,7 +39896,8 @@ function UseAIProvider({
39855
39896
  onFeedback: feedback.submitFeedback,
39856
39897
  pendingApprovals: toolSystem.pendingApprovals,
39857
39898
  onApproveToolCall: toolSystem.pendingApprovals.length > 0 ? toolSystem.approveAll : void 0,
39858
- onRejectToolCall: toolSystem.pendingApprovals.length > 0 ? toolSystem.rejectAll : void 0
39899
+ onRejectToolCall: toolSystem.pendingApprovals.length > 0 ? toolSystem.rejectAll : void 0,
39900
+ submitMode
39859
39901
  };
39860
39902
  const renderDefaultChat = () => {
39861
39903
  if (isUIDisabled) return null;