oblien 1.2.2 → 1.2.4
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/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/chat/index.js +20 -28
- package/src/chat/session.js +1 -0
package/index.d.ts
CHANGED
|
@@ -308,7 +308,7 @@ export class OblienChat {
|
|
|
308
308
|
// Session Creation
|
|
309
309
|
createSession(options: CreateSessionOptions): Promise<SessionData>;
|
|
310
310
|
createGuestSession(options: CreateGuestSessionOptions): Promise<GuestSessionData>;
|
|
311
|
-
getGuest(options: GetGuestOptions | string): Promise<Guest | null>; // From Oblien API (string = namespace)
|
|
311
|
+
getGuest(options: GetGuestOptions | string, getSessions?: boolean): Promise<Guest | null>; // From Oblien API (string = namespace)
|
|
312
312
|
getGuestFromCache(ip: string, fingerprint?: string): Promise<Guest | null>; // From local cache
|
|
313
313
|
|
|
314
314
|
// Session Token Management (Server-side)
|
package/package.json
CHANGED
package/src/chat/index.js
CHANGED
|
@@ -95,7 +95,8 @@ export class OblienChat {
|
|
|
95
95
|
namespace,
|
|
96
96
|
endUserId,
|
|
97
97
|
metadata = {},
|
|
98
|
-
workspace
|
|
98
|
+
workspace,
|
|
99
|
+
useLocalStorage = false
|
|
99
100
|
} = options;
|
|
100
101
|
|
|
101
102
|
if (!ip) {
|
|
@@ -106,45 +107,35 @@ export class OblienChat {
|
|
|
106
107
|
throw new Error('Agent ID is required for guest sessions');
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
//
|
|
110
|
-
const guest = await this.guestManager.getOrCreateGuest(ip, fingerprint, {
|
|
111
|
-
...metadata,
|
|
112
|
-
fingerprint,
|
|
113
|
-
ip,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Create session
|
|
110
|
+
// Create session via API (API will handle guest creation in Oblien database)
|
|
117
111
|
const session = new ChatSession({
|
|
118
112
|
client: this.client,
|
|
119
113
|
});
|
|
120
114
|
|
|
121
|
-
// Use custom namespace if provided, otherwise use guest's default namespace
|
|
122
|
-
const sessionNamespace = namespace || guest.id;
|
|
123
|
-
|
|
124
115
|
const sessionData = await session.create({
|
|
125
116
|
agentId,
|
|
126
117
|
workflowId,
|
|
127
118
|
workspace,
|
|
128
119
|
isGuest: true,
|
|
129
|
-
namespace:
|
|
120
|
+
namespace: namespace,
|
|
130
121
|
ipAddress: ip,
|
|
131
122
|
userAgent: metadata.userAgent,
|
|
132
|
-
guestNamespace: guest.namespace,
|
|
133
123
|
fingerprint: fingerprint,
|
|
134
|
-
endUserId: endUserId
|
|
124
|
+
endUserId: endUserId,
|
|
135
125
|
});
|
|
136
126
|
|
|
137
|
-
//
|
|
138
|
-
|
|
127
|
+
// If using local storage, also store guest locally for caching
|
|
128
|
+
if (useLocalStorage) {
|
|
129
|
+
const guest = await this.guestManager.getOrCreateGuest(ip, fingerprint, {
|
|
130
|
+
...metadata,
|
|
131
|
+
fingerprint,
|
|
132
|
+
ip,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
await this.guestManager.addSession(guest.id, sessionData.sessionId);
|
|
136
|
+
}
|
|
139
137
|
|
|
140
|
-
return
|
|
141
|
-
...sessionData,
|
|
142
|
-
guest: {
|
|
143
|
-
id: guest.id,
|
|
144
|
-
namespace: guest.namespace,
|
|
145
|
-
createdAt: guest.createdAt,
|
|
146
|
-
},
|
|
147
|
-
};
|
|
138
|
+
return sessionData
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
/**
|
|
@@ -167,7 +158,7 @@ export class OblienChat {
|
|
|
167
158
|
* // Get by namespace (object)
|
|
168
159
|
* const guest = await chat.getGuest({ namespace: 'guest-1-2-3-4' });
|
|
169
160
|
*/
|
|
170
|
-
async getGuest(options) {
|
|
161
|
+
async getGuest(options, getSessions = false) {
|
|
171
162
|
// Handle string usage: getGuest('namespace')
|
|
172
163
|
if (typeof options === 'string') {
|
|
173
164
|
options = { namespace: options };
|
|
@@ -184,14 +175,14 @@ export class OblienChat {
|
|
|
184
175
|
}
|
|
185
176
|
|
|
186
177
|
try {
|
|
187
|
-
const response = await this.client.post(`ai/guest/info`, {
|
|
178
|
+
const response = await this.client.post(getSessions ? `ai/guest/sessions` : `ai/guest/info`, {
|
|
188
179
|
ip,
|
|
189
180
|
fingerprint,
|
|
190
181
|
namespace: guestId,
|
|
191
182
|
agent_id: agentId,
|
|
192
183
|
session_id: sessionId,
|
|
193
184
|
});
|
|
194
|
-
return response
|
|
185
|
+
return response;
|
|
195
186
|
} catch (error) {
|
|
196
187
|
// Return null if guest not found (404)
|
|
197
188
|
if (error.message?.includes('not_found') || error.message?.includes('404')) {
|
|
@@ -541,6 +532,7 @@ export class OblienChat {
|
|
|
541
532
|
* @param {string} [options.sortBy] - Sort by 'time' or 'tokens'
|
|
542
533
|
* @param {string} [options.sortOrder] - 'asc' or 'desc'
|
|
543
534
|
* @param {boolean} [options.includeStats] - Include message count and tokens
|
|
535
|
+
* @param {boolean} [options.includeGuests] - Include guest information
|
|
544
536
|
* @returns {Promise<Array>} Array of sessions
|
|
545
537
|
*/
|
|
546
538
|
async listSessions(options = {}) {
|
package/src/chat/session.js
CHANGED
|
@@ -80,6 +80,7 @@ export class ChatSession {
|
|
|
80
80
|
* @param {string} [options.search] - Search in title and user ID
|
|
81
81
|
* @param {string} [options.sortBy] - Sort by 'time' or 'tokens'
|
|
82
82
|
* @param {string} [options.sortOrder] - 'asc' or 'desc'
|
|
83
|
+
* @param {boolean} [options.includeGuests] - Include guest information
|
|
83
84
|
* @param {boolean} [options.includeStats] - Include message count and tokens
|
|
84
85
|
* @returns {Promise<Array>} Array of sessions
|
|
85
86
|
*/
|