@toothfairyai/sdk 0.2.6 → 0.5.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/README.md +1490 -249
- package/build/agent_functions/AgentFunctionManager.d.ts +14 -0
- package/build/agent_functions/AgentFunctionManager.d.ts.map +1 -0
- package/build/agent_functions/AgentFunctionManager.js +33 -0
- package/build/agent_functions/AgentFunctionManager.js.map +1 -0
- package/build/agents/AgentManager.d.ts +14 -0
- package/build/agents/AgentManager.d.ts.map +1 -0
- package/build/agents/AgentManager.js +36 -0
- package/build/agents/AgentManager.js.map +1 -0
- package/build/authorisations/AuthorisationManager.d.ts +14 -0
- package/build/authorisations/AuthorisationManager.d.ts.map +1 -0
- package/build/authorisations/AuthorisationManager.js +33 -0
- package/build/authorisations/AuthorisationManager.js.map +1 -0
- package/build/benchmarks/BenchmarkManager.d.ts +14 -0
- package/build/benchmarks/BenchmarkManager.d.ts.map +1 -0
- package/build/benchmarks/BenchmarkManager.js +33 -0
- package/build/benchmarks/BenchmarkManager.js.map +1 -0
- package/build/billing/BillingManager.d.ts +8 -0
- package/build/billing/BillingManager.d.ts.map +1 -0
- package/build/billing/BillingManager.js +13 -0
- package/build/billing/BillingManager.js.map +1 -0
- package/build/channels/ChannelManager.d.ts +14 -0
- package/build/channels/ChannelManager.d.ts.map +1 -0
- package/build/channels/ChannelManager.js +33 -0
- package/build/channels/ChannelManager.js.map +1 -0
- package/build/charting_settings/ChartingSettingsManager.d.ts +9 -0
- package/build/charting_settings/ChartingSettingsManager.d.ts.map +1 -0
- package/build/charting_settings/ChartingSettingsManager.js +16 -0
- package/build/charting_settings/ChartingSettingsManager.js.map +1 -0
- package/build/chat/ChatManager.d.ts +2 -0
- package/build/chat/ChatManager.d.ts.map +1 -1
- package/build/chat/ChatManager.js +17 -0
- package/build/chat/ChatManager.js.map +1 -1
- package/build/client.d.ts +59 -0
- package/build/client.d.ts.map +1 -1
- package/build/client.js +36 -0
- package/build/client.js.map +1 -1
- package/build/connections/ConnectionManager.d.ts +12 -0
- package/build/connections/ConnectionManager.d.ts.map +1 -0
- package/build/connections/ConnectionManager.js +27 -0
- package/build/connections/ConnectionManager.js.map +1 -0
- package/build/dictionary/DictionaryManager.d.ts +9 -0
- package/build/dictionary/DictionaryManager.d.ts.map +1 -0
- package/build/dictionary/DictionaryManager.js +24 -0
- package/build/dictionary/DictionaryManager.js.map +1 -0
- package/build/embeddings/EmbeddingsManager.d.ts +8 -0
- package/build/embeddings/EmbeddingsManager.d.ts.map +1 -0
- package/build/embeddings/EmbeddingsManager.js +13 -0
- package/build/embeddings/EmbeddingsManager.js.map +1 -0
- package/build/embeddings_settings/EmbeddingsSettingsManager.d.ts +9 -0
- package/build/embeddings_settings/EmbeddingsSettingsManager.d.ts.map +1 -0
- package/build/embeddings_settings/EmbeddingsSettingsManager.js +16 -0
- package/build/embeddings_settings/EmbeddingsSettingsManager.js.map +1 -0
- package/build/hooks/HookManager.d.ts +14 -0
- package/build/hooks/HookManager.d.ts.map +1 -0
- package/build/hooks/HookManager.js +33 -0
- package/build/hooks/HookManager.js.map +1 -0
- package/build/members/MemberManager.d.ts +13 -0
- package/build/members/MemberManager.d.ts.map +1 -0
- package/build/members/MemberManager.js +30 -0
- package/build/members/MemberManager.js.map +1 -0
- package/build/request_logs/RequestLogManager.d.ts +9 -0
- package/build/request_logs/RequestLogManager.d.ts.map +1 -0
- package/build/request_logs/RequestLogManager.js +24 -0
- package/build/request_logs/RequestLogManager.js.map +1 -0
- package/build/scheduled_jobs/ScheduledJobManager.d.ts +14 -0
- package/build/scheduled_jobs/ScheduledJobManager.d.ts.map +1 -0
- package/build/scheduled_jobs/ScheduledJobManager.js +33 -0
- package/build/scheduled_jobs/ScheduledJobManager.js.map +1 -0
- package/build/secrets/SecretManager.d.ts +11 -0
- package/build/secrets/SecretManager.d.ts.map +1 -0
- package/build/secrets/SecretManager.js +16 -0
- package/build/secrets/SecretManager.js.map +1 -0
- package/build/sites/SiteManager.d.ts +13 -0
- package/build/sites/SiteManager.d.ts.map +1 -0
- package/build/sites/SiteManager.js +30 -0
- package/build/sites/SiteManager.js.map +1 -0
- package/build/streaming/StreamingManager.d.ts +4 -1
- package/build/streaming/StreamingManager.d.ts.map +1 -1
- package/build/streaming/StreamingManager.js +46 -14
- package/build/streaming/StreamingManager.js.map +1 -1
- package/build/streams/StreamManager.d.ts +9 -0
- package/build/streams/StreamManager.d.ts.map +1 -0
- package/build/streams/StreamManager.js +24 -0
- package/build/streams/StreamManager.js.map +1 -0
- package/build/types/index.d.ts +566 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ToothFairyAI SDK for JavaScript/TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official TypeScript SDK for the ToothFairyAI API - A comprehensive toolkit for building AI-powered applications with chat, document processing, agent management, and more.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,360 +8,1603 @@ A comprehensive, TypeScript-first SDK for integrating with the ToothFairyAI API.
|
|
|
8
8
|
npm install @toothfairyai/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ToothFairyClient } from '@toothfairyai/sdk';
|
|
15
|
+
|
|
16
|
+
const client = new ToothFairyClient({
|
|
17
|
+
apiKey: 'your-api-key',
|
|
18
|
+
workspaceId: 'your-workspace-id'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Send a message to an agent
|
|
22
|
+
const response = await client.chat.sendToAgent('Hello, how can you help me?', 'agent-id');
|
|
23
|
+
console.log(response.agentResponse);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Table of Contents
|
|
27
|
+
|
|
28
|
+
- [SDK Overview](#sdk-overview)
|
|
29
|
+
- [Client Configuration](#client-configuration)
|
|
30
|
+
- [Core Features](#core-features)
|
|
31
|
+
- [Complete API Reference](#complete-api-reference)
|
|
32
|
+
- [Chat & Messaging](#chat--messaging)
|
|
33
|
+
- [Agents](#agents)
|
|
34
|
+
- [Documents](#documents)
|
|
35
|
+
- [Entities](#entities)
|
|
36
|
+
- [Folders](#folders)
|
|
37
|
+
- [Prompts](#prompts)
|
|
38
|
+
- [Agent Functions](#agent-functions)
|
|
39
|
+
- [Authorisations](#authorisations)
|
|
40
|
+
- [Channels](#channels)
|
|
41
|
+
- [Connections](#connections)
|
|
42
|
+
- [Members](#members)
|
|
43
|
+
- [Sites](#sites)
|
|
44
|
+
- [Benchmarks](#benchmarks)
|
|
45
|
+
- [Hooks](#hooks)
|
|
46
|
+
- [Scheduled Jobs](#scheduled-jobs)
|
|
47
|
+
- [Secrets](#secrets)
|
|
48
|
+
- [Dictionary](#dictionary)
|
|
49
|
+
- [Embeddings](#embeddings)
|
|
50
|
+
- [Settings](#settings)
|
|
51
|
+
- [Billing](#billing)
|
|
52
|
+
- [Streams](#streams)
|
|
53
|
+
- [Request Logs](#request-logs)
|
|
54
|
+
- [Streaming Responses](#streaming-responses)
|
|
55
|
+
- [Error Handling](#error-handling)
|
|
56
|
+
- [Best Practices](#best-practices)
|
|
57
|
+
|
|
58
|
+
## SDK Overview
|
|
59
|
+
|
|
60
|
+
The ToothFairyAI SDK provides a TypeScript-first interface to all 95 API endpoints, organized into 18 specialized managers:
|
|
61
|
+
|
|
62
|
+
| Manager | Purpose | Endpoints |
|
|
63
|
+
|---------|---------|-----------|
|
|
64
|
+
| `client.chat` | Chat conversations & messages | 7 |
|
|
65
|
+
| `client.agents` | AI agent management | 5 |
|
|
66
|
+
| `client.documents` | Document upload & management | 6 |
|
|
67
|
+
| `client.entities` | Topics, intents, NER entities | 5 |
|
|
68
|
+
| `client.folders` | Content organization | 5 |
|
|
69
|
+
| `client.prompts` | Prompt templates | 5 |
|
|
70
|
+
| `client.agentFunctions` | Agent function calls | 5 |
|
|
71
|
+
| `client.authorisations` | Auth configurations | 5 |
|
|
72
|
+
| `client.channels` | Communication channels | 5 |
|
|
73
|
+
| `client.connections` | Database/API connections | 3 |
|
|
74
|
+
| `client.members` | Workspace members | 4 |
|
|
75
|
+
| `client.sites` | Website crawling | 4 |
|
|
76
|
+
| `client.benchmarks` | Performance testing | 5 |
|
|
77
|
+
| `client.hooks` | Custom code execution | 5 |
|
|
78
|
+
| `client.scheduledJobs` | Cron jobs & scheduling | 5 |
|
|
79
|
+
| `client.secrets` | Secret management | 2 |
|
|
80
|
+
| `client.dictionary` | Translation dictionary | 2 |
|
|
81
|
+
| `client.embeddings` | Document embeddings | 1 |
|
|
82
|
+
| `client.chartingSettings` | Charting configuration | 2 |
|
|
83
|
+
| `client.embeddingsSettings` | Embeddings configuration | 2 |
|
|
84
|
+
| `client.billing` | Usage & costs | 1 |
|
|
85
|
+
| `client.streams` | Output streams | 2 |
|
|
86
|
+
| `client.requestLogs` | Request logging | 2 |
|
|
87
|
+
| `client.streaming` | Real-time streaming | - |
|
|
88
|
+
|
|
89
|
+
## Client Configuration
|
|
90
|
+
|
|
91
|
+
### Region-Specific Endpoints
|
|
92
|
+
|
|
93
|
+
ToothFairyAI operates in multiple regions. Configure your client to use the appropriate endpoints:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// US Region
|
|
97
|
+
const clientUS = new ToothFairyClient({
|
|
98
|
+
apiKey: 'your-api-key',
|
|
99
|
+
workspaceId: 'your-workspace-id',
|
|
100
|
+
baseUrl: 'https://api.us.toothfairyai.com',
|
|
101
|
+
aiUrl: 'https://ai.us.toothfairyai.com',
|
|
102
|
+
aiStreamUrl: 'https://ai-stream.us.toothfairyai.com'
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// EU Region
|
|
106
|
+
const clientEU = new ToothFairyClient({
|
|
107
|
+
apiKey: 'your-api-key',
|
|
108
|
+
workspaceId: 'your-workspace-id',
|
|
109
|
+
baseUrl: 'https://api.eu.toothfairyai.com',
|
|
110
|
+
aiUrl: 'https://ai.eu.toothfairyai.com',
|
|
111
|
+
aiStreamUrl: 'https://ai-stream.eu.toothfairyai.com'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Australia Region (default)
|
|
115
|
+
const clientAU = new ToothFairyClient({
|
|
116
|
+
apiKey: 'your-api-key',
|
|
117
|
+
workspaceId: 'your-workspace-id',
|
|
118
|
+
baseUrl: 'https://api.toothfairyai.com',
|
|
119
|
+
aiUrl: 'https://ai.toothfairyai.com',
|
|
120
|
+
aiStreamUrl: 'https://ais.toothfairyai.com'
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Configuration Options
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const client = new ToothFairyClient({
|
|
128
|
+
apiKey: 'your-api-key', // Required: Your API key
|
|
129
|
+
workspaceId: 'your-workspace-id', // Required: Your workspace ID
|
|
130
|
+
baseUrl: 'https://api.toothfairyai.com', // Optional: API base URL (region-specific)
|
|
131
|
+
aiUrl: 'https://ai.toothfairyai.com', // Optional: AI service URL (region-specific)
|
|
132
|
+
aiStreamUrl: 'https://ais.toothfairyai.com', // Optional: Streaming URL (region-specific)
|
|
133
|
+
timeout: 120000 // Optional: Request timeout in ms (default: 120000)
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Getting Your Credentials
|
|
138
|
+
|
|
139
|
+
1. **API Key**: Log in to ToothFairyAI Admin → API Integration → Generate API Key
|
|
140
|
+
2. **Workspace ID**: Found in your workspace settings or API dashboard
|
|
141
|
+
|
|
142
|
+
## Core Features
|
|
143
|
+
|
|
144
|
+
### 1. Chat & Messaging
|
|
145
|
+
Create conversations, send messages, and manage chat history with AI agents.
|
|
146
|
+
|
|
147
|
+
### 2. Agent Management
|
|
148
|
+
Create, configure, and manage AI agents with different modes (retriever, chatter, planner, etc.).
|
|
149
|
+
|
|
150
|
+
### 3. Document Processing
|
|
151
|
+
Upload, search, and manage documents for knowledge base integration.
|
|
152
|
+
|
|
153
|
+
### 4. Entity Management
|
|
154
|
+
Organize content with topics, intents, and named entity recognition.
|
|
155
|
+
|
|
156
|
+
### 5. Streaming
|
|
157
|
+
Real-time streaming responses with EventEmitter-based pattern.
|
|
158
|
+
|
|
159
|
+
## Complete API Reference
|
|
160
|
+
|
|
161
|
+
### Chat & Messaging
|
|
162
|
+
|
|
163
|
+
#### Create a Chat Session
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const chat = await client.chat.create({
|
|
167
|
+
name: 'Customer Support',
|
|
168
|
+
primaryRole: 'agent-id',
|
|
169
|
+
customerId: 'customer-123',
|
|
170
|
+
customerInfo: { name: 'John Doe', email: 'john@example.com' },
|
|
171
|
+
externalParticipantId: 'john@example.com',
|
|
172
|
+
channelSettings: {
|
|
173
|
+
sms: { isEnabled: true, recipient: '+1234567890', providerID: 'twilio' },
|
|
174
|
+
email: { isEnabled: true, recipient: 'john@example.com' }
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
console.log(`Chat ID: ${chat.id}`);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Update a Chat
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const chat = await client.chat.update({
|
|
184
|
+
id: 'chat-id',
|
|
185
|
+
name: 'Updated Chat Name',
|
|
186
|
+
customerId: 'new-customer-id'
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### Get Chat Details
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const chat = await client.chat.get('chat-id');
|
|
194
|
+
console.log(`Chat: ${chat.name}`);
|
|
195
|
+
console.log(`Primary Role: ${chat.primaryRole}`);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### List Chats
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const chats = await client.chat.list(10, 0);
|
|
202
|
+
for (const chat of chats.items) {
|
|
203
|
+
console.log(`${chat.name} (ID: ${chat.id})`);
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Delete a Chat
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
await client.chat.delete('chat-id');
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Create a Message
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const message = await client.chat.createMessage({
|
|
217
|
+
chatID: 'chat-id',
|
|
218
|
+
text: 'Hello, I need help with my account',
|
|
219
|
+
role: 'user',
|
|
220
|
+
userID: 'user-123',
|
|
221
|
+
images: ['https://example.com/image.jpg'],
|
|
222
|
+
files: ['https://example.com/document.pdf']
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Update a Message
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
const message = await client.chat.updateMessage('message-id', {
|
|
230
|
+
text: 'Updated message text',
|
|
231
|
+
role: 'user'
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### Get a Message
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const message = await client.chat.getMessage('message-id');
|
|
239
|
+
console.log(`Message: ${message.text}`);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### List Messages in a Chat
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
const messages = await client.chat.listMessages('chat-id', 20, 0);
|
|
246
|
+
for (const msg of messages.items) {
|
|
247
|
+
console.log(`${msg.role}: ${msg.text}`);
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### Send Message to Agent (Non-Streaming)
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
const response = await client.chat.sendToAgent(
|
|
255
|
+
'Hello, how can you help me?',
|
|
256
|
+
'agent-id',
|
|
257
|
+
{
|
|
258
|
+
chatId: 'existing-chat-id', // Optional - creates new chat if not provided
|
|
259
|
+
phoneNumber: '+1234567890', // Optional
|
|
260
|
+
customerId: 'customer-123', // Optional
|
|
261
|
+
providerId: 'provider-id', // Optional
|
|
262
|
+
customerInfo: { name: 'John' }, // Optional
|
|
263
|
+
attachments: {
|
|
264
|
+
images: ['https://example.com/image.jpg'],
|
|
265
|
+
files: ['https://example.com/document.pdf'],
|
|
266
|
+
audios: ['https://example.com/audio.mp3'],
|
|
267
|
+
videos: ['https://example.com/video.mp4']
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
console.log(`Response: ${response.agentResponse}`);
|
|
272
|
+
console.log(`Chat ID: ${response.chatId}`);
|
|
273
|
+
console.log(`Message ID: ${response.messageId}`);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Agents
|
|
277
|
+
|
|
278
|
+
#### Create an Agent
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const agent = await client.agents.create({
|
|
282
|
+
label: 'Customer Support Agent',
|
|
283
|
+
mode: 'retriever', // retriever, coder, chatter, planner, computer, voice
|
|
284
|
+
interpolationString: 'You are a helpful customer support assistant...',
|
|
285
|
+
goals: 'Help customers resolve issues and answer questions',
|
|
286
|
+
temperature: 0.7,
|
|
287
|
+
maxTokens: 2000,
|
|
288
|
+
maxHistory: 10,
|
|
289
|
+
topK: 10,
|
|
290
|
+
docTopK: 5,
|
|
291
|
+
description: 'Specialized agent for customer support',
|
|
292
|
+
hasMemory: true,
|
|
293
|
+
showCitations: true,
|
|
294
|
+
allowedTopics: ['topic-1', 'topic-2'],
|
|
295
|
+
staticDocs: ['doc-1', 'doc-2']
|
|
296
|
+
});
|
|
297
|
+
console.log(`Agent ID: ${agent.id}`);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### Update an Agent
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const agent = await client.agents.update('agent-id', {
|
|
304
|
+
label: 'Updated Agent Name',
|
|
305
|
+
temperature: 0.8,
|
|
306
|
+
maxTokens: 3000
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
#### Get Agent Details
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
const agent = await client.agents.get('agent-id');
|
|
314
|
+
console.log(`Agent: ${agent.label}`);
|
|
315
|
+
console.log(`Mode: ${agent.mode}`);
|
|
316
|
+
console.log(`Goals: ${agent.goals}`);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
#### List Agents
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
const agents = await client.agents.list(10, 0);
|
|
323
|
+
for (const agent of agents.items) {
|
|
324
|
+
console.log(`${agent.label} (${agent.mode})`);
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
#### Delete an Agent
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
await client.agents.delete('agent-id');
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Documents
|
|
335
|
+
|
|
336
|
+
#### Upload a Document
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
const result = await client.documents.upload('/path/to/document.pdf', 'folder-id', {
|
|
340
|
+
onProgress: (percent, loaded, total) => {
|
|
341
|
+
console.log(`Progress: ${percent}%`);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
console.log(`Uploaded: ${result.filename}`);
|
|
345
|
+
console.log(`Size: ${result.sizeInMB} MB`);
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### Upload from Base64
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
const base64Data = 'base64-encoded-file-data';
|
|
352
|
+
const result = await client.documents.uploadFromBase64(
|
|
353
|
+
base64Data,
|
|
354
|
+
'document.pdf',
|
|
355
|
+
'application/pdf',
|
|
356
|
+
'folder-id'
|
|
357
|
+
);
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### Create Document from URL
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
const doc = await client.documents.createFromPath(
|
|
364
|
+
'https://example.com/document.pdf',
|
|
365
|
+
'user-123',
|
|
366
|
+
{
|
|
367
|
+
title: 'My Document',
|
|
368
|
+
folderId: 'folder-id',
|
|
369
|
+
topics: ['topic-1', 'topic-2'],
|
|
370
|
+
status: 'published'
|
|
371
|
+
}
|
|
372
|
+
);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### Create Document Record
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
const doc = await client.documents.create({
|
|
379
|
+
userid: 'user-123',
|
|
380
|
+
title: 'My Document',
|
|
381
|
+
type: 'readComprehensionFile', // readComprehensionUrl, readComprehensionPdf
|
|
382
|
+
topics: ['topic-1'],
|
|
383
|
+
folderid: 'folder-id',
|
|
384
|
+
external_path: 'https://example.com/doc.pdf',
|
|
385
|
+
source: 'external',
|
|
386
|
+
status: 'published',
|
|
387
|
+
scope: 'training'
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
#### Get Document
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
const doc = await client.documents.get('doc-id');
|
|
395
|
+
console.log(`Title: ${doc.title}`);
|
|
396
|
+
console.log(`Type: ${doc.type}`);
|
|
397
|
+
console.log(`Status: ${doc.status}`);
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
#### Update Document
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const doc = await client.documents.update('doc-id', {
|
|
404
|
+
userid: 'user-123',
|
|
405
|
+
title: 'Updated Title',
|
|
406
|
+
topics: ['new-topic'],
|
|
407
|
+
folderid: 'new-folder-id',
|
|
408
|
+
status: 'published'
|
|
409
|
+
});
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
#### List Documents
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
const docs = await client.documents.list(20, 0, 'folder-id', 'published');
|
|
416
|
+
for (const doc of docs.items) {
|
|
417
|
+
console.log(`${doc.title} (ID: ${doc.id})`);
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
#### Delete Document
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
await client.documents.delete('doc-id');
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
#### Search Documents
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
const results = await client.documents.search('dental procedures', {
|
|
431
|
+
topK: 10,
|
|
432
|
+
metadata: { category: 'procedures' }
|
|
433
|
+
});
|
|
434
|
+
for (const result of results) {
|
|
435
|
+
console.log(`Score: ${result.score}`);
|
|
436
|
+
console.log(`Content: ${result.content}`);
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
#### Download Document
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
const result = await client.documents.download(
|
|
444
|
+
'document.pdf',
|
|
445
|
+
'/downloads/document.pdf',
|
|
446
|
+
'documents',
|
|
447
|
+
{
|
|
448
|
+
onProgress: (percent, loaded, total) => {
|
|
449
|
+
console.log(`Download: ${percent}%`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
console.log(`Downloaded: ${result.filename}`);
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### Entities
|
|
457
|
+
|
|
458
|
+
#### Create an Entity
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
const entity = await client.entities.create('user-123', 'Dental Cleaning', 'topic', {
|
|
462
|
+
description: 'Professional teeth cleaning procedures',
|
|
463
|
+
emoji: '🦷',
|
|
464
|
+
parentEntity: 'parent-topic-id',
|
|
465
|
+
backgroundColor: '#FF5733'
|
|
466
|
+
});
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
#### Get Entity
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
const entity = await client.entities.get('entity-id');
|
|
473
|
+
console.log(`Label: ${entity.label}`);
|
|
474
|
+
console.log(`Type: ${entity.type}`);
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
#### Update Entity
|
|
478
|
+
|
|
479
|
+
```typescript
|
|
480
|
+
const entity = await client.entities.update('entity-id', {
|
|
481
|
+
label: 'Updated Label',
|
|
482
|
+
description: 'New description',
|
|
483
|
+
emoji: '🔧'
|
|
484
|
+
});
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
#### Delete Entity
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
await client.entities.delete('entity-id');
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### List Entities
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
const entities = await client.entities.list(20, 'topic');
|
|
497
|
+
for (const entity of entities.items) {
|
|
498
|
+
console.log(`${entity.label} (${entity.type})`);
|
|
499
|
+
}
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
#### Get Entities by Type
|
|
503
|
+
|
|
504
|
+
```typescript
|
|
505
|
+
const topics = await client.entities.getByType('topic');
|
|
506
|
+
const intents = await client.entities.getByType('intent');
|
|
507
|
+
const nerEntities = await client.entities.getByType('ner');
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
#### Search Entities
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
const results = await client.entities.search('cleaning', 'topic');
|
|
514
|
+
for (const entity of results) {
|
|
515
|
+
console.log(`${entity.label}`);
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Folders
|
|
520
|
+
|
|
521
|
+
#### Create a Folder
|
|
522
|
+
|
|
523
|
+
```typescript
|
|
524
|
+
const folder = await client.folders.create('user-123', 'Procedures', {
|
|
525
|
+
description: 'Medical procedures documentation',
|
|
526
|
+
emoji: '📁',
|
|
527
|
+
status: 'active',
|
|
528
|
+
parent: 'parent-folder-id' // Optional - for subfolders
|
|
529
|
+
});
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
#### Get Folder
|
|
533
|
+
|
|
534
|
+
```typescript
|
|
535
|
+
const folder = await client.folders.get('folder-id');
|
|
536
|
+
console.log(`Name: ${folder.name}`);
|
|
537
|
+
console.log(`Parent: ${folder.parent}`);
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### Update Folder
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
const folder = await client.folders.update('folder-id', {
|
|
544
|
+
name: 'Updated Name',
|
|
545
|
+
description: 'New description',
|
|
546
|
+
status: 'active'
|
|
547
|
+
});
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
#### Delete Folder
|
|
551
|
+
|
|
552
|
+
```typescript
|
|
553
|
+
await client.folders.delete('folder-id');
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
#### List Folders
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
const folders = await client.folders.list('active', 20, 0);
|
|
560
|
+
for (const folder of folders.items) {
|
|
561
|
+
console.log(`${folder.name}`);
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
#### Get Root Folders
|
|
566
|
+
|
|
567
|
+
```typescript
|
|
568
|
+
const rootFolders = await client.folders.getRootFolders();
|
|
569
|
+
for (const folder of rootFolders) {
|
|
570
|
+
console.log(`Root: ${folder.name}`);
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
#### Get Subfolders
|
|
575
|
+
|
|
576
|
+
```typescript
|
|
577
|
+
const subfolders = await client.folders.getSubfolders('folder-id');
|
|
578
|
+
for (const folder of subfolders) {
|
|
579
|
+
console.log(`Subfolder: ${folder.name}`);
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
#### Get Folder Tree
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
const tree = await client.folders.getTree();
|
|
587
|
+
|
|
588
|
+
function printTree(nodes: any[], level = 0) {
|
|
589
|
+
for (const node of nodes) {
|
|
590
|
+
console.log(' '.repeat(level) + `📁 ${node.name}`);
|
|
591
|
+
printTree(node.children, level + 1);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
printTree(tree);
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
#### Search Folders
|
|
599
|
+
|
|
600
|
+
```typescript
|
|
601
|
+
const results = await client.folders.search('procedures');
|
|
602
|
+
for (const folder of results) {
|
|
603
|
+
console.log(`${folder.name}`);
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
### Prompts
|
|
608
|
+
|
|
609
|
+
#### Create a Prompt
|
|
610
|
+
|
|
611
|
+
```typescript
|
|
612
|
+
const prompt = await client.prompts.create('user-123', {
|
|
613
|
+
type: 'greeting',
|
|
614
|
+
label: 'Greeting',
|
|
615
|
+
promptLength: 50,
|
|
616
|
+
interpolationString: 'Hello {{name}}, how can I help you today?',
|
|
617
|
+
scope: 'global',
|
|
618
|
+
style: 'friendly',
|
|
619
|
+
domain: 'customer-support',
|
|
620
|
+
promptPlaceholder: 'Enter greeting message',
|
|
621
|
+
availableToAgents: ['agent-1', 'agent-2']
|
|
622
|
+
});
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
#### Get Prompt
|
|
626
|
+
|
|
627
|
+
```typescript
|
|
628
|
+
const prompt = await client.prompts.get('prompt-id');
|
|
629
|
+
console.log(`Label: ${prompt.label}`);
|
|
630
|
+
console.log(`Template: ${prompt.interpolationString}`);
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
#### Update Prompt
|
|
634
|
+
|
|
635
|
+
```typescript
|
|
636
|
+
const prompt = await client.prompts.update('prompt-id', {
|
|
637
|
+
label: 'Updated Label',
|
|
638
|
+
interpolationString: 'New template string',
|
|
639
|
+
availableToAgents: ['agent-3']
|
|
640
|
+
});
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
#### Delete Prompt
|
|
644
|
+
|
|
645
|
+
```typescript
|
|
646
|
+
await client.prompts.delete('prompt-id');
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
#### List Prompts
|
|
650
|
+
|
|
651
|
+
```typescript
|
|
652
|
+
const prompts = await client.prompts.list({
|
|
653
|
+
type: 'greeting',
|
|
654
|
+
limit: 20,
|
|
655
|
+
offset: 0
|
|
656
|
+
});
|
|
657
|
+
for (const prompt of prompts.items) {
|
|
658
|
+
console.log(`${prompt.label}`);
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
#### Get Prompts by Type
|
|
663
|
+
|
|
664
|
+
```typescript
|
|
665
|
+
const greetings = await client.prompts.getByType('greeting');
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
#### Get Prompts by Agent
|
|
669
|
+
|
|
670
|
+
```typescript
|
|
671
|
+
const agentPrompts = await client.prompts.getByAgent('agent-id');
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
#### Get Prompts by Scope
|
|
675
|
+
|
|
676
|
+
```typescript
|
|
677
|
+
const globalPrompts = await client.prompts.getByScope('global');
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
#### Search Prompts
|
|
681
|
+
|
|
682
|
+
```typescript
|
|
683
|
+
const results = await client.prompts.search('greeting', 'greeting');
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
#### Clone Prompt
|
|
687
|
+
|
|
688
|
+
```typescript
|
|
689
|
+
const cloned = await client.prompts.clone('prompt-id', 'user-123', {
|
|
690
|
+
label: 'Cloned Greeting',
|
|
691
|
+
interpolationString: 'Modified template'
|
|
692
|
+
});
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
### Agent Functions
|
|
696
|
+
|
|
697
|
+
#### Create an Agent Function
|
|
698
|
+
|
|
699
|
+
```typescript
|
|
700
|
+
const func = await client.agentFunctions.create({
|
|
701
|
+
id: 'function-1',
|
|
702
|
+
name: 'Weather API',
|
|
703
|
+
url: 'https://api.weather.com/current',
|
|
704
|
+
model: 'gpt-4',
|
|
705
|
+
requestType: 'GET',
|
|
706
|
+
authorisationType: 'bearer',
|
|
707
|
+
authorisationKey: 'your-token',
|
|
708
|
+
description: 'Get current weather data',
|
|
709
|
+
parameters: [
|
|
710
|
+
{ name: 'location', type: 'string', required: true }
|
|
711
|
+
]
|
|
712
|
+
});
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
#### Update Agent Function
|
|
716
|
+
|
|
717
|
+
```typescript
|
|
718
|
+
const func = await client.agentFunctions.update({
|
|
719
|
+
id: 'function-1',
|
|
720
|
+
name: 'Updated Function Name',
|
|
721
|
+
url: 'https://new-url.com'
|
|
722
|
+
});
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
#### Delete Agent Function
|
|
726
|
+
|
|
727
|
+
```typescript
|
|
728
|
+
await client.agentFunctions.delete('function-1');
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
#### Get Agent Function
|
|
732
|
+
|
|
733
|
+
```typescript
|
|
734
|
+
const func = await client.agentFunctions.get('function-1');
|
|
735
|
+
console.log(`Name: ${func.name}`);
|
|
736
|
+
console.log(`URL: ${func.url}`);
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
#### List Agent Functions
|
|
740
|
+
|
|
741
|
+
```typescript
|
|
742
|
+
const functions = await client.agentFunctions.list(20);
|
|
743
|
+
for (const func of functions.items) {
|
|
744
|
+
console.log(`${func.name}`);
|
|
745
|
+
}
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
### Authorisations
|
|
749
|
+
|
|
750
|
+
#### Create an Authorisation
|
|
751
|
+
|
|
752
|
+
```typescript
|
|
753
|
+
const auth = await client.authorisations.create({
|
|
754
|
+
id: 'auth-1',
|
|
755
|
+
name: 'GitHub OAuth',
|
|
756
|
+
type: 'oauth',
|
|
757
|
+
tokenSecret: 'encrypted-token',
|
|
758
|
+
description: 'GitHub OAuth token for API access',
|
|
759
|
+
scope: 'repo,user',
|
|
760
|
+
grantType: 'authorization_code',
|
|
761
|
+
clientId: 'github-client-id',
|
|
762
|
+
clientSecret: 'encrypted-secret',
|
|
763
|
+
authorizationBaseUrl: 'https://github.com/login/oauth/authorize',
|
|
764
|
+
tokenBaseUrl: 'https://github.com/login/oauth/access_token'
|
|
765
|
+
});
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
#### Update Authorisation
|
|
769
|
+
|
|
770
|
+
```typescript
|
|
771
|
+
const auth = await client.authorisations.update({
|
|
772
|
+
id: 'auth-1',
|
|
773
|
+
name: 'Updated Auth Name',
|
|
774
|
+
scope: 'repo,user,admin'
|
|
775
|
+
});
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
#### Delete Authorisation
|
|
779
|
+
|
|
780
|
+
```typescript
|
|
781
|
+
await client.authorisations.delete('auth-1');
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
#### Get Authorisation
|
|
785
|
+
|
|
786
|
+
```typescript
|
|
787
|
+
const auth = await client.authorisations.get('auth-1');
|
|
788
|
+
console.log(`Name: ${auth.name}`);
|
|
789
|
+
console.log(`Type: ${auth.type}`);
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
#### List Authorisations
|
|
793
|
+
|
|
794
|
+
```typescript
|
|
795
|
+
const auths = await client.authorisations.list(20);
|
|
796
|
+
for (const auth of auths.items) {
|
|
797
|
+
console.log(`${auth.name} (${auth.type})`);
|
|
798
|
+
}
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
### Channels
|
|
802
|
+
|
|
803
|
+
#### Create a Channel
|
|
804
|
+
|
|
805
|
+
```typescript
|
|
806
|
+
const channel = await client.channels.create({
|
|
807
|
+
id: 'channel-1',
|
|
808
|
+
name: 'SMS Channel',
|
|
809
|
+
channel: 'sms',
|
|
810
|
+
provider: 'twilio',
|
|
811
|
+
senderid: '+1234567890',
|
|
812
|
+
description: 'SMS notifications via Twilio',
|
|
813
|
+
isActive: true
|
|
814
|
+
});
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
#### Update Channel
|
|
818
|
+
|
|
819
|
+
```typescript
|
|
820
|
+
const channel = await client.channels.update({
|
|
821
|
+
id: 'channel-1',
|
|
822
|
+
name: 'Updated Channel',
|
|
823
|
+
isActive: false
|
|
824
|
+
});
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
#### Delete Channel
|
|
828
|
+
|
|
829
|
+
```typescript
|
|
830
|
+
await client.channels.delete('channel-1');
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
#### Get Channel
|
|
834
|
+
|
|
835
|
+
```typescript
|
|
836
|
+
const channel = await client.channels.get('channel-1');
|
|
837
|
+
console.log(`Name: ${channel.name}`);
|
|
838
|
+
console.log(`Provider: ${channel.provider}`);
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
#### List Channels
|
|
842
|
+
|
|
843
|
+
```typescript
|
|
844
|
+
const channels = await client.channels.list(20);
|
|
845
|
+
for (const channel of channels.items) {
|
|
846
|
+
console.log(`${channel.name} (${channel.provider})`);
|
|
847
|
+
}
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
### Connections
|
|
851
|
+
|
|
852
|
+
#### Get Connection
|
|
853
|
+
|
|
854
|
+
```typescript
|
|
855
|
+
const connection = await client.connections.get('connection-id');
|
|
856
|
+
console.log(`Name: ${connection.name}`);
|
|
857
|
+
console.log(`Type: ${connection.type}`);
|
|
858
|
+
console.log(`Host: ${connection.host}`);
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
#### List Connections
|
|
862
|
+
|
|
863
|
+
```typescript
|
|
864
|
+
const connections = await client.connections.list(20);
|
|
865
|
+
for (const conn of connections.items) {
|
|
866
|
+
console.log(`${conn.name} (${conn.type})`);
|
|
867
|
+
}
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
#### Delete Connection
|
|
871
|
+
|
|
872
|
+
```typescript
|
|
873
|
+
await client.connections.delete('connection-id');
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
### Members
|
|
877
|
+
|
|
878
|
+
#### Get Member
|
|
879
|
+
|
|
880
|
+
```typescript
|
|
881
|
+
const member = await client.members.get('member-id');
|
|
882
|
+
console.log(`User ID: ${member.userID}`);
|
|
883
|
+
console.log(`Role: ${member.role}`);
|
|
884
|
+
console.log(`Status: ${member.status}`);
|
|
885
|
+
```
|
|
886
|
+
|
|
887
|
+
#### List Members
|
|
888
|
+
|
|
889
|
+
```typescript
|
|
890
|
+
const members = await client.members.list(20);
|
|
891
|
+
for (const member of members.items) {
|
|
892
|
+
console.log(`${member.userID} (${member.role})`);
|
|
893
|
+
}
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
#### Update Member
|
|
897
|
+
|
|
898
|
+
```typescript
|
|
899
|
+
const member = await client.members.update({
|
|
900
|
+
id: 'member-id',
|
|
901
|
+
role: 'admin',
|
|
902
|
+
status: 'active'
|
|
903
|
+
});
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
#### Delete Member
|
|
907
|
+
|
|
908
|
+
```typescript
|
|
909
|
+
await client.members.delete('member-id');
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
### Sites
|
|
913
|
+
|
|
914
|
+
#### Get Site
|
|
915
|
+
|
|
916
|
+
```typescript
|
|
917
|
+
const site = await client.sites.get('site-id');
|
|
918
|
+
console.log(`Name: ${site.name}`);
|
|
919
|
+
console.log(`URL: ${site.url}`);
|
|
920
|
+
console.log(`Status: ${site.status}`);
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
#### List Sites
|
|
924
|
+
|
|
925
|
+
```typescript
|
|
926
|
+
const sites = await client.sites.list(20);
|
|
927
|
+
for (const site of sites.items) {
|
|
928
|
+
console.log(`${site.name} - ${site.url}`);
|
|
929
|
+
}
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
#### Update Site
|
|
933
|
+
|
|
934
|
+
```typescript
|
|
935
|
+
const site = await client.sites.update({
|
|
936
|
+
id: 'site-id',
|
|
937
|
+
name: 'Updated Site',
|
|
938
|
+
status: 'active',
|
|
939
|
+
allowedPaths: ['/docs', '/blog']
|
|
940
|
+
});
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
#### Delete Site
|
|
944
|
+
|
|
945
|
+
```typescript
|
|
946
|
+
await client.sites.delete('site-id');
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
### Benchmarks
|
|
950
|
+
|
|
951
|
+
#### Create a Benchmark
|
|
952
|
+
|
|
953
|
+
```typescript
|
|
954
|
+
const benchmark = await client.benchmarks.create({
|
|
955
|
+
id: 'benchmark-1',
|
|
956
|
+
name: 'Customer Support Test',
|
|
957
|
+
description: 'Test agent performance on customer support queries',
|
|
958
|
+
questions: [
|
|
959
|
+
{
|
|
960
|
+
question: 'How do I reset my password?',
|
|
961
|
+
answer: 'Go to Settings > Security > Reset Password',
|
|
962
|
+
reasoning: 'Standard password reset flow',
|
|
963
|
+
context: 'Account management'
|
|
964
|
+
}
|
|
965
|
+
],
|
|
966
|
+
files: ['doc-1', 'doc-2']
|
|
967
|
+
});
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
#### Update Benchmark
|
|
971
|
+
|
|
972
|
+
```typescript
|
|
973
|
+
const benchmark = await client.benchmarks.update({
|
|
974
|
+
id: 'benchmark-1',
|
|
975
|
+
name: 'Updated Benchmark',
|
|
976
|
+
description: 'New description'
|
|
977
|
+
});
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
#### Delete Benchmark
|
|
981
|
+
|
|
982
|
+
```typescript
|
|
983
|
+
await client.benchmarks.delete('benchmark-1');
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
#### Get Benchmark
|
|
987
|
+
|
|
988
|
+
```typescript
|
|
989
|
+
const benchmark = await client.benchmarks.get('benchmark-1');
|
|
990
|
+
console.log(`Name: ${benchmark.name}`);
|
|
991
|
+
console.log(`Questions: ${benchmark.questions?.length}`);
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
#### List Benchmarks
|
|
995
|
+
|
|
996
|
+
```typescript
|
|
997
|
+
const benchmarks = await client.benchmarks.list(20);
|
|
998
|
+
for (const benchmark of benchmarks.items) {
|
|
999
|
+
console.log(`${benchmark.name}`);
|
|
1000
|
+
}
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
### Hooks
|
|
1004
|
+
|
|
1005
|
+
#### Create a Hook
|
|
1006
|
+
|
|
1007
|
+
```typescript
|
|
1008
|
+
const hook = await client.hooks.create({
|
|
1009
|
+
id: 'hook-1',
|
|
1010
|
+
name: 'Data Processing Hook',
|
|
1011
|
+
functionName: 'process_data',
|
|
1012
|
+
customExecutionCode: 'def process_data(data): return data.upper()',
|
|
1013
|
+
customExecutionInstructions: 'Process incoming data',
|
|
1014
|
+
availableLibraries: 'pandas,numpy',
|
|
1015
|
+
allowExternalAPI: true,
|
|
1016
|
+
hardcodedScript: false
|
|
1017
|
+
});
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
#### Update Hook
|
|
1021
|
+
|
|
1022
|
+
```typescript
|
|
1023
|
+
const hook = await client.hooks.update({
|
|
1024
|
+
id: 'hook-1',
|
|
1025
|
+
name: 'Updated Hook',
|
|
1026
|
+
customExecutionCode: 'def process_data(data): return data.lower()'
|
|
1027
|
+
});
|
|
1028
|
+
```
|
|
12
1029
|
|
|
13
|
-
|
|
1030
|
+
#### Delete Hook
|
|
1031
|
+
|
|
1032
|
+
```typescript
|
|
1033
|
+
await client.hooks.delete('hook-1');
|
|
1034
|
+
```
|
|
14
1035
|
|
|
15
|
-
|
|
1036
|
+
#### Get Hook
|
|
16
1037
|
|
|
17
1038
|
```typescript
|
|
18
|
-
|
|
1039
|
+
const hook = await client.hooks.get('hook-1');
|
|
1040
|
+
console.log(`Name: ${hook.name}`);
|
|
1041
|
+
console.log(`Function: ${hook.functionName}`);
|
|
1042
|
+
```
|
|
19
1043
|
|
|
20
|
-
|
|
21
|
-
const clientUS = new ToothFairyClient({
|
|
22
|
-
apiKey: 'your-api-key',
|
|
23
|
-
workspaceId: 'your-workspace-id',
|
|
24
|
-
baseUrl: 'https://api.us.toothfairyai.com',
|
|
25
|
-
aiUrl: 'https://ai.us.toothfairyai.com',
|
|
26
|
-
aiStreamUrl: 'https://ai-stream.us.toothfairyai.com'
|
|
27
|
-
});
|
|
1044
|
+
#### List Hooks
|
|
28
1045
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1046
|
+
```typescript
|
|
1047
|
+
const hooks = await client.hooks.list(20);
|
|
1048
|
+
for (const hook of hooks.items) {
|
|
1049
|
+
console.log(`${hook.name}`);
|
|
1050
|
+
}
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
### Scheduled Jobs
|
|
1054
|
+
|
|
1055
|
+
#### Create a Scheduled Job
|
|
1056
|
+
|
|
1057
|
+
```typescript
|
|
1058
|
+
const job = await client.scheduledJobs.create({
|
|
1059
|
+
id: 'job-1',
|
|
1060
|
+
name: 'Daily Report',
|
|
1061
|
+
description: 'Generate daily report at 9 AM',
|
|
1062
|
+
agentID: 'agent-id',
|
|
1063
|
+
customPromptID: 'prompt-id',
|
|
1064
|
+
forcedPrompt: 'Generate a daily summary report',
|
|
1065
|
+
schedule: {
|
|
1066
|
+
frequency: 'DAILY',
|
|
1067
|
+
hour: 9,
|
|
1068
|
+
minute: 0
|
|
1069
|
+
},
|
|
1070
|
+
timezone: 'UTC',
|
|
1071
|
+
isActive: true,
|
|
1072
|
+
status: 'ACTIVE'
|
|
36
1073
|
});
|
|
1074
|
+
```
|
|
37
1075
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1076
|
+
#### Update Scheduled Job
|
|
1077
|
+
|
|
1078
|
+
```typescript
|
|
1079
|
+
const job = await client.scheduledJobs.update({
|
|
1080
|
+
id: 'job-1',
|
|
1081
|
+
name: 'Updated Job',
|
|
1082
|
+
isActive: false,
|
|
1083
|
+
schedule: {
|
|
1084
|
+
frequency: 'WEEKLY',
|
|
1085
|
+
dayOfWeek: 1,
|
|
1086
|
+
hour: 9
|
|
1087
|
+
}
|
|
45
1088
|
});
|
|
46
1089
|
```
|
|
47
1090
|
|
|
48
|
-
|
|
49
|
-
- **US**: `api.us.toothfairyai.com` / `ai.us.toothfairyai.com`
|
|
50
|
-
- **EU**: `api.eu.toothfairyai.com` / `ai.eu.toothfairyai.com`
|
|
51
|
-
- **Australia** (default): `api.toothfairyai.com` / `ai.toothfairyai.com`
|
|
1091
|
+
#### Delete Scheduled Job
|
|
52
1092
|
|
|
53
|
-
|
|
1093
|
+
```typescript
|
|
1094
|
+
await client.scheduledJobs.delete('job-1');
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
#### Get Scheduled Job
|
|
54
1098
|
|
|
55
1099
|
```typescript
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1100
|
+
const job = await client.scheduledJobs.get('job-1');
|
|
1101
|
+
console.log(`Name: ${job.name}`);
|
|
1102
|
+
console.log(`Status: ${job.status}`);
|
|
1103
|
+
console.log(`Schedule: ${JSON.stringify(job.schedule)}`);
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
#### List Scheduled Jobs
|
|
1107
|
+
|
|
1108
|
+
```typescript
|
|
1109
|
+
const jobs = await client.scheduledJobs.list(20);
|
|
1110
|
+
for (const job of jobs.items) {
|
|
1111
|
+
console.log(`${job.name} (${job.status})`);
|
|
1112
|
+
}
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1115
|
+
### Secrets
|
|
1116
|
+
|
|
1117
|
+
#### Create a Secret
|
|
1118
|
+
|
|
1119
|
+
```typescript
|
|
1120
|
+
const secret = await client.secrets.create({
|
|
1121
|
+
id: 'secret-1',
|
|
1122
|
+
name: 'API Key',
|
|
1123
|
+
description: 'External API key for service X'
|
|
63
1124
|
});
|
|
64
1125
|
```
|
|
65
1126
|
|
|
66
|
-
|
|
1127
|
+
#### Delete Secret
|
|
67
1128
|
|
|
68
1129
|
```typescript
|
|
69
|
-
|
|
1130
|
+
await client.secrets.delete('secret-1');
|
|
1131
|
+
```
|
|
70
1132
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
1133
|
+
### Dictionary
|
|
1134
|
+
|
|
1135
|
+
#### Get Dictionary Entry
|
|
1136
|
+
|
|
1137
|
+
```typescript
|
|
1138
|
+
const entry = await client.dictionary.get('entry-id');
|
|
1139
|
+
console.log(`Source: ${entry.sourceText}`);
|
|
1140
|
+
console.log(`Target: ${entry.targetText}`);
|
|
1141
|
+
console.log(`Languages: ${entry.sourceLanguage} -> ${entry.targetLanguage}`);
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
#### List Dictionary Entries
|
|
1145
|
+
|
|
1146
|
+
```typescript
|
|
1147
|
+
const entries = await client.dictionary.list(20);
|
|
1148
|
+
for (const entry of entries.items) {
|
|
1149
|
+
console.log(`${entry.sourceLanguage} -> ${entry.targetLanguage}`);
|
|
1150
|
+
}
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
### Embeddings
|
|
1154
|
+
|
|
1155
|
+
#### Get Document Embeddings
|
|
1156
|
+
|
|
1157
|
+
```typescript
|
|
1158
|
+
const embeddings = await client.embeddings.get();
|
|
1159
|
+
for (const emb of embeddings) {
|
|
1160
|
+
console.log(`Document: ${emb.title}`);
|
|
1161
|
+
console.log(`Chunk: ${emb.chunk_id}`);
|
|
1162
|
+
console.log(`Type: ${emb.type}`);
|
|
1163
|
+
}
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
### Settings
|
|
1167
|
+
|
|
1168
|
+
#### Charting Settings
|
|
1169
|
+
|
|
1170
|
+
```typescript
|
|
1171
|
+
// Get charting settings
|
|
1172
|
+
const settings = await client.chartingSettings.get('settings-id');
|
|
1173
|
+
console.log(`Primary Color: ${settings.primaryColor}`);
|
|
1174
|
+
console.log(`Secondary Color: ${settings.secondaryColor}`);
|
|
1175
|
+
|
|
1176
|
+
// Update charting settings
|
|
1177
|
+
const updated = await client.chartingSettings.update({
|
|
1178
|
+
id: 'settings-id',
|
|
1179
|
+
primaryColor: '#FF5733',
|
|
1180
|
+
secondaryColor: '#33FF57',
|
|
1181
|
+
lineColor: '#3357FF'
|
|
75
1182
|
});
|
|
1183
|
+
```
|
|
76
1184
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1185
|
+
#### Embeddings Settings
|
|
1186
|
+
|
|
1187
|
+
```typescript
|
|
1188
|
+
// Get embeddings settings
|
|
1189
|
+
const settings = await client.embeddingsSettings.get('settings-id');
|
|
1190
|
+
console.log(`Max Chunk Words: ${settings.maxChunkWords}`);
|
|
1191
|
+
console.log(`Chunking Strategy: ${settings.chunkingStrategy}`);
|
|
1192
|
+
|
|
1193
|
+
// Update embeddings settings
|
|
1194
|
+
const updated = await client.embeddingsSettings.update({
|
|
1195
|
+
id: 'settings-id',
|
|
1196
|
+
maxChunkWords: 1000,
|
|
1197
|
+
chunkingStrategy: 'summary',
|
|
1198
|
+
imageExtractionStrategy: 'safe'
|
|
1199
|
+
});
|
|
1200
|
+
```
|
|
1201
|
+
|
|
1202
|
+
### Billing
|
|
1203
|
+
|
|
1204
|
+
#### Get Monthly Costs
|
|
1205
|
+
|
|
1206
|
+
```typescript
|
|
1207
|
+
const costs = await client.billing.getMonthCosts();
|
|
1208
|
+
console.log(`API Usage: ${JSON.stringify(costs.apiUsage)}`);
|
|
1209
|
+
console.log(`Training Usage: ${JSON.stringify(costs.trainingUsage)}`);
|
|
1210
|
+
console.log(`Total Cost: $${costs.apiUsage?.totalCostUSD || 0}`);
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
### Streams
|
|
1214
|
+
|
|
1215
|
+
#### Get Output Stream
|
|
1216
|
+
|
|
1217
|
+
```typescript
|
|
1218
|
+
const stream = await client.streams.get('stream-id');
|
|
1219
|
+
console.log(`Content: ${stream.content}`);
|
|
1220
|
+
console.log(`Type: ${stream.type}`);
|
|
1221
|
+
console.log(`Status: ${stream.status}`);
|
|
1222
|
+
```
|
|
1223
|
+
|
|
1224
|
+
#### List Output Streams
|
|
1225
|
+
|
|
1226
|
+
```typescript
|
|
1227
|
+
const streams = await client.streams.list(20);
|
|
1228
|
+
for (const stream of streams.items) {
|
|
1229
|
+
console.log(`${stream.type} - ${stream.status}`);
|
|
1230
|
+
}
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
### Request Logs
|
|
1234
|
+
|
|
1235
|
+
#### Get Request Log
|
|
1236
|
+
|
|
1237
|
+
```typescript
|
|
1238
|
+
const log = await client.requestLogs.get('log-id');
|
|
1239
|
+
console.log(`Type: ${log.type}`);
|
|
1240
|
+
console.log(`Status: ${log.status}`);
|
|
1241
|
+
console.log(`Tokens: ${log.tokens}`);
|
|
1242
|
+
console.log(`Words: ${log.words}`);
|
|
80
1243
|
```
|
|
81
1244
|
|
|
82
|
-
|
|
1245
|
+
#### List Request Logs
|
|
83
1246
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- 🌍 **Multi-Region Support**: US, EU, and Australia endpoints
|
|
1247
|
+
```typescript
|
|
1248
|
+
const logs = await client.requestLogs.list(20);
|
|
1249
|
+
for (const log of logs.items) {
|
|
1250
|
+
console.log(`${log.type} - ${log.status} (${log.tokens} tokens)`);
|
|
1251
|
+
}
|
|
1252
|
+
```
|
|
1253
|
+
|
|
1254
|
+
## Streaming Responses
|
|
93
1255
|
|
|
94
|
-
|
|
1256
|
+
### Simple Streaming
|
|
95
1257
|
|
|
96
|
-
|
|
1258
|
+
```typescript
|
|
1259
|
+
const session = await client.streaming.sendToAgent('Tell me about dental care', 'agent-id');
|
|
97
1260
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
- **`client.entities`** - Entity management (topics, intents, NER)
|
|
102
|
-
- **`client.folders`** - Folder organization
|
|
103
|
-
- **`client.prompts`** - AI prompt management
|
|
1261
|
+
session.on('data', (data) => {
|
|
1262
|
+
console.log(data.text, end='', flush=true);
|
|
1263
|
+
});
|
|
104
1264
|
|
|
105
|
-
|
|
1265
|
+
session.on('complete', () => {
|
|
1266
|
+
console.log('\nDone!');
|
|
1267
|
+
console.log(`Chat ID: ${session.chatId}`);
|
|
1268
|
+
console.log(`Message ID: ${session.messageId}`);
|
|
1269
|
+
});
|
|
1270
|
+
```
|
|
106
1271
|
|
|
107
|
-
###
|
|
1272
|
+
### Streaming with Event Types
|
|
108
1273
|
|
|
109
1274
|
```typescript
|
|
110
|
-
// Start a streaming conversation
|
|
111
1275
|
const session = await client.streaming.sendToAgent('Hello', 'agent-id');
|
|
112
1276
|
|
|
113
|
-
// Listen for different types of events
|
|
114
1277
|
session.on('status', (data) => {
|
|
115
|
-
console.log('
|
|
1278
|
+
console.log('Status:', data.status);
|
|
116
1279
|
});
|
|
117
1280
|
|
|
118
1281
|
session.on('progress', (data) => {
|
|
119
|
-
console.log('
|
|
1282
|
+
console.log('Progress:', data.processing_status);
|
|
120
1283
|
});
|
|
121
1284
|
|
|
122
1285
|
session.on('data', (data) => {
|
|
123
|
-
console.log('
|
|
1286
|
+
console.log('Response:', data.text);
|
|
124
1287
|
});
|
|
125
1288
|
|
|
126
1289
|
session.on('complete', (data) => {
|
|
127
|
-
console.log('
|
|
1290
|
+
console.log('Complete:', data);
|
|
128
1291
|
});
|
|
129
1292
|
|
|
130
1293
|
session.on('error', (error) => {
|
|
131
|
-
console.error('
|
|
1294
|
+
console.error('Error:', error);
|
|
132
1295
|
});
|
|
133
1296
|
```
|
|
134
1297
|
|
|
135
|
-
###
|
|
136
|
-
|
|
137
|
-
The SDK now supports comprehensive event tracking similar to the CLI's `--show-progress` flag:
|
|
1298
|
+
### Streaming with Progress Tracking
|
|
138
1299
|
|
|
139
1300
|
```typescript
|
|
140
1301
|
// Enable ALL SSE events tracking
|
|
141
1302
|
const session = await client.streaming.sendToAgent('Explain AI', 'agent-id', {
|
|
142
|
-
showProgress: true
|
|
1303
|
+
showProgress: true
|
|
143
1304
|
});
|
|
144
1305
|
|
|
145
|
-
// Standard events
|
|
1306
|
+
// Standard events
|
|
146
1307
|
session.on('data', (data) => {
|
|
147
1308
|
console.log('Agent text:', data.text);
|
|
148
1309
|
});
|
|
149
1310
|
|
|
150
|
-
session.on('status', (data) => {
|
|
151
|
-
console.log('Status:', data.status);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
1311
|
// NEW: Raw SSE events (when showProgress=true)
|
|
155
1312
|
session.on('sse_event', (data) => {
|
|
156
1313
|
console.log('Raw SSE event:', data);
|
|
157
1314
|
// This gives you access to ALL events from the streaming endpoint
|
|
158
|
-
// Useful for debugging, analytics, or building custom progress indicators
|
|
159
1315
|
});
|
|
160
1316
|
```
|
|
161
1317
|
|
|
162
|
-
|
|
163
|
-
- `'status'`: Connection status updates ('connected', 'complete')
|
|
164
|
-
- `'progress'`: Agent processing status updates
|
|
165
|
-
- `'data'`: Streaming response text chunks
|
|
166
|
-
- `'complete'`: Final response with metadata
|
|
167
|
-
- `'error'`: Error events
|
|
168
|
-
- `'chat_created'`: Chat creation events with chat ID
|
|
169
|
-
- `'sse_event'`: All raw SSE events (when `showProgress=true`)
|
|
170
|
-
|
|
171
|
-
**When to use `showProgress`:**
|
|
172
|
-
- **Debugging**: See exactly what events the SSE endpoint sends
|
|
173
|
-
- **Analytics**: Track detailed agent processing metrics
|
|
174
|
-
- **Custom UI**: Build advanced progress indicators
|
|
175
|
-
- **Monitoring**: Monitor all agent processing stages
|
|
1318
|
+
### Continue a Conversation
|
|
176
1319
|
|
|
177
1320
|
```typescript
|
|
178
|
-
//
|
|
179
|
-
const
|
|
180
|
-
showProgress: true
|
|
181
|
-
});
|
|
1321
|
+
// First message creates a new chat
|
|
1322
|
+
const session1 = await client.streaming.sendToAgent('Hello', 'agent-id');
|
|
182
1323
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
session.on('sse_event', (data) => {
|
|
187
|
-
eventCount++;
|
|
188
|
-
eventTypes.add(data.type || data.status || 'unknown');
|
|
189
|
-
|
|
190
|
-
console.log(`Event #${eventCount}: ${JSON.stringify(data)}`);
|
|
1324
|
+
session1.on('data', (data) => {
|
|
1325
|
+
console.log(data.text, end='');
|
|
191
1326
|
});
|
|
192
1327
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
1328
|
+
session1.on('complete', () => {
|
|
1329
|
+
// Continue in the same chat
|
|
1330
|
+
const session2 = await client.streaming.sendToAgent(
|
|
1331
|
+
'Tell me more',
|
|
1332
|
+
'agent-id',
|
|
1333
|
+
{ chatId: session1.chatId } // Use the chat ID from first session
|
|
1334
|
+
);
|
|
1335
|
+
|
|
1336
|
+
session2.on('data', (data) => {
|
|
1337
|
+
console.log(data.text, end='');
|
|
1338
|
+
});
|
|
196
1339
|
});
|
|
197
1340
|
```
|
|
198
1341
|
|
|
199
|
-
###
|
|
1342
|
+
### Streaming with Attachments
|
|
200
1343
|
|
|
201
1344
|
```typescript
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
console.log(`Upload progress: ${percent}%`);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// Create a document from URL
|
|
210
|
-
const document = await client.documents.createFromPath(
|
|
211
|
-
'https://example.com/policy.pdf',
|
|
212
|
-
'user-123',
|
|
1345
|
+
const session = await client.streaming.sendToAgent(
|
|
1346
|
+
'What\'s in this image?',
|
|
1347
|
+
'agent-id',
|
|
213
1348
|
{
|
|
214
|
-
|
|
215
|
-
|
|
1349
|
+
attachments: {
|
|
1350
|
+
images: ['https://example.com/image.jpg']
|
|
1351
|
+
}
|
|
216
1352
|
}
|
|
217
1353
|
);
|
|
218
1354
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
topK: 5
|
|
1355
|
+
session.on('data', (data) => {
|
|
1356
|
+
console.log(data.text, end='');
|
|
222
1357
|
});
|
|
1358
|
+
```
|
|
223
1359
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
1360
|
+
## Error Handling
|
|
1361
|
+
|
|
1362
|
+
```typescript
|
|
1363
|
+
import { ToothFairyError } from '@toothfairyai/sdk';
|
|
1364
|
+
|
|
1365
|
+
const client = new ToothFairyClient({
|
|
1366
|
+
apiKey: '...',
|
|
1367
|
+
workspaceId: '...'
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
try {
|
|
1371
|
+
const response = await client.chat.sendToAgent('Hello', 'agent-id');
|
|
1372
|
+
} catch (error) {
|
|
1373
|
+
if (error instanceof ToothFairyError) {
|
|
1374
|
+
console.error('Error:', error.message);
|
|
1375
|
+
console.error('Code:', error.code);
|
|
1376
|
+
console.error('Status:', error.statusCode);
|
|
1377
|
+
console.error('Response:', error.response);
|
|
1378
|
+
} else {
|
|
1379
|
+
console.error('Unknown error:', error);
|
|
232
1380
|
}
|
|
233
|
-
|
|
1381
|
+
}
|
|
234
1382
|
```
|
|
235
1383
|
|
|
236
|
-
###
|
|
1384
|
+
### Specific Error Types
|
|
237
1385
|
|
|
238
1386
|
```typescript
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
1387
|
+
import {
|
|
1388
|
+
ToothFairyError
|
|
1389
|
+
} from '@toothfairyai/sdk';
|
|
1390
|
+
|
|
1391
|
+
try {
|
|
1392
|
+
const client = new ToothFairyClient({
|
|
1393
|
+
apiKey: '',
|
|
1394
|
+
workspaceId: ''
|
|
1395
|
+
});
|
|
1396
|
+
} catch (error) {
|
|
1397
|
+
if (error instanceof ToothFairyError) {
|
|
1398
|
+
console.error('Error:', error.message);
|
|
1399
|
+
console.error('Code:', error.code);
|
|
251
1400
|
}
|
|
252
|
-
}
|
|
1401
|
+
}
|
|
253
1402
|
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1403
|
+
try {
|
|
1404
|
+
const result = await client.documents.upload('large_file.pdf');
|
|
1405
|
+
} catch (error) {
|
|
1406
|
+
if (error instanceof ToothFairyError) {
|
|
1407
|
+
console.error('Error:', error.message);
|
|
1408
|
+
console.error('Status:', error.statusCode);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
```
|
|
1412
|
+
|
|
1413
|
+
## Connection Testing
|
|
1414
|
+
|
|
1415
|
+
```typescript
|
|
1416
|
+
// Test connection
|
|
1417
|
+
const isConnected = await client.testConnection();
|
|
1418
|
+
console.log(`Connected: ${isConnected}`);
|
|
1419
|
+
|
|
1420
|
+
// Get health status
|
|
1421
|
+
const health = await client.getHealth();
|
|
1422
|
+
console.log(`Status: ${health.status}`);
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1425
|
+
## Best Practices
|
|
1426
|
+
|
|
1427
|
+
### 1. Use Environment Variables for Credentials
|
|
1428
|
+
|
|
1429
|
+
```typescript
|
|
1430
|
+
import { ToothFairyClient } from '@toothfairyai/sdk';
|
|
1431
|
+
|
|
1432
|
+
const client = new ToothFairyClient({
|
|
1433
|
+
apiKey: process.env.TOOTHPAIRY_API_KEY!,
|
|
1434
|
+
workspaceId: process.env.TOOTHPAIRY_WORKSPACE_ID!
|
|
260
1435
|
});
|
|
1436
|
+
```
|
|
261
1437
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
1438
|
+
### 2. Handle Pagination
|
|
1439
|
+
|
|
1440
|
+
```typescript
|
|
1441
|
+
async function getAllChats() {
|
|
1442
|
+
const allChats: any[] = [];
|
|
1443
|
+
let offset = 0;
|
|
1444
|
+
const limit = 100;
|
|
1445
|
+
|
|
1446
|
+
while (true) {
|
|
1447
|
+
const response = await client.chat.list(limit, offset);
|
|
1448
|
+
allChats.push(...response.items);
|
|
1449
|
+
|
|
1450
|
+
if (response.items.length < limit) {
|
|
1451
|
+
break;
|
|
272
1452
|
}
|
|
1453
|
+
|
|
1454
|
+
offset += limit;
|
|
273
1455
|
}
|
|
274
|
-
|
|
1456
|
+
|
|
1457
|
+
return allChats;
|
|
1458
|
+
}
|
|
275
1459
|
```
|
|
276
1460
|
|
|
277
|
-
###
|
|
1461
|
+
### 3. Use Streaming for Long Responses
|
|
278
1462
|
|
|
279
1463
|
```typescript
|
|
280
|
-
//
|
|
281
|
-
const
|
|
282
|
-
'
|
|
283
|
-
'
|
|
284
|
-
'topic',
|
|
285
|
-
{
|
|
286
|
-
description: 'Customer support related topics',
|
|
287
|
-
emoji: '🎧'
|
|
288
|
-
}
|
|
1464
|
+
// For long responses, use streaming to show progress
|
|
1465
|
+
const session = await client.streaming.sendToAgent(
|
|
1466
|
+
'Generate a comprehensive report',
|
|
1467
|
+
'agent-id'
|
|
289
1468
|
);
|
|
290
1469
|
|
|
291
|
-
|
|
292
|
-
|
|
1470
|
+
session.on('data', (data) => {
|
|
1471
|
+
console.log(data.text, end='', flush=true);
|
|
1472
|
+
});
|
|
1473
|
+
```
|
|
293
1474
|
|
|
294
|
-
|
|
295
|
-
const supportEntities = await client.entities.search('support');
|
|
1475
|
+
### 4. Implement Retry Logic
|
|
296
1476
|
|
|
297
|
-
|
|
298
|
-
|
|
1477
|
+
```typescript
|
|
1478
|
+
async function sendWithRetry(
|
|
1479
|
+
message: string,
|
|
1480
|
+
agentId: string,
|
|
1481
|
+
maxRetries = 3
|
|
1482
|
+
): Promise<any> {
|
|
1483
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
1484
|
+
try {
|
|
1485
|
+
return await client.chat.sendToAgent(message, agentId);
|
|
1486
|
+
} catch (error) {
|
|
1487
|
+
if (attempt < maxRetries - 1) {
|
|
1488
|
+
const delay = Math.pow(2, attempt) * 1000; // Exponential backoff
|
|
1489
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
1490
|
+
} else {
|
|
1491
|
+
throw error;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
299
1496
|
```
|
|
300
1497
|
|
|
301
|
-
###
|
|
1498
|
+
### 5. Use Chat IDs for Conversations
|
|
302
1499
|
|
|
303
1500
|
```typescript
|
|
304
|
-
// Create a
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
1501
|
+
// Create a chat once
|
|
1502
|
+
const chat = await client.chat.create({
|
|
1503
|
+
name: 'Support Session',
|
|
1504
|
+
primaryRole: 'agent-id'
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1507
|
+
// Use the same chat ID for all messages in the conversation
|
|
1508
|
+
const response1 = await client.chat.sendToAgent('Hello', 'agent-id', {
|
|
1509
|
+
chatId: chat.id
|
|
1510
|
+
});
|
|
1511
|
+
const response2 = await client.chat.sendToAgent('Tell me more', 'agent-id', {
|
|
1512
|
+
chatId: chat.id
|
|
308
1513
|
});
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
### 6. Organize Documents with Folders
|
|
309
1517
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
1518
|
+
```typescript
|
|
1519
|
+
// Create folder structure
|
|
1520
|
+
const procedures = await client.folders.create('user-123', 'Procedures', {
|
|
1521
|
+
description: 'Medical procedures documentation'
|
|
313
1522
|
});
|
|
314
1523
|
|
|
315
|
-
|
|
316
|
-
|
|
1524
|
+
const policies = await client.folders.create('user-123', 'Policies', {
|
|
1525
|
+
description: 'Company policies'
|
|
1526
|
+
});
|
|
317
1527
|
|
|
318
|
-
//
|
|
319
|
-
|
|
1528
|
+
// Upload documents to appropriate folders
|
|
1529
|
+
await client.documents.upload('procedure1.pdf', procedures.id);
|
|
1530
|
+
await client.documents.upload('policy1.pdf', policies.id);
|
|
320
1531
|
```
|
|
321
1532
|
|
|
322
|
-
###
|
|
1533
|
+
### 7. Use Topics for Content Organization
|
|
323
1534
|
|
|
324
1535
|
```typescript
|
|
325
|
-
// Create
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
1536
|
+
// Create topics
|
|
1537
|
+
const cleaningTopic = await client.entities.create(
|
|
1538
|
+
'user-123',
|
|
1539
|
+
'Dental Cleaning',
|
|
1540
|
+
'topic',
|
|
1541
|
+
{
|
|
1542
|
+
description: 'Professional teeth cleaning procedures',
|
|
1543
|
+
emoji: '🦷'
|
|
1544
|
+
}
|
|
1545
|
+
);
|
|
1546
|
+
|
|
1547
|
+
// Associate documents with topics
|
|
1548
|
+
const doc = await client.documents.createFromPath(
|
|
1549
|
+
'cleaning_guide.pdf',
|
|
1550
|
+
'user-123',
|
|
1551
|
+
{
|
|
1552
|
+
title: 'Cleaning Guide',
|
|
1553
|
+
topics: [cleaningTopic.id]
|
|
1554
|
+
}
|
|
1555
|
+
);
|
|
1556
|
+
```
|
|
333
1557
|
|
|
334
|
-
|
|
335
|
-
const systemPrompts = await client.prompts.getByType('system');
|
|
1558
|
+
### 8. Monitor Usage with Billing
|
|
336
1559
|
|
|
337
|
-
|
|
338
|
-
|
|
1560
|
+
```typescript
|
|
1561
|
+
// Check monthly usage
|
|
1562
|
+
const costs = await client.billing.getMonthCosts();
|
|
1563
|
+
const apiCost = costs.apiUsage?.totalCostUSD || 0;
|
|
1564
|
+
const trainingCost = costs.trainingUsage?.totalCharge || 0;
|
|
1565
|
+
|
|
1566
|
+
console.log(`API Cost: $${apiCost.toFixed(2)}`);
|
|
1567
|
+
console.log(`Training Cost: $${trainingCost.toFixed(2)}`);
|
|
1568
|
+
console.log(`Total: $${(apiCost + trainingCost).toFixed(2)}`);
|
|
1569
|
+
```
|
|
339
1570
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
1571
|
+
### 9. Use Scheduled Jobs for Automation
|
|
1572
|
+
|
|
1573
|
+
```typescript
|
|
1574
|
+
// Create a daily report job
|
|
1575
|
+
const job = await client.scheduledJobs.create({
|
|
1576
|
+
id: 'daily-report',
|
|
1577
|
+
name: 'Daily Summary Report',
|
|
1578
|
+
agentID: 'report-agent-id',
|
|
1579
|
+
schedule: {
|
|
1580
|
+
frequency: 'DAILY',
|
|
1581
|
+
hour: 9,
|
|
1582
|
+
minute: 0
|
|
1583
|
+
},
|
|
1584
|
+
timezone: 'UTC',
|
|
1585
|
+
isActive: true,
|
|
1586
|
+
status: 'ACTIVE'
|
|
343
1587
|
});
|
|
344
1588
|
```
|
|
345
1589
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
The SDK provides structured error handling:
|
|
1590
|
+
### 10. Secure Secrets Management
|
|
349
1591
|
|
|
350
1592
|
```typescript
|
|
351
|
-
|
|
1593
|
+
// Store sensitive data as secrets
|
|
1594
|
+
await client.secrets.create({
|
|
1595
|
+
id: 'external-api-key',
|
|
1596
|
+
name: 'External Service API Key',
|
|
1597
|
+
description: 'API key for external service integration'
|
|
1598
|
+
});
|
|
352
1599
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
} else {
|
|
362
|
-
console.error('Unknown error:', error);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
1600
|
+
// Reference secrets in agent functions
|
|
1601
|
+
await client.agentFunctions.create({
|
|
1602
|
+
id: 'api-function',
|
|
1603
|
+
name: 'External API Call',
|
|
1604
|
+
url: 'https://api.example.com/data',
|
|
1605
|
+
authorisationType: 'apikey',
|
|
1606
|
+
// Use secret reference instead of hardcoding
|
|
1607
|
+
});
|
|
365
1608
|
```
|
|
366
1609
|
|
|
367
1610
|
## Integration Examples
|
|
@@ -374,8 +1617,8 @@ import { ToothFairyClient } from '@toothfairyai/sdk';
|
|
|
374
1617
|
|
|
375
1618
|
const app = express();
|
|
376
1619
|
const client = new ToothFairyClient({
|
|
377
|
-
apiKey: process.env.
|
|
378
|
-
workspaceId: process.env.
|
|
1620
|
+
apiKey: process.env.TOOTHPAIRY_API_KEY!,
|
|
1621
|
+
workspaceId: process.env.TOOTHPAIRY_WORKSPACE_ID!
|
|
379
1622
|
});
|
|
380
1623
|
|
|
381
1624
|
app.post('/chat', async (req, res) => {
|
|
@@ -400,11 +1643,14 @@ import { NextApiRequest, NextApiResponse } from 'next';
|
|
|
400
1643
|
import { ToothFairyClient } from '@toothfairyai/sdk';
|
|
401
1644
|
|
|
402
1645
|
const client = new ToothFairyClient({
|
|
403
|
-
apiKey: process.env.
|
|
404
|
-
workspaceId: process.env.
|
|
1646
|
+
apiKey: process.env.TOOTHPAIRY_API_KEY!,
|
|
1647
|
+
workspaceId: process.env.TOOTHPAIRY_WORKSPACE_ID!
|
|
405
1648
|
});
|
|
406
1649
|
|
|
407
|
-
export default async function handler(
|
|
1650
|
+
export default async function handler(
|
|
1651
|
+
req: NextApiRequest,
|
|
1652
|
+
res: NextApiResponse
|
|
1653
|
+
) {
|
|
408
1654
|
const { message, agentId } = req.body;
|
|
409
1655
|
|
|
410
1656
|
try {
|
|
@@ -430,7 +1676,7 @@ const client = new ToothFairyClient({
|
|
|
430
1676
|
function ChatComponent() {
|
|
431
1677
|
const [messages, setMessages] = useState<string[]>([]);
|
|
432
1678
|
const [currentResponse, setCurrentResponse] = useState('');
|
|
433
|
-
|
|
1679
|
+
|
|
434
1680
|
const sendMessage = async (message: string) => {
|
|
435
1681
|
const session = await client.streaming.sendToAgent(message, 'agent-id');
|
|
436
1682
|
|
|
@@ -453,18 +1699,6 @@ function ChatComponent() {
|
|
|
453
1699
|
}
|
|
454
1700
|
```
|
|
455
1701
|
|
|
456
|
-
## Comparison with CLI
|
|
457
|
-
|
|
458
|
-
| Feature | SDK (`@toothfairyai/sdk`) | CLI (`@toothfairyai/cli`) |
|
|
459
|
-
|---------|---------------------------|---------------------------|
|
|
460
|
-
| **Purpose** | Programmatic integration in applications | Interactive command-line operations |
|
|
461
|
-
| **Usage** | `import { ToothFairyClient } from '@toothfairyai/sdk'` | `toothfairy stream "message" --agent-id xyz` |
|
|
462
|
-
| **Dependencies** | Minimal (axios only) | CLI tools (commander, chalk, ora) |
|
|
463
|
-
| **TypeScript** | TypeScript-first with comprehensive types | Basic TypeScript support |
|
|
464
|
-
| **Streaming** | EventEmitter-based real-time events | Callback-based streaming |
|
|
465
|
-
| **Error Handling** | Structured error classes | CLI-friendly error messages |
|
|
466
|
-
| **Use Cases** | Web apps, servers, integrations | Testing, debugging, CI/CD |
|
|
467
|
-
|
|
468
1702
|
## Development
|
|
469
1703
|
|
|
470
1704
|
### Building
|
|
@@ -476,7 +1710,14 @@ npm run build
|
|
|
476
1710
|
### Testing
|
|
477
1711
|
|
|
478
1712
|
```bash
|
|
1713
|
+
# Run unit tests
|
|
479
1714
|
npm test
|
|
1715
|
+
|
|
1716
|
+
# Run integration tests (requires API credentials)
|
|
1717
|
+
TF_API_KEY=your-api-key \
|
|
1718
|
+
TF_WORKSPACE_ID=your-workspace-id \
|
|
1719
|
+
TF_AGENT_ID=your-agent-id \
|
|
1720
|
+
npx ts-node tests/integration/test-streaming.ts
|
|
480
1721
|
```
|
|
481
1722
|
|
|
482
1723
|
### Linting
|