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
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File upload and retrieval endpoints for multimodal messages.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createErrorFromResponse } from '../errors.js';
|
|
6
|
+
import { buildHeaders, getRequestCredentials, RequestContext } from '../request.js';
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Types
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
export interface FileUploadContext extends RequestContext {}
|
|
12
|
+
|
|
13
|
+
export interface FileUploadResponse {
|
|
14
|
+
data: {
|
|
15
|
+
file_id: string;
|
|
16
|
+
mime_type: string;
|
|
17
|
+
size_bytes: number;
|
|
18
|
+
filename: string;
|
|
19
|
+
extracted_text: string | null;
|
|
20
|
+
url: string;
|
|
21
|
+
direct_url?: string | null;
|
|
22
|
+
direct_url_expires_at?: number | null;
|
|
23
|
+
};
|
|
24
|
+
metadata?: {
|
|
25
|
+
request_id: string;
|
|
26
|
+
timestamp: string;
|
|
27
|
+
message: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FileInfoResponse {
|
|
32
|
+
data: {
|
|
33
|
+
file_id: string;
|
|
34
|
+
mime_type: string;
|
|
35
|
+
size_bytes: number;
|
|
36
|
+
filename?: string | null;
|
|
37
|
+
extracted_text: string | null;
|
|
38
|
+
direct_url?: string | null;
|
|
39
|
+
direct_url_expires_at?: number | null;
|
|
40
|
+
};
|
|
41
|
+
metadata?: {
|
|
42
|
+
request_id: string;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
message: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface FileAccessUrlResponse {
|
|
49
|
+
data: {
|
|
50
|
+
file_id: string;
|
|
51
|
+
url: string;
|
|
52
|
+
expires_at?: number | null;
|
|
53
|
+
mime_type: string;
|
|
54
|
+
};
|
|
55
|
+
metadata?: {
|
|
56
|
+
request_id: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
message: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface MultimodalConfigResponse {
|
|
63
|
+
data: {
|
|
64
|
+
media_storage_type: string;
|
|
65
|
+
media_max_size_mb: number;
|
|
66
|
+
document_handling: string;
|
|
67
|
+
};
|
|
68
|
+
metadata?: {
|
|
69
|
+
request_id: string;
|
|
70
|
+
timestamp: string;
|
|
71
|
+
message: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Upload file
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
/**
|
|
79
|
+
* Upload a file (image, audio, document) to the server.
|
|
80
|
+
*
|
|
81
|
+
* @param ctx - Connection context
|
|
82
|
+
* @param file - A File, Blob, or { data: Blob; filename: string } object
|
|
83
|
+
* @returns FileUploadResponse with file_id and metadata
|
|
84
|
+
*/
|
|
85
|
+
export async function uploadFile(
|
|
86
|
+
ctx: FileUploadContext,
|
|
87
|
+
file: File | Blob | { data: Blob; filename: string }
|
|
88
|
+
): Promise<FileUploadResponse> {
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
const timeoutId = setTimeout(() => controller.abort(), ctx.timeout);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const formData = new FormData();
|
|
94
|
+
|
|
95
|
+
// `File` only became a global in Node 20; this package supports Node 18, where a bare
|
|
96
|
+
// `instanceof File` throws ReferenceError. Guard before touching the global.
|
|
97
|
+
if (typeof File !== 'undefined' && file instanceof File) {
|
|
98
|
+
formData.append('file', file, file.name);
|
|
99
|
+
} else if ('data' in file && 'filename' in file) {
|
|
100
|
+
formData.append('file', file.data, file.filename);
|
|
101
|
+
} else {
|
|
102
|
+
formData.append('file', file, 'upload');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const response = await fetch(`${ctx.baseUrl}/v1/files/upload`, {
|
|
106
|
+
method: 'POST',
|
|
107
|
+
headers: buildHeaders(ctx as RequestContext),
|
|
108
|
+
body: formData,
|
|
109
|
+
...getRequestCredentials(ctx as RequestContext),
|
|
110
|
+
signal: controller.signal,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
clearTimeout(timeoutId);
|
|
114
|
+
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
const error = await createErrorFromResponse(
|
|
117
|
+
response,
|
|
118
|
+
'File upload failed',
|
|
119
|
+
'/v1/files/upload',
|
|
120
|
+
'POST'
|
|
121
|
+
);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return (await response.json()) as FileUploadResponse;
|
|
126
|
+
} finally {
|
|
127
|
+
clearTimeout(timeoutId);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Get file (binary download)
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
/**
|
|
135
|
+
* Download a file by its file_id. Returns raw Blob.
|
|
136
|
+
*/
|
|
137
|
+
export async function getFile(ctx: FileUploadContext, fileId: string): Promise<Blob> {
|
|
138
|
+
const controller = new AbortController();
|
|
139
|
+
const timeoutId = setTimeout(() => controller.abort(), ctx.timeout);
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const response = await fetch(`${ctx.baseUrl}/v1/files/${encodeURIComponent(fileId)}`, {
|
|
143
|
+
method: 'GET',
|
|
144
|
+
headers: buildHeaders(ctx as RequestContext),
|
|
145
|
+
...getRequestCredentials(ctx as RequestContext),
|
|
146
|
+
signal: controller.signal,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
clearTimeout(timeoutId);
|
|
150
|
+
|
|
151
|
+
if (!response.ok) {
|
|
152
|
+
const error = await createErrorFromResponse(
|
|
153
|
+
response,
|
|
154
|
+
'File download failed',
|
|
155
|
+
`/v1/files/${fileId}`,
|
|
156
|
+
'GET'
|
|
157
|
+
);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return await response.blob();
|
|
162
|
+
} finally {
|
|
163
|
+
clearTimeout(timeoutId);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
// Get file info (metadata)
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
export async function getFileInfo(
|
|
171
|
+
ctx: FileUploadContext,
|
|
172
|
+
fileId: string
|
|
173
|
+
): Promise<FileInfoResponse> {
|
|
174
|
+
const controller = new AbortController();
|
|
175
|
+
const timeoutId = setTimeout(() => controller.abort(), ctx.timeout);
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
const response = await fetch(`${ctx.baseUrl}/v1/files/${encodeURIComponent(fileId)}/info`, {
|
|
179
|
+
method: 'GET',
|
|
180
|
+
headers: buildHeaders(ctx as RequestContext),
|
|
181
|
+
...getRequestCredentials(ctx as RequestContext),
|
|
182
|
+
signal: controller.signal,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
clearTimeout(timeoutId);
|
|
186
|
+
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
const error = await createErrorFromResponse(
|
|
189
|
+
response,
|
|
190
|
+
'File info request failed',
|
|
191
|
+
`/v1/files/${fileId}/info`,
|
|
192
|
+
'GET'
|
|
193
|
+
);
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return (await response.json()) as FileInfoResponse;
|
|
198
|
+
} finally {
|
|
199
|
+
clearTimeout(timeoutId);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Get file access URL
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
export async function getFileAccessUrl(
|
|
207
|
+
ctx: FileUploadContext,
|
|
208
|
+
fileId: string
|
|
209
|
+
): Promise<FileAccessUrlResponse> {
|
|
210
|
+
const controller = new AbortController();
|
|
211
|
+
const timeoutId = setTimeout(() => controller.abort(), ctx.timeout);
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
const response = await fetch(`${ctx.baseUrl}/v1/files/${encodeURIComponent(fileId)}/url`, {
|
|
215
|
+
method: 'GET',
|
|
216
|
+
headers: buildHeaders(ctx as RequestContext),
|
|
217
|
+
...getRequestCredentials(ctx as RequestContext),
|
|
218
|
+
signal: controller.signal,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
clearTimeout(timeoutId);
|
|
222
|
+
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
const error = await createErrorFromResponse(
|
|
225
|
+
response,
|
|
226
|
+
'File access URL request failed',
|
|
227
|
+
`/v1/files/${fileId}/url`,
|
|
228
|
+
'GET'
|
|
229
|
+
);
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return (await response.json()) as FileAccessUrlResponse;
|
|
234
|
+
} finally {
|
|
235
|
+
clearTimeout(timeoutId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
// Get multimodal config
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
export async function getMultimodalConfig(
|
|
243
|
+
ctx: FileUploadContext
|
|
244
|
+
): Promise<MultimodalConfigResponse> {
|
|
245
|
+
const controller = new AbortController();
|
|
246
|
+
const timeoutId = setTimeout(() => controller.abort(), ctx.timeout);
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
const response = await fetch(`${ctx.baseUrl}/v1/config/multimodal`, {
|
|
250
|
+
method: 'GET',
|
|
251
|
+
headers: buildHeaders(ctx as RequestContext, {
|
|
252
|
+
accept: 'application/json',
|
|
253
|
+
}),
|
|
254
|
+
...getRequestCredentials(ctx as RequestContext),
|
|
255
|
+
signal: controller.signal,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
clearTimeout(timeoutId);
|
|
259
|
+
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
const error = await createErrorFromResponse(
|
|
262
|
+
response,
|
|
263
|
+
'Multimodal config request failed',
|
|
264
|
+
'/v1/config/multimodal',
|
|
265
|
+
'GET'
|
|
266
|
+
);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return (await response.json()) as MultimodalConfigResponse;
|
|
271
|
+
} finally {
|
|
272
|
+
clearTimeout(timeoutId);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ResponseMetadata } from './metadata.js';
|
|
2
|
+
import { createErrorFromResponse } from '../errors.js';
|
|
3
|
+
import { buildHeaders, getRequestCredentials, RequestContext } from '../request.js';
|
|
4
|
+
|
|
5
|
+
export interface FixGraphContext extends RequestContext {}
|
|
6
|
+
|
|
7
|
+
export interface FixGraphRequest {
|
|
8
|
+
thread_id: string;
|
|
9
|
+
config?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface FixGraphResponse {
|
|
13
|
+
data: {
|
|
14
|
+
success: boolean;
|
|
15
|
+
message: string;
|
|
16
|
+
removed_count: number;
|
|
17
|
+
state?: Record<string, any>;
|
|
18
|
+
};
|
|
19
|
+
metadata: ResponseMetadata;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fix graph state by removing messages with empty tool calls
|
|
24
|
+
*
|
|
25
|
+
* This is useful for cleaning up incomplete tool call messages that may have
|
|
26
|
+
* failed or been interrupted during execution.
|
|
27
|
+
*
|
|
28
|
+
* @param context - Request context with baseUrl, auth, timeout
|
|
29
|
+
* @param request - Fix request with thread_id and optional config
|
|
30
|
+
* @returns Promise<FixGraphResponse> with fix operation result
|
|
31
|
+
*/
|
|
32
|
+
export async function fixGraph(
|
|
33
|
+
context: FixGraphContext,
|
|
34
|
+
request: FixGraphRequest
|
|
35
|
+
): Promise<FixGraphResponse> {
|
|
36
|
+
try {
|
|
37
|
+
if (context.debug) {
|
|
38
|
+
console.debug('TenxGraphClient: Fixing graph state for thread:', request.thread_id);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const timeoutId = setTimeout(() => controller.abort(), context.timeout);
|
|
43
|
+
|
|
44
|
+
const response = await fetch(`${context.baseUrl}/v1/graph/fix`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: buildHeaders(context as RequestContext, {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
accept: 'application/json',
|
|
49
|
+
}),
|
|
50
|
+
...getRequestCredentials(context as RequestContext),
|
|
51
|
+
body: JSON.stringify(request),
|
|
52
|
+
signal: controller.signal,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
console.warn(`TenxGraphClient: Fix graph failed with HTTP ${response.status}`);
|
|
59
|
+
const error = await createErrorFromResponse(
|
|
60
|
+
response,
|
|
61
|
+
'Fix graph state failed',
|
|
62
|
+
'/v1/graph/fix',
|
|
63
|
+
'POST'
|
|
64
|
+
);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const data: FixGraphResponse = await response.json();
|
|
69
|
+
|
|
70
|
+
if (context.debug) {
|
|
71
|
+
console.info('TenxGraphClient: Graph state fixed successfully', {
|
|
72
|
+
removed_count: data.data.removed_count,
|
|
73
|
+
success: data.data.success,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return data;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (context.debug) {
|
|
80
|
+
console.debug('TenxGraphClient: Fix graph failed:', error);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if ((error as Error).name === 'AbortError') {
|
|
84
|
+
console.warn(`TenxGraphClient: Fix graph timeout after ${context.timeout}ms`);
|
|
85
|
+
throw new Error(`Request timeout after ${context.timeout}ms`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.error('TenxGraphClient: Fix graph failed:', error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ResponseMetadata } from './metadata.js';
|
|
2
|
+
import { MemoryType } from './storeMemory.js';
|
|
3
|
+
import { buildHeaders, getRequestCredentials, RequestContext } from '../request.js';
|
|
4
|
+
|
|
5
|
+
export interface ForgetMemoriesContext extends RequestContext {}
|
|
6
|
+
|
|
7
|
+
export interface ForgetMemoriesRequest {
|
|
8
|
+
config?: Record<string, any>;
|
|
9
|
+
options?: Record<string, any>;
|
|
10
|
+
memory_type?: MemoryType;
|
|
11
|
+
category?: string;
|
|
12
|
+
filters?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ForgetMemoriesData {
|
|
16
|
+
success: boolean;
|
|
17
|
+
data: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ForgetMemoriesResponse {
|
|
21
|
+
data: ForgetMemoriesData;
|
|
22
|
+
metadata: ResponseMetadata;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function forgetMemories(
|
|
26
|
+
context: ForgetMemoriesContext,
|
|
27
|
+
request: ForgetMemoriesRequest
|
|
28
|
+
): Promise<ForgetMemoriesResponse> {
|
|
29
|
+
try {
|
|
30
|
+
const url = `${context.baseUrl}/v1/store/memories/forget`;
|
|
31
|
+
|
|
32
|
+
// Prepare request body - only include optional fields if provided
|
|
33
|
+
const body: Record<string, any> = {};
|
|
34
|
+
|
|
35
|
+
if (request.config) {
|
|
36
|
+
body.config = request.config;
|
|
37
|
+
}
|
|
38
|
+
if (request.options) {
|
|
39
|
+
body.options = request.options;
|
|
40
|
+
}
|
|
41
|
+
if (request.memory_type) {
|
|
42
|
+
body.memory_type = request.memory_type;
|
|
43
|
+
}
|
|
44
|
+
if (request.category) {
|
|
45
|
+
body.category = request.category;
|
|
46
|
+
}
|
|
47
|
+
if (request.filters) {
|
|
48
|
+
body.filters = request.filters;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (context.debug) {
|
|
52
|
+
console.log('[DEBUG] Forget memories request:', body);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
// `ReturnType<typeof setTimeout>` rather than NodeJS.Timeout: this client runs in
|
|
57
|
+
// browsers too, and the NodeJS namespace would force consumers to install @types/node.
|
|
58
|
+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
59
|
+
|
|
60
|
+
if (context.timeout > 0) {
|
|
61
|
+
timeoutId = setTimeout(() => controller.abort(), context.timeout);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const response = await fetch(url, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: buildHeaders(context as RequestContext, {
|
|
67
|
+
'Content-Type': 'application/json',
|
|
68
|
+
}),
|
|
69
|
+
...getRequestCredentials(context as RequestContext),
|
|
70
|
+
body: JSON.stringify(body),
|
|
71
|
+
...(context.timeout > 0 && { signal: controller.signal }),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (timeoutId) {
|
|
75
|
+
clearTimeout(timeoutId);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new Error(`Forget memories failed: ${response.status} ${response.statusText}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const data: ForgetMemoriesResponse = await response.json();
|
|
83
|
+
|
|
84
|
+
if (context.debug) {
|
|
85
|
+
console.log('[DEBUG] Forget memories response:', data);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return data;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if ((error as Error).name === 'AbortError') {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ResponseMetadata } from './metadata.js';
|
|
2
|
+
import { createErrorFromResponse } from '../errors.js';
|
|
3
|
+
import { buildHeaders, getRequestCredentials, RequestContext } from '../request.js';
|
|
4
|
+
import { MemoryResult } from './searchMemory.js';
|
|
5
|
+
|
|
6
|
+
export interface GetMemoryContext extends RequestContext {}
|
|
7
|
+
|
|
8
|
+
export interface GetMemoryRequest {
|
|
9
|
+
memoryId: string;
|
|
10
|
+
config?: Record<string, any>;
|
|
11
|
+
options?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface GetMemoryData {
|
|
15
|
+
memory: MemoryResult;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GetMemoryResponse {
|
|
19
|
+
data: GetMemoryData;
|
|
20
|
+
metadata: ResponseMetadata;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function getMemory(
|
|
24
|
+
context: GetMemoryContext,
|
|
25
|
+
request: GetMemoryRequest
|
|
26
|
+
): Promise<GetMemoryResponse> {
|
|
27
|
+
try {
|
|
28
|
+
if (context.debug) {
|
|
29
|
+
console.debug('TenxGraphClient: Fetching memory with ID:', request.memoryId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const controller = new AbortController();
|
|
33
|
+
const timeoutId = setTimeout(() => controller.abort(), context.timeout);
|
|
34
|
+
|
|
35
|
+
const url = `${context.baseUrl}/v1/store/memories/${request.memoryId}`;
|
|
36
|
+
|
|
37
|
+
// Prepare request body
|
|
38
|
+
const body = {
|
|
39
|
+
config: request.config || {},
|
|
40
|
+
options: request.options || {},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: buildHeaders(context as RequestContext, {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
}),
|
|
48
|
+
...getRequestCredentials(context as RequestContext),
|
|
49
|
+
body: JSON.stringify(body),
|
|
50
|
+
signal: controller.signal,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
clearTimeout(timeoutId);
|
|
54
|
+
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
console.warn(`TenxGraphClient: Get memory failed with HTTP ${response.status}`);
|
|
57
|
+
const error = await createErrorFromResponse(
|
|
58
|
+
response,
|
|
59
|
+
'Get memory request failed',
|
|
60
|
+
'/v1/memory/{memory_id}',
|
|
61
|
+
'GET'
|
|
62
|
+
);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const data: GetMemoryResponse = await response.json();
|
|
67
|
+
|
|
68
|
+
if (context.debug) {
|
|
69
|
+
console.info('TenxGraphClient: Memory fetched successfully', {
|
|
70
|
+
memory_id: request.memoryId,
|
|
71
|
+
content: data.data.memory.content.substring(0, 50),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return data;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (context.debug) {
|
|
78
|
+
console.debug('TenxGraphClient: Get memory failed:', error);
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ResponseMetadata } from './metadata.js';
|
|
2
|
+
import { createErrorFromResponse } from '../errors.js';
|
|
3
|
+
import { buildHeaders, getRequestCredentials, RequestContext } from '../request.js';
|
|
4
|
+
|
|
5
|
+
export interface GraphContext extends RequestContext {}
|
|
6
|
+
|
|
7
|
+
export interface GraphNode {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface GraphEdge {
|
|
13
|
+
id: string;
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GraphInfo {
|
|
19
|
+
node_count: number;
|
|
20
|
+
edge_count: number;
|
|
21
|
+
checkpointer: boolean;
|
|
22
|
+
checkpointer_type: string;
|
|
23
|
+
publisher: boolean;
|
|
24
|
+
store: boolean;
|
|
25
|
+
interrupt_before: string[];
|
|
26
|
+
interrupt_after: string[];
|
|
27
|
+
context_type: string;
|
|
28
|
+
id_generator: string;
|
|
29
|
+
id_type: string;
|
|
30
|
+
state_type: string;
|
|
31
|
+
state_fields: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface GraphData {
|
|
35
|
+
info: GraphInfo;
|
|
36
|
+
nodes: GraphNode[];
|
|
37
|
+
edges: GraphEdge[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface GraphResponse {
|
|
41
|
+
data: GraphData;
|
|
42
|
+
metadata: ResponseMetadata;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function graph(context: GraphContext): Promise<GraphResponse> {
|
|
46
|
+
try {
|
|
47
|
+
if (context.debug) {
|
|
48
|
+
console.debug('TenxGraphClient: Fetching graph from', context.baseUrl);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timeoutId = setTimeout(() => controller.abort(), context.timeout);
|
|
53
|
+
|
|
54
|
+
const response = await fetch(`${context.baseUrl}/v1/graph`, {
|
|
55
|
+
method: 'GET',
|
|
56
|
+
headers: buildHeaders(context as RequestContext, {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
accept: 'application/json',
|
|
59
|
+
}),
|
|
60
|
+
...getRequestCredentials(context as RequestContext),
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
clearTimeout(timeoutId);
|
|
65
|
+
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
console.warn(`TenxGraphClient: Graph fetch failed with HTTP ${response.status}`);
|
|
68
|
+
const error = await createErrorFromResponse(
|
|
69
|
+
response,
|
|
70
|
+
'Graph fetch failed',
|
|
71
|
+
'/v1/graph',
|
|
72
|
+
'GET'
|
|
73
|
+
);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const data: GraphResponse = await response.json();
|
|
78
|
+
|
|
79
|
+
if (context.debug) {
|
|
80
|
+
console.info('TenxGraphClient: Graph fetch successful', data);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return data;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (context.debug) {
|
|
86
|
+
console.debug('TenxGraphClient: Graph fetch failed:', error);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ((error as Error).name === 'AbortError') {
|
|
90
|
+
console.warn(`TenxGraphClient: Graph fetch timeout after ${context.timeout}ms`);
|
|
91
|
+
throw new Error(`Request timeout after ${context.timeout}ms`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.error('TenxGraphClient: Graph fetch failed:', error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|