@pixeldojo/mcp 0.18.0 → 0.19.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/dist/index.cjs CHANGED
@@ -595,7 +595,7 @@ var init_generate = __esm({
595
595
  DRAFT_DESCRIPTION = "Seedance 2.5 draft mode: render a cheap 480p draft (runs on seedance-2-5) so the user can try takes before paying for full resolution. The reply gives the draft's job id and duration; pass them to upgrade_draft to render that exact take at 1080p.";
596
596
  UPGRADE_DESCRIPTION = "Job id of a finished Seedance 2.5 draft to render at 1080p, the same take with full detail. Also pass `duration` equal to the draft's (the draft reply states it). The draft's prompt and media are reused, so prompt and references are ignored. Billed as a 1080p run.";
597
597
  InputSchema = zod.z.object({
598
- prompt: zod.z.string().min(1).max(8e3).describe("Prompt describing what to generate."),
598
+ prompt: zod.z.string().min(1).max(8e3).describe('Prompt describing what to generate. Write @Name to use a character or element the user saved in Character Studio ("@Mara on a beach"): its photos are attached automatically on models that take reference images. pixeldojo_library source=characters lists them.'),
599
599
  model: zod.z.string().optional().describe(
600
600
  `Model apiId. Recommended (the models the PixelDojo studios use): "seedream-5" for images (the default), "seedance-2-5" for video (prompt only or a starting image), "wan-3-0-video" for video the others refuse. Use another model only when the user names one. Full catalog: https://pixeldojo.ai/api/v1/models; one model's fields: https://pixeldojo.ai/llm/{apiId}.txt. Omit for seedream-5, which makes still images only; name a video model to get a video.`
601
601
  ),
@@ -635,7 +635,7 @@ var init_generate = __esm({
635
635
  InputJsonSchema = {
636
636
  type: "object",
637
637
  properties: {
638
- prompt: { type: "string", description: "Prompt describing what to generate." },
638
+ prompt: { type: "string", description: 'Prompt describing what to generate. Write @Name to use a character or element the user saved in Character Studio ("@Mara on a beach"): its photos are attached automatically on models that take reference images. pixeldojo_library source=characters lists them.' },
639
639
  model: {
640
640
  type: "string",
641
641
  description: `Model apiId. Recommended (the models the PixelDojo studios use): "seedream-5" for images (the default), "seedance-2-5" for video (prompt only or a starting image), "wan-3-0-video" for video the others refuse. Use another model only when the user names one. Full catalog: https://pixeldojo.ai/api/v1/models; one model's fields: https://pixeldojo.ai/llm/{apiId}.txt. Omit for seedream-5, which makes still images only; name a video model to get a video.`
@@ -849,7 +849,7 @@ var init_edit = __esm({
849
849
  InputJsonSchema2 = {
850
850
  type: "object",
851
851
  properties: {
852
- prompt: { type: "string", description: "Edit instruction." },
852
+ prompt: { type: "string", description: 'Edit instruction. Write @Name to use a character or element the user saved in Character Studio ("@Mara on a beach"): its photos are attached automatically on models that take reference images. pixeldojo_library source=characters lists them.' },
853
853
  image_url: {
854
854
  type: "string",
855
855
  format: "uri",
@@ -1455,6 +1455,13 @@ async function filmApi(ctx, method, path, body) {
1455
1455
  const data = await res.json().catch(() => ({}));
1456
1456
  return { status: res.status, data };
1457
1457
  }
1458
+ function keepGoing(filmId, afterSec, extra = {}) {
1459
+ const set = Object.fromEntries(Object.entries(extra).filter(([, v]) => v !== void 0));
1460
+ return { input: { film_id: filmId, action: "status", ...set }, afterSec };
1461
+ }
1462
+ function shotLabels(f) {
1463
+ return new Map(f.scenes.flatMap((s, si) => s.shots.map((sh, i) => [sh.id, `${si + 1}.${i + 1}`])));
1464
+ }
1458
1465
  async function applyCast(ctx, filmId, cast) {
1459
1466
  let charged = false;
1460
1467
  const lines = await Promise.all(cast.map(async (c) => {
@@ -1574,12 +1581,13 @@ async function plan(input, ctx) {
1574
1581
  const castStarted = Date.now();
1575
1582
  const cast = input.cast?.length ? await applyCast(ctx, id, input.cast) : { lines: [], charged: false };
1576
1583
  const pollBudget = Math.max(0, PLANNER_MAX_POLLS - Math.ceil((Date.now() - castStarted) / PLANNER_POLL_MS));
1577
- const reply = (text) => ({
1584
+ const reply = (text, followUp) => ({
1578
1585
  kind: "text",
1579
1586
  text: [
1580
1587
  ...cast.lines,
1581
1588
  cast.charged ? text.replace(/Nothing has been charged( yet)?\./g, "Only the cast portraits above have been charged.") : text
1582
- ].join("\n")
1589
+ ].join("\n"),
1590
+ ...followUp ? { followUp } : {}
1583
1591
  });
1584
1592
  let planned;
1585
1593
  if (music) {
@@ -1590,14 +1598,14 @@ ${input.lyrics.trim()}` : ""].filter(Boolean).join("\n\n");
1590
1598
  let script = input.script?.trim() ?? "";
1591
1599
  if (!script) {
1592
1600
  const wrote = await runPlanner(ctx, id, `/api/films/${id}/script`, { idea: input.idea.trim() }, pollBudget);
1593
- if ("pending" in wrote) return reply(stillPlanningText(id, "script"));
1601
+ if ("pending" in wrote) return reply(stillPlanningText(id, "script"), keepGoing(id, 30, { soundtrack: input.soundtrack }));
1594
1602
  if ("error" in wrote) return reply(`Script writing failed: ${wrote.error}`);
1595
1603
  script = wrote.film.script ?? "";
1596
1604
  if (!script) return reply("Script writing failed: the studio returned an empty script.");
1597
1605
  }
1598
1606
  planned = await runPlanner(ctx, id, `/api/films/${id}/plan`, { script });
1599
1607
  }
1600
- if ("pending" in planned) return reply(stillPlanningText(id));
1608
+ if ("pending" in planned) return reply(stillPlanningText(id), keepGoing(id, 30, { soundtrack: input.soundtrack }));
1601
1609
  if ("error" in planned) return reply(`Shot planning failed: ${planned.error}`);
1602
1610
  const film = planned.film;
1603
1611
  if (needsSlice(film)) {
@@ -1610,17 +1618,17 @@ ${err} Call action "status" to retry the cut.`);
1610
1618
  return reply([plannedText(film, ctx), uncast.length ? `
1611
1619
  ${castNeededText(id, uncast)}` : ""].filter(Boolean).join("\n"));
1612
1620
  }
1613
- async function resumePlanning(film, ctx) {
1621
+ async function resumePlanning(film, ctx, soundtrack) {
1614
1622
  if (film.scenes.length > 0 && film.llmJob?.status !== "running") return null;
1615
1623
  if (film.llmJob?.status === "running") {
1616
- return { kind: "text", text: stillPlanningText(film.id, film.llmJob.kind === "script" ? "script" : "plan") };
1624
+ return { kind: "text", text: stillPlanningText(film.id, film.llmJob.kind === "script" ? "script" : "plan"), followUp: keepGoing(film.id, 30, { soundtrack }) };
1617
1625
  }
1618
1626
  const prior = film.llmJob?.status === "error" ? `The last planning run failed (${film.llmJob.error ?? "unknown"}). ` : "";
1619
1627
  if (!film.script?.trim()) {
1620
1628
  return { kind: "text", text: `${prior}This film has nothing to plan from. Start a new one with action "plan".` };
1621
1629
  }
1622
1630
  const planned = await runPlanner(ctx, film.id, `/api/films/${film.id}/plan`, { script: film.script }, 0);
1623
- if ("pending" in planned) return { kind: "text", text: `${prior}${stillPlanningText(film.id)}` };
1631
+ if ("pending" in planned) return { kind: "text", text: `${prior}${stillPlanningText(film.id)}`, followUp: keepGoing(film.id, 30, { soundtrack }) };
1624
1632
  if ("error" in planned) return { kind: "text", text: `Shot planning failed: ${planned.error} Call action "status" to retry.` };
1625
1633
  if (needsSlice(planned.film)) {
1626
1634
  const err = await sliceSong(ctx, planned.film);
@@ -1630,22 +1638,30 @@ ${err} Call action "status" to retry the cut.` };
1630
1638
  }
1631
1639
  return { kind: "text", text: plannedText(planned.film, ctx) };
1632
1640
  }
1633
- async function produce(filmId, ctx) {
1641
+ async function produce(filmId, soundtrack, ctx) {
1634
1642
  const { data } = await filmApi(ctx, "GET", `/api/films/${filmId}`);
1635
1643
  if (!data.film) return { kind: "text", text: `Film not found: ${data.error ?? filmId}` };
1636
- const planning = await resumePlanning(data.film, ctx);
1644
+ const planning = await resumePlanning(data.film, ctx, soundtrack);
1637
1645
  if (planning) return planning;
1638
1646
  const uncast = await uncastRolesOf(ctx, filmId);
1639
1647
  if (uncast.length) return { kind: "text", text: `Nothing was charged. ${castNeededText(filmId, uncast)}` };
1640
1648
  const pending = shots(data.film).filter((sh) => sh.status === "idle" || sh.status === "failed" && !sh.frameUrl);
1641
1649
  let fired = 0;
1650
+ let refused;
1642
1651
  for (const sh of pending.slice(0, 6)) {
1643
1652
  const r = await filmApi(ctx, "POST", `/api/films/${filmId}/shots/${sh.id}/generate`, { kind: "frame" });
1644
1653
  if (r.status === 200) fired += 1;
1654
+ else if (!benignDispatchRefusal(r.status, r.data.error)) refused ??= r.data.error ?? `HTTP ${r.status}`;
1655
+ }
1656
+ if (fired === 0 && refused) {
1657
+ return { kind: "text", text: `Production could not start on "${data.film.title}": ${refused}` };
1645
1658
  }
1646
1659
  return {
1647
1660
  kind: "text",
1648
- text: `Production started on "${data.film.title}": ${fired} frame(s) dispatched (each is a normal frame charge; the server's Frame check reviews every one). Poll pixeldojo_film with {"film_id": "${filmId}", "action": "status"} every ~30 seconds \u2014 each poll advances the pipeline.`
1661
+ text: `Production started on "${data.film.title}": ${fired} frame(s) dispatched (each is a normal frame charge; the server's Frame check reviews every one).${refused ? ` Some could not start: ${refused}` : ""} Poll pixeldojo_film with {"film_id": "${filmId}", "action": "status"} every ~30 seconds \u2014 each poll advances the pipeline.`,
1662
+ // The caller's soundtrack choice rides along: the follow-up status calls
1663
+ // are the ones that reach the score.
1664
+ followUp: keepGoing(filmId, 30, { soundtrack })
1649
1665
  };
1650
1666
  }
1651
1667
  function buildScorePlanBody(film) {
@@ -1691,30 +1707,49 @@ async function advance(filmId, soundtrack, musicJobId, ctx) {
1691
1707
  if (film.status === "exported" && film.exportUrl) {
1692
1708
  return {
1693
1709
  kind: "text",
1694
- text: `Film finished: "${film.title}"
1710
+ text: [
1711
+ `Film finished: "${film.title}"
1695
1712
  Watch/download: ${film.exportUrl}
1696
1713
  Workspace: ${ctx.baseUrl}/film-studio/${film.id}
1697
- It is saved in the Library folder "Film: ${film.title}".`
1714
+ It is saved in the Library folder "Film: ${film.title}".`,
1715
+ shotIndex(film)
1716
+ ].filter(Boolean).join("\n")
1698
1717
  };
1699
1718
  }
1700
- if (film.exportError) {
1701
- return { kind: "text", text: `Export failed: ${film.exportError} Poll again with action "status" to retry.` };
1719
+ const startExport = async () => {
1720
+ const r = await filmApi(ctx, "POST", `/api/films/${filmId}/export`, {});
1721
+ return r.status === 200 || r.status === 409 ? null : r.data.error ?? `HTTP ${r.status}`;
1722
+ };
1723
+ if (film.exportError && all.length > 0 && all.every((sh) => sh.status === "clip-ready")) {
1724
+ const again = await startExport();
1725
+ return {
1726
+ kind: "text",
1727
+ text: again ? `Export failed: ${film.exportError} Starting it again failed too: ${again}` : `The last export failed (${film.exportError}). Started it again; exports are free. Call pixeldojo_film with {"film_id": "${filmId}", "action": "status"} in about a minute for the finished film.`
1728
+ };
1702
1729
  }
1703
- const planning = await resumePlanning(film, ctx);
1730
+ const planning = await resumePlanning(film, ctx, soundtrack);
1704
1731
  if (planning) return planning;
1705
1732
  if (needsSlice(film)) {
1706
1733
  const err = await sliceSong(ctx, film);
1707
1734
  if (err) return { kind: "text", text: `${err} Poll again with action "status" to retry.` };
1708
- return { kind: "text", text: `Song cut into one slice per shot. Poll again with {"film_id": "${filmId}", "action": "status"} to keep production moving.` };
1735
+ return {
1736
+ kind: "text",
1737
+ text: `Song cut into one slice per shot. Poll again with {"film_id": "${filmId}", "action": "status"} to keep production moving.`,
1738
+ followUp: keepGoing(filmId, 5, { soundtrack })
1739
+ };
1709
1740
  }
1710
1741
  if (shots(film).length > 0 && shots(film).every((sh) => sh.status === "idle")) {
1711
1742
  return { kind: "text", text: plannedText(film, ctx) };
1712
1743
  }
1713
1744
  let started = 0;
1714
1745
  const resent = /* @__PURE__ */ new Set();
1746
+ const refusedStarts = [];
1715
1747
  const dispatch = async (sh, kind) => {
1716
1748
  const r = await filmApi(ctx, "POST", `/api/films/${filmId}/shots/${sh.id}/generate`, { kind });
1717
- if (r.status !== 200) return;
1749
+ if (r.status !== 200) {
1750
+ if (!benignDispatchRefusal(r.status, r.data.error)) refusedStarts.push(r.data.error ?? `HTTP ${r.status}`);
1751
+ return;
1752
+ }
1718
1753
  started += 1;
1719
1754
  if (sh.status === "failed") resent.add(sh.id);
1720
1755
  };
@@ -1744,27 +1779,47 @@ It is saved in the Library folder "Film: ${film.title}".`
1744
1779
  const outUrl = out?.audio ?? out?.video ?? out?.images?.[0];
1745
1780
  if (job.status === "completed" && typeof outUrl === "string") {
1746
1781
  await filmApi(ctx, "PATCH", `/api/films/${filmId}`, { audioStems: [{ kind: "music", url: outUrl }] });
1747
- await filmApi(ctx, "POST", `/api/films/${filmId}/export`, {});
1748
- return { kind: "text", text: `Score attached \u2014 export started. Poll again in ~60s with {"film_id": "${filmId}", "action": "status"} for the finished film URL.` };
1782
+ const exportError2 = await startExport();
1783
+ if (exportError2) return { kind: "text", text: `Score attached, but the export could not start: ${exportError2}` };
1784
+ return {
1785
+ kind: "text",
1786
+ text: `Score attached \u2014 export started. Poll again in ~60s with {"film_id": "${filmId}", "action": "status"} for the finished film URL.`,
1787
+ followUp: keepGoing(filmId, 60, { soundtrack })
1788
+ };
1749
1789
  }
1750
1790
  if (job.status === "failed") {
1751
1791
  return { kind: "text", text: `The score failed (${job.error ?? "unknown"}) and was refunded. Poll again to retry, or pass soundtrack "none" to export without music.` };
1752
1792
  }
1753
- return { kind: "text", text: `Score still composing. Poll again in ~20s with {"film_id": "${filmId}", "action": "status", "music_job_id": "${musicJobId}"}.` };
1793
+ return {
1794
+ kind: "text",
1795
+ text: `Score still composing. Poll again in ~20s with {"film_id": "${filmId}", "action": "status", "music_job_id": "${musicJobId}"}.`,
1796
+ followUp: keepGoing(filmId, 20, { soundtrack, music_job_id: musicJobId })
1797
+ };
1754
1798
  }
1755
1799
  const body = soundtrack === "scene-synced" ? buildScorePlanBody(film) : buildFlatMusicBody(film, all);
1756
1800
  const dispatch2 = await ctx.client.run("text-to-music", body);
1757
- return { kind: "text", text: `All ${all.length} clips ready \u2014 the ${soundtrack} score is composing (charged like any music generation). Poll again in ~20s with {"film_id": "${filmId}", "action": "status", "music_job_id": "${dispatch2.jobId}"}.` };
1801
+ return {
1802
+ kind: "text",
1803
+ text: `All ${all.length} clips ready \u2014 the ${soundtrack} score is composing (charged like any music generation). Poll again in ~20s with {"film_id": "${filmId}", "action": "status", "music_job_id": "${dispatch2.jobId}"}.`,
1804
+ followUp: keepGoing(filmId, 20, { soundtrack, music_job_id: dispatch2.jobId })
1805
+ };
1758
1806
  }
1759
- await filmApi(ctx, "POST", `/api/films/${filmId}/export`, {});
1760
- return { kind: "text", text: `All clips ready \u2014 export started (${progressLine(film)}). Poll again in ~60s with action "status" for the finished film URL.` };
1807
+ const exportError = await startExport();
1808
+ if (exportError) return { kind: "text", text: `All clips ready, but the export could not start: ${exportError}` };
1809
+ return {
1810
+ kind: "text",
1811
+ text: `All clips ready \u2014 export started (${progressLine(film)}). Poll again in ~60s with action "status" for the finished film URL.`,
1812
+ followUp: keepGoing(filmId, 60, { soundtrack })
1813
+ };
1761
1814
  }
1762
1815
  const failed = all.filter((sh) => sh.status === "failed");
1763
1816
  const refused = failed.filter(isRefused);
1764
1817
  const retrying = failed.filter((sh) => !isRefused(sh));
1765
1818
  const sentAgain = retrying.filter((sh) => resent.has(sh.id)).length;
1766
- const paused = refused.length > 0 && started === 0 && !all.some((sh) => sh.status === "frame-generating" || sh.status === "clip-generating");
1767
- const labels = new Map(film.scenes.flatMap((s, si) => s.shots.map((sh, i) => [sh.id, `${si + 1}.${i + 1}`])));
1819
+ const rendering = all.some((sh) => sh.status === "frame-generating" || sh.status === "clip-generating");
1820
+ const paused = refused.length > 0 && started === 0 && !rendering;
1821
+ const moving = started > 0 || rendering;
1822
+ const labels = shotLabels(film);
1768
1823
  const reason = (sh) => {
1769
1824
  const text = (sh.errorMessage ?? "no reason given").replace(/\s*Retry (?:the shot|it)\.\s*$/i, "");
1770
1825
  return text.length > 300 ? `${text.slice(0, 297)}...` : text;
@@ -1776,14 +1831,75 @@ It is saved in the Library folder "Film: ${film.title}".`
1776
1831
  `${paused ? "Paused" : "In progress"}: ${progressLine(film)}.`,
1777
1832
  refused.length > 0 ? `${one ? "Shot" : "Shots"} ${refused.map((sh) => labels.get(sh.id)).join(", ")} need${one ? "s" : ""} a new frame or prompt. The provider refused ${one ? "it" : "them"} (${reason(refused[0])}) and usually refuses the same input again, so status does not resend ${one ? "it" : "them"}: every retry is a charged render. Change ${one ? "it" : "them"} and render again at ${ctx.baseUrl}/film-studio/${filmId}.` : "",
1778
1833
  retrying.length > 0 ? `${retrying.length} shot(s) failed (${reason(retrying[0])}): ${sentAgain === retrying.length ? "sent again" : sentAgain > 0 ? `${sentAgain} sent again, the rest on a later poll` : "sent again on a later poll"}.` : "",
1779
- paused ? `Nothing else is rendering. Once the shot${one ? "" : "s"} render${one ? "s" : ""} again, call pixeldojo_film with {"film_id": "${filmId}", "action": "status"} to carry on.` : `Poll again in ~30s with {"film_id": "${filmId}", "action": "status"}.`
1780
- ].filter(Boolean).join("\n")
1834
+ refusedStarts.length > 0 ? `${refusedStarts.length} render(s) could not start: ${refusedStarts[0]}` : "",
1835
+ paused ? `Nothing else is rendering. Once the shot${one ? "" : "s"} render${one ? "s" : ""} again, call pixeldojo_film with {"film_id": "${filmId}", "action": "status"} to carry on.` : moving ? `Poll again in ~30s with {"film_id": "${filmId}", "action": "status"}.` : `Nothing is rendering. Fix what is above, then call pixeldojo_film with {"film_id": "${filmId}", "action": "status"} to carry on.`
1836
+ ].filter(Boolean).join("\n"),
1837
+ ...moving && !paused ? { followUp: keepGoing(filmId, 30, { soundtrack }) } : {}
1838
+ };
1839
+ }
1840
+ function shotIndex(f) {
1841
+ const all = shots(f);
1842
+ if (all.length === 0 || all.length > 24) return "";
1843
+ const labels = shotLabels(f);
1844
+ let at = 0;
1845
+ const clock = (sec) => `${Math.floor(sec / 60)}:${String(Math.round(sec % 60)).padStart(2, "0")}`;
1846
+ const lines = all.map((sh) => {
1847
+ const from = at;
1848
+ at += sh.durationSec || 0;
1849
+ const what = sh.prompt.replace(/\s+/g, " ").trim();
1850
+ return ` ${labels.get(sh.id)} (about ${clock(from)}-${clock(at)}): ${what.length > 70 ? `${what.slice(0, 67)}...` : what}`;
1851
+ });
1852
+ return ['Shots (redo any with action "redo" and its label):', ...lines].join("\n");
1853
+ }
1854
+ async function redoShots(input, ctx) {
1855
+ const filmId = input.film_id;
1856
+ if (!input.shots?.length) {
1857
+ return { kind: "text", text: 'Pass shots: the labels status reports, like ["2.3"] for scene 2, shot 3.' };
1858
+ }
1859
+ const { data } = await filmApi(ctx, "GET", `/api/films/${filmId}`);
1860
+ const film = data.film;
1861
+ if (!film) return { kind: "text", text: `Film not found: ${data.error ?? filmId}` };
1862
+ const labels = shotLabels(film);
1863
+ const byLabel = new Map(shots(film).map((sh) => [labels.get(sh.id), sh]));
1864
+ const byId = new Map(shots(film).map((sh) => [sh.id, sh]));
1865
+ const kind = input.redo;
1866
+ const lines = [];
1867
+ let started = 0;
1868
+ let credits = 0;
1869
+ for (const ref of Array.from(new Set(input.shots))) {
1870
+ const sh = byLabel.get(ref) ?? byId.get(ref);
1871
+ if (!sh) {
1872
+ lines.push(`No shot ${ref} in this film (shots run 1.1 to ${Array.from(byLabel.keys()).pop()}).`);
1873
+ continue;
1874
+ }
1875
+ const label = labels.get(sh.id);
1876
+ if (kind === "clip" && !sh.frameUrl) {
1877
+ lines.push(`Shot ${label} has no frame yet, so there is no clip to redo. Redo it with redo "frame".`);
1878
+ continue;
1879
+ }
1880
+ const r = await filmApi(ctx, "POST", `/api/films/${filmId}/shots/${sh.id}/generate`, { kind });
1881
+ if (r.status === 200) {
1882
+ started += 1;
1883
+ credits += r.data.creditCost ?? 0;
1884
+ lines.push(`Shot ${label}: new ${kind} rendering${r.data.creditCost ? ` (${r.data.creditCost} credits)` : ""}.`);
1885
+ } else {
1886
+ lines.push(`Shot ${label}: could not start: ${r.data.error ?? `HTTP ${r.status}`}`);
1887
+ }
1888
+ }
1889
+ if (started === 0) return { kind: "text", text: [...lines, "Nothing was started."].join("\n") };
1890
+ return {
1891
+ kind: "text",
1892
+ text: [
1893
+ ...lines,
1894
+ `${credits ? `${credits} credits charged for the new take${started > 1 ? "s" : ""}. ` : ""}${kind === "frame" ? "Each new frame gets the Frame check, then a new clip. " : ""}The new take replaces the old one; keep calling pixeldojo_film with {"film_id": "${filmId}", "action": "status"}, which saves it and cuts a new export with it.`
1895
+ ].join("\n"),
1896
+ followUp: keepGoing(filmId, 30, { soundtrack: input.soundtrack })
1781
1897
  };
1782
1898
  }
1783
1899
  async function run8(input, ctx) {
1784
1900
  const action = input.action === "plan" && input.film_id ? input.cast?.length ? "cast" : "status" : input.action;
1785
1901
  if (action === "plan") return plan(input, ctx);
1786
- if (!input.film_id) return { kind: "text", text: "produce/status/cast need the film_id returned by the plan step." };
1902
+ if (!input.film_id) return { kind: "text", text: "produce/status/cast/redo need the film_id returned by the plan step." };
1787
1903
  if (action === "cast") {
1788
1904
  if (!input.cast?.length) return { kind: "text", text: "Pass cast: [{ name, prompt | image_urls | character_id }] to cast characters (add replace: true to swap someone already cast, or remove: true to take them off)." };
1789
1905
  const { lines } = await applyCast(ctx, input.film_id, input.cast);
@@ -1796,10 +1912,11 @@ async function run8(input, ctx) {
1796
1912
  ].join("\n")
1797
1913
  };
1798
1914
  }
1799
- if (action === "produce") return produce(input.film_id, ctx);
1915
+ if (action === "produce") return produce(input.film_id, input.soundtrack, ctx);
1916
+ if (action === "redo") return redoShots(input, ctx);
1800
1917
  return advance(input.film_id, input.soundtrack, input.music_job_id, ctx);
1801
1918
  }
1802
- var STORY_LOOKS, MUSIC_VIDEO_LOOKS, LOOKS, MUSIC_CLIP_ENGINE_ID, InputSchema8, InputJsonSchema8, shots, count, frameDone, RETRY_CLEARS, REFUSED, isRefused, PLANNER_POLL_MS, PLANNER_MAX_POLLS, isMusicVideo, needsSlice, stillPlanningText, LOOK_MUSIC, ARC, filmSkill;
1919
+ var STORY_LOOKS, MUSIC_VIDEO_LOOKS, LOOKS, MUSIC_CLIP_ENGINE_ID, InputSchema8, InputJsonSchema8, shots, benignDispatchRefusal, count, frameDone, RETRY_CLEARS, REFUSED, isRefused, PLANNER_POLL_MS, PLANNER_MAX_POLLS, isMusicVideo, needsSlice, stillPlanningText, LOOK_MUSIC, ARC, filmSkill;
1803
1920
  var init_film = __esm({
1804
1921
  "src/skills/film.ts"() {
1805
1922
  init_upload_helpers();
@@ -1817,8 +1934,10 @@ var init_film = __esm({
1817
1934
  lyrics: zod.z.string().max(1e4).optional().describe("Music video mode: the song lyrics, so shots land on the right lines. Optional."),
1818
1935
  aspect: zod.z.enum(["16:9", "9:16"]).default("16:9"),
1819
1936
  length: zod.z.enum(["30s", "60s", "2-3min", "5min"]).default("60s").describe("Target length; drives the shot count (~6/12/24/60 shots)."),
1820
- film_id: zod.z.string().max(40).optional().describe("Existing film id (from a previous call) for produce/status/cast."),
1821
- action: zod.z.enum(["plan", "produce", "status", "cast"]).default("plan").describe("'plan' creates + storyboards (free). 'cast' casts, replaces or removes characters on an existing film. 'produce' starts charged generation. 'status' advances production and reports progress; poll it every ~30s until it returns the finished film."),
1937
+ film_id: zod.z.string().max(40).optional().describe("Existing film id (from a previous call) for produce/status/cast/redo."),
1938
+ action: zod.z.enum(["plan", "produce", "status", "cast", "redo"]).default("plan").describe("'plan' creates + storyboards (free). 'cast' casts, replaces or removes characters on an existing film. 'produce' starts charged generation. 'status' advances production and reports progress; poll it every ~30s until it returns the finished film. 'redo' renders a new take of the listed shots (charged), then status re-saves and re-exports."),
1939
+ shots: zod.z.array(zod.z.string().trim().min(1).max(40)).min(1).max(12).optional().describe('Redo: the shots to render again, by the labels status reports ("2.3" is scene 2, shot 3) or shot id.'),
1940
+ redo: zod.z.enum(["clip", "frame"]).default("clip").describe("Redo: 'clip' (default) renders a new take of the clip from the same frame; 'frame' paints a new storyboard frame, then a new clip from it."),
1822
1941
  cast: zod.z.array(
1823
1942
  zod.z.object({
1824
1943
  name: zod.z.string().trim().min(1).max(60),
@@ -1853,11 +1972,22 @@ var init_film = __esm({
1853
1972
  lyrics: { type: "string", description: "Plan step, music video mode (optional): the song lyrics, so shots land on the right lines." },
1854
1973
  aspect: { type: "string", enum: ["16:9", "9:16"], description: "Plan step: frame aspect ratio. Default 16:9." },
1855
1974
  length: { type: "string", enum: ["30s", "60s", "2-3min", "5min"], description: "Plan step: target length, which sets the shot count (~6/12/24/60 shots). Default 60s. Ignored for a music video, whose length is the song." },
1856
- film_id: { type: "string", description: 'The film_id returned by the plan step. Required for produce and status; with it, action "plan" is treated as "status".' },
1975
+ film_id: { type: "string", description: 'The film_id returned by the plan step. Required for produce, status and redo; with it, action "plan" is treated as "status".' },
1857
1976
  action: {
1858
1977
  type: "string",
1859
- enum: ["plan", "produce", "status", "cast"],
1860
- description: "plan (default, free): writes the script and plans shots, returns film_id, a cost estimate, and any characters still to cast. cast: casts, replaces or removes characters on an existing film (pass film_id and cast). produce (charged): starts rendering frames; refused until every named character is cast. status: advances production one step and reports progress; call it every ~30s until it returns the finished film URL."
1978
+ enum: ["plan", "produce", "status", "cast", "redo"],
1979
+ description: "plan (default, free): writes the script and plans shots, returns film_id, a cost estimate, and any characters still to cast. cast: casts, replaces or removes characters on an existing film (pass film_id and cast). produce (charged): starts rendering frames; refused until every named character is cast. status: advances production one step and reports progress; call it every ~30s until it returns the finished film URL. redo (charged): renders a new take of the shots listed in `shots`, on a film in production or already finished; then call status, which saves the new take and cuts a new export with it."
1980
+ },
1981
+ shots: {
1982
+ type: "array",
1983
+ items: { type: "string" },
1984
+ maxItems: 12,
1985
+ description: 'Redo only: the shots to render again, by the labels status and the finished film report ("2.3" is scene 2, shot 3), or by shot id.'
1986
+ },
1987
+ redo: {
1988
+ type: "string",
1989
+ enum: ["clip", "frame"],
1990
+ description: "Redo only: 'clip' (default) renders a new take of the clip from the same storyboard frame, the fix for a glitch, bad motion or lip sync. 'frame' paints a new frame first (and then a new clip from it), the fix for a wrong look, face or composition. Each is charged like any render of that shot. To change what a shot shows, edit it on the storyboard."
1861
1991
  },
1862
1992
  cast: {
1863
1993
  type: "array",
@@ -1897,6 +2027,7 @@ var init_film = __esm({
1897
2027
  }
1898
2028
  };
1899
2029
  shots = (f) => f.scenes.flatMap((s) => s.shots);
2030
+ benignDispatchRefusal = (status2, error) => status2 === 429 || status2 === 409 && /already generating/i.test(error ?? "");
1900
2031
  count = (f, pred) => shots(f).filter(pred).length;
1901
2032
  frameDone = (sh) => Boolean(sh.frameUrl) && sh.status !== "idle" && sh.status !== "frame-generating";
1902
2033
  RETRY_CLEARS = /automatic audio check flagged|output audio\b[\s\S]*?sensitive information|temporarily unavailable/i;
@@ -1927,8 +2058,8 @@ var init_film = __esm({
1927
2058
  };
1928
2059
  filmSkill = {
1929
2060
  name: "pixeldojo_film",
1930
- description: "Make a finished short film from one idea: screenplay, storyboard frames (AI-reviewed), video clips with spoken dialogue, scene-synced soundtrack, stitched export. Or a music video: pass song_path (a local file) or song_url (your own PixelDojo upload from pixeldojo_upload, never a third-party link) with optional lyrics; the film is cut to that song, each clip lip-synced to its slice on the studio music video engine, and no score is composed: the export plays the song. Every named character must be cast (cast: your own images, a portrait prompt, or a Character Studio character) before frames render; cast entries can also replace or remove someone. Phased: plan is free; cast; produce starts charged generation; status advances production (poll every ~30s).",
1931
- hostedDescription: "Make a finished short film from one idea: screenplay, storyboard frames (AI-reviewed), video clips with spoken dialogue, scene-synced soundtrack, stitched export. Or a music video: pass song_url (your own PixelDojo upload made with POST /api/v1/upload, never a third-party link) with optional lyrics; the film is cut to that song, each clip lip-synced to its slice on the studio music video engine, and no score is composed: the export plays the song. Every named character must be cast (cast: your own images, a portrait prompt, or a Character Studio character) before frames render; cast entries can also replace or remove someone. Phased: plan is free; cast; produce starts charged generation; status advances production (poll every ~30s).",
2061
+ description: "Make a finished short film from one idea: screenplay, storyboard frames (AI-reviewed), video clips with spoken dialogue, scene-synced soundtrack, stitched export. Or a music video: pass song_path (a local file) or song_url (your own PixelDojo upload from pixeldojo_upload, never a third-party link) with optional lyrics; the film is cut to that song, each clip lip-synced to its slice on the studio music video engine, and no score is composed: the export plays the song. Every named character must be cast (cast: your own images, a portrait prompt, or a Character Studio character) before frames render; cast entries can also replace or remove someone. Phased: plan is free; cast; produce starts charged generation; status advances production (poll every ~30s); redo renders a new take of chosen shots and status re-exports.",
2062
+ hostedDescription: "Make a finished short film from one idea: screenplay, storyboard frames (AI-reviewed), video clips with spoken dialogue, scene-synced soundtrack, stitched export. Or a music video: pass song_url (your own PixelDojo upload made with POST /api/v1/upload, never a third-party link) with optional lyrics; the film is cut to that song, each clip lip-synced to its slice on the studio music video engine, and no score is composed: the export plays the song. Every named character must be cast (cast: your own images, a portrait prompt, or a Character Studio character) before frames render; cast entries can also replace or remove someone. Phased: plan is free; cast; produce starts charged generation; status advances production (poll every ~30s); redo renders a new take of chosen shots and status re-exports.",
1932
2063
  inputZod: InputSchema8,
1933
2064
  inputJsonSchema: InputJsonSchema8,
1934
2065
  allowedModels: [],
@@ -2142,7 +2273,7 @@ var init_video = __esm({
2142
2273
  },
2143
2274
  prompt: {
2144
2275
  type: "string",
2145
- description: "What to change, how the character should move, or what happens next. Required for change and extend. Optional for move (wan-video-character-swap ignores it)."
2276
+ description: "What to change, how the character should move, or what happens next. Required for change and extend. Optional for move (wan-video-character-swap ignores it). @Name uses a character or element the user saved in Character Studio (photos attached automatically)."
2146
2277
  },
2147
2278
  video_url: {
2148
2279
  type: "string",
@@ -2745,7 +2876,7 @@ async function run13(input, ctx) {
2745
2876
  );
2746
2877
  return {
2747
2878
  kind: "handoff",
2748
- text: `Campaign ${result.campaignId}: ` + (stillRunning.length > 0 ? `${stillRunning.length} of ${result.subJobs?.length ?? 0} sub-jobs still ${stillRunning[0].status}. Wait a few seconds, then poll again.` : `aggregate state pending. Poll again shortly.`),
2879
+ text: `Campaign ${result.campaignId}: ` + (result.progress ? `${result.progress}. Wait a few seconds, then poll again.` : stillRunning.length > 0 ? `${stillRunning.length} of ${result.subJobs?.length ?? 0} sub-jobs still ${stillRunning[0].status}. Wait a few seconds, then poll again.` : `aggregate state pending. Poll again shortly.`),
2749
2880
  jobId: result.campaignId,
2750
2881
  statusUrl: result.statusUrl ?? ctx.buildStatusUrl(result.campaignId)
2751
2882
  };
@@ -2925,6 +3056,26 @@ var init_audio = __esm({
2925
3056
  }
2926
3057
  });
2927
3058
  async function run16(input, ctx) {
3059
+ if (input.source === "characters") {
3060
+ const { characters } = await ctx.client.listCharacters({ q: input.q, limit: input.limit ?? 25 });
3061
+ if (characters.length === 0) {
3062
+ return {
3063
+ kind: "text",
3064
+ text: input.q ? `No saved character or element matches "${input.q}".` : "No saved characters or elements yet. Save one from photos with pixeldojo_save_character."
3065
+ };
3066
+ }
3067
+ const lines2 = characters.map(
3068
+ (c) => `- ${c.mention} (${c.kind})${c.description ? `: ${c.description.slice(0, 100)}` : ""}
3069
+ images: ${c.image_urls.slice(0, 4).join(" ")}`
3070
+ );
3071
+ return {
3072
+ kind: "text",
3073
+ text: `${characters.length} saved character(s)/element(s):
3074
+ ${lines2.join("\n")}
3075
+
3076
+ Write the @Name in a pixeldojo_generate / pixeldojo_video / pixeldojo_edit prompt and their photos are attached automatically (models that take reference images).`
3077
+ };
3078
+ }
2928
3079
  const res = await ctx.client.listLibrary({
2929
3080
  q: input.q,
2930
3081
  model: input.model,
@@ -2959,6 +3110,7 @@ var InputSchema16, InputJsonSchema16, librarySkill;
2959
3110
  var init_library = __esm({
2960
3111
  "src/skills/library.ts"() {
2961
3112
  InputSchema16 = zod.z.object({
3113
+ source: zod.z.enum(["media", "characters"]).optional().describe("media (default): saved and recent results. characters: saved Character Studio characters and elements, usable as @Name in prompts."),
2962
3114
  q: zod.z.string().optional().describe("Substring match against the prompt that produced the asset."),
2963
3115
  model: zod.z.string().optional().describe("Restrict to a single model (apiId)."),
2964
3116
  modality: zod.z.enum(["image", "video", "audio"]).optional().describe("Restrict to one output type."),
@@ -2967,6 +3119,11 @@ var init_library = __esm({
2967
3119
  InputJsonSchema16 = {
2968
3120
  type: "object",
2969
3121
  properties: {
3122
+ source: {
3123
+ type: "string",
3124
+ enum: ["media", "characters"],
3125
+ description: "media (default): saved media and recent generations. characters: the saved Character Studio characters, products, outfits, locations, props and styles. Write @Name in any prompt to use one."
3126
+ },
2970
3127
  q: {
2971
3128
  type: "string",
2972
3129
  description: "Substring match against the prompt that produced the asset. Omit to list the newest items."
@@ -2983,7 +3140,7 @@ var init_library = __esm({
2983
3140
  };
2984
3141
  librarySkill = {
2985
3142
  name: "pixeldojo_library",
2986
- description: "Search your Library: saved media (permanent) and recent API/MCP generations (deleted 1 hour after they finish), newest first. Returns asset URLs to reuse as reference inputs.",
3143
+ description: "Search your Library, newest first. source=media (default): saved media (permanent) and recent API/MCP generations (deleted 1 hour after they finish), as URLs to reuse as references. source=characters: saved Character Studio characters and elements, each usable as @Name in any prompt.",
2987
3144
  inputZod: InputSchema16,
2988
3145
  inputJsonSchema: InputJsonSchema16,
2989
3146
  allowedModels: [],
@@ -2992,6 +3149,100 @@ var init_library = __esm({
2992
3149
  };
2993
3150
  }
2994
3151
  });
3152
+ async function run17(input, ctx) {
3153
+ const res = await ctx.client.saveMedia({
3154
+ url: input.url,
3155
+ prompt: input.prompt,
3156
+ tool_name: input.tool_name,
3157
+ modality: input.modality,
3158
+ job_id: input.job_id
3159
+ });
3160
+ return {
3161
+ kind: "text",
3162
+ text: `Saved to My Media (permanent): ${res.url}
3163
+ It will appear at https://pixeldojo.ai/my-images and in pixeldojo_library searches.`
3164
+ };
3165
+ }
3166
+ var InputSchema17, InputJsonSchema17, saveSkill;
3167
+ var init_save = __esm({
3168
+ "src/skills/save.ts"() {
3169
+ InputSchema17 = zod.z.object({
3170
+ url: zod.z.string().url().describe("The asset URL to save (image or video)."),
3171
+ prompt: zod.z.string().optional().describe("The prompt that produced it \u2014 makes it findable in the library later."),
3172
+ tool_name: zod.z.string().optional().describe("Tool/model slug that produced it."),
3173
+ modality: zod.z.enum(["image", "video", "audio"]).optional(),
3174
+ job_id: zod.z.string().optional().describe("The jobId that produced this asset, when known.")
3175
+ });
3176
+ InputJsonSchema17 = {
3177
+ type: "object",
3178
+ properties: {
3179
+ url: { type: "string", format: "uri", description: "The result URL to keep (image or video from a PixelDojo job)." },
3180
+ prompt: { type: "string", description: "The prompt that produced it, so it is findable in the library later." },
3181
+ tool_name: { type: "string", description: "Model apiId that produced it, when known." },
3182
+ modality: { type: "string", enum: ["image", "video", "audio"], description: "Output type, when the URL does not make it obvious." },
3183
+ job_id: { type: "string", description: "The jobId that produced it, when known." }
3184
+ },
3185
+ required: ["url"]
3186
+ };
3187
+ saveSkill = {
3188
+ name: "pixeldojo_save",
3189
+ description: `Save a generated image or video into the user's My Media library permanently ("save this", "keep it"). Results otherwise expire 1 hour after they finish. Pass the result URL; it is safety-checked before it is kept.`,
3190
+ inputZod: InputSchema17,
3191
+ inputJsonSchema: InputJsonSchema17,
3192
+ allowedModels: [],
3193
+ defaultModel: "",
3194
+ run: run17
3195
+ };
3196
+ }
3197
+ });
3198
+ async function run18(input, ctx) {
3199
+ const res = await ctx.client.saveCharacter({
3200
+ name: input.name,
3201
+ kind: input.kind ?? "character",
3202
+ image_urls: input.image_urls,
3203
+ description: input.description
3204
+ });
3205
+ return {
3206
+ kind: "text",
3207
+ text: `Saved ${res.kind} "${res.name}" to Character Studio (${res.image_urls.length} image${res.image_urls.length === 1 ? "" : "s"}). Use it in any prompt as ${res.mention}, for example "${res.mention} walking on a beach at sunset". It also appears at https://pixeldojo.ai/characters.`
3208
+ };
3209
+ }
3210
+ var KINDS, InputSchema18, InputJsonSchema18, saveCharacterSkill;
3211
+ var init_save_character = __esm({
3212
+ "src/skills/save-character.ts"() {
3213
+ KINDS = ["character", "product", "outfit", "location", "object", "style"];
3214
+ InputSchema18 = zod.z.object({
3215
+ name: zod.z.string().min(1).max(60).describe("What to call it. Used as @Name in prompts."),
3216
+ kind: zod.z.enum(KINDS).optional().describe("Default character."),
3217
+ image_urls: zod.z.array(zod.z.string().url()).max(8).optional().describe("3 to 5 photos from different angles works best for a character."),
3218
+ description: zod.z.string().max(1500).optional().describe("Appearance notes, or the scene text for an element.")
3219
+ });
3220
+ InputJsonSchema18 = {
3221
+ type: "object",
3222
+ properties: {
3223
+ name: { type: "string", description: "What to call it. Used as @Name in prompts afterwards." },
3224
+ kind: { type: "string", enum: KINDS, description: "character (default), product, outfit, location, object (a prop) or style." },
3225
+ image_urls: {
3226
+ type: "array",
3227
+ items: { type: "string", format: "uri" },
3228
+ maxItems: 8,
3229
+ description: "Photos of it. For a person, 3 to 5 clear photos from different angles. Required for a character."
3230
+ },
3231
+ description: { type: "string", description: "Optional appearance notes, or the scene text for an element without photos." }
3232
+ },
3233
+ required: ["name"]
3234
+ };
3235
+ saveCharacterSkill = {
3236
+ name: "pixeldojo_save_character",
3237
+ description: "Save a character (a person, from 3-5 photos) or an element (product, outfit, location, prop, style) to the user's Character Studio library. Afterwards write @Name in any prompt to use it. List saved ones with pixeldojo_library source=characters.",
3238
+ inputZod: InputSchema18,
3239
+ inputJsonSchema: InputJsonSchema18,
3240
+ allowedModels: [],
3241
+ defaultModel: "",
3242
+ run: run18
3243
+ };
3244
+ }
3245
+ });
2995
3246
  function substitutePlaceholders(args, inputs, prevUrl) {
2996
3247
  const missing = [];
2997
3248
  const fill = (value) => {
@@ -3248,6 +3499,8 @@ __export(skills_exports, {
3248
3499
  librarySkill: () => librarySkill,
3249
3500
  listWorkflowsSkill: () => listWorkflowsSkill,
3250
3501
  runWorkflowSkill: () => runWorkflowSkill,
3502
+ saveCharacterSkill: () => saveCharacterSkill,
3503
+ saveSkill: () => saveSkill,
3251
3504
  saveWorkflowSkill: () => saveWorkflowSkill,
3252
3505
  statusSkill: () => statusSkill,
3253
3506
  storyboardSkill: () => storyboardSkill,
@@ -3293,6 +3546,8 @@ var init_skills = __esm({
3293
3546
  init_upload();
3294
3547
  init_audio();
3295
3548
  init_library();
3549
+ init_save();
3550
+ init_save_character();
3296
3551
  init_workflows();
3297
3552
  exports.ALL_SKILLS = [
3298
3553
  generateSkill,
@@ -3302,6 +3557,8 @@ var init_skills = __esm({
3302
3557
  upscaleSkill,
3303
3558
  audioSkill,
3304
3559
  librarySkill,
3560
+ saveSkill,
3561
+ saveCharacterSkill,
3305
3562
  saveWorkflowSkill,
3306
3563
  runWorkflowSkill,
3307
3564
  listWorkflowsSkill,
@@ -3349,6 +3606,8 @@ var init_skills = __esm({
3349
3606
  pixeldojo_status: read("Check job status"),
3350
3607
  pixeldojo_campaign_status: read("Check campaign status"),
3351
3608
  pixeldojo_library: read("Search media library"),
3609
+ pixeldojo_save: render("Save to My Media"),
3610
+ pixeldojo_save_character: render("Save character or element"),
3352
3611
  pixeldojo_list_workflows: read("List saved workflows"),
3353
3612
  pixeldojo_from_url: { ...read("Read product page"), openWorldHint: true }
3354
3613
  };
@@ -3405,8 +3664,8 @@ function makeRedactedLogger(target = console) {
3405
3664
  }
3406
3665
 
3407
3666
  // src/server.ts
3408
- var PACKAGE_VERSION = "0.18.0" ;
3409
- var SERVER_INSTRUCTIONS = "PixelDojo generates images, video, audio and short films across 100+ models, billed in credits from the connected PixelDojo account. A job that runs past the 30-second wait returns a jobId to check later; check it rather than submitting again, since every new submission is charged. Generated asset URLs are deleted one hour after they are created, so download anything the user wants to keep. Finished films are the exception and stay in the account library.";
3667
+ var PACKAGE_VERSION = "0.19.0" ;
3668
+ var SERVER_INSTRUCTIONS = "Pixel Dojo generates images, video, audio and short films from one catalog of AI models, billed in credits from the connected Pixel Dojo account. A job that runs past the 30-second wait returns a jobId to check later; check it rather than submitting again, since every new submission is charged. Generated asset URLs are deleted one hour after they are created: pixeldojo_save keeps one in the user's My Media permanently (after a safety check), and finished films stay in the account library. In any prompt, @Name uses a character, product, outfit, location, prop or style the user saved in Character Studio: its photos are attached automatically. pixeldojo_library source=characters lists them, and pixeldojo_save_character saves a new one from 3 to 5 photos.";
3410
3669
  function buildServer(options) {
3411
3670
  if (!options.apiKey) {
3412
3671
  throw new Error(