@xnetjs/plugins 0.12.0 → 2.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.
@@ -1,6 +1,7 @@
1
1
  import { NodeQueryDescriptor, NodeQueryResult } from '@xnetjs/data';
2
2
  import { PublicWriteBudgetPolicy, AbuseSurface, AISignalProvenanceInput } from '@xnetjs/abuse';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
+ import * as Y from 'yjs';
4
5
 
5
6
  /**
6
7
  * AI surface contract types for xNet resources, tools, mutation plans, and audit events.
@@ -234,7 +235,12 @@ type AiPageMarkdownApplyAdapterInput = {
234
235
  operation: AiOperation;
235
236
  };
236
237
  type AiPageMarkdownApplyAdapterResult = {
237
- mode: 'tiptap-yjs' | 'yjs' | 'custom';
238
+ /**
239
+ * `blocknote-yjs` = applied into the BlockNote `content-v4` fragment
240
+ * (see `createBlockNotePageMarkdownAdapter`); `yjs` = another Yjs-backed
241
+ * document shape; `custom` = host-specific.
242
+ */
243
+ mode: 'blocknote-yjs' | 'yjs' | 'custom';
238
244
  yjsField?: string;
239
245
  documentUpdate?: unknown;
240
246
  warnings?: string[];
@@ -246,7 +252,7 @@ type AiPageMarkdownApplyResult = {
246
252
  applied: boolean;
247
253
  pageId: string;
248
254
  planId: string;
249
- mode: 'tiptap-yjs' | 'yjs' | 'custom' | 'node-property';
255
+ mode: 'blocknote-yjs' | 'yjs' | 'custom' | 'node-property';
250
256
  baseRevision: string;
251
257
  liveRevision: string;
252
258
  markdownHash: string;
@@ -522,6 +528,77 @@ declare function stripXNetPageFrontmatter(markdown: string): string;
522
528
  declare function renderMarkdownLineDiff(before: string, after: string): string;
523
529
  declare function renderMarkdownReviewDiff(before: string, after: string): XNetMarkdownReviewDiff;
524
530
 
531
+ /**
532
+ * Yjs-fragment ↔ markdown conversion for AI page projections (0312).
533
+ *
534
+ * v4 pages persist BlockNote's ProseMirror schema in the Y.XmlFragment
535
+ * `content-v4`: the fragment holds one `blockGroup`, each block is a
536
+ * `blockContainer` (with a unique `id` attribute) wrapping one blockContent
537
+ * element (paragraph/heading/…) plus an optional nested `blockGroup` of
538
+ * child blocks. v3 and earlier documents live in the legacy `content`
539
+ * fragment (TipTap schema) and are read-only here.
540
+ *
541
+ * Both directions walk the Yjs XML tree directly — no editor, DOM, or
542
+ * BlockNote dependency — mirroring the dependency-light approach of the
543
+ * editor package's lazy legacy importer. The write path covers the markdown
544
+ * subset AI agents emit (paragraphs, headings, bullet/numbered/check lists,
545
+ * fenced code, quotes, callouts, wikilinks); reading is broader and degrades
546
+ * unknown blocks to text, like the legacy importer.
547
+ */
548
+
549
+ /** The Y.XmlFragment field that holds v4 (BlockNote) page documents. */
550
+ declare const XNET_PAGE_FRAGMENT_FIELD = "content-v4";
551
+ /** The legacy (TipTap, v3 and below) fragment field, read as a fallback. */
552
+ declare const XNET_PAGE_LEGACY_FRAGMENT_FIELD = "content";
553
+ type XNetPageFragmentReadOptions = {
554
+ /** BlockNote fragment field. Defaults to `content-v4`. */
555
+ field?: string;
556
+ /** Legacy TipTap fragment field read when the v4 fragment is empty. */
557
+ legacyField?: string;
558
+ };
559
+ /** Convert a BlockNote (`content-v4`) fragment to markdown. */
560
+ declare function blockNoteFragmentToMarkdown(fragment: Y.XmlFragment): string;
561
+ /** Convert a legacy TipTap (`content`) fragment to markdown (lossy). */
562
+ declare function legacyFragmentToMarkdown(fragment: Y.XmlFragment): string;
563
+ /**
564
+ * Read a page Y.Doc as markdown: the BlockNote `content-v4` fragment when it
565
+ * has content, otherwise the legacy TipTap `content` fragment.
566
+ */
567
+ declare function xnetPageFragmentToMarkdown(doc: Y.Doc, options?: XNetPageFragmentReadOptions): string;
568
+ type XNetPageFragmentWriteOptions = {
569
+ /** BlockNote fragment field. Defaults to `content-v4`. */
570
+ field?: string;
571
+ /** Block id factory (BlockNote requires a unique `id` per blockContainer). */
572
+ generateBlockId?: () => string;
573
+ };
574
+ /**
575
+ * Replace a page's BlockNote fragment with the given markdown (the AI apply
576
+ * path). Runs in a single Yjs transaction; every blockContainer gets a fresh
577
+ * unique id. Covers the AI markdown subset: paragraphs, headings,
578
+ * bullet/numbered/check lists (2-space nesting), fenced code, quotes,
579
+ * `> [!kind]` callouts, and `[[wikilinks]]`. Anything else lands as
580
+ * paragraph text — never dropped.
581
+ */
582
+ declare function replaceXNetPageFragmentWithMarkdown(doc: Y.Doc, markdown: string, options?: XNetPageFragmentWriteOptions): void;
583
+ /** Resolves the live (or loaded) Y.Doc for a page node id. */
584
+ type XNetPageDocResolver = (pageId: string) => Promise<Y.Doc | null> | Y.Doc | null;
585
+ type BlockNotePageMarkdownAdapterOptions = {
586
+ resolveDoc: XNetPageDocResolver;
587
+ /** BlockNote fragment field. Defaults to `content-v4`. */
588
+ field?: string;
589
+ generateBlockId?: () => string;
590
+ };
591
+ /**
592
+ * The BlockNote/Yjs `AiPageMarkdownApplyAdapter` (replaces the TipTap-era
593
+ * document bridge): applies validated AI markdown plans into the page's
594
+ * `content-v4` fragment, and reads pages back out of it. Hosts wire
595
+ * `resolveDoc` to their document store; without an adapter the AI surface
596
+ * falls back to the `markdown` node property.
597
+ */
598
+ declare function createBlockNotePageMarkdownAdapter(options: BlockNotePageMarkdownAdapterOptions): AiPageMarkdownApplyAdapter & {
599
+ readMarkdown: (pageId: string) => Promise<string | null>;
600
+ };
601
+
525
602
  /**
526
603
  * Local HTTP API Server
527
604
  *
@@ -1798,4 +1875,4 @@ declare const SERVICE_IPC_CHANNELS: {
1798
1875
  readonly OUTPUT: "xnet:service:output";
1799
1876
  };
1800
1877
 
1801
- export { AI_RISK_LEVELS, AI_SCOPES, AI_TARGET_KINDS, type AgentApi, type AgentScriptContext, type AgentScriptSession, type AgentSearchResult, type AgentWriteProposal, type AiAuditEvent, type AiChangeSet, type AiContextPack, type AiContextPackResource, type AiContextSeed, type AiJsonSchema, type AiJsonSchemaType, type AiMutationPlan, type AiMutationPlanStatus, type AiOperation, type AiPageMarkdownApplyAdapter, type AiPageMarkdownApplyAdapterInput, type AiPageMarkdownApplyAdapterResult, type AiPageMarkdownApplyResult, type AiPageMarkdownRollbackResult, type AiResource, type AiResourceContent, type AiRiskLevel, type AiScope, type AiSearchOptions, type AiSearchResult, type AiSurfaceLimits, AiSurfaceService, type AiSurfaceServiceConfig, type AiTargetKind, type AiToolCallResult, type AiToolDefinition, type AiValidationResult, type AiWorkspaceChangedFile, type AiWorkspaceChangedFileStatus, type AiWorkspaceCheckoutOptions, type AiWorkspaceConflict, type AiWorkspaceConflictKind, type AiWorkspaceExportKind, type AiWorkspaceExportOptions, type AiWorkspaceExportResult, type AiWorkspaceExportScope, AiWorkspaceExporter, type AiWorkspaceExporterConfig, type AiWorkspaceManifestEntry, type AiWorkspacePendingPlan, type AiWorkspaceReviewAction, type AiWorkspaceReviewEntry, type AiWorkspaceReviewEntryKind, type AiWorkspaceReviewIndex, type AiWorkspaceReviewStatus, type AiWorkspaceWatchHandle, type AiWorkspaceWatchOptions, AiWorkspaceWatcher, type AiWorkspaceWatcherScanOptions, type AiWorkspaceWatcherScanResult, type CreateAgentScriptContextInput, type FlatNode, type IProcessManager, type LocalAPIConfig, LocalAPIServer, type LocalAPITokenConfig, type LocalAPITokenScope, type LocalAPITokenSummary, type MCPPropertySchema, type MCPRequest, type MCPResource, type MCPResponse, MCPServer, type MCPServerConfig, type MCPTool, type McpHttpServerConfig, type McpHttpServerHandle, type MemoryNodeStore, type NodeChangeEventData, type NodeData, type NodeStoreAPI, ProcessManager, type ProcessManagerEvents, SERVICE_IPC_CHANNELS, type SchemaData, type SchemaRegistryAPI, ScriptSandbox, type ServiceClient, type ServiceCommunication, type ServiceDefinition, type ServiceHealthCheck, type ServiceLifecycle, type ServiceOutputEvent, type ServiceProcessConfig, type ServiceProvides, type ServiceState, type ServiceStatus, type ServiceStatusEvent, XNET_AGENT_SKILL_MD, XNET_MARKDOWN_DIRECTIVE_SPECS, type XNetMarkdownDiffLine, type XNetMarkdownDiffLineKind, type XNetMarkdownDirective, type XNetMarkdownDirectiveSpec, type XNetMarkdownReviewDiff, type XNetPageMarkdownFrontmatter, type XNetPageMarkdownValidation, type XNetPageMarkdownValidationOptions, attachAiPlanValidation, createAgentScriptContext, createAiChangeSet, createAiOperation, createAiSurfaceService, createAiValidationResult, createAiWorkspaceExporter, createAiWorkspaceWatcher, createLocalAPI, createMCPServer, createMcpHttpServer, createMemoryNodeStore, createMemorySchemaRegistry, createWorkspaceFixtureSchemas, flattenRowForTsv, getXNetMarkdownDirectiveSpecs, isAiRiskLevel, isAiScope, isAiTargetKind, parseAiMutationPlan, parseXNetPageFrontmatter, renderMarkdownLineDiff, renderMarkdownReviewDiff, serializeAiMutationPlan, stripXNetPageFrontmatter, toTsv, validateAiMutationPlan, validateXNetPageMarkdown };
1878
+ export { AI_RISK_LEVELS, AI_SCOPES, AI_TARGET_KINDS, type AgentApi, type AgentScriptContext, type AgentScriptSession, type AgentSearchResult, type AgentWriteProposal, type AiAuditEvent, type AiChangeSet, type AiContextPack, type AiContextPackResource, type AiContextSeed, type AiJsonSchema, type AiJsonSchemaType, type AiMutationPlan, type AiMutationPlanStatus, type AiOperation, type AiPageMarkdownApplyAdapter, type AiPageMarkdownApplyAdapterInput, type AiPageMarkdownApplyAdapterResult, type AiPageMarkdownApplyResult, type AiPageMarkdownRollbackResult, type AiResource, type AiResourceContent, type AiRiskLevel, type AiScope, type AiSearchOptions, type AiSearchResult, type AiSurfaceLimits, AiSurfaceService, type AiSurfaceServiceConfig, type AiTargetKind, type AiToolCallResult, type AiToolDefinition, type AiValidationResult, type AiWorkspaceChangedFile, type AiWorkspaceChangedFileStatus, type AiWorkspaceCheckoutOptions, type AiWorkspaceConflict, type AiWorkspaceConflictKind, type AiWorkspaceExportKind, type AiWorkspaceExportOptions, type AiWorkspaceExportResult, type AiWorkspaceExportScope, AiWorkspaceExporter, type AiWorkspaceExporterConfig, type AiWorkspaceManifestEntry, type AiWorkspacePendingPlan, type AiWorkspaceReviewAction, type AiWorkspaceReviewEntry, type AiWorkspaceReviewEntryKind, type AiWorkspaceReviewIndex, type AiWorkspaceReviewStatus, type AiWorkspaceWatchHandle, type AiWorkspaceWatchOptions, AiWorkspaceWatcher, type AiWorkspaceWatcherScanOptions, type AiWorkspaceWatcherScanResult, type BlockNotePageMarkdownAdapterOptions, type CreateAgentScriptContextInput, type FlatNode, type IProcessManager, type LocalAPIConfig, LocalAPIServer, type LocalAPITokenConfig, type LocalAPITokenScope, type LocalAPITokenSummary, type MCPPropertySchema, type MCPRequest, type MCPResource, type MCPResponse, MCPServer, type MCPServerConfig, type MCPTool, type McpHttpServerConfig, type McpHttpServerHandle, type MemoryNodeStore, type NodeChangeEventData, type NodeData, type NodeStoreAPI, ProcessManager, type ProcessManagerEvents, SERVICE_IPC_CHANNELS, type SchemaData, type SchemaRegistryAPI, ScriptSandbox, type ServiceClient, type ServiceCommunication, type ServiceDefinition, type ServiceHealthCheck, type ServiceLifecycle, type ServiceOutputEvent, type ServiceProcessConfig, type ServiceProvides, type ServiceState, type ServiceStatus, type ServiceStatusEvent, XNET_AGENT_SKILL_MD, XNET_MARKDOWN_DIRECTIVE_SPECS, XNET_PAGE_FRAGMENT_FIELD, XNET_PAGE_LEGACY_FRAGMENT_FIELD, type XNetMarkdownDiffLine, type XNetMarkdownDiffLineKind, type XNetMarkdownDirective, type XNetMarkdownDirectiveSpec, type XNetMarkdownReviewDiff, type XNetPageDocResolver, type XNetPageFragmentReadOptions, type XNetPageFragmentWriteOptions, type XNetPageMarkdownFrontmatter, type XNetPageMarkdownValidation, type XNetPageMarkdownValidationOptions, attachAiPlanValidation, blockNoteFragmentToMarkdown, createAgentScriptContext, createAiChangeSet, createAiOperation, createAiSurfaceService, createAiValidationResult, createAiWorkspaceExporter, createAiWorkspaceWatcher, createBlockNotePageMarkdownAdapter, createLocalAPI, createMCPServer, createMcpHttpServer, createMemoryNodeStore, createMemorySchemaRegistry, createWorkspaceFixtureSchemas, flattenRowForTsv, getXNetMarkdownDirectiveSpecs, isAiRiskLevel, isAiScope, isAiTargetKind, legacyFragmentToMarkdown, parseAiMutationPlan, parseXNetPageFrontmatter, renderMarkdownLineDiff, renderMarkdownReviewDiff, replaceXNetPageFragmentWithMarkdown, serializeAiMutationPlan, stripXNetPageFrontmatter, toTsv, validateAiMutationPlan, validateXNetPageMarkdown, xnetPageFragmentToMarkdown };