sagedesk 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Muhammad Zeeshan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/mzeeshanwahid/sagedesk/main/assets/cover.jpg" width="1200" alt="sagedesk cover" />
3
+ <h1 style="margin-top: 16px;">SageDesk</h1>
4
+ <p>Local RAG-powered support chat widget. No API key. No backend. No monthly cost. Semantic search runs entirely in the visitor's browser via WebAssembly.</p>
5
+ </div>
6
+
7
+ <br/>
8
+
9
+ <p align="center"><a href="https://www.npmjs.com/package/sagedesk"><img src="https://img.shields.io/npm/v/sagedesk?color=0ea5e9&label=npm" alt="npm version" /></a> <a href="https://bundlephobia.com/package/sagedesk"><img src="https://img.shields.io/bundlephobia/minzip/sagedesk?color=22c55e&label=gzipped" alt="bundle size" /></a> <a href="./LICENSE"><img src="https://img.shields.io/npm/l/sagedesk?color=a855f7" alt="license" /></a> <a href="https://github.com/mzeeshanwahid/sagedesk/actions"><img src="https://img.shields.io/github/actions/workflow/status/mzeeshanwahid/sagedesk/ci.yml?label=tests" alt="tests" /></a> <a href="./package.json"><img src="https://img.shields.io/badge/dependencies-zero-f97316" alt="zero dependencies" /></a> <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-5.x-3178c6" alt="TypeScript" /></a></p>
10
+
11
+ ---
12
+
13
+ ## How it works
14
+
15
+ 1. **Build time** - You run `npx sagedesk build` on your machine. It reads your `knowledge.json`, embeds every entry using a local transformer model (default: `all-MiniLM-L6-v2`), and writes a minified vector index to a static JSON file.
16
+ 2. **Runtime** - The widget fetches the index and loads the same model via WebAssembly. Visitor queries are embedded in-browser and matched against the index using optimized semantic search in under 100ms. **No API call is ever made.**
17
+
18
+ ---
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install sagedesk
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Step 1 - Write your knowledge file
29
+
30
+ Create `knowledge.json` at the root of your project.
31
+
32
+ ```json
33
+ {
34
+ "knowledge": [
35
+ {
36
+ "id": "about-1",
37
+ "queries": [
38
+ "Who built this site?",
39
+ "Who is the developer?",
40
+ "Tell me about the author"
41
+ ],
42
+ "answer": "This site was built by Jane Doe, a full-stack developer specialising in React and Node.js."
43
+ },
44
+ {
45
+ "id": "services-1",
46
+ "question": "What services do you offer?",
47
+ "answer": "We offer web development, API design, and technical consulting."
48
+ }
49
+ ]
50
+ }
51
+ ```
52
+
53
+ ### Knowledge Schema
54
+
55
+ | Field | Type | Required | Description |
56
+ |---|:---:|:---:|:---:|
57
+ | `knowledge[].id` | `string` | yes | Unique identifier for the entry. |
58
+ | `knowledge[].queries` | `string[]` | no | **Recommended.** Multiple phrasings for better matching. |
59
+ | `knowledge[].question` | `string` | no | Legacy single-question field. |
60
+ | `knowledge[].answer` | `string` | yes | The answer text shown to visitors. |
61
+
62
+ ---
63
+
64
+ ## Step 2 - Build the index
65
+
66
+ ```bash
67
+ npx sagedesk build --input knowledge.json --output public/support-index.json
68
+ ```
69
+
70
+ This generates the vector index. Run this whenever your knowledge file changes.
71
+
72
+ ### CLI Options
73
+
74
+ | Option | Description | Default |
75
+ |---|:---:|:---:|
76
+ | `-i, --input <path>` | Path to knowledge JSON (Required) | - |
77
+ | `-o, --output <path>` | Output path for index JSON | `./public/support-index.json` |
78
+ | `--model <name>` | Embedding model to use | `all-MiniLM-L6-v2` |
79
+ | `--minScore <number>` | Confidence threshold (0.0 to 1.0) | `0.42` |
80
+ | `--verbose` | Print chunk details during build | `false` |
81
+
82
+ ---
83
+
84
+ ## Step 3 - Add the widget
85
+
86
+ ### Vanilla HTML / JS
87
+
88
+ ```html
89
+ <script type="module">
90
+ import { init } from 'https://esm.sh/sagedesk';
91
+
92
+ init({
93
+ indexUrl: '/support-index.json',
94
+ agent: {
95
+ name: 'Support',
96
+ greeting: 'Hey! How can I help you today?',
97
+ accentColor: '#534AB7',
98
+ theme: 'classic'
99
+ }
100
+ });
101
+ </script>
102
+ ```
103
+
104
+ ### React
105
+
106
+ ```tsx
107
+ import { SageDeskWidget } from 'sagedesk/react';
108
+
109
+ export default function App() {
110
+ return (
111
+ <SageDeskWidget
112
+ indexUrl="/support-index.json"
113
+ agent={{
114
+ name: 'Support',
115
+ accentColor: '#534AB7',
116
+ theme: 'light'
117
+ }}
118
+ />
119
+ );
120
+ }
121
+ ```
122
+
123
+ ### Next.js (App Router)
124
+
125
+ Place in your root layout for site-wide availability.
126
+
127
+ ```tsx
128
+ // app/layout.tsx
129
+ import { SageDeskNext } from 'sagedesk/next';
130
+
131
+ export default function RootLayout({ children }) {
132
+ return (
133
+ <html lang="en">
134
+ <body>
135
+ {children}
136
+ <SageDeskNext
137
+ indexUrl="/support-index.json"
138
+ agent={{
139
+ name: 'Support',
140
+ theme: 'dark'
141
+ }}
142
+ />
143
+ </body>
144
+ </html>
145
+ );
146
+ }
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Configuration (`AgentConfig`)
152
+
153
+ | Field | Type | Default | Description |
154
+ |---|:---:|:---:|:---:|
155
+ | `name` | `string` | **Required** | Display name in the chat header. |
156
+ | `theme` | `classic`, `light`, `dark` | `classic` | Visual style of the widget. |
157
+ | `model` | `string` | `all-MiniLM-L6-v2` | **Must match build-time model.** |
158
+ | `accentColor` | `string` | `#534AB7` | Hex color for primary UI elements. |
159
+ | `greeting` | `string` | - | Initial message shown to visitors. |
160
+ | `fallback` | `string` | - | Message shown when no match is found. |
161
+ | `position` | `bottom-right`, `bottom-left` | `bottom-right` | Widget placement. |
162
+ | `avatarUrl` | `string` | - | Optional URL for the agent's avatar. |
163
+ | `contactUrl` | `string` | - | Link shown in fallback responses. |
164
+ | `poweredBy` | `boolean` | `true` | Show "Powered by sagedesk" footer. |
165
+ | `suggestedChips` | `string[]` | - | Override auto-generated suggested questions. |
166
+
167
+ ---
168
+
169
+ ## Model Selection
170
+
171
+ sagedesk defaults to `all-MiniLM-L6-v2` (~22MB), which offers an excellent balance of speed and quality for English.
172
+
173
+ | Model | Dimensions | Size | Best For |
174
+ |---|:---:|:---:|:---:|
175
+ | `all-MiniLM-L6-v2` | 384 | ~22 MB | Most English sites. |
176
+ | `bge-small-en-v1-5` | 384 | ~25 MB | High-precision English. |
177
+ | `paraphrase-multilingual-MiniLM-L12-v2` | 384 | ~45 MB | 50+ languages. |
178
+ | `all-mpnet-base-v2` | 768 | ~85 MB | Maximum semantic quality. |
179
+
180
+ > **Note:** The model used in `npx sagedesk build --model <name>` must match the `agent.model` property in your runtime configuration.
181
+
182
+ ---
183
+
184
+ ## Browser Support
185
+
186
+ Requires **WebAssembly** support.
187
+
188
+ - Chrome 90+
189
+ - Firefox 89+
190
+ - Safari 15+
191
+ - Edge 90+
192
+
193
+ The widget degrades gracefully by hiding itself on unsupported browsers.
194
+
195
+ ---
196
+
197
+ ## License
198
+
199
+ MIT