dreamboard 0.1.21 → 0.1.22

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 (186) hide show
  1. package/dist/{chunk-EYYWGWTO.js → chunk-2RCUHMGL.js} +343 -1911
  2. package/dist/chunk-2RCUHMGL.js.map +1 -0
  3. package/dist/{chunk-MOVHYB6E.js → chunk-AQ5UUNJS.js} +1018 -692
  4. package/dist/chunk-AQ5UUNJS.js.map +1 -0
  5. package/dist/{chunk-BMYC6772.js → chunk-H3O43F5P.js} +9765 -3068
  6. package/dist/chunk-H3O43F5P.js.map +1 -0
  7. package/dist/dev-host/dev-api-proxy-plugin.ts +330 -0
  8. package/dist/dev-host/dev-diagnostics.ts +62 -0
  9. package/dist/dev-host/dev-fallback-stylesheet.ts +50 -0
  10. package/dist/dev-host/dev-host-controller.ts +686 -0
  11. package/dist/dev-host/dev-host-player-query.ts +17 -0
  12. package/dist/dev-host/dev-host-session-transport.ts +52 -0
  13. package/dist/dev-host/dev-host-storage.ts +56 -0
  14. package/dist/dev-host/dev-log-relay-plugin.ts +469 -0
  15. package/dist/dev-host/dev-runtime-config.ts +14 -0
  16. package/dist/dev-host/dev-runtime-platform.ts +419 -0
  17. package/dist/dev-host/dev-virtual-modules-plugin.ts +63 -0
  18. package/dist/dev-host/host-main.css +182 -0
  19. package/dist/dev-host/host-main.tsx +754 -0
  20. package/dist/dev-host/index.html +56 -0
  21. package/dist/dev-host/plugin-main.ts +55 -0
  22. package/dist/dev-host/plugin.html +24 -0
  23. package/dist/dev-host/start-dev-server.ts +138 -0
  24. package/dist/dev-host/virtual-modules.d.ts +27 -0
  25. package/dist/dist-FEPN3BDN.js +16543 -0
  26. package/dist/dist-FEPN3BDN.js.map +1 -0
  27. package/dist/{dist-WJRJNFLI.js → dist-FRURQI7Q.js} +4 -2
  28. package/dist/index.js +3 -3
  29. package/dist/internal.js +159 -124
  30. package/dist/internal.js.map +1 -1
  31. package/dist/runtime-packages/tailwind-config/shared-styles.css +146 -0
  32. package/dist/runtime-packages/ui/src/components/.gitkeep +0 -0
  33. package/dist/runtime-packages/ui/src/components/accordion.tsx +66 -0
  34. package/dist/runtime-packages/ui/src/components/ai-elements/actions.tsx +65 -0
  35. package/dist/runtime-packages/ui/src/components/ai-elements/artifact.tsx +147 -0
  36. package/dist/runtime-packages/ui/src/components/ai-elements/branch.tsx +215 -0
  37. package/dist/runtime-packages/ui/src/components/ai-elements/canvas.tsx +22 -0
  38. package/dist/runtime-packages/ui/src/components/ai-elements/chain-of-thought.tsx +228 -0
  39. package/dist/runtime-packages/ui/src/components/ai-elements/code-block.tsx +179 -0
  40. package/dist/runtime-packages/ui/src/components/ai-elements/confirmation.tsx +158 -0
  41. package/dist/runtime-packages/ui/src/components/ai-elements/connection.tsx +28 -0
  42. package/dist/runtime-packages/ui/src/components/ai-elements/context.tsx +408 -0
  43. package/dist/runtime-packages/ui/src/components/ai-elements/controls.tsx +18 -0
  44. package/dist/runtime-packages/ui/src/components/ai-elements/conversation.tsx +97 -0
  45. package/dist/runtime-packages/ui/src/components/ai-elements/edge.tsx +140 -0
  46. package/dist/runtime-packages/ui/src/components/ai-elements/image.tsx +24 -0
  47. package/dist/runtime-packages/ui/src/components/ai-elements/inline-citation.tsx +287 -0
  48. package/dist/runtime-packages/ui/src/components/ai-elements/loader.tsx +96 -0
  49. package/dist/runtime-packages/ui/src/components/ai-elements/message.tsx +463 -0
  50. package/dist/runtime-packages/ui/src/components/ai-elements/node.tsx +71 -0
  51. package/dist/runtime-packages/ui/src/components/ai-elements/open-in-chat.tsx +365 -0
  52. package/dist/runtime-packages/ui/src/components/ai-elements/panel.tsx +15 -0
  53. package/dist/runtime-packages/ui/src/components/ai-elements/plan.tsx +142 -0
  54. package/dist/runtime-packages/ui/src/components/ai-elements/prompt-input.tsx +1380 -0
  55. package/dist/runtime-packages/ui/src/components/ai-elements/queue.tsx +274 -0
  56. package/dist/runtime-packages/ui/src/components/ai-elements/reasoning.tsx +182 -0
  57. package/dist/runtime-packages/ui/src/components/ai-elements/response.tsx +22 -0
  58. package/dist/runtime-packages/ui/src/components/ai-elements/shimmer.tsx +64 -0
  59. package/dist/runtime-packages/ui/src/components/ai-elements/sources.tsx +77 -0
  60. package/dist/runtime-packages/ui/src/components/ai-elements/suggestion.tsx +53 -0
  61. package/dist/runtime-packages/ui/src/components/ai-elements/task.tsx +87 -0
  62. package/dist/runtime-packages/ui/src/components/ai-elements/tool.tsx +165 -0
  63. package/dist/runtime-packages/ui/src/components/ai-elements/toolbar.tsx +16 -0
  64. package/dist/runtime-packages/ui/src/components/ai-elements/web-preview.tsx +263 -0
  65. package/dist/runtime-packages/ui/src/components/alert-dialog.tsx +157 -0
  66. package/dist/runtime-packages/ui/src/components/alert.tsx +66 -0
  67. package/dist/runtime-packages/ui/src/components/avatar.tsx +53 -0
  68. package/dist/runtime-packages/ui/src/components/badge.tsx +46 -0
  69. package/dist/runtime-packages/ui/src/components/button-group.tsx +83 -0
  70. package/dist/runtime-packages/ui/src/components/button.tsx +65 -0
  71. package/dist/runtime-packages/ui/src/components/card.tsx +92 -0
  72. package/dist/runtime-packages/ui/src/components/carousel.tsx +241 -0
  73. package/dist/runtime-packages/ui/src/components/collapsible.tsx +33 -0
  74. package/dist/runtime-packages/ui/src/components/command.tsx +184 -0
  75. package/dist/runtime-packages/ui/src/components/context-menu.tsx +252 -0
  76. package/dist/runtime-packages/ui/src/components/counter.tsx +11 -0
  77. package/dist/runtime-packages/ui/src/components/dialog.tsx +146 -0
  78. package/dist/runtime-packages/ui/src/components/drawer.tsx +132 -0
  79. package/dist/runtime-packages/ui/src/components/dropdown-menu.tsx +257 -0
  80. package/dist/runtime-packages/ui/src/components/form.tsx +168 -0
  81. package/dist/runtime-packages/ui/src/components/header.tsx +13 -0
  82. package/dist/runtime-packages/ui/src/components/hover-card.tsx +44 -0
  83. package/dist/runtime-packages/ui/src/components/input-group.tsx +178 -0
  84. package/dist/runtime-packages/ui/src/components/input.tsx +21 -0
  85. package/dist/runtime-packages/ui/src/components/item.tsx +193 -0
  86. package/dist/runtime-packages/ui/src/components/label.tsx +24 -0
  87. package/dist/runtime-packages/ui/src/components/navigation-menu.tsx +168 -0
  88. package/dist/runtime-packages/ui/src/components/popover.tsx +55 -0
  89. package/dist/runtime-packages/ui/src/components/progress.tsx +31 -0
  90. package/dist/runtime-packages/ui/src/components/radio-group.tsx +45 -0
  91. package/dist/runtime-packages/ui/src/components/resizable.tsx +56 -0
  92. package/dist/runtime-packages/ui/src/components/scroll-area.tsx +58 -0
  93. package/dist/runtime-packages/ui/src/components/select.tsx +187 -0
  94. package/dist/runtime-packages/ui/src/components/separator.tsx +28 -0
  95. package/dist/runtime-packages/ui/src/components/skeleton.tsx +13 -0
  96. package/dist/runtime-packages/ui/src/components/sonner.tsx +25 -0
  97. package/dist/runtime-packages/ui/src/components/spinner.tsx +16 -0
  98. package/dist/runtime-packages/ui/src/components/switch.tsx +31 -0
  99. package/dist/runtime-packages/ui/src/components/table.tsx +137 -0
  100. package/dist/runtime-packages/ui/src/components/tabs.tsx +74 -0
  101. package/dist/runtime-packages/ui/src/components/textarea.tsx +23 -0
  102. package/dist/runtime-packages/ui/src/components/theme-provider.tsx +73 -0
  103. package/dist/runtime-packages/ui/src/components/tooltip.tsx +61 -0
  104. package/dist/runtime-packages/ui/src/components/ui/file-upload.tsx +195 -0
  105. package/dist/runtime-packages/ui/src/hooks/.gitkeep +0 -0
  106. package/dist/runtime-packages/ui/src/index.ts +68 -0
  107. package/dist/runtime-packages/ui/src/lib/utils.ts +6 -0
  108. package/dist/runtime-packages/ui-host-runtime/src/actor-principal.ts +68 -0
  109. package/dist/runtime-packages/ui-host-runtime/src/components/host-controls.tsx +359 -0
  110. package/dist/runtime-packages/ui-host-runtime/src/components/host-feedback-toaster.tsx +274 -0
  111. package/dist/runtime-packages/ui-host-runtime/src/components/host-feedback.tsx +214 -0
  112. package/dist/runtime-packages/ui-host-runtime/src/components/host-session-metadata.tsx +135 -0
  113. package/dist/runtime-packages/ui-host-runtime/src/components/index.ts +5 -0
  114. package/dist/runtime-packages/ui-host-runtime/src/components/perf-overlay.tsx +194 -0
  115. package/dist/runtime-packages/ui-host-runtime/src/host-controls.tsx +1 -0
  116. package/dist/runtime-packages/ui-host-runtime/src/host-feedback.tsx +1 -0
  117. package/dist/runtime-packages/ui-host-runtime/src/host-session-transport.ts +162 -0
  118. package/dist/runtime-packages/ui-host-runtime/src/index.ts +2 -0
  119. package/dist/runtime-packages/ui-host-runtime/src/logger.ts +11 -0
  120. package/dist/runtime-packages/ui-host-runtime/src/perf.ts +253 -0
  121. package/dist/runtime-packages/ui-host-runtime/src/plugin-bridge.ts +195 -0
  122. package/dist/runtime-packages/ui-host-runtime/src/plugin-health-check.ts +138 -0
  123. package/dist/runtime-packages/ui-host-runtime/src/plugin-messages.ts +159 -0
  124. package/dist/runtime-packages/ui-host-runtime/src/plugin-session-gateway.ts +524 -0
  125. package/dist/runtime-packages/ui-host-runtime/src/runtime/index.ts +12 -0
  126. package/dist/runtime-packages/ui-host-runtime/src/screenshot/projection-to-snapshot.ts +122 -0
  127. package/dist/runtime-packages/ui-host-runtime/src/screenshot/static-store-api.ts +26 -0
  128. package/dist/runtime-packages/ui-host-runtime/src/session-ingress-controller.ts +477 -0
  129. package/dist/runtime-packages/ui-host-runtime/src/session-ingress.ts +209 -0
  130. package/dist/runtime-packages/ui-host-runtime/src/session-live-runtime.ts +112 -0
  131. package/dist/runtime-packages/ui-host-runtime/src/session-model.ts +318 -0
  132. package/dist/runtime-packages/ui-host-runtime/src/session-projection.ts +211 -0
  133. package/dist/runtime-packages/ui-host-runtime/src/session-state-reducer.ts +814 -0
  134. package/dist/runtime-packages/ui-host-runtime/src/sse-manager.ts +334 -0
  135. package/dist/runtime-packages/ui-host-runtime/src/unified-session-store.ts +180 -0
  136. package/dist/scaffold/assets/static/app/tsconfig.framework.json +3 -1
  137. package/dist/scaffold/assets/static/ui/tsconfig.framework.json +7 -19
  138. package/package.json +52 -17
  139. package/skills/dreamboard/SKILL.md +41 -75
  140. package/LICENSE +0 -89
  141. package/NOTICE +0 -1
  142. package/dist/chunk-BMYC6772.js.map +0 -1
  143. package/dist/chunk-EYYWGWTO.js.map +0 -1
  144. package/dist/chunk-MOVHYB6E.js.map +0 -1
  145. package/dist/scaffold/assets/static/ui/App.tsx +0 -22
  146. package/dist/src-CUL7EGGG.js +0 -634
  147. package/dist/src-CUL7EGGG.js.map +0 -1
  148. package/skills/dreamboard/references/authoring-lifecycle.md +0 -102
  149. package/skills/dreamboard/references/board-surfaces.md +0 -36
  150. package/skills/dreamboard/references/board-topology.md +0 -443
  151. package/skills/dreamboard/references/boards-and-topology.md +0 -100
  152. package/skills/dreamboard/references/card-actions.md +0 -107
  153. package/skills/dreamboard/references/cli.md +0 -120
  154. package/skills/dreamboard/references/core-concepts.md +0 -514
  155. package/skills/dreamboard/references/custom-renderers.md +0 -26
  156. package/skills/dreamboard/references/derived-values.md +0 -55
  157. package/skills/dreamboard/references/effects.md +0 -111
  158. package/skills/dreamboard/references/game-contract.md +0 -89
  159. package/skills/dreamboard/references/game-definition.md +0 -89
  160. package/skills/dreamboard/references/game-shell.md +0 -80
  161. package/skills/dreamboard/references/hand-surfaces.md +0 -33
  162. package/skills/dreamboard/references/index.md +0 -112
  163. package/skills/dreamboard/references/inputs-and-targets.md +0 -160
  164. package/skills/dreamboard/references/interactions.md +0 -158
  165. package/skills/dreamboard/references/manifest-fields.md +0 -137
  166. package/skills/dreamboard/references/manifest.md +0 -81
  167. package/skills/dreamboard/references/package-surfaces.md +0 -69
  168. package/skills/dreamboard/references/phases.md +0 -145
  169. package/skills/dreamboard/references/prompts-and-choices.md +0 -55
  170. package/skills/dreamboard/references/quickstart.md +0 -71
  171. package/skills/dreamboard/references/rule-authoring.md +0 -144
  172. package/skills/dreamboard/references/setup-bootstrap.md +0 -78
  173. package/skills/dreamboard/references/stages-and-zones.md +0 -59
  174. package/skills/dreamboard/references/static-views.md +0 -67
  175. package/skills/dreamboard/references/table-queries-and-ops.md +0 -103
  176. package/skills/dreamboard/references/testing-bases.md +0 -147
  177. package/skills/dreamboard/references/testing-generated-contracts.md +0 -142
  178. package/skills/dreamboard/references/testing-runtime-assertions.md +0 -124
  179. package/skills/dreamboard/references/testing-scenarios.md +0 -148
  180. package/skills/dreamboard/references/testing-ui-tests.md +0 -174
  181. package/skills/dreamboard/references/testing.md +0 -161
  182. package/skills/dreamboard/references/ui-architecture.md +0 -137
  183. package/skills/dreamboard/references/ui-components.md +0 -34
  184. package/skills/dreamboard/references/views.md +0 -72
  185. package/skills/dreamboard/references/workspace-layout.md +0 -136
  186. /package/dist/{dist-WJRJNFLI.js.map → dist-FRURQI7Q.js.map} +0 -0
@@ -0,0 +1,138 @@
1
+ import { PluginBridge } from "./plugin-bridge.js";
2
+ import type { LoggerLike } from "./logger.js";
3
+ import { consoleLogger } from "./logger.js";
4
+
5
+ export interface HealthCheckConfig {
6
+ pingInterval: number;
7
+ pongTimeout: number;
8
+ maxMissedPongs: number;
9
+ }
10
+
11
+ const DEFAULT_CONFIG: HealthCheckConfig = {
12
+ pingInterval: 5000,
13
+ pongTimeout: 2000,
14
+ maxMissedPongs: 3,
15
+ };
16
+
17
+ export class PluginHealthCheck {
18
+ private bridge: PluginBridge;
19
+ private config: HealthCheckConfig;
20
+ private onUnhealthy: () => void;
21
+ private logger: LoggerLike;
22
+
23
+ private pingIntervalId: ReturnType<typeof setInterval> | null = null;
24
+ private pongTimeoutId: ReturnType<typeof setTimeout> | null = null;
25
+ private missedPongCount = 0;
26
+ private isRunning = false;
27
+ private pongUnsubscribe: (() => void) | null = null;
28
+
29
+ constructor(
30
+ bridge: PluginBridge,
31
+ options: {
32
+ config?: Partial<HealthCheckConfig>;
33
+ onUnhealthy: () => void;
34
+ logger?: LoggerLike;
35
+ },
36
+ ) {
37
+ this.bridge = bridge;
38
+ this.config = { ...DEFAULT_CONFIG, ...options.config };
39
+ this.onUnhealthy = options.onUnhealthy;
40
+ this.logger = options.logger ?? consoleLogger;
41
+ }
42
+
43
+ start(): void {
44
+ if (this.isRunning) {
45
+ this.logger.warn("[HealthCheck] Already running");
46
+ return;
47
+ }
48
+
49
+ this.isRunning = true;
50
+ this.missedPongCount = 0;
51
+
52
+ this.pongUnsubscribe = this.bridge.onPluginMessage("pong", () => {
53
+ this.handlePong();
54
+ });
55
+
56
+ this.pingIntervalId = setInterval(() => {
57
+ this.sendPing();
58
+ }, this.config.pingInterval);
59
+
60
+ this.sendPing();
61
+ }
62
+
63
+ stop(): void {
64
+ if (!this.isRunning) {
65
+ return;
66
+ }
67
+
68
+ this.isRunning = false;
69
+
70
+ if (this.pingIntervalId) {
71
+ clearInterval(this.pingIntervalId);
72
+ this.pingIntervalId = null;
73
+ }
74
+
75
+ if (this.pongTimeoutId) {
76
+ clearTimeout(this.pongTimeoutId);
77
+ this.pongTimeoutId = null;
78
+ }
79
+
80
+ if (this.pongUnsubscribe) {
81
+ this.pongUnsubscribe();
82
+ this.pongUnsubscribe = null;
83
+ }
84
+
85
+ this.missedPongCount = 0;
86
+ this.logger.log("[HealthCheck] Stopped monitoring");
87
+ }
88
+
89
+ private sendPing(): void {
90
+ if (!this.isRunning) {
91
+ return;
92
+ }
93
+
94
+ if (this.pongTimeoutId) {
95
+ clearTimeout(this.pongTimeoutId);
96
+ }
97
+
98
+ this.bridge.sendPing();
99
+
100
+ this.pongTimeoutId = setTimeout(() => {
101
+ this.handleMissedPong();
102
+ }, this.config.pongTimeout);
103
+ }
104
+
105
+ private handlePong(): void {
106
+ if (this.pongTimeoutId) {
107
+ clearTimeout(this.pongTimeoutId);
108
+ this.pongTimeoutId = null;
109
+ }
110
+
111
+ if (this.missedPongCount > 0) {
112
+ this.logger.log("[HealthCheck] Plugin recovered");
113
+ this.missedPongCount = 0;
114
+ }
115
+ }
116
+
117
+ private handleMissedPong(): void {
118
+ this.missedPongCount++;
119
+
120
+ this.logger.warn(
121
+ `[HealthCheck] Missed pong #${this.missedPongCount}/${this.config.maxMissedPongs}`,
122
+ );
123
+
124
+ if (this.missedPongCount >= this.config.maxMissedPongs) {
125
+ this.logger.error("[HealthCheck] Plugin iframe is unresponsive!");
126
+ this.stop();
127
+ this.onUnhealthy();
128
+ }
129
+ }
130
+
131
+ isHealthCheckRunning(): boolean {
132
+ return this.isRunning;
133
+ }
134
+
135
+ getMissedPongCount(): number {
136
+ return this.missedPongCount;
137
+ }
138
+ }
@@ -0,0 +1,159 @@
1
+ import { z } from "zod";
2
+ import type { PluginStateSnapshot } from "@dreamboard/ui-sdk/reducer";
3
+
4
+ export const InitMessageSchema = z.object({
5
+ type: z.literal("init"),
6
+ sessionId: z.string(),
7
+ controllablePlayerIds: z.array(z.string()),
8
+ controllingPlayerId: z.string(),
9
+ userId: z.string().nullable(),
10
+ });
11
+
12
+ export const PingMessageSchema = z.object({
13
+ type: z.literal("ping"),
14
+ });
15
+
16
+ export const StateSyncMessageSchema = z.object({
17
+ type: z.literal("state-sync"),
18
+ syncId: z.number(),
19
+ state: z.custom<PluginStateSnapshot>((data) => {
20
+ return (
21
+ typeof data === "object" &&
22
+ data !== null &&
23
+ "session" in data &&
24
+ "notifications" in data
25
+ );
26
+ }),
27
+ });
28
+
29
+ export const SubmitResultMessageSchema = z.object({
30
+ type: z.literal("submit-result"),
31
+ messageId: z.string(),
32
+ accepted: z.boolean(),
33
+ errorCode: z.string().optional(),
34
+ message: z.string().optional(),
35
+ });
36
+
37
+ export const MainToPluginMessageSchema = z.discriminatedUnion("type", [
38
+ InitMessageSchema,
39
+ PingMessageSchema,
40
+ StateSyncMessageSchema,
41
+ SubmitResultMessageSchema,
42
+ ]);
43
+
44
+ export type MainToPluginMessage = z.infer<typeof MainToPluginMessageSchema>;
45
+
46
+ export const ReadyMessageSchema = z.object({
47
+ type: z.literal("ready"),
48
+ });
49
+
50
+ // `params` is intentionally `z.unknown()` rather than `z.record(...)`. The
51
+ // unified interaction wire carries every player input — actions and prompt
52
+ // responses alike — and the ingress layer's `runtimePayloadSchema` already
53
+ // accepts scalars (`z.boolean() | z.number() | z.string() | z.null() |
54
+ // Array<...> | Record<...>`). Constraining this bridge field to an object
55
+ // would make the host stricter than the ingress it forwards into, which
56
+ // would mask legitimate scalar payloads (e.g. if a future authoring API
57
+ // exposes runtime-opened prompts with a scalar `responseSchema`). Safety
58
+ // still lives downstream: the reducer re-validates prompt responses via
59
+ // `validatePromptResponseInput` and actions via collector schemas, so this
60
+ // widening doesn't weaken end-to-end validation.
61
+ export const InteractionMessageSchema = z.object({
62
+ type: z.literal("interaction"),
63
+ messageId: z.string(),
64
+ playerId: z.string(),
65
+ interactionId: z.string(),
66
+ params: z.unknown(),
67
+ // Optional client-minted correlation id (UUID) that lets the whole
68
+ // click-to-render path be stitched across plugin iframe, web host,
69
+ // backend spans/logs and SSE. Added for Tier-0 input-latency
70
+ // observability; the backend rides it through as an HTTP header
71
+ // (`X-Dreamboard-Client-Action-Id`) but no wire contract changed.
72
+ clientActionId: z.string().optional(),
73
+ // Plugin-iframe `Date.now()` captured right before the postMessage
74
+ // is sent, used as the `t0_click` timestamp on the host-side perf
75
+ // buffer. Date.now() is intentional: the iframe and the host share
76
+ // a wall-clock base, but not a `performance.now()` origin.
77
+ clientSubmittedAtMs: z.number().optional(),
78
+ });
79
+
80
+ export const ValidateInteractionMessageSchema = z.object({
81
+ type: z.literal("validate-interaction"),
82
+ playerId: z.string(),
83
+ interactionId: z.string(),
84
+ params: z.unknown(),
85
+ messageId: z.string(),
86
+ });
87
+
88
+ export const ValidateInteractionResultMessageSchema = z.object({
89
+ type: z.literal("validate-interaction-result"),
90
+ messageId: z.string(),
91
+ result: z.object({
92
+ valid: z.boolean(),
93
+ errorCode: z.string().optional(),
94
+ message: z.string().optional(),
95
+ }),
96
+ });
97
+
98
+ export const PluginErrorMessageSchema = z.object({
99
+ type: z.literal("error"),
100
+ message: z.string(),
101
+ code: z.string().optional(),
102
+ });
103
+
104
+ export const PongMessageSchema = z.object({
105
+ type: z.literal("pong"),
106
+ });
107
+
108
+ export const SwitchPlayerMessageSchema = z.object({
109
+ type: z.literal("switch-player"),
110
+ playerId: z.string(),
111
+ });
112
+
113
+ export const StateAckMessageSchema = z.object({
114
+ type: z.literal("state-ack"),
115
+ syncId: z.number(),
116
+ // Plugin-iframe `Date.now()` captured when the state-sync message
117
+ // was received. Threaded so the host-side perf HUD can compute the
118
+ // `t7_state_sync_received` mark without needing perf to be enabled
119
+ // inside the plugin iframe itself.
120
+ clientReceivedAtMs: z.number().optional(),
121
+ });
122
+
123
+ /**
124
+ * Plugin -> host message sent from a `queueMicrotask` scheduled inside
125
+ * the state-sync handler so the timestamp reflects roughly when React
126
+ * would have committed the DOM update for the new state. Dev-only /
127
+ * perf-only: host records it as `t8_render_commit` on the perf HUD.
128
+ */
129
+ export const StateRenderedMessageSchema = z.object({
130
+ type: z.literal("state-rendered"),
131
+ syncId: z.number(),
132
+ clientReceivedAtMs: z.number(),
133
+ clientRenderedAtMs: z.number(),
134
+ });
135
+
136
+ export const MarkNotificationReadMessageSchema = z.object({
137
+ type: z.literal("mark-notification-read"),
138
+ notificationId: z.string(),
139
+ });
140
+
141
+ export const RestoreHistoryMessageSchema = z.object({
142
+ type: z.literal("restore-history"),
143
+ entryId: z.string(),
144
+ });
145
+
146
+ export const PluginToMainMessageSchema = z.discriminatedUnion("type", [
147
+ ReadyMessageSchema,
148
+ InteractionMessageSchema,
149
+ ValidateInteractionMessageSchema,
150
+ PluginErrorMessageSchema,
151
+ PongMessageSchema,
152
+ SwitchPlayerMessageSchema,
153
+ StateAckMessageSchema,
154
+ StateRenderedMessageSchema,
155
+ MarkNotificationReadMessageSchema,
156
+ RestoreHistoryMessageSchema,
157
+ ]);
158
+
159
+ export type PluginToMainMessage = z.infer<typeof PluginToMainMessageSchema>;