@odin-ai/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +470 -0
- package/dist/BaseClient.d.ts +54 -0
- package/dist/BaseClient.d.ts.map +1 -0
- package/dist/ChatSDK.d.ts +93 -0
- package/dist/ChatSDK.d.ts.map +1 -0
- package/dist/SmartTablesSDK.d.ts +397 -0
- package/dist/SmartTablesSDK.d.ts.map +1 -0
- package/dist/VoiceSDK.d.ts +73 -0
- package/dist/VoiceSDK.d.ts.map +1 -0
- package/dist/WorkflowSDK.d.ts +188 -0
- package/dist/WorkflowSDK.d.ts.map +1 -0
- package/dist/examples/basic-chat.d.ts +2 -0
- package/dist/examples/basic-chat.d.ts.map +1 -0
- package/dist/examples/react-integration.d.ts +7 -0
- package/dist/examples/react-integration.d.ts.map +1 -0
- package/dist/examples/smart-tables-basic.d.ts +2 -0
- package/dist/examples/smart-tables-basic.d.ts.map +1 -0
- package/dist/examples/smart-tables-comprehensive.d.ts +2 -0
- package/dist/examples/smart-tables-comprehensive.d.ts.map +1 -0
- package/dist/examples/smart-tables-demo.d.ts +2 -0
- package/dist/examples/smart-tables-demo.d.ts.map +1 -0
- package/dist/examples/smart-tables-import.d.ts +2 -0
- package/dist/examples/smart-tables-import.d.ts.map +1 -0
- package/dist/examples/streaming-chat.d.ts +2 -0
- package/dist/examples/streaming-chat.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2281 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2295 -0
- package/dist/index.js.map +1 -0
- package/dist/src/BaseClient.d.ts +48 -0
- package/dist/src/BaseClient.d.ts.map +1 -0
- package/dist/src/ChatSDK.d.ts +91 -0
- package/dist/src/ChatSDK.d.ts.map +1 -0
- package/dist/src/SmartTablesSDK.d.ts +312 -0
- package/dist/src/SmartTablesSDK.d.ts.map +1 -0
- package/dist/src/components/MessageBubble.d.ts +24 -0
- package/dist/src/components/MessageBubble.d.ts.map +1 -0
- package/dist/src/components/MessageList.d.ts +28 -0
- package/dist/src/components/MessageList.d.ts.map +1 -0
- package/dist/src/components/index.d.ts +4 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/types.d.ts +348 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/types.d.ts +262 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useVoiceConversation.d.ts +34 -0
- package/dist/useVoiceConversation.d.ts.map +1 -0
- package/dist/voice-types.d.ts +169 -0
- package/dist/voice-types.d.ts.map +1 -0
- package/dist/workflow-types.d.ts +431 -0
- package/dist/workflow-types.d.ts.map +1 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Odin AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
# Odin AI SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with the Odin AI platform, including Chat, Smart Tables, Voice, and **Workflows**.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @odin-ai/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Available SDKs
|
|
12
|
+
|
|
13
|
+
| SDK | Description |
|
|
14
|
+
|-----|-------------|
|
|
15
|
+
| `ChatSDK` | Chat conversations with AI agents |
|
|
16
|
+
| `SmartTablesSDK` | Structured data tables with AI enrichment |
|
|
17
|
+
| `VoiceSDK` | Voice conversations with AI |
|
|
18
|
+
| **`WorkflowSDK`** | Execute and monitor workflows with real-time updates |
|
|
19
|
+
|
|
20
|
+
## Authentication
|
|
21
|
+
|
|
22
|
+
All SDKs support two authentication methods:
|
|
23
|
+
|
|
24
|
+
### 1. Access Token Authentication (Web App)
|
|
25
|
+
|
|
26
|
+
For web applications that already have user sessions:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { ChatSDK } from '@odin-ai/sdk';
|
|
30
|
+
|
|
31
|
+
const chatSDK = new ChatSDK({
|
|
32
|
+
baseUrl: 'https://api.example.com/',
|
|
33
|
+
projectId: 'your-project-id',
|
|
34
|
+
accessToken: 'your-access-token', // From user session
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. API Key Authentication (External SDK)
|
|
39
|
+
|
|
40
|
+
For external applications and server-to-server communication:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { ChatSDK } from '@odin-ai/sdk';
|
|
44
|
+
|
|
45
|
+
const chatSDK = new ChatSDK({
|
|
46
|
+
baseUrl: 'https://api.example.com/',
|
|
47
|
+
projectId: 'your-project-id',
|
|
48
|
+
apiKey: 'your-api-key',
|
|
49
|
+
apiSecret: 'your-api-secret',
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage Examples
|
|
54
|
+
|
|
55
|
+
### Creating a Chat
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const chat = await chatSDK.createChat('My Chat', ['document-key-1']);
|
|
59
|
+
console.log('Created chat:', chat.chat_id);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Sending a Message
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const response = await chatSDK.sendMessage('Hello!', {
|
|
66
|
+
chatId: 'chat-id',
|
|
67
|
+
agentType: 'chat_agent',
|
|
68
|
+
});
|
|
69
|
+
console.log('Response:', response);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Streaming Messages
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
await chatSDK.sendMessageStream('Tell me about...', {
|
|
76
|
+
chatId: 'chat-id',
|
|
77
|
+
onChunk: (chunk) => console.log('Chunk:', chunk),
|
|
78
|
+
onComplete: (message) => console.log('Complete:', message),
|
|
79
|
+
onError: (error) => console.error('Error:', error),
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Listing Chats
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const chats = await chatSDK.listChats();
|
|
87
|
+
console.log('Chats:', chats.chats);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Deleting a Chat
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
await chatSDK.deleteChat('chat-id');
|
|
94
|
+
console.log('Chat deleted');
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Error Handling
|
|
98
|
+
|
|
99
|
+
The SDK throws errors for failed requests. Always wrap SDK calls in try-catch blocks:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
try {
|
|
103
|
+
const chat = await chatSDK.createChat('My Chat');
|
|
104
|
+
// Handle success
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error('Failed to create chat:', error.message);
|
|
107
|
+
// Handle error
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## TypeScript Support
|
|
112
|
+
|
|
113
|
+
The SDK is written in TypeScript and includes full type definitions for all methods and responses.
|
|
114
|
+
|
|
115
|
+
## Features
|
|
116
|
+
|
|
117
|
+
- ✅ **Authentication**: X-API-KEY and X-API-SECRET headers
|
|
118
|
+
- ✅ **Chat Management**: Create, list, get, delete, rename chats
|
|
119
|
+
- ✅ **Message Sending**: Both simple and streaming responses
|
|
120
|
+
- ✅ **File Support**: Image and document uploads
|
|
121
|
+
- ✅ **Pagination**: Cursor-based pagination for chat listing
|
|
122
|
+
- ✅ **TypeScript**: Full type safety and IntelliSense support
|
|
123
|
+
- ✅ **Error Handling**: Comprehensive error handling
|
|
124
|
+
- ✅ **Real-time**: Streaming message responses
|
|
125
|
+
- ✅ **Feedback**: User feedback on AI responses
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
### Configuration
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
interface ChatSDKConfig {
|
|
133
|
+
apiKey: string; // X-API-KEY header
|
|
134
|
+
apiSecret: string; // X-API-SECRET header
|
|
135
|
+
baseUrl: string; // API base URL
|
|
136
|
+
projectId: string; // Project ID for all operations
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Chat Management
|
|
141
|
+
|
|
142
|
+
#### `createChat(name?, documentKeys?)`
|
|
143
|
+
Creates a new chat in the project.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const chat = await chatSDK.createChat('My Chat', ['doc1', 'doc2']);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### `listChats(cursor?, limit?)`
|
|
150
|
+
Lists chats with pagination support.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const { chats, has_more, next_cursor } = await chatSDK.listChats();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### `getChatHistory(chatId)`
|
|
157
|
+
Gets a specific chat with its message history.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const chatHistory = await chatSDK.getChatHistory('chat-id');
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### `deleteChat(chatId)`
|
|
164
|
+
Deletes a chat and all its messages.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
await chatSDK.deleteChat('chat-id');
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### `updateChatName(chatId, newName)`
|
|
171
|
+
Updates the name of an existing chat.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
await chatSDK.updateChatName('chat-id', 'New Chat Name');
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Message Operations
|
|
178
|
+
|
|
179
|
+
#### `sendMessage(message, options?)`
|
|
180
|
+
Sends a message and returns the response.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const response = await chatSDK.sendMessage('Hello!', {
|
|
184
|
+
chatId: 'chat-id',
|
|
185
|
+
agentType: 'chat_agent',
|
|
186
|
+
documentKeys: ['doc1'],
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### `sendMessageStream(message, options?)`
|
|
191
|
+
Sends a message with streaming response support.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
await chatSDK.sendMessageStream('Tell me about AI', {
|
|
195
|
+
chatId: 'chat-id',
|
|
196
|
+
onChunk: (chunk) => {
|
|
197
|
+
// Handle streaming text chunks
|
|
198
|
+
console.log('Chunk:', chunk);
|
|
199
|
+
},
|
|
200
|
+
onMessageObject: (obj) => {
|
|
201
|
+
// Handle structured message objects
|
|
202
|
+
console.log('Message object:', obj);
|
|
203
|
+
},
|
|
204
|
+
onComplete: (message) => {
|
|
205
|
+
// Handle completion
|
|
206
|
+
console.log('Complete:', message);
|
|
207
|
+
},
|
|
208
|
+
onError: (error) => {
|
|
209
|
+
// Handle errors
|
|
210
|
+
console.error('Error:', error);
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Feedback
|
|
216
|
+
|
|
217
|
+
#### `sendFeedback(messageId, chatId, feedback)`
|
|
218
|
+
Sends user feedback (thumbs up/down) for a message.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
await chatSDK.sendFeedback('message-id', 'chat-id', true); // thumbs up
|
|
222
|
+
await chatSDK.sendFeedback('message-id', 'chat-id', false); // thumbs down
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Advanced Usage
|
|
226
|
+
|
|
227
|
+
### File Uploads
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
231
|
+
const files = Array.from(fileInput.files || []);
|
|
232
|
+
|
|
233
|
+
await chatSDK.sendMessageStream('Analyze this image', {
|
|
234
|
+
chatId: 'chat-id',
|
|
235
|
+
images: files,
|
|
236
|
+
onChunk: (chunk) => console.log(chunk),
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Custom Agents
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
await chatSDK.sendMessage('Help me write code', {
|
|
244
|
+
chatId: 'chat-id',
|
|
245
|
+
agentType: 'chat_agent',
|
|
246
|
+
agentId: 'custom-agent-id',
|
|
247
|
+
modelName: 'gpt-4o',
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Knowledge Base Integration
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
await chatSDK.sendMessage('What does our documentation say about X?', {
|
|
255
|
+
chatId: 'chat-id',
|
|
256
|
+
documentKeys: ['doc1', 'doc2', 'doc3'],
|
|
257
|
+
useKnowledgebase: true,
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Metadata
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
await chatSDK.sendMessage('Hello', {
|
|
265
|
+
chatId: 'chat-id',
|
|
266
|
+
metadata: {
|
|
267
|
+
userId: 'user-123',
|
|
268
|
+
sessionId: 'session-456',
|
|
269
|
+
customField: 'value',
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Examples
|
|
275
|
+
|
|
276
|
+
See the `/examples` directory for complete working examples:
|
|
277
|
+
|
|
278
|
+
- `basic-chat.ts` - Simple chat implementation
|
|
279
|
+
- `streaming-chat.ts` - Real-time streaming chat
|
|
280
|
+
- `file-upload.ts` - Chat with file uploads
|
|
281
|
+
- `react-integration.tsx` - React component integration
|
|
282
|
+
- `workflow-basic.ts` - Basic workflow listing and execution
|
|
283
|
+
- `workflow-streaming.ts` - Real-time streaming workflow execution
|
|
284
|
+
- `workflow-react-embed.tsx` - React component for embedding workflows
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## WorkflowSDK
|
|
289
|
+
|
|
290
|
+
Execute and monitor workflows from external applications with real-time streaming updates.
|
|
291
|
+
|
|
292
|
+
### Quick Start
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { WorkflowSDK } from '@odin-ai/sdk';
|
|
296
|
+
|
|
297
|
+
const sdk = new WorkflowSDK({
|
|
298
|
+
baseUrl: 'https://ecs-api.getodin.ai/',
|
|
299
|
+
projectId: 'your-project-id',
|
|
300
|
+
accessToken: 'your-access-token', // From Firebase, Supabase, or your auth
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// List workflows
|
|
304
|
+
const { tools: workflows } = await sdk.listWorkflows();
|
|
305
|
+
|
|
306
|
+
// Execute with streaming updates
|
|
307
|
+
const session = await sdk.executeWorkflowStream('workflow-id', {
|
|
308
|
+
inputs: { name: 'John' },
|
|
309
|
+
onNodeStarted: (event) => console.log(`Starting ${event.node_id}`),
|
|
310
|
+
onNodeCompleted: (event) => console.log(`Completed ${event.node_id}`),
|
|
311
|
+
onExecutionCompleted: (event) => console.log('Done!', event.result),
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Key Features
|
|
316
|
+
|
|
317
|
+
- **List & retrieve workflows** - Get available workflows in your project
|
|
318
|
+
- **Execute workflows** - Run workflows with custom input values
|
|
319
|
+
- **Real-time streaming** - SSE-based updates for node-by-node progress
|
|
320
|
+
- **Execution history** - Track past executions and results
|
|
321
|
+
- **File upload support** - Execute workflows with file inputs
|
|
322
|
+
- **Full TypeScript support** - Complete type definitions
|
|
323
|
+
|
|
324
|
+
See [WorkflowSDK Documentation](./docs/WorkflowSDK.md) for full API reference.
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Workflow Embed
|
|
329
|
+
|
|
330
|
+
Embed workflow visualization directly in your web application with a lightweight bundle (335 KB / 106 KB gzipped).
|
|
331
|
+
|
|
332
|
+
### Installation
|
|
333
|
+
|
|
334
|
+
Include the embed script and CSS:
|
|
335
|
+
|
|
336
|
+
```html
|
|
337
|
+
<link rel="stylesheet" href="https://cdn.getodin.ai/embed/odin-workflow.css">
|
|
338
|
+
<script src="https://cdn.getodin.ai/embed/odin-workflow.js"></script>
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Or build from source:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
cd ai-content-creator
|
|
345
|
+
npx vite build --config vite.embed.config.ts
|
|
346
|
+
# Output: dist/embed/odin-workflow.js, dist/embed/odin-workflow.css
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Usage
|
|
350
|
+
|
|
351
|
+
#### Method 1: JavaScript API
|
|
352
|
+
|
|
353
|
+
```javascript
|
|
354
|
+
OdinWorkflow.mount(document.getElementById('workflow-container'), {
|
|
355
|
+
apiUrl: 'https://ecs-api.getodin.ai/',
|
|
356
|
+
projectId: 'your-project-id',
|
|
357
|
+
workflowId: 'your-workflow-id',
|
|
358
|
+
accessToken: 'your-access-token',
|
|
359
|
+
theme: 'odin', // 'odin' | 'aai' | 'leah' | 'emerald' | 'sunset'
|
|
360
|
+
onExecutionStart: (executionId) => console.log('Started:', executionId),
|
|
361
|
+
onExecutionComplete: (result) => console.log('Complete:', result),
|
|
362
|
+
onError: (error) => console.error('Error:', error),
|
|
363
|
+
});
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
#### Method 2: Web Component
|
|
367
|
+
|
|
368
|
+
```html
|
|
369
|
+
<odin-workflow
|
|
370
|
+
api-url="https://ecs-api.getodin.ai/"
|
|
371
|
+
project-id="your-project-id"
|
|
372
|
+
workflow-id="your-workflow-id"
|
|
373
|
+
access-token="your-access-token"
|
|
374
|
+
theme="odin"
|
|
375
|
+
></odin-workflow>
|
|
376
|
+
|
|
377
|
+
<script>
|
|
378
|
+
document.querySelector('odin-workflow').addEventListener('execution-complete', (e) => {
|
|
379
|
+
console.log('Workflow completed:', e.detail.result);
|
|
380
|
+
});
|
|
381
|
+
</script>
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Authentication Examples
|
|
385
|
+
|
|
386
|
+
#### With Firebase Auth
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
import { initializeApp } from 'firebase/app';
|
|
390
|
+
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
|
|
391
|
+
|
|
392
|
+
const app = initializeApp({ apiKey: '...', authDomain: '...' });
|
|
393
|
+
const auth = getAuth(app);
|
|
394
|
+
|
|
395
|
+
const userCredential = await signInWithEmailAndPassword(auth, email, password);
|
|
396
|
+
const accessToken = await userCredential.user.getIdToken();
|
|
397
|
+
|
|
398
|
+
OdinWorkflow.mount(container, {
|
|
399
|
+
apiUrl: 'https://ecs-api.getodin.ai/',
|
|
400
|
+
projectId: 'your-project-id',
|
|
401
|
+
workflowId: 'your-workflow-id',
|
|
402
|
+
accessToken: accessToken,
|
|
403
|
+
});
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
#### With Supabase Auth
|
|
407
|
+
|
|
408
|
+
```javascript
|
|
409
|
+
import { createClient } from '@supabase/supabase-js';
|
|
410
|
+
|
|
411
|
+
const supabase = createClient('https://your-project.supabase.co', 'your-anon-key');
|
|
412
|
+
|
|
413
|
+
const { data: { session } } = await supabase.auth.signInWithPassword({
|
|
414
|
+
email: 'user@example.com',
|
|
415
|
+
password: 'password',
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
OdinWorkflow.mount(container, {
|
|
419
|
+
apiUrl: 'https://ecs-api.getodin.ai/',
|
|
420
|
+
projectId: 'your-project-id',
|
|
421
|
+
workflowId: 'your-workflow-id',
|
|
422
|
+
accessToken: session.access_token,
|
|
423
|
+
});
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Available Themes
|
|
427
|
+
|
|
428
|
+
| Theme | Primary Color |
|
|
429
|
+
|-------|---------------|
|
|
430
|
+
| `odin` | Blue (#4485FF) |
|
|
431
|
+
| `aai` | Orange (#FF5A10) |
|
|
432
|
+
| `leah` | Purple (#A855F7) |
|
|
433
|
+
| `emerald` | Green (#10B981) |
|
|
434
|
+
| `sunset` | Amber (#F59E0B) |
|
|
435
|
+
|
|
436
|
+
### Props Reference
|
|
437
|
+
|
|
438
|
+
| Prop | Type | Required | Description |
|
|
439
|
+
|------|------|----------|-------------|
|
|
440
|
+
| `apiUrl` | string | ✅ | API base URL |
|
|
441
|
+
| `projectId` | string | ✅ | Your project ID |
|
|
442
|
+
| `workflowId` | string | ✅ | Workflow to display |
|
|
443
|
+
| `accessToken` | string | ✅ | Auth token |
|
|
444
|
+
| `theme` | string | ❌ | Theme name (default: 'odin') |
|
|
445
|
+
| `height` | string/number | ❌ | Container height |
|
|
446
|
+
| `width` | string/number | ❌ | Container width |
|
|
447
|
+
| `darkMode` | boolean | ❌ | Enable dark mode |
|
|
448
|
+
| `hideHeader` | boolean | ❌ | Hide workflow header |
|
|
449
|
+
| `hideInputs` | boolean | ❌ | Hide input fields |
|
|
450
|
+
| `showControls` | boolean | ❌ | Show zoom controls |
|
|
451
|
+
| `initialInputs` | object | ❌ | Pre-fill input values |
|
|
452
|
+
| `onExecutionStart` | function | ❌ | Callback when execution starts |
|
|
453
|
+
| `onExecutionComplete` | function | ❌ | Callback when execution completes |
|
|
454
|
+
| `onError` | function | ❌ | Callback on error |
|
|
455
|
+
|
|
456
|
+
See [examples/workflow-embed-supabase.html](./examples/workflow-embed-supabase.html) for a complete Supabase example.
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## Contributing
|
|
461
|
+
|
|
462
|
+
1. Fork the repository
|
|
463
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
464
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
465
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
466
|
+
5. Open a Pull Request
|
|
467
|
+
|
|
468
|
+
## License
|
|
469
|
+
|
|
470
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface BaseClientConfig {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
projectId: string;
|
|
4
|
+
accessToken?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
apiSecret?: string;
|
|
7
|
+
customFetch?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export interface APIError extends Error {
|
|
10
|
+
status?: number;
|
|
11
|
+
detail?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generic HTTP client for AI Content Creator SDKs
|
|
15
|
+
*/
|
|
16
|
+
export declare class BaseClient {
|
|
17
|
+
protected config: BaseClientConfig;
|
|
18
|
+
protected headers: Record<string, string>;
|
|
19
|
+
protected customFetch: typeof fetch;
|
|
20
|
+
constructor(config: BaseClientConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Make an HTTP request with proper error handling
|
|
23
|
+
*/
|
|
24
|
+
protected makeRequest(endpoint: string, method?: string, body?: any, customHeaders?: Record<string, string>): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Make a GET request
|
|
27
|
+
*/
|
|
28
|
+
protected get(endpoint: string, headers?: Record<string, string>): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Make a POST request
|
|
31
|
+
*/
|
|
32
|
+
protected post(endpoint: string, body?: any, headers?: Record<string, string>): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Make a PUT request
|
|
35
|
+
*/
|
|
36
|
+
protected put(endpoint: string, body?: any, headers?: Record<string, string>): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Make a DELETE request
|
|
39
|
+
*/
|
|
40
|
+
protected delete(endpoint: string, body?: any, headers?: Record<string, string>): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Handle error responses from the API
|
|
43
|
+
*/
|
|
44
|
+
protected handleErrorResponse(response: Response): Promise<never>;
|
|
45
|
+
/**
|
|
46
|
+
* Create an error object from an HTTP response
|
|
47
|
+
*/
|
|
48
|
+
protected createErrorFromResponse(response: Response): Promise<APIError>;
|
|
49
|
+
/**
|
|
50
|
+
* Update the access token at runtime. Useful when the application's session token is refreshed.
|
|
51
|
+
*/
|
|
52
|
+
setAccessToken(newAccessToken: string): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=BaseClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../src/BaseClient.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,KAAK,CAAC;CAC5B;AAED,MAAM,WAAW,QAAS,SAAQ,KAAK;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC;IACnC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,SAAS,CAAC,WAAW,EAAE,OAAO,KAAK,CAAC;gBAExB,MAAM,EAAE,gBAAgB;IAsCpC;;OAEG;cACa,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAAc,EACtB,IAAI,CAAC,EAAE,GAAG,EACV,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,OAAO,CAAC,GAAG,CAAC;IAqCf;;OAEG;cACa,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAIrF;;OAEG;cACa,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAIlG;;OAEG;cACa,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAIjG;;OAEG;cACa,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAIpG;;OAEG;cACa,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAavE;;OAEG;cACa,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmB9E;;OAEG;IACI,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;CAWpD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ChatSDKConfig, SendMessageOptions, StreamCallbacks, CreateChatResponse, SendMessageResponse, ListChatsResponse, ChatHistoryResponse } from "./types";
|
|
2
|
+
import { BaseClient } from "./BaseClient";
|
|
3
|
+
/**
|
|
4
|
+
* Main SDK class for interacting with the AI Content Creator chat system
|
|
5
|
+
*/
|
|
6
|
+
export declare class ChatSDK extends BaseClient {
|
|
7
|
+
/**
|
|
8
|
+
* Initialize the Chat SDK
|
|
9
|
+
* @param config Configuration object with API credentials and settings
|
|
10
|
+
*/
|
|
11
|
+
constructor(config: ChatSDKConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Create a new chat in the project
|
|
14
|
+
* @param name Optional name for the chat (defaults to "Untitled")
|
|
15
|
+
* @param documentKeys Optional array of document keys for knowledge base context
|
|
16
|
+
* @returns Promise resolving to the created chat information
|
|
17
|
+
*/
|
|
18
|
+
createChat(name?: string, documentKeys?: string[]): Promise<CreateChatResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* List chats in the project with pagination support
|
|
21
|
+
* @param cursor Optional cursor for pagination
|
|
22
|
+
* @param limit Number of chats to return (default: 30, max: 100)
|
|
23
|
+
* @returns Promise resolving to paginated chat list
|
|
24
|
+
*/
|
|
25
|
+
listChats(cursor?: number, limit?: number): Promise<ListChatsResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Get a specific chat with its message history
|
|
28
|
+
* @param chatId The ID of the chat to retrieve
|
|
29
|
+
* @returns Promise resolving to chat details with messages
|
|
30
|
+
*/
|
|
31
|
+
getChatHistory(chatId: string): Promise<ChatHistoryResponse>;
|
|
32
|
+
/**
|
|
33
|
+
* Delete a chat and all its messages
|
|
34
|
+
* @param chatId The ID of the chat to delete
|
|
35
|
+
* @returns Promise that resolves when the chat is deleted
|
|
36
|
+
*/
|
|
37
|
+
deleteChat(chatId: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Update the name of an existing chat
|
|
40
|
+
* @param chatId The ID of the chat to update
|
|
41
|
+
* @param newName The new name for the chat
|
|
42
|
+
* @returns Promise that resolves when the name is updated
|
|
43
|
+
*/
|
|
44
|
+
updateChatName(chatId: string, newName: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Send a message and get the response
|
|
47
|
+
* @param message The message text to send
|
|
48
|
+
* @param options Optional configuration for the message
|
|
49
|
+
* @returns Promise resolving to the message response
|
|
50
|
+
*/
|
|
51
|
+
sendMessage(message: string, options?: SendMessageOptions): Promise<SendMessageResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Send a message with streaming response support
|
|
54
|
+
* @param message The message text to send
|
|
55
|
+
* @param options Configuration including streaming callbacks
|
|
56
|
+
* @returns Promise that resolves when streaming is complete
|
|
57
|
+
*/
|
|
58
|
+
sendMessageStream(message: string, options?: SendMessageOptions & StreamCallbacks): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Send user feedback for a message
|
|
61
|
+
* @param messageId The ID of the message to provide feedback for
|
|
62
|
+
* @param chatId The ID of the chat containing the message
|
|
63
|
+
* @param feedback True for positive feedback, false for negative
|
|
64
|
+
* @returns Promise that resolves when feedback is sent
|
|
65
|
+
*/
|
|
66
|
+
sendFeedback(messageId: string, chatId: string, feedback: boolean): Promise<void>;
|
|
67
|
+
private messageChunkString;
|
|
68
|
+
private docMessageString;
|
|
69
|
+
private messageInitObject;
|
|
70
|
+
private actionsMap;
|
|
71
|
+
private hasCalledOnStart;
|
|
72
|
+
/**
|
|
73
|
+
* Reset streaming state for a new message
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
private resetStreamingState;
|
|
77
|
+
/**
|
|
78
|
+
* Parse streaming response chunks and trigger appropriate callbacks
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
private parseStreamChunk;
|
|
82
|
+
/**
|
|
83
|
+
* Handle error responses from the API
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
protected handleErrorResponse(response: Response): Promise<never>;
|
|
87
|
+
/**
|
|
88
|
+
* Create an error object from an HTTP response
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
protected createErrorFromResponse(response: Response): Promise<Error>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ChatSDK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatSDK.d.ts","sourceRoot":"","sources":["../src/ChatSDK.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAY,MAAM,cAAc,CAAC;AAEpD;;GAEG;AACH,qBAAa,OAAQ,SAAQ,UAAU;IACrC;;;OAGG;gBACS,MAAM,EAAE,aAAa;IAIjC;;;;;OAKG;IACG,UAAU,CACd,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,kBAAkB,CAAC;IAQ9B;;;;;OAKG;IACG,SAAS,CACb,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,GAAE,MAAW,GACjB,OAAO,CAAC,iBAAiB,CAAC;IAS7B;;;;OAIG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAIlE;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO/C;;;;;OAKG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpE;;;;;OAKG;IACG,WAAW,CACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,mBAAmB,CAAC;IAyB/B;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kBAAkB,GAAG,eAAoB,GACjD,OAAO,CAAC,IAAI,CAAC;IAuJhB;;;;;;OAMG;IACG,YAAY,CAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,IAAI,CAAC;IAShB,OAAO,CAAC,kBAAkB,CAAM;IAChC,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,gBAAgB,CAAS;IAEjC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAkPxB;;;OAGG;cACa,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAKvE;;;OAGG;cACa,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;CA+B5E"}
|