@orchata-ai/sdk 0.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 +22 -0
- package/README.md +420 -0
- package/dist/ai.cjs +266 -0
- package/dist/ai.cjs.map +1 -0
- package/dist/ai.d.cts +95 -0
- package/dist/ai.d.ts +95 -0
- package/dist/ai.js +263 -0
- package/dist/ai.js.map +1 -0
- package/dist/client-Bs_xoN9p.d.cts +752 -0
- package/dist/client-Bs_xoN9p.d.ts +752 -0
- package/dist/index.cjs +704 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +688 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-agnostic HTTP client using native fetch
|
|
3
|
+
*/
|
|
4
|
+
interface FetchClientConfig {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
apiKey: string;
|
|
7
|
+
timeout: number;
|
|
8
|
+
fetch: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
type HttpMethod = "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
11
|
+
interface RequestOptions {
|
|
12
|
+
method?: HttpMethod;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Low-level HTTP client for making API requests.
|
|
20
|
+
* Uses native fetch for cross-runtime compatibility.
|
|
21
|
+
*/
|
|
22
|
+
declare class FetchClient {
|
|
23
|
+
private readonly config;
|
|
24
|
+
constructor(config: FetchClientConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Make an HTTP request to the API.
|
|
27
|
+
*/
|
|
28
|
+
request<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Make a GET request.
|
|
31
|
+
*/
|
|
32
|
+
get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Make a POST request.
|
|
35
|
+
*/
|
|
36
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Make a PATCH request.
|
|
39
|
+
*/
|
|
40
|
+
patch<T>(path: string, body?: unknown): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Make a DELETE request.
|
|
43
|
+
*/
|
|
44
|
+
delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Make a multipart/form-data POST request.
|
|
47
|
+
*/
|
|
48
|
+
postFormData<T>(path: string, formData: FormData): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Build the full URL with query parameters.
|
|
51
|
+
*/
|
|
52
|
+
private buildUrl;
|
|
53
|
+
/**
|
|
54
|
+
* Handle error responses from the API.
|
|
55
|
+
*/
|
|
56
|
+
private handleErrorResponse;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Orchata SDK Types
|
|
61
|
+
*
|
|
62
|
+
* These types can be regenerated from the OpenAPI spec using:
|
|
63
|
+
* bun run generate-types
|
|
64
|
+
*/
|
|
65
|
+
type LucideIcon = "folder" | "book" | "file-text" | "database" | "package" | "archive" | "briefcase" | "inbox" | "layers" | "box";
|
|
66
|
+
type DocumentStatus = "PENDING" | "PROCESSING" | "COMPLETED" | "FAILED";
|
|
67
|
+
type SpaceStatus = "active" | "archived" | "all";
|
|
68
|
+
type RelevanceMethod = "keyword" | "embedding" | "hybrid";
|
|
69
|
+
type MatchReason = "keyword_match" | "embedding_similarity" | "both";
|
|
70
|
+
interface Space {
|
|
71
|
+
id: string;
|
|
72
|
+
orgId: string;
|
|
73
|
+
name: string;
|
|
74
|
+
slug: string;
|
|
75
|
+
icon: LucideIcon;
|
|
76
|
+
description: string;
|
|
77
|
+
isArchived: boolean;
|
|
78
|
+
archivedAt: string | null;
|
|
79
|
+
createdAt: string;
|
|
80
|
+
updatedAt: string;
|
|
81
|
+
}
|
|
82
|
+
interface CreateSpaceParams {
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
icon: LucideIcon;
|
|
86
|
+
}
|
|
87
|
+
interface UpdateSpaceParams {
|
|
88
|
+
name?: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
icon?: LucideIcon;
|
|
91
|
+
slug?: string;
|
|
92
|
+
isArchived?: boolean;
|
|
93
|
+
}
|
|
94
|
+
interface ListSpacesParams {
|
|
95
|
+
page?: number;
|
|
96
|
+
pageSize?: number;
|
|
97
|
+
status?: SpaceStatus;
|
|
98
|
+
}
|
|
99
|
+
interface ListSpacesResponse {
|
|
100
|
+
spaces: Space[];
|
|
101
|
+
total: number;
|
|
102
|
+
page: number;
|
|
103
|
+
pageSize: number;
|
|
104
|
+
totalPages: number;
|
|
105
|
+
}
|
|
106
|
+
interface SpaceResponse {
|
|
107
|
+
space: Space;
|
|
108
|
+
}
|
|
109
|
+
interface Document {
|
|
110
|
+
id: string;
|
|
111
|
+
orgId: string;
|
|
112
|
+
spaceId: string;
|
|
113
|
+
filename: string;
|
|
114
|
+
mimeType: string;
|
|
115
|
+
fileSize: string;
|
|
116
|
+
storageUrl: string;
|
|
117
|
+
status: DocumentStatus;
|
|
118
|
+
errorMessage: string | null;
|
|
119
|
+
embeddingModel: string;
|
|
120
|
+
metadata: Record<string, unknown>;
|
|
121
|
+
createdAt: string;
|
|
122
|
+
updatedAt: string;
|
|
123
|
+
}
|
|
124
|
+
interface UploadDocumentParams {
|
|
125
|
+
spaceId: string;
|
|
126
|
+
content: string;
|
|
127
|
+
filename?: string;
|
|
128
|
+
embeddingModel?: string;
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
interface UploadDocumentFileParams {
|
|
132
|
+
spaceId: string;
|
|
133
|
+
file: File | Blob;
|
|
134
|
+
filename?: string;
|
|
135
|
+
embeddingModel?: string;
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
137
|
+
}
|
|
138
|
+
interface BatchDocumentItem {
|
|
139
|
+
filename: string;
|
|
140
|
+
content: string;
|
|
141
|
+
metadata?: Record<string, unknown>;
|
|
142
|
+
}
|
|
143
|
+
interface BatchUploadParams {
|
|
144
|
+
spaceId: string;
|
|
145
|
+
documents: BatchDocumentItem[];
|
|
146
|
+
}
|
|
147
|
+
interface BatchUploadResponse {
|
|
148
|
+
successful: Array<{
|
|
149
|
+
filename: string;
|
|
150
|
+
documentId: string;
|
|
151
|
+
status: string;
|
|
152
|
+
}>;
|
|
153
|
+
failed: Array<{
|
|
154
|
+
filename: string;
|
|
155
|
+
error: string;
|
|
156
|
+
}>;
|
|
157
|
+
totalSuccessful: number;
|
|
158
|
+
totalFailed: number;
|
|
159
|
+
}
|
|
160
|
+
interface UpdateDocumentParams {
|
|
161
|
+
spaceId: string;
|
|
162
|
+
status?: DocumentStatus;
|
|
163
|
+
errorMessage?: string | null;
|
|
164
|
+
metadata?: Record<string, unknown>;
|
|
165
|
+
}
|
|
166
|
+
interface ListDocumentsParams {
|
|
167
|
+
spaceId: string;
|
|
168
|
+
page?: number;
|
|
169
|
+
pageSize?: number;
|
|
170
|
+
status?: DocumentStatus;
|
|
171
|
+
}
|
|
172
|
+
interface ListDocumentsResponse {
|
|
173
|
+
documents: Document[];
|
|
174
|
+
total: number;
|
|
175
|
+
page: number;
|
|
176
|
+
pageSize: number;
|
|
177
|
+
totalPages: number;
|
|
178
|
+
}
|
|
179
|
+
interface DocumentResponse {
|
|
180
|
+
document: Document;
|
|
181
|
+
}
|
|
182
|
+
interface DocumentContentResponse {
|
|
183
|
+
id: string;
|
|
184
|
+
filename: string;
|
|
185
|
+
content: string;
|
|
186
|
+
}
|
|
187
|
+
interface QueryParams {
|
|
188
|
+
query: string;
|
|
189
|
+
spaceIds: string | string[];
|
|
190
|
+
topK?: number;
|
|
191
|
+
threshold?: number;
|
|
192
|
+
metadata?: Record<string, unknown>;
|
|
193
|
+
groupBySpace?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface QueryResultChunk {
|
|
196
|
+
id: string;
|
|
197
|
+
content: string;
|
|
198
|
+
chunkIndex: number;
|
|
199
|
+
}
|
|
200
|
+
interface QueryResultDocument {
|
|
201
|
+
id: string;
|
|
202
|
+
filename: string;
|
|
203
|
+
metadata: Record<string, unknown>;
|
|
204
|
+
}
|
|
205
|
+
interface QueryResultSpace {
|
|
206
|
+
id: string;
|
|
207
|
+
name: string;
|
|
208
|
+
description: string;
|
|
209
|
+
}
|
|
210
|
+
interface QueryResultItem {
|
|
211
|
+
chunk: QueryResultChunk;
|
|
212
|
+
document: QueryResultDocument;
|
|
213
|
+
space: QueryResultSpace;
|
|
214
|
+
similarity: number;
|
|
215
|
+
metadata: Record<string, unknown>;
|
|
216
|
+
}
|
|
217
|
+
interface QueryResponse {
|
|
218
|
+
results: QueryResultItem[];
|
|
219
|
+
totalResults: number;
|
|
220
|
+
groupedBySpace?: Record<string, {
|
|
221
|
+
space: QueryResultSpace;
|
|
222
|
+
chunks: QueryResultItem[];
|
|
223
|
+
totalMatches: number;
|
|
224
|
+
}>;
|
|
225
|
+
}
|
|
226
|
+
interface SmartQueryParams {
|
|
227
|
+
query: string;
|
|
228
|
+
maxSpaces?: number;
|
|
229
|
+
relevanceMethod?: RelevanceMethod;
|
|
230
|
+
keywordWeight?: number;
|
|
231
|
+
}
|
|
232
|
+
interface SmartQueryResultSpace {
|
|
233
|
+
space: QueryResultSpace;
|
|
234
|
+
relevanceScore: number;
|
|
235
|
+
matchReason: MatchReason;
|
|
236
|
+
}
|
|
237
|
+
interface SmartQueryResponse {
|
|
238
|
+
relevantSpaces: SmartQueryResultSpace[];
|
|
239
|
+
totalSpaces: number;
|
|
240
|
+
}
|
|
241
|
+
interface DeleteResponse {
|
|
242
|
+
success: boolean;
|
|
243
|
+
message: string;
|
|
244
|
+
}
|
|
245
|
+
interface OrchataConfig {
|
|
246
|
+
/**
|
|
247
|
+
* Your Orchata API key.
|
|
248
|
+
* Can be obtained from the Orchata dashboard.
|
|
249
|
+
*/
|
|
250
|
+
apiKey: string;
|
|
251
|
+
/**
|
|
252
|
+
* Base URL for the Orchata API.
|
|
253
|
+
* @default "https://api.orchata.ai"
|
|
254
|
+
*/
|
|
255
|
+
baseUrl?: string;
|
|
256
|
+
/**
|
|
257
|
+
* Request timeout in milliseconds.
|
|
258
|
+
* @default 30000
|
|
259
|
+
*/
|
|
260
|
+
timeout?: number;
|
|
261
|
+
/**
|
|
262
|
+
* Custom fetch implementation.
|
|
263
|
+
* Useful for testing or custom HTTP handling.
|
|
264
|
+
*/
|
|
265
|
+
fetch?: typeof fetch;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Documents Resource
|
|
270
|
+
*
|
|
271
|
+
* Manage documents within spaces in Orchata.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Documents API resource.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* // List documents in a space
|
|
280
|
+
* const { documents } = await client.documents.list({ spaceId: 'space_123' });
|
|
281
|
+
*
|
|
282
|
+
* // Upload a document with raw content
|
|
283
|
+
* const { document } = await client.documents.upload({
|
|
284
|
+
* spaceId: 'space_123',
|
|
285
|
+
* content: '# My Document\n\nContent here...',
|
|
286
|
+
* filename: 'my-doc.md'
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* // Upload a file (browser only)
|
|
290
|
+
* const { document } = await client.documents.uploadFile({
|
|
291
|
+
* spaceId: 'space_123',
|
|
292
|
+
* file: fileInput.files[0]
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* // Get processed content
|
|
296
|
+
* const { content } = await client.documents.getContent('doc_123', 'space_123');
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
declare class Documents {
|
|
300
|
+
private readonly client;
|
|
301
|
+
constructor(client: FetchClient);
|
|
302
|
+
/**
|
|
303
|
+
* List documents in a space.
|
|
304
|
+
*
|
|
305
|
+
* @param params - Query parameters including spaceId
|
|
306
|
+
* @returns Paginated list of documents
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* // List all documents
|
|
311
|
+
* const { documents, total } = await client.documents.list({
|
|
312
|
+
* spaceId: 'space_123'
|
|
313
|
+
* });
|
|
314
|
+
*
|
|
315
|
+
* // Filter by status
|
|
316
|
+
* const { documents } = await client.documents.list({
|
|
317
|
+
* spaceId: 'space_123',
|
|
318
|
+
* status: 'COMPLETED'
|
|
319
|
+
* });
|
|
320
|
+
*
|
|
321
|
+
* // Paginate
|
|
322
|
+
* const { documents, totalPages } = await client.documents.list({
|
|
323
|
+
* spaceId: 'space_123',
|
|
324
|
+
* page: 2,
|
|
325
|
+
* pageSize: 10
|
|
326
|
+
* });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
list(params: ListDocumentsParams): Promise<ListDocumentsResponse>;
|
|
330
|
+
/**
|
|
331
|
+
* Get a specific document by ID.
|
|
332
|
+
*
|
|
333
|
+
* @param id - The document ID
|
|
334
|
+
* @param spaceId - The space ID containing the document
|
|
335
|
+
* @returns The document
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const { document } = await client.documents.get('doc_123', 'space_123');
|
|
340
|
+
* console.log(document.filename, document.status);
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
get(id: string, spaceId: string): Promise<DocumentResponse>;
|
|
344
|
+
/**
|
|
345
|
+
* Upload a document with raw content.
|
|
346
|
+
*
|
|
347
|
+
* This is the recommended method for programmatic uploads,
|
|
348
|
+
* especially from AI agents or backend services.
|
|
349
|
+
*
|
|
350
|
+
* @param params - Upload parameters
|
|
351
|
+
* @returns The created document
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const { document } = await client.documents.upload({
|
|
356
|
+
* spaceId: 'space_123',
|
|
357
|
+
* content: '# API Documentation\n\nThis document describes...',
|
|
358
|
+
* filename: 'api-docs.md',
|
|
359
|
+
* metadata: { category: 'technical', version: '1.0' }
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
upload(params: UploadDocumentParams): Promise<DocumentResponse>;
|
|
364
|
+
/**
|
|
365
|
+
* Upload a file as a document.
|
|
366
|
+
*
|
|
367
|
+
* This method is useful for browser-based uploads where
|
|
368
|
+
* you have access to File objects.
|
|
369
|
+
*
|
|
370
|
+
* @param params - Upload parameters including the file
|
|
371
|
+
* @returns The created document
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* // Browser file input
|
|
376
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
377
|
+
* const { document } = await client.documents.uploadFile({
|
|
378
|
+
* spaceId: 'space_123',
|
|
379
|
+
* file: fileInput.files[0]
|
|
380
|
+
* });
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
uploadFile(params: UploadDocumentFileParams): Promise<DocumentResponse>;
|
|
384
|
+
/**
|
|
385
|
+
* Upload multiple documents in a single request.
|
|
386
|
+
*
|
|
387
|
+
* Maximum 100 documents per batch. Each document is processed
|
|
388
|
+
* independently, so partial failures are possible.
|
|
389
|
+
*
|
|
390
|
+
* @param params - Batch upload parameters
|
|
391
|
+
* @returns Results for each document
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* const result = await client.documents.batchUpload({
|
|
396
|
+
* spaceId: 'space_123',
|
|
397
|
+
* documents: [
|
|
398
|
+
* { filename: 'doc1.md', content: '# Doc 1\n\nContent...' },
|
|
399
|
+
* { filename: 'doc2.md', content: '# Doc 2\n\nContent...' },
|
|
400
|
+
* ]
|
|
401
|
+
* });
|
|
402
|
+
*
|
|
403
|
+
* console.log(`Uploaded: ${result.totalSuccessful}`);
|
|
404
|
+
* console.log(`Failed: ${result.totalFailed}`);
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
batchUpload(params: BatchUploadParams): Promise<BatchUploadResponse>;
|
|
408
|
+
/**
|
|
409
|
+
* Update a document's metadata or status.
|
|
410
|
+
*
|
|
411
|
+
* @param id - The document ID
|
|
412
|
+
* @param params - Fields to update (includes spaceId)
|
|
413
|
+
* @returns The updated document
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* const { document } = await client.documents.update('doc_123', {
|
|
418
|
+
* spaceId: 'space_123',
|
|
419
|
+
* metadata: { reviewed: true }
|
|
420
|
+
* });
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
update(id: string, params: UpdateDocumentParams): Promise<DocumentResponse>;
|
|
424
|
+
/**
|
|
425
|
+
* Delete a document.
|
|
426
|
+
*
|
|
427
|
+
* This permanently removes the document and its vectors.
|
|
428
|
+
*
|
|
429
|
+
* @param id - The document ID
|
|
430
|
+
* @param spaceId - The space ID containing the document
|
|
431
|
+
* @returns Deletion confirmation
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* await client.documents.delete('doc_123', 'space_123');
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
delete(id: string, spaceId: string): Promise<DeleteResponse>;
|
|
439
|
+
/**
|
|
440
|
+
* Get the processed content of a document.
|
|
441
|
+
*
|
|
442
|
+
* Only available for documents with COMPLETED status.
|
|
443
|
+
*
|
|
444
|
+
* @param id - The document ID
|
|
445
|
+
* @param spaceId - The space ID containing the document
|
|
446
|
+
* @returns The processed document content
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* const { content, filename } = await client.documents.getContent(
|
|
451
|
+
* 'doc_123',
|
|
452
|
+
* 'space_123'
|
|
453
|
+
* );
|
|
454
|
+
* console.log(content);
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
getContent(id: string, spaceId: string): Promise<DocumentContentResponse>;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Queries Resource
|
|
462
|
+
*
|
|
463
|
+
* Query your knowledge base using semantic search.
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Queries API resource.
|
|
468
|
+
*
|
|
469
|
+
* Note: These methods are also exposed directly on the Orchata client
|
|
470
|
+
* as `client.query()` and `client.smartQuery()` for convenience.
|
|
471
|
+
*/
|
|
472
|
+
declare class Queries {
|
|
473
|
+
private readonly client;
|
|
474
|
+
constructor(client: FetchClient);
|
|
475
|
+
/**
|
|
476
|
+
* Query one or more spaces for similar content.
|
|
477
|
+
*
|
|
478
|
+
* Accepts a single space ID or array of space IDs. Results are merged
|
|
479
|
+
* and globally ranked by default, or can be grouped by space.
|
|
480
|
+
*
|
|
481
|
+
* @param params - Query parameters
|
|
482
|
+
* @returns Query results with matching chunks
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* // Simple query
|
|
487
|
+
* const { results } = await client.query({
|
|
488
|
+
* spaceIds: 'space_123',
|
|
489
|
+
* query: 'How do I reset my password?'
|
|
490
|
+
* });
|
|
491
|
+
*
|
|
492
|
+
* // Query multiple spaces
|
|
493
|
+
* const { results } = await client.query({
|
|
494
|
+
* spaceIds: ['space_123', 'space_456'],
|
|
495
|
+
* query: 'How do I reset my password?',
|
|
496
|
+
* topK: 5
|
|
497
|
+
* });
|
|
498
|
+
*
|
|
499
|
+
* // Query with metadata filter
|
|
500
|
+
* const { results } = await client.query({
|
|
501
|
+
* spaceIds: 'space_123',
|
|
502
|
+
* query: 'API documentation',
|
|
503
|
+
* metadata: { category: 'docs' }
|
|
504
|
+
* });
|
|
505
|
+
*
|
|
506
|
+
* // Group results by space
|
|
507
|
+
* const { groupedBySpace } = await client.query({
|
|
508
|
+
* spaceIds: ['space_123', 'space_456'],
|
|
509
|
+
* query: 'authentication',
|
|
510
|
+
* groupBySpace: true
|
|
511
|
+
* });
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
query(params: QueryParams): Promise<QueryResponse>;
|
|
515
|
+
/**
|
|
516
|
+
* Discover the most relevant spaces for a query.
|
|
517
|
+
*
|
|
518
|
+
* Uses hybrid keyword and embedding similarity to find which
|
|
519
|
+
* spaces are most likely to contain relevant content. This is
|
|
520
|
+
* useful when you have many spaces and want to narrow down
|
|
521
|
+
* which ones to query.
|
|
522
|
+
*
|
|
523
|
+
* @param params - Smart query parameters
|
|
524
|
+
* @returns Relevant spaces ranked by relevance
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* // Find relevant spaces
|
|
529
|
+
* const { relevantSpaces } = await client.smartQuery({
|
|
530
|
+
* query: 'How do I authenticate users?',
|
|
531
|
+
* maxSpaces: 3
|
|
532
|
+
* });
|
|
533
|
+
*
|
|
534
|
+
* // Use different relevance methods
|
|
535
|
+
* const { relevantSpaces } = await client.smartQuery({
|
|
536
|
+
* query: 'authentication',
|
|
537
|
+
* relevanceMethod: 'keyword', // or 'embedding' or 'hybrid'
|
|
538
|
+
* });
|
|
539
|
+
*
|
|
540
|
+
* // Full workflow: discover then query
|
|
541
|
+
* const { relevantSpaces } = await client.smartQuery({
|
|
542
|
+
* query: 'user authentication'
|
|
543
|
+
* });
|
|
544
|
+
*
|
|
545
|
+
* const { results } = await client.query({
|
|
546
|
+
* spaceIds: relevantSpaces.map(s => s.space.id),
|
|
547
|
+
* query: 'user authentication'
|
|
548
|
+
* });
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
smartQuery(params: SmartQueryParams): Promise<SmartQueryResponse>;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Spaces Resource
|
|
556
|
+
*
|
|
557
|
+
* Manage knowledge base spaces in Orchata.
|
|
558
|
+
*/
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Spaces API resource.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```typescript
|
|
565
|
+
* // List all spaces
|
|
566
|
+
* const { spaces, total } = await client.spaces.list();
|
|
567
|
+
*
|
|
568
|
+
* // Create a new space
|
|
569
|
+
* const { space } = await client.spaces.create({
|
|
570
|
+
* name: 'Documentation',
|
|
571
|
+
* description: 'Product documentation and guides',
|
|
572
|
+
* icon: 'book'
|
|
573
|
+
* });
|
|
574
|
+
*
|
|
575
|
+
* // Get a specific space
|
|
576
|
+
* const { space } = await client.spaces.get('space_123');
|
|
577
|
+
*
|
|
578
|
+
* // Update a space
|
|
579
|
+
* const { space } = await client.spaces.update('space_123', {
|
|
580
|
+
* name: 'Updated Name'
|
|
581
|
+
* });
|
|
582
|
+
*
|
|
583
|
+
* // Delete a space
|
|
584
|
+
* await client.spaces.delete('space_123');
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
declare class Spaces {
|
|
588
|
+
private readonly client;
|
|
589
|
+
constructor(client: FetchClient);
|
|
590
|
+
/**
|
|
591
|
+
* List all spaces in your organization.
|
|
592
|
+
*
|
|
593
|
+
* @param params - Optional pagination and filter parameters
|
|
594
|
+
* @returns Paginated list of spaces
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```typescript
|
|
598
|
+
* // List all active spaces
|
|
599
|
+
* const { spaces, total } = await client.spaces.list();
|
|
600
|
+
*
|
|
601
|
+
* // List archived spaces
|
|
602
|
+
* const { spaces } = await client.spaces.list({ status: 'archived' });
|
|
603
|
+
*
|
|
604
|
+
* // Paginate through spaces
|
|
605
|
+
* const { spaces, totalPages } = await client.spaces.list({
|
|
606
|
+
* page: 2,
|
|
607
|
+
* pageSize: 10
|
|
608
|
+
* });
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
list(params?: ListSpacesParams): Promise<ListSpacesResponse>;
|
|
612
|
+
/**
|
|
613
|
+
* Get a specific space by ID.
|
|
614
|
+
*
|
|
615
|
+
* @param id - The space ID
|
|
616
|
+
* @returns The space
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* const { space } = await client.spaces.get('space_123');
|
|
621
|
+
* console.log(space.name, space.description);
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
get(id: string): Promise<SpaceResponse>;
|
|
625
|
+
/**
|
|
626
|
+
* Create a new space.
|
|
627
|
+
*
|
|
628
|
+
* @param params - Space creation parameters
|
|
629
|
+
* @returns The created space
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* const { space } = await client.spaces.create({
|
|
634
|
+
* name: 'Knowledge Base',
|
|
635
|
+
* description: 'Company knowledge and documentation',
|
|
636
|
+
* icon: 'database'
|
|
637
|
+
* });
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
create(params: CreateSpaceParams): Promise<SpaceResponse>;
|
|
641
|
+
/**
|
|
642
|
+
* Update an existing space.
|
|
643
|
+
*
|
|
644
|
+
* @param id - The space ID
|
|
645
|
+
* @param params - Fields to update
|
|
646
|
+
* @returns The updated space
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```typescript
|
|
650
|
+
* const { space } = await client.spaces.update('space_123', {
|
|
651
|
+
* name: 'Updated Name',
|
|
652
|
+
* description: 'New description'
|
|
653
|
+
* });
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
update(id: string, params: UpdateSpaceParams): Promise<SpaceResponse>;
|
|
657
|
+
/**
|
|
658
|
+
* Delete (archive) a space.
|
|
659
|
+
*
|
|
660
|
+
* @param id - The space ID
|
|
661
|
+
* @returns Deletion confirmation
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* await client.spaces.delete('space_123');
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
delete(id: string): Promise<DeleteResponse>;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Orchata Client
|
|
673
|
+
*
|
|
674
|
+
* The main entry point for the Orchata SDK.
|
|
675
|
+
*/
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Orchata SDK Client
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```typescript
|
|
682
|
+
* import { Orchata } from '@orchata-ai/sdk';
|
|
683
|
+
*
|
|
684
|
+
* const client = new Orchata({ apiKey: 'oai_xxx' });
|
|
685
|
+
*
|
|
686
|
+
* // List spaces
|
|
687
|
+
* const { spaces } = await client.spaces.list();
|
|
688
|
+
*
|
|
689
|
+
* // Query documents
|
|
690
|
+
* const results = await client.query({
|
|
691
|
+
* spaceIds: ['space_123'],
|
|
692
|
+
* query: 'What is the meaning of life?'
|
|
693
|
+
* });
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
declare class Orchata {
|
|
697
|
+
readonly spaces: Spaces;
|
|
698
|
+
readonly documents: Documents;
|
|
699
|
+
/**
|
|
700
|
+
* Query one or more spaces for similar content.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* // Query a single space
|
|
705
|
+
* const results = await client.query({
|
|
706
|
+
* spaceIds: 'space_123',
|
|
707
|
+
* query: 'How do I reset my password?'
|
|
708
|
+
* });
|
|
709
|
+
*
|
|
710
|
+
* // Query multiple spaces
|
|
711
|
+
* const results = await client.query({
|
|
712
|
+
* spaceIds: ['space_123', 'space_456'],
|
|
713
|
+
* query: 'How do I reset my password?',
|
|
714
|
+
* topK: 5
|
|
715
|
+
* });
|
|
716
|
+
*
|
|
717
|
+
* // Query with metadata filter
|
|
718
|
+
* const results = await client.query({
|
|
719
|
+
* spaceIds: 'space_123',
|
|
720
|
+
* query: 'API documentation',
|
|
721
|
+
* metadata: { category: 'docs' }
|
|
722
|
+
* });
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
readonly query: Queries["query"];
|
|
726
|
+
/**
|
|
727
|
+
* Discover the most relevant spaces for a query.
|
|
728
|
+
*
|
|
729
|
+
* Uses hybrid keyword and embedding similarity to find
|
|
730
|
+
* which spaces are most likely to contain relevant content.
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* ```typescript
|
|
734
|
+
* const { relevantSpaces } = await client.smartQuery({
|
|
735
|
+
* query: 'How do I authenticate users?',
|
|
736
|
+
* maxSpaces: 3
|
|
737
|
+
* });
|
|
738
|
+
*
|
|
739
|
+
* // Use the discovered spaces for a full query
|
|
740
|
+
* const results = await client.query({
|
|
741
|
+
* spaceIds: relevantSpaces.map(s => s.space.id),
|
|
742
|
+
* query: 'How do I authenticate users?'
|
|
743
|
+
* });
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
readonly smartQuery: Queries["smartQuery"];
|
|
747
|
+
private readonly _client;
|
|
748
|
+
private readonly _queries;
|
|
749
|
+
constructor(config: OrchataConfig);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export { Queries as A, type BatchDocumentItem as B, type CreateSpaceParams as C, type DocumentStatus as D, type LucideIcon as L, type MatchReason as M, Orchata as O, type QueryParams as Q, type RelevanceMethod as R, type SpaceStatus as S, type UpdateSpaceParams as U, type OrchataConfig as a, type DeleteResponse as b, type Space as c, type ListSpacesParams as d, type ListSpacesResponse as e, type SpaceResponse as f, type Document as g, type UploadDocumentParams as h, type UploadDocumentFileParams as i, type BatchUploadParams as j, type BatchUploadResponse as k, type UpdateDocumentParams as l, type ListDocumentsParams as m, type ListDocumentsResponse as n, type DocumentResponse as o, type DocumentContentResponse as p, type QueryResultChunk as q, type QueryResultDocument as r, type QueryResultSpace as s, type QueryResultItem as t, type QueryResponse as u, type SmartQueryParams as v, type SmartQueryResultSpace as w, type SmartQueryResponse as x, Spaces as y, Documents as z };
|