@inkeep/agents-ui 0.17.4 → 0.17.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/primitives/components/embedded-chat/file-upload-input.cjs +1 -1
- package/dist/primitives/components/embedded-chat/file-upload-input.js +179 -160
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/chat-base-events-provider.cjs +1 -1
- package/dist/primitives/providers/chat-base-events-provider.js +1 -1
- package/dist/styled/inkeep.css.cjs +3 -0
- package/dist/styled/inkeep.css.js +3 -0
- package/dist/types/config/ai.d.ts +22 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),r=require("react"),b=require("../../atoms/icons/custom-icon.cjs"),_=require("../../providers/image-preview-provider.cjs"),y=require("../../providers/message-provider.cjs"),m=require("./chat-provider.cjs"),p=require("../../atoms/file-upload.cjs"),g=require("../../utils/misc.cjs"),c=require("../../utils/compose-event-handlers.cjs"),o=require("../factory.cjs"),w=require("../../providers/config-provider.cjs"),E={"application/pdf":"filePdf","text/plain":"fileText","text/markdown":"fileMarkdown","text/html":"fileHtml","text/csv":"fileCsv","text/x-log":"fileLog","application/json":"fileJson","text/x-sql":"fileSql","application/x-sql":"fileSql","text/x-script.python":"filePy","text/x-python":"filePy","text/x-python-script":"filePy"};function C(t){return t.startsWith("image/")}const u={"image/png":[".png"],"image/jpeg":[".jpg",".jpeg"],"image/webp":[".webp"],"application/pdf":[".pdf"],"text/plain":[".txt",".text",".bat",".cfg",".conf",".def",".dic",".in",".list"],"text/x-log":[".log"],"text/markdown":[".md",".markdown"],"text/html":[".html",".htm"],"text/csv":[".csv"],"text/xml":[".xml"],"text/css":[".css"],"application/json":[".json"],"application/yaml":[".yaml",".yml"],"application/x-yaml":[".yaml",".yml"],"text/x-yaml":[".yaml",".yml"],"application/toml":[".toml"],"application/x-toml":[".toml"],"application/graphql":[".graphql",".gql"],"application/x-graphql":[".graphql",".gql"],"text/x-graphql":[".graphql",".gql"],"application/x-ndjson":[".ndjson"],"application/json5":[".json5"],"application/x-json5":[".json5"],"application/javascript":[".js",".mjs"],"text/javascript":[".js",".mjs"],"application/typescript":[".ts"],"text/x-typescript":[".ts"],"text/jsx":[".jsx"],"text/tsx":[".tsx"],"text/x-sh":[".sh"],"text/x-bash":[".bash"],"application/x-bash":[".bash"],"text/x-zsh":[".zsh"],"text/x-shellscript":[".sh",".ksh"],"application/x-powershell":[".ps1"],"text/vbscript":[".vbs"],"text/x-awk":[".awk"],"application/x-awk":[".awk"],"text/x-c":[".c",".h"],"text/x-c++":[".cpp",".cc",".cxx",".hh"],"text/x-csharp":[".cs"],"text/x-objectivec":[".m"],"text/x-objectivec++":[".mm"],"text/x-java":[".java"],"text/x-scala":[".scala"],"application/x-scala":[".scala"],"text/x-kotlin":[".kt"],"text/x-groovy":[".groovy"],"text/x-clojure":[".clj"],"text/x-go":[".go"],"text/x-golang":[".go"],"text/x-rust":[".rs"],"application/x-rust":[".rs"],"text/x-swift":[".swift"],"text/x-dart":[".dart"],"text/x-python":[".py"],"text/x-script.python":[".py"],"text/x-python-script":[".py"],"text/x-ruby":[".rb"],"text/x-perl":[".pl"],"text/x-lua":[".lua"],"text/x-r":[".r"],"text/x-R":[".r"],"text/x-julia":[".jl"],"text/x-elixir":[".ex"],"text/x-erlang":[".erl"],"text/x-haskell":[".hs"],"text/x-lisp":[".lisp"],"text/x-php":[".php"],"application/x-php":[".php"],"application/x-httpd-php":[".php"],"application/x-httpd-php-source":[".php"],"text/x-tex":[".tex"],"text/x-rst":[".rst"],"text/x-handlebars":[".hbs"],"text/x-mustache":[".mustache"],"text/x-ejs":[".ejs"],"text/x-jinja2":[".jinja",".jinja2"],"text/x-liquid":[".liquid"],"text/x-erb":[".erb"],"text/x-twig":[".twig"],"text/x-pug":[".pug"],"text/x-jade":[".jade"],"text/x-tmpl":[".tmpl"],"text/x-astro":[".astro"],"text/x-sass":[".sass"],"text/x-scss":[".scss"],"text/x-less":[".less"],"text/x-sql":[".sql"],"application/x-sql":[".sql"],"text/x-makefile":[".makefile",".mk"],"text/x-cmake":[".cmake"],"text/x-dockerfile":[".dockerfile"],"text/x-gradle":[".gradle"],"text/x-ini":[".ini"],"text/x-properties":[".properties"],"text/x-protobuf":[".proto"],"application/x-protobuf":[".proto"],"text/x-hcl":[".hcl"],"text/x-terraform":[".tf"],"application/x-terraform":[".tf"],"text/x-diff":[".diff"],"text/x-patch":[".patch"],"application/x-patch":[".patch"],"text/x-asm":[".asm",".s"],"message/rfc822":[".eml",".mht",".mhtml",".mime",".nws"],"text/srt":[".srt"],"application/x-subrip":[".srt"],"text/x-subrip":[".srt"],"text/vtt":[".vtt"],"text/x-vcard":[".vcf"],"text/calendar":[".ics",".ifb"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[".docx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":[".pptx"],"application/vnd.oasis.opendocument.text":[".odt"],"application/vnd.oasis.opendocument.spreadsheet":[".ods"],"application/vnd.oasis.opendocument.presentation":[".odp"],"application/vnd.apple.pages":[".pages"],"application/vnd.apple.numbers":[".numbers"],"application/vnd.apple.keynote":[".key"],"application/x-iwork-pages-sffpages":[".pages"],"application/x-iwork-numbers-sffnumbers":[".numbers"],"application/x-iwork-keynote-sffkey":[".key"]},j=new Set(Object.keys(u)),F=10,I=1024*1024*10,N=Object.entries(u).reduce((t,[e,i])=>{for(const n of i)t[n]=e;return t},{});function k(t){if(t.type)return t;const e=`.${t.name.split(".").pop()?.toLowerCase()}`,i=N[e];return i?new File([t],t.name,{type:i}):t}function T(t){if(!t.length)return null;const e=i=>t.some(n=>n.errors.includes(i));return e("TOO_MANY_FILES")?{title:"Attachment limit reached",message:`You can only attach up to ${F} files per message.`}:e("FILE_INVALID_TYPE")?{title:"Unsupported file type",message:"Supported formats include images, PDFs, text, code, and document files."}:e("FILE_TOO_LARGE")?{title:"File too large",message:`Files must be smaller than ${I/1024/1024}MB.`}:e("FILE_EXISTS")?{title:"File already exists",message:`The file "${t.find(n=>n.errors.includes("FILE_EXISTS"))?.file.name??"file"}" is already attached to this message.`}:{title:"File rejected",message:"This file could not be added."}}const M=o.ikp("div",{_id:"aiChatMessage__Files"}),q=({children:t,...e})=>{const{message:i}=y.useMessage();if(i.role!=="user")return null;const n=(i.parts??[]).filter(s=>{if(s.type!=="file")return!1;const l=s.mediaType;return j.has(l??"")});return n.length?a.jsx(M,{...e,children:t(n)}):null},L=o.ikp("button",{_id:"aiChatMessage__File"}),A=({url:t,name:e,mediaType:i,onClick:n,...s})=>{const{openImagePreview:l}=_.useImagePreview(),[d,h]=r.useState(!0),f=r.useMemo(()=>new File([],e??"file",{type:i}),[e,i]);return a.jsx(P.Provider,{value:{file:f,objectUrl:t,isLoading:d,setIsLoading:h,onRemove:()=>{}},children:a.jsx(L,{type:"button","aria-label":C(i??"")?`Preview ${e??"file"}`:`Open ${e??"file"} in new tab`,"data-loading":g.dataAttr(d),onClick:c.composeEventHandlers(n,()=>{if(C(i??""))l({url:t,name:e??"file"});else if(t)if(t.startsWith("data:")){const v=document.createElement("a");v.href=t,v.download=e??"file",v.click()}else window.open(t,"_blank","noopener,noreferrer")}),...s})})},U=o.ikp("div",{_id:"aiChatInput__Fieldset"}),S=t=>{const e=p.useFileUploadApi();return a.jsx(U,{...e.getDropzoneProps({disableClick:!0}),"data-drag-over":g.dataAttr(e.dragging),...t})},R=({...t})=>{const{files:e,setFiles:i,showInputNotification:n}=m.useChat();return a.jsx(p.FileUploadRoot,{accept:u,maxFiles:F,maxFileSize:I,preventDocumentDrop:!0,acceptedFiles:e,onFileAccept:s=>i(s.files),onFileReject:s=>{const l=T(s.files);l&&n(l)},children:a.jsx(S,{...t})})},O=o.ikp("div",{_id:"aiChatInput__DropZone"}),H=o.ikp("div",{_id:"aiChatInput__Notification"}),D=t=>{const{inputNotification:e}=m.useChat();return e?a.jsx(H,{role:"alert",...t}):null},B=o.ikp("p",{_id:"aiChatInput__NotificationTitle"}),X=({children:t,...e})=>{const{inputNotification:i}=m.useChat();return i?.title?a.jsxs(B,{...e,children:[t,i.title]}):null},Y=o.ikp("p",{_id:"aiChatInput__NotificationMessage"}),$=t=>{const{inputNotification:e}=m.useChat();return a.jsx(Y,{...t,children:e?.message})},z=o.ikp("button",{_id:"aiChatInput__NotificationClose"}),Z=({onClick:t,...e})=>{const{clearInputNotification:i}=m.useChat();return a.jsx(z,{type:"button","aria-label":"Dismiss",onClick:c.composeEventHandlers(t,i),...e})},K=o.ikp("div",{_id:"aiChatInput__NotificationContent"}),V=o.ikp("div",{_id:"aiChatInput__NotificationHeader"}),W=o.ikp(b.CustomIcon,{_id:"aiChatInput__FileUploadButtonIcon",iconKey:"fileUpload"}),G=o.ikp("button",{_id:"aiChatInput__FileUploadButton"}),J=t=>{const{aiChatSettings:e}=w.useInkeepConfig(),i=p.useFileUploadApi(),{onClick:n,...s}=t;return a.jsx(G,{type:"button","aria-label":"Upload file",disabled:e.isViewOnly,onClick:c.composeEventHandlers(n,()=>i.openFilePicker()),...s})},Q=o.ikp("input",{_id:"aiChatInput__FileInput"}),tt=t=>{const e=p.useFileUploadApi();return a.jsx(Q,{...t,...e.getHiddenInputProps()})},et=o.ikp("div",{_id:"aiChatInput__FileList"}),it=({children:t,...e})=>{const n=p.useFileUploadApi().acceptedFiles;return n.length?a.jsx(et,{...e,children:t(n)}):null},P=r.createContext(null);function x(){const t=r.useContext(P);if(!t)throw new Error("useFileContext must be used within EmbeddedChatPrimitiveFileItem");return t}const nt=o.ikp("div",{_id:"aiChatInput__FileItem"}),at=({file:t,...e})=>{const i=p.useFileUploadApi(),[n,s]=r.useState(void 0),[l,d]=r.useState(!0);r.useEffect(()=>i.createFileUrl(t,f=>{s(f),d(!0)}),[t]);const h=()=>i.deleteFile(t);return a.jsx(P.Provider,{value:{file:t,objectUrl:n,isLoading:l,setIsLoading:d,onRemove:h},children:a.jsx(nt,{"data-loading":g.dataAttr(l),...e})})},ot=o.ikp("button",{_id:"aiChatInput__FilePreviewTrigger"}),st=({onClick:t,...e})=>{const{objectUrl:i,file:n}=x(),{openImagePreview:s}=_.useImagePreview();return a.jsx(ot,{type:"button","aria-label":`Preview ${n.name}`,disabled:!i,onClick:c.composeEventHandlers(t,()=>{i&&s({url:i,name:n.name})}),...e})},lt=o.ikp("span",{_id:"aiChatInput__FileContent"}),rt=t=>a.jsx(lt,{...t}),pt=o.ikp("img",{_id:"aiChatInput__FileThumbnail"}),ct=({onLoad:t,...e})=>{const{objectUrl:i,file:n,setIsLoading:s}=x();return a.jsx(pt,{src:i,alt:n.name,onLoad:c.composeEventHandlers(t,()=>s(!1)),...e})},dt=({className:t})=>{const{file:e}=x(),i=E[k(e).type]??"file";return a.jsx(b.CustomIcon,{iconKey:i,className:t})},mt=o.ikp("span",{_id:"aiChatInput__FileName"}),xt=t=>{const{file:e}=x();return a.jsx(mt,{...t,children:e.name})},ut=o.ikp("button",{_id:"aiChatInput__FileRemove"}),ht=o.ikp(b.CustomIcon,{_id:"aiChatInput__FileRemoveIcon",iconKey:"close"}),ft=({onClick:t,...e})=>{const{onRemove:i}=x();return a.jsx(ut,{type:"button","aria-label":"Remove file",onClick:c.composeEventHandlers(t,i),...e})};exports.ACCEPTED_FILE_MIME_TYPES=j;exports.EmbeddedChatPrimitiveDropZone=O;exports.EmbeddedChatPrimitiveFileContent=rt;exports.EmbeddedChatPrimitiveFileInput=tt;exports.EmbeddedChatPrimitiveFileItem=at;exports.EmbeddedChatPrimitiveFileList=it;exports.EmbeddedChatPrimitiveFileName=xt;exports.EmbeddedChatPrimitiveFilePreviewTrigger=st;exports.EmbeddedChatPrimitiveFileRemove=ft;exports.EmbeddedChatPrimitiveFileRemoveIcon=ht;exports.EmbeddedChatPrimitiveFileThumbnail=ct;exports.EmbeddedChatPrimitiveFileTypeIcon=dt;exports.EmbeddedChatPrimitiveFileUploadButton=J;exports.EmbeddedChatPrimitiveFileUploadButtonIcon=W;exports.EmbeddedChatPrimitiveInputFieldset=R;exports.EmbeddedChatPrimitiveInputNotification=D;exports.EmbeddedChatPrimitiveInputNotificationClose=Z;exports.EmbeddedChatPrimitiveInputNotificationContent=K;exports.EmbeddedChatPrimitiveInputNotificationHeader=V;exports.EmbeddedChatPrimitiveInputNotificationMessage=$;exports.EmbeddedChatPrimitiveInputNotificationTitle=X;exports.EmbeddedChatPrimitiveMessageFile=A;exports.EmbeddedChatPrimitiveMessageFiles=q;exports.FILE_ACCEPT_MAP=u;exports.FILE_TYPE_ICON_MAP=E;exports.MAX_FILES=F;exports.MAX_FILE_SIZE=I;exports.isImageMimeType=C;exports.normalizeFileType=k;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),p=require("react"),b=require("../../atoms/icons/custom-icon.cjs"),j=require("../../providers/image-preview-provider.cjs"),N=require("../../providers/message-provider.cjs"),u=require("./chat-provider.cjs"),m=require("../../atoms/file-upload.cjs"),F=require("../../utils/misc.cjs"),x=require("../../utils/compose-event-handlers.cjs"),s=require("../factory.cjs"),y=require("../../providers/config-provider.cjs"),k={"application/pdf":"filePdf","text/plain":"fileText","text/markdown":"fileMarkdown","text/html":"fileHtml","text/csv":"fileCsv","text/x-log":"fileLog","application/json":"fileJson","text/x-sql":"fileSql","application/x-sql":"fileSql","text/x-script.python":"filePy","text/x-python":"filePy","text/x-python-script":"filePy"};function C(e){return e.startsWith("image/")}const v={"image/png":[".png"],"image/jpeg":[".jpg",".jpeg"],"image/webp":[".webp"],"application/pdf":[".pdf"],"text/plain":[".txt",".text",".bat",".cfg",".conf",".def",".dic",".in",".list"],"text/x-log":[".log"],"text/markdown":[".md",".markdown"],"text/html":[".html",".htm"],"text/csv":[".csv"],"text/xml":[".xml"],"text/css":[".css"],"application/json":[".json"],"application/yaml":[".yaml",".yml"],"application/x-yaml":[".yaml",".yml"],"text/x-yaml":[".yaml",".yml"],"application/toml":[".toml"],"application/x-toml":[".toml"],"application/graphql":[".graphql",".gql"],"application/x-graphql":[".graphql",".gql"],"text/x-graphql":[".graphql",".gql"],"application/x-ndjson":[".ndjson"],"application/json5":[".json5"],"application/x-json5":[".json5"],"application/javascript":[".js",".mjs"],"text/javascript":[".js",".mjs"],"application/typescript":[".ts"],"text/x-typescript":[".ts"],"text/jsx":[".jsx"],"text/tsx":[".tsx"],"text/x-sh":[".sh"],"text/x-bash":[".bash"],"application/x-bash":[".bash"],"text/x-zsh":[".zsh"],"text/x-shellscript":[".sh",".ksh"],"application/x-powershell":[".ps1"],"text/vbscript":[".vbs"],"text/x-awk":[".awk"],"application/x-awk":[".awk"],"text/x-c":[".c",".h"],"text/x-c++":[".cpp",".cc",".cxx",".hh"],"text/x-csharp":[".cs"],"text/x-objectivec":[".m"],"text/x-objectivec++":[".mm"],"text/x-java":[".java"],"text/x-scala":[".scala"],"application/x-scala":[".scala"],"text/x-kotlin":[".kt"],"text/x-groovy":[".groovy"],"text/x-clojure":[".clj"],"text/x-go":[".go"],"text/x-golang":[".go"],"text/x-rust":[".rs"],"application/x-rust":[".rs"],"text/x-swift":[".swift"],"text/x-dart":[".dart"],"text/x-python":[".py"],"text/x-script.python":[".py"],"text/x-python-script":[".py"],"text/x-ruby":[".rb"],"text/x-perl":[".pl"],"text/x-lua":[".lua"],"text/x-r":[".r"],"text/x-R":[".r"],"text/x-julia":[".jl"],"text/x-elixir":[".ex"],"text/x-erlang":[".erl"],"text/x-haskell":[".hs"],"text/x-lisp":[".lisp"],"text/x-php":[".php"],"application/x-php":[".php"],"application/x-httpd-php":[".php"],"application/x-httpd-php-source":[".php"],"text/x-tex":[".tex"],"text/x-rst":[".rst"],"text/x-handlebars":[".hbs"],"text/x-mustache":[".mustache"],"text/x-ejs":[".ejs"],"text/x-jinja2":[".jinja",".jinja2"],"text/x-liquid":[".liquid"],"text/x-erb":[".erb"],"text/x-twig":[".twig"],"text/x-pug":[".pug"],"text/x-jade":[".jade"],"text/x-tmpl":[".tmpl"],"text/x-astro":[".astro"],"text/x-sass":[".sass"],"text/x-scss":[".scss"],"text/x-less":[".less"],"text/x-sql":[".sql"],"application/x-sql":[".sql"],"text/x-makefile":[".makefile",".mk"],"text/x-cmake":[".cmake"],"text/x-dockerfile":[".dockerfile"],"text/x-gradle":[".gradle"],"text/x-ini":[".ini"],"text/x-properties":[".properties"],"text/x-protobuf":[".proto"],"application/x-protobuf":[".proto"],"text/x-hcl":[".hcl"],"text/x-terraform":[".tf"],"application/x-terraform":[".tf"],"text/x-diff":[".diff"],"text/x-patch":[".patch"],"application/x-patch":[".patch"],"text/x-asm":[".asm",".s"],"message/rfc822":[".eml",".mht",".mhtml",".mime",".nws"],"text/srt":[".srt"],"application/x-subrip":[".srt"],"text/x-subrip":[".srt"],"text/vtt":[".vtt"],"text/x-vcard":[".vcf"],"text/calendar":[".ics",".ifb"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[".docx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":[".pptx"],"application/vnd.oasis.opendocument.text":[".odt"],"application/vnd.oasis.opendocument.spreadsheet":[".ods"],"application/vnd.oasis.opendocument.presentation":[".odp"],"application/vnd.apple.pages":[".pages"],"application/vnd.apple.numbers":[".numbers"],"application/vnd.apple.keynote":[".key"],"application/x-iwork-pages-sffpages":[".pages"],"application/x-iwork-numbers-sffnumbers":[".numbers"],"application/x-iwork-keynote-sffkey":[".key"]},w=new Set(Object.keys(v)),I=10,P=1024*1024*10,T=Object.entries(v).reduce((e,[t,i])=>{for(const n of i)e[n]=t;return e},{});function M(e){if(e.type)return e;const t=`.${e.name.split(".").pop()?.toLowerCase()}`,i=T[t];return i?new File([e],e.name,{type:i}):e}function q(e){if(!e.length)return null;const t=i=>e.some(n=>n.errors.includes(i));return t("TOO_MANY_FILES")?{title:"Attachment limit reached",message:`You can only attach up to ${I} files per message.`}:t("FILE_INVALID_TYPE")?{title:"Unsupported file type",message:"Supported formats include images, PDFs, text, code, and document files."}:t("FILE_TOO_LARGE")?{title:"File too large",message:`Files must be smaller than ${P/1024/1024}MB.`}:t("FILE_EXISTS")?{title:"File already exists",message:`The file "${e.find(n=>n.errors.includes("FILE_EXISTS"))?.file.name??"file"}" is already attached to this message.`}:{title:"File rejected",message:"This file could not be added."}}const L=s.ikp("div",{_id:"aiChatMessage__Files"}),f=new WeakSet;let E=!1;function A(e,t){const i=t.map(a=>{if(!a.providerMetadata)return{...a};try{return{...a,providerMetadata:structuredClone(a.providerMetadata)}}catch{return E||(E=!0,console.warn("[transformMessageFiles] providerMetadata is not structured-cloneable; passing a shared reference. A transformer that mutates it writes through into live message state.")),{...a}}});let n;try{n=e(i)}catch(a){return f.has(e)||(f.add(e),console.warn("[transformMessageFiles] transformer threw",a)),t}return Array.isArray(n)?n.filter(a=>a!=null):(f.has(e)||(f.add(e),console.warn("[transformMessageFiles] transformer must return an array, got:",n)),t)}const S=({children:e,...t})=>{const{message:i}=N.useMessage(),{aiChatSettings:n}=y.useInkeepConfig();if(i.role!=="user")return null;const a=(i.parts??[]).filter(l=>l.type==="file"),r=n.transformMessageFiles,d=(r?A(r,a):a).filter(l=>w.has(l.mediaType??""));return d.length?o.jsx(L,{...t,children:e(d)}):null},U=s.ikp("button",{_id:"aiChatMessage__File"}),R=({url:e,name:t,mediaType:i,onClick:n,...a})=>{const{openImagePreview:r}=j.useImagePreview(),[c,d]=p.useState(!0),l=p.useMemo(()=>new File([],t??"file",{type:i}),[t,i]);return o.jsx(_.Provider,{value:{file:l,objectUrl:e,isLoading:c,setIsLoading:d,onRemove:()=>{}},children:o.jsx(U,{type:"button","aria-label":C(i??"")?`Preview ${t??"file"}`:`Open ${t??"file"} in new tab`,"data-loading":F.dataAttr(c),onClick:x.composeEventHandlers(n,()=>{if(C(i??""))r({url:e,name:t??"file"});else if(e)if(e.startsWith("data:")){const g=document.createElement("a");g.href=e,g.download=t??"file",g.click()}else window.open(e,"_blank","noopener,noreferrer")}),...a})})},O=s.ikp("div",{_id:"aiChatInput__Fieldset"}),H=e=>{const t=m.useFileUploadApi();return o.jsx(O,{...t.getDropzoneProps({disableClick:!0}),"data-drag-over":F.dataAttr(t.dragging),...e})},D=({...e})=>{const{files:t,setFiles:i,showInputNotification:n}=u.useChat();return o.jsx(m.FileUploadRoot,{accept:v,maxFiles:I,maxFileSize:P,preventDocumentDrop:!0,acceptedFiles:t,onFileAccept:a=>i(a.files),onFileReject:a=>{const r=q(a.files);r&&n(r)},children:o.jsx(H,{...e})})},B=s.ikp("div",{_id:"aiChatInput__DropZone"}),X=s.ikp("div",{_id:"aiChatInput__Notification"}),Y=e=>{const{inputNotification:t}=u.useChat();return t?o.jsx(X,{role:"alert",...e}):null},$=s.ikp("p",{_id:"aiChatInput__NotificationTitle"}),z=({children:e,...t})=>{const{inputNotification:i}=u.useChat();return i?.title?o.jsxs($,{...t,children:[e,i.title]}):null},Z=s.ikp("p",{_id:"aiChatInput__NotificationMessage"}),W=e=>{const{inputNotification:t}=u.useChat();return o.jsx(Z,{...e,children:t?.message})},K=s.ikp("button",{_id:"aiChatInput__NotificationClose"}),V=({onClick:e,...t})=>{const{clearInputNotification:i}=u.useChat();return o.jsx(K,{type:"button","aria-label":"Dismiss",onClick:x.composeEventHandlers(e,i),...t})},G=s.ikp("div",{_id:"aiChatInput__NotificationContent"}),J=s.ikp("div",{_id:"aiChatInput__NotificationHeader"}),Q=s.ikp(b.CustomIcon,{_id:"aiChatInput__FileUploadButtonIcon",iconKey:"fileUpload"}),ee=s.ikp("button",{_id:"aiChatInput__FileUploadButton"}),te=e=>{const{aiChatSettings:t}=y.useInkeepConfig(),i=m.useFileUploadApi(),{onClick:n,...a}=e;return o.jsx(ee,{type:"button","aria-label":"Upload file",disabled:t.isViewOnly,onClick:x.composeEventHandlers(n,()=>i.openFilePicker()),...a})},ie=s.ikp("input",{_id:"aiChatInput__FileInput"}),ne=e=>{const t=m.useFileUploadApi();return o.jsx(ie,{...e,...t.getHiddenInputProps()})},ae=s.ikp("div",{_id:"aiChatInput__FileList"}),oe=({children:e,...t})=>{const n=m.useFileUploadApi().acceptedFiles;return n.length?o.jsx(ae,{...t,children:e(n)}):null},_=p.createContext(null);function h(){const e=p.useContext(_);if(!e)throw new Error("useFileContext must be used within EmbeddedChatPrimitiveFileItem");return e}const se=s.ikp("div",{_id:"aiChatInput__FileItem"}),re=({file:e,...t})=>{const i=m.useFileUploadApi(),[n,a]=p.useState(void 0),[r,c]=p.useState(!0);p.useEffect(()=>i.createFileUrl(e,l=>{a(l),c(!0)}),[e]);const d=()=>i.deleteFile(e);return o.jsx(_.Provider,{value:{file:e,objectUrl:n,isLoading:r,setIsLoading:c,onRemove:d},children:o.jsx(se,{"data-loading":F.dataAttr(r),...t})})},le=s.ikp("button",{_id:"aiChatInput__FilePreviewTrigger"}),pe=({onClick:e,...t})=>{const{objectUrl:i,file:n}=h(),{openImagePreview:a}=j.useImagePreview();return o.jsx(le,{type:"button","aria-label":`Preview ${n.name}`,disabled:!i,onClick:x.composeEventHandlers(e,()=>{i&&a({url:i,name:n.name})}),...t})},ce=s.ikp("span",{_id:"aiChatInput__FileContent"}),de=e=>o.jsx(ce,{...e}),me=s.ikp("img",{_id:"aiChatInput__FileThumbnail"}),xe=({onLoad:e,...t})=>{const{objectUrl:i,file:n,setIsLoading:a}=h();return o.jsx(me,{src:i,alt:n.name,onLoad:x.composeEventHandlers(e,()=>a(!1)),...t})},ue=({className:e})=>{const{file:t}=h(),i=k[M(t).type]??"file";return o.jsx(b.CustomIcon,{iconKey:i,className:e})},he=s.ikp("span",{_id:"aiChatInput__FileName"}),fe=e=>{const{file:t}=h();return o.jsx(he,{...e,children:t.name})},ve=s.ikp("button",{_id:"aiChatInput__FileRemove"}),ge=s.ikp(b.CustomIcon,{_id:"aiChatInput__FileRemoveIcon",iconKey:"close"}),Ce=({onClick:e,...t})=>{const{onRemove:i}=h();return o.jsx(ve,{type:"button","aria-label":"Remove file",onClick:x.composeEventHandlers(e,i),...t})};exports.ACCEPTED_FILE_MIME_TYPES=w;exports.EmbeddedChatPrimitiveDropZone=B;exports.EmbeddedChatPrimitiveFileContent=de;exports.EmbeddedChatPrimitiveFileInput=ne;exports.EmbeddedChatPrimitiveFileItem=re;exports.EmbeddedChatPrimitiveFileList=oe;exports.EmbeddedChatPrimitiveFileName=fe;exports.EmbeddedChatPrimitiveFilePreviewTrigger=pe;exports.EmbeddedChatPrimitiveFileRemove=Ce;exports.EmbeddedChatPrimitiveFileRemoveIcon=ge;exports.EmbeddedChatPrimitiveFileThumbnail=xe;exports.EmbeddedChatPrimitiveFileTypeIcon=ue;exports.EmbeddedChatPrimitiveFileUploadButton=te;exports.EmbeddedChatPrimitiveFileUploadButtonIcon=Q;exports.EmbeddedChatPrimitiveInputFieldset=D;exports.EmbeddedChatPrimitiveInputNotification=Y;exports.EmbeddedChatPrimitiveInputNotificationClose=V;exports.EmbeddedChatPrimitiveInputNotificationContent=G;exports.EmbeddedChatPrimitiveInputNotificationHeader=J;exports.EmbeddedChatPrimitiveInputNotificationMessage=W;exports.EmbeddedChatPrimitiveInputNotificationTitle=z;exports.EmbeddedChatPrimitiveMessageFile=R;exports.EmbeddedChatPrimitiveMessageFiles=S;exports.FILE_ACCEPT_MAP=v;exports.FILE_TYPE_ICON_MAP=k;exports.MAX_FILES=I;exports.MAX_FILE_SIZE=P;exports.isImageMimeType=C;exports.normalizeFileType=M;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import
|
|
2
|
+
import { jsx as s, jsxs as k } from "react/jsx-runtime";
|
|
3
|
+
import P, { useState as g, useEffect as M, useMemo as N } from "react";
|
|
4
4
|
import { CustomIcon as v } from "../../atoms/icons/custom-icon.js";
|
|
5
|
-
import { useImagePreview as
|
|
6
|
-
import { useMessage as
|
|
7
|
-
import { useChat as
|
|
8
|
-
import { useFileUploadApi as
|
|
9
|
-
import { dataAttr as
|
|
10
|
-
import { composeEventHandlers as
|
|
5
|
+
import { useImagePreview as y } from "../../providers/image-preview-provider.js";
|
|
6
|
+
import { useMessage as T } from "../../providers/message-provider.js";
|
|
7
|
+
import { useChat as m } from "./chat-provider.js";
|
|
8
|
+
import { useFileUploadApi as x, FileUploadRoot as L } from "../../atoms/file-upload.js";
|
|
9
|
+
import { dataAttr as b } from "../../utils/misc.js";
|
|
10
|
+
import { composeEventHandlers as d } from "../../utils/compose-event-handlers.js";
|
|
11
11
|
import { ikp as o } from "../factory.js";
|
|
12
|
-
import { useInkeepConfig as
|
|
13
|
-
const
|
|
12
|
+
import { useInkeepConfig as j } from "../../providers/config-provider.js";
|
|
13
|
+
const q = {
|
|
14
14
|
"application/pdf": "filePdf",
|
|
15
15
|
"text/plain": "fileText",
|
|
16
16
|
"text/markdown": "fileMarkdown",
|
|
@@ -24,7 +24,7 @@ const L = {
|
|
|
24
24
|
"text/x-python": "filePy",
|
|
25
25
|
"text/x-python-script": "filePy"
|
|
26
26
|
};
|
|
27
|
-
function
|
|
27
|
+
function C(t) {
|
|
28
28
|
return t.startsWith("image/");
|
|
29
29
|
}
|
|
30
30
|
const _ = {
|
|
@@ -173,7 +173,7 @@ const _ = {
|
|
|
173
173
|
"application/x-iwork-pages-sffpages": [".pages"],
|
|
174
174
|
"application/x-iwork-numbers-sffnumbers": [".numbers"],
|
|
175
175
|
"application/x-iwork-keynote-sffkey": [".key"]
|
|
176
|
-
},
|
|
176
|
+
}, S = new Set(Object.keys(_)), E = 10, w = 1024 * 1024 * 10, A = Object.entries(_).reduce(
|
|
177
177
|
(t, [e, i]) => {
|
|
178
178
|
for (const n of i) t[n] = e;
|
|
179
179
|
return t;
|
|
@@ -182,7 +182,7 @@ const _ = {
|
|
|
182
182
|
);
|
|
183
183
|
function R(t) {
|
|
184
184
|
if (t.type) return t;
|
|
185
|
-
const e = `.${t.name.split(".").pop()?.toLowerCase()}`, i =
|
|
185
|
+
const e = `.${t.name.split(".").pop()?.toLowerCase()}`, i = A[e];
|
|
186
186
|
return i ? new File([t], t.name, { type: i }) : t;
|
|
187
187
|
}
|
|
188
188
|
function U(t) {
|
|
@@ -190,13 +190,13 @@ function U(t) {
|
|
|
190
190
|
const e = (i) => t.some((n) => n.errors.includes(i));
|
|
191
191
|
return e("TOO_MANY_FILES") ? {
|
|
192
192
|
title: "Attachment limit reached",
|
|
193
|
-
message: `You can only attach up to ${
|
|
193
|
+
message: `You can only attach up to ${E} files per message.`
|
|
194
194
|
} : e("FILE_INVALID_TYPE") ? {
|
|
195
195
|
title: "Unsupported file type",
|
|
196
196
|
message: "Supported formats include images, PDFs, text, code, and document files."
|
|
197
197
|
} : e("FILE_TOO_LARGE") ? {
|
|
198
198
|
title: "File too large",
|
|
199
|
-
message: `Files must be smaller than ${
|
|
199
|
+
message: `Files must be smaller than ${w / 1024 / 1024}MB.`
|
|
200
200
|
} : e("FILE_EXISTS") ? {
|
|
201
201
|
title: "File already exists",
|
|
202
202
|
message: `The file "${t.find((n) => n.errors.includes("FILE_EXISTS"))?.file.name ?? "file"}" is already attached to this message.`
|
|
@@ -205,266 +205,285 @@ function U(t) {
|
|
|
205
205
|
message: "This file could not be added."
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
const
|
|
208
|
+
const O = o("div", {
|
|
209
209
|
_id: "aiChatMessage__Files"
|
|
210
|
-
}),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
}), f = /* @__PURE__ */ new WeakSet();
|
|
211
|
+
let I = !1;
|
|
212
|
+
function D(t, e) {
|
|
213
|
+
const i = e.map((a) => {
|
|
214
|
+
if (!a.providerMetadata) return { ...a };
|
|
215
|
+
try {
|
|
216
|
+
return { ...a, providerMetadata: structuredClone(a.providerMetadata) };
|
|
217
|
+
} catch {
|
|
218
|
+
return I || (I = !0, console.warn(
|
|
219
|
+
"[transformMessageFiles] providerMetadata is not structured-cloneable; passing a shared reference. A transformer that mutates it writes through into live message state."
|
|
220
|
+
)), { ...a };
|
|
221
|
+
}
|
|
217
222
|
});
|
|
218
|
-
|
|
219
|
-
|
|
223
|
+
let n;
|
|
224
|
+
try {
|
|
225
|
+
n = t(i);
|
|
226
|
+
} catch (a) {
|
|
227
|
+
return f.has(t) || (f.add(t), console.warn("[transformMessageFiles] transformer threw", a)), e;
|
|
228
|
+
}
|
|
229
|
+
return Array.isArray(n) ? n.filter((a) => a != null) : (f.has(t) || (f.add(t), console.warn("[transformMessageFiles] transformer must return an array, got:", n)), e);
|
|
230
|
+
}
|
|
231
|
+
const ut = ({ children: t, ...e }) => {
|
|
232
|
+
const { message: i } = T(), { aiChatSettings: n } = j();
|
|
233
|
+
if (i.role !== "user") return null;
|
|
234
|
+
const a = (i.parts ?? []).filter((l) => l.type === "file"), r = n.transformMessageFiles, c = (r ? D(r, a) : a).filter(
|
|
235
|
+
(l) => S.has(l.mediaType ?? "")
|
|
236
|
+
);
|
|
237
|
+
return c.length ? /* @__PURE__ */ s(O, { ...e, children: t(c) }) : null;
|
|
238
|
+
}, $ = o("button", {
|
|
220
239
|
_id: "aiChatMessage__File"
|
|
221
|
-
}),
|
|
240
|
+
}), ft = ({
|
|
222
241
|
url: t,
|
|
223
242
|
name: e,
|
|
224
243
|
mediaType: i,
|
|
225
244
|
onClick: n,
|
|
226
|
-
...
|
|
245
|
+
...a
|
|
227
246
|
}) => {
|
|
228
|
-
const { openImagePreview:
|
|
247
|
+
const { openImagePreview: r } = y(), [p, c] = g(!0), l = N(
|
|
229
248
|
() => new File([], e ?? "file", { type: i }),
|
|
230
249
|
[e, i]
|
|
231
250
|
);
|
|
232
|
-
return /* @__PURE__ */
|
|
233
|
-
|
|
251
|
+
return /* @__PURE__ */ s(
|
|
252
|
+
F.Provider,
|
|
234
253
|
{
|
|
235
|
-
value: { file:
|
|
254
|
+
value: { file: l, objectUrl: t, isLoading: p, setIsLoading: c, onRemove: () => {
|
|
236
255
|
} },
|
|
237
|
-
children: /* @__PURE__ */
|
|
238
|
-
|
|
256
|
+
children: /* @__PURE__ */ s(
|
|
257
|
+
$,
|
|
239
258
|
{
|
|
240
259
|
type: "button",
|
|
241
|
-
"aria-label":
|
|
242
|
-
"data-loading":
|
|
243
|
-
onClick:
|
|
244
|
-
if (
|
|
245
|
-
|
|
260
|
+
"aria-label": C(i ?? "") ? `Preview ${e ?? "file"}` : `Open ${e ?? "file"} in new tab`,
|
|
261
|
+
"data-loading": b(p),
|
|
262
|
+
onClick: d(n, () => {
|
|
263
|
+
if (C(i ?? ""))
|
|
264
|
+
r({ url: t, name: e ?? "file" });
|
|
246
265
|
else if (t)
|
|
247
266
|
if (t.startsWith("data:")) {
|
|
248
|
-
const
|
|
249
|
-
|
|
267
|
+
const h = document.createElement("a");
|
|
268
|
+
h.href = t, h.download = e ?? "file", h.click();
|
|
250
269
|
} else
|
|
251
270
|
window.open(t, "_blank", "noopener,noreferrer");
|
|
252
271
|
}),
|
|
253
|
-
...
|
|
272
|
+
...a
|
|
254
273
|
}
|
|
255
274
|
)
|
|
256
275
|
}
|
|
257
276
|
);
|
|
258
|
-
},
|
|
277
|
+
}, B = o("div", {
|
|
259
278
|
_id: "aiChatInput__Fieldset"
|
|
260
|
-
}),
|
|
261
|
-
const e =
|
|
262
|
-
return /* @__PURE__ */
|
|
263
|
-
|
|
279
|
+
}), z = (t) => {
|
|
280
|
+
const e = x();
|
|
281
|
+
return /* @__PURE__ */ s(
|
|
282
|
+
B,
|
|
264
283
|
{
|
|
265
284
|
...e.getDropzoneProps({ disableClick: !0 }),
|
|
266
|
-
"data-drag-over":
|
|
285
|
+
"data-drag-over": b(e.dragging),
|
|
267
286
|
...t
|
|
268
287
|
}
|
|
269
288
|
);
|
|
270
|
-
},
|
|
289
|
+
}, ht = ({
|
|
271
290
|
...t
|
|
272
291
|
}) => {
|
|
273
|
-
const { files: e, setFiles: i, showInputNotification: n } =
|
|
274
|
-
return /* @__PURE__ */
|
|
275
|
-
|
|
292
|
+
const { files: e, setFiles: i, showInputNotification: n } = m();
|
|
293
|
+
return /* @__PURE__ */ s(
|
|
294
|
+
L,
|
|
276
295
|
{
|
|
277
296
|
accept: _,
|
|
278
|
-
maxFiles:
|
|
279
|
-
maxFileSize:
|
|
297
|
+
maxFiles: E,
|
|
298
|
+
maxFileSize: w,
|
|
280
299
|
preventDocumentDrop: !0,
|
|
281
300
|
acceptedFiles: e,
|
|
282
|
-
onFileAccept: (
|
|
283
|
-
onFileReject: (
|
|
284
|
-
const
|
|
285
|
-
|
|
301
|
+
onFileAccept: (a) => i(a.files),
|
|
302
|
+
onFileReject: (a) => {
|
|
303
|
+
const r = U(a.files);
|
|
304
|
+
r && n(r);
|
|
286
305
|
},
|
|
287
|
-
children: /* @__PURE__ */
|
|
306
|
+
children: /* @__PURE__ */ s(z, { ...t })
|
|
288
307
|
}
|
|
289
308
|
);
|
|
290
|
-
},
|
|
309
|
+
}, gt = o("div", {
|
|
291
310
|
_id: "aiChatInput__DropZone"
|
|
292
|
-
}),
|
|
311
|
+
}), H = o("div", {
|
|
293
312
|
_id: "aiChatInput__Notification"
|
|
294
|
-
}),
|
|
295
|
-
const { inputNotification: e } =
|
|
296
|
-
return e ? /* @__PURE__ */
|
|
297
|
-
},
|
|
313
|
+
}), vt = (t) => {
|
|
314
|
+
const { inputNotification: e } = m();
|
|
315
|
+
return e ? /* @__PURE__ */ s(H, { role: "alert", ...t }) : null;
|
|
316
|
+
}, X = o("p", {
|
|
298
317
|
_id: "aiChatInput__NotificationTitle"
|
|
299
|
-
}),
|
|
318
|
+
}), bt = ({
|
|
300
319
|
children: t,
|
|
301
320
|
...e
|
|
302
321
|
}) => {
|
|
303
|
-
const { inputNotification: i } =
|
|
304
|
-
return i?.title ? /* @__PURE__ */
|
|
322
|
+
const { inputNotification: i } = m();
|
|
323
|
+
return i?.title ? /* @__PURE__ */ k(X, { ...e, children: [
|
|
305
324
|
t,
|
|
306
325
|
i.title
|
|
307
326
|
] }) : null;
|
|
308
|
-
},
|
|
327
|
+
}, Y = o("p", {
|
|
309
328
|
_id: "aiChatInput__NotificationMessage"
|
|
310
|
-
}),
|
|
311
|
-
const { inputNotification: e } =
|
|
312
|
-
return /* @__PURE__ */
|
|
313
|
-
},
|
|
329
|
+
}), _t = (t) => {
|
|
330
|
+
const { inputNotification: e } = m();
|
|
331
|
+
return /* @__PURE__ */ s(Y, { ...t, children: e?.message });
|
|
332
|
+
}, W = o("button", {
|
|
314
333
|
_id: "aiChatInput__NotificationClose"
|
|
315
|
-
}),
|
|
334
|
+
}), Ft = ({
|
|
316
335
|
onClick: t,
|
|
317
336
|
...e
|
|
318
337
|
}) => {
|
|
319
|
-
const { clearInputNotification: i } =
|
|
320
|
-
return /* @__PURE__ */
|
|
321
|
-
|
|
338
|
+
const { clearInputNotification: i } = m();
|
|
339
|
+
return /* @__PURE__ */ s(
|
|
340
|
+
W,
|
|
322
341
|
{
|
|
323
342
|
type: "button",
|
|
324
343
|
"aria-label": "Dismiss",
|
|
325
|
-
onClick:
|
|
344
|
+
onClick: d(t, i),
|
|
326
345
|
...e
|
|
327
346
|
}
|
|
328
347
|
);
|
|
329
|
-
},
|
|
348
|
+
}, Ct = o("div", {
|
|
330
349
|
_id: "aiChatInput__NotificationContent"
|
|
331
|
-
}),
|
|
350
|
+
}), It = o("div", {
|
|
332
351
|
_id: "aiChatInput__NotificationHeader"
|
|
333
|
-
}),
|
|
352
|
+
}), Pt = o(v, {
|
|
334
353
|
_id: "aiChatInput__FileUploadButtonIcon",
|
|
335
354
|
iconKey: "fileUpload"
|
|
336
|
-
}),
|
|
355
|
+
}), K = o("button", {
|
|
337
356
|
_id: "aiChatInput__FileUploadButton"
|
|
338
|
-
}),
|
|
339
|
-
const { aiChatSettings: e } =
|
|
340
|
-
return /* @__PURE__ */
|
|
341
|
-
|
|
357
|
+
}), yt = (t) => {
|
|
358
|
+
const { aiChatSettings: e } = j(), i = x(), { onClick: n, ...a } = t;
|
|
359
|
+
return /* @__PURE__ */ s(
|
|
360
|
+
K,
|
|
342
361
|
{
|
|
343
362
|
type: "button",
|
|
344
363
|
"aria-label": "Upload file",
|
|
345
364
|
disabled: e.isViewOnly,
|
|
346
|
-
onClick:
|
|
347
|
-
...
|
|
365
|
+
onClick: d(n, () => i.openFilePicker()),
|
|
366
|
+
...a
|
|
348
367
|
}
|
|
349
368
|
);
|
|
350
|
-
},
|
|
369
|
+
}, Z = o("input", {
|
|
351
370
|
_id: "aiChatInput__FileInput"
|
|
352
|
-
}),
|
|
353
|
-
const e =
|
|
354
|
-
return /* @__PURE__ */
|
|
355
|
-
},
|
|
371
|
+
}), jt = (t) => {
|
|
372
|
+
const e = x();
|
|
373
|
+
return /* @__PURE__ */ s(Z, { ...t, ...e.getHiddenInputProps() });
|
|
374
|
+
}, V = o("div", {
|
|
356
375
|
_id: "aiChatInput__FileList"
|
|
357
|
-
}),
|
|
358
|
-
const n =
|
|
359
|
-
return n.length ? /* @__PURE__ */
|
|
360
|
-
},
|
|
361
|
-
function
|
|
362
|
-
const t =
|
|
376
|
+
}), Et = ({ children: t, ...e }) => {
|
|
377
|
+
const n = x().acceptedFiles;
|
|
378
|
+
return n.length ? /* @__PURE__ */ s(V, { ...e, children: t(n) }) : null;
|
|
379
|
+
}, F = P.createContext(null);
|
|
380
|
+
function u() {
|
|
381
|
+
const t = P.useContext(F);
|
|
363
382
|
if (!t) throw new Error("useFileContext must be used within EmbeddedChatPrimitiveFileItem");
|
|
364
383
|
return t;
|
|
365
384
|
}
|
|
366
|
-
const
|
|
385
|
+
const G = o("div", {
|
|
367
386
|
_id: "aiChatInput__FileItem"
|
|
368
|
-
}),
|
|
369
|
-
const i =
|
|
370
|
-
|
|
371
|
-
|
|
387
|
+
}), wt = ({ file: t, ...e }) => {
|
|
388
|
+
const i = x(), [n, a] = g(void 0), [r, p] = g(!0);
|
|
389
|
+
M(() => i.createFileUrl(t, (l) => {
|
|
390
|
+
a(l), p(!0);
|
|
372
391
|
}), [t]);
|
|
373
|
-
const
|
|
374
|
-
return /* @__PURE__ */
|
|
375
|
-
},
|
|
392
|
+
const c = () => i.deleteFile(t);
|
|
393
|
+
return /* @__PURE__ */ s(F.Provider, { value: { file: t, objectUrl: n, isLoading: r, setIsLoading: p, onRemove: c }, children: /* @__PURE__ */ s(G, { "data-loading": b(r), ...e }) });
|
|
394
|
+
}, J = o("button", {
|
|
376
395
|
_id: "aiChatInput__FilePreviewTrigger"
|
|
377
|
-
}),
|
|
396
|
+
}), kt = ({
|
|
378
397
|
onClick: t,
|
|
379
398
|
...e
|
|
380
399
|
}) => {
|
|
381
|
-
const { objectUrl: i, file: n } =
|
|
382
|
-
return /* @__PURE__ */
|
|
383
|
-
|
|
400
|
+
const { objectUrl: i, file: n } = u(), { openImagePreview: a } = y();
|
|
401
|
+
return /* @__PURE__ */ s(
|
|
402
|
+
J,
|
|
384
403
|
{
|
|
385
404
|
type: "button",
|
|
386
405
|
"aria-label": `Preview ${n.name}`,
|
|
387
406
|
disabled: !i,
|
|
388
|
-
onClick:
|
|
389
|
-
i &&
|
|
407
|
+
onClick: d(t, () => {
|
|
408
|
+
i && a({ url: i, name: n.name });
|
|
390
409
|
}),
|
|
391
410
|
...e
|
|
392
411
|
}
|
|
393
412
|
);
|
|
394
|
-
},
|
|
413
|
+
}, Q = o("span", {
|
|
395
414
|
_id: "aiChatInput__FileContent"
|
|
396
|
-
}),
|
|
415
|
+
}), Mt = (t) => /* @__PURE__ */ s(Q, { ...t }), tt = o("img", {
|
|
397
416
|
_id: "aiChatInput__FileThumbnail"
|
|
398
|
-
}),
|
|
417
|
+
}), Nt = ({
|
|
399
418
|
onLoad: t,
|
|
400
419
|
...e
|
|
401
420
|
}) => {
|
|
402
|
-
const { objectUrl: i, file: n, setIsLoading:
|
|
403
|
-
return /* @__PURE__ */
|
|
404
|
-
|
|
421
|
+
const { objectUrl: i, file: n, setIsLoading: a } = u();
|
|
422
|
+
return /* @__PURE__ */ s(
|
|
423
|
+
tt,
|
|
405
424
|
{
|
|
406
425
|
src: i,
|
|
407
426
|
alt: n.name,
|
|
408
|
-
onLoad:
|
|
427
|
+
onLoad: d(t, () => a(!1)),
|
|
409
428
|
...e
|
|
410
429
|
}
|
|
411
430
|
);
|
|
412
|
-
},
|
|
413
|
-
const { file: e } =
|
|
414
|
-
return /* @__PURE__ */
|
|
415
|
-
},
|
|
431
|
+
}, Tt = ({ className: t }) => {
|
|
432
|
+
const { file: e } = u(), i = q[R(e).type] ?? "file";
|
|
433
|
+
return /* @__PURE__ */ s(v, { iconKey: i, className: t });
|
|
434
|
+
}, et = o("span", {
|
|
416
435
|
_id: "aiChatInput__FileName"
|
|
417
|
-
}),
|
|
418
|
-
const { file: e } =
|
|
419
|
-
return /* @__PURE__ */
|
|
420
|
-
},
|
|
436
|
+
}), Lt = (t) => {
|
|
437
|
+
const { file: e } = u();
|
|
438
|
+
return /* @__PURE__ */ s(et, { ...t, children: e.name });
|
|
439
|
+
}, it = o("button", {
|
|
421
440
|
_id: "aiChatInput__FileRemove"
|
|
422
|
-
}),
|
|
441
|
+
}), qt = o(v, {
|
|
423
442
|
_id: "aiChatInput__FileRemoveIcon",
|
|
424
443
|
iconKey: "close"
|
|
425
|
-
}),
|
|
444
|
+
}), St = ({
|
|
426
445
|
onClick: t,
|
|
427
446
|
...e
|
|
428
447
|
}) => {
|
|
429
|
-
const { onRemove: i } =
|
|
430
|
-
return /* @__PURE__ */
|
|
431
|
-
|
|
448
|
+
const { onRemove: i } = u();
|
|
449
|
+
return /* @__PURE__ */ s(
|
|
450
|
+
it,
|
|
432
451
|
{
|
|
433
452
|
type: "button",
|
|
434
453
|
"aria-label": "Remove file",
|
|
435
|
-
onClick:
|
|
454
|
+
onClick: d(t, i),
|
|
436
455
|
...e
|
|
437
456
|
}
|
|
438
457
|
);
|
|
439
458
|
};
|
|
440
459
|
export {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
460
|
+
S as ACCEPTED_FILE_MIME_TYPES,
|
|
461
|
+
gt as EmbeddedChatPrimitiveDropZone,
|
|
462
|
+
Mt as EmbeddedChatPrimitiveFileContent,
|
|
463
|
+
jt as EmbeddedChatPrimitiveFileInput,
|
|
464
|
+
wt as EmbeddedChatPrimitiveFileItem,
|
|
465
|
+
Et as EmbeddedChatPrimitiveFileList,
|
|
466
|
+
Lt as EmbeddedChatPrimitiveFileName,
|
|
467
|
+
kt as EmbeddedChatPrimitiveFilePreviewTrigger,
|
|
468
|
+
St as EmbeddedChatPrimitiveFileRemove,
|
|
469
|
+
qt as EmbeddedChatPrimitiveFileRemoveIcon,
|
|
470
|
+
Nt as EmbeddedChatPrimitiveFileThumbnail,
|
|
471
|
+
Tt as EmbeddedChatPrimitiveFileTypeIcon,
|
|
472
|
+
yt as EmbeddedChatPrimitiveFileUploadButton,
|
|
473
|
+
Pt as EmbeddedChatPrimitiveFileUploadButtonIcon,
|
|
474
|
+
ht as EmbeddedChatPrimitiveInputFieldset,
|
|
475
|
+
vt as EmbeddedChatPrimitiveInputNotification,
|
|
476
|
+
Ft as EmbeddedChatPrimitiveInputNotificationClose,
|
|
477
|
+
Ct as EmbeddedChatPrimitiveInputNotificationContent,
|
|
478
|
+
It as EmbeddedChatPrimitiveInputNotificationHeader,
|
|
479
|
+
_t as EmbeddedChatPrimitiveInputNotificationMessage,
|
|
480
|
+
bt as EmbeddedChatPrimitiveInputNotificationTitle,
|
|
481
|
+
ft as EmbeddedChatPrimitiveMessageFile,
|
|
482
|
+
ut as EmbeddedChatPrimitiveMessageFiles,
|
|
464
483
|
_ as FILE_ACCEPT_MAP,
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
484
|
+
q as FILE_TYPE_ICON_MAP,
|
|
485
|
+
E as MAX_FILES,
|
|
486
|
+
w as MAX_FILE_SIZE,
|
|
487
|
+
C as isImageMimeType,
|
|
469
488
|
R as normalizeFileType
|
|
470
489
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.17.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.17.5",a=t.useMemo(()=>({widgetLibraryVersion:c,componentType:o,tags:r}),[o,r,c]),v={logEvent:t.useCallback(async u=>{const E={...a,...u.properties,...i},d={eventName:u.eventName,properties:E};return s.onEvent?.(d)},[s,a,i])};return l.jsx(n.Provider,{value:v,children:e})},m=()=>{const e=t.useContext(n);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsContext=n;exports.BaseEventsProvider=g;exports.useBaseEvents=m;
|
|
@@ -3,7 +3,7 @@ import { jsx as u } from "react/jsx-runtime";
|
|
|
3
3
|
import { createContext as E, useMemo as d, useCallback as l, useContext as g } from "react";
|
|
4
4
|
import { useInkeepConfig as x } from "./config-provider.js";
|
|
5
5
|
const c = E(void 0), b = ({ children: e }) => {
|
|
6
|
-
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.17.
|
|
6
|
+
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.17.5", i = d(
|
|
7
7
|
() => ({
|
|
8
8
|
widgetLibraryVersion: r,
|
|
9
9
|
componentType: o,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.17.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.17.5",a=u.useMemo(()=>({widgetLibraryVersion:c,componentType:i}),[i,c]),{effectiveAuthToken:b,applicableRefreshSession:f,getCaptchaHeader:E,invalidateCaptcha:P}=O.useChatAuth(),{baseUrl:m,appId:A,analyticsApiBaseUrl:C,headers:I}=h,p=y?.optOutAllAnalytics??!1,{logEvent:l}=U.useEventsApi({baseUrl:C??m,appId:A,authToken:b,getCaptchaHeader:E,invalidateCaptcha:P,refreshSession:f,headers:I}),k={logEvent:u.useCallback(async s=>{const q={eventName:s.eventName,properties:{...a,...t?{tags:t}:{},...s.properties,...r}};if(!p){const e=s.properties??{},v=typeof e.conversationId=="string"?e.conversationId:void 0,d=typeof e.messageId=="string"?e.messageId:void 0,S=!!o&&Object.keys(o).length>0,w={...t?{tags:t}:{},...r??{}},T={...a,...s.properties};l({body:{type:s.eventName,...v?{conversationId:v}:{},...d?{messageId:d}:{},...S?{userProperties:o}:{},properties:w,metadata:T}})}try{return await n.onEvent?.(q)}catch(e){console.warn("[events] onEvent callback threw",e)}},[n,a,t,r,l,p,o])};return j.jsx(x.BaseEventsContext.Provider,{value:k,children:g})};exports.ChatBaseEventsProvider=M;
|
|
@@ -6,7 +6,7 @@ import { useChatAuth as O } from "./chat-auth-provider.js";
|
|
|
6
6
|
import { useEventsApi as j } from "../hooks/use-events-api.js";
|
|
7
7
|
import { BaseEventsContext as M } from "./base-events-provider.js";
|
|
8
8
|
const F = ({ children: m }) => {
|
|
9
|
-
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.17.
|
|
9
|
+
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.17.5", a = x(
|
|
10
10
|
() => ({
|
|
11
11
|
widgetLibraryVersion: c,
|
|
12
12
|
componentType: i
|
|
@@ -3,6 +3,7 @@ import { GetHelpOption, CustomMessageAction } from './settings/actions';
|
|
|
3
3
|
import { SearchAndChatFilters } from './filters';
|
|
4
4
|
import { ComponentsConfig } from './components';
|
|
5
5
|
import { FileUIPart } from 'ai';
|
|
6
|
+
export type { FileUIPart } from 'ai';
|
|
6
7
|
export interface InkeepAIChatSettings {
|
|
7
8
|
/**
|
|
8
9
|
* Headers for requests
|
|
@@ -43,6 +44,27 @@ export interface InkeepAIChatSettings {
|
|
|
43
44
|
* @beta This type is subject to change.
|
|
44
45
|
*/
|
|
45
46
|
files?: FileUIPart[];
|
|
47
|
+
/**
|
|
48
|
+
* Transform the file attachments displayed on a user message before they render as
|
|
49
|
+
* chips. Called per message at render time with the message's file parts, for live
|
|
50
|
+
* and history-loaded messages alike. The input includes all of the message's file
|
|
51
|
+
* parts regardless of MIME type; the widget's accepted-file-types filter is
|
|
52
|
+
* re-applied to the returned list, so unsupported types still never render. Return
|
|
53
|
+
* the parts to display: omit entries to hide them, or return shallow-modified copies
|
|
54
|
+
* (for example, with a friendlier filename) to rename them. Display-only, so it does
|
|
55
|
+
* not affect what is sent to the agent, stored, or visible to the LLM. Not a
|
|
56
|
+
* security boundary: hidden parts are still sent, stored in conversation history,
|
|
57
|
+
* and present in client memory, and if the transformer throws or returns a
|
|
58
|
+
* non-array, the widget fails open and renders the original untransformed parts.
|
|
59
|
+
* Null entries in a returned array are dropped, treated as intent to omit rather
|
|
60
|
+
* than as a failure. Every returned (whitelisted) part is displayed verbatim, so
|
|
61
|
+
* returning entries that were not in the input adds chips for files the user never
|
|
62
|
+
* attached. Must be pure and cheap, since it runs on every message render.
|
|
63
|
+
* Return new or copied objects and do not mutate the input parts.
|
|
64
|
+
*
|
|
65
|
+
* @beta This type is subject to change.
|
|
66
|
+
*/
|
|
67
|
+
transformMessageFiles?: (files: FileUIPart[]) => Array<FileUIPart | null | undefined>;
|
|
46
68
|
/**
|
|
47
69
|
* The placeholder text to display in the chat input field when empty.
|
|
48
70
|
* Use this to provide guidance on what kind of questions users can ask.
|