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
4 changes: 4 additions & 0 deletions apps/api/src/opendirector_api/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
"preview_expired": "The preview expired. Generate it again.",
"reference_invalid": "A reference is no longer valid. Select it again and retry.",
"role_restricted": "This item does not allow that operation.",
"canvas_run_layout_extent": "Canvas positions or dimensions are too large to arrange. Resize the affected items.",
"canvas_run_layout_group": "Run layout is only available for top-level groups.",
"canvas_run_layout_conflict": "Locked Run areas overlap. Unlock one of the groups and try again.",
"canvas_run_layout_shared_object": "Two Runs use the same editable object. Copy the configuration or editor document and try again.",
"storage_unavailable": "A stored file is missing or has changed. Restore the file and try again.",
"capability_unsupported": "This capability is not supported yet.",
"model_list_http_error": "Could not load the model list from the service.",
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ opendirector --project PROJECT_UUID video create --model MODEL_CONFIG_UUID -

`canvas add-material` 和 `video create` 通过必填的 `--x`、`--y` 明确创建位置。Agent 先读取画布对象的位置、尺寸及分组,再安排新元素布局。`video create` 创建可编辑的生成节点与参考关系,返回 `specId` 和 `itemId`。所有画布修改命令以及批量事务通过共用返回层提供 `canvasItems`,包含元素身份、版本、位置、尺寸、父级、坐标系及可见性。位置未变化的操作也返回目标元素的几何信息,供后续布局判断。几何信息读取失败时,回执保留已提交状态并返回 `geometryReadError`。模型可通过配置 UUID 或唯一匹配的完整模型名指定。重名配置返回候选 UUID 和端点,由调用者明确选择。模型的输入模式必须支持所选参数。`--reference-item` 支持重复指定参考节点。提交生成时使用创建回执中的对象版本,后台任务由服务端继续执行。

### Run 自动布局 / Run auto-layout

在画布中右键顶层分组,选择「加入 Run 自动布局」。通过 CLI 或 Agent 新建 Run 时,在 `canvas.show` 的 group 对象设置 `autoLayout: "run"`,并将本轮的计划、片段和时间线节点的 `parentId` 设为该分组 ID。同批新增或改变尺寸的节点会在保存时统一排布。各轮以稳定顺序换行,锁定的 Run 和普通顶层节点作为固定占位。不同 Run 可复用已登记素材,各自保存生成配置和编辑文档。要重新整理,右键画布空白处选择「整理 Run」,或运行 `opendirector canvas layout-runs`。通过 `canvas update --item-id ID --auto-layout free --expected-version canvas_item:ID:REV` 恢复手动布局。

On the canvas, right-click a top-level group and select **Include in Run layout**. From the CLI or Agent, set `autoLayout: "run"` on the group in `canvas.show`, then set `parentId` on its plan, clip, and timeline nodes to that group ID. New and resized nodes are arranged in the same save. Runs wrap in a stable order around locked Runs and ordinary top-level nodes. Runs can reuse registered assets, and each Run owns its own generation configurations and editor documents. To arrange Runs explicitly, right-click the canvas background or run `opendirector canvas layout-runs`. Use `canvas update --item-id ID --auto-layout free --expected-version canvas_item:ID:REV` to return a group to manual layout.

```bash
opendirector --project PROJECT_UUID generation submit --spec-id SPEC_UUID --expected-spec-revision 1 --origin-item-id ITEM_UUID --expected-version generation_spec:SPEC_UUID:1 --expected-version canvas_item:ITEM_UUID:1
opendirector --project PROJECT_UUID job show JOB_UUID
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/opendirector/application/creation_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,12 @@ def _mutate(self, data, kind, payload):
if (ref and str(ref.get('id')) == str(obj['id'])) or attached:
self._editable(data, item['id'])
old.update(obj)
elif kind == 'canvas.layoutRuns':
pass # The commit arranges the authoritative canvas after validating edits.
elif kind == 'canvas.show':
obj = payload.item.model_dump(mode='json')
if obj.get('autoLayout') == 'run' and obj['parentId'] is not None:
raise ContractError('canvas_run_layout_group', '自动排列只适用于顶层分组。', payload.item.id)
if str(obj['projectId']) != str(data['project']['id']):
raise ContractError('invalid_input', '节点不属于当前工程。')
old = next((o for o in data['canvasItems'] if o['id'] == obj['id']), None)
Expand Down Expand Up @@ -556,7 +560,16 @@ def _mutate(self, data, kind, payload):
self._editable(data, move.itemId)['position'] = move.position.model_dump()
elif kind == 'canvas.update':
item = self._editable(data, payload.itemId, unlocking=value.get('locked') is False)
layout = value.pop('autoLayout', None)
if layout is not None and item['kind'] != 'group':
raise ContractError('canvas_run_layout_group', '自动排列只适用于顶层分组。', payload.itemId)
if layout == 'run':
item['autoLayout'] = 'run'
elif layout == 'free':
item.pop('autoLayout', None)
item.update({key: val for key, val in value.items() if key != 'itemId' and (val is not None or key == 'parentId')})
if item.get('autoLayout') == 'run' and item['parentId'] is not None:
raise ContractError('canvas_run_layout_group', '自动排列只适用于顶层分组。', payload.itemId)
if item.get('color') == '':
item.pop('color')
elif kind == 'canvas.hide':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.configure',
UNDOABLE = {'canvas.createGeneration', 'creation.batch', 'canvas.show', 'canvas.hide', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', 'canvas.configure',
'canvas.materialize', 'canvas.applyEdit', 'timeline.publishRender', 'canvas.publishMedia', 'canvas.applyVersion', 'canvas.attachEditor', 'canvas.detachEditor', 'generationSpec.update', 'generationSpec.restore',
'reference.add', 'reference.update', 'reference.restore', 'reference.remove', 'result.select', 'editor.save', 'generationSpec.setPrompt'}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/opendirector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def execute(self, kind, payload, versions=(), preview=None, *, identity=None):
value["canvasItems"].append({
**{field: item[field] for field in
("id", "kind", "revision", "parentId", "position", "width", "height", "visible")},
**({"autoLayout": item["autoLayout"]} if item.get("autoLayout") else {}),
"coordinateSpace": "canvas" if item["parentId"] is None else "parent",
})
except (ProjectError, OSError, httpx.HTTPError) as error:
Expand Down Expand Up @@ -395,6 +396,7 @@ def summarize(snapshot):
for asset in snapshot.get("assets", ())],
"canvasItems": [{"id": item["id"], "revision": item["revision"], "kind": item.get("kind"),
"title": item.get("title"), "visible": item.get("visible", True),
**({"autoLayout": item["autoLayout"]} if item.get("autoLayout") else {}),
"binding": {"role": item["binding"]["role"],
"objectRef": item["binding"].get("objectRef", {}).get("id") or
item["binding"].get("objectRef", {}).get("assetId")} }
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/opendirector/domain/creation/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class DirectorCanvasItem(EditorCanvasItem):

class GroupCanvasItem(CanvasItemBase):
kind: Literal['group'] = Field(description='Business object or media type.')
autoLayout: Literal['run'] | None = Field(default=None, exclude_if=lambda value: value is None,
description='Set to run to opt this top-level group into shared Run layout. Put its plan, clips and timeline under this group ID.')
binding: ContainerBinding = Field(default_factory=lambda: ContainerBinding(role='container'), description='Business object displayed by this canvas item.')


Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/opendirector/domain/creation/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class CanvasPresentationUpdate(Contract):
color: CanvasColor | None = Field(default=None, exclude_if=lambda value: value is None, description="Group background color in #RRGGBB format, or '' for the default.")
parentId: UUID | None = Field(default=None, description='Parent canvas group ID, or null for the root.')
# Presence of parentId distinguishes retaining a group from ungrouping.
autoLayout: Literal['run', 'free'] | None = Field(default=None, exclude_if=lambda value: value is None,
description='Enable Run layout for a top-level group, or use free to return it to manual layout.')


class CanvasHide(Contract):
Expand Down Expand Up @@ -339,6 +341,7 @@ def required_versions(self) -> list[tuple[str, UUID]]:
('CanvasShowCommand', 'canvas.show', CanvasShow, 'Create or restore a canvas display item.'),
('CanvasMoveCommand', 'canvas.move', CanvasMove, 'Move one or more canvas items.'),
('CanvasUpdateCommand', 'canvas.update', CanvasPresentationUpdate, 'Update canvas presentation, grouping or lock state.'),
('CanvasLayoutRunsCommand', 'canvas.layoutRuns', EmptyPayload, 'Arrange the current canvas Run groups and their children without moving locked groups.'),
('CanvasHideCommand', 'canvas.hide', CanvasHide, 'Remove a canvas item; preserves project contents. Remove all visible items to clear the canvas.'),
('CanvasMaterializeCommand', 'canvas.materialize', CanvasMaterialize, 'Bind an asset to an empty or material canvas item.'),
('CanvasApplyEditCommand', 'canvas.applyEdit', CanvasApplyEdit, 'Apply an editor result to a canvas item.'),
Expand Down Expand Up @@ -373,7 +376,7 @@ def required_versions(self) -> list[tuple[str, UUID]]:
COMMAND_MODELS[_type] = _model
globals()[_name] = _model

_BATCH_TYPES = {'canvas.show', 'canvas.move', 'canvas.update', 'canvas.hide', 'canvas.materialize', 'canvas.applyEdit',
_BATCH_TYPES = {'canvas.show', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', '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,
Expand Down Expand Up @@ -407,7 +410,7 @@ def command_fingerprint(command: Command) -> str:

from opendirector.domain.timeline_errors import TimelineIssueCode

IssueCode = Literal[TimelineIssueCode, 'invalid_input', 'revision_conflict', 'role_restricted', 'missing_object', 'reference_invalid', 'image_quality_unsupported',
IssueCode = Literal[TimelineIssueCode, 'invalid_input', 'revision_conflict', 'role_restricted', 'canvas_run_layout_group', 'canvas_run_layout_conflict', 'canvas_run_layout_extent', 'canvas_run_layout_shared_object', 'missing_object', 'reference_invalid', 'image_quality_unsupported',
'bigmodel_video_model', 'bigmodel_video_output', 'bigmodel_video_image',
'bigmodel_video_frames', 'bigmodel_video_prompt', 'bigmodel_video_cancel',
'kling_model', 'kling_mode', 'kling_image', 'kling_frames', 'kling_prompt', 'kling_aspect', 'kling_output', 'kling_cancel',
Expand All @@ -432,6 +435,8 @@ class ContractIssue(Contract):
message: str = Field(min_length=1, max_length=500, description='Human-readable issue description.')
objectId: UUID | None = Field(default=None, description='Target business object ID.')
field: str | None = Field(default=None, max_length=200, description='Path of the field responsible for this issue.')
relatedObjectId: UUID | None = Field(default=None, exclude_if=lambda value: value is None,
description='Other business object involved in the issue.')


class CommandReceipt(Contract):
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/opendirector/domain/creation/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def project_relations(self):
parents = {}
for item in self.canvasItems:
if item.parentId:
if item.kind == 'group' and item.autoLayout == 'run':
raise ValueError('Run layout requires a top-level group')
if item.parentId not in items or items[item.parentId].kind != 'group':
raise ValueError('Parent must be a group in the same project')
parents[item.id] = [item.parentId]
Expand Down
Loading
Loading