codicent-app-sdk 0.3.66 → 0.3.68

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,6 +11,7 @@ interface ChatInputProps {
11
11
  noMemory?: boolean;
12
12
  selectAll?: boolean;
13
13
  clearOnFocus?: boolean;
14
+ id?: string;
14
15
  }
15
16
  declare const ChatInput: React.FC<ChatInputProps>;
16
17
  export default ChatInput;
@@ -1 +1 @@
1
- {"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../../src/components/ChatInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAQ1E,UAAU,cAAc;IACtB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAoED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAkLvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../../src/components/ChatInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAQ1E,UAAU,cAAc;IACtB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAoED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoLvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),i=require("./FileThumbnail.js"),t=require("../hooks/useStateWithLocalStorage.js");require("../services/codicent.js"),require("./Markdown.js");var s=require("./Textarea.js");require("./Button.js"),require("./Spinner.js"),require("./TextHeader.js"),require("./TypingIndicator.js"),require("./Dialog.js"),require("./CombinedPlaceholderDialog.js"),require("./ChatMessage.js"),require("./Header.js"),require("../utils/MessageContent.js"),require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/index.js");var a=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"),require("./MessageInput.js"),require("./UploadFile.js"),require("./SnapFooter.js"),require("./Profile.js"),require("./MessageItem.js"),require("./Content.js"),require("./AiInput.js"),require("./SearchBox.js"),require("./HtmlView.js"),require("./Footer.js"),require("./Page.js"),require("../pages/AppFrame.js"),require("../pages/Snap.js"),require("../pages/Search.js"),require("../pages/Login.js"),require("../pages/CrmPage.js"),require("../pages/ImageView.js"),require("../pages/FormInvite.js"),require("../pages/FormAccept.js"),require("../pages/Sales.js"),require("../stores/chatStore.js");var o=require("../hooks/useLocalization.js"),l=require("../hooks/useAppStyles.js"),n=require("../node_modules/@griffel/react/makeStyles.esm.js"),u=require("../node_modules/@fluentui/react-button/lib/components/Button/Button.js"),c=require("../node_modules/@fluentui/react-spinner/lib/components/Spinner/Spinner.js"),d=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-3.js"),p=require("../node_modules/@griffel/core/mergeClasses.esm.js"),g=require("../node_modules/@fluentui/tokens/lib/tokens.js"),j=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-0.js");const f=n.makeStyles({inputContainer:{display:"flex",flexDirection:"column",padding:"8px",width:"100%",position:"relative",gap:"8px"},textareaWrapper:{position:"relative",width:"100%",display:"flex",flexDirection:"column"},actionButtonRow:{position:"absolute",left:"8px",bottom:"8px",right:"8px",zIndex:1,display:"flex",justifyContent:"space-between",alignItems:"center"},fileList:{display:"flex",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"thin",msOverflowStyle:"none",padding:"4px 0",maxWidth:"100%",boxSizing:"border-box",gap:"4px",minHeight:"72px",backgroundColor:g.tokens.colorNeutralBackground2,borderRadius:g.tokens.borderRadiusMedium,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:g.tokens.colorNeutralStroke1,borderRadius:"3px"}},hiddenInput:{display:"none"},button:{color:g.tokens.colorNeutralForeground2,"&:hover":{color:g.tokens.colorBrandBackground,backgroundColor:"transparent"}}});exports.default=({onSend:n,disableSend:g,onSelectFiles:m,getImageUrl:q,getFileInfo:x,codicent:b,defaultText:h,rows:S,noMemory:k,selectAll:v})=>{const _=f(),[y,w]=t.default("chatInput-"+b,""),T=r.useRef(null),[C,N]=r.useState([]),[B,D]=r.useState([]),[F,E]=r.useState(!1),[O,I]=r.useState([]),{t:A}=o.default(),P=l.default();r.useEffect((()=>{h&&w(h)}),[w,h]),r.useEffect((()=>{!0===k&&w("")}),[k,w]);const R=()=>{if(""===y.trim()&&0===O.length)return;const e=C.length>0?" #"+C.join(" #"):"",r=B.length>0?"\n#file:"+B.join("\n#file:"):"";n(e+y+r),w(""),N([]),D([]),I([])};return e.jsxs("div",{className:_.inputContainer,children:[e.jsx("input",{title:A("Välj fil att ladda upp"),type:"file",ref:T,className:_.hiddenInput,onChange:async e=>{const r=e.target.files;if(r&&r.length>0&&m){E(!0);try{const e=await m(r),i=await Promise.all(e.map((e=>x(e))));D((r=>[...r,...e])),I((e=>[...e,...i]))}catch(e){console.error("Failed to upload files",e)}finally{E(!1),T.current&&(T.current.value="")}}},multiple:!0,accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.txt"}),O.length>0&&e.jsx("div",{className:_.fileList,children:O.map((r=>e.jsx(i.FileThumbnail,{file:r,getImageUrl:q,onDelete:()=>{return e=r.id,D((r=>r.filter((r=>r!==e)))),void I((r=>r.filter((r=>r.id!==e))));var e}},r.id)))}),e.jsxs("div",{className:_.textareaWrapper,onPaste:async e=>{for(const r of e.clipboardData.items)if(-1!==r.type.indexOf("image")){const i=r.getAsFile();if(i&&(e.preventDefault(),m))try{E(!0);const e=new DataTransfer;e.items.add(i);const r=await m(e.files),t=await Promise.all(r.map((e=>x(e))));D((e=>[...e,...r])),I((e=>[...e,...t]))}catch(e){console.error("Failed to upload pasted image",e)}finally{E(!1)}}},children:[e.jsx(s.Textarea,{size:"large",placeholder:A(a.getConfigValue("APP_CHAT_TEXT_PLACEHOLDER")||"Skriv ditt meddelande här..."),value:y,onChange:e=>w(e.target.value),onKeyDown:e=>{g||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),R())},autoFocus:!1,rows:S||4,onFocus:e=>{if(!0===v){e.target.select()}}}),e.jsxs("div",{className:_.actionButtonRow,children:[e.jsx("div",{children:m&&e.jsx(u.Button,{appearance:"subtle",size:"small",title:A("Lägg till fil"),icon:F?e.jsx(c.Spinner,{}):e.jsx(j.AddRegular,{}),onClick:()=>T.current?.click(),className:_.button})}),e.jsx(u.Button,{appearance:a.getConfigValue("SHOW_SEND_BUTTON_TEXT")?"primary":"subtle",size:a.getConfigValue("SHOW_SEND_BUTTON_TEXT")?"small":"large",title:A("Skicka"),disabled:g,icon:""===y.trim()&&0===O.length?e.jsx(d.SendRegular,{}):e.jsx(d.SendFilled,{}),onClick:R,className:a.getConfigValue("SEND_BUTTON_ROUND_BACKGROUND")?p.mergeClasses(P.roundButton,_.button):a.getConfigValue("SHOW_SEND_BUTTON_TEXT")?void 0:_.button,children:a.getConfigValue("SHOW_SEND_BUTTON_TEXT")&&e.jsx("span",{children:A("Skicka")})})]})]})]})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),i=require("./FileThumbnail.js"),t=require("../hooks/useStateWithLocalStorage.js");require("../services/codicent.js"),require("./Markdown.js");var s=require("./Textarea.js");require("./Button.js"),require("./Spinner.js"),require("./TextHeader.js"),require("./TypingIndicator.js"),require("./Dialog.js"),require("./CombinedPlaceholderDialog.js"),require("./ChatMessage.js"),require("./Header.js"),require("../utils/MessageContent.js"),require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/index.js");var a=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"),require("./MessageInput.js"),require("./UploadFile.js"),require("./SnapFooter.js"),require("./Profile.js"),require("./MessageItem.js"),require("./Content.js"),require("./AiInput.js"),require("./SearchBox.js"),require("./HtmlView.js"),require("./Footer.js"),require("./Page.js"),require("../pages/AppFrame.js"),require("../pages/Snap.js"),require("../pages/Search.js"),require("../pages/Login.js"),require("../pages/CrmPage.js"),require("../pages/ImageView.js"),require("../pages/FormInvite.js"),require("../pages/FormAccept.js"),require("../pages/Sales.js"),require("../stores/chatStore.js");var o=require("../hooks/useLocalization.js"),l=require("../hooks/useAppStyles.js"),n=require("../node_modules/@griffel/react/makeStyles.esm.js"),u=require("../node_modules/@fluentui/react-button/lib/components/Button/Button.js"),c=require("../node_modules/@fluentui/react-spinner/lib/components/Spinner/Spinner.js"),d=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-3.js"),p=require("../node_modules/@griffel/core/mergeClasses.esm.js"),g=require("../node_modules/@fluentui/tokens/lib/tokens.js"),j=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-0.js");const f=n.makeStyles({inputContainer:{display:"flex",flexDirection:"column",padding:"8px",width:"100%",position:"relative",gap:"8px"},textareaWrapper:{position:"relative",width:"100%",display:"flex",flexDirection:"column"},actionButtonRow:{position:"absolute",left:"8px",bottom:"8px",right:"8px",zIndex:1,display:"flex",justifyContent:"space-between",alignItems:"center"},fileList:{display:"flex",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"thin",msOverflowStyle:"none",padding:"4px 0",maxWidth:"100%",boxSizing:"border-box",gap:"4px",minHeight:"72px",backgroundColor:g.tokens.colorNeutralBackground2,borderRadius:g.tokens.borderRadiusMedium,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:g.tokens.colorNeutralStroke1,borderRadius:"3px"}},hiddenInput:{display:"none"},button:{color:g.tokens.colorNeutralForeground2,"&:hover":{color:g.tokens.colorBrandBackground,backgroundColor:"transparent"}}});exports.default=({onSend:n,disableSend:g,onSelectFiles:m,getImageUrl:q,getFileInfo:x,codicent:h,defaultText:b,rows:S,noMemory:k,selectAll:v,id:_})=>{const y=f(),[w,T]=t.default("chatInput-"+h,""),C=r.useRef(null),[N,B]=r.useState([]),[D,F]=r.useState([]),[E,O]=r.useState(!1),[I,A]=r.useState([]),{t:P}=o.default(),R=l.default();r.useEffect((()=>{b&&T(b)}),[T,b]),r.useEffect((()=>{!0===k&&T("")}),[k,T]);const H=()=>{if(""===w.trim()&&0===I.length)return;const e=N.length>0?" #"+N.join(" #"):"",r=D.length>0?"\n#file:"+D.join("\n#file:"):"";n(e+w+r),T(""),B([]),F([]),A([])};return e.jsxs("div",{className:y.inputContainer,children:[e.jsx("input",{title:P("Välj fil att ladda upp"),type:"file",ref:C,className:y.hiddenInput,onChange:async e=>{const r=e.target.files;if(r&&r.length>0&&m){O(!0);try{const e=await m(r),i=await Promise.all(e.map((e=>x(e))));F((r=>[...r,...e])),A((e=>[...e,...i]))}catch(e){console.error("Failed to upload files",e)}finally{O(!1),C.current&&(C.current.value="")}}},multiple:!0,accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.txt"}),I.length>0&&e.jsx("div",{className:y.fileList,children:I.map((r=>e.jsx(i.FileThumbnail,{file:r,getImageUrl:q,onDelete:()=>{return e=r.id,F((r=>r.filter((r=>r!==e)))),void A((r=>r.filter((r=>r.id!==e))));var e}},r.id)))}),e.jsxs("div",{className:y.textareaWrapper,onPaste:async e=>{for(const r of e.clipboardData.items)if(-1!==r.type.indexOf("image")){const i=r.getAsFile();if(i&&(e.preventDefault(),m))try{O(!0);const e=new DataTransfer;e.items.add(i);const r=await m(e.files),t=await Promise.all(r.map((e=>x(e))));F((e=>[...e,...r])),A((e=>[...e,...t]))}catch(e){console.error("Failed to upload pasted image",e)}finally{O(!1)}}},children:[e.jsx(s.Textarea,{size:"large",id:_||"chat-input",placeholder:P(a.getConfigValue("APP_CHAT_TEXT_PLACEHOLDER")||"Skriv ditt meddelande här..."),value:w,onChange:e=>T(e.target.value),onKeyDown:e=>{g||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),H())},autoFocus:!1,rows:S||4,onFocus:e=>{if(!0===v){e.target.select()}}}),e.jsxs("div",{className:y.actionButtonRow,children:[e.jsx("div",{children:m&&e.jsx(u.Button,{appearance:"subtle",size:"small",title:P("Lägg till fil"),icon:E?e.jsx(c.Spinner,{}):e.jsx(j.AddRegular,{}),onClick:()=>C.current?.click(),className:y.button})}),e.jsx(u.Button,{appearance:a.getConfigValue("SHOW_SEND_BUTTON_TEXT")?"primary":"subtle",size:a.getConfigValue("SHOW_SEND_BUTTON_TEXT")?"small":"large",title:P("Skicka"),disabled:g,icon:""===w.trim()&&0===I.length?e.jsx(d.SendRegular,{}):e.jsx(d.SendFilled,{}),onClick:H,className:a.getConfigValue("SEND_BUTTON_ROUND_BACKGROUND")?p.mergeClasses(R.roundButton,y.button):a.getConfigValue("SHOW_SEND_BUTTON_TEXT")?void 0:y.button,children:a.getConfigValue("SHOW_SEND_BUTTON_TEXT")&&e.jsx("span",{children:P("Skicka")})})]})]})]})};
@@ -1 +1 @@
1
- {"version":3,"file":"ChatMessage.d.ts","sourceRoot":"","sources":["../../../src/components/ChatMessage.tsx"],"names":[],"mappings":"AAoBA,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAgDD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAiD3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"ChatMessage.d.ts","sourceRoot":"","sources":["../../../src/components/ChatMessage.tsx"],"names":[],"mappings":"AAoBA,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAgDD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAyD3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime");require("react"),require("../services/codicent.js");var r=require("./Markdown.js");require("./Textarea.js");var s=require("./Button.js");require("./Spinner.js"),require("./TextHeader.js"),require("./TypingIndicator.js"),require("./Dialog.js"),require("./ChatInput.js"),require("./CombinedPlaceholderDialog.js"),require("./Header.js");var t=require("../utils/MessageContent.js");require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/index.js");var i=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"),require("./FileThumbnail.js"),require("./MessageInput.js"),require("./UploadFile.js"),require("./SnapFooter.js"),require("./Profile.js"),require("./MessageItem.js"),require("./Content.js"),require("./AiInput.js"),require("./SearchBox.js"),require("./HtmlView.js"),require("./Footer.js"),require("./Page.js"),require("../pages/AppFrame.js"),require("../pages/Snap.js"),require("../pages/Search.js"),require("../pages/Login.js"),require("../pages/CrmPage.js"),require("../pages/ImageView.js"),require("../pages/FormInvite.js"),require("../pages/FormAccept.js"),require("../pages/Sales.js"),require("../stores/chatStore.js");var o=require("../hooks/useLocalization.js");require("../hooks/useAppStyles.js");var a=require("../node_modules/@griffel/react/makeStyles.esm.js"),n=require("../node_modules/@fluentui/tokens/lib/tokens.js"),u=require("../node_modules/@griffel/core/mergeClasses.esm.js"),l=require("../node_modules/@fluentui/react-text/lib/components/Text/Text.js"),d=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js");const c=a.makeStyles({message:{display:"flex",marginBottom:"16px",webkitUserSelect:"text",userSelect:"text"},user:{justifyContent:"flex-end"},bot:{justifyContent:"flex-start"},messageContent:{maxWidth:"80%",padding:"12px 16px",borderRadius:"16px",fontSize:"1rem",lineHeight:"1.4",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},userMessage:{backgroundColor:i.getConfigValue("CHAT_USER_BACKGROUND_COLOR")||n.tokens.colorBrandBackground,color:i.getConfigValue("CHAT_USER_TEXT_COLOR")||n.tokens.colorNeutralForegroundInverted,borderTopRightRadius:"0"},botMessage:{backgroundColor:i.getConfigValue("CHAT_BOT_BACKGROUND_COLOR")||n.tokens.colorBrandBackground2,color:i.getConfigValue("CHAT_BOT_TEXT_COLOR")||n.tokens.colorNeutralForeground1,borderTopLeftRadius:"0"},newMessage:{animation:"$fadeIn 0.5s ease-in-out"}});exports.default=({sender:i,content:a,isNew:n,children:g,showSuggestions:j,onSuggestionClicked:p})=>{const q=c(),{t:m}=o.default();let f=[];if("bot"===i&&a.includes("#suggested_questions")){const e=a.split("#suggested_questions");a=e[0],f=e[1].split("\n").filter((e=>""!==e.trim())).map((e=>e.trim()))}const x=new t.default(a);let C=x.content;"user"===i&&x.content.includes("---")&&(C=x.content.split("---")[0]);const _=x.content.startsWith("Error code: ")?m("Ett fel uppstod 😟 => starta en ny chatt"):null;return e.jsx("div",{className:u.mergeClasses(q.message,"user"===i?q.user:q.bot),children:e.jsxs("div",{className:u.mergeClasses(q.messageContent,"user"===i?q.userMessage:q.botMessage,n&&q.newMessage),children:[e.jsxs(l.Text,{size:400,children:[_,!_&&e.jsx(r.default,{content:C}),x.files.length>0&&e.jsx(d.ChannelRegular,{}),j&&f&&f.length>0&&e.jsx("div",{style:{marginTop:"8px",display:"flex",gap:"8px",flexWrap:"wrap"},children:f.map(((r,t)=>e.jsx(s.Button,{size:"small",shape:"circular",onClick:()=>p?.(r),style:{textAlign:"left"},children:r},t)))})]}),g]})})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime");require("react"),require("../services/codicent.js");var r=require("./Markdown.js");require("./Textarea.js");var s=require("./Button.js");require("./Spinner.js"),require("./TextHeader.js"),require("./TypingIndicator.js"),require("./Dialog.js"),require("./ChatInput.js"),require("./CombinedPlaceholderDialog.js"),require("./Header.js");var t=require("../utils/MessageContent.js");require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/index.js");var i=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"),require("./FileThumbnail.js"),require("./MessageInput.js"),require("./UploadFile.js"),require("./SnapFooter.js"),require("./Profile.js"),require("./MessageItem.js"),require("./Content.js"),require("./AiInput.js"),require("./SearchBox.js"),require("./HtmlView.js"),require("./Footer.js"),require("./Page.js"),require("../pages/AppFrame.js"),require("../pages/Snap.js"),require("../pages/Search.js"),require("../pages/Login.js"),require("../pages/CrmPage.js"),require("../pages/ImageView.js"),require("../pages/FormInvite.js"),require("../pages/FormAccept.js"),require("../pages/Sales.js"),require("../stores/chatStore.js");var o=require("../hooks/useLocalization.js");require("../hooks/useAppStyles.js");var a=require("../node_modules/@griffel/react/makeStyles.esm.js"),n=require("../node_modules/@griffel/core/mergeClasses.esm.js"),u=require("../node_modules/@fluentui/tokens/lib/tokens.js"),l=require("../node_modules/@fluentui/react-text/lib/components/Text/Text.js"),d=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js");const c=a.makeStyles({message:{display:"flex",marginBottom:"16px",webkitUserSelect:"text",userSelect:"text"},user:{justifyContent:"flex-end"},bot:{justifyContent:"flex-start"},messageContent:{maxWidth:"80%",padding:"12px 16px",borderRadius:"16px",fontSize:"1rem",lineHeight:"1.4",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},userMessage:{borderTopRightRadius:"0"},botMessage:{borderTopLeftRadius:"0"},newMessage:{animation:"$fadeIn 0.5s ease-in-out"}});exports.default=({sender:a,content:g,isNew:j,children:p,showSuggestions:q,onSuggestionClicked:m})=>{const f=c(),{t:x}=o.default();let C=[];if("bot"===a&&g.includes("#suggested_questions")){const e=g.split("#suggested_questions");g=e[0],C=e[1].split("\n").filter((e=>""!==e.trim())).map((e=>e.trim()))}const _=new t.default(g);let h=_.content;"user"===a&&_.content.includes("---")&&(h=_.content.split("---")[0]);const b=_.content.startsWith("Error code: ")?x("Ett fel uppstod 😟 => starta en ny chatt"):null;return e.jsx("div",{className:n.mergeClasses(f.message,"user"===a?f.user:f.bot),children:e.jsxs("div",{className:n.mergeClasses(f.messageContent,"user"===a?f.userMessage:f.botMessage,j&&f.newMessage),style:{backgroundColor:"user"===a?i.getConfigValue("CHAT_USER_BACKGROUND_COLOR")||u.tokens.colorBrandBackground:i.getConfigValue("CHAT_BOT_BACKGROUND_COLOR")||u.tokens.colorBrandBackground2,color:"user"===a?i.getConfigValue("CHAT_USER_TEXT_COLOR")||u.tokens.colorNeutralForegroundInverted:i.getConfigValue("CHAT_BOT_TEXT_COLOR")||u.tokens.colorNeutralForeground1},children:[e.jsxs(l.Text,{size:400,children:[b,!b&&e.jsx(r.default,{content:h}),_.files.length>0&&e.jsx(d.ChannelRegular,{}),q&&C&&C.length>0&&e.jsx("div",{style:{marginTop:"8px",display:"flex",gap:"8px",flexWrap:"wrap"},children:C.map(((r,t)=>e.jsx(s.Button,{size:"small",shape:"circular",onClick:()=>m?.(r),style:{textAlign:"left"},children:r},t)))})]}),p]})})};
@@ -11,6 +11,7 @@ export interface TextareaProps {
11
11
  className?: string;
12
12
  onFocus?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
13
13
  onPaste?: (event: React.ClipboardEvent<HTMLTextAreaElement>) => void;
14
+ id?: string;
14
15
  }
15
16
  export declare const Textarea: React.FC<TextareaProps>;
16
17
  //# sourceMappingURL=Textarea.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;CACtE;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAkB5C,CAAC"}
1
+ {"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACrE,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAkB5C,CAAC"}
@@ -1 +1 @@
1
- "use strict";var t,e=require("../node_modules/@stripe/stripe-js/dist/index.js"),n=require("../utils/MessageContent.js");require("../node_modules/tinycolor2/esm/tinycolor.js"),require("react/jsx-runtime"),require("react"),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");let o="https://codicent.com/",a="-";const i=()=>void 0!==window.Codicent&&(window.Codicent.init({token:a,baseUrl:o}),window.Codicent.handleMessage=function(t){const e=new CustomEvent("codicent-log",{detail:{message:t}});window.dispatchEvent(e)},!0);let s=i();if(!s){const t=setInterval((()=>{s=i(),s&&clearInterval(t)}),100)}class r{constructor(t){this.createDataMessage=async(t,e)=>await window.Codicent.data.create({codicent:this.codicent,tag:t,data:e}),this.readDataMessages=async(t,e)=>await window.Codicent.data.read({codicent:this.codicent,tag:t,search:e}),this.readOneDataMessage=async t=>await window.Codicent.data.readOne(t),this.updateDataMessage=async(t,e)=>await window.Codicent.data.update({id:t,data:e,codicent:this.codicent}),this.deleteDataMessage=async t=>await window.Codicent.data.delete({id:t,codicent:this.codicent}),this.getAppTheme=async()=>{try{const t=await window.Codicent.getDataMessages({tags:["app-theme"],codicent:this.codicent});return t.length>0?t[0].data:null}catch(t){return console.error("Error fetching app theme:",t),null}},this.getAppButtons=async()=>{const t=(await window.Codicent.getDataMessages({tags:[this.options.BUTTON_TAG],codicent:this.codicent})).map((t=>t.data));return t.sort(((t,e)=>t.title>e.title?1:-1)),t},this.getAppTasks=async()=>(await window.Codicent.getMessages({search:`@${this.codicent} #app-task`,length:50})).map((t=>{const e=new n.default(t.content).content.split("\n"),o=e[0],a=e.slice(1).join("\n");return{id:t.id,title:o,content:a}})),this.getAppPrompts=async()=>(await window.Codicent.getDataMessages({tags:["chatprompt"],codicent:this.codicent})).map((t=>t.data)).map((({title:t,prompt:e})=>({title:t,prompt:e}))),this.uploadFile=async(t,e)=>await window.Codicent.upload(e,t),this.getFileInfo=async t=>await window.Codicent.getFileInfo(t),this.sendMessage=(t,e)=>window.Codicent.postMessage({message:`@${this.codicent} ${t}`,type:"text",parentId:e}),this.chat=(t,e)=>window.Codicent.getChatReply3({message:t,codicent:this.codicent,messageId:e}),this.getMessagesFast=async(t,e,n=100,a=void 0)=>{const i=await fetch(`${o}app/AppGetMessages`,{method:"POST",headers:[["Authorization",`Bearer ${this.getToken()}`],["Content-Type","application/json; charset=utf-8"]],body:JSON.stringify({tags:t,codicent:this.codicent,search:e,length:n})});if(!i.ok)throw 401===i.status&&this.handleUnauthorized(),new Error(`${i.statusText}`);let s=await i.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),a){const t=await this.getPublicFlow(a);s=s.concat(t),s.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime()))}return s},this.getMessages=async(t,e)=>{let n=[];for(const e of t){const t=await window.Codicent.getMessages({search:`@${this.codicent} #${e}`,length:10});"chat"===e&&t.forEach((t=>t.content=`#chat\n${t.content}`)),n=n.concat(t)}if(e)try{const t=await this.getPublicFlow(e);n=n.concat(t)}catch(t){console.warn("Error fetching public flow, PUBLIC_TAG missing in codicent?",t)}return n=n.filter(((t,e,n)=>e===n.findIndex((e=>e.id===t.id)))),n.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime())),n},this.registerUser=async(t,e,n,a)=>{const i=await fetch(`${o}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${a}`]],body:JSON.stringify({nickname:t,email:e,userId:n})});if(!i.ok)return"";const s=await i.text();return window.Codicent.init({token:a,baseUrl:o}),s},this.loginUser=async(t,e)=>{try{const n=await fetch(`${o}app/LoginAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${e}`]],body:JSON.stringify({userId:t})});if(!n.ok)return 404===n.status||400===n.status?null:401===n.status?(this.handleUnauthorized(),null):"";const a=await n.text();return this.setToken(a),a}catch(t){return console.warn("Error logging in user:",t),""}},this.nicknameExists=async t=>{const e=await fetch(`${o}app/NicknameExists?nickname=${encodeURIComponent(t)}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"]]});if(!e.ok)return!1;return await e.json()},this.logout=()=>{this.setToken("")},this.isRegistered=()=>null!==localStorage.getItem("codicent_nickname"),this.getApps=async()=>{try{const t=await fetch(`${o}app/AppGetApps`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw t.status,new Error(`${t.statusText}`);const e=(await t.json()).filter(((t,e,n)=>e===n.findIndex((e=>e.id===t.id))&&(this.options.APP_NAME||t.id.startsWith(this.options.APP_PREFIX))));return e}catch(t){return console.warn("Error fetching apps:",t),null}},this.addFollower=async(t,e)=>{const n=await fetch(`${o}app/AddFollower?nickname=${t}&followerNickname=${e}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!n.ok)throw n.status,new Error(`${n.statusText||"Failed to add follower!"}`);return await n.json()},this.cloneProject=async(t,e)=>{const n=await fetch(`${o}app/CloneProject?project=${t}&newProject=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!n.ok)throw n.status,new Error(`${n.statusText}`);let a=await n.json();if(a){const t='#data #app-theme \n{\n "textcolor": "#212121",\n "backgroundcolor": "#273044",\n "color": "#ffffff",\n "logo": "https://codicent.com/logo512.png",\n "title": "",\n "themeColor": "#581d71",\n "buttonColor": "#c0c0c0",\n "buttonTextColor": "#000000",\n "font": "Montserrat",\n "welcome": "Hej {{username}}!",\n "chatPlaceholder": "Tjena, Loociz här! Vad vill du?",\n "textPlaceholder": "Skriv det du vill spara, så tar jag (Loociz alltså) hand om det!",\n "transcriptionInstructions": "Tryck på knappen för att start och sedan stoppa ljudinspelning."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}if(a){const t='#data #app-button\n{\n "title": "Ta fram företagsinfo",\n "url": "/#/chat?text=Hej!%20Jag%20vill%20spara%20f%C3%B6retagsinfo.%20Guida%20mig%20steg%20f%C3%B6r%20steg%2C%20ett%20i%20taget%2C%20tills%20vi%20har%20all%20info%20om%20mitt%20f%C3%B6retag.%20Exempel%20p%C3%A5%20data%3A%20f%C3%B6retagsnamn%20eller%20id%C3%A9namn%2C%20org.nr.%2C%20%C3%A4gare%2C%20kontaktinformation%2C%20vision%2C%20aff%C3%A4rsid%C3%A9%2C%20mm."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}}}return a},this.getNickname=async()=>{try{const t=a.split(".")[1],e=atob(t),n=JSON.parse(e),i=n.sub||n.userId,s=await fetch(`${o}app/GetNickname?userId=${i}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${s.statusText}`);return await s.text()}catch{return""}},this.getChatInstructions=async()=>{try{const t=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:1});if(t.length>0)return t[0].content}catch{console.warn("Error fetching chat instructions")}return""},this.updateChatInstructions=async t=>{try{const e=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:100}),n=`@${this.codicent} #instructions\n${t}`;e.length>0?e[0].content!==n&&(console.log("updating instructions",n),await window.Codicent.postMessage({message:n,type:"text",parentId:e[0].id})):(console.log("new instructions",n),await window.Codicent.postMessage({message:n,type:"text"}))}catch{console.warn("Error updating chat instructions")}},this.getUserInfo=async(t,e=!1)=>{const n=await fetch(`${o}/app/GetUserInfo?nickname=${t}${e?"&t="+Date.now():""}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!n.ok)throw 401===n.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${n.statusText}`);const a=await n.json(),{email:i,picture:s,description:r,followers:c,properties:h,owner:d}=a;return{nickname:t,email:i,name:r,picture:s,followers:c,properties:h,owner:d}},this.updateUserInfo=async({nickname:t,email:e,name:n,picture:a})=>{const i=await fetch(`${o}/app/AddOrUpdateUser`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({nickname:t,email:e,name:n,picture:a,description:""})});if(!i.ok)throw i.status,new Error(`${i.statusText}`);return await this.getUserInfo(t,!0)},this.requestInvite=async(t,e)=>{const n=await fetch(`${o}/app/CreateInvitationOrRequest?forUserNickname=${t}&toProjectNickname=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!n.ok||(console.warn(`requestInvite() => ${n.statusText}`),!1)},this.getProjectInfo=this.getUserInfo,this.updateMembersAccess=async(t,e)=>{const n=await fetch(`${o}/app/AddOrUpdateProjectProperty?project=${t}&key=APP_EDITORS&value=${e.join(",")}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!n.ok||(console.warn(`updateMembersAccess() => ${n.statusText}`),!1)},this.getMembersAccess=async t=>{const e=(await this.getProjectInfo(t,!0)).properties.find((t=>"APP_EDITORS"===t.name));return e&&e.value?e.value.split(","):[]},this.setToken=t=>{a=t,a&&window.Codicent.init({token:a,baseUrl:o})},this.getToken=()=>a,this.checkPurchaseStatus=async()=>{const t=await fetch(`${o}payments/GetPaymentStatus`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw new Error("Failed to check purchase status");const{isPaid:e}=await t.json();return e},this.checkSubscriptionStatus=async()=>{if(!this.options.SUBSCRIPTION_NEEDED)return"active";const t=await fetch(`${o}payments/GetSubscriptionStatus?t=${Date.now()}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`],["Cache-Control","no-cache, no-store, must-revalidate"],["Pragma","no-cache"],["Expires","0"]]});if(!t.ok)throw new Error("Failed to check subscription status");const{status:e}=await t.json();return e},this.createCheckoutSession=async t=>{const e=await fetch(`${o}payments/CreateCheckoutSession`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({priceId:t,successUrl:window.location.href,cancelUrl:window.location.href})});if(!e.ok)throw new Error("Failed to create checkout session");const{id:n}=await e.json();return n},this.redirectToCheckout=async t=>{const n=await e.loadStripe(this.options.STRIPE_PUBLIC_KEY);if(!n)throw new Error("Stripe failed to load");const o=await this.createCheckoutSession(t),{error:a}=await n.redirectToCheckout({sessionId:o});if(a)throw new Error(a.message)},this.getChatHistory=async t=>{const e=await fetch(`${o}api/GetMessageHistory?messageId=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get chat history");let n=await e.json();return n=n.filter((t=>!t.content.includes("#function_result")&&!t.content.includes("#finish_reason_function_call"))),n},this.getPublicFlow=async t=>{const e=await fetch(`${o}/app/GetPublicFlow?codicent=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get public flow");const n=await e.json();return n.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),n},this.getMessageContent=async t=>{const e=await fetch(`${o}app/GetMessageContent?id=${t}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(e.ok){const t=await e.json();return{content:t.content,url:t.url}}return{content:"",url:""}},this.logAction=async(t,e)=>{if(!this.options.APP_LOG_CODICENT)return"";const n={content:`@${this.options.APP_LOG_CODICENT} #debug #${e}\n${t}`,type:"text"},a=await fetch(`${o}app/AddChatMessage`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.options.APP_LOG_TOKEN}`]],body:JSON.stringify(n)});if(!a.ok)throw new Error(`${a.statusText||"Failed to post log message!"}`);return(await a.json()).id},this.createApp=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.APP_PREFIX}${t}`;if(!await this.nicknameExists(e)){if(await this.cloneProject(this.options.APP_TEMPLATE,e)){if(this.options.ANONYMOUS_TOKEN)try{const t=this.options.ANONYMOUS_TOKEN.split(".")[1],n=atob(t),o=JSON.parse(n).nickname;if(!await this.addFollower(e,o))throw new Error("Failed to add follower: "+o)}catch(t){console.error("Error extracting adding anonymous follower:",t)}return e}}}}catch(t){console.error("Error creating app:",t)}return null},this.findUsername=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.USER_PREFIX}${t}`;if(!await this.nicknameExists(e))return e}}catch(t){console.warn("Error finding username:",t)}return null},this.getForms=async()=>{const t=await fetch(`${o}app/GetForms?codicent=${this.codicent}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await t.json()},this.getFormById=async t=>{const e=await fetch(`${o}app/GetFormById?id=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await e.json()},this.codicent="",this.options=t}handleUnauthorized(){this.onUnauthorized&&this.onUnauthorized()}}t=r,r.getImageUrl=(t,e)=>`${o}app/GetImage?fileId=${t}&width=${e}`,r.getFileUrl=(t,e)=>`${o}app/DownloadFile?fileId=${t}${e?`&extension=${e}`:""}`,r.downloadFile=async e=>{fetch(t.getFileUrl(e.id)).then((t=>{if(t.headers.forEach(((t,e)=>{console.log(`${e}: ${t}`)})),t.ok)return t.blob();throw new Error("Network response was not ok.")})).then((t=>{const n=window.URL.createObjectURL(t),o=document.createElement("a");o.style.display="none",o.href=n,o.download=e.filename,document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n)})).catch((t=>{console.error("There was a problem with the fetch operation:",t)}))},r.getMiniChatReply=async(t,e="codicent-mini",n)=>{const a=await fetch(`${o}app/GetAi2ChatReply?message=${t}&project=${e}${n?"&messageId="+n:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!a.ok)return void a.status;return(await a.json()).content.replace("@codicent-mini","").trim()},exports.CodicentService=r;
1
+ "use strict";var t,e=require("../node_modules/@stripe/stripe-js/dist/index.js"),n=require("../utils/MessageContent.js");require("../node_modules/tinycolor2/esm/tinycolor.js"),require("react/jsx-runtime"),require("react"),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");let o="https://codicent.com/",a="-";const i=()=>void 0!==window.Codicent&&(window.Codicent.handleMessage=function(t){const e=new CustomEvent("codicent-log",{detail:{message:t}});window.dispatchEvent(e)},window.Codicent.init({token:a,baseUrl:o}),!0);let s=i();if(!s){const t=setInterval((()=>{s=i(),s&&clearInterval(t)}),100)}class r{constructor(t){this.createDataMessage=async(t,e)=>await window.Codicent.data.create({codicent:this.codicent,tag:t,data:e}),this.readDataMessages=async(t,e)=>await window.Codicent.data.read({codicent:this.codicent,tag:t,search:e}),this.readOneDataMessage=async t=>await window.Codicent.data.readOne(t),this.updateDataMessage=async(t,e)=>await window.Codicent.data.update({id:t,data:e,codicent:this.codicent}),this.deleteDataMessage=async t=>await window.Codicent.data.delete({id:t,codicent:this.codicent}),this.getAppTheme=async()=>{try{const t=await window.Codicent.getDataMessages({tags:["app-theme"],codicent:this.codicent});return t.length>0?t[0].data:null}catch(t){return console.error("Error fetching app theme:",t),null}},this.getAppButtons=async()=>{const t=(await window.Codicent.getDataMessages({tags:[this.options.BUTTON_TAG],codicent:this.codicent})).map((t=>t.data));return t.sort(((t,e)=>t.title>e.title?1:-1)),t},this.getAppTasks=async()=>(await window.Codicent.getMessages({search:`@${this.codicent} #app-task`,length:50})).map((t=>{const e=new n.default(t.content).content.split("\n"),o=e[0],a=e.slice(1).join("\n");return{id:t.id,title:o,content:a}})),this.getAppPrompts=async()=>(await window.Codicent.getDataMessages({tags:["chatprompt"],codicent:this.codicent})).map((t=>t.data)).map((({title:t,prompt:e})=>({title:t,prompt:e}))),this.uploadFile=async(t,e)=>await window.Codicent.upload(e,t),this.getFileInfo=async t=>await window.Codicent.getFileInfo(t),this.sendMessage=(t,e)=>window.Codicent.postMessage({message:`@${this.codicent} ${t}`,type:"text",parentId:e}),this.chat=(t,e)=>window.Codicent.getChatReply3({message:t,codicent:this.codicent,messageId:e}),this.getMessagesFast=async(t,e,n=100,a=void 0)=>{const i=await fetch(`${o}app/AppGetMessages`,{method:"POST",headers:[["Authorization",`Bearer ${this.getToken()}`],["Content-Type","application/json; charset=utf-8"]],body:JSON.stringify({tags:t,codicent:this.codicent,search:e,length:n})});if(!i.ok)throw 401===i.status&&this.handleUnauthorized(),new Error(`${i.statusText}`);let s=await i.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),a){const t=await this.getPublicFlow(a);s=s.concat(t),s.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime()))}return s},this.getMessages=async(t,e)=>{let n=[];for(const e of t){const t=await window.Codicent.getMessages({search:`@${this.codicent} #${e}`,length:10});"chat"===e&&t.forEach((t=>t.content=`#chat\n${t.content}`)),n=n.concat(t)}if(e)try{const t=await this.getPublicFlow(e);n=n.concat(t)}catch(t){console.warn("Error fetching public flow, PUBLIC_TAG missing in codicent?",t)}return n=n.filter(((t,e,n)=>e===n.findIndex((e=>e.id===t.id)))),n.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime())),n},this.registerUser=async(t,e,n,a)=>{const i=await fetch(`${o}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${a}`]],body:JSON.stringify({nickname:t,email:e,userId:n})});if(!i.ok)return"";const s=await i.text();return window.Codicent.init({token:a,baseUrl:o}),s},this.loginUser=async(t,e)=>{try{const n=await fetch(`${o}app/LoginAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${e}`]],body:JSON.stringify({userId:t})});if(!n.ok)return 404===n.status||400===n.status?null:401===n.status?(this.handleUnauthorized(),null):"";const a=await n.text();return this.setToken(a),a}catch(t){return console.warn("Error logging in user:",t),""}},this.nicknameExists=async t=>{const e=await fetch(`${o}app/NicknameExists?nickname=${encodeURIComponent(t)}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"]]});if(!e.ok)return!1;return await e.json()},this.logout=()=>{this.setToken("")},this.isRegistered=()=>null!==localStorage.getItem("codicent_nickname"),this.getApps=async()=>{try{const t=await fetch(`${o}app/AppGetApps`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw t.status,new Error(`${t.statusText}`);const e=(await t.json()).filter(((t,e,n)=>e===n.findIndex((e=>e.id===t.id))&&(this.options.APP_NAME||t.id.startsWith(this.options.APP_PREFIX))));return e}catch(t){return console.warn("Error fetching apps:",t),null}},this.addFollower=async(t,e)=>{const n=await fetch(`${o}app/AddFollower?nickname=${t}&followerNickname=${e}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!n.ok)throw n.status,new Error(`${n.statusText||"Failed to add follower!"}`);return await n.json()},this.cloneProject=async(t,e)=>{const n=await fetch(`${o}app/CloneProject?project=${t}&newProject=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!n.ok)throw n.status,new Error(`${n.statusText}`);let a=await n.json();if(a){const t='#data #app-theme \n{\n "textcolor": "#212121",\n "backgroundcolor": "#273044",\n "color": "#ffffff",\n "logo": "https://codicent.com/logo512.png",\n "title": "",\n "themeColor": "#581d71",\n "buttonColor": "#c0c0c0",\n "buttonTextColor": "#000000",\n "font": "Montserrat",\n "welcome": "Hej {{username}}!",\n "chatPlaceholder": "Tjena, Loociz här! Vad vill du?",\n "textPlaceholder": "Skriv det du vill spara, så tar jag (Loociz alltså) hand om det!",\n "transcriptionInstructions": "Tryck på knappen för att start och sedan stoppa ljudinspelning."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}if(a){const t='#data #app-button\n{\n "title": "Ta fram företagsinfo",\n "url": "/#/chat?text=Hej!%20Jag%20vill%20spara%20f%C3%B6retagsinfo.%20Guida%20mig%20steg%20f%C3%B6r%20steg%2C%20ett%20i%20taget%2C%20tills%20vi%20har%20all%20info%20om%20mitt%20f%C3%B6retag.%20Exempel%20p%C3%A5%20data%3A%20f%C3%B6retagsnamn%20eller%20id%C3%A9namn%2C%20org.nr.%2C%20%C3%A4gare%2C%20kontaktinformation%2C%20vision%2C%20aff%C3%A4rsid%C3%A9%2C%20mm."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}}}return a},this.getNickname=async()=>{try{const t=a.split(".")[1],e=atob(t),n=JSON.parse(e),i=n.sub||n.userId,s=await fetch(`${o}app/GetNickname?userId=${i}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${s.statusText}`);return await s.text()}catch{return""}},this.getChatInstructions=async()=>{try{const t=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:1});if(t.length>0)return t[0].content}catch{console.warn("Error fetching chat instructions")}return""},this.updateChatInstructions=async t=>{try{const e=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:100}),n=`@${this.codicent} #instructions\n${t}`;e.length>0?e[0].content!==n&&(console.log("updating instructions",n),await window.Codicent.postMessage({message:n,type:"text",parentId:e[0].id})):(console.log("new instructions",n),await window.Codicent.postMessage({message:n,type:"text"}))}catch{console.warn("Error updating chat instructions")}},this.getUserInfo=async(t,e=!1)=>{const n=await fetch(`${o}/app/GetUserInfo?nickname=${t}${e?"&t="+Date.now():""}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!n.ok)throw 401===n.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${n.statusText}`);const a=await n.json(),{email:i,picture:s,description:r,followers:c,properties:h,owner:d}=a;return{nickname:t,email:i,name:r,picture:s,followers:c,properties:h,owner:d}},this.updateUserInfo=async({nickname:t,email:e,name:n,picture:a})=>{const i=await fetch(`${o}/app/AddOrUpdateUser`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({nickname:t,email:e,name:n,picture:a,description:""})});if(!i.ok)throw i.status,new Error(`${i.statusText}`);return await this.getUserInfo(t,!0)},this.requestInvite=async(t,e)=>{const n=await fetch(`${o}/app/CreateInvitationOrRequest?forUserNickname=${t}&toProjectNickname=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!n.ok||(console.warn(`requestInvite() => ${n.statusText}`),!1)},this.getProjectInfo=this.getUserInfo,this.updateMembersAccess=async(t,e)=>{const n=await fetch(`${o}/app/AddOrUpdateProjectProperty?project=${t}&key=APP_EDITORS&value=${e.join(",")}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!n.ok||(console.warn(`updateMembersAccess() => ${n.statusText}`),!1)},this.getMembersAccess=async t=>{const e=(await this.getProjectInfo(t,!0)).properties.find((t=>"APP_EDITORS"===t.name));return e&&e.value?e.value.split(","):[]},this.setToken=t=>{a=t,a&&window.Codicent.init({token:a,baseUrl:o})},this.getToken=()=>a,this.checkPurchaseStatus=async()=>{const t=await fetch(`${o}payments/GetPaymentStatus`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw new Error("Failed to check purchase status");const{isPaid:e}=await t.json();return e},this.checkSubscriptionStatus=async()=>{if(!this.options.SUBSCRIPTION_NEEDED)return"active";const t=await fetch(`${o}payments/GetSubscriptionStatus?t=${Date.now()}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`],["Cache-Control","no-cache, no-store, must-revalidate"],["Pragma","no-cache"],["Expires","0"]]});if(!t.ok)throw new Error("Failed to check subscription status");const{status:e}=await t.json();return e},this.createCheckoutSession=async t=>{const e=await fetch(`${o}payments/CreateCheckoutSession`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({priceId:t,successUrl:window.location.href,cancelUrl:window.location.href})});if(!e.ok)throw new Error("Failed to create checkout session");const{id:n}=await e.json();return n},this.redirectToCheckout=async t=>{const n=await e.loadStripe(this.options.STRIPE_PUBLIC_KEY);if(!n)throw new Error("Stripe failed to load");const o=await this.createCheckoutSession(t),{error:a}=await n.redirectToCheckout({sessionId:o});if(a)throw new Error(a.message)},this.getChatHistory=async t=>{const e=await fetch(`${o}api/GetMessageHistory?messageId=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get chat history");let n=await e.json();return n=n.filter((t=>!t.content.includes("#function_result")&&!t.content.includes("#finish_reason_function_call"))),n},this.getPublicFlow=async t=>{const e=await fetch(`${o}/app/GetPublicFlow?codicent=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get public flow");const n=await e.json();return n.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),n},this.getMessageContent=async t=>{const e=await fetch(`${o}app/GetMessageContent?id=${t}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(e.ok){const t=await e.json();return{content:t.content,url:t.url}}return{content:"",url:""}},this.logAction=async(t,e)=>{if(!this.options.APP_LOG_CODICENT)return"";const n={content:`@${this.options.APP_LOG_CODICENT} #debug #${e}\n${t}`,type:"text"},a=await fetch(`${o}app/AddChatMessage`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.options.APP_LOG_TOKEN}`]],body:JSON.stringify(n)});if(!a.ok)throw new Error(`${a.statusText||"Failed to post log message!"}`);return(await a.json()).id},this.createApp=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.APP_PREFIX}${t}`;if(!await this.nicknameExists(e)){if(await this.cloneProject(this.options.APP_TEMPLATE,e)){if(this.options.ANONYMOUS_TOKEN)try{const t=this.options.ANONYMOUS_TOKEN.split(".")[1],n=atob(t),o=JSON.parse(n).nickname;if(!await this.addFollower(e,o))throw new Error("Failed to add follower: "+o)}catch(t){console.error("Error extracting adding anonymous follower:",t)}return e}}}}catch(t){console.error("Error creating app:",t)}return null},this.findUsername=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.USER_PREFIX}${t}`;if(!await this.nicknameExists(e))return e}}catch(t){console.warn("Error finding username:",t)}return null},this.getForms=async()=>{const t=await fetch(`${o}app/GetForms?codicent=${this.codicent}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await t.json()},this.getFormById=async t=>{const e=await fetch(`${o}app/GetFormById?id=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await e.json()},this.codicent="",this.options=t}handleUnauthorized(){this.onUnauthorized&&this.onUnauthorized()}}t=r,r.getImageUrl=(t,e)=>`${o}app/GetImage?fileId=${t}&width=${e}`,r.getFileUrl=(t,e)=>`${o}app/DownloadFile?fileId=${t}${e?`&extension=${e}`:""}`,r.downloadFile=async e=>{fetch(t.getFileUrl(e.id)).then((t=>{if(t.headers.forEach(((t,e)=>{console.log(`${e}: ${t}`)})),t.ok)return t.blob();throw new Error("Network response was not ok.")})).then((t=>{const n=window.URL.createObjectURL(t),o=document.createElement("a");o.style.display="none",o.href=n,o.download=e.filename,document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n)})).catch((t=>{console.error("There was a problem with the fetch operation:",t)}))},r.getMiniChatReply=async(t,e="codicent-mini",n)=>{const a=await fetch(`${o}app/GetAi2ChatReply?message=${t}&project=${e}${n?"&messageId="+n:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!a.ok)return void a.status;return(await a.json()).content.replace("@codicent-mini","").trim()},exports.CodicentService=r;
@@ -11,6 +11,7 @@ interface ChatInputProps {
11
11
  noMemory?: boolean;
12
12
  selectAll?: boolean;
13
13
  clearOnFocus?: boolean;
14
+ id?: string;
14
15
  }
15
16
  declare const ChatInput: React.FC<ChatInputProps>;
16
17
  export default ChatInput;
@@ -1 +1 @@
1
- {"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../../src/components/ChatInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAQ1E,UAAU,cAAc;IACtB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAoED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAkLvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../../src/components/ChatInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAQ1E,UAAU,cAAc;IACtB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAoED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAoLvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1 +1 @@
1
- import{jsxs as e,jsx as o}from"react/jsx-runtime";import{useRef as t,useState as i,useEffect as r}from"react";import{FileThumbnail as a}from"./FileThumbnail.js";import s from"../hooks/useStateWithLocalStorage.js";import"../services/codicent.js";import"./Markdown.js";import{Textarea as l}from"./Textarea.js";import"./Button.js";import"./Spinner.js";import"./TextHeader.js";import"./TypingIndicator.js";import"./Dialog.js";import"./CombinedPlaceholderDialog.js";import"./ChatMessage.js";import"./Header.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/index.js";import{getConfigValue as n}from"../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";import"./MessageInput.js";import"./UploadFile.js";import"./SnapFooter.js";import"./Profile.js";import"./MessageItem.js";import"./Content.js";import"./AiInput.js";import"./SearchBox.js";import"./HtmlView.js";import"./Footer.js";import"./Page.js";import"../pages/AppFrame.js";import"../pages/Snap.js";import"../pages/Search.js";import"../pages/Login.js";import"../pages/CrmPage.js";import"../pages/ImageView.js";import"../pages/FormInvite.js";import"../pages/FormAccept.js";import"../pages/Sales.js";import"../stores/chatStore.js";import p from"../hooks/useLocalization.js";import m from"../hooks/useAppStyles.js";import{makeStyles as c}from"../node_modules/@griffel/react/makeStyles.esm.js";import{Button as d}from"../node_modules/@fluentui/react-button/lib/components/Button/Button.js";import{Spinner as u}from"../node_modules/@fluentui/react-spinner/lib/components/Spinner/Spinner.js";import{SendRegular as f,SendFilled as g}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-3.js";import{mergeClasses as j}from"../node_modules/@griffel/core/mergeClasses.esm.js";import{tokens as h}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{AddRegular as b}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-0.js";const x=c({inputContainer:{display:"flex",flexDirection:"column",padding:"8px",width:"100%",position:"relative",gap:"8px"},textareaWrapper:{position:"relative",width:"100%",display:"flex",flexDirection:"column"},actionButtonRow:{position:"absolute",left:"8px",bottom:"8px",right:"8px",zIndex:1,display:"flex",justifyContent:"space-between",alignItems:"center"},fileList:{display:"flex",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"thin",msOverflowStyle:"none",padding:"4px 0",maxWidth:"100%",boxSizing:"border-box",gap:"4px",minHeight:"72px",backgroundColor:h.colorNeutralBackground2,borderRadius:h.borderRadiusMedium,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:h.colorNeutralStroke1,borderRadius:"3px"}},hiddenInput:{display:"none"},button:{color:h.colorNeutralForeground2,"&:hover":{color:h.colorBrandBackground,backgroundColor:"transparent"}}}),_=({onSend:c,disableSend:h,onSelectFiles:_,getImageUrl:S,getFileInfo:k,codicent:v,defaultText:w,rows:y,noMemory:T,selectAll:N})=>{const C=x(),[D,B]=s("chatInput-"+v,""),F=t(null),[I,O]=i([]),[E,A]=i([]),[H,P]=i(!1),[U,W]=i([]),{t:L}=p(),R=m();r((()=>{w&&B(w)}),[B,w]),r((()=>{!0===T&&B("")}),[T,B]);const M=()=>{if(""===D.trim()&&0===U.length)return;const e=I.length>0?" #"+I.join(" #"):"",o=E.length>0?"\n#file:"+E.join("\n#file:"):"";c(e+D+o),B(""),O([]),A([]),W([])};return e("div",{className:C.inputContainer,children:[o("input",{title:L("Välj fil att ladda upp"),type:"file",ref:F,className:C.hiddenInput,onChange:async e=>{const o=e.target.files;if(o&&o.length>0&&_){P(!0);try{const e=await _(o),t=await Promise.all(e.map((e=>k(e))));A((o=>[...o,...e])),W((e=>[...e,...t]))}catch(e){console.error("Failed to upload files",e)}finally{P(!1),F.current&&(F.current.value="")}}},multiple:!0,accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.txt"}),U.length>0&&o("div",{className:C.fileList,children:U.map((e=>o(a,{file:e,getImageUrl:S,onDelete:()=>{return o=e.id,A((e=>e.filter((e=>e!==o)))),void W((e=>e.filter((e=>e.id!==o))));var o}},e.id)))}),e("div",{className:C.textareaWrapper,onPaste:async e=>{for(const o of e.clipboardData.items)if(-1!==o.type.indexOf("image")){const t=o.getAsFile();if(t&&(e.preventDefault(),_))try{P(!0);const e=new DataTransfer;e.items.add(t);const o=await _(e.files),i=await Promise.all(o.map((e=>k(e))));A((e=>[...e,...o])),W((e=>[...e,...i]))}catch(e){console.error("Failed to upload pasted image",e)}finally{P(!1)}}},children:[o(l,{size:"large",placeholder:L(n("APP_CHAT_TEXT_PLACEHOLDER")||"Skriv ditt meddelande här..."),value:D,onChange:e=>B(e.target.value),onKeyDown:e=>{h||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),M())},autoFocus:!1,rows:y||4,onFocus:e=>{if(!0===N){e.target.select()}}}),e("div",{className:C.actionButtonRow,children:[o("div",{children:_&&o(d,{appearance:"subtle",size:"small",title:L("Lägg till fil"),icon:o(H?u:b,{}),onClick:()=>F.current?.click(),className:C.button})}),o(d,{appearance:n("SHOW_SEND_BUTTON_TEXT")?"primary":"subtle",size:n("SHOW_SEND_BUTTON_TEXT")?"small":"large",title:L("Skicka"),disabled:h,icon:""===D.trim()&&0===U.length?o(f,{}):o(g,{}),onClick:M,className:n("SEND_BUTTON_ROUND_BACKGROUND")?j(R.roundButton,C.button):n("SHOW_SEND_BUTTON_TEXT")?void 0:C.button,children:n("SHOW_SEND_BUTTON_TEXT")&&o("span",{children:L("Skicka")})})]})]})]})};export{_ as default};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as o,useState as i,useEffect as r}from"react";import{FileThumbnail as a}from"./FileThumbnail.js";import s from"../hooks/useStateWithLocalStorage.js";import"../services/codicent.js";import"./Markdown.js";import{Textarea as l}from"./Textarea.js";import"./Button.js";import"./Spinner.js";import"./TextHeader.js";import"./TypingIndicator.js";import"./Dialog.js";import"./CombinedPlaceholderDialog.js";import"./ChatMessage.js";import"./Header.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/index.js";import{getConfigValue as n}from"../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";import"./MessageInput.js";import"./UploadFile.js";import"./SnapFooter.js";import"./Profile.js";import"./MessageItem.js";import"./Content.js";import"./AiInput.js";import"./SearchBox.js";import"./HtmlView.js";import"./Footer.js";import"./Page.js";import"../pages/AppFrame.js";import"../pages/Snap.js";import"../pages/Search.js";import"../pages/Login.js";import"../pages/CrmPage.js";import"../pages/ImageView.js";import"../pages/FormInvite.js";import"../pages/FormAccept.js";import"../pages/Sales.js";import"../stores/chatStore.js";import p from"../hooks/useLocalization.js";import m from"../hooks/useAppStyles.js";import{makeStyles as c}from"../node_modules/@griffel/react/makeStyles.esm.js";import{Button as d}from"../node_modules/@fluentui/react-button/lib/components/Button/Button.js";import{Spinner as u}from"../node_modules/@fluentui/react-spinner/lib/components/Spinner/Spinner.js";import{SendRegular as f,SendFilled as g}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-3.js";import{mergeClasses as j}from"../node_modules/@griffel/core/mergeClasses.esm.js";import{tokens as h}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{AddRegular as b}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-0.js";const x=c({inputContainer:{display:"flex",flexDirection:"column",padding:"8px",width:"100%",position:"relative",gap:"8px"},textareaWrapper:{position:"relative",width:"100%",display:"flex",flexDirection:"column"},actionButtonRow:{position:"absolute",left:"8px",bottom:"8px",right:"8px",zIndex:1,display:"flex",justifyContent:"space-between",alignItems:"center"},fileList:{display:"flex",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"thin",msOverflowStyle:"none",padding:"4px 0",maxWidth:"100%",boxSizing:"border-box",gap:"4px",minHeight:"72px",backgroundColor:h.colorNeutralBackground2,borderRadius:h.borderRadiusMedium,"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:h.colorNeutralStroke1,borderRadius:"3px"}},hiddenInput:{display:"none"},button:{color:h.colorNeutralForeground2,"&:hover":{color:h.colorBrandBackground,backgroundColor:"transparent"}}}),_=({onSend:c,disableSend:h,onSelectFiles:_,getImageUrl:S,getFileInfo:k,codicent:v,defaultText:w,rows:y,noMemory:T,selectAll:N,id:C})=>{const D=x(),[B,F]=s("chatInput-"+v,""),I=o(null),[O,E]=i([]),[A,H]=i([]),[P,U]=i(!1),[W,L]=i([]),{t:R}=p(),M=m();r((()=>{w&&F(w)}),[F,w]),r((()=>{!0===T&&F("")}),[T,F]);const z=()=>{if(""===B.trim()&&0===W.length)return;const e=O.length>0?" #"+O.join(" #"):"",t=A.length>0?"\n#file:"+A.join("\n#file:"):"";c(e+B+t),F(""),E([]),H([]),L([])};return e("div",{className:D.inputContainer,children:[t("input",{title:R("Välj fil att ladda upp"),type:"file",ref:I,className:D.hiddenInput,onChange:async e=>{const t=e.target.files;if(t&&t.length>0&&_){U(!0);try{const e=await _(t),o=await Promise.all(e.map((e=>k(e))));H((t=>[...t,...e])),L((e=>[...e,...o]))}catch(e){console.error("Failed to upload files",e)}finally{U(!1),I.current&&(I.current.value="")}}},multiple:!0,accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.txt"}),W.length>0&&t("div",{className:D.fileList,children:W.map((e=>t(a,{file:e,getImageUrl:S,onDelete:()=>{return t=e.id,H((e=>e.filter((e=>e!==t)))),void L((e=>e.filter((e=>e.id!==t))));var t}},e.id)))}),e("div",{className:D.textareaWrapper,onPaste:async e=>{for(const t of e.clipboardData.items)if(-1!==t.type.indexOf("image")){const o=t.getAsFile();if(o&&(e.preventDefault(),_))try{U(!0);const e=new DataTransfer;e.items.add(o);const t=await _(e.files),i=await Promise.all(t.map((e=>k(e))));H((e=>[...e,...t])),L((e=>[...e,...i]))}catch(e){console.error("Failed to upload pasted image",e)}finally{U(!1)}}},children:[t(l,{size:"large",id:C||"chat-input",placeholder:R(n("APP_CHAT_TEXT_PLACEHOLDER")||"Skriv ditt meddelande här..."),value:B,onChange:e=>F(e.target.value),onKeyDown:e=>{h||"Enter"!==e.key||e.shiftKey||(e.preventDefault(),z())},autoFocus:!1,rows:y||4,onFocus:e=>{if(!0===N){e.target.select()}}}),e("div",{className:D.actionButtonRow,children:[t("div",{children:_&&t(d,{appearance:"subtle",size:"small",title:R("Lägg till fil"),icon:t(P?u:b,{}),onClick:()=>I.current?.click(),className:D.button})}),t(d,{appearance:n("SHOW_SEND_BUTTON_TEXT")?"primary":"subtle",size:n("SHOW_SEND_BUTTON_TEXT")?"small":"large",title:R("Skicka"),disabled:h,icon:""===B.trim()&&0===W.length?t(f,{}):t(g,{}),onClick:z,className:n("SEND_BUTTON_ROUND_BACKGROUND")?j(M.roundButton,D.button):n("SHOW_SEND_BUTTON_TEXT")?void 0:D.button,children:n("SHOW_SEND_BUTTON_TEXT")&&t("span",{children:R("Skicka")})})]})]})]})};export{_ as default};
@@ -1 +1 @@
1
- {"version":3,"file":"ChatMessage.d.ts","sourceRoot":"","sources":["../../../src/components/ChatMessage.tsx"],"names":[],"mappings":"AAoBA,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAgDD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAiD3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"ChatMessage.d.ts","sourceRoot":"","sources":["../../../src/components/ChatMessage.tsx"],"names":[],"mappings":"AAoBA,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAgDD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAyD3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import"react";import"../services/codicent.js";import t from"./Markdown.js";import"./Textarea.js";import{Button as s}from"./Button.js";import"./Spinner.js";import"./TextHeader.js";import"./TypingIndicator.js";import"./Dialog.js";import"./ChatInput.js";import"./CombinedPlaceholderDialog.js";import"./Header.js";import r from"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/index.js";import{getConfigValue as i}from"../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";import"./FileThumbnail.js";import"./MessageInput.js";import"./UploadFile.js";import"./SnapFooter.js";import"./Profile.js";import"./MessageItem.js";import"./Content.js";import"./AiInput.js";import"./SearchBox.js";import"./HtmlView.js";import"./Footer.js";import"./Page.js";import"../pages/AppFrame.js";import"../pages/Snap.js";import"../pages/Search.js";import"../pages/Login.js";import"../pages/CrmPage.js";import"../pages/ImageView.js";import"../pages/FormInvite.js";import"../pages/FormAccept.js";import"../pages/Sales.js";import"../stores/chatStore.js";import n from"../hooks/useLocalization.js";import"../hooks/useAppStyles.js";import{makeStyles as a}from"../node_modules/@griffel/react/makeStyles.esm.js";import{tokens as p}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{mergeClasses as l}from"../node_modules/@griffel/core/mergeClasses.esm.js";import{Text as m}from"../node_modules/@fluentui/react-text/lib/components/Text/Text.js";import{ChannelRegular as c}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js";const d=a({message:{display:"flex",marginBottom:"16px",webkitUserSelect:"text",userSelect:"text"},user:{justifyContent:"flex-end"},bot:{justifyContent:"flex-start"},messageContent:{maxWidth:"80%",padding:"12px 16px",borderRadius:"16px",fontSize:"1rem",lineHeight:"1.4",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},userMessage:{backgroundColor:i("CHAT_USER_BACKGROUND_COLOR")||p.colorBrandBackground,color:i("CHAT_USER_TEXT_COLOR")||p.colorNeutralForegroundInverted,borderTopRightRadius:"0"},botMessage:{backgroundColor:i("CHAT_BOT_BACKGROUND_COLOR")||p.colorBrandBackground2,color:i("CHAT_BOT_TEXT_COLOR")||p.colorNeutralForeground1,borderTopLeftRadius:"0"},newMessage:{animation:"$fadeIn 0.5s ease-in-out"}}),u=({sender:i,content:a,isNew:p,children:u,showSuggestions:g,onSuggestionClicked:j})=>{const f=d(),{t:_}=n();let b=[];if("bot"===i&&a.includes("#suggested_questions")){const e=a.split("#suggested_questions");a=e[0],b=e[1].split("\n").filter((e=>""!==e.trim())).map((e=>e.trim()))}const h=new r(a);let x=h.content;"user"===i&&h.content.includes("---")&&(x=h.content.split("---")[0]);const C=h.content.startsWith("Error code: ")?_("Ett fel uppstod 😟 => starta en ny chatt"):null;return e("div",{className:l(f.message,"user"===i?f.user:f.bot),children:o("div",{className:l(f.messageContent,"user"===i?f.userMessage:f.botMessage,p&&f.newMessage),children:[o(m,{size:400,children:[C,!C&&e(t,{content:x}),h.files.length>0&&e(c,{}),g&&b&&b.length>0&&e("div",{style:{marginTop:"8px",display:"flex",gap:"8px",flexWrap:"wrap"},children:b.map(((o,t)=>e(s,{size:"small",shape:"circular",onClick:()=>j?.(o),style:{textAlign:"left"},children:o},t)))})]}),u]})})};export{u as default};
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import"react";import"../services/codicent.js";import o from"./Markdown.js";import"./Textarea.js";import{Button as s}from"./Button.js";import"./Spinner.js";import"./TextHeader.js";import"./TypingIndicator.js";import"./Dialog.js";import"./ChatInput.js";import"./CombinedPlaceholderDialog.js";import"./Header.js";import r from"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/index.js";import{getConfigValue as i}from"../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";import"./FileThumbnail.js";import"./MessageInput.js";import"./UploadFile.js";import"./SnapFooter.js";import"./Profile.js";import"./MessageItem.js";import"./Content.js";import"./AiInput.js";import"./SearchBox.js";import"./HtmlView.js";import"./Footer.js";import"./Page.js";import"../pages/AppFrame.js";import"../pages/Snap.js";import"../pages/Search.js";import"../pages/Login.js";import"../pages/CrmPage.js";import"../pages/ImageView.js";import"../pages/FormInvite.js";import"../pages/FormAccept.js";import"../pages/Sales.js";import"../stores/chatStore.js";import n from"../hooks/useLocalization.js";import"../hooks/useAppStyles.js";import{makeStyles as a}from"../node_modules/@griffel/react/makeStyles.esm.js";import{mergeClasses as p}from"../node_modules/@griffel/core/mergeClasses.esm.js";import{tokens as m}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{Text as l}from"../node_modules/@fluentui/react-text/lib/components/Text/Text.js";import{ChannelRegular as d}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js";const c=a({message:{display:"flex",marginBottom:"16px",webkitUserSelect:"text",userSelect:"text"},user:{justifyContent:"flex-end"},bot:{justifyContent:"flex-start"},messageContent:{maxWidth:"80%",padding:"12px 16px",borderRadius:"16px",fontSize:"1rem",lineHeight:"1.4",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"auto"},userMessage:{borderTopRightRadius:"0"},botMessage:{borderTopLeftRadius:"0"},newMessage:{animation:"$fadeIn 0.5s ease-in-out"}}),u=({sender:a,content:u,isNew:g,children:j,showSuggestions:f,onSuggestionClicked:_})=>{const h=c(),{t:x}=n();let b=[];if("bot"===a&&u.includes("#suggested_questions")){const e=u.split("#suggested_questions");u=e[0],b=e[1].split("\n").filter((e=>""!==e.trim())).map((e=>e.trim()))}const C=new r(u);let w=C.content;"user"===a&&C.content.includes("---")&&(w=C.content.split("---")[0]);const T=C.content.startsWith("Error code: ")?x("Ett fel uppstod 😟 => starta en ny chatt"):null;return e("div",{className:p(h.message,"user"===a?h.user:h.bot),children:t("div",{className:p(h.messageContent,"user"===a?h.userMessage:h.botMessage,g&&h.newMessage),style:{backgroundColor:"user"===a?i("CHAT_USER_BACKGROUND_COLOR")||m.colorBrandBackground:i("CHAT_BOT_BACKGROUND_COLOR")||m.colorBrandBackground2,color:"user"===a?i("CHAT_USER_TEXT_COLOR")||m.colorNeutralForegroundInverted:i("CHAT_BOT_TEXT_COLOR")||m.colorNeutralForeground1},children:[t(l,{size:400,children:[T,!T&&e(o,{content:w}),C.files.length>0&&e(d,{}),f&&b&&b.length>0&&e("div",{style:{marginTop:"8px",display:"flex",gap:"8px",flexWrap:"wrap"},children:b.map(((t,o)=>e(s,{size:"small",shape:"circular",onClick:()=>_?.(t),style:{textAlign:"left"},children:t},o)))})]}),j]})})};export{u as default};
@@ -11,6 +11,7 @@ export interface TextareaProps {
11
11
  className?: string;
12
12
  onFocus?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
13
13
  onPaste?: (event: React.ClipboardEvent<HTMLTextAreaElement>) => void;
14
+ id?: string;
14
15
  }
15
16
  export declare const Textarea: React.FC<TextareaProps>;
16
17
  //# sourceMappingURL=Textarea.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;CACtE;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAkB5C,CAAC"}
1
+ {"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACrE,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAkB5C,CAAC"}
@@ -1 +1 @@
1
- import{loadStripe as t}from"../node_modules/@stripe/stripe-js/dist/index.js";import e from"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"react/jsx-runtime";import"react";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";var o;let n="https://codicent.com/",a="-";const i=()=>void 0!==window.Codicent&&(window.Codicent.init({token:a,baseUrl:n}),window.Codicent.handleMessage=function(t){const e=new CustomEvent("codicent-log",{detail:{message:t}});window.dispatchEvent(e)},!0);let s=i();if(!s){const t=setInterval((()=>{s=i(),s&&clearInterval(t)}),100)}class r{constructor(o){this.createDataMessage=async(t,e)=>await window.Codicent.data.create({codicent:this.codicent,tag:t,data:e}),this.readDataMessages=async(t,e)=>await window.Codicent.data.read({codicent:this.codicent,tag:t,search:e}),this.readOneDataMessage=async t=>await window.Codicent.data.readOne(t),this.updateDataMessage=async(t,e)=>await window.Codicent.data.update({id:t,data:e,codicent:this.codicent}),this.deleteDataMessage=async t=>await window.Codicent.data.delete({id:t,codicent:this.codicent}),this.getAppTheme=async()=>{try{const t=await window.Codicent.getDataMessages({tags:["app-theme"],codicent:this.codicent});return t.length>0?t[0].data:null}catch(t){return console.error("Error fetching app theme:",t),null}},this.getAppButtons=async()=>{const t=(await window.Codicent.getDataMessages({tags:[this.options.BUTTON_TAG],codicent:this.codicent})).map((t=>t.data));return t.sort(((t,e)=>t.title>e.title?1:-1)),t},this.getAppTasks=async()=>(await window.Codicent.getMessages({search:`@${this.codicent} #app-task`,length:50})).map((t=>{const o=new e(t.content).content.split("\n"),n=o[0],a=o.slice(1).join("\n");return{id:t.id,title:n,content:a}})),this.getAppPrompts=async()=>(await window.Codicent.getDataMessages({tags:["chatprompt"],codicent:this.codicent})).map((t=>t.data)).map((({title:t,prompt:e})=>({title:t,prompt:e}))),this.uploadFile=async(t,e)=>await window.Codicent.upload(e,t),this.getFileInfo=async t=>await window.Codicent.getFileInfo(t),this.sendMessage=(t,e)=>window.Codicent.postMessage({message:`@${this.codicent} ${t}`,type:"text",parentId:e}),this.chat=(t,e)=>window.Codicent.getChatReply3({message:t,codicent:this.codicent,messageId:e}),this.getMessagesFast=async(t,e,o=100,a=void 0)=>{const i=await fetch(`${n}app/AppGetMessages`,{method:"POST",headers:[["Authorization",`Bearer ${this.getToken()}`],["Content-Type","application/json; charset=utf-8"]],body:JSON.stringify({tags:t,codicent:this.codicent,search:e,length:o})});if(!i.ok)throw 401===i.status&&this.handleUnauthorized(),new Error(`${i.statusText}`);let s=await i.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),a){const t=await this.getPublicFlow(a);s=s.concat(t),s.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime()))}return s},this.getMessages=async(t,e)=>{let o=[];for(const e of t){const t=await window.Codicent.getMessages({search:`@${this.codicent} #${e}`,length:10});"chat"===e&&t.forEach((t=>t.content=`#chat\n${t.content}`)),o=o.concat(t)}if(e)try{const t=await this.getPublicFlow(e);o=o.concat(t)}catch(t){console.warn("Error fetching public flow, PUBLIC_TAG missing in codicent?",t)}return o=o.filter(((t,e,o)=>e===o.findIndex((e=>e.id===t.id)))),o.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime())),o},this.registerUser=async(t,e,o,a)=>{const i=await fetch(`${n}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${a}`]],body:JSON.stringify({nickname:t,email:e,userId:o})});if(!i.ok)return"";const s=await i.text();return window.Codicent.init({token:a,baseUrl:n}),s},this.loginUser=async(t,e)=>{try{const o=await fetch(`${n}app/LoginAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${e}`]],body:JSON.stringify({userId:t})});if(!o.ok)return 404===o.status||400===o.status?null:401===o.status?(this.handleUnauthorized(),null):"";const a=await o.text();return this.setToken(a),a}catch(t){return console.warn("Error logging in user:",t),""}},this.nicknameExists=async t=>{const e=await fetch(`${n}app/NicknameExists?nickname=${encodeURIComponent(t)}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"]]});if(!e.ok)return!1;return await e.json()},this.logout=()=>{this.setToken("")},this.isRegistered=()=>null!==localStorage.getItem("codicent_nickname"),this.getApps=async()=>{try{const t=await fetch(`${n}app/AppGetApps`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw t.status,new Error(`${t.statusText}`);const e=await t.json();return e.filter(((t,e,o)=>e===o.findIndex((e=>e.id===t.id))&&(this.options.APP_NAME||t.id.startsWith(this.options.APP_PREFIX))))}catch(t){return console.warn("Error fetching apps:",t),null}},this.addFollower=async(t,e)=>{const o=await fetch(`${n}app/AddFollower?nickname=${t}&followerNickname=${e}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!o.ok)throw o.status,new Error(`${o.statusText||"Failed to add follower!"}`);return await o.json()},this.cloneProject=async(t,e)=>{const o=await fetch(`${n}app/CloneProject?project=${t}&newProject=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!o.ok)throw o.status,new Error(`${o.statusText}`);let a=await o.json();if(a){const t='#data #app-theme \n{\n "textcolor": "#212121",\n "backgroundcolor": "#273044",\n "color": "#ffffff",\n "logo": "https://codicent.com/logo512.png",\n "title": "",\n "themeColor": "#581d71",\n "buttonColor": "#c0c0c0",\n "buttonTextColor": "#000000",\n "font": "Montserrat",\n "welcome": "Hej {{username}}!",\n "chatPlaceholder": "Tjena, Loociz här! Vad vill du?",\n "textPlaceholder": "Skriv det du vill spara, så tar jag (Loociz alltså) hand om det!",\n "transcriptionInstructions": "Tryck på knappen för att start och sedan stoppa ljudinspelning."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}if(a){const t='#data #app-button\n{\n "title": "Ta fram företagsinfo",\n "url": "/#/chat?text=Hej!%20Jag%20vill%20spara%20f%C3%B6retagsinfo.%20Guida%20mig%20steg%20f%C3%B6r%20steg%2C%20ett%20i%20taget%2C%20tills%20vi%20har%20all%20info%20om%20mitt%20f%C3%B6retag.%20Exempel%20p%C3%A5%20data%3A%20f%C3%B6retagsnamn%20eller%20id%C3%A9namn%2C%20org.nr.%2C%20%C3%A4gare%2C%20kontaktinformation%2C%20vision%2C%20aff%C3%A4rsid%C3%A9%2C%20mm."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}}}return a},this.getNickname=async()=>{try{const t=a.split(".")[1],e=atob(t),o=JSON.parse(e),i=o.sub||o.userId,s=await fetch(`${n}app/GetNickname?userId=${i}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${s.statusText}`);return await s.text()}catch{return""}},this.getChatInstructions=async()=>{try{const t=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:1});if(t.length>0)return t[0].content}catch{console.warn("Error fetching chat instructions")}return""},this.updateChatInstructions=async t=>{try{const e=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:100}),o=`@${this.codicent} #instructions\n${t}`;e.length>0?e[0].content!==o&&(console.log("updating instructions",o),await window.Codicent.postMessage({message:o,type:"text",parentId:e[0].id})):(console.log("new instructions",o),await window.Codicent.postMessage({message:o,type:"text"}))}catch{console.warn("Error updating chat instructions")}},this.getUserInfo=async(t,e=!1)=>{const o=await fetch(`${n}/app/GetUserInfo?nickname=${t}${e?"&t="+Date.now():""}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!o.ok)throw 401===o.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${o.statusText}`);const a=await o.json(),{email:i,picture:s,description:r,followers:c,properties:h,owner:d}=a;return{nickname:t,email:i,name:r,picture:s,followers:c,properties:h,owner:d}},this.updateUserInfo=async({nickname:t,email:e,name:o,picture:a})=>{const i=await fetch(`${n}/app/AddOrUpdateUser`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({nickname:t,email:e,name:o,picture:a,description:""})});if(!i.ok)throw i.status,new Error(`${i.statusText}`);return await this.getUserInfo(t,!0)},this.requestInvite=async(t,e)=>{const o=await fetch(`${n}/app/CreateInvitationOrRequest?forUserNickname=${t}&toProjectNickname=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!o.ok||(console.warn(`requestInvite() => ${o.statusText}`),!1)},this.getProjectInfo=this.getUserInfo,this.updateMembersAccess=async(t,e)=>{const o=await fetch(`${n}/app/AddOrUpdateProjectProperty?project=${t}&key=APP_EDITORS&value=${e.join(",")}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!o.ok||(console.warn(`updateMembersAccess() => ${o.statusText}`),!1)},this.getMembersAccess=async t=>{const e=(await this.getProjectInfo(t,!0)).properties.find((t=>"APP_EDITORS"===t.name));return e&&e.value?e.value.split(","):[]},this.setToken=t=>{a=t,a&&window.Codicent.init({token:a,baseUrl:n})},this.getToken=()=>a,this.checkPurchaseStatus=async()=>{const t=await fetch(`${n}payments/GetPaymentStatus`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw new Error("Failed to check purchase status");const{isPaid:e}=await t.json();return e},this.checkSubscriptionStatus=async()=>{if(!this.options.SUBSCRIPTION_NEEDED)return"active";const t=await fetch(`${n}payments/GetSubscriptionStatus?t=${Date.now()}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`],["Cache-Control","no-cache, no-store, must-revalidate"],["Pragma","no-cache"],["Expires","0"]]});if(!t.ok)throw new Error("Failed to check subscription status");const{status:e}=await t.json();return e},this.createCheckoutSession=async t=>{const e=await fetch(`${n}payments/CreateCheckoutSession`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({priceId:t,successUrl:window.location.href,cancelUrl:window.location.href})});if(!e.ok)throw new Error("Failed to create checkout session");const{id:o}=await e.json();return o},this.redirectToCheckout=async e=>{const o=await t(this.options.STRIPE_PUBLIC_KEY);if(!o)throw new Error("Stripe failed to load");const n=await this.createCheckoutSession(e),{error:a}=await o.redirectToCheckout({sessionId:n});if(a)throw new Error(a.message)},this.getChatHistory=async t=>{const e=await fetch(`${n}api/GetMessageHistory?messageId=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get chat history");let o=await e.json();return o=o.filter((t=>!t.content.includes("#function_result")&&!t.content.includes("#finish_reason_function_call"))),o},this.getPublicFlow=async t=>{const e=await fetch(`${n}/app/GetPublicFlow?codicent=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get public flow");const o=await e.json();return o.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),o},this.getMessageContent=async t=>{const e=await fetch(`${n}app/GetMessageContent?id=${t}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(e.ok){const t=await e.json();return{content:t.content,url:t.url}}return{content:"",url:""}},this.logAction=async(t,e)=>{if(!this.options.APP_LOG_CODICENT)return"";const o={content:`@${this.options.APP_LOG_CODICENT} #debug #${e}\n${t}`,type:"text"},a=await fetch(`${n}app/AddChatMessage`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.options.APP_LOG_TOKEN}`]],body:JSON.stringify(o)});if(!a.ok)throw new Error(`${a.statusText||"Failed to post log message!"}`);return(await a.json()).id},this.createApp=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.APP_PREFIX}${t}`;if(!await this.nicknameExists(e)){if(await this.cloneProject(this.options.APP_TEMPLATE,e)){if(this.options.ANONYMOUS_TOKEN)try{const t=this.options.ANONYMOUS_TOKEN.split(".")[1],o=atob(t),n=JSON.parse(o).nickname;if(!await this.addFollower(e,n))throw new Error("Failed to add follower: "+n)}catch(t){console.error("Error extracting adding anonymous follower:",t)}return e}}}}catch(t){console.error("Error creating app:",t)}return null},this.findUsername=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.USER_PREFIX}${t}`;if(!await this.nicknameExists(e))return e}}catch(t){console.warn("Error finding username:",t)}return null},this.getForms=async()=>{const t=await fetch(`${n}app/GetForms?codicent=${this.codicent}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await t.json()},this.getFormById=async t=>{const e=await fetch(`${n}app/GetFormById?id=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await e.json()},this.codicent="",this.options=o}handleUnauthorized(){this.onUnauthorized&&this.onUnauthorized()}}o=r,r.getImageUrl=(t,e)=>`${n}app/GetImage?fileId=${t}&width=${e}`,r.getFileUrl=(t,e)=>`${n}app/DownloadFile?fileId=${t}${e?`&extension=${e}`:""}`,r.downloadFile=async t=>{fetch(o.getFileUrl(t.id)).then((t=>{if(t.headers.forEach(((t,e)=>{console.log(`${e}: ${t}`)})),t.ok)return t.blob();throw new Error("Network response was not ok.")})).then((e=>{const o=window.URL.createObjectURL(e),n=document.createElement("a");n.style.display="none",n.href=o,n.download=t.filename,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(o)})).catch((t=>{console.error("There was a problem with the fetch operation:",t)}))},r.getMiniChatReply=async(t,e="codicent-mini",o)=>{const a=await fetch(`${n}app/GetAi2ChatReply?message=${t}&project=${e}${o?"&messageId="+o:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!a.ok)return void a.status;return(await a.json()).content.replace("@codicent-mini","").trim()};export{r as CodicentService};
1
+ import{loadStripe as t}from"../node_modules/@stripe/stripe-js/dist/index.js";import e from"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"react/jsx-runtime";import"react";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";var o;let n="https://codicent.com/",a="-";const i=()=>void 0!==window.Codicent&&(window.Codicent.handleMessage=function(t){const e=new CustomEvent("codicent-log",{detail:{message:t}});window.dispatchEvent(e)},window.Codicent.init({token:a,baseUrl:n}),!0);let s=i();if(!s){const t=setInterval((()=>{s=i(),s&&clearInterval(t)}),100)}class r{constructor(o){this.createDataMessage=async(t,e)=>await window.Codicent.data.create({codicent:this.codicent,tag:t,data:e}),this.readDataMessages=async(t,e)=>await window.Codicent.data.read({codicent:this.codicent,tag:t,search:e}),this.readOneDataMessage=async t=>await window.Codicent.data.readOne(t),this.updateDataMessage=async(t,e)=>await window.Codicent.data.update({id:t,data:e,codicent:this.codicent}),this.deleteDataMessage=async t=>await window.Codicent.data.delete({id:t,codicent:this.codicent}),this.getAppTheme=async()=>{try{const t=await window.Codicent.getDataMessages({tags:["app-theme"],codicent:this.codicent});return t.length>0?t[0].data:null}catch(t){return console.error("Error fetching app theme:",t),null}},this.getAppButtons=async()=>{const t=(await window.Codicent.getDataMessages({tags:[this.options.BUTTON_TAG],codicent:this.codicent})).map((t=>t.data));return t.sort(((t,e)=>t.title>e.title?1:-1)),t},this.getAppTasks=async()=>(await window.Codicent.getMessages({search:`@${this.codicent} #app-task`,length:50})).map((t=>{const o=new e(t.content).content.split("\n"),n=o[0],a=o.slice(1).join("\n");return{id:t.id,title:n,content:a}})),this.getAppPrompts=async()=>(await window.Codicent.getDataMessages({tags:["chatprompt"],codicent:this.codicent})).map((t=>t.data)).map((({title:t,prompt:e})=>({title:t,prompt:e}))),this.uploadFile=async(t,e)=>await window.Codicent.upload(e,t),this.getFileInfo=async t=>await window.Codicent.getFileInfo(t),this.sendMessage=(t,e)=>window.Codicent.postMessage({message:`@${this.codicent} ${t}`,type:"text",parentId:e}),this.chat=(t,e)=>window.Codicent.getChatReply3({message:t,codicent:this.codicent,messageId:e}),this.getMessagesFast=async(t,e,o=100,a=void 0)=>{const i=await fetch(`${n}app/AppGetMessages`,{method:"POST",headers:[["Authorization",`Bearer ${this.getToken()}`],["Content-Type","application/json; charset=utf-8"]],body:JSON.stringify({tags:t,codicent:this.codicent,search:e,length:o})});if(!i.ok)throw 401===i.status&&this.handleUnauthorized(),new Error(`${i.statusText}`);let s=await i.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),a){const t=await this.getPublicFlow(a);s=s.concat(t),s.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime()))}return s},this.getMessages=async(t,e)=>{let o=[];for(const e of t){const t=await window.Codicent.getMessages({search:`@${this.codicent} #${e}`,length:10});"chat"===e&&t.forEach((t=>t.content=`#chat\n${t.content}`)),o=o.concat(t)}if(e)try{const t=await this.getPublicFlow(e);o=o.concat(t)}catch(t){console.warn("Error fetching public flow, PUBLIC_TAG missing in codicent?",t)}return o=o.filter(((t,e,o)=>e===o.findIndex((e=>e.id===t.id)))),o.sort(((t,e)=>e.createdAt.getTime()-t.createdAt.getTime())),o},this.registerUser=async(t,e,o,a)=>{const i=await fetch(`${n}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${a}`]],body:JSON.stringify({nickname:t,email:e,userId:o})});if(!i.ok)return"";const s=await i.text();return window.Codicent.init({token:a,baseUrl:n}),s},this.loginUser=async(t,e)=>{try{const o=await fetch(`${n}app/LoginAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${e}`]],body:JSON.stringify({userId:t})});if(!o.ok)return 404===o.status||400===o.status?null:401===o.status?(this.handleUnauthorized(),null):"";const a=await o.text();return this.setToken(a),a}catch(t){return console.warn("Error logging in user:",t),""}},this.nicknameExists=async t=>{const e=await fetch(`${n}app/NicknameExists?nickname=${encodeURIComponent(t)}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"]]});if(!e.ok)return!1;return await e.json()},this.logout=()=>{this.setToken("")},this.isRegistered=()=>null!==localStorage.getItem("codicent_nickname"),this.getApps=async()=>{try{const t=await fetch(`${n}app/AppGetApps`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw t.status,new Error(`${t.statusText}`);const e=await t.json();return e.filter(((t,e,o)=>e===o.findIndex((e=>e.id===t.id))&&(this.options.APP_NAME||t.id.startsWith(this.options.APP_PREFIX))))}catch(t){return console.warn("Error fetching apps:",t),null}},this.addFollower=async(t,e)=>{const o=await fetch(`${n}app/AddFollower?nickname=${t}&followerNickname=${e}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!o.ok)throw o.status,new Error(`${o.statusText||"Failed to add follower!"}`);return await o.json()},this.cloneProject=async(t,e)=>{const o=await fetch(`${n}app/CloneProject?project=${t}&newProject=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!o.ok)throw o.status,new Error(`${o.statusText}`);let a=await o.json();if(a){const t='#data #app-theme \n{\n "textcolor": "#212121",\n "backgroundcolor": "#273044",\n "color": "#ffffff",\n "logo": "https://codicent.com/logo512.png",\n "title": "",\n "themeColor": "#581d71",\n "buttonColor": "#c0c0c0",\n "buttonTextColor": "#000000",\n "font": "Montserrat",\n "welcome": "Hej {{username}}!",\n "chatPlaceholder": "Tjena, Loociz här! Vad vill du?",\n "textPlaceholder": "Skriv det du vill spara, så tar jag (Loociz alltså) hand om det!",\n "transcriptionInstructions": "Tryck på knappen för att start och sedan stoppa ljudinspelning."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}if(a){const t='#data #app-button\n{\n "title": "Ta fram företagsinfo",\n "url": "/#/chat?text=Hej!%20Jag%20vill%20spara%20f%C3%B6retagsinfo.%20Guida%20mig%20steg%20f%C3%B6r%20steg%2C%20ett%20i%20taget%2C%20tills%20vi%20har%20all%20info%20om%20mitt%20f%C3%B6retag.%20Exempel%20p%C3%A5%20data%3A%20f%C3%B6retagsnamn%20eller%20id%C3%A9namn%2C%20org.nr.%2C%20%C3%A4gare%2C%20kontaktinformation%2C%20vision%2C%20aff%C3%A4rsid%C3%A9%2C%20mm."\n}';try{await window.Codicent.postMessage({message:`@${e} ${t}`,type:"text"})||(a=!1)}catch{a=!1}}}return a},this.getNickname=async()=>{try{const t=a.split(".")[1],e=atob(t),o=JSON.parse(e),i=o.sub||o.userId,s=await fetch(`${n}app/GetNickname?userId=${i}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${s.statusText}`);return await s.text()}catch{return""}},this.getChatInstructions=async()=>{try{const t=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:1});if(t.length>0)return t[0].content}catch{console.warn("Error fetching chat instructions")}return""},this.updateChatInstructions=async t=>{try{const e=await window.Codicent.getMessages({search:`@${this.codicent} #instructions`,length:100}),o=`@${this.codicent} #instructions\n${t}`;e.length>0?e[0].content!==o&&(console.log("updating instructions",o),await window.Codicent.postMessage({message:o,type:"text",parentId:e[0].id})):(console.log("new instructions",o),await window.Codicent.postMessage({message:o,type:"text"}))}catch{console.warn("Error updating chat instructions")}},this.getUserInfo=async(t,e=!1)=>{const o=await fetch(`${n}/app/GetUserInfo?nickname=${t}${e?"&t="+Date.now():""}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!o.ok)throw 401===o.status?(this.handleUnauthorized(),new Error("Unauthorized")):new Error(`${o.statusText}`);const a=await o.json(),{email:i,picture:s,description:r,followers:c,properties:h,owner:d}=a;return{nickname:t,email:i,name:r,picture:s,followers:c,properties:h,owner:d}},this.updateUserInfo=async({nickname:t,email:e,name:o,picture:a})=>{const i=await fetch(`${n}/app/AddOrUpdateUser`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({nickname:t,email:e,name:o,picture:a,description:""})});if(!i.ok)throw i.status,new Error(`${i.statusText}`);return await this.getUserInfo(t,!0)},this.requestInvite=async(t,e)=>{const o=await fetch(`${n}/app/CreateInvitationOrRequest?forUserNickname=${t}&toProjectNickname=${e}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!o.ok||(console.warn(`requestInvite() => ${o.statusText}`),!1)},this.getProjectInfo=this.getUserInfo,this.updateMembersAccess=async(t,e)=>{const o=await fetch(`${n}/app/AddOrUpdateProjectProperty?project=${t}&key=APP_EDITORS&value=${e.join(",")}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return!!o.ok||(console.warn(`updateMembersAccess() => ${o.statusText}`),!1)},this.getMembersAccess=async t=>{const e=(await this.getProjectInfo(t,!0)).properties.find((t=>"APP_EDITORS"===t.name));return e&&e.value?e.value.split(","):[]},this.setToken=t=>{a=t,a&&window.Codicent.init({token:a,baseUrl:n})},this.getToken=()=>a,this.checkPurchaseStatus=async()=>{const t=await fetch(`${n}payments/GetPaymentStatus`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!t.ok)throw new Error("Failed to check purchase status");const{isPaid:e}=await t.json();return e},this.checkSubscriptionStatus=async()=>{if(!this.options.SUBSCRIPTION_NEEDED)return"active";const t=await fetch(`${n}payments/GetSubscriptionStatus?t=${Date.now()}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`],["Cache-Control","no-cache, no-store, must-revalidate"],["Pragma","no-cache"],["Expires","0"]]});if(!t.ok)throw new Error("Failed to check subscription status");const{status:e}=await t.json();return e},this.createCheckoutSession=async t=>{const e=await fetch(`${n}payments/CreateCheckoutSession`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]],body:JSON.stringify({priceId:t,successUrl:window.location.href,cancelUrl:window.location.href})});if(!e.ok)throw new Error("Failed to create checkout session");const{id:o}=await e.json();return o},this.redirectToCheckout=async e=>{const o=await t(this.options.STRIPE_PUBLIC_KEY);if(!o)throw new Error("Stripe failed to load");const n=await this.createCheckoutSession(e),{error:a}=await o.redirectToCheckout({sessionId:n});if(a)throw new Error(a.message)},this.getChatHistory=async t=>{const e=await fetch(`${n}api/GetMessageHistory?messageId=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get chat history");let o=await e.json();return o=o.filter((t=>!t.content.includes("#function_result")&&!t.content.includes("#finish_reason_function_call"))),o},this.getPublicFlow=async t=>{const e=await fetch(`${n}/app/GetPublicFlow?codicent=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});if(!e.ok)throw new Error("Failed to get public flow");const o=await e.json();return o.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),o},this.getMessageContent=async t=>{const e=await fetch(`${n}app/GetMessageContent?id=${t}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(e.ok){const t=await e.json();return{content:t.content,url:t.url}}return{content:"",url:""}},this.logAction=async(t,e)=>{if(!this.options.APP_LOG_CODICENT)return"";const o={content:`@${this.options.APP_LOG_CODICENT} #debug #${e}\n${t}`,type:"text"},a=await fetch(`${n}app/AddChatMessage`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.options.APP_LOG_TOKEN}`]],body:JSON.stringify(o)});if(!a.ok)throw new Error(`${a.statusText||"Failed to post log message!"}`);return(await a.json()).id},this.createApp=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.APP_PREFIX}${t}`;if(!await this.nicknameExists(e)){if(await this.cloneProject(this.options.APP_TEMPLATE,e)){if(this.options.ANONYMOUS_TOKEN)try{const t=this.options.ANONYMOUS_TOKEN.split(".")[1],o=atob(t),n=JSON.parse(o).nickname;if(!await this.addFollower(e,n))throw new Error("Failed to add follower: "+n)}catch(t){console.error("Error extracting adding anonymous follower:",t)}return e}}}}catch(t){console.error("Error creating app:",t)}return null},this.findUsername=async()=>{try{for(let t=0;t<50;t++){const t=Math.floor(99999*Math.random())+1,e=`${this.options.USER_PREFIX}${t}`;if(!await this.nicknameExists(e))return e}}catch(t){console.warn("Error finding username:",t)}return null},this.getForms=async()=>{const t=await fetch(`${n}app/GetForms?codicent=${this.codicent}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await t.json()},this.getFormById=async t=>{const e=await fetch(`${n}app/GetFormById?id=${t}`,{method:"GET",headers:[["Authorization",`Bearer ${this.getToken()}`]]});return await e.json()},this.codicent="",this.options=o}handleUnauthorized(){this.onUnauthorized&&this.onUnauthorized()}}o=r,r.getImageUrl=(t,e)=>`${n}app/GetImage?fileId=${t}&width=${e}`,r.getFileUrl=(t,e)=>`${n}app/DownloadFile?fileId=${t}${e?`&extension=${e}`:""}`,r.downloadFile=async t=>{fetch(o.getFileUrl(t.id)).then((t=>{if(t.headers.forEach(((t,e)=>{console.log(`${e}: ${t}`)})),t.ok)return t.blob();throw new Error("Network response was not ok.")})).then((e=>{const o=window.URL.createObjectURL(e),n=document.createElement("a");n.style.display="none",n.href=o,n.download=t.filename,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(o)})).catch((t=>{console.error("There was a problem with the fetch operation:",t)}))},r.getMiniChatReply=async(t,e="codicent-mini",o)=>{const a=await fetch(`${n}app/GetAi2ChatReply?message=${t}&project=${e}${o?"&messageId="+o:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!a.ok)return void a.status;return(await a.json()).content.replace("@codicent-mini","").trim()};export{r as CodicentService};
package/dist/index.d.ts CHANGED
@@ -132,6 +132,7 @@ interface TextareaProps {
132
132
  className?: string;
133
133
  onFocus?: (event: React$1.FocusEvent<HTMLTextAreaElement>) => void;
134
134
  onPaste?: (event: React$1.ClipboardEvent<HTMLTextAreaElement>) => void;
135
+ id?: string;
135
136
  }
136
137
  declare const Textarea: React$1.FC<TextareaProps>;
137
138
 
@@ -225,6 +226,7 @@ interface ChatInputProps {
225
226
  noMemory?: boolean;
226
227
  selectAll?: boolean;
227
228
  clearOnFocus?: boolean;
229
+ id?: string;
228
230
  }
229
231
  declare const ChatInput: React__default.FC<ChatInputProps>;
230
232
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codicent-app-sdk",
3
- "version": "0.3.66",
3
+ "version": "0.3.68",
4
4
  "description": "SDK for building AI-powered applications with Codicent",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",