@cliptude/cli 0.1.30 → 0.1.32

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.
@@ -0,0 +1,547 @@
1
+ /* Views shared by the job, review and publish-kit widgets (inlined by cliptude_mcp/apps.py after bridge.js).
2
+ *
3
+ * Views.mount(container, data, ctx) picks the view for one tool result:
4
+ * a 428 review -> review(): settings, warnings, acknowledgements, credits, Confirm / Change something
5
+ * a script or narration -> script(): numbered narration, word count vs the duration's budget, Approve / Ask
6
+ * a job or product job -> progress(): status, progress bar, step; the publish kit inline once it is ready
7
+ * anything else -> result(): job / run / render / avatar id and status, or the error
8
+ * Views.publishKit(container, kit) the publish kit (video, thumbnails, titles, description, chapters, tags)
9
+ *
10
+ * Safety: the only tools/call that spends anything is in confirmReview, which runs from the Confirm button's
11
+ * click handler and checks event.isTrusted. Nothing here confirms a review on its own. */
12
+ var Views = (function () {
13
+ "use strict";
14
+ var h = UI.h;
15
+
16
+ /* ------------------------------------------------------------------ helpers */
17
+ function open(url) { Cliptude.openLink(url).catch(function () { UI.toast("The link could not be opened here."); }); }
18
+
19
+ function selectText(el) {
20
+ try {
21
+ var range = document.createRange(); range.selectNodeContents(el);
22
+ var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range);
23
+ } catch (e) {}
24
+ }
25
+
26
+ /** Clipboard API (clipboardWrite permission), else execCommand, else select the text for the user. */
27
+ function copy(text, el) {
28
+ function fallback() {
29
+ var area = h("textarea", { style: { position: "fixed", opacity: "0", top: "0", left: "0" } });
30
+ area.value = text; document.body.appendChild(area); area.select();
31
+ var ok = false;
32
+ try { ok = document.execCommand("copy"); } catch (e) { ok = false; }
33
+ area.remove();
34
+ if (ok) { UI.toast("Copied."); return; }
35
+ if (el) selectText(el);
36
+ UI.toast("Selected. Press ⌘C or Ctrl+C to copy.");
37
+ }
38
+ if (navigator.clipboard && navigator.clipboard.writeText) {
39
+ navigator.clipboard.writeText(text).then(function () { UI.toast("Copied."); }, fallback);
40
+ } else fallback();
41
+ }
42
+
43
+ function words(text) { return String(text || "").split(/\s+/).filter(Boolean).length; }
44
+ function num(n) { return Number(n || 0).toLocaleString("en-US"); }
45
+ function str(v) {
46
+ if (v === null || v === undefined) return "";
47
+ if (typeof v === "boolean") return v ? "On" : "Off";
48
+ if (Array.isArray(v)) return v.join(", ");
49
+ if (typeof v === "object") return JSON.stringify(v);
50
+ return String(v);
51
+ }
52
+ function section(title, children, extra) {
53
+ return h("section", { class: "sec" }, [
54
+ h("div", { class: "sec-head" }, [h("h2", {}, [title]), extra || null])
55
+ ].concat(children));
56
+ }
57
+
58
+ /* ------------------------------------------------------------------ script */
59
+ // Spoken words for a duration bucket at ~150 words a minute (MCP instructions / cliptude-script skill).
60
+ var WORD_BUDGET = {
61
+ "6-8": [900, 1200], "8-10": [1250, 1540], "10-12": [1550, 1850], "18-20": [2800, 3090],
62
+ "30-40": [4700, 6180], "50-60": [7800, 9270]
63
+ };
64
+ var MIN_WORDS = 880;
65
+
66
+ function budgetLine(count, duration) {
67
+ var range = WORD_BUDGET[String(duration || "")];
68
+ var minutes = count / 150;
69
+ var est = "≈ " + (minutes < 10 ? minutes.toFixed(1) : Math.round(minutes)) + " min spoken";
70
+ if (!range) {
71
+ return { text: num(count) + " words · " + est + (count < MIN_WORDS ? " · under the " + MIN_WORDS + "-word minimum" : ""),
72
+ kind: count < MIN_WORDS ? "warn" : "" };
73
+ }
74
+ var kind = count < range[0] || count > range[1] ? "warn" : "ok";
75
+ var verdict = count < range[0] ? "short for " : count > range[1] ? "long for " : "fits ";
76
+ return { text: num(count) + " words · " + est + " · " + verdict + duration + " min (" + num(range[0]) + "–" + num(range[1]) + ")", kind: kind };
77
+ }
78
+
79
+ /** data: {script, duration, title} or a narration {sentences:[{id,text,start,end}], duration_s}. */
80
+ function script(container, data, ctx) {
81
+ var sentences = Array.isArray(data.sentences) ? data.sentences : null;
82
+ var text = sentences ? sentences.map(function (s) { return s.text || ""; }).join(" ") : String(data.script || "");
83
+ var count = words(text);
84
+ var isNarration = !!sentences;
85
+ var body = h("div", { class: "script", tabindex: "0" });
86
+ if (isNarration) {
87
+ sentences.forEach(function (s, i) {
88
+ body.appendChild(h("p", { class: "sentence" }, [
89
+ h("span", { class: "num", "aria-label": "Sentence " + (s.id !== undefined ? s.id : i) }, [String(s.id !== undefined ? s.id : i)]),
90
+ h("span", {}, [s.text || ""])
91
+ ]));
92
+ });
93
+ } else {
94
+ text.split(/\n\s*\n/).map(function (p) { return p.trim(); }).filter(Boolean).forEach(function (p) {
95
+ body.appendChild(h("p", {}, [p]));
96
+ });
97
+ }
98
+ var facts = [];
99
+ if (isNarration) {
100
+ facts.push(h("span", { class: "chip" }, [num(count) + " words"]));
101
+ facts.push(h("span", { class: "chip" }, [sentences.length + " sentences"]));
102
+ if (data.duration_s) facts.push(h("span", { class: "chip" }, [Math.floor(data.duration_s / 60) + ":" + String(Math.round(data.duration_s % 60)).padStart(2, "0") + " voiced"]));
103
+ } else {
104
+ var b = budgetLine(count, data.duration);
105
+ facts.push(h("span", { class: "chip " + (b.kind === "warn" ? "warn" : b.kind === "ok" ? "ok" : "") }, [b.text]));
106
+ }
107
+ var noun = isNarration ? "narration" : "script";
108
+ var changes = h("div", { class: "changes", hidden: true }, [
109
+ h("label", { class: "sr-only", for: "changes-text" }, ["What should change?"]),
110
+ h("textarea", { id: "changes-text", rows: "3", placeholder: "What should change? (a fact, the opening, the length…)" }),
111
+ h("div", { class: "toolbar" }, [h("button", { type: "button", class: "primary", onclick: function () {
112
+ var asked = (document.getElementById("changes-text").value || "").trim();
113
+ UI.choose(asked ? "Please change the " + noun + ": " + asked
114
+ : "I want changes to the " + noun + ". Ask me what to change.", { approved: false });
115
+ } }, ["Send"])])
116
+ ]);
117
+ UI.clear(container);
118
+ container.appendChild(h("div", { class: "head" }, [
119
+ h("h1", {}, [(isNarration ? "Narration" : "Script") + (data.title ? " · " + data.title : "")]),
120
+ h("span", { class: "chips" }, facts)
121
+ ]));
122
+ if (data.warning) container.appendChild(h("div", { class: "callout warn", role: "note" }, [data.warning]));
123
+ container.appendChild(body);
124
+ container.appendChild(changes);
125
+ container.appendChild(h("div", { class: "selection" }, [
126
+ h("span", { class: "toolbar" }, [
127
+ h("button", { type: "button", onclick: function () { copy(isNarration ? sentences.map(function (s) { return s.text; }).join("\n") : text, body); } }, ["Copy"]),
128
+ h("button", { type: "button", onclick: function () { changes.hidden = !changes.hidden; if (!changes.hidden) changes.querySelector("textarea").focus(); } }, ["Ask for changes"])
129
+ ]),
130
+ h("button", { type: "button", class: "primary", onclick: function () {
131
+ UI.choose("I approve this " + noun + ".", { approved: true, job_id: data.id || data.job_id || "" });
132
+ } }, ["Approve " + noun])
133
+ ]));
134
+ }
135
+
136
+ /* ------------------------------------------------------------------ publish kit */
137
+ function publishKit(container, kit, opts) {
138
+ opts = opts || {};
139
+ var current = kit.video && kit.video.url ? -1 : 0; // -1 is the video; 0..n-1 a thumbnail
140
+
141
+ function stageSection(items, status, video) {
142
+ var hasVideo = !!(video && video.url);
143
+ if (!hasVideo && current < 0) current = 0;
144
+ if (!items.length && !hasVideo) {
145
+ return section("Video and thumbnails", [h("div", { class: "status" }, [video && video.note ? video.note :
146
+ status && status !== "completed" ? "Thumbnails are " + status.replace(/_/g, " ") + "." : "No video or thumbnails yet."])]);
147
+ }
148
+ var showVideo = hasVideo && current < 0;
149
+ var item = showVideo ? null : (items[current] || items[0]);
150
+ var poster = items.length ? items[0].url : "";
151
+ var stage = showVideo
152
+ ? h("video", { class: "stage-video", src: video.url, poster: poster, controls: "", playsinline: "", preload: "metadata",
153
+ "aria-label": "The finished video" })
154
+ : h("img", { class: "big", src: item.url, alt: (item.label || "Thumbnail") + " preview" });
155
+ var strip = h("div", { class: "thumbs", role: "list" });
156
+ if (hasVideo) {
157
+ strip.appendChild(h("button", { type: "button", class: "card", role: "listitem", "aria-pressed": String(showVideo),
158
+ "aria-label": "Play the video", onclick: function () { current = -1; render(); } },
159
+ [h("span", { class: "thumb-wrap" }, [UI.img(poster, "", "▶"), h("span", { class: "play", "aria-hidden": "true" }, ["▶"])]),
160
+ h("span", { class: "body" }, [h("span", { class: "name" }, ["Video"])])]));
161
+ }
162
+ items.forEach(function (t, i) {
163
+ strip.appendChild(h("button", { type: "button", class: "card", role: "listitem", "aria-pressed": String(!showVideo && i === current),
164
+ "aria-label": "Show " + (t.label || "thumbnail " + (i + 1)), onclick: function () { current = i; render(); } },
165
+ [UI.img(t.url, "", String(i + 1)), h("span", { class: "body" }, [h("span", { class: "name" }, [t.label || "Thumbnail " + (i + 1)])])]));
166
+ });
167
+ var tools = showVideo
168
+ ? [h("button", { type: "button", onclick: function () { open(video.url); } }, ["Open video"])]
169
+ : [h("button", { type: "button", onclick: function () { open(item.url); } }, ["Open full size"]),
170
+ h("button", { type: "button", onclick: function () {
171
+ UI.choose("I will use “" + (item.label || "this thumbnail") + "” as the thumbnail: " + item.url, { thumbnail_url: item.url });
172
+ } }, ["Use this thumbnail"])];
173
+ var children = [stage];
174
+ if (!hasVideo && video && video.note) children.push(h("div", { class: "status" }, [video.note]));
175
+ children.push(strip);
176
+ return section(showVideo ? "Video" : "Thumbnails (" + items.length + ")", children, h("span", { class: "toolbar" }, tools));
177
+ }
178
+
179
+ function titlesSection(titles) {
180
+ if (!titles.length) return null;
181
+ var list = h("div", { class: "list", role: "list" });
182
+ titles.forEach(function (t) {
183
+ list.appendChild(h("div", { class: "row title-row", role: "listitem" }, [
184
+ h("div", { class: "main" }, [h("span", { class: "name" }, [t])]),
185
+ h("button", { type: "button", "aria-label": "Copy title: " + t, onclick: function () { copy(t); } }, ["Copy"]),
186
+ h("button", { type: "button", onclick: function () { UI.choose("Use this title for the video: “" + t + "”", { title: t }); } }, ["Use"])
187
+ ]));
188
+ });
189
+ return section("Title ideas", [list]);
190
+ }
191
+
192
+ function textSection(title, text) {
193
+ if (!text) return null;
194
+ var pre = h("pre", { class: "copy", tabindex: "0" }, [text]);
195
+ return section(title, [pre], h("button", { type: "button", onclick: function () { copy(text, pre); } }, ["Copy " + title.toLowerCase()]));
196
+ }
197
+
198
+ function tagsSection(tags) {
199
+ if (!tags.length) return null;
200
+ var box = h("div", { class: "chips", role: "list" });
201
+ tags.forEach(function (t) { box.appendChild(h("span", { class: "chip tag", role: "listitem" }, [t])); });
202
+ return section("Tags (" + tags.length + ")", [box], h("button", { type: "button", onclick: function () { copy(tags.join(", "), box); } }, ["Copy all tags"]));
203
+ }
204
+
205
+ function render() {
206
+ var meta = kit.publish_metadata || {};
207
+ var thumbs = (kit.thumbnails && kit.thumbnails.items) || [];
208
+ var tags = meta.tags || [];
209
+ var description = String(meta.description || "");
210
+ if (tags.length) {
211
+ // The generated description ends with its tags line; show it once, as chips.
212
+ var line = tags.join(", ").toLowerCase();
213
+ description = description.split(/\n\s*\n/).filter(function (p) {
214
+ var flat = p.split(",").map(function (x) { return x.trim().replace(/^#/, "").toLowerCase(); }).filter(Boolean);
215
+ return !(flat.length >= 5 && flat.every(function (x) { return line.indexOf(x) >= 0; }));
216
+ }).join("\n\n");
217
+ }
218
+ var downloads = meta.downloads || {};
219
+ UI.clear(container);
220
+ [stageSection(thumbs, kit.thumbnails && kit.thumbnails.status, kit.video),
221
+ titlesSection(meta.title_variants || []),
222
+ textSection("Description", description.trim()),
223
+ textSection("Chapters", meta.chapters || ""),
224
+ tagsSection(tags),
225
+ downloads.voiceover_url || downloads.project_zip_url ? section("Downloads", [h("div", { class: "toolbar" }, [
226
+ downloads.voiceover_url ? h("button", { type: "button", onclick: function () { open(downloads.voiceover_url); } }, ["Voiceover"]) : null,
227
+ downloads.project_zip_url ? h("button", { type: "button", onclick: function () { open(downloads.project_zip_url); } }, ["Project files"]) : null
228
+ ])]) : null
229
+ ].forEach(function (s) { if (s) container.appendChild(s); });
230
+ if (!container.childNodes.length) UI.status(container, "Nothing to publish yet.");
231
+ }
232
+ render();
233
+ }
234
+
235
+ /* ------------------------------------------------------------------ review */
236
+ var TOOL_LABELS = {
237
+ create_job: "Create the video", create_plan_job: "Start the agent-planned video", create_script: "Write the script",
238
+ create_voiceover: "Make the narration audio", continue_job: "Build the full video",
239
+ render_product_video: "Build the product video", draft_product_script: "Draft the product video",
240
+ run_agent: "Edit with Cliptude Agent", render_project: "Export the edited video", create_avatar: "Create the avatar"
241
+ };
242
+ var ACK_TOOLS = { create_job: 1, create_plan_job: 1, create_script: 1, create_voiceover: 1, draft_product_script: 1 };
243
+ var OUTPUT_TOOLS = { "Script only": "create_script", "Narration audio only": "create_voiceover" };
244
+
245
+ function isReview(data) {
246
+ var detail = data && data.detail;
247
+ return !!(data && data.status === 428 && detail && typeof detail === "object" && detail.review && detail.review_token);
248
+ }
249
+
250
+ /** Which tool returned this review: the server's tag, the host's tool info, else the review's own words. */
251
+ function reviewTool(data) {
252
+ var review = data.detail.review || {};
253
+ var info = Cliptude.state.hostContext && Cliptude.state.hostContext.toolInfo;
254
+ if (data.tool && TOOL_LABELS[data.tool]) return data.tool;
255
+ if (info && info.tool && TOOL_LABELS[info.tool.name]) return info.tool.name;
256
+ if (review.action && TOOL_LABELS[review.action]) return review.action;
257
+ var output = (review.settings || []).filter(function (s) { return s.label === "Output"; })[0];
258
+ if (output) {
259
+ if (OUTPUT_TOOLS[output.value]) return OUTPUT_TOOLS[output.value];
260
+ if (/Agent-planned/.test(output.value)) return "create_plan_job";
261
+ return "create_job";
262
+ }
263
+ return "";
264
+ }
265
+
266
+ function reviewSummary(review, tool) {
267
+ if (review.summary) return review.summary;
268
+ var get = function (label) {
269
+ var row = (review.settings || []).filter(function (s) { return s.label === label; })[0];
270
+ return row ? str(row.value) : "";
271
+ };
272
+ var title = get("Title") || get("Avatar name");
273
+ var output = get("Output");
274
+ return (TOOL_LABELS[tool] || "Go ahead") + (output ? ": " + output : "") + (title ? " — “" + title + "”" : "") + ".";
275
+ }
276
+
277
+ function creditsBox(credits) {
278
+ if (!credits || typeof credits !== "object") return null;
279
+ var rows = [];
280
+ function add(label, value, cls) {
281
+ if (value === undefined || value === null || value === "") return;
282
+ rows.push(h("div", { class: "credit " + (cls || "") }, [h("span", { class: "k" }, [label]), h("span", { class: "v" }, [typeof value === "number" ? num(value) : String(value)])]));
283
+ }
284
+ add("Credits required", credits.credits_required, "lead");
285
+ add("Held while building", credits.credits_held_while_building);
286
+ add("Already paid", credits.credits_already_paid);
287
+ add("Full video price", credits.full_video_price);
288
+ add("Available", credits.credits_available);
289
+ var enough = credits.enough_credits;
290
+ return h("div", { class: "credits" }, rows.concat(enough === undefined ? [] : [
291
+ h("span", { class: "chip " + (enough ? "ok" : "warn") }, [enough ? "Enough credits" : "Not enough credits"])
292
+ ]));
293
+ }
294
+
295
+ function review(container, data, ctx) {
296
+ var detail = data.detail;
297
+ var rev = detail.review || {};
298
+ var tool = reviewTool(data);
299
+ var acks = rev.acknowledgements_required || [];
300
+ var missing = detail.missing || [];
301
+ var summary = reviewSummary(rev, tool);
302
+ var state = { busy: false };
303
+
304
+ UI.clear(container);
305
+ container.appendChild(h("div", { class: "head" }, [
306
+ h("h1", {}, ["Review: " + (TOOL_LABELS[tool] || "confirm before Cliptude spends credits")]),
307
+ h("span", { class: "chip info" }, ["Nothing happens until you confirm"])
308
+ ]));
309
+ container.appendChild(h("p", { class: "summary" }, [summary]));
310
+ var out = h("div", { id: "outcome" }); // the result of the confirmed call shows here, at the top
311
+ container.appendChild(out);
312
+ var credits = creditsBox(rev.credits);
313
+ if (credits) container.appendChild(credits);
314
+
315
+ (rev.warnings || []).forEach(function (w) {
316
+ container.appendChild(h("div", { class: "callout warn", role: "note" }, [str(w)]));
317
+ });
318
+
319
+ var boxes = [];
320
+ if (acks.length) {
321
+ var list = h("div", { class: "list" });
322
+ acks.forEach(function (a) {
323
+ var id = "ack-" + a.id;
324
+ var box = h("input", { type: "checkbox", id: id, value: a.id, onchange: sync });
325
+ boxes.push(box);
326
+ list.appendChild(h("label", { class: "row ack" + (missing.indexOf(a.id) >= 0 ? " missing" : ""), for: id }, [
327
+ box,
328
+ h("span", { class: "main" }, [
329
+ h("span", { class: "name" }, ["I accept: " + a.id.replace(/_/g, " ")]),
330
+ h("span", { class: "desc full" }, [a.message || ""])
331
+ ])
332
+ ]));
333
+ });
334
+ container.appendChild(section("Approve each of these to go on", [list]));
335
+ }
336
+
337
+ var table = h("dl", { class: "settings" });
338
+ (rev.settings || []).forEach(function (s) {
339
+ table.appendChild(h("dt", {}, [s.label || ""]));
340
+ var value = str(s.value);
341
+ table.appendChild(h("dd", { class: s.on === false || value === "Off" ? "off" : "" }, [value]));
342
+ });
343
+ container.appendChild(section("Every setting", [table]));
344
+
345
+ var confirm = h("button", { type: "button", class: "primary", id: "confirm" }, ["Confirm"]);
346
+ var change = h("button", { type: "button", onclick: function () {
347
+ UI.choose("I want to change something before this runs: " + summary + " Ask me what to change.", { confirmed: false });
348
+ } }, ["Change something"]);
349
+ var note = h("span", { class: "what" }, [""]);
350
+ container.appendChild(h("div", { class: "selection" }, [note, h("span", { class: "toolbar" }, [change, confirm])]));
351
+
352
+ function chosen() { return boxes.filter(function (b) { return b.checked; }).map(function (b) { return b.value; }); }
353
+ function sync() {
354
+ var left = boxes.length - chosen().length;
355
+ confirm.disabled = state.busy || left > 0;
356
+ note.textContent = left > 0 ? "Tick " + left + " more to confirm." :
357
+ rev.credits && rev.credits.enough_credits === false ? "Not enough credits: confirming will be refused." : "";
358
+ }
359
+ sync();
360
+
361
+ // The only place a widget resends a reviewed call. A real click only; never on load or from data.
362
+ confirm.addEventListener("click", function (event) { confirmReview(event); });
363
+ function confirmReview(event) {
364
+ if (!event || !event.isTrusted || state.busy || confirm.disabled) return;
365
+ var ids = chosen();
366
+ var input = ctx.input();
367
+ if (Cliptude.canCallTools() && tool && input) {
368
+ state.busy = true; sync();
369
+ confirm.textContent = "Confirming…";
370
+ var args = {};
371
+ Object.keys(input).forEach(function (k) { if (k !== "review_token" && k !== "acknowledge") args[k] = input[k]; });
372
+ args.review_token = detail.review_token;
373
+ if (ACK_TOOLS[tool] && ids.length) args.acknowledge = ids;
374
+ Cliptude.callTool(tool, args).then(function (res) {
375
+ if (isReview(res)) { mount(container, res, ctx); UI.toast("The review changed: check it again."); return; }
376
+ result(out, res, tool);
377
+ try { out.scrollIntoView({ block: "nearest" }); } catch (e) {}
378
+ confirm.textContent = UI.errorText(res) ? "Confirm" : "Confirmed";
379
+ if (UI.errorText(res)) { state.busy = false; sync(); return; }
380
+ note.textContent = "Confirmed: " + resultLine(res, tool);
381
+ UI.choose("I confirmed in the review: " + summary + " Result: " + resultLine(res, tool), { confirmed: true });
382
+ }).catch(function () {
383
+ state.busy = false; confirm.textContent = "Confirm"; sync();
384
+ sendConfirm(ids);
385
+ });
386
+ } else {
387
+ sendConfirm(ids);
388
+ }
389
+ }
390
+ function sendConfirm(ids) {
391
+ UI.choose("I confirm: " + summary + " review_token=" + detail.review_token +
392
+ (ids.length ? " acknowledge=" + ids.join(",") : ""), { confirmed: true, review_token: detail.review_token, acknowledge: ids });
393
+ }
394
+ }
395
+
396
+ /* ------------------------------------------------------------------ result card */
397
+ var NEXT = {
398
+ create_job: "Claude checks it with get_job; each check updates the card.",
399
+ create_script: "Claude checks it with get_job; the script shows here to approve when it is written.",
400
+ create_voiceover: "Claude checks it with get_job until the narration is ready.",
401
+ create_plan_job: "Cliptude voices the narration; then Claude plans every visual.",
402
+ continue_job: "Claude checks it with get_job; each check updates the card.",
403
+ render_product_video: "Cliptude builds the video; Claude checks it with get_product_video_status.",
404
+ draft_product_script: "Claude checks it with get_product_video_status.",
405
+ run_agent: "Cliptude Agent is editing; Claude follows it with get_agent_run.",
406
+ render_project: "The export is rendering; Claude checks it with get_render.",
407
+ create_avatar: "HeyGen finishes the avatar in a few minutes; it then shows under your avatars."
408
+ };
409
+
410
+ function pick(data) {
411
+ var inner = data.run || data.render || data.avatar || data.job || data;
412
+ return {
413
+ id: String(data.id || data.job_id || inner.id || ""),
414
+ status: String(inner.status || data.status || data.stage || ""),
415
+ title: String(data.title || inner.title || inner.name || ""),
416
+ kind: data.run ? "Agent run" : data.render ? "Export" : data.avatar ? "Avatar" : "Job"
417
+ };
418
+ }
419
+ function resultLine(data, tool) {
420
+ var p = pick(data || {});
421
+ return p.kind + (p.id ? " " + p.id : "") + (p.status ? " is " + p.status.replace(/_/g, " ") : "") + ".";
422
+ }
423
+
424
+ function result(container, data, tool) {
425
+ UI.clear(container);
426
+ var err = UI.errorText(data);
427
+ if (err) {
428
+ var detail = (data && data.detail) || {};
429
+ container.appendChild(h("div", { class: "status error", role: "alert" }, [err]));
430
+ if (detail.billing_url) container.appendChild(h("div", { class: "toolbar" }, [
431
+ h("button", { type: "button", class: "primary", onclick: function () { open(detail.billing_url); } }, ["Add credits"])
432
+ ]));
433
+ return;
434
+ }
435
+ var p = pick(data);
436
+ var chips = [h("span", { class: "chip info" }, [p.status ? p.status.replace(/_/g, " ") : "started"])];
437
+ if (data.estimated_minutes) chips.push(h("span", { class: "chip" }, ["≈ " + data.estimated_minutes + " min"]));
438
+ if (data.credits_reserved) chips.push(h("span", { class: "chip" }, [num(data.credits_reserved) + " credits held"]));
439
+ container.appendChild(h("div", { class: "row result" }, [
440
+ h("div", { class: "main" }, [
441
+ h("span", { class: "name" }, [p.title || p.kind]),
442
+ p.id ? h("span", { class: "muted" }, [p.kind + " " + p.id]) : null,
443
+ h("span", { class: "chips" }, chips),
444
+ NEXT[tool] ? h("span", { class: "desc full" }, [NEXT[tool]]) : null
445
+ ]),
446
+ data.editor_url ? h("button", { type: "button", onclick: function () { open(data.editor_url); } }, ["Open editor"]) : null
447
+ ]));
448
+ }
449
+
450
+ /* ------------------------------------------------------------------ progress */
451
+ var STATUS_LABELS = {
452
+ "not-started": "Not started", saved: "Saved", pending: "Pending", queued: "Queued", running: "Working",
453
+ awaiting_project: "Waiting for the project", ready_for_edit: "Ready to review", plan_ready: "Plan ready",
454
+ completed: "Completed", failed: "Failed", revoked: "Cancelled",
455
+ script_drafting: "Writing the script", script_ready: "Script ready", voicing: "Voicing the narration",
456
+ producing: "Building the video", ready_for_review: "Ready to review", rendered: "Rendered", cancelled: "Cancelled"
457
+ };
458
+ var kitLoaded = {};
459
+
460
+ function isReady(job) {
461
+ var stage = job.stage || "";
462
+ if (stage) return stage === "ready_for_review" || stage === "rendered";
463
+ var kind = job.output_kind || "video";
464
+ return (job.status === "ready_for_edit" || job.status === "completed") && (kind === "video" || kind === "plan");
465
+ }
466
+
467
+ function progress(container, job) {
468
+ var id = String(job.id || job.job_id || "");
469
+ var stage = job.stage || job.status || "";
470
+ var label = STATUS_LABELS[stage] || String(stage).replace(/_/g, " ");
471
+ var pct = Math.max(0, Math.min(100, Number(job.progress || 0)));
472
+ var failed = stage === "failed" || job.status === "failed";
473
+ var ready = isReady(job);
474
+ var done = ready || failed || job.status === "completed" || stage === "plan_ready" || stage === "script_ready";
475
+ if (ready) pct = 100;
476
+
477
+ UI.clear(container);
478
+ container.appendChild(h("div", { class: "head" }, [
479
+ h("h1", {}, [job.title || (job.product && job.product.title) || "Video job"]),
480
+ h("span", { class: "chip " + (failed ? "warn" : ready ? "ok" : "info") }, [label])
481
+ ]));
482
+ if (!failed) {
483
+ container.appendChild(h("div", { class: "bar", role: "progressbar", "aria-valuemin": "0", "aria-valuemax": "100",
484
+ "aria-valuenow": String(Math.round(pct)), "aria-label": "Progress" }, [h("span", { style: { width: pct + "%" } })]));
485
+ }
486
+ var facts = [];
487
+ if (!done && job.current_step) facts.push(h("span", {}, [String(job.current_step)]));
488
+ if (!done) facts.push(h("span", { class: "muted" }, [Math.round(pct) + "%"]));
489
+ if (job.estimated_minutes && !done) facts.push(h("span", { class: "muted" }, ["≈ " + job.estimated_minutes + " min"]));
490
+ if (job.duration) facts.push(h("span", { class: "muted" }, [job.duration + " min video"]));
491
+ if (id) facts.push(h("span", { class: "muted" }, ["Job " + id.slice(0, 8)]));
492
+ container.appendChild(h("div", { class: "facts" }, facts));
493
+ if (failed) container.appendChild(h("div", { class: "status error", role: "alert" }, [String(job.error || job.current_step || "The job failed.")]));
494
+ if (job.warning) container.appendChild(h("div", { class: "callout warn", role: "note" }, [job.warning]));
495
+ if (!done) container.appendChild(h("p", { class: "muted" }, ["Claude checks on the job every so often; each check shows the latest here."]));
496
+
497
+ var voice = job.voiceover && job.voiceover.url;
498
+ if (voice) container.appendChild(section("Narration audio", [h("audio", { src: voice, controls: "", preload: "none", class: "audio" })]));
499
+ if (stage === "plan_ready") container.appendChild(h("p", { class: "summary" }, ["The narration is voiced. Claude plans every visual next, then builds the video."]));
500
+
501
+ if (!ready || !id) return;
502
+ var kitBox = h("div", { class: "kit" });
503
+ container.appendChild(kitBox);
504
+ function showKitButton() {
505
+ UI.clear(kitBox).appendChild(h("div", { class: "toolbar" }, [
506
+ job.editor_url ? h("button", { type: "button", onclick: function () { open(job.editor_url); } }, ["Open editor"]) : null,
507
+ h("button", { type: "button", class: "primary", onclick: function () {
508
+ UI.choose("Show the publish kit for job " + id + ".", { job_id: id });
509
+ } }, ["Show publish kit"])
510
+ ]));
511
+ }
512
+ if (!Cliptude.canCallTools()) { showKitButton(); return; }
513
+ // Ready: fetch the publish kit once (free, read-mostly: it opens the editor project) and show it here.
514
+ UI.status(kitBox, "Loading the publish kit…");
515
+ var pending = kitLoaded[id] || (kitLoaded[id] = Cliptude.callTool("show_publish_kit", { job_id: id }));
516
+ pending.then(function (kit) {
517
+ if (!kit || UI.errorText(kit)) { showKitButton(); return; }
518
+ publishKit(kitBox, kit);
519
+ }).catch(showKitButton);
520
+ }
521
+
522
+ /* ------------------------------------------------------------------ dispatch */
523
+ function isScript(data) {
524
+ if (Array.isArray(data.sentences) && data.sentences.length && typeof data.sentences[0] === "object") return true;
525
+ if (typeof data.script !== "string" || !data.script.trim()) return false;
526
+ if (data.stage) return data.stage === "script_ready";
527
+ return (data.output_kind === "script" && data.status === "completed") || !data.status;
528
+ }
529
+
530
+ function mount(container, data, ctx) {
531
+ ctx = ctx || { input: function () { return null; } };
532
+ if (isReview(data)) { review(container, data, ctx); return "review"; }
533
+ var err = UI.errorText(data);
534
+ var info = Cliptude.state.hostContext && Cliptude.state.hostContext.toolInfo;
535
+ ctx.tool = ctx.tool || data.tool || (info && info.tool && info.tool.name) || "";
536
+ // A failed job carries its error too (status "failed"); API errors have a numeric status or none.
537
+ var isJob = typeof data.status === "string" && (data.id || data.job_id);
538
+ if (err && !isJob) { result(container, data, ctx.tool); return "error"; }
539
+ if (isScript(data)) { script(container, data, ctx); return "script"; }
540
+ if (ctx.mode === "job") { progress(container, data); return "progress"; }
541
+ result(container, data, ctx.tool);
542
+ return "result";
543
+ }
544
+
545
+ return { mount: mount, review: review, script: script, progress: progress, result: result, publishKit: publishKit,
546
+ copy: copy, isReview: isReview, budgetLine: budgetLine };
547
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cliptude/cli",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Cliptude CLI — generate videos from saved templates.",
5
5
  "homepage": "https://github.com/cliptude/cliptude#readme",
6
6
  "bin": {
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cliptude-mcp"
7
- version = "0.1.30"
7
+ version = "0.1.32"
8
8
  description = "Cliptude jobs CLI and MCP server (thin client of /api/v1)."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"