@modelriver/client 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/README.md +409 -0
- package/cdn/v1.0.0/modelriver.min.js +2 -0
- package/cdn/v1.0.0/modelriver.min.js.map +1 -0
- package/dist/angular.cjs +769 -0
- package/dist/angular.cjs.map +1 -0
- package/dist/angular.d.ts +82 -0
- package/dist/angular.d.ts.map +1 -0
- package/dist/angular.mjs +766 -0
- package/dist/angular.mjs.map +1 -0
- package/dist/client.d.ts +114 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.cjs +606 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +597 -0
- package/dist/index.mjs.map +1 -0
- package/dist/modelriver.umd.js +2 -0
- package/dist/modelriver.umd.js.map +1 -0
- package/dist/react.cjs +739 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +40 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.mjs +737 -0
- package/dist/react.mjs.map +1 -0
- package/dist/svelte.cjs +727 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.ts +48 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.mjs +725 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/types.d.ts +236 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +73 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/vue.cjs +748 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +40 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.mjs +746 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +121 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var phoenix = require('phoenix');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ModelRiver Client SDK Utilities
|
|
7
|
+
*
|
|
8
|
+
* Helper functions for JWT decoding, localStorage operations, and URL building.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Default WebSocket base URL
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_BASE_URL = 'wss://api.modelriver.com/socket';
|
|
14
|
+
/**
|
|
15
|
+
* Default storage key prefix
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_STORAGE_KEY_PREFIX = 'modelriver_';
|
|
18
|
+
/**
|
|
19
|
+
* Default heartbeat interval (30 seconds)
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_HEARTBEAT_INTERVAL = 30000;
|
|
22
|
+
/**
|
|
23
|
+
* Default request timeout (5 minutes)
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_REQUEST_TIMEOUT = 300000;
|
|
26
|
+
/**
|
|
27
|
+
* Active request storage key suffix
|
|
28
|
+
*/
|
|
29
|
+
const ACTIVE_REQUEST_KEY = 'active_request';
|
|
30
|
+
/**
|
|
31
|
+
* Decode a base64url string to a regular string
|
|
32
|
+
*/
|
|
33
|
+
function base64UrlDecode(str) {
|
|
34
|
+
// Replace base64url characters with base64 characters
|
|
35
|
+
let base64 = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
36
|
+
// Pad with '=' to make length a multiple of 4
|
|
37
|
+
const padding = base64.length % 4;
|
|
38
|
+
if (padding) {
|
|
39
|
+
base64 += '='.repeat(4 - padding);
|
|
40
|
+
}
|
|
41
|
+
// Decode
|
|
42
|
+
try {
|
|
43
|
+
return atob(base64);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new Error('Invalid base64url string');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Decode a JWT token and extract the payload
|
|
51
|
+
* Note: This does NOT verify the signature - that's done server-side
|
|
52
|
+
*/
|
|
53
|
+
function decodeToken(token) {
|
|
54
|
+
if (!token || typeof token !== 'string') {
|
|
55
|
+
throw new Error('Invalid token: token must be a non-empty string');
|
|
56
|
+
}
|
|
57
|
+
const parts = token.split('.');
|
|
58
|
+
if (parts.length !== 3) {
|
|
59
|
+
throw new Error('Invalid token: JWT must have 3 parts');
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const payload = JSON.parse(base64UrlDecode(parts[1]));
|
|
63
|
+
// Validate required fields
|
|
64
|
+
if (!payload.project_id || !payload.channel_id) {
|
|
65
|
+
throw new Error('Invalid token: missing required fields (project_id, channel_id)');
|
|
66
|
+
}
|
|
67
|
+
// Build topic if not present
|
|
68
|
+
const topic = payload.topic || `ai_response:${payload.project_id}:${payload.channel_id}`;
|
|
69
|
+
return {
|
|
70
|
+
project_id: payload.project_id,
|
|
71
|
+
channel_id: payload.channel_id,
|
|
72
|
+
topic,
|
|
73
|
+
exp: payload.exp,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof Error && error.message.startsWith('Invalid token:')) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
throw new Error('Invalid token: failed to decode payload');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if a token is expired
|
|
85
|
+
*/
|
|
86
|
+
function isTokenExpired(payload) {
|
|
87
|
+
if (!payload.exp) {
|
|
88
|
+
return false; // No expiration set
|
|
89
|
+
}
|
|
90
|
+
// exp is in seconds, Date.now() is in milliseconds
|
|
91
|
+
return Date.now() >= payload.exp * 1000;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Build the WebSocket URL with token
|
|
95
|
+
*/
|
|
96
|
+
function buildWebSocketUrl(baseUrl, token) {
|
|
97
|
+
const url = baseUrl.endsWith('/websocket') ? baseUrl : `${baseUrl}/websocket`;
|
|
98
|
+
return `${url}?token=${encodeURIComponent(token)}&vsn=2.0.0`;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Check if localStorage is available
|
|
102
|
+
*/
|
|
103
|
+
function isStorageAvailable() {
|
|
104
|
+
try {
|
|
105
|
+
const testKey = '__modelriver_test__';
|
|
106
|
+
localStorage.setItem(testKey, 'test');
|
|
107
|
+
localStorage.removeItem(testKey);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Save active request to localStorage
|
|
116
|
+
*/
|
|
117
|
+
function saveActiveRequest(prefix, projectId, channelId, wsToken) {
|
|
118
|
+
if (!isStorageAvailable())
|
|
119
|
+
return;
|
|
120
|
+
const request = {
|
|
121
|
+
channelId,
|
|
122
|
+
timestamp: Date.now(),
|
|
123
|
+
projectId,
|
|
124
|
+
wsToken,
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
localStorage.setItem(`${prefix}${ACTIVE_REQUEST_KEY}`, JSON.stringify(request));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Storage might be full or disabled
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get active request from localStorage
|
|
135
|
+
* Returns null if not found or expired (older than 5 minutes)
|
|
136
|
+
*/
|
|
137
|
+
function getActiveRequest(prefix) {
|
|
138
|
+
if (!isStorageAvailable())
|
|
139
|
+
return null;
|
|
140
|
+
try {
|
|
141
|
+
const stored = localStorage.getItem(`${prefix}${ACTIVE_REQUEST_KEY}`);
|
|
142
|
+
if (!stored)
|
|
143
|
+
return null;
|
|
144
|
+
const request = JSON.parse(stored);
|
|
145
|
+
// Check if request is less than 5 minutes old
|
|
146
|
+
const age = Date.now() - request.timestamp;
|
|
147
|
+
if (age > DEFAULT_REQUEST_TIMEOUT) {
|
|
148
|
+
clearActiveRequest(prefix);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return request;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Clear active request from localStorage
|
|
159
|
+
*/
|
|
160
|
+
function clearActiveRequest(prefix) {
|
|
161
|
+
if (!isStorageAvailable())
|
|
162
|
+
return;
|
|
163
|
+
try {
|
|
164
|
+
localStorage.removeItem(`${prefix}${ACTIVE_REQUEST_KEY}`);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// Ignore errors
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create initial workflow steps
|
|
172
|
+
*/
|
|
173
|
+
function createInitialSteps() {
|
|
174
|
+
return [
|
|
175
|
+
{ id: 'queue', name: 'Queueing request', status: 'pending' },
|
|
176
|
+
{ id: 'process', name: 'Processing AI request', status: 'pending' },
|
|
177
|
+
{ id: 'receive', name: 'Waiting for response', status: 'pending' },
|
|
178
|
+
{ id: 'complete', name: 'Response received', status: 'pending' },
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Update a step in the steps array
|
|
183
|
+
*/
|
|
184
|
+
function updateStep(steps, id, updates) {
|
|
185
|
+
return steps.map((step) => step.id === id ? { ...step, ...updates } : step);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Logger utility for debug mode
|
|
189
|
+
*/
|
|
190
|
+
function createLogger(debug) {
|
|
191
|
+
const prefix = '[ModelRiver]';
|
|
192
|
+
return {
|
|
193
|
+
log: (...args) => {
|
|
194
|
+
if (debug)
|
|
195
|
+
console.log(prefix, ...args);
|
|
196
|
+
},
|
|
197
|
+
warn: (...args) => {
|
|
198
|
+
if (debug)
|
|
199
|
+
console.warn(prefix, ...args);
|
|
200
|
+
},
|
|
201
|
+
error: (...args) => {
|
|
202
|
+
// Always log errors
|
|
203
|
+
console.error(prefix, ...args);
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* ModelRiver Client SDK
|
|
210
|
+
*
|
|
211
|
+
* Core client class for connecting to ModelRiver's WebSocket-based AI response streaming.
|
|
212
|
+
*/
|
|
213
|
+
/**
|
|
214
|
+
* ModelRiver WebSocket Client
|
|
215
|
+
*
|
|
216
|
+
* Connects to ModelRiver's Phoenix Channels for real-time AI response streaming.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const client = new ModelRiverClient({
|
|
221
|
+
* baseUrl: 'wss://api.modelriver.com/socket',
|
|
222
|
+
* debug: true,
|
|
223
|
+
* });
|
|
224
|
+
*
|
|
225
|
+
* client.on('response', (data) => {
|
|
226
|
+
* console.log('AI Response:', data);
|
|
227
|
+
* });
|
|
228
|
+
*
|
|
229
|
+
* client.connect({ wsToken: 'your-token-from-backend' });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
class ModelRiverClient {
|
|
233
|
+
constructor(options = {}) {
|
|
234
|
+
this.socket = null;
|
|
235
|
+
this.channel = null;
|
|
236
|
+
this.heartbeatInterval = null;
|
|
237
|
+
this.connectionState = 'disconnected';
|
|
238
|
+
this.steps = [];
|
|
239
|
+
this.response = null;
|
|
240
|
+
this.error = null;
|
|
241
|
+
this.currentToken = null;
|
|
242
|
+
this.currentWsToken = null;
|
|
243
|
+
this.isConnecting = false;
|
|
244
|
+
// Event listeners
|
|
245
|
+
this.listeners = new Map();
|
|
246
|
+
this.options = {
|
|
247
|
+
baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
248
|
+
debug: options.debug ?? false,
|
|
249
|
+
persist: options.persist ?? true,
|
|
250
|
+
storageKeyPrefix: options.storageKeyPrefix ?? DEFAULT_STORAGE_KEY_PREFIX,
|
|
251
|
+
heartbeatInterval: options.heartbeatInterval ?? DEFAULT_HEARTBEAT_INTERVAL,
|
|
252
|
+
requestTimeout: options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT,
|
|
253
|
+
};
|
|
254
|
+
this.logger = createLogger(this.options.debug);
|
|
255
|
+
this.logger.log('Client initialized with options:', this.options);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get current client state
|
|
259
|
+
*/
|
|
260
|
+
getState() {
|
|
261
|
+
return {
|
|
262
|
+
connectionState: this.connectionState,
|
|
263
|
+
isConnected: this.connectionState === 'connected',
|
|
264
|
+
isConnecting: this.isConnecting,
|
|
265
|
+
steps: [...this.steps],
|
|
266
|
+
response: this.response,
|
|
267
|
+
error: this.error,
|
|
268
|
+
hasPendingRequest: this.hasPendingRequest(),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Check if there's a pending request that can be reconnected
|
|
273
|
+
*/
|
|
274
|
+
hasPendingRequest() {
|
|
275
|
+
if (!this.options.persist)
|
|
276
|
+
return false;
|
|
277
|
+
const request = getActiveRequest(this.options.storageKeyPrefix);
|
|
278
|
+
return request !== null;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Connect to WebSocket with token
|
|
282
|
+
*/
|
|
283
|
+
connect(options) {
|
|
284
|
+
if (this.isConnecting) {
|
|
285
|
+
this.logger.warn('Connection already in progress, skipping...');
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const { wsToken } = options;
|
|
289
|
+
// Decode and validate token
|
|
290
|
+
let tokenPayload;
|
|
291
|
+
try {
|
|
292
|
+
tokenPayload = decodeToken(wsToken);
|
|
293
|
+
this.logger.log('Token decoded:', {
|
|
294
|
+
projectId: tokenPayload.project_id,
|
|
295
|
+
channelId: tokenPayload.channel_id,
|
|
296
|
+
topic: tokenPayload.topic,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
catch (err) {
|
|
300
|
+
const errorMsg = err instanceof Error ? err.message : 'Invalid token';
|
|
301
|
+
this.setError(errorMsg);
|
|
302
|
+
this.emit('error', errorMsg);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// Check token expiration
|
|
306
|
+
if (isTokenExpired(tokenPayload)) {
|
|
307
|
+
const errorMsg = 'Token has expired';
|
|
308
|
+
this.setError(errorMsg);
|
|
309
|
+
this.emit('error', errorMsg);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
this.isConnecting = true;
|
|
313
|
+
this.currentToken = tokenPayload;
|
|
314
|
+
this.currentWsToken = wsToken;
|
|
315
|
+
this.emit('connecting');
|
|
316
|
+
// Clean up any existing connection
|
|
317
|
+
this.cleanupConnection();
|
|
318
|
+
// Initialize steps
|
|
319
|
+
this.steps = createInitialSteps();
|
|
320
|
+
this.error = null;
|
|
321
|
+
this.response = null;
|
|
322
|
+
// Save to localStorage for persistence
|
|
323
|
+
if (this.options.persist) {
|
|
324
|
+
saveActiveRequest(this.options.storageKeyPrefix, tokenPayload.project_id, tokenPayload.channel_id, wsToken);
|
|
325
|
+
}
|
|
326
|
+
// Update queue step to loading
|
|
327
|
+
this.updateStepAndEmit('queue', { status: 'loading' });
|
|
328
|
+
// Create Phoenix Socket
|
|
329
|
+
const wsUrl = buildWebSocketUrl(this.options.baseUrl, wsToken);
|
|
330
|
+
this.logger.log('Connecting to:', wsUrl.replace(wsToken, '***TOKEN***'));
|
|
331
|
+
this.socket = new phoenix.Socket(this.options.baseUrl, {
|
|
332
|
+
params: { token: wsToken },
|
|
333
|
+
});
|
|
334
|
+
this.socket.onOpen(() => {
|
|
335
|
+
this.logger.log('Socket connected');
|
|
336
|
+
this.connectionState = 'connected';
|
|
337
|
+
this.isConnecting = false;
|
|
338
|
+
this.emit('connected');
|
|
339
|
+
// Join channel
|
|
340
|
+
this.joinChannel(tokenPayload.topic);
|
|
341
|
+
});
|
|
342
|
+
this.socket.onError((error) => {
|
|
343
|
+
this.logger.error('Socket error:', error);
|
|
344
|
+
this.connectionState = 'error';
|
|
345
|
+
this.isConnecting = false;
|
|
346
|
+
const errorMsg = 'WebSocket connection error';
|
|
347
|
+
this.setError(errorMsg);
|
|
348
|
+
this.updateStepAndEmit('queue', { status: 'error', errorMessage: errorMsg });
|
|
349
|
+
this.emit('error', errorMsg);
|
|
350
|
+
});
|
|
351
|
+
this.socket.onClose((event) => {
|
|
352
|
+
this.logger.log('Socket closed:', event);
|
|
353
|
+
this.connectionState = 'disconnected';
|
|
354
|
+
this.isConnecting = false;
|
|
355
|
+
this.stopHeartbeat();
|
|
356
|
+
this.emit('disconnected', 'Socket closed');
|
|
357
|
+
});
|
|
358
|
+
this.socket.connect();
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Join the Phoenix channel
|
|
362
|
+
*/
|
|
363
|
+
joinChannel(topic) {
|
|
364
|
+
if (!this.socket)
|
|
365
|
+
return;
|
|
366
|
+
this.logger.log('Joining channel:', topic);
|
|
367
|
+
this.channel = this.socket.channel(topic, {});
|
|
368
|
+
this.channel.join()
|
|
369
|
+
.receive('ok', () => {
|
|
370
|
+
this.logger.log('Channel joined successfully');
|
|
371
|
+
this.updateStepAndEmit('queue', { status: 'success', duration: 100 });
|
|
372
|
+
this.updateStepAndEmit('process', { status: 'loading' });
|
|
373
|
+
this.updateStepAndEmit('receive', { status: 'loading' });
|
|
374
|
+
this.emit('channel_joined');
|
|
375
|
+
this.startHeartbeat();
|
|
376
|
+
})
|
|
377
|
+
.receive('error', (error) => {
|
|
378
|
+
const reason = error?.reason || 'unknown';
|
|
379
|
+
this.logger.error('Channel join failed:', reason);
|
|
380
|
+
let errorMsg = 'Failed to join channel';
|
|
381
|
+
if (reason === 'unauthorized_project_access') {
|
|
382
|
+
errorMsg = 'Unauthorized: You do not have access to this project';
|
|
383
|
+
}
|
|
384
|
+
else if (reason === 'invalid_channel_format') {
|
|
385
|
+
errorMsg = 'Invalid channel format';
|
|
386
|
+
}
|
|
387
|
+
else if (reason === 'invalid_project_uuid' || reason === 'invalid_channel_uuid') {
|
|
388
|
+
errorMsg = 'Invalid project or channel ID';
|
|
389
|
+
}
|
|
390
|
+
else if (reason !== 'unknown') {
|
|
391
|
+
errorMsg = `Channel join failed: ${reason}`;
|
|
392
|
+
}
|
|
393
|
+
this.setError(errorMsg);
|
|
394
|
+
this.updateStepAndEmit('queue', { status: 'error', errorMessage: errorMsg });
|
|
395
|
+
this.emit('channel_error', reason);
|
|
396
|
+
});
|
|
397
|
+
// Listen for AI response
|
|
398
|
+
this.channel.on('response', (payload) => {
|
|
399
|
+
this.logger.log('AI Response received:', payload);
|
|
400
|
+
this.handleResponse(payload);
|
|
401
|
+
});
|
|
402
|
+
// Listen for errors
|
|
403
|
+
this.channel.on('error', (payload) => {
|
|
404
|
+
const errorMsg = payload?.message || 'An error occurred';
|
|
405
|
+
this.logger.error('Channel error:', errorMsg);
|
|
406
|
+
this.handleError(errorMsg);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Handle AI response
|
|
411
|
+
*/
|
|
412
|
+
handleResponse(payload) {
|
|
413
|
+
const isSuccess = payload.status === 'success' ||
|
|
414
|
+
payload.status === 'SUCCESS' ||
|
|
415
|
+
payload.meta?.status === 'success' ||
|
|
416
|
+
payload.status === 'ok';
|
|
417
|
+
if (isSuccess) {
|
|
418
|
+
this.updateStepAndEmit('process', { status: 'success', duration: payload.meta?.duration_ms });
|
|
419
|
+
this.updateStepAndEmit('receive', { status: 'success', duration: 50 });
|
|
420
|
+
this.updateStepAndEmit('complete', { status: 'success' });
|
|
421
|
+
this.response = payload;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
const errorMsg = payload.error?.message || 'Unknown error';
|
|
425
|
+
this.updateStepAndEmit('process', { status: 'error', errorMessage: errorMsg });
|
|
426
|
+
this.updateStepAndEmit('receive', { status: 'error' });
|
|
427
|
+
this.updateStepAndEmit('complete', { status: 'error' });
|
|
428
|
+
this.setError(errorMsg);
|
|
429
|
+
}
|
|
430
|
+
// Clear active request from localStorage
|
|
431
|
+
if (this.options.persist) {
|
|
432
|
+
clearActiveRequest(this.options.storageKeyPrefix);
|
|
433
|
+
}
|
|
434
|
+
// Emit response event
|
|
435
|
+
this.emit('response', payload);
|
|
436
|
+
// Close connection after receiving response
|
|
437
|
+
setTimeout(() => {
|
|
438
|
+
this.cleanupConnection();
|
|
439
|
+
}, 1000);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Handle error
|
|
443
|
+
*/
|
|
444
|
+
handleError(errorMsg) {
|
|
445
|
+
this.setError(errorMsg);
|
|
446
|
+
this.updateStepAndEmit('process', { status: 'error', errorMessage: errorMsg });
|
|
447
|
+
this.emit('error', errorMsg);
|
|
448
|
+
if (this.options.persist) {
|
|
449
|
+
clearActiveRequest(this.options.storageKeyPrefix);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Disconnect from WebSocket
|
|
454
|
+
*/
|
|
455
|
+
disconnect() {
|
|
456
|
+
this.logger.log('Disconnecting...');
|
|
457
|
+
this.isConnecting = false;
|
|
458
|
+
this.cleanupConnection();
|
|
459
|
+
if (this.options.persist) {
|
|
460
|
+
clearActiveRequest(this.options.storageKeyPrefix);
|
|
461
|
+
}
|
|
462
|
+
this.emit('disconnected', 'Manual disconnect');
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Reset state and clear stored data
|
|
466
|
+
*/
|
|
467
|
+
reset() {
|
|
468
|
+
this.logger.log('Resetting...');
|
|
469
|
+
this.disconnect();
|
|
470
|
+
this.steps = [];
|
|
471
|
+
this.response = null;
|
|
472
|
+
this.error = null;
|
|
473
|
+
this.currentToken = null;
|
|
474
|
+
this.currentWsToken = null;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Try to reconnect using stored token
|
|
478
|
+
*/
|
|
479
|
+
reconnect() {
|
|
480
|
+
if (!this.options.persist) {
|
|
481
|
+
this.logger.warn('Persistence is disabled, cannot reconnect');
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
const activeRequest = getActiveRequest(this.options.storageKeyPrefix);
|
|
485
|
+
if (!activeRequest) {
|
|
486
|
+
this.logger.log('No active request found for reconnection');
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
this.logger.log('Reconnecting with stored token...');
|
|
490
|
+
this.connect({ wsToken: activeRequest.wsToken });
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Add event listener
|
|
495
|
+
*/
|
|
496
|
+
on(event, callback) {
|
|
497
|
+
if (!this.listeners.has(event)) {
|
|
498
|
+
this.listeners.set(event, new Set());
|
|
499
|
+
}
|
|
500
|
+
this.listeners.get(event).add(callback);
|
|
501
|
+
// Return unsubscribe function
|
|
502
|
+
return () => {
|
|
503
|
+
this.listeners.get(event)?.delete(callback);
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Remove event listener
|
|
508
|
+
*/
|
|
509
|
+
off(event, callback) {
|
|
510
|
+
this.listeners.get(event)?.delete(callback);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Emit event to listeners
|
|
514
|
+
*/
|
|
515
|
+
emit(event, ...args) {
|
|
516
|
+
const callbacks = this.listeners.get(event);
|
|
517
|
+
if (callbacks) {
|
|
518
|
+
callbacks.forEach((callback) => {
|
|
519
|
+
try {
|
|
520
|
+
callback(...args);
|
|
521
|
+
}
|
|
522
|
+
catch (err) {
|
|
523
|
+
this.logger.error(`Error in ${event} listener:`, err);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Update step and emit event
|
|
530
|
+
*/
|
|
531
|
+
updateStepAndEmit(id, updates) {
|
|
532
|
+
this.steps = updateStep(this.steps, id, updates);
|
|
533
|
+
const step = this.steps.find((s) => s.id === id);
|
|
534
|
+
if (step) {
|
|
535
|
+
this.emit('step', step);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Set error state
|
|
540
|
+
*/
|
|
541
|
+
setError(error) {
|
|
542
|
+
this.error = error;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Start heartbeat
|
|
546
|
+
*/
|
|
547
|
+
startHeartbeat() {
|
|
548
|
+
this.stopHeartbeat();
|
|
549
|
+
this.heartbeatInterval = setInterval(() => {
|
|
550
|
+
if (this.channel) {
|
|
551
|
+
this.channel.push('heartbeat', {});
|
|
552
|
+
}
|
|
553
|
+
}, this.options.heartbeatInterval);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Stop heartbeat
|
|
557
|
+
*/
|
|
558
|
+
stopHeartbeat() {
|
|
559
|
+
if (this.heartbeatInterval) {
|
|
560
|
+
clearInterval(this.heartbeatInterval);
|
|
561
|
+
this.heartbeatInterval = null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Clean up connection resources
|
|
566
|
+
*/
|
|
567
|
+
cleanupConnection() {
|
|
568
|
+
this.stopHeartbeat();
|
|
569
|
+
if (this.channel) {
|
|
570
|
+
try {
|
|
571
|
+
this.channel.leave();
|
|
572
|
+
}
|
|
573
|
+
catch {
|
|
574
|
+
// Ignore errors during cleanup
|
|
575
|
+
}
|
|
576
|
+
this.channel = null;
|
|
577
|
+
}
|
|
578
|
+
if (this.socket) {
|
|
579
|
+
try {
|
|
580
|
+
this.socket.disconnect();
|
|
581
|
+
}
|
|
582
|
+
catch {
|
|
583
|
+
// Ignore errors during cleanup
|
|
584
|
+
}
|
|
585
|
+
this.socket = null;
|
|
586
|
+
}
|
|
587
|
+
this.connectionState = 'disconnected';
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Destroy the client and clean up all resources
|
|
591
|
+
*/
|
|
592
|
+
destroy() {
|
|
593
|
+
this.reset();
|
|
594
|
+
this.listeners.clear();
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
599
|
+
exports.DEFAULT_HEARTBEAT_INTERVAL = DEFAULT_HEARTBEAT_INTERVAL;
|
|
600
|
+
exports.DEFAULT_REQUEST_TIMEOUT = DEFAULT_REQUEST_TIMEOUT;
|
|
601
|
+
exports.ModelRiverClient = ModelRiverClient;
|
|
602
|
+
exports.buildWebSocketUrl = buildWebSocketUrl;
|
|
603
|
+
exports.decodeToken = decodeToken;
|
|
604
|
+
exports.isStorageAvailable = isStorageAvailable;
|
|
605
|
+
exports.isTokenExpired = isTokenExpired;
|
|
606
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/client.ts"],"sourcesContent":[null,null],"names":["Socket"],"mappings":";;;;AAAA;;;;AAIG;AAIH;;AAEG;AACI,MAAM,gBAAgB,GAAG;AAEhC;;AAEG;AACI,MAAM,0BAA0B,GAAG,aAAa;AAEvD;;AAEG;AACI,MAAM,0BAA0B,GAAG;AAE1C;;AAEG;AACI,MAAM,uBAAuB,GAAG;AAEvC;;AAEG;AACI,MAAM,kBAAkB,GAAG,gBAAgB;AAElD;;AAEG;AACH,SAAS,eAAe,CAAC,GAAW,EAAA;;AAElC,IAAA,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;;AAGtD,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC;IACjC,IAAI,OAAO,EAAE;QACX,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC;IACnC;;AAGA,IAAA,IAAI;AACF,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB;AAAE,IAAA,MAAM;AACN,QAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC;IAC7C;AACF;AAEA;;;AAGG;AACG,SAAU,WAAW,CAAC,KAAa,EAAA;IACvC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AACvC,QAAA,MAAM,IAAI,K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AiB,CAAC;AACrC,YAAA,IAAI,CAAC,iBAAiB,GAAG,IAAI;QAC/B;IACF;AAEA;;AAEG;IACK,iBAAiB,GAAA;QACvB,IAAI,CAAC,aAAa,EAAE;AAEpB,QAAA,IAAI,IAAI,CAAC,OAAO,EAAE;AAChB,YAAA,IAAI;AACF,gBAAA,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACtB;AAAE,YAAA,MAAM;;YAER;AACA,YAAA,IAAI,CAAC,OAAO,GAAG,IAAI;QACrB;AAEA,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;AACf,YAAA,IAAI;AACF,gBAAA,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC1B;AAAE,YAAA,MAAM;;YAER;AACA,YAAA,IAAI,CAAC,MAAM,GAAG,IAAI;QACpB;AAEA,QAAA,IAAI,CAAC,eAAe,GAAG,cAAc;IACvC;AAEA;;AAEG;IACH,OAAO,GAAA;QACL,IAAI,CAAC,KAAK,EAAE;AACZ,QAAA,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE;IACxB;AACD;;;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @modelriver/client
|
|
3
|
+
*
|
|
4
|
+
* Official ModelRiver client SDK for real-time AI response streaming via WebSockets.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { ModelRiverClient } from '@modelriver/client';
|
|
9
|
+
*
|
|
10
|
+
* const client = new ModelRiverClient({
|
|
11
|
+
* baseUrl: 'wss://api.modelriver.com/socket',
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* client.on('response', (data) => {
|
|
15
|
+
* console.log('AI Response:', data);
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* client.connect({ wsToken: 'your-token-from-backend' });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export { ModelRiverClient } from './client';
|
|
22
|
+
export type { ModelRiverClientOptions, ConnectOptions, TokenPayload, WorkflowStep, WorkflowStepStatus, TokenUsage, ResponseMeta, ResponseError, AIResponse, ConnectionState, ActiveRequest, ModelRiverEventType, ModelRiverEventMap, ModelRiverState, UseModelRiverReturn, UseModelRiverVueReturn, ModelRiverSvelteStore, } from './types';
|
|
23
|
+
export { decodeToken, isTokenExpired, buildWebSocketUrl, isStorageAvailable, DEFAULT_BASE_URL, DEFAULT_HEARTBEAT_INTERVAL, DEFAULT_REQUEST_TIMEOUT, } from './utils';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,YAAY,EACV,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EACV,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,SAAS,CAAC"}
|