@ai-gui/react 0.4.0 → 0.4.2

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/dist/index.cjs CHANGED
@@ -230,17 +230,11 @@ function renderNode(node, ctx) {
230
230
  "data-aigui-block-loading": "",
231
231
  "data-block-type": node.type
232
232
  }, node.key);
233
- try {
234
- const out = r(node);
235
- if (out && typeof out.then === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AsyncOutput, {
236
- promise: out,
237
- sanitize: ctx.sanitize,
238
- context: ctx
239
- }, node.key);
240
- return renderOutput(out, node.key, ctx.sanitize, ctx);
241
- } catch {
242
- return renderFallback(node, ctx);
243
- }
233
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PluginOutputHost, {
234
+ node,
235
+ renderer: r,
236
+ context: ctx
237
+ }, node.key);
244
238
  }
245
239
  switch (node.type) {
246
240
  case "heading": return (0, react.createElement)(node.tag ?? "h1", {
@@ -258,6 +252,33 @@ function renderNode(node, ctx) {
258
252
  default: return renderFallback(node, ctx);
259
253
  }
260
254
  }
255
+ function PluginOutputHost({ node, renderer, context }) {
256
+ const cache = (0, react.useRef)();
257
+ const signature = nodeSignature(node);
258
+ try {
259
+ if (!cache.current || cache.current.renderer !== renderer || cache.current.signature !== signature) cache.current = {
260
+ renderer,
261
+ signature,
262
+ output: renderer(node)
263
+ };
264
+ const output = cache.current.output;
265
+ if (output && typeof output.then === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AsyncOutput, {
266
+ promise: output,
267
+ sanitize: context.sanitize,
268
+ context
269
+ });
270
+ return renderOutput(output, void 0, context.sanitize, context);
271
+ } catch {
272
+ return renderFallback(node, context);
273
+ }
274
+ }
275
+ function nodeSignature(node) {
276
+ try {
277
+ return JSON.stringify(node);
278
+ } catch {
279
+ return node;
280
+ }
281
+ }
261
282
  function renderFallback(node, ctx) {
262
283
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { dangerouslySetInnerHTML: { __html: renderHtml(node.html ?? node.content ?? "", ctx) } }, node.key);
263
284
  }
package/dist/index.js CHANGED
@@ -206,17 +206,11 @@ function renderNode(node, ctx) {
206
206
  "data-aigui-block-loading": "",
207
207
  "data-block-type": node.type
208
208
  }, node.key);
209
- try {
210
- const out = r(node);
211
- if (out && typeof out.then === "function") return /* @__PURE__ */ jsx(AsyncOutput, {
212
- promise: out,
213
- sanitize: ctx.sanitize,
214
- context: ctx
215
- }, node.key);
216
- return renderOutput(out, node.key, ctx.sanitize, ctx);
217
- } catch {
218
- return renderFallback(node, ctx);
219
- }
209
+ return /* @__PURE__ */ jsx(PluginOutputHost, {
210
+ node,
211
+ renderer: r,
212
+ context: ctx
213
+ }, node.key);
220
214
  }
221
215
  switch (node.type) {
222
216
  case "heading": return createElement(node.tag ?? "h1", {
@@ -234,6 +228,33 @@ function renderNode(node, ctx) {
234
228
  default: return renderFallback(node, ctx);
235
229
  }
236
230
  }
231
+ function PluginOutputHost({ node, renderer, context }) {
232
+ const cache = useRef();
233
+ const signature = nodeSignature(node);
234
+ try {
235
+ if (!cache.current || cache.current.renderer !== renderer || cache.current.signature !== signature) cache.current = {
236
+ renderer,
237
+ signature,
238
+ output: renderer(node)
239
+ };
240
+ const output = cache.current.output;
241
+ if (output && typeof output.then === "function") return /* @__PURE__ */ jsx(AsyncOutput, {
242
+ promise: output,
243
+ sanitize: context.sanitize,
244
+ context
245
+ });
246
+ return renderOutput(output, void 0, context.sanitize, context);
247
+ } catch {
248
+ return renderFallback(node, context);
249
+ }
250
+ }
251
+ function nodeSignature(node) {
252
+ try {
253
+ return JSON.stringify(node);
254
+ } catch {
255
+ return node;
256
+ }
257
+ }
237
258
  function renderFallback(node, ctx) {
238
259
  return /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: renderHtml(node.html ?? node.content ?? "", ctx) } }, node.key);
239
260
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-gui/react",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "React adapter for AIGUI — stream LLM output into live React components with cards, plugins, and interactive widgets.",
5
5
  "keywords": [
6
6
  "llm",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@ai-gui/core": "0.4.0"
53
+ "@ai-gui/core": "0.4.2"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": ">=18",