@pixerate/editor 0.19.0 → 0.21.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 (112) hide show
  1. package/README.md +95 -4
  2. package/dist/agent/index.cjs +625 -2
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +286 -2
  5. package/dist/agent/index.d.ts +286 -2
  6. package/dist/agent/index.js +624 -1
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/canvas/index.cjs +1240 -22
  9. package/dist/canvas/index.cjs.map +1 -1
  10. package/dist/canvas/index.d.cts +515 -3
  11. package/dist/canvas/index.d.ts +515 -3
  12. package/dist/canvas/index.js +1219 -1
  13. package/dist/canvas/index.js.map +1 -1
  14. package/dist/chunk-3TYMNULT.js +1367 -0
  15. package/dist/chunk-3TYMNULT.js.map +1 -0
  16. package/dist/chunk-4QPLEUL2.cjs +4480 -0
  17. package/dist/chunk-4QPLEUL2.cjs.map +1 -0
  18. package/dist/chunk-4SUNJZWB.cjs +553 -0
  19. package/dist/chunk-4SUNJZWB.cjs.map +1 -0
  20. package/dist/chunk-A7DKIA72.js +2657 -0
  21. package/dist/chunk-A7DKIA72.js.map +1 -0
  22. package/dist/chunk-AXV2ZW34.cjs +118 -0
  23. package/dist/chunk-AXV2ZW34.cjs.map +1 -0
  24. package/dist/chunk-B2ZRLN4S.js +118 -0
  25. package/dist/chunk-B2ZRLN4S.js.map +1 -0
  26. package/dist/chunk-CYFJCKC4.js +4480 -0
  27. package/dist/chunk-CYFJCKC4.js.map +1 -0
  28. package/dist/chunk-GVW4P7BG.js +2706 -0
  29. package/dist/chunk-GVW4P7BG.js.map +1 -0
  30. package/dist/chunk-JACER6TE.cjs +1 -0
  31. package/dist/chunk-JACER6TE.cjs.map +1 -0
  32. package/dist/chunk-JYRIOFEN.cjs +2657 -0
  33. package/dist/chunk-JYRIOFEN.cjs.map +1 -0
  34. package/dist/chunk-KYRZDWM4.js +299 -0
  35. package/dist/chunk-KYRZDWM4.js.map +1 -0
  36. package/dist/chunk-LA7PEGU3.cjs +299 -0
  37. package/dist/chunk-LA7PEGU3.cjs.map +1 -0
  38. package/dist/chunk-N7FG6CBO.js +1 -0
  39. package/dist/chunk-N7FG6CBO.js.map +1 -0
  40. package/dist/chunk-OYXSKQFR.js +553 -0
  41. package/dist/chunk-OYXSKQFR.js.map +1 -0
  42. package/dist/chunk-TVRC4KVT.cjs +1367 -0
  43. package/dist/chunk-TVRC4KVT.cjs.map +1 -0
  44. package/dist/chunk-U6NDQFOK.cjs +2706 -0
  45. package/dist/chunk-U6NDQFOK.cjs.map +1 -0
  46. package/dist/controller-OUdxPY-X.d.cts +754 -0
  47. package/dist/controller-OUdxPY-X.d.ts +754 -0
  48. package/dist/extensions/index.cjs +144 -3
  49. package/dist/extensions/index.cjs.map +1 -1
  50. package/dist/extensions/index.d.cts +9 -144
  51. package/dist/extensions/index.d.ts +9 -144
  52. package/dist/extensions/index.js +145 -4
  53. package/dist/grammar/index.cjs +31 -3
  54. package/dist/grammar/index.cjs.map +1 -1
  55. package/dist/grammar/index.d.cts +239 -19
  56. package/dist/grammar/index.d.ts +239 -19
  57. package/dist/grammar/index.js +31 -3
  58. package/dist/history/index.d.cts +2 -41
  59. package/dist/history/index.d.ts +2 -41
  60. package/dist/index-Ng1pG7JE.d.ts +899 -0
  61. package/dist/index-k3mFbPx_.d.cts +899 -0
  62. package/dist/index.cjs +457 -20
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +99 -12
  65. package/dist/index.d.ts +99 -12
  66. package/dist/index.js +457 -20
  67. package/dist/index.js.map +1 -1
  68. package/dist/registry-iAHbqkYt.d.cts +128 -0
  69. package/dist/registry-iAHbqkYt.d.ts +128 -0
  70. package/dist/serializers/index.cjs +26 -3
  71. package/dist/serializers/index.cjs.map +1 -1
  72. package/dist/serializers/index.d.cts +119 -6
  73. package/dist/serializers/index.d.ts +119 -6
  74. package/dist/serializers/index.js +24 -1
  75. package/dist/spreadsheet/index.cjs +122 -2
  76. package/dist/spreadsheet/index.cjs.map +1 -1
  77. package/dist/spreadsheet/index.d.cts +371 -313
  78. package/dist/spreadsheet/index.d.ts +371 -313
  79. package/dist/spreadsheet/index.js +127 -7
  80. package/dist/tokens-CyLZmIei.d.cts +76 -0
  81. package/dist/tokens-CyLZmIei.d.ts +76 -0
  82. package/dist/track-changes-G8JcWB8b.d.cts +306 -0
  83. package/dist/track-changes-G8JcWB8b.d.ts +306 -0
  84. package/dist/types-BZgcDsC5.d.cts +42 -0
  85. package/dist/types-BZgcDsC5.d.ts +42 -0
  86. package/dist/{types-JV3S8VeR.d.cts → types-DMe0vFB1.d.cts} +1 -1
  87. package/dist/{types-JV3S8VeR.d.ts → types-DMe0vFB1.d.ts} +1 -1
  88. package/package.json +11 -4
  89. package/dist/chunk-7FWEWE6T.js +0 -1888
  90. package/dist/chunk-7FWEWE6T.js.map +0 -1
  91. package/dist/chunk-AIZUKWTL.js +0 -1715
  92. package/dist/chunk-AIZUKWTL.js.map +0 -1
  93. package/dist/chunk-GLSIZKOX.js +0 -17
  94. package/dist/chunk-GLSIZKOX.js.map +0 -1
  95. package/dist/chunk-LDES3EOS.cjs +0 -1888
  96. package/dist/chunk-LDES3EOS.cjs.map +0 -1
  97. package/dist/chunk-LLUAKTLW.cjs +0 -532
  98. package/dist/chunk-LLUAKTLW.cjs.map +0 -1
  99. package/dist/chunk-MPPXH7U5.cjs +0 -336
  100. package/dist/chunk-MPPXH7U5.cjs.map +0 -1
  101. package/dist/chunk-O7LOPQMH.js +0 -336
  102. package/dist/chunk-O7LOPQMH.js.map +0 -1
  103. package/dist/chunk-QGVMBCT5.js +0 -532
  104. package/dist/chunk-QGVMBCT5.js.map +0 -1
  105. package/dist/chunk-SEDR75VH.cjs +0 -17
  106. package/dist/chunk-SEDR75VH.cjs.map +0 -1
  107. package/dist/chunk-YQCI4CCN.cjs +0 -1715
  108. package/dist/chunk-YQCI4CCN.cjs.map +0 -1
  109. package/dist/mention-Dcevh3ff.d.cts +0 -32
  110. package/dist/mention-Dcevh3ff.d.ts +0 -32
  111. package/dist/tokens-7kRTEtPb.d.cts +0 -39
  112. package/dist/tokens-7kRTEtPb.d.ts +0 -39
@@ -1,4 +1,6 @@
1
- import { C as CanvasNode, a as CanvasEdge, X as XYPosition, S as Side } from '../types-JV3S8VeR.js';
1
+ import { C as CanvasNode, a as CanvasEdge, X as XYPosition, S as Side } from '../types-DMe0vFB1.js';
2
+ import { Editor } from '@tiptap/core';
3
+ import { W as SpreadsheetController } from '../controller-OUdxPY-X.js';
2
4
 
3
5
  /**
4
6
  * Agent presence state for visual multiplayer/agent choreography.
@@ -93,6 +95,11 @@ type AgentCommand<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdg
93
95
  } | {
94
96
  type: 'choreography:wait';
95
97
  ms: number;
98
+ } | {
99
+ type: 'tool:call';
100
+ /** Exposed tool name in a `ToolRegistry`. */
101
+ name: string;
102
+ arguments?: Record<string, unknown>;
96
103
  };
97
104
  /**
98
105
  * Atomic execution steps returned by the planner.
@@ -146,6 +153,11 @@ type AgentStep<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge =
146
153
  } | {
147
154
  type: 'step:wait';
148
155
  ms: number;
156
+ } | {
157
+ /** Execute with `ToolRegistry.callTool(name, arguments)`. */
158
+ type: 'step:tool_call';
159
+ name: string;
160
+ arguments: Record<string, unknown>;
149
161
  };
150
162
 
151
163
  /**
@@ -163,6 +175,20 @@ declare function planAgentCommand<TNode extends CanvasNode = CanvasNode, TEdge e
163
175
  };
164
176
  idGenerator?: () => string;
165
177
  }): AgentStep<TNode, TEdge>[];
178
+ /**
179
+ * Converts an MCP tool call into a planner command. `edit_canvas` and
180
+ * `edit_prompt` (see `tools.ts`) map to canvas/prompt commands using the MCP
181
+ * schema's vocabulary; every other tool, including dynamic `ToolRegistry`
182
+ * tools, becomes a `tool:call` command. Returns `null` when a static tool's
183
+ * arguments are missing what the operation needs.
184
+ */
185
+ declare function toolCallToAgentCommand<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(name: string, args?: Record<string, any>): AgentCommand<TNode, TEdge> | null;
186
+ /**
187
+ * Plans the steps for an MCP tool call: static editor tools are planned like
188
+ * the equivalent commands, any other tool becomes a `step:tool_call` to be
189
+ * executed with `ToolRegistry.callTool`. Returns `[]` for invalid arguments.
190
+ */
191
+ declare function planToolCall<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(name: string, args: Record<string, any>, snapshot: EditorSnapshot<TNode, TEdge>, options?: Parameters<typeof planAgentCommand>[2]): AgentStep<TNode, TEdge>[];
166
192
 
167
193
  /**
168
194
  * Standard MCP Tool Definitions for @pixerate/editor.
@@ -439,4 +465,262 @@ declare const EDITOR_MCP_TOOLS: readonly [{
439
465
  };
440
466
  }];
441
467
 
442
- export { type AgentCommand, type AgentPresence, type AgentStep, EDITOR_MCP_TOOLS, EXPORT_EXCLUDED_SELECTORS, type EditorSnapshot, MCP_TOOL_EDIT_CANVAS, MCP_TOOL_EDIT_PROMPT, MCP_TOOL_GET_EDITOR_STATE, MCP_TOOL_VIEW_EDITOR, normalizeSide, planAgentCommand };
468
+ /**
469
+ * JSON-Schema-lite: the subset of JSON Schema used by MCP tool `inputSchema`s,
470
+ * plus a small validator for tool-call arguments. Unknown keywords are ignored.
471
+ */
472
+ type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
473
+ interface JsonSchema {
474
+ type?: JsonSchemaType | readonly JsonSchemaType[];
475
+ description?: string;
476
+ title?: string;
477
+ enum?: readonly unknown[];
478
+ const?: unknown;
479
+ default?: unknown;
480
+ properties?: {
481
+ readonly [key: string]: JsonSchema;
482
+ };
483
+ required?: readonly string[];
484
+ additionalProperties?: boolean | JsonSchema;
485
+ items?: JsonSchema;
486
+ minItems?: number;
487
+ maxItems?: number;
488
+ minimum?: number;
489
+ maximum?: number;
490
+ minLength?: number;
491
+ maxLength?: number;
492
+ pattern?: string;
493
+ [keyword: string]: unknown;
494
+ }
495
+ interface SchemaValidationError {
496
+ /** JSON-pointer-like path to the offending value, e.g. `/node/id` (`""` is the root). */
497
+ path: string;
498
+ message: string;
499
+ }
500
+ /**
501
+ * Validates `value` against `schema` and returns every error found (an empty
502
+ * array means valid). Supports `type` (incl. arrays of types), `enum`, `const`,
503
+ * `properties`, `required`, `additionalProperties`, `items`, `minItems`,
504
+ * `maxItems`, `minimum`, `maximum`, `minLength`, `maxLength` and `pattern`.
505
+ */
506
+ declare function validateJsonSchema(value: unknown, schema: JsonSchema | undefined, path?: string): SchemaValidationError[];
507
+
508
+ /**
509
+ * MCP-shaped tool definition, as returned by `tools/list`.
510
+ */
511
+ interface McpToolDefinition {
512
+ name: string;
513
+ title?: string;
514
+ description?: string;
515
+ inputSchema: JsonSchema & {
516
+ type: 'object';
517
+ };
518
+ outputSchema?: JsonSchema;
519
+ annotations?: {
520
+ title?: string;
521
+ readOnlyHint?: boolean;
522
+ destructiveHint?: boolean;
523
+ idempotentHint?: boolean;
524
+ openWorldHint?: boolean;
525
+ [key: string]: unknown;
526
+ };
527
+ }
528
+ type McpToolContent = {
529
+ type: 'text';
530
+ text: string;
531
+ } | {
532
+ type: 'image';
533
+ data: string;
534
+ mimeType: string;
535
+ } | {
536
+ type: string;
537
+ [key: string]: unknown;
538
+ };
539
+ /** MCP `tools/call` result. */
540
+ interface McpToolResult {
541
+ content: McpToolContent[];
542
+ structuredContent?: Record<string, unknown>;
543
+ isError?: boolean;
544
+ }
545
+ /** MCP `tools/list` result. */
546
+ interface McpListToolsResult {
547
+ tools: McpToolDefinition[];
548
+ }
549
+ interface ToolCallContext {
550
+ /** Name the tool was called by (possibly namespaced). */
551
+ name: string;
552
+ /** Id of the provider that owns the tool. */
553
+ providerId: string;
554
+ signal?: AbortSignal;
555
+ }
556
+ /**
557
+ * Handler return values are normalized into an {@link McpToolResult}: a full
558
+ * result (`{ content: [...] }`) is passed through, a string becomes a text
559
+ * block, `undefined` becomes an empty result, and anything else is returned
560
+ * as `structuredContent` (plain objects) plus a JSON text block.
561
+ */
562
+ type AgentToolHandler = (args: Record<string, any>, context: ToolCallContext) => unknown | Promise<unknown>;
563
+ interface AgentTool extends McpToolDefinition {
564
+ handler: AgentToolHandler;
565
+ }
566
+ /**
567
+ * A source of tools, typically one per mounted editor, spreadsheet or canvas.
568
+ */
569
+ interface AgentToolProvider {
570
+ /** Unique id within a registry, e.g. `doc-1`. Used as the namespace on collisions. */
571
+ id: string;
572
+ /** Always prefix this provider's tools with `<namespace>__`. */
573
+ namespace?: string;
574
+ /** Tools, or a function returning the current tools (re-read on every `listTools`). */
575
+ tools: readonly AgentTool[] | (() => readonly AgentTool[]);
576
+ /** Lets the provider signal that its tool list changed; returns an unsubscribe function. */
577
+ subscribe?: (notify: () => void) => () => void;
578
+ }
579
+ type ToolErrorCode = 'unknown_tool' | 'invalid_arguments' | 'tool_failed';
580
+ /** Structured error carried in `structuredContent.error` of a failed call. */
581
+ interface ToolCallError {
582
+ code: ToolErrorCode;
583
+ message: string;
584
+ tool: string;
585
+ details?: SchemaValidationError[];
586
+ }
587
+ declare class ToolRegistryError extends Error {
588
+ readonly code: 'duplicate_provider' | 'name_collision' | 'invalid_tool';
589
+ constructor(code: ToolRegistryError['code'], message: string);
590
+ }
591
+ interface ToolRegistryOptions {
592
+ /**
593
+ * What to do when two providers contribute the same tool name:
594
+ * `namespace` (default) exposes every colliding tool as `<providerId>__<name>`;
595
+ * `error` makes `register` throw.
596
+ */
597
+ onCollision?: 'namespace' | 'error';
598
+ /** Coalescing window for `listChanged` notifications in ms (default 0: same tick). */
599
+ listChangedDelayMs?: number;
600
+ /** Validate arguments against `inputSchema` before calling handlers (default `true`). */
601
+ validateArguments?: boolean;
602
+ }
603
+ /** Separator between namespace and tool name; valid in MCP and LLM tool-name charsets. */
604
+ declare const TOOL_NAMESPACE_SEPARATOR = "__";
605
+ /** Normalizes a handler's return value into an MCP `tools/call` result. */
606
+ declare function toToolResult(value: unknown): McpToolResult;
607
+ /**
608
+ * Transport-agnostic registry of agent tools contributed by live providers.
609
+ *
610
+ * `listTools()` and `callTool()` return MCP `tools/list` / `tools/call`
611
+ * result shapes, and `onListChanged` fires (coalesced) whenever the exposed
612
+ * tool list changes, mirroring MCP's `notifications/tools/list_changed`, so an
613
+ * MCP server can be a thin wrapper around it.
614
+ */
615
+ declare class ToolRegistry {
616
+ /** MCP server capabilities this registry supports. */
617
+ readonly capabilities: {
618
+ readonly tools: {
619
+ readonly listChanged: true;
620
+ };
621
+ };
622
+ private readonly entries;
623
+ private readonly listeners;
624
+ private readonly options;
625
+ private timer;
626
+ private lastSignature;
627
+ constructor(options?: ToolRegistryOptions);
628
+ /**
629
+ * Registers a provider and returns a function that unregisters it.
630
+ * Throws a {@link ToolRegistryError} for a duplicate provider id, an invalid
631
+ * tool name, or (with `onCollision: 'error'`) a tool name collision.
632
+ */
633
+ register(provider: AgentToolProvider): () => void;
634
+ /** Removes a provider by id or instance. Returns whether it was registered. */
635
+ unregister(providerOrId: string | AgentToolProvider): boolean;
636
+ /** Registered provider ids in registration order. */
637
+ providerIds(): string[];
638
+ /**
639
+ * Resolves exposed names. Tools are ordered by provider registration, then
640
+ * by their order within the provider.
641
+ */
642
+ private resolve;
643
+ /** MCP `tools/list` result for the current providers. */
644
+ listTools(): McpListToolsResult;
645
+ /** Whether a tool with this exposed name exists. */
646
+ hasTool(name: string): boolean;
647
+ /** Looks up a tool definition by exposed name. */
648
+ getTool(name: string): McpToolDefinition | undefined;
649
+ /**
650
+ * Calls a tool by exposed name and returns an MCP `tools/call` result.
651
+ * Never rejects: unknown tools, invalid arguments and handler errors come
652
+ * back as `isError: true` results with a {@link ToolCallError} in
653
+ * `structuredContent.error` (MCP transports may map `unknown_tool` to a
654
+ * JSON-RPC `-32602` error instead).
655
+ */
656
+ callTool(name: string, args?: Record<string, unknown>, options?: {
657
+ signal?: AbortSignal;
658
+ }): Promise<McpToolResult>;
659
+ /**
660
+ * Subscribes to tool-list changes. Notifications are coalesced: many
661
+ * registrations or provider signals within the delay window produce one
662
+ * call, and none if the exposed list ends up unchanged (e.g. a provider
663
+ * unmounted and remounted). Returns an unsubscribe function.
664
+ */
665
+ onListChanged(listener: (tools: McpToolDefinition[]) => void): () => void;
666
+ /** Schedules a coalesced `listChanged` check; providers may call it directly. */
667
+ notifyListChanged(): void;
668
+ /** Runs a pending `listChanged` check immediately. */
669
+ flush(): void;
670
+ private signature;
671
+ /** Unregisters every provider and listener and cancels pending notifications. */
672
+ dispose(): void;
673
+ }
674
+ declare function createToolRegistry(options?: ToolRegistryOptions): ToolRegistry;
675
+
676
+ interface ToolProviderOptions {
677
+ /** Provider id (unique per registry). */
678
+ id: string;
679
+ /** Always prefix tool names with `<namespace>__`. */
680
+ namespace?: string;
681
+ }
682
+ /** A TipTap editor, or anything exposing one as `.editor` (e.g. `EditorController`). */
683
+ type RichTextToolTarget = Editor | {
684
+ editor: Editor;
685
+ };
686
+ /**
687
+ * Tools for a mounted rich-text editor: `get_text` (always), plus
688
+ * `insert_text` and `replace_selection` while the editor is editable.
689
+ * Positions are ProseMirror document positions (as in `selection.from`).
690
+ * The provider re-announces its tool list when editability changes and
691
+ * exposes no tools once the editor is destroyed.
692
+ */
693
+ declare function createRichTextToolProvider(target: RichTextToolTarget, options: ToolProviderOptions): AgentToolProvider;
694
+ /**
695
+ * Tools for a spreadsheet controller: `get_range` (A1 notation, values and raw
696
+ * input) and `set_cell` (raw input; values starting with `=` are formulas).
697
+ */
698
+ declare function createSpreadsheetToolProvider(controller: SpreadsheetController, options: ToolProviderOptions): AgentToolProvider;
699
+ interface EditorMcpToolProviderOptions<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge> extends ToolProviderOptions {
700
+ /** Current editor / canvas state. */
701
+ getSnapshot: () => EditorSnapshot<TNode, TEdge>;
702
+ /** Applies planned steps (e.g. via your canvas runes / editor controller). */
703
+ applySteps: (steps: AgentStep<TNode, TEdge>[]) => void | Promise<void>;
704
+ /** Optional `view_editor` implementation; the tool is only exposed when provided. */
705
+ captureView?: (args: {
706
+ scope?: 'viewport' | 'canvas';
707
+ format?: 'jpeg' | 'png';
708
+ maxEdge?: number;
709
+ }) => Promise<{
710
+ data: string;
711
+ mimeType: string;
712
+ }> | {
713
+ data: string;
714
+ mimeType: string;
715
+ };
716
+ /** Options forwarded to the planner. */
717
+ plannerOptions?: Parameters<typeof planToolCall>[3];
718
+ }
719
+ /**
720
+ * Exposes the static MCP tools from `tools.ts` (`get_editor_state`,
721
+ * `edit_canvas`, `edit_prompt`, `view_editor`) through a `ToolRegistry`,
722
+ * planning edits with `planToolCall` and handing the steps to `applySteps`.
723
+ */
724
+ declare function createEditorMcpToolProvider<TNode extends CanvasNode = CanvasNode, TEdge extends CanvasEdge = CanvasEdge>(options: EditorMcpToolProviderOptions<TNode, TEdge>): AgentToolProvider;
725
+
726
+ export { type AgentCommand, type AgentPresence, type AgentStep, type AgentTool, type AgentToolHandler, type AgentToolProvider, EDITOR_MCP_TOOLS, EXPORT_EXCLUDED_SELECTORS, type EditorMcpToolProviderOptions, type EditorSnapshot, type JsonSchema, type JsonSchemaType, MCP_TOOL_EDIT_CANVAS, MCP_TOOL_EDIT_PROMPT, MCP_TOOL_GET_EDITOR_STATE, MCP_TOOL_VIEW_EDITOR, type McpListToolsResult, type McpToolContent, type McpToolDefinition, type McpToolResult, type RichTextToolTarget, type SchemaValidationError, TOOL_NAMESPACE_SEPARATOR, type ToolCallContext, type ToolCallError, type ToolErrorCode, type ToolProviderOptions, ToolRegistry, ToolRegistryError, type ToolRegistryOptions, createEditorMcpToolProvider, createRichTextToolProvider, createSpreadsheetToolProvider, createToolRegistry, normalizeSide, planAgentCommand, planToolCall, toToolResult, toolCallToAgentCommand, validateJsonSchema };