@clipen/clipen-cli 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
- package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +229 -68
- package/package.json +8 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/qwen_worker.py +13 -4
- package/src/clipen/analysis/setup.py +2 -1
- package/src/clipen/analysis/setup_cli.py +58 -12
- package/src/clipen/bootstrap.py +499 -167
- package/src/clipen/cli.py +40 -15
- package/src/clipen/controller/app.py +120 -38
- package/src/clipen/controller/server.py +70 -27
- package/src/clipen/editing/agent_repository.py +8 -0
- package/src/clipen/editing/agent_tools.py +1 -1
- package/src/clipen/editing/caption_design.py +134 -0
- package/src/clipen/editing/change_report.py +17 -0
- package/src/clipen/editing/component_looks.py +3 -3
- package/src/clipen/editing/component_review.py +0 -38
- package/src/clipen/editing/coordinator.py +20 -0
- package/src/clipen/editing/evidence_jobs.py +3 -1
- package/src/clipen/editing/history_changes.py +56 -27
- package/src/clipen/editing/production_catalog.py +67 -13
- package/src/clipen/editing/production_media.py +13 -2
- package/src/clipen/editing/production_preview.py +11 -9
- package/src/clipen/editing/production_progress.py +48 -3
- package/src/clipen/editing/production_tools.py +11 -20
- package/src/clipen/editing/program_subtitles.py +5 -13
- package/src/clipen/editing/resolve_export.py +2 -183
- package/src/clipen/editing/skill_tools.py +142 -218
- package/src/clipen/editing/tool_receipts.py +2 -1
- package/src/clipen/editing/versions.py +55 -10
- package/src/clipen/editing/visual_preview.py +62 -0
- package/src/clipen/editing/workbench.py +21 -1
- package/src/clipen/i18n.py +155 -0
- package/src/clipen/locale_en.py +546 -0
- package/src/clipen/mcp_editing/__main__.py +8 -0
- package/src/clipen/media/storage.py +2 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/projects/models.py +16 -1
- package/src/clipen/projects/picker.py +3 -1
- package/src/clipen/projects/storage.py +17 -1
- package/src/clipen/providers/claude_editing.py +3 -1
- package/src/clipen/providers/codex_editing.py +3 -1
- package/src/clipen/providers/editing_agent.py +42 -5
- package/src/clipen/providers/liveness.py +39 -0
- package/src/clipen/rendering/custom_components.py +216 -25
- package/src/clipen/rendering/custom_render.py +90 -54
- package/src/clipen/rendering/fetched_fonts.py +127 -0
- package/src/clipen/rendering/production_effects.py +24 -2
- package/src/clipen/rendering/program_components.py +18 -240
- package/src/clipen/rendering/renderer.py +23 -17
- package/src/clipen/rendering/titles.py +29 -12
- package/src/clipen/skills/builtin/SKILL.md +3 -3
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +6 -6
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
- package/src/clipen/skills/catalog.py +22 -8
- package/src/clipen/skills/package.py +1 -10
- package/src/clipen/terminal.py +344 -0
- package/src/clipen/workspace.py +97 -28
- package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
- package/apps/web/dist/assets/index-CaxEZKLc.css +0 -1
- package/src/clipen/editing/resolve_titles.py +0 -291
- package/src/clipen/rendering/program_creator.py +0 -804
- package/src/clipen/rendering/program_identities.py +0 -350
- package/src/clipen/rendering/program_motion.py +0 -186
- package/src/clipen/rendering/program_studio.py +0 -227
- package/src/clipen/rendering/program_styles.py +0 -321
- package/src/clipen/skills/builtin/components.json +0 -133
package/src/clipen/cli.py
CHANGED
|
@@ -7,9 +7,12 @@ import sys
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from typing import Sequence
|
|
9
9
|
|
|
10
|
+
from clipen import __version__
|
|
10
11
|
from clipen.controller import LocalSessionAuthority
|
|
11
12
|
from clipen.controller.server import ServerPaths, probe_claude, probe_codex, run_server
|
|
13
|
+
from clipen.i18n import speaking, system_language, tr
|
|
12
14
|
from clipen.provider_registry import PROVIDERS
|
|
15
|
+
from clipen.terminal import Terminal
|
|
13
16
|
from clipen.workspace import (
|
|
14
17
|
WorkspaceError,
|
|
15
18
|
inspect_workspace_projects,
|
|
@@ -22,7 +25,12 @@ def _repo_root() -> Path:
|
|
|
22
25
|
root = Path(configured) if configured else Path(__file__).resolve().parents[2]
|
|
23
26
|
resolved = root.resolve(strict=True)
|
|
24
27
|
if not (resolved / "apps" / "web" / "dist" / "index.html").is_file():
|
|
25
|
-
raise RuntimeError(
|
|
28
|
+
raise RuntimeError(
|
|
29
|
+
tr(
|
|
30
|
+
"找不到 Clipen 操作介面,請重新安裝(npx @clipen/clipen-cli 或 ./clipen install)。",
|
|
31
|
+
"The Clipen interface is missing. Install again (npx @clipen/clipen-cli or ./clipen install).",
|
|
32
|
+
)
|
|
33
|
+
)
|
|
26
34
|
return resolved
|
|
27
35
|
|
|
28
36
|
|
|
@@ -34,28 +42,42 @@ def _data_root() -> Path:
|
|
|
34
42
|
|
|
35
43
|
|
|
36
44
|
def main(arguments: Sequence[str] | None = None) -> int:
|
|
45
|
+
# The terminal and the page's first look speak the Mac's language, or the one chosen with `clipen language`.
|
|
46
|
+
with speaking(system_language()):
|
|
47
|
+
return _main(arguments)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _main(arguments: Sequence[str] | None) -> int:
|
|
37
51
|
selected = list(sys.argv[1:] if arguments is None else arguments)
|
|
38
52
|
if len(selected) != 1 or selected[0] not in PROVIDERS:
|
|
39
|
-
|
|
53
|
+
Terminal(sys.stderr).error(tr("用法:clipen ", "Usage: clipen ") + tr("|", " | ").join(PROVIDERS))
|
|
40
54
|
return 2
|
|
41
55
|
descriptor = PROVIDERS[selected[0]]
|
|
42
56
|
# Resolved at call time so each probe stays a module attribute.
|
|
43
57
|
probe = {"codex": probe_codex, "claude": probe_claude}[descriptor.provider_id]
|
|
58
|
+
terminal = Terminal()
|
|
44
59
|
try:
|
|
45
60
|
repo_root = _repo_root()
|
|
46
61
|
data_root = _data_root()
|
|
47
62
|
workspace = prepare_workspace(Path.cwd())
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
terminal.logo(tr(f"v{__version__} · AI 剪輯工作台", f"v{__version__} · AI video editing studio"))
|
|
64
|
+
terminal.intro(f"Clipen {__version__}")
|
|
65
|
+
with terminal.spinner(tr("正在啟動 Clipen", "Starting Clipen")) as spinner:
|
|
66
|
+
inspection = inspect_workspace_projects(workspace)
|
|
67
|
+
attempt_root = data_root / "provider-attempts"
|
|
68
|
+
attempt_root.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
69
|
+
spinner.update(tr(f"正在連接 {descriptor.display_name}", f"Connecting to {descriptor.display_name}"))
|
|
70
|
+
provider = probe(attempt_root)
|
|
71
|
+
folder = str(workspace.root).replace(str(Path.home()), "~", 1)
|
|
72
|
+
count = (
|
|
73
|
+
tr(
|
|
74
|
+
f"{inspection.project_count} 個作品",
|
|
75
|
+
f"{inspection.project_count} {'project' if inspection.project_count == 1 else 'projects'}",
|
|
76
|
+
)
|
|
77
|
+
if inspection.project_count
|
|
78
|
+
else tr("還沒有作品", "no projects yet")
|
|
79
|
+
)
|
|
80
|
+
spinner.done(f"{folder} {terminal.dim(f'· {count}')}")
|
|
59
81
|
return run_server(
|
|
60
82
|
ServerPaths(
|
|
61
83
|
static_root=repo_root / "apps" / "web" / "dist",
|
|
@@ -68,10 +90,13 @@ def main(arguments: Sequence[str] | None = None) -> int:
|
|
|
68
90
|
LocalSessionAuthority(),
|
|
69
91
|
)
|
|
70
92
|
except KeyboardInterrupt:
|
|
71
|
-
|
|
93
|
+
terminal.write()
|
|
94
|
+
terminal.write(
|
|
95
|
+
tr(f"{terminal.paint('90', '■')} Clipen 已停止", f"{terminal.paint('90', '■')} Clipen stopped")
|
|
96
|
+
)
|
|
72
97
|
return 130
|
|
73
98
|
except (OSError, RuntimeError, ValueError, WorkspaceError) as error:
|
|
74
|
-
|
|
99
|
+
Terminal(sys.stderr).error(tr(f"Clipen 無法啟動:{error}", f"Clipen could not start: {error}"))
|
|
75
100
|
return 1
|
|
76
101
|
|
|
77
102
|
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
|
+
import base64
|
|
6
7
|
import hashlib
|
|
7
8
|
import json
|
|
9
|
+
import re
|
|
8
10
|
import secrets
|
|
9
11
|
import threading
|
|
10
12
|
from dataclasses import dataclass
|
|
11
13
|
from enum import Enum
|
|
12
14
|
from http.cookies import SimpleCookie
|
|
13
15
|
from pathlib import Path
|
|
16
|
+
from urllib.parse import parse_qs
|
|
14
17
|
|
|
15
18
|
from starlette.applications import Starlette
|
|
16
19
|
from starlette.concurrency import run_in_threadpool
|
|
@@ -30,6 +33,7 @@ from clipen.analysis import (
|
|
|
30
33
|
from clipen.analysis.evidence_service import EvidenceService
|
|
31
34
|
from clipen.annotations import AnnotationRepository
|
|
32
35
|
from clipen.editing import EditAgentCoordinator
|
|
36
|
+
from clipen.i18n import english, speaking, tr
|
|
33
37
|
from clipen.media import InventoryCoordinator, MediaPreviewRepository
|
|
34
38
|
from clipen.projects import (
|
|
35
39
|
DirectoryRole,
|
|
@@ -40,6 +44,7 @@ from clipen.projects.models import validate_request_id
|
|
|
40
44
|
|
|
41
45
|
_SESSION_COOKIE = "clipen_session"
|
|
42
46
|
_CSRF_HEADER = "x-clipen-csrf"
|
|
47
|
+
_LIVE_PAGE = re.compile(r"/api/projects/[^/]+/production/[^/]+/live/(page|caption)")
|
|
43
48
|
_INSTANCE_HEADER = "x-clipen-instance"
|
|
44
49
|
_SESSION_LIFETIME_SECONDS = 12 * 60 * 60
|
|
45
50
|
_MUTATING_METHODS = frozenset({"POST", "PUT", "PATCH", "DELETE"})
|
|
@@ -196,12 +201,16 @@ class LocalRequestGuard:
|
|
|
196
201
|
return
|
|
197
202
|
|
|
198
203
|
supplied_origin = headers.get("origin")
|
|
204
|
+
method = str(scope.get("method", "GET")).upper()
|
|
205
|
+
path = str(scope.get("path", ""))
|
|
206
|
+
# A live design runs in a sealed frame with no origin; it may only fetch the fonts Clipen carries.
|
|
207
|
+
if path.startswith("/component-fonts/") and method == "GET" and supplied_origin == "null":
|
|
208
|
+
await self.app(scope, receive, self._secure_send(scope, send))
|
|
209
|
+
return
|
|
199
210
|
if supplied_origin is not None and supplied_origin != self.origin:
|
|
200
211
|
await self._reject(scope, receive, send, 403, "invalid_origin")
|
|
201
212
|
return
|
|
202
213
|
|
|
203
|
-
method = str(scope.get("method", "GET")).upper()
|
|
204
|
-
path = str(scope.get("path", ""))
|
|
205
214
|
credentials = None
|
|
206
215
|
if path.startswith("/api/") and path not in {
|
|
207
216
|
"/api/health",
|
|
@@ -241,6 +250,17 @@ class LocalRequestGuard:
|
|
|
241
250
|
headers["cross-origin-resource-policy"] = "same-origin"
|
|
242
251
|
headers["permissions-policy"] = "camera=(), microphone=(), geolocation=(), payment=(), usb=()"
|
|
243
252
|
path = str(scope.get("path", ""))
|
|
253
|
+
if _LIVE_PAGE.fullmatch(path.split("?", 1)[0]):
|
|
254
|
+
# The design an AI wrote runs sealed: no origin, no network, nothing but Clipen's fonts,
|
|
255
|
+
# inside Clipen's own page only.
|
|
256
|
+
headers["content-security-policy"] = (
|
|
257
|
+
"default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; "
|
|
258
|
+
f"font-src {self.origin}; img-src data: blob:; base-uri 'none'; form-action 'none'; "
|
|
259
|
+
"frame-ancestors 'self'; sandbox allow-scripts"
|
|
260
|
+
)
|
|
261
|
+
headers["x-frame-options"] = "SAMEORIGIN"
|
|
262
|
+
elif path.startswith("/component-fonts/"):
|
|
263
|
+
headers["cross-origin-resource-policy"] = "cross-origin"
|
|
244
264
|
if path.startswith("/api/") or path in {"", "/", "/index.html"}:
|
|
245
265
|
headers["cache-control"] = "no-store"
|
|
246
266
|
elif path.startswith("/assets/"):
|
|
@@ -258,7 +278,7 @@ class LocalRequestGuard:
|
|
|
258
278
|
code: str,
|
|
259
279
|
) -> None:
|
|
260
280
|
response = JSONResponse(
|
|
261
|
-
{"error": {"code": code, "message": "無法驗證本機工作台連線。"}},
|
|
281
|
+
{"error": {"code": code, "message": tr("無法驗證本機工作台連線。")}},
|
|
262
282
|
status_code=status_code,
|
|
263
283
|
)
|
|
264
284
|
await response(scope, receive, self._secure_send(scope, send))
|
|
@@ -308,7 +328,7 @@ def create_app(
|
|
|
308
328
|
{
|
|
309
329
|
"error": {
|
|
310
330
|
"code": "session_required",
|
|
311
|
-
"message": "請從 Clipen Terminal 重新開啟工作台。",
|
|
331
|
+
"message": tr("請從 Clipen Terminal 重新開啟工作台。"),
|
|
312
332
|
}
|
|
313
333
|
},
|
|
314
334
|
status_code=401,
|
|
@@ -320,7 +340,7 @@ def create_app(
|
|
|
320
340
|
"id": provider.provider_id,
|
|
321
341
|
"name": provider.name,
|
|
322
342
|
"state": provider.state.value,
|
|
323
|
-
"message": provider.message,
|
|
343
|
+
"message": tr(provider.message),
|
|
324
344
|
},
|
|
325
345
|
"session": {"csrf_token": credentials.csrf_token},
|
|
326
346
|
}
|
|
@@ -330,7 +350,7 @@ def create_app(
|
|
|
330
350
|
# Which model runs and how much quota is left; read-only, never calls a model.
|
|
331
351
|
if authority.authenticate(_cookie_value(request.headers, _SESSION_COOKIE)) is None:
|
|
332
352
|
return JSONResponse(
|
|
333
|
-
{"error": {"code": "session_required", "message": "請從 Clipen Terminal 重新開啟工作台。"}},
|
|
353
|
+
{"error": {"code": "session_required", "message": tr("請從 Clipen Terminal 重新開啟工作台。")}},
|
|
334
354
|
status_code=401,
|
|
335
355
|
)
|
|
336
356
|
details = (
|
|
@@ -344,7 +364,7 @@ def create_app(
|
|
|
344
364
|
# Lets the UI warn before production: on battery a closed lid still sleeps the Mac.
|
|
345
365
|
if authority.authenticate(_cookie_value(request.headers, _SESSION_COOKIE)) is None:
|
|
346
366
|
return JSONResponse(
|
|
347
|
-
{"error": {"code": "session_required", "message": "請從 Clipen Terminal 重新開啟工作台。"}},
|
|
367
|
+
{"error": {"code": "session_required", "message": tr("請從 Clipen Terminal 重新開啟工作台。")}},
|
|
348
368
|
status_code=401,
|
|
349
369
|
)
|
|
350
370
|
from clipen.power import power_status
|
|
@@ -356,7 +376,7 @@ def create_app(
|
|
|
356
376
|
expected = config.instance_secret
|
|
357
377
|
if expected is None or supplied is None or not secrets.compare_digest(supplied, expected):
|
|
358
378
|
return JSONResponse(
|
|
359
|
-
{"error": {"code": "instance_invalid", "message": "找不到 Clipen instance。"}},
|
|
379
|
+
{"error": {"code": "instance_invalid", "message": tr("找不到 Clipen instance。")}},
|
|
360
380
|
status_code=404,
|
|
361
381
|
)
|
|
362
382
|
return JSONResponse({"running": True})
|
|
@@ -481,16 +501,16 @@ def create_app(
|
|
|
481
501
|
|
|
482
502
|
async def asr_setup_error_response(error: ASRSetupError) -> JSONResponse:
|
|
483
503
|
messages = {
|
|
484
|
-
"asr_setup_busy": "本機語音辨識正在安裝或移除,請稍候。",
|
|
485
|
-
"asr_release_unsafe": "語音辨識安裝位置不安全,Clipen 沒有進行刪除。",
|
|
486
|
-
"asr_remove_failed": "無法移除本機語音辨識,毛片與分析成果沒有變動。",
|
|
487
|
-
"asr_pre_remove_failed": "無法先安全停止素材分析,語音辨識沒有被移除。",
|
|
504
|
+
"asr_setup_busy": tr("本機語音辨識正在安裝或移除,請稍候。"),
|
|
505
|
+
"asr_release_unsafe": tr("語音辨識安裝位置不安全,Clipen 沒有進行刪除。"),
|
|
506
|
+
"asr_remove_failed": tr("無法移除本機語音辨識,毛片與分析成果沒有變動。"),
|
|
507
|
+
"asr_pre_remove_failed": tr("無法先安全停止素材分析,語音辨識沒有被移除。"),
|
|
488
508
|
}
|
|
489
509
|
return JSONResponse(
|
|
490
510
|
{
|
|
491
511
|
"error": {
|
|
492
512
|
"code": error.code,
|
|
493
|
-
"message": messages.get(error.code, "Clipen 無法安全完成語音辨識設定。"),
|
|
513
|
+
"message": messages.get(error.code, tr("Clipen 無法安全完成語音辨識設定。")),
|
|
494
514
|
}
|
|
495
515
|
},
|
|
496
516
|
status_code=409,
|
|
@@ -715,6 +735,66 @@ def create_app(
|
|
|
715
735
|
except ProjectError as error:
|
|
716
736
|
return await project_error_response(error)
|
|
717
737
|
|
|
738
|
+
async def workbench_live(request: Request) -> Response:
|
|
739
|
+
# A free design playing in the person's browser, and the cut it plays over.
|
|
740
|
+
try:
|
|
741
|
+
from clipen.editing.visual_preview import kept_cut, live_page
|
|
742
|
+
|
|
743
|
+
coordinator = require_edit_agents()
|
|
744
|
+
project, run = request.path_params["project_id"], request.path_params["run_id"]
|
|
745
|
+
revision = request.query_params.get("revision", "")
|
|
746
|
+
if request.path_params["part"] == "cut":
|
|
747
|
+
path = await run_in_threadpool(kept_cut, coordinator.repository, project, run, revision)
|
|
748
|
+
return FileResponse(path, media_type="video/mp4", headers={"Cache-Control": "private, no-store"})
|
|
749
|
+
if request.path_params["part"] == "caption":
|
|
750
|
+
from clipen.editing.visual_preview import caption_page
|
|
751
|
+
|
|
752
|
+
item = request.query_params.get("item", "")
|
|
753
|
+
draft = None
|
|
754
|
+
if request.query_params.get("draft"):
|
|
755
|
+
try:
|
|
756
|
+
padded = request.query_params["draft"]
|
|
757
|
+
draft = json.loads(base64.urlsafe_b64decode(padded + "=" * (-len(padded) % 4)))
|
|
758
|
+
except (ValueError, UnicodeDecodeError) as error:
|
|
759
|
+
raise ProjectError("caption_text_invalid", "字幕設定格式不正確。", status_code=422) from error
|
|
760
|
+
page = await run_in_threadpool(
|
|
761
|
+
caption_page, coordinator.repository, project, run, revision, item, draft
|
|
762
|
+
)
|
|
763
|
+
return Response(page, media_type="text/html; charset=utf-8", headers={"Cache-Control": "no-store"})
|
|
764
|
+
if request.path_params["part"] != "page":
|
|
765
|
+
raise ProjectError("not_found", "找不到這個項目。", status_code=404)
|
|
766
|
+
try:
|
|
767
|
+
padded = request.query_params.get("draft", "")
|
|
768
|
+
draft = json.loads(base64.urlsafe_b64decode(padded + "=" * (-len(padded) % 4)))
|
|
769
|
+
except (ValueError, UnicodeDecodeError) as error:
|
|
770
|
+
raise ProjectError("component_invalid", "元件設定格式不正確。", status_code=422) from error
|
|
771
|
+
page = await run_in_threadpool(live_page, coordinator.repository, project, run, revision, draft)
|
|
772
|
+
return Response(page, media_type="text/html; charset=utf-8", headers={"Cache-Control": "no-store"})
|
|
773
|
+
except ProjectError as error:
|
|
774
|
+
return await project_error_response(error)
|
|
775
|
+
|
|
776
|
+
async def component_font(request: Request) -> Response:
|
|
777
|
+
# The fonts Clipen carries, for a live design in its sealed frame (which has no origin of its own).
|
|
778
|
+
from importlib.resources import files
|
|
779
|
+
|
|
780
|
+
from clipen.rendering.custom_render import FONTS
|
|
781
|
+
|
|
782
|
+
name = request.path_params["name"]
|
|
783
|
+
if name.startswith("fetched/"):
|
|
784
|
+
from clipen.rendering.fetched_fonts import root
|
|
785
|
+
|
|
786
|
+
base = root().resolve()
|
|
787
|
+
path = (base / name[len("fetched/") :]).resolve()
|
|
788
|
+
if not (path.is_relative_to(base) and path.is_file() and path.suffix.lower() in {".ttf", ".otf"}):
|
|
789
|
+
return Response(status_code=404)
|
|
790
|
+
elif name in FONTS:
|
|
791
|
+
path = Path(str(files("clipen.rendering").joinpath("fonts", name)))
|
|
792
|
+
else:
|
|
793
|
+
return Response(status_code=404)
|
|
794
|
+
return FileResponse(
|
|
795
|
+
path, media_type="font/ttf", headers={"Access-Control-Allow-Origin": "*", "Cache-Control": "max-age=86400"}
|
|
796
|
+
)
|
|
797
|
+
|
|
718
798
|
async def project_cover(request: Request) -> Response:
|
|
719
799
|
# A still cut from the project's own footage for its card on the home page.
|
|
720
800
|
try:
|
|
@@ -888,7 +968,7 @@ def create_app(
|
|
|
888
968
|
payload = await read_json(request)
|
|
889
969
|
require_fields(payload, {"request_id"})
|
|
890
970
|
validate_request_id(payload["request_id"])
|
|
891
|
-
folder = await run_in_threadpool(require_workspace().picker.choose_folder, "選擇要匯入的 Skill 資料夾")
|
|
971
|
+
folder = await run_in_threadpool(require_workspace().picker.choose_folder, tr("選擇要匯入的 Skill 資料夾"))
|
|
892
972
|
if folder is None:
|
|
893
973
|
return Response(status_code=204)
|
|
894
974
|
package = await run_in_threadpool(skill_library().import_folder, folder)
|
|
@@ -915,7 +995,7 @@ def create_app(
|
|
|
915
995
|
offset = int(request.query_params.get("offset", "0"))
|
|
916
996
|
limit = int(request.query_params.get("limit", "30"))
|
|
917
997
|
if not 0 <= offset <= 100000 or not 1 <= limit <= 100:
|
|
918
|
-
raise ValueError("分頁參數無效。")
|
|
998
|
+
raise ValueError(tr("分頁參數無效。"))
|
|
919
999
|
return JSONResponse(
|
|
920
1000
|
await run_in_threadpool(history, repository, request.query_params.get("project_id"), offset, limit)
|
|
921
1001
|
)
|
|
@@ -1024,30 +1104,12 @@ def create_app(
|
|
|
1024
1104
|
)
|
|
1025
1105
|
elif operation == "resolve":
|
|
1026
1106
|
require_fields(payload, set())
|
|
1027
|
-
from clipen.editing.resolve_export import export_resolve, reveal
|
|
1107
|
+
from clipen.editing.resolve_export import export_resolve, reveal
|
|
1028
1108
|
from clipen.editing.workbench import idle
|
|
1029
1109
|
|
|
1030
1110
|
await run_in_threadpool(idle, coordinator.repository, project, run)
|
|
1031
1111
|
result = await run_in_threadpool(export_resolve, coordinator.repository, project, run)
|
|
1032
1112
|
await run_in_threadpool(reveal, Path(result["fcpxml"]))
|
|
1033
|
-
# Saving the timeline as .drt in Resolve is enough; Clipen makes the editable copy on its own.
|
|
1034
|
-
if result.get("editable_overlays"):
|
|
1035
|
-
start_watching(Path(result["folder"]))
|
|
1036
|
-
elif operation in {"resolve_titles", "resolve_status"}:
|
|
1037
|
-
require_fields(payload, {"folder"})
|
|
1038
|
-
from clipen.editing.resolve_export import convert_timeline, export_folder, reveal, timeline_status
|
|
1039
|
-
|
|
1040
|
-
exports = (await run_in_threadpool(export_folder, coordinator.repository, project)).resolve()
|
|
1041
|
-
package = Path(str(payload["folder"])).resolve()
|
|
1042
|
-
if package.parent != exports:
|
|
1043
|
-
raise ProjectError(
|
|
1044
|
-
"resolve_package_invalid", "只能轉換這個專案匯出到「Clipen 匯出」的資料夾。", status_code=422
|
|
1045
|
-
)
|
|
1046
|
-
if operation == "resolve_status":
|
|
1047
|
-
return JSONResponse(await run_in_threadpool(timeline_status, package))
|
|
1048
|
-
target, titles = await run_in_threadpool(convert_timeline, package)
|
|
1049
|
-
await run_in_threadpool(reveal, target)
|
|
1050
|
-
result = {"drt": str(target), "titles": titles}
|
|
1051
1113
|
else:
|
|
1052
1114
|
raise ProjectError("command_invalid", "不支援這個編輯操作。", status_code=404)
|
|
1053
1115
|
return JSONResponse(result)
|
|
@@ -1294,9 +1356,9 @@ def create_app(
|
|
|
1294
1356
|
"state": "ready" if preparations is not None else "setup_required",
|
|
1295
1357
|
"phase": "ready" if preparations is not None else "not_installed",
|
|
1296
1358
|
"message": (
|
|
1297
|
-
"本機語音辨識可用"
|
|
1359
|
+
tr("本機語音辨識可用")
|
|
1298
1360
|
if preparations is not None
|
|
1299
|
-
else "需要約 1.6 GB 空間安裝隔離的本機語音辨識環境與模型"
|
|
1361
|
+
else tr("需要約 1.6 GB 空間安裝隔離的本機語音辨識環境與模型")
|
|
1300
1362
|
),
|
|
1301
1363
|
"error_code": None,
|
|
1302
1364
|
"completed_units": 3 if preparations is not None else 0,
|
|
@@ -1376,7 +1438,7 @@ def create_app(
|
|
|
1376
1438
|
payload["request_id"],
|
|
1377
1439
|
payload["expected_revision"],
|
|
1378
1440
|
payload["scope_id"],
|
|
1379
|
-
payload.get("language", "zh"),
|
|
1441
|
+
payload.get("language", "en" if english() else "zh"),
|
|
1380
1442
|
payload.get("vocabulary", []),
|
|
1381
1443
|
)
|
|
1382
1444
|
return JSONResponse({"analysis": run.to_public()}, status_code=202)
|
|
@@ -1479,6 +1541,8 @@ def create_app(
|
|
|
1479
1541
|
),
|
|
1480
1542
|
Route("/api/projects/{project_id}/production/music", production_music, methods=["GET", "POST"]),
|
|
1481
1543
|
Route("/api/projects/{project_id}/production/{run_id}/workbench", production_workbench, methods=["GET"]),
|
|
1544
|
+
Route("/api/projects/{project_id}/production/{run_id}/live/{part}", workbench_live, methods=["GET"]),
|
|
1545
|
+
Route("/component-fonts/{name:path}", component_font, methods=["GET"]),
|
|
1482
1546
|
Route(
|
|
1483
1547
|
"/api/projects/{project_id}/production/{run_id}/workbench/{operation}",
|
|
1484
1548
|
production_workbench,
|
|
@@ -1631,13 +1695,31 @@ def create_app(
|
|
|
1631
1695
|
],
|
|
1632
1696
|
)
|
|
1633
1697
|
return LocalRequestGuard(
|
|
1634
|
-
app,
|
|
1698
|
+
_Speaking(app),
|
|
1635
1699
|
authority=authority,
|
|
1636
1700
|
origin=config.origin,
|
|
1637
1701
|
allowed_hosts=config.allowed_hosts,
|
|
1638
1702
|
)
|
|
1639
1703
|
|
|
1640
1704
|
|
|
1705
|
+
class _Speaking:
|
|
1706
|
+
"""Answer each request in the language its page names, so messages and labels match the page."""
|
|
1707
|
+
|
|
1708
|
+
def __init__(self, app: ASGIApp) -> None:
|
|
1709
|
+
self.app = app
|
|
1710
|
+
|
|
1711
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
|
1712
|
+
if scope["type"] != "http":
|
|
1713
|
+
await self.app(scope, receive, send)
|
|
1714
|
+
return
|
|
1715
|
+
asked = next((value.decode("latin-1") for name, value in scope["headers"] if name == b"x-clipen-locale"), None)
|
|
1716
|
+
if asked is None:
|
|
1717
|
+
# EventSource cannot set headers; the page then names its language in the address.
|
|
1718
|
+
asked = parse_qs(scope.get("query_string", b"").decode("latin-1")).get("lang", [None])[0]
|
|
1719
|
+
with speaking(asked):
|
|
1720
|
+
await self.app(scope, receive, send)
|
|
1721
|
+
|
|
1722
|
+
|
|
1641
1723
|
def _query_integer(
|
|
1642
1724
|
request: Request,
|
|
1643
1725
|
name: str,
|
|
@@ -19,6 +19,8 @@ from dataclasses import dataclass
|
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
from typing import Callable
|
|
21
21
|
|
|
22
|
+
from clipen.i18n import tr
|
|
23
|
+
|
|
22
24
|
try:
|
|
23
25
|
import fcntl as _fcntl
|
|
24
26
|
except ImportError: # Windows does not provide POSIX advisory file locks.
|
|
@@ -40,6 +42,8 @@ from clipen.projects import ProjectWorkspace
|
|
|
40
42
|
from clipen.provider_registry import exec_adapter_factory
|
|
41
43
|
from clipen.providers import CodexExecAdapter, ProviderUnavailable
|
|
42
44
|
from clipen.providers.claude import ClaudeCliAdapter
|
|
45
|
+
from clipen.rendering import PreviewRenderRepository
|
|
46
|
+
from clipen.terminal import Terminal, display_width
|
|
43
47
|
|
|
44
48
|
from .app import (
|
|
45
49
|
ControllerConfig,
|
|
@@ -72,7 +76,12 @@ class _InstanceLease:
|
|
|
72
76
|
@classmethod
|
|
73
77
|
def acquire(cls, root: Path) -> "_InstanceLease | None":
|
|
74
78
|
if _fcntl is None:
|
|
75
|
-
raise RuntimeError(
|
|
79
|
+
raise RuntimeError(
|
|
80
|
+
tr(
|
|
81
|
+
"這個開發版本尚不支援 Windows;本機工作台需要 POSIX 檔案鎖",
|
|
82
|
+
"This version does not support Windows yet; Clipen needs POSIX file locks",
|
|
83
|
+
)
|
|
84
|
+
)
|
|
76
85
|
lock_path = root / ".controller.lock"
|
|
77
86
|
flags = os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0)
|
|
78
87
|
descriptor = os.open(lock_path, flags, 0o600)
|
|
@@ -232,7 +241,9 @@ def _bind_socket(
|
|
|
232
241
|
except OSError as error:
|
|
233
242
|
listener.close()
|
|
234
243
|
if port == 0 or error.errno not in (errno.EADDRINUSE, errno.EACCES):
|
|
235
|
-
raise PortUnavailable(
|
|
244
|
+
raise PortUnavailable(
|
|
245
|
+
tr("無法取得可用的本機連線埠,請稍後再試", "No local port is free; try again shortly")
|
|
246
|
+
) from error
|
|
236
247
|
raise AssertionError("port allocation must return a listener or raise")
|
|
237
248
|
|
|
238
249
|
|
|
@@ -306,12 +317,44 @@ def _find_existing_controller(registry_path: Path) -> ExistingController | None:
|
|
|
306
317
|
|
|
307
318
|
|
|
308
319
|
def _print_ui_url(url: str, *, first_connection: bool = False) -> None:
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
320
|
+
terminal = Terminal()
|
|
321
|
+
if first_connection:
|
|
322
|
+
terminal.warn(
|
|
323
|
+
tr(
|
|
324
|
+
f"瀏覽器沒有自動開啟,請點這個網址\n{terminal.link(url)}",
|
|
325
|
+
f"The browser did not open by itself; click this address\n{terminal.link(url)}",
|
|
326
|
+
)
|
|
327
|
+
)
|
|
313
328
|
else:
|
|
314
|
-
|
|
329
|
+
terminal.info(tr(f"網址 {terminal.link(url)}", f"Address {terminal.link(url)}"))
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def _announce(provider: ProviderStatus, public_url: str, *, opened: bool, interactive: bool) -> None:
|
|
333
|
+
"""The one panel the person sees once Clipen is serving: where to go next and how to stop."""
|
|
334
|
+
terminal = Terminal()
|
|
335
|
+
bar = terminal.paint("90", "│")
|
|
336
|
+
if provider.state is ProviderState.READY:
|
|
337
|
+
ai = f"{provider.name} {terminal.paint('32', tr('● 已連接', '● connected'))}"
|
|
338
|
+
else:
|
|
339
|
+
ai = f"{provider.name} {terminal.paint('33', f'▲ {tr(provider.message)}')}"
|
|
340
|
+
title = (
|
|
341
|
+
tr("Clipen 已在瀏覽器開啟,接下來請在瀏覽器操作", "Clipen is open in your browser; carry on there")
|
|
342
|
+
if opened
|
|
343
|
+
else tr("Clipen 已啟動,請點下面的網址開啟", "Clipen is running; click the address below to open it")
|
|
344
|
+
)
|
|
345
|
+
terminal.write(bar)
|
|
346
|
+
terminal.write(f"{terminal.paint('32', '◆')} {terminal.bold(title)}")
|
|
347
|
+
terminal.write(bar)
|
|
348
|
+
rows = ((tr("網址", "Address"), terminal.link(public_url)), ("AI", ai))
|
|
349
|
+
width = max(display_width(name) for name, _ in rows)
|
|
350
|
+
for name, value in rows:
|
|
351
|
+
terminal.write(f"{bar} {terminal.dim(name + ' ' * (width - display_width(name)))} {value}")
|
|
352
|
+
keys = (
|
|
353
|
+
tr("Enter 重新開啟網頁 · Ctrl+C 關閉 Clipen", "Enter reopens the page · Ctrl+C quits Clipen")
|
|
354
|
+
if interactive
|
|
355
|
+
else tr("Ctrl+C 關閉 Clipen", "Ctrl+C quits Clipen")
|
|
356
|
+
)
|
|
357
|
+
terminal.outro(terminal.dim(keys))
|
|
315
358
|
|
|
316
359
|
|
|
317
360
|
def _terminal_reopen_loop(
|
|
@@ -331,7 +374,6 @@ def _terminal_reopen_loop(
|
|
|
331
374
|
except Exception:
|
|
332
375
|
opened = False
|
|
333
376
|
if not opened:
|
|
334
|
-
print("瀏覽器未自動開啟。", flush=True)
|
|
335
377
|
_print_ui_url(public_url, first_connection=True)
|
|
336
378
|
|
|
337
379
|
|
|
@@ -384,8 +426,12 @@ async def _serve(
|
|
|
384
426
|
)
|
|
385
427
|
evidence_service.recover()
|
|
386
428
|
preparation_repository = PreparationRepository(workspace.repository)
|
|
429
|
+
# A film left rendering when Clipen last stopped has no process behind it any more; left
|
|
430
|
+
# as running, the page would wait on it forever and newer saves would never render.
|
|
431
|
+
renders = PreviewRenderRepository(workspace.repository)
|
|
387
432
|
for project in workspace.repository.list_projects():
|
|
388
433
|
preparation_repository.interrupt_incomplete(project.project_id)
|
|
434
|
+
renders.interrupt_incomplete(project.project_id)
|
|
389
435
|
if paths.asr_requirements is not None:
|
|
390
436
|
analysis_runtime = ManagedAnalysisRuntime(
|
|
391
437
|
preparation_repository,
|
|
@@ -430,22 +476,13 @@ async def _serve(
|
|
|
430
476
|
while not server.started and not server.should_exit:
|
|
431
477
|
await asyncio.sleep(0.02)
|
|
432
478
|
if server.started:
|
|
433
|
-
|
|
434
|
-
if provider.state is ProviderState.READY:
|
|
435
|
-
print(f"AI:{provider.name} 可用", flush=True)
|
|
436
|
-
else:
|
|
437
|
-
print(f"AI:{provider.name} 需要處理", flush=True)
|
|
438
|
-
_print_ui_url(public_url)
|
|
439
|
-
print("狀態:等待 UI 操作", flush=True)
|
|
479
|
+
interactive = sys.stdin.isatty()
|
|
440
480
|
try:
|
|
441
481
|
opened = browser_open(public_url)
|
|
442
482
|
except Exception:
|
|
443
483
|
opened = False
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
_print_ui_url(public_url, first_connection=True)
|
|
447
|
-
if sys.stdin.isatty():
|
|
448
|
-
print("按 Enter 重新開啟 UI · 按 Ctrl+C 關閉 Clipen", flush=True)
|
|
484
|
+
_announce(provider, public_url, opened=opened, interactive=interactive)
|
|
485
|
+
if interactive:
|
|
449
486
|
threading.Thread(
|
|
450
487
|
target=_terminal_reopen_loop,
|
|
451
488
|
args=(
|
|
@@ -456,8 +493,6 @@ async def _serve(
|
|
|
456
493
|
name="clipen-terminal-reopen",
|
|
457
494
|
daemon=True,
|
|
458
495
|
).start()
|
|
459
|
-
else:
|
|
460
|
-
print("按 Ctrl+C 關閉 Clipen", flush=True)
|
|
461
496
|
|
|
462
497
|
announcement = asyncio.create_task(announce_when_started())
|
|
463
498
|
previous_hup = None
|
|
@@ -500,16 +535,22 @@ def run_server(
|
|
|
500
535
|
if lease is None:
|
|
501
536
|
existing = _find_existing_controller(instance_root / ".controller.json")
|
|
502
537
|
if existing is None:
|
|
503
|
-
|
|
538
|
+
Terminal().error(
|
|
539
|
+
tr(
|
|
540
|
+
"Clipen 無法連接正在啟動的本機工作台。請稍後再試。",
|
|
541
|
+
"Clipen cannot reach the instance that is starting. Try again shortly.",
|
|
542
|
+
)
|
|
543
|
+
)
|
|
504
544
|
return 1
|
|
505
|
-
|
|
545
|
+
Terminal().step(
|
|
546
|
+
tr("Clipen 已在執行,已幫你重新開啟網頁", "Clipen is already running; reopened the page for you")
|
|
547
|
+
)
|
|
506
548
|
_print_ui_url(existing.public_url)
|
|
507
549
|
try:
|
|
508
550
|
opened = browser_open(existing.public_url)
|
|
509
551
|
except Exception:
|
|
510
552
|
opened = False
|
|
511
553
|
if not opened:
|
|
512
|
-
print("瀏覽器未自動開啟。", flush=True)
|
|
513
554
|
_print_ui_url(existing.public_url, first_connection=True)
|
|
514
555
|
return 0
|
|
515
556
|
try:
|
|
@@ -523,11 +564,13 @@ def run_server(
|
|
|
523
564
|
)
|
|
524
565
|
)
|
|
525
566
|
except PortUnavailable as error:
|
|
526
|
-
|
|
567
|
+
Terminal().error(tr(f"Clipen 無法啟動:{error}", f"Clipen could not start: {error}"))
|
|
527
568
|
return 1
|
|
528
569
|
except KeyboardInterrupt:
|
|
529
570
|
pass
|
|
530
571
|
finally:
|
|
531
572
|
lease.close()
|
|
532
|
-
|
|
573
|
+
terminal = Terminal()
|
|
574
|
+
terminal.write()
|
|
575
|
+
terminal.write(tr(f"{terminal.paint('90', '■')} Clipen 已停止", f"{terminal.paint('90', '■')} Clipen stopped"))
|
|
533
576
|
return 0
|
|
@@ -8,6 +8,7 @@ import sqlite3
|
|
|
8
8
|
from typing import Mapping
|
|
9
9
|
|
|
10
10
|
from clipen.domain import EditTimeline
|
|
11
|
+
from clipen.i18n import english
|
|
11
12
|
from clipen.projects import ProjectError, ProjectRepository
|
|
12
13
|
from clipen.projects.models import validate_project_id, validate_request_id
|
|
13
14
|
from clipen.projects.storage import command_digest, utc_now
|
|
@@ -231,6 +232,8 @@ class EditAgentRepository:
|
|
|
231
232
|
"font_style_id": selected_font,
|
|
232
233
|
"target_duration_seconds": target,
|
|
233
234
|
"music_choice": selected_music,
|
|
235
|
+
# The AI writes in the language of the person who asked.
|
|
236
|
+
**({"language": "en"} if english() else {}),
|
|
234
237
|
}
|
|
235
238
|
),
|
|
236
239
|
encoded(skill),
|
|
@@ -423,6 +426,11 @@ class EditAgentRepository:
|
|
|
423
426
|
hand_over(intent)
|
|
424
427
|
if choice is not None:
|
|
425
428
|
intent["music_choice"] = choice
|
|
429
|
+
# A revision is written in the language of whoever asked for it.
|
|
430
|
+
if english():
|
|
431
|
+
intent["language"] = "en"
|
|
432
|
+
else:
|
|
433
|
+
intent.pop("language", None)
|
|
426
434
|
db.execute("UPDATE production_sessions SET intent_json=? WHERE run_id=?", (encoded(intent), normalized))
|
|
427
435
|
self._append_event(
|
|
428
436
|
db,
|
|
@@ -72,8 +72,8 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
72
72
|
if getattr(self, "_user_edit", False):
|
|
73
73
|
# Only a person can reword a graphic directly; the AI revises through its own component tools.
|
|
74
74
|
handlers["edit_component"] = self._edit_component
|
|
75
|
-
handlers["set_component_text"] = self._edit_component
|
|
76
75
|
handlers["edit_component_look"] = self._edit_component_look
|
|
76
|
+
handlers["edit_caption"] = self._edit_caption
|
|
77
77
|
handler = (lambda args: self.production_call(name, args)) if name in EXTRA_NAMES else handlers.get(name)
|
|
78
78
|
if handler is None:
|
|
79
79
|
raise ProjectError("tool_not_allowed", "這個工具未獲 Clipen 授權。", status_code=404)
|