@graphty/graphty-element 2.6.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/dist/ai.js +3 -3
  2. package/dist/catalog.js +53 -54
  3. package/dist/chunks/{AiManager-4iQpsJW1.js → AiManager-Bhh0rR_p.js} +706 -655
  4. package/dist/chunks/GraphSession-DPoTaT3b.js +21175 -0
  5. package/dist/chunks/{GraphtyLogger-B_O67a6c.js → GraphtyLogger-BtcBJQPL.js} +1 -1
  6. package/dist/chunks/{VoiceInputAdapter-Cc6mHXTI.js → VoiceInputAdapter-CdLsJ_nG.js} +1 -1
  7. package/dist/chunks/{XRPivotCameraController-BLa89LXn.js → XRPivotCameraController-CiLJ9Gz6.js} +2 -2
  8. package/dist/chunks/algorithms-qij74zEN.js +6811 -0
  9. package/dist/chunks/{capability-check-Am2zliFj.js → capability-check-BbgTejS3.js} +1 -1
  10. package/dist/chunks/definePalette-BYt2Llxs.js +1333 -0
  11. package/dist/chunks/fields-5uVC1Pll.js +4999 -0
  12. package/dist/chunks/{format-detection-BHwrAVzW.js → format-detection-FKaDMshR.js} +1 -1
  13. package/dist/chunks/{index-BkBLbvui.js → index-Cc_6D9hV.js} +6034 -7127
  14. package/dist/chunks/interpolation-Dk206AhZ.js +105 -0
  15. package/dist/chunks/paletteRegistry-De3CGdst.js +357 -0
  16. package/dist/chunks/parse-SVp77JbE.js +669 -0
  17. package/dist/chunks/{pluginRegistry-Bs8bEkz9.js → pluginRegistry-Ddfl6Mv2.js} +27 -24
  18. package/dist/chunks/{registry-BdGvyZou.js → registry-CgMqldp4.js} +1 -1
  19. package/dist/chunks/{DataSource-BL2UzPff.js → sources-BbAJCDIH.js} +279 -108
  20. package/dist/commands.d.ts +128 -19
  21. package/dist/commands.js +49 -1
  22. package/dist/custom-elements.json +1 -1
  23. package/dist/extend.d.ts +10 -2
  24. package/dist/extend.js +64 -57
  25. package/dist/graphty-catalog.json +6 -3
  26. package/dist/graphty.bundle.js +267177 -240648
  27. package/dist/graphty.js +84 -78
  28. package/dist/index.d.ts +4 -0
  29. package/dist/logging.js +2 -2
  30. package/dist/schema.js +70 -71
  31. package/dist/session.d.ts +5 -6
  32. package/dist/session.js +40 -86
  33. package/dist/src/Edge.d.ts +31 -67
  34. package/dist/src/Graph.d.ts +335 -77
  35. package/dist/src/Node.d.ts +36 -3
  36. package/dist/src/NodeBehavior.d.ts +28 -0
  37. package/dist/src/Styles.d.ts +15 -4
  38. package/dist/src/acceleration/AccelerationController.d.ts +8 -0
  39. package/dist/src/acceleration/narrow.d.ts +9 -1
  40. package/dist/src/acceleration/types.d.ts +10 -0
  41. package/dist/src/ai/AiController.d.ts +12 -0
  42. package/dist/src/ai/AiManager.d.ts +7 -0
  43. package/dist/src/ai/commands/AlgorithmCommands.d.ts +1 -1
  44. package/dist/src/ai/commands/LayoutCommands.d.ts +1 -1
  45. package/dist/src/ai/commands/StyleCommands.d.ts +1 -1
  46. package/dist/src/ai/commands/types.d.ts +20 -1
  47. package/dist/src/algorithms/Algorithm.d.ts +21 -4
  48. package/dist/src/algorithms/BFSAlgorithm.d.ts +0 -9
  49. package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +0 -14
  50. package/dist/src/algorithms/DFSAlgorithm.d.ts +1 -1
  51. package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +5 -0
  52. package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +5 -0
  53. package/dist/src/algorithms/LeidenAlgorithm.d.ts +5 -0
  54. package/dist/src/algorithms/PageRankAlgorithm.d.ts +1 -1
  55. package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +1 -1
  56. package/dist/src/algorithms/metrics/fields.d.ts +23 -1
  57. package/dist/src/algorithms/utils/graphUtils.d.ts +13 -1
  58. package/dist/src/catalog/paletteRegistry.d.ts +4 -4
  59. package/dist/src/catalog/registry.d.ts +3 -2
  60. package/dist/src/catalog/types.d.ts +18 -1
  61. package/dist/src/config/GraphStyle.d.ts +1 -1
  62. package/dist/src/config/StyleTemplate.d.ts +2 -2
  63. package/dist/src/config/xr-config-schema.d.ts +4 -4
  64. package/dist/src/data/CSVDataSource.d.ts +77 -22
  65. package/dist/src/data/ErrorAggregator.d.ts +5 -0
  66. package/dist/src/data/GEXFDataSource.d.ts +12 -61
  67. package/dist/src/data/GraphMLDataSource.d.ts +3 -44
  68. package/dist/src/data/GraphStore.d.ts +322 -15
  69. package/dist/src/data/JsonDataSource.d.ts +43 -1
  70. package/dist/src/data/graph-io-import.d.ts +89 -0
  71. package/dist/src/data/graph-io-records.d.ts +64 -0
  72. package/dist/src/data/lane.d.ts +23 -0
  73. package/dist/src/data/positions.d.ts +13 -0
  74. package/dist/src/data/seedPosition.d.ts +16 -0
  75. package/dist/src/errors/GraphtyError.d.ts +3 -1
  76. package/dist/src/errors/codes.d.ts +23 -0
  77. package/dist/src/events.d.ts +12 -0
  78. package/dist/src/graphty-element.d.ts +149 -54
  79. package/dist/src/input/types.d.ts +2 -0
  80. package/dist/src/layout/D3GraphLayoutEngine.d.ts +17 -3
  81. package/dist/src/layout/FixedLayoutEngine.d.ts +20 -4
  82. package/dist/src/layout/KamadaKawaiLayoutEngine.d.ts +6 -0
  83. package/dist/src/layout/LayoutEngine.d.ts +214 -116
  84. package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -3
  85. package/dist/src/layout/SimulationLayoutEngine.d.ts +8 -3
  86. package/dist/src/managers/AlgorithmManager.d.ts +24 -5
  87. package/dist/src/managers/DataManager.d.ts +258 -181
  88. package/dist/src/managers/EventManager.d.ts +5 -2
  89. package/dist/src/managers/GraphContext.d.ts +7 -0
  90. package/dist/src/managers/InputManager.d.ts +11 -0
  91. package/dist/src/managers/LayoutManager.d.ts +129 -50
  92. package/dist/src/managers/RenderManager.d.ts +14 -1
  93. package/dist/src/managers/UpdateManager.d.ts +20 -0
  94. package/dist/src/screenshot/ScreenshotCapture.d.ts +1 -1
  95. package/dist/src/session/GraphSession.d.ts +83 -6
  96. package/dist/src/session/commands/algo.d.ts +169 -0
  97. package/dist/src/session/commands/config.d.ts +45 -0
  98. package/dist/src/session/commands/data.d.ts +178 -0
  99. package/dist/src/session/commands/doors.d.ts +93 -0
  100. package/dist/src/session/commands/index.d.ts +20 -0
  101. package/dist/src/session/commands/layout.d.ts +104 -0
  102. package/dist/src/session/commands/positions.d.ts +30 -0
  103. package/dist/src/session/commands/sets.d.ts +113 -0
  104. package/dist/src/session/commands/style.d.ts +92 -0
  105. package/dist/src/session/commands/view.d.ts +57 -0
  106. package/dist/src/session/commands/visibility.d.ts +41 -0
  107. package/dist/src/session/data.d.ts +131 -4
  108. package/dist/src/session/index.d.ts +1 -1
  109. package/dist/src/session/planning.d.ts +25 -8
  110. package/dist/src/session/project/Dispatcher.d.ts +905 -0
  111. package/dist/src/session/project/History.d.ts +382 -0
  112. package/dist/src/session/project/arrangement.d.ts +247 -0
  113. package/dist/src/session/project/derive.d.ts +132 -0
  114. package/dist/src/session/project/digest.d.ts +33 -0
  115. package/dist/src/session/project/draft.d.ts +194 -0
  116. package/dist/src/session/project/graphOps.d.ts +304 -0
  117. package/dist/src/session/project/ingest.d.ts +364 -0
  118. package/dist/src/session/project/state.d.ts +145 -0
  119. package/dist/src/session/project/strict.d.ts +68 -0
  120. package/dist/src/session/results/RunResult.d.ts +48 -0
  121. package/dist/src/session/results/statistics.d.ts +20 -0
  122. package/dist/src/session/runs/Run.d.ts +80 -4
  123. package/dist/src/session/runs/RunsApi.d.ts +23 -6
  124. package/dist/src/session/runs/types.d.ts +25 -6
  125. package/dist/src/session/scope/ElementMask.d.ts +14 -0
  126. package/dist/src/session/scope/ScopeApi.d.ts +3 -22
  127. package/dist/src/session/scope/spaces.d.ts +29 -0
  128. package/dist/src/session/sealed.d.ts +22 -0
  129. package/dist/src/session/selection/SelectionApi.d.ts +14 -4
  130. package/dist/src/session/sets/SetsApi.d.ts +13 -5
  131. package/dist/src/session/sets/store.d.ts +54 -53
  132. package/dist/src/session/sets/types.d.ts +5 -2
  133. package/dist/src/session/styles/Layer.d.ts +5 -0
  134. package/dist/src/session/styles/StylesApi.d.ts +68 -17
  135. package/dist/src/session/styles/autoApply.d.ts +64 -53
  136. package/dist/src/session/styles/index.d.ts +3 -3
  137. package/dist/src/session/styles/predicate.d.ts +7 -0
  138. package/dist/src/session/styles/repaint.d.ts +16 -1
  139. package/dist/src/session/styles/sources.d.ts +1 -1
  140. package/dist/src/session/types.d.ts +625 -54
  141. package/dist/src/session/visibility/VisibilityApi.d.ts +38 -18
  142. package/dist/src/session/visibility/filter.d.ts +10 -0
  143. package/dist/src/simple/defineAlgorithm.d.ts +28 -0
  144. package/dist/src/simple/defineLayout.d.ts +35 -0
  145. package/dist/src/simple/defineLogDestination.d.ts +31 -0
  146. package/dist/src/simple/definePalette.d.ts +26 -0
  147. package/dist/src/simple/definition.d.ts +106 -0
  148. package/dist/src/simple/options.d.ts +33 -0
  149. package/dist/src/simple/source.d.ts +49 -0
  150. package/dist/src/simple/types.d.ts +366 -0
  151. package/dist/src/simple/view.d.ts +107 -0
  152. package/dist/webgpu.js +2 -2
  153. package/package.json +10 -12
  154. package/dist/chunks/GraphSession-BhuHSXIo.js +0 -12819
  155. package/dist/chunks/GraphStyle-Cwr55SAE.js +0 -65
  156. package/dist/chunks/algorithms-BJ6DQMOe.js +0 -3777
  157. package/dist/chunks/detect-fyuVnlCT.js +0 -88
  158. package/dist/chunks/interpolation-DY-PNpqX.js +0 -43
  159. package/dist/chunks/optionsFromZod-CKMYSwTz.js +0 -3636
  160. package/dist/chunks/paletteRegistry-BCFSwJGK.js +0 -1196
  161. package/dist/chunks/parse-BMTqt4SS.js +0 -3658
  162. package/dist/src/data/csv-variant-detection.d.ts +0 -29
  163. package/dist/src/data/ingest.d.ts +0 -104
@@ -1,17 +1,17 @@
1
- import { l as Y } from "./VoiceInputAdapter-Cc6mHXTI.js";
2
- import { G as J } from "./GraphtyLogger-B_O67a6c.js";
3
- import { z as c } from "zod";
4
- import { k as Q, A as x, B as P } from "./optionsFromZod-CKMYSwTz.js";
5
- import { N as ee, e as te, C as se, d as re } from "./algorithms-BJ6DQMOe.js";
6
- import ae from "jmespath";
1
+ import { l as ee } from "./VoiceInputAdapter-CdLsJ_nG.js";
2
+ import { G as te } from "./GraphtyLogger-BtcBJQPL.js";
3
+ import { z as d } from "zod";
4
+ import { t as se, A as M, U as E } from "./fields-5uVC1Pll.js";
5
+ import { k as re, N as ae, f as oe, C as ne, e as ie } from "./algorithms-qij74zEN.js";
6
+ import le from "jmespath";
7
+ import { i as _ } from "./pluginRegistry-Ddfl6Mv2.js";
7
8
  import { inferSchema as A } from "@jsonhero/schema-infer";
8
- import { i as oe } from "./pluginRegistry-Bs8bEkz9.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 {
9
+ import { createAnthropic as ce } from "@ai-sdk/anthropic";
10
+ import { createGoogleGenerativeAI as ue } from "@ai-sdk/google";
11
+ import { createOpenAI as de } from "@ai-sdk/openai";
12
+ import { generateText as me, streamText as pe } from "ai";
13
+ import { A as he } from "./ApiKeyManager-C0ac91dE.js";
14
+ class K {
15
15
  /**
16
16
  * Creates a new AiStatusManager instance.
17
17
  */
@@ -112,13 +112,13 @@ class F {
112
112
  * @param result - Optional result data
113
113
  */
114
114
  updateToolCallStatus(e, t, s) {
115
- const { toolCalls: r } = this.status;
116
- if (!r)
115
+ const { toolCalls: a } = this.status;
116
+ if (!a)
117
117
  return;
118
- const o = r.findIndex((l) => l.name === e);
118
+ const o = a.findIndex((l) => l.name === e);
119
119
  if (o === -1)
120
120
  return;
121
- const n = [...r];
121
+ const n = [...a];
122
122
  n[o] = {
123
123
  ...n[o],
124
124
  status: t,
@@ -186,14 +186,19 @@ class F {
186
186
  };
187
187
  }
188
188
  }
189
- const f = J.getLogger(["graphty", "ai"]);
190
- class me {
189
+ const f = te.getLogger(["graphty", "ai"]);
190
+ class T extends Error {
191
+ constructor(e) {
192
+ super(e.message), this.result = e;
193
+ }
194
+ }
195
+ class ge {
191
196
  /**
192
197
  * Creates a new AiController instance.
193
198
  * @param options - Configuration options for the controller
194
199
  */
195
200
  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 F(), this.schemaManager = e.schemaManager ?? null, this.emitEvent = e.emitEvent, this.statusManager.subscribe((t) => {
201
+ 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 K(), this.schemaManager = e.schemaManager ?? null, this.emitEvent = e.emitEvent, this.statusManager.subscribe((t) => {
197
202
  this.emitAiEvent({
198
203
  type: "ai-status-change",
199
204
  status: t
@@ -224,41 +229,26 @@ class me {
224
229
  timestamp: this.startTime
225
230
  }), this.statusManager.submit();
226
231
  try {
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
- if (f.debug("Response", {
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
- type: "ai-stream-chunk",
235
- text: r.text,
236
- accumulated: r.text
237
- })), r.toolCalls.length === 0) {
238
- this.statusManager.complete();
239
- const n = {
240
- success: !0,
241
- message: r.text || "No response from AI",
242
- llmText: r.text
243
- };
244
- return this.emitAiEvent({
245
- type: "ai-command-complete",
246
- result: n,
247
- duration: Date.now() - this.startTime
248
- }), n;
232
+ let t;
233
+ try {
234
+ t = await this.graph.getSession().transaction(e, (s, a) => this.converse(e, s, a), {
235
+ provenance: { via: "assistant" }
236
+ });
237
+ } catch (s) {
238
+ if (!(s instanceof T))
239
+ throw s;
240
+ ({ result: t } = s);
249
241
  }
250
- this.statusManager.startExecuting();
251
- const o = await this.executeToolCalls(r.toolCalls, r.text);
252
242
  return this.statusManager.complete(), this.emitAiEvent({
253
243
  type: "ai-command-complete",
254
- result: o,
244
+ result: t,
255
245
  duration: Date.now() - this.startTime
256
- }), o;
246
+ }), t;
257
247
  } catch (t) {
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({
248
+ const s = t instanceof Error ? t.message : String(t), a = t instanceof Error ? t : new Error(s);
249
+ return this.lastError = a, this.statusManager.setError(a, !0), this.emitAiEvent({
260
250
  type: "ai-command-error",
261
- error: r,
251
+ error: a,
262
252
  input: e,
263
253
  canRetry: !0
264
254
  }), {
@@ -320,87 +310,128 @@ When the user asks you to perform an action, use the appropriate tool. If no too
320
310
  ${this.schemaManager.getFormattedSchema()}
321
311
  `;
322
312
  }
313
+ /**
314
+ * One message, inside its transaction: ask the model, then run the tools it calls.
315
+ * @param input - The user's natural language input
316
+ * @param tx - The message's transaction, which the tools write through
317
+ * @param signal - Fires when the message is cancelled or its transaction aborted
318
+ * @returns The execution result
319
+ */
320
+ async converse(e, t, s) {
321
+ const { abortController: a } = this;
322
+ s.addEventListener(
323
+ "abort",
324
+ () => {
325
+ a?.abort(s.reason);
326
+ },
327
+ { once: !0 }
328
+ );
329
+ const o = a?.signal ?? s, n = this.buildMessages(e), l = this.commandRegistry.toToolDefinitions();
330
+ f.debug("Request", { messages: n, tools: l.map((c) => c.name) }), this.statusManager.startStreaming();
331
+ const i = await this.provider.generate(n, l, { signal: o });
332
+ return f.debug("Response", {
333
+ text: i.text || "(no text)",
334
+ toolCalls: i.toolCalls.map((c) => ({ name: c.name, arguments: c.arguments }))
335
+ }), i.text && (this.statusManager.appendStreamedText(i.text), this.emitAiEvent({
336
+ type: "ai-stream-chunk",
337
+ text: i.text,
338
+ accumulated: i.text
339
+ })), i.toolCalls.length === 0 ? {
340
+ success: !0,
341
+ message: i.text || "No response from AI",
342
+ llmText: i.text
343
+ } : (this.statusManager.startExecuting(), this.executeToolCalls(i.toolCalls, t, o, i.text));
344
+ }
323
345
  /**
324
346
  * Execute a list of tool calls.
325
347
  * @param toolCalls - Tool calls to execute
348
+ * @param tx - The message's transaction
349
+ * @param signal - Fires when the message is cancelled
326
350
  * @param llmText - Text response from LLM (if any)
327
351
  * @returns Combined execution result
352
+ * @throws MessageRolledBack when a tool threw, so the message's transaction rolls back.
328
353
  */
329
- async executeToolCalls(e, t) {
330
- const s = [];
331
- for (const r of e) {
332
- this.statusManager.addToolCall(r.name), this.statusManager.updateToolCallStatus(r.name, "executing"), this.emitAiEvent({
354
+ async executeToolCalls(e, t, s, a) {
355
+ const o = [];
356
+ let n = !1;
357
+ for (const i of e) {
358
+ s.throwIfAborted(), this.statusManager.addToolCall(i.name), this.statusManager.updateToolCallStatus(i.name, "executing"), this.emitAiEvent({
333
359
  type: "ai-stream-tool-call",
334
- name: r.name,
335
- params: r.arguments
360
+ name: i.name,
361
+ params: i.arguments
336
362
  });
337
363
  try {
338
- const o = await this.executeToolCall(r);
339
- if (s.push(o), this.statusManager.updateToolCallStatus(
340
- r.name,
341
- o.success ? "complete" : "error",
342
- o.data ?? { message: o.message }
364
+ const c = await this.executeToolCall(i, t);
365
+ if (o.push(c), this.statusManager.updateToolCallStatus(
366
+ i.name,
367
+ c.success ? "complete" : "error",
368
+ c.data ?? { message: c.message }
343
369
  ), this.emitAiEvent({
344
370
  type: "ai-stream-tool-result",
345
- name: r.name,
346
- result: o.data ?? { message: o.message },
347
- success: o.success
348
- }), !o.success)
371
+ name: i.name,
372
+ result: c.data ?? { message: c.message },
373
+ success: c.success
374
+ }), !c.success)
349
375
  break;
350
- } catch (o) {
351
- const n = o instanceof Error ? o.message : String(o), l = {
376
+ } catch (c) {
377
+ const u = c instanceof Error ? c.message : String(c), p = {
352
378
  success: !1,
353
- message: `Error executing ${r.name}: ${n}`
379
+ message: `Error executing ${i.name}: ${u}`
354
380
  };
355
- s.push(l), this.statusManager.updateToolCallStatus(r.name, "error", { error: n }), this.emitAiEvent({
381
+ o.push(p), this.statusManager.updateToolCallStatus(i.name, "error", { error: u }), this.emitAiEvent({
356
382
  type: "ai-stream-tool-result",
357
- name: r.name,
358
- result: { error: n },
383
+ name: i.name,
384
+ result: { error: u },
359
385
  success: !1
360
- });
386
+ }), n = !0;
361
387
  break;
362
388
  }
363
389
  }
364
- return this.combineResults(s, t);
390
+ const l = this.combineResults(o, a);
391
+ if (n)
392
+ throw new T(l);
393
+ return l;
365
394
  }
366
395
  /**
367
396
  * Execute a single tool call.
368
397
  * @param toolCall - The tool call to execute
398
+ * @param tx - The message's transaction, handed to the command as `ctx.tx`
369
399
  * @returns Command result
370
400
  */
371
- async executeToolCall(e) {
401
+ async executeToolCall(e, t) {
372
402
  f.debug("Executing command", { name: e.name, arguments: e.arguments });
373
- const t = this.commandRegistry.get(e.name);
374
- if (!t)
403
+ const s = this.commandRegistry.get(e.name);
404
+ if (!s)
375
405
  return f.debug("Command result: FAILED - Unknown command", { name: e.name }), {
376
406
  success: !1,
377
407
  message: `Unknown command: ${e.name}. Command not found in registry.`
378
408
  };
379
- let s;
409
+ let a;
380
410
  try {
381
- s = t.parameters.parse(e.arguments), f.debug("Validated arguments", { arguments: s });
382
- } catch (n) {
383
- const l = n instanceof Error ? n.message : String(n);
384
- return f.debug("Command result: FAILED - Invalid arguments", { error: l }), {
411
+ a = s.parameters.parse(e.arguments), f.debug("Validated arguments", { arguments: a });
412
+ } catch (l) {
413
+ const i = l instanceof Error ? l.message : String(l);
414
+ return f.debug("Command result: FAILED - Invalid arguments", { error: i }), {
385
415
  success: !1,
386
- message: `Invalid arguments for ${e.name}: ${l}`
416
+ message: `Invalid arguments for ${e.name}: ${i}`
387
417
  };
388
418
  }
389
- const r = {
419
+ const o = {
390
420
  graph: this.graph,
421
+ tx: t,
391
422
  abortSignal: this.abortController?.signal ?? new AbortController().signal,
392
- emitEvent: (n, l) => {
393
- f.debug("Command emitted event", { type: n, data: l });
423
+ emitEvent: (l, i) => {
424
+ f.debug("Command emitted event", { type: l, data: i });
394
425
  },
395
- updateStatus: (n) => {
396
- n.stageMessage && this.statusManager.setStage("executing", n.stageMessage);
426
+ updateStatus: (l) => {
427
+ l.stageMessage && this.statusManager.setStage("executing", l.stageMessage);
397
428
  }
398
- }, o = await t.execute(this.graph, s, r);
429
+ }, n = await s.execute(this.graph, a, o);
399
430
  return f.debug("Command result", {
400
- success: o.success,
401
- message: o.message,
402
- data: o.data
403
- }), o;
431
+ success: n.success,
432
+ message: n.message,
433
+ data: n.data
434
+ }), n;
404
435
  }
405
436
  /**
406
437
  * Combine multiple command results into a single result.
@@ -415,12 +446,12 @@ ${this.schemaManager.getFormattedSchema()}
415
446
  message: t ?? "No commands executed",
416
447
  llmText: t
417
448
  };
418
- const s = e.every((i) => i.success), r = e.map((i) => i.message);
419
- t && r.unshift(t);
449
+ const s = e.every((i) => i.success), a = e.map((i) => i.message);
450
+ t && a.unshift(t);
420
451
  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
452
  return {
422
453
  success: s,
423
- message: r.join(`
454
+ message: a.join(`
424
455
  `),
425
456
  data: l.data,
426
457
  affectedNodes: o.length > 0 ? o : void 0,
@@ -460,7 +491,7 @@ ${this.schemaManager.getFormattedSchema()}
460
491
  this.disposed = !0, this.cancel(), this.statusManager.reset();
461
492
  }
462
493
  }
463
- class pe {
494
+ class fe {
464
495
  constructor() {
465
496
  this.commands = /* @__PURE__ */ new Map();
466
497
  }
@@ -529,7 +560,7 @@ class pe {
529
560
  }));
530
561
  }
531
562
  }
532
- const he = {
563
+ const ye = {
533
564
  maxSampleSize: 1e3,
534
565
  maxDepth: 3,
535
566
  enumMaxAbsoluteUnique: 10,
@@ -537,7 +568,7 @@ const he = {
537
568
  enumMaxStringLength: 64,
538
569
  enumMinSampleSize: 25
539
570
  };
540
- class ge {
571
+ class ve {
541
572
  constructor(e) {
542
573
  this.values = /* @__PURE__ */ new Map(), this.options = e;
543
574
  }
@@ -559,10 +590,10 @@ class ge {
559
590
  */
560
591
  trackObject(e, t = "", s = 0) {
561
592
  if (!(s >= this.options.maxDepth))
562
- for (const [r, o] of Object.entries(e)) {
563
- if (t === "" && r === "id")
593
+ for (const [a, o] of Object.entries(e)) {
594
+ if (t === "" && a === "id")
564
595
  continue;
565
- const n = t ? `${t}.${r}` : r;
596
+ const n = t ? `${t}.${a}` : a;
566
597
  typeof o == "string" ? this.trackValue(n, o) : o !== null && typeof o == "object" && !Array.isArray(o) && this.trackObject(o, n, s + 1);
567
598
  }
568
599
  }
@@ -581,27 +612,27 @@ class ge {
581
612
  const t = this.values.get(e);
582
613
  if (!t || t.length < this.options.enumMinSampleSize)
583
614
  return { isEnum: !1 };
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);
615
+ const s = [...new Set(t)], a = s.length / t.length, o = s.length <= this.options.enumMaxAbsoluteUnique || a <= this.options.enumMaxUniqueRatio, n = s.every((l) => l.length <= this.options.enumMaxStringLength);
585
616
  return o && n ? { isEnum: !0, values: s.sort() } : { isEnum: !1 };
586
617
  }
587
618
  }
588
- class O {
619
+ class W {
589
620
  /**
590
621
  * Creates a new SchemaExtractor instance.
591
622
  * @param graph - The graph to extract schema from
592
623
  * @param options - Optional extraction options
593
624
  */
594
625
  constructor(e, t = {}) {
595
- this.graph = e, this.options = { ...he, ...t };
626
+ this.graph = e, this.options = { ...ye, ...t };
596
627
  }
597
628
  /**
598
629
  * Extract schema from the graph.
599
630
  * @returns SchemaSummary with node and edge property information
600
631
  */
601
632
  extract() {
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);
633
+ const e = this.graph.getDataManager(), t = this.graph.getNodeCount(), s = this.graph.getEdgeCount(), a = 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
634
  return {
604
- nodeProperties: this.extractFromCollection(r),
635
+ nodeProperties: this.extractFromCollection(a),
605
636
  edgeProperties: this.extractFromCollection(o),
606
637
  nodeCount: t,
607
638
  edgeCount: s
@@ -615,14 +646,14 @@ class O {
615
646
  extractFromCollection(e) {
616
647
  if (e.length === 0)
617
648
  return [];
618
- const t = e.length <= this.options.maxSampleSize ? e : this.sampleEvenly(e, this.options.maxSampleSize), [s, ...r] = t;
649
+ const t = e.length <= this.options.maxSampleSize ? e : this.sampleEvenly(e, this.options.maxSampleSize), [s, ...a] = t;
619
650
  let o = A(s);
620
- for (const i of r)
651
+ for (const i of a)
621
652
  o = A(
622
653
  i,
623
654
  o
624
655
  );
625
- const n = o.toSnapshot(), l = new ge(this.options);
656
+ const n = o.toSnapshot(), l = new ve(this.options);
626
657
  for (const i of t)
627
658
  l.trackObject(i, "", 0);
628
659
  return this.mergeResults(n, l);
@@ -636,12 +667,12 @@ class O {
636
667
  mergeResults(e, t) {
637
668
  const s = [];
638
669
  if (e.type === "object" && e.properties) {
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);
670
+ for (const [a, o] of Object.entries(e.properties.required))
671
+ this.extractProperties(a, o, t, "", !1, s);
672
+ for (const [a, o] of Object.entries(e.properties.optional))
673
+ this.extractProperties(a, o, t, "", !0, s);
643
674
  }
644
- return s.sort((r, o) => r.name.localeCompare(o.name));
675
+ return s.sort((a, o) => a.name.localeCompare(o.name));
645
676
  }
646
677
  /**
647
678
  * Recursively extract properties, handling nested objects with dot notation.
@@ -653,19 +684,19 @@ class O {
653
684
  * @param properties - Array to accumulate property summaries
654
685
  * @param depth - Current recursion depth
655
686
  */
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)
687
+ extractProperties(e, t, s, a, o, n, l = 0) {
688
+ const i = a ? `${a}.${e}` : e;
689
+ if (a === "" && e === "id" || l >= this.options.maxDepth)
659
690
  return;
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))
691
+ let c = o, u = t;
692
+ if (t.type === "nullable" && t.schema && (c = !0, u = t.schema), u.type === "object" && u.properties) {
693
+ for (const [m, h] of Object.entries(u.properties.required))
663
694
  this.extractProperties(m, h, s, i, !1, n, l + 1);
664
- for (const [m, h] of Object.entries(d.properties.optional))
695
+ for (const [m, h] of Object.entries(u.properties.optional))
665
696
  this.extractProperties(m, h, s, i, !0, n, l + 1);
666
697
  return;
667
698
  }
668
- const p = this.schemaToSummary(i, d, s, u);
699
+ const p = this.schemaToSummary(i, u, s, c);
669
700
  p && n.push(p);
670
701
  }
671
702
  /**
@@ -676,11 +707,11 @@ class O {
676
707
  * @param nullable - Whether the property can be null
677
708
  * @returns Property summary or null if not convertible
678
709
  */
679
- schemaToSummary(e, t, s, r) {
710
+ schemaToSummary(e, t, s, a) {
680
711
  const o = {
681
712
  name: e,
682
713
  type: this.inferredTypeToPropertyType(t),
683
- nullable: r
714
+ nullable: a
684
715
  };
685
716
  switch (t.type) {
686
717
  case "string": {
@@ -735,19 +766,19 @@ class O {
735
766
  * @returns Array of evenly distributed samples
736
767
  */
737
768
  sampleEvenly(e, t) {
738
- const s = [], r = e.length / t;
769
+ const s = [], a = e.length / t;
739
770
  for (let o = 0; o < t; o++) {
740
- const n = Math.floor(o * r);
771
+ const n = Math.floor(o * a);
741
772
  s.push(e[n]);
742
773
  }
743
774
  return s;
744
775
  }
745
776
  }
746
- const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"]).describe("Type of information to query about the graph"), ye = {
777
+ const be = d.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"]).describe("Type of information to query about the graph"), we = {
747
778
  name: "queryGraph",
748
779
  description: "Query information about the graph structure, including node count, edge count, current layout, and overall statistics.",
749
- parameters: c.object({
750
- query: fe
780
+ parameters: d.object({
781
+ query: be
751
782
  }),
752
783
  examples: [
753
784
  { input: "How many nodes are there?", params: { query: "nodeCount" } },
@@ -756,12 +787,12 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
756
787
  { input: "Show me the graph summary", params: { query: "summary" } },
757
788
  { input: "Give me all the graph stats", params: { query: "all" } }
758
789
  ],
759
- execute(a, e) {
790
+ execute(r, e) {
760
791
  const { query: t } = e;
761
792
  try {
762
793
  switch (t) {
763
794
  case "nodeCount": {
764
- const s = a.getNodeCount();
795
+ const s = r.getNodeCount();
765
796
  return Promise.resolve({
766
797
  success: !0,
767
798
  message: `The graph has ${s} node${s !== 1 ? "s" : ""}.`,
@@ -769,7 +800,7 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
769
800
  });
770
801
  }
771
802
  case "edgeCount": {
772
- const s = a.getEdgeCount();
803
+ const s = r.getEdgeCount();
773
804
  return Promise.resolve({
774
805
  success: !0,
775
806
  message: `The graph has ${s} edge${s !== 1 ? "s" : ""}.`,
@@ -777,37 +808,37 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
777
808
  });
778
809
  }
779
810
  case "currentLayout": {
780
- const r = a.getLayoutManager().layoutEngine?.type ?? "unknown";
811
+ const a = r.getLayoutManager().layoutEngine?.type ?? "unknown";
781
812
  return Promise.resolve({
782
813
  success: !0,
783
- message: `The current layout is "${r}".`,
784
- data: { layout: r }
814
+ message: `The current layout is "${a}".`,
815
+ data: { layout: a }
785
816
  });
786
817
  }
787
818
  case "all":
788
819
  case "summary": {
789
- const s = a.getNodeCount(), r = a.getEdgeCount(), n = a.getLayoutManager().layoutEngine?.type ?? "unknown", l = a.getViewMode() === "2d";
820
+ const s = r.getNodeCount(), a = r.getEdgeCount(), n = r.getLayoutManager().layoutEngine?.type ?? "unknown", l = r.getViewMode() === "2d";
790
821
  return Promise.resolve({
791
822
  success: !0,
792
823
  message: `Graph Summary:
793
824
  - Nodes: ${s}
794
- - Edges: ${r}
825
+ - Edges: ${a}
795
826
  - Layout: ${n}
796
827
  - Mode: ${l ? "2D" : "3D"}`,
797
828
  data: {
798
829
  nodeCount: s,
799
- edgeCount: r,
830
+ edgeCount: a,
800
831
  layout: n,
801
832
  is2D: l
802
833
  }
803
834
  });
804
835
  }
805
836
  default: {
806
- const s = a.getNodeCount(), r = a.getEdgeCount();
837
+ const s = r.getNodeCount(), a = r.getEdgeCount();
807
838
  return Promise.resolve({
808
839
  success: !0,
809
- message: `Unknown query type "${String(t)}". The graph has ${s} nodes and ${r} edges.`,
810
- data: { nodeCount: s, edgeCount: r }
840
+ message: `Unknown query type "${String(t)}". The graph has ${s} nodes and ${a} edges.`,
841
+ data: { nodeCount: s, edgeCount: a }
811
842
  });
812
843
  }
813
844
  }
@@ -818,44 +849,44 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
818
849
  });
819
850
  }
820
851
  }
821
- }, ve = 50, be = {
852
+ }, Se = 50, Ce = {
822
853
  name: "findNodes",
823
854
  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(
855
+ parameters: d.object({
856
+ selector: d.string().describe(
826
857
  `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
858
  ),
828
- limit: c.number().optional().describe("Maximum number of node IDs to return (default 50)")
859
+ limit: d.number().optional().describe("Maximum number of node IDs to return (default 50)")
829
860
  }),
830
861
  examples: [
831
862
  { input: "Find all server nodes", params: { selector: "type == 'server'" } },
832
863
  { input: "Find nodes with high degree", params: { selector: "degree > 5" } },
833
864
  { input: "Get first 10 nodes", params: { selector: "", limit: 10 } }
834
865
  ],
835
- execute(a, e) {
866
+ execute(r, e) {
836
867
  const { selector: t, limit: s } = e;
837
868
  try {
838
- const r = a.getDataManager(), o = Array.from(r.nodes.values());
869
+ const a = r.getDataManager(), o = Array.from(a.nodes.values());
839
870
  let n;
840
871
  !t || t === "" || t === "*" ? n = o : n = o.filter((p) => {
841
872
  try {
842
873
  const m = /^(\w+)\s*==\s*['"](.+)['"]$/.exec(t);
843
874
  if (m) {
844
- const [, g, b] = m, v = p.data[g];
845
- return typeof v == "boolean" ? v === (b === "true") : v === b;
875
+ const [, g, v] = m, w = p.data[g];
876
+ return typeof w == "boolean" ? w === (v === "true") : w === v;
846
877
  }
847
878
  const h = /^(\w+)\s*(>|<|>=|<=)\s*(\d+)$/.exec(t);
848
879
  if (h) {
849
- const [, g, b, v] = h, w = Number(p.data[g]), S = Number(v);
850
- switch (b) {
880
+ const [, g, v, w] = h, S = Number(p.data[g]), C = Number(w);
881
+ switch (v) {
851
882
  case ">":
852
- return w > S;
883
+ return S > C;
853
884
  case "<":
854
- return w < S;
885
+ return S < C;
855
886
  case ">=":
856
- return w >= S;
887
+ return S >= C;
857
888
  case "<=":
858
- return w <= S;
889
+ return S <= C;
859
890
  default:
860
891
  return !1;
861
892
  }
@@ -865,31 +896,31 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
865
896
  return !1;
866
897
  }
867
898
  });
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;
899
+ const l = n.length, i = n.slice(0, s !== void 0 && s > 0 ? s : Se).map((p) => String(p.id)), c = i.length, u = l > c;
869
900
  return Promise.resolve({
870
901
  success: !0,
871
- message: `Found ${l} matching node${l !== 1 ? "s" : ""}${d ? ` (showing ${u})` : ""}.`,
902
+ message: `Found ${l} matching node${l !== 1 ? "s" : ""}${u ? ` (showing ${c})` : ""}.`,
872
903
  data: {
873
904
  total: l,
874
- returned: u,
875
- count: u,
876
- truncated: d,
905
+ returned: c,
906
+ count: c,
907
+ truncated: u,
877
908
  nodeIds: i
878
909
  },
879
910
  affectedNodes: i
880
911
  });
881
- } catch (r) {
912
+ } catch (a) {
882
913
  return Promise.resolve({
883
914
  success: !1,
884
- message: `Failed to find nodes: ${r.message}`
915
+ message: `Failed to find nodes: ${a.message}`
885
916
  });
886
917
  }
887
918
  }
888
- }, we = c.enum(["nodeTypes", "edgeTypes", "nodeProperties", "edgeProperties", "all"]).describe("Type of schema information to retrieve"), Se = {
919
+ }, $e = d.enum(["nodeTypes", "edgeTypes", "nodeProperties", "edgeProperties", "all"]).describe("Type of schema information to retrieve"), xe = {
889
920
  name: "getSchema",
890
921
  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.",
891
- parameters: c.object({
892
- query: we
922
+ parameters: d.object({
923
+ query: $e
893
924
  }),
894
925
  examples: [
895
926
  { input: "What types of nodes are there?", params: { query: "nodeTypes" } },
@@ -898,21 +929,21 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
898
929
  { input: "What edge properties are available?", params: { query: "edgeProperties" } },
899
930
  { input: "Show me the data schema", params: { query: "all" } }
900
931
  ],
901
- execute(a, e) {
932
+ execute(r, e) {
902
933
  const { query: t } = e;
903
934
  try {
904
- const r = new O(a).extract(), o = a.getDataManager(), n = (l, i, u = 20) => {
905
- const d = /* @__PURE__ */ new Set();
935
+ const a = new W(r).extract(), o = r.getDataManager(), n = (l, i, c = 20) => {
936
+ const u = /* @__PURE__ */ new Set();
906
937
  for (const p of l) {
907
938
  const m = p.data?.[i];
908
- if (typeof m == "string" && (d.add(m), d.size > u))
939
+ if (typeof m == "string" && (u.add(m), u.size > c))
909
940
  return [];
910
941
  }
911
- return Array.from(d).sort();
942
+ return Array.from(u).sort();
912
943
  };
913
944
  switch (t) {
914
945
  case "nodeTypes": {
915
- let i = r.nodeProperties.find((u) => u.name === "type")?.enumValues ?? [];
946
+ let i = a.nodeProperties.find((c) => c.name === "type")?.enumValues ?? [];
916
947
  return i.length === 0 && (i = n(o.nodes.values(), "type")), i.length === 0 ? Promise.resolve({
917
948
  success: !0,
918
949
  message: "No distinct node types found. Nodes may not have a 'type' property, or there are too many unique values to categorize.",
@@ -924,7 +955,7 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
924
955
  });
925
956
  }
926
957
  case "edgeTypes": {
927
- let i = r.edgeProperties.find((u) => u.name === "type")?.enumValues ?? [];
958
+ let i = a.edgeProperties.find((c) => c.name === "type")?.enumValues ?? [];
928
959
  return i.length === 0 && (i = n(o.edges.values(), "type")), i.length === 0 ? Promise.resolve({
929
960
  success: !0,
930
961
  message: "No distinct edge types found. Edges may not have a 'type' property, or there are too many unique values to categorize.",
@@ -936,22 +967,22 @@ const fe = c.enum(["nodeCount", "edgeCount", "currentLayout", "all", "summary"])
936
967
  });
937
968
  }
938
969
  case "nodeProperties": {
939
- const l = r.nodeProperties.map((i) => {
940
- let u = `${i.name}: ${i.type}`;
941
- return i.enumValues && i.enumValues.length > 0 && (u += ` (values: ${i.enumValues.join(", ")})`), i.range && (u += ` (range: ${i.range.min}-${i.range.max})`), u;
970
+ const l = a.nodeProperties.map((i) => {
971
+ let c = `${i.name}: ${i.type}`;
972
+ return i.enumValues && i.enumValues.length > 0 && (c += ` (values: ${i.enumValues.join(", ")})`), i.range && (c += ` (range: ${i.range.min}-${i.range.max})`), c;
942
973
  });
943
974
  return Promise.resolve({
944
975
  success: !0,
945
976
  message: `Node properties:
946
977
  ${l.map((i) => `- ${i}`).join(`
947
978
  `)}`,
948
- data: { nodeProperties: r.nodeProperties }
979
+ data: { nodeProperties: a.nodeProperties }
949
980
  });
950
981
  }
951
982
  case "edgeProperties": {
952
- const l = r.edgeProperties.map((i) => {
953
- let u = `${i.name}: ${i.type}`;
954
- return i.enumValues && i.enumValues.length > 0 && (u += ` (values: ${i.enumValues.join(", ")})`), i.range && (u += ` (range: ${i.range.min}-${i.range.max})`), u;
983
+ const l = a.edgeProperties.map((i) => {
984
+ let c = `${i.name}: ${i.type}`;
985
+ return i.enumValues && i.enumValues.length > 0 && (c += ` (values: ${i.enumValues.join(", ")})`), i.range && (c += ` (range: ${i.range.min}-${i.range.max})`), c;
955
986
  });
956
987
  return l.length === 0 ? Promise.resolve({
957
988
  success: !0,
@@ -962,23 +993,23 @@ ${l.map((i) => `- ${i}`).join(`
962
993
  message: `Edge properties:
963
994
  ${l.map((i) => `- ${i}`).join(`
964
995
  `)}`,
965
- data: { edgeProperties: r.edgeProperties }
996
+ data: { edgeProperties: a.edgeProperties }
966
997
  });
967
998
  }
968
999
  case "all": {
969
- let i = r.nodeProperties.find((g) => g.name === "type")?.enumValues ?? [];
1000
+ let i = a.nodeProperties.find((g) => g.name === "type")?.enumValues ?? [];
970
1001
  i.length === 0 && (i = n(o.nodes.values(), "type"));
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);
1002
+ let u = a.edgeProperties.find((g) => g.name === "type")?.enumValues ?? [];
1003
+ u.length === 0 && (u = n(o.edges.values(), "type"));
1004
+ const p = a.nodeProperties.map((g) => g.name), m = a.edgeProperties.map((g) => g.name);
974
1005
  let h = `Graph Schema Summary:
975
- - ${r.nodeCount} nodes with ${r.nodeProperties.length} properties
976
- - ${r.edgeCount} edges with ${r.edgeProperties.length} properties`;
1006
+ - ${a.nodeCount} nodes with ${a.nodeProperties.length} properties
1007
+ - ${a.edgeCount} edges with ${a.edgeProperties.length} properties`;
977
1008
  return i.length > 0 && (h += `
978
1009
 
979
- Node types: ${i.join(", ")}`), d.length > 0 && (h += `
1010
+ Node types: ${i.join(", ")}`), u.length > 0 && (h += `
980
1011
 
981
- Edge types: ${d.join(", ")}`), p.length > 0 && (h += `
1012
+ Edge types: ${u.join(", ")}`), p.length > 0 && (h += `
982
1013
 
983
1014
  Node properties: ${p.join(", ")}`), m.length > 0 && (h += `
984
1015
 
@@ -986,12 +1017,12 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
986
1017
  success: !0,
987
1018
  message: h,
988
1019
  data: {
989
- nodeCount: r.nodeCount,
990
- edgeCount: r.edgeCount,
1020
+ nodeCount: a.nodeCount,
1021
+ edgeCount: a.edgeCount,
991
1022
  nodeTypes: i,
992
- edgeTypes: d,
993
- nodeProperties: r.nodeProperties,
994
- edgeProperties: r.edgeProperties
1023
+ edgeTypes: u,
1024
+ nodeProperties: a.nodeProperties,
1025
+ edgeProperties: a.edgeProperties
995
1026
  }
996
1027
  });
997
1028
  }
@@ -1008,12 +1039,16 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
1008
1039
  });
1009
1040
  }
1010
1041
  }
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 = {
1042
+ };
1043
+ function y(r, e) {
1044
+ return e?.tx ?? r.getSession();
1045
+ }
1046
+ const Me = d.string().describe("Layout algorithm type (e.g., 'circular', 'ngraph', 'random', 'spiral', 'd3')"), Pe = d.enum(["2d", "3d"]).describe("Dimension mode: '2d' or '3d'"), Ee = {
1012
1047
  name: "setLayout",
1013
1048
  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'.",
1014
- parameters: c.object({
1015
- type: Ce,
1016
- options: c.record(c.unknown()).optional().describe("Additional layout-specific options")
1049
+ parameters: d.object({
1050
+ type: Me,
1051
+ options: d.record(d.unknown()).optional().describe("Additional layout-specific options")
1017
1052
  }),
1018
1053
  examples: [
1019
1054
  { input: "Use circular layout", params: { type: "circular" } },
@@ -1023,30 +1058,30 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
1023
1058
  { input: "Use D3 force layout", params: { type: "d3" } },
1024
1059
  { input: "Shell layout", params: { type: "shell" } }
1025
1060
  ],
1026
- async execute(a, e) {
1027
- const { type: t, options: s = {} } = e;
1061
+ async execute(r, e, t) {
1062
+ const { type: s, options: a = {} } = e;
1028
1063
  try {
1029
- return await a.setLayout(t, s), {
1064
+ return await y(r, t).layout.set(re(s) ?? s, { engine: s, options: a }), {
1030
1065
  success: !0,
1031
- message: `Layout changed to "${t}". The graph is now being rearranged.`,
1032
- data: { layoutType: t }
1066
+ message: `Layout changed to "${s}". The graph is now being rearranged.`,
1067
+ data: { layoutType: s }
1033
1068
  };
1034
- } catch (r) {
1035
- const o = r.message;
1036
- return o.includes("not found") || o.includes("unknown") || o.includes("invalid") ? {
1069
+ } catch (o) {
1070
+ const n = o.message;
1071
+ return _(o) && o.code === "E_UNKNOWN_LAYOUT" || n.includes("not found") || n.includes("unknown") || n.includes("invalid") ? {
1037
1072
  success: !1,
1038
- message: `Invalid layout type "${t}". Try 'circular', 'ngraph', 'random', 'spiral', 'shell', or 'd3'.`
1073
+ message: `Invalid layout type "${s}". Try 'circular', 'ngraph', 'random', 'spiral', 'shell', or 'd3'.`
1039
1074
  } : {
1040
1075
  success: !1,
1041
- message: `Failed to set layout to "${t}": ${o}`
1076
+ message: `Failed to set layout to "${s}": ${n}`
1042
1077
  };
1043
1078
  }
1044
1079
  }
1045
- }, Me = {
1080
+ }, Ae = {
1046
1081
  name: "setDimension",
1047
1082
  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.",
1048
- parameters: c.object({
1049
- dimension: $e
1083
+ parameters: d.object({
1084
+ dimension: Pe
1050
1085
  }),
1051
1086
  examples: [
1052
1087
  { input: "Switch to 2D view", params: { dimension: "2d" } },
@@ -1054,27 +1089,27 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
1054
1089
  { input: "Make it flat", params: { dimension: "2d" } },
1055
1090
  { input: "Enable 3D mode", params: { dimension: "3d" } }
1056
1091
  ],
1057
- async execute(a, e) {
1058
- const { dimension: t } = e;
1092
+ async execute(r, e, t) {
1093
+ const { dimension: s } = e;
1059
1094
  try {
1060
- const s = t === "2d", r = s ? "2D" : "3D";
1061
- return await a.setViewMode(s ? "2d" : "3d"), {
1095
+ const a = s === "2d", o = a ? "2D" : "3D";
1096
+ return await y(r, t).layout.setDimension(a ? "2d" : "3d"), {
1062
1097
  success: !0,
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 }
1098
+ message: `Switched to ${o} mode. The graph will now be displayed ${a ? "on a flat plane" : "in three-dimensional space"}.`,
1099
+ data: { dimension: o, is2D: a }
1065
1100
  };
1066
- } catch (s) {
1101
+ } catch (a) {
1067
1102
  return {
1068
1103
  success: !1,
1069
- message: `Failed to change dimension: ${s.message}`
1104
+ message: `Failed to change dimension: ${a.message}`
1070
1105
  };
1071
1106
  }
1072
1107
  }
1073
- }, Pe = c.enum(["vr", "ar", "exit"]).describe("VR for virtual reality, AR for augmented reality, exit to return to normal view"), Ae = {
1108
+ }, Te = d.enum(["vr", "ar", "exit"]).describe("VR for virtual reality, AR for augmented reality, exit to return to normal view"), Ne = {
1074
1109
  name: "setImmersiveMode",
1075
1110
  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.",
1076
- parameters: c.object({
1077
- mode: Pe
1111
+ parameters: d.object({
1112
+ mode: Te
1078
1113
  }),
1079
1114
  examples: [
1080
1115
  { input: "Enter VR mode", params: { mode: "vr" } },
@@ -1085,25 +1120,25 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
1085
1120
  { input: "Show augmented reality view", params: { mode: "ar" } },
1086
1121
  { input: "Go back to normal view", params: { mode: "exit" } }
1087
1122
  ],
1088
- async execute(a, e) {
1123
+ async execute(r, e) {
1089
1124
  const { mode: t } = e;
1090
1125
  try {
1091
1126
  if (t === "exit") {
1092
- const n = a.exitImmersiveMode;
1093
- return n && await n.call(a), {
1127
+ const n = r.exitImmersiveMode;
1128
+ return n && await n.call(r), {
1094
1129
  success: !0,
1095
1130
  message: "Exited immersive mode, returned to normal view."
1096
1131
  };
1097
1132
  }
1098
- const { getXRHelper: s } = a, r = s?.call(a);
1099
- if (!r)
1133
+ const { getXRHelper: s } = r, a = s?.call(r);
1134
+ if (!a)
1100
1135
  return {
1101
1136
  success: !1,
1102
1137
  message: `WebXR is not available. ${t.toUpperCase()} mode requires a WebXR-capable browser and device.`
1103
1138
  };
1104
1139
  if (t === "vr") {
1105
- const { enterVR: n } = r;
1106
- return n ? (await n.call(r), {
1140
+ const { enterVR: n } = a;
1141
+ return n ? (await n.call(a), {
1107
1142
  success: !0,
1108
1143
  message: "Entering VR mode. Put on your headset to view the graph in virtual reality."
1109
1144
  }) : {
@@ -1111,8 +1146,8 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
1111
1146
  message: "VR mode is not supported on this device or browser."
1112
1147
  };
1113
1148
  }
1114
- const { enterAR: o } = r;
1115
- return o ? (await o.call(r), {
1149
+ const { enterAR: o } = a;
1150
+ return o ? (await o.call(a), {
1116
1151
  success: !0,
1117
1152
  message: "Entering AR mode. Point your device to see the graph in augmented reality."
1118
1153
  }) : {
@@ -1126,60 +1161,60 @@ Edge properties: ${m.join(", ")}`), Promise.resolve({
1126
1161
  };
1127
1162
  }
1128
1163
  }
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(
1164
+ }, ke = d.object({
1165
+ color: d.string().optional().describe("Color for the node (e.g., '#ff0000', 'red')"),
1166
+ size: d.number().positive().optional().describe("Size of the node (default is 1)"),
1167
+ shape: d.string().optional().describe("Shape type (e.g., 'sphere', 'box', 'cylinder')"),
1168
+ glowColor: d.string().optional().describe("Glow effect color"),
1169
+ glowStrength: d.number().positive().optional().describe("Glow effect strength. One strength is drawn at a time for the whole scene"),
1170
+ outlineColor: d.string().optional().describe("Outline color"),
1171
+ outlineWidth: d.number().positive().optional().describe(
1137
1172
  "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"
1138
1173
  ),
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) {
1174
+ enabled: d.boolean().optional().describe("Whether the node is visible")
1175
+ }).describe("Style properties for nodes"), Ie = d.object({
1176
+ color: d.string().optional().describe("Color for the edge line (e.g., '#00ff00', 'green')"),
1177
+ width: d.number().positive().optional().describe("Width of the edge line"),
1178
+ lineType: d.string().optional().describe("Line pattern (e.g., 'solid', 'dash', 'dot')"),
1179
+ arrowColor: d.string().optional().describe("Color for the arrow head"),
1180
+ arrowSize: d.number().positive().optional().describe("Size of the arrow head"),
1181
+ arrowOpacity: d.number().min(0).max(1).optional().describe("Opacity of the arrow head, 0 to 1"),
1182
+ enabled: d.boolean().optional().describe("Whether the edge is visible")
1183
+ }).describe("Style properties for edges"), Re = { by: "plugin", name: "graphty-ai" };
1184
+ function De(r) {
1150
1185
  const e = {}, t = [];
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 };
1186
+ return r.color !== void 0 && (e["node.color"] = r.color), r.size !== void 0 && (e["node.size"] = r.size), r.shape !== void 0 && (e["node.shape"] = r.shape), r.glowColor !== void 0 && (e["node.glow"] = r.glowColor), r.glowStrength !== void 0 && (e["node.glowStrength"] = r.glowStrength), r.outlineColor !== void 0 && (e["node.outline"] = r.outlineColor), r.enabled === !1 && (e["node.opacity"] = 0), r.outlineWidth !== void 0 && t.push({ property: "outlineWidth", reason: ae }), { set: e, unsupported: t };
1152
1187
  }
1153
- function Ie(a) {
1188
+ function Le(r) {
1154
1189
  const e = {};
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: [] };
1190
+ return r.color !== void 0 && (e["edge.color"] = r.color), r.width !== void 0 && (e["edge.width"] = r.width), r.lineType !== void 0 && (e["edge.style"] = r.lineType), r.enabled === !1 && (e["edge.opacity"] = 0), r.arrowColor !== void 0 && (e["edge.arrowHeadColor"] = r.arrowColor), r.arrowSize !== void 0 && (e["edge.arrowHeadSize"] = r.arrowSize), r.arrowOpacity !== void 0 && (e["edge.arrowHeadOpacity"] = r.arrowOpacity), { set: e, unsupported: [] };
1156
1191
  }
1157
- const Re = /* @__PURE__ */ new Set(["", "*", "all", "*.*", "true"]);
1158
- function De(a) {
1159
- return !a || Re.has(a.toLowerCase().trim());
1192
+ const je = /* @__PURE__ */ new Set(["", "*", "all", "*.*", "true"]);
1193
+ function ze(r) {
1194
+ return !r || je.has(r.toLowerCase().trim());
1160
1195
  }
1161
- function _(a, e, t, s) {
1196
+ function G(r, e, t, s) {
1162
1197
  return {
1163
- name: a,
1198
+ name: r,
1164
1199
  target: e,
1165
1200
  kind: "custom",
1166
- source: Ne,
1167
- selector: De(t) ? { match: "everything" } : { match: "expression", where: t.replace(/"/g, "'") },
1201
+ source: Re,
1202
+ selector: ze(t) ? { match: "everything" } : { match: "expression", where: t.replace(/"/g, "'") },
1168
1203
  set: s
1169
1204
  };
1170
1205
  }
1171
- function K(a) {
1172
- return oe(a) ? `${a.message} (${a.code})` : a instanceof Error ? a.message : String(a);
1206
+ function H(r) {
1207
+ return _(r) ? `${r.message} (${r.code})` : r instanceof Error ? r.message : String(r);
1173
1208
  }
1174
- async function W(a, e, t, s) {
1175
- const { styles: r } = a.getSession(), o = r.validate(e);
1209
+ async function B(r, e, t, s) {
1210
+ const { styles: a } = r, o = a.validate(e);
1176
1211
  if (!o.ok)
1177
1212
  return {
1178
1213
  success: !1,
1179
1214
  message: `That ${s} style could not be applied: ${o.errors.map((n) => n.message).join(" ")}`
1180
1215
  };
1181
1216
  try {
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.`;
1217
+ const n = await a.add(e), l = t.map(({ property: c, reason: u }) => ` ${c} was not applied: ${u}`).join(""), i = o.unresolvedPaths.length === 0 ? "" : ` Nothing in this graph answers ${o.unresolvedPaths.join(", ")} yet, so the layer may paint nothing until it does.`;
1183
1218
  return {
1184
1219
  success: !0,
1185
1220
  message: `Added the ${s} style layer "${n.name}".${l}${i}`,
@@ -1188,19 +1223,19 @@ async function W(a, e, t, s) {
1188
1223
  } catch (n) {
1189
1224
  return {
1190
1225
  success: !1,
1191
- message: `That ${s} style could not be applied: ${K(n)}`
1226
+ message: `That ${s} style could not be applied: ${H(n)}`
1192
1227
  };
1193
1228
  }
1194
1229
  }
1195
- const Le = {
1230
+ const Ue = {
1196
1231
  name: "findAndStyleNodes",
1197
1232
  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.`,
1198
- parameters: c.object({
1199
- selector: c.string().describe(
1233
+ parameters: d.object({
1234
+ selector: d.string().describe(
1200
1235
  `Expression matching nodes (empty string matches all). A record's own fields live under 'data.', so write 'data.type == "server"'.`
1201
1236
  ),
1202
- style: Ee,
1203
- layerName: c.string().optional().describe("Name for this style layer (for later removal)")
1237
+ style: ke,
1238
+ layerName: d.string().optional().describe("Name for this style layer (for later removal)")
1204
1239
  }),
1205
1240
  examples: [
1206
1241
  {
@@ -1224,23 +1259,23 @@ const Le = {
1224
1259
  params: { selector: "", style: { shape: "box" }, layerName: "box-shapes" }
1225
1260
  }
1226
1261
  ],
1227
- async execute(a, e) {
1262
+ async execute(r, e, t) {
1228
1263
  const {
1229
- selector: t,
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");
1264
+ selector: s,
1265
+ style: a,
1266
+ layerName: o = `ai-node-style-${Date.now()}`
1267
+ } = e, { set: n, unsupported: l } = De(a);
1268
+ return B(y(r, t), G(o, "node", s, n), l, "node");
1234
1269
  }
1235
- }, je = {
1270
+ }, qe = {
1236
1271
  name: "findAndStyleEdges",
1237
1272
  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.",
1238
- parameters: c.object({
1239
- selector: c.string().describe(
1273
+ parameters: d.object({
1274
+ selector: d.string().describe(
1240
1275
  "Expression matching edges (empty string matches all). A record's own fields live under 'data.', so write 'data.weight > `0.5`'."
1241
1276
  ),
1242
- style: Te,
1243
- layerName: c.string().optional().describe("Name for this style layer (for later removal)")
1277
+ style: Ie,
1278
+ layerName: d.string().optional().describe("Name for this style layer (for later removal)")
1244
1279
  }),
1245
1280
  examples: [
1246
1281
  {
@@ -1260,73 +1295,73 @@ const Le = {
1260
1295
  params: { selector: "", style: { lineType: "dash" }, layerName: "dashed" }
1261
1296
  }
1262
1297
  ],
1263
- async execute(a, e) {
1298
+ async execute(r, e, t) {
1264
1299
  const {
1265
- selector: t,
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");
1300
+ selector: s,
1301
+ style: a,
1302
+ layerName: o = `ai-edge-style-${Date.now()}`
1303
+ } = e, { set: n, unsupported: l } = Le(a);
1304
+ return B(y(r, t), G(o, "edge", s, n), l, "edge");
1270
1305
  }
1271
- }, ze = {
1306
+ }, Ve = {
1272
1307
  name: "clearStyles",
1273
1308
  description: "Clear styles added by AI commands. Specify a layerName to clear a specific style, or leave empty to clear all AI-added styles.",
1274
- parameters: c.object({
1275
- layerName: c.string().optional().describe("Name of the style layer to clear (clears all if not specified)")
1309
+ parameters: d.object({
1310
+ layerName: d.string().optional().describe("Name of the style layer to clear (clears all if not specified)")
1276
1311
  }),
1277
1312
  examples: [
1278
1313
  { input: "Clear all styling", params: {} },
1279
1314
  { input: "Remove red node styling", params: { layerName: "red-nodes" } }
1280
1315
  ],
1281
- async execute(a, e) {
1282
- const { layerName: t } = e, { styles: s } = a.getSession();
1316
+ async execute(r, e, t) {
1317
+ const { layerName: s } = e, { styles: a } = y(r, t);
1283
1318
  try {
1284
- if (t === void 0) {
1285
- const o = await s.removeBySource(
1286
- (n) => n.by === "plugin" && n.name === "graphty-ai"
1319
+ if (s === void 0) {
1320
+ const n = await a.removeBySource(
1321
+ (l) => l.by === "plugin" && l.name === "graphty-ai"
1287
1322
  );
1288
1323
  return {
1289
1324
  success: !0,
1290
- message: `Cleared ${String(o.length)} AI-added style layer(s).`,
1291
- data: { clearedCount: o.length }
1325
+ message: `Cleared ${String(n.length)} AI-added style layer(s).`,
1326
+ data: { clearedCount: n.length }
1292
1327
  };
1293
1328
  }
1294
- const r = s.list().filter(
1295
- (o) => o.name === t && o.source.by === "plugin" && o.source.name === "graphty-ai"
1329
+ const o = a.list().filter(
1330
+ (n) => n.name === s && n.source.by === "plugin" && n.source.name === "graphty-ai"
1296
1331
  );
1297
- if (r.length === 0)
1332
+ if (o.length === 0)
1298
1333
  return {
1299
1334
  success: !0,
1300
- message: `Style layer "${t}" not found (may already be cleared).`
1335
+ message: `Style layer "${s}" not found (may already be cleared).`
1301
1336
  };
1302
- for (const o of r)
1303
- await s.remove(o.id);
1337
+ for (const n of o)
1338
+ await a.remove(n.id);
1304
1339
  return {
1305
1340
  success: !0,
1306
- message: `Cleared style layer "${t}".`,
1307
- data: { clearedCount: r.length }
1341
+ message: `Cleared style layer "${s}".`,
1342
+ data: { clearedCount: o.length }
1308
1343
  };
1309
- } catch (r) {
1344
+ } catch (o) {
1310
1345
  return {
1311
1346
  success: !1,
1312
- message: `Failed to clear styles: ${K(r)}`
1347
+ message: `Failed to clear styles: ${H(o)}`
1313
1348
  };
1314
1349
  }
1315
1350
  }
1316
1351
  };
1317
- function E() {
1352
+ function N() {
1318
1353
  return [
1319
- ...se.map((a) => a.id),
1320
- ...Q().map((a) => a.id)
1354
+ ...ne.map((r) => r.id),
1355
+ ...se().map((r) => r.id)
1321
1356
  ];
1322
1357
  }
1323
- const qe = c.string().describe(
1358
+ const Fe = d.string().describe(
1324
1359
  "Named camera view. The element ships 'fitToGraph', 'topView', 'sideView', 'frontView' and 'isometric'; an application may have registered others."
1325
- ), T = c.object({
1326
- x: c.number(),
1327
- y: c.number(),
1328
- z: c.number()
1329
- }).describe("3D position coordinates"), Ue = {
1360
+ ), k = d.object({
1361
+ x: d.number(),
1362
+ y: d.number(),
1363
+ z: d.number()
1364
+ }).describe("3D position coordinates"), Oe = {
1330
1365
  name: "setCameraPosition",
1331
1366
  /*
1332
1367
  * READ AT PROMPT TIME, NOT AT IMPORT TIME. The description is what the system prompt shows
@@ -1337,13 +1372,13 @@ const qe = c.string().describe(
1337
1372
  * registered.
1338
1373
  */
1339
1374
  get description() {
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.`;
1375
+ return `Set the camera position using a preset (${N().join(", ")}) or specific coordinates. Presets automatically calculate the best view for the current graph. Animation can be enabled for smooth transitions.`;
1341
1376
  },
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)")
1377
+ parameters: d.object({
1378
+ preset: Fe.optional().describe("Named camera preset to apply"),
1379
+ position: k.optional().describe("Custom camera position (3D only)"),
1380
+ target: k.optional().describe("Point the camera should look at (3D only)"),
1381
+ animate: d.boolean().optional().describe("Whether to animate the camera transition (default: true)")
1347
1382
  }),
1348
1383
  examples: [
1349
1384
  { input: "Show from top", params: { preset: "topView", animate: !0 } },
@@ -1356,11 +1391,11 @@ const qe = c.string().describe(
1356
1391
  params: { position: { x: 10, y: 20, z: 30 }, target: { x: 0, y: 0, z: 0 } }
1357
1392
  }
1358
1393
  ],
1359
- async execute(a, e) {
1394
+ async execute(r, e) {
1360
1395
  const {
1361
1396
  preset: t,
1362
1397
  position: s,
1363
- target: r,
1398
+ target: a,
1364
1399
  animate: o = !0
1365
1400
  } = e;
1366
1401
  try {
@@ -1370,23 +1405,23 @@ const qe = c.string().describe(
1370
1405
  message: "Either 'preset' or 'position' must be provided."
1371
1406
  };
1372
1407
  if (t)
1373
- return te(t) ? (await a.setCameraState({ preset: t }, { animate: o, description: `Setting camera to ${t} view` }), {
1408
+ return oe(t) ? (await r.setCameraState({ preset: t }, { animate: o, description: `Setting camera to ${t} view` }), {
1374
1409
  success: !0,
1375
1410
  message: `Camera moved to ${t} view${o ? " (animated)" : ""}.`,
1376
1411
  data: { preset: t, animated: o }
1377
1412
  }) : {
1378
1413
  success: !1,
1379
- message: `Unknown camera view "${t}". Available views: ${E().join(", ")}.`
1414
+ message: `Unknown camera view "${t}". Available views: ${N().join(", ")}.`
1380
1415
  };
1381
1416
  if (s) {
1382
1417
  const n = { position: s };
1383
- return r && (n.target = r), await a.setCameraState(n, {
1418
+ return a && (n.target = a), await r.setCameraState(n, {
1384
1419
  animate: o,
1385
1420
  description: "Moving camera to specified position"
1386
1421
  }), {
1387
1422
  success: !0,
1388
1423
  message: `Camera moved to position (${s.x}, ${s.y}, ${s.z})${o ? " (animated)" : ""}.`,
1389
- data: { position: s, target: r, animated: o }
1424
+ data: { position: s, target: a, animated: o }
1390
1425
  };
1391
1426
  }
1392
1427
  return {
@@ -1401,78 +1436,78 @@ const qe = c.string().describe(
1401
1436
  }
1402
1437
  }
1403
1438
  };
1404
- function Ve(a, e) {
1405
- const t = a.getDataManager(), { nodes: s } = t, r = [];
1439
+ function _e(r, e) {
1440
+ const t = r.getDataManager(), { nodes: s } = t, a = [];
1406
1441
  if (!e || e.length === 0) {
1407
1442
  for (const [o] of s)
1408
- r.push(String(o));
1409
- return r;
1443
+ a.push(String(o));
1444
+ return a;
1410
1445
  }
1411
1446
  try {
1412
1447
  const n = `[?${e.replace(/"/g, "'")}]`;
1413
1448
  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));
1449
+ const { data: c } = i, u = le.search([c], n);
1450
+ Array.isArray(u) && u.length > 0 && a.push(String(l));
1416
1451
  }
1417
1452
  } catch {
1418
1453
  return [];
1419
1454
  }
1420
- return r;
1455
+ return a;
1421
1456
  }
1422
- const Fe = {
1457
+ const Ke = {
1423
1458
  name: "zoomToNodes",
1424
1459
  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.",
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)")
1460
+ parameters: d.object({
1461
+ selector: d.string().optional().describe("JMESPath expression to match nodes (empty matches all)"),
1462
+ animate: d.boolean().optional().describe("Whether to animate the zoom (default: true)"),
1463
+ padding: d.number().optional().describe("Extra padding around nodes (default: 1.2 = 20% padding)")
1429
1464
  }),
1430
1465
  examples: [
1431
1466
  { input: "Zoom to fit all nodes", params: { selector: "" } },
1432
1467
  { input: "Zoom to server nodes", params: { selector: "type == 'server'" } },
1433
1468
  { input: "Fit graph with more padding", params: { selector: "", padding: 1.5 } }
1434
1469
  ],
1435
- async execute(a, e) {
1470
+ async execute(r, e) {
1436
1471
  const { selector: t = "", animate: s = !0 } = e;
1437
1472
  try {
1438
- const r = Ve(a, t);
1439
- if (r.length === 0 && t && t.length > 0)
1473
+ const a = _e(r, t);
1474
+ if (a.length === 0 && t && t.length > 0)
1440
1475
  return {
1441
1476
  success: !0,
1442
1477
  message: `No nodes matched the selector "${t}".`,
1443
1478
  affectedNodes: []
1444
1479
  };
1445
- await a.applyCameraView("fitToGraph", {
1446
- ...t && t.length > 0 ? { scope: { nodes: r } } : {},
1480
+ await r.applyCameraView("fitToGraph", {
1481
+ ...t && t.length > 0 ? { scope: { nodes: a } } : {},
1447
1482
  animate: s,
1448
1483
  description: `Zooming to fit ${t ? "matching nodes" : "all nodes"}`
1449
1484
  });
1450
- const o = t ? r.length : a.getNodeCount();
1485
+ const o = t ? a.length : r.getNodeCount();
1451
1486
  return {
1452
1487
  success: !0,
1453
1488
  message: `Zoomed to fit ${o} node(s)${t ? ` matching "${t}"` : ""}.`,
1454
- affectedNodes: r,
1489
+ affectedNodes: a,
1455
1490
  data: { nodeCount: o, animated: s }
1456
1491
  };
1457
- } catch (r) {
1492
+ } catch (a) {
1458
1493
  return {
1459
1494
  success: !1,
1460
- message: `Failed to zoom to nodes: ${r.message}`
1495
+ message: `Failed to zoom to nodes: ${a.message}`
1461
1496
  };
1462
1497
  }
1463
1498
  }
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(
1499
+ }, I = d.object({
1500
+ namespace: d.string().describe("The namespace of the algorithm (e.g., 'graphty')"),
1501
+ type: d.string().describe("The type of algorithm to run (e.g., 'degree', 'pagerank')"),
1502
+ options: d.record(d.string(), d.unknown()).optional().describe(
1468
1503
  "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
1504
  )
1470
- }), k = 50, I = c.object({
1471
- namespace: c.string().optional().describe("Optional namespace to filter algorithms by")
1472
- }), Oe = {
1505
+ }), R = 50, D = d.object({
1506
+ namespace: d.string().optional().describe("Optional namespace to filter algorithms by")
1507
+ }), We = {
1473
1508
  name: "runAlgorithm",
1474
1509
  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,
1510
+ parameters: I,
1476
1511
  examples: [
1477
1512
  {
1478
1513
  input: "Calculate the degree of each node",
@@ -1491,63 +1526,72 @@ const Fe = {
1491
1526
  params: { namespace: "graphty", type: "dijkstra", options: { source: "A", target: "B" } }
1492
1527
  }
1493
1528
  ],
1494
- async execute(a, e) {
1495
- const t = N.safeParse(e);
1496
- if (!t.success)
1529
+ async execute(r, e, t) {
1530
+ const s = I.safeParse(e);
1531
+ if (!s.success)
1497
1532
  return {
1498
1533
  success: !1,
1499
- message: `Invalid parameters: ${t.error.message}`
1534
+ message: `Invalid parameters: ${s.error.message}`
1500
1535
  };
1501
- const { namespace: s, type: r, options: o } = t.data;
1536
+ const { namespace: a, type: o, options: n } = s.data;
1502
1537
  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.`;
1538
+ if (!M.get(r, a, o)) {
1539
+ const h = M.getRegisteredAlgorithms(a), g = h.length > 0 ? `Available in namespace '${a}': ${h.map((v) => v.split(":")[1]).join(", ")}` : `No algorithms found in namespace '${a}'. Use listAlgorithms to see available options.`;
1505
1540
  return {
1506
1541
  success: !1,
1507
- message: `Algorithm not found: ${s}:${r}. ${h}`
1542
+ message: `Algorithm not found: ${a}:${o}. ${g}`
1508
1543
  };
1509
1544
  }
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 }), {
1545
+ const i = (a === "graphty" ? ie(o) : void 0) ?? E(`${a}:${o}`) ?? E(o);
1546
+ if (i === void 0)
1547
+ return await y(r, t).execute({
1548
+ op: "algo.legacy",
1549
+ namespace: a,
1550
+ type: o,
1551
+ ...n === void 0 ? {} : { options: n }
1552
+ }), {
1513
1553
  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() }
1554
+ message: `Successfully ran ${a}:${o} algorithm. Results are now available in node data.`,
1555
+ data: { namespace: a, type: o, nodeCount: r.getNodeCount() }
1516
1556
  };
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,
1557
+ const c = "params" in i ? i.params : {}, u = await y(r, t).run({
1558
+ op: "algo.run",
1559
+ algorithm: i.descriptor.key,
1560
+ params: { ...c, ...n }
1561
+ }), p = {
1562
+ namespace: a,
1563
+ type: o,
1564
+ algorithm: i.descriptor.key,
1521
1565
  shape: u.shape,
1522
1566
  summary: u.summary(),
1523
1567
  graph: u.graph
1524
1568
  };
1525
- let p;
1569
+ let m;
1526
1570
  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
1571
+ const h = u.ranking("order").map((g) => String(g.id)).reverse();
1572
+ m = h.slice(0, R), p.path = {
1573
+ nodeIds: m,
1574
+ total: h.length,
1575
+ truncated: h.length > R
1532
1576
  };
1533
1577
  }
1534
1578
  return {
1535
1579
  success: !0,
1536
- message: `Successfully ran ${s}:${r} algorithm. ${u.reading()}`,
1537
- data: d,
1538
- ...p === void 0 ? {} : { affectedNodes: p }
1580
+ message: `Successfully ran ${a}:${o} algorithm. ${u.reading()}`,
1581
+ data: p,
1582
+ ...m === void 0 ? {} : { affectedNodes: m }
1539
1583
  };
1540
- } catch (n) {
1584
+ } catch (l) {
1541
1585
  return {
1542
1586
  success: !1,
1543
- message: `Failed to run algorithm ${s}:${r}: ${n instanceof Error ? n.message : String(n)}`
1587
+ message: `Failed to run algorithm ${a}:${o}: ${l instanceof Error ? l.message : String(l)}`
1544
1588
  };
1545
1589
  }
1546
1590
  }
1547
- }, _e = {
1591
+ }, Ge = {
1548
1592
  name: "listAlgorithms",
1549
1593
  description: "List all available graph algorithms that can be run on the graph. Optionally filter by namespace.",
1550
- parameters: I,
1594
+ parameters: D,
1551
1595
  examples: [
1552
1596
  {
1553
1597
  input: "What algorithms are available?",
@@ -1563,8 +1607,8 @@ const Fe = {
1563
1607
  }
1564
1608
  ],
1565
1609
  // eslint-disable-next-line @typescript-eslint/require-await
1566
- async execute(a, e) {
1567
- const t = I.safeParse(e);
1610
+ async execute(r, e) {
1611
+ const t = D.safeParse(e);
1568
1612
  if (!t.success)
1569
1613
  return {
1570
1614
  success: !1,
@@ -1572,8 +1616,8 @@ const Fe = {
1572
1616
  };
1573
1617
  const { namespace: s } = t.data;
1574
1618
  try {
1575
- const r = x.getRegisteredAlgorithms(s);
1576
- return r.length === 0 ? {
1619
+ const a = M.getRegisteredAlgorithms(s);
1620
+ return a.length === 0 ? {
1577
1621
  success: !0,
1578
1622
  message: s ? `No algorithms found in namespace '${s}'.` : "No algorithms are currently registered.",
1579
1623
  data: {
@@ -1582,180 +1626,180 @@ const Fe = {
1582
1626
  }
1583
1627
  } : {
1584
1628
  success: !0,
1585
- message: s ? `Found ${r.length} algorithm(s) in namespace '${s}': ${r.join(", ")}` : `Found ${r.length} available algorithm(s): ${r.join(", ")}`,
1629
+ message: s ? `Found ${a.length} algorithm(s) in namespace '${s}': ${a.join(", ")}` : `Found ${a.length} available algorithm(s): ${a.join(", ")}`,
1586
1630
  data: {
1587
- algorithms: r,
1588
- count: r.length
1631
+ algorithms: a,
1632
+ count: a.length
1589
1633
  }
1590
1634
  };
1591
- } catch (r) {
1635
+ } catch (a) {
1592
1636
  return {
1593
1637
  success: !1,
1594
- message: `Failed to list algorithms: ${r instanceof Error ? r.message : String(r)}`
1638
+ message: `Failed to list algorithms: ${a instanceof Error ? a.message : String(a)}`
1595
1639
  };
1596
1640
  }
1597
1641
  }
1598
1642
  };
1599
- function Ke(a, e = 100) {
1600
- return a.length <= e ? a : `${a.slice(0, e)}...`;
1643
+ function He(r, e = 100) {
1644
+ return r.length <= e ? r : `${r.slice(0, e)}...`;
1601
1645
  }
1602
- function M(a, e) {
1603
- if (a == null)
1646
+ function P(r, e) {
1647
+ if (r == null)
1604
1648
  return;
1605
1649
  const t = e.split(".");
1606
- let s = a;
1607
- for (const r of t) {
1650
+ let s = r;
1651
+ for (const a of t) {
1608
1652
  if (s == null || typeof s != "object")
1609
1653
  return;
1610
- s = s[r];
1654
+ s = s[a];
1611
1655
  }
1612
1656
  return s;
1613
1657
  }
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") {
1658
+ function $(r, e = 100) {
1659
+ if (r == null)
1660
+ return r;
1661
+ if (typeof r == "string")
1662
+ return He(r, e);
1663
+ if (Array.isArray(r))
1664
+ return r.map((t) => $(t, e));
1665
+ if (typeof r == "object") {
1622
1666
  const t = {};
1623
- for (const [s, r] of Object.entries(a))
1624
- t[s] = C(r, e);
1667
+ for (const [s, a] of Object.entries(r))
1668
+ t[s] = $(a, e);
1625
1669
  return t;
1626
1670
  }
1627
- return a;
1671
+ return r;
1628
1672
  }
1629
- function G(a) {
1630
- if (a.length === 0)
1673
+ function X(r) {
1674
+ if (r.length === 0)
1631
1675
  return { min: 0, max: 0, avg: 0, median: 0, count: 0 };
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 };
1676
+ const e = [...r].sort((i, c) => i - c), t = r.reduce((i, c) => i + c, 0), s = e[0], a = e[e.length - 1], o = t / r.length, n = Math.floor(e.length / 2), l = e.length % 2 === 0 ? (e[n - 1] + e[n]) / 2 : e[n];
1677
+ return { min: s, max: a, avg: o, median: l, count: r.length };
1634
1678
  }
1635
- function We(a, e = 5) {
1636
- if (a.length === 0)
1679
+ function Be(r, e = 5) {
1680
+ if (r.length === 0)
1637
1681
  return [];
1638
- const t = Math.min(...a), s = Math.max(...a);
1682
+ const t = Math.min(...r), s = Math.max(...r);
1639
1683
  if (t === s)
1640
1684
  return [
1641
1685
  {
1642
- range: R(t, s),
1643
- count: a.length,
1686
+ range: L(t, s),
1687
+ count: r.length,
1644
1688
  min: t,
1645
1689
  max: s
1646
1690
  }
1647
1691
  ];
1648
- const r = (s - t) / e, o = [];
1692
+ const a = (s - t) / e, o = [];
1649
1693
  for (let n = 0; n < e; n++) {
1650
- const l = t + n * r, i = n === e - 1 ? s : t + (n + 1) * r;
1694
+ const l = t + n * a, i = n === e - 1 ? s : t + (n + 1) * a;
1651
1695
  o.push({
1652
- range: R(l, i),
1696
+ range: L(l, i),
1653
1697
  count: 0,
1654
1698
  min: l,
1655
1699
  max: i
1656
1700
  });
1657
1701
  }
1658
- for (const n of a) {
1659
- let l = Math.floor((n - t) / r);
1702
+ for (const n of r) {
1703
+ let l = Math.floor((n - t) / a);
1660
1704
  l >= e && (l = e - 1), o[l].count++;
1661
1705
  }
1662
1706
  return o;
1663
1707
  }
1664
- function R(a, e) {
1708
+ function L(r, e) {
1665
1709
  const t = (s) => Number.isInteger(s) ? s.toString() : s.toFixed(2);
1666
- return `${t(a)} - ${t(e)}`;
1710
+ return `${t(r)} - ${t(e)}`;
1667
1711
  }
1668
- function Ge(a) {
1669
- if (a == null)
1712
+ function Xe(r) {
1713
+ if (r == null)
1670
1714
  return "null";
1671
- if (Array.isArray(a))
1715
+ if (Array.isArray(r))
1672
1716
  return "array";
1673
- const e = typeof a;
1717
+ const e = typeof r;
1674
1718
  return e === "string" || e === "number" || e === "boolean" ? e : e === "object" ? "object" : "null";
1675
1719
  }
1676
- function He(a, e) {
1720
+ function Ye(r, e) {
1677
1721
  const t = [];
1678
1722
  let s = 0;
1679
- for (const r of a) {
1680
- const o = M(r.data, e);
1723
+ for (const a of r) {
1724
+ const o = P(a.data, e);
1681
1725
  o == null ? s++ : t.push(o);
1682
1726
  }
1683
1727
  return { values: t, nullCount: s };
1684
1728
  }
1685
- function H(a) {
1686
- if (a.length === 0)
1729
+ function Y(r) {
1730
+ if (r.length === 0)
1687
1731
  return "null";
1688
1732
  const e = /* @__PURE__ */ new Map();
1689
- for (const t of a) {
1690
- const s = Ge(t);
1733
+ for (const t of r) {
1734
+ const s = Xe(t);
1691
1735
  e.set(s, (e.get(s) ?? 0) + 1);
1692
1736
  }
1693
1737
  return e.delete("null"), e.size === 0 ? "null" : e.size > 1 ? "mixed" : e.keys().next().value;
1694
1738
  }
1695
- function Be(a, e = 3) {
1739
+ function Ze(r, e = 3) {
1696
1740
  const t = /* @__PURE__ */ new Set();
1697
- for (const s of a)
1698
- B(s.data, "", t, 0, e);
1741
+ for (const s of r)
1742
+ Z(s.data, "", t, 0, e);
1699
1743
  return Array.from(t).sort();
1700
1744
  }
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)) {
1745
+ function Z(r, e, t, s, a) {
1746
+ if (!(s >= a || r === null || r === void 0 || typeof r != "object" || Array.isArray(r)))
1747
+ for (const o of Object.keys(r)) {
1704
1748
  const n = e ? `${e}.${o}` : o;
1705
1749
  t.add(n);
1706
- const l = a[o];
1707
- l !== null && typeof l == "object" && !Array.isArray(l) && B(l, n, t, s + 1, r);
1750
+ const l = r[o];
1751
+ l !== null && typeof l == "object" && !Array.isArray(l) && Z(l, n, t, s + 1, a);
1708
1752
  }
1709
1753
  }
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];
1754
+ const Je = d.enum(["nodes", "edges", "both"]).optional().describe("What to sample: 'nodes', 'edges', or 'both' (default)"), j = 3, z = 10, U = 100;
1755
+ function b(r, e) {
1756
+ if (r.length <= e)
1757
+ return [...r];
1758
+ const t = [...r];
1715
1759
  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]];
1760
+ const a = s + Math.floor(Math.random() * (t.length - s));
1761
+ [t[s], t[a]] = [t[a], t[s]];
1718
1762
  }
1719
1763
  return t.slice(0, e);
1720
1764
  }
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) {
1726
- const u = t(i);
1727
- if (u === void 0)
1728
- r.push(i);
1765
+ function q(r, e, t) {
1766
+ if (r.length <= e)
1767
+ return [...r];
1768
+ const s = /* @__PURE__ */ new Map(), a = [];
1769
+ for (const i of r) {
1770
+ const c = t(i);
1771
+ if (c === void 0)
1772
+ a.push(i);
1729
1773
  else {
1730
- const d = s.get(u) ?? [];
1731
- d.push(i), s.set(u, d);
1774
+ const u = s.get(c) ?? [];
1775
+ u.push(i), s.set(c, u);
1732
1776
  }
1733
1777
  }
1734
- const o = s.size + (r.length > 0 ? 1 : 0);
1778
+ const o = s.size + (a.length > 0 ? 1 : 0);
1735
1779
  if (o === 0)
1736
- return y(a, e);
1780
+ return b(r, e);
1737
1781
  const n = Math.max(1, Math.floor(e / o)), l = [];
1738
1782
  for (const i of s.values()) {
1739
- const u = y(i, n);
1740
- l.push(...u);
1783
+ const c = b(i, n);
1784
+ l.push(...c);
1741
1785
  }
1742
- if (r.length > 0) {
1743
- const i = y(r, n);
1786
+ if (a.length > 0) {
1787
+ const i = b(a, n);
1744
1788
  l.push(...i);
1745
1789
  }
1746
1790
  if (l.length < e) {
1747
- const i = a.filter((d) => !l.includes(d)), u = y(i, e - l.length);
1748
- l.push(...u);
1791
+ const i = r.filter((u) => !l.includes(u)), c = b(i, e - l.length);
1792
+ l.push(...c);
1749
1793
  }
1750
1794
  return l.slice(0, e);
1751
1795
  }
1752
- const Ze = {
1796
+ const Qe = {
1753
1797
  name: "sampleData",
1754
1798
  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.",
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)")
1799
+ parameters: d.object({
1800
+ target: Je,
1801
+ count: d.number().min(1).max(z).optional().describe(`Number of samples to return per type (1-${z}, default ${j})`),
1802
+ stratifyBy: d.string().optional().describe("Property path to stratify sampling by (e.g., 'data.type' to sample from each type)")
1759
1803
  }),
1760
1804
  examples: [
1761
1805
  { input: "Show me some example nodes", params: { target: "nodes" } },
@@ -1766,36 +1810,36 @@ const Ze = {
1766
1810
  params: { target: "nodes", count: 6, stratifyBy: "data.type" }
1767
1811
  }
1768
1812
  ],
1769
- execute(a, e) {
1813
+ execute(r, e) {
1770
1814
  const {
1771
1815
  target: t = "both",
1772
- count: s = D,
1773
- stratifyBy: r
1816
+ count: s = j,
1817
+ stratifyBy: a
1774
1818
  } = e;
1775
1819
  try {
1776
- const o = a.getDataManager(), n = {};
1820
+ const o = r.getDataManager(), n = {};
1777
1821
  if (t === "nodes" || t === "both") {
1778
1822
  const i = Array.from(o.nodes.values());
1779
- let u;
1780
- r ? u = z(i, s, (d) => {
1781
- const p = M(d.data, r);
1823
+ let c;
1824
+ a ? c = q(i, s, (u) => {
1825
+ const p = P(u.data, a);
1782
1826
  return typeof p == "string" ? p : void 0;
1783
- }) : u = y(i, s), n.nodes = u.map((d) => ({
1784
- id: String(d.id),
1785
- data: C(d.data, j)
1827
+ }) : c = b(i, s), n.nodes = c.map((u) => ({
1828
+ id: String(u.id),
1829
+ data: $(u.data, U)
1786
1830
  }));
1787
1831
  }
1788
1832
  if (t === "edges" || t === "both") {
1789
1833
  const i = Array.from(o.edges.values());
1790
- let u;
1791
- r ? u = z(i, s, (d) => {
1792
- const p = M(d.data, r);
1834
+ let c;
1835
+ a ? c = q(i, s, (u) => {
1836
+ const p = P(u.data, a);
1793
1837
  return typeof p == "string" ? p : void 0;
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)
1838
+ }) : c = b(i, s), n.edges = c.map((u) => ({
1839
+ id: u.id,
1840
+ source: String(u.srcId),
1841
+ target: String(u.dstId),
1842
+ data: $(u.data, U)
1799
1843
  }));
1800
1844
  }
1801
1845
  const l = [];
@@ -1811,35 +1855,35 @@ const Ze = {
1811
1855
  });
1812
1856
  }
1813
1857
  }
1814
- }, q = 20, U = 50, Ye = 5;
1815
- function Je(a, e, t, s, r) {
1858
+ }, V = 20, F = 50, et = 5;
1859
+ function tt(r, e, t, s, a) {
1816
1860
  const o = t.filter((p) => typeof p == "string"), n = /* @__PURE__ */ new Map();
1817
1861
  for (const p of o)
1818
1862
  n.set(p, (n.get(p) ?? 0) + 1);
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] = {
1863
+ const l = Array.from(n.entries()).sort((p, m) => m[1] - p[1]), i = l.length > a, c = l.slice(0, a), u = {};
1864
+ for (const [p, m] of c)
1865
+ u[p] = {
1822
1866
  count: m,
1823
1867
  percentage: m / o.length * 100
1824
1868
  };
1825
1869
  return {
1826
- property: a,
1870
+ property: r,
1827
1871
  target: e,
1828
1872
  type: "string",
1829
1873
  totalCount: o.length + s,
1830
1874
  nullCount: s,
1831
1875
  uniqueCount: n.size,
1832
- distribution: d,
1876
+ distribution: u,
1833
1877
  truncated: i
1834
1878
  };
1835
1879
  }
1836
- function Qe(a, e, t, s) {
1837
- const r = t.filter((l) => typeof l == "number"), o = G(r), n = We(r, Ye);
1880
+ function st(r, e, t, s) {
1881
+ const a = t.filter((l) => typeof l == "number"), o = X(a), n = Be(a, et);
1838
1882
  return {
1839
- property: a,
1883
+ property: r,
1840
1884
  target: e,
1841
1885
  type: "number",
1842
- totalCount: r.length + s,
1886
+ totalCount: a.length + s,
1843
1887
  nullCount: s,
1844
1888
  statistics: {
1845
1889
  min: o.min,
@@ -1853,43 +1897,43 @@ function Qe(a, e, t, s) {
1853
1897
  }))
1854
1898
  };
1855
1899
  }
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;
1900
+ function rt(r, e, t, s) {
1901
+ const a = t.filter((l) => typeof l == "boolean"), o = a.filter((l) => l).length, n = a.length - o;
1858
1902
  return {
1859
- property: a,
1903
+ property: r,
1860
1904
  target: e,
1861
1905
  type: "boolean",
1862
- totalCount: r.length + s,
1906
+ totalCount: a.length + s,
1863
1907
  nullCount: s,
1864
1908
  distribution: {
1865
1909
  true: {
1866
1910
  count: o,
1867
- percentage: r.length > 0 ? o / r.length * 100 : 0
1911
+ percentage: a.length > 0 ? o / a.length * 100 : 0
1868
1912
  },
1869
1913
  false: {
1870
1914
  count: n,
1871
- percentage: r.length > 0 ? n / r.length * 100 : 0
1915
+ percentage: a.length > 0 ? n / a.length * 100 : 0
1872
1916
  }
1873
1917
  }
1874
1918
  };
1875
1919
  }
1876
- function tt(a, e, t, s, r) {
1920
+ function at(r, e, t, s, a) {
1877
1921
  const o = t.filter((h) => Array.isArray(h)), n = [], l = [];
1878
1922
  for (const h of o)
1879
1923
  l.push(h.length), n.push(...h);
1880
- const i = H(n), u = /* @__PURE__ */ new Set();
1924
+ const i = Y(n), c = /* @__PURE__ */ new Set();
1881
1925
  for (const h of n)
1882
- typeof h == "string" ? u.add(h) : typeof h == "number" || typeof h == "boolean" ? u.add(String(h)) : h != null && u.add(JSON.stringify(h));
1883
- const d = Array.from(u), p = d.length > r, m = G(l);
1926
+ typeof h == "string" ? c.add(h) : typeof h == "number" || typeof h == "boolean" ? c.add(String(h)) : h != null && c.add(JSON.stringify(h));
1927
+ const u = Array.from(c), p = u.length > a, m = X(l);
1884
1928
  return {
1885
- property: a,
1929
+ property: r,
1886
1930
  target: e,
1887
1931
  type: "array",
1888
1932
  totalCount: o.length + s,
1889
1933
  nullCount: s,
1890
1934
  itemType: i,
1891
- uniqueItems: d.slice(0, r),
1892
- uniqueItemCount: d.length,
1935
+ uniqueItems: u.slice(0, a),
1936
+ uniqueItemCount: u.length,
1893
1937
  lengthStatistics: {
1894
1938
  min: m.min,
1895
1939
  max: m.max,
@@ -1898,28 +1942,28 @@ function tt(a, e, t, s, r) {
1898
1942
  truncated: p
1899
1943
  };
1900
1944
  }
1901
- function st(a, e, t, s) {
1902
- const r = {};
1945
+ function ot(r, e, t, s) {
1946
+ const a = {};
1903
1947
  for (const o of t) {
1904
1948
  const n = typeof 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);
1949
+ Array.isArray(o) ? a.array = (a.array || 0) + 1 : n === "object" && o !== null ? a.object = (a.object || 0) + 1 : (n === "string" || n === "number" || n === "boolean") && (a[n] = (a[n] || 0) + 1);
1906
1950
  }
1907
1951
  return {
1908
- property: a,
1952
+ property: r,
1909
1953
  target: e,
1910
1954
  type: "mixed",
1911
1955
  totalCount: t.length + s,
1912
1956
  nullCount: s,
1913
- typeCounts: r
1957
+ typeCounts: a
1914
1958
  };
1915
1959
  }
1916
- const rt = {
1960
+ const nt = {
1917
1961
  name: "describeProperty",
1918
1962
  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.",
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})`)
1963
+ parameters: d.object({
1964
+ property: d.string().describe("Property path to analyze (e.g., 'type', 'data.category', 'weight')"),
1965
+ target: d.enum(["nodes", "edges"]).optional().describe("Whether to analyze node or edge properties (default: 'nodes')"),
1966
+ limit: d.number().min(1).max(F).optional().describe(`Maximum number of unique values to show (1-${F}, default ${V})`)
1923
1967
  }),
1924
1968
  examples: [
1925
1969
  { input: "Describe the type property on nodes", params: { property: "type", target: "nodes" } },
@@ -1930,22 +1974,22 @@ const rt = {
1930
1974
  { input: "Show me the distribution of data.category", params: { property: "data.category" } },
1931
1975
  { input: "Analyze the tags property", params: { property: "tags", limit: 10 } }
1932
1976
  ],
1933
- execute(a, e) {
1977
+ execute(r, e) {
1934
1978
  const {
1935
1979
  property: t,
1936
1980
  target: s = "nodes",
1937
- limit: r = q
1981
+ limit: a = V
1938
1982
  } = e;
1939
1983
  try {
1940
- const o = a.getDataManager(), n = Array.from(s === "nodes" ? o.nodes.values() : o.edges.values());
1984
+ const o = r.getDataManager(), n = Array.from(s === "nodes" ? o.nodes.values() : o.edges.values());
1941
1985
  if (n.length === 0)
1942
1986
  return Promise.resolve({
1943
1987
  success: !1,
1944
1988
  message: `No ${s} found in the graph.`
1945
1989
  });
1946
- const { values: l, nullCount: i } = He(n, t);
1990
+ const { values: l, nullCount: i } = Ye(n, t);
1947
1991
  if (l.length === 0 && i === n.length) {
1948
- const m = Be(n);
1992
+ const m = Ze(n);
1949
1993
  return Promise.resolve({
1950
1994
  success: !1,
1951
1995
  message: `Property "${t}" not found on ${s}. Available properties: ${m.slice(0, 10).join(", ")}${m.length > 10 ? "..." : ""}`,
@@ -1954,23 +1998,23 @@ const rt = {
1954
1998
  }
1955
1999
  });
1956
2000
  }
1957
- const u = H(l);
1958
- let d;
1959
- switch (u) {
2001
+ const c = Y(l);
2002
+ let u;
2003
+ switch (c) {
1960
2004
  case "string":
1961
- d = Je(t, s, l, i, r);
2005
+ u = tt(t, s, l, i, a);
1962
2006
  break;
1963
2007
  case "number":
1964
- d = Qe(t, s, l, i);
2008
+ u = st(t, s, l, i);
1965
2009
  break;
1966
2010
  case "boolean":
1967
- d = et(t, s, l, i);
2011
+ u = rt(t, s, l, i);
1968
2012
  break;
1969
2013
  case "array":
1970
- d = tt(t, s, l, i, r);
2014
+ u = at(t, s, l, i, a);
1971
2015
  break;
1972
2016
  case "mixed":
1973
- d = st(t, s, l, i);
2017
+ u = ot(t, s, l, i);
1974
2018
  break;
1975
2019
  default:
1976
2020
  return Promise.resolve({
@@ -1979,29 +2023,29 @@ const rt = {
1979
2023
  });
1980
2024
  }
1981
2025
  let p;
1982
- switch (u) {
2026
+ switch (c) {
1983
2027
  case "string": {
1984
- const m = d;
2028
+ const m = u;
1985
2029
  p = `Property "${t}" is a string with ${m.uniqueCount} unique value${m.uniqueCount !== 1 ? "s" : ""}.`;
1986
2030
  break;
1987
2031
  }
1988
2032
  case "number": {
1989
- const m = d;
2033
+ const m = u;
1990
2034
  p = `Property "${t}" is a number (min: ${m.statistics.min.toFixed(2)}, max: ${m.statistics.max.toFixed(2)}, avg: ${m.statistics.avg.toFixed(2)}).`;
1991
2035
  break;
1992
2036
  }
1993
2037
  case "boolean": {
1994
- const m = d;
2038
+ const m = u;
1995
2039
  p = `Property "${t}" is a boolean (true: ${m.distribution.true.percentage.toFixed(1)}%, false: ${m.distribution.false.percentage.toFixed(1)}%).`;
1996
2040
  break;
1997
2041
  }
1998
2042
  case "array": {
1999
- const m = d;
2043
+ const m = u;
2000
2044
  p = `Property "${t}" is an array of ${m.itemType} values with ${m.uniqueItemCount} unique item${m.uniqueItemCount !== 1 ? "s" : ""}.`;
2001
2045
  break;
2002
2046
  }
2003
2047
  case "mixed": {
2004
- const h = Object.keys(d.typeCounts).join(", ");
2048
+ const h = Object.keys(u.typeCounts).join(", ");
2005
2049
  p = `Property "${t}" has mixed types: ${h}.`;
2006
2050
  break;
2007
2051
  }
@@ -2011,7 +2055,7 @@ const rt = {
2011
2055
  return Promise.resolve({
2012
2056
  success: !0,
2013
2057
  message: p,
2014
- data: d
2058
+ data: u
2015
2059
  });
2016
2060
  } catch (o) {
2017
2061
  return Promise.resolve({
@@ -2021,7 +2065,7 @@ const rt = {
2021
2065
  }
2022
2066
  }
2023
2067
  };
2024
- class at {
2068
+ class it {
2025
2069
  constructor() {
2026
2070
  this.name = "mock", this.supportsStreaming = !0, this.supportsTools = !0, this.responses = /* @__PURE__ */ new Map(), this.defaultResponse = {
2027
2071
  text: "This is a mock response.",
@@ -2088,12 +2132,12 @@ class at {
2088
2132
  * @returns Matching response or default response
2089
2133
  */
2090
2134
  findResponse(e) {
2091
- const t = [...e].reverse().find((r) => r.role === "user");
2135
+ const t = [...e].reverse().find((a) => a.role === "user");
2092
2136
  if (!t)
2093
2137
  return this.defaultResponse;
2094
2138
  const s = t.content.toLowerCase();
2095
- for (const [r, o] of this.responses)
2096
- if (s.includes(r))
2139
+ for (const [a, o] of this.responses)
2140
+ if (s.includes(a))
2097
2141
  return o;
2098
2142
  return this.defaultResponse;
2099
2143
  }
@@ -2115,7 +2159,7 @@ class at {
2115
2159
  throw new Error("Request was aborted");
2116
2160
  if (this.configuredError)
2117
2161
  throw this.configuredError;
2118
- if (this.delay > 0 && await new Promise((r) => setTimeout(r, this.delay)), s?.signal?.aborted)
2162
+ if (this.delay > 0 && await new Promise((a) => setTimeout(a, this.delay)), s?.signal?.aborted)
2119
2163
  throw new Error("Request was aborted");
2120
2164
  return this.findResponse(e);
2121
2165
  }
@@ -2127,24 +2171,24 @@ class at {
2127
2171
  * @param callbacks - Streaming callbacks for text and tool calls
2128
2172
  * @param signal - Optional abort signal
2129
2173
  */
2130
- async generateStream(e, t, s, r) {
2174
+ async generateStream(e, t, s, a) {
2131
2175
  if (this.callHistory.push({
2132
2176
  messages: e,
2133
2177
  tools: t,
2134
2178
  streaming: !0,
2135
2179
  timestamp: Date.now()
2136
- }), r?.aborted)
2180
+ }), a?.aborted)
2137
2181
  throw new Error("Request was aborted");
2138
2182
  if (this.configuredError)
2139
2183
  throw s.onError(this.configuredError), this.configuredError;
2140
2184
  const o = this.findResponse(e), { text: n } = o;
2141
2185
  for (const l of n) {
2142
- if (r?.aborted)
2186
+ if (a?.aborted)
2143
2187
  throw new Error("Request was aborted");
2144
2188
  s.onChunk(l), this.delay > 0 && await new Promise((i) => setTimeout(i, this.delay / n.length));
2145
2189
  }
2146
2190
  for (const l of o.toolCalls) {
2147
- if (r?.aborted)
2191
+ if (a?.aborted)
2148
2192
  throw new Error("Request was aborted");
2149
2193
  s.onToolCall(l.name, l.arguments);
2150
2194
  }
@@ -2163,7 +2207,7 @@ class at {
2163
2207
  return Promise.resolve(!0);
2164
2208
  }
2165
2209
  }
2166
- class ot {
2210
+ class lt {
2167
2211
  /**
2168
2212
  * Creates a new VercelAiProvider instance.
2169
2213
  * @param providerType - Type of provider (openai, anthropic, or google)
@@ -2187,9 +2231,9 @@ class ot {
2187
2231
  throw new Error(`API key not configured for ${this.name}`);
2188
2232
  switch (this.providerType) {
2189
2233
  case "openai":
2190
- return le({ apiKey: this.apiKey, baseURL: this.baseUrl })(this.model ?? "gpt-4o");
2234
+ return de({ apiKey: this.apiKey, baseURL: this.baseUrl })(this.model ?? "gpt-4o");
2191
2235
  case "anthropic":
2192
- return ne({
2236
+ return ce({
2193
2237
  apiKey: this.apiKey,
2194
2238
  baseURL: this.baseUrl,
2195
2239
  // Enable browser support - Anthropic requires this header for CORS
@@ -2198,7 +2242,7 @@ class ot {
2198
2242
  }
2199
2243
  })(this.model ?? "claude-3-haiku-20240307");
2200
2244
  default:
2201
- return ie({ apiKey: this.apiKey, baseURL: this.baseUrl })(this.model ?? "gemini-2.0-flash");
2245
+ return ue({ apiKey: this.apiKey, baseURL: this.baseUrl })(this.model ?? "gemini-2.0-flash");
2202
2246
  }
2203
2247
  }
2204
2248
  /**
@@ -2210,8 +2254,8 @@ class ot {
2210
2254
  * @returns Promise resolving to LLM response
2211
2255
  */
2212
2256
  async generate(e, t, s) {
2213
- const r = this.getModel(), o = this.convertMessages(e), n = this.convertTools(t), l = await ce({
2214
- model: r,
2257
+ const a = this.getModel(), o = this.convertMessages(e), n = this.convertTools(t), l = await me({
2258
+ model: a,
2215
2259
  messages: o,
2216
2260
  tools: n,
2217
2261
  maxOutputTokens: this.maxTokens,
@@ -2231,22 +2275,22 @@ class ot {
2231
2275
  * @param callbacks - Streaming callbacks for text and tool calls
2232
2276
  * @param signal - Optional abort signal
2233
2277
  */
2234
- async generateStream(e, t, s, r) {
2235
- const o = this.getModel(), n = this.convertMessages(e), l = this.convertTools(t), i = ue({
2278
+ async generateStream(e, t, s, a) {
2279
+ const o = this.getModel(), n = this.convertMessages(e), l = this.convertTools(t), i = pe({
2236
2280
  model: o,
2237
2281
  messages: n,
2238
2282
  tools: l,
2239
2283
  maxOutputTokens: this.maxTokens,
2240
2284
  temperature: this.temperature,
2241
- abortSignal: r
2285
+ abortSignal: a
2242
2286
  });
2243
- let u = "";
2244
- const d = [];
2287
+ let c = "";
2288
+ const u = [];
2245
2289
  try {
2246
2290
  for await (const m of i.fullStream)
2247
2291
  switch (m.type) {
2248
2292
  case "text-delta":
2249
- u += m.text, s.onChunk(m.text);
2293
+ c += m.text, s.onChunk(m.text);
2250
2294
  break;
2251
2295
  case "tool-call": {
2252
2296
  let h = {};
@@ -2256,7 +2300,7 @@ class ot {
2256
2300
  name: m.toolName,
2257
2301
  arguments: h
2258
2302
  };
2259
- d.push(g), s.onToolCall(m.toolName, h);
2303
+ u.push(g), s.onToolCall(m.toolName, h);
2260
2304
  break;
2261
2305
  }
2262
2306
  case "tool-result": {
@@ -2272,8 +2316,8 @@ class ot {
2272
2316
  }
2273
2317
  const p = await i.usage;
2274
2318
  s.onComplete({
2275
- text: u,
2276
- toolCalls: d,
2319
+ text: c,
2320
+ toolCalls: u,
2277
2321
  usage: p.inputTokens !== void 0 && p.outputTokens !== void 0 ? { promptTokens: p.inputTokens, completionTokens: p.outputTokens } : void 0
2278
2322
  });
2279
2323
  } catch (p) {
@@ -2366,75 +2410,75 @@ class ot {
2366
2410
  }
2367
2411
  }
2368
2412
  }
2369
- async function nt() {
2413
+ async function ct() {
2370
2414
  return (await import("./WebLlmProvider-BEFvNcC5.js")).WebLlmProvider;
2371
2415
  }
2372
- function it(a) {
2373
- if (a === "mock")
2374
- return new at();
2375
- if (a === "webllm")
2416
+ function ut(r) {
2417
+ if (r === "mock")
2418
+ return new it();
2419
+ if (r === "webllm")
2376
2420
  throw new Error(
2377
2421
  "WebLlmProvider cannot be created synchronously. Use createWebLlmProvider() or getWebLlmProviderClass() instead."
2378
2422
  );
2379
- return new ot(a);
2423
+ return new lt(r);
2380
2424
  }
2381
- async function It() {
2382
- const a = await nt();
2383
- return new a();
2425
+ async function Lt() {
2426
+ const r = await ct();
2427
+ return new r();
2384
2428
  }
2385
- const $ = 10, V = 50;
2386
- function lt(a) {
2429
+ const x = 10, O = 50;
2430
+ function dt(r) {
2387
2431
  const e = [];
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
2432
+ return e.push(mt(r)), r.nodeProperties.length > 0 ? e.push(pt(r.nodeProperties)) : r.nodeCount > 0 && e.push(`### Node Properties
2433
+ No custom properties on node data.`), r.edgeProperties.length > 0 ? e.push(ht(r.edgeProperties)) : r.edgeCount > 0 && e.push(`### Edge Properties
2390
2434
  No custom properties on edge data.`), e.join(`
2391
2435
 
2392
2436
  `);
2393
2437
  }
2394
- function ct(a) {
2438
+ function mt(r) {
2395
2439
  return `## Data Schema
2396
- - Nodes: ${a.nodeCount}
2397
- - Edges: ${a.edgeCount}`;
2440
+ - Nodes: ${r.nodeCount}
2441
+ - Edges: ${r.edgeCount}`;
2398
2442
  }
2399
- function ut(a) {
2443
+ function pt(r) {
2400
2444
  const e = ["### Node Properties"];
2401
- for (const t of a)
2402
- e.push(X(t));
2445
+ for (const t of r)
2446
+ e.push(J(t));
2403
2447
  return e.join(`
2404
2448
  `);
2405
2449
  }
2406
- function dt(a) {
2450
+ function ht(r) {
2407
2451
  const e = ["### Edge Properties"];
2408
- for (const t of a)
2409
- e.push(X(t));
2452
+ for (const t of r)
2453
+ e.push(J(t));
2410
2454
  return e.join(`
2411
2455
  `);
2412
2456
  }
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}`;
2457
+ function J(r) {
2458
+ const e = vt(r.name), t = r.nullable ? "?" : "", s = gt(r), a = ft(r);
2459
+ return `- \`${e}\`: ${s}${t}${a}`;
2416
2460
  }
2417
- function mt(a) {
2418
- return a.type === "array" && a.itemType ? `${a.itemType}[]` : a.type;
2461
+ function gt(r) {
2462
+ return r.type === "array" && r.itemType ? `${r.itemType}[]` : r.type;
2419
2463
  }
2420
- function pt(a) {
2464
+ function ft(r) {
2421
2465
  const e = [];
2422
- if (a.format && e.push(`format: ${a.format}`), a.enumValues && a.enumValues.length > 0) {
2423
- const t = ht(a.enumValues);
2466
+ if (r.format && e.push(`format: ${r.format}`), r.enumValues && r.enumValues.length > 0) {
2467
+ const t = yt(r.enumValues);
2424
2468
  e.push(`values: [${t}]`);
2425
2469
  }
2426
- return a.range && e.push(`range: ${a.range.min}..${a.range.max}`), e.length === 0 ? "" : ` (${e.join(", ")})`;
2470
+ return r.range && e.push(`range: ${r.range.min}..${r.range.max}`), e.length === 0 ? "" : ` (${e.join(", ")})`;
2427
2471
  }
2428
- function ht(a) {
2429
- if (a.length <= $)
2430
- return a.map((s) => `"${s}"`).join(", ");
2431
- const e = a.slice(0, $), t = a.length - $;
2472
+ function yt(r) {
2473
+ if (r.length <= x)
2474
+ return r.map((s) => `"${s}"`).join(", ");
2475
+ const e = r.slice(0, x), t = r.length - x;
2432
2476
  return `${e.map((s) => `"${s}"`).join(", ")}, ... +${t} more`;
2433
2477
  }
2434
- function gt(a) {
2435
- return a.length <= V ? a : `${a.slice(0, V - 3)}...`;
2478
+ function vt(r) {
2479
+ return r.length <= O ? r : `${r.slice(0, O - 3)}...`;
2436
2480
  }
2437
- class ft {
2481
+ class bt {
2438
2482
  /**
2439
2483
  * Create a new SchemaManager.
2440
2484
  * @param graph - The graph to extract schema from
@@ -2451,7 +2495,7 @@ class ft {
2451
2495
  */
2452
2496
  extract() {
2453
2497
  if (this.cachedSchema === null) {
2454
- const e = new O(this.graph, this.options);
2498
+ const e = new W(this.graph, this.options);
2455
2499
  this.cachedSchema = e.extract();
2456
2500
  }
2457
2501
  return this.cachedSchema;
@@ -2472,7 +2516,7 @@ class ft {
2472
2516
  getFormattedSchema() {
2473
2517
  if (this.cachedFormattedSchema === null) {
2474
2518
  const e = this.extract();
2475
- this.cachedFormattedSchema = lt(e);
2519
+ this.cachedFormattedSchema = dt(e);
2476
2520
  }
2477
2521
  return this.cachedFormattedSchema;
2478
2522
  }
@@ -2486,13 +2530,13 @@ class ft {
2486
2530
  this.cachedSchema = null, this.cachedFormattedSchema = null;
2487
2531
  }
2488
2532
  }
2489
- const yt = 300;
2490
- class Z {
2533
+ const wt = 300;
2534
+ class Q {
2491
2535
  /**
2492
2536
  * Creates a new AiManager instance.
2493
2537
  */
2494
2538
  constructor() {
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();
2539
+ 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 fe(), this.apiKeyManager = new he(), this.statusManager = new K();
2496
2540
  }
2497
2541
  /**
2498
2542
  * Initialize the AI Manager with a graph and configuration.
@@ -2504,10 +2548,10 @@ class Z {
2504
2548
  encryptionKey: t.keyPersistence.encryptionKey,
2505
2549
  storage: t.keyPersistence.storage ?? "localStorage",
2506
2550
  prefix: t.keyPersistence.prefix
2507
- }), t.providerInstance ? this.provider = t.providerInstance : (this.provider = it(t.provider), t.apiKey && (this.apiKeyManager.setKey(t.provider, t.apiKey), this.provider.configure({
2551
+ }), t.providerInstance ? this.provider = t.providerInstance : (this.provider = ut(t.provider), t.apiKey && (this.apiKeyManager.setKey(t.provider, t.apiKey), this.provider.configure({
2508
2552
  apiKey: t.apiKey,
2509
2553
  model: t.model
2510
- }))), t.registerBuiltinCommands !== !1 && this.registerBuiltinCommands(), this.initializeSchemaManager(), this.controller = new me({
2554
+ }))), t.registerBuiltinCommands !== !1 && this.registerBuiltinCommands(), this.initializeSchemaManager(), this.controller = new ge({
2511
2555
  provider: this.provider,
2512
2556
  commandRegistry: this.commandRegistry,
2513
2557
  graph: this.graph,
@@ -2524,9 +2568,9 @@ class Z {
2524
2568
  */
2525
2569
  initializeSchemaManager() {
2526
2570
  if (this.graph) {
2527
- this.schemaManager = new ft(this.graph), this.schemaManager.extract(), this.debouncedSchemaUpdate = Y.debounce(() => {
2571
+ this.schemaManager = new bt(this.graph), this.schemaManager.extract(), this.debouncedSchemaUpdate = ee.debounce(() => {
2528
2572
  this.schemaManager && this.schemaManager.invalidateCache();
2529
- }, yt);
2573
+ }, wt);
2530
2574
  try {
2531
2575
  const { eventManager: e } = this.graph;
2532
2576
  this.dataAddedListenerId = e.addListener("data-added", () => {
@@ -2540,10 +2584,17 @@ class Z {
2540
2584
  * Register built-in commands for graph control.
2541
2585
  */
2542
2586
  registerBuiltinCommands() {
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);
2587
+ this.registerCommand(we), this.registerCommand(Ce), this.registerCommand(xe), this.registerCommand(Qe), this.registerCommand(nt), this.registerCommand(Ge), this.registerCommand(We), this.registerCommand(Ee), this.registerCommand(Ae), this.registerCommand(Ne), this.registerCommand(Ue), this.registerCommand(qe), this.registerCommand(Ve), this.registerCommand(Oe), this.registerCommand(Ke);
2544
2588
  }
2545
2589
  /**
2546
2590
  * Register a custom command.
2591
+ *
2592
+ * Each assistant message is one undoable step. A command joins it by writing through
2593
+ * `ctx.tx` (`ctx.tx.styles.add`, `ctx.tx.layout.set`, `ctx.tx.run`): those changes are undone
2594
+ * with the rest of the message, and rolled back if a command throws. A change made through
2595
+ * `ctx.graph` is a step of its own and is not rolled back. A command stops when
2596
+ * `ctx.abortSignal` fires, which happens when the message is cancelled or undone while it is
2597
+ * still going.
2547
2598
  * @param command - The command to register
2548
2599
  */
2549
2600
  registerCommand(e) {
@@ -2668,41 +2719,41 @@ class Z {
2668
2719
  }
2669
2720
  }
2670
2721
  }
2671
- function vt() {
2672
- return new Z();
2722
+ function St() {
2723
+ return new Q();
2673
2724
  }
2674
- const Rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2725
+ const jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2675
2726
  __proto__: null,
2676
- AiManager: Z,
2677
- createAiManager: vt
2727
+ AiManager: Q,
2728
+ createAiManager: St
2678
2729
  }, Symbol.toStringTag, { value: "Module" }));
2679
2730
  export {
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
2731
+ ge as A,
2732
+ fe as C,
2733
+ it as M,
2734
+ W as S,
2735
+ lt as V,
2736
+ Q as a,
2737
+ K as b,
2738
+ bt as c,
2739
+ Ve as d,
2740
+ St as e,
2741
+ dt as f,
2742
+ ut as g,
2743
+ Lt as h,
2744
+ nt as i,
2745
+ qe as j,
2746
+ Ue as k,
2747
+ Ce as l,
2748
+ ct as m,
2749
+ Ge as n,
2750
+ Oe as o,
2751
+ Ae as p,
2752
+ we as q,
2753
+ We as r,
2754
+ Qe as s,
2755
+ Ne as t,
2756
+ Ee as u,
2757
+ jt as v,
2758
+ Ke as z
2708
2759
  };