codicent-app-sdk 0.3.71 → 0.3.72

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.
@@ -11,5 +11,6 @@ export declare function useChat(state: AppStateMachine): {
11
11
  handleSend: (text: string, retryCount?: number) => void;
12
12
  newChat: () => void;
13
13
  openChat: (id: string) => void;
14
+ reloadChatHistory: () => Promise<boolean>;
14
15
  };
15
16
  //# sourceMappingURL=useChat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../../src/hooks/useChat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAO,MAAM,UAAU,CAAC;AAOhD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe;;;uBAWnC,MAAM;;mBAqGmB,MAAM;EAwBzC"}
1
+ {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../../src/hooks/useChat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAO,MAAM,UAAU,CAAC;AAOhD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe;;;uBAmDnC,MAAM;;mBA2IR,MAAM;;EA2Bd"}
@@ -1 +1 @@
1
- "use strict";var e=require("react"),t=require("../stores/chatStore.js");require("../utils/MessageContent.js"),require("../node_modules/tinycolor2/esm/tinycolor.js");var r=require("../utils/logging.js");require("react/jsx-runtime"),require("../_virtual/index.js"),require("../config/index.js"),require("../lib/wavtools/lib/wav_packer.js"),require("../lib/wavtools/lib/analysis/audio_analysis.js"),require("../lib/wavtools/lib/wav_stream_player.js"),require("../lib/wavtools/lib/wav_recorder.js"),exports.useChat=function(s){const[a,o]=e.useState(t.chatStore.getState()),{service:n}=s;e.useEffect((()=>t.chatStore.subscribe(o)),[n]);const i=e.useCallback(((e,s=0)=>{if(""===e.trim())return;const o=`$user-msg-${Date.now()}`,c={id:o,sender:"user",content:e},u=a.messages.length>0?a.messages[a.messages.length-1].id:void 0;t.chatStore.addMessage(c),t.chatStore.setBotTyping(!0),r.default("chat-send");const l=Promise.race([n.chat(e,u),new Promise(((e,t)=>{setTimeout((()=>t(new Error("Request timeout - please try again"))),3e4)}))]).then((e=>{const{id:s,content:a}=e,o={id:s,sender:"bot",content:a,isNew:!0};t.chatStore.setConversationId(s),t.chatStore.addMessage(o),t.chatStore.setBotTyping(!1),r.default("chat-receive"),a.startsWith("Error code: ")&&r.default("chat-error: "+a)})).catch((a=>{console.error("Chat error details:",{error:a,message:a?.message,name:a?.name,stack:a?.stack,tempId:o,lastMessageId:u,retryCount:s,timestamp:(new Date).toISOString()});if(0===s&&("AbortError"===a?.name||a?.message?.includes("timeout")||a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError")))return console.log("Auto-retrying chat request..."),t.chatStore.removeMessage(o),t.chatStore.setBotTyping(!1),void setTimeout((()=>i(e,s+1)),2e3);let c="An error occurred while sending the message. Please try again.";if(n.onUnauthorized&&a?.toString().includes("401"))return alert("Session expired. Please log in again."),void n.onUnauthorized();"AbortError"===a?.name||a?.message?.includes("timeout")?(c="Request timed out. Please check your connection and try again.",r.default("chat-timeout")):a?.message?.includes("HTTP error: 500")?(c="Server error. Please try again in a moment.",r.default("chat-server-error")):(a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError"))&&(c="Network error. Please check your connection and try again.",r.default("chat-network-error")),alert(c),t.chatStore.removeMessage(o),t.chatStore.setBotTyping(!1),r.default("chat-error")}));t.chatStore.addPendingRequest(o,l)}),[n,a.messages]),c=e.useCallback((()=>{t.chatStore.reset(),t.chatStore.clearMessages(),r.default("new-chat")}),[]),u=e.useCallback((e=>{t.chatStore.reset(),t.chatStore.clearMessages(),r.default("open-chat"),n.getChatHistory(e).then((e=>{e.forEach(((e,r)=>{const s={id:e.id,sender:r%2==0?"user":"bot",content:e.content};t.chatStore.addMessage(s)}))}))}),[]);return{messages:a.messages,isBotTyping:a.isBotTyping,handleSend:i,newChat:c,openChat:u}};
1
+ "use strict";var e=require("react"),t=require("../stores/chatStore.js");require("../utils/MessageContent.js"),require("../node_modules/tinycolor2/esm/tinycolor.js");var s=require("../utils/logging.js");require("react/jsx-runtime"),require("../_virtual/index.js"),require("../config/index.js"),require("../lib/wavtools/lib/wav_packer.js"),require("../lib/wavtools/lib/analysis/audio_analysis.js"),require("../lib/wavtools/lib/wav_stream_player.js"),require("../lib/wavtools/lib/wav_recorder.js"),exports.useChat=function(r){const[a,o]=e.useState(t.chatStore.getState()),{service:n}=r;e.useEffect((()=>t.chatStore.subscribe(o)),[n]);const i=e.useCallback((async()=>{const e=t.chatStore.getConversationId();if(e){console.log("Reloading chat history to check for missed messages...");try{const r=await n.getChatHistory(e),a=t.chatStore.getMessages();return r.length>a.length?(console.log(`Found ${r.length-a.length} missed messages, updating chat...`),t.chatStore.reset(),r.forEach(((e,s)=>{const r={id:e.id,sender:s%2==0?"user":"bot",content:e.content};t.chatStore.addMessage(r)})),t.chatStore.setConversationId(e),s.default("chat-history-reloaded"),!0):(console.log("No missed messages found"),!1)}catch(e){return console.error("Failed to reload chat history:",e),!1}}return!1}),[n]),c=e.useCallback(((e,r=0)=>{if(""===e.trim())return;const o=`$user-msg-${Date.now()}`,l={id:o,sender:"user",content:e},d=a.messages.length>0?a.messages[a.messages.length-1].id:void 0;t.chatStore.addMessage(l),t.chatStore.setBotTyping(!0),s.default("chat-send");const u=Promise.race([n.chat(e,d),new Promise(((e,t)=>{setTimeout((()=>t(new Error("Request timeout - please try again"))),3e4)}))]).then((e=>{const{id:r,content:a}=e,o={id:r,sender:"bot",content:a,isNew:!0};t.chatStore.setConversationId(r),t.chatStore.addMessage(o),t.chatStore.setBotTyping(!1),s.default("chat-receive"),a.startsWith("Error code: ")&&s.default("chat-error: "+a)})).catch((async a=>{console.error("Chat error details:",{error:a,message:a?.message,name:a?.name,stack:a?.stack,tempId:o,lastMessageId:d,retryCount:r,timestamp:(new Date).toISOString()});if(0===r&&("AbortError"===a?.name||a?.message?.includes("timeout")||a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError")))return console.log("Auto-retrying chat request..."),t.chatStore.removeMessage(o),t.chatStore.setBotTyping(!1),void setTimeout((()=>c(e,r+1)),2e3);function l(){let e="An error occurred while sending the message. Please try again.";if(n.onUnauthorized&&a?.toString().includes("401"))return alert("Session expired. Please log in again."),void n.onUnauthorized();"AbortError"===a?.name||a?.message?.includes("timeout")?(e="Request timed out. Please check your connection and try again.",s.default("chat-timeout")):a?.message?.includes("HTTP error: 500")?(e="Server error. Please try again in a moment.",s.default("chat-server-error")):(a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError"))&&(e="Network error. Please check your connection and try again.",s.default("chat-network-error")),alert(e),t.chatStore.removeMessage(o),t.chatStore.setBotTyping(!1),s.default("chat-error")}"AbortError"===a?.name||a?.message?.includes("timeout")||a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError")||a?.message?.includes("WebSocket")||a?.message?.includes("SignalR")||a?.message?.includes("Connection")?(console.log("Potential SignalR/connection issue detected, checking for missed messages..."),setTimeout((async()=>{if(await i())return t.chatStore.removeMessage(o),t.chatStore.setBotTyping(!1),console.log("Recovered missed message(s) from server"),void s.default("chat-recovered");l()}),2e3)):l()}));t.chatStore.addPendingRequest(o,u)}),[n,a.messages,i]),l=e.useCallback((()=>{t.chatStore.reset(),t.chatStore.clearMessages(),s.default("new-chat")}),[]),d=e.useCallback((e=>{t.chatStore.reset(),t.chatStore.clearMessages(),s.default("open-chat"),n.getChatHistory(e).then((e=>{e.forEach(((e,s)=>{const r={id:e.id,sender:s%2==0?"user":"bot",content:e.content};t.chatStore.addMessage(r)}))}))}),[n]);return{messages:a.messages,isBotTyping:a.isBotTyping,handleSend:c,newChat:l,openChat:d,reloadChatHistory:i}};
@@ -11,5 +11,6 @@ export declare function useChat(state: AppStateMachine): {
11
11
  handleSend: (text: string, retryCount?: number) => void;
12
12
  newChat: () => void;
13
13
  openChat: (id: string) => void;
14
+ reloadChatHistory: () => Promise<boolean>;
14
15
  };
15
16
  //# sourceMappingURL=useChat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../../src/hooks/useChat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAO,MAAM,UAAU,CAAC;AAOhD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe;;;uBAWnC,MAAM;;mBAqGmB,MAAM;EAwBzC"}
1
+ {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../../src/hooks/useChat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAO,MAAM,UAAU,CAAC;AAOhD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe;;;uBAmDnC,MAAM;;mBA2IR,MAAM;;EA2Bd"}
@@ -1 +1 @@
1
- import{useState as e,useEffect as t,useCallback as s}from"react";import{chatStore as r}from"../stores/chatStore.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import o from"../utils/logging.js";import"react/jsx-runtime";import"../_virtual/index.js";import"../config/index.js";import"../lib/wavtools/lib/wav_packer.js";import"../lib/wavtools/lib/analysis/audio_analysis.js";import"../lib/wavtools/lib/wav_stream_player.js";import"../lib/wavtools/lib/wav_recorder.js";function a(a){const[n,i]=e(r.getState()),{service:c}=a;t((()=>r.subscribe(i)),[c]);const m=s(((e,t=0)=>{if(""===e.trim())return;const s=`$user-msg-${Date.now()}`,a={id:s,sender:"user",content:e},i=n.messages.length>0?n.messages[n.messages.length-1].id:void 0;r.addMessage(a),r.setBotTyping(!0),o("chat-send");const d=Promise.race([c.chat(e,i),new Promise(((e,t)=>{setTimeout((()=>t(new Error("Request timeout - please try again"))),3e4)}))]).then((e=>{const{id:t,content:s}=e,a={id:t,sender:"bot",content:s,isNew:!0};r.setConversationId(t),r.addMessage(a),r.setBotTyping(!1),o("chat-receive"),s.startsWith("Error code: ")&&o("chat-error: "+s)})).catch((a=>{console.error("Chat error details:",{error:a,message:a?.message,name:a?.name,stack:a?.stack,tempId:s,lastMessageId:i,retryCount:t,timestamp:(new Date).toISOString()});if(0===t&&("AbortError"===a?.name||a?.message?.includes("timeout")||a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError")))return console.log("Auto-retrying chat request..."),r.removeMessage(s),r.setBotTyping(!1),void setTimeout((()=>m(e,t+1)),2e3);let n="An error occurred while sending the message. Please try again.";if(c.onUnauthorized&&a?.toString().includes("401"))return alert("Session expired. Please log in again."),void c.onUnauthorized();"AbortError"===a?.name||a?.message?.includes("timeout")?(n="Request timed out. Please check your connection and try again.",o("chat-timeout")):a?.message?.includes("HTTP error: 500")?(n="Server error. Please try again in a moment.",o("chat-server-error")):(a?.message?.includes("Failed to fetch")||a?.message?.includes("NetworkError"))&&(n="Network error. Please check your connection and try again.",o("chat-network-error")),alert(n),r.removeMessage(s),r.setBotTyping(!1),o("chat-error")}));r.addPendingRequest(s,d)}),[c,n.messages]),d=s((()=>{r.reset(),r.clearMessages(),o("new-chat")}),[]),g=s((e=>{r.reset(),r.clearMessages(),o("open-chat"),c.getChatHistory(e).then((e=>{e.forEach(((e,t)=>{const s={id:e.id,sender:t%2==0?"user":"bot",content:e.content};r.addMessage(s)}))}))}),[]);return{messages:n.messages,isBotTyping:n.isBotTyping,handleSend:m,newChat:d,openChat:g}}export{a as useChat};
1
+ import{useState as e,useEffect as s,useCallback as t}from"react";import{chatStore as o}from"../stores/chatStore.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import r from"../utils/logging.js";import"react/jsx-runtime";import"../_virtual/index.js";import"../config/index.js";import"../lib/wavtools/lib/wav_packer.js";import"../lib/wavtools/lib/analysis/audio_analysis.js";import"../lib/wavtools/lib/wav_stream_player.js";import"../lib/wavtools/lib/wav_recorder.js";function n(n){const[a,i]=e(o.getState()),{service:c}=n;s((()=>o.subscribe(i)),[c]);const d=t((async()=>{const e=o.getConversationId();if(e){console.log("Reloading chat history to check for missed messages...");try{const s=await c.getChatHistory(e),t=o.getMessages();return s.length>t.length?(console.log(`Found ${s.length-t.length} missed messages, updating chat...`),o.reset(),s.forEach(((e,s)=>{const t={id:e.id,sender:s%2==0?"user":"bot",content:e.content};o.addMessage(t)})),o.setConversationId(e),r("chat-history-reloaded"),!0):(console.log("No missed messages found"),!1)}catch(e){return console.error("Failed to reload chat history:",e),!1}}return!1}),[c]),g=t(((e,s=0)=>{if(""===e.trim())return;const t=`$user-msg-${Date.now()}`,n={id:t,sender:"user",content:e},i=a.messages.length>0?a.messages[a.messages.length-1].id:void 0;o.addMessage(n),o.setBotTyping(!0),r("chat-send");const l=Promise.race([c.chat(e,i),new Promise(((e,s)=>{setTimeout((()=>s(new Error("Request timeout - please try again"))),3e4)}))]).then((e=>{const{id:s,content:t}=e,n={id:s,sender:"bot",content:t,isNew:!0};o.setConversationId(s),o.addMessage(n),o.setBotTyping(!1),r("chat-receive"),t.startsWith("Error code: ")&&r("chat-error: "+t)})).catch((async n=>{console.error("Chat error details:",{error:n,message:n?.message,name:n?.name,stack:n?.stack,tempId:t,lastMessageId:i,retryCount:s,timestamp:(new Date).toISOString()});if(0===s&&("AbortError"===n?.name||n?.message?.includes("timeout")||n?.message?.includes("Failed to fetch")||n?.message?.includes("NetworkError")))return console.log("Auto-retrying chat request..."),o.removeMessage(t),o.setBotTyping(!1),void setTimeout((()=>g(e,s+1)),2e3);function a(){let e="An error occurred while sending the message. Please try again.";if(c.onUnauthorized&&n?.toString().includes("401"))return alert("Session expired. Please log in again."),void c.onUnauthorized();"AbortError"===n?.name||n?.message?.includes("timeout")?(e="Request timed out. Please check your connection and try again.",r("chat-timeout")):n?.message?.includes("HTTP error: 500")?(e="Server error. Please try again in a moment.",r("chat-server-error")):(n?.message?.includes("Failed to fetch")||n?.message?.includes("NetworkError"))&&(e="Network error. Please check your connection and try again.",r("chat-network-error")),alert(e),o.removeMessage(t),o.setBotTyping(!1),r("chat-error")}"AbortError"===n?.name||n?.message?.includes("timeout")||n?.message?.includes("Failed to fetch")||n?.message?.includes("NetworkError")||n?.message?.includes("WebSocket")||n?.message?.includes("SignalR")||n?.message?.includes("Connection")?(console.log("Potential SignalR/connection issue detected, checking for missed messages..."),setTimeout((async()=>{if(await d())return o.removeMessage(t),o.setBotTyping(!1),console.log("Recovered missed message(s) from server"),void r("chat-recovered");a()}),2e3)):a()}));o.addPendingRequest(t,l)}),[c,a.messages,d]),l=t((()=>{o.reset(),o.clearMessages(),r("new-chat")}),[]),m=t((e=>{o.reset(),o.clearMessages(),r("open-chat"),c.getChatHistory(e).then((e=>{e.forEach(((e,s)=>{const t={id:e.id,sender:s%2==0?"user":"bot",content:e.content};o.addMessage(t)}))}))}),[c]);return{messages:a.messages,isBotTyping:a.isBotTyping,handleSend:g,newChat:l,openChat:m,reloadChatHistory:d}}export{n as useChat};
package/dist/index.d.ts CHANGED
@@ -379,6 +379,7 @@ declare function useChat(state: AppStateMachine): {
379
379
  handleSend: (text: string, retryCount?: number) => void;
380
380
  newChat: () => void;
381
381
  openChat: (id: string) => void;
382
+ reloadChatHistory: () => Promise<boolean>;
382
383
  };
383
384
 
384
385
  declare const useCodicentState: (state: AppStateMachine) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codicent-app-sdk",
3
- "version": "0.3.71",
3
+ "version": "0.3.72",
4
4
  "description": "SDK for building AI-powered applications with Codicent",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",