@r-a-i-t-h/viz-protocol 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 r-a-i-t-h
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Static context dependency graph shape — shared by host analysis and UI.
3
+ * The analyzer that builds this lives in `@r-a-i-t-h/viz-host` (needs live XState logic).
4
+ */
5
+ export type DepEntityKind = 'contextKey' | 'action' | 'guard' | 'invoke';
6
+ export type DepCoverage = 'known' | 'partial' | 'opaque';
7
+ export type DepRelation = 'reads' | 'writes';
8
+ export type DepSite = 'entry' | 'exit' | 'transition' | 'invoke';
9
+ export interface ContextDepNode {
10
+ id: string;
11
+ kind: DepEntityKind;
12
+ label: string;
13
+ coverage: DepCoverage;
14
+ }
15
+ export interface ContextDepEdge {
16
+ from: string;
17
+ to: string;
18
+ relation: DepRelation;
19
+ at: {
20
+ stateId: string;
21
+ site: DepSite;
22
+ eventType?: string;
23
+ };
24
+ }
25
+ export interface ContextDepGraph {
26
+ nodes: ContextDepNode[];
27
+ edges: ContextDepEdge[];
28
+ }
29
+ //# sourceMappingURL=contextDeps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextDeps.d.ts","sourceRoot":"","sources":["../src/contextDeps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEzE,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEzD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE7C,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,WAAW,CAAC;IACtB,EAAE,EAAE;QACF,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,OAAO,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Static context dependency graph shape — shared by host analysis and UI.
3
+ * The analyzer that builds this lives in `@r-a-i-t-h/viz-host` (needs live XState logic).
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=contextDeps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextDeps.js","sourceRoot":"","sources":["../src/contextDeps.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
package/dist/ids.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** Strip leading `#` from XState state node ids for Viz* id matching. */
2
+ export declare function normalizeStateNodeId(id: string): string;
3
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEvD"}
package/dist/ids.js ADDED
@@ -0,0 +1,5 @@
1
+ /** Strip leading `#` from XState state node ids for Viz* id matching. */
2
+ export function normalizeStateNodeId(id) {
3
+ return id.replace(/^#/, '');
4
+ }
5
+ //# sourceMappingURL=ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,UAAU,oBAAoB,CAAC,EAAU;IAC7C,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Shared viz presentation model + wire protocol.
3
+ *
4
+ * Host projects into Viz*; visualizer renders Viz*. No XState here.
5
+ */
6
+ export type { ContextDepEdge, ContextDepGraph, ContextDepNode, DepCoverage, DepEntityKind, DepRelation, DepSite, } from './contextDeps.js';
7
+ export type { VizActorRefMarker, VizAnalysis, VizBadge, VizBadgeKind, VizEvent, VizFrame, VizInvoke, VizLogEntry, VizMachine, VizNextEvent, VizNextEventCandidate, VizNode, VizNodeDetails, VizNodeKind, VizSymbol, VizTransition, } from './model.js';
8
+ export { isVizActorRefMarker } from './model.js';
9
+ export type { HostBridgeStatus, VisualizerSnapshot } from './snapshot.js';
10
+ export { VIZ_CHANNEL, VIZ_PROTOCOL_VERSION, VIZ_WINDOW_NAME, isVizMessage, toPortable, type VizDownstreamMessage, type VizMessage, type VizUpstreamMessage, } from './protocol.js';
11
+ export { connectPopupReceiver, type PopupMessageHandler, } from './popupReceiver.js';
12
+ export { normalizeStateNodeId } from './ids.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,cAAc,EACd,eAAe,EACf,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,OAAO,GACR,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,WAAW,EACX,SAAS,EACT,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shared viz presentation model + wire protocol.
3
+ *
4
+ * Host projects into Viz*; visualizer renders Viz*. No XState here.
5
+ */
6
+ export { isVizActorRefMarker } from './model.js';
7
+ export { VIZ_CHANNEL, VIZ_PROTOCOL_VERSION, VIZ_WINDOW_NAME, isVizMessage, toPortable, } from './protocol.js';
8
+ export { connectPopupReceiver, } from './popupReceiver.js';
9
+ export { normalizeStateNodeId } from './ids.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+BH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAIjD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,UAAU,GAIX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,oBAAoB,GAErB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Shared viz presentation model — spoken by the host projector and the popup UI.
3
+ * No XState structural types here; those stay behind `projectMachine` / `projectFrame`.
4
+ */
5
+ import type { ContextDepGraph } from './contextDeps.js';
6
+ export interface VizMachine {
7
+ sessionId: string;
8
+ /** Display name (machine id or fallback). */
9
+ label: string;
10
+ /** Parent actor session when this machine was invoked/spawned. */
11
+ parentSessionId?: string;
12
+ /** Actor input captured at registration (portable / sanitized). */
13
+ input?: unknown;
14
+ /** Machine root as a tree. */
15
+ root: VizNode;
16
+ /** Static analyses computed against live logic on the host. */
17
+ analysis: VizAnalysis;
18
+ }
19
+ /**
20
+ * Portable stand-in for a live ActorRef in scrubbed context.
21
+ * Host replaces refs before postMessage so sessionId survives JSON.
22
+ */
23
+ export interface VizActorRefMarker {
24
+ __viz: 'actorRef';
25
+ sessionId: string;
26
+ id: string;
27
+ }
28
+ export declare function isVizActorRefMarker(value: unknown): value is VizActorRefMarker;
29
+ export interface VizNode {
30
+ id: string;
31
+ key: string;
32
+ kind: VizNodeKind;
33
+ /** Child layout hint — already decided from XState compound vs parallel. */
34
+ layout: 'sequential' | 'parallel' | 'none';
35
+ children: VizNode[];
36
+ /** Which child ids are initial targets (for arrow glyph). */
37
+ initialChildIds: string[];
38
+ /** Compact badges — no raw entry/exit arrays. */
39
+ badges: VizBadge[];
40
+ /** Ordinary named events (not after/always — those are badges + details). */
41
+ events: VizEvent[];
42
+ /** Longer copy for watch cards / hover — still viz vocabulary. */
43
+ details: VizNodeDetails;
44
+ }
45
+ export type VizNodeKind = 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
46
+ export interface VizBadge {
47
+ kind: VizBadgeKind;
48
+ /** Short label on the node chrome. */
49
+ label: string;
50
+ /** Lines for hover tip. */
51
+ lines: string[];
52
+ /** Node ids to highlight while this badge is hovered. */
53
+ highlightIds: string[];
54
+ }
55
+ /**
56
+ * Non-`on` (and lifecycle) markers. Projector maps XState concepts → these.
57
+ * Popup only switches on VizBadgeKind.
58
+ */
59
+ export type VizBadgeKind = 'entry' | 'exit' | 'after' | 'always' | 'invoke' | 'history';
60
+ export interface VizEvent {
61
+ /** Event type string as shown in the UI (`TICK`, not internal keys). */
62
+ type: string;
63
+ /** Ordered transition candidates (guard cascade). */
64
+ transitions: VizTransition[];
65
+ /** Union of all transition targets — for cheap hover highlight. */
66
+ highlightIds: string[];
67
+ /** Lines for hover when guards/actions exist (subset of full transition lines). */
68
+ hoverLines: string[];
69
+ /** Full transition lines for watch-card details. */
70
+ detailLines: string[];
71
+ /** Wildcard / partial annotation for hover only. */
72
+ pattern?: 'exact' | 'wildcard' | 'partial';
73
+ }
74
+ export interface VizTransition {
75
+ /** Target node ids (empty = internal / no target). */
76
+ targetIds: string[];
77
+ guard?: VizSymbol;
78
+ actions: VizSymbol[];
79
+ reenter?: boolean;
80
+ /** Delay label for after-transitions. */
81
+ delayLabel?: string;
82
+ /** Preformatted one-line summary for lists. */
83
+ line: string;
84
+ }
85
+ /** Named executable without the function. */
86
+ export interface VizSymbol {
87
+ kind: 'action' | 'guard' | 'actor' | 'delay';
88
+ name: string;
89
+ /** Optional params summary / assign key list, already stringified. */
90
+ detail?: string;
91
+ }
92
+ export interface VizNodeDetails {
93
+ /** Dot path from machine root keys (`""` = root, `"a.b"` = nested). */
94
+ path: string;
95
+ tags: string[];
96
+ entry: VizSymbol[];
97
+ exit: VizSymbol[];
98
+ after: VizTransition[];
99
+ always: VizTransition[];
100
+ invokes: VizInvoke[];
101
+ history?: 'shallow' | 'deep';
102
+ }
103
+ export interface VizInvoke {
104
+ id: string;
105
+ src: string;
106
+ inputSummary?: string;
107
+ onDone: VizTransition[];
108
+ onError: VizTransition[];
109
+ highlightIds: string[];
110
+ }
111
+ export interface VizAnalysis {
112
+ contextDeps: ContextDepGraph;
113
+ }
114
+ /** Ordered transition candidate for next-events / cond cascade. */
115
+ export interface VizNextEventCandidate {
116
+ providerId: string;
117
+ targetIds: string[];
118
+ guard?: VizSymbol;
119
+ actions: VizSymbol[];
120
+ /** Preformatted one-line summary (`1.` prefix added in UI). */
121
+ line: string;
122
+ }
123
+ /** An event the active configuration can handle, with providing state ids. */
124
+ export interface VizNextEvent {
125
+ type: string;
126
+ /** State node ids that declare a handler (including active ancestors). */
127
+ providerIds: string[];
128
+ /** Guard cascade across providers (definition order within each provider). */
129
+ candidates: VizNextEventCandidate[];
130
+ /** Providers + candidate targets — for hover highlight. */
131
+ highlightIds: string[];
132
+ }
133
+ /** Runtime frame — projected from an inspection snapshot. */
134
+ export interface VizFrame {
135
+ sessionId: string;
136
+ /**
137
+ * Active state paths (key segments from the root), same shape as former
138
+ * `activePaths(value)` — used for graph/watch “you are here” overlay.
139
+ */
140
+ activePaths: string[];
141
+ /** Scrubbed context for the dump panel. */
142
+ context: unknown;
143
+ /** Raw state value for the JSON dump panel. */
144
+ value: unknown;
145
+ status: 'active' | 'done' | 'error' | 'stopped';
146
+ output?: unknown;
147
+ /** Event that produced this frame, if any. */
148
+ eventType?: string;
149
+ /**
150
+ * Events since each top-level context key last changed (0 = changed this
151
+ * frame). Host-tracked so popup replay stays consistent.
152
+ */
153
+ contextKeyAges?: Record<string, number>;
154
+ /** Named events the active configuration can handle (+ providing states). */
155
+ nextEvents?: VizNextEvent[];
156
+ }
157
+ /** Debug log entry (still inspection-flavored for the event log panel). */
158
+ export interface VizLogEntry {
159
+ seq: number;
160
+ type: string;
161
+ sessionId: string;
162
+ eventType?: string;
163
+ value?: unknown;
164
+ at: number;
165
+ }
166
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,8BAA8B;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,+DAA+D;IAC/D,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAO9E;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,4EAA4E;IAC5E,MAAM,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;IAC3C,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,iDAAiD;IACjD,MAAM,EAAE,QAA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,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,2CAA2C;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,+CAA+C;IAC/C,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAChD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,6EAA6E;IAC7E,UAAU,CAAC,EAAE,YAAY,EAAE,CAAC;CAC7B;AAED,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ"}
package/dist/model.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shared viz presentation model — spoken by the host projector and the popup UI.
3
+ * No XState structural types here; those stay behind `projectMachine` / `projectFrame`.
4
+ */
5
+ export function isVizActorRefMarker(value) {
6
+ return (!!value &&
7
+ typeof value === 'object' &&
8
+ value.__viz === 'actorRef' &&
9
+ typeof value.sessionId === 'string');
10
+ }
11
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4BH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACxB,KAA2B,CAAC,KAAK,KAAK,UAAU;QACjD,OAAQ,KAA2B,CAAC,SAAS,KAAK,QAAQ,CAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type VizDownstreamMessage } from './protocol.js';
2
+ export type PopupMessageHandler = (message: VizDownstreamMessage) => void;
3
+ /**
4
+ * Runs inside the popup visualizer. Announces readiness to `window.opener`
5
+ * (the host, which may itself be a nested iframe) and delivers downstream
6
+ * messages to a handler.
7
+ *
8
+ * Does not send `@viz.bye` on React effect cleanup — StrictMode remounts would
9
+ * otherwise clear the host's popup handle while leaving status "connected".
10
+ * Teardown uses `pagehide` (actual close / navigate) instead.
11
+ */
12
+ export declare function connectPopupReceiver(onMessage: PopupMessageHandler): () => void;
13
+ //# sourceMappingURL=popupReceiver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popupReceiver.d.ts","sourceRoot":"","sources":["../src/popupReceiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,oBAAoB,EAE1B,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAE1E;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAgD/E"}
@@ -0,0 +1,55 @@
1
+ import { isVizMessage, VIZ_CHANNEL, VIZ_PROTOCOL_VERSION, } from './protocol.js';
2
+ /**
3
+ * Runs inside the popup visualizer. Announces readiness to `window.opener`
4
+ * (the host, which may itself be a nested iframe) and delivers downstream
5
+ * messages to a handler.
6
+ *
7
+ * Does not send `@viz.bye` on React effect cleanup — StrictMode remounts would
8
+ * otherwise clear the host's popup handle while leaving status "connected".
9
+ * Teardown uses `pagehide` (actual close / navigate) instead.
10
+ */
11
+ export function connectPopupReceiver(onMessage) {
12
+ const handle = (event) => {
13
+ if (!isVizMessage(event.data))
14
+ return;
15
+ const data = event.data;
16
+ if (data.type === '@viz.machine' ||
17
+ data.type === '@viz.frame' ||
18
+ data.type === '@viz.log' ||
19
+ data.type === '@viz.closed') {
20
+ onMessage(data);
21
+ }
22
+ };
23
+ const target = window.opener && !window.opener.closed
24
+ ? window.opener
25
+ : window.parent !== window
26
+ ? window.parent
27
+ : null;
28
+ const sendBye = () => {
29
+ if (!target)
30
+ return;
31
+ const bye = { channel: VIZ_CHANNEL, type: '@viz.bye' };
32
+ try {
33
+ target.postMessage(bye, '*');
34
+ }
35
+ catch {
36
+ // ignore
37
+ }
38
+ };
39
+ window.addEventListener('message', handle);
40
+ // pagehide fires on real close/navigation; not on React StrictMode remount.
41
+ window.addEventListener('pagehide', sendBye);
42
+ if (target) {
43
+ const hello = {
44
+ channel: VIZ_CHANNEL,
45
+ type: '@viz.hello',
46
+ version: VIZ_PROTOCOL_VERSION,
47
+ };
48
+ target.postMessage(hello, '*');
49
+ }
50
+ return () => {
51
+ window.removeEventListener('message', handle);
52
+ window.removeEventListener('pagehide', sendBye);
53
+ };
54
+ }
55
+ //# sourceMappingURL=popupReceiver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popupReceiver.js","sourceRoot":"","sources":["../src/popupReceiver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AAIvB;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA8B;IACjE,MAAM,MAAM,GAAG,CAAC,KAAmB,EAAE,EAAE;QACrC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,OAAO;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACxB,IACE,IAAI,CAAC,IAAI,KAAK,cAAc;YAC5B,IAAI,CAAC,IAAI,KAAK,YAAY;YAC1B,IAAI,CAAC,IAAI,KAAK,UAAU;YACxB,IAAI,CAAC,IAAI,KAAK,aAAa,EAC3B,CAAC;YACD,SAAS,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,MAAM,GACV,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM;QACpC,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM;YACxB,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,IAAI,CAAC;IAEb,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,MAAM,GAAG,GAAuB,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;QAC3E,IAAI,CAAC;YACH,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3C,4EAA4E;IAC5E,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE7C,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,KAAK,GAAuB;YAChC,OAAO,EAAE,WAAW;YACpB,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,oBAAoB;SAC9B,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Cross-window protocol for the visualizer.
3
+ *
4
+ * Transport: `window.postMessage` with targetOrigin `"*"`.
5
+ *
6
+ * Why postMessage (and not BroadcastChannel / SharedWorker / etc.):
7
+ * - Works across origins (hidden iframe on host-A, popup from host-B).
8
+ * - Works when the machine runs inside a sandboxed iframe (given
9
+ * `allow-scripts` + `allow-popups` / `allow-popups-to-escape-sandbox`).
10
+ * - Needs no permissions, service workers, or shared storage.
11
+ * - Same approach used by `@statelyai/inspect`'s BrowserAdapter.
12
+ *
13
+ * Handshake (mirrors Stately's `@statelyai.connected`):
14
+ * 1. Host opens the popup via `window.open` (must be a user gesture).
15
+ * 2. Popup loads and posts `@viz.hello` to `window.opener`.
16
+ * 3. Host marks the link connected and replays deferred payloads
17
+ * (VizMachine + latest VizFrame), then streams live updates.
18
+ *
19
+ * Payloads are already-projected viz models — not raw XState definitions.
20
+ */
21
+ import type { VizFrame, VizLogEntry, VizMachine } from './model.js';
22
+ export declare const VIZ_CHANNEL: "viz";
23
+ export declare const VIZ_PROTOCOL_VERSION: 1;
24
+ /** Namespaced window name so a second open focuses the same popup. */
25
+ export declare const VIZ_WINDOW_NAME = "viz-inspector";
26
+ /** Messages the popup sends to the host. */
27
+ export type VizUpstreamMessage = {
28
+ channel: typeof VIZ_CHANNEL;
29
+ type: '@viz.hello';
30
+ version: typeof VIZ_PROTOCOL_VERSION;
31
+ } | {
32
+ channel: typeof VIZ_CHANNEL;
33
+ type: '@viz.bye';
34
+ };
35
+ /** Messages the host sends to the popup. */
36
+ export type VizDownstreamMessage = {
37
+ channel: typeof VIZ_CHANNEL;
38
+ type: '@viz.machine';
39
+ payload: VizMachine;
40
+ } | {
41
+ channel: typeof VIZ_CHANNEL;
42
+ type: '@viz.frame';
43
+ payload: VizFrame;
44
+ } | {
45
+ channel: typeof VIZ_CHANNEL;
46
+ type: '@viz.log';
47
+ payload: VizLogEntry;
48
+ } | {
49
+ channel: typeof VIZ_CHANNEL;
50
+ type: '@viz.closed';
51
+ };
52
+ export type VizMessage = VizUpstreamMessage | VizDownstreamMessage;
53
+ export declare function isVizMessage(data: unknown): data is VizMessage;
54
+ /**
55
+ * Structured-clone / postMessage–safe serialization.
56
+ * Drops functions and other non-JSON values (should already be gone after
57
+ * projection, but kept as a safety net).
58
+ */
59
+ export declare function toPortable<T>(value: T): T;
60
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpE,eAAO,MAAM,WAAW,EAAG,KAAc,CAAC;AAC1C,eAAO,MAAM,oBAAoB,EAAG,CAAU,CAAC;AAE/C,sEAAsE;AACtE,eAAO,MAAM,eAAe,kBAAkB,CAAC;AAE/C,4CAA4C;AAC5C,MAAM,MAAM,kBAAkB,GAC1B;IACE,OAAO,EAAE,OAAO,WAAW,CAAC;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,OAAO,oBAAoB,CAAC;CACtC,GACD;IACE,OAAO,EAAE,OAAO,WAAW,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEN,4CAA4C;AAC5C,MAAM,MAAM,oBAAoB,GAC5B;IACE,OAAO,EAAE,OAAO,WAAW,CAAC;IAC5B,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC;CACrB,GACD;IACE,OAAO,EAAE,OAAO,WAAW,CAAC;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,QAAQ,CAAC;CACnB,GACD;IACE,OAAO,EAAE,OAAO,WAAW,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;CACtB,GACD;IACE,OAAO,EAAE,OAAO,WAAW,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEN,MAAM,MAAM,UAAU,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AAEnE,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,UAAU,CAS9D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAIzC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Cross-window protocol for the visualizer.
3
+ *
4
+ * Transport: `window.postMessage` with targetOrigin `"*"`.
5
+ *
6
+ * Why postMessage (and not BroadcastChannel / SharedWorker / etc.):
7
+ * - Works across origins (hidden iframe on host-A, popup from host-B).
8
+ * - Works when the machine runs inside a sandboxed iframe (given
9
+ * `allow-scripts` + `allow-popups` / `allow-popups-to-escape-sandbox`).
10
+ * - Needs no permissions, service workers, or shared storage.
11
+ * - Same approach used by `@statelyai/inspect`'s BrowserAdapter.
12
+ *
13
+ * Handshake (mirrors Stately's `@statelyai.connected`):
14
+ * 1. Host opens the popup via `window.open` (must be a user gesture).
15
+ * 2. Popup loads and posts `@viz.hello` to `window.opener`.
16
+ * 3. Host marks the link connected and replays deferred payloads
17
+ * (VizMachine + latest VizFrame), then streams live updates.
18
+ *
19
+ * Payloads are already-projected viz models — not raw XState definitions.
20
+ */
21
+ export const VIZ_CHANNEL = 'viz';
22
+ export const VIZ_PROTOCOL_VERSION = 1;
23
+ /** Namespaced window name so a second open focuses the same popup. */
24
+ export const VIZ_WINDOW_NAME = 'viz-inspector';
25
+ export function isVizMessage(data) {
26
+ return (typeof data === 'object' &&
27
+ data !== null &&
28
+ 'channel' in data &&
29
+ data.channel === VIZ_CHANNEL &&
30
+ 'type' in data &&
31
+ typeof data.type === 'string');
32
+ }
33
+ /**
34
+ * Structured-clone / postMessage–safe serialization.
35
+ * Drops functions and other non-JSON values (should already be gone after
36
+ * projection, but kept as a safety net).
37
+ */
38
+ export function toPortable(value) {
39
+ return JSON.parse(JSON.stringify(value, (_key, v) => (typeof v === 'function' ? undefined : v)));
40
+ }
41
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAc,CAAC;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAE/C,sEAAsE;AACtE,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAsC/C,MAAM,UAAU,YAAY,CAAC,IAAa;IACxC,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,SAAS,IAAI,IAAI;QAChB,IAA6B,CAAC,OAAO,KAAK,WAAW;QACtD,MAAM,IAAI,IAAI;QACd,OAAQ,IAA0B,CAAC,IAAI,KAAK,QAAQ,CACrD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAI,KAAQ;IACpC,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACzE,CAAC;AACT,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Portable snapshot shared by the host store and any visualizer UI.
3
+ */
4
+ import type { VizFrame, VizLogEntry, VizMachine } from './model.js';
5
+ export type HostBridgeStatus = 'idle' | 'opening' | 'awaiting-hello' | 'connected' | 'blocked';
6
+ /**
7
+ * Everything a visualizer UI needs for one tick.
8
+ * Machines and frames are already projected (Viz*), not raw XState shapes.
9
+ */
10
+ export interface VisualizerSnapshot {
11
+ /**
12
+ * Every machine-backed actor observed so far (registration order).
13
+ * Each `@xstate.actor` inspection event adds one; a UI with more than one
14
+ * should offer a selector (prefer parent/child tree when links exist).
15
+ */
16
+ machines: VizMachine[];
17
+ /** Latest projected frame per sessionId. */
18
+ frames: Record<string, VizFrame>;
19
+ log: VizLogEntry[];
20
+ /** Whether an in-page visualizer surface should be shown (caller decides how). */
21
+ inlineVisible: boolean;
22
+ popupStatus: HostBridgeStatus;
23
+ }
24
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,SAAS,GACT,gBAAgB,GAChB,WAAW,GACX,SAAS,CAAC;AAEd;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,GAAG,EAAE,WAAW,EAAE,CAAC;IACnB,kFAAkF;IAClF,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,gBAAgB,CAAC;CAC/B"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Portable snapshot shared by the host store and any visualizer UI.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@r-a-i-t-h/viz-protocol",
3
+ "version": "0.1.0",
4
+ "description": "Shared Viz* model and @viz.* wire types for XState visualizer hosts",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/r-a-i-t-h/viz.git",
10
+ "directory": "packages/protocol"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": ["dist", "LICENSE"],
24
+ "scripts": {
25
+ "build": "tsc -p tsconfig.json",
26
+ "clean": "rm -rf dist"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "~6.0.2"
30
+ }
31
+ }