@runtypelabs/persona 4.21.1 → 4.22.1

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 (129) hide show
  1. package/dist/animations/glyph-cycle.d.cts +1 -1
  2. package/dist/animations/glyph-cycle.d.ts +1 -1
  3. package/dist/animations/{types-B_JdVK9o.d.cts → types-9Vxm-PPz.d.cts} +136 -6
  4. package/dist/animations/{types-B_JdVK9o.d.ts → types-9Vxm-PPz.d.ts} +136 -6
  5. package/dist/animations/wipe.d.cts +1 -1
  6. package/dist/animations/wipe.d.ts +1 -1
  7. package/dist/animations-extra.d.cts +136 -6
  8. package/dist/animations-extra.d.ts +136 -6
  9. package/dist/{approval-ui-RNNBR5R3.js → approval-ui-K7R5Q5OC.js} +1 -1
  10. package/dist/approval-ui.cjs +2 -2
  11. package/dist/approval-ui.d.cts +221 -16
  12. package/dist/approval-ui.d.ts +221 -16
  13. package/dist/approval-ui.js +2 -2
  14. package/dist/artifacts-ui-F4N6VMKF.js +7 -0
  15. package/dist/artifacts-ui.cjs +1 -1
  16. package/dist/artifacts-ui.d.cts +221 -16
  17. package/dist/artifacts-ui.d.ts +221 -16
  18. package/dist/artifacts-ui.js +1 -1
  19. package/dist/chunk-NQLDCJAP.js +4 -0
  20. package/dist/codegen.cjs +1 -1
  21. package/dist/codegen.js +1 -1
  22. package/dist/context-mentions.d.cts +221 -16
  23. package/dist/context-mentions.d.ts +221 -16
  24. package/dist/event-stream-view-GL3ADRY2.js +1 -0
  25. package/dist/event-stream-view.cjs +1 -1
  26. package/dist/event-stream-view.d.cts +221 -16
  27. package/dist/event-stream-view.d.ts +221 -16
  28. package/dist/event-stream-view.js +1 -1
  29. package/dist/forms-ui.d.cts +234 -25
  30. package/dist/forms-ui.d.ts +234 -25
  31. package/dist/history-view.d.cts +136 -6
  32. package/dist/history-view.d.ts +136 -6
  33. package/dist/index.cjs +70 -70
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +302 -32
  36. package/dist/index.d.ts +302 -32
  37. package/dist/index.global.js +54 -54
  38. package/dist/index.global.js.map +1 -1
  39. package/dist/index.js +69 -69
  40. package/dist/index.js.map +1 -1
  41. package/dist/launcher.global.js +2 -2
  42. package/dist/launcher.global.js.map +1 -1
  43. package/dist/session-reconnect.d.cts +221 -16
  44. package/dist/session-reconnect.d.ts +221 -16
  45. package/dist/smart-dom-reader.d.cts +221 -16
  46. package/dist/smart-dom-reader.d.ts +221 -16
  47. package/dist/testing.cjs +3 -3
  48. package/dist/testing.d.cts +3 -4
  49. package/dist/testing.d.ts +3 -4
  50. package/dist/testing.js +3 -3
  51. package/dist/theme-editor-preview.cjs +73 -73
  52. package/dist/theme-editor-preview.d.cts +221 -16
  53. package/dist/theme-editor-preview.d.ts +221 -16
  54. package/dist/theme-editor-preview.js +51 -51
  55. package/dist/theme-editor.cjs +4 -4
  56. package/dist/theme-editor.d.cts +221 -16
  57. package/dist/theme-editor.d.ts +221 -16
  58. package/dist/theme-editor.js +2 -2
  59. package/dist/theme-reference.cjs +1 -1
  60. package/dist/theme-reference.d.cts +65 -1
  61. package/dist/theme-reference.d.ts +65 -1
  62. package/dist/theme-reference.js +1 -1
  63. package/dist/voice-runtime.d.cts +6 -2
  64. package/dist/voice-runtime.d.ts +6 -2
  65. package/dist/webmcp-polyfill.js +1 -4
  66. package/dist/webmcp-runtime-JI7T4QYF.js +6 -0
  67. package/dist/webmcp-runtime.cjs +2 -2
  68. package/dist/webmcp-runtime.d.cts +34 -2
  69. package/dist/webmcp-runtime.d.ts +34 -2
  70. package/dist/webmcp-runtime.js +2 -2
  71. package/package.json +2 -2
  72. package/src/ask-user-question-tool.ts +1 -1
  73. package/src/client-history-rest.test.ts +2 -1
  74. package/src/client-visitor-history.test.ts +20 -4
  75. package/src/client.composer-options.test.ts +1 -1
  76. package/src/client.interrupt.test.ts +2 -2
  77. package/src/client.test.ts +477 -915
  78. package/src/client.ts +134 -494
  79. package/src/client.unified-tools.test.ts +76 -0
  80. package/src/components/artifact-preview.ts +5 -0
  81. package/src/components/event-stream-badge-theming.test.ts +162 -0
  82. package/src/components/event-stream-view.test.ts +76 -76
  83. package/src/components/event-stream-view.ts +55 -20
  84. package/src/components/tool-bubble.test.ts +12 -0
  85. package/src/components/tool-bubble.ts +13 -2
  86. package/src/event-stream-view-bundle.test.ts +2 -2
  87. package/src/generated/runtype-openapi-contract.ts +137 -1
  88. package/src/index-core.ts +2 -0
  89. package/src/internal/runtype-history-provider.test.ts +2 -2
  90. package/src/runtime/init.registry.test.ts +56 -0
  91. package/src/runtime/init.ts +17 -0
  92. package/src/session-history.test.ts +1 -1
  93. package/src/session.quote.test.ts +1 -1
  94. package/src/session.resubmit-from.test.ts +1 -1
  95. package/src/session.test.ts +5 -5
  96. package/src/session.ts +95 -36
  97. package/src/suggest-replies-tool.ts +1 -1
  98. package/src/testing/mock-stream.test.ts +37 -16
  99. package/src/testing/mock-stream.ts +14 -9
  100. package/src/types/theme.ts +41 -1
  101. package/src/types.ts +57 -15
  102. package/src/ui.ask-user-question-plugin.test.ts +7 -7
  103. package/src/ui.composer-defer-one.test.ts +6 -34
  104. package/src/ui.composer-draft-persistence.test.ts +1 -1
  105. package/src/ui.composer-quote.test.ts +1 -1
  106. package/src/ui.message-history-actions.test.ts +1 -1
  107. package/src/ui.reasoning-display.test.ts +136 -2
  108. package/src/ui.streaming-coalescing.test.ts +10 -13
  109. package/src/ui.ts +101 -35
  110. package/src/ui.typing-indicator.test.ts +216 -0
  111. package/src/ui.voice-custom-provider.test.ts +211 -0
  112. package/src/utils/__snapshots__/tokens-parity.test.ts.snap +1740 -0
  113. package/src/utils/event-stream-buffer.test.ts +13 -13
  114. package/src/utils/event-stream-capture.test.ts +20 -20
  115. package/src/utils/formatting.ts +22 -0
  116. package/src/utils/theme.ts +16 -0
  117. package/src/utils/throughput-tracker.test.ts +100 -142
  118. package/src/utils/throughput-tracker.ts +18 -132
  119. package/src/utils/tokens.ts +59 -0
  120. package/src/utils/voice-support.ts +18 -1
  121. package/src/voice/voice-turn-tracker.ts +18 -0
  122. package/src/webmcp-bridge.test.ts +132 -23
  123. package/src/webmcp-bridge.ts +27 -3
  124. package/src/webmcp-runtime-entry.ts +71 -11
  125. package/dist/artifacts-ui-J6AKUGTS.js +0 -7
  126. package/dist/chunk-HBE7LFNT.js +0 -4
  127. package/dist/event-stream-view-73NWKWVQ.js +0 -1
  128. package/dist/webmcp-runtime-P3CHZRHF.js +0 -6
  129. package/src/utils/__fixtures__/unified-translator.oracle.ts +0 -717
@@ -131,14 +131,21 @@ export class WebMcpBridge {
131
131
  return infos
132
132
  .filter((info) => this.passesClientAllowlist(info.name))
133
133
  .map<ClientToolDefinition>((info) => {
134
+ const annotations = pickAnnotations(info.annotations);
134
135
  const def: ClientToolDefinition = {
135
136
  name: info.name,
136
137
  description: info.description,
138
+ parametersSchema: normalizeInputSchema(info.inputSchema),
137
139
  origin: "webmcp",
138
140
  ...(pageOrigin ? { pageOrigin } : {}),
141
+ ...(annotations ? { annotations } : {}),
142
+ // Hoisted because the server acts on the TOP-LEVEL field
143
+ // (`InlineClientToolSchema.untrustedContentHint` gates output
144
+ // spotlighting); the nested `annotations` object is metadata only.
145
+ ...(annotations?.untrustedContentHint === true
146
+ ? { untrustedContentHint: true }
147
+ : {}),
139
148
  };
140
- const schema = parseSchema(info.inputSchema);
141
- if (schema) def.parametersSchema = schema;
142
149
  return def;
143
150
  });
144
151
  }
@@ -404,19 +411,72 @@ const matchesGlob = (name: string, pattern: string): boolean => {
404
411
  };
405
412
 
406
413
  /**
407
- * Parse the JSON-string `inputSchema` from `getTools()` back into an object for
408
- * `parametersSchema`. Returns `undefined` for a missing or unparseable schema
409
- * (the server can still accept a tool with no declared parameters).
414
+ * A tool that declared no usable schema. Sent rather than omitted: see below.
410
415
  */
411
- const parseSchema = (raw: string | undefined): object | undefined => {
412
- if (raw === undefined || raw === "") return undefined;
416
+ const EMPTY_INPUT_SCHEMA = { type: "object", properties: {} } as const;
417
+
418
+ /**
419
+ * `getTools()`'s `inputSchema`, in either generation, as the JSON Schema object
420
+ * `dispatch.clientTools[].parametersSchema` carries.
421
+ *
422
+ * TWO shapes are live in the field. `webmcp#241` replaced the serialized JSON
423
+ * string with a JSON Schema object; `@mcp-b/webmcp-polyfill` adopted that in v5
424
+ * and Chrome ships it from 154.0.8013 (cross-document tools first), while
425
+ * Chrome 149-153 -- most of the Origin Trial population -- and 154's
426
+ * same-document tools still emit the string. So: branch on `typeof`, and guard
427
+ * the parse of the string arm. Assuming one shape is a silent failure here and
428
+ * a loud one at dispatch, which is how the object generation shipped past us
429
+ * (`JSON.parse(object)` throws, every schema was dropped, every turn 400'd).
430
+ *
431
+ * ALWAYS returns an object. `parametersSchema` is required by the server's
432
+ * `InlineClientToolSchema`, and one entry missing it fails the whole top-level
433
+ * `DispatchRequestSchema` union -- 400-ing the entire turn rather than dropping
434
+ * the one tool, with an `INVALID_UNION` at path `""` that names nothing. A tool
435
+ * with no schema, or an unparseable one, degrades to "takes no arguments"
436
+ * instead of taking the conversation down with it.
437
+ */
438
+ /**
439
+ * Copy the WebMCP annotation hints onto the wire, dropping anything else.
440
+ *
441
+ * `getTools()` returns `annotations` since `@mcp-b/webmcp-polyfill` v5 (absent
442
+ * on v4 and when the tool declared none). Only the spec's two boolean hints are
443
+ * forwarded -- annotations are page-authored, so an explicit copy keeps
444
+ * functions/junk off the dispatch payload. Returns `undefined` when nothing
445
+ * usable remains so the member is omitted, matching the spec's own
446
+ * omit-when-empty behavior.
447
+ */
448
+ const pickAnnotations = (
449
+ raw: ModelContextToolInfo["annotations"],
450
+ ): ClientToolDefinition["annotations"] | undefined => {
451
+ if (!raw || typeof raw !== "object") return undefined;
452
+ const picked = {
453
+ ...(typeof raw.readOnlyHint === "boolean"
454
+ ? { readOnlyHint: raw.readOnlyHint }
455
+ : {}),
456
+ ...(typeof raw.untrustedContentHint === "boolean"
457
+ ? { untrustedContentHint: raw.untrustedContentHint }
458
+ : {}),
459
+ };
460
+ return Object.keys(picked).length > 0 ? picked : undefined;
461
+ };
462
+
463
+ const normalizeInputSchema = (raw: object | string | undefined): object => {
464
+ if (raw === undefined || raw === "") return { ...EMPTY_INPUT_SCHEMA };
465
+
466
+ // Object generation (webmcp#241): pass through as-is. Arrays are `typeof
467
+ // "object"` but are not JSON Schema objects, so they fall through.
468
+ if (typeof raw === "object") {
469
+ return raw !== null && !Array.isArray(raw) ? raw : { ...EMPTY_INPUT_SCHEMA };
470
+ }
471
+
472
+ // String generation: guarded parse.
413
473
  try {
414
- const parsed = JSON.parse(raw);
415
- return parsed !== null && typeof parsed === "object"
474
+ const parsed: unknown = JSON.parse(raw);
475
+ return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
416
476
  ? (parsed as object)
417
- : undefined;
477
+ : { ...EMPTY_INPUT_SCHEMA };
418
478
  } catch {
419
- return undefined;
479
+ return { ...EMPTY_INPUT_SCHEMA };
420
480
  }
421
481
  };
422
482
 
@@ -1,7 +0,0 @@
1
- import{c as Qe,d as et,e as tt,f as nt,g as ot,h as rt,i as st,q as V,r as ge,s as Te,t as lt,v as ct,w as dt}from"./chunk-NIKYKSNZ.js";import{a as ye}from"./chunk-7NQ4ZTHF.js";import{a as m,b as at,d as it}from"./chunk-76IELU7F.js";function oe(e){let t=String(e).split(/[\\/]/);return t[t.length-1]??""}function ft(e){let t=oe(e),n=t.lastIndexOf(".");return n<=0?"":t.slice(n+1).toLowerCase()}function ke(e){if(typeof e!="string")return"";let t=e.indexOf(`
2
- `);if(t===-1||!e.slice(0,t).startsWith("```"))return e;let r=e.slice(t+1),o=r.lastIndexOf(`
3
- `);return(o===-1?r:r.slice(0,o)).split("`\u200B``").join("```")}function fe(e){let t=ft(e.path);if(t)return t==="html"||t==="htm"?"html":t==="svg"?"svg":t==="md"||t==="mdx"?"markdown":"other";let n=(e.mimeType||"").toLowerCase();return n.includes("html")?"html":n.includes("svg")?"svg":n.includes("markdown")?"markdown":"other"}function ce(e){switch(fe(e)){case"html":return"HTML";case"svg":return"SVG";case"markdown":return"Markdown";default:{let t=ft(e.path);return t?t.toUpperCase():"File"}}}function Se(e){let t=e.markdown??"";return e.file?{filename:oe(e.file.path)||"artifact",mime:e.file.mimeType||"application/octet-stream",content:ke(t)}:{filename:`${e.title||"artifact"}.md`,mime:"text/markdown",content:t}}function Ee(e){let t=new Blob([e.content],{type:e.mime}),n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.download=e.filename,r.click(),URL.revokeObjectURL(n)}var Pe="persona-artifact-custom-action-btn";function be(e,t){let n=t?.documentChrome??!1,r;if(typeof e.icon=="function"){if(e.showLabel){let o="persona-label-btn persona-label-btn--sm "+Pe+(n?" persona-artifact-doc-copy-btn":"");r=m("button",o)}else{let o="persona-icon-btn "+Pe+(n?" persona-artifact-doc-icon-btn":"");r=m("button",o)}r.type="button",r.setAttribute("aria-label",e.label),r.title=e.label;try{let o=e.icon();o&&r.appendChild(o)}catch{}if(e.showLabel){let o=m("span");o.textContent=e.label,r.appendChild(o)}}else e.showLabel||!e.icon?r=ge({icon:e.icon,label:e.label,className:Pe+(n?" persona-artifact-doc-copy-btn":"")}):r=V({icon:e.icon,label:e.label,className:Pe+(n?" persona-artifact-doc-icon-btn":"")});return t?.onClick&&r.addEventListener("click",t.onClick),r}function ve(e){if(!e)return null;let t={artifactId:e.id,title:e.title??"",artifactType:e.artifactType};return e.artifactType==="markdown"?(t.markdown=e.markdown??"",e.file&&(t.file=e.file)):t.jsonPayload=JSON.stringify({component:e.component,props:e.props},null,2),t}var Ne="http://www.w3.org/2000/svg";function pt(e){let t=document.createElementNS(Ne,"svg");t.setAttribute("class",it("persona-spinner",e)),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.setAttribute("focusable","false");let n=document.createElementNS(Ne,"circle");n.setAttribute("class","persona-spinner-track"),n.setAttribute("cx","12"),n.setAttribute("cy","12"),n.setAttribute("r","9");let r=document.createElementNS(Ne,"circle");return r.setAttribute("class","persona-spinner-arc"),r.setAttribute("cx","12"),r.setAttribute("cy","12"),r.setAttribute("r","9"),t.appendChild(n),t.appendChild(r),t}function ut(e,t,n){let r=n?.loadingAnimation??"shimmer",o=n?.loadingAnimationDuration??2e3;if(r==="none"){e.textContent=t;return}if(r==="pulse"){e.setAttribute("data-preserve-animation","true"),e.classList.add("persona-tool-loading-pulse"),e.style.setProperty("--persona-tool-anim-duration",`${o}ms`),e.textContent=t;return}e.setAttribute("data-preserve-animation","true"),e.classList.add(`persona-tool-loading-${r}`),e.style.setProperty("--persona-tool-anim-duration",`${o}ms`),r==="shimmer-color"&&(n?.loadingAnimationColor&&e.style.setProperty("--persona-tool-anim-color",n.loadingAnimationColor),n?.loadingAnimationSecondaryColor&&e.style.setProperty("--persona-tool-anim-secondary-color",n.loadingAnimationSecondaryColor)),ct(e,t,0)}var Ve="persona-artifact-status-label",mt="persona-artifact-status-detail",yt="data-artifact-status-label",ze=new Map,gt=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now();function he(e){e&&ze.delete(e)}function Ot(e){let t=e.artifactType==="markdown"?e.file:void 0;return t?ce(t):e.artifactType==="component"?"Component":"Document"}function we(e,t,n){let r=Ot(e),o=`Generating ${r.toLowerCase()}...`,s=t?.statusLabel;if(typeof s=="string")return{label:s};if(typeof s!="function")return{label:o};let i=e.id,l=ze.get(i);e.status!=="complete"&&l===void 0&&(l=gt(),ze.set(i,l));let A=l===void 0?0:Math.max(0,gt()-l),h=e.artifactType==="component",f=!h&&typeof e.markdown=="string"?e.markdown:"",p=h?0:f.length,u=h||f===""?0:f.split(`
4
- `).length,c=e.artifactType==="markdown"?e.file:void 0,y={artifactId:i,artifactType:e.artifactType,title:e.title,typeLabel:r,file:c,chars:p,lines:u,elapsedMs:A,content:()=>h?"":f,surface:n};try{let g=s(y);return typeof g=="string"?{label:g}:g&&typeof g=="object"&&typeof g.label=="string"?{label:g.label,detail:typeof g.detail=="string"?g.detail:void 0}:{label:o}}catch{return{label:o}}}function Ft(e){e.className=Ve,e.removeAttribute("data-preserve-animation"),e.style.removeProperty("--persona-tool-anim-duration"),e.style.removeProperty("--persona-tool-anim-color"),e.style.removeProperty("--persona-tool-anim-secondary-color"),e.replaceChildren()}function pe(e,t,n){let r=e.querySelector(`:scope > .${Ve}`);r||(r=m("span",Ve),e.appendChild(r)),r.getAttribute(yt)!==t.label&&(Ft(r),ut(r,t.label,n),r.setAttribute(yt,t.label));let o=e.querySelector(`:scope > .${mt}`),s=t.detail;s?(o||(o=m("span",mt),e.appendChild(o)),o.textContent!==s&&(o.textContent=s)):o&&o.remove()}var _t={keyword:"persona-code-token-keyword",string:"persona-code-token-string",comment:"persona-code-token-comment",number:"persona-code-token-number",tag:"persona-code-token-tag",attr:"persona-code-token-attr",property:"persona-code-token-property"},Dt=15e4,Me={html:"html",htm:"html",xhtml:"html",xml:"html",svg:"html",css:"css",js:"js",jsx:"js",mjs:"js",cjs:"js",ts:"js",tsx:"js",mts:"js",cts:"js",javascript:"js",typescript:"js",ecmascript:"js",json:"json",jsonc:"json",json5:"json"};function jt(e,t){let n=(e||"").trim().toLowerCase();if(n&&Me[n])return Me[n];if(t){let r=t.lastIndexOf(".");if(r>=0){let o=t.slice(r+1).toLowerCase();if(Me[o])return Me[o]}}return null}function Re(e,t){let n=[],r=0,o=0,s=i=>{i>o&&n.push({type:"plain",value:e.slice(o,i)})};for(;r<e.length;){let i=!1;for(let l of t){l.re.lastIndex=r;let A=l.re.exec(e);if(A&&A.index===r&&A[0].length>0){s(r);let h=l.map?l.map(A[0]):l.type;n.push({type:h,value:A[0]}),r+=A[0].length,o=r,i=!0;break}}i||(r+=1)}return s(e.length),n}var Nt=new Set(["abstract","any","as","async","await","boolean","break","case","catch","class","const","continue","debugger","declare","default","delete","do","else","enum","export","extends","false","finally","for","from","function","get","if","implements","import","in","instanceof","interface","keyof","let","namespace","never","new","null","number","object","of","private","protected","public","readonly","return","satisfies","set","static","string","super","switch","symbol","this","throw","true","try","type","typeof","undefined","unknown","var","void","while","yield"]),Vt=[{type:"comment",re:/\/\/[^\n]*/y},{type:"comment",re:/\/\*[\s\S]*?\*\//y},{type:"string",re:/`(?:\\[\s\S]|[^\\`])*`/y},{type:"string",re:/"(?:\\.|[^"\\\n])*"/y},{type:"string",re:/'(?:\\.|[^'\\\n])*'/y},{type:"number",re:/0[xX][0-9a-fA-F]+|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y},{type:"plain",re:/[A-Za-z_$][\w$]*/y,map:e=>Nt.has(e)?"keyword":"plain"}];function bt(e){return Re(e,Vt)}var zt=[{type:"string",re:/"(?:\\.|[^"\\])*"/y},{type:"number",re:/-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y},{type:"plain",re:/[A-Za-z_]\w*/y,map:e=>e==="true"||e==="false"||e==="null"?"keyword":"plain"}];function Wt(e){let t=Re(e,zt);for(let n=0;n<t.length;n+=1){if(t[n].type!=="string")continue;let r=n+1;for(;r<t.length&&t[r].value.trim()==="";)r+=1;let o=t[r];o&&o.value.replace(/^\s*/,"").startsWith(":")&&(t[n].type="property")}return t}var Ut=[{type:"comment",re:/\/\*[\s\S]*?\*\//y},{type:"string",re:/"(?:\\.|[^"\\\n])*"/y},{type:"string",re:/'(?:\\.|[^'\\\n])*'/y},{type:"keyword",re:/@[A-Za-z-]+/y},{type:"number",re:/#[0-9a-fA-F]{3,8}\b/y},{type:"number",re:/-?(?:\d+\.?\d*|\.\d+)(?:[a-z%]+)?/y},{type:"plain",re:/[A-Za-z_-][\w-]*/y}];function ht(e){let t=Re(e,Ut),n="";for(let r=0;r<t.length;r+=1){let o=t[r];if(o.type==="plain"&&/^[A-Za-z_-][\w-]*$/.test(o.value)){let i=r+1;for(;i<t.length&&t[i].value.trim()==="";)i+=1;let l=t[i];l&&l.value.replace(/^\s*/,"").startsWith(":")&&(n===""||n==="{"||n==="}"||n===";"||n===",")&&(o.type="property")}let s=o.value.replace(/\s+$/,"");s&&(n=s[s.length-1])}return t}var $t=[{type:"tag",re:/<\/?\s*[A-Za-z][\w:-]*/y},{type:"string",re:/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/y},{type:"attr",re:/[A-Za-z_:@][\w:.-]*(?=\s*=)/y},{type:"attr",re:/[A-Za-z_:@][\w:.-]*/y},{type:"tag",re:/\/?>/y}];function qt(e){let t=[],n=(s,i)=>{i&&t.push({type:s,value:i})},r=e.length,o=0;for(;o<r;){if(e.startsWith("<!--",o)){let i=e.indexOf("-->",o+4),l=i===-1?r:i+3;n("comment",e.slice(o,l)),o=l;continue}if(e[o]==="<"&&e[o+1]==="!"){let i=e.indexOf(">",o),l=i===-1?r:i+1;n("tag",e.slice(o,l)),o=l;continue}if(e[o]==="<"&&/[A-Za-z/]/.test(e[o+1]||"")){let i=e.indexOf(">",o),l=i===-1?r:i+1,A=e.slice(o,l);for(let f of Re(A,$t))t.push(f);o=l;let h=/^<\s*(script|style)\b/i.exec(A);if(h&&!/\/>\s*$/.test(A)){let f=h[1].toLowerCase(),u=new RegExp("</\\s*"+f+"\\s*>","i").exec(e.slice(o)),c=u?o+u.index:r,y=e.slice(o,c),g=f==="script"?bt(y):ht(y);for(let S of g)t.push(S);o=c}continue}let s=e.indexOf("<",o);if(s===o)n("plain",e[o]),o+=1;else{let i=s===-1?r:s;n("plain",e.slice(o,i)),o=i}}return t}function Gt(e,t){switch(t){case"html":return qt(e);case"css":return ht(e);case"js":return bt(e);case"json":return Wt(e)}}function Kt(e){let t=at(),n=m("span","persona-code-line"),r=(o,s)=>{if(!s)return;let i=_t[o];if(i){let l=m("span",i);l.textContent=s,n.appendChild(l)}else n.appendChild(document.createTextNode(s))};for(let o of e){let s=o.value.split(`
5
- `);for(let i=0;i<s.length;i+=1)i>0&&(t.appendChild(n),t.appendChild(document.createTextNode(`
6
- `)),n=m("span","persona-code-line")),r(o.type,s[i])}return n.childNodes.length>0?t.appendChild(n):t.lastChild||t.appendChild(n),t}function wt(e,t,n){let r=e.length<=Dt?jt(t,n):null,o=r?Gt(e,r):[{type:"plain",value:e}];return Kt(o)}var At=null,vt=e=>{At=e.componentRegistry},Ct=()=>At;function He(e){if(!e)return"";if(e.artifactType==="markdown"){let t=e.markdown??"";return e.file?ke(t):t}return JSON.stringify({component:e.component,props:e.props},null,2)}var We=!1;function Zt(e){return"persona-artifact-vt-"+((e||"artifact").replace(/[^A-Za-z0-9_-]/g,"-").replace(/^-+/,"")||"artifact")}function xt(e,t,n,r){let o=typeof document<"u"?document.startViewTransition:void 0,s=!1;try{s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch{s=!1}if(t!=="auto"||!e||typeof o!="function"||We||s){r();return}We=!0;let i=Zt(n);e.style.setProperty("view-transition-name",i);let l=()=>{We=!1,e.style.removeProperty("view-transition-name")};try{o.call(document,()=>{r()}).finished.then(l,l)}catch{l(),r()}}var Jt="persona-font-mono persona-text-xs persona-whitespace-pre-wrap persona-break-words persona-text-persona-primary",Xt="persona-text-sm persona-leading-relaxed persona-markdown-bubble";function Yt(e){let t=m("div","persona-rounded-lg persona-border persona-border-persona-border persona-p-3 persona-text-persona-primary"),n=m("div","persona-font-semibold persona-text-sm persona-mb-2");n.textContent=e.component?`Component: ${e.component}`:"Component";let r=m("pre","persona-font-mono persona-text-xs persona-whitespace-pre-wrap persona-overflow-x-auto");return r.textContent=JSON.stringify(e.props??{},null,2),t.appendChild(n),t.appendChild(r),t}function Qt(e){if(e===!1)return{enabled:!1,delayMs:0,minVisibleMs:0,timeoutMs:0,injectReadySignal:!1,label:"Starting preview...",labelDelayMs:2e3};let t=e&&typeof e=="object"?e:void 0;return{enabled:!0,delayMs:t?.delayMs??200,minVisibleMs:t?.minVisibleMs??300,timeoutMs:t?.timeoutMs??8e3,injectReadySignal:t?.injectReadySignal!==!1,label:t?.label===!1?!1:t?.label??"Starting preview...",labelDelayMs:t?.labelDelayMs??2e3,renderIndicator:t?.renderIndicator}}var en=220;function tn(){try{if(typeof crypto<"u"&&crypto.getRandomValues){let e=new Uint32Array(2);return crypto.getRandomValues(e),e[0].toString(36)+e[1].toString(36)}}catch{}return Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)}function nn(e){return`
7
- <script>(function(){var d=false;var t=`+JSON.stringify(e)+";function r(){if(d)return;d=true;try{parent.postMessage({persona:'artifact-preview-ready',token:t},'*');}catch(e){}}function s(){if(typeof requestAnimationFrame==='function'){requestAnimationFrame(function(){requestAnimationFrame(r);});}setTimeout(r,150);}if(document.readyState==='complete'){s();}else{window.addEventListener('load',s);}})();</script>"}function on(e,t,n){let r=m("div","persona-artifact-frame-loading");if(n.renderIndicator)try{let i=n.renderIndicator({artifactId:e,config:t});if(i)return r.appendChild(i),{el:r,revealLabel:()=>{}}}catch{}let o=m("div","persona-artifact-frame-loading-indicator");o.appendChild(pt());let s=null;return n.label!==!1&&(s=m("div","persona-artifact-frame-loading-text"),s.textContent=n.label,o.appendChild(s)),r.appendChild(o),{el:r,revealLabel:()=>{s&&s.classList.add("persona-artifact-frame-loading-text--visible")}}}function rn(e,t,n,r,o,s){let i=null,l=0,A=!1,h=new Set,f=()=>{h.forEach(x=>clearTimeout(x)),h.clear()},p=(x,P)=>{let $=setTimeout(()=>{h.delete($),x()},P);h.add($)},u=()=>{i&&i.parentElement&&i.remove(),i=null},c=()=>{if(i||A)return;let x=on(o,s,r);i=x.el,e.appendChild(i),l=Date.now(),r.label!==!1&&p(x.revealLabel,r.labelDelayMs)},y=()=>{i&&(i.classList.add("persona-artifact-frame-loading--out"),p(u,en))},g=()=>{n!==null?typeof window<"u"&&window.removeEventListener("message",I):t.removeEventListener("load",L)},S=()=>{if(A||(A=!0,g(),f(),!i))return;let x=Math.max(0,r.minVisibleMs-(Date.now()-l));x>0?p(y,x):y()};function I(x){if(n===null)return;let P=x.data;!P||P.persona!=="artifact-preview-ready"||P.token!==n||x.source===t.contentWindow&&S()}function L(){let x=P=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>P()):setTimeout(P,0)};x(()=>x(()=>S()))}return p(c,r.delayMs),p(S,r.timeoutMs),n!==null?typeof window<"u"&&window.addEventListener("message",I):t.addEventListener("load",L),()=>{A=!0,f(),g(),u()}}function Ie(e,t){let{config:n}=t,r=t.registry??Ct()??dt,o=t.bodyLayout,s=n.markdown?nt(n.markdown):null,i=rt(n.sanitize),l=e,A=!1,h=d=>{let M=tt()!==null;s&&!M&&!A&&(A=!0,Qe(()=>Z(l)));let O=s?s(d):ot(d);return s&&M&&i?i(O):O},f=m("div","persona-artifact-preview-body"),p=null,u=null,c=null,y=()=>{c&&(c(),c=null),p=null,u=null},g=null,S=null,I=null,L=!1,x=()=>{g=null,S=null,I=null,L=!1},P=null,$=null,J=()=>{P=null,$=null},re=40,Y=0,ie=d=>typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>d()):setTimeout(d,0),_=d=>d.scrollHeight-d.clientHeight-d.scrollTop<=re,K=d=>{if(!o)return;let M=d.scrollHeight-d.clientHeight>1,O=d.scrollHeight-d.clientHeight-d.scrollTop;d.classList.toggle("persona-artifact-fade-top",o.fadeTop&&M&&d.scrollTop>1),d.classList.toggle("persona-artifact-fade-bottom",o.fadeBottom&&M&&O>1)},D=d=>{Y||(Y=ie(()=>{Y=0,d.scrollTop=d.scrollHeight,K(d)}))},z=(d,M,O,b)=>{let T=!!o,F=O.id+"|"+(T?"w":"p");if(!g||I!==F||g.parentElement!==f){y(),J(),f.replaceChildren();let w=m("pre",Jt+" persona-code-pre"),H=m("code","persona-code");if(w.appendChild(H),T){let j=m("div","persona-artifact-source-window");if(j.appendChild(w),f.appendChild(j),!(o?.overflow==="clip")&&typeof j.addEventListener=="function"){let X=()=>j.scrollHeight-j.clientHeight>1;j.addEventListener("scroll",()=>{_(j)&&(L=!1),K(j)},{passive:!0}),j.addEventListener("wheel",ee=>{X()&&ee.deltaY<0&&(L=!0)},{passive:!0}),j.addEventListener("touchmove",()=>{X()&&(L=!0)},{passive:!0})}g=j}else f.appendChild(w),g=w;S=H,I=F}let k=T?g:null;k&&(k.classList.toggle("persona-artifact-source-window--fixed",b),k.classList.toggle("persona-artifact-source-window--clip",b&&o?.overflow==="clip"));let R=k?_(k):!0;if(S.replaceChildren(wt(d,M?.language,M?.path)),k){let w=O.status!=="complete";b&&w&&o?.followOutput&&!L&&R?D(k):w||(L=!1),K(k)}},W=d=>{y(),x(),J(),f.replaceChildren();let M=m("div",Xt);M.innerHTML=h(d),f.appendChild(M)},Q=d=>{let M=d.id,O=n.features?.artifacts,b=we(d,O,"status-body");if(P&&$===M&&P.parentElement===f){let k=P.querySelector(".persona-artifact-status-view-text");k&&pe(k,b,O);return}y(),x(),f.replaceChildren();let T=m("div","persona-artifact-status-view"),F=m("div","persona-artifact-status-view-text");pe(F,b,O),T.appendChild(F),f.appendChild(T),P=T,$=M},Z=d=>{l=d;let M=t.resolveViewMode?.(d)??o?.viewMode??"rendered",O=d.artifactType==="markdown"?d.file:void 0,b=d.status!=="complete";b||he(d.id);let T=b?o?.streamingHeight:o?.completeHeight,F=!!o&&typeof T=="number";if(o?.streamingView==="status"&&b){Q(d);return}if(O){let R=ke(d.markdown??""),w=fe(O),H=n.features?.artifacts?.filePreview?.enabled!==!1;if(!b&&M==="rendered"&&H&&(w==="html"||w==="svg")){let ue=d.id+"\0"+R;if(p&&u===ue&&p.parentElement===f)return;x(),J(),y(),f.replaceChildren();let X=n.features?.artifacts?.filePreview,ee=X?.iframeSandbox??"allow-scripts";!X?.dangerouslyAllowSameOrigin&&ee.includes("allow-same-origin")&&(console.warn("[AgentWidget] Stripped allow-same-origin from filePreview.iframeSandbox: it lets artifact content run with the page origin. Set filePreview.dangerouslyAllowSameOrigin to keep it."),ee=ee.split(/\s+/).filter(B=>B&&B!=="allow-same-origin").join(" "));let me=Qt(X?.loading),U=m("div","persona-artifact-frame"),te=m("iframe","persona-artifact-iframe");te.setAttribute("sandbox",ee),te.setAttribute("data-artifact-id",d.id);let Ae=null;me.enabled&&me.injectReadySignal?(Ae=tn(),te.srcdoc=R+nn(Ae)):te.srcdoc=R,U.appendChild(te),f.appendChild(U),me.enabled&&(c=rn(U,te,Ae,me,d.id,n)),p=U,u=ue;return}if(y(),!b&&w==="markdown"&&M==="rendered"){W(R);return}z(R,{language:O.language,path:O.path},d,F);return}if(d.artifactType==="markdown"){if(M==="source"){y(),z(d.markdown??"",void 0,d,F);return}W(d.markdown??"");return}y(),x(),J(),f.replaceChildren();let k=d.component?r.get(d.component):void 0;if(k){let w={message:{id:d.id,role:"assistant",content:"",createdAt:new Date().toISOString()},config:n,updateProps:()=>{}};try{let H=k(d.props??{},w);if(H){f.appendChild(H);return}}catch{}}f.appendChild(Yt(d))};return Z(e),{el:f,update(d){Z(d)},destroy(){y()}}}import{Check as an,ChevronDown as sn,Maximize as ln,Minimize as cn}from"lucide";function Lt(e,t){let n=t.orientation??"horizontal",r=n==="vertical"?"ArrowUp":"ArrowLeft",o=n==="vertical"?"ArrowDown":"ArrowRight";e.setAttribute("role","tablist");let s=[],i=!1,l=p=>{typeof p.scrollIntoView=="function"&&p.scrollIntoView({block:"nearest",inline:"nearest"})},A=p=>{let u=p;return s.findIndex(c=>c===u||c.contains(u))},h=p=>{let u=A(p.target);if(u<0)return;let c=u;if(p.key===o)c=Math.min(u+1,s.length-1);else if(p.key===r)c=Math.max(u-1,0);else if(p.key==="Home")c=0;else if(p.key==="End")c=s.length-1;else return;p.preventDefault(),c!==u&&t.onSelect(c)},f=p=>{let u=A(p.target);u>=0&&l(s[u])};return e.addEventListener("keydown",h),e.addEventListener("focusin",f),{beforeRender(){i=typeof document<"u"&&e.contains(document.activeElement)},render(p,u){if(s=p,p.forEach((c,y)=>{c.setAttribute("role","tab");let g=y===u;c.setAttribute("aria-selected",g?"true":"false"),c.tabIndex=g||u<0&&y===0?0:-1}),i){let c=(u>=0?p[u]:void 0)??p[0];c&&typeof c.focus=="function"&&(l(c),c.focus())}},destroy(){e.removeEventListener("keydown",h),e.removeEventListener("focusin",f)}}}function Tt(e,t){let n=e.features?.artifacts?.layout,o=(n?.toolbarPreset??"default")==="document",s=n?.toolbarTitle??"Artifacts",i=n?.closeButtonLabel??"Close",l=n?.panePadding?.trim(),A=n?.tabFadeSize?.trim(),h=a=>({start:a===!1?!1:typeof a=="object"&&a?a.start!==!1:!0,end:a===!1?!1:typeof a=="object"&&a?a.end!==!1:!0}),{start:f,end:p}=h(n?.tabFade),u=typeof document<"u"?m("div","persona-artifact-backdrop persona-fixed persona-inset-0 persona-z-[55] persona-bg-black/30 persona-hidden md:persona-hidden"):null,c=()=>{u?.classList.add("persona-hidden"),y.classList.remove("persona-artifact-drawer-open"),K?.closeMenu()};u&&u.addEventListener("click",()=>{c(),t.onDismiss?.()});let y=m("aside","persona-artifact-pane persona-flex persona-flex-col persona-min-h-0 persona-min-w-0 persona-bg-persona-surface persona-text-persona-primary persona-border-l persona-border-persona-border");y.setAttribute("data-persona-theme-zone","artifact-pane"),o&&y.classList.add("persona-artifact-pane-document");let g=m("div","persona-artifact-toolbar persona-flex persona-items-center persona-justify-between persona-gap-2 persona-px-2 persona-py-2 persona-border-b persona-border-persona-border persona-shrink-0");g.setAttribute("data-persona-theme-zone","artifact-toolbar"),o&&g.classList.add("persona-artifact-toolbar-document");let S=m("span","persona-text-xs persona-font-medium persona-truncate");S.textContent=s;let I=V({icon:"x",label:i});I.addEventListener("click",()=>{c(),t.onDismiss?.()});let L="rendered",x=Te({items:[{id:"rendered",icon:"eye",label:"Rendered view",className:o?"persona-artifact-doc-icon-btn persona-artifact-view-btn":void 0},{id:"source",icon:"code-xml",label:"Source",className:o?"persona-artifact-doc-icon-btn persona-artifact-code-btn":void 0}],selectedId:"rendered",className:"persona-artifact-toggle-group persona-shrink-0",onSelect:a=>{L=a==="source"?"source":"rendered",Le()}}),P=m("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0"),$=n?.documentToolbarShowCopyLabel===!0,J=n?.documentToolbarShowCopyChevron===!0,re=n?.documentToolbarCopyMenuItems,Y=!!(J&&re&&re.length>0),ie=null,_,K=null;if(o&&($||J)&&!Y){if(_=$?ge({icon:"copy",label:"Copy",iconSize:14,className:"persona-artifact-doc-copy-btn"}):V({icon:"copy",label:"Copy",className:"persona-artifact-doc-copy-btn"}),J){let a=ye(sn,14,"currentColor",2);a&&_.appendChild(a)}}else o&&Y?(K=lt({label:"Copy",icon:"copy",iconSize:14,iconOnly:!$,primaryClassName:"persona-artifact-doc-copy-btn",chevronLabel:"More copy options",chevronClassName:"persona-artifact-doc-copy-menu-chevron persona-artifact-doc-icon-btn",menuItems:(re??[]).map(a=>({id:a.id,label:a.label})),position:"bottom-right",portal:()=>y.closest("[data-persona-root]")??document.body,onSelect:a=>{k(a)}}),ie=K.element,_=K.primaryButton):o?_=V({icon:"copy",label:"Copy",className:"persona-artifact-doc-icon-btn"}):(_=V({icon:"copy",label:"Copy"}),n?.showCopyButton!==!0&&_.classList.add("persona-hidden"));let D=o?V({icon:"refresh-cw",label:"Refresh",className:"persona-artifact-doc-icon-btn"}):V({icon:"refresh-cw",label:"Refresh"});n?.onDocumentToolbarRefresh||D.classList.add("persona-hidden");let z=o?V({icon:"x",label:i,className:"persona-artifact-doc-icon-btn"}):V({icon:"x",label:i}),W=V({icon:"maximize",label:"Expand artifacts panel",className:"persona-artifact-expand-btn"+(o?" persona-artifact-doc-icon-btn":""),onClick:()=>t.onToggleExpand?.()});n?.showExpandToggle!==!0&&W.classList.add("persona-hidden");let Q=m("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0 persona-artifact-toolbar-custom-actions"),Z=e.features?.artifacts?.toolbarActions??[],d=()=>{let a=B.find(ae=>ae.id===q)??B[B.length-1],C=a?.id??null,v=a?.artifactType==="markdown"?a.markdown??"":"",E=a?JSON.stringify({component:a.component,props:a.props},null,2):"",{filename:N,mime:G,content:se}=Se({title:a?.title,markdown:a?.markdown??"",file:a?.file});return{markdown:v,jsonPayload:E,id:C,file:a?.file,suggestedFilename:N,mime:G,content:se}},M=()=>{let{suggestedFilename:a,mime:C,content:v}=d();v&&Ee({filename:a,mime:C,content:v})},O=a=>{let{id:C,...v}=d();return{actionId:a,artifactId:C,...v}},b=async()=>{let a=B.find(C=>C.id===q)??B[B.length-1];try{return await navigator.clipboard.writeText(He(a)),!0}catch{return!1}},T=null,F=()=>{T?.();let a=_.querySelector("svg"),C=Number(a?.getAttribute("width"))||16,v=ye(an,C,"currentColor",2);if(!a||!v)return;a.replaceWith(v);let E=_.querySelector("span");E&&(E.textContent="Copied");let N=setTimeout(()=>T?.(),2e3);T=()=>{clearTimeout(N),v.replaceWith(a),E&&(E.textContent="Copy"),T=null}};_.addEventListener("click",async()=>{let a=n?.onDocumentToolbarCopyMenuSelect;if(a&&Y){try{if(await a(O("primary"))===!1){await b()&&F();return}F()}catch{}return}await b()&&F()});async function k(a){let C=n?.onDocumentToolbarCopyMenuSelect;try{if(C&&await C(O(a))!==!1)return;if(a==="download"){M();return}let{markdown:v,jsonPayload:E}=d();a==="markdown"||a==="md"?await navigator.clipboard.writeText(v):a==="json"||a==="source"?await navigator.clipboard.writeText(E):await navigator.clipboard.writeText(v||E),F()}catch{}}D.addEventListener("click",async()=>{try{await n?.onDocumentToolbarRefresh?.()}catch{}Le()}),z.addEventListener("click",()=>{c(),t.onDismiss?.()});let R=m("span","persona-min-w-0 persona-flex-1 persona-text-xs persona-font-medium persona-text-persona-primary persona-truncate persona-text-center md:persona-text-left");if(o)g.replaceChildren(),ie?P.append(ie,D,z):P.append(_,D,z),P.insertBefore(Q,z),P.insertBefore(W,z),g.append(x.element,R,P);else{let a=m("div","persona-flex persona-items-center persona-gap-1 persona-shrink-0");a.append(_,Q,W,I),g.appendChild(S),g.appendChild(a)}l&&(g.style.paddingLeft=l,g.style.paddingRight=l);let w=m("div","persona-artifact-list persona-shrink-0 persona-flex persona-gap-1 persona-overflow-x-auto persona-p-2 persona-border-b persona-border-persona-border");A&&w.style.setProperty("--persona-artifact-tab-fade-size",A);let H=e.features?.artifacts?.renderTabBar,j=m("div","persona-artifact-tab-custom persona-shrink-0 persona-border-b persona-border-persona-border persona-hidden"),ue=Lt(w,{onSelect:a=>t.onSelect(B[a].id)}),X=a=>{let C=a.scrollWidth-a.clientWidth,v=C>1,E=Math.abs(a.scrollLeft);a.classList.toggle("persona-artifact-tab-fade-start",f&&v&&E>1),a.classList.toggle("persona-artifact-tab-fade-end",p&&v&&E<C-1)},ee=0,me=()=>{if(ee)return;let a=()=>{ee=0,X(w)};ee=typeof requestAnimationFrame=="function"?requestAnimationFrame(a):setTimeout(a,0)};w.addEventListener("scroll",()=>me(),{passive:!0}),typeof ResizeObserver<"u"&&new ResizeObserver(()=>X(w)).observe(w);let U=m("div","persona-artifact-content persona-flex-1 persona-min-h-0 persona-overflow-y-auto persona-p-3"),te=()=>{U.scrollLeft=0},Ae=()=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(te):setTimeout(te,0)};if(l){for(let a of[w,j])a.style.paddingLeft=l,a.style.paddingRight=l;U.style.padding=l}y.appendChild(g),y.appendChild(w),y.appendChild(j),y.appendChild(U);let B=[],q=null,Oe=!1,Ue=!1,Fe=!0,_e=!1,$e=null,De="",ne=null,xe=!1,Bt=a=>a.artifactType==="markdown"&&!!a.file||o?L:"rendered",qe=a=>{o||(a&&!xe?(g.insertBefore(x.element,S),xe=!0):!a&&xe&&(x.element.remove(),xe=!1))},Ge=()=>q&&B.find(a=>a.id===q)||B[B.length-1],Ke=()=>{let a=ve(Ge());if(!a){Q.replaceChildren();return}let C=Z.filter(v=>v.visible===void 0||v.visible(a)).map(v=>be(v,{documentChrome:o,onClick:()=>{let E=ve(Ge());if(E)try{Promise.resolve(v.onClick(E)).catch(()=>{})}catch{}}}));Q.replaceChildren(...C)},Le=()=>{Ke();let a=o&&B.length<=1,C=!!H;if(w.classList.toggle("persona-hidden",a||C),j.classList.toggle("persona-hidden",a||!C),C&&H){let N=B.map(G=>G.id).join("|")+" "+(q??"");if(N!==De){De=N;let G=H({records:B,selectedId:q,onSelect:t.onSelect});j.firstElementChild!==G&&j.replaceChildren(G)}}else{ue.beforeRender(),w.replaceChildren();let N=[],G=-1;for(let[se,ae]of B.entries()){let le=m("button","persona-artifact-tab persona-shrink-0 persona-rounded-lg persona-px-2 persona-py-1 persona-text-xs persona-border persona-border-transparent persona-text-persona-primary");le.type="button";let je=ae.artifactType==="markdown"?ae.file:void 0,Xe=je?oe(je.path):ae.title||ae.id.slice(0,8),Ye=je?.path||ae.title||Xe;le.textContent=Xe,le.title=Ye,le.setAttribute("aria-label",Ye),ae.id===q&&(le.classList.add("persona-bg-persona-container","persona-border-persona-border"),G=se),le.addEventListener("click",()=>t.onSelect(ae.id)),w.appendChild(le),N.push(le)}if(ue.render(N,G),G>=0&&q!==$e){$e=q;let se=N[G];typeof se.scrollIntoView=="function"&&se.scrollIntoView({block:"nearest",inline:"nearest"})}X(w)}let v=q&&B.find(N=>N.id===q)||B[B.length-1];if(!v){U.replaceChildren(),ne?.destroy(),ne=null,qe(!1);return}let E=v.artifactType==="markdown"?v.file:void 0;if(qe(!!E&&fe(E)!=="other"),o){let N=E?ce(E):v.artifactType==="markdown"?"MD":v.component??"Component",G=(v.title||"Document").trim(),se=E?oe(E.path):G.replace(/\s*·\s*MD\s*$/i,"").trim()||"Document";R.textContent=`${se} \xB7 ${N}`}else S.textContent=E?oe(E.path):s;ne?(ne.el.parentElement!==U&&U.replaceChildren(ne.el),ne.update(v)):(ne=Ie(v,{config:e,resolveViewMode:Bt}),U.replaceChildren(ne.el)),U.classList.toggle("persona-artifact-content-flush",!!U.querySelector(".persona-code-pre"))},Ze=()=>{let a=B.length>0;if(y.classList.toggle("persona-hidden",!a),u){let E=((typeof y.closest=="function"?y.closest("[data-persona-root]"):null)?.classList.contains("persona-artifact-narrow-host")??!1)||typeof window<"u"&&window.matchMedia("(max-width: 640px)").matches;a&&E&&Oe?(u.classList.remove("persona-hidden"),y.classList.add("persona-artifact-drawer-open")):(u.classList.add("persona-hidden"),y.classList.remove("persona-artifact-drawer-open"))}},Je=()=>{_e=!1,Le(),Ze()};return{element:y,backdrop:u,update(a){let C=a.selectedId??a.artifacts[a.artifacts.length-1]?.id??null,v=C!==q;B=a.artifacts,q=C,B.length>0&&(Oe=!0),_e=!0,Fe&&Je(),v&&te()},setMobileOpen(a){Oe=a,!a&&u?(u.classList.add("persona-hidden"),y.classList.remove("persona-artifact-drawer-open")):Ze()},setExpanded(a){a!==Ue&&(Ue=a,Ae());let C=ye(a?cn:ln,16,"currentColor",2);C&&W.replaceChildren(C);let v=a?"Collapse artifacts panel":"Expand artifacts panel";W.setAttribute("aria-label",v),W.title=v},setExpandToggleVisible(a){W.classList.toggle("persona-hidden",!a)},setCopyButtonVisible(a){o||_.classList.toggle("persona-hidden",!a)},setRefreshButtonVisible(a){D.classList.toggle("persona-hidden",!a)},setCustomActions(a){Z=a,Ke()},setTabFade(a){let C=h(a);C.start===f&&C.end===p||(f=C.start,p=C.end,X(w))},setRenderTabBar(a){a!==H&&(H=a,De="",Le())},setVisible(a){a!==Fe&&(Fe=a,a&&_e&&Je())},destroy(){ne?.destroy(),ne=null}}}import{FileText as dn}from"lucide";function kt(e,t){let n=e.file&&typeof e.file=="object"&&!Array.isArray(e.file)?e.file:void 0,r=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",o=n?oe(n.path):r,s=typeof e.artifactId=="string"?e.artifactId:"",i=e.status==="streaming"?"streaming":"complete",l=typeof e.artifactType=="string"?e.artifactType:"markdown",A=e.presentation&&typeof e.presentation=="object"&&!Array.isArray(e.presentation)?e.presentation:void 0,h=n?ce(n):l==="component"?"Component":"Document",f=document.createElement("div");f.className="persona-artifact-card persona-flex persona-w-full persona-max-w-full persona-items-center persona-gap-3 persona-px-4 persona-py-3",f.tabIndex=0,f.setAttribute("role","button"),f.setAttribute("aria-label",`Open ${o} in artifact panel`),s&&f.setAttribute("data-open-artifact",s);let p=document.createElement("div");p.className="persona-flex persona-h-10 persona-w-10 persona-flex-shrink-0 persona-items-center persona-justify-center persona-rounded-lg",p.style.border="1px solid var(--persona-border, #e5e7eb)",p.style.color="var(--persona-muted, #9ca3af)",p.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg>';let u=document.createElement("div");u.className="persona-min-w-0 persona-flex-1 persona-flex persona-flex-col persona-gap-0.5";let c=document.createElement("div");c.className="persona-truncate persona-text-sm persona-font-medium",c.style.color="var(--persona-text, #1f2937)",c.textContent=o;let y=document.createElement("div");if(y.className="persona-text-xs persona-flex persona-items-center persona-gap-1.5",y.style.color="var(--persona-muted, #9ca3af)",i==="streaming"){let g=t?.config?.features?.artifacts,S={id:s,artifactType:l==="component"?"component":"markdown",title:r,status:"streaming",...typeof e.markdown=="string"?{markdown:e.markdown}:{},...n?{file:n}:{},...A?{presentation:A}:{}},I=we(S,g,"card");pe(y,I,g)}else s&&he(s),y.textContent=h;if(u.append(c,y),f.append(p,u),i==="complete"){let g=t?.config?.features?.artifacts?.cardActions;if(g&&g.length>0){let I={artifactId:s||null,title:o,artifactType:l,markdown:typeof e.markdown=="string"?e.markdown:void 0,file:n};for(let L of g)try{if(L.visible===void 0||L.visible(I)){let x=be(L);x.setAttribute("data-artifact-custom-action",L.id),x.className=`${x.className} persona-flex-shrink-0`,f.append(x)}}catch{}}let S=ge({label:"Download",className:"persona-flex-shrink-0"});S.title=`Download ${o}`,S.setAttribute("data-download-artifact",s),f.append(S)}return f}var Be=(e,t)=>{let n=t?.config?.features?.artifacts?.renderCard;if(n){let r=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",o=typeof e.artifactId=="string"?e.artifactId:"",s=e.status==="streaming"?"streaming":"complete",i=typeof e.artifactType=="string"?e.artifactType:"markdown",l=n({artifact:{artifactId:o,title:r,artifactType:i,status:s},config:t.config,defaultRenderer:()=>kt(e,t)});if(l)return l}return kt(e,t)};var de=new WeakMap;function Rt(e,t,n){if(t.length===0)return;let r=new Map(t.map(o=>[o.id,o]));e.querySelectorAll("[data-artifact-inline]").forEach(o=>{let s=de.get(o);if(!s)return;let i=r.get(o.getAttribute("data-artifact-inline")??"");i&&s(i,n)})}function Ht(e){return de.has(e)}function fn(e){let t=typeof e.artifactId=="string"?e.artifactId:"",n=typeof e.title=="string"&&e.title?e.title:void 0,r=e.status==="streaming"?"streaming":"complete",o=e.presentation&&typeof e.presentation=="object"&&!Array.isArray(e.presentation)?e.presentation:void 0;if(e.artifactType==="component"){let i=e.componentProps,l=i&&typeof i=="object"&&!Array.isArray(i)?i:{};return{id:t,artifactType:"component",title:n,status:r,component:typeof e.component=="string"?e.component:"",props:l,...o?{presentation:o}:{}}}let s=e.file&&typeof e.file=="object"&&!Array.isArray(e.file)?e.file:void 0;return{id:t,artifactType:"markdown",title:n,status:r,markdown:typeof e.markdown=="string"?e.markdown:"",...s?{file:s}:{},...o?{presentation:o}:{}}}function St(e){let t=e.artifactType==="markdown"?e.file:void 0,n=t?oe(t.path):e.title&&e.title.trim()?e.title:"Untitled artifact",r=t?ce(t):e.artifactType==="component"?"Component":"Document";return{title:n,typeLabel:r}}function pn(e){let t={artifactId:e.id,title:e.title??"",status:e.status,artifactType:e.artifactType};return e.artifactType==="markdown"&&(typeof e.markdown=="string"&&(t.markdown=e.markdown),e.file&&(t.file=e.file)),t}var Et=180,un=240,mn=.8,yn=300,gn=500,bn="cubic-bezier(0.2, 0, 0, 1)",Pt=240,hn=.35;function wn(e,t,n){let{swap:r,onSettled:o}=n,s=!1;try{s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch{s=!1}if(!t||!e.isConnected||s||typeof e.animate!="function"){r(),o();return}e.style.height=`${t}px`,e.style.overflow="hidden";let i=[];for(let l of Array.from(e.children))l instanceof HTMLElement&&i.push(l.animate([{opacity:1},{opacity:0}],{duration:Et,easing:"ease-out",fill:"forwards"}));window.setTimeout(()=>{for(let I of i)I.cancel();r();let l=()=>{e.style.removeProperty("height"),e.style.removeProperty("overflow")};if(!e.isConnected){l(),o();return}e.style.height="auto";let A=e.getBoundingClientRect().height;if(e.style.height=`${t}px`,!A||Math.abs(A-t)<1){l(),o();return}let h=Math.abs(t-A),f=Math.round(Math.min(gn,Math.max(yn,un+h*mn))),p=Math.round(f*hn),u=e.firstElementChild instanceof HTMLElement?e.firstElementChild:null,c=u?u.animate([{opacity:0},{opacity:1}],{duration:Pt,delay:p,easing:"ease-out",fill:"backwards"}):null,y=e.animate([{height:`${t}px`},{height:`${A}px`}],{duration:f,easing:bn});e.style.height=`${A}px`;let g=!1,S=()=>{g||(g=!0,l(),o())};Promise.allSettled([y.finished,c?.finished].filter(Boolean)).then(S),window.setTimeout(S,Math.max(f,p+Pt)+120)},Et)}function An(e){let t=e?.inlineChrome;if(t===!1)return{chromeEnabled:!1,showCopy:!1,showExpand:!1,showViewToggle:!1};let n=typeof t=="object"?t:void 0;return{chromeEnabled:!0,showCopy:n?.showCopy!==!1,showExpand:n?.showExpand!==!1,showViewToggle:n?.showViewToggle!==!1}}var Ce="--persona-artifact-inline-body-height";function vn(e){let t=e?.inlineBody,n=t?.streamingView==="status"?"status":"source",r=t?.viewMode==="source"?"source":"rendered",o=320,s=320,i=t?.height;typeof i=="number"||i==="auto"?(o=i,s=i):i&&typeof i=="object"&&(o=i.streaming??320,s=i.complete??320);let l=t?.overflow==="clip"?"clip":"scroll",A=l==="clip"?!1:t?.followOutput!==!1,h,f,p=t?.fadeMask;p===!0?(h=!0,f=!0):p===!1?(h=!1,f=!1):p&&typeof p=="object"?(h=p.top===!0,f=p.bottom===!0):l==="clip"?(h=!1,f=!0):(h=!0,f=!0);let u=t?.transition==="none"?"none":"auto",c=t?.completeDisplay==="card"?"card":"inline";return{streamingView:n,viewMode:r,streamingHeight:o,completeHeight:s,followOutput:A,overflow:l,fadeTop:h,fadeBottom:f,transition:u,completeDisplay:c}}function Mt(e,t){let n=fn(e),r=t.config?.features?.artifacts,{chromeEnabled:o,showCopy:s,showExpand:i,showViewToggle:l}=An(r),A=r?.inlineActions??[],h=vn(r),f=h.completeDisplay==="card",p=null,u=n,c=m("div","persona-artifact-inline persona-w-full persona-max-w-full");c.setAttribute("data-persona-theme-zone","artifact-inline"),n.id&&c.setAttribute("data-artifact-inline",n.id);let y=b=>Be(pn(b),t),g=null,S=b=>{g?.destroy(),g=null,c.classList.add("persona-artifact-inline--card"),c.style.removeProperty(Ce),c.replaceChildren(y(b)),de.set(c,T=>{c.replaceChildren(y(T))})};if(f&&n.status==="complete")return S(n),c;let I=Ie(n,{config:t.config,bodyLayout:h,resolveViewMode:()=>p??h.viewMode});g=I;let L=m("div","persona-artifact-inline-body");L.appendChild(I.el);let x=b=>{let T=b.status!=="complete",F=T?h.streamingHeight:h.completeHeight,k=typeof F=="number";k?c.style.setProperty(Ce,`${F}px`):c.style.removeProperty(Ce);let R=!!I.el.querySelector(".persona-code-pre"),w=!!I.el.querySelector("iframe, .persona-artifact-source-window--fixed, .persona-artifact-status-view");L.classList.toggle("persona-artifact-content-flush",R),L.classList.toggle("persona-artifact-inline-body--sized",k&&w),L.classList.toggle("persona-artifact-inline-body--cap",!T&&!w&&typeof h.completeHeight=="number")},P=n.status,$=(b,T)=>{P!=="complete"&&b.status==="complete"?(typeof h.completeHeight=="number"?c.style.setProperty(Ce,`${h.completeHeight}px`):c.style.removeProperty(Ce),xt(L,T?.suppressTransition?"none":h.transition,b.id,()=>{I.update(b),x(b)})):I.update(b),x(b),P=b.status};x(n);let J=h.overflow==="clip"&&i&&!!n.id;if(J&&(L.setAttribute("data-expand-artifact-inline",n.id),L.setAttribute("role","button"),L.setAttribute("tabindex","0"),L.classList.add("persona-cursor-pointer"),L.setAttribute("aria-label",`Open ${St(n).title} in panel`)),!o)return c.appendChild(L),de.set(c,$),c;let re=m("div","persona-artifact-inline-chrome");re.setAttribute("data-persona-theme-zone","artifact-inline-chrome");let Y=m("div","persona-artifact-inline-chrome-lead"),ie=m("span","persona-flex persona-items-center persona-flex-shrink-0"),_=ye(dn,16,"currentColor",2);_&&ie.appendChild(_);let K=m("span","persona-artifact-inline-title persona-truncate persona-min-w-0"),D=m("span","persona-artifact-inline-type");Y.append(ie,K,D);let z=m("div","persona-artifact-inline-chrome-actions"),W=m("span","persona-flex persona-items-center persona-gap-1"),Q=()=>p??h.viewMode,Z=l?Te({items:[{id:"rendered",icon:"eye",label:"Rendered view",className:"persona-artifact-doc-icon-btn persona-artifact-view-btn"},{id:"source",icon:"code-xml",label:"Source",className:"persona-artifact-doc-icon-btn persona-artifact-code-btn"}],selectedId:Q(),className:"persona-artifact-toggle-group persona-flex-shrink-0",onSelect:b=>{let T=b==="source"?"source":"rendered";T!==Q()&&(p=T,I.update(u),x(u))}}):null,d=s?V({icon:"copy",label:"Copy",className:"persona-artifact-doc-icon-btn persona-flex-shrink-0"}):null;d&&n.id&&d.setAttribute("data-copy-artifact",n.id);let M=i?V({icon:"maximize",label:"Open in panel",className:"persona-artifact-doc-icon-btn persona-flex-shrink-0"}):null;M&&n.id&&M.setAttribute("data-expand-artifact-inline",n.id),z.appendChild(W),Z&&z.appendChild(Z.element),d&&z.appendChild(d),M&&z.appendChild(M),re.append(Y,z),c.append(re,L);let O=b=>{let{title:T,typeLabel:F}=St(b);K.textContent=T,K.title=T,J&&L.setAttribute("aria-label",`Open ${T} in panel`);let k=b.status!=="complete";if(k){D.classList.contains("persona-artifact-inline-status")||(D.className="persona-artifact-inline-status",D.removeAttribute("data-preserve-animation"),D.replaceChildren());let R=we(b,r,"inline-chrome");pe(D,R,r)}else he(b.id),D.className="persona-artifact-inline-type",D.removeAttribute("data-preserve-animation"),D.replaceChildren(),D.textContent=F;if(d&&d.classList.toggle("persona-hidden",k),Z){let R=b.artifactType==="markdown"?b.file:void 0,w=!1;if(!k&&R&&h.viewMode!=="source"){let H=fe(R);H==="markdown"?w=!0:(H==="html"||H==="svg")&&(w=r?.filePreview?.enabled!==!1)}Z.element.classList.toggle("persona-hidden",!w),Z.setSelected(Q())}if(W.replaceChildren(),!k&&A.length>0){let R=ve(b);if(R)for(let w of A)try{if(w.visible===void 0||w.visible(R)){let H=be(w,{documentChrome:!0});H.setAttribute("data-artifact-custom-action",w.id),H.classList.add("persona-flex-shrink-0"),W.appendChild(H)}}catch{}}};return O(n),de.set(c,(b,T)=>{if(f&&P!=="complete"&&b.status==="complete"){let F=c.isConnected?c.getBoundingClientRect().height:0;P="complete";let k=b,R=!1,w=H=>{k=H,R=!0};de.set(c,w),wn(c,F,{swap:()=>{S(k),R=!1,de.set(c,w)},onSettled:()=>{R?S(k):de.set(c,H=>{c.replaceChildren(y(H))})}});return}(b.status!=="complete"||b.id!==u.id)&&(p=null),u=b,$(b,T),O(b)}),c}var It=(e,t)=>{let n=t?.config?.features?.artifacts?.renderInline;if(n){let r=typeof e.title=="string"&&e.title?e.title:"Untitled artifact",o=typeof e.artifactId=="string"?e.artifactId:"",s=e.status==="streaming"?"streaming":"complete",i=typeof e.artifactType=="string"?e.artifactType:"markdown",l=n({artifact:{artifactId:o,title:r,artifactType:i,status:s},config:t.config,defaultRenderer:()=>Mt(e,t)});if(l)return l}return Mt(e,t)};export{Be as PersonaArtifactCard,It as PersonaArtifactInline,et as __provideMarkdownParsers,st as __setIconsExtraLoader,He as artifactCopyText,Tt as createArtifactPane,Se as downloadInfoFor,Ht as hasLiveInlineArtifactBlock,vt as initArtifactsUi,Ee as triggerArtifactDownload,Rt as updateInlineArtifactBlocks};
@@ -1,4 +0,0 @@
1
- var c="webmcp:",g=new Map,A=t=>{g.clear();for(let r of t){let e=r.title?.trim();e&&g.set(r.name,e)}},w=t=>g.get(h(t)),u=null;function R(t){if(t.length===0)return"0:empty";let r=t.map(e=>[e.name,e.description??"",e.parametersSchema?JSON.stringify(e.parametersSchema):"",e.origin??"",e.annotations?JSON.stringify(e.annotations):""].join("")).sort();return`${t.length}:${m(r.join(""))}`}function p(t,r){let e=3735928559^r,n=1103547991^r;for(let o=0;o<t.length;o++){let s=t.charCodeAt(o);e=Math.imul(e^s,2654435761),n=Math.imul(n^s,1597334677)}return e=Math.imul(e^e>>>16,2246822507),e^=Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(e^e>>>13,3266489909),4294967296*(2097151&n)+(e>>>0)}function m(t){let r=p(t,0).toString(36),e=p(t,2654435761).toString(36);return`${r}.${e}`}var h=t=>t.startsWith(c)?t.slice(c.length):t,D=t=>t.startsWith(c),E=()=>u?u():import("@mcp-b/webmcp-polyfill");import{parse as T,STR as y,OBJ as M}from"partial-json";var d=t=>t.replace(/\\n/g,`
2
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"),_=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}},W=t=>{let r=t.completedAt??Date.now(),e=t.startedAt??r,o=(t.durationMs!==void 0?t.durationMs:Math.max(0,r-e))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},F=t=>t.status==="complete"?W(t):t.status==="pending"?"Waiting":"",P=t=>{let e=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,(t.completedAt??Date.now())-(t.startedAt??t.completedAt??Date.now())))/1e3;return e<.1?"Used tool for <0.1 seconds":`Used tool for ${e>=10?Math.round(e).toString():e.toFixed(1).replace(/\.0$/,"")} seconds`};var C=t=>t.status==="complete"?P(t):"Using tool...",x=t=>{let r=t/1e3;return r<.1?"<0.1s":r>=10?`${Math.round(r)}s`:`${r.toFixed(1).replace(/\.0$/,"")}s`},S=t=>{let r=typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,(t.completedAt??Date.now())-(t.startedAt??t.completedAt??Date.now()));return x(r)},$=t=>{let r=t.durationMs!==void 0?t.durationMs:Math.max(0,(t.completedAt??Date.now())-(t.startedAt??t.completedAt??Date.now()));return x(r)},I=(t,r,e)=>{if(!r)return e;let n=t.name?.trim()||"tool",o=S(t);return r.replace(/\{toolName\}/g,n).replace(/\{duration\}/g,o)},N=(t,r)=>{let e=t.replace(/\{toolName\}/g,r),n=[],o=/\*\*(.+?)\*\*|\*(.+?)\*|~(.+?)~/g,s=0,i;for(;(i=o.exec(e))!==null;)i.index>s&&l(n,e.slice(s,i.index),[]),i[1]!==void 0?l(n,i[1],["bold"]):i[2]!==void 0?l(n,i[2],["italic"]):i[3]!==void 0&&l(n,i[3],["dim"]),s=i.index+i[0].length;return s<e.length&&l(n,e.slice(s),[]),n},l=(t,r,e)=>{let n=r.split("{duration}");for(let o=0;o<n.length;o++)n[o]&&t.push({text:n[o],styles:e}),o<n.length-1&&t.push({text:"{duration}",styles:e,isDuration:!0})},b=()=>{let t=null,r=0,e=n=>{let o=/"text"\s*:\s*"((?:[^"\\]|\\.|")*?)"/,s=n.match(o);if(s&&s[1])try{return s[1].replace(/\\n/g,`
3
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return s[1]}let i=/"text"\s*:\s*"((?:[^"\\]|\\.)*)/,a=n.match(i);if(a&&a[1])try{return a[1].replace(/\\n/g,`
4
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return a[1]}return null};return{getExtractedText:()=>t,processChunk:async n=>{if(n.length<=r)return t!==null?{text:t,raw:n}:null;let o=n.trim();if(!o.startsWith("{")&&!o.startsWith("["))return null;let s=e(n);return s!==null&&(t=s),r=n.length,t!==null?{text:t,raw:n}:null},close:async()=>{}}},L=t=>{try{let r=JSON.parse(t);if(r&&typeof r=="object"&&typeof r.text=="string")return r.text}catch{return null}return null},O=()=>{let t={processChunk:r=>null,getExtractedText:()=>null};return t.__isPlainTextParser=!0,t},j=()=>{let t=b();return{processChunk:async r=>{let e=r.trim();return!e.startsWith("{")&&!e.startsWith("[")?null:t.processChunk(r)},getExtractedText:t.getExtractedText.bind(t),close:t.close?.bind(t)}},U=()=>{let t=null,r=0;return{getExtractedText:()=>t,processChunk:e=>{let n=e.trim();if(!n.startsWith("{")&&!n.startsWith("["))return null;if(e.length<=r)return t!==null||t===""?{text:t||"",raw:e}:null;try{let o=T(e,y|M);o&&typeof o=="object"&&(o.component&&typeof o.component=="string"?t=typeof o.text=="string"?d(o.text):"":o.type==="init"&&o.form?t="":typeof o.text=="string"&&(t=d(o.text)))}catch{}return r=e.length,t!==null?{text:t,raw:e}:null},close:()=>{}}};var B=()=>{let t=null;return{processChunk:r=>{if(!r.trim().startsWith("<"))return null;let n=r.match(/<text[^>]*>([\s\S]*?)<\/text>/);return n&&n[1]?(t=n[1],{text:t,raw:r}):null},getExtractedText:()=>t}};export{c as a,A as b,w as c,R as d,D as e,E as f,_ as g,F as h,C as i,x as j,S as k,$ as l,I as m,N as n,L as o,O as p,j as q,U as r,B as s};
@@ -1 +0,0 @@
1
- import{b as Ve,d as We,e as $e,f as ze}from"./chunk-VK6JOIYJ.js";import{a as F}from"./chunk-7NQ4ZTHF.js";import{a as l}from"./chunk-76IELU7F.js";import{Check as Je,ChevronDown as st,ChevronRight as at,Clipboard as Ue,ClipboardCopy as je,Search as it,X as qe}from"lucide";function ee(t,e){e&&e.split(/\s+/).forEach(n=>n&&t.classList.add(n))}var lt={flow_:{bg:"var(--persona-palette-colors-success-100, #dcfce7)",text:"var(--persona-palette-colors-success-700, #166534)"},step_:{bg:"var(--persona-palette-colors-primary-100, #f5f5f5)",text:"var(--persona-palette-colors-primary-700, #0a0a0a)"},reason_:{bg:"var(--persona-palette-colors-warning-100, #ffedd5)",text:"var(--persona-palette-colors-warning-700, #9a3412)"},tool_:{bg:"var(--persona-palette-colors-purple-100, #f3e8ff)",text:"var(--persona-palette-colors-purple-700, #6b21a8)"},agent_:{bg:"var(--persona-palette-colors-teal-100, #ccfbf1)",text:"var(--persona-palette-colors-teal-700, #115e59)"},error:{bg:"var(--persona-palette-colors-error-100, #fecaca)",text:"var(--persona-palette-colors-error-700, #991b1b)"}},pt={bg:"var(--persona-palette-colors-gray-100, #f3f4f6)",text:"var(--persona-palette-colors-gray-600, #4b5563)"},ut=["flowName","stepName","reasoningText","text","name","tool","toolName"],ct=100;function dt(t,e){let n={...lt,...e};if(n[t])return n[t];for(let r of Object.keys(n))if(r.endsWith("_")&&t.startsWith(r))return n[r];return pt}function ft(t,e){return`+${((t-e)/1e3).toFixed(3)}s`}function ht(t){let e=new Date(t),n=String(e.getHours()).padStart(2,"0"),r=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0"),a=String(e.getMilliseconds()).padStart(3,"0");return`${n}:${r}:${i}.${a}`}function mt(t,e){try{let n=JSON.parse(t);if(typeof n!="object"||n===null)return null;for(let r of e){let i=r.split("."),a=n;for(let p of i)if(a&&typeof a=="object"&&a!==null)a=a[p];else{a=void 0;break}if(typeof a=="string"&&a.trim())return a.trim()}}catch{}return null}function gt(t){return navigator.clipboard?.writeText?navigator.clipboard.writeText(t):new Promise(e=>{let n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),e()})}function vt(t){let e;try{e=JSON.parse(t.payload)}catch{e=t.payload}return JSON.stringify({type:t.type,timestamp:new Date(t.timestamp).toISOString(),payload:e},null,2)}function yt(t){return t.tokensPerSecond===void 0||!Number.isFinite(t.tokensPerSecond)?"-- tok/s":`${t.tokensPerSecond.toFixed(1)} tok/s`}function bt(t){let e=[];return t.outputTokens!==void 0&&e.push(`${t.outputTokens.toLocaleString()} tok`),t.durationMs!==void 0&&e.push(`${(t.durationMs/1e3).toFixed(2)}s`),t.source&&e.push(t.source),e.join(" \xB7 ")}function xt(t,e,n){let r,i;try{i=JSON.parse(t.payload),r=JSON.stringify(i,null,2)}catch{i=t.payload,r=t.payload}let a=e.find(g=>g.renderEventStreamPayload);if(a?.renderEventStreamPayload&&n){let g=a.renderEventStreamPayload({event:t,config:n,defaultRenderer:()=>p(),parsedPayload:i});if(g)return g}return p();function p(){let g=l("div","persona-bg-persona-container persona-border-t persona-border-persona-divider persona-px-3 persona-py-2 persona-ml-4 persona-mr-3 persona-mb-1 persona-rounded-b persona-overflow-auto persona-max-h-[300px]"),b=l("pre","persona-m-0 persona-whitespace-pre-wrap persona-break-all persona-text-[11px] persona-text-persona-secondary persona-font-mono");return b.textContent=r,g.appendChild(b),g}}function Se(t,e,n,r,i,a,p,g){let b=i.has(t.id),x=l("div","persona-border-b persona-border-persona-divider persona-text-xs");ee(x,r.classNames?.eventRow);let ue=p.find(L=>L.renderEventStreamRow);if(ue?.renderEventStreamRow&&g){let L=ue.renderEventStreamRow({event:t,index:e,config:g,defaultRenderer:()=>V(),isExpanded:b,onToggleExpand:()=>a(t.id)});if(L)return x.appendChild(L),x}return x.appendChild(V()),x;function V(){let L=l("div",""),D=l("div","persona-flex persona-items-center persona-gap-2 persona-px-3 persona-py-3 hover:persona-bg-persona-container persona-cursor-pointer persona-group");D.setAttribute("data-event-id",t.id);let te=l("span","persona-flex-shrink-0 persona-text-persona-muted persona-w-4 persona-text-center persona-flex persona-items-center persona-justify-center"),M=F(b?st:at,"14px","currentColor",2);M&&te.appendChild(M);let I=l("span","persona-text-[11px] persona-text-persona-muted persona-whitespace-nowrap persona-flex-shrink-0 persona-font-mono persona-w-[70px]"),S=r.timestampFormat??"relative";I.textContent=S==="relative"?ft(t.timestamp,n):ht(t.timestamp);let A=null;r.showSequenceNumbers!==!1&&(A=l("span","persona-text-[11px] persona-text-persona-muted persona-font-mono persona-flex-shrink-0 persona-w-[28px] persona-text-right"),A.textContent=String(e+1));let R=dt(t.type,r.badgeColors),N=l("span","persona-inline-flex persona-items-center persona-px-2 persona-py-0.5 persona-rounded persona-text-[11px] persona-font-mono persona-font-medium persona-whitespace-nowrap persona-flex-shrink-0 persona-border");N.style.backgroundColor=R.bg,N.style.color=R.text,N.style.borderColor=R.text+"50",N.textContent=t.type;let ne=r.descriptionFields??ut,Q=mt(t.payload,ne),W=null;Q&&(W=l("span","persona-text-[11px] persona-text-persona-secondary persona-truncate persona-min-w-0"),W.textContent=Q);let T=l("div","persona-flex-1 persona-min-w-0"),C=l("button","persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-flex-shrink-0 persona-border-none persona-bg-transparent persona-p-0"),re=F(Ue,"12px","currentColor",1.5);return re&&C.appendChild(re),C.addEventListener("click",async X=>{X.stopPropagation(),await gt(vt(t)),C.innerHTML="";let H=F(Je,"12px","currentColor",1.5);H&&C.appendChild(H),setTimeout(()=>{C.innerHTML="";let Z=F(Ue,"12px","currentColor",1.5);Z&&C.appendChild(Z)},1500)}),D.appendChild(te),D.appendChild(I),A&&D.appendChild(A),D.appendChild(N),W&&D.appendChild(W),D.appendChild(T),D.appendChild(C),L.appendChild(D),b&&L.appendChild(xt(t,p,g)),L}}function Ge(t){let{buffer:e,getFullHistory:n,onClose:r,config:i,plugins:a=[],getThroughput:p}=t,g=t.renderIconByName??(()=>null),b=i?.features?.scrollToBottom,x=b?.enabled!==!1,ue=b?.iconName??"arrow-down",V=b?.label??"",L=i?.features?.eventStream??{},D=a.find(M=>M.renderEventStreamView);if(D?.renderEventStreamView&&i){let M=D.renderEventStreamView({config:i,events:e.getAll(),defaultRenderer:()=>te().element,onClose:r});if(M)return{element:M,update:()=>{},destroy:()=>{}}}return te();function te(){let M=L.classNames,I=l("div","persona-event-stream-view persona-flex persona-flex-col persona-flex-1 persona-min-h-0");ee(I,M?.panel);let S=[],A="",R="",N=null,ne=[],Q={},W=0,T=Ve(),C=0,re=0,X=!1,H=null,Z=!1,Te=0,J=new Set,O=new Map,Ce="",we="",K=null,v,m,y,_,oe=null,B=null,$=null;function ve(){let o=l("div","persona-event-toolbar persona-relative persona-flex persona-flex-col persona-flex-shrink-0"),s=l("div","persona-flex persona-items-center persona-gap-2 persona-px-4 persona-py-3 persona-pb-0 persona-border-persona-divider persona-bg-persona-surface persona-overflow-hidden");if(ee(s,M?.headerBar),p){B=l("div","persona-relative persona-flex persona-items-center persona-gap-1.5 persona-whitespace-nowrap"),B.style.cursor="help",oe=l("span","persona-text-[11px] persona-font-mono persona-bg-persona-container persona-text-persona-muted persona-px-2 persona-py-0.5 persona-rounded persona-border persona-border-persona-border persona-tabular-nums"),oe.textContent="-- tok/s",$=l("div","persona-absolute persona-z-50 persona-whitespace-nowrap persona-rounded persona-border persona-border-persona-border persona-bg-persona-container persona-text-persona-primary persona-text-[11px] persona-font-mono persona-px-2 persona-py-1 persona-shadow"),$.style.display="none",$.style.pointerEvents="none";let q=B,pe=$,rt=()=>{if(!pe.textContent)return;let Be=q.getBoundingClientRect(),Fe=o.getBoundingClientRect();pe.style.left=`${Be.left-Fe.left}px`,pe.style.top=`${Be.bottom-Fe.top+4}px`,pe.style.display="block"},ot=()=>{pe.style.display="none"};B.addEventListener("mouseenter",rt),B.addEventListener("mouseleave",ot),B.appendChild(oe)}let u=l("div","persona-flex-1");v=l("select","persona-text-xs persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded persona-px-2.5 persona-py-1 persona-text-persona-primary persona-cursor-pointer");let E=l("option","");E.value="",E.textContent="All events (0)",v.appendChild(E),m=l("button","persona-inline-flex persona-items-center persona-gap-1.5 persona-rounded persona-text-xs persona-text-persona-muted hover:persona-bg-persona-container hover:persona-text-persona-primary persona-cursor-pointer persona-border persona-border-persona-border persona-bg-persona-surface persona-flex-shrink-0 persona-px-2.5 persona-py-1"),m.type="button",m.title="Copy All";let U=F(je,"12px","currentColor",1.5);U&&m.appendChild(U);let j=l("span","persona-event-copy-all persona-text-xs");j.textContent="Copy All",m.appendChild(j),B&&s.appendChild(B),s.appendChild(u),s.appendChild(v),s.appendChild(m);let c=l("div","persona-relative persona-px-4 persona-py-2.5 persona-border-b persona-border-persona-divider persona-bg-persona-surface");ee(c,M?.searchBar);let d=F(it,"14px","var(--persona-muted, #9ca3af)",1.5),h=l("span","persona-absolute persona-left-6 persona-top-1/2 persona--translate-y-1/2 persona-pointer-events-none persona-flex persona-items-center");d&&h.appendChild(d),y=l("input","persona-text-sm persona-bg-persona-surface persona-border persona-border-persona-border persona-rounded-md persona-pl-8 persona-pr-3 persona-py-1 persona-w-full persona-text-persona-primary"),ee(y,M?.searchInput),y.type="text",y.placeholder="Search event payloads...",_=l("button","persona-absolute persona-right-5 persona-top-1/2 persona--translate-y-1/2 persona-text-persona-muted hover:persona-text-persona-primary persona-cursor-pointer persona-border-none persona-bg-transparent persona-p-0 persona-leading-none"),_.type="button",_.style.display="none";let k=F(qe,"12px","currentColor",2);return k&&_.appendChild(k),c.appendChild(h),c.appendChild(y),c.appendChild(_),o.appendChild(s),o.appendChild(c),$&&o.appendChild($),o}let ye,ke=a.find(o=>o.renderEventStreamToolbar);ke?.renderEventStreamToolbar&&i?ye=ke.renderEventStreamToolbar({config:i,defaultRenderer:()=>ve(),eventCount:e.getSize(),filteredCount:0,onFilterChange:s=>{A=s,le(),G()},onSearchChange:s=>{R=s,le(),G()}})??ve():ye=ve();let se=l("div","persona-text-xs persona-text-persona-muted persona-text-center persona-py-0.5 persona-px-4 persona-bg-persona-container persona-border-b persona-border-persona-divider persona-italic persona-flex-shrink-0");se.style.display="none";function Xe(){if(!p||!oe||!B)return;let o=p(),s=yt(o);oe.textContent=s;let u=bt(o);$&&($.textContent=u,u||($.style.display="none")),B.setAttribute("aria-label",u?`Throughput: ${s}, ${u}`:`Throughput: ${s}`)}let ce=l("div","persona-flex-1 persona-min-h-0 persona-relative"),f=l("div","persona-event-stream-list persona-overflow-y-auto persona-min-h-0");f.style.height="100%";let w=l("div","persona-scroll-to-bottom-indicator persona-absolute persona-bottom-3 persona-left-1/2 persona-transform persona--translate-x-1/2 persona-cursor-pointer persona-z-10 persona-text-xs");ee(w,M?.scrollIndicator),w.style.display="none",w.setAttribute("data-persona-scroll-to-bottom-has-label",V?"true":"false");let Re=g(ue,"14px","currentColor",2);Re&&w.appendChild(Re);let ae=l("span","");ae.textContent=V,w.appendChild(ae);let ie=l("div","persona-flex persona-items-center persona-justify-center persona-h-full persona-text-sm persona-text-persona-muted");ie.style.display="none",ce.appendChild(f),ce.appendChild(ie),ce.appendChild(w),I.setAttribute("tabindex","0"),I.appendChild(ye),I.appendChild(se),I.appendChild(ce);function Ze(){let o=e.getAll(),s={};for(let c of o)s[c.type]=(s[c.type]||0)+1;let u=Object.keys(s).sort(),E=u.length!==ne.length||!u.every((c,d)=>c===ne[d]),z=!E&&u.some(c=>s[c]!==Q[c]),U=o.length!==Object.values(Q).reduce((c,d)=>c+d,0);if(!E&&!z&&!U||(ne=u,Q=s,!v))return;let j=v.value;if(v.options[0].textContent=`All events (${o.length})`,E){for(;v.options.length>1;)v.remove(1);for(let c of u){let d=l("option","");d.value=c,d.textContent=`${c} (${s[c]||0})`,v.appendChild(d)}j&&u.includes(j)?v.value=j:j&&(v.value="",A="")}else for(let c=1;c<v.options.length;c++){let d=v.options[c];d.textContent=`${d.value} (${s[d.value]||0})`}}function et(){let o=e.getAll();if(A&&(o=o.filter(s=>s.type===A)),R){let s=R.toLowerCase();o=o.filter(u=>u.type.toLowerCase().includes(s)||u.payload.toLowerCase().includes(s))}return o}function be(){return A!==""||R!==""}function le(){W=0,C=0,T.resume(),w.style.display="none"}function de(o){J.has(o)?J.delete(o):J.add(o),K=o;let s=f.scrollTop,u=T.isFollowing();Z=!0,T.pause(),G(),f.scrollTop=s,u&&T.resume(),Z=!1}function Le(){return We(f,50)}function G(){re=Date.now(),X=!1,Xe(),Ze();let o=e.getEvictedCount();o>0?(se.textContent=`${o.toLocaleString()} older events truncated`,se.style.display=""):se.style.display="none",S=et();let s=S.length,u=e.getSize()>0;s===0&&u&&be()?(ie.textContent=R?`No events matching '${R}'`:"No events matching filter",ie.style.display="",f.style.display="none"):(ie.style.display="none",f.style.display=""),m&&(m.title=be()?`Copy Filtered (${s})`:"Copy All"),x&&!T.isFollowing()&&s>W&&(C+=s-W,ae.textContent=V?`${V}${C>0?` (${C})`:""}`:"",w.style.display=""),W=s;let E=e.getAll(),z=E.length>0?E[0].timestamp:0,U=new Set(S.map(d=>d.id));for(let d of J)U.has(d)||J.delete(d);let j=A!==Ce||R!==we,c=O.size===0&&S.length>0;if(j||c||S.length===0){f.innerHTML="",O.clear();let d=document.createDocumentFragment();for(let h=0;h<S.length;h++){let k=Se(S[h],h,z,L,J,de,a,i);O.set(S[h].id,k),d.appendChild(k)}f.appendChild(d),Ce=A,we=R,K=null}else{if(K!==null){let h=O.get(K);if(h&&h.parentNode===f){let k=S.findIndex(q=>q.id===K);if(k>=0){let q=Se(S[k],k,z,L,J,de,a,i);f.insertBefore(q,h),h.remove(),O.set(K,q)}}K=null}let d=new Set(S.map(h=>h.id));for(let[h,k]of O)d.has(h)||(k.remove(),O.delete(h));for(let h=0;h<S.length;h++){let k=S[h];if(!O.has(k.id)){let q=Se(k,h,z,L,J,de,a,i);O.set(k.id,q),f.appendChild(q)}}}T.isFollowing()&&(f.scrollTop=f.scrollHeight)}function tt(){if(Date.now()-re>=ct){H!==null&&(cancelAnimationFrame(H),H=null),G();return}X||(X=!0,H=requestAnimationFrame(()=>{H=null,G()}))}let Me=(o,s)=>{if(!m)return;m.innerHTML="";let u=F(o,"12px","currentColor",1.5);u&&m.appendChild(u);let E=l("span","persona-text-xs");E.textContent="Copy All",m.appendChild(E),setTimeout(()=>{m.innerHTML="";let z=F(je,"12px","currentColor",1.5);z&&m.appendChild(z);let U=l("span","persona-text-xs");U.textContent="Copy All",m.appendChild(U),m.disabled=!1},s)},Ae=async()=>{if(m){m.disabled=!0;try{let o;be()?o=S:n?(o=await n(),o.length===0&&(o=e.getAll())):o=e.getAll();let s=o.map(u=>{try{return JSON.parse(u.payload)}catch{return u.payload}});await navigator.clipboard.writeText(JSON.stringify(s,null,2)),Me(Je,1500)}catch{Me(qe,1500)}}},Ne=()=>{v&&(A=v.value,le(),G())},_e=()=>{!y||!_||(_.style.display=y.value?"":"none",N&&clearTimeout(N),N=setTimeout(()=>{R=y.value,le(),G()},150))},xe=()=>{!y||!_||(y.value="",R="",_.style.display="none",N&&clearTimeout(N),le(),G())},Pe=()=>{if(Z)return;let o=f.scrollTop,{action:s,nextLastScrollTop:u}=$e({following:T.isFollowing(),currentScrollTop:o,lastScrollTop:Te,nearBottom:Le(),userScrollThreshold:1,resumeRequiresDownwardScroll:!0});Te=u,s==="resume"?(T.resume(),C=0,w.style.display="none"):s==="pause"&&(T.pause(),x&&(ae.textContent=V,w.style.display=""))},De=o=>{let s=ze({following:T.isFollowing(),deltaY:o.deltaY,nearBottom:Le(),resumeWhenNearBottom:!0});s==="pause"?(T.pause(),x&&(ae.textContent=V,w.style.display="")):s==="resume"&&(T.resume(),C=0,w.style.display="none")},Ie=()=>{x&&(f.scrollTop=f.scrollHeight,T.resume(),C=0,w.style.display="none")},He=o=>{let s=o.target;if(!s||s.closest("button"))return;let u=s.closest("[data-event-id]");if(!u)return;let E=u.getAttribute("data-event-id");E&&de(E)},Oe=o=>{if((o.metaKey||o.ctrlKey)&&o.key==="f"){o.preventDefault(),y?.focus(),y?.select();return}o.key==="Escape"&&(y&&document.activeElement===y?(xe(),y.blur(),I.focus()):r&&r())};m&&m.addEventListener("click",Ae),v&&v.addEventListener("change",Ne),y&&y.addEventListener("input",_e),_&&_.addEventListener("click",xe),f.addEventListener("scroll",Pe),f.addEventListener("wheel",De,{passive:!0}),f.addEventListener("click",He),w.addEventListener("click",Ie),I.addEventListener("keydown",Oe);function nt(){N&&clearTimeout(N),H!==null&&(cancelAnimationFrame(H),H=null),X=!1,O.clear(),m&&m.removeEventListener("click",Ae),v&&v.removeEventListener("change",Ne),y&&y.removeEventListener("input",_e),_&&_.removeEventListener("click",xe),f.removeEventListener("scroll",Pe),f.removeEventListener("wheel",De),f.removeEventListener("click",He),w.removeEventListener("click",Ie),I.removeEventListener("keydown",Oe)}return{element:I,update:tt,destroy:nt}}}var fe=class{constructor(e=2e3,n=null){this.head=0;this.count=0;this.totalCaptured=0;this.eventTypesSet=new Set;this.maxSize=e,this.buffer=new Array(e),this.store=n}push(e){this.buffer[this.head]=e,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.totalCaptured++,this.eventTypesSet.add(e.type),this.store?.put(e)}getAll(){return this.count===0?[]:this.count<this.maxSize?this.buffer.slice(0,this.count):[...this.buffer.slice(this.head,this.maxSize),...this.buffer.slice(0,this.head)]}async restore(){if(!this.store)return 0;let e=await this.store.getAll();if(e.length===0)return 0;let n=e.length>this.maxSize?e.slice(e.length-this.maxSize):e;for(let r of n)this.buffer[this.head]=r,this.head=(this.head+1)%this.maxSize,this.count<this.maxSize&&this.count++,this.eventTypesSet.add(r.type);return this.totalCaptured=e.length,n.length}getAllFromStore(){return this.store?this.store.getAll():Promise.resolve(this.getAll())}getRecent(e){let n=this.getAll();return e>=n.length?n:n.slice(n.length-e)}getSize(){return this.count}getTotalCaptured(){return this.totalCaptured}getEvictedCount(){return this.totalCaptured-this.count}clear(){this.buffer=new Array(this.maxSize),this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),this.store?.clear()}destroy(){this.buffer=[],this.head=0,this.count=0,this.totalCaptured=0,this.eventTypesSet.clear(),this.store?.destroy()}getEventTypes(){return Array.from(this.eventTypesSet)}};var he=class{constructor(e="persona-event-stream",n="events"){this.db=null;this.pendingWrites=[];this.flushScheduled=!1;this.isDestroyed=!1;this.dbName=e,this.storeName=n}open(){return new Promise((e,n)=>{try{let r=indexedDB.open(this.dbName,1);r.onupgradeneeded=()=>{let i=r.result;i.objectStoreNames.contains(this.storeName)||i.createObjectStore(this.storeName,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})},r.onsuccess=()=>{this.db=r.result,e()},r.onerror=()=>{n(r.error)}}catch(r){n(r)}})}put(e){!this.db||this.isDestroyed||(this.pendingWrites.push(e),this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushWrites())))}putBatch(e){if(!(!this.db||this.isDestroyed||e.length===0))try{let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let i of e)r.put(i)}catch{}}getAll(){return new Promise((e,n)=>{if(!this.db){e([]);return}try{let p=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).index("timestamp").getAll();p.onsuccess=()=>{e(p.result)},p.onerror=()=>{n(p.error)}}catch(r){n(r)}})}getCount(){return new Promise((e,n)=>{if(!this.db){e(0);return}try{let a=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName).count();a.onsuccess=()=>{e(a.result)},a.onerror=()=>{n(a.error)}}catch(r){n(r)}})}clear(){return new Promise((e,n)=>{if(!this.db){e();return}this.pendingWrites=[];try{let a=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();a.onsuccess=()=>{e()},a.onerror=()=>{n(a.error)}}catch(r){n(r)}})}close(){this.db&&(this.db.close(),this.db=null)}destroy(){return this.isDestroyed=!0,this.pendingWrites=[],this.close(),new Promise((e,n)=>{try{let r=indexedDB.deleteDatabase(this.dbName);r.onsuccess=()=>{e()},r.onerror=()=>{n(r.error)}}catch(r){n(r)}})}flushWrites(){if(this.flushScheduled=!1,!this.db||this.isDestroyed||this.pendingWrites.length===0)return;let e=this.pendingWrites;this.pendingWrites=[];try{let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName);for(let i of e)r.put(i)}catch{}}};var St=new Set(["flow_start","flow_run_start","agent_start","dispatch_start","run_start"]),Et=new Set(["step_start","execution_start"]),Tt=new Set(["step_delta","step_chunk","chunk","agent_turn_delta"]),Ct=new Set(["step_complete","agent_turn_complete"]),wt=new Set(["flow_complete","agent_complete"]),Ke=new Set(["step_error","flow_error","agent_error","dispatch_error","error"]),Qe=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),P=t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,Y=(t,e)=>{let n=t[e];return Qe(n)?n:void 0};function Ee(t){return t>0?Math.max(1,Math.ceil(t/4)):0}function me(t,e){if(!(t<=0||e===void 0||e<250))return t/(e/1e3)}function kt(t,e){return typeof e.type=="string"?e.type:t}function Rt(t){return typeof t.text=="string"?t.text:typeof t.delta=="string"?t.delta:typeof t.content=="string"?t.content:typeof t.chunk=="string"?t.chunk:""}function Lt(t,e){return t==="step_delta"||t==="step_chunk"?e.stepType!=="tool"&&e.executionType!=="context":t!=="agent_turn_delta"?!0:(typeof e.contentType=="string"?e.contentType:typeof e.content_type=="string"?e.content_type:void 0)==="text"}function Ye(t){let e=Y(t,"result"),n=[Y(t,"tokens"),Y(t,"totalTokens"),e?Y(e,"tokens"):void 0,Y(t,"usage"),e?Y(e,"usage"):void 0];for(let r of n){if(!r)continue;let i=P(r.output)??P(r.outputTokens)??P(r.completionTokens);if(i!==void 0)return i}return P(t.outputTokens)??P(t.completionTokens)??(e?P(e.outputTokens)??P(e.completionTokens):void 0)}function Mt(t){let e=Y(t,"result");return P(t.executionTime)??P(t.executionTimeMs)??P(t.execution_time)??P(t.duration)??(e?P(e.executionTime)??P(e.executionTimeMs):void 0)}function At(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var ge=class{constructor(e=At){this.metric={status:"idle"};this.run=null;this.now=e}getMetric(){let e=this.run;if(e&&this.metric.status==="running"&&e.firstDeltaAt!==void 0&&this.metric.outputTokens!==void 0){let n=this.now()-e.firstDeltaAt;return{...this.metric,durationMs:n,tokensPerSecond:me(this.metric.outputTokens,n)}}return this.metric}reset(){this.run=null,this.metric={status:"idle"}}startRun(e){this.run={startedAt:e,visibleCharCount:0,exactOutputTokens:0},this.metric={status:"running"}}processEvent(e,n){if(!Qe(n)){Ke.has(e)&&this.run&&(this.run=null,this.metric={status:"error"});return}let r=kt(e,n),i=this.now();if(St.has(r)){this.startRun(i);return}if(Et.has(r)){this.run||this.startRun(i);return}if(Tt.has(r)){if(!Lt(r,n))return;let a=Rt(n);if(!a)return;this.run||this.startRun(i);let p=this.run;p.firstDeltaAt??(p.firstDeltaAt=i),p.visibleCharCount+=a.length;let g=p.exactOutputTokens+Ee(p.visibleCharCount),b=i-p.firstDeltaAt;this.metric={status:"running",tokensPerSecond:me(g,b),outputTokens:g,durationMs:b,source:p.exactOutputTokens>0?"usage":"estimate"};return}if(Ct.has(r)){if(!this.run)return;let a=this.run,p=Ye(n);p!==void 0&&(a.exactOutputTokens+=p,a.visibleCharCount=0);let g=a.exactOutputTokens>0,b=a.exactOutputTokens+Ee(a.visibleCharCount),x=this.resolveDuration(a,n,i);this.metric={status:"running",tokensPerSecond:me(b,x),outputTokens:b,durationMs:x,source:g?"usage":"estimate"};return}if(wt.has(r)){if(!this.run)return;let a=this.run,p=Ye(n),g=p??a.exactOutputTokens+Ee(a.visibleCharCount),b=p!==void 0||a.exactOutputTokens>0?"usage":"estimate",x=this.resolveDuration(a,n,i);this.metric={status:"complete",tokensPerSecond:me(g,x),outputTokens:g,durationMs:x,source:b},this.run=null;return}if(Ke.has(r)){if(!this.run)return;this.run=null,this.metric={status:"error"}}}resolveDuration(e,n,r){let i=e.firstDeltaAt!==void 0?r-e.firstDeltaAt:void 0;return i!==void 0&&i>=250?i:Mt(n)??r-e.startedAt}};export{fe as EventStreamBuffer,he as EventStreamStore,ge as ThroughputTracker,Ge as createEventStreamView};
@@ -1,6 +0,0 @@
1
- var g="webmcp:",M=t=>t.startsWith(g)?t.slice(g.length):t,d={warn(t,...e){typeof console<"u"&&typeof console.warn=="function"&&console.warn(`[Persona/WebMCP] ${t}`,...e)}},p=class{constructor(e,n){this.config=e;this.deps=n;this.installed=!1;this.readyPromise=null;this.incompatibleContextWarned=!1;this.confirmHandler=e.onConfirm??null,this.timeoutMs=3e4}setConfirmHandler(e){this.confirmHandler=e}isOperational(){return this.config.enabled!==!0||!this.installed?!1:this.getModelContext()!==null}async snapshotForDispatch(){if(await this.ensureReady(),this.config.enabled!==!0)return[];let e=this.getModelContext();if(!e)return[];let n;try{n=await e.getTools()}catch(i){return d.warn("getTools() threw: shipping an empty WebMCP snapshot.",i),[]}this.deps.recordToolDisplayTitles(n);let o=typeof location<"u"?location.origin:"";return n.filter(i=>this.passesClientAllowlist(i.name)).map(i=>{let s={name:i.name,description:i.description,origin:"webmcp",...o?{pageOrigin:o}:{}},a=w(i.inputSchema);return a&&(s.parametersSchema=a),s})}async executeToolCall(e,n,o){if(await this.ensureReady(),this.config.enabled!==!0)return l("WebMCP is not enabled on this widget.");let i=this.getModelContext();if(!i){let r=typeof document<"u"&&!!document.modelContext;return l(r?"WebMCP is not operational: document.modelContext is present but does not expose the strict getTools()/executeTool() surface (likely a different or older WebMCP polyfill).":"WebMCP bridge is not operational on this page (document.modelContext not available).")}let s=M(e),a;try{a=await i.getTools()}catch(r){let f=r instanceof Error?r.message:String(r);return l(`Failed to read WebMCP registry: ${f}`)}this.deps.recordToolDisplayTitles(a);let u=a.find(r=>r.name===s);if(!u)return l(`WebMCP tool not registered on this page: ${s}`);if(!this.passesClientAllowlist(s))return l(`WebMCP tool not allowed by client allowlist: ${s}`);if(o?.aborted)return l("Aborted by cancel()");let m=this.deps.getToolDisplayTitle(s),h={toolName:s,args:n,description:u.description,...m?{title:m}:{},reason:"gate"};if(!await this.requestConfirm(h))return l("User declined the tool call.");if(o?.aborted)return l("Aborted by cancel()");let c=new AbortController,b=!1,C=setTimeout(()=>{b=!0,c.abort()},this.timeoutMs),y=()=>c.abort();o&&(o.aborted?c.abort():o.addEventListener("abort",y,{once:!0}));try{let r=await i.executeTool(u,v(n),{signal:c.signal});return T(r)}catch(r){if(b)return l(`WebMCP tool '${s}' timed out after ${this.timeoutMs}ms`);if(o?.aborted)return l("Aborted by cancel()");let f=r instanceof Error?r.message:String(r);return l(f)}finally{clearTimeout(C),o&&o.removeEventListener("abort",y)}}ensureReady(){return this.config.enabled!==!0?Promise.resolve():(this.readyPromise||(this.readyPromise=this.install()),this.readyPromise)}async install(){try{if(this.getModelContext()){this.installed=!0;return}(await this.deps.loadPolyfill()).initializeWebMCPPolyfill(),this.installed=!0}catch(e){d.warn("Failed to load @mcp-b/webmcp-polyfill: WebMCP consumption disabled.",e),this.installed=!1}}getModelContext(){if(typeof document>"u")return null;let e=document.modelContext;if(!e||typeof e!="object")return null;let n=e;return typeof n.getTools!="function"||typeof n.executeTool!="function"?(this.incompatibleContextWarned||(this.incompatibleContextWarned=!0,d.warn("document.modelContext is present but does not expose getTools()/executeTool(): WebMCP consumption is disabled. Another (incompatible or older) WebMCP polyfill likely installed document.modelContext before Persona. Remove it, or use a polyfill implementing the strict standard surface (e.g. @mcp-b/webmcp-polyfill).")),null):e}async requestConfirm(e){let n=this.confirmHandler??W;try{return await n(e)}catch(o){return d.warn(`Confirm handler threw for WebMCP tool '${e.toolName}'; declining.`,o),!1}}passesClientAllowlist(e){let n=this.config.allowlist;return!n||n.length===0?!0:n.some(o=>x(e,o))}},x=(t,e)=>{if(e==="*")return!0;let n=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&");return new RegExp("^"+n.replace(/\*/g,".*")+"$").test(t)},w=t=>{if(!(t===void 0||t===""))try{let e=JSON.parse(t);return e!==null&&typeof e=="object"?e:void 0}catch{return}},T=t=>{if(t==null)return{content:[{type:"text",text:""}]};let e;try{e=JSON.parse(t)}catch{return{content:[{type:"text",text:t}]}}return e!==null&&typeof e=="object"&&Array.isArray(e.content)?e:{content:[{type:"text",text:typeof e=="string"?e:A(e)}]}},l=t=>({isError:!0,content:[{type:"text",text:t}]}),W=async t=>{if(typeof window>"u"||typeof window.confirm!="function")return!1;let e=P(t.args),n=`Allow the AI to call ${t.toolName}`+(e?`
2
-
3
- Arguments:
4
- ${e}`:"")+(t.description?`
5
-
6
- ${t.description}`:"");return window.confirm(n)},P=t=>{if(t==null)return"";try{let e=JSON.stringify(t,null,2);return e.length>500?e.slice(0,500)+"\u2026":e}catch{return String(t)}},v=t=>{if(t===void 0)return"{}";try{let e=JSON.stringify(t);return e===void 0?"{}":e}catch{return"{}"}},A=t=>{if(t===void 0)return"";try{return JSON.stringify(t)}catch{return String(t)}};export{p as WebMcpBridge};