@stream-mdx/protocol 0.4.0 → 1.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,100 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 159a237: Use source-owned records for root code fences, tables, and paragraphs, with bounded line, row, and span updates and on-demand full-source reads. Patch consumers must accept wire protocol 2.0, replace `appendLines` with `appendCode`, adopt `appendParagraph` and `updateParagraphSpans`, and handle native table operations; the retired operation has no compatibility alias. Plugins must use the source snapshot and on-demand `readBlocks` document context instead of a retained `blocks` array.
8
+
9
+ Live consumers now initialize one canonical root input document from the
10
+ `INITIALIZED` snapshot baseline and retain later admitted bytes with ordered
11
+ semantic `appendInputSource` root patches. Missing live baselines are
12
+ incompatible; cold `Block[]` and standalone snapshots keep only their honest
13
+ per-block source slices. Native code, table, and paragraph windows share the
14
+ consumer input document while retaining independent owner generations and
15
+ exact newly owned `sourceAppend` suffixes. Empty baselines are valid, and static
16
+ artifact version 1 is unchanged.
17
+
18
+ Preserve owner identity and retirement guards when replacing active snapshots. Reject regressing revisions and source frontiers, while allowing valid source-stable table and paragraph dependency meaning updates after finalization. Same-generation finalized source cannot grow or reopen. Keep final code highlighting and fallback presentation intact without retransmitting source in presentation-only patches.
19
+
20
+ For paragraph owners after raw Markdown EOF, reopen only the actual trailing paragraph under a fresh owner generation. Do not fuse intervening definition or root source into an earlier paragraph. Keep genuinely unowned provisional following roots eligible for continuation.
21
+
22
+ Do not re-finalize completed paragraph owners when later roots extend the shared input. Preserve their original parser frontier and captured source while still publishing valid late dependency changes.
23
+
24
+ Queue imperative append and finalize calls behind their matching initialization acknowledgement. Ignore errors from detached or superseded initializations without changing public worker attachment readiness, and keep detached snapshot callbacks callable.
25
+
26
+ Render managed paragraph children through the native span view while preserving registered source props and finalized block overrides. Default appends avoid global block/MDX scans; legacy full-source custom props use an explicit cold projection. Cold Block exports also retain admitted open native tables.
27
+
28
+ Blocks whose rendering depends on HTML stay on the base HTML grouping path. Genuine inline-HTML paragraphs and HTML-bearing containers retire native owners instead of adopting or rehoming them; tail-local auto-close and native ownership for non-HTML blocks remain.
29
+
30
+ - Release the coordinated 1.0.0 package line. Upgrade all installed StreamMDX packages together and recopy the hosted worker from the matching version. Internal runtime dependencies remain exact versions; the optional unified adapter's StreamMDX peers require the 1.x line.
31
+
32
+ Migration from 0.5.0:
33
+
34
+ - Remove imports of `@stream-mdx/plugins/registry`, `/base`, and `/math`, their `stream-mdx/plugins/*` convenience re-exports, and `@stream-mdx/worker/streaming/custom-matcher`. `PluginRegistry`, `globalPluginRegistry`, legacy match handlers, and legacy math plugin factories are no longer public. Use native Lezer extensions, serializable `SyntaxRuleSpec` rules, and per-engine `DocumentPluginRegistry` document plugins. Native extension functions belong in the engine or custom worker bundle, not in structured-clone `INIT` messages.
35
+ - `MarkdownEngine` owns its parser, queue, document state, plugins, and caches. Construct it with `{ post, extensions? }`, send configuration and document resets through `handle({ type: "INIT", ... })`, and call terminal `dispose()` when finished. Use public `serveMarkdownWorker` and `createInlineEngineWorker` factories instead of old global runtime plumbing. Worker URLs and actual Worker factories create renderer-owned workers that terminate on detach; an existing Worker is caller-owned. Caller-created inline adapters also need caller-owned termination. See `docs/PUBLIC_API.md` and `docs/PLUGIN_ABI.md` for supported wiring.
36
+ `managedWorker={true}` requires a supplied Worker instance or caller-accessible factory and caller-owned initialization/document commands. URL/default workers and `engine="main-thread"` are rejected, even with a supplied worker source. Managed auto cannot silently fall back inline. Borrowed instances remain caller-owned; factory-created workers remain component-owned and terminate on detach.
37
+ - Provisional lookahead inputs over 512 characters now return raw text before completeness scanning, including closed strings. Oversized finalized/nonprovisional complete content is preserved; within-budget finalized projection retains its behavior. Internal defaults are `maxScanChars: 512`, `maxNewlines: 2`, `maxSyntheticOps: 6`, `maxNestingDepth: 8`, `maxValidationFailures: 1`, and `maxProviderMs: 5`. Provider timers start before scanning; these caps are not React props or latency guarantees.
38
+ - Core root exports no longer expose Lezer converter, math extension factory, link-label normalization, entity decoder, or default/regex plugin adapter internals. Use retained parser/preparation APIs and public worker/compiler entries. Owning parser settings remain authoritative, including disabled math in nested snapshot fallbacks.
39
+ - `ComponentRegistry` treats a block component as custom only when it differs from the built-in default. Custom paragraph and quote wrappers must render the supplied `children` projection to retain native inline, HTML, and nested-block ownership. Do not reconstruct those children from raw source.
40
+ - `CodeFenceRendererProps.renderCode` is a React node, not a callback. Return it directly as a fallback. `language`, fence metadata, and emitted `language-*` classes preserve the authored info word, such as `js`, rather than the canonical Shiki grammar name. Renderer lookups still fall back to canonical names and accept aliases. Unlabeled and indented code has no language class or `data-language` attribute.
41
+ - `restart()` cancels the current async iterator generation; it does not replay a consumed iterator. Supply a fresh iterator for a new stream. Renderer-owned text replacements reset the engine document, while caller-initialized managed workers retain their document ownership.
42
+ - URL transformation and HTML/style sanitization now apply across native client rendering, SSR, and the optional unified adapter. Rejected URLs are omitted; custom components must honor the supplied sanitized attributes and children. `allowedElements` and `disallowedElements` are mutually exclusive.
43
+
44
+ The remaining consumed changesets describe the new opt-in renderers, controls, animation, table virtualization, themes, native extension APIs, and correctness/security fixes. These features do not enable themselves when upgrading. See the root README migration section and the generated package changelogs before upgrading custom integrations.
45
+
46
+ ### Patch Changes
47
+
48
+ - 3f24715: Bound host-accepted and in-flight source with generation-tagged worker admission acknowledgements. Imperative append accepts a whole UTF-16 chunk or refuses it without partial admission; automatic iterators losslessly split larger chunks and wait for capacity.
49
+
50
+ Finalization seals the host generation immediately and resolves one shared promise after all earlier accepted source reaches the matching native finalization and semantic store barrier. Reset invalidates pending capacity/finalization waits, including automatic source replacement on a reused renderer. The barrier does not imply a React commit or optional enrichment readiness.
51
+
52
+ Cache inline regex eligibility per immutable parser context, rather than rescanning the whole context at each token position. A later marker-bearing context still performs its own check, and weak keys do not retain completed contexts.
53
+
54
+ Demo automation now observes synchronous source and completion state immediately after fast-forward or finalization, and restart opens a fresh wrapper session before replacing its worker.
55
+
56
+ - 3f24715: Require each live worker PATCH and every schema-2 protocol event to carry its native root document generation. Renderers and TUI event stores reject stale-generation work against the current validated INITIALIZED baseline, including after queueing; TUI replacement also clears old transaction/status metadata. Caller-managed worker attachment stays pending until an observed baseline, then drains accepted input once. Node and direct snapshot compilers bind patch/finalization handling to that baseline. Static snapshot artifacts remain version 1.
57
+
58
+ Explicit cold TUI replacement retires the old native lease, so delayed snapshots and lifecycle events cannot reclaim the replacement. A validated newer same-stream baseline can resume delivery.
59
+
60
+ Bind same-turn restart capacity waits to the new session's admitting renderer, retaining their requested capacity and cancellation options without dropping accepted source.
61
+
62
+ Use the task-packed protocol dependency in installed Node, Next, and Vite smoke consumers instead of allowing a registry fallback.
63
+
64
+ Generate JavaScript for both installed runtime loaders and replay a replacement root's actual finalization patches before checking completed source.
65
+
66
+ Render the terminal example from authored cold block source without adding duplicate heading, quote, or code-fence markers.
67
+
68
+ - Updated dependencies [1669abb]
69
+ - Updated dependencies [0e96940]
70
+ - Updated dependencies [5833985]
71
+ - Updated dependencies [9c482bd]
72
+ - Updated dependencies [150a0ac]
73
+ - Updated dependencies [7879ed5]
74
+ - Updated dependencies [73bdb36]
75
+ - Updated dependencies [fdaa309]
76
+ - Updated dependencies [e02e7cf]
77
+ - Updated dependencies
78
+ - @stream-mdx/core@1.0.0
79
+
80
+ ## 0.5.0
81
+
82
+ ### Minor Changes
83
+
84
+ - Promote the current hardening and product-surface tranche as `0.5.0`.
85
+
86
+ This release rolls up:
87
+
88
+ - renderer/store correctness hardening
89
+ - seeded smoke and scheduler-parity release discipline
90
+ - benchmark methodology and comparison cleanup
91
+ - docs, showcase, and TUI/product surface maturation
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies
96
+ - @stream-mdx/core@0.5.0
97
+
3
98
  ## 0.1.1
99
+
4
100
  - Initial protocol types and event envelope for StreamMDX Protocol v1.
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # @stream-mdx/protocol
1
+ # `@stream-mdx/protocol`
2
2
 
3
- Protocol types for StreamMDX JSON/object streaming.
3
+ `@stream-mdx/protocol` defines the transport-facing protocol types for structured StreamMDX event/object streaming. It is intended for consumers that need a stable, typed contract outside the React/browser UI layer.
4
4
 
5
- This package defines the event envelope, capability metadata, and token
6
- structures used by StreamMDX Protocol v1. It is intended for consumers that
7
- need a stable, versioned contract (e.g., terminal UIs).
5
+ Typical consumers include:
8
6
 
9
- Most web-only consumers do not need this package directly. Start with `stream-mdx`
10
- or `@stream-mdx/react` for the React renderer.
7
+ - TUIs and CLI tools
8
+ - NDJSON transports
9
+ - service boundaries that want typed event envelopes
10
+ - debugging or replay tooling that records and replays structured patch streams
11
11
 
12
12
  ## Install
13
13
 
@@ -15,21 +15,28 @@ or `@stream-mdx/react` for the React renderer.
15
15
  npm install @stream-mdx/protocol
16
16
  ```
17
17
 
18
- ## What this provides
18
+ ## What This Package Provides
19
19
 
20
- - Shared protocol types for streaming events and capability negotiation.
21
- - Token / block payload shapes intended for structured-clone-safe transport.
20
+ | Surface | Purpose |
21
+ | --- | --- |
22
+ | Event envelope types | Transport-safe event/message contracts |
23
+ | Capability metadata | Describe supported features or modes |
24
+ | Token/block payload types | Structured-clone-safe payload shapes |
22
25
 
23
- ## Typical usage (TUI/CLI)
26
+ ## Typical Pairings
24
27
 
25
- Pair it with `@stream-mdx/tui` for NDJSON helpers + a lightweight snapshot store:
28
+ | Pair with | Why |
29
+ | --- | --- |
30
+ | [`@stream-mdx/tui`](../markdown-v2-tui/README.md) | NDJSON helpers and snapshot store |
31
+ | [`@stream-mdx/core`](../markdown-v2-core/README.md) | Shared low-level types and helpers |
32
+ | [`@stream-mdx/worker`](../markdown-v2-worker/README.md) | Worker-side generation/consumption paths |
26
33
 
27
- ```bash
28
- npm install @stream-mdx/tui @stream-mdx/protocol @stream-mdx/core
29
- ```
30
-
31
- ## Docs
34
+ ## Documentation
32
35
 
33
- - Public API: https://github.com/kmccleary3301/stream-mdx/blob/main/docs/PUBLIC_API.md
34
- - CLI usage: https://github.com/kmccleary3301/stream-mdx/blob/main/docs/CLI_USAGE.md
35
- - Protocol spec: https://github.com/kmccleary3301/stream-mdx/blob/main/docs/STREAMMDX_JSON_DIFF_SPEC.md
36
+ - Start from the runnable example path with `npm run example:tui-minimal` from the repo root.
37
+ - [`../../examples/tui-minimal/README.md`](../../examples/tui-minimal/README.md)
38
+ - [`../../docs/TUI_MINIMAL_EXAMPLE.md`](../../docs/TUI_MINIMAL_EXAMPLE.md)
39
+ - [`../../docs/TUI_GUIDE.md`](../../docs/TUI_GUIDE.md)
40
+ - [`../../docs/STREAMMDX_JSON_DIFF_SPEC.md`](../../docs/STREAMMDX_JSON_DIFF_SPEC.md)
41
+ - [`../../docs/CLI_USAGE.md`](../../docs/CLI_USAGE.md)
42
+ - [`../../docs/PUBLIC_API.md`](../../docs/PUBLIC_API.md)
package/dist/index.cjs CHANGED
@@ -21,13 +21,40 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  STREAM_MDX_PROTOCOL_ID: () => STREAM_MDX_PROTOCOL_ID,
24
- STREAM_MDX_SCHEMA_VERSION: () => STREAM_MDX_SCHEMA_VERSION
24
+ STREAM_MDX_SCHEMA_VERSION: () => import_core.STREAM_MDX_SCHEMA_VERSION,
25
+ SourceCapacityError: () => SourceCapacityError,
26
+ StreamSessionError: () => StreamSessionError
25
27
  });
26
28
  module.exports = __toCommonJS(index_exports);
29
+ var import_core = require("@stream-mdx/core");
30
+
31
+ // src/stream-admission.ts
32
+ var SourceCapacityError = class extends Error {
33
+ constructor(offeredSourceUnits, pendingSourceUnits, hardLimitSourceUnits) {
34
+ super(
35
+ `Appending ${offeredSourceUnits} UTF-16 source units would exceed the ${hardLimitSourceUnits}-unit admission limit (${pendingSourceUnits} units are pending)`
36
+ );
37
+ this.name = "SourceCapacityError";
38
+ this.offeredSourceUnits = offeredSourceUnits;
39
+ this.pendingSourceUnits = pendingSourceUnits;
40
+ this.hardLimitSourceUnits = hardLimitSourceUnits;
41
+ this.retryable = offeredSourceUnits <= hardLimitSourceUnits;
42
+ }
43
+ };
44
+ var StreamSessionError = class extends Error {
45
+ constructor(reason, message) {
46
+ super(message);
47
+ this.name = "StreamSessionError";
48
+ this.reason = reason;
49
+ }
50
+ };
51
+
52
+ // src/index.ts
27
53
  var STREAM_MDX_PROTOCOL_ID = "streammdx";
28
- var STREAM_MDX_SCHEMA_VERSION = "1.0";
29
54
  // Annotate the CommonJS export names for ESM import in node:
30
55
  0 && (module.exports = {
31
56
  STREAM_MDX_PROTOCOL_ID,
32
- STREAM_MDX_SCHEMA_VERSION
57
+ STREAM_MDX_SCHEMA_VERSION,
58
+ SourceCapacityError,
59
+ StreamSessionError
33
60
  });
package/dist/index.d.cts CHANGED
@@ -1,8 +1,41 @@
1
- import { Block, Patch, PatchMetrics } from '@stream-mdx/core';
2
- export { DiffBlock, DiffKind, DiffLine, DiffLineKind, ThemedLine, ThemedToken, TokenLineV1, TokenSpan, TokenStyle } from '@stream-mdx/core';
1
+ import { STREAM_MDX_SCHEMA_VERSION, NodeSnapshot, Patch, PatchMetrics } from '@stream-mdx/core';
2
+ export { DiffBlock, DiffKind, DiffLine, DiffLineKind, STREAM_MDX_SCHEMA_VERSION, ThemedLine, ThemedToken, TokenLineV1, TokenSpan, TokenStyle } from '@stream-mdx/core';
3
+
4
+ type AppendResult = {
5
+ /** Total UTF-16 source units accepted by append calls in this session. */
6
+ acceptedSourceUnits: number;
7
+ /** Accepted append units not yet acknowledged by the worker. */
8
+ pendingSourceUnits: number;
9
+ /** Whether the soft admission threshold has been reached. */
10
+ shouldPause: boolean;
11
+ };
12
+ type FinalizeResult = {
13
+ /** Native worker document generation that finalized this host session. */
14
+ generation: number;
15
+ /** Total UTF-16 source units accepted by append calls in this session. */
16
+ acceptedSourceUnits: number;
17
+ /** Accepted source units whose semantic patches have committed to the renderer store. */
18
+ committedSourceUnits: number;
19
+ };
20
+ type WaitForCapacityOptions = {
21
+ /** UTF-16 source units the next append needs to admit. */
22
+ units: number;
23
+ signal?: AbortSignal;
24
+ };
25
+ type StreamSessionErrorReason = "sealed" | "stale-generation" | "disposed";
26
+ declare class SourceCapacityError extends Error {
27
+ readonly offeredSourceUnits: number;
28
+ readonly pendingSourceUnits: number;
29
+ readonly hardLimitSourceUnits: number;
30
+ readonly retryable: boolean;
31
+ constructor(offeredSourceUnits: number, pendingSourceUnits: number, hardLimitSourceUnits: number);
32
+ }
33
+ declare class StreamSessionError extends Error {
34
+ readonly reason: StreamSessionErrorReason;
35
+ constructor(reason: StreamSessionErrorReason, message: string);
36
+ }
3
37
 
4
38
  declare const STREAM_MDX_PROTOCOL_ID = "streammdx";
5
- declare const STREAM_MDX_SCHEMA_VERSION = "1.0";
6
39
  type StreamMdxEventType = "init" | "snapshot" | "patch" | "metrics" | "error" | "done";
7
40
  type StreamMdxCapabilityLevel = "none" | "v1";
8
41
  type StreamMdxCapabilities = {
@@ -24,41 +57,42 @@ type StreamMdxEventBase = {
24
57
  protocol: typeof STREAM_MDX_PROTOCOL_ID;
25
58
  schemaVersion: typeof STREAM_MDX_SCHEMA_VERSION;
26
59
  streamId: string;
60
+ generation: number;
27
61
  event: StreamMdxEventType;
28
62
  tx?: number;
29
63
  };
30
- type StreamMdxInitEventV1 = StreamMdxEventBase & {
64
+ type StreamMdxInitEvent = StreamMdxEventBase & {
31
65
  event: "init";
32
66
  createdAt?: number;
33
67
  capabilities?: StreamMdxCapabilities;
34
68
  theme?: StreamMdxTheme;
35
69
  shikiVersion?: string;
36
70
  };
37
- type StreamMdxSnapshotEventV1 = StreamMdxEventBase & {
71
+ type StreamMdxSnapshotEvent = StreamMdxEventBase & {
38
72
  event: "snapshot";
39
- blocks: Block[];
73
+ snapshot: NodeSnapshot;
40
74
  };
41
- type StreamMdxPatchEventV1 = StreamMdxEventBase & {
75
+ type StreamMdxPatchEvent = StreamMdxEventBase & {
42
76
  event: "patch";
43
77
  tx: number;
44
78
  patches: Patch[];
45
79
  metrics?: PatchMetrics | null;
46
80
  };
47
- type StreamMdxMetricsEventV1 = StreamMdxEventBase & {
81
+ type StreamMdxMetricsEvent = StreamMdxEventBase & {
48
82
  event: "metrics";
49
83
  tx?: number;
50
84
  metrics: PatchMetrics;
51
85
  };
52
- type StreamMdxErrorEventV1 = StreamMdxEventBase & {
86
+ type StreamMdxErrorEvent = StreamMdxEventBase & {
53
87
  event: "error";
54
88
  message: string;
55
89
  stack?: string;
56
90
  };
57
- type StreamMdxDoneEventV1 = StreamMdxEventBase & {
91
+ type StreamMdxDoneEvent = StreamMdxEventBase & {
58
92
  event: "done";
59
93
  finalTx?: number;
60
94
  status: "ok" | "error";
61
95
  };
62
- type StreamMdxEventV1 = StreamMdxInitEventV1 | StreamMdxSnapshotEventV1 | StreamMdxPatchEventV1 | StreamMdxMetricsEventV1 | StreamMdxErrorEventV1 | StreamMdxDoneEventV1;
96
+ type StreamMdxEvent = StreamMdxInitEvent | StreamMdxSnapshotEvent | StreamMdxPatchEvent | StreamMdxMetricsEvent | StreamMdxErrorEvent | StreamMdxDoneEvent;
63
97
 
64
- export { STREAM_MDX_PROTOCOL_ID, STREAM_MDX_SCHEMA_VERSION, type StreamMdxCapabilities, type StreamMdxCapabilityLevel, type StreamMdxDoneEventV1, type StreamMdxErrorEventV1, type StreamMdxEventBase, type StreamMdxEventType, type StreamMdxEventV1, type StreamMdxInitEventV1, type StreamMdxMetricsEventV1, type StreamMdxPatchEventV1, type StreamMdxSnapshotEventV1, type StreamMdxTheme };
98
+ export { type AppendResult, type FinalizeResult, STREAM_MDX_PROTOCOL_ID, SourceCapacityError, type StreamMdxCapabilities, type StreamMdxCapabilityLevel, type StreamMdxDoneEvent, type StreamMdxErrorEvent, type StreamMdxEvent, type StreamMdxEventBase, type StreamMdxEventType, type StreamMdxInitEvent, type StreamMdxMetricsEvent, type StreamMdxPatchEvent, type StreamMdxSnapshotEvent, type StreamMdxTheme, StreamSessionError, type StreamSessionErrorReason, type WaitForCapacityOptions };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,41 @@
1
- import { Block, Patch, PatchMetrics } from '@stream-mdx/core';
2
- export { DiffBlock, DiffKind, DiffLine, DiffLineKind, ThemedLine, ThemedToken, TokenLineV1, TokenSpan, TokenStyle } from '@stream-mdx/core';
1
+ import { STREAM_MDX_SCHEMA_VERSION, NodeSnapshot, Patch, PatchMetrics } from '@stream-mdx/core';
2
+ export { DiffBlock, DiffKind, DiffLine, DiffLineKind, STREAM_MDX_SCHEMA_VERSION, ThemedLine, ThemedToken, TokenLineV1, TokenSpan, TokenStyle } from '@stream-mdx/core';
3
+
4
+ type AppendResult = {
5
+ /** Total UTF-16 source units accepted by append calls in this session. */
6
+ acceptedSourceUnits: number;
7
+ /** Accepted append units not yet acknowledged by the worker. */
8
+ pendingSourceUnits: number;
9
+ /** Whether the soft admission threshold has been reached. */
10
+ shouldPause: boolean;
11
+ };
12
+ type FinalizeResult = {
13
+ /** Native worker document generation that finalized this host session. */
14
+ generation: number;
15
+ /** Total UTF-16 source units accepted by append calls in this session. */
16
+ acceptedSourceUnits: number;
17
+ /** Accepted source units whose semantic patches have committed to the renderer store. */
18
+ committedSourceUnits: number;
19
+ };
20
+ type WaitForCapacityOptions = {
21
+ /** UTF-16 source units the next append needs to admit. */
22
+ units: number;
23
+ signal?: AbortSignal;
24
+ };
25
+ type StreamSessionErrorReason = "sealed" | "stale-generation" | "disposed";
26
+ declare class SourceCapacityError extends Error {
27
+ readonly offeredSourceUnits: number;
28
+ readonly pendingSourceUnits: number;
29
+ readonly hardLimitSourceUnits: number;
30
+ readonly retryable: boolean;
31
+ constructor(offeredSourceUnits: number, pendingSourceUnits: number, hardLimitSourceUnits: number);
32
+ }
33
+ declare class StreamSessionError extends Error {
34
+ readonly reason: StreamSessionErrorReason;
35
+ constructor(reason: StreamSessionErrorReason, message: string);
36
+ }
3
37
 
4
38
  declare const STREAM_MDX_PROTOCOL_ID = "streammdx";
5
- declare const STREAM_MDX_SCHEMA_VERSION = "1.0";
6
39
  type StreamMdxEventType = "init" | "snapshot" | "patch" | "metrics" | "error" | "done";
7
40
  type StreamMdxCapabilityLevel = "none" | "v1";
8
41
  type StreamMdxCapabilities = {
@@ -24,41 +57,42 @@ type StreamMdxEventBase = {
24
57
  protocol: typeof STREAM_MDX_PROTOCOL_ID;
25
58
  schemaVersion: typeof STREAM_MDX_SCHEMA_VERSION;
26
59
  streamId: string;
60
+ generation: number;
27
61
  event: StreamMdxEventType;
28
62
  tx?: number;
29
63
  };
30
- type StreamMdxInitEventV1 = StreamMdxEventBase & {
64
+ type StreamMdxInitEvent = StreamMdxEventBase & {
31
65
  event: "init";
32
66
  createdAt?: number;
33
67
  capabilities?: StreamMdxCapabilities;
34
68
  theme?: StreamMdxTheme;
35
69
  shikiVersion?: string;
36
70
  };
37
- type StreamMdxSnapshotEventV1 = StreamMdxEventBase & {
71
+ type StreamMdxSnapshotEvent = StreamMdxEventBase & {
38
72
  event: "snapshot";
39
- blocks: Block[];
73
+ snapshot: NodeSnapshot;
40
74
  };
41
- type StreamMdxPatchEventV1 = StreamMdxEventBase & {
75
+ type StreamMdxPatchEvent = StreamMdxEventBase & {
42
76
  event: "patch";
43
77
  tx: number;
44
78
  patches: Patch[];
45
79
  metrics?: PatchMetrics | null;
46
80
  };
47
- type StreamMdxMetricsEventV1 = StreamMdxEventBase & {
81
+ type StreamMdxMetricsEvent = StreamMdxEventBase & {
48
82
  event: "metrics";
49
83
  tx?: number;
50
84
  metrics: PatchMetrics;
51
85
  };
52
- type StreamMdxErrorEventV1 = StreamMdxEventBase & {
86
+ type StreamMdxErrorEvent = StreamMdxEventBase & {
53
87
  event: "error";
54
88
  message: string;
55
89
  stack?: string;
56
90
  };
57
- type StreamMdxDoneEventV1 = StreamMdxEventBase & {
91
+ type StreamMdxDoneEvent = StreamMdxEventBase & {
58
92
  event: "done";
59
93
  finalTx?: number;
60
94
  status: "ok" | "error";
61
95
  };
62
- type StreamMdxEventV1 = StreamMdxInitEventV1 | StreamMdxSnapshotEventV1 | StreamMdxPatchEventV1 | StreamMdxMetricsEventV1 | StreamMdxErrorEventV1 | StreamMdxDoneEventV1;
96
+ type StreamMdxEvent = StreamMdxInitEvent | StreamMdxSnapshotEvent | StreamMdxPatchEvent | StreamMdxMetricsEvent | StreamMdxErrorEvent | StreamMdxDoneEvent;
63
97
 
64
- export { STREAM_MDX_PROTOCOL_ID, STREAM_MDX_SCHEMA_VERSION, type StreamMdxCapabilities, type StreamMdxCapabilityLevel, type StreamMdxDoneEventV1, type StreamMdxErrorEventV1, type StreamMdxEventBase, type StreamMdxEventType, type StreamMdxEventV1, type StreamMdxInitEventV1, type StreamMdxMetricsEventV1, type StreamMdxPatchEventV1, type StreamMdxSnapshotEventV1, type StreamMdxTheme };
98
+ export { type AppendResult, type FinalizeResult, STREAM_MDX_PROTOCOL_ID, SourceCapacityError, type StreamMdxCapabilities, type StreamMdxCapabilityLevel, type StreamMdxDoneEvent, type StreamMdxErrorEvent, type StreamMdxEvent, type StreamMdxEventBase, type StreamMdxEventType, type StreamMdxInitEvent, type StreamMdxMetricsEvent, type StreamMdxPatchEvent, type StreamMdxSnapshotEvent, type StreamMdxTheme, StreamSessionError, type StreamSessionErrorReason, type WaitForCapacityOptions };
package/dist/index.mjs CHANGED
@@ -1,7 +1,32 @@
1
+ // src/index.ts
2
+ import { STREAM_MDX_SCHEMA_VERSION } from "@stream-mdx/core";
3
+
4
+ // src/stream-admission.ts
5
+ var SourceCapacityError = class extends Error {
6
+ constructor(offeredSourceUnits, pendingSourceUnits, hardLimitSourceUnits) {
7
+ super(
8
+ `Appending ${offeredSourceUnits} UTF-16 source units would exceed the ${hardLimitSourceUnits}-unit admission limit (${pendingSourceUnits} units are pending)`
9
+ );
10
+ this.name = "SourceCapacityError";
11
+ this.offeredSourceUnits = offeredSourceUnits;
12
+ this.pendingSourceUnits = pendingSourceUnits;
13
+ this.hardLimitSourceUnits = hardLimitSourceUnits;
14
+ this.retryable = offeredSourceUnits <= hardLimitSourceUnits;
15
+ }
16
+ };
17
+ var StreamSessionError = class extends Error {
18
+ constructor(reason, message) {
19
+ super(message);
20
+ this.name = "StreamSessionError";
21
+ this.reason = reason;
22
+ }
23
+ };
24
+
1
25
  // src/index.ts
2
26
  var STREAM_MDX_PROTOCOL_ID = "streammdx";
3
- var STREAM_MDX_SCHEMA_VERSION = "1.0";
4
27
  export {
5
28
  STREAM_MDX_PROTOCOL_ID,
6
- STREAM_MDX_SCHEMA_VERSION
29
+ STREAM_MDX_SCHEMA_VERSION,
30
+ SourceCapacityError,
31
+ StreamSessionError
7
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-mdx/protocol",
3
- "version": "0.4.0",
3
+ "version": "1.0.0",
4
4
  "description": "StreamMDX protocol types and event envelope for JSON/object streaming",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,6 +34,6 @@
34
34
  "prepack": "npm run build"
35
35
  },
36
36
  "dependencies": {
37
- "@stream-mdx/core": "0.4.0"
37
+ "@stream-mdx/core": "1.0.0"
38
38
  }
39
39
  }