diff --git a/apps/api/src/opendirector_api/localization.py b/apps/api/src/opendirector_api/localization.py index fd3d72d25..edee8dd0d 100644 --- a/apps/api/src/opendirector_api/localization.py +++ b/apps/api/src/opendirector_api/localization.py @@ -16,6 +16,7 @@ from opendirector.domain.capability_messages import english_capability_message, missing_tool_model_message ENGLISH_BY_CODE = { + "canvas_position_space_required": "Specify canvas or parent positionSpace when creating an item inside a group.", 'keyframe_unsupported': 'This model or mode does not support keyframes. Clear the keyframe times or choose another model.', 'keyframe_mode': 'Keyframes work in Universal reference mode only, not with first/last frames, continuation or structure control.', 'keyframe_kind': 'A keyframe must be an image.', diff --git a/docs/guides/cli.md b/docs/guides/cli.md index ff46af94c..2ac1a29f7 100644 --- a/docs/guides/cli.md +++ b/docs/guides/cli.md @@ -30,11 +30,11 @@ opendirector --project PROJECT_UUID video create --model MODEL_CONFIG_UUID - ### 画布坐标与分组 / Canvas coordinates and groups -`canvas.show` 和 `canvas.createGeneration` 接受 `positionSpace: "canvas"`,`canvas.move` 可在每个 `items` 条目中指定它。服务端会减去所有祖先分组的偏移。省略该字段或传 `"parent"` 时,继续使用组内坐标。顶层节点的两种坐标相同。在 `creation batch` 中,使用画布坐标的子节点应排在其父组之后。例如父组在 `(1600, 620)`,子节点用 `"canvas"` 提交 `(1650, 700)`,保存的组内坐标为 `(50, 80)`。 +`canvas.show` 和 `canvas.createGeneration` 接受 `positionSpace: "canvas"`,`canvas.move` 可在每个 `items` 条目中指定它。服务端会减去所有祖先分组的偏移。传 `"parent"` 时使用组内坐标。新建分组子节点必须显式指定坐标空间。顶层节点的两种坐标相同。在 `creation batch` 中,使用画布坐标的子节点应排在其父组之后。例如父组在 `(1600, 620)`,子节点用 `"canvas"` 提交 `(1650, 700)`,保存的组内坐标为 `(50, 80)`。 换组时,用 `canvas.update` 同时提交 `parentId` 和 `preserveCanvasPosition: true`。传 `parentId: null` 可移到顶层。如果需要同时移动节点,则提交 `parentId`、`position` 和所需的 `positionSpace`。显式放置操作的回执通过 `canvasPlacements` 返回父组、保存坐标和最终画布坐标。启用 Run 或 Pipeline 自动布局时,最终位置仍由自动布局决定。 -Set `positionSpace: "canvas"` on `canvas.show` or `canvas.createGeneration`, or on individual `items` entries in `canvas.move`. The server subtracts the offsets of every ancestor group. Omit the field or pass `"parent"` to use parent-relative coordinates. Both spaces match at the canvas root. In `creation batch`, place a group before any child that uses canvas coordinates. For example, canvas position `(1650, 700)` inside a group at `(1600, 620)` is stored as `(50, 80)`. +Set `positionSpace: "canvas"` on `canvas.show` or `canvas.createGeneration`, or on individual `items` entries in `canvas.move`. The server subtracts the offsets of every ancestor group. Pass `"parent"` to use parent-relative coordinates. Creating a new child item in a group requires an explicit coordinate space. Both spaces match at the canvas root. In `creation batch`, place a group before any child that uses canvas coordinates. For example, canvas position `(1650, 700)` inside a group at `(1600, 620)` is stored as `(50, 80)`. To reparent a node in place, send `parentId` and `preserveCanvasPosition: true` in the same `canvas.update`. Use `parentId: null` to move it to the root. To reparent and move the node together, send `parentId`, `position` and the desired `positionSpace`. Explicit placement receipts report the parent, stored position and final canvas position in `canvasPlacements`. Run or Pipeline auto-layout still controls final positions where enabled. diff --git a/feature-assets/canvas-position-space/command-receipts.json b/feature-assets/canvas-position-space/command-receipts.json new file mode 100644 index 000000000..832480ff3 --- /dev/null +++ b/feature-assets/canvas-position-space/command-receipts.json @@ -0,0 +1,21 @@ +{ + "ambiguous": "canvas_position_space_required", + "items": [ + { + "title": "Parent position (50,50)", + "position": { + "x": 50, + "y": 50 + } + }, + { + "title": "Canvas position (830,350)", + "position": { + "x": 430, + "y": 50 + } + } + ], + "relative": "applied", + "absolute": "applied" +} diff --git a/feature-assets/canvas-position-space/create-and-reopen.mp4 b/feature-assets/canvas-position-space/create-and-reopen.mp4 new file mode 100644 index 000000000..27b06226a Binary files /dev/null and b/feature-assets/canvas-position-space/create-and-reopen.mp4 differ diff --git a/feature-assets/canvas-position-space/reopened-canvas.jpg b/feature-assets/canvas-position-space/reopened-canvas.jpg new file mode 100644 index 000000000..7c16835c3 Binary files /dev/null and b/feature-assets/canvas-position-space/reopened-canvas.jpg differ diff --git a/packages/core/src/opendirector/application/creation_canvas.py b/packages/core/src/opendirector/application/creation_canvas.py index 844c5cfa3..8488bd964 100644 --- a/packages/core/src/opendirector/application/creation_canvas.py +++ b/packages/core/src/opendirector/application/creation_canvas.py @@ -551,11 +551,15 @@ def _mutate(self, data, kind, payload): 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) - if payload.positionSpace == 'canvas' and obj['parentId'] is not None: - if not old: - self._editable(data, obj['parentId']) - lookup = self._placement_lookup({item['id']: item for item in data['canvasItems']}) - obj['position'] = self._relative_position(payload.item.position, obj['parentId'], lookup, obj['id']) + if obj['parentId'] is not None: + if old is None and payload.positionSpace is None: + raise ContractError('canvas_position_space_required', + '新建分组子节点时,请显式指定 positionSpace 为 canvas 或 parent。', payload.item.id) + if payload.positionSpace == 'canvas': + if old is None: + self._editable(data, obj['parentId']) + lookup = self._placement_lookup({item['id']: item for item in data['canvasItems']}) + obj['position'] = self._relative_position(payload.item.position, obj['parentId'], lookup, obj['id']) if old: # Restoring an existing identity cannot replace its binding or # overwrite newer presentation data supplied by another client. diff --git a/packages/core/src/opendirector/domain/creation/commands.py b/packages/core/src/opendirector/domain/creation/commands.py index b1ccad39a..b2169e409 100644 --- a/packages/core/src/opendirector/domain/creation/commands.py +++ b/packages/core/src/opendirector/domain/creation/commands.py @@ -103,7 +103,7 @@ class GroupPlanDraft(Contract): class CanvasPlacement(Contract): positionSpace: PositionSpace | None = Field(default=None, exclude_if=lambda value: value is None, - description='Use parent-relative coordinates by default, or canvas for absolute coordinates.') + description='Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.') class CanvasShow(CanvasPlacement): @@ -505,7 +505,7 @@ def command_fingerprint(command: Command) -> str: from opendirector.domain.timeline_errors import TimelineIssueCode -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', +IssueCode = Literal[TimelineIssueCode, 'invalid_input', 'canvas_position_space_required', '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', 'keyframe_unsupported', 'keyframe_mode', 'keyframe_kind', 'keyframe_count', 'keyframe_needs_reference', 'keyframe_time', 'keyframe_image', 'bigmodel_video_model', 'bigmodel_video_output', 'bigmodel_video_image', 'bigmodel_video_frames', 'bigmodel_video_prompt', 'bigmodel_video_cancel', diff --git a/src/backend/creationProjection.ts b/src/backend/creationProjection.ts index fdf3602f8..1487d9836 100644 --- a/src/backend/creationProjection.ts +++ b/src/backend/creationProjection.ts @@ -1689,6 +1689,7 @@ export class CreationProjection { const show: CreationOperation = { type: "canvas.show", payload: { + ...(node.parentId ? { positionSpace: "parent" } : {}), item: { id: node.id, projectId: this.client.id, diff --git a/src/contracts/creation.schema.json b/src/contracts/creation.schema.json index b975150e4..545ca7bab 100644 --- a/src/contracts/creation.schema.json +++ b/src/contracts/creation.schema.json @@ -1953,7 +1953,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "spec": { @@ -2983,7 +2983,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "itemId": { @@ -3021,7 +3021,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" } }, @@ -3085,7 +3085,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "itemId": { @@ -3433,7 +3433,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "item": { @@ -4353,6 +4353,7 @@ "timeline_bundled_font_fingerprint", "timeline_bundled_font_unavailable", "invalid_input", + "canvas_position_space_required", "revision_conflict", "role_restricted", "canvas_run_layout_group", @@ -20362,7 +20363,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "spec": { @@ -21420,7 +21421,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "itemId": { @@ -21458,7 +21459,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" } }, @@ -21522,7 +21523,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "itemId": { @@ -21880,7 +21881,7 @@ } ], "default": null, - "description": "Use parent-relative coordinates by default, or canvas for absolute coordinates.", + "description": "Use canvas for absolute coordinates or parent for group-relative coordinates. An explicit choice is required when creating a child item in a group.", "title": "Positionspace" }, "item": { @@ -22825,6 +22826,7 @@ "timeline_bundled_font_fingerprint", "timeline_bundled_font_unavailable", "invalid_input", + "canvas_position_space_required", "revision_conflict", "role_restricted", "canvas_run_layout_group", diff --git a/src/contracts/generated.ts b/src/contracts/generated.ts index 8d19e286b..e6bc8087d 100644 --- a/src/contracts/generated.ts +++ b/src/contracts/generated.ts @@ -483,7 +483,7 @@ export interface ContractInput { } export interface ContractIssueInput extends ContractInput { - readonly code: "timeline_package_invalid" | "timeline_package_too_large" | "timeline_revision_missing" | "timeline_import_missing" | "timeline_import_conflict" | "timeline_registration_rejected" | "timeline_font_too_large" | "timeline_font_unavailable" | "timeline_font_unsupported" | "timeline_font_invalid" | "timeline_font_fingerprint" | "timeline_font_coverage" | "timeline_font_total_bytes" | "timeline_font_unverified" | "timeline_font_mime" | "timeline_bundled_font_fingerprint" | "timeline_bundled_font_unavailable" | "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" | "keyframe_unsupported" | "keyframe_mode" | "keyframe_kind" | "keyframe_count" | "keyframe_needs_reference" | "keyframe_time" | "keyframe_image" | "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" | "higgsfield_model" | "higgsfield_key" | "higgsfield_output" | "higgsfield_parameters" | "higgsfield_mode" | "higgsfield_image" | "higgsfield_format" | "higgsfield_media_size" | "higgsfield_duration" | "higgsfield_reference_count" | "higgsfield_reference_changed" | "higgsfield_frames" | "higgsfield_references" | "higgsfield_prompt" | "capability_unavailable" | "capability_paused" | "capability_connection_changed" | "capability_unsupported" | "preview_expired" | "storage_unavailable" | "submission_unknown" | "provider_error" | "moss_speech_text" | "moss_speech_voice" | "moss_speech_reference" | "moss_prompt_limit" | "moss_image_size" | "moss_image_reference" | "moss_layout_reference" | "bigmodel_image_size" | "bigmodel_image_reference" | "bigmodel_image_prompt" | "minimax_image_reference" | "minimax_image_count" | "minimax_image_bytes" | "minimax_speech_text" | "minimax_speech_voice" | "minimax_speech_reference" | "minimax_speech_model" | "zhipu_speech_text" | "zhipu_speech_voice" | "zhipu_speech_reference" | "voice_library_unsupported" | "voice_connection_changed" | "voice_reference_required" | "voice_transcript_required" | "voice_transcript_too_long" | "voice_description_too_long" | "voice_not_found" | "voice_delete_unsupported" | "voice_consent_required" | "voice_name_invalid" | "voice_audio_invalid" | "voice_format" | "voice_size" | "voice_duration" | "voice_provider_protocol" | "voice_provider_error" | "voice_provider_timeout" | "voice_model_unsupported" | "voice_name_taken" | "voice_provider_quota"; + readonly code: "timeline_package_invalid" | "timeline_package_too_large" | "timeline_revision_missing" | "timeline_import_missing" | "timeline_import_conflict" | "timeline_registration_rejected" | "timeline_font_too_large" | "timeline_font_unavailable" | "timeline_font_unsupported" | "timeline_font_invalid" | "timeline_font_fingerprint" | "timeline_font_coverage" | "timeline_font_total_bytes" | "timeline_font_unverified" | "timeline_font_mime" | "timeline_bundled_font_fingerprint" | "timeline_bundled_font_unavailable" | "invalid_input" | "canvas_position_space_required" | "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" | "keyframe_unsupported" | "keyframe_mode" | "keyframe_kind" | "keyframe_count" | "keyframe_needs_reference" | "keyframe_time" | "keyframe_image" | "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" | "higgsfield_model" | "higgsfield_key" | "higgsfield_output" | "higgsfield_parameters" | "higgsfield_mode" | "higgsfield_image" | "higgsfield_format" | "higgsfield_media_size" | "higgsfield_duration" | "higgsfield_reference_count" | "higgsfield_reference_changed" | "higgsfield_frames" | "higgsfield_references" | "higgsfield_prompt" | "capability_unavailable" | "capability_paused" | "capability_connection_changed" | "capability_unsupported" | "preview_expired" | "storage_unavailable" | "submission_unknown" | "provider_error" | "moss_speech_text" | "moss_speech_voice" | "moss_speech_reference" | "moss_prompt_limit" | "moss_image_size" | "moss_image_reference" | "moss_layout_reference" | "bigmodel_image_size" | "bigmodel_image_reference" | "bigmodel_image_prompt" | "minimax_image_reference" | "minimax_image_count" | "minimax_image_bytes" | "minimax_speech_text" | "minimax_speech_voice" | "minimax_speech_reference" | "minimax_speech_model" | "zhipu_speech_text" | "zhipu_speech_voice" | "zhipu_speech_reference" | "voice_library_unsupported" | "voice_connection_changed" | "voice_reference_required" | "voice_transcript_required" | "voice_transcript_too_long" | "voice_description_too_long" | "voice_not_found" | "voice_delete_unsupported" | "voice_consent_required" | "voice_name_invalid" | "voice_audio_invalid" | "voice_format" | "voice_size" | "voice_duration" | "voice_provider_protocol" | "voice_provider_error" | "voice_provider_timeout" | "voice_model_unsupported" | "voice_name_taken" | "voice_provider_quota"; readonly message: string; readonly objectId?: string | null; readonly field?: string | null; @@ -2379,7 +2379,7 @@ export interface Contract { } export interface ContractIssue extends Contract { - readonly code: "timeline_package_invalid" | "timeline_package_too_large" | "timeline_revision_missing" | "timeline_import_missing" | "timeline_import_conflict" | "timeline_registration_rejected" | "timeline_font_too_large" | "timeline_font_unavailable" | "timeline_font_unsupported" | "timeline_font_invalid" | "timeline_font_fingerprint" | "timeline_font_coverage" | "timeline_font_total_bytes" | "timeline_font_unverified" | "timeline_font_mime" | "timeline_bundled_font_fingerprint" | "timeline_bundled_font_unavailable" | "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" | "keyframe_unsupported" | "keyframe_mode" | "keyframe_kind" | "keyframe_count" | "keyframe_needs_reference" | "keyframe_time" | "keyframe_image" | "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" | "higgsfield_model" | "higgsfield_key" | "higgsfield_output" | "higgsfield_parameters" | "higgsfield_mode" | "higgsfield_image" | "higgsfield_format" | "higgsfield_media_size" | "higgsfield_duration" | "higgsfield_reference_count" | "higgsfield_reference_changed" | "higgsfield_frames" | "higgsfield_references" | "higgsfield_prompt" | "capability_unavailable" | "capability_paused" | "capability_connection_changed" | "capability_unsupported" | "preview_expired" | "storage_unavailable" | "submission_unknown" | "provider_error" | "moss_speech_text" | "moss_speech_voice" | "moss_speech_reference" | "moss_prompt_limit" | "moss_image_size" | "moss_image_reference" | "moss_layout_reference" | "bigmodel_image_size" | "bigmodel_image_reference" | "bigmodel_image_prompt" | "minimax_image_reference" | "minimax_image_count" | "minimax_image_bytes" | "minimax_speech_text" | "minimax_speech_voice" | "minimax_speech_reference" | "minimax_speech_model" | "zhipu_speech_text" | "zhipu_speech_voice" | "zhipu_speech_reference" | "voice_library_unsupported" | "voice_connection_changed" | "voice_reference_required" | "voice_transcript_required" | "voice_transcript_too_long" | "voice_description_too_long" | "voice_not_found" | "voice_delete_unsupported" | "voice_consent_required" | "voice_name_invalid" | "voice_audio_invalid" | "voice_format" | "voice_size" | "voice_duration" | "voice_provider_protocol" | "voice_provider_error" | "voice_provider_timeout" | "voice_model_unsupported" | "voice_name_taken" | "voice_provider_quota"; + readonly code: "timeline_package_invalid" | "timeline_package_too_large" | "timeline_revision_missing" | "timeline_import_missing" | "timeline_import_conflict" | "timeline_registration_rejected" | "timeline_font_too_large" | "timeline_font_unavailable" | "timeline_font_unsupported" | "timeline_font_invalid" | "timeline_font_fingerprint" | "timeline_font_coverage" | "timeline_font_total_bytes" | "timeline_font_unverified" | "timeline_font_mime" | "timeline_bundled_font_fingerprint" | "timeline_bundled_font_unavailable" | "invalid_input" | "canvas_position_space_required" | "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" | "keyframe_unsupported" | "keyframe_mode" | "keyframe_kind" | "keyframe_count" | "keyframe_needs_reference" | "keyframe_time" | "keyframe_image" | "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" | "higgsfield_model" | "higgsfield_key" | "higgsfield_output" | "higgsfield_parameters" | "higgsfield_mode" | "higgsfield_image" | "higgsfield_format" | "higgsfield_media_size" | "higgsfield_duration" | "higgsfield_reference_count" | "higgsfield_reference_changed" | "higgsfield_frames" | "higgsfield_references" | "higgsfield_prompt" | "capability_unavailable" | "capability_paused" | "capability_connection_changed" | "capability_unsupported" | "preview_expired" | "storage_unavailable" | "submission_unknown" | "provider_error" | "moss_speech_text" | "moss_speech_voice" | "moss_speech_reference" | "moss_prompt_limit" | "moss_image_size" | "moss_image_reference" | "moss_layout_reference" | "bigmodel_image_size" | "bigmodel_image_reference" | "bigmodel_image_prompt" | "minimax_image_reference" | "minimax_image_count" | "minimax_image_bytes" | "minimax_speech_text" | "minimax_speech_voice" | "minimax_speech_reference" | "minimax_speech_model" | "zhipu_speech_text" | "zhipu_speech_voice" | "zhipu_speech_reference" | "voice_library_unsupported" | "voice_connection_changed" | "voice_reference_required" | "voice_transcript_required" | "voice_transcript_too_long" | "voice_description_too_long" | "voice_not_found" | "voice_delete_unsupported" | "voice_consent_required" | "voice_name_invalid" | "voice_audio_invalid" | "voice_format" | "voice_size" | "voice_duration" | "voice_provider_protocol" | "voice_provider_error" | "voice_provider_timeout" | "voice_model_unsupported" | "voice_name_taken" | "voice_provider_quota"; readonly message: string; readonly objectId: string | null; readonly field: string | null; diff --git a/tests/test_creation_api.py b/tests/test_creation_api.py index f0833fb01..2879dfde7 100644 --- a/tests/test_creation_api.py +++ b/tests/test_creation_api.py @@ -364,7 +364,10 @@ def _show_layout_item(project_id, kind, **item): item.setdefault('binding', dict(role='empty')) defaults = dict(id=str(uuid4()), projectId=project_id, kind=kind, position=dict(x=0, y=0), width=900, height=160) - return dict(type='canvas.show', payload=dict(item=defaults | item)) + payload = dict(item=defaults | item) + if item.get('parentId') is not None: + payload['positionSpace'] = 'parent' + return dict(type='canvas.show', payload=payload) def _layout_item_id(operation): diff --git a/tests/test_creation_canvas_service.py b/tests/test_creation_canvas_service.py index 7e28ccb92..01c0a38f8 100644 --- a/tests/test_creation_canvas_service.py +++ b/tests/test_creation_canvas_service.py @@ -663,7 +663,7 @@ def show(item_id, x, y, *, parent=None, space=None): show(parent_id, 1600, 620), show(nested_id, 1620, 650, parent=parent_id, space='canvas'), show(child_id, 1650, 700, parent=nested_id, space='canvas'), - show(legacy_id, 24, 40, parent=parent_id), + show(legacy_id, 24, 40, parent=parent_id, space='parent'), dict(type='canvas.createGeneration', payload=dict(positionSpace='canvas', spec=dict(id=spec_id, projectId=pid, kind='image', purpose='generation'), item=dict(id=generation_id, projectId=pid, kind='image', parentId=parent_id, position=dict(x=1650, y=700), @@ -716,7 +716,7 @@ def test_canvas_placement_rejects_entire_batch(project, fault): root_id, child_id, unrelated_id = uuid4(), uuid4(), uuid4() assert send(store, pid, 'creation.batch', session=session, operations=[ dict(type='canvas.show', payload=dict(item=dict(id=root_id, projectId=pid, kind='group'))), - dict(type='canvas.show', payload=dict(item=dict(id=child_id, projectId=pid, kind='group', + dict(type='canvas.show', payload=dict(positionSpace='parent', item=dict(id=child_id, projectId=pid, kind='group', parentId=root_id, locked=fault in {'locked_parent', 'locked_reparent'}))), ]).status == 'applied' before = store.snapshot(pid) @@ -741,3 +741,40 @@ def test_canvas_placement_rejects_entire_batch(project, fault): }[fault] assert not receipt.canvasPlacements assert store.snapshot(pid) == before + + +def test_group_creation_rejects_unlabeled_canvas_coordinates(project): + store, pid, session = project + group_id, child_id = uuid4(), uuid4() + parent = dict(id=group_id, projectId=pid, kind='group', position=dict(x=200, y=620), + width=1900, height=520) + child = dict(id=child_id, projectId=pid, kind='group', parentId=group_id, + position=dict(x=560, y=665)) + + def submit(space=None): + payload = dict(item=child) + if space: + payload['positionSpace'] = space + command = parse_command(dict(commandId=uuid4(), projectId=pid, type='creation.batch', + payload=dict(operations=[ + dict(type='canvas.show', payload=dict(item=parent)), + dict(type='canvas.show', payload=payload), + ]))) + return store.execute(command, session=session, source='agent') + + rejected = submit() + assert rejected.status == 'rejected' + assert rejected.issues[0].code == 'canvas_position_space_required' + assert store.snapshot(pid).canvasItems == () + original_position = child['position'] + child['position'] = dict(x=24, y=45) + inside = submit() + assert inside.status == 'rejected' + assert inside.issues[0].code == 'canvas_position_space_required' + assert store.snapshot(pid).canvasItems == () + child['position'] = original_position + applied = submit('canvas') + assert applied.status == 'applied' + placed, = applied.canvasPlacements + assert placed.position.model_dump() == dict(x=360, y=45) + assert placed.canvasPosition.model_dump() == dict(x=560, y=665) diff --git a/tests/test_creation_history_service.py b/tests/test_creation_history_service.py index e8005b82e..67b137be7 100644 --- a/tests/test_creation_history_service.py +++ b/tests/test_creation_history_service.py @@ -23,7 +23,7 @@ def test_timeline_text_history_rechecks_all_current_owner_locks(project, tmp_pat assert send(store, pid, 'creation.batch', session=session, operations=[ dict(type='editor.create', payload=dict(document=document)), dict(type='canvas.show', payload=dict(item=dict(id=parent_id, projectId=pid, kind='group'))), - *[dict(type='canvas.show', payload=dict(item=dict(id=item_id, projectId=pid, kind='timeline', parentId=parent_id, + *[dict(type='canvas.show', payload=dict(positionSpace='parent', item=dict(id=item_id, projectId=pid, kind='timeline', parentId=parent_id, binding=dict(role='editor', objectRef=dict(id=document['id'], kind='timeline'))))) for item_id in [owner_id, second_id]], ]).status == 'applied' doc = store.snapshot(pid).editorDocuments[0]