oblien 1.1.8 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oblien",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Server-side SDK for Oblien AI Platform - Build AI-powered applications with chat, agents, and workflows",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/chat/index.js CHANGED
@@ -20,7 +20,7 @@ export class OblienChat {
20
20
  }
21
21
 
22
22
  this.client = client;
23
-
23
+
24
24
  // Initialize guest manager if not provided
25
25
  this.guestManager = options.guestManager || new GuestManager({
26
26
  storage: options.guestStorage,
@@ -87,15 +87,15 @@ export class OblienChat {
87
87
  * });
88
88
  */
89
89
  async createGuestSession(options) {
90
- const {
91
- ip,
92
- fingerprint,
93
- agentId,
94
- workflowId,
90
+ const {
91
+ ip,
92
+ fingerprint,
93
+ agentId,
94
+ workflowId,
95
95
  namespace,
96
96
  endUserId,
97
- metadata = {},
98
- workspace
97
+ metadata = {},
98
+ workspace
99
99
  } = options;
100
100
 
101
101
  if (!ip) {
@@ -119,7 +119,7 @@ export class OblienChat {
119
119
  });
120
120
 
121
121
  // Use custom namespace if provided, otherwise use guest's default namespace
122
- const sessionNamespace = namespace || guest.namespace;
122
+ const sessionNamespace = namespace || guest.id;
123
123
 
124
124
  const sessionData = await session.create({
125
125
  agentId,
@@ -173,19 +173,22 @@ export class OblienChat {
173
173
  options = { namespace: options };
174
174
  }
175
175
 
176
- const { ip, fingerprint, namespace } = options;
176
+ const agentId = options.agentId || options.agent_id;
177
+ const sessionId = options.sessionId || options.session_id;
178
+ const guestId = options.guestId || options.namespace;
177
179
 
178
- if (!ip && !fingerprint && !namespace) {
179
- throw new Error('Either IP, fingerprint, or namespace is required');
180
+ if (!agentId && !sessionId && !guestId) {
181
+ throw new Error('Either agentId, sessionId, or guestId is required');
180
182
  }
181
183
 
182
- const params = new URLSearchParams();
183
- if (namespace) params.append('namespace', namespace);
184
- if (ip) params.append('ip', ip);
185
- if (fingerprint) params.append('fingerprint', fingerprint);
186
-
187
184
  try {
188
- const response = await this.client.get(`ai/guest/info?${params.toString()}`);
185
+ const response = await this.client.post(`ai/guest/info`, {
186
+ ip,
187
+ fingerprint,
188
+ namespace: namespace || guestId,
189
+ agent_id: agentId,
190
+ session_id: sessionId,
191
+ });
189
192
  return response.success ? response.guest : null;
190
193
  } catch (error) {
191
194
  // Return null if guest not found (404)
@@ -219,7 +222,7 @@ export class OblienChat {
219
222
  const guest = await this.guestManager.getGuest(guestIdByIp);
220
223
  if (guest) return guest;
221
224
  }
222
-
225
+
223
226
  // Fallback to old method (generate guest ID from IP)
224
227
  const fallbackGuestId = this.guestManager.generateGuestId(ip);
225
228
  return await this.guestManager.getGuest(fallbackGuestId);
@@ -245,16 +248,16 @@ export class OblienChat {
245
248
  * @returns {Promise<Object>} Response data
246
249
  */
247
250
  async send(options = {}) {
248
- const {
251
+ const {
249
252
  token,
250
253
  message,
251
- uploadId,
252
- files,
253
- stream = false,
254
+ uploadId,
255
+ files,
256
+ stream = false,
254
257
  onChunk,
255
258
  onError,
256
259
  onComplete,
257
- metadata = {}
260
+ metadata = {}
258
261
  } = options;
259
262
 
260
263
  if (!message || !message.trim()) {
@@ -308,7 +311,7 @@ export class OblienChat {
308
311
  try {
309
312
  while (true) {
310
313
  const { done, value } = await reader.read();
311
-
314
+
312
315
  if (done) {
313
316
  if (onComplete) onComplete();
314
317
  break;
@@ -320,7 +323,7 @@ export class OblienChat {
320
323
 
321
324
  for (const line of lines) {
322
325
  if (line.trim() === '') continue;
323
-
326
+
324
327
  try {
325
328
  const data = JSON.parse(line);
326
329
  if (onChunk) onChunk(data);
@@ -379,10 +382,10 @@ export class OblienChat {
379
382
  }
380
383
 
381
384
  const formData = new FormData();
382
-
385
+
383
386
  // Handle both single file and array of files
384
387
  const fileArray = Array.isArray(files) ? files : [files];
385
-
388
+
386
389
  fileArray.forEach((file, index) => {
387
390
  if (file instanceof File || file instanceof Blob) {
388
391
  formData.append('files', file);
@@ -542,7 +545,7 @@ export class OblienChat {
542
545
  const session = new ChatSession({
543
546
  client: this.client,
544
547
  });
545
-
548
+
546
549
  return await session.list(options);
547
550
  }
548
551
 
@@ -178,7 +178,11 @@ export class GuestManager {
178
178
  * @returns {Promise<Object|null>} Guest object or null
179
179
  */
180
180
  async getGuest(guestId) {
181
- return await this.storage.get(`guest:${guestId}`);
181
+ try {
182
+ return await this.storage.get(`guest:${guestId}`);
183
+ } catch (error) {
184
+ return null;
185
+ }
182
186
  }
183
187
 
184
188
  /**
@@ -421,7 +425,7 @@ export class RedisStorage {
421
425
  async set(key, value, ttl) {
422
426
  const data = JSON.stringify(value);
423
427
  if (ttl) {
424
- await this.redis.setEx(key, ttl, data);
428
+ await this.redis.setex(key, ttl, data);
425
429
  } else {
426
430
  await this.redis.set(key, data);
427
431
  }