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
31 changes: 16 additions & 15 deletions apps/api/src/opendirector_api/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,26 @@ def __init__(self, projects):
self._started: dict[str, float] = {}
self._started_lock = threading.Lock()

def _resolve(self, db, project_id: UUID, session: str | None = None) -> Path:
self.projects._recover()
directory, manifest = self.projects._find(db, project_id)
# Conversation storage only needs the current project. Replaying its
# ancestry here holds the shared catalog lock past other requests' timeout.
self.projects._current(db, project_id, directory, manifest)
if session:
self.projects._lease(db, project_id, directory, session, browser_only=True)
return directory

def path(self, project_id: UUID, session: str | None = None) -> Path:
with self.projects.local.transaction() as db:
self.projects._recover()
directory, _ = self.projects._find(db, project_id)
if session:
self.projects._lease(db, project_id, directory, session, browser_only=True)
return directory
return self._resolve(db, project_id, session)

def update(self, project_id: UUID, session: str | None = None, *, draft: Draft | None = None,
begin: dict | None = None, finish: dict | None = None, conversation_id: UUID | None = None,
before_begin=None, agent_session: str | None = None) -> dict:
finish_mono, finish_at = (_monotonic(), _utc_now()) if finish is not None else (None, None)
with self.projects.local.transaction() as db:
self.projects._recover()
directory, _ = self.projects._find(db, project_id)
if session:
self.projects._lease(db, project_id, directory, session, browser_only=True)
directory = self._resolve(db, project_id, session)
folder = child(directory, 'agent-runs')
folder.mkdir(exist_ok=True)
file = child(folder, 'conversation.json')
Expand Down Expand Up @@ -312,9 +315,9 @@ def cancel_queued(self, project_id: UUID, session: str | None = None) -> list[di
return cancelled

def list(self, project_id: UUID) -> dict:
directory = self.path(project_id)
file = child(child(directory, 'agent-runs'), 'conversation.json')
with self.projects.local.transaction():
with self.projects.local.transaction() as db:
directory = self._resolve(db, project_id)
file = child(child(directory, 'agent-runs'), 'conversation.json')
current = read_json(file) if file.exists() else {'messages': [], **Draft().model_dump()}
current['conversationId'] = current.get('conversationId') or str(uuid5(project_id, 'assistant'))
return {'activeId': current['conversationId'], 'items': [
Expand Down Expand Up @@ -385,9 +388,7 @@ def conversation_of(self, project_id: UUID, turn_id: UUID) -> str:

def activate(self, project_id: UUID, conversation_id: UUID, session: str, *, create=False) -> dict:
with self.projects.local.transaction() as db:
self.projects._recover()
directory, _ = self.projects._find(db, project_id)
self.projects._lease(db, project_id, directory, session, browser_only=True)
directory = self._resolve(db, project_id, session)
folder = child(directory, 'agent-runs')
folder.mkdir(exist_ok=True)
file = child(folder, 'conversation.json')
Expand Down
14 changes: 13 additions & 1 deletion apps/api/src/opendirector_api/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from opendirector.application.creation_video_compatibility import CreationVideoCompatibility, VideoConversionTask
from opendirector.domain.creation.timeline_packages import TimelinePackageImportRequest, TimelinePackageImportReceipt
from opendirector.domain.creation.assets import Asset, UploadInfo
from opendirector.domain.creation.character_workshop import WorkshopRequest
from opendirector.domain.creation.base import MediaKind
from opendirector.domain.creation.commands import Command, CommandReceipt, Query as CreationQuery
from opendirector.domain.creation.project import ProjectSnapshot, ViewState
Expand Down Expand Up @@ -82,7 +83,7 @@ async def disconnected():
await asyncio.gather(work, disconnect, return_exceptions=True)


def creation_routes(projects: CreationProjects, generation=None, prompt_optimization=None):
def creation_routes(projects: CreationProjects, generation=None, prompt_optimization=None, workshop=None):
router = APIRouter(prefix='/api/creation', tags=['Unified creation projects'])
reference_checks = asyncio.Semaphore(2)
assets = CreationAssets(projects)
Expand Down Expand Up @@ -125,6 +126,17 @@ async def optimize_prompt(project_id: UUID, item_id: UUID, value: PromptOptimiza
project_id, item_id, value.prompt, value.inlineReferences,
value.preferredModelId, value.assistantModel))

@router.get('/projects/{project_id}/workshops/{editor_id}')
async def get_workshop(project_id: UUID, editor_id: UUID):
return await run_in_threadpool(workshop.get, project_id, editor_id)

@router.post('/projects/{project_id}/workshops/{editor_id}')
async def workshop_action(project_id: UUID, editor_id: UUID, value: WorkshopRequest, x_opendirector_session: UUID = Header()):
try:
return await workshop.action(project_id, editor_id, value.model_dump(mode='json', exclude_unset=True), str(x_opendirector_session) if x_opendirector_session else None)
except (ValueError, KeyError, StopIteration, TypeError):
raise ProjectError('工坊参数无效,请刷新后重试。', 422, code='invalid_input') from None

@router.get('/projects')
def list_projects(navigation: bool = False):
return projects.list_projects(navigation=navigation)
Expand Down
35 changes: 35 additions & 0 deletions apps/api/src/opendirector_api/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,41 @@
'voice_provider_timeout': 'The voice service timed out. Check its status and try again.',
'voice_name_taken': 'This account already has a voice with that name. Choose another name.',
'voice_provider_quota': 'The voice service account has insufficient balance or resource packages. Top up and try again.',
"workshop_short": "The effective video is shorter than 0.5 seconds.",
"workshop_media": "Media processing failed. Check FFmpeg and the video file.",
"workshop_scenedetect": "Install scenedetect[opencv] and retry.",
"workshop_duration": "Unexpected generated duration. The raw result is retained for inspection and recovery.",
"workshop_binding": "Select a person and bind character references.",
"workshop_binding_conflict": "Selections of the same person are bound to different replacements. Choose the same replacement and retry.",
"workshop_anchor_limit": "Each segment supports up to 26 source characters, with up to 20 selections per character.",
"workshop_model": "Configure an image understanding model and a video model supporting joint video and image references with declared output specifications.",
"workshop_budget": "References or segment duration exceed model limits. Adjust the inputs.",
"workshop_image_model": "Select an image editing model that accepts reference images and a multimodal analysis model.",
"workshop_image_geometry": "The model returned an unexpected aspect ratio. The original result is retained. Retry or choose another image model.",
"workshop_image_reference": "The image model rejected its inputs. Check the source keyframe and character reference images.",
"workshop_keyframe_failed": "Some keyframe previews failed. Retry the missing previews or continue with the previews that are ready.",
"workshop_image_moderation": "The image service rejected an input during content review. Check the keyframe and character reference images, then retry with images that meet the service’s requirements.",
"workshop_discard_confirmation": "The candidate list changed. Review the candidates to remove and try again.",
"workshop_analysis_connect": "Could not connect to the analysis model. Test the connection in model settings. If the endpoint uses a local tunnel, restore it, or select another connected model and generate again.",
"workshop_analysis_timeout": "The analysis model did not respond in time. Retry later or select another analysis model and generate again.",
"workshop_analysis_auth": "The analysis service denied access. Check the model API key, account, or permissions and retry.",
"workshop_analysis_incomplete": "The analysis model did not return a complete response. Resume this task or select another analysis model and generate again.",
"workshop_analysis_response": "The analysis service returned an error or dropped the connection. Test the model in settings and retry.",
"workshop_analysis_budget": "Character analysis exceeds the model server’s multimodal encoder budget. Check the server configuration or adjust the references.",
"workshop_prompt_write": "The multimodal model did not return usable editing directions. Try again.",
"workshop_keyframe_prompt_write": "Could not write the keyframe prompts. Retry the missing images or continue with available previews.",
"workshop_prompt_too_long": "The prompt is too long after adding the replacement boundary. Shorten the prompt and try again.",
"workshop_analysis": "Person analysis could not be verified. Add an anchor and retry.",
"workshop_incomplete": "The current clips could not be read. Check that the source and result media are still available.",
"workshop_no_segments": "There are no clips to export. Import and segment the source video first.",
"workshop_edit_range": "Select adjacent segments. Both split parts must be at least 0.5 seconds.",
"workshop_replace_confirmation": "The result track already contains a clip. Confirm replacement first.",
"workshop_conflict": "The workshop changed. Refresh and retry.",
"workshop_submission_unknown": "The video model did not return a task ID. The original submission could not be confirmed.",
"workshop_active": "This segment has an active task. Inspect or resume the existing task.",
"workshop_generation": "Generation did not complete. Inspect shared job records and resume the original task.",
"workshop_interrupted": "Local processing was interrupted. The remote task may still be running; resume the original task.",

"moss_speech_text": "Enter the text to read aloud.",
"moss_speech_voice": "Enter a Voice ID available to your MOSS account.",
"moss_speech_reference": "MOSS speech generation does not accept references. Enter speech text and a Voice ID.",
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/opendirector_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def create_app(store: LocalProjects | None = None, chat_provider=None, generatio
creation_generation = CreationGeneration(creation_projects, model_configs, generation_provider, availability=availability)
pipelines = PipelineExecutor(creation_projects, creation_generation, model_configs)
creation_generation.pipelines = pipelines
from opendirector.application.character_workshop import CharacterWorkshop
character_workshop = CharacterWorkshop(creation_projects, creation_generation)
creation_generation.character_workshop = character_workshop
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 @@ -83,6 +86,7 @@ async def lifespan(app):
await asyncio.gather(*agents, return_exceptions=True)
try:
await pipelines.close()
await character_workshop.close()
await creation_tools.close()
finally:
await creation_generation.close()
Expand All @@ -91,7 +95,7 @@ async def lifespan(app):
app = FastAPI(title="OpenDirector Local API", version="0.1.6", lifespan=lifespan)
app.include_router(creation_routes(creation_projects, creation_generation,
PromptOptimization(creation_projects, model_configs, chat_provider or ChatCompletions(),
cli_rewrite=_cli_prompt_rewrite)))
cli_rewrite=_cli_prompt_rewrite), workshop=character_workshop))
app.include_router(agent_routes(creation_projects, creation_generation, model_configs, chat_provider, active=active_agents))
app.include_router(library_routes(creation_projects))
app.include_router(voice_routes(creation_generation.voices))
Expand Down Expand Up @@ -129,6 +133,7 @@ async def project_error(request, error):
),
"code": error.code,
**({'requiredCapability': required_capability} if required_capability else {}),
**({"details": error.details} if error.details is not None else {}),
},
status_code=error.status,
)
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This directory is the entry point for the repository's shared documentation. The
| [macOS installation validation](development/macos-install-validation.md) | Installation and usage scenarios verified on Apple Silicon | The corresponding acceptance checks are repeated |
| [Bilingual interface](development/i18n.md) | Language selection, message organization, and checks | Language policy, message structure, or checks change |
| [Python installation and packaging](development/packaging.md) | Installation, platform wheel builds, and isolated verification | Packaging, resource paths, or build process changes |
| [Character Replacement Workshop](guides/character-workshop.md) ([中文](guides/character-workshop.zh-CN.md)) | Video import, scene detection, person anchors, reference generation, candidates and backend export | Workshop capabilities or recovery semantics change |
| [Business CLI](guides/cli.md) | Querying, editing, and generating through a terminal or Agent Shell | Commands, authorization, or receipt semantics change |
| [DeepSeek Harness plugin](../plugins/deepseek-harness/README.md) | Installing the DSH bundle and editing an OpenDirector project from DSH | Plugin setup, tools, or creation workflows change |
| [Video model capabilities](guides/video-model-capabilities.md) ([中文](guides/video-model-capabilities.zh-CN.md)) | Declaring output specifications supported by a service | Configuration fields or capability integration changes |
Expand Down
Loading
Loading