@graphty/graphty-element 2.3.0 → 2.3.1
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/dist/ai.js +115 -222
- package/dist/catalog.js +56 -55
- package/dist/chunks/{AiManager-Bd_r1Hei.js → AiManager-BBmGJbH4.js} +793 -654
- package/dist/chunks/{DataSource-bt0DhBjG.js → DataSource-OeN3NeyD.js} +1 -1
- package/dist/chunks/{GraphSession-iNyKm7Ds.js → GraphSession-Bef1AYw9.js} +2136 -2104
- package/dist/chunks/{GraphStyle-D0PXnZKu.js → GraphStyle-Cwr55SAE.js} +5 -2
- package/dist/chunks/{VoiceInputAdapter-DszYl6Ha.js → VoiceInputAdapter-Dr9Gcmds.js} +1 -1
- package/dist/chunks/{XRPivotCameraController-XtxbbZ-D.js → XRPivotCameraController-BbfgZWpS.js} +1 -1
- package/dist/chunks/algorithms-CpX56sUB.js +3482 -0
- package/dist/chunks/{capability-check-BqIEXcun.js → capability-check-Blhb2aBB.js} +1 -1
- package/dist/chunks/{detect-DM29BEaB.js → detect-Cqwshr9a.js} +1 -1
- package/dist/chunks/{format-detection-BEdmtvsy.js → format-detection-BXGO1lSn.js} +1 -1
- package/dist/chunks/{index-CD0_RJv-.js → index-C0mIoumR.js} +2258 -2129
- package/dist/chunks/optionsFromZod-17lkrAJs.js +2565 -0
- package/dist/chunks/paletteRegistry-x7WOEKZY.js +1153 -0
- package/dist/chunks/scales-BRwl51k8.js +3047 -0
- package/dist/custom-elements.json +1 -1
- package/dist/extend.js +42 -42
- package/dist/graphty-catalog.json +1 -1
- package/dist/graphty.bundle.js +25814 -25456
- package/dist/graphty.js +29 -29
- package/dist/schema.js +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/session.js +28 -29
- package/dist/src/Graph.d.ts +33 -3
- package/dist/src/camera/builtins.d.ts +14 -1
- package/dist/src/camera/types.d.ts +7 -0
- package/dist/src/cameras/CameraManager.d.ts +13 -0
- package/dist/src/cameras/OrbitCameraController.d.ts +9 -0
- package/dist/src/catalog/types.d.ts +10 -0
- package/dist/src/config/GraphStyle.d.ts +5 -1
- package/dist/src/config/StyleTemplate.d.ts +2 -2
- package/dist/src/graphty-element.d.ts +11 -6
- package/dist/src/managers/StylePainter.d.ts +9 -0
- package/dist/src/managers/UpdateManager.d.ts +5 -0
- package/dist/src/session/results/index.d.ts +1 -1
- package/dist/src/session/results/statistics.d.ts +8 -1
- package/dist/src/session/results/types.d.ts +33 -0
- package/dist/src/session/selection/targets.d.ts +4 -1
- package/dist/src/session/styles/predicate.d.ts +26 -1
- package/dist/src/session/styles/repaint.d.ts +11 -0
- package/dist/src/session/styles/selector.d.ts +13 -1
- package/dist/src/session/styles/sources.d.ts +9 -0
- package/package.json +1 -1
- package/dist/chunks/Algorithm-RQ629NLb.js +0 -494
- package/dist/chunks/cameras-ii4vngYY.js +0 -435
- package/dist/chunks/paletteRegistry-DnWHQsAD.js +0 -3166
- package/dist/chunks/scales-DyuwlJKI.js +0 -6087
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { l as
|
|
2
|
-
import { G as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { e as
|
|
6
|
-
import
|
|
7
|
-
import { inferSchema as
|
|
8
|
-
import { i as
|
|
9
|
-
import { createAnthropic as
|
|
10
|
-
import { createGoogleGenerativeAI as
|
|
11
|
-
import { createOpenAI as
|
|
12
|
-
import { generateText as
|
|
13
|
-
import { A as
|
|
14
|
-
class
|
|
1
|
+
import { l as Y } from "./VoiceInputAdapter-Dr9Gcmds.js";
|
|
2
|
+
import { G as J } from "./GraphtyLogger-5KEttFUo.js";
|
|
3
|
+
import { z as c } from "zod";
|
|
4
|
+
import { k as Q, A as x, B as P } from "./optionsFromZod-17lkrAJs.js";
|
|
5
|
+
import { N as ee, e as te, C as se, d as re } from "./algorithms-CpX56sUB.js";
|
|
6
|
+
import ae from "jmespath";
|
|
7
|
+
import { inferSchema as A } from "@jsonhero/schema-infer";
|
|
8
|
+
import { i as oe } from "./GraphtyError-BwcnblTH.js";
|
|
9
|
+
import { createAnthropic as ne } from "@ai-sdk/anthropic";
|
|
10
|
+
import { createGoogleGenerativeAI as ie } from "@ai-sdk/google";
|
|
11
|
+
import { createOpenAI as le } from "@ai-sdk/openai";
|
|
12
|
+
import { generateText as ce, streamText as ue } from "ai";
|
|
13
|
+
import { A as de } from "./ApiKeyManager-C0ac91dE.js";
|
|
14
|
+
class F {
|
|
15
15
|
/**
|
|
16
16
|
* Creates a new AiStatusManager instance.
|
|
17
17
|
*/
|
|
@@ -111,18 +111,18 @@ class I {
|
|
|
111
111
|
* @param status - New status for the tool call
|
|
112
112
|
* @param result - Optional result data
|
|
113
113
|
*/
|
|
114
|
-
updateToolCallStatus(e, t,
|
|
115
|
-
const { toolCalls:
|
|
116
|
-
if (!
|
|
114
|
+
updateToolCallStatus(e, t, s) {
|
|
115
|
+
const { toolCalls: r } = this.status;
|
|
116
|
+
if (!r)
|
|
117
117
|
return;
|
|
118
|
-
const o =
|
|
118
|
+
const o = r.findIndex((l) => l.name === e);
|
|
119
119
|
if (o === -1)
|
|
120
120
|
return;
|
|
121
|
-
const n = [...
|
|
121
|
+
const n = [...r];
|
|
122
122
|
n[o] = {
|
|
123
123
|
...n[o],
|
|
124
124
|
status: t,
|
|
125
|
-
result:
|
|
125
|
+
result: s
|
|
126
126
|
}, this.status = {
|
|
127
127
|
...this.status,
|
|
128
128
|
toolCalls: n
|
|
@@ -186,14 +186,14 @@ class I {
|
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
const f =
|
|
190
|
-
class
|
|
189
|
+
const f = J.getLogger(["graphty", "ai"]);
|
|
190
|
+
class me {
|
|
191
191
|
/**
|
|
192
192
|
* Creates a new AiController instance.
|
|
193
193
|
* @param options - Configuration options for the controller
|
|
194
194
|
*/
|
|
195
195
|
constructor(e) {
|
|
196
|
-
this.abortController = null, this.disposed = !1, this.currentInput = null, this.startTime = null, this.lastInput = null, this.lastError = null, this.provider = e.provider, this.commandRegistry = e.commandRegistry, this.graph = e.graph, this.statusManager = new
|
|
196
|
+
this.abortController = null, this.disposed = !1, this.currentInput = null, this.startTime = null, this.lastInput = null, this.lastError = null, this.provider = e.provider, this.commandRegistry = e.commandRegistry, this.graph = e.graph, this.statusManager = new F(), this.schemaManager = e.schemaManager ?? null, this.emitEvent = e.emitEvent, this.statusManager.subscribe((t) => {
|
|
197
197
|
this.emitAiEvent({
|
|
198
198
|
type: "ai-status-change",
|
|
199
199
|
status: t
|
|
@@ -224,22 +224,22 @@ class re {
|
|
|
224
224
|
timestamp: this.startTime
|
|
225
225
|
}), this.statusManager.submit();
|
|
226
226
|
try {
|
|
227
|
-
const t = this.buildMessages(e),
|
|
228
|
-
f.debug("Request", { messages: t, tools:
|
|
229
|
-
const
|
|
227
|
+
const t = this.buildMessages(e), s = this.commandRegistry.toToolDefinitions();
|
|
228
|
+
f.debug("Request", { messages: t, tools: s.map((n) => n.name) }), this.statusManager.startStreaming();
|
|
229
|
+
const r = await this.provider.generate(t, s, { signal: this.abortController.signal });
|
|
230
230
|
if (f.debug("Response", {
|
|
231
|
-
text:
|
|
232
|
-
toolCalls:
|
|
233
|
-
}),
|
|
231
|
+
text: r.text || "(no text)",
|
|
232
|
+
toolCalls: r.toolCalls.map((n) => ({ name: n.name, arguments: n.arguments }))
|
|
233
|
+
}), r.text && (this.statusManager.appendStreamedText(r.text), this.emitAiEvent({
|
|
234
234
|
type: "ai-stream-chunk",
|
|
235
|
-
text:
|
|
236
|
-
accumulated:
|
|
237
|
-
})),
|
|
235
|
+
text: r.text,
|
|
236
|
+
accumulated: r.text
|
|
237
|
+
})), r.toolCalls.length === 0) {
|
|
238
238
|
this.statusManager.complete();
|
|
239
239
|
const n = {
|
|
240
240
|
success: !0,
|
|
241
|
-
message:
|
|
242
|
-
llmText:
|
|
241
|
+
message: r.text || "No response from AI",
|
|
242
|
+
llmText: r.text
|
|
243
243
|
};
|
|
244
244
|
return this.emitAiEvent({
|
|
245
245
|
type: "ai-command-complete",
|
|
@@ -248,22 +248,22 @@ class re {
|
|
|
248
248
|
}), n;
|
|
249
249
|
}
|
|
250
250
|
this.statusManager.startExecuting();
|
|
251
|
-
const o = await this.executeToolCalls(
|
|
251
|
+
const o = await this.executeToolCalls(r.toolCalls, r.text);
|
|
252
252
|
return this.statusManager.complete(), this.emitAiEvent({
|
|
253
253
|
type: "ai-command-complete",
|
|
254
254
|
result: o,
|
|
255
255
|
duration: Date.now() - this.startTime
|
|
256
256
|
}), o;
|
|
257
257
|
} catch (t) {
|
|
258
|
-
const
|
|
259
|
-
return this.lastError =
|
|
258
|
+
const s = t instanceof Error ? t.message : String(t), r = t instanceof Error ? t : new Error(s);
|
|
259
|
+
return this.lastError = r, this.statusManager.setError(r, !0), this.emitAiEvent({
|
|
260
260
|
type: "ai-command-error",
|
|
261
|
-
error:
|
|
261
|
+
error: r,
|
|
262
262
|
input: e,
|
|
263
263
|
canRetry: !0
|
|
264
264
|
}), {
|
|
265
265
|
success: !1,
|
|
266
|
-
message: `Error: ${
|
|
266
|
+
message: `Error: ${s}`
|
|
267
267
|
};
|
|
268
268
|
} finally {
|
|
269
269
|
this.abortController = null, this.currentInput = null;
|
|
@@ -327,22 +327,22 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
327
327
|
* @returns Combined execution result
|
|
328
328
|
*/
|
|
329
329
|
async executeToolCalls(e, t) {
|
|
330
|
-
const
|
|
331
|
-
for (const
|
|
332
|
-
this.statusManager.addToolCall(
|
|
330
|
+
const s = [];
|
|
331
|
+
for (const r of e) {
|
|
332
|
+
this.statusManager.addToolCall(r.name), this.statusManager.updateToolCallStatus(r.name, "executing"), this.emitAiEvent({
|
|
333
333
|
type: "ai-stream-tool-call",
|
|
334
|
-
name:
|
|
335
|
-
params:
|
|
334
|
+
name: r.name,
|
|
335
|
+
params: r.arguments
|
|
336
336
|
});
|
|
337
337
|
try {
|
|
338
|
-
const o = await this.executeToolCall(
|
|
339
|
-
if (
|
|
340
|
-
|
|
338
|
+
const o = await this.executeToolCall(r);
|
|
339
|
+
if (s.push(o), this.statusManager.updateToolCallStatus(
|
|
340
|
+
r.name,
|
|
341
341
|
o.success ? "complete" : "error",
|
|
342
342
|
o.data ?? { message: o.message }
|
|
343
343
|
), this.emitAiEvent({
|
|
344
344
|
type: "ai-stream-tool-result",
|
|
345
|
-
name:
|
|
345
|
+
name: r.name,
|
|
346
346
|
result: o.data ?? { message: o.message },
|
|
347
347
|
success: o.success
|
|
348
348
|
}), !o.success)
|
|
@@ -350,18 +350,18 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
350
350
|
} catch (o) {
|
|
351
351
|
const n = o instanceof Error ? o.message : String(o), l = {
|
|
352
352
|
success: !1,
|
|
353
|
-
message: `Error executing ${
|
|
353
|
+
message: `Error executing ${r.name}: ${n}`
|
|
354
354
|
};
|
|
355
|
-
|
|
355
|
+
s.push(l), this.statusManager.updateToolCallStatus(r.name, "error", { error: n }), this.emitAiEvent({
|
|
356
356
|
type: "ai-stream-tool-result",
|
|
357
|
-
name:
|
|
357
|
+
name: r.name,
|
|
358
358
|
result: { error: n },
|
|
359
359
|
success: !1
|
|
360
360
|
});
|
|
361
361
|
break;
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
|
-
return this.combineResults(
|
|
364
|
+
return this.combineResults(s, t);
|
|
365
365
|
}
|
|
366
366
|
/**
|
|
367
367
|
* Execute a single tool call.
|
|
@@ -376,9 +376,9 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
376
376
|
success: !1,
|
|
377
377
|
message: `Unknown command: ${e.name}. Command not found in registry.`
|
|
378
378
|
};
|
|
379
|
-
let
|
|
379
|
+
let s;
|
|
380
380
|
try {
|
|
381
|
-
|
|
381
|
+
s = t.parameters.parse(e.arguments), f.debug("Validated arguments", { arguments: s });
|
|
382
382
|
} catch (n) {
|
|
383
383
|
const l = n instanceof Error ? n.message : String(n);
|
|
384
384
|
return f.debug("Command result: FAILED - Invalid arguments", { error: l }), {
|
|
@@ -386,7 +386,7 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
386
386
|
message: `Invalid arguments for ${e.name}: ${l}`
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
const
|
|
389
|
+
const r = {
|
|
390
390
|
graph: this.graph,
|
|
391
391
|
abortSignal: this.abortController?.signal ?? new AbortController().signal,
|
|
392
392
|
emitEvent: (n, l) => {
|
|
@@ -395,7 +395,7 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
395
395
|
updateStatus: (n) => {
|
|
396
396
|
n.stageMessage && this.statusManager.setStage("executing", n.stageMessage);
|
|
397
397
|
}
|
|
398
|
-
}, o = await t.execute(this.graph,
|
|
398
|
+
}, o = await t.execute(this.graph, s, r);
|
|
399
399
|
return f.debug("Command result", {
|
|
400
400
|
success: o.success,
|
|
401
401
|
message: o.message,
|
|
@@ -415,12 +415,12 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
415
415
|
message: t ?? "No commands executed",
|
|
416
416
|
llmText: t
|
|
417
417
|
};
|
|
418
|
-
const
|
|
419
|
-
t &&
|
|
420
|
-
const o = e.flatMap((i) => i.affectedNodes ?? [])
|
|
418
|
+
const s = e.every((i) => i.success), r = e.map((i) => i.message);
|
|
419
|
+
t && r.unshift(t);
|
|
420
|
+
const o = [...new Set(e.flatMap((i) => i.affectedNodes ?? []))], n = [...new Set(e.flatMap((i) => i.affectedEdges ?? []))], l = e.filter((i) => i.success).pop() ?? e[e.length - 1];
|
|
421
421
|
return {
|
|
422
|
-
success:
|
|
423
|
-
message:
|
|
422
|
+
success: s,
|
|
423
|
+
message: r.join(`
|
|
424
424
|
`),
|
|
425
425
|
data: l.data,
|
|
426
426
|
affectedNodes: o.length > 0 ? o : void 0,
|
|
@@ -460,7 +460,7 @@ ${this.schemaManager.getFormattedSchema()}
|
|
|
460
460
|
this.disposed = !0, this.cancel(), this.statusManager.reset();
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
|
-
class
|
|
463
|
+
class pe {
|
|
464
464
|
constructor() {
|
|
465
465
|
this.commands = /* @__PURE__ */ new Map();
|
|
466
466
|
}
|
|
@@ -529,7 +529,7 @@ class ae {
|
|
|
529
529
|
}));
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
-
const
|
|
532
|
+
const he = {
|
|
533
533
|
maxSampleSize: 1e3,
|
|
534
534
|
maxDepth: 3,
|
|
535
535
|
enumMaxAbsoluteUnique: 10,
|
|
@@ -537,7 +537,7 @@ const oe = {
|
|
|
537
537
|
enumMaxStringLength: 64,
|
|
538
538
|
enumMinSampleSize: 25
|
|
539
539
|
};
|
|
540
|
-
class
|
|
540
|
+
class ge {
|
|
541
541
|
constructor(e) {
|
|
542
542
|
this.values = /* @__PURE__ */ new Map(), this.options = e;
|
|
543
543
|
}
|
|
@@ -548,8 +548,8 @@ class ne {
|
|
|
548
548
|
*/
|
|
549
549
|
trackValue(e, t) {
|
|
550
550
|
this.values.has(e) || this.values.set(e, []);
|
|
551
|
-
const
|
|
552
|
-
|
|
551
|
+
const s = this.values.get(e);
|
|
552
|
+
s && s.push(t);
|
|
553
553
|
}
|
|
554
554
|
/**
|
|
555
555
|
* Recursively track string values from an object.
|
|
@@ -557,13 +557,13 @@ class ne {
|
|
|
557
557
|
* @param prefix - Property path prefix
|
|
558
558
|
* @param depth - Current recursion depth
|
|
559
559
|
*/
|
|
560
|
-
trackObject(e, t = "",
|
|
561
|
-
if (!(
|
|
562
|
-
for (const [
|
|
563
|
-
if (t === "" &&
|
|
560
|
+
trackObject(e, t = "", s = 0) {
|
|
561
|
+
if (!(s >= this.options.maxDepth))
|
|
562
|
+
for (const [r, o] of Object.entries(e)) {
|
|
563
|
+
if (t === "" && r === "id")
|
|
564
564
|
continue;
|
|
565
|
-
const n = t ? `${t}.${
|
|
566
|
-
typeof o == "string" ? this.trackValue(n, o) : o !== null && typeof o == "object" && !Array.isArray(o) && this.trackObject(o, n,
|
|
565
|
+
const n = t ? `${t}.${r}` : r;
|
|
566
|
+
typeof o == "string" ? this.trackValue(n, o) : o !== null && typeof o == "object" && !Array.isArray(o) && this.trackObject(o, n, s + 1);
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
/**
|
|
@@ -581,30 +581,30 @@ class ne {
|
|
|
581
581
|
const t = this.values.get(e);
|
|
582
582
|
if (!t || t.length < this.options.enumMinSampleSize)
|
|
583
583
|
return { isEnum: !1 };
|
|
584
|
-
const
|
|
585
|
-
return o && n ? { isEnum: !0, values:
|
|
584
|
+
const s = [...new Set(t)], r = s.length / t.length, o = s.length <= this.options.enumMaxAbsoluteUnique || r <= this.options.enumMaxUniqueRatio, n = s.every((l) => l.length <= this.options.enumMaxStringLength);
|
|
585
|
+
return o && n ? { isEnum: !0, values: s.sort() } : { isEnum: !1 };
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
|
-
class
|
|
588
|
+
class O {
|
|
589
589
|
/**
|
|
590
590
|
* Creates a new SchemaExtractor instance.
|
|
591
591
|
* @param graph - The graph to extract schema from
|
|
592
592
|
* @param options - Optional extraction options
|
|
593
593
|
*/
|
|
594
594
|
constructor(e, t = {}) {
|
|
595
|
-
this.graph = e, this.options = { ...
|
|
595
|
+
this.graph = e, this.options = { ...he, ...t };
|
|
596
596
|
}
|
|
597
597
|
/**
|
|
598
598
|
* Extract schema from the graph.
|
|
599
599
|
* @returns SchemaSummary with node and edge property information
|
|
600
600
|
*/
|
|
601
601
|
extract() {
|
|
602
|
-
const e = this.graph.getDataManager(), t = this.graph.getNodeCount(),
|
|
602
|
+
const e = this.graph.getDataManager(), t = this.graph.getNodeCount(), s = this.graph.getEdgeCount(), r = Array.from(e.nodes.values()).map((n) => n.data).filter((n) => n !== void 0), o = Array.from(e.edges.values()).map((n) => n.data).filter((n) => n !== void 0);
|
|
603
603
|
return {
|
|
604
|
-
nodeProperties: this.extractFromCollection(
|
|
604
|
+
nodeProperties: this.extractFromCollection(r),
|
|
605
605
|
edgeProperties: this.extractFromCollection(o),
|
|
606
606
|
nodeCount: t,
|
|
607
|
-
edgeCount:
|
|
607
|
+
edgeCount: s
|
|
608
608
|
};
|
|
609
609
|
}
|
|
610
610
|
/**
|
|
@@ -615,14 +615,14 @@ class D {
|
|
|
615
615
|
extractFromCollection(e) {
|
|
616
616
|
if (e.length === 0)
|
|
617
617
|
return [];
|
|
618
|
-
const t = e.length <= this.options.maxSampleSize ? e : this.sampleEvenly(e, this.options.maxSampleSize), [
|
|
619
|
-
let o =
|
|
620
|
-
for (const i of
|
|
621
|
-
o =
|
|
618
|
+
const t = e.length <= this.options.maxSampleSize ? e : this.sampleEvenly(e, this.options.maxSampleSize), [s, ...r] = t;
|
|
619
|
+
let o = A(s);
|
|
620
|
+
for (const i of r)
|
|
621
|
+
o = A(
|
|
622
622
|
i,
|
|
623
623
|
o
|
|
624
624
|
);
|
|
625
|
-
const n = o.toSnapshot(), l = new
|
|
625
|
+
const n = o.toSnapshot(), l = new ge(this.options);
|
|
626
626
|
for (const i of t)
|
|
627
627
|
l.trackObject(i, "", 0);
|
|
628
628
|
return this.mergeResults(n, l);
|
|
@@ -634,14 +634,14 @@ class D {
|
|
|
634
634
|
* @returns Array of merged property summaries
|
|
635
635
|
*/
|
|
636
636
|
mergeResults(e, t) {
|
|
637
|
-
const
|
|
637
|
+
const s = [];
|
|
638
638
|
if (e.type === "object" && e.properties) {
|
|
639
|
-
for (const [
|
|
640
|
-
this.extractProperties(
|
|
641
|
-
for (const [
|
|
642
|
-
this.extractProperties(
|
|
639
|
+
for (const [r, o] of Object.entries(e.properties.required))
|
|
640
|
+
this.extractProperties(r, o, t, "", !1, s);
|
|
641
|
+
for (const [r, o] of Object.entries(e.properties.optional))
|
|
642
|
+
this.extractProperties(r, o, t, "", !0, s);
|
|
643
643
|
}
|
|
644
|
-
return
|
|
644
|
+
return s.sort((r, o) => r.name.localeCompare(o.name));
|
|
645
645
|
}
|
|
646
646
|
/**
|
|
647
647
|
* Recursively extract properties, handling nested objects with dot notation.
|
|
@@ -653,19 +653,19 @@ class D {
|
|
|
653
653
|
* @param properties - Array to accumulate property summaries
|
|
654
654
|
* @param depth - Current recursion depth
|
|
655
655
|
*/
|
|
656
|
-
extractProperties(e, t,
|
|
657
|
-
const i =
|
|
658
|
-
if (
|
|
656
|
+
extractProperties(e, t, s, r, o, n, l = 0) {
|
|
657
|
+
const i = r ? `${r}.${e}` : e;
|
|
658
|
+
if (r === "" && e === "id" || l >= this.options.maxDepth)
|
|
659
659
|
return;
|
|
660
|
-
let u = o,
|
|
661
|
-
if (t.type === "nullable" && t.schema && (u = !0,
|
|
662
|
-
for (const [
|
|
663
|
-
this.extractProperties(
|
|
664
|
-
for (const [
|
|
665
|
-
this.extractProperties(
|
|
660
|
+
let u = o, d = t;
|
|
661
|
+
if (t.type === "nullable" && t.schema && (u = !0, d = t.schema), d.type === "object" && d.properties) {
|
|
662
|
+
for (const [m, h] of Object.entries(d.properties.required))
|
|
663
|
+
this.extractProperties(m, h, s, i, !1, n, l + 1);
|
|
664
|
+
for (const [m, h] of Object.entries(d.properties.optional))
|
|
665
|
+
this.extractProperties(m, h, s, i, !0, n, l + 1);
|
|
666
666
|
return;
|
|
667
667
|
}
|
|
668
|
-
const p = this.schemaToSummary(i,
|
|
668
|
+
const p = this.schemaToSummary(i, d, s, u);
|
|
669
669
|
p && n.push(p);
|
|
670
670
|
}
|
|
671
671
|
/**
|
|
@@ -676,16 +676,16 @@ class D {
|
|
|
676
676
|
* @param nullable - Whether the property can be null
|
|
677
677
|
* @returns Property summary or null if not convertible
|
|
678
678
|
*/
|
|
679
|
-
schemaToSummary(e, t,
|
|
679
|
+
schemaToSummary(e, t, s, r) {
|
|
680
680
|
const o = {
|
|
681
681
|
name: e,
|
|
682
682
|
type: this.inferredTypeToPropertyType(t),
|
|
683
|
-
nullable:
|
|
683
|
+
nullable: r
|
|
684
684
|
};
|
|
685
685
|
switch (t.type) {
|
|
686
686
|
case "string": {
|
|
687
687
|
t.format?.name && (o.format = t.format.name);
|
|
688
|
-
const n =
|
|
688
|
+
const n = s.getEnumAnalysis(e);
|
|
689
689
|
n.isEnum && n.values && (o.enumValues = n.values);
|
|
690
690
|
break;
|
|
691
691
|
}
|
|
@@ -735,19 +735,19 @@ class D {
|
|
|
735
735
|
* @returns Array of evenly distributed samples
|
|
736
736
|
*/
|
|
737
737
|
sampleEvenly(e, t) {
|
|
738
|
-
const
|
|
738
|
+
const s = [], r = e.length / t;
|
|
739
739
|
for (let o = 0; o < t; o++) {
|
|
740
|
-
const n = Math.floor(o *
|
|
741
|
-
|
|
740
|
+
const n = Math.floor(o * r);
|
|
741
|
+
s.push(e[n]);
|
|
742
742
|
}
|
|
743
|
-
return
|
|
743
|
+
return s;
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
|
-
const
|
|
746
|
+
const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"]).describe("Type of information to query about the graph"), ye = {
|
|
747
747
|
name: "queryGraph",
|
|
748
748
|
description: "Query information about the graph structure, including node count, edge count, current layout, and overall statistics.",
|
|
749
|
-
parameters:
|
|
750
|
-
query:
|
|
749
|
+
parameters: c.object({
|
|
750
|
+
query: fe
|
|
751
751
|
}),
|
|
752
752
|
examples: [
|
|
753
753
|
{ input: "How many nodes are there?", params: { query: "nodeCount" } },
|
|
@@ -756,106 +756,106 @@ const ie = m.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
|
|
|
756
756
|
{ input: "Show me the graph summary", params: { query: "summary" } },
|
|
757
757
|
{ input: "Give me all the graph stats", params: { query: "all" } }
|
|
758
758
|
],
|
|
759
|
-
execute(
|
|
759
|
+
execute(a, e) {
|
|
760
760
|
const { query: t } = e;
|
|
761
761
|
try {
|
|
762
762
|
switch (t) {
|
|
763
763
|
case "nodeCount": {
|
|
764
|
-
const
|
|
764
|
+
const s = a.getNodeCount();
|
|
765
765
|
return Promise.resolve({
|
|
766
766
|
success: !0,
|
|
767
|
-
message: `The graph has ${
|
|
768
|
-
data: { nodeCount:
|
|
767
|
+
message: `The graph has ${s} node${s !== 1 ? "s" : ""}.`,
|
|
768
|
+
data: { nodeCount: s }
|
|
769
769
|
});
|
|
770
770
|
}
|
|
771
771
|
case "edgeCount": {
|
|
772
|
-
const
|
|
772
|
+
const s = a.getEdgeCount();
|
|
773
773
|
return Promise.resolve({
|
|
774
774
|
success: !0,
|
|
775
|
-
message: `The graph has ${
|
|
776
|
-
data: { edgeCount:
|
|
775
|
+
message: `The graph has ${s} edge${s !== 1 ? "s" : ""}.`,
|
|
776
|
+
data: { edgeCount: s }
|
|
777
777
|
});
|
|
778
778
|
}
|
|
779
779
|
case "currentLayout": {
|
|
780
|
-
const
|
|
780
|
+
const r = a.getLayoutManager().layoutEngine?.type ?? "unknown";
|
|
781
781
|
return Promise.resolve({
|
|
782
782
|
success: !0,
|
|
783
|
-
message: `The current layout is "${
|
|
784
|
-
data: { layout:
|
|
783
|
+
message: `The current layout is "${r}".`,
|
|
784
|
+
data: { layout: r }
|
|
785
785
|
});
|
|
786
786
|
}
|
|
787
787
|
case "all":
|
|
788
788
|
case "summary": {
|
|
789
|
-
const
|
|
789
|
+
const s = a.getNodeCount(), r = a.getEdgeCount(), n = a.getLayoutManager().layoutEngine?.type ?? "unknown", l = a.getViewMode() === "2d";
|
|
790
790
|
return Promise.resolve({
|
|
791
791
|
success: !0,
|
|
792
792
|
message: `Graph Summary:
|
|
793
|
-
- Nodes: ${
|
|
794
|
-
- Edges: ${
|
|
793
|
+
- Nodes: ${s}
|
|
794
|
+
- Edges: ${r}
|
|
795
795
|
- Layout: ${n}
|
|
796
796
|
- Mode: ${l ? "2D" : "3D"}`,
|
|
797
797
|
data: {
|
|
798
|
-
nodeCount:
|
|
799
|
-
edgeCount:
|
|
798
|
+
nodeCount: s,
|
|
799
|
+
edgeCount: r,
|
|
800
800
|
layout: n,
|
|
801
801
|
is2D: l
|
|
802
802
|
}
|
|
803
803
|
});
|
|
804
804
|
}
|
|
805
805
|
default: {
|
|
806
|
-
const
|
|
806
|
+
const s = a.getNodeCount(), r = a.getEdgeCount();
|
|
807
807
|
return Promise.resolve({
|
|
808
808
|
success: !0,
|
|
809
|
-
message: `Unknown query type "${String(t)}". The graph has ${
|
|
810
|
-
data: { nodeCount:
|
|
809
|
+
message: `Unknown query type "${String(t)}". The graph has ${s} nodes and ${r} edges.`,
|
|
810
|
+
data: { nodeCount: s, edgeCount: r }
|
|
811
811
|
});
|
|
812
812
|
}
|
|
813
813
|
}
|
|
814
|
-
} catch (
|
|
814
|
+
} catch (s) {
|
|
815
815
|
return Promise.resolve({
|
|
816
816
|
success: !1,
|
|
817
|
-
message: `Failed to query graph: ${
|
|
817
|
+
message: `Failed to query graph: ${s.message}`
|
|
818
818
|
});
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
|
-
},
|
|
821
|
+
}, ve = 50, be = {
|
|
822
822
|
name: "findNodes",
|
|
823
|
-
description: "Find nodes in the graph that match specific criteria. Returns matching node IDs
|
|
824
|
-
parameters:
|
|
825
|
-
selector:
|
|
823
|
+
description: "Find nodes in the graph that match specific criteria. Returns the total number of matches and at most `limit` matching node IDs (50 when no limit is given), with `truncated` true when the list was cut. Note: selectors search within node data directly, so use 'type' not 'data.type'.",
|
|
824
|
+
parameters: c.object({
|
|
825
|
+
selector: c.string().describe(
|
|
826
826
|
`Simple selector to match nodes (e.g., 'type == "server"'). Search is performed on node data directly, so use property names like 'type' not 'data.type'.`
|
|
827
827
|
),
|
|
828
|
-
limit:
|
|
828
|
+
limit: c.number().optional().describe("Maximum number of node IDs to return (default 50)")
|
|
829
829
|
}),
|
|
830
830
|
examples: [
|
|
831
831
|
{ input: "Find all server nodes", params: { selector: "type == 'server'" } },
|
|
832
832
|
{ input: "Find nodes with high degree", params: { selector: "degree > 5" } },
|
|
833
833
|
{ input: "Get first 10 nodes", params: { selector: "", limit: 10 } }
|
|
834
834
|
],
|
|
835
|
-
execute(
|
|
836
|
-
const { selector: t, limit:
|
|
835
|
+
execute(a, e) {
|
|
836
|
+
const { selector: t, limit: s } = e;
|
|
837
837
|
try {
|
|
838
|
-
const
|
|
838
|
+
const r = a.getDataManager(), o = Array.from(r.nodes.values());
|
|
839
839
|
let n;
|
|
840
|
-
!t || t === "" || t === "*" ? n = o : n = o.filter((
|
|
840
|
+
!t || t === "" || t === "*" ? n = o : n = o.filter((p) => {
|
|
841
841
|
try {
|
|
842
|
-
const
|
|
843
|
-
if (
|
|
844
|
-
const [,
|
|
845
|
-
return typeof
|
|
842
|
+
const m = /^(\w+)\s*==\s*['"](.+)['"]$/.exec(t);
|
|
843
|
+
if (m) {
|
|
844
|
+
const [, g, b] = m, v = p.data[g];
|
|
845
|
+
return typeof v == "boolean" ? v === (b === "true") : v === b;
|
|
846
846
|
}
|
|
847
|
-
const
|
|
848
|
-
if (
|
|
849
|
-
const [,
|
|
850
|
-
switch (
|
|
847
|
+
const h = /^(\w+)\s*(>|<|>=|<=)\s*(\d+)$/.exec(t);
|
|
848
|
+
if (h) {
|
|
849
|
+
const [, g, b, v] = h, w = Number(p.data[g]), S = Number(v);
|
|
850
|
+
switch (b) {
|
|
851
851
|
case ">":
|
|
852
|
-
return
|
|
852
|
+
return w > S;
|
|
853
853
|
case "<":
|
|
854
|
-
return
|
|
854
|
+
return w < S;
|
|
855
855
|
case ">=":
|
|
856
|
-
return
|
|
856
|
+
return w >= S;
|
|
857
857
|
case "<=":
|
|
858
|
-
return
|
|
858
|
+
return w <= S;
|
|
859
859
|
default:
|
|
860
860
|
return !1;
|
|
861
861
|
}
|
|
@@ -864,29 +864,32 @@ const ie = m.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
|
|
|
864
864
|
} catch {
|
|
865
865
|
return !1;
|
|
866
866
|
}
|
|
867
|
-
})
|
|
868
|
-
const l = n.map((
|
|
867
|
+
});
|
|
868
|
+
const l = n.length, i = n.slice(0, s !== void 0 && s > 0 ? s : ve).map((p) => String(p.id)), u = i.length, d = l > u;
|
|
869
869
|
return Promise.resolve({
|
|
870
870
|
success: !0,
|
|
871
|
-
message: `Found ${l
|
|
871
|
+
message: `Found ${l} matching node${l !== 1 ? "s" : ""}${d ? ` (showing ${u})` : ""}.`,
|
|
872
872
|
data: {
|
|
873
|
-
|
|
874
|
-
|
|
873
|
+
total: l,
|
|
874
|
+
returned: u,
|
|
875
|
+
count: u,
|
|
876
|
+
truncated: d,
|
|
877
|
+
nodeIds: i
|
|
875
878
|
},
|
|
876
|
-
affectedNodes:
|
|
879
|
+
affectedNodes: i
|
|
877
880
|
});
|
|
878
|
-
} catch (
|
|
881
|
+
} catch (r) {
|
|
879
882
|
return Promise.resolve({
|
|
880
883
|
success: !1,
|
|
881
|
-
message: `Failed to find nodes: ${
|
|
884
|
+
message: `Failed to find nodes: ${r.message}`
|
|
882
885
|
});
|
|
883
886
|
}
|
|
884
887
|
}
|
|
885
|
-
},
|
|
888
|
+
}, we = c.enum(["nodeTypes", "edgeTypes", "nodeProperties", "edgeProperties", "all"]).describe("Type of schema information to retrieve"), Se = {
|
|
886
889
|
name: "getSchema",
|
|
887
890
|
description: "Get schema information about the graph data including node types, edge types, and available properties. Use this to discover what types of nodes exist or what properties are available for filtering.",
|
|
888
|
-
parameters:
|
|
889
|
-
query:
|
|
891
|
+
parameters: c.object({
|
|
892
|
+
query: we
|
|
890
893
|
}),
|
|
891
894
|
examples: [
|
|
892
895
|
{ input: "What types of nodes are there?", params: { query: "nodeTypes" } },
|
|
@@ -895,21 +898,21 @@ const ie = m.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
|
|
|
895
898
|
{ input: "What edge properties are available?", params: { query: "edgeProperties" } },
|
|
896
899
|
{ input: "Show me the data schema", params: { query: "all" } }
|
|
897
900
|
],
|
|
898
|
-
execute(
|
|
901
|
+
execute(a, e) {
|
|
899
902
|
const { query: t } = e;
|
|
900
903
|
try {
|
|
901
|
-
const
|
|
902
|
-
const
|
|
904
|
+
const r = new O(a).extract(), o = a.getDataManager(), n = (l, i, u = 20) => {
|
|
905
|
+
const d = /* @__PURE__ */ new Set();
|
|
903
906
|
for (const p of l) {
|
|
904
|
-
const
|
|
905
|
-
if (typeof
|
|
907
|
+
const m = p.data?.[i];
|
|
908
|
+
if (typeof m == "string" && (d.add(m), d.size > u))
|
|
906
909
|
return [];
|
|
907
910
|
}
|
|
908
|
-
return Array.from(
|
|
911
|
+
return Array.from(d).sort();
|
|
909
912
|
};
|
|
910
913
|
switch (t) {
|
|
911
914
|
case "nodeTypes": {
|
|
912
|
-
let i =
|
|
915
|
+
let i = r.nodeProperties.find((u) => u.name === "type")?.enumValues ?? [];
|
|
913
916
|
return i.length === 0 && (i = n(o.nodes.values(), "type")), i.length === 0 ? Promise.resolve({
|
|
914
917
|
success: !0,
|
|
915
918
|
message: "No distinct node types found. Nodes may not have a 'type' property, or there are too many unique values to categorize.",
|
|
@@ -921,7 +924,7 @@ const ie = m.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
|
|
|
921
924
|
});
|
|
922
925
|
}
|
|
923
926
|
case "edgeTypes": {
|
|
924
|
-
let i =
|
|
927
|
+
let i = r.edgeProperties.find((u) => u.name === "type")?.enumValues ?? [];
|
|
925
928
|
return i.length === 0 && (i = n(o.edges.values(), "type")), i.length === 0 ? Promise.resolve({
|
|
926
929
|
success: !0,
|
|
927
930
|
message: "No distinct edge types found. Edges may not have a 'type' property, or there are too many unique values to categorize.",
|
|
@@ -933,7 +936,7 @@ const ie = m.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
|
|
|
933
936
|
});
|
|
934
937
|
}
|
|
935
938
|
case "nodeProperties": {
|
|
936
|
-
const l =
|
|
939
|
+
const l = r.nodeProperties.map((i) => {
|
|
937
940
|
let u = `${i.name}: ${i.type}`;
|
|
938
941
|
return i.enumValues && i.enumValues.length > 0 && (u += ` (values: ${i.enumValues.join(", ")})`), i.range && (u += ` (range: ${i.range.min}-${i.range.max})`), u;
|
|
939
942
|
});
|
|
@@ -942,11 +945,11 @@ const ie = m.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
|
|
|
942
945
|
message: `Node properties:
|
|
943
946
|
${l.map((i) => `- ${i}`).join(`
|
|
944
947
|
`)}`,
|
|
945
|
-
data: { nodeProperties:
|
|
948
|
+
data: { nodeProperties: r.nodeProperties }
|
|
946
949
|
});
|
|
947
950
|
}
|
|
948
951
|
case "edgeProperties": {
|
|
949
|
-
const l =
|
|
952
|
+
const l = r.edgeProperties.map((i) => {
|
|
950
953
|
let u = `${i.name}: ${i.type}`;
|
|
951
954
|
return i.enumValues && i.enumValues.length > 0 && (u += ` (values: ${i.enumValues.join(", ")})`), i.range && (u += ` (range: ${i.range.min}-${i.range.max})`), u;
|
|
952
955
|
});
|
|
@@ -959,36 +962,36 @@ ${l.map((i) => `- ${i}`).join(`
|
|
|
959
962
|
message: `Edge properties:
|
|
960
963
|
${l.map((i) => `- ${i}`).join(`
|
|
961
964
|
`)}`,
|
|
962
|
-
data: { edgeProperties:
|
|
965
|
+
data: { edgeProperties: r.edgeProperties }
|
|
963
966
|
});
|
|
964
967
|
}
|
|
965
968
|
case "all": {
|
|
966
|
-
let i =
|
|
969
|
+
let i = r.nodeProperties.find((g) => g.name === "type")?.enumValues ?? [];
|
|
967
970
|
i.length === 0 && (i = n(o.nodes.values(), "type"));
|
|
968
|
-
let
|
|
969
|
-
|
|
970
|
-
const p =
|
|
971
|
+
let d = r.edgeProperties.find((g) => g.name === "type")?.enumValues ?? [];
|
|
972
|
+
d.length === 0 && (d = n(o.edges.values(), "type"));
|
|
973
|
+
const p = r.nodeProperties.map((g) => g.name), m = r.edgeProperties.map((g) => g.name);
|
|
971
974
|
let h = `Graph Schema Summary:
|
|
972
|
-
- ${
|
|
973
|
-
- ${
|
|
975
|
+
- ${r.nodeCount} nodes with ${r.nodeProperties.length} properties
|
|
976
|
+
- ${r.edgeCount} edges with ${r.edgeProperties.length} properties`;
|
|
974
977
|
return i.length > 0 && (h += `
|
|
975
978
|
|
|
976
|
-
Node types: ${i.join(", ")}`),
|
|
979
|
+
Node types: ${i.join(", ")}`), d.length > 0 && (h += `
|
|
977
980
|
|
|
978
|
-
Edge types: ${
|
|
981
|
+
Edge types: ${d.join(", ")}`), p.length > 0 && (h += `
|
|
979
982
|
|
|
980
|
-
Node properties: ${p.join(", ")}`),
|
|
983
|
+
Node properties: ${p.join(", ")}`), m.length > 0 && (h += `
|
|
981
984
|
|
|
982
|
-
Edge properties: ${
|
|
985
|
+
Edge properties: ${m.join(", ")}`), Promise.resolve({
|
|
983
986
|
success: !0,
|
|
984
987
|
message: h,
|
|
985
988
|
data: {
|
|
986
|
-
nodeCount:
|
|
987
|
-
edgeCount:
|
|
989
|
+
nodeCount: r.nodeCount,
|
|
990
|
+
edgeCount: r.edgeCount,
|
|
988
991
|
nodeTypes: i,
|
|
989
|
-
edgeTypes:
|
|
990
|
-
nodeProperties:
|
|
991
|
-
edgeProperties:
|
|
992
|
+
edgeTypes: d,
|
|
993
|
+
nodeProperties: r.nodeProperties,
|
|
994
|
+
edgeProperties: r.edgeProperties
|
|
992
995
|
}
|
|
993
996
|
});
|
|
994
997
|
}
|
|
@@ -998,19 +1001,19 @@ Edge properties: ${d.join(", ")}`), Promise.resolve({
|
|
|
998
1001
|
message: `Unknown schema query type: ${String(t)}`
|
|
999
1002
|
});
|
|
1000
1003
|
}
|
|
1001
|
-
} catch (
|
|
1004
|
+
} catch (s) {
|
|
1002
1005
|
return Promise.resolve({
|
|
1003
1006
|
success: !1,
|
|
1004
|
-
message: `Failed to get schema: ${
|
|
1007
|
+
message: `Failed to get schema: ${s.message}`
|
|
1005
1008
|
});
|
|
1006
1009
|
}
|
|
1007
1010
|
}
|
|
1008
|
-
},
|
|
1011
|
+
}, Ce = c.string().describe("Layout algorithm type (e.g., 'circular', 'ngraph', 'random', 'spiral', 'd3')"), $e = c.enum(["2d", "3d"]).describe("Dimension mode: '2d' or '3d'"), xe = {
|
|
1009
1012
|
name: "setLayout",
|
|
1010
1013
|
description: "Change the graph layout algorithm. Common layouts include 'circular' (nodes in a circle), 'ngraph' (force-directed physics), 'random', 'spiral', 'shell', 'd3' (D3 force simulation), 'spring', 'planar', 'spectral', and 'forceatlas2'.",
|
|
1011
|
-
parameters:
|
|
1012
|
-
type:
|
|
1013
|
-
options:
|
|
1014
|
+
parameters: c.object({
|
|
1015
|
+
type: Ce,
|
|
1016
|
+
options: c.record(c.unknown()).optional().describe("Additional layout-specific options")
|
|
1014
1017
|
}),
|
|
1015
1018
|
examples: [
|
|
1016
1019
|
{ input: "Use circular layout", params: { type: "circular" } },
|
|
@@ -1020,16 +1023,16 @@ Edge properties: ${d.join(", ")}`), Promise.resolve({
|
|
|
1020
1023
|
{ input: "Use D3 force layout", params: { type: "d3" } },
|
|
1021
1024
|
{ input: "Shell layout", params: { type: "shell" } }
|
|
1022
1025
|
],
|
|
1023
|
-
async execute(
|
|
1024
|
-
const { type: t, options:
|
|
1026
|
+
async execute(a, e) {
|
|
1027
|
+
const { type: t, options: s = {} } = e;
|
|
1025
1028
|
try {
|
|
1026
|
-
return await
|
|
1029
|
+
return await a.setLayout(t, s), {
|
|
1027
1030
|
success: !0,
|
|
1028
1031
|
message: `Layout changed to "${t}". The graph is now being rearranged.`,
|
|
1029
1032
|
data: { layoutType: t }
|
|
1030
1033
|
};
|
|
1031
|
-
} catch (
|
|
1032
|
-
const o =
|
|
1034
|
+
} catch (r) {
|
|
1035
|
+
const o = r.message;
|
|
1033
1036
|
return o.includes("not found") || o.includes("unknown") || o.includes("invalid") ? {
|
|
1034
1037
|
success: !1,
|
|
1035
1038
|
message: `Invalid layout type "${t}". Try 'circular', 'ngraph', 'random', 'spiral', 'shell', or 'd3'.`
|
|
@@ -1039,11 +1042,11 @@ Edge properties: ${d.join(", ")}`), Promise.resolve({
|
|
|
1039
1042
|
};
|
|
1040
1043
|
}
|
|
1041
1044
|
}
|
|
1042
|
-
},
|
|
1045
|
+
}, Me = {
|
|
1043
1046
|
name: "setDimension",
|
|
1044
1047
|
description: "Switch between 2D and 3D graph visualization modes. In 2D mode, nodes are arranged on a flat plane. In 3D mode, nodes can be positioned in three-dimensional space.",
|
|
1045
|
-
parameters:
|
|
1046
|
-
dimension:
|
|
1048
|
+
parameters: c.object({
|
|
1049
|
+
dimension: $e
|
|
1047
1050
|
}),
|
|
1048
1051
|
examples: [
|
|
1049
1052
|
{ input: "Switch to 2D view", params: { dimension: "2d" } },
|
|
@@ -1051,27 +1054,27 @@ Edge properties: ${d.join(", ")}`), Promise.resolve({
|
|
|
1051
1054
|
{ input: "Make it flat", params: { dimension: "2d" } },
|
|
1052
1055
|
{ input: "Enable 3D mode", params: { dimension: "3d" } }
|
|
1053
1056
|
],
|
|
1054
|
-
async execute(
|
|
1057
|
+
async execute(a, e) {
|
|
1055
1058
|
const { dimension: t } = e;
|
|
1056
1059
|
try {
|
|
1057
|
-
const
|
|
1058
|
-
return await
|
|
1060
|
+
const s = t === "2d", r = s ? "2D" : "3D";
|
|
1061
|
+
return await a.setViewMode(s ? "2d" : "3d"), {
|
|
1059
1062
|
success: !0,
|
|
1060
|
-
message: `Switched to ${
|
|
1061
|
-
data: { dimension:
|
|
1063
|
+
message: `Switched to ${r} mode. The graph will now be displayed ${s ? "on a flat plane" : "in three-dimensional space"}.`,
|
|
1064
|
+
data: { dimension: r, is2D: s }
|
|
1062
1065
|
};
|
|
1063
|
-
} catch (
|
|
1066
|
+
} catch (s) {
|
|
1064
1067
|
return {
|
|
1065
1068
|
success: !1,
|
|
1066
|
-
message: `Failed to change dimension: ${
|
|
1069
|
+
message: `Failed to change dimension: ${s.message}`
|
|
1067
1070
|
};
|
|
1068
1071
|
}
|
|
1069
1072
|
}
|
|
1070
|
-
},
|
|
1073
|
+
}, Pe = c.enum(["vr", "ar", "exit"]).describe("VR for virtual reality, AR for augmented reality, exit to return to normal view"), Ae = {
|
|
1071
1074
|
name: "setImmersiveMode",
|
|
1072
1075
|
description: "Enter or exit VR/AR immersive modes using WebXR. Use 'vr' for virtual reality (headset), 'ar' for augmented reality (pass-through or mobile AR), or 'exit' to return to normal desktop view.",
|
|
1073
|
-
parameters:
|
|
1074
|
-
mode:
|
|
1076
|
+
parameters: c.object({
|
|
1077
|
+
mode: Pe
|
|
1075
1078
|
}),
|
|
1076
1079
|
examples: [
|
|
1077
1080
|
{ input: "Enter VR mode", params: { mode: "vr" } },
|
|
@@ -1082,25 +1085,25 @@ Edge properties: ${d.join(", ")}`), Promise.resolve({
|
|
|
1082
1085
|
{ input: "Show augmented reality view", params: { mode: "ar" } },
|
|
1083
1086
|
{ input: "Go back to normal view", params: { mode: "exit" } }
|
|
1084
1087
|
],
|
|
1085
|
-
async execute(
|
|
1088
|
+
async execute(a, e) {
|
|
1086
1089
|
const { mode: t } = e;
|
|
1087
1090
|
try {
|
|
1088
1091
|
if (t === "exit") {
|
|
1089
|
-
const n =
|
|
1090
|
-
return n && await n.call(
|
|
1092
|
+
const n = a.exitImmersiveMode;
|
|
1093
|
+
return n && await n.call(a), {
|
|
1091
1094
|
success: !0,
|
|
1092
1095
|
message: "Exited immersive mode, returned to normal view."
|
|
1093
1096
|
};
|
|
1094
1097
|
}
|
|
1095
|
-
const { getXRHelper:
|
|
1096
|
-
if (!
|
|
1098
|
+
const { getXRHelper: s } = a, r = s?.call(a);
|
|
1099
|
+
if (!r)
|
|
1097
1100
|
return {
|
|
1098
1101
|
success: !1,
|
|
1099
1102
|
message: `WebXR is not available. ${t.toUpperCase()} mode requires a WebXR-capable browser and device.`
|
|
1100
1103
|
};
|
|
1101
1104
|
if (t === "vr") {
|
|
1102
|
-
const { enterVR: n } =
|
|
1103
|
-
return n ? (await n.call(
|
|
1105
|
+
const { enterVR: n } = r;
|
|
1106
|
+
return n ? (await n.call(r), {
|
|
1104
1107
|
success: !0,
|
|
1105
1108
|
message: "Entering VR mode. Put on your headset to view the graph in virtual reality."
|
|
1106
1109
|
}) : {
|
|
@@ -1108,96 +1111,96 @@ Edge properties: ${d.join(", ")}`), Promise.resolve({
|
|
|
1108
1111
|
message: "VR mode is not supported on this device or browser."
|
|
1109
1112
|
};
|
|
1110
1113
|
}
|
|
1111
|
-
const { enterAR: o } =
|
|
1112
|
-
return o ? (await o.call(
|
|
1114
|
+
const { enterAR: o } = r;
|
|
1115
|
+
return o ? (await o.call(r), {
|
|
1113
1116
|
success: !0,
|
|
1114
1117
|
message: "Entering AR mode. Point your device to see the graph in augmented reality."
|
|
1115
1118
|
}) : {
|
|
1116
1119
|
success: !1,
|
|
1117
1120
|
message: "AR mode is not supported on this device or browser."
|
|
1118
1121
|
};
|
|
1119
|
-
} catch (
|
|
1122
|
+
} catch (s) {
|
|
1120
1123
|
return {
|
|
1121
1124
|
success: !1,
|
|
1122
|
-
message: `Failed to enter ${t.toUpperCase()} mode: ${
|
|
1125
|
+
message: `Failed to enter ${t.toUpperCase()} mode: ${s.message}`
|
|
1123
1126
|
};
|
|
1124
1127
|
}
|
|
1125
1128
|
}
|
|
1126
|
-
},
|
|
1127
|
-
color:
|
|
1128
|
-
size:
|
|
1129
|
-
shape:
|
|
1130
|
-
glowColor:
|
|
1131
|
-
glowStrength:
|
|
1132
|
-
outlineColor:
|
|
1133
|
-
outlineWidth:
|
|
1129
|
+
}, Ee = c.object({
|
|
1130
|
+
color: c.string().optional().describe("Color for the node (e.g., '#ff0000', 'red')"),
|
|
1131
|
+
size: c.number().positive().optional().describe("Size of the node (default is 1)"),
|
|
1132
|
+
shape: c.string().optional().describe("Shape type (e.g., 'sphere', 'box', 'cylinder')"),
|
|
1133
|
+
glowColor: c.string().optional().describe("Glow effect color"),
|
|
1134
|
+
glowStrength: c.number().positive().optional().describe("Glow effect strength. One strength is drawn at a time for the whole scene"),
|
|
1135
|
+
outlineColor: c.string().optional().describe("Outline color"),
|
|
1136
|
+
outlineWidth: c.number().positive().optional().describe(
|
|
1134
1137
|
"Outline width. Not drawn: every outline in the scene is stroked at one width, so asking for this is answered with the reason rather than applied"
|
|
1135
1138
|
),
|
|
1136
|
-
enabled:
|
|
1137
|
-
}).describe("Style properties for nodes"),
|
|
1138
|
-
color:
|
|
1139
|
-
width:
|
|
1140
|
-
lineType:
|
|
1141
|
-
arrowColor:
|
|
1142
|
-
arrowSize:
|
|
1143
|
-
arrowOpacity:
|
|
1144
|
-
enabled:
|
|
1145
|
-
}).describe("Style properties for edges"),
|
|
1146
|
-
function
|
|
1139
|
+
enabled: c.boolean().optional().describe("Whether the node is visible")
|
|
1140
|
+
}).describe("Style properties for nodes"), Te = c.object({
|
|
1141
|
+
color: c.string().optional().describe("Color for the edge line (e.g., '#00ff00', 'green')"),
|
|
1142
|
+
width: c.number().positive().optional().describe("Width of the edge line"),
|
|
1143
|
+
lineType: c.string().optional().describe("Line pattern (e.g., 'solid', 'dash', 'dot')"),
|
|
1144
|
+
arrowColor: c.string().optional().describe("Color for the arrow head"),
|
|
1145
|
+
arrowSize: c.number().positive().optional().describe("Size of the arrow head"),
|
|
1146
|
+
arrowOpacity: c.number().min(0).max(1).optional().describe("Opacity of the arrow head, 0 to 1"),
|
|
1147
|
+
enabled: c.boolean().optional().describe("Whether the edge is visible")
|
|
1148
|
+
}).describe("Style properties for edges"), Ne = { by: "plugin", name: "graphty-ai" };
|
|
1149
|
+
function ke(a) {
|
|
1147
1150
|
const e = {}, t = [];
|
|
1148
|
-
return
|
|
1151
|
+
return a.color !== void 0 && (e["node.color"] = a.color), a.size !== void 0 && (e["node.size"] = a.size), a.shape !== void 0 && (e["node.shape"] = a.shape), a.glowColor !== void 0 && (e["node.glow"] = a.glowColor), a.glowStrength !== void 0 && (e["node.glowStrength"] = a.glowStrength), a.outlineColor !== void 0 && (e["node.outline"] = a.outlineColor), a.enabled === !1 && (e["node.opacity"] = 0), a.outlineWidth !== void 0 && t.push({ property: "outlineWidth", reason: ee }), { set: e, unsupported: t };
|
|
1149
1152
|
}
|
|
1150
|
-
function
|
|
1153
|
+
function Ie(a) {
|
|
1151
1154
|
const e = {};
|
|
1152
|
-
return
|
|
1155
|
+
return a.color !== void 0 && (e["edge.color"] = a.color), a.width !== void 0 && (e["edge.width"] = a.width), a.lineType !== void 0 && (e["edge.style"] = a.lineType), a.enabled === !1 && (e["edge.opacity"] = 0), a.arrowColor !== void 0 && (e["edge.arrowHeadColor"] = a.arrowColor), a.arrowSize !== void 0 && (e["edge.arrowHeadSize"] = a.arrowSize), a.arrowOpacity !== void 0 && (e["edge.arrowHeadOpacity"] = a.arrowOpacity), { set: e, unsupported: [] };
|
|
1153
1156
|
}
|
|
1154
|
-
const
|
|
1155
|
-
function
|
|
1156
|
-
return !
|
|
1157
|
+
const Re = /* @__PURE__ */ new Set(["", "*", "all", "*.*", "true"]);
|
|
1158
|
+
function De(a) {
|
|
1159
|
+
return !a || Re.has(a.toLowerCase().trim());
|
|
1157
1160
|
}
|
|
1158
|
-
function
|
|
1161
|
+
function _(a, e, t, s) {
|
|
1159
1162
|
return {
|
|
1160
|
-
name:
|
|
1163
|
+
name: a,
|
|
1161
1164
|
target: e,
|
|
1162
1165
|
kind: "custom",
|
|
1163
|
-
source:
|
|
1164
|
-
selector:
|
|
1165
|
-
set:
|
|
1166
|
+
source: Ne,
|
|
1167
|
+
selector: De(t) ? { match: "everything" } : { match: "expression", where: t.replace(/"/g, "'") },
|
|
1168
|
+
set: s
|
|
1166
1169
|
};
|
|
1167
1170
|
}
|
|
1168
|
-
function
|
|
1169
|
-
return
|
|
1171
|
+
function K(a) {
|
|
1172
|
+
return oe(a) ? `${a.message} (${a.code})` : a instanceof Error ? a.message : String(a);
|
|
1170
1173
|
}
|
|
1171
|
-
async function
|
|
1172
|
-
const { styles:
|
|
1174
|
+
async function W(a, e, t, s) {
|
|
1175
|
+
const { styles: r } = a.getSession(), o = r.validate(e);
|
|
1173
1176
|
if (!o.ok)
|
|
1174
1177
|
return {
|
|
1175
1178
|
success: !1,
|
|
1176
|
-
message: `That ${
|
|
1179
|
+
message: `That ${s} style could not be applied: ${o.errors.map((n) => n.message).join(" ")}`
|
|
1177
1180
|
};
|
|
1178
1181
|
try {
|
|
1179
|
-
const n = await
|
|
1182
|
+
const n = await r.add(e), l = t.map(({ property: u, reason: d }) => ` ${u} was not applied: ${d}`).join(""), i = o.unresolvedPaths.length === 0 ? "" : ` Nothing in this graph answers ${o.unresolvedPaths.join(", ")} yet, so the layer may paint nothing until it does.`;
|
|
1180
1183
|
return {
|
|
1181
1184
|
success: !0,
|
|
1182
|
-
message: `Added the ${
|
|
1185
|
+
message: `Added the ${s} style layer "${n.name}".${l}${i}`,
|
|
1183
1186
|
data: { layerId: n.id, layerName: n.name }
|
|
1184
1187
|
};
|
|
1185
1188
|
} catch (n) {
|
|
1186
1189
|
return {
|
|
1187
1190
|
success: !1,
|
|
1188
|
-
message: `That ${
|
|
1191
|
+
message: `That ${s} style could not be applied: ${K(n)}`
|
|
1189
1192
|
};
|
|
1190
1193
|
}
|
|
1191
1194
|
}
|
|
1192
|
-
const
|
|
1195
|
+
const Le = {
|
|
1193
1196
|
name: "findAndStyleNodes",
|
|
1194
1197
|
description: `Style the nodes matching a selector by adding a style layer. Use an empty selector to match every node. A node's own fields are published under 'data.', so write 'data.type == "server"'. Styles include color, size, shape, glow color and outline color.`,
|
|
1195
|
-
parameters:
|
|
1196
|
-
selector:
|
|
1198
|
+
parameters: c.object({
|
|
1199
|
+
selector: c.string().describe(
|
|
1197
1200
|
`Expression matching nodes (empty string matches all). A record's own fields live under 'data.', so write 'data.type == "server"'.`
|
|
1198
1201
|
),
|
|
1199
|
-
style:
|
|
1200
|
-
layerName:
|
|
1202
|
+
style: Ee,
|
|
1203
|
+
layerName: c.string().optional().describe("Name for this style layer (for later removal)")
|
|
1201
1204
|
}),
|
|
1202
1205
|
examples: [
|
|
1203
1206
|
{
|
|
@@ -1221,23 +1224,23 @@ const Me = {
|
|
|
1221
1224
|
params: { selector: "", style: { shape: "box" }, layerName: "box-shapes" }
|
|
1222
1225
|
}
|
|
1223
1226
|
],
|
|
1224
|
-
async execute(
|
|
1227
|
+
async execute(a, e) {
|
|
1225
1228
|
const {
|
|
1226
1229
|
selector: t,
|
|
1227
|
-
style:
|
|
1228
|
-
layerName:
|
|
1229
|
-
} = e, { set: o, unsupported: n } =
|
|
1230
|
-
return
|
|
1230
|
+
style: s,
|
|
1231
|
+
layerName: r = `ai-node-style-${Date.now()}`
|
|
1232
|
+
} = e, { set: o, unsupported: n } = ke(s);
|
|
1233
|
+
return W(a, _(r, "node", t, o), n, "node");
|
|
1231
1234
|
}
|
|
1232
|
-
},
|
|
1235
|
+
}, je = {
|
|
1233
1236
|
name: "findAndStyleEdges",
|
|
1234
1237
|
description: "Style the edges matching a selector by adding a style layer. Use an empty selector to match every edge. An edge's own fields are published under 'data.', so write 'data.weight > `0.5`'. Styles include color, width and line pattern.",
|
|
1235
|
-
parameters:
|
|
1236
|
-
selector:
|
|
1238
|
+
parameters: c.object({
|
|
1239
|
+
selector: c.string().describe(
|
|
1237
1240
|
"Expression matching edges (empty string matches all). A record's own fields live under 'data.', so write 'data.weight > `0.5`'."
|
|
1238
1241
|
),
|
|
1239
|
-
style:
|
|
1240
|
-
layerName:
|
|
1242
|
+
style: Te,
|
|
1243
|
+
layerName: c.string().optional().describe("Name for this style layer (for later removal)")
|
|
1241
1244
|
}),
|
|
1242
1245
|
examples: [
|
|
1243
1246
|
{
|
|
@@ -1257,29 +1260,29 @@ const Me = {
|
|
|
1257
1260
|
params: { selector: "", style: { lineType: "dash" }, layerName: "dashed" }
|
|
1258
1261
|
}
|
|
1259
1262
|
],
|
|
1260
|
-
async execute(
|
|
1263
|
+
async execute(a, e) {
|
|
1261
1264
|
const {
|
|
1262
1265
|
selector: t,
|
|
1263
|
-
style:
|
|
1264
|
-
layerName:
|
|
1265
|
-
} = e, { set: o, unsupported: n } =
|
|
1266
|
-
return
|
|
1266
|
+
style: s,
|
|
1267
|
+
layerName: r = `ai-edge-style-${Date.now()}`
|
|
1268
|
+
} = e, { set: o, unsupported: n } = Ie(s);
|
|
1269
|
+
return W(a, _(r, "edge", t, o), n, "edge");
|
|
1267
1270
|
}
|
|
1268
|
-
},
|
|
1271
|
+
}, ze = {
|
|
1269
1272
|
name: "clearStyles",
|
|
1270
1273
|
description: "Clear styles added by AI commands. Specify a layerName to clear a specific style, or leave empty to clear all AI-added styles.",
|
|
1271
|
-
parameters:
|
|
1272
|
-
layerName:
|
|
1274
|
+
parameters: c.object({
|
|
1275
|
+
layerName: c.string().optional().describe("Name of the style layer to clear (clears all if not specified)")
|
|
1273
1276
|
}),
|
|
1274
1277
|
examples: [
|
|
1275
1278
|
{ input: "Clear all styling", params: {} },
|
|
1276
1279
|
{ input: "Remove red node styling", params: { layerName: "red-nodes" } }
|
|
1277
1280
|
],
|
|
1278
|
-
async execute(
|
|
1279
|
-
const { layerName: t } = e, { styles:
|
|
1281
|
+
async execute(a, e) {
|
|
1282
|
+
const { layerName: t } = e, { styles: s } = a.getSession();
|
|
1280
1283
|
try {
|
|
1281
1284
|
if (t === void 0) {
|
|
1282
|
-
const o = await
|
|
1285
|
+
const o = await s.removeBySource(
|
|
1283
1286
|
(n) => n.by === "plugin" && n.name === "graphty-ai"
|
|
1284
1287
|
);
|
|
1285
1288
|
return {
|
|
@@ -1288,42 +1291,42 @@ const Me = {
|
|
|
1288
1291
|
data: { clearedCount: o.length }
|
|
1289
1292
|
};
|
|
1290
1293
|
}
|
|
1291
|
-
const
|
|
1294
|
+
const r = s.list().filter(
|
|
1292
1295
|
(o) => o.name === t && o.source.by === "plugin" && o.source.name === "graphty-ai"
|
|
1293
1296
|
);
|
|
1294
|
-
if (
|
|
1297
|
+
if (r.length === 0)
|
|
1295
1298
|
return {
|
|
1296
1299
|
success: !0,
|
|
1297
1300
|
message: `Style layer "${t}" not found (may already be cleared).`
|
|
1298
1301
|
};
|
|
1299
|
-
for (const o of
|
|
1300
|
-
await
|
|
1302
|
+
for (const o of r)
|
|
1303
|
+
await s.remove(o.id);
|
|
1301
1304
|
return {
|
|
1302
1305
|
success: !0,
|
|
1303
1306
|
message: `Cleared style layer "${t}".`,
|
|
1304
|
-
data: { clearedCount:
|
|
1307
|
+
data: { clearedCount: r.length }
|
|
1305
1308
|
};
|
|
1306
|
-
} catch (
|
|
1309
|
+
} catch (r) {
|
|
1307
1310
|
return {
|
|
1308
1311
|
success: !1,
|
|
1309
|
-
message: `Failed to clear styles: ${
|
|
1312
|
+
message: `Failed to clear styles: ${K(r)}`
|
|
1310
1313
|
};
|
|
1311
1314
|
}
|
|
1312
1315
|
}
|
|
1313
1316
|
};
|
|
1314
|
-
function
|
|
1317
|
+
function E() {
|
|
1315
1318
|
return [
|
|
1316
|
-
...
|
|
1317
|
-
...
|
|
1319
|
+
...se.map((a) => a.id),
|
|
1320
|
+
...Q().map((a) => a.id)
|
|
1318
1321
|
];
|
|
1319
1322
|
}
|
|
1320
|
-
const
|
|
1323
|
+
const qe = c.string().describe(
|
|
1321
1324
|
"Named camera view. The element ships 'fitToGraph', 'topView', 'sideView', 'frontView' and 'isometric'; an application may have registered others."
|
|
1322
|
-
),
|
|
1323
|
-
x:
|
|
1324
|
-
y:
|
|
1325
|
-
z:
|
|
1326
|
-
}).describe("3D position coordinates"),
|
|
1325
|
+
), T = c.object({
|
|
1326
|
+
x: c.number(),
|
|
1327
|
+
y: c.number(),
|
|
1328
|
+
z: c.number()
|
|
1329
|
+
}).describe("3D position coordinates"), Ue = {
|
|
1327
1330
|
name: "setCameraPosition",
|
|
1328
1331
|
/*
|
|
1329
1332
|
* READ AT PROMPT TIME, NOT AT IMPORT TIME. The description is what the system prompt shows
|
|
@@ -1334,13 +1337,13 @@ const Te = m.string().describe(
|
|
|
1334
1337
|
* registered.
|
|
1335
1338
|
*/
|
|
1336
1339
|
get description() {
|
|
1337
|
-
return `Set the camera position using a preset (${
|
|
1340
|
+
return `Set the camera position using a preset (${E().join(", ")}) or specific coordinates. Presets automatically calculate the best view for the current graph. Animation can be enabled for smooth transitions.`;
|
|
1338
1341
|
},
|
|
1339
|
-
parameters:
|
|
1340
|
-
preset:
|
|
1341
|
-
position:
|
|
1342
|
-
target:
|
|
1343
|
-
animate:
|
|
1342
|
+
parameters: c.object({
|
|
1343
|
+
preset: qe.optional().describe("Named camera preset to apply"),
|
|
1344
|
+
position: T.optional().describe("Custom camera position (3D only)"),
|
|
1345
|
+
target: T.optional().describe("Point the camera should look at (3D only)"),
|
|
1346
|
+
animate: c.boolean().optional().describe("Whether to animate the camera transition (default: true)")
|
|
1344
1347
|
}),
|
|
1345
1348
|
examples: [
|
|
1346
1349
|
{ input: "Show from top", params: { preset: "topView", animate: !0 } },
|
|
@@ -1353,37 +1356,37 @@ const Te = m.string().describe(
|
|
|
1353
1356
|
params: { position: { x: 10, y: 20, z: 30 }, target: { x: 0, y: 0, z: 0 } }
|
|
1354
1357
|
}
|
|
1355
1358
|
],
|
|
1356
|
-
async execute(
|
|
1359
|
+
async execute(a, e) {
|
|
1357
1360
|
const {
|
|
1358
1361
|
preset: t,
|
|
1359
|
-
position:
|
|
1360
|
-
target:
|
|
1362
|
+
position: s,
|
|
1363
|
+
target: r,
|
|
1361
1364
|
animate: o = !0
|
|
1362
1365
|
} = e;
|
|
1363
1366
|
try {
|
|
1364
|
-
if (!t && !
|
|
1367
|
+
if (!t && !s)
|
|
1365
1368
|
return {
|
|
1366
1369
|
success: !1,
|
|
1367
1370
|
message: "Either 'preset' or 'position' must be provided."
|
|
1368
1371
|
};
|
|
1369
1372
|
if (t)
|
|
1370
|
-
return
|
|
1373
|
+
return te(t) ? (await a.setCameraState({ preset: t }, { animate: o, description: `Setting camera to ${t} view` }), {
|
|
1371
1374
|
success: !0,
|
|
1372
1375
|
message: `Camera moved to ${t} view${o ? " (animated)" : ""}.`,
|
|
1373
1376
|
data: { preset: t, animated: o }
|
|
1374
1377
|
}) : {
|
|
1375
1378
|
success: !1,
|
|
1376
|
-
message: `Unknown camera view "${t}". Available views: ${
|
|
1379
|
+
message: `Unknown camera view "${t}". Available views: ${E().join(", ")}.`
|
|
1377
1380
|
};
|
|
1378
|
-
if (
|
|
1379
|
-
const n = { position:
|
|
1380
|
-
return
|
|
1381
|
+
if (s) {
|
|
1382
|
+
const n = { position: s };
|
|
1383
|
+
return r && (n.target = r), await a.setCameraState(n, {
|
|
1381
1384
|
animate: o,
|
|
1382
1385
|
description: "Moving camera to specified position"
|
|
1383
1386
|
}), {
|
|
1384
1387
|
success: !0,
|
|
1385
|
-
message: `Camera moved to position (${
|
|
1386
|
-
data: { position:
|
|
1388
|
+
message: `Camera moved to position (${s.x}, ${s.y}, ${s.z})${o ? " (animated)" : ""}.`,
|
|
1389
|
+
data: { position: s, target: r, animated: o }
|
|
1387
1390
|
};
|
|
1388
1391
|
}
|
|
1389
1392
|
return {
|
|
@@ -1398,227 +1401,361 @@ const Te = m.string().describe(
|
|
|
1398
1401
|
}
|
|
1399
1402
|
}
|
|
1400
1403
|
};
|
|
1401
|
-
function
|
|
1402
|
-
const t =
|
|
1404
|
+
function Ve(a, e) {
|
|
1405
|
+
const t = a.getDataManager(), { nodes: s } = t, r = [];
|
|
1403
1406
|
if (!e || e.length === 0) {
|
|
1404
|
-
for (const [o] of
|
|
1405
|
-
|
|
1406
|
-
return
|
|
1407
|
+
for (const [o] of s)
|
|
1408
|
+
r.push(String(o));
|
|
1409
|
+
return r;
|
|
1407
1410
|
}
|
|
1408
1411
|
try {
|
|
1409
1412
|
const n = `[?${e.replace(/"/g, "'")}]`;
|
|
1410
|
-
for (const [l, i] of
|
|
1411
|
-
const { data: u } = i,
|
|
1412
|
-
Array.isArray(
|
|
1413
|
+
for (const [l, i] of s) {
|
|
1414
|
+
const { data: u } = i, d = ae.search([u], n);
|
|
1415
|
+
Array.isArray(d) && d.length > 0 && r.push(String(l));
|
|
1413
1416
|
}
|
|
1414
1417
|
} catch {
|
|
1415
1418
|
return [];
|
|
1416
1419
|
}
|
|
1417
|
-
return
|
|
1420
|
+
return r;
|
|
1418
1421
|
}
|
|
1419
|
-
const
|
|
1422
|
+
const Fe = {
|
|
1420
1423
|
name: "zoomToNodes",
|
|
1421
1424
|
description: "Zoom the camera to fit specific nodes in view. Use a JMESPath selector to choose which nodes to focus on, or leave empty to fit all nodes. Optionally add padding around the nodes.",
|
|
1422
|
-
parameters:
|
|
1423
|
-
selector:
|
|
1424
|
-
animate:
|
|
1425
|
-
padding:
|
|
1425
|
+
parameters: c.object({
|
|
1426
|
+
selector: c.string().optional().describe("JMESPath expression to match nodes (empty matches all)"),
|
|
1427
|
+
animate: c.boolean().optional().describe("Whether to animate the zoom (default: true)"),
|
|
1428
|
+
padding: c.number().optional().describe("Extra padding around nodes (default: 1.2 = 20% padding)")
|
|
1426
1429
|
}),
|
|
1427
1430
|
examples: [
|
|
1428
1431
|
{ input: "Zoom to fit all nodes", params: { selector: "" } },
|
|
1429
1432
|
{ input: "Zoom to server nodes", params: { selector: "type == 'server'" } },
|
|
1430
1433
|
{ input: "Fit graph with more padding", params: { selector: "", padding: 1.5 } }
|
|
1431
1434
|
],
|
|
1432
|
-
async execute(
|
|
1433
|
-
const { selector: t = "", animate:
|
|
1435
|
+
async execute(a, e) {
|
|
1436
|
+
const { selector: t = "", animate: s = !0 } = e;
|
|
1434
1437
|
try {
|
|
1435
|
-
const
|
|
1436
|
-
if (
|
|
1438
|
+
const r = Ve(a, t);
|
|
1439
|
+
if (r.length === 0 && t && t.length > 0)
|
|
1437
1440
|
return {
|
|
1438
1441
|
success: !0,
|
|
1439
1442
|
message: `No nodes matched the selector "${t}".`,
|
|
1440
1443
|
affectedNodes: []
|
|
1441
1444
|
};
|
|
1442
|
-
await
|
|
1443
|
-
...t && t.length > 0 ? { scope: { nodes:
|
|
1444
|
-
animate:
|
|
1445
|
+
await a.applyCameraView("fitToGraph", {
|
|
1446
|
+
...t && t.length > 0 ? { scope: { nodes: r } } : {},
|
|
1447
|
+
animate: s,
|
|
1445
1448
|
description: `Zooming to fit ${t ? "matching nodes" : "all nodes"}`
|
|
1446
1449
|
});
|
|
1447
|
-
const o = t ?
|
|
1450
|
+
const o = t ? r.length : a.getNodeCount();
|
|
1448
1451
|
return {
|
|
1449
1452
|
success: !0,
|
|
1450
1453
|
message: `Zoomed to fit ${o} node(s)${t ? ` matching "${t}"` : ""}.`,
|
|
1451
|
-
affectedNodes:
|
|
1452
|
-
data: { nodeCount: o, animated:
|
|
1454
|
+
affectedNodes: r,
|
|
1455
|
+
data: { nodeCount: o, animated: s }
|
|
1456
|
+
};
|
|
1457
|
+
} catch (r) {
|
|
1458
|
+
return {
|
|
1459
|
+
success: !1,
|
|
1460
|
+
message: `Failed to zoom to nodes: ${r.message}`
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}, N = c.object({
|
|
1465
|
+
namespace: c.string().describe("The namespace of the algorithm (e.g., 'graphty')"),
|
|
1466
|
+
type: c.string().describe("The type of algorithm to run (e.g., 'degree', 'pagerank')"),
|
|
1467
|
+
options: c.record(c.string(), c.unknown()).optional().describe(
|
|
1468
|
+
"The algorithm's options, by name (e.g., { source: 'a', target: 'b' } for dijkstra, { dampingFactor: 0.9 } for pagerank). An unknown name or an out-of-range value is refused."
|
|
1469
|
+
)
|
|
1470
|
+
}), k = 50, I = c.object({
|
|
1471
|
+
namespace: c.string().optional().describe("Optional namespace to filter algorithms by")
|
|
1472
|
+
}), Oe = {
|
|
1473
|
+
name: "runAlgorithm",
|
|
1474
|
+
description: "Run a graph algorithm to analyze the graph structure, optionally with options such as a source and target. Returns a bounded summary: the top 10 elements and the value range for a metric, the group sizes for a partition, the route for a path, plus any graph-level values.",
|
|
1475
|
+
parameters: N,
|
|
1476
|
+
examples: [
|
|
1477
|
+
{
|
|
1478
|
+
input: "Calculate the degree of each node",
|
|
1479
|
+
params: { namespace: "graphty", type: "degree" }
|
|
1480
|
+
},
|
|
1481
|
+
{
|
|
1482
|
+
input: "Run pagerank algorithm",
|
|
1483
|
+
params: { namespace: "graphty", type: "pagerank" }
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
input: "Compute centrality metrics",
|
|
1487
|
+
params: { namespace: "graphty", type: "degree" }
|
|
1488
|
+
},
|
|
1489
|
+
{
|
|
1490
|
+
input: "Find the shortest path from node A to node B",
|
|
1491
|
+
params: { namespace: "graphty", type: "dijkstra", options: { source: "A", target: "B" } }
|
|
1492
|
+
}
|
|
1493
|
+
],
|
|
1494
|
+
async execute(a, e) {
|
|
1495
|
+
const t = N.safeParse(e);
|
|
1496
|
+
if (!t.success)
|
|
1497
|
+
return {
|
|
1498
|
+
success: !1,
|
|
1499
|
+
message: `Invalid parameters: ${t.error.message}`
|
|
1500
|
+
};
|
|
1501
|
+
const { namespace: s, type: r, options: o } = t.data;
|
|
1502
|
+
try {
|
|
1503
|
+
if (!x.get(a, s, r)) {
|
|
1504
|
+
const m = x.getRegisteredAlgorithms(s), h = m.length > 0 ? `Available in namespace '${s}': ${m.map((g) => g.split(":")[1]).join(", ")}` : `No algorithms found in namespace '${s}'. Use listAlgorithms to see available options.`;
|
|
1505
|
+
return {
|
|
1506
|
+
success: !1,
|
|
1507
|
+
message: `Algorithm not found: ${s}:${r}. ${h}`
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
const l = (s === "graphty" ? re(r) : void 0) ?? P(`${s}:${r}`) ?? P(r);
|
|
1511
|
+
if (l === void 0)
|
|
1512
|
+
return await a.runAlgorithm(s, r, { algorithmOptions: o }), {
|
|
1513
|
+
success: !0,
|
|
1514
|
+
message: `Successfully ran ${s}:${r} algorithm. Results are now available in node data.`,
|
|
1515
|
+
data: { namespace: s, type: r, nodeCount: a.getNodeCount() }
|
|
1516
|
+
};
|
|
1517
|
+
const i = "params" in l ? l.params : {}, u = await a.run(l.descriptor.key, { ...i, ...o }), d = {
|
|
1518
|
+
namespace: s,
|
|
1519
|
+
type: r,
|
|
1520
|
+
algorithm: l.descriptor.key,
|
|
1521
|
+
shape: u.shape,
|
|
1522
|
+
summary: u.summary(),
|
|
1523
|
+
graph: u.graph
|
|
1453
1524
|
};
|
|
1454
|
-
|
|
1525
|
+
let p;
|
|
1526
|
+
if (u.shape === "path") {
|
|
1527
|
+
const m = u.ranking("order").map((h) => String(h.id)).reverse();
|
|
1528
|
+
p = m.slice(0, k), d.path = {
|
|
1529
|
+
nodeIds: p,
|
|
1530
|
+
total: m.length,
|
|
1531
|
+
truncated: m.length > k
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
return {
|
|
1535
|
+
success: !0,
|
|
1536
|
+
message: `Successfully ran ${s}:${r} algorithm. ${u.reading()}`,
|
|
1537
|
+
data: d,
|
|
1538
|
+
...p === void 0 ? {} : { affectedNodes: p }
|
|
1539
|
+
};
|
|
1540
|
+
} catch (n) {
|
|
1541
|
+
return {
|
|
1542
|
+
success: !1,
|
|
1543
|
+
message: `Failed to run algorithm ${s}:${r}: ${n instanceof Error ? n.message : String(n)}`
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}, _e = {
|
|
1548
|
+
name: "listAlgorithms",
|
|
1549
|
+
description: "List all available graph algorithms that can be run on the graph. Optionally filter by namespace.",
|
|
1550
|
+
parameters: I,
|
|
1551
|
+
examples: [
|
|
1552
|
+
{
|
|
1553
|
+
input: "What algorithms are available?",
|
|
1554
|
+
params: {}
|
|
1555
|
+
},
|
|
1556
|
+
{
|
|
1557
|
+
input: "List graphty algorithms",
|
|
1558
|
+
params: { namespace: "graphty" }
|
|
1559
|
+
},
|
|
1560
|
+
{
|
|
1561
|
+
input: "Show me the available analysis tools",
|
|
1562
|
+
params: {}
|
|
1563
|
+
}
|
|
1564
|
+
],
|
|
1565
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1566
|
+
async execute(a, e) {
|
|
1567
|
+
const t = I.safeParse(e);
|
|
1568
|
+
if (!t.success)
|
|
1569
|
+
return {
|
|
1570
|
+
success: !1,
|
|
1571
|
+
message: `Invalid parameters: ${t.error.message}`
|
|
1572
|
+
};
|
|
1573
|
+
const { namespace: s } = t.data;
|
|
1574
|
+
try {
|
|
1575
|
+
const r = x.getRegisteredAlgorithms(s);
|
|
1576
|
+
return r.length === 0 ? {
|
|
1577
|
+
success: !0,
|
|
1578
|
+
message: s ? `No algorithms found in namespace '${s}'.` : "No algorithms are currently registered.",
|
|
1579
|
+
data: {
|
|
1580
|
+
algorithms: [],
|
|
1581
|
+
count: 0
|
|
1582
|
+
}
|
|
1583
|
+
} : {
|
|
1584
|
+
success: !0,
|
|
1585
|
+
message: s ? `Found ${r.length} algorithm(s) in namespace '${s}': ${r.join(", ")}` : `Found ${r.length} available algorithm(s): ${r.join(", ")}`,
|
|
1586
|
+
data: {
|
|
1587
|
+
algorithms: r,
|
|
1588
|
+
count: r.length
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
} catch (r) {
|
|
1455
1592
|
return {
|
|
1456
1593
|
success: !1,
|
|
1457
|
-
message: `Failed to
|
|
1594
|
+
message: `Failed to list algorithms: ${r instanceof Error ? r.message : String(r)}`
|
|
1458
1595
|
};
|
|
1459
1596
|
}
|
|
1460
1597
|
}
|
|
1461
1598
|
};
|
|
1462
|
-
function
|
|
1463
|
-
return
|
|
1599
|
+
function Ke(a, e = 100) {
|
|
1600
|
+
return a.length <= e ? a : `${a.slice(0, e)}...`;
|
|
1464
1601
|
}
|
|
1465
|
-
function
|
|
1466
|
-
if (
|
|
1602
|
+
function M(a, e) {
|
|
1603
|
+
if (a == null)
|
|
1467
1604
|
return;
|
|
1468
1605
|
const t = e.split(".");
|
|
1469
|
-
let
|
|
1470
|
-
for (const
|
|
1471
|
-
if (
|
|
1606
|
+
let s = a;
|
|
1607
|
+
for (const r of t) {
|
|
1608
|
+
if (s == null || typeof s != "object")
|
|
1472
1609
|
return;
|
|
1473
|
-
|
|
1610
|
+
s = s[r];
|
|
1474
1611
|
}
|
|
1475
|
-
return
|
|
1612
|
+
return s;
|
|
1476
1613
|
}
|
|
1477
|
-
function
|
|
1478
|
-
if (
|
|
1479
|
-
return
|
|
1480
|
-
if (typeof
|
|
1481
|
-
return
|
|
1482
|
-
if (Array.isArray(
|
|
1483
|
-
return
|
|
1484
|
-
if (typeof
|
|
1614
|
+
function C(a, e = 100) {
|
|
1615
|
+
if (a == null)
|
|
1616
|
+
return a;
|
|
1617
|
+
if (typeof a == "string")
|
|
1618
|
+
return Ke(a, e);
|
|
1619
|
+
if (Array.isArray(a))
|
|
1620
|
+
return a.map((t) => C(t, e));
|
|
1621
|
+
if (typeof a == "object") {
|
|
1485
1622
|
const t = {};
|
|
1486
|
-
for (const [
|
|
1487
|
-
t[
|
|
1623
|
+
for (const [s, r] of Object.entries(a))
|
|
1624
|
+
t[s] = C(r, e);
|
|
1488
1625
|
return t;
|
|
1489
1626
|
}
|
|
1490
|
-
return
|
|
1627
|
+
return a;
|
|
1491
1628
|
}
|
|
1492
|
-
function
|
|
1493
|
-
if (
|
|
1629
|
+
function G(a) {
|
|
1630
|
+
if (a.length === 0)
|
|
1494
1631
|
return { min: 0, max: 0, avg: 0, median: 0, count: 0 };
|
|
1495
|
-
const e = [...
|
|
1496
|
-
return { min:
|
|
1632
|
+
const e = [...a].sort((i, u) => i - u), t = a.reduce((i, u) => i + u, 0), s = e[0], r = e[e.length - 1], o = t / a.length, n = Math.floor(e.length / 2), l = e.length % 2 === 0 ? (e[n - 1] + e[n]) / 2 : e[n];
|
|
1633
|
+
return { min: s, max: r, avg: o, median: l, count: a.length };
|
|
1497
1634
|
}
|
|
1498
|
-
function
|
|
1499
|
-
if (
|
|
1635
|
+
function We(a, e = 5) {
|
|
1636
|
+
if (a.length === 0)
|
|
1500
1637
|
return [];
|
|
1501
|
-
const t = Math.min(...
|
|
1502
|
-
if (t ===
|
|
1638
|
+
const t = Math.min(...a), s = Math.max(...a);
|
|
1639
|
+
if (t === s)
|
|
1503
1640
|
return [
|
|
1504
1641
|
{
|
|
1505
|
-
range:
|
|
1506
|
-
count:
|
|
1642
|
+
range: R(t, s),
|
|
1643
|
+
count: a.length,
|
|
1507
1644
|
min: t,
|
|
1508
|
-
max:
|
|
1645
|
+
max: s
|
|
1509
1646
|
}
|
|
1510
1647
|
];
|
|
1511
|
-
const
|
|
1648
|
+
const r = (s - t) / e, o = [];
|
|
1512
1649
|
for (let n = 0; n < e; n++) {
|
|
1513
|
-
const l = t + n *
|
|
1650
|
+
const l = t + n * r, i = n === e - 1 ? s : t + (n + 1) * r;
|
|
1514
1651
|
o.push({
|
|
1515
|
-
range:
|
|
1652
|
+
range: R(l, i),
|
|
1516
1653
|
count: 0,
|
|
1517
1654
|
min: l,
|
|
1518
1655
|
max: i
|
|
1519
1656
|
});
|
|
1520
1657
|
}
|
|
1521
|
-
for (const n of
|
|
1522
|
-
let l = Math.floor((n - t) /
|
|
1658
|
+
for (const n of a) {
|
|
1659
|
+
let l = Math.floor((n - t) / r);
|
|
1523
1660
|
l >= e && (l = e - 1), o[l].count++;
|
|
1524
1661
|
}
|
|
1525
1662
|
return o;
|
|
1526
1663
|
}
|
|
1527
|
-
function
|
|
1528
|
-
const t = (
|
|
1529
|
-
return `${t(
|
|
1664
|
+
function R(a, e) {
|
|
1665
|
+
const t = (s) => Number.isInteger(s) ? s.toString() : s.toFixed(2);
|
|
1666
|
+
return `${t(a)} - ${t(e)}`;
|
|
1530
1667
|
}
|
|
1531
|
-
function
|
|
1532
|
-
if (
|
|
1668
|
+
function Ge(a) {
|
|
1669
|
+
if (a == null)
|
|
1533
1670
|
return "null";
|
|
1534
|
-
if (Array.isArray(
|
|
1671
|
+
if (Array.isArray(a))
|
|
1535
1672
|
return "array";
|
|
1536
|
-
const e = typeof
|
|
1673
|
+
const e = typeof a;
|
|
1537
1674
|
return e === "string" || e === "number" || e === "boolean" ? e : e === "object" ? "object" : "null";
|
|
1538
1675
|
}
|
|
1539
|
-
function
|
|
1676
|
+
function He(a, e) {
|
|
1540
1677
|
const t = [];
|
|
1541
|
-
let
|
|
1542
|
-
for (const
|
|
1543
|
-
const o =
|
|
1544
|
-
o == null ?
|
|
1678
|
+
let s = 0;
|
|
1679
|
+
for (const r of a) {
|
|
1680
|
+
const o = M(r.data, e);
|
|
1681
|
+
o == null ? s++ : t.push(o);
|
|
1545
1682
|
}
|
|
1546
|
-
return { values: t, nullCount:
|
|
1683
|
+
return { values: t, nullCount: s };
|
|
1547
1684
|
}
|
|
1548
|
-
function
|
|
1549
|
-
if (
|
|
1685
|
+
function H(a) {
|
|
1686
|
+
if (a.length === 0)
|
|
1550
1687
|
return "null";
|
|
1551
1688
|
const e = /* @__PURE__ */ new Map();
|
|
1552
|
-
for (const t of
|
|
1553
|
-
const
|
|
1554
|
-
e.set(
|
|
1689
|
+
for (const t of a) {
|
|
1690
|
+
const s = Ge(t);
|
|
1691
|
+
e.set(s, (e.get(s) ?? 0) + 1);
|
|
1555
1692
|
}
|
|
1556
1693
|
return e.delete("null"), e.size === 0 ? "null" : e.size > 1 ? "mixed" : e.keys().next().value;
|
|
1557
1694
|
}
|
|
1558
|
-
function
|
|
1695
|
+
function Be(a, e = 3) {
|
|
1559
1696
|
const t = /* @__PURE__ */ new Set();
|
|
1560
|
-
for (const
|
|
1561
|
-
|
|
1697
|
+
for (const s of a)
|
|
1698
|
+
B(s.data, "", t, 0, e);
|
|
1562
1699
|
return Array.from(t).sort();
|
|
1563
1700
|
}
|
|
1564
|
-
function
|
|
1565
|
-
if (!(
|
|
1566
|
-
for (const o of Object.keys(
|
|
1701
|
+
function B(a, e, t, s, r) {
|
|
1702
|
+
if (!(s >= r || a === null || a === void 0 || typeof a != "object" || Array.isArray(a)))
|
|
1703
|
+
for (const o of Object.keys(a)) {
|
|
1567
1704
|
const n = e ? `${e}.${o}` : o;
|
|
1568
1705
|
t.add(n);
|
|
1569
|
-
const l =
|
|
1570
|
-
l !== null && typeof l == "object" && !Array.isArray(l) &&
|
|
1706
|
+
const l = a[o];
|
|
1707
|
+
l !== null && typeof l == "object" && !Array.isArray(l) && B(l, n, t, s + 1, r);
|
|
1571
1708
|
}
|
|
1572
1709
|
}
|
|
1573
|
-
const
|
|
1574
|
-
function y(
|
|
1575
|
-
if (
|
|
1576
|
-
return [...
|
|
1577
|
-
const t = [...
|
|
1578
|
-
for (let
|
|
1579
|
-
const
|
|
1580
|
-
[t[
|
|
1710
|
+
const Xe = c.enum(["nodes", "edges", "both"]).optional().describe("What to sample: 'nodes', 'edges', or 'both' (default)"), D = 3, L = 10, j = 100;
|
|
1711
|
+
function y(a, e) {
|
|
1712
|
+
if (a.length <= e)
|
|
1713
|
+
return [...a];
|
|
1714
|
+
const t = [...a];
|
|
1715
|
+
for (let s = 0; s < e; s++) {
|
|
1716
|
+
const r = s + Math.floor(Math.random() * (t.length - s));
|
|
1717
|
+
[t[s], t[r]] = [t[r], t[s]];
|
|
1581
1718
|
}
|
|
1582
1719
|
return t.slice(0, e);
|
|
1583
1720
|
}
|
|
1584
|
-
function
|
|
1585
|
-
if (
|
|
1586
|
-
return [...
|
|
1587
|
-
const
|
|
1588
|
-
for (const i of
|
|
1721
|
+
function z(a, e, t) {
|
|
1722
|
+
if (a.length <= e)
|
|
1723
|
+
return [...a];
|
|
1724
|
+
const s = /* @__PURE__ */ new Map(), r = [];
|
|
1725
|
+
for (const i of a) {
|
|
1589
1726
|
const u = t(i);
|
|
1590
1727
|
if (u === void 0)
|
|
1591
|
-
|
|
1728
|
+
r.push(i);
|
|
1592
1729
|
else {
|
|
1593
|
-
const
|
|
1594
|
-
|
|
1730
|
+
const d = s.get(u) ?? [];
|
|
1731
|
+
d.push(i), s.set(u, d);
|
|
1595
1732
|
}
|
|
1596
1733
|
}
|
|
1597
|
-
const o =
|
|
1734
|
+
const o = s.size + (r.length > 0 ? 1 : 0);
|
|
1598
1735
|
if (o === 0)
|
|
1599
|
-
return y(
|
|
1736
|
+
return y(a, e);
|
|
1600
1737
|
const n = Math.max(1, Math.floor(e / o)), l = [];
|
|
1601
|
-
for (const i of
|
|
1738
|
+
for (const i of s.values()) {
|
|
1602
1739
|
const u = y(i, n);
|
|
1603
1740
|
l.push(...u);
|
|
1604
1741
|
}
|
|
1605
|
-
if (
|
|
1606
|
-
const i = y(
|
|
1742
|
+
if (r.length > 0) {
|
|
1743
|
+
const i = y(r, n);
|
|
1607
1744
|
l.push(...i);
|
|
1608
1745
|
}
|
|
1609
1746
|
if (l.length < e) {
|
|
1610
|
-
const i =
|
|
1747
|
+
const i = a.filter((d) => !l.includes(d)), u = y(i, e - l.length);
|
|
1611
1748
|
l.push(...u);
|
|
1612
1749
|
}
|
|
1613
1750
|
return l.slice(0, e);
|
|
1614
1751
|
}
|
|
1615
|
-
const
|
|
1752
|
+
const Ze = {
|
|
1616
1753
|
name: "sampleData",
|
|
1617
1754
|
description: "Get sample nodes and/or edges from the graph to inspect actual data structures. Useful for understanding what properties exist and what values they contain before writing selectors.",
|
|
1618
|
-
parameters:
|
|
1619
|
-
target:
|
|
1620
|
-
count:
|
|
1621
|
-
stratifyBy:
|
|
1755
|
+
parameters: c.object({
|
|
1756
|
+
target: Xe,
|
|
1757
|
+
count: c.number().min(1).max(L).optional().describe(`Number of samples to return per type (1-${L}, default ${D})`),
|
|
1758
|
+
stratifyBy: c.string().optional().describe("Property path to stratify sampling by (e.g., 'data.type' to sample from each type)")
|
|
1622
1759
|
}),
|
|
1623
1760
|
examples: [
|
|
1624
1761
|
{ input: "Show me some example nodes", params: { target: "nodes" } },
|
|
@@ -1629,36 +1766,36 @@ const qe = {
|
|
|
1629
1766
|
params: { target: "nodes", count: 6, stratifyBy: "data.type" }
|
|
1630
1767
|
}
|
|
1631
1768
|
],
|
|
1632
|
-
execute(
|
|
1769
|
+
execute(a, e) {
|
|
1633
1770
|
const {
|
|
1634
1771
|
target: t = "both",
|
|
1635
|
-
count:
|
|
1636
|
-
stratifyBy:
|
|
1772
|
+
count: s = D,
|
|
1773
|
+
stratifyBy: r
|
|
1637
1774
|
} = e;
|
|
1638
1775
|
try {
|
|
1639
|
-
const o =
|
|
1776
|
+
const o = a.getDataManager(), n = {};
|
|
1640
1777
|
if (t === "nodes" || t === "both") {
|
|
1641
1778
|
const i = Array.from(o.nodes.values());
|
|
1642
1779
|
let u;
|
|
1643
|
-
|
|
1644
|
-
const p =
|
|
1780
|
+
r ? u = z(i, s, (d) => {
|
|
1781
|
+
const p = M(d.data, r);
|
|
1645
1782
|
return typeof p == "string" ? p : void 0;
|
|
1646
|
-
}) : u = y(i,
|
|
1647
|
-
id: String(
|
|
1648
|
-
data:
|
|
1783
|
+
}) : u = y(i, s), n.nodes = u.map((d) => ({
|
|
1784
|
+
id: String(d.id),
|
|
1785
|
+
data: C(d.data, j)
|
|
1649
1786
|
}));
|
|
1650
1787
|
}
|
|
1651
1788
|
if (t === "edges" || t === "both") {
|
|
1652
1789
|
const i = Array.from(o.edges.values());
|
|
1653
1790
|
let u;
|
|
1654
|
-
|
|
1655
|
-
const p =
|
|
1791
|
+
r ? u = z(i, s, (d) => {
|
|
1792
|
+
const p = M(d.data, r);
|
|
1656
1793
|
return typeof p == "string" ? p : void 0;
|
|
1657
|
-
}) : u = y(i,
|
|
1658
|
-
id:
|
|
1659
|
-
source: String(
|
|
1660
|
-
target: String(
|
|
1661
|
-
data:
|
|
1794
|
+
}) : u = y(i, s), n.edges = u.map((d) => ({
|
|
1795
|
+
id: d.id,
|
|
1796
|
+
source: String(d.srcId),
|
|
1797
|
+
target: String(d.dstId),
|
|
1798
|
+
data: C(d.data, j)
|
|
1662
1799
|
}));
|
|
1663
1800
|
}
|
|
1664
1801
|
const l = [];
|
|
@@ -1674,36 +1811,36 @@ const qe = {
|
|
|
1674
1811
|
});
|
|
1675
1812
|
}
|
|
1676
1813
|
}
|
|
1677
|
-
},
|
|
1678
|
-
function
|
|
1814
|
+
}, q = 20, U = 50, Ye = 5;
|
|
1815
|
+
function Je(a, e, t, s, r) {
|
|
1679
1816
|
const o = t.filter((p) => typeof p == "string"), n = /* @__PURE__ */ new Map();
|
|
1680
1817
|
for (const p of o)
|
|
1681
1818
|
n.set(p, (n.get(p) ?? 0) + 1);
|
|
1682
|
-
const l = Array.from(n.entries()).sort((p,
|
|
1683
|
-
for (const [p,
|
|
1684
|
-
|
|
1685
|
-
count:
|
|
1686
|
-
percentage:
|
|
1819
|
+
const l = Array.from(n.entries()).sort((p, m) => m[1] - p[1]), i = l.length > r, u = l.slice(0, r), d = {};
|
|
1820
|
+
for (const [p, m] of u)
|
|
1821
|
+
d[p] = {
|
|
1822
|
+
count: m,
|
|
1823
|
+
percentage: m / o.length * 100
|
|
1687
1824
|
};
|
|
1688
1825
|
return {
|
|
1689
|
-
property:
|
|
1826
|
+
property: a,
|
|
1690
1827
|
target: e,
|
|
1691
1828
|
type: "string",
|
|
1692
|
-
totalCount: o.length +
|
|
1693
|
-
nullCount:
|
|
1829
|
+
totalCount: o.length + s,
|
|
1830
|
+
nullCount: s,
|
|
1694
1831
|
uniqueCount: n.size,
|
|
1695
|
-
distribution:
|
|
1832
|
+
distribution: d,
|
|
1696
1833
|
truncated: i
|
|
1697
1834
|
};
|
|
1698
1835
|
}
|
|
1699
|
-
function
|
|
1700
|
-
const
|
|
1836
|
+
function Qe(a, e, t, s) {
|
|
1837
|
+
const r = t.filter((l) => typeof l == "number"), o = G(r), n = We(r, Ye);
|
|
1701
1838
|
return {
|
|
1702
|
-
property:
|
|
1839
|
+
property: a,
|
|
1703
1840
|
target: e,
|
|
1704
1841
|
type: "number",
|
|
1705
|
-
totalCount:
|
|
1706
|
-
nullCount:
|
|
1842
|
+
totalCount: r.length + s,
|
|
1843
|
+
nullCount: s,
|
|
1707
1844
|
statistics: {
|
|
1708
1845
|
min: o.min,
|
|
1709
1846
|
max: o.max,
|
|
@@ -1716,73 +1853,73 @@ function Oe(s, e, t, r) {
|
|
|
1716
1853
|
}))
|
|
1717
1854
|
};
|
|
1718
1855
|
}
|
|
1719
|
-
function
|
|
1720
|
-
const
|
|
1856
|
+
function et(a, e, t, s) {
|
|
1857
|
+
const r = t.filter((l) => typeof l == "boolean"), o = r.filter((l) => l).length, n = r.length - o;
|
|
1721
1858
|
return {
|
|
1722
|
-
property:
|
|
1859
|
+
property: a,
|
|
1723
1860
|
target: e,
|
|
1724
1861
|
type: "boolean",
|
|
1725
|
-
totalCount:
|
|
1726
|
-
nullCount:
|
|
1862
|
+
totalCount: r.length + s,
|
|
1863
|
+
nullCount: s,
|
|
1727
1864
|
distribution: {
|
|
1728
1865
|
true: {
|
|
1729
1866
|
count: o,
|
|
1730
|
-
percentage:
|
|
1867
|
+
percentage: r.length > 0 ? o / r.length * 100 : 0
|
|
1731
1868
|
},
|
|
1732
1869
|
false: {
|
|
1733
1870
|
count: n,
|
|
1734
|
-
percentage:
|
|
1871
|
+
percentage: r.length > 0 ? n / r.length * 100 : 0
|
|
1735
1872
|
}
|
|
1736
1873
|
}
|
|
1737
1874
|
};
|
|
1738
1875
|
}
|
|
1739
|
-
function
|
|
1876
|
+
function tt(a, e, t, s, r) {
|
|
1740
1877
|
const o = t.filter((h) => Array.isArray(h)), n = [], l = [];
|
|
1741
1878
|
for (const h of o)
|
|
1742
1879
|
l.push(h.length), n.push(...h);
|
|
1743
|
-
const i =
|
|
1880
|
+
const i = H(n), u = /* @__PURE__ */ new Set();
|
|
1744
1881
|
for (const h of n)
|
|
1745
1882
|
typeof h == "string" ? u.add(h) : typeof h == "number" || typeof h == "boolean" ? u.add(String(h)) : h != null && u.add(JSON.stringify(h));
|
|
1746
|
-
const
|
|
1883
|
+
const d = Array.from(u), p = d.length > r, m = G(l);
|
|
1747
1884
|
return {
|
|
1748
|
-
property:
|
|
1885
|
+
property: a,
|
|
1749
1886
|
target: e,
|
|
1750
1887
|
type: "array",
|
|
1751
|
-
totalCount: o.length +
|
|
1752
|
-
nullCount:
|
|
1888
|
+
totalCount: o.length + s,
|
|
1889
|
+
nullCount: s,
|
|
1753
1890
|
itemType: i,
|
|
1754
|
-
uniqueItems:
|
|
1755
|
-
uniqueItemCount:
|
|
1891
|
+
uniqueItems: d.slice(0, r),
|
|
1892
|
+
uniqueItemCount: d.length,
|
|
1756
1893
|
lengthStatistics: {
|
|
1757
|
-
min:
|
|
1758
|
-
max:
|
|
1759
|
-
avg:
|
|
1894
|
+
min: m.min,
|
|
1895
|
+
max: m.max,
|
|
1896
|
+
avg: m.avg
|
|
1760
1897
|
},
|
|
1761
1898
|
truncated: p
|
|
1762
1899
|
};
|
|
1763
1900
|
}
|
|
1764
|
-
function
|
|
1765
|
-
const
|
|
1901
|
+
function st(a, e, t, s) {
|
|
1902
|
+
const r = {};
|
|
1766
1903
|
for (const o of t) {
|
|
1767
1904
|
const n = typeof o;
|
|
1768
|
-
Array.isArray(o) ?
|
|
1905
|
+
Array.isArray(o) ? r.array = (r.array || 0) + 1 : n === "object" && o !== null ? r.object = (r.object || 0) + 1 : (n === "string" || n === "number" || n === "boolean") && (r[n] = (r[n] || 0) + 1);
|
|
1769
1906
|
}
|
|
1770
1907
|
return {
|
|
1771
|
-
property:
|
|
1908
|
+
property: a,
|
|
1772
1909
|
target: e,
|
|
1773
1910
|
type: "mixed",
|
|
1774
|
-
totalCount: t.length +
|
|
1775
|
-
nullCount:
|
|
1776
|
-
typeCounts:
|
|
1911
|
+
totalCount: t.length + s,
|
|
1912
|
+
nullCount: s,
|
|
1913
|
+
typeCounts: r
|
|
1777
1914
|
};
|
|
1778
1915
|
}
|
|
1779
|
-
const
|
|
1916
|
+
const rt = {
|
|
1780
1917
|
name: "describeProperty",
|
|
1781
1918
|
description: "Get detailed information about a specific property in node or edge data. Returns value distributions for strings, statistics for numbers, counts for booleans, and unique items for arrays.",
|
|
1782
|
-
parameters:
|
|
1783
|
-
property:
|
|
1784
|
-
target:
|
|
1785
|
-
limit:
|
|
1919
|
+
parameters: c.object({
|
|
1920
|
+
property: c.string().describe("Property path to analyze (e.g., 'type', 'data.category', 'weight')"),
|
|
1921
|
+
target: c.enum(["nodes", "edges"]).optional().describe("Whether to analyze node or edge properties (default: 'nodes')"),
|
|
1922
|
+
limit: c.number().min(1).max(U).optional().describe(`Maximum number of unique values to show (1-${U}, default ${q})`)
|
|
1786
1923
|
}),
|
|
1787
1924
|
examples: [
|
|
1788
1925
|
{ input: "Describe the type property on nodes", params: { property: "type", target: "nodes" } },
|
|
@@ -1793,47 +1930,47 @@ const We = {
|
|
|
1793
1930
|
{ input: "Show me the distribution of data.category", params: { property: "data.category" } },
|
|
1794
1931
|
{ input: "Analyze the tags property", params: { property: "tags", limit: 10 } }
|
|
1795
1932
|
],
|
|
1796
|
-
execute(
|
|
1933
|
+
execute(a, e) {
|
|
1797
1934
|
const {
|
|
1798
1935
|
property: t,
|
|
1799
|
-
target:
|
|
1800
|
-
limit:
|
|
1936
|
+
target: s = "nodes",
|
|
1937
|
+
limit: r = q
|
|
1801
1938
|
} = e;
|
|
1802
1939
|
try {
|
|
1803
|
-
const o =
|
|
1940
|
+
const o = a.getDataManager(), n = Array.from(s === "nodes" ? o.nodes.values() : o.edges.values());
|
|
1804
1941
|
if (n.length === 0)
|
|
1805
1942
|
return Promise.resolve({
|
|
1806
1943
|
success: !1,
|
|
1807
|
-
message: `No ${
|
|
1944
|
+
message: `No ${s} found in the graph.`
|
|
1808
1945
|
});
|
|
1809
|
-
const { values: l, nullCount: i } =
|
|
1946
|
+
const { values: l, nullCount: i } = He(n, t);
|
|
1810
1947
|
if (l.length === 0 && i === n.length) {
|
|
1811
|
-
const
|
|
1948
|
+
const m = Be(n);
|
|
1812
1949
|
return Promise.resolve({
|
|
1813
1950
|
success: !1,
|
|
1814
|
-
message: `Property "${t}" not found on ${
|
|
1951
|
+
message: `Property "${t}" not found on ${s}. Available properties: ${m.slice(0, 10).join(", ")}${m.length > 10 ? "..." : ""}`,
|
|
1815
1952
|
data: {
|
|
1816
|
-
availableProperties:
|
|
1953
|
+
availableProperties: m.slice(0, 20)
|
|
1817
1954
|
}
|
|
1818
1955
|
});
|
|
1819
1956
|
}
|
|
1820
|
-
const u =
|
|
1821
|
-
let
|
|
1957
|
+
const u = H(l);
|
|
1958
|
+
let d;
|
|
1822
1959
|
switch (u) {
|
|
1823
1960
|
case "string":
|
|
1824
|
-
|
|
1961
|
+
d = Je(t, s, l, i, r);
|
|
1825
1962
|
break;
|
|
1826
1963
|
case "number":
|
|
1827
|
-
|
|
1964
|
+
d = Qe(t, s, l, i);
|
|
1828
1965
|
break;
|
|
1829
1966
|
case "boolean":
|
|
1830
|
-
|
|
1967
|
+
d = et(t, s, l, i);
|
|
1831
1968
|
break;
|
|
1832
1969
|
case "array":
|
|
1833
|
-
|
|
1970
|
+
d = tt(t, s, l, i, r);
|
|
1834
1971
|
break;
|
|
1835
1972
|
case "mixed":
|
|
1836
|
-
|
|
1973
|
+
d = st(t, s, l, i);
|
|
1837
1974
|
break;
|
|
1838
1975
|
default:
|
|
1839
1976
|
return Promise.resolve({
|
|
@@ -1844,27 +1981,27 @@ const We = {
|
|
|
1844
1981
|
let p;
|
|
1845
1982
|
switch (u) {
|
|
1846
1983
|
case "string": {
|
|
1847
|
-
const
|
|
1848
|
-
p = `Property "${t}" is a string with ${
|
|
1984
|
+
const m = d;
|
|
1985
|
+
p = `Property "${t}" is a string with ${m.uniqueCount} unique value${m.uniqueCount !== 1 ? "s" : ""}.`;
|
|
1849
1986
|
break;
|
|
1850
1987
|
}
|
|
1851
1988
|
case "number": {
|
|
1852
|
-
const
|
|
1853
|
-
p = `Property "${t}" is a number (min: ${
|
|
1989
|
+
const m = d;
|
|
1990
|
+
p = `Property "${t}" is a number (min: ${m.statistics.min.toFixed(2)}, max: ${m.statistics.max.toFixed(2)}, avg: ${m.statistics.avg.toFixed(2)}).`;
|
|
1854
1991
|
break;
|
|
1855
1992
|
}
|
|
1856
1993
|
case "boolean": {
|
|
1857
|
-
const
|
|
1858
|
-
p = `Property "${t}" is a boolean (true: ${
|
|
1994
|
+
const m = d;
|
|
1995
|
+
p = `Property "${t}" is a boolean (true: ${m.distribution.true.percentage.toFixed(1)}%, false: ${m.distribution.false.percentage.toFixed(1)}%).`;
|
|
1859
1996
|
break;
|
|
1860
1997
|
}
|
|
1861
1998
|
case "array": {
|
|
1862
|
-
const
|
|
1863
|
-
p = `Property "${t}" is an array of ${
|
|
1999
|
+
const m = d;
|
|
2000
|
+
p = `Property "${t}" is an array of ${m.itemType} values with ${m.uniqueItemCount} unique item${m.uniqueItemCount !== 1 ? "s" : ""}.`;
|
|
1864
2001
|
break;
|
|
1865
2002
|
}
|
|
1866
2003
|
case "mixed": {
|
|
1867
|
-
const h = Object.keys(
|
|
2004
|
+
const h = Object.keys(d.typeCounts).join(", ");
|
|
1868
2005
|
p = `Property "${t}" has mixed types: ${h}.`;
|
|
1869
2006
|
break;
|
|
1870
2007
|
}
|
|
@@ -1874,7 +2011,7 @@ const We = {
|
|
|
1874
2011
|
return Promise.resolve({
|
|
1875
2012
|
success: !0,
|
|
1876
2013
|
message: p,
|
|
1877
|
-
data:
|
|
2014
|
+
data: d
|
|
1878
2015
|
});
|
|
1879
2016
|
} catch (o) {
|
|
1880
2017
|
return Promise.resolve({
|
|
@@ -1884,7 +2021,7 @@ const We = {
|
|
|
1884
2021
|
}
|
|
1885
2022
|
}
|
|
1886
2023
|
};
|
|
1887
|
-
class
|
|
2024
|
+
class at {
|
|
1888
2025
|
constructor() {
|
|
1889
2026
|
this.name = "mock", this.supportsStreaming = !0, this.supportsTools = !0, this.responses = /* @__PURE__ */ new Map(), this.defaultResponse = {
|
|
1890
2027
|
text: "This is a mock response.",
|
|
@@ -1951,12 +2088,12 @@ class Ge {
|
|
|
1951
2088
|
* @returns Matching response or default response
|
|
1952
2089
|
*/
|
|
1953
2090
|
findResponse(e) {
|
|
1954
|
-
const t = [...e].reverse().find((
|
|
2091
|
+
const t = [...e].reverse().find((r) => r.role === "user");
|
|
1955
2092
|
if (!t)
|
|
1956
2093
|
return this.defaultResponse;
|
|
1957
|
-
const
|
|
1958
|
-
for (const [
|
|
1959
|
-
if (
|
|
2094
|
+
const s = t.content.toLowerCase();
|
|
2095
|
+
for (const [r, o] of this.responses)
|
|
2096
|
+
if (s.includes(r))
|
|
1960
2097
|
return o;
|
|
1961
2098
|
return this.defaultResponse;
|
|
1962
2099
|
}
|
|
@@ -1968,17 +2105,17 @@ class Ge {
|
|
|
1968
2105
|
* @param options.signal - Optional abort signal
|
|
1969
2106
|
* @returns Promise resolving to LLM response
|
|
1970
2107
|
*/
|
|
1971
|
-
async generate(e, t,
|
|
2108
|
+
async generate(e, t, s) {
|
|
1972
2109
|
if (this.callHistory.push({
|
|
1973
2110
|
messages: e,
|
|
1974
2111
|
tools: t,
|
|
1975
2112
|
streaming: !1,
|
|
1976
2113
|
timestamp: Date.now()
|
|
1977
|
-
}),
|
|
2114
|
+
}), s?.signal?.aborted)
|
|
1978
2115
|
throw new Error("Request was aborted");
|
|
1979
2116
|
if (this.configuredError)
|
|
1980
2117
|
throw this.configuredError;
|
|
1981
|
-
if (this.delay > 0 && await new Promise((
|
|
2118
|
+
if (this.delay > 0 && await new Promise((r) => setTimeout(r, this.delay)), s?.signal?.aborted)
|
|
1982
2119
|
throw new Error("Request was aborted");
|
|
1983
2120
|
return this.findResponse(e);
|
|
1984
2121
|
}
|
|
@@ -1990,28 +2127,28 @@ class Ge {
|
|
|
1990
2127
|
* @param callbacks - Streaming callbacks for text and tool calls
|
|
1991
2128
|
* @param signal - Optional abort signal
|
|
1992
2129
|
*/
|
|
1993
|
-
async generateStream(e, t,
|
|
2130
|
+
async generateStream(e, t, s, r) {
|
|
1994
2131
|
if (this.callHistory.push({
|
|
1995
2132
|
messages: e,
|
|
1996
2133
|
tools: t,
|
|
1997
2134
|
streaming: !0,
|
|
1998
2135
|
timestamp: Date.now()
|
|
1999
|
-
}),
|
|
2136
|
+
}), r?.aborted)
|
|
2000
2137
|
throw new Error("Request was aborted");
|
|
2001
2138
|
if (this.configuredError)
|
|
2002
|
-
throw
|
|
2139
|
+
throw s.onError(this.configuredError), this.configuredError;
|
|
2003
2140
|
const o = this.findResponse(e), { text: n } = o;
|
|
2004
2141
|
for (const l of n) {
|
|
2005
|
-
if (
|
|
2142
|
+
if (r?.aborted)
|
|
2006
2143
|
throw new Error("Request was aborted");
|
|
2007
|
-
|
|
2144
|
+
s.onChunk(l), this.delay > 0 && await new Promise((i) => setTimeout(i, this.delay / n.length));
|
|
2008
2145
|
}
|
|
2009
2146
|
for (const l of o.toolCalls) {
|
|
2010
|
-
if (
|
|
2147
|
+
if (r?.aborted)
|
|
2011
2148
|
throw new Error("Request was aborted");
|
|
2012
|
-
|
|
2149
|
+
s.onToolCall(l.name, l.arguments);
|
|
2013
2150
|
}
|
|
2014
|
-
|
|
2151
|
+
s.onComplete(o);
|
|
2015
2152
|
}
|
|
2016
2153
|
/**
|
|
2017
2154
|
* Validate the API key.
|
|
@@ -2026,7 +2163,7 @@ class Ge {
|
|
|
2026
2163
|
return Promise.resolve(!0);
|
|
2027
2164
|
}
|
|
2028
2165
|
}
|
|
2029
|
-
class
|
|
2166
|
+
class ot {
|
|
2030
2167
|
/**
|
|
2031
2168
|
* Creates a new VercelAiProvider instance.
|
|
2032
2169
|
* @param providerType - Type of provider (openai, anthropic, or google)
|
|
@@ -2050,9 +2187,9 @@ class He {
|
|
|
2050
2187
|
throw new Error(`API key not configured for ${this.name}`);
|
|
2051
2188
|
switch (this.providerType) {
|
|
2052
2189
|
case "openai":
|
|
2053
|
-
return
|
|
2190
|
+
return le({ apiKey: this.apiKey, baseURL: this.baseUrl })(this.model ?? "gpt-4o");
|
|
2054
2191
|
case "anthropic":
|
|
2055
|
-
return
|
|
2192
|
+
return ne({
|
|
2056
2193
|
apiKey: this.apiKey,
|
|
2057
2194
|
baseURL: this.baseUrl,
|
|
2058
2195
|
// Enable browser support - Anthropic requires this header for CORS
|
|
@@ -2061,7 +2198,7 @@ class He {
|
|
|
2061
2198
|
}
|
|
2062
2199
|
})(this.model ?? "claude-3-haiku-20240307");
|
|
2063
2200
|
default:
|
|
2064
|
-
return
|
|
2201
|
+
return ie({ apiKey: this.apiKey, baseURL: this.baseUrl })(this.model ?? "gemini-2.0-flash");
|
|
2065
2202
|
}
|
|
2066
2203
|
}
|
|
2067
2204
|
/**
|
|
@@ -2072,14 +2209,14 @@ class He {
|
|
|
2072
2209
|
* @param options.signal - Optional abort signal
|
|
2073
2210
|
* @returns Promise resolving to LLM response
|
|
2074
2211
|
*/
|
|
2075
|
-
async generate(e, t,
|
|
2076
|
-
const
|
|
2077
|
-
model:
|
|
2212
|
+
async generate(e, t, s) {
|
|
2213
|
+
const r = this.getModel(), o = this.convertMessages(e), n = this.convertTools(t), l = await ce({
|
|
2214
|
+
model: r,
|
|
2078
2215
|
messages: o,
|
|
2079
2216
|
tools: n,
|
|
2080
2217
|
maxOutputTokens: this.maxTokens,
|
|
2081
2218
|
temperature: this.temperature,
|
|
2082
|
-
abortSignal:
|
|
2219
|
+
abortSignal: s?.signal
|
|
2083
2220
|
}), { usage: i } = l;
|
|
2084
2221
|
return {
|
|
2085
2222
|
text: l.text,
|
|
@@ -2094,53 +2231,53 @@ class He {
|
|
|
2094
2231
|
* @param callbacks - Streaming callbacks for text and tool calls
|
|
2095
2232
|
* @param signal - Optional abort signal
|
|
2096
2233
|
*/
|
|
2097
|
-
async generateStream(e, t,
|
|
2098
|
-
const o = this.getModel(), n = this.convertMessages(e), l = this.convertTools(t), i =
|
|
2234
|
+
async generateStream(e, t, s, r) {
|
|
2235
|
+
const o = this.getModel(), n = this.convertMessages(e), l = this.convertTools(t), i = ue({
|
|
2099
2236
|
model: o,
|
|
2100
2237
|
messages: n,
|
|
2101
2238
|
tools: l,
|
|
2102
2239
|
maxOutputTokens: this.maxTokens,
|
|
2103
2240
|
temperature: this.temperature,
|
|
2104
|
-
abortSignal:
|
|
2241
|
+
abortSignal: r
|
|
2105
2242
|
});
|
|
2106
2243
|
let u = "";
|
|
2107
|
-
const
|
|
2244
|
+
const d = [];
|
|
2108
2245
|
try {
|
|
2109
|
-
for await (const
|
|
2110
|
-
switch (
|
|
2246
|
+
for await (const m of i.fullStream)
|
|
2247
|
+
switch (m.type) {
|
|
2111
2248
|
case "text-delta":
|
|
2112
|
-
u +=
|
|
2249
|
+
u += m.text, s.onChunk(m.text);
|
|
2113
2250
|
break;
|
|
2114
2251
|
case "tool-call": {
|
|
2115
2252
|
let h = {};
|
|
2116
|
-
"input" in
|
|
2253
|
+
"input" in m ? { input: h } = m : "args" in m && ({ args: h } = m);
|
|
2117
2254
|
const g = {
|
|
2118
|
-
id:
|
|
2119
|
-
name:
|
|
2255
|
+
id: m.toolCallId,
|
|
2256
|
+
name: m.toolName,
|
|
2120
2257
|
arguments: h
|
|
2121
2258
|
};
|
|
2122
|
-
|
|
2259
|
+
d.push(g), s.onToolCall(m.toolName, h);
|
|
2123
2260
|
break;
|
|
2124
2261
|
}
|
|
2125
2262
|
case "tool-result": {
|
|
2126
2263
|
let h;
|
|
2127
|
-
"output" in
|
|
2264
|
+
"output" in m ? { output: h } = m : "result" in m && ({ result: h } = m), s.onToolResult(m.toolName, h);
|
|
2128
2265
|
break;
|
|
2129
2266
|
}
|
|
2130
2267
|
case "error":
|
|
2131
|
-
|
|
2268
|
+
s.onError(new Error(String(m.error)));
|
|
2132
2269
|
break;
|
|
2133
2270
|
default:
|
|
2134
2271
|
break;
|
|
2135
2272
|
}
|
|
2136
2273
|
const p = await i.usage;
|
|
2137
|
-
|
|
2274
|
+
s.onComplete({
|
|
2138
2275
|
text: u,
|
|
2139
|
-
toolCalls:
|
|
2276
|
+
toolCalls: d,
|
|
2140
2277
|
usage: p.inputTokens !== void 0 && p.outputTokens !== void 0 ? { promptTokens: p.inputTokens, completionTokens: p.outputTokens } : void 0
|
|
2141
2278
|
});
|
|
2142
2279
|
} catch (p) {
|
|
2143
|
-
throw
|
|
2280
|
+
throw s.onError(p instanceof Error ? p : new Error(String(p))), p;
|
|
2144
2281
|
}
|
|
2145
2282
|
}
|
|
2146
2283
|
/**
|
|
@@ -2160,11 +2297,11 @@ class He {
|
|
|
2160
2297
|
role: "assistant",
|
|
2161
2298
|
content: [
|
|
2162
2299
|
...t.content ? [{ type: "text", text: t.content }] : [],
|
|
2163
|
-
...t.toolCalls.map((
|
|
2300
|
+
...t.toolCalls.map((s) => ({
|
|
2164
2301
|
type: "tool-call",
|
|
2165
|
-
toolCallId:
|
|
2166
|
-
toolName:
|
|
2167
|
-
input:
|
|
2302
|
+
toolCallId: s.id,
|
|
2303
|
+
toolName: s.name,
|
|
2304
|
+
input: s.arguments
|
|
2168
2305
|
}))
|
|
2169
2306
|
]
|
|
2170
2307
|
} : { role: "assistant", content: t.content };
|
|
@@ -2193,10 +2330,10 @@ class He {
|
|
|
2193
2330
|
*/
|
|
2194
2331
|
convertTools(e) {
|
|
2195
2332
|
const t = {};
|
|
2196
|
-
for (const
|
|
2197
|
-
t[
|
|
2198
|
-
description:
|
|
2199
|
-
inputSchema:
|
|
2333
|
+
for (const s of e)
|
|
2334
|
+
t[s.name] = {
|
|
2335
|
+
description: s.description,
|
|
2336
|
+
inputSchema: s.parameters
|
|
2200
2337
|
};
|
|
2201
2338
|
return t;
|
|
2202
2339
|
}
|
|
@@ -2229,75 +2366,75 @@ class He {
|
|
|
2229
2366
|
}
|
|
2230
2367
|
}
|
|
2231
2368
|
}
|
|
2232
|
-
async function
|
|
2369
|
+
async function nt() {
|
|
2233
2370
|
return (await import("./WebLlmProvider-BEFvNcC5.js")).WebLlmProvider;
|
|
2234
2371
|
}
|
|
2235
|
-
function
|
|
2236
|
-
if (
|
|
2237
|
-
return new
|
|
2238
|
-
if (
|
|
2372
|
+
function it(a) {
|
|
2373
|
+
if (a === "mock")
|
|
2374
|
+
return new at();
|
|
2375
|
+
if (a === "webllm")
|
|
2239
2376
|
throw new Error(
|
|
2240
2377
|
"WebLlmProvider cannot be created synchronously. Use createWebLlmProvider() or getWebLlmProviderClass() instead."
|
|
2241
2378
|
);
|
|
2242
|
-
return new
|
|
2379
|
+
return new ot(a);
|
|
2243
2380
|
}
|
|
2244
|
-
async function
|
|
2245
|
-
const
|
|
2246
|
-
return new
|
|
2381
|
+
async function It() {
|
|
2382
|
+
const a = await nt();
|
|
2383
|
+
return new a();
|
|
2247
2384
|
}
|
|
2248
|
-
const
|
|
2249
|
-
function
|
|
2385
|
+
const $ = 10, V = 50;
|
|
2386
|
+
function lt(a) {
|
|
2250
2387
|
const e = [];
|
|
2251
|
-
return e.push(
|
|
2252
|
-
No custom properties on node data.`),
|
|
2388
|
+
return e.push(ct(a)), a.nodeProperties.length > 0 ? e.push(ut(a.nodeProperties)) : a.nodeCount > 0 && e.push(`### Node Properties
|
|
2389
|
+
No custom properties on node data.`), a.edgeProperties.length > 0 ? e.push(dt(a.edgeProperties)) : a.edgeCount > 0 && e.push(`### Edge Properties
|
|
2253
2390
|
No custom properties on edge data.`), e.join(`
|
|
2254
2391
|
|
|
2255
2392
|
`);
|
|
2256
2393
|
}
|
|
2257
|
-
function
|
|
2394
|
+
function ct(a) {
|
|
2258
2395
|
return `## Data Schema
|
|
2259
|
-
- Nodes: ${
|
|
2260
|
-
- Edges: ${
|
|
2396
|
+
- Nodes: ${a.nodeCount}
|
|
2397
|
+
- Edges: ${a.edgeCount}`;
|
|
2261
2398
|
}
|
|
2262
|
-
function
|
|
2399
|
+
function ut(a) {
|
|
2263
2400
|
const e = ["### Node Properties"];
|
|
2264
|
-
for (const t of
|
|
2265
|
-
e.push(
|
|
2401
|
+
for (const t of a)
|
|
2402
|
+
e.push(X(t));
|
|
2266
2403
|
return e.join(`
|
|
2267
2404
|
`);
|
|
2268
2405
|
}
|
|
2269
|
-
function
|
|
2406
|
+
function dt(a) {
|
|
2270
2407
|
const e = ["### Edge Properties"];
|
|
2271
|
-
for (const t of
|
|
2272
|
-
e.push(
|
|
2408
|
+
for (const t of a)
|
|
2409
|
+
e.push(X(t));
|
|
2273
2410
|
return e.join(`
|
|
2274
2411
|
`);
|
|
2275
2412
|
}
|
|
2276
|
-
function
|
|
2277
|
-
const e =
|
|
2278
|
-
return `- \`${e}\`: ${
|
|
2413
|
+
function X(a) {
|
|
2414
|
+
const e = gt(a.name), t = a.nullable ? "?" : "", s = mt(a), r = pt(a);
|
|
2415
|
+
return `- \`${e}\`: ${s}${t}${r}`;
|
|
2279
2416
|
}
|
|
2280
|
-
function
|
|
2281
|
-
return
|
|
2417
|
+
function mt(a) {
|
|
2418
|
+
return a.type === "array" && a.itemType ? `${a.itemType}[]` : a.type;
|
|
2282
2419
|
}
|
|
2283
|
-
function
|
|
2420
|
+
function pt(a) {
|
|
2284
2421
|
const e = [];
|
|
2285
|
-
if (
|
|
2286
|
-
const t =
|
|
2422
|
+
if (a.format && e.push(`format: ${a.format}`), a.enumValues && a.enumValues.length > 0) {
|
|
2423
|
+
const t = ht(a.enumValues);
|
|
2287
2424
|
e.push(`values: [${t}]`);
|
|
2288
2425
|
}
|
|
2289
|
-
return
|
|
2426
|
+
return a.range && e.push(`range: ${a.range.min}..${a.range.max}`), e.length === 0 ? "" : ` (${e.join(", ")})`;
|
|
2290
2427
|
}
|
|
2291
|
-
function
|
|
2292
|
-
if (
|
|
2293
|
-
return
|
|
2294
|
-
const e =
|
|
2295
|
-
return `${e.map((
|
|
2428
|
+
function ht(a) {
|
|
2429
|
+
if (a.length <= $)
|
|
2430
|
+
return a.map((s) => `"${s}"`).join(", ");
|
|
2431
|
+
const e = a.slice(0, $), t = a.length - $;
|
|
2432
|
+
return `${e.map((s) => `"${s}"`).join(", ")}, ... +${t} more`;
|
|
2296
2433
|
}
|
|
2297
|
-
function
|
|
2298
|
-
return
|
|
2434
|
+
function gt(a) {
|
|
2435
|
+
return a.length <= V ? a : `${a.slice(0, V - 3)}...`;
|
|
2299
2436
|
}
|
|
2300
|
-
class
|
|
2437
|
+
class ft {
|
|
2301
2438
|
/**
|
|
2302
2439
|
* Create a new SchemaManager.
|
|
2303
2440
|
* @param graph - The graph to extract schema from
|
|
@@ -2314,7 +2451,7 @@ class at {
|
|
|
2314
2451
|
*/
|
|
2315
2452
|
extract() {
|
|
2316
2453
|
if (this.cachedSchema === null) {
|
|
2317
|
-
const e = new
|
|
2454
|
+
const e = new O(this.graph, this.options);
|
|
2318
2455
|
this.cachedSchema = e.extract();
|
|
2319
2456
|
}
|
|
2320
2457
|
return this.cachedSchema;
|
|
@@ -2335,7 +2472,7 @@ class at {
|
|
|
2335
2472
|
getFormattedSchema() {
|
|
2336
2473
|
if (this.cachedFormattedSchema === null) {
|
|
2337
2474
|
const e = this.extract();
|
|
2338
|
-
this.cachedFormattedSchema =
|
|
2475
|
+
this.cachedFormattedSchema = lt(e);
|
|
2339
2476
|
}
|
|
2340
2477
|
return this.cachedFormattedSchema;
|
|
2341
2478
|
}
|
|
@@ -2349,13 +2486,13 @@ class at {
|
|
|
2349
2486
|
this.cachedSchema = null, this.cachedFormattedSchema = null;
|
|
2350
2487
|
}
|
|
2351
2488
|
}
|
|
2352
|
-
const
|
|
2353
|
-
class
|
|
2489
|
+
const yt = 300;
|
|
2490
|
+
class Z {
|
|
2354
2491
|
/**
|
|
2355
2492
|
* Creates a new AiManager instance.
|
|
2356
2493
|
*/
|
|
2357
2494
|
constructor() {
|
|
2358
|
-
this.graph = null, this.controller = null, this.provider = null, this.schemaManager = null, this.dataAddedListenerId = null, this.debouncedSchemaUpdate = null, this.disposed = !1, this.initialized = !1, this.commandRegistry = new
|
|
2495
|
+
this.graph = null, this.controller = null, this.provider = null, this.schemaManager = null, this.dataAddedListenerId = null, this.debouncedSchemaUpdate = null, this.disposed = !1, this.initialized = !1, this.commandRegistry = new pe(), this.apiKeyManager = new de(), this.statusManager = new F();
|
|
2359
2496
|
}
|
|
2360
2497
|
/**
|
|
2361
2498
|
* Initialize the AI Manager with a graph and configuration.
|
|
@@ -2367,18 +2504,18 @@ class F {
|
|
|
2367
2504
|
encryptionKey: t.keyPersistence.encryptionKey,
|
|
2368
2505
|
storage: t.keyPersistence.storage ?? "localStorage",
|
|
2369
2506
|
prefix: t.keyPersistence.prefix
|
|
2370
|
-
}), t.providerInstance ? this.provider = t.providerInstance : (this.provider =
|
|
2507
|
+
}), t.providerInstance ? this.provider = t.providerInstance : (this.provider = it(t.provider), t.apiKey && (this.apiKeyManager.setKey(t.provider, t.apiKey), this.provider.configure({
|
|
2371
2508
|
apiKey: t.apiKey,
|
|
2372
2509
|
model: t.model
|
|
2373
|
-
}))), t.registerBuiltinCommands !== !1 && this.registerBuiltinCommands(), this.initializeSchemaManager(), this.controller = new
|
|
2510
|
+
}))), t.registerBuiltinCommands !== !1 && this.registerBuiltinCommands(), this.initializeSchemaManager(), this.controller = new me({
|
|
2374
2511
|
provider: this.provider,
|
|
2375
2512
|
commandRegistry: this.commandRegistry,
|
|
2376
2513
|
graph: this.graph,
|
|
2377
2514
|
schemaManager: this.schemaManager,
|
|
2378
2515
|
// Onto the graph's own event channel, so `addListener` and the element's DOM
|
|
2379
2516
|
// forwarder both deliver every AI event.
|
|
2380
|
-
emitEvent: (
|
|
2381
|
-
e.eventManager.emitGraphEvent(
|
|
2517
|
+
emitEvent: (s) => {
|
|
2518
|
+
e.eventManager.emitGraphEvent(s.type, { ...s });
|
|
2382
2519
|
}
|
|
2383
2520
|
}), this.initialized = !0);
|
|
2384
2521
|
}
|
|
@@ -2387,9 +2524,9 @@ class F {
|
|
|
2387
2524
|
*/
|
|
2388
2525
|
initializeSchemaManager() {
|
|
2389
2526
|
if (this.graph) {
|
|
2390
|
-
this.schemaManager = new
|
|
2527
|
+
this.schemaManager = new ft(this.graph), this.schemaManager.extract(), this.debouncedSchemaUpdate = Y.debounce(() => {
|
|
2391
2528
|
this.schemaManager && this.schemaManager.invalidateCache();
|
|
2392
|
-
},
|
|
2529
|
+
}, yt);
|
|
2393
2530
|
try {
|
|
2394
2531
|
const { eventManager: e } = this.graph;
|
|
2395
2532
|
this.dataAddedListenerId = e.addListener("data-added", () => {
|
|
@@ -2403,7 +2540,7 @@ class F {
|
|
|
2403
2540
|
* Register built-in commands for graph control.
|
|
2404
2541
|
*/
|
|
2405
2542
|
registerBuiltinCommands() {
|
|
2406
|
-
this.registerCommand(
|
|
2543
|
+
this.registerCommand(ye), this.registerCommand(be), this.registerCommand(Se), this.registerCommand(Ze), this.registerCommand(rt), this.registerCommand(_e), this.registerCommand(Oe), this.registerCommand(xe), this.registerCommand(Me), this.registerCommand(Ae), this.registerCommand(Le), this.registerCommand(je), this.registerCommand(ze), this.registerCommand(Ue), this.registerCommand(Fe);
|
|
2407
2544
|
}
|
|
2408
2545
|
/**
|
|
2409
2546
|
* Register a custom command.
|
|
@@ -2531,39 +2668,41 @@ class F {
|
|
|
2531
2668
|
}
|
|
2532
2669
|
}
|
|
2533
2670
|
}
|
|
2534
|
-
function
|
|
2535
|
-
return new
|
|
2671
|
+
function vt() {
|
|
2672
|
+
return new Z();
|
|
2536
2673
|
}
|
|
2537
|
-
const
|
|
2674
|
+
const Rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2538
2675
|
__proto__: null,
|
|
2539
|
-
AiManager:
|
|
2540
|
-
createAiManager:
|
|
2676
|
+
AiManager: Z,
|
|
2677
|
+
createAiManager: vt
|
|
2541
2678
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2542
2679
|
export {
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2680
|
+
me as A,
|
|
2681
|
+
pe as C,
|
|
2682
|
+
at as M,
|
|
2683
|
+
O as S,
|
|
2684
|
+
ot as V,
|
|
2685
|
+
Z as a,
|
|
2686
|
+
F as b,
|
|
2687
|
+
ft as c,
|
|
2688
|
+
ze as d,
|
|
2689
|
+
vt as e,
|
|
2690
|
+
lt as f,
|
|
2691
|
+
it as g,
|
|
2692
|
+
It as h,
|
|
2693
|
+
rt as i,
|
|
2694
|
+
je as j,
|
|
2695
|
+
Le as k,
|
|
2696
|
+
be as l,
|
|
2697
|
+
nt as m,
|
|
2698
|
+
_e as n,
|
|
2699
|
+
Ue as o,
|
|
2700
|
+
Me as p,
|
|
2701
|
+
ye as q,
|
|
2702
|
+
Oe as r,
|
|
2703
|
+
Ze as s,
|
|
2704
|
+
Ae as t,
|
|
2705
|
+
xe as u,
|
|
2706
|
+
Rt as v,
|
|
2707
|
+
Fe as z
|
|
2569
2708
|
};
|