Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/opendirector/application/creation_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/opendirector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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},
}}))

Expand Down
4 changes: 4 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_creation_canvas_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading