dsh-open-artifact 0.16.2 → 0.16.3

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 (109) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/icon.svg +1 -1
  3. package/lib/client.js +2504 -2430
  4. package/lib/index.js +26 -8
  5. package/package.json +1 -1
  6. package/skills/open-artifact/SKILL.md +8 -5
  7. package/vendor/frame-host/client/comments.js +1 -1
  8. package/vendor/frame-host/frame-host.mjs +15 -2
  9. package/vendor/harnesses/antigravity.json +3 -0
  10. package/vendor/harnesses/chatgpt.json +3 -0
  11. package/vendor/harnesses/claude-code.json +3 -0
  12. package/vendor/harnesses/codex.json +3 -0
  13. package/vendor/harnesses/copilot.json +3 -0
  14. package/vendor/harnesses/cursor.json +3 -0
  15. package/vendor/harnesses/dsh.json +3 -0
  16. package/vendor/harnesses/zcode.json +3 -0
  17. package/vendor/home/assets/index-BMcfb5B7.css +1 -0
  18. package/vendor/home/assets/index-CxVzqoE0.js +43 -0
  19. package/vendor/home/index.html +2 -2
  20. package/vendor/open-artifact.mjs +1278 -456
  21. package/vendor/runtime.json +1 -1
  22. package/vendor/shell/assets/index-BMcfb5B7.css +1 -0
  23. package/vendor/{type-server/shell/assets/index-xloVcJb_.js → shell/assets/index-C_XsG-Qe.js} +1 -1
  24. package/vendor/shell/index.html +2 -2
  25. package/vendor/type-server/cli.mjs +16 -3
  26. package/vendor/type-server/editors/data/assets/{index-DcaVBiGm.js → index-CMhqwoHV.js} +1 -1
  27. package/vendor/type-server/editors/data/index.html +1 -1
  28. package/vendor/type-server/editors/design/assets/{index-B5Wv_tnf.js → index-DUW-k3ks.js} +1 -1
  29. package/vendor/type-server/editors/design/index.html +1 -1
  30. package/vendor/type-server/editors/design-system/assets/{index-BqDGbG4f.js → index-l9dVDF3y.js} +1 -1
  31. package/vendor/type-server/editors/design-system/index.html +1 -1
  32. package/vendor/type-server/editors/docs/assets/{abnfDiagram-WEYOIA3C-CDTl-yCx.js → abnfDiagram-WEYOIA3C-C7HiIlhQ.js} +1 -1
  33. package/vendor/type-server/editors/docs/assets/{architectureDiagram-ZHVYKT53-BOl_bS-V.js → architectureDiagram-ZHVYKT53-BNtmYbnl.js} +1 -1
  34. package/vendor/type-server/editors/docs/assets/{blockDiagram-RJAE7QA3-CkMxyQ6a.js → blockDiagram-RJAE7QA3-CmB3Jqrq.js} +1 -1
  35. package/vendor/type-server/editors/docs/assets/{c4Diagram-XDPPPE54-BLHAzoyQ.js → c4Diagram-XDPPPE54-BInEfPqU.js} +1 -1
  36. package/vendor/type-server/editors/docs/assets/channel-BT2p6jtG.js +1 -0
  37. package/vendor/type-server/editors/docs/assets/{chunk-2E7WHVMD-B2ZKLsyS.js → chunk-2E7WHVMD-DERsVzyR.js} +1 -1
  38. package/vendor/type-server/editors/docs/assets/{chunk-2Q5K7J3B-DkNtD1xL.js → chunk-2Q5K7J3B-C5h24pTP.js} +1 -1
  39. package/vendor/type-server/editors/docs/assets/{chunk-4EMNKR2T-C3xRZwqt.js → chunk-4EMNKR2T-CtlMesOe.js} +1 -1
  40. package/vendor/type-server/editors/docs/assets/{chunk-55XCU76K-DEOjkZqt.js → chunk-55XCU76K-BcHXSlto.js} +1 -1
  41. package/vendor/type-server/editors/docs/assets/{chunk-5VM5RSS4-DCKBSHxZ.js → chunk-5VM5RSS4-DnqXPWSg.js} +1 -1
  42. package/vendor/type-server/editors/docs/assets/{chunk-JWPE2WC7-DrvooUmN.js → chunk-JWPE2WC7-Bls1jQHy.js} +1 -1
  43. package/vendor/type-server/editors/docs/assets/{chunk-VQ5W62QI-DYMeK3pU.js → chunk-VQ5W62QI-B-9NPBBl.js} +1 -1
  44. package/vendor/type-server/editors/docs/assets/{chunk-XXDRQBXY-Cvl-anAV.js → chunk-XXDRQBXY-DqHJwIOI.js} +1 -1
  45. package/vendor/type-server/editors/docs/assets/{chunk-ZCHMQSOR-gWl3U20G.js → chunk-ZCHMQSOR-CO0N7boC.js} +2 -2
  46. package/vendor/type-server/editors/docs/assets/{classDiagram-v2-4MYWR3UA-On9X3_w5.js → classDiagram-v2-4MYWR3UA-Dm4tBHd-.js} +1 -1
  47. package/vendor/type-server/editors/docs/assets/{core-Cw4Llisp.js → core-CMnn1N7u.js} +1 -1
  48. package/vendor/type-server/editors/docs/assets/{cose-bilkent-JH36ORCC-B72D_yQn.js → cose-bilkent-JH36ORCC-DGyUtGAA.js} +1 -1
  49. package/vendor/type-server/editors/docs/assets/{cynefin-EF2NZ3EQ-B_v4ABxk.js → cynefin-EF2NZ3EQ-BdlZazYw.js} +1 -1
  50. package/vendor/type-server/editors/docs/assets/{cynefinDiagram-WF24UDRP-Bu9uLebD.js → cynefinDiagram-WF24UDRP-BjKufr-c.js} +1 -1
  51. package/vendor/type-server/editors/docs/assets/{dagre-NK4GIZVX-DOkgWNtI.js → dagre-NK4GIZVX-BZlO2--v.js} +1 -1
  52. package/vendor/type-server/editors/docs/assets/{diagram-CBK3MWTC-CgIhmBRJ.js → diagram-CBK3MWTC-3STWIa1n.js} +1 -1
  53. package/vendor/type-server/editors/docs/assets/{diagram-I5XIIV2D-HpeiOnYm.js → diagram-I5XIIV2D-BIiZBp1S.js} +1 -1
  54. package/vendor/type-server/editors/docs/assets/{diagram-ODIL2UCW-CWmar6iG.js → diagram-ODIL2UCW-Cxn7JmvU.js} +1 -1
  55. package/vendor/type-server/editors/docs/assets/{diagram-PFBEJUXE-CXcCGIYn.js → diagram-PFBEJUXE-D2k1jJ3f.js} +1 -1
  56. package/vendor/type-server/editors/docs/assets/{diagram-RJA3I4VV-jEFt8GAQ.js → diagram-RJA3I4VV-7ZRL3Uk6.js} +1 -1
  57. package/vendor/type-server/editors/docs/assets/{diagram-TYUNFSNR-Da-kw_Xm.js → diagram-TYUNFSNR-Jyx-ylJA.js} +1 -1
  58. package/vendor/type-server/editors/docs/assets/{ebnfDiagram-V4P3TTPT-BaZ03UMA.js → ebnfDiagram-V4P3TTPT-DGfWrKui.js} +1 -1
  59. package/vendor/type-server/editors/docs/assets/{elk-QONTBCTQ-Bri5BDi4.js → elk-QONTBCTQ-B7tKj3Ar.js} +1 -1
  60. package/vendor/type-server/editors/docs/assets/{erDiagram-KYQIGQAA-aju23vzr.js → erDiagram-KYQIGQAA-D06HHDAP.js} +1 -1
  61. package/vendor/type-server/editors/docs/assets/{flowDiagram-IUGLLWBU-DezRFFND.js → flowDiagram-IUGLLWBU-CZJZKHIM.js} +1 -1
  62. package/vendor/type-server/editors/docs/assets/{ganttDiagram-R7GPNTJY-DDDYA5M0.js → ganttDiagram-R7GPNTJY-BaBRsp-X.js} +1 -1
  63. package/vendor/type-server/editors/docs/assets/{gitGraphDiagram-PDYL7XHY-Brbvftki.js → gitGraphDiagram-PDYL7XHY-B2bt-1sQ.js} +1 -1
  64. package/vendor/type-server/editors/docs/assets/{index-rie6Fmea.js → index-YZPGEMCI.js} +3 -3
  65. package/vendor/type-server/editors/docs/assets/{infoDiagram-MVDRKAX5-Buk7jjzD.js → infoDiagram-MVDRKAX5-C1qijMFd.js} +1 -1
  66. package/vendor/type-server/editors/docs/assets/{ishikawaDiagram-HPEHV2GE-k1-dGoms.js → ishikawaDiagram-HPEHV2GE-C2fcPeVy.js} +1 -1
  67. package/vendor/type-server/editors/docs/assets/{journeyDiagram-BOSHW7O7-fuODgQ0y.js → journeyDiagram-BOSHW7O7-DAdGOjA_.js} +1 -1
  68. package/vendor/type-server/editors/docs/assets/{kanban-definition-FNSA4HC5-0EJOb8QO.js → kanban-definition-FNSA4HC5-Cjm2BYYa.js} +1 -1
  69. package/vendor/type-server/editors/docs/assets/{mermaid.core-rflC9T3b.js → mermaid.core-T4owCd57.js} +4 -4
  70. package/vendor/type-server/editors/docs/assets/{mindmap-definition-6OY57UG3-BA4jPnUz.js → mindmap-definition-6OY57UG3-DqNbrCsa.js} +1 -1
  71. package/vendor/type-server/editors/docs/assets/{pegDiagram-ECIUJNBX-D1mSs1Df.js → pegDiagram-ECIUJNBX-B8pnl9eq.js} +1 -1
  72. package/vendor/type-server/editors/docs/assets/{pieDiagram-GNMPY74T-DISpmq94.js → pieDiagram-GNMPY74T-CqN2ryDn.js} +1 -1
  73. package/vendor/type-server/editors/docs/assets/{quadrantDiagram-D57K4MC3-C_DveStJ.js → quadrantDiagram-D57K4MC3-D6ZHYaMj.js} +1 -1
  74. package/vendor/type-server/editors/docs/assets/{railroadDiagram-Y72NRBL7-XkLhMgFv.js → railroadDiagram-Y72NRBL7-DbFNy0DV.js} +1 -1
  75. package/vendor/type-server/editors/docs/assets/{requirementDiagram-EQYSW5RA-DKtU2dUB.js → requirementDiagram-EQYSW5RA-CBjn24a2.js} +1 -1
  76. package/vendor/type-server/editors/docs/assets/{sankeyDiagram-SY24JHO5-DXnpKoyA.js → sankeyDiagram-SY24JHO5-Be5yf8X0.js} +1 -1
  77. package/vendor/type-server/editors/docs/assets/{sequenceDiagram-BLEHNHQU-D3XryRDT.js → sequenceDiagram-BLEHNHQU-CM75oaFL.js} +1 -1
  78. package/vendor/type-server/editors/docs/assets/{sizeCapture-INFHLROL-Ce0anhUv.js → sizeCapture-INFHLROL-BS3ZKpfq.js} +1 -1
  79. package/vendor/type-server/editors/docs/assets/{stateDiagram-v2-A6IESKWZ-C_-4V6la.js → stateDiagram-v2-A6IESKWZ-DBao6lhy.js} +1 -1
  80. package/vendor/type-server/editors/docs/assets/{swimlanes-B3ENRKFQ-DsaAidHj.js → swimlanes-B3ENRKFQ-OBdPnY1S.js} +1 -1
  81. package/vendor/type-server/editors/docs/assets/swimlanesDiagram-AYQRV4AK-D73Zrbfj.js +8 -0
  82. package/vendor/type-server/editors/docs/assets/{timeline-definition-JXYKGLGB-DfKECQ2o.js → timeline-definition-JXYKGLGB-BqkDYP31.js} +1 -1
  83. package/vendor/type-server/editors/docs/assets/{usecaseDiagram-WPOLBNNX-Dc8tWzRe.js → usecaseDiagram-WPOLBNNX-0IvdCTW3.js} +1 -1
  84. package/vendor/type-server/editors/docs/assets/{vennDiagram-Q3Y3IDCW-tc61BjSp.js → vennDiagram-Q3Y3IDCW-Dt2rtwRE.js} +1 -1
  85. package/vendor/type-server/editors/docs/assets/{wardleyDiagram-IVAIDKWA-DyVqcsy4.js → wardleyDiagram-IVAIDKWA-G9f9s0F7.js} +1 -1
  86. package/vendor/type-server/editors/docs/assets/{xychartDiagram-4URNHDU4-B8VxiLaY.js → xychartDiagram-4URNHDU4-CaUTu_0n.js} +1 -1
  87. package/vendor/type-server/editors/docs/index.html +1 -1
  88. package/vendor/type-server/editors/motion/assets/{gif-jobs-DY7KR2r5.js → gif-jobs-C1zQj3s9.js} +1 -1
  89. package/vendor/type-server/editors/motion/assets/{index-DBRxctvJ.js → index-Cw_UcKR5.js} +3 -3
  90. package/vendor/type-server/editors/motion/assets/{src-CP9lpzx7.js → src-wn9P_DUt.js} +1 -1
  91. package/vendor/type-server/editors/motion/index.html +1 -1
  92. package/vendor/type-server/editors/sheets/assets/{index-B6FKM2kq.js → index-C3CIL5GM.js} +2 -2
  93. package/vendor/type-server/editors/sheets/assets/{workbook-worker-D4VqJhLz.js → workbook-worker-CbhVg0YQ.js} +1 -1
  94. package/vendor/type-server/editors/sheets/index.html +1 -1
  95. package/vendor/type-server/editors/slides/assets/{index-DI_AWWuc.js → index-fJEPQZQY.js} +2 -2
  96. package/vendor/type-server/editors/slides/assets/{src-CWCcr2Hw.js → src-mZdWgqty.js} +1 -1
  97. package/vendor/type-server/editors/slides/index.html +1 -1
  98. package/vendor/type-server/editors/whiteboard/assets/{drawing-look-worker-CS2Hv0Nf.js → drawing-look-worker-gMYrygDq.js} +2 -2
  99. package/vendor/type-server/editors/whiteboard/assets/{index-BkWtA61j.js → index-BtZ30wGI.js} +2 -2
  100. package/vendor/type-server/editors/whiteboard/index.html +1 -1
  101. package/vendor/type-server/shell/assets/index-BMcfb5B7.css +1 -0
  102. package/vendor/{shell/assets/index-xloVcJb_.js → type-server/shell/assets/index-C_XsG-Qe.js} +1 -1
  103. package/vendor/type-server/shell/index.html +2 -2
  104. package/vendor/home/assets/index-CQTGVxZi.js +0 -43
  105. package/vendor/home/assets/index-CkjifzaW.css +0 -1
  106. package/vendor/shell/assets/index-CkjifzaW.css +0 -1
  107. package/vendor/type-server/editors/docs/assets/channel-CR_04g-H.js +0 -1
  108. package/vendor/type-server/editors/docs/assets/swimlanesDiagram-AYQRV4AK-iNMg14LW.js +0 -8
  109. package/vendor/type-server/shell/assets/index-CkjifzaW.css +0 -1
@@ -114,8 +114,8 @@
114
114
  color: var(--oa-preboot-fg);
115
115
  }
116
116
  </style>
117
- <script type="module" crossorigin src="/_open-artifact/shell/assets/index-xloVcJb_.js"></script>
118
- <link rel="stylesheet" crossorigin href="/_open-artifact/shell/assets/index-CkjifzaW.css">
117
+ <script type="module" crossorigin src="/_open-artifact/shell/assets/index-C_XsG-Qe.js"></script>
118
+ <link rel="stylesheet" crossorigin href="/_open-artifact/shell/assets/index-BMcfb5B7.css">
119
119
  </head>
120
120
  <body>
121
121
  <div id="root"></div>
@@ -317,7 +317,7 @@ var init_tools = __esm({
317
317
  scope: {
318
318
  type: "string",
319
319
  enum: ["types", "mine", "all"],
320
- description: "list: types (the installed types), mine (this session's and this workspace's artifacts; the default) or all (every artifact)."
320
+ description: "list: types (the installed types), mine (this session's and this project's artifacts; the default) or all (every artifact)."
321
321
  },
322
322
  type: {
323
323
  type: "string",
@@ -333,7 +333,12 @@ var init_tools = __esm({
333
333
  title: { type: "string", description: "publish without url: the new artifact's name. quickstart: the name it will have, to find similar ones." },
334
334
  folder: {
335
335
  type: "string",
336
- description: "publish without url, or adopt: where the artifact's folder goes (absolute, or relative to the workspace). Default <workspace>/artifacts/<slug>."
336
+ description: "publish without url: the exact folder for the new artifact (absolute, or relative to the workspace), only when the person named one. Omitted: Open Artifact chooses the folder and its name. adopt: the folder to add."
337
+ },
338
+ location: {
339
+ type: "string",
340
+ enum: ["home", "workspace"],
341
+ description: "publish without url: where the new artifact's folder goes when the person asked: workspace (in the project, under the working folder) or home (the person's Open Artifact folder). Omitted: what the person's settings say. The folder is named from the title either way."
337
342
  },
338
343
  url: { type: "string", description: "An artifact: open-artifact://artifact/<id>, as publish returned it." },
339
344
  files: {
@@ -581,7 +586,7 @@ Messages that start with "${COMMENT_HEADER}" or "${REQUEST_HEADER}" carry what a
581
586
  });
582
587
 
583
588
  // packages/protocol/src/skill.ts
584
- var HEADING, INTRO2, WHEN_WRITTEN, STEP_SHOW_HOST, STEP_SHOW_AGENT_BROWSER, STEP_SHOW_SYSTEM, STEP_SHOW_LINK;
589
+ var HEADING, INTRO2, FOLDER_RULE, STEP_CREATE, STEP_CREATE_QUICKSTART, WHEN_WRITTEN, STEP_SHOW_HOST, STEP_SHOW_AGENT_BROWSER, STEP_SHOW_SYSTEM, STEP_SHOW_LINK;
585
590
  var init_skill = __esm({
586
591
  "packages/protocol/src/skill.ts"() {
587
592
  "use strict";
@@ -596,6 +601,14 @@ Every artifact, whatever its type, is served by the one local Open Artifact daem
596
601
  frame (the Shell): the type's own editor inside, with its own comments, plus the Shell's title bar, Share and
597
602
  Export panels and "Send to {{agent}}". The person can fix a slide title or move a sticky themselves instead of asking
598
603
  you for every tweak, and export the result; a plain file gives them none of that.`;
604
+ FOLDER_RULE = `Open Artifact chooses the folder and names it from the title: do not make up a path. When the person asks
605
+ for it in the project, add \`location: "workspace"\`; in their Open Artifact folder, \`location: "home"\`; and
606
+ \`folder\` only when they name an exact path.`;
607
+ STEP_CREATE = `**Create it:** \`Artifact {action: "publish", type_url: "open-artifact://type/<type id>", title: "<a short title>", open: "after_first_write"}\`.
608
+ Do not call \`quickstart\` first when the type is chosen.
609
+ ${FOLDER_RULE}`;
610
+ STEP_CREATE_QUICKSTART = `**Create it** with the \`create\` call of this answer, with a short title in place of \`<name>\`.
611
+ ${FOLDER_RULE}`;
599
612
  WHEN_WRITTEN = `once the content is written \u2014 or right after the first playable batch when the type's
600
613
  instructions ask to show progress live (never while it is empty) \u2014`;
601
614
  STEP_SHOW_HOST = `**Show it.** Your app shows the page by itself: with \`open: "after_first_write"\` (the default) it opens once you
@@ -32,7 +32,7 @@ Error generating stack: `+h.message+`
32
32
  `:"";switch(i(c)?!e&&g>0&&!i(A.at(g-1))&&(r=[]):a(u+"r"),c.t){case"blank":r.push(`
33
33
  `);break;case"p":r.push(...ZC(c.c,u),I);break;case"h":r.push(D.jsx("strong",{className:"font-semibold",children:ZC(c.c,u)},u),I);break;case"code":{const C=c.info===""?null:D.jsxs("span",{className:"block text-caption text-muted",children:[c.info,`
34
34
  `]});r.push(e?D.jsxs(R.Fragment,{children:[C&&D.jsxs("span",{className:"text-muted",children:[c.info," "]}),D.jsx("code",{dir:"ltr",className:w9,children:c.text})]},u):D.jsxs("pre",{dir:"ltr",className:ZBA,children:[C,D.jsx("code",{className:"[&&]:[word-break:normal]",children:c.text})]},u),e?I:"");break}case"quote":r.push(e?D.jsx("span",{className:"italic",children:bC(c.c,e,u,n)},u):D.jsx("blockquote",{className:$BA,children:D.jsx("span",{className:Tb,children:bC(c.c,e,u,n)})},u),e?I:"");break;case"list":{if(e){c.items.forEach((f,B)=>{r.push(" ".repeat(n)+(c.ordered?f.n+". ":"• "),...bC(f.c,e,u+"."+B,n+1)),f.c.at(-1)?.t!=="blank"&&r.push(B<c.items.length-1?`
35
- `:I)});break}const C=c.items.map((f,B)=>D.jsx("li",{value:c.ordered?f.n:void 0,children:D.jsx("span",{className:Tb,children:bC(f.c,e,u+"."+B,n+1)})},B));r.push(c.ordered?D.jsx("ol",{className:eQA,children:C},u):D.jsx("ul",{className:AQA,children:C},u));break}}}),a(t+".end"),o}function ZC(A,e){return A.map((t,n)=>{if(typeof t=="string")return t;const o=e+":"+n;switch(t.t){case"raw":return D.jsx(R.Fragment,{children:t.raw},o);case"code":return D.jsx("code",{dir:"ltr",className:w9,children:t.text},o);case"em":return D.jsx("em",{children:ZC(t.c,o)},o);case"strong":return D.jsx("strong",{className:"font-semibold",children:ZC(t.c,o)},o);case"del":return D.jsx("del",{children:ZC(t.c,o)},o)}})}function UK(A,e=new Date){const t=new Date(A);if(Number.isNaN(t.getTime()))return"";if(e.getTime()-t.getTime()<6e4)return"now";const n=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"}),o=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),i=Math.round((o(e)-o(t))/864e5);return i===0?n:i===1?`Yesterday, ${n}`:`${t.toLocaleDateString("en-US",{month:"short",day:"numeric",...t.getFullYear()!==e.getFullYear()?{year:"numeric"}:{}})}, ${n}`}function hQA(A,e=new Date){const t=new Date(A);if(Number.isNaN(t.getTime()))return"";const n=Math.floor((e.getTime()-t.getTime())/6e4);if(n<1)return"now";if(n<60)return`${n}m`;const o=Math.floor(n/60);if(o<24)return`${o}h`;const i=Math.floor(o/24);return i<7?`${i}d`:t.toLocaleDateString("en-US",{month:"short",day:"numeric",...t.getFullYear()!==e.getFullYear()?{year:"numeric"}:{}})}const YK=A=>{let e;const t=new Set,n=(g,u)=>{const I=typeof g=="function"?g(e):g;if(!Object.is(I,e)){const C=e;e=u??(typeof I!="object"||I===null)?I:Object.assign({},e,I),t.forEach(f=>f(e,C))}},o=()=>e,a={setState:n,getState:o,getInitialState:()=>c,subscribe:g=>(t.add(g),()=>t.delete(g))},c=e=A(n,o,a);return a},pQA=(A=>A?YK(A):YK),wQA=A=>A;function yQA(A,e=wQA){const t=QC.useSyncExternalStore(A.subscribe,QC.useCallback(()=>e(A.getState()),[A,e]),QC.useCallback(()=>e(A.getInitialState()),[A,e]));return QC.useDebugValue(t),t}const TK=A=>{const e=pQA(A),t=n=>yQA(e,n);return Object.assign(t,e),t},nn=(A=>A?TK(A):TK),DQA=4e3,N9="Wait for the current change to finish.";function mQA(A,e){return e?A.map(t=>t.id===e.id?R9(t,e.status):t):A}function R9(A,e,t){if(A.status===e&&A.resolvedBy===t)return A;const{resolvedBy:n,...o}=A;return e==="resolved"&&t?{...o,status:e,resolvedBy:t}:{...o,status:e}}function bQA(A){return A.wakesIdle===!1?`${A.name} gets this on its next turn: send it a message to start one`:"Waiting for the agent"}function KK(A,e){return e===!1?{title:`Sent to ${A}`,description:`${A} gets it on its next turn. If it is idle, send it a message there to start one.`}:{title:`Sent to ${A}`}}function M9(A){return A.reduce((e,t)=>t.status==="open"?e+t.messages.length:e,0)}function SQA(A){return A==="detached"?"What this was on is gone; shown on what held it.":A==="orphaned"?"What this was on has been deleted.":null}function NQA(A){const e=A.maxThreads??500,t=A.noun??"document",n=p=>A.notify?.(p);let o=null,i,r=0;const a=nn()(p=>({available:!1,threads:[],on:!1,listOpen:!1,active:null,draft:null,showResolved:!1,sendNew:!1,draftText:"",replies:{},statusChange:null,setOn(w){p({on:w,draft:null}),A.onModeChange?.(w)},setListOpen(w){p({listOpen:w})},setActive(w){p({active:w,draft:null})},setDraft(w){p(w===null?{draft:w,active:null,draftText:"",sendNew:!1}:{draft:w,active:null})},setShowResolved(w){p({showResolved:w})},setSendNew(w){p({sendNew:w})},setDraftText(w){p({draftText:w})},setReply(w,b){p(N=>({replies:{...N.replies,[w]:b}}))}})),c=new Map,g=p=>{let w=c.get(p.anchor);return w===void 0&&(w=A.parse(p.anchor),c.size>2e3&&c.clear(),c.set(p.anchor,w)),w};let u=[];const I=(p,w)=>{u=p;const b=w&&"statusChange"in w?w.statusChange??null:a.getState().statusChange;a.setState({...w,threads:mQA(p,b)})},C=p=>{n({title:"The comment could not be saved",description:p instanceof Error?p.message:String(p)})},f=p=>{I(u.map(w=>w.id===p.id?p:w)),A.heard?.([p])},B=p=>A.checkText?A.checkText(p):p.trim().slice(0,DQA)||void 0,Q=()=>!!o&&A.canComment(),d=()=>!!o&&A.canSendToAgent(),m={store:a,adapter:A,async start(p,w){if(!p)return;o=p;const b=r;a.setState({available:!0});try{const k=await p.list();if(b!==r)return;I(k),A.heard?.(k)}catch{}if(b!==r)return;i=p.onChange(k=>{const M=a.getState().active;I(k,{active:M&&k.some(x=>x.id===M)?M:null}),A.heard?.(k)});const N=w?a.getState().threads.find(k=>k.id===w):void 0;N&&m.reveal(N)},stop(){r+=1,i?.(),i=void 0},capability:()=>o,canComment:Q,canSendToAgent:d,canRemove:()=>!!o&&(A.canRemove?A.canRemove():A.canComment()),anchorOf:g,labelOf:p=>A.label(p),stateOf:p=>A.state?.(p)??"ok",stateNote:p=>A.stateNote?A.stateNote(p??"ok"):SQA(p),async create(p,w,b){if(!o)return!1;const N=B(w);if(!N)return!1;if(a.getState().threads.length>=e)return n({title:`This ${t} already has ${e} comments`}),!1;try{const k=A.detail?.(p),M=await o.create({anchor:A.serialize(p),label:A.label(p),...k!==void 0?{detail:k}:{},location:A.location?.(p)??{},text:N}),x=!!b?.send&&d();return I(u.some(L=>L.id===M.id)?u:[...u,M],{draft:null,draftText:"",sendNew:!1,active:A.opensCreated?.(x)===!1?null:M.id}),A.heard?.([M]),x&&await m.sendToAgent(M.id),!0}catch(k){return C(k),!1}},async reply(p,w,b){if(!o)return!1;const N=B(w);if(!N)return!1;try{let k=await o.reply(p,N);return k.status==="resolved"&&(k=await o.setResolved(p,!1)),f(k),a.setState(M=>{const{[p]:x,...L}=M.replies;return{replies:L}}),b?.send&&d()&&await m.sendToAgent(p),!0}catch(k){return C(k),!1}},async resolve(p,w){if(!o)return;const b=a.getState(),N=w?"resolved":"open",k=b.threads.find(x=>x.id===p);if(!k||b.statusChange||k.status===N)return;const M=w&&b.active===p&&!b.showResolved;I(u,{statusChange:{id:p,status:N},...M?{active:null}:{}});try{const x=await o.setResolved(p,w);I(u.map(L=>L.id===p?R9(L,x.status,x.resolvedBy):L),{statusChange:null}),A.heard?.([x])}catch(x){I(u,{statusChange:null}),C(x);const L=a.getState();M&&L.active===null&&L.draft===null&&u.some(G=>G.id===p)&&a.setState({active:p})}},async remove(p,w){if(!(!o||A.canRemove&&!A.canRemove()))try{await o.remove(p,w),w||I(u.filter(b=>b.id!==p),{active:a.getState().active===p?null:a.getState().active})}catch(b){C(b)}},async move(p,w){if(o)try{f(await o.move(p,A.serialize(w),A.location?.(w)))}catch(b){C(b)}},async sendToAgent(p){if(!o||!d())return!1;const w=A.sendToAgent?a.getState().threads.find(b=>b.id===p):void 0;if(A.sendToAgent)return w?A.sendToAgent(w,g(w)):!1;try{return f(await o.sendToAgent(p)),n(KK(A.agentName?.()||"the agent",A.agentWakesIdle?.())),!0}catch(b){return C(b),!1}},async sendAllToAgent(){if(!o||!d())return;const p=a.getState().threads.filter(M=>m.canSendThread(M));if(!p.length)return;if(A.sendToAgent){await Promise.all(p.map(M=>A.sendToAgent(M,g(M))));return}const w=o,b=await Promise.allSettled(p.map(M=>w.sendToAgent(M.id)));let N=0;for(const M of b)M.status==="fulfilled"&&(f(M.value),N++);N&&n(KK(A.agentName?.()||"the agent",A.agentWakesIdle?.()));const k=b.find(M=>M.status==="rejected");k&&C(k.reason)},canSendThread(p){if(p.status!=="open")return!1;const w=p.messages.at(-1);return!w||w.author.kind!=="person"?!1:!p.agent||p.agent.status==="replied"},reveal(p){A.reveal?.(g(p)),a.getState().setActive(p.id)},show(p){const w=a.getState();w.on||w.setOn(!0),p.status==="resolved"&&!a.getState().showResolved&&a.getState().setShowResolved(!0),m.reveal(p)},viewerName:()=>A.viewerName?.()||"You"};return m}const k9=300,$C=12,RQA=k9+$C*2;function MQA({comments:A,agent:e,top:t=$C,hint:n}){return A.store(i=>i.listOpen&&i.available)?D.jsx(YE,{mark:"data-comments-panel-layer",children:D.jsx(kQA,{comments:A,agent:e,top:t,hint:n})}):null}const JK=A=>A.messages[0]?.at??"";function kQA({comments:A,agent:e,top:t,hint:n}){const{dark:o}=UE(),i=A.store(f=>f.threads),r=A.store(f=>f.showResolved),a=A.store(f=>f.on),c=A.store(f=>f.active),g=()=>A.store.getState().setListOpen(!1),u=i.filter(f=>f.messages.length>0),I=u.filter(f=>r||f.status==="open").sort((f,B)=>JK(B).localeCompare(JK(f))),C=u.filter(f=>f.status==="resolved").length;return D.jsxs("section",{"aria-label":"All comments","data-comments-panel":"",className:Yt(kx(),"fixed flex flex-col text-body text-primary"),style:{top:t,right:$C,width:k9,maxWidth:`calc(100vw - ${$C*2}px)`,maxHeight:`calc(100dvh - ${t+$C}px)`,zIndex:40,pointerEvents:"auto",...vx(o)},onKeyDown:f=>{const B=f.target instanceof Element&&f.target.closest("[data-cds=Menu]");f.key==="Escape"&&!f.defaultPrevented&&!B&&(f.preventDefault(),g())},children:[D.jsxs("div",{className:"flex shrink-0 items-center gap-xs",style:{padding:"10px 10px 6px 16px"},children:[D.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:"All comments"}),D.jsx(xQA,{showResolved:r,onShowResolved:f=>A.store.getState().setShowResolved(f)}),D.jsx($i,{variant:"ghost",iconOnly:!0,"aria-label":"Close",icon:D.jsx(xi,{name:"X",size:"sm"}),onClick:g})]}),D.jsx(GQA,{comments:A,agent:e,threads:u}),D.jsxs("div",{className:"flex min-h-0 flex-col gap-xs overflow-y-auto [--cds-comment-card-bg:var(--cds-surface-2)]",style:{padding:"0 12px 12px"},children:[u.length===0?D.jsxs("div",{"data-comments-empty":"",className:"flex flex-1 flex-col items-center justify-center gap-xs px-lg text-center",style:{paddingBlock:"var(--cds-pad-xl)"},children:[D.jsx("span",{className:"text-body font-medium text-secondary",children:"No comments yet"}),D.jsx("span",{className:"text-caption text-muted",children:A.canComment()?n??"Press the comment button, then click anywhere on the artifact to add one.":"Only people with comment access can add one."})]}):I.length===0?D.jsxs("span",{"data-comments-filtered-empty":"",className:"px-lg text-center text-caption text-muted",style:{paddingBlock:"var(--cds-pad-xl)"},children:["No open comments.",C>0?D.jsxs(D.Fragment,{children:[" ",D.jsx("button",{type:"button",className:"cds-text-link cds-text-link-underline inline text-inherit",onClick:()=>A.store.getState().setShowResolved(!0),children:`Show ${C} resolved`})]}):null]}):null,I.map(f=>D.jsx(FQA,{comments:A,agent:e,thread:f,current:a&&c===f.id},f.id))]})]})}function vQA(){return D.jsx("svg",{"data-cds":"Icon","aria-hidden":!0,width:"1em",height:"1em",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.2,strokeLinecap:"round",style:{fontSize:"calc(1rem * var(--cds-rem-scale,1))"},children:D.jsx("path",{d:"M2.5 4.5h11M4.5 8h7M6.5 11.5h3"})})}function xQA({showResolved:A,onShowResolved:e}){const[t,n]=Tx();return D.jsxs(yE,{open:t,onOpenChange:n,modal:!1,children:[D.jsx(Cl,{content:"Filter",disabled:t,children:D.jsx(DE,{render:D.jsx($i,{variant:"ghost",iconOnly:!0,tooltip:!1,"aria-label":"Filter",icon:D.jsx(vQA,{})})})}),D.jsx(xx,{align:"end",children:D.jsxs(KP,{checked:A,onCheckedChange:e,closeOnClick:!1,className:Yt(s9,"group/cb text-primary data-[highlighted]:bg-fill-ghost-hover"),children:[D.jsx(l9,{}),D.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Show resolved"})]})})]})}function GQA({comments:A,agent:e,threads:t}){const[n,o]=R.useState(!1),[i,r]=R.useState(!1),a=t.filter(u=>u.status==="open"&&u.messages.some(I=>I.author.kind==="person"));if(!A.canSendToAgent()||!e.available||a.length===0)return null;const g=!a.some(u=>A.canSendThread(u))?i?`These comments were just sent to ${e.name}.`:`${e.name} has every comment.`:void 0;return D.jsx("div",{className:"flex shrink-0 flex-col items-end gap-sm",style:{padding:"0 12px 8px"},children:D.jsx(Cl,{content:g,side:"bottom",children:D.jsx($i,{"data-comments-send-all":"","data-size":"sm",variant:"secondary",busy:n,"aria-disabled":g!==void 0||n||void 0,className:"aria-disabled:opacity-disabled",onClick:()=>{g!==void 0||n||(o(!0),A.sendAllToAgent().then(()=>r(!0)).finally(()=>o(!1)))},children:`Send all to ${e.name}`})})})}function FQA({comments:A,agent:e,thread:t,current:n}){const[o,i]=R.useState(!1),[r,a]=R.useState(!1),c=A.store(d=>d.statusChange),g=R.useId(),u=t.messages[0],I=t.messages.length-1,C=t.status==="resolved",f=A.canComment(),B=u.author.kind==="agent"?u.author.name||e.name:u.author.name||"Someone",Q=[...C&&f?[{label:"Reopen",icon:"Comment",onSelect:()=>{A.resolve(t.id,!1)}}]:[],...A.canRemove()?[{label:"Delete thread",icon:"Trash",variant:"danger",onSelect:()=>i(!0)}]:[]];return D.jsxs(I9,{variant:"flat",expanded:!1,active:n,labelledBy:g,onExpand:()=>A.show(t),className:"rounded",children:[D.jsx(Vd,{nameId:g,authorName:B,agent:u.author.kind==="agent",timestamp:D.jsxs(D.Fragment,{children:[hQA(u.at),C&&" · Resolved",t.agent?D.jsx("span",{role:"img","aria-label":`Sent to ${e.name}`,className:"inline-flex",style:{width:18,height:18,marginInlineStart:4,verticalAlign:"middle",color:"var(--cds-fill-brand)"},children:D.jsx(c9,{})}):null]}),confirm:o?D.jsx(E9,{busy:r,onCancel:()=>i(!1),onDelete:()=>{a(!0),A.remove(t.id).finally(()=>a(!1))}}):void 0,actions:D.jsxs(Yx,{placement:n?"pinned":void 0,children:[f?D.jsx(f9,{resolved:C,disabled:c!==null,onResolve:()=>{A.resolve(t.id,!0)}}):null,D.jsx(C9,{items:Q,disabled:c!==null&&c.id!==t.id,waitReason:c?.id===t.id?N9:void 0})]}),children:D.jsx("span",{className:"line-clamp-3",children:hR(u.text,{flat:!0})})}),I>0&&!o?D.jsx("button",{type:"button","data-cds-part":"replies-toggle",className:"self-start text-body font-normal text-accent hover:underline",children:I===1?"1 reply":`${I} replies`}):null]})}function v9(A,e,t){switch(A.status){case"delivered":return A.drafted?{title:x9(t?.name).sent}:{title:"Sent to the agent"};case"queued":if(t?.wakesIdle===!1){const n=t.name||"The agent";return{title:`Queued for ${n}`,description:`${n} gets it on its next turn. If it is idle, send it a message there to start one.`}}return{title:"Queued for the agent",description:`It will see the request the next time it checks ${e}.`};case"staged":return{title:"Request prepared",description:"Your agent will ask before acting on it."};default:return{title:"Could not reach the agent",description:A.reason??"Try again, or copy your request into the conversation."}}}function LQA(){try{return/^zh\b/i.test(globalThis.navigator?.language??"")}catch{return!1}}function x9(A,e=LQA()){const t=String(A??"").trim();return e?{sent:`已放进 ${t||"智能体"} 的对话:到那里发出去。`,via:"在对话里,等你发出",label:"在对话里,等你发出"}:{sent:`It is in the ${t||"agent"} conversation now: send it there.`,via:"in the conversation, for you to send",label:"In the conversation, for you to send"}}function G9(A){return{status:"failed",reason:A instanceof Error?A.message:String(A)}}function UQA(A,e,t){if(!A)return()=>{};let n=!1,o=!1;A.status().then(r=>{!n&&!o&&e(r)},()=>{});const i=A.onStatus(r=>{n||(o=!0,e(r))});return()=>{n=!0,i()}}function HK(A,e){return{x:e.x*A.zoom+A.x,y:e.y*A.zoom+A.y}}function YQA(A,e){const t=A.zoom||1;return{x:(e.x-A.x)/t,y:(e.y-A.y)/t}}function TQA(A,e){return{left:e.x*A.zoom+A.x,top:e.y*A.zoom+A.y,width:e.w*A.zoom,height:e.h*A.zoom}}const KQA=5,OK="#ae7303",JQA="<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'><path d='M 2 26 L 2 14 A 12 12 0 1 1 14 26 Z' fill='#000' stroke='#fff' stroke-width='2'/></svg>";`${JQA.replace(/[ '<>#]/g,A=>"%"+A.charCodeAt(0).toString(16).toUpperCase())}`;const xs=36,_Q=4,Ln=8,HQA=330,_K=6,mR=48;function PQ(A,e){const t=e.height-(A.y+_Q),n=A.y-_Q,o=t<320&&n>t&&(n>=240||t<240&&n>=48);return{left:Math.min(Math.max(A.x,0),Math.max(0,e.width-(xs+Ln))),top:o?A.y-(xs+_Q):A.y+_Q,flip:o}}const F9=A=>Math.max(320,Math.round(A*.6));function OQA(A,e){const t=Ln,n=e.height-Ln,o=(r,a,c)=>Math.min(Math.max(r,a),c),i=A.flip?o(A.top+xs+2,Math.min(n,t+mR),n)-t:n-o(A.top-2,t,Math.max(t,n-mR));return Math.min(F9(e.height),Math.max(0,i))}function bR({pin:A,corner:e,viewport:t,width:n=HQA,onEscape:o,children:i}){const r=R.useRef(null),[a,c]=R.useState(0);R.useLayoutEffect(()=>{const B=r.current;if(!B)return;c(B.offsetHeight);const Q=new ResizeObserver(()=>c(B.offsetHeight));return Q.observe(B),()=>Q.disconnect()},[]);const g=Math.max(0,Math.min(n,t.width-2*Ln));let u,I,C;if(e||!A){const B=e??{x:Ln,y:Ln};u=Math.max(Ln,Math.min(B.x,t.width-Ln-g)),I=Math.max(Ln,Math.min(B.y,t.height-Ln-a)),typeof i=="function"&&(C=Math.min(F9(t.height),Math.max(mR,t.height-Ln-Math.max(Ln,B.y))))}else{if(u=A.left+xs+_K,u+g>t.width-Ln){const B=A.left-_K-g;u=B>=Ln?B:Math.max(Ln,t.width-Ln-g)}I=A.flip?A.top+xs+2-a:A.top-2,I=Math.max(Ln,Math.min(I,t.height-Ln-a)),typeof i=="function"&&(C=OQA(A,t))}const f={position:"absolute",left:u,top:I,width:g,pointerEvents:"auto",...C===void 0?{}:{maxHeight:C,"--comment-card-room":`${C}px`,display:"flex",flexDirection:"column"},...a?{}:{opacity:0,pointerEvents:"none"}};return D.jsx("div",{ref:r,style:f,"data-comment-card":"",onKeyDown:B=>{B.key!=="Escape"||B.defaultPrevented||(B.preventDefault(),o())},children:typeof i=="function"?i(C):i})}const _QA="cds-reset absolute flex items-center justify-center rounded-full rounded-tl-none border-0 p-0 cursor-[var(--cds-cursor-interactive)] outline-none focus-visible:outline-hidden focus-visible:shadow-focus";function L9({pin:A,avatar:e,draft:t=!1,label:n,title:o,expanded:i,faded:r=!1,...a}){const{pinId:c,...g}=a,u={left:A.left,top:A.top,width:xs,height:xs,pointerEvents:t?"none":"auto",touchAction:"none",...A.flip?{borderRadius:"9999px 9999px 9999px 0"}:{},...r?{opacity:.7}:{}};return D.jsx("button",{type:"button","data-comment-pin":c,"aria-label":n,title:o,"aria-expanded":i,tabIndex:t?-1:void 0,className:Yt(_QA,t?"bg-fill-accent":"bg-surface-2 shadow-panel-sm"),style:u,...g,children:D.jsx("span",{className:"flex rounded-full bg-surface-1",children:e})})}function SR(A,e){return A.author.kind==="agent"?A.author.name||e.name:A.author.name||"Someone"}function PQA(A,e){const t=A.messages[0];return t?D.jsx(Xh,{name:SR(t,e),variant:t.author.kind==="agent"?"agent":"default",size:"sm"}):D.jsx(Xh,{name:"?",size:"sm"})}function jQA({comments:A,camera:e,viewport:t,place:n,highlight:o,anchorAt:i,movable:r,onMove:a,agent:c,revision:g,piles:u=!0,insets:I}){const C=(r??!0)&&!!(i||a),f=A.store(F=>F.available),B=A.store(F=>F.threads),Q=A.store(F=>F.active),d=A.store(F=>F.draft),y=A.store(F=>F.on),m=A.store(F=>F.showResolved),p=A.store(F=>F.listOpen),[w,b]=R.useState(null),N=R.useMemo(()=>{if(!f)return[];const F=[];for(const K of B){if(K.messages.length===0||K.status!=="open"&&!m&&K.id!==Q)continue;const _=A.anchorOf(K),P=n(_);P&&F.push({key:K.id,thread:K,anchor:_,state:P.state,screen:HK(e,P.world)})}if(d!==null){const K=n(d);K&&F.push({key:"draft",thread:null,anchor:d,state:K.state,screen:HK(e,K.world)})}return F},[f,B,Q,d,m,e,n,g,A]);if(!f||!y&&!Q&&d===null&&N.length===0)return null;const k=d!==null?"draft":Q,M=N.find(F=>F.key===k),x=M&&o?o(M.anchor):null,L=N.filter(F=>F.thread),G=u?RBA({points:L.map(F=>({id:F.key,x:F.screen.x,y:F.screen.y})),openId:Q,box:{left:0,top:0,width:t.width,height:t.height},top:0,floor:I?.top??0,foot:I?.bottom?I.bottom+8:0,reserveRight:p?RQA:0}):null,Y=L.filter(F=>!G?.piled.has(F.key)).map(F=>({...F,box:PQ(F.screen,t)})),J=UBA(Y.map(F=>({id:F.key,x:F.box.left,y:F.box.top,w:xs})),t.width,xs),U=F=>A.store.getState().setActive(F),T=M?.thread?M:void 0;return D.jsxs(D.Fragment,{children:[x?D.jsx("div",{"data-comment-target":"",className:Yt("pointer-events-none absolute",!x.area&&"rounded"),style:{...TQA(e,x),border:x.area?`1px dashed ${OK}`:`1.5px solid ${OK}`}}):null,D.jsxs(YE,{className:"pointer-events-none absolute inset-0 z-[3]",mark:"data-comment-layer",onEscape:()=>{const F=A.store.getState();return F.draft!==null||F.active?(F.setDraft(null),F.setActive(null),!0):!1},children:[Y.map(F=>{const K=F.thread,_=w?.id===K.id?w:null,P={...F.box,left:F.box.left+(J.get(F.key)??0)+(_?.x??0),top:F.box.top+(_?.y??0)};return D.jsx(qQA,{comments:A,thread:K,box:P,avatar:PQA(K,c),expanded:Q===K.id,detached:F.state==="detached",onDrag:j=>b(j?{id:K.id,...j}:null),movable:C,onDrop:j=>{const O={x:F.screen.x+j.x,y:F.screen.y+j.y};a?a(K.id,O):i&&A.move(K.id,i(YQA(e,O)))}},F.key)}),G?D.jsx("div",{style:{display:"contents",pointerEvents:"auto"},children:D.jsx(LBA,{piles:G,onOpen:F=>{const K=B.find(_=>_.id===F);K&&A.show(K)}})}):null,T?D.jsx(bR,{pin:PQ(T.screen,t),viewport:t,onEscape:()=>U(null),children:F=>D.jsx(U9,{comments:A,agent:c,thread:T.thread,state:T.state,maxHeight:F})},T.key):null,M&&!M.thread&&d!==null?D.jsxs(D.Fragment,{children:[D.jsx(L9,{pin:PQ(M.screen,t),draft:!0,label:"New comment",avatar:D.jsx(Xh,{name:A.viewerName(),size:"sm"})}),D.jsx(bR,{pin:PQ(M.screen,t),viewport:t,onEscape:()=>A.store.getState().setDraft(null),children:()=>D.jsx(zQA,{comments:A,agent:c,anchor:d})})]}):null]})]})}function qQA({comments:A,thread:e,box:t,avatar:n,expanded:o,detached:i,movable:r,onDrag:a,onDrop:c}){const g=R.useRef(null),u=R.useRef(!1),I=e.status==="resolved";return D.jsx(L9,{pinId:e.id,pin:t,avatar:n,expanded:o,faded:i,label:`Comment: ${e.label}${I?" (resolved)":""}`,title:i?"What this comment was on is gone":e.label,onPointerDown:C=>{if(C.button===0){g.current={x:C.clientX,y:C.clientY,moved:!1},u.current=!1;try{C.currentTarget.setPointerCapture(C.pointerId)}catch{}}},onPointerMove:C=>{const f=g.current;if(!f||!r||!A.canComment())return;const B=C.clientX-f.x,Q=C.clientY-f.y;!f.moved&&Math.hypot(B,Q)<KQA||(f.moved=!0,a({x:B,y:Q}))},onPointerUp:C=>{const f=g.current;g.current=null,f?.moved&&(u.current=!0,a(null),c({x:C.clientX-f.x,y:C.clientY-f.y}))},onClick:()=>{if(u.current){u.current=!1;return}const C=A.store.getState();C.setActive(C.active===e.id?null:e.id)}})}function WQA(A,e){const t=R.useRef(null);R.useLayoutEffect(()=>{const o=t.current,i=A.current;if(!o||!i)return;i.scrollTop=i.scrollHeight;const r=e.messages.at(-1);if(r&&r.id!==o.after&&r.author.kind==="agent"){const a=[...i.querySelectorAll('[data-cds-part="comment"]')].at(-1),c=a?i.getBoundingClientRect().top-a.getBoundingClientRect().top:0;if(c>0){i.scrollTop-=c,t.current=null;return}}o.at=i.scrollTop});const n=()=>{t.current=null};return{start:()=>{t.current={after:e.messages.at(-1)?.id,at:0}},regionProps:{onPointerDownCapture:n,onWheelCapture:o=>{o.deltaY<0&&n()},onScroll:o=>{const i=o.currentTarget,r=t.current;r&&Math.abs(i.scrollTop-r.at)>2&&i.scrollHeight-i.scrollTop-i.clientHeight>2&&n()}}}}function U9(A){return D.jsx(h9,{children:D.jsx(VQA,{...A})})}function VQA({comments:A,agent:e,thread:t,state:n,maxHeight:o,onClose:i}){const[r,a]=R.useState(!1),[c,g]=R.useState(!1),[u,I]=R.useState(!1),C=A.store(Y=>Y.statusChange),f=R.useId(),B=R.useRef(null),Q=WQA(B,t),d=A.store(Y=>Y.replies[t.id])??{text:"",send:!1},y=A.canSendToAgent()&&e.available,m=A.canComment(),[p,...w]=t.messages;if(!p)return null;const b=i??(()=>A.store.getState().setActive(null)),N=A.stateNote(n??A.stateOf(A.anchorOf(t))),k=`Send to ${e.name}`,M=A.canRemove()?[{label:"Delete thread",icon:"Trash",variant:"danger",onSelect:()=>a(!0)}]:[],x=t.status==="open"?t.agent?.status:void 0,L=x==="pending"?"queued":x==="delivered"?"working":void 0,G=Y=>A.store.getState().setReply(t.id,Y);return D.jsxs(I9,{expanded:!0,active:!0,onClose:b,labelledBy:f,maxHeight:o,scrollRef:B,scrollProps:Q.regionProps,className:"min-h-0 flex-1",reply:m&&D.jsx(uBA,{children:D.jsx(B9,{label:"Reply",placeholder:t.status==="resolved"?"Reply to reopen…":y&&d.send?"What do you want to edit?":void 0,value:d.text,onChange:Y=>G({...d,text:Y}),sendBox:y?{label:k,checked:d.send,onCheckedChange:Y=>G({...d,send:Y})}:void 0,busy:u,onSubmit:(Y,{send:J})=>{Q.start(),I(!0),A.reply(t.id,Y,{send:y&&J}).finally(()=>I(!1))},onCancel:b})}),children:[D.jsx(Vd,{nameId:f,authorName:SR(p,e),agent:p.author.kind==="agent",timestamp:UK(p.at),footnote:N??void 0,confirm:r?D.jsx(E9,{busy:c,onCancel:()=>a(!1),onDelete:()=>{g(!0),A.remove(t.id).finally(()=>g(!1))}}):void 0,actions:m||M.length>0?D.jsxs(Yx,{children:[m?D.jsx(f9,{resolved:t.status==="resolved",disabled:C!==null,onResolve:()=>{A.resolve(t.id,!0)}}):null,D.jsx(C9,{items:M,disabled:C!==null&&C.id!==t.id,waitReason:C?.id===t.id?N9:void 0})]}):void 0,children:hR(p.text)}),w.length>0||L?D.jsxs(gBA,{children:[w.map(Y=>D.jsx(Vd,{authorName:SR(Y,e),agent:Y.author.kind==="agent",timestamp:UK(Y.at),children:hR(Y.text)},Y.id)),L?D.jsx(Vd,{authorName:e.name,agent:!0,working:L,footnote:L==="queued"?bQA(e):t.agent?.drafted?x9(e.name).label:"Working…"}):null]}):null]})}function zQA(A){return D.jsx(h9,{children:D.jsx(XQA,{...A})})}function XQA({comments:A,agent:e,anchor:t,onCancel:n}){const o=A.store(I=>I.draftText),i=A.store(I=>I.sendNew),[r,a]=R.useState(!1),c=R.useRef(null),g=A.canSendToAgent()&&e.available;R.useEffect(()=>{c.current?.focus({preventScroll:!0})},[t]);const u=()=>n?n():A.store.getState().setDraft(null);return D.jsx(B9,{textareaRef:c,context:A.labelOf(t),value:o,onChange:I=>A.store.getState().setDraftText(I),sendBox:g?{label:`Send to ${e.name}`,checked:i,onCheckedChange:I=>A.store.getState().setSendNew(I)}:void 0,busy:r,onSubmit:(I,C)=>{r||(a(!0),A.create(t,I,{send:g&&C.send}).finally(()=>a(!1)))},onCancel:u})}function ZQA({comments:A,shortcut:e="C",side:t="bottom"}){return A.store(o=>o.available)?D.jsx(YE,{inline:!0,mark:"data-comments-button",children:D.jsx($QA,{comments:A,shortcut:e,side:t})}):null}function $QA({comments:A,shortcut:e,side:t}){const[n,o]=Tx(),i=A.store(C=>M9(C.threads)),r=A.store(C=>C.on),a=A.store(C=>C.listOpen),c=!r&&i>0,g=r?"Done commenting":i>0?`${i} open ${i===1?"comment":"comments"}`:"Comments",u=C=>{o(!1),A.store.getState().setListOpen(C)},I=a?{label:"Hide comments",onSelect:()=>u(!1)}:{label:"Show all comments",trailing:i,onSelect:()=>u(!0)};return D.jsxs("span",{className:"flex shrink-0 items-center",children:[A.canComment()?D.jsx(Cl,{content:g,shortcut:e,side:t,children:D.jsx($i,{variant:"ghost",iconOnly:!0,tooltip:!1,"aria-label":"Comments","aria-pressed":r,icon:D.jsxs("span",{className:"relative inline-flex",children:[D.jsx(xi,{name:r?"CommentFilled":"Comment",size:"sm"}),c?D.jsx("span",{"aria-hidden":!0,className:"absolute rounded-full bg-fill-accent",style:{top:-1,right:-2,width:6,height:6,boxShadow:"0 0 0 1.5px var(--cds-page-bg)"}}):null]}),onClick:()=>A.store.getState().setOn(!r)})}):null,D.jsxs(yE,{open:n,onOpenChange:o,modal:!1,children:[D.jsx(Cl,{content:"Comment options",disabled:n,side:t,children:D.jsx(DE,{render:D.jsx($i,{variant:"ghost","aria-label":"Comment options",style:{paddingInline:2},children:D.jsx(xi,{name:"CaretDown",size:"xs"})})})}),D.jsx(xx,{align:"end",children:D.jsx(a9,{items:[I]})})]})]})}const Kb=200,AdA=119,Gf=nn()(()=>({message:"",serial:0}));function edA(A){const e=A.replace(/\s+/g," ").trim();if(e.length<=Kb)return e;const t=e.slice(0,Kb).search(/\s+\S*$/);return`${t>=AdA?e.slice(0,t):e.slice(0,Kb-1).replace(/[\uD800-\uDBFF]$/,"")}…`}function pt(A){const e=edA(A);e&&Gf.setState(t=>({message:e,serial:t.serial+1}))}function tdA(){const A=Gf(t=>t.message),e=Gf(t=>t.serial);return D.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},children:D.jsx("span",{children:A},e)})}function ndA(A){return A&&/(^|\s)max-h-/.test(A)?void 0:{maxHeight:"var(--available-height)",overflowY:"auto"}}const TE=R.forwardRef(function({className:e,...t},n){return D.jsx("div",{ref:n,className:De("pointer-events-auto flex items-center gap-1 rounded-[12px] bg-chrome text-chrome-fg shadow-chrome",e),...t})});function Jx({className:A,vertical:e=!0}){return D.jsx("div",{"aria-hidden":"true",className:De(e?"mx-0.5 h-[18px] w-px":"my-1 h-px w-full","shrink-0 bg-chrome-line",A)})}const odA=A=>A?{[A]:""}:{};function bs({label:A,shortcut:e,side:t="bottom",children:n,disabled:o}){return D.jsxs(Nv,{disabled:o,children:[D.jsx(Rv,{render:n}),D.jsx(Mv,{children:D.jsx(Gv,{side:t,sideOffset:8,className:"z-[1000]",children:D.jsxs(Fv,{className:"flex max-w-80 items-center gap-1.5 rounded-[6px] bg-tip px-2 py-[5px] text-[13px] leading-[18px] text-tip-fg shadow-[0_1px_2px_rgb(11_11_11/0.06),0_2px_8px_rgb(11_11_11/0.08)] transition-opacity data-[ending-style]:opacity-0 data-[starting-style]:opacity-0",children:[D.jsx("span",{children:A}),e?D.jsx("kbd",{className:"rounded-[4px] bg-white/15 px-1 font-sans text-[12px] leading-4 text-tip-fg/80",children:e}):null]})})})]})}const idA={md:"h-7",lg:"h-8",xl:"h-9"},rdA={md:"w-7",lg:"w-8",xl:"w-9"},zi=R.forwardRef(function({pressed:e,square:t,size:n="md",className:o,type:i="button",...r},a){return D.jsx("button",{ref:a,type:i,"aria-pressed":e,className:De("inline-flex shrink-0 select-none items-center justify-center gap-1 whitespace-nowrap rounded-[8px] text-[14px] font-control leading-5 text-chrome-fg outline-none transition-colors duration-100 ease-out","hover:bg-chrome-hover focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-chrome-focus","disabled:pointer-events-none disabled:opacity-40",idA[n],t?rdA[n]:"px-[9px]",e&&"bg-chrome-pressed text-chrome-pressed-fg hover:bg-chrome-pressed",o),...r})}),Af=R.forwardRef(function({tip:e,shortcut:t,side:n,disabled:o,...i},r){const a=D.jsx(zi,{ref:r,disabled:o,...i});return D.jsx(bs,{label:e,shortcut:t,side:n,children:o?D.jsx("span",{className:"inline-flex",children:a}):a})}),ef=R.forwardRef(function({label:e,tip:t,icon:n,shortcut:o,tipSide:i="top",size:r="xl",className:a,...c},g){return D.jsx(bs,{label:t??e,shortcut:o,side:i,children:D.jsx(zi,{ref:g,square:!0,size:r,"aria-label":e,className:De("[&_svg]:size-[18px] [&_svg]:shrink-0",a),...c,children:n})})}),sdA="min-w-[128px] max-w-[320px] rounded-[14px] bg-chrome p-1.5 text-[14px] leading-5 font-control text-chrome-fg shadow-chrome-popup outline-none origin-[var(--transform-origin)] transition-[opacity,transform] duration-100 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0",adA="flex h-7 cursor-default select-none items-center gap-2 rounded-[8px] px-2.5 outline-none data-[highlighted]:bg-chrome-hover data-[popup-open]:bg-chrome-hover data-[disabled]:opacity-40";function cdA({trigger:A,children:e,side:t="bottom",align:n="start",className:o,tip:i,open:r,onOpenChange:a,sideOffset:c=6,mark:g,popupBase:u=sdA}){const I=D.jsx(DE,{render:A});return D.jsxs(yE,{open:r,onOpenChange:a?C=>a(C):void 0,children:[i?D.jsx(bs,{label:i.label,shortcut:i.shortcut,side:i.side??(t==="top"?"top":"bottom"),children:I}):I,D.jsx(Jv,{children:D.jsx(Ov,{side:t,align:n,sideOffset:c,className:"z-[1000]",children:D.jsx(Kv,{...odA(g),className:De(u,o),style:ndA(o),children:e})})})]})}function ldA({children:A,onSelect:e,shortcut:t,checked:n,disabled:o,danger:i,icon:r,title:a,description:c,closeOnClick:g}){return D.jsxs(JP,{className:De(adA,c!==void 0&&"h-auto min-h-7 items-start py-1.5",i&&"text-danger data-[highlighted]:bg-danger data-[highlighted]:text-white"),disabled:o,onClick:u=>{g!==!1&&wcA(u.nativeEvent),e?.()},closeOnClick:g,title:a,children:[n!==void 0?D.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:n?D.jsx(ju,{className:"size-4 text-chrome-accent",strokeWidth:2.25}):null}):null,r?D.jsx("span",{"data-chrome-icon":"",className:"flex size-4 shrink-0 items-center justify-center text-chrome-muted",children:r}):null,c!==void 0?D.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[D.jsx("span",{className:"truncate",children:A}),D.jsx("span",{className:"truncate text-[12px] leading-4 text-chrome-muted",children:c})]}):D.jsx("span",{className:"min-w-0 flex-1 truncate",children:A}),t?D.jsx("span",{className:"ml-6 max-w-40 shrink-0 truncate text-[13px] text-chrome-muted",children:t}):null]})}function Vc(){return typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent)}const $g=Vc()?"⌘":"Ctrl+",gdA=$g==="⌘"?"⇧":"Shift+";function udA(A,e,t){if(t<=0||e<0||e>=t)return null;switch(A){case"ArrowRight":case"ArrowDown":return(e+1)%t;case"ArrowLeft":case"ArrowUp":return(e-1+t)%t;case"Home":return 0;case"End":return t-1;default:return null}}function IdA(A){let e=!1;A.setCanRestore(A.roleMayRestore),A.report({history:!0});const t=()=>{A.history.list().then(o=>{e||A.setCanRestore(o.canRestore&&A.roleMayRestore)},()=>{})};t();const n=[A.history.onChange(t),A.onCommand(o=>{o.cmd==="history"&&A.toggle()})];return()=>{e=!0;for(const o of n)o();A.report({history:void 0})}}async function CdA(A,e,t,n=12){const o=t(Object.keys(await A.files(e))),i=[];let r=0;const a=async()=>{for(;r<o.length;){const c=o[r++],g=await A.read(e,c).catch(()=>null);g!==null&&i.push([c,g])}};return await Promise.all(Array.from({length:Math.min(n,o.length)},a)),i}const fdA="1.4.0";class zc extends Error{code;paths;retryable;constructor(e,t,n,o){super(t),this.name="ArtifactError",this.code=e,n&&(this.paths=n),o&&(this.retryable=!0)}}function EdA(A){return A==="owner"||A==="editor"}const tC={maxDocumentBytes:262144,maxDepth:32},PK={defaultMs:12e4,maxMs:6e5};function BdA(A,e={}){const t=e.timeoutMs??1e4,n=new Map;return Object.freeze({version:fdA,use:i=>{const r=n.get(i);if(r)return r;const a=new Promise(c=>{const g=setTimeout(()=>c(null),t);Promise.resolve().then(()=>A.get(i)).then(u=>{clearTimeout(g),c(u?Object.freeze(u):null)},()=>{clearTimeout(g),c(null)})});return n.set(i,a),a}})}function QdA(A,e){const t=globalThis.window?.openartifact;if(t)return t;const n=BdA(A,e);return Object.defineProperty(window,"openartifact",{value:n,configurable:!1,enumerable:!0,writable:!1}),n}const Xe={session:"_api/session",files:"_api/files",file:"_api/file",publish:"_api/publish",assets:"_api/assets",events:"_api/events",agentSend:"_api/agent/send",presence:"_api/presence",peers:"_api/peers",downloads:"_api/downloads",roomEmit:"_api/room/emit",dbGet:"_api/db/get",dbList:"_api/db/list",dbWrite:"_api/db/write",comments:"_api/comments",commentsCreate:"_api/comments/create",commentsReply:"_api/comments/reply",commentsEdit:"_api/comments/edit",commentsReact:"_api/comments/react",commentsResolve:"_api/comments/resolve",commentsMove:"_api/comments/move",commentsRemove:"_api/comments/remove",commentsSend:"_api/comments/send",history:"_api/history",historyFiles:"_api/history/files",historyFile:"_api/history/file",historyDiff:"_api/history/diff",historyRestore:"_api/history/restore",historyDismiss:"_api/history/dismiss",systemCopy:"_api/design/system-copy",mcpTools:"_api/mcp/tools",mcpCall:"_api/mcp/call",dataRefresh:"_api/data/refresh"},jQ={read:"_api/sheet/read",send:"_api/sheet/send",widget:"_api/sheet/widget",importFile:"_api/sheet/import"},ddA="sheet",hdA="sheetWalkthrough",Qa={session:"_api/doc/session",read:"_api/doc/read",call:"_api/doc/call",history:"_api/doc/history",version:"_api/doc/version",restore:"_api/doc/restore",importFile:"_api/doc/import",exportFile:"_api/doc/export"};function pdA(A,e,t){return e===401||e===403?"removed":e<200||e>=300||!t||t.id===A.id&&t.role===A.role?null:"changed"}async function Jb(A){let e={};try{e=await A.json()}catch{}const t=A.status===409?"conflict":A.status===403?"not_writer":A.status===404?"not_found":"unavailable";return new zc(e.code??t,e.message??`HTTP ${A.status}`,e.paths,e.retryable===!0)}function wdA(){const A=new Uint8Array(8);return crypto.getRandomValues(A),Array.from(A,e=>e.toString(16).padStart(2,"0")).join("")}function Y9(A={}){const e=new URL(A.base??"./",location.href),t=wdA(),n=(x,L)=>{const G=new URL(x,e);for(const[Y,J]of Object.entries(L??{}))G.searchParams.set(Y,J);return G.toString()},o=async(x,L,G)=>{let Y;try{Y=await fetch(n(x,G),L)}catch(J){throw new zc("unavailable",J instanceof Error?J.message:String(J))}if(!Y.ok)throw await Jb(Y);return await Y.json()},i=(x,L)=>o(x,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(L)}),r=new Map,a=(x,L)=>{for(const G of r.get(x)??[])G(L)},c=(x,L)=>{let G=r.get(x);return G||(G=new Set,r.set(x,G),I?.addEventListener(x,f)),G.add(L),p(),()=>G.delete(L)};let g=null,u=!1,I=null,C=null;const f=x=>{a(x.type,JSON.parse(x.data))},B=()=>{const x=new EventSource(n(Xe.events,{client:t}));I=x;for(const L of r.keys())x.addEventListener(L,f);x.onerror=()=>{m().then(L=>{L||x.readyState!==EventSource.CLOSED||I!==x||(I=null,C=setTimeout(()=>{C=null,p()},2e3))})}};let Q=!1,d=!1;const y=x=>{Q||(Q=!0,C&&clearTimeout(C),C=null,I?.close(),I=null,g?.close(),g=null,A.onAccessChange?A.onAccessChange(x):location.reload())},m=async()=>{if(Q)return!0;if(!w||d)return!1;d=!0;try{const x=(await w.catch(()=>null))?.viewer;if(!x)return!1;let L;try{L=await fetch(n(Xe.session),{cache:"no-store"})}catch{return!1}const G=L.ok?(await L.json().catch(()=>null))?.viewer:null,Y=pdA(x,L.status,G);return Y&&y(Y),Y!==null}finally{d=!1}};function p(){if(g||I||C||Q)return;if(typeof WebSocket>"u")return B();const x=new URL(n(Xe.events,{client:t}));x.protocol=x.protocol==="https:"?"wss:":"ws:";const L=new WebSocket(x);g=L,L.onopen=()=>{u=!0},L.onmessage=G=>{let Y;try{Y=JSON.parse(String(G.data))}catch{return}Y.event&&a(Y.event,Y.data)},L.onclose=()=>{if(g===L&&(g=null),!Q){if(!u)return B();m().then(G=>{G||g||I||C||(C=setTimeout(()=>{C=null,p()},2e3))})}}}let w=null;const b=()=>w??=o(Xe.session),N={async artifact(){const{artifact:x,stores:L}=await b();return{id:x.id,...L?.systemCopy?{systemCopy:(Y,J)=>o(Xe.systemCopy,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({namespace:Y,action:J})})}:{},title:async()=>(await o(Xe.session)).artifact.title,list:async()=>(await o(Xe.files)).files,readText:async Y=>new TextDecoder().decode(await k(Y)),readBytes:Y=>k(Y),publish:async Y=>{const J={files:Y,client:t};return o(Xe.publish,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(J)})},onChange:Y=>c("files",Y)}},async assets(){const{viewer:x}=await b();return EdA(x.role)?{upload:async(G,Y)=>o(Xe.assets,{method:"POST",headers:{"content-type":G.type||"application/octet-stream"},body:G},Y?.name?{name:Y.name}:void 0)}:null},async user(){const{viewer:x}=await b();return{me:async()=>x}},async agent(){return{send:async(L,G)=>{const Y={request:L,deliver:G?.deliver??"send"};return o(Xe.agentSend,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Y)})},status:async()=>(await o(Xe.session)).agent,onStatus:L=>c("agent",L)}},async room(){return{self:async()=>t,presence:async L=>{const G={client:t,patch:L};await o(Xe.presence,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(G)})},peers:async()=>(await o(Xe.peers)).peers,onPeers:L=>c("peers",L),emit:async(L,G)=>{const Y={client:t,topic:L,data:G};await i(Xe.roomEmit,Y)},onMessage:L=>c("room",L)}},async db(){const{stores:x}=await b();return x?.db?{get:async G=>(await o(Xe.dbGet,{cache:"no-store"},{path:G})).data,list:async G=>(await o(Xe.dbList,{cache:"no-store"},{collection:G})).documents,listing:async G=>{const{documents:Y,epoch:J,seq:U}=await o(Xe.dbList,{cache:"no-store"},{collection:G});return typeof J=="string"&&typeof U=="number"?{documents:Y,epoch:J,seq:U}:{documents:Y}},write:async G=>{const Y={writes:G,client:t},{epoch:J,seq:U,documents:T}=await i(Xe.dbWrite,Y);return typeof J=="string"&&typeof U=="number"&&T!==void 0?{epoch:J,seq:U,documents:T}:void 0},onChange:G=>c("db",G)}:null},async comments(){const{stores:x}=await b();if(!x?.comments)return null;const L=async(Y,J)=>(await i(Y,J)).thread;return{list:async()=>(await o(Xe.comments,{cache:"no-store"})).threads,create:Y=>L(Xe.commentsCreate,{input:Y}),reply:(Y,J,U)=>L(Xe.commentsReply,{threadId:Y,text:J,...U?.to?.length?{to:U.to}:{}}),edit:(Y,J,U,T)=>L(Xe.commentsEdit,{threadId:Y,messageId:J,text:U,...T?.to?{to:T.to}:{}}),react:(Y,J,U,T)=>L(Xe.commentsReact,{threadId:Y,messageId:J,emoji:U,on:T}),setResolved:(Y,J)=>L(Xe.commentsResolve,{threadId:Y,resolved:J}),move:(Y,J,U)=>L(Xe.commentsMove,{threadId:Y,anchor:J,...U?{location:U}:{}}),remove:async(Y,J)=>{await i(Xe.commentsRemove,{threadId:Y,...J?{messageId:J}:{}})},sendToAgent:(Y,J)=>L(Xe.commentsSend,{threadId:Y,...J?.unasked?{unasked:!0}:{}}),onChange:Y=>c("comments",Y)}},async doc(){const{stores:x}=await b();return x?.doc?{session:()=>i(Qa.session,{client:t}),read:G=>i(Qa.read,{tab:G}),call:G=>i(Qa.call,{...G,client:t}),history:G=>i(Qa.history,{tab:G}),version:(G,Y)=>i(Qa.version,{tab:G,rev:Y}),restore:G=>i(Qa.restore,G),importFile:(G,Y,J)=>o(Qa.importFile,{method:"POST",headers:{"content-type":"application/octet-stream"},body:Y},{name:G,...J?{tabName:J}:{}}),exportFile:async G=>{let Y;try{Y=await fetch(n(Qa.exportFile,{format:G.format,...G.tab?{tab:G.tab}:{},...G.paper?{paper:G.paper}:{}}),{cache:"no-store"})}catch(F){throw new zc("unavailable",F instanceof Error?F.message:String(F))}if(!Y.ok)throw await Jb(Y);const J=Y.headers.get("content-disposition")??"",U=decodeURIComponent(/filename\*=UTF-8''([^;]+)/.exec(J)?.[1]??"")||`doc.${G.format==="markdown"?"md":G.format}`;let T=[];try{T=JSON.parse(decodeURIComponent(Y.headers.get("x-doc-export-notes")??"%5B%5D"))}catch{}return{name:U,mime:Y.headers.get("content-type")??"application/octet-stream",bytes:new Uint8Array(await Y.arrayBuffer()),notes:T}},onFrame:G=>c("doc",G)}:null},async history(){const{stores:x}=await b();if(!x?.history)return null;const L=(Y,J)=>({n:String(Y),...J===void 0?{}:{path:J}});return{list:()=>o(Xe.history,{cache:"no-store"}),files:async Y=>(await o(Xe.historyFiles,{cache:"no-store"},L(Y))).files,read:async(Y,J)=>new TextDecoder().decode(await M(Xe.historyFile,L(Y,J))),readBytes:(Y,J)=>M(Xe.historyFile,L(Y,J)),diff:(Y,J)=>o(Xe.historyDiff,{cache:"no-store"},L(Y,J)),restore:(Y,J)=>i(Xe.historyRestore,{n:Y,...J?{paths:J}:{},client:t}),dismissNotice:async Y=>{await i(Xe.historyDismiss,{id:Y})},onChange:Y=>c("history",Y)}},async mcp(){const{viewer:x}=await b();return x.role!=="owner"?null:{callTool:async(G,Y,J,U)=>{const T=U?.signal;T?.throwIfAborted();const F={server:G,tool:Y,args:J,...U?.timeoutMs===void 0?{}:{timeoutMs:U.timeoutMs}};try{return await o(Xe.mcpCall,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(F),...T?{signal:T}:{}})}catch(K){throw T?.aborted?T.reason:K}},listTools:G=>o(Xe.mcpTools,{cache:"no-store"},G===void 0?void 0:{server:G})}},async sheet(){const{stores:x}=await b();if(!x?.sheet)return null;let L=Promise.resolve();return{read:Y=>i(jQ.read,Y),send:Y=>{const J=L.then(()=>i(jQ.send,Y));return L=J.catch(()=>{}),J},widget:Y=>i(jQ.widget,Y),importFile:(Y,J)=>o(jQ.importFile,{method:"POST",headers:{"content-type":Y.type||"application/octet-stream"},body:Y},{name:J}),onFrame:Y=>c(ddA,Y),onWalkthrough:Y=>c(hdA,Y)}},async downloads(){return{save:async({name:L,data:G})=>o(Xe.downloads,{method:"POST",headers:{"content-type":G.type||"application/octet-stream"},body:G},{name:L})}}};function k(x){return M(Xe.file,{path:x})}async function M(x,L){let G;try{G=await fetch(n(x,L),{cache:"no-store"})}catch(Y){throw new zc("unavailable",Y instanceof Error?Y.message:String(Y))}if(!G.ok)throw await Jb(G);return new Uint8Array(await G.arrayBuffer())}return{get(x){const L=N[x];return L?L():null}}}const ydA="[Artifact comment sent to agent]",DdA="[Artifact edit request sent to agent]",mdA="[Artifact task finished]",bdA="[Open Artifact] ",SdA={id:"open_artifact_id"},T9="#view-inline",NdA=1,RdA=1,MdA=/^[a-z][a-z0-9]{0,23}$/,kdA="may not have run: the artifact was updated before this call was answered",vdA=["quickstart","list","publish","read","open","call","adopt","delete","share"],xdA=["get","list","query","set","update","delete","str_replace","batch"],GdA=["read","reply","resolve","reopen","wait"],FdA=["share","export"],LdA={type:"object",properties:{action:{type:"string",enum:vdA,description:"What to do: quickstart, list, publish, read, open, call, adopt, delete or share. Omitted: publish."},intent:{type:"string",description:"quickstart: what is being made (design, design-system, slides, whiteboard, document, data, sheets, motion, page, other), or a few words about it."},scope:{type:"string",enum:["types","mine","all"],description:"list: types (the installed types), mine (this session's and this workspace's artifacts; the default) or all (every artifact)."},type:{type:"string",description:"list: only artifacts of this type (an id, or open-artifact://type/<id>). quickstart: the type already chosen (an id), to get its create call and steps without matching."},query:{type:"string",description:"list: only artifacts whose title contains this text."},limit:{type:"integer",description:"list: how many to return (default 50, at most 200)."},cursor:{type:"string",description:"list: the next_cursor of the previous page."},type_url:{type:"string",description:"publish without url: the type to create from (open-artifact://type/<id>, from quickstart). read without url: the type to describe."},title:{type:"string",description:"publish without url: the new artifact's name. quickstart: the name it will have, to find similar ones."},folder:{type:"string",description:"publish without url, or adopt: where the artifact's folder goes (absolute, or relative to the workspace). Default <workspace>/artifacts/<slug>."},url:{type:"string",description:"An artifact: open-artifact://artifact/<id>, as publish returned it."},files:{type:"object",additionalProperties:!0,description:'publish with url: files to write under the artifact root, as {"rel/path": "text"} or {"rel/path": {"content": "...", "encoding": "base64"}}; null deletes.'},if_match:{type:"object",additionalProperties:!0,description:'publish with url: {"rel/path": sha256 | null | "*"}. Write only while the file still has the sha256 you read, does not exist (null), or anyway ("*"). One mismatch writes nothing and returns the current versions.'},check:{type:"boolean",description:"publish with url: run the type's check action after writing; its result comes back as check."},capabilities:{type:"object",additionalProperties:!0,description:'publish, page artifacts only: the runtime capabilities the page may use, as {"db": true, "assets": true, ...}. Omitted: kept; {}: none; otherwise the whole set. With url it may be given without files.'},open:{type:"string",enum:["after_first_write","now","never"],description:"publish without url: after_first_write (the default) opens the page in your app once your first write lands; now opens it at once; never leaves it closed. Where your app cannot show pages by itself the result says so: open view_url in your app's built-in browser, if you have one."},related:{type:"boolean",description:"quickstart: list existing artifacts the recommended type can build on, such as design systems (default true)."},path:{type:"string",description:"read: one file or folder under the root (omitted: the record and the file list)."},paths:{type:"array",items:{type:"string"},description:"read: several files under the root at once."},name:{type:"string",description:"call: the action's name (check, upload, ...; read with url lists them)."},args:{type:"object",additionalProperties:!0,description:"call: the action's arguments. upload: {file: absolute path, name?, group?}."},panel:{type:"string",enum:FdA,description:"open: also open the page's Share panel (share), for the person to share it on the network, or its Export tab (export), for them to download a file."},cloud:{type:"string",description:"share: publish the artifact to this cloud remote (its name, as `open-artifact remote list` shows it). It works only on a remote the person set up and let agents publish to (agentMayPublish); otherwise the person publishes it, from the Share panel or with `open-artifact publish <id> --remote <name>`."}}},UdA={type:"object",properties:{action:{type:"string",enum:xdA,description:"What to do: get, list, query, set, update, delete, str_replace or batch."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>)."},collection:{type:"string",description:"The collection: alone for list / query (query needs it), with doc_id for one document."},doc_id:{type:"string",description:"With collection: the document to get / set / update / delete / str_replace."},path:{type:"string",description:"collection/doc_id, instead of the two."},data:{type:"object",additionalProperties:!0,description:"set / update: the document's fields."},file_path:{type:"string",description:"set / update: a JSON file holding the fields, instead of data."},if_match:{description:'set / update / delete / str_replace: the sha256 get returned (write only if unchanged), null (only if it does not exist) or "*" (replace whatever is there).'},field:{type:"string",description:"str_replace: the text field, as a dot path (body, notes.text)."},old:{type:"string",description:"str_replace: the passage to replace; it must occur exactly once."},new:{type:"string",description:"str_replace: the passage that replaces it."},where:{type:"array",items:{type:"object",additionalProperties:!0},description:"query: [{field, op, value}], all must hold. op: ==, !=, <, <=, >, >=, in, not-in (up to 30 values), array-contains."},order_by:{type:"object",additionalProperties:!0,description:'query: {field, dir: "asc" | "desc"}.'},limit:{type:"integer",description:"list / query: how many documents (default 100, at most 1000)."},cursor:{type:"string",description:"list / query: the next_cursor of the previous page."},out_file:{type:"string",description:"get / list / query: write the result to this JSON file (absolute, or relative to the workspace) and return only its path and counts."},writes:{type:"array",items:{type:"object",additionalProperties:!0},description:"batch: [{op: set|update|delete|str_replace, path | collection+doc_id, data | file_path, if_match?, field?, old?, new?}], at most 500."}},required:["action","url"]},YdA={type:"object",properties:{action:{type:"string",enum:GdA,description:"What to do: read, reply, resolve, reopen or wait."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>). wait: optional."},thread_id:{type:"string",description:'reply / resolve / reopen: the thread (after ";thread=" in the message).'},text:{type:"string",description:"reply: the answer."},resolve:{type:"boolean",description:"reply: resolve the thread too."},all:{type:"boolean",description:"read: resolved threads too."},since:{type:"string",description:"read: only threads with a message at or after this time (ISO 8601)."},acknowledge_duplicate:{type:"boolean",description:"reply: send the same text as your last reply in this thread again, on purpose."},timeout_ms:{type:"number",description:"wait: how long (default 600000)."}},required:["action"]},jK={Artifact:LdA,ArtifactData:UdA,ArtifactComments:YdA},TdA={Artifact:["Make and change artifacts: typed folders of files that open as live pages the person can view, edit, comment on and export. Actions:","- quickstart {intent, type?}: call first for a new artifact; recommends a type (or takes the one given) and returns the call that creates it, the steps for this app and similar artifacts that already exist.",'- list {scope: "mine" | "all" | "types", type?, query?}: find existing artifacts, or the installed types.',"- publish {type_url, title, folder?, open?}: create an artifact; the result carries its root folder and the type's instructions. publish {url, files, if_match?, check?}: write files when you have no file tools of your own. A page artifact also takes capabilities (on create or write): the runtime capabilities its page may use.","- read {url, path? | paths?}: the artifact's record, files and actions, or some of its files with their sha256. read {type_url}: a type's instructions, before creating.",`- open {url, panel?}: show it to the person in the computer's browser (or the app, when it shows pages), once its content is written. When your app has a built-in browser, open view_url there instead. panel "share" or "export" opens its Share panel or Export tab for them.`,"- call {url, name, args?}: run one of the type's actions (check, upload, ...). A long one answers {task, pending: true}; its result comes later as a message.","- adopt {url | folder}: take over an artifact, or add an existing folder. Only when the person asks.","- share {url}: whether it is shared on the local network, and its links. Only the person changes that, in the page's Share panel.","- delete {url}: forget an artifact; its folder stays. Only when the person asks."].join(`
35
+ `:I)});break}const C=c.items.map((f,B)=>D.jsx("li",{value:c.ordered?f.n:void 0,children:D.jsx("span",{className:Tb,children:bC(f.c,e,u+"."+B,n+1)})},B));r.push(c.ordered?D.jsx("ol",{className:eQA,children:C},u):D.jsx("ul",{className:AQA,children:C},u));break}}}),a(t+".end"),o}function ZC(A,e){return A.map((t,n)=>{if(typeof t=="string")return t;const o=e+":"+n;switch(t.t){case"raw":return D.jsx(R.Fragment,{children:t.raw},o);case"code":return D.jsx("code",{dir:"ltr",className:w9,children:t.text},o);case"em":return D.jsx("em",{children:ZC(t.c,o)},o);case"strong":return D.jsx("strong",{className:"font-semibold",children:ZC(t.c,o)},o);case"del":return D.jsx("del",{children:ZC(t.c,o)},o)}})}function UK(A,e=new Date){const t=new Date(A);if(Number.isNaN(t.getTime()))return"";if(e.getTime()-t.getTime()<6e4)return"now";const n=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"}),o=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),i=Math.round((o(e)-o(t))/864e5);return i===0?n:i===1?`Yesterday, ${n}`:`${t.toLocaleDateString("en-US",{month:"short",day:"numeric",...t.getFullYear()!==e.getFullYear()?{year:"numeric"}:{}})}, ${n}`}function hQA(A,e=new Date){const t=new Date(A);if(Number.isNaN(t.getTime()))return"";const n=Math.floor((e.getTime()-t.getTime())/6e4);if(n<1)return"now";if(n<60)return`${n}m`;const o=Math.floor(n/60);if(o<24)return`${o}h`;const i=Math.floor(o/24);return i<7?`${i}d`:t.toLocaleDateString("en-US",{month:"short",day:"numeric",...t.getFullYear()!==e.getFullYear()?{year:"numeric"}:{}})}const YK=A=>{let e;const t=new Set,n=(g,u)=>{const I=typeof g=="function"?g(e):g;if(!Object.is(I,e)){const C=e;e=u??(typeof I!="object"||I===null)?I:Object.assign({},e,I),t.forEach(f=>f(e,C))}},o=()=>e,a={setState:n,getState:o,getInitialState:()=>c,subscribe:g=>(t.add(g),()=>t.delete(g))},c=e=A(n,o,a);return a},pQA=(A=>A?YK(A):YK),wQA=A=>A;function yQA(A,e=wQA){const t=QC.useSyncExternalStore(A.subscribe,QC.useCallback(()=>e(A.getState()),[A,e]),QC.useCallback(()=>e(A.getInitialState()),[A,e]));return QC.useDebugValue(t),t}const TK=A=>{const e=pQA(A),t=n=>yQA(e,n);return Object.assign(t,e),t},nn=(A=>A?TK(A):TK),DQA=4e3,N9="Wait for the current change to finish.";function mQA(A,e){return e?A.map(t=>t.id===e.id?R9(t,e.status):t):A}function R9(A,e,t){if(A.status===e&&A.resolvedBy===t)return A;const{resolvedBy:n,...o}=A;return e==="resolved"&&t?{...o,status:e,resolvedBy:t}:{...o,status:e}}function bQA(A){return A.wakesIdle===!1?`${A.name} gets this on its next turn: send it a message to start one`:"Waiting for the agent"}function KK(A,e){return e===!1?{title:`Sent to ${A}`,description:`${A} gets it on its next turn. If it is idle, send it a message there to start one.`}:{title:`Sent to ${A}`}}function M9(A){return A.reduce((e,t)=>t.status==="open"?e+t.messages.length:e,0)}function SQA(A){return A==="detached"?"What this was on is gone; shown on what held it.":A==="orphaned"?"What this was on has been deleted.":null}function NQA(A){const e=A.maxThreads??500,t=A.noun??"document",n=p=>A.notify?.(p);let o=null,i,r=0;const a=nn()(p=>({available:!1,threads:[],on:!1,listOpen:!1,active:null,draft:null,showResolved:!1,sendNew:!1,draftText:"",replies:{},statusChange:null,setOn(w){p({on:w,draft:null}),A.onModeChange?.(w)},setListOpen(w){p({listOpen:w})},setActive(w){p({active:w,draft:null})},setDraft(w){p(w===null?{draft:w,active:null,draftText:"",sendNew:!1}:{draft:w,active:null})},setShowResolved(w){p({showResolved:w})},setSendNew(w){p({sendNew:w})},setDraftText(w){p({draftText:w})},setReply(w,b){p(N=>({replies:{...N.replies,[w]:b}}))}})),c=new Map,g=p=>{let w=c.get(p.anchor);return w===void 0&&(w=A.parse(p.anchor),c.size>2e3&&c.clear(),c.set(p.anchor,w)),w};let u=[];const I=(p,w)=>{u=p;const b=w&&"statusChange"in w?w.statusChange??null:a.getState().statusChange;a.setState({...w,threads:mQA(p,b)})},C=p=>{n({title:"The comment could not be saved",description:p instanceof Error?p.message:String(p)})},f=p=>{I(u.map(w=>w.id===p.id?p:w)),A.heard?.([p])},B=p=>A.checkText?A.checkText(p):p.trim().slice(0,DQA)||void 0,Q=()=>!!o&&A.canComment(),d=()=>!!o&&A.canSendToAgent(),m={store:a,adapter:A,async start(p,w){if(!p)return;o=p;const b=r;a.setState({available:!0});try{const k=await p.list();if(b!==r)return;I(k),A.heard?.(k)}catch{}if(b!==r)return;i=p.onChange(k=>{const M=a.getState().active;I(k,{active:M&&k.some(x=>x.id===M)?M:null}),A.heard?.(k)});const N=w?a.getState().threads.find(k=>k.id===w):void 0;N&&m.reveal(N)},stop(){r+=1,i?.(),i=void 0},capability:()=>o,canComment:Q,canSendToAgent:d,canRemove:()=>!!o&&(A.canRemove?A.canRemove():A.canComment()),anchorOf:g,labelOf:p=>A.label(p),stateOf:p=>A.state?.(p)??"ok",stateNote:p=>A.stateNote?A.stateNote(p??"ok"):SQA(p),async create(p,w,b){if(!o)return!1;const N=B(w);if(!N)return!1;if(a.getState().threads.length>=e)return n({title:`This ${t} already has ${e} comments`}),!1;try{const k=A.detail?.(p),M=await o.create({anchor:A.serialize(p),label:A.label(p),...k!==void 0?{detail:k}:{},location:A.location?.(p)??{},text:N}),x=!!b?.send&&d();return I(u.some(L=>L.id===M.id)?u:[...u,M],{draft:null,draftText:"",sendNew:!1,active:A.opensCreated?.(x)===!1?null:M.id}),A.heard?.([M]),x&&await m.sendToAgent(M.id),!0}catch(k){return C(k),!1}},async reply(p,w,b){if(!o)return!1;const N=B(w);if(!N)return!1;try{let k=await o.reply(p,N);return k.status==="resolved"&&(k=await o.setResolved(p,!1)),f(k),a.setState(M=>{const{[p]:x,...L}=M.replies;return{replies:L}}),b?.send&&d()&&await m.sendToAgent(p),!0}catch(k){return C(k),!1}},async resolve(p,w){if(!o)return;const b=a.getState(),N=w?"resolved":"open",k=b.threads.find(x=>x.id===p);if(!k||b.statusChange||k.status===N)return;const M=w&&b.active===p&&!b.showResolved;I(u,{statusChange:{id:p,status:N},...M?{active:null}:{}});try{const x=await o.setResolved(p,w);I(u.map(L=>L.id===p?R9(L,x.status,x.resolvedBy):L),{statusChange:null}),A.heard?.([x])}catch(x){I(u,{statusChange:null}),C(x);const L=a.getState();M&&L.active===null&&L.draft===null&&u.some(G=>G.id===p)&&a.setState({active:p})}},async remove(p,w){if(!(!o||A.canRemove&&!A.canRemove()))try{await o.remove(p,w),w||I(u.filter(b=>b.id!==p),{active:a.getState().active===p?null:a.getState().active})}catch(b){C(b)}},async move(p,w){if(o)try{f(await o.move(p,A.serialize(w),A.location?.(w)))}catch(b){C(b)}},async sendToAgent(p){if(!o||!d())return!1;const w=A.sendToAgent?a.getState().threads.find(b=>b.id===p):void 0;if(A.sendToAgent)return w?A.sendToAgent(w,g(w)):!1;try{return f(await o.sendToAgent(p)),n(KK(A.agentName?.()||"the agent",A.agentWakesIdle?.())),!0}catch(b){return C(b),!1}},async sendAllToAgent(){if(!o||!d())return;const p=a.getState().threads.filter(M=>m.canSendThread(M));if(!p.length)return;if(A.sendToAgent){await Promise.all(p.map(M=>A.sendToAgent(M,g(M))));return}const w=o,b=await Promise.allSettled(p.map(M=>w.sendToAgent(M.id)));let N=0;for(const M of b)M.status==="fulfilled"&&(f(M.value),N++);N&&n(KK(A.agentName?.()||"the agent",A.agentWakesIdle?.()));const k=b.find(M=>M.status==="rejected");k&&C(k.reason)},canSendThread(p){if(p.status!=="open")return!1;const w=p.messages.at(-1);return!w||w.author.kind!=="person"?!1:!p.agent||p.agent.status==="replied"},reveal(p){A.reveal?.(g(p)),a.getState().setActive(p.id)},show(p){const w=a.getState();w.on||w.setOn(!0),p.status==="resolved"&&!a.getState().showResolved&&a.getState().setShowResolved(!0),m.reveal(p)},viewerName:()=>A.viewerName?.()||"You"};return m}const k9=300,$C=12,RQA=k9+$C*2;function MQA({comments:A,agent:e,top:t=$C,hint:n}){return A.store(i=>i.listOpen&&i.available)?D.jsx(YE,{mark:"data-comments-panel-layer",children:D.jsx(kQA,{comments:A,agent:e,top:t,hint:n})}):null}const JK=A=>A.messages[0]?.at??"";function kQA({comments:A,agent:e,top:t,hint:n}){const{dark:o}=UE(),i=A.store(f=>f.threads),r=A.store(f=>f.showResolved),a=A.store(f=>f.on),c=A.store(f=>f.active),g=()=>A.store.getState().setListOpen(!1),u=i.filter(f=>f.messages.length>0),I=u.filter(f=>r||f.status==="open").sort((f,B)=>JK(B).localeCompare(JK(f))),C=u.filter(f=>f.status==="resolved").length;return D.jsxs("section",{"aria-label":"All comments","data-comments-panel":"",className:Yt(kx(),"fixed flex flex-col text-body text-primary"),style:{top:t,right:$C,width:k9,maxWidth:`calc(100vw - ${$C*2}px)`,maxHeight:`calc(100dvh - ${t+$C}px)`,zIndex:40,pointerEvents:"auto",...vx(o)},onKeyDown:f=>{const B=f.target instanceof Element&&f.target.closest("[data-cds=Menu]");f.key==="Escape"&&!f.defaultPrevented&&!B&&(f.preventDefault(),g())},children:[D.jsxs("div",{className:"flex shrink-0 items-center gap-xs",style:{padding:"10px 10px 6px 16px"},children:[D.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:"All comments"}),D.jsx(xQA,{showResolved:r,onShowResolved:f=>A.store.getState().setShowResolved(f)}),D.jsx($i,{variant:"ghost",iconOnly:!0,"aria-label":"Close",icon:D.jsx(xi,{name:"X",size:"sm"}),onClick:g})]}),D.jsx(GQA,{comments:A,agent:e,threads:u}),D.jsxs("div",{className:"flex min-h-0 flex-col gap-xs overflow-y-auto [--cds-comment-card-bg:var(--cds-surface-2)]",style:{padding:"0 12px 12px"},children:[u.length===0?D.jsxs("div",{"data-comments-empty":"",className:"flex flex-1 flex-col items-center justify-center gap-xs px-lg text-center",style:{paddingBlock:"var(--cds-pad-xl)"},children:[D.jsx("span",{className:"text-body font-medium text-secondary",children:"No comments yet"}),D.jsx("span",{className:"text-caption text-muted",children:A.canComment()?n??"Press the comment button, then click anywhere on the artifact to add one.":"Only people with comment access can add one."})]}):I.length===0?D.jsxs("span",{"data-comments-filtered-empty":"",className:"px-lg text-center text-caption text-muted",style:{paddingBlock:"var(--cds-pad-xl)"},children:["No open comments.",C>0?D.jsxs(D.Fragment,{children:[" ",D.jsx("button",{type:"button",className:"cds-text-link cds-text-link-underline inline text-inherit",onClick:()=>A.store.getState().setShowResolved(!0),children:`Show ${C} resolved`})]}):null]}):null,I.map(f=>D.jsx(FQA,{comments:A,agent:e,thread:f,current:a&&c===f.id},f.id))]})]})}function vQA(){return D.jsx("svg",{"data-cds":"Icon","aria-hidden":!0,width:"1em",height:"1em",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.2,strokeLinecap:"round",style:{fontSize:"calc(1rem * var(--cds-rem-scale,1))"},children:D.jsx("path",{d:"M2.5 4.5h11M4.5 8h7M6.5 11.5h3"})})}function xQA({showResolved:A,onShowResolved:e}){const[t,n]=Tx();return D.jsxs(yE,{open:t,onOpenChange:n,modal:!1,children:[D.jsx(Cl,{content:"Filter",disabled:t,children:D.jsx(DE,{render:D.jsx($i,{variant:"ghost",iconOnly:!0,tooltip:!1,"aria-label":"Filter",icon:D.jsx(vQA,{})})})}),D.jsx(xx,{align:"end",children:D.jsxs(KP,{checked:A,onCheckedChange:e,closeOnClick:!1,className:Yt(s9,"group/cb text-primary data-[highlighted]:bg-fill-ghost-hover"),children:[D.jsx(l9,{}),D.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Show resolved"})]})})]})}function GQA({comments:A,agent:e,threads:t}){const[n,o]=R.useState(!1),[i,r]=R.useState(!1),a=t.filter(u=>u.status==="open"&&u.messages.some(I=>I.author.kind==="person"));if(!A.canSendToAgent()||!e.available||a.length===0)return null;const g=!a.some(u=>A.canSendThread(u))?i?`These comments were just sent to ${e.name}.`:`${e.name} has every comment.`:void 0;return D.jsx("div",{className:"flex shrink-0 flex-col items-end gap-sm",style:{padding:"0 12px 8px"},children:D.jsx(Cl,{content:g,side:"bottom",children:D.jsx($i,{"data-comments-send-all":"","data-size":"sm",variant:"secondary",busy:n,"aria-disabled":g!==void 0||n||void 0,className:"aria-disabled:opacity-disabled",onClick:()=>{g!==void 0||n||(o(!0),A.sendAllToAgent().then(()=>r(!0)).finally(()=>o(!1)))},children:`Send all to ${e.name}`})})})}function FQA({comments:A,agent:e,thread:t,current:n}){const[o,i]=R.useState(!1),[r,a]=R.useState(!1),c=A.store(d=>d.statusChange),g=R.useId(),u=t.messages[0],I=t.messages.length-1,C=t.status==="resolved",f=A.canComment(),B=u.author.kind==="agent"?u.author.name||e.name:u.author.name||"Someone",Q=[...C&&f?[{label:"Reopen",icon:"Comment",onSelect:()=>{A.resolve(t.id,!1)}}]:[],...A.canRemove()?[{label:"Delete thread",icon:"Trash",variant:"danger",onSelect:()=>i(!0)}]:[]];return D.jsxs(I9,{variant:"flat",expanded:!1,active:n,labelledBy:g,onExpand:()=>A.show(t),className:"rounded",children:[D.jsx(Vd,{nameId:g,authorName:B,agent:u.author.kind==="agent",timestamp:D.jsxs(D.Fragment,{children:[hQA(u.at),C&&" · Resolved",t.agent?D.jsx("span",{role:"img","aria-label":`Sent to ${e.name}`,className:"inline-flex",style:{width:18,height:18,marginInlineStart:4,verticalAlign:"middle",color:"var(--cds-fill-brand)"},children:D.jsx(c9,{})}):null]}),confirm:o?D.jsx(E9,{busy:r,onCancel:()=>i(!1),onDelete:()=>{a(!0),A.remove(t.id).finally(()=>a(!1))}}):void 0,actions:D.jsxs(Yx,{placement:n?"pinned":void 0,children:[f?D.jsx(f9,{resolved:C,disabled:c!==null,onResolve:()=>{A.resolve(t.id,!0)}}):null,D.jsx(C9,{items:Q,disabled:c!==null&&c.id!==t.id,waitReason:c?.id===t.id?N9:void 0})]}),children:D.jsx("span",{className:"line-clamp-3",children:hR(u.text,{flat:!0})})}),I>0&&!o?D.jsx("button",{type:"button","data-cds-part":"replies-toggle",className:"self-start text-body font-normal text-accent hover:underline",children:I===1?"1 reply":`${I} replies`}):null]})}function v9(A,e,t){switch(A.status){case"delivered":return A.drafted?{title:x9(t?.name).sent}:{title:"Sent to the agent"};case"queued":if(t?.wakesIdle===!1){const n=t.name||"The agent";return{title:`Queued for ${n}`,description:`${n} gets it on its next turn. If it is idle, send it a message there to start one.`}}return{title:"Queued for the agent",description:`It will see the request the next time it checks ${e}.`};case"staged":return{title:"Request prepared",description:"Your agent will ask before acting on it."};default:return{title:"Could not reach the agent",description:A.reason??"Try again, or copy your request into the conversation."}}}function LQA(){try{return/^zh\b/i.test(globalThis.navigator?.language??"")}catch{return!1}}function x9(A,e=LQA()){const t=String(A??"").trim();return e?{sent:`已放进 ${t||"智能体"} 的对话:到那里发出去。`,via:"在对话里,等你发出",label:"在对话里,等你发出"}:{sent:`It is in the ${t||"agent"} conversation now: send it there.`,via:"in the conversation, for you to send",label:"In the conversation, for you to send"}}function G9(A){return{status:"failed",reason:A instanceof Error?A.message:String(A)}}function UQA(A,e,t){if(!A)return()=>{};let n=!1,o=!1;A.status().then(r=>{!n&&!o&&e(r)},()=>{});const i=A.onStatus(r=>{n||(o=!0,e(r))});return()=>{n=!0,i()}}function HK(A,e){return{x:e.x*A.zoom+A.x,y:e.y*A.zoom+A.y}}function YQA(A,e){const t=A.zoom||1;return{x:(e.x-A.x)/t,y:(e.y-A.y)/t}}function TQA(A,e){return{left:e.x*A.zoom+A.x,top:e.y*A.zoom+A.y,width:e.w*A.zoom,height:e.h*A.zoom}}const KQA=5,OK="#ae7303",JQA="<svg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'><path d='M 2 26 L 2 14 A 12 12 0 1 1 14 26 Z' fill='#000' stroke='#fff' stroke-width='2'/></svg>";`${JQA.replace(/[ '<>#]/g,A=>"%"+A.charCodeAt(0).toString(16).toUpperCase())}`;const xs=36,_Q=4,Ln=8,HQA=330,_K=6,mR=48;function PQ(A,e){const t=e.height-(A.y+_Q),n=A.y-_Q,o=t<320&&n>t&&(n>=240||t<240&&n>=48);return{left:Math.min(Math.max(A.x,0),Math.max(0,e.width-(xs+Ln))),top:o?A.y-(xs+_Q):A.y+_Q,flip:o}}const F9=A=>Math.max(320,Math.round(A*.6));function OQA(A,e){const t=Ln,n=e.height-Ln,o=(r,a,c)=>Math.min(Math.max(r,a),c),i=A.flip?o(A.top+xs+2,Math.min(n,t+mR),n)-t:n-o(A.top-2,t,Math.max(t,n-mR));return Math.min(F9(e.height),Math.max(0,i))}function bR({pin:A,corner:e,viewport:t,width:n=HQA,onEscape:o,children:i}){const r=R.useRef(null),[a,c]=R.useState(0);R.useLayoutEffect(()=>{const B=r.current;if(!B)return;c(B.offsetHeight);const Q=new ResizeObserver(()=>c(B.offsetHeight));return Q.observe(B),()=>Q.disconnect()},[]);const g=Math.max(0,Math.min(n,t.width-2*Ln));let u,I,C;if(e||!A){const B=e??{x:Ln,y:Ln};u=Math.max(Ln,Math.min(B.x,t.width-Ln-g)),I=Math.max(Ln,Math.min(B.y,t.height-Ln-a)),typeof i=="function"&&(C=Math.min(F9(t.height),Math.max(mR,t.height-Ln-Math.max(Ln,B.y))))}else{if(u=A.left+xs+_K,u+g>t.width-Ln){const B=A.left-_K-g;u=B>=Ln?B:Math.max(Ln,t.width-Ln-g)}I=A.flip?A.top+xs+2-a:A.top-2,I=Math.max(Ln,Math.min(I,t.height-Ln-a)),typeof i=="function"&&(C=OQA(A,t))}const f={position:"absolute",left:u,top:I,width:g,pointerEvents:"auto",...C===void 0?{}:{maxHeight:C,"--comment-card-room":`${C}px`,display:"flex",flexDirection:"column"},...a?{}:{opacity:0,pointerEvents:"none"}};return D.jsx("div",{ref:r,style:f,"data-comment-card":"",onKeyDown:B=>{B.key!=="Escape"||B.defaultPrevented||(B.preventDefault(),o())},children:typeof i=="function"?i(C):i})}const _QA="cds-reset absolute flex items-center justify-center rounded-full rounded-tl-none border-0 p-0 cursor-[var(--cds-cursor-interactive)] outline-none focus-visible:outline-hidden focus-visible:shadow-focus";function L9({pin:A,avatar:e,draft:t=!1,label:n,title:o,expanded:i,faded:r=!1,...a}){const{pinId:c,...g}=a,u={left:A.left,top:A.top,width:xs,height:xs,pointerEvents:t?"none":"auto",touchAction:"none",...A.flip?{borderRadius:"9999px 9999px 9999px 0"}:{},...r?{opacity:.7}:{}};return D.jsx("button",{type:"button","data-comment-pin":c,"aria-label":n,title:o,"aria-expanded":i,tabIndex:t?-1:void 0,className:Yt(_QA,t?"bg-fill-accent":"bg-surface-2 shadow-panel-sm"),style:u,...g,children:D.jsx("span",{className:"flex rounded-full bg-surface-1",children:e})})}function SR(A,e){return A.author.kind==="agent"?A.author.name||e.name:A.author.name||"Someone"}function PQA(A,e){const t=A.messages[0];return t?D.jsx(Xh,{name:SR(t,e),variant:t.author.kind==="agent"?"agent":"default",size:"sm"}):D.jsx(Xh,{name:"?",size:"sm"})}function jQA({comments:A,camera:e,viewport:t,place:n,highlight:o,anchorAt:i,movable:r,onMove:a,agent:c,revision:g,piles:u=!0,insets:I}){const C=(r??!0)&&!!(i||a),f=A.store(F=>F.available),B=A.store(F=>F.threads),Q=A.store(F=>F.active),d=A.store(F=>F.draft),y=A.store(F=>F.on),m=A.store(F=>F.showResolved),p=A.store(F=>F.listOpen),[w,b]=R.useState(null),N=R.useMemo(()=>{if(!f)return[];const F=[];for(const K of B){if(K.messages.length===0||K.status!=="open"&&!m&&K.id!==Q)continue;const _=A.anchorOf(K),P=n(_);P&&F.push({key:K.id,thread:K,anchor:_,state:P.state,screen:HK(e,P.world)})}if(d!==null){const K=n(d);K&&F.push({key:"draft",thread:null,anchor:d,state:K.state,screen:HK(e,K.world)})}return F},[f,B,Q,d,m,e,n,g,A]);if(!f||!y&&!Q&&d===null&&N.length===0)return null;const k=d!==null?"draft":Q,M=N.find(F=>F.key===k),x=M&&o?o(M.anchor):null,L=N.filter(F=>F.thread),G=u?RBA({points:L.map(F=>({id:F.key,x:F.screen.x,y:F.screen.y})),openId:Q,box:{left:0,top:0,width:t.width,height:t.height},top:0,floor:I?.top??0,foot:I?.bottom?I.bottom+8:0,reserveRight:p?RQA:0}):null,Y=L.filter(F=>!G?.piled.has(F.key)).map(F=>({...F,box:PQ(F.screen,t)})),J=UBA(Y.map(F=>({id:F.key,x:F.box.left,y:F.box.top,w:xs})),t.width,xs),U=F=>A.store.getState().setActive(F),T=M?.thread?M:void 0;return D.jsxs(D.Fragment,{children:[x?D.jsx("div",{"data-comment-target":"",className:Yt("pointer-events-none absolute",!x.area&&"rounded"),style:{...TQA(e,x),border:x.area?`1px dashed ${OK}`:`1.5px solid ${OK}`}}):null,D.jsxs(YE,{className:"pointer-events-none absolute inset-0 z-[3]",mark:"data-comment-layer",onEscape:()=>{const F=A.store.getState();return F.draft!==null||F.active?(F.setDraft(null),F.setActive(null),!0):!1},children:[Y.map(F=>{const K=F.thread,_=w?.id===K.id?w:null,P={...F.box,left:F.box.left+(J.get(F.key)??0)+(_?.x??0),top:F.box.top+(_?.y??0)};return D.jsx(qQA,{comments:A,thread:K,box:P,avatar:PQA(K,c),expanded:Q===K.id,detached:F.state==="detached",onDrag:j=>b(j?{id:K.id,...j}:null),movable:C,onDrop:j=>{const O={x:F.screen.x+j.x,y:F.screen.y+j.y};a?a(K.id,O):i&&A.move(K.id,i(YQA(e,O)))}},F.key)}),G?D.jsx("div",{style:{display:"contents",pointerEvents:"auto"},children:D.jsx(LBA,{piles:G,onOpen:F=>{const K=B.find(_=>_.id===F);K&&A.show(K)}})}):null,T?D.jsx(bR,{pin:PQ(T.screen,t),viewport:t,onEscape:()=>U(null),children:F=>D.jsx(U9,{comments:A,agent:c,thread:T.thread,state:T.state,maxHeight:F})},T.key):null,M&&!M.thread&&d!==null?D.jsxs(D.Fragment,{children:[D.jsx(L9,{pin:PQ(M.screen,t),draft:!0,label:"New comment",avatar:D.jsx(Xh,{name:A.viewerName(),size:"sm"})}),D.jsx(bR,{pin:PQ(M.screen,t),viewport:t,onEscape:()=>A.store.getState().setDraft(null),children:()=>D.jsx(zQA,{comments:A,agent:c,anchor:d})})]}):null]})]})}function qQA({comments:A,thread:e,box:t,avatar:n,expanded:o,detached:i,movable:r,onDrag:a,onDrop:c}){const g=R.useRef(null),u=R.useRef(!1),I=e.status==="resolved";return D.jsx(L9,{pinId:e.id,pin:t,avatar:n,expanded:o,faded:i,label:`Comment: ${e.label}${I?" (resolved)":""}`,title:i?"What this comment was on is gone":e.label,onPointerDown:C=>{if(C.button===0){g.current={x:C.clientX,y:C.clientY,moved:!1},u.current=!1;try{C.currentTarget.setPointerCapture(C.pointerId)}catch{}}},onPointerMove:C=>{const f=g.current;if(!f||!r||!A.canComment())return;const B=C.clientX-f.x,Q=C.clientY-f.y;!f.moved&&Math.hypot(B,Q)<KQA||(f.moved=!0,a({x:B,y:Q}))},onPointerUp:C=>{const f=g.current;g.current=null,f?.moved&&(u.current=!0,a(null),c({x:C.clientX-f.x,y:C.clientY-f.y}))},onClick:()=>{if(u.current){u.current=!1;return}const C=A.store.getState();C.setActive(C.active===e.id?null:e.id)}})}function WQA(A,e){const t=R.useRef(null);R.useLayoutEffect(()=>{const o=t.current,i=A.current;if(!o||!i)return;i.scrollTop=i.scrollHeight;const r=e.messages.at(-1);if(r&&r.id!==o.after&&r.author.kind==="agent"){const a=[...i.querySelectorAll('[data-cds-part="comment"]')].at(-1),c=a?i.getBoundingClientRect().top-a.getBoundingClientRect().top:0;if(c>0){i.scrollTop-=c,t.current=null;return}}o.at=i.scrollTop});const n=()=>{t.current=null};return{start:()=>{t.current={after:e.messages.at(-1)?.id,at:0}},regionProps:{onPointerDownCapture:n,onWheelCapture:o=>{o.deltaY<0&&n()},onScroll:o=>{const i=o.currentTarget,r=t.current;r&&Math.abs(i.scrollTop-r.at)>2&&i.scrollHeight-i.scrollTop-i.clientHeight>2&&n()}}}}function U9(A){return D.jsx(h9,{children:D.jsx(VQA,{...A})})}function VQA({comments:A,agent:e,thread:t,state:n,maxHeight:o,onClose:i}){const[r,a]=R.useState(!1),[c,g]=R.useState(!1),[u,I]=R.useState(!1),C=A.store(Y=>Y.statusChange),f=R.useId(),B=R.useRef(null),Q=WQA(B,t),d=A.store(Y=>Y.replies[t.id])??{text:"",send:!1},y=A.canSendToAgent()&&e.available,m=A.canComment(),[p,...w]=t.messages;if(!p)return null;const b=i??(()=>A.store.getState().setActive(null)),N=A.stateNote(n??A.stateOf(A.anchorOf(t))),k=`Send to ${e.name}`,M=A.canRemove()?[{label:"Delete thread",icon:"Trash",variant:"danger",onSelect:()=>a(!0)}]:[],x=t.status==="open"?t.agent?.status:void 0,L=x==="pending"?"queued":x==="delivered"?"working":void 0,G=Y=>A.store.getState().setReply(t.id,Y);return D.jsxs(I9,{expanded:!0,active:!0,onClose:b,labelledBy:f,maxHeight:o,scrollRef:B,scrollProps:Q.regionProps,className:"min-h-0 flex-1",reply:m&&D.jsx(uBA,{children:D.jsx(B9,{label:"Reply",placeholder:t.status==="resolved"?"Reply to reopen…":y&&d.send?"What do you want to edit?":void 0,value:d.text,onChange:Y=>G({...d,text:Y}),sendBox:y?{label:k,checked:d.send,onCheckedChange:Y=>G({...d,send:Y})}:void 0,busy:u,onSubmit:(Y,{send:J})=>{Q.start(),I(!0),A.reply(t.id,Y,{send:y&&J}).finally(()=>I(!1))},onCancel:b})}),children:[D.jsx(Vd,{nameId:f,authorName:SR(p,e),agent:p.author.kind==="agent",timestamp:UK(p.at),footnote:N??void 0,confirm:r?D.jsx(E9,{busy:c,onCancel:()=>a(!1),onDelete:()=>{g(!0),A.remove(t.id).finally(()=>g(!1))}}):void 0,actions:m||M.length>0?D.jsxs(Yx,{children:[m?D.jsx(f9,{resolved:t.status==="resolved",disabled:C!==null,onResolve:()=>{A.resolve(t.id,!0)}}):null,D.jsx(C9,{items:M,disabled:C!==null&&C.id!==t.id,waitReason:C?.id===t.id?N9:void 0})]}):void 0,children:hR(p.text)}),w.length>0||L?D.jsxs(gBA,{children:[w.map(Y=>D.jsx(Vd,{authorName:SR(Y,e),agent:Y.author.kind==="agent",timestamp:UK(Y.at),children:hR(Y.text)},Y.id)),L?D.jsx(Vd,{authorName:e.name,agent:!0,working:L,footnote:L==="queued"?bQA(e):t.agent?.drafted?x9(e.name).label:"Working…"}):null]}):null]})}function zQA(A){return D.jsx(h9,{children:D.jsx(XQA,{...A})})}function XQA({comments:A,agent:e,anchor:t,onCancel:n}){const o=A.store(I=>I.draftText),i=A.store(I=>I.sendNew),[r,a]=R.useState(!1),c=R.useRef(null),g=A.canSendToAgent()&&e.available;R.useEffect(()=>{c.current?.focus({preventScroll:!0})},[t]);const u=()=>n?n():A.store.getState().setDraft(null);return D.jsx(B9,{textareaRef:c,context:A.labelOf(t),value:o,onChange:I=>A.store.getState().setDraftText(I),sendBox:g?{label:`Send to ${e.name}`,checked:i,onCheckedChange:I=>A.store.getState().setSendNew(I)}:void 0,busy:r,onSubmit:(I,C)=>{r||(a(!0),A.create(t,I,{send:g&&C.send}).finally(()=>a(!1)))},onCancel:u})}function ZQA({comments:A,shortcut:e="C",side:t="bottom"}){return A.store(o=>o.available)?D.jsx(YE,{inline:!0,mark:"data-comments-button",children:D.jsx($QA,{comments:A,shortcut:e,side:t})}):null}function $QA({comments:A,shortcut:e,side:t}){const[n,o]=Tx(),i=A.store(C=>M9(C.threads)),r=A.store(C=>C.on),a=A.store(C=>C.listOpen),c=!r&&i>0,g=r?"Done commenting":i>0?`${i} open ${i===1?"comment":"comments"}`:"Comments",u=C=>{o(!1),A.store.getState().setListOpen(C)},I=a?{label:"Hide comments",onSelect:()=>u(!1)}:{label:"Show all comments",trailing:i,onSelect:()=>u(!0)};return D.jsxs("span",{className:"flex shrink-0 items-center",children:[A.canComment()?D.jsx(Cl,{content:g,shortcut:e,side:t,children:D.jsx($i,{variant:"ghost",iconOnly:!0,tooltip:!1,"aria-label":"Comments","aria-pressed":r,icon:D.jsxs("span",{className:"relative inline-flex",children:[D.jsx(xi,{name:r?"CommentFilled":"Comment",size:"sm"}),c?D.jsx("span",{"aria-hidden":!0,className:"absolute rounded-full bg-fill-accent",style:{top:-1,right:-2,width:6,height:6,boxShadow:"0 0 0 1.5px var(--cds-page-bg)"}}):null]}),onClick:()=>A.store.getState().setOn(!r)})}):null,D.jsxs(yE,{open:n,onOpenChange:o,modal:!1,children:[D.jsx(Cl,{content:"Comment options",disabled:n,side:t,children:D.jsx(DE,{render:D.jsx($i,{variant:"ghost","aria-label":"Comment options",style:{paddingInline:2},children:D.jsx(xi,{name:"CaretDown",size:"xs"})})})}),D.jsx(xx,{align:"end",children:D.jsx(a9,{items:[I]})})]})]})}const Kb=200,AdA=119,Gf=nn()(()=>({message:"",serial:0}));function edA(A){const e=A.replace(/\s+/g," ").trim();if(e.length<=Kb)return e;const t=e.slice(0,Kb).search(/\s+\S*$/);return`${t>=AdA?e.slice(0,t):e.slice(0,Kb-1).replace(/[\uD800-\uDBFF]$/,"")}…`}function pt(A){const e=edA(A);e&&Gf.setState(t=>({message:e,serial:t.serial+1}))}function tdA(){const A=Gf(t=>t.message),e=Gf(t=>t.serial);return D.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},children:D.jsx("span",{children:A},e)})}function ndA(A){return A&&/(^|\s)max-h-/.test(A)?void 0:{maxHeight:"var(--available-height)",overflowY:"auto"}}const TE=R.forwardRef(function({className:e,...t},n){return D.jsx("div",{ref:n,className:De("pointer-events-auto flex items-center gap-1 rounded-[12px] bg-chrome text-chrome-fg shadow-chrome",e),...t})});function Jx({className:A,vertical:e=!0}){return D.jsx("div",{"aria-hidden":"true",className:De(e?"mx-0.5 h-[18px] w-px":"my-1 h-px w-full","shrink-0 bg-chrome-line",A)})}const odA=A=>A?{[A]:""}:{};function bs({label:A,shortcut:e,side:t="bottom",children:n,disabled:o}){return D.jsxs(Nv,{disabled:o,children:[D.jsx(Rv,{render:n}),D.jsx(Mv,{children:D.jsx(Gv,{side:t,sideOffset:8,className:"z-[1000]",children:D.jsxs(Fv,{className:"flex max-w-80 items-center gap-1.5 rounded-[6px] bg-tip px-2 py-[5px] text-[13px] leading-[18px] text-tip-fg shadow-[0_1px_2px_rgb(11_11_11/0.06),0_2px_8px_rgb(11_11_11/0.08)] transition-opacity data-[ending-style]:opacity-0 data-[starting-style]:opacity-0",children:[D.jsx("span",{children:A}),e?D.jsx("kbd",{className:"rounded-[4px] bg-white/15 px-1 font-sans text-[12px] leading-4 text-tip-fg/80",children:e}):null]})})})]})}const idA={md:"h-7",lg:"h-8",xl:"h-9"},rdA={md:"w-7",lg:"w-8",xl:"w-9"},zi=R.forwardRef(function({pressed:e,square:t,size:n="md",className:o,type:i="button",...r},a){return D.jsx("button",{ref:a,type:i,"aria-pressed":e,className:De("inline-flex shrink-0 select-none items-center justify-center gap-1 whitespace-nowrap rounded-[8px] text-[14px] font-control leading-5 text-chrome-fg outline-none transition-colors duration-100 ease-out","hover:bg-chrome-hover focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-chrome-focus","disabled:pointer-events-none disabled:opacity-40",idA[n],t?rdA[n]:"px-[9px]",e&&"bg-chrome-pressed text-chrome-pressed-fg hover:bg-chrome-pressed",o),...r})}),Af=R.forwardRef(function({tip:e,shortcut:t,side:n,disabled:o,...i},r){const a=D.jsx(zi,{ref:r,disabled:o,...i});return D.jsx(bs,{label:e,shortcut:t,side:n,children:o?D.jsx("span",{className:"inline-flex",children:a}):a})}),ef=R.forwardRef(function({label:e,tip:t,icon:n,shortcut:o,tipSide:i="top",size:r="xl",className:a,...c},g){return D.jsx(bs,{label:t??e,shortcut:o,side:i,children:D.jsx(zi,{ref:g,square:!0,size:r,"aria-label":e,className:De("[&_svg]:size-[18px] [&_svg]:shrink-0",a),...c,children:n})})}),sdA="min-w-[128px] max-w-[320px] rounded-[14px] bg-chrome p-1.5 text-[14px] leading-5 font-control text-chrome-fg shadow-chrome-popup outline-none origin-[var(--transform-origin)] transition-[opacity,transform] duration-100 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0",adA="flex h-7 cursor-default select-none items-center gap-2 rounded-[8px] px-2.5 outline-none data-[highlighted]:bg-chrome-hover data-[popup-open]:bg-chrome-hover data-[disabled]:opacity-40";function cdA({trigger:A,children:e,side:t="bottom",align:n="start",className:o,tip:i,open:r,onOpenChange:a,sideOffset:c=6,mark:g,popupBase:u=sdA}){const I=D.jsx(DE,{render:A});return D.jsxs(yE,{open:r,onOpenChange:a?C=>a(C):void 0,children:[i?D.jsx(bs,{label:i.label,shortcut:i.shortcut,side:i.side??(t==="top"?"top":"bottom"),children:I}):I,D.jsx(Jv,{children:D.jsx(Ov,{side:t,align:n,sideOffset:c,className:"z-[1000]",children:D.jsx(Kv,{...odA(g),className:De(u,o),style:ndA(o),children:e})})})]})}function ldA({children:A,onSelect:e,shortcut:t,checked:n,disabled:o,danger:i,icon:r,title:a,description:c,closeOnClick:g}){return D.jsxs(JP,{className:De(adA,c!==void 0&&"h-auto min-h-7 items-start py-1.5",i&&"text-danger data-[highlighted]:bg-danger data-[highlighted]:text-white"),disabled:o,onClick:u=>{g!==!1&&wcA(u.nativeEvent),e?.()},closeOnClick:g,title:a,children:[n!==void 0?D.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:n?D.jsx(ju,{className:"size-4 text-chrome-accent",strokeWidth:2.25}):null}):null,r?D.jsx("span",{"data-chrome-icon":"",className:"flex size-4 shrink-0 items-center justify-center text-chrome-muted",children:r}):null,c!==void 0?D.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[D.jsx("span",{className:"truncate",children:A}),D.jsx("span",{className:"truncate text-[12px] leading-4 text-chrome-muted",children:c})]}):D.jsx("span",{className:"min-w-0 flex-1 truncate",children:A}),t?D.jsx("span",{className:"ml-6 max-w-40 shrink-0 truncate text-[13px] text-chrome-muted",children:t}):null]})}function Vc(){return typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent)}const $g=Vc()?"⌘":"Ctrl+",gdA=$g==="⌘"?"⇧":"Shift+";function udA(A,e,t){if(t<=0||e<0||e>=t)return null;switch(A){case"ArrowRight":case"ArrowDown":return(e+1)%t;case"ArrowLeft":case"ArrowUp":return(e-1+t)%t;case"Home":return 0;case"End":return t-1;default:return null}}function IdA(A){let e=!1;A.setCanRestore(A.roleMayRestore),A.report({history:!0});const t=()=>{A.history.list().then(o=>{e||A.setCanRestore(o.canRestore&&A.roleMayRestore)},()=>{})};t();const n=[A.history.onChange(t),A.onCommand(o=>{o.cmd==="history"&&A.toggle()})];return()=>{e=!0;for(const o of n)o();A.report({history:void 0})}}async function CdA(A,e,t,n=12){const o=t(Object.keys(await A.files(e))),i=[];let r=0;const a=async()=>{for(;r<o.length;){const c=o[r++],g=await A.read(e,c).catch(()=>null);g!==null&&i.push([c,g])}};return await Promise.all(Array.from({length:Math.min(n,o.length)},a)),i}const fdA="1.4.0";class zc extends Error{code;paths;retryable;constructor(e,t,n,o){super(t),this.name="ArtifactError",this.code=e,n&&(this.paths=n),o&&(this.retryable=!0)}}function EdA(A){return A==="owner"||A==="editor"}const tC={maxDocumentBytes:262144,maxDepth:32},PK={defaultMs:12e4,maxMs:6e5};function BdA(A,e={}){const t=e.timeoutMs??1e4,n=new Map;return Object.freeze({version:fdA,use:i=>{const r=n.get(i);if(r)return r;const a=new Promise(c=>{const g=setTimeout(()=>c(null),t);Promise.resolve().then(()=>A.get(i)).then(u=>{clearTimeout(g),c(u?Object.freeze(u):null)},()=>{clearTimeout(g),c(null)})});return n.set(i,a),a}})}function QdA(A,e){const t=globalThis.window?.openartifact;if(t)return t;const n=BdA(A,e);return Object.defineProperty(window,"openartifact",{value:n,configurable:!1,enumerable:!0,writable:!1}),n}const Xe={session:"_api/session",files:"_api/files",file:"_api/file",publish:"_api/publish",assets:"_api/assets",events:"_api/events",agentSend:"_api/agent/send",presence:"_api/presence",peers:"_api/peers",downloads:"_api/downloads",roomEmit:"_api/room/emit",dbGet:"_api/db/get",dbList:"_api/db/list",dbWrite:"_api/db/write",comments:"_api/comments",commentsCreate:"_api/comments/create",commentsReply:"_api/comments/reply",commentsEdit:"_api/comments/edit",commentsReact:"_api/comments/react",commentsResolve:"_api/comments/resolve",commentsMove:"_api/comments/move",commentsRemove:"_api/comments/remove",commentsSend:"_api/comments/send",history:"_api/history",historyFiles:"_api/history/files",historyFile:"_api/history/file",historyDiff:"_api/history/diff",historyRestore:"_api/history/restore",historyDismiss:"_api/history/dismiss",systemCopy:"_api/design/system-copy",mcpTools:"_api/mcp/tools",mcpCall:"_api/mcp/call",dataRefresh:"_api/data/refresh"},jQ={read:"_api/sheet/read",send:"_api/sheet/send",widget:"_api/sheet/widget",importFile:"_api/sheet/import"},ddA="sheet",hdA="sheetWalkthrough",Qa={session:"_api/doc/session",read:"_api/doc/read",call:"_api/doc/call",history:"_api/doc/history",version:"_api/doc/version",restore:"_api/doc/restore",importFile:"_api/doc/import",exportFile:"_api/doc/export"};function pdA(A,e,t){return e===401||e===403?"removed":e<200||e>=300||!t||t.id===A.id&&t.role===A.role?null:"changed"}async function Jb(A){let e={};try{e=await A.json()}catch{}const t=A.status===409?"conflict":A.status===403?"not_writer":A.status===404?"not_found":"unavailable";return new zc(e.code??t,e.message??`HTTP ${A.status}`,e.paths,e.retryable===!0)}function wdA(){const A=new Uint8Array(8);return crypto.getRandomValues(A),Array.from(A,e=>e.toString(16).padStart(2,"0")).join("")}function Y9(A={}){const e=new URL(A.base??"./",location.href),t=wdA(),n=(x,L)=>{const G=new URL(x,e);for(const[Y,J]of Object.entries(L??{}))G.searchParams.set(Y,J);return G.toString()},o=async(x,L,G)=>{let Y;try{Y=await fetch(n(x,G),L)}catch(J){throw new zc("unavailable",J instanceof Error?J.message:String(J))}if(!Y.ok)throw await Jb(Y);return await Y.json()},i=(x,L)=>o(x,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(L)}),r=new Map,a=(x,L)=>{for(const G of r.get(x)??[])G(L)},c=(x,L)=>{let G=r.get(x);return G||(G=new Set,r.set(x,G),I?.addEventListener(x,f)),G.add(L),p(),()=>G.delete(L)};let g=null,u=!1,I=null,C=null;const f=x=>{a(x.type,JSON.parse(x.data))},B=()=>{const x=new EventSource(n(Xe.events,{client:t}));I=x;for(const L of r.keys())x.addEventListener(L,f);x.onerror=()=>{m().then(L=>{L||x.readyState!==EventSource.CLOSED||I!==x||(I=null,C=setTimeout(()=>{C=null,p()},2e3))})}};let Q=!1,d=!1;const y=x=>{Q||(Q=!0,C&&clearTimeout(C),C=null,I?.close(),I=null,g?.close(),g=null,A.onAccessChange?A.onAccessChange(x):location.reload())},m=async()=>{if(Q)return!0;if(!w||d)return!1;d=!0;try{const x=(await w.catch(()=>null))?.viewer;if(!x)return!1;let L;try{L=await fetch(n(Xe.session),{cache:"no-store"})}catch{return!1}const G=L.ok?(await L.json().catch(()=>null))?.viewer:null,Y=pdA(x,L.status,G);return Y&&y(Y),Y!==null}finally{d=!1}};function p(){if(g||I||C||Q)return;if(typeof WebSocket>"u")return B();const x=new URL(n(Xe.events,{client:t}));x.protocol=x.protocol==="https:"?"wss:":"ws:";const L=new WebSocket(x);g=L,L.onopen=()=>{u=!0},L.onmessage=G=>{let Y;try{Y=JSON.parse(String(G.data))}catch{return}Y.event&&a(Y.event,Y.data)},L.onclose=()=>{if(g===L&&(g=null),!Q){if(!u)return B();m().then(G=>{G||g||I||C||(C=setTimeout(()=>{C=null,p()},2e3))})}}}let w=null;const b=()=>w??=o(Xe.session),N={async artifact(){const{artifact:x,stores:L}=await b();return{id:x.id,...L?.systemCopy?{systemCopy:(Y,J)=>o(Xe.systemCopy,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({namespace:Y,action:J})})}:{},title:async()=>(await o(Xe.session)).artifact.title,list:async()=>(await o(Xe.files)).files,readText:async Y=>new TextDecoder().decode(await k(Y)),readBytes:Y=>k(Y),publish:async Y=>{const J={files:Y,client:t};return o(Xe.publish,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(J)})},onChange:Y=>c("files",Y)}},async assets(){const{viewer:x}=await b();return EdA(x.role)?{upload:async(G,Y)=>o(Xe.assets,{method:"POST",headers:{"content-type":G.type||"application/octet-stream"},body:G},Y?.name?{name:Y.name}:void 0)}:null},async user(){const{viewer:x}=await b();return{me:async()=>x}},async agent(){return{send:async(L,G)=>{const Y={request:L,deliver:G?.deliver??"send"};return o(Xe.agentSend,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Y)})},status:async()=>(await o(Xe.session)).agent,onStatus:L=>c("agent",L)}},async room(){return{self:async()=>t,presence:async L=>{const G={client:t,patch:L};await o(Xe.presence,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(G)})},peers:async()=>(await o(Xe.peers)).peers,onPeers:L=>c("peers",L),emit:async(L,G)=>{const Y={client:t,topic:L,data:G};await i(Xe.roomEmit,Y)},onMessage:L=>c("room",L)}},async db(){const{stores:x}=await b();return x?.db?{get:async G=>(await o(Xe.dbGet,{cache:"no-store"},{path:G})).data,list:async G=>(await o(Xe.dbList,{cache:"no-store"},{collection:G})).documents,listing:async G=>{const{documents:Y,epoch:J,seq:U}=await o(Xe.dbList,{cache:"no-store"},{collection:G});return typeof J=="string"&&typeof U=="number"?{documents:Y,epoch:J,seq:U}:{documents:Y}},write:async G=>{const Y={writes:G,client:t},{epoch:J,seq:U,documents:T}=await i(Xe.dbWrite,Y);return typeof J=="string"&&typeof U=="number"&&T!==void 0?{epoch:J,seq:U,documents:T}:void 0},onChange:G=>c("db",G)}:null},async comments(){const{stores:x}=await b();if(!x?.comments)return null;const L=async(Y,J)=>(await i(Y,J)).thread;return{list:async()=>(await o(Xe.comments,{cache:"no-store"})).threads,create:Y=>L(Xe.commentsCreate,{input:Y}),reply:(Y,J,U)=>L(Xe.commentsReply,{threadId:Y,text:J,...U?.to?.length?{to:U.to}:{}}),edit:(Y,J,U,T)=>L(Xe.commentsEdit,{threadId:Y,messageId:J,text:U,...T?.to?{to:T.to}:{}}),react:(Y,J,U,T)=>L(Xe.commentsReact,{threadId:Y,messageId:J,emoji:U,on:T}),setResolved:(Y,J)=>L(Xe.commentsResolve,{threadId:Y,resolved:J}),move:(Y,J,U)=>L(Xe.commentsMove,{threadId:Y,anchor:J,...U?{location:U}:{}}),remove:async(Y,J)=>{await i(Xe.commentsRemove,{threadId:Y,...J?{messageId:J}:{}})},sendToAgent:(Y,J)=>L(Xe.commentsSend,{threadId:Y,...J?.unasked?{unasked:!0}:{}}),onChange:Y=>c("comments",Y)}},async doc(){const{stores:x}=await b();return x?.doc?{session:()=>i(Qa.session,{client:t}),read:G=>i(Qa.read,{tab:G}),call:G=>i(Qa.call,{...G,client:t}),history:G=>i(Qa.history,{tab:G}),version:(G,Y)=>i(Qa.version,{tab:G,rev:Y}),restore:G=>i(Qa.restore,G),importFile:(G,Y,J)=>o(Qa.importFile,{method:"POST",headers:{"content-type":"application/octet-stream"},body:Y},{name:G,...J?{tabName:J}:{}}),exportFile:async G=>{let Y;try{Y=await fetch(n(Qa.exportFile,{format:G.format,...G.tab?{tab:G.tab}:{},...G.paper?{paper:G.paper}:{}}),{cache:"no-store"})}catch(F){throw new zc("unavailable",F instanceof Error?F.message:String(F))}if(!Y.ok)throw await Jb(Y);const J=Y.headers.get("content-disposition")??"",U=decodeURIComponent(/filename\*=UTF-8''([^;]+)/.exec(J)?.[1]??"")||`doc.${G.format==="markdown"?"md":G.format}`;let T=[];try{T=JSON.parse(decodeURIComponent(Y.headers.get("x-doc-export-notes")??"%5B%5D"))}catch{}return{name:U,mime:Y.headers.get("content-type")??"application/octet-stream",bytes:new Uint8Array(await Y.arrayBuffer()),notes:T}},onFrame:G=>c("doc",G)}:null},async history(){const{stores:x}=await b();if(!x?.history)return null;const L=(Y,J)=>({n:String(Y),...J===void 0?{}:{path:J}});return{list:()=>o(Xe.history,{cache:"no-store"}),files:async Y=>(await o(Xe.historyFiles,{cache:"no-store"},L(Y))).files,read:async(Y,J)=>new TextDecoder().decode(await M(Xe.historyFile,L(Y,J))),readBytes:(Y,J)=>M(Xe.historyFile,L(Y,J)),diff:(Y,J)=>o(Xe.historyDiff,{cache:"no-store"},L(Y,J)),restore:(Y,J)=>i(Xe.historyRestore,{n:Y,...J?{paths:J}:{},client:t}),dismissNotice:async Y=>{await i(Xe.historyDismiss,{id:Y})},onChange:Y=>c("history",Y)}},async mcp(){const{viewer:x}=await b();return x.role!=="owner"?null:{callTool:async(G,Y,J,U)=>{const T=U?.signal;T?.throwIfAborted();const F={server:G,tool:Y,args:J,...U?.timeoutMs===void 0?{}:{timeoutMs:U.timeoutMs}};try{return await o(Xe.mcpCall,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(F),...T?{signal:T}:{}})}catch(K){throw T?.aborted?T.reason:K}},listTools:G=>o(Xe.mcpTools,{cache:"no-store"},G===void 0?void 0:{server:G})}},async sheet(){const{stores:x}=await b();if(!x?.sheet)return null;let L=Promise.resolve();return{read:Y=>i(jQ.read,Y),send:Y=>{const J=L.then(()=>i(jQ.send,Y));return L=J.catch(()=>{}),J},widget:Y=>i(jQ.widget,Y),importFile:(Y,J)=>o(jQ.importFile,{method:"POST",headers:{"content-type":Y.type||"application/octet-stream"},body:Y},{name:J}),onFrame:Y=>c(ddA,Y),onWalkthrough:Y=>c(hdA,Y)}},async downloads(){return{save:async({name:L,data:G})=>o(Xe.downloads,{method:"POST",headers:{"content-type":G.type||"application/octet-stream"},body:G},{name:L})}}};function k(x){return M(Xe.file,{path:x})}async function M(x,L){let G;try{G=await fetch(n(x,L),{cache:"no-store"})}catch(Y){throw new zc("unavailable",Y instanceof Error?Y.message:String(Y))}if(!G.ok)throw await Jb(G);return new Uint8Array(await G.arrayBuffer())}return{get(x){const L=N[x];return L?L():null}}}const ydA="[Artifact comment sent to agent]",DdA="[Artifact edit request sent to agent]",mdA="[Artifact task finished]",bdA="[Open Artifact] ",SdA={id:"open_artifact_id"},T9="#view-inline",NdA=1,RdA=1,MdA=/^[a-z][a-z0-9]{0,23}$/,kdA="may not have run: the artifact was updated before this call was answered",vdA=["quickstart","list","publish","read","open","call","adopt","delete","share"],xdA=["get","list","query","set","update","delete","str_replace","batch"],GdA=["read","reply","resolve","reopen","wait"],FdA=["share","export"],LdA={type:"object",properties:{action:{type:"string",enum:vdA,description:"What to do: quickstart, list, publish, read, open, call, adopt, delete or share. Omitted: publish."},intent:{type:"string",description:"quickstart: what is being made (design, design-system, slides, whiteboard, document, data, sheets, motion, page, other), or a few words about it."},scope:{type:"string",enum:["types","mine","all"],description:"list: types (the installed types), mine (this session's and this project's artifacts; the default) or all (every artifact)."},type:{type:"string",description:"list: only artifacts of this type (an id, or open-artifact://type/<id>). quickstart: the type already chosen (an id), to get its create call and steps without matching."},query:{type:"string",description:"list: only artifacts whose title contains this text."},limit:{type:"integer",description:"list: how many to return (default 50, at most 200)."},cursor:{type:"string",description:"list: the next_cursor of the previous page."},type_url:{type:"string",description:"publish without url: the type to create from (open-artifact://type/<id>, from quickstart). read without url: the type to describe."},title:{type:"string",description:"publish without url: the new artifact's name. quickstart: the name it will have, to find similar ones."},folder:{type:"string",description:"publish without url: the exact folder for the new artifact (absolute, or relative to the workspace), only when the person named one. Omitted: Open Artifact chooses the folder and its name. adopt: the folder to add."},location:{type:"string",enum:["home","workspace"],description:"publish without url: where the new artifact's folder goes when the person asked: workspace (in the project, under the working folder) or home (the person's Open Artifact folder). Omitted: what the person's settings say. The folder is named from the title either way."},url:{type:"string",description:"An artifact: open-artifact://artifact/<id>, as publish returned it."},files:{type:"object",additionalProperties:!0,description:'publish with url: files to write under the artifact root, as {"rel/path": "text"} or {"rel/path": {"content": "...", "encoding": "base64"}}; null deletes.'},if_match:{type:"object",additionalProperties:!0,description:'publish with url: {"rel/path": sha256 | null | "*"}. Write only while the file still has the sha256 you read, does not exist (null), or anyway ("*"). One mismatch writes nothing and returns the current versions.'},check:{type:"boolean",description:"publish with url: run the type's check action after writing; its result comes back as check."},capabilities:{type:"object",additionalProperties:!0,description:'publish, page artifacts only: the runtime capabilities the page may use, as {"db": true, "assets": true, ...}. Omitted: kept; {}: none; otherwise the whole set. With url it may be given without files.'},open:{type:"string",enum:["after_first_write","now","never"],description:"publish without url: after_first_write (the default) opens the page in your app once your first write lands; now opens it at once; never leaves it closed. Where your app cannot show pages by itself the result says so: open view_url in your app's built-in browser, if you have one."},related:{type:"boolean",description:"quickstart: list existing artifacts the recommended type can build on, such as design systems (default true)."},path:{type:"string",description:"read: one file or folder under the root (omitted: the record and the file list)."},paths:{type:"array",items:{type:"string"},description:"read: several files under the root at once."},name:{type:"string",description:"call: the action's name (check, upload, ...; read with url lists them)."},args:{type:"object",additionalProperties:!0,description:"call: the action's arguments. upload: {file: absolute path, name?, group?}."},panel:{type:"string",enum:FdA,description:"open: also open the page's Share panel (share), for the person to share it on the network, or its Export tab (export), for them to download a file."},cloud:{type:"string",description:"share: publish the artifact to this cloud remote (its name, as `open-artifact remote list` shows it). It works only on a remote the person set up and let agents publish to (agentMayPublish); otherwise the person publishes it, from the Share panel or with `open-artifact publish <id> --remote <name>`."}}},UdA={type:"object",properties:{action:{type:"string",enum:xdA,description:"What to do: get, list, query, set, update, delete, str_replace or batch."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>)."},collection:{type:"string",description:"The collection: alone for list / query (query needs it), with doc_id for one document."},doc_id:{type:"string",description:"With collection: the document to get / set / update / delete / str_replace."},path:{type:"string",description:"collection/doc_id, instead of the two."},data:{type:"object",additionalProperties:!0,description:"set / update: the document's fields."},file_path:{type:"string",description:"set / update: a JSON file holding the fields, instead of data."},if_match:{description:'set / update / delete / str_replace: the sha256 get returned (write only if unchanged), null (only if it does not exist) or "*" (replace whatever is there).'},field:{type:"string",description:"str_replace: the text field, as a dot path (body, notes.text)."},old:{type:"string",description:"str_replace: the passage to replace; it must occur exactly once."},new:{type:"string",description:"str_replace: the passage that replaces it."},where:{type:"array",items:{type:"object",additionalProperties:!0},description:"query: [{field, op, value}], all must hold. op: ==, !=, <, <=, >, >=, in, not-in (up to 30 values), array-contains."},order_by:{type:"object",additionalProperties:!0,description:'query: {field, dir: "asc" | "desc"}.'},limit:{type:"integer",description:"list / query: how many documents (default 100, at most 1000)."},cursor:{type:"string",description:"list / query: the next_cursor of the previous page."},out_file:{type:"string",description:"get / list / query: write the result to this JSON file (absolute, or relative to the workspace) and return only its path and counts."},writes:{type:"array",items:{type:"object",additionalProperties:!0},description:"batch: [{op: set|update|delete|str_replace, path | collection+doc_id, data | file_path, if_match?, field?, old?, new?}], at most 500."}},required:["action","url"]},YdA={type:"object",properties:{action:{type:"string",enum:GdA,description:"What to do: read, reply, resolve, reopen or wait."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>). wait: optional."},thread_id:{type:"string",description:'reply / resolve / reopen: the thread (after ";thread=" in the message).'},text:{type:"string",description:"reply: the answer."},resolve:{type:"boolean",description:"reply: resolve the thread too."},all:{type:"boolean",description:"read: resolved threads too."},since:{type:"string",description:"read: only threads with a message at or after this time (ISO 8601)."},acknowledge_duplicate:{type:"boolean",description:"reply: send the same text as your last reply in this thread again, on purpose."},timeout_ms:{type:"number",description:"wait: how long (default 600000)."}},required:["action"]},jK={Artifact:LdA,ArtifactData:UdA,ArtifactComments:YdA},TdA={Artifact:["Make and change artifacts: typed folders of files that open as live pages the person can view, edit, comment on and export. Actions:","- quickstart {intent, type?}: call first for a new artifact; recommends a type (or takes the one given) and returns the call that creates it, the steps for this app and similar artifacts that already exist.",'- list {scope: "mine" | "all" | "types", type?, query?}: find existing artifacts, or the installed types.',"- publish {type_url, title, folder?, open?}: create an artifact; the result carries its root folder and the type's instructions. publish {url, files, if_match?, check?}: write files when you have no file tools of your own. A page artifact also takes capabilities (on create or write): the runtime capabilities its page may use.","- read {url, path? | paths?}: the artifact's record, files and actions, or some of its files with their sha256. read {type_url}: a type's instructions, before creating.",`- open {url, panel?}: show it to the person in the computer's browser (or the app, when it shows pages), once its content is written. When your app has a built-in browser, open view_url there instead. panel "share" or "export" opens its Share panel or Export tab for them.`,"- call {url, name, args?}: run one of the type's actions (check, upload, ...). A long one answers {task, pending: true}; its result comes later as a message.","- adopt {url | folder}: take over an artifact, or add an existing folder. Only when the person asks.","- share {url}: whether it is shared on the local network, and its links. Only the person changes that, in the page's Share panel.","- delete {url}: forget an artifact; its folder stays. Only when the person asks."].join(`
36
36
  `),ArtifactData:'Read and write the document store of an artifact whose type keeps one (its instructions say so). get, list and query read documents with their sha256; set, update, delete, str_replace and batch write them. update merges fields, and {"__delete__": true} removes one; str_replace changes one passage of a long text field. Replacing or deleting an existing document needs if_match: the sha256 you read, or "*". Your writes show live on open pages.',ArtifactComments:`Comments the person leaves on their artifact's page, kept in the artifact's own folder on this computer (no outside service). read lists the threads; reply answers one (thread_id is after ";thread=" in the message), with resolve: true when it is done; resolve and reopen change a thread's state. A thread sent to you is the person asking for your answer in it, so replying there is what they asked for. Answer only threads sent to you, in one or two lines. wait blocks until the next message for this session: use it only when nothing else can wake you.`},qK={Artifact:{title:"Artifact",openWorldHint:!1},ArtifactData:{title:"Artifact data",openWorldHint:!1},ArtifactComments:{title:"Artifact comments",destructiveHint:!1,openWorldHint:!1}},KdA={Artifact:{quickstart:"read",list:"read",read:"read",publish:"write",call:"write",open:"ui",delete:"remove",adopt:"remove",share:"person"},ArtifactData:{get:"read",list:"read",query:"read",set:"write",update:"write",str_replace:"write",batch:"write",delete:"write"},ArtifactComments:{read:"read",wait:"read",reply:"write",resolve:"write",reopen:"write"}},JdA={Artifact:["publish","open","call","share"],ArtifactData:["get","list","query","set","update","str_replace","batch","delete"],ArtifactComments:["read","reply","resolve","reopen"]};function HdA(A={any:!1,actions:!1}){return Object.keys(jK).map(e=>{const t=e==="Artifact"?A.any:A.actions;return{name:e,description:TdA[e],inputSchema:jK[e],annotations:t?{...qK[e],openWorldHint:!0}:qK[e],actions:KdA[e],remoteActions:[...JdA[e]]}})}HdA();const OdA=300,_dA=12,WK=["Artifact","ArtifactData","ArtifactComments"];function La(A,e=OdA){const t=String(A??"").replace(/[<>]/g,"").replace(/\s+/g," ").trim();return t.length>e?`${t.slice(0,e-1).trimEnd()}…`:t}function PdA(A){const e=La(A,Number.MAX_SAFE_INTEGER),t=e.search(/[.!?。!?](\s|$)/);return t>=0?e.slice(0,t+1):e}function jdA(A){const e=La(A,24);return/^[a-z0-9]{1,5}$/i.test(e)?e.toUpperCase():e}const VK=A=>!A||/[.!?。!?…]$/.test(A)?A:`${A}.`;function qdA(A,e=!1){const t=La(A.title,80)||A.id;if(e)return`- ${A.id}: ${t}`;const n=La(A.when)||La(PdA(A.description)),o=(A.exports??[]).map(jdA).filter(Boolean),i=[VK(t),VK(n),o.length?`Exports: ${o.join(", ")}.`:""].filter(Boolean);return`- ${A.id}: ${i.join(" ")}`}const WdA="Open Artifact lets you make artifacts: typed folders of files (a slide deck, a design canvas, a whiteboard, a data dashboard, a spreadsheet, a doc, an animated motion piece, a free HTML page and more) that open as live pages the person can view, edit, comment on and export. You make and change them with the Artifact, ArtifactData and ArtifactComments tools.",VdA=`<where_output_goes>
37
37
  Decide where your output will live before you make anything.
38
38
  - Something the person will read once and move on from (an answer, an explanation, a summary, a short report) goes in your reply, however long it is. A diagram or chart that explains your answer goes in the reply too, when you can show one there.
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
6
6
  <title>Data</title>
7
- <script type="module" crossorigin src="./assets/index-DcaVBiGm.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-CMhqwoHV.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="./assets/index-Blfs4lTl.css">
9
9
  </head>
10
10
  <body>
@@ -53,7 +53,7 @@ class Component extends DCLogic {}
53
53
  `};const n=A.text.match(/^\s*/)?.[0].length??0;return{start:n,end:n,text:`<helmet>
54
54
  ${e.trim()}
55
55
  </helmet>
56
- `}}function hw(A,e){if(e.kind==="source")return{source:e.text,created:[]};const t=_o(A);if(e.kind==="props"){if(!t.script||!t.props)return null;const l={...t.props};for(const[c,u]of Object.entries(e.values)){const C=l[c];!C||c==="$preview"||!("editor"in C)||(l[c]={...C,default:u})}return{source:Wz(t,l),created:[]}}if(e.kind==="scriptText"){if(!t.script)return null;const l=t.script.body.text,c=qm(l),u=c.filter(Q=>Q.value===e.value),C=c.find(Q=>Q.start===e.start&&Q.end===e.end&&Q.value===e.value)??(u.length===1?u[0]:void 0);if(!C)return null;const B=l.slice(0,C.start)+wV(e.text,C.quote)+l.slice(C.end);return B===l?null:{source:Vz(t,B),created:[]}}if(!t.template)return null;const n=Er(t.template.text);let o;try{switch(e.kind){case"look":o=J5(n,e.look);break;case"style":{const l=Aa(n,e.targets);if(!l)return null;o=l.flatMap(c=>$d(n,c,e.patch));break}case"styles":{const l=Aa(n,e.edits.map(c=>c.target));if(!l)return null;o=l.flatMap((c,u)=>$d(n,c,e.edits[u].patch));break}case"attr":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;o=Bw(n,l,e.name,e.value);break}case"text":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;o=NV(l,e.text);break}case"richText":{const l=ut(n,e.target.tid,e.target.path);if(!l||!Dc(l))return null;const c=fV(e.html);if(o=[{start:l.openEnd,end:l.closeStart,text:c}],l.tag==="p"&&EV(c)){const u=l.start+1;o.push({start:u,end:u+l.rawTag.length,text:"div"});const C=l.closeStart+2;o.push({start:C,end:C+l.rawTag.length,text:"div"})}break}case"wrapText":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;const c=rU(l,n.text,e.inline);if(!c.length)return null;o=c.flatMap(u=>[{start:u.start,end:u.start,text:"<span>"},{start:u.end,end:u.end,text:"</span>"}]);break}case"importText":{const l=ut(n,e.target.tid,e.target.path);if(!l||l.tag!=="x-import")return null;const c=cU(e,e.text,gU(l,yU(A)));if(c.kind!=="commit")return null;o=c.key==="__text"?RV(l,fr(c.text)):Bw(n,l,c.key.slice(1),c.text);break}case"linkText":{const l=ut(n,e.target.tid,e.target.path);if(!l||l.closeStart<=l.openEnd||l.tag==="a")return null;o=[{start:l.openEnd,end:l.openEnd,text:`<a ${lU("href",e.href)}>`},{start:l.closeStart,end:l.closeStart,text:"</a>"}];break}case"remove":{const l=Aa(n,e.targets);if(!l)return null;o=IU(n,l);break}case"duplicate":{const l=Aa(n,e.targets);if(!l)return null;o=vV(n,l);break}case"insert":{const l=e.target?ut(n,e.target.tid,e.target.path):null;if(e.target&&!l)return null;o=eB(n,l,e.position,e.html),e.helmet&&o.push(mM(n,e.helmet));break}case"move":{const l=Aa(n,e.targets),c=ut(n,e.target.tid,e.target.path);if(!l||!c)return null;o=GV(n,l,c,e.position);break}case"wrap":{const l=Aa(n,e.targets);if(!l||l.length===0)return null;o=FV(n,l,e.open,e.close);break}case"unwrap":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;o=KV(n,l);break}case"replace":{const l=Aa(n,e.edits.map(c=>c.target));if(!l||!l.length)return null;o=l.map((c,u)=>({start:c.start,end:c.end,text:e.edits[u].html})),e.helmet&&o.push(mM(n,e.helmet));break}}}catch{return null}const s=Pm(n.text,o),r=Er(s);let g=e.kind==="style"||e.kind==="styles"||e.kind==="attr"||e.kind==="text"||e.kind==="importText"?[]:H5(r,T5(o)).filter(l=>!O5(r.elements[l.tid]));if(e.kind==="richText"){const l=ut(n,e.target.tid,e.target.path),c=l?r.elements.find(Q=>Q.start===l.start):void 0,u=[],C=Q=>{for(const E of Ge(Q.children))E.tag==="a"&&u.push(E),C(E)};c&&e.link!=null&&C(c);const B=e.link!=null?u[e.link]:void 0;g=B?[kU(r,B)]:[]}return{source:zz(t,s),created:g}}function j5(A,e){let t=A;const n=[];for(const o of e){const s=hw(t,o);s&&(t=s.source,n.push(o))}return{source:t,kept:n,dropped:e.length-n.length}}const DM=A=>{if(A===null)return{canvas:tB(),error:null};try{return{canvas:mQ(JSON.parse(A)),error:null}}catch(e){return{canvas:tB(),error:e instanceof Error?e.message:String(e)}}},ri=(A,e)=>[...A.slice(-199),e],oA=ao()((A,e)=>({status:"loading",error:null,title:"",readOnly:!1,canvas:tB(),canvasSaved:tB(),canvasHash:null,canvasError:null,boards:{},trash:[],undo:[],redo:[],edits:0,save:"saved",revision:0,gesture:null,load({title:t,readOnly:n,canvas:o,boards:s}){const r=DM(o.text),g={};for(const[l,c]of Object.entries(s))g[l]={source:c.text,saved:c.text,hash:c.hash,pending:[]};A({status:"ready",title:r.canvas.title||t,readOnly:n,canvas:r.canvas,canvasSaved:r.canvas,canvasHash:o.hash,canvasError:r.error,boards:g,save:n?"readonly":"saved"})},fail(t){A({status:"error",error:t})},editBoard(t,n,o={}){const s=e(),r=s.boards[t];if(s.readOnly||!r?.source)return null;const g=hw(r.source,n);if(!g||g.source===r.source)return g;const l={source:g.source,pending:[...r.pending,n]},c=s.undo[s.undo.length-1],u=o.coalesce&&c?.scope==="board"&&c.path===t&&c.key===o.coalesce&&c.after.source===r.source,C=u?c.before:{source:r.source,pending:r.pending},B={scope:"board",path:t,before:C,after:l,...o.coalesce?{key:o.coalesce}:{}};return A({boards:{...s.boards,[t]:{...r,...l}},undo:u?[...s.undo.slice(0,-1),B]:ri(s.undo,B),redo:[],edits:s.edits+1,revision:s.revision+1}),g},updateCanvas(t){const n=e();if(n.readOnly||n.canvasError)return;const o=t(n.canvas);o!==n.canvas&&A({canvas:o,...n.gesture?{}:{undo:ri(n.undo,{scope:"canvas",before:n.canvas,after:o}),redo:[]},revision:n.revision+1})},beginGesture(){e().gesture||A({gesture:e().canvas})},endGesture(){const{gesture:t,canvas:n,undo:o}=e();t&&A({gesture:null,...t!==n?{undo:ri(o,{scope:"canvas",before:t,after:n}),redo:[]}:{}})},createBoard(t,n,o){const s=e();if(s.readOnly)return;const r=s.boards[t],g={...s.canvas,boards:{...s.canvas.boards,[t]:o},order:[...s.canvas.order.filter(l=>l!==t),t]};A({boards:{...s.boards,[t]:{source:n,saved:r?.saved??null,hash:r?.hash??null,pending:[]}},canvas:g,trash:s.trash.filter(l=>l!==t),undo:ri(s.undo,{scope:"canvas",before:s.canvas,after:g}),redo:[],edits:s.edits+1,revision:s.revision+1})},deleteBoards(t){const n=e();if(n.readOnly||t.length===0)return;const o={...n.canvas.boards};for(const r of t)delete o[r];const s={...n.canvas,boards:o,order:n.canvas.order.filter(r=>!t.includes(r))};A({canvas:s,trash:[...new Set([...n.trash,...t])],undo:ri(n.undo,{scope:"canvas",before:n.canvas,after:s}),redo:[],edits:n.edits+1,revision:n.revision+1})},editBoards(t,n){const o=e();if(o.readOnly)return 0;const s={...o.boards},r=[];for(const g of t){const l=s[g];if(!l?.source)continue;const c=hw(l.source,n);if(!c||c.source===l.source)continue;const u={source:c.source,pending:[...l.pending,n]};s[g]={...l,...u},r.push({scope:"board",path:g,before:{source:l.source,pending:l.pending},after:u})}return r.length&&A({boards:s,undo:ri(o.undo,{scope:"boards",changes:r}),redo:[],edits:o.edits+1,revision:o.revision+1}),r.length},undoLast(){const t=e(),n=t.undo[t.undo.length-1];if(!n||t.readOnly)return null;if(n.scope==="canvas"){const o=Nh(n.after,n.before,t.canvas);A({canvas:o,undo:t.undo.slice(0,-1),redo:ri(t.redo,n),revision:t.revision+1})}else{const o={...t.boards};for(const s of n.scope==="board"?[n]:n.changes){if(!o[s.path])return null;o[s.path]={...o[s.path],...s.before}}A({boards:o,undo:t.undo.slice(0,-1),redo:ri(t.redo,n),revision:t.revision+1})}return n},redoLast(){const t=e(),n=t.redo[t.redo.length-1];if(!n||t.readOnly)return null;if(n.scope==="canvas"){const o=Nh(n.before,n.after,t.canvas);A({canvas:o,redo:t.redo.slice(0,-1),undo:ri(t.undo,n),revision:t.revision+1})}else{const o={...t.boards};for(const s of n.scope==="board"?[n]:n.changes){if(!o[s.path])return null;o[s.path]={...o[s.path],...s.after}}A({boards:o,redo:t.redo.slice(0,-1),undo:ri(t.undo,n),revision:t.revision+1})}return n},remoteBoard(t,n,o){const s=e(),r=s.boards[t],g=c=>c.filter(u=>u.scope==="canvas"||(u.scope==="board"?u.path!==t:!u.changes.some(C=>C.path===t)));if(n===null)return r&&A({boards:{...s.boards,[t]:{...r,saved:null,hash:null,...r.pending.length?{}:{source:null}}}}),0;const l=r?.pending.length?j5(n,r.pending):{source:n,kept:[],dropped:0};return A({boards:{...s.boards,[t]:{source:l.source,saved:n,hash:o,pending:l.kept}},undo:g(s.undo),redo:g(s.redo),...l.kept.length?{revision:s.revision+1}:{}}),l.dropped},remoteCanvas(t,n){const o=e(),s=DM(t);if(s.error){A({canvasError:s.error,canvasHash:n});return}const r=o.canvas!==o.canvasSaved,g=r?Nh(o.canvasSaved,o.canvas,s.canvas):s.canvas;A({canvas:g,canvasSaved:s.canvas,canvasHash:n,canvasError:null,title:s.canvas.title||o.title,...r?{revision:o.revision+1}:{}})},acknowledge(t,n){const o=e(),s={...o.boards};for(const[r,{source:g,pendingCount:l}]of Object.entries(t.boards)){const c=s[r];!c||!(r in n)||(s[r]={...c,saved:g,hash:n[r]??null,pending:c.pending.slice(l)})}for(const r of t.deleted){const g=s[r];g&&(s[r]={...g,saved:null,hash:null})}A({boards:s,trash:o.trash.filter(r=>!t.deleted.includes(r)),...t.canvas&&"canvas.json"in n?{canvasSaved:t.canvas.canvas,canvasHash:n["canvas.json"]??null}:{}})},setSave(t){e().save!==t&&A({save:t})},setTitle(t){A({title:t})}}));function oB(A){return A.readOnly?!1:A.canvas!==A.canvasSaved||A.trash.some(e=>A.boards[e]?.hash)?!0:Object.entries(A.boards).some(([e,t])=>t.source!==null&&xU(A,e,t))}function xU(A,e,t){return t.source===null?!1:t.source!==t.saved?!0:t.hash===null&&e in A.canvas.boards}const Ta=.01,zI=8,Rn={kind:"none"},q5=[1.5,3,5,8],MU="mc-toolbar/top";function P5(){try{return typeof localStorage>"u"||localStorage.getItem(MU)!=="0"}catch{return!0}}const X=ao()((A,e)=>({camera:{x:0,y:0,zoom:1},page:null,tool:"select",selection:Rn,hover:null,peek:null,textEdit:null,noteEdit:null,mode:"canvas",focused:null,focusedExportWidth:null,playing:null,panel:"properties",panelOpen:!1,frames:{},layoutTick:0,overrides:{},composer:!1,spacePan:!1,pen:{stroke:3,dash:"solid"},findOpen:!1,toolbarTop:P5(),crop:null,errorsOpen:!1,closedNotices:{},unsentFix:null,setCamera(t){const n=Math.min(zI,Math.max(Ta,t.zoom));A({camera:{...t,zoom:n}})},setPage(t){e().page!==t&&A({page:t,playing:null,selection:Rn,hover:null,peek:null,crop:null})},setTool(t){A({tool:t,playing:null})},select(t){A({selection:t,playing:null,noteEdit:null,...e().crop?{crop:null}:{}})},setHover(t){const n=e().hover;n?.board===t?.board&&n?.tid===t?.tid&&n?.instance===t?.instance||A({hover:t})},setPeek(t){e().peek!==t&&A({peek:t})},setTextEdit(t){A({textEdit:t})},patchTextEdit(t){const{textEdit:n}=e();n&&A({textEdit:{...n,...t}})},setNoteEdit(t){A({noteEdit:t})},focus(t){A(t?{mode:"focused",focused:t,playing:null,hover:null}:{mode:"canvas",focused:null})},play(t){A({playing:t,hover:null,selection:Rn,tool:"select",noteEdit:null,textEdit:null})},setPanel(t,n=!0){A({panel:t,panelOpen:n})},togglePanel(){A({panelOpen:!e().panelOpen})},frame(t,n){const o=e().frames,s=o[t]??{booted:!1,errors:[],size:null};A({frames:{...o,[t]:{...s,...n}},layoutTick:e().layoutTick+1})},dropFrame(t){const{[t]:n,...o}=e().frames;A({frames:o})},parkFrame(t){const n=e().frames[t];if(!n)return;const o=structuredClone(n.errors),s=n.size?structuredClone(n.size):null;A({frames:{...e().frames,[t]:{booted:!1,errors:o,size:s}}})},tick(){A({layoutTick:e().layoutTick+1})},setOverride(t,n,o){const s=e().overrides;A({overrides:{...s,[t]:{...s[t]??{},[n]:o}}})},clearOverrides(t){const{[t]:n,...o}=e().overrides;A({overrides:o})},setComposer(t){A({composer:t})},setPen(t){A({pen:{...e().pen,...t}})},setSpacePan(t){e().spacePan!==t&&A({spacePan:t})},setFindOpen(t){e().findOpen!==t&&A({findOpen:t})},setToolbarTop(t){try{localStorage.setItem(MU,t?"1":"0")}catch{}A({toolbarTop:t})},setCrop(t){A({crop:t})},setErrorsOpen(t){e().errorsOpen!==t&&A({errorsOpen:t})},setClosedNotices(t){e().closedNotices!==t&&A({closedNotices:t})},setUnsentFix(t){A({unsentFix:t})}}));function Ul(A,e,t){return{x:(e-A.x)/A.zoom,y:(t-A.y)/A.zoom}}const z5="1.4.0";class ec extends Error{code;paths;retryable;constructor(e,t,n,o){super(t),this.name="ArtifactError",this.code=e,n&&(this.paths=n),o&&(this.retryable=!0)}}function bM(A,e){if(!A||typeof A!="object")return!1;const t=A;return t.name!=="ArtifactError"||typeof t.code!="string"?!1:e===void 0||t.code===e}function V5(A){return A==="owner"||A==="editor"}const SM={defaultMs:12e4,maxMs:6e5};function Z5(A,e={}){const t=e.timeoutMs??1e4,n=new Map;return Object.freeze({version:z5,use:s=>{const r=n.get(s);if(r)return r;const g=new Promise(l=>{const c=setTimeout(()=>l(null),t);Promise.resolve().then(()=>A.get(s)).then(u=>{clearTimeout(c),l(u?Object.freeze(u):null)},()=>{clearTimeout(c),l(null)})});return n.set(s,g),g}})}function W5(A,e){const t=globalThis.window?.openartifact;if(t)return t;const n=Z5(A,e);return Object.defineProperty(window,"openartifact",{value:n,configurable:!1,enumerable:!0,writable:!1}),n}async function eD(A){const e=globalThis.window?.openartifact;if(!e)return null;try{return await e.use(A)}catch{return null}}const Ne={session:"_api/session",files:"_api/files",file:"_api/file",publish:"_api/publish",assets:"_api/assets",events:"_api/events",agentSend:"_api/agent/send",presence:"_api/presence",peers:"_api/peers",downloads:"_api/downloads",roomEmit:"_api/room/emit",dbGet:"_api/db/get",dbList:"_api/db/list",dbWrite:"_api/db/write",comments:"_api/comments",commentsCreate:"_api/comments/create",commentsReply:"_api/comments/reply",commentsEdit:"_api/comments/edit",commentsReact:"_api/comments/react",commentsResolve:"_api/comments/resolve",commentsMove:"_api/comments/move",commentsRemove:"_api/comments/remove",commentsSend:"_api/comments/send",history:"_api/history",historyFiles:"_api/history/files",historyFile:"_api/history/file",historyDiff:"_api/history/diff",historyRestore:"_api/history/restore",historyDismiss:"_api/history/dismiss",systemCopy:"_api/design/system-copy",mcpTools:"_api/mcp/tools",mcpCall:"_api/mcp/call",dataRefresh:"_api/data/refresh"},vu={read:"_api/sheet/read",send:"_api/sheet/send",widget:"_api/sheet/widget",importFile:"_api/sheet/import"},_5="sheet",X5="sheetWalkthrough",Vs={session:"_api/doc/session",read:"_api/doc/read",call:"_api/doc/call",history:"_api/doc/history",version:"_api/doc/version",restore:"_api/doc/restore",importFile:"_api/doc/import",exportFile:"_api/doc/export"};function $5(A,e,t){return e===401||e===403?"removed":e<200||e>=300||!t||t.id===A.id&&t.role===A.role?null:"changed"}async function Uh(A){let e={};try{e=await A.json()}catch{}const t=A.status===409?"conflict":A.status===403?"not_writer":A.status===404?"not_found":"unavailable";return new ec(e.code??t,e.message??`HTTP ${A.status}`,e.paths,e.retryable===!0)}function AZ(){const A=new Uint8Array(8);return crypto.getRandomValues(A),Array.from(A,e=>e.toString(16).padStart(2,"0")).join("")}function NU(A={}){const e=new URL(A.base??"./",location.href),t=AZ(),n=(F,G)=>{const K=new URL(F,e);for(const[R,Y]of Object.entries(G??{}))K.searchParams.set(R,Y);return K.toString()},o=async(F,G,K)=>{let R;try{R=await fetch(n(F,K),G)}catch(Y){throw new ec("unavailable",Y instanceof Error?Y.message:String(Y))}if(!R.ok)throw await Uh(R);return await R.json()},s=(F,G)=>o(F,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(G)}),r=new Map,g=(F,G)=>{for(const K of r.get(F)??[])K(G)},l=(F,G)=>{let K=r.get(F);return K||(K=new Set,r.set(F,K),C?.addEventListener(F,Q)),K.add(G),w(),()=>K.delete(G)};let c=null,u=!1,C=null,B=null;const Q=F=>{g(F.type,JSON.parse(F.data))},E=()=>{const F=new EventSource(n(Ne.events,{client:t}));C=F;for(const G of r.keys())F.addEventListener(G,Q);F.onerror=()=>{x().then(G=>{G||F.readyState!==EventSource.CLOSED||C!==F||(C=null,B=setTimeout(()=>{B=null,w()},2e3))})}};let h=!1,p=!1;const b=F=>{h||(h=!0,B&&clearTimeout(B),B=null,C?.close(),C=null,c?.close(),c=null,A.onAccessChange?A.onAccessChange(F):location.reload())},x=async()=>{if(h)return!0;if(!m||p)return!1;p=!0;try{const F=(await m.catch(()=>null))?.viewer;if(!F)return!1;let G;try{G=await fetch(n(Ne.session),{cache:"no-store"})}catch{return!1}const K=G.ok?(await G.json().catch(()=>null))?.viewer:null,R=$5(F,G.status,K);return R&&b(R),R!==null}finally{p=!1}};function w(){if(c||C||B||h)return;if(typeof WebSocket>"u")return E();const F=new URL(n(Ne.events,{client:t}));F.protocol=F.protocol==="https:"?"wss:":"ws:";const G=new WebSocket(F);c=G,G.onopen=()=>{u=!0},G.onmessage=K=>{let R;try{R=JSON.parse(String(K.data))}catch{return}R.event&&g(R.event,R.data)},G.onclose=()=>{if(c===G&&(c=null),!h){if(!u)return E();x().then(K=>{K||c||C||B||(B=setTimeout(()=>{B=null,w()},2e3))})}}}let m=null;const M=()=>m??=o(Ne.session),N={async artifact(){const{artifact:F,stores:G}=await M();return{id:F.id,...G?.systemCopy?{systemCopy:(R,Y)=>o(Ne.systemCopy,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({namespace:R,action:Y})})}:{},title:async()=>(await o(Ne.session)).artifact.title,list:async()=>(await o(Ne.files)).files,readText:async R=>new TextDecoder().decode(await v(R)),readBytes:R=>v(R),publish:async R=>{const Y={files:R,client:t};return o(Ne.publish,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Y)})},onChange:R=>l("files",R)}},async assets(){const{viewer:F}=await M();return V5(F.role)?{upload:async(K,R)=>o(Ne.assets,{method:"POST",headers:{"content-type":K.type||"application/octet-stream"},body:K},R?.name?{name:R.name}:void 0)}:null},async user(){const{viewer:F}=await M();return{me:async()=>F}},async agent(){return{send:async(G,K)=>{const R={request:G,deliver:K?.deliver??"send"};return o(Ne.agentSend,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(R)})},status:async()=>(await o(Ne.session)).agent,onStatus:G=>l("agent",G)}},async room(){return{self:async()=>t,presence:async G=>{const K={client:t,patch:G};await o(Ne.presence,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(K)})},peers:async()=>(await o(Ne.peers)).peers,onPeers:G=>l("peers",G),emit:async(G,K)=>{const R={client:t,topic:G,data:K};await s(Ne.roomEmit,R)},onMessage:G=>l("room",G)}},async db(){const{stores:F}=await M();return F?.db?{get:async K=>(await o(Ne.dbGet,{cache:"no-store"},{path:K})).data,list:async K=>(await o(Ne.dbList,{cache:"no-store"},{collection:K})).documents,listing:async K=>{const{documents:R,epoch:Y,seq:T}=await o(Ne.dbList,{cache:"no-store"},{collection:K});return typeof Y=="string"&&typeof T=="number"?{documents:R,epoch:Y,seq:T}:{documents:R}},write:async K=>{const R={writes:K,client:t},{epoch:Y,seq:T,documents:j}=await s(Ne.dbWrite,R);return typeof Y=="string"&&typeof T=="number"&&j!==void 0?{epoch:Y,seq:T,documents:j}:void 0},onChange:K=>l("db",K)}:null},async comments(){const{stores:F}=await M();if(!F?.comments)return null;const G=async(R,Y)=>(await s(R,Y)).thread;return{list:async()=>(await o(Ne.comments,{cache:"no-store"})).threads,create:R=>G(Ne.commentsCreate,{input:R}),reply:(R,Y,T)=>G(Ne.commentsReply,{threadId:R,text:Y,...T?.to?.length?{to:T.to}:{}}),edit:(R,Y,T,j)=>G(Ne.commentsEdit,{threadId:R,messageId:Y,text:T,...j?.to?{to:j.to}:{}}),react:(R,Y,T,j)=>G(Ne.commentsReact,{threadId:R,messageId:Y,emoji:T,on:j}),setResolved:(R,Y)=>G(Ne.commentsResolve,{threadId:R,resolved:Y}),move:(R,Y,T)=>G(Ne.commentsMove,{threadId:R,anchor:Y,...T?{location:T}:{}}),remove:async(R,Y)=>{await s(Ne.commentsRemove,{threadId:R,...Y?{messageId:Y}:{}})},sendToAgent:(R,Y)=>G(Ne.commentsSend,{threadId:R,...Y?.unasked?{unasked:!0}:{}}),onChange:R=>l("comments",R)}},async doc(){const{stores:F}=await M();return F?.doc?{session:()=>s(Vs.session,{client:t}),read:K=>s(Vs.read,{tab:K}),call:K=>s(Vs.call,{...K,client:t}),history:K=>s(Vs.history,{tab:K}),version:(K,R)=>s(Vs.version,{tab:K,rev:R}),restore:K=>s(Vs.restore,K),importFile:(K,R,Y)=>o(Vs.importFile,{method:"POST",headers:{"content-type":"application/octet-stream"},body:R},{name:K,...Y?{tabName:Y}:{}}),exportFile:async K=>{let R;try{R=await fetch(n(Vs.exportFile,{format:K.format,...K.tab?{tab:K.tab}:{},...K.paper?{paper:K.paper}:{}}),{cache:"no-store"})}catch(L){throw new ec("unavailable",L instanceof Error?L.message:String(L))}if(!R.ok)throw await Uh(R);const Y=R.headers.get("content-disposition")??"",T=decodeURIComponent(/filename\*=UTF-8''([^;]+)/.exec(Y)?.[1]??"")||`doc.${K.format==="markdown"?"md":K.format}`;let j=[];try{j=JSON.parse(decodeURIComponent(R.headers.get("x-doc-export-notes")??"%5B%5D"))}catch{}return{name:T,mime:R.headers.get("content-type")??"application/octet-stream",bytes:new Uint8Array(await R.arrayBuffer()),notes:j}},onFrame:K=>l("doc",K)}:null},async history(){const{stores:F}=await M();if(!F?.history)return null;const G=(R,Y)=>({n:String(R),...Y===void 0?{}:{path:Y}});return{list:()=>o(Ne.history,{cache:"no-store"}),files:async R=>(await o(Ne.historyFiles,{cache:"no-store"},G(R))).files,read:async(R,Y)=>new TextDecoder().decode(await k(Ne.historyFile,G(R,Y))),readBytes:(R,Y)=>k(Ne.historyFile,G(R,Y)),diff:(R,Y)=>o(Ne.historyDiff,{cache:"no-store"},G(R,Y)),restore:(R,Y)=>s(Ne.historyRestore,{n:R,...Y?{paths:Y}:{},client:t}),dismissNotice:async R=>{await s(Ne.historyDismiss,{id:R})},onChange:R=>l("history",R)}},async mcp(){const{viewer:F}=await M();return F.role!=="owner"?null:{callTool:async(K,R,Y,T)=>{const j=T?.signal;j?.throwIfAborted();const L={server:K,tool:R,args:Y,...T?.timeoutMs===void 0?{}:{timeoutMs:T.timeoutMs}};try{return await o(Ne.mcpCall,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(L),...j?{signal:j}:{}})}catch(U){throw j?.aborted?j.reason:U}},listTools:K=>o(Ne.mcpTools,{cache:"no-store"},K===void 0?void 0:{server:K})}},async sheet(){const{stores:F}=await M();if(!F?.sheet)return null;let G=Promise.resolve();return{read:R=>s(vu.read,R),send:R=>{const Y=G.then(()=>s(vu.send,R));return G=Y.catch(()=>{}),Y},widget:R=>s(vu.widget,R),importFile:(R,Y)=>o(vu.importFile,{method:"POST",headers:{"content-type":R.type||"application/octet-stream"},body:R},{name:Y}),onFrame:R=>l(_5,R),onWalkthrough:R=>l(X5,R)}},async downloads(){return{save:async({name:G,data:K})=>o(Ne.downloads,{method:"POST",headers:{"content-type":K.type||"application/octet-stream"},body:K},{name:G})}}};function v(F){return k(Ne.file,{path:F})}async function k(F,G){let K;try{K=await fetch(n(F,G),{cache:"no-store"})}catch(R){throw new ec("unavailable",R instanceof Error?R.message:String(R))}if(!K.ok)throw await Uh(K);return new Uint8Array(await K.arrayBuffer())}return{get(F){const G=N[F];return G?G():null}}}const eZ="[Artifact comment sent to agent]",tZ="[Artifact edit request sent to agent]",nZ="[Artifact task finished]",oZ="[Open Artifact] ",iZ={id:"open_artifact_id"},sZ=1,rZ=1,aZ=/^[a-z][a-z0-9]{0,23}$/,gZ="may not have run: the artifact was updated before this call was answered",cZ=["quickstart","list","publish","read","open","call","adopt","delete","share"],lZ=["get","list","query","set","update","delete","str_replace","batch"],IZ=["read","reply","resolve","reopen","wait"],CZ=["share","export"],uZ={type:"object",properties:{action:{type:"string",enum:cZ,description:"What to do: quickstart, list, publish, read, open, call, adopt, delete or share. Omitted: publish."},intent:{type:"string",description:"quickstart: what is being made (design, design-system, slides, whiteboard, document, data, sheets, motion, page, other), or a few words about it."},scope:{type:"string",enum:["types","mine","all"],description:"list: types (the installed types), mine (this session's and this workspace's artifacts; the default) or all (every artifact)."},type:{type:"string",description:"list: only artifacts of this type (an id, or open-artifact://type/<id>). quickstart: the type already chosen (an id), to get its create call and steps without matching."},query:{type:"string",description:"list: only artifacts whose title contains this text."},limit:{type:"integer",description:"list: how many to return (default 50, at most 200)."},cursor:{type:"string",description:"list: the next_cursor of the previous page."},type_url:{type:"string",description:"publish without url: the type to create from (open-artifact://type/<id>, from quickstart). read without url: the type to describe."},title:{type:"string",description:"publish without url: the new artifact's name. quickstart: the name it will have, to find similar ones."},folder:{type:"string",description:"publish without url, or adopt: where the artifact's folder goes (absolute, or relative to the workspace). Default <workspace>/artifacts/<slug>."},url:{type:"string",description:"An artifact: open-artifact://artifact/<id>, as publish returned it."},files:{type:"object",additionalProperties:!0,description:'publish with url: files to write under the artifact root, as {"rel/path": "text"} or {"rel/path": {"content": "...", "encoding": "base64"}}; null deletes.'},if_match:{type:"object",additionalProperties:!0,description:'publish with url: {"rel/path": sha256 | null | "*"}. Write only while the file still has the sha256 you read, does not exist (null), or anyway ("*"). One mismatch writes nothing and returns the current versions.'},check:{type:"boolean",description:"publish with url: run the type's check action after writing; its result comes back as check."},capabilities:{type:"object",additionalProperties:!0,description:'publish, page artifacts only: the runtime capabilities the page may use, as {"db": true, "assets": true, ...}. Omitted: kept; {}: none; otherwise the whole set. With url it may be given without files.'},open:{type:"string",enum:["after_first_write","now","never"],description:"publish without url: after_first_write (the default) opens the page in your app once your first write lands; now opens it at once; never leaves it closed. Where your app cannot show pages by itself the result says so: open view_url in your app's built-in browser, if you have one."},related:{type:"boolean",description:"quickstart: list existing artifacts the recommended type can build on, such as design systems (default true)."},path:{type:"string",description:"read: one file or folder under the root (omitted: the record and the file list)."},paths:{type:"array",items:{type:"string"},description:"read: several files under the root at once."},name:{type:"string",description:"call: the action's name (check, upload, ...; read with url lists them)."},args:{type:"object",additionalProperties:!0,description:"call: the action's arguments. upload: {file: absolute path, name?, group?}."},panel:{type:"string",enum:CZ,description:"open: also open the page's Share panel (share), for the person to share it on the network, or its Export tab (export), for them to download a file."},cloud:{type:"string",description:"share: publish the artifact to this cloud remote (its name, as `open-artifact remote list` shows it). It works only on a remote the person set up and let agents publish to (agentMayPublish); otherwise the person publishes it, from the Share panel or with `open-artifact publish <id> --remote <name>`."}}},dZ={type:"object",properties:{action:{type:"string",enum:lZ,description:"What to do: get, list, query, set, update, delete, str_replace or batch."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>)."},collection:{type:"string",description:"The collection: alone for list / query (query needs it), with doc_id for one document."},doc_id:{type:"string",description:"With collection: the document to get / set / update / delete / str_replace."},path:{type:"string",description:"collection/doc_id, instead of the two."},data:{type:"object",additionalProperties:!0,description:"set / update: the document's fields."},file_path:{type:"string",description:"set / update: a JSON file holding the fields, instead of data."},if_match:{description:'set / update / delete / str_replace: the sha256 get returned (write only if unchanged), null (only if it does not exist) or "*" (replace whatever is there).'},field:{type:"string",description:"str_replace: the text field, as a dot path (body, notes.text)."},old:{type:"string",description:"str_replace: the passage to replace; it must occur exactly once."},new:{type:"string",description:"str_replace: the passage that replaces it."},where:{type:"array",items:{type:"object",additionalProperties:!0},description:"query: [{field, op, value}], all must hold. op: ==, !=, <, <=, >, >=, in, not-in (up to 30 values), array-contains."},order_by:{type:"object",additionalProperties:!0,description:'query: {field, dir: "asc" | "desc"}.'},limit:{type:"integer",description:"list / query: how many documents (default 100, at most 1000)."},cursor:{type:"string",description:"list / query: the next_cursor of the previous page."},out_file:{type:"string",description:"get / list / query: write the result to this JSON file (absolute, or relative to the workspace) and return only its path and counts."},writes:{type:"array",items:{type:"object",additionalProperties:!0},description:"batch: [{op: set|update|delete|str_replace, path | collection+doc_id, data | file_path, if_match?, field?, old?, new?}], at most 500."}},required:["action","url"]},BZ={type:"object",properties:{action:{type:"string",enum:IZ,description:"What to do: read, reply, resolve, reopen or wait."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>). wait: optional."},thread_id:{type:"string",description:'reply / resolve / reopen: the thread (after ";thread=" in the message).'},text:{type:"string",description:"reply: the answer."},resolve:{type:"boolean",description:"reply: resolve the thread too."},all:{type:"boolean",description:"read: resolved threads too."},since:{type:"string",description:"read: only threads with a message at or after this time (ISO 8601)."},acknowledge_duplicate:{type:"boolean",description:"reply: send the same text as your last reply in this thread again, on purpose."},timeout_ms:{type:"number",description:"wait: how long (default 600000)."}},required:["action"]},kM={Artifact:uZ,ArtifactData:dZ,ArtifactComments:BZ},QZ={Artifact:["Make and change artifacts: typed folders of files that open as live pages the person can view, edit, comment on and export. Actions:","- quickstart {intent, type?}: call first for a new artifact; recommends a type (or takes the one given) and returns the call that creates it, the steps for this app and similar artifacts that already exist.",'- list {scope: "mine" | "all" | "types", type?, query?}: find existing artifacts, or the installed types.',"- publish {type_url, title, folder?, open?}: create an artifact; the result carries its root folder and the type's instructions. publish {url, files, if_match?, check?}: write files when you have no file tools of your own. A page artifact also takes capabilities (on create or write): the runtime capabilities its page may use.","- read {url, path? | paths?}: the artifact's record, files and actions, or some of its files with their sha256. read {type_url}: a type's instructions, before creating.",`- open {url, panel?}: show it to the person in the computer's browser (or the app, when it shows pages), once its content is written. When your app has a built-in browser, open view_url there instead. panel "share" or "export" opens its Share panel or Export tab for them.`,"- call {url, name, args?}: run one of the type's actions (check, upload, ...). A long one answers {task, pending: true}; its result comes later as a message.","- adopt {url | folder}: take over an artifact, or add an existing folder. Only when the person asks.","- share {url}: whether it is shared on the local network, and its links. Only the person changes that, in the page's Share panel.","- delete {url}: forget an artifact; its folder stays. Only when the person asks."].join(`
56
+ `}}function hw(A,e){if(e.kind==="source")return{source:e.text,created:[]};const t=_o(A);if(e.kind==="props"){if(!t.script||!t.props)return null;const l={...t.props};for(const[c,u]of Object.entries(e.values)){const C=l[c];!C||c==="$preview"||!("editor"in C)||(l[c]={...C,default:u})}return{source:Wz(t,l),created:[]}}if(e.kind==="scriptText"){if(!t.script)return null;const l=t.script.body.text,c=qm(l),u=c.filter(Q=>Q.value===e.value),C=c.find(Q=>Q.start===e.start&&Q.end===e.end&&Q.value===e.value)??(u.length===1?u[0]:void 0);if(!C)return null;const B=l.slice(0,C.start)+wV(e.text,C.quote)+l.slice(C.end);return B===l?null:{source:Vz(t,B),created:[]}}if(!t.template)return null;const n=Er(t.template.text);let o;try{switch(e.kind){case"look":o=J5(n,e.look);break;case"style":{const l=Aa(n,e.targets);if(!l)return null;o=l.flatMap(c=>$d(n,c,e.patch));break}case"styles":{const l=Aa(n,e.edits.map(c=>c.target));if(!l)return null;o=l.flatMap((c,u)=>$d(n,c,e.edits[u].patch));break}case"attr":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;o=Bw(n,l,e.name,e.value);break}case"text":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;o=NV(l,e.text);break}case"richText":{const l=ut(n,e.target.tid,e.target.path);if(!l||!Dc(l))return null;const c=fV(e.html);if(o=[{start:l.openEnd,end:l.closeStart,text:c}],l.tag==="p"&&EV(c)){const u=l.start+1;o.push({start:u,end:u+l.rawTag.length,text:"div"});const C=l.closeStart+2;o.push({start:C,end:C+l.rawTag.length,text:"div"})}break}case"wrapText":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;const c=rU(l,n.text,e.inline);if(!c.length)return null;o=c.flatMap(u=>[{start:u.start,end:u.start,text:"<span>"},{start:u.end,end:u.end,text:"</span>"}]);break}case"importText":{const l=ut(n,e.target.tid,e.target.path);if(!l||l.tag!=="x-import")return null;const c=cU(e,e.text,gU(l,yU(A)));if(c.kind!=="commit")return null;o=c.key==="__text"?RV(l,fr(c.text)):Bw(n,l,c.key.slice(1),c.text);break}case"linkText":{const l=ut(n,e.target.tid,e.target.path);if(!l||l.closeStart<=l.openEnd||l.tag==="a")return null;o=[{start:l.openEnd,end:l.openEnd,text:`<a ${lU("href",e.href)}>`},{start:l.closeStart,end:l.closeStart,text:"</a>"}];break}case"remove":{const l=Aa(n,e.targets);if(!l)return null;o=IU(n,l);break}case"duplicate":{const l=Aa(n,e.targets);if(!l)return null;o=vV(n,l);break}case"insert":{const l=e.target?ut(n,e.target.tid,e.target.path):null;if(e.target&&!l)return null;o=eB(n,l,e.position,e.html),e.helmet&&o.push(mM(n,e.helmet));break}case"move":{const l=Aa(n,e.targets),c=ut(n,e.target.tid,e.target.path);if(!l||!c)return null;o=GV(n,l,c,e.position);break}case"wrap":{const l=Aa(n,e.targets);if(!l||l.length===0)return null;o=FV(n,l,e.open,e.close);break}case"unwrap":{const l=ut(n,e.target.tid,e.target.path);if(!l)return null;o=KV(n,l);break}case"replace":{const l=Aa(n,e.edits.map(c=>c.target));if(!l||!l.length)return null;o=l.map((c,u)=>({start:c.start,end:c.end,text:e.edits[u].html})),e.helmet&&o.push(mM(n,e.helmet));break}}}catch{return null}const s=Pm(n.text,o),r=Er(s);let g=e.kind==="style"||e.kind==="styles"||e.kind==="attr"||e.kind==="text"||e.kind==="importText"?[]:H5(r,T5(o)).filter(l=>!O5(r.elements[l.tid]));if(e.kind==="richText"){const l=ut(n,e.target.tid,e.target.path),c=l?r.elements.find(Q=>Q.start===l.start):void 0,u=[],C=Q=>{for(const E of Ge(Q.children))E.tag==="a"&&u.push(E),C(E)};c&&e.link!=null&&C(c);const B=e.link!=null?u[e.link]:void 0;g=B?[kU(r,B)]:[]}return{source:zz(t,s),created:g}}function j5(A,e){let t=A;const n=[];for(const o of e){const s=hw(t,o);s&&(t=s.source,n.push(o))}return{source:t,kept:n,dropped:e.length-n.length}}const DM=A=>{if(A===null)return{canvas:tB(),error:null};try{return{canvas:mQ(JSON.parse(A)),error:null}}catch(e){return{canvas:tB(),error:e instanceof Error?e.message:String(e)}}},ri=(A,e)=>[...A.slice(-199),e],oA=ao()((A,e)=>({status:"loading",error:null,title:"",readOnly:!1,canvas:tB(),canvasSaved:tB(),canvasHash:null,canvasError:null,boards:{},trash:[],undo:[],redo:[],edits:0,save:"saved",revision:0,gesture:null,load({title:t,readOnly:n,canvas:o,boards:s}){const r=DM(o.text),g={};for(const[l,c]of Object.entries(s))g[l]={source:c.text,saved:c.text,hash:c.hash,pending:[]};A({status:"ready",title:r.canvas.title||t,readOnly:n,canvas:r.canvas,canvasSaved:r.canvas,canvasHash:o.hash,canvasError:r.error,boards:g,save:n?"readonly":"saved"})},fail(t){A({status:"error",error:t})},editBoard(t,n,o={}){const s=e(),r=s.boards[t];if(s.readOnly||!r?.source)return null;const g=hw(r.source,n);if(!g||g.source===r.source)return g;const l={source:g.source,pending:[...r.pending,n]},c=s.undo[s.undo.length-1],u=o.coalesce&&c?.scope==="board"&&c.path===t&&c.key===o.coalesce&&c.after.source===r.source,C=u?c.before:{source:r.source,pending:r.pending},B={scope:"board",path:t,before:C,after:l,...o.coalesce?{key:o.coalesce}:{}};return A({boards:{...s.boards,[t]:{...r,...l}},undo:u?[...s.undo.slice(0,-1),B]:ri(s.undo,B),redo:[],edits:s.edits+1,revision:s.revision+1}),g},updateCanvas(t){const n=e();if(n.readOnly||n.canvasError)return;const o=t(n.canvas);o!==n.canvas&&A({canvas:o,...n.gesture?{}:{undo:ri(n.undo,{scope:"canvas",before:n.canvas,after:o}),redo:[]},revision:n.revision+1})},beginGesture(){e().gesture||A({gesture:e().canvas})},endGesture(){const{gesture:t,canvas:n,undo:o}=e();t&&A({gesture:null,...t!==n?{undo:ri(o,{scope:"canvas",before:t,after:n}),redo:[]}:{}})},createBoard(t,n,o){const s=e();if(s.readOnly)return;const r=s.boards[t],g={...s.canvas,boards:{...s.canvas.boards,[t]:o},order:[...s.canvas.order.filter(l=>l!==t),t]};A({boards:{...s.boards,[t]:{source:n,saved:r?.saved??null,hash:r?.hash??null,pending:[]}},canvas:g,trash:s.trash.filter(l=>l!==t),undo:ri(s.undo,{scope:"canvas",before:s.canvas,after:g}),redo:[],edits:s.edits+1,revision:s.revision+1})},deleteBoards(t){const n=e();if(n.readOnly||t.length===0)return;const o={...n.canvas.boards};for(const r of t)delete o[r];const s={...n.canvas,boards:o,order:n.canvas.order.filter(r=>!t.includes(r))};A({canvas:s,trash:[...new Set([...n.trash,...t])],undo:ri(n.undo,{scope:"canvas",before:n.canvas,after:s}),redo:[],edits:n.edits+1,revision:n.revision+1})},editBoards(t,n){const o=e();if(o.readOnly)return 0;const s={...o.boards},r=[];for(const g of t){const l=s[g];if(!l?.source)continue;const c=hw(l.source,n);if(!c||c.source===l.source)continue;const u={source:c.source,pending:[...l.pending,n]};s[g]={...l,...u},r.push({scope:"board",path:g,before:{source:l.source,pending:l.pending},after:u})}return r.length&&A({boards:s,undo:ri(o.undo,{scope:"boards",changes:r}),redo:[],edits:o.edits+1,revision:o.revision+1}),r.length},undoLast(){const t=e(),n=t.undo[t.undo.length-1];if(!n||t.readOnly)return null;if(n.scope==="canvas"){const o=Nh(n.after,n.before,t.canvas);A({canvas:o,undo:t.undo.slice(0,-1),redo:ri(t.redo,n),revision:t.revision+1})}else{const o={...t.boards};for(const s of n.scope==="board"?[n]:n.changes){if(!o[s.path])return null;o[s.path]={...o[s.path],...s.before}}A({boards:o,undo:t.undo.slice(0,-1),redo:ri(t.redo,n),revision:t.revision+1})}return n},redoLast(){const t=e(),n=t.redo[t.redo.length-1];if(!n||t.readOnly)return null;if(n.scope==="canvas"){const o=Nh(n.before,n.after,t.canvas);A({canvas:o,redo:t.redo.slice(0,-1),undo:ri(t.undo,n),revision:t.revision+1})}else{const o={...t.boards};for(const s of n.scope==="board"?[n]:n.changes){if(!o[s.path])return null;o[s.path]={...o[s.path],...s.after}}A({boards:o,redo:t.redo.slice(0,-1),undo:ri(t.undo,n),revision:t.revision+1})}return n},remoteBoard(t,n,o){const s=e(),r=s.boards[t],g=c=>c.filter(u=>u.scope==="canvas"||(u.scope==="board"?u.path!==t:!u.changes.some(C=>C.path===t)));if(n===null)return r&&A({boards:{...s.boards,[t]:{...r,saved:null,hash:null,...r.pending.length?{}:{source:null}}}}),0;const l=r?.pending.length?j5(n,r.pending):{source:n,kept:[],dropped:0};return A({boards:{...s.boards,[t]:{source:l.source,saved:n,hash:o,pending:l.kept}},undo:g(s.undo),redo:g(s.redo),...l.kept.length?{revision:s.revision+1}:{}}),l.dropped},remoteCanvas(t,n){const o=e(),s=DM(t);if(s.error){A({canvasError:s.error,canvasHash:n});return}const r=o.canvas!==o.canvasSaved,g=r?Nh(o.canvasSaved,o.canvas,s.canvas):s.canvas;A({canvas:g,canvasSaved:s.canvas,canvasHash:n,canvasError:null,title:s.canvas.title||o.title,...r?{revision:o.revision+1}:{}})},acknowledge(t,n){const o=e(),s={...o.boards};for(const[r,{source:g,pendingCount:l}]of Object.entries(t.boards)){const c=s[r];!c||!(r in n)||(s[r]={...c,saved:g,hash:n[r]??null,pending:c.pending.slice(l)})}for(const r of t.deleted){const g=s[r];g&&(s[r]={...g,saved:null,hash:null})}A({boards:s,trash:o.trash.filter(r=>!t.deleted.includes(r)),...t.canvas&&"canvas.json"in n?{canvasSaved:t.canvas.canvas,canvasHash:n["canvas.json"]??null}:{}})},setSave(t){e().save!==t&&A({save:t})},setTitle(t){A({title:t})}}));function oB(A){return A.readOnly?!1:A.canvas!==A.canvasSaved||A.trash.some(e=>A.boards[e]?.hash)?!0:Object.entries(A.boards).some(([e,t])=>t.source!==null&&xU(A,e,t))}function xU(A,e,t){return t.source===null?!1:t.source!==t.saved?!0:t.hash===null&&e in A.canvas.boards}const Ta=.01,zI=8,Rn={kind:"none"},q5=[1.5,3,5,8],MU="mc-toolbar/top";function P5(){try{return typeof localStorage>"u"||localStorage.getItem(MU)!=="0"}catch{return!0}}const X=ao()((A,e)=>({camera:{x:0,y:0,zoom:1},page:null,tool:"select",selection:Rn,hover:null,peek:null,textEdit:null,noteEdit:null,mode:"canvas",focused:null,focusedExportWidth:null,playing:null,panel:"properties",panelOpen:!1,frames:{},layoutTick:0,overrides:{},composer:!1,spacePan:!1,pen:{stroke:3,dash:"solid"},findOpen:!1,toolbarTop:P5(),crop:null,errorsOpen:!1,closedNotices:{},unsentFix:null,setCamera(t){const n=Math.min(zI,Math.max(Ta,t.zoom));A({camera:{...t,zoom:n}})},setPage(t){e().page!==t&&A({page:t,playing:null,selection:Rn,hover:null,peek:null,crop:null})},setTool(t){A({tool:t,playing:null})},select(t){A({selection:t,playing:null,noteEdit:null,...e().crop?{crop:null}:{}})},setHover(t){const n=e().hover;n?.board===t?.board&&n?.tid===t?.tid&&n?.instance===t?.instance||A({hover:t})},setPeek(t){e().peek!==t&&A({peek:t})},setTextEdit(t){A({textEdit:t})},patchTextEdit(t){const{textEdit:n}=e();n&&A({textEdit:{...n,...t}})},setNoteEdit(t){A({noteEdit:t})},focus(t){A(t?{mode:"focused",focused:t,playing:null,hover:null}:{mode:"canvas",focused:null})},play(t){A({playing:t,hover:null,selection:Rn,tool:"select",noteEdit:null,textEdit:null})},setPanel(t,n=!0){A({panel:t,panelOpen:n})},togglePanel(){A({panelOpen:!e().panelOpen})},frame(t,n){const o=e().frames,s=o[t]??{booted:!1,errors:[],size:null};A({frames:{...o,[t]:{...s,...n}},layoutTick:e().layoutTick+1})},dropFrame(t){const{[t]:n,...o}=e().frames;A({frames:o})},parkFrame(t){const n=e().frames[t];if(!n)return;const o=structuredClone(n.errors),s=n.size?structuredClone(n.size):null;A({frames:{...e().frames,[t]:{booted:!1,errors:o,size:s}}})},tick(){A({layoutTick:e().layoutTick+1})},setOverride(t,n,o){const s=e().overrides;A({overrides:{...s,[t]:{...s[t]??{},[n]:o}}})},clearOverrides(t){const{[t]:n,...o}=e().overrides;A({overrides:o})},setComposer(t){A({composer:t})},setPen(t){A({pen:{...e().pen,...t}})},setSpacePan(t){e().spacePan!==t&&A({spacePan:t})},setFindOpen(t){e().findOpen!==t&&A({findOpen:t})},setToolbarTop(t){try{localStorage.setItem(MU,t?"1":"0")}catch{}A({toolbarTop:t})},setCrop(t){A({crop:t})},setErrorsOpen(t){e().errorsOpen!==t&&A({errorsOpen:t})},setClosedNotices(t){e().closedNotices!==t&&A({closedNotices:t})},setUnsentFix(t){A({unsentFix:t})}}));function Ul(A,e,t){return{x:(e-A.x)/A.zoom,y:(t-A.y)/A.zoom}}const z5="1.4.0";class ec extends Error{code;paths;retryable;constructor(e,t,n,o){super(t),this.name="ArtifactError",this.code=e,n&&(this.paths=n),o&&(this.retryable=!0)}}function bM(A,e){if(!A||typeof A!="object")return!1;const t=A;return t.name!=="ArtifactError"||typeof t.code!="string"?!1:e===void 0||t.code===e}function V5(A){return A==="owner"||A==="editor"}const SM={defaultMs:12e4,maxMs:6e5};function Z5(A,e={}){const t=e.timeoutMs??1e4,n=new Map;return Object.freeze({version:z5,use:s=>{const r=n.get(s);if(r)return r;const g=new Promise(l=>{const c=setTimeout(()=>l(null),t);Promise.resolve().then(()=>A.get(s)).then(u=>{clearTimeout(c),l(u?Object.freeze(u):null)},()=>{clearTimeout(c),l(null)})});return n.set(s,g),g}})}function W5(A,e){const t=globalThis.window?.openartifact;if(t)return t;const n=Z5(A,e);return Object.defineProperty(window,"openartifact",{value:n,configurable:!1,enumerable:!0,writable:!1}),n}async function eD(A){const e=globalThis.window?.openartifact;if(!e)return null;try{return await e.use(A)}catch{return null}}const Ne={session:"_api/session",files:"_api/files",file:"_api/file",publish:"_api/publish",assets:"_api/assets",events:"_api/events",agentSend:"_api/agent/send",presence:"_api/presence",peers:"_api/peers",downloads:"_api/downloads",roomEmit:"_api/room/emit",dbGet:"_api/db/get",dbList:"_api/db/list",dbWrite:"_api/db/write",comments:"_api/comments",commentsCreate:"_api/comments/create",commentsReply:"_api/comments/reply",commentsEdit:"_api/comments/edit",commentsReact:"_api/comments/react",commentsResolve:"_api/comments/resolve",commentsMove:"_api/comments/move",commentsRemove:"_api/comments/remove",commentsSend:"_api/comments/send",history:"_api/history",historyFiles:"_api/history/files",historyFile:"_api/history/file",historyDiff:"_api/history/diff",historyRestore:"_api/history/restore",historyDismiss:"_api/history/dismiss",systemCopy:"_api/design/system-copy",mcpTools:"_api/mcp/tools",mcpCall:"_api/mcp/call",dataRefresh:"_api/data/refresh"},vu={read:"_api/sheet/read",send:"_api/sheet/send",widget:"_api/sheet/widget",importFile:"_api/sheet/import"},_5="sheet",X5="sheetWalkthrough",Vs={session:"_api/doc/session",read:"_api/doc/read",call:"_api/doc/call",history:"_api/doc/history",version:"_api/doc/version",restore:"_api/doc/restore",importFile:"_api/doc/import",exportFile:"_api/doc/export"};function $5(A,e,t){return e===401||e===403?"removed":e<200||e>=300||!t||t.id===A.id&&t.role===A.role?null:"changed"}async function Uh(A){let e={};try{e=await A.json()}catch{}const t=A.status===409?"conflict":A.status===403?"not_writer":A.status===404?"not_found":"unavailable";return new ec(e.code??t,e.message??`HTTP ${A.status}`,e.paths,e.retryable===!0)}function AZ(){const A=new Uint8Array(8);return crypto.getRandomValues(A),Array.from(A,e=>e.toString(16).padStart(2,"0")).join("")}function NU(A={}){const e=new URL(A.base??"./",location.href),t=AZ(),n=(F,G)=>{const K=new URL(F,e);for(const[R,Y]of Object.entries(G??{}))K.searchParams.set(R,Y);return K.toString()},o=async(F,G,K)=>{let R;try{R=await fetch(n(F,K),G)}catch(Y){throw new ec("unavailable",Y instanceof Error?Y.message:String(Y))}if(!R.ok)throw await Uh(R);return await R.json()},s=(F,G)=>o(F,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(G)}),r=new Map,g=(F,G)=>{for(const K of r.get(F)??[])K(G)},l=(F,G)=>{let K=r.get(F);return K||(K=new Set,r.set(F,K),C?.addEventListener(F,Q)),K.add(G),w(),()=>K.delete(G)};let c=null,u=!1,C=null,B=null;const Q=F=>{g(F.type,JSON.parse(F.data))},E=()=>{const F=new EventSource(n(Ne.events,{client:t}));C=F;for(const G of r.keys())F.addEventListener(G,Q);F.onerror=()=>{x().then(G=>{G||F.readyState!==EventSource.CLOSED||C!==F||(C=null,B=setTimeout(()=>{B=null,w()},2e3))})}};let h=!1,p=!1;const b=F=>{h||(h=!0,B&&clearTimeout(B),B=null,C?.close(),C=null,c?.close(),c=null,A.onAccessChange?A.onAccessChange(F):location.reload())},x=async()=>{if(h)return!0;if(!m||p)return!1;p=!0;try{const F=(await m.catch(()=>null))?.viewer;if(!F)return!1;let G;try{G=await fetch(n(Ne.session),{cache:"no-store"})}catch{return!1}const K=G.ok?(await G.json().catch(()=>null))?.viewer:null,R=$5(F,G.status,K);return R&&b(R),R!==null}finally{p=!1}};function w(){if(c||C||B||h)return;if(typeof WebSocket>"u")return E();const F=new URL(n(Ne.events,{client:t}));F.protocol=F.protocol==="https:"?"wss:":"ws:";const G=new WebSocket(F);c=G,G.onopen=()=>{u=!0},G.onmessage=K=>{let R;try{R=JSON.parse(String(K.data))}catch{return}R.event&&g(R.event,R.data)},G.onclose=()=>{if(c===G&&(c=null),!h){if(!u)return E();x().then(K=>{K||c||C||B||(B=setTimeout(()=>{B=null,w()},2e3))})}}}let m=null;const M=()=>m??=o(Ne.session),N={async artifact(){const{artifact:F,stores:G}=await M();return{id:F.id,...G?.systemCopy?{systemCopy:(R,Y)=>o(Ne.systemCopy,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({namespace:R,action:Y})})}:{},title:async()=>(await o(Ne.session)).artifact.title,list:async()=>(await o(Ne.files)).files,readText:async R=>new TextDecoder().decode(await v(R)),readBytes:R=>v(R),publish:async R=>{const Y={files:R,client:t};return o(Ne.publish,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Y)})},onChange:R=>l("files",R)}},async assets(){const{viewer:F}=await M();return V5(F.role)?{upload:async(K,R)=>o(Ne.assets,{method:"POST",headers:{"content-type":K.type||"application/octet-stream"},body:K},R?.name?{name:R.name}:void 0)}:null},async user(){const{viewer:F}=await M();return{me:async()=>F}},async agent(){return{send:async(G,K)=>{const R={request:G,deliver:K?.deliver??"send"};return o(Ne.agentSend,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(R)})},status:async()=>(await o(Ne.session)).agent,onStatus:G=>l("agent",G)}},async room(){return{self:async()=>t,presence:async G=>{const K={client:t,patch:G};await o(Ne.presence,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(K)})},peers:async()=>(await o(Ne.peers)).peers,onPeers:G=>l("peers",G),emit:async(G,K)=>{const R={client:t,topic:G,data:K};await s(Ne.roomEmit,R)},onMessage:G=>l("room",G)}},async db(){const{stores:F}=await M();return F?.db?{get:async K=>(await o(Ne.dbGet,{cache:"no-store"},{path:K})).data,list:async K=>(await o(Ne.dbList,{cache:"no-store"},{collection:K})).documents,listing:async K=>{const{documents:R,epoch:Y,seq:T}=await o(Ne.dbList,{cache:"no-store"},{collection:K});return typeof Y=="string"&&typeof T=="number"?{documents:R,epoch:Y,seq:T}:{documents:R}},write:async K=>{const R={writes:K,client:t},{epoch:Y,seq:T,documents:j}=await s(Ne.dbWrite,R);return typeof Y=="string"&&typeof T=="number"&&j!==void 0?{epoch:Y,seq:T,documents:j}:void 0},onChange:K=>l("db",K)}:null},async comments(){const{stores:F}=await M();if(!F?.comments)return null;const G=async(R,Y)=>(await s(R,Y)).thread;return{list:async()=>(await o(Ne.comments,{cache:"no-store"})).threads,create:R=>G(Ne.commentsCreate,{input:R}),reply:(R,Y,T)=>G(Ne.commentsReply,{threadId:R,text:Y,...T?.to?.length?{to:T.to}:{}}),edit:(R,Y,T,j)=>G(Ne.commentsEdit,{threadId:R,messageId:Y,text:T,...j?.to?{to:j.to}:{}}),react:(R,Y,T,j)=>G(Ne.commentsReact,{threadId:R,messageId:Y,emoji:T,on:j}),setResolved:(R,Y)=>G(Ne.commentsResolve,{threadId:R,resolved:Y}),move:(R,Y,T)=>G(Ne.commentsMove,{threadId:R,anchor:Y,...T?{location:T}:{}}),remove:async(R,Y)=>{await s(Ne.commentsRemove,{threadId:R,...Y?{messageId:Y}:{}})},sendToAgent:(R,Y)=>G(Ne.commentsSend,{threadId:R,...Y?.unasked?{unasked:!0}:{}}),onChange:R=>l("comments",R)}},async doc(){const{stores:F}=await M();return F?.doc?{session:()=>s(Vs.session,{client:t}),read:K=>s(Vs.read,{tab:K}),call:K=>s(Vs.call,{...K,client:t}),history:K=>s(Vs.history,{tab:K}),version:(K,R)=>s(Vs.version,{tab:K,rev:R}),restore:K=>s(Vs.restore,K),importFile:(K,R,Y)=>o(Vs.importFile,{method:"POST",headers:{"content-type":"application/octet-stream"},body:R},{name:K,...Y?{tabName:Y}:{}}),exportFile:async K=>{let R;try{R=await fetch(n(Vs.exportFile,{format:K.format,...K.tab?{tab:K.tab}:{},...K.paper?{paper:K.paper}:{}}),{cache:"no-store"})}catch(L){throw new ec("unavailable",L instanceof Error?L.message:String(L))}if(!R.ok)throw await Uh(R);const Y=R.headers.get("content-disposition")??"",T=decodeURIComponent(/filename\*=UTF-8''([^;]+)/.exec(Y)?.[1]??"")||`doc.${K.format==="markdown"?"md":K.format}`;let j=[];try{j=JSON.parse(decodeURIComponent(R.headers.get("x-doc-export-notes")??"%5B%5D"))}catch{}return{name:T,mime:R.headers.get("content-type")??"application/octet-stream",bytes:new Uint8Array(await R.arrayBuffer()),notes:j}},onFrame:K=>l("doc",K)}:null},async history(){const{stores:F}=await M();if(!F?.history)return null;const G=(R,Y)=>({n:String(R),...Y===void 0?{}:{path:Y}});return{list:()=>o(Ne.history,{cache:"no-store"}),files:async R=>(await o(Ne.historyFiles,{cache:"no-store"},G(R))).files,read:async(R,Y)=>new TextDecoder().decode(await k(Ne.historyFile,G(R,Y))),readBytes:(R,Y)=>k(Ne.historyFile,G(R,Y)),diff:(R,Y)=>o(Ne.historyDiff,{cache:"no-store"},G(R,Y)),restore:(R,Y)=>s(Ne.historyRestore,{n:R,...Y?{paths:Y}:{},client:t}),dismissNotice:async R=>{await s(Ne.historyDismiss,{id:R})},onChange:R=>l("history",R)}},async mcp(){const{viewer:F}=await M();return F.role!=="owner"?null:{callTool:async(K,R,Y,T)=>{const j=T?.signal;j?.throwIfAborted();const L={server:K,tool:R,args:Y,...T?.timeoutMs===void 0?{}:{timeoutMs:T.timeoutMs}};try{return await o(Ne.mcpCall,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(L),...j?{signal:j}:{}})}catch(U){throw j?.aborted?j.reason:U}},listTools:K=>o(Ne.mcpTools,{cache:"no-store"},K===void 0?void 0:{server:K})}},async sheet(){const{stores:F}=await M();if(!F?.sheet)return null;let G=Promise.resolve();return{read:R=>s(vu.read,R),send:R=>{const Y=G.then(()=>s(vu.send,R));return G=Y.catch(()=>{}),Y},widget:R=>s(vu.widget,R),importFile:(R,Y)=>o(vu.importFile,{method:"POST",headers:{"content-type":R.type||"application/octet-stream"},body:R},{name:Y}),onFrame:R=>l(_5,R),onWalkthrough:R=>l(X5,R)}},async downloads(){return{save:async({name:G,data:K})=>o(Ne.downloads,{method:"POST",headers:{"content-type":K.type||"application/octet-stream"},body:K},{name:G})}}};function v(F){return k(Ne.file,{path:F})}async function k(F,G){let K;try{K=await fetch(n(F,G),{cache:"no-store"})}catch(R){throw new ec("unavailable",R instanceof Error?R.message:String(R))}if(!K.ok)throw await Uh(K);return new Uint8Array(await K.arrayBuffer())}return{get(F){const G=N[F];return G?G():null}}}const eZ="[Artifact comment sent to agent]",tZ="[Artifact edit request sent to agent]",nZ="[Artifact task finished]",oZ="[Open Artifact] ",iZ={id:"open_artifact_id"},sZ=1,rZ=1,aZ=/^[a-z][a-z0-9]{0,23}$/,gZ="may not have run: the artifact was updated before this call was answered",cZ=["quickstart","list","publish","read","open","call","adopt","delete","share"],lZ=["get","list","query","set","update","delete","str_replace","batch"],IZ=["read","reply","resolve","reopen","wait"],CZ=["share","export"],uZ={type:"object",properties:{action:{type:"string",enum:cZ,description:"What to do: quickstart, list, publish, read, open, call, adopt, delete or share. Omitted: publish."},intent:{type:"string",description:"quickstart: what is being made (design, design-system, slides, whiteboard, document, data, sheets, motion, page, other), or a few words about it."},scope:{type:"string",enum:["types","mine","all"],description:"list: types (the installed types), mine (this session's and this project's artifacts; the default) or all (every artifact)."},type:{type:"string",description:"list: only artifacts of this type (an id, or open-artifact://type/<id>). quickstart: the type already chosen (an id), to get its create call and steps without matching."},query:{type:"string",description:"list: only artifacts whose title contains this text."},limit:{type:"integer",description:"list: how many to return (default 50, at most 200)."},cursor:{type:"string",description:"list: the next_cursor of the previous page."},type_url:{type:"string",description:"publish without url: the type to create from (open-artifact://type/<id>, from quickstart). read without url: the type to describe."},title:{type:"string",description:"publish without url: the new artifact's name. quickstart: the name it will have, to find similar ones."},folder:{type:"string",description:"publish without url: the exact folder for the new artifact (absolute, or relative to the workspace), only when the person named one. Omitted: Open Artifact chooses the folder and its name. adopt: the folder to add."},location:{type:"string",enum:["home","workspace"],description:"publish without url: where the new artifact's folder goes when the person asked: workspace (in the project, under the working folder) or home (the person's Open Artifact folder). Omitted: what the person's settings say. The folder is named from the title either way."},url:{type:"string",description:"An artifact: open-artifact://artifact/<id>, as publish returned it."},files:{type:"object",additionalProperties:!0,description:'publish with url: files to write under the artifact root, as {"rel/path": "text"} or {"rel/path": {"content": "...", "encoding": "base64"}}; null deletes.'},if_match:{type:"object",additionalProperties:!0,description:'publish with url: {"rel/path": sha256 | null | "*"}. Write only while the file still has the sha256 you read, does not exist (null), or anyway ("*"). One mismatch writes nothing and returns the current versions.'},check:{type:"boolean",description:"publish with url: run the type's check action after writing; its result comes back as check."},capabilities:{type:"object",additionalProperties:!0,description:'publish, page artifacts only: the runtime capabilities the page may use, as {"db": true, "assets": true, ...}. Omitted: kept; {}: none; otherwise the whole set. With url it may be given without files.'},open:{type:"string",enum:["after_first_write","now","never"],description:"publish without url: after_first_write (the default) opens the page in your app once your first write lands; now opens it at once; never leaves it closed. Where your app cannot show pages by itself the result says so: open view_url in your app's built-in browser, if you have one."},related:{type:"boolean",description:"quickstart: list existing artifacts the recommended type can build on, such as design systems (default true)."},path:{type:"string",description:"read: one file or folder under the root (omitted: the record and the file list)."},paths:{type:"array",items:{type:"string"},description:"read: several files under the root at once."},name:{type:"string",description:"call: the action's name (check, upload, ...; read with url lists them)."},args:{type:"object",additionalProperties:!0,description:"call: the action's arguments. upload: {file: absolute path, name?, group?}."},panel:{type:"string",enum:CZ,description:"open: also open the page's Share panel (share), for the person to share it on the network, or its Export tab (export), for them to download a file."},cloud:{type:"string",description:"share: publish the artifact to this cloud remote (its name, as `open-artifact remote list` shows it). It works only on a remote the person set up and let agents publish to (agentMayPublish); otherwise the person publishes it, from the Share panel or with `open-artifact publish <id> --remote <name>`."}}},dZ={type:"object",properties:{action:{type:"string",enum:lZ,description:"What to do: get, list, query, set, update, delete, str_replace or batch."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>)."},collection:{type:"string",description:"The collection: alone for list / query (query needs it), with doc_id for one document."},doc_id:{type:"string",description:"With collection: the document to get / set / update / delete / str_replace."},path:{type:"string",description:"collection/doc_id, instead of the two."},data:{type:"object",additionalProperties:!0,description:"set / update: the document's fields."},file_path:{type:"string",description:"set / update: a JSON file holding the fields, instead of data."},if_match:{description:'set / update / delete / str_replace: the sha256 get returned (write only if unchanged), null (only if it does not exist) or "*" (replace whatever is there).'},field:{type:"string",description:"str_replace: the text field, as a dot path (body, notes.text)."},old:{type:"string",description:"str_replace: the passage to replace; it must occur exactly once."},new:{type:"string",description:"str_replace: the passage that replaces it."},where:{type:"array",items:{type:"object",additionalProperties:!0},description:"query: [{field, op, value}], all must hold. op: ==, !=, <, <=, >, >=, in, not-in (up to 30 values), array-contains."},order_by:{type:"object",additionalProperties:!0,description:'query: {field, dir: "asc" | "desc"}.'},limit:{type:"integer",description:"list / query: how many documents (default 100, at most 1000)."},cursor:{type:"string",description:"list / query: the next_cursor of the previous page."},out_file:{type:"string",description:"get / list / query: write the result to this JSON file (absolute, or relative to the workspace) and return only its path and counts."},writes:{type:"array",items:{type:"object",additionalProperties:!0},description:"batch: [{op: set|update|delete|str_replace, path | collection+doc_id, data | file_path, if_match?, field?, old?, new?}], at most 500."}},required:["action","url"]},BZ={type:"object",properties:{action:{type:"string",enum:IZ,description:"What to do: read, reply, resolve, reopen or wait."},url:{type:"string",description:"The artifact (open-artifact://artifact/<id>). wait: optional."},thread_id:{type:"string",description:'reply / resolve / reopen: the thread (after ";thread=" in the message).'},text:{type:"string",description:"reply: the answer."},resolve:{type:"boolean",description:"reply: resolve the thread too."},all:{type:"boolean",description:"read: resolved threads too."},since:{type:"string",description:"read: only threads with a message at or after this time (ISO 8601)."},acknowledge_duplicate:{type:"boolean",description:"reply: send the same text as your last reply in this thread again, on purpose."},timeout_ms:{type:"number",description:"wait: how long (default 600000)."}},required:["action"]},kM={Artifact:uZ,ArtifactData:dZ,ArtifactComments:BZ},QZ={Artifact:["Make and change artifacts: typed folders of files that open as live pages the person can view, edit, comment on and export. Actions:","- quickstart {intent, type?}: call first for a new artifact; recommends a type (or takes the one given) and returns the call that creates it, the steps for this app and similar artifacts that already exist.",'- list {scope: "mine" | "all" | "types", type?, query?}: find existing artifacts, or the installed types.',"- publish {type_url, title, folder?, open?}: create an artifact; the result carries its root folder and the type's instructions. publish {url, files, if_match?, check?}: write files when you have no file tools of your own. A page artifact also takes capabilities (on create or write): the runtime capabilities its page may use.","- read {url, path? | paths?}: the artifact's record, files and actions, or some of its files with their sha256. read {type_url}: a type's instructions, before creating.",`- open {url, panel?}: show it to the person in the computer's browser (or the app, when it shows pages), once its content is written. When your app has a built-in browser, open view_url there instead. panel "share" or "export" opens its Share panel or Export tab for them.`,"- call {url, name, args?}: run one of the type's actions (check, upload, ...). A long one answers {task, pending: true}; its result comes later as a message.","- adopt {url | folder}: take over an artifact, or add an existing folder. Only when the person asks.","- share {url}: whether it is shared on the local network, and its links. Only the person changes that, in the page's Share panel.","- delete {url}: forget an artifact; its folder stays. Only when the person asks."].join(`
57
57
  `),ArtifactData:'Read and write the document store of an artifact whose type keeps one (its instructions say so). get, list and query read documents with their sha256; set, update, delete, str_replace and batch write them. update merges fields, and {"__delete__": true} removes one; str_replace changes one passage of a long text field. Replacing or deleting an existing document needs if_match: the sha256 you read, or "*". Your writes show live on open pages.',ArtifactComments:`Comments the person leaves on their artifact's page, kept in the artifact's own folder on this computer (no outside service). read lists the threads; reply answers one (thread_id is after ";thread=" in the message), with resolve: true when it is done; resolve and reopen change a thread's state. A thread sent to you is the person asking for your answer in it, so replying there is what they asked for. Answer only threads sent to you, in one or two lines. wait blocks until the next message for this session: use it only when nothing else can wake you.`},xM={Artifact:{title:"Artifact",openWorldHint:!1},ArtifactData:{title:"Artifact data",openWorldHint:!1},ArtifactComments:{title:"Artifact comments",destructiveHint:!1,openWorldHint:!1}},fZ={Artifact:{quickstart:"read",list:"read",read:"read",publish:"write",call:"write",open:"ui",delete:"remove",adopt:"remove",share:"person"},ArtifactData:{get:"read",list:"read",query:"read",set:"write",update:"write",str_replace:"write",batch:"write",delete:"write"},ArtifactComments:{read:"read",wait:"read",reply:"write",resolve:"write",reopen:"write"}},EZ={Artifact:["publish","open","call","share"],ArtifactData:["get","list","query","set","update","str_replace","batch","delete"],ArtifactComments:["read","reply","resolve","reopen"]};function hZ(A={any:!1,actions:!1}){return Object.keys(kM).map(e=>{const t=e==="Artifact"?A.any:A.actions;return{name:e,description:QZ[e],inputSchema:kM[e],annotations:t?{...xM[e],openWorldHint:!0}:xM[e],actions:fZ[e],remoteActions:[...EZ[e]]}})}hZ();const pZ=300,wZ=12,MM=["Artifact","ArtifactData","ArtifactComments"];function Ir(A,e=pZ){const t=String(A??"").replace(/[<>]/g,"").replace(/\s+/g," ").trim();return t.length>e?`${t.slice(0,e-1).trimEnd()}…`:t}function yZ(A){const e=Ir(A,Number.MAX_SAFE_INTEGER),t=e.search(/[.!?。!?](\s|$)/);return t>=0?e.slice(0,t+1):e}function mZ(A){const e=Ir(A,24);return/^[a-z0-9]{1,5}$/i.test(e)?e.toUpperCase():e}const NM=A=>!A||/[.!?。!?…]$/.test(A)?A:`${A}.`;function DZ(A,e=!1){const t=Ir(A.title,80)||A.id;if(e)return`- ${A.id}: ${t}`;const n=Ir(A.when)||Ir(yZ(A.description)),o=(A.exports??[]).map(mZ).filter(Boolean),s=[NM(t),NM(n),o.length?`Exports: ${o.join(", ")}.`:""].filter(Boolean);return`- ${A.id}: ${s.join(" ")}`}const bZ="Open Artifact lets you make artifacts: typed folders of files (a slide deck, a design canvas, a whiteboard, a data dashboard, a spreadsheet, a doc, an animated motion piece, a free HTML page and more) that open as live pages the person can view, edit, comment on and export. You make and change them with the Artifact, ArtifactData and ArtifactComments tools.",SZ=`<where_output_goes>
58
58
  Decide where your output will live before you make anything.
59
59
  - Something the person will read once and move on from (an answer, an explanation, a summary, a short report) goes in your reply, however long it is. A diagram or chart that explains your answer goes in the reply too, when you can show one there.
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <link rel="icon" href="data:," />
7
7
  <title>Design</title>
8
- <script type="module" crossorigin src="./assets/index-B5Wv_tnf.js"></script>
8
+ <script type="module" crossorigin src="./assets/index-DUW-k3ks.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="./assets/index-k79cVH5r.css">
10
10
  </head>
11
11
  <body>