@pixerate/editor 0.47.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.cjs +248 -29
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +18 -6
- package/dist/agent/index.d.ts +18 -6
- package/dist/agent/index.js +228 -9
- package/dist/agent/index.js.map +1 -1
- package/dist/{builtins-xs7rK6ys.d.cts → builtins-1kqwLUnb.d.cts} +1 -1
- package/dist/{builtins-D2nMtw2W.d.ts → builtins-BKYlHH1s.d.ts} +1 -1
- package/dist/chart/index.cjs +216 -3541
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.d.cts +4 -494
- package/dist/chart/index.d.ts +4 -494
- package/dist/chart/index.js +155 -3480
- package/dist/chart/index.js.map +1 -1
- package/dist/{chunk-5VXI5GED.js → chunk-2CJ3LPYQ.js} +3 -3
- package/dist/{chunk-TXXNBDQX.cjs → chunk-2Q46FKZK.cjs} +113 -34
- package/dist/chunk-2Q46FKZK.cjs.map +1 -0
- package/dist/chunk-3JNRQVTS.cjs +521 -0
- package/dist/chunk-3JNRQVTS.cjs.map +1 -0
- package/dist/chunk-5TWIN7ZJ.js +113 -0
- package/dist/chunk-5TWIN7ZJ.js.map +1 -0
- package/dist/{chunk-PQFAHT5O.js → chunk-DQPBQXKG.js} +27 -94
- package/dist/chunk-DQPBQXKG.js.map +1 -0
- package/dist/{chunk-ZFBBVGCI.js → chunk-EKYHKQPG.js} +243 -243
- package/dist/{chunk-ZFBBVGCI.js.map → chunk-EKYHKQPG.js.map} +1 -1
- package/dist/{chunk-J3R2OWOE.cjs → chunk-FEMIVHN3.cjs} +610 -15
- package/dist/chunk-FEMIVHN3.cjs.map +1 -0
- package/dist/{chunk-C3NWJE3K.js → chunk-GJBIVWB2.js} +11 -672
- package/dist/chunk-GJBIVWB2.js.map +1 -0
- package/dist/chunk-GTZXF4BI.cjs +3424 -0
- package/dist/chunk-GTZXF4BI.cjs.map +1 -0
- package/dist/chunk-JOX6MJW4.cjs +674 -0
- package/dist/chunk-JOX6MJW4.cjs.map +1 -0
- package/dist/{chunk-REAGGLXS.js → chunk-JQ3BB3E6.js} +2 -2
- package/dist/{chunk-H4PICYNL.cjs → chunk-LNKZPIQD.cjs} +113 -180
- package/dist/chunk-LNKZPIQD.cjs.map +1 -0
- package/dist/chunk-OV7UAKIY.js +674 -0
- package/dist/chunk-OV7UAKIY.js.map +1 -0
- package/dist/{chunk-TK2XZK6Z.js → chunk-QFTVLEVN.js} +596 -1
- package/dist/chunk-QFTVLEVN.js.map +1 -0
- package/dist/{chunk-KRGXUQ2Y.js → chunk-T6XU4B54.js} +82 -3
- package/dist/chunk-T6XU4B54.js.map +1 -0
- package/dist/chunk-TGBCBQFV.cjs +113 -0
- package/dist/chunk-TGBCBQFV.cjs.map +1 -0
- package/dist/{chunk-SQC26VQV.cjs → chunk-UN33YOXW.cjs} +191 -191
- package/dist/{chunk-SQC26VQV.cjs.map → chunk-UN33YOXW.cjs.map} +1 -1
- package/dist/chunk-WBOAXDKD.js +3424 -0
- package/dist/chunk-WBOAXDKD.js.map +1 -0
- package/dist/{chunk-LYGEEDNR.cjs → chunk-XP5IUZUO.cjs} +242 -242
- package/dist/chunk-XP5IUZUO.cjs.map +1 -0
- package/dist/{chunk-BBRK6MOI.cjs → chunk-YU4WQE5M.cjs} +100 -100
- package/dist/{chunk-BBRK6MOI.cjs.map → chunk-YU4WQE5M.cjs.map} +1 -1
- package/dist/commands/index.d.cts +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/controller-ChjCCMLl.d.cts +822 -0
- package/dist/controller-DtbEo3om.d.ts +822 -0
- package/dist/export/index.cjs +4 -2
- package/dist/export/index.cjs.map +1 -1
- package/dist/export/index.d.cts +5 -1
- package/dist/export/index.d.ts +5 -1
- package/dist/export/index.js +3 -1
- package/dist/extensions/index.cjs +33 -4
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +4 -2
- package/dist/extensions/index.d.ts +4 -2
- package/dist/extensions/index.js +32 -3
- package/dist/{index-QrqMmZ75.d.cts → index-DoHqT1mq.d.cts} +203 -7
- package/dist/{index-CSUCQYAH.d.ts → index-YLZ0fKqE.d.ts} +203 -7
- package/dist/index.cjs +39 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +33 -7
- package/dist/index.js.map +1 -1
- package/dist/spreadsheet/index.cjs +4 -4
- package/dist/spreadsheet/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-C3NWJE3K.js.map +0 -1
- package/dist/chunk-H4PICYNL.cjs.map +0 -1
- package/dist/chunk-J3R2OWOE.cjs.map +0 -1
- package/dist/chunk-KRGXUQ2Y.js.map +0 -1
- package/dist/chunk-LYGEEDNR.cjs.map +0 -1
- package/dist/chunk-NEOO6QJD.cjs +0 -1182
- package/dist/chunk-NEOO6QJD.cjs.map +0 -1
- package/dist/chunk-PQFAHT5O.js.map +0 -1
- package/dist/chunk-TK2XZK6Z.js.map +0 -1
- package/dist/chunk-TXXNBDQX.cjs.map +0 -1
- package/dist/types-BVqWm3d1.d.cts +0 -320
- package/dist/types-BVqWm3d1.d.ts +0 -320
- /package/dist/{chunk-5VXI5GED.js.map → chunk-2CJ3LPYQ.js.map} +0 -0
- /package/dist/{chunk-REAGGLXS.js.map → chunk-JQ3BB3E6.js.map} +0 -0
package/dist/agent/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHART_UPDATE_PROPERTIES,
|
|
3
|
+
SERIES_PROPS,
|
|
4
|
+
VALUE
|
|
5
|
+
} from "../chunk-5TWIN7ZJ.js";
|
|
1
6
|
import {
|
|
2
7
|
EDITOR_CANVAS_TOOLS,
|
|
3
8
|
EDITOR_MCP_TOOLS,
|
|
@@ -35,14 +40,26 @@ import {
|
|
|
35
40
|
validateJsonSchema
|
|
36
41
|
} from "../chunk-4FX5ACVG.js";
|
|
37
42
|
import {
|
|
43
|
+
MAX_SPARKLINE_VALUES,
|
|
44
|
+
SPARKLINE_KINDS,
|
|
38
45
|
TABLE_ACTIONS,
|
|
39
46
|
applyReplacements,
|
|
47
|
+
getDocumentCharts,
|
|
40
48
|
getTableActionState,
|
|
41
49
|
getTableState,
|
|
42
50
|
isTableEnabled,
|
|
51
|
+
normalizeSparklineValues,
|
|
43
52
|
runTableAction,
|
|
44
|
-
searchDocument
|
|
45
|
-
|
|
53
|
+
searchDocument,
|
|
54
|
+
sparklineLabel
|
|
55
|
+
} from "../chunk-QFTVLEVN.js";
|
|
56
|
+
import {
|
|
57
|
+
describeChart
|
|
58
|
+
} from "../chunk-WBOAXDKD.js";
|
|
59
|
+
import {
|
|
60
|
+
normalizeChartSpec,
|
|
61
|
+
parseChartValue
|
|
62
|
+
} from "../chunk-OV7UAKIY.js";
|
|
46
63
|
import {
|
|
47
64
|
getEditorMarkdown,
|
|
48
65
|
getEditorText,
|
|
@@ -50,12 +67,14 @@ import {
|
|
|
50
67
|
} from "../chunk-UKI64KUD.js";
|
|
51
68
|
import "../chunk-O5RYH2PG.js";
|
|
52
69
|
import "../chunk-SWE3NPOU.js";
|
|
53
|
-
import "../chunk-
|
|
70
|
+
import "../chunk-JQ3BB3E6.js";
|
|
54
71
|
import {
|
|
55
72
|
colNameToIndex,
|
|
56
73
|
indexToColName,
|
|
57
74
|
isFormulaError
|
|
58
|
-
} from "../chunk-
|
|
75
|
+
} from "../chunk-EKYHKQPG.js";
|
|
76
|
+
import "../chunk-664LQYFJ.js";
|
|
77
|
+
import "../chunk-QVZZGT4X.js";
|
|
59
78
|
import {
|
|
60
79
|
ensureLayout,
|
|
61
80
|
getLayoutedNodes,
|
|
@@ -387,6 +406,204 @@ function planToolCall(name, args, snapshot, options) {
|
|
|
387
406
|
|
|
388
407
|
// src/agent/providers.ts
|
|
389
408
|
import { TextSelection } from "@tiptap/pm/state";
|
|
409
|
+
|
|
410
|
+
// src/agent/documentChartTools.ts
|
|
411
|
+
import { closeHistory } from "@tiptap/pm/history";
|
|
412
|
+
var READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
413
|
+
var WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
414
|
+
var WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
415
|
+
var SIZE_WIDTH = {
|
|
416
|
+
type: ["number", "null"],
|
|
417
|
+
minimum: 50,
|
|
418
|
+
maximum: 4096,
|
|
419
|
+
description: "Width in pixels, or null to fill the line (default null)."
|
|
420
|
+
};
|
|
421
|
+
var SIZE_HEIGHT = { type: "number", minimum: 50, maximum: 4096, description: "Height in pixels (default 320)." };
|
|
422
|
+
var SPEC_PROPERTIES = {
|
|
423
|
+
...CHART_UPDATE_PROPERTIES,
|
|
424
|
+
categories: { type: "array", items: { type: "string" }, description: "Category labels in order (x axis labels, or pie slices)." },
|
|
425
|
+
series: {
|
|
426
|
+
type: "array",
|
|
427
|
+
description: "The series, each with one value per category (padded with gaps).",
|
|
428
|
+
items: {
|
|
429
|
+
type: "object",
|
|
430
|
+
properties: { id: { type: "string", description: "Stable id (default: from the name)." }, ...SERIES_PROPS },
|
|
431
|
+
required: ["name", "values"],
|
|
432
|
+
additionalProperties: false
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
function cleanSeries(series) {
|
|
437
|
+
if (!Array.isArray(series)) return series;
|
|
438
|
+
return series.map((s) => s && typeof s === "object" ? Object.fromEntries(Object.entries(s).filter(([, v]) => v !== null)) : s);
|
|
439
|
+
}
|
|
440
|
+
function checkedSpec(input) {
|
|
441
|
+
const { spec, issues } = normalizeChartSpec({ ...input, ...input.series !== void 0 ? { series: cleanSeries(input.series) } : {} });
|
|
442
|
+
if (issues.length) throw new Error(`The chart was not changed: ${issues.map((i) => i.message).join(" ")}`);
|
|
443
|
+
return spec;
|
|
444
|
+
}
|
|
445
|
+
function describe(chart, includeSpec) {
|
|
446
|
+
const { spec, node } = chart;
|
|
447
|
+
return {
|
|
448
|
+
id: chart.id,
|
|
449
|
+
pos: chart.pos,
|
|
450
|
+
type: spec.type,
|
|
451
|
+
title: spec.title,
|
|
452
|
+
categories: spec.categories,
|
|
453
|
+
series: spec.series.map((s) => ({ id: s.id, name: s.name })),
|
|
454
|
+
width: node.attrs.width ?? null,
|
|
455
|
+
height: node.attrs.height,
|
|
456
|
+
description: describeChart(spec),
|
|
457
|
+
...includeSpec ? { spec } : {}
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function sparklines(doc) {
|
|
461
|
+
const found = [];
|
|
462
|
+
doc.descendants((node, pos) => {
|
|
463
|
+
if (node.type.name === "sparkline") found.push({ pos, kind: node.attrs.kind, values: node.attrs.values, label: sparklineLabel(node) });
|
|
464
|
+
});
|
|
465
|
+
return found;
|
|
466
|
+
}
|
|
467
|
+
function checkPosition(editor, at) {
|
|
468
|
+
const size = editor.state.doc.content.size;
|
|
469
|
+
if (at !== void 0 && at > size) throw new Error(`Position ${at} is outside the document (size ${size}).`);
|
|
470
|
+
}
|
|
471
|
+
function createDocumentChartTools(editor) {
|
|
472
|
+
const chartType = () => editor().schema.nodes.chart;
|
|
473
|
+
const findChart = (args) => {
|
|
474
|
+
const charts = getDocumentCharts(editor().state.doc);
|
|
475
|
+
const list = charts.map((c) => `"${c.id}" at ${c.pos}`).join(", ") || "none; add one with insert_chart";
|
|
476
|
+
if (args.chartId !== void 0) {
|
|
477
|
+
const chart = charts.find((c) => c.id === args.chartId);
|
|
478
|
+
if (!chart) throw new Error(`There is no chart "${args.chartId}" in the document. Charts: ${list}.`);
|
|
479
|
+
if (args.pos !== void 0 && args.pos !== chart.pos) throw new Error(`Chart "${args.chartId}" is at ${chart.pos}, not ${args.pos}; pass one of chartId or pos.`);
|
|
480
|
+
return chart;
|
|
481
|
+
}
|
|
482
|
+
if (args.pos !== void 0) {
|
|
483
|
+
const chart = charts.find((c) => c.pos === args.pos);
|
|
484
|
+
if (!chart) throw new Error(`There is no chart at position ${args.pos}. Charts: ${list}.`);
|
|
485
|
+
return chart;
|
|
486
|
+
}
|
|
487
|
+
throw new Error(`Pass chartId or pos (from list_document_charts). Charts: ${list}.`);
|
|
488
|
+
};
|
|
489
|
+
const listCharts = {
|
|
490
|
+
name: "list_document_charts",
|
|
491
|
+
title: "List charts in the document",
|
|
492
|
+
description: "Lists the charts in the document in order: id, document position, type, title, categories, series (ids and names), size in pixels and a plain-language description of the data. Also lists inline sparklines (position, kind, values). Pass the id or position to update_chart_in_document.",
|
|
493
|
+
inputSchema: {
|
|
494
|
+
type: "object",
|
|
495
|
+
properties: { includeSpec: { type: "boolean", description: "Also return each chart's full spec (default false)." } },
|
|
496
|
+
additionalProperties: false
|
|
497
|
+
},
|
|
498
|
+
annotations: { title: "List charts in the document", ...READ },
|
|
499
|
+
handler: ({ includeSpec = false }) => {
|
|
500
|
+
const doc = editor().state.doc;
|
|
501
|
+
return { charts: getDocumentCharts(doc).map((c) => describe(c, includeSpec)), sparklines: editor().schema.nodes.sparkline ? sparklines(doc) : [] };
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
const insertChart = {
|
|
505
|
+
name: "insert_chart",
|
|
506
|
+
title: "Insert a chart",
|
|
507
|
+
description: "Inserts a chart block at a document position (or the cursor), as one undo step. Give the categories and series (one value per category) and any presentation fields (type, titles, axes, legend, stacking, palette, \u2026). Invalid fields change nothing and come back as sentences. Returns the new chart's id, position and stored spec.",
|
|
508
|
+
inputSchema: {
|
|
509
|
+
type: "object",
|
|
510
|
+
properties: {
|
|
511
|
+
spec: { type: "object", description: "The chart: categories and series, plus optional presentation fields.", properties: SPEC_PROPERTIES, required: ["categories", "series"], additionalProperties: false },
|
|
512
|
+
at: { type: "integer", minimum: 0, description: "Document position (default: the selection). A position inside a paragraph splits it." },
|
|
513
|
+
width: SIZE_WIDTH,
|
|
514
|
+
height: SIZE_HEIGHT
|
|
515
|
+
},
|
|
516
|
+
required: ["spec"],
|
|
517
|
+
additionalProperties: false
|
|
518
|
+
},
|
|
519
|
+
annotations: { title: "Insert a chart", ...WRITE },
|
|
520
|
+
handler: ({ spec: input, at, width = null, height }) => {
|
|
521
|
+
const ed = editor();
|
|
522
|
+
checkPosition(ed, at);
|
|
523
|
+
const spec = checkedSpec(input);
|
|
524
|
+
const id = ed.extensionManager.extensions.find((e) => e.name === "chart")?.options.generateId?.() ?? `chart-${Date.now().toString(36)}`;
|
|
525
|
+
const node = { type: "chart", attrs: { id, spec, width, ...height !== void 0 ? { height } : {} } };
|
|
526
|
+
const chain = ed.chain().command(({ tr }) => (closeHistory(tr), true));
|
|
527
|
+
const ok = (at !== void 0 ? chain.insertContentAt(at, node) : chain.insertContent(node)).run();
|
|
528
|
+
const chart = getDocumentCharts(ed.state.doc).find((c) => c.id === id);
|
|
529
|
+
if (!ok || !chart) throw new Error(`A chart cannot go at ${at ?? ed.state.selection.from}; pass a position between blocks or inside a paragraph.`);
|
|
530
|
+
return { id: chart.id, pos: chart.pos, spec: chart.spec, width: chart.node.attrs.width, height: chart.node.attrs.height };
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
const updateChart = {
|
|
534
|
+
name: "update_chart_in_document",
|
|
535
|
+
title: "Change a chart in the document",
|
|
536
|
+
description: "Changes one chart (by id or position from list_document_charts) as one undo step: data (categories, series \u2014 given series replace all) and / or presentation fields, which merge into the current spec (axes and legend field by field), plus its size. All-or-nothing: invalid values change nothing and come back as sentences. Returns the chart's id, position and new spec.",
|
|
537
|
+
inputSchema: {
|
|
538
|
+
type: "object",
|
|
539
|
+
properties: {
|
|
540
|
+
chartId: { type: "string", description: "Chart id from list_document_charts." },
|
|
541
|
+
pos: { type: "integer", minimum: 0, description: "Document position of the chart (from list_document_charts), instead of chartId." },
|
|
542
|
+
changes: { type: "object", description: "Fields to change; omitted fields keep their value.", properties: SPEC_PROPERTIES, additionalProperties: false },
|
|
543
|
+
width: SIZE_WIDTH,
|
|
544
|
+
height: { ...SIZE_HEIGHT, description: "Height in pixels (default: unchanged)." }
|
|
545
|
+
},
|
|
546
|
+
additionalProperties: false
|
|
547
|
+
},
|
|
548
|
+
annotations: { title: "Change a chart in the document", ...WRITE_IDEMPOTENT },
|
|
549
|
+
handler: ({ chartId, pos, changes, width, height }) => {
|
|
550
|
+
const ed = editor();
|
|
551
|
+
const chart = findChart({ chartId, pos });
|
|
552
|
+
if (!changes && width === void 0 && height === void 0) throw new Error('Nothing to change: pass changes, width or height, e.g. {"changes": {"type": "line"}}.');
|
|
553
|
+
const s = chart.spec;
|
|
554
|
+
const patch = changes ?? {};
|
|
555
|
+
const spec = checkedSpec({
|
|
556
|
+
...s,
|
|
557
|
+
...patch,
|
|
558
|
+
xAxis: patch.xAxis ? { ...s.xAxis, ...patch.xAxis } : s.xAxis,
|
|
559
|
+
yAxis: patch.yAxis ? { ...s.yAxis, ...patch.yAxis } : s.yAxis,
|
|
560
|
+
yAxis2: patch.yAxis2 ? { ...s.yAxis2, ...patch.yAxis2 } : s.yAxis2,
|
|
561
|
+
legend: patch.legend ? { ...s.legend, ...patch.legend } : s.legend
|
|
562
|
+
});
|
|
563
|
+
const attrs = { ...chart.node.attrs, spec, ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} };
|
|
564
|
+
ed.view.dispatch(closeHistory(ed.state.tr.setNodeMarkup(chart.pos, void 0, attrs)));
|
|
565
|
+
return { id: chart.id, pos: chart.pos, spec, width: attrs.width, height: attrs.height };
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const insertSparkline = {
|
|
569
|
+
name: "insert_sparkline",
|
|
570
|
+
title: "Insert a sparkline",
|
|
571
|
+
description: "Inserts a word-sized chart into the text at a document position (or the cursor), as one undo step. Returns its position and stored values.",
|
|
572
|
+
inputSchema: {
|
|
573
|
+
type: "object",
|
|
574
|
+
properties: {
|
|
575
|
+
values: { type: "array", items: VALUE, minItems: 1, maxItems: MAX_SPARKLINE_VALUES, description: "Values in order (null for a gap)." },
|
|
576
|
+
kind: { type: "string", enum: [...SPARKLINE_KINDS], description: "line (default), column, or win-loss (sign only)." },
|
|
577
|
+
at: { type: "integer", minimum: 0, description: "Document position inside a paragraph (default: the selection)." },
|
|
578
|
+
width: { type: "number", minimum: 4, maximum: 1e3, description: "Width in pixels (default 80)." },
|
|
579
|
+
height: { type: "number", minimum: 4, maximum: 200, description: "Height in pixels (default 18)." },
|
|
580
|
+
color: { type: "string", description: "CSS colour (default: the first palette colour)." },
|
|
581
|
+
label: { type: "string", description: 'Accessible label (default: "Trend from <first> to <last>").' }
|
|
582
|
+
},
|
|
583
|
+
required: ["values"],
|
|
584
|
+
additionalProperties: false
|
|
585
|
+
},
|
|
586
|
+
annotations: { title: "Insert a sparkline", ...WRITE },
|
|
587
|
+
handler: ({ values, kind = "line", at, width = 80, height = 18, color = null, label = null }) => {
|
|
588
|
+
const ed = editor();
|
|
589
|
+
checkPosition(ed, at);
|
|
590
|
+
const parsed = values.map((v) => parseChartValue(v));
|
|
591
|
+
const bad = parsed.findIndex((v) => v === void 0);
|
|
592
|
+
if (bad >= 0) throw new Error(`values[${bad}] ("${String(values[bad])}") is not a number; pass numbers, numeric text or null. Nothing was inserted.`);
|
|
593
|
+
const pos = at ?? ed.state.selection.from;
|
|
594
|
+
if (!ed.state.doc.resolve(pos).parent.inlineContent) throw new Error(`Position ${pos} is between blocks; a sparkline goes inside a paragraph (use a position from get_text {blocks: true}).`);
|
|
595
|
+
const stored = normalizeSparklineValues(parsed);
|
|
596
|
+
ed.chain().command(({ tr }) => (closeHistory(tr), true)).insertContentAt(pos, { type: "sparkline", attrs: { values: stored, kind, width, height, color, label } }).run();
|
|
597
|
+
return { pos, kind, values: stored };
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
return {
|
|
601
|
+
read: () => chartType() ? [listCharts] : [],
|
|
602
|
+
write: () => chartType() ? [insertChart, updateChart, ...editor().schema.nodes.sparkline ? [insertSparkline] : []] : []
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/agent/providers.ts
|
|
390
607
|
var toEditor = (target) => "commands" in target ? target : target.editor;
|
|
391
608
|
function replaceWithText(editor, from, to, text) {
|
|
392
609
|
const { state, view } = editor;
|
|
@@ -432,6 +649,7 @@ function findMatches(editor, query, args, replacement) {
|
|
|
432
649
|
}
|
|
433
650
|
function createRichTextToolProvider(target, options) {
|
|
434
651
|
const editor = () => toEditor(target);
|
|
652
|
+
const charts = createDocumentChartTools(editor);
|
|
435
653
|
const getText = {
|
|
436
654
|
name: "get_text",
|
|
437
655
|
title: "Get document text",
|
|
@@ -721,9 +939,9 @@ function createRichTextToolProvider(target, options) {
|
|
|
721
939
|
tools: () => {
|
|
722
940
|
const ed = editor();
|
|
723
941
|
if (!ed || ed.isDestroyed) return [];
|
|
724
|
-
if (!ed.isEditable) return [getText, findText];
|
|
942
|
+
if (!ed.isEditable) return [getText, findText, ...charts.read()];
|
|
725
943
|
const tools = [getText, findText, insertText, replaceText, replaceRange, replaceSelection, setSelection];
|
|
726
|
-
return isTableEnabled(ed) ? [
|
|
944
|
+
return [...tools, ...isTableEnabled(ed) ? [editTable] : [], ...charts.read(), ...charts.write()];
|
|
727
945
|
},
|
|
728
946
|
subscribe: (notify) => {
|
|
729
947
|
const ed = editor();
|
|
@@ -1053,8 +1271,8 @@ var COMPONENT_ID = { type: "string", description: "Component or component set id
|
|
|
1053
1271
|
var PARENT_ID = { type: "string", description: "Frame to place the instance in (default: the canvas root)." };
|
|
1054
1272
|
var X = { type: "number", description: "X position (canvas coordinates, or relative to the parent frame)." };
|
|
1055
1273
|
var Y = { type: "number", description: "Y position (canvas coordinates, or relative to the parent frame)." };
|
|
1056
|
-
var
|
|
1057
|
-
var
|
|
1274
|
+
var READ2 = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
1275
|
+
var WRITE2 = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
1058
1276
|
var DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false };
|
|
1059
1277
|
var TITLES = {
|
|
1060
1278
|
list_components: "List components",
|
|
@@ -1088,7 +1306,7 @@ function createCanvasComponentToolProvider(controller, options = { id: "canvas-c
|
|
|
1088
1306
|
inputSchema: { type: "object", properties, ...extra.required ? { required: extra.required } : {}, additionalProperties: false },
|
|
1089
1307
|
annotations: {
|
|
1090
1308
|
title: TITLES[name],
|
|
1091
|
-
...extra.readOnly ?
|
|
1309
|
+
...extra.readOnly ? READ2 : DESTRUCTIVE_TOOLS.has(name) ? DESTRUCTIVE : WRITE2
|
|
1092
1310
|
},
|
|
1093
1311
|
handler
|
|
1094
1312
|
});
|
|
@@ -1268,6 +1486,7 @@ export {
|
|
|
1268
1486
|
ToolRegistry,
|
|
1269
1487
|
ToolRegistryError,
|
|
1270
1488
|
createCanvasComponentToolProvider,
|
|
1489
|
+
createDocumentChartTools,
|
|
1271
1490
|
createEditorMcpToolProvider,
|
|
1272
1491
|
createMcpServer,
|
|
1273
1492
|
createRichTextToolProvider,
|