营收增长了两成。
', messages: [], }) - const imported = await importStoredFiles([new File(['docx bytes'], 'report.docx')], 'keep') + const imported = await importStoredFiles( + rootSources([new File(['docx bytes'], 'report.docx')]), + 'keep', + ) const fileId = imported.addedIds[0] if (!fileId) throw new Error('Missing fixture') const stored = await getStoredFile(fileId) @@ -426,7 +430,10 @@ describe('reader agent', () => { }, { sheet: '汇总', data: [['合计', 3]] }, ]) - const imported = await importStoredFiles([new File(['xlsx bytes'], 'effort.xlsx')], 'keep') + const imported = await importStoredFiles( + rootSources([new File(['xlsx bytes'], 'effort.xlsx')]), + 'keep', + ) const fileId = imported.addedIds[0] if (!fileId) throw new Error('Missing fixture') const stored = await getStoredFile(fileId) diff --git a/ui-packages/web/src/features/agent/document-tools.ts b/ui-packages/web/src/features/agent/document-tools.ts index 0f7812f..aac0dcc 100644 --- a/ui-packages/web/src/features/agent/document-tools.ts +++ b/ui-packages/web/src/features/agent/document-tools.ts @@ -39,7 +39,7 @@ export type DocumentAccess = { open: (fileId: string, signal?: AbortSignal) => Promisetext
', 'text/html') await importStoredFiles( - [new File(['context'], 'Fixture attachment.txt', { type: 'text/plain' })], + rootSources([new File(['context'], 'Fixture attachment.txt', { type: 'text/plain' })]), 'keep', 'attachments', ) - let next: ListInput | null = { name: 'FIXTURE' } + let next: ListInput | null = { path: 'FIXTURE' } const files = [] while (next) { const result = await tools.list(next) @@ -72,7 +75,7 @@ describe('local reader tools', () => { } expect(files).toHaveLength(107) expect(new Set(files.map(file => file.id)).size).toBe(107) - expect(files.find(file => file.name === 'Fixture attachment.txt')).toMatchObject({ + expect(files.find(file => file.path === 'Fixture attachment.txt')).toMatchObject({ collection: 'attachments', textReadable: true, }) @@ -92,7 +95,7 @@ describe('local reader tools', () => { { type: 'text/markdown' }, ), ) - await importStoredFiles(contents, 'keep') + await importStoredFiles(rootSources(contents), 'keep') let next: SearchInput | null = { query: 'SEARCH this\nphrase' } const matches: SearchMatch[] = [] while (next) { @@ -143,7 +146,7 @@ describe('local reader tools', () => { tools.read({ ...result.next, range: { unit: 'line', start: 2, end: 3 } }), ).rejects.toThrow('does not match') await importStoredFiles( - [new File(['new content'], 'Changing.txt', { type: 'text/plain' })], + rootSources([new File(['new content'], 'Changing.txt', { type: 'text/plain' })]), 'replace', ) await expect(tools.read(result.next)).rejects.toThrow('File changed') @@ -155,12 +158,14 @@ describe('local reader tools', () => { it('reports unreadable files separately and bounds pages of errors', async () => { await importStoredFiles( - Array.from( - { length: 130 }, - (_, index) => - new File(['Unreadable fixture
'], `Unreadable ${index}.html`, { - type: 'text/html', - }), + rootSources( + Array.from( + { length: 130 }, + (_, index) => + new File(['Unreadable fixture
'], `Unreadable ${index}.html`, { + type: 'text/html', + }), + ), ), 'keep', ) @@ -179,7 +184,7 @@ describe('local reader tools', () => { expect(issueCount).toBe(131) expect(ids).toEqual([id]) const bad = await importStoredFiles( - [new File([new Uint8Array([255])], 'Broken.txt', { type: 'text/plain' })], + rootSources([new File([new Uint8Array([255])], 'Broken.txt', { type: 'text/plain' })]), 'keep', ) await expect(tools.read({ fileId: bad.addedIds[0] ?? '' })).rejects.toThrow('UTF-8') @@ -287,7 +292,7 @@ describe('active source tools', () => { it('reads raw source with lossless bounded pagination and detects changes', () => { let source: ActiveSourceSnapshot = { fileId: 'a', - name: 'A.md', + path: 'A.md', version: crypto.randomUUID(), content: `# Raw source\n${'中😀'.repeat(15000)}`, } @@ -317,7 +322,7 @@ describe('active source tools', () => { it('edits only the matching active file and version with a unique exact match', () => { let source: ActiveSourceSnapshot = { fileId: 'a', - name: 'A.md', + path: 'A.md', version: crypto.randomUUID(), content: 'same same', } diff --git a/ui-packages/web/src/features/agent/local-tools.ts b/ui-packages/web/src/features/agent/local-tools.ts index 4102e1e..ad4e713 100644 --- a/ui-packages/web/src/features/agent/local-tools.ts +++ b/ui-packages/web/src/features/agent/local-tools.ts @@ -42,14 +42,14 @@ const validSourceCursor = (value: unknown): value is SourceCursor => integer(value.offset, 0) export type WorkspaceTextWriter = ( - name: string, + path: string, content: string, signal?: AbortSignal, ) => Promise{document.name}
+{document.path}
{formatBytes(document.size)}This file is stored locally and can be used as context in a later iteration.
{drafts[file.id]?.saveError}
}- This removes the browser copy of {file.name}. The original file on your + This removes the browser copy of {file.path}. The original file on your computer will not change.
{dirty &&Unsaved source changes will also be discarded.
} diff --git a/ui-packages/web/src/features/resources/file-tree.ts b/ui-packages/web/src/features/resources/file-tree.ts new file mode 100644 index 0000000..c9a7090 --- /dev/null +++ b/ui-packages/web/src/features/resources/file-tree.ts @@ -0,0 +1,50 @@ +import { baseName, type StoredFileMetadata } from '../../core/files' + +export type FileTreeNode = + | { kind: 'folder'; key: string; name: string; children: FileTreeNode[] } + | { kind: 'file'; file: StoredFileMetadata; name: string } + +type FolderNode = Extract