@tangle-network/agent-app 0.60.80 → 0.60.82

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.
@@ -84,7 +84,7 @@ import {
84
84
  warmBinOf,
85
85
  warmWeekdayOf,
86
86
  writeProfileFilesToBox
87
- } from "../chunk-MBEJPQW6.js";
87
+ } from "../chunk-A5CZ2X6C.js";
88
88
  import {
89
89
  EGRESS_PROXY_RECOVERY_PHASE,
90
90
  EGRESS_PROXY_RECOVERY_REQUIRED,
@@ -17,10 +17,15 @@
17
17
  * open for as long as the member's tab is, which is exactly as long as a warm
18
18
  * is useful. The browser never awaits it for UI.
19
19
  *
20
- * IDEMPOTENCE. The in-process map only collapses concurrent calls within one
21
- * isolate. Two isolates can both run the warm, so the product's warm must be
22
- * safe to repeat: a resume of a running box is a no-op, and a creation needs a
23
- * claim store (see `createSandboxPrewarmer`).
20
+ * IDEMPOTENCE. The in-process record only collapses concurrent calls within
21
+ * one isolate, and a second call answers `joined` at once instead of awaiting
22
+ * the first: on Workers a warm's I/O belongs to the request that started it, so
23
+ * when that request is cancelled (the member navigates) its promise never
24
+ * settles, and requests awaiting it hung 43-45 s (Hospitality production,
25
+ * 2026-10-11). A record older than `staleMs` no longer counts. Two isolates can
26
+ * both run the warm, so the product's warm must be safe to repeat: a resume of
27
+ * a running box is a no-op, and a creation needs a claim store (see
28
+ * `createSandboxPrewarmer`).
24
29
  *
25
30
  * FAILURE. A thrown warm answers 200 `{ outcome: 'failed' }` without the error
26
31
  * text, which can name internal hosts. `onEvent` receives the error so the
@@ -49,11 +54,13 @@ export type WorkspacePrewarmAuthorization =
49
54
  key: string;
50
55
  warm: () => Promise<WorkspacePrewarmReport | void>;
51
56
  };
57
+ /** Why the browser asked: `useWorkspacePrewarm` sends `page-open` or `composer-focus`. */
58
+ export type WorkspacePrewarmReason = 'page-open' | 'composer-focus';
52
59
  export type WorkspacePrewarmReport = Record<string, string | number | boolean | null>;
53
60
  export type WorkspacePrewarmOutcome =
54
61
  /** This request ran the warm to completion. */
55
62
  'warmed'
56
- /** Another request in this isolate was already running it; this one waited for it. */
63
+ /** Another request in this isolate is already running it; this one answered at once. */
57
64
  | 'joined'
58
65
  /** The same key warmed successfully within `recentMs`; nothing ran. */
59
66
  | 'recent' | 'declined'
@@ -61,7 +68,7 @@ export type WorkspacePrewarmOutcome =
61
68
  | 'automated' | 'failed';
62
69
  export interface WorkspacePrewarmResponse {
63
70
  outcome: WorkspacePrewarmOutcome;
64
- /** Time this request spent, including any warm it ran or joined. */
71
+ /** Time this request spent, including any warm it ran. A `joined` answer never waits. */
65
72
  ms: number;
66
73
  reason?: string;
67
74
  report?: WorkspacePrewarmReport;
@@ -83,9 +90,15 @@ export interface CreateWorkspacePrewarmRouteOptions<Context = void> {
83
90
  authorize(input: {
84
91
  request: Request;
85
92
  context: Context;
93
+ reason: WorkspacePrewarmReason;
86
94
  }): Promise<WorkspacePrewarmAuthorization>;
87
95
  /** After a successful warm, answer `recent` for this long. Default 30 000 ms. */
88
96
  recentMs?: number;
97
+ /** A warm started longer ago than this no longer blocks the key: its request
98
+ * may have been cancelled, taking the warm with it. A longer warm still
99
+ * running is repeated, which is safe because warms must be idempotent.
100
+ * Default 45 000 ms (a suspended box resumes in ~31 s). */
101
+ staleMs?: number;
89
102
  /** Observability for warms this route ran. Errors thrown here are ignored. */
90
103
  onEvent?(event: WorkspacePrewarmEvent): void;
91
104
  /** Clock seam for tests. */
@@ -139,7 +139,7 @@ import {
139
139
  withoutRecordGridCreated,
140
140
  withoutRecordGridRemoved,
141
141
  withoutRecordGridUpdate
142
- } from "../chunk-OUW5AI2G.js";
142
+ } from "../chunk-A2TCZVW4.js";
143
143
  import {
144
144
  SessionHistoryPanel,
145
145
  formatSessionTimestamp,
@@ -16,6 +16,8 @@
16
16
  export interface WorkspacePrewarmRequestOptions {
17
17
  /** Minimum gap between requests for the same URL in this tab. Default 60 000 ms. */
18
18
  minIntervalMs?: number;
19
+ /** Sent to the route so a product can budget page opens apart from composer focus. Default `page-open`. */
20
+ reason?: 'page-open' | 'composer-focus';
19
21
  }
20
22
  export interface UseWorkspacePrewarmOptions extends WorkspacePrewarmRequestOptions {
21
23
  /** The product's prewarm route for this workspace. Empty disables. */
@@ -36,13 +36,14 @@ function WorkspaceExportPanel({ endpoint, canExport, title = "Export workspace d
36
36
  const drive = useCallback(async (id) => {
37
37
  if (driving.current === id) return;
38
38
  driving.current = id;
39
+ const retired = () => !mounted.current || driving.current !== id;
39
40
  let failures = 0;
40
41
  try {
41
42
  for (; ; ) {
42
- if (!mounted.current) return;
43
+ if (retired()) return;
43
44
  try {
44
45
  const next = await readJson(await doFetch(`${endpoint}/${id}/advance`, { method: "POST", credentials: "same-origin" }));
45
- if (!mounted.current) return;
46
+ if (retired()) return;
46
47
  failures = 0;
47
48
  setError(null);
48
49
  upsert(next);
@@ -57,7 +58,7 @@ function WorkspaceExportPanel({ endpoint, canExport, title = "Export workspace d
57
58
  } catch (err) {
58
59
  if (mounted.current) setError(err instanceof Error ? err.message : String(err));
59
60
  } finally {
60
- driving.current = null;
61
+ if (driving.current === id) driving.current = null;
61
62
  }
62
63
  }, [doFetch, endpoint, upsert]);
63
64
  const refresh = useCallback(async () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/workspace-export/react.tsx"],"sourcesContent":["/**\n * Export panel for a workspace settings page. Starts an export, drives it to\n * completion by calling `advance` while the page is open, shows each source as\n * it finishes, and offers the signed download link. Reopening the page resumes\n * a running export.\n */\n\nimport { Button, Card, StatusPill, type StatusTone } from '@tangle-network/ui/primitives'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport type { ExportProgress } from './types'\n\nexport interface WorkspaceExportPanelProps {\n /** The mount path of the product's export routes, e.g. `/api/workspaces/ws-1/exports`. */\n endpoint: string\n /** Hidden for non-owners; the server refuses them regardless. */\n canExport: boolean\n title?: string\n className?: string\n fetcher?: typeof fetch\n}\n\nconst BYTE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB']\n\nfunction formatBytes(bytes: number): string {\n let value = bytes\n let unit = 0\n while (value >= 1024 && unit < BYTE_UNITS.length - 1) {\n value /= 1024\n unit += 1\n }\n return `${value < 10 && unit ? value.toFixed(1) : Math.round(value)} ${BYTE_UNITS[unit]}`\n}\n\nconst TONE: Record<ExportProgress['status'], StatusTone> = { running: 'info', complete: 'success', failed: 'danger' }\nconst LABEL: Record<ExportProgress['status'], string> = { running: 'Preparing', complete: 'Ready', failed: 'Failed' }\n\nasync function readJson<T>(response: Response): Promise<T> {\n const body = (await response.json().catch(() => null)) as { error?: { message?: string } } | null\n if (!response.ok) throw new Error(body?.error?.message ?? `Request failed (${response.status})`)\n return body as T\n}\n\nexport function WorkspaceExportPanel({ endpoint, canExport, title = 'Export workspace data', className, fetcher }: WorkspaceExportPanelProps) {\n const doFetch = fetcher ?? fetch\n const [exports, setExports] = useState<ExportProgress[]>([])\n const [error, setError] = useState<string | null>(null)\n const [loading, setLoading] = useState(true)\n const [starting, setStarting] = useState(false)\n const driving = useRef<string | null>(null)\n const mounted = useRef(true)\n\n useEffect(() => () => {\n mounted.current = false\n }, [])\n\n const upsert = useCallback((next: ExportProgress) => {\n setExports((current) => [next, ...current.filter((e) => e.id !== next.id)])\n }, [])\n\n const drive = useCallback(async (id: string) => {\n if (driving.current === id) return\n driving.current = id\n // A failed request is retried: the server records each attempt and fails\n // the export itself once a source cannot finish.\n let failures = 0\n try {\n for (;;) {\n if (!mounted.current) return\n try {\n const next = await readJson<ExportProgress>(await doFetch(`${endpoint}/${id}/advance`, { method: 'POST', credentials: 'same-origin' }))\n if (!mounted.current) return\n failures = 0\n setError(null)\n upsert(next)\n if (next.status !== 'running') return\n } catch (err) {\n failures += 1\n if (failures >= 6) throw err\n if (mounted.current) setError(`Still working; retrying (${failures})`)\n }\n // Another tab may hold the lease, or the last request failed; wait before asking again.\n await new Promise((resolve) => setTimeout(resolve, failures ? 3000 * failures : 1500))\n }\n } catch (err) {\n if (mounted.current) setError(err instanceof Error ? err.message : String(err))\n } finally {\n driving.current = null\n }\n }, [doFetch, endpoint, upsert])\n\n const refresh = useCallback(async () => {\n setLoading(true)\n setError(null)\n try {\n const body = await readJson<{ exports: ExportProgress[] }>(await doFetch(endpoint, { credentials: 'same-origin' }))\n if (!mounted.current) return\n setExports(body.exports)\n const running = body.exports.find((e) => e.status === 'running')\n if (running) void drive(running.id)\n } catch (err) {\n if (mounted.current) setError(err instanceof Error ? err.message : String(err))\n } finally {\n if (mounted.current) setLoading(false)\n }\n }, [doFetch, drive, endpoint])\n\n useEffect(() => {\n if (canExport) void refresh()\n }, [canExport, refresh])\n\n const start = async () => {\n setStarting(true)\n setError(null)\n try {\n const job = await readJson<ExportProgress>(await doFetch(endpoint, { method: 'POST', credentials: 'same-origin' }))\n upsert(job)\n void drive(job.id)\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err))\n } finally {\n setStarting(false)\n }\n }\n\n if (!canExport) return null\n const latest = exports[0]\n const running = latest?.status === 'running'\n\n return (\n <Card className={['min-w-0 space-y-4 p-5 shadow-none', className].filter(Boolean).join(' ')} aria-busy={running || loading || undefined}>\n <header className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <h2 className=\"text-base font-semibold\">{title}</h2>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n One zip with every conversation, record, file and the agent workspace, plus a manifest with checksums. Connection credentials are never included.\n </p>\n </div>\n <Button type=\"button\" onClick={start} disabled={starting || running}>\n {running ? 'Exporting…' : starting ? 'Starting…' : 'Export'}\n </Button>\n </header>\n\n {error ? (\n <div role=\"alert\" className=\"flex flex-wrap items-center gap-3 rounded-xl border border-destructive/40 p-3 text-sm text-destructive\">\n <p className=\"min-w-0 flex-1 break-words\">{error}</p>\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={() => (latest?.status === 'running' ? void drive(latest.id) : void refresh())}>\n Retry\n </Button>\n </div>\n ) : null}\n\n {latest ? (\n <section aria-label=\"Latest export\" className=\"space-y-3 rounded-xl border border-border p-4\">\n <div className=\"flex flex-wrap items-center gap-3\">\n <StatusPill tone={TONE[latest.status]} size=\"sm\">{LABEL[latest.status]}</StatusPill>\n <span className=\"text-sm text-muted-foreground\">\n {latest.unitsDone} of {latest.unitsTotal} sources · {formatBytes(latest.bytes)}\n </span>\n {latest.current ? <span className=\"min-w-0 truncate text-sm text-muted-foreground\">Now: {latest.current}</span> : null}\n </div>\n <div\n role=\"progressbar\"\n aria-label=\"Export progress\"\n aria-valuemin={0}\n aria-valuemax={latest.unitsTotal}\n aria-valuenow={latest.unitsDone}\n className=\"h-2 overflow-hidden rounded-full bg-muted\"\n >\n <div\n className=\"h-full rounded-full bg-primary transition-[width] duration-300 motion-reduce:transition-none\"\n style={{ width: `${latest.unitsTotal ? Math.round((latest.unitsDone / latest.unitsTotal) * 100) : 0}%` }}\n />\n </div>\n {latest.status === 'failed' ? (\n <p className=\"text-sm text-destructive [overflow-wrap:anywhere]\">{latest.error ?? 'The export failed.'} Start a new export to try again.</p>\n ) : null}\n {latest.downloadUrl ? (\n <div className=\"flex flex-wrap items-center gap-3\">\n <Button asChild>\n <a href={latest.downloadUrl} download>Download zip</a>\n </Button>\n <span className=\"text-xs text-muted-foreground\">\n Link expires {latest.downloadExpiresAt ? new Date(latest.downloadExpiresAt).toLocaleTimeString() : 'soon'}; refresh the page for a new one.\n </span>\n </div>\n ) : null}\n <details className=\"text-sm\">\n <summary className=\"cursor-pointer text-muted-foreground\">Sources</summary>\n <ul className=\"mt-2 divide-y divide-border\">\n {latest.units.map((unit) => (\n <li key={unit.name} className=\"flex flex-wrap items-center justify-between gap-2 py-1.5\">\n <span className=\"min-w-0 [overflow-wrap:anywhere]\">{unit.name}</span>\n <span className=\"text-xs text-muted-foreground\">\n {unit.status === 'pending' ? 'waiting' : unit.status === 'empty' ? 'nothing to export' : unit.status === 'failed' ? 'failed' : unit.rows !== undefined ? `${unit.rows} rows` : unit.files !== undefined ? `${unit.files} files · ${formatBytes(unit.bytes)}` : formatBytes(unit.bytes)}\n </span>\n </li>\n ))}\n </ul>\n </details>\n </section>\n ) : loading ? (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">Loading exports…</p>\n ) : null}\n </Card>\n )\n}\n"],"mappings":";AAOA,SAAS,QAAQ,MAAM,kBAAmC;AAC1D,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AA2HjD,SACE,KADF;AA9GR,IAAM,aAAa,CAAC,KAAK,MAAM,MAAM,MAAM,IAAI;AAE/C,SAAS,YAAY,OAAuB;AAC1C,MAAI,QAAQ;AACZ,MAAI,OAAO;AACX,SAAO,SAAS,QAAQ,OAAO,WAAW,SAAS,GAAG;AACpD,aAAS;AACT,YAAQ;AAAA,EACV;AACA,SAAO,GAAG,QAAQ,MAAM,OAAO,MAAM,QAAQ,CAAC,IAAI,KAAK,MAAM,KAAK,CAAC,IAAI,WAAW,IAAI,CAAC;AACzF;AAEA,IAAM,OAAqD,EAAE,SAAS,QAAQ,UAAU,WAAW,QAAQ,SAAS;AACpH,IAAM,QAAkD,EAAE,SAAS,aAAa,UAAU,SAAS,QAAQ,SAAS;AAEpH,eAAe,SAAY,UAAgC;AACzD,QAAM,OAAQ,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,IAAI;AACpD,MAAI,CAAC,SAAS,GAAI,OAAM,IAAI,MAAM,MAAM,OAAO,WAAW,mBAAmB,SAAS,MAAM,GAAG;AAC/F,SAAO;AACT;AAEO,SAAS,qBAAqB,EAAE,UAAU,WAAW,QAAQ,yBAAyB,WAAW,QAAQ,GAA8B;AAC5I,QAAM,UAAU,WAAW;AAC3B,QAAM,CAAC,SAAS,UAAU,IAAI,SAA2B,CAAC,CAAC;AAC3D,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,UAAU,OAAsB,IAAI;AAC1C,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AAA,MACH,OAAO,cACN,qBAAC,SAAI,WAAU,qCACb;AAAA,4BAAC,UAAO,SAAO,MACb,8BAAC,OAAE,MAAM,OAAO,aAAa,UAAQ,MAAC,0BAAY,GACpD;AAAA,QACA,qBAAC,UAAK,WAAU,iCAAgC;AAAA;AAAA,UAChC,OAAO,oBAAoB,IAAI,KAAK,OAAO,iBAAiB,EAAE,mBAAmB,IAAI;AAAA,UAAO;AAAA,WAC5G;AAAA,SACF,IACE;AAAA,MACJ,qBAAC,aAAQ,WAAU,WACjB;AAAA,4BAAC,aAAQ,WAAU,wCAAuC,qBAAO;AAAA,QACjE,oBAAC,QAAG,WAAU,+BACX,iBAAO,MAAM,IAAI,CAAC,SACjB,qBAAC,QAAmB,WAAU,4DAC5B;AAAA,8BAAC,UAAK,WAAU,oCAAoC,eAAK,MAAK;AAAA,UAC9D,oBAAC,UAAK,WAAU,iCACb,eAAK,WAAW,YAAY,YAAY,KAAK,WAAW,UAAU,sBAAsB,KAAK,WAAW,WAAW,WAAW,KAAK,SAAS,SAAY,GAAG,KAAK,IAAI,UAAU,KAAK,UAAU,SAAY,GAAG,KAAK,KAAK,eAAY,YAAY,KAAK,KAAK,CAAC,KAAK,YAAY,KAAK,KAAK,GACvR;AAAA,aAJO,KAAK,IAKd,CACD,GACH;AAAA,SACF;AAAA,OACF,IACE,UACF,oBAAC,OAAE,MAAK,UAAS,WAAU,iCAAgC,mCAAgB,IACzE;AAAA,KACN;AAEJ;","names":["running"]}
1
+ {"version":3,"sources":["../../src/workspace-export/react.tsx"],"sourcesContent":["/**\n * Export panel for a workspace settings page. Starts an export, drives it to\n * completion by calling `advance` while the page is open, shows each source as\n * it finishes, and offers the signed download link. Reopening the page resumes\n * a running export.\n */\n\nimport { Button, Card, StatusPill, type StatusTone } from '@tangle-network/ui/primitives'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport type { ExportProgress } from './types'\n\nexport interface WorkspaceExportPanelProps {\n /** The mount path of the product's export routes, e.g. `/api/workspaces/ws-1/exports`. */\n endpoint: string\n /** Hidden for non-owners; the server refuses them regardless. */\n canExport: boolean\n title?: string\n className?: string\n fetcher?: typeof fetch\n}\n\nconst BYTE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB']\n\nfunction formatBytes(bytes: number): string {\n let value = bytes\n let unit = 0\n while (value >= 1024 && unit < BYTE_UNITS.length - 1) {\n value /= 1024\n unit += 1\n }\n return `${value < 10 && unit ? value.toFixed(1) : Math.round(value)} ${BYTE_UNITS[unit]}`\n}\n\nconst TONE: Record<ExportProgress['status'], StatusTone> = { running: 'info', complete: 'success', failed: 'danger' }\nconst LABEL: Record<ExportProgress['status'], string> = { running: 'Preparing', complete: 'Ready', failed: 'Failed' }\n\nasync function readJson<T>(response: Response): Promise<T> {\n const body = (await response.json().catch(() => null)) as { error?: { message?: string } } | null\n if (!response.ok) throw new Error(body?.error?.message ?? `Request failed (${response.status})`)\n return body as T\n}\n\nexport function WorkspaceExportPanel({ endpoint, canExport, title = 'Export workspace data', className, fetcher }: WorkspaceExportPanelProps) {\n const doFetch = fetcher ?? fetch\n const [exports, setExports] = useState<ExportProgress[]>([])\n const [error, setError] = useState<string | null>(null)\n const [loading, setLoading] = useState(true)\n const [starting, setStarting] = useState(false)\n const driving = useRef<string | null>(null)\n const mounted = useRef(true)\n\n useEffect(() => () => {\n mounted.current = false\n }, [])\n\n const upsert = useCallback((next: ExportProgress) => {\n setExports((current) => [next, ...current.filter((e) => e.id !== next.id)])\n }, [])\n\n const drive = useCallback(async (id: string) => {\n // One driver at a time: starting another export retires the old loop, so a\n // stale running job and a new one are never advanced together.\n if (driving.current === id) return\n driving.current = id\n const retired = () => !mounted.current || driving.current !== id\n // A failed request is retried: the server records each attempt and fails\n // the export itself once a source cannot finish.\n let failures = 0\n try {\n for (;;) {\n if (retired()) return\n try {\n const next = await readJson<ExportProgress>(await doFetch(`${endpoint}/${id}/advance`, { method: 'POST', credentials: 'same-origin' }))\n if (retired()) return\n failures = 0\n setError(null)\n upsert(next)\n if (next.status !== 'running') return\n } catch (err) {\n failures += 1\n if (failures >= 6) throw err\n if (mounted.current) setError(`Still working; retrying (${failures})`)\n }\n // Another tab may hold the lease, or the last request failed; wait before asking again.\n await new Promise((resolve) => setTimeout(resolve, failures ? 3000 * failures : 1500))\n }\n } catch (err) {\n if (mounted.current) setError(err instanceof Error ? err.message : String(err))\n } finally {\n if (driving.current === id) driving.current = null\n }\n }, [doFetch, endpoint, upsert])\n\n const refresh = useCallback(async () => {\n setLoading(true)\n setError(null)\n try {\n const body = await readJson<{ exports: ExportProgress[] }>(await doFetch(endpoint, { credentials: 'same-origin' }))\n if (!mounted.current) return\n setExports(body.exports)\n const running = body.exports.find((e) => e.status === 'running')\n if (running) void drive(running.id)\n } catch (err) {\n if (mounted.current) setError(err instanceof Error ? err.message : String(err))\n } finally {\n if (mounted.current) setLoading(false)\n }\n }, [doFetch, drive, endpoint])\n\n useEffect(() => {\n if (canExport) void refresh()\n }, [canExport, refresh])\n\n const start = async () => {\n setStarting(true)\n setError(null)\n try {\n const job = await readJson<ExportProgress>(await doFetch(endpoint, { method: 'POST', credentials: 'same-origin' }))\n upsert(job)\n void drive(job.id)\n } catch (err) {\n setError(err instanceof Error ? err.message : String(err))\n } finally {\n setStarting(false)\n }\n }\n\n if (!canExport) return null\n const latest = exports[0]\n const running = latest?.status === 'running'\n\n return (\n <Card className={['min-w-0 space-y-4 p-5 shadow-none', className].filter(Boolean).join(' ')} aria-busy={running || loading || undefined}>\n <header className=\"flex flex-wrap items-start justify-between gap-3\">\n <div className=\"min-w-0\">\n <h2 className=\"text-base font-semibold\">{title}</h2>\n <p className=\"mt-1 text-sm text-muted-foreground\">\n One zip with every conversation, record, file and the agent workspace, plus a manifest with checksums. Connection credentials are never included.\n </p>\n </div>\n <Button type=\"button\" onClick={start} disabled={starting || running}>\n {running ? 'Exporting…' : starting ? 'Starting…' : 'Export'}\n </Button>\n </header>\n\n {error ? (\n <div role=\"alert\" className=\"flex flex-wrap items-center gap-3 rounded-xl border border-destructive/40 p-3 text-sm text-destructive\">\n <p className=\"min-w-0 flex-1 break-words\">{error}</p>\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={() => (latest?.status === 'running' ? void drive(latest.id) : void refresh())}>\n Retry\n </Button>\n </div>\n ) : null}\n\n {latest ? (\n <section aria-label=\"Latest export\" className=\"space-y-3 rounded-xl border border-border p-4\">\n <div className=\"flex flex-wrap items-center gap-3\">\n <StatusPill tone={TONE[latest.status]} size=\"sm\">{LABEL[latest.status]}</StatusPill>\n <span className=\"text-sm text-muted-foreground\">\n {latest.unitsDone} of {latest.unitsTotal} sources · {formatBytes(latest.bytes)}\n </span>\n {latest.current ? <span className=\"min-w-0 truncate text-sm text-muted-foreground\">Now: {latest.current}</span> : null}\n </div>\n <div\n role=\"progressbar\"\n aria-label=\"Export progress\"\n aria-valuemin={0}\n aria-valuemax={latest.unitsTotal}\n aria-valuenow={latest.unitsDone}\n className=\"h-2 overflow-hidden rounded-full bg-muted\"\n >\n <div\n className=\"h-full rounded-full bg-primary transition-[width] duration-300 motion-reduce:transition-none\"\n style={{ width: `${latest.unitsTotal ? Math.round((latest.unitsDone / latest.unitsTotal) * 100) : 0}%` }}\n />\n </div>\n {latest.status === 'failed' ? (\n <p className=\"text-sm text-destructive [overflow-wrap:anywhere]\">{latest.error ?? 'The export failed.'} Start a new export to try again.</p>\n ) : null}\n {latest.downloadUrl ? (\n <div className=\"flex flex-wrap items-center gap-3\">\n <Button asChild>\n <a href={latest.downloadUrl} download>Download zip</a>\n </Button>\n <span className=\"text-xs text-muted-foreground\">\n Link expires {latest.downloadExpiresAt ? new Date(latest.downloadExpiresAt).toLocaleTimeString() : 'soon'}; refresh the page for a new one.\n </span>\n </div>\n ) : null}\n <details className=\"text-sm\">\n <summary className=\"cursor-pointer text-muted-foreground\">Sources</summary>\n <ul className=\"mt-2 divide-y divide-border\">\n {latest.units.map((unit) => (\n <li key={unit.name} className=\"flex flex-wrap items-center justify-between gap-2 py-1.5\">\n <span className=\"min-w-0 [overflow-wrap:anywhere]\">{unit.name}</span>\n <span className=\"text-xs text-muted-foreground\">\n {unit.status === 'pending' ? 'waiting' : unit.status === 'empty' ? 'nothing to export' : unit.status === 'failed' ? 'failed' : unit.rows !== undefined ? `${unit.rows} rows` : unit.files !== undefined ? `${unit.files} files · ${formatBytes(unit.bytes)}` : formatBytes(unit.bytes)}\n </span>\n </li>\n ))}\n </ul>\n </details>\n </section>\n ) : loading ? (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">Loading exports…</p>\n ) : null}\n </Card>\n )\n}\n"],"mappings":";AAOA,SAAS,QAAQ,MAAM,kBAAmC;AAC1D,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AA8HjD,SACE,KADF;AAjHR,IAAM,aAAa,CAAC,KAAK,MAAM,MAAM,MAAM,IAAI;AAE/C,SAAS,YAAY,OAAuB;AAC1C,MAAI,QAAQ;AACZ,MAAI,OAAO;AACX,SAAO,SAAS,QAAQ,OAAO,WAAW,SAAS,GAAG;AACpD,aAAS;AACT,YAAQ;AAAA,EACV;AACA,SAAO,GAAG,QAAQ,MAAM,OAAO,MAAM,QAAQ,CAAC,IAAI,KAAK,MAAM,KAAK,CAAC,IAAI,WAAW,IAAI,CAAC;AACzF;AAEA,IAAM,OAAqD,EAAE,SAAS,QAAQ,UAAU,WAAW,QAAQ,SAAS;AACpH,IAAM,QAAkD,EAAE,SAAS,aAAa,UAAU,SAAS,QAAQ,SAAS;AAEpH,eAAe,SAAY,UAAgC;AACzD,QAAM,OAAQ,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,IAAI;AACpD,MAAI,CAAC,SAAS,GAAI,OAAM,IAAI,MAAM,MAAM,OAAO,WAAW,mBAAmB,SAAS,MAAM,GAAG;AAC/F,SAAO;AACT;AAEO,SAAS,qBAAqB,EAAE,UAAU,WAAW,QAAQ,yBAAyB,WAAW,QAAQ,GAA8B;AAC5I,QAAM,UAAU,WAAW;AAC3B,QAAM,CAAC,SAAS,UA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
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.60.80",
3
+ "version": "0.60.82",
4
4
  "packageManager": "pnpm@11.24.0",
5
5
  "description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
6
6
  "keywords": [