@agimon-ai/po-style-system-tooling 0.2.14-alpha.7 → 0.2.14-alpha.9
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/README.md +0 -1
- package/dist/cli.cjs +2 -39
- package/dist/cli.mjs +2 -39
- package/dist/index.cjs +74 -7
- package/dist/index.d.cts +45 -34
- package/dist/index.d.mts +45 -34
- package/dist/index.mjs +72 -2
- package/dist/{stdio-OeP9ajK2.mjs → stdio-8KmKB4TW.mjs} +66 -477
- package/dist/{stdio-DdX1dqxV.cjs → stdio-DKWqsPkv.cjs} +70 -481
- package/package.json +1 -1
- package/skills/style-system/SKILL.md +43 -21
package/README.md
CHANGED
|
@@ -21,7 +21,6 @@ style-system --help
|
|
|
21
21
|
| `get-css-classes` | Extract the valid CSS classes from a theme CSS file |
|
|
22
22
|
| `get-ui-component` | Render a component to a screenshot using the app's design-system config |
|
|
23
23
|
| `list-app-components` | List app-specific components and package components |
|
|
24
|
-
| `polish-component` | Design-system-aware component polish |
|
|
25
24
|
| `generate-oxlint-config` | Generate an oxlint `no-restricted-classes` config from theme tokens |
|
|
26
25
|
| `mcp-serve` | Run as an MCP server over stdio |
|
|
27
26
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_stdio = require("./stdio-
|
|
2
|
+
const require_stdio = require("./stdio-DKWqsPkv.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_stdio.__toESM(node_path, 1);
|
|
6
6
|
let zod = require("zod");
|
|
7
|
-
let _agimon_ai_foundation_exec = require("@agimon-ai/foundation-exec");
|
|
8
7
|
let _modelcontextprotocol_server = require("@modelcontextprotocol/server");
|
|
9
8
|
require("reflect-metadata");
|
|
10
9
|
let commander = require("commander");
|
|
11
10
|
let chalk = require("chalk");
|
|
12
11
|
chalk = require_stdio.__toESM(chalk, 1);
|
|
12
|
+
let _agimon_ai_foundation_exec = require("@agimon-ai/foundation-exec");
|
|
13
13
|
let node_http = require("node:http");
|
|
14
14
|
let _modelcontextprotocol_node = require("@modelcontextprotocol/node");
|
|
15
15
|
//#region src/utils/print.ts
|
|
@@ -425,42 +425,6 @@ const mcpServeCommand = new commander.Command("mcp-serve").description("Start MC
|
|
|
425
425
|
}
|
|
426
426
|
});
|
|
427
427
|
//#endregion
|
|
428
|
-
//#region src/commands/polish-component.ts
|
|
429
|
-
/**
|
|
430
|
-
* Polish Component Command
|
|
431
|
-
*
|
|
432
|
-
* DESIGN PATTERNS:
|
|
433
|
-
* - Command pattern with Commander for CLI argument parsing
|
|
434
|
-
* - Async/await pattern for asynchronous operations
|
|
435
|
-
* - Error handling pattern with try-catch and proper exit codes
|
|
436
|
-
*
|
|
437
|
-
* CODING STANDARDS:
|
|
438
|
-
* - Use async action handlers for asynchronous operations
|
|
439
|
-
* - Handle errors gracefully with process.exit()
|
|
440
|
-
*
|
|
441
|
-
* AVOID:
|
|
442
|
-
* - Synchronous blocking operations in action handlers
|
|
443
|
-
* - Missing error handling (always use try-catch)
|
|
444
|
-
* - Hardcoded values (use options or environment variables)
|
|
445
|
-
*/
|
|
446
|
-
const polishComponentCommand = new commander.Command("polish-component").description("Polish a UI component using Antigravity with design system context").argument("<file>", "Path to the component .tsx file to polish").option("-i, --instructions <text>", "Specific polishing instructions (e.g., \"improve spacing\")").action(async (file, options) => {
|
|
447
|
-
try {
|
|
448
|
-
const result = await require_stdio.createContainer().get(require_stdio.STYLE_SYSTEM_TYPES.PolishComponentTool).execute({
|
|
449
|
-
filePath: file,
|
|
450
|
-
instructions: options.instructions
|
|
451
|
-
});
|
|
452
|
-
if (result.isError) {
|
|
453
|
-
const firstContent = result.content[0];
|
|
454
|
-
const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
|
|
455
|
-
throw new Error(errorText);
|
|
456
|
-
}
|
|
457
|
-
for (const content of result.content) if (content.type === "text") console.error(content.text);
|
|
458
|
-
} catch (error) {
|
|
459
|
-
console.error("Error:", error instanceof Error ? error.message : String(error));
|
|
460
|
-
process.exit(1);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
//#endregion
|
|
464
428
|
//#region src/cli.ts
|
|
465
429
|
/**
|
|
466
430
|
* MCP Server CLI Entry Point
|
|
@@ -493,7 +457,6 @@ async function main() {
|
|
|
493
457
|
program.addCommand(listThemesCommand);
|
|
494
458
|
program.addCommand(listSharedComponentsCommand);
|
|
495
459
|
program.addCommand(mcpServeCommand);
|
|
496
|
-
program.addCommand(polishComponentCommand);
|
|
497
460
|
await program.parseAsync(process.argv);
|
|
498
461
|
}
|
|
499
462
|
main();
|
package/dist/cli.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { A as STYLE_SYSTEM_TYPES, C as getAppDesignSystemConfig, N as DEFAULT_STYLE_SYSTEM_CONFIG, P as TailwindCSSClassesService, R as log, a as STYLE_SYSTEM_CLI_NAME,
|
|
2
|
+
import { A as STYLE_SYSTEM_TYPES, C as getAppDesignSystemConfig, N as DEFAULT_STYLE_SYSTEM_CONFIG, P as TailwindCSSClassesService, R as log, a as STYLE_SYSTEM_CLI_NAME, i as createServer$1, k as resolveStyleSystemThemePath, o as STYLE_SYSTEM_VERSION, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler, y as getBundlerServiceFromConfig } from "./stdio-8KmKB4TW.mjs";
|
|
3
3
|
import { promises } from "node:fs";
|
|
4
4
|
import path, { join } from "node:path";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { registerManagedProcess } from "@agimon-ai/foundation-exec";
|
|
7
6
|
import { createMcpHandler } from "@modelcontextprotocol/server";
|
|
8
7
|
import "reflect-metadata";
|
|
9
8
|
import { Command } from "commander";
|
|
10
9
|
import * as chalkImport from "chalk";
|
|
10
|
+
import { registerManagedProcess } from "@agimon-ai/foundation-exec";
|
|
11
11
|
import { createServer } from "node:http";
|
|
12
12
|
import { localhostHostValidation, localhostOriginValidation, toNodeHandler } from "@modelcontextprotocol/node";
|
|
13
13
|
//#region src/utils/print.ts
|
|
@@ -423,42 +423,6 @@ const mcpServeCommand = new Command("mcp-serve").description("Start MCP server w
|
|
|
423
423
|
}
|
|
424
424
|
});
|
|
425
425
|
//#endregion
|
|
426
|
-
//#region src/commands/polish-component.ts
|
|
427
|
-
/**
|
|
428
|
-
* Polish Component Command
|
|
429
|
-
*
|
|
430
|
-
* DESIGN PATTERNS:
|
|
431
|
-
* - Command pattern with Commander for CLI argument parsing
|
|
432
|
-
* - Async/await pattern for asynchronous operations
|
|
433
|
-
* - Error handling pattern with try-catch and proper exit codes
|
|
434
|
-
*
|
|
435
|
-
* CODING STANDARDS:
|
|
436
|
-
* - Use async action handlers for asynchronous operations
|
|
437
|
-
* - Handle errors gracefully with process.exit()
|
|
438
|
-
*
|
|
439
|
-
* AVOID:
|
|
440
|
-
* - Synchronous blocking operations in action handlers
|
|
441
|
-
* - Missing error handling (always use try-catch)
|
|
442
|
-
* - Hardcoded values (use options or environment variables)
|
|
443
|
-
*/
|
|
444
|
-
const polishComponentCommand = new Command("polish-component").description("Polish a UI component using Antigravity with design system context").argument("<file>", "Path to the component .tsx file to polish").option("-i, --instructions <text>", "Specific polishing instructions (e.g., \"improve spacing\")").action(async (file, options) => {
|
|
445
|
-
try {
|
|
446
|
-
const result = await createContainer().get(STYLE_SYSTEM_TYPES.PolishComponentTool).execute({
|
|
447
|
-
filePath: file,
|
|
448
|
-
instructions: options.instructions
|
|
449
|
-
});
|
|
450
|
-
if (result.isError) {
|
|
451
|
-
const firstContent = result.content[0];
|
|
452
|
-
const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
|
|
453
|
-
throw new Error(errorText);
|
|
454
|
-
}
|
|
455
|
-
for (const content of result.content) if (content.type === "text") console.error(content.text);
|
|
456
|
-
} catch (error) {
|
|
457
|
-
console.error("Error:", error instanceof Error ? error.message : String(error));
|
|
458
|
-
process.exit(1);
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
//#endregion
|
|
462
426
|
//#region src/cli.ts
|
|
463
427
|
/**
|
|
464
428
|
* Main entry point
|
|
@@ -473,7 +437,6 @@ async function main() {
|
|
|
473
437
|
program.addCommand(listThemesCommand);
|
|
474
438
|
program.addCommand(listSharedComponentsCommand);
|
|
475
439
|
program.addCommand(mcpServeCommand);
|
|
476
|
-
program.addCommand(polishComponentCommand);
|
|
477
440
|
await program.parseAsync(process.argv);
|
|
478
441
|
}
|
|
479
442
|
main();
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_stdio = require("./stdio-
|
|
2
|
+
const require_stdio = require("./stdio-DKWqsPkv.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_stdio.__toESM(node_path, 1);
|
|
@@ -87,6 +87,76 @@ var StoryPreviewService = class {
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
//#endregion
|
|
90
|
+
//#region src/services/WarmStoryRenderer/WarmStoryRenderer.ts
|
|
91
|
+
/** The style-system tools a warm host exposes, by tool name. */
|
|
92
|
+
const WARM_RENDERER_TOOLS = {
|
|
93
|
+
get_component_visual: require_stdio.STYLE_SYSTEM_TYPES.GetComponentVisualTool,
|
|
94
|
+
get_css_classes: require_stdio.STYLE_SYSTEM_TYPES.GetCSSClassesTool,
|
|
95
|
+
list_themes: require_stdio.STYLE_SYSTEM_TYPES.ListThemesTool,
|
|
96
|
+
list_shared_components: require_stdio.STYLE_SYSTEM_TYPES.ListSharedComponentsTool,
|
|
97
|
+
list_app_components: require_stdio.STYLE_SYSTEM_TYPES.ListAppComponentsTool
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Keeps one browser and one Vite dev server warm across renders, so a render after the first
|
|
101
|
+
* skips the browser launch and the static build. Rendered screenshots come back as base64.
|
|
102
|
+
*/
|
|
103
|
+
function createWarmStoryRenderer(options = {}) {
|
|
104
|
+
let browser;
|
|
105
|
+
const sharedBrowser = () => {
|
|
106
|
+
browser ??= require_stdio.launchBrowserWithFallback().catch((error) => {
|
|
107
|
+
browser = void 0;
|
|
108
|
+
throw error;
|
|
109
|
+
});
|
|
110
|
+
return browser;
|
|
111
|
+
};
|
|
112
|
+
const container = require_stdio.createContainer({
|
|
113
|
+
sharedBrowser,
|
|
114
|
+
temporaryDirectory: options.temporaryDirectory
|
|
115
|
+
});
|
|
116
|
+
const bundler = require_stdio.createDefaultBundlerService();
|
|
117
|
+
let queue = Promise.resolve();
|
|
118
|
+
let disposed = false;
|
|
119
|
+
const ensureDevServer = async (appPath) => {
|
|
120
|
+
const resolved = node_path.default.resolve(appPath);
|
|
121
|
+
if (bundler.isServerRunning() && bundler.getCurrentAppPath() === resolved) return;
|
|
122
|
+
if (bundler.isServerRunning()) await bundler.cleanup();
|
|
123
|
+
await bundler.startDevServer(resolved);
|
|
124
|
+
};
|
|
125
|
+
const run = async (tool, input) => {
|
|
126
|
+
if (disposed) throw new Error("The story renderer is shut down.");
|
|
127
|
+
if (tool === "get_component_visual" && typeof input.appPath === "string") await ensureDevServer(input.appPath);
|
|
128
|
+
const result = await container.get(WARM_RENDERER_TOOLS[tool]).execute(input);
|
|
129
|
+
const text = result.content.flatMap((item) => item.type === "text" && item.text ? [item.text] : []).join("\n\n");
|
|
130
|
+
const images = [];
|
|
131
|
+
if (tool === "get_component_visual" && !result.isError) {
|
|
132
|
+
const imagePath = /"imagePath":\s*"([^"]+)"/u.exec(text)?.[1];
|
|
133
|
+
if (imagePath) images.push({
|
|
134
|
+
data: (await node_fs.promises.readFile(imagePath)).toString("base64"),
|
|
135
|
+
mimeType: "image/png"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
text,
|
|
140
|
+
images,
|
|
141
|
+
isError: result.isError === true
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
call(tool, input) {
|
|
146
|
+
const next = queue.then(() => run(tool, input));
|
|
147
|
+
queue = next.catch(() => void 0);
|
|
148
|
+
return next;
|
|
149
|
+
},
|
|
150
|
+
async dispose() {
|
|
151
|
+
disposed = true;
|
|
152
|
+
await queue;
|
|
153
|
+
const open = browser;
|
|
154
|
+
browser = void 0;
|
|
155
|
+
await Promise.allSettled([open?.then((instance) => instance.close()), bundler.cleanup()]);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
90
160
|
exports.BaseBundlerService = require_stdio.BaseBundlerService;
|
|
91
161
|
exports.BaseCSSClassesService = require_stdio.BaseCSSClassesService;
|
|
92
162
|
Object.defineProperty(exports, "CSSClassesServiceFactory", {
|
|
@@ -133,12 +203,6 @@ Object.defineProperty(exports, "ListThemesTool", {
|
|
|
133
203
|
return require_stdio.ListThemesTool;
|
|
134
204
|
}
|
|
135
205
|
});
|
|
136
|
-
Object.defineProperty(exports, "PolishComponentTool", {
|
|
137
|
-
enumerable: true,
|
|
138
|
-
get: function() {
|
|
139
|
-
return require_stdio.PolishComponentTool;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
206
|
exports.STYLE_SYSTEM_TYPES = require_stdio.STYLE_SYSTEM_TYPES;
|
|
143
207
|
exports.StdioTransportHandler = require_stdio.StdioTransportHandler;
|
|
144
208
|
Object.defineProperty(exports, "StoriesIndexService", {
|
|
@@ -157,10 +221,12 @@ Object.defineProperty(exports, "StyleSystemConfigLoader", {
|
|
|
157
221
|
exports.TailwindCSSClassesService = require_stdio.TailwindCSSClassesService;
|
|
158
222
|
exports.ThemeService = require_stdio.ThemeService;
|
|
159
223
|
exports.ViteReactBundlerService = require_stdio.ViteReactBundlerService;
|
|
224
|
+
exports.WARM_RENDERER_TOOLS = WARM_RENDERER_TOOLS;
|
|
160
225
|
exports.createContainer = require_stdio.createContainer;
|
|
161
226
|
exports.createDefaultBundlerService = require_stdio.createDefaultBundlerService;
|
|
162
227
|
exports.createServer = require_stdio.createServer;
|
|
163
228
|
exports.createStyleSystemModule = require_stdio.createStyleSystemModule;
|
|
229
|
+
exports.createWarmStoryRenderer = createWarmStoryRenderer;
|
|
164
230
|
exports.extractCustomTokenNames = require_stdio.extractCustomTokenNames;
|
|
165
231
|
exports.generateRestrictedClassesConfig = require_stdio.generateRestrictedClassesConfig;
|
|
166
232
|
exports.getAppDesignSystemConfig = require_stdio.getAppDesignSystemConfig;
|
|
@@ -168,6 +234,7 @@ exports.getBundlerService = require_stdio.getBundlerService;
|
|
|
168
234
|
exports.getBundlerServiceFromConfig = require_stdio.getBundlerServiceFromConfig;
|
|
169
235
|
exports.getSharedComponentTags = require_stdio.getSharedComponentTags;
|
|
170
236
|
exports.hasStyleSystemProjectConfig = require_stdio.hasStyleSystemProjectConfig;
|
|
237
|
+
exports.launchBrowserWithFallback = require_stdio.launchBrowserWithFallback;
|
|
171
238
|
exports.resetStyleSystemConfigCache = require_stdio.resetStyleSystemConfigCache;
|
|
172
239
|
exports.resolveAppDesignSystemConfig = require_stdio.resolveAppDesignSystemConfig;
|
|
173
240
|
exports.resolveStyleSystemThemePath = require_stdio.resolveStyleSystemThemePath;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Container, ContainerModule } from "inversify";
|
|
2
|
+
import { Browser } from "playwright";
|
|
2
3
|
import "zod";
|
|
3
4
|
import { CallToolResult, Server } from "@modelcontextprotocol/server";
|
|
4
5
|
import { AliasOptions, Plugin, UserConfig } from "vite";
|
|
@@ -6,6 +7,8 @@ import { AliasOptions, Plugin, UserConfig } from "vite";
|
|
|
6
7
|
interface StyleSystemModuleOptions {
|
|
7
8
|
defaultThemePath?: string;
|
|
8
9
|
temporaryDirectory?: string;
|
|
10
|
+
/** A browser a long-lived host keeps warm across renders; one-shot CLI runs leave it unset. */
|
|
11
|
+
sharedBrowser?: () => Promise<Browser>;
|
|
9
12
|
}
|
|
10
13
|
export declare function createStyleSystemModule(optionsInput?: StyleSystemModuleOptions): ContainerModule;
|
|
11
14
|
//#endregion
|
|
@@ -16,7 +19,6 @@ export declare const STYLE_SYSTEM_TYPES: {
|
|
|
16
19
|
readonly GetComponentVisualTool: symbol;
|
|
17
20
|
readonly ListSharedComponentsTool: symbol;
|
|
18
21
|
readonly ListAppComponentsTool: symbol;
|
|
19
|
-
readonly PolishComponentTool: symbol;
|
|
20
22
|
readonly ThemeServiceFactory: symbol;
|
|
21
23
|
readonly CSSClassesServiceFactory: symbol;
|
|
22
24
|
readonly StoriesIndexService: symbol;
|
|
@@ -866,6 +868,7 @@ export declare class ComponentRendererService {
|
|
|
866
868
|
private bundlerFactory;
|
|
867
869
|
private log;
|
|
868
870
|
private readonly preserveOutput;
|
|
871
|
+
private readonly sharedBrowser;
|
|
869
872
|
/**
|
|
870
873
|
* Creates a new ComponentRendererService instance
|
|
871
874
|
* @param designSystemConfig - Design system configuration
|
|
@@ -875,6 +878,7 @@ export declare class ComponentRendererService {
|
|
|
875
878
|
constructor(designSystemConfig: DesignSystemConfig, appPath: string, options?: {
|
|
876
879
|
bundlerFactory?: BundlerFactory;
|
|
877
880
|
temporaryDirectory?: string;
|
|
881
|
+
sharedBrowser?: () => Promise<Browser>;
|
|
878
882
|
});
|
|
879
883
|
/**
|
|
880
884
|
* Get the bundler service instance.
|
|
@@ -1985,38 +1989,6 @@ export declare class ListSharedComponentsTool implements Tool<ListSharedComponen
|
|
|
1985
1989
|
execute(input: ListSharedComponentsInput): Promise<CallToolResult>;
|
|
1986
1990
|
}
|
|
1987
1991
|
//#endregion
|
|
1988
|
-
//#region src/tools/PolishComponentTool.d.ts
|
|
1989
|
-
interface PolishComponentInput {
|
|
1990
|
-
filePath: string;
|
|
1991
|
-
instructions?: string;
|
|
1992
|
-
}
|
|
1993
|
-
export declare class PolishComponentTool implements Tool<PolishComponentInput> {
|
|
1994
|
-
static readonly TOOL_NAME = "polish_component";
|
|
1995
|
-
private antigravityService;
|
|
1996
|
-
private getUiComponentService;
|
|
1997
|
-
private cssClassesServiceFactory;
|
|
1998
|
-
private storiesIndexFactory;
|
|
1999
|
-
constructor(getUiComponentService: GetUiComponentService, cssClassesServiceFactory: CSSClassesServiceFactory, storiesIndexFactory: StoriesIndexFactory);
|
|
2000
|
-
getDefinition(): ToolDefinition;
|
|
2001
|
-
execute(input: PolishComponentInput): Promise<CallToolResult>;
|
|
2002
|
-
private detectPlatform;
|
|
2003
|
-
private buildSystemPrompt;
|
|
2004
|
-
/**
|
|
2005
|
-
* Read design tokens from config.themePath.
|
|
2006
|
-
* For web: extracts Tailwind CSS classes. For native: reads the TypeScript types file.
|
|
2007
|
-
*/
|
|
2008
|
-
private getDesignTokens;
|
|
2009
|
-
private findStoriesFile;
|
|
2010
|
-
/**
|
|
2011
|
-
* Find the app that owns a file, for style-system context.
|
|
2012
|
-
* Only apps declaring their own style-system.config.yaml are eligible.
|
|
2013
|
-
*/
|
|
2014
|
-
private findAppPath;
|
|
2015
|
-
private getComponentVisual;
|
|
2016
|
-
private getDesignPrinciples;
|
|
2017
|
-
private getSharedComponents;
|
|
2018
|
-
}
|
|
2019
|
-
//#endregion
|
|
2020
1992
|
//#region src/transports/stdio.d.ts
|
|
2021
1993
|
/** Modern MCP stdio only: reject legacy initialization explicitly. */
|
|
2022
1994
|
export declare class StdioTransportHandler {
|
|
@@ -2028,4 +2000,43 @@ export declare class StdioTransportHandler {
|
|
|
2028
2000
|
stop(): Promise<void>;
|
|
2029
2001
|
}
|
|
2030
2002
|
//#endregion
|
|
2031
|
-
|
|
2003
|
+
//#region src/utils/screenshot.d.ts
|
|
2004
|
+
/**
|
|
2005
|
+
* Attempts to launch a browser, trying multiple configurations in order of preference.
|
|
2006
|
+
* @returns Launched browser instance
|
|
2007
|
+
* @throws Error if no browser can be launched
|
|
2008
|
+
*/
|
|
2009
|
+
export declare function launchBrowserWithFallback(): Promise<Browser>;
|
|
2010
|
+
//#endregion
|
|
2011
|
+
//#region src/services/WarmStoryRenderer/WarmStoryRenderer.d.ts
|
|
2012
|
+
/** The style-system tools a warm host exposes, by tool name. */
|
|
2013
|
+
export declare const WARM_RENDERER_TOOLS: {
|
|
2014
|
+
readonly get_component_visual: symbol;
|
|
2015
|
+
readonly get_css_classes: symbol;
|
|
2016
|
+
readonly list_themes: symbol;
|
|
2017
|
+
readonly list_shared_components: symbol;
|
|
2018
|
+
readonly list_app_components: symbol;
|
|
2019
|
+
};
|
|
2020
|
+
type WarmRendererToolName = keyof typeof WARM_RENDERER_TOOLS;
|
|
2021
|
+
interface WarmRendererResult {
|
|
2022
|
+
text: string;
|
|
2023
|
+
images: {
|
|
2024
|
+
data: string;
|
|
2025
|
+
mimeType: string;
|
|
2026
|
+
}[];
|
|
2027
|
+
isError: boolean;
|
|
2028
|
+
}
|
|
2029
|
+
interface WarmStoryRenderer {
|
|
2030
|
+
/** Runs one tool. Calls are serialized: the dev server serves one app at a time. */
|
|
2031
|
+
call(tool: WarmRendererToolName, input: Record<string, unknown>): Promise<WarmRendererResult>;
|
|
2032
|
+
dispose(): Promise<void>;
|
|
2033
|
+
}
|
|
2034
|
+
/**
|
|
2035
|
+
* Keeps one browser and one Vite dev server warm across renders, so a render after the first
|
|
2036
|
+
* skips the browser launch and the static build. Rendered screenshots come back as base64.
|
|
2037
|
+
*/
|
|
2038
|
+
export declare function createWarmStoryRenderer(options?: {
|
|
2039
|
+
temporaryDirectory?: string;
|
|
2040
|
+
}): WarmStoryRenderer;
|
|
2041
|
+
//#endregion
|
|
2042
|
+
export type { CSSClassCategory, CSSClassValue, CSSClassesResult, DesignSystemConfig, OxlintRestrictedClassPattern, OxlintRestrictedClassesConfig, ResolvedDesignSystemConfig, StoryPreviewIdentity, StoryPreviewInput, StoryPreviewResult, StoryPreviewServiceOptions, StyleSystemConfig, StyleSystemModuleOptions, Tool, ToolDefinition, WarmRendererResult, WarmRendererToolName, WarmStoryRenderer };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Container, ContainerModule } from "inversify";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { Browser } from "playwright";
|
|
3
4
|
import { CallToolResult, Server } from "@modelcontextprotocol/server";
|
|
4
5
|
import { AliasOptions, Plugin, UserConfig } from "vite";
|
|
5
6
|
//#region src/container/module.d.ts
|
|
6
7
|
interface StyleSystemModuleOptions {
|
|
7
8
|
defaultThemePath?: string;
|
|
8
9
|
temporaryDirectory?: string;
|
|
10
|
+
/** A browser a long-lived host keeps warm across renders; one-shot CLI runs leave it unset. */
|
|
11
|
+
sharedBrowser?: () => Promise<Browser>;
|
|
9
12
|
}
|
|
10
13
|
export declare function createStyleSystemModule(optionsInput?: StyleSystemModuleOptions): ContainerModule;
|
|
11
14
|
//#endregion
|
|
@@ -16,7 +19,6 @@ export declare const STYLE_SYSTEM_TYPES: {
|
|
|
16
19
|
readonly GetComponentVisualTool: symbol;
|
|
17
20
|
readonly ListSharedComponentsTool: symbol;
|
|
18
21
|
readonly ListAppComponentsTool: symbol;
|
|
19
|
-
readonly PolishComponentTool: symbol;
|
|
20
22
|
readonly ThemeServiceFactory: symbol;
|
|
21
23
|
readonly CSSClassesServiceFactory: symbol;
|
|
22
24
|
readonly StoriesIndexService: symbol;
|
|
@@ -866,6 +868,7 @@ export declare class ComponentRendererService {
|
|
|
866
868
|
private bundlerFactory;
|
|
867
869
|
private log;
|
|
868
870
|
private readonly preserveOutput;
|
|
871
|
+
private readonly sharedBrowser;
|
|
869
872
|
/**
|
|
870
873
|
* Creates a new ComponentRendererService instance
|
|
871
874
|
* @param designSystemConfig - Design system configuration
|
|
@@ -875,6 +878,7 @@ export declare class ComponentRendererService {
|
|
|
875
878
|
constructor(designSystemConfig: DesignSystemConfig, appPath: string, options?: {
|
|
876
879
|
bundlerFactory?: BundlerFactory;
|
|
877
880
|
temporaryDirectory?: string;
|
|
881
|
+
sharedBrowser?: () => Promise<Browser>;
|
|
878
882
|
});
|
|
879
883
|
/**
|
|
880
884
|
* Get the bundler service instance.
|
|
@@ -1985,38 +1989,6 @@ export declare class ListSharedComponentsTool implements Tool<ListSharedComponen
|
|
|
1985
1989
|
execute(input: ListSharedComponentsInput): Promise<CallToolResult>;
|
|
1986
1990
|
}
|
|
1987
1991
|
//#endregion
|
|
1988
|
-
//#region src/tools/PolishComponentTool.d.ts
|
|
1989
|
-
interface PolishComponentInput {
|
|
1990
|
-
filePath: string;
|
|
1991
|
-
instructions?: string;
|
|
1992
|
-
}
|
|
1993
|
-
export declare class PolishComponentTool implements Tool<PolishComponentInput> {
|
|
1994
|
-
static readonly TOOL_NAME = "polish_component";
|
|
1995
|
-
private antigravityService;
|
|
1996
|
-
private getUiComponentService;
|
|
1997
|
-
private cssClassesServiceFactory;
|
|
1998
|
-
private storiesIndexFactory;
|
|
1999
|
-
constructor(getUiComponentService: GetUiComponentService, cssClassesServiceFactory: CSSClassesServiceFactory, storiesIndexFactory: StoriesIndexFactory);
|
|
2000
|
-
getDefinition(): ToolDefinition;
|
|
2001
|
-
execute(input: PolishComponentInput): Promise<CallToolResult>;
|
|
2002
|
-
private detectPlatform;
|
|
2003
|
-
private buildSystemPrompt;
|
|
2004
|
-
/**
|
|
2005
|
-
* Read design tokens from config.themePath.
|
|
2006
|
-
* For web: extracts Tailwind CSS classes. For native: reads the TypeScript types file.
|
|
2007
|
-
*/
|
|
2008
|
-
private getDesignTokens;
|
|
2009
|
-
private findStoriesFile;
|
|
2010
|
-
/**
|
|
2011
|
-
* Find the app that owns a file, for style-system context.
|
|
2012
|
-
* Only apps declaring their own style-system.config.yaml are eligible.
|
|
2013
|
-
*/
|
|
2014
|
-
private findAppPath;
|
|
2015
|
-
private getComponentVisual;
|
|
2016
|
-
private getDesignPrinciples;
|
|
2017
|
-
private getSharedComponents;
|
|
2018
|
-
}
|
|
2019
|
-
//#endregion
|
|
2020
1992
|
//#region src/transports/stdio.d.ts
|
|
2021
1993
|
/** Modern MCP stdio only: reject legacy initialization explicitly. */
|
|
2022
1994
|
export declare class StdioTransportHandler {
|
|
@@ -2028,4 +2000,43 @@ export declare class StdioTransportHandler {
|
|
|
2028
2000
|
stop(): Promise<void>;
|
|
2029
2001
|
}
|
|
2030
2002
|
//#endregion
|
|
2031
|
-
|
|
2003
|
+
//#region src/utils/screenshot.d.ts
|
|
2004
|
+
/**
|
|
2005
|
+
* Attempts to launch a browser, trying multiple configurations in order of preference.
|
|
2006
|
+
* @returns Launched browser instance
|
|
2007
|
+
* @throws Error if no browser can be launched
|
|
2008
|
+
*/
|
|
2009
|
+
export declare function launchBrowserWithFallback(): Promise<Browser>;
|
|
2010
|
+
//#endregion
|
|
2011
|
+
//#region src/services/WarmStoryRenderer/WarmStoryRenderer.d.ts
|
|
2012
|
+
/** The style-system tools a warm host exposes, by tool name. */
|
|
2013
|
+
export declare const WARM_RENDERER_TOOLS: {
|
|
2014
|
+
readonly get_component_visual: symbol;
|
|
2015
|
+
readonly get_css_classes: symbol;
|
|
2016
|
+
readonly list_themes: symbol;
|
|
2017
|
+
readonly list_shared_components: symbol;
|
|
2018
|
+
readonly list_app_components: symbol;
|
|
2019
|
+
};
|
|
2020
|
+
type WarmRendererToolName = keyof typeof WARM_RENDERER_TOOLS;
|
|
2021
|
+
interface WarmRendererResult {
|
|
2022
|
+
text: string;
|
|
2023
|
+
images: {
|
|
2024
|
+
data: string;
|
|
2025
|
+
mimeType: string;
|
|
2026
|
+
}[];
|
|
2027
|
+
isError: boolean;
|
|
2028
|
+
}
|
|
2029
|
+
interface WarmStoryRenderer {
|
|
2030
|
+
/** Runs one tool. Calls are serialized: the dev server serves one app at a time. */
|
|
2031
|
+
call(tool: WarmRendererToolName, input: Record<string, unknown>): Promise<WarmRendererResult>;
|
|
2032
|
+
dispose(): Promise<void>;
|
|
2033
|
+
}
|
|
2034
|
+
/**
|
|
2035
|
+
* Keeps one browser and one Vite dev server warm across renders, so a render after the first
|
|
2036
|
+
* skips the browser launch and the static build. Rendered screenshots come back as base64.
|
|
2037
|
+
*/
|
|
2038
|
+
export declare function createWarmStoryRenderer(options?: {
|
|
2039
|
+
temporaryDirectory?: string;
|
|
2040
|
+
}): WarmStoryRenderer;
|
|
2041
|
+
//#endregion
|
|
2042
|
+
export type { CSSClassCategory, CSSClassValue, CSSClassesResult, DesignSystemConfig, OxlintRestrictedClassPattern, OxlintRestrictedClassesConfig, ResolvedDesignSystemConfig, StoryPreviewIdentity, StoryPreviewInput, StoryPreviewResult, StoryPreviewServiceOptions, StyleSystemConfig, StyleSystemModuleOptions, Tool, ToolDefinition, WarmRendererResult, WarmRendererToolName, WarmStoryRenderer };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as STYLE_SYSTEM_TYPES, C as getAppDesignSystemConfig, D as resolveAppDesignSystemConfig, E as resetStyleSystemConfigCache, F as BaseCSSClassesService, I as TemplatesManagerService, L as isContained, M as CSSClassesServiceFactory, N as DEFAULT_STYLE_SYSTEM_CONFIG, O as StyleSystemConfigLoader, P as TailwindCSSClassesService, S as
|
|
1
|
+
import { A as STYLE_SYSTEM_TYPES, C as getAppDesignSystemConfig, D as resolveAppDesignSystemConfig, E as resetStyleSystemConfigCache, F as BaseCSSClassesService, I as TemplatesManagerService, L as isContained, M as CSSClassesServiceFactory, N as DEFAULT_STYLE_SYSTEM_CONFIG, O as StyleSystemConfigLoader, P as TailwindCSSClassesService, S as launchBrowserWithFallback, T as hasStyleSystemProjectConfig, _ as createDefaultBundlerService, b as ViteReactBundlerService, c as createStyleSystemModule, d as GetComponentVisualTool, f as GetCSSClassesTool, g as ThemeService, h as ComponentRendererService, i as createServer, j as StoriesIndexService, k as resolveStyleSystemThemePath, l as ListAppComponentsTool, m as GetUiComponentService, n as extractCustomTokenNames, p as ListThemesTool, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler, u as ListSharedComponentsTool, v as getBundlerService, w as getSharedComponentTags, x as BaseBundlerService, y as getBundlerServiceFromConfig } from "./stdio-8KmKB4TW.mjs";
|
|
2
2
|
import { promises } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -85,4 +85,74 @@ var StoryPreviewService = class {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
//#endregion
|
|
88
|
-
|
|
88
|
+
//#region src/services/WarmStoryRenderer/WarmStoryRenderer.ts
|
|
89
|
+
/** The style-system tools a warm host exposes, by tool name. */
|
|
90
|
+
const WARM_RENDERER_TOOLS = {
|
|
91
|
+
get_component_visual: STYLE_SYSTEM_TYPES.GetComponentVisualTool,
|
|
92
|
+
get_css_classes: STYLE_SYSTEM_TYPES.GetCSSClassesTool,
|
|
93
|
+
list_themes: STYLE_SYSTEM_TYPES.ListThemesTool,
|
|
94
|
+
list_shared_components: STYLE_SYSTEM_TYPES.ListSharedComponentsTool,
|
|
95
|
+
list_app_components: STYLE_SYSTEM_TYPES.ListAppComponentsTool
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Keeps one browser and one Vite dev server warm across renders, so a render after the first
|
|
99
|
+
* skips the browser launch and the static build. Rendered screenshots come back as base64.
|
|
100
|
+
*/
|
|
101
|
+
function createWarmStoryRenderer(options = {}) {
|
|
102
|
+
let browser;
|
|
103
|
+
const sharedBrowser = () => {
|
|
104
|
+
browser ??= launchBrowserWithFallback().catch((error) => {
|
|
105
|
+
browser = void 0;
|
|
106
|
+
throw error;
|
|
107
|
+
});
|
|
108
|
+
return browser;
|
|
109
|
+
};
|
|
110
|
+
const container = createContainer({
|
|
111
|
+
sharedBrowser,
|
|
112
|
+
temporaryDirectory: options.temporaryDirectory
|
|
113
|
+
});
|
|
114
|
+
const bundler = createDefaultBundlerService();
|
|
115
|
+
let queue = Promise.resolve();
|
|
116
|
+
let disposed = false;
|
|
117
|
+
const ensureDevServer = async (appPath) => {
|
|
118
|
+
const resolved = path.resolve(appPath);
|
|
119
|
+
if (bundler.isServerRunning() && bundler.getCurrentAppPath() === resolved) return;
|
|
120
|
+
if (bundler.isServerRunning()) await bundler.cleanup();
|
|
121
|
+
await bundler.startDevServer(resolved);
|
|
122
|
+
};
|
|
123
|
+
const run = async (tool, input) => {
|
|
124
|
+
if (disposed) throw new Error("The story renderer is shut down.");
|
|
125
|
+
if (tool === "get_component_visual" && typeof input.appPath === "string") await ensureDevServer(input.appPath);
|
|
126
|
+
const result = await container.get(WARM_RENDERER_TOOLS[tool]).execute(input);
|
|
127
|
+
const text = result.content.flatMap((item) => item.type === "text" && item.text ? [item.text] : []).join("\n\n");
|
|
128
|
+
const images = [];
|
|
129
|
+
if (tool === "get_component_visual" && !result.isError) {
|
|
130
|
+
const imagePath = /"imagePath":\s*"([^"]+)"/u.exec(text)?.[1];
|
|
131
|
+
if (imagePath) images.push({
|
|
132
|
+
data: (await promises.readFile(imagePath)).toString("base64"),
|
|
133
|
+
mimeType: "image/png"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
text,
|
|
138
|
+
images,
|
|
139
|
+
isError: result.isError === true
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
call(tool, input) {
|
|
144
|
+
const next = queue.then(() => run(tool, input));
|
|
145
|
+
queue = next.catch(() => void 0);
|
|
146
|
+
return next;
|
|
147
|
+
},
|
|
148
|
+
async dispose() {
|
|
149
|
+
disposed = true;
|
|
150
|
+
await queue;
|
|
151
|
+
const open = browser;
|
|
152
|
+
browser = void 0;
|
|
153
|
+
await Promise.allSettled([open?.then((instance) => instance.close()), bundler.cleanup()]);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { BaseBundlerService, BaseCSSClassesService, CSSClassesServiceFactory, ComponentRendererService, DEFAULT_STYLE_SYSTEM_CONFIG, GetCSSClassesTool, GetComponentVisualTool, GetUiComponentService, ListAppComponentsTool, ListSharedComponentsTool, ListThemesTool, STYLE_SYSTEM_TYPES, StdioTransportHandler, StoriesIndexService, StoryPreviewService, StyleSystemConfigLoader, TailwindCSSClassesService, ThemeService, ViteReactBundlerService, WARM_RENDERER_TOOLS, createContainer, createDefaultBundlerService, createServer, createStyleSystemModule, createWarmStoryRenderer, extractCustomTokenNames, generateRestrictedClassesConfig, getAppDesignSystemConfig, getBundlerService, getBundlerServiceFromConfig, getSharedComponentTags, hasStyleSystemProjectConfig, launchBrowserWithFallback, resetStyleSystemConfigCache, resolveAppDesignSystemConfig, resolveStyleSystemThemePath };
|