@tangle-network/agent-app 0.60.110 → 0.60.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/teams-react/index.js +8 -8
- package/dist/teams-react/index.js.map +1 -1
- package/dist/workspace-export/engine.d.ts +8 -0
- package/dist/workspace-export/index.d.ts +2 -2
- package/dist/workspace-export/index.js +185 -51
- package/dist/workspace-export/index.js.map +1 -1
- package/dist/workspace-export/react.js +4 -2
- package/dist/workspace-export/react.js.map +1 -1
- package/dist/workspace-export/sandbox.d.ts +37 -8
- package/dist/workspace-export/tar.d.ts +10 -6
- package/dist/workspace-export/types.d.ts +15 -2
- package/package.json +1 -1
|
@@ -115,7 +115,9 @@ function WorkspaceExportPanel({ endpoint, canExport, title = "Export workspace d
|
|
|
115
115
|
latest.unitsDone,
|
|
116
116
|
" of ",
|
|
117
117
|
latest.unitsTotal,
|
|
118
|
-
" sources
|
|
118
|
+
" sources",
|
|
119
|
+
latest.unitsFailed ? ` \xB7 ${latest.unitsFailed} failed` : "",
|
|
120
|
+
" \xB7 ",
|
|
119
121
|
formatBytes(latest.bytes)
|
|
120
122
|
] }),
|
|
121
123
|
latest.current ? /* @__PURE__ */ jsxs("span", { className: "min-w-0 truncate text-sm text-muted-foreground", children: [
|
|
@@ -136,7 +138,7 @@ function WorkspaceExportPanel({ endpoint, canExport, title = "Export workspace d
|
|
|
136
138
|
children: /* @__PURE__ */ jsx(
|
|
137
139
|
"div",
|
|
138
140
|
{
|
|
139
|
-
className:
|
|
141
|
+
className: `h-full rounded-full ${latest.status === "failed" ? "bg-destructive" : "bg-primary"} transition-[width] duration-300 motion-reduce:transition-none`,
|
|
140
142
|
style: { width: `${latest.unitsTotal ? Math.round(latest.unitsDone / latest.unitsTotal * 100) : 0}%` }
|
|
141
143
|
}
|
|
142
144
|
)
|
|
@@ -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, type ReactNode } 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 /** One short muted line under the title. Pass `null` to render none. */\n description?: ReactNode\n className?: string\n fetcher?: typeof fetch\n /** True when the product runs `continueRunning` on a cron, so the export finishes after the page closes. */\n continuesInBackground?: boolean\n}\n\nconst DEFAULT_DESCRIPTION = 'Everything in one zip. Credentials are never included.'\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', description = DEFAULT_DESCRIPTION, className, fetcher, continuesInBackground = false }: 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 {description != null && description !== false ? (\n <p className=\"mt-1 text-sm text-muted-foreground\">{description}</p>\n ) : null}\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 {running && continuesInBackground ? (\n <p className=\"text-xs text-muted-foreground\">You can close this page. The export keeps going, and the download is here when you return.</p>\n ) : null}\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,gBAAgC;AAoIjE,SACE,KADF;AAnHR,IAAM,sBAAsB;AAE5B,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,M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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, type ReactNode } 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 /** One short muted line under the title. Pass `null` to render none. */\n description?: ReactNode\n className?: string\n fetcher?: typeof fetch\n /** True when the product runs `continueRunning` on a cron, so the export finishes after the page closes. */\n continuesInBackground?: boolean\n}\n\nconst DEFAULT_DESCRIPTION = 'Everything in one zip. Credentials are never included.'\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', description = DEFAULT_DESCRIPTION, className, fetcher, continuesInBackground = false }: 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 {description != null && description !== false ? (\n <p className=\"mt-1 text-sm text-muted-foreground\">{description}</p>\n ) : null}\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{latest.unitsFailed ? ` · ${latest.unitsFailed} failed` : ''} · {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 {running && continuesInBackground ? (\n <p className=\"text-xs text-muted-foreground\">You can close this page. The export keeps going, and the download is here when you return.</p>\n ) : null}\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 ${latest.status === 'failed' ? 'bg-destructive' : '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,gBAAgC;AAoIjE,SACE,KADF;AAnHR,IAAM,sBAAsB;AAE5B,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,cAAc,qBA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G,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,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The sandbox
|
|
3
|
-
*
|
|
2
|
+
* The sandbox sources every app needs, so no product hand-rolls box lifecycle
|
|
3
|
+
* around `fs.openArchive` and `fs.read`.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Both refuse a box that is not running. A stopped box is resumed for the
|
|
6
|
+
* export and stopped again once it has been read, so exporting neither fails on
|
|
7
|
+
* an idle workspace nor leaves the owner paying for a box they had stopped. A
|
|
8
|
+
* box that no longer exists exports nothing. A box busy with another lifecycle
|
|
9
|
+
* operation (a page-open warm, the previous export's stop) is retried on a
|
|
10
|
+
* later request instead of failing the export.
|
|
9
11
|
*/
|
|
10
|
-
import type { ExportArchiveSource, ExportDataClass } from './types';
|
|
11
|
-
/** The slice of the Sandbox SDK's `SandboxInstance`
|
|
12
|
+
import type { ExportArchiveSource, ExportDataClass, ExportFilesSource } from './types';
|
|
13
|
+
/** The slice of the Sandbox SDK's `SandboxInstance` these sources use. */
|
|
12
14
|
export interface ArchivableBox {
|
|
13
15
|
readonly status: string;
|
|
14
16
|
resume(): Promise<void>;
|
|
@@ -20,8 +22,15 @@ export interface ArchivableBox {
|
|
|
20
22
|
openArchive(dir: string, options?: {
|
|
21
23
|
signal?: AbortSignal;
|
|
22
24
|
}): Promise<ReadableStream<Uint8Array>>;
|
|
25
|
+
read?(path: string): Promise<string>;
|
|
23
26
|
};
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Never customer data: installed packages and the platform's runtime state. In
|
|
30
|
+
* a Hospitality box they were 98% of the archive (110 MB of node_modules and
|
|
31
|
+
* 12.5 MB of .sidecar beside 0.4 MB of workspace files).
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_SANDBOX_EXCLUDE: readonly string[];
|
|
25
34
|
/**
|
|
26
35
|
* One sandbox's filesystem as `sandbox/<name>.tar.gz`. `getBox` returns the
|
|
27
36
|
* SDK instance (`client.get(id)`), or `null` when the box is gone.
|
|
@@ -31,8 +40,28 @@ export declare function sandboxArchive(args: {
|
|
|
31
40
|
getBox(): Promise<ArchivableBox | null>;
|
|
32
41
|
/** Directory to archive, relative to the box workspace. Default `.`. */
|
|
33
42
|
dir?: string;
|
|
43
|
+
/** Directory names left out wherever they appear. Default `DEFAULT_SANDBOX_EXCLUDE`. */
|
|
44
|
+
exclude?: readonly string[];
|
|
34
45
|
dataClass?: ExportDataClass;
|
|
35
46
|
description?: string;
|
|
36
47
|
/** How long to wait for a resumed box. Default 120 s. */
|
|
37
48
|
resumeTimeoutMs?: number;
|
|
38
49
|
}): ExportArchiveSource;
|
|
50
|
+
/**
|
|
51
|
+
* Named text files read from one sandbox, written under `files/<name>/<path>`.
|
|
52
|
+
* Use it where the product stores documents in a box under internal names (a
|
|
53
|
+
* content-addressed vault), so the owner gets each one under its real name.
|
|
54
|
+
* `list` reads the product's own records; the box is resumed only when it
|
|
55
|
+
* returns files.
|
|
56
|
+
*/
|
|
57
|
+
export declare function sandboxFiles(args: {
|
|
58
|
+
name: string;
|
|
59
|
+
getBox(): Promise<ArchivableBox | null>;
|
|
60
|
+
list(): Promise<{
|
|
61
|
+
path: string;
|
|
62
|
+
boxPath: string;
|
|
63
|
+
}[]>;
|
|
64
|
+
dataClass?: ExportDataClass;
|
|
65
|
+
description?: string;
|
|
66
|
+
resumeTimeoutMs?: number;
|
|
67
|
+
}): ExportFilesSource;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reads an uncompressed tar stream in flight
|
|
2
|
+
* Reads an uncompressed tar stream in flight.
|
|
3
3
|
*
|
|
4
|
-
* It counts members for the manifest
|
|
5
|
-
* credential files (see `isCredentialFile`) with
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* It counts members for the manifest, overwrites the contents of known
|
|
5
|
+
* credential files (see `isCredentialFile`) with `*` so the archive still shows
|
|
6
|
+
* the file existed, and drops every member under an excluded directory name
|
|
7
|
+
* (`node_modules`, runtime caches) with its long-name records, so the result
|
|
8
|
+
* stays a valid tar. Handles ustar prefixes, GNU long names (`L`) and pax
|
|
9
|
+
* `path=` records.
|
|
8
10
|
*/
|
|
9
11
|
export interface TarStats {
|
|
10
12
|
files: number;
|
|
11
13
|
bytes: number;
|
|
12
14
|
blanked: string[];
|
|
15
|
+
/** Members dropped because a path segment is excluded. */
|
|
16
|
+
excluded?: number;
|
|
13
17
|
}
|
|
14
|
-
export declare function createTarInspector(stats: TarStats): TransformStream<Uint8Array, Uint8Array>;
|
|
18
|
+
export declare function createTarInspector(stats: TarStats, exclude?: readonly string[]): TransformStream<Uint8Array, Uint8Array>;
|
|
@@ -9,9 +9,15 @@ interface SourceBase {
|
|
|
9
9
|
/** One line for the manifest, e.g. which table or prefix this reads. */
|
|
10
10
|
description?: string;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Rows written as NDJSON to `data/<name>.ndjson`, or with `format: 'csv'` as a
|
|
14
|
+
* spreadsheet at `spreadsheets/<name>.csv`. A source with no rows writes no file.
|
|
15
|
+
*/
|
|
13
16
|
export interface ExportRowsSource extends SourceBase {
|
|
14
17
|
kind: 'rows';
|
|
18
|
+
/** `csv` needs `columns`: the header row, in order. Default `ndjson`. */
|
|
19
|
+
format?: 'ndjson' | 'csv';
|
|
20
|
+
columns?: readonly string[];
|
|
15
21
|
/** Yield rows or pages of rows. Products decrypt their own encrypted columns here. */
|
|
16
22
|
rows(): AsyncIterable<ExportRow | ExportRow[]>;
|
|
17
23
|
/** The count the database reports, recorded beside the written count. */
|
|
@@ -39,6 +45,8 @@ export interface ExportArchiveSource extends SourceBase {
|
|
|
39
45
|
kind: 'archive';
|
|
40
46
|
/** `null` when there is nothing to archive (no sandbox for this workspace). */
|
|
41
47
|
open(): Promise<ReadableStream<Uint8Array> | null>;
|
|
48
|
+
/** Directory names whose contents are left out wherever they appear, e.g. `node_modules`. */
|
|
49
|
+
exclude?: readonly string[];
|
|
42
50
|
}
|
|
43
51
|
/** One JSON document written to `data/<name>.json`. */
|
|
44
52
|
export interface ExportJsonSource extends SourceBase {
|
|
@@ -83,12 +91,15 @@ export interface ExportUnit {
|
|
|
83
91
|
files?: number;
|
|
84
92
|
/** Files listed so far by a files unit that continues in the next request. */
|
|
85
93
|
cursor?: number;
|
|
86
|
-
/** Members and bytes inside a sandbox archive
|
|
94
|
+
/** Members and bytes inside a sandbox archive, and members left out by `exclude`. */
|
|
87
95
|
archive?: {
|
|
88
96
|
files: number;
|
|
89
97
|
bytes: number;
|
|
90
98
|
blanked: string[];
|
|
99
|
+
excluded?: number;
|
|
91
100
|
};
|
|
101
|
+
/** Times the source asked to be retried later (a busy sandbox) without spending an attempt. */
|
|
102
|
+
deferrals?: number;
|
|
92
103
|
redactions: number;
|
|
93
104
|
error?: string;
|
|
94
105
|
}
|
|
@@ -119,7 +130,9 @@ export interface ExportProgress {
|
|
|
119
130
|
completedAt?: string;
|
|
120
131
|
error?: string;
|
|
121
132
|
unitsTotal: number;
|
|
133
|
+
/** Sources finished, with or without data. Failed sources are counted in `unitsFailed`, never here. */
|
|
122
134
|
unitsDone: number;
|
|
135
|
+
unitsFailed: number;
|
|
123
136
|
current?: string;
|
|
124
137
|
bytes: number;
|
|
125
138
|
units: {
|
package/package.json
CHANGED