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
15 changes: 14 additions & 1 deletion apps/api/src/opendirector_api/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ async def execute(project_id: UUID, value: Command, request: Request, x_opendire
imported_from = x_canvas_import if x_canvas_import in {'generated', 'edited'} else None
if x_canvas_import is not None and imported_from is None:
raise ProjectError('归档来源必须是 generated 或 edited。', 400)
if value.type in {'generation.submit', 'job.cancel', 'job.recover'}:
if value.type in {'generation.submit', 'job.cancel', 'job.recover',
'pipeline.start', 'pipeline.pause', 'pipeline.resume',
'pipeline.cancel', 'pipeline.retry', 'pipeline.adopt'}:
if generation is None:
raise ProjectError('任务服务不可用。', 503)
receipt = await generation.execute(value, session=session)
Expand Down Expand Up @@ -228,6 +230,17 @@ def projection(project_id: UUID):
async def query(project_id: UUID, value: CreationQuery):
if value.projectId != project_id:
raise ProjectError('查询不属于当前工程。')
if value.type in {'pipeline.plan', 'pipeline.execution.get', 'pipeline.executions.list'}:
executor = getattr(generation, 'pipelines', None)
if executor is None:
raise ProjectError('流水线执行服务不可用。', 503, code='pipeline_unavailable')
if value.type == 'pipeline.plan':
return await executor.plan(
project_id, value.scope, cache_policy=value.cachePolicy, force_from_item_id=value.forceFromItemId,
)
if value.type == 'pipeline.executions.list':
return {'executions': await executor.history(project_id, value.groupId)}
return await executor.status(project_id, value.objectId)
result = await canvas.query(value)
if value.type == 'asset.preview' and 'preview' in result:
result['preview'].pop('path')
Expand Down
5 changes: 5 additions & 0 deletions apps/api/src/opendirector_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from opendirector.domain.creation.validation import ContractError
from opendirector.domain.settings import GeneralSettings, GeneralSettingsPatch
from opendirector.application.creation_generation import CreationGeneration
from opendirector.application.creation_pipeline import PipelineExecutor
from opendirector.application.model_catalog import ModelCatalog
from opendirector.application.model_availability import ModelAvailability
from opendirector.application.preferences import Preferences
Expand Down Expand Up @@ -61,6 +62,8 @@ def create_app(store: LocalProjects | None = None, chat_provider=None, generatio
creation_projects = CreationProjects(store)
availability = ModelAvailability(model_configs, capability_probe)
creation_generation = CreationGeneration(creation_projects, model_configs, generation_provider, availability=availability)
pipelines = PipelineExecutor(creation_projects, creation_generation, model_configs)
creation_generation.pipelines = pipelines
creation_tools = ToolTasks(store, model_configs, CreationToolAssets(creation_projects), projects=creation_projects, availability=availability)
catalog = ModelCatalog(model_configs, chat_provider or ChatCompletions(), availability)

Expand All @@ -71,13 +74,15 @@ async def lifespan(app):
await creation_generation.start()
try:
await creation_tools.start()
await pipelines.start()
yield
finally:
agents = [entry.task for entry in list(active_agents.values()) if entry.task is not None]
for agent in agents:
agent.cancel()
await asyncio.gather(*agents, return_exceptions=True)
try:
await pipelines.close()
await creation_tools.close()
finally:
await creation_generation.close()
Expand Down
6 changes: 6 additions & 0 deletions docs/development/lessons.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,9 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u
- **Trigger:** Reusing one editor component inside a settings dialog and inside a first-run page.
- **Lesson:** The model service editor renders under both `.cw-settings-dialog` and the first-run `.cw-welcome` setup step. Every shared control rule was written as a descendant of the dialog, so the second host silently fell back to bare browser controls: buttons lost border, padding and radius, inputs lost their height, and the `--settings-*` metrics declared on the dialog were undefined. The markup was correct in both hosts, which is why text and click assertions passed while the layout was unusable.
- **Check:** Hang shared styles off the component's own root and use `:is(hostA, hostB)` only where a rule must still win from the host. Declare the component's design tokens and inherited `font` on that root too; a `var()` whose declaration lives on one host does not fail loudly, it resolves to the inherited or initial value. Compare computed styles and geometry of the same controls under both hosts before and after the change, on a freshly started dev server; a stale module graph can serve the previous CSS and make an unchanged reading look like proof.

## Tool schemas distinguish query envelopes from nested inputs

- **Trigger:** Adding a nested input model to an Agent query.
- **Lesson:** [PR #565](https://github.com/ThinkFlowLab/OpenDirector/pull/565) added Pipeline scopes to the query schema. Removing host-provided IDs from every definition raised `KeyError: 'queryId'` on a scope definition and prevented Agent turns from starting.
- **Check:** Project host-owned fields out of the root query branches. Verify that the exposed tool schema preserves nested discriminators and required fields, and that an Agent turn can initialize its tool gateway.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions packages/core/src/opendirector/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def tools() -> list[dict]:
'additionalProperties': False}))
query_schema = TypeAdapter(Query).json_schema()
query_schema['type'] = 'object'
for definition in query_schema['$defs'].values():
for branch in query_schema['oneOf']:
name = branch['$ref'].removeprefix('#/$defs/')
definition = query_schema['$defs'][name]
for field in ('queryId', 'projectId'):
definition['properties'].pop(field)
definition['required'].remove(field)
Expand Down Expand Up @@ -389,6 +391,17 @@ def recording():
# A rejected query must name the accepted types rather than echo a
# tag list the model has to reinterpret.
raise ProjectError(query_guidance(failure)) from None
if query.type in {'pipeline.plan', 'pipeline.execution.get', 'pipeline.executions.list'}:
executor = getattr(self.generation, 'pipelines', None)
if executor is None:
raise ProjectError('流水线执行服务不可用。', 503, code='pipeline_unavailable')
if query.type == 'pipeline.plan':
return await executor.plan(
project_id, query.scope, cache_policy=query.cachePolicy, force_from_item_id=query.forceFromItemId,
)
if query.type == 'pipeline.executions.list':
return {'executions': await executor.history(project_id, query.groupId)}
return await executor.status(project_id, query.objectId)
result = await CreationCanvas(self.projects).query(query)
if query.type == 'asset.preview' and 'preview' in result:
with self.projects.local.transaction() as db:
Expand Down Expand Up @@ -470,7 +483,8 @@ def narrow(value: JsonValue) -> None:
raise ProjectError('批量命令包含未开放的 Agent 操作。', 403)
if command.type == 'generation.submit':
receipt = await self.generation.execute(command, session=session, source='agent', agent_origin=(turn_id, call_id))
elif command.type in {'job.cancel', 'job.recover'}:
elif command.type in {'job.cancel', 'job.recover', 'pipeline.start', 'pipeline.pause',
'pipeline.resume', 'pipeline.cancel', 'pipeline.retry', 'pipeline.adopt'}:
receipt = await self.generation.execute(command, session=session, source='agent')
elif command.type in {'asset.writeText', 'artifact.publish'}:
if config is not None:
Expand Down
20 changes: 13 additions & 7 deletions packages/core/src/opendirector/application/creation_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,11 @@ 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':
elif kind in {'canvas.layoutRuns', 'canvas.layoutPipelines'}:
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:
if obj.get('autoLayout') in {'run', 'pipeline'} 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', '节点不属于当前工程。')
Expand Down Expand Up @@ -563,12 +563,12 @@ def _mutate(self, data, kind, payload):
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'
if layout in {'run', 'pipeline'}:
item['autoLayout'] = layout
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:
if item.get('autoLayout') in {'run', 'pipeline'} and item['parentId'] is not None:
raise ContractError('canvas_run_layout_group', '自动排列只适用于顶层分组。', payload.itemId)
if item.get('color') == '':
item.pop('color')
Expand Down Expand Up @@ -680,8 +680,14 @@ def _mutate(self, data, kind, payload):
allowed = downstream_kinds(snapshot, source_item) if source_item else DOWNSTREAM.get(source_kind, set())
if spec['kind'] not in allowed:
raise ContractError('reference_invalid', '该节点类型不能作为目标节点的参考。', payload.reference.id)
for value in resolve_reference(snapshot, payload.reference):
self._available(next(asset for asset in snapshot.assets if asset.id == value.asset.assetId))
pending_generation = (
ref['binding'] == 'follow_current' and source_item is not None
and source_item.binding.role == 'generation'
and current_asset(snapshot, source_item) is None
)
if not pending_generation:
for value in resolve_reference(snapshot, payload.reference):
self._available(next(asset for asset in snapshot.assets if asset.id == value.asset.assetId))
elif kind == 'reference.remove':
ref = self._get(data, 'reference', payload.referenceId)
spec = self._get(data, 'generation_spec', ref['targetSpecId'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from opendirector.domain.creation.assets import AssetProvenance
from opendirector.domain.creation.canvas import TextCanvasItem, ImageCanvasItem, VideoCanvasItem, AudioCanvasItem
from opendirector.domain.creation.base import ObjectVersion
from opendirector.domain.creation.commands import CommandReceipt, command_fingerprint
from opendirector.domain.creation.commands import parse_command
from opendirector.domain.creation.generation import (DEFAULT_MUSIC_SECONDS, InputSnapshot, Job, ResultVersion, execution_spec,
reference_music_seconds, validate_generation)
Expand Down Expand Up @@ -468,6 +469,31 @@ def accept(before):
return self.projects.commit(command, accept, session=session, source=source)

async def execute(self, command, *, session=None, source='ui', agent_origin=None):
if command.type in {'pipeline.start', 'pipeline.pause', 'pipeline.resume',
'pipeline.cancel', 'pipeline.retry', 'pipeline.adopt'}:
executor = getattr(self, 'pipelines', None)
if executor is None:
raise ProjectError('流水线执行服务不可用。', 503, code='pipeline_unavailable')
fingerprint = command_fingerprint(command)
if command.type == 'pipeline.start':
execution = await executor.submit(
command.projectId, command.payload, command.commandId, session, input_fingerprint=fingerprint,
)
else:
method = {
'pipeline.pause': 'pause',
'pipeline.resume': 'resume',
'pipeline.cancel': 'cancel',
'pipeline.retry': 'retry',
'pipeline.adopt': 'adopt',
}[command.type]
execution = await getattr(executor, method)(
command.projectId, command.payload, session,
operation_id=command.commandId, input_fingerprint=fingerprint,
)
return CommandReceipt(commandId=command.commandId, projectId=command.projectId,
inputFingerprint=fingerprint, status='applied',
pipelineExecutionId=execution['executionId'])
if command.type == 'generation.submit':
pending = asyncio.create_task(asyncio.to_thread(self.prepare, command, session=session, source=source, agent_origin=agent_origin))
async def finish():
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.layoutRuns', 'canvas.configure',
UNDOABLE = {'canvas.createGeneration', 'creation.batch', 'canvas.show', 'canvas.hide', 'canvas.move', 'canvas.update', 'canvas.layoutRuns', 'canvas.layoutPipelines', '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
Loading
Loading