@attrove/sdk 0.1.3 → 0.1.5
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/cjs/README.md +247 -0
- package/cjs/package.json +56 -0
- package/cjs/src/__mocks__/version.js +17 -0
- package/cjs/src/__mocks__/version.js.map +1 -0
- package/cjs/src/admin-client.js +221 -0
- package/cjs/src/admin-client.js.map +1 -0
- package/cjs/src/client.js +312 -0
- package/cjs/src/client.js.map +1 -0
- package/cjs/src/constants.js +69 -0
- package/cjs/src/constants.js.map +1 -0
- package/cjs/src/errors/index.js +307 -0
- package/cjs/src/errors/index.js.map +1 -0
- package/cjs/src/index.js +98 -0
- package/cjs/src/index.js.map +1 -0
- package/cjs/src/resources/conversations.js +95 -0
- package/cjs/src/resources/conversations.js.map +1 -0
- package/cjs/src/resources/index.js +17 -0
- package/cjs/src/resources/index.js.map +1 -0
- package/cjs/src/resources/integrations.js +69 -0
- package/cjs/src/resources/integrations.js.map +1 -0
- package/cjs/src/resources/messages.js +98 -0
- package/cjs/src/resources/messages.js.map +1 -0
- package/cjs/src/resources/query.js +143 -0
- package/cjs/src/resources/query.js.map +1 -0
- package/cjs/src/resources/users.js +91 -0
- package/cjs/src/resources/users.js.map +1 -0
- package/cjs/src/types/index.js +292 -0
- package/cjs/src/types/index.js.map +1 -0
- package/cjs/src/utils/fetch.js +417 -0
- package/cjs/src/utils/fetch.js.map +1 -0
- package/cjs/src/utils/index.js +12 -0
- package/cjs/src/utils/index.js.map +1 -0
- package/cjs/src/utils/streaming.js +368 -0
- package/cjs/src/utils/streaming.js.map +1 -0
- package/cjs/src/version.js +31 -0
- package/cjs/src/version.js.map +1 -0
- package/esm/README.md +247 -0
- package/esm/package.json +56 -0
- package/esm/src/__mocks__/version.js +12 -0
- package/esm/src/__mocks__/version.js.map +1 -0
- package/esm/src/admin-client.js +216 -0
- package/esm/src/admin-client.js.map +1 -0
- package/esm/src/client.js +308 -0
- package/esm/src/client.js.map +1 -0
- package/esm/src/constants.js +65 -0
- package/esm/src/constants.js.map +1 -0
- package/esm/src/errors/index.js +285 -0
- package/esm/src/errors/index.js.map +1 -0
- package/esm/src/index.js +68 -0
- package/esm/src/index.js.map +1 -0
- package/esm/src/resources/conversations.js +91 -0
- package/esm/src/resources/conversations.js.map +1 -0
- package/esm/src/resources/index.js +9 -0
- package/esm/src/resources/index.js.map +1 -0
- package/esm/src/resources/integrations.js +65 -0
- package/esm/src/resources/integrations.js.map +1 -0
- package/esm/src/resources/messages.js +94 -0
- package/esm/src/resources/messages.js.map +1 -0
- package/esm/src/resources/query.js +139 -0
- package/esm/src/resources/query.js.map +1 -0
- package/esm/src/resources/users.js +87 -0
- package/esm/src/resources/users.js.map +1 -0
- package/esm/src/types/index.js +277 -0
- package/esm/src/types/index.js.map +1 -0
- package/esm/src/utils/fetch.js +413 -0
- package/esm/src/utils/fetch.js.map +1 -0
- package/esm/src/utils/index.js +6 -0
- package/esm/src/utils/index.js.map +1 -0
- package/esm/src/utils/streaming.js +363 -0
- package/esm/src/utils/streaming.js.map +1 -0
- package/esm/src/version.js +26 -0
- package/esm/src/version.js.map +1 -0
- package/package.json +16 -9
- package/types/src/__mocks__/version.d.ts +8 -0
- package/types/src/__mocks__/version.d.ts.map +1 -0
- package/types/src/admin-client.d.ts +144 -0
- package/types/src/admin-client.d.ts.map +1 -0
- package/types/src/client.d.ts +233 -0
- package/types/src/client.d.ts.map +1 -0
- package/types/src/constants.d.ts +47 -0
- package/types/src/constants.d.ts.map +1 -0
- package/types/src/errors/index.d.ts +206 -0
- package/types/src/errors/index.d.ts.map +1 -0
- package/types/src/index.d.ts +65 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/resources/conversations.d.ts +81 -0
- package/types/src/resources/conversations.d.ts.map +1 -0
- package/types/src/resources/index.d.ts +12 -0
- package/types/src/resources/index.d.ts.map +1 -0
- package/types/src/resources/integrations.d.ts +63 -0
- package/types/src/resources/integrations.d.ts.map +1 -0
- package/types/src/resources/messages.d.ts +69 -0
- package/types/src/resources/messages.d.ts.map +1 -0
- package/types/src/resources/query.d.ts +86 -0
- package/types/src/resources/query.d.ts.map +1 -0
- package/types/src/resources/users.d.ts +88 -0
- package/types/src/resources/users.d.ts.map +1 -0
- package/types/src/types/index.d.ts +807 -0
- package/types/src/types/index.d.ts.map +1 -0
- package/types/src/utils/fetch.d.ts +161 -0
- package/types/src/utils/fetch.d.ts.map +1 -0
- package/types/src/utils/index.d.ts +8 -0
- package/types/src/utils/index.d.ts.map +1 -0
- package/types/src/utils/streaming.d.ts +210 -0
- package/types/src/utils/streaming.d.ts.map +1 -0
- package/types/src/version.d.ts +21 -0
- package/types/src/version.d.ts.map +1 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket Streaming Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides WebSocket connection management for streaming LLM responses.
|
|
5
|
+
*
|
|
6
|
+
* Security Note: The WebSocket connection passes the authentication token
|
|
7
|
+
* as a query parameter. While this is a common pattern for WebSocket auth
|
|
8
|
+
* (since WebSocket doesn't support custom headers in browsers), be aware that:
|
|
9
|
+
* - Tokens may appear in server access logs
|
|
10
|
+
* - Tokens may be visible in network inspection tools
|
|
11
|
+
* - Using short-lived tokens is recommended for production use
|
|
12
|
+
*/
|
|
13
|
+
import { isValidStreamFrame } from '../types';
|
|
14
|
+
import { AttroveError, NetworkError, TimeoutError } from '../errors';
|
|
15
|
+
import { ErrorCodes } from '../types';
|
|
16
|
+
import { getWsCloseReason, DEFAULT_TIMEOUT } from '../constants';
|
|
17
|
+
/**
|
|
18
|
+
* Streaming query client for WebSocket-based LLM responses.
|
|
19
|
+
*
|
|
20
|
+
* Provides real-time streaming of AI-generated answers with support for:
|
|
21
|
+
* - Progress callbacks for each chunk
|
|
22
|
+
* - State change notifications
|
|
23
|
+
* - Cancellation via AbortSignal
|
|
24
|
+
* - Automatic cleanup on completion or error
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const streaming = new StreamingClient(baseUrl, apiKey);
|
|
29
|
+
* try {
|
|
30
|
+
* const result = await streaming.stream(query, messageId, history, options, {
|
|
31
|
+
* onChunk: (chunk) => console.log(chunk),
|
|
32
|
+
* });
|
|
33
|
+
* console.log('Answer:', result.answer);
|
|
34
|
+
* } finally {
|
|
35
|
+
* streaming.close();
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class StreamingClient {
|
|
40
|
+
constructor(baseUrl, token) {
|
|
41
|
+
this.ws = null;
|
|
42
|
+
this.currentMessageId = null;
|
|
43
|
+
// Convert HTTP URL to WebSocket URL
|
|
44
|
+
const wsBaseUrl = baseUrl.replace(/^http/, 'ws');
|
|
45
|
+
this.wsUrl = `${wsBaseUrl}/ws/llm-stream`;
|
|
46
|
+
this.token = token;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Connect to the WebSocket server.
|
|
50
|
+
*
|
|
51
|
+
* @throws {TimeoutError} If connection times out
|
|
52
|
+
* @throws {NetworkError} If connection fails
|
|
53
|
+
*/
|
|
54
|
+
async connect(timeout = DEFAULT_TIMEOUT) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const timeoutId = setTimeout(() => {
|
|
57
|
+
reject(new TimeoutError(`WebSocket connection timed out after ${timeout}ms`));
|
|
58
|
+
}, timeout);
|
|
59
|
+
try {
|
|
60
|
+
// Note: Token is passed as query parameter because WebSocket API
|
|
61
|
+
// doesn't support custom headers in browsers. This is a common pattern
|
|
62
|
+
// but means the token may appear in server logs.
|
|
63
|
+
const url = new URL(this.wsUrl);
|
|
64
|
+
url.searchParams.set('token', this.token);
|
|
65
|
+
const ws = new WebSocket(url.toString());
|
|
66
|
+
ws.onopen = () => {
|
|
67
|
+
clearTimeout(timeoutId);
|
|
68
|
+
resolve(ws);
|
|
69
|
+
};
|
|
70
|
+
ws.onerror = () => {
|
|
71
|
+
clearTimeout(timeoutId);
|
|
72
|
+
reject(new NetworkError(`WebSocket connection to ${this.wsUrl} failed. Check your network connection and ensure the API endpoint is accessible.`));
|
|
73
|
+
};
|
|
74
|
+
ws.onclose = (event) => {
|
|
75
|
+
if (event.code !== 1000) {
|
|
76
|
+
clearTimeout(timeoutId);
|
|
77
|
+
const reason = getWsCloseReason(event.code);
|
|
78
|
+
reject(new NetworkError(`WebSocket closed during connection (code ${event.code}: ${reason}). This may indicate a server issue or network problem.`));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
clearTimeout(timeoutId);
|
|
84
|
+
reject(new NetworkError(`Failed to create WebSocket: ${err instanceof Error ? err.message : String(err)}`));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Stream a query response.
|
|
90
|
+
*
|
|
91
|
+
* @param query - The natural language question to answer
|
|
92
|
+
* @param messageId - Unique message ID for tracking this stream
|
|
93
|
+
* @param history - Conversation history for context
|
|
94
|
+
* @param queryOptions - Query options (filters, timezone, etc.)
|
|
95
|
+
* @param streamOptions - Streaming options (callbacks, timeout, etc.)
|
|
96
|
+
* @returns Stream result with full answer and metadata
|
|
97
|
+
*
|
|
98
|
+
* @throws {NetworkError} If WebSocket connection fails or errors during streaming
|
|
99
|
+
* @throws {TimeoutError} If connection times out
|
|
100
|
+
* @throws {AttroveError} If the server returns an error
|
|
101
|
+
*/
|
|
102
|
+
async stream(query, messageId, history, queryOptions = {}, streamOptions = {}) {
|
|
103
|
+
const { onChunk, onState, onStart, onError, onEnd, onWarning, signal, timeout = DEFAULT_TIMEOUT } = streamOptions;
|
|
104
|
+
// Store warning callback for use in cancel() and cleanup()
|
|
105
|
+
this.onWarning = onWarning;
|
|
106
|
+
let answer = '';
|
|
107
|
+
let usedMessageIds = [];
|
|
108
|
+
let cancelled = false;
|
|
109
|
+
let completed = false;
|
|
110
|
+
// Connect to WebSocket
|
|
111
|
+
this.ws = await this.connect(timeout);
|
|
112
|
+
this.currentMessageId = messageId;
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
if (!this.ws) {
|
|
115
|
+
reject(new NetworkError('WebSocket not connected'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const ws = this.ws;
|
|
119
|
+
// Track abort handler for cleanup
|
|
120
|
+
let abortHandler;
|
|
121
|
+
// Cleanup function to remove listeners and close connection
|
|
122
|
+
const cleanupAndFinish = () => {
|
|
123
|
+
completed = true;
|
|
124
|
+
if (signal && abortHandler) {
|
|
125
|
+
signal.removeEventListener('abort', abortHandler);
|
|
126
|
+
}
|
|
127
|
+
this.cleanup();
|
|
128
|
+
};
|
|
129
|
+
// Handle abort signal
|
|
130
|
+
if (signal) {
|
|
131
|
+
abortHandler = () => {
|
|
132
|
+
if (!completed) {
|
|
133
|
+
this.cancel();
|
|
134
|
+
cancelled = true;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
signal.addEventListener('abort', abortHandler);
|
|
138
|
+
// Check if already aborted
|
|
139
|
+
if (signal.aborted) {
|
|
140
|
+
this.cancel();
|
|
141
|
+
cancelled = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Send the query to the server after connection is established
|
|
145
|
+
const queryPayload = {
|
|
146
|
+
type: 'query',
|
|
147
|
+
message_id: messageId,
|
|
148
|
+
query,
|
|
149
|
+
client_timezone: queryOptions.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
150
|
+
history: history.length > 0 ? history : undefined,
|
|
151
|
+
integration_ids: queryOptions.integrationIds,
|
|
152
|
+
conversation_ids: queryOptions.conversationIds,
|
|
153
|
+
allow_bot_messages: queryOptions.allowBotMessages,
|
|
154
|
+
expand: queryOptions.includeSources ? 'sources' : undefined,
|
|
155
|
+
};
|
|
156
|
+
try {
|
|
157
|
+
ws.send(JSON.stringify(queryPayload));
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
const error = new NetworkError(`Failed to send query to server: ${err instanceof Error ? err.message : String(err)}`);
|
|
161
|
+
onError?.(error);
|
|
162
|
+
cleanupAndFinish();
|
|
163
|
+
reject(error);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
ws.onmessage = (event) => {
|
|
167
|
+
// Parse JSON separately to provide better error messages
|
|
168
|
+
let parsed;
|
|
169
|
+
try {
|
|
170
|
+
parsed = JSON.parse(event.data);
|
|
171
|
+
}
|
|
172
|
+
catch (parseErr) {
|
|
173
|
+
const error = new AttroveError(`Failed to parse stream message: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`, ErrorCodes.INTERNAL_ERROR, undefined, { category: 'parse', rawDataPreview: String(event.data).substring(0, 200) });
|
|
174
|
+
onError?.(error);
|
|
175
|
+
cleanupAndFinish();
|
|
176
|
+
reject(error);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Validate the frame structure at runtime
|
|
180
|
+
if (!isValidStreamFrame(parsed)) {
|
|
181
|
+
const error = new AttroveError('Received invalid stream frame format from server', ErrorCodes.INTERNAL_ERROR, undefined, { category: 'parse', rawDataPreview: JSON.stringify(parsed).substring(0, 200) });
|
|
182
|
+
onError?.(error);
|
|
183
|
+
cleanupAndFinish();
|
|
184
|
+
reject(error);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const frame = parsed;
|
|
188
|
+
// Verify message ID matches - log mismatch for debugging
|
|
189
|
+
if (frame.message_id !== messageId) {
|
|
190
|
+
const warningContext = {
|
|
191
|
+
expected: messageId,
|
|
192
|
+
received: frame.message_id,
|
|
193
|
+
frameType: frame.type,
|
|
194
|
+
};
|
|
195
|
+
if (onWarning) {
|
|
196
|
+
onWarning('Received message with mismatched message_id, ignoring', warningContext);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// prettier-ignore
|
|
200
|
+
console.warn('[AttroveSDK] Received message with mismatched message_id, ignoring:', warningContext);
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// Process the parsed frame - callback errors will propagate naturally
|
|
205
|
+
switch (frame.type) {
|
|
206
|
+
case 'stream_start':
|
|
207
|
+
onStart?.();
|
|
208
|
+
break;
|
|
209
|
+
case 'state':
|
|
210
|
+
onState?.(frame.state);
|
|
211
|
+
break;
|
|
212
|
+
case 'chunk':
|
|
213
|
+
answer += frame.content;
|
|
214
|
+
onChunk?.(frame.content);
|
|
215
|
+
break;
|
|
216
|
+
case 'message_ids':
|
|
217
|
+
usedMessageIds = frame.used_message_ids;
|
|
218
|
+
break;
|
|
219
|
+
case 'error': {
|
|
220
|
+
const error = new AttroveError(frame.error, ErrorCodes.INTERNAL_ERROR);
|
|
221
|
+
onError?.(error);
|
|
222
|
+
cleanupAndFinish();
|
|
223
|
+
reject(error);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case 'end': {
|
|
227
|
+
cancelled = frame.reason === 'cancelled';
|
|
228
|
+
if (frame.used_message_ids) {
|
|
229
|
+
usedMessageIds = frame.used_message_ids;
|
|
230
|
+
}
|
|
231
|
+
onEnd?.(frame.reason);
|
|
232
|
+
// Build updated history
|
|
233
|
+
const updatedHistory = [
|
|
234
|
+
...history,
|
|
235
|
+
{ role: 'assistant', content: answer },
|
|
236
|
+
];
|
|
237
|
+
cleanupAndFinish();
|
|
238
|
+
resolve({
|
|
239
|
+
answer,
|
|
240
|
+
history: updatedHistory,
|
|
241
|
+
usedMessageIds,
|
|
242
|
+
cancelled,
|
|
243
|
+
});
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
ws.onerror = () => {
|
|
249
|
+
if (!completed) {
|
|
250
|
+
const error = new NetworkError(`WebSocket error during streaming. The connection was interrupted. You may need to retry the query.`);
|
|
251
|
+
onError?.(error);
|
|
252
|
+
cleanupAndFinish();
|
|
253
|
+
reject(error);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
ws.onclose = (event) => {
|
|
257
|
+
if (!completed && event.code !== 1000) {
|
|
258
|
+
const reason = getWsCloseReason(event.code);
|
|
259
|
+
const error = new NetworkError(`WebSocket closed unexpectedly (code ${event.code}: ${reason}). The stream may need to be retried.`);
|
|
260
|
+
onError?.(error);
|
|
261
|
+
cleanupAndFinish();
|
|
262
|
+
reject(error);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Cancel the current stream.
|
|
269
|
+
*
|
|
270
|
+
* Sends a stop message to the server to cancel the ongoing query.
|
|
271
|
+
* This is a best-effort operation - if the connection is already
|
|
272
|
+
* closed or in an invalid state, the cancellation will return
|
|
273
|
+
* a result indicating the failure reason but won't throw an error.
|
|
274
|
+
*
|
|
275
|
+
* @returns Result object with success status and reason
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* const result = streaming.cancel();
|
|
280
|
+
* if (!result.success) {
|
|
281
|
+
* if (result.reason === 'no_active_stream') {
|
|
282
|
+
* console.log('No stream to cancel');
|
|
283
|
+
* } else if (result.reason === 'send_failed') {
|
|
284
|
+
* console.error('Failed to send cancel:', result.error);
|
|
285
|
+
* }
|
|
286
|
+
* }
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
cancel() {
|
|
290
|
+
if (!this.ws || !this.currentMessageId) {
|
|
291
|
+
return { success: false, reason: 'no_active_stream' };
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
this.ws.send(JSON.stringify({
|
|
295
|
+
type: 'stop',
|
|
296
|
+
message_id: this.currentMessageId,
|
|
297
|
+
}));
|
|
298
|
+
return { success: true, reason: 'sent' };
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
// Cancellation is best-effort - the WebSocket may already be closed
|
|
302
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
303
|
+
const context = { messageId: this.currentMessageId, wsReadyState: this.ws?.readyState };
|
|
304
|
+
if (this.onWarning) {
|
|
305
|
+
this.onWarning('Failed to send cancel message', { error: errorMessage, ...context });
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
// prettier-ignore
|
|
309
|
+
console.warn('[AttroveSDK] Failed to send cancel message:', errorMessage, context);
|
|
310
|
+
}
|
|
311
|
+
return { success: false, reason: 'send_failed', error: errorMessage };
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Clean up resources.
|
|
316
|
+
*
|
|
317
|
+
* Closes the WebSocket connection and resets internal state.
|
|
318
|
+
* This is called automatically when a stream completes, errors,
|
|
319
|
+
* or is cancelled.
|
|
320
|
+
*/
|
|
321
|
+
cleanup() {
|
|
322
|
+
if (this.ws) {
|
|
323
|
+
try {
|
|
324
|
+
this.ws.close(1000);
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
// Cleanup is best-effort - the WebSocket may already be closed
|
|
328
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
329
|
+
if (this.onWarning) {
|
|
330
|
+
this.onWarning('Failed to close WebSocket cleanly', { error: errorMessage });
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
// prettier-ignore
|
|
334
|
+
console.warn('[AttroveSDK] Failed to close WebSocket cleanly:', errorMessage);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
this.ws = null;
|
|
338
|
+
}
|
|
339
|
+
this.currentMessageId = null;
|
|
340
|
+
this.onWarning = undefined;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Close the connection.
|
|
344
|
+
*
|
|
345
|
+
* Call this when you're done with the streaming client to ensure
|
|
346
|
+
* all resources are properly cleaned up.
|
|
347
|
+
*/
|
|
348
|
+
close() {
|
|
349
|
+
this.cleanup();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Generate a unique message ID for streaming.
|
|
354
|
+
*
|
|
355
|
+
* Creates a message ID in the format `msg_{timestamp}_{random}` that is
|
|
356
|
+
* sufficiently unique for tracking individual stream requests.
|
|
357
|
+
*
|
|
358
|
+
* @returns A unique message ID string
|
|
359
|
+
*/
|
|
360
|
+
export function generateMessageId() {
|
|
361
|
+
return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
362
|
+
}
|
|
363
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/utils/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAA+F,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC3I,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAkIjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,eAAe;IAO1B,YAAY,OAAe,EAAE,KAAa;QAJlC,OAAE,GAAqB,IAAI,CAAC;QAC5B,qBAAgB,GAAkB,IAAI,CAAC;QAI7C,oCAAoC;QACpC,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,GAAG,SAAS,gBAAgB,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,OAAO,CAAC,UAAkB,eAAe;QACrD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;gBAChC,MAAM,CAAC,IAAI,YAAY,CAAC,wCAAwC,OAAO,IAAI,CAAC,CAAC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AC;IACH,CAAC;IAED;;;;;;OAMG;IACK,OAAO;QACb,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,+DAA+D;gBAC/D,MAAM,YAAY,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBACtE,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;oBACnB,IAAI,CAAC,SAAS,CAAC,mCAAmC,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;gBAC/E,CAAC;qBAAM,CAAC;oBACN,kBAAkB;oBAClB,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,YAAY,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;YACD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Version Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides version information for the SDK using a static constant.
|
|
5
|
+
* This ensures browser compatibility while keeping the API consistent.
|
|
6
|
+
*/
|
|
7
|
+
import { SDK_VERSION } from './constants';
|
|
8
|
+
/**
|
|
9
|
+
* Get the SDK version.
|
|
10
|
+
*
|
|
11
|
+
* Returns the SDK version string from the hardcoded constant.
|
|
12
|
+
* This value should be kept in sync with package.json during releases.
|
|
13
|
+
*/
|
|
14
|
+
export function getVersion() {
|
|
15
|
+
return SDK_VERSION;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reset the cached version.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated This function has no effect. Version is now a static constant.
|
|
21
|
+
* Kept for API compatibility with existing tests.
|
|
22
|
+
*/
|
|
23
|
+
export function resetVersionCache() {
|
|
24
|
+
// No-op - version is now a static constant
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/version.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB;IAC/B,2CAA2C;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@attrove/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Official TypeScript SDK for the Attrove API - AI-powered context retrieval for your apps",
|
|
5
|
-
"main": "./src/index.
|
|
6
|
-
"module": "./src/index.
|
|
7
|
-
"types": "./src/index.ts",
|
|
5
|
+
"main": "./cjs/src/index.js",
|
|
6
|
+
"module": "./esm/src/index.js",
|
|
7
|
+
"types": "./types/src/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./types/src/index.d.ts",
|
|
12
|
+
"default": "./esm/src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./types/src/index.d.ts",
|
|
16
|
+
"default": "./cjs/src/index.js"
|
|
17
|
+
}
|
|
13
18
|
}
|
|
14
19
|
},
|
|
15
20
|
"files": [
|
|
16
|
-
"
|
|
21
|
+
"cjs",
|
|
22
|
+
"esm",
|
|
23
|
+
"types",
|
|
17
24
|
"README.md"
|
|
18
25
|
],
|
|
19
26
|
"sideEffects": false,
|
|
@@ -52,4 +59,4 @@
|
|
|
52
59
|
"publishConfig": {
|
|
53
60
|
"access": "public"
|
|
54
61
|
}
|
|
55
|
-
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock version module for Jest tests.
|
|
3
|
+
*
|
|
4
|
+
* This avoids the import.meta.url ESM issue when running tests with ts-jest.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getVersion(): string;
|
|
7
|
+
export declare function resetVersionCache(): void;
|
|
8
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/src/__mocks__/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attrove Admin Client
|
|
3
|
+
*
|
|
4
|
+
* Server-to-server client for partner operations like user provisioning
|
|
5
|
+
* and integration token generation.
|
|
6
|
+
*/
|
|
7
|
+
import { HttpClient } from './utils/fetch';
|
|
8
|
+
import { AttroveAdminConfig, CreateUserOptions, CreateUserResponse, CreateTokenResponse } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Users admin resource for managing users.
|
|
11
|
+
*
|
|
12
|
+
* Provides methods for creating users, generating integration tokens,
|
|
13
|
+
* and managing user data.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AdminUsersResource {
|
|
16
|
+
private readonly http;
|
|
17
|
+
private readonly clientId;
|
|
18
|
+
constructor(http: HttpClient, clientId: string);
|
|
19
|
+
/**
|
|
20
|
+
* Create or retrieve a user.
|
|
21
|
+
*
|
|
22
|
+
* Creates a new user by email, or retrieves an existing user if one exists.
|
|
23
|
+
* Returns an API key (sk_) for authenticating requests on behalf of this user.
|
|
24
|
+
*
|
|
25
|
+
* @param options - User creation options
|
|
26
|
+
* @returns User ID and API key
|
|
27
|
+
*
|
|
28
|
+
* @throws {ValidationError} If the email is invalid
|
|
29
|
+
* @throws {AuthenticationError} If partner credentials are invalid
|
|
30
|
+
* @throws {RateLimitError} If rate limits are exceeded
|
|
31
|
+
* @throws {NetworkError} If unable to reach the API
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const admin = Attrove.admin({ clientId, clientSecret });
|
|
36
|
+
*
|
|
37
|
+
* const { id, apiKey } = await admin.users.create({
|
|
38
|
+
* email: 'user@example.com',
|
|
39
|
+
* firstName: 'John',
|
|
40
|
+
* lastName: 'Doe'
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Use the apiKey to make API calls on behalf of this user
|
|
44
|
+
* const attrove = new Attrove({ apiKey, userId: id });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
create(options: CreateUserOptions): Promise<CreateUserResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Create an integration token for a user.
|
|
50
|
+
*
|
|
51
|
+
* Generates a short-lived token (pit_) for initiating OAuth flows.
|
|
52
|
+
* Use this token to redirect end-users to connect their integrations.
|
|
53
|
+
*
|
|
54
|
+
* @param userId - User ID (UUID format)
|
|
55
|
+
* @returns Integration token and expiration time
|
|
56
|
+
*
|
|
57
|
+
* @throws {ValidationError} If the userId is not a valid UUID
|
|
58
|
+
* @throws {AuthenticationError} If partner credentials are invalid
|
|
59
|
+
* @throws {NotFoundError} If the user doesn't exist
|
|
60
|
+
* @throws {RateLimitError} If rate limits are exceeded
|
|
61
|
+
* @throws {NetworkError} If unable to reach the API
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const admin = Attrove.admin({ clientId, clientSecret });
|
|
66
|
+
*
|
|
67
|
+
* const { token, expires_at } = await admin.users.createConnectToken(userId);
|
|
68
|
+
*
|
|
69
|
+
* // Redirect user to OAuth flow with this token
|
|
70
|
+
* const oauthUrl = `https://connect.attrove.com/oauth/gmail?token=${token}`;
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
createConnectToken(userId: string): Promise<CreateTokenResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* Delete a user.
|
|
76
|
+
*
|
|
77
|
+
* Permanently deletes a user and all associated data.
|
|
78
|
+
*
|
|
79
|
+
* @experimental This method is not yet implemented and will throw an error.
|
|
80
|
+
*
|
|
81
|
+
* @param userId - User ID (UUID format)
|
|
82
|
+
*
|
|
83
|
+
* @throws {Error} Always throws - not yet implemented
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* // Not yet available
|
|
88
|
+
* const admin = Attrove.admin({ clientId, clientSecret });
|
|
89
|
+
* await admin.users.delete(userId);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
delete(userId: string): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Admin client for server-to-server operations.
|
|
96
|
+
*
|
|
97
|
+
* Use this client for operations that require partner authentication:
|
|
98
|
+
* - Creating users
|
|
99
|
+
* - Generating integration tokens
|
|
100
|
+
* - Managing user data
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { Attrove } from '@attrove/sdk';
|
|
105
|
+
*
|
|
106
|
+
* const admin = Attrove.admin({
|
|
107
|
+
* clientId: 'your-client-id',
|
|
108
|
+
* clientSecret: 'your-client-secret'
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Create a user
|
|
112
|
+
* const { id, apiKey } = await admin.users.create({
|
|
113
|
+
* email: 'user@example.com'
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // Generate an integration token
|
|
117
|
+
* const { token: connectToken } = await admin.users.createConnectToken(id);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare class AttroveAdmin {
|
|
121
|
+
private readonly http;
|
|
122
|
+
private readonly config;
|
|
123
|
+
/**
|
|
124
|
+
* Users resource for managing users.
|
|
125
|
+
*/
|
|
126
|
+
readonly users: AdminUsersResource;
|
|
127
|
+
/**
|
|
128
|
+
* Create a new admin client.
|
|
129
|
+
*
|
|
130
|
+
* @param config - Admin client configuration
|
|
131
|
+
* @throws {ValidationError} If the configuration is invalid (missing clientId, clientSecret, etc.)
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const admin = new AttroveAdmin({
|
|
136
|
+
* clientId: 'your-client-id',
|
|
137
|
+
* clientSecret: 'your-client-secret',
|
|
138
|
+
* timeout: 60000 // 60 seconds
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
constructor(config: AttroveAdminConfig);
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=admin-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-client.d.ts","sourceRoot":"","sources":["../../../../../packages/sdk/src/admin-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EAEpB,MAAM,SAAS,CAAC;AA6CjB;;;;;GAKG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM;IAGnC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAmBrE;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkBtE;;;;;;;;;;;;;;;;;OAiBG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAI5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsF;IAE7G;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IAEnC;;;;;;;;;;;;;;OAcG;gBACS,MAAM,EAAE,kBAAkB;CAyBvC"}
|