10xgraph-client 0.6.0 → 1.0.0-rc.2
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 +207 -0
- package/README.md +11 -5
- package/dist/agent.d.ts +17 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/cjs/agent.d.ts +33 -0
- package/dist/cjs/client.d.ts +533 -0
- package/dist/cjs/compat.d.ts +27 -0
- package/dist/cjs/endpoints/addThreadMessages.d.ts +25 -0
- package/dist/cjs/endpoints/clearThreadState.d.ts +14 -0
- package/dist/cjs/endpoints/deleteFile.d.ts +13 -0
- package/dist/cjs/endpoints/deleteMemory.d.ts +18 -0
- package/dist/cjs/endpoints/deleteThread.d.ts +18 -0
- package/dist/cjs/endpoints/deleteThreadMessage.d.ts +19 -0
- package/dist/cjs/endpoints/files.d.ts +115 -0
- package/dist/cjs/endpoints/fixGraph.d.ts +33 -0
- package/dist/cjs/endpoints/forgetMemories.d.ts +21 -0
- package/dist/cjs/endpoints/getMemory.d.ts +18 -0
- package/dist/cjs/endpoints/graph.d.ts +50 -0
- package/dist/cjs/endpoints/graphTools.d.ts +31 -0
- package/dist/cjs/endpoints/invoke.d.ts +66 -0
- package/dist/cjs/endpoints/listMemories.d.ts +24 -0
- package/dist/cjs/endpoints/metadata.d.ts +5 -0
- package/dist/cjs/endpoints/observability.d.ts +111 -0
- package/dist/cjs/endpoints/ping.d.ts +9 -0
- package/dist/cjs/endpoints/realtime.d.ts +154 -0
- package/dist/cjs/endpoints/searchMemory.d.ts +56 -0
- package/dist/cjs/endpoints/stateSchema.d.ts +49 -0
- package/dist/cjs/endpoints/stopGraph.d.ts +35 -0
- package/dist/cjs/endpoints/storeMemory.d.ts +32 -0
- package/dist/cjs/endpoints/stream.d.ts +67 -0
- package/dist/cjs/endpoints/threadDetails.d.ts +18 -0
- package/dist/cjs/endpoints/threadMessage.d.ts +16 -0
- package/dist/cjs/endpoints/threadMessages.d.ts +28 -0
- package/dist/cjs/endpoints/threadState.d.ts +13 -0
- package/dist/cjs/endpoints/threads.d.ts +35 -0
- package/dist/cjs/endpoints/updateMemory.d.ts +20 -0
- package/dist/cjs/endpoints/updateThreadMessageFeedback.d.ts +19 -0
- package/dist/cjs/endpoints/updateThreadState.d.ts +22 -0
- package/dist/cjs/endpoints/wsStream.d.ts +34 -0
- package/dist/cjs/errors.d.ts +212 -0
- package/dist/cjs/index.d.ts +41 -0
- package/dist/cjs/interrupt.d.ts +45 -0
- package/dist/cjs/message.d.ts +173 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/request.d.ts +60 -0
- package/dist/cjs/tools.d.ts +80 -0
- package/dist/cjs/ws.d.ts +47 -0
- package/dist/client.d.ts +95 -40
- package/dist/client.d.ts.map +1 -1
- package/dist/endpoints/addThreadMessages.d.ts +4 -0
- package/dist/endpoints/addThreadMessages.d.ts.map +1 -1
- package/dist/endpoints/clearThreadState.d.ts.map +1 -1
- package/dist/endpoints/deleteFile.d.ts +14 -0
- package/dist/endpoints/deleteFile.d.ts.map +1 -0
- package/dist/endpoints/deleteMemory.d.ts.map +1 -1
- package/dist/endpoints/deleteThread.d.ts.map +1 -1
- package/dist/endpoints/deleteThreadMessage.d.ts.map +1 -1
- package/dist/endpoints/files.d.ts +33 -0
- package/dist/endpoints/files.d.ts.map +1 -1
- package/dist/endpoints/fixGraph.d.ts +8 -3
- package/dist/endpoints/fixGraph.d.ts.map +1 -1
- package/dist/endpoints/forgetMemories.d.ts.map +1 -1
- package/dist/endpoints/getMemory.d.ts.map +1 -1
- package/dist/endpoints/graph.d.ts +20 -8
- package/dist/endpoints/graph.d.ts.map +1 -1
- package/dist/endpoints/graphTools.d.ts.map +1 -1
- package/dist/endpoints/invoke.d.ts +8 -0
- package/dist/endpoints/invoke.d.ts.map +1 -1
- package/dist/endpoints/listMemories.d.ts +6 -0
- package/dist/endpoints/listMemories.d.ts.map +1 -1
- package/dist/endpoints/observability.d.ts +54 -0
- package/dist/endpoints/observability.d.ts.map +1 -1
- package/dist/endpoints/ping.d.ts.map +1 -1
- package/dist/endpoints/realtime.d.ts +25 -4
- package/dist/endpoints/realtime.d.ts.map +1 -1
- package/dist/endpoints/searchMemory.d.ts.map +1 -1
- package/dist/endpoints/stateSchema.d.ts.map +1 -1
- package/dist/endpoints/stopGraph.d.ts +13 -3
- package/dist/endpoints/stopGraph.d.ts.map +1 -1
- package/dist/endpoints/storeMemory.d.ts.map +1 -1
- package/dist/endpoints/stream.d.ts +8 -0
- package/dist/endpoints/stream.d.ts.map +1 -1
- package/dist/endpoints/threadDetails.d.ts.map +1 -1
- package/dist/endpoints/threadMessage.d.ts.map +1 -1
- package/dist/endpoints/threadMessages.d.ts +6 -0
- package/dist/endpoints/threadMessages.d.ts.map +1 -1
- package/dist/endpoints/threadState.d.ts.map +1 -1
- package/dist/endpoints/threads.d.ts +6 -0
- package/dist/endpoints/threads.d.ts.map +1 -1
- package/dist/endpoints/updateMemory.d.ts.map +1 -1
- package/dist/endpoints/updateThreadMessageFeedback.d.ts +20 -0
- package/dist/endpoints/updateThreadMessageFeedback.d.ts.map +1 -0
- package/dist/endpoints/updateThreadState.d.ts +6 -1
- package/dist/endpoints/updateThreadState.d.ts.map +1 -1
- package/dist/endpoints/wsStream.d.ts +2 -0
- package/dist/endpoints/wsStream.d.ts.map +1 -1
- package/dist/errors.d.ts +60 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1742 -1217
- package/dist/index.js.map +1 -1
- package/dist/interrupt.d.ts +46 -0
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/request.d.ts +28 -0
- package/dist/request.d.ts.map +1 -1
- package/dist/tools.d.ts +14 -0
- package/dist/tools.d.ts.map +1 -1
- package/package.json +11 -6
- package/src/agent.ts +17 -4
- package/src/client.ts +248 -128
- package/src/endpoints/addThreadMessages.ts +15 -10
- package/src/endpoints/clearThreadState.ts +19 -20
- package/src/endpoints/deleteFile.ts +65 -0
- package/src/endpoints/deleteMemory.ts +9 -13
- package/src/endpoints/deleteThread.ts +9 -13
- package/src/endpoints/deleteThreadMessage.ts +9 -13
- package/src/endpoints/files.ts +164 -131
- package/src/endpoints/fixGraph.ts +15 -16
- package/src/endpoints/forgetMemories.ts +44 -60
- package/src/endpoints/getMemory.ts +9 -9
- package/src/endpoints/graph.ts +28 -21
- package/src/endpoints/graphTools.ts +7 -13
- package/src/endpoints/invoke.ts +105 -84
- package/src/endpoints/listMemories.ts +18 -13
- package/src/endpoints/observability.ts +77 -34
- package/src/endpoints/ping.ts +7 -13
- package/src/endpoints/realtime.ts +101 -39
- package/src/endpoints/searchMemory.ts +19 -13
- package/src/endpoints/stateSchema.ts +7 -13
- package/src/endpoints/stopGraph.ts +20 -16
- package/src/endpoints/storeMemory.ts +7 -8
- package/src/endpoints/stream.ts +179 -61
- package/src/endpoints/threadDetails.ts +9 -14
- package/src/endpoints/threadMessage.ts +9 -9
- package/src/endpoints/threadMessages.ts +15 -9
- package/src/endpoints/threadState.ts +19 -20
- package/src/endpoints/threads.ts +13 -12
- package/src/endpoints/updateMemory.ts +9 -9
- package/src/endpoints/updateThreadMessageFeedback.ts +80 -0
- package/src/endpoints/updateThreadState.ts +28 -22
- package/src/endpoints/wsStream.ts +167 -42
- package/src/errors.ts +332 -93
- package/src/index.ts +9 -0
- package/src/interrupt.ts +60 -0
- package/src/request.ts +134 -0
- package/src/tools.ts +95 -0
package/dist/index.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
class
|
|
2
|
-
constructor(e = "url", r, o, s, n, i, a, c,
|
|
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 =
|
|
1
|
+
class O {
|
|
2
|
+
constructor(e = "url", r, o, s, n, i, a, c, l, y, g, b) {
|
|
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 = l, this.height = y, this.duration_ms = g, this.page = b;
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
class
|
|
6
|
+
class Dt {
|
|
7
7
|
constructor(e, r, o, s, n) {
|
|
8
8
|
this.url = e, this.file_id = r, this.page = o, this.index = s, this.title = n;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
class
|
|
11
|
+
class X {
|
|
12
12
|
constructor(e = "", r = []) {
|
|
13
13
|
this.type = "text", this.text = "", this.annotations = [], this.text = e, this.annotations = r;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
class
|
|
17
|
-
constructor(e = new
|
|
18
|
-
this.type = "image", this.media = new
|
|
16
|
+
class Z {
|
|
17
|
+
constructor(e = new O(), r, o) {
|
|
18
|
+
this.type = "image", this.media = new O(), this.media = e, this.alt_text = r, this.bbox = o;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
22
|
-
constructor(e = new
|
|
23
|
-
this.type = "audio", this.media = new
|
|
21
|
+
class ie {
|
|
22
|
+
constructor(e = new O(), r, o, s) {
|
|
23
|
+
this.type = "audio", this.media = new O(), this.media = e, this.transcript = r, this.sample_rate = o, this.channels = s;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
27
|
-
constructor(e = new
|
|
28
|
-
this.type = "video", this.media = new
|
|
26
|
+
class ae {
|
|
27
|
+
constructor(e = new O(), r) {
|
|
28
|
+
this.type = "video", this.media = new O(), this.media = e, this.thumbnail = r;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
class
|
|
32
|
-
constructor(e = new
|
|
33
|
-
this.type = "document", this.media = new
|
|
31
|
+
class ce {
|
|
32
|
+
constructor(e = new O(), r, o) {
|
|
33
|
+
this.type = "document", this.media = new O(), this.media = e, this.pages = r, this.excerpt = o;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class
|
|
36
|
+
class Mt {
|
|
37
37
|
constructor(e = "", r, o) {
|
|
38
38
|
this.type = "data", this.mime_type = "", this.mime_type = e, this.data_base64 = r, this.media = o;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
class
|
|
41
|
+
class Ft {
|
|
42
42
|
constructor(e = "", r = "", o = {}, s) {
|
|
43
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
44
|
}
|
|
45
45
|
}
|
|
46
|
-
class
|
|
46
|
+
class Bt {
|
|
47
47
|
constructor(e = "", r = "", o = {}, s = "remote") {
|
|
48
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
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class F {
|
|
52
52
|
constructor(e) {
|
|
53
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
54
|
}
|
|
55
55
|
}
|
|
56
|
-
class
|
|
56
|
+
class Ht {
|
|
57
57
|
constructor(e = "", r) {
|
|
58
58
|
this.type = "reasoning", this.summary = "", this.summary = e, this.details = r;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
class
|
|
61
|
+
class Jt {
|
|
62
62
|
constructor(e = "citation", r = [], o) {
|
|
63
63
|
this.type = "annotation", this.kind = "citation", this.refs = [], this.kind = e, this.refs = r, this.spans = o;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
class
|
|
66
|
+
class Wt {
|
|
67
67
|
constructor(e = "", r, o) {
|
|
68
68
|
this.type = "error", this.message = "", this.message = e, this.code = r, this.data = o;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
class
|
|
71
|
+
class Vt {
|
|
72
72
|
constructor() {
|
|
73
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
74
|
}
|
|
75
75
|
}
|
|
76
|
-
class
|
|
76
|
+
class A {
|
|
77
77
|
constructor(e, r, o = null) {
|
|
78
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
79
|
}
|
|
80
80
|
static text_message(e, r = "user", o = null) {
|
|
81
|
-
return new
|
|
81
|
+
return new A(r, [{ type: "text", text: e }], o);
|
|
82
82
|
}
|
|
83
83
|
static tool_message(e, r = null, o = {}) {
|
|
84
|
-
const s = new
|
|
84
|
+
const s = new A("tool", e, r);
|
|
85
85
|
return s.metadata = o, s;
|
|
86
86
|
}
|
|
87
87
|
text() {
|
|
@@ -128,9 +128,9 @@ class C {
|
|
|
128
128
|
* ```
|
|
129
129
|
*/
|
|
130
130
|
static withImage(e, r, o = "user") {
|
|
131
|
-
return new
|
|
132
|
-
new
|
|
133
|
-
new
|
|
131
|
+
return new A(o, [
|
|
132
|
+
new X(e),
|
|
133
|
+
new Z(new O("url", r, void 0, void 0, void 0))
|
|
134
134
|
]);
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
@@ -143,9 +143,9 @@ class C {
|
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
static withFile(e, r, o, s = "user") {
|
|
146
|
-
const n = new
|
|
147
|
-
let
|
|
148
|
-
return i ?
|
|
146
|
+
const n = new O("file_id", void 0, r, void 0, o), i = o?.startsWith("image/"), a = o?.startsWith("audio/"), c = o?.startsWith("video/");
|
|
147
|
+
let l;
|
|
148
|
+
return i ? l = new Z(n) : a ? l = new ie(n) : c ? l = new ae(n) : l = new ce(n), new A(s, [new X(e), l]);
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* Create a multimodal message with arbitrary content blocks.
|
|
@@ -160,10 +160,10 @@ class C {
|
|
|
160
160
|
* ```
|
|
161
161
|
*/
|
|
162
162
|
static multimodal(e, r = "user") {
|
|
163
|
-
return new
|
|
163
|
+
return new A(r, e);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function le(t) {
|
|
167
167
|
const e = t ?? {}, { type: r, properties: o, required: s, ...n } = e;
|
|
168
168
|
return {
|
|
169
169
|
...n,
|
|
@@ -172,7 +172,27 @@ function W(t) {
|
|
|
172
172
|
required: s ?? []
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
const de = 1024 * 1024;
|
|
176
|
+
function he(t, e) {
|
|
177
|
+
if (!e) return null;
|
|
178
|
+
if (t === null || typeof t != "object" || Array.isArray(t))
|
|
179
|
+
return "arguments must be an object";
|
|
180
|
+
const r = t;
|
|
181
|
+
for (const s of e.required ?? [])
|
|
182
|
+
if (!(s in r)) return `missing required argument '${s}'`;
|
|
183
|
+
const o = e.properties ?? {};
|
|
184
|
+
if (e.additionalProperties === !1) {
|
|
185
|
+
for (const s of Object.keys(r))
|
|
186
|
+
if (!(s in o)) return `unexpected argument '${s}'`;
|
|
187
|
+
}
|
|
188
|
+
for (const [s, n] of Object.entries(o)) {
|
|
189
|
+
const i = r[s], a = n?.type;
|
|
190
|
+
if (i === void 0 || typeof a != "string") continue;
|
|
191
|
+
if (!(a === "string" ? typeof i == "string" : a === "number" ? typeof i == "number" : a === "integer" ? Number.isInteger(i) : a === "boolean" ? typeof i == "boolean" : a === "array" ? Array.isArray(i) : a === "object" ? i !== null && typeof i == "object" && !Array.isArray(i) : !0)) return `argument '${s}' must be of type ${a}`;
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
class ue {
|
|
176
196
|
constructor(e = []) {
|
|
177
197
|
this.tools = /* @__PURE__ */ new Map(), this.toolsByNode = /* @__PURE__ */ new Map();
|
|
178
198
|
for (const r of e)
|
|
@@ -195,6 +215,14 @@ class z {
|
|
|
195
215
|
value: e.parameters,
|
|
196
216
|
writable: !0,
|
|
197
217
|
configurable: !0
|
|
218
|
+
}), Object.defineProperty(r, "validate", {
|
|
219
|
+
value: e.validate,
|
|
220
|
+
writable: !0,
|
|
221
|
+
configurable: !0
|
|
222
|
+
}), Object.defineProperty(r, "maxArgsBytes", {
|
|
223
|
+
value: e.maxArgsBytes,
|
|
224
|
+
writable: !0,
|
|
225
|
+
configurable: !0
|
|
198
226
|
}), Object.defineProperty(r, "node", {
|
|
199
227
|
value: e.node,
|
|
200
228
|
writable: !0,
|
|
@@ -219,7 +247,7 @@ class z {
|
|
|
219
247
|
function: {
|
|
220
248
|
name: r,
|
|
221
249
|
description: o.description || `Execute ${r}`,
|
|
222
|
-
parameters:
|
|
250
|
+
parameters: le(o.parameters)
|
|
223
251
|
}
|
|
224
252
|
};
|
|
225
253
|
e.push(s);
|
|
@@ -232,50 +260,75 @@ class z {
|
|
|
232
260
|
*/
|
|
233
261
|
async executeToolCalls(e) {
|
|
234
262
|
const r = [];
|
|
235
|
-
for (const
|
|
236
|
-
if (
|
|
237
|
-
for (const
|
|
238
|
-
|
|
239
|
-
const o = []
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
263
|
+
for (const i of e)
|
|
264
|
+
if (i.content)
|
|
265
|
+
for (const a of i.content)
|
|
266
|
+
a.type === "remote_tool_call" && r.push(a);
|
|
267
|
+
const o = [], s = /* @__PURE__ */ new Set(), n = (i, a) => A.tool_message([
|
|
268
|
+
new F({
|
|
269
|
+
call_id: i,
|
|
270
|
+
output: { error: a },
|
|
271
|
+
status: "failed",
|
|
272
|
+
is_error: !0
|
|
273
|
+
})
|
|
274
|
+
]);
|
|
275
|
+
for (const i of r) {
|
|
276
|
+
const a = i.name;
|
|
277
|
+
if (i.id && s.has(i.id)) {
|
|
278
|
+
o.push(n(i.id, `Duplicate tool call id '${i.id}' rejected`));
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (i.id && s.add(i.id), this.tools.has(a)) {
|
|
282
|
+
const c = this.tools.get(a);
|
|
244
283
|
try {
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
284
|
+
const l = c.maxArgsBytes ?? de;
|
|
285
|
+
if ((JSON.stringify(i.args ?? null)?.length ?? 0) > l) {
|
|
286
|
+
o.push(n(i.id, `Arguments for '${a}' exceed ${l} bytes`));
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const g = he(i.args ?? {}, c.parameters);
|
|
290
|
+
if (g) {
|
|
291
|
+
o.push(n(i.id, `Invalid arguments for '${a}': ${g}`));
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (c.validate && await c.validate(i.args) === !1) {
|
|
295
|
+
o.push(n(i.id, `Arguments for '${a}' were rejected`));
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const b = await c(i.args), G = new F({
|
|
299
|
+
call_id: i.id,
|
|
300
|
+
output: b,
|
|
248
301
|
status: "completed",
|
|
249
302
|
is_error: !1
|
|
250
303
|
});
|
|
251
|
-
o.push(
|
|
252
|
-
} catch (
|
|
253
|
-
const
|
|
254
|
-
call_id:
|
|
255
|
-
output: { error:
|
|
304
|
+
o.push(A.tool_message([G]));
|
|
305
|
+
} catch (l) {
|
|
306
|
+
const y = l instanceof Error ? l.message : String(l), g = new F({
|
|
307
|
+
call_id: i.id,
|
|
308
|
+
output: { error: y },
|
|
256
309
|
status: "failed",
|
|
257
310
|
is_error: !0
|
|
258
311
|
});
|
|
259
|
-
o.push(
|
|
312
|
+
o.push(A.tool_message([g]));
|
|
260
313
|
}
|
|
261
314
|
} else {
|
|
262
|
-
const
|
|
263
|
-
call_id:
|
|
264
|
-
output: { error: `Tool '${
|
|
315
|
+
const c = new F({
|
|
316
|
+
call_id: i.id,
|
|
317
|
+
output: { error: `Tool '${a}' not found` },
|
|
265
318
|
status: "failed",
|
|
266
319
|
is_error: !0
|
|
267
320
|
});
|
|
268
|
-
o.push(
|
|
321
|
+
o.push(A.tool_message([c]));
|
|
269
322
|
}
|
|
270
323
|
}
|
|
271
324
|
return o;
|
|
272
325
|
}
|
|
273
326
|
}
|
|
274
|
-
class
|
|
275
|
-
constructor(e, r, o, s, n, i = [], a, c,
|
|
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 =
|
|
277
|
-
const
|
|
278
|
-
|
|
327
|
+
class T extends Error {
|
|
328
|
+
constructor(e, r, o, s, n, i = [], a, c, l, y) {
|
|
329
|
+
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 = l, this.recoverySuggestion = y;
|
|
330
|
+
const g = Error.captureStackTrace;
|
|
331
|
+
g && g(this, this.constructor);
|
|
279
332
|
}
|
|
280
333
|
/**
|
|
281
334
|
* Get a user-friendly error message with recovery suggestion
|
|
@@ -305,37 +358,42 @@ Suggestion: ${this.recoverySuggestion}` : this.message;
|
|
|
305
358
|
};
|
|
306
359
|
}
|
|
307
360
|
}
|
|
308
|
-
class
|
|
361
|
+
class fe extends T {
|
|
309
362
|
constructor(e, r, o, s = []) {
|
|
310
363
|
super(e, 400, "BAD_REQUEST", r, o, s), this.name = "BadRequestError";
|
|
311
364
|
}
|
|
312
365
|
}
|
|
313
|
-
class
|
|
366
|
+
class pe extends T {
|
|
314
367
|
constructor(e, r, o, s = []) {
|
|
315
368
|
super(e, 401, "AUTHENTICATION_FAILED", r, o, s), this.name = "AuthenticationError";
|
|
316
369
|
}
|
|
317
370
|
}
|
|
318
|
-
class
|
|
371
|
+
class me extends T {
|
|
319
372
|
constructor(e, r, o, s = []) {
|
|
320
373
|
super(e, 403, "PERMISSION_ERROR", r, o, s), this.name = "PermissionError";
|
|
321
374
|
}
|
|
322
375
|
}
|
|
323
|
-
class
|
|
376
|
+
class ge extends T {
|
|
324
377
|
constructor(e, r, o, s = []) {
|
|
325
378
|
super(e, 404, "RESOURCE_NOT_FOUND", r, o, s), this.name = "NotFoundError";
|
|
326
379
|
}
|
|
327
380
|
}
|
|
328
|
-
class
|
|
381
|
+
class ye extends T {
|
|
382
|
+
constructor(e, r, o, s = []) {
|
|
383
|
+
super(e, 409, "CONFLICT", r, o, s), this.name = "ConflictError";
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
class Q extends T {
|
|
329
387
|
constructor(e, r, o, s = []) {
|
|
330
388
|
super(e, 422, "VALIDATION_ERROR", r, o, s), this.name = "ValidationError";
|
|
331
389
|
}
|
|
332
390
|
}
|
|
333
|
-
class
|
|
391
|
+
class Te extends T {
|
|
334
392
|
constructor(e, r, o, s = "INTERNAL_SERVER_ERROR", n = [], i = 500) {
|
|
335
393
|
super(e, i, s, r, o, n), this.name = "ServerError";
|
|
336
394
|
}
|
|
337
395
|
}
|
|
338
|
-
class
|
|
396
|
+
class be extends T {
|
|
339
397
|
constructor(e, r, o, s = [], n) {
|
|
340
398
|
super(
|
|
341
399
|
e,
|
|
@@ -351,7 +409,7 @@ class V extends g {
|
|
|
351
409
|
), this.name = "GraphError";
|
|
352
410
|
}
|
|
353
411
|
}
|
|
354
|
-
class
|
|
412
|
+
class we extends T {
|
|
355
413
|
constructor(e, r, o, s = [], n, i) {
|
|
356
414
|
super(
|
|
357
415
|
e,
|
|
@@ -367,7 +425,7 @@ class Y extends g {
|
|
|
367
425
|
), this.name = "NodeError", this.nodeName = i;
|
|
368
426
|
}
|
|
369
427
|
}
|
|
370
|
-
class
|
|
428
|
+
class _e extends T {
|
|
371
429
|
constructor(e, r, o, s = [], n, i) {
|
|
372
430
|
super(
|
|
373
431
|
e,
|
|
@@ -383,7 +441,7 @@ class K extends g {
|
|
|
383
441
|
), this.name = "GraphRecursionError", this.recursionLimit = i;
|
|
384
442
|
}
|
|
385
443
|
}
|
|
386
|
-
class
|
|
444
|
+
class Ce extends T {
|
|
387
445
|
constructor(e, r, o, s = [], n) {
|
|
388
446
|
super(
|
|
389
447
|
e,
|
|
@@ -399,7 +457,7 @@ class Z extends g {
|
|
|
399
457
|
), this.name = "StorageError";
|
|
400
458
|
}
|
|
401
459
|
}
|
|
402
|
-
class
|
|
460
|
+
class Ee extends T {
|
|
403
461
|
constructor(e, r, o, s = [], n) {
|
|
404
462
|
super(
|
|
405
463
|
e,
|
|
@@ -415,7 +473,7 @@ class Q extends g {
|
|
|
415
473
|
), this.name = "TransientStorageError";
|
|
416
474
|
}
|
|
417
475
|
}
|
|
418
|
-
class
|
|
476
|
+
class ve extends T {
|
|
419
477
|
constructor(e, r, o, s = [], n) {
|
|
420
478
|
super(
|
|
421
479
|
e,
|
|
@@ -431,7 +489,7 @@ class X extends g {
|
|
|
431
489
|
), this.name = "MetricsError";
|
|
432
490
|
}
|
|
433
491
|
}
|
|
434
|
-
class
|
|
492
|
+
class Se extends T {
|
|
435
493
|
constructor(e, r, o, s = [], n, i, a) {
|
|
436
494
|
super(
|
|
437
495
|
e,
|
|
@@ -447,7 +505,7 @@ class q extends g {
|
|
|
447
505
|
), this.name = "SchemaVersionError", this.expectedVersion = i, this.actualVersion = a;
|
|
448
506
|
}
|
|
449
507
|
}
|
|
450
|
-
class
|
|
508
|
+
class Ge extends T {
|
|
451
509
|
constructor(e, r, o, s = [], n) {
|
|
452
510
|
super(
|
|
453
511
|
e,
|
|
@@ -463,139 +521,263 @@ class ee extends g {
|
|
|
463
521
|
), this.name = "SerializationError";
|
|
464
522
|
}
|
|
465
523
|
}
|
|
466
|
-
|
|
524
|
+
class Re extends T {
|
|
525
|
+
constructor(e, r, o, s = [], n) {
|
|
526
|
+
super(
|
|
527
|
+
e,
|
|
528
|
+
429,
|
|
529
|
+
"RATE_LIMIT_EXCEEDED",
|
|
530
|
+
r,
|
|
531
|
+
o,
|
|
532
|
+
s,
|
|
533
|
+
void 0,
|
|
534
|
+
void 0,
|
|
535
|
+
void 0,
|
|
536
|
+
"Wait for the retry-after period before sending the request again."
|
|
537
|
+
), this.name = "RateLimitError", this.retryAfterSeconds = n;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
class M extends T {
|
|
541
|
+
constructor(e, r, o, s) {
|
|
542
|
+
super(
|
|
543
|
+
`Request timeout after ${e}ms`,
|
|
544
|
+
0,
|
|
545
|
+
"REQUEST_TIMEOUT",
|
|
546
|
+
"unknown",
|
|
547
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
548
|
+
[],
|
|
549
|
+
void 0,
|
|
550
|
+
r,
|
|
551
|
+
o,
|
|
552
|
+
"Increase the client timeout or check that the server is reachable and not overloaded."
|
|
553
|
+
), this.name = "RequestTimeoutError", this.timeoutMs = e, s !== void 0 && (this.cause = s);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
class D extends T {
|
|
557
|
+
constructor(e, r, o, s) {
|
|
558
|
+
super(
|
|
559
|
+
e,
|
|
560
|
+
0,
|
|
561
|
+
"NETWORK_ERROR",
|
|
562
|
+
"unknown",
|
|
563
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
564
|
+
[],
|
|
565
|
+
void 0,
|
|
566
|
+
r,
|
|
567
|
+
o,
|
|
568
|
+
"Check that the server is running, the base URL is correct and the network is reachable."
|
|
569
|
+
), this.name = "NetworkError", s !== void 0 && (this.cause = s);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
class B extends T {
|
|
573
|
+
constructor(e, r, o, s) {
|
|
574
|
+
super(
|
|
575
|
+
e,
|
|
576
|
+
0,
|
|
577
|
+
"WEBSOCKET_ERROR",
|
|
578
|
+
"unknown",
|
|
579
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
580
|
+
[],
|
|
581
|
+
void 0,
|
|
582
|
+
o,
|
|
583
|
+
"WS"
|
|
584
|
+
), this.name = "WebSocketError", this.closeCode = r, s !== void 0 && (this.cause = s);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
class V extends T {
|
|
588
|
+
constructor(e, r = "STREAM_ERROR", o = "unknown", s, n, i) {
|
|
589
|
+
super(
|
|
590
|
+
e,
|
|
591
|
+
0,
|
|
592
|
+
r,
|
|
593
|
+
o,
|
|
594
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
595
|
+
[],
|
|
596
|
+
void 0,
|
|
597
|
+
s,
|
|
598
|
+
n
|
|
599
|
+
), this.name = "StreamError", i !== void 0 && (this.cause = i);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function H(t) {
|
|
603
|
+
return t !== null && typeof t == "object" && !Array.isArray(t) ? t : null;
|
|
604
|
+
}
|
|
605
|
+
function ke(t) {
|
|
606
|
+
const e = H(t);
|
|
607
|
+
if (!e) return null;
|
|
608
|
+
const r = H(e.metadata) ?? {}, o = {
|
|
609
|
+
message: typeof r.message == "string" ? r.message : "",
|
|
610
|
+
request_id: typeof r.request_id == "string" ? r.request_id : "",
|
|
611
|
+
timestamp: typeof r.timestamp == "string" ? r.timestamp : ""
|
|
612
|
+
}, s = H(e.error);
|
|
613
|
+
if (s)
|
|
614
|
+
return {
|
|
615
|
+
metadata: o,
|
|
616
|
+
error: {
|
|
617
|
+
code: typeof s.code == "string" ? s.code : "",
|
|
618
|
+
message: typeof s.message == "string" ? s.message : "",
|
|
619
|
+
details: Array.isArray(s.details) ? s.details : [],
|
|
620
|
+
...typeof s.retry_after_seconds == "number" ? { retry_after_seconds: s.retry_after_seconds } : {}
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
if (typeof e.error == "string") {
|
|
624
|
+
const n = typeof e.detail == "string" ? e.detail : e.error;
|
|
625
|
+
return { metadata: o, error: { code: e.error, message: n, details: [] } };
|
|
626
|
+
}
|
|
627
|
+
if (typeof e.detail == "string")
|
|
628
|
+
return { metadata: o, error: { code: "", message: e.detail, details: [] } };
|
|
629
|
+
if (Array.isArray(e.detail)) {
|
|
630
|
+
const n = e.detail.filter((i) => H(i) !== null);
|
|
631
|
+
return {
|
|
632
|
+
metadata: o,
|
|
633
|
+
error: { code: "", message: n[0]?.msg || "Validation error", details: n }
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
async function re(t) {
|
|
467
639
|
try {
|
|
468
|
-
const e = t.headers
|
|
469
|
-
|
|
640
|
+
const e = t.headers?.get("content-type");
|
|
641
|
+
if (e && e.includes("application/json")) {
|
|
642
|
+
const r = await t.json();
|
|
643
|
+
return { parsed: ke(r), raw: r };
|
|
644
|
+
}
|
|
645
|
+
return { parsed: null, raw: void 0 };
|
|
470
646
|
} catch {
|
|
471
|
-
return null;
|
|
647
|
+
return { parsed: null, raw: void 0 };
|
|
472
648
|
}
|
|
473
649
|
}
|
|
474
|
-
async function
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
}
|
|
650
|
+
async function zt(t) {
|
|
651
|
+
return (await re(t)).parsed;
|
|
652
|
+
}
|
|
653
|
+
function $e(t) {
|
|
654
|
+
const e = {};
|
|
655
|
+
try {
|
|
656
|
+
t.headers?.forEach((r, o) => {
|
|
657
|
+
e[o.toLowerCase()] = r;
|
|
658
|
+
});
|
|
659
|
+
} catch {
|
|
530
660
|
}
|
|
531
|
-
|
|
532
|
-
|
|
661
|
+
return e;
|
|
662
|
+
}
|
|
663
|
+
function Ae(t) {
|
|
664
|
+
if (!t) return;
|
|
665
|
+
const e = Number(t);
|
|
666
|
+
if (Number.isFinite(e) && e >= 0) return e;
|
|
667
|
+
const r = Date.parse(t);
|
|
668
|
+
if (!Number.isNaN(r)) return Math.max(0, Math.ceil((r - Date.now()) / 1e3));
|
|
669
|
+
}
|
|
670
|
+
function N(t, e) {
|
|
671
|
+
const r = t.toUpperCase();
|
|
672
|
+
return e.some((o) => r.startsWith(o));
|
|
673
|
+
}
|
|
674
|
+
async function u(t, e, r, o) {
|
|
675
|
+
const { parsed: s, raw: n } = await re(t), i = t.headers?.get("x-request-id") || "", a = s?.error.message || e || `HTTP error! status: ${t.status}`, c = s?.metadata.request_id || i || "unknown", l = s?.metadata.timestamp || (/* @__PURE__ */ new Date()).toISOString(), y = s?.error.details || [], g = s?.error.code || "", b = Oe(t.status, g, a, c, l, y, {
|
|
676
|
+
retryAfter: Ae(t.headers?.get("retry-after")) ?? s?.error.retry_after_seconds,
|
|
677
|
+
endpoint: r,
|
|
678
|
+
method: o
|
|
679
|
+
});
|
|
680
|
+
return b.endpoint = r, b.method = o, b.responseHeaders = $e(t), n !== void 0 && (b.responseBody = n), b;
|
|
681
|
+
}
|
|
682
|
+
function Oe(t, e, r, o, s, n, i) {
|
|
683
|
+
if (N(e, ["RECURSION", "GRAPH_RECURSION"]))
|
|
684
|
+
return new _e(r, o, s, n);
|
|
685
|
+
if (N(e, ["GRAPH"]))
|
|
686
|
+
return new be(r, o, s, n);
|
|
687
|
+
if (N(e, ["NODE"]))
|
|
688
|
+
return new we(r, o, s, n);
|
|
689
|
+
if (N(e, ["STORAGE_TRANSIENT", "TRANSIENT_STORAGE"]))
|
|
690
|
+
return new Ee(r, o, s, n);
|
|
691
|
+
if (N(e, ["STORAGE_SCHEMA", "SCHEMA_VERSION"]))
|
|
692
|
+
return new Se(r, o, s, n);
|
|
693
|
+
if (N(e, ["STORAGE_SERIALIZATION", "SERIALIZATION"]))
|
|
694
|
+
return new Ge(r, o, s, n);
|
|
695
|
+
if (N(e, ["STORAGE"]))
|
|
696
|
+
return new Ce(r, o, s, n);
|
|
697
|
+
if (N(e, ["METRICS"]))
|
|
698
|
+
return new ve(r, o, s, n);
|
|
699
|
+
if (e === "VALIDATION_ERROR" || e === "AGENTFLOW_VALIDATION_ERROR")
|
|
700
|
+
return new Q(r, o, s, n);
|
|
701
|
+
switch (t) {
|
|
533
702
|
case 400:
|
|
534
|
-
return new
|
|
703
|
+
return new fe(r, o, s, n);
|
|
535
704
|
case 401:
|
|
536
|
-
return new
|
|
705
|
+
return new pe(r, o, s, n);
|
|
537
706
|
case 403:
|
|
538
|
-
return new
|
|
707
|
+
return new me(r, o, s, n);
|
|
539
708
|
case 404:
|
|
540
|
-
return new
|
|
709
|
+
return new ge(r, o, s, n);
|
|
710
|
+
case 409:
|
|
711
|
+
return new ye(r, o, s, n);
|
|
541
712
|
case 422:
|
|
542
|
-
return new
|
|
713
|
+
return new Q(r, o, s, n);
|
|
714
|
+
case 429:
|
|
715
|
+
return new Re(r, o, s, n, i.retryAfter);
|
|
543
716
|
case 500:
|
|
544
717
|
case 502:
|
|
545
718
|
case 503:
|
|
546
719
|
case 504:
|
|
547
|
-
return new
|
|
720
|
+
return new Te(
|
|
721
|
+
r,
|
|
722
|
+
o,
|
|
723
|
+
s,
|
|
724
|
+
e || "INTERNAL_SERVER_ERROR",
|
|
548
725
|
n,
|
|
549
|
-
|
|
550
|
-
i,
|
|
551
|
-
"INTERNAL_SERVER_ERROR",
|
|
552
|
-
[],
|
|
553
|
-
t.status
|
|
726
|
+
t
|
|
554
727
|
);
|
|
555
728
|
default:
|
|
556
|
-
return new
|
|
729
|
+
return new T(
|
|
730
|
+
r,
|
|
731
|
+
t,
|
|
732
|
+
e || "UNKNOWN_ERROR",
|
|
733
|
+
o,
|
|
734
|
+
s,
|
|
557
735
|
n,
|
|
558
|
-
t.status,
|
|
559
|
-
"UNKNOWN_ERROR",
|
|
560
|
-
"unknown",
|
|
561
|
-
i,
|
|
562
|
-
[],
|
|
563
736
|
void 0,
|
|
564
|
-
|
|
565
|
-
|
|
737
|
+
i.endpoint,
|
|
738
|
+
i.method
|
|
566
739
|
);
|
|
567
740
|
}
|
|
568
741
|
}
|
|
569
|
-
function
|
|
742
|
+
function K(t, e) {
|
|
743
|
+
if (!e) return () => {
|
|
744
|
+
};
|
|
745
|
+
if (e.aborted)
|
|
746
|
+
return t.abort(), () => {
|
|
747
|
+
};
|
|
748
|
+
const r = () => t.abort();
|
|
749
|
+
return e.addEventListener("abort", r, { once: !0 }), () => e.removeEventListener("abort", r);
|
|
750
|
+
}
|
|
751
|
+
function j(t, e, r) {
|
|
570
752
|
if (r != null) {
|
|
571
753
|
for (const o of Object.keys(t))
|
|
572
754
|
o.toLowerCase() === e.toLowerCase() && delete t[o];
|
|
573
755
|
t[e] = r;
|
|
574
756
|
}
|
|
575
757
|
}
|
|
576
|
-
function
|
|
758
|
+
function q(t, e) {
|
|
577
759
|
if (e) {
|
|
578
760
|
if (e instanceof Headers) {
|
|
579
761
|
e.forEach((r, o) => {
|
|
580
|
-
|
|
762
|
+
j(t, o, r);
|
|
581
763
|
});
|
|
582
764
|
return;
|
|
583
765
|
}
|
|
584
766
|
if (Array.isArray(e)) {
|
|
585
767
|
for (const [r, o] of e)
|
|
586
|
-
|
|
768
|
+
j(t, r, o);
|
|
587
769
|
return;
|
|
588
770
|
}
|
|
589
771
|
for (const [r, o] of Object.entries(e))
|
|
590
|
-
o !== void 0 &&
|
|
772
|
+
o !== void 0 && j(t, r, String(o));
|
|
591
773
|
}
|
|
592
774
|
}
|
|
593
|
-
function
|
|
775
|
+
function Ne(t, e) {
|
|
594
776
|
return Object.keys(t).some(
|
|
595
777
|
(r) => r.toLowerCase() === e.toLowerCase()
|
|
596
778
|
);
|
|
597
779
|
}
|
|
598
|
-
function
|
|
780
|
+
function Ie(t) {
|
|
599
781
|
const e = globalThis.Buffer;
|
|
600
782
|
if (e)
|
|
601
783
|
return e.from(t, "utf-8").toString("base64");
|
|
@@ -608,718 +790,878 @@ function oe(t) {
|
|
|
608
790
|
}
|
|
609
791
|
throw new Error("Basic authentication is not supported in this runtime");
|
|
610
792
|
}
|
|
611
|
-
function
|
|
793
|
+
function Ue(t, e) {
|
|
612
794
|
if (!e)
|
|
613
795
|
return;
|
|
614
796
|
if (e.type === "bearer") {
|
|
615
|
-
|
|
797
|
+
j(t, "Authorization", `Bearer ${e.token}`);
|
|
616
798
|
return;
|
|
617
799
|
}
|
|
618
800
|
if (e.type === "basic") {
|
|
619
|
-
const o =
|
|
620
|
-
|
|
801
|
+
const o = Ie(`${e.username}:${e.password}`);
|
|
802
|
+
j(t, "Authorization", `Basic ${o}`);
|
|
621
803
|
return;
|
|
622
804
|
}
|
|
623
805
|
const r = e.prefix ? `${e.prefix} ${e.value}` : e.value;
|
|
624
|
-
|
|
806
|
+
j(t, e.name, r);
|
|
625
807
|
}
|
|
626
|
-
function
|
|
808
|
+
function d(t, e) {
|
|
627
809
|
const r = {};
|
|
628
|
-
return
|
|
810
|
+
return q(r, e), q(r, t.headers), t.auth ? Ue(r, t.auth) : t.authToken && !Ne(r, "Authorization") && j(r, "Authorization", `Bearer ${t.authToken}`), r;
|
|
629
811
|
}
|
|
630
|
-
function
|
|
812
|
+
function h(t) {
|
|
631
813
|
return t.credentials ? { credentials: t.credentials } : {};
|
|
632
814
|
}
|
|
633
|
-
function
|
|
815
|
+
function Yt(t) {
|
|
634
816
|
return { type: "bearer", token: t };
|
|
635
817
|
}
|
|
636
|
-
function
|
|
818
|
+
function Kt(t, e) {
|
|
637
819
|
return { type: "basic", username: t, password: e };
|
|
638
820
|
}
|
|
639
|
-
function
|
|
821
|
+
function Xt(t, e, r) {
|
|
640
822
|
return { type: "header", name: t, value: e, prefix: r };
|
|
641
823
|
}
|
|
642
|
-
|
|
824
|
+
function E(t) {
|
|
825
|
+
return encodeURIComponent(String(t));
|
|
826
|
+
}
|
|
827
|
+
function je(t) {
|
|
828
|
+
let e = t.length;
|
|
829
|
+
for (; e > 0 && t.charCodeAt(e - 1) === 47; ) e--;
|
|
830
|
+
return t.slice(0, e);
|
|
831
|
+
}
|
|
832
|
+
const xe = 5;
|
|
833
|
+
function ee(t) {
|
|
834
|
+
try {
|
|
835
|
+
return new URL(t).origin;
|
|
836
|
+
} catch {
|
|
837
|
+
return null;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function J(t) {
|
|
841
|
+
try {
|
|
842
|
+
return new URL(t).pathname;
|
|
843
|
+
} catch {
|
|
844
|
+
return t;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
async function f(t, e, r = {}) {
|
|
848
|
+
const o = new AbortController(), s = t.timeout > 0 ? setTimeout(() => o.abort(), t.timeout) : void 0;
|
|
849
|
+
s?.unref?.();
|
|
850
|
+
const n = K(o, t.signal), i = (r.method || "GET").toUpperCase(), a = t.auth?.type === "header" && t.auth.name.toLowerCase() !== "authorization";
|
|
851
|
+
try {
|
|
852
|
+
let c = e, l = { ...r, signal: o.signal };
|
|
853
|
+
a && (l.redirect = "manual");
|
|
854
|
+
for (let y = 0; ; y++) {
|
|
855
|
+
const g = await fetch(c, l);
|
|
856
|
+
if (a && g.type === "opaqueredirect")
|
|
857
|
+
throw new D(
|
|
858
|
+
"The server redirected the request and the browser does not expose the target, so it was not followed (header credentials must not be sent to another origin). Point baseUrl at the final URL.",
|
|
859
|
+
J(e),
|
|
860
|
+
i
|
|
861
|
+
);
|
|
862
|
+
if (!a || !(g.status >= 300 && g.status < 400))
|
|
863
|
+
return g;
|
|
864
|
+
const b = g.headers?.get("location"), G = b ? new URL(b, c).toString() : null;
|
|
865
|
+
if (!G || ee(G) !== ee(e) || y >= xe)
|
|
866
|
+
throw new D(
|
|
867
|
+
"Refusing to follow a redirect that leaves the base URL origin (credentials would be forwarded)",
|
|
868
|
+
J(e),
|
|
869
|
+
i
|
|
870
|
+
);
|
|
871
|
+
c = G, g.status === 303 && (l = { ...l, method: "GET", body: void 0 });
|
|
872
|
+
}
|
|
873
|
+
} catch (c) {
|
|
874
|
+
if (c instanceof T) throw c;
|
|
875
|
+
if (c?.name === "AbortError")
|
|
876
|
+
throw t.signal?.aborted ? c : new M(t.timeout, J(e), i, c);
|
|
877
|
+
const y = c instanceof Error ? c.message : String(c);
|
|
878
|
+
throw new D(`Network request failed: ${y}`, J(e), i, c);
|
|
879
|
+
} finally {
|
|
880
|
+
s !== void 0 && clearTimeout(s), n();
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
async function Pe(t) {
|
|
643
884
|
try {
|
|
644
885
|
t.debug && console.debug("TenxGraphClient: Pinging server at", t.baseUrl);
|
|
645
|
-
const e =
|
|
886
|
+
const e = await f(t, `${t.baseUrl}/ping`, {
|
|
646
887
|
method: "GET",
|
|
647
|
-
headers:
|
|
888
|
+
headers: d(t, {
|
|
648
889
|
"Content-Type": "application/json"
|
|
649
890
|
}),
|
|
650
|
-
...
|
|
651
|
-
signal: e.signal
|
|
891
|
+
...h(t)
|
|
652
892
|
});
|
|
653
|
-
if (
|
|
654
|
-
throw console.warn(`TenxGraphClient: Ping failed with HTTP ${
|
|
655
|
-
const
|
|
656
|
-
return t.debug && console.info("TenxGraphClient: Ping successful",
|
|
893
|
+
if (!e.ok)
|
|
894
|
+
throw console.warn(`TenxGraphClient: Ping failed with HTTP ${e.status}`), await u(e, "Ping request failed", "/ping", "GET");
|
|
895
|
+
const r = await e.json();
|
|
896
|
+
return t.debug && console.info("TenxGraphClient: Ping successful", r), r;
|
|
657
897
|
} catch (e) {
|
|
658
|
-
throw t.debug && console.debug("TenxGraphClient: Ping failed:", e),
|
|
898
|
+
throw t.debug && console.debug("TenxGraphClient: Ping failed:", e), console.error("TenxGraphClient: Ping failed:", e), e;
|
|
659
899
|
}
|
|
660
900
|
}
|
|
661
|
-
async function
|
|
901
|
+
async function Le(t) {
|
|
662
902
|
try {
|
|
663
903
|
t.debug && console.debug("TenxGraphClient: Fetching graph from", t.baseUrl);
|
|
664
|
-
const e =
|
|
904
|
+
const e = await f(t, `${t.baseUrl}/v1/graph`, {
|
|
665
905
|
method: "GET",
|
|
666
|
-
headers:
|
|
906
|
+
headers: d(t, {
|
|
667
907
|
"Content-Type": "application/json",
|
|
668
908
|
accept: "application/json"
|
|
669
909
|
}),
|
|
670
|
-
...
|
|
671
|
-
signal: e.signal
|
|
910
|
+
...h(t)
|
|
672
911
|
});
|
|
673
|
-
if (
|
|
674
|
-
throw console.warn(`TenxGraphClient: Graph fetch failed with HTTP ${
|
|
675
|
-
|
|
912
|
+
if (!e.ok)
|
|
913
|
+
throw console.warn(`TenxGraphClient: Graph fetch failed with HTTP ${e.status}`), await u(
|
|
914
|
+
e,
|
|
676
915
|
"Graph fetch failed",
|
|
677
916
|
"/v1/graph",
|
|
678
917
|
"GET"
|
|
679
918
|
);
|
|
680
|
-
const
|
|
681
|
-
return t.debug && console.info("TenxGraphClient: Graph fetch successful",
|
|
919
|
+
const r = await e.json();
|
|
920
|
+
return t.debug && console.info("TenxGraphClient: Graph fetch successful", r), r;
|
|
682
921
|
} catch (e) {
|
|
683
|
-
throw t.debug && console.debug("TenxGraphClient: Graph fetch failed:", e),
|
|
922
|
+
throw t.debug && console.debug("TenxGraphClient: Graph fetch failed:", e), console.error("TenxGraphClient: Graph fetch failed:", e), e;
|
|
684
923
|
}
|
|
685
924
|
}
|
|
686
|
-
async function
|
|
925
|
+
async function De(t) {
|
|
687
926
|
try {
|
|
688
927
|
t.debug && console.debug("TenxGraphClient: Fetching graph tools from", t.baseUrl);
|
|
689
|
-
const e =
|
|
928
|
+
const e = await f(t, `${t.baseUrl}/v1/graph/tools`, {
|
|
690
929
|
method: "GET",
|
|
691
|
-
headers:
|
|
930
|
+
headers: d(t, {
|
|
692
931
|
"Content-Type": "application/json",
|
|
693
932
|
accept: "application/json"
|
|
694
933
|
}),
|
|
695
|
-
...
|
|
696
|
-
signal: e.signal
|
|
934
|
+
...h(t)
|
|
697
935
|
});
|
|
698
|
-
if (
|
|
699
|
-
throw console.warn(`TenxGraphClient: Graph tools fetch failed with HTTP ${
|
|
700
|
-
|
|
936
|
+
if (!e.ok)
|
|
937
|
+
throw console.warn(`TenxGraphClient: Graph tools fetch failed with HTTP ${e.status}`), await u(
|
|
938
|
+
e,
|
|
701
939
|
"Graph tools fetch failed",
|
|
702
940
|
"/v1/graph/tools",
|
|
703
941
|
"GET"
|
|
704
942
|
);
|
|
705
|
-
const
|
|
706
|
-
return t.debug && console.info("TenxGraphClient: Graph tools fetch successful",
|
|
943
|
+
const r = await e.json();
|
|
944
|
+
return t.debug && console.info("TenxGraphClient: Graph tools fetch successful", r), r;
|
|
707
945
|
} catch (e) {
|
|
708
|
-
throw t.debug && console.debug("TenxGraphClient: Graph tools fetch failed:", e),
|
|
946
|
+
throw t.debug && console.debug("TenxGraphClient: Graph tools fetch failed:", e), console.error("TenxGraphClient: Graph tools fetch failed:", e), e;
|
|
709
947
|
}
|
|
710
948
|
}
|
|
711
|
-
async function
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
949
|
+
async function Me(t, e, r) {
|
|
950
|
+
const o = r ? `?run_id=${encodeURIComponent(r)}` : "", s = await f(
|
|
951
|
+
t,
|
|
952
|
+
`${t.baseUrl}/v1/observability/${encodeURIComponent(e)}${o}`,
|
|
953
|
+
{
|
|
954
|
+
method: "GET",
|
|
955
|
+
headers: d(t, {
|
|
956
|
+
"Content-Type": "application/json",
|
|
957
|
+
accept: "application/json"
|
|
958
|
+
}),
|
|
959
|
+
...h(t)
|
|
960
|
+
}
|
|
961
|
+
);
|
|
962
|
+
if (!s.ok)
|
|
963
|
+
throw await u(
|
|
964
|
+
s,
|
|
965
|
+
"Observability fetch failed",
|
|
966
|
+
`/v1/observability/${e}`,
|
|
967
|
+
"GET"
|
|
724
968
|
);
|
|
725
|
-
|
|
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
|
-
}
|
|
969
|
+
return await s.json();
|
|
736
970
|
}
|
|
737
|
-
async function
|
|
971
|
+
async function Fe(t) {
|
|
738
972
|
try {
|
|
739
973
|
t.debug && console.debug("TenxGraphClient: Fetching state schema from", t.baseUrl);
|
|
740
|
-
const e =
|
|
974
|
+
const e = await f(t, `${t.baseUrl}/v1/graph:StateSchema`, {
|
|
741
975
|
method: "GET",
|
|
742
|
-
headers:
|
|
976
|
+
headers: d(t, {
|
|
743
977
|
"Content-Type": "application/json",
|
|
744
978
|
accept: "application/json"
|
|
745
979
|
}),
|
|
746
|
-
...
|
|
747
|
-
signal: e.signal
|
|
980
|
+
...h(t)
|
|
748
981
|
});
|
|
749
|
-
if (
|
|
750
|
-
throw console.warn(`TenxGraphClient: State schema fetch failed with HTTP ${
|
|
751
|
-
|
|
982
|
+
if (!e.ok)
|
|
983
|
+
throw console.warn(`TenxGraphClient: State schema fetch failed with HTTP ${e.status}`), await u(
|
|
984
|
+
e,
|
|
752
985
|
"State schema fetch failed",
|
|
753
986
|
"/v1/state_schema",
|
|
754
987
|
"GET"
|
|
755
988
|
);
|
|
756
|
-
const
|
|
757
|
-
return t.debug && console.info("TenxGraphClient: State schema fetch successful",
|
|
989
|
+
const r = await e.json();
|
|
990
|
+
return t.debug && console.info("TenxGraphClient: State schema fetch successful", r), r;
|
|
758
991
|
} catch (e) {
|
|
759
|
-
throw t.debug && console.debug("TenxGraphClient: State schema fetch failed:", e),
|
|
992
|
+
throw t.debug && console.debug("TenxGraphClient: State schema fetch failed:", e), console.error("TenxGraphClient: State schema fetch failed:", e), e;
|
|
760
993
|
}
|
|
761
994
|
}
|
|
762
|
-
async function
|
|
995
|
+
async function Be(t, e) {
|
|
763
996
|
try {
|
|
764
997
|
t.debug && console.debug(`TenxGraphClient: Fetching thread state for thread ${e}`);
|
|
765
|
-
const r =
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
998
|
+
const r = await f(
|
|
999
|
+
t,
|
|
1000
|
+
`${t.baseUrl}/v1/threads/${E(e)}/state`,
|
|
1001
|
+
{
|
|
1002
|
+
method: "GET",
|
|
1003
|
+
headers: d(t, {
|
|
1004
|
+
"Content-Type": "application/json",
|
|
1005
|
+
accept: "application/json"
|
|
1006
|
+
}),
|
|
1007
|
+
...h(t)
|
|
1008
|
+
}
|
|
1009
|
+
);
|
|
1010
|
+
if (!r.ok)
|
|
1011
|
+
throw console.warn(`TenxGraphClient: Thread state fetch failed with HTTP ${r.status}`), await u(
|
|
1012
|
+
r,
|
|
777
1013
|
"Thread state fetch failed",
|
|
778
1014
|
"/v1/threads/{thread_id}/state",
|
|
779
1015
|
"GET"
|
|
780
1016
|
);
|
|
781
|
-
const
|
|
1017
|
+
const o = await r.json();
|
|
782
1018
|
return t.debug && console.info(
|
|
783
1019
|
`TenxGraphClient: Thread state fetched successfully for thread ${e}`,
|
|
784
|
-
|
|
785
|
-
),
|
|
1020
|
+
o
|
|
1021
|
+
), o;
|
|
786
1022
|
} catch (r) {
|
|
787
|
-
throw
|
|
1023
|
+
throw t.debug && console.debug("TenxGraphClient: Thread state fetch failed:", r), r;
|
|
788
1024
|
}
|
|
789
1025
|
}
|
|
790
|
-
async function
|
|
1026
|
+
async function He(t, e, r) {
|
|
791
1027
|
try {
|
|
792
1028
|
t.debug && (console.debug(`TenxGraphClient: Updating thread state for thread ${e}`), console.debug("TenxGraphClient: Request payload:", JSON.stringify(r, null, 2)));
|
|
793
|
-
const o =
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1029
|
+
const o = await f(
|
|
1030
|
+
t,
|
|
1031
|
+
`${t.baseUrl}/v1/threads/${E(e)}/state`,
|
|
1032
|
+
{
|
|
1033
|
+
method: "PUT",
|
|
1034
|
+
headers: d(t, {
|
|
1035
|
+
"Content-Type": "application/json",
|
|
1036
|
+
accept: "application/json"
|
|
1037
|
+
}),
|
|
1038
|
+
...h(t),
|
|
1039
|
+
body: JSON.stringify(r)
|
|
1040
|
+
}
|
|
1041
|
+
);
|
|
1042
|
+
if (!o.ok)
|
|
1043
|
+
throw console.warn(`TenxGraphClient: Thread state update failed with HTTP ${o.status}`), await u(
|
|
1044
|
+
o,
|
|
806
1045
|
"Thread state update failed",
|
|
807
1046
|
"/v1/threads/{thread_id}/state",
|
|
808
1047
|
"PUT"
|
|
809
1048
|
);
|
|
810
|
-
const
|
|
1049
|
+
const s = await o.json();
|
|
811
1050
|
return t.debug && console.info(
|
|
812
1051
|
`TenxGraphClient: Thread state updated successfully for thread ${e}`,
|
|
813
|
-
|
|
814
|
-
),
|
|
1052
|
+
s
|
|
1053
|
+
), s;
|
|
815
1054
|
} catch (o) {
|
|
816
|
-
throw
|
|
1055
|
+
throw t.debug && console.debug("TenxGraphClient: Thread state update failed:", o), o;
|
|
817
1056
|
}
|
|
818
1057
|
}
|
|
819
|
-
async function
|
|
1058
|
+
async function Je(t, e) {
|
|
820
1059
|
try {
|
|
821
1060
|
t.debug && console.debug(`TenxGraphClient: Clearing thread state for thread ${e}`);
|
|
822
|
-
const r =
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1061
|
+
const r = await f(
|
|
1062
|
+
t,
|
|
1063
|
+
`${t.baseUrl}/v1/threads/${E(e)}/state`,
|
|
1064
|
+
{
|
|
1065
|
+
method: "DELETE",
|
|
1066
|
+
headers: d(t, {
|
|
1067
|
+
"Content-Type": "application/json",
|
|
1068
|
+
accept: "application/json"
|
|
1069
|
+
}),
|
|
1070
|
+
...h(t)
|
|
1071
|
+
}
|
|
1072
|
+
);
|
|
1073
|
+
if (!r.ok)
|
|
1074
|
+
throw console.warn(`TenxGraphClient: Thread state clear failed with HTTP ${r.status}`), await u(
|
|
1075
|
+
r,
|
|
834
1076
|
"Thread state clear failed",
|
|
835
1077
|
"/v1/threads/{thread_id}/state",
|
|
836
1078
|
"DELETE"
|
|
837
1079
|
);
|
|
838
|
-
const
|
|
1080
|
+
const o = await r.json();
|
|
839
1081
|
return t.debug && console.info(
|
|
840
1082
|
`TenxGraphClient: Thread state cleared successfully for thread ${e}`,
|
|
841
|
-
|
|
842
|
-
),
|
|
1083
|
+
o
|
|
1084
|
+
), o;
|
|
843
1085
|
} catch (r) {
|
|
844
|
-
throw
|
|
1086
|
+
throw t.debug && console.debug("TenxGraphClient: Thread state clear failed:", r), r;
|
|
845
1087
|
}
|
|
846
1088
|
}
|
|
847
|
-
async function
|
|
1089
|
+
async function oe(t, e) {
|
|
848
1090
|
try {
|
|
849
1091
|
t.debug && console.debug("TenxGraphClient: Fetching thread messages for thread", e.threadId);
|
|
850
|
-
const r = new
|
|
851
|
-
e.search !== void 0 &&
|
|
852
|
-
const
|
|
1092
|
+
const r = new URLSearchParams();
|
|
1093
|
+
e.search !== void 0 && r.append("search", e.search), e.offset !== void 0 && r.append("offset", e.offset.toString()), e.limit !== void 0 && r.append("limit", e.limit.toString());
|
|
1094
|
+
const o = r.toString(), s = `${t.baseUrl}/v1/threads/${E(e.threadId)}/messages${o ? "?" + o : ""}`, n = await f(t, s, {
|
|
853
1095
|
method: "GET",
|
|
854
|
-
headers:
|
|
1096
|
+
headers: d(t, {
|
|
855
1097
|
"Content-Type": "application/json"
|
|
856
1098
|
}),
|
|
857
|
-
...
|
|
858
|
-
signal: r.signal
|
|
1099
|
+
...h(t)
|
|
859
1100
|
});
|
|
860
|
-
if (
|
|
1101
|
+
if (!n.ok)
|
|
861
1102
|
throw console.warn(
|
|
862
|
-
`TenxGraphClient: Checkpoint messages fetch failed with HTTP ${
|
|
863
|
-
), await
|
|
864
|
-
|
|
1103
|
+
`TenxGraphClient: Checkpoint messages fetch failed with HTTP ${n.status}`
|
|
1104
|
+
), await u(
|
|
1105
|
+
n,
|
|
865
1106
|
"Thread messages fetch failed",
|
|
866
1107
|
"/v1/threads/{thread_id}/messages",
|
|
867
1108
|
"GET"
|
|
868
1109
|
);
|
|
869
|
-
const
|
|
870
|
-
return t.debug && console.info("TenxGraphClient: Thread messages fetched successfully",
|
|
1110
|
+
const i = await n.json();
|
|
1111
|
+
return t.debug && console.info("TenxGraphClient: Thread messages fetched successfully", i), i;
|
|
871
1112
|
} catch (r) {
|
|
872
1113
|
throw t.debug && console.debug("TenxGraphClient: Checkpoint messages fetch failed:", r), r;
|
|
873
1114
|
}
|
|
874
1115
|
}
|
|
875
|
-
const
|
|
876
|
-
|
|
1116
|
+
const Zt = oe;
|
|
1117
|
+
var W = /* @__PURE__ */ ((t) => (t.MESSAGE = "message", t.UPDATES = "updates", t.STATE = "state", t.ERROR = "error", t))(W || {});
|
|
1118
|
+
const L = "/v1/graph/stream";
|
|
1119
|
+
async function* We(t, e, r) {
|
|
1120
|
+
const o = new TextDecoder();
|
|
1121
|
+
let s = "", n = !1;
|
|
1122
|
+
try {
|
|
1123
|
+
for (; ; ) {
|
|
1124
|
+
let i;
|
|
1125
|
+
r?.beforeRead();
|
|
1126
|
+
try {
|
|
1127
|
+
i = await t.read();
|
|
1128
|
+
} catch (y) {
|
|
1129
|
+
throw y?.name === "AbortError" ? y : new V(
|
|
1130
|
+
`Stream connection lost: ${y?.message ?? String(y)}`,
|
|
1131
|
+
"STREAM_INTERRUPTED",
|
|
1132
|
+
"unknown",
|
|
1133
|
+
L,
|
|
1134
|
+
"POST",
|
|
1135
|
+
y
|
|
1136
|
+
);
|
|
1137
|
+
} finally {
|
|
1138
|
+
r?.afterRead();
|
|
1139
|
+
}
|
|
1140
|
+
const { done: a, value: c } = i;
|
|
1141
|
+
if (a) {
|
|
1142
|
+
s += o.decode(), s.trim() && (yield* te(s, e, !0)), n = !0;
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
s += o.decode(c, { stream: !0 }), s = (yield* te(s, e, !1)).remaining;
|
|
1146
|
+
}
|
|
1147
|
+
} finally {
|
|
1148
|
+
if (!n)
|
|
1149
|
+
try {
|
|
1150
|
+
await t.cancel();
|
|
1151
|
+
} catch {
|
|
1152
|
+
}
|
|
1153
|
+
t.releaseLock();
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
function Y(t, e) {
|
|
1157
|
+
return new V(
|
|
1158
|
+
`Stream data could not be parsed (${t.slice(0, 100)}); the stream was cut or corrupted`,
|
|
1159
|
+
"STREAM_TRUNCATED",
|
|
1160
|
+
"unknown",
|
|
1161
|
+
L,
|
|
1162
|
+
"POST",
|
|
1163
|
+
e
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
function* te(t, e, r) {
|
|
1167
|
+
for (; t.includes(`
|
|
1168
|
+
`); ) {
|
|
1169
|
+
const o = t.indexOf(`
|
|
1170
|
+
`), s = t.slice(0, o).trim();
|
|
1171
|
+
if (t = t.slice(o + 1), s)
|
|
1172
|
+
try {
|
|
1173
|
+
const n = JSON.parse(s);
|
|
1174
|
+
e && console.debug("TenxGraphClient: Stream chunk received (NDJSON):", n.event), yield n;
|
|
1175
|
+
} catch (n) {
|
|
1176
|
+
throw Y(s, n);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
for (; t.trim(); ) {
|
|
1180
|
+
const o = Ve(t);
|
|
1181
|
+
if (o)
|
|
1182
|
+
try {
|
|
1183
|
+
const s = JSON.parse(o.json);
|
|
1184
|
+
e && console.debug("TenxGraphClient: Stream chunk received (concat):", s.event), yield s, t = o.remaining;
|
|
1185
|
+
} catch (s) {
|
|
1186
|
+
throw Y(o.json, s);
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
if (r && t.trim())
|
|
1190
|
+
try {
|
|
1191
|
+
const s = JSON.parse(t.trim());
|
|
1192
|
+
e && console.debug("TenxGraphClient: Final stream chunk:", s.event), yield s, t = "";
|
|
1193
|
+
} catch (s) {
|
|
1194
|
+
throw Y(t.trim(), s);
|
|
1195
|
+
}
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return { remaining: t };
|
|
1200
|
+
}
|
|
1201
|
+
function Ve(t) {
|
|
1202
|
+
if (t = t.trim(), !t || t[0] !== "{")
|
|
1203
|
+
return null;
|
|
1204
|
+
let e = 0, r = !1, o = !1;
|
|
1205
|
+
for (let s = 0; s < t.length; s++) {
|
|
1206
|
+
const n = t[s];
|
|
1207
|
+
if (o) {
|
|
1208
|
+
o = !1;
|
|
1209
|
+
continue;
|
|
1210
|
+
}
|
|
1211
|
+
if (n === "\\") {
|
|
1212
|
+
o = !0;
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1215
|
+
if (n === '"') {
|
|
1216
|
+
r = !r;
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
if (!r) {
|
|
1220
|
+
if (n === "{")
|
|
1221
|
+
e++;
|
|
1222
|
+
else if (n === "}" && (e--, e === 0))
|
|
1223
|
+
return {
|
|
1224
|
+
json: t.slice(0, s + 1),
|
|
1225
|
+
remaining: t.slice(s + 1).trim()
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return null;
|
|
1230
|
+
}
|
|
1231
|
+
function ze(t) {
|
|
1232
|
+
return t.some(
|
|
1233
|
+
(e) => e.content && e.content.some((r) => r.type === "remote_tool_call")
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
async function* Ye(t, e) {
|
|
1237
|
+
const r = e.recursion_limit ?? 25, o = Math.max(1, r), s = t.timeout > 0 ? t.timeout : 0;
|
|
1238
|
+
t.debug && (console.debug("TenxGraphClient: Starting stream invoke with recursion_limit:", r), console.debug("TenxGraphClient: Initial request:", JSON.stringify(e, null, 2)));
|
|
1239
|
+
let n = e.messages, i = 0;
|
|
1240
|
+
const a = e.initial_state;
|
|
1241
|
+
let c = e.config;
|
|
1242
|
+
const l = e.response_granularity, y = e.on_busy, g = e.resume, b = e.interrupt_id;
|
|
1243
|
+
for (; ; ) {
|
|
1244
|
+
t.signal?.throwIfAborted(), i++, t.debug && console.debug(`TenxGraphClient: Stream iteration ${i}/${o}`);
|
|
1245
|
+
const G = {
|
|
1246
|
+
messages: n,
|
|
1247
|
+
initial_state: i === 1 ? a : void 0,
|
|
1248
|
+
config: c,
|
|
1249
|
+
recursion_limit: r,
|
|
1250
|
+
on_busy: y,
|
|
1251
|
+
resume: i === 1 ? g : void 0,
|
|
1252
|
+
interrupt_id: i === 1 ? b : void 0,
|
|
1253
|
+
response_granularity: l
|
|
1254
|
+
};
|
|
1255
|
+
t.debug && console.debug(
|
|
1256
|
+
"TenxGraphClient: Stream request payload:",
|
|
1257
|
+
JSON.stringify(G, null, 2)
|
|
1258
|
+
);
|
|
1259
|
+
const m = new AbortController();
|
|
1260
|
+
let v;
|
|
1261
|
+
const $ = () => {
|
|
1262
|
+
v !== void 0 && clearTimeout(v), v = void 0;
|
|
1263
|
+
}, S = () => {
|
|
1264
|
+
$(), s > 0 && (v = setTimeout(() => m.abort(), s));
|
|
1265
|
+
}, p = K(m, t.signal);
|
|
1266
|
+
let w = !1, R = !1;
|
|
1267
|
+
try {
|
|
1268
|
+
S();
|
|
1269
|
+
let _;
|
|
1270
|
+
try {
|
|
1271
|
+
_ = await fetch(`${t.baseUrl}${L}`, {
|
|
1272
|
+
method: "POST",
|
|
1273
|
+
headers: d(t, {
|
|
1274
|
+
"Content-Type": "application/json",
|
|
1275
|
+
Accept: "application/x-ndjson, application/json"
|
|
1276
|
+
}),
|
|
1277
|
+
...h(t),
|
|
1278
|
+
body: JSON.stringify(G),
|
|
1279
|
+
signal: m.signal
|
|
1280
|
+
});
|
|
1281
|
+
} catch (C) {
|
|
1282
|
+
throw C instanceof TypeError ? new D(`Network error: ${C.message}`, L, "POST", C) : C;
|
|
1283
|
+
}
|
|
1284
|
+
if ($(), !_.ok)
|
|
1285
|
+
throw console.warn(`TenxGraphClient: Stream failed with HTTP ${_.status}`), S(), await u(
|
|
1286
|
+
_,
|
|
1287
|
+
"Stream request failed",
|
|
1288
|
+
L,
|
|
1289
|
+
"POST"
|
|
1290
|
+
);
|
|
1291
|
+
if (!_.body)
|
|
1292
|
+
throw new Error("No response body for stream");
|
|
1293
|
+
const k = [], P = _.body.getReader();
|
|
1294
|
+
for await (const C of We(P, t.debug, {
|
|
1295
|
+
beforeRead: S,
|
|
1296
|
+
afterRead: $
|
|
1297
|
+
})) {
|
|
1298
|
+
yield C;
|
|
1299
|
+
const U = C.thread_id || C.metadata?.thread_id;
|
|
1300
|
+
U && !c?.thread_id && (c = { ...c ?? {}, thread_id: U }), C.event === "error" && (R = !0), C.message && k.push(C.message);
|
|
1301
|
+
}
|
|
1302
|
+
if (w = !0, t.debug && (console.info("TenxGraphClient: Stream iteration completed"), console.debug("TenxGraphClient: Received", k.length, "messages")), ze(k) && t.toolExecutor && !R) {
|
|
1303
|
+
if (i >= o) {
|
|
1304
|
+
t.debug && console.warn(`TenxGraphClient: Recursion limit of ${r} reached`), yield {
|
|
1305
|
+
event: "error",
|
|
1306
|
+
data: {
|
|
1307
|
+
recursion_limit_reached: !0,
|
|
1308
|
+
message: `Recursion limit of ${r} reached with tool calls still pending`
|
|
1309
|
+
},
|
|
1310
|
+
thread_id: c?.thread_id
|
|
1311
|
+
};
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
t.debug && console.debug("TenxGraphClient: Found remote tool calls, executing...");
|
|
1315
|
+
const C = await t.toolExecutor.executeToolCalls(k);
|
|
1316
|
+
t.debug && console.debug(`TenxGraphClient: Executed ${C.length} tool calls`), n = C.map((U) => x(U));
|
|
1317
|
+
continue;
|
|
1318
|
+
} else {
|
|
1319
|
+
t.debug && console.debug("TenxGraphClient: No remote tool calls found, finishing");
|
|
1320
|
+
break;
|
|
1321
|
+
}
|
|
1322
|
+
} catch (_) {
|
|
1323
|
+
throw _.name === "AbortError" ? t.signal?.aborted ? _ : (console.warn(`TenxGraphClient: Stream timeout after ${t.timeout}ms`), new M(t.timeout, L, "POST", _)) : (console.error("TenxGraphClient: Stream failed:", _), _);
|
|
1324
|
+
} finally {
|
|
1325
|
+
$(), p(), w || m.abort();
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
t.debug && console.debug(`TenxGraphClient: Stream invoke completed after ${i} iterations`);
|
|
1329
|
+
}
|
|
1330
|
+
function Ke(t) {
|
|
1331
|
+
return t.map((e) => {
|
|
1332
|
+
const r = {};
|
|
1333
|
+
for (const [o, s] of Object.entries(e))
|
|
1334
|
+
s !== void 0 && (r[o] = s);
|
|
1335
|
+
return r;
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
function x(t) {
|
|
1339
|
+
const e = {
|
|
1340
|
+
role: t.role,
|
|
1341
|
+
content: Ke(t.content)
|
|
1342
|
+
};
|
|
1343
|
+
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;
|
|
1344
|
+
}
|
|
1345
|
+
async function Xe(t, e) {
|
|
877
1346
|
try {
|
|
878
1347
|
t.debug && console.debug("TenxGraphClient: Adding thread messages to thread", e.threadId);
|
|
879
|
-
const r =
|
|
1348
|
+
const r = `${t.baseUrl}/v1/threads/${E(e.threadId)}/messages`, o = {
|
|
880
1349
|
config: e.config,
|
|
881
|
-
messages: e.messages,
|
|
1350
|
+
messages: e.messages.map((i) => x(i)),
|
|
882
1351
|
metadata: e.metadata || {}
|
|
883
|
-
},
|
|
1352
|
+
}, s = await f(t, r, {
|
|
884
1353
|
method: "POST",
|
|
885
|
-
headers:
|
|
1354
|
+
headers: d(t, {
|
|
886
1355
|
"Content-Type": "application/json"
|
|
887
1356
|
}),
|
|
888
|
-
...
|
|
889
|
-
body: JSON.stringify(
|
|
890
|
-
signal: r.signal
|
|
1357
|
+
...h(t),
|
|
1358
|
+
body: JSON.stringify(o)
|
|
891
1359
|
});
|
|
892
|
-
if (
|
|
893
|
-
throw console.warn(`TenxGraphClient: Add checkpoint messages failed with HTTP ${
|
|
894
|
-
|
|
1360
|
+
if (!s.ok)
|
|
1361
|
+
throw console.warn(`TenxGraphClient: Add checkpoint messages failed with HTTP ${s.status}`), await u(
|
|
1362
|
+
s,
|
|
895
1363
|
"Add thread messages failed",
|
|
896
1364
|
"/v1/threads/{thread_id}/messages",
|
|
897
1365
|
"POST"
|
|
898
1366
|
);
|
|
899
|
-
const
|
|
900
|
-
return t.debug && console.info("TenxGraphClient: Thread messages added successfully",
|
|
1367
|
+
const n = await s.json();
|
|
1368
|
+
return t.debug && console.info("TenxGraphClient: Thread messages added successfully", n), n;
|
|
901
1369
|
} catch (r) {
|
|
902
1370
|
throw t.debug && console.debug("TenxGraphClient: Add checkpoint messages failed:", r), r;
|
|
903
1371
|
}
|
|
904
1372
|
}
|
|
905
|
-
async function
|
|
1373
|
+
async function Ze(t, e) {
|
|
906
1374
|
try {
|
|
907
1375
|
t.debug && console.debug(
|
|
908
1376
|
"TenxGraphClient: Fetching thread message",
|
|
909
1377
|
`thread: ${e.threadId}`,
|
|
910
1378
|
`message: ${e.messageId}`
|
|
911
1379
|
);
|
|
912
|
-
const r =
|
|
1380
|
+
const r = `${t.baseUrl}/v1/threads/${E(e.threadId)}/messages/${E(e.messageId)}`, o = await f(t, r, {
|
|
913
1381
|
method: "GET",
|
|
914
|
-
headers:
|
|
1382
|
+
headers: d(t, {
|
|
915
1383
|
"Content-Type": "application/json"
|
|
916
1384
|
}),
|
|
917
|
-
...
|
|
918
|
-
signal: r.signal
|
|
1385
|
+
...h(t)
|
|
919
1386
|
});
|
|
920
|
-
if (
|
|
921
|
-
throw console.warn(`TenxGraphClient: Thread message fetch failed with HTTP ${
|
|
922
|
-
|
|
1387
|
+
if (!o.ok)
|
|
1388
|
+
throw console.warn(`TenxGraphClient: Thread message fetch failed with HTTP ${o.status}`), await u(
|
|
1389
|
+
o,
|
|
923
1390
|
"Thread message fetch failed",
|
|
924
1391
|
"/v1/threads/{thread_id}/messages/{message_id}",
|
|
925
1392
|
"GET"
|
|
926
1393
|
);
|
|
927
|
-
const
|
|
928
|
-
return t.debug && console.info("TenxGraphClient: Thread message fetched successfully",
|
|
1394
|
+
const s = await o.json();
|
|
1395
|
+
return t.debug && console.info("TenxGraphClient: Thread message fetched successfully", s), s;
|
|
929
1396
|
} catch (r) {
|
|
930
1397
|
throw t.debug && console.debug("TenxGraphClient: Thread message fetch failed:", r), r;
|
|
931
1398
|
}
|
|
932
1399
|
}
|
|
933
|
-
async function
|
|
1400
|
+
async function Qe(t, e) {
|
|
934
1401
|
try {
|
|
935
1402
|
t.debug && console.debug(`TenxGraphClient: Fetching thread details for thread ${e}`);
|
|
936
|
-
const r =
|
|
1403
|
+
const r = `${t.baseUrl}/v1/threads/${E(e)}`, o = await f(t, r, {
|
|
937
1404
|
method: "GET",
|
|
938
|
-
headers:
|
|
1405
|
+
headers: d(t, {
|
|
939
1406
|
"Content-Type": "application/json",
|
|
940
1407
|
accept: "application/json"
|
|
941
1408
|
}),
|
|
942
|
-
...
|
|
943
|
-
signal: r.signal
|
|
1409
|
+
...h(t)
|
|
944
1410
|
});
|
|
945
|
-
if (
|
|
946
|
-
throw console.warn(`TenxGraphClient: Thread details fetch failed with HTTP ${
|
|
947
|
-
|
|
1411
|
+
if (!o.ok)
|
|
1412
|
+
throw console.warn(`TenxGraphClient: Thread details fetch failed with HTTP ${o.status}`), await u(
|
|
1413
|
+
o,
|
|
948
1414
|
"Thread details fetch failed",
|
|
949
1415
|
"/v1/threads/{thread_id}",
|
|
950
1416
|
"GET"
|
|
951
1417
|
);
|
|
952
|
-
const
|
|
953
|
-
return t.debug && console.info("TenxGraphClient: Thread details fetched successfully",
|
|
1418
|
+
const s = await o.json();
|
|
1419
|
+
return t.debug && console.info("TenxGraphClient: Thread details fetched successfully", s), s;
|
|
954
1420
|
} catch (r) {
|
|
955
|
-
throw
|
|
1421
|
+
throw t.debug && console.debug("TenxGraphClient: Thread details fetch failed:", r), r;
|
|
956
1422
|
}
|
|
957
1423
|
}
|
|
958
|
-
async function
|
|
1424
|
+
async function qe(t, e) {
|
|
959
1425
|
try {
|
|
960
1426
|
t.debug && console.debug(
|
|
961
1427
|
"TenxGraphClient: Deleting thread message",
|
|
962
1428
|
`thread: ${e.threadId}`,
|
|
963
1429
|
`message: ${e.messageId}`
|
|
964
1430
|
);
|
|
965
|
-
const r =
|
|
1431
|
+
const r = `${t.baseUrl}/v1/threads/${E(e.threadId)}/messages/${E(e.messageId)}`, o = await f(t, r, {
|
|
966
1432
|
method: "DELETE",
|
|
967
|
-
headers:
|
|
1433
|
+
headers: d(t, {
|
|
968
1434
|
"Content-Type": "application/json",
|
|
969
1435
|
accept: "application/json"
|
|
970
1436
|
}),
|
|
971
|
-
...
|
|
972
|
-
body: JSON.stringify({ config: e.config || {} })
|
|
973
|
-
signal: r.signal
|
|
1437
|
+
...h(t),
|
|
1438
|
+
body: JSON.stringify({ config: e.config || {} })
|
|
974
1439
|
});
|
|
975
|
-
if (
|
|
976
|
-
throw console.warn(`TenxGraphClient: Delete thread message failed with HTTP ${
|
|
977
|
-
|
|
1440
|
+
if (!o.ok)
|
|
1441
|
+
throw console.warn(`TenxGraphClient: Delete thread message failed with HTTP ${o.status}`), await u(
|
|
1442
|
+
o,
|
|
978
1443
|
"Delete thread message failed",
|
|
979
1444
|
"/v1/threads/{thread_id}/messages/{message_id}",
|
|
980
1445
|
"DELETE"
|
|
981
1446
|
);
|
|
982
|
-
const
|
|
983
|
-
return t.debug && console.info("TenxGraphClient: Thread message deleted successfully",
|
|
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;
|
|
1447
|
+
const s = await o.json();
|
|
1448
|
+
return t.debug && console.info("TenxGraphClient: Thread message deleted successfully", s), s;
|
|
1010
1449
|
} catch (r) {
|
|
1011
|
-
throw
|
|
1450
|
+
throw t.debug && console.debug("TenxGraphClient: Delete thread message failed:", r), r;
|
|
1012
1451
|
}
|
|
1013
1452
|
}
|
|
1014
|
-
async function
|
|
1453
|
+
async function et(t, e) {
|
|
1015
1454
|
try {
|
|
1016
|
-
t.debug &&
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1455
|
+
t.debug && console.debug(
|
|
1456
|
+
"TenxGraphClient: Updating thread message feedback",
|
|
1457
|
+
`thread: ${e.threadId}`,
|
|
1458
|
+
`message: ${e.messageId}`
|
|
1459
|
+
);
|
|
1460
|
+
const r = `${t.baseUrl}/v1/threads/${E(e.threadId)}/messages/${E(e.messageId)}`, o = await f(t, r, {
|
|
1461
|
+
method: "PUT",
|
|
1462
|
+
headers: d(t, {
|
|
1022
1463
|
"Content-Type": "application/json",
|
|
1023
1464
|
accept: "application/json"
|
|
1024
1465
|
}),
|
|
1025
|
-
...
|
|
1026
|
-
|
|
1466
|
+
...h(t),
|
|
1467
|
+
body: JSON.stringify({ feedback: e.feedback })
|
|
1027
1468
|
});
|
|
1028
|
-
if (
|
|
1029
|
-
throw console.warn(
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
"
|
|
1469
|
+
if (!o.ok)
|
|
1470
|
+
throw console.warn(
|
|
1471
|
+
`TenxGraphClient: Update thread message feedback failed with HTTP ${o.status}`
|
|
1472
|
+
), await u(
|
|
1473
|
+
o,
|
|
1474
|
+
"Update thread message feedback failed",
|
|
1475
|
+
"/v1/threads/{thread_id}/messages/{message_id}",
|
|
1476
|
+
"PUT"
|
|
1034
1477
|
);
|
|
1035
|
-
const
|
|
1036
|
-
return t.debug &&
|
|
1478
|
+
const s = await o.json();
|
|
1479
|
+
return t.debug && console.info("TenxGraphClient: Thread message feedback updated successfully", s), s;
|
|
1037
1480
|
} catch (r) {
|
|
1038
|
-
throw
|
|
1481
|
+
throw t.debug && console.debug("TenxGraphClient: Update thread message feedback failed:", r), r;
|
|
1039
1482
|
}
|
|
1040
1483
|
}
|
|
1041
|
-
async function
|
|
1042
|
-
const r = new AbortController(), o = setTimeout(() => r.abort(), t.timeout);
|
|
1484
|
+
async function tt(t, e) {
|
|
1043
1485
|
try {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1486
|
+
t.debug && console.debug("TenxGraphClient: Deleting thread", `thread: ${e.threadId}`);
|
|
1487
|
+
const r = `${t.baseUrl}/v1/threads/${E(e.threadId)}`, o = await f(t, r, {
|
|
1488
|
+
method: "DELETE",
|
|
1489
|
+
headers: d(t, {
|
|
1047
1490
|
"Content-Type": "application/json",
|
|
1048
1491
|
accept: "application/json"
|
|
1049
1492
|
}),
|
|
1050
|
-
...
|
|
1051
|
-
body: JSON.stringify(e)
|
|
1052
|
-
signal: r.signal
|
|
1493
|
+
...h(t),
|
|
1494
|
+
body: JSON.stringify({ config: e.config || {} })
|
|
1053
1495
|
});
|
|
1054
|
-
if (
|
|
1055
|
-
throw console.warn(`TenxGraphClient:
|
|
1056
|
-
|
|
1057
|
-
"
|
|
1058
|
-
"/v1/
|
|
1059
|
-
"
|
|
1496
|
+
if (!o.ok)
|
|
1497
|
+
throw console.warn(`TenxGraphClient: Delete thread failed with HTTP ${o.status}`), await u(
|
|
1498
|
+
o,
|
|
1499
|
+
"Delete thread failed",
|
|
1500
|
+
"/v1/threads/{thread_id}",
|
|
1501
|
+
"DELETE"
|
|
1060
1502
|
);
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
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
|
-
}
|
|
1503
|
+
const s = await o.json();
|
|
1504
|
+
return t.debug && console.info("TenxGraphClient: Thread deleted successfully", s), s;
|
|
1505
|
+
} catch (r) {
|
|
1506
|
+
throw t.debug && console.debug("TenxGraphClient: Delete thread failed:", r), r;
|
|
1229
1507
|
}
|
|
1230
|
-
return null;
|
|
1231
1508
|
}
|
|
1232
|
-
function
|
|
1233
|
-
|
|
1234
|
-
(
|
|
1235
|
-
|
|
1509
|
+
async function rt(t, e) {
|
|
1510
|
+
try {
|
|
1511
|
+
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}`));
|
|
1512
|
+
const r = new URLSearchParams();
|
|
1513
|
+
e?.search && r.append("search", e.search), e?.offset !== void 0 && r.append("offset", e.offset.toString()), e?.limit !== void 0 && r.append("limit", e.limit.toString());
|
|
1514
|
+
const o = r.toString(), s = `${t.baseUrl}/v1/threads${o ? `?${o}` : ""}`, n = await f(t, s, {
|
|
1515
|
+
method: "GET",
|
|
1516
|
+
headers: d(t, {
|
|
1517
|
+
"Content-Type": "application/json",
|
|
1518
|
+
accept: "application/json"
|
|
1519
|
+
}),
|
|
1520
|
+
...h(t)
|
|
1521
|
+
});
|
|
1522
|
+
if (!n.ok)
|
|
1523
|
+
throw console.warn(`TenxGraphClient: Threads list fetch failed with HTTP ${n.status}`), await u(
|
|
1524
|
+
n,
|
|
1525
|
+
"Threads list fetch failed",
|
|
1526
|
+
"/v1/threads",
|
|
1527
|
+
"GET"
|
|
1528
|
+
);
|
|
1529
|
+
const i = await n.json();
|
|
1530
|
+
return t.debug && (console.info("TenxGraphClient: Threads list fetched successfully", i), console.debug(` Found ${i.data.threads.length} threads`)), i;
|
|
1531
|
+
} catch (r) {
|
|
1532
|
+
throw t.debug && console.debug("TenxGraphClient: Threads list fetch failed:", r), r;
|
|
1533
|
+
}
|
|
1236
1534
|
}
|
|
1237
|
-
async function
|
|
1238
|
-
const r =
|
|
1239
|
-
|
|
1240
|
-
|
|
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);
|
|
1535
|
+
async function ot(t, e) {
|
|
1536
|
+
const r = new AbortController(), o = t.timeout > 0 ? setTimeout(() => r.abort(), t.timeout) : void 0, s = K(r, t.signal);
|
|
1537
|
+
try {
|
|
1538
|
+
let n;
|
|
1256
1539
|
try {
|
|
1257
|
-
|
|
1540
|
+
n = await fetch(`${t.baseUrl}/v1/graph/invoke`, {
|
|
1258
1541
|
method: "POST",
|
|
1259
|
-
headers:
|
|
1542
|
+
headers: d(t, {
|
|
1260
1543
|
"Content-Type": "application/json",
|
|
1261
|
-
|
|
1544
|
+
accept: "application/json"
|
|
1262
1545
|
}),
|
|
1263
|
-
...
|
|
1264
|
-
body: JSON.stringify(
|
|
1265
|
-
signal:
|
|
1546
|
+
...h(t),
|
|
1547
|
+
body: JSON.stringify(e),
|
|
1548
|
+
signal: r.signal
|
|
1266
1549
|
});
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
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);
|
|
1550
|
+
} catch (a) {
|
|
1551
|
+
throw a instanceof TypeError ? new D(
|
|
1552
|
+
`Network error: ${a.message}`,
|
|
1553
|
+
"/v1/graph/invoke",
|
|
1554
|
+
"POST",
|
|
1555
|
+
a
|
|
1556
|
+
) : a;
|
|
1290
1557
|
}
|
|
1558
|
+
if (!n.ok)
|
|
1559
|
+
throw console.warn(`TenxGraphClient: Invoke failed with HTTP ${n.status}`), await u(
|
|
1560
|
+
n,
|
|
1561
|
+
"Invoke request failed",
|
|
1562
|
+
"/v1/graph/invoke",
|
|
1563
|
+
"POST"
|
|
1564
|
+
);
|
|
1565
|
+
const i = await n.json();
|
|
1566
|
+
if (!i || typeof i != "object" || !i.data || typeof i.data != "object")
|
|
1567
|
+
throw new V(
|
|
1568
|
+
"Invoke response had no data object",
|
|
1569
|
+
"INVALID_RESPONSE",
|
|
1570
|
+
"unknown",
|
|
1571
|
+
"/v1/graph/invoke",
|
|
1572
|
+
"POST"
|
|
1573
|
+
);
|
|
1574
|
+
return Array.isArray(i.data.messages) || (i.data.messages = []), i;
|
|
1575
|
+
} catch (n) {
|
|
1576
|
+
throw n.name === "AbortError" ? t.signal?.aborted ? n : (console.warn(`TenxGraphClient: Invoke timeout after ${t.timeout}ms`), new M(t.timeout, "/v1/graph/invoke", "POST", n)) : (console.error("TenxGraphClient: Invoke failed:", n), n);
|
|
1577
|
+
} finally {
|
|
1578
|
+
o !== void 0 && clearTimeout(o), s();
|
|
1291
1579
|
}
|
|
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
1580
|
}
|
|
1294
|
-
function
|
|
1295
|
-
return t.
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
Array.isArray(s) && s.length === 0 || s !== void 0 && (r[o] = s);
|
|
1299
|
-
return r;
|
|
1300
|
-
});
|
|
1581
|
+
function st(t) {
|
|
1582
|
+
return !t.data || !t.data.messages ? !1 : t.data.messages.some(
|
|
1583
|
+
(e) => e.content && e.content.some((r) => r.type === "remote_tool_call")
|
|
1584
|
+
);
|
|
1301
1585
|
}
|
|
1302
|
-
function
|
|
1303
|
-
const e =
|
|
1304
|
-
|
|
1305
|
-
|
|
1586
|
+
async function nt(t, e, r) {
|
|
1587
|
+
const o = e.recursion_limit ?? 25, s = Math.max(1, o);
|
|
1588
|
+
t.debug && (console.debug("TenxGraphClient: Starting invoke with recursion_limit:", o), console.debug("TenxGraphClient: Initial request:", JSON.stringify(e, null, 2)));
|
|
1589
|
+
const n = [];
|
|
1590
|
+
let i = e.messages, a = 0, c = !1, l;
|
|
1591
|
+
const y = e.initial_state;
|
|
1592
|
+
let g = e.config;
|
|
1593
|
+
const b = e.response_granularity, G = e.on_busy, m = e.resume, v = e.interrupt_id;
|
|
1594
|
+
for (; ; ) {
|
|
1595
|
+
t.signal?.throwIfAborted(), a++, t.debug && console.debug(`TenxGraphClient: Iteration ${a}/${s}`);
|
|
1596
|
+
const S = {
|
|
1597
|
+
messages: i,
|
|
1598
|
+
initial_state: a === 1 ? y : void 0,
|
|
1599
|
+
config: g,
|
|
1600
|
+
recursion_limit: o,
|
|
1601
|
+
on_busy: G,
|
|
1602
|
+
resume: a === 1 ? m : void 0,
|
|
1603
|
+
interrupt_id: a === 1 ? v : void 0,
|
|
1604
|
+
response_granularity: b
|
|
1605
|
+
};
|
|
1606
|
+
t.debug && console.debug("TenxGraphClient: Request payload:", JSON.stringify(S, null, 2));
|
|
1607
|
+
const p = await ot(t, S);
|
|
1608
|
+
l = p;
|
|
1609
|
+
const w = p.data.meta?.thread_id;
|
|
1610
|
+
w && !g?.thread_id && (g = { ...g ?? {}, thread_id: w }), t.debug && (console.info("TenxGraphClient: Invoke successful"), console.debug("TenxGraphClient: Response:", JSON.stringify(p, null, 2))), p.data.messages && n.push(...p.data.messages);
|
|
1611
|
+
const R = st(p), _ = R && !!t.toolExecutor && a < s;
|
|
1612
|
+
if (r) {
|
|
1613
|
+
const k = {
|
|
1614
|
+
iteration: a,
|
|
1615
|
+
messages: p.data.messages,
|
|
1616
|
+
state: p.data.state,
|
|
1617
|
+
context: p.data.context,
|
|
1618
|
+
summary: p.data.summary,
|
|
1619
|
+
meta: p.data.meta,
|
|
1620
|
+
has_tool_calls: R,
|
|
1621
|
+
is_final: !_
|
|
1622
|
+
};
|
|
1623
|
+
await r(k);
|
|
1624
|
+
}
|
|
1625
|
+
if (R && t.toolExecutor && a >= s) {
|
|
1626
|
+
c = !0, t.debug && console.warn(`TenxGraphClient: Recursion limit of ${o} reached`);
|
|
1627
|
+
break;
|
|
1628
|
+
}
|
|
1629
|
+
if (R && t.toolExecutor) {
|
|
1630
|
+
t.debug && console.debug("TenxGraphClient: Found remote tool calls, executing...");
|
|
1631
|
+
const k = await t.toolExecutor.executeToolCalls(p.data.messages);
|
|
1632
|
+
t.debug && console.debug(`TenxGraphClient: Executed ${k.length} tool calls`), n.push(...k), i = k.map((P) => x(P));
|
|
1633
|
+
continue;
|
|
1634
|
+
} else {
|
|
1635
|
+
t.debug && console.debug("TenxGraphClient: No remote tool calls found, finishing");
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
const $ = {
|
|
1640
|
+
messages: l?.data.messages || [],
|
|
1641
|
+
state: l?.data.state,
|
|
1642
|
+
context: l?.data.context,
|
|
1643
|
+
summary: l?.data.summary,
|
|
1644
|
+
meta: l?.data.meta || { is_new_thread: !1, thread_id: "" },
|
|
1645
|
+
all_messages: n,
|
|
1646
|
+
iterations: a,
|
|
1647
|
+
recursion_limit_reached: c
|
|
1306
1648
|
};
|
|
1307
|
-
return t.
|
|
1649
|
+
return t.debug && (console.debug(`TenxGraphClient: Invoke completed after ${a} iterations`), console.debug(`TenxGraphClient: Total messages: ${n.length}`)), $;
|
|
1308
1650
|
}
|
|
1309
|
-
const
|
|
1310
|
-
function
|
|
1651
|
+
const it = "10xgraph-bearer";
|
|
1652
|
+
function at(t) {
|
|
1311
1653
|
return t.auth ? t.auth.type === "bearer" ? t.auth.token : null : t.authToken ? t.authToken : null;
|
|
1312
1654
|
}
|
|
1313
|
-
function
|
|
1655
|
+
function se(t, e) {
|
|
1314
1656
|
return t.baseUrl.replace(/^https:/, "wss:").replace(/^http:/, "ws:").replace(/\/$/, "") + e;
|
|
1315
1657
|
}
|
|
1316
|
-
function
|
|
1658
|
+
function ne(t, e) {
|
|
1317
1659
|
const r = e.webSocketImpl ?? globalThis.WebSocket;
|
|
1318
1660
|
if (!r)
|
|
1319
1661
|
throw new Error(
|
|
1320
1662
|
"No WebSocket implementation available. In Node < 21 pass `webSocketImpl` in the client config (e.g. the `ws` package: `new TenxGraphClient({ ..., webSocketImpl: WebSocket })`)."
|
|
1321
1663
|
);
|
|
1322
|
-
const o =
|
|
1664
|
+
const o = at(e), s = o ? [it, o] : void 0, n = d(e), i = n.Authorization ?? n.authorization;
|
|
1323
1665
|
if (i)
|
|
1324
1666
|
try {
|
|
1325
1667
|
return new r(t, s, { headers: { Authorization: i } });
|
|
@@ -1327,103 +1669,160 @@ function M(t, e) {
|
|
|
1327
1669
|
}
|
|
1328
1670
|
return new r(t, s);
|
|
1329
1671
|
}
|
|
1330
|
-
|
|
1672
|
+
const I = "/v1/graph/ws";
|
|
1673
|
+
function ct(t) {
|
|
1331
1674
|
return t.some(
|
|
1332
1675
|
(e) => e.content && e.content.some((r) => r.type === "remote_tool_call")
|
|
1333
1676
|
);
|
|
1334
1677
|
}
|
|
1335
|
-
async function*
|
|
1336
|
-
|
|
1678
|
+
async function* lt(t, e) {
|
|
1679
|
+
t.signal?.throwIfAborted();
|
|
1680
|
+
const r = se(t, I);
|
|
1337
1681
|
t.debug && console.debug("TenxGraphClient [WS]: connecting to", r);
|
|
1338
|
-
const o =
|
|
1339
|
-
let
|
|
1340
|
-
const
|
|
1341
|
-
if (
|
|
1342
|
-
const
|
|
1343
|
-
|
|
1682
|
+
const o = ne(r, t), s = e.recursion_limit ?? 25, n = Math.max(1, s), i = t.timeout > 0 ? t.timeout : 0, a = [];
|
|
1683
|
+
let c = null;
|
|
1684
|
+
const l = (m) => {
|
|
1685
|
+
if (a.push(m), c) {
|
|
1686
|
+
const v = c;
|
|
1687
|
+
c = null, v();
|
|
1344
1688
|
}
|
|
1345
|
-
},
|
|
1346
|
-
|
|
1347
|
-
})
|
|
1348
|
-
|
|
1689
|
+
}, y = () => new Promise((m) => {
|
|
1690
|
+
a.length > 0 ? m() : c = m;
|
|
1691
|
+
}), g = async () => {
|
|
1692
|
+
let m;
|
|
1693
|
+
i > 0 && (m = setTimeout(() => l(new M(i, I, "WS")), i));
|
|
1349
1694
|
try {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
t.debug && console.warn("TenxGraphClient [WS]: failed to parse chunk:", l);
|
|
1695
|
+
await y();
|
|
1696
|
+
} finally {
|
|
1697
|
+
m !== void 0 && clearTimeout(m);
|
|
1354
1698
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1699
|
+
return a.shift();
|
|
1700
|
+
};
|
|
1701
|
+
o.addEventListener("message", (m) => {
|
|
1702
|
+
try {
|
|
1703
|
+
const v = JSON.parse(m.data);
|
|
1704
|
+
l(v);
|
|
1705
|
+
} catch (v) {
|
|
1706
|
+
l(
|
|
1707
|
+
new V(
|
|
1708
|
+
"WebSocket frame could not be parsed as JSON",
|
|
1709
|
+
"STREAM_TRUNCATED",
|
|
1710
|
+
"unknown",
|
|
1711
|
+
I,
|
|
1712
|
+
"WS",
|
|
1713
|
+
v
|
|
1714
|
+
)
|
|
1715
|
+
);
|
|
1363
1716
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
response_granularity: e.response_granularity
|
|
1717
|
+
}), o.addEventListener("error", () => {
|
|
1718
|
+
l(new B("WebSocket error", void 0, I));
|
|
1719
|
+
}), o.addEventListener("close", (m) => {
|
|
1720
|
+
t.debug && console.debug("TenxGraphClient [WS]: connection closed, code=", m.code), l({ closed: !0, code: m.code });
|
|
1721
|
+
});
|
|
1722
|
+
const b = () => {
|
|
1723
|
+
const m = new Error("The operation was aborted");
|
|
1724
|
+
return m.name = "AbortError", m;
|
|
1725
|
+
}, G = () => {
|
|
1726
|
+
l(b()), (o.readyState === 1 || o.readyState === 0) && o.close(1e3);
|
|
1375
1727
|
};
|
|
1728
|
+
t.signal?.addEventListener("abort", G, { once: !0 });
|
|
1376
1729
|
try {
|
|
1730
|
+
await new Promise((S, p) => {
|
|
1731
|
+
if (t.signal?.aborted) {
|
|
1732
|
+
p(b());
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
if (o.readyState === 1) {
|
|
1736
|
+
S();
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
let w;
|
|
1740
|
+
const R = () => {
|
|
1741
|
+
w !== void 0 && clearTimeout(w), o.removeEventListener("open", _), o.removeEventListener("error", k), o.removeEventListener("close", P), t.signal?.removeEventListener("abort", z);
|
|
1742
|
+
}, _ = () => {
|
|
1743
|
+
R(), S();
|
|
1744
|
+
}, k = () => {
|
|
1745
|
+
R(), p(new B("WebSocket connection failed", void 0, I));
|
|
1746
|
+
}, P = (C) => {
|
|
1747
|
+
R();
|
|
1748
|
+
const U = C?.code;
|
|
1749
|
+
p(
|
|
1750
|
+
new B(`WebSocket closed before it opened (code ${U})`, U, I)
|
|
1751
|
+
);
|
|
1752
|
+
}, z = () => {
|
|
1753
|
+
R(), p(b());
|
|
1754
|
+
};
|
|
1755
|
+
o.addEventListener("open", _), o.addEventListener("error", k), o.addEventListener("close", P), t.signal?.addEventListener("abort", z, { once: !0 }), i > 0 && (w = setTimeout(() => {
|
|
1756
|
+
R(), p(new M(i, I, "WS"));
|
|
1757
|
+
}, i));
|
|
1758
|
+
}), a.length = 0, t.debug && console.debug("TenxGraphClient [WS]: connected");
|
|
1759
|
+
let m = e.config?.thread_id, v = 0, $ = {
|
|
1760
|
+
invoke_type: "fresh",
|
|
1761
|
+
messages: e.messages,
|
|
1762
|
+
initial_state: e.initial_state,
|
|
1763
|
+
config: e.config,
|
|
1764
|
+
recursion_limit: s,
|
|
1765
|
+
on_busy: e.on_busy,
|
|
1766
|
+
resume: e.resume,
|
|
1767
|
+
interrupt_id: e.interrupt_id,
|
|
1768
|
+
response_granularity: e.response_granularity
|
|
1769
|
+
};
|
|
1377
1770
|
e: for (; ; ) {
|
|
1378
|
-
t.debug && console.debug(
|
|
1379
|
-
`TenxGraphClient [WS]: sending ${
|
|
1380
|
-
), o.send(JSON.stringify(
|
|
1381
|
-
const
|
|
1771
|
+
v++, t.debug && console.debug(
|
|
1772
|
+
`TenxGraphClient [WS]: sending ${$.invoke_type} request, thread_id=${m ?? "new"}`
|
|
1773
|
+
), o.send(JSON.stringify($));
|
|
1774
|
+
const S = [];
|
|
1382
1775
|
t: for (; ; ) {
|
|
1383
|
-
await
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
if (
|
|
1776
|
+
const p = await g();
|
|
1777
|
+
if ("closed" in p)
|
|
1778
|
+
throw new B(
|
|
1779
|
+
`WebSocket closed before the run finished (code ${p.code})`,
|
|
1780
|
+
p.code,
|
|
1781
|
+
I
|
|
1782
|
+
);
|
|
1783
|
+
if (p instanceof Error)
|
|
1784
|
+
throw p;
|
|
1785
|
+
const w = p;
|
|
1786
|
+
if (w.thread_id && (m = w.thread_id), w.metadata?.thread_id && (m = w.metadata.thread_id), w.event === W.UPDATES && w.data?.status === "done")
|
|
1391
1787
|
break t;
|
|
1392
|
-
|
|
1788
|
+
if (w.message && S.push(w.message), yield w, w.event === W.ERROR)
|
|
1789
|
+
break e;
|
|
1393
1790
|
}
|
|
1394
1791
|
if (t.debug && console.debug(
|
|
1395
|
-
`TenxGraphClient [WS]: run complete, ${
|
|
1396
|
-
),
|
|
1792
|
+
`TenxGraphClient [WS]: run complete, ${S.length} messages collected`
|
|
1793
|
+
), ct(S) && t.toolExecutor) {
|
|
1794
|
+
if (v >= n) {
|
|
1795
|
+
t.debug && console.warn(`TenxGraphClient [WS]: recursion limit of ${s} reached`), yield {
|
|
1796
|
+
event: W.ERROR,
|
|
1797
|
+
data: {
|
|
1798
|
+
recursion_limit_reached: !0,
|
|
1799
|
+
message: `Recursion limit of ${s} reached with tool calls still pending`
|
|
1800
|
+
},
|
|
1801
|
+
thread_id: m
|
|
1802
|
+
};
|
|
1803
|
+
break e;
|
|
1804
|
+
}
|
|
1397
1805
|
t.debug && console.debug("TenxGraphClient [WS]: remote tool calls detected, executing…");
|
|
1398
|
-
const
|
|
1806
|
+
const p = await t.toolExecutor.executeToolCalls(S);
|
|
1399
1807
|
t.debug && console.debug(
|
|
1400
|
-
`TenxGraphClient [WS]: ${
|
|
1401
|
-
),
|
|
1808
|
+
`TenxGraphClient [WS]: ${p.length} tool result(s) ready, resuming`
|
|
1809
|
+
), $ = {
|
|
1402
1810
|
invoke_type: "resume",
|
|
1403
|
-
tool_result:
|
|
1404
|
-
config: { ...e.config ?? {}, thread_id:
|
|
1405
|
-
recursion_limit:
|
|
1811
|
+
tool_result: p.map(x),
|
|
1812
|
+
config: { ...e.config ?? {}, thread_id: m },
|
|
1813
|
+
recursion_limit: s,
|
|
1814
|
+
on_busy: e.on_busy,
|
|
1406
1815
|
response_granularity: e.response_granularity
|
|
1407
1816
|
};
|
|
1408
1817
|
} else
|
|
1409
1818
|
break e;
|
|
1410
1819
|
}
|
|
1411
1820
|
} finally {
|
|
1412
|
-
(o.readyState === 1 || o.readyState === 0) && o.close(1e3), t.debug && console.debug("TenxGraphClient [WS]: stream finished");
|
|
1821
|
+
t.signal?.removeEventListener("abort", G), (o.readyState === 1 || o.readyState === 0) && o.close(1e3), t.debug && console.debug("TenxGraphClient [WS]: stream finished");
|
|
1413
1822
|
}
|
|
1414
1823
|
}
|
|
1415
|
-
const
|
|
1416
|
-
function
|
|
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) {
|
|
1824
|
+
const dt = 24e3, Qt = 16e3, ht = 1e4;
|
|
1825
|
+
function ut(t) {
|
|
1427
1826
|
if (t instanceof ArrayBuffer)
|
|
1428
1827
|
return new Uint8Array(t);
|
|
1429
1828
|
if (ArrayBuffer.isView(t)) {
|
|
@@ -1432,20 +1831,26 @@ function xe(t) {
|
|
|
1432
1831
|
}
|
|
1433
1832
|
return null;
|
|
1434
1833
|
}
|
|
1435
|
-
class
|
|
1834
|
+
class ft {
|
|
1436
1835
|
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 ??
|
|
1836
|
+
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 ?? null, this.init = { ...r }, this.threadId === null && delete this.init.thread_id, this.reconnectCfg = {
|
|
1438
1837
|
enabled: o?.reconnect?.enabled ?? !0,
|
|
1439
1838
|
baseDelay: o?.reconnect?.baseDelay ?? 0.5,
|
|
1440
1839
|
maxDelay: o?.reconnect?.maxDelay ?? 10,
|
|
1441
1840
|
maxAttempts: o?.reconnect?.maxAttempts ?? 5
|
|
1442
1841
|
}, 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
1842
|
this.resolveReady = s, this.rejectReady = n;
|
|
1843
|
+
}), this.ready.catch(() => {
|
|
1444
1844
|
}), this.connect();
|
|
1445
1845
|
}
|
|
1446
1846
|
// ── Public send API ─────────────────────────────────────────────────────────
|
|
1847
|
+
/**
|
|
1848
|
+
* Frames are dropped unless the socket is open; await `session.ready` (or the `open`
|
|
1849
|
+
* event) before sending, so mic callbacks that fire early do not throw.
|
|
1850
|
+
*/
|
|
1447
1851
|
sendAudio(e) {
|
|
1448
|
-
this.ws
|
|
1852
|
+
const r = this.ws;
|
|
1853
|
+
r && r.readyState === 1 && r.send(e);
|
|
1449
1854
|
}
|
|
1450
1855
|
sendText(e) {
|
|
1451
1856
|
this.sendControl({ type: "text", text: e });
|
|
@@ -1457,7 +1862,7 @@ class Pe {
|
|
|
1457
1862
|
this.sendControl({ type: "activity_end" });
|
|
1458
1863
|
}
|
|
1459
1864
|
close() {
|
|
1460
|
-
this.closedByUser = !0, this.sendControl({ type: "close" });
|
|
1865
|
+
this.closedByUser = !0, this.clearTimers(), this.sendControl({ type: "close" });
|
|
1461
1866
|
const e = this.ws;
|
|
1462
1867
|
e && (e.readyState === 0 || e.readyState === 1) && e.close(1e3);
|
|
1463
1868
|
}
|
|
@@ -1479,32 +1884,49 @@ class Pe {
|
|
|
1479
1884
|
});
|
|
1480
1885
|
}
|
|
1481
1886
|
sendControl(e) {
|
|
1482
|
-
this.ws
|
|
1887
|
+
const r = this.ws;
|
|
1888
|
+
r && r.readyState === 1 && r.send(JSON.stringify(e));
|
|
1889
|
+
}
|
|
1890
|
+
clearTimers() {
|
|
1891
|
+
this.reconnectTimer !== void 0 && clearTimeout(this.reconnectTimer), this.stableTimer !== void 0 && clearTimeout(this.stableTimer), this.reconnectTimer = void 0, this.stableTimer = void 0;
|
|
1483
1892
|
}
|
|
1484
1893
|
connect() {
|
|
1485
|
-
const e =
|
|
1894
|
+
const e = se(this.ctx, "/v1/graph/live");
|
|
1486
1895
|
this.ctx.debug && console.debug("TenxGraphClient [realtime]: connecting to", e);
|
|
1487
|
-
const r =
|
|
1896
|
+
const r = this.ctx.getAuthToken, o = ne(e, r ? { ...this.ctx, authToken: r() } : this.ctx);
|
|
1488
1897
|
try {
|
|
1489
|
-
|
|
1898
|
+
o.binaryType = "arraybuffer";
|
|
1490
1899
|
} catch {
|
|
1491
1900
|
}
|
|
1492
|
-
this.ws =
|
|
1493
|
-
this.ws ===
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
}),
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
this.
|
|
1500
|
-
|
|
1501
|
-
this.
|
|
1901
|
+
this.ws = o, o.addEventListener("open", () => {
|
|
1902
|
+
this.ws === o && (this.sendControl(this.init), this.readyResolved || (this.readyResolved = !0, this.resolveReady()), this.emit("open"), this.stableTimer !== void 0 && clearTimeout(this.stableTimer), this.stableTimer = setTimeout(() => {
|
|
1903
|
+
this.stableTimer = void 0, this.reconnectAttempts = 0;
|
|
1904
|
+
}, ht));
|
|
1905
|
+
}), o.addEventListener("message", (s) => {
|
|
1906
|
+
this.ws === o && this.handleMessage(s.data);
|
|
1907
|
+
}), o.addEventListener("close", (s) => {
|
|
1908
|
+
if (this.ws !== o) return;
|
|
1909
|
+
const n = s?.code ?? 1e3;
|
|
1910
|
+
if (this.stableTimer !== void 0 && clearTimeout(this.stableTimer), this.stableTimer = void 0, this.emit("close", n), n === 1008 && !this.closedByUser && !this.fatal) {
|
|
1911
|
+
this.fatal = !0;
|
|
1912
|
+
const i = {
|
|
1913
|
+
type: "error",
|
|
1914
|
+
code: "policy_violation",
|
|
1915
|
+
message: "Realtime connection closed by the server (1008, policy violation)",
|
|
1916
|
+
fatal: !0
|
|
1917
|
+
};
|
|
1918
|
+
this.emit("error", i), this.emit("event", i);
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
this.maybeReconnect(n);
|
|
1922
|
+
}), o.addEventListener("error", () => {
|
|
1923
|
+
this.ws === o && (this.readyResolved || (this.readyResolved = !0, this.rejectReady(new Error("Realtime WebSocket connection failed"))));
|
|
1502
1924
|
});
|
|
1503
1925
|
}
|
|
1504
1926
|
handleMessage(e) {
|
|
1505
|
-
const r =
|
|
1927
|
+
const r = ut(e);
|
|
1506
1928
|
if (r) {
|
|
1507
|
-
this.emit("audio", r,
|
|
1929
|
+
this.emit("audio", r, dt);
|
|
1508
1930
|
return;
|
|
1509
1931
|
}
|
|
1510
1932
|
if (typeof e != "string") return;
|
|
@@ -1515,446 +1937,460 @@ class Pe {
|
|
|
1515
1937
|
this.ctx.debug && console.warn("TenxGraphClient [realtime]: bad JSON frame", e);
|
|
1516
1938
|
return;
|
|
1517
1939
|
}
|
|
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);
|
|
1940
|
+
o.type === "session_started" && o.thread_id && (this.threadId = o.thread_id), 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
1941
|
}
|
|
1520
|
-
maybeReconnect() {
|
|
1942
|
+
maybeReconnect(e) {
|
|
1521
1943
|
if (this.closedByUser || this.fatal || !this.reconnectCfg.enabled)
|
|
1522
1944
|
return;
|
|
1523
1945
|
if (this.reconnectAttempts >= this.reconnectCfg.maxAttempts) {
|
|
1524
1946
|
this.fatal = !0;
|
|
1525
|
-
const
|
|
1947
|
+
const n = {
|
|
1526
1948
|
type: "error",
|
|
1527
1949
|
code: "reconnect_failed",
|
|
1528
1950
|
message: `Realtime reconnect gave up after ${this.reconnectCfg.maxAttempts} attempt(s)`,
|
|
1529
1951
|
fatal: !0
|
|
1530
1952
|
};
|
|
1531
|
-
this.emit("error",
|
|
1953
|
+
this.emit("error", n), this.emit("event", n);
|
|
1532
1954
|
return;
|
|
1533
1955
|
}
|
|
1534
1956
|
this.reconnectAttempts += 1;
|
|
1535
|
-
const
|
|
1536
|
-
this.emit("reconnecting",
|
|
1957
|
+
const r = this.reconnectAttempts, s = (e === 1013 ? this.reconnectCfg.maxDelay : Math.min(this.reconnectCfg.baseDelay * 2 ** (r - 1), this.reconnectCfg.maxDelay)) * 1e3 * (0.5 + Math.random() * 0.5);
|
|
1958
|
+
this.emit("reconnecting", r), this.reconnectTimer = setTimeout(() => {
|
|
1959
|
+
this.reconnectTimer = void 0, this.reconnect();
|
|
1960
|
+
}, s);
|
|
1537
1961
|
}
|
|
1538
1962
|
reconnect() {
|
|
1539
|
-
this.
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1963
|
+
if (!this.closedByUser) {
|
|
1964
|
+
this.init = {
|
|
1965
|
+
...this.init,
|
|
1966
|
+
// The server-given id, so the same thread continues; none yet means the first connect
|
|
1967
|
+
// never got `session_started`, and the server makes a new one.
|
|
1968
|
+
...this.threadId ? { thread_id: this.threadId } : {},
|
|
1969
|
+
...this.resumptionHandle ? { resumption_handle: this.resumptionHandle } : {}
|
|
1970
|
+
};
|
|
1971
|
+
try {
|
|
1972
|
+
this.connect(), this.ws?.addEventListener("open", () => this.emit("reconnected"), {
|
|
1973
|
+
once: !0
|
|
1974
|
+
});
|
|
1975
|
+
} catch (e) {
|
|
1976
|
+
this.ctx.debug && console.warn("TenxGraphClient [realtime]: reconnect failed", e), this.maybeReconnect();
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1548
1979
|
}
|
|
1549
1980
|
}
|
|
1550
|
-
var
|
|
1551
|
-
async function
|
|
1981
|
+
var pt = /* @__PURE__ */ ((t) => (t.EPISODIC = "episodic", t.SEMANTIC = "semantic", t.PROCEDURAL = "procedural", t.ENTITY = "entity", t.RELATIONSHIP = "relationship", t.CUSTOM = "custom", t.DECLARATIVE = "declarative", t))(pt || {});
|
|
1982
|
+
async function mt(t, e) {
|
|
1552
1983
|
try {
|
|
1553
1984
|
t.debug && console.debug("TenxGraphClient: Storing memory with type", e.memory_type);
|
|
1554
|
-
const r =
|
|
1985
|
+
const r = `${t.baseUrl}/v1/store/memories`, o = {
|
|
1555
1986
|
config: e.config || {},
|
|
1556
1987
|
options: e.options || {},
|
|
1557
1988
|
content: e.content,
|
|
1558
1989
|
memory_type: e.memory_type,
|
|
1559
1990
|
category: e.category,
|
|
1560
1991
|
metadata: e.metadata || {}
|
|
1561
|
-
},
|
|
1992
|
+
}, s = await f(t, r, {
|
|
1562
1993
|
method: "POST",
|
|
1563
|
-
headers:
|
|
1994
|
+
headers: d(t, {
|
|
1564
1995
|
"Content-Type": "application/json"
|
|
1565
1996
|
}),
|
|
1566
|
-
...
|
|
1567
|
-
body: JSON.stringify(
|
|
1568
|
-
signal: r.signal
|
|
1997
|
+
...h(t),
|
|
1998
|
+
body: JSON.stringify(o)
|
|
1569
1999
|
});
|
|
1570
|
-
if (
|
|
1571
|
-
throw console.warn(`TenxGraphClient: Store memory failed with HTTP ${
|
|
1572
|
-
|
|
2000
|
+
if (!s.ok)
|
|
2001
|
+
throw console.warn(`TenxGraphClient: Store memory failed with HTTP ${s.status}`), await u(
|
|
2002
|
+
s,
|
|
1573
2003
|
"Store memory request failed",
|
|
1574
2004
|
"/v1/memory",
|
|
1575
2005
|
"POST"
|
|
1576
2006
|
);
|
|
1577
|
-
const
|
|
1578
|
-
return t.debug && console.info("TenxGraphClient: Memory stored successfully",
|
|
2007
|
+
const n = await s.json();
|
|
2008
|
+
return t.debug && console.info("TenxGraphClient: Memory stored successfully", n), n;
|
|
1579
2009
|
} catch (r) {
|
|
1580
2010
|
throw t.debug && console.debug("TenxGraphClient: Store memory failed:", r), r;
|
|
1581
2011
|
}
|
|
1582
2012
|
}
|
|
1583
|
-
var
|
|
1584
|
-
async function
|
|
2013
|
+
var gt = /* @__PURE__ */ ((t) => (t.SIMILARITY = "similarity", t.TEMPORAL = "temporal", t.RELEVANCE = "relevance", t.HYBRID = "hybrid", t.GRAPH_TRAVERSAL = "graph_traversal", t))(gt || {}), yt = /* @__PURE__ */ ((t) => (t.COSINE = "cosine", t.EUCLIDEAN = "euclidean", t.DOT_PRODUCT = "dot_product", t.MANHATTAN = "manhattan", t))(yt || {});
|
|
2014
|
+
async function Tt(t, e) {
|
|
1585
2015
|
try {
|
|
1586
2016
|
t.debug && console.debug("TenxGraphClient: Searching memories with query:", e.query);
|
|
1587
|
-
const r =
|
|
2017
|
+
const r = `${t.baseUrl}/v1/store/search`, o = {
|
|
1588
2018
|
config: e.config || {},
|
|
1589
2019
|
options: e.options || {},
|
|
1590
2020
|
query: e.query,
|
|
1591
|
-
memory_type: e.memory_type || L.EPISODIC,
|
|
1592
|
-
category: e.category || "",
|
|
1593
2021
|
limit: e.limit !== void 0 ? e.limit : 10,
|
|
1594
|
-
score_threshold: e.score_threshold !== void 0 ? e.score_threshold : 0,
|
|
1595
2022
|
filters: e.filters || {},
|
|
1596
2023
|
retrieval_strategy: e.retrieval_strategy || "similarity",
|
|
1597
2024
|
distance_metric: e.distance_metric || "cosine",
|
|
1598
2025
|
max_tokens: e.max_tokens !== void 0 ? e.max_tokens : 4e3
|
|
1599
|
-
}
|
|
2026
|
+
};
|
|
2027
|
+
e.memory_type !== void 0 && e.memory_type !== null && (o.memory_type = e.memory_type), e.category !== void 0 && e.category !== null && (o.category = e.category), e.score_threshold !== void 0 && e.score_threshold !== null && (o.score_threshold = e.score_threshold);
|
|
2028
|
+
const s = await f(t, r, {
|
|
1600
2029
|
method: "POST",
|
|
1601
|
-
headers:
|
|
2030
|
+
headers: d(t, {
|
|
1602
2031
|
"Content-Type": "application/json"
|
|
1603
2032
|
}),
|
|
1604
|
-
...
|
|
1605
|
-
body: JSON.stringify(
|
|
1606
|
-
signal: r.signal
|
|
2033
|
+
...h(t),
|
|
2034
|
+
body: JSON.stringify(o)
|
|
1607
2035
|
});
|
|
1608
|
-
if (
|
|
1609
|
-
throw console.warn(`TenxGraphClient: Search memory failed with HTTP ${
|
|
1610
|
-
|
|
2036
|
+
if (!s.ok)
|
|
2037
|
+
throw console.warn(`TenxGraphClient: Search memory failed with HTTP ${s.status}`), await u(
|
|
2038
|
+
s,
|
|
1611
2039
|
"Search memory request failed",
|
|
1612
2040
|
"/v1/memory/search",
|
|
1613
2041
|
"POST"
|
|
1614
2042
|
);
|
|
1615
|
-
const
|
|
2043
|
+
const n = await s.json();
|
|
1616
2044
|
return t.debug && console.info("TenxGraphClient: Memory search successful", {
|
|
1617
2045
|
query: e.query,
|
|
1618
|
-
results_count:
|
|
1619
|
-
}),
|
|
2046
|
+
results_count: n.data.results.length
|
|
2047
|
+
}), n;
|
|
1620
2048
|
} catch (r) {
|
|
1621
2049
|
throw t.debug && console.debug("TenxGraphClient: Search memory failed:", r), r;
|
|
1622
2050
|
}
|
|
1623
2051
|
}
|
|
1624
|
-
async function
|
|
2052
|
+
async function bt(t, e) {
|
|
1625
2053
|
try {
|
|
1626
2054
|
t.debug && console.debug("TenxGraphClient: Fetching memory with ID:", e.memoryId);
|
|
1627
|
-
const r =
|
|
2055
|
+
const r = `${t.baseUrl}/v1/store/memories/${E(e.memoryId)}`, o = {
|
|
1628
2056
|
config: e.config || {},
|
|
1629
2057
|
options: e.options || {}
|
|
1630
|
-
},
|
|
2058
|
+
}, s = await f(t, r, {
|
|
1631
2059
|
method: "POST",
|
|
1632
|
-
headers:
|
|
2060
|
+
headers: d(t, {
|
|
1633
2061
|
"Content-Type": "application/json"
|
|
1634
2062
|
}),
|
|
1635
|
-
...
|
|
1636
|
-
body: JSON.stringify(
|
|
1637
|
-
signal: r.signal
|
|
2063
|
+
...h(t),
|
|
2064
|
+
body: JSON.stringify(o)
|
|
1638
2065
|
});
|
|
1639
|
-
if (
|
|
1640
|
-
throw console.warn(`TenxGraphClient: Get memory failed with HTTP ${
|
|
1641
|
-
|
|
2066
|
+
if (!s.ok)
|
|
2067
|
+
throw console.warn(`TenxGraphClient: Get memory failed with HTTP ${s.status}`), await u(
|
|
2068
|
+
s,
|
|
1642
2069
|
"Get memory request failed",
|
|
1643
2070
|
"/v1/memory/{memory_id}",
|
|
1644
2071
|
"GET"
|
|
1645
2072
|
);
|
|
1646
|
-
const
|
|
2073
|
+
const n = await s.json();
|
|
1647
2074
|
return t.debug && console.info("TenxGraphClient: Memory fetched successfully", {
|
|
1648
2075
|
memory_id: e.memoryId,
|
|
1649
|
-
content:
|
|
1650
|
-
}),
|
|
2076
|
+
content: n.data.memory.content.substring(0, 50)
|
|
2077
|
+
}), n;
|
|
1651
2078
|
} catch (r) {
|
|
1652
2079
|
throw t.debug && console.debug("TenxGraphClient: Get memory failed:", r), r;
|
|
1653
2080
|
}
|
|
1654
2081
|
}
|
|
1655
|
-
async function
|
|
2082
|
+
async function wt(t, e) {
|
|
1656
2083
|
try {
|
|
1657
2084
|
t.debug && console.debug("TenxGraphClient: Updating memory with ID:", e.memoryId);
|
|
1658
|
-
const r =
|
|
2085
|
+
const r = `${t.baseUrl}/v1/store/memories/${E(e.memoryId)}`, o = {
|
|
1659
2086
|
config: e.config || {},
|
|
1660
2087
|
options: e.options || {},
|
|
1661
2088
|
content: e.content,
|
|
1662
2089
|
metadata: e.metadata || {}
|
|
1663
2090
|
};
|
|
1664
|
-
t.debug && console.debug("TenxGraphClient: Request payload:", JSON.stringify(
|
|
1665
|
-
const
|
|
2091
|
+
t.debug && console.debug("TenxGraphClient: Request payload:", JSON.stringify(o, null, 2));
|
|
2092
|
+
const s = await f(t, r, {
|
|
1666
2093
|
method: "PUT",
|
|
1667
|
-
headers:
|
|
2094
|
+
headers: d(t, {
|
|
1668
2095
|
"Content-Type": "application/json"
|
|
1669
2096
|
}),
|
|
1670
|
-
...
|
|
1671
|
-
body: JSON.stringify(
|
|
1672
|
-
signal: r.signal
|
|
2097
|
+
...h(t),
|
|
2098
|
+
body: JSON.stringify(o)
|
|
1673
2099
|
});
|
|
1674
|
-
if (
|
|
1675
|
-
throw console.warn(`TenxGraphClient: Update memory failed with HTTP ${
|
|
1676
|
-
|
|
2100
|
+
if (!s.ok)
|
|
2101
|
+
throw console.warn(`TenxGraphClient: Update memory failed with HTTP ${s.status}`), await u(
|
|
2102
|
+
s,
|
|
1677
2103
|
"Update memory request failed",
|
|
1678
2104
|
"/v1/memory/{memory_id}",
|
|
1679
2105
|
"PUT"
|
|
1680
2106
|
);
|
|
1681
|
-
const
|
|
2107
|
+
const n = await s.json();
|
|
1682
2108
|
return t.debug && console.info("TenxGraphClient: Memory updated successfully", {
|
|
1683
2109
|
memory_id: e.memoryId,
|
|
1684
|
-
success:
|
|
1685
|
-
}),
|
|
2110
|
+
success: n.data.success
|
|
2111
|
+
}), n;
|
|
1686
2112
|
} catch (r) {
|
|
1687
2113
|
throw t.debug && console.debug("TenxGraphClient: Update memory failed:", r), r;
|
|
1688
2114
|
}
|
|
1689
2115
|
}
|
|
1690
|
-
async function
|
|
2116
|
+
async function _t(t, e) {
|
|
1691
2117
|
try {
|
|
1692
2118
|
t.debug && console.debug("TenxGraphClient: Deleting memory with ID:", e.memoryId);
|
|
1693
|
-
const r =
|
|
2119
|
+
const r = `${t.baseUrl}/v1/store/memories/${E(e.memoryId)}`, o = {
|
|
1694
2120
|
config: e.config || {},
|
|
1695
2121
|
options: e.options || {}
|
|
1696
2122
|
};
|
|
1697
|
-
t.debug && console.debug("TenxGraphClient: Delete request payload:", JSON.stringify(
|
|
1698
|
-
const
|
|
2123
|
+
t.debug && console.debug("TenxGraphClient: Delete request payload:", JSON.stringify(o, null, 2));
|
|
2124
|
+
const s = await f(t, r, {
|
|
1699
2125
|
method: "DELETE",
|
|
1700
|
-
headers:
|
|
2126
|
+
headers: d(t, {
|
|
1701
2127
|
"Content-Type": "application/json",
|
|
1702
2128
|
accept: "application/json"
|
|
1703
2129
|
}),
|
|
1704
|
-
...
|
|
1705
|
-
body: JSON.stringify(
|
|
1706
|
-
signal: r.signal
|
|
2130
|
+
...h(t),
|
|
2131
|
+
body: JSON.stringify(o)
|
|
1707
2132
|
});
|
|
1708
|
-
if (
|
|
1709
|
-
throw console.warn(`TenxGraphClient: Delete memory failed with HTTP ${
|
|
1710
|
-
|
|
2133
|
+
if (!s.ok)
|
|
2134
|
+
throw console.warn(`TenxGraphClient: Delete memory failed with HTTP ${s.status}`), await u(
|
|
2135
|
+
s,
|
|
1711
2136
|
"Delete memory request failed",
|
|
1712
2137
|
"/v1/memory/{memory_id}",
|
|
1713
2138
|
"DELETE"
|
|
1714
2139
|
);
|
|
1715
|
-
const
|
|
2140
|
+
const n = await s.json();
|
|
1716
2141
|
return t.debug && console.info("TenxGraphClient: Memory deleted successfully", {
|
|
1717
2142
|
memory_id: e.memoryId,
|
|
1718
|
-
success:
|
|
1719
|
-
}),
|
|
2143
|
+
success: n.data.success
|
|
2144
|
+
}), n;
|
|
1720
2145
|
} catch (r) {
|
|
1721
|
-
throw
|
|
2146
|
+
throw t.debug && console.debug("TenxGraphClient: Delete memory failed:", r), r;
|
|
1722
2147
|
}
|
|
1723
2148
|
}
|
|
1724
|
-
async function
|
|
2149
|
+
async function Ct(t, e) {
|
|
1725
2150
|
try {
|
|
1726
2151
|
t.debug && console.debug("TenxGraphClient: Fetching list of memories", {
|
|
1727
2152
|
limit: e.limit
|
|
1728
2153
|
});
|
|
1729
|
-
const r =
|
|
2154
|
+
const r = `${t.baseUrl}/v1/store/memories/list`, o = {
|
|
1730
2155
|
config: e.config || {},
|
|
1731
2156
|
options: e.options || {},
|
|
1732
2157
|
limit: e.limit || 100
|
|
1733
2158
|
};
|
|
1734
|
-
t.debug && console.debug(
|
|
2159
|
+
e.offset !== void 0 && (o.offset = e.offset), t.debug && console.debug(
|
|
1735
2160
|
"TenxGraphClient: List memories request payload:",
|
|
1736
|
-
JSON.stringify(
|
|
2161
|
+
JSON.stringify(o, null, 2)
|
|
1737
2162
|
);
|
|
1738
|
-
const
|
|
2163
|
+
const s = await f(t, r, {
|
|
1739
2164
|
method: "POST",
|
|
1740
|
-
headers:
|
|
2165
|
+
headers: d(t, {
|
|
1741
2166
|
"Content-Type": "application/json",
|
|
1742
2167
|
accept: "application/json"
|
|
1743
2168
|
}),
|
|
1744
|
-
...
|
|
1745
|
-
body: JSON.stringify(
|
|
1746
|
-
signal: r.signal
|
|
2169
|
+
...h(t),
|
|
2170
|
+
body: JSON.stringify(o)
|
|
1747
2171
|
});
|
|
1748
|
-
if (
|
|
1749
|
-
throw console.warn(`TenxGraphClient: List memories failed with HTTP ${
|
|
1750
|
-
|
|
2172
|
+
if (!s.ok)
|
|
2173
|
+
throw console.warn(`TenxGraphClient: List memories failed with HTTP ${s.status}`), await u(
|
|
2174
|
+
s,
|
|
1751
2175
|
"List memories request failed",
|
|
1752
2176
|
"/v1/memory",
|
|
1753
2177
|
"GET"
|
|
1754
2178
|
);
|
|
1755
|
-
const
|
|
2179
|
+
const n = await s.json();
|
|
1756
2180
|
return t.debug && console.info("TenxGraphClient: Memories list fetched successfully", {
|
|
1757
|
-
count:
|
|
2181
|
+
count: n.data.memories.length,
|
|
1758
2182
|
limit: e.limit
|
|
1759
|
-
}),
|
|
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;
|
|
2183
|
+
}), n;
|
|
1784
2184
|
} catch (r) {
|
|
1785
|
-
throw
|
|
1786
|
-
}
|
|
2185
|
+
throw t.debug && console.debug("TenxGraphClient: List memories failed:", r), r;
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
async function Et(t, e) {
|
|
2189
|
+
const r = `${t.baseUrl}/v1/store/memories/forget`, o = {};
|
|
2190
|
+
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);
|
|
2191
|
+
const s = await f(t, r, {
|
|
2192
|
+
method: "POST",
|
|
2193
|
+
headers: d(t, {
|
|
2194
|
+
"Content-Type": "application/json"
|
|
2195
|
+
}),
|
|
2196
|
+
...h(t),
|
|
2197
|
+
body: JSON.stringify(o)
|
|
2198
|
+
});
|
|
2199
|
+
if (!s.ok)
|
|
2200
|
+
throw new Error(`Forget memories failed: ${s.status} ${s.statusText}`);
|
|
2201
|
+
const n = await s.json();
|
|
2202
|
+
return t.debug && console.log("[DEBUG] Forget memories response:", n), n;
|
|
1787
2203
|
}
|
|
1788
|
-
async function
|
|
2204
|
+
async function vt(t, e) {
|
|
1789
2205
|
try {
|
|
1790
2206
|
t.debug && console.debug("TenxGraphClient: Stopping graph execution for thread:", e.thread_id);
|
|
1791
|
-
const r =
|
|
2207
|
+
const r = await f(t, `${t.baseUrl}/v1/graph/stop`, {
|
|
1792
2208
|
method: "POST",
|
|
1793
|
-
headers:
|
|
2209
|
+
headers: d(t, {
|
|
1794
2210
|
"Content-Type": "application/json",
|
|
1795
2211
|
accept: "application/json"
|
|
1796
2212
|
}),
|
|
1797
|
-
...
|
|
1798
|
-
body: JSON.stringify(e)
|
|
1799
|
-
signal: r.signal
|
|
2213
|
+
...h(t),
|
|
2214
|
+
body: JSON.stringify(e)
|
|
1800
2215
|
});
|
|
1801
|
-
if (
|
|
1802
|
-
throw console.warn(`TenxGraphClient: Stop graph failed with HTTP ${
|
|
1803
|
-
|
|
2216
|
+
if (!r.ok)
|
|
2217
|
+
throw console.warn(`TenxGraphClient: Stop graph failed with HTTP ${r.status}`), await u(
|
|
2218
|
+
r,
|
|
1804
2219
|
"Stop graph execution failed",
|
|
1805
2220
|
"/v1/graph/stop",
|
|
1806
2221
|
"POST"
|
|
1807
2222
|
);
|
|
1808
|
-
const
|
|
1809
|
-
return t.debug && console.info("TenxGraphClient: Graph execution stopped successfully",
|
|
2223
|
+
const o = await r.json();
|
|
2224
|
+
return t.debug && console.info("TenxGraphClient: Graph execution stopped successfully", o), o;
|
|
1810
2225
|
} catch (r) {
|
|
1811
|
-
throw t.debug && console.debug("TenxGraphClient: Stop graph failed:", r),
|
|
2226
|
+
throw t.debug && console.debug("TenxGraphClient: Stop graph failed:", r), console.error("TenxGraphClient: Stop graph failed:", r), r;
|
|
1812
2227
|
}
|
|
1813
2228
|
}
|
|
1814
|
-
async function
|
|
2229
|
+
async function St(t, e) {
|
|
1815
2230
|
try {
|
|
1816
2231
|
t.debug && console.debug("TenxGraphClient: Fixing graph state for thread:", e.thread_id);
|
|
1817
|
-
const r =
|
|
2232
|
+
const r = await f(t, `${t.baseUrl}/v1/graph/fix`, {
|
|
1818
2233
|
method: "POST",
|
|
1819
|
-
headers:
|
|
2234
|
+
headers: d(t, {
|
|
1820
2235
|
"Content-Type": "application/json",
|
|
1821
2236
|
accept: "application/json"
|
|
1822
2237
|
}),
|
|
1823
|
-
...
|
|
1824
|
-
body: JSON.stringify(e)
|
|
1825
|
-
signal: r.signal
|
|
2238
|
+
...h(t),
|
|
2239
|
+
body: JSON.stringify(e)
|
|
1826
2240
|
});
|
|
1827
|
-
if (
|
|
1828
|
-
throw console.warn(`TenxGraphClient: Fix graph failed with HTTP ${
|
|
1829
|
-
|
|
2241
|
+
if (!r.ok)
|
|
2242
|
+
throw console.warn(`TenxGraphClient: Fix graph failed with HTTP ${r.status}`), await u(
|
|
2243
|
+
r,
|
|
1830
2244
|
"Fix graph state failed",
|
|
1831
2245
|
"/v1/graph/fix",
|
|
1832
2246
|
"POST"
|
|
1833
2247
|
);
|
|
1834
|
-
const
|
|
2248
|
+
const o = await r.json();
|
|
1835
2249
|
return t.debug && console.info("TenxGraphClient: Graph state fixed successfully", {
|
|
1836
|
-
removed_count:
|
|
1837
|
-
success:
|
|
1838
|
-
}),
|
|
2250
|
+
removed_count: o.data.removed_count,
|
|
2251
|
+
success: o.data.success
|
|
2252
|
+
}), o;
|
|
1839
2253
|
} catch (r) {
|
|
1840
|
-
throw t.debug && console.debug("TenxGraphClient: Fix graph failed:", r),
|
|
2254
|
+
throw t.debug && console.debug("TenxGraphClient: Fix graph failed:", r), console.error("TenxGraphClient: Fix graph failed:", r), r;
|
|
1841
2255
|
}
|
|
1842
2256
|
}
|
|
1843
|
-
async function
|
|
1844
|
-
const r = new
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
"POST"
|
|
1861
|
-
);
|
|
1862
|
-
return await n.json();
|
|
1863
|
-
} finally {
|
|
1864
|
-
clearTimeout(o);
|
|
1865
|
-
}
|
|
2257
|
+
async function Gt(t, e) {
|
|
2258
|
+
const r = new FormData();
|
|
2259
|
+
typeof File < "u" && e instanceof File ? r.append("file", e, e.name) : "data" in e && "filename" in e ? r.append("file", e.data, e.filename) : r.append("file", e, "upload");
|
|
2260
|
+
const o = await f(t, `${t.baseUrl}/v1/files/upload`, {
|
|
2261
|
+
method: "POST",
|
|
2262
|
+
headers: d(t),
|
|
2263
|
+
body: r,
|
|
2264
|
+
...h(t)
|
|
2265
|
+
});
|
|
2266
|
+
if (!o.ok)
|
|
2267
|
+
throw await u(
|
|
2268
|
+
o,
|
|
2269
|
+
"File upload failed",
|
|
2270
|
+
"/v1/files/upload",
|
|
2271
|
+
"POST"
|
|
2272
|
+
);
|
|
2273
|
+
return await o.json();
|
|
1866
2274
|
}
|
|
1867
|
-
async function
|
|
1868
|
-
const r =
|
|
1869
|
-
|
|
1870
|
-
|
|
2275
|
+
async function Rt(t, e) {
|
|
2276
|
+
const r = await f(
|
|
2277
|
+
t,
|
|
2278
|
+
`${t.baseUrl}/v1/files/${encodeURIComponent(e)}`,
|
|
2279
|
+
{
|
|
1871
2280
|
method: "GET",
|
|
1872
|
-
headers:
|
|
1873
|
-
...
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
2281
|
+
headers: d(t),
|
|
2282
|
+
...h(t)
|
|
2283
|
+
}
|
|
2284
|
+
);
|
|
2285
|
+
if (!r.ok)
|
|
2286
|
+
throw await u(
|
|
2287
|
+
r,
|
|
2288
|
+
"File download failed",
|
|
2289
|
+
`/v1/files/${e}`,
|
|
2290
|
+
"GET"
|
|
2291
|
+
);
|
|
2292
|
+
return await r.blob();
|
|
2293
|
+
}
|
|
2294
|
+
async function kt(t, e) {
|
|
2295
|
+
const r = new URLSearchParams();
|
|
2296
|
+
e?.limit !== void 0 && r.append("limit", String(e.limit)), e?.offset !== void 0 && r.append("offset", String(e.offset));
|
|
2297
|
+
const o = r.toString(), s = await f(t, `${t.baseUrl}/v1/files${o ? `?${o}` : ""}`, {
|
|
2298
|
+
method: "GET",
|
|
2299
|
+
headers: d(t),
|
|
2300
|
+
...h(t)
|
|
2301
|
+
});
|
|
2302
|
+
if (!s.ok)
|
|
2303
|
+
throw await u(
|
|
2304
|
+
s,
|
|
2305
|
+
"List files request failed",
|
|
2306
|
+
"/v1/files",
|
|
2307
|
+
"GET"
|
|
2308
|
+
);
|
|
2309
|
+
return await s.json();
|
|
1887
2310
|
}
|
|
1888
|
-
async function
|
|
1889
|
-
const r =
|
|
1890
|
-
|
|
1891
|
-
|
|
2311
|
+
async function $t(t, e) {
|
|
2312
|
+
const r = await f(
|
|
2313
|
+
t,
|
|
2314
|
+
`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/info`,
|
|
2315
|
+
{
|
|
1892
2316
|
method: "GET",
|
|
1893
|
-
headers:
|
|
1894
|
-
...
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
} finally {
|
|
1906
|
-
clearTimeout(o);
|
|
1907
|
-
}
|
|
2317
|
+
headers: d(t),
|
|
2318
|
+
...h(t)
|
|
2319
|
+
}
|
|
2320
|
+
);
|
|
2321
|
+
if (!r.ok)
|
|
2322
|
+
throw await u(
|
|
2323
|
+
r,
|
|
2324
|
+
"File info request failed",
|
|
2325
|
+
`/v1/files/${e}/info`,
|
|
2326
|
+
"GET"
|
|
2327
|
+
);
|
|
2328
|
+
return await r.json();
|
|
1908
2329
|
}
|
|
1909
|
-
async function
|
|
1910
|
-
const r =
|
|
1911
|
-
|
|
1912
|
-
|
|
2330
|
+
async function At(t, e) {
|
|
2331
|
+
const r = await f(
|
|
2332
|
+
t,
|
|
2333
|
+
`${t.baseUrl}/v1/files/${encodeURIComponent(e)}/url`,
|
|
2334
|
+
{
|
|
1913
2335
|
method: "GET",
|
|
1914
|
-
headers:
|
|
1915
|
-
...
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
}
|
|
2336
|
+
headers: d(t),
|
|
2337
|
+
...h(t)
|
|
2338
|
+
}
|
|
2339
|
+
);
|
|
2340
|
+
if (!r.ok)
|
|
2341
|
+
throw await u(
|
|
2342
|
+
r,
|
|
2343
|
+
"File access URL request failed",
|
|
2344
|
+
`/v1/files/${e}/url`,
|
|
2345
|
+
"GET"
|
|
2346
|
+
);
|
|
2347
|
+
return await r.json();
|
|
2348
|
+
}
|
|
2349
|
+
async function Ot(t) {
|
|
2350
|
+
const e = await f(t, `${t.baseUrl}/v1/config/multimodal`, {
|
|
2351
|
+
method: "GET",
|
|
2352
|
+
headers: d(t, {
|
|
2353
|
+
accept: "application/json"
|
|
2354
|
+
}),
|
|
2355
|
+
...h(t)
|
|
2356
|
+
});
|
|
2357
|
+
if (!e.ok)
|
|
2358
|
+
throw await u(
|
|
2359
|
+
e,
|
|
2360
|
+
"Multimodal config request failed",
|
|
2361
|
+
"/v1/config/multimodal",
|
|
2362
|
+
"GET"
|
|
2363
|
+
);
|
|
2364
|
+
return await e.json();
|
|
1929
2365
|
}
|
|
1930
|
-
async function
|
|
1931
|
-
const e = new AbortController(), r = setTimeout(() => e.abort(), t.timeout);
|
|
2366
|
+
async function Nt(t, e) {
|
|
1932
2367
|
try {
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
2368
|
+
t.debug && console.debug("TenxGraphClient: Deleting file", `file: ${e}`);
|
|
2369
|
+
const r = `${t.baseUrl}/v1/files/${encodeURIComponent(e)}`, o = await f(t, r, {
|
|
2370
|
+
method: "DELETE",
|
|
2371
|
+
headers: d(t, {
|
|
1936
2372
|
accept: "application/json"
|
|
1937
2373
|
}),
|
|
1938
|
-
...
|
|
1939
|
-
signal: e.signal
|
|
2374
|
+
...h(t)
|
|
1940
2375
|
});
|
|
1941
|
-
if (
|
|
1942
|
-
throw await
|
|
2376
|
+
if (!o.ok)
|
|
2377
|
+
throw console.warn(`TenxGraphClient: Delete file failed with HTTP ${o.status}`), await u(
|
|
1943
2378
|
o,
|
|
1944
|
-
"
|
|
1945
|
-
|
|
1946
|
-
"
|
|
2379
|
+
"Delete file failed",
|
|
2380
|
+
`/v1/files/${e}`,
|
|
2381
|
+
"DELETE"
|
|
1947
2382
|
);
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
2383
|
+
const s = await o.json();
|
|
2384
|
+
return t.debug && console.info("TenxGraphClient: File deleted successfully", s), s;
|
|
2385
|
+
} catch (r) {
|
|
2386
|
+
throw t.debug && console.debug("TenxGraphClient: Delete file failed:", r), r;
|
|
1951
2387
|
}
|
|
1952
2388
|
}
|
|
1953
|
-
function
|
|
2389
|
+
function It(t) {
|
|
1954
2390
|
return typeof t == "object" && t !== null;
|
|
1955
2391
|
}
|
|
1956
|
-
function
|
|
1957
|
-
return
|
|
2392
|
+
function Ut(t, e, r) {
|
|
2393
|
+
return It(t) ? {
|
|
1958
2394
|
search: t.search,
|
|
1959
2395
|
offset: t.offset,
|
|
1960
2396
|
limit: t.limit
|
|
@@ -1964,11 +2400,11 @@ function tt(t, e, r) {
|
|
|
1964
2400
|
limit: r
|
|
1965
2401
|
};
|
|
1966
2402
|
}
|
|
1967
|
-
function
|
|
2403
|
+
function jt(t) {
|
|
1968
2404
|
return typeof t == "object" && t !== null;
|
|
1969
2405
|
}
|
|
1970
|
-
function
|
|
1971
|
-
return
|
|
2406
|
+
function xt(t, e, r, o) {
|
|
2407
|
+
return jt(e) ? {
|
|
1972
2408
|
threadId: t,
|
|
1973
2409
|
search: e.search,
|
|
1974
2410
|
offset: e.offset,
|
|
@@ -1980,14 +2416,27 @@ function ot(t, e, r, o) {
|
|
|
1980
2416
|
limit: o
|
|
1981
2417
|
};
|
|
1982
2418
|
}
|
|
1983
|
-
class
|
|
2419
|
+
class Pt {
|
|
1984
2420
|
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
|
|
2421
|
+
this.baseUrl = je(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 ue([]);
|
|
2422
|
+
}
|
|
2423
|
+
/**
|
|
2424
|
+
* Replace the bearer token used for later requests (for example after a refresh).
|
|
2425
|
+
* Does not touch an open stream or socket.
|
|
2426
|
+
*/
|
|
2427
|
+
setAuthToken(e) {
|
|
2428
|
+
this.authToken = e;
|
|
1986
2429
|
}
|
|
1987
|
-
|
|
2430
|
+
/** Drop the bearer token and any `auth` credentials. Later requests are sent without them. */
|
|
2431
|
+
clearAuth() {
|
|
2432
|
+
this.authToken = null, this.auth = null;
|
|
2433
|
+
}
|
|
2434
|
+
createContext(e) {
|
|
2435
|
+
const r = typeof this.authToken == "function" ? this.authToken() : this.authToken;
|
|
1988
2436
|
return {
|
|
1989
2437
|
baseUrl: this.baseUrl,
|
|
1990
|
-
authToken:
|
|
2438
|
+
authToken: r,
|
|
2439
|
+
signal: e?.signal,
|
|
1991
2440
|
auth: this.auth,
|
|
1992
2441
|
headers: this.headers,
|
|
1993
2442
|
credentials: this.credentials,
|
|
@@ -2012,32 +2461,32 @@ class st {
|
|
|
2012
2461
|
/**
|
|
2013
2462
|
* Ping the server to check connectivity
|
|
2014
2463
|
*/
|
|
2015
|
-
async ping() {
|
|
2016
|
-
const
|
|
2017
|
-
return
|
|
2464
|
+
async ping(e) {
|
|
2465
|
+
const r = this.createContext(e);
|
|
2466
|
+
return Pe(r);
|
|
2018
2467
|
}
|
|
2019
2468
|
/**
|
|
2020
2469
|
* Fetch the agent graph
|
|
2021
2470
|
*/
|
|
2022
|
-
async graph() {
|
|
2023
|
-
const
|
|
2024
|
-
return
|
|
2471
|
+
async graph(e) {
|
|
2472
|
+
const r = this.createContext(e);
|
|
2473
|
+
return Le(r);
|
|
2025
2474
|
}
|
|
2026
2475
|
/**
|
|
2027
2476
|
* Fetch the tools exposed by the graph's tool nodes, grouped by node.
|
|
2028
2477
|
* Each tool is tagged with its source (local / mcp / remote).
|
|
2029
2478
|
*/
|
|
2030
|
-
async graphTools() {
|
|
2031
|
-
const
|
|
2032
|
-
return
|
|
2479
|
+
async graphTools(e) {
|
|
2480
|
+
const r = this.createContext(e);
|
|
2481
|
+
return De(r);
|
|
2033
2482
|
}
|
|
2034
2483
|
/**
|
|
2035
2484
|
* Fetch the reconstructed observability trace (spans, events, cost) for a
|
|
2036
2485
|
* thread. Returns the latest run by default, or a specific run when given.
|
|
2037
2486
|
*/
|
|
2038
|
-
async observability(e, r) {
|
|
2039
|
-
const
|
|
2040
|
-
return
|
|
2487
|
+
async observability(e, r, o) {
|
|
2488
|
+
const s = this.createContext(o);
|
|
2489
|
+
return Me(s, e, r);
|
|
2041
2490
|
}
|
|
2042
2491
|
/**
|
|
2043
2492
|
* Stop a running graph execution for a specific thread
|
|
@@ -2045,25 +2494,28 @@ class st {
|
|
|
2045
2494
|
* @param config - Optional configuration for the stop operation
|
|
2046
2495
|
* @returns StopGraphResponse with the stop operation result
|
|
2047
2496
|
*/
|
|
2048
|
-
async stopGraph(e, r) {
|
|
2049
|
-
const
|
|
2050
|
-
return
|
|
2497
|
+
async stopGraph(e, r, o) {
|
|
2498
|
+
const s = this.createContext(o);
|
|
2499
|
+
return vt(s, {
|
|
2051
2500
|
thread_id: e,
|
|
2052
2501
|
config: r
|
|
2053
2502
|
});
|
|
2054
2503
|
}
|
|
2055
2504
|
/**
|
|
2056
|
-
*
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2505
|
+
* Repair a thread whose run stopped after the model asked for tools but before
|
|
2506
|
+
* the results were saved. The server removes assistant messages with unanswered
|
|
2507
|
+
* tool calls (matched by tool call id) and tool results whose call no longer
|
|
2508
|
+
* exists. Unanswered calls of the latest assistant message are kept while the
|
|
2509
|
+
* thread is paused (interrupt, client tool call or human approval). When nothing
|
|
2510
|
+
* needs fixing, removed_count is 0 and the state is not written.
|
|
2059
2511
|
*
|
|
2060
2512
|
* @param threadId - The ID of the thread to fix state for
|
|
2061
2513
|
* @param config - Optional configuration for the fix operation
|
|
2062
2514
|
* @returns FixGraphResponse with the fix operation result including removed_count
|
|
2063
2515
|
*/
|
|
2064
|
-
async fixGraph(e, r) {
|
|
2065
|
-
const
|
|
2066
|
-
return
|
|
2516
|
+
async fixGraph(e, r, o) {
|
|
2517
|
+
const s = this.createContext(o);
|
|
2518
|
+
return St(s, {
|
|
2067
2519
|
thread_id: e,
|
|
2068
2520
|
config: r
|
|
2069
2521
|
});
|
|
@@ -2074,9 +2526,9 @@ class st {
|
|
|
2074
2526
|
/**
|
|
2075
2527
|
* Fetch the state schema of the agent
|
|
2076
2528
|
*/
|
|
2077
|
-
async graphStateSchema() {
|
|
2078
|
-
const
|
|
2079
|
-
return
|
|
2529
|
+
async graphStateSchema(e) {
|
|
2530
|
+
const r = this.createContext(e);
|
|
2531
|
+
return Fe(r);
|
|
2080
2532
|
}
|
|
2081
2533
|
/**
|
|
2082
2534
|
* ***************** ALL THREAD APIS *****************
|
|
@@ -2086,9 +2538,9 @@ class st {
|
|
|
2086
2538
|
* @param threadId - The ID of the thread to fetch state for
|
|
2087
2539
|
* @returns ThreadStateResponse containing the thread's current state
|
|
2088
2540
|
*/
|
|
2089
|
-
async threadState(e) {
|
|
2090
|
-
const
|
|
2091
|
-
return
|
|
2541
|
+
async threadState(e, r) {
|
|
2542
|
+
const o = this.createContext(r);
|
|
2543
|
+
return Be(o, e);
|
|
2092
2544
|
}
|
|
2093
2545
|
/**
|
|
2094
2546
|
* Update the state of a specific thread (checkpoint)
|
|
@@ -2097,9 +2549,9 @@ class st {
|
|
|
2097
2549
|
* @param state - New AgentState for the thread
|
|
2098
2550
|
* @returns UpdateThreadStateResponse with the updated state
|
|
2099
2551
|
*/
|
|
2100
|
-
async updateThreadState(e, r, o) {
|
|
2101
|
-
const
|
|
2102
|
-
return
|
|
2552
|
+
async updateThreadState(e, r, o, s) {
|
|
2553
|
+
const n = this.createContext(s);
|
|
2554
|
+
return He(n, e, {
|
|
2103
2555
|
config: r,
|
|
2104
2556
|
state: o
|
|
2105
2557
|
});
|
|
@@ -2109,38 +2561,51 @@ class st {
|
|
|
2109
2561
|
* @param threadId - The ID of the thread to clear state for
|
|
2110
2562
|
* @returns ClearThreadStateResponse with the clear operation result
|
|
2111
2563
|
*/
|
|
2112
|
-
async clearThreadState(e) {
|
|
2113
|
-
const
|
|
2114
|
-
return
|
|
2564
|
+
async clearThreadState(e, r) {
|
|
2565
|
+
const o = this.createContext(r);
|
|
2566
|
+
return Je(o, e);
|
|
2115
2567
|
}
|
|
2116
2568
|
/**
|
|
2117
2569
|
* Fetch details for a specific thread
|
|
2118
2570
|
* @param threadId - The ID of the thread to fetch
|
|
2119
2571
|
* @returns ThreadDetailsResponse containing thread details
|
|
2120
2572
|
*/
|
|
2121
|
-
async threadDetails(e) {
|
|
2122
|
-
const
|
|
2123
|
-
return
|
|
2573
|
+
async threadDetails(e, r) {
|
|
2574
|
+
const o = this.createContext(r);
|
|
2575
|
+
return Qe(o, e);
|
|
2124
2576
|
}
|
|
2125
|
-
async threads(e, r, o) {
|
|
2126
|
-
const s = this.createContext(),
|
|
2127
|
-
|
|
2577
|
+
async threads(e, r, o, s) {
|
|
2578
|
+
const n = typeof r == "object" ? r : s, i = this.createContext(n), a = Ut(
|
|
2579
|
+
e,
|
|
2580
|
+
typeof r == "number" ? r : void 0,
|
|
2581
|
+
o
|
|
2582
|
+
);
|
|
2583
|
+
return rt(i, a);
|
|
2128
2584
|
}
|
|
2129
|
-
async threadMessages(e, r, o, s) {
|
|
2130
|
-
const n = this.createContext(),
|
|
2131
|
-
|
|
2585
|
+
async threadMessages(e, r, o, s, n) {
|
|
2586
|
+
const i = typeof o == "object" ? o : n, a = this.createContext(i), c = xt(
|
|
2587
|
+
e,
|
|
2588
|
+
r,
|
|
2589
|
+
typeof o == "number" ? o : void 0,
|
|
2590
|
+
s
|
|
2591
|
+
);
|
|
2592
|
+
return oe(a, c);
|
|
2132
2593
|
}
|
|
2133
2594
|
/**
|
|
2134
2595
|
* Add messages to a specific thread checkpoint
|
|
2596
|
+
*
|
|
2597
|
+
* @deprecated Requires the `checkpointer:import` scope (admin only) in 10xgraph-api releases after 0.9.0.
|
|
2598
|
+
* Use `updateThreadMessageFeedback` to attach feedback to a message.
|
|
2599
|
+
*
|
|
2135
2600
|
* @param threadId - The ID of the thread to add messages to
|
|
2136
2601
|
* @param messages - Array of messages to add to the checkpoint
|
|
2137
2602
|
* @param config - Configuration map for the checkpoint
|
|
2138
2603
|
* @param metadata - Optional metadata for the checkpoint
|
|
2139
2604
|
* @returns AddCheckpointMessagesResponse containing the operation result
|
|
2140
2605
|
*/
|
|
2141
|
-
async addThreadMessages(e, r, o = {}, s) {
|
|
2142
|
-
const
|
|
2143
|
-
return
|
|
2606
|
+
async addThreadMessages(e, r, o = {}, s, n) {
|
|
2607
|
+
const i = this.createContext(n);
|
|
2608
|
+
return Xe(i, {
|
|
2144
2609
|
threadId: e,
|
|
2145
2610
|
config: o,
|
|
2146
2611
|
messages: r,
|
|
@@ -2153,9 +2618,9 @@ class st {
|
|
|
2153
2618
|
* @param messageId - The ID of the message to fetch
|
|
2154
2619
|
* @returns ThreadMessageResponse containing the message and metadata
|
|
2155
2620
|
*/
|
|
2156
|
-
async singleMessage(e, r) {
|
|
2157
|
-
const
|
|
2158
|
-
return
|
|
2621
|
+
async singleMessage(e, r, o) {
|
|
2622
|
+
const s = this.createContext(o);
|
|
2623
|
+
return Ze(s, {
|
|
2159
2624
|
threadId: e,
|
|
2160
2625
|
messageId: r
|
|
2161
2626
|
});
|
|
@@ -2167,23 +2632,39 @@ class st {
|
|
|
2167
2632
|
* @param config - Optional configuration map to send with the request body
|
|
2168
2633
|
* @returns DeleteThreadMessageResponse containing the deletion result
|
|
2169
2634
|
*/
|
|
2170
|
-
async deleteMessage(e, r, o) {
|
|
2171
|
-
const
|
|
2172
|
-
return
|
|
2635
|
+
async deleteMessage(e, r, o, s) {
|
|
2636
|
+
const n = this.createContext(s);
|
|
2637
|
+
return qe(n, {
|
|
2173
2638
|
threadId: e,
|
|
2174
2639
|
messageId: r,
|
|
2175
2640
|
config: o
|
|
2176
2641
|
});
|
|
2177
2642
|
}
|
|
2643
|
+
/**
|
|
2644
|
+
* Replace the feedback attached to a message (`message.metadata.feedback`).
|
|
2645
|
+
* Nothing else on the message changes.
|
|
2646
|
+
* @param threadId - The ID of the thread
|
|
2647
|
+
* @param messageId - The ID of the message to attach feedback to
|
|
2648
|
+
* @param feedback - Any JSON object, at most 8192 serialized bytes and nesting depth 10
|
|
2649
|
+
* @returns UpdateThreadMessageFeedbackResponse containing the updated message
|
|
2650
|
+
*/
|
|
2651
|
+
async updateThreadMessageFeedback(e, r, o, s) {
|
|
2652
|
+
const n = this.createContext(s);
|
|
2653
|
+
return et(n, {
|
|
2654
|
+
threadId: e,
|
|
2655
|
+
messageId: r,
|
|
2656
|
+
feedback: o
|
|
2657
|
+
});
|
|
2658
|
+
}
|
|
2178
2659
|
/**
|
|
2179
2660
|
* Delete a specific thread
|
|
2180
2661
|
* @param threadId - The ID of the thread to delete
|
|
2181
2662
|
* @param config - Optional configuration map to send with the request body
|
|
2182
2663
|
* @returns DeleteThreadResponse containing the deletion result
|
|
2183
2664
|
*/
|
|
2184
|
-
async deleteThread(e, r) {
|
|
2185
|
-
const
|
|
2186
|
-
return
|
|
2665
|
+
async deleteThread(e, r, o) {
|
|
2666
|
+
const s = this.createContext(o);
|
|
2667
|
+
return tt(s, {
|
|
2187
2668
|
threadId: e,
|
|
2188
2669
|
config: r
|
|
2189
2670
|
});
|
|
@@ -2197,15 +2678,19 @@ class st {
|
|
|
2197
2678
|
async invoke(e, r) {
|
|
2198
2679
|
const o = {
|
|
2199
2680
|
...this.createContext(),
|
|
2200
|
-
toolExecutor: this.toolExecutor
|
|
2681
|
+
toolExecutor: this.toolExecutor,
|
|
2682
|
+
signal: r?.signal
|
|
2201
2683
|
}, s = {
|
|
2202
|
-
messages: e.map((n) =>
|
|
2684
|
+
messages: e.map((n) => x(n)),
|
|
2203
2685
|
initial_state: r?.initial_state,
|
|
2204
2686
|
config: r?.config,
|
|
2205
|
-
recursion_limit: r?.recursion_limit
|
|
2687
|
+
recursion_limit: r?.recursion_limit ?? 25,
|
|
2688
|
+
on_busy: r?.on_busy,
|
|
2689
|
+
resume: r?.resume,
|
|
2690
|
+
interrupt_id: r?.interrupt_id,
|
|
2206
2691
|
response_granularity: r?.response_granularity || "full"
|
|
2207
2692
|
};
|
|
2208
|
-
return
|
|
2693
|
+
return nt(o, s, r?.onPartialResult);
|
|
2209
2694
|
}
|
|
2210
2695
|
/**
|
|
2211
2696
|
* Stream invoke to the agent graph
|
|
@@ -2234,15 +2719,19 @@ class st {
|
|
|
2234
2719
|
stream(e, r) {
|
|
2235
2720
|
const o = {
|
|
2236
2721
|
...this.createContext(),
|
|
2237
|
-
toolExecutor: this.toolExecutor
|
|
2722
|
+
toolExecutor: this.toolExecutor,
|
|
2723
|
+
signal: r?.signal
|
|
2238
2724
|
}, s = {
|
|
2239
|
-
messages: e.map((n) =>
|
|
2725
|
+
messages: e.map((n) => x(n)),
|
|
2240
2726
|
initial_state: r?.initial_state,
|
|
2241
2727
|
config: r?.config,
|
|
2242
|
-
recursion_limit: r?.recursion_limit
|
|
2728
|
+
recursion_limit: r?.recursion_limit ?? 25,
|
|
2729
|
+
on_busy: r?.on_busy,
|
|
2730
|
+
resume: r?.resume,
|
|
2731
|
+
interrupt_id: r?.interrupt_id,
|
|
2243
2732
|
response_granularity: r?.response_granularity || "low"
|
|
2244
2733
|
};
|
|
2245
|
-
return
|
|
2734
|
+
return Ye(o, s);
|
|
2246
2735
|
}
|
|
2247
2736
|
/**
|
|
2248
2737
|
* Stream invoke via a persistent WebSocket connection.
|
|
@@ -2283,15 +2772,19 @@ class st {
|
|
|
2283
2772
|
wsStream(e, r) {
|
|
2284
2773
|
const o = {
|
|
2285
2774
|
...this.createContext(),
|
|
2286
|
-
toolExecutor: this.toolExecutor
|
|
2775
|
+
toolExecutor: this.toolExecutor,
|
|
2776
|
+
signal: r?.signal
|
|
2287
2777
|
}, s = {
|
|
2288
|
-
messages: e.map((n) =>
|
|
2778
|
+
messages: e.map((n) => x(n)),
|
|
2289
2779
|
initial_state: r?.initial_state,
|
|
2290
2780
|
config: r?.config,
|
|
2291
2781
|
recursion_limit: r?.recursion_limit ?? 25,
|
|
2782
|
+
on_busy: r?.on_busy,
|
|
2783
|
+
resume: r?.resume,
|
|
2784
|
+
interrupt_id: r?.interrupt_id,
|
|
2292
2785
|
response_granularity: r?.response_granularity ?? "low"
|
|
2293
2786
|
};
|
|
2294
|
-
return
|
|
2787
|
+
return lt(o, s);
|
|
2295
2788
|
}
|
|
2296
2789
|
/**
|
|
2297
2790
|
* Open a realtime (audio-to-audio) session over ``/v1/graph/live``.
|
|
@@ -2303,7 +2796,7 @@ class st {
|
|
|
2303
2796
|
*
|
|
2304
2797
|
* @example
|
|
2305
2798
|
* ```ts
|
|
2306
|
-
* const session = client.realtime({ model: 'gemini-
|
|
2799
|
+
* const session = client.realtime({ model: 'gemini-3.8-live' });
|
|
2307
2800
|
* session.on('audio', (pcm) => speaker.write(pcm));
|
|
2308
2801
|
* session.on('output_transcript', (e) => console.log(e.text));
|
|
2309
2802
|
* await session.ready;
|
|
@@ -2311,8 +2804,12 @@ class st {
|
|
|
2311
2804
|
* ```
|
|
2312
2805
|
*/
|
|
2313
2806
|
realtime(e, r) {
|
|
2314
|
-
const o =
|
|
2315
|
-
|
|
2807
|
+
const o = {
|
|
2808
|
+
...this.createContext(),
|
|
2809
|
+
// Re-resolved on every reconnect so a refreshed token is used
|
|
2810
|
+
getAuthToken: () => typeof this.authToken == "function" ? this.authToken() : this.authToken
|
|
2811
|
+
};
|
|
2812
|
+
return new ft(o, e, r);
|
|
2316
2813
|
}
|
|
2317
2814
|
/**
|
|
2318
2815
|
* Store a memory in the agent's memory system
|
|
@@ -2331,9 +2828,9 @@ class st {
|
|
|
2331
2828
|
* console.log('Memory stored with ID:', result.data.memory_id);
|
|
2332
2829
|
* ```
|
|
2333
2830
|
*/
|
|
2334
|
-
async storeMemory(e) {
|
|
2335
|
-
const
|
|
2336
|
-
return
|
|
2831
|
+
async storeMemory(e, r) {
|
|
2832
|
+
const o = this.createContext(r);
|
|
2833
|
+
return mt(o, e);
|
|
2337
2834
|
}
|
|
2338
2835
|
/**
|
|
2339
2836
|
* Search for memories in the agent's memory system
|
|
@@ -2354,9 +2851,9 @@ class st {
|
|
|
2354
2851
|
* });
|
|
2355
2852
|
* ```
|
|
2356
2853
|
*/
|
|
2357
|
-
async searchMemory(e) {
|
|
2358
|
-
const
|
|
2359
|
-
return
|
|
2854
|
+
async searchMemory(e, r) {
|
|
2855
|
+
const o = this.createContext(r);
|
|
2856
|
+
return Tt(o, e);
|
|
2360
2857
|
}
|
|
2361
2858
|
/**
|
|
2362
2859
|
* Get a specific memory by ID
|
|
@@ -2375,12 +2872,12 @@ class st {
|
|
|
2375
2872
|
* ```
|
|
2376
2873
|
*/
|
|
2377
2874
|
async getMemory(e, r) {
|
|
2378
|
-
const o = this.createContext(), s = {
|
|
2875
|
+
const o = this.createContext(r), s = {
|
|
2379
2876
|
memoryId: e,
|
|
2380
2877
|
config: r?.config,
|
|
2381
2878
|
options: r?.options
|
|
2382
2879
|
};
|
|
2383
|
-
return
|
|
2880
|
+
return bt(o, s);
|
|
2384
2881
|
}
|
|
2385
2882
|
/**
|
|
2386
2883
|
* Update an existing memory by ID
|
|
@@ -2399,14 +2896,14 @@ class st {
|
|
|
2399
2896
|
* ```
|
|
2400
2897
|
*/
|
|
2401
2898
|
async updateMemory(e, r, o) {
|
|
2402
|
-
const s = this.createContext(), n = {
|
|
2899
|
+
const s = this.createContext(o), n = {
|
|
2403
2900
|
memoryId: e,
|
|
2404
2901
|
content: r,
|
|
2405
2902
|
config: o?.config,
|
|
2406
2903
|
options: o?.options,
|
|
2407
2904
|
metadata: o?.metadata
|
|
2408
2905
|
};
|
|
2409
|
-
return
|
|
2906
|
+
return wt(s, n);
|
|
2410
2907
|
}
|
|
2411
2908
|
/**
|
|
2412
2909
|
* Delete a memory by ID
|
|
@@ -2425,12 +2922,12 @@ class st {
|
|
|
2425
2922
|
* ```
|
|
2426
2923
|
*/
|
|
2427
2924
|
async deleteMemory(e, r) {
|
|
2428
|
-
const o = this.createContext(), s = {
|
|
2925
|
+
const o = this.createContext(r), s = {
|
|
2429
2926
|
memoryId: e,
|
|
2430
2927
|
config: r?.config,
|
|
2431
2928
|
options: r?.options
|
|
2432
2929
|
};
|
|
2433
|
-
return
|
|
2930
|
+
return _t(o, s);
|
|
2434
2931
|
}
|
|
2435
2932
|
/**
|
|
2436
2933
|
* List all memories with optional pagination
|
|
@@ -2451,12 +2948,13 @@ class st {
|
|
|
2451
2948
|
* ```
|
|
2452
2949
|
*/
|
|
2453
2950
|
async listMemories(e) {
|
|
2454
|
-
const r = this.createContext(), o = {
|
|
2951
|
+
const r = this.createContext(e), o = {
|
|
2455
2952
|
config: e?.config,
|
|
2456
2953
|
options: e?.options,
|
|
2457
|
-
limit: e?.limit
|
|
2954
|
+
limit: e?.limit,
|
|
2955
|
+
offset: e?.offset
|
|
2458
2956
|
};
|
|
2459
|
-
return
|
|
2957
|
+
return Ct(r, o);
|
|
2460
2958
|
}
|
|
2461
2959
|
/**
|
|
2462
2960
|
* Forget (delete) memories based on filters and criteria
|
|
@@ -2476,14 +2974,14 @@ class st {
|
|
|
2476
2974
|
* ```
|
|
2477
2975
|
*/
|
|
2478
2976
|
async forgetMemories(e) {
|
|
2479
|
-
const r = this.createContext(), o = {
|
|
2977
|
+
const r = this.createContext(e), o = {
|
|
2480
2978
|
config: e?.config,
|
|
2481
2979
|
options: e?.options,
|
|
2482
2980
|
memory_type: e?.memory_type,
|
|
2483
2981
|
category: e?.category,
|
|
2484
2982
|
filters: e?.filters
|
|
2485
2983
|
};
|
|
2486
|
-
return
|
|
2984
|
+
return Et(r, o);
|
|
2487
2985
|
}
|
|
2488
2986
|
// ------------------------------------------------------------------
|
|
2489
2987
|
// Files / Multimodal API
|
|
@@ -2501,164 +2999,191 @@ class st {
|
|
|
2501
2999
|
* const msg = Message.withImage('Describe this', result.data.url);
|
|
2502
3000
|
* ```
|
|
2503
3001
|
*/
|
|
2504
|
-
async uploadFile(e) {
|
|
2505
|
-
const
|
|
2506
|
-
return
|
|
3002
|
+
async uploadFile(e, r) {
|
|
3003
|
+
const o = this.createContext(r);
|
|
3004
|
+
return Gt(o, e);
|
|
2507
3005
|
}
|
|
2508
3006
|
/**
|
|
2509
3007
|
* Download a file by its file_id. Returns raw Blob.
|
|
2510
3008
|
*/
|
|
2511
|
-
async getFile(e) {
|
|
2512
|
-
const
|
|
2513
|
-
return
|
|
3009
|
+
async getFile(e, r) {
|
|
3010
|
+
const o = this.createContext(r);
|
|
3011
|
+
return Rt(o, e);
|
|
3012
|
+
}
|
|
3013
|
+
/**
|
|
3014
|
+
* List the caller's uploaded files (GET /v1/files).
|
|
3015
|
+
* Throws a TenxGraphError with status 501 when the media store cannot enumerate files.
|
|
3016
|
+
*/
|
|
3017
|
+
async listFiles(e, r) {
|
|
3018
|
+
const o = this.createContext(r);
|
|
3019
|
+
return kt(o, e);
|
|
2514
3020
|
}
|
|
2515
3021
|
/**
|
|
2516
3022
|
* Get metadata about a stored file.
|
|
2517
3023
|
*/
|
|
2518
|
-
async getFileInfo(e) {
|
|
2519
|
-
const
|
|
2520
|
-
return
|
|
3024
|
+
async getFileInfo(e, r) {
|
|
3025
|
+
const o = this.createContext(r);
|
|
3026
|
+
return $t(o, e);
|
|
2521
3027
|
}
|
|
2522
3028
|
/**
|
|
2523
3029
|
* Get the best access URL for a stored file.
|
|
2524
3030
|
* For cloud-backed media this will typically be a signed URL.
|
|
2525
3031
|
* For local or memory-backed media this may fall back to the API file route.
|
|
2526
3032
|
*/
|
|
2527
|
-
async getFileAccessUrl(e) {
|
|
2528
|
-
const
|
|
2529
|
-
return
|
|
2530
|
-
}
|
|
2531
|
-
/**
|
|
2532
|
-
* Get the current multimodal configuration from the server.
|
|
2533
|
-
*/
|
|
2534
|
-
async getMultimodalConfig() {
|
|
2535
|
-
const e = this.createContext();
|
|
2536
|
-
return qe(e);
|
|
3033
|
+
async getFileAccessUrl(e, r) {
|
|
3034
|
+
const o = this.createContext(r);
|
|
3035
|
+
return At(o, e);
|
|
2537
3036
|
}
|
|
2538
3037
|
/**
|
|
2539
|
-
*
|
|
2540
|
-
*
|
|
3038
|
+
* Delete a stored file. Only the file's owner can delete it.
|
|
3039
|
+
* Requires the `files:delete` permission; the server returns 404 when the file
|
|
3040
|
+
* does not exist or belongs to someone else.
|
|
3041
|
+
*
|
|
3042
|
+
* @param fileId - The file_id returned by `uploadFile`
|
|
3043
|
+
* @returns DeleteFileResponse with `data.file_id` and `data.deleted`
|
|
2541
3044
|
*/
|
|
2542
|
-
|
|
2543
|
-
const
|
|
2544
|
-
|
|
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;
|
|
3045
|
+
async deleteFile(e, r) {
|
|
3046
|
+
const o = this.createContext(r);
|
|
3047
|
+
return Nt(o, e);
|
|
2548
3048
|
}
|
|
2549
3049
|
/**
|
|
2550
|
-
*
|
|
2551
|
-
* Server requires array of content blocks, not simplified string
|
|
3050
|
+
* Get the current multimodal configuration from the server.
|
|
2552
3051
|
*/
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
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
|
-
});
|
|
3052
|
+
async getMultimodalConfig(e) {
|
|
3053
|
+
const r = this.createContext(e);
|
|
3054
|
+
return Ot(r);
|
|
2560
3055
|
}
|
|
2561
3056
|
}
|
|
2562
|
-
|
|
3057
|
+
function qt(t) {
|
|
3058
|
+
const e = t.data;
|
|
3059
|
+
if (t.event !== "updates" || e === null || typeof e != "object") return null;
|
|
3060
|
+
const r = e.interrupt;
|
|
3061
|
+
return r === null || typeof r != "object" ? null : typeof r.id == "string" ? r : null;
|
|
3062
|
+
}
|
|
3063
|
+
function er(t, e = !0) {
|
|
3064
|
+
return { resume: e, interrupt_id: t.id };
|
|
3065
|
+
}
|
|
3066
|
+
function tr(t) {
|
|
3067
|
+
return { resume: null, interrupt_id: t.id };
|
|
3068
|
+
}
|
|
3069
|
+
class Lt {
|
|
2563
3070
|
constructor() {
|
|
2564
3071
|
this.current_node = "START", this.step = 0, this.is_running = !0, this.is_interrupted = !1, this.is_stopped_requested = !1;
|
|
2565
3072
|
}
|
|
2566
3073
|
}
|
|
2567
|
-
class
|
|
3074
|
+
class rr {
|
|
2568
3075
|
constructor(e = {}) {
|
|
2569
|
-
this.context = [], this.context_summary = null, this.execution_meta = new
|
|
3076
|
+
this.context = [], this.context_summary = null, this.execution_meta = new Lt(), Object.assign(this, e);
|
|
2570
3077
|
}
|
|
2571
3078
|
}
|
|
2572
|
-
const
|
|
3079
|
+
const or = Pt, sr = T;
|
|
2573
3080
|
export {
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
3081
|
+
or as AgentFlowClient,
|
|
3082
|
+
sr as AgentFlowError,
|
|
3083
|
+
rr as AgentState,
|
|
3084
|
+
Jt as AnnotationBlock,
|
|
3085
|
+
Dt as AnnotationRef,
|
|
3086
|
+
ie as AudioBlock,
|
|
3087
|
+
pe as AuthenticationError,
|
|
3088
|
+
fe as BadRequestError,
|
|
3089
|
+
ye as ConflictError,
|
|
3090
|
+
de as DEFAULT_MAX_TOOL_ARGS_BYTES,
|
|
3091
|
+
Mt as DataBlock,
|
|
3092
|
+
yt as DistanceMetric,
|
|
3093
|
+
ce as DocumentBlock,
|
|
3094
|
+
Wt as ErrorBlock,
|
|
3095
|
+
be as GraphError,
|
|
3096
|
+
_e as GraphRecursionError,
|
|
3097
|
+
Z as ImageBlock,
|
|
3098
|
+
O as MediaRef,
|
|
3099
|
+
pt as MemoryType,
|
|
3100
|
+
A as Message,
|
|
3101
|
+
ve as MetricsError,
|
|
3102
|
+
D as NetworkError,
|
|
3103
|
+
we as NodeError,
|
|
3104
|
+
ge as NotFoundError,
|
|
3105
|
+
me as PermissionError,
|
|
3106
|
+
Qt as REALTIME_INPUT_SAMPLE_RATE,
|
|
3107
|
+
dt as REALTIME_OUTPUT_SAMPLE_RATE,
|
|
3108
|
+
Re as RateLimitError,
|
|
3109
|
+
ft as RealtimeSession,
|
|
3110
|
+
Ht as ReasoningBlock,
|
|
3111
|
+
Bt as RemoteToolCallBlock,
|
|
3112
|
+
M as RequestTimeoutError,
|
|
3113
|
+
gt as RetrievalStrategy,
|
|
3114
|
+
Se as SchemaVersionError,
|
|
3115
|
+
Ge as SerializationError,
|
|
3116
|
+
Te as ServerError,
|
|
3117
|
+
Ce as StorageError,
|
|
3118
|
+
V as StreamError,
|
|
3119
|
+
W as StreamEventType,
|
|
3120
|
+
Pt as TenxGraphClient,
|
|
3121
|
+
T as TenxGraphError,
|
|
3122
|
+
X as TextBlock,
|
|
3123
|
+
Vt as TokenUsages,
|
|
3124
|
+
Ft as ToolCallBlock,
|
|
3125
|
+
ue as ToolExecutor,
|
|
3126
|
+
F as ToolResultBlock,
|
|
3127
|
+
Ee as TransientStorageError,
|
|
3128
|
+
Q as ValidationError,
|
|
3129
|
+
ae as VideoBlock,
|
|
3130
|
+
it as WS_BEARER_SUBPROTOCOL,
|
|
3131
|
+
B as WebSocketError,
|
|
3132
|
+
Xe as addThreadMessages,
|
|
3133
|
+
er as approveInterrupt,
|
|
3134
|
+
Kt as basicAuth,
|
|
3135
|
+
Yt as bearerAuth,
|
|
3136
|
+
d as buildHeaders,
|
|
3137
|
+
se as buildWsUrl,
|
|
3138
|
+
he as checkToolArguments,
|
|
3139
|
+
Zt as checkpointMessages,
|
|
3140
|
+
Je as clearThreadState,
|
|
3141
|
+
u as createErrorFromResponse,
|
|
3142
|
+
Nt as deleteFile,
|
|
3143
|
+
_t as deleteMemory,
|
|
3144
|
+
tt as deleteThread,
|
|
3145
|
+
qe as deleteThreadMessage,
|
|
3146
|
+
E as encodePathSegment,
|
|
3147
|
+
f as fetchWithTimeout,
|
|
3148
|
+
St as fixGraph,
|
|
3149
|
+
Et as forgetMemories,
|
|
3150
|
+
Rt as getFile,
|
|
3151
|
+
At as getFileAccessUrl,
|
|
3152
|
+
$t as getFileInfo,
|
|
3153
|
+
qt as getInterrupt,
|
|
3154
|
+
bt as getMemory,
|
|
3155
|
+
Ot as getMultimodalConfig,
|
|
3156
|
+
h as getRequestCredentials,
|
|
3157
|
+
Le as graph,
|
|
3158
|
+
De as graphTools,
|
|
3159
|
+
Xt as headerAuth,
|
|
3160
|
+
nt as invoke,
|
|
3161
|
+
K as linkAbortSignal,
|
|
3162
|
+
kt as listFiles,
|
|
3163
|
+
Ct as listMemories,
|
|
3164
|
+
je as normalizeBaseUrl,
|
|
3165
|
+
le as normalizeToolParameters,
|
|
3166
|
+
Me as observability,
|
|
3167
|
+
ne as openWebSocket,
|
|
3168
|
+
zt as parseErrorResponse,
|
|
3169
|
+
Pe as ping,
|
|
3170
|
+
tr as rejectInterrupt,
|
|
3171
|
+
at as resolveBearerToken,
|
|
3172
|
+
Tt as searchMemory,
|
|
3173
|
+
x as serializeMessage,
|
|
3174
|
+
Fe as stateSchema,
|
|
3175
|
+
vt as stopGraph,
|
|
3176
|
+
mt as storeMemory,
|
|
3177
|
+
Ye as streamInvoke,
|
|
3178
|
+
Qe as threadDetails,
|
|
3179
|
+
Ze as threadMessage,
|
|
3180
|
+
oe as threadMessages,
|
|
3181
|
+
Be as threadState,
|
|
3182
|
+
rt as threads,
|
|
3183
|
+
wt as updateMemory,
|
|
3184
|
+
et as updateThreadMessageFeedback,
|
|
3185
|
+
He as updateThreadState,
|
|
3186
|
+
Gt as uploadFile,
|
|
3187
|
+
lt as wsStreamInvoke
|
|
2663
3188
|
};
|
|
2664
3189
|
//# sourceMappingURL=index.js.map
|