CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.
TypeScript ai-agentsai-diagramai-presentationbomcadcanvasdiagramdiagram-generatordrawioflowchartinfographicspptppt-generatorpresentation-generatorreactsvgedittext-to-diagramtypescriptworkflow
fix(skills): find image config from the script, keep keys out of git, make CAD export runnable
codingFeng101cbfbe050e10f
diff --git a/.gitignore b/.gitignoreindex 3fe120a..f9b457a 100644--- a/.gitignore+++ b/.gitignore@@ -26,6 +26,7 @@ lerna-debug.log*.env.*!.env.example*.local+skill/*/config/image-provider.json# Cache / temp.cache/diff --git a/package-lock.json b/package-lock.jsonindex 141c883..a70a6a4 100644--- a/package-lock.json+++ b/package-lock.json@@ -68,6 +68,7 @@"eslint-plugin-react-hooks": "^5.2.0","eslint-plugin-react-refresh": "^0.4.19","globals": "^16.0.0",+ "playwright": "^1.64.0","postcss": "^8.5.6","tailwindcss": "^3.4.19","typescript": "~5.8.3",@@ -9075,6 +9076,35 @@"integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==","license": "MIT"},+ "node_modules/playwright": {+ "version": "1.64.0",+ "resolved": "https://registry.npmmirror.com/playwright/-/playwright-1.64.0.tgz",+ "integrity": "sha512-kVzTnYFYEyQ9RGzBjNCd2+yEqWmVbxl3AHPynv3qQ6JTjv4a+kwRcnqQwIpuP3NnrnIrE/Q6wWAIAvMfIE2/Yg==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "playwright-core": "1.64.0"+ },+ "bin": {+ "playwright": "cli.js"+ },+ "engines": {+ "node": ">=20"+ }+ },+ "node_modules/playwright-core": {+ "version": "1.64.0",+ "resolved": "https://registry.npmmirror.com/playwright-core/-/playwright-core-1.64.0.tgz",+ "integrity": "sha512-T9r+MZkTECl2+oUcZ26YgZzTrYidTsIhYYkJix+6iDOymOb1FB2RLLSOxRGnZGv5DStt+aduIVbt+E8WygXYpg==",+ "dev": true,+ "license": "Apache-2.0",+ "bin": {+ "playwright-core": "cli.js"+ },+ "engines": {+ "node": ">=20"+ }+ },"node_modules/png-chunk-text": {"version": "1.0.0","resolved": "https://registry.npmmirror.com/png-chunk-text/-/png-chunk-text-1.0.0.tgz",diff --git a/package.json b/package.jsonindex 3664c9d..3c1e9ee 100644--- a/package.json+++ b/package.json@@ -74,6 +74,7 @@"eslint-plugin-react-hooks": "^5.2.0","eslint-plugin-react-refresh": "^0.4.19","globals": "^16.0.0",+ "playwright": "^1.64.0","postcss": "^8.5.6","tailwindcss": "^3.4.19","typescript": "~5.8.3",diff --git a/skill/cad-skill/SKILL.md b/skill/cad-skill/SKILL.mdindex 17709fa..8dc9fd0 100644--- a/skill/cad-skill/SKILL.md+++ b/skill/cad-skill/SKILL.md@@ -11,7 +11,9 @@ Use when the task requires one step in an interior-design workflow.## First-Use Reminder-On the first use of this skill in a conversation, remind the user that image generation reads `config/image-provider.json`, and that it must be filled in before any image can be produced.+On the first use of this skill in a conversation, remind the user that image generation reads `config/image-provider.json` in this skill folder, and that it must be filled in before any image can be produced. If it does not exist, they copy `config/image-provider.example.json` to it; the filled file is git-ignored and must not be committed.++The 2D preview export (`scripts/export-cad-2d-image.mjs`) needs Playwright's Chromium. If it reports that Chromium cannot launch, tell the user to run `npx playwright install chromium` once.## Orderdiff --git a/skill/cad-skill/config/image-provider.json b/skill/cad-skill/config/image-provider.example.jsonsimilarity index 100%rename from skill/cad-skill/config/image-provider.jsonrename to skill/cad-skill/config/image-provider.example.jsondiff --git a/skill/cad-skill/package.json b/skill/cad-skill/package.jsonindex c27311c..4121dab 100644--- a/skill/cad-skill/package.json+++ b/skill/cad-skill/package.json@@ -9,6 +9,6 @@"build:bundle": "node scripts/build-cad-bundle.mjs"},"dependencies": {- "playwright": "^1.59.1"+ "playwright": "^1.64.0"}}diff --git a/skill/cad-skill/references/image-provider-config.md b/skill/cad-skill/references/image-provider-config.mdindex 34fe3a0..438fc38 100644--- a/skill/cad-skill/references/image-provider-config.md+++ b/skill/cad-skill/references/image-provider-config.md@@ -16,7 +16,15 @@ point `baseUrl` at whichever compatible gateway serves the model.## File Path-- `config/image-provider.json`+- `config/image-provider.json` inside this skill folder+- the scripts find it from their own location, so they can run from any working directory+- pass `--config-file <path>` to use a different file (resolved from the working directory)++## Setup++The file holds a secret and is git-ignored. On first use, copy+`config/image-provider.example.json` to `config/image-provider.json` and fill it in.+Never commit the filled file.## Examplediff --git a/skill/cad-skill/scripts/build-cad-bundle.mjs b/skill/cad-skill/scripts/build-cad-bundle.mjsindex 75a4c98..73cf473 100644--- a/skill/cad-skill/scripts/build-cad-bundle.mjs+++ b/skill/cad-skill/scripts/build-cad-bundle.mjs@@ -3,6 +3,7 @@import fs from "node:fs";import path from "node:path";import { spawnSync } from "node:child_process";+import { fileURLToPath } from "node:url";function parseArgs(argv) {const args = {@@ -64,7 +65,7 @@ function main() {const outDir = path.resolve(process.cwd(), args.outDir);fs.mkdirSync(outDir, { recursive: true });- const scriptDir = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, "$1")));+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));const export2dScript = path.join(scriptDir, "export-cad-2d-image.mjs");const generateImageScript = path.join(scriptDir, "generate-cad-image.mjs");diff --git a/skill/cad-skill/scripts/export-cad-2d-image.mjs b/skill/cad-skill/scripts/export-cad-2d-image.mjsindex 793d291..94810e1 100644--- a/skill/cad-skill/scripts/export-cad-2d-image.mjs+++ b/skill/cad-skill/scripts/export-cad-2d-image.mjs@@ -3,6 +3,7 @@import fs from "node:fs";import os from "node:os";import path from "node:path";+import { pathToFileURL } from "node:url";import { chromium } from "playwright";function parseArgs(argv) {@@ -103,7 +104,14 @@ async function main() {const outputPath = path.resolve(process.cwd(), args.output);fs.mkdirSync(path.dirname(outputPath), { recursive: true });- const browser = await chromium.launch();+ let browser;+ try {+ browser = await chromium.launch();+ } catch (error) {+ fs.rmSync(tempDir, { recursive: true, force: true });+ const detail = error instanceof Error ? error.message.split("\n")[0] : String(error);+ fail(`Could not launch Chromium (${detail}). Install it once with: npx playwright install chromium`);+ }try {const page = await browser.newPage({viewport: {@@ -112,7 +120,7 @@ async function main() {},deviceScaleFactor: 1,});- await page.goto(`file:///${htmlPath.replace(/\\/g, "/")}`);+ await page.goto(pathToFileURL(htmlPath).href);await page.locator("#stage").waitFor();if (String(args.format).toLowerCase() === "jpg" || String(args.format).toLowerCase() === "jpeg") {diff --git a/skill/cad-skill/scripts/generate-cad-image.mjs b/skill/cad-skill/scripts/generate-cad-image.mjsindex b80b422..cfe825c 100644--- a/skill/cad-skill/scripts/generate-cad-image.mjs+++ b/skill/cad-skill/scripts/generate-cad-image.mjs@@ -2,6 +2,7 @@import fs from "node:fs";import path from "node:path";+import { fileURLToPath } from "node:url";import { generateImageThroughGateway } from "./lib/gateway.mjs";import { OPENAI_DEFAULT_BASE_URL } from "./lib/image-route.mjs";@@ -44,12 +45,14 @@ function fail(message) {process.exit(1);}+// The skill's own config file, found from this script rather than from the+// caller's working directory, so the script can run from anywhere.+const DEFAULT_CONFIG_FILE = fileURLToPath(new URL("../config/image-provider.json", import.meta.url));+function loadConfig(configFile) {- const target = configFile- ? path.resolve(process.cwd(), configFile)- : path.resolve(process.cwd(), "config", "image-provider.json");+ const target = configFile ? path.resolve(process.cwd(), configFile) : DEFAULT_CONFIG_FILE;if (!fs.existsSync(target)) {- fail(`Missing provider config file: ${target}`);+ fail(`Missing provider config file: ${target}. Copy image-provider.example.json next to it and fill it in.`);}return JSON.parse(fs.readFileSync(target, "utf8"));}@@ -77,7 +80,7 @@ async function main() {const baseUrl = String(rawConfig.baseUrl || OPENAI_DEFAULT_BASE_URL).trim();if (!apiKey || !model) {- fail("Missing image configuration. Required: apiKey, model. Fill config/image-provider.json.");+ fail(`Missing image configuration. Required: apiKey, model. Fill ${args.configFile || DEFAULT_CONFIG_FILE}.`);}const dataUrl = await generateImageThroughGateway({diff --git a/skill/ppt-skill/SKILL.md b/skill/ppt-skill/SKILL.mdindex 6be5124..30f6240 100644--- a/skill/ppt-skill/SKILL.md+++ b/skill/ppt-skill/SKILL.md@@ -17,7 +17,9 @@ Use when the task requires:## First-Use ReminderOn the first use of this skill in a conversation, remind the user that image generation reads-`config/image-provider.json`, and that it must be filled in before any image can be produced.+`config/image-provider.json` in this skill folder, and that it must be filled in before any image can be produced.+If it does not exist, they copy `config/image-provider.example.json` to it; the filled file is git-ignored and+must not be committed.## Orderdiff --git a/skill/ppt-skill/config/image-provider.json b/skill/ppt-skill/config/image-provider.example.jsonsimilarity index 100%rename from skill/ppt-skill/config/image-provider.jsonrename to skill/ppt-skill/config/image-provider.example.jsondiff --git a/skill/ppt-skill/references/image-provider-config.md b/skill/ppt-skill/references/image-provider-config.mdindex 59411fc..b2830f0 100644--- a/skill/ppt-skill/references/image-provider-config.md+++ b/skill/ppt-skill/references/image-provider-config.md@@ -16,7 +16,15 @@ point `baseUrl` at whichever compatible gateway serves the model.## File Path-- `config/image-provider.json`+- `config/image-provider.json` inside this skill folder+- the scripts find it from their own location, so they can run from any working directory+- pass `--config-file <path>` to use a different file (resolved from the working directory)++## Setup++The file holds a secret and is git-ignored. On first use, copy+`config/image-provider.example.json` to `config/image-provider.json` and fill it in.+Never commit the filled file.## Examplediff --git a/skill/ppt-skill/scripts/lib/common.mjs b/skill/ppt-skill/scripts/lib/common.mjsindex fc263d5..169d357 100644--- a/skill/ppt-skill/scripts/lib/common.mjs+++ b/skill/ppt-skill/scripts/lib/common.mjs@@ -1,7 +1,14 @@import fs from "node:fs";import path from "node:path";+import { fileURLToPath } from "node:url";import { OPENAI_DEFAULT_BASE_URL } from "./image-route.mjs";+// The skill's own config file, found from this script rather than from the+// caller's working directory, so the scripts can run from anywhere.+export const DEFAULT_IMAGE_CONFIG_FILE = fileURLToPath(+ new URL("../../config/image-provider.json", import.meta.url),+);+export function fail(message) {console.error(message);process.exit(1);@@ -25,11 +32,9 @@ export function resolveFromCwd(inputPath) {}export function loadImageConfig(configFile) {- const target = configFile- ? resolveFromCwd(configFile)- : resolveFromCwd(path.join("config", "image-provider.json"));+ const target = configFile ? resolveFromCwd(configFile) : DEFAULT_IMAGE_CONFIG_FILE;if (!fs.existsSync(target)) {- fail(`Missing image config file: ${target}`);+ fail(`Missing image config file: ${target}. Copy image-provider.example.json next to it and fill it in.`);}const raw = readJson(target);const apiKey = String(raw.apiKey || "").trim();