Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): expose project boards to the client
joshistoast61aef53dfae3
diff --git a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjsindex 660bfd9ad6..2154cbefe1 100644--- a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.mjs@@ -36,6 +36,9 @@ export const MOCK_BACKEND_REPRESENTATIVE_VIDEO_NAME = 'fixture-video-001.mp4';const FIXED_EPOCH_MS = Date.parse(MOCK_BACKEND_FIXED_EPOCH);const range = (length, build) => Array.from({ length }, (_, index) => build(index));const ordinal = (index, width = 3) => String(index + 1).padStart(width, '0');++/** The single user every fixture belongs to; matches `MOCK_USER_ID` in the mock backend. */+const FIXTURE_USER_ID = 'fixture-user';const timestampAt = (index) => new Date(FIXED_EPOCH_MS - index * 60_000).toISOString();export const isMockBackendProfileName = (value) => MOCK_BACKEND_PROFILE_NAMES.includes(value);@@ -207,45 +210,66 @@ const createVideos = () => [},];-const createBoards = (images, videos) =>- range(10, (index) => {- const boardId = `fixture-board-${ordinal(index, 2)}`;- const boardImages = images.filter((image) => image.board_id === boardId);- const boardVideos = videos.filter((video) => video.board_id === boardId);- const cover = [- ...boardImages.map((image) => ({- createdAt: image.created_at,- kind: 'image',- name: image.image_name,- starred: image.starred,- })),- ...boardVideos.map((video) => ({- createdAt: video.created_at,- kind: 'video',- name: video.video_name,- starred: video.starred,- })),- ].sort(- (left, right) =>- Number(right.starred) - Number(left.starred) ||- right.createdAt.localeCompare(left.createdAt) ||- right.kind.localeCompare(left.kind) ||- right.name.localeCompare(left.name)- )[0];+/**+ * The board a project owns. Every project has exactly one, and only project APIs may rename or+ * delete it — the generic board routes refuse a claimed board.+ */+export const projectBoardId = (index) => `fixture-project-board-${ordinal(index, 2)}`;++const buildBoard = (boardId, boardName, images, videos, createdAt) => {+ const boardImages = images.filter((image) => image.board_id === boardId);+ const boardVideos = videos.filter((video) => video.board_id === boardId);+ const cover = [+ ...boardImages.map((image) => ({+ createdAt: image.created_at,+ kind: 'image',+ name: image.image_name,+ starred: image.starred,+ })),+ ...boardVideos.map((video) => ({+ createdAt: video.created_at,+ kind: 'video',+ name: video.video_name,+ starred: video.starred,+ })),+ ].sort(+ (left, right) =>+ Number(right.starred) - Number(left.starred) ||+ right.createdAt.localeCompare(left.createdAt) ||+ right.kind.localeCompare(left.kind) ||+ right.name.localeCompare(left.name)+ )[0];- return {- archived: false,- asset_count: boardImages.filter((image) => image.image_category !== 'general').length,- board_id: boardId,- board_name: `Fixture Board ${ordinal(index, 2)}`,- cover_image_name: cover?.kind === 'image' ? cover.name : null,- cover_video_name: cover?.kind === 'video' ? cover.name : null,- created_at: timestampAt(index * 10),- image_count: boardImages.filter((image) => image.image_category === 'general').length,- owner_username: null,- video_count: boardVideos.length,- };- });+ return {+ archived: false,+ asset_count: boardImages.filter((image) => image.image_category !== 'general').length,+ board_id: boardId,+ board_name: boardName,+ board_visibility: 'private',+ cover_image_name: cover?.kind === 'image' ? cover.name : null,+ cover_video_name: cover?.kind === 'video' ? cover.name : null,+ created_at: createdAt,+ image_count: boardImages.filter((image) => image.image_category === 'general').length,+ owner_username: null,+ user_id: FIXTURE_USER_ID,+ video_count: boardVideos.length,+ };+};++const createBoards = (images, videos, projectCount) => [+ ...range(10, (index) =>+ buildBoard(+ `fixture-board-${ordinal(index, 2)}`,+ `Fixture Board ${ordinal(index, 2)}`,+ images,+ videos,+ timestampAt(index * 10)+ )+ ),+ ...range(projectCount, (index) =>+ buildBoard(projectBoardId(index), `Fixture Project ${ordinal(index, 3)}`, images, videos, timestampAt(index))+ ),+];const QUEUE_STATUSES = ['pending', 'waiting', 'in_progress', 'completed', 'failed', 'canceled'];@@ -537,6 +561,8 @@ const createProjects = (count, workflowNodeCount, layerCount) =>const timestamp = timestampAt(index);return {+ // Every project owns exactly one private board; the server is authoritative for which.+ board_id: projectBoardId(index),created_at: timestamp,data,name: data.name,@@ -597,7 +623,7 @@ const createRepresentativeFixture = () => {const videos = createVideos();return {- boards: createBoards(images, videos),+ boards: createBoards(images, videos, counts.projects),images,models: createModels(counts.models),nodeCatalog: {diff --git a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjs b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjsindex 28b5c06763..17776e852d 100644--- a/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend-fixtures.test.mjs@@ -506,3 +506,136 @@ test('the representative video accessibility journey owns the only generated-medassert.match(source, /getByRole\('list', \{ exact: true, name: 'Gallery items' \}\)/);assert.match(source, /INVOKEAI_ACCESSIBILITY_JOURNEY/);});++test('project boards are owned, protected from the generic board routes, and enumerable', async () => {+ await withRepresentativeBackend(async (backend) => {+ const projects = await getJson(backend, '/api/v1/projects/');+ const project = projects.find((entry) => entry.project_id === 'fixture-project-002');++ // Every project owns exactly one board, and no two share one.+ assert.equal(new Set(projects.map((entry) => entry.board_id)).size, projects.length);+ assert.ok(project.board_id);++ const board = await getJson(backend, `/api/v1/boards/${project.board_id}`);+ assert.equal(board.project_id, project.project_id);+ assert.equal(board.board_name, project.name);++ // An unclaimed board omits the key entirely, matching the backend's null-excluding DTO.+ const plainBoard = await getJson(backend, '/api/v1/boards/fixture-board-02');+ assert.equal('project_id' in plainBoard, false);++ // The generic routes refuse a claimed board; only the project APIs may touch it.+ for (const [method, path, body] of [+ ['PATCH', `/api/v1/boards/${project.board_id}`, { board_name: 'Renamed' }],+ ['DELETE', `/api/v1/boards/${project.board_id}?include_images=true`, undefined],+ ]) {+ const refused = await fetch(`${backend.origin}${path}`, {+ body: body === undefined ? undefined : JSON.stringify(body),+ headers: { 'content-type': 'application/json' },+ method,+ });+ assert.equal(refused.status, 409, `${method} ${path} should be refused`);+ }+ assert.equal((await getJson(backend, `/api/v1/boards/${project.board_id}`)).board_name, project.name);++ // Renaming the project renames its board; the two never disagree.+ await getJson(backend, `/api/v1/projects/${project.project_id}`, {+ body: JSON.stringify({ data: project.data, expected_revision: project.revision, name: 'Renamed Project' }),+ headers: { 'content-type': 'application/json' },+ method: 'PUT',+ });+ assert.equal((await getJson(backend, `/api/v1/boards/${project.board_id}`)).board_name, 'Renamed Project');+ });+});++test('the board snapshot lists only what the gallery would show on a project board', async () => {+ await withRepresentativeBackend(async (backend) => {+ const [project] = await getJson(backend, '/api/v1/projects/');+ const boardId = project.board_id;+ const upload = async (category, isIntermediate) => {+ const form = new FormData();+ form.append('file', new Blob(['x'], { type: 'image/png' }), `${category}-${isIntermediate}.png`);+ const created = await fetch(+ `${backend.origin}/api/v1/images/upload?image_category=${category}` ++ `&is_intermediate=${isIntermediate}&board_id=${boardId}`,+ { body: form, method: 'POST' }+ );+ return (await created.json()).image_name;+ };++ const general = await upload('general', false);+ const control = await upload('control', false);+ await upload('other', false);+ await upload('general', true);++ const snapshot = await getJson(backend, `/api/v1/projects/${project.project_id}/board-snapshot`);++ // `other` is the canvas's private category and intermediates are hidden — neither travels.+ assert.deepEqual(snapshot.items.map((item) => item.name).sort(), [control, general].sort());+ assert.deepEqual(snapshot.items.map((item) => item.category).sort(), ['control', 'general']);+ assert.equal(+ snapshot.items.every((item) => item.kind === 'image' && item.starred === false),+ true+ );++ await getJson(backend, '/api/v1/images/star', {+ body: JSON.stringify({ image_names: [general] }),+ headers: { 'content-type': 'application/json' },+ method: 'POST',+ });+ const starred = await getJson(backend, `/api/v1/projects/${project.project_id}/board-snapshot`);+ assert.equal(starred.items.find((item) => item.name === general).starred, true);++ assert.equal((await fetch(`${backend.origin}/api/v1/projects/nope/board-snapshot`)).status, 404);+ });+});++test('copying media mints fresh identities and deleting a project keeps its media', async () => {+ await withRepresentativeBackend(async (backend) => {+ const [project] = await getJson(backend, '/api/v1/projects/');+ const source = 'fixture-image-0002.png';++ const staging = await getJson(backend, '/api/v1/boards/?board_name=Staging', { method: 'POST' });+ const copied = await getJson(backend, '/api/v1/images/copy', {+ body: JSON.stringify({ board_id: staging.board_id, image_names: [source, 'missing.png'] }),+ headers: { 'content-type': 'application/json' },+ method: 'POST',+ });++ assert.deepEqual(copied.failed, ['missing.png']);+ assert.equal(copied.copied.length, 1);+ const [{ image_name: copyName }] = copied.copied;+ // A copy is a new identity, because board membership keys on the name.+ assert.notEqual(copyName, source);+ const copy = await getJson(backend, `/api/v1/images/i/${copyName}`);+ assert.equal(copy.board_id, staging.board_id);+ assert.equal(copy.image_category, (await getJson(backend, `/api/v1/images/i/${source}`)).image_category);+ // The source keeps its own board.+ assert.notEqual((await getJson(backend, `/api/v1/images/i/${source}`)).board_id, staging.board_id);++ // The staging board can then be claimed, which is how an import commits.+ const claimed = await getJson(backend, '/api/v1/projects/', {+ body: JSON.stringify({ board_id: staging.board_id, data: {}, name: 'Imported', project_id: 'imported-1' }),+ headers: { 'content-type': 'application/json' },+ method: 'POST',+ });+ assert.equal(claimed.board_id, staging.board_id);+ // ...but only once.+ const second = await fetch(`${backend.origin}/api/v1/projects/`, {+ body: JSON.stringify({ board_id: staging.board_id, data: {}, name: 'Again', project_id: 'imported-2' }),+ headers: { 'content-type': 'application/json' },+ method: 'POST',+ });+ assert.equal(second.status, 409);++ // Deleting a project removes its board but leaves the media uncategorized.+ await fetch(`${backend.origin}/api/v1/projects/${claimed.project_id}`, { method: 'DELETE' });+ assert.equal((await fetch(`${backend.origin}/api/v1/boards/${staging.board_id}`)).status, 404);+ assert.equal((await getJson(backend, `/api/v1/images/i/${copyName}`)).board_id, null);++ assert.equal(+ (await getJson(backend, '/api/v1/projects/')).some((entry) => entry.project_id === project.project_id),+ true+ );+ });+});diff --git a/invokeai/frontend/webv2/scripts/mock-backend.mjs b/invokeai/frontend/webv2/scripts/mock-backend.mjsindex aaa8be8e29..24cd2bc638 100644--- a/invokeai/frontend/webv2/scripts/mock-backend.mjs+++ b/invokeai/frontend/webv2/scripts/mock-backend.mjs@@ -65,6 +65,7 @@ const createState = (profile) => {images: new Map(fixture.images.map((image) => [image.image_name, clone(image)])),models: new Map(fixture.models.map((model) => [model.key, clone(model)])),mutationClock: 0,+ nextBoardNumber: fixture.boards.length + 1,nextImageNumber: fixture.images.length + 1,nextProjectNumber: fixture.projects.length + 1,nextVideoNumber: fixture.videos.length + 1,@@ -87,6 +88,7 @@ const timestamp = (state) => {};const summaryOf = (project) => ({+ board_id: project.board_id,created_at: project.created_at,name: project.name,project_id: project.project_id,@@ -358,6 +360,44 @@ const listVideos = (state, url) => {};};+/** The project that owns this board, if any. Derived, exactly as the backend derives it. */+const projectIdForBoard = (state, boardId) =>+ [...state.projects.values()].find((project) => project.board_id === boardId)?.project_id ?? null;++/**+ * Visible board membership, matching `GET /projects/{id}/board-snapshot`: intermediates and the+ * canvas's private `other` category are excluded, and the result is sorted by kind then name.+ */+const boardSnapshotItems = (state, boardId) => {+ const visible = (category) => ['general', 'control', 'mask', 'user'].includes(category);+ const items = [+ ...[...state.images.values()]+ .filter((image) => image.board_id === boardId && !image.is_intermediate && visible(image.image_category))+ .map((image) => ({+ category: image.image_category,+ kind: 'image',+ name: image.image_name,+ starred: Boolean(image.starred),+ })),+ ...[...state.videos.values()]+ .filter(+ (video) =>+ video.board_id === boardId &&+ video.owner_user_id === MOCK_USER_ID &&+ !video.is_intermediate &&+ visible(video.video_category)+ )+ .map((video) => ({+ category: video.video_category,+ kind: 'video',+ name: video.video_name,+ starred: Boolean(video.starred),+ })),+ ];++ return items.sort((left, right) => left.kind.localeCompare(right.kind) || left.name.localeCompare(right.name));+};+const boardDto = (state, board) => {const images = [...state.images.values()].filter((image) => image.board_id === board.board_id);const videos = [...state.videos.values()].filter(@@ -384,12 +424,16 @@ const boardDto = (state, board) => {right.name.localeCompare(left.name))[0];+ const projectId = projectIdForBoard(state, board.board_id);+return {...board,asset_count: images.filter((image) => image.image_category !== 'general').length,cover_image_name: cover?.kind === 'image' ? cover.name : null,cover_video_name: cover?.kind === 'video' ? cover.name : null,image_count: images.filter((image) => image.image_category === 'general').length,+ // The backend's BoardRecord excludes nulls, so an unclaimed board omits the key entirely.+ ...(projectId === null ? {} : { project_id: projectId }),video_count: videos.length,};};@@ -594,10 +638,42 @@ export const startMockBackend = async (port, { profile = 'empty' } = {}) => {const now = timestamp(state);const projectNumber = state.nextProjectNumber;+ const name = requested.name ?? `Project Name #${projectNumber}`;++ // Creating a project either adopts the board it was given or makes one. Adopting is what+ // lets an import upload its media before the project exists, so that creating the project+ // is the import's single commit point.+ let boardId = requested.board_id ?? null;+ if (boardId === null) {+ boardId = `mock-project-board-${projectNumber}`;+ state.boards.set(boardId, {+ archived: false,+ board_id: boardId,+ board_name: name,+ board_visibility: 'private',+ created_at: now,+ deleted_at: null,+ owner_username: null,+ updated_at: now,+ user_id: MOCK_USER_ID,+ });+ } else {+ const board = state.boards.get(boardId);+ if (!board) {+ return json(404, { detail: 'Board not found' });+ }+ if (board.board_visibility !== 'private' || projectIdForBoard(state, boardId) !== null) {+ return json(409, { detail: 'Board is not available to be claimed by a project' });+ }+ board.board_name = name;+ board.updated_at = now;+ }+const project = {+ board_id: boardId,created_at: now,data: requested.data ?? {},- name: requested.name ?? `Project Name #${projectNumber}`,+ name,project_id: requested.project_id ?? `mock-project-${projectNumber}`,revision: 1,updated_at: now,@@ -634,14 +710,44 @@ export const startMockBackend = async (port, { profile = 'empty' } = {}) => {project.revision += 1;project.updated_at = timestamp(state);+ // The board's name tracks the project's; the two commit together.+ const board = state.boards.get(project.board_id);+ if (board) {+ board.board_name = project.name;+ board.updated_at = project.updated_at;+ }+return json(200, project);}if (method === 'DELETE') {- state.projects.delete(projectId);+ if (project) {+ state.projects.delete(projectId);+ // The board goes with the project; its media survives as uncategorized.+ state.boards.delete(project.board_id);+ for (const image of state.images.values()) {+ if (image.board_id === project.board_id) {+ image.board_id = null;+ }+ }+ for (const video of state.videos.values()) {+ if (video.board_id === project.board_id) {+ video.board_id = null;+ }+ }+ }return json(200, { ok: true });}}+ const boardSnapshotMatch = /^\/api\/v1\/projects\/([^/]+)\/board-snapshot$/.exec(path);+ if (method === 'GET' && boardSnapshotMatch) {+ const project = state.projects.get(decodeURIComponent(boardSnapshotMatch[1]));++ return project+ ? json(200, { items: boardSnapshotItems(state, project.board_id) })+ : json(404, { detail: 'Project not found' });+ }+if (path.startsWith('/api/v1/client_state/')) {const key = url.searchParams.get('key') ?? '';@@ -788,11 +894,33 @@ export const startMockBackend = async (port, { profile = 'empty' } = {}) => {return json(200, state.nodeCatalog);}- if (method === 'GET' && (path === '/api/v1/boards' || path === '/api/v1/boards/')) {- return json(- 200,- [...state.boards.values()].map((board) => boardDto(state, board))- );+ if (path === '/api/v1/boards' || path === '/api/v1/boards/') {+ if (method === 'GET') {+ return json(+ 200,+ [...state.boards.values()].map((board) => boardDto(state, board))+ );+ }+ if (method === 'POST') {+ const now = timestamp(state);+ const boardId = `mock-board-${state.nextBoardNumber}`;+ const board = {+ archived: false,+ board_id: boardId,+ board_name: url.searchParams.get('board_name') ?? `Board ${state.nextBoardNumber}`,+ board_visibility: 'private',+ created_at: now,+ deleted_at: null,+ owner_username: null,+ updated_at: now,+ user_id: MOCK_USER_ID,+ };++ state.nextBoardNumber += 1;+ state.boards.set(boardId, board);++ return json(201, boardDto(state, board));+ }}const boardMatch = /^\/api\/v1\/boards\/([^/]+)$/.exec(path);@@ -806,7 +934,34 @@ export const startMockBackend = async (port, { profile = 'empty' } = {}) => {if (method === 'GET') {return json(200, boardDto(state, board));}+ if (method === 'PATCH') {+ const changes = await readJsonBody(request);++ // A project's board takes its name, archived state and visibility from the project.+ if (+ projectIdForBoard(state, boardId) !== null &&+ (changes.board_name !== undefined ||+ changes.archived !== undefined ||+ changes.board_visibility !== undefined)+ ) {+ return json(409, { detail: 'This board belongs to a project' });+ }++ for (const key of ['archived', 'board_name', 'board_visibility', 'cover_image_name']) {+ if (changes[key] !== undefined) {+ board[key] = changes[key];+ }+ }+ board.updated_at = timestamp(state);++ return json(201, boardDto(state, board));+ }if (method === 'DELETE') {+ if (projectIdForBoard(state, boardId) !== null) {+ // Refused before any media is touched — the whole point of the ordering.+ return json(409, { detail: 'This board belongs to a project' });+ }+const includeImages = url.searchParams.get('include_images') === 'true';const boardImages = [...state.images.values()].filter((image) => image.board_id === boardId);const boardVideos = [...state.videos.values()].filter(@@ -918,6 +1073,114 @@ export const startMockBackend = async (port, { profile = 'empty' } = {}) => {return json(201, image);}+ if (method === 'POST' && (path === '/api/v1/images/star' || path === '/api/v1/images/unstar')) {+ const body = await readJsonBody(request);+ const names = Array.isArray(body.image_names) ? [...new Set(body.image_names)] : [];+ const succeeded = [];+ const affectedBoards = [];+ const starred = path.endsWith('/star');++ for (const name of names) {+ const image = state.images.get(name);++ if (!image) {+ continue;+ }+ image.starred = starred;+ succeeded.push(name);+ affectedBoards.push(image.board_id ?? 'none');+ }++ return json(200, {+ affected_boards: [...new Set(affectedBoards)],+ ...(starred ? { starred_images: succeeded } : { unstarred_images: succeeded }),+ });+ }++ if (method === 'POST' && path === '/api/v1/images/copy') {+ const body = await readJsonBody(request);+ const names = Array.isArray(body.image_names) ? body.image_names : [];+ const boardId = body.board_id ?? null;++ if (boardId !== null && !state.boards.has(boardId)) {+ return json(404, { detail: 'Board not found' });+ }++ const copied = [];+ const failed = [];++ for (const name of names) {+ const source = state.images.get(name);++ if (!source) {+ failed.push(name);+ continue;+ }++ const suffix = String(state.nextImageNumber).padStart(3, '0');+ const imageName = `fixture-copy-${suffix}.png`;+ const now = timestamp(state);++ state.nextImageNumber += 1;+ // A genuinely new identity: `board_images` keys on the name, so a copy must own its own.+ // Category and provenance travel; starring does not (callers use /images/star).+ state.images.set(imageName, {+ ...clone(source),+ board_id: boardId,+ created_at: now,+ image_name: imageName,+ image_url: `/api/v1/images/i/${imageName}/full`,+ is_intermediate: false,+ starred: false,+ thumbnail_url: `/api/v1/images/i/${imageName}/thumbnail`,+ updated_at: now,+ });+ copied.push({ image_name: imageName, source_image_name: name });+ }++ return json(200, { copied, failed });+ }++ if (method === 'POST' && path === '/api/v1/videos/copy') {+ const body = await readJsonBody(request);+ const names = Array.isArray(body.video_names) ? body.video_names : [];+ const boardId = body.board_id ?? null;++ if (boardId !== null && !state.boards.has(boardId)) {+ return json(404, { detail: 'Board not found' });+ }++ const copied = [];+ const failed = [];++ for (const name of names) {+ const source = state.videos.get(name);++ if (!source || source.owner_user_id !== MOCK_USER_ID) {+ failed.push(name);+ continue;+ }++ const suffix = String(state.nextVideoNumber).padStart(3, '0');+ const videoName = `fixture-copy-${suffix}.mp4`;+ const now = timestamp(state);++ state.nextVideoNumber += 1;+ state.videos.set(videoName, {+ ...clone(source),+ board_id: boardId,+ created_at: now,+ is_intermediate: false,+ starred: false,+ updated_at: now,+ video_name: videoName,+ });+ copied.push({ source_video_name: name, video_name: videoName });+ }++ return json(200, { copied, failed });+ }+if (method === 'GET' && (path === '/api/v1/images' || path === '/api/v1/images/')) {return json(200, listImages(state, url));}diff --git a/invokeai/frontend/webv2/src/workbench/projects/api.ts b/invokeai/frontend/webv2/src/workbench/projects/api.tsindex 5892151a24..1e7b1f1f10 100644--- a/invokeai/frontend/webv2/src/workbench/projects/api.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/api.ts@@ -13,6 +13,11 @@ const CLIENT_STATE_BASE = '/api/v1/client_state/default';export interface ProjectSummaryDTO {project_id: string;+ /**+ * The project's private board. Authoritative: the `projectBoardId` in the project document is a+ * cache the client overwrites from this on hydration, never the other way round.+ */+ board_id: string;name: string;revision: number;created_at: string;@@ -25,10 +30,33 @@ export interface ProjectRecordDTO extends ProjectSummaryDTO {export interface ProjectCreateRequest {project_id?: string;+ /**+ * An existing unclaimed private board for the new project to adopt, renamed to match. Omit to+ * have the server create one.+ *+ * Restoring a project uploads its media into such a board first and passes it here, which makes+ * creating the project the single commit point for an import: the media is in place before the+ * project exists, and a create that fails leaves no half-built project behind.+ */+ board_id?: string;name: string;data: Record<string, unknown>;}+export type ProjectBoardItemKind = 'image' | 'video';+export type ProjectBoardItemCategory = 'general' | 'control' | 'mask' | 'user';++export interface ProjectBoardItemDTO {+ category: ProjectBoardItemCategory;+ kind: ProjectBoardItemKind;+ name: string;+ starred: boolean;+}++export interface ProjectBoardSnapshotDTO {+ items: ProjectBoardItemDTO[];+}+export interface ProjectUpdateRequest {name: string;data: Record<string, unknown>;@@ -59,6 +87,17 @@ export const deleteProject = async (projectId: string, signal?: AbortSignal): Prawait apiFetch(`${PROJECTS_BASE}/${encodeURIComponent(projectId)}`, { method: 'DELETE', signal });};+/**+ * Everything on the project's board that the gallery would show — including results the document+ * never references, which is exactly what a project file has to carry to be the whole workspace+ * rather than only the canvas. Intermediates and the canvas's private `other` category are+ * excluded by the backend.+ */+export const getProjectBoardSnapshot = (projectId: string, signal?: AbortSignal): Promise<ProjectBoardSnapshotDTO> =>+ apiFetchJson<ProjectBoardSnapshotDTO>(`${PROJECTS_BASE}/${encodeURIComponent(projectId)}/board-snapshot`, {+ signal,+ });+/** A save was based on a stale revision — another tab or device saved first. */export const isProjectConflictError = (error: unknown): boolean => error instanceof ApiError && error.status === 409;