@scenar/cli 0.1.20-rc.1 → 0.2.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/package.json +17 -5
- package/src/__tests__/publish-command.test.ts +46 -0
- package/src/__tests__/publish-flow.test.ts +220 -0
- package/src/__tests__/read-viewport.test.ts +45 -0
- package/src/__tests__/run-publish.test.ts +92 -0
- package/src/__tests__/serve-command.test.ts +44 -0
- package/src/__tests__/serve-request-path.test.ts +67 -0
- package/src/__tests__/serve-static-server.test.ts +88 -0
- package/src/api.d.ts +31 -0
- package/src/api.d.ts.map +1 -0
- package/src/api.js +28 -0
- package/src/api.js.map +1 -0
- package/src/api.ts +55 -0
- package/src/bundle/read-viewport.d.ts +23 -0
- package/src/bundle/read-viewport.d.ts.map +1 -0
- package/src/bundle/read-viewport.js +25 -0
- package/src/bundle/read-viewport.js.map +1 -0
- package/src/bundle/read-viewport.ts +36 -0
- package/src/commands/deploy.d.ts.map +1 -1
- package/src/commands/deploy.js +8 -24
- package/src/commands/deploy.js.map +1 -1
- package/src/commands/deploy.ts +10 -28
- package/src/commands/narrate.d.ts.map +1 -1
- package/src/commands/narrate.js +39 -170
- package/src/commands/narrate.js.map +1 -1
- package/src/commands/narrate.ts +48 -289
- package/src/commands/pack.d.ts.map +1 -1
- package/src/commands/pack.js +12 -112
- package/src/commands/pack.js.map +1 -1
- package/src/commands/pack.ts +12 -128
- package/src/commands/publish.d.ts +3 -0
- package/src/commands/publish.d.ts.map +1 -0
- package/src/commands/publish.js +64 -0
- package/src/commands/publish.js.map +1 -0
- package/src/commands/publish.ts +86 -0
- package/src/commands/render.d.ts.map +1 -1
- package/src/commands/render.js +12 -194
- package/src/commands/render.js.map +1 -1
- package/src/commands/render.ts +19 -286
- package/src/commands/serve.d.ts +3 -0
- package/src/commands/serve.d.ts.map +1 -0
- package/src/commands/serve.js +91 -0
- package/src/commands/serve.js.map +1 -0
- package/src/commands/serve.ts +112 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +4 -0
- package/src/index.js.map +1 -1
- package/src/index.ts +4 -0
- package/src/narrate/run-narrate.d.ts +43 -0
- package/src/narrate/run-narrate.d.ts.map +1 -0
- package/src/narrate/run-narrate.js +174 -0
- package/src/narrate/run-narrate.js.map +1 -0
- package/src/narrate/run-narrate.ts +298 -0
- package/src/pack/run-pack.d.ts +34 -0
- package/src/pack/run-pack.d.ts.map +1 -0
- package/src/pack/run-pack.js +117 -0
- package/src/pack/run-pack.js.map +1 -0
- package/src/pack/run-pack.ts +163 -0
- package/src/publish/github.d.ts +11 -0
- package/src/publish/github.d.ts.map +1 -0
- package/src/publish/github.js +197 -0
- package/src/publish/github.js.map +1 -0
- package/src/publish/github.ts +216 -0
- package/src/publish/publish-flow.d.ts +110 -0
- package/src/publish/publish-flow.d.ts.map +1 -0
- package/src/publish/publish-flow.js +117 -0
- package/src/publish/publish-flow.js.map +1 -0
- package/src/publish/publish-flow.ts +199 -0
- package/src/publish/run-publish.d.ts +41 -0
- package/src/publish/run-publish.d.ts.map +1 -0
- package/src/publish/run-publish.js +77 -0
- package/src/publish/run-publish.js.map +1 -0
- package/src/publish/run-publish.ts +131 -0
- package/src/render/run-render.d.ts +31 -0
- package/src/render/run-render.d.ts.map +1 -0
- package/src/render/run-render.js +196 -0
- package/src/render/run-render.js.map +1 -0
- package/src/render/run-render.ts +287 -0
- package/src/serve/request-path.d.ts +23 -0
- package/src/serve/request-path.d.ts.map +1 -0
- package/src/serve/request-path.js +52 -0
- package/src/serve/request-path.js.map +1 -0
- package/src/serve/request-path.ts +55 -0
- package/src/serve/run-serve.d.ts +31 -0
- package/src/serve/run-serve.d.ts.map +1 -0
- package/src/serve/run-serve.js +35 -0
- package/src/serve/run-serve.js.map +1 -0
- package/src/serve/run-serve.ts +68 -0
- package/src/serve/static-server.d.ts +38 -0
- package/src/serve/static-server.d.ts.map +1 -0
- package/src/serve/static-server.js +91 -0
- package/src/serve/static-server.js.map +1 -0
- package/src/serve/static-server.ts +118 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/api.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGnG,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG7E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACjF,YAAY,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,OAAO,GACR,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The programmatic API of the Scenar CLI — the same orchestration the commands
|
|
3
|
+
* run, exposed as plain functions so other tools (notably @scenar/mcp-server)
|
|
4
|
+
* can drive Scenar without shelling out. Each `run*` performs one operation and
|
|
5
|
+
* returns a structured result; none touch process.exit or the process streams
|
|
6
|
+
* (they accept an optional `onLog` for progress).
|
|
7
|
+
*/
|
|
8
|
+
// Pack
|
|
9
|
+
export { runPack } from "./pack/run-pack.js";
|
|
10
|
+
// Narrate
|
|
11
|
+
export { runNarrate } from "./narrate/run-narrate.js";
|
|
12
|
+
// Render
|
|
13
|
+
export { runRender } from "./render/run-render.js";
|
|
14
|
+
// Serve
|
|
15
|
+
export { runServe } from "./serve/run-serve.js";
|
|
16
|
+
export { startBundleServer, createBundleServer } from "./serve/static-server.js";
|
|
17
|
+
// Publish (GitHub Pages)
|
|
18
|
+
export { runPublish } from "./publish/run-publish.js";
|
|
19
|
+
export { runPublishFlow, validateRepoName, validatePublishPath, normalizePath, pagesUrl, repoUrl, } from "./publish/publish-flow.js";
|
|
20
|
+
export { createGithubPublisher } from "./publish/github.js";
|
|
21
|
+
// Validate
|
|
22
|
+
export { validateScenario } from "./validate/scenario-validator.js";
|
|
23
|
+
export { loadScenarioYaml } from "./util/load-yaml.js";
|
|
24
|
+
// Bundle helpers (viewport + embed snippet)
|
|
25
|
+
export { readBundleViewport } from "./bundle/read-viewport.js";
|
|
26
|
+
export { buildEmbedSnippet } from "./deploy/embed-snippet.js";
|
|
27
|
+
export { DEFAULT_VIEWPORT, parseViewport } from "./pack/viewport.js";
|
|
28
|
+
//# sourceMappingURL=api.js.map
|
package/src/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACP,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,UAAU;AACV,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,QAAQ;AACR,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAGjF,yBAAyB;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,OAAO,GACR,MAAM,2BAA2B,CAAC;AAMnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,WAAW;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,4CAA4C;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The programmatic API of the Scenar CLI — the same orchestration the commands
|
|
3
|
+
* run, exposed as plain functions so other tools (notably @scenar/mcp-server)
|
|
4
|
+
* can drive Scenar without shelling out. Each `run*` performs one operation and
|
|
5
|
+
* returns a structured result; none touch process.exit or the process streams
|
|
6
|
+
* (they accept an optional `onLog` for progress).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Pack
|
|
10
|
+
export { runPack } from "./pack/run-pack.js";
|
|
11
|
+
export type { RunPackOptions, PackResult } from "./pack/run-pack.js";
|
|
12
|
+
export type { PackManifest } from "./pack/pack-manifest.js";
|
|
13
|
+
|
|
14
|
+
// Narrate
|
|
15
|
+
export { runNarrate } from "./narrate/run-narrate.js";
|
|
16
|
+
export type { RunNarrateOptions, NarrateResult, NarratedScenario } from "./narrate/run-narrate.js";
|
|
17
|
+
|
|
18
|
+
// Render
|
|
19
|
+
export { runRender } from "./render/run-render.js";
|
|
20
|
+
export type { RunRenderOptions, RenderResult } from "./render/run-render.js";
|
|
21
|
+
|
|
22
|
+
// Serve
|
|
23
|
+
export { runServe } from "./serve/run-serve.js";
|
|
24
|
+
export type { RunServeOptions, ServeResult } from "./serve/run-serve.js";
|
|
25
|
+
export { startBundleServer, createBundleServer } from "./serve/static-server.js";
|
|
26
|
+
export type { BundleServerHandle, StartBundleServerOptions } from "./serve/static-server.js";
|
|
27
|
+
|
|
28
|
+
// Publish (GitHub Pages)
|
|
29
|
+
export { runPublish } from "./publish/run-publish.js";
|
|
30
|
+
export type { RunPublishOptions, PublishRunResult } from "./publish/run-publish.js";
|
|
31
|
+
export {
|
|
32
|
+
runPublishFlow,
|
|
33
|
+
validateRepoName,
|
|
34
|
+
validatePublishPath,
|
|
35
|
+
normalizePath,
|
|
36
|
+
pagesUrl,
|
|
37
|
+
repoUrl,
|
|
38
|
+
} from "./publish/publish-flow.js";
|
|
39
|
+
export type {
|
|
40
|
+
PublishFlowDeps,
|
|
41
|
+
PublishOptions,
|
|
42
|
+
PublishResult,
|
|
43
|
+
} from "./publish/publish-flow.js";
|
|
44
|
+
export { createGithubPublisher } from "./publish/github.js";
|
|
45
|
+
|
|
46
|
+
// Validate
|
|
47
|
+
export { validateScenario } from "./validate/scenario-validator.js";
|
|
48
|
+
export { loadScenarioYaml } from "./util/load-yaml.js";
|
|
49
|
+
|
|
50
|
+
// Bundle helpers (viewport + embed snippet)
|
|
51
|
+
export { readBundleViewport } from "./bundle/read-viewport.js";
|
|
52
|
+
export type { BundleViewport } from "./bundle/read-viewport.js";
|
|
53
|
+
export { buildEmbedSnippet } from "./deploy/embed-snippet.js";
|
|
54
|
+
export { DEFAULT_VIEWPORT, parseViewport } from "./pack/viewport.js";
|
|
55
|
+
export type { Viewport } from "./pack/viewport.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Viewport } from "../pack/viewport.js";
|
|
2
|
+
/** The outcome of reading a bundle's recorded viewport. */
|
|
3
|
+
export interface BundleViewport {
|
|
4
|
+
/** The viewport to use — the recorded one, or {@link DEFAULT_VIEWPORT}. */
|
|
5
|
+
readonly viewport: Viewport;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the viewport came from the bundle's scenario.json. False when the
|
|
8
|
+
* file is missing/unreadable/invalid (older bundles, or hand-assembled dirs),
|
|
9
|
+
* in which case {@link DEFAULT_VIEWPORT} is returned. Callers decide whether
|
|
10
|
+
* to surface a "re-pack to embed at the exact aspect ratio" note.
|
|
11
|
+
*/
|
|
12
|
+
readonly recorded: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read the canonical viewport recorded in a bundle's scenario.json (DD-004),
|
|
16
|
+
* falling back to {@link DEFAULT_VIEWPORT} when it is absent or malformed.
|
|
17
|
+
*
|
|
18
|
+
* Shared by `deploy` and `serve` so the two derive the embed snippet's aspect
|
|
19
|
+
* ratio from one place and cannot drift. Pure-ish (one file read, no logging) —
|
|
20
|
+
* the caller owns any user-facing note about a missing viewport.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readBundleViewport(bundleDir: string): Promise<BundleViewport>;
|
|
23
|
+
//# sourceMappingURL=read-viewport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-viewport.d.ts","sourceRoot":"","sources":["../../../src/bundle/read-viewport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmC,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAErF,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CASnF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { SCENARIO_JSON_FILE } from "../pack/pack-manifest.js";
|
|
4
|
+
import { DEFAULT_VIEWPORT, parseViewport } from "../pack/viewport.js";
|
|
5
|
+
/**
|
|
6
|
+
* Read the canonical viewport recorded in a bundle's scenario.json (DD-004),
|
|
7
|
+
* falling back to {@link DEFAULT_VIEWPORT} when it is absent or malformed.
|
|
8
|
+
*
|
|
9
|
+
* Shared by `deploy` and `serve` so the two derive the embed snippet's aspect
|
|
10
|
+
* ratio from one place and cannot drift. Pure-ish (one file read, no logging) —
|
|
11
|
+
* the caller owns any user-facing note about a missing viewport.
|
|
12
|
+
*/
|
|
13
|
+
export async function readBundleViewport(bundleDir) {
|
|
14
|
+
try {
|
|
15
|
+
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
16
|
+
const viewport = parseViewport(JSON.parse(raw).viewport);
|
|
17
|
+
if (viewport)
|
|
18
|
+
return { viewport, recorded: true };
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
22
|
+
}
|
|
23
|
+
return { viewport: DEFAULT_VIEWPORT, recorded: false };
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=read-viewport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-viewport.js","sourceRoot":"","sources":["../../../src/bundle/read-viewport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAiB,MAAM,qBAAqB,CAAC;AAerF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,SAAiB;IACxD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,aAAa,CAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAA4B,CAAC,QAAQ,CAAC,CAAC;QACrF,IAAI,QAAQ;YAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;IAC5E,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { SCENARIO_JSON_FILE } from "../pack/pack-manifest.js";
|
|
4
|
+
import { DEFAULT_VIEWPORT, parseViewport, type Viewport } from "../pack/viewport.js";
|
|
5
|
+
|
|
6
|
+
/** The outcome of reading a bundle's recorded viewport. */
|
|
7
|
+
export interface BundleViewport {
|
|
8
|
+
/** The viewport to use — the recorded one, or {@link DEFAULT_VIEWPORT}. */
|
|
9
|
+
readonly viewport: Viewport;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the viewport came from the bundle's scenario.json. False when the
|
|
12
|
+
* file is missing/unreadable/invalid (older bundles, or hand-assembled dirs),
|
|
13
|
+
* in which case {@link DEFAULT_VIEWPORT} is returned. Callers decide whether
|
|
14
|
+
* to surface a "re-pack to embed at the exact aspect ratio" note.
|
|
15
|
+
*/
|
|
16
|
+
readonly recorded: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Read the canonical viewport recorded in a bundle's scenario.json (DD-004),
|
|
21
|
+
* falling back to {@link DEFAULT_VIEWPORT} when it is absent or malformed.
|
|
22
|
+
*
|
|
23
|
+
* Shared by `deploy` and `serve` so the two derive the embed snippet's aspect
|
|
24
|
+
* ratio from one place and cannot drift. Pure-ish (one file read, no logging) —
|
|
25
|
+
* the caller owns any user-facing note about a missing viewport.
|
|
26
|
+
*/
|
|
27
|
+
export async function readBundleViewport(bundleDir: string): Promise<BundleViewport> {
|
|
28
|
+
try {
|
|
29
|
+
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
30
|
+
const viewport = parseViewport((JSON.parse(raw) as { viewport?: unknown }).viewport);
|
|
31
|
+
if (viewport) return { viewport, recorded: true };
|
|
32
|
+
} catch {
|
|
33
|
+
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
34
|
+
}
|
|
35
|
+
return { viewport: DEFAULT_VIEWPORT, recorded: false };
|
|
36
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqF5D"}
|
package/src/commands/deploy.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve, join } from "node:path";
|
|
2
2
|
import { readFile, stat } from "node:fs/promises";
|
|
3
|
-
import { PACK_MANIFEST_FILE
|
|
4
|
-
import {
|
|
3
|
+
import { PACK_MANIFEST_FILE } from "../pack/pack-manifest.js";
|
|
4
|
+
import { readBundleViewport } from "../bundle/read-viewport.js";
|
|
5
5
|
import { createBackendClients } from "../deploy/client.js";
|
|
6
6
|
import { putFile } from "../deploy/upload.js";
|
|
7
7
|
import { buildEmbedSnippet } from "../deploy/embed-snippet.js";
|
|
@@ -62,7 +62,12 @@ export function registerDeployCommand(program) {
|
|
|
62
62
|
// piping). Responsive iframe at the bundle's canonical aspect ratio
|
|
63
63
|
// (DD-002/DD-004); falls back to the default viewport for bundles packed
|
|
64
64
|
// before the viewport was recorded.
|
|
65
|
-
const viewport = await
|
|
65
|
+
const { viewport, recorded } = await readBundleViewport(resolvedDir);
|
|
66
|
+
if (!recorded) {
|
|
67
|
+
process.stderr.write(` Note: no recorded viewport for "${name}"; ` +
|
|
68
|
+
`snippet uses the default ${viewport.width}x${viewport.height}. ` +
|
|
69
|
+
"Re-pack with the current CLI to embed at the exact aspect ratio.\n");
|
|
70
|
+
}
|
|
66
71
|
process.stderr.write("\n Embed snippet (paste into any page):\n\n");
|
|
67
72
|
process.stderr.write(`${indent(buildEmbedSnippet({ embedUrl, viewport, title: name }))}\n`);
|
|
68
73
|
}
|
|
@@ -123,27 +128,6 @@ function makeDeps(clients, bundleDir) {
|
|
|
123
128
|
},
|
|
124
129
|
};
|
|
125
130
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Read the canonical viewport recorded in the bundle's scenario.json (DD-004).
|
|
128
|
-
* Falls back to {@link DEFAULT_VIEWPORT} for bundles packed before the viewport
|
|
129
|
-
* was recorded, or if the file is missing/malformed — a snippet with sensible
|
|
130
|
-
* proportions always beats no snippet. `scenarioLabel` is only for the warning.
|
|
131
|
-
*/
|
|
132
|
-
async function readScenarioViewport(bundleDir, scenarioLabel) {
|
|
133
|
-
try {
|
|
134
|
-
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
135
|
-
const viewport = parseViewport(JSON.parse(raw).viewport);
|
|
136
|
-
if (viewport)
|
|
137
|
-
return viewport;
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
141
|
-
}
|
|
142
|
-
process.stderr.write(` Note: no recorded viewport for "${scenarioLabel}"; ` +
|
|
143
|
-
`snippet uses the default ${DEFAULT_VIEWPORT.width}x${DEFAULT_VIEWPORT.height}. ` +
|
|
144
|
-
"Re-pack with the current CLI to embed at the exact aspect ratio.\n");
|
|
145
|
-
return DEFAULT_VIEWPORT;
|
|
146
|
-
}
|
|
147
131
|
/** Indent every line by two spaces (for nesting a block under a heading). */
|
|
148
132
|
function indent(block) {
|
|
149
133
|
return block.replace(/^/gm, " ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM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C3F,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAiB,CAAC;IAC/C,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpF,MAAM,IAAI,KAAK,CAAC,GAAG,kBAAkB,kCAAkC,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/src/commands/deploy.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { resolve, join } from "node:path";
|
|
|
2
2
|
import { readFile, stat } from "node:fs/promises";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import type { PackManifest } from "../pack/pack-manifest.js";
|
|
5
|
-
import { PACK_MANIFEST_FILE
|
|
6
|
-
import {
|
|
5
|
+
import { PACK_MANIFEST_FILE } from "../pack/pack-manifest.js";
|
|
6
|
+
import { readBundleViewport } from "../bundle/read-viewport.js";
|
|
7
7
|
import { createBackendClients } from "../deploy/client.js";
|
|
8
8
|
import { putFile } from "../deploy/upload.js";
|
|
9
9
|
import { buildEmbedSnippet } from "../deploy/embed-snippet.js";
|
|
@@ -91,7 +91,14 @@ export function registerDeployCommand(program: Command): void {
|
|
|
91
91
|
// piping). Responsive iframe at the bundle's canonical aspect ratio
|
|
92
92
|
// (DD-002/DD-004); falls back to the default viewport for bundles packed
|
|
93
93
|
// before the viewport was recorded.
|
|
94
|
-
const viewport = await
|
|
94
|
+
const { viewport, recorded } = await readBundleViewport(resolvedDir);
|
|
95
|
+
if (!recorded) {
|
|
96
|
+
process.stderr.write(
|
|
97
|
+
` Note: no recorded viewport for "${name}"; ` +
|
|
98
|
+
`snippet uses the default ${viewport.width}x${viewport.height}. ` +
|
|
99
|
+
"Re-pack with the current CLI to embed at the exact aspect ratio.\n",
|
|
100
|
+
);
|
|
101
|
+
}
|
|
95
102
|
process.stderr.write("\n Embed snippet (paste into any page):\n\n");
|
|
96
103
|
process.stderr.write(`${indent(buildEmbedSnippet({ embedUrl, viewport, title: name }))}\n`);
|
|
97
104
|
} catch (error) {
|
|
@@ -156,31 +163,6 @@ function makeDeps(
|
|
|
156
163
|
};
|
|
157
164
|
}
|
|
158
165
|
|
|
159
|
-
/**
|
|
160
|
-
* Read the canonical viewport recorded in the bundle's scenario.json (DD-004).
|
|
161
|
-
* Falls back to {@link DEFAULT_VIEWPORT} for bundles packed before the viewport
|
|
162
|
-
* was recorded, or if the file is missing/malformed — a snippet with sensible
|
|
163
|
-
* proportions always beats no snippet. `scenarioLabel` is only for the warning.
|
|
164
|
-
*/
|
|
165
|
-
async function readScenarioViewport(
|
|
166
|
-
bundleDir: string,
|
|
167
|
-
scenarioLabel: string,
|
|
168
|
-
): Promise<Viewport> {
|
|
169
|
-
try {
|
|
170
|
-
const raw = await readFile(join(bundleDir, SCENARIO_JSON_FILE), "utf-8");
|
|
171
|
-
const viewport = parseViewport((JSON.parse(raw) as { viewport?: unknown }).viewport);
|
|
172
|
-
if (viewport) return viewport;
|
|
173
|
-
} catch {
|
|
174
|
-
// Missing/unreadable/invalid scenario.json — fall through to the default.
|
|
175
|
-
}
|
|
176
|
-
process.stderr.write(
|
|
177
|
-
` Note: no recorded viewport for "${scenarioLabel}"; ` +
|
|
178
|
-
`snippet uses the default ${DEFAULT_VIEWPORT.width}x${DEFAULT_VIEWPORT.height}. ` +
|
|
179
|
-
"Re-pack with the current CLI to embed at the exact aspect ratio.\n",
|
|
180
|
-
);
|
|
181
|
-
return DEFAULT_VIEWPORT;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
166
|
/** Indent every line by two spaces (for nesting a block under a heading). */
|
|
185
167
|
function indent(block: string): string {
|
|
186
168
|
return block.replace(/^/gm, " ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"narrate.d.ts","sourceRoot":"","sources":["../../../src/commands/narrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"narrate.d.ts","sourceRoot":"","sources":["../../../src/commands/narrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6D7D"}
|
package/src/commands/narrate.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join, resolve, extname, basename, dirname } from "node:path";
|
|
3
|
-
import { loadScenarioYaml } from "../util/load-yaml.js";
|
|
4
|
-
import { loadStepsFromTs } from "../util/load-ts.js";
|
|
5
|
-
import { discoverScenarios } from "../util/discover-scenarios.js";
|
|
6
|
-
import { computeHash, loadCache, saveCache, fileExists, isCached, getCachedDuration, buildCacheFile, } from "../util/narration-cache.js";
|
|
7
|
-
import { validateScenario } from "../validate/scenario-validator.js";
|
|
8
|
-
import { resolveProvider } from "../tts/resolve-provider.js";
|
|
1
|
+
import { runNarrate } from "../narrate/run-narrate.js";
|
|
9
2
|
export function registerNarrateCommand(program) {
|
|
10
3
|
program
|
|
11
4
|
.command("narrate")
|
|
@@ -18,173 +11,49 @@ export function registerNarrateCommand(program) {
|
|
|
18
11
|
.option("--voice <voice>", "voice name (provider-specific)")
|
|
19
12
|
.option("--base-url <path>", "URL path prefix for src fields in manifest")
|
|
20
13
|
.action(async (fileOrDir, options) => {
|
|
21
|
-
const provider = await resolveProvider(options.tts);
|
|
22
|
-
const resolved = resolve(fileOrDir);
|
|
23
|
-
const info = await stat(resolved);
|
|
24
|
-
if (info.isDirectory()) {
|
|
25
|
-
await runNarrateDirectory(resolved, options, provider);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
await runNarrateSingleFile(resolved, options, provider);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function extractNarratedSteps(steps) {
|
|
33
|
-
const result = [];
|
|
34
|
-
for (let i = 0; i < steps.length; i++) {
|
|
35
|
-
const text = steps[i].narration ?? steps[i].narrationText;
|
|
36
|
-
if (typeof text === "string" && text.length > 0) {
|
|
37
|
-
result.push({ index: i, text });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
function buildRuntimeManifest(totalSteps, entries) {
|
|
43
|
-
const steps = Array.from({ length: totalSteps }, () => null);
|
|
44
|
-
for (const [idx, entry] of entries) {
|
|
45
|
-
steps[idx] = entry;
|
|
46
|
-
}
|
|
47
|
-
return { steps };
|
|
48
|
-
}
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Single-file narration
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
async function loadStepsFromFile(filePath) {
|
|
53
|
-
const ext = extname(filePath).toLowerCase();
|
|
54
|
-
if (ext === ".ts" || ext === ".tsx") {
|
|
55
|
-
const steps = await loadStepsFromTs(filePath);
|
|
56
|
-
return { steps, totalSteps: steps.length };
|
|
57
|
-
}
|
|
58
|
-
const scenario = await loadScenarioYaml(filePath);
|
|
59
|
-
const validation = validateScenario(scenario);
|
|
60
|
-
if (!validation.valid) {
|
|
61
|
-
throw new Error(`Scenario has ${validation.errors.length} error(s). Run 'scenar validate ${filePath}' for details.`);
|
|
62
|
-
}
|
|
63
|
-
const steps = scenario["steps"];
|
|
64
|
-
if (!steps) {
|
|
65
|
-
throw new Error("No steps found in scenario.");
|
|
66
|
-
}
|
|
67
|
-
return { steps: steps, totalSteps: steps.length };
|
|
68
|
-
}
|
|
69
|
-
async function runNarrateSingleFile(filePath, options, provider) {
|
|
70
|
-
const { steps, totalSteps } = await loadStepsFromFile(filePath);
|
|
71
|
-
const narratedSteps = extractNarratedSteps(steps);
|
|
72
|
-
if (narratedSteps.length === 0) {
|
|
73
|
-
process.stderr.write("\x1b[33m!\x1b[0m No steps contain narration text. Nothing to generate.\n");
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const outDir = options.out ?? join(dirname(filePath), "narration");
|
|
77
|
-
const voice = options.voice ?? "";
|
|
78
|
-
await generateNarration({
|
|
79
|
-
scenarioId: basename(dirname(filePath)),
|
|
80
|
-
narratedSteps,
|
|
81
|
-
totalSteps,
|
|
82
|
-
outDir,
|
|
83
|
-
voice,
|
|
84
|
-
baseUrl: options.baseUrl,
|
|
85
|
-
provider,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
// Directory-mode narration
|
|
90
|
-
// ---------------------------------------------------------------------------
|
|
91
|
-
async function runNarrateDirectory(dirPath, options, provider) {
|
|
92
|
-
const scenarios = await discoverScenarios(dirPath);
|
|
93
|
-
if (scenarios.length === 0) {
|
|
94
|
-
process.stderr.write("\x1b[33m!\x1b[0m No scenario directories with steps.ts found.\n");
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
process.stderr.write(`Discovered ${scenarios.length} scenario(s)\n\n`);
|
|
98
|
-
let totalGenerated = 0;
|
|
99
|
-
let totalCached = 0;
|
|
100
|
-
let totalSkipped = 0;
|
|
101
|
-
let scenariosWithNarration = 0;
|
|
102
|
-
const errors = [];
|
|
103
|
-
for (const scenario of scenarios) {
|
|
104
|
-
process.stderr.write(` ${scenario.id}\n`);
|
|
105
14
|
try {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
scenariosWithNarration++;
|
|
114
|
-
const outDir = options.out
|
|
115
|
-
? join(options.out, scenario.id)
|
|
116
|
-
: join(dirPath, scenario.id, "narration");
|
|
117
|
-
const stats = await generateNarration({
|
|
118
|
-
scenarioId: scenario.id,
|
|
119
|
-
narratedSteps,
|
|
120
|
-
totalSteps: steps.length,
|
|
121
|
-
outDir,
|
|
122
|
-
voice: options.voice ?? "",
|
|
15
|
+
const result = await runNarrate({
|
|
16
|
+
target: fileOrDir,
|
|
17
|
+
tts: options.tts,
|
|
18
|
+
out: options.out,
|
|
19
|
+
voice: options.voice,
|
|
123
20
|
baseUrl: options.baseUrl,
|
|
124
|
-
|
|
21
|
+
onLog: (message) => process.stderr.write(`${message}\n`),
|
|
125
22
|
});
|
|
126
|
-
|
|
127
|
-
|
|
23
|
+
if (result.mode === "file") {
|
|
24
|
+
const only = result.scenarios[0];
|
|
25
|
+
if (only?.skipped) {
|
|
26
|
+
process.stderr.write("\x1b[33m!\x1b[0m No steps contain narration text. Nothing to generate.\n");
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Directory mode: print the aggregate summary.
|
|
31
|
+
if (result.scenarios.length === 0) {
|
|
32
|
+
process.stderr.write("\x1b[33m!\x1b[0m No scenario directories with steps.ts found.\n");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const withNarration = result.scenarios.filter((s) => !s.skipped).length;
|
|
36
|
+
process.stderr.write("\n");
|
|
37
|
+
process.stderr.write(`Scenarios with narration: ${withNarration}\n`);
|
|
38
|
+
process.stderr.write(`Audio files generated: ${result.totalGenerated}\n`);
|
|
39
|
+
process.stderr.write(`Audio files cached: ${result.totalCached}\n`);
|
|
40
|
+
process.stderr.write(`Scenarios skipped: ${result.totalSkipped}\n`);
|
|
41
|
+
if (result.errors.length > 0) {
|
|
42
|
+
process.stderr.write(`\n\x1b[31m${result.errors.length} scenario(s) failed:\x1b[0m\n`);
|
|
43
|
+
for (const { id, message } of result.errors) {
|
|
44
|
+
process.stderr.write(` - ${id}: ${message}\n`);
|
|
45
|
+
}
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
process.stderr.write("\nDone\n");
|
|
50
|
+
}
|
|
128
51
|
}
|
|
129
52
|
catch (error) {
|
|
130
|
-
|
|
131
|
-
|
|
53
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
54
|
+
process.stderr.write(`\x1b[31mError:\x1b[0m ${msg}\n`);
|
|
55
|
+
process.exitCode = 1;
|
|
132
56
|
}
|
|
133
|
-
}
|
|
134
|
-
process.stderr.write("\n");
|
|
135
|
-
process.stderr.write(`Scenarios with narration: ${scenariosWithNarration}\n`);
|
|
136
|
-
process.stderr.write(`Audio files generated: ${totalGenerated}\n`);
|
|
137
|
-
process.stderr.write(`Audio files cached: ${totalCached}\n`);
|
|
138
|
-
process.stderr.write(`Scenarios skipped: ${totalSkipped}\n`);
|
|
139
|
-
if (errors.length > 0) {
|
|
140
|
-
process.stderr.write(`\n\x1b[31m${errors.length} scenario(s) failed:\x1b[0m\n`);
|
|
141
|
-
for (const { id, error } of errors) {
|
|
142
|
-
process.stderr.write(` - ${id}: ${error}\n`);
|
|
143
|
-
}
|
|
144
|
-
process.exitCode = 1;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
process.stderr.write("\nDone\n");
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async function generateNarration(opts) {
|
|
151
|
-
const { scenarioId, narratedSteps, totalSteps, outDir, voice, baseUrl, provider } = opts;
|
|
152
|
-
await mkdir(outDir, { recursive: true });
|
|
153
|
-
const existingCache = await loadCache(outDir);
|
|
154
|
-
const stats = { generated: 0, cached: 0 };
|
|
155
|
-
const manifestEntries = new Map();
|
|
156
|
-
const cacheEntries = new Map();
|
|
157
|
-
for (const step of narratedSteps) {
|
|
158
|
-
const hash = computeHash(step.text, voice);
|
|
159
|
-
const fileName = `step-${step.index}.mp3`;
|
|
160
|
-
const mp3Path = join(outDir, fileName);
|
|
161
|
-
const srcPrefix = baseUrl
|
|
162
|
-
? `${baseUrl.replace(/\/$/, "")}/${scenarioId}`
|
|
163
|
-
: `.`;
|
|
164
|
-
const src = `${srcPrefix}/${fileName}`;
|
|
165
|
-
if (isCached(existingCache, step.index, hash, voice) && await fileExists(mp3Path)) {
|
|
166
|
-
const durationMs = getCachedDuration(existingCache, step.index);
|
|
167
|
-
manifestEntries.set(step.index, { src, durationMs });
|
|
168
|
-
cacheEntries.set(step.index, { hash, durationMs });
|
|
169
|
-
stats.cached++;
|
|
170
|
-
process.stderr.write(` step ${step.index}: cached\n`);
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
process.stderr.write(` step ${step.index}: generating...\n`);
|
|
174
|
-
const result = await provider.synthesize(step.text, {
|
|
175
|
-
voice: voice || undefined,
|
|
176
|
-
});
|
|
177
|
-
await writeFile(mp3Path, result.audio);
|
|
178
|
-
manifestEntries.set(step.index, { src, durationMs: result.durationMs });
|
|
179
|
-
cacheEntries.set(step.index, { hash, durationMs: result.durationMs });
|
|
180
|
-
stats.generated++;
|
|
181
|
-
process.stderr.write(` step ${step.index}: ${result.durationMs}ms (${result.audio.length} bytes)\n`);
|
|
182
|
-
}
|
|
183
|
-
const manifest = buildRuntimeManifest(totalSteps, manifestEntries);
|
|
184
|
-
await writeFile(join(outDir, "manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
185
|
-
const cache = buildCacheFile(voice, totalSteps, cacheEntries);
|
|
186
|
-
await saveCache(outDir, cache);
|
|
187
|
-
process.stderr.write(`\x1b[32m+\x1b[0m ${scenarioId}: ${stats.generated} generated, ${stats.cached} cached\n`);
|
|
188
|
-
return stats;
|
|
57
|
+
});
|
|
189
58
|
}
|
|
190
59
|
//# sourceMappingURL=narrate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"narrate.js","sourceRoot":"","sources":["../../../src/commands/narrate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"narrate.js","sourceRoot":"","sources":["../../../src/commands/narrate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AASvD,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,OAAO;SACJ,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CACV,mDAAmD;QACjD,gEAAgE;QAChE,4DAA4D,CAC/D;SACA,QAAQ,CAAC,eAAe,EAAE,gDAAg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