@atelier201/cli 0.0.0-stage → 0.4.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/AGENTS.md +378 -0
- package/README.md +145 -2
- package/dist/api-types.generated.js +8 -0
- package/dist/api-types.generated.js.map +1 -0
- package/dist/commands/api.js +111 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/auth.js +284 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/builds.js +169 -0
- package/dist/commands/builds.js.map +1 -0
- package/dist/commands/changesets.js +91 -0
- package/dist/commands/changesets.js.map +1 -0
- package/dist/commands/common.js +89 -0
- package/dist/commands/common.js.map +1 -0
- package/dist/commands/completion.js +120 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/content.js +281 -0
- package/dist/commands/content.js.map +1 -0
- package/dist/commands/doctor.js +141 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/domains.js +109 -0
- package/dist/commands/domains.js.map +1 -0
- package/dist/commands/feedback.js +39 -0
- package/dist/commands/feedback.js.map +1 -0
- package/dist/commands/files.js +286 -0
- package/dist/commands/files.js.map +1 -0
- package/dist/commands/help-json.js +127 -0
- package/dist/commands/help-json.js.map +1 -0
- package/dist/commands/history.js +83 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/mcp.js +129 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/media.js +273 -0
- package/dist/commands/media.js.map +1 -0
- package/dist/commands/pages.js +33 -0
- package/dist/commands/pages.js.map +1 -0
- package/dist/commands/previews.js +73 -0
- package/dist/commands/previews.js.map +1 -0
- package/dist/commands/publish.js +228 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/read.js +85 -0
- package/dist/commands/read.js.map +1 -0
- package/dist/commands/site-guest.js +159 -0
- package/dist/commands/site-guest.js.map +1 -0
- package/dist/commands/site.js +204 -0
- package/dist/commands/site.js.map +1 -0
- package/dist/commands/sites.js +168 -0
- package/dist/commands/sites.js.map +1 -0
- package/dist/commands/skills.js +45 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/workspace.js +89 -0
- package/dist/commands/workspace.js.map +1 -0
- package/dist/credentials.js +151 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.js +166 -0
- package/dist/errors.js.map +1 -0
- package/dist/exit-codes.js +83 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/http.js +275 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +184 -0
- package/dist/index.js.map +1 -0
- package/dist/keychain.js +185 -0
- package/dist/keychain.js.map +1 -0
- package/dist/oauth/browser.js +33 -0
- package/dist/oauth/browser.js.map +1 -0
- package/dist/oauth/pkce.js +118 -0
- package/dist/oauth/pkce.js.map +1 -0
- package/dist/oauth/server.js +276 -0
- package/dist/oauth/server.js.map +1 -0
- package/dist/output.js +161 -0
- package/dist/output.js.map +1 -0
- package/dist/project.js +178 -0
- package/dist/project.js.map +1 -0
- package/dist/refresh-lock.js +84 -0
- package/dist/refresh-lock.js.map +1 -0
- package/dist/run.js +197 -0
- package/dist/run.js.map +1 -0
- package/dist/session.js +147 -0
- package/dist/session.js.map +1 -0
- package/dist/site-link.js +145 -0
- package/dist/site-link.js.map +1 -0
- package/dist/site-sync.js +191 -0
- package/dist/site-sync.js.map +1 -0
- package/dist/tar.js +228 -0
- package/dist/tar.js.map +1 -0
- package/dist/version.js +34 -0
- package/dist/version.js.map +1 -0
- package/package.json +47 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `atelier201 help --json` — the whole command surface as machine-readable JSON.
|
|
3
|
+
*
|
|
4
|
+
* `AGENTS.md` is prose an agent has to be given; this is discoverable at
|
|
5
|
+
* runtime and cannot go stale, because it is generated from the same commander
|
|
6
|
+
* tree that actually runs.
|
|
7
|
+
*/
|
|
8
|
+
import { EXIT } from "../exit-codes.js";
|
|
9
|
+
import { VERSION } from "../version.js";
|
|
10
|
+
export function registerHelpJson(program) {
|
|
11
|
+
program
|
|
12
|
+
.command("help")
|
|
13
|
+
.argument("[command...]", "Show help for a specific command")
|
|
14
|
+
.description("Show help; --json dumps every command, flag and exit code")
|
|
15
|
+
.option("--json", "Emit the whole command surface as JSON")
|
|
16
|
+
.action((commandPath, options, command) => {
|
|
17
|
+
const root = command.parent ?? program;
|
|
18
|
+
if (!options.json) {
|
|
19
|
+
const target = findCommand(root, commandPath ?? []);
|
|
20
|
+
process.stdout.write(`${(target ?? root).helpInformation()}\n`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
process.stdout.write(`${JSON.stringify(buildHelpDocument(root), null, 2)}\n`);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function buildHelpDocument(root) {
|
|
27
|
+
return {
|
|
28
|
+
name: "atelier201",
|
|
29
|
+
version: VERSION,
|
|
30
|
+
description: root.description(),
|
|
31
|
+
api_base_url_env: "ATELIER201_API_URL",
|
|
32
|
+
exit_codes: [
|
|
33
|
+
{ code: EXIT.OK, meaning: "Success" },
|
|
34
|
+
{ code: EXIT.API_ERROR, meaning: "API or server error, or the request never arrived" },
|
|
35
|
+
{ code: EXIT.USAGE, meaning: "Bad usage: wrong flags, missing arguments, invalid input" },
|
|
36
|
+
{ code: EXIT.AUTH, meaning: "Authentication or permission failure" },
|
|
37
|
+
{ code: EXIT.NOT_FOUND, meaning: "The resource does not exist in this workspace" },
|
|
38
|
+
{ code: EXIT.RATE_LIMITED, meaning: "Rate limited; honour Retry-After" },
|
|
39
|
+
{ code: EXIT.CONFLICT, meaning: "State conflict, for example a result that is not ready" },
|
|
40
|
+
],
|
|
41
|
+
environment: [
|
|
42
|
+
{ name: "ATELIER201_API_KEY", purpose: "API key. Overrides any stored credential." },
|
|
43
|
+
{ name: "ATELIER201_API_URL", purpose: "API base URL. Defaults to https://api.atelier201.com/v1." },
|
|
44
|
+
{ name: "ATELIER201_MCP_URL", purpose: "MCP base URL. Defaults to https://mcp.atelier201.com." },
|
|
45
|
+
{ name: "ATELIER201_AUTH_URL", purpose: "OAuth authorization server. Defaults to the API origin." },
|
|
46
|
+
{ name: "ATELIER201_PROFILE", purpose: "Named credential profile. Same as --profile." },
|
|
47
|
+
{ name: "ATELIER201_NO_TUI", purpose: "Any non-empty value forces JSON output." },
|
|
48
|
+
{ name: "ATELIER201_NO_KEYCHAIN", purpose: "Any value skips the OS keychain and uses the config file." },
|
|
49
|
+
{
|
|
50
|
+
name: "NO_COLOR",
|
|
51
|
+
purpose: "Standard (no-color.org). Any non-empty value disables colour. It does not change the output format.",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
/**
|
|
55
|
+
* Which commands can be repeated safely after a failure, and which cannot.
|
|
56
|
+
* An agent deciding whether to try again after exit 1 needs this and cannot
|
|
57
|
+
* infer it from the command name.
|
|
58
|
+
*/
|
|
59
|
+
retry_policy: {
|
|
60
|
+
description: "429 is retried for every command. 408 and 5xx are retried only for idempotent requests (RFC 9110 §9.2.2). A non-idempotent write that fails with a 5xx is reported rather than repeated, because the change may already have been applied, so re-read the resource before retrying it yourself. A request that carries an Idempotency-Key is the exception: a repeat returns the first answer, so it is retried like an idempotent one.",
|
|
61
|
+
never_retried_after_5xx: [
|
|
62
|
+
"atelier201 api POST",
|
|
63
|
+
"atelier201 api PATCH",
|
|
64
|
+
"atelier201 sites create",
|
|
65
|
+
"atelier201 files commit",
|
|
66
|
+
"atelier201 changesets open, stage and commit",
|
|
67
|
+
"atelier201 history restore",
|
|
68
|
+
"atelier201 builds start",
|
|
69
|
+
"atelier201 previews create",
|
|
70
|
+
"atelier201 publish, publish rollback and publish unpublish",
|
|
71
|
+
"atelier201 domains add",
|
|
72
|
+
"atelier201 site push",
|
|
73
|
+
"atelier201 media upload",
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
error_envelope: {
|
|
77
|
+
description: "Every failure is written to stderr as this shape, whether it came from the API or from the CLI itself. request_id is null when the request never reached the server.",
|
|
78
|
+
example: {
|
|
79
|
+
error: {
|
|
80
|
+
type: "not_found_error",
|
|
81
|
+
code: "resource_not_found",
|
|
82
|
+
message: "No site with id '…' in this workspace.",
|
|
83
|
+
docs_url: "https://atelier201.com/docs/api/errors#resource_not_found",
|
|
84
|
+
},
|
|
85
|
+
request_id: "req_01K9X7",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
global_options: describeOptions(root),
|
|
89
|
+
commands: root.commands
|
|
90
|
+
.filter((command) => command.name() !== "help")
|
|
91
|
+
.map((command) => describeCommand(command, "atelier201")),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function describeCommand(command, prefix) {
|
|
95
|
+
const path = `${prefix} ${command.name()}`;
|
|
96
|
+
return {
|
|
97
|
+
name: command.name(),
|
|
98
|
+
path,
|
|
99
|
+
description: command.description(),
|
|
100
|
+
usage: `${path} ${command.usage()}`.trim(),
|
|
101
|
+
arguments: command.registeredArguments.map((argument) => ({
|
|
102
|
+
name: argument.name(),
|
|
103
|
+
required: argument.required,
|
|
104
|
+
description: argument.description,
|
|
105
|
+
})),
|
|
106
|
+
options: describeOptions(command),
|
|
107
|
+
commands: command.commands.map((child) => describeCommand(child, path)),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function describeOptions(command) {
|
|
111
|
+
return command.options.map((option) => ({
|
|
112
|
+
flags: option.flags,
|
|
113
|
+
description: option.description,
|
|
114
|
+
...(option.defaultValue === undefined ? {} : { default: option.defaultValue }),
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
function findCommand(root, segments) {
|
|
118
|
+
let current = root;
|
|
119
|
+
for (const segment of segments) {
|
|
120
|
+
const next = current.commands.find((candidate) => candidate.name() === segment || candidate.aliases().includes(segment));
|
|
121
|
+
if (!next)
|
|
122
|
+
return null;
|
|
123
|
+
current = next;
|
|
124
|
+
}
|
|
125
|
+
return current;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=help-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AC,KAAK,EAAE,IAAI,CAAC,CAAC;KACxE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,OAAgB;IACvC,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC;QAC9C,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,GAAG,CAAC,MAAM,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;KAC/E,CAAC,CAAC,CAAC;AACN,CAAC;AAED,SAAS,WAAW,CAAC,IAAa,EAAE,QAAkB;IACpD,IAAI,OAAO,GAAY,IAAI,CAAC;IAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAChC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CACrF,CAAC;QACF,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `atelier201 history …`: what changed on a site's draft, and going back.
|
|
3
|
+
*
|
|
4
|
+
* Every change is one entry. Restoring never erases anything: it adds a new
|
|
5
|
+
* entry that makes the files match an earlier one. None of it spends credits or
|
|
6
|
+
* changes what visitors see (only `atelier201 publish` does).
|
|
7
|
+
*/
|
|
8
|
+
import { formatDate } from "../output.js";
|
|
9
|
+
import { run, unwrap } from "../run.js";
|
|
10
|
+
import { addSite, seg, shortRevision, siteOf, sitePath, wholeNumber } from "./common.js";
|
|
11
|
+
export function registerHistory(program) {
|
|
12
|
+
const history = program
|
|
13
|
+
.command("history")
|
|
14
|
+
.description("The changes made to a site's draft, and going back to one. Costs no credits; visitors see nothing until you publish");
|
|
15
|
+
addSite(history
|
|
16
|
+
.command("list")
|
|
17
|
+
.description("List the changes, newest first: what changed, who changed it, through which surface. Costs no credits; changes nothing")
|
|
18
|
+
.option("--limit <n>", "How many entries (1-100)")
|
|
19
|
+
.option("--before <timestamp>", "Only entries before this ISO 8601 time: the next_before of the previous page")).action(async (options, command) => {
|
|
20
|
+
await run(command, async (session) => {
|
|
21
|
+
const { siteId } = siteOf(options);
|
|
22
|
+
const response = await session.client.request("GET", sitePath(siteId, "/revisions"), {
|
|
23
|
+
query: {
|
|
24
|
+
limit: options.limit === undefined ? undefined : wholeNumber(options.limit, "--limit", 1, 100),
|
|
25
|
+
before: options.before,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const result = unwrap(response.body);
|
|
29
|
+
session.printer.data(result, {
|
|
30
|
+
rows: result.revisions,
|
|
31
|
+
columns: [
|
|
32
|
+
{ header: "REVISION", value: (row) => shortRevision(row.revision) },
|
|
33
|
+
{ header: "WHEN", value: (row) => formatDate(row.created_at) },
|
|
34
|
+
{ header: "BY", value: (row) => `${row.author} (${row.origin})` },
|
|
35
|
+
{ header: "FILES", value: (row) => String(row.files_changed) },
|
|
36
|
+
{ header: "SUMMARY", value: (row) => row.summary },
|
|
37
|
+
],
|
|
38
|
+
summary: result.next_before ? `More: --before ${result.next_before}` : undefined,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
addSite(history
|
|
43
|
+
.command("compare")
|
|
44
|
+
.description("The files added, modified and deleted between two revisions. Costs no credits; changes nothing")
|
|
45
|
+
.requiredOption("--to <revision>", "The later revision (a 40 character id from 'history list')")
|
|
46
|
+
.option("--from <revision>", "The earlier revision to compare from (optional)")).action(async (options, command) => {
|
|
47
|
+
await run(command, async (session) => {
|
|
48
|
+
const { siteId } = siteOf(options);
|
|
49
|
+
const response = await session.client.request("GET", sitePath(siteId, "/compare"), {
|
|
50
|
+
query: { from: options.from, to: options.to },
|
|
51
|
+
});
|
|
52
|
+
const result = unwrap(response.body);
|
|
53
|
+
session.printer.data(result, {
|
|
54
|
+
rows: result.changes,
|
|
55
|
+
fields: [
|
|
56
|
+
{ label: "From", value: result.from ?? "-" },
|
|
57
|
+
{ label: "To", value: result.to },
|
|
58
|
+
],
|
|
59
|
+
columns: [
|
|
60
|
+
{ header: "ACTION", value: (row) => row.action },
|
|
61
|
+
{ header: "PATH", value: (row) => row.path },
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
addSite(history
|
|
67
|
+
.command("restore <revision>")
|
|
68
|
+
.description("Make the draft's files exactly those of an earlier revision, as a NEW history entry (nothing is erased). Costs no credits; does not publish, so visitors see no difference")).action(async (revision, options, command) => {
|
|
69
|
+
await run(command, async (session) => {
|
|
70
|
+
const { siteId } = siteOf(options);
|
|
71
|
+
const response = await session.client.request("POST", sitePath(siteId, `/revisions/${seg(revision)}/restore`));
|
|
72
|
+
const result = unwrap(response.body);
|
|
73
|
+
session.printer.data(result, {
|
|
74
|
+
fields: [
|
|
75
|
+
{ label: "Revision", value: result.revision },
|
|
76
|
+
{ label: "Changed", value: result.changed ? "yes" : "no, the draft already matched" },
|
|
77
|
+
],
|
|
78
|
+
summary: result.changed ? "Restored in the draft. Next: 'atelier201 builds start --wait', then 'atelier201 publish'." : undefined,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/commands/history.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,GAAG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,CAAC,UAAU,CAAC,CAAC,CAAC;YAC/G,MAAM,MAAM,GAAG,MAAM,CAA8B,QAAQ,CAAC,IAAI,CAAC,CAAC;YAClE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC3B,MAAM,EAAE;oBACN,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE;oBAC7C,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,+BAA+B,EAAE;iBACtF;gBACD,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,2FAA2F,CAAC,CAAC,CAAC,SAAS;aAClI,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `atelier201 mcp` — a stdio-to-HTTP MCP bridge.
|
|
3
|
+
*
|
|
4
|
+
* The Atelier201 MCP server speaks Streamable HTTP; the legacy HTTP+SSE transport
|
|
5
|
+
* is deprecated by the specification and deliberately not implemented on the
|
|
6
|
+
* server. Some clients still only launch a subprocess and talk newline-delimited
|
|
7
|
+
* JSON-RPC over stdin/stdout. This bridge is how those clients reach the remote
|
|
8
|
+
* server without us maintaining a transport the spec has retired.
|
|
9
|
+
*
|
|
10
|
+
* It is intentionally dumb: it does not interpret MCP semantics, only frames
|
|
11
|
+
* and forwards. The two headers it does set — `Mcp-Method` and `Mcp-Name` — are
|
|
12
|
+
* part of the 2026-07-28 spec and let the edge rate-limiter treat
|
|
13
|
+
* `publish_site` differently from `list_sites` without parsing a body.
|
|
14
|
+
*/
|
|
15
|
+
import readline from "node:readline";
|
|
16
|
+
import { run } from "../run.js";
|
|
17
|
+
import { USER_AGENT } from "../version.js";
|
|
18
|
+
export function registerMcp(program) {
|
|
19
|
+
program
|
|
20
|
+
.command("mcp")
|
|
21
|
+
.description("Run a stdio↔HTTP bridge to the Atelier201 MCP server")
|
|
22
|
+
.action(async (_options, command) => {
|
|
23
|
+
await run(command, async (session) => bridge(session));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export async function bridge(session) {
|
|
27
|
+
const endpoint = `${session.mcpUrl}/mcp`;
|
|
28
|
+
// Resolved once, up front: a client that fails to authenticate should learn
|
|
29
|
+
// it immediately rather than on its first tool call.
|
|
30
|
+
const { token } = await session.requireToken();
|
|
31
|
+
const input = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
32
|
+
for await (const line of input) {
|
|
33
|
+
const trimmed = line.trim();
|
|
34
|
+
if (!trimmed)
|
|
35
|
+
continue;
|
|
36
|
+
let message;
|
|
37
|
+
try {
|
|
38
|
+
message = JSON.parse(trimmed);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
writeLine(jsonRpcError(null, -32700, "Parse error: the bridge received invalid JSON."));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await forward(endpoint, token, message);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
writeLine(jsonRpcError(message.id ?? null, -32603, `The MCP bridge could not reach ${endpoint}: ${error instanceof Error ? error.message : String(error)}`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function forward(endpoint, token, message) {
|
|
53
|
+
const headers = {
|
|
54
|
+
Authorization: `Bearer ${token}`,
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
Accept: "application/json, text/event-stream",
|
|
57
|
+
"User-Agent": USER_AGENT,
|
|
58
|
+
};
|
|
59
|
+
if (typeof message.method === "string")
|
|
60
|
+
headers["Mcp-Method"] = message.method;
|
|
61
|
+
const params = message.params;
|
|
62
|
+
if (params && typeof params.name === "string")
|
|
63
|
+
headers["Mcp-Name"] = params.name;
|
|
64
|
+
const response = await fetch(endpoint, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers,
|
|
67
|
+
body: JSON.stringify(message),
|
|
68
|
+
});
|
|
69
|
+
// A notification gets 202 and no body. Emitting anything here would break the
|
|
70
|
+
// client's request/response accounting.
|
|
71
|
+
if (response.status === 202 || response.status === 204)
|
|
72
|
+
return;
|
|
73
|
+
const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
|
|
74
|
+
if (!response.ok && !contentType.includes("json")) {
|
|
75
|
+
const text = await response.text().catch(() => "");
|
|
76
|
+
writeLine(jsonRpcError(message.id ?? null, -32603, `The MCP server returned HTTP ${response.status}. ${text.slice(0, 300)}`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (contentType.includes("text/event-stream") && response.body) {
|
|
80
|
+
await pipeEventStream(response.body);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const text = await response.text();
|
|
84
|
+
if (!text.trim())
|
|
85
|
+
return;
|
|
86
|
+
writeLine(text.trim());
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Streamable HTTP may answer a single POST with an SSE stream carrying several
|
|
90
|
+
* messages. Each `data:` payload is one JSON-RPC message and goes out as its
|
|
91
|
+
* own stdout line.
|
|
92
|
+
*/
|
|
93
|
+
async function pipeEventStream(body) {
|
|
94
|
+
const decoder = new TextDecoder();
|
|
95
|
+
const reader = body.getReader();
|
|
96
|
+
let buffer = "";
|
|
97
|
+
for (;;) {
|
|
98
|
+
const { done, value } = await reader.read();
|
|
99
|
+
if (done)
|
|
100
|
+
break;
|
|
101
|
+
buffer += decoder.decode(value, { stream: true });
|
|
102
|
+
let separator = buffer.indexOf("\n\n");
|
|
103
|
+
while (separator !== -1) {
|
|
104
|
+
const event = buffer.slice(0, separator);
|
|
105
|
+
buffer = buffer.slice(separator + 2);
|
|
106
|
+
emitEvent(event);
|
|
107
|
+
separator = buffer.indexOf("\n\n");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (buffer.trim())
|
|
111
|
+
emitEvent(buffer);
|
|
112
|
+
}
|
|
113
|
+
function emitEvent(event) {
|
|
114
|
+
const payload = event
|
|
115
|
+
.split(/\r?\n/)
|
|
116
|
+
.filter((line) => line.startsWith("data:"))
|
|
117
|
+
.map((line) => line.slice(5).trimStart())
|
|
118
|
+
.join("\n")
|
|
119
|
+
.trim();
|
|
120
|
+
if (payload)
|
|
121
|
+
writeLine(payload);
|
|
122
|
+
}
|
|
123
|
+
function writeLine(payload) {
|
|
124
|
+
process.stdout.write(`${payload}\n`);
|
|
125
|
+
}
|
|
126
|
+
function jsonRpcError(id, code, message) {
|
|
127
|
+
return JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } });
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,OAAO;SACJ,OAAO,CAAC,KAAK,CAAC;SACd,WAAW,CAAC,sDAAsD,CAAC;SACnE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAgB,EAAE,EAAE;QAC3C,MAAM,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAgB;IAC3C,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,MAAM,MAAM,CAAC;IACzC,4EAA4E;IAC5E,qDAAqD;IACrD,MAAM,EAAE,KAAK,EAAE,GAA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G,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;SACxC,IAAI,CAAC,IAAI,CAAC;SACV,IAAI,EAAE,CAAC;IACV,IAAI,OAAO;QAAE,SAAS,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,YAAY,CACnB,EAA0B,EAC1B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `atelier201 media …`: images, PDFs and short videos of a site.
|
|
3
|
+
*
|
|
4
|
+
* A file is reachable at /media/<filename> from the next build on; visitors of the live site see it
|
|
5
|
+
* once you build and publish. Every command is free except `media generate`, which spends credits
|
|
6
|
+
* at a fixed price per model: it shows the price and asks first (`--yes` when there is no terminal).
|
|
7
|
+
*/
|
|
8
|
+
import { readFile, stat } from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { CliError, usageError } from "../errors.js";
|
|
11
|
+
import { EXIT } from "../exit-codes.js";
|
|
12
|
+
import { formatDate, formatNumber } from "../output.js";
|
|
13
|
+
import { confirmSpend, run, unwrap } from "../run.js";
|
|
14
|
+
import { addSite, seg, siteOf, sitePath, wholeNumber } from "./common.js";
|
|
15
|
+
/** LIMITS.mediaFileBytes in `@atelier201/site-format`. */
|
|
16
|
+
export const MAX_MEDIA_BYTES = 20 * 1024 * 1024;
|
|
17
|
+
const megabytes = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
18
|
+
export function registerMedia(program) {
|
|
19
|
+
const media = program
|
|
20
|
+
.command("media")
|
|
21
|
+
.description("Images, PDFs and short videos of a site. Costs no credits; visitors see a file once you build and publish");
|
|
22
|
+
addSite(media.command("list").description("List the uploaded files with the storage used and the plan's quota. Costs no credits; changes nothing")).action(async (options, command) => {
|
|
23
|
+
await run(command, async (session) => {
|
|
24
|
+
const { siteId } = siteOf(options);
|
|
25
|
+
const response = await session.client.request("GET", sitePath(siteId, "/media"));
|
|
26
|
+
const result = unwrap(response.body);
|
|
27
|
+
session.printer.data(result, {
|
|
28
|
+
rows: result.media,
|
|
29
|
+
fields: [{ label: "Storage", value: `${megabytes(result.used_bytes)} of ${megabytes(result.quota_bytes)}` }],
|
|
30
|
+
columns: [
|
|
31
|
+
{ header: "PATH", value: (row) => row.url_path },
|
|
32
|
+
{ header: "TYPE", value: (row) => row.mime },
|
|
33
|
+
{ header: "SIZE", value: (row) => formatNumber(row.size) },
|
|
34
|
+
{ header: "ADDED", value: (row) => formatDate(row.created_at) },
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
addSite(media
|
|
40
|
+
.command("upload <file>")
|
|
41
|
+
.description("Upload an image, PDF or short video (20 MB at most) as the raw request body. Reference it as /media/<filename> in content; it is included from the next build. Costs no credits; visitors see nothing until you build and publish")
|
|
42
|
+
.option("--name <filename>", "The name on the site. Default: the local file's name")
|
|
43
|
+
.option("--alt <text>", "Alternative text, for screen readers and search engines")).action(async (file, options, command) => {
|
|
44
|
+
await run(command, async (session) => {
|
|
45
|
+
const { siteId } = siteOf(options);
|
|
46
|
+
let size;
|
|
47
|
+
try {
|
|
48
|
+
size = (await stat(file)).size;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw usageError(`No file at '${file}'.`, "file");
|
|
52
|
+
}
|
|
53
|
+
if (size > MAX_MEDIA_BYTES) {
|
|
54
|
+
throw new CliError(`'${file}' is ${megabytes(size)}; a media file is limited to ${megabytes(MAX_MEDIA_BYTES)}.`, {
|
|
55
|
+
exitCode: EXIT.USAGE,
|
|
56
|
+
code: "request_too_large",
|
|
57
|
+
hint: "Compress it, or host a long video on a video service and link to it.",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const filename = String(options.name ?? path.basename(file));
|
|
61
|
+
const response = await session.client.request("POST", sitePath(siteId, "/media"), {
|
|
62
|
+
query: { filename, alt: options.alt },
|
|
63
|
+
body: new Uint8Array(await readFile(file)),
|
|
64
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
65
|
+
});
|
|
66
|
+
const result = unwrap(response.body);
|
|
67
|
+
session.printer.data(result, {
|
|
68
|
+
fields: [
|
|
69
|
+
{ label: "Path", value: result.url_path },
|
|
70
|
+
{ label: "Type", value: result.mime },
|
|
71
|
+
{ label: "Size", value: formatNumber(result.size) },
|
|
72
|
+
],
|
|
73
|
+
summary: result.next_action,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
addSite(media
|
|
78
|
+
.command("delete <path>")
|
|
79
|
+
.description("Remove a file from the next builds. Published builds keep their copy until they are replaced. Costs no credits")).action(async (mediaPath, options, command) => {
|
|
80
|
+
await run(command, async (session) => {
|
|
81
|
+
const { siteId } = siteOf(options);
|
|
82
|
+
const response = await session.client.request("DELETE", sitePath(siteId, "/media"), {
|
|
83
|
+
query: { path: mediaPath },
|
|
84
|
+
});
|
|
85
|
+
const result = unwrap(response.body);
|
|
86
|
+
session.printer.data(result, {
|
|
87
|
+
fields: [
|
|
88
|
+
{ label: "Path", value: result.path },
|
|
89
|
+
{ label: "Deleted", value: result.deleted ? "yes" : "no" },
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const stock = media.command("stock").description("Free photos and videos from Pixabay, copied into the site's media with their credit. Costs no credits");
|
|
95
|
+
addSite(stock
|
|
96
|
+
.command("search <query...>")
|
|
97
|
+
.description("Search free stock photos (or videos with --video). Nothing is stored; import the one you choose. Costs no credits; changes nothing")
|
|
98
|
+
.option("--video", "Videos instead of photos")
|
|
99
|
+
.option("--orientation <o>", "landscape, portrait or square")
|
|
100
|
+
.option("--provider <p>", "pixabay, the only library for now")
|
|
101
|
+
.option("--limit <n>", "Results, 1 to 30. Default 12")
|
|
102
|
+
.option("--page <n>", "The page of results. Default 1")).action(async (words, options, command) => {
|
|
103
|
+
await run(command, async (session) => {
|
|
104
|
+
const { siteId } = siteOf(options);
|
|
105
|
+
const response = await session.client.request("GET", sitePath(siteId, "/media/stock"), {
|
|
106
|
+
query: {
|
|
107
|
+
query: words.join(" "),
|
|
108
|
+
kind: options.video ? "video" : undefined,
|
|
109
|
+
orientation: options.orientation,
|
|
110
|
+
provider: options.provider,
|
|
111
|
+
per_page: options.limit ? String(wholeNumber(options.limit, "--limit", 1, 30)) : undefined,
|
|
112
|
+
page: options.page ? String(wholeNumber(options.page, "--page", 1, 50)) : undefined,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
const result = unwrap(response.body);
|
|
116
|
+
session.printer.data(result, {
|
|
117
|
+
rows: result.results,
|
|
118
|
+
columns: [
|
|
119
|
+
{ header: "PROVIDER", value: (row) => row.provider },
|
|
120
|
+
{ header: "ID", value: (row) => row.id },
|
|
121
|
+
{ header: "SIZE", value: (row) => `${row.width}x${row.height}${row.duration ? ` ${row.duration}s` : ""}` },
|
|
122
|
+
{ header: "BY", value: (row) => row.author },
|
|
123
|
+
{ header: "DESCRIPTION", value: (row) => row.description },
|
|
124
|
+
{ header: "PREVIEW", value: (row) => row.preview_url },
|
|
125
|
+
],
|
|
126
|
+
summary: `${result.attribution} Import one with: atelier201 media stock import <provider> <id>`,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
addSite(stock
|
|
131
|
+
.command("import <provider> <id>")
|
|
132
|
+
.description("Copy one search result into the site's media, with its credit kept with the file. Costs no credits; visitors see nothing until you build and publish")
|
|
133
|
+
.option("--video", "The result is a video")
|
|
134
|
+
.option("--name <name>", "The name on the site, without extension. Default: from its description")
|
|
135
|
+
.option("--alt <text>", "What it shows, for screen readers and search engines. Default: the library's description")).action(async (provider, id, options, command) => {
|
|
136
|
+
await run(command, async (session) => {
|
|
137
|
+
const { siteId } = siteOf(options);
|
|
138
|
+
if (provider !== "pixabay")
|
|
139
|
+
throw usageError("provider is pixabay.", "provider");
|
|
140
|
+
const response = await session.client.request("POST", sitePath(siteId, "/media/stock"), {
|
|
141
|
+
body: { provider, id, kind: options.video ? "video" : undefined, filename: options.name, alt: options.alt },
|
|
142
|
+
});
|
|
143
|
+
const result = unwrap(response.body);
|
|
144
|
+
session.printer.data(result, {
|
|
145
|
+
fields: [
|
|
146
|
+
{ label: "Path", value: result.url_path },
|
|
147
|
+
{ label: "Type", value: result.mime },
|
|
148
|
+
{ label: "Size", value: formatNumber(result.size) },
|
|
149
|
+
{ label: "Credit", value: result.credit ?? "" },
|
|
150
|
+
],
|
|
151
|
+
summary: result.next_action,
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
addSite(media
|
|
156
|
+
.command("place <target>")
|
|
157
|
+
.description("Put a picture in an image field, with its alt text, in one history entry: atelier201 media place business:/hero/image --query \"bakery counter with bread\" --alt \"Our counter\". The picture is a description searched in free stock (--query), a result you chose (--stock-id) or a file of the site's media (--media). Costs no credits; the build starts")
|
|
158
|
+
.requiredOption("--alt <text>", "What the picture shows, in the site's language")
|
|
159
|
+
.option("--query <words>", "A description searched in the free stock library (first result)")
|
|
160
|
+
.option("--stock-id <id>", "A result id from 'atelier201 media stock search'")
|
|
161
|
+
.option("--media <path>", "A file already in the site's media, e.g. /media/storefront.jpg")
|
|
162
|
+
.option("--orientation <shape>", "With --query: landscape | portrait | square")).action(async (target, options, command) => {
|
|
163
|
+
await run(command, async (session) => {
|
|
164
|
+
const { siteId } = siteOf(options);
|
|
165
|
+
const response = await session.client.request("POST", sitePath(siteId, "/images:place"), {
|
|
166
|
+
body: { target, alt: options.alt, query: options.query, stock_id: options.stockId, media_path: options.media, orientation: options.orientation },
|
|
167
|
+
});
|
|
168
|
+
const result = unwrap(response.body);
|
|
169
|
+
session.printer.data(result, {
|
|
170
|
+
fields: [
|
|
171
|
+
{ label: "Field", value: result.target },
|
|
172
|
+
{ label: "Picture", value: result.image },
|
|
173
|
+
{ label: "Credit", value: result.credit ?? "" },
|
|
174
|
+
{ label: "Build", value: result.build?.id ?? "not started" },
|
|
175
|
+
],
|
|
176
|
+
summary: result.next_action,
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
media
|
|
181
|
+
.command("models")
|
|
182
|
+
.description("The AI models 'media generate' can use, what each is best at, and their prices in credits. Costs no credits")
|
|
183
|
+
.action(async (_options, command) => {
|
|
184
|
+
await run(command, async (session) => {
|
|
185
|
+
const response = await session.client.request("GET", "/media/models");
|
|
186
|
+
const result = unwrap(response.body);
|
|
187
|
+
const rows = [...result.images.map((m) => ({ ...m, kind: "image" })), ...result.videos.map((m) => ({ ...m, kind: "video" }))];
|
|
188
|
+
session.printer.data(result, {
|
|
189
|
+
rows,
|
|
190
|
+
columns: [
|
|
191
|
+
{ header: "MODEL", value: (row) => String(row.id) },
|
|
192
|
+
{ header: "KIND", value: (row) => String(row.kind) },
|
|
193
|
+
{ header: "CREDITS", value: (row) => JSON.stringify(row.credits ?? row.credits_per_second) },
|
|
194
|
+
{ header: "BEST FOR", value: (row) => String(row.best_for) },
|
|
195
|
+
],
|
|
196
|
+
summary: `Image prices are per image (draft/standard/high); video prices are per second. Stock libraries: ${Object.entries(result.stock_providers ?? {}).map(([name, state]) => `${name} ${state}`).join(", ")}.`,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
addSite(media
|
|
201
|
+
.command("generate <prompt...>")
|
|
202
|
+
.description("SPENDS CREDITS: make an image or a short video with AI into the site's media, at a fixed price per model ('atelier201 media models'). Shows the exact price and asks first (--yes accepts it; required when there is no terminal). A failure gives the credits back. An image comes back done; a video takes one to five minutes ('atelier201 media generation <id> --wait')")
|
|
203
|
+
.requiredOption("--model <id>", "gpt-image, nano-banana, flux, p-image (images); wan, minimax, seedance, p-video (videos)")
|
|
204
|
+
.option("--aspect <ratio>", "16:9, 1:1, 9:16, 4:3, 3:4, 3:2 or 2:3")
|
|
205
|
+
.option("--quality <q>", "Images: draft, standard (default) or high")
|
|
206
|
+
.option("--duration <seconds>", "Videos: length in seconds")
|
|
207
|
+
.option("--resolution <r>", "Videos: 480p, 720p, 768p, 1080p or 2k, as the model allows ('atelier201 media models')")
|
|
208
|
+
.option("--audio", "Videos: with sound (seedance only)")
|
|
209
|
+
.option("--name <name>", "The name on the site, without extension")
|
|
210
|
+
.option("--alt <text>", "What it shows, for screen readers and search engines")
|
|
211
|
+
.option("--estimate", "Only show the price and the balance. Costs nothing")
|
|
212
|
+
.option("--yes", "Accept the price without the prompt (required when there is no terminal)")).action(async (words, options, command) => {
|
|
213
|
+
await run(command, async (session) => {
|
|
214
|
+
const { siteId } = siteOf(options);
|
|
215
|
+
const request = {
|
|
216
|
+
model: String(options.model),
|
|
217
|
+
prompt: words.join(" "),
|
|
218
|
+
aspect_ratio: options.aspect,
|
|
219
|
+
quality: options.quality,
|
|
220
|
+
duration: options.duration ? wholeNumber(options.duration, "--duration", 1, 10) : undefined,
|
|
221
|
+
resolution: options.resolution,
|
|
222
|
+
audio: options.audio ? true : undefined,
|
|
223
|
+
filename: options.name,
|
|
224
|
+
alt: options.alt,
|
|
225
|
+
};
|
|
226
|
+
const quote = unwrap((await session.client.request("POST", sitePath(siteId, "/media/generations"), { body: { ...request, estimate_only: true } })).body);
|
|
227
|
+
const price = quote.estimated_credits ?? 0;
|
|
228
|
+
if (options.estimate) {
|
|
229
|
+
session.printer.data(quote, {
|
|
230
|
+
fields: [
|
|
231
|
+
{ label: "Price", value: `${formatNumber(price)} credits` },
|
|
232
|
+
{ label: "Balance", value: `${formatNumber(quote.balance ?? 0)} credits` },
|
|
233
|
+
],
|
|
234
|
+
summary: quote.next_action ?? undefined,
|
|
235
|
+
});
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
session.printer.note(`Price: ${formatNumber(price)} credits (balance ${formatNumber(quote.balance ?? 0)})`);
|
|
239
|
+
await confirmSpend(session, `Spend ${formatNumber(price)} credits on this ${request.model} generation?`, {
|
|
240
|
+
yes: Boolean(options.yes),
|
|
241
|
+
command: `media generate --site ${siteId} --model ${request.model} "…"`,
|
|
242
|
+
});
|
|
243
|
+
const response = await session.client.request("POST", sitePath(siteId, "/media/generations"), { body: { ...request, max_credits: price } });
|
|
244
|
+
printGeneration(session, unwrap(response.body));
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
addSite(media
|
|
248
|
+
.command("generation <id>")
|
|
249
|
+
.description("Where an AI generation stands: running, succeeded (with its media path) or failed (credits given back). Costs no credits")
|
|
250
|
+
.option("--wait", "Wait up to 55 seconds for it to finish")).action(async (id, options, command) => {
|
|
251
|
+
await run(command, async (session) => {
|
|
252
|
+
const { siteId } = siteOf(options);
|
|
253
|
+
const response = await session.client.request("GET", sitePath(siteId, `/media/generations/${seg(id)}`), {
|
|
254
|
+
query: { wait_seconds: options.wait ? "55" : undefined },
|
|
255
|
+
});
|
|
256
|
+
printGeneration(session, unwrap(response.body));
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function printGeneration(session, result) {
|
|
261
|
+
session.printer.data(result, {
|
|
262
|
+
fields: [
|
|
263
|
+
{ label: "Generation", value: result.id ?? "" },
|
|
264
|
+
{ label: "Status", value: result.status ?? "" },
|
|
265
|
+
...(result.media ? [{ label: "Path", value: result.media.url_path }] : []),
|
|
266
|
+
...(result.credits ? [{ label: "Credits", value: formatNumber(result.credits) }] : []),
|
|
267
|
+
...(result.credits_refunded ? [{ label: "Refunded", value: formatNumber(result.credits_refunded) }] : []),
|
|
268
|
+
...(result.error ? [{ label: "Error", value: result.error }] : []),
|
|
269
|
+
],
|
|
270
|
+
summary: result.next_action ?? undefined,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=media.js.map
|