From 933adff5cdf6e758d56324abd252c7e7ed98c47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E5=BF=97=E9=B9=8F?= Date: Tue, 1 Dec 2026 11:01:05 +0000 Subject: [PATCH] [bugfix] canvas: name a material node after its asset when no title is given ## summary - `canvas add-material` placed every node with an empty title, so in the timeline media library several clips showed only a type icon and could not be told apart. The browser names a placed asset after its file. - The CLI now sends the asset name as the title, with `--title` to set another one. - `canvas.show` fills in the asset name for a new material item whose request leaves the title out, so the agent's command path and other API callers get the same result. An explicit title, including an empty one, is kept. ## validation - New tests: the service defaults, keeps and blanks a title as asked; the CLI writes the asset name and honours `--title`. Both fail without the change. Co-Authored-By: Claude Opus 5.5 --- docs/guides/cli.md | 2 +- .../application/creation_canvas.py | 11 +++++++---- packages/core/src/opendirector/cli.py | 5 +++-- tests/test_cli.py | 4 ++++ tests/test_creation_canvas_service.py | 19 +++++++++++++++++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/docs/guides/cli.md b/docs/guides/cli.md index b91586561..d0b4de813 100644 --- a/docs/guides/cli.md +++ b/docs/guides/cli.md @@ -26,7 +26,7 @@ opendirector --project PROJECT_UUID video create --model MODEL_CONFIG_UUID - opendirector --project PROJECT_UUID video create --model MODEL_CONFIG_UUID --prompt "人物起舞" --duration 5 --reference-item COSTUME_ITEM_UUID --keyframe POSE_ITEM_UUID@1.25 ``` -`canvas add-material` 和 `video create` 通过必填的 `--x`、`--y` 明确创建位置。Agent 先读取画布对象的位置、尺寸及分组,再安排新元素布局。`video create` 创建可编辑的生成节点与参考关系,返回 `specId` 和 `itemId`。所有画布修改命令以及批量事务通过共用返回层提供 `canvasItems`,包含元素身份、版本、位置、尺寸、父级、坐标系及可见性。位置未变化的操作也返回目标元素的几何信息,供后续布局判断。几何信息读取失败时,回执保留已提交状态并返回 `geometryReadError`。模型可通过配置 UUID 或唯一匹配的完整模型名指定。重名配置返回候选 UUID 和端点,由调用者明确选择。模型的输入模式必须支持所选参数。`--reference-item` 支持重复指定参考节点。`--keyframe ITEM_UUID@秒数` 把一张图片节点固定到成片的该时间点,可重复指定;它只用于参考模式,需要模型的 `inputRules.maxKeyframes` 不为空,并且至少同时有一个 `--reference-item`。提交生成时使用创建回执中的对象版本,后台任务由服务端继续执行。 +`canvas add-material` 和 `video create` 通过必填的 `--x`、`--y` 明确创建位置。`canvas add-material` 新建的节点默认以素材文件名为标题,在画布和时间线素材库中显示;可用 `--title` 另行指定。Agent 先读取画布对象的位置、尺寸及分组,再安排新元素布局。`video create` 创建可编辑的生成节点与参考关系,返回 `specId` 和 `itemId`。所有画布修改命令以及批量事务通过共用返回层提供 `canvasItems`,包含元素身份、版本、位置、尺寸、父级、坐标系及可见性。位置未变化的操作也返回目标元素的几何信息,供后续布局判断。几何信息读取失败时,回执保留已提交状态并返回 `geometryReadError`。模型可通过配置 UUID 或唯一匹配的完整模型名指定。重名配置返回候选 UUID 和端点,由调用者明确选择。模型的输入模式必须支持所选参数。`--reference-item` 支持重复指定参考节点。`--keyframe ITEM_UUID@秒数` 把一张图片节点固定到成片的该时间点,可重复指定;它只用于参考模式,需要模型的 `inputRules.maxKeyframes` 不为空,并且至少同时有一个 `--reference-item`。提交生成时使用创建回执中的对象版本,后台任务由服务端继续执行。 ### 画布坐标与分组 / Canvas coordinates and groups diff --git a/packages/core/src/opendirector/application/creation_canvas.py b/packages/core/src/opendirector/application/creation_canvas.py index 98f2bdb40..844c5cfa3 100644 --- a/packages/core/src/opendirector/application/creation_canvas.py +++ b/packages/core/src/opendirector/application/creation_canvas.py @@ -572,11 +572,14 @@ def _mutate(self, data, kind, payload): parent['visible'] = True parent_id = parent['parentId'] else: - if obj['binding']['role'] == 'material' and not ({'width', 'height'} & payload.item.model_fields_set): + if obj['binding']['role'] == 'material': asset = self._get(data, 'asset', obj['binding']['objectRef']['assetId']) - metadata = asset.get('metadata') or {} - obj['width'], obj['height'] = media_card_size(obj['kind'], metadata.get('width'), - metadata.get('height'), obj['width'], obj['height']) + if not ({'width', 'height'} & payload.item.model_fields_set): + metadata = asset.get('metadata') or {} + obj['width'], obj['height'] = media_card_size(obj['kind'], metadata.get('width'), + metadata.get('height'), obj['width'], obj['height']) + if 'title' not in payload.item.model_fields_set: + obj['title'] = asset['name'][:255] obj['visible'] = True data['canvasItems'].append(obj) elif kind == 'canvas.move': diff --git a/packages/core/src/opendirector/cli.py b/packages/core/src/opendirector/cli.py index a3a497ef6..097a36715 100644 --- a/packages/core/src/opendirector/cli.py +++ b/packages/core/src/opendirector/cli.py @@ -562,7 +562,8 @@ def optimize_prompt(ctx: typer.Context, def add_material(ctx: typer.Context, asset: Annotated[UUID, typer.Option(help="Registered project asset ID.")], x: Annotated[float, typer.Option(help="Canvas X coordinate. Choose using the current item positions and sizes.")], y: Annotated[float, typer.Option(help="Canvas Y coordinate. Choose using the current item positions and sizes.")], - item_id: Annotated[UUID | None, typer.Option(help="New canvas item UUID.")] = None): + item_id: Annotated[UUID | None, typer.Option(help="New canvas item UUID.")] = None, + title: Annotated[str | None, typer.Option(help="Node title shown on the canvas and in the timeline media library; defaults to the asset name.")] = None): client = ctx.obj client.command = ctx.command_path snapshot = client.snapshot() @@ -573,7 +574,7 @@ def add_material(ctx: typer.Context, asset: Annotated[UUID, typer.Option(help="R reference["assetId"] = source["id"] emit(client.execute("canvas.show", {"item": { "id": str(item_id or client.operation_id or uuid4()), "projectId": snapshot["project"]["id"], - "kind": source["kind"], "position": {"x": x, "y": y}, + "kind": source["kind"], "title": (source["name"] if title is None else title)[:255], "position": {"x": x, "y": y}, "binding": {"role": "material", "objectRef": reference}, }})) diff --git a/tests/test_cli.py b/tests/test_cli.py index 0181f7aaa..fd61a01db 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -158,6 +158,10 @@ def invoke(arguments): assert shown["canvasItems"][0]["width"] == 352 item = invoke(["project", "show"])["canvasItems"][0] assert item["binding"]["objectRef"]["assetId"] == asset["id"] + assert item["title"] == "plan.txt" + named = invoke(["canvas", "add-material", "--asset", asset["id"], "--x", "20", "--y", "400", "--title", "Plan B"]) + assert next(value for value in invoke(["project", "show"])["canvasItems"] + if value["id"] == named["canvasItems"][0]["id"])["title"] == "Plan B" file = tmp_path / "upload.txt" file.write_text("Imported text") diff --git a/tests/test_creation_canvas_service.py b/tests/test_creation_canvas_service.py index e3b281db4..7e28ccb92 100644 --- a/tests/test_creation_canvas_service.py +++ b/tests/test_creation_canvas_service.py @@ -116,6 +116,25 @@ def checking(stream, asset): assert canvas.projection(pid)['edges'][0]['state'] == 'unavailable' +def test_a_material_item_shown_without_a_title_is_named_after_its_asset(project): + store, project_id, session = project + assert send(store, project_id, 'asset.writeText', session=session, name='opening-shot.md', text='Dawn').status == 'applied' + asset = store.snapshot(project_id).assets[-1] + untitled, titled, blank = uuid4(), uuid4(), uuid4() + receipt = send(store, project_id, 'creation.batch', session=session, operations=[ + dict(type='canvas.show', payload=dict(item=dict(id=untitled, projectId=project_id, kind='text', + binding=dict(role='material', objectRef=asset_ref(asset))))), + dict(type='canvas.show', payload=dict(item=dict(id=titled, projectId=project_id, kind='text', title='Opening', + binding=dict(role='material', objectRef=asset_ref(asset))))), + dict(type='canvas.show', payload=dict(item=dict(id=blank, projectId=project_id, kind='text', title='', + binding=dict(role='material', objectRef=asset_ref(asset)))))]) + assert receipt.status == 'applied', receipt + titles = {item.id: item.title for item in store.snapshot(project_id).canvasItems} + assert titles[untitled] == 'opening-shot.md' + assert titles[titled] == 'Opening' + assert titles[blank] == '' + + def test_blank_rejected_and_batch_rolls_back_all_earlier_operations(project): store, pid, session = project source, _ = media(project)