codicent-app-sdk 0.3.37 → 0.3.39
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/README.md +53 -0
- package/dist/cjs/components/FileThumbnail.js +1 -1
- package/dist/cjs/components/MessageInput.d.ts.map +1 -1
- package/dist/cjs/components/MessageInput.js +1 -1
- package/dist/cjs/components/MessageInput.js.map +1 -1
- package/dist/cjs/components/Textarea.d.ts +1 -0
- package/dist/cjs/components/Textarea.d.ts.map +1 -1
- package/dist/cjs/components/Textarea.js.map +1 -1
- package/dist/cjs/hooks/useTemplateVariables.js +1 -1
- package/dist/cjs/hooks/useTemplateVariables.js.map +1 -1
- package/dist/cjs/services/codicent.js +1 -1
- package/dist/esm/components/FileThumbnail.js +1 -1
- package/dist/esm/components/MessageInput.d.ts.map +1 -1
- package/dist/esm/components/MessageInput.js +1 -1
- package/dist/esm/components/MessageInput.js.map +1 -1
- package/dist/esm/components/Textarea.d.ts +1 -0
- package/dist/esm/components/Textarea.d.ts.map +1 -1
- package/dist/esm/components/Textarea.js.map +1 -1
- package/dist/esm/hooks/useTemplateVariables.js +1 -1
- package/dist/esm/hooks/useTemplateVariables.js.map +1 -1
- package/dist/esm/services/codicent.js +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -209,3 +209,56 @@ For full documentation, visit [our docs site](https://izaxon.github.io/codicent-
|
|
|
209
209
|
## License
|
|
210
210
|
|
|
211
211
|
MIT © Codicent Inside AB
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Fast Local SDK Testing Workflow
|
|
216
|
+
|
|
217
|
+
To quickly test changes in your local SDK with your app project, you can use npm link or a local file dependency. This avoids publishing to npm for every change.
|
|
218
|
+
|
|
219
|
+
### Option 1: Using `npm link`
|
|
220
|
+
|
|
221
|
+
1. **Build your SDK in watch mode (if needed):**
|
|
222
|
+
- If your SDK uses TypeScript or a bundler (like rollup), run it in watch mode so changes are rebuilt automatically.
|
|
223
|
+
```cmd
|
|
224
|
+
npm run build -- --watch
|
|
225
|
+
```
|
|
226
|
+
Or for TypeScript:
|
|
227
|
+
```cmd
|
|
228
|
+
npx tsc --watch
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
2. **Link your SDK globally:**
|
|
232
|
+
In your SDK root folder:
|
|
233
|
+
```cmd
|
|
234
|
+
npm link
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
3. **Link your SDK in your app project:**
|
|
238
|
+
In your app project folder (the one that uses the SDK):
|
|
239
|
+
```cmd
|
|
240
|
+
npm link codicent-app-sdk
|
|
241
|
+
```
|
|
242
|
+
(Replace `codicent-app-sdk` with the actual name in your SDK’s `package.json` if different.)
|
|
243
|
+
|
|
244
|
+
4. **Test changes instantly:**
|
|
245
|
+
Now, when you make changes to your SDK and rebuild, your app will use the updated local version immediately—no need to publish or reinstall from npm.
|
|
246
|
+
|
|
247
|
+
5. **Unlink when done:**
|
|
248
|
+
When you want to go back to using the npm-published version, run in your app project:
|
|
249
|
+
```cmd
|
|
250
|
+
npm uninstall codicent-app-sdk
|
|
251
|
+
npm install codicent-app-sdk
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Option 2: Using a Local File Dependency
|
|
255
|
+
|
|
256
|
+
1. In your app’s `package.json`, set the dependency to point to your local SDK folder:
|
|
257
|
+
```json
|
|
258
|
+
"dependencies": {
|
|
259
|
+
"codicent-app-sdk": "file:../codicent-app-sdk"
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
2. Run `npm install` in your app project.
|
|
263
|
+
|
|
264
|
+
---
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),o=require("../node_modules/@griffel/react/makeStyles.esm.js"),t=require("../node_modules/@fluentui/react-button/lib/components/Button/Button.js"),i=require("../node_modules/@fluentui/react-image/lib/components/Image/Image.js"),r=require("../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js"),n=require("../node_modules/@fluentui/tokens/lib/tokens.js"),l=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js");const s=o.makeStyles({thumbnail:{width:"64px",height:"64px",borderRadius:n.tokens.borderRadiusMedium,backgroundColor:n.tokens.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:n.tokens.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:n.tokens.colorNeutralForegroundInverted,padding:"4px",fontSize:n.tokens.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:n.tokens.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:n.tokens.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:n.tokens.colorNeutralBackground1Hover}}});exports.FileThumbnail=({file:o,getImageUrl:n,onClick:a,onDelete:u,thumbnailSize:c})=>{const d=s();return e.jsxs("div",{className:d.thumbnail,onClick:a,title:o.filename,children:[u&&e.jsx(t.Button,{className:d.deleteButton,icon:e.jsx(l.DismissRegular,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),o.contentType.startsWith("image")?e.jsx(i.Image,{className:d.image,src:`${n(o.id,c||200)}&width=${c}`,alt:o.filename}):e.jsx(r.DocumentData32Regular,{className:d.fileIcon}),e.jsx("div",{className:d.fileName,children:o.filename})]})};
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),o=require("../node_modules/@griffel/react/makeStyles.esm.js"),t=require("../node_modules/@fluentui/react-button/lib/components/Button/Button.js"),i=require("../node_modules/@fluentui/react-image/lib/components/Image/Image.js"),r=require("../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js"),n=require("../node_modules/@fluentui/tokens/lib/tokens.js"),l=require("../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js");const s=o.makeStyles({thumbnail:{width:"64px",height:"64px",borderRadius:n.tokens.borderRadiusMedium,backgroundColor:n.tokens.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:n.tokens.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:n.tokens.colorNeutralForegroundInverted,padding:"4px",fontSize:n.tokens.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:n.tokens.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:n.tokens.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:n.tokens.colorNeutralBackground1Hover}}});exports.FileThumbnail=({file:o,getImageUrl:n,onClick:a,onDelete:u,thumbnailSize:c})=>{const d=s();return e.jsxs("div",{className:d.thumbnail,onClick:a,title:o.filename,children:[u&&e.jsx(t.Button,{className:d.deleteButton,icon:e.jsx(l.DismissRegular,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),o.contentType&&o.contentType.startsWith("image")?e.jsx(i.Image,{className:d.image,src:`${n(o.id,c||200)}&width=${c}`,alt:o.filename}):e.jsx(r.DocumentData32Regular,{className:d.fileIcon}),e.jsx("div",{className:d.fileName,children:o.filename})]})};
|
|
2
2
|
//# sourceMappingURL=FileThumbnail.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/MessageInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAQlE,UAAU,iBAAiB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACvD,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACpD;AA+DD,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/MessageInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAQlE,UAAU,iBAAiB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACvD,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACpD;AA+DD,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA0M7C,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react");require("../services/codicent.js"),require("./Markdown.js");var a=require("./Textarea.js"),t=require("./Button.js"),i=require("./Spinner.js");require("./TextHeader.js"),require("./TypingIndicator.js"),require("./Dialog.js"),require("./ChatInput.js"),require("./CombinedPlaceholderDialog.js"),require("./ChatMessage.js"),require("./Header.js");var s=require("../utils/MessageContent.js");require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/index.js");var o=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");var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react");require("../services/codicent.js"),require("./Markdown.js");var a=require("./Textarea.js"),t=require("./Button.js"),i=require("./Spinner.js");require("./TextHeader.js"),require("./TypingIndicator.js"),require("./Dialog.js"),require("./ChatInput.js"),require("./CombinedPlaceholderDialog.js"),require("./ChatMessage.js"),require("./Header.js");var s=require("../utils/MessageContent.js");require("../node_modules/tinycolor2/esm/tinycolor.js"),require("../_virtual/index.js");var o=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");var n=require("./FileThumbnail.js");require("./UploadFile.js"),require("./SnapFooter.js"),require("./Profile.js"),require("./MessageItem.js"),require("./Content.js"),require("./AiInput.js"),require("./SearchBox.js"),require("./HtmlView.js"),require("./Footer.js"),require("./Page.js"),require("../pages/AppFrame.js"),require("../pages/Snap.js"),require("../pages/Search.js"),require("../pages/Login.js"),require("../pages/CrmPage.js"),require("../pages/ImageView.js"),require("../pages/FormInvite.js"),require("../pages/FormAccept.js"),require("../pages/Sales.js"),require("../stores/chatStore.js");var l=require("../hooks/useLocalization.js");require("../hooks/useAppStyles.js");var u=require("../hooks/useToaster.js"),c=require("../node_modules/@griffel/react/makeStyles.esm.js"),p=require("../node_modules/@fluentui/tokens/lib/tokens.js");const d=c.makeStyles({container:{display:"flex",padding:"8px",width:"100%",position:"relative"},textareaWrapper:{position:"relative",flexGrow:1,display:"flex",flexDirection:"column",maxWidth:"100%"},textarea:{width:"100%",paddingBottom:"40px"},actionButtonRow:{position:"absolute",left:"8px",bottom:"8px",right:"8px",zIndex:1,display:"flex",justifyContent:"space-between"},leftButtonGroup:{display:"flex",gap:"4px"},actionButton:{color:p.tokens.colorNeutralForeground2,"&:hover":{color:p.tokens.colorBrandBackground,backgroundColor:"transparent"}},fileList:{display:"flex",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"thin",msOverflowStyle:"none",padding:"4px",margin:"0 -4px",maxWidth:"100%",boxSizing:"border-box","&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:p.tokens.colorNeutralStroke1,borderRadius:"3px"}}});exports.default=({defaultText:c,onSend:p,onLocationChange:g,hasLocation:f,files:j=[],onFilesChange:m,onUploadFile:x,onUploadImage:q,onUploadCamera:h,getImageUrl:v,isUploading:b,rows:k,size:y,disableSend:S,placeholder:w,onChange:C,onImagePasted:B,onHandleDefaultFiles:T})=>{const[_,D]=r.useState(""),[F,N]=r.useState([]),I=d(),z=u.default(),{t:A}=l.default();r.useEffect((()=>{C?.(_)}),[_,C]),r.useEffect((()=>{const e=new s.default(c||"");D(e.content||""),N(e.tags||[]),e.files.length>0&&T?.(e.files)}),[c]);const E=async()=>{if(""===_.trim()&&0===j.length)return void z.notify(A("Meddelandet får inte vara tomt"),"","","error");const e=F.length>0?`#${F.join(" #")} `:"#log ";p(e+_),D("");const r=new s.default(c||"");N(r.tags||[]),m?.([])};return e.jsx("div",{className:I.container,onDrop:async e=>{if(e.preventDefault(),!m)return;const r=Array.from(e.dataTransfer.files);if(r.length>0)if(B&&r.every((e=>e.type&&e.type.startsWith("image/"))))for(const e of r)B(e);else m(r)},onDragOver:e=>{e.preventDefault()},children:e.jsxs("div",{className:I.textareaWrapper,children:[v&&j.length>0&&e.jsxs("div",{className:I.fileList,children:[j.map((r=>e.jsx(n.FileThumbnail,{file:r,getImageUrl:v,onDelete:()=>{return e=r.id,void m?.(j.filter((r=>r.id!==e)));var e}},r.id))),b&&e.jsx(i.Spinner,{})]}),e.jsx(a.Textarea,{size:"large",resize:"vertical",rows:k||7,value:_,onChange:e=>D(e.target.value),placeholder:w||A("Skriv vad du vill spara här..."),onKeyDown:e=>{!0!==S?"Enter"!==e.key||e.shiftKey||(e.preventDefault(),E()):"Enter"===e.key&&e.ctrlKey&&(e.preventDefault(),E())},onPaste:e=>{if(!m&&!B)return;const r=e.clipboardData.items;for(const a of r)if("file"===a.kind){const r=a.getAsFile();r&&(B&&r.type.startsWith("image/")?(e.preventDefault(),B(r)):m&&(e.preventDefault(),m([r])))}},className:I.textarea}),e.jsxs("div",{className:I.actionButtonRow,children:[e.jsxs("div",{className:I.leftButtonGroup,children:[x&&e.jsx(t.Button,{appearance:"transparent",icon:q?"AttachRegular":"AddRegular",size:"small",title:A("Lägg till fil"),onClick:x,className:I.actionButton}),q&&e.jsx(t.Button,{appearance:"transparent",icon:"ImageRegular",size:"small",title:A("Lägg till bild"),onClick:q,className:I.actionButton}),h&&e.jsx(t.Button,{appearance:"transparent",icon:"CameraRegular",size:"small",title:A("Ta kort"),onClick:h,className:I.actionButton}),g&&e.jsx(t.Button,{appearance:"transparent",icon:f?"LocationFilled":"LocationRegular",size:"small",title:A("Spara plats"),onClick:()=>g(!f),className:I.actionButton})]}),e.jsx(t.Button,{appearance:o.getConfigValue("SHOW_SAVE_BUTTON_TEXT")?"primary":"subtle",onClick:E,icon:"SendFilled",iconPosition:"before",title:A("Spara"),size:y||(o.getConfigValue("SHOW_SAVE_BUTTON_TEXT")?"small":"large"),children:o.getConfigValue("SHOW_SAVE_BUTTON_TEXT")&&e.jsx("span",{children:A("Spara")})})]})]})})};
|
|
2
2
|
//# sourceMappingURL=MessageInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInput.js","sources":["../../../../src/components/MessageInput.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","container","display","padding","width"],"mappings":"kpDAqCeA,EAACC,EAAAA,WAAa,CAC3BC,UAAoB,CACrBC,QAAA,OA+DDC,
|
|
1
|
+
{"version":3,"file":"MessageInput.js","sources":["../../../../src/components/MessageInput.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","container","display","padding","width"],"mappings":"kpDAqCeA,EAACC,EAAAA,WAAa,CAC3BC,UAAoB,CACrBC,QAAA,OA+DDC,cA4MAC,MAAe"}
|
|
@@ -10,6 +10,7 @@ export interface TextareaProps {
|
|
|
10
10
|
rows?: number;
|
|
11
11
|
className?: string;
|
|
12
12
|
onFocus?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
|
|
13
|
+
onPaste?: (event: React.ClipboardEvent<HTMLTextAreaElement>) => void;
|
|
13
14
|
}
|
|
14
15
|
export declare const Textarea: React.FC<TextareaProps>;
|
|
15
16
|
//# sourceMappingURL=Textarea.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;CACtE;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAkB5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","textarea","width","minHeight","paddingBottom","value","onChange","size","props","classes","event","data"],"mappings":"+RAWOA,EAASC,EAAAA,WAAC,CACfC,SAAW,CACPC,MAAG,OACIC,UAAG,OACdC,cAAoB,2BAGN,EAAAC,QAAAC,WAAAC,UAAAC,MACd,MAASC,EAAGV,kGACM,CAAAW,EAAMC,
|
|
1
|
+
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","textarea","width","minHeight","paddingBottom","value","onChange","size","props","classes","event","data","syntheticEvent"],"mappings":"+RAWOA,EAASC,EAAAA,WAAC,CACfC,SAAW,CACPC,MAAG,OACIC,UAAG,OACdC,cAAoB,2BAGN,EAAAC,QAAAC,WAAAC,UAAAC,MACd,MAASC,EAAGV,kGACM,CAAAW,EAAMC,KACxB,GAAQL,EAAU,CAGb,MAAAM,EAAgB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";exports.useTemplateVariables=e=>({extractTemplateVariables:e=>Array.from(e.matchAll(/{{([^}]+)}}/gs)).map((e=>({name:e[1].trim(),value:""}))),replaceTemplateVariables:(e,a)=>{let l=e;return a.forEach((e=>{const a=e.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`{{${a}}}`,"g"),t=e.value.replace(/\n/g,"\n");l=l.replace(r,t)})),l},extractFilePlaceholders:e=>Array.from(e.matchAll(/\[\[(.*?)\]\]/g)).map((e=>({placeholder:e[0],description:e[1].trim()||"file"}))),replaceFilePlaceholders:(e,a)=>{let l=e;return a.forEach((({placeholder:e,fileId:a})=>{l=l.replace(e,a
|
|
1
|
+
"use strict";exports.useTemplateVariables=e=>({extractTemplateVariables:e=>Array.from(e.matchAll(/{{([^}]+)}}/gs)).map((e=>({name:e[1].trim(),value:""}))),replaceTemplateVariables:(e,a)=>{let l=e;return a.forEach((e=>{const a=e.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`{{${a}}}`,"g"),t=e.value.replace(/\n/g,"\n");l=l.replace(r,t)})),l},extractFilePlaceholders:e=>Array.from(e.matchAll(/\[\[(.*?)\]\]/g)).map((e=>({placeholder:e[0],description:e[1].trim()||"file"}))),replaceFilePlaceholders:(e,a)=>{let l=e;return a.forEach((({placeholder:e,fileId:a})=>{l=l.replace(e,a?`%23file:${a}`:"")})),l},handleSelectFiles:async a=>await Promise.all(Array.from(a).map((a=>{const l=new FormData;return l.append("file",a),e(a.name,l)})))});
|
|
2
2
|
//# sourceMappingURL=useTemplateVariables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTemplateVariables.js","sources":["../../../../src/hooks/useTemplateVariables.ts"],"sourcesContent":[null],"names":["uploadFile","async","files","Promise","all","Array","from","map","file","fileForm","FormData","append","name"],"mappings":"0CAAiCA,
|
|
1
|
+
{"version":3,"file":"useTemplateVariables.js","sources":["../../../../src/hooks/useTemplateVariables.ts"],"sourcesContent":[null],"names":["uploadFile","async","files","Promise","all","Array","from","map","file","fileForm","FormData","append","name"],"mappings":"0CAAiCA,4kBAClBC,MAAAC,SACCC,QAAAC,IAAAC,MAAAC,KAAAJ,GAAAK,KAAAC,IACf,MAAAC,EAAA,IAAAC,SAGY,SADmBC,OAAA,OAAAH,KACVA,EAAAI,KAAAH,EAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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;
|
|
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,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as e,jsx as o}from"react/jsx-runtime";import{makeStyles as t}from"../node_modules/@griffel/react/makeStyles.esm.js";import{Button as i}from"../node_modules/@fluentui/react-button/lib/components/Button/Button.js";import{Image as r}from"../node_modules/@fluentui/react-image/lib/components/Image/Image.js";import{DocumentData32Regular as n}from"../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js";import{tokens as l}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{DismissRegular as a}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js";const s=t({thumbnail:{width:"64px",height:"64px",borderRadius:l.borderRadiusMedium,backgroundColor:l.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:l.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:l.colorNeutralForegroundInverted,padding:"4px",fontSize:l.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:l.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:l.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:l.colorNeutralBackground1Hover}}}),c=({file:t,getImageUrl:l,onClick:c,onDelete:u,thumbnailSize:d})=>{const m=s();return e("div",{className:m.thumbnail,onClick:c,title:t.filename,children:[u&&o(i,{className:m.deleteButton,icon:o(a,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),t.contentType.startsWith("image")?o(r,{className:m.image,src:`${l(t.id,d||200)}&width=${d}`,alt:t.filename}):o(n,{className:m.fileIcon}),o("div",{className:m.fileName,children:t.filename})]})};export{c as FileThumbnail};
|
|
1
|
+
import{jsxs as e,jsx as o}from"react/jsx-runtime";import{makeStyles as t}from"../node_modules/@griffel/react/makeStyles.esm.js";import{Button as i}from"../node_modules/@fluentui/react-button/lib/components/Button/Button.js";import{Image as r}from"../node_modules/@fluentui/react-image/lib/components/Image/Image.js";import{DocumentData32Regular as n}from"../node_modules/@fluentui/react-icons/lib/sizedIcons/chunk-6.js";import{tokens as l}from"../node_modules/@fluentui/tokens/lib/tokens.js";import{DismissRegular as a}from"../node_modules/@fluentui/react-icons/lib/icons/chunk-1.js";const s=t({thumbnail:{width:"64px",height:"64px",borderRadius:l.borderRadiusMedium,backgroundColor:l.colorNeutralBackground2,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",cursor:"pointer",flexShrink:0,flexGrow:0,margin:"4px","&:hover":{backgroundColor:l.colorNeutralBackground2Hover}},image:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"inherit"},fileName:{position:"absolute",bottom:0,left:0,right:0,backgroundColor:"rgba(0, 0, 0, 0.6)",color:l.colorNeutralForegroundInverted,padding:"4px",fontSize:l.fontSizeBase200,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",borderBottomLeftRadius:"inherit",borderBottomRightRadius:"inherit"},fileIcon:{fontSize:"32px",color:l.colorNeutralForeground2},deleteButton:{position:"absolute",top:"4px",right:"4px",minWidth:"20px",height:"20px",padding:"2px",backgroundColor:l.colorNeutralBackground1,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1,"&:hover":{backgroundColor:l.colorNeutralBackground1Hover}}}),c=({file:t,getImageUrl:l,onClick:c,onDelete:u,thumbnailSize:d})=>{const m=s();return e("div",{className:m.thumbnail,onClick:c,title:t.filename,children:[u&&o(i,{className:m.deleteButton,icon:o(a,{}),appearance:"subtle",size:"small",onClick:e=>{e.stopPropagation(),u?.()},title:"Ta bort"}),t.contentType&&t.contentType.startsWith("image")?o(r,{className:m.image,src:`${l(t.id,d||200)}&width=${d}`,alt:t.filename}):o(n,{className:m.fileIcon}),o("div",{className:m.fileName,children:t.filename})]})};export{c as FileThumbnail};
|
|
2
2
|
//# sourceMappingURL=FileThumbnail.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/MessageInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAQlE,UAAU,iBAAiB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACvD,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACpD;AA+DD,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/MessageInput.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAQlE,UAAU,iBAAiB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACvD,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACrC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACpD;AA+DD,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA0M7C,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useState as o,useEffect as a}from"react";import"../services/codicent.js";import"./Markdown.js";import{Textarea as r}from"./Textarea.js";import{Button as i}from"./Button.js";import{Spinner as s}from"./Spinner.js";import"./TextHeader.js";import"./TypingIndicator.js";import"./Dialog.js";import"./ChatInput.js";import"./CombinedPlaceholderDialog.js";import"./ChatMessage.js";import"./Header.js";import l from"../utils/MessageContent.js";import"../node_modules/tinycolor2/esm/tinycolor.js";import"../_virtual/index.js";import{getConfigValue as n}from"../config/index.js";import"../lib/wavtools/lib/wav_packer.js";import"../lib/wavtools/lib/analysis/audio_analysis.js";import"../lib/wavtools/lib/wav_stream_player.js";import"../lib/wavtools/lib/wav_recorder.js";import{FileThumbnail as p}from"./FileThumbnail.js";import"./UploadFile.js";import"./SnapFooter.js";import"./Profile.js";import"./MessageItem.js";import"./Content.js";import"./AiInput.js";import"./SearchBox.js";import"./HtmlView.js";import"./Footer.js";import"./Page.js";import"../pages/AppFrame.js";import"../pages/Snap.js";import"../pages/Search.js";import"../pages/Login.js";import"../pages/CrmPage.js";import"../pages/ImageView.js";import"../pages/FormInvite.js";import"../pages/FormAccept.js";import"../pages/Sales.js";import"../stores/chatStore.js";import m from"../hooks/useLocalization.js";import"../hooks/useAppStyles.js";import c from"../hooks/useToaster.js";import{makeStyles as d}from"../node_modules/@griffel/react/makeStyles.esm.js";import{tokens as g}from"../node_modules/@fluentui/tokens/lib/tokens.js";const f=d({container:{display:"flex",padding:"8px",width:"100%",position:"relative"},textareaWrapper:{position:"relative",flexGrow:1,display:"flex",flexDirection:"column",maxWidth:"100%"},textarea:{width:"100%",paddingBottom:"40px"},actionButtonRow:{position:"absolute",left:"8px",bottom:"8px",right:"8px",zIndex:1,display:"flex",justifyContent:"space-between"},leftButtonGroup:{display:"flex",gap:"4px"},actionButton:{color:g.colorNeutralForeground2,"&:hover":{color:g.colorBrandBackground,backgroundColor:"transparent"}},fileList:{display:"flex",overflowX:"auto",overflowY:"hidden",scrollbarWidth:"thin",msOverflowStyle:"none",padding:"4px",margin:"0 -4px",maxWidth:"100%",boxSizing:"border-box","&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:g.colorNeutralStroke1,borderRadius:"3px"}}}),u=({defaultText:d,onSend:g,onLocationChange:u,hasLocation:j,files:h=[],onFilesChange:v,onUploadFile:b,onUploadImage:x,onUploadCamera:y,getImageUrl:k,isUploading:w,rows:S,size:C,disableSend:T,placeholder:_,onChange:B,onImagePasted:D,onHandleDefaultFiles:N})=>{const[F,I]=o(""),[z,A]=o([]),L=f(),U=c(),{t:W}=m();a((()=>{B?.(F)}),[F,B]),a((()=>{const e=new l(d||"");I(e.content||""),A(e.tags||[]),e.files.length>0&&N?.(e.files)}),[d]);const E=async()=>{if(""===F.trim()&&0===h.length)return void U.notify(W("Meddelandet får inte vara tomt"),"","","error");const e=z.length>0?`#${z.join(" #")} `:"#log ";g(e+F),I("");const t=new l(d||"");A(t.tags||[]),v?.([])};return e("div",{className:L.container,onDrop:async e=>{if(e.preventDefault(),!v)return;const t=Array.from(e.dataTransfer.files);if(t.length>0)if(D&&t.every((e=>e.type&&e.type.startsWith("image/"))))for(const e of t)D(e);else v(t)},onDragOver:e=>{e.preventDefault()},children:t("div",{className:L.textareaWrapper,children:[k&&h.length>0&&t("div",{className:L.fileList,children:[h.map((t=>e(p,{file:t,getImageUrl:k,onDelete:()=>{return e=t.id,void v?.(h.filter((t=>t.id!==e)));var e}},t.id))),w&&e(s,{})]}),e(r,{size:"large",resize:"vertical",rows:S||7,value:F,onChange:e=>I(e.target.value),placeholder:_||W("Skriv vad du vill spara här..."),onKeyDown:e=>{!0!==T?"Enter"!==e.key||e.shiftKey||(e.preventDefault(),E()):"Enter"===e.key&&e.ctrlKey&&(e.preventDefault(),E())},onPaste:e=>{if(!v&&!D)return;const t=e.clipboardData.items;for(const o of t)if("file"===o.kind){const t=o.getAsFile();t&&(D&&t.type.startsWith("image/")?(e.preventDefault(),D(t)):v&&(e.preventDefault(),v([t])))}},className:L.textarea}),t("div",{className:L.actionButtonRow,children:[t("div",{className:L.leftButtonGroup,children:[b&&e(i,{appearance:"transparent",icon:x?"AttachRegular":"AddRegular",size:"small",title:W("Lägg till fil"),onClick:b,className:L.actionButton}),x&&e(i,{appearance:"transparent",icon:"ImageRegular",size:"small",title:W("Lägg till bild"),onClick:x,className:L.actionButton}),y&&e(i,{appearance:"transparent",icon:"CameraRegular",size:"small",title:W("Ta kort"),onClick:y,className:L.actionButton}),u&&e(i,{appearance:"transparent",icon:j?"LocationFilled":"LocationRegular",size:"small",title:W("Spara plats"),onClick:()=>u(!j),className:L.actionButton})]}),e(i,{appearance:n("SHOW_SAVE_BUTTON_TEXT")?"primary":"subtle",onClick:E,icon:"SendFilled",iconPosition:"before",title:W("Spara"),size:C||(n("SHOW_SAVE_BUTTON_TEXT")?"small":"large"),children:n("SHOW_SAVE_BUTTON_TEXT")&&e("span",{children:W("Spara")})})]})]})})};export{u as default};
|
|
2
2
|
//# sourceMappingURL=MessageInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInput.js","sources":["../../../../src/components/MessageInput.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","container","display","padding","width"],"mappings":"smDAqCeA,EAACC,EAAa,CAC3BC,UAAoB,CACrBC,QAAA,OA+DDC,
|
|
1
|
+
{"version":3,"file":"MessageInput.js","sources":["../../../../src/components/MessageInput.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","container","display","padding","width"],"mappings":"smDAqCeA,EAACC,EAAa,CAC3BC,UAAoB,CACrBC,QAAA,OA+DDC,cA4MAC,MAAe"}
|
|
@@ -10,6 +10,7 @@ export interface TextareaProps {
|
|
|
10
10
|
rows?: number;
|
|
11
11
|
className?: string;
|
|
12
12
|
onFocus?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
|
|
13
|
+
onPaste?: (event: React.ClipboardEvent<HTMLTextAreaElement>) => void;
|
|
13
14
|
}
|
|
14
15
|
export declare const Textarea: React.FC<TextareaProps>;
|
|
15
16
|
//# sourceMappingURL=Textarea.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../src/components/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtF,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;CACtE;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAkB5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","textarea","width","minHeight","paddingBottom","Textarea","value","onChange","size","props","classes","event","data"],"mappings":"gUAWOA,EAASC,EAAC,CACfC,SAAW,CACPC,MAAG,OACIC,UAAG,OACdC,cAAoB,UAGbC,EAAO,EAAAC,QAAAC,WAAAC,UAAAC,MACd,MAASC,EAAGX,2EACM,CAAAY,EAAMC,
|
|
1
|
+
{"version":3,"file":"Textarea.js","sources":["../../../../src/components/Textarea.tsx"],"sourcesContent":[null],"names":["useStyles","makeStyles","textarea","width","minHeight","paddingBottom","Textarea","value","onChange","size","props","classes","event","data","syntheticEvent"],"mappings":"gUAWOA,EAASC,EAAC,CACfC,SAAW,CACPC,MAAG,OACIC,UAAG,OACdC,cAAoB,UAGbC,EAAO,EAAAC,QAAAC,WAAAC,UAAAC,MACd,MAASC,EAAGX,2EACM,CAAAY,EAAMC,KACxB,GAAQL,EAAU,CAGb,MAAAM,EAAgB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=e=>({extractTemplateVariables:e=>Array.from(e.matchAll(/{{([^}]+)}}/gs)).map((e=>({name:e[1].trim(),value:""}))),replaceTemplateVariables:(e,a)=>{let l=e;return a.forEach((e=>{const a=e.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`{{${a}}}`,"g"),t=e.value.replace(/\n/g,"\n");l=l.replace(r,t)})),l},extractFilePlaceholders:e=>Array.from(e.matchAll(/\[\[(.*?)\]\]/g)).map((e=>({placeholder:e[0],description:e[1].trim()||"file"}))),replaceFilePlaceholders:(e,a)=>{let l=e;return a.forEach((({placeholder:e,fileId:a})=>{l=l.replace(e,a
|
|
1
|
+
const e=e=>({extractTemplateVariables:e=>Array.from(e.matchAll(/{{([^}]+)}}/gs)).map((e=>({name:e[1].trim(),value:""}))),replaceTemplateVariables:(e,a)=>{let l=e;return a.forEach((e=>{const a=e.name.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`{{${a}}}`,"g"),t=e.value.replace(/\n/g,"\n");l=l.replace(r,t)})),l},extractFilePlaceholders:e=>Array.from(e.matchAll(/\[\[(.*?)\]\]/g)).map((e=>({placeholder:e[0],description:e[1].trim()||"file"}))),replaceFilePlaceholders:(e,a)=>{let l=e;return a.forEach((({placeholder:e,fileId:a})=>{l=l.replace(e,a?`%23file:${a}`:"")})),l},handleSelectFiles:async a=>await Promise.all(Array.from(a).map((a=>{const l=new FormData;return l.append("file",a),e(a.name,l)})))});export{e as useTemplateVariables};
|
|
2
2
|
//# sourceMappingURL=useTemplateVariables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTemplateVariables.js","sources":["../../../../src/hooks/useTemplateVariables.ts"],"sourcesContent":[null],"names":["uploadFile","async","files","Promise","all","Array","from","map","file","fileForm","FormData","append","name"],"mappings":"QAAiCA,
|
|
1
|
+
{"version":3,"file":"useTemplateVariables.js","sources":["../../../../src/hooks/useTemplateVariables.ts"],"sourcesContent":[null],"names":["uploadFile","async","files","Promise","all","Array","from","map","file","fileForm","FormData","append","name"],"mappings":"QAAiCA,4kBAClBC,MAAAC,SACCC,QAAAC,IAAAC,MAAAC,KAAAJ,GAAAK,KAAAC,IACf,MAAAC,EAAA,IAAAC,SAGY,SADmBC,OAAA,OAAAH,KACVA,EAAAI,KAAAH,EAAA"}
|
|
@@ -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/",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};
|
|
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
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,7 @@ interface TextareaProps {
|
|
|
123
123
|
rows?: number;
|
|
124
124
|
className?: string;
|
|
125
125
|
onFocus?: (event: React$1.FocusEvent<HTMLTextAreaElement>) => void;
|
|
126
|
+
onPaste?: (event: React$1.ClipboardEvent<HTMLTextAreaElement>) => void;
|
|
126
127
|
}
|
|
127
128
|
declare const Textarea: React$1.FC<TextareaProps>;
|
|
128
129
|
|