oblien 1.1.0 → 1.1.2
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 +377 -495
- package/agents.js +14 -0
- package/icons.js +11 -0
- package/index.d.ts +12 -3
- package/index.js +16 -0
- package/package.json +9 -2
- package/sandbox.js +12 -0
- package/search.js +11 -0
- package/src/agents/agent.js +229 -0
- package/src/agents/index.js +212 -0
- package/src/agents/settings.js +100 -0
- package/src/agents/tools.js +155 -0
- package/src/chat/index.js +9 -1
- package/src/chat/session.js +3 -0
- package/src/client.js +8 -10
- package/src/icons/index.js +185 -0
- package/src/sandbox/index.js +185 -0
- package/src/sandbox/sandbox.js +124 -0
- package/src/search/index.js +191 -0
package/README.md
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
# Oblien Core SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🔐 **Direct header authentication** - Uses `x-client-id` and `x-client-secret` headers
|
|
8
|
-
- 👤 **Dual-layer guest identification** - IP + fingerprint for better guest tracking
|
|
9
|
-
- 🔄 **Smart guest matching** - Detects same guest even when IP or fingerprint changes
|
|
10
|
-
- 📊 **Namespace management** - Multi-tenant workspaces with service configurations
|
|
11
|
-
- ⚡ **Automatic rate limiting** - Built-in limits for guest sessions
|
|
12
|
-
- 💾 **Flexible storage** - NodeCache (default), Redis, or custom adapters
|
|
13
|
-
- 🎯 **Complete usage tracking** - Monitor credits, quotas, and activity
|
|
3
|
+
Complete Node.js SDK for the Oblien AI Platform. Manage agents, chat sessions, sandboxes, namespaces, and more.
|
|
14
4
|
|
|
15
5
|
## Installation
|
|
16
6
|
|
|
@@ -18,639 +8,531 @@ Server-side SDK for building AI-powered applications with Oblien platform.
|
|
|
18
8
|
npm install oblien
|
|
19
9
|
```
|
|
20
10
|
|
|
21
|
-
## What This SDK Does
|
|
22
|
-
|
|
23
|
-
**Server-Side Only** - This SDK is for creating and managing chat sessions on your server. It **does not** handle actual messaging - that happens client-side in the browser using the tokens this SDK generates.
|
|
24
|
-
|
|
25
|
-
### Workflow:
|
|
26
|
-
|
|
27
|
-
1. **Server:** Create session using this SDK → Get token
|
|
28
|
-
2. **Server:** Send token to client (browser)
|
|
29
|
-
3. **Client:** Use token to chat directly with Oblien API
|
|
30
|
-
4. **Client:** Use [react-chat-agent](https://npmjs.com/package/react-chat-agent) or your own implementation
|
|
31
|
-
|
|
32
11
|
## Quick Start
|
|
33
12
|
|
|
34
|
-
### 1. Initialize Client
|
|
35
|
-
|
|
36
13
|
```javascript
|
|
14
|
+
// Import client
|
|
37
15
|
import { OblienClient } from 'oblien';
|
|
38
16
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
apiSecret: 'your-client-secret', // Your Oblien Client Secret (required)
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 2. Create Chat Session
|
|
46
|
-
|
|
47
|
-
```javascript
|
|
17
|
+
// Import modules (tree-shakeable)
|
|
18
|
+
import { OblienAgents } from 'oblien/agents';
|
|
48
19
|
import { OblienChat } from 'oblien/chat';
|
|
20
|
+
import { OblienSandboxes } from 'oblien/sandbox';
|
|
21
|
+
import { OblienSearch } from 'oblien/search';
|
|
22
|
+
import { OblienIcons } from 'oblien/icons';
|
|
23
|
+
import { OblienNamespaces } from 'oblien/namespaces';
|
|
24
|
+
import { OblienCredits } from 'oblien/credits';
|
|
49
25
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
agentId: 'your-agent-id',
|
|
55
|
-
namespace: 'user_123', // Optional: User ID for rate limiting/tracking
|
|
56
|
-
// workflowId: 'workflow-id', // Optional
|
|
57
|
-
// workspace: {}, // Optional
|
|
26
|
+
// Initialize client
|
|
27
|
+
const client = new OblienClient({
|
|
28
|
+
clientId: 'your-client-id',
|
|
29
|
+
clientSecret: 'your-client-secret'
|
|
58
30
|
});
|
|
59
31
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// }
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### 3. Send Token to Client
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
// Express example
|
|
73
|
-
app.post('/api/create-session', async (req, res) => {
|
|
74
|
-
const session = await chat.createSession({
|
|
75
|
-
agentId: req.body.agentId,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
res.json({
|
|
79
|
-
sessionId: session.sessionId,
|
|
80
|
-
token: session.token, // Client uses this to chat
|
|
81
|
-
});
|
|
82
|
-
});
|
|
32
|
+
// Use modules
|
|
33
|
+
const agents = new OblienAgents(client);
|
|
34
|
+
const chat = new OblienChat(client);
|
|
35
|
+
const sandboxes = new OblienSandboxes(client);
|
|
36
|
+
const search = new OblienSearch(client);
|
|
37
|
+
const icons = new OblienIcons(client);
|
|
83
38
|
```
|
|
84
39
|
|
|
85
|
-
|
|
40
|
+
---
|
|
86
41
|
|
|
87
|
-
|
|
88
|
-
// In browser (using react-chat-agent)
|
|
89
|
-
import { ChatProvider } from 'react-chat-agent';
|
|
90
|
-
|
|
91
|
-
function App() {
|
|
92
|
-
const [sessionToken, setSessionToken] = useState(null);
|
|
93
|
-
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
// Get token from your server
|
|
96
|
-
fetch('/api/create-session', {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
body: JSON.stringify({ agentId: 'agent-id' }),
|
|
99
|
-
})
|
|
100
|
-
.then(r => r.json())
|
|
101
|
-
.then(data => setSessionToken(data.token));
|
|
102
|
-
}, []);
|
|
103
|
-
|
|
104
|
-
if (!sessionToken) return <div>Loading...</div>;
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<ChatProvider token={sessionToken}>
|
|
108
|
-
<ChatPanel />
|
|
109
|
-
</ChatProvider>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
```
|
|
42
|
+
## Modules Overview
|
|
113
43
|
|
|
114
|
-
|
|
44
|
+
### 🤖 Agents Module
|
|
115
45
|
|
|
116
|
-
|
|
46
|
+
Manage AI agents with settings, tools, and analytics.
|
|
117
47
|
|
|
118
48
|
```javascript
|
|
119
|
-
import {
|
|
49
|
+
import { OblienAgents } from 'oblien/agents';
|
|
120
50
|
|
|
121
|
-
const
|
|
51
|
+
const agents = new OblienAgents(client);
|
|
122
52
|
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
fingerprint, // NEW: Enables dual-layer identification
|
|
131
|
-
agentId: 'your-agent-id',
|
|
132
|
-
metadata: {
|
|
133
|
-
userAgent: req.headers['user-agent'],
|
|
134
|
-
referrer: req.headers['referer'],
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
res.json({
|
|
139
|
-
sessionId: session.sessionId,
|
|
140
|
-
token: session.token,
|
|
141
|
-
guest: session.guest,
|
|
142
|
-
// Guest sessions are rate-limited automatically
|
|
143
|
-
});
|
|
53
|
+
// Create agent
|
|
54
|
+
const agent = await agents.create({
|
|
55
|
+
name: 'Support Agent',
|
|
56
|
+
namespace: 'production',
|
|
57
|
+
prompts: {
|
|
58
|
+
identity: 'You are a helpful assistant.'
|
|
59
|
+
}
|
|
144
60
|
});
|
|
145
|
-
```
|
|
146
61
|
|
|
147
|
-
|
|
62
|
+
// Configure settings
|
|
63
|
+
const agentInstance = agents.agent(agent.agentId);
|
|
64
|
+
await agentInstance.settings.updateModelConfig({
|
|
65
|
+
model: 'oblien-master',
|
|
66
|
+
temperature: 0.8
|
|
67
|
+
});
|
|
148
68
|
|
|
149
|
-
|
|
150
|
-
-
|
|
151
|
-
- ✅ Automatic rate limiting (100K tokens/day, 50 messages/day)
|
|
152
|
-
- ✅ Privacy-friendly (IP masked, fingerprint hashed)
|
|
153
|
-
- ✅ Auto-expiring sessions (24h TTL)
|
|
154
|
-
- ✅ Built-in caching with `node-cache` (no Redis required!)
|
|
155
|
-
- ✅ Optional Redis support for distributed systems
|
|
69
|
+
// Assign tools
|
|
70
|
+
await agentInstance.settings.updateTools(['web-search', 'calculator']);
|
|
156
71
|
|
|
157
|
-
|
|
72
|
+
// Get analytics
|
|
73
|
+
const overview = await agentInstance.getOverview({ days: 7 });
|
|
74
|
+
```
|
|
158
75
|
|
|
159
|
-
|
|
76
|
+
**Features:**
|
|
77
|
+
- ✅ CRUD operations (create, read, update, delete)
|
|
78
|
+
- ✅ Settings management (5 sections: switches, model, tools, guest limits, context)
|
|
79
|
+
- ✅ Tools management (list, search, create, validate)
|
|
80
|
+
- ✅ Analytics & monitoring
|
|
81
|
+
- ✅ Namespace support
|
|
82
|
+
- ✅ User management
|
|
160
83
|
|
|
161
|
-
|
|
162
|
-
- **IP changes, fingerprint stays** → Same guest detected ✅
|
|
163
|
-
- **Both change** → New guest created
|
|
84
|
+
📖 [Full Documentation](./docs/AGENTS_COMPLETE.md) | 💡 [Examples](./examples/agents-complete-example.js)
|
|
164
85
|
|
|
165
|
-
|
|
86
|
+
---
|
|
166
87
|
|
|
167
|
-
|
|
88
|
+
### 💬 Chat Module
|
|
168
89
|
|
|
169
|
-
|
|
90
|
+
Create and manage chat sessions with guest support.
|
|
170
91
|
|
|
171
92
|
```javascript
|
|
172
|
-
import {
|
|
93
|
+
import { OblienChat } from 'oblien/chat';
|
|
173
94
|
|
|
174
|
-
const
|
|
95
|
+
const chat = new OblienChat(client);
|
|
175
96
|
|
|
176
|
-
// Create
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
metadata: { region: 'us-east-1' },
|
|
181
|
-
tags: ['production', 'critical'],
|
|
97
|
+
// Create session
|
|
98
|
+
const session = await chat.createSession({
|
|
99
|
+
agentId: 'agent-id',
|
|
100
|
+
namespace: 'production'
|
|
182
101
|
});
|
|
183
102
|
|
|
184
|
-
//
|
|
185
|
-
await
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
rateLimitRequests: 1000,
|
|
190
|
-
rateLimitPeriod: 'hour',
|
|
103
|
+
// Create guest session
|
|
104
|
+
const guestSession = await chat.createGuestSession({
|
|
105
|
+
ip: '192.168.1.1',
|
|
106
|
+
fingerprint: 'abc123',
|
|
107
|
+
agentId: 'agent-id'
|
|
191
108
|
});
|
|
192
109
|
|
|
193
|
-
//
|
|
194
|
-
const
|
|
195
|
-
console.log(usage.summary); // Credits, tokens, requests per service
|
|
196
|
-
|
|
197
|
-
// List all namespaces
|
|
198
|
-
const result = await namespaces.list({
|
|
199
|
-
status: 'active',
|
|
200
|
-
type: 'production',
|
|
201
|
-
});
|
|
110
|
+
// List sessions
|
|
111
|
+
const sessions = await chat.listSessions({ limit: 20 });
|
|
202
112
|
```
|
|
203
113
|
|
|
204
|
-
|
|
114
|
+
**Features:**
|
|
115
|
+
- ✅ Session management
|
|
116
|
+
- ✅ Guest sessions with fingerprint tracking
|
|
117
|
+
- ✅ Token generation
|
|
118
|
+
- ✅ Automatic guest ID generation
|
|
205
119
|
|
|
206
|
-
|
|
207
|
-
- ✅ **Service configuration** - Enable/disable services per namespace
|
|
208
|
-
- ✅ **Usage tracking** - Monitor credits, tokens, and requests
|
|
209
|
-
- ✅ **Quota management** - Set limits per service
|
|
210
|
-
- ✅ **Activity logging** - Complete audit trail
|
|
211
|
-
- ✅ **Rich metadata** - Custom fields and tags
|
|
120
|
+
📖 [Documentation](./docs/CHAT.md) | 💡 [Examples](./examples/chat-example.js)
|
|
212
121
|
|
|
213
|
-
|
|
122
|
+
---
|
|
214
123
|
|
|
215
|
-
|
|
124
|
+
### 📦 Sandboxes Module
|
|
216
125
|
|
|
217
|
-
Manage
|
|
126
|
+
Manage cloud sandboxes (containerized environments).
|
|
218
127
|
|
|
219
128
|
```javascript
|
|
220
|
-
import {
|
|
129
|
+
import { OblienSandboxes } from 'oblien/sandbox';
|
|
221
130
|
|
|
222
|
-
const
|
|
131
|
+
const sandboxes = new OblienSandboxes(client);
|
|
223
132
|
|
|
224
|
-
//
|
|
225
|
-
const
|
|
133
|
+
// Create sandbox
|
|
134
|
+
const sandbox = await sandboxes.create({
|
|
135
|
+
name: 'my-dev-env',
|
|
136
|
+
region: 'us-east-1',
|
|
137
|
+
template: 'node-20',
|
|
138
|
+
autoStart: true
|
|
139
|
+
});
|
|
226
140
|
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
quotaLimit: 10000,
|
|
232
|
-
period: 'monthly',
|
|
141
|
+
// Use sandbox
|
|
142
|
+
const { url, token } = sandbox.sandbox;
|
|
143
|
+
const response = await fetch(`${url}/files/list`, {
|
|
144
|
+
headers: { 'Authorization': `Bearer ${token}` }
|
|
233
145
|
});
|
|
234
146
|
|
|
235
|
-
//
|
|
236
|
-
|
|
147
|
+
// Control lifecycle
|
|
148
|
+
await sandboxes.stop(sandboxId);
|
|
149
|
+
await sandboxes.start(sandboxId);
|
|
150
|
+
await sandboxes.restart(sandboxId);
|
|
237
151
|
|
|
238
|
-
//
|
|
239
|
-
const
|
|
240
|
-
packageId: 'pro',
|
|
241
|
-
});
|
|
242
|
-
console.log('Checkout URL:', checkout.checkoutUrl);
|
|
152
|
+
// Regenerate token (1h expiry)
|
|
153
|
+
const newToken = await sandboxes.regenerateToken(sandboxId);
|
|
243
154
|
|
|
244
|
-
// Get
|
|
245
|
-
const
|
|
246
|
-
namespace: 'production',
|
|
247
|
-
service: 'ai',
|
|
248
|
-
limit: 50,
|
|
249
|
-
});
|
|
155
|
+
// Get metrics
|
|
156
|
+
const metrics = await sandboxes.getMetrics(sandboxId);
|
|
250
157
|
```
|
|
251
158
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
- ✅
|
|
255
|
-
- ✅
|
|
256
|
-
- ✅
|
|
257
|
-
- ✅
|
|
258
|
-
- ✅
|
|
259
|
-
- ✅ **Package management** - Predefined credit packages
|
|
159
|
+
**Features:**
|
|
160
|
+
- ✅ Create, start, stop, restart, delete sandboxes
|
|
161
|
+
- ✅ Auto-start option
|
|
162
|
+
- ✅ Token management (1h JWT)
|
|
163
|
+
- ✅ Resource metrics
|
|
164
|
+
- ✅ Multiple templates & regions
|
|
165
|
+
- ✅ Platform statistics
|
|
260
166
|
|
|
261
|
-
|
|
167
|
+
📖 [Full Documentation](./docs/SANDBOXES.md) | 💡 [Examples](./examples/sandbox-example.js)
|
|
262
168
|
|
|
263
|
-
|
|
169
|
+
---
|
|
264
170
|
|
|
265
|
-
###
|
|
171
|
+
### 🗂️ Namespaces Module
|
|
266
172
|
|
|
267
|
-
|
|
173
|
+
Manage namespaces and service configurations.
|
|
268
174
|
|
|
269
175
|
```javascript
|
|
270
|
-
import {
|
|
271
|
-
|
|
272
|
-
const chat = new OblienChat(client);
|
|
273
|
-
// Uses NodeCacheStorage by default
|
|
274
|
-
// Automatic expiration, memory management, and cleanup
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### Option 1: Custom NodeCache Settings
|
|
176
|
+
import { OblienNamespaces } from 'oblien/namespaces';
|
|
278
177
|
|
|
279
|
-
|
|
280
|
-
import { OblienChat, NodeCacheStorage } from 'oblien/chat';
|
|
178
|
+
const namespaces = new OblienNamespaces(client);
|
|
281
179
|
|
|
282
|
-
|
|
180
|
+
// Create namespace
|
|
181
|
+
const namespace = await namespaces.create({
|
|
182
|
+
name: 'production',
|
|
183
|
+
slug: 'prod',
|
|
184
|
+
type: 'production'
|
|
185
|
+
});
|
|
283
186
|
|
|
284
|
-
|
|
285
|
-
|
|
187
|
+
// Configure services
|
|
188
|
+
await namespaces.configureService(namespaceId, {
|
|
189
|
+
service: 'ai',
|
|
190
|
+
enabled: true,
|
|
191
|
+
config: { /* ... */ }
|
|
286
192
|
});
|
|
287
193
|
|
|
288
|
-
// Get
|
|
289
|
-
|
|
194
|
+
// Get usage stats
|
|
195
|
+
const usage = await namespaces.getUsage(namespaceId);
|
|
290
196
|
```
|
|
291
197
|
|
|
292
|
-
|
|
198
|
+
**Features:**
|
|
199
|
+
- ✅ Namespace CRUD
|
|
200
|
+
- ✅ Service configuration
|
|
201
|
+
- ✅ Usage tracking
|
|
202
|
+
- ✅ Activity logs
|
|
293
203
|
|
|
294
|
-
|
|
295
|
-
import { createClient } from 'redis';
|
|
296
|
-
import { OblienChat, RedisStorage } from 'oblien/chat';
|
|
204
|
+
📖 [Documentation](./docs/NAMESPACES.md)
|
|
297
205
|
|
|
298
|
-
|
|
299
|
-
await redis.connect();
|
|
206
|
+
---
|
|
300
207
|
|
|
301
|
-
|
|
302
|
-
guestStorage: new RedisStorage(redis),
|
|
303
|
-
guestTTL: 86400, // 24 hours
|
|
304
|
-
});
|
|
305
|
-
```
|
|
208
|
+
### 🎨 Icons Module
|
|
306
209
|
|
|
307
|
-
|
|
210
|
+
Search and fetch icons, images, and videos using AI-powered semantic search.
|
|
308
211
|
|
|
309
212
|
```javascript
|
|
310
|
-
import {
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
213
|
+
import { OblienIcons } from 'oblien/icons';
|
|
214
|
+
|
|
215
|
+
const icons = new OblienIcons(client);
|
|
216
|
+
|
|
217
|
+
// Search for icons
|
|
218
|
+
const results = await icons.search('home', { limit: 20 });
|
|
219
|
+
|
|
220
|
+
// Fetch specific icons
|
|
221
|
+
const icon = await icons.fetchIcon('settings gear');
|
|
222
|
+
|
|
223
|
+
// Fetch multiple icons at once
|
|
224
|
+
const iconSet = await icons.fetchIcons([
|
|
225
|
+
'home',
|
|
226
|
+
'user profile',
|
|
227
|
+
'settings',
|
|
228
|
+
'notification bell'
|
|
229
|
+
]);
|
|
230
|
+
|
|
231
|
+
// Fetch mixed media (icons, images, videos)
|
|
232
|
+
const media = await icons.fetch([
|
|
233
|
+
{ type: 'icon', description: 'user avatar' },
|
|
234
|
+
{ type: 'image', description: 'mountain landscape' },
|
|
235
|
+
{ type: 'video', description: 'product demo' }
|
|
236
|
+
]);
|
|
316
237
|
```
|
|
317
238
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
239
|
+
**Features:**
|
|
240
|
+
- ✅ Semantic icon search with AI embeddings
|
|
241
|
+
- ✅ Fetch icons, images, and videos
|
|
242
|
+
- ✅ Relevance scoring
|
|
243
|
+
- ✅ Multiple icon styles (Outline, Filled, etc.)
|
|
244
|
+
- ✅ Batch fetching
|
|
245
|
+
- ✅ Pagination support
|
|
246
|
+
- ✅ CDN-hosted assets
|
|
321
247
|
|
|
322
|
-
|
|
248
|
+
📖 [Full Documentation](./docs/ICONS.md) | 💡 [Examples](./examples/icons-example.js)
|
|
323
249
|
|
|
324
|
-
|
|
325
|
-
const client = new OblienClient({
|
|
326
|
-
apiKey: string,
|
|
327
|
-
apiSecret?: string,
|
|
328
|
-
baseURL?: string,
|
|
329
|
-
});
|
|
330
|
-
```
|
|
250
|
+
---
|
|
331
251
|
|
|
332
|
-
###
|
|
252
|
+
### 💳 Credits Module
|
|
333
253
|
|
|
334
|
-
|
|
254
|
+
Manage billing and credits.
|
|
335
255
|
|
|
336
256
|
```javascript
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
// Create regular session (authenticated users)
|
|
340
|
-
await chat.createSession({
|
|
341
|
-
agentId,
|
|
342
|
-
namespace?, // Optional: user_id for tracking
|
|
343
|
-
workflowId?,
|
|
344
|
-
workspace?
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
// Create guest session (with dual-layer identification)
|
|
348
|
-
await chat.createGuestSession({
|
|
349
|
-
ip,
|
|
350
|
-
fingerprint?, // NEW: Browser fingerprint for better tracking
|
|
351
|
-
agentId,
|
|
352
|
-
workflowId?,
|
|
353
|
-
metadata?,
|
|
354
|
-
workspace?
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// Get session info
|
|
358
|
-
await chat.getSession(sessionId);
|
|
257
|
+
import { OblienCredits } from 'oblien/credits';
|
|
359
258
|
|
|
360
|
-
|
|
361
|
-
await chat.listSessions({ page?, limit? });
|
|
259
|
+
const credits = new OblienCredits(client);
|
|
362
260
|
|
|
363
|
-
//
|
|
364
|
-
await
|
|
261
|
+
// Get balance
|
|
262
|
+
const balance = await credits.getBalance();
|
|
365
263
|
|
|
366
|
-
//
|
|
367
|
-
await
|
|
368
|
-
await chat.getAllGuests(); // Admin only
|
|
369
|
-
await chat.cleanupGuests(); // Clean expired
|
|
264
|
+
// Get usage
|
|
265
|
+
const usage = await credits.getUsage({ period: 'monthly' });
|
|
370
266
|
```
|
|
371
267
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
268
|
+
**Features:**
|
|
269
|
+
- ✅ Balance checking
|
|
270
|
+
- ✅ Usage tracking
|
|
271
|
+
- ✅ Transaction history
|
|
375
272
|
|
|
376
|
-
|
|
377
|
-
import { GuestManager } from 'oblien/chat';
|
|
378
|
-
|
|
379
|
-
const guestManager = new GuestManager({
|
|
380
|
-
storage?: StorageAdapter,
|
|
381
|
-
ttl?: number, // seconds
|
|
382
|
-
onGuestCreated?: (guest) => void,
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// With dual-layer identification
|
|
386
|
-
await guestManager.getOrCreateGuest(ip, fingerprint?, metadata?);
|
|
387
|
-
|
|
388
|
-
// Find existing guest by IP and/or fingerprint
|
|
389
|
-
await guestManager.findExistingGuest(fingerprint, ip);
|
|
390
|
-
|
|
391
|
-
await guestManager.getGuest(guestId);
|
|
392
|
-
await guestManager.updateGuest(guestId, updates);
|
|
393
|
-
await guestManager.deleteGuest(guestId);
|
|
394
|
-
await guestManager.getAllGuests();
|
|
395
|
-
await guestManager.cleanup();
|
|
396
|
-
```
|
|
273
|
+
---
|
|
397
274
|
|
|
398
275
|
## Complete Example
|
|
399
276
|
|
|
400
|
-
### Express Server
|
|
401
|
-
|
|
402
277
|
```javascript
|
|
403
|
-
|
|
404
|
-
import { OblienClient
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
278
|
+
// Import client and modules
|
|
279
|
+
import { OblienClient } from 'oblien';
|
|
280
|
+
import { OblienAgents } from 'oblien/agents';
|
|
281
|
+
import { OblienChat } from 'oblien/chat';
|
|
282
|
+
import { OblienSandboxes } from 'oblien/sandbox';
|
|
408
283
|
|
|
409
|
-
// Initialize
|
|
284
|
+
// Initialize
|
|
410
285
|
const client = new OblienClient({
|
|
411
|
-
|
|
412
|
-
|
|
286
|
+
clientId: 'your-client-id',
|
|
287
|
+
clientSecret: 'your-client-secret'
|
|
413
288
|
});
|
|
414
289
|
|
|
290
|
+
const agents = new OblienAgents(client);
|
|
415
291
|
const chat = new OblienChat(client);
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
res.json(session);
|
|
426
|
-
} catch (error) {
|
|
427
|
-
res.status(500).json({ error: error.message });
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// Create guest session with dual-layer identification
|
|
432
|
-
app.post('/api/guest-session', async (req, res) => {
|
|
433
|
-
try {
|
|
434
|
-
const ip = req.ip || req.headers['x-forwarded-for'];
|
|
435
|
-
const fingerprint = req.body.fingerprint; // From client
|
|
436
|
-
|
|
437
|
-
// Check for existing guest first
|
|
438
|
-
const existingGuest = await chat.getGuest(ip, fingerprint);
|
|
439
|
-
|
|
440
|
-
if (existingGuest && existingGuest.sessions.length > 0) {
|
|
441
|
-
// Return existing session if available
|
|
442
|
-
const latestSession = existingGuest.sessions[existingGuest.sessions.length - 1];
|
|
443
|
-
const sessionDetails = await chat.getSession(latestSession);
|
|
444
|
-
|
|
445
|
-
if (sessionDetails?.token) {
|
|
446
|
-
return res.json({
|
|
447
|
-
...sessionDetails,
|
|
448
|
-
isExisting: true,
|
|
449
|
-
});
|
|
450
|
-
}
|
|
292
|
+
const sandboxes = new OblienSandboxes(client);
|
|
293
|
+
|
|
294
|
+
async function main() {
|
|
295
|
+
// 1. Create agent with tools
|
|
296
|
+
const agent = await agents.create({
|
|
297
|
+
name: 'Code Assistant',
|
|
298
|
+
namespace: 'production',
|
|
299
|
+
prompts: {
|
|
300
|
+
identity: 'You are a coding assistant.'
|
|
451
301
|
}
|
|
452
|
-
|
|
453
|
-
// Create new guest session
|
|
454
|
-
const session = await chat.createGuestSession({
|
|
455
|
-
ip,
|
|
456
|
-
fingerprint,
|
|
457
|
-
agentId: req.body.agentId,
|
|
458
|
-
metadata: {
|
|
459
|
-
userAgent: req.headers['user-agent'],
|
|
460
|
-
},
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
res.json(session);
|
|
464
|
-
} catch (error) {
|
|
465
|
-
res.status(500).json({ error: error.message });
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
app.listen(3000);
|
|
470
|
-
```
|
|
302
|
+
});
|
|
471
303
|
|
|
472
|
-
|
|
304
|
+
// Configure agent
|
|
305
|
+
const agentInstance = agents.agent(agent.agentId);
|
|
306
|
+
await agentInstance.settings.updateTools(['web-search', 'calculator']);
|
|
307
|
+
await agentInstance.settings.updateModelConfig({
|
|
308
|
+
temperature: 0.7,
|
|
309
|
+
max_tokens: 3000
|
|
310
|
+
});
|
|
473
311
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
312
|
+
// 2. Create sandbox for code execution
|
|
313
|
+
const sandbox = await sandboxes.create({
|
|
314
|
+
name: 'code-env',
|
|
315
|
+
template: 'node-20',
|
|
316
|
+
autoStart: true
|
|
317
|
+
});
|
|
477
318
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
319
|
+
// 3. Create chat session
|
|
320
|
+
const session = await chat.createSession({
|
|
321
|
+
agentId: agent.agentId,
|
|
322
|
+
namespace: 'production'
|
|
323
|
+
});
|
|
482
324
|
|
|
483
|
-
|
|
325
|
+
console.log('Setup complete!');
|
|
326
|
+
console.log('- Agent ID:', agent.agentId);
|
|
327
|
+
console.log('- Sandbox URL:', sandbox.sandbox.url);
|
|
328
|
+
console.log('- Session ID:', session.sessionId);
|
|
329
|
+
}
|
|
484
330
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return res.status(405).json({ error: 'Method not allowed' });
|
|
488
|
-
}
|
|
331
|
+
main();
|
|
332
|
+
```
|
|
489
333
|
|
|
490
|
-
|
|
491
|
-
// For guests
|
|
492
|
-
if (!req.headers.authorization) {
|
|
493
|
-
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
|
|
494
|
-
const fingerprint = req.body.fingerprint;
|
|
495
|
-
|
|
496
|
-
const session = await chat.createGuestSession({
|
|
497
|
-
ip,
|
|
498
|
-
fingerprint, // Dual-layer identification
|
|
499
|
-
agentId: req.body.agentId,
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
return res.json(session);
|
|
503
|
-
}
|
|
334
|
+
---
|
|
504
335
|
|
|
505
|
-
|
|
506
|
-
const session = await chat.createSession({
|
|
507
|
-
agentId: req.body.agentId,
|
|
508
|
-
namespace: req.user.id, // User ID for tracking
|
|
509
|
-
});
|
|
336
|
+
## Module Structure
|
|
510
337
|
|
|
511
|
-
res.json(session);
|
|
512
|
-
} catch (error) {
|
|
513
|
-
res.status(500).json({ error: error.message });
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
338
|
```
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
339
|
+
oblien/
|
|
340
|
+
├── src/
|
|
341
|
+
│ ├── agents/ # Agents management
|
|
342
|
+
│ │ ├── index.js # OblienAgents class
|
|
343
|
+
│ │ ├── agent.js # Agent instance
|
|
344
|
+
│ │ ├── settings.js # AgentSettings class
|
|
345
|
+
│ │ └── tools.js # Tools class
|
|
346
|
+
│ ├── chat/ # Chat sessions
|
|
347
|
+
│ │ ├── index.js # OblienChat class
|
|
348
|
+
│ │ └── session.js # ChatSession class
|
|
349
|
+
│ ├── sandbox/ # Sandboxes management
|
|
350
|
+
│ │ ├── index.js # OblienSandboxes class
|
|
351
|
+
│ │ └── sandbox.js # Sandbox instance
|
|
352
|
+
│ ├── namespaces/ # Namespaces management
|
|
353
|
+
│ ├── credits/ # Credits & billing
|
|
354
|
+
│ └── client.js # OblienClient (base)
|
|
355
|
+
├── docs/ # Documentation
|
|
356
|
+
│ ├── AGENTS_COMPLETE.md
|
|
357
|
+
│ ├── SANDBOXES.md
|
|
358
|
+
│ ├── CHAT.md
|
|
359
|
+
│ └── NAMESPACES.md
|
|
360
|
+
└── examples/ # Usage examples
|
|
361
|
+
├── agents-complete-example.js
|
|
362
|
+
├── sandbox-example.js
|
|
363
|
+
└── chat-example.js
|
|
524
364
|
```
|
|
525
365
|
|
|
526
|
-
|
|
366
|
+
---
|
|
527
367
|
|
|
528
|
-
|
|
529
|
-
|---------|-------------------|----------|-------|
|
|
530
|
-
| **Setup** | ✅ Zero config | ✅ Zero config | ⚠️ Requires Redis |
|
|
531
|
-
| **Auto-expiry** | ✅ Yes | ✅ Manual | ✅ Yes |
|
|
532
|
-
| **Memory limit** | ✅ Configurable | ❌ No | ✅ Configurable |
|
|
533
|
-
| **Statistics** | ✅ Yes | ❌ No | ⚠️ Via Redis |
|
|
534
|
-
| **Distributed** | ❌ Single instance | ❌ Single instance | ✅ Multi-server |
|
|
535
|
-
| **Persistence** | ❌ Memory only | ❌ Memory only | ✅ Disk backup |
|
|
536
|
-
| **Production** | ✅ Recommended | ❌ Dev only | ✅ High-traffic |
|
|
368
|
+
## API Endpoints
|
|
537
369
|
|
|
538
|
-
|
|
370
|
+
| Module | Base Path | Operations |
|
|
371
|
+
|--------|-----------|------------|
|
|
372
|
+
| **Agents** | `/ai/agents` | CRUD, settings, tools, analytics |
|
|
373
|
+
| **Chat** | `/ai/session` | Create, list, history |
|
|
374
|
+
| **Sandboxes** | `/sandbox` | CRUD, start/stop/restart, metrics |
|
|
375
|
+
| **Tools** | `/ai/tools` | List, search, create |
|
|
376
|
+
| **Namespaces** | `/namespaces` | CRUD, services, usage |
|
|
539
377
|
|
|
540
|
-
|
|
541
|
-
- **InMemory**: Development, testing, quick prototypes
|
|
542
|
-
- **Redis**: Distributed systems, > 1M guests/day, need persistence
|
|
378
|
+
---
|
|
543
379
|
|
|
544
|
-
##
|
|
380
|
+
## Authentication
|
|
545
381
|
|
|
546
|
-
|
|
382
|
+
All modules use client credentials authentication:
|
|
547
383
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
Run the test example:
|
|
554
|
-
```bash
|
|
555
|
-
cd node_modules/oblien
|
|
556
|
-
node examples/raw.js
|
|
384
|
+
```javascript
|
|
385
|
+
const client = new OblienClient({
|
|
386
|
+
clientId: 'your-client-id', // X-Client-ID header
|
|
387
|
+
clientSecret: 'your-client-secret' // X-Client-Secret header
|
|
388
|
+
});
|
|
557
389
|
```
|
|
558
390
|
|
|
391
|
+
Get your credentials from the [Oblien Dashboard](https://dashboard.oblien.com).
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
559
395
|
## TypeScript Support
|
|
560
396
|
|
|
561
|
-
|
|
397
|
+
The SDK includes TypeScript definitions:
|
|
562
398
|
|
|
563
399
|
```typescript
|
|
564
|
-
import {
|
|
400
|
+
import {
|
|
401
|
+
OblienClient,
|
|
402
|
+
OblienAgents,
|
|
403
|
+
Agent,
|
|
404
|
+
AgentSettings,
|
|
405
|
+
Tools,
|
|
406
|
+
OblienSandboxes,
|
|
407
|
+
Sandbox
|
|
408
|
+
} from 'oblien';
|
|
565
409
|
|
|
566
410
|
const client: OblienClient = new OblienClient({
|
|
567
|
-
|
|
568
|
-
|
|
411
|
+
clientId: string,
|
|
412
|
+
clientSecret: string
|
|
569
413
|
});
|
|
570
|
-
|
|
571
|
-
const chat: OblienChat = new OblienChat(client);
|
|
572
414
|
```
|
|
573
415
|
|
|
574
|
-
|
|
416
|
+
---
|
|
575
417
|
|
|
576
|
-
|
|
418
|
+
## Error Handling
|
|
577
419
|
|
|
578
|
-
|
|
420
|
+
```javascript
|
|
421
|
+
try {
|
|
422
|
+
const agent = await agents.create({ /* ... */ });
|
|
423
|
+
} catch (error) {
|
|
424
|
+
console.error('Error:', error.message);
|
|
425
|
+
|
|
426
|
+
if (error.message.includes('401')) {
|
|
427
|
+
// Authentication failed
|
|
428
|
+
} else if (error.message.includes('404')) {
|
|
429
|
+
// Resource not found
|
|
430
|
+
} else if (error.message.includes('429')) {
|
|
431
|
+
// Rate limit exceeded
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
|
579
435
|
|
|
580
|
-
|
|
436
|
+
---
|
|
581
437
|
|
|
582
|
-
|
|
583
|
-
- 100K tokens/day
|
|
584
|
-
- 50 messages/day
|
|
585
|
-
- 20 messages/hour
|
|
438
|
+
## Best Practices
|
|
586
439
|
|
|
587
|
-
|
|
440
|
+
1. **Reuse Client**: Create one client instance and share across modules
|
|
441
|
+
2. **Error Handling**: Always wrap API calls in try-catch
|
|
442
|
+
3. **Token Management**: For sandboxes, refresh tokens before 1h expiry
|
|
443
|
+
4. **Resource Cleanup**: Stop/delete unused sandboxes and sessions
|
|
444
|
+
5. **Namespace Organization**: Use namespaces to separate environments
|
|
445
|
+
6. **Tool Validation**: Validate tools before assigning to agents
|
|
588
446
|
|
|
589
|
-
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## Examples
|
|
450
|
+
|
|
451
|
+
### Multi-Agent System
|
|
590
452
|
|
|
591
453
|
```javascript
|
|
592
|
-
//
|
|
593
|
-
await
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
agentId: 'agent-id',
|
|
454
|
+
// Create specialized agents
|
|
455
|
+
const coder = await agents.create({
|
|
456
|
+
name: 'Coder',
|
|
457
|
+
prompts: { identity: 'Expert coder' }
|
|
597
458
|
});
|
|
598
459
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
ip: '5.6.7.8', // Different IP
|
|
603
|
-
fingerprint: 'abc123', // Same fingerprint
|
|
604
|
-
agentId: 'agent-id',
|
|
460
|
+
const reviewer = await agents.create({
|
|
461
|
+
name: 'Reviewer',
|
|
462
|
+
prompts: { identity: 'Code reviewer' }
|
|
605
463
|
});
|
|
606
464
|
|
|
607
|
-
//
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
fingerprint: 'xyz789', // Different fingerprint
|
|
612
|
-
agentId: 'agent-id',
|
|
613
|
-
});
|
|
614
|
-
```
|
|
465
|
+
// Configure each with specific tools
|
|
466
|
+
await agents.agent(coder.agentId).settings.updateTools([
|
|
467
|
+
'web-search', 'code-interpreter'
|
|
468
|
+
]);
|
|
615
469
|
|
|
616
|
-
|
|
470
|
+
await agents.agent(reviewer.agentId).settings.updateTools([
|
|
471
|
+
'code-analyzer', 'security-scanner'
|
|
472
|
+
]);
|
|
473
|
+
```
|
|
617
474
|
|
|
618
|
-
|
|
475
|
+
### Guest Chat System
|
|
619
476
|
|
|
620
477
|
```javascript
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
namespace: '
|
|
478
|
+
// Create agent for customer support
|
|
479
|
+
const supportAgent = await agents.create({
|
|
480
|
+
name: 'Support Bot',
|
|
481
|
+
namespace: 'production'
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// Set guest limits
|
|
485
|
+
await agents.agent(supportAgent.agentId).settings.updateGuestLimits({
|
|
486
|
+
enabled: true,
|
|
487
|
+
max_messages_per_day: 100,
|
|
488
|
+
max_total_tokens_per_day: 50000
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// Create guest session
|
|
492
|
+
const session = await chat.createGuestSession({
|
|
493
|
+
ip: req.ip,
|
|
494
|
+
fingerprint: req.headers['x-fingerprint'],
|
|
495
|
+
agentId: supportAgent.agentId
|
|
625
496
|
});
|
|
626
497
|
```
|
|
627
498
|
|
|
628
|
-
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## Links
|
|
629
502
|
|
|
630
|
-
**
|
|
503
|
+
- **Website**: https://oblien.com
|
|
504
|
+
- **Documentation**: https://docs.oblien.com
|
|
505
|
+
- **Dashboard**: https://dashboard.oblien.com
|
|
506
|
+
- **API Reference**: https://api.oblien.com/docs
|
|
507
|
+
- **Support**: support@oblien.com
|
|
508
|
+
- **GitHub**: https://github.com/oblien/oblien
|
|
631
509
|
|
|
632
|
-
|
|
510
|
+
---
|
|
633
511
|
|
|
634
|
-
|
|
512
|
+
## License
|
|
635
513
|
|
|
636
|
-
-
|
|
637
|
-
- Guest lookup (cached): ~1ms
|
|
638
|
-
- Guest cleanup (1000 guests): ~100ms
|
|
514
|
+
MIT License - see LICENSE file for details
|
|
639
515
|
|
|
640
|
-
|
|
516
|
+
---
|
|
641
517
|
|
|
642
|
-
|
|
643
|
-
- `redis` - Optional, for distributed systems (peer dependency)
|
|
518
|
+
## Changelog
|
|
644
519
|
|
|
645
|
-
|
|
520
|
+
### v1.2.0
|
|
521
|
+
- ✅ Added Sandboxes module
|
|
522
|
+
- ✅ Enhanced Agents module with proper settings sections
|
|
523
|
+
- ✅ Added Tools management
|
|
524
|
+
- ✅ Improved documentation
|
|
646
525
|
|
|
647
|
-
|
|
526
|
+
### v1.1.0
|
|
527
|
+
- ✅ Added Agents module
|
|
528
|
+
- ✅ Added Namespaces module
|
|
529
|
+
- ✅ Guest session support
|
|
648
530
|
|
|
649
|
-
|
|
531
|
+
### v1.0.0
|
|
532
|
+
- ✅ Initial release
|
|
533
|
+
- ✅ Chat module
|
|
534
|
+
- ✅ Credits module
|
|
535
|
+
|
|
536
|
+
---
|
|
650
537
|
|
|
651
|
-
|
|
652
|
-
- [GitHub](https://github.com/oblien/oblien)
|
|
653
|
-
- [Website](https://oblien.com)
|
|
654
|
-
- [React Chat Agent](https://npmjs.com/package/react-chat-agent) - Client-side chat component
|
|
655
|
-
- [Agent Sandbox](https://npmjs.com/package/agent-sandbox) - Sandbox SDK
|
|
656
|
-
- [AI smart assets fetch](https://npmjs.com/package/assets-ai) - Assets AI
|
|
538
|
+
Made with ❤️ by the Oblien Team
|