@doclessai/sdk 0.3.0 → 0.3.2
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 +90 -0
- package/dist/{chunk-IPMERHAH.js → chunk-JDHWLRWB.js} +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -1
- package/dist/loader.cjs +2 -2
- package/dist/loader.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# DoclessAI SDK
|
|
2
|
+
|
|
3
|
+
Plug-and-play AI assistants infrastructure as a service. Seamlessly integrate intelligent AI-powered chat assistants into your applications.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@doclessai/sdk)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
**Homepage:** [doclessai.com](https://doclessai.vercel.app)
|
|
10
|
+
|
|
11
|
+
## 🚀 Features
|
|
12
|
+
|
|
13
|
+
- ✨ **Ready-to-use Chat Widget** - Drop-in React component for instant chat functionality
|
|
14
|
+
- 📄 **Media Upload Support** - Allow users to upload images for AI analysis
|
|
15
|
+
- 🎨 **Markdown Support** - Rich text responses with formatting
|
|
16
|
+
- 🔔 **Toast Notifications** - User-friendly feedback for errors and interactions
|
|
17
|
+
- 📱 **Responsive Design** - Works seamlessly on desktop and mobile
|
|
18
|
+
- 🎯 **Type-Safe** - Full TypeScript support with types included
|
|
19
|
+
- 🔧 **Flexible Client** - Use the DoclessClient directly for custom integrations
|
|
20
|
+
- 🌐 **Less Configuration** - Works out of the box with minimal setup
|
|
21
|
+
|
|
22
|
+
## 📦 Installation
|
|
23
|
+
|
|
24
|
+
Install the package using npm, yarn, or pnpm:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @doclessai/sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 🎯 Quick Start
|
|
31
|
+
|
|
32
|
+
### Using the Chat Widget (React)
|
|
33
|
+
|
|
34
|
+
The easiest way to add AI chat to your application:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { ChatWidget } from '@doclessai/sdk';
|
|
38
|
+
|
|
39
|
+
export default function App() {
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<h1>My App</h1>
|
|
43
|
+
<ChatWidget appKey="your-app-key-here" />
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Using the DoclessClient
|
|
50
|
+
|
|
51
|
+
For more control, use the client directly:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { DoclessClient } from '@doclessai/sdk';
|
|
55
|
+
|
|
56
|
+
const client = new DoclessClient({
|
|
57
|
+
appKey: 'your-app-key-here'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Ask a question
|
|
61
|
+
const response = await client.ask('user-query');
|
|
62
|
+
console.log(response.res);
|
|
63
|
+
|
|
64
|
+
// Ask with image attachment
|
|
65
|
+
const response = await client.ask('user-query',image);
|
|
66
|
+
console.log(response.res); // text response
|
|
67
|
+
console.log(response.image); // image url if returned
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 🔗 Resources
|
|
72
|
+
|
|
73
|
+
- **Homepage:** [doclessai.com](https://doclessai.vercel.app)
|
|
74
|
+
- **GitHub:** [github.com/Dattatray8/doclessai-sdk](https://github.com/Dattatray8/doclessai-sdk)
|
|
75
|
+
- **NPM Package:** [@doclessai/sdk](https://www.npmjs.com/package/@doclessai/sdk)
|
|
76
|
+
|
|
77
|
+
## 👥 Author
|
|
78
|
+
|
|
79
|
+
**Dattatray** - [GitHub Profile](https://github.com/Dattatray8)
|
|
80
|
+
|
|
81
|
+
## 🙏 Support
|
|
82
|
+
|
|
83
|
+
If you encounter any issues or have questions, please:
|
|
84
|
+
1. Check the [documentation](https://doclessai.vercel.app/get-started)
|
|
85
|
+
2. Search existing [issues](https://github.com/Dattatray8/doclessai-sdk/issues)
|
|
86
|
+
3. Create a new issue with detailed information
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
Built with ❤️ by the DoclessAI team.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var g=class{appKey;baseUrl;
|
|
1
|
+
var g=class{appKey;baseUrl;constructor(i){this.appKey=i.appKey,this.baseUrl=i.baseUrl||"https://doclessai.vercel.app/api/v1"}async ask(i,p){let f=new AbortController;try{let o=new FormData;o.append("appKey",this.appKey),o.append("query",i),p&&o.append("image",p);let n=await fetch(`${this.baseUrl}/chat`,{method:"POST",signal:f.signal,headers:{"X-SDK-Name":"@doclessai/sdk","X-SDK-Version":"0.3.1"},body:o});if(!n.ok){let x=await n.json().catch(()=>({}));throw new Error(x.message||`DoclessAI Request failed with status ${n.status}`)}return await n.json()}catch(o){throw o instanceof Error&&o.name==="AbortError"?new Error("DoclessAI Error: Request timed out."):new Error(`DoclessAI Error: ${o instanceof Error?o.message:"Unknown error"}`)}}};import{useState as d,useRef as I,useEffect as D,useMemo as z}from"react";import{toast as S,Toaster as A}from"react-hot-toast";import M from"react-markdown";import{jsx as e,jsxs as r}from"react/jsx-runtime";function F({name:u="Assistant",appKey:i}){let[p,f]=d(!1),[o,n]=d(""),[x,y]=d([{role:"assistant",content:"Hello! How can I help you today?"}]),[s,m]=d(!1),[h,b]=d(null),[w,v]=d(null),k=I(null),c=I(null),R=z(()=>new g({appKey:i}),[i]);D(()=>{c.current&&c.current.scrollTo({top:c.current.scrollHeight,behavior:"smooth"})},[x,s]);let C=async()=>{if(!o.trim()||s)return;let t=o.trim(),a=h;n(""),y(l=>[...l,{role:"user",content:t}]),m(!0);try{let l=await R.ask(t,a||void 0);b(null),y(E=>[...E,{role:"assistant",content:l.res,image:l.image}])}catch(l){S.error(l?.message||"Something went wrong"),n(t)}finally{m(!1)}};return r("div",{style:{fontFamily:"Inter, system-ui, sans-serif"},children:[e(A,{position:"top-center",reverseOrder:!1}),e("style",{children:`
|
|
2
2
|
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-5px); } }
|
|
3
3
|
@keyframes blink { 0%, 90%, 100% { opacity: 1; } 95% { opacity: 0.3; } }
|
|
4
4
|
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
@@ -13,4 +13,4 @@ var g=class{appKey;baseUrl;timeout;constructor(n){this.appKey=n.appKey,this.base
|
|
|
13
13
|
.markdown-container li { margin-bottom: 6px; line-height: 1.4; }
|
|
14
14
|
.markdown-container strong { font-weight: 700; color: #111827; }
|
|
15
15
|
.markdown-container a { color: #4f46e5; text-decoration: underline; }
|
|
16
|
-
`}),w&&
|
|
16
|
+
`}),w&&r("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"})]}),!p&&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:r("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"}),r("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"})]})]})}),p&&r("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:[r("div",{style:{backgroundColor:"#4f46e5",padding:"14px 18px",display:"flex",alignItems:"center",justifyContent:"space-between",color:"#fff"},children:[r("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:u})]}),e("span",{style:{cursor:"pointer",fontSize:"18px",opacity:.8},onClick:()=>f(!1),children:"\u2715"})]}),r("div",{ref:c,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"#f9fafb"},children:[x.map((t,a)=>e("div",{style:{alignSelf:t.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",flexDirection:"column",gap:"4px"},children:r("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(M,{children:t.content})}):e("div",{style:{whiteSpace:"pre-wrap"},children:t.content})]})},a)),e("div",{ref:c}),s&&r("div",{style:{fontSize:"12px",color:"#6b7280",marginLeft:"4px"},children:[u," is thinking..."]})]}),r("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb",backgroundColor:"#fff"},children:[r("div",{style:{display:"flex",alignItems:"center",gap:"10px",backgroundColor:"#f3f4f6",padding:"6px 14px",borderRadius:"28px"},children:[r("button",{style:{background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex"},onClick:()=>k.current?.click(),children:[r("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 a=t.target.files?.[0];a&&(b(a),S.success(`Attached: ${a.name}`))}})]}),h&&r("div",{style:{fontSize:"11px",color:"#4f46e5",maxWidth:"80px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["\u{1F4CE} ",h.name]}),e("input",{type:"text",value:o,onChange:t=>n(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:!o.trim()||s,style:{background:o.trim()&&!s?"#4f46e5":"transparent",border:"none",borderRadius:"50%",width:"34px",height:"34px",display:"flex",alignItems:"center",justifyContent:"center",cursor:o.trim()&&!s?"pointer":"default",transition:"all 0.2s"},children:r("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:o.trim()&&!s?"#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"})]})})]}),r("div",{style:{textAlign:"center",fontSize:"11px",color:"#9ca3af",marginTop:"10px"},children:["Powered by ",e("strong",{children:"DoclessAI"})]})]})]})]})}export{g as a,F as b};
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var A=Object.create;var h=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var W=(n,r)=>{for(var i in r)h(n,i,{get:r[i],enumerable:!0})},R=(n,r,i,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of F(r))!L.call(n,t)&&t!==i&&h(n,t,{get:()=>r[t],enumerable:!(l=M(r,t))||l.enumerable});return n};var H=(n,r,i)=>(i=n!=null?A(T(n)):{},R(r||!n||!n.__esModule?h(i,"default",{value:n,enumerable:!0}):i,n)),K=n=>R(h({},"__esModule",{value:!0}),n);var B={};W(B,{ChatWidget:()=>m,DoclessClient:()=>x});module.exports=K(B);var x=class{appKey;baseUrl;constructor(r){this.appKey=r.appKey,this.baseUrl=r.baseUrl||"https://doclessai.vercel.app/api/v1"}async ask(r,i){let l=new AbortController;try{let t=new FormData;t.append("appKey",this.appKey),t.append("query",r),i&&t.append("image",i);let a=await fetch(`${this.baseUrl}/chat`,{method:"POST",signal:l.signal,headers:{"X-SDK-Name":"@doclessai/sdk","X-SDK-Version":"0.3.1"},body:t});if(!a.ok){let u=await a.json().catch(()=>({}));throw new Error(u.message||`DoclessAI Request failed with status ${a.status}`)}return await a.json()}catch(t){throw t instanceof Error&&t.name==="AbortError"?new Error("DoclessAI Error: Request timed out."):new Error(`DoclessAI Error: ${t instanceof Error?t.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 m({name:n="Assistant",appKey:r}){let[i,l]=(0,s.useState)(!1),[t,a]=(0,s.useState)(""),[u,b]=(0,s.useState)([{role:"assistant",content:"Hello! How can I help you today?"}]),[d,w]=(0,s.useState)(!1),[y,v]=(0,s.useState)(null),[k,C]=(0,s.useState)(null),I=(0,s.useRef)(null),f=(0,s.useRef)(null),D=(0,s.useMemo)(()=>new x({appKey:r}),[r]);(0,s.useEffect)(()=>{f.current&&f.current.scrollTo({top:f.current.scrollHeight,behavior:"smooth"})},[u,d]);let S=async()=>{if(!t.trim()||d)return;let o=t.trim(),p=y;a(""),b(c=>[...c,{role:"user",content:o}]),w(!0);try{let c=await D.ask(o,p||void 0);v(null),b(z=>[...z,{role:"assistant",content:c.res,image:c.image}])}catch(c){g.toast.error(c?.message||"Something went wrong"),a(o)}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
2
|
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-5px); } }
|
|
3
3
|
@keyframes blink { 0%, 90%, 100% { opacity: 1; } 95% { opacity: 0.3; } }
|
|
4
4
|
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
.markdown-container li { margin-bottom: 6px; line-height: 1.4; }
|
|
14
14
|
.markdown-container strong { font-weight: 700; color: #111827; }
|
|
15
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"})]}),!
|
|
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"})]}),!i&&(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"})]})]})}),i&&(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:n})]}),(0,e.jsx)("span",{style:{cursor:"pointer",fontSize:"18px",opacity:.8},onClick:()=>l(!1),children:"\u2715"})]}),(0,e.jsxs)("div",{ref:f,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"#f9fafb"},children:[u.map((o,p)=>(0,e.jsx)("div",{style:{alignSelf:o.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",flexDirection:"column",gap:"4px"},children:(0,e.jsxs)("div",{style:{backgroundColor:o.role==="user"?"#4f46e5":"#fff",color:o.role==="user"?"#fff":"#374151",padding:"12px 16px",borderRadius:"12px",fontSize:"14px",border:o.role==="user"?"none":"1px solid #e5e7eb",boxShadow:o.role==="user"?"0 2px 4px rgba(79,70,229,0.2)":"0 1px 2px rgba(0,0,0,0.05)"},children:[o.image&&(0,e.jsx)("div",{style:{marginBottom:"10px"},children:(0,e.jsx)("img",{src:o.image,onClick:()=>C(o.image),style:{width:"100%",borderRadius:"8px",cursor:"zoom-in"},alt:"Reference"})}),o.role==="assistant"?(0,e.jsx)("div",{className:"markdown-container",children:(0,e.jsx)(E.default,{children:o.content})}):(0,e.jsx)("div",{style:{whiteSpace:"pre-wrap"},children:o.content})]})},p)),(0,e.jsx)("div",{ref:f}),d&&(0,e.jsxs)("div",{style:{fontSize:"12px",color:"#6b7280",marginLeft:"4px"},children:[n," 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:o=>{let p=o.target.files?.[0];p&&(v(p),g.toast.success(`Attached: ${p.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:t,onChange:o=>a(o.target.value),onKeyDown:o=>o.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:!t.trim()||d,style:{background:t.trim()&&!d?"#4f46e5":"transparent",border:"none",borderRadius:"50%",width:"34px",height:"34px",display:"flex",alignItems:"center",justifyContent:"center",cursor:t.trim()&&!d?"pointer":"default",transition:"all 0.2s"},children:(0,e.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:t.trim()&&!d?"#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
CHANGED
|
@@ -9,12 +9,10 @@ interface AssistantResponse {
|
|
|
9
9
|
interface DoclessConfig {
|
|
10
10
|
appKey: string;
|
|
11
11
|
baseUrl?: string;
|
|
12
|
-
timeout?: number;
|
|
13
12
|
}
|
|
14
13
|
declare class DoclessClient {
|
|
15
14
|
private appKey;
|
|
16
15
|
private baseUrl;
|
|
17
|
-
private timeout;
|
|
18
16
|
constructor(config: DoclessConfig);
|
|
19
17
|
ask(query: string, file?: File): Promise<AssistantResponse>;
|
|
20
18
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,10 @@ interface AssistantResponse {
|
|
|
9
9
|
interface DoclessConfig {
|
|
10
10
|
appKey: string;
|
|
11
11
|
baseUrl?: string;
|
|
12
|
-
timeout?: number;
|
|
13
12
|
}
|
|
14
13
|
declare class DoclessClient {
|
|
15
14
|
private appKey;
|
|
16
15
|
private baseUrl;
|
|
17
|
-
private timeout;
|
|
18
16
|
constructor(config: DoclessConfig);
|
|
19
17
|
ask(query: string, file?: File): Promise<AssistantResponse>;
|
|
20
18
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,b as t}from"./chunk-
|
|
1
|
+
import{a as e,b as t}from"./chunk-JDHWLRWB.js";export{t as ChatWidget,e as DoclessClient};
|
package/dist/loader.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var F=Object.create;var R=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var B=(n,r,i,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of K(r))!H.call(n,t)&&t!==i&&R(n,t,{get:()=>r[t],enumerable:!(a=T(r,t))||a.enumerable});return n};var h=(n,r,i)=>(i=n!=null?F(W(n)):{},B(r||!n||!n.__esModule?R(i,"default",{value:n,enumerable:!0}):i,n));var z=h(require("react"),1),M=h(require("react-dom/client"),1);var s=require("react");var u=class{appKey;baseUrl;constructor(r){this.appKey=r.appKey,this.baseUrl=r.baseUrl||"https://doclessai.vercel.app/api/v1"}async ask(r,i){let a=new AbortController;try{let t=new FormData;t.append("appKey",this.appKey),t.append("query",r),i&&t.append("image",i);let l=await fetch(`${this.baseUrl}/chat`,{method:"POST",signal:a.signal,headers:{"X-SDK-Name":"@doclessai/sdk","X-SDK-Version":"0.3.1"},body:t});if(!l.ok){let g=await l.json().catch(()=>({}));throw new Error(g.message||`DoclessAI Request failed with status ${l.status}`)}return await l.json()}catch(t){throw t instanceof Error&&t.name==="AbortError"?new Error("DoclessAI Error: Request timed out."):new Error(`DoclessAI Error: ${t instanceof Error?t.message:"Unknown error"}`)}}};var x=require("react-hot-toast"),E=h(require("react-markdown"),1),e=require("react/jsx-runtime");function y({name:n="Assistant",appKey:r}){let[i,a]=(0,s.useState)(!1),[t,l]=(0,s.useState)(""),[g,b]=(0,s.useState)([{role:"assistant",content:"Hello! How can I help you today?"}]),[d,w]=(0,s.useState)(!1),[m,v]=(0,s.useState)(null),[k,C]=(0,s.useState)(null),S=(0,s.useRef)(null),f=(0,s.useRef)(null),A=(0,s.useMemo)(()=>new u({appKey:r}),[r]);(0,s.useEffect)(()=>{f.current&&f.current.scrollTo({top:f.current.scrollHeight,behavior:"smooth"})},[g,d]);let I=async()=>{if(!t.trim()||d)return;let o=t.trim(),p=m;l(""),b(c=>[...c,{role:"user",content:o}]),w(!0);try{let c=await A.ask(o,p||void 0);v(null),b(L=>[...L,{role:"assistant",content:c.res,image:c.image}])}catch(c){x.toast.error(c?.message||"Something went wrong"),l(o)}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
2
|
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-5px); } }
|
|
3
3
|
@keyframes blink { 0%, 90%, 100% { opacity: 1; } 95% { opacity: 0.3; } }
|
|
4
4
|
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
.markdown-container li { margin-bottom: 6px; line-height: 1.4; }
|
|
14
14
|
.markdown-container strong { font-weight: 700; color: #111827; }
|
|
15
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"})]}),!
|
|
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"})]}),!i&&(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:()=>a(!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"})]})]})}),i&&(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:n})]}),(0,e.jsx)("span",{style:{cursor:"pointer",fontSize:"18px",opacity:.8},onClick:()=>a(!1),children:"\u2715"})]}),(0,e.jsxs)("div",{ref:f,style:{flex:1,overflowY:"auto",padding:"16px",display:"flex",flexDirection:"column",gap:"12px",backgroundColor:"#f9fafb"},children:[g.map((o,p)=>(0,e.jsx)("div",{style:{alignSelf:o.role==="user"?"flex-end":"flex-start",maxWidth:"85%",display:"flex",flexDirection:"column",gap:"4px"},children:(0,e.jsxs)("div",{style:{backgroundColor:o.role==="user"?"#4f46e5":"#fff",color:o.role==="user"?"#fff":"#374151",padding:"12px 16px",borderRadius:"12px",fontSize:"14px",border:o.role==="user"?"none":"1px solid #e5e7eb",boxShadow:o.role==="user"?"0 2px 4px rgba(79,70,229,0.2)":"0 1px 2px rgba(0,0,0,0.05)"},children:[o.image&&(0,e.jsx)("div",{style:{marginBottom:"10px"},children:(0,e.jsx)("img",{src:o.image,onClick:()=>C(o.image),style:{width:"100%",borderRadius:"8px",cursor:"zoom-in"},alt:"Reference"})}),o.role==="assistant"?(0,e.jsx)("div",{className:"markdown-container",children:(0,e.jsx)(E.default,{children:o.content})}):(0,e.jsx)("div",{style:{whiteSpace:"pre-wrap"},children:o.content})]})},p)),(0,e.jsx)("div",{ref:f}),d&&(0,e.jsxs)("div",{style:{fontSize:"12px",color:"#6b7280",marginLeft:"4px"},children:[n," 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:o=>{let p=o.target.files?.[0];p&&(v(p),x.toast.success(`Attached: ${p.name}`))}})]}),m&&(0,e.jsxs)("div",{style:{fontSize:"11px",color:"#4f46e5",maxWidth:"80px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["\u{1F4CE} ",m.name]}),(0,e.jsx)("input",{type:"text",value:t,onChange:o=>l(o.target.value),onKeyDown:o=>o.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:!t.trim()||d,style:{background:t.trim()&&!d?"#4f46e5":"transparent",border:"none",borderRadius:"50%",width:"34px",height:"34px",display:"flex",alignItems:"center",justifyContent:"center",cursor:t.trim()&&!d?"pointer":"default",transition:"all 0.2s"},children:(0,e.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:t.trim()&&!d?"#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 r=document.currentScript?.getAttribute("data-app-key")||"";if(!r)return;let i=document.createElement("div");i.id="docless-ai-root",document.body.appendChild(i),M.default.createRoot(i).render(z.default.createElement(y,{appKey:r}))};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",D):D();
|
package/dist/loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as o}from"./chunk-
|
|
1
|
+
import{b as o}from"./chunk-JDHWLRWB.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();
|