diff --git a/apps/desktop/src/lib/trpc/routers/attachments/attachments.test.ts b/apps/desktop/src/lib/trpc/routers/attachments/attachments.test.ts new file mode 100644 index 00000000000..0b73fbb0e11 --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/attachments/attachments.test.ts @@ -0,0 +1,113 @@ +import { afterEach, describe, expect, it } from "bun:test"; +import { + chmodSync, + existsSync, + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { WORKSPACE_ATTACHMENTS_DIR } from "@superset/shared/workspace-attachments"; +import { writeAttachmentsIntoWorktree } from "./attachments"; + +const roots: string[] = []; + +function setup() { + const root = mkdtempSync(join(tmpdir(), "attachments-")); + roots.push(root); + const source = join(root, "build.dmg"); + writeFileSync(source, "first"); + const worktreePath = join(root, "worktree"); + mkdirSync(worktreePath); + return { + root, + source, + worktreePath, + directory: join(worktreePath, WORKSPACE_ATTACHMENTS_DIR), + }; +} + +afterEach(() => { + for (const root of roots.splice(0)) { + rmSync(root, { recursive: true, force: true }); + } +}); + +describe("writeAttachmentsIntoWorktree", () => { + it("copies paths and writes bytes in order, into a self-ignoring dir", async () => { + const { source, worktreePath, directory } = setup(); + + const paths = await writeAttachmentsIntoWorktree({ + worktreePath, + items: [ + { kind: "path", sourcePath: source }, + { + kind: "base64", + name: "image.png", + data: Buffer.from("png").toString("base64"), + }, + ], + }); + + expect(paths).toEqual({ + ok: true, + paths: [ + `${WORKSPACE_ATTACHMENTS_DIR}/build.dmg`, + `${WORKSPACE_ATTACHMENTS_DIR}/image.png`, + ], + }); + expect(readFileSync(join(directory, "build.dmg"), "utf8")).toBe("first"); + expect(readFileSync(join(directory, "image.png"), "utf8")).toBe("png"); + expect(readFileSync(join(directory, ".gitignore"), "utf8")).toBe("*\n"); + }); + + it("never overwrites an earlier attachment", async () => { + const { source, worktreePath, directory } = setup(); + const items = [{ kind: "path" as const, sourcePath: source }]; + + await writeAttachmentsIntoWorktree({ worktreePath, items }); + writeFileSync(source, "second"); + expect(await writeAttachmentsIntoWorktree({ worktreePath, items })).toEqual( + { ok: true, paths: [`${WORKSPACE_ATTACHMENTS_DIR}/build_1.dmg`] }, + ); + expect(readFileSync(join(directory, "build.dmg"), "utf8")).toBe("first"); + }); + + it("reports which source is missing, a folder or unreadable, before writing anything", async () => { + const { root, source, worktreePath, directory } = setup(); + const unreadable = join(root, "locked.txt"); + writeFileSync(unreadable, "secret"); + chmodSync(unreadable, 0o000); + + for (const [sourcePath, problem] of [ + [join(root, "moved.dmg"), "missing"], + [root, "not-a-file"], + [unreadable, "unreadable"], + ] as const) { + expect( + await writeAttachmentsIntoWorktree({ + worktreePath, + items: [ + { kind: "path", sourcePath: source }, + { kind: "path", sourcePath }, + ], + }), + ).toEqual({ ok: false, index: 1, problem }); + } + expect(existsSync(directory)).toBe(false); + }); + + it("refuses a UNC source path", async () => { + const { worktreePath } = setup(); + + await expect( + writeAttachmentsIntoWorktree({ + worktreePath, + items: [{ kind: "path", sourcePath: "//server/share/x.png" }], + }), + ).rejects.toThrow("Not a local absolute path"); + }); +}); diff --git a/apps/desktop/src/lib/trpc/routers/attachments/attachments.ts b/apps/desktop/src/lib/trpc/routers/attachments/attachments.ts new file mode 100644 index 00000000000..ae46fc66840 --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/attachments/attachments.ts @@ -0,0 +1,145 @@ +import { constants } from "node:fs"; +import { copyFile, open, stat, writeFile } from "node:fs/promises"; +import { basename, isAbsolute, join } from "node:path"; +import { + MAX_ATTACHMENT_BYTES, + MAX_ATTACHMENTS, +} from "@superset/shared/attachment-limits"; +import { + attachmentFallbackName, + attachmentNameWithSuffix, + sanitizeAttachmentFileName, + WORKSPACE_ATTACHMENTS_DIR, +} from "@superset/shared/workspace-attachments"; +import { ensureWorkspaceAttachmentsDir } from "@superset/shared/workspace-attachments-dir"; +import { TRPCError } from "@trpc/server"; +import { z } from "zod"; +import { publicProcedure, router } from "../.."; + +const MAX_NAME_ATTEMPTS = 50; + +const itemSchema = z.discriminatedUnion("kind", [ + z.object({ kind: z.literal("path"), sourcePath: z.string().min(1) }), + z.object({ + kind: z.literal("base64"), + name: z.string(), + data: z.string().max(Math.ceil(MAX_ATTACHMENT_BYTES / 3) * 4), + }), +]); + +export type LocalAttachmentItem = z.infer; + +export type AttachmentSourceProblem = "missing" | "not-a-file" | "unreadable"; + +export type WriteAttachmentsResult = + | { ok: true; paths: string[] } + | { ok: false; index: number; problem: AttachmentSourceProblem }; + +function badRequest(message: string): TRPCError { + return new TRPCError({ code: "BAD_REQUEST", message }); +} + +// Windows opens an SMB connection for a UNC path, which can leak the user's NTLM hash. +function assertLocalAbsolute(path: string): void { + if (!isAbsolute(path) || /^[\\/]{2}/.test(path)) { + throw badRequest(`Not a local absolute path: ${path}`); + } +} + +function errnoOf(error: unknown): string | undefined { + return (error as NodeJS.ErrnoException | null)?.code; +} + +async function sourceProblem( + sourcePath: string, +): Promise { + try { + if (!(await stat(sourcePath)).isFile()) return "not-a-file"; + await (await open(sourcePath, "r")).close(); + return null; + } catch (error) { + const code = errnoOf(error); + if (code === "ENOENT" || code === "ENOTDIR") return "missing"; + if (code === "EACCES" || code === "EPERM") return "unreadable"; + throw error; + } +} + +async function assertWorktree(worktreePath: string): Promise { + assertLocalAbsolute(worktreePath); + if (!(await stat(worktreePath)).isDirectory()) { + throw badRequest(`Not a directory: ${worktreePath}`); + } +} + +function baseNameOf(item: LocalAttachmentItem, index: number): string { + const raw = item.kind === "path" ? basename(item.sourcePath) : item.name; + return sanitizeAttachmentFileName(raw) ?? attachmentFallbackName(index); +} + +async function writeExclusive( + item: LocalAttachmentItem, + destination: string, +): Promise { + if (item.kind === "path") { + await copyFile(item.sourcePath, destination, constants.COPYFILE_EXCL); + return; + } + await writeFile(destination, Buffer.from(item.data, "base64"), { + flag: "wx", + }); +} + +async function writeUnique( + item: LocalAttachmentItem, + directory: string, + base: string, +): Promise { + for (let attempt = 0; attempt < MAX_NAME_ATTEMPTS; attempt++) { + const fileName = attachmentNameWithSuffix(base, attempt); + try { + await writeExclusive(item, join(directory, fileName)); + return fileName; + } catch (error) { + if (errnoOf(error) !== "EEXIST") throw error; + } + } + throw new Error(`Could not find a free name for ${base}`); +} + +export async function writeAttachmentsIntoWorktree(input: { + worktreePath: string; + items: LocalAttachmentItem[]; +}): Promise { + await assertWorktree(input.worktreePath); + for (const [index, item] of input.items.entries()) { + if (item.kind !== "path") continue; + assertLocalAbsolute(item.sourcePath); + const problem = await sourceProblem(item.sourcePath); + if (problem) return { ok: false, index, problem }; + } + const directory = ensureWorkspaceAttachmentsDir(input.worktreePath); + const paths: string[] = []; + for (const [index, item] of input.items.entries()) { + const fileName = await writeUnique( + item, + directory, + baseNameOf(item, index), + ); + paths.push(`${WORKSPACE_ATTACHMENTS_DIR}/${fileName}`); + } + return { ok: true, paths }; +} + +export const createAttachmentsRouter = () => { + return router({ + writeIntoWorktree: publicProcedure + .input( + z.object({ + worktreePath: z.string().min(1), + items: z.array(itemSchema).min(1).max(MAX_ATTACHMENTS), + }), + ) + .mutation(({ input }) => writeAttachmentsIntoWorktree(input)), + }); +}; diff --git a/apps/desktop/src/lib/trpc/routers/attachments/index.ts b/apps/desktop/src/lib/trpc/routers/attachments/index.ts new file mode 100644 index 00000000000..52dfd0d5254 --- /dev/null +++ b/apps/desktop/src/lib/trpc/routers/attachments/index.ts @@ -0,0 +1 @@ +export { createAttachmentsRouter } from "./attachments"; diff --git a/apps/desktop/src/lib/trpc/routers/index.ts b/apps/desktop/src/lib/trpc/routers/index.ts index ab502c806f3..4ac730fb987 100644 --- a/apps/desktop/src/lib/trpc/routers/index.ts +++ b/apps/desktop/src/lib/trpc/routers/index.ts @@ -1,6 +1,7 @@ import type { BrowserWindow } from "electron"; import { router } from ".."; import { createAnalyticsRouter } from "./analytics"; +import { createAttachmentsRouter } from "./attachments"; import { createAuthRouter } from "./auth"; import { createAutoUpdateRouter } from "./auto-update"; import { createBrowserRouter } from "./browser/browser"; @@ -38,6 +39,7 @@ import { createWorkspacesRouter } from "./workspaces"; export const createAppRouter = (getWindow: () => BrowserWindow | null) => { return router({ analytics: createAnalyticsRouter(), + attachments: createAttachmentsRouter(), browser: createBrowserRouter(), browserHistory: createBrowserHistoryRouter(), downloads: createDownloadsRouter(), diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/components/WorkspaceSidebar/components/FilesTab/hooks/useFilesTabDrop/useFilesTabDrop.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/components/WorkspaceSidebar/components/FilesTab/hooks/useFilesTabDrop/useFilesTabDrop.ts index 354152c64f2..b5091ec6129 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/components/WorkspaceSidebar/components/FilesTab/hooks/useFilesTabDrop/useFilesTabDrop.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/components/WorkspaceSidebar/components/FilesTab/hooks/useFilesTabDrop/useFilesTabDrop.ts @@ -2,10 +2,12 @@ import { msg } from "@lingui/core/macro"; import { useLingui } from "@lingui/react/macro"; import type { FileTree } from "@pierre/trees"; import { i18n } from "@superset/i18n"; +import { MAX_INLINE_ATTACHMENT_BYTES } from "@superset/shared/attachment-limits"; import { alert } from "@superset/ui/atoms/Alert"; import { toast } from "@superset/ui/sonner"; import { workspaceTrpc } from "@superset/workspace-client"; import { useCallback, useEffect, useState } from "react"; +import { useWorkspaceHostTarget } from "renderer/hooks/host-service/useWorkspaceHostUrl"; import { fileToBase64 } from "renderer/lib/file-to-base64"; import { asDirectoryHandle, @@ -262,6 +264,10 @@ export function useFilesTabDrop({ workspaceId, }: UseFilesTabDropOptions): FilesTabDrop { const { t } = useLingui(); + const hostTarget = useWorkspaceHostTarget(workspaceId); + const onThisMachine = + hostTarget.status === "local-starting" || + (hostTarget.status === "ready" && hostTarget.kind === "local"); const writeFile = workspaceTrpc.filesystem.writeFile.useMutation(); const createDirectory = workspaceTrpc.filesystem.createDirectory.useMutation(); @@ -376,10 +382,28 @@ export function useFilesTabDrop({ // instead of dribbling them into a worktree the user has left. Files // whose names already exist are collected (not overwritten) and the // user is asked to confirm replacement below. + const isTooLarge = (file: File) => + !onThisMachine && file.size > MAX_INLINE_ATTACHMENT_BYTES; + const tooLarge = tree.files.filter(({ file }) => isTooLarge(file)); + if (tooLarge.length > 0) { + const count = tooLarge.length; + const limit = `${Math.round(MAX_INLINE_ATTACHMENT_BYTES / 1024 / 1024)}MB`; + toast.error( + tooLarge.length === 1 + ? t({ + message: `1 file is over ${limit} and was not added`, + }) + : t({ + message: `${count} files are over ${limit} and were not added`, + }), + ); + } + let added = 0; let failed = 0; const collisions: DroppedFile[] = []; for (const { relPath, file } of tree.files) { + if (isTooLarge(file)) continue; if (!bridge.isCurrent(versionToken)) break; try { if ((await writeOneFile(relPath, file, false)) === "exists") { @@ -532,7 +556,16 @@ export function useFilesTabDrop({ ], }); }, - [model, bridge, writeFile, createDirectory, rootPath, workspaceId, t], + [ + model, + bridge, + writeFile, + createDirectory, + rootPath, + workspaceId, + onThisMachine, + t, + ], ); const onDragOver = useCallback((e: React.DragEvent) => { diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/writeDesignModeAttachments.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/writeDesignModeAttachments.ts index 93b26383d43..bdb53f683d9 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/writeDesignModeAttachments.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/writeDesignModeAttachments.ts @@ -1,3 +1,6 @@ +import { msg } from "@lingui/core/macro"; +import { i18n } from "@superset/i18n"; +import { MAX_INLINE_ATTACHMENT_BYTES } from "@superset/shared/attachment-limits"; import { WORKSPACE_ATTACHMENTS_DIR, WORKSPACE_ATTACHMENTS_GITIGNORE, @@ -70,18 +73,30 @@ export async function writeDesignModeAttachments({ // Timestamp alone can collide across rapid sends; suffix for uniqueness. const baseName = `design-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`; const contextName = `${baseName}.md`; + const context = formatDesignModeContextMarkdown(payload, comment, { + workspaceId, + paneId, + }); + if (new TextEncoder().encode(context).length > MAX_INLINE_ATTACHMENT_BYTES) { + throw new Error( + i18n._( + msg({ message: "The selected element's context is too large to send" }), + ), + ); + } await client.filesystem.writeFile.mutate({ workspaceId, absolutePath: joinAbsolutePath(attachmentsDirectory, contextName), - content: formatDesignModeContextMarkdown(payload, comment, { - workspaceId, - paneId, - }), + content: context, }); let screenshotPath: string | null = null; const dataUrl = payload.screenshot?.dataUrl; - if (dataUrl?.startsWith("data:image/png;base64,")) { + const screenshotBytes = dataUrl ? (dataUrl.length * 3) / 4 : 0; + if ( + dataUrl?.startsWith("data:image/png;base64,") && + screenshotBytes <= MAX_INLINE_ATTACHMENT_BYTES + ) { const screenshotName = `${baseName}.png`; await client.filesystem.writeFile.mutate({ workspaceId, diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/Composer.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/Composer.tsx index f5467313f73..c9824967e9c 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/Composer.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/Composer.tsx @@ -511,13 +511,21 @@ export const Composer = memo(function Composer({ steer: boolean, draft: ComposerDraft, ) => { - const tags = await uploadAttachments(files); - if (!tags) { + const upload = await uploadAttachments(files); + if (!upload.ok) { + const keep = new Set(upload.keep); + const restored: ComposerDraft = { + ...draft, + attachments: draft.attachments.filter((attachment) => + keep.has(attachment.file), + ), + }; const input = promptInputRef.current; - if (input) input.restoreDraft(draft); - else prependToDraft(draftKey, [draft]); + if (input) input.restoreDraft(restored); + else prependToDraft(draftKey, [restored]); return; } + const { tags, parts } = upload; const message = text.trim(); const elements = elementsForChips(message, mentions); const mcpContext = mcpContextLine( @@ -528,18 +536,24 @@ export const Composer = memo(function Composer({ env.NEXT_PUBLIC_WEB_URL, otherHostOf, ); + const body = [message, ...tags].filter(Boolean).join("\n"); onSend( [ - { - type: "text", - text: [message, ...tags].filter(Boolean).join("\n"), - ...(elements.length > 0 ? { elements } : {}), - }, + ...(body || parts.length === 0 + ? [ + { + type: "text" as const, + text: body, + ...(elements.length > 0 ? { elements } : {}), + }, + ] + : []), ...[mcpContext, chatContext].flatMap((context) => context ? [{ type: "text" as const, text: context, hidden: true }] : [], ), + ...parts, ], { steer, draft }, ); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/hooks/useUploadAttachments/useUploadAttachments.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/hooks/useUploadAttachments/useUploadAttachments.ts index 60d8a3b05a3..e6c12cf0965 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/hooks/useUploadAttachments/useUploadAttachments.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Composer/hooks/useUploadAttachments/useUploadAttachments.ts @@ -1,51 +1,144 @@ import { useLingui } from "@lingui/react/macro"; -import { errorMessage } from "@superset/i18n/errors"; +import { errorMessage, rawErrorMessage } from "@superset/i18n/errors"; +import { hostReadsAttachmentParts } from "@superset/shared/host-version"; import { toast } from "@superset/ui/sonner"; import { workspaceTrpc } from "@superset/workspace-client"; +import { useQueryClient } from "@tanstack/react-query"; import { useCallback } from "react"; +import { useHostServiceInfo } from "renderer/hooks/host-service/useHostServiceInfo"; +import { track } from "renderer/lib/analytics"; +import { useAttachmentRoute } from "../../../../../../hooks/useAttachmentRoute"; +import { useSendAttachments } from "../../../../../../hooks/useSendAttachments"; +import { createAttachmentDeps } from "../../../../../../utils/createAttachmentDeps"; import { - PasteUploadLimitError, - uploadPastedFiles, -} from "../../../../../../utils/uploadPastedFiles"; + AttachmentLimitError, + type AttachmentPart, + AttachmentSourceError, + assertWithinLimits, + fitsInline, + sendAttachments, +} from "../../../../../../utils/sendAttachmentsToWorkspace"; +import { primeAttachmentSource } from "../../../../utils/attachmentSource"; import { formatAttachmentTag } from "../../../../utils/attachmentTags"; +export type UploadAttachmentsResult = + | { ok: true; tags: string[]; parts: AttachmentPart[] } + | { ok: false; keep: File[] }; + +/** + * Chat attachments as parts when the host's adapters read them; this + * machine's host is this build. A file on this machine too big for a part is + * copied into the worktree and goes as a path tag, so it never needs a cap. + * A remote host or box below the floor gets path tags for everything. + */ export function useUploadAttachments(workspaceId: string) { const { t } = useLingui(); - const { data: workspace } = workspaceTrpc.workspace.get.useQuery({ - id: workspaceId, - }); - const createDirectory = - workspaceTrpc.filesystem.createDirectory.useMutation(); - const writeFile = workspaceTrpc.filesystem.writeFile.useMutation(); - const worktreePath = workspace?.worktreePath; + const { route, hostUrl, worktreePath } = useAttachmentRoute(workspaceId); + const remoteInfo = useHostServiceInfo( + route === "same-machine" ? null : hostUrl, + ); + const readsParts = + route === "same-machine" || + hostReadsAttachmentParts(remoteInfo.data?.version); + const sendPaths = useSendAttachments(workspaceId); + const host = workspaceTrpc.useUtils().client; + const queryClient = useQueryClient(); return useCallback( - async (files: File[]): Promise => { - if (files.length === 0) return []; + async (files: File[]): Promise => { + if (files.length === 0) return { ok: true, tags: [], parts: [] }; + const describe = (error: unknown): string => { + if (error instanceof AttachmentLimitError) return error.message; + if (error instanceof AttachmentSourceError) { + const name = error.fileName; + switch (error.problem) { + case "missing": + return t({ + message: `"${name}" was moved or deleted. Attach it again.`, + }); + case "not-a-file": + return t({ + message: `"${name}" is a folder. Attach the files inside it instead.`, + }); + case "unreadable": + return t({ + message: `Paradev doesn't have permission to read "${name}".`, + }); + } + } + return errorMessage(error, t({ message: "Unknown error" })); + }; + const asParts = + route && readsParts + ? route === "same-machine" + ? files.filter(fitsInline) + : files + : []; + const asPaths = files.filter((file) => !asParts.includes(file)); try { - if (!worktreePath) throw new Error("Workspace is not ready"); - const paths = await uploadPastedFiles({ - deps: { - createDirectory: (input) => createDirectory.mutateAsync(input), - writeFile: (input) => writeFile.mutateAsync(input), - }, - workspaceId, - worktreePath, - files, + assertWithinLimits(files, Number.POSITIVE_INFINITY); + const parts = + route && asParts.length > 0 + ? await sendAttachments({ + deps: createAttachmentDeps({ host, route, worktreePath }), + route, + workspaceId, + files: asParts, + onSent: (part, file) => + void primeAttachmentSource(queryClient, part, file), + }) + : []; + const paths = await sendPaths(asPaths); + track("attachments_sent", { + surface: "chat", + route, + parts: parts.length, + paths: paths.length, }); - return paths.map((path, index) => - formatAttachmentTag({ path, type: files[index]?.type ?? "" }), - ); + return { + ok: true, + parts, + tags: paths.map((path, index) => + formatAttachmentTag({ + path, + type: asPaths[index]?.type ?? "", + name: asPaths[index]?.name, + }), + ), + }; } catch (error) { + if ( + !(error instanceof AttachmentLimitError) && + !(error instanceof AttachmentSourceError) + ) { + track("attachments_send_failed", { + surface: "chat", + route, + error: rawErrorMessage(error), + }); + } toast.error(t({ message: "Couldn't attach files" }), { - description: - error instanceof PasteUploadLimitError - ? error.message - : errorMessage(error, t({ message: "Unknown error" })), + description: describe(error), }); - return null; + const bad = + error instanceof AttachmentSourceError + ? asPaths[error.index] + : undefined; + return { + ok: false, + keep: bad ? files.filter((file) => file !== bad) : files, + }; } }, - [worktreePath, workspaceId, createDirectory, writeFile, t], + [ + host, + queryClient, + readsParts, + route, + sendPaths, + t, + workspaceId, + worktreePath, + ], ); } diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.test.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.test.tsx index de68d151bfa..25cc6208f60 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.test.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.test.tsx @@ -119,7 +119,7 @@ describe("AttachmentImage", () => { throw new Error("no workspace"); }, ); - await waitFor(() => view.getByText("big.png")); + await waitFor(() => view.getByTitle("big.png")); expect(view.queryByRole("button", tile)).toBeNull(); }); @@ -128,7 +128,7 @@ describe("AttachmentImage", () => { () => read(false), () => ({ worktreePath: null }), ); - await waitFor(() => view.getByText("big.png")); + await waitFor(() => view.getByTitle("big.png")); }); test("a failed read of a file over the cap says so in the overlay", async () => { diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.tsx index 281234f1893..d5953bd2b77 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/AttachmentImage/AttachmentImage.tsx @@ -1,4 +1,4 @@ -import { Badge } from "@superset/ui/badge"; +import { AttachmentFileCard } from "@superset/chat-ui/AttachmentFileCard"; import { useCallback, useState } from "react"; import { useChatImageSource } from "../../hooks/useChatImageSource"; import { useChatImageGallery } from "../../providers/ChatImageGalleryProvider"; @@ -8,6 +8,7 @@ import { PreviewableImage } from "./components/PreviewableImage"; export function AttachmentImage({ alt, + name: attachedName, owner, path, type, @@ -17,10 +18,11 @@ export function AttachmentImage({ path: string; type: string; alt?: string | undefined; + name?: string | undefined; }) { const { open, registerThumbnail } = useChatImageGallery(); const id = galleryImageId(owner, path); - const name = path.split("/").pop() ?? path; + const name = attachedName || (path.split("/").pop() ?? path); const source = useChatImageSource({ path, mimeType: type }, { full: false }); const [unrenderable, setUnrenderable] = useState(false); const register = useCallback( @@ -33,7 +35,7 @@ export function AttachmentImage({ const openPreview = () => open(id); if (source.status === "error" || unrenderable) - return {name}; + return ; if (source.status === "loading") return (
diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/UserMessageRow.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/UserMessageRow.tsx index 83108ca48e3..5891162b676 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/UserMessageRow.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/UserMessageRow.tsx @@ -5,6 +5,7 @@ import { userMessageText, } from "@superset/chat/core"; import type { AvailableCommand, UserMessage } from "@superset/chat/protocol"; +import { AttachmentFileCard } from "@superset/chat-ui/AttachmentFileCard"; import { Message, MessageContent } from "@superset/ui/ai-elements/message"; import { Badge } from "@superset/ui/badge"; import { Button } from "@superset/ui/button"; @@ -13,7 +14,10 @@ import { cn } from "@superset/ui/utils"; import { Pencil } from "lucide-react"; import { useRef, useState } from "react"; import { useChatPaneActions } from "../../../../providers/ChatPaneActionsProvider"; -import { parseAttachmentTags } from "../../../../utils/attachmentTags"; +import { + attachmentDisplayName, + parseAttachmentTags, +} from "../../../../utils/attachmentTags"; import { type MessageSegment, splitByElements, @@ -21,6 +25,7 @@ import { import { CopyButton } from "../../../CopyButton"; import { AttachmentImage } from "../AttachmentImage"; import { MessageTime } from "../MessageTime"; +import { AttachmentPartImage } from "./components/AttachmentPartImage"; import { PastedTextBlock } from "./components/PastedTextBlock"; import { UserMessageEditor } from "./components/UserMessageEditor"; import { UserMessageText } from "./components/UserMessageText"; @@ -73,18 +78,27 @@ export function UserMessageRow({ const images = attachments.filter((attachment) => attachment.type.startsWith("image/"), ); + const parts = item.content.flatMap((content) => + content.type === "attachment" ? [content] : [], + ); + const partKey = (part: (typeof parts)[number], index: number) => + part.fileId ?? part.attachmentId ?? `${part.name}-${index}`; + const imageParts = parts.filter((part) => part.mimeType.startsWith("image/")); const files = [ ...attachments .filter((attachment) => !attachment.type.startsWith("image/")) .map((attachment) => ({ key: attachment.path, - name: attachment.path.split("/").pop() ?? attachment.path, + name: attachmentDisplayName(attachment), + mediaType: attachment.type, + })), + ...parts + .filter((part) => !part.mimeType.startsWith("image/")) + .map((part, index) => ({ + key: partKey(part, index), + name: part.name, + mediaType: part.mimeType, })), - ...item.content.flatMap((content) => - content.type === "attachment" - ? [{ key: content.attachmentId, name: content.name }] - : [], - ), ]; const copyable = (text.length > 0 || pastedTexts.length > 0) && !pending; const copyText = [text, ...pastedTexts].filter(Boolean).join("\n\n"); @@ -94,7 +108,8 @@ export function UserMessageRow({ editableMessageIds?.has(item.id) === true && attachments.length === 0 && pastedTexts.length === 0 && - files.length === 0; + files.length === 0 && + imageParts.length === 0; if (editing && editable) { return ( @@ -119,7 +134,7 @@ export function UserMessageRow({ {sender} )} - {images.length > 0 && ( + {(images.length > 0 || imageParts.length > 0) && (
))} + {imageParts.map((part, index) => ( + + ))} +
+ )} + {files.length > 0 && ( +
+ {files.map((file) => ( + + ))}
)} {pastedTexts.length > 0 && ( @@ -149,11 +185,11 @@ export function UserMessageRow({ ))}
)} - {(text || files.length > 0) && ( + {text && ( - {files.length > 0 && ( -
- {files.map((file) => ( - - {file.name} - - ))} -
- )}
)} {copyable && ( diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/components/AttachmentPartImage/AttachmentPartImage.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/components/AttachmentPartImage/AttachmentPartImage.tsx new file mode 100644 index 00000000000..ae85a9432e4 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/components/AttachmentPartImage/AttachmentPartImage.tsx @@ -0,0 +1,32 @@ +import { AttachmentFileCard } from "@superset/chat-ui/AttachmentFileCard"; +import { useState } from "react"; +import type { AttachmentPart } from "../../../../../../../../utils/sendAttachmentsToWorkspace"; +import { useAttachmentSource } from "../../../../hooks/useAttachmentSource"; + +export function AttachmentPartImage({ part }: { part: AttachmentPart }) { + const { src, isLoading } = useAttachmentSource(part); + const [unrenderable, setUnrenderable] = useState(false); + if (isLoading) + return ( +
+ ); + if (!src || unrenderable) + return ( + + ); + return ( +
+ {part.name} setUnrenderable(true)} + src={src} + /> +
+ ); +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/components/AttachmentPartImage/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/components/AttachmentPartImage/index.ts new file mode 100644 index 00000000000..c3c2f6914ee --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/UserMessageRow/components/AttachmentPartImage/index.ts @@ -0,0 +1 @@ +export { AttachmentPartImage } from "./AttachmentPartImage"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useAttachmentSource/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useAttachmentSource/index.ts new file mode 100644 index 00000000000..c0b86cd6611 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useAttachmentSource/index.ts @@ -0,0 +1 @@ +export { useAttachmentSource } from "./useAttachmentSource"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useAttachmentSource/useAttachmentSource.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useAttachmentSource/useAttachmentSource.ts new file mode 100644 index 00000000000..63e353e86bf --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useAttachmentSource/useAttachmentSource.ts @@ -0,0 +1,47 @@ +import { workspaceTrpc } from "@superset/workspace-client"; +import { useQuery } from "@tanstack/react-query"; +import { apiTrpcClient } from "renderer/lib/api-trpc-client"; +import type { AttachmentPart } from "../../../../../../utils/sendAttachmentsToWorkspace"; +import { + attachmentSourceKey, + createCloudUrlResolver, + isThumbnailable, + readAttachmentSource, +} from "../../../../utils/attachmentSource"; + +const resolveCloudUrl = createCloudUrlResolver((fileIds) => + apiTrpcClient.attachment.resolveEach.mutate({ fileIds }), +); + +const HOUR_MS = 60 * 60 * 1000; + +/** A data URL for an attachment part's thumbnail, or null for a name badge. */ +export function useAttachmentSource(part: AttachmentPart): { + src: string | null; + isLoading: boolean; +} { + const host = workspaceTrpc.useUtils().client; + const showable = + isThumbnailable(part) && Boolean(part.fileId || part.attachmentId); + const query = useQuery({ + queryKey: attachmentSourceKey(part), + enabled: showable, + staleTime: Number.POSITIVE_INFINITY, + gcTime: HOUR_MS, + retry: 1, + queryFn: () => + readAttachmentSource(part, { + cloudUrl: resolveCloudUrl, + fetchBlob: async (url) => { + const response = await fetch(url); + return response.ok ? response.blob() : null; + }, + hostRead: (attachmentId) => + host.attachments.read.query({ attachmentId }), + }), + }); + return { + src: showable ? (query.data ?? null) : null, + isLoading: showable && query.isPending, + }; +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useChatImageSource/useChatImageSource.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useChatImageSource/useChatImageSource.ts index a3e3a4bb4b2..bee05692299 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useChatImageSource/useChatImageSource.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/hooks/useChatImageSource/useChatImageSource.ts @@ -1,9 +1,10 @@ -import { MAX_CHAT_IMAGE_BYTES } from "@superset/shared/attachment-limits"; +import { + MAX_CHAT_IMAGE_BYTES, + MAX_THUMBNAIL_BYTES, +} from "@superset/shared/attachment-limits"; import { workspaceTrpc } from "@superset/workspace-client"; import { useChatPaneActions } from "../../../../providers/ChatPaneActionsProvider"; -export const MAX_THUMBNAIL_BYTES = 5 * 1024 * 1024; - const READ_OPTIONS = { staleTime: Number.POSITIVE_INFINITY, retry: false, @@ -20,6 +21,8 @@ export type ChatImageSource = * capped; `full` follows it with the larger read for a file over the cap, so * a thumbnail and the overlay showing the same file share one cached read. */ +export { MAX_THUMBNAIL_BYTES }; + export function useChatImageSource( image: { path: string; mimeType: string } | null, { full }: { full: boolean }, diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/utils/galleryImages/galleryImages.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/utils/galleryImages/galleryImages.ts index 769339ac78e..4dc4bc60749 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/utils/galleryImages/galleryImages.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/utils/galleryImages/galleryImages.ts @@ -7,7 +7,10 @@ import type { UserMessage, } from "@superset/chat/protocol"; import { isImageAttachment } from "@superset/chat/protocol"; -import { parseAttachmentTags } from "../../../../utils/attachmentTags"; +import { + attachmentDisplayName, + parseAttachmentTags, +} from "../../../../utils/attachmentTags"; import type { TranscriptRow } from "../transcriptRows"; export type GalleryImage = { @@ -19,7 +22,12 @@ export type GalleryImage = { alt?: string | undefined; }; -type ItemImage = { path: string; mimeType: string; alt?: string | undefined }; +type ItemImage = { + path: string; + mimeType: string; + alt?: string | undefined; + name?: string | undefined; +}; /** `owner` is the transcript key of the item that shows the image. */ export function galleryImageId(owner: string, path: string): string { @@ -32,6 +40,7 @@ function userImages(content: readonly UserContent[]): ItemImage[] { .map((attachment) => ({ path: attachment.path, mimeType: attachment.type, + name: attachmentDisplayName(attachment), })); } @@ -92,7 +101,7 @@ export function galleryImages(rows: readonly TranscriptRow[]): GalleryImage[] { id: galleryImageId(owner, image.path), path: image.path, mimeType: image.mimeType, - filename: image.path.split("/").pop() ?? image.path, + filename: image.name ?? image.path.split("/").pop() ?? image.path, alt: image.alt, }); } diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/WorkDrawer/components/QueuedPromptRow/QueuedPromptRow.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/WorkDrawer/components/QueuedPromptRow/QueuedPromptRow.tsx index 7e74e556e27..199482a0bfb 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/WorkDrawer/components/QueuedPromptRow/QueuedPromptRow.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/WorkDrawer/components/QueuedPromptRow/QueuedPromptRow.tsx @@ -21,7 +21,10 @@ import { ListEnd, Trash2, } from "lucide-react"; -import { parseAttachmentTags } from "../../../../utils/attachmentTags"; +import { + attachmentDisplayName, + parseAttachmentTags, +} from "../../../../utils/attachmentTags"; export function QueuedPromptRow({ rowKey, @@ -49,9 +52,7 @@ export function QueuedPromptRow({ userMessageText(prompt), ); const attachmentNames = [ - ...attachments.map( - (attachment) => attachment.path.split("/").pop() ?? attachment.path, - ), + ...attachments.map(attachmentDisplayName), ...prompt.content.flatMap((content) => content.type === "attachment" ? [content.name] : [], ), diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/attachmentSource.test.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/attachmentSource.test.ts new file mode 100644 index 00000000000..9bf3c5b5f04 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/attachmentSource.test.ts @@ -0,0 +1,97 @@ +import { describe, expect, it } from "bun:test"; +import { QueryClient } from "@tanstack/react-query"; +import { + attachmentSourceKey, + createCloudUrlResolver, + primeAttachmentSource, + readAttachmentSource, +} from "./attachmentSource"; + +const FILE_ID = "8c1f6f8e-3a2b-4c5d-9e0f-112233445566"; + +const part = (ids: { fileId?: string; attachmentId?: string }) => ({ + type: "attachment" as const, + ...ids, + name: "shot.png", + mimeType: "image/png", + sizeBytes: 3, +}); + +const unexpected = async (): Promise => { + throw new Error("unexpected read"); +}; + +describe("readAttachmentSource", () => { + it("reads a cloud part from storage, never the host", async () => { + const asked: string[] = []; + const src = await readAttachmentSource(part({ fileId: FILE_ID }), { + cloudUrl: async (fileId) => { + asked.push(fileId); + return "https://r2.test/shot"; + }, + fetchBlob: async () => new Blob([new Uint8Array([1, 2, 3])]), + hostRead: unexpected, + }); + expect(asked).toEqual([FILE_ID]); + expect(src).toStartWith("data:"); + }); + + it("reads a host part from the host, never storage", async () => { + expect( + await readAttachmentSource(part({ attachmentId: "a1" }), { + cloudUrl: unexpected, + fetchBlob: unexpected, + hostRead: async () => ({ mediaType: "image/png", data: "AQID" }), + }), + ).toBe("data:image/png;base64,AQID"); + }); + + it("gives a badge for a cloud part storage no longer has", async () => { + expect( + await readAttachmentSource(part({ fileId: FILE_ID }), { + cloudUrl: async () => null, + fetchBlob: unexpected, + hostRead: unexpected, + }), + ).toBeNull(); + }); +}); + +describe("primeAttachmentSource", () => { + it("lets the sent row render the file it attached without any read", async () => { + const queryClient = new QueryClient(); + const sent = part({ fileId: FILE_ID }); + await primeAttachmentSource( + queryClient, + sent, + new File([new Uint8Array([1, 2, 3])], "shot.png", { type: "image/png" }), + ); + const src = await queryClient.fetchQuery({ + queryKey: attachmentSourceKey(sent), + queryFn: unexpected, + staleTime: Number.POSITIVE_INFINITY, + }); + expect(src).toStartWith("data:image/png;base64,"); + }); +}); + +describe("createCloudUrlResolver", () => { + it("resolves the thumbnails asked for together in one call", async () => { + const calls: string[][] = []; + const resolve = createCloudUrlResolver(async (fileIds) => { + calls.push(fileIds); + return fileIds.map((fileId) => + fileId === "gone" + ? { fileId, missing: true as const } + : { fileId, url: `https://r2.test/${fileId}` }, + ); + }); + const urls = await Promise.all([ + resolve("a"), + resolve("b"), + resolve("gone"), + ]); + expect(calls).toEqual([["a", "b", "gone"]]); + expect(urls).toEqual(["https://r2.test/a", "https://r2.test/b", null]); + }); +}); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/attachmentSource.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/attachmentSource.ts new file mode 100644 index 00000000000..bf6242821df --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/attachmentSource.ts @@ -0,0 +1,109 @@ +import { + MAX_ATTACHMENTS, + MAX_THUMBNAIL_BYTES, +} from "@superset/shared/attachment-limits"; +import type { QueryClient } from "@tanstack/react-query"; +import type { AttachmentPart } from "../../../../utils/sendAttachmentsToWorkspace"; + +/** A part names its bytes by one identity; `fileId` wins, like every reader. */ +export function attachmentSourceKey(part: AttachmentPart) { + return part.fileId + ? (["attachment", "cloud", part.fileId] as const) + : (["attachment", "host", part.attachmentId ?? ""] as const); +} + +export function isThumbnailable(part: AttachmentPart): boolean { + return ( + part.mimeType.startsWith("image/") && + (part.sizeBytes ?? 0) <= MAX_THUMBNAIL_BYTES + ); +} + +export function blobToDataUrl(blob: Blob): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => + typeof reader.result === "string" + ? resolve(reader.result) + : reject(new Error("Unexpected file reader result")); + reader.onerror = () => + reject(reader.error ?? new Error("Failed to read file")); + reader.readAsDataURL(blob); + }); +} + +/** The row for a message just sent shows the file attached, not a read back. */ +export async function primeAttachmentSource( + queryClient: QueryClient, + part: AttachmentPart, + file: File, +): Promise { + if (!isThumbnailable(part)) return; + queryClient.setQueryData( + attachmentSourceKey(part), + await blobToDataUrl(file), + ); +} + +type ResolveEach = ( + fileIds: string[], +) => Promise< + Array<{ fileId: string; url: string } | { fileId: string; missing: true }> +>; + +/** + * Coalesces the reads a transcript makes as it renders, so its visible + * thumbnails resolve in a few calls rather than one each. + */ +export function createCloudUrlResolver(resolveEach: ResolveEach) { + let pending = new Map void>>(); + + const flush = async () => { + const batch = pending; + pending = new Map(); + const ids = [...batch.keys()]; + for (let start = 0; start < ids.length; start += MAX_ATTACHMENTS) { + const chunk = ids.slice(start, start + MAX_ATTACHMENTS); + const answers = await resolveEach(chunk).catch(() => []); + const urls = new Map( + answers.flatMap((answer) => + "url" in answer ? [[answer.fileId, answer.url] as const] : [], + ), + ); + for (const fileId of chunk) { + for (const settle of batch.get(fileId) ?? []) + settle(urls.get(fileId) ?? null); + } + } + }; + + return (fileId: string): Promise => + new Promise((resolve) => { + if (pending.size === 0) queueMicrotask(() => void flush()); + pending.set(fileId, [...(pending.get(fileId) ?? []), resolve]); + }); +} + +/** + * Where a part's bytes come from: storage for a cloud part, so no box is + * needed; the host for a host part, the only place they exist. + */ +export async function readAttachmentSource( + part: AttachmentPart, + readers: { + cloudUrl: (fileId: string) => Promise; + fetchBlob: (url: string) => Promise; + hostRead: ( + attachmentId: string, + ) => Promise<{ mediaType: string; data: string }>; + }, +): Promise { + if (part.fileId) { + const url = await readers.cloudUrl(part.fileId); + const blob = url ? await readers.fetchBlob(url) : null; + return blob ? blobToDataUrl(blob) : null; + } + if (!part.attachmentId) return null; + const read = await readers.hostRead(part.attachmentId); + return `data:${read.mediaType};base64,${read.data}`; +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/index.ts new file mode 100644 index 00000000000..b83bfc02488 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentSource/index.ts @@ -0,0 +1,8 @@ +export { + attachmentSourceKey, + blobToDataUrl, + createCloudUrlResolver, + isThumbnailable, + primeAttachmentSource, + readAttachmentSource, +} from "./attachmentSource"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/attachmentTags.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/attachmentTags.ts deleted file mode 100644 index da97f524658..00000000000 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/attachmentTags.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { parsePastedText } from "@superset/chat/core"; -import { - LEGACY_WORKSPACE_ATTACHMENTS_DIR, - WORKSPACE_ATTACHMENTS_DIR, -} from "@superset/shared/workspace-attachments"; - -export type AttachmentTag = { path: string; type: string }; - -const TAG = //g; -const SAFE_TYPE = /^[\w.+-]+\/[\w.+-]+$/; -const SAFE_NAME = /^[A-Za-z0-9._-]+$/; - -function isWorkspaceAttachmentPath(path: string): boolean { - const prefix = [WORKSPACE_ATTACHMENTS_DIR, LEGACY_WORKSPACE_ATTACHMENTS_DIR] - .map((dir) => `${dir}/`) - .find((dir) => path.startsWith(dir)); - if (!prefix) return false; - const name = path.slice(prefix.length); - return SAFE_NAME.test(name) && name !== "." && name !== ".."; -} - -export function formatAttachmentTag({ path, type }: AttachmentTag): string { - return SAFE_TYPE.test(type) - ? `` - : ``; -} - -export function parseAttachmentTags(message: string): { - text: string; - attachments: AttachmentTag[]; - pastedTexts: string[]; -} { - const { text, pastes } = parsePastedText(message); - const attachments: AttachmentTag[] = []; - const rest = text.replace( - TAG, - (match: string, path: string, type?: string) => { - if (!isWorkspaceAttachmentPath(path)) return match; - attachments.push({ path, type: type ?? "" }); - return ""; - }, - ); - return { text: rest.trim(), attachments, pastedTexts: pastes }; -} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/index.ts index 5318c550353..313695879ff 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/index.ts +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/index.ts @@ -1,5 +1,6 @@ export { type AttachmentTag, + attachmentDisplayName, formatAttachmentTag, parseAttachmentTags, -} from "./attachmentTags"; +} from "@superset/chat/core"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx index dd6cf265743..ad18fa9ce79 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/TerminalPane.tsx @@ -47,6 +47,7 @@ import { useTheme } from "renderer/stores/theme"; import { resolveTerminalThemeType } from "renderer/stores/theme/utils"; import { isWithinWorkspacePath } from "shared/absolute-paths"; import { useLinkClickHint } from "../../hooks/useLinkClickHint"; +import { useSendAttachments } from "../../hooks/useSendAttachments"; import { runFileLinkAction, runFolderLinkAction, @@ -54,10 +55,7 @@ import { type TerminalLinkActionDeps, terminalPullRequestLinkAction, } from "../../utils/runTerminalLinkAction"; -import { - PasteUploadLimitError, - uploadPastedFiles, -} from "../../utils/uploadPastedFiles"; +import { AttachmentLimitError } from "../../utils/sendAttachmentsToWorkspace"; import { LinkActionMenu } from "./components/LinkActionMenu"; import { TerminalAgentAutoResume } from "./components/TerminalAgentAutoResume"; import { TerminalCopiedIndicator } from "./components/TerminalCopiedIndicator"; @@ -418,9 +416,9 @@ export function TerminalPane({ // The default paste path forwards Ctrl+V and lets the TUI read the OS // clipboard — which only exists on the machine the PTY runs on. When the // workspace lives on another host (relay-reached machine, cloud sandbox), - // ship the clipboard bytes there via filesystem.writeFile and paste the - // resulting paths instead. Local workspaces keep the Ctrl+V forward, which - // lets TUIs attach the image natively. + // send the clipboard files to the workspace and paste the resulting paths + // instead. Local workspaces keep the Ctrl+V forward, which lets TUIs + // attach the image natively. const { machineId } = useLocalHostService(); const hostWorkspaces = useHostWorkspaces(); const workspaceHostId = hostWorkspaces.workspaces.find( @@ -434,28 +432,14 @@ export function TerminalPane({ Boolean(machineId) && workspaceHostId !== machineId; - const writeFileMutation = workspaceTrpc.filesystem.writeFile.useMutation(); - const createDirectoryMutation = - workspaceTrpc.filesystem.createDirectory.useMutation(); - const writeFileRef = useRef(writeFileMutation.mutateAsync); - writeFileRef.current = writeFileMutation.mutateAsync; - const createDirectoryRef = useRef(createDirectoryMutation.mutateAsync); - createDirectoryRef.current = createDirectoryMutation.mutateAsync; + const sendAttachments = useSendAttachments(workspaceId); // Fire-and-forget: ship files to the workspace, then paste the paths. const uploadAndPasteFiles = useCallback( - (files: File[], worktree: string) => { + (files: File[]) => { void (async () => { try { - const paths = await uploadPastedFiles({ - deps: { - createDirectory: (input) => createDirectoryRef.current(input), - writeFile: (input) => writeFileRef.current(input), - }, - workspaceId, - worktreePath: worktree, - files, - }); + const paths = await sendAttachments(files); terminalRuntimeRegistry.paste( terminalId, shellEscapePaths(paths), @@ -464,7 +448,7 @@ export function TerminalPane({ } catch (error) { console.error("[v2 Terminal] remote file upload failed", error); toast.error( - error instanceof PasteUploadLimitError + error instanceof AttachmentLimitError ? error.message : files.length === 1 ? t({ @@ -477,15 +461,15 @@ export function TerminalPane({ } })(); }, - [terminalId, terminalInstanceId, workspaceId, t], + [terminalId, terminalInstanceId, sendAttachments, t], ); useEffect(() => { - if (!isRemoteHost || !worktreePath) return; + if (!isRemoteHost) return; terminalRuntimeRegistry.setImagePasteOverride( terminalId, - (files) => uploadAndPasteFiles(files, worktreePath), + uploadAndPasteFiles, terminalInstanceId, ); return () => { @@ -495,13 +479,7 @@ export function TerminalPane({ terminalInstanceId, ); }; - }, [ - terminalId, - terminalInstanceId, - worktreePath, - isRemoteHost, - uploadAndPasteFiles, - ]); + }, [terminalId, terminalInstanceId, isRemoteHost, uploadAndPasteFiles]); useTerminalInterruptClear({ terminalId, @@ -605,7 +583,7 @@ export function TerminalPane({ // remote workspace's PTY runs on. When every dropped entry is a plain // file, ship the bytes instead. Folders keep the path flow (their File // entries carry no content), which at least preserves today's behavior. - if (isRemoteHost && worktreePath) { + if (isRemoteHost) { const items = Array.from(event.dataTransfer.items); const allPlainFiles = items.length > 0 && @@ -620,7 +598,7 @@ export function TerminalPane({ terminalRuntimeRegistry .getTerminal(terminalId, terminalInstanceId) ?.focus(); - uploadAndPasteFiles(files, worktreePath); + uploadAndPasteFiles(files); return; } } diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/components/TerminalRichInput/TerminalRichInput.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/components/TerminalRichInput/TerminalRichInput.tsx index b684e2b92cd..e65db0b37e6 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/components/TerminalRichInput/TerminalRichInput.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/TerminalPane/components/TerminalRichInput/TerminalRichInput.tsx @@ -20,10 +20,8 @@ import { usePluginMentionOptions } from "renderer/hooks/usePluginMentionOptions" import { useHotkeyDisplay } from "renderer/hotkeys"; import { track } from "renderer/lib/analytics"; import { terminalRuntimeRegistry } from "renderer/lib/terminal/terminal-runtime-registry"; -import { - PasteUploadLimitError, - uploadPastedFiles, -} from "../../../../utils/uploadPastedFiles"; +import { useSendAttachments } from "../../../../hooks/useSendAttachments"; +import { AttachmentLimitError } from "../../../../utils/sendAttachmentsToWorkspace"; import { TerminalPaneIcon } from "../TerminalPaneIcon"; import { TiptapPromptEditor } from "./components/TiptapPromptEditor"; import { prepareTerminalSubmission } from "./prepareTerminalSubmission"; @@ -125,13 +123,7 @@ function TerminalRichInputInner({ [trpcUtils, workspaceId], ); - const writeFileMutation = workspaceTrpc.filesystem.writeFile.useMutation(); - const createDirectoryMutation = - workspaceTrpc.filesystem.createDirectory.useMutation(); - const writeFileRef = useRef(writeFileMutation.mutateAsync); - writeFileRef.current = writeFileMutation.mutateAsync; - const createDirectoryRef = useRef(createDirectoryMutation.mutateAsync); - createDirectoryRef.current = createDirectoryMutation.mutateAsync; + const sendAttachments = useSendAttachments(workspaceId); const handleSubmit = useCallback( async (message: PromptInputMessage) => { @@ -141,27 +133,15 @@ function TerminalRichInputInner({ // async onSubmit), so the user does not lose the draft or the files. let attachmentPaths: string[] = []; if (message.files.length > 0) { - if (!cwd) { - toast.error(t({ message: "Workspace path is not available yet" })); - throw new Error("no worktree path"); - } try { - attachmentPaths = await uploadPastedFiles({ - deps: { - createDirectory: (input) => createDirectoryRef.current(input), - writeFile: (input) => writeFileRef.current(input), - }, - workspaceId, - worktreePath: cwd, - files: await toFiles(message.files), - }); + attachmentPaths = await sendAttachments(await toFiles(message.files)); } catch (error) { console.error( "[v2 TerminalRichInput] attachment upload failed", error, ); toast.error( - error instanceof PasteUploadLimitError + error instanceof AttachmentLimitError ? error.message : message.files.length === 1 ? "Failed to attach the file" @@ -193,8 +173,7 @@ function TerminalRichInputInner({ terminalInstanceId, controller, workspaceId, - cwd, - t, + sendAttachments, sendToTerminalAgent, ], ); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useAttachmentRoute/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useAttachmentRoute/index.ts new file mode 100644 index 00000000000..e0b0b652cd2 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useAttachmentRoute/index.ts @@ -0,0 +1 @@ +export { useAttachmentRoute } from "./useAttachmentRoute"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useAttachmentRoute/useAttachmentRoute.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useAttachmentRoute/useAttachmentRoute.ts new file mode 100644 index 00000000000..e6696e9a9d4 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useAttachmentRoute/useAttachmentRoute.ts @@ -0,0 +1,34 @@ +import { workspaceTrpc } from "@superset/workspace-client"; +import { useWorkspaceHostTarget } from "renderer/hooks/host-service/useWorkspaceHostUrl"; +import type { AttachmentRoute } from "../../utils/sendAttachmentsToWorkspace"; + +/** + * Where this workspace's attachments go. Null until the host is known: an + * unresolved target must not fall through to storage, since it may be this + * machine. + */ +export function useAttachmentRoute(workspaceId: string): { + route: AttachmentRoute | null; + hostUrl: string | null; + worktreePath: string | undefined; +} { + const target = useWorkspaceHostTarget(workspaceId); + const { data: workspace } = workspaceTrpc.workspace.get.useQuery({ + id: workspaceId, + }); + const worktreePath = workspace?.worktreePath; + if (target.status === "local-starting") + return { route: "same-machine", hostUrl: null, worktreePath }; + if (target.status !== "ready") + return { route: null, hostUrl: null, worktreePath }; + return { + route: + target.kind === "local" + ? "same-machine" + : target.kind === "sandbox" + ? "cloud" + : "remote", + hostUrl: target.url, + worktreePath, + }; +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useSendAttachments/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useSendAttachments/index.ts new file mode 100644 index 00000000000..f52d0716aa7 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useSendAttachments/index.ts @@ -0,0 +1 @@ +export { useSendAttachments } from "./useSendAttachments"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useSendAttachments/useSendAttachments.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useSendAttachments/useSendAttachments.ts new file mode 100644 index 00000000000..e074539da01 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/hooks/useSendAttachments/useSendAttachments.ts @@ -0,0 +1,39 @@ +import { workspaceTrpc } from "@superset/workspace-client"; +import { useCallback, useRef } from "react"; +import { createAttachmentDeps } from "../../utils/createAttachmentDeps"; +import { sendAttachmentsToWorkspace } from "../../utils/sendAttachmentsToWorkspace"; +import { useAttachmentRoute } from "../useAttachmentRoute"; + +/** + * A stable function that gets files into the workspace's worktree and + * returns their worktree-relative paths. Stable so a terminal's paste + * override, registered once, always sees the current host target. + */ +export function useSendAttachments( + workspaceId: string, +): (files: File[]) => Promise { + const attachmentRoute = useAttachmentRoute(workspaceId); + const routeRef = useRef(attachmentRoute); + routeRef.current = attachmentRoute; + const host = workspaceTrpc.useUtils().client; + const hostRef = useRef(host); + hostRef.current = host; + + return useCallback( + async (files: File[]) => { + const { route, worktreePath } = routeRef.current; + if (!route) throw new Error("Workspace is not ready"); + return sendAttachmentsToWorkspace({ + deps: createAttachmentDeps({ + host: hostRef.current, + route, + worktreePath, + }), + route, + workspaceId, + files, + }); + }, + [workspaceId], + ); +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/createAttachmentDeps/createAttachmentDeps.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/createAttachmentDeps/createAttachmentDeps.ts new file mode 100644 index 00000000000..307f8f701b1 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/createAttachmentDeps/createAttachmentDeps.ts @@ -0,0 +1,53 @@ +import type { workspaceTrpc } from "@superset/workspace-client"; +import { apiTrpcClient } from "renderer/lib/api-trpc-client"; +import { fileToBase64 } from "renderer/lib/file-to-base64"; +import { electronTrpcClient } from "renderer/lib/trpc-client"; +import type { + AttachmentRoute, + SendAttachmentsDeps, +} from "../sendAttachmentsToWorkspace"; + +type HostClient = ReturnType["client"]; + +export function createAttachmentDeps({ + host, + route, + worktreePath, +}: { + host: HostClient; + route: AttachmentRoute; + worktreePath: string | undefined; +}): SendAttachmentsDeps { + return { + createUpload: (input) => + apiTrpcClient.attachment.createUpload.mutate(input), + putObject: (target, file) => + fetch(target.url, { method: "PUT", headers: target.headers, body: file }), + attachFiles: (input) => + apiTrpcClient.cloudWorkspace.attachFiles.mutate(input), + materialize: (input) => + host.attachments.materializeIntoWorkspace.mutate(input), + hostUpload: (input) => host.attachments.upload.mutate(input), + worktreePath: async (workspaceId) => { + const workspace = await host.workspace.get.query({ id: workspaceId }); + if (!workspace?.worktreePath) throw new Error("Workspace path not found"); + return workspace.worktreePath; + }, + createDirectory: (input) => host.filesystem.createDirectory.mutate(input), + writeFile: (input) => host.filesystem.writeFile.mutate(input), + sameMachine: + route === "same-machine" + ? { + pathOf: (file) => window.webUtils.getPathForFile(file), + readBase64: fileToBase64, + write: (items) => { + if (!worktreePath) throw new Error("Workspace is not ready"); + return electronTrpcClient.attachments.writeIntoWorktree.mutate({ + worktreePath, + items, + }); + }, + } + : undefined, + }; +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/createAttachmentDeps/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/createAttachmentDeps/index.ts new file mode 100644 index 00000000000..423c4f94af7 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/createAttachmentDeps/index.ts @@ -0,0 +1 @@ +export { createAttachmentDeps } from "./createAttachmentDeps"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/index.ts new file mode 100644 index 00000000000..4c576eaf580 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/index.ts @@ -0,0 +1,11 @@ +export { + AttachmentLimitError, + type AttachmentPart, + type AttachmentRoute, + AttachmentSourceError, + assertWithinLimits, + fitsInline, + type SendAttachmentsDeps, + sendAttachments, + sendAttachmentsToWorkspace, +} from "./sendAttachmentsToWorkspace"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/sendAttachmentsToWorkspace.test.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/sendAttachmentsToWorkspace.test.ts new file mode 100644 index 00000000000..760839b6873 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/sendAttachmentsToWorkspace.test.ts @@ -0,0 +1,426 @@ +import { describe, expect, it } from "bun:test"; +import { + MAX_ATTACHMENT_BYTES, + MAX_ATTACHMENTS, + MAX_INLINE_ATTACHMENT_BYTES, +} from "@superset/shared/attachment-limits"; +import { + WORKSPACE_ATTACHMENTS_DIR, + WORKSPACE_ATTACHMENTS_GITIGNORE, +} from "@superset/shared/workspace-attachments"; +import { + AttachmentLimitError, + type AttachmentPart, + AttachmentSourceError, + type LocalAttachmentItem, + type SendAttachmentsDeps, + sendAttachments, + sendAttachmentsToWorkspace, +} from "./sendAttachmentsToWorkspace"; + +interface Recorded { + uploads: Array<{ name: string; contentType: string; sizeBytes: number }>; + puts: Array<{ url: string; file: File }>; + attached: Array<{ id: string; fileIds: string[] }>; + materialized: Array<{ workspaceId: string; fileIds: string[] }>; + hostUploads: Array<{ mediaType: string; originalFilename: string }>; + writes: Array<{ absolutePath: string; content: unknown }>; +} + +const DIR = `/repo/${WORKSPACE_ATTACHMENTS_DIR}`; + +function makeDeps( + options: { putStatus?: number; existing?: Set } = {}, +) { + const recorded: Recorded = { + uploads: [], + puts: [], + attached: [], + materialized: [], + hostUploads: [], + writes: [], + }; + let nextId = 0; + const existing = options.existing ?? new Set(); + const deps: SendAttachmentsDeps = { + async createUpload(input) { + recorded.uploads.push(input); + nextId += 1; + return { + fileId: `file-${nextId}`, + upload: { url: `https://r2.test/${nextId}`, headers: {} }, + }; + }, + async putObject(target, file) { + recorded.puts.push({ url: target.url, file }); + return new Response(null, { status: options.putStatus ?? 200 }); + }, + async attachFiles(input) { + recorded.attached.push(input); + }, + async materialize(input) { + recorded.materialized.push(input); + return { + paths: input.fileIds.map( + (id) => `${WORKSPACE_ATTACHMENTS_DIR}/${id}.png`, + ), + }; + }, + async hostUpload(input) { + recorded.hostUploads.push({ + mediaType: input.mediaType, + originalFilename: input.originalFilename, + }); + nextId += 1; + return { + attachmentId: `host-${nextId}`, + mediaType: input.mediaType, + sizeBytes: 4, + }; + }, + async worktreePath() { + return "/repo"; + }, + async createDirectory() {}, + async writeFile(input) { + if (existing.has(input.absolutePath)) + return { ok: false, reason: "exists" }; + existing.add(input.absolutePath); + recorded.writes.push({ + absolutePath: input.absolutePath, + content: input.content, + }); + return { ok: true }; + }, + }; + return { deps, recorded }; +} + +const png = (name: string, size = 4) => + new File([new Uint8Array(size)], name, { type: "image/png" }); + +const sized = (name: string, size: number) => + ({ name, type: "image/png", size }) as File; + +describe("sendAttachments", () => { + it("a cloud workspace's parts are storage objects, anchored to it, named by fileId alone", async () => { + const { deps, recorded } = makeDeps(); + const parts = await sendAttachments({ + deps, + route: "cloud", + workspaceId: "cloud-ws", + files: [png("a.png"), png("b.png", 9)], + }); + + expect(parts).toEqual([ + { + type: "attachment", + fileId: "file-1", + name: "a.png", + mimeType: "image/png", + sizeBytes: 4, + }, + { + type: "attachment", + fileId: "file-2", + name: "b.png", + mimeType: "image/png", + sizeBytes: 9, + }, + ]); + expect(recorded.attached).toEqual([ + { id: "cloud-ws", fileIds: ["file-1", "file-2"] }, + ]); + expect(recorded.hostUploads).toEqual([]); + expect(recorded.materialized).toEqual([]); + }); + + it("a host workspace's parts go to the host store and never to storage", async () => { + const { deps, recorded } = makeDeps(); + const parts = await sendAttachments({ + deps, + route: "remote", + workspaceId: "ws-1", + files: [png("a.png")], + }); + + expect(parts).toEqual([ + { + type: "attachment", + attachmentId: "host-1", + name: "a.png", + mimeType: "image/png", + sizeBytes: 4, + }, + ]); + expect(recorded.hostUploads).toEqual([ + { mediaType: "image/png", originalFilename: "a.png" }, + ]); + expect(recorded.uploads).toEqual([]); + expect(recorded.attached).toEqual([]); + }); + + it("refuses a host workspace a file over the inline cap, before sending anything", async () => { + const { deps, recorded } = makeDeps(); + await expect( + sendAttachments({ + deps, + route: "same-machine", + workspaceId: "ws-1", + files: [ + png("ok.png"), + sized("big.png", MAX_INLINE_ATTACHMENT_BYTES + 1), + ], + }), + ).rejects.toBeInstanceOf(AttachmentLimitError); + expect(recorded.hostUploads).toEqual([]); + }); + + it("hands each part and the file it came from to the caller, for the sent row", async () => { + const { deps } = makeDeps(); + const file = png("a.png"); + const sent: Array<[AttachmentPart, File]> = []; + await sendAttachments({ + deps, + route: "cloud", + workspaceId: "cloud-ws", + files: [file], + onSent: (part, from) => sent.push([part, from]), + }); + expect(sent.map(([part, from]) => [part.fileId, from])).toEqual([ + ["file-1", file], + ]); + }); + + it("names a nameless blob from its mime type and defaults the content type", async () => { + const { deps, recorded } = makeDeps(); + await sendAttachments({ + deps, + route: "cloud", + workspaceId: "cloud-ws", + files: [ + new File([new Uint8Array(2)], "", { type: "image/jpeg" }), + new File([new Uint8Array(2)], "", { type: "" }), + ], + }); + expect(recorded.uploads).toEqual([ + { name: "attachment_1.jpg", contentType: "image/jpeg", sizeBytes: 2 }, + { + name: "attachment_2", + contentType: "application/octet-stream", + sizeBytes: 2, + }, + ]); + }); + + it("refuses more files than one send may carry", async () => { + const { deps, recorded } = makeDeps(); + const files = Array.from({ length: MAX_ATTACHMENTS + 1 }, (_, i) => + png(`${i}.png`), + ); + await expect( + sendAttachments({ deps, route: "cloud", workspaceId: "ws", files }), + ).rejects.toBeInstanceOf(AttachmentLimitError); + expect(recorded.uploads).toEqual([]); + }); + + it("surfaces a rejected PUT and never anchors the files", async () => { + const { deps, recorded } = makeDeps({ putStatus: 403 }); + await expect( + sendAttachments({ + deps, + route: "cloud", + workspaceId: "ws", + files: [png("a.png")], + }), + ).rejects.toThrow("Upload failed for a.png (403)"); + expect(recorded.attached).toEqual([]); + }); +}); + +describe("sendAttachmentsToWorkspace", () => { + it("a box gets paths through storage: upload, anchor, then materialize", async () => { + const { deps, recorded } = makeDeps(); + const paths = await sendAttachmentsToWorkspace({ + deps, + route: "cloud", + workspaceId: "cloud-ws", + files: [png("shot.png")], + }); + expect(recorded.attached).toEqual([ + { id: "cloud-ws", fileIds: ["file-1"] }, + ]); + expect(recorded.materialized).toEqual([ + { workspaceId: "cloud-ws", fileIds: ["file-1"] }, + ]); + expect(recorded.writes).toEqual([]); + expect(paths).toEqual([`${WORKSPACE_ATTACHMENTS_DIR}/file-1.png`]); + }); + + it("a relay-reached host gets the bytes written into its worktree, and storage is never called", async () => { + const { deps, recorded } = makeDeps(); + const paths = await sendAttachmentsToWorkspace({ + deps, + route: "remote", + workspaceId: "ws-1", + files: [png("shot.png")], + }); + expect(recorded.uploads).toEqual([]); + expect(recorded.writes).toEqual([ + { + absolutePath: `${DIR}/.gitignore`, + content: WORKSPACE_ATTACHMENTS_GITIGNORE, + }, + { + absolutePath: `${DIR}/shot.png`, + content: { kind: "base64", data: "AAAAAA==" }, + }, + ]); + expect(paths).toEqual([`${WORKSPACE_ATTACHMENTS_DIR}/shot.png`]); + }); + + it("never overwrites a path an earlier paste already wrote", async () => { + const { deps } = makeDeps({ existing: new Set([`${DIR}/shot.png`]) }); + expect( + await sendAttachmentsToWorkspace({ + deps, + route: "remote", + workspaceId: "ws-1", + files: [png("shot.png")], + }), + ).toEqual([`${WORKSPACE_ATTACHMENTS_DIR}/shot_1.png`]); + }); + + it("refuses a relay-reached host a file over the inline cap", async () => { + const { deps, recorded } = makeDeps(); + await expect( + sendAttachmentsToWorkspace({ + deps, + route: "remote", + workspaceId: "ws-1", + files: [sized("big.png", MAX_INLINE_ATTACHMENT_BYTES + 1)], + }), + ).rejects.toBeInstanceOf(AttachmentLimitError); + expect(recorded.writes).toEqual([]); + }); + + it("keeps a same-machine send off storage: paths are copied, blobs written, order kept", async () => { + const { deps, recorded } = makeDeps(); + const dmg = new File([new Uint8Array(1)], "build.dmg"); + Object.defineProperty(dmg, "size", { value: MAX_ATTACHMENT_BYTES * 2 }); + const notes = new File(["n"], "notes.txt"); + const diskPaths = new Map([ + [dmg, "/Users/me/build.dmg"], + [notes, "/Users/me/notes.txt"], + ]); + const written: LocalAttachmentItem[][] = []; + + const paths = await sendAttachmentsToWorkspace({ + deps: { + ...deps, + sameMachine: { + pathOf: (file) => diskPaths.get(file) ?? "", + readBase64: async () => "cG5n", + async write(items) { + written.push(items); + return { + ok: true, + paths: items.map((_, i) => `${WORKSPACE_ATTACHMENTS_DIR}/${i}`), + }; + }, + }, + }, + route: "same-machine", + workspaceId: "ws-1", + files: [dmg, png("shot.png"), notes], + }); + + expect(written).toEqual([ + [ + { kind: "path", sourcePath: "/Users/me/build.dmg" }, + { kind: "base64", name: "shot.png", data: "cG5n" }, + { kind: "path", sourcePath: "/Users/me/notes.txt" }, + ], + ]); + expect(paths).toEqual([ + `${WORKSPACE_ATTACHMENTS_DIR}/0`, + `${WORKSPACE_ATTACHMENTS_DIR}/1`, + `${WORKSPACE_ATTACHMENTS_DIR}/2`, + ]); + expect(recorded.uploads).toEqual([]); + expect(recorded.materialized).toEqual([]); + }); + + it("caps same-machine blobs, since their bytes cross IPC", async () => { + const { deps } = makeDeps(); + const big = png("huge.png"); + Object.defineProperty(big, "size", { value: MAX_ATTACHMENT_BYTES + 1 }); + + await expect( + sendAttachmentsToWorkspace({ + deps: { + ...deps, + sameMachine: { + pathOf: () => "", + readBase64: async () => "", + write: async () => ({ ok: true, paths: [] }), + }, + }, + route: "same-machine", + workspaceId: "ws-1", + files: [big], + }), + ).rejects.toThrow(AttachmentLimitError); + }); + + it("throws when the host returns a different number of paths than files", async () => { + const { deps } = makeDeps(); + + await expect( + sendAttachmentsToWorkspace({ + deps: { ...deps, materialize: async () => ({ paths: [] }) }, + route: "cloud", + workspaceId: "ws-1", + files: [png("a.png")], + }), + ).rejects.toThrow("Expected 1 attachment paths, got 0"); + }); + + it("names the file this machine could not read, so the composer can say which", async () => { + const { deps } = makeDeps(); + + const error = await sendAttachmentsToWorkspace({ + deps: { + ...deps, + sameMachine: { + pathOf: (file) => `/Users/me/${file.name}`, + readBase64: async () => "", + write: async () => ({ ok: false, index: 1, problem: "missing" }), + }, + }, + route: "same-machine", + workspaceId: "ws-1", + files: [png("a.png"), png("moved.png")], + }).catch((caught: unknown) => caught); + + expect(error).toBeInstanceOf(AttachmentSourceError); + expect(error).toMatchObject({ + index: 1, + fileName: "moved.png", + problem: "missing", + }); + }); + + it("does nothing for an empty list", async () => { + const { deps, recorded } = makeDeps(); + expect( + await sendAttachmentsToWorkspace({ + deps, + route: "cloud", + workspaceId: "ws-1", + files: [], + }), + ).toEqual([]); + expect(recorded.uploads).toEqual([]); + }); +}); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/sendAttachmentsToWorkspace.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/sendAttachmentsToWorkspace.ts new file mode 100644 index 00000000000..9c390dd2b76 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/sendAttachmentsToWorkspace/sendAttachmentsToWorkspace.ts @@ -0,0 +1,392 @@ +import { msg } from "@lingui/core/macro"; +import type { UserContent } from "@superset/chat/protocol"; +import { i18n } from "@superset/i18n"; +import { + MAX_ATTACHMENT_BYTES, + MAX_ATTACHMENTS, + MAX_INLINE_ATTACHMENT_BYTES, +} from "@superset/shared/attachment-limits"; +import { + attachmentFallbackName, + attachmentNameWithSuffix, + sanitizeAttachmentFileName, + WORKSPACE_ATTACHMENTS_DIR, + WORKSPACE_ATTACHMENTS_GITIGNORE, +} from "@superset/shared/workspace-attachments"; +import { fileToBase64 } from "renderer/lib/file-to-base64"; + +export type AttachmentPart = Extract; + +/** + * Where a workspace's files go. `same-machine`: this desktop writes them + * itself. `remote`: a machine someone owns, reached through the relay; the + * bytes go to it and nowhere else. `cloud`: a box, so the bytes go through + * our storage and outlive it. + */ +export type AttachmentRoute = "same-machine" | "remote" | "cloud"; + +/** Thrown for limits the user can act on; the message is toast-ready. */ +export class AttachmentLimitError extends Error {} + +export type AttachmentSourceProblem = "missing" | "not-a-file" | "unreadable"; + +/** A file on this machine that could not be attached; `index` is its place in the send. */ +export class AttachmentSourceError extends Error { + constructor( + readonly index: number, + readonly fileName: string, + readonly problem: AttachmentSourceProblem, + ) { + super(`${fileName}: ${problem}`); + } +} + +function formatMb(bytes: number): string { + return `${Math.round(bytes / 1024 / 1024)}MB`; +} + +export interface AttachmentUploadTarget { + url: string; + headers: Record; +} + +export type LocalAttachmentItem = + | { kind: "path"; sourcePath: string } + | { kind: "base64"; name: string; data: string }; + +export type SameMachineWriteResult = + | { ok: true; paths: string[] } + | { ok: false; index: number; problem: AttachmentSourceProblem }; + +interface FsWriteOutcome { + ok: boolean; + reason?: string; +} + +export interface SendAttachmentsDeps { + createUpload(input: { + name: string; + contentType: string; + sizeBytes: number; + }): Promise<{ fileId: string; upload: AttachmentUploadTarget }>; + putObject(target: AttachmentUploadTarget, file: File): Promise; + /** A box can fetch only the files attached to it. */ + attachFiles(input: { id: string; fileIds: string[] }): Promise; + materialize(input: { + workspaceId: string; + fileIds: string[]; + }): Promise<{ paths: string[] }>; + hostUpload(input: { + data: { kind: "base64"; data: string }; + mediaType: string; + originalFilename: string; + }): Promise<{ attachmentId: string; mediaType: string; sizeBytes: number }>; + worktreePath(workspaceId: string): Promise; + createDirectory(input: { + workspaceId: string; + absolutePath: string; + recursive: boolean; + }): Promise; + writeFile(input: { + workspaceId: string; + absolutePath: string; + content: string | { kind: "base64"; data: string }; + options: { create: boolean; overwrite: boolean }; + }): Promise; + sameMachine?: { + pathOf(file: File): string; + readBase64(file: File): Promise; + write(items: LocalAttachmentItem[]): Promise; + }; +} + +const MIME_EXTENSIONS: Record = { + "image/png": "png", + "image/jpeg": "jpg", + "image/gif": "gif", + "image/webp": "webp", + "image/svg+xml": "svg", + "image/tiff": "tiff", + "image/bmp": "bmp", +}; + +const FALLBACK_CONTENT_TYPE = "application/octet-stream"; +const MAX_NAME_ATTEMPTS = 50; + +/** + * Clipboard files keep their name when they have one (Chromium synthesizes + * "image.png" for a screenshot; Finder copies keep the real name); a blob + * with none takes its extension from the mime type, the only signal it + * carries. + */ +function nameOf(file: File, index: number): string { + if (file.name) return file.name; + const extension = MIME_EXTENSIONS[file.type]; + return attachmentFallbackName(index, extension ? `.${extension}` : ""); +} + +function typeOf(file: File): string { + return file.type || FALLBACK_CONTENT_TYPE; +} + +/** Fits the request body a host holds in memory; above it, a host takes a path instead. */ +export function fitsInline(file: File): boolean { + return file.size <= MAX_INLINE_ATTACHMENT_BYTES; +} + +/** + * A host takes the bytes in one request body, so its cap is the transport's. + * `sized` is the files whose size counts; the same-machine route copies a + * file from disk, so only its clipboard blobs are capped. + */ +export function assertWithinLimits( + files: File[], + cap: number, + sized: File[] = files, +): void { + if (files.length > MAX_ATTACHMENTS) { + const count = files.length; + const max = MAX_ATTACHMENTS; + throw new AttachmentLimitError( + i18n._( + msg({ + message: `${count} files attached — a message carries at most ${max}`, + }), + ), + ); + } + for (const file of sized) { + if (file.size <= cap) continue; + const name = file.name || i18n._(msg({ message: "attachment" })); + const size = formatMb(file.size); + const limit = formatMb(cap); + throw new AttachmentLimitError( + cap === MAX_INLINE_ATTACHMENT_BYTES + ? i18n._( + msg({ + message: `"${name}" is ${size} — files over ${limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead.`, + }), + ) + : i18n._( + msg({ + message: `"${name}" is ${size} — files over ${limit} can't be attached`, + }), + ), + ); + } +} + +async function uploadToStorage( + deps: SendAttachmentsDeps, + workspaceId: string, + files: File[], +): Promise { + const fileIds = await Promise.all( + files.map(async (file, index) => { + const name = nameOf(file, index); + const { fileId, upload } = await deps.createUpload({ + name, + contentType: typeOf(file), + sizeBytes: file.size, + }); + const response = await deps.putObject(upload, file); + if (!response.ok) { + throw new Error(`Upload failed for ${name} (${response.status})`); + } + return fileId; + }), + ); + await deps.attachFiles({ id: workspaceId, fileIds }); + return fileIds; +} + +function expectOnePathEach(files: File[], paths: string[]): string[] { + if (paths.length !== files.length) { + throw new Error( + `Expected ${files.length} attachment paths, got ${paths.length}`, + ); + } + return paths; +} + +async function writeOnSameMachine( + sameMachine: NonNullable, + files: File[], +): Promise { + const sourcePaths = files.map((file) => sameMachine.pathOf(file)); + assertWithinLimits( + files, + MAX_ATTACHMENT_BYTES, + files.filter((_, index) => !sourcePaths[index]), + ); + const items = await Promise.all( + files.map(async (file, index): Promise => { + const sourcePath = sourcePaths[index]; + if (sourcePath) return { kind: "path", sourcePath }; + return { + kind: "base64", + name: nameOf(file, index), + data: await sameMachine.readBase64(file), + }; + }), + ); + const result = await sameMachine.write(items); + if (!result.ok) { + throw new AttachmentSourceError( + result.index, + files[result.index]?.name || attachmentFallbackName(result.index), + result.problem, + ); + } + return expectOnePathEach(files, result.paths); +} + +/** + * Create-only writes report "exists", so the real directory decides the name: + * a second screenshot must never overwrite a path an earlier prompt names. + */ +async function writeUnique( + deps: SendAttachmentsDeps, + workspaceId: string, + dirAbs: string, + base: string, + data: string, +): Promise { + for (let attempt = 0; attempt < MAX_NAME_ATTEMPTS; attempt++) { + const fileName = attachmentNameWithSuffix(base, attempt); + const outcome = await deps.writeFile({ + workspaceId, + absolutePath: `${dirAbs}/${fileName}`, + content: { kind: "base64", data }, + options: { create: true, overwrite: false }, + }); + if (outcome.ok !== false) return fileName; + if (outcome.reason !== "exists") { + throw new Error(outcome.reason ?? "write failed"); + } + } + throw new Error(`Could not find a free name for ${base}`); +} + +async function writeIntoRemoteWorktree( + deps: SendAttachmentsDeps, + workspaceId: string, + files: File[], +): Promise { + const dirAbs = `${await deps.worktreePath(workspaceId)}/${WORKSPACE_ATTACHMENTS_DIR}`; + await deps.createDirectory({ + workspaceId, + absolutePath: dirAbs, + recursive: true, + }); + const ignore = await deps.writeFile({ + workspaceId, + absolutePath: `${dirAbs}/.gitignore`, + content: WORKSPACE_ATTACHMENTS_GITIGNORE, + options: { create: true, overwrite: false }, + }); + if (ignore.ok === false && ignore.reason !== "exists") { + throw new Error(ignore.reason ?? "write failed"); + } + const paths: string[] = []; + for (const [index, file] of files.entries()) { + const base = + sanitizeAttachmentFileName(nameOf(file, index)) ?? + attachmentFallbackName(index); + const fileName = await writeUnique( + deps, + workspaceId, + dirAbs, + base, + await fileToBase64(file), + ); + paths.push(`${WORKSPACE_ATTACHMENTS_DIR}/${fileName}`); + } + return paths; +} + +/** + * The parts a chat message carries for `files`, one identity each, chosen by + * where the workspace lives: a cloud part is a `fileId` in storage, which + * renders without the box; a host part is an `attachmentId` in that host's + * store, and its bytes never leave the host. + */ +export async function sendAttachments(options: { + deps: SendAttachmentsDeps; + route: AttachmentRoute; + workspaceId: string; + files: File[]; + onSent?: (part: AttachmentPart, file: File) => void; +}): Promise { + const { deps, route, workspaceId, files } = options; + if (files.length === 0) return []; + assertWithinLimits( + files, + route === "cloud" ? MAX_ATTACHMENT_BYTES : MAX_INLINE_ATTACHMENT_BYTES, + ); + + const parts: AttachmentPart[] = + route === "cloud" + ? (await uploadToStorage(deps, workspaceId, files)).map( + (fileId, index) => { + const file = files[index] as File; + return { + type: "attachment", + fileId, + name: nameOf(file, index), + mimeType: typeOf(file), + sizeBytes: file.size, + }; + }, + ) + : await Promise.all( + files.map(async (file, index) => { + const record = await deps.hostUpload({ + data: { kind: "base64", data: await fileToBase64(file) }, + mediaType: typeOf(file), + originalFilename: nameOf(file, index), + }); + return { + type: "attachment" as const, + attachmentId: record.attachmentId, + name: nameOf(file, index), + mimeType: record.mediaType, + sizeBytes: record.sizeBytes, + }; + }), + ); + for (const [index, part] of parts.entries()) { + options.onSent?.(part, files[index] as File); + } + return parts; +} + +/** + * Worktree-relative paths for surfaces that take text: a PTY, a file too big + * for a part on this machine, or a chat message to a host too old to read + * parts. This machine copies the files itself, with no cap. A relay-reached + * host gets the bytes in the request, since storage would put them on our + * servers. A box gets them through storage, because its ingress can cut a + * request body the host answers early. + */ +export async function sendAttachmentsToWorkspace(options: { + deps: SendAttachmentsDeps; + route: AttachmentRoute; + workspaceId: string; + files: File[]; +}): Promise { + const { deps, route, workspaceId, files } = options; + if (files.length === 0) return []; + if (route === "same-machine") { + if (!deps.sameMachine) throw new Error("Workspace is not ready"); + return writeOnSameMachine(deps.sameMachine, files); + } + if (route === "remote") { + assertWithinLimits(files, MAX_INLINE_ATTACHMENT_BYTES); + return writeIntoRemoteWorktree(deps, workspaceId, files); + } + assertWithinLimits(files, MAX_ATTACHMENT_BYTES); + const fileIds = await uploadToStorage(deps, workspaceId, files); + const { paths } = await deps.materialize({ workspaceId, fileIds }); + return expectOnePathEach(files, paths); +} diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/index.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/index.ts deleted file mode 100644 index c1582bc0276..00000000000 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { - PasteUploadLimitError, - uploadPastedFiles, -} from "./uploadPastedFiles"; diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/uploadPastedFiles.test.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/uploadPastedFiles.test.ts deleted file mode 100644 index afd97401f77..00000000000 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/uploadPastedFiles.test.ts +++ /dev/null @@ -1,237 +0,0 @@ -import { afterAll, beforeAll, describe, expect, it } from "bun:test"; -import { WORKSPACE_ATTACHMENTS_DIR } from "@superset/shared/workspace-attachments"; -import { - PasteUploadLimitError, - type UploadPastedFilesDeps, - uploadPastedFiles, -} from "./uploadPastedFiles"; - -// fileToBase64 goes through FileReader.readAsDataURL, which the renderer has -// but Bun's test runtime may not — pin a minimal implementation over -// Blob.arrayBuffer so the tests exercise the real base64 pipeline. -let fileReads = 0; - -class TestFileReader { - result: string | null = null; - error: Error | null = null; - onload: (() => void) | null = null; - onerror: (() => void) | null = null; - - readAsDataURL(file: File) { - fileReads += 1; - file - .arrayBuffer() - .then((buffer) => { - const base64 = Buffer.from(buffer).toString("base64"); - this.result = `data:${file.type};base64,${base64}`; - this.onload?.(); - }) - .catch((error) => { - this.error = error; - this.onerror?.(); - }); - } -} - -const originalFileReader = (globalThis as { FileReader?: unknown }).FileReader; - -beforeAll(() => { - (globalThis as { FileReader?: unknown }).FileReader = TestFileReader; -}); - -afterAll(() => { - (globalThis as { FileReader?: unknown }).FileReader = originalFileReader; -}); - -interface RecordedWrite { - absolutePath: string; - content: string | { kind: "base64"; data: string }; - options: { create: boolean; overwrite: boolean }; -} - -/** - * Fake deps backed by a real "directory": create-only writes report "exists" - * on a name collision exactly like the host does, so the collision-probing - * naming is exercised for real. - */ -function makeDeps(options: { existing?: string[]; failWrites?: boolean } = {}) { - const createdDirs: string[] = []; - const writes: RecordedWrite[] = []; - const existing = new Set(options.existing ?? []); - const deps: UploadPastedFilesDeps = { - async createDirectory(input) { - createdDirs.push(input.absolutePath); - }, - async writeFile(input) { - const write: RecordedWrite = { - absolutePath: input.absolutePath, - content: input.content, - options: input.options, - }; - writes.push(write); - if (options.failWrites && !input.absolutePath.endsWith(".gitignore")) { - return { ok: false, reason: "conflict" }; - } - if (existing.has(input.absolutePath) && !input.options.overwrite) { - return { ok: false, reason: "exists" }; - } - existing.add(input.absolutePath); - return { ok: true }; - }, - }; - return { deps, createdDirs, writes }; -} - -const WORKTREE = "/home/user/.superset/worktrees/demo"; -const DIR_ABS = `${WORKTREE}/${WORKSPACE_ATTACHMENTS_DIR}`; - -describe("uploadPastedFiles", () => { - it("creates the attachments dir, self-ignores it, writes each file, returns relative paths", async () => { - const { deps, createdDirs, writes } = makeDeps(); - const files = [ - new File([new Uint8Array([1, 2, 3])], "image.png", { - type: "image/png", - }), - new File([new Uint8Array([4, 5])], "notes.pdf", { - type: "application/pdf", - }), - ]; - - const paths = await uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files, - }); - - expect(createdDirs).toEqual([DIR_ABS]); - expect(writes[0]).toEqual({ - absolutePath: `${DIR_ABS}/.gitignore`, - content: "*\n", - // create-only: a user's own .gitignore edit is never clobbered. - options: { create: true, overwrite: false }, - }); - // Worktree-relative, matching the agent-launch and mobile convention. - expect(paths).toEqual([ - `${WORKSPACE_ATTACHMENTS_DIR}/image.png`, - `${WORKSPACE_ATTACHMENTS_DIR}/notes.pdf`, - ]); - expect(writes[1]?.options).toEqual({ create: true, overwrite: false }); - expect(writes[1]?.content).toEqual({ - kind: "base64", - data: Buffer.from([1, 2, 3]).toString("base64"), - }); - }); - - it("never overwrites an earlier paste — collisions probe to a fresh _N name", async () => { - const { deps, writes } = makeDeps({ - existing: [`${DIR_ABS}/image.png`, `${DIR_ABS}/image_1.png`], - }); - - const paths = await uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files: [new File(["x"], "image.png", { type: "image/png" })], - }); - - expect(paths).toEqual([`${WORKSPACE_ATTACHMENTS_DIR}/image_2.png`]); - // Every probe was create-only; nothing was written over. - expect(writes.every((w) => w.options.overwrite === false)).toBe(true); - }); - - it("tolerates a .gitignore that already exists from an earlier paste", async () => { - const { deps } = makeDeps({ existing: [`${DIR_ABS}/.gitignore`] }); - - const paths = await uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files: [new File(["x"], "image.png", { type: "image/png" })], - }); - - expect(paths).toEqual([`${WORKSPACE_ATTACHMENTS_DIR}/image.png`]); - }); - - it("throws when a file write is refused", async () => { - const { deps } = makeDeps({ failWrites: true }); - - await expect( - uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files: [new File(["x"], "image.png", { type: "image/png" })], - }), - ).rejects.toThrow("conflict"); - }); - - it("refuses oversized files before reading any bytes", async () => { - const { deps, createdDirs, writes } = makeDeps(); - fileReads = 0; - const big = new File([new Uint8Array(1)], "video.mov", { - type: "video/quicktime", - }); - // A 2GB Blob in the test would be real memory; fake the size instead — - // the check reads file.size only. - Object.defineProperty(big, "size", { value: 2 * 1024 * 1024 * 1024 }); - - await expect( - uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files: [big], - }), - ).rejects.toThrow(PasteUploadLimitError); - // Failed fast: nothing read, no directory created, no bytes shipped. - expect(fileReads).toBe(0); - expect(createdDirs).toHaveLength(0); - expect(writes).toHaveLength(0); - }); - - it("refuses batches over the total budget", async () => { - const { deps, createdDirs, writes } = makeDeps(); - fileReads = 0; - const files = Array.from({ length: 5 }, (_, i) => { - const f = new File([new Uint8Array(1)], `part${i}.bin`, { - type: "application/octet-stream", - }); - Object.defineProperty(f, "size", { value: 45 * 1024 * 1024 }); - return f; - }); - - await expect( - uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files, - }), - ).rejects.toThrow(PasteUploadLimitError); - expect(fileReads).toBe(0); - expect(createdDirs).toHaveLength(0); - expect(writes).toHaveLength(0); - }); - - it("sanitizes path-hostile clipboard names and falls back to attachment_N", async () => { - const { deps } = makeDeps(); - - const paths = await uploadPastedFiles({ - deps, - workspaceId: "ws-1", - worktreePath: WORKTREE, - files: [ - new File(["x"], "../shot: 1/final.png", { type: "image/png" }), - new File(["y"], "", { type: "image/png" }), - new File(["z"], "", { type: "application/x-thing" }), - ], - }); - - expect(paths).toEqual([ - `${WORKSPACE_ATTACHMENTS_DIR}/.._shot__1_final.png`, - `${WORKSPACE_ATTACHMENTS_DIR}/attachment_2.png`, - `${WORKSPACE_ATTACHMENTS_DIR}/attachment_3`, - ]); - }); -}); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/uploadPastedFiles.ts b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/uploadPastedFiles.ts deleted file mode 100644 index 12c1058d49f..00000000000 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/utils/uploadPastedFiles/uploadPastedFiles.ts +++ /dev/null @@ -1,166 +0,0 @@ -import { - attachmentFallbackName, - attachmentNameWithSuffix, - sanitizeAttachmentFileName, - WORKSPACE_ATTACHMENTS_DIR, - WORKSPACE_ATTACHMENTS_GITIGNORE, -} from "@superset/shared/workspace-attachments"; -import { fileToBase64 } from "renderer/lib/file-to-base64"; - -// Pastes follow the shared workspace-attachments convention (same directory -// and naming as agent-launch and the mobile composer): worktree-relative -// paths, since `filesystem.writeFile` refuses paths outside the worktree. -// The directory self-ignores (see the `.gitignore` write below) so -// attachments never dirty git status. - -/** Collision-probe cap; matches the spirit of createUniqueEntry's bound. */ -const MAX_NAME_ATTEMPTS = 50; - -// Same caps as the agent-launch adapter's attachment writer. The bytes are -// FileReader-read and base64'd (~1.33x) in renderer memory, then travel as -// one JSON body — an accidentally pasted multi-GB Finder file must fail -// fast instead of stalling the renderer and the host. -const MAX_SINGLE_FILE_BYTES = 50 * 1024 * 1024; -const MAX_TOTAL_BYTES = 200 * 1024 * 1024; - -/** Thrown for limits the user can act on; the message is toast-ready. */ -export class PasteUploadLimitError extends Error {} - -function formatMb(bytes: number): string { - return `${Math.round(bytes / 1024 / 1024)}MB`; -} - -interface FsWriteOutcome { - ok: boolean; - reason?: string; -} - -export interface UploadPastedFilesDeps { - createDirectory(input: { - workspaceId: string; - absolutePath: string; - recursive: boolean; - }): Promise; - writeFile(input: { - workspaceId: string; - absolutePath: string; - content: string | { kind: "base64"; data: string }; - options: { create: boolean; overwrite: boolean }; - }): Promise; -} - -const MIME_EXTENSIONS: Record = { - "image/png": "png", - "image/jpeg": "jpg", - "image/gif": "gif", - "image/webp": "webp", - "image/svg+xml": "svg", - "image/tiff": "tiff", - "image/bmp": "bmp", -}; - -/** - * Clipboard names (Chromium synthesizes "image.png" for screenshots; Finder - * copies keep their real name) go through the shared sanitizer; generated - * fallbacks take their extension from the mime type, the only signal a - * clipboard file carries. - */ -function baseFileName(file: File, index: number): string { - const sanitized = sanitizeAttachmentFileName(file.name); - if (sanitized) return sanitized; - const extension = MIME_EXTENSIONS[file.type]; - return attachmentFallbackName(index, extension ? `.${extension}` : ""); -} - -/** - * Write one file under a collision-free name. The batch conventions dedupe - * against an in-memory set; pastes arrive one at a time across a session, so - * probe the real directory instead (create-only writes report "exists") — - * a second screenshot must never overwrite a path an earlier prompt already - * references. - */ -async function writeUnique( - deps: UploadPastedFilesDeps, - workspaceId: string, - dirAbs: string, - base: string, - data: string, -): Promise { - for (let attempt = 0; attempt < MAX_NAME_ATTEMPTS; attempt++) { - const fileName = attachmentNameWithSuffix(base, attempt); - const outcome = await deps.writeFile({ - workspaceId, - absolutePath: `${dirAbs}/${fileName}`, - content: { kind: "base64", data }, - options: { create: true, overwrite: false }, - }); - if (outcome.ok !== false) return fileName; - if (outcome.reason !== "exists") { - throw new Error(outcome.reason ?? "write failed"); - } - } - throw new Error(`Could not find a free name for ${base}`); -} - -/** - * Ship clipboard files to a workspace whose PTY runs on another machine and - * return the worktree-relative paths written, ready to paste into the - * terminal. Throws on the first failed write — the caller owns the error - * surface. - */ -export async function uploadPastedFiles(options: { - deps: UploadPastedFilesDeps; - workspaceId: string; - worktreePath: string; - files: File[]; -}): Promise { - const { deps, workspaceId, worktreePath, files } = options; - const dirAbs = `${worktreePath}/${WORKSPACE_ATTACHMENTS_DIR}`; - - let totalBytes = 0; - for (const file of files) { - if (file.size > MAX_SINGLE_FILE_BYTES) { - throw new PasteUploadLimitError( - `"${file.name || "pasted file"}" is ${formatMb(file.size)} — files over ${formatMb(MAX_SINGLE_FILE_BYTES)} can't be sent to a remote workspace`, - ); - } - totalBytes += file.size; - } - if (totalBytes > MAX_TOTAL_BYTES) { - throw new PasteUploadLimitError( - `Pasted files total ${formatMb(totalBytes)} — more than the ${formatMb(MAX_TOTAL_BYTES)} limit for a remote workspace`, - ); - } - - await deps.createDirectory({ - workspaceId, - absolutePath: dirAbs, - recursive: true, - }); - - // `*` ignores every attachment and the .gitignore itself, so agents never - // see attachments as untracked changes. create-only: a user's own edit wins. - const ignoreOutcome = await deps.writeFile({ - workspaceId, - absolutePath: `${dirAbs}/.gitignore`, - content: WORKSPACE_ATTACHMENTS_GITIGNORE, - options: { create: true, overwrite: false }, - }); - if (ignoreOutcome.ok === false && ignoreOutcome.reason !== "exists") { - throw new Error(ignoreOutcome.reason ?? "write failed"); - } - - const paths: string[] = []; - for (const [index, file] of files.entries()) { - const data = await fileToBase64(file); - const fileName = await writeUnique( - deps, - workspaceId, - dirAbs, - baseFileName(file, index), - data, - ); - paths.push(`${WORKSPACE_ATTACHMENTS_DIR}/${fileName}`); - } - return paths; -} diff --git a/apps/mobile/lib/attachments/chatParts.test.ts b/apps/mobile/lib/attachments/chatParts.test.ts new file mode 100644 index 00000000000..8bc80614d33 --- /dev/null +++ b/apps/mobile/lib/attachments/chatParts.test.ts @@ -0,0 +1,119 @@ +import { beforeAll, describe, expect, test } from "bun:test"; +import { initI18n } from "@superset/i18n"; +import { MAX_INLINE_ATTACHMENT_BYTES } from "@superset/shared/attachment-limits"; +import { + AttachmentLimitError, + type ChatAttachmentFile, + type ChatPartsDeps, + chatAttachmentParts, +} from "./chatParts"; + +const FILE_ID = "8c1f6f8e-3a2b-4c5d-9e0f-112233445566"; + +function file(name: string, size = 3): ChatAttachmentFile { + return { + name, + mimeType: "image/png", + size, + readBase64: async () => "AQID", + }; +} + +function recordingDeps() { + const calls: string[] = []; + const deps: ChatPartsDeps = { + awaitUploads: async () => { + calls.push("awaitUploads"); + return [FILE_ID]; + }, + attachFiles: async () => { + calls.push("attachFiles"); + }, + importFromCloud: async () => { + calls.push("importFromCloud"); + return [ + { + attachmentId: "imported", + originalFilename: "shot.png", + mediaType: "image/png", + sizeBytes: 3, + }, + ]; + }, + hostUpload: async (input) => { + calls.push(`hostUpload:${input.data.data}`); + return { attachmentId: "host-1", mediaType: "image/png", sizeBytes: 3 }; + }, + }; + return { deps, calls }; +} + +beforeAll(() => initI18n()); + +describe("chatAttachmentParts", () => { + test("a cloud part carries its fileId and skips the import", async () => { + const { deps, calls } = recordingDeps(); + const parts = await chatAttachmentParts({ + home: "cloud", + readsParts: true, + files: [file("shot.png")], + deps, + }); + expect(parts).toEqual([ + { + type: "attachment", + fileId: FILE_ID, + name: "shot.png", + mimeType: "image/png", + sizeBytes: 3, + }, + ]); + expect(calls).toEqual(["awaitUploads", "attachFiles"]); + }); + + test("a box too old to read parts gets the copy it imports", async () => { + const { deps, calls } = recordingDeps(); + const parts = await chatAttachmentParts({ + home: "cloud", + readsParts: false, + files: [file("shot.png")], + deps, + }); + expect(parts[0]?.attachmentId).toBe("imported"); + expect(parts[0]?.fileId).toBeUndefined(); + expect(calls).toEqual(["awaitUploads", "attachFiles", "importFromCloud"]); + }); + + test("a host part goes to the host in the request and never to storage", async () => { + const { deps, calls } = recordingDeps(); + const parts = await chatAttachmentParts({ + home: "host", + readsParts: true, + files: [file("shot.png")], + deps, + }); + expect(parts).toEqual([ + { + type: "attachment", + attachmentId: "host-1", + name: "shot.png", + mimeType: "image/png", + sizeBytes: 3, + }, + ]); + expect(calls).toEqual(["hostUpload:AQID"]); + }); + + test("a host refuses a file over the inline cap before sending anything", async () => { + const { deps, calls } = recordingDeps(); + await expect( + chatAttachmentParts({ + home: "host", + readsParts: true, + files: [file("big.png", MAX_INLINE_ATTACHMENT_BYTES + 1)], + deps, + }), + ).rejects.toBeInstanceOf(AttachmentLimitError); + expect(calls).toEqual([]); + }); +}); diff --git a/apps/mobile/lib/attachments/chatParts.ts b/apps/mobile/lib/attachments/chatParts.ts new file mode 100644 index 00000000000..1c3d217336e --- /dev/null +++ b/apps/mobile/lib/attachments/chatParts.ts @@ -0,0 +1,120 @@ +import { msg } from "@lingui/core/macro"; +import { i18n } from "@superset/i18n"; +import { MAX_INLINE_ATTACHMENT_BYTES } from "@superset/shared/attachment-limits"; + +export interface ChatAttachmentPart { + type: "attachment"; + attachmentId?: string; + fileId?: string; + name: string; + mimeType: string; + sizeBytes?: number; +} + +export interface ChatAttachmentFile { + name: string; + mimeType: string; + size: number; + readBase64: () => Promise; +} + +interface HostRecord { + attachmentId: string; + originalFilename?: string; + mediaType: string; + sizeBytes: number; +} + +export interface ChatPartsDeps { + /** The storage ids of the draft's uploads, waiting on any still in flight. */ + awaitUploads: () => Promise; + attachFiles: (fileIds: string[]) => Promise; + importFromCloud: (fileIds: string[]) => Promise; + hostUpload: (input: { + data: { kind: "base64"; data: string }; + mediaType: string; + originalFilename: string; + }) => Promise; +} + +/** Thrown for limits the user can act on; the message is alert-ready. */ +export class AttachmentLimitError extends Error {} + +/** A host takes the bytes in one request body, which it holds in memory. */ +export function assertFitsHost(files: ChatAttachmentFile[]): void { + const tooLarge = files.find( + (file) => file.size > MAX_INLINE_ATTACHMENT_BYTES, + ); + if (!tooLarge) return; + const name = tooLarge.name; + const limit = `${Math.round(MAX_INLINE_ATTACHMENT_BYTES / 1024 / 1024)}MB`; + throw new AttachmentLimitError( + i18n._( + msg({ + message: `"${name}" is over ${limit}, the most a workspace outside the cloud can take`, + }), + ), + ); +} + +/** + * The parts a chat message carries, by where the workspace lives. A cloud + * part is a storage object, so it renders without the box; a host part is in + * that host's store, and its bytes never reach our servers. A box too old to + * read a part by `fileId` gets the copy it imports instead. + */ +export async function chatAttachmentParts({ + home, + readsParts, + files, + deps, +}: { + home: "cloud" | "host"; + readsParts: boolean; + files: ChatAttachmentFile[]; + deps: ChatPartsDeps; +}): Promise { + if (files.length === 0) return []; + if (home === "host") { + assertFitsHost(files); + return Promise.all( + files.map(async (file) => { + const record = await deps.hostUpload({ + data: { kind: "base64", data: await file.readBase64() }, + mediaType: file.mimeType, + originalFilename: file.name, + }); + return { + type: "attachment" as const, + attachmentId: record.attachmentId, + name: file.name, + mimeType: record.mediaType, + sizeBytes: record.sizeBytes, + }; + }), + ); + } + + const fileIds = await deps.awaitUploads(); + await deps.attachFiles(fileIds); + if (readsParts) { + return fileIds.map((fileId, index) => { + const file = files[index] as ChatAttachmentFile; + return { + type: "attachment", + fileId, + name: file.name, + mimeType: file.mimeType, + sizeBytes: file.size, + }; + }); + } + const imported = await deps.importFromCloud(fileIds); + return imported.map((record) => ({ + type: "attachment", + attachmentId: record.attachmentId, + name: record.originalFilename ?? "attachment", + mimeType: record.mediaType, + sizeBytes: record.sizeBytes, + })); +} diff --git a/apps/mobile/lib/attachments/upload.ts b/apps/mobile/lib/attachments/upload.ts index 24b19bb82cf..5a7dfeacf1d 100644 --- a/apps/mobile/lib/attachments/upload.ts +++ b/apps/mobile/lib/attachments/upload.ts @@ -5,6 +5,7 @@ import { File } from "expo-file-system"; import type { PromptInputAttachmentItem } from "@/components/ai-elements/prompt-input"; import { apiClient } from "@/lib/trpc/client"; import { useComposerDraftsStore } from "@/screens/(authenticated)/stores/composerDraftsStore"; +import type { ChatAttachmentFile } from "./chatParts"; import { waitForSettledUploads } from "./settle"; const FALLBACK_MEDIA_TYPE = "application/octet-stream"; @@ -17,12 +18,29 @@ const FALLBACK_MEDIA_TYPE = "application/octet-stream"; */ const controllers = new Map(); +/** + * Drafts whose workspace is on a machine someone owns. Their bytes go to that + * host at send and never to our storage, so nothing uploads at attach time. + */ +const hostDrafts = new Set(); + +export function setDraftAttachmentHome( + draftKey: string, + home: "cloud" | "host", +): void { + if (home === "host") hostDrafts.add(draftKey); + else hostDrafts.delete(draftKey); +} + /** * The name to store an attachment under when the picker gave us none. The * uri's last segment is what the user would recognize; a generated name is * the last resort, and the host renames anything unusable anyway. */ -function nameOf(attachment: PromptInputAttachmentItem, index: number): string { +export function nameOf( + attachment: PromptInputAttachmentItem, + index: number, +): string { if (attachment.name) return attachment.name; const fromUri = decodeURIComponent( attachment.uri.split("?")[0]?.split("/").pop() ?? "", @@ -139,6 +157,7 @@ export function startAttachmentUploads( draftKey: string, attachments: PromptInputAttachmentItem[], ): void { + if (hostDrafts.has(draftKey)) return; for (const [index, attachment] of attachments.entries()) { if (controllers.has(attachment.id)) continue; void upload(draftKey, attachment, index); @@ -168,14 +187,17 @@ export async function awaitAttachmentUploads( useComposerDraftsStore.getState().draftsByKey[draftKey]?.uploads ?? {}; // A failure earlier in the draft's life is worth one more try now that the // user has actually asked to send: the usual cause is a connection that - // has since come back. + // has since come back. One that never started was attached while the + // workspace's home was still unknown. const stale = uploadsNow(); startAttachmentUploads( draftKey, // Only entries the draft still holds: `beginUpload` refuses to write // state for an attachment that is gone, so starting one would upload // bytes nothing could ever wait on. - attachments.filter((item) => stale[item.id]?.error !== undefined), + attachments.filter( + (item) => !stale[item.id] || stale[item.id]?.error !== undefined, + ), ); const uploads = await waitForSettledUploads( @@ -194,3 +216,18 @@ export async function awaitAttachmentUploads( return entry.fileId; }); } + +/** The composer's attachments as files a host can be sent, read only when sent. */ +export function toAttachmentFiles( + attachments: PromptInputAttachmentItem[], +): ChatAttachmentFile[] { + return attachments.map((attachment, index) => { + const file = new File(attachment.uri); + return { + name: nameOf(attachment, index), + mimeType: attachment.mediaType ?? FALLBACK_MEDIA_TYPE, + size: file.size ?? 0, + readBase64: () => file.base64(), + }; + }); +} diff --git a/apps/mobile/lib/attachments/worktreeWrite.test.ts b/apps/mobile/lib/attachments/worktreeWrite.test.ts new file mode 100644 index 00000000000..ee6048e1438 --- /dev/null +++ b/apps/mobile/lib/attachments/worktreeWrite.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, test } from "bun:test"; +import { WORKSPACE_ATTACHMENTS_DIR } from "@superset/shared/workspace-attachments"; +import { writeAttachmentsToWorktree } from "./worktreeWrite"; + +const DIR = `/repo/${WORKSPACE_ATTACHMENTS_DIR}`; + +describe("writeAttachmentsToWorktree", () => { + test("writes the bytes into the worktree create-only and names around what is there", async () => { + const existing = new Set([`${DIR}/shot.png`]); + const written: string[] = []; + const paths = await writeAttachmentsToWorktree( + [ + { + name: "shot.png", + mimeType: "image/png", + size: 3, + readBase64: async () => "AQID", + }, + ], + { + worktreePath: async () => "/repo", + createDirectory: async () => {}, + writeFile: async ({ absolutePath }) => { + if (existing.has(absolutePath)) + return { ok: false, reason: "exists" }; + existing.add(absolutePath); + written.push(absolutePath); + return { ok: true }; + }, + }, + ); + expect(written).toEqual([`${DIR}/.gitignore`, `${DIR}/shot_1.png`]); + expect(paths).toEqual([`${WORKSPACE_ATTACHMENTS_DIR}/shot_1.png`]); + }); +}); diff --git a/apps/mobile/lib/attachments/worktreeWrite.ts b/apps/mobile/lib/attachments/worktreeWrite.ts new file mode 100644 index 00000000000..94f7c90fd37 --- /dev/null +++ b/apps/mobile/lib/attachments/worktreeWrite.ts @@ -0,0 +1,71 @@ +import { + attachmentFallbackName, + attachmentNameWithSuffix, + sanitizeAttachmentFileName, + WORKSPACE_ATTACHMENTS_DIR, + WORKSPACE_ATTACHMENTS_GITIGNORE, +} from "@superset/shared/workspace-attachments"; +import { assertFitsHost, type ChatAttachmentFile } from "./chatParts"; + +const MAX_NAME_ATTEMPTS = 50; + +export interface WorktreeWriteDeps { + worktreePath: () => Promise; + createDirectory: (absolutePath: string) => Promise; + writeFile: (input: { + absolutePath: string; + content: string | { kind: "base64"; data: string }; + }) => Promise<{ ok: boolean; reason?: string }>; +} + +/** + * Worktree-relative paths for a PTY on a machine someone owns: the bytes go to + * that host in the request and are written create-only, so a later paste never + * overwrites a path an earlier prompt names. + */ +export async function writeAttachmentsToWorktree( + files: ChatAttachmentFile[], + deps: WorktreeWriteDeps, +): Promise { + assertFitsHost(files); + + const dir = `${await deps.worktreePath()}/${WORKSPACE_ATTACHMENTS_DIR}`; + await deps.createDirectory(dir); + const ignore = await deps.writeFile({ + absolutePath: `${dir}/.gitignore`, + content: WORKSPACE_ATTACHMENTS_GITIGNORE, + }); + if (!ignore.ok && ignore.reason !== "exists") { + throw new Error(ignore.reason ?? "write failed"); + } + + const paths: string[] = []; + for (const [index, file] of files.entries()) { + const base = + sanitizeAttachmentFileName(file.name) ?? attachmentFallbackName(index); + const data = await file.readBase64(); + const name = await writeUnique(deps, dir, base, data); + paths.push(`${WORKSPACE_ATTACHMENTS_DIR}/${name}`); + } + return paths; +} + +async function writeUnique( + deps: WorktreeWriteDeps, + dir: string, + base: string, + data: string, +): Promise { + for (let attempt = 0; attempt < MAX_NAME_ATTEMPTS; attempt++) { + const name = attachmentNameWithSuffix(base, attempt); + const outcome = await deps.writeFile({ + absolutePath: `${dir}/${name}`, + content: { kind: "base64", data }, + }); + if (outcome.ok) return name; + if (outcome.reason !== "exists") { + throw new Error(outcome.reason ?? "write failed"); + } + } + throw new Error(`Could not find a free name for ${base}`); +} diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/WorkspaceScreen/WorkspaceScreen.tsx b/apps/mobile/screens/(authenticated)/workspace/[id]/WorkspaceScreen/WorkspaceScreen.tsx index 4e750ac2bd5..33e5622f4c1 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/WorkspaceScreen/WorkspaceScreen.tsx +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/WorkspaceScreen/WorkspaceScreen.tsx @@ -7,7 +7,9 @@ import type { ComposerSessionTab, } from "@superset/composer"; import { i18n } from "@superset/i18n"; +import { rawErrorMessage } from "@superset/i18n/errors"; import { BRAND } from "@superset/shared/brand"; +import { hostReadsAttachmentParts } from "@superset/shared/host-version"; import { TitlePress } from "@superset/title-press"; import { useQueryClient } from "@tanstack/react-query"; import * as Clipboard from "expo-clipboard"; @@ -36,11 +38,18 @@ import { View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; +import type { PromptInputAttachmentItem } from "@/components/ai-elements/prompt-input"; import { Icon } from "@/components/ui/icon"; import { Text } from "@/components/ui/text"; import { useArchivedCloudWorkspaces } from "@/hooks/useArchivedCloudWorkspaces"; import { getHostWorkspacesQueryKey } from "@/hooks/useHostWorkspaces"; import { useWorkspaceHost } from "@/hooks/useWorkspaceHost"; +import { chatAttachmentParts } from "@/lib/attachments/chatParts"; +import { + awaitAttachmentUploads, + setDraftAttachmentHome, + toAttachmentFiles, +} from "@/lib/attachments/upload"; import { getChatTransport } from "@/lib/chat"; import { errorCopy } from "@/lib/errors"; import { @@ -414,6 +423,11 @@ export function WorkspaceScreen() { ? hostServiceUrl(host.organizationId, host.machineId) : null; const hostCompatibility = useHostCompatibility(hostUrl); + const hostVersion = hostCompatibility.hostVersion; + useEffect(() => { + if (!id || isResolving || !host) return; + setDraftAttachmentHome(workspaceDraftKey(id), cloud ? "cloud" : "host"); + }, [id, isResolving, host, cloud]); const { renameWorkspace, deleteWorkspace, copyId, copyLink, shareWorkspace } = useWorkspaceHeaderActions(workspace, host); const pinned = usePinnedWorkspacesStore((state) => @@ -770,35 +784,43 @@ export function WorkspaceScreen() { // separates and delays the Enter, and frames the text as a bracketed paste // only when the running program actually has that mode on. const handleSubmit = useCallback( - async (text: string, attachmentFileIds: string[] = []) => { + async (text: string, attachments: PromptInputAttachmentItem[] = []) => { if (!hostUrl || !activeTerminalId || !id) { throw new Error("Terminal is not connected"); } if (activeIsChat) { if (!chatRef.current) throw new Error("Chat is not connected"); - // A cloud box resolves only the files attached to it. - if (cloud && attachmentFileIds.length > 0) { - await apiClient.cloudWorkspace.attachFiles.mutate({ - id, - fileIds: attachmentFileIds, + const host = getHostServiceClientByUrl(hostUrl); + const home = cloud ? "cloud" : "host"; + const parts = await chatAttachmentParts({ + home, + readsParts: hostReadsAttachmentParts(hostVersion), + files: toAttachmentFiles(attachments), + deps: { + awaitUploads: () => + awaitAttachmentUploads(workspaceDraftKey(id), attachments), + // A cloud box resolves only the files attached to it. + attachFiles: (fileIds) => + apiClient.cloudWorkspace.attachFiles.mutate({ id, fileIds }), + importFromCloud: (fileIds) => + host.attachments.importFromCloud.mutate({ fileIds }), + hostUpload: (input) => host.attachments.upload.mutate(input), + }, + }).catch((error: unknown) => { + posthog.capture("attachments_send_failed", { + surface: "chat", + home, + error: rawErrorMessage(error), + }); + throw error; + }); + if (parts.length > 0) + posthog.capture("attachments_sent", { + surface: "chat", + home, + count: parts.length, }); - } - const imported = - attachmentFileIds.length > 0 - ? await getHostServiceClientByUrl( - hostUrl, - ).attachments.importFromCloud.mutate({ - fileIds: attachmentFileIds, - }) - : []; - await chatRef.current.send( - text, - imported.map((entry) => ({ - attachmentId: entry.attachmentId, - name: entry.originalFilename ?? "attachment", - mimeType: entry.mediaType, - })), - ); + await chatRef.current.send(text, parts); composerRef.current?.blur(); return; } @@ -808,7 +830,7 @@ export function WorkspaceScreen() { text, }); }, - [hostUrl, activeTerminalId, id, activeIsChat, cloud], + [hostUrl, activeTerminalId, id, activeIsChat, cloud, hostVersion], ); const handleQuickKey = useCallback( diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/UserMessageBubble.tsx b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/UserMessageBubble.tsx index 5c0db076fe2..cdf07812149 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/UserMessageBubble.tsx +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/UserMessageBubble.tsx @@ -1,6 +1,7 @@ import { Trans } from "@lingui/react/macro"; import { - parsePastedText, + attachmentDisplayName, + parseAttachmentTags, readBookkeeping, userMessageText, } from "@superset/chat/core"; @@ -41,10 +42,31 @@ export function UserMessageBubble({ const note = pending ? null : readBookkeeping(harness, raw); if (note) return {note.label}; - const { text, pastes } = parsePastedText(raw); - const attachments = content.flatMap((part) => - part.type === "attachment" ? [part] : [], - ); + const { + text, + attachments: tags, + pastedTexts: pastes, + } = parseAttachmentTags(raw); + const attachments = [ + ...content.flatMap((part) => + part.type === "attachment" && (part.fileId || part.attachmentId) + ? [ + { + key: part.fileId ?? part.attachmentId ?? part.name, + source: { fileId: part.fileId, attachmentId: part.attachmentId }, + name: part.name, + mimeType: part.mimeType, + }, + ] + : [], + ), + ...tags.map((tag) => ({ + key: tag.path, + source: {}, + name: attachmentDisplayName(tag), + mimeType: "", + })), + ]; const wide = attachments.length > 0 || pastes.length > 0; const failed = pending?.failed === true; return ( @@ -72,19 +94,19 @@ export function UserMessageBubble({ {attachments.map((attachment) => isViewableImage(attachment.mimeType) ? ( ) : ( ), )} diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentFileCard/AttachmentFileCard.tsx b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentFileCard/AttachmentFileCard.tsx index 9d2e4820425..51911e26645 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentFileCard/AttachmentFileCard.tsx +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentFileCard/AttachmentFileCard.tsx @@ -5,24 +5,27 @@ import { FileText } from "lucide-react-native"; import { View } from "react-native"; import { Icon } from "@/components/ui/icon"; import { Text } from "@/components/ui/text"; -import { useAttachmentFile } from "../../hooks/useAttachmentFile"; +import { + type AttachmentSource, + useAttachmentFile, +} from "../../hooks/useAttachmentFile"; const GLYPH_SIZE = 36; export function AttachmentFileCard({ - attachmentId, + source, hostUrl, name, mediaType, }: { - attachmentId: string; + source: AttachmentSource; hostUrl: string | undefined; name: string; mediaType: string; }) { const { data: uri } = useAttachmentFile({ hostUrl, - attachmentId, + source, name, mediaType, }); diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentThumbnail/AttachmentThumbnail.tsx b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentThumbnail/AttachmentThumbnail.tsx index ece7b1ba74c..acfe21e4038 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentThumbnail/AttachmentThumbnail.tsx +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatRowView/components/UserMessageBubble/components/AttachmentThumbnail/AttachmentThumbnail.tsx @@ -1,31 +1,34 @@ import { presentImage } from "@superset/composer"; import { Image } from "expo-image"; import { Pressable } from "react-native"; -import { useAttachmentFile } from "../../hooks/useAttachmentFile"; +import { + type AttachmentSource, + useAttachmentFile, +} from "../../hooks/useAttachmentFile"; import { AttachmentFileCard } from "../AttachmentFileCard"; export function AttachmentThumbnail({ - attachmentId, + source, hostUrl, name, mediaType, }: { - attachmentId: string; + source: AttachmentSource; hostUrl: string | undefined; name: string; mediaType: string; }) { const { data: uri, isError } = useAttachmentFile({ hostUrl, - attachmentId, + source, name, mediaType, }); - if (isError || !hostUrl) { + if (isError || (!source.fileId && !hostUrl)) { return ( { - if (!hostUrl) throw new Error("no host"); const directory = new Directory(Paths.cache, "sent-attachments"); directory.create({ idempotent: true }); const file = new File( directory, - `${attachmentId}.${extensionOf(name, mediaType)}`, + `${fileId ?? attachmentId}.${extensionOf(name, mediaType)}`, ); - if (!file.exists) { - const { data } = await getHostServiceClientByUrl( - hostUrl, - ).attachments.read.query({ attachmentId }); - file.write(data, { encoding: "base64" }); + if (file.exists) return file.uri; + if (fileId) { + const [resolved] = await apiClient.attachment.resolveEach.mutate({ + fileIds: [fileId], + }); + if (!resolved || !("url" in resolved)) + throw new Error("Attachment is gone"); + await File.downloadFileAsync(resolved.url, file); + return file.uri; } + if (!hostUrl || !attachmentId) throw new Error("no host"); + const { data } = await getHostServiceClientByUrl( + hostUrl, + ).attachments.read.query({ attachmentId }); + file.write(data, { encoding: "base64" }); return file.uri; }, }); diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatSessionView/ChatSessionView.tsx b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatSessionView/ChatSessionView.tsx index c885b24a5a4..bb0e2783d3e 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatSessionView/ChatSessionView.tsx +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/components/ChatSessionView/ChatSessionView.tsx @@ -28,6 +28,7 @@ import { import { ActionSheetIOS, Alert, Pressable, View } from "react-native"; import { Conversation } from "@/components/ai-elements/conversation"; import { Text } from "@/components/ui/text"; +import type { ChatAttachmentPart } from "@/lib/attachments/chatParts"; import { type ChatHost, createChatSessionClient, @@ -74,11 +75,7 @@ function activityTexts( ); } -export interface ChatAttachment { - attachmentId: string; - name: string; - mimeType: string; -} +export type ChatAttachment = Omit; export interface ChatSessionViewHandle { send: (text: string, attachments?: ChatAttachment[]) => Promise; @@ -346,8 +343,8 @@ export const ChatSessionView = forwardRef< chat.sendPrompt([ ...(text.trim() ? [{ type: "text" as const, text }] : []), ...attachments.map((attachment) => ({ - type: "attachment" as const, ...attachment, + type: "attachment" as const, })), ]); }, diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/TerminalComposer.tsx b/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/TerminalComposer.tsx index cdfda8b6d78..2a1b66ad47c 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/TerminalComposer.tsx +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/TerminalComposer.tsx @@ -11,8 +11,10 @@ import { import type { SlashCommand } from "@superset/shared/slash-commands"; import { forwardRef, useImperativeHandle, useRef, useState } from "react"; import { Alert, View } from "react-native"; -import type { PromptInputMessage } from "@/components/ai-elements/prompt-input"; -import { awaitAttachmentUploads } from "@/lib/attachments/upload"; +import type { + PromptInputAttachmentItem, + PromptInputMessage, +} from "@/components/ai-elements/prompt-input"; import { errorCopy } from "@/lib/errors"; import { posthog } from "@/lib/posthog"; import { useAttachmentsSheet } from "@/screens/(authenticated)/hooks/useAttachmentsSheet"; @@ -40,7 +42,10 @@ interface TerminalComposerProps { workspaceId: string; placeholder?: string; /** Submit the current draft to the PTY. Rejects if it never got there. */ - onSubmit: (text: string, attachmentFileIds?: string[]) => Promise; + onSubmit: ( + text: string, + attachments?: PromptInputAttachmentItem[], + ) => Promise; onQuickKey: (key: TerminalQuickKey) => void; /** Where attachments land; null while the workspace or host is unresolved. */ attachmentTarget: TerminalAttachmentTarget | null; @@ -95,7 +100,7 @@ interface TerminalComposerProps { onModeSelect?: (modeId: string) => void; canStop?: boolean; onStop?: () => void; - /** Hand attachments over as uploaded file ids, not as worktree paths. */ + /** Hand attachments over as they are, not as worktree paths. */ sendsAttachments?: boolean; } @@ -191,7 +196,7 @@ export const TerminalComposer = forwardRef< const submit = async ({ text, attachments: files }: PromptInputMessage) => { let body = text; - let attachmentFileIds: string[] | undefined; + let sent: PromptInputAttachmentItem[] | undefined; // The tray is shared across tabs, so files attached in an agent session // are still there after switching to a plain shell — which would execute // the paths rather than read them. `allowAttachments` has to gate the @@ -206,16 +211,7 @@ export const TerminalComposer = forwardRef< return; } if (sendsAttachments) { - attachmentFileIds = await awaitAttachmentUploads(draftKey, files).catch( - (cause: unknown) => { - Alert.alert( - t({ message: "Could not attach files" }), - errorCopy(cause), - ); - return undefined; - }, - ); - if (!attachmentFileIds) return; + sent = files; } else { // A PTY takes bytes, not files: the agent gets the attachments as // worktree-relative paths appended to the message. The hook alerts @@ -229,7 +225,7 @@ export const TerminalComposer = forwardRef< } setIsSubmitting(true); try { - await onSubmit(body, attachmentFileIds); + await onSubmit(body, sent); posthog.capture("terminal_rich_input_submitted", { workspace_id: workspaceId, message_length: text.trim().length, diff --git a/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/hooks/useWriteTerminalAttachments/useWriteTerminalAttachments.ts b/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/hooks/useWriteTerminalAttachments/useWriteTerminalAttachments.ts index f6eeba243d7..a259962d80f 100644 --- a/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/hooks/useWriteTerminalAttachments/useWriteTerminalAttachments.ts +++ b/apps/mobile/screens/(authenticated)/workspace/[id]/components/TerminalComposer/hooks/useWriteTerminalAttachments/useWriteTerminalAttachments.ts @@ -4,7 +4,11 @@ import { useMutation } from "@tanstack/react-query"; import { Alert } from "react-native"; import type { PromptInputAttachmentItem } from "@/components/ai-elements/prompt-input"; import { asAttachmentError } from "@/lib/attachments/errors"; -import { awaitAttachmentUploads } from "@/lib/attachments/upload"; +import { + awaitAttachmentUploads, + toAttachmentFiles, +} from "@/lib/attachments/upload"; +import { writeAttachmentsToWorktree } from "@/lib/attachments/worktreeWrite"; import { errorCopy } from "@/lib/errors"; import { getHostServiceClientByUrl } from "@/lib/host-service/client"; import { apiClient } from "@/lib/trpc/client"; @@ -28,30 +32,50 @@ interface WriteArgs { * worktree-relative paths. A live PTY only takes bytes, so paths are how an * attachment reaches the agent. * - * The bytes go device → cloud storage → host, never through the relay: a - * relay request body is buffered whole in a Cloudflare Worker and refused - * above 100 MB by its edge, which is what made a large attachment fail with - * an unparseable response rather than an error anyone could read. - * - * By here the upload is usually finished — it started when the file was - * attached — so this waits only on what the message outpaced. + * A box gets the bytes device → cloud storage → box; the upload started when + * the file was attached. A machine someone owns gets them in the request, + * under the inline cap, so they never reach our storage. */ export function useWriteTerminalAttachments() { return useMutation({ mutationFn: async ({ target, attachments }: WriteArgs) => { if (attachments.length === 0) return []; + if (!target.isCloud) { + const client = getHostServiceClientByUrl(target.hostUrl); + return writeAttachmentsToWorktree(toAttachmentFiles(attachments), { + worktreePath: async () => { + const workspace = await client.workspace.get.query({ + id: target.workspaceId, + }); + if (!workspace?.worktreePath) + throw new Error("Workspace path not found"); + return workspace.worktreePath; + }, + createDirectory: (absolutePath) => + client.filesystem.createDirectory.mutate({ + workspaceId: target.workspaceId, + absolutePath, + recursive: true, + }), + writeFile: async ({ absolutePath, content }) => + (await client.filesystem.writeFile.mutate({ + workspaceId: target.workspaceId, + absolutePath, + content, + options: { create: true, overwrite: false }, + })) ?? { ok: true }, + }); + } const fileIds = await awaitAttachmentUploads( target.draftKey, attachments, ); const client = getHostServiceClientByUrl(target.hostUrl); try { - if (target.isCloud) { - await apiClient.cloudWorkspace.attachFiles.mutate({ - id: target.workspaceId, - fileIds, - }); - } + await apiClient.cloudWorkspace.attachFiles.mutate({ + id: target.workspaceId, + fileIds, + }); const { paths } = await client.attachments.materializeIntoWorkspace.mutate({ workspaceId: target.workspaceId, diff --git a/docs/cloud-sandbox-mismatches.md b/docs/cloud-sandbox-mismatches.md index ca7a1363ade..be60431554f 100644 --- a/docs/cloud-sandbox-mismatches.md +++ b/docs/cloud-sandbox-mismatches.md @@ -371,13 +371,36 @@ forwards Ctrl+V and lets the TUI (Claude Code, Codex) read the image from the OS clipboard — of the machine the PTY runs on. A sandbox (or any relay-reached host) never holds the user's local screenshot, so the paste silently did nothing or surfaced "Failed to paste image". Fixed renderer-side: -for non-local hosts the desktop ships the clipboard bytes over -`filesystem.writeFile` into the shared `.superset/attachments/` worktree dir -(the same convention the agent-launch terminal adapter and the mobile -composer use — mobile proved the pattern) and pastes the worktree-relative -path instead (`setImagePasteOverride` in the terminal runtime registry). -Chosen over a new host endpoint because deployed sandboxes never update -their baked host-service. +for non-local hosts the desktop writes the clipboard files into the worktree +and pastes their worktree-relative paths instead (`setImagePasteOverride` in +the terminal runtime registry, `useSendAttachments` in the pane registry). +The bytes go where the workspace lives. A box gets them through storage: +`attachment.createUpload`, a presigned PUT, `cloudWorkspace.attachFiles`, +then `attachments.materializeIntoWorkspace` on the box. A relay-reached +machine gets them as base64 `filesystem.writeFile`, capped at +`MAX_INLINE_ATTACHMENT_BYTES`, so they never reach our servers. A workspace +on the same machine as the desktop gets them from the desktop's main process +(`attachments.writeIntoWorktree`), which copies a file from disk with no cap. +Chat attachments follow the same rule as parts: a `fileId` for a box, an +`attachmentId` in the host's store otherwise. A file on this machine too big +for a part goes as a copied path instead. + +**The ingress drops an upload the host answers early.** tRPC's streamed batch +(`httpBatchStreamLink`, `trpc-accept: application/jsonl`) returns its response +head before it has read the request body. Behind a Vercel sandbox's ingress +(`sb-*.vercel.run`, which the gate forwards to) that early response ends the +exchange: the rest of the upload is dropped, the procedure never runs, and the +client sees a stream that ends after the head line — "value$1 is not iterable" +in tRPC's consumer. It is a race, not a size limit: a 500 KB body on a home +uplink loses it about half the time, a 1 MB body on a datacenter link wins +it. This is why shipping file bytes through `filesystem.writeFile` broke +(SUPER-2658) and why attachments go through storage instead. host-service now +buffers every `/trpc/*` body before handing it to tRPC, so no response starts +before the request is complete. A box runs that host-service from its next +boot (see "A box's host-service is as new as its last boot"); one that never +sleeps keeps the race until it restarts. Reproducing with curl: pass +`-H "Expect:"` — curl's automatic `Expect: 100-continue` on bodies ≥1 MB +masks the bug, and browsers never send it. **A URL launcher succeeds and reaches nobody.** The image ships `xdg-utils` (`packages/sandbox/bundle/rootfs/usr/local/share/superset/desktop.Aptfile`) @@ -425,6 +448,19 @@ missing. The CLI bundle has the same gap. ## Lifecycle +**A box's host-service is as new as its last boot.** A sandbox bundle release +repins every live environment (`environments.bundleSha`, set by +`packages/sandbox/src/environments/release.ts`), and every wake builds the +box's claim from its environment (`wakeCloudWorkspace` → `buildSandboxClaim`). +When the box boots, `superset-boot` installs the pinned bundle if its hash +differs from the one installed. So a cold wake, a restart or a new box runs +the current host-service. A warm resume does not boot, and a box that never +sleeps keeps the host-service it last booted with. Do not assume a box is +frozen at the bundle it was provisioned with, and do not assume it is current +either: gate a new host feature on the version the box reports +(`health.check`), the same way as a remote host. The chat attachment parts +floor (`ATTACHMENT_PARTS_MIN_HOST_VERSION`) works like this. + **A tag-filtered sandbox list is not sorted by status time. Fixed.** The usage reconciler scans by `statusUpdatedAt` and stops at entries older than the maximum session length. Vercel's server-side tag filter uses creation-order pagination diff --git a/packages/chat-runtime/src/harness/acp/acpAdapter.test.ts b/packages/chat-runtime/src/harness/acp/acpAdapter.test.ts index 80a92b267a8..986dae4d006 100644 --- a/packages/chat-runtime/src/harness/acp/acpAdapter.test.ts +++ b/packages/chat-runtime/src/harness/acp/acpAdapter.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it, jest } from "bun:test"; import { spawn } from "node:child_process"; import type { Item } from "@superset/chat/protocol"; import { AGENT_DEFAULT_MODE, wrapHiddenText } from "@superset/chat/protocol"; -import type { AdapterEvent } from "../types"; +import type { AdapterEvent, ResolveAttachment } from "../types"; import { AcpAdapter, type AcpAdapterOptions, @@ -5614,11 +5614,7 @@ describe("AcpAdapter config options", () => { describe("AcpAdapter attachments", () => { const startWith = ( agent: FakeAcpAgent, - resolveAttachment: (id: string) => Promise<{ - path: string; - mimeType: string; - data: string; - } | null>, + resolveAttachment: ResolveAttachment, ) => { const adapter = new AcpAdapter({ command: "fake", @@ -5712,6 +5708,25 @@ describe("AcpAdapter attachments", () => { ); expect(told).toBe(true); }); + + it("hands the resolver the whole part, so a cloud part resolves by its fileId", async () => { + const agent = new FakeAcpAgent(); + const asked: unknown[] = []; + const { adapter } = startWith(agent, async (part) => { + asked.push(part); + return null; + }); + await flush(); + const part = { + type: "attachment" as const, + fileId: "8c1f6f8e-3a2b-4c5d-9e0f-112233445566", + name: "shot.png", + mimeType: "image/png", + }; + adapter.prompt([part]); + await flush(); + expect(asked).toEqual([part]); + }); }); describe("AcpAdapter images", () => { diff --git a/packages/chat-runtime/src/harness/acp/acpAdapter.ts b/packages/chat-runtime/src/harness/acp/acpAdapter.ts index 49a2cb77221..79cefba77f9 100644 --- a/packages/chat-runtime/src/harness/acp/acpAdapter.ts +++ b/packages/chat-runtime/src/harness/acp/acpAdapter.ts @@ -26,6 +26,8 @@ import type { AdapterEvent, HarnessAdapter, HarnessStartOptions, + ResolveAttachment, + ResolvedAttachment, } from "../types"; import { type RefusedWindow, @@ -181,11 +183,7 @@ type V2Turn = { idle?: AcpStateUpdate & { seq: number }; }; -export type AcpAttachment = { - path: string; - mimeType: string; - data: string; -}; +export type AcpAttachment = ResolvedAttachment; /** `path` is relative to the session cwd. */ export type AcpStoredImage = { path: string }; @@ -233,7 +231,7 @@ export type AcpAdapterOptions = SpawnAcpOptions & { shellPollMs?: number; startupTimeoutMs?: number; requestTimeoutMs?: number; - resolveAttachment?: (attachmentId: string) => Promise; + resolveAttachment?: ResolveAttachment; /** Without it, images the agent sends are dropped. */ storeImage?: ( image: AcpImageSource, @@ -2228,7 +2226,7 @@ export class AcpAdapter implements HarnessAdapter { continue; } const attachment = await this.options - .resolveAttachment?.(entry.attachmentId) + .resolveAttachment?.(entry) .catch(() => null); if (!attachment) { dropped.push(entry.name); diff --git a/packages/chat-runtime/src/harness/attachedFiles/attachedFiles.test.ts b/packages/chat-runtime/src/harness/attachedFiles/attachedFiles.test.ts new file mode 100644 index 00000000000..f687d34139d --- /dev/null +++ b/packages/chat-runtime/src/harness/attachedFiles/attachedFiles.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, test } from "bun:test"; +import { attachedFilesBlock } from "./attachedFiles"; + +describe("attachedFilesBlock", () => { + test("lists each file by the name it was attached with, then its path", () => { + expect( + attachedFilesBlock([ + { name: "spec.pdf", path: "/store/a1/a1.pdf" }, + { name: "notes.txt", path: "/store/b2/b2.txt" }, + ]), + ).toBe( + "# Attached files\n\nThe user attached these files. They are available on this host at:\n\n- spec.pdf: /store/a1/a1.pdf\n- notes.txt: /store/b2/b2.txt", + ); + }); +}); diff --git a/packages/chat-runtime/src/harness/attachedFiles/attachedFiles.ts b/packages/chat-runtime/src/harness/attachedFiles/attachedFiles.ts new file mode 100644 index 00000000000..5d64423900b --- /dev/null +++ b/packages/chat-runtime/src/harness/attachedFiles/attachedFiles.ts @@ -0,0 +1,10 @@ +/** + * Store files are named by id, so a bare path hands the agent a UUID; the + * name the user gave it goes beside the path. + */ +export function attachedFilesBlock( + files: { name: string; path: string }[], +): string { + const lines = files.map((file) => `- ${file.name}: ${file.path}`); + return `# Attached files\n\nThe user attached these files. They are available on this host at:\n\n${lines.join("\n")}`; +} diff --git a/packages/chat-runtime/src/harness/attachedFiles/index.ts b/packages/chat-runtime/src/harness/attachedFiles/index.ts new file mode 100644 index 00000000000..61b2cda2944 --- /dev/null +++ b/packages/chat-runtime/src/harness/attachedFiles/index.ts @@ -0,0 +1 @@ +export { attachedFilesBlock } from "./attachedFiles"; diff --git a/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.test.ts b/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.test.ts index 7ce57aa227f..54087c67b40 100644 --- a/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.test.ts +++ b/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.test.ts @@ -1,5 +1,7 @@ import { describe, expect, test } from "bun:test"; -import type { AdapterEvent } from "../../types"; +import type { SDKUserMessage } from "@anthropic-ai/claude-agent-sdk"; +import { attachedFilesBlock } from "../../attachedFiles"; +import type { AdapterEvent, ResolveAttachment } from "../../types"; import { ClaudeAdapter, type ClaudeQuery, @@ -268,3 +270,129 @@ describe("ClaudeAdapter permission modes", () => { expect(reverted.value).toMatchObject({ session: { modeId: "default" } }); }); }); + +describe("ClaudeAdapter attachments", () => { + function capturePrompts(resolveAttachment: ResolveAttachment) { + const sent: SDKUserMessage[] = []; + const stream: ClaudeSession = { + async *[Symbol.asyncIterator]() { + await new Promise(() => {}); + }, + }; + const adapter = new ClaudeAdapter({ + resolveAttachment, + query: ({ prompt }) => { + void (async () => { + for await (const message of prompt as AsyncIterable) + sent.push(message); + })(); + return stream; + }, + }); + adapter.start({ cwd: "/workspace" }); + return { adapter, sent }; + } + + const flush = () => new Promise((resolve) => setTimeout(resolve, 0)); + const part = (name: string, mimeType: string) => ({ + type: "attachment" as const, + attachmentId: name, + name, + mimeType, + }); + + test("sends an image as an image block", async () => { + const { adapter, sent } = capturePrompts(async () => ({ + path: "/store/a/a.png", + mimeType: "image/png", + data: "cG5n", + })); + adapter.prompt([ + { type: "text", text: "what is this" }, + part("shot.png", "image/png"), + ]); + await flush(); + expect(sent.map((message) => message.message.content)).toEqual([ + [ + { type: "text", text: "what is this" }, + { + type: "image", + source: { type: "base64", media_type: "image/png", data: "cG5n" }, + }, + ], + ]); + }); + + test("hands a non-image over as its name and path", async () => { + const { adapter, sent } = capturePrompts(async () => ({ + path: "/store/b/b.pdf", + mimeType: "application/pdf", + data: "cGRm", + })); + adapter.prompt([part("spec.pdf", "application/pdf")]); + await flush(); + expect(sent[0]?.message.content).toEqual([ + { + type: "text", + text: attachedFilesBlock([ + { name: "spec.pdf", path: "/store/b/b.pdf" }, + ]), + }, + ]); + }); + + test("drops an empty text part, which the API refuses as a block", async () => { + const { adapter, sent } = capturePrompts(async () => ({ + path: "/store/a/a.png", + mimeType: "image/png", + data: "cG5n", + })); + adapter.prompt([{ type: "text", text: "" }, part("shot.png", "image/png")]); + await flush(); + expect(sent[0]?.message.content).toEqual([ + { + type: "image", + source: { type: "base64", media_type: "image/png", data: "cG5n" }, + }, + ]); + }); + + test("tells the agent which file it could not read", async () => { + const { adapter, sent } = capturePrompts(async () => null); + adapter.prompt([part("gone.png", "image/png")]); + await flush(); + expect(sent[0]?.message.content).toEqual([ + { type: "text", text: "[gone.png: could not be read]" }, + ]); + }); + + test("a prompt sent while an attachment resolves still goes second", async () => { + let release: () => void = () => {}; + const { adapter, sent } = capturePrompts( + () => + new Promise((resolve) => { + release = () => + resolve({ + path: "/store/c/c.png", + mimeType: "image/png", + data: "", + }); + }), + ); + adapter.prompt([part("first.png", "image/png")]); + adapter.prompt([{ type: "text", text: "second" }]); + await flush(); + expect(sent).toEqual([]); + release(); + await flush(); + expect(sent.map((message) => message.message.content)).toEqual([ + [ + { + type: "image", + source: { type: "base64", media_type: "image/png", data: "" }, + }, + ], + [{ type: "text", text: "second" }], + ]); + }); +}); diff --git a/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts b/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts index 07782ee66e4..b282e64da6b 100644 --- a/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts +++ b/packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts @@ -8,10 +8,12 @@ import type { Decision, UserContent, } from "@superset/chat/protocol"; +import { attachedFilesBlock } from "../../attachedFiles"; import type { AdapterEvent, HarnessAdapter, HarnessStartOptions, + ResolveAttachment, } from "../../types"; import { ClaudeTranslator } from "../translateStream"; @@ -77,6 +79,7 @@ export type ClaudeAdapterOptions = { query: ClaudeQuery; pathToClaudeCodeExecutable?: string; launch?: () => Promise; + resolveAttachment?: ResolveAttachment; now?: () => number; mintId?: () => string; }; @@ -168,12 +171,31 @@ class PromptQueue { } } +type SdkUserContent = SDKUserMessage["message"]["content"]; +type SdkContentBlock = Exclude[number]; +type ClaudeImageType = "image/png" | "image/jpeg" | "image/gif" | "image/webp"; + +const CLAUDE_IMAGE_TYPES = new Set([ + "image/png", + "image/jpeg", + "image/gif", + "image/webp", +] satisfies ClaudeImageType[]); + function promptText(content: UserContent[]): string { return content - .map((part) => (part.type === "text" ? part.text : `[${part.name}]`)) + .map((part) => (part.type === "text" ? part.text : "")) .join("\n"); } +function userMessage(content: SdkUserContent): SDKUserMessage { + return { + type: "user", + message: { role: "user", content }, + parent_tool_use_id: null, + }; +} + export class ClaudeAdapter implements HarnessAdapter { private readonly events = new EventQueue(); private readonly prompts = new PromptQueue(); @@ -184,6 +206,7 @@ export class ClaudeAdapter implements HarnessAdapter { private sessionId: string | null = null; private modeId: ClaudePermissionMode = "default"; private pump: Promise | null = null; + private resolvingPrompt: Promise | null = null; private disposed = false; constructor(private readonly options: ClaudeAdapterOptions) {} @@ -256,13 +279,59 @@ export class ClaudeAdapter implements HarnessAdapter { } prompt(content: UserContent[]): void { - this.prompts.push({ - type: "user", - message: { role: "user", content: promptText(content) }, - parent_tool_use_id: null, + const hasAttachment = content.some((part) => part.type === "attachment"); + if (!hasAttachment && !this.resolvingPrompt) { + this.prompts.push(userMessage(promptText(content))); + return; + } + const blocks = this.contentBlocks(content); + const queued = (this.resolvingPrompt ?? Promise.resolve()) + .then(() => blocks) + .then((resolved) => this.prompts.push(userMessage(resolved))); + this.resolvingPrompt = queued; + void queued.finally(() => { + if (this.resolvingPrompt === queued) this.resolvingPrompt = null; }); } + private async contentBlocks( + content: UserContent[], + ): Promise { + const blocks: SdkContentBlock[] = []; + for (const part of content) { + if (part.type === "text") { + if (part.text) blocks.push({ type: "text", text: part.text }); + continue; + } + const file = await ( + this.options.resolveAttachment?.(part) ?? Promise.resolve(null) + ).catch(() => null); + if (!file) { + blocks.push({ + type: "text", + text: `[${part.name}: could not be read]`, + }); + continue; + } + blocks.push( + CLAUDE_IMAGE_TYPES.has(file.mimeType) + ? { + type: "image", + source: { + type: "base64", + media_type: file.mimeType as ClaudeImageType, + data: file.data, + }, + } + : { + type: "text", + text: attachedFilesBlock([{ name: part.name, path: file.path }]), + }, + ); + } + return blocks; + } + cancelTurn(): void { const interrupt = this.session?.interrupt; if (!interrupt) { diff --git a/packages/chat-runtime/src/harness/claude/createClaudeAdapter/createClaudeAdapter.ts b/packages/chat-runtime/src/harness/claude/createClaudeAdapter/createClaudeAdapter.ts index 79124c60d72..3b7ed020ab3 100644 --- a/packages/chat-runtime/src/harness/claude/createClaudeAdapter/createClaudeAdapter.ts +++ b/packages/chat-runtime/src/harness/claude/createClaudeAdapter/createClaudeAdapter.ts @@ -10,10 +10,12 @@ import { ClaudeAdapter } from "../claudeAdapter"; export function createClaudeAdapter(options?: { pathToClaudeCodeExecutable?: string; launch?: ClaudeAdapterOptions["launch"]; + resolveAttachment?: ClaudeAdapterOptions["resolveAttachment"]; }): HarnessAdapter { return new ClaudeAdapter({ query, pathToClaudeCodeExecutable: options?.pathToClaudeCodeExecutable, launch: options?.launch, + resolveAttachment: options?.resolveAttachment, }); } diff --git a/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.test.ts b/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.test.ts index 4ccab1c5151..c1c3641f299 100644 --- a/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.test.ts +++ b/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.test.ts @@ -6,9 +6,11 @@ import type { SessionState, ToolCall, Turn, + UserContent, } from "@superset/chat/protocol"; import { itemSchema, turnSchema } from "@superset/chat/protocol"; -import type { AdapterEvent } from "../../types"; +import { attachedFilesBlock } from "../../attachedFiles"; +import type { AdapterEvent, ResolveAttachment } from "../../types"; import { FixturePlayer } from "../fixturePlayer"; import type { CodexFixtureName } from "../fixtures"; import { fixtureCwd, loadCodexFixture } from "../fixtures"; @@ -18,6 +20,8 @@ const FIXED_NOW = 1_785_000_000_000; type ReplayOptions = { onEvent?(event: AdapterEvent, adapter: CodexAdapter): void; + prompt?: UserContent[]; + resolveAttachment?: ResolveAttachment; }; type ReplayResult = { @@ -40,6 +44,7 @@ async function replay( let minted = 0; const adapter = new CodexAdapter({ createTransport: (_spawnOptions, handlers) => player.transport(handlers), + resolveAttachment: options.resolveAttachment, now: () => FIXED_NOW, mintId: () => { minted += 1; @@ -55,7 +60,7 @@ async function replay( } })(); - adapter.prompt([{ type: "text", text: "fixture prompt" }]); + adapter.prompt(options.prompt ?? [{ type: "text", text: "fixture prompt" }]); const deadline = Date.now() + 5000; while (!player.exhausted) { @@ -307,3 +312,66 @@ describe("codexAdapter fixtures", () => { expect(settled.text.endsWith("36")).toBe(true); }); }); + +describe("codexAdapter attachments", () => { + const part = (name: string, mimeType: string) => ({ + type: "attachment" as const, + attachmentId: name, + name, + mimeType, + }); + + async function turnInput( + prompt: UserContent[], + resolveAttachment: ResolveAttachment, + ): Promise { + const { player } = await replay("text", { prompt, resolveAttachment }); + return (player.paramsSent("turn/start")[0] as { input: unknown }).input; + } + + test("an image goes to app-server as a localImage", async () => { + expect( + await turnInput( + [{ type: "text", text: "look" }, part("shot.png", "image/png")], + async () => ({ + path: "/store/a/a.png", + mimeType: "image/png", + data: "", + }), + ), + ).toEqual([ + { type: "text", text: "look", text_elements: [] }, + { type: "localImage", path: "/store/a/a.png" }, + ]); + }); + + test("a non-image goes as its name and path", async () => { + expect( + await turnInput([part("spec.pdf", "application/pdf")], async () => ({ + path: "/store/b/b.pdf", + mimeType: "application/pdf", + data: "", + })), + ).toEqual([ + { + type: "text", + text: attachedFilesBlock([ + { name: "spec.pdf", path: "/store/b/b.pdf" }, + ]), + text_elements: [], + }, + ]); + }); + + test("an unreadable attachment is named, not dropped", async () => { + expect( + await turnInput([part("gone.png", "image/png")], async () => null), + ).toEqual([ + { + type: "text", + text: "[gone.png: could not be read]", + text_elements: [], + }, + ]); + }); +}); diff --git a/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.ts b/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.ts index 1291d669ae0..ceb0c7b2d9f 100644 --- a/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.ts +++ b/packages/chat-runtime/src/harness/codex/codexAdapter/codexAdapter.ts @@ -4,16 +4,20 @@ import type { Decision, Item, SessionState, + TextElement, ToolCall, Turn, UserContent, } from "@superset/chat/protocol"; import { isKnownItem } from "@superset/chat/protocol"; +import { attachedFilesBlock } from "../../attachedFiles"; import { EventQueue } from "../../eventQueue"; import type { AdapterEvent, + AttachmentPart, HarnessAdapter, HarnessStartOptions, + ResolveAttachment, } from "../../types"; import { mapThreadItem } from "../mapThreadItem"; import type { @@ -109,6 +113,7 @@ export type CodexAdapterOptions = SpawnCodexOptions & { launch?: () => Promise>; minVersion?: string; clientVersion?: string; + resolveAttachment?: ResolveAttachment; now?: () => number; mintId?: () => string; createTransport?( @@ -126,6 +131,7 @@ export class CodexAdapter implements HarnessAdapter { private pendingTurnStart = false; private cancelRequested = false; private readonly queuedInput: unknown[][] = []; + private resolvingPrompt: Promise | null = null; private client: CodexRpcClient | null = null; private threadId: string | null = null; private cwd = process.cwd(); @@ -153,7 +159,22 @@ export class CodexAdapter implements HarnessAdapter { } prompt(content: UserContent[]): void { - const input = this.toCodexInput(content); + const hasAttachment = content.some((part) => part.type === "attachment"); + if (!hasAttachment && !this.resolvingPrompt) { + this.deliver(this.toCodexInput(content)); + return; + } + const input = this.toCodexInputWithAttachments(content); + const queued = (this.resolvingPrompt ?? Promise.resolve()) + .then(() => input) + .then((resolved) => this.deliver(resolved)); + this.resolvingPrompt = queued; + void queued.finally(() => { + if (this.resolvingPrompt === queued) this.resolvingPrompt = null; + }); + } + + private deliver(input: unknown[]): void { if (!this.threadId || !this.client) { this.queuedInput.push(input); return; @@ -659,31 +680,39 @@ export class CodexAdapter implements HarnessAdapter { } private toCodexInput(content: UserContent[]): unknown[] { + return content.flatMap((entry) => + entry.type === "text" ? [codexTextInput(entry.text, entry.elements)] : [], + ); + } + + private async toCodexInputWithAttachments( + content: UserContent[], + ): Promise { const input: unknown[] = []; - let skippedAttachment = false; for (const entry of content) { - if (entry.type === "text") { - input.push({ - type: "text", - text: entry.text, - text_elements: (entry.elements ?? []).map((element) => ({ - byteRange: element.byteRange, - placeholder: null, - })), - }); - continue; - } - skippedAttachment = true; - } - if (skippedAttachment) { - this.emitNotice( - "info", - "Attachments are not supported by the codex harness and were omitted", + input.push( + entry.type === "text" + ? codexTextInput(entry.text, entry.elements) + : await this.attachmentInput(entry), ); } return input; } + /** app-server's turn/start takes a `localImage` by path; anything else goes as a path in text. */ + private async attachmentInput(entry: AttachmentPart): Promise { + const file = await ( + this.options.resolveAttachment?.(entry) ?? Promise.resolve(null) + ).catch(() => null); + if (file?.mimeType.startsWith("image/")) + return { type: "localImage", path: file.path }; + return codexTextInput( + file + ? attachedFilesBlock([{ name: entry.name, path: file.path }]) + : `[${entry.name}: could not be read]`, + ); + } + private emitItem(item: Item, turnId: string): void { this.emit({ kind: "item", item, turnId }); } @@ -727,3 +756,17 @@ export function createCodexAdapter( ): HarnessAdapter { return new CodexAdapter(options); } + +function codexTextInput( + text: string, + elements: TextElement[] = [], +): Record { + return { + type: "text", + text, + text_elements: elements.map((element) => ({ + byteRange: element.byteRange, + placeholder: null, + })), + }; +} diff --git a/packages/chat-runtime/src/harness/codex/fixturePlayer/fixturePlayer.ts b/packages/chat-runtime/src/harness/codex/fixturePlayer/fixturePlayer.ts index 91bb1d1e639..8a4d3213e67 100644 --- a/packages/chat-runtime/src/harness/codex/fixturePlayer/fixturePlayer.ts +++ b/packages/chat-runtime/src/harness/codex/fixturePlayer/fixturePlayer.ts @@ -6,6 +6,7 @@ export class FixturePlayer { private handlers: CodexTransportHandlers | null = null; private pumping = false; private readonly sentMethods: string[] = []; + private readonly sentParams: { method: string; params: unknown }[] = []; constructor(private readonly frames: readonly RecordedFrame[]) {} @@ -13,6 +14,12 @@ export class FixturePlayer { return this.sentMethods; } + paramsSent(method: string): unknown[] { + return this.sentParams + .filter((sent) => sent.method === method) + .map((sent) => sent.params); + } + get exhausted(): boolean { return this.index >= this.frames.length; } @@ -29,8 +36,11 @@ export class FixturePlayer { } private onSend(line: string): void { - const sent = JSON.parse(line) as { method?: string }; - if (sent.method) this.sentMethods.push(sent.method); + const sent = JSON.parse(line) as { method?: string; params?: unknown }; + if (sent.method) { + this.sentMethods.push(sent.method); + this.sentParams.push({ method: sent.method, params: sent.params }); + } const next = this.frames[this.index]; if (next?.direction === "out") { diff --git a/packages/chat-runtime/src/harness/index.ts b/packages/chat-runtime/src/harness/index.ts index 7f66eeb0a06..ea1053e69b8 100644 --- a/packages/chat-runtime/src/harness/index.ts +++ b/packages/chat-runtime/src/harness/index.ts @@ -5,6 +5,7 @@ export type { AcpStoredImage, } from "./acp"; export { AcpAdapter, createAcpAdapter } from "./acp"; +export { attachedFilesBlock } from "./attachedFiles"; export { BackgroundTasks } from "./backgroundTasks"; export type { ClaudeAdapterOptions, @@ -22,7 +23,10 @@ export type { FakeHarnessScript, ScriptedEvent } from "./fake"; export { FakeHarness } from "./fake"; export type { AdapterEvent, + AttachmentPart, DiscoverNativeSessionsInput, HarnessAdapter, HarnessStartOptions, + ResolveAttachment, + ResolvedAttachment, } from "./types"; diff --git a/packages/chat-runtime/src/harness/types.ts b/packages/chat-runtime/src/harness/types.ts index b6f532ce226..2f0b5e88c36 100644 --- a/packages/chat-runtime/src/harness/types.ts +++ b/packages/chat-runtime/src/harness/types.ts @@ -14,6 +14,20 @@ export type AdapterEvent = | { kind: "turn"; turn: Turn } | { kind: "session"; session: Partial }; +export type AttachmentPart = Extract; + +/** `data` is an image's bytes, base64; empty for any other file, which goes by `path`. */ +export type ResolvedAttachment = { + path: string; + mimeType: string; + data: string; +}; + +/** Null when the bytes cannot be had: the adapter tells the agent so. */ +export type ResolveAttachment = ( + part: AttachmentPart, +) => Promise; + export type HarnessStartOptions = { cwd: string; modeId?: string; diff --git a/packages/chat-ui/src/components/AttachmentFileCard/AttachmentFileCard.tsx b/packages/chat-ui/src/components/AttachmentFileCard/AttachmentFileCard.tsx new file mode 100644 index 00000000000..46a76869ff5 --- /dev/null +++ b/packages/chat-ui/src/components/AttachmentFileCard/AttachmentFileCard.tsx @@ -0,0 +1,90 @@ +"use client"; + +import { cn } from "@superset/ui/utils"; +import { + FileArchiveIcon, + FileCode2Icon, + FileJson2Icon, + FileTextIcon, + ImageIcon, + Music2Icon, +} from "lucide-react"; +import type { JSX } from "react"; + +const CODE_EXTENSIONS = new Set([ + "ts", + "tsx", + "js", + "jsx", + "py", + "rs", + "go", + "rb", + "swift", + "css", + "html", + "sh", +]); +const DATA_EXTENSIONS = new Set(["json", "yaml", "yml", "toml", "lock"]); +const ARCHIVE_EXTENSIONS = new Set(["zip", "tar", "gz", "tgz", "7z", "rar"]); + +// Mime type first (audio, images demoted after a failed preview), then +// extension for the text-ish formats mime can't distinguish. +function fileTypeIcon(mediaType: string, extension: string): JSX.Element { + if (mediaType.startsWith("audio/")) + return ; + if (mediaType.startsWith("image/")) + return ; + const lowered = extension.toLowerCase(); + if (CODE_EXTENSIONS.has(lowered)) + return ; + if (DATA_EXTENSIONS.has(lowered)) + return ; + if (ARCHIVE_EXTENSIONS.has(lowered)) + return ; + return ; +} + +export type AttachmentFileCardProps = { + name: string; + mediaType: string; + onClick?: () => void; + className?: string; +}; + +export function AttachmentFileCard({ + name, + mediaType, + onClick, + className, +}: AttachmentFileCardProps) { + const dotIndex = name.lastIndexOf("."); + const hasExtension = dotIndex > 0 && dotIndex < name.length - 1; + const stem = hasExtension ? name.slice(0, dotIndex) : name; + const extension = hasExtension ? name.slice(dotIndex + 1).toUpperCase() : ""; + const Root = onClick ? "button" : "div"; + return ( + + {onClick && ( + + )} +
+ {fileTypeIcon(mediaType, extension)} +
+
+
{stem}
+ {extension && ( +
{extension}
+ )} +
+
+ ); +} diff --git a/packages/chat-ui/src/components/AttachmentFileCard/index.ts b/packages/chat-ui/src/components/AttachmentFileCard/index.ts new file mode 100644 index 00000000000..eca587b03d7 --- /dev/null +++ b/packages/chat-ui/src/components/AttachmentFileCard/index.ts @@ -0,0 +1,4 @@ +export { + AttachmentFileCard, + type AttachmentFileCardProps, +} from "./AttachmentFileCard"; diff --git a/packages/chat-ui/src/components/PromptInput/components/AttachmentPills/AttachmentPills.tsx b/packages/chat-ui/src/components/PromptInput/components/AttachmentPills/AttachmentPills.tsx index 29854a8d1c5..60e05e04594 100644 --- a/packages/chat-ui/src/components/PromptInput/components/AttachmentPills/AttachmentPills.tsx +++ b/packages/chat-ui/src/components/PromptInput/components/AttachmentPills/AttachmentPills.tsx @@ -1,14 +1,6 @@ "use client"; -import { - FileArchiveIcon, - FileCode2Icon, - FileJson2Icon, - FileTextIcon, - ImageIcon, - Music2Icon, -} from "lucide-react"; -import type { JSX } from "react"; +import { AttachmentFileCard } from "../../../AttachmentFileCard"; import { PastedTextCard } from "../../../PastedTextCard"; import type { PromptInputAttachment } from "../../types"; import { RemoveButton } from "./components/RemoveButton"; @@ -25,40 +17,6 @@ export type AttachmentPillsProps = { ) => void; }; -const CODE_EXTENSIONS = new Set([ - "ts", - "tsx", - "js", - "jsx", - "py", - "rs", - "go", - "rb", - "swift", - "css", - "html", - "sh", -]); -const DATA_EXTENSIONS = new Set(["json", "yaml", "yml", "toml", "lock"]); -const ARCHIVE_EXTENSIONS = new Set(["zip", "tar", "gz", "tgz", "7z", "rar"]); - -// Mime type first (audio, images demoted after a failed preview), then -// extension for the text-ish formats mime can't distinguish. -function fileTypeIcon(mediaType: string, extension: string): JSX.Element { - if (mediaType.startsWith("audio/")) - return ; - if (mediaType.startsWith("image/")) - return ; - const lowered = extension.toLowerCase(); - if (CODE_EXTENSIONS.has(lowered)) - return ; - if (DATA_EXTENSIONS.has(lowered)) - return ; - if (ARCHIVE_EXTENSIONS.has(lowered)) - return ; - return ; -} - export function AttachmentPills({ attachments, onRemove, @@ -80,9 +38,6 @@ export function AttachmentPills({ ); } const filename = attachment.file.name || "attachment"; - const dotIndex = filename.lastIndexOf("."); - const extension = - dotIndex > 0 ? filename.slice(dotIndex + 1).toUpperCase() : ""; const reveal = onReveal && attachment.sourcePath ? ( onReveal(attachment)} /> @@ -121,26 +76,11 @@ export function AttachmentPills({ } return (
- + /> onRemove(attachment.id)} /> {reveal}
diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/attachmentTags.test.ts b/packages/chat/src/core/attachmentTags/attachmentTags.test.ts similarity index 72% rename from apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/attachmentTags.test.ts rename to packages/chat/src/core/attachmentTags/attachmentTags.test.ts index b0be40eacaf..d6dac888f4b 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/utils/attachmentTags/attachmentTags.test.ts +++ b/packages/chat/src/core/attachmentTags/attachmentTags.test.ts @@ -1,5 +1,9 @@ import { describe, expect, it } from "bun:test"; -import { formatAttachmentTag, parseAttachmentTags } from "./attachmentTags"; +import { + attachmentDisplayName, + formatAttachmentTag, + parseAttachmentTags, +} from "./attachmentTags"; function legacyPastedMessage( prompt: string, @@ -77,4 +81,29 @@ describe("attachmentTags", () => { pastedTexts: [paste], }); }); + + it("keeps the attached name, escaped, and falls back to the file on disk without one", () => { + const message = [ + formatAttachmentTag({ + path: ".paradev/attachments/Superset-arm64__21_.dmg", + type: "application/x-apple-diskimage", + name: 'Superset-arm64 (21) "final" .dmg', + }), + formatAttachmentTag({ + path: ".paradev/attachments/notes.txt", + type: "text/plain", + name: "notes.txt", + }), + ].join("\n"); + + expect(message).toContain( + 'name="Superset-arm64 (21) "final" <v2>.dmg"', + ); + expect(message).not.toContain('name="notes.txt"'); + const { attachments } = parseAttachmentTags(message); + expect(attachments.map(attachmentDisplayName)).toEqual([ + 'Superset-arm64 (21) "final" .dmg', + "notes.txt", + ]); + }); }); diff --git a/packages/chat/src/core/attachmentTags/attachmentTags.ts b/packages/chat/src/core/attachmentTags/attachmentTags.ts new file mode 100644 index 00000000000..9d8107270b4 --- /dev/null +++ b/packages/chat/src/core/attachmentTags/attachmentTags.ts @@ -0,0 +1,94 @@ +import { + LEGACY_WORKSPACE_ATTACHMENTS_DIR, + WORKSPACE_ATTACHMENTS_DIR, +} from "@superset/shared/workspace-attachments"; +import { parsePastedText } from "../pastedText/pastedText"; + +export type AttachmentTag = { path: string; type: string; name?: string }; + +const TAG = + //g; +const SAFE_TYPE = /^[\w.+-]+\/[\w.+-]+$/; +const SAFE_NAME = /^[A-Za-z0-9._-]+$/; +const MAX_NAME_LENGTH = 255; + +const ESCAPES: Record = { + "&": "&", + '"': """, + "<": "<", + ">": ">", +}; +const UNESCAPES: Record = { + amp: "&", + quot: '"', + lt: "<", + gt: ">", +}; + +function escapeAttribute(value: string): string { + return value.replace(/[&"<>]/g, (char) => ESCAPES[char] ?? char); +} + +function unescapeAttribute(value: string): string { + return value.replace( + /&(amp|quot|lt|gt);/g, + (match, entity: string) => UNESCAPES[entity] ?? match, + ); +} + +function baseName(path: string): string { + return path.split("/").pop() ?? path; +} + +function isWorkspaceAttachmentPath(path: string): boolean { + const prefix = [WORKSPACE_ATTACHMENTS_DIR, LEGACY_WORKSPACE_ATTACHMENTS_DIR] + .map((dir) => `${dir}/`) + .find((dir) => path.startsWith(dir)); + if (!prefix) return false; + const name = path.slice(prefix.length); + return SAFE_NAME.test(name) && name !== "." && name !== ".."; +} + +/** The name the user attached; tags written before names were kept fall back to the file on disk. */ +export function attachmentDisplayName(tag: AttachmentTag): string { + return tag.name || baseName(tag.path); +} + +export function formatAttachmentTag({ + path, + type, + name, +}: AttachmentTag): string { + const attributes = [`path="${path}"`]; + if (SAFE_TYPE.test(type)) attributes.push(`type="${type}"`); + const cleanName = name + ?.replace(/\p{Cc}/gu, "") + .trim() + .slice(0, MAX_NAME_LENGTH); + if (cleanName && cleanName !== baseName(path)) { + attributes.push(`name="${escapeAttribute(cleanName)}"`); + } + return ``; +} + +export function parseAttachmentTags(message: string): { + text: string; + attachments: AttachmentTag[]; + pastedTexts: string[]; +} { + const { text, pastes } = parsePastedText(message); + const attachments: AttachmentTag[] = []; + const rest = text.replace( + TAG, + (match: string, path: string, type?: string, name?: string) => { + if (!isWorkspaceAttachmentPath(path)) return match; + attachments.push({ + path, + type: type ?? "", + ...(name ? { name: unescapeAttribute(name) } : {}), + }); + return ""; + }, + ); + return { text: rest.trim(), attachments, pastedTexts: pastes }; +} diff --git a/packages/chat/src/core/index.ts b/packages/chat/src/core/index.ts index c16f640044e..d7dea344ba9 100644 --- a/packages/chat/src/core/index.ts +++ b/packages/chat/src/core/index.ts @@ -1,3 +1,4 @@ +export * from "./attachmentTags/attachmentTags"; export * from "./bookkeeping/readBookkeeping"; export * from "./coalesce"; export * from "./config/launchConfigSelections"; diff --git a/packages/chat/src/protocol/items.ts b/packages/chat/src/protocol/items.ts index e0ea3b3ebca..32ba65f6d8a 100644 --- a/packages/chat/src/protocol/items.ts +++ b/packages/chat/src/protocol/items.ts @@ -26,12 +26,20 @@ export const userContentSchema = z.discriminatedUnion("type", [ /** Reaches the agent, but is not kept on the transcript's user message. */ hidden: z.boolean().optional(), }), - z.looseObject({ - type: z.literal("attachment"), - attachmentId: z.string().min(1), - name: z.string(), - mimeType: z.string(), - }), + z + .looseObject({ + type: z.literal("attachment"), + /** In the host's attachment store: a workspace on a machine someone owns. */ + attachmentId: z.string().min(1).optional(), + /** In our storage: a cloud workspace. Readers prefer it when both are set. */ + fileId: z.string().uuid().optional(), + name: z.string(), + mimeType: z.string(), + sizeBytes: z.number().int().nonnegative().optional(), + }) + .refine((part) => part.attachmentId || part.fileId, { + message: "An attachment needs an attachmentId or a fileId", + }), ]); export type UserContent = z.infer; diff --git a/packages/host-service/src/app.ts b/packages/host-service/src/app.ts index c3f00e64556..9af393aa126 100644 --- a/packages/host-service/src/app.ts +++ b/packages/host-service/src/app.ts @@ -61,6 +61,10 @@ import { } from "./terminal-agents"; import { matchesAgentBinding } from "./terminal-agents/matches-agent-binding"; import { appRouter } from "./trpc/router"; +import { + ATTACHMENT_SWEEP_INTERVAL_MS, + sweepAttachmentStore, +} from "./trpc/router/attachments/sweep"; import { gitStatusStore } from "./trpc/router/git/utils/git-status-store"; import { disposeLocalMobileDevices, @@ -358,6 +362,7 @@ export function createApp(options: CreateAppOptions): CreateAppResult { }; const chatV3 = createChatV3Mount({ db, + api, dbPath: config.dbPath, agents: createChatAgentBridge(chatAgentContext), onSessionChanged: ({ scopeId, occurredAt }) => @@ -397,6 +402,18 @@ export function createApp(options: CreateAppOptions): CreateAppResult { ? null : setInterval(() => void runProjectPurge(), PROJECT_PURGE_INTERVAL_MS); projectPurgeTimer?.unref?.(); + const runAttachmentSweep = () => + sweepAttachmentStore().catch((err) => { + console.warn("[host-service] attachment sweep failed:", err); + }); + const attachmentSweepTimer = + process.env.SUPERSET_HOST_RUN_MODE === "sandbox" + ? null + : setInterval( + () => void runAttachmentSweep(), + ATTACHMENT_SWEEP_INTERVAL_MS, + ); + attachmentSweepTimer?.unref?.(); if (process.env.SUPERSET_HOST_RUN_MODE !== "sandbox") { startLocalMobileDeviceCleanup(db); } @@ -427,6 +444,7 @@ export function createApp(options: CreateAppOptions): CreateAppResult { console.warn("[host-service] archived-workspace reconcile failed:", err); }); await runProjectPurge(); + await runAttachmentSweep(); // Re-share the default account's Claude/Codex config into the selected // provider profiles. Last: it touches no host state the sweeps above // repair, and a slow filesystem must not delay them. @@ -518,6 +536,19 @@ export function createApp(options: CreateAppOptions): CreateAppResult { }); registerChatV3Routes({ app, db, mount: chatV3, upgradeWebSocket }); + // tRPC answers a streamed batch before it has read the request body, and + // a sandbox's ingress treats that early response as the end of the + // exchange and drops the upload still in flight. Hand tRPC a body it + // already has, so no response starts before the request is complete. + app.use("/trpc/*", async (c, next) => { + if (c.req.raw.body !== null && !c.req.raw.bodyUsed) { + c.req.raw = new Request(c.req.raw, { + body: await c.req.raw.arrayBuffer(), + }); + } + await next(); + }); + app.use( "/trpc/*", trpcServer({ @@ -559,6 +590,7 @@ export function createApp(options: CreateAppOptions): CreateAppResult { const dispose = async (): Promise => { agentJobs.stopAll(); if (projectPurgeTimer) clearInterval(projectPurgeTimer); + if (attachmentSweepTimer) clearInterval(attachmentSweepTimer); await disposeWorkspaceTitleJobs(db); // Each step is best-effort and isolated: a throw in one cleanup must // not skip the others, otherwise a flaky `.stop()` could leak the diff --git a/packages/host-service/src/chat-v3/acpHarnesses.ts b/packages/host-service/src/chat-v3/acpHarnesses.ts index 90ff41fea6b..bb6a5660cb0 100644 --- a/packages/host-service/src/chat-v3/acpHarnesses.ts +++ b/packages/host-service/src/chat-v3/acpHarnesses.ts @@ -1,10 +1,8 @@ -import { readFile } from "node:fs/promises"; import { createRequire } from "node:module"; import { dirname, join } from "node:path"; -import type { HarnessFactory } from "@superset/chat-runtime"; +import type { HarnessFactory, ResolveAttachment } from "@superset/chat-runtime"; import { createAcpAdapter } from "@superset/chat-runtime"; import type { HostDb } from "../db"; -import { resolveAttachmentPath } from "../trpc/router/attachments/storage"; import { captureSessionAccount } from "../trpc/router/usage/session-account/session-account"; import { ACP_HARNESSES } from "./acpCatalogue"; import { resolveAgentCli } from "./agentCli"; @@ -13,16 +11,6 @@ import { storeAgentImage } from "./agentImages"; import { agentLoginCommand } from "./agentLogin"; import type { ChatAgentBridge } from "./chatAgentBridge"; -async function resolveAttachment(attachmentId: string) { - const resolved = resolveAttachmentPath(attachmentId); - if (!resolved) return null; - return { - path: resolved.path, - mimeType: resolved.metadata.mediaType, - data: (await readFile(resolved.path)).toString("base64"), - }; -} - function resolveAdapterEntry(packageName: string): string { const moduleRequire = createRequire(import.meta.url); const pkgJson = moduleRequire.resolve(`${packageName}/package.json`); @@ -32,6 +20,7 @@ function resolveAdapterEntry(packageName: string): string { export function acpHarnessFactory( harness: string, db: HostDb, + resolveAttachment: ResolveAttachment, agents?: ChatAgentBridge, ): HarnessFactory | null { const entry = ACP_HARNESSES[harness]; @@ -112,11 +101,12 @@ export function acpHarnessFactory( export function acpHarnessEntries( db: HostDb, + resolveAttachment: ResolveAttachment, agents?: ChatAgentBridge, ): [string, HarnessFactory][] { const entries: [string, HarnessFactory][] = []; for (const harness of Object.keys(ACP_HARNESSES)) { - const factory = acpHarnessFactory(harness, db, agents); + const factory = acpHarnessFactory(harness, db, resolveAttachment, agents); if (factory) entries.push([harness, factory]); } return entries; diff --git a/packages/host-service/src/chat-v3/agentImages.ts b/packages/host-service/src/chat-v3/agentImages.ts index cf0d8eeb63b..a9cbd354130 100644 --- a/packages/host-service/src/chat-v3/agentImages.ts +++ b/packages/host-service/src/chat-v3/agentImages.ts @@ -20,8 +20,8 @@ import { MAX_CHAT_IMAGE_BYTES } from "@superset/shared/attachment-limits"; import { sanitizeAttachmentFileName, WORKSPACE_ATTACHMENTS_DIR, - WORKSPACE_ATTACHMENTS_GITIGNORE, } from "@superset/shared/workspace-attachments"; +import { ensureWorkspaceAttachmentsDir } from "@superset/shared/workspace-attachments-dir"; import mimeTypes from "mime-types"; const NAME_HASH_CHARS = 12; @@ -39,18 +39,6 @@ function stemFor(name: string | undefined): string { return sanitized ?? "image"; } -export function attachmentsDir(cwd: string): string { - const dir = join(cwd, WORKSPACE_ATTACHMENTS_DIR); - mkdirSync(dir, { recursive: true }); - try { - closeSync(openSync(join(dir, ".gitignore"), "wx")); - writeFileSync(join(dir, ".gitignore"), WORKSPACE_ATTACHMENTS_GITIGNORE); - } catch (error) { - if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error; - } - return dir; -} - function isUsableFile(path: string, maxBytes: number): boolean { try { const stat = statSync(path); @@ -101,7 +89,7 @@ function storeImage( .digest("hex") .slice(0, NAME_HASH_CHARS); const fileName = `${stemFor(name)}-${hash}.${extensionFor(source.mimeType, name)}`; - const target = join(attachmentsDir(cwd), fileName); + const target = join(ensureWorkspaceAttachmentsDir(cwd), fileName); if (!existsSync(target)) writeFileSync(target, bytes); return { path: `${WORKSPACE_ATTACHMENTS_DIR}/${fileName}` }; } @@ -148,7 +136,7 @@ export function storeAgentImage( } const stored = storeImage(source, cwd, maxBytes); if (stored && referencePath) { - attachmentsDir(cwd); + ensureWorkspaceAttachmentsDir(cwd); mkdirSync(referenceDir, { recursive: true }); writeFileSync(referencePath, JSON.stringify(basename(stored.path))); } diff --git a/packages/host-service/src/chat-v3/mount.ts b/packages/host-service/src/chat-v3/mount.ts index 34979e1d3b0..f9bc221583f 100644 --- a/packages/host-service/src/chat-v3/mount.ts +++ b/packages/host-service/src/chat-v3/mount.ts @@ -10,6 +10,7 @@ import type { ChatSessionChange, HarnessFactory, HarnessRegistry, + ResolveAttachment, WsSinkSocket, } from "@superset/chat-runtime"; import { @@ -23,12 +24,16 @@ import { import { HOST_CHAT_RESUME_MARKER_FILE } from "@superset/shared/host-version"; import type { Hono, MiddlewareHandler } from "hono"; import type { HostDb } from "../db"; +import { reportAttachmentResolveFailure } from "../sentry"; +import { importCloudAttachments } from "../trpc/router/attachments/attachments"; +import type { ApiClient } from "../types"; import { cliFloor } from "./acpCatalogue"; import { acpHarnessEntries } from "./acpHarnesses"; import { resolveAgentCli } from "./agentCli"; import { buildChatAgentEnv } from "./agentEnv"; import type { ChatAgentBridge } from "./chatAgentBridge"; import { createGitCheckpoints } from "./gitCheckpoints"; +import { createAttachmentResolver } from "./resolveAttachment"; import { createResolveCwd } from "./resolveCwd"; import { recordUnfinishedChats, @@ -56,12 +61,14 @@ function migrationsFolder(): string { function harnessRegistry( db: HostDb, agents: ChatAgentBridge | undefined, + resolveAttachment: ResolveAttachment, ): HarnessRegistry { const entries: [string, HarnessFactory][] = [ [ "claude-code", (options) => createClaudeAdapter({ + resolveAttachment, launch: async () => { const cli = await resolveAgentCli({ binary: "claude", @@ -86,6 +93,7 @@ function harnessRegistry( "codex", (options) => new CodexAdapter({ + resolveAttachment, launch: async () => { const cli = await resolveAgentCli({ binary: "codex", @@ -102,7 +110,7 @@ function harnessRegistry( }, }), ], - ...acpHarnessEntries(db, agents), + ...acpHarnessEntries(db, resolveAttachment, agents), ]; return new Map(entries); } @@ -121,6 +129,7 @@ export type ChatV3Mount = { */ export function createChatV3Mount(options: { db: HostDb; + api: ApiClient; dbPath: string; agents?: ChatAgentBridge; onSessionChanged?: (change: ChatSessionChange) => void; @@ -136,7 +145,14 @@ export function createChatV3Mount(options: { built = createChatRuntime({ dataDir: dirname(options.dbPath), migrationsFolder: migrationsFolder(), - harnesses: harnessRegistry(options.db, options.agents), + harnesses: harnessRegistry( + options.db, + options.agents, + createAttachmentResolver({ + importCloud: (fileIds) => importCloudAttachments(options, fileIds), + report: reportAttachmentResolveFailure, + }), + ), observer: options.agents, checkpoints: createGitCheckpoints(), onSessionChanged: options.onSessionChanged, diff --git a/packages/host-service/src/chat-v3/resolveAttachment.test.ts b/packages/host-service/src/chat-v3/resolveAttachment.test.ts new file mode 100644 index 00000000000..0d94dfb5356 --- /dev/null +++ b/packages/host-service/src/chat-v3/resolveAttachment.test.ts @@ -0,0 +1,141 @@ +import { afterEach, beforeEach, describe, expect, it } from "bun:test"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import type { AttachmentUploadResult } from "../trpc/router/attachments"; +import { + type AttachmentMetadata, + indexAttachmentFileId, + writeAttachment, +} from "../trpc/router/attachments/storage"; +import { createAttachmentResolver } from "./resolveAttachment"; + +let manifestDir: string; + +beforeEach(() => { + manifestDir = mkdtempSync(join(tmpdir(), "superset-resolve-attachment-")); + process.env.HOST_MANIFEST_DIR = manifestDir; +}); + +afterEach(() => { + rmSync(manifestDir, { recursive: true, force: true }); + delete process.env.HOST_MANIFEST_DIR; +}); + +function store(fields: Partial = {}): AttachmentMetadata { + const metadata: AttachmentMetadata = { + attachmentId: crypto.randomUUID(), + mediaType: "image/png", + sizeBytes: 3, + createdAt: 0, + ...fields, + }; + writeAttachment(new Uint8Array([1, 2, 3]), metadata); + if (metadata.fileId) + indexAttachmentFileId({ ...metadata, fileId: metadata.fileId }); + return metadata; +} + +function resolverWith( + importCloud: (fileIds: string[]) => Promise, +) { + const imports: string[][] = []; + const reported: unknown[] = []; + const resolve = createAttachmentResolver({ + importCloud: (fileIds) => { + imports.push(fileIds); + return importCloud(fileIds); + }, + report: (error) => reported.push(error), + }); + return { resolve, imports, reported }; +} + +const part = (ids: { attachmentId?: string; fileId?: string }) => ({ + type: "attachment" as const, + ...ids, + name: "shot.png", + mimeType: "image/png", +}); + +const noImport = async () => { + throw new Error("should not import"); +}; + +describe("createAttachmentResolver", () => { + it("reads a host part from the store by its attachmentId", async () => { + const entry = store(); + const { resolve } = resolverWith(noImport); + expect(await resolve(part({ attachmentId: entry.attachmentId }))).toEqual({ + path: expect.stringContaining(entry.attachmentId), + mimeType: "image/png", + data: Buffer.from([1, 2, 3]).toString("base64"), + }); + }); + + it("serves a cloud part from the box's cached copy without importing", async () => { + const fileId = crypto.randomUUID(); + const entry = store({ fileId }); + const { resolve, imports } = resolverWith(noImport); + + const file = await resolve(part({ fileId })); + expect(file?.path).toContain(entry.attachmentId); + expect(imports).toEqual([]); + }); + + it("imports a cloud part into an empty store, as on a recreated box", async () => { + const fileId = crypto.randomUUID(); + const { resolve, imports } = resolverWith(async () => { + const entry = store({ fileId }); + return [ + { + attachmentId: entry.attachmentId, + fileId, + mediaType: entry.mediaType, + sizeBytes: entry.sizeBytes, + }, + ]; + }); + + const file = await resolve(part({ fileId })); + expect(imports).toEqual([[fileId]]); + expect(file?.mimeType).toBe("image/png"); + }); + + it("prefers the fileId when a part carries both", async () => { + const fileId = crypto.randomUUID(); + const cloudCopy = store({ fileId }); + const hostEntry = store(); + const { resolve } = resolverWith(noImport); + + const file = await resolve( + part({ attachmentId: hostEntry.attachmentId, fileId }), + ); + expect(file?.path).toContain(cloudCopy.attachmentId); + }); + + it("gives null for an id the store does not have", async () => { + const { resolve, reported } = resolverWith(noImport); + expect( + await resolve(part({ attachmentId: crypto.randomUUID() })), + ).toBeNull(); + expect(reported).toEqual([]); + }); + + it("reports an import that fails and gives null", async () => { + const failure = new Error("storage down"); + const { resolve, reported } = resolverWith(async () => { + throw failure; + }); + expect(await resolve(part({ fileId: crypto.randomUUID() }))).toBeNull(); + expect(reported).toEqual([failure]); + }); + + it("hands a non-image over by path, without reading its bytes", async () => { + const entry = store({ mediaType: "application/pdf" }); + const { resolve } = resolverWith(noImport); + expect( + (await resolve(part({ attachmentId: entry.attachmentId })))?.data, + ).toBe(""); + }); +}); diff --git a/packages/host-service/src/chat-v3/resolveAttachment.ts b/packages/host-service/src/chat-v3/resolveAttachment.ts new file mode 100644 index 00000000000..f573df703fc --- /dev/null +++ b/packages/host-service/src/chat-v3/resolveAttachment.ts @@ -0,0 +1,50 @@ +import { readFile } from "node:fs/promises"; +import type { ResolveAttachment } from "@superset/chat-runtime"; +import type { AttachmentUploadResult } from "../trpc/router/attachments"; +import { + handOutAttachment, + handOutAttachmentByFileId, +} from "../trpc/router/attachments/storage"; + +/** + * One resolver for every adapter. A part names where it lives: `fileId` is a + * cloud workspace's storage object, cached in this box's store or pulled into + * it now (a recreated box has an empty store); `attachmentId` is the store + * entry itself. + */ +export function createAttachmentResolver({ + importCloud, + report, +}: { + importCloud: (fileIds: string[]) => Promise; + report: (error: unknown) => void; +}): ResolveAttachment { + const fromCloud = async (fileId: string) => { + const cached = handOutAttachmentByFileId(fileId); + if (cached) return cached; + const [imported] = await importCloud([fileId]); + return imported ? handOutAttachment(imported.attachmentId) : null; + }; + + return async (part) => { + try { + const found = part.fileId + ? await fromCloud(part.fileId) + : part.attachmentId + ? handOutAttachment(part.attachmentId) + : null; + if (!found) return null; + const mimeType = found.metadata.mediaType; + return { + path: found.path, + mimeType, + data: mimeType.startsWith("image/") + ? (await readFile(found.path)).toString("base64") + : "", + }; + } catch (error) { + report(error); + return null; + } + }; +} diff --git a/packages/host-service/src/sentry.ts b/packages/host-service/src/sentry.ts index b2b3ecac1b9..f1d305db2f7 100644 --- a/packages/host-service/src/sentry.ts +++ b/packages/host-service/src/sentry.ts @@ -39,6 +39,12 @@ export function initSentry(options: { organizationId?: string }): void { initialized = true; } +/** A file a user attached that the agent did not get. */ +export function reportAttachmentResolveFailure(error: unknown): void { + if (!initialized) return; + Sentry.captureException(error, { tags: { attachment_resolve: "failed" } }); +} + export async function captureFatalStartupError(error: unknown): Promise { if (!initialized) return; Sentry.captureException(error); diff --git a/packages/host-service/src/trpc/router/agents/agents.test.ts b/packages/host-service/src/trpc/router/agents/agents.test.ts index 676c2f5da86..b1a2edbcf62 100644 --- a/packages/host-service/src/trpc/router/agents/agents.test.ts +++ b/packages/host-service/src/trpc/router/agents/agents.test.ts @@ -11,6 +11,12 @@ import { migrate } from "drizzle-orm/bun-sqlite/migrator"; import type { HostDb } from "../../../db"; import * as schema from "../../../db/schema"; import { TerminalAgentStore } from "../../../terminal-agents"; +import { importCloudAttachments } from "../attachments/attachments"; +import { + type AttachmentMetadata, + readAttachmentMetadata, + writeAttachment, +} from "../attachments/storage"; import { setDefaultAccountSelection } from "../usage/default-account"; import { bindResumedSession, @@ -1212,3 +1218,110 @@ describe("continuationTarget", () => { ).toEqual({ terminalId, label: "Team Claude" }); }); }); + +describe("attachments handed to an agent launch", () => { + const workspaceId = "11111111-1111-1111-1111-111111111111"; + let manifestDir: string; + + beforeEach(() => { + manifestDir = mkdtempSync(join(tmpdir(), "superset-agent-attachments-")); + process.env.HOST_MANIFEST_DIR = manifestDir; + }); + + afterEach(() => { + rmSync(manifestDir, { recursive: true, force: true }); + delete process.env.HOST_MANIFEST_DIR; + }); + + function seedClaude(db: HostDb) { + db.insert(schema.hostAgentConfigs) + .values({ + id: "00000000-0000-0000-0000-00000000000a", + presetId: "claude", + label: "Claude", + command: "claude", + argsJson: "[]", + promptTransport: "argv", + promptArgsJson: "[]", + resumeArgsJson: "[]", + forkArgsJson: "[]", + envJson: "{}", + displayOrder: 0, + }) + .run(); + } + + it("a cloud launch's first-prompt part carries the fileId it was imported from", async () => { + const server = Bun.serve({ + port: 0, + fetch: () => new Response("png"), + }); + try { + const fileId = crypto.randomUUID(); + const [imported] = await importCloudAttachments( + { + api: { + attachment: { + resolve: { + mutate: async () => [ + { + fileId, + name: "shot.png", + contentType: "image/png", + sizeBytes: 3, + url: server.url.href, + }, + ], + }, + }, + }, + }, + [fileId], + ); + const db = createTestDb(); + seedClaude(db); + + const target = chatLaunchTarget(db, { + workspaceId, + agent: "claude", + prompt: "look", + surface: "chat", + attachmentIds: [imported?.attachmentId ?? ""], + }); + expect(target?.attachments).toEqual([ + { + attachmentId: imported?.attachmentId ?? "", + fileId, + name: "shot.png", + mimeType: "image/png", + sizeBytes: 3, + }, + ]); + } finally { + server.stop(true); + } + }); + + it("a terminal launch stamps the attachments it lists as used", () => { + const metadata: AttachmentMetadata = { + attachmentId: crypto.randomUUID(), + mediaType: "image/png", + sizeBytes: 1, + createdAt: 0, + lastUsedAt: 0, + }; + writeAttachment(new Uint8Array([1]), metadata); + const db = createTestDb(); + seedClaude(db); + + buildTerminalAgentLaunch(db, { + workspaceId, + agent: "claude", + prompt: "look", + attachmentIds: [metadata.attachmentId], + }); + expect( + readAttachmentMetadata(metadata.attachmentId)?.lastUsedAt, + ).toBeGreaterThan(0); + }); +}); diff --git a/packages/host-service/src/trpc/router/agents/agents.ts b/packages/host-service/src/trpc/router/agents/agents.ts index 9a312049d3f..fad6d80e73e 100644 --- a/packages/host-service/src/trpc/router/agents/agents.ts +++ b/packages/host-service/src/trpc/router/agents/agents.ts @@ -1,4 +1,5 @@ import { acpStartModes } from "@superset/chat/core"; +import { attachedFilesBlock } from "@superset/chat-runtime"; import { isBuiltinAgentId } from "@superset/shared/agent-catalog"; import { FORK_SESSION_ID_TOKEN } from "@superset/shared/agent-definition"; import { @@ -45,7 +46,10 @@ import { import { hasHarnessSession } from "../../../terminal-agents/harness-sessions"; import type { HostServiceContext } from "../../../types"; import { protectedProcedure, router } from "../../index"; -import { resolveAttachmentPath } from "../attachments/storage"; +import { + handOutAttachment, + resolveAttachmentPath, +} from "../attachments/storage"; import { createChatSession } from "../sessions/create-chat-session"; import { toTerminalSessionError } from "../terminal/errors"; import { seedAgentFolderTrust } from "../workspace-creation/shared/seed-agent-trust"; @@ -125,12 +129,10 @@ function buildForkArgv(forkArgs: string[], rawSessionId: string): string[] { function buildAttachmentBlock( prompt: string, - resolved: Array<{ attachmentId: string; path: string }>, + resolved: Array<{ name: string; path: string }>, ): string { if (resolved.length === 0) return prompt; - const lines = resolved.map((item) => `- ${item.path}`); - const block = `\n\n# Attached files\n\nThe user attached these files. They are available on this host at:\n\n${lines.join("\n")}`; - return prompt + block; + return `${prompt}\n\n${attachedFilesBlock(resolved)}`; } export interface AgentRunInput { @@ -433,16 +435,19 @@ export function buildTerminalAgentLaunch( validateAgentForkSelection(config, input.forkSessionId); validateForkSessionIsResolvable(db, config, input); - const resolvedAttachments: Array<{ attachmentId: string; path: string }> = []; + const resolvedAttachments: Array<{ name: string; path: string }> = []; for (const attachmentId of input.attachmentIds ?? []) { - const resolved = resolveAttachmentPath(attachmentId); + const resolved = handOutAttachment(attachmentId); if (!resolved) { throw new TRPCError({ code: "NOT_FOUND", message: `Attachment not found: ${attachmentId}`, }); } - resolvedAttachments.push({ attachmentId, path: resolved.path }); + resolvedAttachments.push({ + name: resolved.metadata.originalFilename ?? attachmentId, + path: resolved.path, + }); } const prompt = buildAttachmentBlock(input.prompt, resolvedAttachments); @@ -645,13 +650,25 @@ function bindingRunsConfig( return binding.agentId === launchIdentity(config); } +/** + * An imported copy keeps its `fileId` next to the host id: the adapters read + * `attachmentId` today, and `fileId` is what renders the part without this box. + */ +export interface ChatLaunchAttachment { + attachmentId: string; + fileId?: string; + name: string; + mimeType: string; + sizeBytes: number; +} + export function chatLaunchTarget( db: HostDb, input: AgentRunInput, ): { harness: string; label: string; - attachments: Array<{ attachmentId: string; name: string; mimeType: string }>; + attachments: ChatLaunchAttachment[]; } | null { if ( input.surface !== "chat" || @@ -661,18 +678,16 @@ export function chatLaunchTarget( ) { return null; } - const attachments: Array<{ - attachmentId: string; - name: string; - mimeType: string; - }> = []; + const attachments: ChatLaunchAttachment[] = []; for (const attachmentId of input.attachmentIds ?? []) { const resolved = resolveAttachmentPath(attachmentId); if (!resolved) return null; attachments.push({ attachmentId, + ...(resolved.metadata.fileId ? { fileId: resolved.metadata.fileId } : {}), name: resolved.metadata.originalFilename ?? attachmentId, mimeType: resolved.metadata.mediaType, + sizeBytes: resolved.metadata.sizeBytes, }); } const config = resolveHostAgentConfig(db, input.agent); diff --git a/packages/host-service/src/trpc/router/attachments/attachments.test.ts b/packages/host-service/src/trpc/router/attachments/attachments.test.ts index 5189805194c..30b5fb0c388 100644 --- a/packages/host-service/src/trpc/router/attachments/attachments.test.ts +++ b/packages/host-service/src/trpc/router/attachments/attachments.test.ts @@ -3,13 +3,16 @@ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { resolveAppHomeDir } from "@superset/agent-setup/paths"; +import { MAX_INLINE_ATTACHMENT_BYTES } from "@superset/shared/attachment-limits"; import type { HostServiceContext } from "../../../types"; -import { attachmentsRouter } from "./attachments"; -import { MAX_INLINE_ATTACHMENT_BYTES } from "./constants"; +import { attachmentsRouter, importCloudAttachments } from "./attachments"; import { getAttachmentDir, getAttachmentFilePath, getAttachmentsRoot, + handOutAttachmentByFileId, + readAttachmentMetadata, + writeAttachmentMetadata, } from "./storage"; let tempBase: string; @@ -188,6 +191,20 @@ describe("attachmentsRouter.read", () => { }); }); + it("stamps the attachment as used", async () => { + const caller = createCaller(); + const { attachmentId } = await caller.upload({ + data: { kind: "base64", data: PNG_BASE64 }, + mediaType: "image/png", + }); + const metadata = readAttachmentMetadata(attachmentId); + if (!metadata) throw new Error("upload wrote no metadata"); + writeAttachmentMetadata({ ...metadata, lastUsedAt: 0 }); + + await caller.read({ attachmentId }); + expect(readAttachmentMetadata(attachmentId)?.lastUsedAt).toBeGreaterThan(0); + }); + it("reports a missing attachment as NOT_FOUND", async () => { await expect( createCaller().read({ @@ -197,6 +214,43 @@ describe("attachmentsRouter.read", () => { }); }); +describe("importCloudAttachments", () => { + it("records the fileId a copy came from, so a lookup by fileId finds it", async () => { + const server = Bun.serve({ + port: 0, + fetch: () => new Response(Buffer.from(PNG_BASE64, "base64")), + }); + try { + const fileId = crypto.randomUUID(); + const ctx = { + api: { + attachment: { + resolve: { + mutate: async () => [ + { + fileId, + name: "shot.png", + contentType: "image/png", + sizeBytes: 68, + url: server.url.href, + }, + ], + }, + }, + }, + }; + + const [imported] = await importCloudAttachments(ctx, [fileId]); + expect(imported?.fileId).toBe(fileId); + expect(handOutAttachmentByFileId(fileId)?.metadata.attachmentId).toBe( + imported?.attachmentId, + ); + } finally { + server.stop(true); + } + }); +}); + describe("attachmentsRouter.delete", () => { it("removes the attachment directory", async () => { const caller = createCaller(); diff --git a/packages/host-service/src/trpc/router/attachments/attachments.ts b/packages/host-service/src/trpc/router/attachments/attachments.ts index 12e83318cdb..6fb1dcd8f97 100644 --- a/packages/host-service/src/trpc/router/attachments/attachments.ts +++ b/packages/host-service/src/trpc/router/attachments/attachments.ts @@ -2,24 +2,28 @@ import { randomUUID } from "node:crypto"; import { closeSync, openSync } from "node:fs"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; +import { + MAX_ATTACHMENTS, + MAX_INLINE_ATTACHMENT_BYTES, +} from "@superset/shared/attachment-limits"; import { assignAttachmentFileName, attachmentNameWithSuffix, WORKSPACE_ATTACHMENTS_DIR, } from "@superset/shared/workspace-attachments"; +import { ensureWorkspaceAttachmentsDir } from "@superset/shared/workspace-attachments-dir"; import { TRPCError } from "@trpc/server"; import mimeTypes from "mime-types"; import { z } from "zod"; -import { attachmentsDir } from "../../../chat-v3/agentImages"; import { protectedProcedure, router } from "../../index"; import { resolveWorktreePath } from "../git/utils/resolve-worktree"; -import { MAX_INLINE_ATTACHMENT_BYTES } from "./constants"; import { type CloudAttachment, downloadAttachment } from "./download"; import { type AttachmentMetadata, deleteAttachment, + handOutAttachment, + indexAttachmentFileId, prepareAttachmentTarget, - resolveAttachmentPath, writeAttachment, writeAttachmentMetadata, } from "./storage"; @@ -129,12 +133,14 @@ export const attachmentsRouter = router({ }); } + const now = Date.now(); const metadata: AttachmentMetadata = { attachmentId: randomUUID(), mediaType, originalFilename: input.originalFilename, sizeBytes: bytes.length, - createdAt: Date.now(), + createdAt: now, + lastUsedAt: now, }; // Buffer already extends Uint8Array; no need to wrap. @@ -156,7 +162,11 @@ export const attachmentsRouter = router({ * an attachment can legitimately be. */ importFromCloud: protectedProcedure - .input(z.object({ fileIds: z.array(z.string().uuid()).min(1).max(10) })) + .input( + z.object({ + fileIds: z.array(z.string().uuid()).min(1).max(MAX_ATTACHMENTS), + }), + ) .mutation(({ ctx, input }) => importCloudAttachments(ctx, input.fileIds)), /** @@ -168,12 +178,12 @@ export const attachmentsRouter = router({ .input( z.object({ workspaceId: z.string(), - fileIds: z.array(z.string().uuid()).min(1).max(10), + fileIds: z.array(z.string().uuid()).min(1).max(MAX_ATTACHMENTS), }), ) .mutation(async ({ ctx, input }) => { const worktreePath = resolveWorktreePath(ctx, input.workspaceId); - const directory = attachmentsDir(worktreePath); + const directory = ensureWorkspaceAttachmentsDir(worktreePath); const resolved = await ctx.api.attachment.resolve.mutate({ fileIds: input.fileIds, @@ -201,7 +211,7 @@ export const attachmentsRouter = router({ read: protectedProcedure .input(z.object({ attachmentId: z.string().uuid() })) .query(async ({ input }) => { - const resolved = resolveAttachmentPath(input.attachmentId); + const resolved = handOutAttachment(input.attachmentId); if (!resolved) { throw new TRPCError({ code: "NOT_FOUND", @@ -236,6 +246,8 @@ export const attachmentsRouter = router({ export type AttachmentUploadResult = { attachmentId: string; + /** Set when the bytes came from cloud storage: the identity a reader without this host resolves. */ + fileId?: string; originalFilename?: string; mediaType: string; sizeBytes: number; @@ -261,17 +273,22 @@ export async function importCloudAttachments( const resolved = await ctx.api.attachment.resolve.mutate({ fileIds }); const results: AttachmentUploadResult[] = []; for (const attachment of resolved) { - const metadata: AttachmentMetadata = { + const now = Date.now(); + const metadata = { attachmentId: randomUUID(), + fileId: attachment.fileId, mediaType: mediaTypeOf(attachment.contentType), originalFilename: attachment.name, sizeBytes: attachment.sizeBytes, - createdAt: Date.now(), - }; + createdAt: now, + lastUsedAt: now, + } satisfies AttachmentMetadata; await downloadAttachment(attachment, prepareAttachmentTarget(metadata)); writeAttachmentMetadata(metadata); + indexAttachmentFileId(metadata); results.push({ attachmentId: metadata.attachmentId, + fileId: metadata.fileId, originalFilename: metadata.originalFilename, mediaType: metadata.mediaType, sizeBytes: metadata.sizeBytes, diff --git a/packages/host-service/src/trpc/router/attachments/constants.ts b/packages/host-service/src/trpc/router/attachments/constants.ts deleted file mode 100644 index 7e0f02a29c2..00000000000 --- a/packages/host-service/src/trpc/router/attachments/constants.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Per-file cap on the inline upload — bytes sent base64 in the request body, - * so the ceiling is really the transport's rather than a product decision. - * `importFromCloud` has no equivalent limit here: those bytes arrive from - * cloud storage, and what a composer may send is decided by - * `@superset/shared/attachment-limits`. - */ -export const MAX_INLINE_ATTACHMENT_BYTES = 25 * 1024 * 1024; diff --git a/packages/host-service/src/trpc/router/attachments/index.ts b/packages/host-service/src/trpc/router/attachments/index.ts index 26fbefbf2f2..9cccede2c59 100644 --- a/packages/host-service/src/trpc/router/attachments/index.ts +++ b/packages/host-service/src/trpc/router/attachments/index.ts @@ -1,3 +1,3 @@ +export { MAX_INLINE_ATTACHMENT_BYTES } from "@superset/shared/attachment-limits"; export type { AttachmentUploadResult } from "./attachments"; export { attachmentsRouter, claimFileName } from "./attachments"; -export { MAX_INLINE_ATTACHMENT_BYTES } from "./constants"; diff --git a/packages/host-service/src/trpc/router/attachments/storage.ts b/packages/host-service/src/trpc/router/attachments/storage.ts index e2431ff3350..17ea410a4c8 100644 --- a/packages/host-service/src/trpc/router/attachments/storage.ts +++ b/packages/host-service/src/trpc/router/attachments/storage.ts @@ -3,9 +3,10 @@ import { mkdirSync, readFileSync, rmSync, + unlinkSync, writeFileSync, } from "node:fs"; -import { join } from "node:path"; +import { dirname, join } from "node:path"; import { resolveAppHomeDir } from "@superset/agent-setup/paths"; import mimeTypes from "mime-types"; @@ -15,8 +16,15 @@ export interface AttachmentMetadata { originalFilename?: string; sizeBytes: number; createdAt: number; + /** The storage object a box's cached copy was imported from. */ + fileId?: string; + /** Absent on an entry written before the store was swept. */ + lastUsedAt?: number; } +/** Inside the store root, so a sweep must skip it. */ +export const FILE_ID_INDEX_DIR = ".by-file-id"; + /** * Resolves the per-org attachment storage root. Honors * `HOST_MANIFEST_DIR` (set by host-service-coordinator with the active @@ -113,6 +121,8 @@ export function deleteAttachment( attachmentId: string, baseDirOverride?: string, ): void { + const metadata = readAttachmentMetadata(attachmentId, baseDirOverride); + if (metadata) unindexAttachmentFileId(metadata, baseDirOverride); const dir = getAttachmentDir(attachmentId, baseDirOverride); rmSync(dir, { recursive: true, force: true }); } @@ -148,3 +158,62 @@ export function resolveAttachmentPath( ); return existsSync(path) ? { path, metadata } : null; } + +/** Every path that hands an attachment out goes through here, so the sweep sees it as used. */ +export function handOutAttachment( + attachmentId: string, + baseDirOverride?: string, +): { path: string; metadata: AttachmentMetadata } | null { + const resolved = resolveAttachmentPath(attachmentId, baseDirOverride); + if (!resolved) return null; + const metadata = { ...resolved.metadata, lastUsedAt: Date.now() }; + writeAttachmentMetadata(metadata, baseDirOverride); + return { path: resolved.path, metadata }; +} + +const FILE_ID_PATTERN = /^[0-9a-f-]{36}$/i; + +function fileIdIndexPath(fileId: string, baseDirOverride?: string): string { + return join(getAttachmentsRoot(baseDirOverride), FILE_ID_INDEX_DIR, fileId); +} + +export function indexAttachmentFileId( + metadata: AttachmentMetadata & { fileId: string }, + baseDirOverride?: string, +): void { + const path = fileIdIndexPath(metadata.fileId, baseDirOverride); + mkdirSync(dirname(path), { recursive: true, mode: 0o700 }); + writeFileSync(path, metadata.attachmentId, { mode: 0o600 }); +} + +export function unindexAttachmentFileId( + metadata: AttachmentMetadata, + baseDirOverride?: string, +): void { + if (!metadata.fileId) return; + const path = fileIdIndexPath(metadata.fileId, baseDirOverride); + if (readIndexedAttachmentId(path) === metadata.attachmentId) unlinkSync(path); +} + +function readIndexedAttachmentId(path: string): string | null { + try { + return readFileSync(path, "utf-8"); + } catch { + return null; + } +} + +/** The cached copy of a storage object, as `handOutAttachment` hands it out. */ +export function handOutAttachmentByFileId( + fileId: string, + baseDirOverride?: string, +): { path: string; metadata: AttachmentMetadata } | null { + if (!FILE_ID_PATTERN.test(fileId)) return null; + const attachmentId = readIndexedAttachmentId( + fileIdIndexPath(fileId, baseDirOverride), + ); + if (!attachmentId) return null; + const metadata = readAttachmentMetadata(attachmentId, baseDirOverride); + if (metadata?.fileId !== fileId) return null; + return handOutAttachment(attachmentId, baseDirOverride); +} diff --git a/packages/host-service/src/trpc/router/attachments/sweep.test.ts b/packages/host-service/src/trpc/router/attachments/sweep.test.ts new file mode 100644 index 00000000000..628a1e94d88 --- /dev/null +++ b/packages/host-service/src/trpc/router/attachments/sweep.test.ts @@ -0,0 +1,103 @@ +import { afterEach, beforeEach, describe, expect, it } from "bun:test"; +import { existsSync, mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { + type AttachmentMetadata, + getAttachmentDir, + handOutAttachment, + handOutAttachmentByFileId, + indexAttachmentFileId, + readAttachmentMetadata, + writeAttachment, +} from "./storage"; +import { sweepAttachmentStore } from "./sweep"; + +const DAY_MS = 24 * 60 * 60 * 1000; +const NOW = Date.now() - 365 * DAY_MS; + +let base: string; + +beforeEach(() => { + base = mkdtempSync(join(tmpdir(), "superset-attachment-sweep-")); +}); + +afterEach(() => { + rmSync(base, { recursive: true, force: true }); +}); + +function seed(fields: Partial = {}): AttachmentMetadata { + const metadata: AttachmentMetadata = { + attachmentId: crypto.randomUUID(), + mediaType: "image/png", + sizeBytes: 1, + createdAt: NOW - 90 * DAY_MS, + ...fields, + }; + writeAttachment(new Uint8Array([1]), metadata, base); + return metadata; +} + +const sweep = () => + sweepAttachmentStore({ now: NOW, retentionDays: 30, baseDirOverride: base }); + +describe("sweepAttachmentStore", () => { + it("removes an entry unused past retention and keeps a recent one", async () => { + const stale = seed({ lastUsedAt: NOW - 31 * DAY_MS }); + const recent = seed({ lastUsedAt: NOW - 29 * DAY_MS }); + + expect((await sweep()).removed).toEqual([stale.attachmentId]); + expect(existsSync(getAttachmentDir(stale.attachmentId, base))).toBe(false); + expect(existsSync(getAttachmentDir(recent.attachmentId, base))).toBe(true); + }); + + it("stamps an entry from before lastUsedAt instead of removing it", async () => { + const unstamped = seed(); + + expect((await sweep()).removed).toEqual([]); + expect( + readAttachmentMetadata(unstamped.attachmentId, base)?.lastUsedAt, + ).toBe(NOW); + }); + + it("keeps an entry handed out after the pass started", async () => { + const stale = seed({ lastUsedAt: NOW - 31 * DAY_MS }); + + const pass = sweep(); + expect(handOutAttachment(stale.attachmentId, base)).not.toBeNull(); + + expect((await pass).removed).toEqual([]); + expect(existsSync(getAttachmentDir(stale.attachmentId, base))).toBe(true); + }); + + it("drops the fileId lookup with the entry it pointed to", async () => { + const fileId = crypto.randomUUID(); + const stale = seed({ fileId, lastUsedAt: NOW - 31 * DAY_MS }); + indexAttachmentFileId({ ...stale, fileId }, base); + + await sweep(); + expect(handOutAttachmentByFileId(fileId, base)).toBeNull(); + }); +}); + +describe("handOutAttachment", () => { + it("stamps the entry it hands out", () => { + const entry = seed({ lastUsedAt: NOW - 31 * DAY_MS }); + const handed = handOutAttachment(entry.attachmentId, base); + expect(handed?.metadata.lastUsedAt).toBeGreaterThan(NOW); + expect( + readAttachmentMetadata(entry.attachmentId, base)?.lastUsedAt, + ).toBeGreaterThan(NOW); + }); + + it("finds a cloud copy by its fileId and stamps it", () => { + const fileId = crypto.randomUUID(); + const entry = seed({ fileId, lastUsedAt: NOW - 31 * DAY_MS }); + indexAttachmentFileId({ ...entry, fileId }, base); + + const handed = handOutAttachmentByFileId(fileId, base); + expect(handed?.metadata.attachmentId).toBe(entry.attachmentId); + expect(handed?.metadata.lastUsedAt).toBeGreaterThan(NOW); + expect(handOutAttachmentByFileId(crypto.randomUUID(), base)).toBeNull(); + }); +}); diff --git a/packages/host-service/src/trpc/router/attachments/sweep.ts b/packages/host-service/src/trpc/router/attachments/sweep.ts new file mode 100644 index 00000000000..946934e1eac --- /dev/null +++ b/packages/host-service/src/trpc/router/attachments/sweep.ts @@ -0,0 +1,79 @@ +import { renameSync } from "node:fs"; +import { readdir, rm } from "node:fs/promises"; +import { join } from "node:path"; +import { ATTACHMENT_RETENTION_DAYS } from "@superset/shared/attachment-limits"; +import { + FILE_ID_INDEX_DIR, + getAttachmentsRoot, + readAttachmentMetadata, + unindexAttachmentFileId, + writeAttachmentMetadata, +} from "./storage"; + +const DAY_MS = 24 * 60 * 60 * 1000; +const SWEEPING_PREFIX = ".sweeping-"; + +export const ATTACHMENT_SWEEP_INTERVAL_MS = DAY_MS; + +/** + * Removes store entries nobody has used for `retentionDays`. An entry from + * before `lastUsedAt` existed is stamped now instead, so it gets the full + * retention from the first sweep. + */ +export async function sweepAttachmentStore({ + now = Date.now(), + retentionDays = ATTACHMENT_RETENTION_DAYS, + baseDirOverride, +}: { + now?: number; + retentionDays?: number; + baseDirOverride?: string; +} = {}): Promise<{ removed: string[] }> { + const root = getAttachmentsRoot(baseDirOverride); + const entries = await readdir(root).catch(() => [] as string[]); + const removed: string[] = []; + for (const entry of entries) { + if (entry.startsWith(SWEEPING_PREFIX)) { + await rm(join(root, entry), { recursive: true, force: true }); + continue; + } + if (entry === FILE_ID_INDEX_DIR) continue; + const doomed = claimIfUnused(entry, { + cutoff: now - retentionDays * DAY_MS, + now, + root, + baseDirOverride, + }); + if (!doomed) continue; + await rm(doomed, { recursive: true, force: true }); + removed.push(entry); + } + return { removed }; +} + +/** + * Synchronous from the metadata read to the rename, so a hand-out on this + * event loop can't run between the check and the removal. Once renamed, the + * entry is unreachable by id, and the slow delete can run async. + */ +function claimIfUnused( + attachmentId: string, + { + cutoff, + now, + root, + baseDirOverride, + }: { cutoff: number; now: number; root: string; baseDirOverride?: string }, +): string | null { + const metadata = readAttachmentMetadata(attachmentId, baseDirOverride); + if (!metadata) return null; + if (metadata.lastUsedAt === undefined) { + writeAttachmentMetadata({ ...metadata, lastUsedAt: now }, baseDirOverride); + return null; + } + if (metadata.lastUsedAt >= cutoff) return null; + unindexAttachmentFileId(metadata, baseDirOverride); + const doomed = join(root, `${SWEEPING_PREFIX}${attachmentId}`); + renameSync(join(root, attachmentId), doomed); + return doomed; +} diff --git a/packages/host-service/src/trpc/router/sessions/create-chat-session.ts b/packages/host-service/src/trpc/router/sessions/create-chat-session.ts index cbe0d58e036..ff73061bc0f 100644 --- a/packages/host-service/src/trpc/router/sessions/create-chat-session.ts +++ b/packages/host-service/src/trpc/router/sessions/create-chat-session.ts @@ -1,4 +1,5 @@ import type { ChatRuntime } from "@superset/chat-runtime"; +import type { ChatLaunchAttachment } from "../agents/agents"; import type { ChatSessionResult, CreateChatSessionInput, @@ -7,7 +8,7 @@ import type { type ChatTarget = { harness: string; label: string; - attachments: Array<{ attachmentId: string; name: string; mimeType: string }>; + attachments: ChatLaunchAttachment[]; }; export function createChatSession( diff --git a/packages/host-service/test/integration/trpc-request-body.integration.test.ts b/packages/host-service/test/integration/trpc-request-body.integration.test.ts new file mode 100644 index 00000000000..2baa91a704e --- /dev/null +++ b/packages/host-service/test/integration/trpc-request-body.integration.test.ts @@ -0,0 +1,66 @@ +import { afterAll, beforeAll, describe, expect, it } from "bun:test"; +import { createTestHost, type TestHost } from "../helpers/createTestHost"; + +let host: TestHost; + +beforeAll(async () => { + host = await createTestHost(); +}); + +afterAll(async () => { + await host.dispose(); +}); + +/** A request body that stays open until the test closes it. */ +function openBody(): { + stream: ReadableStream; + finish: (text: string) => void; +} { + let controller!: ReadableStreamDefaultController; + const stream = new ReadableStream({ + start(c) { + controller = c; + }, + }); + return { + stream, + finish(text) { + controller.enqueue(new TextEncoder().encode(text)); + controller.close(); + }, + }; +} + +describe("tRPC request bodies", () => { + // A sandbox's ingress drops the exchange when the host answers before the + // upload is complete, so a streamed batch must not start its response + // until the whole body has arrived. + it("does not answer a streamed batch before the body has fully arrived", async () => { + const body = openBody(); + let settled = false; + const response = host + .fetch("http://host-service.test/trpc/health.check?batch=1", { + method: "POST", + headers: { + authorization: `Bearer ${host.psk}`, + "content-type": "application/json", + "trpc-accept": "application/jsonl", + }, + body: body.stream, + // @ts-expect-error -- required by the Fetch spec for a stream body + duplex: "half", + }) + .then((res) => { + settled = true; + return res; + }); + + await new Promise((resolve) => setTimeout(resolve, 20)); + expect(settled).toBe(false); + + body.finish(JSON.stringify({ "0": { json: null } })); + const res = await response; + expect(res.status).toBe(200); + expect(await res.text()).toContain('"status":"ok"'); + }); +}); diff --git a/packages/host-service/undefined/worktrees/01017e7a-7b49-4a96-9d2f-08194c589568/fix-login-67cf0731/README.md b/packages/host-service/undefined/worktrees/01017e7a-7b49-4a96-9d2f-08194c589568/fix-login-67cf0731/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/01017e7a-7b49-4a96-9d2f-08194c589568/fix-login-67cf0731/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/066a7e6b-23b2-49e3-8286-1436201d840b/fix-login-6aae80e0/README.md b/packages/host-service/undefined/worktrees/066a7e6b-23b2-49e3-8286-1436201d840b/fix-login-6aae80e0/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/066a7e6b-23b2-49e3-8286-1436201d840b/fix-login-6aae80e0/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/0ff2771a-67a7-4834-96f3-50f1add0a8c1/fix-login-10cfe30e/README.md b/packages/host-service/undefined/worktrees/0ff2771a-67a7-4834-96f3-50f1add0a8c1/fix-login-10cfe30e/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/0ff2771a-67a7-4834-96f3-50f1add0a8c1/fix-login-10cfe30e/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/16702455-2a7a-436a-82d3-c6dd259165e9/team/fix-login-cd8985ff/README.md b/packages/host-service/undefined/worktrees/16702455-2a7a-436a-82d3-c6dd259165e9/team/fix-login-cd8985ff/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/16702455-2a7a-436a-82d3-c6dd259165e9/team/fix-login-cd8985ff/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/17344ed2-1498-4c3e-bbd7-337b1af7c44e/fix-login-f02297e8/README.md b/packages/host-service/undefined/worktrees/17344ed2-1498-4c3e-bbd7-337b1af7c44e/fix-login-f02297e8/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/17344ed2-1498-4c3e-bbd7-337b1af7c44e/fix-login-f02297e8/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/18dabdef-fac6-4a23-a807-d4b843e3b457/fix-login-325a16f1/README.md b/packages/host-service/undefined/worktrees/18dabdef-fac6-4a23-a807-d4b843e3b457/fix-login-325a16f1/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/18dabdef-fac6-4a23-a807-d4b843e3b457/fix-login-325a16f1/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/1b2c8bac-9da1-4898-bd94-cec5e01c8730/fix-login-b9ef52ac/README.md b/packages/host-service/undefined/worktrees/1b2c8bac-9da1-4898-bd94-cec5e01c8730/fix-login-b9ef52ac/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/1b2c8bac-9da1-4898-bd94-cec5e01c8730/fix-login-b9ef52ac/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/24848ea4-bc7a-42a7-8193-c535fcb3eecd/fix-login-4241817d/README.md b/packages/host-service/undefined/worktrees/24848ea4-bc7a-42a7-8193-c535fcb3eecd/fix-login-4241817d/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/24848ea4-bc7a-42a7-8193-c535fcb3eecd/fix-login-4241817d/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/24d2471e-e70f-4a7f-a2ef-16819519563e/fix-login-4c4de663/README.md b/packages/host-service/undefined/worktrees/24d2471e-e70f-4a7f-a2ef-16819519563e/fix-login-4c4de663/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/24d2471e-e70f-4a7f-a2ef-16819519563e/fix-login-4c4de663/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/2697d4a4-3f8d-4b9e-8999-e11a840406c9/fix-login-a9abda00/README.md b/packages/host-service/undefined/worktrees/2697d4a4-3f8d-4b9e-8999-e11a840406c9/fix-login-a9abda00/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/2697d4a4-3f8d-4b9e-8999-e11a840406c9/fix-login-a9abda00/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/26a8eaea-5d9f-4af6-acdb-a30e288cffbb/fix-login-c41be2c1/README.md b/packages/host-service/undefined/worktrees/26a8eaea-5d9f-4af6-acdb-a30e288cffbb/fix-login-c41be2c1/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/26a8eaea-5d9f-4af6-acdb-a30e288cffbb/fix-login-c41be2c1/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/2841c552-80c4-4cb8-84f1-5c8c121dd396/fix-login-873d9b87/README.md b/packages/host-service/undefined/worktrees/2841c552-80c4-4cb8-84f1-5c8c121dd396/fix-login-873d9b87/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/2841c552-80c4-4cb8-84f1-5c8c121dd396/fix-login-873d9b87/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/2fc79365-e18c-4879-98e3-cac5f33bf5e5/team/typed-branch/README.md b/packages/host-service/undefined/worktrees/2fc79365-e18c-4879-98e3-cac5f33bf5e5/team/typed-branch/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/2fc79365-e18c-4879-98e3-cac5f33bf5e5/team/typed-branch/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/3375e216-1179-424d-8c7d-9303c0b909dc/second-spruce-d84b8292/README.md b/packages/host-service/undefined/worktrees/3375e216-1179-424d-8c7d-9303c0b909dc/second-spruce-d84b8292/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/3375e216-1179-424d-8c7d-9303c0b909dc/second-spruce-d84b8292/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/3af0fdc3-d304-4ed9-929b-81516fab8908/fix-login-3e56a780/README.md b/packages/host-service/undefined/worktrees/3af0fdc3-d304-4ed9-929b-81516fab8908/fix-login-3e56a780/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/3af0fdc3-d304-4ed9-929b-81516fab8908/fix-login-3e56a780/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/3e5fffcc-c9c3-4a1b-8f80-8305a08ddb90/fix-login-7f92d196/README.md b/packages/host-service/undefined/worktrees/3e5fffcc-c9c3-4a1b-8f80-8305a08ddb90/fix-login-7f92d196/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/3e5fffcc-c9c3-4a1b-8f80-8305a08ddb90/fix-login-7f92d196/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/42222ad8-d6ba-44fe-846a-5dcf72072673/fix-login-1fd7ec20/README.md b/packages/host-service/undefined/worktrees/42222ad8-d6ba-44fe-846a-5dcf72072673/fix-login-1fd7ec20/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/42222ad8-d6ba-44fe-846a-5dcf72072673/fix-login-1fd7ec20/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/474dfd62-ce6d-46e7-b5b9-7ee232c542dc/explicit-a/README.md b/packages/host-service/undefined/worktrees/474dfd62-ce6d-46e7-b5b9-7ee232c542dc/explicit-a/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/474dfd62-ce6d-46e7-b5b9-7ee232c542dc/explicit-a/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/4942393d-245e-4d51-8e46-10e88b4b23f6/fix-login-190c250f/README.md b/packages/host-service/undefined/worktrees/4942393d-245e-4d51-8e46-10e88b4b23f6/fix-login-190c250f/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/4942393d-245e-4d51-8e46-10e88b4b23f6/fix-login-190c250f/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/4d32da0b-4048-48e0-b990-b1a3bdd534c4/fix-login-b79c4bad/README.md b/packages/host-service/undefined/worktrees/4d32da0b-4048-48e0-b990-b1a3bdd534c4/fix-login-b79c4bad/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/4d32da0b-4048-48e0-b990-b1a3bdd534c4/fix-login-b79c4bad/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/4f609fdf-a33c-4a12-bed1-05db2272b127/fix-login-1f3b8799/README.md b/packages/host-service/undefined/worktrees/4f609fdf-a33c-4a12-bed1-05db2272b127/fix-login-1f3b8799/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/4f609fdf-a33c-4a12-bed1-05db2272b127/fix-login-1f3b8799/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/5203447c-fada-4798-aef5-34c05d3a65a1/fix-login-ac841533/README.md b/packages/host-service/undefined/worktrees/5203447c-fada-4798-aef5-34c05d3a65a1/fix-login-ac841533/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/5203447c-fada-4798-aef5-34c05d3a65a1/fix-login-ac841533/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/54da92b3-79e9-4a68-b22b-ae2df3569e84/explicit-a/README.md b/packages/host-service/undefined/worktrees/54da92b3-79e9-4a68-b22b-ae2df3569e84/explicit-a/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/54da92b3-79e9-4a68-b22b-ae2df3569e84/explicit-a/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/579e47ee-0e91-47e2-a196-37ff8c6ab9ff/fix-login-44ec9970/README.md b/packages/host-service/undefined/worktrees/579e47ee-0e91-47e2-a196-37ff8c6ab9ff/fix-login-44ec9970/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/579e47ee-0e91-47e2-a196-37ff8c6ab9ff/fix-login-44ec9970/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/58ee600b-df7d-4589-b1b8-3808651b2a4b/what-git-rebase-84dd146c/README.md b/packages/host-service/undefined/worktrees/58ee600b-df7d-4589-b1b8-3808651b2a4b/what-git-rebase-84dd146c/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/58ee600b-df7d-4589-b1b8-3808651b2a4b/what-git-rebase-84dd146c/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/59306363-b823-4997-8f3b-dda7cd0c6d40/fix-login-957c17db/README.md b/packages/host-service/undefined/worktrees/59306363-b823-4997-8f3b-dda7cd0c6d40/fix-login-957c17db/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/59306363-b823-4997-8f3b-dda7cd0c6d40/fix-login-957c17db/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/5b2e5516-1971-498a-8f22-27437c56c686/fix-login-593e2b17/README.md b/packages/host-service/undefined/worktrees/5b2e5516-1971-498a-8f22-27437c56c686/fix-login-593e2b17/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/5b2e5516-1971-498a-8f22-27437c56c686/fix-login-593e2b17/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/675beb32-b86c-47ea-a833-3d96e7ecfa7b/what-git-rebase-044137a4/README.md b/packages/host-service/undefined/worktrees/675beb32-b86c-47ea-a833-3d96e7ecfa7b/what-git-rebase-044137a4/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/675beb32-b86c-47ea-a833-3d96e7ecfa7b/what-git-rebase-044137a4/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/77558d93-049b-40d0-a4e3-6653d0f003fd/fix-login-3c2e302f/README.md b/packages/host-service/undefined/worktrees/77558d93-049b-40d0-a4e3-6653d0f003fd/fix-login-3c2e302f/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/77558d93-049b-40d0-a4e3-6653d0f003fd/fix-login-3c2e302f/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/7789004e-ffc3-4975-be0b-5c7d8c6bac3d/fix-login-903c37ba/README.md b/packages/host-service/undefined/worktrees/7789004e-ffc3-4975-be0b-5c7d8c6bac3d/fix-login-903c37ba/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/7789004e-ffc3-4975-be0b-5c7d8c6bac3d/fix-login-903c37ba/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/83139903-2396-4c36-8e1b-7d2e311ea937/fix-login-b8e1150c/README.md b/packages/host-service/undefined/worktrees/83139903-2396-4c36-8e1b-7d2e311ea937/fix-login-b8e1150c/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/83139903-2396-4c36-8e1b-7d2e311ea937/fix-login-b8e1150c/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/8b4a0226-168a-4e01-a343-679dc547818b/team/typed-branch/README.md b/packages/host-service/undefined/worktrees/8b4a0226-168a-4e01-a343-679dc547818b/team/typed-branch/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/8b4a0226-168a-4e01-a343-679dc547818b/team/typed-branch/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/94c7f164-6f57-42e5-bf43-1630b3fb650d/my-workspace/README.md b/packages/host-service/undefined/worktrees/94c7f164-6f57-42e5-bf43-1630b3fb650d/my-workspace/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/94c7f164-6f57-42e5-bf43-1630b3fb650d/my-workspace/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/94f2904e-772d-44d7-b00f-42228adaeeb5/fix-login-2e40daa5/README.md b/packages/host-service/undefined/worktrees/94f2904e-772d-44d7-b00f-42228adaeeb5/fix-login-2e40daa5/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/94f2904e-772d-44d7-b00f-42228adaeeb5/fix-login-2e40daa5/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/957c7815-bc28-4611-b82d-ed875964a2b4/fix-login-9417ec7e/README.md b/packages/host-service/undefined/worktrees/957c7815-bc28-4611-b82d-ed875964a2b4/fix-login-9417ec7e/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/957c7815-bc28-4611-b82d-ed875964a2b4/fix-login-9417ec7e/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/9609bb27-7c51-4ef6-9c73-c36e1656f5c9/fix-login-c6c1cba2/README.md b/packages/host-service/undefined/worktrees/9609bb27-7c51-4ef6-9c73-c36e1656f5c9/fix-login-c6c1cba2/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/9609bb27-7c51-4ef6-9c73-c36e1656f5c9/fix-login-c6c1cba2/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/962e6d59-6f5f-4b77-b11d-17590ae306a6/fix-login-82c2b237/README.md b/packages/host-service/undefined/worktrees/962e6d59-6f5f-4b77-b11d-17590ae306a6/fix-login-82c2b237/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/962e6d59-6f5f-4b77-b11d-17590ae306a6/fix-login-82c2b237/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/992d0d5f-2899-4b69-aaa4-c598ad3ce75a/fix-login-9f382856/README.md b/packages/host-service/undefined/worktrees/992d0d5f-2899-4b69-aaa4-c598ad3ce75a/fix-login-9f382856/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/992d0d5f-2899-4b69-aaa4-c598ad3ce75a/fix-login-9f382856/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/a09de9b0-1471-4291-9eaf-f9b118b8ae63/fix-login-ad916343/README.md b/packages/host-service/undefined/worktrees/a09de9b0-1471-4291-9eaf-f9b118b8ae63/fix-login-ad916343/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/a09de9b0-1471-4291-9eaf-f9b118b8ae63/fix-login-ad916343/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/a0b8a037-6ae6-44b1-8c07-281b743bc43e/fix-login-4550fd47/README.md b/packages/host-service/undefined/worktrees/a0b8a037-6ae6-44b1-8c07-281b743bc43e/fix-login-4550fd47/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/a0b8a037-6ae6-44b1-8c07-281b743bc43e/fix-login-4550fd47/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/a94215c5-06e7-4ddb-9256-e5f7b58cc0de/fix-login-596f3d35/README.md b/packages/host-service/undefined/worktrees/a94215c5-06e7-4ddb-9256-e5f7b58cc0de/fix-login-596f3d35/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/a94215c5-06e7-4ddb-9256-e5f7b58cc0de/fix-login-596f3d35/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/aad987d7-beaa-437d-869b-cabf1560afe5/fix-login-7548db7b/README.md b/packages/host-service/undefined/worktrees/aad987d7-beaa-437d-869b-cabf1560afe5/fix-login-7548db7b/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/aad987d7-beaa-437d-869b-cabf1560afe5/fix-login-7548db7b/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/ac072299-17ec-4b35-a337-d09ab65d05de/fix-login-f935e51b/README.md b/packages/host-service/undefined/worktrees/ac072299-17ec-4b35-a337-d09ab65d05de/fix-login-f935e51b/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/ac072299-17ec-4b35-a337-d09ab65d05de/fix-login-f935e51b/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/ac1213d7-ec34-4d3c-9759-93d49c231f86/fix-login-e826c9cb/README.md b/packages/host-service/undefined/worktrees/ac1213d7-ec34-4d3c-9759-93d49c231f86/fix-login-e826c9cb/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/ac1213d7-ec34-4d3c-9759-93d49c231f86/fix-login-e826c9cb/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/af23535c-042d-4e4d-8e79-129d1fe8beba/fix-login-ac1d6896/README.md b/packages/host-service/undefined/worktrees/af23535c-042d-4e4d-8e79-129d1fe8beba/fix-login-ac1d6896/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/af23535c-042d-4e4d-8e79-129d1fe8beba/fix-login-ac1d6896/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/afe7d67c-b135-46ed-b17e-5dba57d9d60b/team/fix-login-4362d689/README.md b/packages/host-service/undefined/worktrees/afe7d67c-b135-46ed-b17e-5dba57d9d60b/team/fix-login-4362d689/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/afe7d67c-b135-46ed-b17e-5dba57d9d60b/team/fix-login-4362d689/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/b34d48f9-1f26-4b2d-8922-9b8b3bced6c8/fix-login-c670e5a5/README.md b/packages/host-service/undefined/worktrees/b34d48f9-1f26-4b2d-8922-9b8b3bced6c8/fix-login-c670e5a5/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/b34d48f9-1f26-4b2d-8922-9b8b3bced6c8/fix-login-c670e5a5/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/b5205b1c-47e7-43bc-99f9-3b82dc650da0/fix-login-a400891c/README.md b/packages/host-service/undefined/worktrees/b5205b1c-47e7-43bc-99f9-3b82dc650da0/fix-login-a400891c/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/b5205b1c-47e7-43bc-99f9-3b82dc650da0/fix-login-a400891c/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/b8538d2d-4d2a-4362-b014-27eaac785790/fix-login-55e2967d/README.md b/packages/host-service/undefined/worktrees/b8538d2d-4d2a-4362-b014-27eaac785790/fix-login-55e2967d/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/b8538d2d-4d2a-4362-b014-27eaac785790/fix-login-55e2967d/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/b88a6c16-e9e0-42ce-a62b-40c4f46e0b55/positive-motorcycle-490515f3/README.md b/packages/host-service/undefined/worktrees/b88a6c16-e9e0-42ce-a62b-40c4f46e0b55/positive-motorcycle-490515f3/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/b88a6c16-e9e0-42ce-a62b-40c4f46e0b55/positive-motorcycle-490515f3/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/b947e4f2-d7cd-4bb7-92b0-367740e6d5d6/fix-login-6b3c4611/README.md b/packages/host-service/undefined/worktrees/b947e4f2-d7cd-4bb7-92b0-367740e6d5d6/fix-login-6b3c4611/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/b947e4f2-d7cd-4bb7-92b0-367740e6d5d6/fix-login-6b3c4611/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/bb4beebd-6e97-4b60-801a-d6e8815d2e60/fix-login-6cdfbffc/README.md b/packages/host-service/undefined/worktrees/bb4beebd-6e97-4b60-801a-d6e8815d2e60/fix-login-6cdfbffc/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/bb4beebd-6e97-4b60-801a-d6e8815d2e60/fix-login-6cdfbffc/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/bc690917-d551-460c-bcea-9b90ce0a3bd7/fix-login-fd27475c/README.md b/packages/host-service/undefined/worktrees/bc690917-d551-460c-bcea-9b90ce0a3bd7/fix-login-fd27475c/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/bc690917-d551-460c-bcea-9b90ce0a3bd7/fix-login-fd27475c/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/c131738e-7063-4be6-96bd-c453d11e830e/fix-login-73cfe67d/README.md b/packages/host-service/undefined/worktrees/c131738e-7063-4be6-96bd-c453d11e830e/fix-login-73cfe67d/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/c131738e-7063-4be6-96bd-c453d11e830e/fix-login-73cfe67d/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/c1c7d29d-850a-413b-b46b-2249e3c581d2/fix-login-2ce7ee03/README.md b/packages/host-service/undefined/worktrees/c1c7d29d-850a-413b-b46b-2249e3c581d2/fix-login-2ce7ee03/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/c1c7d29d-850a-413b-b46b-2249e3c581d2/fix-login-2ce7ee03/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/c7efbdcf-1750-462e-b7db-33d38b2ea1a6/fix-login-eb8529e7/README.md b/packages/host-service/undefined/worktrees/c7efbdcf-1750-462e-b7db-33d38b2ea1a6/fix-login-eb8529e7/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/c7efbdcf-1750-462e-b7db-33d38b2ea1a6/fix-login-eb8529e7/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/ca100d58-27df-4bf8-958f-237f768aadfb/fix-login-169943be/README.md b/packages/host-service/undefined/worktrees/ca100d58-27df-4bf8-958f-237f768aadfb/fix-login-169943be/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/ca100d58-27df-4bf8-958f-237f768aadfb/fix-login-169943be/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/cd06a693-431b-4aaf-a053-a7b5285b0e1d/fix-login-ad19d69d/README.md b/packages/host-service/undefined/worktrees/cd06a693-431b-4aaf-a053-a7b5285b0e1d/fix-login-ad19d69d/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/cd06a693-431b-4aaf-a053-a7b5285b0e1d/fix-login-ad19d69d/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/e23363c7-78f9-44c2-abf4-41391fb7853a/fix-login-f07baf87/README.md b/packages/host-service/undefined/worktrees/e23363c7-78f9-44c2-abf4-41391fb7853a/fix-login-f07baf87/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/e23363c7-78f9-44c2-abf4-41391fb7853a/fix-login-f07baf87/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/eb94f4fe-2b6b-442b-a605-73b9ebc5d82c/energetic-apparatus-15b2ff09/README.md b/packages/host-service/undefined/worktrees/eb94f4fe-2b6b-442b-a605-73b9ebc5d82c/energetic-apparatus-15b2ff09/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/eb94f4fe-2b6b-442b-a605-73b9ebc5d82c/energetic-apparatus-15b2ff09/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/f0445291-c286-4ec9-8019-e171b5195f10/my-workspace/README.md b/packages/host-service/undefined/worktrees/f0445291-c286-4ec9-8019-e171b5195f10/my-workspace/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/f0445291-c286-4ec9-8019-e171b5195f10/my-workspace/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/f344110f-90ed-41c8-b6ce-d6d5a4c3e508/fix-login-a7fec0aa/README.md b/packages/host-service/undefined/worktrees/f344110f-90ed-41c8-b6ce-d6d5a4c3e508/fix-login-a7fec0aa/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/f344110f-90ed-41c8-b6ce-d6d5a4c3e508/fix-login-a7fec0aa/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/f5a30032-56f1-4cb9-976f-22251cccbdc0/fix-login-4fc97805/README.md b/packages/host-service/undefined/worktrees/f5a30032-56f1-4cb9-976f-22251cccbdc0/fix-login-4fc97805/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/f5a30032-56f1-4cb9-976f-22251cccbdc0/fix-login-4fc97805/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/fb3a5161-eefc-4660-81fa-23109f08e930/fix-login-74110ff0/README.md b/packages/host-service/undefined/worktrees/fb3a5161-eefc-4660-81fa-23109f08e930/fix-login-74110ff0/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/fb3a5161-eefc-4660-81fa-23109f08e930/fix-login-74110ff0/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/fcf23ce3-26a1-4b51-a3e5-c248471959b3/fix-login-c906ab23/README.md b/packages/host-service/undefined/worktrees/fcf23ce3-26a1-4b51-a3e5-c248471959b3/fix-login-c906ab23/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/fcf23ce3-26a1-4b51-a3e5-c248471959b3/fix-login-c906ab23/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/host-service/undefined/worktrees/fdf10566-c9f8-4bb8-a894-4b1317395277/east-trust-b2813850/README.md b/packages/host-service/undefined/worktrees/fdf10566-c9f8-4bb8-a894-4b1317395277/east-trust-b2813850/README.md new file mode 100644 index 00000000000..6d4d45bcd12 --- /dev/null +++ b/packages/host-service/undefined/worktrees/fdf10566-c9f8-4bb8-a894-4b1317395277/east-trust-b2813850/README.md @@ -0,0 +1 @@ +initial commit \ No newline at end of file diff --git a/packages/i18n/locales/cs/messages.po b/packages/i18n/locales/cs/messages.po index bb5bf495d14..ac2914622a9 100644 --- a/packages/i18n/locales/cs/messages.po +++ b/packages/i18n/locales/cs/messages.po @@ -67,12 +67,27 @@ msgstr "„{0}“ bude sloučen do {1} pomocí {2}. Odsud to nelze vrátit zpět msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "„{0}“ se přestane spouštět a její historie běhů bude odstraněna. Tuto akci nelze vrátit zpět." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "„{name}“ má {size} — soubory nad {limit} nelze připojit" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "„{name}“ má {size} — soubory nad {limit} nelze k tomuto pracovnímu prostoru připojit. Pokud je soubor na počítači pracovního prostoru, uveďte místo toho jeho cestu." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "„{name}“ je složka. Připojte místo toho soubory v ní." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "„{name}“ přesahuje {limit}, víc pracovní prostor mimo cloud nepřijme" + msgid "\"{name}\" paused" msgstr "„{name}“ pozastaveno" msgid "\"{name}\" resumed" msgstr "„{name}“ pokračuje" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "„{name}“ byl přesunut nebo smazán. Připojte ho znovu." + msgid "\"{title}\" has finished its task" msgstr "„{title}“ dokončil svůj úkol" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Použit # zdroj} few {Použity # zdroje} many {Pou msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {použit # nástroj} few {použity # nástroje} many {použito # nástroje} other {použito # nástrojů}}" +msgid "{count} files are over {limit} and were not added" +msgstr "Soubory nad {limit} nebyly přidány: {count}" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "Připojené soubory: {count} — zpráva může obsahovat nejvýše {max}" + msgid "{count} GitHub stars" msgstr "{count} hvězd na GitHubu" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — zapomenout tento web" +msgid "1 file is over {limit} and was not added" +msgstr "1 soubor přesahuje {limit} a nebyl přidán" + msgid "1 hr" msgstr "1 h" @@ -13885,6 +13909,9 @@ msgstr "Design systém Paradev" msgid "Paradev desktop app" msgstr "Desktopová aplikace Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev nemá oprávnění ke čtení „{name}“." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise je Paradev pro týmy. Ozvěte se a řekneme vám, co obsahuje a jak může fungovat ve vaší organizaci." @@ -19157,6 +19184,9 @@ msgstr "Stejná aplikace běží na iPadu nativně, na výšku i na šířku." msgid "The scorecard" msgstr "Hodnocení" +msgid "The selected element's context is too large to send" +msgstr "Kontext vybraného prvku je příliš velký na odeslání" + msgid "The self-driving software factory" msgstr "Samořídící softwarová továrna" @@ -21328,9 +21358,6 @@ msgstr "Pracovní prostor je otevřený, ale terminál se nepodařilo spustit." msgid "Workspace path is not available" msgstr "Cesta k pracovnímu prostoru není dostupná" -msgid "Workspace path is not available yet" -msgstr "Cesta pracovního prostoru zatím není dostupná" - msgid "Workspace restored" msgstr "Pracovní prostor obnoven" diff --git a/packages/i18n/locales/de/messages.po b/packages/i18n/locales/de/messages.po index fd95770a136..579b1d039ff 100644 --- a/packages/i18n/locales/de/messages.po +++ b/packages/i18n/locales/de/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" wird per {2} in {1} zusammengeführt. Das lässt sich von hier a msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" wird nicht mehr ausgelöst und der Ausführungsverlauf wird entfernt. Das lässt sich nicht rückgängig machen." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "„{name}“ ist {size} groß – Dateien über {limit} können nicht angehängt werden" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "„{name}“ ist {size} groß – Dateien über {limit} können an diesen Arbeitsbereich nicht angehängt werden. Liegt die Datei auf dem Rechner des Arbeitsbereichs, gib stattdessen ihren Pfad an." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" ist ein Ordner. Hänge stattdessen die Dateien darin an." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "„{name}“ ist größer als {limit} – mehr nimmt ein Arbeitsbereich außerhalb der Cloud nicht an" + msgid "\"{name}\" paused" msgstr "\"{name}\" pausiert" msgid "\"{name}\" resumed" msgstr "\"{name}\" fortgesetzt" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" wurde verschoben oder gelöscht. Hänge die Datei erneut an." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" hat seine Aufgabe abgeschlossen" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {# Quelle genutzt} other {# Quellen genutzt}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {# Werkzeug verwendet} other {# Werkzeuge verwendet}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} Dateien sind größer als {limit} und wurden nicht hinzugefügt" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} Dateien angehängt – eine Nachricht kann höchstens {max} enthalten" + msgid "{count} GitHub stars" msgstr "{count} GitHub-Stars" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 Cookie — diese Website vergessen" +msgid "1 file is over {limit} and was not added" +msgstr "1 Datei ist größer als {limit} und wurde nicht hinzugefügt" + msgid "1 hr" msgstr "1 Std." @@ -13885,6 +13909,9 @@ msgstr "Paradev Design System" msgid "Paradev desktop app" msgstr "Paradev-Desktop-App" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev hat keine Berechtigung, \"{name}\" zu lesen." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise ist Paradev für Teams. Melde dich, um mehr darüber zu erfahren, was enthalten ist und wie es für deine Organisation funktionieren kann." @@ -19157,6 +19184,9 @@ msgstr "Dieselbe App läuft nativ auf dem iPad, im Hoch- und im Querformat." msgid "The scorecard" msgstr "Der Scorecard" +msgid "The selected element's context is too large to send" +msgstr "Der Kontext des ausgewählten Elements ist zu groß zum Senden" + msgid "The self-driving software factory" msgstr "Die selbstfahrende Softwarefabrik" @@ -21328,9 +21358,6 @@ msgstr "Arbeitsbereich geöffnet, aber das Terminal konnte nicht starten." msgid "Workspace path is not available" msgstr "Pfad des Arbeitsbereichs ist nicht verfügbar" -msgid "Workspace path is not available yet" -msgstr "Der Workspace-Pfad ist noch nicht verfügbar" - msgid "Workspace restored" msgstr "Arbeitsbereich wiederhergestellt" diff --git a/packages/i18n/locales/en/messages.po b/packages/i18n/locales/en/messages.po index 21b3687efe5..87853881be4 100644 --- a/packages/i18n/locales/en/messages.po +++ b/packages/i18n/locales/en/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" will be merged into {1} via {2}. This can't be undone from here. msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" will stop firing and its run history will be removed. This can't be undone." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" is {size} — files over {limit} can't be attached" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" is a folder. Attach the files inside it instead." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" + msgid "\"{name}\" paused" msgstr "\"{name}\" paused" msgid "\"{name}\" resumed" msgstr "\"{name}\" resumed" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" was moved or deleted. Attach it again." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" has finished its task" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Used # source} other {Used # sources}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {used # tool} other {used # tools}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} files are over {limit} and were not added" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} files attached — a message carries at most {max}" + msgid "{count} GitHub stars" msgstr "{count} GitHub stars" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — forget this site" +msgid "1 file is over {limit} and was not added" +msgstr "1 file is over {limit} and was not added" + msgid "1 hr" msgstr "1 hr" @@ -13885,6 +13909,9 @@ msgstr "Paradev Design System" msgid "Paradev desktop app" msgstr "Paradev desktop app" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev doesn't have permission to read \"{name}\"." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." @@ -19157,6 +19184,9 @@ msgstr "The same app runs natively on iPad, in portrait and landscape." msgid "The scorecard" msgstr "The scorecard" +msgid "The selected element's context is too large to send" +msgstr "The selected element's context is too large to send" + msgid "The self-driving software factory" msgstr "The self-driving software factory" @@ -21328,9 +21358,6 @@ msgstr "Workspace opened, but terminal failed to start." msgid "Workspace path is not available" msgstr "Workspace path is not available" -msgid "Workspace path is not available yet" -msgstr "Workspace path is not available yet" - msgid "Workspace restored" msgstr "Workspace restored" diff --git a/packages/i18n/locales/es/messages.po b/packages/i18n/locales/es/messages.po index 0bfc3e037c8..724d08d55bf 100644 --- a/packages/i18n/locales/es/messages.po +++ b/packages/i18n/locales/es/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" se fusionará en {1} mediante {2}. No se puede deshacer desde aq msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" dejará de dispararse y se eliminará su historial de ejecuciones. Esto no se puede deshacer." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "«{name}» ocupa {size}: no se pueden adjuntar archivos de más de {limit}" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "«{name}» ocupa {size}: no se pueden adjuntar archivos de más de {limit} a este espacio de trabajo. Si el archivo está en la máquina del espacio de trabajo, menciona su ruta." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" es una carpeta. Adjunta los archivos que contiene." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "«{name}» supera {limit}, el máximo que admite un espacio de trabajo fuera de la nube" + msgid "\"{name}\" paused" msgstr "\"{name}\" en pausa" msgid "\"{name}\" resumed" msgstr "\"{name}\" reanudada" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" se movió o se eliminó. Vuelve a adjuntarlo." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" ha terminado su tarea" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Se usó # fuente} other {Se usaron # fuentes}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {usó # herramienta} other {usó # herramientas}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} archivos superan {limit} y no se añadieron" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} archivos adjuntos: un mensaje admite como máximo {max}" + msgid "{count} GitHub stars" msgstr "{count} estrellas en GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie: olvidar este sitio" +msgid "1 file is over {limit} and was not added" +msgstr "1 archivo supera {limit} y no se añadió" + msgid "1 hr" msgstr "1 h" @@ -13885,6 +13909,9 @@ msgstr "Sistema de diseño de Paradev" msgid "Paradev desktop app" msgstr "App de escritorio de Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev no tiene permiso para leer \"{name}\"." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise es Paradev para equipos. Escríbenos para saber más sobre lo que incluye y cómo puede funcionar en tu organización." @@ -19157,6 +19184,9 @@ msgstr "La misma app funciona de forma nativa en iPad, en vertical y en horizont msgid "The scorecard" msgstr "El cuadro de resultados" +msgid "The selected element's context is too large to send" +msgstr "El contexto del elemento seleccionado es demasiado grande para enviarlo" + msgid "The self-driving software factory" msgstr "La fábrica de software autónoma" @@ -21328,9 +21358,6 @@ msgstr "El espacio de trabajo se abrió, pero el terminal no se pudo iniciar." msgid "Workspace path is not available" msgstr "La ruta del espacio de trabajo no está disponible" -msgid "Workspace path is not available yet" -msgstr "La ruta del espacio de trabajo aún no está disponible" - msgid "Workspace restored" msgstr "Espacio de trabajo restaurado" diff --git a/packages/i18n/locales/fr/messages.po b/packages/i18n/locales/fr/messages.po index e484cd67037..4a192f417b7 100644 --- a/packages/i18n/locales/fr/messages.po +++ b/packages/i18n/locales/fr/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" sera fusionnée dans {1} via {2}. Cette action est irréversible msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "« {0} » ne se déclenchera plus et son historique d'exécutions sera supprimé. Cette action est irréversible." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "« {name} » fait {size} — les fichiers de plus de {limit} ne peuvent pas être joints" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "« {name} » fait {size} — les fichiers de plus de {limit} ne peuvent pas être joints à cet espace de travail. Si le fichier se trouve sur la machine de l’espace de travail, indiquez plutôt son chemin." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "« {name} » est un dossier. Joignez plutôt les fichiers qu’il contient." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "« {name} » dépasse {limit}, le maximum qu’accepte un espace de travail hors du cloud" + msgid "\"{name}\" paused" msgstr "« {name} » mise en pause" msgid "\"{name}\" resumed" msgstr "« {name} » reprise" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "« {name} » a été déplacé ou supprimé. Joignez-le à nouveau." + msgid "\"{title}\" has finished its task" msgstr "« {title} » a terminé sa tâche" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {# source utilisée} other {# sources utilisées}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {# outil utilisé} other {# outils utilisés}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} fichiers dépassent {limit} et n’ont pas été ajoutés" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} fichiers joints — un message en contient au plus {max}" + msgid "{count} GitHub stars" msgstr "{count} étoiles GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — oublier ce site" +msgid "1 file is over {limit} and was not added" +msgstr "1 fichier dépasse {limit} et n’a pas été ajouté" + msgid "1 hr" msgstr "1 h" @@ -13885,6 +13909,9 @@ msgstr "Système de design Paradev" msgid "Paradev desktop app" msgstr "Application de bureau Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev n’a pas l’autorisation de lire « {name} »." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise, c'est Paradev pour les équipes. Contactez-nous pour savoir ce qu'il comprend et comment il peut s'adapter à votre organisation." @@ -19157,6 +19184,9 @@ msgstr "La même app fonctionne nativement sur iPad, en portrait comme en paysag msgid "The scorecard" msgstr "Le bilan" +msgid "The selected element's context is too large to send" +msgstr "Le contexte de l’élément sélectionné est trop volumineux pour être envoyé" + msgid "The self-driving software factory" msgstr "L'usine logicielle autonome" @@ -21328,9 +21358,6 @@ msgstr "Espace de travail ouvert, mais le terminal n'a pas démarré." msgid "Workspace path is not available" msgstr "Le chemin de l'espace de travail n'est pas disponible" -msgid "Workspace path is not available yet" -msgstr "Le chemin de l’espace de travail n’est pas encore disponible" - msgid "Workspace restored" msgstr "Espace de travail restauré" diff --git a/packages/i18n/locales/id/messages.po b/packages/i18n/locales/id/messages.po index 210a0bc4b57..659ae97b739 100644 --- a/packages/i18n/locales/id/messages.po +++ b/packages/i18n/locales/id/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" akan di-merge ke {1} lewat {2}. Ini tidak bisa dibatalkan dari s msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" akan berhenti berjalan dan riwayat run-nya akan dihapus. Ini tidak bisa dibatalkan." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" berukuran {size} — file di atas {limit} tidak dapat dilampirkan" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" berukuran {size} — file di atas {limit} tidak dapat dilampirkan ke workspace ini. Jika file ada di mesin workspace, sebutkan path-nya saja." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" adalah folder. Lampirkan file di dalamnya sebagai gantinya." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" melebihi {limit}, batas maksimum untuk workspace di luar cloud" + msgid "\"{name}\" paused" msgstr "\"{name}\" dijeda" msgid "\"{name}\" resumed" msgstr "\"{name}\" dilanjutkan" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" telah dipindahkan atau dihapus. Lampirkan lagi." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" telah menyelesaikan tugasnya" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Memakai # sumber} other {Memakai # sumber}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {menggunakan # alat} other {menggunakan # alat}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} file melebihi {limit} dan tidak ditambahkan" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} file dilampirkan — satu pesan memuat paling banyak {max}" + msgid "{count} GitHub stars" msgstr "{count} star GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — lupakan situs ini" +msgid "1 file is over {limit} and was not added" +msgstr "1 file melebihi {limit} dan tidak ditambahkan" + msgid "1 hr" msgstr "1 jam" @@ -13885,6 +13909,9 @@ msgstr "Design System Paradev" msgid "Paradev desktop app" msgstr "Aplikasi desktop Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev tidak memiliki izin untuk membaca \"{name}\"." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise adalah Paradev untuk tim. Hubungi kami untuk tahu lebih banyak soal apa saja yang termasuk dan bagaimana cocoknya untuk organisasi Anda." @@ -19157,6 +19184,9 @@ msgstr "Aplikasi yang sama berjalan native di iPad, dalam mode potret dan lanska msgid "The scorecard" msgstr "Kartu skor" +msgid "The selected element's context is too large to send" +msgstr "Konteks elemen yang dipilih terlalu besar untuk dikirim" + msgid "The self-driving software factory" msgstr "Pabrik perangkat lunak yang menyetir sendiri" @@ -21328,9 +21358,6 @@ msgstr "Workspace terbuka, tapi terminal gagal dijalankan." msgid "Workspace path is not available" msgstr "Path workspace tidak tersedia" -msgid "Workspace path is not available yet" -msgstr "Jalur ruang kerja belum tersedia" - msgid "Workspace restored" msgstr "Workspace dipulihkan" diff --git a/packages/i18n/locales/it/messages.po b/packages/i18n/locales/it/messages.po index 077a8ff463b..196b28e9abc 100644 --- a/packages/i18n/locales/it/messages.po +++ b/packages/i18n/locales/it/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" verrà unita in {1} tramite {2}. L'operazione non può essere an msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" smetterà di scattare e la sua cronologia delle esecuzioni verrà rimossa. L'operazione non può essere annullata." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" pesa {size}: non è possibile allegare file più grandi di {limit}" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" pesa {size}: non è possibile allegare a questo workspace file più grandi di {limit}. Se il file si trova sulla macchina del workspace, indica invece il suo percorso." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" è una cartella. Allega invece i file al suo interno." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" supera {limit}, il massimo che un workspace fuori dal cloud può ricevere" + msgid "\"{name}\" paused" msgstr "\"{name}\" messa in pausa" msgid "\"{name}\" resumed" msgstr "\"{name}\" ripresa" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" è stato spostato o eliminato. Allegalo di nuovo." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" ha completato il suo task" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Usata # fonte} other {Usate # fonti}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {usato # strumento} other {usati # strumenti}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} file superano {limit} e non sono stati aggiunti" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} file allegati: un messaggio ne può contenere al massimo {max}" + msgid "{count} GitHub stars" msgstr "{count} star su GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — dimentica questo sito" +msgid "1 file is over {limit} and was not added" +msgstr "1 file supera {limit} e non è stato aggiunto" + msgid "1 hr" msgstr "1 h" @@ -13885,6 +13909,9 @@ msgstr "Paradev Design System" msgid "Paradev desktop app" msgstr "App desktop di Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev non ha l'autorizzazione per leggere \"{name}\"." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise è Paradev per i team. Contattaci per sapere cosa include e come può funzionare per la tua organizzazione." @@ -19157,6 +19184,9 @@ msgstr "La stessa app funziona in modo nativo su iPad, in verticale e in orizzon msgid "The scorecard" msgstr "La scheda di valutazione" +msgid "The selected element's context is too large to send" +msgstr "Il contesto dell’elemento selezionato è troppo grande per essere inviato" + msgid "The self-driving software factory" msgstr "La fabbrica di software a guida autonoma" @@ -21328,9 +21358,6 @@ msgstr "Workspace aperto, ma il terminale non è partito." msgid "Workspace path is not available" msgstr "Il percorso del workspace non è disponibile" -msgid "Workspace path is not available yet" -msgstr "Il percorso dello spazio di lavoro non è ancora disponibile" - msgid "Workspace restored" msgstr "Workspace ripristinato" diff --git a/packages/i18n/locales/ja/messages.po b/packages/i18n/locales/ja/messages.po index bbdd2294d12..aad4a5524df 100644 --- a/packages/i18n/locales/ja/messages.po +++ b/packages/i18n/locales/ja/messages.po @@ -67,12 +67,27 @@ msgstr "「{0}」は{2}で{1}にマージされます。ここからは元に戻 msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "「{0}」は発火しなくなり、実行履歴も削除されます。この操作は元に戻せません。" +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "「{name}」は {size} です — {limit} を超えるファイルは添付できません" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "「{name}」は {size} です — このワークスペースには {limit} を超えるファイルを添付できません。ファイルがワークスペースのマシン上にある場合は、代わりにそのパスを記載してください。" + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "「{name}」はフォルダです。代わりにフォルダ内のファイルを添付してください。" + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "「{name}」は {limit} を超えています。クラウド外のワークスペースが受け取れるのは {limit} までです" + msgid "\"{name}\" paused" msgstr "「{name}」を一時停止しました" msgid "\"{name}\" resumed" msgstr "「{name}」を再開しました" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "「{name}」は移動または削除されました。もう一度添付してください。" + msgid "\"{title}\" has finished its task" msgstr "「{title}」がタスクを完了しました" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {#件のソースを使用} other {#件のソース msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {#件のツールを使用} other {#件のツールを使用}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} 件のファイルが {limit} を超えているため追加されませんでした" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} 件のファイルが添付されています — 1 つのメッセージに添付できるのは最大 {max} 件です" + msgid "{count} GitHub stars" msgstr "GitHubスター{count}件" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1件のCookie — このサイトを削除" +msgid "1 file is over {limit} and was not added" +msgstr "1 件のファイルが {limit} を超えているため追加されませんでした" + msgid "1 hr" msgstr "1時間" @@ -13885,6 +13909,9 @@ msgstr "Paradevデザインシステム" msgid "Paradev desktop app" msgstr "Paradev デスクトップアプリ" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev には「{name}」を読み取る権限がありません。" + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterpriseは、チーム向けのParadevです。含まれる内容や組織での活用方法については、お問い合わせください。" @@ -19157,6 +19184,9 @@ msgstr "同じアプリが iPad でネイティブに動作し、縦向きにも msgid "The scorecard" msgstr "スコアカード" +msgid "The selected element's context is too large to send" +msgstr "選択した要素のコンテキストが大きすぎるため送信できません" + msgid "The self-driving software factory" msgstr "自動運転するソフトウェア工場" @@ -21328,9 +21358,6 @@ msgstr "ワークスペースを開きましたが、ターミナルを起動で msgid "Workspace path is not available" msgstr "ワークスペースのパスを利用できません" -msgid "Workspace path is not available yet" -msgstr "ワークスペースのパスはまだ利用できません" - msgid "Workspace restored" msgstr "ワークスペースを復元しました" diff --git a/packages/i18n/locales/ko/messages.po b/packages/i18n/locales/ko/messages.po index c6cec17718f..a80b14e3ddb 100644 --- a/packages/i18n/locales/ko/messages.po +++ b/packages/i18n/locales/ko/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\"이(가) {2} 방식으로 {1}에 머지됩니다. 여기에서는 msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\"이(가) 더 이상 실행되지 않으며 실행 기록도 삭제됩니다. 되돌릴 수 없습니다." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\"의 크기는 {size}입니다 — {limit}를 넘는 파일은 첨부할 수 없습니다" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\"의 크기는 {size}입니다 — 이 워크스페이스에는 {limit}를 넘는 파일을 첨부할 수 없습니다. 파일이 워크스페이스의 머신에 있다면 대신 경로를 적어 주세요." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\"은(는) 폴더입니다. 대신 폴더 안의 파일을 첨부하세요." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\"이(가) {limit}를 넘습니다. 클라우드 밖의 워크스페이스는 최대 {limit}까지 받을 수 있습니다" + msgid "\"{name}\" paused" msgstr "\"{name}\"을(를) 일시 중지했습니다" msgid "\"{name}\" resumed" msgstr "\"{name}\"을(를) 재개했습니다" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\"이(가) 이동되었거나 삭제되었습니다. 다시 첨부하세요." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\"이(가) 작업을 완료했습니다" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {출처 #개 사용} other {출처 #개 사용}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {도구 #개 사용} other {도구 #개 사용}}" +msgid "{count} files are over {limit} and were not added" +msgstr "파일 {count}개가 {limit}를 넘어 추가되지 않았습니다" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "파일 {count}개가 첨부됨 — 메시지 하나에는 최대 {max}개까지 첨부할 수 있습니다" + msgid "{count} GitHub stars" msgstr "GitHub 스타 {count}개" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "쿠키 1개 — 이 사이트 잊기" +msgid "1 file is over {limit} and was not added" +msgstr "파일 1개가 {limit}를 넘어 추가되지 않았습니다" + msgid "1 hr" msgstr "1시간" @@ -13885,6 +13909,9 @@ msgstr "Paradev 디자인 시스템" msgid "Paradev desktop app" msgstr "Paradev 데스크톱 앱" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev에 \"{name}\"을(를) 읽을 권한이 없습니다." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise는 팀을 위한 Paradev입니다. 어떤 기능이 포함되고 조직에 어떻게 적용할 수 있는지 문의해 주세요." @@ -19157,6 +19184,9 @@ msgstr "같은 앱이 iPad에서 네이티브로 실행되며 세로와 가로 msgid "The scorecard" msgstr "성적표" +msgid "The selected element's context is too large to send" +msgstr "선택한 요소의 컨텍스트가 너무 커서 보낼 수 없습니다" + msgid "The self-driving software factory" msgstr "자율 주행 소프트웨어 공장" @@ -21328,9 +21358,6 @@ msgstr "워크스페이스를 열었지만 터미널을 시작하지 못했습 msgid "Workspace path is not available" msgstr "워크스페이스 경로를 사용할 수 없습니다" -msgid "Workspace path is not available yet" -msgstr "작업 공간 경로를 아직 사용할 수 없습니다" - msgid "Workspace restored" msgstr "워크스페이스를 복원했습니다" diff --git a/packages/i18n/locales/nl/messages.po b/packages/i18n/locales/nl/messages.po index 45c8d9a3c92..05503982939 100644 --- a/packages/i18n/locales/nl/messages.po +++ b/packages/i18n/locales/nl/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" wordt via {2} in {1} gemerged. Dit kan hier niet ongedaan worden msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" wordt niet meer geactiveerd en de geschiedenis van runs wordt verwijderd. Dit kan niet ongedaan worden gemaakt." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" is {size} — bestanden groter dan {limit} kunnen niet worden bijgevoegd" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" is {size} — bestanden groter dan {limit} kunnen niet aan deze werkruimte worden bijgevoegd. Staat het bestand op de machine van de werkruimte, noem dan in plaats daarvan het pad." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" is een map. Voeg in plaats daarvan de bestanden in de map toe." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" is groter dan {limit}, het maximum dat een werkruimte buiten de cloud aankan" + msgid "\"{name}\" paused" msgstr "\"{name}\" gepauzeerd" msgid "\"{name}\" resumed" msgstr "\"{name}\" hervat" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" is verplaatst of verwijderd. Voeg het opnieuw toe." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" is klaar met de taak" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {# bron gebruikt} other {# bronnen gebruikt}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {# tool gebruikt} other {# tools gebruikt}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} bestanden zijn groter dan {limit} en zijn niet toegevoegd" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} bestanden bijgevoegd — een bericht kan er maximaal {max} bevatten" + msgid "{count} GitHub stars" msgstr "{count} GitHub-sterren" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — deze site vergeten" +msgid "1 file is over {limit} and was not added" +msgstr "1 bestand is groter dan {limit} en is niet toegevoegd" + msgid "1 hr" msgstr "1 u" @@ -13885,6 +13909,9 @@ msgstr "Paradev Design System" msgid "Paradev desktop app" msgstr "Paradev-desktopapp" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev heeft geen toestemming om \"{name}\" te lezen." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise is Paradev voor teams. Neem contact op om te horen wat erbij zit en hoe het voor jouw organisatie kan werken." @@ -19157,6 +19184,9 @@ msgstr "Dezelfde app draait native op iPad, staand en liggend." msgid "The scorecard" msgstr "De scorekaart" +msgid "The selected element's context is too large to send" +msgstr "De context van het geselecteerde element is te groot om te verzenden" + msgid "The self-driving software factory" msgstr "De zelfrijdende softwarefabriek" @@ -21328,9 +21358,6 @@ msgstr "Werkruimte geopend, maar de terminal kon niet starten." msgid "Workspace path is not available" msgstr "Pad van werkruimte is niet beschikbaar" -msgid "Workspace path is not available yet" -msgstr "Het werkruimtepad is nog niet beschikbaar" - msgid "Workspace restored" msgstr "Werkruimte hersteld" diff --git a/packages/i18n/locales/pl/messages.po b/packages/i18n/locales/pl/messages.po index 83acb4d20aa..78746167f3e 100644 --- a/packages/i18n/locales/pl/messages.po +++ b/packages/i18n/locales/pl/messages.po @@ -67,12 +67,27 @@ msgstr "„{0}” zostanie scalony do {1} przez {2}. Nie można tego stąd cofn msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "„{0}” przestanie się uruchamiać, a jej historia uruchomień zostanie usunięta. Tej operacji nie można cofnąć." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "„{name}” ma {size} — nie można załączać plików większych niż {limit}" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "„{name}” ma {size} — do tego obszaru roboczego nie można załączać plików większych niż {limit}. Jeśli plik jest na maszynie obszaru roboczego, podaj zamiast tego jego ścieżkę." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "„{name}” to folder. Zamiast tego załącz pliki z jego wnętrza." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "„{name}” przekracza {limit} — tyle maksymalnie przyjmuje obszar roboczy poza chmurą" + msgid "\"{name}\" paused" msgstr "„{name}” wstrzymana" msgid "\"{name}\" resumed" msgstr "„{name}” wznowiona" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "„{name}” został przeniesiony lub usunięty. Załącz go ponownie." + msgid "\"{title}\" has finished its task" msgstr "„{title}” zakończył swoje zadanie" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Użyto # źródła} few {Użyto # źródeł} many { msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {użyto # narzędzia} few {użyto # narzędzi} many {użyto # narzędzi} other {użyto # narzędzia}}" +msgid "{count} files are over {limit} and were not added" +msgstr "Pliki większe niż {limit} nie zostały dodane: {count}" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "Załączone pliki: {count} — wiadomość może zawierać najwyżej {max}" + msgid "{count} GitHub stars" msgstr "{count} gwiazdek GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — zapomnij tę witrynę" +msgid "1 file is over {limit} and was not added" +msgstr "1 plik jest większy niż {limit} i nie został dodany" + msgid "1 hr" msgstr "1 godz." @@ -13885,6 +13909,9 @@ msgstr "System projektowy Paradev" msgid "Paradev desktop app" msgstr "Aplikacja desktopowa Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev nie ma uprawnień do odczytu „{name}”." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise to Paradev dla zespołów. Odezwij się, aby dowiedzieć się, co obejmuje i jak może zadziałać w Twojej organizacji." @@ -19157,6 +19184,9 @@ msgstr "Ta sama aplikacja działa natywnie na iPadzie, w pionie i w poziomie." msgid "The scorecard" msgstr "Karta wyników" +msgid "The selected element's context is too large to send" +msgstr "Kontekst wybranego elementu jest zbyt duży, aby go wysłać" + msgid "The self-driving software factory" msgstr "Samojezdna fabryka oprogramowania" @@ -21328,9 +21358,6 @@ msgstr "Obszar roboczy otwarty, ale terminal się nie uruchomił." msgid "Workspace path is not available" msgstr "Ścieżka obszaru roboczego jest niedostępna" -msgid "Workspace path is not available yet" -msgstr "Ścieżka obszaru roboczego nie jest jeszcze dostępna" - msgid "Workspace restored" msgstr "Przywrócono obszar roboczy" diff --git a/packages/i18n/locales/pt-BR/messages.po b/packages/i18n/locales/pt-BR/messages.po index a174474ad4a..bdbe50844f2 100644 --- a/packages/i18n/locales/pt-BR/messages.po +++ b/packages/i18n/locales/pt-BR/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" será mesclado em {1} via {2}. Não dá para desfazer daqui." msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" vai parar de disparar e seu histórico de execuções será removido. Não dá para desfazer." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" tem {size} — arquivos com mais de {limit} não podem ser anexados" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" tem {size} — arquivos com mais de {limit} não podem ser anexados a esta área de trabalho. Se o arquivo estiver na máquina da área de trabalho, mencione o caminho dele." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" é uma pasta. Anexe os arquivos que estão nela." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" passa de {limit}, o máximo que uma área de trabalho fora da nuvem aceita" + msgid "\"{name}\" paused" msgstr "\"{name}\" pausada" msgid "\"{name}\" resumed" msgstr "\"{name}\" retomada" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" foi movido ou excluído. Anexe-o novamente." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" terminou a tarefa" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Usou # fonte} other {Usou # fontes}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {usou # ferramenta} other {usou # ferramentas}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} arquivos passam de {limit} e não foram adicionados" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} arquivos anexados — uma mensagem leva no máximo {max}" + msgid "{count} GitHub stars" msgstr "{count} estrelas no GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — esquecer este site" +msgid "1 file is over {limit} and was not added" +msgstr "1 arquivo passa de {limit} e não foi adicionado" + msgid "1 hr" msgstr "1 h" @@ -13885,6 +13909,9 @@ msgstr "Design System do Paradev" msgid "Paradev desktop app" msgstr "App para desktop do Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "O Paradev não tem permissão para ler \"{name}\"." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "O Paradev Enterprise é o Paradev para times. Fale com a gente para saber o que está incluído e como ele pode funcionar na sua organização." @@ -19157,6 +19184,9 @@ msgstr "O mesmo app roda nativamente no iPad, na vertical e na horizontal." msgid "The scorecard" msgstr "O placar" +msgid "The selected element's context is too large to send" +msgstr "O contexto do elemento selecionado é grande demais para ser enviado" + msgid "The self-driving software factory" msgstr "A fábrica de software autônoma" @@ -21328,9 +21358,6 @@ msgstr "Área de trabalho aberta, mas o terminal não iniciou." msgid "Workspace path is not available" msgstr "O caminho da área de trabalho não está disponível" -msgid "Workspace path is not available yet" -msgstr "O caminho do espaço de trabalho ainda não está disponível" - msgid "Workspace restored" msgstr "Área de trabalho restaurada" diff --git a/packages/i18n/locales/ru/messages.po b/packages/i18n/locales/ru/messages.po index 24b0f225af8..1e19bd23839 100644 --- a/packages/i18n/locales/ru/messages.po +++ b/packages/i18n/locales/ru/messages.po @@ -67,12 +67,27 @@ msgstr "«{0}» будет объединён в {1} через {2}. Отмен msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "«{0}» перестанет срабатывать, а история её запусков будет удалена. Это нельзя отменить." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "«{name}» занимает {size} — файлы больше {limit} прикрепить нельзя" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "«{name}» занимает {size} — к этой рабочей области нельзя прикрепить файлы больше {limit}. Если файл находится на машине рабочей области, укажите вместо этого его путь." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "«{name}» — это папка. Прикрепите файлы из неё." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "«{name}» больше {limit} — это максимум для рабочей области вне облака" + msgid "\"{name}\" paused" msgstr "«{name}» приостановлена" msgid "\"{name}\" resumed" msgstr "«{name}» возобновлена" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "«{name}» перемещён или удалён. Прикрепите его снова." + msgid "\"{title}\" has finished its task" msgstr "«{title}» завершил задачу" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Использован # источник} few {И msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {использован # инструмент} few {использовано # инструмента} many {использовано # инструментов} other {использовано # инструмента}}" +msgid "{count} files are over {limit} and were not added" +msgstr "Файлы больше {limit} не добавлены: {count}" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "Прикреплено файлов: {count} — в одном сообщении не больше {max}" + msgid "{count} GitHub stars" msgstr "{count} звёзд на GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — забыть этот сайт" +msgid "1 file is over {limit} and was not added" +msgstr "1 файл больше {limit} и не был добавлен" + msgid "1 hr" msgstr "1 ч" @@ -13885,6 +13909,9 @@ msgstr "Дизайн-система Paradev" msgid "Paradev desktop app" msgstr "Десктопное приложение Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "У Paradev нет разрешения на чтение «{name}»." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise — это Paradev для команд. Напишите нам, чтобы узнать, что входит и как это подойдёт вашей организации." @@ -19157,6 +19184,9 @@ msgstr "То же приложение работает на iPad нативно msgid "The scorecard" msgstr "Таблица оценок" +msgid "The selected element's context is too large to send" +msgstr "Контекст выбранного элемента слишком велик для отправки" + msgid "The self-driving software factory" msgstr "Самоуправляемая софтверная фабрика" @@ -21328,9 +21358,6 @@ msgstr "Рабочая область открыта, но терминал не msgid "Workspace path is not available" msgstr "Путь к рабочей области недоступен" -msgid "Workspace path is not available yet" -msgstr "Путь рабочего пространства пока недоступен" - msgid "Workspace restored" msgstr "Рабочая область восстановлена" diff --git a/packages/i18n/locales/tr/messages.po b/packages/i18n/locales/tr/messages.po index d51d2b3b54d..cb7f68935c1 100644 --- a/packages/i18n/locales/tr/messages.po +++ b/packages/i18n/locales/tr/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\", {2} ile {1} dalına birleştirilecek. Buradan geri alınamaz." msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" artık tetiklenmeyecek ve çalıştırma geçmişi kaldırılacak. Bu geri alınamaz." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" {size} boyutunda — {limit} üzerindeki dosyalar eklenemez" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" {size} boyutunda — bu çalışma alanına {limit} üzerindeki dosyalar eklenemez. Dosya çalışma alanının makinesindeyse bunun yerine yolunu belirtin." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" bir klasör. Bunun yerine içindeki dosyaları ekle." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" {limit} sınırını aşıyor; bulut dışındaki bir çalışma alanı en fazla bu kadarını alabilir" + msgid "\"{name}\" paused" msgstr "\"{name}\" duraklatıldı" msgid "\"{name}\" resumed" msgstr "\"{name}\" sürdürüldü" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" taşındı veya silindi. Yeniden ekle." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" görevini tamamladı" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {# kaynak kullanıldı} other {# kaynak kullanıldı msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {# araç kullanıldı} other {# araç kullanıldı}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} dosya {limit} sınırını aştığı için eklenmedi" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "{count} dosya eklendi — bir mesaj en fazla {max} dosya taşıyabilir" + msgid "{count} GitHub stars" msgstr "{count} GitHub yıldızı" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 çerez — bu siteyi unut" +msgid "1 file is over {limit} and was not added" +msgstr "1 dosya {limit} sınırını aştığı için eklenmedi" + msgid "1 hr" msgstr "1 sa" @@ -13885,6 +13909,9 @@ msgstr "Paradev Tasarım Sistemi" msgid "Paradev desktop app" msgstr "Paradev masaüstü uygulaması" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev'in \"{name}\" dosyasını okuma izni yok." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise, takımlar için Paradev'dir. Nelerin dahil olduğunu ve kuruluşunuzda nasıl işleyebileceğini öğrenmek için bize ulaşın." @@ -19157,6 +19184,9 @@ msgstr "Aynı uygulama iPad'de yerel olarak, dikey ve yatay modda çalışır." msgid "The scorecard" msgstr "Puan tablosu" +msgid "The selected element's context is too large to send" +msgstr "Seçilen öğenin bağlamı gönderilemeyecek kadar büyük" + msgid "The self-driving software factory" msgstr "Kendi kendini süren yazılım fabrikası" @@ -21328,9 +21358,6 @@ msgstr "Çalışma alanı açıldı, ancak terminal başlatılamadı." msgid "Workspace path is not available" msgstr "Çalışma alanı yolu kullanılamıyor" -msgid "Workspace path is not available yet" -msgstr "Çalışma alanı yolu henüz kullanılamıyor" - msgid "Workspace restored" msgstr "Çalışma alanı geri yüklendi" diff --git a/packages/i18n/locales/uk/messages.po b/packages/i18n/locales/uk/messages.po index a8f995f3122..25365fe493c 100644 --- a/packages/i18n/locales/uk/messages.po +++ b/packages/i18n/locales/uk/messages.po @@ -61,12 +61,27 @@ msgstr "«{0}» буде злито в {1} через {2}. Звідси це н msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "«{0}» більше не спрацьовуватиме, а історію її запусків буде видалено. Це не можна скасувати." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "«{name}» має розмір {size} — файли понад {limit} прикріпити не можна" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "«{name}» має розмір {size} — до цього робочого простору не можна прикріпити файли понад {limit}. Якщо файл є на машині робочого простору, вкажіть замість цього його шлях." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "«{name}» — це папка. Прикріпіть файли з неї." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "«{name}» більший за {limit} — це максимум для робочого простору поза хмарою" + msgid "\"{name}\" paused" msgstr "«{name}» призупинено" msgid "\"{name}\" resumed" msgstr "«{name}» відновлено" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "«{name}» переміщено або видалено. Прикріпіть його знову." + msgid "\"{title}\" has finished its task" msgstr "«{title}»: завдання виконано" @@ -899,6 +914,12 @@ msgstr "{count, plural, one {Використано # джерело} few {Ви msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {використано # інструмент} few {використано # інструменти} many {використано # інструментів} other {використано # інструмента}}" +msgid "{count} files are over {limit} and were not added" +msgstr "Файли понад {limit} не додано: {count}" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "Прикріплено файлів: {count} — в одному повідомленні не більше {max}" + msgid "{count} GitHub stars" msgstr "Зірок на GitHub: {count}" @@ -1537,6 +1558,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 файл cookie — забути цей сайт" +msgid "1 file is over {limit} and was not added" +msgstr "1 файл більший за {limit} і не був доданий" + msgid "1 hr" msgstr "1 год" @@ -13879,6 +13903,9 @@ msgstr "Дизайн-система Paradev" msgid "Paradev desktop app" msgstr "Десктопний застосунок Paradev" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev не має дозволу на читання «{name}»." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise призначений для команд. Зв'яжіться з нами, щоб дізнатися більше про те, що входить у тариф і як він може працювати для вашої організації." @@ -19151,6 +19178,9 @@ msgstr "Той самий застосунок працює нативно на msgid "The scorecard" msgstr "Таблиця оцінок" +msgid "The selected element's context is too large to send" +msgstr "Контекст вибраного елемента завеликий для надсилання" + msgid "The self-driving software factory" msgstr "Самокерована фабрика програмного забезпечення" @@ -21322,9 +21352,6 @@ msgstr "Робочий простір відкрито, але термінал msgid "Workspace path is not available" msgstr "Шлях до робочого простору недоступний" -msgid "Workspace path is not available yet" -msgstr "Шлях до робочого простору ще недоступний" - msgid "Workspace restored" msgstr "Робочий простір відновлено" diff --git a/packages/i18n/locales/vi/messages.po b/packages/i18n/locales/vi/messages.po index a6f98fd22bb..beaf3c4717d 100644 --- a/packages/i18n/locales/vi/messages.po +++ b/packages/i18n/locales/vi/messages.po @@ -67,12 +67,27 @@ msgstr "\"{0}\" sẽ được merge vào {1} bằng {2}. Không thể hoàn tác msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "\"{0}\" sẽ ngừng kích hoạt và lịch sử chạy sẽ bị xóa. Không thể hoàn tác." +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "\"{name}\" có dung lượng {size} — không thể đính kèm tệp lớn hơn {limit}" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "\"{name}\" có dung lượng {size} — không thể đính kèm tệp lớn hơn {limit} vào workspace này. Nếu tệp nằm trên máy của workspace, hãy ghi đường dẫn của tệp thay vào đó." + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "\"{name}\" là một thư mục. Hãy đính kèm các tệp bên trong thay thế." + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "\"{name}\" vượt quá {limit}, mức tối đa mà một workspace ngoài cloud có thể nhận" + msgid "\"{name}\" paused" msgstr "Đã tạm dừng \"{name}\"" msgid "\"{name}\" resumed" msgstr "Đã tiếp tục \"{name}\"" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "\"{name}\" đã bị di chuyển hoặc xóa. Hãy đính kèm lại." + msgid "\"{title}\" has finished its task" msgstr "\"{title}\" đã hoàn thành tác vụ" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {Đã dùng # nguồn} other {Đã dùng # nguồn}} msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {đã dùng # công cụ} other {đã dùng # công cụ}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} tệp vượt quá {limit} và không được thêm" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "Đã đính kèm {count} tệp — mỗi tin nhắn chứa tối đa {max} tệp" + msgid "{count} GitHub stars" msgstr "{count} star GitHub" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1 cookie — quên trang này" +msgid "1 file is over {limit} and was not added" +msgstr "1 tệp vượt quá {limit} và không được thêm" + msgid "1 hr" msgstr "1 giờ" @@ -13885,6 +13909,9 @@ msgstr "Hệ thống thiết kế Paradev" msgid "Paradev desktop app" msgstr "Ứng dụng Paradev cho máy tính" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev không có quyền đọc \"{name}\"." + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise là Paradev dành cho đội nhóm. Hãy liên hệ để biết thêm về những gì được bao gồm và cách nó phù hợp với tổ chức của bạn." @@ -19157,6 +19184,9 @@ msgstr "Cùng một ứng dụng chạy native trên iPad, ở cả chế độ msgid "The scorecard" msgstr "Bảng điểm" +msgid "The selected element's context is too large to send" +msgstr "Ngữ cảnh của phần tử đã chọn quá lớn để gửi" + msgid "The self-driving software factory" msgstr "Nhà máy phần mềm tự vận hành" @@ -21328,9 +21358,6 @@ msgstr "Đã mở workspace, nhưng terminal không khởi động được." msgid "Workspace path is not available" msgstr "Không có đường dẫn workspace" -msgid "Workspace path is not available yet" -msgstr "Đường dẫn không gian làm việc chưa sẵn sàng" - msgid "Workspace restored" msgstr "Đã khôi phục workspace" diff --git a/packages/i18n/locales/zh-CN/messages.po b/packages/i18n/locales/zh-CN/messages.po index ffd1fe42f01..119623f82fe 100644 --- a/packages/i18n/locales/zh-CN/messages.po +++ b/packages/i18n/locales/zh-CN/messages.po @@ -67,12 +67,27 @@ msgstr "“{0}”将通过{2}合并到{1}。在这里无法撤销。" msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "“{0}”将不再触发,其运行历史也会被移除。此操作无法撤销。" +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "“{name}”大小为 {size} — 无法附加超过 {limit} 的文件" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "“{name}”大小为 {size} — 无法向此工作区附加超过 {limit} 的文件。如果该文件位于工作区所在的机器上,请改为提及其路径。" + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "“{name}”是一个文件夹。请改为附加其中的文件。" + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "“{name}”超过 {limit},这是云端以外的工作区可接收的上限" + msgid "\"{name}\" paused" msgstr "“{name}”已暂停" msgid "\"{name}\" resumed" msgstr "“{name}”已恢复" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "“{name}”已被移动或删除。请重新附加。" + msgid "\"{title}\" has finished its task" msgstr "“{title}”已完成任务" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {使用了#个来源} other {使用了#个来源}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {使用了 # 个工具} other {使用了 # 个工具}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} 个文件超过 {limit},未添加" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "已附加 {count} 个文件 — 一条消息最多可包含 {max} 个" + msgid "{count} GitHub stars" msgstr "{count}个GitHub星标" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1个cookie——忘记此站点" +msgid "1 file is over {limit} and was not added" +msgstr "1 个文件超过 {limit},未添加" + msgid "1 hr" msgstr "1 小时" @@ -13885,6 +13909,9 @@ msgstr "Paradev设计系统" msgid "Paradev desktop app" msgstr "Paradev 桌面应用" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev 没有读取“{name}”的权限。" + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise是面向团队的Paradev。联系我们,了解它包含什么,以及如何适配你的组织。" @@ -19157,6 +19184,9 @@ msgstr "同一个应用在 iPad 上原生运行,支持竖屏和横屏。" msgid "The scorecard" msgstr "评分表" +msgid "The selected element's context is too large to send" +msgstr "所选元素的上下文太大,无法发送" + msgid "The self-driving software factory" msgstr "自动驾驶的软件工厂" @@ -21328,9 +21358,6 @@ msgstr "工作区已打开,但终端启动失败。" msgid "Workspace path is not available" msgstr "工作区路径不可用" -msgid "Workspace path is not available yet" -msgstr "工作区路径尚不可用" - msgid "Workspace restored" msgstr "工作区已恢复" diff --git a/packages/i18n/locales/zh-TW/messages.po b/packages/i18n/locales/zh-TW/messages.po index 0e2cc140439..9e3c3eecc29 100644 --- a/packages/i18n/locales/zh-TW/messages.po +++ b/packages/i18n/locales/zh-TW/messages.po @@ -67,12 +67,27 @@ msgstr "「{0}」將通過{2}合併到{1}。在這裡無法復原。" msgid "\"{0}\" will stop firing and its run history will be removed. This can't be undone." msgstr "「{0}」將不再觸發,其執行歷史也會被移除。此操作無法復原。" +msgid "\"{name}\" is {size} — files over {limit} can't be attached" +msgstr "「{name}」大小為 {size} — 無法附加超過 {limit} 的檔案" + +msgid "\"{name}\" is {size} — files over {limit} can't be attached to this workspace. If the file is on the workspace's machine, mention its path instead." +msgstr "「{name}」大小為 {size} — 無法將超過 {limit} 的檔案附加到此工作區。若檔案位於工作區所在的機器上,請改為提及其路徑。" + +msgid "\"{name}\" is a folder. Attach the files inside it instead." +msgstr "「{name}」是資料夾。請改為附加其中的檔案。" + +msgid "\"{name}\" is over {limit}, the most a workspace outside the cloud can take" +msgstr "「{name}」超過 {limit},這是雲端以外的工作區可接收的上限" + msgid "\"{name}\" paused" msgstr "「{name}」已暫停" msgid "\"{name}\" resumed" msgstr "「{name}」已恢復" +msgid "\"{name}\" was moved or deleted. Attach it again." +msgstr "「{name}」已被移動或刪除。請重新附加。" + msgid "\"{title}\" has finished its task" msgstr "「{title}」已完成任務" @@ -905,6 +920,12 @@ msgstr "{count, plural, one {使用了#個來源} other {使用了#個來源}}" msgid "{count, plural, one {used # tool} other {used # tools}}" msgstr "{count, plural, one {使用了 # 個工具} other {使用了 # 個工具}}" +msgid "{count} files are over {limit} and were not added" +msgstr "{count} 個檔案超過 {limit},未新增" + +msgid "{count} files attached — a message carries at most {max}" +msgstr "已附加 {count} 個檔案 — 一則訊息最多可包含 {max} 個" + msgid "{count} GitHub stars" msgstr "{count}個GitHub星標" @@ -1543,6 +1564,9 @@ msgstr "1" msgid "1 cookie — forget this site" msgstr "1個cookie——忘記此站點" +msgid "1 file is over {limit} and was not added" +msgstr "1 個檔案超過 {limit},未新增" + msgid "1 hr" msgstr "1 小時" @@ -13885,6 +13909,9 @@ msgstr "Paradev設計系統" msgid "Paradev desktop app" msgstr "Paradev 桌面 App" +msgid "Paradev doesn't have permission to read \"{name}\"." +msgstr "Paradev 沒有讀取「{name}」的權限。" + msgid "Paradev Enterprise is Paradev for teams. Reach out to learn more about what's included and how it can work for your organization." msgstr "Paradev Enterprise是面向團隊的Paradev。聯絡我們,瞭解它包含什麼,以及如何適配你的組織。" @@ -19157,6 +19184,9 @@ msgstr "同一個應用程式在 iPad 上原生執行,支援直向和橫向。 msgid "The scorecard" msgstr "評分表" +msgid "The selected element's context is too large to send" +msgstr "所選元素的內容脈絡太大,無法傳送" + msgid "The self-driving software factory" msgstr "自動駕駛的軟體工廠" @@ -21328,9 +21358,6 @@ msgstr "工作區已開啟,但終端啟動失敗。" msgid "Workspace path is not available" msgstr "工作區路徑不可用" -msgid "Workspace path is not available yet" -msgstr "工作區路徑尚不可用" - msgid "Workspace restored" msgstr "工作區已還原" diff --git a/packages/shared/package.json b/packages/shared/package.json index a870ab8cb2b..eb24f36c349 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -377,6 +377,10 @@ "types": "./src/workspace-attachments.ts", "default": "./src/workspace-attachments.ts" }, + "./workspace-attachments-dir": { + "types": "./src/workspace-attachments-dir.ts", + "default": "./src/workspace-attachments-dir.ts" + }, "./agent-permissions-migration": { "types": "./src/agent-permissions-migration.ts", "default": "./src/agent-permissions-migration.ts" diff --git a/packages/shared/src/attachment-limits.ts b/packages/shared/src/attachment-limits.ts index c5e18dad369..cd36bc4f91c 100644 --- a/packages/shared/src/attachment-limits.ts +++ b/packages/shared/src/attachment-limits.ts @@ -16,3 +16,23 @@ export const MAX_CHAT_IMAGE_BYTES = 50 * 1024 * 1024; /** Per send, matching what the desktop terminal composer accepts. */ export const MAX_ATTACHMENTS = 10; + +/** + * Per file, for bytes sent base64 in a request body to a host, and read back + * the same way. The ceiling is the transport's: the host holds the body in + * memory. A workspace on a machine someone owns refuses above it, because its + * attachments must not go through our storage. + */ +export const MAX_INLINE_ATTACHMENT_BYTES = 25 * 1024 * 1024; + +/** Largest image a transcript renders inline; anything larger is a name badge. */ +export const MAX_THUMBNAIL_BYTES = 5 * 1024 * 1024; + +/** A host's attachment store removes an entry nobody has used for this long. */ +export const ATTACHMENT_RETENTION_DAYS = 30; + +/** + * The first host whose adapters read an attachment part, by `attachmentId` or + * `fileId`. Below it a client sends path tags in the text instead. + */ +export const ATTACHMENT_PARTS_MIN_HOST_VERSION = "2.0.4"; diff --git a/packages/shared/src/cloud-agent-launch.ts b/packages/shared/src/cloud-agent-launch.ts index 05b4439bccb..435e56f4162 100644 --- a/packages/shared/src/cloud-agent-launch.ts +++ b/packages/shared/src/cloud-agent-launch.ts @@ -1,4 +1,5 @@ import { z } from "zod"; +import { MAX_ATTACHMENTS } from "./attachment-limits"; import { HOST_AGENT_PRESETS } from "./host-agent-presets"; /** @@ -41,7 +42,7 @@ export const cloudAgentLaunchSchema = z.object({ * them to at create time, so the ids travel and the box pulls the bytes * itself once host-service is up. */ - attachmentFileIds: z.array(z.string().uuid()).max(10).optional(), + attachmentFileIds: z.array(z.string().uuid()).max(MAX_ATTACHMENTS).optional(), surface: z.enum(["terminal", "chat"]).optional(), /** * Set only by cloud automation dispatch. A manual create must not name a diff --git a/packages/shared/src/host-version.test.ts b/packages/shared/src/host-version.test.ts index 9f28f405949..0f99daad478 100644 --- a/packages/shared/src/host-version.test.ts +++ b/packages/shared/src/host-version.test.ts @@ -1,7 +1,9 @@ import { describe, expect, test } from "bun:test"; +import { ATTACHMENT_PARTS_MIN_HOST_VERSION } from "./attachment-limits"; import { deriveHostVersionState, hostNeedsUpdate, + hostReadsAttachmentParts, isHostUpdateTarget, parseHostInstallSource, } from "./host-version"; @@ -81,3 +83,14 @@ test("only released app versions can target a standalone update", () => { for (const version of ["1.27.0-canary.1", "0.0.0-dev", "v1.27.0", "01.27.0"]) expect(isHostUpdateTarget(version)).toBe(false); }); + +describe("hostReadsAttachmentParts", () => { + test("a host at or above the floor reads parts; an older or unknown one gets path tags", () => { + expect(hostReadsAttachmentParts(ATTACHMENT_PARTS_MIN_HOST_VERSION)).toBe( + true, + ); + expect(hostReadsAttachmentParts("9.0.0")).toBe(true); + expect(hostReadsAttachmentParts("1.40.0")).toBe(false); + expect(hostReadsAttachmentParts(undefined)).toBe(false); + }); +}); diff --git a/packages/shared/src/host-version.ts b/packages/shared/src/host-version.ts index aac8d7033a6..393ac4c087b 100644 --- a/packages/shared/src/host-version.ts +++ b/packages/shared/src/host-version.ts @@ -1,4 +1,5 @@ import semver from "semver"; +import { ATTACHMENT_PARTS_MIN_HOST_VERSION } from "./attachment-limits"; /** * Minimum host-service version a v2 workspace UI can work with against a @@ -106,3 +107,16 @@ export function hostNeedsUpdate(state: HostVersionState): boolean { export function isHostUpdateTarget(version: string): boolean { return /^\d+\.\d+\.\d+$/.test(version) && semver.valid(version) !== null; } + +/** + * Whether a host's adapters read a chat attachment part. Below the floor a + * client puts path tags in the text instead. + */ +export function hostReadsAttachmentParts( + hostVersion: string | null | undefined, +): boolean { + const version = semver.coerce(hostVersion ?? ""); + return ( + version !== null && semver.gte(version, ATTACHMENT_PARTS_MIN_HOST_VERSION) + ); +} diff --git a/packages/shared/src/workspace-attachments-dir.ts b/packages/shared/src/workspace-attachments-dir.ts new file mode 100644 index 00000000000..9da4e0e7397 --- /dev/null +++ b/packages/shared/src/workspace-attachments-dir.ts @@ -0,0 +1,24 @@ +import { closeSync, mkdirSync, openSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { + WORKSPACE_ATTACHMENTS_DIR, + WORKSPACE_ATTACHMENTS_GITIGNORE, +} from "./workspace-attachments"; + +/** + * The worktree directory attachments are written into, created with a + * `.gitignore` that hides everything in it so an agent never sees + * attachments as untracked changes. The ignore file is create-only: a + * user's own edit wins. + */ +export function ensureWorkspaceAttachmentsDir(worktreePath: string): string { + const dir = join(worktreePath, WORKSPACE_ATTACHMENTS_DIR); + mkdirSync(dir, { recursive: true }); + try { + closeSync(openSync(join(dir, ".gitignore"), "wx")); + writeFileSync(join(dir, ".gitignore"), WORKSPACE_ATTACHMENTS_GITIGNORE); + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error; + } + return dir; +} diff --git a/packages/trpc/src/router/attachment/attachment.ts b/packages/trpc/src/router/attachment/attachment.ts index a0b96c3162a..47fadc75c44 100644 --- a/packages/trpc/src/router/attachment/attachment.ts +++ b/packages/trpc/src/router/attachment/attachment.ts @@ -1,25 +1,17 @@ import { db } from "@superset/db/client"; -import { attachments, files } from "@superset/db/schema"; +import { files, type SelectFile } from "@superset/db/schema"; import { fileOriginalKey } from "@superset/shared/usercontent"; import type { TRPCRouterRecord } from "@trpc/server"; -import { and, eq, inArray } from "drizzle-orm"; import { headObject, presignedGetUrl, presignedPutUrl } from "../../lib/r2"; +import type { SandboxCaller } from "../../lib/sandbox/api-credential"; import { protectedProcedure, userError } from "../../trpc"; import { requireActiveOrgMembership } from "../utils/active-org"; +import { resolvableFiles, TRANSFER_ONLY } from "./resolvable"; import { createAttachmentUploadSchema, resolveAttachmentsSchema, } from "./schema"; -/** - * What marks a `files` row as one of these. Every other kind of file is - * identified by its content — page assets deduplicate on the digest — and no - * real file hashes to the empty string, so this both keeps an attachment out - * of any reuse lookup and keeps `resolve` off files it has no business - * handing a URL for. - */ -const TRANSFER_ONLY = ""; - /** * Composer attachments: bytes on their way from a client to the machine an * agent is running on. @@ -29,11 +21,10 @@ const TRANSFER_ONLY = ""; * bodies in a Worker isolate and is refused outright by Cloudflare's edge * above 100 MB. What travels over the relay is a list of file ids. * - * Rows here stay `pending` for their whole life, which is the point: the - * object is a transfer buffer, dead as soon as the host has written it into - * the worktree, and `pending` is exactly what the file sweep reclaims a day - * later. Nothing references these bytes afterwards, so there is no `ready` - * state to move to and no parent to attach them to. + * A row stays `pending` while it is only a transfer buffer, which the file + * sweep reclaims a day later. A file sent to a cloud workspace is kept + * instead: `anchorAttachments` marks it `ready` on that workspace, and it is + * reaped with the workspace's box. */ export const attachmentRouter = { /** @@ -89,14 +80,8 @@ export const attachmentRouter = { * Presigned GETs for a host about to materialize these into a worktree, * with the metadata it needs to name the files. * - * Scoped to the caller's own organization and to attachments, which is - * what keeps a host to the bytes it asked for: `files.id` is the only - * thing the caller presents, and knowing one is not authority to read it. - * Without the second scope this would sign a URL for any file in the org, - * a page's private assets included. - * - * A box calling for itself gets only the files attached to its own - * workspace: access to the box is access to its files, nothing wider. + * Scoped by `resolvableFiles`: `files.id` is the only thing the caller + * presents, and knowing one is not authority to read it. * * A mutation despite reading nothing but rows: the URLs it mints are * short-lived credentials, and a query's response is cacheable. @@ -104,33 +89,7 @@ export const attachmentRouter = { resolve: protectedProcedure .input(resolveAttachmentsSchema) .mutation(async ({ ctx, input }) => { - const organizationId = await requireActiveOrgMembership(ctx); - - const rows = await db - .select() - .from(files) - .where( - and( - inArray(files.id, input.fileIds), - eq(files.organizationId, organizationId), - eq(files.sha256, TRANSFER_ONLY), - ctx.sandboxCaller - ? inArray( - files.id, - db - .select({ id: attachments.fileId }) - .from(attachments) - .where( - and( - eq(attachments.parentKind, "cloud_workspace"), - eq(attachments.parentId, ctx.sandboxCaller.workspaceId), - ), - ), - ) - : undefined, - ), - ); - const byId = new Map(rows.map((row) => [row.id, row])); + const byId = await loadResolvable(ctx, input.fileIds); // In the order asked for: the caller names attachments positionally // and a reordered answer would rename them. @@ -144,29 +103,69 @@ export const attachmentRouter = { i18nKey: "serverError.attachment.notFound", }); } - - // A presigned PUT lands without the API seeing it, so this is - // where an upload is held to what it declared. A short read - // that never finished is the case worth catching — it would - // otherwise reach the agent as a truncated file. - const key = fileOriginalKey(file.id); - const head = await headObject(key); - if (!head || head.sizeBytes !== file.sizeBytes) { + const resolved = await signUploaded(file); + if (!resolved) { throw userError({ code: "BAD_REQUEST", message: "Attachment was not uploaded — send the bytes first", i18nKey: "serverError.attachment.notUploaded", }); } + return resolved; + }), + ); + }), - return { - fileId: file.id, - name: file.name, - contentType: file.contentType, - sizeBytes: file.sizeBytes, - url: await presignedGetUrl(key), - }; + /** + * `resolve` for a reader that shows what it can: a transcript with one + * file gone still renders the rest. Every id gets an answer, in the order + * asked for, and one the caller may not see is reported the same as one + * that does not exist. + */ + resolveEach: protectedProcedure + .input(resolveAttachmentsSchema) + .mutation(async ({ ctx, input }) => { + const byId = await loadResolvable(ctx, input.fileIds); + return await Promise.all( + input.fileIds.map(async (fileId) => { + const file = byId.get(fileId); + const resolved = file ? await signUploaded(file) : null; + return resolved ?? { fileId, missing: true as const }; }), ); }), } satisfies TRPCRouterRecord; + +async function loadResolvable( + ctx: Parameters[0] & { + sandboxCaller: SandboxCaller | null; + }, + fileIds: string[], +) { + const rows = await resolvableFiles({ + organizationId: await requireActiveOrgMembership(ctx), + userId: ctx.session.user.id, + boxWorkspaceId: ctx.sandboxCaller?.workspaceId ?? null, + fileIds, + }); + return new Map(rows.map((row) => [row.id, row])); +} + +/** + * A presigned PUT lands without the API seeing it, so this is where an + * upload is held to what it declared. A short read that never finished is + * the case worth catching — it would otherwise reach the agent as a + * truncated file. Null when the bytes are not there. + */ +async function signUploaded(file: SelectFile) { + const key = fileOriginalKey(file.id); + const head = await headObject(key); + if (!head || head.sizeBytes !== file.sizeBytes) return null; + return { + fileId: file.id, + name: file.name, + contentType: file.contentType, + sizeBytes: file.sizeBytes, + url: await presignedGetUrl(key), + }; +} diff --git a/packages/trpc/src/router/attachment/resolvable.integration.ts b/packages/trpc/src/router/attachment/resolvable.integration.ts new file mode 100644 index 00000000000..d1dd4af50d0 --- /dev/null +++ b/packages/trpc/src/router/attachment/resolvable.integration.ts @@ -0,0 +1,148 @@ +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { db, dbWs } from "@superset/db/client"; +import { + attachments, + cloudWorkspaces, + environments, + files, + organizations, + users, +} from "@superset/db/schema"; +import { eq, inArray } from "drizzle-orm"; +import { resolvableFiles, TRANSFER_ONLY } from "./resolvable"; + +const ORG = crypto.randomUUID(); +const OWNER = crypto.randomUUID(); +const TEAMMATE = crypto.randomUUID(); +const now = Date.now(); + +const insertFile = async ( + status: "pending" | "ready", + sha256 = TRANSFER_ONLY, +) => { + const id = crypto.randomUUID(); + await db.insert(files).values({ + id, + organizationId: ORG, + name: "screenshot.png", + contentType: "image/png", + sizeBytes: 4, + sha256, + status, + createdByUserId: OWNER, + }); + return id; +}; + +const insertWorkspace = async (visibility: "org" | "just_me") => { + const [environment] = await db + .select({ id: environments.id }) + .from(environments) + .where(eq(environments.organizationId, ORG)); + const id = crypto.randomUUID(); + await db.insert(cloudWorkspaces).values({ + id, + organizationId: ORG, + name: "box", + branch: "main", + baseBranch: "main", + providerSandboxId: `box-${id}`, + environmentId: environment?.id as string, + visibility, + createdByUserId: OWNER, + }); + return id; +}; + +const anchor = (fileId: string, workspaceId: string) => + db.insert(attachments).values({ + fileId, + parentKind: "cloud_workspace", + parentId: workspaceId, + }); + +const resolvable = async ( + userId: string, + fileIds: string[], + boxWorkspaceId: string | null = null, +) => + ( + await resolvableFiles({ + organizationId: ORG, + userId, + boxWorkspaceId, + fileIds, + }) + ) + .map((row) => row.id) + .sort(); + +beforeAll(async () => { + await db + .insert(organizations) + .values({ id: ORG, name: "Resolve Org", slug: `resolve-org-${now}` }); + await db.insert(users).values([ + { id: OWNER, name: "Owner", email: `owner-${now}@example.com` }, + { id: TEAMMATE, name: "Teammate", email: `teammate-${now}@example.com` }, + ]); + await db.insert(environments).values({ + organizationId: ORG, + name: "default", + sourceKind: "image", + sourceRef: "image", + bundleSha: "sha", + }); +}); + +afterAll(async () => { + await db.delete(organizations).where(eq(organizations.id, ORG)); + await db.delete(users).where(inArray(users.id, [OWNER, TEAMMATE])); + await dbWs.$client.end?.().catch(() => {}); +}); + +describe("resolvableFiles", () => { + test("an upload in flight resolves for anyone in the org", async () => { + const pending = await insertFile("pending"); + expect(await resolvable(TEAMMATE, [pending])).toEqual([pending]); + }); + + test("a kept file resolves only through a workspace the caller can see", async () => { + const shared = await insertWorkspace("org"); + const hidden = await insertWorkspace("just_me"); + const inShared = await insertFile("ready"); + const inHidden = await insertFile("ready"); + await anchor(inShared, shared); + await anchor(inHidden, hidden); + + expect(await resolvable(OWNER, [inShared, inHidden])).toEqual( + [inShared, inHidden].sort(), + ); + expect(await resolvable(TEAMMATE, [inShared, inHidden])).toEqual([ + inShared, + ]); + }); + + test("a kept file on no cloud workspace does not resolve", async () => { + const loose = await insertFile("ready"); + expect(await resolvable(OWNER, [loose])).toEqual([]); + }); + + test("a box resolves only its own files, never one in flight", async () => { + const box = await insertWorkspace("org"); + const other = await insertWorkspace("org"); + const own = await insertFile("ready"); + const theirs = await insertFile("ready"); + const pending = await insertFile("pending"); + await anchor(own, box); + await anchor(theirs, other); + + expect(await resolvable(OWNER, [own, theirs, pending], box)).toEqual([own]); + }); + + test("a page asset never resolves", async () => { + const box = await insertWorkspace("org"); + const asset = await insertFile("ready", "ab".repeat(32)); + await anchor(asset, box); + expect(await resolvable(OWNER, [asset])).toEqual([]); + }); +}); diff --git a/packages/trpc/src/router/attachment/resolvable.ts b/packages/trpc/src/router/attachment/resolvable.ts new file mode 100644 index 00000000000..5e229aa2031 --- /dev/null +++ b/packages/trpc/src/router/attachment/resolvable.ts @@ -0,0 +1,69 @@ +import { db } from "@superset/db/client"; +import { attachments, cloudWorkspaces, files } from "@superset/db/schema"; +import { and, eq, inArray, or, type SQL } from "drizzle-orm"; +import { visibleTo } from "../cloud-workspace/access"; + +/** + * What marks a `files` row as a composer attachment. Every other kind of file is + * identified by its content — page assets deduplicate on the digest — and no + * real file hashes to the empty string, so this both keeps an attachment out + * of any reuse lookup and keeps `resolve` off files it has no business + * handing a URL for. + */ +export const TRANSFER_ONLY = ""; + +/** + * The attachments among `fileIds` a caller may read. + * + * A box gets only the files anchored to its own workspace. Anyone else gets + * an upload still in flight, and a kept file only through a cloud workspace + * they can see. In flight stays org-wide because a host resolves with its + * owner's credential, and the sender may be a teammate who shares that host. + */ +export function resolvableFiles({ + organizationId, + userId, + boxWorkspaceId, + fileIds, +}: { + organizationId: string; + userId: string; + boxWorkspaceId: string | null; + fileIds: string[]; +}) { + return db + .select() + .from(files) + .where( + and( + inArray(files.id, fileIds), + eq(files.organizationId, organizationId), + eq(files.sha256, TRANSFER_ONLY), + boxWorkspaceId + ? inArray( + files.id, + anchoredTo(eq(cloudWorkspaces.id, boxWorkspaceId)), + ) + : or( + eq(files.status, "pending"), + inArray( + files.id, + anchoredTo( + and( + eq(cloudWorkspaces.organizationId, organizationId), + visibleTo(userId), + ), + ), + ), + ), + ), + ); +} + +function anchoredTo(workspaces: SQL | undefined) { + return db + .select({ id: attachments.fileId }) + .from(attachments) + .innerJoin(cloudWorkspaces, eq(cloudWorkspaces.id, attachments.parentId)) + .where(and(eq(attachments.parentKind, "cloud_workspace"), workspaces)); +} diff --git a/packages/trpc/src/router/cloud-workspace/cloud-workspace.ts b/packages/trpc/src/router/cloud-workspace/cloud-workspace.ts index daa3a8fe434..3a578274726 100644 --- a/packages/trpc/src/router/cloud-workspace/cloud-workspace.ts +++ b/packages/trpc/src/router/cloud-workspace/cloud-workspace.ts @@ -8,6 +8,7 @@ import { githubRepositories, users, } from "@superset/db/schema"; +import { MAX_ATTACHMENTS } from "@superset/shared/attachment-limits"; import { MACHINE_SIZES, machineSpec } from "@superset/shared/billing"; import { CLOUD_AGENT_PROMPT_MAX_LENGTH, @@ -52,7 +53,7 @@ import { recordCloudWorkspaceActivity } from "./activity"; import { queueSettleWorkspace, settleWorkspaceNow } from "./meter"; import { nextSandboxNameFor } from "./provision"; import { listPullRequests } from "./pull-requests"; -import { queueReap } from "./reap"; +import { queueReap, reapWorkspaceFiles } from "./reap"; import { cloudWorkspaceRecordRouter } from "./record"; import { cloudWorkspaceSharingRouter } from "./sharing"; import { queueProvision, startCloudWorkspace } from "./start"; @@ -362,7 +363,10 @@ export const cloudWorkspaceRouter = { * bytes once it is up; the same cap `attachments.importFromCloud` * takes, since that is what runs in there. */ - attachmentFileIds: z.array(z.string().uuid()).max(10).optional(), + attachmentFileIds: z + .array(z.string().uuid()) + .max(MAX_ATTACHMENTS) + .optional(), /** What the person typed, kept as the workspace's prompt; `prompt` may carry built context. */ typedPrompt: z.string().max(20000).optional(), /** Tasks the composer linked; each must be in this organization. */ @@ -686,6 +690,7 @@ export const cloudWorkspaceRouter = { ), ); await deleteSandbox(row.providerSandboxId); + await reapWorkspaceFiles(row.id); }); } await recordCloudWorkspaceActivity( diff --git a/packages/trpc/src/router/cloud-workspace/reap.test.ts b/packages/trpc/src/router/cloud-workspace/reap.test.ts index eae67f86ccf..24e28c7d776 100644 --- a/packages/trpc/src/router/cloud-workspace/reap.test.ts +++ b/packages/trpc/src/router/cloud-workspace/reap.test.ts @@ -1,11 +1,13 @@ import { beforeEach, describe, expect, test } from "bun:test"; import { db } from "@superset/db/client"; import { stub } from "../../../test/stub"; +import * as files from "../../lib/files"; import * as sandbox from "../../lib/sandbox"; import * as jobs from "./jobs"; import * as meter from "./meter"; type Row = { + id: string; status: string; deletedAt: Date | null; provider: string; @@ -22,6 +24,7 @@ let meterFailure: Error | null = null; let boxRunning = true; let archiveHook: sandbox.BoxHookOutcome = { kind: "ran", status: "ok" }; let onArchiveHook: () => void = () => {}; +let reapedFiles: string[] = []; stub(db.query.cloudWorkspaces, { findFirst: () => Promise.resolve(row) }); stub(sandbox, { @@ -64,6 +67,15 @@ stub(jobs, { }, }); +stub(files, { + detachAll: ({ parentIds }: { parentIds: string[] }) => + Promise.resolve(parentIds.map((id) => `file-of-${id}`)), + reapOrphanFiles: (fileIds: string[]) => { + reapedFiles.push(...fileIds); + return Promise.resolve(); + }, +}); + stub(meter, { settleWorkspaceNow: () => { meterCalls.push("settle"); @@ -127,6 +139,7 @@ describe("queueReap", () => { describe("reapArchivedCloudWorkspace", () => { beforeEach(() => { row = { + id: input.cloudWorkspaceId, status: "deleted", deletedAt: archivedAt, provider: "vercel", @@ -139,6 +152,7 @@ describe("reapArchivedCloudWorkspace", () => { boxRunning = true; archiveHook = { kind: "ran", status: "ok" }; onArchiveHook = () => {}; + reapedFiles = []; }); test("the stop stage runs the archive hook, stops the box and queues its final settle", async () => { @@ -148,6 +162,7 @@ describe("reapArchivedCloudWorkspace", () => { expect(sandboxCalls).toEqual(["archive-hook", "stop:ws-box"]); expect(meterCalls).toEqual(["queue"]); expect(queued).toEqual([]); + expect(reapedFiles).toEqual([]); }); test("a failing or unsupported archive hook still stops the box", async () => { @@ -194,6 +209,11 @@ describe("reapArchivedCloudWorkspace", () => { expect(sandboxCalls).toEqual(["delete:ws-box"]); }); + test("the delete stage removes the files sent to the workspace", async () => { + await reapArchivedCloudWorkspace({ ...input, stage: "delete" }); + expect(reapedFiles).toEqual([`file-of-${input.cloudWorkspaceId}`]); + }); + test("a delete still deletes when the final settle fails: at most one lock window goes unbilled", async () => { meterFailure = new Error("autumn down"); expect( @@ -209,6 +229,7 @@ describe("reapArchivedCloudWorkspace", () => { "skipped", ); expect(sandboxCalls).toEqual([]); + expect(reapedFiles).toEqual([]); }); test(`the ${stage} stage leaves a later archive's box alone`, async () => { @@ -229,6 +250,7 @@ describe("reapArchivedCloudWorkspace", () => { await reapArchivedCloudWorkspace({ ...input, stage: "delete" }), ).toBe("skipped"); row = { + id: input.cloudWorkspaceId, status: "deleted", deletedAt: archivedAt, provider: "e2b", diff --git a/packages/trpc/src/router/cloud-workspace/reap.ts b/packages/trpc/src/router/cloud-workspace/reap.ts index 852aa5091c9..3f03164b9f5 100644 --- a/packages/trpc/src/router/cloud-workspace/reap.ts +++ b/packages/trpc/src/router/cloud-workspace/reap.ts @@ -1,6 +1,7 @@ import { db } from "@superset/db/client"; import { cloudWorkspaces } from "@superset/db/schema"; import { eq } from "drizzle-orm"; +import { detachAll, reapOrphanFiles } from "../../lib/files"; import { deleteSandbox, describeSandbox, @@ -90,6 +91,7 @@ export async function reapArchivedCloudWorkspace( console.error(`[cloud-workspace] ${row.id} final settle failed`, error), ); await deleteSandbox(row.providerSandboxId); + await reapWorkspaceFiles(row.id); return "reaped"; } if (!(await runArchiveHook(row, input))) return "skipped"; @@ -98,6 +100,21 @@ export async function reapArchivedCloudWorkspace( return "stopped"; } +/** Drops the files sent to a workspace whose box is gone for good. */ +export async function reapWorkspaceFiles(cloudWorkspaceId: string) { + await reapOrphanFiles( + await detachAll({ + parentKind: "cloud_workspace", + parentIds: [cloudWorkspaceId], + }), + ).catch((error) => + console.error( + `[cloud-workspace] ${cloudWorkspaceId} file reap failed`, + error, + ), + ); +} + function queueReapStage( input: ReapArchivedCloudWorkspaceInput, delaySeconds: number, diff --git a/packages/trpc/src/router/cloud-workspace/record.ts b/packages/trpc/src/router/cloud-workspace/record.ts index 3dd873768ab..4d5f5d24bfd 100644 --- a/packages/trpc/src/router/cloud-workspace/record.ts +++ b/packages/trpc/src/router/cloud-workspace/record.ts @@ -18,6 +18,7 @@ import { users, } from "@superset/db/schema"; import { retiredTaskColumns } from "@superset/db/task-list-query"; +import { MAX_ATTACHMENTS } from "@superset/shared/attachment-limits"; import { LABELS_MAX_PER_WORKSPACE } from "@superset/shared/labels"; import type { TRPCRouterRecord } from "@trpc/server"; import { TRPCError } from "@trpc/server"; @@ -622,7 +623,7 @@ export const cloudWorkspaceRecordRouter = { .input( z.object({ id: z.string().uuid(), - fileIds: z.array(z.string().uuid()).min(1).max(10), + fileIds: z.array(z.string().uuid()).min(1).max(MAX_ATTACHMENTS), }), ) .mutation(async ({ ctx, input }) => {