Skip to content
Open
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
11 changes: 10 additions & 1 deletion apps/api/src/opendirector_api/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@

from opendirector.domain.timeline_errors import timeline_error_message
from opendirector.domain.url_import import url_import_message
from opendirector.domain.creation.contract_messages import contract_message

from opendirector.domain.creation.commands import CommandReceipt
from opendirector.domain.capabilities import Capability
from opendirector.domain.capability_messages import english_capability_message, missing_tool_model_message

from opendirector.domain.creation.assets import ASSET_DOWNLOAD_ENGLISH

_DRAFT_DISCARD_MESSAGES = (
'Replacing a configured draft requires explicit discard (discardGenerationDraft).',
'替换已配置的草稿需要明确丢弃(discardGenerationDraft)。',
)

ENGLISH_BY_CODE = {
**ASSET_DOWNLOAD_ENGLISH,
'keyframe_unsupported': 'This model or mode does not support keyframes. Clear the keyframe times or choose another model.',
Expand Down Expand Up @@ -199,9 +205,12 @@ def localized_error_for_language(
code: str = "operation_rejected",
required_capability: Capability | None = None,
) -> str:
specific = timeline_error_message(code, language) or url_import_message(code, language, chinese)
specific = (timeline_error_message(code, language) or url_import_message(code, language, chinese)
or contract_message(code, language, chinese))
if specific is not None:
return specific
if chinese in _DRAFT_DISCARD_MESSAGES:
return _DRAFT_DISCARD_MESSAGES[0 if wants_english_language(language) else 1]
if not wants_english_language(language):
return chinese
if code == 'tool_model_missing':
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/opendirector/application/creation_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from opendirector.domain.creation.models import ModelConfigPublic
from opendirector.domain.creation.project import ProjectSnapshot, asset_references
from opendirector.domain.creation.index import object_index
from opendirector.domain.creation.contract_messages import version_required_message
from opendirector.domain.creation.validation import ContractError
from opendirector.domain.input_rules import input_rules
from opendirector.domain.rule_facts import FRAME_IMAGE_LIMIT
Expand Down Expand Up @@ -399,8 +400,12 @@ def _apply_edit(self, data, payload, before, command):
raise ContractError('invalid_input', '裁剪参数与输出尺寸不一致。', doc.id)

expected = {(v.objectType, v.id): v.revision for v in command.expectedVersions}
if old_doc and expected.get(('editor_document', doc.id)) != old_doc.revision:
raise ContractError('revision_conflict', '应用编辑需要编辑文档版本。', doc.id)
if old_doc:
key = ('editor_document', doc.id)
if key not in expected:
raise ContractError('version_required', version_required_message([key]), doc.id)
if expected[key] != old_doc.revision:
raise ContractError('revision_conflict', 'Object changed; reread before modifying', doc.id)
output = self.assets._reference(snapshot, payload.asset)
if output.kind != 'image' or output.id == current.id:
raise ContractError('invalid_input', '编辑输出必须是独立图片素材。', output.id)
Expand Down Expand Up @@ -496,7 +501,8 @@ def _publish_render(self, data, payload):
existing = next((i for i in snapshot.canvasItems if i.id == payload.outputId), None)
if existing is not None:
if payload.expectedOutputRevision is None:
raise ContractError('revision_conflict', '输出节点已存在,请提供其当前版本。', payload.outputId)
key = ('canvas_item', payload.outputId)
raise ContractError('version_required', version_required_message([key]), payload.outputId)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里真正缺的是 payload.expectedOutputRevision。通用文案却让调用方往 expectedVersions 里补,CLI 也提示 --expected-version;只照这个提示重试还是会进同一分支。建议给 timeline 单独的双语恢复提示,明确 payload 字段和对应 CLI 入参,再加一个按提示重试就能成功的用例。

target = self._editable(data, payload.outputId)
previous = current_asset(snapshot, existing)
if (existing.kind != 'video' or existing.binding.role != 'material' or previous is None
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/opendirector/domain/creation/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,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', 'revision_conflict', 'version_required', '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',
Expand All @@ -561,7 +561,7 @@ def command_fingerprint(command: Command) -> str:

class ContractIssue(Contract):
code: IssueCode = Field(description='Stable error or issue code.')
message: str = Field(min_length=1, max_length=500, description='Human-readable issue description.')
message: str = Field(min_length=1, max_length=2000, 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import re
from uuid import UUID

CONTRACT_MESSAGES = {
'version_required': (
'expectedVersions 缺少本命令修改对象的当前版本。请读取每个对象的当前版本(query object.get --object-id ID),'
'并一次全部提供:expectedVersions += [{entries}];CLI:{options}',
'expectedVersions missing current versions for objects this command changes. '
'Read each current revision (query object.get --object-id ID) and send all of them: '
'expectedVersions += [{entries}]; CLI: {options}',
),
}


def _pattern(template: str) -> re.Pattern:
parts = re.split(r'\{(\w+)\}', template)
return re.compile(''.join(re.escape(part) if index % 2 == 0 else f'(?P<{part}>.*?)'
for index, part in enumerate(parts)), re.DOTALL)


_PATTERNS = {code: _pattern(texts[1]) for code, texts in CONTRACT_MESSAGES.items()}


def contract_text(code: str, **fields: object) -> str:
return CONTRACT_MESSAGES[code][1].format(**fields)


def contract_message(code: str | None, language: str | None, message: str) -> str | None:
pattern = _PATTERNS.get(code or '')
match = pattern.fullmatch(message) if pattern else None
if match is None:
return None
primary = (language or '').strip().split(',', 1)[0].split(';', 1)[0].strip().lower()
if primary and not primary.startswith('zh'):
return message
return CONTRACT_MESSAGES[code][0].format(**match.groupdict())


def version_required_message(
missing: list[tuple[str, UUID]],
known: dict[tuple[str, UUID], int] | None = None,
) -> str:
entries, options = [], []
for kind, identity in dict.fromkeys(missing):
revision = (known or {}).get((kind, identity))
entries.append(f'{{"objectType":"{kind}","id":"{identity}","revision":{revision or "REVISION"}}}')
options.append(f'--expected-version {kind}:{identity}:{revision or "REVISION"}')
return contract_text('version_required', entries=', '.join(entries), options=' '.join(options))
22 changes: 17 additions & 5 deletions packages/core/src/opendirector/domain/creation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .canvas import GroupCanvasItem, MediaCanvasItem, role_after
from .commands import Command, ContractIssue, IssueCode
from .contract_messages import version_required_message
from .project import ProjectSnapshot


Expand Down Expand Up @@ -72,8 +73,17 @@ def get(kind, object_id):
if item.binding.role == 'empty' and item.binding.draftSpec:
spec = get('generation_spec', item.binding.draftSpec.id)
if spec.prompt or spec.modelConfigId or spec.promptContent:
if not payload.discardGenerationDraft or expected.get(('generation_spec', spec.id)) != spec.revision:
raise ContractError('revision_conflict', 'Replacing configured draft requires explicit discard and its version', spec.id)
key = ('generation_spec', spec.id)
if key not in expected:
raise ContractError('version_required', version_required_message([key]), spec.id)
if expected[key] != spec.revision:
raise ContractError('revision_conflict', 'Object changed; reread before modifying', spec.id)
if not payload.discardGenerationDraft:
raise ContractError(
'invalid_input',
'Replacing a configured draft requires explicit discard (discardGenerationDraft).',
spec.id,
)
else:
if item.kind == 'file':
raise ContractError('role_restricted', 'File nodes cannot generate', item_id)
Expand All @@ -88,9 +98,11 @@ def get(kind, object_id):
raise ContractError('role_restricted', 'Configuration edits cannot change purpose, kind or result selection', current.id)
if command.type == 'reference.add':
spec = get('generation_spec', payload.reference.targetSpecId)
if any(isinstance(item, MediaCanvasItem) and item.binding.role == 'empty' and item.binding.draftSpec
and item.binding.draftSpec.id == spec.id and ('canvas_item', item.id) not in expected for item in project.canvasItems):
raise ContractError('revision_conflict', 'Locking an empty node requires its current version', spec.id)
missing = [('canvas_item', item.id) for item in project.canvasItems
if isinstance(item, MediaCanvasItem) and item.binding.role == 'empty' and item.binding.draftSpec
and item.binding.draftSpec.id == spec.id and ('canvas_item', item.id) not in expected]
if missing:
raise ContractError('version_required', version_required_message(missing), missing[0][1])
if command.type in {'job.cancel', 'job.recover'}:
get('job', payload.jobId)
if command.type == 'result.select':
Expand Down
6 changes: 4 additions & 2 deletions src/contracts/creation.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4466,6 +4466,7 @@
"timeline_bundled_font_unavailable",
"invalid_input",
"revision_conflict",
"version_required",
"role_restricted",
"canvas_run_layout_group",
"canvas_run_layout_conflict",
Expand Down Expand Up @@ -4563,7 +4564,7 @@
},
"message": {
"description": "Human-readable issue description.",
"maxLength": 500,
"maxLength": 2000,
"minLength": 1,
"title": "Message",
"type": "string"
Expand Down Expand Up @@ -23169,6 +23170,7 @@
"timeline_bundled_font_unavailable",
"invalid_input",
"revision_conflict",
"version_required",
"role_restricted",
"canvas_run_layout_group",
"canvas_run_layout_conflict",
Expand Down Expand Up @@ -23266,7 +23268,7 @@
},
"message": {
"description": "Human-readable issue description.",
"maxLength": 500,
"maxLength": 2000,
"minLength": 1,
"title": "Message",
"type": "string"
Expand Down
Loading
Loading