@mastra/playground-ui 71.0.0-alpha.5 → 71.0.0-alpha.6

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.
@@ -22,14 +22,17 @@ var readOnlyRegistry = studioRegistry().registry;
22
22
  * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.
23
23
  */
24
24
  function GenUiInterface({ parts, onSend, disabled = false }) {
25
+ const [wentLive, setWentLive] = (0, react.useState)(false);
26
+ if (onSend && !disabled && !wentLive) setWentLive(true);
25
27
  const spec = (0, _json_render_react.buildSpecFromParts)(structuredClone(parts));
26
28
  if (!spec) return null;
27
29
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
28
30
  "data-slot": "gen-ui-interface",
29
31
  className: "@container min-w-0",
30
- children: onSend && !disabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LiveInterface, {
32
+ children: onSend && (wentLive || !disabled) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LiveInterface, {
31
33
  spec,
32
- onSend
34
+ onSend,
35
+ disabled
33
36
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ReadOnlyInterface, { spec })
34
37
  });
35
38
  }
@@ -44,14 +47,18 @@ function ReadOnlyInterface({ spec }) {
44
47
  });
45
48
  }
46
49
  /**
47
- * Mounts once the interface can act, so its state starts from the complete spec. json-render keeps
48
- * the action handlers it mounts with; the parent switches back to read-only whenever the chat
49
- * replies, so the `onSend` captured here is never older than the current idle chat.
50
+ * Mounts once the interface can act, so its state starts from the complete spec, and keeps that state
51
+ * from then on. json-render keeps the action handlers it mounts with, so they send through a ref to
52
+ * the latest `onSend`.
50
53
  */
51
- function LiveInterface({ spec, onSend }) {
54
+ function LiveInterface({ spec, onSend, disabled }) {
55
+ const onSendRef = (0, react.useRef)(onSend);
56
+ (0, react.useEffect)(() => {
57
+ onSendRef.current = onSend;
58
+ }, [onSend]);
52
59
  const [live] = (0, react.useState)(() => {
53
60
  const store = (0, _json_render_core.createStateStore)(spec.state ?? {});
54
- const { registry, handlers } = studioRegistry(onSend);
61
+ const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));
55
62
  return {
56
63
  store,
57
64
  registry,
@@ -59,7 +66,7 @@ function LiveInterface({ spec, onSend }) {
59
66
  };
60
67
  });
61
68
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_domains_chat_messages_gen_ui_interactive_context.GenUiInteractiveContext.Provider, {
62
- value: true,
69
+ value: !disabled,
63
70
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_json_render_react.JSONUIProvider, {
64
71
  registry: live.registry,
65
72
  store: live.store,
@@ -1 +1 @@
1
- {"version":3,"file":"gen-ui-interface.cjs.js","names":["defineRegistry","studioCatalog","studioComponents","buildSpecFromParts","JSONUIProvider","Renderer","useState","createStateStore","GenUiInteractiveContext"],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && !disabled ? <LiveInterface spec={spec} onSend={onSend} /> : <ReadOnlyInterface spec={spec} />}\n </div>\n );\n}\n\nfunction ReadOnlyInterface({ spec }: { spec: Spec }) {\n // Uncontrolled: the provider follows the state a streaming spec declares as it arrives.\n return (\n <JSONUIProvider registry={readOnlyRegistry} initialState={spec.state}>\n <Renderer spec={spec} registry={readOnlyRegistry} />\n </JSONUIProvider>\n );\n}\n\n/**\n * Mounts once the interface can act, so its state starts from the complete spec. json-render keeps\n * the action handlers it mounts with; the parent switches back to read-only whenever the chat\n * replies, so the `onSend` captured here is never older than the current idle chat.\n */\nfunction LiveInterface({ spec, onSend }: { spec: Spec; onSend: GenUiSend }) {\n const [live] = useState(() => {\n const store = createStateStore(spec.state ?? {});\n const { registry, handlers } = studioRegistry(onSend);\n return { store, registry, handlers: handlers(() => undefined, store.getSnapshot) };\n });\n\n return (\n <GenUiInteractiveContext.Provider value>\n <JSONUIProvider registry={live.registry} store={live.store} handlers={live.handlers}>\n <Renderer spec={spec} registry={live.registry} />\n </JSONUIProvider>\n </GenUiInteractiveContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,iBAAiB;AAc9B,SAAS,eAAe,QAAoB;CAC1C,QAAA,GAAOA,mBAAAA,eAAAA,CAAeC,2BAAAA,eAAe;EACnC,YAAYC,uDAAAA;EACZ,SAAS,EACP,aAAa,OAAO,QAAQ,WAAW,UAAU;GAC/C,IAAI,QAAQ,SAAS,SAAS,OAAO,SAAS,KAAK;EACrD,EACF;CACF,CAAC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BAAAA,UAAD;IAAgB;IAAM,UAAU,KAAK;GAAW,CAAA;EAClC,CAAA;CACgB,CAAA;AAEtC"}
1
+ {"version":3,"file":"gen-ui-interface.cjs.js","names":["defineRegistry","studioCatalog","studioComponents","useState","buildSpecFromParts","JSONUIProvider","Renderer","useRef","createStateStore","GenUiInteractiveContext"],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useEffect, useRef, useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // Once live, stays live: disabling it while the chat replies must not reset what the user entered.\n const [wentLive, setWentLive] = useState(false);\n if (onSend && !disabled && !wentLive) setWentLive(true);\n\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && (wentLive || !disabled) ? (\n <LiveInterface spec={spec} onSend={onSend} disabled={disabled} />\n ) : (\n <ReadOnlyInterface spec={spec} />\n )}\n </div>\n );\n}\n\nfunction ReadOnlyInterface({ spec }: { spec: Spec }) {\n // Uncontrolled: the provider follows the state a streaming spec declares as it arrives.\n return (\n <JSONUIProvider registry={readOnlyRegistry} initialState={spec.state}>\n <Renderer spec={spec} registry={readOnlyRegistry} />\n </JSONUIProvider>\n );\n}\n\n/**\n * Mounts once the interface can act, so its state starts from the complete spec, and keeps that state\n * from then on. json-render keeps the action handlers it mounts with, so they send through a ref to\n * the latest `onSend`.\n */\nfunction LiveInterface({ spec, onSend, disabled }: { spec: Spec; onSend: GenUiSend; disabled: boolean }) {\n const onSendRef = useRef(onSend);\n useEffect(() => {\n onSendRef.current = onSend;\n }, [onSend]);\n\n const [live] = useState(() => {\n const store = createStateStore(spec.state ?? {});\n const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));\n return { store, registry, handlers: handlers(() => undefined, store.getSnapshot) };\n });\n\n return (\n <GenUiInteractiveContext.Provider value={!disabled}>\n <JSONUIProvider registry={live.registry} store={live.store} handlers={live.handlers}>\n <Renderer spec={spec} registry={live.registry} />\n </JSONUIProvider>\n </GenUiInteractiveContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,iBAAiB;AAc9B,SAAS,eAAe,QAAoB;CAC1C,QAAA,GAAOA,mBAAAA,eAAAA,CAAeC,2BAAAA,eAAe;EACnC,YAAYC,uDAAAA;EACZ,SAAS,EACP,aAAa,OAAO,QAAQ,WAAW,UAAU;GAC/C,IAAI,QAAQ,SAAS,SAAS,OAAO,SAAS,KAAK;EACrD,EACF;CACF,CAAC;AACH;AAEA,IAAM,mBAAmB,eAAe,CAAC,CAAC;;;;;AAM1C,SAAgB,eAAe,EAAE,OAAO,QAAQ,WAAW,SAA8B;CAEvF,M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AAA,CAACC,yDAAAA,wBAAwB,UAAzB;EAAkC,OAAO,CAAC;EACxC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACJ,mBAAAA,gBAAD;GAAgB,UAAU,KAAK;GAAU,OAAO,KAAK;GAAO,UAAU,KAAK;GACzE,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,mBAAAA,UAAD;IAAgB;IAAM,UAAU,KAAK;GAAW,CAAA;EAClC,CAAA;CACgB,CAAA;AAEtC"}
@@ -1,6 +1,6 @@
1
1
  import { GenUiInteractiveContext } from "./interactive-context.es.js";
2
2
  import { studioComponents } from "./studio-components.es.js";
3
- import { useState } from "react";
3
+ import { useEffect, useRef, useState } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { studioCatalog } from "@mastra/json-render/studio";
6
6
  import { createStateStore } from "@json-render/core";
@@ -21,14 +21,17 @@ var readOnlyRegistry = studioRegistry().registry;
21
21
  * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.
22
22
  */
23
23
  function GenUiInterface({ parts, onSend, disabled = false }) {
24
+ const [wentLive, setWentLive] = useState(false);
25
+ if (onSend && !disabled && !wentLive) setWentLive(true);
24
26
  const spec = buildSpecFromParts(structuredClone(parts));
25
27
  if (!spec) return null;
26
28
  return /* @__PURE__ */ jsx("div", {
27
29
  "data-slot": "gen-ui-interface",
28
30
  className: "@container min-w-0",
29
- children: onSend && !disabled ? /* @__PURE__ */ jsx(LiveInterface, {
31
+ children: onSend && (wentLive || !disabled) ? /* @__PURE__ */ jsx(LiveInterface, {
30
32
  spec,
31
- onSend
33
+ onSend,
34
+ disabled
32
35
  }) : /* @__PURE__ */ jsx(ReadOnlyInterface, { spec })
33
36
  });
34
37
  }
@@ -43,14 +46,18 @@ function ReadOnlyInterface({ spec }) {
43
46
  });
44
47
  }
45
48
  /**
46
- * Mounts once the interface can act, so its state starts from the complete spec. json-render keeps
47
- * the action handlers it mounts with; the parent switches back to read-only whenever the chat
48
- * replies, so the `onSend` captured here is never older than the current idle chat.
49
+ * Mounts once the interface can act, so its state starts from the complete spec, and keeps that state
50
+ * from then on. json-render keeps the action handlers it mounts with, so they send through a ref to
51
+ * the latest `onSend`.
49
52
  */
50
- function LiveInterface({ spec, onSend }) {
53
+ function LiveInterface({ spec, onSend, disabled }) {
54
+ const onSendRef = useRef(onSend);
55
+ useEffect(() => {
56
+ onSendRef.current = onSend;
57
+ }, [onSend]);
51
58
  const [live] = useState(() => {
52
59
  const store = createStateStore(spec.state ?? {});
53
- const { registry, handlers } = studioRegistry(onSend);
60
+ const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));
54
61
  return {
55
62
  store,
56
63
  registry,
@@ -58,7 +65,7 @@ function LiveInterface({ spec, onSend }) {
58
65
  };
59
66
  });
60
67
  return /* @__PURE__ */ jsx(GenUiInteractiveContext.Provider, {
61
- value: true,
68
+ value: !disabled,
62
69
  children: /* @__PURE__ */ jsx(JSONUIProvider, {
63
70
  registry: live.registry,
64
71
  store: live.store,
@@ -1 +1 @@
1
- {"version":3,"file":"gen-ui-interface.es.js","names":[],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && !disabled ? <LiveInterface spec={spec} onSend={onSend} /> : <ReadOnlyInterface spec={spec} />}\n </div>\n );\n}\n\nfunction ReadOnlyInterface({ spec }: { spec: Spec }) {\n // Uncontrolled: the provider follows the state a streaming spec declares as it arrives.\n return (\n <JSONUIProvider registry={readOnlyRegistry} initialState={spec.state}>\n <Renderer spec={spec} registry={readOnlyRegistry} />\n </JSONUIProvider>\n );\n}\n\n/**\n * Mounts once the interface can act, so its state starts from the complete spec. json-render keeps\n * the action handlers it mounts with; the parent switches back to read-only whenever the chat\n * replies, so the `onSend` captured here is never older than the current idle chat.\n */\nfunction LiveInterface({ spec, onSend }: { spec: Spec; onSend: GenUiSend }) {\n const [live] = useState(() => {\n const store = createStateStore(spec.state ?? {});\n const { registry, handlers } = studioRegistry(onSend);\n return { store, registry, handlers: handlers(() => undefined, store.getSnapshot) };\n });\n\n return (\n <GenUiInteractiveContext.Provider value>\n <JSONUIProvider registry={live.registry} store={live.store} handlers={live.handlers}>\n <Renderer spec={spec} registry={live.registry} />\n </JSONUIProvider>\n </GenUiInteractiveContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AASA,IAAa,iBAAiB;AAc9B,SAAS,eAAe,QAAoB;CAC1C,OAAO,eAAe,eAAe;EACnC,YAAY;EACZ,SAAS,EACP,aAAa,OAAO,QAAQ,WAAW,UAAU;GAC/C,IAAI,QAAQ,SAAS,SAAS,OAAO,SAAS,KAAK;EACrD,EACF;CACF,CAAC;AACH;AAEA,IAAM,mBAAmB,eAAe,CAAC,CAAC;;;;;AAM1C,SAAgB,eAAe,EAAE,OAAO,QAAQ,WAAW,SAA8B;CAEvF,MAAM,OAAO,mBAAmB,gBAAgB,KAAK,CAAC;CACtD,IAAI,CAAC,MAAM,OAAO;CAElB,OACE,oBAAC,OAAD;EAAK,aAAU;EAAmB,WAAU;EACzC,UAAA,UAAU,CAAC,WAAW,oBAAC,eAAD;GAAqB;GAAc;EAAS,CAAA,IAAI,oBAAC,mBAAD,EAAyB,KAAO,CAAA;CACpG,CAAA;AAET;AAEA,SAAS,kBAAkB,EAAE,QAAwB;CAEnD,OACE,oBAAC,gBAAD;EAAgB,UAAU;EAAkB,cAAc,KAAK;EAC7D,UAAA,oBAAC,UAAD;GAAgB;GAAM,UAAU;EAAmB,CAAA;CACrC,CAAA;AAEpB;;;;;;AAOA,SAAS,cAAc,EAAE,MAAM,UAA6C;CAC1E,MAAM,CAAC,QAAQ,eAAe;EAC5B,MAAM,QAAQ,iBAAiB,KAAK,SAAS,CAAC,CAAC;EAC/C,MAAM,EAAE,UAAU,aAAa,eAAe,MAAM;EACpD,OAAO;GAAE;GAAO;GAAU,UAAU,eAAe,KAAA,GAAW,MAAM,WAAW;EAAE;CACnF,CAAC;CAED,OACE,oBAAC,wBAAwB,UAAzB;EAAkC,OAAA;EAChC,UAAA,oBAAC,gBAAD;GAAgB,UAAU,KAAK;GAAU,OAAO,KAAK;GAAO,UAAU,KAAK;GACzE,UAAA,oBAAC,UAAD;IAAgB;IAAM,UAAU,KAAK;GAAW,CAAA;EAClC,CAAA;CACgB,CAAA;AAEtC"}
1
+ {"version":3,"file":"gen-ui-interface.es.js","names":[],"sources":["../../../../../src/domains/chat/messages/gen-ui/gen-ui-interface.tsx"],"sourcesContent":["import { createStateStore } from '@json-render/core';\nimport type { Spec } from '@json-render/core';\nimport { JSONUIProvider, Renderer, buildSpecFromParts, defineRegistry } from '@json-render/react';\nimport type { DataPart } from '@json-render/react';\nimport { studioCatalog } from '@mastra/json-render/studio';\nimport { useEffect, useRef, useState } from 'react';\nimport { GenUiInteractiveContext } from './interactive-context';\nimport { studioComponents } from './studio-components';\n\nexport const SPEC_PART_TYPE = 'data-spec';\n\n/** Sends `message` as the user's next turn, with the interface's current state. */\nexport type GenUiSend = (message: string, state: Record<string, unknown>) => void;\n\nexport interface GenUiInterfaceProps {\n /** The reply's `data-spec` parts, in order. */\n parts: DataPart[];\n /** Omit to render the interface read-only. */\n onSend?: GenUiSend;\n /** Disables the interface's controls, e.g. while the chat is replying. */\n disabled?: boolean;\n}\n\nfunction studioRegistry(onSend?: GenUiSend) {\n return defineRegistry(studioCatalog, {\n components: studioComponents,\n actions: {\n sendMessage: async (params, _setState, state) => {\n if (params?.message) onSend?.(params.message, state);\n },\n },\n });\n}\n\nconst readOnlyRegistry = studioRegistry().registry;\n\n/**\n * Renders the interface an agent composed in its reply with `studioCatalog`. Once it can act, the\n * interface keeps its own state (form values) and its `sendMessage` action passes it back to the agent.\n */\nexport function GenUiInterface({ parts, onSend, disabled = false }: GenUiInterfaceProps) {\n // Once live, stays live: disabling it while the chat replies must not reset what the user entered.\n const [wentLive, setWentLive] = useState(false);\n if (onSend && !disabled && !wentLive) setWentLive(true);\n\n // buildSpecFromParts mutates nested objects of the parts it reads.\n const spec = buildSpecFromParts(structuredClone(parts));\n if (!spec) return null;\n\n return (\n <div data-slot=\"gen-ui-interface\" className=\"@container min-w-0\">\n {onSend && (wentLive || !disabled) ? (\n <LiveInterface spec={spec} onSend={onSend} disabled={disabled} />\n ) : (\n <ReadOnlyInterface spec={spec} />\n )}\n </div>\n );\n}\n\nfunction ReadOnlyInterface({ spec }: { spec: Spec }) {\n // Uncontrolled: the provider follows the state a streaming spec declares as it arrives.\n return (\n <JSONUIProvider registry={readOnlyRegistry} initialState={spec.state}>\n <Renderer spec={spec} registry={readOnlyRegistry} />\n </JSONUIProvider>\n );\n}\n\n/**\n * Mounts once the interface can act, so its state starts from the complete spec, and keeps that state\n * from then on. json-render keeps the action handlers it mounts with, so they send through a ref to\n * the latest `onSend`.\n */\nfunction LiveInterface({ spec, onSend, disabled }: { spec: Spec; onSend: GenUiSend; disabled: boolean }) {\n const onSendRef = useRef(onSend);\n useEffect(() => {\n onSendRef.current = onSend;\n }, [onSend]);\n\n const [live] = useState(() => {\n const store = createStateStore(spec.state ?? {});\n const { registry, handlers } = studioRegistry((message, state) => onSendRef.current(message, state));\n return { store, registry, handlers: handlers(() => undefined, store.getSnapshot) };\n });\n\n return (\n <GenUiInteractiveContext.Provider value={!disabled}>\n <JSONUIProvider registry={live.registry} store={live.store} handlers={live.handlers}>\n <Renderer spec={spec} registry={live.registry} />\n </JSONUIProvider>\n </GenUiInteractiveContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AASA,IAAa,iBAAiB;AAc9B,SAAS,eAAe,QAAoB;CAC1C,OAAO,eAAe,eAAe;EACnC,YAAY;EACZ,SAAS,EACP,aAAa,OAAO,QAAQ,WAAW,UAAU;GAC/C,IAAI,QAAQ,SAAS,SAAS,OAAO,SAAS,KAAK;EACrD,EACF;CACF,CAAC;AACH;AAEA,IAAM,mBAAmB,eAAe,CAAC,CAAC;;;;;AAM1C,SAAgB,eAAe,EAAE,OAAO,QAAQ,WAAW,SAA8B;CAEvF,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,IAAI,UAAU,CAAC,YAAY,CAAC,UAAU,YAAY,IAAI;CAGtD,MAAM,OAAO,mBAAmB,gBAAgB,KAAK,CAAC;CACtD,IAAI,CAAC,MAAM,OAAO;CAElB,OACE,oBAAC,OAAD;EAAK,aAAU;EAAmB,WAAU;EACzC,UAAA,WAAW,YAAY,CAAC,YACvB,oBAAC,eAAD;GAAqB;GAAc;GAAkB;EAAW,CAAA,IAEhE,oBAAC,mBAAD,EAAyB,KAAO,CAAA;CAE/B,CAAA;AAET;AAEA,SAAS,kBAAkB,EAAE,QAAwB;CAEnD,OACE,oBAAC,gBAAD;EAAgB,UAAU;EAAkB,cAAc,KAAK;EAC7D,UAAA,oBAAC,UAAD;GAAgB;GAAM,UAAU;EAAmB,CAAA;CACrC,CAAA;AAEpB;;;;;;AAOA,SAAS,cAAc,EAAE,MAAM,QAAQ,YAAkE;CACvG,MAAM,YAAY,OAAO,MAAM;CAC/B,gBAAgB;EACd,UAAU,UAAU;CACtB,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,CAAC,QAAQ,eAAe;EAC5B,MAAM,QAAQ,iBAAiB,KAAK,SAAS,CAAC,CAAC;EAC/C,MAAM,EAAE,UAAU,aAAa,gBAAgB,SAAS,UAAU,UAAU,QAAQ,SAAS,KAAK,CAAC;EACnG,OAAO;GAAE;GAAO;GAAU,UAAU,eAAe,KAAA,GAAW,MAAM,WAAW;EAAE;CACnF,CAAC;CAED,OACE,oBAAC,wBAAwB,UAAzB;EAAkC,OAAO,CAAC;EACxC,UAAA,oBAAC,gBAAD;GAAgB,UAAU,KAAK;GAAU,OAAO,KAAK;GAAO,UAAU,KAAK;GACzE,UAAA,oBAAC,UAAD;IAAgB;IAAM,UAAU,KAAK;GAAW,CAAA;EAClC,CAAA;CACgB,CAAA;AAEtC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mastra/playground-ui",
3
3
  "type": "module",
4
- "version": "71.0.0-alpha.5",
4
+ "version": "71.0.0-alpha.6",
5
5
  "description": "Mastra Playground components",
6
6
  "sideEffects": [
7
7
  "**/*.css"
@@ -230,9 +230,9 @@
230
230
  "react": ">=19.0.0",
231
231
  "react-dom": ">=19.0.0",
232
232
  "tailwindcss": "^4.0.0",
233
- "@mastra/ai-sdk": "^1.12.0",
234
233
  "@mastra/client-js": "^1.61.2-alpha.4",
235
- "@mastra/react": "1.16.0-alpha.4"
234
+ "@mastra/react": "1.16.0-alpha.4",
235
+ "@mastra/ai-sdk": "^1.12.0"
236
236
  },
237
237
  "devDependencies": {
238
238
  "@modelcontextprotocol/client": "2.4.0",
@@ -278,14 +278,14 @@
278
278
  "vite": "^8.3.5",
279
279
  "vite-plugin-lib-inject-css": "^2.2.2",
280
280
  "vitest": "5.1.0",
281
+ "@internal/ai-sdk-v5": "0.0.98",
282
+ "@internal/lint": "0.0.151",
281
283
  "@mastra/ai-sdk": "1.12.0",
282
284
  "@mastra/client-js": "^1.61.2-alpha.4",
283
285
  "@mastra/core": "1.86.0-alpha.4",
284
286
  "@mastra/memory": "1.41.3-alpha.0",
285
287
  "@mastra/react": "1.16.0-alpha.4",
286
- "@internal/ai-sdk-v5": "0.0.98",
287
- "@mastra/schema-compat": "1.4.0",
288
- "@internal/lint": "0.0.151"
288
+ "@mastra/schema-compat": "1.4.0"
289
289
  },
290
290
  "homepage": "https://mastra.ai",
291
291
  "repository": {