10xgraph-client 0.0.0-stage → 0.6.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/CHANGELOG.md +276 -0
- package/LICENSE +21 -0
- package/README.md +400 -2
- package/dist/agent.d.ts +22 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/client.d.ts +479 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/compat.d.ts +28 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/endpoints/addThreadMessages.d.ts +22 -0
- package/dist/endpoints/addThreadMessages.d.ts.map +1 -0
- package/dist/endpoints/clearThreadState.d.ts +15 -0
- package/dist/endpoints/clearThreadState.d.ts.map +1 -0
- package/dist/endpoints/deleteMemory.d.ts +19 -0
- package/dist/endpoints/deleteMemory.d.ts.map +1 -0
- package/dist/endpoints/deleteThread.d.ts +19 -0
- package/dist/endpoints/deleteThread.d.ts.map +1 -0
- package/dist/endpoints/deleteThreadMessage.d.ts +20 -0
- package/dist/endpoints/deleteThreadMessage.d.ts.map +1 -0
- package/dist/endpoints/files.d.ts +83 -0
- package/dist/endpoints/files.d.ts.map +1 -0
- package/dist/endpoints/fixGraph.d.ts +29 -0
- package/dist/endpoints/fixGraph.d.ts.map +1 -0
- package/dist/endpoints/forgetMemories.d.ts +22 -0
- package/dist/endpoints/forgetMemories.d.ts.map +1 -0
- package/dist/endpoints/getMemory.d.ts +19 -0
- package/dist/endpoints/getMemory.d.ts.map +1 -0
- package/dist/endpoints/graph.d.ts +39 -0
- package/dist/endpoints/graph.d.ts.map +1 -0
- package/dist/endpoints/graphTools.d.ts +32 -0
- package/dist/endpoints/graphTools.d.ts.map +1 -0
- package/dist/endpoints/invoke.d.ts +59 -0
- package/dist/endpoints/invoke.d.ts.map +1 -0
- package/dist/endpoints/listMemories.d.ts +19 -0
- package/dist/endpoints/listMemories.d.ts.map +1 -0
- package/dist/endpoints/metadata.d.ts +6 -0
- package/dist/endpoints/metadata.d.ts.map +1 -0
- package/dist/endpoints/observability.d.ts +58 -0
- package/dist/endpoints/observability.d.ts.map +1 -0
- package/dist/endpoints/ping.d.ts +10 -0
- package/dist/endpoints/ping.d.ts.map +1 -0
- package/dist/endpoints/realtime.d.ts +134 -0
- package/dist/endpoints/realtime.d.ts.map +1 -0
- package/dist/endpoints/searchMemory.d.ts +57 -0
- package/dist/endpoints/searchMemory.d.ts.map +1 -0
- package/dist/endpoints/stateSchema.d.ts +50 -0
- package/dist/endpoints/stateSchema.d.ts.map +1 -0
- package/dist/endpoints/stopGraph.d.ts +26 -0
- package/dist/endpoints/stopGraph.d.ts.map +1 -0
- package/dist/endpoints/storeMemory.d.ts +33 -0
- package/dist/endpoints/storeMemory.d.ts.map +1 -0
- package/dist/endpoints/stream.d.ts +60 -0
- package/dist/endpoints/stream.d.ts.map +1 -0
- package/dist/endpoints/threadDetails.d.ts +19 -0
- package/dist/endpoints/threadDetails.d.ts.map +1 -0
- package/dist/endpoints/threadMessage.d.ts +17 -0
- package/dist/endpoints/threadMessage.d.ts.map +1 -0
- package/dist/endpoints/threadMessages.d.ts +23 -0
- package/dist/endpoints/threadMessages.d.ts.map +1 -0
- package/dist/endpoints/threadState.d.ts +14 -0
- package/dist/endpoints/threadState.d.ts.map +1 -0
- package/dist/endpoints/threads.d.ts +30 -0
- package/dist/endpoints/threads.d.ts.map +1 -0
- package/dist/endpoints/updateMemory.d.ts +21 -0
- package/dist/endpoints/updateMemory.d.ts.map +1 -0
- package/dist/endpoints/updateThreadState.d.ts +18 -0
- package/dist/endpoints/updateThreadState.d.ts.map +1 -0
- package/dist/endpoints/wsStream.d.ts +33 -0
- package/dist/endpoints/wsStream.d.ts.map +1 -0
- package/dist/errors.d.ts +155 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2664 -0
- package/dist/index.js.map +1 -0
- package/dist/message.d.ts +174 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/request.d.ts +33 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/tools.d.ts +67 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/ws.d.ts +48 -0
- package/dist/ws.d.ts.map +1 -0
- package/package.json +99 -4
- package/src/agent.ts +43 -0
- package/src/client.ts +1044 -0
- package/src/compat.ts +35 -0
- package/src/endpoints/addThreadMessages.ts +83 -0
- package/src/endpoints/clearThreadState.ts +75 -0
- package/src/endpoints/deleteMemory.ts +91 -0
- package/src/endpoints/deleteThread.ts +78 -0
- package/src/endpoints/deleteThreadMessage.ts +83 -0
- package/src/endpoints/files.ts +274 -0
- package/src/endpoints/fixGraph.ts +91 -0
- package/src/endpoints/forgetMemories.ts +95 -0
- package/src/endpoints/getMemory.ts +82 -0
- package/src/endpoints/graph.ts +97 -0
- package/src/endpoints/graphTools.ts +90 -0
- package/src/endpoints/invoke.ts +318 -0
- package/src/endpoints/listMemories.ts +97 -0
- package/src/endpoints/metadata.ts +6 -0
- package/src/endpoints/observability.ts +107 -0
- package/src/endpoints/ping.ts +58 -0
- package/src/endpoints/realtime.ts +326 -0
- package/src/endpoints/searchMemory.ts +132 -0
- package/src/endpoints/stateSchema.ts +106 -0
- package/src/endpoints/stopGraph.ts +85 -0
- package/src/endpoints/storeMemory.ts +98 -0
- package/src/endpoints/stream.ts +440 -0
- package/src/endpoints/threadDetails.ts +78 -0
- package/src/endpoints/threadMessage.ts +76 -0
- package/src/endpoints/threadMessages.ts +97 -0
- package/src/endpoints/threadState.ts +74 -0
- package/src/endpoints/threads.ts +112 -0
- package/src/endpoints/updateMemory.ts +90 -0
- package/src/endpoints/updateThreadState.ts +82 -0
- package/src/endpoints/wsStream.ts +251 -0
- package/src/errors.ts +553 -0
- package/src/index.ts +108 -0
- package/src/message.ts +436 -0
- package/src/request.ts +168 -0
- package/src/tools.ts +225 -0
- package/src/ws.ts +100 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling for 10xGraph API
|
|
3
|
+
* Provides structured error types for all HTTP status codes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Error response structure from API
|
|
7
|
+
export interface ErrorDetail {
|
|
8
|
+
loc?: string[];
|
|
9
|
+
msg?: string;
|
|
10
|
+
type?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ApiErrorResponse {
|
|
14
|
+
metadata: {
|
|
15
|
+
message: string;
|
|
16
|
+
request_id: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
};
|
|
19
|
+
error: {
|
|
20
|
+
code: string;
|
|
21
|
+
message: string;
|
|
22
|
+
details: ErrorDetail[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Base error class for all 10xGraph API errors
|
|
28
|
+
*/
|
|
29
|
+
export class TenxGraphError extends Error {
|
|
30
|
+
public readonly statusCode: number;
|
|
31
|
+
public readonly errorCode: string;
|
|
32
|
+
public readonly requestId: string;
|
|
33
|
+
public readonly timestamp: string;
|
|
34
|
+
public readonly details: ErrorDetail[];
|
|
35
|
+
public readonly context?: Record<string, any>;
|
|
36
|
+
public readonly endpoint?: string;
|
|
37
|
+
public readonly method?: string;
|
|
38
|
+
public readonly recoverySuggestion?: string;
|
|
39
|
+
|
|
40
|
+
constructor(
|
|
41
|
+
message: string,
|
|
42
|
+
statusCode: number,
|
|
43
|
+
errorCode: string,
|
|
44
|
+
requestId: string,
|
|
45
|
+
timestamp: string,
|
|
46
|
+
details: ErrorDetail[] = [],
|
|
47
|
+
context?: Record<string, any>,
|
|
48
|
+
endpoint?: string,
|
|
49
|
+
method?: string,
|
|
50
|
+
recoverySuggestion?: string
|
|
51
|
+
) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = 'TenxGraphError';
|
|
54
|
+
this.statusCode = statusCode;
|
|
55
|
+
this.errorCode = errorCode;
|
|
56
|
+
this.requestId = requestId;
|
|
57
|
+
this.timestamp = timestamp;
|
|
58
|
+
this.details = details;
|
|
59
|
+
this.context = context;
|
|
60
|
+
this.endpoint = endpoint;
|
|
61
|
+
this.method = method;
|
|
62
|
+
this.recoverySuggestion = recoverySuggestion;
|
|
63
|
+
|
|
64
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8).
|
|
65
|
+
// Typed structurally so the build does not depend on @types/node.
|
|
66
|
+
const captureStackTrace = (
|
|
67
|
+
Error as ErrorConstructor & {
|
|
68
|
+
captureStackTrace?: (target: object, ctor?: unknown) => void;
|
|
69
|
+
}
|
|
70
|
+
).captureStackTrace;
|
|
71
|
+
if (captureStackTrace) {
|
|
72
|
+
captureStackTrace(this, this.constructor);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get a user-friendly error message with recovery suggestion
|
|
78
|
+
*/
|
|
79
|
+
getUserMessage(): string {
|
|
80
|
+
if (this.recoverySuggestion) {
|
|
81
|
+
return `${this.message}\n\nSuggestion: ${this.recoverySuggestion}`;
|
|
82
|
+
}
|
|
83
|
+
return this.message;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get full error details for debugging
|
|
88
|
+
*/
|
|
89
|
+
toJSON(): Record<string, any> {
|
|
90
|
+
return {
|
|
91
|
+
name: this.name,
|
|
92
|
+
message: this.message,
|
|
93
|
+
statusCode: this.statusCode,
|
|
94
|
+
errorCode: this.errorCode,
|
|
95
|
+
requestId: this.requestId,
|
|
96
|
+
timestamp: this.timestamp,
|
|
97
|
+
details: this.details,
|
|
98
|
+
context: this.context,
|
|
99
|
+
endpoint: this.endpoint,
|
|
100
|
+
method: this.method,
|
|
101
|
+
recoverySuggestion: this.recoverySuggestion,
|
|
102
|
+
stack: this.stack,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 400 Bad Request Error
|
|
109
|
+
* Thrown when the request is malformed or contains invalid data
|
|
110
|
+
*/
|
|
111
|
+
export class BadRequestError extends TenxGraphError {
|
|
112
|
+
constructor(message: string, requestId: string, timestamp: string, details: ErrorDetail[] = []) {
|
|
113
|
+
super(message, 400, 'BAD_REQUEST', requestId, timestamp, details);
|
|
114
|
+
this.name = 'BadRequestError';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 401 Unauthorized Error
|
|
120
|
+
* Thrown when authentication credentials are missing or invalid
|
|
121
|
+
*/
|
|
122
|
+
export class AuthenticationError extends TenxGraphError {
|
|
123
|
+
constructor(message: string, requestId: string, timestamp: string, details: ErrorDetail[] = []) {
|
|
124
|
+
super(message, 401, 'AUTHENTICATION_FAILED', requestId, timestamp, details);
|
|
125
|
+
this.name = 'AuthenticationError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 403 Forbidden Error
|
|
131
|
+
* Thrown when the user doesn't have permission to access the resource
|
|
132
|
+
*/
|
|
133
|
+
export class PermissionError extends TenxGraphError {
|
|
134
|
+
constructor(message: string, requestId: string, timestamp: string, details: ErrorDetail[] = []) {
|
|
135
|
+
super(message, 403, 'PERMISSION_ERROR', requestId, timestamp, details);
|
|
136
|
+
this.name = 'PermissionError';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 404 Not Found Error
|
|
142
|
+
* Thrown when the requested resource doesn't exist
|
|
143
|
+
*/
|
|
144
|
+
export class NotFoundError extends TenxGraphError {
|
|
145
|
+
constructor(message: string, requestId: string, timestamp: string, details: ErrorDetail[] = []) {
|
|
146
|
+
super(message, 404, 'RESOURCE_NOT_FOUND', requestId, timestamp, details);
|
|
147
|
+
this.name = 'NotFoundError';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 422 Validation Error
|
|
153
|
+
* Thrown when the request data fails validation
|
|
154
|
+
*/
|
|
155
|
+
export class ValidationError extends TenxGraphError {
|
|
156
|
+
constructor(message: string, requestId: string, timestamp: string, details: ErrorDetail[] = []) {
|
|
157
|
+
super(message, 422, 'VALIDATION_ERROR', requestId, timestamp, details);
|
|
158
|
+
this.name = 'ValidationError';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 500 Server Error
|
|
164
|
+
* Thrown when the server encounters an internal error
|
|
165
|
+
*/
|
|
166
|
+
export class ServerError extends TenxGraphError {
|
|
167
|
+
constructor(
|
|
168
|
+
message: string,
|
|
169
|
+
requestId: string,
|
|
170
|
+
timestamp: string,
|
|
171
|
+
errorCode: string = 'INTERNAL_SERVER_ERROR',
|
|
172
|
+
details: ErrorDetail[] = [],
|
|
173
|
+
statusCode: number = 500
|
|
174
|
+
) {
|
|
175
|
+
super(message, statusCode, errorCode, requestId, timestamp, details);
|
|
176
|
+
this.name = 'ServerError';
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Graph Error
|
|
182
|
+
* Thrown when there's an error in graph execution
|
|
183
|
+
*/
|
|
184
|
+
export class GraphError extends TenxGraphError {
|
|
185
|
+
constructor(
|
|
186
|
+
message: string,
|
|
187
|
+
requestId: string,
|
|
188
|
+
timestamp: string,
|
|
189
|
+
details: ErrorDetail[] = [],
|
|
190
|
+
context?: Record<string, any>
|
|
191
|
+
) {
|
|
192
|
+
super(
|
|
193
|
+
message,
|
|
194
|
+
500,
|
|
195
|
+
'GRAPH_ERROR',
|
|
196
|
+
requestId,
|
|
197
|
+
timestamp,
|
|
198
|
+
details,
|
|
199
|
+
context,
|
|
200
|
+
undefined,
|
|
201
|
+
undefined,
|
|
202
|
+
'Check your graph configuration and ensure all nodes are properly connected.'
|
|
203
|
+
);
|
|
204
|
+
this.name = 'GraphError';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Node Error
|
|
210
|
+
* Thrown when there's an error executing a specific node
|
|
211
|
+
*/
|
|
212
|
+
export class NodeError extends TenxGraphError {
|
|
213
|
+
public readonly nodeName?: string;
|
|
214
|
+
|
|
215
|
+
constructor(
|
|
216
|
+
message: string,
|
|
217
|
+
requestId: string,
|
|
218
|
+
timestamp: string,
|
|
219
|
+
details: ErrorDetail[] = [],
|
|
220
|
+
context?: Record<string, any>,
|
|
221
|
+
nodeName?: string
|
|
222
|
+
) {
|
|
223
|
+
super(
|
|
224
|
+
message,
|
|
225
|
+
500,
|
|
226
|
+
'NODE_ERROR',
|
|
227
|
+
requestId,
|
|
228
|
+
timestamp,
|
|
229
|
+
details,
|
|
230
|
+
context,
|
|
231
|
+
undefined,
|
|
232
|
+
undefined,
|
|
233
|
+
'Review the node implementation and ensure all required inputs are provided.'
|
|
234
|
+
);
|
|
235
|
+
this.name = 'NodeError';
|
|
236
|
+
this.nodeName = nodeName;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Graph Recursion Error
|
|
242
|
+
* Thrown when graph execution exceeds the recursion limit
|
|
243
|
+
*/
|
|
244
|
+
export class GraphRecursionError extends TenxGraphError {
|
|
245
|
+
public readonly recursionLimit?: number;
|
|
246
|
+
|
|
247
|
+
constructor(
|
|
248
|
+
message: string,
|
|
249
|
+
requestId: string,
|
|
250
|
+
timestamp: string,
|
|
251
|
+
details: ErrorDetail[] = [],
|
|
252
|
+
context?: Record<string, any>,
|
|
253
|
+
recursionLimit?: number
|
|
254
|
+
) {
|
|
255
|
+
super(
|
|
256
|
+
message,
|
|
257
|
+
500,
|
|
258
|
+
'GRAPH_RECURSION_ERROR',
|
|
259
|
+
requestId,
|
|
260
|
+
timestamp,
|
|
261
|
+
details,
|
|
262
|
+
context,
|
|
263
|
+
undefined,
|
|
264
|
+
undefined,
|
|
265
|
+
'Consider increasing the recursion_limit parameter or check for infinite loops in your graph.'
|
|
266
|
+
);
|
|
267
|
+
this.name = 'GraphRecursionError';
|
|
268
|
+
this.recursionLimit = recursionLimit;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Storage Error
|
|
274
|
+
* Thrown when there's an error accessing storage
|
|
275
|
+
*/
|
|
276
|
+
export class StorageError extends TenxGraphError {
|
|
277
|
+
constructor(
|
|
278
|
+
message: string,
|
|
279
|
+
requestId: string,
|
|
280
|
+
timestamp: string,
|
|
281
|
+
details: ErrorDetail[] = [],
|
|
282
|
+
context?: Record<string, any>
|
|
283
|
+
) {
|
|
284
|
+
super(
|
|
285
|
+
message,
|
|
286
|
+
500,
|
|
287
|
+
'STORAGE_ERROR',
|
|
288
|
+
requestId,
|
|
289
|
+
timestamp,
|
|
290
|
+
details,
|
|
291
|
+
context,
|
|
292
|
+
undefined,
|
|
293
|
+
undefined,
|
|
294
|
+
'Check your storage configuration and ensure the storage backend is accessible.'
|
|
295
|
+
);
|
|
296
|
+
this.name = 'StorageError';
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Transient Storage Error
|
|
302
|
+
* Thrown when there's a temporary storage issue (503 Service Unavailable)
|
|
303
|
+
*/
|
|
304
|
+
export class TransientStorageError extends TenxGraphError {
|
|
305
|
+
constructor(
|
|
306
|
+
message: string,
|
|
307
|
+
requestId: string,
|
|
308
|
+
timestamp: string,
|
|
309
|
+
details: ErrorDetail[] = [],
|
|
310
|
+
context?: Record<string, any>
|
|
311
|
+
) {
|
|
312
|
+
super(
|
|
313
|
+
message,
|
|
314
|
+
503,
|
|
315
|
+
'TRANSIENT_STORAGE_ERROR',
|
|
316
|
+
requestId,
|
|
317
|
+
timestamp,
|
|
318
|
+
details,
|
|
319
|
+
context,
|
|
320
|
+
undefined,
|
|
321
|
+
undefined,
|
|
322
|
+
'This is a temporary issue. Please retry your request after a short delay.'
|
|
323
|
+
);
|
|
324
|
+
this.name = 'TransientStorageError';
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Metrics Error
|
|
330
|
+
* Thrown when there's an error collecting or reporting metrics
|
|
331
|
+
*/
|
|
332
|
+
export class MetricsError extends TenxGraphError {
|
|
333
|
+
constructor(
|
|
334
|
+
message: string,
|
|
335
|
+
requestId: string,
|
|
336
|
+
timestamp: string,
|
|
337
|
+
details: ErrorDetail[] = [],
|
|
338
|
+
context?: Record<string, any>
|
|
339
|
+
) {
|
|
340
|
+
super(
|
|
341
|
+
message,
|
|
342
|
+
500,
|
|
343
|
+
'METRICS_ERROR',
|
|
344
|
+
requestId,
|
|
345
|
+
timestamp,
|
|
346
|
+
details,
|
|
347
|
+
context,
|
|
348
|
+
undefined,
|
|
349
|
+
undefined,
|
|
350
|
+
"Check your metrics configuration. This error typically doesn't affect core functionality."
|
|
351
|
+
);
|
|
352
|
+
this.name = 'MetricsError';
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Schema Version Error
|
|
358
|
+
* Thrown when there's a version mismatch in data schemas
|
|
359
|
+
*/
|
|
360
|
+
export class SchemaVersionError extends TenxGraphError {
|
|
361
|
+
public readonly expectedVersion?: string;
|
|
362
|
+
public readonly actualVersion?: string;
|
|
363
|
+
|
|
364
|
+
constructor(
|
|
365
|
+
message: string,
|
|
366
|
+
requestId: string,
|
|
367
|
+
timestamp: string,
|
|
368
|
+
details: ErrorDetail[] = [],
|
|
369
|
+
context?: Record<string, any>,
|
|
370
|
+
expectedVersion?: string,
|
|
371
|
+
actualVersion?: string
|
|
372
|
+
) {
|
|
373
|
+
super(
|
|
374
|
+
message,
|
|
375
|
+
422,
|
|
376
|
+
'SCHEMA_VERSION_ERROR',
|
|
377
|
+
requestId,
|
|
378
|
+
timestamp,
|
|
379
|
+
details,
|
|
380
|
+
context,
|
|
381
|
+
undefined,
|
|
382
|
+
undefined,
|
|
383
|
+
'Update your client to match the server schema version or contact support.'
|
|
384
|
+
);
|
|
385
|
+
this.name = 'SchemaVersionError';
|
|
386
|
+
this.expectedVersion = expectedVersion;
|
|
387
|
+
this.actualVersion = actualVersion;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Serialization Error
|
|
393
|
+
* Thrown when there's an error serializing or deserializing data
|
|
394
|
+
*/
|
|
395
|
+
export class SerializationError extends TenxGraphError {
|
|
396
|
+
constructor(
|
|
397
|
+
message: string,
|
|
398
|
+
requestId: string,
|
|
399
|
+
timestamp: string,
|
|
400
|
+
details: ErrorDetail[] = [],
|
|
401
|
+
context?: Record<string, any>
|
|
402
|
+
) {
|
|
403
|
+
super(
|
|
404
|
+
message,
|
|
405
|
+
500,
|
|
406
|
+
'SERIALIZATION_ERROR',
|
|
407
|
+
requestId,
|
|
408
|
+
timestamp,
|
|
409
|
+
details,
|
|
410
|
+
context,
|
|
411
|
+
undefined,
|
|
412
|
+
undefined,
|
|
413
|
+
'Ensure your data format is compatible with the API schema.'
|
|
414
|
+
);
|
|
415
|
+
this.name = 'SerializationError';
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Parse error response from API
|
|
421
|
+
*/
|
|
422
|
+
export async function parseErrorResponse(response: Response): Promise<ApiErrorResponse | null> {
|
|
423
|
+
try {
|
|
424
|
+
const contentType = response.headers.get('content-type');
|
|
425
|
+
if (contentType && contentType.includes('application/json')) {
|
|
426
|
+
return (await response.json()) as ApiErrorResponse;
|
|
427
|
+
}
|
|
428
|
+
return null;
|
|
429
|
+
} catch {
|
|
430
|
+
// If we can't parse the error response, return null
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Create appropriate error instance based on HTTP status code and error code
|
|
437
|
+
*/
|
|
438
|
+
export async function createErrorFromResponse(
|
|
439
|
+
response: Response,
|
|
440
|
+
fallbackMessage?: string,
|
|
441
|
+
endpoint?: string,
|
|
442
|
+
method?: string
|
|
443
|
+
): Promise<TenxGraphError> {
|
|
444
|
+
const errorData = await parseErrorResponse(response);
|
|
445
|
+
|
|
446
|
+
// If we successfully parsed the error response
|
|
447
|
+
if (errorData) {
|
|
448
|
+
const { metadata, error } = errorData;
|
|
449
|
+
const message = error.message || fallbackMessage || `HTTP error ${response.status}`;
|
|
450
|
+
const requestId = metadata.request_id || 'unknown';
|
|
451
|
+
const timestamp = metadata.timestamp || new Date().toISOString();
|
|
452
|
+
const details = error.details || [];
|
|
453
|
+
const errorCode = error.code || '';
|
|
454
|
+
|
|
455
|
+
// Try to match specific error types by error code first (takes priority)
|
|
456
|
+
if (errorCode.startsWith('GRAPH_RECURSION')) {
|
|
457
|
+
return new GraphRecursionError(message, requestId, timestamp, details);
|
|
458
|
+
} else if (errorCode.startsWith('GRAPH')) {
|
|
459
|
+
return new GraphError(message, requestId, timestamp, details);
|
|
460
|
+
} else if (errorCode.startsWith('NODE')) {
|
|
461
|
+
return new NodeError(message, requestId, timestamp, details);
|
|
462
|
+
} else if (errorCode.startsWith('TRANSIENT_STORAGE')) {
|
|
463
|
+
return new TransientStorageError(message, requestId, timestamp, details);
|
|
464
|
+
} else if (errorCode.startsWith('STORAGE')) {
|
|
465
|
+
return new StorageError(message, requestId, timestamp, details);
|
|
466
|
+
} else if (errorCode.startsWith('METRICS')) {
|
|
467
|
+
return new MetricsError(message, requestId, timestamp, details);
|
|
468
|
+
} else if (errorCode.startsWith('SCHEMA_VERSION')) {
|
|
469
|
+
return new SchemaVersionError(message, requestId, timestamp, details);
|
|
470
|
+
} else if (errorCode.startsWith('SERIALIZATION')) {
|
|
471
|
+
return new SerializationError(message, requestId, timestamp, details);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Match by HTTP status code
|
|
475
|
+
switch (response.status) {
|
|
476
|
+
case 400:
|
|
477
|
+
return new BadRequestError(message, requestId, timestamp, details);
|
|
478
|
+
case 401:
|
|
479
|
+
return new AuthenticationError(message, requestId, timestamp, details);
|
|
480
|
+
case 403:
|
|
481
|
+
return new PermissionError(message, requestId, timestamp, details);
|
|
482
|
+
case 404:
|
|
483
|
+
return new NotFoundError(message, requestId, timestamp, details);
|
|
484
|
+
case 422:
|
|
485
|
+
return new ValidationError(message, requestId, timestamp, details);
|
|
486
|
+
case 500:
|
|
487
|
+
case 502:
|
|
488
|
+
case 503:
|
|
489
|
+
case 504:
|
|
490
|
+
return new ServerError(
|
|
491
|
+
message,
|
|
492
|
+
requestId,
|
|
493
|
+
timestamp,
|
|
494
|
+
errorCode || 'INTERNAL_SERVER_ERROR',
|
|
495
|
+
details,
|
|
496
|
+
response.status
|
|
497
|
+
);
|
|
498
|
+
default:
|
|
499
|
+
return new TenxGraphError(
|
|
500
|
+
message,
|
|
501
|
+
response.status,
|
|
502
|
+
errorCode || 'UNKNOWN_ERROR',
|
|
503
|
+
requestId,
|
|
504
|
+
timestamp,
|
|
505
|
+
details,
|
|
506
|
+
undefined,
|
|
507
|
+
endpoint,
|
|
508
|
+
method
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Fallback if we couldn't parse the error response
|
|
514
|
+
const message = fallbackMessage || `HTTP error! status: ${response.status}`;
|
|
515
|
+
const timestamp = new Date().toISOString();
|
|
516
|
+
|
|
517
|
+
switch (response.status) {
|
|
518
|
+
case 400:
|
|
519
|
+
return new BadRequestError(message, 'unknown', timestamp);
|
|
520
|
+
case 401:
|
|
521
|
+
return new AuthenticationError(message, 'unknown', timestamp);
|
|
522
|
+
case 403:
|
|
523
|
+
return new PermissionError(message, 'unknown', timestamp);
|
|
524
|
+
case 404:
|
|
525
|
+
return new NotFoundError(message, 'unknown', timestamp);
|
|
526
|
+
case 422:
|
|
527
|
+
return new ValidationError(message, 'unknown', timestamp);
|
|
528
|
+
case 500:
|
|
529
|
+
case 502:
|
|
530
|
+
case 503:
|
|
531
|
+
case 504:
|
|
532
|
+
return new ServerError(
|
|
533
|
+
message,
|
|
534
|
+
'unknown',
|
|
535
|
+
timestamp,
|
|
536
|
+
'INTERNAL_SERVER_ERROR',
|
|
537
|
+
[],
|
|
538
|
+
response.status
|
|
539
|
+
);
|
|
540
|
+
default:
|
|
541
|
+
return new TenxGraphError(
|
|
542
|
+
message,
|
|
543
|
+
response.status,
|
|
544
|
+
'UNKNOWN_ERROR',
|
|
545
|
+
'unknown',
|
|
546
|
+
timestamp,
|
|
547
|
+
[],
|
|
548
|
+
undefined,
|
|
549
|
+
endpoint,
|
|
550
|
+
method
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Re-export tool-related types and classes
|
|
2
|
+
export * from './tools.js';
|
|
3
|
+
|
|
4
|
+
// Re-export client functionality
|
|
5
|
+
export * from './client.js';
|
|
6
|
+
|
|
7
|
+
// Export error types and classes
|
|
8
|
+
export * from './errors.js';
|
|
9
|
+
|
|
10
|
+
// Export request/auth helpers
|
|
11
|
+
export * from './request.js';
|
|
12
|
+
|
|
13
|
+
// Export ping Response types
|
|
14
|
+
export * from './endpoints/ping.js';
|
|
15
|
+
|
|
16
|
+
// Export graph Response types
|
|
17
|
+
export * from './endpoints/graph.js';
|
|
18
|
+
|
|
19
|
+
// Export graph tools Response types
|
|
20
|
+
export * from './endpoints/graphTools.js';
|
|
21
|
+
|
|
22
|
+
// Export observability Response types
|
|
23
|
+
export * from './endpoints/observability.js';
|
|
24
|
+
|
|
25
|
+
// Export stop graph Response types
|
|
26
|
+
export * from './endpoints/stopGraph.js';
|
|
27
|
+
|
|
28
|
+
// Export fix graph Response types
|
|
29
|
+
export * from './endpoints/fixGraph.js';
|
|
30
|
+
|
|
31
|
+
// Export state schema Response types
|
|
32
|
+
export * from './endpoints/stateSchema.js';
|
|
33
|
+
|
|
34
|
+
// Export thread state Response types
|
|
35
|
+
export * from './endpoints/threadState.js';
|
|
36
|
+
|
|
37
|
+
// Export update thread state Response types
|
|
38
|
+
export * from './endpoints/updateThreadState.js';
|
|
39
|
+
|
|
40
|
+
// Export clear thread state Response types
|
|
41
|
+
export * from './endpoints/clearThreadState.js';
|
|
42
|
+
|
|
43
|
+
// Export checkpoint messages Response types
|
|
44
|
+
export * from './endpoints/threadMessages.js';
|
|
45
|
+
|
|
46
|
+
// Export add checkpoint messages Response types
|
|
47
|
+
export * from './endpoints/addThreadMessages.js';
|
|
48
|
+
|
|
49
|
+
// Export thread message Response types
|
|
50
|
+
export * from './endpoints/threadMessage.js';
|
|
51
|
+
// Export delete thread message Response types
|
|
52
|
+
export * from './endpoints/deleteThreadMessage.js';
|
|
53
|
+
// Export delete thread Response types
|
|
54
|
+
export * from './endpoints/deleteThread.js';
|
|
55
|
+
// Export threads list Response types
|
|
56
|
+
export * from './endpoints/threads.js';
|
|
57
|
+
// Export thread details Response types
|
|
58
|
+
export * from './endpoints/threadDetails.js';
|
|
59
|
+
|
|
60
|
+
// Export invoke types
|
|
61
|
+
export * from './endpoints/invoke.js';
|
|
62
|
+
|
|
63
|
+
// Export stream types
|
|
64
|
+
export * from './endpoints/stream.js';
|
|
65
|
+
|
|
66
|
+
// Export WebSocket stream types
|
|
67
|
+
export * from './endpoints/wsStream.js';
|
|
68
|
+
|
|
69
|
+
// Export shared WebSocket helpers
|
|
70
|
+
export * from './ws.js';
|
|
71
|
+
|
|
72
|
+
// Export realtime (audio) session types + class
|
|
73
|
+
export * from './endpoints/realtime.js';
|
|
74
|
+
|
|
75
|
+
// Export store memory types
|
|
76
|
+
export * from './endpoints/storeMemory.js';
|
|
77
|
+
|
|
78
|
+
// Export search memory types
|
|
79
|
+
export * from './endpoints/searchMemory.js';
|
|
80
|
+
|
|
81
|
+
// Export get memory types
|
|
82
|
+
export * from './endpoints/getMemory.js';
|
|
83
|
+
|
|
84
|
+
// Export update memory types
|
|
85
|
+
export * from './endpoints/updateMemory.js';
|
|
86
|
+
|
|
87
|
+
// Export delete memory types
|
|
88
|
+
export * from './endpoints/deleteMemory.js';
|
|
89
|
+
|
|
90
|
+
// Export list memories types
|
|
91
|
+
export * from './endpoints/listMemories.js';
|
|
92
|
+
|
|
93
|
+
// Export forget memories types
|
|
94
|
+
export * from './endpoints/forgetMemories.js';
|
|
95
|
+
|
|
96
|
+
// Export file upload / multimodal types
|
|
97
|
+
export * from './endpoints/files.js';
|
|
98
|
+
|
|
99
|
+
// Export shared metadata types
|
|
100
|
+
export * from './endpoints/metadata.js';
|
|
101
|
+
|
|
102
|
+
// Export Agent class
|
|
103
|
+
export * from './agent.js';
|
|
104
|
+
|
|
105
|
+
export * from './message.js';
|
|
106
|
+
|
|
107
|
+
// Deprecated AgentFlow* aliases (removed in 2.0)
|
|
108
|
+
export * from './compat.js';
|