@seed-ship/mcp-ui-solid 6.4.0 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/README.md +37 -0
  3. package/dist/adapters/connector.cjs +112 -0
  4. package/dist/adapters/connector.cjs.map +1 -0
  5. package/dist/adapters/connector.d.ts +71 -0
  6. package/dist/adapters/connector.d.ts.map +1 -0
  7. package/dist/adapters/connector.js +112 -0
  8. package/dist/adapters/connector.js.map +1 -0
  9. package/dist/adapters/index.d.ts +18 -0
  10. package/dist/adapters/index.d.ts.map +1 -0
  11. package/dist/adapters.cjs +6 -0
  12. package/dist/adapters.cjs.map +1 -0
  13. package/dist/adapters.d.cts +18 -0
  14. package/dist/adapters.d.ts +18 -0
  15. package/dist/adapters.js +6 -0
  16. package/dist/adapters.js.map +1 -0
  17. package/dist/components/ExpandableWrapper.cjs +24 -6
  18. package/dist/components/ExpandableWrapper.cjs.map +1 -1
  19. package/dist/components/ExpandableWrapper.d.ts.map +1 -1
  20. package/dist/components/ExpandableWrapper.js +24 -6
  21. package/dist/components/ExpandableWrapper.js.map +1 -1
  22. package/dist/components/FeedbackInline.cjs +6 -2
  23. package/dist/components/FeedbackInline.cjs.map +1 -1
  24. package/dist/components/FeedbackInline.d.ts +2 -2
  25. package/dist/components/FeedbackInline.d.ts.map +1 -1
  26. package/dist/components/FeedbackInline.js +7 -3
  27. package/dist/components/FeedbackInline.js.map +1 -1
  28. package/dist/components/PresentationFeedback.cjs +207 -0
  29. package/dist/components/PresentationFeedback.cjs.map +1 -0
  30. package/dist/components/PresentationFeedback.d.ts +113 -0
  31. package/dist/components/PresentationFeedback.d.ts.map +1 -0
  32. package/dist/components/PresentationFeedback.js +207 -0
  33. package/dist/components/PresentationFeedback.js.map +1 -0
  34. package/dist/components/StreamingUIRenderer.cjs +82 -195
  35. package/dist/components/StreamingUIRenderer.cjs.map +1 -1
  36. package/dist/components/StreamingUIRenderer.d.ts +25 -5
  37. package/dist/components/StreamingUIRenderer.d.ts.map +1 -1
  38. package/dist/components/StreamingUIRenderer.js +84 -197
  39. package/dist/components/StreamingUIRenderer.js.map +1 -1
  40. package/dist/components/UIResourceRenderer.cjs +40 -10
  41. package/dist/components/UIResourceRenderer.cjs.map +1 -1
  42. package/dist/components/UIResourceRenderer.d.ts +20 -0
  43. package/dist/components/UIResourceRenderer.d.ts.map +1 -1
  44. package/dist/components/UIResourceRenderer.js +42 -12
  45. package/dist/components/UIResourceRenderer.js.map +1 -1
  46. package/dist/components/index.d.ts +2 -0
  47. package/dist/components/index.d.ts.map +1 -1
  48. package/dist/components.cjs +3 -0
  49. package/dist/components.cjs.map +1 -1
  50. package/dist/components.d.cts +2 -0
  51. package/dist/components.d.ts +2 -0
  52. package/dist/components.js +3 -0
  53. package/dist/components.js.map +1 -1
  54. package/dist/context/MCPUIStringsContext.cjs +38 -0
  55. package/dist/context/MCPUIStringsContext.cjs.map +1 -0
  56. package/dist/context/MCPUIStringsContext.d.ts +95 -0
  57. package/dist/context/MCPUIStringsContext.d.ts.map +1 -0
  58. package/dist/context/MCPUIStringsContext.js +38 -0
  59. package/dist/context/MCPUIStringsContext.js.map +1 -0
  60. package/dist/index.cjs +12 -0
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.d.cts +8 -0
  63. package/dist/index.d.ts +8 -0
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +12 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/mcp-ui-spec/dist/schemas.cjs +103 -0
  68. package/dist/mcp-ui-spec/dist/schemas.cjs.map +1 -1
  69. package/dist/mcp-ui-spec/dist/schemas.js +103 -0
  70. package/dist/mcp-ui-spec/dist/schemas.js.map +1 -1
  71. package/dist/utils/duplicate-mount-registry.cjs +27 -0
  72. package/dist/utils/duplicate-mount-registry.cjs.map +1 -0
  73. package/dist/utils/duplicate-mount-registry.d.ts +84 -0
  74. package/dist/utils/duplicate-mount-registry.d.ts.map +1 -0
  75. package/dist/utils/duplicate-mount-registry.js +27 -0
  76. package/dist/utils/duplicate-mount-registry.js.map +1 -0
  77. package/dist/utils/stable-key.cjs +41 -0
  78. package/dist/utils/stable-key.cjs.map +1 -0
  79. package/dist/utils/stable-key.d.ts +33 -0
  80. package/dist/utils/stable-key.d.ts.map +1 -0
  81. package/dist/utils/stable-key.js +41 -0
  82. package/dist/utils/stable-key.js.map +1 -0
  83. package/docs/briefs/ROADMAP-opendata-macro-mcpui.md +912 -0
  84. package/package.json +17 -5
  85. package/src/adapters/connector.test.ts +165 -0
  86. package/src/adapters/connector.ts +234 -0
  87. package/src/adapters/index.ts +24 -0
  88. package/src/components/ExpandableWrapper.test.tsx +5 -2
  89. package/src/components/ExpandableWrapper.tsx +8 -6
  90. package/src/components/FeedbackInline.test.tsx +6 -3
  91. package/src/components/FeedbackInline.tsx +8 -6
  92. package/src/components/PresentationFeedback.test.tsx +163 -0
  93. package/src/components/PresentationFeedback.tsx +326 -0
  94. package/src/components/StreamingUIRenderer.parity.test.tsx +158 -0
  95. package/src/components/StreamingUIRenderer.tsx +42 -166
  96. package/src/components/UIResourceRenderer.identity.test.tsx +161 -0
  97. package/src/components/UIResourceRenderer.tsx +63 -2
  98. package/src/components/index.ts +10 -0
  99. package/src/context/MCPUIStringsContext.test.tsx +116 -0
  100. package/src/context/MCPUIStringsContext.tsx +128 -0
  101. package/src/index.ts +35 -0
  102. package/src/utils/duplicate-mount-registry.test.ts +82 -0
  103. package/src/utils/duplicate-mount-registry.ts +113 -0
  104. package/src/utils/stable-key.test.ts +96 -0
  105. package/src/utils/stable-key.ts +91 -0
  106. package/tsconfig.tsbuildinfo +1 -1
  107. package/vite.config.ts +1 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Opt-in duplicate-mount registry (v6.5.0).
3
+ *
4
+ * Tracks how many times each `getUiResourceStableKey()` has been mounted
5
+ * concurrently across all `<UIResourceRenderer>` instances. When the same
6
+ * key is mounted more than once, registered reporters fire so consumers
7
+ * can detect double-render bugs in their parent framework.
8
+ *
9
+ * **Opt-in by design** : the registry is always populated (cheap), but
10
+ * notifications only fire when a consumer has wired one of the two opt-in
11
+ * paths :
12
+ * - module-level `setDuplicateMountReporter(fn)` (app-wide telemetry)
13
+ * - per-instance `<UIResourceRenderer onMountDuplicate={fn}>` prop
14
+ *
15
+ * **What this does NOT do** : visual deduplication. The renderer never
16
+ * hides or replaces a duplicate mount automatically — that would mask
17
+ * parent-framework bugs and could remove legitimate co-mounts (e.g. drawer
18
+ * + main panel showing the same card). Consumers who want dedup implement
19
+ * it on top of the reported events.
20
+ */
21
+ export interface DuplicateMountInfo {
22
+ /** Stable key from `getUiResourceStableKey(content)`. */
23
+ key: string;
24
+ /**
25
+ * Current concurrent mount count. The reporter fires whenever this
26
+ * crosses 2 (i.e. on the 2nd, 3rd, etc. mount of the same key while
27
+ * earlier mounts are still alive).
28
+ */
29
+ count: number;
30
+ /** `Date.now()` of the FIRST mount of this key (telemetry, not identity). */
31
+ firstMountedAt: number;
32
+ }
33
+ export type DuplicateMountReporter = (info: DuplicateMountInfo) => void;
34
+ /**
35
+ * Wire a module-level reporter for duplicate mount events. Pass `null` to
36
+ * unwire. Only one module reporter at a time (replaces any previous one).
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { setDuplicateMountReporter } from '@seed-ship/mcp-ui-solid'
41
+ *
42
+ * setDuplicateMountReporter(({ key, count }) => {
43
+ * telemetry.warn('mcp-ui.duplicate-mount', { key, count })
44
+ * })
45
+ * ```
46
+ */
47
+ export declare function setDuplicateMountReporter(reporter: DuplicateMountReporter | null): void;
48
+ /**
49
+ * Internal — read by `<UIResourceRenderer>` to dispatch on mount. Not part
50
+ * of the public API.
51
+ *
52
+ * @internal
53
+ */
54
+ export declare function getDuplicateMountReporter(): DuplicateMountReporter | null;
55
+ /**
56
+ * Internal — registers a mount for `key` and returns the resulting state.
57
+ * The caller decides whether to surface a notification based on `count > 1`.
58
+ *
59
+ * @internal
60
+ */
61
+ export declare function _registerMount(key: string): DuplicateMountInfo;
62
+ /**
63
+ * Internal — undoes a prior `_registerMount(key)`. Removes the entry when
64
+ * the count reaches zero so the registry never leaks across mount/unmount
65
+ * cycles of unique keys.
66
+ *
67
+ * @internal
68
+ */
69
+ export declare function _unregisterMount(key: string): void;
70
+ /**
71
+ * Internal — clears the registry and unwires any module reporter. Used by
72
+ * tests to ensure isolation between cases.
73
+ *
74
+ * @internal
75
+ */
76
+ export declare function _resetRegistry(): void;
77
+ /**
78
+ * Internal — read the current count for a key (0 if not mounted). Useful
79
+ * for tests and for consumers building their own debug overlays.
80
+ *
81
+ * @internal
82
+ */
83
+ export declare function _getMountCount(key: string): number;
84
+ //# sourceMappingURL=duplicate-mount-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate-mount-registry.d.ts","sourceRoot":"","sources":["../../src/utils/duplicate-mount-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAA;IACX;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,6EAA6E;IAC7E,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAA;AAKvE;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,GAAG,IAAI,CAEvF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,IAAI,sBAAsB,GAAG,IAAI,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAK9D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAKlD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAGrC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD"}
@@ -0,0 +1,27 @@
1
+ const registry = /* @__PURE__ */ new Map();
2
+ let moduleReporter = null;
3
+ function setDuplicateMountReporter(reporter) {
4
+ moduleReporter = reporter;
5
+ }
6
+ function getDuplicateMountReporter() {
7
+ return moduleReporter;
8
+ }
9
+ function _registerMount(key) {
10
+ const entry = registry.get(key) ?? { count: 0, firstMountedAt: Date.now() };
11
+ entry.count += 1;
12
+ registry.set(key, entry);
13
+ return { key, count: entry.count, firstMountedAt: entry.firstMountedAt };
14
+ }
15
+ function _unregisterMount(key) {
16
+ const entry = registry.get(key);
17
+ if (!entry) return;
18
+ entry.count -= 1;
19
+ if (entry.count <= 0) registry.delete(key);
20
+ }
21
+ export {
22
+ _registerMount,
23
+ _unregisterMount,
24
+ getDuplicateMountReporter,
25
+ setDuplicateMountReporter
26
+ };
27
+ //# sourceMappingURL=duplicate-mount-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate-mount-registry.js","sources":["../../src/utils/duplicate-mount-registry.ts"],"sourcesContent":["/**\n * Opt-in duplicate-mount registry (v6.5.0).\n *\n * Tracks how many times each `getUiResourceStableKey()` has been mounted\n * concurrently across all `<UIResourceRenderer>` instances. When the same\n * key is mounted more than once, registered reporters fire so consumers\n * can detect double-render bugs in their parent framework.\n *\n * **Opt-in by design** : the registry is always populated (cheap), but\n * notifications only fire when a consumer has wired one of the two opt-in\n * paths :\n * - module-level `setDuplicateMountReporter(fn)` (app-wide telemetry)\n * - per-instance `<UIResourceRenderer onMountDuplicate={fn}>` prop\n *\n * **What this does NOT do** : visual deduplication. The renderer never\n * hides or replaces a duplicate mount automatically — that would mask\n * parent-framework bugs and could remove legitimate co-mounts (e.g. drawer\n * + main panel showing the same card). Consumers who want dedup implement\n * it on top of the reported events.\n */\n\nexport interface DuplicateMountInfo {\n /** Stable key from `getUiResourceStableKey(content)`. */\n key: string\n /**\n * Current concurrent mount count. The reporter fires whenever this\n * crosses 2 (i.e. on the 2nd, 3rd, etc. mount of the same key while\n * earlier mounts are still alive).\n */\n count: number\n /** `Date.now()` of the FIRST mount of this key (telemetry, not identity). */\n firstMountedAt: number\n}\n\nexport type DuplicateMountReporter = (info: DuplicateMountInfo) => void\n\nconst registry = new Map<string, { count: number; firstMountedAt: number }>()\nlet moduleReporter: DuplicateMountReporter | null = null\n\n/**\n * Wire a module-level reporter for duplicate mount events. Pass `null` to\n * unwire. Only one module reporter at a time (replaces any previous one).\n *\n * @example\n * ```ts\n * import { setDuplicateMountReporter } from '@seed-ship/mcp-ui-solid'\n *\n * setDuplicateMountReporter(({ key, count }) => {\n * telemetry.warn('mcp-ui.duplicate-mount', { key, count })\n * })\n * ```\n */\nexport function setDuplicateMountReporter(reporter: DuplicateMountReporter | null): void {\n moduleReporter = reporter\n}\n\n/**\n * Internal — read by `<UIResourceRenderer>` to dispatch on mount. Not part\n * of the public API.\n *\n * @internal\n */\nexport function getDuplicateMountReporter(): DuplicateMountReporter | null {\n return moduleReporter\n}\n\n/**\n * Internal — registers a mount for `key` and returns the resulting state.\n * The caller decides whether to surface a notification based on `count > 1`.\n *\n * @internal\n */\nexport function _registerMount(key: string): DuplicateMountInfo {\n const entry = registry.get(key) ?? { count: 0, firstMountedAt: Date.now() }\n entry.count += 1\n registry.set(key, entry)\n return { key, count: entry.count, firstMountedAt: entry.firstMountedAt }\n}\n\n/**\n * Internal — undoes a prior `_registerMount(key)`. Removes the entry when\n * the count reaches zero so the registry never leaks across mount/unmount\n * cycles of unique keys.\n *\n * @internal\n */\nexport function _unregisterMount(key: string): void {\n const entry = registry.get(key)\n if (!entry) return\n entry.count -= 1\n if (entry.count <= 0) registry.delete(key)\n}\n\n/**\n * Internal — clears the registry and unwires any module reporter. Used by\n * tests to ensure isolation between cases.\n *\n * @internal\n */\nexport function _resetRegistry(): void {\n registry.clear()\n moduleReporter = null\n}\n\n/**\n * Internal — read the current count for a key (0 if not mounted). Useful\n * for tests and for consumers building their own debug overlays.\n *\n * @internal\n */\nexport function _getMountCount(key: string): number {\n return registry.get(key)?.count ?? 0\n}\n"],"names":[],"mappings":"AAoCA,MAAM,+BAAe,IAAA;AACrB,IAAI,iBAAgD;AAe7C,SAAS,0BAA0B,UAA+C;AACvF,mBAAiB;AACnB;AAQO,SAAS,4BAA2D;AACzE,SAAO;AACT;AAQO,SAAS,eAAe,KAAiC;AAC9D,QAAM,QAAQ,SAAS,IAAI,GAAG,KAAK,EAAE,OAAO,GAAG,gBAAgB,KAAK,IAAA,EAAI;AACxE,QAAM,SAAS;AACf,WAAS,IAAI,KAAK,KAAK;AACvB,SAAO,EAAE,KAAK,OAAO,MAAM,OAAO,gBAAgB,MAAM,eAAA;AAC1D;AASO,SAAS,iBAAiB,KAAmB;AAClD,QAAM,QAAQ,SAAS,IAAI,GAAG;AAC9B,MAAI,CAAC,MAAO;AACZ,QAAM,SAAS;AACf,MAAI,MAAM,SAAS,EAAG,UAAS,OAAO,GAAG;AAC3C;"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const FNV_OFFSET_BASIS = 2166136261;
4
+ const FNV_PRIME = 16777619;
5
+ function fnv1a(str) {
6
+ let hash = FNV_OFFSET_BASIS;
7
+ for (let i = 0; i < str.length; i++) {
8
+ hash ^= str.charCodeAt(i);
9
+ hash = Math.imul(hash, FNV_PRIME);
10
+ }
11
+ return (hash >>> 0).toString(36).padStart(7, "0");
12
+ }
13
+ function stableStringify(value) {
14
+ if (value === void 0) return "undefined";
15
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
16
+ if (Array.isArray(value)) {
17
+ return "[" + value.map(stableStringify).join(",") + "]";
18
+ }
19
+ const obj = value;
20
+ const keys = Object.keys(obj).sort().filter((k) => obj[k] !== void 0);
21
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
22
+ }
23
+ function normalizeForHash(input) {
24
+ if (!input || typeof input !== "object") return input;
25
+ const { id: _id, ...rest } = input;
26
+ if (rest.metadata && typeof rest.metadata === "object" && !Array.isArray(rest.metadata)) {
27
+ const meta = rest.metadata;
28
+ const { generatedAt: _t, ...metaRest } = meta;
29
+ rest.metadata = Object.keys(metaRest).length > 0 ? metaRest : void 0;
30
+ }
31
+ return rest;
32
+ }
33
+ function getUiResourceStableKey(input) {
34
+ if (input && typeof input === "object") {
35
+ const id = input.id;
36
+ if (typeof id === "string" && id.length > 0) return id;
37
+ }
38
+ return fnv1a(stableStringify(normalizeForHash(input)));
39
+ }
40
+ exports.getUiResourceStableKey = getUiResourceStableKey;
41
+ //# sourceMappingURL=stable-key.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable-key.cjs","sources":["../../src/utils/stable-key.ts"],"sourcesContent":["/**\n * Stable identity key for UIResource payloads (v6.5.0).\n *\n * Consumers need a way to derive a deterministic key from a layout/component\n * payload — for `<For>` keys, dedup detection, telemetry correlation, etc.\n *\n * Spec semantics : `UILayout.id` and `UIComponent.id` are obligatoires for\n * any well-formed payload. When they are present and non-empty, this helper\n * returns them as-is. When they are missing (e.g. consumer passing a \"bare\"\n * chart payload `{ type: 'chart', params: {...} }` without wrapping it in\n * a layout), the helper derives a stable key from the *content* — never\n * from a timestamp or counter.\n *\n * The hash is FNV-1a 32-bit on a deterministically stringified form of the\n * payload (sorted keys, undefined entries skipped). This is intentionally\n * synchronous and dependency-free so consumers can call it inside a Solid\n * memo or render function without ceremony.\n */\n\nconst FNV_OFFSET_BASIS = 0x811c9dc5\nconst FNV_PRIME = 0x01000193\n\nfunction fnv1a(str: string): string {\n let hash = FNV_OFFSET_BASIS\n for (let i = 0; i < str.length; i++) {\n hash ^= str.charCodeAt(i)\n hash = Math.imul(hash, FNV_PRIME)\n }\n return (hash >>> 0).toString(36).padStart(7, '0')\n}\n\n/**\n * Deterministic JSON-like serialization. Object keys are sorted ; entries\n * with `undefined` values are skipped (mirroring `JSON.stringify` semantics\n * but with a stable order). Used as the input to `fnv1a()`.\n */\nfunction stableStringify(value: unknown): string {\n if (value === undefined) return 'undefined'\n if (value === null || typeof value !== 'object') return JSON.stringify(value)\n if (Array.isArray(value)) {\n return '[' + value.map(stableStringify).join(',') + ']'\n }\n const obj = value as Record<string, unknown>\n const keys = Object.keys(obj)\n .sort()\n .filter((k) => obj[k] !== undefined)\n return (\n '{' +\n keys.map((k) => JSON.stringify(k) + ':' + stableStringify(obj[k])).join(',') +\n '}'\n )\n}\n\n/**\n * Strip fields that should NOT contribute to identity :\n * - top-level `id` : we're computing the absent identity\n * - `metadata.generatedAt` : timestamp of generation, not of identity\n */\nfunction normalizeForHash(input: unknown): unknown {\n if (!input || typeof input !== 'object') return input\n const { id: _id, ...rest } = input as Record<string, unknown>\n void _id\n if (rest.metadata && typeof rest.metadata === 'object' && !Array.isArray(rest.metadata)) {\n const meta = rest.metadata as Record<string, unknown>\n const { generatedAt: _t, ...metaRest } = meta\n void _t\n rest.metadata = Object.keys(metaRest).length > 0 ? metaRest : undefined\n }\n return rest\n}\n\n/**\n * Returns a stable identity key for a UIResource payload.\n *\n * - If `input.id` is a non-empty string, returns it verbatim. This is the\n * path taken by well-formed payloads (cf. spec §Identity).\n * - Otherwise, returns a 7-char base36 FNV-1a hash of the normalized\n * content. Stable across renders, identical for structurally identical\n * payloads.\n *\n * The hash is NOT cryptographic ; it's a dedup/correlation key. Collisions\n * are theoretically possible but vanishingly rare for the payload shapes\n * MCP-UI emits in practice.\n */\nexport function getUiResourceStableKey(input: unknown): string {\n if (input && typeof input === 'object') {\n const id = (input as { id?: unknown }).id\n if (typeof id === 'string' && id.length > 0) return id\n }\n return fnv1a(stableStringify(normalizeForHash(input)))\n}\n"],"names":[],"mappings":";;AAmBA,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAElB,SAAS,MAAM,KAAqB;AAClC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,YAAQ,IAAI,WAAW,CAAC;AACxB,WAAO,KAAK,KAAK,MAAM,SAAS;AAAA,EAClC;AACA,UAAQ,SAAS,GAAG,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAClD;AAOA,SAAS,gBAAgB,OAAwB;AAC/C,MAAI,UAAU,OAAW,QAAO;AAChC,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO,KAAK,UAAU,KAAK;AAC5E,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,MAAM,IAAI,eAAe,EAAE,KAAK,GAAG,IAAI;AAAA,EACtD;AACA,QAAM,MAAM;AACZ,QAAM,OAAO,OAAO,KAAK,GAAG,EACzB,KAAA,EACA,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,MAAS;AACrC,SACE,MACA,KAAK,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,IAAI,MAAM,gBAAgB,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,IAC3E;AAEJ;AAOA,SAAS,iBAAiB,OAAyB;AACjD,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,EAAE,IAAI,KAAK,GAAG,SAAS;AAE7B,MAAI,KAAK,YAAY,OAAO,KAAK,aAAa,YAAY,CAAC,MAAM,QAAQ,KAAK,QAAQ,GAAG;AACvF,UAAM,OAAO,KAAK;AAClB,UAAM,EAAE,aAAa,IAAI,GAAG,aAAa;AAEzC,SAAK,WAAW,OAAO,KAAK,QAAQ,EAAE,SAAS,IAAI,WAAW;AAAA,EAChE;AACA,SAAO;AACT;AAeO,SAAS,uBAAuB,OAAwB;AAC7D,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,KAAM,MAA2B;AACvC,QAAI,OAAO,OAAO,YAAY,GAAG,SAAS,EAAG,QAAO;AAAA,EACtD;AACA,SAAO,MAAM,gBAAgB,iBAAiB,KAAK,CAAC,CAAC;AACvD;;"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Stable identity key for UIResource payloads (v6.5.0).
3
+ *
4
+ * Consumers need a way to derive a deterministic key from a layout/component
5
+ * payload — for `<For>` keys, dedup detection, telemetry correlation, etc.
6
+ *
7
+ * Spec semantics : `UILayout.id` and `UIComponent.id` are obligatoires for
8
+ * any well-formed payload. When they are present and non-empty, this helper
9
+ * returns them as-is. When they are missing (e.g. consumer passing a "bare"
10
+ * chart payload `{ type: 'chart', params: {...} }` without wrapping it in
11
+ * a layout), the helper derives a stable key from the *content* — never
12
+ * from a timestamp or counter.
13
+ *
14
+ * The hash is FNV-1a 32-bit on a deterministically stringified form of the
15
+ * payload (sorted keys, undefined entries skipped). This is intentionally
16
+ * synchronous and dependency-free so consumers can call it inside a Solid
17
+ * memo or render function without ceremony.
18
+ */
19
+ /**
20
+ * Returns a stable identity key for a UIResource payload.
21
+ *
22
+ * - If `input.id` is a non-empty string, returns it verbatim. This is the
23
+ * path taken by well-formed payloads (cf. spec §Identity).
24
+ * - Otherwise, returns a 7-char base36 FNV-1a hash of the normalized
25
+ * content. Stable across renders, identical for structurally identical
26
+ * payloads.
27
+ *
28
+ * The hash is NOT cryptographic ; it's a dedup/correlation key. Collisions
29
+ * are theoretically possible but vanishingly rare for the payload shapes
30
+ * MCP-UI emits in practice.
31
+ */
32
+ export declare function getUiResourceStableKey(input: unknown): string;
33
+ //# sourceMappingURL=stable-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable-key.d.ts","sourceRoot":"","sources":["../../src/utils/stable-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAsDH;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAM7D"}
@@ -0,0 +1,41 @@
1
+ const FNV_OFFSET_BASIS = 2166136261;
2
+ const FNV_PRIME = 16777619;
3
+ function fnv1a(str) {
4
+ let hash = FNV_OFFSET_BASIS;
5
+ for (let i = 0; i < str.length; i++) {
6
+ hash ^= str.charCodeAt(i);
7
+ hash = Math.imul(hash, FNV_PRIME);
8
+ }
9
+ return (hash >>> 0).toString(36).padStart(7, "0");
10
+ }
11
+ function stableStringify(value) {
12
+ if (value === void 0) return "undefined";
13
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
14
+ if (Array.isArray(value)) {
15
+ return "[" + value.map(stableStringify).join(",") + "]";
16
+ }
17
+ const obj = value;
18
+ const keys = Object.keys(obj).sort().filter((k) => obj[k] !== void 0);
19
+ return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
20
+ }
21
+ function normalizeForHash(input) {
22
+ if (!input || typeof input !== "object") return input;
23
+ const { id: _id, ...rest } = input;
24
+ if (rest.metadata && typeof rest.metadata === "object" && !Array.isArray(rest.metadata)) {
25
+ const meta = rest.metadata;
26
+ const { generatedAt: _t, ...metaRest } = meta;
27
+ rest.metadata = Object.keys(metaRest).length > 0 ? metaRest : void 0;
28
+ }
29
+ return rest;
30
+ }
31
+ function getUiResourceStableKey(input) {
32
+ if (input && typeof input === "object") {
33
+ const id = input.id;
34
+ if (typeof id === "string" && id.length > 0) return id;
35
+ }
36
+ return fnv1a(stableStringify(normalizeForHash(input)));
37
+ }
38
+ export {
39
+ getUiResourceStableKey
40
+ };
41
+ //# sourceMappingURL=stable-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stable-key.js","sources":["../../src/utils/stable-key.ts"],"sourcesContent":["/**\n * Stable identity key for UIResource payloads (v6.5.0).\n *\n * Consumers need a way to derive a deterministic key from a layout/component\n * payload — for `<For>` keys, dedup detection, telemetry correlation, etc.\n *\n * Spec semantics : `UILayout.id` and `UIComponent.id` are obligatoires for\n * any well-formed payload. When they are present and non-empty, this helper\n * returns them as-is. When they are missing (e.g. consumer passing a \"bare\"\n * chart payload `{ type: 'chart', params: {...} }` without wrapping it in\n * a layout), the helper derives a stable key from the *content* — never\n * from a timestamp or counter.\n *\n * The hash is FNV-1a 32-bit on a deterministically stringified form of the\n * payload (sorted keys, undefined entries skipped). This is intentionally\n * synchronous and dependency-free so consumers can call it inside a Solid\n * memo or render function without ceremony.\n */\n\nconst FNV_OFFSET_BASIS = 0x811c9dc5\nconst FNV_PRIME = 0x01000193\n\nfunction fnv1a(str: string): string {\n let hash = FNV_OFFSET_BASIS\n for (let i = 0; i < str.length; i++) {\n hash ^= str.charCodeAt(i)\n hash = Math.imul(hash, FNV_PRIME)\n }\n return (hash >>> 0).toString(36).padStart(7, '0')\n}\n\n/**\n * Deterministic JSON-like serialization. Object keys are sorted ; entries\n * with `undefined` values are skipped (mirroring `JSON.stringify` semantics\n * but with a stable order). Used as the input to `fnv1a()`.\n */\nfunction stableStringify(value: unknown): string {\n if (value === undefined) return 'undefined'\n if (value === null || typeof value !== 'object') return JSON.stringify(value)\n if (Array.isArray(value)) {\n return '[' + value.map(stableStringify).join(',') + ']'\n }\n const obj = value as Record<string, unknown>\n const keys = Object.keys(obj)\n .sort()\n .filter((k) => obj[k] !== undefined)\n return (\n '{' +\n keys.map((k) => JSON.stringify(k) + ':' + stableStringify(obj[k])).join(',') +\n '}'\n )\n}\n\n/**\n * Strip fields that should NOT contribute to identity :\n * - top-level `id` : we're computing the absent identity\n * - `metadata.generatedAt` : timestamp of generation, not of identity\n */\nfunction normalizeForHash(input: unknown): unknown {\n if (!input || typeof input !== 'object') return input\n const { id: _id, ...rest } = input as Record<string, unknown>\n void _id\n if (rest.metadata && typeof rest.metadata === 'object' && !Array.isArray(rest.metadata)) {\n const meta = rest.metadata as Record<string, unknown>\n const { generatedAt: _t, ...metaRest } = meta\n void _t\n rest.metadata = Object.keys(metaRest).length > 0 ? metaRest : undefined\n }\n return rest\n}\n\n/**\n * Returns a stable identity key for a UIResource payload.\n *\n * - If `input.id` is a non-empty string, returns it verbatim. This is the\n * path taken by well-formed payloads (cf. spec §Identity).\n * - Otherwise, returns a 7-char base36 FNV-1a hash of the normalized\n * content. Stable across renders, identical for structurally identical\n * payloads.\n *\n * The hash is NOT cryptographic ; it's a dedup/correlation key. Collisions\n * are theoretically possible but vanishingly rare for the payload shapes\n * MCP-UI emits in practice.\n */\nexport function getUiResourceStableKey(input: unknown): string {\n if (input && typeof input === 'object') {\n const id = (input as { id?: unknown }).id\n if (typeof id === 'string' && id.length > 0) return id\n }\n return fnv1a(stableStringify(normalizeForHash(input)))\n}\n"],"names":[],"mappings":"AAmBA,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAElB,SAAS,MAAM,KAAqB;AAClC,MAAI,OAAO;AACX,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,YAAQ,IAAI,WAAW,CAAC;AACxB,WAAO,KAAK,KAAK,MAAM,SAAS;AAAA,EAClC;AACA,UAAQ,SAAS,GAAG,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAClD;AAOA,SAAS,gBAAgB,OAAwB;AAC/C,MAAI,UAAU,OAAW,QAAO;AAChC,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO,KAAK,UAAU,KAAK;AAC5E,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,MAAM,IAAI,eAAe,EAAE,KAAK,GAAG,IAAI;AAAA,EACtD;AACA,QAAM,MAAM;AACZ,QAAM,OAAO,OAAO,KAAK,GAAG,EACzB,KAAA,EACA,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,MAAS;AACrC,SACE,MACA,KAAK,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,IAAI,MAAM,gBAAgB,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,IAC3E;AAEJ;AAOA,SAAS,iBAAiB,OAAyB;AACjD,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,EAAE,IAAI,KAAK,GAAG,SAAS;AAE7B,MAAI,KAAK,YAAY,OAAO,KAAK,aAAa,YAAY,CAAC,MAAM,QAAQ,KAAK,QAAQ,GAAG;AACvF,UAAM,OAAO,KAAK;AAClB,UAAM,EAAE,aAAa,IAAI,GAAG,aAAa;AAEzC,SAAK,WAAW,OAAO,KAAK,QAAQ,EAAE,SAAS,IAAI,WAAW;AAAA,EAChE;AACA,SAAO;AACT;AAeO,SAAS,uBAAuB,OAAwB;AAC7D,MAAI,SAAS,OAAO,UAAU,UAAU;AACtC,UAAM,KAAM,MAA2B;AACvC,QAAI,OAAO,OAAO,YAAY,GAAG,SAAS,EAAG,QAAO;AAAA,EACtD;AACA,SAAO,MAAM,gBAAgB,iBAAiB,KAAK,CAAC,CAAC;AACvD;"}