@doclessai/sdk 0.3.0
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/chunk-IPMERHAH.js +16 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +1 -0
- package/dist/loader.cjs +16 -0
- package/dist/loader.d.cts +2 -0
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var g=class{appKey;baseUrl;timeout;constructor(n){this.appKey=n.appKey,this.baseUrl=n.baseUrl||"https://doclessai.vercel.app/api/v1",this.timeout=n.timeout||3e4}async ask(n,c){let f=new AbortController,i=setTimeout(()=>f.abort(),this.timeout);try{let r=new FormData;r.append("appKey",this.appKey),r.append("query",n),c&&r.append("image",c);let s=await fetch(`${this.baseUrl}/chat`,{method:"POST",signal:f.signal,headers:{"X-SDK-Name":"@doclessai/sdk","X-SDK-Version":"0.2.1"},body:r});if(clearTimeout(i),!s.ok){let u=await s.json().catch(()=>({}));throw new Error(u.message||`DoclessAI Request failed with status ${s.status}`)}return await s.json()}catch(r){throw clearTimeout(i),r instanceof Error&&r.name==="AbortError"?new Error("DoclessAI Error: Request timed out."):new Error(`DoclessAI Error: ${r instanceof Error?r.message:"Unknown error"}`)}}};import{useState as p,useRef as I,useEffect as D,useMemo as z}from"react";import{toast as S,Toaster as T}from"react-hot-toast";import A from"react-markdown";import{jsx as e,jsxs as o}from"react/jsx-runtime";function M({name:h="Assistant",appKey:n}){let[c,f]=p(!1),[i,r]=p(""),[s,u]=p([{role:"assistant",content:"Hello! How can I help you today?"}]),[a,y]=p(!1),[m,b]=p(null),[w,v]=p(null),k=I(null),x=I(null),R=z(()=>new g({appKey:n}),[n]);D(()=>{x.current&&x.current.scrollTo({top:x.current.scrollHeight,behavior:"smooth"})},[s,a]);let C=async()=>{if(!i.trim()||a)return;let t=i.trim(),l=m;r(""),u(d=>[...d,{role:"user",content:t}]),y(!0);try{let d=await R.ask(t,l||void 0);b(null),u(E=>[...E,{role:"assistant",content:d.res,image:d.image}])}catch(d){S.error(d?.message||"Something went wrong"),r(t)}finally{y(!1)}};return o("div",{style:{fontFamily:"Inter, system-ui, sans-serif"},children:[e(T,{position:"top-center",reverseOrder:!1}),e("style",{children:`
|
|
2
|
+
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-5px); } }
|
|
3
|
+
@keyframes blink { 0%, 90%, 100% { opacity: 1; } 95% { opacity: 0.3; } }
|
|
4
|
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
5
|
+
|
|
6
|
+
.chat-bubble { animation: float 2s ease-in-out infinite; }
|
|
7
|
+
.robot-eye { animation: blink 3s ease-in-out infinite; }
|
|
8
|
+
|
|
9
|
+
/* Markdown Styling */
|
|
10
|
+
.markdown-container p { margin: 0 0 12px 0; line-height: 1.5; }
|
|
11
|
+
.markdown-container p:last-child { margin-bottom: 0; }
|
|
12
|
+
.markdown-container ul, .markdown-container ol { margin: 10px 0; padding-left: 20px; }
|
|
13
|
+
.markdown-container li { margin-bottom: 6px; line-height: 1.4; }
|
|
14
|
+
.markdown-container strong { font-weight: 700; color: #111827; }
|
|
15
|
+
.markdown-container a { color: #4f46e5; text-decoration: underline; }
|
|
16
|
+
`}),w&&o("div",{onClick:()=>v(null),style:{position:"fixed",inset:0,backgroundColor:"rgba(0,0,0,0.8)",backdropFilter:"blur(5px)",zIndex:2e4,display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out",padding:"20px"},children:[e("button",{style:{position:"absolute",top:"20px",right:"20px",background:"#fff",border:"none",borderRadius:"50%",width:"40px",height:"40px",cursor:"pointer",fontSize:"20px"},children:"\u2715"}),e("img",{src:w,style:{maxWidth:"100%",maxHeight:"90vh",borderRadius:"8px",boxShadow:"0 0 30px rgba(0,0,0,0.5)"},alt:"Zoomed reference"})]}),!c&&e("svg",{width:"60",height:"60",viewBox:"0 0 60 60",fill:"none",style:{cursor:"pointer",position:"fixed",bottom:"20px",right:"20px",zIndex:9999,filter:"drop-shadow(0px 4px 12px rgba(0, 0, 0, 0.15))"},onClick:()=>f(!0),children:o("g",{className:"chat-bubble",children:[e("ellipse",{cx:"30",cy:"52",rx:"15",ry:"3",fill:"#000",opacity:"0.1"}),e("path",{d:"M45 15C45 8.37258 39.6274 3 33 3H15C8.37258 3 3 8.37258 3 15V33C3 39.6274 8.37258 45 15 45H18V52L26 45H33C39.6274 45 45 39.6274 45 33V15Z",fill:"#4F46E5"}),o("g",{transform:"translate(12, 14)",children:[e("line",{x1:"12",y1:"0",x2:"12",y2:"3",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round"}),e("circle",{cx:"12",cy:"0",r:"1.5",fill:"white"}),e("rect",{x:"6",y:"3",width:"12",height:"10",rx:"2",fill:"white"}),e("circle",{className:"robot-eye",cx:"9.5",cy:"8",r:"1.5",fill:"#4F46E5"}),e("circle",{className:"robot-eye",cx:"14.5",cy:"8",r:"1.5",fill:"#4F46E5"}),e("line",{x1:"9",y1:"11",x2:"15",y2:"11",stroke:"#4F46E5",strokeWidth:"1",strokeLinecap:"round"}),e("rect",{x:"7",y:"14",width:"10",height:"6",rx:"1",fill:"white"}),e("rect",{x:"4",y:"15",width:"2",height:"4",rx:"1",fill:"white"}),e("rect",{x:"18",y:"15",width:"2",height:"4",rx:"1",fill:"white"})]})]})}),c&&o("div",{style:{position:"fixed",bottom:"20px",right:"20px",width:"min(400px, 90vw)",height:"min(600px, 85vh)",backgroundColor:"#fff",boxShadow:"0 12px 40px rgba(79, 70, 229, 0.25)",borderRadius:"16px",display:"flex",flexDirection:"column",zIndex:1e4,overflow:"hidden",border:"1px solid #e5e7eb",animation:"fadeIn 0.2s ease-out"},children:[o("div",{style:{backgroundColor:"#4f46e5",padding:"14px 18px",display:"flex",alignItems:"center",justifyContent:"space-between",color:"#fff"},children:[o("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e("div",{style:{width:"8px",height:"8px",backgroundColor:"#22c55e",borderRadius:"50%",boxShadow:"0 0 8px #22c55e"}}),e("span",{style:{fontWeight:600,fontSize:"15px"},children:h})]}),e("span",{style:{cursor:"pointer",fontSize:"18px",opacity:.8},onClick:()=>f(!1),children:"\u2715"})]}),o("div",{ref:x,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"#f9fafb"},children:[s.map((t,l)=>e("div",{style:{alignSelf:t.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",flexDirection:"column",gap:"4px"},children:o("div",{style:{backgroundColor:t.role==="user"?"#4f46e5":"#fff",color:t.role==="user"?"#fff":"#374151",padding:"12px 16px",borderRadius:"12px",fontSize:"14px",border:t.role==="user"?"none":"1px solid #e5e7eb",boxShadow:t.role==="user"?"0 2px 4px rgba(79,70,229,0.2)":"0 1px 2px rgba(0,0,0,0.05)"},children:[t.image&&e("div",{style:{marginBottom:"10px"},children:e("img",{src:t.image,onClick:()=>v(t.image),style:{width:"100%",borderRadius:"8px",cursor:"zoom-in"},alt:"Reference"})}),t.role==="assistant"?e("div",{className:"markdown-container",children:e(A,{children:t.content})}):e("div",{style:{whiteSpace:"pre-wrap"},children:t.content})]})},l)),e("div",{ref:x}),a&&o("div",{style:{fontSize:"12px",color:"#6b7280",marginLeft:"4px"},children:[h," is thinking..."]})]}),o("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb",backgroundColor:"#fff"},children:[o("div",{style:{display:"flex",alignItems:"center",gap:"10px",backgroundColor:"#f3f4f6",padding:"6px 14px",borderRadius:"28px"},children:[o("button",{style:{background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex"},onClick:()=>k.current?.click(),children:[o("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#9ca3af",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),e("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),e("polyline",{points:"21 15 16 10 5 21"})]}),e("input",{type:"file",accept:"image/*",ref:k,style:{display:"none"},onChange:t=>{let l=t.target.files?.[0];l&&(b(l),S.success(`Attached: ${l.name}`))}})]}),m&&o("div",{style:{fontSize:"11px",color:"#4f46e5",maxWidth:"80px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["\u{1F4CE} ",m.name]}),e("input",{type:"text",value:i,onChange:t=>r(t.target.value),onKeyDown:t=>t.key==="Enter"&&C(),placeholder:"Type a message...",style:{flex:1,border:"none",background:"none",padding:"10px 0",outline:"none",fontSize:"14px",color:"#1f2937"}}),e("button",{onClick:C,disabled:!i.trim()||a,style:{background:i.trim()&&!a?"#4f46e5":"transparent",border:"none",borderRadius:"50%",width:"34px",height:"34px",display:"flex",alignItems:"center",justifyContent:"center",cursor:i.trim()&&!a?"pointer":"default",transition:"all 0.2s"},children:o("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:i.trim()&&!a?"#fff":"#9ca3af",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),e("polyline",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]}),o("div",{style:{textAlign:"center",fontSize:"11px",color:"#9ca3af",marginTop:"10px"},children:["Powered by ",e("strong",{children:"DoclessAI"})]})]})]})]})}export{g as a,M as b};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";var T=Object.create;var m=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var W=(r,o)=>{for(var n in o)m(r,n,{get:o[n],enumerable:!0})},R=(r,o,n,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of M(o))!L.call(r,i)&&i!==n&&m(r,i,{get:()=>o[i],enumerable:!(l=A(o,i))||l.enumerable});return r};var H=(r,o,n)=>(n=r!=null?T(F(r)):{},R(o||!r||!r.__esModule?m(n,"default",{value:r,enumerable:!0}):n,r)),K=r=>R(m({},"__esModule",{value:!0}),r);var B={};W(B,{ChatWidget:()=>b,DoclessClient:()=>u});module.exports=K(B);var u=class{appKey;baseUrl;timeout;constructor(o){this.appKey=o.appKey,this.baseUrl=o.baseUrl||"https://doclessai.vercel.app/api/v1",this.timeout=o.timeout||3e4}async ask(o,n){let l=new AbortController,i=setTimeout(()=>l.abort(),this.timeout);try{let a=new FormData;a.append("appKey",this.appKey),a.append("query",o),n&&a.append("image",n);let d=await fetch(`${this.baseUrl}/chat`,{method:"POST",signal:l.signal,headers:{"X-SDK-Name":"@doclessai/sdk","X-SDK-Version":"0.2.1"},body:a});if(clearTimeout(i),!d.ok){let h=await d.json().catch(()=>({}));throw new Error(h.message||`DoclessAI Request failed with status ${d.status}`)}return await d.json()}catch(a){throw clearTimeout(i),a instanceof Error&&a.name==="AbortError"?new Error("DoclessAI Error: Request timed out."):new Error(`DoclessAI Error: ${a instanceof Error?a.message:"Unknown error"}`)}}};var s=require("react");var g=require("react-hot-toast"),E=H(require("react-markdown"),1),e=require("react/jsx-runtime");function b({name:r="Assistant",appKey:o}){let[n,l]=(0,s.useState)(!1),[i,a]=(0,s.useState)(""),[d,h]=(0,s.useState)([{role:"assistant",content:"Hello! How can I help you today?"}]),[p,w]=(0,s.useState)(!1),[y,v]=(0,s.useState)(null),[k,C]=(0,s.useState)(null),I=(0,s.useRef)(null),x=(0,s.useRef)(null),D=(0,s.useMemo)(()=>new u({appKey:o}),[o]);(0,s.useEffect)(()=>{x.current&&x.current.scrollTo({top:x.current.scrollHeight,behavior:"smooth"})},[d,p]);let S=async()=>{if(!i.trim()||p)return;let t=i.trim(),c=y;a(""),h(f=>[...f,{role:"user",content:t}]),w(!0);try{let f=await D.ask(t,c||void 0);v(null),h(z=>[...z,{role:"assistant",content:f.res,image:f.image}])}catch(f){g.toast.error(f?.message||"Something went wrong"),a(t)}finally{w(!1)}};return(0,e.jsxs)("div",{style:{fontFamily:"Inter, system-ui, sans-serif"},children:[(0,e.jsx)(g.Toaster,{position:"top-center",reverseOrder:!1}),(0,e.jsx)("style",{children:`
|
|
2
|
+
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-5px); } }
|
|
3
|
+
@keyframes blink { 0%, 90%, 100% { opacity: 1; } 95% { opacity: 0.3; } }
|
|
4
|
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
5
|
+
|
|
6
|
+
.chat-bubble { animation: float 2s ease-in-out infinite; }
|
|
7
|
+
.robot-eye { animation: blink 3s ease-in-out infinite; }
|
|
8
|
+
|
|
9
|
+
/* Markdown Styling */
|
|
10
|
+
.markdown-container p { margin: 0 0 12px 0; line-height: 1.5; }
|
|
11
|
+
.markdown-container p:last-child { margin-bottom: 0; }
|
|
12
|
+
.markdown-container ul, .markdown-container ol { margin: 10px 0; padding-left: 20px; }
|
|
13
|
+
.markdown-container li { margin-bottom: 6px; line-height: 1.4; }
|
|
14
|
+
.markdown-container strong { font-weight: 700; color: #111827; }
|
|
15
|
+
.markdown-container a { color: #4f46e5; text-decoration: underline; }
|
|
16
|
+
`}),k&&(0,e.jsxs)("div",{onClick:()=>C(null),style:{position:"fixed",inset:0,backgroundColor:"rgba(0,0,0,0.8)",backdropFilter:"blur(5px)",zIndex:2e4,display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out",padding:"20px"},children:[(0,e.jsx)("button",{style:{position:"absolute",top:"20px",right:"20px",background:"#fff",border:"none",borderRadius:"50%",width:"40px",height:"40px",cursor:"pointer",fontSize:"20px"},children:"\u2715"}),(0,e.jsx)("img",{src:k,style:{maxWidth:"100%",maxHeight:"90vh",borderRadius:"8px",boxShadow:"0 0 30px rgba(0,0,0,0.5)"},alt:"Zoomed reference"})]}),!n&&(0,e.jsx)("svg",{width:"60",height:"60",viewBox:"0 0 60 60",fill:"none",style:{cursor:"pointer",position:"fixed",bottom:"20px",right:"20px",zIndex:9999,filter:"drop-shadow(0px 4px 12px rgba(0, 0, 0, 0.15))"},onClick:()=>l(!0),children:(0,e.jsxs)("g",{className:"chat-bubble",children:[(0,e.jsx)("ellipse",{cx:"30",cy:"52",rx:"15",ry:"3",fill:"#000",opacity:"0.1"}),(0,e.jsx)("path",{d:"M45 15C45 8.37258 39.6274 3 33 3H15C8.37258 3 3 8.37258 3 15V33C3 39.6274 8.37258 45 15 45H18V52L26 45H33C39.6274 45 45 39.6274 45 33V15Z",fill:"#4F46E5"}),(0,e.jsxs)("g",{transform:"translate(12, 14)",children:[(0,e.jsx)("line",{x1:"12",y1:"0",x2:"12",y2:"3",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"0",r:"1.5",fill:"white"}),(0,e.jsx)("rect",{x:"6",y:"3",width:"12",height:"10",rx:"2",fill:"white"}),(0,e.jsx)("circle",{className:"robot-eye",cx:"9.5",cy:"8",r:"1.5",fill:"#4F46E5"}),(0,e.jsx)("circle",{className:"robot-eye",cx:"14.5",cy:"8",r:"1.5",fill:"#4F46E5"}),(0,e.jsx)("line",{x1:"9",y1:"11",x2:"15",y2:"11",stroke:"#4F46E5",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("rect",{x:"7",y:"14",width:"10",height:"6",rx:"1",fill:"white"}),(0,e.jsx)("rect",{x:"4",y:"15",width:"2",height:"4",rx:"1",fill:"white"}),(0,e.jsx)("rect",{x:"18",y:"15",width:"2",height:"4",rx:"1",fill:"white"})]})]})}),n&&(0,e.jsxs)("div",{style:{position:"fixed",bottom:"20px",right:"20px",width:"min(400px, 90vw)",height:"min(600px, 85vh)",backgroundColor:"#fff",boxShadow:"0 12px 40px rgba(79, 70, 229, 0.25)",borderRadius:"16px",display:"flex",flexDirection:"column",zIndex:1e4,overflow:"hidden",border:"1px solid #e5e7eb",animation:"fadeIn 0.2s ease-out"},children:[(0,e.jsxs)("div",{style:{backgroundColor:"#4f46e5",padding:"14px 18px",display:"flex",alignItems:"center",justifyContent:"space-between",color:"#fff"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[(0,e.jsx)("div",{style:{width:"8px",height:"8px",backgroundColor:"#22c55e",borderRadius:"50%",boxShadow:"0 0 8px #22c55e"}}),(0,e.jsx)("span",{style:{fontWeight:600,fontSize:"15px"},children:r})]}),(0,e.jsx)("span",{style:{cursor:"pointer",fontSize:"18px",opacity:.8},onClick:()=>l(!1),children:"\u2715"})]}),(0,e.jsxs)("div",{ref:x,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"#f9fafb"},children:[d.map((t,c)=>(0,e.jsx)("div",{style:{alignSelf:t.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",flexDirection:"column",gap:"4px"},children:(0,e.jsxs)("div",{style:{backgroundColor:t.role==="user"?"#4f46e5":"#fff",color:t.role==="user"?"#fff":"#374151",padding:"12px 16px",borderRadius:"12px",fontSize:"14px",border:t.role==="user"?"none":"1px solid #e5e7eb",boxShadow:t.role==="user"?"0 2px 4px rgba(79,70,229,0.2)":"0 1px 2px rgba(0,0,0,0.05)"},children:[t.image&&(0,e.jsx)("div",{style:{marginBottom:"10px"},children:(0,e.jsx)("img",{src:t.image,onClick:()=>C(t.image),style:{width:"100%",borderRadius:"8px",cursor:"zoom-in"},alt:"Reference"})}),t.role==="assistant"?(0,e.jsx)("div",{className:"markdown-container",children:(0,e.jsx)(E.default,{children:t.content})}):(0,e.jsx)("div",{style:{whiteSpace:"pre-wrap"},children:t.content})]})},c)),(0,e.jsx)("div",{ref:x}),p&&(0,e.jsxs)("div",{style:{fontSize:"12px",color:"#6b7280",marginLeft:"4px"},children:[r," is thinking..."]})]}),(0,e.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb",backgroundColor:"#fff"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"10px",backgroundColor:"#f3f4f6",padding:"6px 14px",borderRadius:"28px"},children:[(0,e.jsxs)("button",{style:{background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex"},onClick:()=>I.current?.click(),children:[(0,e.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#9ca3af",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,e.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,e.jsx)("polyline",{points:"21 15 16 10 5 21"})]}),(0,e.jsx)("input",{type:"file",accept:"image/*",ref:I,style:{display:"none"},onChange:t=>{let c=t.target.files?.[0];c&&(v(c),g.toast.success(`Attached: ${c.name}`))}})]}),y&&(0,e.jsxs)("div",{style:{fontSize:"11px",color:"#4f46e5",maxWidth:"80px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["\u{1F4CE} ",y.name]}),(0,e.jsx)("input",{type:"text",value:i,onChange:t=>a(t.target.value),onKeyDown:t=>t.key==="Enter"&&S(),placeholder:"Type a message...",style:{flex:1,border:"none",background:"none",padding:"10px 0",outline:"none",fontSize:"14px",color:"#1f2937"}}),(0,e.jsx)("button",{onClick:S,disabled:!i.trim()||p,style:{background:i.trim()&&!p?"#4f46e5":"transparent",border:"none",borderRadius:"50%",width:"34px",height:"34px",display:"flex",alignItems:"center",justifyContent:"center",cursor:i.trim()&&!p?"pointer":"default",transition:"all 0.2s"},children:(0,e.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:i.trim()&&!p?"#fff":"#9ca3af",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,e.jsx)("polyline",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]}),(0,e.jsxs)("div",{style:{textAlign:"center",fontSize:"11px",color:"#9ca3af",marginTop:"10px"},children:["Powered by ",(0,e.jsx)("strong",{children:"DoclessAI"})]})]})]})]})}0&&(module.exports={ChatWidget,DoclessClient});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface AssistantResponse {
|
|
4
|
+
res: string;
|
|
5
|
+
image: string | null;
|
|
6
|
+
elementId: string | null;
|
|
7
|
+
route: string | null;
|
|
8
|
+
}
|
|
9
|
+
interface DoclessConfig {
|
|
10
|
+
appKey: string;
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
declare class DoclessClient {
|
|
15
|
+
private appKey;
|
|
16
|
+
private baseUrl;
|
|
17
|
+
private timeout;
|
|
18
|
+
constructor(config: DoclessConfig);
|
|
19
|
+
ask(query: string, file?: File): Promise<AssistantResponse>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare function ChatWidget({ name, appKey }: {
|
|
23
|
+
name?: string;
|
|
24
|
+
appKey: string;
|
|
25
|
+
}): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { type AssistantResponse, ChatWidget, DoclessClient, type DoclessConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface AssistantResponse {
|
|
4
|
+
res: string;
|
|
5
|
+
image: string | null;
|
|
6
|
+
elementId: string | null;
|
|
7
|
+
route: string | null;
|
|
8
|
+
}
|
|
9
|
+
interface DoclessConfig {
|
|
10
|
+
appKey: string;
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}
|
|
14
|
+
declare class DoclessClient {
|
|
15
|
+
private appKey;
|
|
16
|
+
private baseUrl;
|
|
17
|
+
private timeout;
|
|
18
|
+
constructor(config: DoclessConfig);
|
|
19
|
+
ask(query: string, file?: File): Promise<AssistantResponse>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare function ChatWidget({ name, appKey }: {
|
|
23
|
+
name?: string;
|
|
24
|
+
appKey: string;
|
|
25
|
+
}): react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
export { type AssistantResponse, ChatWidget, DoclessClient, type DoclessConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,b as t}from"./chunk-IPMERHAH.js";export{t as ChatWidget,e as DoclessClient};
|
package/dist/loader.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";var L=Object.create;var R=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var B=(i,o,n,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of K(o))!H.call(i,r)&&r!==n&&R(i,r,{get:()=>o[r],enumerable:!(l=F(o,r))||l.enumerable});return i};var y=(i,o,n)=>(n=i!=null?L(W(i)):{},B(o||!i||!i.__esModule?R(n,"default",{value:i,enumerable:!0}):n,i));var z=y(require("react"),1),M=y(require("react-dom/client"),1);var s=require("react");var m=class{appKey;baseUrl;timeout;constructor(o){this.appKey=o.appKey,this.baseUrl=o.baseUrl||"https://doclessai.vercel.app/api/v1",this.timeout=o.timeout||3e4}async ask(o,n){let l=new AbortController,r=setTimeout(()=>l.abort(),this.timeout);try{let a=new FormData;a.append("appKey",this.appKey),a.append("query",o),n&&a.append("image",n);let d=await fetch(`${this.baseUrl}/chat`,{method:"POST",signal:l.signal,headers:{"X-SDK-Name":"@doclessai/sdk","X-SDK-Version":"0.2.1"},body:a});if(clearTimeout(r),!d.ok){let g=await d.json().catch(()=>({}));throw new Error(g.message||`DoclessAI Request failed with status ${d.status}`)}return await d.json()}catch(a){throw clearTimeout(r),a instanceof Error&&a.name==="AbortError"?new Error("DoclessAI Error: Request timed out."):new Error(`DoclessAI Error: ${a instanceof Error?a.message:"Unknown error"}`)}}};var x=require("react-hot-toast"),E=y(require("react-markdown"),1),e=require("react/jsx-runtime");function b({name:i="Assistant",appKey:o}){let[n,l]=(0,s.useState)(!1),[r,a]=(0,s.useState)(""),[d,g]=(0,s.useState)([{role:"assistant",content:"Hello! How can I help you today?"}]),[c,w]=(0,s.useState)(!1),[h,v]=(0,s.useState)(null),[k,C]=(0,s.useState)(null),S=(0,s.useRef)(null),u=(0,s.useRef)(null),T=(0,s.useMemo)(()=>new m({appKey:o}),[o]);(0,s.useEffect)(()=>{u.current&&u.current.scrollTo({top:u.current.scrollHeight,behavior:"smooth"})},[d,c]);let I=async()=>{if(!r.trim()||c)return;let t=r.trim(),p=h;a(""),g(f=>[...f,{role:"user",content:t}]),w(!0);try{let f=await T.ask(t,p||void 0);v(null),g(A=>[...A,{role:"assistant",content:f.res,image:f.image}])}catch(f){x.toast.error(f?.message||"Something went wrong"),a(t)}finally{w(!1)}};return(0,e.jsxs)("div",{style:{fontFamily:"Inter, system-ui, sans-serif"},children:[(0,e.jsx)(x.Toaster,{position:"top-center",reverseOrder:!1}),(0,e.jsx)("style",{children:`
|
|
2
|
+
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-5px); } }
|
|
3
|
+
@keyframes blink { 0%, 90%, 100% { opacity: 1; } 95% { opacity: 0.3; } }
|
|
4
|
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
5
|
+
|
|
6
|
+
.chat-bubble { animation: float 2s ease-in-out infinite; }
|
|
7
|
+
.robot-eye { animation: blink 3s ease-in-out infinite; }
|
|
8
|
+
|
|
9
|
+
/* Markdown Styling */
|
|
10
|
+
.markdown-container p { margin: 0 0 12px 0; line-height: 1.5; }
|
|
11
|
+
.markdown-container p:last-child { margin-bottom: 0; }
|
|
12
|
+
.markdown-container ul, .markdown-container ol { margin: 10px 0; padding-left: 20px; }
|
|
13
|
+
.markdown-container li { margin-bottom: 6px; line-height: 1.4; }
|
|
14
|
+
.markdown-container strong { font-weight: 700; color: #111827; }
|
|
15
|
+
.markdown-container a { color: #4f46e5; text-decoration: underline; }
|
|
16
|
+
`}),k&&(0,e.jsxs)("div",{onClick:()=>C(null),style:{position:"fixed",inset:0,backgroundColor:"rgba(0,0,0,0.8)",backdropFilter:"blur(5px)",zIndex:2e4,display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out",padding:"20px"},children:[(0,e.jsx)("button",{style:{position:"absolute",top:"20px",right:"20px",background:"#fff",border:"none",borderRadius:"50%",width:"40px",height:"40px",cursor:"pointer",fontSize:"20px"},children:"\u2715"}),(0,e.jsx)("img",{src:k,style:{maxWidth:"100%",maxHeight:"90vh",borderRadius:"8px",boxShadow:"0 0 30px rgba(0,0,0,0.5)"},alt:"Zoomed reference"})]}),!n&&(0,e.jsx)("svg",{width:"60",height:"60",viewBox:"0 0 60 60",fill:"none",style:{cursor:"pointer",position:"fixed",bottom:"20px",right:"20px",zIndex:9999,filter:"drop-shadow(0px 4px 12px rgba(0, 0, 0, 0.15))"},onClick:()=>l(!0),children:(0,e.jsxs)("g",{className:"chat-bubble",children:[(0,e.jsx)("ellipse",{cx:"30",cy:"52",rx:"15",ry:"3",fill:"#000",opacity:"0.1"}),(0,e.jsx)("path",{d:"M45 15C45 8.37258 39.6274 3 33 3H15C8.37258 3 3 8.37258 3 15V33C3 39.6274 8.37258 45 15 45H18V52L26 45H33C39.6274 45 45 39.6274 45 33V15Z",fill:"#4F46E5"}),(0,e.jsxs)("g",{transform:"translate(12, 14)",children:[(0,e.jsx)("line",{x1:"12",y1:"0",x2:"12",y2:"3",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round"}),(0,e.jsx)("circle",{cx:"12",cy:"0",r:"1.5",fill:"white"}),(0,e.jsx)("rect",{x:"6",y:"3",width:"12",height:"10",rx:"2",fill:"white"}),(0,e.jsx)("circle",{className:"robot-eye",cx:"9.5",cy:"8",r:"1.5",fill:"#4F46E5"}),(0,e.jsx)("circle",{className:"robot-eye",cx:"14.5",cy:"8",r:"1.5",fill:"#4F46E5"}),(0,e.jsx)("line",{x1:"9",y1:"11",x2:"15",y2:"11",stroke:"#4F46E5",strokeWidth:"1",strokeLinecap:"round"}),(0,e.jsx)("rect",{x:"7",y:"14",width:"10",height:"6",rx:"1",fill:"white"}),(0,e.jsx)("rect",{x:"4",y:"15",width:"2",height:"4",rx:"1",fill:"white"}),(0,e.jsx)("rect",{x:"18",y:"15",width:"2",height:"4",rx:"1",fill:"white"})]})]})}),n&&(0,e.jsxs)("div",{style:{position:"fixed",bottom:"20px",right:"20px",width:"min(400px, 90vw)",height:"min(600px, 85vh)",backgroundColor:"#fff",boxShadow:"0 12px 40px rgba(79, 70, 229, 0.25)",borderRadius:"16px",display:"flex",flexDirection:"column",zIndex:1e4,overflow:"hidden",border:"1px solid #e5e7eb",animation:"fadeIn 0.2s ease-out"},children:[(0,e.jsxs)("div",{style:{backgroundColor:"#4f46e5",padding:"14px 18px",display:"flex",alignItems:"center",justifyContent:"space-between",color:"#fff"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[(0,e.jsx)("div",{style:{width:"8px",height:"8px",backgroundColor:"#22c55e",borderRadius:"50%",boxShadow:"0 0 8px #22c55e"}}),(0,e.jsx)("span",{style:{fontWeight:600,fontSize:"15px"},children:i})]}),(0,e.jsx)("span",{style:{cursor:"pointer",fontSize:"18px",opacity:.8},onClick:()=>l(!1),children:"\u2715"})]}),(0,e.jsxs)("div",{ref:u,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"#f9fafb"},children:[d.map((t,p)=>(0,e.jsx)("div",{style:{alignSelf:t.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",flexDirection:"column",gap:"4px"},children:(0,e.jsxs)("div",{style:{backgroundColor:t.role==="user"?"#4f46e5":"#fff",color:t.role==="user"?"#fff":"#374151",padding:"12px 16px",borderRadius:"12px",fontSize:"14px",border:t.role==="user"?"none":"1px solid #e5e7eb",boxShadow:t.role==="user"?"0 2px 4px rgba(79,70,229,0.2)":"0 1px 2px rgba(0,0,0,0.05)"},children:[t.image&&(0,e.jsx)("div",{style:{marginBottom:"10px"},children:(0,e.jsx)("img",{src:t.image,onClick:()=>C(t.image),style:{width:"100%",borderRadius:"8px",cursor:"zoom-in"},alt:"Reference"})}),t.role==="assistant"?(0,e.jsx)("div",{className:"markdown-container",children:(0,e.jsx)(E.default,{children:t.content})}):(0,e.jsx)("div",{style:{whiteSpace:"pre-wrap"},children:t.content})]})},p)),(0,e.jsx)("div",{ref:u}),c&&(0,e.jsxs)("div",{style:{fontSize:"12px",color:"#6b7280",marginLeft:"4px"},children:[i," is thinking..."]})]}),(0,e.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb",backgroundColor:"#fff"},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"10px",backgroundColor:"#f3f4f6",padding:"6px 14px",borderRadius:"28px"},children:[(0,e.jsxs)("button",{style:{background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex"},onClick:()=>S.current?.click(),children:[(0,e.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#9ca3af",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,e.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,e.jsx)("polyline",{points:"21 15 16 10 5 21"})]}),(0,e.jsx)("input",{type:"file",accept:"image/*",ref:S,style:{display:"none"},onChange:t=>{let p=t.target.files?.[0];p&&(v(p),x.toast.success(`Attached: ${p.name}`))}})]}),h&&(0,e.jsxs)("div",{style:{fontSize:"11px",color:"#4f46e5",maxWidth:"80px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["\u{1F4CE} ",h.name]}),(0,e.jsx)("input",{type:"text",value:r,onChange:t=>a(t.target.value),onKeyDown:t=>t.key==="Enter"&&I(),placeholder:"Type a message...",style:{flex:1,border:"none",background:"none",padding:"10px 0",outline:"none",fontSize:"14px",color:"#1f2937"}}),(0,e.jsx)("button",{onClick:I,disabled:!r.trim()||c,style:{background:r.trim()&&!c?"#4f46e5":"transparent",border:"none",borderRadius:"50%",width:"34px",height:"34px",display:"flex",alignItems:"center",justifyContent:"center",cursor:r.trim()&&!c?"pointer":"default",transition:"all 0.2s"},children:(0,e.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:r.trim()&&!c?"#fff":"#9ca3af",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,e.jsx)("polyline",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]}),(0,e.jsxs)("div",{style:{textAlign:"center",fontSize:"11px",color:"#9ca3af",marginTop:"10px"},children:["Powered by ",(0,e.jsx)("strong",{children:"DoclessAI"})]})]})]})]})}var D=()=>{let o=document.currentScript?.getAttribute("data-app-key")||"";if(!o)return;let n=document.createElement("div");n.id="docless-ai-root",document.body.appendChild(n),M.default.createRoot(n).render(z.default.createElement(b,{appKey:o}))};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",D):D();
|
package/dist/loader.d.ts
ADDED
package/dist/loader.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as o}from"./chunk-IPMERHAH.js";import n from"react";import d from"react-dom/client";var r=()=>{let e=document.currentScript?.getAttribute("data-app-key")||"";if(!e)return;let t=document.createElement("div");t.id="docless-ai-root",document.body.appendChild(t),d.createRoot(t).render(n.createElement(o,{appKey:e}))};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r):r();
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@doclessai/sdk",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Plug-and-play AI assistants infrastructure as a service.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"homepage": "https://doclessai.com",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/Dattatray8/doclessai-sdk.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Dattatray8/doclessai-sdk/issues"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./loader": "./dist/loader.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup src/index.ts src/loader.ts --format cjs,esm --dts --clean --minify",
|
|
30
|
+
"dev": "tsup src/index.ts src/loader.ts --format cjs,esm --watch --dts",
|
|
31
|
+
"lint": "tsc --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"ai",
|
|
35
|
+
"assistant",
|
|
36
|
+
"rag",
|
|
37
|
+
"gemini",
|
|
38
|
+
"doclessai"
|
|
39
|
+
],
|
|
40
|
+
"author": "Dattatray",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"react-hot-toast": "^2.6.0",
|
|
44
|
+
"react-markdown": "^10.1.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/react": "^19.2.13",
|
|
48
|
+
"@types/react-dom": "^19.2.3",
|
|
49
|
+
"tsup": "^8.0.0",
|
|
50
|
+
"typescript": "^5.0.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": ">=18",
|
|
54
|
+
"react-dom": ">=18"
|
|
55
|
+
}
|
|
56
|
+
}
|