diff --git a/apps/api/src/opendirector_api/localization.py b/apps/api/src/opendirector_api/localization.py index c94c74953..66e303f5e 100644 --- a/apps/api/src/opendirector_api/localization.py +++ b/apps/api/src/opendirector_api/localization.py @@ -288,6 +288,8 @@ def localized_error_for_language( return translated if code == 'command_conflict' and chinese == '该工程标识已经使用。': return 'This project ID is already in use.' + if code == 'invalid_input' and chinese == '对象标识已存在。': + return 'This object ID is already in use.' if code == 'invalid_input' and chinese == '聊天引用超过数量上限,请移除部分引用。': return 'The chat reference limit was exceeded. Remove some references and retry.' if code == 'invalid_input' and chinese == '视频裁切需要视频来源节点。': diff --git a/docs/guides/cli.md b/docs/guides/cli.md index 3ace1e3e1..a2cb1351c 100644 --- a/docs/guides/cli.md +++ b/docs/guides/cli.md @@ -95,6 +95,10 @@ Agent 的 Shell 通过 PATH 使用同一个 `opendirector`。宿主提供受令 ## 可编辑时间线文字与跨工程包 +用 `opendirector timeline create --file timeline.json` 一次创建可编辑时间线及其画布节点。文件的 `payload.document` 保存完整时间线,`payload.itemId` 指定独立的新节点 ID。可选的 `title` 和 `position` 指定节点标题与画布位置。回执列出文档和节点。重试时保留相同的 `--operation-id` 和输入。仅需创建文档时使用 `editor create`。 + +写入 `timeline.create` 历史后,请使用支持该命令的版本打开工程。若需要切回旧版,请使用执行该命令前的工程备份。 + 时间线文字与媒体使用同一 `editor.create` / `editor.save` 文档,正文、时间、样式、层次和字体资产均保存在工程中。先通过 `query object.get` 读取文档,保留完整文档结构并携带当前 `editor_document` 版本提交;不要直接修改项目文件。`editor save --help` / `--help-field payload.document` 提供正式契约。正文来源是可选的不可变文本资产引用,不会随着来源后续变化自动改写文字。 ```bash @@ -125,6 +129,10 @@ Agent 执行上下文可使用相同命令,路径须位于本轮执行目录 ### Editable timeline text and portable packages +Run `opendirector timeline create --file timeline.json` to create an editable timeline and its canvas node in one command. Set `payload.document` to the complete timeline and `payload.itemId` to a fresh node ID. Use the optional `title` and `position` fields to place and name the node. The receipt lists both objects. Reuse the same `--operation-id` and inputs on retry. Use `editor create` when you only need a document. + +After `timeline.create` is recorded in the project history, open the project in a version that supports the command. To return to an older version, use a project backup from before the command ran. + Text uses the same complete `editor.create` / `editor.save` document as media. Read the current document with `query object.get`, preserve its structure, and submit its current `editor_document` revision. The schema and nested fields are available through `editor save --help` and `--help-field payload.document`. `timeline default-font` finds the bundled offline font without opening a project; import that file into the target project before referencing its AssetRef. Text-source references retain immutable provenance and do not automatically refresh the wording. The commands above export an exact saved revision, import it as a new timeline, or explicitly replace a target with `--replace-editor` and `--expected-revision`. Export destinations must not already exist. Native `.timeline.zip` packages include all retained font, clip, media-library and text-source resources plus the bundled font license; target resources belong to the target project. The package limit is 512 MiB. Unknown versions/capabilities, missing resources, and fingerprint mismatches reject import. Only an `applied` receipt confirms the completed timeline write; retry incomplete operations with the same operation ID, file, and arguments. Replacement rechecks the current revision and owner/parent locks. diff --git a/packages/core/src/opendirector/agent/tools.py b/packages/core/src/opendirector/agent/tools.py index 3d481890f..b1a56be56 100644 --- a/packages/core/src/opendirector/agent/tools.py +++ b/packages/core/src/opendirector/agent/tools.py @@ -84,6 +84,7 @@ def query_guidance(failure): Use opendirector asset download with the saved asset ID and revision to inspect original bytes in the execution directory. Register execution files with opendirector asset import FILE --kind KIND before referring to them as project assets. For independently processed clips, register each execution file and add a material node. The video trim command publishes its own output asset and node. For Motion canvas nodes, publish rendered MP4s with opendirector motion render --publish-item-id so the video node stays linked to its source Motion node. +Use opendirector timeline create to deliver a new editable timeline on the canvas. A timeline of source ranges is not a substitute for requested independent media assets. Successful generation results are already registered project assets. Inspect them using their existing asset identity and canvas item. Do not publish inspection copies or extracted inspection frames, or add another canvas item for the same delivery unless the user requests it. Publish newly created deliverables after editing or processing. A command receipt is execution evidence, not quality approval. Preserve user constraints. @@ -285,6 +286,9 @@ def invalid_path(level: str, node: dict, requested: str) -> ProjectError: spec['purpose'] = 'generation' item['kind'] = spec['kind'] item['binding'] = {'role': 'generation', 'objectRef': {'id': spec['id']}} + if command == 'timeline.create': + example['payload']['document']['id'] = str(uuid5(project_id, 'example:timeline-document')) + example['payload']['itemId'] = str(uuid5(project_id, 'example:timeline-node')) if command == 'generation.submit': example['payload']['originItemId'] = str(project_id) model = COMMANDS[command] diff --git a/packages/core/src/opendirector/application/creation_canvas.py b/packages/core/src/opendirector/application/creation_canvas.py index 4953dc450..421300c2f 100644 --- a/packages/core/src/opendirector/application/creation_canvas.py +++ b/packages/core/src/opendirector/application/creation_canvas.py @@ -13,9 +13,9 @@ from opendirector.domain.creation.assets import AssetRef from opendirector.domain.creation.base import CanvasItemVersion, ObjectVersion, Point -from opendirector.domain.creation.commands import CanvasShow, Query, ReferenceWrite, SpecWrite +from opendirector.domain.creation.commands import CanvasShow, EditorWrite, Query, ReferenceWrite, SpecWrite from opendirector.domain.creation.generation import FollowingSource, ResolvedReference -from opendirector.domain.creation.canvas import CanvasReferenceSources, canvas_origin, FollowingReferenceSource, PinnedReferenceSource, media_card_size, node_capabilities, VideoCanvasItem +from opendirector.domain.creation.canvas import CanvasReferenceSources, canvas_origin, FollowingReferenceSource, PinnedReferenceSource, media_card_size, node_capabilities, TimelineCanvasItem, VideoCanvasItem from opendirector.domain.creation.models import ModelConfigPublic from opendirector.domain.creation.project import ProjectSnapshot, asset_references from opendirector.domain.creation.index import object_index @@ -520,6 +520,14 @@ def _mutate(self, data, kind, payload): if kind == 'canvas.publishMedia': from .creation_media_publication import publish_media publish_media(self, data, payload) + elif kind == 'timeline.create': + if any(item['id'] == str(payload.itemId) for item in data['canvasItems']): + raise ContractError('invalid_input', '对象标识已存在。', payload.itemId) + self._mutate(data, 'editor.create', EditorWrite(document=payload.document)) + item = TimelineCanvasItem(id=payload.itemId, projectId=payload.document.projectId, + kind='timeline', title=payload.title, position=payload.position, + binding=dict(role='editor', objectRef=dict(id=payload.document.id, kind='timeline'))) + self._mutate(data, 'canvas.show', CanvasShow(item=item)) elif kind == 'timeline.publishRender': self._publish_render(data, payload) elif kind == 'canvas.createGeneration': diff --git a/packages/core/src/opendirector/application/creation_history.py b/packages/core/src/opendirector/application/creation_history.py index 373bc3945..386302acb 100644 --- a/packages/core/src/opendirector/application/creation_history.py +++ b/packages/core/src/opendirector/application/creation_history.py @@ -14,7 +14,7 @@ EDITABLE = {'canvasItems', 'generationSpecs', 'references', 'editorDocuments'} ABSENT = object() -UNDOABLE = {'canvas.createGeneration', 'creation.batch', 'canvas.show', 'canvas.hide', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', 'canvas.layoutPipelines', 'canvas.configure', +UNDOABLE = {'canvas.createGeneration', 'timeline.create', 'creation.batch', 'canvas.show', 'canvas.hide', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', 'canvas.layoutPipelines', 'canvas.configure', 'canvas.materialize', 'canvas.applyEdit', 'timeline.publishRender', 'canvas.publishMedia', 'canvas.applyVersion', 'canvas.exportVersion', 'canvas.attachEditor', 'canvas.detachEditor', 'generationSpec.update', 'generationSpec.restore', 'reference.add', 'reference.update', 'reference.restore', 'reference.remove', 'result.select', 'editor.save', 'generationSpec.setPrompt'} diff --git a/packages/core/src/opendirector/domain/creation/commands.py b/packages/core/src/opendirector/domain/creation/commands.py index d05e398fe..6d93aa626 100644 --- a/packages/core/src/opendirector/domain/creation/commands.py +++ b/packages/core/src/opendirector/domain/creation/commands.py @@ -12,7 +12,7 @@ from .segment_run import SegmentRunPlan from .canvas import GroupAssembly, CanvasItem from .contract_messages import contract_error, contract_text, kebab -from .editors import EditorDocument +from .editors import EditorDocument, TimelineDocument from .pipeline import PipelineCachePolicy, PipelineScope from opendirector.domain.rule_facts import PROMPT_MAX_LENGTH from .generation import GenerationSpec, Job, PromptPart, Reference @@ -276,6 +276,13 @@ class PipelineAdopt(Contract): jobId: UUID = Field(description='Succeeded candidate job ID to adopt.') +class TimelineCreate(Contract): + document: TimelineDocument = Field(description='New editable timeline document. Assign a fresh document ID.') + itemId: UUID = Field(description='Fresh canvas node ID, distinct from the document ID.') + title: str = Field(default='', max_length=255, description='User-visible canvas node title.') + position: Point = Field(default_factory=Point, description='Position on the root canvas.') + + class TimelinePublishRender(Contract): itemId: UUID = Field(description='Canvas item ID.') editorId: UUID = Field(description='Editable document ID.') @@ -523,6 +530,7 @@ def missing_versions_message(self, supplied) -> str: ('CanvasApplyEditCommand', 'canvas.applyEdit', CanvasApplyEdit, 'Apply an editor result to a canvas item.'), ('VideoTrimCommand', 'video.trim', VideoTrim, 'Trim a source canvas video using its exact asset version, then publish a new video node and its edit snapshot.'), ('CanvasPublishMediaCommand', 'canvas.publishMedia', CanvasPublishMedia, 'Publish edited media outputs with their editor snapshot.'), + ('TimelineCreateCommand', 'timeline.create', TimelineCreate, 'Create an editable timeline and its visible canvas node in one command.'), ('TimelinePublishRenderCommand', 'timeline.publishRender', TimelinePublishRender, 'Publish a rendered timeline result.'), ('PipelineStartCommand', 'pipeline.start', PipelineStart, 'Compile and start a durable concurrent Pipeline execution in the background.'), ('PipelinePauseCommand', 'pipeline.pause', PipelineControl, 'Pause an active Pipeline execution after its in-flight steps finish.'), @@ -548,7 +556,7 @@ def missing_versions_message(self, supplied) -> str: ('JobRecoverCommand', 'job.recover', JobControl, 'Recover an existing job without creating a new attempt.'), ('JobCheckpointCommand', 'job.checkpoint', JobCheckpoint, 'Persist a job execution checkpoint.'), ('ResultSelectCommand', 'result.select', ResultSelect, 'Adopt an existing generation result.'), - ('EditorCreateCommand', 'editor.create', EditorWrite, 'Create an editable document.'), + ('EditorCreateCommand', 'editor.create', EditorWrite, 'Create an editable document only. Use timeline create for a visible timeline.'), ('EditorSaveCommand', 'editor.save', EditorWrite, 'Save an editable document.'), ('HistoryUndoCommand', 'history.undo', HistoryReplay, 'Undo a recorded reversible command.'), ('HistoryRedoCommand', 'history.redo', HistoryReplay, 'Reapply an undone command.'), @@ -560,7 +568,7 @@ def missing_versions_message(self, supplied) -> str: COMMAND_MODELS[_type] = _model globals()[_name] = _model -_BATCH_TYPES = {'canvas.createGeneration', 'canvas.show', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', 'canvas.layoutPipelines', 'canvas.hide', 'canvas.materialize', 'canvas.applyEdit', +_BATCH_TYPES = {'canvas.createGeneration', 'timeline.create', 'canvas.show', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', 'canvas.layoutPipelines', 'canvas.hide', 'canvas.materialize', 'canvas.applyEdit', 'canvas.configure', 'canvas.attachEditor', 'canvas.detachEditor', 'generationSpec.create', 'generationSpec.update', 'reference.add', 'reference.update', 'reference.restore', 'reference.remove', 'editor.create', 'editor.save', 'result.select', 'generationSpec.setPrompt'} _OPERATIONS = tuple(create_model(name + 'Operation', __base__=Contract, diff --git a/packages/core/src/opendirector/infrastructure/creation_publication.py b/packages/core/src/opendirector/infrastructure/creation_publication.py index bba3ef818..0968a87f3 100644 --- a/packages/core/src/opendirector/infrastructure/creation_publication.py +++ b/packages/core/src/opendirector/infrastructure/creation_publication.py @@ -35,6 +35,8 @@ def _canvas_placements(command, snapshot): payload = operation.payload if operation.type in {'canvas.show', 'canvas.createGeneration'} and payload.positionSpace is not None: target_ids[payload.item.id] = None + elif operation.type == 'timeline.create': + target_ids[payload.itemId] = None elif operation.type == 'canvas.move': target_ids.update(dict.fromkeys(move.itemId for move in payload.items if move.positionSpace is not None)) elif operation.type == 'canvas.update' and (payload.position is not None or payload.preserveCanvasPosition): diff --git a/src/contracts/creation.schema.json b/src/contracts/creation.schema.json index 975a7fc3d..d8329e67f 100644 --- a/src/contracts/creation.schema.json +++ b/src/contracts/creation.schema.json @@ -1942,7 +1942,8 @@ "reference.remove": "#/$defs/ReferenceRemoveCommandOperation", "reference.restore": "#/$defs/ReferenceRestoreCommandOperation", "reference.update": "#/$defs/ReferenceUpdateCommandOperation", - "result.select": "#/$defs/ResultSelectCommandOperation" + "result.select": "#/$defs/ResultSelectCommandOperation", + "timeline.create": "#/$defs/TimelineCreateCommandOperation" }, "propertyName": "type" }, @@ -1974,6 +1975,9 @@ { "$ref": "#/$defs/CanvasApplyEditCommandOperation" }, + { + "$ref": "#/$defs/TimelineCreateCommandOperation" + }, { "$ref": "#/$defs/CanvasConfigureCommandOperation" }, @@ -5145,6 +5149,7 @@ "reference.restore": "#/$defs/ReferenceRestoreCommand", "reference.update": "#/$defs/ReferenceUpdateCommand", "result.select": "#/$defs/ResultSelectCommand", + "timeline.create": "#/$defs/TimelineCreateCommand", "timeline.publishRender": "#/$defs/TimelinePublishRenderCommand", "video.trim": "#/$defs/VideoTrimCommand" }, @@ -5217,6 +5222,9 @@ { "$ref": "#/$defs/CanvasPublishMediaCommand" }, + { + "$ref": "#/$defs/TimelineCreateCommand" + }, { "$ref": "#/$defs/TimelinePublishRenderCommand" }, @@ -5930,7 +5938,7 @@ }, "EditorCreateCommand": { "additionalProperties": false, - "description": "Create an editable document.", + "description": "Create an editable document only. Use timeline create for a visible timeline.", "properties": { "commandId": { "description": "Stable command ID for idempotent replay.", @@ -5975,7 +5983,7 @@ }, "payload": { "$ref": "#/$defs/EditorWrite", - "description": "Create an editable document." + "description": "Create an editable document only. Use timeline create for a visible timeline." } }, "required": [ @@ -5989,7 +5997,7 @@ }, "EditorCreateCommandOperation": { "additionalProperties": false, - "description": "Create an editable document.", + "description": "Create an editable document only. Use timeline create for a visible timeline.", "properties": { "type": { "const": "editor.create", @@ -5999,7 +6007,7 @@ }, "payload": { "$ref": "#/$defs/EditorWrite", - "description": "Create an editable document." + "description": "Create an editable document only. Use timeline create for a visible timeline." } }, "required": [ @@ -17300,6 +17308,119 @@ "title": "TimelineClip", "type": "object" }, + "TimelineCreate": { + "additionalProperties": false, + "properties": { + "document": { + "$ref": "#/$defs/TimelineDocument", + "description": "New editable timeline document. Assign a fresh document ID." + }, + "itemId": { + "description": "Fresh canvas node ID, distinct from the document ID.", + "format": "uuid", + "title": "Itemid", + "type": "string" + }, + "title": { + "default": "", + "description": "User-visible canvas node title.", + "maxLength": 255, + "title": "Title", + "type": "string" + }, + "position": { + "$ref": "#/$defs/Point", + "description": "Position on the root canvas." + } + }, + "required": [ + "document", + "itemId" + ], + "title": "TimelineCreate", + "type": "object" + }, + "TimelineCreateCommand": { + "additionalProperties": false, + "description": "Create an editable timeline and its visible canvas node in one command.", + "properties": { + "commandId": { + "description": "Stable command ID for idempotent replay.", + "format": "uuid", + "title": "Commandid", + "type": "string" + }, + "projectId": { + "description": "Owning project ID.", + "format": "uuid", + "title": "Projectid", + "type": "string" + }, + "type": { + "const": "timeline.create", + "description": "Command discriminator.", + "title": "Type", + "type": "string" + }, + "expectedVersions": { + "default": [], + "description": "Current versions of mutated existing objects; payload revision fields do not replace these.", + "items": { + "$ref": "#/$defs/ObjectVersion" + }, + "title": "Expectedversions", + "type": "array" + }, + "expectedPreview": { + "anyOf": [ + { + "pattern": "^[0-9a-f]{64}$", + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Fingerprint of the confirmed impact preview.", + "title": "Expectedpreview" + }, + "payload": { + "$ref": "#/$defs/TimelineCreate", + "description": "Create an editable timeline and its visible canvas node in one command." + } + }, + "required": [ + "commandId", + "projectId", + "type", + "payload" + ], + "title": "TimelineCreateCommand", + "type": "object" + }, + "TimelineCreateCommandOperation": { + "additionalProperties": false, + "description": "Create an editable timeline and its visible canvas node in one command.", + "properties": { + "type": { + "const": "timeline.create", + "description": "Operation discriminator.", + "title": "Type", + "type": "string" + }, + "payload": { + "$ref": "#/$defs/TimelineCreate", + "description": "Create an editable timeline and its visible canvas node in one command." + } + }, + "required": [ + "type", + "payload" + ], + "title": "TimelineCreateCommandOperation", + "type": "object" + }, "TimelineData": { "additionalProperties": false, "properties": { @@ -20010,6 +20131,7 @@ "reference.restore": "#/$defs/ReferenceRestoreCommand", "reference.update": "#/$defs/ReferenceUpdateCommand", "result.select": "#/$defs/ResultSelectCommand", + "timeline.create": "#/$defs/TimelineCreateCommand", "timeline.publishRender": "#/$defs/TimelinePublishRenderCommand", "video.trim": "#/$defs/VideoTrimCommand" }, @@ -20082,6 +20204,9 @@ { "$ref": "#/$defs/CanvasPublishMediaCommand" }, + { + "$ref": "#/$defs/TimelineCreateCommand" + }, { "$ref": "#/$defs/TimelinePublishRenderCommand" }, @@ -22363,7 +22488,8 @@ "reference.remove": "#/$defs/ReferenceRemoveCommandOperation", "reference.restore": "#/$defs/ReferenceRestoreCommandOperation", "reference.update": "#/$defs/ReferenceUpdateCommandOperation", - "result.select": "#/$defs/ResultSelectCommandOperation" + "result.select": "#/$defs/ResultSelectCommandOperation", + "timeline.create": "#/$defs/TimelineCreateCommandOperation" }, "propertyName": "type" }, @@ -22395,6 +22521,9 @@ { "$ref": "#/$defs/CanvasApplyEditCommandOperation" }, + { + "$ref": "#/$defs/TimelineCreateCommandOperation" + }, { "$ref": "#/$defs/CanvasConfigureCommandOperation" }, @@ -25637,6 +25766,7 @@ "reference.restore": "#/$defs/ReferenceRestoreCommand", "reference.update": "#/$defs/ReferenceUpdateCommand", "result.select": "#/$defs/ResultSelectCommand", + "timeline.create": "#/$defs/TimelineCreateCommand", "timeline.publishRender": "#/$defs/TimelinePublishRenderCommand", "video.trim": "#/$defs/VideoTrimCommand" }, @@ -25709,6 +25839,9 @@ { "$ref": "#/$defs/CanvasPublishMediaCommand" }, + { + "$ref": "#/$defs/TimelineCreateCommand" + }, { "$ref": "#/$defs/TimelinePublishRenderCommand" }, @@ -26450,7 +26583,7 @@ }, "EditorCreateCommand": { "additionalProperties": false, - "description": "Create an editable document.", + "description": "Create an editable document only. Use timeline create for a visible timeline.", "properties": { "commandId": { "description": "Stable command ID for idempotent replay.", @@ -26495,7 +26628,7 @@ }, "payload": { "$ref": "#/$defs/EditorWrite", - "description": "Create an editable document." + "description": "Create an editable document only. Use timeline create for a visible timeline." } }, "required": [ @@ -26511,7 +26644,7 @@ }, "EditorCreateCommandOperation": { "additionalProperties": false, - "description": "Create an editable document.", + "description": "Create an editable document only. Use timeline create for a visible timeline.", "properties": { "type": { "const": "editor.create", @@ -26521,7 +26654,7 @@ }, "payload": { "$ref": "#/$defs/EditorWrite", - "description": "Create an editable document." + "description": "Create an editable document only. Use timeline create for a visible timeline." } }, "required": [ @@ -38228,6 +38361,123 @@ "title": "TimelineClip", "type": "object" }, + "TimelineCreate": { + "additionalProperties": false, + "properties": { + "document": { + "$ref": "#/$defs/TimelineDocument", + "description": "New editable timeline document. Assign a fresh document ID." + }, + "itemId": { + "description": "Fresh canvas node ID, distinct from the document ID.", + "format": "uuid", + "title": "Itemid", + "type": "string" + }, + "title": { + "default": "", + "description": "User-visible canvas node title.", + "maxLength": 255, + "title": "Title", + "type": "string" + }, + "position": { + "$ref": "#/$defs/Point", + "description": "Position on the root canvas." + } + }, + "required": [ + "document", + "itemId", + "title", + "position" + ], + "title": "TimelineCreate", + "type": "object" + }, + "TimelineCreateCommand": { + "additionalProperties": false, + "description": "Create an editable timeline and its visible canvas node in one command.", + "properties": { + "commandId": { + "description": "Stable command ID for idempotent replay.", + "format": "uuid", + "title": "Commandid", + "type": "string" + }, + "projectId": { + "description": "Owning project ID.", + "format": "uuid", + "title": "Projectid", + "type": "string" + }, + "type": { + "const": "timeline.create", + "description": "Command discriminator.", + "title": "Type", + "type": "string" + }, + "expectedVersions": { + "default": [], + "description": "Current versions of mutated existing objects; payload revision fields do not replace these.", + "items": { + "$ref": "#/$defs/ObjectVersion" + }, + "title": "Expectedversions", + "type": "array" + }, + "expectedPreview": { + "anyOf": [ + { + "pattern": "^[0-9a-f]{64}$", + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Fingerprint of the confirmed impact preview.", + "title": "Expectedpreview" + }, + "payload": { + "$ref": "#/$defs/TimelineCreate", + "description": "Create an editable timeline and its visible canvas node in one command." + } + }, + "required": [ + "commandId", + "projectId", + "type", + "expectedVersions", + "expectedPreview", + "payload" + ], + "title": "TimelineCreateCommand", + "type": "object" + }, + "TimelineCreateCommandOperation": { + "additionalProperties": false, + "description": "Create an editable timeline and its visible canvas node in one command.", + "properties": { + "type": { + "const": "timeline.create", + "description": "Operation discriminator.", + "title": "Type", + "type": "string" + }, + "payload": { + "$ref": "#/$defs/TimelineCreate", + "description": "Create an editable timeline and its visible canvas node in one command." + } + }, + "required": [ + "type", + "payload" + ], + "title": "TimelineCreateCommandOperation", + "type": "object" + }, "TimelineData": { "additionalProperties": false, "properties": { @@ -41041,6 +41291,7 @@ "reference.restore": "#/$defs/ReferenceRestoreCommand", "reference.update": "#/$defs/ReferenceUpdateCommand", "result.select": "#/$defs/ResultSelectCommand", + "timeline.create": "#/$defs/TimelineCreateCommand", "timeline.publishRender": "#/$defs/TimelinePublishRenderCommand", "video.trim": "#/$defs/VideoTrimCommand" }, @@ -41113,6 +41364,9 @@ { "$ref": "#/$defs/CanvasPublishMediaCommand" }, + { + "$ref": "#/$defs/TimelineCreateCommand" + }, { "$ref": "#/$defs/TimelinePublishRenderCommand" }, diff --git a/src/contracts/generated.ts b/src/contracts/generated.ts index c6707b93b..540a08115 100644 --- a/src/contracts/generated.ts +++ b/src/contracts/generated.ts @@ -185,7 +185,7 @@ export interface BatchCommandInput extends CommandBaseInput { } export interface BatchPayloadInput extends ContractInput { - readonly operations: ReadonlyArray; + readonly operations: ReadonlyArray; } export interface CameraFrameInput extends ContractInput { @@ -529,7 +529,7 @@ export interface CreationContractsInput extends ContractInput { readonly generationSpec: TextGenerationSpecInput | ImageGenerationSpecInput | VideoGenerationSpecInput | AudioGenerationSpecInput; readonly reference: PinnedReferenceInput | FollowingReferenceInput; readonly editorDocument: TimelineDocumentInput | SubjectDocumentInput | LayerDocumentInput | ImageCropDocumentInput | StackDocumentInput | ToolDocumentInput | DirectorDocumentInput | MediaEditDocumentInput | MotionDocumentInput; - readonly command: ProjectCreateCommandInput | ProjectRenameCommandInput | ProjectTrashCommandInput | ProjectRestoreCommandInput | AssetImportCommandInput | ArtifactPublishCommandInput | AssetWriteTextCommandInput | AssetMetadataCommandInput | AssetDeleteCommandInput | CanvasCreateGenerationCommandInput | GroupSavePlanCommandInput | GroupPublishRunCommandInput | CanvasShowCommandInput | CanvasMoveCommandInput | CanvasUpdateCommandInput | CanvasLayoutRunsCommandInput | CanvasLayoutPipelinesCommandInput | CanvasHideCommandInput | CanvasMaterializeCommandInput | CanvasApplyEditCommandInput | VideoTrimCommandInput | CanvasPublishMediaCommandInput | TimelinePublishRenderCommandInput | PipelineStartCommandInput | PipelinePauseCommandInput | PipelineResumeCommandInput | PipelineCancelCommandInput | PipelineRetryCommandInput | PipelineAdoptCommandInput | NodeVersionApplyCommandInput | NodeVersionExportCommandInput | CanvasConfigureCommandInput | CanvasEditorAttachCommandInput | CanvasEditorDetachCommandInput | SpecCreateCommandInput | SpecUpdateCommandInput | SpecRestoreCommandInput | SpecPromptCommandInput | ReferenceAddCommandInput | ReferenceUpdateCommandInput | ReferenceRestoreCommandInput | ReferenceRemoveCommandInput | GenerationSubmitCommandInput | JobCancelCommandInput | JobRecoverCommandInput | JobCheckpointCommandInput | ResultSelectCommandInput | EditorCreateCommandInput | EditorSaveCommandInput | HistoryUndoCommandInput | HistoryRedoCommandInput | BatchCommandInput; + readonly command: ProjectCreateCommandInput | ProjectRenameCommandInput | ProjectTrashCommandInput | ProjectRestoreCommandInput | AssetImportCommandInput | ArtifactPublishCommandInput | AssetWriteTextCommandInput | AssetMetadataCommandInput | AssetDeleteCommandInput | CanvasCreateGenerationCommandInput | GroupSavePlanCommandInput | GroupPublishRunCommandInput | CanvasShowCommandInput | CanvasMoveCommandInput | CanvasUpdateCommandInput | CanvasLayoutRunsCommandInput | CanvasLayoutPipelinesCommandInput | CanvasHideCommandInput | CanvasMaterializeCommandInput | CanvasApplyEditCommandInput | VideoTrimCommandInput | CanvasPublishMediaCommandInput | TimelineCreateCommandInput | TimelinePublishRenderCommandInput | PipelineStartCommandInput | PipelinePauseCommandInput | PipelineResumeCommandInput | PipelineCancelCommandInput | PipelineRetryCommandInput | PipelineAdoptCommandInput | NodeVersionApplyCommandInput | NodeVersionExportCommandInput | CanvasConfigureCommandInput | CanvasEditorAttachCommandInput | CanvasEditorDetachCommandInput | SpecCreateCommandInput | SpecUpdateCommandInput | SpecRestoreCommandInput | SpecPromptCommandInput | ReferenceAddCommandInput | ReferenceUpdateCommandInput | ReferenceRestoreCommandInput | ReferenceRemoveCommandInput | GenerationSubmitCommandInput | JobCancelCommandInput | JobRecoverCommandInput | JobCheckpointCommandInput | ResultSelectCommandInput | EditorCreateCommandInput | EditorSaveCommandInput | HistoryUndoCommandInput | HistoryRedoCommandInput | BatchCommandInput; readonly receipt: CommandReceiptInput; readonly query: ProjectQueryInput | ObjectQueryInput | VersionsQueryInput | AssetSearchQueryInput | AssetUsageQueryInput | CanvasStatusQueryInput | JobStatusQueryInput | AssetPreviewQueryInput | ReceiptQueryInput | PipelinePlanQueryInput | PipelineExecutionQueryInput | PipelineExecutionsQueryInput; readonly event: ProjectEventInput; @@ -1761,6 +1761,23 @@ export interface TimelineClipInput extends ContractInput { readonly muted?: boolean; } +export interface TimelineCreateInput extends ContractInput { + readonly document: TimelineDocumentInput; + readonly itemId: string; + readonly title?: string; + readonly position?: PointInput; +} + +export interface TimelineCreateCommandInput extends CommandBaseInput { + readonly type: "timeline.create"; + readonly payload: TimelineCreateInput; +} + +export interface TimelineCreateCommandOperationInput { + readonly type: "timeline.create"; + readonly payload: TimelineCreateInput; +} + export interface TimelineDataInput extends ContractInput { readonly fps: number; readonly width: number; @@ -2069,7 +2086,7 @@ export type ReferenceInput = PinnedReferenceInput | FollowingReferenceInput; export type EditorDocumentInput = TimelineDocumentInput | SubjectDocumentInput | LayerDocumentInput | ImageCropDocumentInput | StackDocumentInput | ToolDocumentInput | DirectorDocumentInput | MediaEditDocumentInput | MotionDocumentInput; -export type CommandInput = ProjectCreateCommandInput | ProjectRenameCommandInput | ProjectTrashCommandInput | ProjectRestoreCommandInput | AssetImportCommandInput | ArtifactPublishCommandInput | AssetWriteTextCommandInput | AssetMetadataCommandInput | AssetDeleteCommandInput | CanvasCreateGenerationCommandInput | GroupSavePlanCommandInput | GroupPublishRunCommandInput | CanvasShowCommandInput | CanvasMoveCommandInput | CanvasUpdateCommandInput | CanvasLayoutRunsCommandInput | CanvasLayoutPipelinesCommandInput | CanvasHideCommandInput | CanvasMaterializeCommandInput | CanvasApplyEditCommandInput | VideoTrimCommandInput | CanvasPublishMediaCommandInput | TimelinePublishRenderCommandInput | PipelineStartCommandInput | PipelinePauseCommandInput | PipelineResumeCommandInput | PipelineCancelCommandInput | PipelineRetryCommandInput | PipelineAdoptCommandInput | NodeVersionApplyCommandInput | NodeVersionExportCommandInput | CanvasConfigureCommandInput | CanvasEditorAttachCommandInput | CanvasEditorDetachCommandInput | SpecCreateCommandInput | SpecUpdateCommandInput | SpecRestoreCommandInput | SpecPromptCommandInput | ReferenceAddCommandInput | ReferenceUpdateCommandInput | ReferenceRestoreCommandInput | ReferenceRemoveCommandInput | GenerationSubmitCommandInput | JobCancelCommandInput | JobRecoverCommandInput | JobCheckpointCommandInput | ResultSelectCommandInput | EditorCreateCommandInput | EditorSaveCommandInput | HistoryUndoCommandInput | HistoryRedoCommandInput | BatchCommandInput; +export type CommandInput = ProjectCreateCommandInput | ProjectRenameCommandInput | ProjectTrashCommandInput | ProjectRestoreCommandInput | AssetImportCommandInput | ArtifactPublishCommandInput | AssetWriteTextCommandInput | AssetMetadataCommandInput | AssetDeleteCommandInput | CanvasCreateGenerationCommandInput | GroupSavePlanCommandInput | GroupPublishRunCommandInput | CanvasShowCommandInput | CanvasMoveCommandInput | CanvasUpdateCommandInput | CanvasLayoutRunsCommandInput | CanvasLayoutPipelinesCommandInput | CanvasHideCommandInput | CanvasMaterializeCommandInput | CanvasApplyEditCommandInput | VideoTrimCommandInput | CanvasPublishMediaCommandInput | TimelineCreateCommandInput | TimelinePublishRenderCommandInput | PipelineStartCommandInput | PipelinePauseCommandInput | PipelineResumeCommandInput | PipelineCancelCommandInput | PipelineRetryCommandInput | PipelineAdoptCommandInput | NodeVersionApplyCommandInput | NodeVersionExportCommandInput | CanvasConfigureCommandInput | CanvasEditorAttachCommandInput | CanvasEditorDetachCommandInput | SpecCreateCommandInput | SpecUpdateCommandInput | SpecRestoreCommandInput | SpecPromptCommandInput | ReferenceAddCommandInput | ReferenceUpdateCommandInput | ReferenceRestoreCommandInput | ReferenceRemoveCommandInput | GenerationSubmitCommandInput | JobCancelCommandInput | JobRecoverCommandInput | JobCheckpointCommandInput | ResultSelectCommandInput | EditorCreateCommandInput | EditorSaveCommandInput | HistoryUndoCommandInput | HistoryRedoCommandInput | BatchCommandInput; export type ExecutionParametersInput = TextExecutionInput | ImageExecutionInput | VideoExecutionInput | AudioExecutionInput; @@ -2266,7 +2283,7 @@ export interface BatchCommand extends CommandBase { } export interface BatchPayload extends Contract { - readonly operations: ReadonlyArray; + readonly operations: ReadonlyArray; } export interface CameraFrame extends Contract { @@ -2610,7 +2627,7 @@ export interface CreationContracts extends Contract { readonly generationSpec: TextGenerationSpec | ImageGenerationSpec | VideoGenerationSpec | AudioGenerationSpec; readonly reference: PinnedReference | FollowingReference; readonly editorDocument: TimelineDocument | SubjectDocument | LayerDocument | ImageCropDocument | StackDocument | ToolDocument | DirectorDocument | MediaEditDocument | MotionDocument; - readonly command: ProjectCreateCommand | ProjectRenameCommand | ProjectTrashCommand | ProjectRestoreCommand | AssetImportCommand | ArtifactPublishCommand | AssetWriteTextCommand | AssetMetadataCommand | AssetDeleteCommand | CanvasCreateGenerationCommand | GroupSavePlanCommand | GroupPublishRunCommand | CanvasShowCommand | CanvasMoveCommand | CanvasUpdateCommand | CanvasLayoutRunsCommand | CanvasLayoutPipelinesCommand | CanvasHideCommand | CanvasMaterializeCommand | CanvasApplyEditCommand | VideoTrimCommand | CanvasPublishMediaCommand | TimelinePublishRenderCommand | PipelineStartCommand | PipelinePauseCommand | PipelineResumeCommand | PipelineCancelCommand | PipelineRetryCommand | PipelineAdoptCommand | NodeVersionApplyCommand | NodeVersionExportCommand | CanvasConfigureCommand | CanvasEditorAttachCommand | CanvasEditorDetachCommand | SpecCreateCommand | SpecUpdateCommand | SpecRestoreCommand | SpecPromptCommand | ReferenceAddCommand | ReferenceUpdateCommand | ReferenceRestoreCommand | ReferenceRemoveCommand | GenerationSubmitCommand | JobCancelCommand | JobRecoverCommand | JobCheckpointCommand | ResultSelectCommand | EditorCreateCommand | EditorSaveCommand | HistoryUndoCommand | HistoryRedoCommand | BatchCommand; + readonly command: ProjectCreateCommand | ProjectRenameCommand | ProjectTrashCommand | ProjectRestoreCommand | AssetImportCommand | ArtifactPublishCommand | AssetWriteTextCommand | AssetMetadataCommand | AssetDeleteCommand | CanvasCreateGenerationCommand | GroupSavePlanCommand | GroupPublishRunCommand | CanvasShowCommand | CanvasMoveCommand | CanvasUpdateCommand | CanvasLayoutRunsCommand | CanvasLayoutPipelinesCommand | CanvasHideCommand | CanvasMaterializeCommand | CanvasApplyEditCommand | VideoTrimCommand | CanvasPublishMediaCommand | TimelineCreateCommand | TimelinePublishRenderCommand | PipelineStartCommand | PipelinePauseCommand | PipelineResumeCommand | PipelineCancelCommand | PipelineRetryCommand | PipelineAdoptCommand | NodeVersionApplyCommand | NodeVersionExportCommand | CanvasConfigureCommand | CanvasEditorAttachCommand | CanvasEditorDetachCommand | SpecCreateCommand | SpecUpdateCommand | SpecRestoreCommand | SpecPromptCommand | ReferenceAddCommand | ReferenceUpdateCommand | ReferenceRestoreCommand | ReferenceRemoveCommand | GenerationSubmitCommand | JobCancelCommand | JobRecoverCommand | JobCheckpointCommand | ResultSelectCommand | EditorCreateCommand | EditorSaveCommand | HistoryUndoCommand | HistoryRedoCommand | BatchCommand; readonly receipt: CommandReceipt; readonly query: ProjectQuery | ObjectQuery | VersionsQuery | AssetSearchQuery | AssetUsageQuery | CanvasStatusQuery | JobStatusQuery | AssetPreviewQuery | ReceiptQuery | PipelinePlanQuery | PipelineExecutionQuery | PipelineExecutionsQuery; readonly event: ProjectEvent; @@ -3841,6 +3858,23 @@ export interface TimelineClip extends Contract { readonly muted: boolean; } +export interface TimelineCreate extends Contract { + readonly document: TimelineDocument; + readonly itemId: string; + readonly title: string; + readonly position: Point; +} + +export interface TimelineCreateCommand extends CommandBase { + readonly type: "timeline.create"; + readonly payload: TimelineCreate; +} + +export interface TimelineCreateCommandOperation { + readonly type: "timeline.create"; + readonly payload: TimelineCreate; +} + export interface TimelineData extends Contract { readonly fps: number; readonly width: number; @@ -4149,7 +4183,7 @@ export type Reference = PinnedReference | FollowingReference; export type EditorDocument = TimelineDocument | SubjectDocument | LayerDocument | ImageCropDocument | StackDocument | ToolDocument | DirectorDocument | MediaEditDocument | MotionDocument; -export type Command = ProjectCreateCommand | ProjectRenameCommand | ProjectTrashCommand | ProjectRestoreCommand | AssetImportCommand | ArtifactPublishCommand | AssetWriteTextCommand | AssetMetadataCommand | AssetDeleteCommand | CanvasCreateGenerationCommand | GroupSavePlanCommand | GroupPublishRunCommand | CanvasShowCommand | CanvasMoveCommand | CanvasUpdateCommand | CanvasLayoutRunsCommand | CanvasLayoutPipelinesCommand | CanvasHideCommand | CanvasMaterializeCommand | CanvasApplyEditCommand | VideoTrimCommand | CanvasPublishMediaCommand | TimelinePublishRenderCommand | PipelineStartCommand | PipelinePauseCommand | PipelineResumeCommand | PipelineCancelCommand | PipelineRetryCommand | PipelineAdoptCommand | NodeVersionApplyCommand | NodeVersionExportCommand | CanvasConfigureCommand | CanvasEditorAttachCommand | CanvasEditorDetachCommand | SpecCreateCommand | SpecUpdateCommand | SpecRestoreCommand | SpecPromptCommand | ReferenceAddCommand | ReferenceUpdateCommand | ReferenceRestoreCommand | ReferenceRemoveCommand | GenerationSubmitCommand | JobCancelCommand | JobRecoverCommand | JobCheckpointCommand | ResultSelectCommand | EditorCreateCommand | EditorSaveCommand | HistoryUndoCommand | HistoryRedoCommand | BatchCommand; +export type Command = ProjectCreateCommand | ProjectRenameCommand | ProjectTrashCommand | ProjectRestoreCommand | AssetImportCommand | ArtifactPublishCommand | AssetWriteTextCommand | AssetMetadataCommand | AssetDeleteCommand | CanvasCreateGenerationCommand | GroupSavePlanCommand | GroupPublishRunCommand | CanvasShowCommand | CanvasMoveCommand | CanvasUpdateCommand | CanvasLayoutRunsCommand | CanvasLayoutPipelinesCommand | CanvasHideCommand | CanvasMaterializeCommand | CanvasApplyEditCommand | VideoTrimCommand | CanvasPublishMediaCommand | TimelineCreateCommand | TimelinePublishRenderCommand | PipelineStartCommand | PipelinePauseCommand | PipelineResumeCommand | PipelineCancelCommand | PipelineRetryCommand | PipelineAdoptCommand | NodeVersionApplyCommand | NodeVersionExportCommand | CanvasConfigureCommand | CanvasEditorAttachCommand | CanvasEditorDetachCommand | SpecCreateCommand | SpecUpdateCommand | SpecRestoreCommand | SpecPromptCommand | ReferenceAddCommand | ReferenceUpdateCommand | ReferenceRestoreCommand | ReferenceRemoveCommand | GenerationSubmitCommand | JobCancelCommand | JobRecoverCommand | JobCheckpointCommand | ResultSelectCommand | EditorCreateCommand | EditorSaveCommand | HistoryUndoCommand | HistoryRedoCommand | BatchCommand; export type ExecutionParameters = TextExecution | ImageExecution | VideoExecution | AudioExecution; diff --git a/tests/browser/timeline_workflow.mjs b/tests/browser/timeline_workflow.mjs index 92c8d8857..a3888f77c 100644 --- a/tests/browser/timeline_workflow.mjs +++ b/tests/browser/timeline_workflow.mjs @@ -145,53 +145,36 @@ try { "applied", ); await call(`/api/creation/projects/${pid}/open`, {}); - assert.equal( - ( - await command(pid, "creation.batch", { - operations: [ - { - type: "editor.create", - payload: { - document: { - id: editorId, - projectId: pid, - kind: "timeline", - data: { - fps: 20, - width: 128, - height: 96, - tracks: [ - { - id: "visual", - kind: "visual", - title: "Visual", - clips: [], - }, - ], - }, - }, - }, - }, - { - type: "canvas.show", - payload: { - item: { - id: itemId, - projectId: pid, - kind: "timeline", - title: "Timeline acceptance", - position: { x: 150, y: 150 }, - binding: { - role: "editor", - objectRef: { id: editorId, kind: "timeline" }, - }, - }, - }, - }, - ], - }) - ).status, - "applied", + const timelineInput = { + itemId, + title: "Timeline acceptance", + position: { x: 150, y: 150 }, + document: { + id: editorId, + projectId: pid, + kind: "timeline", + data: { + fps: 20, + width: 128, + height: 96, + tracks: [{ id: "visual", kind: "visual", title: "Visual", clips: [] }], + }, + }, + }; + const createdTimeline = JSON.parse(execFileSync(pythonExecutable(), [ + "-m", "opendirector.cli", "--url", api, "--project", pid, "--session", seedSession, + "timeline", "create", "--file", "-", + ], { + input: JSON.stringify({ payload: timelineInput }), + encoding: "utf8", + env: { ...process.env, PYTHONPATH: sourcePythonPath(), OPENDIRECTOR_AGENT_SOCKET: "", OPENDIRECTOR_AGENT_HOST: "" }, + timeout: 30000, + windowsHide: true, + })); + assert.equal(createdTimeline.status, "applied"); + assert.deepEqual( + new Map(createdTimeline.changed.map(({ objectType, id }) => [objectType, id])), + new Map([["canvas_item", itemId], ["editor_document", editorId]]), ); const released = await fetch(api + `/api/creation/sessions/${seedSession}`, { method: "DELETE", diff --git a/tests/test_cli.py b/tests/test_cli.py index 4f05e7447..9e00f0c89 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -806,6 +806,16 @@ def test_capabilities_names_commands_that_have_no_command_model(help_color): assert "--action" in detailed["video blockout-task"]["options"] +def test_agent_cli_discovers_one_command_for_a_visible_timeline(help_color): + result = CliRunner().invoke(cli.app, ["capabilities", "--compact"]) + assert result.exit_code == 0, result.output + commands = {entry["command"]: entry for entry in json.loads(result.output)["commands"]} + assert "timeline create" in commands, "Agent CLI needs a command that creates a timeline on the canvas" + assert commands["timeline create"]["type"] == "timeline.create" + assert set(commands["timeline create"]["required"]) == {"document", "itemId"} + assert "timeline create" in commands["editor create"]["summary"] + + @pytest.mark.parametrize("live", [False, True], ids=["http", "agent"]) def test_revision_scoped_object_queries_use_head_snapshot_before_shared_records(tmp_path, monkeypatch, live): import asyncio diff --git a/tests/test_creation_assembly.py b/tests/test_creation_assembly.py index c87fe3a86..3eea5a5cf 100644 --- a/tests/test_creation_assembly.py +++ b/tests/test_creation_assembly.py @@ -6,12 +6,17 @@ import wave from PIL import Image +from pydantic import TypeAdapter import pytest +from opendirector.agent.context import RunContext +from opendirector.agent.gateway import ToolGateway +from opendirector.agent.tools import AgentTools from opendirector.application.creation_assets import CreationAssets from opendirector.application.creation_canvas import DOWNSTREAM, asset_ref, resolved_inputs from opendirector.infrastructure.creation_projects import CreationProjects from opendirector.infrastructure.local_projects import LocalProjects +from opendirector.infrastructure.model_configs import ModelConfigs from test_creation_canvas_service import project, media, send, ver @@ -69,6 +74,65 @@ def editor(project, kind, asset, source, **changes): inputConnections=[dict(id=uuid4(), sourceId=source.id, slotId=slot, asset=asset_ref(asset))], **changes) +@pytest.mark.anyio +@pytest.mark.parametrize('with_clip', [False, True], ids=['empty', 'image-clip']) +async def test_agent_creates_visible_timeline_and_replays_after_reopen(project, tmp_path, with_clip): + store, pid, session = project + document = dict(id=uuid4(), projectId=pid, kind='timeline', data=dict(fps=30, width=1920, height=1080, + tracks=[dict(id='visual', kind='visual', title='Visual', clips=[])])) + if with_clip: + source, asset = upload_source(project, tmp_path, 'image') + document = editor(project, 'timeline', asset, source) + item_id = uuid4() + request = dict(type='timeline.create', payload=dict(document=document, itemId=item_id, + title='Editable timeline', position=dict(x=180, y=240))) + arguments = TypeAdapter(dict).dump_python(request, mode='json') + run = RunContext(runtime='codex', project_id=pid, turn_id=uuid4(), session=session, directory=tmp_path, + config=None, messages=[], selected_skills=[]) + gateway = ToolGateway(AgentTools(store, None, ModelConfigs(tmp_path)), run) + try: + help_result = await gateway.call('help', 'command_schema', {'type': 'timeline.create'}) + assert help_result.error is None, help_result.value + result = await gateway.call('create-timeline', 'execute_command', arguments) + assert result.error is None, result.value + assert result.value['status'] == 'applied' + assert {(obj['objectType'], obj['id']) for obj in result.value['changed']} == { + ('editor_document', str(document['id'])), ('canvas_item', str(item_id)), + } + finally: + await gateway.close() + + reopened = CreationProjects(LocalProjects(store.local.repository)) + before_retry = reopened.snapshot(pid) + saved, = before_retry.editorDocuments + item, = (item for item in before_retry.canvasItems if item.kind == 'timeline') + assert (item.id, item.title, item.position.x, item.position.y) == (item_id, 'Editable timeline', 180, 240) + assert item.visible and item.binding.objectRef.id == saved.id == document['id'] + assert len(saved.data.tracks[0].clips) == int(with_clip) + if with_clip: + assert saved.data.tracks[0].clips[0].resource.asset.assetId == asset.id + assert saved.inputConnections[0].sourceId == source.id + assert not before_retry.jobs + gateway = ToolGateway(AgentTools(reopened, None, ModelConfigs(tmp_path)), run) + try: + replay = await gateway.call('create-timeline', 'execute_command', arguments) + assert replay.value == result.value + finally: + await gateway.close() + assert reopened.snapshot(pid) == before_retry + + +def test_timeline_create_rolls_back_when_the_canvas_identity_is_already_used(project, tmp_path): + store, pid, session = project + source, asset = upload_source(project, tmp_path, 'image') + document = editor(project, 'timeline', asset, source) + before = store.snapshot(pid) + receipt = send(store, pid, 'timeline.create', session=session, document=document, itemId=source.id) + assert receipt.status == 'rejected' + assert not receipt.changed and not receipt.jobIds + assert CreationProjects(LocalProjects(store.local.repository)).snapshot(pid) == before + + @pytest.mark.parametrize(('source_kind', 'target_kind'), [ ('image', 'subject'), ('video', 'subject'), ('image', 'timeline'), ('video', 'timeline'), ('audio', 'timeline'),