codicent-app-sdk 0.3.34 → 0.3.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useAuthState.d.ts.map +1 -1
- package/dist/cjs/hooks/useAuthState.js +1 -1
- package/dist/cjs/hooks/useAuthState.js.map +1 -1
- package/dist/cjs/pages/CrmPage.d.ts.map +1 -1
- package/dist/cjs/pages/CrmPage.js +1 -1
- package/dist/cjs/services/codicent.d.ts +2 -0
- package/dist/cjs/services/codicent.d.ts.map +1 -1
- package/dist/cjs/services/codicent.js +1 -1
- package/dist/cjs/services/codicent.js.map +1 -1
- package/dist/esm/hooks/useAuthState.d.ts.map +1 -1
- package/dist/esm/hooks/useAuthState.js +1 -1
- package/dist/esm/hooks/useAuthState.js.map +1 -1
- package/dist/esm/node_modules/style-to-js/cjs/index.js +1 -1
- package/dist/esm/pages/CrmPage.d.ts.map +1 -1
- package/dist/esm/pages/CrmPage.js +1 -1
- package/dist/esm/services/codicent.d.ts +2 -0
- package/dist/esm/services/codicent.d.ts.map +1 -1
- package/dist/esm/services/codicent.js +1 -1
- package/dist/esm/services/codicent.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAuthState.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAUrC,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IAInB,IAAI,EA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ty(exports,"__esModule",{value:!0});var e=require("react"),r=require("../services/codicent.js");require("../components/Markdown.js"),require("../components/Textarea.js"),require("../components/Button.js"),require("react/jsx-runtime"),require("../components/Spinner.js"),require("../components/TextHeader.js"),require("../components/TypingIndicator.js"),require("../components/Dialog.js"),require("../components/ChatInput.js"),require("../components/CombinedPlaceholderDialog.js"),require("../components/ChatMessage.js"),require("../components/Header.js");var o=require("../config/index.js");require("../stores/chatStore.js"),require("../utils/MessageContent.js"),require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/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("./useLocalization.js"),require("./useAppStyles.js"),require("../components/FileThumbnail.js"),require("../components/MessageInput.js"),require("../components/UploadFile.js"),require("../components/SnapFooter.js"),require("../components/Profile.js"),require("../components/MessageItem.js"),require("../components/Content.js"),require("../components/AiInput.js"),require("../components/SearchBox.js"),require("../components/HtmlView.js"),require("../components/Footer.js"),require("../components/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");exports.default=s=>{const{isAuthenticated:t,getAccessTokenSilently:n,user:i,isLoading:u,logout:a,getAccessTokenWithPopup:c,loginWithRedirect:l}=s,[g,p]=e.useState(null),[q,
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("../services/codicent.js");require("../components/Markdown.js"),require("../components/Textarea.js"),require("../components/Button.js"),require("react/jsx-runtime"),require("../components/Spinner.js"),require("../components/TextHeader.js"),require("../components/TypingIndicator.js"),require("../components/Dialog.js"),require("../components/ChatInput.js"),require("../components/CombinedPlaceholderDialog.js"),require("../components/ChatMessage.js"),require("../components/Header.js");var o=require("../config/index.js");require("../stores/chatStore.js"),require("../utils/MessageContent.js"),require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/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("./useLocalization.js"),require("./useAppStyles.js"),require("../components/FileThumbnail.js"),require("../components/MessageInput.js"),require("../components/UploadFile.js"),require("../components/SnapFooter.js"),require("../components/Profile.js"),require("../components/MessageItem.js"),require("../components/Content.js"),require("../components/AiInput.js"),require("../components/SearchBox.js"),require("../components/HtmlView.js"),require("../components/Footer.js"),require("../components/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");exports.default=s=>{const{isAuthenticated:t,getAccessTokenSilently:n,user:i,isLoading:u,logout:a,getAccessTokenWithPopup:c,loginWithRedirect:l}=s,[g,p]=e.useState(null),[q,E]=e.useState(void 0),[j,C]=e.useState(null),[m,_]=e.useState(""),T=e.useMemo((()=>new r.CodicentService({API_BASE_URL:o.getConfigValue("API_BASE_URL"),APP_LOG_CODICENT:o.getConfigValue("APP_LOG_CODICENT"),APP_LOG_TOKEN:o.getConfigValue("APP_LOG_TOKEN"),APP_NAME:o.getConfigValue("APP_NAME"),APP_PREFIX:o.getConfigValue("APP_PREFIX"),APP_TEMPLATE:o.getConfigValue("APP_TEMPLATE"),BUTTON_TAG:o.getConfigValue("BUTTON_TAG"),STRIPE_PUBLIC_KEY:o.getConfigValue("STRIPE_PUBLIC_KEY"),SUBSCRIPTION_NEEDED:o.getConfigValue("SUBSCRIPTION_NEEDED"),USER_PREFIX:o.getConfigValue("USER_PREFIX"),ANONYMOUS_TOKEN:o.getConfigValue("ANONYMOUS_TOKEN")})),[]);e.useEffect((()=>{u||(async()=>{try{const e=await n({});console.debug("CODICENT: ACCESS TOKEN",e),p(e)}catch(e){console.debug("CODICENT: Failed to get access token",e);const r=e;if(r&&"object"==typeof r&&"error"in r&&"login_required"===r.error)console.warn("CODICENT: Login required"),P();else if(r&&"object"==typeof r&&"error"in r&&"consent_required"===r.error)try{const e=await c();if(!e)return void C("Failed to get access token: no token from auth0 with popup");console.log("CODICENT: GOT ACCESS TOKEN"),p(e)}catch(e){console.warn("CODICENT: Failed to get access token with popup",e),P()}else C("Failed to get access token: "+(r.message?.toString()||r.toString())),console.log("CODICENT: ACCESS TOKEN ERROR",r)}})().then((()=>{}))}),[t,c,n,l,u]),e.useEffect((()=>{if(i&&i.sub&&g&&void 0===q){let e=!0;return T.loginUser(i.sub,g).then((r=>{e&&(null===r?E(!1):""===r?C("Kontrollera internetanslutningen och försök igen."):(T.setToken(g),T.getNickname().then(_),E(!0)))})).catch((()=>{e&&(C("Ett fel uppstod. Försök igen senare."),E(!1))})),()=>{e=!1}}}),[i,g,q,T]);const P=()=>{T.logout(),p(null),C(null),E(void 0),_(""),a({logoutParams:{returnTo:o.getConfigValue("AUTH_REDIRECT_URL")}})};return{isAuthenticated:t,isRegistered:q,accessToken:g,authError:j,isLoading:u,user:i,nickname:m,logout:P,registerUser:async e=>{const r=await T.registerUser(e,i.email,i.sub,g);return r&&(T.setToken(g),E(!0)),r},codicentService:T,loginWithRedirect:l}};
|
2
2
|
//# sourceMappingURL=useAuthState.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAuthState.js","sources":["../../../../src/hooks/useAuthState.ts"],"sourcesContent":[null],"names":["isAuthenticated","getAccessTokenSilently","user","isLoading","logout","getAccessTokenWithPopup","loginWithRedirect","auth0","accessToken","setAccessToken","useState","isRegistered","setIsRegistered","undefined","authError","setAuthError","nickname","setNickname","codicentService","useMemo","CodicentService","API_BASE_URL","getConfigValue","APP_LOG_CODICENT","APP_LOG_TOKEN","APP_NAME","APP_PREFIX","APP_TEMPLATE"],"mappings":"qwDAcE,MAAAA,gBAAAA,EAAwBC,uBAAAA,EAAUC,KAAAA,EAAAC,UAAAA,EAAAC,OAAAA,EAAAC,wBAAAA,EAAAC,kBAAAA,GAAAC,GAClCC,EAAsBC,GAAKC,EAAAA,SAAA,OAC3BC,EAAoBC,GAAKF,EAAAA,cAAAG,IAChBC,EAASC,GAACL,EAAAA,SAAA,OAKXM,EAASC,GAAAP,EAAAA,SAAA,IACXQ,EAAaC,EAAAA,SAAA,IAAA,IAAAC,kBAAA,CACPC,aAAGC,iCACAC,mBAAkBD,eAAA,oBACjCE,cAAmBF,EAA+BA,eAAA,iBACnDG,SAAAH,EAAAA,eAAA,YAEDI,WAAkBJ,EAAAA,eAAA,
|
1
|
+
{"version":3,"file":"useAuthState.js","sources":["../../../../src/hooks/useAuthState.ts"],"sourcesContent":[null],"names":["isAuthenticated","getAccessTokenSilently","user","isLoading","logout","getAccessTokenWithPopup","loginWithRedirect","auth0","accessToken","setAccessToken","useState","isRegistered","setIsRegistered","undefined","authError","setAuthError","nickname","setNickname","codicentService","useMemo","CodicentService","API_BASE_URL","getConfigValue","APP_LOG_CODICENT","APP_LOG_TOKEN","APP_NAME","APP_PREFIX","APP_TEMPLATE"],"mappings":"qwDAcE,MAAAA,gBAAAA,EAAwBC,uBAAAA,EAAUC,KAAAA,EAAAC,UAAAA,EAAAC,OAAAA,EAAAC,wBAAAA,EAAAC,kBAAAA,GAAAC,GAClCC,EAAsBC,GAAKC,EAAAA,SAAA,OAC3BC,EAAoBC,GAAKF,EAAAA,cAAAG,IAChBC,EAASC,GAACL,EAAAA,SAAA,OAKXM,EAASC,GAAAP,EAAAA,SAAA,IACXQ,EAAaC,EAAAA,SAAA,IAAA,IAAAC,kBAAA,CACPC,aAAGC,iCACAC,mBAAkBD,eAAA,oBACjCE,cAAmBF,EAA+BA,eAAA,iBACnDG,SAAAH,EAAAA,eAAA,YAEDI,WAAkBJ,EAAAA,eAAA,cAyOlBK,eAA4BL,eAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CrmPage.d.ts","sourceRoot":"","sources":["../../../src/pages/CrmPage.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAA+B,MAAM,UAAU,CAAC;AAuDzE,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,KAAK,EAAE,gBAAgB,CAAA;CAAE,
|
1
|
+
{"version":3,"file":"CrmPage.d.ts","sourceRoot":"","sources":["../../../src/pages/CrmPage.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAA+B,MAAM,UAAU,CAAC;AAuDzE,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAoRzD,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),o=require("../services/codicent.js");require("../components/Markdown.js"),require("../components/Textarea.js"),require("../components/Button.js"),require("../components/Spinner.js");var t=require("../components/TextHeader.js");require("../components/TypingIndicator.js"),require("../components/Dialog.js"),require("../components/ChatInput.js"),require("../components/CombinedPlaceholderDialog.js"),require("../components/ChatMessage.js"),require("../components/Header.js"),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("../components/FileThumbnail.js");var n=require("../components/MessageInput.js"),s=require("../components/UploadFile.js");require("../components/SnapFooter.js"),require("../components/Profile.js"),require("../components/MessageItem.js"),require("../components/Content.js"),require("../components/AiInput.js"),require("../components/SearchBox.js"),require("../components/HtmlView.js"),require("../components/Footer.js");var a=require("../components/Page.js");require("./AppFrame.js"),require("./Snap.js"),require("./Search.js"),require("./Login.js"),require("./ImageView.js"),require("./FormInvite.js"),require("./FormAccept.js"),require("./Sales.js"),require("../stores/chatStore.js");var l=require("../hooks/useLocalization.js");require("../hooks/useAppStyles.js");var u=require("../hooks/useToaster.js"),c=require("react-router-dom"),d=require("../node_modules/@griffel/react/makeStyles.esm.js"),p=require("../node_modules/@griffel/core/index.esm.js"),m=require("../node_modules/@fluentui/tokens/lib/tokens.js");const g=d.makeStyles({main:{flexGrow:1,...p.shorthands.padding("10px"),overflowY:"auto"},container:{maxWidth:"640px",margin:"0 auto",backgroundPosition:"calc(50% + 100px) center",backgroundRepeat:"no-repeat",backgroundSize:"contain",height:"100%"},root:{height:"100%"},item:{height:"auto",width:"auto",flexShrink:1,marginBottom:"1rem"},chat:{flexGrow:1,boxSizing:"border-box",overflow:"hidden",border:"none"},attachmentBar:{display:"none"},iconButton:{width:"24px",height:"24px"},imageCard:{alignContent:"center",borderRadius:m.tokens.borderRadiusLarge,height:"240px",textAlign:"left",position:"relative"}}),j=({state:d})=>{const p=g(),{t:m}=l.default(),[j,q]=r.useState(!1),h=r.useRef(null),f=r.useRef(null),v=r.useRef(null),[x]=r.useState(null),[S,b]=r.useState([]),{service:C}=d,[k,_]=c.useSearchParams(),[w,I]=r.useState("");r.useState(void 0),r.useState(void 0),r.useState(void 0);const[U,y]=r.useState(void 0),F=u.default(),P=r.useCallback((e=>{for(const r of e)C.getFileInfo(r).then((e=>{b((r=>[...r,e]))}))}),[C,b]),M=r.useCallback((e=>{const r=new FormData;r.append("file",e),C.uploadFile(e.name,r).then((e=>{P([e])})).catch((()=>{F.notify(m("Error"),m("Error uploading pasted image"),"")}))}),[C,P,F,m]),A=e=>{q(e)};r.useEffect((()=>{const e=k.get("text"),r=k.get("url");e&&(I(e),k.delete("text")),r&&(k.delete("url"),I(((e||"")+" "+r).trim())),_(k,{replace:!0})}),[k,_,I,C,P]);return e.jsx(a.Page,{hideHeader:!0,children:e.jsxs("div",{className:p.container,style:{backgroundImage:`url(${i.getConfigValue("COMPOSE_BACKGROUND_IMAGE_URL")})`},children:[e.jsx(t.default,{title:i.getConfigValue("APP_SAVE_TITLE")?m(i.getConfigValue("APP_SAVE_TITLE")):m("Spara")}),e.jsx(n.default,{defaultText:w,onSend:e=>{e=`${e="#crm\n"+e.replace("#log ","")}${x?" "+x:""}${S.length>0?"\n":""}${S.map((e=>`#file:${e.id}`)).join(" ")}`,C.sendMessage(e).then((()=>{F.notify(m("Meddelande"),m("Meddelandet är sparat."),"")}))},files:S,onFilesChange:b,isUploading:j,onUploadImage:()=>{f.current?.triggerUpload()},onUploadCamera:()=>{v.current?.triggerUpload()},getImageUrl:o.CodicentService.getImageUrl,hasLocation:!!x,disableSend:!0,rows:9,placeholder:m("Beskriv CRM-aktivitet här..."),onChange:e=>{y(e)},onImagePasted:M}),e.jsx(s.default,{ref:h,onFileUploaded:P,onUploading:A,multiple:!0,codicentService:C}),e.jsx(s.default,{codicentService:C,ref:f,onFileUploaded:P,onUploading:A,multiple:!0,accept:"image/*"}),e.jsx(s.default,{codicentService:C,ref:v,onFileUploaded:P,onUploading:A,multiple:!0,accept:"image/*",capture:"environment"})]})})};exports.CrmPage=j,exports.default=j;
|
2
2
|
//# sourceMappingURL=CrmPage.js.map
|
@@ -27,6 +27,7 @@ export interface CodicentServiceOptions {
|
|
27
27
|
STRIPE_PUBLIC_KEY: string;
|
28
28
|
SUBSCRIPTION_NEEDED: boolean;
|
29
29
|
USER_PREFIX: string;
|
30
|
+
ANONYMOUS_TOKEN?: string;
|
30
31
|
}
|
31
32
|
export declare class CodicentService {
|
32
33
|
codicent: string;
|
@@ -57,6 +58,7 @@ export declare class CodicentService {
|
|
57
58
|
logout: () => void;
|
58
59
|
isRegistered: () => boolean;
|
59
60
|
getApps: () => Promise<AppInfo[] | null>;
|
61
|
+
addFollower: (nickname: string, followerNickname: string) => Promise<boolean>;
|
60
62
|
cloneProject: (project: string, newProject: string) => Promise<boolean>;
|
61
63
|
getNickname: () => Promise<string>;
|
62
64
|
getChatInstructions: () => Promise<string>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codicent.d.ts","sourceRoot":"","sources":["../../../src/services/codicent.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvC,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC/C;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;
|
1
|
+
{"version":3,"file":"codicent.d.ts","sourceRoot":"","sources":["../../../src/services/codicent.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI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EF,iBAAiB,OAAc,MAAM;;;OAcnC;IAEF,SAAS,YAAmB,MAAM,YAAY,MAAM,qBAqBlD;IAEF,SAAS,+BAuCP;IAEF,YAAY,+BAeV;IAEF,MAAM,CAAC,YAAY,SAAgB,QAAQ,mBAyBzC;IAEF,MAAM,CAAC,gBAAgB,YAAmB,MAAM,YAAW,MAAM,cAAgC,MAAM,iCA0BrG;IAEF,QAAQ;cAMkB,MAAM;gBAAU,MAAM;eAAS,MAAM;SAC7D;IAEF,WAAW,OAAc,MAAM,kBAO7B;CACH"}
|
@@ -1,2 +1,2 @@
|
|
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/",i="-";const a=()=>void 0!==window.Codicent&&(window.Codicent.init({token:i,baseUrl:o}),!0);let s=a();if(!s){const t=setInterval((()=>{s=a(),s&&clearInterval(t)}),100)}class r{constructor(t){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],i=e.slice(1).join("\n");return{id:t.id,title:o,content:i}})),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,i=void 0)=>{const a=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(!a.ok)throw a.status,new Error(`${a.statusText}`);let s=await a.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),i){const t=await this.getPublicFlow(i);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,i)=>{const a=await fetch(`${o}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${i}`]],body:JSON.stringify({nickname:t,email:e,userId:n})});if(!a.ok)return"";const s=await a.text();return window.Codicent.init({token:i,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||401===n.status?null:"";const i=await n.text();return this.setToken(i),i}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.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 i=await n.json();if(i){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"})||(i=!1)}catch{i=!1}if(i){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"})||(i=!1)}catch{i=!1}}}return i},this.getNickname=async()=>{try{const t=i.split(".")[1],e=atob(t),n=JSON.parse(e),a=n.sub||n.userId,s=await fetch(`${o}app/GetNickname?userId=${a}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?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?new Error("Unauthorized"):new Error(`${n.statusText}`);const i=await n.json(),{email:a,picture:s,description:r,followers:c,properties:h}=i;return{nickname:t,email:a,name:r,picture:s,followers:c,properties:h}},this.updateUserInfo=async({nickname:t,email:e,name:n,picture:i})=>{const a=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:i,description:""})});if(!a.ok)throw a.status,new Error(`${a.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=>{i=t,i&&window.Codicent.init({token:i,baseUrl:o})},this.getToken=()=>i,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:i}=await n.redirectToCheckout({sessionId:o});if(i)throw new Error(i.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"},i=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(!i.ok)throw new Error(`${i.statusText||"Failed to post log message!"}`);return(await i.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)){return await this.cloneProject(this.options.APP_TEMPLATE,e)?e:null}}}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}}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 i=await fetch(`${o}app/GetAi2ChatReply?message=${t}&project=${e}${n?"&messageId="+n:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!i.ok)return void i.status;return(await i.json()).content.replace("@codicent-mini","").trim()},exports.CodicentService=r;
|
1
|
+
"use strict";var t,e=require("../node_modules/@stripe/stripe-js/dist/index.js"),o=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 n="https://codicent.com/",i="-";const a=()=>void 0!==window.Codicent&&(window.Codicent.init({token:i,baseUrl:n}),!0);let s=a();if(!s){const t=setInterval((()=>{s=a(),s&&clearInterval(t)}),100)}class r{constructor(t){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 o.default(t.content).content.split("\n"),n=e[0],i=e.slice(1).join("\n");return{id:t.id,title:n,content:i}})),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,i=void 0)=>{const a=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(!a.ok)throw a.status,new Error(`${a.statusText}`);let s=await a.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),i){const t=await this.getPublicFlow(i);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,i)=>{const a=await fetch(`${n}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${i}`]],body:JSON.stringify({nickname:t,email:e,userId:o})});if(!a.ok)return"";const s=await a.text();return window.Codicent.init({token:i,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||401===o.status?null:"";const i=await o.text();return this.setToken(i),i}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()).filter(((t,e,o)=>e===o.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 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 i=await o.json();if(i){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"})||(i=!1)}catch{i=!1}if(i){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"})||(i=!1)}catch{i=!1}}}return i},this.getNickname=async()=>{try{const t=i.split(".")[1],e=atob(t),o=JSON.parse(e),a=o.sub||o.userId,s=await fetch(`${n}app/GetNickname?userId=${a}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?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?new Error("Unauthorized"):new Error(`${o.statusText}`);const i=await o.json(),{email:a,picture:s,description:r,followers:c,properties:h}=i;return{nickname:t,email:a,name:r,picture:s,followers:c,properties:h}},this.updateUserInfo=async({nickname:t,email:e,name:o,picture:i})=>{const a=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:i,description:""})});if(!a.ok)throw a.status,new Error(`${a.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=>{i=t,i&&window.Codicent.init({token:i,baseUrl:n})},this.getToken=()=>i,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 t=>{const o=await e.loadStripe(this.options.STRIPE_PUBLIC_KEY);if(!o)throw new Error("Stripe failed to load");const n=await this.createCheckoutSession(t),{error:i}=await o.redirectToCheckout({sessionId:n});if(i)throw new Error(i.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"},i=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(!i.ok)throw new Error(`${i.statusText||"Failed to post log message!"}`);return(await i.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 null}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=t}}t=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 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 o=window.URL.createObjectURL(t),n=document.createElement("a");n.style.display="none",n.href=o,n.download=e.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 i=await fetch(`${n}app/GetAi2ChatReply?message=${t}&project=${e}${o?"&messageId="+o:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!i.ok)return void i.status;return(await i.json()).content.replace("@codicent-mini","").trim()},exports.CodicentService=r;
|
2
2
|
//# sourceMappingURL=codicent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codicent.js","sources":["../../../../src/services/codicent.ts"],"sourcesContent":[null],"names":["_a","baseUrl","token","initializeCodicent","window","Codicent","init","initialized","setInterval","clearInterval","initInterval","CodicentService","constructor","options","this","getAppTheme","datas","getDataMessages","tags","codicent","length","data","error","console","async","appButtons","BUTTON_TAG","map","d","sort","a","b","title","getAppTasks","getMessages","search","m","rows","MessageContent","
|
1
|
+
{"version":3,"file":"codicent.js","sources":["../../../../src/services/codicent.ts"],"sourcesContent":[null],"names":["_a","baseUrl","token","initializeCodicent","window","Codicent","init","initialized","setInterval","clearInterval","initInterval","CodicentService","constructor","options","this","getAppTheme","datas","getDataMessages","tags","codicent","length","data","error","console","getAppButtons","async","appButtons","BUTTON_TAG","map","d","sort","a","b","title","getAppTasks","getMessages","search","m","rows","MessageContent","content","split","prompt","slice","join","id","getAppPrompts","uploadFile","filename","formData","upload","getFileInfo","fileId","sendMessage","message","parentId","postMessage","type","chat","messageId","getChatReply3","getMessagesFast","publicCodicent","undefined","response","fetch","method","headers","getToken","body","JSON","stringify","status","messages","json","forEach","createdAt","Date","parse","concat","publicMessages","getTime"],"mappings":"iBA4BAA,wdAGEC,0BACAC,EAAO,IACP,MAAAC,EAAW,SAAuB,IAARC,OAAAC,WAAaD,OAAAC,SAAAC,KAAA,CACvCJ,QAAkBD,aAA4B,OAM9CM,EAAaJ,IACd,IAAAI,EAAA,CAED,QAAuCC,aAAA,KACzBD,MACIA,GACHE,cAASC,EACd,GACE,KAEA,MAAAC,EACV,WAAAC,CAAiBC,GACEC,KAAAC,sBACR,IACI,MAAGC,QAAOZ,OAAAC,SAAAY,gBAAA,CAAAC,KAAA,CAA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AAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,eAAe,EAAE,eAAe,CAAC;IACjC,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChF;AAED,QAAA,MAAM,YAAY,UAAW,qBAAqB,KAAG,
|
1
|
+
{"version":3,"file":"useAuthState.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuthState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAUrC,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IAInB,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,eAAe,EAAE,eAAe,CAAC;IACjC,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChF;AAED,QAAA,MAAM,YAAY,UAAW,qBAAqB,KAAG,YAuOpD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{useState as o,useMemo as e,useEffect as t}from"react";import{CodicentService as s}from"../services/codicent.js";import"../components/Markdown.js";import"../components/Textarea.js";import"../components/Button.js";import"react/jsx-runtime";import"../components/Spinner.js";import"../components/TextHeader.js";import"../components/TypingIndicator.js";import"../components/Dialog.js";import"../components/ChatInput.js";import"../components/CombinedPlaceholderDialog.js";import"../components/ChatMessage.js";import"../components/Header.js";import{getConfigValue as n}from"../config/index.js";import"../stores/chatStore.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/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"./useLocalization.js";import"./useAppStyles.js";import"../components/FileThumbnail.js";import"../components/MessageInput.js";import"../components/UploadFile.js";import"../components/SnapFooter.js";import"../components/Profile.js";import"../components/MessageItem.js";import"../components/Content.js";import"../components/AiInput.js";import"../components/SearchBox.js";import"../components/HtmlView.js";import"../components/Footer.js";import"../components/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";const i=i=>{const{isAuthenticated:r,getAccessTokenSilently:p,user:a,isLoading:m,logout:c,getAccessTokenWithPopup:l,loginWithRedirect:g}=i,[j,
|
1
|
+
import{useState as o,useMemo as e,useEffect as t}from"react";import{CodicentService as s}from"../services/codicent.js";import"../components/Markdown.js";import"../components/Textarea.js";import"../components/Button.js";import"react/jsx-runtime";import"../components/Spinner.js";import"../components/TextHeader.js";import"../components/TypingIndicator.js";import"../components/Dialog.js";import"../components/ChatInput.js";import"../components/CombinedPlaceholderDialog.js";import"../components/ChatMessage.js";import"../components/Header.js";import{getConfigValue as n}from"../config/index.js";import"../stores/chatStore.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/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"./useLocalization.js";import"./useAppStyles.js";import"../components/FileThumbnail.js";import"../components/MessageInput.js";import"../components/UploadFile.js";import"../components/SnapFooter.js";import"../components/Profile.js";import"../components/MessageItem.js";import"../components/Content.js";import"../components/AiInput.js";import"../components/SearchBox.js";import"../components/HtmlView.js";import"../components/Footer.js";import"../components/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";const i=i=>{const{isAuthenticated:r,getAccessTokenSilently:p,user:a,isLoading:m,logout:c,getAccessTokenWithPopup:l,loginWithRedirect:g}=i,[j,E]=o(null),[u,T]=o(void 0),[_,P]=o(null),[d,A]=o(""),C=e((()=>new s({API_BASE_URL:n("API_BASE_URL"),APP_LOG_CODICENT:n("APP_LOG_CODICENT"),APP_LOG_TOKEN:n("APP_LOG_TOKEN"),APP_NAME:n("APP_NAME"),APP_PREFIX:n("APP_PREFIX"),APP_TEMPLATE:n("APP_TEMPLATE"),BUTTON_TAG:n("BUTTON_TAG"),STRIPE_PUBLIC_KEY:n("STRIPE_PUBLIC_KEY"),SUBSCRIPTION_NEEDED:n("SUBSCRIPTION_NEEDED"),USER_PREFIX:n("USER_PREFIX"),ANONYMOUS_TOKEN:n("ANONYMOUS_TOKEN")})),[]);t((()=>{m||(async()=>{try{const o=await p({});console.debug("CODICENT: ACCESS TOKEN",o),E(o)}catch(o){console.debug("CODICENT: Failed to get access token",o);const e=o;if(e&&"object"==typeof e&&"error"in e&&"login_required"===e.error)console.warn("CODICENT: Login required"),I();else if(e&&"object"==typeof e&&"error"in e&&"consent_required"===e.error)try{const o=await l();if(!o)return void P("Failed to get access token: no token from auth0 with popup");console.log("CODICENT: GOT ACCESS TOKEN"),E(o)}catch(o){console.warn("CODICENT: Failed to get access token with popup",o),I()}else P("Failed to get access token: "+(e.message?.toString()||e.toString())),console.log("CODICENT: ACCESS TOKEN ERROR",e)}})().then((()=>{}))}),[r,l,p,g,m]),t((()=>{if(a&&a.sub&&j&&void 0===u){let o=!0;return C.loginUser(a.sub,j).then((e=>{o&&(null===e?T(!1):""===e?P("Kontrollera internetanslutningen och försök igen."):(C.setToken(j),C.getNickname().then(A),T(!0)))})).catch((()=>{o&&(P("Ett fel uppstod. Försök igen senare."),T(!1))})),()=>{o=!1}}}),[a,j,u,C]);const I=()=>{C.logout(),E(null),P(null),T(void 0),A(""),c({logoutParams:{returnTo:n("AUTH_REDIRECT_URL")}})};return{isAuthenticated:r,isRegistered:u,accessToken:j,authError:_,isLoading:m,user:a,nickname:d,logout:I,registerUser:async o=>{const e=await C.registerUser(o,a.email,a.sub,j);return e&&(C.setToken(j),T(!0)),e},codicentService:C,loginWithRedirect:g}};export{i as default};
|
2
2
|
//# sourceMappingURL=useAuthState.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAuthState.js","sources":["../../../../src/hooks/useAuthState.ts"],"sourcesContent":[null],"names":["useAuthState","isAuthenticated","getAccessTokenSilently","user","isLoading","logout","getAccessTokenWithPopup","loginWithRedirect","auth0","accessToken","setAccessToken","useState","isRegistered","setIsRegistered","undefined","authError","setAuthError","nickname","setNickname","codicentService","useMemo","CodicentService","API_BASE_URL","getConfigValue","APP_LOG_CODICENT","APP_LOG_TOKEN","APP_NAME","APP_PREFIX","APP_TEMPLATE"],"mappings":"unDAaiB,MAAAA,MACf,MAAAC,gBAAAA,EAAwBC,uBAAAA,EAAUC,KAAAA,EAAAC,UAAAA,EAAAC,OAAAA,EAAAC,wBAAAA,EAAAC,kBAAAA,GAAAC,GAClCC,EAAsBC,GAAKC,EAAA,OAC3BC,EAAoBC,GAAKF,OAAAG,IAChBC,EAASC,GAACL,EAAA,OAKXM,EAASC,GAAAP,EAAA,IACXQ,EAAaC,GAAA,IAAA,IAAAC,EAAA,CACPC,aAAGC,kBACAC,mBAAkB,oBACjCC,cAAmBF,EAA+B,iBACnDG,SAAAH,EAAA,YAEDI,WAAkBJ,EAAA,
|
1
|
+
{"version":3,"file":"useAuthState.js","sources":["../../../../src/hooks/useAuthState.ts"],"sourcesContent":[null],"names":["useAuthState","isAuthenticated","getAccessTokenSilently","user","isLoading","logout","getAccessTokenWithPopup","loginWithRedirect","auth0","accessToken","setAccessToken","useState","isRegistered","setIsRegistered","undefined","authError","setAuthError","nickname","setNickname","codicentService","useMemo","CodicentService","API_BASE_URL","getConfigValue","APP_LOG_CODICENT","APP_LOG_TOKEN","APP_NAME","APP_PREFIX","APP_TEMPLATE"],"mappings":"unDAaiB,MAAAA,MACf,MAAAC,gBAAAA,EAAwBC,uBAAAA,EAAUC,KAAAA,EAAAC,UAAAA,EAAAC,OAAAA,EAAAC,wBAAAA,EAAAC,kBAAAA,GAAAC,GAClCC,EAAsBC,GAAKC,EAAA,OAC3BC,EAAoBC,GAAKF,OAAAG,IAChBC,EAASC,GAACL,EAAA,OAKXM,EAASC,GAAAP,EAAA,IACXQ,EAAaC,GAAA,IAAA,IAAAC,EAAA,CACPC,aAAGC,kBACAC,mBAAkB,oBACjCC,cAAmBF,EAA+B,iBACnDG,SAAAH,EAAA,YAEDI,WAAkBJ,EAAA,cAyOlBK,eAA4B"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{
|
1
|
+
import{getDefaultExportFromCjs as t,commonjsGlobal as r}from"../../../_virtual/_commonjsHelpers.js";import"../../style-to-object/cjs/index.js";import"./utilities.js";import{__exports as e}from"../../../_virtual/index4.js";import{__exports as i}from"../../../_virtual/utilities.js";var o=(r&&r.__importDefault||function(t){return t&&t.__esModule?t:{default:t}})(e),s=i;function a(t,r){var e={};return t&&"string"==typeof t?((0,o.default)(t,(function(t,i){t&&i&&(e[(0,s.camelCase)(t,r)]=i)})),e):e}a.default=a;var u=t(a);export{u as default};
|
2
2
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CrmPage.d.ts","sourceRoot":"","sources":["../../../src/pages/CrmPage.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAA+B,MAAM,UAAU,CAAC;AAuDzE,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,KAAK,EAAE,gBAAgB,CAAA;CAAE,
|
1
|
+
{"version":3,"file":"CrmPage.d.ts","sourceRoot":"","sources":["../../../src/pages/CrmPage.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,gBAAgB,EAA+B,MAAM,UAAU,CAAC;AAuDzE,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,KAAK,EAAE,gBAAgB,CAAA;CAAE,CAoRzD,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{jsx as
|
1
|
+
import{jsx as o,jsxs as e}from"react/jsx-runtime";import{useState as t,useRef as r,useCallback as i,useEffect as n}from"react";import{CodicentService as s}from"../services/codicent.js";import"../components/Markdown.js";import"../components/Textarea.js";import"../components/Button.js";import"../components/Spinner.js";import a from"../components/TextHeader.js";import"../components/TypingIndicator.js";import"../components/Dialog.js";import"../components/ChatInput.js";import"../components/CombinedPlaceholderDialog.js";import"../components/ChatMessage.js";import"../components/Header.js";import"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/index.js";import{getConfigValue as m}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"../components/FileThumbnail.js";import p from"../components/MessageInput.js";import l from"../components/UploadFile.js";import"../components/SnapFooter.js";import"../components/Profile.js";import"../components/MessageItem.js";import"../components/Content.js";import"../components/AiInput.js";import"../components/SearchBox.js";import"../components/HtmlView.js";import"../components/Footer.js";import{Page as c}from"../components/Page.js";import"./AppFrame.js";import"./Snap.js";import"./Search.js";import"./Login.js";import"./ImageView.js";import"./FormInvite.js";import"./FormAccept.js";import"./Sales.js";import"../stores/chatStore.js";import d from"../hooks/useLocalization.js";import"../hooks/useAppStyles.js";import g from"../hooks/useToaster.js";import{useSearchParams as j}from"react-router-dom";import{makeStyles as u}from"../node_modules/@griffel/react/makeStyles.esm.js";import{shorthands as f}from"../node_modules/@griffel/core/index.esm.js";import{tokens as h}from"../node_modules/@fluentui/tokens/lib/tokens.js";const v=u({main:{flexGrow:1,...f.padding("10px"),overflowY:"auto"},container:{maxWidth:"640px",margin:"0 auto",backgroundPosition:"calc(50% + 100px) center",backgroundRepeat:"no-repeat",backgroundSize:"contain",height:"100%"},root:{height:"100%"},item:{height:"auto",width:"auto",flexShrink:1,marginBottom:"1rem"},chat:{flexGrow:1,boxSizing:"border-box",overflow:"hidden",border:"none"},attachmentBar:{display:"none"},iconButton:{width:"24px",height:"24px"},imageCard:{alignContent:"center",borderRadius:h.borderRadiusLarge,height:"240px",textAlign:"left",position:"relative"}}),x=({state:u})=>{const f=v(),{t:h}=d(),[x,b]=t(!1),S=r(null),w=r(null),_=r(null),[I]=t(null),[U,k]=t([]),{service:F}=u,[C,y]=j(),[A,M]=t("");t(void 0),t(void 0),t(void 0);const[P,T]=t(void 0),E=g(),B=i((o=>{for(const e of o)F.getFileInfo(e).then((o=>{k((e=>[...e,o]))}))}),[F,k]),L=i((o=>{const e=new FormData;e.append("file",o),F.uploadFile(o.name,e).then((o=>{B([o])})).catch((()=>{E.notify(h("Error"),h("Error uploading pasted image"),"")}))}),[F,B,E,h]),R=o=>{b(o)};n((()=>{const o=C.get("text"),e=C.get("url");o&&(M(o),C.delete("text")),e&&(C.delete("url"),M(((o||"")+" "+e).trim())),y(C,{replace:!0})}),[C,y,M,F,B]);return o(c,{hideHeader:!0,children:e("div",{className:f.container,style:{backgroundImage:`url(${m("COMPOSE_BACKGROUND_IMAGE_URL")})`},children:[o(a,{title:m("APP_SAVE_TITLE")?h(m("APP_SAVE_TITLE")):h("Spara")}),o(p,{defaultText:A,onSend:o=>{o=`${o="#crm\n"+o.replace("#log ","")}${I?" "+I:""}${U.length>0?"\n":""}${U.map((o=>`#file:${o.id}`)).join(" ")}`,F.sendMessage(o).then((()=>{E.notify(h("Meddelande"),h("Meddelandet är sparat."),"")}))},files:U,onFilesChange:k,isUploading:x,onUploadImage:()=>{w.current?.triggerUpload()},onUploadCamera:()=>{_.current?.triggerUpload()},getImageUrl:s.getImageUrl,hasLocation:!!I,disableSend:!0,rows:9,placeholder:h("Beskriv CRM-aktivitet här..."),onChange:o=>{T(o)},onImagePasted:L}),o(l,{ref:S,onFileUploaded:B,onUploading:R,multiple:!0,codicentService:F}),o(l,{codicentService:F,ref:w,onFileUploaded:B,onUploading:R,multiple:!0,accept:"image/*"}),o(l,{codicentService:F,ref:_,onFileUploaded:B,onUploading:R,multiple:!0,accept:"image/*",capture:"environment"})]})})};export{x as CrmPage,x as default};
|
2
2
|
//# sourceMappingURL=CrmPage.js.map
|
@@ -27,6 +27,7 @@ export interface CodicentServiceOptions {
|
|
27
27
|
STRIPE_PUBLIC_KEY: string;
|
28
28
|
SUBSCRIPTION_NEEDED: boolean;
|
29
29
|
USER_PREFIX: string;
|
30
|
+
ANONYMOUS_TOKEN?: string;
|
30
31
|
}
|
31
32
|
export declare class CodicentService {
|
32
33
|
codicent: string;
|
@@ -57,6 +58,7 @@ export declare class CodicentService {
|
|
57
58
|
logout: () => void;
|
58
59
|
isRegistered: () => boolean;
|
59
60
|
getApps: () => Promise<AppInfo[] | null>;
|
61
|
+
addFollower: (nickname: string, followerNickname: string) => Promise<boolean>;
|
60
62
|
cloneProject: (project: string, newProject: string) => Promise<boolean>;
|
61
63
|
getNickname: () => Promise<string>;
|
62
64
|
getChatInstructions: () => Promise<string>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codicent.d.ts","sourceRoot":"","sources":["../../../src/services/codicent.ts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BAAU,MAAM;eAAS,MAAM;SAC7D;IAEF,WAAW,OAAc,MAAM,kBAO7B;CACH"}
|
@@ -1,2 +1,2 @@
|
|
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/",i="-";const a=()=>void 0!==window.Codicent&&(window.Codicent.init({token:i,baseUrl:n}),!0);let s=a();if(!s){const t=setInterval((()=>{s=a(),s&&clearInterval(t)}),100)}class r{constructor(o){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],i=o.slice(1).join("\n");return{id:t.id,title:n,content:i}})),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,i=void 0)=>{const a=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(!a.ok)throw a.status,new Error(`${a.statusText}`);let s=await a.json();if(s.forEach((t=>{t.createdAt=new Date(Date.parse(t.createdAt))})),i){const t=await this.getPublicFlow(i);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,i)=>{const a=await fetch(`${n}app/RegisterAuth0User`,{method:"POST",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${i}`]],body:JSON.stringify({nickname:t,email:e,userId:o})});if(!a.ok)return"";const s=await a.text();return window.Codicent.init({token:i,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||401===o.status?null:"";const i=await o.text();return this.setToken(i),i}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.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 i=await o.json();if(i){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"})||(i=!1)}catch{i=!1}if(i){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"})||(i=!1)}catch{i=!1}}}return i},this.getNickname=async()=>{try{const t=i.split(".")[1],e=atob(t),o=JSON.parse(e),a=o.sub||o.userId,s=await fetch(`${n}app/GetNickname?userId=${a}`,{method:"GET",headers:[["Content-Type","application/json; charset=utf-8"],["Authorization",`Bearer ${this.getToken()}`]]});if(!s.ok)throw 401===s.status?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?new Error("Unauthorized"):new Error(`${o.statusText}`);const i=await o.json(),{email:a,picture:s,description:r,followers:c,properties:h}=i;return{nickname:t,email:a,name:r,picture:s,followers:c,properties:h}},this.updateUserInfo=async({nickname:t,email:e,name:o,picture:i})=>{const a=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:i,description:""})});if(!a.ok)throw a.status,new Error(`${a.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=>{i=t,i&&window.Codicent.init({token:i,baseUrl:n})},this.getToken=()=>i,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:i}=await o.redirectToCheckout({sessionId:n});if(i)throw new Error(i.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"},i=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(!i.ok)throw new Error(`${i.statusText||"Failed to post log message!"}`);return(await i.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)){return await this.cloneProject(this.options.APP_TEMPLATE,e)?e:null}}}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}}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 i=await fetch(`${n}app/GetAi2ChatReply?message=${t}&project=${e}${o?"&messageId="+o:""}`,{method:"GET",headers:[["Authorization","Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjJlMTliNjNmLWQxNDgtNGRmMi04MzMxLTZlZGE3ZTQzNjQ1ZCIsIm5pY2tuYW1lIjoiam9oYW4iLCJuYW1lIjoiSm9oYW4gSXNha3Nzb24iLCJ1c2VySWQiOiIyZTE5YjYzZi1kMTQ4LTRkZjItODMzMS02ZWRhN2U0MzY0NWQiLCJwcm9qZWN0IjoiY29kaWNlbnQtbWluaSIsIm5iZiI6MTczNjkzMjcyOCwiZXhwIjoxNzY4NDY4NzI4LCJpYXQiOjE3MzY5MzI3Mjh9.l2J7GgfU01iihdud7QP1aYBCM3NgxxqiM4VrplLO1s0"]]});if(!i.ok)return void i.status;return(await i.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.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.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 i.status,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||401===o.status?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?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?new Error("Unauthorized"):new Error(`${o.statusText}`);const a=await o.json(),{email:i,picture:s,description:r,followers:c,properties:h}=a;return{nickname:t,email:i,name:r,picture:s,followers:c,properties:h}},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 null}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}}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};
|
2
2
|
//# sourceMappingURL=codicent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codicent.js","sources":["../../../../src/services/codicent.ts"],"sourcesContent":[null],"names":["_a","baseUrl","token","initializeCodicent","window","Codicent","init","initialized","setInterval","clearInterval","initInterval","CodicentService","constructor","options","this","getAppTheme","datas","getDataMessages","tags","codicent","length","data","error","console","async","appButtons","BUTTON_TAG","map","d","sort","a","b","title","getAppTasks","getMessages","search","m","rows","MessageContent","content","split","prompt","slice","join","id","getAppPrompts","uploadFile","filename","formData","upload","getFileInfo","fileId","sendMessage","message","parentId","postMessage","type","chat","messageId","getChatReply3","getMessagesFast","publicCodicent","undefined","response","fetch","method","headers","getToken","body","JSON","
|
1
|
+
{"version":3,"file":"codicent.js","sources":["../../../../src/services/codicent.ts"],"sourcesContent":[null],"names":["_a","baseUrl","token","initializeCodicent","window","Codicent","init","initialized","setInterval","clearInterval","initInterval","CodicentService","constructor","options","this","getAppTheme","datas","getDataMessages","tags","codicent","length","data","error","console","getAppButtons","async","appButtons","BUTTON_TAG","map","d","sort","a","b","title","getAppTasks","getMessages","search","m","rows","MessageContent","content","split","prompt","slice","join","id","getAppPrompts","uploadFile","filename","formData","upload","getFileInfo","fileId","sendMessage","message","parentId","postMessage","type","chat","messageId","getChatReply3","getMessagesFast","publicCodicent","undefined","response","fetch","method","headers","getToken","body","JSON","stringify","status","messages","json","forEach","createdAt","Date","parse","concat","publicMessages","getTime"],"mappings":"ycA4BA,IAAAA,MAGEC,0BACAC,EAAO,IACP,MAAAC,EAAW,SAAuB,IAARC,OAAAC,WAAaD,OAAAC,SAAAC,KAAA,CACvCJ,QAAkBD,aAA4B,OAM9CM,EAAaJ,IACd,IAAAI,EAAA,CAED,QAAuCC,aAAA,KACzBD,MACIA,GACHE,cAASC,EACd,GACE,KAEA,MAAAC,EACV,WAAAC,CAAiBC,GACEC,KAAAC,sBACR,IACI,MAAGC,QAAOZ,OAAAC,SAAAY,gBAAA,CAAAC,KAAA,CAAA,aAAAC,SAAAL,KAAAK,WAG3B,OAFCH,EAAAI,OAAA,EAAAJ,EAAA,GAAAK,KAAA,IAGgB,CACP,MAAOC,GAgBb,OAdUC,cAA+B,4BAAAD,GAczC,IAEF,QAkB8BE,cAAAC,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rD,KAAAsD,cAEM,CAAA,eAKN,oCAIFC,KAAAC,KAAgCC,UAAA,CAAQrD,OAAAC,SAetCL,KAAAK,SAAAiB,SAAAhB,aA0BF,IAAA4C,WAkBkBA,EAAAQ,oCA6DhB,IAAAC,QAAAT,EAAAU,OAmFK,GAjFPD,EAA4BE,SAAAtC,IA8D1BA,EAAAuC,UAAA,IAAAC,KAAAA,KAAAC,MAAAzC,EAAAuC,WAAA,IAmBKd,EAA4B,eA2BahD,mBAAiBgD,GA4BzDW,EAAAA,EAAAM,OAAAC,GAMwBP,EAAA3C,MAAA,CAAAC,EAAAC,IAAAA,EAAA4C,UAAAK,UAAAlD,EAAA6C,UAAAK,mBAA+BR,CAAA,EAGpD3D,KAAAqB,kBAOTjB,EAAAC,KACH,IAAAsD,EAAA"}
|
package/dist/index.d.ts
CHANGED
@@ -36,6 +36,7 @@ interface CodicentServiceOptions {
|
|
36
36
|
STRIPE_PUBLIC_KEY: string;
|
37
37
|
SUBSCRIPTION_NEEDED: boolean;
|
38
38
|
USER_PREFIX: string;
|
39
|
+
ANONYMOUS_TOKEN?: string;
|
39
40
|
}
|
40
41
|
declare class CodicentService {
|
41
42
|
codicent: string;
|
@@ -66,6 +67,7 @@ declare class CodicentService {
|
|
66
67
|
logout: () => void;
|
67
68
|
isRegistered: () => boolean;
|
68
69
|
getApps: () => Promise<AppInfo[] | null>;
|
70
|
+
addFollower: (nickname: string, followerNickname: string) => Promise<boolean>;
|
69
71
|
cloneProject: (project: string, newProject: string) => Promise<boolean>;
|
70
72
|
getNickname: () => Promise<string>;
|
71
73
|
getChatInstructions: () => Promise<string>;
|