@iota-uz/sdk 0.4.28 → 0.4.30

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 CHANGED
@@ -52,11 +52,10 @@ applet rpc gen --name <applet-name>
52
52
  applet rpc check --name <applet-name>
53
53
  applet rpc watch --name <applet-name>
54
54
  applet deps check
55
- applet sdk local --sdk-root ../../applets
56
- applet sdk local --off
57
55
  applet check # deps + RPC drift for all applets
58
56
  applet schema export --name <applet>
59
57
  applet dev # start dev environment (all configured applets)
58
+ applet dev --sdk-root ../../applets
60
59
  applet dev --rpc-watch # include RPC codegen watch during dev
61
60
  applet build [name] # build production bundle
62
61
  applet list # list configured applets
@@ -67,17 +66,18 @@ applet secrets delete --name <applet> --key OPENAI_API_KEY
67
66
 
68
67
  - **Specific version:** `go install github.com/iota-uz/applets/cmd/applet@v0.4.4`
69
68
  - **Shell completion:** `applet completion bash`, `applet completion zsh`, or `applet completion fish` — see `applet completion --help` for install instructions.
70
- - **Local SDK alias mode:** `applet sdk local` writes local-only settings to `.applets/local.env` (gitignored). `applet dev` then injects `IOTA_SDK_DIST` so Vite aliases `@iota-uz/sdk` to your local SDK dist.
69
+ - **Convention-based local SDK:** when `applet dev` can see a canonical local `@iota-uz/sdk` source checkout (for example `./applets` in a monorepo), it automatically builds/watches that SDK and wires applet consumers to a managed local SDK package for dev.
70
+ - **Explicit escape hatch:** use `applet dev --sdk-root ../../applets` only when your local SDK checkout lives in a non-conventional location.
71
71
 
72
72
  ---
73
73
 
74
74
  ## DX Migration Notes (Breaking)
75
75
 
76
76
  - `applets/` is the canonical source of `@iota-uz/sdk`; `iota-sdk/package.json` is no longer the publish source.
77
- - Local SDK iteration uses runtime alias mode only: `applet sdk local --sdk-root ../../applets` and `applet sdk local --off`.
77
+ - Local SDK iteration prefers convention over configuration. If your repo has `./applets` (or a conventional sibling `../applets`) you should not need any manual override at all.
78
+ - For non-conventional layouts, pass `--sdk-root` directly to `applet dev` instead of persisting local env overrides.
78
79
  - Never commit local `pnpm` overrides/workspace links for `@iota-uz/sdk`.
79
80
  - `applet dev` now detects `go.work` dependencies and automatically watches/restarts critical processes when dependency code changes.
80
- - Keep `.applets/local.env` local-only. It is intentionally gitignored and must not be committed.
81
81
 
82
82
  ### Release flow
83
83
 
@@ -36,8 +36,8 @@ function createAppletViteConfig(opts) {
36
36
  resolve: {
37
37
  dedupe: DEFAULT_DEDUPE,
38
38
  alias: createLocalSdkAliases({
39
- enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),
40
- sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST
39
+ enabled: opts.enableLocalSdkAliases,
40
+ sdkDistDir: opts.sdkDistDir
41
41
  })
42
42
  },
43
43
  server: {
@@ -63,8 +63,8 @@ function createAppletBackendProxy(opts) {
63
63
  };
64
64
  }
65
65
  function createLocalSdkAliases(opts) {
66
- const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST);
67
- const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST;
66
+ const dir = opts?.sdkDistDir;
67
+ const enabled = opts?.enabled ?? Boolean(dir);
68
68
  if (!enabled || !dir) {
69
69
  return [];
70
70
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],"names":["path","createRequire","fs","os","crypto","spawnSync"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,IAAM,cAAA,GAAiB,CAAC,OAAA,EAAS,WAAA,EAAa,oBAAoB,UAAU,CAAA;AAKrE,SAAS,oBAAoB,QAAA,EAA0B;AAC5D,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,kBAAA,IAAsB,QAAA,GAAW,UAAA;AAC1D,EAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAG,CAAA,GAAI,OAAO,IAAA,GAAO,GAAA;AAC5C;AAKO,SAAS,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,EAAS,OAAO,CAAA;AAC1C,UAAA,IAAI;AACF,YAAAA,mBAAA,CAAG,WAAW,OAAO,CAAA;AAAA,UACvB,CAAA,CAAA,MAAQ;AAAA,UAER;AAAA,QACF;AAAA,MACF;AAEA,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,MAAM,YAAA,GAAeF,uBAAK,UAAA,CAAW,aAAa,IAAI,aAAA,GAAgBA,sBAAAA,CAAK,IAAA,CAAK,IAAA,EAAM,aAAa,CAAA;AACnG,QAAA,IAAI;AACF,UAAA,OAAA,GAAUE,mBAAA,CAAG,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA;AAAA,QACjD,CAAA,CAAA,MAAQ;AACN,UAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,YAAA,OAAA,CAAQ,IAAA;AAAA,cACN,0DAA0D,YAAY,CAAA,uFAAA;AAAA,aACxE;AAAA,UACF;AACA,UAAA,OAAA,GAAU,EAAA;AAAA,QACZ;AAAA,MACF;AAEA,MAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,MAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAC3B,MAAA,OAAO,CAAA,eAAA,EAAkB,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA,CAAA;AAAA,IAC9C;AAAA,GACF;AACF;AAMO,SAAS,wBAAA,CACd,OAAA,GAAgE,EAAC,EACzD;AACR,EAAA,OAAO,qCAAA,CAAsC;AAAA,IAC3C,GAAG,OAAA;AAAA,IACH,QAAA,EAAU,QAAQ,QAAA,IAAY,eAAA;AAAA,IAC9B,aAAA,EAAe,QAAQ,aAAA,IAAiB,gBAAA;AAAA,IACxC,UAAA,EAAY,CAAC,gCAAgC;AAAA,GAC9C,CAAA;AACH","file":"vite.cjs","sourcesContent":["/**\n * Applet Frontend Kit: Vite config helpers for applets running behind a base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite';\nimport path from 'node:path';\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"). */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"). */\n backendUrl: string\n /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is'];\n\n/**\n * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.\n */\nexport function getAppletAssetsBase(basePath: string): string {\n const base = process.env.APPLET_ASSETS_BASE ?? basePath + '/assets/';\n return base.endsWith('/') ? base : base + '/';\n}\n\n/**\n * Returns dev server port from APPLET_VITE_PORT env, or the given default.\n */\nexport function getAppletVitePort(defaultPort = 5173): number {\n const p = process.env.APPLET_VITE_PORT;\n if (p === undefined || p === '') {return defaultPort;}\n const n = Number(p);\n return Number.isFinite(n) ? n : defaultPort;\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const base = getAppletAssetsBase(opts.basePath);\n const port = getAppletVitePort(5173);\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),\n sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath: opts.basePath,\n backendUrl: opts.backendUrl,\n }),\n },\n };\n if (opts.extend) {\n return mergeConfig(config, opts.extend);\n }\n return config;\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '');\n const target = opts.backendUrl.replace(/\\/+$/, '');\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n };\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST);\n const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST;\n if (!enabled || !dir) {return [];}\n const sdkDist = path.resolve(dir);\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ];\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve;\n const bResolve = b.resolve;\n const aServer = a.server;\n const bServer = b.server;\n const aPlugins = a.plugins;\n const bPlugins = b.plugins;\n\n const merged: UserConfig = { ...a, ...b };\n\n if (bResolve) {\n const aAlias = aResolve?.alias;\n const bAlias = bResolve.alias;\n const aIsArray = Array.isArray(aAlias);\n const bIsArray = Array.isArray(bAlias);\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias);\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n };\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer };\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins];\n }\n return merged;\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite';\nimport { spawnSync } from 'node:child_process';\nimport crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles';\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID;\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath;\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'));\n return req.resolve(specifierOrPath);\n } catch {\n return null;\n }\n }\n return path.join(root, specifierOrPath);\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css';\n const outputCssPath = options.outputCssPath ?? 'dist/style.css';\n const tailwindConfigPath = options.tailwindConfigPath;\n const prependCss = options.prependCss ?? [];\n let root = process.cwd();\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root;\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) {return RESOLVED_ID;}\n return null;\n },\n load(id: string) {\n if (id !== RESOLVED_ID) {return null;}\n\n const parts: string[] = [];\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root);\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'));\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss);\n let mainCss: string | null = null;\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`);\n const args = ['-i', inputPath, '-o', tmpFile];\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath);\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath);\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n });\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8');\n try {\n fs.unlinkSync(tmpFile);\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath);\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8');\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n );\n }\n mainCss = '';\n }\n }\n\n parts.push(mainCss);\n const css = parts.join('\\n');\n return `export default ${JSON.stringify(css)}`;\n },\n };\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n });\n}\n"]}
1
+ {"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],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EAAe,QAAQ,aAAA,IAAiB,gBAAA;AAAA,IACxC,UAAA,EAAY,CAAC,gCAAgC;AAAA,GAC9C,CAAA;AACH","file":"vite.cjs","sourcesContent":["/**\n * Applet Frontend Kit: Vite config helpers for applets running behind a base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite';\nimport path from 'node:path';\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"). */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"). */\n backendUrl: string\n /** Enable Vite aliases to a local SDK dist during dev iteration. Rare: prefer applet dev's managed local package. */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true. */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is'];\n\n/**\n * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.\n */\nexport function getAppletAssetsBase(basePath: string): string {\n const base = process.env.APPLET_ASSETS_BASE ?? basePath + '/assets/';\n return base.endsWith('/') ? base : base + '/';\n}\n\n/**\n * Returns dev server port from APPLET_VITE_PORT env, or the given default.\n */\nexport function getAppletVitePort(defaultPort = 5173): number {\n const p = process.env.APPLET_VITE_PORT;\n if (p === undefined || p === '') {return defaultPort;}\n const n = Number(p);\n return Number.isFinite(n) ? n : defaultPort;\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const base = getAppletAssetsBase(opts.basePath);\n const port = getAppletVitePort(5173);\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases,\n sdkDistDir: opts.sdkDistDir,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath: opts.basePath,\n backendUrl: opts.backendUrl,\n }),\n },\n };\n if (opts.extend) {\n return mergeConfig(config, opts.extend);\n }\n return config;\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '');\n const target = opts.backendUrl.replace(/\\/+$/, '');\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n };\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Rare escape hatch for non-standard local SDK layouts. Prefer applet dev's managed local package flow.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const dir = opts?.sdkDistDir;\n const enabled = opts?.enabled ?? Boolean(dir);\n if (!enabled || !dir) {return [];}\n const sdkDist = path.resolve(dir);\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ];\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve;\n const bResolve = b.resolve;\n const aServer = a.server;\n const bServer = b.server;\n const aPlugins = a.plugins;\n const bPlugins = b.plugins;\n\n const merged: UserConfig = { ...a, ...b };\n\n if (bResolve) {\n const aAlias = aResolve?.alias;\n const bAlias = bResolve.alias;\n const aIsArray = Array.isArray(aAlias);\n const bIsArray = Array.isArray(bAlias);\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias);\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n };\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer };\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins];\n }\n return merged;\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite';\nimport { spawnSync } from 'node:child_process';\nimport crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles';\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID;\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath;\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'));\n return req.resolve(specifierOrPath);\n } catch {\n return null;\n }\n }\n return path.join(root, specifierOrPath);\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css';\n const outputCssPath = options.outputCssPath ?? 'dist/style.css';\n const tailwindConfigPath = options.tailwindConfigPath;\n const prependCss = options.prependCss ?? [];\n let root = process.cwd();\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root;\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) {return RESOLVED_ID;}\n return null;\n },\n load(id: string) {\n if (id !== RESOLVED_ID) {return null;}\n\n const parts: string[] = [];\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root);\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'));\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss);\n let mainCss: string | null = null;\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`);\n const args = ['-i', inputPath, '-o', tmpFile];\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath);\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath);\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n });\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8');\n try {\n fs.unlinkSync(tmpFile);\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath);\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8');\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n );\n }\n mainCss = '';\n }\n }\n\n parts.push(mainCss);\n const css = parts.join('\\n');\n return `export default ${JSON.stringify(css)}`;\n },\n };\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n });\n}\n"]}
@@ -10,9 +10,9 @@ type AppletViteOptions = {
10
10
  basePath: string;
11
11
  /** Backend URL for proxy (e.g. "http://localhost:3200"). */
12
12
  backendUrl: string;
13
- /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */
13
+ /** Enable Vite aliases to a local SDK dist during dev iteration. Rare: prefer applet dev's managed local package. */
14
14
  enableLocalSdkAliases?: boolean;
15
- /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */
15
+ /** Override SDK dist directory when enableLocalSdkAliases is true. */
16
16
  sdkDistDir?: string;
17
17
  /** Merge additional Vite config */
18
18
  extend?: UserConfig;
@@ -46,7 +46,7 @@ declare function createAppletBackendProxy(opts: {
46
46
  }): Record<string, string>;
47
47
  /**
48
48
  * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.
49
- * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.
49
+ * Rare escape hatch for non-standard local SDK layouts. Prefer applet dev's managed local package flow.
50
50
  */
51
51
  declare function createLocalSdkAliases(opts?: {
52
52
  enabled?: boolean;
@@ -10,9 +10,9 @@ type AppletViteOptions = {
10
10
  basePath: string;
11
11
  /** Backend URL for proxy (e.g. "http://localhost:3200"). */
12
12
  backendUrl: string;
13
- /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */
13
+ /** Enable Vite aliases to a local SDK dist during dev iteration. Rare: prefer applet dev's managed local package. */
14
14
  enableLocalSdkAliases?: boolean;
15
- /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */
15
+ /** Override SDK dist directory when enableLocalSdkAliases is true. */
16
16
  sdkDistDir?: string;
17
17
  /** Merge additional Vite config */
18
18
  extend?: UserConfig;
@@ -46,7 +46,7 @@ declare function createAppletBackendProxy(opts: {
46
46
  }): Record<string, string>;
47
47
  /**
48
48
  * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.
49
- * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.
49
+ * Rare escape hatch for non-standard local SDK layouts. Prefer applet dev's managed local package flow.
50
50
  */
51
51
  declare function createLocalSdkAliases(opts?: {
52
52
  enabled?: boolean;
@@ -27,8 +27,8 @@ function createAppletViteConfig(opts) {
27
27
  resolve: {
28
28
  dedupe: DEFAULT_DEDUPE,
29
29
  alias: createLocalSdkAliases({
30
- enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),
31
- sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST
30
+ enabled: opts.enableLocalSdkAliases,
31
+ sdkDistDir: opts.sdkDistDir
32
32
  })
33
33
  },
34
34
  server: {
@@ -54,8 +54,8 @@ function createAppletBackendProxy(opts) {
54
54
  };
55
55
  }
56
56
  function createLocalSdkAliases(opts) {
57
- const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST);
58
- const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST;
57
+ const dir = opts?.sdkDistDir;
58
+ const enabled = opts?.enabled ?? Boolean(dir);
59
59
  if (!enabled || !dir) {
60
60
  return [];
61
61
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],"names":["path"],"mappings":";;;;;;;;AAoBA,IAAM,cAAA,GAAiB,CAAC,OAAA,EAAS,WAAA,EAAa,oBAAoB,UAAU,CAAA;AAKrE,SAAS,oBAAoB,QAAA,EAA0B;AAC5D,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,kBAAA,IAAsB,QAAA,GAAW,UAAA;AAC1D,EAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAG,CAAA,GAAI,OAAO,IAAA,GAAO,GAAA;AAC5C;AAKO,SAAS,iBAAA,CAAkB,cAAc,IAAA,EAAc;AAC5D,EAAA,MAAM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A,UACvB,CAAA,CAAA,MAAQ;AAAA,UAER;AAAA,QACF;AAAA,MACF;AAEA,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,MAAM,YAAA,GAAeA,MAAK,UAAA,CAAW,aAAa,IAAI,aAAA,GAAgBA,KAAAA,CAAK,IAAA,CAAK,IAAA,EAAM,aAAa,CAAA;AACnG,QAAA,IAAI;AACF,UAAA,OAAA,GAAU,EAAA,CAAG,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA;AAAA,QACjD,CAAA,CAAA,MAAQ;AACN,UAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,YAAA,OAAA,CAAQ,IAAA;AAAA,cACN,0DAA0D,YAAY,CAAA,uFAAA;AAAA,aACxE;AAAA,UACF;AACA,UAAA,OAAA,GAAU,EAAA;AAAA,QACZ;AAAA,MACF;AAEA,MAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,MAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAC3B,MAAA,OAAO,CAAA,eAAA,EAAkB,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA,CAAA;AAAA,IAC9C;AAAA,GACF;AACF;AAMO,SAAS,wBAAA,CACd,OAAA,GAAgE,EAAC,EACzD;AACR,EAAA,OAAO,qCAAA,CAAsC;AAAA,IAC3C,GAAG,OAAA;AAAA,IACH,QAAA,EAAU,QAAQ,QAAA,IAAY,eAAA;AAAA,IAC9B,aAAA,EAAe,QAAQ,aAAA,IAAiB,gBAAA;AAAA,IACxC,UAAA,EAAY,CAAC,gCAAgC;AAAA,GAC9C,CAAA;AACH","file":"vite.mjs","sourcesContent":["/**\n * Applet Frontend Kit: Vite config helpers for applets running behind a base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite';\nimport path from 'node:path';\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"). */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"). */\n backendUrl: string\n /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is'];\n\n/**\n * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.\n */\nexport function getAppletAssetsBase(basePath: string): string {\n const base = process.env.APPLET_ASSETS_BASE ?? basePath + '/assets/';\n return base.endsWith('/') ? base : base + '/';\n}\n\n/**\n * Returns dev server port from APPLET_VITE_PORT env, or the given default.\n */\nexport function getAppletVitePort(defaultPort = 5173): number {\n const p = process.env.APPLET_VITE_PORT;\n if (p === undefined || p === '') {return defaultPort;}\n const n = Number(p);\n return Number.isFinite(n) ? n : defaultPort;\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const base = getAppletAssetsBase(opts.basePath);\n const port = getAppletVitePort(5173);\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),\n sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath: opts.basePath,\n backendUrl: opts.backendUrl,\n }),\n },\n };\n if (opts.extend) {\n return mergeConfig(config, opts.extend);\n }\n return config;\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '');\n const target = opts.backendUrl.replace(/\\/+$/, '');\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n };\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST);\n const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST;\n if (!enabled || !dir) {return [];}\n const sdkDist = path.resolve(dir);\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ];\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve;\n const bResolve = b.resolve;\n const aServer = a.server;\n const bServer = b.server;\n const aPlugins = a.plugins;\n const bPlugins = b.plugins;\n\n const merged: UserConfig = { ...a, ...b };\n\n if (bResolve) {\n const aAlias = aResolve?.alias;\n const bAlias = bResolve.alias;\n const aIsArray = Array.isArray(aAlias);\n const bIsArray = Array.isArray(bAlias);\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias);\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n };\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer };\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins];\n }\n return merged;\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite';\nimport { spawnSync } from 'node:child_process';\nimport crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles';\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID;\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath;\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'));\n return req.resolve(specifierOrPath);\n } catch {\n return null;\n }\n }\n return path.join(root, specifierOrPath);\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css';\n const outputCssPath = options.outputCssPath ?? 'dist/style.css';\n const tailwindConfigPath = options.tailwindConfigPath;\n const prependCss = options.prependCss ?? [];\n let root = process.cwd();\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root;\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) {return RESOLVED_ID;}\n return null;\n },\n load(id: string) {\n if (id !== RESOLVED_ID) {return null;}\n\n const parts: string[] = [];\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root);\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'));\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss);\n let mainCss: string | null = null;\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`);\n const args = ['-i', inputPath, '-o', tmpFile];\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath);\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath);\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n });\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8');\n try {\n fs.unlinkSync(tmpFile);\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath);\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8');\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n );\n }\n mainCss = '';\n }\n }\n\n parts.push(mainCss);\n const css = parts.join('\\n');\n return `export default ${JSON.stringify(css)}`;\n },\n };\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n });\n}\n"]}
1
+ {"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],"names":["path"],"mappings":";;;;;;;;AAoBA,IAAM,cAAA,GAAiB,CAAC,OAAA,EAAS,WAAA,EAAa,oBAAoB,U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GAAU,EAAA,CAAG,YAAA,CAAa,OAAA,EAAS,OAAO,CAAA;AAC1C,UAAA,IAAI;AACF,YAAA,EAAA,CAAG,WAAW,OAAO,CAAA;AAAA,UACvB,CAAA,CAAA,MAAQ;AAAA,UAER;AAAA,QACF;AAAA,MACF;AAEA,MAAA,IAAI,YAAY,IAAA,EAAM;AACpB,QAAA,MAAM,YAAA,GAAeA,MAAK,UAAA,CAAW,aAAa,IAAI,aAAA,GAAgBA,KAAAA,CAAK,IAAA,CAAK,IAAA,EAAM,aAAa,CAAA;AACnG,QAAA,IAAI;AACF,UAAA,OAAA,GAAU,EAAA,CAAG,YAAA,CAAa,YAAA,EAAc,OAAO,CAAA;AAAA,QACjD,CAAA,CAAA,MAAQ;AACN,UAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,YAAA,OAAA,CAAQ,IAAA;AAAA,cACN,0DAA0D,YAAY,CAAA,uFAAA;AAAA,aACxE;AAAA,UACF;AACA,UAAA,OAAA,GAAU,EAAA;AAAA,QACZ;AAAA,MACF;AAEA,MAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,MAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAC3B,MAAA,OAAO,CAAA,eAAA,EAAkB,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA,CAAA;AAAA,IAC9C;AAAA,GACF;AACF;AAMO,SAAS,wBAAA,CACd,OAAA,GAAgE,EAAC,EACzD;AACR,EAAA,OAAO,qCAAA,CAAsC;AAAA,IAC3C,GAAG,OAAA;AAAA,IACH,QAAA,EAAU,QAAQ,QAAA,IAAY,eAAA;AAAA,IAC9B,aAAA,EAAe,QAAQ,aAAA,IAAiB,gBAAA;AAAA,IACxC,UAAA,EAAY,CAAC,gCAAgC;AAAA,GAC9C,CAAA;AACH","file":"vite.mjs","sourcesContent":["/**\n * Applet Frontend Kit: Vite config helpers for applets running behind a base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite';\nimport path from 'node:path';\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"). */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"). */\n backendUrl: string\n /** Enable Vite aliases to a local SDK dist during dev iteration. Rare: prefer applet dev's managed local package. */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true. */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is'];\n\n/**\n * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.\n */\nexport function getAppletAssetsBase(basePath: string): string {\n const base = process.env.APPLET_ASSETS_BASE ?? basePath + '/assets/';\n return base.endsWith('/') ? base : base + '/';\n}\n\n/**\n * Returns dev server port from APPLET_VITE_PORT env, or the given default.\n */\nexport function getAppletVitePort(defaultPort = 5173): number {\n const p = process.env.APPLET_VITE_PORT;\n if (p === undefined || p === '') {return defaultPort;}\n const n = Number(p);\n return Number.isFinite(n) ? n : defaultPort;\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const base = getAppletAssetsBase(opts.basePath);\n const port = getAppletVitePort(5173);\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases,\n sdkDistDir: opts.sdkDistDir,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath: opts.basePath,\n backendUrl: opts.backendUrl,\n }),\n },\n };\n if (opts.extend) {\n return mergeConfig(config, opts.extend);\n }\n return config;\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '');\n const target = opts.backendUrl.replace(/\\/+$/, '');\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n };\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Rare escape hatch for non-standard local SDK layouts. Prefer applet dev's managed local package flow.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const dir = opts?.sdkDistDir;\n const enabled = opts?.enabled ?? Boolean(dir);\n if (!enabled || !dir) {return [];}\n const sdkDist = path.resolve(dir);\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ];\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve;\n const bResolve = b.resolve;\n const aServer = a.server;\n const bServer = b.server;\n const aPlugins = a.plugins;\n const bPlugins = b.plugins;\n\n const merged: UserConfig = { ...a, ...b };\n\n if (bResolve) {\n const aAlias = aResolve?.alias;\n const bAlias = bResolve.alias;\n const aIsArray = Array.isArray(aAlias);\n const bIsArray = Array.isArray(bAlias);\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias);\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n };\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer };\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins];\n }\n return merged;\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite';\nimport { spawnSync } from 'node:child_process';\nimport crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport { createRequire } from 'node:module';\nimport os from 'node:os';\nimport path from 'node:path';\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles';\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID;\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath;\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'));\n return req.resolve(specifierOrPath);\n } catch {\n return null;\n }\n }\n return path.join(root, specifierOrPath);\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css';\n const outputCssPath = options.outputCssPath ?? 'dist/style.css';\n const tailwindConfigPath = options.tailwindConfigPath;\n const prependCss = options.prependCss ?? [];\n let root = process.cwd();\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root;\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) {return RESOLVED_ID;}\n return null;\n },\n load(id: string) {\n if (id !== RESOLVED_ID) {return null;}\n\n const parts: string[] = [];\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root);\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'));\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss);\n let mainCss: string | null = null;\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`);\n const args = ['-i', inputPath, '-o', tmpFile];\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath);\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath);\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n });\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8');\n try {\n fs.unlinkSync(tmpFile);\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath);\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8');\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n );\n }\n mainCss = '';\n }\n }\n\n parts.push(mainCss);\n const css = parts.join('\\n');\n return `export default ${JSON.stringify(css)}`;\n },\n };\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n });\n}\n"]}