@dawnwood/cli 0.5.0 → 0.7.0

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 CHANGED
@@ -34,8 +34,9 @@ npx @dawnwood/cli whoami
34
34
  | Storyboard tools | `flashback_montage`, `reclone_voice`, `likeness_reroll`, `import_clip`, `job_status` |
35
35
  | Sign-off and delivery | `signoff_episode`, `build_delivery_pack` |
36
36
  | Account | `credits_balance`, `get_review_url` |
37
- | Clips | `upload_video`, `clips_create`, `clips_get_job`, `clips_edit_clip`, `clips_send_to_matrix`, `clips_list_jobs`, `clips_series_episodes`, `clips_retry` |
38
- | Matrix (posting) | `matrix_status`, `matrix_accounts`, `matrix_update_account`, `matrix_lanes`, `matrix_update_lane`, `matrix_media`, `matrix_add_media`, `matrix_plan_posts`, `matrix_schedule_posts`, `matrix_posts`, `matrix_cancel_post`, `matrix_comments`, `matrix_report` |
37
+ | Review & rework | loaded at startup from the console agent: `render_status`, `update_shot`, `render_shot`, `rerender_group`, `retake_range`, `propose_fix`, `adopt_take`, … (spending tools need `user_message`) |
38
+ | Clips | `upload_video`, `upload_image`, `clips_create`, `clips_get_job`, `clips_edit_clip`, `clips_send_to_matrix`, `clips_list_jobs`, `clips_series_episodes`, `clips_retry` |
39
+ | Matrix (posting) | `matrix_status`, `matrix_accounts`, `matrix_update_account`, `matrix_lanes`, `matrix_update_lane`, `matrix_media`, `matrix_add_media`, `matrix_update_media`, `matrix_plan_posts`, `matrix_schedule_posts`, `matrix_posts`, `matrix_cancel_post`, `matrix_comments`, `matrix_report` |
39
40
 
40
41
  Poll with `get_run`, `art_status` or `job_status`, no more than every 10 seconds.
41
42
  `list_runs` is for browsing, not polling. Approvals are gate actions: give the
package/dist/bridge.js ADDED
@@ -0,0 +1,80 @@
1
+ import { z } from "zod";
2
+ import { apiCall } from "./api.js";
3
+ const USER_MESSAGE = "The user's latest message, verbatim. Required for tools that spend credits: it is how the server knows the user asked for this, and a new message is what lets a retry through after two failed attempts on the same target.";
4
+ /** JSON schema(服务端工具定义的子集)→ zod。不认识的形状一律放宽成 unknown,由服务端校验。 */
5
+ export function toZod(s) {
6
+ if (!s)
7
+ return z.unknown();
8
+ const t = Array.isArray(s.type) ? s.type.find((x) => x !== "null") : s.type;
9
+ let out;
10
+ if (s.enum && s.enum.length && s.enum.every((x) => typeof x === "string")) {
11
+ out = z.enum(s.enum);
12
+ }
13
+ else if (t === "string")
14
+ out = z.string();
15
+ else if (t === "integer")
16
+ out = z.number().int();
17
+ else if (t === "number")
18
+ out = z.number();
19
+ else if (t === "boolean")
20
+ out = z.boolean();
21
+ else if (t === "array")
22
+ out = z.array(toZod(s.items));
23
+ else if (t === "object")
24
+ out = s.properties ? z.object(toShape(s)).passthrough() : z.record(z.string(), z.unknown());
25
+ else
26
+ out = z.unknown();
27
+ if (Array.isArray(s.type) && s.type.includes("null"))
28
+ out = out.nullable();
29
+ return s.description ? out.describe(s.description) : out;
30
+ }
31
+ export function toShape(s) {
32
+ const req = new Set(s.required || []);
33
+ const shape = {};
34
+ for (const [k, v] of Object.entries(s.properties || {})) {
35
+ shape[k] = req.has(k) ? toZod(v) : toZod(v).optional();
36
+ }
37
+ return shape;
38
+ }
39
+ /** 注册本地还没有的工具(重名的保留本地定义)。返回实际注册的名字。 */
40
+ export function registerBridgeTools(server, tools, agent) {
41
+ const added = [];
42
+ for (const t of tools) {
43
+ const shape = { ...toShape(t.input_schema || {}), user_message: z.string().optional().describe(USER_MESSAGE) };
44
+ const desc = `${t.description}${t.spends ? " Spends credits: pass user_message." : ""}`;
45
+ try {
46
+ server.tool(t.name, desc, shape, async (args) => {
47
+ const { user_message, ...input } = args;
48
+ try {
49
+ const r = await apiCall(`/agent/tools/${encodeURIComponent(t.name)}`, {
50
+ method: "POST", tool: t.name, agent, body: { input, ...(user_message ? { user_message } : {}) },
51
+ });
52
+ const link = r.card && r.card.url ? `\n${r.card.label || "Link"}: ${r.card.url}` : "";
53
+ return { content: [{ type: "text", text: `${r.result ?? ""}${link}` }], ...(r.error ? { isError: true } : {}) };
54
+ }
55
+ catch (e) {
56
+ return { content: [{ type: "text", text: e instanceof Error ? e.message : String(e) }], isError: true };
57
+ }
58
+ });
59
+ added.push(t.name);
60
+ }
61
+ catch {
62
+ // 已由本地定义的同名工具(list_runs 等)—— 保留本地版本
63
+ }
64
+ }
65
+ return added;
66
+ }
67
+ /** 拉服务端工具清单;没登录/网络失败 → 空(MCP 照常起,只少这一组)。 */
68
+ export async function fetchAgentTools(agent, timeoutMs = 8000) {
69
+ try {
70
+ const r = await Promise.race([
71
+ apiCall("/agent/tools", { tool: "agent_tools", agent }),
72
+ new Promise((_, rej) => setTimeout(() => rej(new Error("timeout")), timeoutMs)),
73
+ ]);
74
+ return Array.isArray(r?.tools) ? r.tools : [];
75
+ }
76
+ catch (e) {
77
+ process.stderr.write(`dawnwood: review tools unavailable (${e instanceof Error ? e.message : String(e)}) — the static tools still work\n`);
78
+ return [];
79
+ }
80
+ }
package/dist/mcp.js CHANGED
@@ -14,6 +14,7 @@ import { z } from "zod";
14
14
  import { apiCall } from "./api.js";
15
15
  import { CONSOLE_BASE_DEFAULT, getApiBase } from "./config.js";
16
16
  import { registerOpsTools } from "./ops.js";
17
+ import { fetchAgentTools, registerBridgeTools } from "./bridge.js";
17
18
  const AGENT = process.env.DAWNWOOD_AGENT || "mcp";
18
19
  function consoleBase() {
19
20
  return process.env.DAWNWOOD_CONSOLE_BASE ||
@@ -35,7 +36,7 @@ async function call(path, tool, method, body) {
35
36
  }
36
37
  }
37
38
  export function buildServer() {
38
- const server = new McpServer({ name: "dawnwood", version: "0.5.0" });
39
+ const server = new McpServer({ name: "dawnwood", version: "0.7.0" });
39
40
  // ---- runs 生命周期 ---------------------------------------------------------
40
41
  server.tool("list_runs", "List your runs (drafts and in progress). For browsing only — **never poll status with it**; use get_run for a single run.", async () => call("/runs", "list_runs"));
41
42
  server.tool("get_run", "Read one run's full state (wizard step, bible, scripts, pack, art progress). This is the right tool for polling (O(1) lookup); poll at most every 10 seconds (10s).", { run_id: z.string().describe("run id (snake_case)") }, async ({ run_id }) => call(`/runs/${encodeURIComponent(run_id)}`, "get_run"));
@@ -214,6 +215,8 @@ export function buildServer() {
214
215
  }
215
216
  export async function runMcp() {
216
217
  const server = buildServer();
218
+ // 看片返工那组工具从服务端内嵌 agent 拉(规矩随服务端更新);拉不到也照常起
219
+ registerBridgeTools(server, await fetchAgentTools(AGENT), AGENT);
217
220
  const transport = new StdioServerTransport();
218
221
  await server.connect(transport);
219
222
  // stdio server:进程由客户端(Claude Code 等)托管,直到 stdin 关闭。
package/dist/ops.js CHANGED
@@ -16,19 +16,25 @@ function qs(params) {
16
16
  const p = Object.entries(params).filter(([, v]) => v !== undefined && v !== "").map(([k, v]) => `${k}=${enc(String(v))}`);
17
17
  return p.length ? `?${p.join("&")}` : "";
18
18
  }
19
+ const VIDEO_TYPES = { ".mp4": "video/mp4", ".mov": "video/quicktime" };
20
+ const IMAGE_TYPES = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png" };
19
21
  /** 本地 mp4/mov → POST /assets 拿预签名 → PUT 上传 → asset_id(给 clips_create 或 matrix_add_media 用)。 */
20
22
  export async function uploadVideo(path, agent, fetchImpl = fetch) {
23
+ return uploadFile(path, "video", agent, fetchImpl);
24
+ }
25
+ /** 本地文件(视频或封面图)直传 → asset_id。 */
26
+ export async function uploadFile(path, kind, agent, fetchImpl = fetch) {
21
27
  const ext = extname(path).toLowerCase();
22
- const ct = ext === ".mp4" ? "video/mp4" : ext === ".mov" ? "video/quicktime" : "";
28
+ const ct = (kind === "video" ? VIDEO_TYPES : IMAGE_TYPES)[ext] || "";
23
29
  if (!ct)
24
- throw new Error("only .mp4 or .mov files can be uploaded");
30
+ throw new Error(kind === "video" ? "only .mp4 or .mov files can be uploaded" : "only .jpg or .png images can be uploaded");
25
31
  const size = statSync(path).size;
26
32
  if (!size)
27
33
  throw new Error("the file is empty");
28
- if (size > MAX_UPLOAD_BYTES)
29
- throw new Error(`the file is ${(size / 1e6).toFixed(0)} MB — the limit is 1 GB`);
30
- const reg = await apiCall("/assets", { method: "POST", tool: "upload_video", agent, fetchImpl,
31
- body: { type: "video", subject_ref: "tool:video", content_type: ct, label_en: basename(path) } });
34
+ if (size > (kind === "video" ? MAX_UPLOAD_BYTES : 20 * 1024 * 1024))
35
+ throw new Error(`the file is ${(size / 1e6).toFixed(0)} MB — too large`);
36
+ const reg = await apiCall("/assets", { method: "POST", tool: kind === "video" ? "upload_video" : "upload_image", agent, fetchImpl,
37
+ body: { type: kind, subject_ref: `tool:${kind}`, content_type: ct, label_en: basename(path) } });
32
38
  if (!reg?.upload_url || !reg.asset_id)
33
39
  throw new Error("the server did not return an upload URL");
34
40
  const put = await fetchImpl(reg.upload_url, { method: "PUT", headers: { "content-type": ct }, body: readFileSync(path) });
@@ -44,6 +50,12 @@ export function registerOpsTools(server, call, ok, fail, agent) {
44
50
  catch (e) {
45
51
  return fail(e);
46
52
  } });
53
+ server.tool("upload_image", "Upload a local .jpg/.png (≤20 MB) and return its asset_id — e.g. a cover for clips_edit_clip or matrix_update_media.", { path: z.string().describe("absolute path of a local image file") }, async ({ path }) => { try {
54
+ return ok(await uploadFile(path, "image", agent));
55
+ }
56
+ catch (e) {
57
+ return fail(e);
58
+ } });
47
59
  // ---- Clips ----------------------------------------------------------------
48
60
  server.tool("clips_list_jobs", "List your clip jobs (newest first, summary only) and the price: per_min cr per started source minute, min cr per job, max upload minutes.", async () => call("/v1/clips/jobs", "clips_list_jobs"));
49
61
  server.tool("clips_series_episodes", "For a series you own: the finished episodes you can clip, with each episode's length in seconds (to estimate cost: 1 cr per started minute, 3 cr minimum).", { work_id: z.string() }, async ({ work_id }) => call(`/v1/clips/series/${enc(work_id)}`, "clips_series_episodes"));
@@ -62,11 +74,12 @@ export function registerOpsTools(server, call, ok, fail, agent) {
62
74
  }).optional(),
63
75
  }, async (a) => call("/v1/clips/jobs", "clips_create", "POST", a));
64
76
  server.tool("clips_get_job", "One clip job with every clip: start/end (source seconds), title, opening hook line, why it was picked, score, spoiler flag, kept, status, and 1-hour playback URLs. The right tool for polling (every ≥10 s).", { job_id: z.string() }, async ({ job_id }) => call(`/v1/clips/jobs/${enc(job_id)}`, "clips_get_job"));
65
- server.tool("clips_edit_clip", "Edit one clip: kept (keep or drop), title, captions ('pop'|'plain'|'none'), nudge_start / nudge_end (move the cut by whole lines, e.g. -1 or 1). Changing the cut or captions re-renders the clip for free.", {
77
+ server.tool("clips_edit_clip", "Edit one clip: kept (keep or drop), title, captions ('pop'|'plain'|'none'), nudge_start / nudge_end (move the cut by whole lines, e.g. -1 or 1), cover_asset_id (your own cover from upload_image; null = back to the automatic cover). Changing the cut or captions re-renders the clip for free. The cover is used as the IG cover, FB opening frame, TikTok cover frame and YouTube thumbnail.", {
66
78
  job_id: z.string(), clip_id: z.string(),
67
79
  kept: z.boolean().optional(), title: z.string().optional(),
68
80
  captions: z.enum(["pop", "plain", "none"]).optional(),
69
81
  nudge_start: z.number().int().optional(), nudge_end: z.number().int().optional(),
82
+ cover_asset_id: z.string().nullable().optional(),
70
83
  }, async ({ job_id, clip_id, ...body }) => call(`/v1/clips/jobs/${enc(job_id)}/clips/${enc(clip_id)}`, "clips_edit_clip", "PATCH", body));
71
84
  server.tool("clips_retry", "Retry a failed clip job from where it stopped (a job that produced nothing was already refunded and is charged again on retry).", { job_id: z.string() }, async ({ job_id }) => call(`/v1/clips/jobs/${enc(job_id)}/retry`, "clips_retry", "POST", {}));
72
85
  server.tool("clips_send_to_matrix", "Put every kept, finished clip of a job into the Matrix library (optionally under lane_id); sending twice does not duplicate. Then schedule them with matrix_plan_posts / matrix_schedule_posts.", { job_id: z.string(), lane_id: z.string().optional() }, async ({ job_id, lane_id }) => call(`/v1/clips/jobs/${enc(job_id)}/send`, "clips_send_to_matrix", "POST", lane_id ? { lane_id } : {}));
@@ -86,10 +99,15 @@ export function registerOpsTools(server, call, ok, fail, agent) {
86
99
  }, async ({ lane_id, ...body }) => call(`/v1/matrix/lanes/${enc(lane_id)}`, "matrix_update_lane", "PATCH", body));
87
100
  // ---- Matrix:素材与排期 ----------------------------------------------------
88
101
  server.tool("matrix_media", "Your Matrix library (uploads, imported episodes, clips sent from Clips), newest first.", async () => call("/v1/matrix/media", "matrix_media"));
89
- server.tool("matrix_add_media", "Register a video in the Matrix library: {asset_id, title?, hook?, lane_id?} after upload_video, or {work_id, chapter} to import one of your own finished episodes.", {
102
+ server.tool("matrix_add_media", "Register a video in the Matrix library: {asset_id, title?, hook?, lane_id?, cover_asset_id?} after upload_video, or {work_id, chapter} to import one of your own finished episodes.", {
90
103
  asset_id: z.string().optional(), title: z.string().optional(), hook: z.string().optional(), lane_id: z.string().optional(),
104
+ cover_asset_id: z.string().optional(),
91
105
  work_id: z.string().optional(), chapter: z.number().int().optional(),
92
106
  }, async (a) => call("/v1/matrix/media", "matrix_add_media", "POST", a));
107
+ server.tool("matrix_update_media", "Edit a library video: title, hook, lane_id, cover_asset_id (from upload_image; null clears it). The cover goes out with every post of this video: IG cover, FB opening frame, TikTok cover frame, YouTube thumbnail.", {
108
+ media_id: z.string(), title: z.string().optional(), hook: z.string().optional(),
109
+ lane_id: z.string().nullable().optional(), cover_asset_id: z.string().nullable().optional(),
110
+ }, async ({ media_id, ...body }) => call(`/v1/matrix/media/${enc(media_id)}`, "matrix_update_media", "PATCH", body));
93
111
  const scheduleShape = {
94
112
  items: z.array(z.object({
95
113
  media_id: z.string(), account: z.string().optional().describe("'<platform>:<account_id>'"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dawnwood/cli",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Dawnwood for agents — CLI + MCP server. Your agent drives the full short-drama pipeline (bible → scripts → pack → renders) against console.dawnwood.ai.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",