feat(storage): add archive storage support for assets

This commit is contained in:
yiling
2026-11-02 13:19:10 +08:00
parent 49a2d7c380
commit 9097ec12bb
100 changed files with 6180 additions and 170 deletions
@@ -0,0 +1,36 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const archiveAssets = defineOperation({
name: 'archive_assets',
title: 'Archive Assets',
description:
'Move the original raw file(s) of one or more assets (files, version stacks, or folders) to ' +
'cold archive storage. All transcoded proxies, previews, and thumbnails remain in main ' +
'storage so assets stay viewable, while original raw file downloads are disabled until restored.',
input: z.object({
assetIds: z
.array(z.string().min(1))
.min(1)
.describe(
'The IDs of the assets (files, version stacks, or folders) to archive. Archiving a folder or version stack archives all eligible files inside it.',
),
}),
output: z.object({
archivedAssetIds: z.array(z.string()).describe('IDs of the file assets queued for archiving.'),
taskIds: z.array(z.string()).describe('IDs of the archive workflow tasks created.'),
skippedCount: z
.number()
.describe(
'Number of candidate files skipped (e.g. already archived or currently archiving).',
),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false, idempotent: true },
cli: {
command: ['archive'],
positional: ['assetIds'],
format: (output) =>
`Queued ${output.archivedAssetIds.length} asset(s) for archiving (${output.skippedCount} skipped)`,
},
})
@@ -0,0 +1,36 @@
import { z } from 'zod'
import { defineOperation } from '../define'
export const restoreArchivedAssets = defineOperation({
name: 'restore_archived_assets',
title: 'Restore Archived Assets',
description:
'Restore the original raw file(s) of one or more archived assets (files, version stacks, or ' +
'folders) from cold archive storage back to main storage.',
input: z.object({
assetIds: z
.array(z.string().min(1))
.min(1)
.describe(
'The IDs of the archived assets (files, version stacks, or folders) to restore back to main storage.',
),
}),
output: z.object({
restoredAssetIds: z
.array(z.string())
.describe('IDs of the file assets queued for restoration.'),
taskIds: z.array(z.string()).describe('IDs of the restore workflow tasks created.'),
skippedCount: z
.number()
.describe('Number of candidate files skipped (e.g. not archived or already restoring).'),
}),
surfaces: ['agent', 'mcp', 'cli'],
annotations: { readOnly: false, destructive: false, idempotent: true },
cli: {
command: ['unarchive'],
aliases: ['restore-archive'],
positional: ['assetIds'],
format: (output) =>
`Queued ${output.restoredAssetIds.length} asset(s) for restoration from archive (${output.skippedCount} skipped)`,
},
})
@@ -28,7 +28,7 @@ const conditionSchema = z.object({
.min(1)
.describe(
'Metadata field key from list_metadata_fields (e.g. "status"), or one of "name", ' +
'"sizeByte", "createdAt", "updatedAt".',
'"sizeByte", "createdAt", "updatedAt", "isArchived".',
),
operator: z
.enum(SEARCH_CONDITION_OPERATORS)
+2
View File
@@ -2,6 +2,7 @@ export * from './define'
export * from './schemas'
export * from './registry'
export { dropNullOptionals } from './null-optionals'
export { archiveAssets } from './asset/archive-assets'
export { copyAssets } from './asset/copy-assets'
export { createFolder } from './asset/create-folder'
export { deleteAsset } from './asset/delete-asset'
@@ -9,6 +10,7 @@ export { getFolderInstructions } from './asset/get-folder-instructions'
export { listAssets } from './asset/list-assets'
export { moveAssets } from './asset/move-assets'
export { renameAsset } from './asset/rename-asset'
export { restoreArchivedAssets } from './asset/restore-archived-assets'
export * from './asset/search-assets'
export * from './asset/read-asset'
export * from './asset/download-asset'
+4
View File
@@ -17,6 +17,7 @@ describe('operation registry', () => {
it('contains the asset, project, comment, metadata, version, and upload operations', () => {
expect(operationDefinitions.map((d) => d.name).sort()).toEqual([
'archive_assets',
'complete_upload',
'copy_assets',
'create_comment',
@@ -38,6 +39,7 @@ describe('operation registry', () => {
'remove_version',
'rename_asset',
'resolve_comment',
'restore_archived_assets',
'search_assets',
'update_asset_metadata',
])
@@ -128,6 +130,8 @@ describe('operation registry', () => {
['move_assets', ['move', 'mv']],
['copy_assets', ['copy', 'cp']],
['delete_asset', ['delete', 'rm']],
['archive_assets', ['archive']],
['restore_archived_assets', ['unarchive', 'restore-archive']],
['read_asset', ['read']],
['get_asset_render', ['render']],
['download_asset', ['download']],
+4
View File
@@ -1,3 +1,4 @@
import { archiveAssets } from './asset/archive-assets'
import { copyAssets } from './asset/copy-assets'
import { createFolder } from './asset/create-folder'
import { deleteAsset } from './asset/delete-asset'
@@ -7,6 +8,7 @@ import { listAssets } from './asset/list-assets'
import { moveAssets } from './asset/move-assets'
import { getAssetRender, readAsset } from './asset/read-asset'
import { renameAsset } from './asset/rename-asset'
import { restoreArchivedAssets } from './asset/restore-archived-assets'
import { searchAssets } from './asset/search-assets'
import { createComment } from './comment/create-comment'
import { listComments } from './comment/list-comments'
@@ -35,6 +37,8 @@ export const operationDefinitions = [
moveAssets,
copyAssets,
deleteAsset,
archiveAssets,
restoreArchivedAssets,
readAsset,
getAssetRender,
downloadAsset,