dsh-open-artifact 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,39 @@ agent plugins. Since 0.9.0 they all share one version; before that `dsh-open-art
6
6
  Each entry is written from the commits since the previous tag (`node scripts/changelog.mjs` lists them); see
7
7
  [Releasing](README.md#releasing).
8
8
 
9
+ ## [0.14.1] - 2026-11-22
10
+
11
+ Open Artifact runs inside an Electron app whose `RunAsNode` fuse is off: the app starts the daemon itself, and type servers run in worker threads.
12
+
13
+ ### Added
14
+
15
+ - An agent app can start the daemon process itself: `createHarness({ daemon: { spawn } })` (and `ensureDaemon({ spawn })`) hands it the runtime's entry, the arguments, the environment and the log file. The kit still chooses the runtime, waits for the daemon, checks its version and tries the next runtime, and its `daemon_failed` error says what the app's start threw. An Electron app with its `RunAsNode` fuse off forks the daemon with `utilityProcess.fork`.
16
+ - When the daemon runs inside an Electron process (`process.type` is set, as in a utility process), it runs the type servers whose command is `node` in worker threads of its own process instead of child processes, since its executable must not be started as Node. Under plain Node, or Electron running as Node, it keeps child processes; it starts nothing to decide. `OPEN_ARTIFACT_NODE_CHILDREN=process|threads` decides instead. Starting, restarting on a type change, stopping when idle, crashes and logs behave as with processes.
17
+ - `open-artifact doctor` says how type servers run ("Type server processes"), the daemon's `/__open-artifact/health` answers it as `nodeChildren`, and the daemon log says it once.
18
+ - `examples/harness-electron` shows the utility-process start beside the default one (`OA_EXAMPLE_DAEMON=utility`).
19
+
20
+ ### Changed
21
+
22
+ - `harness.installSkill` passes `opens: 'host'` when the app gave `createHarness` an `open` callback and did not pass `opens`, so the skill the kit renders itself (no daemon, or one without `skill.get`) says the app shows pages, as the daemon's rendering does.
23
+ - When the daemon stops, it waits for type servers running in threads to end before it exits.
24
+ - A type server's state file (`.artifact-server.json`) also records its thread when it runs in one, and is removed only by the server that wrote it.
25
+
26
+ ### Fixed
27
+
28
+ - A daemon started by an Electron app with its `RunAsNode` fuse off no longer starts a copy of the app when it leaves for a newer runtime; it stops and the app's kit starts the newer one on its next connection.
29
+ - `examples/harness-electron` no longer hangs at start: it awaited `app.whenReady()` at the top level of its main module, which Electron resolves only after that module has finished.
30
+ - The type declarations in the published libraries (`@open-artifact/harness-kit`, `@open-artifact/protocol` and the rest) import `./x.js` instead of `./x.ts`, a file the package does not have. `scripts/build-npm.mjs` rewrites them and fails when one is left.
31
+ - The Shell names the harness that owns an artifact by its profile `title` instead of its id: the Ask pane ("Messages go to the Cindy session…" rather than "the cindy session"), its offline note, the open-session button and menu item, and the owner badge on the home page. A harness whose profile has no title still shows its id as it is.
32
+ - The integrator guide and the Harness API reference document the skill helpers' `opens` option (its values and its default) and what `caps.library` does: it is only recorded and shown, and can be left out by an app with no list of artifacts.
33
+
34
+ ### Integrators
35
+
36
+ - New kit option `daemon.spawn` (types `DaemonSpawn`, `DaemonStart`, `DaemonExitSource`). Without it nothing changes. The Harness API, the protocol (still 1), the Shell messages, the stdio bridge and the shipped profiles did not change, so there is no new `hello` feature.
37
+ - `env` given to `spawn` has no `ELECTRON_RUN_AS_NODE`; in a utility process `process.argv` already has the shape the daemon reads, so fork the entry as it is. Pass `OPEN_ARTIFACT_NODE_CHILDREN=threads` in that `env` to say so explicitly; an app with the fuse on that forks the daemon in a utility process and wants child processes passes `process`. A daemon in a utility process ends with the app. Details and limits in `docs/integrating/runtime.md`.
38
+ - The `.d.ts` files of the npm packages now name `.js` files in their relative imports, so a project on `moduleResolution: node16`/`nodenext`, or a tool that reads the specifiers as written, finds them. Nothing else in the declarations changed.
39
+ - An artifact's `owner` (in `GET /api/open-artifact.artifact` and the library list) has a new optional `harnessTitle`: the profile's `title`, left out when the profile has none. To have the Shell show your app's name, report it as the profile title: `createHarness({ profile: { title: 'My App' } })` (an existing option; no new `hello` feature).
40
+ - Pass `opens` to `installSkill` (and `renderSkill`, `localSkill`, `keepSkillInstalled`) so the skill tells your agent how pages open in your app: `host`, `agent-browser`, `system` or `link`. Left out, `harness.installSkill` and the daemon pick `host` when you pass `open` (an `opens` you pass wins); the standalone `installSkill(client, …)`, `renderSkill` and `localSkill` use only what you pass.
41
+
9
42
  ## [0.14.0] - 2026-11-22
10
43
 
11
44
  Build Open Artifact into your own agent product: an SDK for agent apps, pages shown inside the app, comments delivered to the right session, and a runtime that keeps itself current.
@@ -440,6 +473,7 @@ One version for every package, with Docs and Sheets in every plugin.
440
473
  - Plugins for Claude Code, Codex, Cursor, Copilot, ChatGPT and DeepSeek Harness.
441
474
  - English and Chinese READMEs, under Apache-2.0.
442
475
 
476
+ [0.14.1]: https://github.com/JimLiu/open-artifact/compare/v0.14.0...v0.14.1
443
477
  [0.14.0]: https://github.com/JimLiu/open-artifact/compare/v0.13.0...v0.14.0
444
478
  [0.13.0]: https://github.com/JimLiu/open-artifact/compare/v0.12.5...v0.13.0
445
479
  [0.12.5]: https://github.com/JimLiu/open-artifact/compare/v0.12.4...v0.12.5
package/lib/client.js CHANGED
@@ -1,4 +1,4 @@
1
- // dsh-open-artifact 0.14.0: the DSH plugin (browser half). Built by scripts/build.mjs; do not edit.
1
+ // dsh-open-artifact 0.14.1: the DSH plugin (browser half). Built by scripts/build.mjs; do not edit.
2
2
  window.__ModuleLoader__.load({
3
3
  id: "dsh-open-artifact",
4
4
  factory: (require) => {
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // dsh-open-artifact 0.14.0: the DSH plugin (server half). Built by scripts/build.mjs; do not edit.
1
+ // dsh-open-artifact 0.14.1: the DSH plugin (server half). Built by scripts/build.mjs; do not edit.
2
2
 
3
3
  // packages/harness-kit/src/daemon.ts
4
4
  import { spawn } from "node:child_process";
@@ -1129,12 +1129,26 @@ async function ensureDaemon(options = {}) {
1129
1129
  if (running) await replaceDaemon(running, 5e3);
1130
1130
  const logFile = join2(openArtifactHome(home), "logs", "daemon.out");
1131
1131
  const deadline = Date.now() + timeoutMs;
1132
+ const thrown = [];
1132
1133
  for (const attempt of plan.tries) {
1133
- const child = startDaemonProcess(attempt.bin, { env: attempt.env, ...home ? { home } : {} });
1134
1134
  let exited = false;
1135
- child.once("exit", () => {
1135
+ const onExit = () => {
1136
1136
  exited = true;
1137
- });
1137
+ };
1138
+ if (options.spawn) {
1139
+ const start = { bin: attempt.bin, args: ["daemon", "run"], env: { ...attempt.env, ...home ? { OPEN_ARTIFACT_HOME: home } : {} }, logFile };
1140
+ delete start.env.ELECTRON_RUN_AS_NODE;
1141
+ try {
1142
+ mkdirSync(join2(openArtifactHome(home), "logs"), { recursive: true });
1143
+ const started = await options.spawn(start);
1144
+ if (started && typeof started.once === "function") started.once("exit", onExit);
1145
+ } catch (error) {
1146
+ thrown.push(`${attempt.bin}: ${error?.message ?? String(error)}`);
1147
+ continue;
1148
+ }
1149
+ } else {
1150
+ startDaemonProcess(attempt.bin, { env: attempt.env, ...home ? { home } : {} }).once("exit", onExit);
1151
+ }
1138
1152
  while (Date.now() < deadline) {
1139
1153
  await new Promise((done) => setTimeout(done, 150));
1140
1154
  const state2 = await readDaemon(home);
@@ -1145,7 +1159,8 @@ async function ensureDaemon(options = {}) {
1145
1159
  }
1146
1160
  const state = await readDaemon(home);
1147
1161
  if (state) return state;
1148
- throw new OpenArtifactError("daemon_failed", `The open-artifact daemon did not start; see ${logFile}`);
1162
+ const why = thrown.length ? ` The host's start failed: ${thrown.join("; ")}.` : "";
1163
+ throw new OpenArtifactError("daemon_failed", `The open-artifact daemon did not start; see ${logFile}.${why}`);
1149
1164
  }
1150
1165
  async function api(state, name2, body, options = {}) {
1151
1166
  const url = new URL(`/api/open-artifact.${name2}`, state.url);
@@ -1396,7 +1411,7 @@ import { join as join3, resolve as resolve3 } from "node:path";
1396
1411
  // packages/harness-kit/package.json
1397
1412
  var package_default = {
1398
1413
  name: "@open-artifact/harness-kit",
1399
- version: "0.14.0",
1414
+ version: "0.14.1",
1400
1415
  private: true,
1401
1416
  type: "module",
1402
1417
  description: "The SDK an agent app uses to integrate Open Artifact: find or start the local daemon, hold a Harness API connection that reconnects, register the tools, take comment wakes and page opens, and follow the artifacts its sessions make.",
@@ -1406,7 +1421,7 @@ var package_default = {
1406
1421
  "./embed": "./src/embed/index.ts"
1407
1422
  },
1408
1423
  dependencies: {
1409
- "@open-artifact/protocol": "0.14.0"
1424
+ "@open-artifact/protocol": "0.14.1"
1410
1425
  },
1411
1426
  sideEffects: false,
1412
1427
  engines: {
@@ -1869,7 +1884,8 @@ async function createHarness(options) {
1869
1884
  };
1870
1885
  },
1871
1886
  async installSkill(opts) {
1872
- return (await keepSkillInstalled(client, opts, (listener) => harness.on("state", listener), log)).result;
1887
+ const withOpens = options.open && opts.opens === void 0 ? { ...opts, opens: "host" } : opts;
1888
+ return (await keepSkillInstalled(client, withOpens, (listener) => harness.on("state", listener), log)).result;
1873
1889
  },
1874
1890
  commands: (opts) => commands(client, opts),
1875
1891
  runtime: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-open-artifact",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Open Artifact in DeepSeek Harness: the Artifact, ArtifactData and ArtifactComments tools, comments on artifact pages waking the session that owns them, the Open Artifact page in the sidebar listing the open-artifact library, artifacts the agent opens shown in the session's Browser, and /open-artifact <type> to make a new one.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -2,7 +2,7 @@
2
2
  name: open-artifact
3
3
  description: Make an Open Artifact (a slide deck, a design canvas, a whiteboard, a data dashboard, a doc, a short animated motion piece, …) as a folder of files that opens as a live local page where the person views, edits, comments and exports, with their comments coming back to you. Use when the person types `/open-artifact <type> <what to make>`, or asks for something they will look at closely, keep, change, comment on or present - a presentation, pitch or talk deck; app screens, a mockup, a landing page, a poster, flyer or graphic, or "a few options" to look at; a brainstorm or retro board, a flowchart or an architecture sketch; a dashboard, metrics page, KPI tracker or recurring report from their data; a document, report, proposal, plan, spec, memo, notes or other writing to keep, share or comment on; a short animated video, an explainer, a promo, motion graphics or a GIF - or asks to keep or share a diagram you drew. Not for answers read once, code, or a file in a format they named.
4
4
  argument-hint: <type> <what to make>
5
- generated-by: open-artifact 0.14.0
5
+ generated-by: open-artifact 0.14.1
6
6
  etag: 04b07477a4f91b38
7
7
  ---
8
8
 
@@ -429,11 +429,11 @@ var CommentStore = class {
429
429
  return thread;
430
430
  });
431
431
  }
432
- addMessage(threadId, author, text, { resolve: resolve4 = false, to } = {}) {
432
+ addMessage(threadId2, author, text, { resolve: resolve4 = false, to } = {}) {
433
433
  const body = checkText(text);
434
434
  const recipients = checkTo(to);
435
435
  return this.mutate((doc) => {
436
- const thread = this.find(doc, threadId);
436
+ const thread = this.find(doc, threadId2);
437
437
  const at = now();
438
438
  const message = { id: newId("m_"), author, text: body, at, ...recipients ? { to: recipients } : {} };
439
439
  thread.messages.push(message);
@@ -450,11 +450,11 @@ var CommentStore = class {
450
450
  });
451
451
  }
452
452
  /** Changes the text (and recipients, when given) of `author`'s own message. */
453
- editMessage(threadId, messageId, author, text, to) {
453
+ editMessage(threadId2, messageId, author, text, to) {
454
454
  const body = checkText(text);
455
455
  const recipients = to === void 0 ? void 0 : checkTo(to);
456
456
  return this.mutate((doc) => {
457
- const thread = this.find(doc, threadId);
457
+ const thread = this.find(doc, threadId2);
458
458
  const message = findMessage(thread, messageId);
459
459
  if (!sameAuthor(message.author, author)) throw new FrameError("forbidden", "Only its author edits a comment.", 403);
460
460
  const at = now();
@@ -469,10 +469,10 @@ var CommentStore = class {
469
469
  });
470
470
  }
471
471
  /** Adds (`on`) or takes back `author`'s `emoji` on a message; adding one already there changes nothing. */
472
- react(threadId, messageId, author, emoji, on) {
472
+ react(threadId2, messageId, author, emoji, on) {
473
473
  if (typeof emoji !== "string" || !emoji.trim() || emoji.length > EMOJI_MAX) throw new FrameError("invalid_argument", "A reaction is one emoji.");
474
474
  return this.mutate((doc) => {
475
- const thread = this.find(doc, threadId);
475
+ const thread = this.find(doc, threadId2);
476
476
  const message = findMessage(thread, messageId);
477
477
  const reactions = message.reactions ?? [];
478
478
  const mine = reactions.findIndex((r) => r.emoji === emoji && sameAuthor(r.author, author));
@@ -483,25 +483,25 @@ var CommentStore = class {
483
483
  return thread;
484
484
  });
485
485
  }
486
- setResolved(threadId, resolved, by) {
486
+ setResolved(threadId2, resolved, by) {
487
487
  return this.mutate((doc) => {
488
- const thread = this.find(doc, threadId);
488
+ const thread = this.find(doc, threadId2);
489
489
  setStatus(thread, resolved ? "resolved" : "open", now(), by);
490
490
  return thread;
491
491
  });
492
492
  }
493
- move(threadId, anchor, location) {
493
+ move(threadId2, anchor, location) {
494
494
  return this.mutate((doc) => {
495
- const thread = this.find(doc, threadId);
495
+ const thread = this.find(doc, threadId2);
496
496
  thread.anchor = typeof anchor === "string" ? anchor : JSON.stringify(anchor ?? null);
497
497
  if (isObject(location)) thread.location = location;
498
498
  thread.updatedAt = now();
499
499
  return thread;
500
500
  });
501
501
  }
502
- remove(threadId, messageId) {
502
+ remove(threadId2, messageId) {
503
503
  return this.mutate((doc) => {
504
- const thread = this.find(doc, threadId);
504
+ const thread = this.find(doc, threadId2);
505
505
  if (messageId) {
506
506
  thread.messages = thread.messages.filter((m) => m.id !== messageId);
507
507
  if (thread.messages.length) {
@@ -513,9 +513,9 @@ var CommentStore = class {
513
513
  return { deleted: "thread" };
514
514
  });
515
515
  }
516
- markDelivered(threadId, via) {
516
+ markDelivered(threadId2, via) {
517
517
  return this.mutate((doc) => {
518
- const thread = this.find(doc, threadId);
518
+ const thread = this.find(doc, threadId2);
519
519
  const at = now();
520
520
  thread.agent = { status: "delivered", sentAt: thread.agent?.sentAt ?? at, deliveredAt: at, via };
521
521
  return thread;
@@ -526,9 +526,9 @@ var CommentStore = class {
526
526
  * part in the thread; only such a thread can be, and it keeps its status (nothing waits on the agent). One the agent
527
527
  * had answered remembers it (`unaskedAt`), so the agent's next reply there is marked `joined`.
528
528
  */
529
- markSent(threadId, { unasked = false } = {}) {
529
+ markSent(threadId2, { unasked = false } = {}) {
530
530
  return this.mutate((doc) => {
531
- const thread = this.find(doc, threadId);
531
+ const thread = this.find(doc, threadId2);
532
532
  if (!unasked) {
533
533
  thread.agent = { status: "pending", sentAt: now() };
534
534
  return thread;
@@ -1688,24 +1688,24 @@ var FrameSite = class {
1688
1688
  return p.canSend === false ? "no_session" : "available";
1689
1689
  }
1690
1690
  async sendToAgent(a) {
1691
- let threadId = typeof a.threadId === "string" ? a.threadId : "";
1692
- if (!threadId) {
1693
- threadId = this.comments.create({ anchor: a.anchor, label: a.label, detail: a.detail, location: { custom: a.anchor ?? null }, text: a.text, author: this.author() }).id;
1691
+ let threadId2 = typeof a.threadId === "string" ? a.threadId : "";
1692
+ if (!threadId2) {
1693
+ threadId2 = this.comments.create({ anchor: a.anchor, label: a.label, detail: a.detail, location: { custom: a.anchor ?? null }, text: a.text, author: this.author() }).id;
1694
1694
  } else if (typeof a.text === "string" && a.text.trim()) {
1695
- this.comments.addMessage(threadId, this.author(), a.text);
1695
+ this.comments.addMessage(threadId2, this.author(), a.text);
1696
1696
  }
1697
- this.comments.markSent(threadId);
1697
+ this.comments.markSent(threadId2);
1698
1698
  this.commentsChanged();
1699
- const thread = this.comments.load().threads.find((t) => t.id === threadId);
1699
+ const thread = this.comments.load().threads.find((t) => t.id === threadId2);
1700
1700
  let out;
1701
1701
  try {
1702
1702
  out = await this.ctx.agentHook.thread(agentView(thread));
1703
1703
  } catch (error) {
1704
1704
  throw new FrameError("agent_unavailable", error?.message ?? "The agent could not be reached.", 409);
1705
1705
  }
1706
- const marked = this.comments.markDelivered(threadId, out?.via === "wait" ? "wait" : "hook");
1706
+ const marked = this.comments.markDelivered(threadId2, out?.via === "wait" ? "wait" : "hook");
1707
1707
  this.commentsChanged();
1708
- return { threadId, status: out?.status ?? "delivered", thread: pageThread(marked) };
1708
+ return { threadId: threadId2, status: out?.status ?? "delivered", thread: pageThread(marked) };
1709
1709
  }
1710
1710
  async proposeTitle({ title, ifUnnamed }) {
1711
1711
  if (typeof title !== "string" || !title.trim()) return { applied: false };
@@ -2016,6 +2016,7 @@ import { appendFileSync, existsSync as existsSync5, readFileSync as readFileSync
2016
2016
  import { createServer as createServer2 } from "node:http";
2017
2017
  import { hostname as hostname2 } from "node:os";
2018
2018
  import { basename as basename2, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "node:path";
2019
+ import { threadId } from "node:worker_threads";
2019
2020
 
2020
2021
  // packages/protocol/src/refs.ts
2021
2022
  var OPEN_ARTIFACT_PROTOCOL = 1;
@@ -3144,6 +3145,7 @@ var TypeServer = class {
3144
3145
  try {
3145
3146
  const record = {
3146
3147
  pid: process.pid,
3148
+ ...threadId ? { thread: threadId } : {},
3147
3149
  url: `${this.origin}${site.page}`,
3148
3150
  port: this.port,
3149
3151
  root,
@@ -3168,7 +3170,7 @@ var TypeServer = class {
3168
3170
  try {
3169
3171
  const file = join6(entry.root, STATE_FILE);
3170
3172
  const state = JSON.parse(readFileSync6(file, "utf8"));
3171
- if (state.pid === process.pid) rmSync4(file, { force: true });
3173
+ if (state.pid === process.pid && (state.thread ?? 0) === threadId) rmSync4(file, { force: true });
3172
3174
  } catch {
3173
3175
  }
3174
3176
  try {
@@ -3420,7 +3422,7 @@ async function serve(options) {
3420
3422
  process.once("SIGTERM", stop);
3421
3423
  process.once("SIGINT", stop);
3422
3424
  server.ready();
3423
- server.log(`${server.type} type server at ${server.origin}/ (pid ${process.pid}, ${hostname2()})`);
3425
+ server.log(`${server.type} type server at ${server.origin}/ (pid ${process.pid}${threadId ? `, thread ${threadId}` : ""}, ${hostname2()})`);
3424
3426
  return server;
3425
3427
  }
3426
3428
 
@@ -40,4 +40,4 @@ Messages that start with "${fA}" or "${dA}" carry what a person typed into an ar
40
40
  `)}function YA(n){const i=[...n].filter(l=>ci(l.offer)).sort((l,r)=>l.id.localeCompare(r.id));return i.length?["<offers>","You may end a reply with one short offer to put the work into an artifact, at most once per conversation, and never in a reply that already made or changed one:",...i.map(l=>`- ${l.id}: ${ci(l.offer)}`),"</offers>"].join(`
41
41
  `):null}function qA(n={}){const i=n.types&&n.offer!==!1?YA(n.types):null;return["<open_artifact>",[jA,IA(n.toolNames)].filter(Boolean).join(`
42
42
  `),"",HA,"",LA,"",UA,"",BA,"",n.types?PA(n.types):'Call Artifact {action: "quickstart"} to see the installed artifact types.',...i?["",i]:[],"</open_artifact>"].filter(r=>r!==null).join(`
43
- `)}qA();const VA=3e4;function GA(){const n=typeof navigator>"u"?void 0:navigator.locks;return!n||typeof BroadcastChannel>"u"||typeof EventSource>"u"?null:{openSource:i=>new EventSource(i),openChannel:i=>new BroadcastChannel(i),locks:n}}function XA(n,i){const l=`open-artifact.events ${n}`,r=new Set;let u=null,f=null,d=null;const m=y=>{for(const v of[...r])try{v(y)}catch{}},h=()=>{u=i.openChannel(l),u.onmessage=v=>{typeof v.data=="string"&&m(v.data)};const y=new AbortController;f=y,i.locks.request(l,{signal:y.signal},async()=>{if(y.signal.aborted)return;const v=i.openSource(n);v.onmessage=S=>{m(S.data),u?.postMessage(S.data)},await new Promise(S=>d=S),v.close()}).catch(()=>{})},p=()=>{f?.abort(),f=null,d?.(),d=null,u?.close(),u=null};return{listen(y){return r.add(y),r.size===1&&h(),()=>{r.delete(y)&&(r.size||p())}}}}const Rb=new Map;function FA(n,i){let l=Rb.get(n);return l||(l=XA(n,i),Rb.set(n,l)),l}class vp extends Error{code;status;fix;constructor(i,l,r,u){super(l),this.name="ApiError",this.code=i,this.status=r,this.fix=u}}async function KA(n){try{const i=await n.json();return i&&typeof i=="object"?i:{}}catch{return{}}}const QA=15e3;async function ZA(n){const i=await KA(n);if(!n.ok){const l=typeof i.code=="string"?i.code:"error",r=typeof i.message=="string"?i.message:`HTTP ${n.status}`;throw new vp(l,r,n.status,typeof i.fix=="string"?i.fix:void 0)}return i}function WA(n={}){const i=(n.base??"").replace(/\/$/,""),l=n.fetch??((f,d)=>fetch(f,d)),r=(f,d)=>`${i}/api/open-artifact.${f}${d?`?${new URLSearchParams(d)}`:""}`;async function u(f,d={}){const m=d.body===void 0?{cache:"no-store"}:{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d.body)};d.body===void 0&&typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"&&(m.signal=AbortSignal.timeout(d.timeoutMs??QA));let h;try{h=await l(r(f,d.query),m)}catch(p){throw new vp("connect_failed",p instanceof Error?p.message:String(p),0)}return ZA(h)}return{async artifacts(){const f=await u(Kt.artifacts);return Array.isArray(f.artifacts)?f.artifacts:[]},artifact:f=>u(Kt.artifact,{query:{id:f}}),async types(){const f=await u(Kt.types);return{roots:Array.isArray(f.roots)?f.roots:[],types:Array.isArray(f.types)?f.types:[]}},share:f=>u(Kt.share,{query:{id:f}}),setShare:f=>u(Kt.share,{body:f}),create:f=>u(Kt.create,{body:f}),update:f=>u(Kt.update,{body:f}),duplicate:(f,d)=>u(Kt.duplicate,{body:{id:f,...d&&{name:d}}}),remove:f=>u(Kt.delete,{body:{id:f}}),restore:f=>u(Kt.restore,{body:{id:f}}),async trashed(){const f=await u(Kt.artifacts,{query:{trashed:"1"}});return Array.isArray(f.artifacts)?f.artifacts:[]},purge:f=>u("artifacts.purge",{body:{id:f}}),ask:f=>u(Kt.ask,{body:f}),open:f=>u(Kt.open,{body:{id:f,host:!1}}),boot:(f,d)=>u(Kt.boot,{query:d?.fresh?{id:f,fresh:"1"}:{id:f},timeoutMs:VA}),async remotes(){const f=await u("remotes"),d=f.cloud&&typeof f.cloud=="object"&&Array.isArray(f.cloud.pending)?f.cloud:null;return{remotes:Array.isArray(f.remotes)?f.remotes:[],cloud:d}},cloudSettings:f=>u("cloud.settings",{body:f}),connect:(f,d)=>u("remotes.add",{body:{name:f,host:d,browse:!1}}),connectCancel:f=>u("remotes.add.cancel",{body:{name:f}}),connectWait:(f,d)=>u("remotes.add.wait",{body:{name:f,ms:d}}),publish:(f,d,m={})=>u("artifacts.publish",{body:{id:f,remote:d,...m.data?{data:!0}:{}}}),unpublish:f=>u("artifacts.unpublish",{body:{id:f}}),dataPublish:(f,d={})=>u("artifacts.data",{body:{id:f,...d}}),eventsUrl:r(Kt.events),archiveUrl:f=>r(Kt.archive,{id:f}),typeIconUrl:f=>r("type.icon",{id:f})}}const xn=WA();function Fn(n){return n instanceof Error?n.message:String(n)}const JA=new Set(["artifacts/changed","types/changed","harness/changed","wake/state"]);function $A(n){try{const i=JSON.parse(n);if(!i||typeof i!="object")return null;const l=i.type;return typeof l=="string"&&JA.has(l)?i:null}catch{return null}}function e2(n,i={}){const l=i.url??xn.eventsUrl,r=m=>{const h=$A(m);h&&n(h)},u=i.shared!==void 0?i.shared:i.EventSource?null:GA();if(u)return FA(l,u).listen(r);const f=i.EventSource??(typeof EventSource>"u"?null:EventSource);if(!f)return()=>{};let d;try{d=new f(l)}catch{return()=>{}}return d.onmessage=m=>r(m.data),()=>d.close()}function md(n,i=Date.now(),l=bp){if(!n)return"";const r=Date.parse(n);if(!Number.isFinite(r))return"";const u=Math.max(0,(i-r)/1e3);if(u<60)return he("justNow");const f=new Intl.RelativeTimeFormat(l,{numeric:"auto"});return u<3600?f.format(-Math.round(u/60),"minute"):u<86400?f.format(-Math.round(u/3600),"hour"):u<86400*30?f.format(-Math.round(u/86400),"day"):new Date(r).toLocaleDateString(l)}function t2(n){const i=String(n??"").trim();if(!i)return"?";if(/^[぀-ヿ㐀-鿿가-힯]/.test(i))return[...i][0];const l=i.split(/\s+/);return((l[0]?.[0]??"")+(l[1]?.[0]??"")).toUpperCase()||"?"}const Cb=["#0f766e","#4f46e5","#b45309","#7c3aed","#be185d","#0369a1","#4d7c0f","#9f1239"];function n2(n){let i=0;for(const l of n)i=i*31+l.charCodeAt(0)|0;return Cb[Math.abs(i)%Cb.length]}async function o2(n){try{await navigator.clipboard.writeText(n)}catch{const i=document.createElement("textarea");i.value=n,i.style.position="fixed",i.style.opacity="0",document.body.append(i),i.select(),document.execCommand("copy"),i.remove()}}const i2="__OPEN_ARTIFACT_HOME__";function a2(n){if(!n||typeof n!="object")return{};const i=n.cloud;if(!i||typeof i!="object")return{};const l=i;if(typeof l.signInUrl!="string"||typeof l.signOutUrl!="string"||typeof l.appOrigin!="string")return{};const r=l.user&&typeof l.user=="object"&&typeof l.user.id=="string"&&typeof l.user.name=="string"?l.user:null,u=typeof l.trashDays=="number"&&Number.isInteger(l.trashDays)&&l.trashDays>=0?l.trashDays:void 0,f=l.limits&&typeof l.limits=="object"?l.limits.importBytes:void 0,d=typeof f=="number"&&Number.isInteger(f)&&f>0?{importBytes:f}:void 0,m=Sp(l.site);return{cloud:{user:r,appOrigin:l.appOrigin,signInUrl:l.signInUrl,signOutUrl:l.signOutUrl,...u!==void 0?{trashDays:u}:{},...d?{limits:d}:{},...m?{site:m}:{}}}}function Yf(n){return typeof n!="string"||n.length===0||n.length>2048||/[\u0000-\u001f\u007f]/.test(n)?!1:n.startsWith("/")?!n.startsWith("//")&&!n.includes("\\"):/^https?:\/\//i.test(n)}function Ob(n,i){if(typeof n!="string")return null;const l=n.trim();return l.length>0&&l.length<=i?l:null}function Sp(n){if(!n||typeof n!="object")return;const i=n,l=[];if(Array.isArray(i.links))for(const u of i.links){if(!u||typeof u!="object")continue;const{label:f,href:d,where:m}=u,h=Ob(f,80);h&&Yf(d)&&(m==="account-menu"||m==="home")&&l.push({label:h,href:d,where:m})}let r;if(i.brand&&typeof i.brand=="object"){const{name:u,logoUrl:f}=i.brand,d=Ob(u,80);(d||Yf(f))&&(r={...d?{name:d}:{},...Yf(f)?{logoUrl:f}:{}})}if(!(l.length===0&&!r))return{...l.length>0?{links:l}:{},...r?{brand:r}:{}}}function Q0(n,i){return(Sp(n)?.links??[]).filter(l=>l.where===i).map(({label:l,href:r})=>({label:l,href:r}))}function Z0(n,i){if(n.startsWith("/"))return!1;try{return new URL(n).origin!==i}catch{return!0}}function l2(n,i,l){let r;try{r=new URL(n,l)}catch{return n}return!r.searchParams.has("return_to")&&i.startsWith("/")&&!i.startsWith("//")&&r.searchParams.set("return_to",i),r.origin===l?`${r.pathname}${r.search}${r.hash}`:r.href}function W0(n){if(!n||typeof n!="object")return null;const i=n.accessLogoutUrl;if(typeof i!="string")return null;try{const l=new URL(i);return l.protocol==="https:"||l.protocol==="http:"?l.href:null}catch{return null}}function r2(n){if(!n||typeof n!="object")return!1;if(J0(n))return!0;const i=n.providers;return Array.isArray(i)&&i.some(l=>!!l&&typeof l=="object"&&l.id==="cloudflare-access")}function J0(n){return W0(n)}async function s2(){try{const n=await fetch(`/api/open-artifact.${Kt.embed}`,{cache:"no-store",signal:AbortSignal.timeout(3e3)});if(!n.ok)return null;const i=await n.json();return Array.isArray(i.hosts)?i.hosts.filter(l=>typeof l=="string"):null}catch{return null}}const u2=["design"];function Ab(n){return Date.parse(n.contentAt||n.updatedAt||n.createdAt||"")||0}function c2(n,i){if(!i||!i.harness&&!i.workspace)return[...n];const l=f=>f.replace(/[\\/]+$/,""),r=i.workspace?l(i.workspace):null,u=f=>{if(!r||!f)return!1;const d=l(f);return d===r||d.startsWith(`${r}/`)||d.startsWith(`${r}\\`)};return n.filter(f=>(!i.harness||f.owner?.harness===i.harness)&&(!r||u(f.owner?.workspace)||u(f.root)))}function f2(n){return[...n].sort((i,l)=>Number(l.pinned)-Number(i.pinned)||Ab(l)-Ab(i))}function d2(n){return n.enabled&&n.runnable&&!n.shadowedBy}function $0(n){return d2(n)&&u2.includes(n.id)}function p2(n){return n.find($0)??null}function h2(n){return n?n.live?n.status==="running"?"working":"idle":"offline":"none"}function g2(n,i){return n.map(l=>l.id===i.id?i:l)}function m2(n,i){return n.filter(l=>l.id!==i)}function y2(n,i,l){const r=yA(n);return!r||r.openArtifact!=="host_hello"?null:{origin:i,caps:r.caps,harness:r.harness??null,agentName:r.agentName??null,declared:l,library:r.library??null}}const Mb=n=>{let i;const l=new Set,r=(p,y)=>{const v=typeof p=="function"?p(i):p;if(!Object.is(v,i)){const S=i;i=y??(typeof v!="object"||v===null)?v:Object.assign({},i,v),l.forEach(w=>w(i,S))}},u=()=>i,m={setState:r,getState:u,getInitialState:()=>h,subscribe:p=>(l.add(p),()=>l.delete(p))},h=i=n(r,u,m);return m},b2=(n=>n?Mb(n):Mb),v2=n=>n;function S2(n,i=v2){const l=kl.useSyncExternalStore(n.subscribe,kl.useCallback(()=>i(n.getState()),[n,i]),kl.useCallback(()=>i(n.getInitialState()),[n,i]));return kl.useDebugValue(l),l}const x2=n=>{const i=b2(n),l=r=>S2(i,r);return Object.assign(l,i),l},T2=(n=>x2);function E2(n,i){switch(i.type){case"start":return n.kind==="sending"||n.kind==="checking"?n:{kind:"sending",name:i.name,loaded:0,total:i.size};case"progress":return n.kind!=="sending"?n:{...n,loaded:Math.max(n.loaded,i.loaded),total:i.total||n.total};case"sent":return n.kind==="sending"?{kind:"checking",name:n.name}:n;case"done":return n.kind==="sending"||n.kind==="checking"?{kind:"done",name:n.name,id:i.id}:n;case"failed":return n.kind==="idle"||n.kind==="done"?n:{kind:"failed",name:n.name,said:i.said};case"dismiss":return n.kind==="failed"?{kind:"idle"}:n}}function eS(n){return n.kind==="sending"||n.kind==="checking"||n.kind==="done"}function w2(n){return n.kind==="checking"||n.kind==="done"?100:n.kind!=="sending"||n.total<=0?null:Math.min(100,Math.floor(n.loaded/n.total*100))}function R2(n){const i=n.type.toLowerCase();return/\.zip$/i.test(n.name)||i==="application/zip"||i==="application/x-zip-compressed"}function C2(n){if(!n.length)return null;const i=n.find(R2);return i?{file:i}:{said:{key:"uploadNotZip"}}}function O2(n,i){return i===void 0||!(i>0)||n<=i?null:{key:"uploadTooLargeLimit",vars:{limit:tS(i)}}}function A2(n){return!!n&&n.includes("Files")}function tS(n){if(n<1024)return`${n} B`;const i=["KB","MB","GB"];let l=n/1024,r=0;for(;l>=1024&&r<i.length-1;)l/=1024,r++;return`${l>=10||Number.isInteger(l)?Math.round(l):l.toFixed(1)} ${i[r]}`}function M2(n){const i=/(\d{4,})\s*bytes/i.exec(n);if(!i)return null;const l=Number(i[1]);return Number.isFinite(l)&&l>0?tS(l):null}function Db(n){const{status:i,code:l,message:r}=n;if(i===0)return{key:"uploadNoAnswer"};if(i===401)return{key:"uploadSignedOut"};if(i===403)return{key:"uploadNotAllowed"};if(i===413||l==="too_large"){const u=M2(r);return u?{key:"uploadTooLargeLimit",vars:{limit:u}}:r?{key:"uploadTooLargeSaid",vars:{error:r}}:{key:"uploadTooLarge"}}if(i===415)return{key:"uploadNotZip"};if(i===409)return{key:"uploadConflict"};if(i===400){const u=/The (\S+) type is not installed/.exec(r)?.[1];return l==="unsupported"||u?u?{key:"uploadTypeMissing",vars:{type:u}}:{key:"uploadFailed",vars:{error:r}}:{key:"uploadNotArtifact"}}return i===429?{key:"uploadBusy"}:{key:"uploadFailed",vars:{error:r||`HTTP ${i}`}}}function D2(n,i){let l="error",r="";try{const u=JSON.parse(i);if(u&&typeof u=="object"){const f=u;typeof f.code=="string"&&(l=f.code),typeof f.message=="string"&&(r=f.message)}}catch{}return{status:n,code:l,message:r}}function N2(n){try{const i=JSON.parse(n),l=i&&typeof i=="object"?i.id:void 0;return typeof l=="string"&&l?l:null}catch{return null}}function z2(n=typeof location>"u"?"":location.hash){return n==="#trash"?"trash":"artifacts"}const nS="open-artifact.tab";function _2(){try{return localStorage.getItem(nS)==="types"?"types":"artifacts"}catch{return"artifacts"}}const ze=T2()(n=>({tab:_2(),artifacts:null,types:null,error:null,host:null,creating:null,renaming:null,undo:null,cloudTab:z2(),trash:null,purgeUnsupported:!1,purging:null,upload:{kind:"idle"},setTab:i=>{try{localStorage.setItem(nS,i)}catch{}n({tab:i})},setArtifacts:i=>n({artifacts:i}),setTypes:i=>n({types:i}),setError:i=>n({error:i}),setHost:i=>n({host:i}),setCreating:i=>n({creating:i}),setRenaming:i=>n({renaming:i}),setUndo:i=>n({undo:i}),setCloudTab:i=>n({cloudTab:i}),setTrash:i=>n({trash:i}),setPurgeUnsupported:()=>n({purgeUnsupported:!0}),setPurging:i=>n({purging:i}),uploadEvent:i=>n(l=>({upload:E2(l.upload,i)}))})),to=a2(window[i2]),oS=window.parent!==window;function iS(n){const i=ze.getState().host;i&&window.parent.postMessage(n,i.origin)}function Nb(n){const i=n.data;if(!oS||n.source!==window.parent||!bA(i)||i.openArtifact!=="host_hello")return;const l=n.origin;s2().then(r=>{const u=!!r?.length&&r.includes(l);if(r?.length&&!u)return;const f=y2(i,l,u);f&&(ze.getState().setHost(f),window.parent.postMessage({openArtifact:"home_ready"},l))})}function k2(){return window.addEventListener("message",Nb),oS&&window.parent.postMessage({openArtifact:"home_hello"},"*"),()=>window.removeEventListener("message",Nb)}function j2(n){return n.map(i=>({id:i.id,title:i.title,typeTitle:i.typeTitle,when:typeof i.trashedAt=="string"&&i.trashedAt?{kind:"trashed",at:i.trashedAt}:{kind:"changed",at:i.updatedAt},mine:i.role===void 0||i.role==="owner"})).sort((i,l)=>(Date.parse(l.when.at)||0)-(Date.parse(i.when.at)||0))}function H2(n){return n===void 0||!Number.isInteger(n)||n<0?null:n===0?{key:"trashKeptForever"}:n===1?{key:"trashKeptOneDay"}:{key:"trashKeptDays",vars:{days:n}}}function L2(n,i){return n.mine&&!i}function U2(n,i){return n===501?{unsupported:!0}:n===409?{unsupported:!1,said:{key:"purgeNotTrashed"}}:n===404?{unsupported:!1,said:{key:"purgeGone"}}:{unsupported:!1,said:{key:"couldNotPurge",vars:{error:i||`HTTP ${n}`}}}}const Ln=n=>{yp.add({title:n})},au=n=>`/a/${encodeURIComponent(n)}`;function qf(n){ze.getState().host?.caps.artifacts?iS({openArtifact:"open_artifact",url:n.url,id:n.id,title:n.title,type:n.type}):location.href=au(n.id)}async function Fl(){try{ze.getState().setArtifacts(await xn.artifacts()),ze.getState().setError(null)}catch(n){ze.getState().setError(he("couldNotLoad",{error:Fn(n)}))}}function B2(n){window.open(n,"_blank","noopener")}async function I2(n){await o2(n),Ln(he("webLinkCopied"))}async function aS(){try{ze.getState().setTypes(await xn.types())}catch(n){ze.getState().setError(he("couldNotLoad",{error:Fn(n)}))}}const lS=n=>{const i=ze.getState().artifacts;i&&ze.getState().setArtifacts(g2(i,n))};async function P2(n){const i=!n.pinned;try{lS(await xn.update({id:n.id,pinned:i}))}catch(l){Ln(he(i?"couldNotPin":"couldNotUnpin",{error:Fn(l)}))}}async function Y2(n,i){const l=i.trim();if(!(!l||l===n.title))try{lS(await xn.update({id:n.id,title:l}))}catch(r){Ln(he("couldNotRename",{error:Fn(r)}))}}async function q2(n){try{await xn.duplicate(n.id),Ln(he("duplicated")),await Fl()}catch(i){Ln(he("couldNotDuplicate",{error:Fn(i)}))}}let Vf=null;async function zb(n){const i=ze.getState(),l=i.artifacts;l&&i.setArtifacts(m2(l,n.id));try{await xn.remove(n.id),i.setUndo({id:n.id,title:n.title,...to.cloud?{trash:!0}:{}}),ze.getState().trash&&Ba(),Vf&&clearTimeout(Vf),Vf=setTimeout(()=>{ze.getState().undo?.id===n.id&&ze.getState().setUndo(null)},8e3)}catch(r){l&&i.setArtifacts(l),Ln(he("couldNotDelete",{error:Fn(r)}))}}async function V2(){const n=ze.getState().undo;if(n){ze.getState().setUndo(null);try{await xn.restore(n.id),Ln(he("restored")),await Fl(),ze.getState().trash&&Ba()}catch(i){Ln(he("couldNotRestore",{error:Fn(i)}))}}}async function Ba(){try{ze.getState().setTrash(await xn.trashed())}catch(n){ze.getState().setError(he("couldNotLoad",{error:Fn(n)}))}}async function G2(n){const i=ze.getState(),l=i.trash;l&&i.setTrash(l.filter(r=>r.id!==n.id));try{await xn.restore(n.id),Ln(he("restoredTitle",{title:n.title})),await Promise.all([Fl(),Ba()])}catch(r){l&&ze.getState().setTrash(l),Ln(he("couldNotRestore",{error:Fn(r)}))}}async function X2(n){try{await xn.purge(n.id);const i=ze.getState().trash;i&&ze.getState().setTrash(i.filter(l=>l.id!==n.id)),Ln(he("purged",{title:n.title}))}catch(i){const l=i instanceof vp?i.status:0,r=U2(l,Fn(i));r.unsupported?ze.getState().setPurgeUnsupported():Ln(he(r.said.key,r.said.vars)),Ba()}}const F2="/api/open-artifact.artifacts.import";function rS(n){const i=ze.getState();if(eS(i.upload))return;const l=C2(n);if(!l)return;if("said"in l){const d=n[0]?.name??"";i.uploadEvent({type:"start",name:d,size:0}),i.uploadEvent({type:"failed",said:l.said});return}const r=l.file;i.uploadEvent({type:"start",name:r.name,size:r.size});const u=O2(r.size,to.cloud?.limits?.importBytes);if(u){i.uploadEvent({type:"failed",said:u});return}const f=new XMLHttpRequest;f.open("POST",F2),f.setRequestHeader("Content-Type",cA),f.upload.onprogress=d=>ze.getState().uploadEvent({type:"progress",loaded:d.loaded,total:d.lengthComputable?d.total:0}),f.upload.onload=()=>ze.getState().uploadEvent({type:"sent"}),f.onload=()=>{const d=f.status===201||f.status===200?N2(f.responseText):null;if(d){ze.getState().uploadEvent({type:"done",id:d}),location.href=au(d);return}ze.getState().uploadEvent({type:"failed",said:Db(D2(f.status,f.responseText))})},f.onerror=()=>ze.getState().uploadEvent({type:"failed",said:Db({status:0,code:"connect_failed",message:""})}),f.send(r)}async function K2(n,i,l){if(!i.trim())return he("needTitle");try{const r=await xn.create({type:n.id,title:i.trim(),...l.trim()?{folder:l.trim()}:{}});return location.href=au(r.id),null}catch(r){return he("couldNotCreate",{error:Fn(r)})}}function Q2(n){n.owner&&iS({openArtifact:"open_session",session:n.owner.session,harness:n.owner.harness})}function Z2(){let n=null,i=!1;const l=e2(r=>{r.type==="types/changed"&&(i=!0),n&&clearTimeout(n),n=setTimeout(()=>{Fl(),i&&!to.cloud&&aS(),to.cloud&&ze.getState().cloudTab==="trash"&&Ba(),i=!1},200)});return()=>{n&&clearTimeout(n),l()}}const W2={none:"statusNone",working:"statusWorking",idle:"statusIdle",waiting:"statusWaiting",offline:"statusOffline"};function J2({state:n,className:i}){return E.jsx("span",{"aria-hidden":"true",className:zo("inline-block size-2 shrink-0 rounded-full",n==="working"?"animate-pulse bg-accent motion-reduce:animate-none":n==="idle"||n==="waiting"?"bg-success":"bg-fg-subtle",i)})}function $2({state:n,prefix:i,label:l,className:r}){const u=l??he(W2[n]);return E.jsxs("span",{className:zo("inline-flex min-w-0 items-center gap-1.5 text-xs text-fg-muted",r),children:[E.jsx(J2,{state:n}),E.jsx("span",{className:"truncate",children:i?`${i} · ${u}`:u})]})}function Eo({children:n}){return E.jsx("span",{className:"inline-flex max-w-full items-center gap-1 truncate rounded-full bg-surface-2 px-2 py-px text-xs text-fg-muted",children:n})}function eM({artifact:n}){const i=ze(p=>p.host),l=to.cloud?void 0:n.remote?.url,r=au(n.id),u=!to.cloud,f=!u&&n.role==="owner",d=u||n.role===void 0||n.role==="owner"||n.role==="editor",m=u&&!!(i?.caps.sessions&&n.owner?.session&&(!i.harness||n.owner.harness===i.harness)),h=p=>{p.target.closest('a, button, [role="menu"]')||getSelection()?.toString()||qf(n)};return E.jsxs("div",{onClick:h,className:"group flex min-w-0 cursor-pointer flex-col overflow-hidden rounded-xl border border-line bg-surface transition-[border-color,box-shadow] hover:border-line-strong hover:shadow-popup",children:[n.thumbnail?E.jsx("img",{src:n.thumbnail,alt:"",loading:"lazy",className:"aspect-[16/9] w-full border-b border-line bg-surface-2 object-cover object-top"}):null,E.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5 p-3.5",children:[E.jsxs("a",{href:r,className:"flex min-w-0 items-center gap-1.5 break-words font-semibold text-fg no-underline hover:text-accent",onClick:p=>{!i?.caps.artifacts||p.metaKey||p.ctrlKey||p.shiftKey||(p.preventDefault(),qf(n))},children:[n.pinned?E.jsx(gb,{className:"size-3.5 shrink-0 text-fg-muted","aria-label":he("pinned")}):null,E.jsx("span",{className:"min-w-0",children:n.title}),l?E.jsx("span",{title:he("pubCloudAt",{url:l}),"data-home-published":"",className:"inline-flex shrink-0 text-accent",children:E.jsx(DC,{className:"size-3.5","aria-label":he("pubCloudMark")})}):null]}),E.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[E.jsx(Eo,{children:n.typeTitle}),u?E.jsx(Eo,{children:E.jsx($2,{state:h2(n.owner),prefix:n.owner?.harness})}):null,u&&n.open?E.jsx(Eo,{children:he("pageOpen")}):null]}),n.typeMissing?E.jsxs("div",{className:"flex items-center gap-1 text-xs text-warning",children:[E.jsx(tu,{className:"size-3.5"}),he("typeMissing")]}):null,u?E.jsx("div",{className:"break-all text-xs text-fg-muted",title:n.root,children:n.root}):null,E.jsx("div",{className:"text-xs text-fg-muted",children:he("updated",{when:md(n.contentAt||n.updatedAt)})}),E.jsxs("div",{className:"mt-auto flex items-center gap-1.5 pt-1",children:[E.jsx(fn,{size:"sm",variant:"primary",onClick:()=>qf(n),children:he("open")}),m?E.jsx(fn,{size:"sm",icon:E.jsx(HC,{className:"size-3"}),onClick:()=>Q2(n),children:he("backToSession")}):null,E.jsx("span",{className:"flex-1"}),E.jsxs(H0,{align:"end",trigger:E.jsx(o0,{label:he("moreActions"),icon:E.jsx(zC,{className:"size-4"}),size:"sm",noTooltip:!0}),children:[E.jsx(To,{icon:n.pinned?E.jsx(UC,{className:"size-3.5"}):E.jsx(gb,{className:"size-3.5"}),onSelect:()=>{P2(n)},children:n.pinned?he("unpin"):he("pin")}),l?E.jsxs(E.Fragment,{children:[E.jsx(To,{icon:E.jsx(fp,{className:"size-3.5"}),onSelect:()=>B2(l),children:he("openOnWeb")}),E.jsx(To,{icon:E.jsx(_C,{className:"size-3.5"}),onSelect:()=>{I2(l)},children:he("copyWebLink")})]}):null,d?E.jsx(To,{icon:E.jsx(LC,{className:"size-3.5"}),onSelect:()=>ze.getState().setRenaming(n),children:he("rename")}):null,u?E.jsxs(E.Fragment,{children:[E.jsx(To,{icon:E.jsx(NC,{className:"size-3.5"}),onSelect:()=>{q2(n)},children:he("duplicate")}),E.jsx(ks,{}),E.jsx(To,{icon:E.jsx(dd,{className:"size-3.5"}),danger:!0,onSelect:()=>{zb(n)},children:he("delete")})]}):null,f?E.jsxs(E.Fragment,{children:[E.jsx(ks,{}),E.jsx(To,{icon:E.jsx(dd,{className:"size-3.5"}),danger:!0,onSelect:()=>{zb(n)},children:he("moveToTrash")})]}):null]})]})]})]})}function yd(){const n=ze(r=>r.artifacts),i=ze(r=>r.host?.library??null),l=n&&i?c2(n,i):n;return l===null?E.jsx("p",{className:"py-8 text-fg-muted",children:he("loading")}):l.length?E.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3",children:f2(l).map(r=>E.jsx(eM,{artifact:r},r.id))}):E.jsx(mp,{title:he("artifacts"),children:he(to.cloud?"noArtifactsCloud":"noArtifacts")})}function tM(){const n=b.useRef(null),i=ze(l=>eS(l.upload));return E.jsxs(E.Fragment,{children:[E.jsx(fn,{size:"lg",icon:E.jsx(k0,{className:"size-3.5"}),disabled:i,title:he("uploadHint"),onClick:()=>n.current?.click(),children:he("upload")}),E.jsx("input",{ref:n,type:"file",accept:".zip,application/zip,application/x-zip-compressed","data-home-upload":"",className:"hidden",onChange:l=>{const r=[...l.target.files??[]];l.target.value="",rS(r)}})]})}function nM(){const n=ze(r=>r.upload);if(n.kind==="idle")return null;if(n.kind==="failed")return E.jsxs("div",{role:"alert","data-home-upload-error":"",className:"mb-3 flex items-start gap-2 rounded-lg border border-line bg-surface p-3 text-[13px]",children:[E.jsx(tu,{className:"mt-px size-4 shrink-0 text-danger"}),E.jsx("span",{className:"min-w-0 flex-1 break-words",children:he(n.said.key,n.said.vars)}),E.jsx(o0,{label:he("dismiss"),size:"sm",noTooltip:!0,icon:E.jsx(dp,{className:"size-3.5"}),onClick:()=>ze.getState().uploadEvent({type:"dismiss"})})]});const i=w2(n),l=n.kind==="done"?he("uploadOpening",{name:n.name}):n.kind==="checking"?he("uploadChecking",{name:n.name}):i===null?he("uploadSendingSize",{name:n.name}):he("uploadSending",{name:n.name,percent:i});return E.jsxs("div",{role:"status","data-home-upload-state":n.kind,className:"mb-3 rounded-lg border border-line bg-surface p-3 text-[13px]",children:[E.jsx("div",{className:"mb-2 truncate",children:l}),E.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-surface-2",children:E.jsx("div",{className:"h-full rounded-full bg-accent transition-[width] duration-150",style:{width:`${i??5}%`}})})]})}function oM({children:n}){const[i,l]=b.useState(!1),r=b.useRef(0),u=!!to.cloud?.user,f=d=>u&&A2([...d.dataTransfer.types]);return E.jsxs("div",{className:"relative","data-home-drop":i?"over":"",onDragEnter:d=>{f(d)&&(d.preventDefault(),r.current++,l(!0))},onDragOver:d=>{f(d)&&(d.preventDefault(),d.dataTransfer.dropEffect="copy")},onDragLeave:d=>{f(d)&&(r.current=Math.max(0,r.current-1),r.current||l(!1))},onDrop:d=>{f(d)&&(d.preventDefault(),r.current=0,l(!1),rS([...d.dataTransfer.files]))},children:[n,i?E.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 grid min-h-32 place-items-center rounded-xl border-2 border-dashed border-accent bg-surface/80 text-[13px] font-medium text-accent",children:E.jsxs("span",{className:"flex items-center gap-2",children:[E.jsx(k0,{className:"size-4"}),he("uploadDrop")]})}):null]})}function iM({row:n}){const i=ze(l=>l.purgeUnsupported);return E.jsxs("div",{"data-home-trashed":n.id,className:"flex min-w-0 flex-wrap items-center gap-3 rounded-xl border border-line bg-surface p-3.5",children:[E.jsxs("div",{className:"min-w-0 flex-1",children:[E.jsx("div",{className:"break-words font-semibold",children:n.title}),E.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5 text-xs text-fg-muted",children:[E.jsx(Eo,{children:n.typeTitle}),E.jsx("span",{children:n.when.kind==="trashed"?he("trashedWhen",{when:md(n.when.at)}):he("updated",{when:md(n.when.at)})})]})]}),n.mine?E.jsxs("div",{className:"flex items-center gap-1.5",children:[E.jsx(fn,{size:"sm",icon:E.jsx(BC,{className:"size-3"}),onClick:()=>{G2(n)},children:he("restore")}),L2(n,i)?E.jsx(fn,{size:"sm",variant:"ghost",className:"text-danger",icon:E.jsx(dd,{className:"size-3"}),onClick:()=>ze.getState().setPurging({id:n.id,title:n.title}),children:he("deleteForever")}):null]}):null]})}function aM(){const n=ze(u=>u.trash);b.useEffect(()=>{Ba()},[]);const i=H2(to.cloud?.trashDays),l=E.jsxs("p",{className:"mb-3 mt-0 text-xs text-fg-muted",children:[he("trashNote"),i?` ${he(i.key,i.vars)}`:""]});if(n===null)return E.jsx("p",{className:"py-8 text-fg-muted",children:he("loading")});const r=j2(n);return E.jsxs("div",{"data-home-trash":"",children:[l,r.length?E.jsx("div",{className:"flex flex-col gap-2",children:r.map(u=>E.jsx(iM,{row:u},u.id))}):E.jsx(mp,{title:he("trash"),children:he("trashEmpty")})]})}function lM(){const n=ze(l=>l.purging),i=()=>ze.getState().setPurging(null);return E.jsx(pp,{open:!!n,onOpenChange:l=>!l&&i(),title:n?he("purgeTitle",{title:n.title}):"",description:he("purgeBody"),footer:E.jsxs(E.Fragment,{children:[E.jsx(fn,{size:"lg",onClick:i,children:he("cancel")}),E.jsx(fn,{size:"lg",variant:"danger",onClick:()=>{n&&X2(n),i()},children:he("deleteForever")})]})})}function rM(){const n=ze(i=>i.cloudTab);return E.jsx(K0,{value:n,onChange:i=>ze.getState().setCloudTab(i),className:"[&>[role=tabpanel]]:overflow-visible [&>[role=tabpanel]]:pt-4 [&_[role=tab][aria-selected=true]]:bg-hover [&_[role=tab][aria-selected=true]]:text-fg",items:[{value:"artifacts",label:he("artifacts"),content:E.jsxs(oM,{children:[E.jsx(nM,{}),E.jsx(yd,{})]})},{value:"trash",label:he("trash"),content:E.jsx(aM,{})}]})}function bd({label:n,children:i}){return E.jsxs("label",{className:"mt-3 block",children:[E.jsx("span",{className:"mb-1 block text-xs text-fg-muted",children:n}),i]})}function sM(){const n=ze(y=>y.creating),[i,l]=b.useState(""),[r,u]=b.useState(""),[f,d]=b.useState(""),[m,h]=b.useState(!1);b.useEffect(()=>{n&&(l(""),u(""),d(""))},[n]);const p=async y=>{if(y.preventDefault(),!n||m)return;h(!0);const v=await K2(n,i,r);h(!1),v&&d(v)};return E.jsx(pp,{open:!!n,onOpenChange:y=>!y&&ze.getState().setCreating(null),title:n?he("newOf",{type:n.title}):"",description:n?.description?n.description.slice(0,160):void 0,children:E.jsxs("form",{onSubmit:y=>{p(y)},children:[E.jsx(bd,{label:he("title"),children:E.jsx(hd,{autoFocus:!0,required:!0,value:i,maxLength:200,onChange:y=>l(y.target.value),className:"h-8"})}),E.jsx(bd,{label:he("folderOptional"),children:E.jsx(hd,{value:r,placeholder:he("folderHint"),onChange:y=>u(y.target.value),className:"h-8"})}),f?E.jsx("p",{role:"alert",className:"mb-0 mt-2 text-xs text-danger",children:f}):null,E.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[E.jsx(fn,{size:"lg",onClick:()=>ze.getState().setCreating(null),children:he("cancel")}),E.jsx(fn,{size:"lg",type:"submit",variant:"primary",disabled:m||!i.trim(),children:he("create")})]})]})})}function uM(){const n=ze(u=>u.renaming),[i,l]=b.useState("");b.useEffect(()=>l(n?.title??""),[n]);const r=()=>ze.getState().setRenaming(null);return E.jsx(pp,{open:!!n,onOpenChange:u=>!u&&r(),title:he("renameArtifact"),children:E.jsxs("form",{onSubmit:u=>{u.preventDefault(),n&&Y2(n,i),r()},children:[E.jsx(bd,{label:he("title"),children:E.jsx(hd,{autoFocus:!0,value:i,maxLength:200,onChange:u=>l(u.target.value),className:"h-8"})}),E.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[E.jsx(fn,{size:"lg",onClick:r,children:he("cancel")}),E.jsx(fn,{size:"lg",type:"submit",variant:"primary",disabled:!i.trim(),children:he("save")})]})]})})}function cM(){const n=ze(i=>i.undo);return n?E.jsxs("div",{role:"status",className:"fixed bottom-5 left-1/2 z-[1100] flex max-w-[calc(100vw-32px)] -translate-x-1/2 items-center gap-3 rounded-lg bg-fg px-3.5 py-2 text-[13px] text-surface shadow-popup",children:[E.jsx("span",{className:"min-w-0 truncate",children:he(n.trash?"movedToTrash":"deleted",{title:n.title})}),E.jsx("button",{type:"button",className:"shrink-0 font-semibold text-surface underline-offset-2 hover:underline",onClick:()=>{V2()},children:he("undo")})]}):null}function fM({type:n}){const[i,l]=b.useState(!1);return!n.icon||i?E.jsx("span",{className:"grid size-8 shrink-0 place-items-center rounded-lg bg-surface-2 text-fg-muted",children:E.jsx(IC,{className:"size-4"})}):E.jsx("img",{src:xn.typeIconUrl(n.id),alt:"",className:"size-8 shrink-0 rounded-lg",onError:()=>l(!0)})}function dM({type:n}){return E.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 rounded-xl border border-line bg-surface p-3.5",children:[E.jsxs("div",{className:"flex items-center gap-2.5",children:[E.jsx(fM,{type:n}),E.jsxs("div",{className:"min-w-0",children:[E.jsx("div",{className:"truncate font-semibold",children:n.title}),E.jsx("div",{className:"truncate text-xs text-fg-muted",children:n.id})]})]}),E.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[E.jsx(Eo,{children:n.scope}),E.jsx(Eo,{children:n.runtime}),n.version?E.jsxs(Eo,{children:["v",n.version]}):null,n.enabled?null:E.jsx(Eo,{children:he("disabled")}),n.shadowedBy?E.jsx(Eo,{children:he("shadowedBy",{root:n.shadowedBy})}):null]}),n.description?E.jsx("div",{className:"line-clamp-4 text-xs text-fg-muted",children:n.description}):null,n.problems.length?E.jsxs("div",{className:"flex items-start gap-1 text-xs text-warning",children:[E.jsx(tu,{className:"mt-px size-3.5 shrink-0"}),n.problems.join(" ")]}):null,$0(n)?E.jsx("div",{className:"mt-auto pt-1",children:E.jsx(fn,{size:"sm",variant:"primary",icon:E.jsx(A0,{className:"size-3"}),onClick:()=>ze.getState().setCreating(n),children:he("newOf",{type:n.title})})}):null]})}function pM(){const n=ze(l=>l.types);if(n===null)return E.jsx("p",{className:"py-8 text-fg-muted",children:he("loading")});const i=n.roots.map(l=>`${l.dir} (${l.scope})`).join(", ");return E.jsxs(E.Fragment,{children:[i?E.jsx("p",{className:"mb-3 mt-0 break-all text-xs text-fg-muted",children:he("typeRoots",{roots:i})}):null,n.types.length?E.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3",children:n.types.map(l=>E.jsx(dM,{type:l},`${l.root}:${l.id}`))}):E.jsx(mp,{title:he("noTypes")})]})}async function hM(n){try{const i=await fetch(n,{method:"POST",credentials:"same-origin",headers:{"content-type":"application/json",accept:"application/json"},body:"{}"});if(!i.ok&&i.status!==401)throw new Error(`HTTP ${i.status}`);const l=W0(await i.json().catch(()=>null))??(await sS()).accessLogout;l?location.href=l:location.reload()}catch(i){yp.add({title:he("signOutFailed",{error:i instanceof Error?i.message:String(i)})})}}let _b=null;function sS(){return _b??=fetch("/api/open-artifact.auth.me",{credentials:"same-origin",cache:"no-store"}).then(n=>n.ok?n.json():null).then(n=>({access:r2(n),accessLogout:J0(n)}),()=>({access:!1,accessLogout:null})),_b}function kb({id:n,name:i,avatar:l,size:r=28}){const[u,f]=b.useState(!1),d={width:r,height:r,fontSize:Math.round(r*.4)};return l&&!u?E.jsx("img",{src:l,alt:"",referrerPolicy:"no-referrer",className:"shrink-0 rounded-full bg-surface-2 object-cover",style:d,onError:()=>f(!0)}):E.jsx("span",{"aria-hidden":!0,className:"grid shrink-0 place-items-center rounded-full font-semibold text-white",style:{...d,background:n2(`user${n}`)},children:t2(i)})}function gM(n){Z0(n,location.origin)?window.open(n,"_blank","noopener,noreferrer"):location.href=n}function mM({cloud:n}){const i=n.user,l=Q0(n.site,"account-menu"),[r,u]=b.useState(!1);if(b.useEffect(()=>{if(!i)return;let f=!0;return sS().then(d=>f&&u(d.access)),()=>{f=!1}},[i]),!i){const f=`${location.pathname}${location.search}`;return E.jsx(fn,{size:"lg",variant:"ghost",className:"gap-1.5 px-2 font-normal",icon:E.jsx(kC,{className:"size-4"}),onClick:()=>location.href=l2(n.signInUrl,f,location.origin),children:E.jsx("span",{className:"max-sm:hidden",children:he("signIn")})})}return E.jsxs(H0,{align:"end",trigger:E.jsx("button",{type:"button","aria-label":he("accountOf",{name:i.name}),title:i.email?`${i.name} · ${i.email}`:i.name,className:"inline-flex size-8 shrink-0 items-center justify-center rounded-full outline-none hover:bg-hover focus-visible:outline-2 focus-visible:outline-accent data-[popup-open]:bg-hover",children:E.jsx(kb,{id:i.id,name:i.name,avatar:i.avatar,size:26})}),children:[E.jsx(FC,{children:E.jsxs("span",{className:"flex max-w-64 items-center gap-2.5 py-0.5",children:[E.jsx(kb,{id:i.id,name:i.name,avatar:i.avatar,size:32}),E.jsxs("span",{className:"min-w-0",children:[E.jsx("span",{className:"block truncate text-[13px] font-medium text-fg",children:i.name}),i.email?E.jsx("span",{className:"block truncate text-xs",children:i.email}):null]})]})}),E.jsx(ks,{}),l.map(f=>E.jsx(To,{icon:E.jsx(fp,{className:"size-3.5"}),onSelect:()=>gM(f.href),children:f.label},`${f.label} ${f.href}`)),l.length>0?E.jsx(ks,{}):null,E.jsx(To,{icon:E.jsx(jC,{className:"size-3.5"}),onSelect:()=>{hM(n.signOutUrl)},children:he(r?"signOutAccess":"signOut")})]})}function yM({site:n,compact:i=!1}){const l=Sp(n)?.brand,[r,u]=b.useState(!1);if(!l)return null;const f=l.logoUrl&&!r?E.jsx("img",{src:l.logoUrl,alt:l.name?"":"logo",referrerPolicy:"no-referrer",className:i?"h-5 w-auto shrink-0":"h-6 w-auto shrink-0",onError:()=>u(!0)}):null;return E.jsxs("span",{"data-site-brand":"",className:"inline-flex min-w-0 items-center gap-1.5",children:[f,l.name?E.jsx("span",{className:i?"truncate text-[13px] font-medium text-fg-muted max-sm:hidden":"truncate",children:l.name}):null]})}function bM({site:n}){const i=Q0(n,"home");return i.length===0?null:E.jsx("nav",{"aria-label":"Site links",className:"mb-4 flex flex-wrap gap-x-4 gap-y-1 text-[13px]",children:i.map(l=>{const r=Z0(l.href,location.origin);return E.jsxs("a",{href:l.href,...r?{target:"_blank",rel:"noopener noreferrer"}:{},className:"inline-flex items-center gap-1 text-accent hover:underline",children:[l.label,r?E.jsx(fp,{"aria-hidden":!0,className:"size-3"}):null]},`${l.label} ${l.href}`)})})}function vM(){const n=ze(r=>r.types),i=n?p2(n.types):null,l=E.jsx(fn,{size:"lg",variant:"primary",icon:E.jsx(A0,{className:"size-3.5"}),disabled:!i,onClick:()=>i&&ze.getState().setCreating(i),children:he("newArtifact")});return i||!n?l:E.jsx(t0,{label:he("cannotCreateYet"),children:E.jsx("span",{tabIndex:0,children:l})})}function SM(){const n=ze(u=>u.tab),i=ze(u=>u.error),l=to.cloud,r=l?.site?.brand?.name;return b.useEffect(()=>{r&&(document.title=r)},[r]),b.useEffect(()=>{Fl(),l||aS();const u=k2(),f=Z2();return()=>{u(),f()}},[]),E.jsxs("div",{className:"h-full overflow-auto bg-canvas text-fg",children:[E.jsxs("div",{className:"mx-auto max-w-[1040px] px-4 pb-12 pt-6",children:[E.jsxs("div",{className:"flex items-start justify-between gap-3",children:[E.jsxs("div",{className:"min-w-0",children:[E.jsx("h1",{className:"mb-1 mt-0 text-xl font-semibold",children:l?.site?.brand?E.jsx(yM,{site:l.site}):he("homeTitle")}),E.jsx("p",{className:"mb-5 mt-0 text-fg-muted",children:he(l?"homeSubCloud":"homeSub")}),l?E.jsx(bM,{site:l.site}):null]}),l?E.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[l.user?E.jsx(tM,{}):null,E.jsx(mM,{cloud:l})]}):E.jsx(vM,{})]}),i?E.jsxs("p",{role:"alert",className:"mb-3 flex items-center gap-1.5 text-xs text-danger",children:[E.jsx(tu,{className:"size-3.5"}),i]}):null,l?l.user?E.jsx(rM,{}):E.jsx(yd,{}):E.jsx(K0,{value:n,onChange:u=>ze.getState().setTab(u),className:"[&>[role=tabpanel]]:overflow-visible [&>[role=tabpanel]]:pt-4 [&_[role=tab][aria-selected=true]]:bg-hover [&_[role=tab][aria-selected=true]]:text-fg",items:[{value:"artifacts",label:he("artifacts"),content:E.jsx(yd,{})},{value:"types",label:he("types"),content:E.jsx(pM,{})}]})]}),E.jsx(sM,{}),E.jsx(uM,{}),E.jsx(cM,{}),l?E.jsx(lM,{}):null]})}document.documentElement.lang=bp;NT.createRoot(document.getElementById("root")).render(E.jsx(b.StrictMode,{children:E.jsx(dR,{children:E.jsx(WO,{children:E.jsx(SM,{})})})}));
43
+ `)}qA();const VA=3e4;function GA(){const n=typeof navigator>"u"?void 0:navigator.locks;return!n||typeof BroadcastChannel>"u"||typeof EventSource>"u"?null:{openSource:i=>new EventSource(i),openChannel:i=>new BroadcastChannel(i),locks:n}}function XA(n,i){const l=`open-artifact.events ${n}`,r=new Set;let u=null,f=null,d=null;const m=y=>{for(const v of[...r])try{v(y)}catch{}},h=()=>{u=i.openChannel(l),u.onmessage=v=>{typeof v.data=="string"&&m(v.data)};const y=new AbortController;f=y,i.locks.request(l,{signal:y.signal},async()=>{if(y.signal.aborted)return;const v=i.openSource(n);v.onmessage=S=>{m(S.data),u?.postMessage(S.data)},await new Promise(S=>d=S),v.close()}).catch(()=>{})},p=()=>{f?.abort(),f=null,d?.(),d=null,u?.close(),u=null};return{listen(y){return r.add(y),r.size===1&&h(),()=>{r.delete(y)&&(r.size||p())}}}}const Rb=new Map;function FA(n,i){let l=Rb.get(n);return l||(l=XA(n,i),Rb.set(n,l)),l}class vp extends Error{code;status;fix;constructor(i,l,r,u){super(l),this.name="ApiError",this.code=i,this.status=r,this.fix=u}}async function KA(n){try{const i=await n.json();return i&&typeof i=="object"?i:{}}catch{return{}}}const QA=15e3;async function ZA(n){const i=await KA(n);if(!n.ok){const l=typeof i.code=="string"?i.code:"error",r=typeof i.message=="string"?i.message:`HTTP ${n.status}`;throw new vp(l,r,n.status,typeof i.fix=="string"?i.fix:void 0)}return i}function WA(n={}){const i=(n.base??"").replace(/\/$/,""),l=n.fetch??((f,d)=>fetch(f,d)),r=(f,d)=>`${i}/api/open-artifact.${f}${d?`?${new URLSearchParams(d)}`:""}`;async function u(f,d={}){const m=d.body===void 0?{cache:"no-store"}:{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d.body)};d.body===void 0&&typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"&&(m.signal=AbortSignal.timeout(d.timeoutMs??QA));let h;try{h=await l(r(f,d.query),m)}catch(p){throw new vp("connect_failed",p instanceof Error?p.message:String(p),0)}return ZA(h)}return{async artifacts(){const f=await u(Kt.artifacts);return Array.isArray(f.artifacts)?f.artifacts:[]},artifact:f=>u(Kt.artifact,{query:{id:f}}),async types(){const f=await u(Kt.types);return{roots:Array.isArray(f.roots)?f.roots:[],types:Array.isArray(f.types)?f.types:[]}},share:f=>u(Kt.share,{query:{id:f}}),setShare:f=>u(Kt.share,{body:f}),create:f=>u(Kt.create,{body:f}),update:f=>u(Kt.update,{body:f}),duplicate:(f,d)=>u(Kt.duplicate,{body:{id:f,...d&&{name:d}}}),remove:f=>u(Kt.delete,{body:{id:f}}),restore:f=>u(Kt.restore,{body:{id:f}}),async trashed(){const f=await u(Kt.artifacts,{query:{trashed:"1"}});return Array.isArray(f.artifacts)?f.artifacts:[]},purge:f=>u("artifacts.purge",{body:{id:f}}),ask:f=>u(Kt.ask,{body:f}),open:f=>u(Kt.open,{body:{id:f,host:!1}}),boot:(f,d)=>u(Kt.boot,{query:d?.fresh?{id:f,fresh:"1"}:{id:f},timeoutMs:VA}),async remotes(){const f=await u("remotes"),d=f.cloud&&typeof f.cloud=="object"&&Array.isArray(f.cloud.pending)?f.cloud:null;return{remotes:Array.isArray(f.remotes)?f.remotes:[],cloud:d}},cloudSettings:f=>u("cloud.settings",{body:f}),connect:(f,d)=>u("remotes.add",{body:{name:f,host:d,browse:!1}}),connectCancel:f=>u("remotes.add.cancel",{body:{name:f}}),connectWait:(f,d)=>u("remotes.add.wait",{body:{name:f,ms:d}}),publish:(f,d,m={})=>u("artifacts.publish",{body:{id:f,remote:d,...m.data?{data:!0}:{}}}),unpublish:f=>u("artifacts.unpublish",{body:{id:f}}),dataPublish:(f,d={})=>u("artifacts.data",{body:{id:f,...d}}),eventsUrl:r(Kt.events),archiveUrl:f=>r(Kt.archive,{id:f}),typeIconUrl:f=>r("type.icon",{id:f})}}const xn=WA();function Fn(n){return n instanceof Error?n.message:String(n)}const JA=new Set(["artifacts/changed","types/changed","harness/changed","wake/state"]);function $A(n){try{const i=JSON.parse(n);if(!i||typeof i!="object")return null;const l=i.type;return typeof l=="string"&&JA.has(l)?i:null}catch{return null}}function e2(n,i={}){const l=i.url??xn.eventsUrl,r=m=>{const h=$A(m);h&&n(h)},u=i.shared!==void 0?i.shared:i.EventSource?null:GA();if(u)return FA(l,u).listen(r);const f=i.EventSource??(typeof EventSource>"u"?null:EventSource);if(!f)return()=>{};let d;try{d=new f(l)}catch{return()=>{}}return d.onmessage=m=>r(m.data),()=>d.close()}function md(n,i=Date.now(),l=bp){if(!n)return"";const r=Date.parse(n);if(!Number.isFinite(r))return"";const u=Math.max(0,(i-r)/1e3);if(u<60)return he("justNow");const f=new Intl.RelativeTimeFormat(l,{numeric:"auto"});return u<3600?f.format(-Math.round(u/60),"minute"):u<86400?f.format(-Math.round(u/3600),"hour"):u<86400*30?f.format(-Math.round(u/86400),"day"):new Date(r).toLocaleDateString(l)}function t2(n){const i=String(n??"").trim();if(!i)return"?";if(/^[぀-ヿ㐀-鿿가-힯]/.test(i))return[...i][0];const l=i.split(/\s+/);return((l[0]?.[0]??"")+(l[1]?.[0]??"")).toUpperCase()||"?"}const Cb=["#0f766e","#4f46e5","#b45309","#7c3aed","#be185d","#0369a1","#4d7c0f","#9f1239"];function n2(n){let i=0;for(const l of n)i=i*31+l.charCodeAt(0)|0;return Cb[Math.abs(i)%Cb.length]}async function o2(n){try{await navigator.clipboard.writeText(n)}catch{const i=document.createElement("textarea");i.value=n,i.style.position="fixed",i.style.opacity="0",document.body.append(i),i.select(),document.execCommand("copy"),i.remove()}}const i2="__OPEN_ARTIFACT_HOME__";function a2(n){if(!n||typeof n!="object")return{};const i=n.cloud;if(!i||typeof i!="object")return{};const l=i;if(typeof l.signInUrl!="string"||typeof l.signOutUrl!="string"||typeof l.appOrigin!="string")return{};const r=l.user&&typeof l.user=="object"&&typeof l.user.id=="string"&&typeof l.user.name=="string"?l.user:null,u=typeof l.trashDays=="number"&&Number.isInteger(l.trashDays)&&l.trashDays>=0?l.trashDays:void 0,f=l.limits&&typeof l.limits=="object"?l.limits.importBytes:void 0,d=typeof f=="number"&&Number.isInteger(f)&&f>0?{importBytes:f}:void 0,m=Sp(l.site);return{cloud:{user:r,appOrigin:l.appOrigin,signInUrl:l.signInUrl,signOutUrl:l.signOutUrl,...u!==void 0?{trashDays:u}:{},...d?{limits:d}:{},...m?{site:m}:{}}}}function Yf(n){return typeof n!="string"||n.length===0||n.length>2048||/[\u0000-\u001f\u007f]/.test(n)?!1:n.startsWith("/")?!n.startsWith("//")&&!n.includes("\\"):/^https?:\/\//i.test(n)}function Ob(n,i){if(typeof n!="string")return null;const l=n.trim();return l.length>0&&l.length<=i?l:null}function Sp(n){if(!n||typeof n!="object")return;const i=n,l=[];if(Array.isArray(i.links))for(const u of i.links){if(!u||typeof u!="object")continue;const{label:f,href:d,where:m}=u,h=Ob(f,80);h&&Yf(d)&&(m==="account-menu"||m==="home")&&l.push({label:h,href:d,where:m})}let r;if(i.brand&&typeof i.brand=="object"){const{name:u,logoUrl:f}=i.brand,d=Ob(u,80);(d||Yf(f))&&(r={...d?{name:d}:{},...Yf(f)?{logoUrl:f}:{}})}if(!(l.length===0&&!r))return{...l.length>0?{links:l}:{},...r?{brand:r}:{}}}function Q0(n,i){return(Sp(n)?.links??[]).filter(l=>l.where===i).map(({label:l,href:r})=>({label:l,href:r}))}function Z0(n,i){if(n.startsWith("/"))return!1;try{return new URL(n).origin!==i}catch{return!0}}function l2(n,i,l){let r;try{r=new URL(n,l)}catch{return n}return!r.searchParams.has("return_to")&&i.startsWith("/")&&!i.startsWith("//")&&r.searchParams.set("return_to",i),r.origin===l?`${r.pathname}${r.search}${r.hash}`:r.href}function W0(n){if(!n||typeof n!="object")return null;const i=n.accessLogoutUrl;if(typeof i!="string")return null;try{const l=new URL(i);return l.protocol==="https:"||l.protocol==="http:"?l.href:null}catch{return null}}function r2(n){if(!n||typeof n!="object")return!1;if(J0(n))return!0;const i=n.providers;return Array.isArray(i)&&i.some(l=>!!l&&typeof l=="object"&&l.id==="cloudflare-access")}function J0(n){return W0(n)}async function s2(){try{const n=await fetch(`/api/open-artifact.${Kt.embed}`,{cache:"no-store",signal:AbortSignal.timeout(3e3)});if(!n.ok)return null;const i=await n.json();return Array.isArray(i.hosts)?i.hosts.filter(l=>typeof l=="string"):null}catch{return null}}const u2=["design"];function Ab(n){return Date.parse(n.contentAt||n.updatedAt||n.createdAt||"")||0}function c2(n,i){if(!i||!i.harness&&!i.workspace)return[...n];const l=f=>f.replace(/[\\/]+$/,""),r=i.workspace?l(i.workspace):null,u=f=>{if(!r||!f)return!1;const d=l(f);return d===r||d.startsWith(`${r}/`)||d.startsWith(`${r}\\`)};return n.filter(f=>(!i.harness||f.owner?.harness===i.harness)&&(!r||u(f.owner?.workspace)||u(f.root)))}function f2(n){return[...n].sort((i,l)=>Number(l.pinned)-Number(i.pinned)||Ab(l)-Ab(i))}function d2(n){return n.enabled&&n.runnable&&!n.shadowedBy}function $0(n){return d2(n)&&u2.includes(n.id)}function p2(n){return n.find($0)??null}function h2(n){return n?n.live?n.status==="running"?"working":"idle":"offline":"none"}function g2(n,i){return n.map(l=>l.id===i.id?i:l)}function m2(n,i){return n.filter(l=>l.id!==i)}function y2(n,i,l){const r=yA(n);return!r||r.openArtifact!=="host_hello"?null:{origin:i,caps:r.caps,harness:r.harness??null,agentName:r.agentName??null,declared:l,library:r.library??null}}const Mb=n=>{let i;const l=new Set,r=(p,y)=>{const v=typeof p=="function"?p(i):p;if(!Object.is(v,i)){const S=i;i=y??(typeof v!="object"||v===null)?v:Object.assign({},i,v),l.forEach(w=>w(i,S))}},u=()=>i,m={setState:r,getState:u,getInitialState:()=>h,subscribe:p=>(l.add(p),()=>l.delete(p))},h=i=n(r,u,m);return m},b2=(n=>n?Mb(n):Mb),v2=n=>n;function S2(n,i=v2){const l=kl.useSyncExternalStore(n.subscribe,kl.useCallback(()=>i(n.getState()),[n,i]),kl.useCallback(()=>i(n.getInitialState()),[n,i]));return kl.useDebugValue(l),l}const x2=n=>{const i=b2(n),l=r=>S2(i,r);return Object.assign(l,i),l},T2=(n=>x2);function E2(n,i){switch(i.type){case"start":return n.kind==="sending"||n.kind==="checking"?n:{kind:"sending",name:i.name,loaded:0,total:i.size};case"progress":return n.kind!=="sending"?n:{...n,loaded:Math.max(n.loaded,i.loaded),total:i.total||n.total};case"sent":return n.kind==="sending"?{kind:"checking",name:n.name}:n;case"done":return n.kind==="sending"||n.kind==="checking"?{kind:"done",name:n.name,id:i.id}:n;case"failed":return n.kind==="idle"||n.kind==="done"?n:{kind:"failed",name:n.name,said:i.said};case"dismiss":return n.kind==="failed"?{kind:"idle"}:n}}function eS(n){return n.kind==="sending"||n.kind==="checking"||n.kind==="done"}function w2(n){return n.kind==="checking"||n.kind==="done"?100:n.kind!=="sending"||n.total<=0?null:Math.min(100,Math.floor(n.loaded/n.total*100))}function R2(n){const i=n.type.toLowerCase();return/\.zip$/i.test(n.name)||i==="application/zip"||i==="application/x-zip-compressed"}function C2(n){if(!n.length)return null;const i=n.find(R2);return i?{file:i}:{said:{key:"uploadNotZip"}}}function O2(n,i){return i===void 0||!(i>0)||n<=i?null:{key:"uploadTooLargeLimit",vars:{limit:tS(i)}}}function A2(n){return!!n&&n.includes("Files")}function tS(n){if(n<1024)return`${n} B`;const i=["KB","MB","GB"];let l=n/1024,r=0;for(;l>=1024&&r<i.length-1;)l/=1024,r++;return`${l>=10||Number.isInteger(l)?Math.round(l):l.toFixed(1)} ${i[r]}`}function M2(n){const i=/(\d{4,})\s*bytes/i.exec(n);if(!i)return null;const l=Number(i[1]);return Number.isFinite(l)&&l>0?tS(l):null}function Db(n){const{status:i,code:l,message:r}=n;if(i===0)return{key:"uploadNoAnswer"};if(i===401)return{key:"uploadSignedOut"};if(i===403)return{key:"uploadNotAllowed"};if(i===413||l==="too_large"){const u=M2(r);return u?{key:"uploadTooLargeLimit",vars:{limit:u}}:r?{key:"uploadTooLargeSaid",vars:{error:r}}:{key:"uploadTooLarge"}}if(i===415)return{key:"uploadNotZip"};if(i===409)return{key:"uploadConflict"};if(i===400){const u=/The (\S+) type is not installed/.exec(r)?.[1];return l==="unsupported"||u?u?{key:"uploadTypeMissing",vars:{type:u}}:{key:"uploadFailed",vars:{error:r}}:{key:"uploadNotArtifact"}}return i===429?{key:"uploadBusy"}:{key:"uploadFailed",vars:{error:r||`HTTP ${i}`}}}function D2(n,i){let l="error",r="";try{const u=JSON.parse(i);if(u&&typeof u=="object"){const f=u;typeof f.code=="string"&&(l=f.code),typeof f.message=="string"&&(r=f.message)}}catch{}return{status:n,code:l,message:r}}function N2(n){try{const i=JSON.parse(n),l=i&&typeof i=="object"?i.id:void 0;return typeof l=="string"&&l?l:null}catch{return null}}function z2(n=typeof location>"u"?"":location.hash){return n==="#trash"?"trash":"artifacts"}const nS="open-artifact.tab";function _2(){try{return localStorage.getItem(nS)==="types"?"types":"artifacts"}catch{return"artifacts"}}const ze=T2()(n=>({tab:_2(),artifacts:null,types:null,error:null,host:null,creating:null,renaming:null,undo:null,cloudTab:z2(),trash:null,purgeUnsupported:!1,purging:null,upload:{kind:"idle"},setTab:i=>{try{localStorage.setItem(nS,i)}catch{}n({tab:i})},setArtifacts:i=>n({artifacts:i}),setTypes:i=>n({types:i}),setError:i=>n({error:i}),setHost:i=>n({host:i}),setCreating:i=>n({creating:i}),setRenaming:i=>n({renaming:i}),setUndo:i=>n({undo:i}),setCloudTab:i=>n({cloudTab:i}),setTrash:i=>n({trash:i}),setPurgeUnsupported:()=>n({purgeUnsupported:!0}),setPurging:i=>n({purging:i}),uploadEvent:i=>n(l=>({upload:E2(l.upload,i)}))})),to=a2(window[i2]),oS=window.parent!==window;function iS(n){const i=ze.getState().host;i&&window.parent.postMessage(n,i.origin)}function Nb(n){const i=n.data;if(!oS||n.source!==window.parent||!bA(i)||i.openArtifact!=="host_hello")return;const l=n.origin;s2().then(r=>{const u=!!r?.length&&r.includes(l);if(r?.length&&!u)return;const f=y2(i,l,u);f&&(ze.getState().setHost(f),window.parent.postMessage({openArtifact:"home_ready"},l))})}function k2(){return window.addEventListener("message",Nb),oS&&window.parent.postMessage({openArtifact:"home_hello"},"*"),()=>window.removeEventListener("message",Nb)}function j2(n){return n.map(i=>({id:i.id,title:i.title,typeTitle:i.typeTitle,when:typeof i.trashedAt=="string"&&i.trashedAt?{kind:"trashed",at:i.trashedAt}:{kind:"changed",at:i.updatedAt},mine:i.role===void 0||i.role==="owner"})).sort((i,l)=>(Date.parse(l.when.at)||0)-(Date.parse(i.when.at)||0))}function H2(n){return n===void 0||!Number.isInteger(n)||n<0?null:n===0?{key:"trashKeptForever"}:n===1?{key:"trashKeptOneDay"}:{key:"trashKeptDays",vars:{days:n}}}function L2(n,i){return n.mine&&!i}function U2(n,i){return n===501?{unsupported:!0}:n===409?{unsupported:!1,said:{key:"purgeNotTrashed"}}:n===404?{unsupported:!1,said:{key:"purgeGone"}}:{unsupported:!1,said:{key:"couldNotPurge",vars:{error:i||`HTTP ${n}`}}}}const Ln=n=>{yp.add({title:n})},au=n=>`/a/${encodeURIComponent(n)}`;function qf(n){ze.getState().host?.caps.artifacts?iS({openArtifact:"open_artifact",url:n.url,id:n.id,title:n.title,type:n.type}):location.href=au(n.id)}async function Fl(){try{ze.getState().setArtifacts(await xn.artifacts()),ze.getState().setError(null)}catch(n){ze.getState().setError(he("couldNotLoad",{error:Fn(n)}))}}function B2(n){window.open(n,"_blank","noopener")}async function I2(n){await o2(n),Ln(he("webLinkCopied"))}async function aS(){try{ze.getState().setTypes(await xn.types())}catch(n){ze.getState().setError(he("couldNotLoad",{error:Fn(n)}))}}const lS=n=>{const i=ze.getState().artifacts;i&&ze.getState().setArtifacts(g2(i,n))};async function P2(n){const i=!n.pinned;try{lS(await xn.update({id:n.id,pinned:i}))}catch(l){Ln(he(i?"couldNotPin":"couldNotUnpin",{error:Fn(l)}))}}async function Y2(n,i){const l=i.trim();if(!(!l||l===n.title))try{lS(await xn.update({id:n.id,title:l}))}catch(r){Ln(he("couldNotRename",{error:Fn(r)}))}}async function q2(n){try{await xn.duplicate(n.id),Ln(he("duplicated")),await Fl()}catch(i){Ln(he("couldNotDuplicate",{error:Fn(i)}))}}let Vf=null;async function zb(n){const i=ze.getState(),l=i.artifacts;l&&i.setArtifacts(m2(l,n.id));try{await xn.remove(n.id),i.setUndo({id:n.id,title:n.title,...to.cloud?{trash:!0}:{}}),ze.getState().trash&&Ba(),Vf&&clearTimeout(Vf),Vf=setTimeout(()=>{ze.getState().undo?.id===n.id&&ze.getState().setUndo(null)},8e3)}catch(r){l&&i.setArtifacts(l),Ln(he("couldNotDelete",{error:Fn(r)}))}}async function V2(){const n=ze.getState().undo;if(n){ze.getState().setUndo(null);try{await xn.restore(n.id),Ln(he("restored")),await Fl(),ze.getState().trash&&Ba()}catch(i){Ln(he("couldNotRestore",{error:Fn(i)}))}}}async function Ba(){try{ze.getState().setTrash(await xn.trashed())}catch(n){ze.getState().setError(he("couldNotLoad",{error:Fn(n)}))}}async function G2(n){const i=ze.getState(),l=i.trash;l&&i.setTrash(l.filter(r=>r.id!==n.id));try{await xn.restore(n.id),Ln(he("restoredTitle",{title:n.title})),await Promise.all([Fl(),Ba()])}catch(r){l&&ze.getState().setTrash(l),Ln(he("couldNotRestore",{error:Fn(r)}))}}async function X2(n){try{await xn.purge(n.id);const i=ze.getState().trash;i&&ze.getState().setTrash(i.filter(l=>l.id!==n.id)),Ln(he("purged",{title:n.title}))}catch(i){const l=i instanceof vp?i.status:0,r=U2(l,Fn(i));r.unsupported?ze.getState().setPurgeUnsupported():Ln(he(r.said.key,r.said.vars)),Ba()}}const F2="/api/open-artifact.artifacts.import";function rS(n){const i=ze.getState();if(eS(i.upload))return;const l=C2(n);if(!l)return;if("said"in l){const d=n[0]?.name??"";i.uploadEvent({type:"start",name:d,size:0}),i.uploadEvent({type:"failed",said:l.said});return}const r=l.file;i.uploadEvent({type:"start",name:r.name,size:r.size});const u=O2(r.size,to.cloud?.limits?.importBytes);if(u){i.uploadEvent({type:"failed",said:u});return}const f=new XMLHttpRequest;f.open("POST",F2),f.setRequestHeader("Content-Type",cA),f.upload.onprogress=d=>ze.getState().uploadEvent({type:"progress",loaded:d.loaded,total:d.lengthComputable?d.total:0}),f.upload.onload=()=>ze.getState().uploadEvent({type:"sent"}),f.onload=()=>{const d=f.status===201||f.status===200?N2(f.responseText):null;if(d){ze.getState().uploadEvent({type:"done",id:d}),location.href=au(d);return}ze.getState().uploadEvent({type:"failed",said:Db(D2(f.status,f.responseText))})},f.onerror=()=>ze.getState().uploadEvent({type:"failed",said:Db({status:0,code:"connect_failed",message:""})}),f.send(r)}async function K2(n,i,l){if(!i.trim())return he("needTitle");try{const r=await xn.create({type:n.id,title:i.trim(),...l.trim()?{folder:l.trim()}:{}});return location.href=au(r.id),null}catch(r){return he("couldNotCreate",{error:Fn(r)})}}function Q2(n){n.owner&&iS({openArtifact:"open_session",session:n.owner.session,harness:n.owner.harness})}function Z2(){let n=null,i=!1;const l=e2(r=>{r.type==="types/changed"&&(i=!0),n&&clearTimeout(n),n=setTimeout(()=>{Fl(),i&&!to.cloud&&aS(),to.cloud&&ze.getState().cloudTab==="trash"&&Ba(),i=!1},200)});return()=>{n&&clearTimeout(n),l()}}const W2={none:"statusNone",working:"statusWorking",idle:"statusIdle",waiting:"statusWaiting",offline:"statusOffline"};function J2({state:n,className:i}){return E.jsx("span",{"aria-hidden":"true",className:zo("inline-block size-2 shrink-0 rounded-full",n==="working"?"animate-pulse bg-accent motion-reduce:animate-none":n==="idle"||n==="waiting"?"bg-success":"bg-fg-subtle",i)})}function $2({state:n,prefix:i,label:l,className:r}){const u=l??he(W2[n]);return E.jsxs("span",{className:zo("inline-flex min-w-0 items-center gap-1.5 text-xs text-fg-muted",r),children:[E.jsx(J2,{state:n}),E.jsx("span",{className:"truncate",children:i?`${i} · ${u}`:u})]})}function Eo({children:n}){return E.jsx("span",{className:"inline-flex max-w-full items-center gap-1 truncate rounded-full bg-surface-2 px-2 py-px text-xs text-fg-muted",children:n})}function eM({artifact:n}){const i=ze(p=>p.host),l=to.cloud?void 0:n.remote?.url,r=au(n.id),u=!to.cloud,f=!u&&n.role==="owner",d=u||n.role===void 0||n.role==="owner"||n.role==="editor",m=u&&!!(i?.caps.sessions&&n.owner?.session&&(!i.harness||n.owner.harness===i.harness)),h=p=>{p.target.closest('a, button, [role="menu"]')||getSelection()?.toString()||qf(n)};return E.jsxs("div",{onClick:h,className:"group flex min-w-0 cursor-pointer flex-col overflow-hidden rounded-xl border border-line bg-surface transition-[border-color,box-shadow] hover:border-line-strong hover:shadow-popup",children:[n.thumbnail?E.jsx("img",{src:n.thumbnail,alt:"",loading:"lazy",className:"aspect-[16/9] w-full border-b border-line bg-surface-2 object-cover object-top"}):null,E.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5 p-3.5",children:[E.jsxs("a",{href:r,className:"flex min-w-0 items-center gap-1.5 break-words font-semibold text-fg no-underline hover:text-accent",onClick:p=>{!i?.caps.artifacts||p.metaKey||p.ctrlKey||p.shiftKey||(p.preventDefault(),qf(n))},children:[n.pinned?E.jsx(gb,{className:"size-3.5 shrink-0 text-fg-muted","aria-label":he("pinned")}):null,E.jsx("span",{className:"min-w-0",children:n.title}),l?E.jsx("span",{title:he("pubCloudAt",{url:l}),"data-home-published":"",className:"inline-flex shrink-0 text-accent",children:E.jsx(DC,{className:"size-3.5","aria-label":he("pubCloudMark")})}):null]}),E.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[E.jsx(Eo,{children:n.typeTitle}),u?E.jsx(Eo,{children:E.jsx($2,{state:h2(n.owner),prefix:n.owner?n.owner.harnessTitle??n.owner.harness:void 0})}):null,u&&n.open?E.jsx(Eo,{children:he("pageOpen")}):null]}),n.typeMissing?E.jsxs("div",{className:"flex items-center gap-1 text-xs text-warning",children:[E.jsx(tu,{className:"size-3.5"}),he("typeMissing")]}):null,u?E.jsx("div",{className:"break-all text-xs text-fg-muted",title:n.root,children:n.root}):null,E.jsx("div",{className:"text-xs text-fg-muted",children:he("updated",{when:md(n.contentAt||n.updatedAt)})}),E.jsxs("div",{className:"mt-auto flex items-center gap-1.5 pt-1",children:[E.jsx(fn,{size:"sm",variant:"primary",onClick:()=>qf(n),children:he("open")}),m?E.jsx(fn,{size:"sm",icon:E.jsx(HC,{className:"size-3"}),onClick:()=>Q2(n),children:he("backToSession")}):null,E.jsx("span",{className:"flex-1"}),E.jsxs(H0,{align:"end",trigger:E.jsx(o0,{label:he("moreActions"),icon:E.jsx(zC,{className:"size-4"}),size:"sm",noTooltip:!0}),children:[E.jsx(To,{icon:n.pinned?E.jsx(UC,{className:"size-3.5"}):E.jsx(gb,{className:"size-3.5"}),onSelect:()=>{P2(n)},children:n.pinned?he("unpin"):he("pin")}),l?E.jsxs(E.Fragment,{children:[E.jsx(To,{icon:E.jsx(fp,{className:"size-3.5"}),onSelect:()=>B2(l),children:he("openOnWeb")}),E.jsx(To,{icon:E.jsx(_C,{className:"size-3.5"}),onSelect:()=>{I2(l)},children:he("copyWebLink")})]}):null,d?E.jsx(To,{icon:E.jsx(LC,{className:"size-3.5"}),onSelect:()=>ze.getState().setRenaming(n),children:he("rename")}):null,u?E.jsxs(E.Fragment,{children:[E.jsx(To,{icon:E.jsx(NC,{className:"size-3.5"}),onSelect:()=>{q2(n)},children:he("duplicate")}),E.jsx(ks,{}),E.jsx(To,{icon:E.jsx(dd,{className:"size-3.5"}),danger:!0,onSelect:()=>{zb(n)},children:he("delete")})]}):null,f?E.jsxs(E.Fragment,{children:[E.jsx(ks,{}),E.jsx(To,{icon:E.jsx(dd,{className:"size-3.5"}),danger:!0,onSelect:()=>{zb(n)},children:he("moveToTrash")})]}):null]})]})]})]})}function yd(){const n=ze(r=>r.artifacts),i=ze(r=>r.host?.library??null),l=n&&i?c2(n,i):n;return l===null?E.jsx("p",{className:"py-8 text-fg-muted",children:he("loading")}):l.length?E.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3",children:f2(l).map(r=>E.jsx(eM,{artifact:r},r.id))}):E.jsx(mp,{title:he("artifacts"),children:he(to.cloud?"noArtifactsCloud":"noArtifacts")})}function tM(){const n=b.useRef(null),i=ze(l=>eS(l.upload));return E.jsxs(E.Fragment,{children:[E.jsx(fn,{size:"lg",icon:E.jsx(k0,{className:"size-3.5"}),disabled:i,title:he("uploadHint"),onClick:()=>n.current?.click(),children:he("upload")}),E.jsx("input",{ref:n,type:"file",accept:".zip,application/zip,application/x-zip-compressed","data-home-upload":"",className:"hidden",onChange:l=>{const r=[...l.target.files??[]];l.target.value="",rS(r)}})]})}function nM(){const n=ze(r=>r.upload);if(n.kind==="idle")return null;if(n.kind==="failed")return E.jsxs("div",{role:"alert","data-home-upload-error":"",className:"mb-3 flex items-start gap-2 rounded-lg border border-line bg-surface p-3 text-[13px]",children:[E.jsx(tu,{className:"mt-px size-4 shrink-0 text-danger"}),E.jsx("span",{className:"min-w-0 flex-1 break-words",children:he(n.said.key,n.said.vars)}),E.jsx(o0,{label:he("dismiss"),size:"sm",noTooltip:!0,icon:E.jsx(dp,{className:"size-3.5"}),onClick:()=>ze.getState().uploadEvent({type:"dismiss"})})]});const i=w2(n),l=n.kind==="done"?he("uploadOpening",{name:n.name}):n.kind==="checking"?he("uploadChecking",{name:n.name}):i===null?he("uploadSendingSize",{name:n.name}):he("uploadSending",{name:n.name,percent:i});return E.jsxs("div",{role:"status","data-home-upload-state":n.kind,className:"mb-3 rounded-lg border border-line bg-surface p-3 text-[13px]",children:[E.jsx("div",{className:"mb-2 truncate",children:l}),E.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-surface-2",children:E.jsx("div",{className:"h-full rounded-full bg-accent transition-[width] duration-150",style:{width:`${i??5}%`}})})]})}function oM({children:n}){const[i,l]=b.useState(!1),r=b.useRef(0),u=!!to.cloud?.user,f=d=>u&&A2([...d.dataTransfer.types]);return E.jsxs("div",{className:"relative","data-home-drop":i?"over":"",onDragEnter:d=>{f(d)&&(d.preventDefault(),r.current++,l(!0))},onDragOver:d=>{f(d)&&(d.preventDefault(),d.dataTransfer.dropEffect="copy")},onDragLeave:d=>{f(d)&&(r.current=Math.max(0,r.current-1),r.current||l(!1))},onDrop:d=>{f(d)&&(d.preventDefault(),r.current=0,l(!1),rS([...d.dataTransfer.files]))},children:[n,i?E.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 grid min-h-32 place-items-center rounded-xl border-2 border-dashed border-accent bg-surface/80 text-[13px] font-medium text-accent",children:E.jsxs("span",{className:"flex items-center gap-2",children:[E.jsx(k0,{className:"size-4"}),he("uploadDrop")]})}):null]})}function iM({row:n}){const i=ze(l=>l.purgeUnsupported);return E.jsxs("div",{"data-home-trashed":n.id,className:"flex min-w-0 flex-wrap items-center gap-3 rounded-xl border border-line bg-surface p-3.5",children:[E.jsxs("div",{className:"min-w-0 flex-1",children:[E.jsx("div",{className:"break-words font-semibold",children:n.title}),E.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5 text-xs text-fg-muted",children:[E.jsx(Eo,{children:n.typeTitle}),E.jsx("span",{children:n.when.kind==="trashed"?he("trashedWhen",{when:md(n.when.at)}):he("updated",{when:md(n.when.at)})})]})]}),n.mine?E.jsxs("div",{className:"flex items-center gap-1.5",children:[E.jsx(fn,{size:"sm",icon:E.jsx(BC,{className:"size-3"}),onClick:()=>{G2(n)},children:he("restore")}),L2(n,i)?E.jsx(fn,{size:"sm",variant:"ghost",className:"text-danger",icon:E.jsx(dd,{className:"size-3"}),onClick:()=>ze.getState().setPurging({id:n.id,title:n.title}),children:he("deleteForever")}):null]}):null]})}function aM(){const n=ze(u=>u.trash);b.useEffect(()=>{Ba()},[]);const i=H2(to.cloud?.trashDays),l=E.jsxs("p",{className:"mb-3 mt-0 text-xs text-fg-muted",children:[he("trashNote"),i?` ${he(i.key,i.vars)}`:""]});if(n===null)return E.jsx("p",{className:"py-8 text-fg-muted",children:he("loading")});const r=j2(n);return E.jsxs("div",{"data-home-trash":"",children:[l,r.length?E.jsx("div",{className:"flex flex-col gap-2",children:r.map(u=>E.jsx(iM,{row:u},u.id))}):E.jsx(mp,{title:he("trash"),children:he("trashEmpty")})]})}function lM(){const n=ze(l=>l.purging),i=()=>ze.getState().setPurging(null);return E.jsx(pp,{open:!!n,onOpenChange:l=>!l&&i(),title:n?he("purgeTitle",{title:n.title}):"",description:he("purgeBody"),footer:E.jsxs(E.Fragment,{children:[E.jsx(fn,{size:"lg",onClick:i,children:he("cancel")}),E.jsx(fn,{size:"lg",variant:"danger",onClick:()=>{n&&X2(n),i()},children:he("deleteForever")})]})})}function rM(){const n=ze(i=>i.cloudTab);return E.jsx(K0,{value:n,onChange:i=>ze.getState().setCloudTab(i),className:"[&>[role=tabpanel]]:overflow-visible [&>[role=tabpanel]]:pt-4 [&_[role=tab][aria-selected=true]]:bg-hover [&_[role=tab][aria-selected=true]]:text-fg",items:[{value:"artifacts",label:he("artifacts"),content:E.jsxs(oM,{children:[E.jsx(nM,{}),E.jsx(yd,{})]})},{value:"trash",label:he("trash"),content:E.jsx(aM,{})}]})}function bd({label:n,children:i}){return E.jsxs("label",{className:"mt-3 block",children:[E.jsx("span",{className:"mb-1 block text-xs text-fg-muted",children:n}),i]})}function sM(){const n=ze(y=>y.creating),[i,l]=b.useState(""),[r,u]=b.useState(""),[f,d]=b.useState(""),[m,h]=b.useState(!1);b.useEffect(()=>{n&&(l(""),u(""),d(""))},[n]);const p=async y=>{if(y.preventDefault(),!n||m)return;h(!0);const v=await K2(n,i,r);h(!1),v&&d(v)};return E.jsx(pp,{open:!!n,onOpenChange:y=>!y&&ze.getState().setCreating(null),title:n?he("newOf",{type:n.title}):"",description:n?.description?n.description.slice(0,160):void 0,children:E.jsxs("form",{onSubmit:y=>{p(y)},children:[E.jsx(bd,{label:he("title"),children:E.jsx(hd,{autoFocus:!0,required:!0,value:i,maxLength:200,onChange:y=>l(y.target.value),className:"h-8"})}),E.jsx(bd,{label:he("folderOptional"),children:E.jsx(hd,{value:r,placeholder:he("folderHint"),onChange:y=>u(y.target.value),className:"h-8"})}),f?E.jsx("p",{role:"alert",className:"mb-0 mt-2 text-xs text-danger",children:f}):null,E.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[E.jsx(fn,{size:"lg",onClick:()=>ze.getState().setCreating(null),children:he("cancel")}),E.jsx(fn,{size:"lg",type:"submit",variant:"primary",disabled:m||!i.trim(),children:he("create")})]})]})})}function uM(){const n=ze(u=>u.renaming),[i,l]=b.useState("");b.useEffect(()=>l(n?.title??""),[n]);const r=()=>ze.getState().setRenaming(null);return E.jsx(pp,{open:!!n,onOpenChange:u=>!u&&r(),title:he("renameArtifact"),children:E.jsxs("form",{onSubmit:u=>{u.preventDefault(),n&&Y2(n,i),r()},children:[E.jsx(bd,{label:he("title"),children:E.jsx(hd,{autoFocus:!0,value:i,maxLength:200,onChange:u=>l(u.target.value),className:"h-8"})}),E.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[E.jsx(fn,{size:"lg",onClick:r,children:he("cancel")}),E.jsx(fn,{size:"lg",type:"submit",variant:"primary",disabled:!i.trim(),children:he("save")})]})]})})}function cM(){const n=ze(i=>i.undo);return n?E.jsxs("div",{role:"status",className:"fixed bottom-5 left-1/2 z-[1100] flex max-w-[calc(100vw-32px)] -translate-x-1/2 items-center gap-3 rounded-lg bg-fg px-3.5 py-2 text-[13px] text-surface shadow-popup",children:[E.jsx("span",{className:"min-w-0 truncate",children:he(n.trash?"movedToTrash":"deleted",{title:n.title})}),E.jsx("button",{type:"button",className:"shrink-0 font-semibold text-surface underline-offset-2 hover:underline",onClick:()=>{V2()},children:he("undo")})]}):null}function fM({type:n}){const[i,l]=b.useState(!1);return!n.icon||i?E.jsx("span",{className:"grid size-8 shrink-0 place-items-center rounded-lg bg-surface-2 text-fg-muted",children:E.jsx(IC,{className:"size-4"})}):E.jsx("img",{src:xn.typeIconUrl(n.id),alt:"",className:"size-8 shrink-0 rounded-lg",onError:()=>l(!0)})}function dM({type:n}){return E.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 rounded-xl border border-line bg-surface p-3.5",children:[E.jsxs("div",{className:"flex items-center gap-2.5",children:[E.jsx(fM,{type:n}),E.jsxs("div",{className:"min-w-0",children:[E.jsx("div",{className:"truncate font-semibold",children:n.title}),E.jsx("div",{className:"truncate text-xs text-fg-muted",children:n.id})]})]}),E.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[E.jsx(Eo,{children:n.scope}),E.jsx(Eo,{children:n.runtime}),n.version?E.jsxs(Eo,{children:["v",n.version]}):null,n.enabled?null:E.jsx(Eo,{children:he("disabled")}),n.shadowedBy?E.jsx(Eo,{children:he("shadowedBy",{root:n.shadowedBy})}):null]}),n.description?E.jsx("div",{className:"line-clamp-4 text-xs text-fg-muted",children:n.description}):null,n.problems.length?E.jsxs("div",{className:"flex items-start gap-1 text-xs text-warning",children:[E.jsx(tu,{className:"mt-px size-3.5 shrink-0"}),n.problems.join(" ")]}):null,$0(n)?E.jsx("div",{className:"mt-auto pt-1",children:E.jsx(fn,{size:"sm",variant:"primary",icon:E.jsx(A0,{className:"size-3"}),onClick:()=>ze.getState().setCreating(n),children:he("newOf",{type:n.title})})}):null]})}function pM(){const n=ze(l=>l.types);if(n===null)return E.jsx("p",{className:"py-8 text-fg-muted",children:he("loading")});const i=n.roots.map(l=>`${l.dir} (${l.scope})`).join(", ");return E.jsxs(E.Fragment,{children:[i?E.jsx("p",{className:"mb-3 mt-0 break-all text-xs text-fg-muted",children:he("typeRoots",{roots:i})}):null,n.types.length?E.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-3",children:n.types.map(l=>E.jsx(dM,{type:l},`${l.root}:${l.id}`))}):E.jsx(mp,{title:he("noTypes")})]})}async function hM(n){try{const i=await fetch(n,{method:"POST",credentials:"same-origin",headers:{"content-type":"application/json",accept:"application/json"},body:"{}"});if(!i.ok&&i.status!==401)throw new Error(`HTTP ${i.status}`);const l=W0(await i.json().catch(()=>null))??(await sS()).accessLogout;l?location.href=l:location.reload()}catch(i){yp.add({title:he("signOutFailed",{error:i instanceof Error?i.message:String(i)})})}}let _b=null;function sS(){return _b??=fetch("/api/open-artifact.auth.me",{credentials:"same-origin",cache:"no-store"}).then(n=>n.ok?n.json():null).then(n=>({access:r2(n),accessLogout:J0(n)}),()=>({access:!1,accessLogout:null})),_b}function kb({id:n,name:i,avatar:l,size:r=28}){const[u,f]=b.useState(!1),d={width:r,height:r,fontSize:Math.round(r*.4)};return l&&!u?E.jsx("img",{src:l,alt:"",referrerPolicy:"no-referrer",className:"shrink-0 rounded-full bg-surface-2 object-cover",style:d,onError:()=>f(!0)}):E.jsx("span",{"aria-hidden":!0,className:"grid shrink-0 place-items-center rounded-full font-semibold text-white",style:{...d,background:n2(`user${n}`)},children:t2(i)})}function gM(n){Z0(n,location.origin)?window.open(n,"_blank","noopener,noreferrer"):location.href=n}function mM({cloud:n}){const i=n.user,l=Q0(n.site,"account-menu"),[r,u]=b.useState(!1);if(b.useEffect(()=>{if(!i)return;let f=!0;return sS().then(d=>f&&u(d.access)),()=>{f=!1}},[i]),!i){const f=`${location.pathname}${location.search}`;return E.jsx(fn,{size:"lg",variant:"ghost",className:"gap-1.5 px-2 font-normal",icon:E.jsx(kC,{className:"size-4"}),onClick:()=>location.href=l2(n.signInUrl,f,location.origin),children:E.jsx("span",{className:"max-sm:hidden",children:he("signIn")})})}return E.jsxs(H0,{align:"end",trigger:E.jsx("button",{type:"button","aria-label":he("accountOf",{name:i.name}),title:i.email?`${i.name} · ${i.email}`:i.name,className:"inline-flex size-8 shrink-0 items-center justify-center rounded-full outline-none hover:bg-hover focus-visible:outline-2 focus-visible:outline-accent data-[popup-open]:bg-hover",children:E.jsx(kb,{id:i.id,name:i.name,avatar:i.avatar,size:26})}),children:[E.jsx(FC,{children:E.jsxs("span",{className:"flex max-w-64 items-center gap-2.5 py-0.5",children:[E.jsx(kb,{id:i.id,name:i.name,avatar:i.avatar,size:32}),E.jsxs("span",{className:"min-w-0",children:[E.jsx("span",{className:"block truncate text-[13px] font-medium text-fg",children:i.name}),i.email?E.jsx("span",{className:"block truncate text-xs",children:i.email}):null]})]})}),E.jsx(ks,{}),l.map(f=>E.jsx(To,{icon:E.jsx(fp,{className:"size-3.5"}),onSelect:()=>gM(f.href),children:f.label},`${f.label} ${f.href}`)),l.length>0?E.jsx(ks,{}):null,E.jsx(To,{icon:E.jsx(jC,{className:"size-3.5"}),onSelect:()=>{hM(n.signOutUrl)},children:he(r?"signOutAccess":"signOut")})]})}function yM({site:n,compact:i=!1}){const l=Sp(n)?.brand,[r,u]=b.useState(!1);if(!l)return null;const f=l.logoUrl&&!r?E.jsx("img",{src:l.logoUrl,alt:l.name?"":"logo",referrerPolicy:"no-referrer",className:i?"h-5 w-auto shrink-0":"h-6 w-auto shrink-0",onError:()=>u(!0)}):null;return E.jsxs("span",{"data-site-brand":"",className:"inline-flex min-w-0 items-center gap-1.5",children:[f,l.name?E.jsx("span",{className:i?"truncate text-[13px] font-medium text-fg-muted max-sm:hidden":"truncate",children:l.name}):null]})}function bM({site:n}){const i=Q0(n,"home");return i.length===0?null:E.jsx("nav",{"aria-label":"Site links",className:"mb-4 flex flex-wrap gap-x-4 gap-y-1 text-[13px]",children:i.map(l=>{const r=Z0(l.href,location.origin);return E.jsxs("a",{href:l.href,...r?{target:"_blank",rel:"noopener noreferrer"}:{},className:"inline-flex items-center gap-1 text-accent hover:underline",children:[l.label,r?E.jsx(fp,{"aria-hidden":!0,className:"size-3"}):null]},`${l.label} ${l.href}`)})})}function vM(){const n=ze(r=>r.types),i=n?p2(n.types):null,l=E.jsx(fn,{size:"lg",variant:"primary",icon:E.jsx(A0,{className:"size-3.5"}),disabled:!i,onClick:()=>i&&ze.getState().setCreating(i),children:he("newArtifact")});return i||!n?l:E.jsx(t0,{label:he("cannotCreateYet"),children:E.jsx("span",{tabIndex:0,children:l})})}function SM(){const n=ze(u=>u.tab),i=ze(u=>u.error),l=to.cloud,r=l?.site?.brand?.name;return b.useEffect(()=>{r&&(document.title=r)},[r]),b.useEffect(()=>{Fl(),l||aS();const u=k2(),f=Z2();return()=>{u(),f()}},[]),E.jsxs("div",{className:"h-full overflow-auto bg-canvas text-fg",children:[E.jsxs("div",{className:"mx-auto max-w-[1040px] px-4 pb-12 pt-6",children:[E.jsxs("div",{className:"flex items-start justify-between gap-3",children:[E.jsxs("div",{className:"min-w-0",children:[E.jsx("h1",{className:"mb-1 mt-0 text-xl font-semibold",children:l?.site?.brand?E.jsx(yM,{site:l.site}):he("homeTitle")}),E.jsx("p",{className:"mb-5 mt-0 text-fg-muted",children:he(l?"homeSubCloud":"homeSub")}),l?E.jsx(bM,{site:l.site}):null]}),l?E.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[l.user?E.jsx(tM,{}):null,E.jsx(mM,{cloud:l})]}):E.jsx(vM,{})]}),i?E.jsxs("p",{role:"alert",className:"mb-3 flex items-center gap-1.5 text-xs text-danger",children:[E.jsx(tu,{className:"size-3.5"}),i]}):null,l?l.user?E.jsx(rM,{}):E.jsx(yd,{}):E.jsx(K0,{value:n,onChange:u=>ze.getState().setTab(u),className:"[&>[role=tabpanel]]:overflow-visible [&>[role=tabpanel]]:pt-4 [&_[role=tab][aria-selected=true]]:bg-hover [&_[role=tab][aria-selected=true]]:text-fg",items:[{value:"artifacts",label:he("artifacts"),content:E.jsx(yd,{})},{value:"types",label:he("types"),content:E.jsx(pM,{})}]})]}),E.jsx(sM,{}),E.jsx(uM,{}),E.jsx(cM,{}),l?E.jsx(lM,{}):null]})}document.documentElement.lang=bp;NT.createRoot(document.getElementById("root")).render(E.jsx(b.StrictMode,{children:E.jsx(dR,{children:E.jsx(WO,{children:E.jsx(SM,{})})})}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Open Artifact</title>
7
7
  <script>window.__OPEN_ARTIFACT_HOME__ = /*__OPEN_ARTIFACT_HOME__*/null;</script>
8
- <script type="module" crossorigin src="/_open-artifact/home/assets/index-DJ2oNcZE.js"></script>
8
+ <script type="module" crossorigin src="/_open-artifact/home/assets/index-CMbgE2oc.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/_open-artifact/home/assets/index-B-XFOdw0.css">
10
10
  </head>
11
11
  <body>