@agimon-ai/po-style-system-tooling 0.2.14-alpha.2 → 0.2.14-alpha.20

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/LICENSE CHANGED
@@ -1,21 +1,149 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Vuong Ngo
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
2
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
3
+
4
+ Parameters
5
+
6
+ Licensor: Agimon Pty Ltd
7
+ Licensed Work: Po, the software in the Po source repository and the
8
+ packages released from it, in each version released by
9
+ the Licensor.
10
+ The Licensed Work is (c) 2026 Agimon Pty Ltd.
11
+ Material identified as third-party in the "Third-party
12
+ components" section at the end of this file or in a
13
+ NOTICE file, and any package or directory whose own
14
+ license file grants a different license, is not part of
15
+ the Licensed Work and remains under its own license.
16
+ Additional Use Grant: You may make production use of the Licensed Work if
17
+ your use is Eligible Use. "Eligible Use" is production use that falls
18
+ within at least one of the following:
19
+
20
+ (a) Personal Use. Use by an individual for their own personal purposes,
21
+ and not on behalf of, or for the benefit of, an employer, client, or
22
+ other Organization. Use by an individual in the course of employment
23
+ or engagement by an Organization is use by that Organization.
24
+
25
+ (b) Small Organization Use. Use by or on behalf of an Organization whose
26
+ Annual Revenue is less than USD 1,000,000.
27
+
28
+ (c) Non-profit, Education and Research Use. Use, regardless of Annual
29
+ Revenue, by (i) an Organization registered or recognized as a
30
+ non-profit or charitable organization under the laws of its
31
+ jurisdiction, for its non-profit purposes; (ii) an accredited school,
32
+ college, or university, for teaching, learning, or academic research;
33
+ or (iii) a publicly funded research institution, for its research.
34
+
35
+ (d) Service Provider Use. Use by a consultant, contractor, agency, or other
36
+ service provider, regardless of its own Annual Revenue, solely to
37
+ build, deploy, host, operate, or support the Licensed Work for a client
38
+ whose own use would be Eligible Use under (a), (b), or (c). A service
39
+ provider's use for its own purposes is Eligible Use only if the service
40
+ provider itself qualifies under (b) or (c).
41
+
42
+
43
+ Hosted services. Offering the Licensed Work to third parties as a hosted
44
+ or managed service whose primary value is the Licensed Work is Eligible
45
+ Use only if each such third party's own use would be Eligible Use.
46
+
47
+ Definitions. "Organization" means any company, partnership, sole
48
+ proprietorship, trust, association, government body, or other entity, and
49
+ includes an individual acting in a business or professional capacity.
50
+ "Affiliate" means any entity that directly or indirectly controls, is
51
+ controlled by, or is under common control with an Organization, where
52
+ "control" means ownership of more than 50% of the voting interests of an
53
+ entity or the power to direct its management and policies by contract or
54
+ otherwise. "Annual Revenue" means the total gross revenue of an
55
+ Organization and all of its Affiliates combined, from all sources and
56
+ whether or not related to the Licensed Work, for its most recently
57
+ completed fiscal year, or, if it has not completed a fiscal year, for the
58
+ twelve months before the use (or since its formation, if shorter),
59
+ converted into US dollars at the average exchange rate for that period.
60
+ Proceeds of equity or debt financing are not revenue.
61
+
62
+ Threshold. If an Organization stops qualifying under (b), its existing
63
+ production use remains Eligible Use for 90 days after it stops
64
+ qualifying, after which it must obtain a commercial license or stop
65
+ production use. Use that was Eligible Use when it occurred never requires
66
+ a commercial license after the fact.
67
+ Change Date: Four years from the date a version of the Licensed Work
68
+ is first publicly released by the Licensor.
69
+ Change License: Apache License, Version 2.0
70
+
71
+ For information about alternative licensing arrangements for the Licensed
72
+ Work, please visit: https://agimon.ai/licensing
73
+
74
+ Notice
75
+
76
+ The Business Source License (this document, or the "License") is not an Open
77
+ Source license. However, the Licensed Work will eventually be made available
78
+ under an Open Source License, as stated in this License.
79
+
80
+ -----------------------------------------------------------------------------
81
+
82
+ Business Source License 1.1
83
+
84
+ Terms
85
+
86
+ The Licensor hereby grants you the right to copy, modify, create derivative
87
+ works, redistribute, and make non-production use of the Licensed Work. The
88
+ Licensor may make an Additional Use Grant, above, permitting limited
89
+ production use.
90
+
91
+ Effective on the Change Date, or the fourth anniversary of the first publicly
92
+ available distribution of a specific version of the Licensed Work under this
93
+ License, whichever comes first, the Licensor hereby grants you rights under
94
+ the terms of the Change License, and the rights granted in the paragraph
95
+ above terminate.
96
+
97
+ If your use of the Licensed Work does not comply with the requirements
98
+ currently in effect as described in this License, you must purchase a
99
+ commercial license from the Licensor, its affiliated entities, or authorized
100
+ resellers, or you must refrain from using the Licensed Work.
101
+
102
+ All copies of the original and modified Licensed Work, and derivative works
103
+ of the Licensed Work, are subject to this License. This License applies
104
+ separately for each version of the Licensed Work and the Change Date may vary
105
+ for each version of the Licensed Work released by Licensor.
106
+
107
+ You must conspicuously display this License on each original or modified copy
108
+ of the Licensed Work. If you receive the Licensed Work in original or
109
+ modified form from a third party, the terms and conditions set forth in this
110
+ License apply to your use of that work.
111
+
112
+ Any use of the Licensed Work in violation of this License will automatically
113
+ terminate your rights under this License for the current and all other
114
+ versions of the Licensed Work.
115
+
116
+ This License does not grant you any right in any trademark or logo of
117
+ Licensor or its affiliates (provided that you may use a trademark or logo of
118
+ Licensor as expressly required by this License).
119
+
120
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
121
+ AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
122
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
123
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
124
+ TITLE.
125
+
126
+ MariaDB hereby grants you permission to use this License’s text to license
127
+ your works, and to refer to it using the trademark “Business Source License”,
128
+ as long as you comply with the Covenants of Licensor below.
129
+
130
+ Covenants of Licensor
131
+
132
+ In consideration of the right to use this License’s text and the “Business
133
+ Source License” name and trademark, Licensor covenants to MariaDB, and to all
134
+ other recipients of the licensed work to be provided by Licensor:
135
+
136
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
137
+ or a license that is compatible with GPL Version 2.0 or a later version,
138
+ where “compatible” means that software provided under the Change License can
139
+ be included in a program with software provided under GPL Version 2.0 or a
140
+ later version. Licensor may specify additional Change Licenses without
141
+ limitation.
142
+
143
+ 2. To either: (a) specify an additional grant of rights to use that does not
144
+ impose any additional restriction on the right granted in this License, as
145
+ the Additional Use Grant; or (b) insert the text “None”.
146
+
147
+ 3. To specify a Change Date.
148
+
149
+ 4. Not to modify this License in any other way.
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
 
@@ -146,4 +145,4 @@ these commands.
146
145
 
147
146
  ## License
148
147
 
149
- MIT
148
+ Business Source License 1.1: free for personal use, organisations under USD 1M revenue, non-profits and education. See [LICENSE](LICENSE) and https://agimon.ai/licensing.
package/dist/cli.cjs CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- const require_stdio = require("./stdio-CT9XjOJQ.cjs");
2
+ const require_stdio = require("./stdio-7W52L7gp.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
@@ -138,7 +138,8 @@ const REQUESTABLE_COLOR_SCHEMES = [LIGHT_COLOR_SCHEME, DARK_COLOR_SCHEME];
138
138
  const getUiComponentCommand = new commander.Command("get-ui-component").description("Get a screenshot of a UI component rendered with app-specific design system configuration. Returns screenshot path and story file content.").requiredOption("-c, --component-name <name>", "The name of the component to capture (e.g., \"Button\", \"Card\")").requiredOption("-a, --app-path <path>", "The app path (relative or absolute) to load design system config from (e.g., \"apps/agiflow-app\")").option("-s, --story-name <name>", "The story name to render (e.g., \"Playground\", \"Default\")", "Playground").option("-d, --dark-mode", "Request dark mode for automatic-theme apps").option("--color-scheme <scheme>", "Request light or dark mode for automatic-theme apps").option("--width <pixels>", "Override the configured viewport width", Number).option("--height <pixels>", "Override the configured viewport height", Number).action(async (options) => {
139
139
  try {
140
140
  if (options.colorScheme !== void 0 && !REQUESTABLE_COLOR_SCHEMES.includes(options.colorScheme)) throw new Error("--color-scheme must be light or dark");
141
- const tool = require_stdio.createContainer().get(require_stdio.STYLE_SYSTEM_TYPES.GetComponentVisualTool);
141
+ const sessionTemp = process.env.PO_SESSION_TEMP_DIR;
142
+ const tool = require_stdio.createContainer({ temporaryDirectory: sessionTemp ? (0, node_path.join)(sessionTemp, "previews") : void 0 }).get(require_stdio.STYLE_SYSTEM_TYPES.GetComponentVisualTool);
142
143
  const darkMode = options.colorScheme === DARK_COLOR_SCHEME ? true : options.colorScheme === LIGHT_COLOR_SCHEME ? false : options.darkMode || void 0;
143
144
  const result = await tool.execute({
144
145
  componentName: options.componentName,
@@ -405,7 +406,11 @@ const mcpServeCommand = new commander.Command("mcp-serve").description("Start MC
405
406
  console.error(`Dev server started at ${url} (port: ${port})`);
406
407
  }
407
408
  if (transportType === "stdio") {
408
- const container = require_stdio.createContainer({ defaultThemePath: parsed.themePath });
409
+ const sessionTemp = process.env.PO_SESSION_TEMP_DIR;
410
+ const container = require_stdio.createContainer({
411
+ defaultThemePath: parsed.themePath,
412
+ temporaryDirectory: sessionTemp ? (0, node_path.join)(sessionTemp, "previews") : void 0
413
+ });
409
414
  await startServer(new require_stdio.StdioTransportHandler(() => require_stdio.createServer(container)), bundlerService, devServerPort);
410
415
  } else if (transportType === "http" && parsed.port !== void 0) {
411
416
  const container = require_stdio.createContainer({ defaultThemePath: parsed.themePath });
@@ -420,42 +425,6 @@ const mcpServeCommand = new commander.Command("mcp-serve").description("Start MC
420
425
  }
421
426
  });
422
427
  //#endregion
423
- //#region src/commands/polish-component.ts
424
- /**
425
- * Polish Component Command
426
- *
427
- * DESIGN PATTERNS:
428
- * - Command pattern with Commander for CLI argument parsing
429
- * - Async/await pattern for asynchronous operations
430
- * - Error handling pattern with try-catch and proper exit codes
431
- *
432
- * CODING STANDARDS:
433
- * - Use async action handlers for asynchronous operations
434
- * - Handle errors gracefully with process.exit()
435
- *
436
- * AVOID:
437
- * - Synchronous blocking operations in action handlers
438
- * - Missing error handling (always use try-catch)
439
- * - Hardcoded values (use options or environment variables)
440
- */
441
- 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) => {
442
- try {
443
- const result = await require_stdio.createContainer().get(require_stdio.STYLE_SYSTEM_TYPES.PolishComponentTool).execute({
444
- filePath: file,
445
- instructions: options.instructions
446
- });
447
- if (result.isError) {
448
- const firstContent = result.content[0];
449
- const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
450
- throw new Error(errorText);
451
- }
452
- for (const content of result.content) if (content.type === "text") console.error(content.text);
453
- } catch (error) {
454
- console.error("Error:", error instanceof Error ? error.message : String(error));
455
- process.exit(1);
456
- }
457
- });
458
- //#endregion
459
428
  //#region src/cli.ts
460
429
  /**
461
430
  * MCP Server CLI Entry Point
@@ -488,7 +457,6 @@ async function main() {
488
457
  program.addCommand(listThemesCommand);
489
458
  program.addCommand(listSharedComponentsCommand);
490
459
  program.addCommand(mcpServeCommand);
491
- program.addCommand(polishComponentCommand);
492
460
  await program.parseAsync(process.argv);
493
461
  }
494
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, b as getBundlerServiceFromConfig, i as createServer$1, k as resolveStyleSystemThemePath, o as STYLE_SYSTEM_VERSION, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler } from "./stdio-Dgaj2-_8.mjs";
2
+ import { A as resolveStyleSystemThemePath, B as STYLE_SYSTEM_TYPES, F as TailwindCSSClassesService, P as DEFAULT_STYLE_SYSTEM_CONFIG, a as STYLE_SYSTEM_CLI_NAME, i as createServer$1, o as STYLE_SYSTEM_VERSION, r as generateRestrictedClassesConfig, s as createContainer, t as StdioTransportHandler, w as getAppDesignSystemConfig, y as getBundlerServiceFromConfig, z as log } from "./stdio-Cs3GzGK4.mjs";
3
3
  import { promises } from "node:fs";
4
- import path from "node:path";
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
@@ -136,7 +136,8 @@ const REQUESTABLE_COLOR_SCHEMES = [LIGHT_COLOR_SCHEME, DARK_COLOR_SCHEME];
136
136
  const getUiComponentCommand = new Command("get-ui-component").description("Get a screenshot of a UI component rendered with app-specific design system configuration. Returns screenshot path and story file content.").requiredOption("-c, --component-name <name>", "The name of the component to capture (e.g., \"Button\", \"Card\")").requiredOption("-a, --app-path <path>", "The app path (relative or absolute) to load design system config from (e.g., \"apps/agiflow-app\")").option("-s, --story-name <name>", "The story name to render (e.g., \"Playground\", \"Default\")", "Playground").option("-d, --dark-mode", "Request dark mode for automatic-theme apps").option("--color-scheme <scheme>", "Request light or dark mode for automatic-theme apps").option("--width <pixels>", "Override the configured viewport width", Number).option("--height <pixels>", "Override the configured viewport height", Number).action(async (options) => {
137
137
  try {
138
138
  if (options.colorScheme !== void 0 && !REQUESTABLE_COLOR_SCHEMES.includes(options.colorScheme)) throw new Error("--color-scheme must be light or dark");
139
- const tool = createContainer().get(STYLE_SYSTEM_TYPES.GetComponentVisualTool);
139
+ const sessionTemp = process.env.PO_SESSION_TEMP_DIR;
140
+ const tool = createContainer({ temporaryDirectory: sessionTemp ? join(sessionTemp, "previews") : void 0 }).get(STYLE_SYSTEM_TYPES.GetComponentVisualTool);
140
141
  const darkMode = options.colorScheme === DARK_COLOR_SCHEME ? true : options.colorScheme === LIGHT_COLOR_SCHEME ? false : options.darkMode || void 0;
141
142
  const result = await tool.execute({
142
143
  componentName: options.componentName,
@@ -403,7 +404,11 @@ const mcpServeCommand = new Command("mcp-serve").description("Start MCP server w
403
404
  console.error(`Dev server started at ${url} (port: ${port})`);
404
405
  }
405
406
  if (transportType === "stdio") {
406
- const container = createContainer({ defaultThemePath: parsed.themePath });
407
+ const sessionTemp = process.env.PO_SESSION_TEMP_DIR;
408
+ const container = createContainer({
409
+ defaultThemePath: parsed.themePath,
410
+ temporaryDirectory: sessionTemp ? join(sessionTemp, "previews") : void 0
411
+ });
407
412
  await startServer(new StdioTransportHandler(() => createServer$1(container)), bundlerService, devServerPort);
408
413
  } else if (transportType === "http" && parsed.port !== void 0) {
409
414
  const container = createContainer({ defaultThemePath: parsed.themePath });
@@ -418,42 +423,6 @@ const mcpServeCommand = new Command("mcp-serve").description("Start MCP server w
418
423
  }
419
424
  });
420
425
  //#endregion
421
- //#region src/commands/polish-component.ts
422
- /**
423
- * Polish Component Command
424
- *
425
- * DESIGN PATTERNS:
426
- * - Command pattern with Commander for CLI argument parsing
427
- * - Async/await pattern for asynchronous operations
428
- * - Error handling pattern with try-catch and proper exit codes
429
- *
430
- * CODING STANDARDS:
431
- * - Use async action handlers for asynchronous operations
432
- * - Handle errors gracefully with process.exit()
433
- *
434
- * AVOID:
435
- * - Synchronous blocking operations in action handlers
436
- * - Missing error handling (always use try-catch)
437
- * - Hardcoded values (use options or environment variables)
438
- */
439
- 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) => {
440
- try {
441
- const result = await createContainer().get(STYLE_SYSTEM_TYPES.PolishComponentTool).execute({
442
- filePath: file,
443
- instructions: options.instructions
444
- });
445
- if (result.isError) {
446
- const firstContent = result.content[0];
447
- const errorText = firstContent?.type === "text" ? firstContent.text : "Unknown error";
448
- throw new Error(errorText);
449
- }
450
- for (const content of result.content) if (content.type === "text") console.error(content.text);
451
- } catch (error) {
452
- console.error("Error:", error instanceof Error ? error.message : String(error));
453
- process.exit(1);
454
- }
455
- });
456
- //#endregion
457
426
  //#region src/cli.ts
458
427
  /**
459
428
  * Main entry point
@@ -468,7 +437,6 @@ async function main() {
468
437
  program.addCommand(listThemesCommand);
469
438
  program.addCommand(listSharedComponentsCommand);
470
439
  program.addCommand(mcpServeCommand);
471
- program.addCommand(polishComponentCommand);
472
440
  await program.parseAsync(process.argv);
473
441
  }
474
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-CT9XjOJQ.cjs");
2
+ const require_stdio = require("./stdio-7W52L7gp.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,127 @@ 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
+ const workspaceRoot = options.workspaceRoot ? node_path.default.resolve(options.workspaceRoot) : void 0;
105
+ let browser;
106
+ const sharedBrowser = () => {
107
+ browser ??= require_stdio.launchBrowserWithFallback().catch((error) => {
108
+ browser = void 0;
109
+ throw error;
110
+ });
111
+ return browser;
112
+ };
113
+ let activeBundler;
114
+ const bundlers = /* @__PURE__ */ new Map();
115
+ const container = require_stdio.createContainer({
116
+ ...options,
117
+ workspaceRoot,
118
+ sharedBrowser,
119
+ bundlerFactory: () => {
120
+ if (!activeBundler) throw new Error("The story bundler has not been initialized.");
121
+ return activeBundler;
122
+ }
123
+ });
124
+ const configLoader = container.get(require_stdio.STYLE_SYSTEM_TYPES.StyleSystemConfigLoader);
125
+ const createBundler = (config) => config.bundler ? require_stdio.getBundlerService(config.bundler, workspaceRoot) : require_stdio.createDefaultBundlerService(workspaceRoot);
126
+ let queue = Promise.resolve();
127
+ let disposed = false;
128
+ const ensureDevServer = async (appPath) => {
129
+ const resolved = node_path.default.resolve(workspaceRoot ?? ".", appPath);
130
+ const { config } = await configLoader.resolveProject(resolved);
131
+ const key = config.bundler ?? "vite-react";
132
+ let pending = bundlers.get(key);
133
+ if (!pending) {
134
+ pending = workspaceRoot ? require_stdio.getBundlerServiceFromConfig({
135
+ workspaceRoot,
136
+ configLoader,
137
+ defaultFactory: () => createBundler(config)
138
+ }) : Promise.resolve(createBundler(config));
139
+ bundlers.set(key, pending);
140
+ pending.catch(() => bundlers.delete(key));
141
+ }
142
+ const bundler = await pending;
143
+ if (activeBundler && activeBundler !== bundler && activeBundler.isServerRunning()) await activeBundler.cleanup();
144
+ activeBundler = bundler;
145
+ if (bundler.isServerRunning() && bundler.getCurrentAppPath() === resolved) return;
146
+ if (bundler.isServerRunning()) await bundler.cleanup();
147
+ await bundler.startDevServer(resolved);
148
+ };
149
+ const reset = async () => {
150
+ const open = browser;
151
+ browser = void 0;
152
+ await Promise.allSettled([open?.then((instance) => instance.close()), ...[...bundlers.values()].map((pending) => pending.then((bundler) => bundler.cleanup()))]);
153
+ };
154
+ const run = async (tool, input) => {
155
+ if (disposed) throw new Error("The story renderer is shut down.");
156
+ if (workspaceRoot && typeof input.appPath === "string") {
157
+ const [root, appPath] = await Promise.all([node_fs.promises.realpath(workspaceRoot), node_fs.promises.realpath(node_path.default.resolve(workspaceRoot, input.appPath))]);
158
+ if (!require_stdio.isContained(root, appPath)) throw new Error("appPath must remain inside the configured workspace root.");
159
+ input = {
160
+ ...input,
161
+ appPath
162
+ };
163
+ }
164
+ const visualAppPath = tool === "get_component_visual" && typeof input.appPath === "string" ? input.appPath : void 0;
165
+ const execute = async () => {
166
+ if (visualAppPath) await ensureDevServer(visualAppPath);
167
+ const result = await container.get(WARM_RENDERER_TOOLS[tool]).execute(input);
168
+ return {
169
+ result,
170
+ text: result.content.flatMap((item) => item.type === "text" && item.text ? [item.text] : []).join("\n\n")
171
+ };
172
+ };
173
+ let { result, text } = await execute();
174
+ if (visualAppPath && result.isError && text.includes("Failed to render component")) {
175
+ await reset();
176
+ ({result, text} = await execute());
177
+ }
178
+ const images = [];
179
+ if (tool === "get_component_visual" && !result.isError) {
180
+ const imagePath = /"imagePath":\s*"([^"]+)"/u.exec(text)?.[1];
181
+ if (imagePath) images.push({
182
+ data: (await node_fs.promises.readFile(imagePath)).toString("base64"),
183
+ mimeType: "image/png"
184
+ });
185
+ }
186
+ return {
187
+ text,
188
+ images,
189
+ isError: result.isError === true
190
+ };
191
+ };
192
+ return {
193
+ call(tool, input) {
194
+ const next = queue.then(() => run(tool, input));
195
+ queue = next.catch(() => void 0);
196
+ return next;
197
+ },
198
+ restart() {
199
+ const next = queue.then(reset);
200
+ queue = next.catch(() => void 0);
201
+ return next;
202
+ },
203
+ async dispose() {
204
+ disposed = true;
205
+ await queue;
206
+ await reset();
207
+ }
208
+ };
209
+ }
210
+ //#endregion
90
211
  exports.BaseBundlerService = require_stdio.BaseBundlerService;
91
212
  exports.BaseCSSClassesService = require_stdio.BaseCSSClassesService;
92
213
  Object.defineProperty(exports, "CSSClassesServiceFactory", {
@@ -133,12 +254,7 @@ Object.defineProperty(exports, "ListThemesTool", {
133
254
  return require_stdio.ListThemesTool;
134
255
  }
135
256
  });
136
- Object.defineProperty(exports, "PolishComponentTool", {
137
- enumerable: true,
138
- get: function() {
139
- return require_stdio.PolishComponentTool;
140
- }
141
- });
257
+ exports.MAX_STYLE_SYSTEM_VIEWPORT_DIMENSION = require_stdio.MAX_STYLE_SYSTEM_VIEWPORT_DIMENSION;
142
258
  exports.STYLE_SYSTEM_TYPES = require_stdio.STYLE_SYSTEM_TYPES;
143
259
  exports.StdioTransportHandler = require_stdio.StdioTransportHandler;
144
260
  Object.defineProperty(exports, "StoriesIndexService", {
@@ -157,10 +273,13 @@ Object.defineProperty(exports, "StyleSystemConfigLoader", {
157
273
  exports.TailwindCSSClassesService = require_stdio.TailwindCSSClassesService;
158
274
  exports.ThemeService = require_stdio.ThemeService;
159
275
  exports.ViteReactBundlerService = require_stdio.ViteReactBundlerService;
276
+ exports.ViteReactNativeBundlerService = require_stdio.ViteReactNativeBundlerService;
277
+ exports.WARM_RENDERER_TOOLS = WARM_RENDERER_TOOLS;
160
278
  exports.createContainer = require_stdio.createContainer;
161
279
  exports.createDefaultBundlerService = require_stdio.createDefaultBundlerService;
162
280
  exports.createServer = require_stdio.createServer;
163
281
  exports.createStyleSystemModule = require_stdio.createStyleSystemModule;
282
+ exports.createWarmStoryRenderer = createWarmStoryRenderer;
164
283
  exports.extractCustomTokenNames = require_stdio.extractCustomTokenNames;
165
284
  exports.generateRestrictedClassesConfig = require_stdio.generateRestrictedClassesConfig;
166
285
  exports.getAppDesignSystemConfig = require_stdio.getAppDesignSystemConfig;
@@ -168,6 +287,7 @@ exports.getBundlerService = require_stdio.getBundlerService;
168
287
  exports.getBundlerServiceFromConfig = require_stdio.getBundlerServiceFromConfig;
169
288
  exports.getSharedComponentTags = require_stdio.getSharedComponentTags;
170
289
  exports.hasStyleSystemProjectConfig = require_stdio.hasStyleSystemProjectConfig;
290
+ exports.launchBrowserWithFallback = require_stdio.launchBrowserWithFallback;
171
291
  exports.resetStyleSystemConfigCache = require_stdio.resetStyleSystemConfigCache;
172
292
  exports.resolveAppDesignSystemConfig = require_stdio.resolveAppDesignSystemConfig;
173
293
  exports.resolveStyleSystemThemePath = require_stdio.resolveStyleSystemThemePath;