@savantoai/ai-sdk 2.1.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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 Savanto
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.
22
+
package/README.md ADDED
@@ -0,0 +1,280 @@
1
+ # @savantoai/ai-sdk
2
+
3
+ Official JavaScript/TypeScript SDK for [Savanto](https://savanto.ai) — AI-powered search, chat, recommendations, and knowledge base management.
4
+
5
+ Auto-generated from the [Savanto OpenAPI spec](https://savanto.ai/docs/api). Every endpoint is fully typed with zero manual maintenance.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @savantoai/ai-sdk
11
+ ```
12
+
13
+ Requires **Node.js >= 18** (uses native `fetch`). Works in modern browsers with no polyfills.
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { createClient, searchProducts, chat } from '@savantoai/ai-sdk';
19
+
20
+ const client = createClient({
21
+ baseUrl: 'https://api.savanto.ai',
22
+ auth: 'if_sk_...',
23
+ });
24
+
25
+ // Search products
26
+ const { data } = await searchProducts({
27
+ client,
28
+ body: { query: 'blue running shoes', limit: 10 },
29
+ });
30
+ console.log(data);
31
+
32
+ // AI chat
33
+ const { data: chatResponse } = await chat({
34
+ client,
35
+ body: { message: 'What shoes do you recommend?', threadId: 'thread-1' },
36
+ });
37
+ ```
38
+
39
+ ## Authentication
40
+
41
+ Pass your API key via the `auth` option on the client:
42
+
43
+ ```typescript
44
+ const client = createClient({
45
+ baseUrl: 'https://api.savanto.ai',
46
+ auth: 'if_sk_...',
47
+ });
48
+ ```
49
+
50
+ The client automatically sends it as `Authorization: Bearer <key>` on every request.
51
+
52
+ | Key Type | Prefix | Use |
53
+ |----------|--------|-----|
54
+ | **Secret** | `if_sk_` | Server-side only. Full access to all endpoints. |
55
+ | **Publishable** | `if_pk_` | Safe for client-side. Limited to search, chat, feedback, and prompts. |
56
+
57
+ ## Examples
58
+
59
+ ### Products
60
+
61
+ ```typescript
62
+ import {
63
+ searchProducts,
64
+ upsertProduct,
65
+ getProduct,
66
+ deleteProduct,
67
+ bulkUpsertProducts,
68
+ bulkDeleteProducts,
69
+ listProductIds,
70
+ } from '@savantoai/ai-sdk';
71
+
72
+ // Search
73
+ const { data } = await searchProducts({
74
+ client,
75
+ body: { query: 'warm jacket', limit: 10 },
76
+ });
77
+
78
+ // Upsert
79
+ await upsertProduct({
80
+ client,
81
+ body: { id: 'prod-1', name: 'Running Shoe', price: 99.99 },
82
+ });
83
+
84
+ // Get / Delete
85
+ const { data: product } = await getProduct({ client, path: { id: 'prod-1' } });
86
+ await deleteProduct({ client, path: { id: 'prod-1' } });
87
+
88
+ // Bulk operations
89
+ await bulkUpsertProducts({
90
+ client,
91
+ body: { items: [{ id: 'p1', name: 'Shoe' }, { id: 'p2', name: 'Boot' }] },
92
+ });
93
+ await bulkDeleteProducts({ client, body: { ids: ['p1', 'p2'] } });
94
+
95
+ // List IDs
96
+ const { data: ids } = await listProductIds({ client });
97
+ ```
98
+
99
+ ### Chat
100
+
101
+ ```typescript
102
+ import { chat } from '@savantoai/ai-sdk';
103
+
104
+ const { data, response } = await chat({
105
+ client,
106
+ body: {
107
+ message: 'What is your return policy?',
108
+ threadId: 'thread-1',
109
+ stream: true,
110
+ },
111
+ });
112
+
113
+ // For streaming (NDJSON), read the response body directly:
114
+ const reader = response.body!.getReader();
115
+ const decoder = new TextDecoder();
116
+
117
+ while (true) {
118
+ const { done, value } = await reader.read();
119
+ if (done) break;
120
+ const lines = decoder.decode(value).split('\n').filter(Boolean);
121
+ for (const line of lines) {
122
+ const chunk = JSON.parse(line);
123
+ if (chunk.type === 'text_delta') process.stdout.write(chunk.data);
124
+ }
125
+ }
126
+ ```
127
+
128
+ ### Posts
129
+
130
+ Same pattern as products — `upsertPost`, `searchPosts`, `getPost`, `deletePost`, `bulkUpsertPosts`, `bulkDeletePosts`, `listPostIds`.
131
+
132
+ ```typescript
133
+ import { searchPosts, upsertPost } from '@savantoai/ai-sdk';
134
+
135
+ await upsertPost({
136
+ client,
137
+ body: { id: 'post-1', title: 'Return Policy', content: '...' },
138
+ });
139
+
140
+ const { data } = await searchPosts({
141
+ client,
142
+ body: { query: 'shipping policy' },
143
+ });
144
+ ```
145
+
146
+ ### Feedback
147
+
148
+ ```typescript
149
+ import { submitFeedback, listFeedback } from '@savantoai/ai-sdk';
150
+
151
+ // Submit (publishable key safe)
152
+ await submitFeedback({
153
+ client,
154
+ body: { threadId: 'thread-1', messageIndex: 0, rating: 5, comment: 'Helpful!' },
155
+ });
156
+
157
+ // List (secret key)
158
+ const { data } = await listFeedback({ client });
159
+ ```
160
+
161
+ ### Threads
162
+
163
+ ```typescript
164
+ import { searchThreads, getThreadMessages, deleteThread } from '@savantoai/ai-sdk';
165
+
166
+ const { data } = await searchThreads({
167
+ client,
168
+ body: { query: 'returns' },
169
+ });
170
+
171
+ const { data: messages } = await getThreadMessages({ client, path: { id: 'thread-1' } });
172
+ await deleteThread({ client, path: { id: 'thread-1' } });
173
+ ```
174
+
175
+ ### Webhooks
176
+
177
+ ```typescript
178
+ import { createWebhook, listWebhooks, testWebhook } from '@savantoai/ai-sdk';
179
+
180
+ await createWebhook({
181
+ client,
182
+ body: { name: 'Inventory sync', url: 'https://example.com/hook', events: ['product.upsert'] },
183
+ });
184
+
185
+ const { data } = await listWebhooks({ client });
186
+ const { data: result } = await testWebhook({ client, path: { id: 'webhook-1' } });
187
+ ```
188
+
189
+ ### Recommendations
190
+
191
+ ```typescript
192
+ import { getProductRecommendations } from '@savantoai/ai-sdk';
193
+
194
+ const { data } = await getProductRecommendations({
195
+ client,
196
+ body: { productId: 'prod-1', maxRecommendations: 5 },
197
+ });
198
+ ```
199
+
200
+ ### Crawl & Scrape
201
+
202
+ ```typescript
203
+ import { startCrawl, getCrawlStatus, scrapePage } from '@savantoai/ai-sdk';
204
+
205
+ await startCrawl({ client, body: { url: 'https://mystore.com' } });
206
+ const { data } = await getCrawlStatus({ client, path: { id: 'crawl-abc' } });
207
+ await scrapePage({ client, body: { url: 'https://mystore.com/about' } });
208
+ ```
209
+
210
+ ## Response Format
211
+
212
+ Every function returns `{ data, error, response }`:
213
+
214
+ ```typescript
215
+ const result = await searchProducts({ client, body: { query: 'shoes' } });
216
+
217
+ if (result.error) {
218
+ // Typed error: { error: { message: string, code: string } }
219
+ console.error(result.error);
220
+ } else {
221
+ console.log(result.data);
222
+ }
223
+ ```
224
+
225
+ To throw on errors instead of returning them:
226
+
227
+ ```typescript
228
+ const { data } = await searchProducts({
229
+ client,
230
+ body: { query: 'shoes' },
231
+ throwOnError: true,
232
+ });
233
+ ```
234
+
235
+ ## TypeScript
236
+
237
+ All types are exported:
238
+
239
+ ```typescript
240
+ import type {
241
+ Product,
242
+ ProductInput,
243
+ ProductSearchRequest,
244
+ Post,
245
+ ChatRequest,
246
+ ChatStreamChunk,
247
+ Taxonomy,
248
+ Prompt,
249
+ FeedbackSubmission,
250
+ ErrorResponse,
251
+ } from '@savantoai/ai-sdk';
252
+ ```
253
+
254
+ ## Utilities
255
+
256
+ ```typescript
257
+ import { workspaceIdFromUrl } from '@savantoai/ai-sdk';
258
+
259
+ workspaceIdFromUrl('https://mystore.com'); // 'mystore-com'
260
+ workspaceIdFromUrl('my-store.myshopify.com'); // 'my-store-myshopify-com'
261
+ ```
262
+
263
+ ## API Reference
264
+
265
+ Full endpoint documentation with request/response schemas:
266
+
267
+ **[savanto.ai/docs/api](https://savanto.ai/docs/api)**
268
+
269
+ ## Regeneration
270
+
271
+ The SDK is auto-generated from the OpenAPI spec. To regenerate after API changes:
272
+
273
+ ```bash
274
+ cd cloud && npm run openapi # extract spec to cloud/openapi.json
275
+ cd sdks/javascript && npm run generate # regenerate src/generated/
276
+ ```
277
+
278
+ ## License
279
+
280
+ MIT