oblien 1.0.7 → 1.1.1
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 +387 -408
- package/agents.js +14 -0
- package/credits.js +11 -0
- package/icons.js +11 -0
- package/index.d.ts +261 -0
- package/index.js +23 -0
- package/namespaces.js +12 -0
- package/package.json +13 -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/client.js +18 -0
- package/src/credits/index.js +299 -0
- package/src/icons/index.js +185 -0
- package/src/namespaces/index.js +225 -0
- package/src/namespaces/namespace.js +274 -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 support** - Pass user ID for authenticated session tracking
|
|
11
|
-
- ⚡ **Automatic rate limiting** - Built-in limits for guest sessions
|
|
12
|
-
- 💾 **Flexible storage** - NodeCache (default), Redis, or custom adapters
|
|
13
|
-
- 🎯 **Single function for guest lookup** - `getGuest(ip, fingerprint)` handles both
|
|
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,543 +8,532 @@ 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
|
-
|
|
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
|
+
apiKey: 'your-client-id',
|
|
29
|
+
apiSecret: 'your-client-secret',
|
|
30
|
+
baseURL: 'https://api.oblien.com' // Optional
|
|
58
31
|
});
|
|
59
32
|
|
|
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
|
-
});
|
|
33
|
+
// Use modules
|
|
34
|
+
const agents = new OblienAgents(client);
|
|
35
|
+
const chat = new OblienChat(client);
|
|
36
|
+
const sandboxes = new OblienSandboxes(client);
|
|
37
|
+
const search = new OblienSearch(client);
|
|
38
|
+
const icons = new OblienIcons(client);
|
|
83
39
|
```
|
|
84
40
|
|
|
85
|
-
|
|
41
|
+
---
|
|
86
42
|
|
|
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
|
-
```
|
|
43
|
+
## Modules Overview
|
|
113
44
|
|
|
114
|
-
|
|
45
|
+
### 🤖 Agents Module
|
|
115
46
|
|
|
116
|
-
|
|
47
|
+
Manage AI agents with settings, tools, and analytics.
|
|
117
48
|
|
|
118
49
|
```javascript
|
|
119
|
-
import {
|
|
120
|
-
|
|
121
|
-
const chat = new OblienChat(client);
|
|
50
|
+
import { OblienAgents } from 'oblien/agents';
|
|
122
51
|
|
|
123
|
-
|
|
124
|
-
app.post('/api/guest-session', async (req, res) => {
|
|
125
|
-
const ip = req.ip || req.headers['x-forwarded-for'];
|
|
126
|
-
const fingerprint = req.body.fingerprint; // Browser fingerprint
|
|
127
|
-
|
|
128
|
-
const session = await chat.createGuestSession({
|
|
129
|
-
ip,
|
|
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
|
-
});
|
|
52
|
+
const agents = new OblienAgents(client);
|
|
137
53
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
54
|
+
// Create agent
|
|
55
|
+
const agent = await agents.create({
|
|
56
|
+
name: 'Support Agent',
|
|
57
|
+
namespace: 'production',
|
|
58
|
+
prompts: {
|
|
59
|
+
identity: 'You are a helpful assistant.'
|
|
60
|
+
}
|
|
144
61
|
});
|
|
145
|
-
```
|
|
146
62
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
- ✅ Auto-expiring sessions (24h TTL)
|
|
154
|
-
- ✅ Built-in caching with `node-cache` (no Redis required!)
|
|
155
|
-
- ✅ Optional Redis support for distributed systems
|
|
63
|
+
// Configure settings
|
|
64
|
+
const agentInstance = agents.agent(agent.agentId);
|
|
65
|
+
await agentInstance.settings.updateModelConfig({
|
|
66
|
+
model: 'oblien-master',
|
|
67
|
+
temperature: 0.8
|
|
68
|
+
});
|
|
156
69
|
|
|
157
|
-
|
|
70
|
+
// Assign tools
|
|
71
|
+
await agentInstance.settings.updateTools(['web-search', 'calculator']);
|
|
158
72
|
|
|
159
|
-
|
|
73
|
+
// Get analytics
|
|
74
|
+
const overview = await agentInstance.getOverview({ days: 7 });
|
|
75
|
+
```
|
|
160
76
|
|
|
161
|
-
|
|
162
|
-
-
|
|
163
|
-
-
|
|
77
|
+
**Features:**
|
|
78
|
+
- ✅ CRUD operations (create, read, update, delete)
|
|
79
|
+
- ✅ Settings management (5 sections: switches, model, tools, guest limits, context)
|
|
80
|
+
- ✅ Tools management (list, search, create, validate)
|
|
81
|
+
- ✅ Analytics & monitoring
|
|
82
|
+
- ✅ Namespace support
|
|
83
|
+
- ✅ User management
|
|
164
84
|
|
|
165
|
-
|
|
85
|
+
📖 [Full Documentation](./docs/AGENTS_COMPLETE.md) | 💡 [Examples](./examples/agents-complete-example.js)
|
|
166
86
|
|
|
167
|
-
|
|
87
|
+
---
|
|
168
88
|
|
|
169
|
-
###
|
|
89
|
+
### 💬 Chat Module
|
|
170
90
|
|
|
171
|
-
|
|
91
|
+
Create and manage chat sessions with guest support.
|
|
172
92
|
|
|
173
93
|
```javascript
|
|
174
94
|
import { OblienChat } from 'oblien/chat';
|
|
175
95
|
|
|
176
96
|
const chat = new OblienChat(client);
|
|
177
|
-
// Uses NodeCacheStorage by default
|
|
178
|
-
// Automatic expiration, memory management, and cleanup
|
|
179
|
-
```
|
|
180
97
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const storage = new NodeCacheStorage(86400); // 24 hours TTL
|
|
98
|
+
// Create session
|
|
99
|
+
const session = await chat.createSession({
|
|
100
|
+
agentId: 'agent-id',
|
|
101
|
+
namespace: 'production'
|
|
102
|
+
});
|
|
187
103
|
|
|
188
|
-
|
|
189
|
-
|
|
104
|
+
// Create guest session
|
|
105
|
+
const guestSession = await chat.createGuestSession({
|
|
106
|
+
ip: '192.168.1.1',
|
|
107
|
+
fingerprint: 'abc123',
|
|
108
|
+
agentId: 'agent-id'
|
|
190
109
|
});
|
|
191
110
|
|
|
192
|
-
//
|
|
193
|
-
|
|
111
|
+
// List sessions
|
|
112
|
+
const sessions = await chat.listSessions({ limit: 20 });
|
|
194
113
|
```
|
|
195
114
|
|
|
196
|
-
|
|
115
|
+
**Features:**
|
|
116
|
+
- ✅ Session management
|
|
117
|
+
- ✅ Guest sessions with fingerprint tracking
|
|
118
|
+
- ✅ Token generation
|
|
119
|
+
- ✅ Automatic guest ID generation
|
|
197
120
|
|
|
198
|
-
|
|
199
|
-
import { createClient } from 'redis';
|
|
200
|
-
import { OblienChat, RedisStorage } from 'oblien/chat';
|
|
121
|
+
📖 [Documentation](./docs/CHAT.md) | 💡 [Examples](./examples/chat-example.js)
|
|
201
122
|
|
|
202
|
-
|
|
203
|
-
await redis.connect();
|
|
123
|
+
---
|
|
204
124
|
|
|
205
|
-
|
|
206
|
-
guestStorage: new RedisStorage(redis),
|
|
207
|
-
guestTTL: 86400, // 24 hours
|
|
208
|
-
});
|
|
209
|
-
```
|
|
125
|
+
### 📦 Sandboxes Module
|
|
210
126
|
|
|
211
|
-
|
|
127
|
+
Manage cloud sandboxes (containerized environments).
|
|
212
128
|
|
|
213
129
|
```javascript
|
|
214
|
-
import {
|
|
130
|
+
import { OblienSandboxes } from 'oblien/sandbox';
|
|
131
|
+
|
|
132
|
+
const sandboxes = new OblienSandboxes(client);
|
|
215
133
|
|
|
216
|
-
|
|
217
|
-
|
|
134
|
+
// Create sandbox
|
|
135
|
+
const sandbox = await sandboxes.create({
|
|
136
|
+
name: 'my-dev-env',
|
|
137
|
+
region: 'us-east-1',
|
|
138
|
+
template: 'node-20',
|
|
139
|
+
autoStart: true
|
|
218
140
|
});
|
|
219
|
-
// Note: Basic Map storage, no advanced features
|
|
220
|
-
```
|
|
221
141
|
|
|
222
|
-
|
|
142
|
+
// Use sandbox
|
|
143
|
+
const { url, token } = sandbox.sandbox;
|
|
144
|
+
const response = await fetch(`${url}/files/list`, {
|
|
145
|
+
headers: { 'Authorization': `Bearer ${token}` }
|
|
146
|
+
});
|
|
223
147
|
|
|
224
|
-
|
|
148
|
+
// Control lifecycle
|
|
149
|
+
await sandboxes.stop(sandboxId);
|
|
150
|
+
await sandboxes.start(sandboxId);
|
|
151
|
+
await sandboxes.restart(sandboxId);
|
|
225
152
|
|
|
226
|
-
|
|
153
|
+
// Regenerate token (1h expiry)
|
|
154
|
+
const newToken = await sandboxes.regenerateToken(sandboxId);
|
|
227
155
|
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
apiKey: string,
|
|
231
|
-
apiSecret?: string,
|
|
232
|
-
baseURL?: string,
|
|
233
|
-
});
|
|
156
|
+
// Get metrics
|
|
157
|
+
const metrics = await sandboxes.getMetrics(sandboxId);
|
|
234
158
|
```
|
|
235
159
|
|
|
236
|
-
|
|
160
|
+
**Features:**
|
|
161
|
+
- ✅ Create, start, stop, restart, delete sandboxes
|
|
162
|
+
- ✅ Auto-start option
|
|
163
|
+
- ✅ Token management (1h JWT)
|
|
164
|
+
- ✅ Resource metrics
|
|
165
|
+
- ✅ Multiple templates & regions
|
|
166
|
+
- ✅ Platform statistics
|
|
237
167
|
|
|
238
|
-
|
|
168
|
+
📖 [Full Documentation](./docs/SANDBOXES.md) | 💡 [Examples](./examples/sandbox-example.js)
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### 🗂️ Namespaces Module
|
|
173
|
+
|
|
174
|
+
Manage namespaces and service configurations.
|
|
239
175
|
|
|
240
176
|
```javascript
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
177
|
+
import { OblienNamespaces } from 'oblien/namespaces';
|
|
178
|
+
|
|
179
|
+
const namespaces = new OblienNamespaces(client);
|
|
180
|
+
|
|
181
|
+
// Create namespace
|
|
182
|
+
const namespace = await namespaces.create({
|
|
183
|
+
name: 'production',
|
|
184
|
+
slug: 'prod',
|
|
185
|
+
type: 'production'
|
|
249
186
|
});
|
|
250
187
|
|
|
251
|
-
//
|
|
252
|
-
await
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
workflowId?,
|
|
257
|
-
metadata?,
|
|
258
|
-
workspace?
|
|
188
|
+
// Configure services
|
|
189
|
+
await namespaces.configureService(namespaceId, {
|
|
190
|
+
service: 'ai',
|
|
191
|
+
enabled: true,
|
|
192
|
+
config: { /* ... */ }
|
|
259
193
|
});
|
|
260
194
|
|
|
261
|
-
// Get
|
|
262
|
-
await
|
|
195
|
+
// Get usage stats
|
|
196
|
+
const usage = await namespaces.getUsage(namespaceId);
|
|
197
|
+
```
|
|
263
198
|
|
|
264
|
-
|
|
265
|
-
|
|
199
|
+
**Features:**
|
|
200
|
+
- ✅ Namespace CRUD
|
|
201
|
+
- ✅ Service configuration
|
|
202
|
+
- ✅ Usage tracking
|
|
203
|
+
- ✅ Activity logs
|
|
266
204
|
|
|
267
|
-
|
|
268
|
-
await chat.deleteSession(sessionId);
|
|
205
|
+
📖 [Documentation](./docs/NAMESPACES.md)
|
|
269
206
|
|
|
270
|
-
|
|
271
|
-
await chat.getGuest(ip, fingerprint?); // NEW: Unified function for IP and/or fingerprint lookup
|
|
272
|
-
await chat.getAllGuests(); // Admin only
|
|
273
|
-
await chat.cleanupGuests(); // Clean expired
|
|
274
|
-
```
|
|
207
|
+
---
|
|
275
208
|
|
|
276
|
-
###
|
|
209
|
+
### 🎨 Icons Module
|
|
277
210
|
|
|
278
|
-
|
|
211
|
+
Search and fetch icons, images, and videos using AI-powered semantic search.
|
|
279
212
|
|
|
280
213
|
```javascript
|
|
281
|
-
import {
|
|
214
|
+
import { OblienIcons } from 'oblien/icons';
|
|
215
|
+
|
|
216
|
+
const icons = new OblienIcons(client);
|
|
217
|
+
|
|
218
|
+
// Search for icons
|
|
219
|
+
const results = await icons.search('home', { limit: 20 });
|
|
220
|
+
|
|
221
|
+
// Fetch specific icons
|
|
222
|
+
const icon = await icons.fetchIcon('settings gear');
|
|
223
|
+
|
|
224
|
+
// Fetch multiple icons at once
|
|
225
|
+
const iconSet = await icons.fetchIcons([
|
|
226
|
+
'home',
|
|
227
|
+
'user profile',
|
|
228
|
+
'settings',
|
|
229
|
+
'notification bell'
|
|
230
|
+
]);
|
|
231
|
+
|
|
232
|
+
// Fetch mixed media (icons, images, videos)
|
|
233
|
+
const media = await icons.fetch([
|
|
234
|
+
{ type: 'icon', description: 'user avatar' },
|
|
235
|
+
{ type: 'image', description: 'mountain landscape' },
|
|
236
|
+
{ type: 'video', description: 'product demo' }
|
|
237
|
+
]);
|
|
238
|
+
```
|
|
282
239
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
240
|
+
**Features:**
|
|
241
|
+
- ✅ Semantic icon search with AI embeddings
|
|
242
|
+
- ✅ Fetch icons, images, and videos
|
|
243
|
+
- ✅ Relevance scoring
|
|
244
|
+
- ✅ Multiple icon styles (Outline, Filled, etc.)
|
|
245
|
+
- ✅ Batch fetching
|
|
246
|
+
- ✅ Pagination support
|
|
247
|
+
- ✅ CDN-hosted assets
|
|
288
248
|
|
|
289
|
-
|
|
290
|
-
await guestManager.getOrCreateGuest(ip, fingerprint?, metadata?);
|
|
249
|
+
📖 [Full Documentation](./docs/ICONS.md) | 💡 [Examples](./examples/icons-example.js)
|
|
291
250
|
|
|
292
|
-
|
|
293
|
-
await guestManager.findExistingGuest(fingerprint, ip);
|
|
251
|
+
---
|
|
294
252
|
|
|
295
|
-
|
|
296
|
-
await guestManager.updateGuest(guestId, updates);
|
|
297
|
-
await guestManager.deleteGuest(guestId);
|
|
298
|
-
await guestManager.getAllGuests();
|
|
299
|
-
await guestManager.cleanup();
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
## Complete Example
|
|
253
|
+
### 💳 Credits Module
|
|
303
254
|
|
|
304
|
-
|
|
255
|
+
Manage billing and credits.
|
|
305
256
|
|
|
306
257
|
```javascript
|
|
307
|
-
import
|
|
308
|
-
import { OblienClient, OblienChat } from 'oblien';
|
|
258
|
+
import { OblienCredits } from 'oblien/credits';
|
|
309
259
|
|
|
310
|
-
const
|
|
311
|
-
app.use(express.json());
|
|
260
|
+
const credits = new OblienCredits(client);
|
|
312
261
|
|
|
313
|
-
//
|
|
314
|
-
const
|
|
315
|
-
apiKey: process.env.OBLIEN_API_KEY,
|
|
316
|
-
apiSecret: process.env.OBLIEN_API_SECRET,
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
const chat = new OblienChat(client);
|
|
262
|
+
// Get balance
|
|
263
|
+
const balance = await credits.getBalance();
|
|
320
264
|
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const session = await chat.createSession({
|
|
325
|
-
agentId: req.body.agentId,
|
|
326
|
-
namespace: req.user.id, // Pass user ID as namespace
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
res.json(session);
|
|
330
|
-
} catch (error) {
|
|
331
|
-
res.status(500).json({ error: error.message });
|
|
332
|
-
}
|
|
333
|
-
});
|
|
265
|
+
// Get usage
|
|
266
|
+
const usage = await credits.getUsage({ period: 'monthly' });
|
|
267
|
+
```
|
|
334
268
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const fingerprint = req.body.fingerprint; // From client
|
|
340
|
-
|
|
341
|
-
// Check for existing guest first
|
|
342
|
-
const existingGuest = await chat.getGuest(ip, fingerprint);
|
|
343
|
-
|
|
344
|
-
if (existingGuest && existingGuest.sessions.length > 0) {
|
|
345
|
-
// Return existing session if available
|
|
346
|
-
const latestSession = existingGuest.sessions[existingGuest.sessions.length - 1];
|
|
347
|
-
const sessionDetails = await chat.getSession(latestSession);
|
|
348
|
-
|
|
349
|
-
if (sessionDetails?.token) {
|
|
350
|
-
return res.json({
|
|
351
|
-
...sessionDetails,
|
|
352
|
-
isExisting: true,
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Create new guest session
|
|
358
|
-
const session = await chat.createGuestSession({
|
|
359
|
-
ip,
|
|
360
|
-
fingerprint,
|
|
361
|
-
agentId: req.body.agentId,
|
|
362
|
-
metadata: {
|
|
363
|
-
userAgent: req.headers['user-agent'],
|
|
364
|
-
},
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
res.json(session);
|
|
368
|
-
} catch (error) {
|
|
369
|
-
res.status(500).json({ error: error.message });
|
|
370
|
-
}
|
|
371
|
-
});
|
|
269
|
+
**Features:**
|
|
270
|
+
- ✅ Balance checking
|
|
271
|
+
- ✅ Usage tracking
|
|
272
|
+
- ✅ Transaction history
|
|
372
273
|
|
|
373
|
-
|
|
374
|
-
```
|
|
274
|
+
---
|
|
375
275
|
|
|
376
|
-
|
|
276
|
+
## Complete Example
|
|
377
277
|
|
|
378
278
|
```javascript
|
|
379
|
-
//
|
|
380
|
-
import { OblienClient
|
|
279
|
+
// Import client and modules
|
|
280
|
+
import { OblienClient } from 'oblien';
|
|
281
|
+
import { OblienAgents } from 'oblien/agents';
|
|
282
|
+
import { OblienChat } from 'oblien/chat';
|
|
283
|
+
import { OblienSandboxes } from 'oblien/sandbox';
|
|
381
284
|
|
|
285
|
+
// Initialize
|
|
382
286
|
const client = new OblienClient({
|
|
383
|
-
apiKey:
|
|
384
|
-
apiSecret:
|
|
287
|
+
apiKey: 'your-client-id',
|
|
288
|
+
apiSecret: 'your-client-secret'
|
|
385
289
|
});
|
|
386
290
|
|
|
291
|
+
const agents = new OblienAgents(client);
|
|
387
292
|
const chat = new OblienChat(client);
|
|
293
|
+
const sandboxes = new OblienSandboxes(client);
|
|
294
|
+
|
|
295
|
+
async function main() {
|
|
296
|
+
// 1. Create agent with tools
|
|
297
|
+
const agent = await agents.create({
|
|
298
|
+
name: 'Code Assistant',
|
|
299
|
+
namespace: 'production',
|
|
300
|
+
prompts: {
|
|
301
|
+
identity: 'You are a coding assistant.'
|
|
302
|
+
}
|
|
303
|
+
});
|
|
388
304
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
305
|
+
// Configure agent
|
|
306
|
+
const agentInstance = agents.agent(agent.agentId);
|
|
307
|
+
await agentInstance.settings.updateTools(['web-search', 'calculator']);
|
|
308
|
+
await agentInstance.settings.updateModelConfig({
|
|
309
|
+
temperature: 0.7,
|
|
310
|
+
max_tokens: 3000
|
|
311
|
+
});
|
|
393
312
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const session = await chat.createGuestSession({
|
|
401
|
-
ip,
|
|
402
|
-
fingerprint, // Dual-layer identification
|
|
403
|
-
agentId: req.body.agentId,
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
return res.json(session);
|
|
407
|
-
}
|
|
313
|
+
// 2. Create sandbox for code execution
|
|
314
|
+
const sandbox = await sandboxes.create({
|
|
315
|
+
name: 'code-env',
|
|
316
|
+
template: 'node-20',
|
|
317
|
+
autoStart: true
|
|
318
|
+
});
|
|
408
319
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
320
|
+
// 3. Create chat session
|
|
321
|
+
const session = await chat.createSession({
|
|
322
|
+
agentId: agent.agentId,
|
|
323
|
+
namespace: 'production'
|
|
324
|
+
});
|
|
414
325
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
326
|
+
console.log('Setup complete!');
|
|
327
|
+
console.log('- Agent ID:', agent.agentId);
|
|
328
|
+
console.log('- Sandbox URL:', sandbox.sandbox.url);
|
|
329
|
+
console.log('- Session ID:', session.sessionId);
|
|
419
330
|
}
|
|
331
|
+
|
|
332
|
+
main();
|
|
420
333
|
```
|
|
421
334
|
|
|
422
|
-
|
|
335
|
+
---
|
|
423
336
|
|
|
424
|
-
|
|
425
|
-
OBLIEN_API_KEY=your-api-key
|
|
426
|
-
OBLIEN_API_SECRET=your-api-secret
|
|
427
|
-
OBLIEN_BASE_URL=https://api.oblien.com # Optional
|
|
428
|
-
```
|
|
337
|
+
## Module Structure
|
|
429
338
|
|
|
430
|
-
|
|
339
|
+
```
|
|
340
|
+
oblien/
|
|
341
|
+
├── src/
|
|
342
|
+
│ ├── agents/ # Agents management
|
|
343
|
+
│ │ ├── index.js # OblienAgents class
|
|
344
|
+
│ │ ├── agent.js # Agent instance
|
|
345
|
+
│ │ ├── settings.js # AgentSettings class
|
|
346
|
+
│ │ └── tools.js # Tools class
|
|
347
|
+
│ ├── chat/ # Chat sessions
|
|
348
|
+
│ │ ├── index.js # OblienChat class
|
|
349
|
+
│ │ └── session.js # ChatSession class
|
|
350
|
+
│ ├── sandbox/ # Sandboxes management
|
|
351
|
+
│ │ ├── index.js # OblienSandboxes class
|
|
352
|
+
│ │ └── sandbox.js # Sandbox instance
|
|
353
|
+
│ ├── namespaces/ # Namespaces management
|
|
354
|
+
│ ├── credits/ # Credits & billing
|
|
355
|
+
│ └── client.js # OblienClient (base)
|
|
356
|
+
├── docs/ # Documentation
|
|
357
|
+
│ ├── AGENTS_COMPLETE.md
|
|
358
|
+
│ ├── SANDBOXES.md
|
|
359
|
+
│ ├── CHAT.md
|
|
360
|
+
│ └── NAMESPACES.md
|
|
361
|
+
└── examples/ # Usage examples
|
|
362
|
+
├── agents-complete-example.js
|
|
363
|
+
├── sandbox-example.js
|
|
364
|
+
└── chat-example.js
|
|
365
|
+
```
|
|
431
366
|
|
|
432
|
-
|
|
433
|
-
|---------|-------------------|----------|-------|
|
|
434
|
-
| **Setup** | ✅ Zero config | ✅ Zero config | ⚠️ Requires Redis |
|
|
435
|
-
| **Auto-expiry** | ✅ Yes | ✅ Manual | ✅ Yes |
|
|
436
|
-
| **Memory limit** | ✅ Configurable | ❌ No | ✅ Configurable |
|
|
437
|
-
| **Statistics** | ✅ Yes | ❌ No | ⚠️ Via Redis |
|
|
438
|
-
| **Distributed** | ❌ Single instance | ❌ Single instance | ✅ Multi-server |
|
|
439
|
-
| **Persistence** | ❌ Memory only | ❌ Memory only | ✅ Disk backup |
|
|
440
|
-
| **Production** | ✅ Recommended | ❌ Dev only | ✅ High-traffic |
|
|
367
|
+
---
|
|
441
368
|
|
|
442
|
-
|
|
369
|
+
## API Endpoints
|
|
443
370
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
371
|
+
| Module | Base Path | Operations |
|
|
372
|
+
|--------|-----------|------------|
|
|
373
|
+
| **Agents** | `/ai/agents` | CRUD, settings, tools, analytics |
|
|
374
|
+
| **Chat** | `/ai/session` | Create, list, history |
|
|
375
|
+
| **Sandboxes** | `/sandbox` | CRUD, start/stop/restart, metrics |
|
|
376
|
+
| **Tools** | `/ai/tools` | List, search, create |
|
|
377
|
+
| **Namespaces** | `/namespaces` | CRUD, services, usage |
|
|
447
378
|
|
|
448
|
-
|
|
379
|
+
---
|
|
449
380
|
|
|
450
|
-
|
|
381
|
+
## Authentication
|
|
451
382
|
|
|
452
|
-
|
|
453
|
-
- `express-server.js` - Full Express.js implementation
|
|
454
|
-
- `nextjs-api-route.js` - Next.js API routes (App Router & Pages Router)
|
|
455
|
-
- `with-redis.js` - Production setup with Redis
|
|
383
|
+
All modules use client credentials authentication:
|
|
456
384
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
385
|
+
```javascript
|
|
386
|
+
const client = new OblienClient({
|
|
387
|
+
apiKey: 'your-client-id', // X-Client-ID header
|
|
388
|
+
apiSecret: 'your-client-secret' // X-Client-Secret header
|
|
389
|
+
});
|
|
461
390
|
```
|
|
462
391
|
|
|
392
|
+
Get your credentials from the [Oblien Dashboard](https://dashboard.oblien.com).
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
463
396
|
## TypeScript Support
|
|
464
397
|
|
|
465
|
-
|
|
398
|
+
The SDK includes TypeScript definitions:
|
|
466
399
|
|
|
467
400
|
```typescript
|
|
468
|
-
import {
|
|
401
|
+
import {
|
|
402
|
+
OblienClient,
|
|
403
|
+
OblienAgents,
|
|
404
|
+
Agent,
|
|
405
|
+
AgentSettings,
|
|
406
|
+
Tools,
|
|
407
|
+
OblienSandboxes,
|
|
408
|
+
Sandbox
|
|
409
|
+
} from 'oblien';
|
|
469
410
|
|
|
470
411
|
const client: OblienClient = new OblienClient({
|
|
471
412
|
apiKey: string,
|
|
472
|
-
apiSecret
|
|
413
|
+
apiSecret: string
|
|
473
414
|
});
|
|
474
|
-
|
|
475
|
-
const chat: OblienChat = new OblienChat(client);
|
|
476
415
|
```
|
|
477
416
|
|
|
478
|
-
|
|
417
|
+
---
|
|
479
418
|
|
|
480
|
-
|
|
419
|
+
## Error Handling
|
|
481
420
|
|
|
482
|
-
|
|
421
|
+
```javascript
|
|
422
|
+
try {
|
|
423
|
+
const agent = await agents.create({ /* ... */ });
|
|
424
|
+
} catch (error) {
|
|
425
|
+
console.error('Error:', error.message);
|
|
426
|
+
|
|
427
|
+
if (error.message.includes('401')) {
|
|
428
|
+
// Authentication failed
|
|
429
|
+
} else if (error.message.includes('404')) {
|
|
430
|
+
// Resource not found
|
|
431
|
+
} else if (error.message.includes('429')) {
|
|
432
|
+
// Rate limit exceeded
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
483
438
|
|
|
484
|
-
|
|
439
|
+
## Best Practices
|
|
485
440
|
|
|
486
|
-
**
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
441
|
+
1. **Reuse Client**: Create one client instance and share across modules
|
|
442
|
+
2. **Error Handling**: Always wrap API calls in try-catch
|
|
443
|
+
3. **Token Management**: For sandboxes, refresh tokens before 1h expiry
|
|
444
|
+
4. **Resource Cleanup**: Stop/delete unused sandboxes and sessions
|
|
445
|
+
5. **Namespace Organization**: Use namespaces to separate environments
|
|
446
|
+
6. **Tool Validation**: Validate tools before assigning to agents
|
|
490
447
|
|
|
491
|
-
|
|
448
|
+
---
|
|
492
449
|
|
|
493
|
-
|
|
450
|
+
## Examples
|
|
451
|
+
|
|
452
|
+
### Multi-Agent System
|
|
494
453
|
|
|
495
454
|
```javascript
|
|
496
|
-
//
|
|
497
|
-
await
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
agentId: 'agent-id',
|
|
455
|
+
// Create specialized agents
|
|
456
|
+
const coder = await agents.create({
|
|
457
|
+
name: 'Coder',
|
|
458
|
+
prompts: { identity: 'Expert coder' }
|
|
501
459
|
});
|
|
502
460
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
ip: '5.6.7.8', // Different IP
|
|
507
|
-
fingerprint: 'abc123', // Same fingerprint
|
|
508
|
-
agentId: 'agent-id',
|
|
461
|
+
const reviewer = await agents.create({
|
|
462
|
+
name: 'Reviewer',
|
|
463
|
+
prompts: { identity: 'Code reviewer' }
|
|
509
464
|
});
|
|
510
465
|
|
|
511
|
-
//
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
fingerprint: 'xyz789', // Different fingerprint
|
|
516
|
-
agentId: 'agent-id',
|
|
517
|
-
});
|
|
518
|
-
```
|
|
466
|
+
// Configure each with specific tools
|
|
467
|
+
await agents.agent(coder.agentId).settings.updateTools([
|
|
468
|
+
'web-search', 'code-interpreter'
|
|
469
|
+
]);
|
|
519
470
|
|
|
520
|
-
|
|
471
|
+
await agents.agent(reviewer.agentId).settings.updateTools([
|
|
472
|
+
'code-analyzer', 'security-scanner'
|
|
473
|
+
]);
|
|
474
|
+
```
|
|
521
475
|
|
|
522
|
-
|
|
476
|
+
### Guest Chat System
|
|
523
477
|
|
|
524
478
|
```javascript
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
namespace: '
|
|
479
|
+
// Create agent for customer support
|
|
480
|
+
const supportAgent = await agents.create({
|
|
481
|
+
name: 'Support Bot',
|
|
482
|
+
namespace: 'production'
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// Set guest limits
|
|
486
|
+
await agents.agent(supportAgent.agentId).settings.updateGuestLimits({
|
|
487
|
+
enabled: true,
|
|
488
|
+
max_messages_per_day: 100,
|
|
489
|
+
max_total_tokens_per_day: 50000
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
// Create guest session
|
|
493
|
+
const session = await chat.createGuestSession({
|
|
494
|
+
ip: req.ip,
|
|
495
|
+
fingerprint: req.headers['x-fingerprint'],
|
|
496
|
+
agentId: supportAgent.agentId
|
|
529
497
|
});
|
|
530
498
|
```
|
|
531
499
|
|
|
532
|
-
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
## Links
|
|
503
|
+
|
|
504
|
+
- **Website**: https://oblien.com
|
|
505
|
+
- **Documentation**: https://docs.oblien.com
|
|
506
|
+
- **Dashboard**: https://dashboard.oblien.com
|
|
507
|
+
- **API Reference**: https://api.oblien.com/docs
|
|
508
|
+
- **Support**: support@oblien.com
|
|
509
|
+
- **GitHub**: https://github.com/oblien/oblien
|
|
533
510
|
|
|
534
|
-
|
|
511
|
+
---
|
|
535
512
|
|
|
536
|
-
##
|
|
513
|
+
## License
|
|
537
514
|
|
|
538
|
-
|
|
515
|
+
MIT License - see LICENSE file for details
|
|
539
516
|
|
|
540
|
-
|
|
541
|
-
- Guest lookup (cached): ~1ms
|
|
542
|
-
- Guest cleanup (1000 guests): ~100ms
|
|
517
|
+
---
|
|
543
518
|
|
|
544
|
-
##
|
|
519
|
+
## Changelog
|
|
545
520
|
|
|
546
|
-
|
|
547
|
-
-
|
|
521
|
+
### v1.2.0
|
|
522
|
+
- ✅ Added Sandboxes module
|
|
523
|
+
- ✅ Enhanced Agents module with proper settings sections
|
|
524
|
+
- ✅ Added Tools management
|
|
525
|
+
- ✅ Improved documentation
|
|
548
526
|
|
|
549
|
-
|
|
527
|
+
### v1.1.0
|
|
528
|
+
- ✅ Added Agents module
|
|
529
|
+
- ✅ Added Namespaces module
|
|
530
|
+
- ✅ Guest session support
|
|
550
531
|
|
|
551
|
-
|
|
532
|
+
### v1.0.0
|
|
533
|
+
- ✅ Initial release
|
|
534
|
+
- ✅ Chat module
|
|
535
|
+
- ✅ Credits module
|
|
552
536
|
|
|
553
|
-
|
|
537
|
+
---
|
|
554
538
|
|
|
555
|
-
|
|
556
|
-
- [GitHub](https://github.com/oblien/oblien)
|
|
557
|
-
- [Website](https://oblien.com)
|
|
558
|
-
- [React Chat Agent](https://npmjs.com/package/react-chat-agent) - Client-side chat component
|
|
559
|
-
- [Agent Sandbox](https://npmjs.com/package/agent-sandbox) - Sandbox SDK
|
|
560
|
-
- [AI smart assets fetch](https://npmjs.com/package/assets-ai) - Assets AI
|
|
539
|
+
Made with ❤️ by the Oblien Team
|