build(a2ui): allow sparse core builds

This commit is contained in:
Vincent Koc
2026-04-05 07:33:29 +01:00
parent 2a999bf9c9
commit cb1bf28526
3 changed files with 43 additions and 16 deletions

View File

@@ -14,12 +14,16 @@ A2UI_RENDERER_DIR="$ROOT_DIR/vendor/a2ui/renderers/lit"
A2UI_APP_DIR="$ROOT_DIR/apps/shared/OpenClawKit/Tools/CanvasA2UI"
# Docker builds exclude vendor/apps via .dockerignore.
# In that environment we can keep a prebuilt bundle only if it exists.
# Sparse local builds can also omit these inputs intentionally.
if [[ ! -d "$A2UI_RENDERER_DIR" || ! -d "$A2UI_APP_DIR" ]]; then
if [[ -f "$OUTPUT_FILE" ]]; then
echo "A2UI sources missing; keeping prebuilt bundle."
exit 0
fi
if [[ -n "${OPENCLAW_SPARSE_PROFILE:-}" || "${OPENCLAW_A2UI_SKIP_MISSING:-}" == "1" ]]; then
echo "A2UI sources missing; skipping bundle because OPENCLAW_A2UI_SKIP_MISSING=1 or OPENCLAW_SPARSE_PROFILE is set." >&2
exit 0
fi
echo "A2UI sources missing and no prebuilt bundle found at: $OUTPUT_FILE" >&2
exit 1
fi

View File

@@ -10,15 +10,21 @@ export function getA2uiPaths(env = process.env) {
return { srcDir, outDir };
}
export function shouldSkipMissingA2uiAssets(env = process.env): boolean {
return env.OPENCLAW_A2UI_SKIP_MISSING === "1" || Boolean(env.OPENCLAW_SPARSE_PROFILE);
}
export async function copyA2uiAssets({ srcDir, outDir }: { srcDir: string; outDir: string }) {
const skipMissing = process.env.OPENCLAW_A2UI_SKIP_MISSING === "1";
const skipMissing = shouldSkipMissingA2uiAssets(process.env);
try {
await fs.stat(path.join(srcDir, "index.html"));
await fs.stat(path.join(srcDir, "a2ui.bundle.js"));
} catch (err) {
const message = 'Missing A2UI bundle assets. Run "pnpm canvas:a2ui:bundle" and retry.';
if (skipMissing) {
console.warn(`${message} Skipping copy (OPENCLAW_A2UI_SKIP_MISSING=1).`);
console.warn(
`${message} Skipping copy because OPENCLAW_A2UI_SKIP_MISSING=1 or OPENCLAW_SPARSE_PROFILE is set.`,
);
return;
}
throw new Error(message, { cause: err });

View File

@@ -1,10 +1,27 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { afterEach, describe, expect, it } from "vitest";
import { copyA2uiAssets } from "../../scripts/canvas-a2ui-copy.js";
const ORIGINAL_SKIP_MISSING = process.env.OPENCLAW_A2UI_SKIP_MISSING;
const ORIGINAL_SPARSE_PROFILE = process.env.OPENCLAW_SPARSE_PROFILE;
describe("canvas a2ui copy", () => {
afterEach(() => {
if (ORIGINAL_SKIP_MISSING === undefined) {
delete process.env.OPENCLAW_A2UI_SKIP_MISSING;
} else {
process.env.OPENCLAW_A2UI_SKIP_MISSING = ORIGINAL_SKIP_MISSING;
}
if (ORIGINAL_SPARSE_PROFILE === undefined) {
delete process.env.OPENCLAW_SPARSE_PROFILE;
} else {
process.env.OPENCLAW_SPARSE_PROFILE = ORIGINAL_SPARSE_PROFILE;
}
});
async function withA2uiFixture(run: (dir: string) => Promise<void>) {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-a2ui-"));
try {
@@ -24,19 +41,19 @@ describe("canvas a2ui copy", () => {
it("skips missing assets when OPENCLAW_A2UI_SKIP_MISSING=1", async () => {
await withA2uiFixture(async (dir) => {
const previous = process.env.OPENCLAW_A2UI_SKIP_MISSING;
process.env.OPENCLAW_A2UI_SKIP_MISSING = "1";
try {
await expect(
copyA2uiAssets({ srcDir: dir, outDir: path.join(dir, "out") }),
).resolves.toBeUndefined();
} finally {
if (previous === undefined) {
delete process.env.OPENCLAW_A2UI_SKIP_MISSING;
} else {
process.env.OPENCLAW_A2UI_SKIP_MISSING = previous;
}
}
await expect(
copyA2uiAssets({ srcDir: dir, outDir: path.join(dir, "out") }),
).resolves.toBeUndefined();
});
});
it("skips missing assets when OPENCLAW_SPARSE_PROFILE is set", async () => {
await withA2uiFixture(async (dir) => {
process.env.OPENCLAW_SPARSE_PROFILE = "core";
await expect(
copyA2uiAssets({ srcDir: dir, outDir: path.join(dir, "out") }),
).resolves.toBeUndefined();
});
});