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/dist/index.js
ADDED
|
@@ -0,0 +1,2664 @@
|
|
|
1
|
+
class b {
|
|
2
|
+
constructor(e = "url", r, o, s, n, i, a, c, d, h, l, u) {
|
|
3
|
+
this.kind = "url", this.kind = e, this.url = r, this.file_id = o, this.data_base64 = s, this.mime_type = n, this.size_bytes = i, this.sha256 = a, this.filename = c, this.width = d, this.height = h, this.duration_ms = l, this.page = u;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
class it {
|
|
7
|
+
constructor(e, r, o, s, n) {
|
|
8
|
+
this.url = e, this.file_id = r, this.page = o, this.index = s, this.title = n;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class S {
|
|
12
|
+
constructor(e = "", r = []) {
|
|
13
|
+
this.type = "text", this.text = "", this.annotations = [], this.text = e, this.annotations = r;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class v {
|
|
17
|
+
constructor(e = new b(), r, o) {
|
|
18
|
+
this.type = "image", this.media = new b(), this.media = e, this.alt_text = r, this.bbox = o;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class H {
|
|
22
|
+
constructor(e = new b(), r, o, s) {
|
|
23
|
+
this.type = "audio", this.media = new b(), this.media = e, this.transcript = r, this.sample_rate = o, this.channels = s;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class B {
|
|
27
|
+
constructor(e = new b(), r) {
|
|
28
|
+
this.type = "video", this.media = new b(), this.media = e, this.thumbnail = r;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class J {
|
|
32
|
+
constructor(e = new b(), r, o) {
|
|
33
|
+
this.type = "document", this.media = new b(), this.media = e, this.pages = r, this.excerpt = o;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class at {
|
|
37
|
+
constructor(e = "", r, o) {
|
|
38
|
+
this.type = "data", this.mime_type = "", this.mime_type = e, this.data_base64 = r, this.media = o;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class lt {
|
|
42
|
+
constructor(e = "", r = "", o = {}, s) {
|
|
43
|
+
this.type = "tool_call", this.id = "", this.name = "", this.args = {}, this.id = e, this.name = r, this.args = o, this.tool_type = s;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class ct {
|
|
47
|
+
constructor(e = "", r = "", o = {}, s = "remote") {
|
|
48
|
+
this.type = "remote_tool_call", this.id = "", this.name = "", this.args = {}, this.tool_type = "remote", this.id = e, this.name = r, this.args = o, this.tool_type = s;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class G {
|
|
52
|
+
constructor(e) {
|
|
53
|
+
this.type = "tool_result", this.call_id = "", this.is_error = !1, this.call_id = e.call_id, this.output = e.output, this.status = e.status, this.is_error = e.is_error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class ht {
|
|
57
|
+
constructor(e = "", r) {
|
|
58
|
+
this.type = "reasoning", this.summary = "", this.summary = e, this.details = r;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
class dt {
|
|
62
|
+
constructor(e = "citation", r = [], o) {
|
|
63
|
+
this.type = "annotation", this.kind = "citation", this.refs = [], this.kind = e, this.refs = r, this.spans = o;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class ut {
|
|
67
|
+
constructor(e = "", r, o) {
|
|
68
|
+
this.type = "error", this.message = "", this.message = e, this.code = r, this.data = o;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class mt {
|
|
72
|
+
constructor() {
|
|
73
|
+
this.completion_tokens = 0, this.prompt_tokens = 0, this.total_tokens = 0, this.reasoning_tokens = 0, this.cache_creation_input_tokens = 0, this.cache_read_input_tokens = 0, this.image_tokens = 0, this.audio_tokens = 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class C {
|
|
77
|
+
constructor(e, r, o = null) {
|
|
78
|
+
this.message_id = null, this.content = [], this.delta = !1, this.timestamp = Date.now(), this.metadata = {}, this.role = e, this.content = r, this.message_id = o;
|
|
79
|
+
}
|
|
80
|
+
static text_message(e, r = "user", o = null) {
|
|
81
|
+
return new C(r, [{ type: "text", text: e }], o);
|
|
82
|
+
}
|
|
83
|
+
static tool_message(e, r = null, o = {}) {
|
|
84
|
+
const s = new C("tool", e, r);
|
|
85
|
+
return s.metadata = o, s;
|
|
86
|
+
}
|
|
87
|
+
text() {
|
|
88
|
+
return this.content.map((e) => {
|
|
89
|
+
if (e.type === "text")
|
|
90
|
+
return e.text;
|
|
91
|
+
if (e.type === "tool_result") {
|
|
92
|
+
const r = e.output;
|
|
93
|
+
return typeof r == "string" ? r : JSON.stringify(r);
|
|
94
|
+
}
|
|
95
|
+
return "";
|
|
96
|
+
}).join("");
|
|
97
|
+
}
|
|
98
|
+
attach_media(e, r) {
|
|
99
|
+
let o;
|
|
100
|
+
switch (r) {
|
|
101
|
+
case "image":
|
|
102
|
+
o = { type: "image", media: e };
|
|
103
|
+
break;
|
|
104
|
+
case "audio":
|
|
105
|
+
o = { type: "audio", media: e };
|
|
106
|
+
break;
|
|
107
|
+
case "video":
|
|
108
|
+
o = { type: "video", media: e };
|
|
109
|
+
break;
|
|
110
|
+
case "document":
|
|
111
|
+
o = { type: "document", media: e };
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`Unsupported media type: ${r}`);
|
|
115
|
+
}
|
|
116
|
+
this.content.push(o);
|
|
117
|
+
}
|
|
118
|
+
// ------------------------------------------------------------------
|
|
119
|
+
// Multimodal convenience constructors (Sprint 5.3)
|
|
120
|
+
// ------------------------------------------------------------------
|
|
121
|
+
/**
|
|
122
|
+
* Create a message with an image (via URL or base64).
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const msg = Message.withImage('Describe this', 'https://example.com/photo.jpg');
|
|
127
|
+
* const msg2 = Message.withImage('Describe this', 'data:image/png;base64,...');
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
static withImage(e, r, o = "user") {
|
|
131
|
+
return new C(o, [
|
|
132
|
+
new S(e),
|
|
133
|
+
new v(new b("url", r, void 0, void 0, void 0))
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create a message with a file reference (e.g. from uploadFile result).
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const upload = await client.uploadFile(pdfFile);
|
|
142
|
+
* const msg = Message.withFile('Summarize this PDF', upload.data.file_id, 'application/pdf');
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
static withFile(e, r, o, s = "user") {
|
|
146
|
+
const n = new b("file_id", void 0, r, void 0, o), i = o?.startsWith("image/"), a = o?.startsWith("audio/"), c = o?.startsWith("video/");
|
|
147
|
+
let d;
|
|
148
|
+
return i ? d = new v(n) : a ? d = new H(n) : c ? d = new B(n) : d = new J(n), new C(s, [new S(e), d]);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Create a multimodal message with arbitrary content blocks.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const msg = Message.multimodal([
|
|
156
|
+
* new TextBlock('Look at these'),
|
|
157
|
+
* new ImageBlock(new MediaRef('url', 'https://...')),
|
|
158
|
+
* new ImageBlock(new MediaRef('url', 'https://...')),
|
|
159
|
+
* ]);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
static multimodal(e, r = "user") {
|
|
163
|
+
return new C(r, e);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function W(t) {
|
|
167
|
+
const e = t ?? {}, { type: r, properties: o, required: s, ...n } = e;
|
|
168
|
+
return {
|
|
169
|
+
...n,
|
|
170
|
+
type: r ?? "object",
|
|
171
|
+
properties: o ?? {},
|
|
172
|
+
required: s ?? []
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
class z {
|
|
176
|
+
constructor(e = []) {
|
|
177
|
+
this.tools = /* @__PURE__ */ new Map(), this.toolsByNode = /* @__PURE__ */ new Map();
|
|
178
|
+
for (const r of e)
|
|
179
|
+
this.tools.set(r.name, r), r.node && (this.toolsByNode.has(r.node) || this.toolsByNode.set(r.node, /* @__PURE__ */ new Map()), this.toolsByNode.get(r.node).set(r.name, r));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Register a new tool
|
|
183
|
+
*/
|
|
184
|
+
registerTool(e) {
|
|
185
|
+
const r = async (o) => e.handler(o);
|
|
186
|
+
Object.defineProperty(r, "name", {
|
|
187
|
+
value: e.name,
|
|
188
|
+
writable: !0,
|
|
189
|
+
configurable: !0
|
|
190
|
+
}), Object.defineProperty(r, "description", {
|
|
191
|
+
value: e.description,
|
|
192
|
+
writable: !0,
|
|
193
|
+
configurable: !0
|
|
194
|
+
}), Object.defineProperty(r, "parameters", {
|
|
195
|
+
value: e.parameters,
|
|
196
|
+
writable: !0,
|
|
197
|
+
configurable: !0
|
|
198
|
+
}), Object.defineProperty(r, "node", {
|
|
199
|
+
value: e.node,
|
|
200
|
+
writable: !0,
|
|
201
|
+
configurable: !0
|
|
202
|
+
}), this.tools.set(e.name, r), e.node && (this.toolsByNode.has(e.node) || this.toolsByNode.set(e.node, /* @__PURE__ */ new Map()), this.toolsByNode.get(e.node).set(e.name, r));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get tools for a specific node
|
|
206
|
+
*/
|
|
207
|
+
getToolsForNode(e) {
|
|
208
|
+
const r = this.toolsByNode.get(e);
|
|
209
|
+
return r ? Array.from(r.values()) : [];
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get all tools in OpenAI-compatible format
|
|
213
|
+
*/
|
|
214
|
+
all_tools() {
|
|
215
|
+
const e = [];
|
|
216
|
+
for (const [r, o] of this.tools) {
|
|
217
|
+
const s = {
|
|
218
|
+
type: "function",
|
|
219
|
+
function: {
|
|
220
|
+
name: r,
|
|
221
|
+
description: o.description || `Execute ${r}`,
|
|
222
|
+
parameters: W(o.parameters)
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
e.push(s);
|
|
226
|
+
}
|
|
227
|
+
return e;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Extract and execute all tool calls from the response
|
|
231
|
+
* Returns an array of tool result messages
|
|
232
|
+
*/
|
|
233
|
+
async executeToolCalls(e) {
|
|
234
|
+
const r = [];
|
|
235
|
+
for (const s of e)
|
|
236
|
+
if (s.content)
|
|
237
|
+
for (const n of s.content)
|
|
238
|
+
n.type === "remote_tool_call" && r.push(n);
|
|
239
|
+
const o = [];
|
|
240
|
+
for (const s of r) {
|
|
241
|
+
const n = s.name;
|
|
242
|
+
if (this.tools.has(n)) {
|
|
243
|
+
const i = this.tools.get(n);
|
|
244
|
+
try {
|
|
245
|
+
const a = await i(s.args), c = new G({
|
|
246
|
+
call_id: s.id,
|
|
247
|
+
output: a,
|
|
248
|
+
status: "completed",
|
|
249
|
+
is_error: !1
|
|
250
|
+
});
|
|
251
|
+
o.push(C.tool_message([c]));
|
|
252
|
+
} catch (a) {
|
|
253
|
+
const c = a instanceof Error ? a.message : String(a), d = new G({
|
|
254
|
+
call_id: s.id,
|
|
255
|
+
output: { error: c },
|
|
256
|
+
status: "failed",
|
|
257
|
+
is_error: !0
|
|
258
|
+
});
|
|
259
|
+
o.push(C.tool_message([d]));
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
const i = new G({
|
|
263
|
+
call_id: s.id,
|
|
264
|
+
output: { error: `Tool '${n}' not found` },
|
|
265
|
+
status: "failed",
|
|
266
|
+
is_error: !0
|
|
267
|
+
});
|
|
268
|
+
o.push(C.tool_message([i]));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return o;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
class g extends Error {
|
|
275
|
+
constructor(e, r, o, s, n, i = [], a, c, d, h) {
|
|
276
|
+
super(e), this.name = "TenxGraphError", this.statusCode = r, this.errorCode = o, this.requestId = s, this.timestamp = n, this.details = i, this.context = a, this.endpoint = c, this.method = d, this.recoverySuggestion = h;
|
|
277
|
+
const l = Error.captureStackTrace;
|
|
278
|
+
l && l(this, this.constructor);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Get a user-friendly error message with recovery suggestion
|
|
282
|
+
*/
|
|
283
|
+
getUserMessage() {
|
|
284
|
+
return this.recoverySuggestion ? `${this.message}
|
|
285
|
+
|
|
286
|
+
Suggestion: ${this.recoverySuggestion}` : this.message;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get full error details for debugging
|
|
290
|
+
*/
|
|
291
|
+
toJSON() {
|
|
292
|
+
return {
|
|
293
|
+
name: this.name,
|
|
294
|
+
message: this.message,
|
|
295
|
+
statusCode: this.statusCode,
|
|
296
|
+
errorCode: this.errorCode,
|
|
297
|
+
requestId: this.requestId,
|
|
298
|
+
timestamp: this.timestamp,
|
|
299
|
+
details: this.details,
|
|
300
|
+
context: this.context,
|
|
301
|
+
endpoint: this.endpoint,
|
|
302
|
+
method: this.method,
|
|
303
|
+
recoverySuggestion: this.recoverySuggestion,
|
|
304
|
+
stack: this.stack
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
class R extends g {
|
|
309
|
+
constructor(e, r, o, s = []) {
|
|
310
|
+
super(e, 400, "BAD_REQUEST", r, o, s), this.name = "BadRequestError";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
class $ extends g {
|
|
314
|
+
constructor(e, r, o, s = []) {
|
|
315
|
+
super(e, 401, "AUTHENTICATION_FAILED", r, o, s), this.name = "AuthenticationError";
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
class k extends g {
|
|
319
|
+
constructor(e, r, o, s = []) {
|
|
320
|
+
super(e, 403, "PERMISSION_ERROR", r, o, s), this.name = "PermissionError";
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
class A extends g {
|
|
324
|
+
constructor(e, r, o, s = []) {
|
|
325
|
+
super(e, 404, "RESOURCE_NOT_FOUND", r, o, s), this.name = "NotFoundError";
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
class I extends g {
|
|
329
|
+
constructor(e, r, o, s = []) {
|
|
330
|
+
super(e, 422, "VALIDATION_ERROR", r, o, s), this.name = "ValidationError";
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
class O extends g {
|
|
334
|
+
constructor(e, r, o, s = "INTERNAL_SERVER_ERROR", n = [], i = 500) {
|
|
335
|
+
super(e, i, s, r, o, n), this.name = "ServerError";
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
class V extends g {
|
|
339
|
+
constructor(e, r, o, s = [], n) {
|
|
340
|
+
super(
|
|
341
|
+
e,
|
|
342
|
+
500,
|
|
343
|
+
"GRAPH_ERROR",
|
|
344
|
+
r,
|
|
345
|
+
o,
|
|
346
|
+
s,
|
|
347
|
+
n,
|
|
348
|
+
void 0,
|
|
349
|
+
void 0,
|
|
350
|
+
"Check your graph configuration and ensure all nodes are properly connected."
|
|
351
|
+
), this.name = "GraphError";
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
class Y extends g {
|
|
355
|
+
constructor(e, r, o, s = [], n, i) {
|
|
356
|
+
super(
|
|
357
|
+
e,
|
|
358
|
+
500,
|
|
359
|
+
"NODE_ERROR",
|
|
360
|
+
r,
|
|
361
|
+
o,
|
|
362
|
+
s,
|
|
363
|
+
n,
|
|
364
|
+
void 0,
|
|
365
|
+
void 0,
|
|
366
|
+
"Review the node implementation and ensure all required inputs are provided."
|
|
367
|
+
), this.name = "NodeError", this.nodeName = i;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
class K extends g {
|
|
371
|
+
constructor(e, r, o, s = [], n, i) {
|
|
372
|
+
super(
|
|
373
|
+
e,
|
|
374
|
+
500,
|
|
375
|
+
"GRAPH_RECURSION_ERROR",
|
|
376
|
+
r,
|
|
377
|
+
o,
|
|
378
|
+
s,
|
|
379
|
+
n,
|
|
380
|
+
void 0,
|
|
381
|
+
void 0,
|
|
382
|
+
"Consider increasing the recursion_limit parameter or check for infinite loops in your graph."
|
|
383
|
+
), this.name = "GraphRecursionError", this.recursionLimit = i;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
class Z extends g {
|
|
387
|
+
constructor(e, r, o, s = [], n) {
|
|
388
|
+
super(
|
|
389
|
+
e,
|
|
390
|
+
500,
|
|
391
|
+
"STORAGE_ERROR",
|
|
392
|
+
r,
|
|
393
|
+
o,
|
|
394
|
+
s,
|
|
395
|
+
n,
|
|
396
|
+
void 0,
|
|
397
|
+
void 0,
|
|
398
|
+
"Check your storage configuration and ensure the storage backend is accessible."
|
|
399
|
+
), this.name = "StorageError";
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
class Q extends g {
|
|
403
|
+
constructor(e, r, o, s = [], n) {
|
|
404
|
+
super(
|
|
405
|
+
e,
|
|
406
|
+
503,
|
|
407
|
+
"TRANSIENT_STORAGE_ERROR",
|
|
408
|
+
r,
|
|
409
|
+
o,
|
|
410
|
+
s,
|
|
411
|
+
n,
|
|
412
|
+
void 0,
|
|
413
|
+
void 0,
|
|
414
|
+
"This is a temporary issue. Please retry your request after a short delay."
|
|
415
|
+
), this.name = "TransientStorageError";
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
class X extends g {
|
|
419
|
+
constructor(e, r, o, s = [], n) {
|
|
420
|
+
super(
|
|
421
|
+
e,
|
|
422
|
+
500,
|
|
423
|
+
"METRICS_ERROR",
|
|
424
|
+
r,
|
|
425
|
+
o,
|
|
426
|
+
s,
|
|
427
|
+
n,
|
|
428
|
+
void 0,
|
|
429
|
+
void 0,
|
|
430
|
+
"Check your metrics configuration. This error typically doesn't affect core functionality."
|
|
431
|
+
), this.name = "MetricsError";
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
class q extends g {
|
|
435
|
+
constructor(e, r, o, s = [], n, i, a) {
|
|
436
|
+
super(
|
|
437
|
+
e,
|
|
438
|
+
422,
|
|
439
|
+
"SCHEMA_VERSION_ERROR",
|
|
440
|
+
r,
|
|
441
|
+
o,
|
|
442
|
+
s,
|
|
443
|
+
n,
|
|
444
|
+
void 0,
|
|
445
|
+
void 0,
|
|
446
|
+
"Update your client to match the server schema version or contact support."
|
|
447
|
+
), this.name = "SchemaVersionError", this.expectedVersion = i, this.actualVersion = a;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
class ee extends g {
|
|
451
|
+
constructor(e, r, o, s = [], n) {
|
|
452
|
+
super(
|
|
453
|
+
e,
|
|
454
|
+
500,
|
|
455
|
+
"SERIALIZATION_ERROR",
|
|
456
|
+
r,
|
|
457
|
+
o,
|
|
458
|
+
s,
|
|
459
|
+
n,
|
|
460
|
+
void 0,
|
|
461
|
+
void 0,
|
|
462
|
+
"Ensure your data format is compatible with the API schema."
|
|
463
|
+
), this.name = "SerializationError";
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async function te(t) {
|
|
467
|
+
try {
|
|
468
|
+
const e = t.headers.get("content-type");
|
|
469
|
+
return e && e.includes("application/json") ? await t.json() : null;
|
|
470
|
+
} catch {
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async function p(t, e, r, o) {
|
|
475
|
+
const s = await te(t);
|
|
476
|
+
if (s) {
|
|
477
|
+
const { metadata: a, error: c } = s, d = c.message || e || `HTTP error ${t.status}`, h = a.request_id || "unknown", l = a.timestamp || (/* @__PURE__ */ new Date()).toISOString(), u = c.details || [], T = c.code || "";
|
|
478
|
+
if (T.startsWith("GRAPH_RECURSION"))
|
|
479
|
+
return new K(d, h, l, u);
|
|
480
|
+
if (T.startsWith("GRAPH"))
|
|
481
|
+
return new V(d, h, l, u);
|
|
482
|
+
if (T.startsWith("NODE"))
|
|
483
|
+
return new Y(d, h, l, u);
|
|
484
|
+
if (T.startsWith("TRANSIENT_STORAGE"))
|
|
485
|
+
return new Q(d, h, l, u);
|
|
486
|
+
if (T.startsWith("STORAGE"))
|
|
487
|
+
return new Z(d, h, l, u);
|
|
488
|
+
if (T.startsWith("METRICS"))
|
|
489
|
+
return new X(d, h, l, u);
|
|
490
|
+
if (T.startsWith("SCHEMA_VERSION"))
|
|
491
|
+
return new q(d, h, l, u);
|
|
492
|
+
if (T.startsWith("SERIALIZATION"))
|
|
493
|
+
return new ee(d, h, l, u);
|
|
494
|
+
switch (t.status) {
|
|
495
|
+
case 400:
|
|
496
|
+
return new R(d, h, l, u);
|
|
497
|
+
case 401:
|
|
498
|
+
return new $(d, h, l, u);
|
|
499
|
+
case 403:
|
|
500
|
+
return new k(d, h, l, u);
|
|
501
|
+
case 404:
|
|
502
|
+
return new A(d, h, l, u);
|
|
503
|
+
case 422:
|
|
504
|
+
return new I(d, h, l, u);
|
|
505
|
+
case 500:
|
|
506
|
+
case 502:
|
|
507
|
+
case 503:
|
|
508
|
+
case 504:
|
|
509
|
+
return new O(
|
|
510
|
+
d,
|
|
511
|
+
h,
|
|
512
|
+
l,
|
|
513
|
+
T || "INTERNAL_SERVER_ERROR",
|
|
514
|
+
u,
|
|
515
|
+
t.status
|
|
516
|
+
);
|
|
517
|
+
default:
|
|
518
|
+
return new g(
|
|
519
|
+
d,
|
|
520
|
+
t.status,
|
|
521
|
+
T || "UNKNOWN_ERROR",
|
|
522
|
+
h,
|
|
523
|
+
l,
|
|
524
|
+
u,
|
|
525
|
+
void 0,
|
|
526
|
+
r,
|
|
527
|
+
o
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const n = e || `HTTP error! status: ${t.status}`, i = (/* @__PURE__ */ new Date()).toISOString();
|
|
532
|
+
switch (t.status) {
|
|
533
|
+
case 400:
|
|
534
|
+
return new R(n, "unknown", i);
|
|
535
|
+
case 401:
|
|
536
|
+
return new $(n, "unknown", i);
|
|
537
|
+
case 403:
|
|
538
|
+
return new k(n, "unknown", i);
|
|
539
|
+
case 404:
|
|
540
|
+
return new A(n, "unknown", i);
|
|
541
|
+
case 422:
|
|
542
|
+
return new I(n, "unknown", i);
|
|
543
|
+
case 500:
|
|
544
|
+
case 502:
|
|
545
|
+
case 503:
|
|
546
|
+
case 504:
|
|
547
|
+
return new O(
|
|
548
|
+
n,
|
|
549
|
+
"unknown",
|
|
550
|
+
i,
|
|
551
|
+
"INTERNAL_SERVER_ERROR",
|
|
552
|
+
[],
|
|
553
|
+
t.status
|
|
554
|
+
);
|
|
555
|
+
default:
|
|
556
|
+
return new g(
|
|
557
|
+
n,
|
|
558
|
+
t.status,
|
|
559
|
+
"UNKNOWN_ERROR",
|
|
560
|
+
"unknown",
|
|
561
|
+
i,
|
|
562
|
+
[],
|
|
563
|
+
void 0,
|
|
564
|
+
r,
|
|
565
|
+
o
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function _(t, e, r) {
|
|
570
|
+
if (r != null) {
|
|
571
|
+
for (const o of Object.keys(t))
|
|
572
|
+
o.toLowerCase() === e.toLowerCase() && delete t[o];
|
|
573
|
+
t[e] = r;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
function N(t, e) {
|
|
577
|
+
if (e) {
|
|
578
|
+
if (e instanceof Headers) {
|
|
579
|
+
e.forEach((r, o) => {
|
|
580
|
+
_(t, o, r);
|
|
581
|
+
});
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if (Array.isArray(e)) {
|
|
585
|
+
for (const [r, o] of e)
|
|
586
|
+
_(t, r, o);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
for (const [r, o] of Object.entries(e))
|
|
590
|
+
o !== void 0 && _(t, r, String(o));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function re(t, e) {
|
|
594
|
+
return Object.keys(t).some(
|
|
595
|
+
(r) => r.toLowerCase() === e.toLowerCase()
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
function oe(t) {
|
|
599
|
+
const e = globalThis.Buffer;
|
|
600
|
+
if (e)
|
|
601
|
+
return e.from(t, "utf-8").toString("base64");
|
|
602
|
+
if (typeof btoa == "function") {
|
|
603
|
+
const r = new TextEncoder().encode(t);
|
|
604
|
+
let o = "";
|
|
605
|
+
for (const s of r)
|
|
606
|
+
o += String.fromCharCode(s);
|
|
607
|
+
return btoa(o);
|
|
608
|
+
}
|
|
609
|
+
throw new Error("Basic authentication is not supported in this runtime");
|
|
610
|
+
}
|
|
611
|
+
function se(t, e) {
|
|
612
|
+
if (!e)
|
|
613
|
+
return;
|
|
614
|
+
if (e.type === "bearer") {
|
|
615
|
+
_(t, "Authorization", `Bearer ${e.token}`);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (e.type === "basic") {
|
|
619
|
+
const o = oe(`${e.username}:${e.password}`);
|
|
620
|
+
_(t, "Authorization", `Basic ${o}`);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const r = e.prefix ? `${e.prefix} ${e.value}` : e.value;
|
|
624
|
+
_(t, e.name, r);
|
|
625
|
+
}
|
|
626
|
+
function m(t, e) {
|
|
627
|
+
const r = {};
|
|
628
|
+
return N(r, e), N(r, t.headers), t.auth ? se(r, t.auth) : t.authToken && !re(r, "Authorization") && _(r, "Authorization", `Bearer ${t.authToken}`), r;
|
|
629
|
+
}
|
|
630
|
+
function f(t) {
|
|
631
|
+
return t.credentials ? { credentials: t.credentials } : {};
|
|
632
|
+
}
|
|
633
|
+
function ft(t) {
|
|
634
|
+
return { type: "bearer", token: t };
|
|
635
|
+
}
|
|
636
|
+
function pt(t, e) {
|
|
637
|
+
return { type: "basic", username: t, password: e };
|
|
638
|
+
}
|
|
639
|
+
function gt(t, e, r) {
|
|
640
|
+
return { type: "header", name: t, value: e, prefix: r };
|
|
641
|
+
}
|
|
642
|
+
async function ne(t) {
|
|
643
|
+
try {
|
|
644
|
+
t.debug && console.debug("TenxGraphClient: Pinging server at", t.baseUrl);
|
|
645
|
+
const e = new AbortController(), r = setTimeout(() => e.abort(), t.timeout), o = await fetch(`${t.baseUrl}/ping`, {
|
|
646
|
+
method: "GET",
|
|
647
|
+
headers: m(t, {
|
|
648
|
+
"Content-Type": "application/json"
|
|
649
|
+
}),
|
|
650
|
+
...f(t),
|
|
651
|
+
signal: e.signal
|
|
652
|
+
});
|
|
653
|
+
if (clearTimeout(r), !o.ok)
|
|
654
|
+
throw console.warn(`TenxGraphClient: Ping failed with HTTP ${o.status}`), await p(o, "Ping request failed", "/ping", "GET");
|
|
655
|
+
const s = await o.json();
|
|
656
|
+
return t.debug && console.info("TenxGraphClient: Ping successful", s), s;
|
|
657
|
+
} catch (e) {
|
|
658
|
+
throw t.debug && console.debug("TenxGraphClient: Ping failed:", e), e.name === "AbortError" ? (console.warn(`TenxGraphClient: Ping timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Ping failed:", e), e);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
async function ie(t) {
|
|
662
|
+
try {
|
|
663
|
+
t.debug && console.debug("TenxGraphClient: Fetching graph from", t.baseUrl);
|
|
664
|
+
const e = new AbortController(), r = setTimeout(() => e.abort(), t.timeout), o = await fetch(`${t.baseUrl}/v1/graph`, {
|
|
665
|
+
method: "GET",
|
|
666
|
+
headers: m(t, {
|
|
667
|
+
"Content-Type": "application/json",
|
|
668
|
+
accept: "application/json"
|
|
669
|
+
}),
|
|
670
|
+
...f(t),
|
|
671
|
+
signal: e.signal
|
|
672
|
+
});
|
|
673
|
+
if (clearTimeout(r), !o.ok)
|
|
674
|
+
throw console.warn(`TenxGraphClient: Graph fetch failed with HTTP ${o.status}`), await p(
|
|
675
|
+
o,
|
|
676
|
+
"Graph fetch failed",
|
|
677
|
+
"/v1/graph",
|
|
678
|
+
"GET"
|
|
679
|
+
);
|
|
680
|
+
const s = await o.json();
|
|
681
|
+
return t.debug && console.info("TenxGraphClient: Graph fetch successful", s), s;
|
|
682
|
+
} catch (e) {
|
|
683
|
+
throw t.debug && console.debug("TenxGraphClient: Graph fetch failed:", e), e.name === "AbortError" ? (console.warn(`TenxGraphClient: Graph fetch timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Graph fetch failed:", e), e);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
async function ae(t) {
|
|
687
|
+
try {
|
|
688
|
+
t.debug && console.debug("TenxGraphClient: Fetching graph tools from", t.baseUrl);
|
|
689
|
+
const e = new AbortController(), r = setTimeout(() => e.abort(), t.timeout), o = await fetch(`${t.baseUrl}/v1/graph/tools`, {
|
|
690
|
+
method: "GET",
|
|
691
|
+
headers: m(t, {
|
|
692
|
+
"Content-Type": "application/json",
|
|
693
|
+
accept: "application/json"
|
|
694
|
+
}),
|
|
695
|
+
...f(t),
|
|
696
|
+
signal: e.signal
|
|
697
|
+
});
|
|
698
|
+
if (clearTimeout(r), !o.ok)
|
|
699
|
+
throw console.warn(`TenxGraphClient: Graph tools fetch failed with HTTP ${o.status}`), await p(
|
|
700
|
+
o,
|
|
701
|
+
"Graph tools fetch failed",
|
|
702
|
+
"/v1/graph/tools",
|
|
703
|
+
"GET"
|
|
704
|
+
);
|
|
705
|
+
const s = await o.json();
|
|
706
|
+
return t.debug && console.info("TenxGraphClient: Graph tools fetch successful", s), s;
|
|
707
|
+
} catch (e) {
|
|
708
|
+
throw t.debug && console.debug("TenxGraphClient: Graph tools fetch failed:", e), e.name === "AbortError" ? (console.warn(`TenxGraphClient: Graph tools fetch timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Graph tools fetch failed:", e), e);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
async function le(t, e, r) {
|
|
712
|
+
try {
|
|
713
|
+
const o = new AbortController(), s = setTimeout(() => o.abort(), t.timeout), n = r ? `?run_id=${encodeURIComponent(r)}` : "", i = await fetch(
|
|
714
|
+
`${t.baseUrl}/v1/observability/${encodeURIComponent(e)}${n}`,
|
|
715
|
+
{
|
|
716
|
+
method: "GET",
|
|
717
|
+
headers: m(t, {
|
|
718
|
+
"Content-Type": "application/json",
|
|
719
|
+
accept: "application/json"
|
|
720
|
+
}),
|
|
721
|
+
...f(t),
|
|
722
|
+
signal: o.signal
|
|
723
|
+
}
|
|
724
|
+
);
|
|
725
|
+
if (clearTimeout(s), !i.ok)
|
|
726
|
+
throw await p(
|
|
727
|
+
i,
|
|
728
|
+
"Observability fetch failed",
|
|
729
|
+
`/v1/observability/${e}`,
|
|
730
|
+
"GET"
|
|
731
|
+
);
|
|
732
|
+
return await i.json();
|
|
733
|
+
} catch (o) {
|
|
734
|
+
throw o.name === "AbortError" ? new Error(`Request timeout after ${t.timeout}ms`) : o;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
async function ce(t) {
|
|
738
|
+
try {
|
|
739
|
+
t.debug && console.debug("TenxGraphClient: Fetching state schema from", t.baseUrl);
|
|
740
|
+
const e = new AbortController(), r = setTimeout(() => e.abort(), t.timeout), o = await fetch(`${t.baseUrl}/v1/graph:StateSchema`, {
|
|
741
|
+
method: "GET",
|
|
742
|
+
headers: m(t, {
|
|
743
|
+
"Content-Type": "application/json",
|
|
744
|
+
accept: "application/json"
|
|
745
|
+
}),
|
|
746
|
+
...f(t),
|
|
747
|
+
signal: e.signal
|
|
748
|
+
});
|
|
749
|
+
if (clearTimeout(r), !o.ok)
|
|
750
|
+
throw console.warn(`TenxGraphClient: State schema fetch failed with HTTP ${o.status}`), await p(
|
|
751
|
+
o,
|
|
752
|
+
"State schema fetch failed",
|
|
753
|
+
"/v1/state_schema",
|
|
754
|
+
"GET"
|
|
755
|
+
);
|
|
756
|
+
const s = await o.json();
|
|
757
|
+
return t.debug && console.info("TenxGraphClient: State schema fetch successful", s), s;
|
|
758
|
+
} catch (e) {
|
|
759
|
+
throw t.debug && console.debug("TenxGraphClient: State schema fetch failed:", e), e.name === "AbortError" ? (console.warn(`TenxGraphClient: State schema fetch timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: State schema fetch failed:", e), e);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
async function he(t, e) {
|
|
763
|
+
try {
|
|
764
|
+
t.debug && console.debug(`TenxGraphClient: Fetching thread state for thread ${e}`);
|
|
765
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = await fetch(`${t.baseUrl}/v1/threads/${e}/state`, {
|
|
766
|
+
method: "GET",
|
|
767
|
+
headers: m(t, {
|
|
768
|
+
"Content-Type": "application/json",
|
|
769
|
+
accept: "application/json"
|
|
770
|
+
}),
|
|
771
|
+
...f(t),
|
|
772
|
+
signal: r.signal
|
|
773
|
+
});
|
|
774
|
+
if (clearTimeout(o), !s.ok)
|
|
775
|
+
throw console.warn(`TenxGraphClient: Thread state fetch failed with HTTP ${s.status}`), await p(
|
|
776
|
+
s,
|
|
777
|
+
"Thread state fetch failed",
|
|
778
|
+
"/v1/threads/{thread_id}/state",
|
|
779
|
+
"GET"
|
|
780
|
+
);
|
|
781
|
+
const n = await s.json();
|
|
782
|
+
return t.debug && console.info(
|
|
783
|
+
`TenxGraphClient: Thread state fetched successfully for thread ${e}`,
|
|
784
|
+
n
|
|
785
|
+
), n;
|
|
786
|
+
} catch (r) {
|
|
787
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Thread state fetch timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Thread state fetch failed:", r), r);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
async function de(t, e, r) {
|
|
791
|
+
try {
|
|
792
|
+
t.debug && (console.debug(`TenxGraphClient: Updating thread state for thread ${e}`), console.debug("TenxGraphClient: Request payload:", JSON.stringify(r, null, 2)));
|
|
793
|
+
const o = new AbortController(), s = setTimeout(() => o.abort(), t.timeout), n = await fetch(`${t.baseUrl}/v1/threads/${e}/state`, {
|
|
794
|
+
method: "PUT",
|
|
795
|
+
headers: m(t, {
|
|
796
|
+
"Content-Type": "application/json",
|
|
797
|
+
accept: "application/json"
|
|
798
|
+
}),
|
|
799
|
+
...f(t),
|
|
800
|
+
body: JSON.stringify(r),
|
|
801
|
+
signal: o.signal
|
|
802
|
+
});
|
|
803
|
+
if (clearTimeout(s), !n.ok)
|
|
804
|
+
throw console.warn(`TenxGraphClient: Thread state update failed with HTTP ${n.status}`), await p(
|
|
805
|
+
n,
|
|
806
|
+
"Thread state update failed",
|
|
807
|
+
"/v1/threads/{thread_id}/state",
|
|
808
|
+
"PUT"
|
|
809
|
+
);
|
|
810
|
+
const i = await n.json();
|
|
811
|
+
return t.debug && console.info(
|
|
812
|
+
`TenxGraphClient: Thread state updated successfully for thread ${e}`,
|
|
813
|
+
i
|
|
814
|
+
), i;
|
|
815
|
+
} catch (o) {
|
|
816
|
+
throw o.name === "AbortError" ? (console.warn(`TenxGraphClient: Thread state update timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Thread state update failed:", o), o);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
async function ue(t, e) {
|
|
820
|
+
try {
|
|
821
|
+
t.debug && console.debug(`TenxGraphClient: Clearing thread state for thread ${e}`);
|
|
822
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = await fetch(`${t.baseUrl}/v1/threads/${e}/state`, {
|
|
823
|
+
method: "DELETE",
|
|
824
|
+
headers: m(t, {
|
|
825
|
+
"Content-Type": "application/json",
|
|
826
|
+
accept: "application/json"
|
|
827
|
+
}),
|
|
828
|
+
...f(t),
|
|
829
|
+
signal: r.signal
|
|
830
|
+
});
|
|
831
|
+
if (clearTimeout(o), !s.ok)
|
|
832
|
+
throw console.warn(`TenxGraphClient: Thread state clear failed with HTTP ${s.status}`), await p(
|
|
833
|
+
s,
|
|
834
|
+
"Thread state clear failed",
|
|
835
|
+
"/v1/threads/{thread_id}/state",
|
|
836
|
+
"DELETE"
|
|
837
|
+
);
|
|
838
|
+
const n = await s.json();
|
|
839
|
+
return t.debug && console.info(
|
|
840
|
+
`TenxGraphClient: Thread state cleared successfully for thread ${e}`,
|
|
841
|
+
n
|
|
842
|
+
), n;
|
|
843
|
+
} catch (r) {
|
|
844
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Thread state clear timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Thread state clear failed:", r), r);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
async function U(t, e) {
|
|
848
|
+
try {
|
|
849
|
+
t.debug && console.debug("TenxGraphClient: Fetching thread messages for thread", e.threadId);
|
|
850
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = new URLSearchParams();
|
|
851
|
+
e.search !== void 0 && s.append("search", e.search), e.offset !== void 0 && s.append("offset", e.offset.toString()), e.limit !== void 0 && s.append("limit", e.limit.toString());
|
|
852
|
+
const n = s.toString(), i = `${t.baseUrl}/v1/threads/${e.threadId}/messages${n ? "?" + n : ""}`, a = await fetch(i, {
|
|
853
|
+
method: "GET",
|
|
854
|
+
headers: m(t, {
|
|
855
|
+
"Content-Type": "application/json"
|
|
856
|
+
}),
|
|
857
|
+
...f(t),
|
|
858
|
+
signal: r.signal
|
|
859
|
+
});
|
|
860
|
+
if (clearTimeout(o), !a.ok)
|
|
861
|
+
throw console.warn(
|
|
862
|
+
`TenxGraphClient: Checkpoint messages fetch failed with HTTP ${a.status}`
|
|
863
|
+
), await p(
|
|
864
|
+
a,
|
|
865
|
+
"Thread messages fetch failed",
|
|
866
|
+
"/v1/threads/{thread_id}/messages",
|
|
867
|
+
"GET"
|
|
868
|
+
);
|
|
869
|
+
const c = await a.json();
|
|
870
|
+
return t.debug && console.info("TenxGraphClient: Thread messages fetched successfully", c), c;
|
|
871
|
+
} catch (r) {
|
|
872
|
+
throw t.debug && console.debug("TenxGraphClient: Checkpoint messages fetch failed:", r), r;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
const Tt = U;
|
|
876
|
+
async function me(t, e) {
|
|
877
|
+
try {
|
|
878
|
+
t.debug && console.debug("TenxGraphClient: Adding thread messages to thread", e.threadId);
|
|
879
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/threads/${e.threadId}/messages`, n = {
|
|
880
|
+
config: e.config,
|
|
881
|
+
messages: e.messages,
|
|
882
|
+
metadata: e.metadata || {}
|
|
883
|
+
}, i = await fetch(s, {
|
|
884
|
+
method: "POST",
|
|
885
|
+
headers: m(t, {
|
|
886
|
+
"Content-Type": "application/json"
|
|
887
|
+
}),
|
|
888
|
+
...f(t),
|
|
889
|
+
body: JSON.stringify(n),
|
|
890
|
+
signal: r.signal
|
|
891
|
+
});
|
|
892
|
+
if (clearTimeout(o), !i.ok)
|
|
893
|
+
throw console.warn(`TenxGraphClient: Add checkpoint messages failed with HTTP ${i.status}`), await p(
|
|
894
|
+
i,
|
|
895
|
+
"Add thread messages failed",
|
|
896
|
+
"/v1/threads/{thread_id}/messages",
|
|
897
|
+
"POST"
|
|
898
|
+
);
|
|
899
|
+
const a = await i.json();
|
|
900
|
+
return t.debug && console.info("TenxGraphClient: Thread messages added successfully", a), a;
|
|
901
|
+
} catch (r) {
|
|
902
|
+
throw t.debug && console.debug("TenxGraphClient: Add checkpoint messages failed:", r), r;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
async function fe(t, e) {
|
|
906
|
+
try {
|
|
907
|
+
t.debug && console.debug(
|
|
908
|
+
"TenxGraphClient: Fetching thread message",
|
|
909
|
+
`thread: ${e.threadId}`,
|
|
910
|
+
`message: ${e.messageId}`
|
|
911
|
+
);
|
|
912
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/threads/${e.threadId}/messages/${e.messageId}`, n = await fetch(s, {
|
|
913
|
+
method: "GET",
|
|
914
|
+
headers: m(t, {
|
|
915
|
+
"Content-Type": "application/json"
|
|
916
|
+
}),
|
|
917
|
+
...f(t),
|
|
918
|
+
signal: r.signal
|
|
919
|
+
});
|
|
920
|
+
if (clearTimeout(o), !n.ok)
|
|
921
|
+
throw console.warn(`TenxGraphClient: Thread message fetch failed with HTTP ${n.status}`), await p(
|
|
922
|
+
n,
|
|
923
|
+
"Thread message fetch failed",
|
|
924
|
+
"/v1/threads/{thread_id}/messages/{message_id}",
|
|
925
|
+
"GET"
|
|
926
|
+
);
|
|
927
|
+
const i = await n.json();
|
|
928
|
+
return t.debug && console.info("TenxGraphClient: Thread message fetched successfully", i), i;
|
|
929
|
+
} catch (r) {
|
|
930
|
+
throw t.debug && console.debug("TenxGraphClient: Thread message fetch failed:", r), r;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
async function pe(t, e) {
|
|
934
|
+
try {
|
|
935
|
+
t.debug && console.debug(`TenxGraphClient: Fetching thread details for thread ${e}`);
|
|
936
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/threads/${e}`, n = await fetch(s, {
|
|
937
|
+
method: "GET",
|
|
938
|
+
headers: m(t, {
|
|
939
|
+
"Content-Type": "application/json",
|
|
940
|
+
accept: "application/json"
|
|
941
|
+
}),
|
|
942
|
+
...f(t),
|
|
943
|
+
signal: r.signal
|
|
944
|
+
});
|
|
945
|
+
if (clearTimeout(o), !n.ok)
|
|
946
|
+
throw console.warn(`TenxGraphClient: Thread details fetch failed with HTTP ${n.status}`), await p(
|
|
947
|
+
n,
|
|
948
|
+
"Thread details fetch failed",
|
|
949
|
+
"/v1/threads/{thread_id}",
|
|
950
|
+
"GET"
|
|
951
|
+
);
|
|
952
|
+
const i = await n.json();
|
|
953
|
+
return t.debug && console.info("TenxGraphClient: Thread details fetched successfully", i), i;
|
|
954
|
+
} catch (r) {
|
|
955
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Thread details fetch timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Thread details fetch failed:", r), r);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
async function ge(t, e) {
|
|
959
|
+
try {
|
|
960
|
+
t.debug && console.debug(
|
|
961
|
+
"TenxGraphClient: Deleting thread message",
|
|
962
|
+
`thread: ${e.threadId}`,
|
|
963
|
+
`message: ${e.messageId}`
|
|
964
|
+
);
|
|
965
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/threads/${e.threadId}/messages/${e.messageId}`, n = await fetch(s, {
|
|
966
|
+
method: "DELETE",
|
|
967
|
+
headers: m(t, {
|
|
968
|
+
"Content-Type": "application/json",
|
|
969
|
+
accept: "application/json"
|
|
970
|
+
}),
|
|
971
|
+
...f(t),
|
|
972
|
+
body: JSON.stringify({ config: e.config || {} }),
|
|
973
|
+
signal: r.signal
|
|
974
|
+
});
|
|
975
|
+
if (clearTimeout(o), !n.ok)
|
|
976
|
+
throw console.warn(`TenxGraphClient: Delete thread message failed with HTTP ${n.status}`), await p(
|
|
977
|
+
n,
|
|
978
|
+
"Delete thread message failed",
|
|
979
|
+
"/v1/threads/{thread_id}/messages/{message_id}",
|
|
980
|
+
"DELETE"
|
|
981
|
+
);
|
|
982
|
+
const i = await n.json();
|
|
983
|
+
return t.debug && console.info("TenxGraphClient: Thread message deleted successfully", i), i;
|
|
984
|
+
} catch (r) {
|
|
985
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Delete thread message timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Delete thread message failed:", r), r);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
async function Te(t, e) {
|
|
989
|
+
try {
|
|
990
|
+
t.debug && console.debug("TenxGraphClient: Deleting thread", `thread: ${e.threadId}`);
|
|
991
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/threads/${e.threadId}`, n = await fetch(s, {
|
|
992
|
+
method: "DELETE",
|
|
993
|
+
headers: m(t, {
|
|
994
|
+
"Content-Type": "application/json",
|
|
995
|
+
accept: "application/json"
|
|
996
|
+
}),
|
|
997
|
+
...f(t),
|
|
998
|
+
body: JSON.stringify({ config: e.config || {} }),
|
|
999
|
+
signal: r.signal
|
|
1000
|
+
});
|
|
1001
|
+
if (clearTimeout(o), !n.ok)
|
|
1002
|
+
throw console.warn(`TenxGraphClient: Delete thread failed with HTTP ${n.status}`), await p(
|
|
1003
|
+
n,
|
|
1004
|
+
"Delete thread failed",
|
|
1005
|
+
"/v1/threads/{thread_id}",
|
|
1006
|
+
"DELETE"
|
|
1007
|
+
);
|
|
1008
|
+
const i = await n.json();
|
|
1009
|
+
return t.debug && console.info("TenxGraphClient: Thread deleted successfully", i), i;
|
|
1010
|
+
} catch (r) {
|
|
1011
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Delete thread timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Delete thread failed:", r), r);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
async function ye(t, e) {
|
|
1015
|
+
try {
|
|
1016
|
+
t.debug && (console.debug("TenxGraphClient: Fetching threads list"), e?.search && console.debug(` Search: ${e.search}`), e?.offset !== void 0 && console.debug(` Offset: ${e.offset}`), e?.limit !== void 0 && console.debug(` Limit: ${e.limit}`));
|
|
1017
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = new URLSearchParams();
|
|
1018
|
+
e?.search && s.append("search", e.search), e?.offset !== void 0 && s.append("offset", e.offset.toString()), e?.limit !== void 0 && s.append("limit", e.limit.toString());
|
|
1019
|
+
const n = s.toString(), i = `${t.baseUrl}/v1/threads${n ? `?${n}` : ""}`, a = await fetch(i, {
|
|
1020
|
+
method: "GET",
|
|
1021
|
+
headers: m(t, {
|
|
1022
|
+
"Content-Type": "application/json",
|
|
1023
|
+
accept: "application/json"
|
|
1024
|
+
}),
|
|
1025
|
+
...f(t),
|
|
1026
|
+
signal: r.signal
|
|
1027
|
+
});
|
|
1028
|
+
if (clearTimeout(o), !a.ok)
|
|
1029
|
+
throw console.warn(`TenxGraphClient: Threads list fetch failed with HTTP ${a.status}`), await p(
|
|
1030
|
+
a,
|
|
1031
|
+
"Threads list fetch failed",
|
|
1032
|
+
"/v1/threads",
|
|
1033
|
+
"GET"
|
|
1034
|
+
);
|
|
1035
|
+
const c = await a.json();
|
|
1036
|
+
return t.debug && (console.info("TenxGraphClient: Threads list fetched successfully", c), console.debug(` Found ${c.data.threads.length} threads`)), c;
|
|
1037
|
+
} catch (r) {
|
|
1038
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Threads list fetch timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Threads list fetch failed:", r), r);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
async function we(t, e) {
|
|
1042
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout);
|
|
1043
|
+
try {
|
|
1044
|
+
const s = await fetch(`${t.baseUrl}/v1/graph/invoke`, {
|
|
1045
|
+
method: "POST",
|
|
1046
|
+
headers: m(t, {
|
|
1047
|
+
"Content-Type": "application/json",
|
|
1048
|
+
accept: "application/json"
|
|
1049
|
+
}),
|
|
1050
|
+
...f(t),
|
|
1051
|
+
body: JSON.stringify(e),
|
|
1052
|
+
signal: r.signal
|
|
1053
|
+
});
|
|
1054
|
+
if (clearTimeout(o), !s.ok)
|
|
1055
|
+
throw console.warn(`TenxGraphClient: Invoke failed with HTTP ${s.status}`), await p(
|
|
1056
|
+
s,
|
|
1057
|
+
"Invoke request failed",
|
|
1058
|
+
"/v1/invoke",
|
|
1059
|
+
"POST"
|
|
1060
|
+
);
|
|
1061
|
+
return await s.json();
|
|
1062
|
+
} catch (s) {
|
|
1063
|
+
throw clearTimeout(o), s.name === "AbortError" ? (console.warn(`TenxGraphClient: Invoke timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Invoke failed:", s), s);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
function be(t) {
|
|
1067
|
+
return !t.data || !t.data.messages ? !1 : t.data.messages.some(
|
|
1068
|
+
(e) => e.content && e.content.some((r) => r.type === "remote_tool_call")
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
async function Ce(t, e, r) {
|
|
1072
|
+
const o = e.recursion_limit || 25;
|
|
1073
|
+
t.debug && (console.debug("TenxGraphClient: Starting invoke with recursion_limit:", o), console.debug("TenxGraphClient: Initial request:", JSON.stringify(e, null, 2)));
|
|
1074
|
+
const s = [];
|
|
1075
|
+
let n = e.messages, i = 0, a = !1, c;
|
|
1076
|
+
const d = e.initial_state, h = e.config, l = e.response_granularity;
|
|
1077
|
+
for (; i < o; ) {
|
|
1078
|
+
i++, t.debug && console.debug(`TenxGraphClient: Iteration ${i}/${o}`);
|
|
1079
|
+
const T = {
|
|
1080
|
+
messages: n,
|
|
1081
|
+
initial_state: i === 1 ? d : void 0,
|
|
1082
|
+
config: h,
|
|
1083
|
+
recursion_limit: o,
|
|
1084
|
+
response_granularity: l
|
|
1085
|
+
};
|
|
1086
|
+
t.debug && console.debug("TenxGraphClient: Request payload:", JSON.stringify(T, null, 2));
|
|
1087
|
+
const y = await we(t, T);
|
|
1088
|
+
c = y, t.debug && (console.info("TenxGraphClient: Invoke successful"), console.debug("TenxGraphClient: Response:", JSON.stringify(y, null, 2))), y.data.messages && s.push(...y.data.messages);
|
|
1089
|
+
const w = be(y);
|
|
1090
|
+
if (r) {
|
|
1091
|
+
const E = {
|
|
1092
|
+
iteration: i,
|
|
1093
|
+
messages: y.data.messages,
|
|
1094
|
+
state: y.data.state,
|
|
1095
|
+
context: y.data.context,
|
|
1096
|
+
summary: y.data.summary,
|
|
1097
|
+
meta: y.data.meta,
|
|
1098
|
+
has_tool_calls: w,
|
|
1099
|
+
is_final: !w
|
|
1100
|
+
};
|
|
1101
|
+
await r(E);
|
|
1102
|
+
}
|
|
1103
|
+
if (w && t.toolExecutor) {
|
|
1104
|
+
t.debug && console.debug("TenxGraphClient: Found remote tool calls, executing...");
|
|
1105
|
+
const E = await t.toolExecutor.executeToolCalls(y.data.messages);
|
|
1106
|
+
t.debug && console.debug(`TenxGraphClient: Executed ${E.length} tool calls`), s.push(...E), n = E.map((F) => _e(F));
|
|
1107
|
+
continue;
|
|
1108
|
+
} else {
|
|
1109
|
+
t.debug && console.debug("TenxGraphClient: No remote tool calls found, finishing");
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
i >= o && (a = !0, t.debug && console.warn(`TenxGraphClient: Recursion limit of ${o} reached`));
|
|
1114
|
+
const u = {
|
|
1115
|
+
messages: c?.data.messages || [],
|
|
1116
|
+
state: c?.data.state,
|
|
1117
|
+
context: c?.data.context,
|
|
1118
|
+
summary: c?.data.summary,
|
|
1119
|
+
meta: c?.data.meta || { is_new_thread: !1, thread_id: "" },
|
|
1120
|
+
all_messages: s,
|
|
1121
|
+
iterations: i,
|
|
1122
|
+
recursion_limit_reached: a
|
|
1123
|
+
};
|
|
1124
|
+
return t.debug && (console.debug(`TenxGraphClient: Invoke completed after ${i} iterations`), console.debug(`TenxGraphClient: Total messages: ${s.length}`)), u;
|
|
1125
|
+
}
|
|
1126
|
+
function Ee(t) {
|
|
1127
|
+
return t.map((e) => {
|
|
1128
|
+
const r = {};
|
|
1129
|
+
for (const [o, s] of Object.entries(e))
|
|
1130
|
+
Array.isArray(s) && s.length === 0 || s !== void 0 && (r[o] = s);
|
|
1131
|
+
return r;
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
function _e(t) {
|
|
1135
|
+
const e = {
|
|
1136
|
+
role: t.role,
|
|
1137
|
+
content: Ee(t.content)
|
|
1138
|
+
};
|
|
1139
|
+
return t.message_id !== null && t.message_id !== void 0 ? e.message_id = String(t.message_id) : e.message_id = "0", t.tools_calls && (e.tools_calls = t.tools_calls), t.metadata && Object.keys(t.metadata).length > 0 && (e.metadata = t.metadata), e;
|
|
1140
|
+
}
|
|
1141
|
+
var x = /* @__PURE__ */ ((t) => (t.MESSAGE = "message", t.UPDATES = "updates", t.STATE = "state", t.ERROR = "error", t))(x || {});
|
|
1142
|
+
async function* Ge(t, e) {
|
|
1143
|
+
const r = new TextDecoder();
|
|
1144
|
+
let o = "";
|
|
1145
|
+
try {
|
|
1146
|
+
for (; ; ) {
|
|
1147
|
+
const { done: s, value: n } = await t.read();
|
|
1148
|
+
if (s) {
|
|
1149
|
+
o.trim() && (yield* j(o, e, !0));
|
|
1150
|
+
break;
|
|
1151
|
+
}
|
|
1152
|
+
o += r.decode(n, { stream: !0 }), o = (yield* j(o, e, !1)).remaining;
|
|
1153
|
+
}
|
|
1154
|
+
} finally {
|
|
1155
|
+
t.releaseLock();
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
function* j(t, e, r) {
|
|
1159
|
+
for (; t.includes(`
|
|
1160
|
+
`); ) {
|
|
1161
|
+
const o = t.indexOf(`
|
|
1162
|
+
`), s = t.slice(0, o).trim();
|
|
1163
|
+
if (t = t.slice(o + 1), s)
|
|
1164
|
+
try {
|
|
1165
|
+
const n = JSON.parse(s);
|
|
1166
|
+
e && console.debug("TenxGraphClient: Stream chunk received (NDJSON):", n.event), yield n;
|
|
1167
|
+
} catch (n) {
|
|
1168
|
+
e && console.warn("TenxGraphClient: Failed to parse NDJSON line:", s.slice(0, 100), n);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
for (; t.trim(); ) {
|
|
1172
|
+
const o = Se(t);
|
|
1173
|
+
if (o)
|
|
1174
|
+
try {
|
|
1175
|
+
const s = JSON.parse(o.json);
|
|
1176
|
+
e && console.debug("TenxGraphClient: Stream chunk received (concat):", s.event), yield s, t = o.remaining;
|
|
1177
|
+
} catch (s) {
|
|
1178
|
+
e && console.warn(
|
|
1179
|
+
"TenxGraphClient: Failed to parse concatenated JSON:",
|
|
1180
|
+
o.json.slice(0, 100),
|
|
1181
|
+
s
|
|
1182
|
+
);
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
else {
|
|
1186
|
+
if (r && t.trim())
|
|
1187
|
+
try {
|
|
1188
|
+
const s = JSON.parse(t.trim());
|
|
1189
|
+
e && console.debug("TenxGraphClient: Final stream chunk:", s.event), yield s, t = "";
|
|
1190
|
+
} catch (s) {
|
|
1191
|
+
e && console.warn(
|
|
1192
|
+
"TenxGraphClient: Failed to parse final buffer:",
|
|
1193
|
+
t.slice(0, 100),
|
|
1194
|
+
s
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return { remaining: t };
|
|
1201
|
+
}
|
|
1202
|
+
function Se(t) {
|
|
1203
|
+
if (t = t.trim(), !t || t[0] !== "{")
|
|
1204
|
+
return null;
|
|
1205
|
+
let e = 0, r = !1, o = !1;
|
|
1206
|
+
for (let s = 0; s < t.length; s++) {
|
|
1207
|
+
const n = t[s];
|
|
1208
|
+
if (o) {
|
|
1209
|
+
o = !1;
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
if (n === "\\") {
|
|
1213
|
+
o = !0;
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
if (n === '"') {
|
|
1217
|
+
r = !r;
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (!r) {
|
|
1221
|
+
if (n === "{")
|
|
1222
|
+
e++;
|
|
1223
|
+
else if (n === "}" && (e--, e === 0))
|
|
1224
|
+
return {
|
|
1225
|
+
json: t.slice(0, s + 1),
|
|
1226
|
+
remaining: t.slice(s + 1).trim()
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return null;
|
|
1231
|
+
}
|
|
1232
|
+
function ve(t) {
|
|
1233
|
+
return t.some(
|
|
1234
|
+
(e) => e.content && e.content.some((r) => r.type === "remote_tool_call")
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
async function* Re(t, e) {
|
|
1238
|
+
const r = e.recursion_limit || 25;
|
|
1239
|
+
t.debug && (console.debug("TenxGraphClient: Starting stream invoke with recursion_limit:", r), console.debug("TenxGraphClient: Initial request:", JSON.stringify(e, null, 2)));
|
|
1240
|
+
let o = e.messages, s = 0;
|
|
1241
|
+
const n = e.initial_state, i = e.config, a = e.response_granularity;
|
|
1242
|
+
for (; s < r; ) {
|
|
1243
|
+
s++, t.debug && console.debug(`TenxGraphClient: Stream iteration ${s}/${r}`);
|
|
1244
|
+
const c = {
|
|
1245
|
+
messages: o,
|
|
1246
|
+
initial_state: s === 1 ? n : void 0,
|
|
1247
|
+
config: i,
|
|
1248
|
+
recursion_limit: r,
|
|
1249
|
+
response_granularity: a
|
|
1250
|
+
};
|
|
1251
|
+
t.debug && console.debug(
|
|
1252
|
+
"TenxGraphClient: Stream request payload:",
|
|
1253
|
+
JSON.stringify(c, null, 2)
|
|
1254
|
+
);
|
|
1255
|
+
const d = new AbortController(), h = setTimeout(() => d.abort(), t.timeout);
|
|
1256
|
+
try {
|
|
1257
|
+
const l = await fetch(`${t.baseUrl}/v1/graph/stream`, {
|
|
1258
|
+
method: "POST",
|
|
1259
|
+
headers: m(t, {
|
|
1260
|
+
"Content-Type": "application/json",
|
|
1261
|
+
Accept: "application/x-ndjson, application/json"
|
|
1262
|
+
}),
|
|
1263
|
+
...f(t),
|
|
1264
|
+
body: JSON.stringify(c),
|
|
1265
|
+
signal: d.signal
|
|
1266
|
+
});
|
|
1267
|
+
if (clearTimeout(h), !l.ok)
|
|
1268
|
+
throw console.warn(`TenxGraphClient: Stream failed with HTTP ${l.status}`), await p(
|
|
1269
|
+
l,
|
|
1270
|
+
"Stream request failed",
|
|
1271
|
+
"/v1/stream",
|
|
1272
|
+
"POST"
|
|
1273
|
+
);
|
|
1274
|
+
if (!l.body)
|
|
1275
|
+
throw new Error("No response body for stream");
|
|
1276
|
+
const u = [], T = l.body.getReader();
|
|
1277
|
+
for await (const w of Ge(T, t.debug))
|
|
1278
|
+
yield w, w.message && u.push(w.message);
|
|
1279
|
+
if (t.debug && (console.info("TenxGraphClient: Stream iteration completed"), console.debug("TenxGraphClient: Received", u.length, "messages")), ve(u) && t.toolExecutor) {
|
|
1280
|
+
t.debug && console.debug("TenxGraphClient: Found remote tool calls, executing...");
|
|
1281
|
+
const w = await t.toolExecutor.executeToolCalls(u);
|
|
1282
|
+
t.debug && console.debug(`TenxGraphClient: Executed ${w.length} tool calls`), o = w.map((E) => P(E));
|
|
1283
|
+
continue;
|
|
1284
|
+
} else {
|
|
1285
|
+
t.debug && console.debug("TenxGraphClient: No remote tool calls found, finishing");
|
|
1286
|
+
break;
|
|
1287
|
+
}
|
|
1288
|
+
} catch (l) {
|
|
1289
|
+
throw clearTimeout(h), l.name === "AbortError" ? (console.warn(`TenxGraphClient: Stream timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Stream failed:", l), l);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
s >= r && t.debug && console.warn(`TenxGraphClient: Recursion limit of ${r} reached`), t.debug && console.debug(`TenxGraphClient: Stream invoke completed after ${s} iterations`);
|
|
1293
|
+
}
|
|
1294
|
+
function $e(t) {
|
|
1295
|
+
return t.map((e) => {
|
|
1296
|
+
const r = {};
|
|
1297
|
+
for (const [o, s] of Object.entries(e))
|
|
1298
|
+
Array.isArray(s) && s.length === 0 || s !== void 0 && (r[o] = s);
|
|
1299
|
+
return r;
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
function P(t) {
|
|
1303
|
+
const e = {
|
|
1304
|
+
role: t.role,
|
|
1305
|
+
content: $e(t.content)
|
|
1306
|
+
};
|
|
1307
|
+
return t.message_id !== null && t.message_id !== void 0 ? e.message_id = String(t.message_id) : e.message_id = "0", t.tools_calls && (e.tools_calls = t.tools_calls), t.metadata && Object.keys(t.metadata).length > 0 && (e.metadata = t.metadata), e;
|
|
1308
|
+
}
|
|
1309
|
+
const ke = "10xgraph-bearer";
|
|
1310
|
+
function Ae(t) {
|
|
1311
|
+
return t.auth ? t.auth.type === "bearer" ? t.auth.token : null : t.authToken ? t.authToken : null;
|
|
1312
|
+
}
|
|
1313
|
+
function D(t, e) {
|
|
1314
|
+
return t.baseUrl.replace(/^https:/, "wss:").replace(/^http:/, "ws:").replace(/\/$/, "") + e;
|
|
1315
|
+
}
|
|
1316
|
+
function M(t, e) {
|
|
1317
|
+
const r = e.webSocketImpl ?? globalThis.WebSocket;
|
|
1318
|
+
if (!r)
|
|
1319
|
+
throw new Error(
|
|
1320
|
+
"No WebSocket implementation available. In Node < 21 pass `webSocketImpl` in the client config (e.g. the `ws` package: `new TenxGraphClient({ ..., webSocketImpl: WebSocket })`)."
|
|
1321
|
+
);
|
|
1322
|
+
const o = Ae(e), s = o ? [ke, o] : void 0, n = m(e), i = n.Authorization ?? n.authorization;
|
|
1323
|
+
if (i)
|
|
1324
|
+
try {
|
|
1325
|
+
return new r(t, s, { headers: { Authorization: i } });
|
|
1326
|
+
} catch {
|
|
1327
|
+
}
|
|
1328
|
+
return new r(t, s);
|
|
1329
|
+
}
|
|
1330
|
+
function Ie(t) {
|
|
1331
|
+
return t.some(
|
|
1332
|
+
(e) => e.content && e.content.some((r) => r.type === "remote_tool_call")
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
async function* Oe(t, e) {
|
|
1336
|
+
const r = D(t, "/v1/graph/ws");
|
|
1337
|
+
t.debug && console.debug("TenxGraphClient [WS]: connecting to", r);
|
|
1338
|
+
const o = M(r, t), s = [];
|
|
1339
|
+
let n = null;
|
|
1340
|
+
const i = (h) => {
|
|
1341
|
+
if (s.push(h), n) {
|
|
1342
|
+
const l = n;
|
|
1343
|
+
n = null, l();
|
|
1344
|
+
}
|
|
1345
|
+
}, a = () => new Promise((h) => {
|
|
1346
|
+
s.length > 0 ? h() : n = h;
|
|
1347
|
+
});
|
|
1348
|
+
o.addEventListener("message", (h) => {
|
|
1349
|
+
try {
|
|
1350
|
+
const l = JSON.parse(h.data);
|
|
1351
|
+
i(l);
|
|
1352
|
+
} catch (l) {
|
|
1353
|
+
t.debug && console.warn("TenxGraphClient [WS]: failed to parse chunk:", l);
|
|
1354
|
+
}
|
|
1355
|
+
}), o.addEventListener("error", () => {
|
|
1356
|
+
i(new Error("WebSocket error"));
|
|
1357
|
+
}), o.addEventListener("close", (h) => {
|
|
1358
|
+
t.debug && console.debug("TenxGraphClient [WS]: connection closed, code=", h.code), i("close");
|
|
1359
|
+
}), await new Promise((h, l) => {
|
|
1360
|
+
if (o.readyState === 1) {
|
|
1361
|
+
h();
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
o.addEventListener("open", () => h(), { once: !0 }), o.addEventListener("error", () => l(new Error("WebSocket connection failed")), {
|
|
1365
|
+
once: !0
|
|
1366
|
+
});
|
|
1367
|
+
}), t.debug && console.debug("TenxGraphClient [WS]: connected");
|
|
1368
|
+
let c = e.config?.thread_id, d = {
|
|
1369
|
+
invoke_type: "fresh",
|
|
1370
|
+
messages: e.messages,
|
|
1371
|
+
initial_state: e.initial_state,
|
|
1372
|
+
config: e.config,
|
|
1373
|
+
recursion_limit: e.recursion_limit ?? 25,
|
|
1374
|
+
response_granularity: e.response_granularity
|
|
1375
|
+
};
|
|
1376
|
+
try {
|
|
1377
|
+
e: for (; ; ) {
|
|
1378
|
+
t.debug && console.debug(
|
|
1379
|
+
`TenxGraphClient [WS]: sending ${d.invoke_type} request, thread_id=${c ?? "new"}`
|
|
1380
|
+
), o.send(JSON.stringify(d));
|
|
1381
|
+
const h = [];
|
|
1382
|
+
t: for (; ; ) {
|
|
1383
|
+
await a();
|
|
1384
|
+
const l = s.shift();
|
|
1385
|
+
if (l === "close")
|
|
1386
|
+
break e;
|
|
1387
|
+
if (l instanceof Error)
|
|
1388
|
+
throw l;
|
|
1389
|
+
const u = l;
|
|
1390
|
+
if (u.thread_id && (c = u.thread_id), u.metadata?.thread_id && (c = u.metadata.thread_id), u.event === x.UPDATES && u.data?.status === "done")
|
|
1391
|
+
break t;
|
|
1392
|
+
u.message && h.push(u.message), yield u;
|
|
1393
|
+
}
|
|
1394
|
+
if (t.debug && console.debug(
|
|
1395
|
+
`TenxGraphClient [WS]: run complete, ${h.length} messages collected`
|
|
1396
|
+
), Ie(h) && t.toolExecutor) {
|
|
1397
|
+
t.debug && console.debug("TenxGraphClient [WS]: remote tool calls detected, executing…");
|
|
1398
|
+
const l = await t.toolExecutor.executeToolCalls(h);
|
|
1399
|
+
t.debug && console.debug(
|
|
1400
|
+
`TenxGraphClient [WS]: ${l.length} tool result(s) ready, resuming`
|
|
1401
|
+
), d = {
|
|
1402
|
+
invoke_type: "resume",
|
|
1403
|
+
tool_result: l.map(P),
|
|
1404
|
+
config: { ...e.config ?? {}, thread_id: c },
|
|
1405
|
+
recursion_limit: e.recursion_limit ?? 25,
|
|
1406
|
+
response_granularity: e.response_granularity
|
|
1407
|
+
};
|
|
1408
|
+
} else
|
|
1409
|
+
break e;
|
|
1410
|
+
}
|
|
1411
|
+
} finally {
|
|
1412
|
+
(o.readyState === 1 || o.readyState === 0) && o.close(1e3), t.debug && console.debug("TenxGraphClient [WS]: stream finished");
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
const Ne = 24e3, yt = 16e3;
|
|
1416
|
+
function je() {
|
|
1417
|
+
const t = globalThis.crypto;
|
|
1418
|
+
return t?.randomUUID ? t.randomUUID() : "rt-" + Math.abs(Ue(String(Date.now()))).toString(36);
|
|
1419
|
+
}
|
|
1420
|
+
function Ue(t) {
|
|
1421
|
+
let e = 0;
|
|
1422
|
+
for (let r = 0; r < t.length; r++)
|
|
1423
|
+
e = (e << 5) - e + t.charCodeAt(r), e |= 0;
|
|
1424
|
+
return e;
|
|
1425
|
+
}
|
|
1426
|
+
function xe(t) {
|
|
1427
|
+
if (t instanceof ArrayBuffer)
|
|
1428
|
+
return new Uint8Array(t);
|
|
1429
|
+
if (ArrayBuffer.isView(t)) {
|
|
1430
|
+
const e = t;
|
|
1431
|
+
return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
1432
|
+
}
|
|
1433
|
+
return null;
|
|
1434
|
+
}
|
|
1435
|
+
class Pe {
|
|
1436
|
+
constructor(e, r, o) {
|
|
1437
|
+
this.resumptionHandle = null, this.ws = null, this.listeners = {}, this.readyResolved = !1, this.closedByUser = !1, this.fatal = !1, this.reconnectAttempts = 0, this.ctx = e, this.threadId = r.thread_id ?? je(), this.init = { ...r, thread_id: this.threadId }, this.reconnectCfg = {
|
|
1438
|
+
enabled: o?.reconnect?.enabled ?? !0,
|
|
1439
|
+
baseDelay: o?.reconnect?.baseDelay ?? 0.5,
|
|
1440
|
+
maxDelay: o?.reconnect?.maxDelay ?? 10,
|
|
1441
|
+
maxAttempts: o?.reconnect?.maxAttempts ?? 5
|
|
1442
|
+
}, o?.onAudio && this.on("audio", o.onAudio), o?.onEvent && this.on("event", o.onEvent), o?.onError && this.on("error", o.onError), this.ready = new Promise((s, n) => {
|
|
1443
|
+
this.resolveReady = s, this.rejectReady = n;
|
|
1444
|
+
}), this.connect();
|
|
1445
|
+
}
|
|
1446
|
+
// ── Public send API ─────────────────────────────────────────────────────────
|
|
1447
|
+
sendAudio(e) {
|
|
1448
|
+
this.ws?.send(e);
|
|
1449
|
+
}
|
|
1450
|
+
sendText(e) {
|
|
1451
|
+
this.sendControl({ type: "text", text: e });
|
|
1452
|
+
}
|
|
1453
|
+
activityStart() {
|
|
1454
|
+
this.sendControl({ type: "activity_start" });
|
|
1455
|
+
}
|
|
1456
|
+
activityEnd() {
|
|
1457
|
+
this.sendControl({ type: "activity_end" });
|
|
1458
|
+
}
|
|
1459
|
+
close() {
|
|
1460
|
+
this.closedByUser = !0, this.sendControl({ type: "close" });
|
|
1461
|
+
const e = this.ws;
|
|
1462
|
+
e && (e.readyState === 0 || e.readyState === 1) && e.close(1e3);
|
|
1463
|
+
}
|
|
1464
|
+
// ── Subscription API ─────────────────────────────────────────────────────────
|
|
1465
|
+
on(e, r) {
|
|
1466
|
+
return this.listeners[e] || (this.listeners[e] = []), this.listeners[e].push(r), this;
|
|
1467
|
+
}
|
|
1468
|
+
off(e, r) {
|
|
1469
|
+
return this.listeners[e] = (this.listeners[e] ?? []).filter((o) => o !== r), this;
|
|
1470
|
+
}
|
|
1471
|
+
// ── Internals ────────────────────────────────────────────────────────────────
|
|
1472
|
+
emit(e, ...r) {
|
|
1473
|
+
(this.listeners[e] ?? []).forEach((o) => {
|
|
1474
|
+
try {
|
|
1475
|
+
o(...r);
|
|
1476
|
+
} catch (s) {
|
|
1477
|
+
this.ctx.debug && console.warn("TenxGraphClient [realtime]: listener threw", s);
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
sendControl(e) {
|
|
1482
|
+
this.ws?.send(JSON.stringify(e));
|
|
1483
|
+
}
|
|
1484
|
+
connect() {
|
|
1485
|
+
const e = D(this.ctx, "/v1/graph/live");
|
|
1486
|
+
this.ctx.debug && console.debug("TenxGraphClient [realtime]: connecting to", e);
|
|
1487
|
+
const r = M(e, this.ctx);
|
|
1488
|
+
try {
|
|
1489
|
+
r.binaryType = "arraybuffer";
|
|
1490
|
+
} catch {
|
|
1491
|
+
}
|
|
1492
|
+
this.ws = r, r.addEventListener("open", () => {
|
|
1493
|
+
this.ws === r && (this.sendControl(this.init), this.readyResolved || (this.readyResolved = !0, this.resolveReady()), this.emit("open"));
|
|
1494
|
+
}), r.addEventListener("message", (o) => {
|
|
1495
|
+
this.ws === r && this.handleMessage(o.data);
|
|
1496
|
+
}), r.addEventListener("close", (o) => {
|
|
1497
|
+
if (this.ws !== r) return;
|
|
1498
|
+
const s = o?.code ?? 1e3;
|
|
1499
|
+
this.emit("close", s), this.maybeReconnect();
|
|
1500
|
+
}), r.addEventListener("error", () => {
|
|
1501
|
+
this.ws === r && (this.readyResolved || (this.readyResolved = !0, this.rejectReady(new Error("Realtime WebSocket connection failed"))));
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
handleMessage(e) {
|
|
1505
|
+
const r = xe(e);
|
|
1506
|
+
if (r) {
|
|
1507
|
+
this.emit("audio", r, Ne);
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (typeof e != "string") return;
|
|
1511
|
+
let o;
|
|
1512
|
+
try {
|
|
1513
|
+
o = JSON.parse(e);
|
|
1514
|
+
} catch {
|
|
1515
|
+
this.ctx.debug && console.warn("TenxGraphClient [realtime]: bad JSON frame", e);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
o.type === "session_update" && (this.resumptionHandle = o.resumption_handle ?? this.resumptionHandle), o.type === "error" && o.fatal && (this.fatal = !0), this.emit("event", o), this.emit(o.type, o);
|
|
1519
|
+
}
|
|
1520
|
+
maybeReconnect() {
|
|
1521
|
+
if (this.closedByUser || this.fatal || !this.reconnectCfg.enabled)
|
|
1522
|
+
return;
|
|
1523
|
+
if (this.reconnectAttempts >= this.reconnectCfg.maxAttempts) {
|
|
1524
|
+
this.fatal = !0;
|
|
1525
|
+
const o = {
|
|
1526
|
+
type: "error",
|
|
1527
|
+
code: "reconnect_failed",
|
|
1528
|
+
message: `Realtime reconnect gave up after ${this.reconnectCfg.maxAttempts} attempt(s)`,
|
|
1529
|
+
fatal: !0
|
|
1530
|
+
};
|
|
1531
|
+
this.emit("error", o), this.emit("event", o);
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
this.reconnectAttempts += 1;
|
|
1535
|
+
const e = this.reconnectAttempts, r = Math.min(this.reconnectCfg.baseDelay * 2 ** (e - 1), this.reconnectCfg.maxDelay) * 1e3;
|
|
1536
|
+
this.emit("reconnecting", e), setTimeout(() => this.reconnect(), r);
|
|
1537
|
+
}
|
|
1538
|
+
reconnect() {
|
|
1539
|
+
this.init = {
|
|
1540
|
+
...this.init,
|
|
1541
|
+
thread_id: this.threadId,
|
|
1542
|
+
...this.resumptionHandle ? { resumption_handle: this.resumptionHandle } : {}
|
|
1543
|
+
};
|
|
1544
|
+
const e = () => {
|
|
1545
|
+
this.reconnectAttempts = 0, this.emit("reconnected");
|
|
1546
|
+
};
|
|
1547
|
+
this.connect(), this.ws?.addEventListener("open", e, { once: !0 });
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
var L = /* @__PURE__ */ ((t) => (t.EPISODIC = "episodic", t.SEMANTIC = "semantic", t.PROCEDURAL = "procedural", t.ENTITY = "entity", t.RELATIONSHIP = "relationship", t.CUSTOM = "custom", t.DECLARATIVE = "declarative", t))(L || {});
|
|
1551
|
+
async function De(t, e) {
|
|
1552
|
+
try {
|
|
1553
|
+
t.debug && console.debug("TenxGraphClient: Storing memory with type", e.memory_type);
|
|
1554
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/store/memories`, n = {
|
|
1555
|
+
config: e.config || {},
|
|
1556
|
+
options: e.options || {},
|
|
1557
|
+
content: e.content,
|
|
1558
|
+
memory_type: e.memory_type,
|
|
1559
|
+
category: e.category,
|
|
1560
|
+
metadata: e.metadata || {}
|
|
1561
|
+
}, i = await fetch(s, {
|
|
1562
|
+
method: "POST",
|
|
1563
|
+
headers: m(t, {
|
|
1564
|
+
"Content-Type": "application/json"
|
|
1565
|
+
}),
|
|
1566
|
+
...f(t),
|
|
1567
|
+
body: JSON.stringify(n),
|
|
1568
|
+
signal: r.signal
|
|
1569
|
+
});
|
|
1570
|
+
if (clearTimeout(o), !i.ok)
|
|
1571
|
+
throw console.warn(`TenxGraphClient: Store memory failed with HTTP ${i.status}`), await p(
|
|
1572
|
+
i,
|
|
1573
|
+
"Store memory request failed",
|
|
1574
|
+
"/v1/memory",
|
|
1575
|
+
"POST"
|
|
1576
|
+
);
|
|
1577
|
+
const a = await i.json();
|
|
1578
|
+
return t.debug && console.info("TenxGraphClient: Memory stored successfully", a), a;
|
|
1579
|
+
} catch (r) {
|
|
1580
|
+
throw t.debug && console.debug("TenxGraphClient: Store memory failed:", r), r;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
var Me = /* @__PURE__ */ ((t) => (t.SIMILARITY = "similarity", t.TEMPORAL = "temporal", t.RELEVANCE = "relevance", t.HYBRID = "hybrid", t.GRAPH_TRAVERSAL = "graph_traversal", t))(Me || {}), Le = /* @__PURE__ */ ((t) => (t.COSINE = "cosine", t.EUCLIDEAN = "euclidean", t.DOT_PRODUCT = "dot_product", t.MANHATTAN = "manhattan", t))(Le || {});
|
|
1584
|
+
async function Fe(t, e) {
|
|
1585
|
+
try {
|
|
1586
|
+
t.debug && console.debug("TenxGraphClient: Searching memories with query:", e.query);
|
|
1587
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/store/search`, n = {
|
|
1588
|
+
config: e.config || {},
|
|
1589
|
+
options: e.options || {},
|
|
1590
|
+
query: e.query,
|
|
1591
|
+
memory_type: e.memory_type || L.EPISODIC,
|
|
1592
|
+
category: e.category || "",
|
|
1593
|
+
limit: e.limit !== void 0 ? e.limit : 10,
|
|
1594
|
+
score_threshold: e.score_threshold !== void 0 ? e.score_threshold : 0,
|
|
1595
|
+
filters: e.filters || {},
|
|
1596
|
+
retrieval_strategy: e.retrieval_strategy || "similarity",
|
|
1597
|
+
distance_metric: e.distance_metric || "cosine",
|
|
1598
|
+
max_tokens: e.max_tokens !== void 0 ? e.max_tokens : 4e3
|
|
1599
|
+
}, i = await fetch(s, {
|
|
1600
|
+
method: "POST",
|
|
1601
|
+
headers: m(t, {
|
|
1602
|
+
"Content-Type": "application/json"
|
|
1603
|
+
}),
|
|
1604
|
+
...f(t),
|
|
1605
|
+
body: JSON.stringify(n),
|
|
1606
|
+
signal: r.signal
|
|
1607
|
+
});
|
|
1608
|
+
if (clearTimeout(o), !i.ok)
|
|
1609
|
+
throw console.warn(`TenxGraphClient: Search memory failed with HTTP ${i.status}`), await p(
|
|
1610
|
+
i,
|
|
1611
|
+
"Search memory request failed",
|
|
1612
|
+
"/v1/memory/search",
|
|
1613
|
+
"POST"
|
|
1614
|
+
);
|
|
1615
|
+
const a = await i.json();
|
|
1616
|
+
return t.debug && console.info("TenxGraphClient: Memory search successful", {
|
|
1617
|
+
query: e.query,
|
|
1618
|
+
results_count: a.data.results.length
|
|
1619
|
+
}), a;
|
|
1620
|
+
} catch (r) {
|
|
1621
|
+
throw t.debug && console.debug("TenxGraphClient: Search memory failed:", r), r;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
async function He(t, e) {
|
|
1625
|
+
try {
|
|
1626
|
+
t.debug && console.debug("TenxGraphClient: Fetching memory with ID:", e.memoryId);
|
|
1627
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/store/memories/${e.memoryId}`, n = {
|
|
1628
|
+
config: e.config || {},
|
|
1629
|
+
options: e.options || {}
|
|
1630
|
+
}, i = await fetch(s, {
|
|
1631
|
+
method: "POST",
|
|
1632
|
+
headers: m(t, {
|
|
1633
|
+
"Content-Type": "application/json"
|
|
1634
|
+
}),
|
|
1635
|
+
...f(t),
|
|
1636
|
+
body: JSON.stringify(n),
|
|
1637
|
+
signal: r.signal
|
|
1638
|
+
});
|
|
1639
|
+
if (clearTimeout(o), !i.ok)
|
|
1640
|
+
throw console.warn(`TenxGraphClient: Get memory failed with HTTP ${i.status}`), await p(
|
|
1641
|
+
i,
|
|
1642
|
+
"Get memory request failed",
|
|
1643
|
+
"/v1/memory/{memory_id}",
|
|
1644
|
+
"GET"
|
|
1645
|
+
);
|
|
1646
|
+
const a = await i.json();
|
|
1647
|
+
return t.debug && console.info("TenxGraphClient: Memory fetched successfully", {
|
|
1648
|
+
memory_id: e.memoryId,
|
|
1649
|
+
content: a.data.memory.content.substring(0, 50)
|
|
1650
|
+
}), a;
|
|
1651
|
+
} catch (r) {
|
|
1652
|
+
throw t.debug && console.debug("TenxGraphClient: Get memory failed:", r), r;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
async function Be(t, e) {
|
|
1656
|
+
try {
|
|
1657
|
+
t.debug && console.debug("TenxGraphClient: Updating memory with ID:", e.memoryId);
|
|
1658
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/store/memories/${e.memoryId}`, n = {
|
|
1659
|
+
config: e.config || {},
|
|
1660
|
+
options: e.options || {},
|
|
1661
|
+
content: e.content,
|
|
1662
|
+
metadata: e.metadata || {}
|
|
1663
|
+
};
|
|
1664
|
+
t.debug && console.debug("TenxGraphClient: Request payload:", JSON.stringify(n, null, 2));
|
|
1665
|
+
const i = await fetch(s, {
|
|
1666
|
+
method: "PUT",
|
|
1667
|
+
headers: m(t, {
|
|
1668
|
+
"Content-Type": "application/json"
|
|
1669
|
+
}),
|
|
1670
|
+
...f(t),
|
|
1671
|
+
body: JSON.stringify(n),
|
|
1672
|
+
signal: r.signal
|
|
1673
|
+
});
|
|
1674
|
+
if (clearTimeout(o), !i.ok)
|
|
1675
|
+
throw console.warn(`TenxGraphClient: Update memory failed with HTTP ${i.status}`), await p(
|
|
1676
|
+
i,
|
|
1677
|
+
"Update memory request failed",
|
|
1678
|
+
"/v1/memory/{memory_id}",
|
|
1679
|
+
"PUT"
|
|
1680
|
+
);
|
|
1681
|
+
const a = await i.json();
|
|
1682
|
+
return t.debug && console.info("TenxGraphClient: Memory updated successfully", {
|
|
1683
|
+
memory_id: e.memoryId,
|
|
1684
|
+
success: a.data.success
|
|
1685
|
+
}), a;
|
|
1686
|
+
} catch (r) {
|
|
1687
|
+
throw t.debug && console.debug("TenxGraphClient: Update memory failed:", r), r;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
async function Je(t, e) {
|
|
1691
|
+
try {
|
|
1692
|
+
t.debug && console.debug("TenxGraphClient: Deleting memory with ID:", e.memoryId);
|
|
1693
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/store/memories/${e.memoryId}`, n = {
|
|
1694
|
+
config: e.config || {},
|
|
1695
|
+
options: e.options || {}
|
|
1696
|
+
};
|
|
1697
|
+
t.debug && console.debug("TenxGraphClient: Delete request payload:", JSON.stringify(n, null, 2));
|
|
1698
|
+
const i = await fetch(s, {
|
|
1699
|
+
method: "DELETE",
|
|
1700
|
+
headers: m(t, {
|
|
1701
|
+
"Content-Type": "application/json",
|
|
1702
|
+
accept: "application/json"
|
|
1703
|
+
}),
|
|
1704
|
+
...f(t),
|
|
1705
|
+
body: JSON.stringify(n),
|
|
1706
|
+
signal: r.signal
|
|
1707
|
+
});
|
|
1708
|
+
if (clearTimeout(o), !i.ok)
|
|
1709
|
+
throw console.warn(`TenxGraphClient: Delete memory failed with HTTP ${i.status}`), await p(
|
|
1710
|
+
i,
|
|
1711
|
+
"Delete memory request failed",
|
|
1712
|
+
"/v1/memory/{memory_id}",
|
|
1713
|
+
"DELETE"
|
|
1714
|
+
);
|
|
1715
|
+
const a = await i.json();
|
|
1716
|
+
return t.debug && console.info("TenxGraphClient: Memory deleted successfully", {
|
|
1717
|
+
memory_id: e.memoryId,
|
|
1718
|
+
success: a.data.success
|
|
1719
|
+
}), a;
|
|
1720
|
+
} catch (r) {
|
|
1721
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: Delete memory timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: Delete memory failed:", r), r);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
async function We(t, e) {
|
|
1725
|
+
try {
|
|
1726
|
+
t.debug && console.debug("TenxGraphClient: Fetching list of memories", {
|
|
1727
|
+
limit: e.limit
|
|
1728
|
+
});
|
|
1729
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = `${t.baseUrl}/v1/store/memories/list`, n = {
|
|
1730
|
+
config: e.config || {},
|
|
1731
|
+
options: e.options || {},
|
|
1732
|
+
limit: e.limit || 100
|
|
1733
|
+
};
|
|
1734
|
+
t.debug && console.debug(
|
|
1735
|
+
"TenxGraphClient: List memories request payload:",
|
|
1736
|
+
JSON.stringify(n, null, 2)
|
|
1737
|
+
);
|
|
1738
|
+
const i = await fetch(s, {
|
|
1739
|
+
method: "POST",
|
|
1740
|
+
headers: m(t, {
|
|
1741
|
+
"Content-Type": "application/json",
|
|
1742
|
+
accept: "application/json"
|
|
1743
|
+
}),
|
|
1744
|
+
...f(t),
|
|
1745
|
+
body: JSON.stringify(n),
|
|
1746
|
+
signal: r.signal
|
|
1747
|
+
});
|
|
1748
|
+
if (clearTimeout(o), !i.ok)
|
|
1749
|
+
throw console.warn(`TenxGraphClient: List memories failed with HTTP ${i.status}`), await p(
|
|
1750
|
+
i,
|
|
1751
|
+
"List memories request failed",
|
|
1752
|
+
"/v1/memory",
|
|
1753
|
+
"GET"
|
|
1754
|
+
);
|
|
1755
|
+
const a = await i.json();
|
|
1756
|
+
return t.debug && console.info("TenxGraphClient: Memories list fetched successfully", {
|
|
1757
|
+
count: a.data.memories.length,
|
|
1758
|
+
limit: e.limit
|
|
1759
|
+
}), a;
|
|
1760
|
+
} catch (r) {
|
|
1761
|
+
throw r.name === "AbortError" ? (console.warn(`TenxGraphClient: List memories timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (t.debug && console.debug("TenxGraphClient: List memories failed:", r), r);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
async function ze(t, e) {
|
|
1765
|
+
try {
|
|
1766
|
+
const r = `${t.baseUrl}/v1/store/memories/forget`, o = {};
|
|
1767
|
+
e.config && (o.config = e.config), e.options && (o.options = e.options), e.memory_type && (o.memory_type = e.memory_type), e.category && (o.category = e.category), e.filters && (o.filters = e.filters), t.debug && console.log("[DEBUG] Forget memories request:", o);
|
|
1768
|
+
const s = new AbortController();
|
|
1769
|
+
let n;
|
|
1770
|
+
t.timeout > 0 && (n = setTimeout(() => s.abort(), t.timeout));
|
|
1771
|
+
const i = await fetch(r, {
|
|
1772
|
+
method: "POST",
|
|
1773
|
+
headers: m(t, {
|
|
1774
|
+
"Content-Type": "application/json"
|
|
1775
|
+
}),
|
|
1776
|
+
...f(t),
|
|
1777
|
+
body: JSON.stringify(o),
|
|
1778
|
+
...t.timeout > 0 && { signal: s.signal }
|
|
1779
|
+
});
|
|
1780
|
+
if (n && clearTimeout(n), !i.ok)
|
|
1781
|
+
throw new Error(`Forget memories failed: ${i.status} ${i.statusText}`);
|
|
1782
|
+
const a = await i.json();
|
|
1783
|
+
return t.debug && console.log("[DEBUG] Forget memories response:", a), a;
|
|
1784
|
+
} catch (r) {
|
|
1785
|
+
throw r.name === "AbortError", r;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
async function Ve(t, e) {
|
|
1789
|
+
try {
|
|
1790
|
+
t.debug && console.debug("TenxGraphClient: Stopping graph execution for thread:", e.thread_id);
|
|
1791
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = await fetch(`${t.baseUrl}/v1/graph/stop`, {
|
|
1792
|
+
method: "POST",
|
|
1793
|
+
headers: m(t, {
|
|
1794
|
+
"Content-Type": "application/json",
|
|
1795
|
+
accept: "application/json"
|
|
1796
|
+
}),
|
|
1797
|
+
...f(t),
|
|
1798
|
+
body: JSON.stringify(e),
|
|
1799
|
+
signal: r.signal
|
|
1800
|
+
});
|
|
1801
|
+
if (clearTimeout(o), !s.ok)
|
|
1802
|
+
throw console.warn(`TenxGraphClient: Stop graph failed with HTTP ${s.status}`), await p(
|
|
1803
|
+
s,
|
|
1804
|
+
"Stop graph execution failed",
|
|
1805
|
+
"/v1/graph/stop",
|
|
1806
|
+
"POST"
|
|
1807
|
+
);
|
|
1808
|
+
const n = await s.json();
|
|
1809
|
+
return t.debug && console.info("TenxGraphClient: Graph execution stopped successfully", n), n;
|
|
1810
|
+
} catch (r) {
|
|
1811
|
+
throw t.debug && console.debug("TenxGraphClient: Stop graph failed:", r), r.name === "AbortError" ? (console.warn(`TenxGraphClient: Stop graph timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Stop graph failed:", r), r);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
async function Ye(t, e) {
|
|
1815
|
+
try {
|
|
1816
|
+
t.debug && console.debug("TenxGraphClient: Fixing graph state for thread:", e.thread_id);
|
|
1817
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout), s = await fetch(`${t.baseUrl}/v1/graph/fix`, {
|
|
1818
|
+
method: "POST",
|
|
1819
|
+
headers: m(t, {
|
|
1820
|
+
"Content-Type": "application/json",
|
|
1821
|
+
accept: "application/json"
|
|
1822
|
+
}),
|
|
1823
|
+
...f(t),
|
|
1824
|
+
body: JSON.stringify(e),
|
|
1825
|
+
signal: r.signal
|
|
1826
|
+
});
|
|
1827
|
+
if (clearTimeout(o), !s.ok)
|
|
1828
|
+
throw console.warn(`TenxGraphClient: Fix graph failed with HTTP ${s.status}`), await p(
|
|
1829
|
+
s,
|
|
1830
|
+
"Fix graph state failed",
|
|
1831
|
+
"/v1/graph/fix",
|
|
1832
|
+
"POST"
|
|
1833
|
+
);
|
|
1834
|
+
const n = await s.json();
|
|
1835
|
+
return t.debug && console.info("TenxGraphClient: Graph state fixed successfully", {
|
|
1836
|
+
removed_count: n.data.removed_count,
|
|
1837
|
+
success: n.data.success
|
|
1838
|
+
}), n;
|
|
1839
|
+
} catch (r) {
|
|
1840
|
+
throw t.debug && console.debug("TenxGraphClient: Fix graph failed:", r), r.name === "AbortError" ? (console.warn(`TenxGraphClient: Fix graph timeout after ${t.timeout}ms`), new Error(`Request timeout after ${t.timeout}ms`)) : (console.error("TenxGraphClient: Fix graph failed:", r), r);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
async function Ke(t, e) {
|
|
1844
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout);
|
|
1845
|
+
try {
|
|
1846
|
+
const s = new FormData();
|
|
1847
|
+
typeof File < "u" && e instanceof File ? s.append("file", e, e.name) : "data" in e && "filename" in e ? s.append("file", e.data, e.filename) : s.append("file", e, "upload");
|
|
1848
|
+
const n = await fetch(`${t.baseUrl}/v1/files/upload`, {
|
|
1849
|
+
method: "POST",
|
|
1850
|
+
headers: m(t),
|
|
1851
|
+
body: s,
|
|
1852
|
+
...f(t),
|
|
1853
|
+
signal: r.signal
|
|
1854
|
+
});
|
|
1855
|
+
if (clearTimeout(o), !n.ok)
|
|
1856
|
+
throw await p(
|
|
1857
|
+
n,
|
|
1858
|
+
"File upload failed",
|
|
1859
|
+
"/v1/files/upload",
|
|
1860
|
+
"POST"
|
|
1861
|
+
);
|
|
1862
|
+
return await n.json();
|
|
1863
|
+
} finally {
|
|
1864
|
+
clearTimeout(o);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
async function Ze(t, e) {
|
|
1868
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout);
|
|
1869
|
+
try {
|
|
1870
|
+
const s = await fetch(`${t.baseUrl}/v1/files/${encodeURIComponent(e)}`, {
|
|
1871
|
+
method: "GET",
|
|
1872
|
+
headers: m(t),
|
|
1873
|
+
...f(t),
|
|
1874
|
+
signal: r.signal
|
|
1875
|
+
});
|
|
1876
|
+
if (clearTimeout(o), !s.ok)
|
|
1877
|
+
throw await p(
|
|
1878
|
+
s,
|
|
1879
|
+
"File download failed",
|
|
1880
|
+
`/v1/files/${e}`,
|
|
1881
|
+
"GET"
|
|
1882
|
+
);
|
|
1883
|
+
return await s.blob();
|
|
1884
|
+
} finally {
|
|
1885
|
+
clearTimeout(o);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
async function Qe(t, e) {
|
|
1889
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout);
|
|
1890
|
+
try {
|
|
1891
|
+
const s = await fetch(`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/info`, {
|
|
1892
|
+
method: "GET",
|
|
1893
|
+
headers: m(t),
|
|
1894
|
+
...f(t),
|
|
1895
|
+
signal: r.signal
|
|
1896
|
+
});
|
|
1897
|
+
if (clearTimeout(o), !s.ok)
|
|
1898
|
+
throw await p(
|
|
1899
|
+
s,
|
|
1900
|
+
"File info request failed",
|
|
1901
|
+
`/v1/files/${e}/info`,
|
|
1902
|
+
"GET"
|
|
1903
|
+
);
|
|
1904
|
+
return await s.json();
|
|
1905
|
+
} finally {
|
|
1906
|
+
clearTimeout(o);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
async function Xe(t, e) {
|
|
1910
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout);
|
|
1911
|
+
try {
|
|
1912
|
+
const s = await fetch(`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/url`, {
|
|
1913
|
+
method: "GET",
|
|
1914
|
+
headers: m(t),
|
|
1915
|
+
...f(t),
|
|
1916
|
+
signal: r.signal
|
|
1917
|
+
});
|
|
1918
|
+
if (clearTimeout(o), !s.ok)
|
|
1919
|
+
throw await p(
|
|
1920
|
+
s,
|
|
1921
|
+
"File access URL request failed",
|
|
1922
|
+
`/v1/files/${e}/url`,
|
|
1923
|
+
"GET"
|
|
1924
|
+
);
|
|
1925
|
+
return await s.json();
|
|
1926
|
+
} finally {
|
|
1927
|
+
clearTimeout(o);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
async function qe(t) {
|
|
1931
|
+
const e = new AbortController(), r = setTimeout(() => e.abort(), t.timeout);
|
|
1932
|
+
try {
|
|
1933
|
+
const o = await fetch(`${t.baseUrl}/v1/config/multimodal`, {
|
|
1934
|
+
method: "GET",
|
|
1935
|
+
headers: m(t, {
|
|
1936
|
+
accept: "application/json"
|
|
1937
|
+
}),
|
|
1938
|
+
...f(t),
|
|
1939
|
+
signal: e.signal
|
|
1940
|
+
});
|
|
1941
|
+
if (clearTimeout(r), !o.ok)
|
|
1942
|
+
throw await p(
|
|
1943
|
+
o,
|
|
1944
|
+
"Multimodal config request failed",
|
|
1945
|
+
"/v1/config/multimodal",
|
|
1946
|
+
"GET"
|
|
1947
|
+
);
|
|
1948
|
+
return await o.json();
|
|
1949
|
+
} finally {
|
|
1950
|
+
clearTimeout(r);
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
function et(t) {
|
|
1954
|
+
return typeof t == "object" && t !== null;
|
|
1955
|
+
}
|
|
1956
|
+
function tt(t, e, r) {
|
|
1957
|
+
return et(t) ? {
|
|
1958
|
+
search: t.search,
|
|
1959
|
+
offset: t.offset,
|
|
1960
|
+
limit: t.limit
|
|
1961
|
+
} : {
|
|
1962
|
+
search: t,
|
|
1963
|
+
offset: e,
|
|
1964
|
+
limit: r
|
|
1965
|
+
};
|
|
1966
|
+
}
|
|
1967
|
+
function rt(t) {
|
|
1968
|
+
return typeof t == "object" && t !== null;
|
|
1969
|
+
}
|
|
1970
|
+
function ot(t, e, r, o) {
|
|
1971
|
+
return rt(e) ? {
|
|
1972
|
+
threadId: t,
|
|
1973
|
+
search: e.search,
|
|
1974
|
+
offset: e.offset,
|
|
1975
|
+
limit: e.limit
|
|
1976
|
+
} : {
|
|
1977
|
+
threadId: t,
|
|
1978
|
+
search: e,
|
|
1979
|
+
offset: r,
|
|
1980
|
+
limit: o
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
class st {
|
|
1984
|
+
constructor(e) {
|
|
1985
|
+
this.baseUrl = e.baseUrl, this.authToken = e.authToken, this.auth = e.auth, this.headers = e.headers, this.credentials = e.credentials, this.timeout = e.timeout || 3e5, this.debug = e.debug || !1, this.webSocketImpl = e.webSocketImpl, this.toolExecutor = new z([]);
|
|
1986
|
+
}
|
|
1987
|
+
createContext() {
|
|
1988
|
+
return {
|
|
1989
|
+
baseUrl: this.baseUrl,
|
|
1990
|
+
authToken: this.authToken,
|
|
1991
|
+
auth: this.auth,
|
|
1992
|
+
headers: this.headers,
|
|
1993
|
+
credentials: this.credentials,
|
|
1994
|
+
timeout: this.timeout,
|
|
1995
|
+
debug: this.debug,
|
|
1996
|
+
webSocketImpl: this.webSocketImpl
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Register a tool for remote execution
|
|
2001
|
+
*/
|
|
2002
|
+
registerTool(e) {
|
|
2003
|
+
this.toolExecutor.registerTool(e), this.debug && console.debug(`TenxGraphClient: Registered remote tool handler '${e.name}'`);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Register only the client-side implementation of a remote tool.
|
|
2007
|
+
* The trusted schema must be declared in the server's 10xgraph.json.
|
|
2008
|
+
*/
|
|
2009
|
+
registerToolHandler(e, r) {
|
|
2010
|
+
this.registerTool({ name: e, handler: r });
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Ping the server to check connectivity
|
|
2014
|
+
*/
|
|
2015
|
+
async ping() {
|
|
2016
|
+
const e = this.createContext();
|
|
2017
|
+
return ne(e);
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* Fetch the agent graph
|
|
2021
|
+
*/
|
|
2022
|
+
async graph() {
|
|
2023
|
+
const e = this.createContext();
|
|
2024
|
+
return ie(e);
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Fetch the tools exposed by the graph's tool nodes, grouped by node.
|
|
2028
|
+
* Each tool is tagged with its source (local / mcp / remote).
|
|
2029
|
+
*/
|
|
2030
|
+
async graphTools() {
|
|
2031
|
+
const e = this.createContext();
|
|
2032
|
+
return ae(e);
|
|
2033
|
+
}
|
|
2034
|
+
/**
|
|
2035
|
+
* Fetch the reconstructed observability trace (spans, events, cost) for a
|
|
2036
|
+
* thread. Returns the latest run by default, or a specific run when given.
|
|
2037
|
+
*/
|
|
2038
|
+
async observability(e, r) {
|
|
2039
|
+
const o = this.createContext();
|
|
2040
|
+
return le(o, e, r);
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* Stop a running graph execution for a specific thread
|
|
2044
|
+
* @param threadId - The ID of the thread to stop execution for
|
|
2045
|
+
* @param config - Optional configuration for the stop operation
|
|
2046
|
+
* @returns StopGraphResponse with the stop operation result
|
|
2047
|
+
*/
|
|
2048
|
+
async stopGraph(e, r) {
|
|
2049
|
+
const o = this.createContext();
|
|
2050
|
+
return Ve(o, {
|
|
2051
|
+
thread_id: e,
|
|
2052
|
+
config: r
|
|
2053
|
+
});
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Fix graph state by removing messages with empty tool calls
|
|
2057
|
+
* This is useful for cleaning up incomplete tool call messages that may have
|
|
2058
|
+
* failed or been interrupted during execution.
|
|
2059
|
+
*
|
|
2060
|
+
* @param threadId - The ID of the thread to fix state for
|
|
2061
|
+
* @param config - Optional configuration for the fix operation
|
|
2062
|
+
* @returns FixGraphResponse with the fix operation result including removed_count
|
|
2063
|
+
*/
|
|
2064
|
+
async fixGraph(e, r) {
|
|
2065
|
+
const o = this.createContext();
|
|
2066
|
+
return Ye(o, {
|
|
2067
|
+
thread_id: e,
|
|
2068
|
+
config: r
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
*
|
|
2073
|
+
|
|
2074
|
+
/**
|
|
2075
|
+
* Fetch the state schema of the agent
|
|
2076
|
+
*/
|
|
2077
|
+
async graphStateSchema() {
|
|
2078
|
+
const e = this.createContext();
|
|
2079
|
+
return ce(e);
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* ***************** ALL THREAD APIS *****************
|
|
2083
|
+
*/
|
|
2084
|
+
/**
|
|
2085
|
+
* Fetch the state of a specific thread
|
|
2086
|
+
* @param threadId - The ID of the thread to fetch state for
|
|
2087
|
+
* @returns ThreadStateResponse containing the thread's current state
|
|
2088
|
+
*/
|
|
2089
|
+
async threadState(e) {
|
|
2090
|
+
const r = this.createContext();
|
|
2091
|
+
return he(r, e);
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Update the state of a specific thread (checkpoint)
|
|
2095
|
+
* @param threadId - The ID of the thread to update
|
|
2096
|
+
* @param config - Configuration map for the thread
|
|
2097
|
+
* @param state - New AgentState for the thread
|
|
2098
|
+
* @returns UpdateThreadStateResponse with the updated state
|
|
2099
|
+
*/
|
|
2100
|
+
async updateThreadState(e, r, o) {
|
|
2101
|
+
const s = this.createContext();
|
|
2102
|
+
return de(s, e, {
|
|
2103
|
+
config: r,
|
|
2104
|
+
state: o
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Clear the state of a specific thread (delete checkpoint)
|
|
2109
|
+
* @param threadId - The ID of the thread to clear state for
|
|
2110
|
+
* @returns ClearThreadStateResponse with the clear operation result
|
|
2111
|
+
*/
|
|
2112
|
+
async clearThreadState(e) {
|
|
2113
|
+
const r = this.createContext();
|
|
2114
|
+
return ue(r, e);
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Fetch details for a specific thread
|
|
2118
|
+
* @param threadId - The ID of the thread to fetch
|
|
2119
|
+
* @returns ThreadDetailsResponse containing thread details
|
|
2120
|
+
*/
|
|
2121
|
+
async threadDetails(e) {
|
|
2122
|
+
const r = this.createContext();
|
|
2123
|
+
return pe(r, e);
|
|
2124
|
+
}
|
|
2125
|
+
async threads(e, r, o) {
|
|
2126
|
+
const s = this.createContext(), n = tt(e, r, o);
|
|
2127
|
+
return ye(s, n);
|
|
2128
|
+
}
|
|
2129
|
+
async threadMessages(e, r, o, s) {
|
|
2130
|
+
const n = this.createContext(), i = ot(e, r, o, s);
|
|
2131
|
+
return U(n, i);
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Add messages to a specific thread checkpoint
|
|
2135
|
+
* @param threadId - The ID of the thread to add messages to
|
|
2136
|
+
* @param messages - Array of messages to add to the checkpoint
|
|
2137
|
+
* @param config - Configuration map for the checkpoint
|
|
2138
|
+
* @param metadata - Optional metadata for the checkpoint
|
|
2139
|
+
* @returns AddCheckpointMessagesResponse containing the operation result
|
|
2140
|
+
*/
|
|
2141
|
+
async addThreadMessages(e, r, o = {}, s) {
|
|
2142
|
+
const n = this.createContext();
|
|
2143
|
+
return me(n, {
|
|
2144
|
+
threadId: e,
|
|
2145
|
+
config: o,
|
|
2146
|
+
messages: r,
|
|
2147
|
+
metadata: s
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
/**
|
|
2151
|
+
* Fetch a specific message from a thread by message ID
|
|
2152
|
+
* @param threadId - The ID of the thread
|
|
2153
|
+
* @param messageId - The ID of the message to fetch
|
|
2154
|
+
* @returns ThreadMessageResponse containing the message and metadata
|
|
2155
|
+
*/
|
|
2156
|
+
async singleMessage(e, r) {
|
|
2157
|
+
const o = this.createContext();
|
|
2158
|
+
return fe(o, {
|
|
2159
|
+
threadId: e,
|
|
2160
|
+
messageId: r
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* Delete a specific message from a thread
|
|
2165
|
+
* @param threadId - The ID of the thread
|
|
2166
|
+
* @param messageId - The ID of the message to delete
|
|
2167
|
+
* @param config - Optional configuration map to send with the request body
|
|
2168
|
+
* @returns DeleteThreadMessageResponse containing the deletion result
|
|
2169
|
+
*/
|
|
2170
|
+
async deleteMessage(e, r, o) {
|
|
2171
|
+
const s = this.createContext();
|
|
2172
|
+
return ge(s, {
|
|
2173
|
+
threadId: e,
|
|
2174
|
+
messageId: r,
|
|
2175
|
+
config: o
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Delete a specific thread
|
|
2180
|
+
* @param threadId - The ID of the thread to delete
|
|
2181
|
+
* @param config - Optional configuration map to send with the request body
|
|
2182
|
+
* @returns DeleteThreadResponse containing the deletion result
|
|
2183
|
+
*/
|
|
2184
|
+
async deleteThread(e, r) {
|
|
2185
|
+
const o = this.createContext();
|
|
2186
|
+
return Te(o, {
|
|
2187
|
+
threadId: e,
|
|
2188
|
+
config: r
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* Invoke the agent graph with automatic tool execution loop
|
|
2193
|
+
* @param messages - Array of messages to send
|
|
2194
|
+
* @param options - Invoke options
|
|
2195
|
+
* @returns InvokeResult with all messages and intermediate steps
|
|
2196
|
+
*/
|
|
2197
|
+
async invoke(e, r) {
|
|
2198
|
+
const o = {
|
|
2199
|
+
...this.createContext(),
|
|
2200
|
+
toolExecutor: this.toolExecutor
|
|
2201
|
+
}, s = {
|
|
2202
|
+
messages: e.map((n) => this.serializeMessage(n)),
|
|
2203
|
+
initial_state: r?.initial_state,
|
|
2204
|
+
config: r?.config,
|
|
2205
|
+
recursion_limit: r?.recursion_limit || 25,
|
|
2206
|
+
response_granularity: r?.response_granularity || "full"
|
|
2207
|
+
};
|
|
2208
|
+
return Ce(o, s, r?.onPartialResult);
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* Stream invoke to the agent graph
|
|
2212
|
+
* Returns an async iterable that yields stream chunks as they arrive
|
|
2213
|
+
*
|
|
2214
|
+
* @param messages - Array of messages to send
|
|
2215
|
+
* @param options - Stream options
|
|
2216
|
+
* @returns AsyncGenerator of StreamChunk objects
|
|
2217
|
+
*
|
|
2218
|
+
* @example
|
|
2219
|
+
* ```ts
|
|
2220
|
+
* const stream = client.streamInvoke([userMessage], {
|
|
2221
|
+
* initial_state: {},
|
|
2222
|
+
* response_granularity: 'low'
|
|
2223
|
+
* });
|
|
2224
|
+
*
|
|
2225
|
+
* for await (const chunk of stream) {
|
|
2226
|
+
* if (chunk.event === 'message') {
|
|
2227
|
+
* console.log('Message:', chunk.message?.content);
|
|
2228
|
+
* } else if (chunk.event === 'updates') {
|
|
2229
|
+
* console.log('State updated:', chunk.state);
|
|
2230
|
+
* }
|
|
2231
|
+
* }
|
|
2232
|
+
* ```
|
|
2233
|
+
*/
|
|
2234
|
+
stream(e, r) {
|
|
2235
|
+
const o = {
|
|
2236
|
+
...this.createContext(),
|
|
2237
|
+
toolExecutor: this.toolExecutor
|
|
2238
|
+
}, s = {
|
|
2239
|
+
messages: e.map((n) => this.serializeMessage(n)),
|
|
2240
|
+
initial_state: r?.initial_state,
|
|
2241
|
+
config: r?.config,
|
|
2242
|
+
recursion_limit: r?.recursion_limit || 25,
|
|
2243
|
+
response_granularity: r?.response_granularity || "low"
|
|
2244
|
+
};
|
|
2245
|
+
return Re(o, s);
|
|
2246
|
+
}
|
|
2247
|
+
/**
|
|
2248
|
+
* Stream invoke via a persistent WebSocket connection.
|
|
2249
|
+
*
|
|
2250
|
+
* Identical API to ``stream()`` — same message types, same chunk format,
|
|
2251
|
+
* same tool-execution loop — but uses a single WebSocket instead of one
|
|
2252
|
+
* HTTP request per tool-call iteration. Switch from ``stream()`` to
|
|
2253
|
+
* ``wsStream()`` by changing one method name; everything else stays the
|
|
2254
|
+
* same.
|
|
2255
|
+
*
|
|
2256
|
+
* The WebSocket stays open for the full lifecycle of the call (fresh run +
|
|
2257
|
+
* any resume runs triggered by remote tool calls). The server sends a
|
|
2258
|
+
* ``{ event:"updates", data:{ status:"done" } }`` chunk after each run so
|
|
2259
|
+
* the client knows when to send the next resume request.
|
|
2260
|
+
*
|
|
2261
|
+
* Auth: the bearer token is sent via the ``10xgraph-bearer`` WebSocket
|
|
2262
|
+
* subprotocol (browser-safe; never placed in the URL), with the Authorization
|
|
2263
|
+
* header also set on Node runtimes.
|
|
2264
|
+
*
|
|
2265
|
+
* @param messages - Array of messages to send
|
|
2266
|
+
* @param options - Same options as ``stream()``
|
|
2267
|
+
* @returns AsyncGenerator of StreamChunk objects
|
|
2268
|
+
*
|
|
2269
|
+
* @example
|
|
2270
|
+
* ```ts
|
|
2271
|
+
* const stream = client.wsStream([userMessage], {
|
|
2272
|
+
* config: { thread_id: 'my-thread' },
|
|
2273
|
+
* response_granularity: 'low',
|
|
2274
|
+
* });
|
|
2275
|
+
*
|
|
2276
|
+
* for await (const chunk of stream) {
|
|
2277
|
+
* if (chunk.event === 'message') {
|
|
2278
|
+
* console.log('Message:', chunk.message?.content);
|
|
2279
|
+
* }
|
|
2280
|
+
* }
|
|
2281
|
+
* ```
|
|
2282
|
+
*/
|
|
2283
|
+
wsStream(e, r) {
|
|
2284
|
+
const o = {
|
|
2285
|
+
...this.createContext(),
|
|
2286
|
+
toolExecutor: this.toolExecutor
|
|
2287
|
+
}, s = {
|
|
2288
|
+
messages: e.map((n) => this.serializeMessage(n)),
|
|
2289
|
+
initial_state: r?.initial_state,
|
|
2290
|
+
config: r?.config,
|
|
2291
|
+
recursion_limit: r?.recursion_limit ?? 25,
|
|
2292
|
+
response_granularity: r?.response_granularity ?? "low"
|
|
2293
|
+
};
|
|
2294
|
+
return Oe(o, s);
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Open a realtime (audio-to-audio) session over ``/v1/graph/live``.
|
|
2298
|
+
*
|
|
2299
|
+
* Transport-only: send PCM16 input via ``session.sendAudio(...)`` and receive
|
|
2300
|
+
* PCM16 output via ``session.on('audio', ...)``. Mic capture and audio playback
|
|
2301
|
+
* are the caller's responsibility. The session auto-reconnects (with backoff)
|
|
2302
|
+
* on an unexpected drop and resumes the same ``thread_id``.
|
|
2303
|
+
*
|
|
2304
|
+
* @example
|
|
2305
|
+
* ```ts
|
|
2306
|
+
* const session = client.realtime({ model: 'gemini-2.5-flash-live' });
|
|
2307
|
+
* session.on('audio', (pcm) => speaker.write(pcm));
|
|
2308
|
+
* session.on('output_transcript', (e) => console.log(e.text));
|
|
2309
|
+
* await session.ready;
|
|
2310
|
+
* session.sendAudio(micChunk);
|
|
2311
|
+
* ```
|
|
2312
|
+
*/
|
|
2313
|
+
realtime(e, r) {
|
|
2314
|
+
const o = this.createContext();
|
|
2315
|
+
return new Pe(o, e, r);
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Store a memory in the agent's memory system
|
|
2319
|
+
*
|
|
2320
|
+
* @param request - Memory storage request parameters
|
|
2321
|
+
* @returns Promise<StoreMemoryResponse> containing the memory_id
|
|
2322
|
+
*
|
|
2323
|
+
* @example
|
|
2324
|
+
* ```ts
|
|
2325
|
+
* const result = await client.storeMemory({
|
|
2326
|
+
* content: "User prefers dark mode",
|
|
2327
|
+
* memory_type: MemoryType.SEMANTIC,
|
|
2328
|
+
* category: "preferences",
|
|
2329
|
+
* metadata: { source: "user_settings" }
|
|
2330
|
+
* });
|
|
2331
|
+
* console.log('Memory stored with ID:', result.data.memory_id);
|
|
2332
|
+
* ```
|
|
2333
|
+
*/
|
|
2334
|
+
async storeMemory(e) {
|
|
2335
|
+
const r = this.createContext();
|
|
2336
|
+
return De(r, e);
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Search for memories in the agent's memory system
|
|
2340
|
+
*
|
|
2341
|
+
* @param request - Memory search request parameters
|
|
2342
|
+
* @returns Promise<SearchMemoryResponse> containing matching memories
|
|
2343
|
+
*
|
|
2344
|
+
* @example
|
|
2345
|
+
* ```ts
|
|
2346
|
+
* const results = await client.searchMemory({
|
|
2347
|
+
* query: "dark mode preferences",
|
|
2348
|
+
* memory_type: MemoryType.SEMANTIC,
|
|
2349
|
+
* limit: 5,
|
|
2350
|
+
* retrieval_strategy: RetrievalStrategy.SIMILARITY
|
|
2351
|
+
* });
|
|
2352
|
+
* results.data.results.forEach(result => {
|
|
2353
|
+
* console.log('Memory:', result.content, 'Score:', result.score);
|
|
2354
|
+
* });
|
|
2355
|
+
* ```
|
|
2356
|
+
*/
|
|
2357
|
+
async searchMemory(e) {
|
|
2358
|
+
const r = this.createContext();
|
|
2359
|
+
return Fe(r, e);
|
|
2360
|
+
}
|
|
2361
|
+
/**
|
|
2362
|
+
* Get a specific memory by ID
|
|
2363
|
+
*
|
|
2364
|
+
* @param memoryId - The ID of the memory to retrieve
|
|
2365
|
+
* @param options - Optional config and options
|
|
2366
|
+
* @returns Promise<GetMemoryResponse> containing the memory details
|
|
2367
|
+
*
|
|
2368
|
+
* @example
|
|
2369
|
+
* ```ts
|
|
2370
|
+
* const memory = await client.getMemory('mem-12345', {
|
|
2371
|
+
* config: { include_vector: true }
|
|
2372
|
+
* });
|
|
2373
|
+
* console.log('Memory:', memory.data.memory.content);
|
|
2374
|
+
* console.log('Score:', memory.data.memory.score);
|
|
2375
|
+
* ```
|
|
2376
|
+
*/
|
|
2377
|
+
async getMemory(e, r) {
|
|
2378
|
+
const o = this.createContext(), s = {
|
|
2379
|
+
memoryId: e,
|
|
2380
|
+
config: r?.config,
|
|
2381
|
+
options: r?.options
|
|
2382
|
+
};
|
|
2383
|
+
return He(o, s);
|
|
2384
|
+
}
|
|
2385
|
+
/**
|
|
2386
|
+
* Update an existing memory by ID
|
|
2387
|
+
*
|
|
2388
|
+
* @param memoryId - The ID of the memory to update
|
|
2389
|
+
* @param content - The updated content for the memory
|
|
2390
|
+
* @param options - Optional config, options, and metadata
|
|
2391
|
+
* @returns Promise<UpdateMemoryResponse> containing success status and updated data
|
|
2392
|
+
*
|
|
2393
|
+
* @example
|
|
2394
|
+
* ```ts
|
|
2395
|
+
* const result = await client.updateMemory('mem-12345', 'Updated content', {
|
|
2396
|
+
* metadata: { tags: ['important', 'updated'] }
|
|
2397
|
+
* });
|
|
2398
|
+
* console.log('Update success:', result.data.success);
|
|
2399
|
+
* ```
|
|
2400
|
+
*/
|
|
2401
|
+
async updateMemory(e, r, o) {
|
|
2402
|
+
const s = this.createContext(), n = {
|
|
2403
|
+
memoryId: e,
|
|
2404
|
+
content: r,
|
|
2405
|
+
config: o?.config,
|
|
2406
|
+
options: o?.options,
|
|
2407
|
+
metadata: o?.metadata
|
|
2408
|
+
};
|
|
2409
|
+
return Be(s, n);
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2412
|
+
* Delete a memory by ID
|
|
2413
|
+
*
|
|
2414
|
+
* @param memoryId - The ID of the memory to delete
|
|
2415
|
+
* @param options - Optional config and options
|
|
2416
|
+
* @returns Promise<DeleteMemoryResponse> containing success status and deletion confirmation
|
|
2417
|
+
*
|
|
2418
|
+
* @example
|
|
2419
|
+
* ```ts
|
|
2420
|
+
* const result = await client.deleteMemory('mem-12345', {
|
|
2421
|
+
* config: { soft_delete: true }
|
|
2422
|
+
* });
|
|
2423
|
+
* console.log('Delete success:', result.data.success);
|
|
2424
|
+
* console.log('Deleted:', result.data.data);
|
|
2425
|
+
* ```
|
|
2426
|
+
*/
|
|
2427
|
+
async deleteMemory(e, r) {
|
|
2428
|
+
const o = this.createContext(), s = {
|
|
2429
|
+
memoryId: e,
|
|
2430
|
+
config: r?.config,
|
|
2431
|
+
options: r?.options
|
|
2432
|
+
};
|
|
2433
|
+
return Je(o, s);
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* List all memories with optional pagination
|
|
2437
|
+
*
|
|
2438
|
+
* @param options - Optional config, options, and limit
|
|
2439
|
+
* @returns Promise<ListMemoriesResponse> containing array of memories
|
|
2440
|
+
*
|
|
2441
|
+
* @example
|
|
2442
|
+
* ```ts
|
|
2443
|
+
* const result = await client.listMemories({
|
|
2444
|
+
* limit: 50,
|
|
2445
|
+
* config: { include_vectors: false }
|
|
2446
|
+
* });
|
|
2447
|
+
* console.log('Found memories:', result.data.memories.length);
|
|
2448
|
+
* result.data.memories.forEach(memory => {
|
|
2449
|
+
* console.log('Memory:', memory.content, 'Type:', memory.memory_type);
|
|
2450
|
+
* });
|
|
2451
|
+
* ```
|
|
2452
|
+
*/
|
|
2453
|
+
async listMemories(e) {
|
|
2454
|
+
const r = this.createContext(), o = {
|
|
2455
|
+
config: e?.config,
|
|
2456
|
+
options: e?.options,
|
|
2457
|
+
limit: e?.limit
|
|
2458
|
+
};
|
|
2459
|
+
return We(r, o);
|
|
2460
|
+
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Forget (delete) memories based on filters and criteria
|
|
2463
|
+
*
|
|
2464
|
+
* @param options - Optional config, options, memory type, category, and filters
|
|
2465
|
+
* @returns Promise<ForgetMemoriesResponse> containing success status
|
|
2466
|
+
*
|
|
2467
|
+
* @example
|
|
2468
|
+
* ```ts
|
|
2469
|
+
* // Forget all episodic memories in a category
|
|
2470
|
+
* const result = await client.forgetMemories({
|
|
2471
|
+
* memory_type: MemoryType.EPISODIC,
|
|
2472
|
+
* category: 'temporary',
|
|
2473
|
+
* filters: { tag: 'delete-me' }
|
|
2474
|
+
* });
|
|
2475
|
+
* console.log('Forget success:', result.data.success);
|
|
2476
|
+
* ```
|
|
2477
|
+
*/
|
|
2478
|
+
async forgetMemories(e) {
|
|
2479
|
+
const r = this.createContext(), o = {
|
|
2480
|
+
config: e?.config,
|
|
2481
|
+
options: e?.options,
|
|
2482
|
+
memory_type: e?.memory_type,
|
|
2483
|
+
category: e?.category,
|
|
2484
|
+
filters: e?.filters
|
|
2485
|
+
};
|
|
2486
|
+
return ze(r, o);
|
|
2487
|
+
}
|
|
2488
|
+
// ------------------------------------------------------------------
|
|
2489
|
+
// Files / Multimodal API
|
|
2490
|
+
// ------------------------------------------------------------------
|
|
2491
|
+
/**
|
|
2492
|
+
* Upload a file (image, audio, document) to the server.
|
|
2493
|
+
* Returns file metadata including file_id for use in multimodal messages.
|
|
2494
|
+
*
|
|
2495
|
+
* @param file - A File, Blob, or { data: Blob; filename: string } object
|
|
2496
|
+
* @returns FileUploadResponse with file_id and metadata
|
|
2497
|
+
*
|
|
2498
|
+
* @example
|
|
2499
|
+
* ```ts
|
|
2500
|
+
* const result = await client.uploadFile(file);
|
|
2501
|
+
* const msg = Message.withImage('Describe this', result.data.url);
|
|
2502
|
+
* ```
|
|
2503
|
+
*/
|
|
2504
|
+
async uploadFile(e) {
|
|
2505
|
+
const r = this.createContext();
|
|
2506
|
+
return Ke(r, e);
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Download a file by its file_id. Returns raw Blob.
|
|
2510
|
+
*/
|
|
2511
|
+
async getFile(e) {
|
|
2512
|
+
const r = this.createContext();
|
|
2513
|
+
return Ze(r, e);
|
|
2514
|
+
}
|
|
2515
|
+
/**
|
|
2516
|
+
* Get metadata about a stored file.
|
|
2517
|
+
*/
|
|
2518
|
+
async getFileInfo(e) {
|
|
2519
|
+
const r = this.createContext();
|
|
2520
|
+
return Qe(r, e);
|
|
2521
|
+
}
|
|
2522
|
+
/**
|
|
2523
|
+
* Get the best access URL for a stored file.
|
|
2524
|
+
* For cloud-backed media this will typically be a signed URL.
|
|
2525
|
+
* For local or memory-backed media this may fall back to the API file route.
|
|
2526
|
+
*/
|
|
2527
|
+
async getFileAccessUrl(e) {
|
|
2528
|
+
const r = this.createContext();
|
|
2529
|
+
return Xe(r, e);
|
|
2530
|
+
}
|
|
2531
|
+
/**
|
|
2532
|
+
* Get the current multimodal configuration from the server.
|
|
2533
|
+
*/
|
|
2534
|
+
async getMultimodalConfig() {
|
|
2535
|
+
const e = this.createContext();
|
|
2536
|
+
return qe(e);
|
|
2537
|
+
}
|
|
2538
|
+
/**
|
|
2539
|
+
* Serialize a Message object for API transmission
|
|
2540
|
+
* Converts Message class instances to plain objects
|
|
2541
|
+
*/
|
|
2542
|
+
serializeMessage(e) {
|
|
2543
|
+
const r = {
|
|
2544
|
+
role: e.role,
|
|
2545
|
+
content: this.cleanContent(e.content)
|
|
2546
|
+
};
|
|
2547
|
+
return e.message_id !== null && e.message_id !== void 0 ? r.message_id = String(e.message_id) : r.message_id = "0", e.tools_calls && (r.tools_calls = e.tools_calls), e.metadata && Object.keys(e.metadata).length > 0 && (r.metadata = e.metadata), r;
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Clean content blocks by removing empty arrays and undefined values
|
|
2551
|
+
* Server requires array of content blocks, not simplified string
|
|
2552
|
+
*/
|
|
2553
|
+
cleanContent(e) {
|
|
2554
|
+
return e.map((r) => {
|
|
2555
|
+
const o = {};
|
|
2556
|
+
for (const [s, n] of Object.entries(r))
|
|
2557
|
+
Array.isArray(n) && n.length === 0 || n !== void 0 && (o[s] = n);
|
|
2558
|
+
return o;
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
class nt {
|
|
2563
|
+
constructor() {
|
|
2564
|
+
this.current_node = "START", this.step = 0, this.is_running = !0, this.is_interrupted = !1, this.is_stopped_requested = !1;
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
class wt {
|
|
2568
|
+
constructor(e = {}) {
|
|
2569
|
+
this.context = [], this.context_summary = null, this.execution_meta = new nt(), Object.assign(this, e);
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
const bt = st, Ct = g;
|
|
2573
|
+
export {
|
|
2574
|
+
bt as AgentFlowClient,
|
|
2575
|
+
Ct as AgentFlowError,
|
|
2576
|
+
wt as AgentState,
|
|
2577
|
+
dt as AnnotationBlock,
|
|
2578
|
+
it as AnnotationRef,
|
|
2579
|
+
H as AudioBlock,
|
|
2580
|
+
$ as AuthenticationError,
|
|
2581
|
+
R as BadRequestError,
|
|
2582
|
+
at as DataBlock,
|
|
2583
|
+
Le as DistanceMetric,
|
|
2584
|
+
J as DocumentBlock,
|
|
2585
|
+
ut as ErrorBlock,
|
|
2586
|
+
V as GraphError,
|
|
2587
|
+
K as GraphRecursionError,
|
|
2588
|
+
v as ImageBlock,
|
|
2589
|
+
b as MediaRef,
|
|
2590
|
+
L as MemoryType,
|
|
2591
|
+
C as Message,
|
|
2592
|
+
X as MetricsError,
|
|
2593
|
+
Y as NodeError,
|
|
2594
|
+
A as NotFoundError,
|
|
2595
|
+
k as PermissionError,
|
|
2596
|
+
yt as REALTIME_INPUT_SAMPLE_RATE,
|
|
2597
|
+
Ne as REALTIME_OUTPUT_SAMPLE_RATE,
|
|
2598
|
+
Pe as RealtimeSession,
|
|
2599
|
+
ht as ReasoningBlock,
|
|
2600
|
+
ct as RemoteToolCallBlock,
|
|
2601
|
+
Me as RetrievalStrategy,
|
|
2602
|
+
q as SchemaVersionError,
|
|
2603
|
+
ee as SerializationError,
|
|
2604
|
+
O as ServerError,
|
|
2605
|
+
Z as StorageError,
|
|
2606
|
+
x as StreamEventType,
|
|
2607
|
+
st as TenxGraphClient,
|
|
2608
|
+
g as TenxGraphError,
|
|
2609
|
+
S as TextBlock,
|
|
2610
|
+
mt as TokenUsages,
|
|
2611
|
+
lt as ToolCallBlock,
|
|
2612
|
+
z as ToolExecutor,
|
|
2613
|
+
G as ToolResultBlock,
|
|
2614
|
+
Q as TransientStorageError,
|
|
2615
|
+
I as ValidationError,
|
|
2616
|
+
B as VideoBlock,
|
|
2617
|
+
ke as WS_BEARER_SUBPROTOCOL,
|
|
2618
|
+
me as addThreadMessages,
|
|
2619
|
+
pt as basicAuth,
|
|
2620
|
+
ft as bearerAuth,
|
|
2621
|
+
m as buildHeaders,
|
|
2622
|
+
D as buildWsUrl,
|
|
2623
|
+
Tt as checkpointMessages,
|
|
2624
|
+
ue as clearThreadState,
|
|
2625
|
+
p as createErrorFromResponse,
|
|
2626
|
+
Je as deleteMemory,
|
|
2627
|
+
Te as deleteThread,
|
|
2628
|
+
ge as deleteThreadMessage,
|
|
2629
|
+
Ye as fixGraph,
|
|
2630
|
+
ze as forgetMemories,
|
|
2631
|
+
Ze as getFile,
|
|
2632
|
+
Xe as getFileAccessUrl,
|
|
2633
|
+
Qe as getFileInfo,
|
|
2634
|
+
He as getMemory,
|
|
2635
|
+
qe as getMultimodalConfig,
|
|
2636
|
+
f as getRequestCredentials,
|
|
2637
|
+
ie as graph,
|
|
2638
|
+
ae as graphTools,
|
|
2639
|
+
gt as headerAuth,
|
|
2640
|
+
Ce as invoke,
|
|
2641
|
+
We as listMemories,
|
|
2642
|
+
W as normalizeToolParameters,
|
|
2643
|
+
le as observability,
|
|
2644
|
+
M as openWebSocket,
|
|
2645
|
+
te as parseErrorResponse,
|
|
2646
|
+
ne as ping,
|
|
2647
|
+
Ae as resolveBearerToken,
|
|
2648
|
+
Fe as searchMemory,
|
|
2649
|
+
P as serializeMessage,
|
|
2650
|
+
ce as stateSchema,
|
|
2651
|
+
Ve as stopGraph,
|
|
2652
|
+
De as storeMemory,
|
|
2653
|
+
Re as streamInvoke,
|
|
2654
|
+
pe as threadDetails,
|
|
2655
|
+
fe as threadMessage,
|
|
2656
|
+
U as threadMessages,
|
|
2657
|
+
he as threadState,
|
|
2658
|
+
ye as threads,
|
|
2659
|
+
Be as updateMemory,
|
|
2660
|
+
de as updateThreadState,
|
|
2661
|
+
Ke as uploadFile,
|
|
2662
|
+
Oe as wsStreamInvoke
|
|
2663
|
+
};
|
|
2664
|
+
//# sourceMappingURL=index.js.map
|