Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop: a folder dragged into the chat goes into the project (#66)

最爱双皮奶7fc46b2cff7e
diff --git a/.changeset/quiet-buttons-share.md b/.changeset/quiet-buttons-share.md
new file mode 100644
index 0000000..dc21934
--- /dev/null
+++ b/.changeset/quiet-buttons-share.md
@@ -0,0 +1,5 @@
+---
+'@openfilm/desktop': patch
+---
+
+Desktop: a folder dragged into the chat now goes into the project — every file in it, hidden ones left out — instead of "That is not a file."
diff --git a/apps/desktop/chat/src/App.tsx b/apps/desktop/chat/src/App.tsx
index b6e4517..6fdf342 100644
--- a/apps/desktop/chat/src/App.tsx
+++ b/apps/desktop/chat/src/App.tsx
@@ -820,7 +820,7 @@ function ChatPane({ project, banners, selection, assetsOpen }: { project: Projec
/* a picture shows itself; a video, a frame of itself with a play mark (once one is had) */
const picture = file.kind === 'image' ? file.previewUrl : file.thumb;
/* clicked, it opens to look at: a picture large, a video played, a text read */
- const open = file.previewUrl ? {
+ const open = file.previewUrl && !file.folder ? {
role: 'button' as const,
tabIndex: 0,
'aria-label': t('composer.openAttachment').replace('{name}', file.name),
@@ -837,11 +837,11 @@ function ChatPane({ project, banners, selection, assetsOpen }: { project: Projec
</div>
) : (
<div key={file.id} title={file.error ?? file.name} {...open}
- className={`group relative flex h-10 min-w-0 max-w-[150px] items-center gap-1.5 overflow-hidden rounded-[8px] border bg-[var(--surface-2)] py-1 pl-2 pr-5 transition ${file.previewUrl ? 'cursor-pointer' : ''} ${file.state === 'failed' ? 'border-[var(--danger)]' : 'border-[var(--border)] hover:border-[var(--border-strong)]'}`}>
+ className={`group relative flex h-10 min-w-0 max-w-[150px] items-center gap-1.5 overflow-hidden rounded-[8px] border bg-[var(--surface-2)] py-1 pl-2 pr-5 transition ${file.previewUrl && !file.folder ? 'cursor-pointer' : ''} ${file.state === 'failed' ? 'border-[var(--danger)]' : 'border-[var(--border)] hover:border-[var(--border-strong)]'}`}>
{file.state === 'importing' ? <Loader2 size={13} className="shrink-0 animate-spin text-[var(--text-muted)]" /> : <Icon size={13} className="shrink-0 text-[var(--text-muted)]" />}
<span className="flex min-w-0 flex-col">
<span className="truncate text-[11.5px] leading-tight text-[var(--text-muted)]">{file.name}</span>
- <span className="truncate text-[10.5px] leading-tight text-[var(--text-faint)]">{file.state === 'failed' ? 'Not added' : formatFileSize(file.size)}</span>
+ <span className="truncate text-[10.5px] leading-tight text-[var(--text-faint)]">{file.state === 'failed' ? 'Not added' : file.folder ? t('composer.folder') : formatFileSize(file.size)}</span>
</span>
{remove}
</div>
diff --git a/apps/desktop/chat/src/app-bridge.ts b/apps/desktop/chat/src/app-bridge.ts
index cbcbdfc..092131e 100644
--- a/apps/desktop/chat/src/app-bridge.ts
+++ b/apps/desktop/chat/src/app-bridge.ts
@@ -51,7 +51,7 @@ interface AppBridge {
/** the project's files (Studio's listing), for the @ menu */
projectFiles(): Promise<{ files: Array<{ path: string; kind: string; size: number }>; pages?: Array<{ path: string; size: number }> }>;
/** bring a file into the project (assets/upload/): from its path, or its bytes */
- importFile(file: { path: string; name: string } | { bytes: ArrayBuffer; name: string }): Promise<{ ok: true; path: string } | { ok: false; error: string }>;
+ importFile(file: { path: string; name: string } | { bytes: ArrayBuffer; name: string }): Promise<{ ok: true; path: string; folder?: boolean } | { ok: false; error: string }>;
onSelection(listener: (selection: StudioSelection) => void): () => void;
setChatWidth(width: number, done?: boolean): void;
setChatOpen(open: boolean): void;
diff --git a/apps/desktop/chat/src/i18n/locales/en-US.ts b/apps/desktop/chat/src/i18n/locales/en-US.ts
index 781dbfc..450188d 100644
--- a/apps/desktop/chat/src/i18n/locales/en-US.ts
+++ b/apps/desktop/chat/src/i18n/locales/en-US.ts
@@ -136,6 +136,7 @@ export const enUS = {
agentSetUp: 'Set up',
agentWaiting: 'Signing in…',
effort: 'Effort',
+ folder: 'Folder',
model: 'Model',
openAttachment: 'View {name}',
openSettings: 'Open Settings',
diff --git a/apps/desktop/chat/src/i18n/locales/es.ts b/apps/desktop/chat/src/i18n/locales/es.ts
index 4ce78a6..0475e17 100644
--- a/apps/desktop/chat/src/i18n/locales/es.ts
+++ b/apps/desktop/chat/src/i18n/locales/es.ts
@@ -137,6 +137,7 @@ export const es: Words = {
agentSetUp: 'Configurar',
agentWaiting: 'Iniciando sesión…',
effort: 'Esfuerzo',
+ folder: 'Carpeta',
model: 'Modelo',
openAttachment: 'Ver {name}',
openSettings: 'Abrir Configuración',
diff --git a/apps/desktop/chat/src/i18n/locales/ja.ts b/apps/desktop/chat/src/i18n/locales/ja.ts
index 1848e2c..74562e1 100644
--- a/apps/desktop/chat/src/i18n/locales/ja.ts
+++ b/apps/desktop/chat/src/i18n/locales/ja.ts
@@ -137,6 +137,7 @@ export const ja: Words = {
agentSetUp: '設定',
agentWaiting: 'サインイン中…',
effort: '思考レベル',
+ folder: 'フォルダ',
model: 'モデル',
openAttachment: '{name} を表示',
openSettings: '設定を開く',
diff --git a/apps/desktop/chat/src/i18n/locales/ko.ts b/apps/desktop/chat/src/i18n/locales/ko.ts
index ab390c5..b4dd73b 100644
--- a/apps/desktop/chat/src/i18n/locales/ko.ts
+++ b/apps/desktop/chat/src/i18n/locales/ko.ts
@@ -137,6 +137,7 @@ export const ko: Words = {
agentSetUp: '설정',
agentWaiting: '로그인하는 중…',
effort: '추론 강도',
+ folder: '폴더',
model: '모델',
openAttachment: '{name} 보기',
openSettings: '설정 열기',
diff --git a/apps/desktop/chat/src/i18n/locales/zh-CN.ts b/apps/desktop/chat/src/i18n/locales/zh-CN.ts
index e59c542..a7282aa 100644
--- a/apps/desktop/chat/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/chat/src/i18n/locales/zh-CN.ts
@@ -137,6 +137,7 @@ export const zhCN: Words = {
agentSetUp: '设置',
agentWaiting: '正在登录…',
effort: '思考强度',
+ folder: '文件夹',
model: '模型',
openAttachment: '查看 {name}',
openSettings: '打开设置',
diff --git a/apps/desktop/chat/src/lib/desktop-attachments.ts b/apps/desktop/chat/src/lib/desktop-attachments.ts
index 8d2635b..428f796 100644
--- a/apps/desktop/chat/src/lib/desktop-attachments.ts
+++ b/apps/desktop/chat/src/lib/desktop-attachments.ts
@@ -27,6 +27,8 @@ export interface DesktopAttachment {
state: 'importing' | 'ready' | 'failed';
/** where it landed in the project */
path?: string;
+ /** a folder brought in whole: every file in it is under `path` */
+ folder?: boolean;
/** a picture, as its agent is sent it beside the text */
picture?: PromptImage;
error?: string;
@@ -81,7 +83,7 @@ export function useDesktopAttachments() {
const path = (window as unknown as { openfilmDesktop?: { pathForFile?: (f: File) => string } }).openfilmDesktop?.pathForFile?.(file) ?? '';
void (path ? Promise.resolve(null) : file.arrayBuffer())
.then((bytes) => app.importFile(path ? { path, name: item.name } : { bytes: bytes!, name: item.name }))
- .then((r) => patch(item.id, r.ok ? { state: 'ready', path: r.path } : { state: 'failed', error: r.error }))
+ .then((r) => patch(item.id, r.ok ? { state: 'ready', path: r.path, ...(r.folder ? { folder: true } : {}) } : { state: 'failed', error: r.error }))
.catch((error: unknown) => patch(item.id, { state: 'failed', error: error instanceof Error ? error.message : String(error) }));
}
}, []);
@@ -121,7 +123,7 @@ export function attachmentBlocker(files: readonly DesktopAttachment[]): string |
export function attachedText(files: readonly DesktopAttachment[]): string {
const placed = files.filter((f) => f.path);
if (!placed.length) return '';
- return `\n\nAttached files (in this project folder):\n${placed.map((f) => `- ${f.path} (${attachmentKind({ name: f.name, mediaType: f.mediaType })}, ${formatFileSize(f.size)})`).join('\n')}`;
+ return `\n\nAttached files (in this project folder):\n${placed.map((f) => `- ${f.path} (${f.folder ? 'folder: every file in it' : `${attachmentKind({ name: f.name, mediaType: f.mediaType })}, ${formatFileSize(f.size)}`})`).join('\n')}`;
}
/** The pictures among them, as their agent is sent them. */
diff --git a/apps/desktop/shell/bridge.ts b/apps/desktop/shell/bridge.ts
index a12cccc..95cb175 100644
--- a/apps/desktop/shell/bridge.ts
+++ b/apps/desktop/shell/bridge.ts
@@ -28,7 +28,7 @@ interface Native {
/* the window's tabs (src/tabs.mjs) */
tabs: NonNullable<StudioHost['tabs']>;
localAgents: Record<string, unknown>;
- importFile(request: { projectId: string; path: string; name: string }): Promise<{ ok: true; path: string } | { ok: false; error: string }>;
+ importFile(request: { projectId: string; path: string; name: string }): Promise<{ ok: true; path: string; folder?: boolean } | { ok: false; error: string }>;
chat: Record<string, (...args: never[]) => Promise<unknown>>;
/* the composer's Skills button (src/skills-ipc.mjs) */
skills: Record<string, (...args: never[]) => Promise<unknown>>;
diff --git a/apps/desktop/src/main.mjs b/apps/desktop/src/main.mjs
index 91402e3..d314bb5 100644
--- a/apps/desktop/src/main.mjs
+++ b/apps/desktop/src/main.mjs
@@ -515,14 +515,28 @@ async function start() {
agentHandle('desktop:agents:own-model-remove', ({ id }) => { roster.removeOwnModel(String(id)); return { ok: true }; });
/* a file on the disk brought into the chat goes into the project the page names, through Studio's own import (it
shows in Studio's media at once, and the import is in the project's history); one without a path the page sends
- itself */
+ itself. A folder goes as it is, through Studio's bring (files.mjs bringIn): every file in it, copied where the disk
+ can clone, hidden ones left out */
ipcMain.handle('desktop:import-file', async (event, request) => {
if (!fromPage(event) || !studio) return { ok: false, error: 'Studio is not running.' };
const projectId = String(request?.projectId ?? '');
if (!/^[\w-]+$/.test(projectId)) return { ok: false, error: 'No project is open.' };
const name = basename(String(request?.name ?? '')).replace(/[\u0000-\u001f/\\]+/g, '').slice(0, 200) || 'file';
const path = typeof request?.path === 'string' ? request.path : '';
- try { if (!path || !statSync(path).isFile()) return { ok: false, error: 'That is not a file.' }; } catch { return { ok: false, error: 'That file is not there any more.' }; }
+ if (!path) return { ok: false, error: 'That file is not there any more.' };
+ let info;
+ try { info = statSync(path); } catch { return { ok: false, error: 'That file is not there any more.' }; }
+ if (info.isDirectory()) {
+ try {
+ const res = await fetch(`${studio.origin}/api/projects/${encodeURIComponent(projectId)}/files/bring`, {
+ method: 'POST', headers: { 'x-studio-key': studio.key, 'content-type': 'application/json' },
+ body: JSON.stringify({ into: 'assets/upload', mode: 'copy', paths: [path] }),
+ });
+ const answer = await res.json().catch(() => ({}));
+ return res.ok && answer.landed?.[0] ? { ok: true, path: answer.landed[0], folder: true } : { ok: false, error: answer.error ?? `Studio answered ${res.status}` };
+ } catch (error) { return { ok: false, error: error.message }; }
+ }
+ if (!info.isFile()) return { ok: false, error: 'That is not a file.' };
try {
const res = await fetch(`${studio.origin}/api/projects/${encodeURIComponent(projectId)}/files?path=${encodeURIComponent(`assets/upload/${name}`)}`, {
method: 'PUT', headers: { 'x-studio-key': studio.key }, body: Readable.toWeb(createReadStream(path)), duplex: 'half',