@pixerate/editor 0.28.0 → 0.30.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 (97) hide show
  1. package/README.md +20 -1
  2. package/dist/HistoryManager-DWSLd6Tf.d.ts +150 -0
  3. package/dist/HistoryManager-DeQQMBCj.d.cts +150 -0
  4. package/dist/agent/index.cjs +20 -427
  5. package/dist/agent/index.cjs.map +1 -1
  6. package/dist/agent/index.d.cts +4 -342
  7. package/dist/agent/index.d.ts +4 -342
  8. package/dist/agent/index.js +14 -421
  9. package/dist/agent/index.js.map +1 -1
  10. package/dist/animation/index.cjs +6 -2
  11. package/dist/animation/index.cjs.map +1 -1
  12. package/dist/animation/index.d.cts +3 -73
  13. package/dist/animation/index.d.ts +3 -73
  14. package/dist/animation/index.js +17 -13
  15. package/dist/{builtins-nMXh9sT3.d.cts → builtins-DxC3aUR2.d.cts} +2 -2
  16. package/dist/{builtins-haN82vjT.d.ts → builtins-NGxNxQfJ.d.ts} +2 -2
  17. package/dist/canvas/index.cjs +338 -28
  18. package/dist/canvas/index.cjs.map +1 -1
  19. package/dist/canvas/index.d.cts +109 -4
  20. package/dist/canvas/index.d.ts +109 -4
  21. package/dist/canvas/index.js +323 -13
  22. package/dist/canvas/index.js.map +1 -1
  23. package/dist/chunk-36BLROHV.js +438 -0
  24. package/dist/chunk-36BLROHV.js.map +1 -0
  25. package/dist/{chunk-OYEFRO3D.cjs → chunk-6MDQKHRH.cjs} +4 -4
  26. package/dist/{chunk-OYEFRO3D.cjs.map → chunk-6MDQKHRH.cjs.map} +1 -1
  27. package/dist/{chunk-ARRTP33I.js → chunk-D6S5M7HV.js} +2 -2
  28. package/dist/{chunk-ARRTP33I.js.map → chunk-D6S5M7HV.js.map} +1 -1
  29. package/dist/{chunk-MXZJ4PKN.js → chunk-DDADOHJW.js} +8 -8
  30. package/dist/{chunk-CPOKFNBG.cjs → chunk-I6BZB5ZH.cjs} +2 -2
  31. package/dist/{chunk-CPOKFNBG.cjs.map → chunk-I6BZB5ZH.cjs.map} +1 -1
  32. package/dist/chunk-PIIAZV3L.cjs +244 -0
  33. package/dist/chunk-PIIAZV3L.cjs.map +1 -0
  34. package/dist/{chunk-G2I4QJOT.cjs → chunk-QKLRAA4T.cjs} +3 -244
  35. package/dist/chunk-QKLRAA4T.cjs.map +1 -0
  36. package/dist/{chunk-2H7ZHPEJ.js → chunk-QVZZGT4X.js} +1 -242
  37. package/dist/chunk-QVZZGT4X.js.map +1 -0
  38. package/dist/chunk-UB2OY7FD.js +262 -0
  39. package/dist/chunk-UB2OY7FD.js.map +1 -0
  40. package/dist/chunk-V7CC7RZ6.cjs +438 -0
  41. package/dist/chunk-V7CC7RZ6.cjs.map +1 -0
  42. package/dist/{chunk-PWJARCI4.js → chunk-W7BOBWZD.js} +5 -196
  43. package/dist/chunk-W7BOBWZD.js.map +1 -0
  44. package/dist/{chunk-TTYCN6ZH.cjs → chunk-XHRZSB77.cjs} +8 -199
  45. package/dist/chunk-XHRZSB77.cjs.map +1 -0
  46. package/dist/chunk-XZ4L3R4K.cjs +262 -0
  47. package/dist/chunk-XZ4L3R4K.cjs.map +1 -0
  48. package/dist/chunk-YK57D7PW.js +244 -0
  49. package/dist/chunk-YK57D7PW.js.map +1 -0
  50. package/dist/commands/index.cjs +2 -2
  51. package/dist/commands/index.cjs.map +1 -1
  52. package/dist/commands/index.d.cts +2 -2
  53. package/dist/commands/index.d.ts +2 -2
  54. package/dist/commands/index.js +1 -1
  55. package/dist/commands/index.js.map +1 -1
  56. package/dist/easing-DTmX99QG.d.cts +88 -0
  57. package/dist/easing-DTmX99QG.d.ts +88 -0
  58. package/dist/extensions/index.cjs +5 -5
  59. package/dist/extensions/index.cjs.map +1 -1
  60. package/dist/extensions/index.js +9 -9
  61. package/dist/generation/index.cjs +2 -2
  62. package/dist/generation/index.cjs.map +1 -1
  63. package/dist/generation/index.js +1 -1
  64. package/dist/generation/index.js.map +1 -1
  65. package/dist/history/index.cjs +4 -2
  66. package/dist/history/index.cjs.map +1 -1
  67. package/dist/history/index.d.cts +3 -149
  68. package/dist/history/index.d.ts +3 -149
  69. package/dist/history/index.js +5 -3
  70. package/dist/image-editor/index.cjs.map +1 -1
  71. package/dist/image-editor/index.js.map +1 -1
  72. package/dist/index.cjs +15 -13
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +3 -2
  75. package/dist/index.d.ts +3 -2
  76. package/dist/index.js +22 -20
  77. package/dist/index.js.map +1 -1
  78. package/dist/parameters/index.cjs +1320 -0
  79. package/dist/parameters/index.cjs.map +1 -0
  80. package/dist/parameters/index.d.cts +625 -0
  81. package/dist/parameters/index.d.ts +625 -0
  82. package/dist/parameters/index.js +1320 -0
  83. package/dist/parameters/index.js.map +1 -0
  84. package/dist/tools/index.cjs +31 -0
  85. package/dist/tools/index.cjs.map +1 -0
  86. package/dist/tools/index.d.cts +343 -0
  87. package/dist/tools/index.d.ts +343 -0
  88. package/dist/tools/index.js +31 -0
  89. package/dist/tools/index.js.map +1 -0
  90. package/dist/{types-GT5a5YAX.d.cts → types-DsiXGmjo.d.cts} +1 -1
  91. package/dist/{types-GT5a5YAX.d.ts → types-DsiXGmjo.d.ts} +1 -1
  92. package/package.json +11 -1
  93. package/dist/chunk-2H7ZHPEJ.js.map +0 -1
  94. package/dist/chunk-G2I4QJOT.cjs.map +0 -1
  95. package/dist/chunk-PWJARCI4.js.map +0 -1
  96. package/dist/chunk-TTYCN6ZH.cjs.map +0 -1
  97. /package/dist/{chunk-MXZJ4PKN.js.map → chunk-DDADOHJW.js.map} +0 -0
@@ -1,9 +1,22 @@
1
+ import {
2
+ EDITOR_MCP_TOOLS,
3
+ EXPORT_EXCLUDED_SELECTORS,
4
+ MCP_TOOL_EDIT_CANVAS,
5
+ MCP_TOOL_EDIT_PROMPT,
6
+ MCP_TOOL_GET_EDITOR_STATE,
7
+ MCP_TOOL_VIEW_EDITOR,
8
+ TOOL_NAMESPACE_SEPARATOR,
9
+ ToolRegistry,
10
+ ToolRegistryError,
11
+ createToolRegistry,
12
+ toToolResult
13
+ } from "../chunk-36BLROHV.js";
1
14
  import {
2
15
  hasVariantCommands
3
16
  } from "../chunk-IB3ZHQAX.js";
4
17
  import {
5
18
  validateJsonSchema
6
- } from "../chunk-ARRTP33I.js";
19
+ } from "../chunk-D6S5M7HV.js";
7
20
  import {
8
21
  TABLE_ACTIONS,
9
22
  getTableActionState,
@@ -289,426 +302,6 @@ function planToolCall(name, args, snapshot, options) {
289
302
  return command ? planAgentCommand(command, snapshot, options) : [];
290
303
  }
291
304
 
292
- // src/agent/tools.ts
293
- var MCP_TOOL_GET_EDITOR_STATE = {
294
- name: "get_editor_state",
295
- title: "Get editor state",
296
- annotations: {
297
- title: "Get editor state",
298
- readOnlyHint: true,
299
- destructiveHint: false,
300
- idempotentHint: true,
301
- openWorldHint: false
302
- },
303
- description: "Retrieves the current state of the document, variables, selection, and canvas graph (nodes and edges).",
304
- inputSchema: {
305
- type: "object",
306
- properties: {
307
- includeDocument: {
308
- type: "boolean",
309
- description: "Whether to include the prompt document text and variables (default: true)."
310
- },
311
- includeCanvas: {
312
- type: "boolean",
313
- description: "Whether to include the canvas nodes and edges (default: true)."
314
- }
315
- }
316
- }
317
- };
318
- var MCP_TOOL_EDIT_CANVAS = {
319
- name: "edit_canvas",
320
- title: "Edit the canvas",
321
- annotations: {
322
- title: "Edit the canvas",
323
- readOnlyHint: false,
324
- destructiveHint: true,
325
- idempotentHint: false,
326
- openWorldHint: false
327
- },
328
- description: "Applies high-level structural operations to the visual canvas (adding nodes, connecting edges, organizing layout, or moving elements).",
329
- inputSchema: {
330
- type: "object",
331
- properties: {
332
- operation: {
333
- type: "string",
334
- enum: [
335
- "add_node",
336
- "remove_nodes",
337
- "connect",
338
- "update_node",
339
- "layout",
340
- "select",
341
- "highlight"
342
- ],
343
- description: "The canvas operation to execute."
344
- },
345
- node: {
346
- type: "object",
347
- description: "Node definition when operation is add_node. Can omit position to auto-place."
348
- },
349
- nearNodeId: {
350
- type: "string",
351
- description: "Anchor node ID to position beside using collision-aware placement."
352
- },
353
- side: {
354
- type: "string",
355
- enum: ["top", "right", "bottom", "left"],
356
- description: "Side of the anchor node to place the new node beside."
357
- },
358
- nodeIds: {
359
- type: "array",
360
- items: { type: "string" },
361
- description: "Array of node IDs for remove_nodes, select, or highlight."
362
- },
363
- source: {
364
- type: "string",
365
- description: "Source node ID for connect operation."
366
- },
367
- target: {
368
- type: "string",
369
- description: "Target node ID for connect operation."
370
- },
371
- label: {
372
- type: "string",
373
- description: "Optional edge label for connect operation."
374
- },
375
- direction: {
376
- type: "string",
377
- enum: ["LR", "TB", "RL", "BT"],
378
- description: "Layout direction (default LR)."
379
- },
380
- incremental: {
381
- type: "boolean",
382
- description: "Preserve existing node coordinates and blend layout (default true)."
383
- }
384
- },
385
- required: ["operation"]
386
- }
387
- };
388
- var MCP_TOOL_EDIT_PROMPT = {
389
- name: "edit_prompt",
390
- title: "Edit the prompt",
391
- annotations: {
392
- title: "Edit the prompt",
393
- readOnlyHint: false,
394
- destructiveHint: true,
395
- idempotentHint: false,
396
- openWorldHint: false
397
- },
398
- description: "Applies edits to the prompt template document, including inserting text, replacing ranges, and setting variables.",
399
- inputSchema: {
400
- type: "object",
401
- properties: {
402
- operation: {
403
- type: "string",
404
- enum: ["insert_text", "replace_range", "set_variable", "select"],
405
- description: "The prompt operation to execute."
406
- },
407
- text: {
408
- type: "string",
409
- description: "Text to insert or replace."
410
- },
411
- at: {
412
- type: "number",
413
- description: "Position to insert text at."
414
- },
415
- from: {
416
- type: "number",
417
- description: "Start offset for replace_range or select."
418
- },
419
- to: {
420
- type: "number",
421
- description: "End offset for replace_range or select."
422
- },
423
- name: {
424
- type: "string",
425
- description: "Variable name for set_variable."
426
- },
427
- value: {
428
- description: "Variable value for set_variable."
429
- }
430
- },
431
- required: ["operation"]
432
- }
433
- };
434
- var MCP_TOOL_VIEW_EDITOR = {
435
- name: "view_editor",
436
- title: "View the editor",
437
- annotations: {
438
- title: "View the editor",
439
- readOnlyHint: true,
440
- destructiveHint: false,
441
- idempotentHint: true,
442
- openWorldHint: false
443
- },
444
- description: "Captures a visual image snapshot (JPEG or PNG) of the editor canvas or viewport for multimodal evaluation. Active agent cursor indicators are automatically excluded from the snapshot.",
445
- inputSchema: {
446
- type: "object",
447
- properties: {
448
- scope: {
449
- type: "string",
450
- enum: ["viewport", "canvas"],
451
- description: "Whether to capture only the visible viewport or the full canvas bounding box (default: viewport)."
452
- },
453
- format: {
454
- type: "string",
455
- enum: ["jpeg", "png"],
456
- description: "Image format of the base64 snapshot (default: jpeg)."
457
- },
458
- maxEdge: {
459
- type: "integer",
460
- description: "Maximum width or height dimension in pixels (default: 1024)."
461
- }
462
- }
463
- }
464
- };
465
- var EXPORT_EXCLUDED_SELECTORS = [
466
- ".pixerate-presence",
467
- ".agent-presence",
468
- ".ursula-presence"
469
- ];
470
- var EDITOR_MCP_TOOLS = [
471
- MCP_TOOL_GET_EDITOR_STATE,
472
- MCP_TOOL_EDIT_CANVAS,
473
- MCP_TOOL_EDIT_PROMPT,
474
- MCP_TOOL_VIEW_EDITOR
475
- ];
476
-
477
- // src/agent/registry.ts
478
- var ToolRegistryError = class extends Error {
479
- code;
480
- constructor(code, message) {
481
- super(message);
482
- this.name = "ToolRegistryError";
483
- this.code = code;
484
- }
485
- };
486
- var TOOL_NAMESPACE_SEPARATOR = "__";
487
- var TOOL_NAME_REGEX = /^[A-Za-z0-9_.-]{1,128}$/;
488
- var sanitizeNamespace = (id) => id.replace(/[^A-Za-z0-9_-]/g, "_");
489
- function readTools(provider) {
490
- return typeof provider.tools === "function" ? provider.tools() : provider.tools;
491
- }
492
- function toDefinition(name, tool) {
493
- const { handler: _handler, name: _name, ...rest } = tool;
494
- return { name, ...rest };
495
- }
496
- function errorResult(error) {
497
- const details = error.details?.length ? "\n" + error.details.map((d) => `- ${d.path}: ${d.message}`).join("\n") : "";
498
- return {
499
- isError: true,
500
- content: [{ type: "text", text: `${error.message}${details}` }],
501
- structuredContent: { error }
502
- };
503
- }
504
- function toToolResult(value) {
505
- if (value && typeof value === "object" && Array.isArray(value.content)) {
506
- return value;
507
- }
508
- if (value === void 0) return { content: [] };
509
- if (typeof value === "string") return { content: [{ type: "text", text: value }] };
510
- const text = JSON.stringify(value);
511
- const isPlainObject = typeof value === "object" && value !== null && !Array.isArray(value);
512
- return {
513
- content: [{ type: "text", text: text ?? String(value) }],
514
- ...isPlainObject ? { structuredContent: value } : {}
515
- };
516
- }
517
- var ToolRegistry = class {
518
- /** MCP server capabilities this registry supports. */
519
- capabilities = { tools: { listChanged: true } };
520
- entries = [];
521
- listeners = /* @__PURE__ */ new Set();
522
- options;
523
- timer = null;
524
- lastSignature;
525
- constructor(options = {}) {
526
- this.options = {
527
- onCollision: options.onCollision ?? "namespace",
528
- listChangedDelayMs: options.listChangedDelayMs ?? 0,
529
- validateArguments: options.validateArguments ?? true
530
- };
531
- this.lastSignature = this.signature();
532
- }
533
- /**
534
- * Registers a provider and returns a function that unregisters it.
535
- * Throws a {@link ToolRegistryError} for a duplicate provider id, an invalid
536
- * tool name, or (with `onCollision: 'error'`) a tool name collision.
537
- */
538
- register(provider) {
539
- if (this.entries.some((e) => e.provider.id === provider.id)) {
540
- throw new ToolRegistryError("duplicate_provider", `Tool provider "${provider.id}" is already registered.`);
541
- }
542
- for (const tool of readTools(provider)) {
543
- if (!TOOL_NAME_REGEX.test(tool.name)) {
544
- throw new ToolRegistryError("invalid_tool", `Invalid tool name "${tool.name}" from provider "${provider.id}".`);
545
- }
546
- }
547
- const entry = { provider };
548
- this.entries.push(entry);
549
- try {
550
- const names = this.resolve(this.options.onCollision === "error").map((t) => t.name);
551
- const duplicate = names.find((name, i) => names.indexOf(name) !== i);
552
- if (duplicate) {
553
- throw new ToolRegistryError("name_collision", `Tool name "${duplicate}" is exposed more than once.`);
554
- }
555
- } catch (error) {
556
- this.entries.pop();
557
- throw error;
558
- }
559
- if (provider.subscribe) {
560
- entry.unsubscribe = provider.subscribe(() => this.notifyListChanged());
561
- }
562
- this.notifyListChanged();
563
- let registered = true;
564
- return () => {
565
- if (!registered) return;
566
- registered = false;
567
- this.unregister(provider);
568
- };
569
- }
570
- /** Removes a provider by id or instance. Returns whether it was registered. */
571
- unregister(providerOrId) {
572
- const index = this.entries.findIndex(
573
- (e) => typeof providerOrId === "string" ? e.provider.id === providerOrId : e.provider === providerOrId
574
- );
575
- if (index === -1) return false;
576
- const [entry] = this.entries.splice(index, 1);
577
- entry.unsubscribe?.();
578
- this.notifyListChanged();
579
- return true;
580
- }
581
- /** Registered provider ids in registration order. */
582
- providerIds() {
583
- return this.entries.map((e) => e.provider.id);
584
- }
585
- /**
586
- * Resolves exposed names. Tools are ordered by provider registration, then
587
- * by their order within the provider.
588
- */
589
- resolve(throwOnCollision = false) {
590
- const all = [];
591
- const counts = /* @__PURE__ */ new Map();
592
- for (const { provider } of this.entries) {
593
- for (const tool of readTools(provider)) {
594
- all.push({ name: tool.name, tool, provider });
595
- if (!provider.namespace) counts.set(tool.name, (counts.get(tool.name) ?? 0) + 1);
596
- }
597
- }
598
- for (const item of all) {
599
- const prefix = item.provider.namespace ?? ((counts.get(item.name) ?? 0) > 1 ? item.provider.id : void 0);
600
- if (prefix !== void 0) {
601
- if (throwOnCollision && !item.provider.namespace) {
602
- throw new ToolRegistryError(
603
- "name_collision",
604
- `Tool "${item.name}" from provider "${item.provider.id}" collides with another provider's tool.`
605
- );
606
- }
607
- item.name = `${sanitizeNamespace(prefix)}${TOOL_NAMESPACE_SEPARATOR}${item.name}`;
608
- }
609
- }
610
- return all;
611
- }
612
- /** MCP `tools/list` result for the current providers. */
613
- listTools() {
614
- return { tools: this.resolve().map(({ name, tool }) => toDefinition(name, tool)) };
615
- }
616
- /** Whether a tool with this exposed name exists. */
617
- hasTool(name) {
618
- return this.resolve().some((t) => t.name === name);
619
- }
620
- /** Looks up a tool definition by exposed name. */
621
- getTool(name) {
622
- const found = this.resolve().find((t) => t.name === name);
623
- return found ? toDefinition(found.name, found.tool) : void 0;
624
- }
625
- /**
626
- * Calls a tool by exposed name and returns an MCP `tools/call` result.
627
- * Never rejects: unknown tools, invalid arguments and handler errors come
628
- * back as `isError: true` results with a {@link ToolCallError} in
629
- * `structuredContent.error` (MCP transports may map `unknown_tool` to a
630
- * JSON-RPC `-32602` error instead).
631
- */
632
- async callTool(name, args = {}, options = {}) {
633
- const found = this.resolve().find((t) => t.name === name);
634
- if (!found) {
635
- return errorResult({ code: "unknown_tool", message: `Unknown tool "${name}".`, tool: name });
636
- }
637
- const input = args ?? {};
638
- if (this.options.validateArguments) {
639
- const details = validateJsonSchema(input, found.tool.inputSchema);
640
- if (details.length > 0) {
641
- return errorResult({
642
- code: "invalid_arguments",
643
- message: `Invalid arguments for tool "${name}".`,
644
- tool: name,
645
- details
646
- });
647
- }
648
- }
649
- try {
650
- const value = await found.tool.handler(input, {
651
- name,
652
- providerId: found.provider.id,
653
- signal: options.signal
654
- });
655
- return toToolResult(value);
656
- } catch (error) {
657
- return errorResult({
658
- code: "tool_failed",
659
- message: error instanceof Error ? error.message : String(error),
660
- tool: name
661
- });
662
- }
663
- }
664
- /**
665
- * Subscribes to tool-list changes. Notifications are coalesced: many
666
- * registrations or provider signals within the delay window produce one
667
- * call, and none if the exposed list ends up unchanged (e.g. a provider
668
- * unmounted and remounted). Returns an unsubscribe function.
669
- */
670
- onListChanged(listener) {
671
- this.listeners.add(listener);
672
- return () => {
673
- this.listeners.delete(listener);
674
- };
675
- }
676
- /** Schedules a coalesced `listChanged` check; providers may call it directly. */
677
- notifyListChanged() {
678
- if (this.timer !== null) return;
679
- this.timer = setTimeout(() => this.flush(), this.options.listChangedDelayMs);
680
- }
681
- /** Runs a pending `listChanged` check immediately. */
682
- flush() {
683
- if (this.timer !== null) {
684
- clearTimeout(this.timer);
685
- this.timer = null;
686
- }
687
- const signature = this.signature();
688
- if (signature === this.lastSignature) return;
689
- this.lastSignature = signature;
690
- const { tools } = this.listTools();
691
- for (const listener of Array.from(this.listeners)) listener(tools);
692
- }
693
- signature() {
694
- try {
695
- return JSON.stringify(this.listTools().tools);
696
- } catch {
697
- return String(Math.random());
698
- }
699
- }
700
- /** Unregisters every provider and listener and cancels pending notifications. */
701
- dispose() {
702
- if (this.timer !== null) clearTimeout(this.timer);
703
- this.timer = null;
704
- for (const entry of this.entries.splice(0)) entry.unsubscribe?.();
705
- this.listeners.clear();
706
- }
707
- };
708
- function createToolRegistry(options) {
709
- return new ToolRegistry(options);
710
- }
711
-
712
305
  // src/agent/providers.ts
713
306
  import { TextSelection } from "@tiptap/pm/state";
714
307
  var toEditor = (target) => "commands" in target ? target : target.editor;