assistant-ui 0.0.107 → 0.0.109

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.
@@ -0,0 +1,5 @@
1
+ //#region src/codemods/v0-15/aui-accessor-calls-to-properties.d.ts
2
+ declare const auiAccessorCallsToProperties: (fileInfo: import("jscodeshift/src/core").FileInfo, api: import("jscodeshift/src/core").API, options: any) => string | null;
3
+ //#endregion
4
+ export { auiAccessorCallsToProperties as default };
5
+ //# sourceMappingURL=aui-accessor-calls-to-properties.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aui-accessor-calls-to-properties.d.ts","names":[],"sources":["../../../src/codemods/v0-15/aui-accessor-calls-to-properties.ts"],"mappings":";cA4BM,+BAA4B,yCAAA,UAAA,oCAAA,KAAA"}
@@ -0,0 +1,58 @@
1
+ import { createTransformer } from "../utils/createTransformer.js";
2
+ //#region src/codemods/v0-15/aui-accessor-calls-to-properties.ts
3
+ const NULLARY_SCOPES = /* @__PURE__ */ new Set([
4
+ "threads",
5
+ "threadListItem",
6
+ "thread",
7
+ "message",
8
+ "part",
9
+ "composer",
10
+ "attachment",
11
+ "modelContext",
12
+ "suggestions",
13
+ "suggestion",
14
+ "chainOfThought",
15
+ "queueItem",
16
+ "tools",
17
+ "dataRenderers",
18
+ "interactables",
19
+ "unstable_interactables",
20
+ "mcp",
21
+ "mcpServer",
22
+ "span"
23
+ ]);
24
+ const AUI_HOOKS = /* @__PURE__ */ new Set(["useAui", "useAssistantApi"]);
25
+ const auiAccessorCallsToProperties = createTransformer(({ j, root, markAsChanged }) => {
26
+ const auiNames = /* @__PURE__ */ new Set(["aui"]);
27
+ root.find(j.VariableDeclarator).forEach((path) => {
28
+ const { id, init } = path.value;
29
+ if (j.Identifier.check(id) && init && j.CallExpression.check(init) && j.Identifier.check(init.callee) && AUI_HOOKS.has(init.callee.name)) auiNames.add(id.name);
30
+ });
31
+ const collectParam = (param) => {
32
+ const annotation = param?.typeAnnotation?.typeAnnotation;
33
+ if (j.Identifier.check(param) && annotation && j.TSTypeReference.check(annotation) && j.Identifier.check(annotation.typeName) && annotation.typeName.name === "AssistantClient") auiNames.add(param.name);
34
+ };
35
+ for (const fnType of [
36
+ j.FunctionDeclaration,
37
+ j.FunctionExpression,
38
+ j.ArrowFunctionExpression
39
+ ]) root.find(fnType).forEach((path) => {
40
+ path.value.params.forEach(collectParam);
41
+ });
42
+ root.find(j.CallExpression).forEach((path) => {
43
+ const node = path.value;
44
+ if (node.arguments.length !== 0) return;
45
+ const callee = node.callee;
46
+ if (!j.MemberExpression.check(callee) || callee.computed) return;
47
+ if (!j.Identifier.check(callee.property)) return;
48
+ if (!NULLARY_SCOPES.has(callee.property.name)) return;
49
+ if (!j.Identifier.check(callee.object)) return;
50
+ if (!auiNames.has(callee.object.name)) return;
51
+ j(path).replaceWith(callee);
52
+ markAsChanged();
53
+ });
54
+ });
55
+ //#endregion
56
+ export { auiAccessorCallsToProperties as default };
57
+
58
+ //# sourceMappingURL=aui-accessor-calls-to-properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aui-accessor-calls-to-properties.js","names":[],"sources":["../../../src/codemods/v0-15/aui-accessor-calls-to-properties.ts"],"sourcesContent":["import { createTransformer } from \"../utils/createTransformer\";\n\n// Nullary scope accessors that became properties in v0.15. Parameterized\n// lookups (e.g. `aui.thread.message({ id })`) stay as real calls.\nconst NULLARY_SCOPES = new Set([\n \"threads\",\n \"threadListItem\",\n \"thread\",\n \"message\",\n \"part\",\n \"composer\",\n \"attachment\",\n \"modelContext\",\n \"suggestions\",\n \"suggestion\",\n \"chainOfThought\",\n \"queueItem\",\n \"tools\",\n \"dataRenderers\",\n \"interactables\",\n \"unstable_interactables\",\n \"mcp\",\n \"mcpServer\",\n \"span\",\n]);\n\nconst AUI_HOOKS = new Set([\"useAui\", \"useAssistantApi\"]);\n\nconst auiAccessorCallsToProperties = createTransformer(\n ({ j, root, markAsChanged }) => {\n const auiNames = new Set([\"aui\"]);\n\n root.find(j.VariableDeclarator).forEach((path: any) => {\n const { id, init } = path.value;\n if (\n j.Identifier.check(id) &&\n init &&\n j.CallExpression.check(init) &&\n j.Identifier.check(init.callee) &&\n AUI_HOOKS.has(init.callee.name)\n ) {\n auiNames.add(id.name);\n }\n });\n\n const collectParam = (param: any) => {\n const annotation = param?.typeAnnotation?.typeAnnotation;\n if (\n j.Identifier.check(param) &&\n annotation &&\n j.TSTypeReference.check(annotation) &&\n j.Identifier.check(annotation.typeName) &&\n annotation.typeName.name === \"AssistantClient\"\n ) {\n auiNames.add(param.name);\n }\n };\n for (const fnType of [\n j.FunctionDeclaration,\n j.FunctionExpression,\n j.ArrowFunctionExpression,\n ] as const) {\n root.find(fnType as typeof j.FunctionDeclaration).forEach((path: any) => {\n path.value.params.forEach(collectParam);\n });\n }\n\n root.find(j.CallExpression).forEach((path: any) => {\n const node = path.value;\n if (node.arguments.length !== 0) return;\n const callee = node.callee;\n if (!j.MemberExpression.check(callee) || callee.computed) return;\n if (!j.Identifier.check(callee.property)) return;\n if (!NULLARY_SCOPES.has(callee.property.name)) return;\n if (!j.Identifier.check(callee.object)) return;\n if (!auiNames.has(callee.object.name)) return;\n j(path).replaceWith(callee);\n markAsChanged();\n });\n },\n);\n\nexport default auiAccessorCallsToProperties;\n"],"mappings":";;AAIA,MAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,4BAAY,IAAI,IAAI,CAAC,UAAU,iBAAiB,CAAC;AAEvD,MAAM,+BAA+B,mBAClC,EAAE,GAAG,MAAM,oBAAoB;CAC9B,MAAM,2BAAW,IAAI,IAAI,CAAC,KAAK,CAAC;CAEhC,KAAK,KAAK,EAAE,kBAAkB,CAAC,CAAC,SAAS,SAAc;EACrD,MAAM,EAAE,IAAI,SAAS,KAAK;EAC1B,IACE,EAAE,WAAW,MAAM,EAAE,KACrB,QACA,EAAE,eAAe,MAAM,IAAI,KAC3B,EAAE,WAAW,MAAM,KAAK,MAAM,KAC9B,UAAU,IAAI,KAAK,OAAO,IAAI,GAE9B,SAAS,IAAI,GAAG,IAAI;CAExB,CAAC;CAED,MAAM,gBAAgB,UAAe;EACnC,MAAM,aAAa,OAAO,gBAAgB;EAC1C,IACE,EAAE,WAAW,MAAM,KAAK,KACxB,cACA,EAAE,gBAAgB,MAAM,UAAU,KAClC,EAAE,WAAW,MAAM,WAAW,QAAQ,KACtC,WAAW,SAAS,SAAS,mBAE7B,SAAS,IAAI,MAAM,IAAI;CAE3B;CACA,KAAK,MAAM,UAAU;EACnB,EAAE;EACF,EAAE;EACF,EAAE;CACJ,GACE,KAAK,KAAK,MAAsC,CAAC,CAAC,SAAS,SAAc;EACvE,KAAK,MAAM,OAAO,QAAQ,YAAY;CACxC,CAAC;CAGH,KAAK,KAAK,EAAE,cAAc,CAAC,CAAC,SAAS,SAAc;EACjD,MAAM,OAAO,KAAK;EAClB,IAAI,KAAK,UAAU,WAAW,GAAG;EACjC,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,EAAE,iBAAiB,MAAM,MAAM,KAAK,OAAO,UAAU;EAC1D,IAAI,CAAC,EAAE,WAAW,MAAM,OAAO,QAAQ,GAAG;EAC1C,IAAI,CAAC,eAAe,IAAI,OAAO,SAAS,IAAI,GAAG;EAC/C,IAAI,CAAC,EAAE,WAAW,MAAM,OAAO,MAAM,GAAG;EACxC,IAAI,CAAC,SAAS,IAAI,OAAO,OAAO,IAAI,GAAG;EACvC,EAAE,IAAI,CAAC,CAAC,YAAY,MAAM;EAC1B,cAAc;CAChB,CAAC;AACH,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","names":[],"sources":["../../src/commands/agent.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { resolve, dirname } from \"node:path\";\nimport { existsSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport { launch } from \"@assistant-ui/agent-launcher\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nfunction getPluginPath(): string {\n // In dist/, plugin is at ../../plugin relative to dist/commands/agent.js\n // In dev (src/), plugin is at ../../plugin relative to src/commands/\n const candidates = [\n resolve(__dirname, \"..\", \"..\", \"plugin\"),\n resolve(__dirname, \"..\", \"plugin\"),\n ];\n for (const candidate of candidates) {\n if (existsSync(candidate)) return candidate;\n }\n throw new Error(\n `Could not locate the assistant-ui plugin directory. Checked:\\n${candidates.map((c) => ` ${c}`).join(\"\\n\")}`,\n );\n}\n\nexport const agent = new Command()\n .name(\"agent\")\n .description(\"launch Claude Code with assistant-ui skills\")\n .argument(\"<prompt...>\", \"prompt for the agent\")\n .option(\"--dry\", \"print the command instead of running it\")\n .action((promptParts: string[], opts) => {\n const prompt = promptParts.join(\" \");\n\n launch({\n pluginDir: getPluginPath(),\n skillName: \"assistant-ui\",\n prompt,\n dry: opts.dry,\n });\n });\n"],"mappings":";;;;;;AAMA,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;AAExD,SAAS,gBAAwB;CAG/B,MAAM,aAAa,CACjB,QAAQ,WAAW,MAAM,MAAM,QAAQ,GACvC,QAAQ,WAAW,MAAM,QAAQ,CACnC;CACA,KAAK,MAAM,aAAa,YACtB,IAAI,WAAW,SAAS,GAAG,OAAO;CAEpC,MAAM,IAAI,MACR,iEAAiE,WAAW,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,GAC5G;AACF;AAEA,MAAa,QAAQ,IAAI,QAAQ,CAAC,CAC/B,KAAK,OAAO,CAAC,CACb,YAAY,6CAA6C,CAAC,CAC1D,SAAS,eAAe,sBAAsB,CAAC,CAC/C,OAAO,SAAS,yCAAyC,CAAC,CAC1D,QAAQ,aAAuB,SAAS;CACvC,MAAM,SAAS,YAAY,KAAK,GAAG;CAEnC,OAAO;EACL,WAAW,cAAc;EACzB,WAAW;EACX;EACA,KAAK,KAAK;CACZ,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"agent.js","names":[],"sources":["../../src/commands/agent.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { resolve, dirname } from \"node:path\";\nimport { existsSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport { launch } from \"@assistant-ui/agent-launcher\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nfunction getPluginPath(): string {\n // In dist/, plugin is at ../../plugin relative to dist/commands/agent.js\n // In dev (src/), plugin is at ../../plugin relative to src/commands/\n const candidates = [\n resolve(__dirname, \"..\", \"..\", \"plugin\"),\n resolve(__dirname, \"..\", \"plugin\"),\n ];\n for (const candidate of candidates) {\n if (existsSync(candidate)) return candidate;\n }\n throw new Error(\n `Could not locate the assistant-ui plugin directory. Checked:\\n${candidates.map((c) => ` ${c}`).join(\"\\n\")}`,\n );\n}\n\nexport const agent = new Command()\n .name(\"agent\")\n .description(\"launch Claude Code with assistant-ui skills\")\n .argument(\"<prompt...>\", \"prompt for the agent\")\n .option(\"--dry\", \"print the command instead of running it\")\n .action((promptParts: string[], opts) => {\n const prompt = promptParts.join(\" \");\n\n launch({\n pluginDir: getPluginPath(),\n skillName: \"assistant-ui\",\n prompt,\n dry: opts.dry,\n });\n });\n"],"mappings":";;;;;;AAMA,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAExD,SAAS,gBAAwB;CAG/B,MAAM,aAAa,CACjB,QAAQ,WAAW,MAAM,MAAM,QAAQ,GACvC,QAAQ,WAAW,MAAM,QAAQ,CACnC;CACA,KAAK,MAAM,aAAa,YACtB,IAAI,WAAW,SAAS,GAAG,OAAO;CAEpC,MAAM,IAAI,MACR,iEAAiE,WAAW,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,GAC5G;AACF;AAEA,MAAa,QAAQ,IAAI,QAAQ,CAAC,CAC/B,KAAK,OAAO,CAAC,CACb,YAAY,6CAA6C,CAAC,CAC1D,SAAS,eAAe,sBAAsB,CAAC,CAC/C,OAAO,SAAS,yCAAyC,CAAC,CAC1D,QAAQ,aAAuB,SAAS;CACvC,MAAM,SAAS,YAAY,KAAK,GAAG;CAEnC,OAAO;EACL,WAAW,cAAc;EACzB,WAAW;EACX;EACA,KAAK,KAAK;CACZ,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"info.js","names":["path","fs","os"],"sources":["../../src/commands/info.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { spawnSync } from \"node:child_process\";\nimport chalk from \"chalk\";\nimport { detect } from \"detect-package-manager\";\nimport { satisfies } from \"semver\";\nimport { findWorkspaceRoot, resolveRealPath } from \"../lib/utils/workspace\";\n\nexport { findWorkspaceRoot };\n\nconst ASSISTANT_UI_PACKAGES = [\n // Distribution\n \"@assistant-ui/react\",\n \"@assistant-ui/react-native\",\n \"@assistant-ui/react-ink\",\n // Core (should not be installed directly)\n \"@assistant-ui/core\",\n \"@assistant-ui/store\",\n \"@assistant-ui/tap\",\n // Streaming & Cloud\n \"assistant-stream\",\n \"assistant-cloud\",\n \"@assistant-ui/cloud-ai-sdk\",\n // Adapters\n \"@assistant-ui/eve\",\n \"@assistant-ui/react-ai-sdk\",\n \"@assistant-ui/react-langgraph\",\n \"@assistant-ui/react-ag-ui\",\n \"@assistant-ui/react-a2a\",\n \"@assistant-ui/react-data-stream\",\n \"@assistant-ui/react-google-adk\",\n // UI / Rendering\n \"@assistant-ui/react-markdown\",\n \"@assistant-ui/react-streamdown\",\n \"@assistant-ui/react-lexical\",\n \"@assistant-ui/react-syntax-highlighter\",\n \"@assistant-ui/react-hook-form\",\n // Observability & DevTools\n \"@assistant-ui/react-o11y\",\n \"@assistant-ui/react-devtools\",\n];\n\nconst ECOSYSTEM_PACKAGES = [\n \"react\",\n \"react-dom\",\n \"react-native\",\n \"next\",\n \"vite\",\n \"expo\",\n \"ai\",\n \"zod\",\n \"zustand\",\n \"typescript\",\n];\n\n// Packages that users should NOT install directly — they are internal\n// dependencies pulled in automatically by distribution packages.\nconst SHOULD_NOT_DIRECT_INSTALL = new Set([\n \"@assistant-ui/core\",\n \"@assistant-ui/store\",\n \"@assistant-ui/tap\",\n]);\n\nfunction resolvePackageJson(pkg: string, cwd: string): string | null {\n let dir = cwd;\n const root = path.parse(dir).root;\n while (dir !== root) {\n const candidate = path.join(\n dir,\n \"node_modules\",\n ...pkg.split(\"/\"),\n \"package.json\",\n );\n if (fs.existsSync(candidate)) return candidate;\n dir = path.dirname(dir);\n }\n return null;\n}\n\nfunction getInstalledVersion(pkg: string, cwd: string): string | null {\n try {\n const pkgJsonPath = resolvePackageJson(pkg, cwd);\n if (pkgJsonPath) {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n return pkgJson.version ?? null;\n }\n } catch {\n // ignore\n }\n return null;\n}\n\nfunction readProjectDeps(\n projectPkg: Record<string, unknown>,\n): Record<string, string> {\n return {\n ...((projectPkg.dependencies ?? {}) as Record<string, string>),\n ...((projectPkg.devDependencies ?? {}) as Record<string, string>),\n };\n}\n\nfunction getAssistantUiPackageNames(\n projectPkg: Record<string, unknown>,\n): string[] {\n const declaredPackages = Object.keys(readProjectDeps(projectPkg))\n .filter((name) => name.startsWith(\"@assistant-ui/\"))\n .sort();\n\n return [...new Set([...ASSISTANT_UI_PACKAGES, ...declaredPackages])];\n}\n\nfunction getSpecifiedRange(\n pkg: string,\n projectPkg: Record<string, unknown>,\n): string | null {\n const deps = (projectPkg.dependencies ?? {}) as Record<string, string>;\n const devDeps = (projectPkg.devDependencies ?? {}) as Record<string, string>;\n return deps[pkg] ?? devDeps[pkg] ?? null;\n}\n\nfunction getPeerDeps(pkg: string, cwd: string): Record<string, string> | null {\n try {\n const pkgJsonPath = resolvePackageJson(pkg, cwd);\n if (pkgJsonPath) {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n return (pkgJson.peerDependencies as Record<string, string>) ?? null;\n }\n } catch {\n // ignore\n }\n return null;\n}\n\nfunction detectFramework(\n projectPkg: Record<string, unknown>,\n cwd: string,\n): string {\n const deps = readProjectDeps(projectPkg);\n\n if (deps.next) {\n const v = getInstalledVersion(\"next\", cwd);\n return `Next.js ${v ?? deps.next}`;\n }\n if (deps.expo) {\n const v = getInstalledVersion(\"expo\", cwd);\n return `Expo ${v ?? deps.expo}`;\n }\n if (deps.vite) {\n const v = getInstalledVersion(\"vite\", cwd);\n return `Vite ${v ?? deps.vite}`;\n }\n if (deps[\"@remix-run/react\"] || deps.remix) return \"Remix\";\n if (deps.gatsby) return \"Gatsby\";\n if (deps.astro) return \"Astro\";\n return \"Unknown\";\n}\n\nfunction getOsInfo(): string {\n const platform = os.platform();\n const arch = os.arch();\n const release = os.release();\n\n switch (platform) {\n case \"darwin\": {\n const result = spawnSync(\"sw_vers\", [\"-productVersion\"], {\n encoding: \"utf8\",\n });\n const macVer = result.stdout?.trim();\n return macVer\n ? `macOS ${macVer} (${arch})`\n : `macOS ${release} (${arch})`;\n }\n case \"win32\":\n return `Windows ${release} (${arch})`;\n case \"linux\":\n return `Linux ${release} (${arch})`;\n default:\n return `${platform} ${release} (${arch})`;\n }\n}\n\nfunction getCliVersion(): string {\n try {\n const packageJson = JSON.parse(\n fs.readFileSync(new URL(\"../../package.json\", import.meta.url), \"utf8\"),\n ) as { version?: unknown };\n return typeof packageJson.version === \"string\"\n ? packageJson.version\n : \"unknown\";\n } catch {\n return \"unknown\";\n }\n}\n\nasync function getPackageManagerInfo(\n cwd: string,\n): Promise<{ name: string; version: string }> {\n const pm = await detect({ cwd });\n const result = spawnSync(pm, [\"--version\"], {\n encoding: \"utf8\",\n cwd,\n });\n const version = result.stdout?.trim() ?? \"unknown\";\n return { name: pm, version };\n}\n\nexport function satisfiesRange(version: string, range: string): boolean {\n const normalizedRange = range.startsWith(\"workspace:\")\n ? range.slice(\"workspace:\".length)\n : range;\n\n return (\n normalizedRange === \"\" ||\n normalizedRange === \"^\" ||\n normalizedRange === \"~\" ||\n normalizedRange === \"any\" ||\n satisfies(version, normalizedRange, { includePrerelease: true })\n );\n}\n\ninterface PackageInfo {\n name: string;\n version: string;\n range: string | null;\n}\n\ninterface InfoData {\n cliVersion: string;\n os: string;\n node: string;\n pm: { name: string; version: string };\n framework: string;\n isMonorepo: boolean;\n packages: PackageInfo[];\n ecosystem: PackageInfo[];\n warnings: string[];\n}\n\nfunction collectPackages(\n names: string[],\n cwd: string,\n projectPkg: Record<string, unknown>,\n): PackageInfo[] {\n const result: PackageInfo[] = [];\n const deps = readProjectDeps(projectPkg);\n\n for (const name of names) {\n const version = getInstalledVersion(name, cwd);\n if (version) {\n result.push({\n name,\n version,\n range: getSpecifiedRange(name, projectPkg),\n });\n } else {\n // Fallback: no node_modules, show range from package.json\n const range = deps[name];\n if (range && !range.startsWith(\"workspace:\")) {\n result.push({ name, version: `${range} (not installed)`, range });\n }\n }\n }\n return result;\n}\n\nfunction collectWarnings(\n packages: PackageInfo[],\n cwd: string,\n projectPkg: Record<string, unknown>,\n): string[] {\n const warnings: string[] = [];\n const deps = readProjectDeps(projectPkg);\n\n // Check peer dependency mismatches\n for (const pkg of packages) {\n const peerDeps = getPeerDeps(pkg.name, cwd);\n if (!peerDeps) continue;\n\n for (const [peerName, peerRange] of Object.entries(peerDeps)) {\n const peerVersion = getInstalledVersion(peerName, cwd);\n if (!peerVersion) continue;\n if (!satisfiesRange(peerVersion, peerRange)) {\n warnings.push(\n `${pkg.name} requires ${peerName} ${peerRange}, found ${peerVersion}`,\n );\n }\n }\n }\n\n // Check for direct install of internal packages\n for (const name of SHOULD_NOT_DIRECT_INSTALL) {\n if (deps[name]) {\n warnings.push(\n `${name} should not be installed directly — it is an internal dependency`,\n );\n }\n }\n\n return warnings;\n}\n\nasync function collectInfo(\n cwd: string,\n projectPkg: Record<string, unknown>,\n): Promise<InfoData> {\n const pm = await getPackageManagerInfo(cwd);\n const packages = collectPackages(\n getAssistantUiPackageNames(projectPkg),\n cwd,\n projectPkg,\n );\n const ecosystem = collectPackages(ECOSYSTEM_PACKAGES, cwd, projectPkg);\n const warnings = collectWarnings(packages, cwd, projectPkg);\n\n return {\n cliVersion: getCliVersion(),\n os: getOsInfo(),\n node: process.version,\n pm,\n framework: detectFramework(projectPkg, cwd),\n isMonorepo: findWorkspaceRoot(cwd) !== null,\n packages,\n ecosystem,\n warnings,\n };\n}\n\nfunction formatSection(label: string, items: PackageInfo[]): string[] {\n if (items.length === 0) return [];\n const lines: string[] = [];\n lines.push(\"\");\n lines.push(`${label}:`);\n const maxLen = Math.max(...items.map((p) => p.name.length));\n for (const pkg of items) {\n lines.push(` ${pkg.name.padEnd(maxLen)} ${pkg.version}`);\n }\n return lines;\n}\n\nfunction renderPlain(data: InfoData): string[] {\n const lines: string[] = [];\n\n lines.push(\"Environment:\");\n lines.push(` assistant-ui CLI: ${data.cliVersion}`);\n lines.push(` OS: ${data.os}`);\n lines.push(` Node.js: ${data.node}`);\n lines.push(` Package Manager: ${data.pm.name} ${data.pm.version}`);\n lines.push(` Framework: ${data.framework}`);\n if (data.isMonorepo) {\n lines.push(` Monorepo: yes`);\n }\n\n lines.push(...formatSection(\"Packages\", data.packages));\n lines.push(...formatSection(\"Ecosystem\", data.ecosystem));\n\n if (data.warnings.length > 0) {\n lines.push(\"\");\n lines.push(\"Warnings:\");\n for (const w of data.warnings) {\n lines.push(` ! ${w}`);\n }\n }\n\n return lines;\n}\n\nfunction renderColored(data: InfoData): string[] {\n const lines: string[] = [];\n\n lines.push(chalk.bold(\"Environment:\"));\n lines.push(` assistant-ui CLI: ${data.cliVersion}`);\n lines.push(` OS: ${data.os}`);\n lines.push(` Node.js: ${data.node}`);\n lines.push(` Package Manager: ${data.pm.name} ${data.pm.version}`);\n lines.push(` Framework: ${data.framework}`);\n if (data.isMonorepo) {\n lines.push(` Monorepo: yes`);\n }\n\n if (data.packages.length > 0) {\n const section = formatSection(\"Packages\", data.packages);\n section[0] = \"\";\n section[1] = chalk.bold(\"Packages:\");\n lines.push(...section);\n } else {\n lines.push(\"\");\n lines.push(chalk.yellow(\" No assistant-ui packages found.\"));\n }\n\n if (data.ecosystem.length > 0) {\n const section = formatSection(\"Ecosystem\", data.ecosystem);\n section[0] = \"\";\n section[1] = chalk.bold(\"Ecosystem:\");\n lines.push(...section);\n }\n\n if (data.warnings.length > 0) {\n lines.push(\"\");\n lines.push(chalk.yellow.bold(\"Warnings:\"));\n for (const w of data.warnings) {\n lines.push(chalk.yellow(` ! ${w}`));\n }\n }\n\n return lines;\n}\n\nexport const info = new Command()\n .name(\"info\")\n .description(\"Print environment and package information for bug reports.\")\n .option(\n \"-c, --cwd <cwd>\",\n \"the working directory. defaults to the current directory.\",\n process.cwd(),\n )\n .action(async (opts) => {\n const cwd = resolveRealPath(opts.cwd);\n const packageJsonPath = path.join(cwd, \"package.json\");\n\n if (!fs.existsSync(packageJsonPath)) {\n console.error(\n chalk.red(\"No package.json found in the current directory.\"),\n );\n process.exit(1);\n }\n\n const projectPkg = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\"));\n const data = await collectInfo(cwd, projectPkg);\n\n // Colored output for terminal\n console.log(\"\");\n for (const line of renderColored(data)) {\n console.log(line);\n }\n console.log(\"\");\n\n // Copyable plain text\n const plain = renderPlain(data);\n const block = [\"```\", ...plain, \"```\"].join(\"\\n\");\n\n console.log(chalk.dim(\"— Copy the text below into your bug report —\"));\n console.log(\"\");\n console.log(block);\n console.log(\"\");\n });\n"],"mappings":";;;;;;;;;;AAYA,MAAM,wBAAwB;CAE5B;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;AAEA,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,4CAA4B,IAAI,IAAI;CACxC;CACA;CACA;AACF,CAAC;AAED,S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CACd,CAAC,CACA,OAAO,OAAO,SAAS;CACtB,MAAM,MAAM,gBAAgB,KAAK,GAAG;CACpC,MAAM,kBAAkBD,OAAK,KAAK,KAAK,cAAc;CAErD,IAAI,CAACC,KAAG,WAAW,eAAe,GAAG;EACnC,QAAQ,MACN,MAAM,IAAI,iDAAiD,CAC7D;EACA,QAAQ,KAAK,CAAC;CAChB;CAGA,MAAM,OAAO,MAAM,YAAY,KADZ,KAAK,MAAMA,KAAG,aAAa,iBAAiB,MAAM,CACxB,CAAC;CAG9C,QAAQ,IAAI,EAAE;CACd,KAAK,MAAM,QAAQ,cAAc,IAAI,GACnC,QAAQ,IAAI,IAAI;CAElB,QAAQ,IAAI,EAAE;CAId,MAAM,QAAQ;EAAC;EAAO,GADR,YAAY,IACG;EAAG;CAAK,CAAC,CAAC,KAAK,IAAI;CAEhD,QAAQ,IAAI,MAAM,IAAI,8CAA8C,CAAC;CACrE,QAAQ,IAAI,EAAE;CACd,QAAQ,IAAI,KAAK;CACjB,QAAQ,IAAI,EAAE;AAChB,CAAC"}
1
+ {"version":3,"file":"info.js","names":["path","fs","os"],"sources":["../../src/commands/info.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { spawnSync } from \"node:child_process\";\nimport chalk from \"chalk\";\nimport { detect } from \"detect-package-manager\";\nimport { satisfies } from \"semver\";\nimport { findWorkspaceRoot, resolveRealPath } from \"../lib/utils/workspace\";\n\nexport { findWorkspaceRoot };\n\nconst ASSISTANT_UI_PACKAGES = [\n // Distribution\n \"@assistant-ui/react\",\n \"@assistant-ui/react-native\",\n \"@assistant-ui/react-ink\",\n // Core (should not be installed directly)\n \"@assistant-ui/core\",\n \"@assistant-ui/store\",\n \"@assistant-ui/tap\",\n // Streaming & Cloud\n \"assistant-stream\",\n \"assistant-cloud\",\n \"@assistant-ui/cloud-ai-sdk\",\n // Adapters\n \"@assistant-ui/eve\",\n \"@assistant-ui/react-ai-sdk\",\n \"@assistant-ui/react-langgraph\",\n \"@assistant-ui/react-ag-ui\",\n \"@assistant-ui/react-a2a\",\n \"@assistant-ui/react-data-stream\",\n \"@assistant-ui/react-google-adk\",\n // UI / Rendering\n \"@assistant-ui/react-markdown\",\n \"@assistant-ui/react-streamdown\",\n \"@assistant-ui/react-lexical\",\n \"@assistant-ui/react-syntax-highlighter\",\n \"@assistant-ui/react-hook-form\",\n // Observability & DevTools\n \"@assistant-ui/react-o11y\",\n \"@assistant-ui/react-devtools\",\n];\n\nconst ECOSYSTEM_PACKAGES = [\n \"react\",\n \"react-dom\",\n \"react-native\",\n \"next\",\n \"vite\",\n \"expo\",\n \"ai\",\n \"zod\",\n \"zustand\",\n \"typescript\",\n];\n\n// Packages that users should NOT install directly — they are internal\n// dependencies pulled in automatically by distribution packages.\nconst SHOULD_NOT_DIRECT_INSTALL = new Set([\n \"@assistant-ui/core\",\n \"@assistant-ui/store\",\n \"@assistant-ui/tap\",\n]);\n\nfunction resolvePackageJson(pkg: string, cwd: string): string | null {\n let dir = cwd;\n const root = path.parse(dir).root;\n while (dir !== root) {\n const candidate = path.join(\n dir,\n \"node_modules\",\n ...pkg.split(\"/\"),\n \"package.json\",\n );\n if (fs.existsSync(candidate)) return candidate;\n dir = path.dirname(dir);\n }\n return null;\n}\n\nfunction getInstalledVersion(pkg: string, cwd: string): string | null {\n try {\n const pkgJsonPath = resolvePackageJson(pkg, cwd);\n if (pkgJsonPath) {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n return pkgJson.version ?? null;\n }\n } catch {\n // ignore\n }\n return null;\n}\n\nfunction readProjectDeps(\n projectPkg: Record<string, unknown>,\n): Record<string, string> {\n return {\n ...((projectPkg.dependencies ?? {}) as Record<string, string>),\n ...((projectPkg.devDependencies ?? {}) as Record<string, string>),\n };\n}\n\nfunction getAssistantUiPackageNames(\n projectPkg: Record<string, unknown>,\n): string[] {\n const declaredPackages = Object.keys(readProjectDeps(projectPkg))\n .filter((name) => name.startsWith(\"@assistant-ui/\"))\n .sort();\n\n return [...new Set([...ASSISTANT_UI_PACKAGES, ...declaredPackages])];\n}\n\nfunction getSpecifiedRange(\n pkg: string,\n projectPkg: Record<string, unknown>,\n): string | null {\n const deps = (projectPkg.dependencies ?? {}) as Record<string, string>;\n const devDeps = (projectPkg.devDependencies ?? {}) as Record<string, string>;\n return deps[pkg] ?? devDeps[pkg] ?? null;\n}\n\nfunction getPeerDeps(pkg: string, cwd: string): Record<string, string> | null {\n try {\n const pkgJsonPath = resolvePackageJson(pkg, cwd);\n if (pkgJsonPath) {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n return (pkgJson.peerDependencies as Record<string, string>) ?? null;\n }\n } catch {\n // ignore\n }\n return null;\n}\n\nfunction detectFramework(\n projectPkg: Record<string, unknown>,\n cwd: string,\n): string {\n const deps = readProjectDeps(projectPkg);\n\n if (deps.next) {\n const v = getInstalledVersion(\"next\", cwd);\n return `Next.js ${v ?? deps.next}`;\n }\n if (deps.expo) {\n const v = getInstalledVersion(\"expo\", cwd);\n return `Expo ${v ?? deps.expo}`;\n }\n if (deps.vite) {\n const v = getInstalledVersion(\"vite\", cwd);\n return `Vite ${v ?? deps.vite}`;\n }\n if (deps[\"@remix-run/react\"] || deps.remix) return \"Remix\";\n if (deps.gatsby) return \"Gatsby\";\n if (deps.astro) return \"Astro\";\n return \"Unknown\";\n}\n\nfunction getOsInfo(): string {\n const platform = os.platform();\n const arch = os.arch();\n const release = os.release();\n\n switch (platform) {\n case \"darwin\": {\n const result = spawnSync(\"sw_vers\", [\"-productVersion\"], {\n encoding: \"utf8\",\n });\n const macVer = result.stdout?.trim();\n return macVer\n ? `macOS ${macVer} (${arch})`\n : `macOS ${release} (${arch})`;\n }\n case \"win32\":\n return `Windows ${release} (${arch})`;\n case \"linux\":\n return `Linux ${release} (${arch})`;\n default:\n return `${platform} ${release} (${arch})`;\n }\n}\n\nfunction getCliVersion(): string {\n try {\n const packageJson = JSON.parse(\n fs.readFileSync(new URL(\"../../package.json\", import.meta.url), \"utf8\"),\n ) as { version?: unknown };\n return typeof packageJson.version === \"string\"\n ? packageJson.version\n : \"unknown\";\n } catch {\n return \"unknown\";\n }\n}\n\nasync function getPackageManagerInfo(\n cwd: string,\n): Promise<{ name: string; version: string }> {\n const pm = await detect({ cwd });\n const result = spawnSync(pm, [\"--version\"], {\n encoding: \"utf8\",\n cwd,\n });\n const version = result.stdout?.trim() ?? \"unknown\";\n return { name: pm, version };\n}\n\nexport function satisfiesRange(version: string, range: string): boolean {\n const normalizedRange = range.startsWith(\"workspace:\")\n ? range.slice(\"workspace:\".length)\n : range;\n\n return (\n normalizedRange === \"\" ||\n normalizedRange === \"^\" ||\n normalizedRange === \"~\" ||\n normalizedRange === \"any\" ||\n satisfies(version, normalizedRange, { includePrerelease: true })\n );\n}\n\ninterface PackageInfo {\n name: string;\n version: string;\n range: string | null;\n}\n\ninterface InfoData {\n cliVersion: string;\n os: string;\n node: string;\n pm: { name: string; version: string };\n framework: string;\n isMonorepo: boolean;\n packages: PackageInfo[];\n ecosystem: PackageInfo[];\n warnings: string[];\n}\n\nfunction collectPackages(\n names: string[],\n cwd: string,\n projectPkg: Record<string, unknown>,\n): PackageInfo[] {\n const result: PackageInfo[] = [];\n const deps = readProjectDeps(projectPkg);\n\n for (const name of names) {\n const version = getInstalledVersion(name, cwd);\n if (version) {\n result.push({\n name,\n version,\n range: getSpecifiedRange(name, projectPkg),\n });\n } else {\n // Fallback: no node_modules, show range from package.json\n const range = deps[name];\n if (range && !range.startsWith(\"workspace:\")) {\n result.push({ name, version: `${range} (not installed)`, range });\n }\n }\n }\n return result;\n}\n\nfunction collectWarnings(\n packages: PackageInfo[],\n cwd: string,\n projectPkg: Record<string, unknown>,\n): string[] {\n const warnings: string[] = [];\n const deps = readProjectDeps(projectPkg);\n\n // Check peer dependency mismatches\n for (const pkg of packages) {\n const peerDeps = getPeerDeps(pkg.name, cwd);\n if (!peerDeps) continue;\n\n for (const [peerName, peerRange] of Object.entries(peerDeps)) {\n const peerVersion = getInstalledVersion(peerName, cwd);\n if (!peerVersion) continue;\n if (!satisfiesRange(peerVersion, peerRange)) {\n warnings.push(\n `${pkg.name} requires ${peerName} ${peerRange}, found ${peerVersion}`,\n );\n }\n }\n }\n\n // Check for direct install of internal packages\n for (const name of SHOULD_NOT_DIRECT_INSTALL) {\n if (deps[name]) {\n warnings.push(\n `${name} should not be installed directly — it is an internal dependency`,\n );\n }\n }\n\n return warnings;\n}\n\nasync function collectInfo(\n cwd: string,\n projectPkg: Record<string, unknown>,\n): Promise<InfoData> {\n const pm = await getPackageManagerInfo(cwd);\n const packages = collectPackages(\n getAssistantUiPackageNames(projectPkg),\n cwd,\n projectPkg,\n );\n const ecosystem = collectPackages(ECOSYSTEM_PACKAGES, cwd, projectPkg);\n const warnings = collectWarnings(packages, cwd, projectPkg);\n\n return {\n cliVersion: getCliVersion(),\n os: getOsInfo(),\n node: process.version,\n pm,\n framework: detectFramework(projectPkg, cwd),\n isMonorepo: findWorkspaceRoot(cwd) !== null,\n packages,\n ecosystem,\n warnings,\n };\n}\n\nfunction formatSection(label: string, items: PackageInfo[]): string[] {\n if (items.length === 0) return [];\n const lines: string[] = [];\n lines.push(\"\");\n lines.push(`${label}:`);\n const maxLen = Math.max(...items.map((p) => p.name.length));\n for (const pkg of items) {\n lines.push(` ${pkg.name.padEnd(maxLen)} ${pkg.version}`);\n }\n return lines;\n}\n\nfunction renderPlain(data: InfoData): string[] {\n const lines: string[] = [];\n\n lines.push(\"Environment:\");\n lines.push(` assistant-ui CLI: ${data.cliVersion}`);\n lines.push(` OS: ${data.os}`);\n lines.push(` Node.js: ${data.node}`);\n lines.push(` Package Manager: ${data.pm.name} ${data.pm.version}`);\n lines.push(` Framework: ${data.framework}`);\n if (data.isMonorepo) {\n lines.push(` Monorepo: yes`);\n }\n\n lines.push(...formatSection(\"Packages\", data.packages));\n lines.push(...formatSection(\"Ecosystem\", data.ecosystem));\n\n if (data.warnings.length > 0) {\n lines.push(\"\");\n lines.push(\"Warnings:\");\n for (const w of data.warnings) {\n lines.push(` ! ${w}`);\n }\n }\n\n return lines;\n}\n\nfunction renderColored(data: InfoData): string[] {\n const lines: string[] = [];\n\n lines.push(chalk.bold(\"Environment:\"));\n lines.push(` assistant-ui CLI: ${data.cliVersion}`);\n lines.push(` OS: ${data.os}`);\n lines.push(` Node.js: ${data.node}`);\n lines.push(` Package Manager: ${data.pm.name} ${data.pm.version}`);\n lines.push(` Framework: ${data.framework}`);\n if (data.isMonorepo) {\n lines.push(` Monorepo: yes`);\n }\n\n if (data.packages.length > 0) {\n const section = formatSection(\"Packages\", data.packages);\n section[0] = \"\";\n section[1] = chalk.bold(\"Packages:\");\n lines.push(...section);\n } else {\n lines.push(\"\");\n lines.push(chalk.yellow(\" No assistant-ui packages found.\"));\n }\n\n if (data.ecosystem.length > 0) {\n const section = formatSection(\"Ecosystem\", data.ecosystem);\n section[0] = \"\";\n section[1] = chalk.bold(\"Ecosystem:\");\n lines.push(...section);\n }\n\n if (data.warnings.length > 0) {\n lines.push(\"\");\n lines.push(chalk.yellow.bold(\"Warnings:\"));\n for (const w of data.warnings) {\n lines.push(chalk.yellow(` ! ${w}`));\n }\n }\n\n return lines;\n}\n\nexport const info = new Command()\n .name(\"info\")\n .description(\"Print environment and package information for bug reports.\")\n .option(\n \"-c, --cwd <cwd>\",\n \"the working directory. defaults to the current directory.\",\n process.cwd(),\n )\n .action(async (opts) => {\n const cwd = resolveRealPath(opts.cwd);\n const packageJsonPath = path.join(cwd, \"package.json\");\n\n if (!fs.existsSync(packageJsonPath)) {\n console.error(\n chalk.red(\"No package.json found in the current directory.\"),\n );\n process.exit(1);\n }\n\n const projectPkg = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\"));\n const data = await collectInfo(cwd, projectPkg);\n\n // Colored output for terminal\n console.log(\"\");\n for (const line of renderColored(data)) {\n console.log(line);\n }\n console.log(\"\");\n\n // Copyable plain text\n const plain = renderPlain(data);\n const block = [\"```\", ...plain, \"```\"].join(\"\\n\");\n\n console.log(chalk.dim(\"— Copy the text below into your bug report —\"));\n console.log(\"\");\n console.log(block);\n console.log(\"\");\n });\n"],"mappings":";;;;;;;;;;AAYA,MAAM,wBAAwB;CAE5B;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;AAEA,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,4CAA4B,IAAI,IAAI;CACxC;CACA;CACA;AACF,CAAC;AAED,SAAS,mBAAmB,KAAa,KAA4B;CACnE,IAAI,MAAM;CACV,MAAM,OAAOA,OAAK,MAAM,GAAG,CAAC,CAAC;CAC7B,OAAO,QAAQ,MAAM;EACnB,MAAM,YAAYA,OAAK,KACrB,KACA,gBACA,GAAG,IAAI,MAAM,GAAG,GAChB,cACF;EACA,IAAIC,KAAG,WAAW,SAAS,GAAG,OAAO;EACrC,MAAMD,OAAK,QAAQ,GAAG;CACxB;CACA,OAAO;AACT;AAEA,SAAS,oBAAoB,KAAa,KAA4B;CACpE,IAAI;EACF,MAAM,cAAc,mBAAmB,KAAK,GAAG;EAC/C,IAAI,aAEF,OADgB,KAAK,MAAMC,KAAG,aAAa,aAAa,MAAM,CACjD,CAAC,CAAC,WAAW;CAE9B,QAAQ,CAER;CACA,OAAO;AACT;AAEA,SAAS,gBACP,YACwB;CACxB,OAAO;EACL,GAAK,WAAW,gBAAgB,CAAC;EACjC,GAAK,WAAW,mBAAmB,CAAC;CACtC;AACF;AAEA,SAAS,2BACP,YACU;CACV,MAAM,mBAAmB,OAAO,KAAK,gBAAgB,UAAU,CAAC,CAAC,CAC9D,QAAQ,SAAS,KAAK,WAAW,gBAAgB,CAAC,CAAC,CACnD,KAAK;CAER,OAAO,CAAC,mBAAG,IAAI,IAAI,CA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,SAAS;EACzD,QAAQ,KAAK;EACb,QAAQ,KAAK,MAAM,KAAK,YAAY;EACpC,MAAM,KAAK,GAAG,OAAO;CACvB;CAEA,IAAI,KAAK,SAAS,SAAS,GAAG;EAC5B,MAAM,KAAK,EAAE;EACb,MAAM,KAAK,MAAM,OAAO,KAAK,WAAW,CAAC;EACzC,KAAK,MAAM,KAAK,KAAK,UACnB,MAAM,KAAK,MAAM,OAAO,OAAO,GAAG,CAAC;CAEvC;CAEA,OAAO;AACT;AAEA,MAAa,OAAO,IAAI,QAAQ,CAAC,CAC9B,KAAK,MAAM,CAAC,CACZ,YAAY,4DAA4D,CAAC,CACzE,OACC,mBACA,6DACA,QAAQ,IAAI,CACd,CAAC,CACA,OAAO,OAAO,SAAS;CACtB,MAAM,MAAM,gBAAgB,KAAK,GAAG;CACpC,MAAM,kBAAkBD,OAAK,KAAK,KAAK,cAAc;CAErD,IAAI,CAACC,KAAG,WAAW,eAAe,GAAG;EACnC,QAAQ,MACN,MAAM,IAAI,iDAAiD,CAC7D;EACA,QAAQ,KAAK,CAAC;CAChB;CAGA,MAAM,OAAO,MAAM,YAAY,KADZ,KAAK,MAAMA,KAAG,aAAa,iBAAiB,MAAM,CACxB,CAAC;CAG9C,QAAQ,IAAI,EAAE;CACd,KAAK,MAAM,QAAQ,cAAc,IAAI,GACnC,QAAQ,IAAI,IAAI;CAElB,QAAQ,IAAI,EAAE;CAId,MAAM,QAAQ;EAAC;EAAO,GADR,YAAY,IACG;EAAG;CAAK,CAAC,CAAC,KAAK,IAAI;CAEhD,QAAQ,IAAI,MAAM,IAAI,8CAA8C,CAAC;CACrE,QAAQ,IAAI,EAAE;CACd,QAAQ,IAAI,KAAK;CACjB,QAAQ,IAAI,EAAE;AAChB,CAAC"}
@@ -65,7 +65,8 @@ const init = new Command().name("init").description("initialize assistant-ui in
65
65
  process.exit(1);
66
66
  }
67
67
  try {
68
- const [dlxCmd, dlxArgs] = dlxCommand(await resolvePackageManagerForCwd(targetDir, resolvePackageManager(opts)));
68
+ const pm = await resolvePackageManagerForCwd(targetDir, resolvePackageManager(opts));
69
+ const [dlxCmd, dlxArgs] = dlxCommand(pm);
69
70
  const { initArgs, addArgs } = createExistingProjectInitPlan({
70
71
  yes: opts.yes,
71
72
  overwrite: opts.overwrite
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":[],"sources":["../../src/commands/init.ts"],"sourcesContent":["import { Command, Option } from \"commander\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n dlxCommand,\n resolvePackageManager,\n resolvePackageManagerForCwd,\n} from \"../lib/create-project\";\nimport { runSpawn, SpawnExitError } from \"../lib/run-spawn\";\nimport { logger } from \"../lib/utils/logger\";\nimport {\n getComponentsJsonStyle,\n resolveQuickStartRegistryUrl,\n} from \"../lib/utils/registry\";\nimport { create } from \"./create\";\n\ninterface ExistingProjectInitPlan {\n initArgs: string[];\n addArgs: string[];\n}\n\nexport function createExistingProjectInitPlan(params: {\n yes: boolean;\n overwrite: boolean;\n}): ExistingProjectInitPlan {\n const { yes, overwrite } = params;\n const initArgs = yes\n ? [`shadcn@latest`, \"init\", \"--defaults\", \"--yes\"]\n : [`shadcn@latest`, \"init\"];\n const addArgs = [`shadcn@latest`, \"add\"];\n if (yes) addArgs.push(\"--yes\");\n if (overwrite) addArgs.push(\"--overwrite\");\n\n return { initArgs, addArgs };\n}\n\nexport function isNonInteractiveShell(\n stdinIsTTY = process.stdin.isTTY,\n): boolean {\n return !stdinIsTTY;\n}\n\nexport const init = new Command()\n .name(\"init\")\n .description(\"initialize assistant-ui in an existing project\")\n .argument(\"[project-directory]\", \"directory for the new project\")\n .option(\"-y, --yes\", \"skip confirmation prompt.\", false)\n .option(\"-o, --overwrite\", \"overwrite existing files.\", false)\n .option(\n \"-c, --cwd <cwd>\",\n \"the working directory. defaults to the current directory.\",\n process.cwd(),\n )\n .addOption(\n new Option(\n \"-p, --preset <name-or-url>\",\n \"preset name or URL (forwarded to 'assistant-ui create')\",\n ).hideHelp(),\n )\n .option(\"--use-npm\", \"explicitly use npm\")\n .option(\"--use-pnpm\", \"explicitly use pnpm\")\n .option(\"--use-yarn\", \"explicitly use yarn\")\n .option(\"--use-bun\", \"explicitly use bun\")\n .option(\"--skip-install\", \"skip installing packages\")\n .action(async (projectDirectory, opts) => {\n const cwd = opts.cwd;\n const presetUrl = opts.preset as string | undefined;\n const targetDir = projectDirectory\n ? path.resolve(cwd, projectDirectory)\n : cwd;\n\n const componentsConfigPath = path.join(targetDir, \"components.json\");\n\n if (!presetUrl && fs.existsSync(componentsConfigPath)) {\n logger.warn(\"Project is already initialized.\");\n logger.info(\"Use 'assistant-ui add' to add more components.\");\n return;\n }\n\n const packageJsonPath = path.join(targetDir, \"package.json\");\n const packageJsonExists = fs.existsSync(packageJsonPath);\n\n if (presetUrl || !packageJsonExists) {\n if (!presetUrl) {\n logger.info(\"No existing project found. Running 'create' instead...\");\n logger.break();\n }\n\n const createArgs: string[] = [];\n if (projectDirectory) createArgs.push(projectDirectory);\n if (presetUrl) createArgs.push(\"--preset\", presetUrl);\n if (opts.useNpm) createArgs.push(\"--use-npm\");\n if (opts.usePnpm) createArgs.push(\"--use-pnpm\");\n if (opts.useYarn) createArgs.push(\"--use-yarn\");\n if (opts.useBun) createArgs.push(\"--use-bun\");\n if (opts.skipInstall) createArgs.push(\"--skip-install\");\n\n await create.parseAsync(createArgs, { from: \"user\" });\n return;\n }\n\n logger.info(\"Initializing assistant-ui in existing project...\");\n logger.break();\n\n if (!opts.yes && isNonInteractiveShell()) {\n logger.error(\n [\n \"Detected a non-interactive shell, but 'assistant-ui init' needs interactive prompts by default.\",\n \"To run this in CI/agent mode, re-run with '--yes' so shadcn initialization and component install run non-interactively.\",\n \"Example: assistant-ui init --yes\",\n ].join(\"\\n\"),\n );\n process.exit(1);\n }\n\n try {\n const pm = await resolvePackageManagerForCwd(\n targetDir,\n resolvePackageManager(opts),\n );\n const [dlxCmd, dlxArgs] = dlxCommand(pm);\n\n const { initArgs, addArgs } = createExistingProjectInitPlan({\n yes: opts.yes,\n overwrite: opts.overwrite,\n });\n\n await runSpawn(dlxCmd, [...dlxArgs, ...initArgs], targetDir);\n const registryUrl = resolveQuickStartRegistryUrl(\n getComponentsJsonStyle(targetDir),\n );\n await runSpawn(dlxCmd, [...dlxArgs, ...addArgs, registryUrl], targetDir);\n\n logger.break();\n logger.success(\"Project initialized successfully!\");\n logger.info(\"You can now add more components with 'assistant-ui add'\");\n } catch (error) {\n if (error instanceof SpawnExitError) {\n logger.error(`Initialization failed with code ${error.code}`);\n process.exit(error.code);\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to initialize: ${message}`);\n process.exit(1);\n }\n });\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,8BAA8B,QAGlB;CAC1B,MAAM,EAAE,KAAK,cAAc;CAC3B,MAAM,WAAW,MACb;EAAC;EAAiB;EAAQ;EAAc;CAAO,IAC/C,CAAC,iBAAiB,MAAM;CAC5B,MAAM,UAAU,CAAC,iBAAiB,KAAK;CACvC,IAAI,KAAK,QAAQ,KAAK,OAAO;CAC7B,IAAI,WAAW,QAAQ,KAAK,aAAa;CAEzC,OAAO;EAAE;EAAU;CAAQ;AAC7B;AAEA,SAAgB,sBACd,aAAa,QAAQ,MAAM,OAClB;CACT,OAAO,CAAC;AACV;AAEA,MAAa,OAAO,IAAI,QAAQ,CAAC,CAC9B,KAAK,MAAM,CAAC,CACZ,YAAY,gDAAgD,CAAC,CAC7D,SAAS,uBAAuB,+BAA+B,CAAC,CAChE,OAAO,aAAa,6BAA6B,KAAK,CAAC,CACvD,OAAO,mBAAmB,6BAA6B,KAAK,CAAC,CAC7D,OACC,mBACA,6DACA,QAAQ,IAAI,CACd,CAAC,CACA,UACC,IAAI,OACF,8BACA,yDACF,CAAC,CAAC,SAAS,CACb,CAAC,CACA,OAAO,aAAa,oBAAoB,CAAC,CACzC,OAAO,cAAc,qBAAqB,CAAC,CAC3C,OAAO,cAAc,qBAAqB,CAAC,CAC3C,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EAEvC,MAAM,EAAE,UAAU,YAAY,8BAA8B;GAC1D,KAAK,KAAK;GACV,WAAW,KAAK;EAClB,CAAC;EAED,MAAM,SAAS,QAAQ,CAAC,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS;EAC3D,MAAM,cAAc,6BAClB,uBAAuB,SAAS,CAClC;EACA,MAAM,SAAS,QAAQ;GAAC,GAAG;GAAS,GAAG;GAAS;EAAW,GAAG,SAAS;EAEvE,OAAO,MAAM;EACb,OAAO,QAAQ,mCAAmC;EAClD,OAAO,KAAK,yDAAyD;CACvE,SAAS,OAAO;EACd,IAAI,iBAAiB,gBAAgB;GACnC,OAAO,MAAM,mCAAmC,MAAM,MAAM;GAC5D,QAAQ,KAAK,MAAM,IAAI;EACzB;EACA,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,OAAO,MAAM,yBAAyB,SAAS;EAC/C,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC"}
1
+ {"version":3,"file":"init.js","names":[],"sources":["../../src/commands/init.ts"],"sourcesContent":["import { Command, Option } from \"commander\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n dlxCommand,\n resolvePackageManager,\n resolvePackageManagerForCwd,\n} from \"../lib/create-project\";\nimport { runSpawn, SpawnExitError } from \"../lib/run-spawn\";\nimport { logger } from \"../lib/utils/logger\";\nimport {\n getComponentsJsonStyle,\n resolveQuickStartRegistryUrl,\n} from \"../lib/utils/registry\";\nimport { create } from \"./create\";\n\ninterface ExistingProjectInitPlan {\n initArgs: string[];\n addArgs: string[];\n}\n\nexport function createExistingProjectInitPlan(params: {\n yes: boolean;\n overwrite: boolean;\n}): ExistingProjectInitPlan {\n const { yes, overwrite } = params;\n const initArgs = yes\n ? [`shadcn@latest`, \"init\", \"--defaults\", \"--yes\"]\n : [`shadcn@latest`, \"init\"];\n const addArgs = [`shadcn@latest`, \"add\"];\n if (yes) addArgs.push(\"--yes\");\n if (overwrite) addArgs.push(\"--overwrite\");\n\n return { initArgs, addArgs };\n}\n\nexport function isNonInteractiveShell(\n stdinIsTTY = process.stdin.isTTY,\n): boolean {\n return !stdinIsTTY;\n}\n\nexport const init = new Command()\n .name(\"init\")\n .description(\"initialize assistant-ui in an existing project\")\n .argument(\"[project-directory]\", \"directory for the new project\")\n .option(\"-y, --yes\", \"skip confirmation prompt.\", false)\n .option(\"-o, --overwrite\", \"overwrite existing files.\", false)\n .option(\n \"-c, --cwd <cwd>\",\n \"the working directory. defaults to the current directory.\",\n process.cwd(),\n )\n .addOption(\n new Option(\n \"-p, --preset <name-or-url>\",\n \"preset name or URL (forwarded to 'assistant-ui create')\",\n ).hideHelp(),\n )\n .option(\"--use-npm\", \"explicitly use npm\")\n .option(\"--use-pnpm\", \"explicitly use pnpm\")\n .option(\"--use-yarn\", \"explicitly use yarn\")\n .option(\"--use-bun\", \"explicitly use bun\")\n .option(\"--skip-install\", \"skip installing packages\")\n .action(async (projectDirectory, opts) => {\n const cwd = opts.cwd;\n const presetUrl = opts.preset as string | undefined;\n const targetDir = projectDirectory\n ? path.resolve(cwd, projectDirectory)\n : cwd;\n\n const componentsConfigPath = path.join(targetDir, \"components.json\");\n\n if (!presetUrl && fs.existsSync(componentsConfigPath)) {\n logger.warn(\"Project is already initialized.\");\n logger.info(\"Use 'assistant-ui add' to add more components.\");\n return;\n }\n\n const packageJsonPath = path.join(targetDir, \"package.json\");\n const packageJsonExists = fs.existsSync(packageJsonPath);\n\n if (presetUrl || !packageJsonExists) {\n if (!presetUrl) {\n logger.info(\"No existing project found. Running 'create' instead...\");\n logger.break();\n }\n\n const createArgs: string[] = [];\n if (projectDirectory) createArgs.push(projectDirectory);\n if (presetUrl) createArgs.push(\"--preset\", presetUrl);\n if (opts.useNpm) createArgs.push(\"--use-npm\");\n if (opts.usePnpm) createArgs.push(\"--use-pnpm\");\n if (opts.useYarn) createArgs.push(\"--use-yarn\");\n if (opts.useBun) createArgs.push(\"--use-bun\");\n if (opts.skipInstall) createArgs.push(\"--skip-install\");\n\n await create.parseAsync(createArgs, { from: \"user\" });\n return;\n }\n\n logger.info(\"Initializing assistant-ui in existing project...\");\n logger.break();\n\n if (!opts.yes && isNonInteractiveShell()) {\n logger.error(\n [\n \"Detected a non-interactive shell, but 'assistant-ui init' needs interactive prompts by default.\",\n \"To run this in CI/agent mode, re-run with '--yes' so shadcn initialization and component install run non-interactively.\",\n \"Example: assistant-ui init --yes\",\n ].join(\"\\n\"),\n );\n process.exit(1);\n }\n\n try {\n const pm = await resolvePackageManagerForCwd(\n targetDir,\n resolvePackageManager(opts),\n );\n const [dlxCmd, dlxArgs] = dlxCommand(pm);\n\n const { initArgs, addArgs } = createExistingProjectInitPlan({\n yes: opts.yes,\n overwrite: opts.overwrite,\n });\n\n await runSpawn(dlxCmd, [...dlxArgs, ...initArgs], targetDir);\n const registryUrl = resolveQuickStartRegistryUrl(\n getComponentsJsonStyle(targetDir),\n );\n await runSpawn(dlxCmd, [...dlxArgs, ...addArgs, registryUrl], targetDir);\n\n logger.break();\n logger.success(\"Project initialized successfully!\");\n logger.info(\"You can now add more components with 'assistant-ui add'\");\n } catch (error) {\n if (error instanceof SpawnExitError) {\n logger.error(`Initialization failed with code ${error.code}`);\n process.exit(error.code);\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to initialize: ${message}`);\n process.exit(1);\n }\n });\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,8BAA8B,QAGlB;CAC1B,MAAM,EAAE,KAAK,cAAc;CAC3B,MAAM,WAAW,MACb;EAAC;EAAiB;EAAQ;EAAc;CAAO,IAC/C,CAAC,iBAAiB,MAAM;CAC5B,MAAM,UAAU,CAAC,iBAAiB,KAAK;CACvC,IAAI,KAAK,QAAQ,KAAK,OAAO;CAC7B,IAAI,WAAW,QAAQ,KAAK,aAAa;CAEzC,OAAO;EAAE;EAAU;CAAQ;AAC7B;AAEA,SAAgB,sBACd,aAAa,QAAQ,MAAM,OAClB;CACT,OAAO,CAAC;AACV;AAEA,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,WAAW,KAAK,WAAW;EAC5C,IAAI,KAAK,aAAa,WAAW,KAAK,gBAAgB;EAEtD,MAAM,OAAO,WAAW,YAAY,EAAE,MAAM,OAAO,CAAC;EACpD;CACF;CAEA,OAAO,KAAK,kDAAkD;CAC9D,OAAO,MAAM;CAEb,IAAI,CAAC,KAAK,OAAO,sBAAsB,GAAG;EACxC,OAAO,MACL;GACE;GACA;GACA;EACF,CAAC,CAAC,KAAK,IAAI,CACb;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI;EACF,MAAM,KAAK,MAAM,4BACf,WACA,sBAAsB,IAAI,CAC5B;EACA,MAAM,CAAC,QAAQ,WAAW,WAAW,EAAE;EAEvC,MAAM,EAAE,UAAU,YAAY,8BAA8B;GAC1D,KAAK,KAAK;GACV,WAAW,KAAK;EAClB,CAAC;EAED,MAAM,SAAS,QAAQ,CAAC,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS;EAC3D,MAAM,cAAc,6BAClB,uBAAuB,SAAS,CAClC;EACA,MAAM,SAAS,QAAQ;GAAC,GAAG;GAAS,GAAG;GAAS;EAAW,GAAG,SAAS;EAEvE,OAAO,MAAM;EACb,OAAO,QAAQ,mCAAmC;EAClD,OAAO,KAAK,yDAAyD;CACvE,SAAS,OAAO;EACd,IAAI,iBAAiB,gBAAgB;GACnC,OAAO,MAAM,mCAAmC,MAAM,MAAM;GAC5D,QAAQ,KAAK,MAAM,IAAI;EACzB;EACA,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACrE,OAAO,MAAM,yBAAyB,SAAS;EAC/C,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC"}
@@ -19,9 +19,9 @@ const codemodCommand = addTransformOptions(new Command().name("codemod").descrip
19
19
  process.exit(1);
20
20
  }
21
21
  });
22
- const upgradeCommand = addTransformOptions(new Command().command("upgrade").description("Upgrade ai package dependencies and apply codemods")).action((options) => {
22
+ const upgradeCommand = addTransformOptions(new Command().command("upgrade").description("Upgrade ai package dependencies and apply codemods")).action(async (options) => {
23
23
  try {
24
- upgrade(options);
24
+ await upgrade(options);
25
25
  } catch (err) {
26
26
  const errorMessage = err instanceof Error ? err.message : String(err);
27
27
  const errorStack = err instanceof Error ? err.stack : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade.js","names":[],"sources":["../../src/commands/upgrade.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { transform } from \"../lib/transform\";\nimport { upgrade } from \"../lib/upgrade\";\nimport debug from \"debug\";\n\nexport interface TransformOptions {\n dry?: boolean;\n print?: boolean;\n verbose?: boolean;\n jscodeshift?: string;\n}\n\nconst error = debug(\"codemod:error\");\ndebug.enable(\"codemod:*\");\n\nconst addTransformOptions = (command: Command): Command => {\n return command\n .option(\"-d, --dry\", \"Dry run (no changes are made to files)\")\n .option(\"-p, --print\", \"Print transformed files to stdout\")\n .option(\"--verbose\", \"Show more information about the transform process\")\n .option(\n \"-j, --jscodeshift <options>\",\n \"Pass options directly to jscodeshift\",\n );\n};\n\nexport const codemodCommand = addTransformOptions(\n new Command()\n .name(\"codemod\")\n .description(\"CLI tool for running codemods\")\n .argument(\"<codemod>\", \"Codemod to run (e.g., rewrite-framework-imports)\")\n .argument(\"<source>\", \"Path to source files or directory to transform\"),\n).action((codemod, source, options: TransformOptions) => {\n try {\n transform(codemod, source, options);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n const errorStack = err instanceof Error ? err.stack : undefined;\n error(`Error transforming: ${errorMessage}`);\n if (errorStack) {\n error(errorStack);\n }\n process.exit(1);\n }\n});\n\nexport const upgradeCommand = addTransformOptions(\n new Command()\n .command(\"upgrade\")\n .description(\"Upgrade ai package dependencies and apply codemods\"),\n).action((options: TransformOptions) => {\n try {\n upgrade(options);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n const errorStack = err instanceof Error ? err.stack : undefined;\n error(`Error upgrading: ${errorMessage}`);\n if (errorStack) {\n error(errorStack);\n }\n process.exit(1);\n }\n});\n"],"mappings":";;;;;AAYA,MAAM,QAAQ,MAAM,eAAe;AACnC,MAAM,OAAO,WAAW;AAExB,MAAM,uBAAuB,YAA8B;CACzD,OAAO,QACJ,OAAO,aAAa,wCAAwC,CAAC,CAC7D,OAAO,eAAe,mCAAmC,CAAC,CAC1D,OAAO,aAAa,mDAAmD,CAAC,CACxE,OACC,+BACA,sCACF;AACJ;AAEA,MAAa,iBAAiB,oBAC5B,IAAI,QAAQ,CAAC,CACV,KAAK,SAAS,CAAC,CACf,YAAY,+BAA+B,CAAC,CAC5C,SAAS,aAAa,kDAAkD,CAAC,CACzE,SAAS,YAAY,gDAAgD,CAC1E,CAAC,CAAC,QAAQ,SAAS,QAAQ,YAA8B;CACvD,IAAI;EACF,UAAU,SAAS,QAAQ,OAAO;CACpC,SAAS,KAAK;EACZ,MAAM,eAAe,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EACpE,MAAM,aAAa,eAAe,QAAQ,IAAI,QAAQ,KAAA;EACtD,MAAM,uBAAuB,cAAc;EAC3C,IAAI,YACF,MAAM,UAAU;EAElB,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC;AAED,MAAa,iBAAiB,oBAC5B,IAAI,QAAQ,CAAC,CACV,QAAQ,SAAS,CAAC,CAClB,YAAY,oDAAoD,CACrE,CAAC,CAAC,QAAQ,YAA8B;CACtC,IAAI;EACF,QAAQ,OAAO;CACjB,SAAS,KAAK;EACZ,MAAM,eAAe,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EACpE,MAAM,aAAa,eAAe,QAAQ,IAAI,QAAQ,KAAA;EACtD,MAAM,oBAAoB,cAAc;EACxC,IAAI,YACF,MAAM,UAAU;EAElB,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC"}
1
+ {"version":3,"file":"upgrade.js","names":[],"sources":["../../src/commands/upgrade.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { transform } from \"../lib/transform\";\nimport { upgrade } from \"../lib/upgrade\";\nimport debug from \"debug\";\n\nexport interface TransformOptions {\n dry?: boolean;\n print?: boolean;\n verbose?: boolean;\n jscodeshift?: string;\n}\n\nconst error = debug(\"codemod:error\");\ndebug.enable(\"codemod:*\");\n\nconst addTransformOptions = (command: Command): Command => {\n return command\n .option(\"-d, --dry\", \"Dry run (no changes are made to files)\")\n .option(\"-p, --print\", \"Print transformed files to stdout\")\n .option(\"--verbose\", \"Show more information about the transform process\")\n .option(\n \"-j, --jscodeshift <options>\",\n \"Pass options directly to jscodeshift\",\n );\n};\n\nexport const codemodCommand = addTransformOptions(\n new Command()\n .name(\"codemod\")\n .description(\"CLI tool for running codemods\")\n .argument(\"<codemod>\", \"Codemod to run (e.g., rewrite-framework-imports)\")\n .argument(\"<source>\", \"Path to source files or directory to transform\"),\n).action((codemod, source, options: TransformOptions) => {\n try {\n transform(codemod, source, options);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n const errorStack = err instanceof Error ? err.stack : undefined;\n error(`Error transforming: ${errorMessage}`);\n if (errorStack) {\n error(errorStack);\n }\n process.exit(1);\n }\n});\n\nexport const upgradeCommand = addTransformOptions(\n new Command()\n .command(\"upgrade\")\n .description(\"Upgrade ai package dependencies and apply codemods\"),\n).action(async (options: TransformOptions) => {\n try {\n await upgrade(options);\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : String(err);\n const errorStack = err instanceof Error ? err.stack : undefined;\n error(`Error upgrading: ${errorMessage}`);\n if (errorStack) {\n error(errorStack);\n }\n process.exit(1);\n }\n});\n"],"mappings":";;;;;AAYA,MAAM,QAAQ,MAAM,eAAe;AACnC,MAAM,OAAO,WAAW;AAExB,MAAM,uBAAuB,YAA8B;CACzD,OAAO,QACJ,OAAO,aAAa,wCAAwC,CAAC,CAC7D,OAAO,eAAe,mCAAmC,CAAC,CAC1D,OAAO,aAAa,mDAAmD,CAAC,CACxE,OACC,+BACA,sCACF;AACJ;AAEA,MAAa,iBAAiB,oBAC5B,IAAI,QAAQ,CAAC,CACV,KAAK,SAAS,CAAC,CACf,YAAY,+BAA+B,CAAC,CAC5C,SAAS,aAAa,kDAAkD,CAAC,CACzE,SAAS,YAAY,gDAAgD,CAC1E,CAAC,CAAC,QAAQ,SAAS,QAAQ,YAA8B;CACvD,IAAI;EACF,UAAU,SAAS,QAAQ,OAAO;CACpC,SAAS,KAAK;EACZ,MAAM,eAAe,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EACpE,MAAM,aAAa,eAAe,QAAQ,IAAI,QAAQ,KAAA;EACtD,MAAM,uBAAuB,cAAc;EAC3C,IAAI,YACF,MAAM,UAAU;EAElB,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC;AAED,MAAa,iBAAiB,oBAC5B,IAAI,QAAQ,CAAC,CACV,QAAQ,SAAS,CAAC,CAClB,YAAY,oDAAoD,CACrE,CAAC,CAAC,OAAO,OAAO,YAA8B;CAC5C,IAAI;EACF,MAAM,QAAQ,OAAO;CACvB,SAAS,KAAK;EACZ,MAAM,eAAe,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EACpE,MAAM,aAAa,eAAe,QAAQ,IAAI,QAAQ,KAAA;EACtD,MAAM,oBAAoB,cAAc;EACxC,IAAI,YACF,MAAM,UAAU;EAElB,QAAQ,KAAK,CAAC;CAChB;AACF,CAAC"}
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { buildProgram } from "./program.js";
2
+ import { runCli } from "./run.js";
3
3
  //#region src/index.ts
4
4
  process.on("SIGINT", () => process.exit(0));
5
5
  process.on("SIGTERM", () => process.exit(0));
6
- function main() {
7
- buildProgram().parse();
8
- }
9
- main();
6
+ runCli().catch((error) => {
7
+ console.error(error);
8
+ process.exitCode = 1;
9
+ });
10
10
  //#endregion
11
11
 
12
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { buildProgram } from \"./program\";\n\nprocess.on(\"SIGINT\", () => process.exit(0));\nprocess.on(\"SIGTERM\", () => process.exit(0));\n\nfunction main() {\n buildProgram().parse();\n}\n\nmain();\n"],"mappings":";;;AAIA,QAAQ,GAAG,gBAAgB,QAAQ,KAAK,CAAC,CAAC;AAC1C,QAAQ,GAAG,iBAAiB,QAAQ,KAAK,CAAC,CAAC;AAE3C,SAAS,OAAO;CACd,aAAa,CAAC,CAAC,MAAM;AACvB;AAEA,KAAK"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { runCli } from \"./run\";\n\nprocess.on(\"SIGINT\", () => process.exit(0));\nprocess.on(\"SIGTERM\", () => process.exit(0));\n\nvoid runCli().catch((error: unknown) => {\n console.error(error);\n process.exitCode = 1;\n});\n"],"mappings":";;;AAIA,QAAQ,GAAG,gBAAgB,QAAQ,KAAK,CAAC,CAAC;AAC1C,QAAQ,GAAG,iBAAiB,QAAQ,KAAK,CAAC,CAAC;AAEtC,OAAO,CAAC,CAAC,OAAO,UAAmB;CACtC,QAAQ,MAAM,KAAK;CACnB,QAAQ,WAAW;AACrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","names":["globSync","fs"],"sources":["../../src/lib/transform.ts"],"sourcesContent":["import { execFileSync, spawnSync } from \"node:child_process\";\nimport debug from \"debug\";\nimport path from \"node:path\";\nimport type { TransformOptions } from \"./transform-options\";\nimport { fileURLToPath } from \"node:url\";\nimport * as fs from \"node:fs\";\nimport { sync as globSync } from \"glob\";\n\nconst log = debug(\"codemod:transform\");\nconst error = debug(\"codemod:transform:error\");\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n/**\n * Gets the list of files that need to be processed in the codebase\n * Only includes files that contain \"assistant-ui\" to optimize performance\n */\nexport function getRelevantFiles(cwd: string): string[] {\n const pattern = \"**/*.{js,jsx,ts,tsx}\";\n const files = globSync(pattern, {\n cwd,\n ignore: [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/*.min.js\",\n \"**/*.bundle.js\",\n ],\n });\n\n // Filter files to only include those containing \"assistant-ui\"\n const relevantFiles = files.filter((file) => {\n try {\n const content = fs.readFileSync(path.join(cwd, file), \"utf8\");\n return content.includes(\"assistant-ui\");\n } catch {\n return false;\n }\n });\n\n return relevantFiles.map((file) => path.join(cwd, file));\n}\n\n/**\n * Counts the number of files that need to be processed\n */\nexport function countFilesToProcess(cwd: string): number {\n return getRelevantFiles(cwd).length;\n}\n\nfunction buildCommand(\n codemodPath: string,\n targetFiles: string[],\n options: TransformOptions,\n): string[] {\n const command = [\n \"npx\",\n \"jscodeshift\",\n \"-t\",\n codemodPath,\n ...targetFiles,\n \"--parser\",\n \"tsx\",\n ];\n\n if (options.dry) {\n command.push(\"--dry\");\n }\n\n if (options.print) {\n command.push(\"--print\");\n }\n\n if (options.verbose) {\n command.push(\"--verbose\");\n }\n\n if (options.jscodeshift) {\n command.push(options.jscodeshift);\n }\n\n return command;\n}\n\nexport type TransformErrors = {\n transform: string;\n filename: string;\n summary: string;\n}[];\n\nfunction parseErrors(transform: string, output: string): TransformErrors {\n const errors: TransformErrors = [];\n const errorRegex = /ERR (.+) Transformation error/g;\n const syntaxErrorRegex = /SyntaxError: .+/g;\n\n for (const match of output.matchAll(errorRegex)) {\n const filename = match[1]!;\n const syntaxErrorMatch = syntaxErrorRegex.exec(output);\n if (syntaxErrorMatch) {\n const summary = syntaxErrorMatch[0];\n errors.push({ transform, filename, summary });\n }\n }\n\n return errors;\n}\n\nexport function transform(\n codemod: string,\n source: string,\n transformOptions: TransformOptions,\n options: {\n logStatus: boolean;\n onProgress?: (processedFiles: number) => void;\n relevantFiles?: string[];\n } = { logStatus: true },\n): TransformErrors {\n if (options.logStatus) {\n log(`Applying codemod '${codemod}': ${source}`);\n }\n const codemodPath = path.resolve(__dirname, `../codemods/${codemod}.js`);\n\n // Use pre-computed relevant files if provided, otherwise get them\n const targetFiles = options.relevantFiles || getRelevantFiles(source);\n\n if (targetFiles.length === 0) {\n log(`No relevant files found for codemod '${codemod}'`);\n return [];\n }\n\n log(`Found ${targetFiles.length} relevant files for codemod '${codemod}'`);\n\n const command = buildCommand(codemodPath, targetFiles, transformOptions);\n\n // Use spawn instead of execFileSync to capture output in real-time\n if (options.onProgress) {\n const result = spawnSync(command[0]!, command.slice(1), {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n const stdout = result.stdout || \"\";\n\n // Count the number of processed files from the output\n const processedFiles = (stdout.match(/Processing file/g) || []).length;\n if (options.onProgress) {\n options.onProgress(processedFiles);\n }\n\n const errors = parseErrors(codemod, stdout);\n if (options.logStatus && errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(\n `Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`,\n );\n });\n }\n return errors;\n } else {\n // Use the original synchronous approach if no progress callback\n const stdout = execFileSync(command[0]!, command.slice(1), {\n encoding: \"utf8\",\n stdio: \"pipe\",\n });\n const errors = parseErrors(codemod, stdout);\n if (options.logStatus && errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(\n `Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`,\n );\n });\n }\n return errors;\n }\n}\n"],"mappings":";;;;;;;AAQA,MAAM,MAAM,MAAM,mBAAmB;AACrC,MAAM,QAAQ,MAAM,yBAAyB;AAE7C,MAAM,aAAa,cAAc,OAAO,KAAK,GAAG;AAChD,MAAM,YAAY,KAAK,QAAQ,UAAU;;;;;AAMzC,SAAgB,iBAAiB,KAAuB;CAuBtD,OArBcA,KAAS,wBAAS;EAC9B;EACA,QAAQ;GACN;GACA;GACA;GACA;GACA;EACF;CACF,CAG0B,CAAC,CAAC,QAAQ,SAAS;EAC3C,IAAI;GAEF,OADgBC,KAAG,aAAa,KAAK,KAAK,KAAK,IAAI,GAAG,MACzC,CAAC,CAAC,SAAS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CAGvE,IAAI,QAAQ,YAAY;EAMtB,MAAM,SALS,UAAU,QAAQ,IAAK,QAAQ,MAAM,CAAC,GAAG;GACtD,UAAU;GACV,OAAO;IAAC;IAAU;IAAQ;GAAM;EAClC,CAEoB,CAAC,CAAC,UAAU;EAGhC,MAAM,kBAAkB,OAAO,MAAM,kBAAkB,KAAK,CAAC,EAAA,CAAG;EAChE,IAAI,QAAQ,YACV,QAAQ,WAAW,cAAc;EAGnC,MAAM,SAAS,YAAY,SAAS,MAAM;EAC1C,IAAI,QAAQ,aAAa,OAAO,SAAS,GACvC,OAAO,SAAS,EAAE,WAAW,UAAU,cAAc;GACnD,MACE,mCAAmC,UAAU,SAAS,SAAS,YAAY,QAAQ,EACrF;EACF,CAAC;EAEH,OAAO;CACT,OAAO;EAML,MAAM,SAAS,YAAY,SAJZ,aAAa,QAAQ,IAAK,QAAQ,MAAM,CAAC,GAAG;GACzD,UAAU;GACV,OAAO;EACT,CACyC,CAAC;EAC1C,IAAI,QAAQ,aAAa,OAAO,SAAS,GACvC,OAAO,SAAS,EAAE,WAAW,UAAU,cAAc;GACnD,MACE,mCAAmC,UAAU,SAAS,SAAS,YAAY,QAAQ,EACrF;EACF,CAAC;EAEH,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"transform.js","names":["globSync","fs"],"sources":["../../src/lib/transform.ts"],"sourcesContent":["import { execFileSync, spawnSync } from \"node:child_process\";\nimport debug from \"debug\";\nimport path from \"node:path\";\nimport type { TransformOptions } from \"./transform-options\";\nimport { fileURLToPath } from \"node:url\";\nimport * as fs from \"node:fs\";\nimport { sync as globSync } from \"glob\";\n\nconst log = debug(\"codemod:transform\");\nconst error = debug(\"codemod:transform:error\");\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n/**\n * Gets the list of files that need to be processed in the codebase\n * Only includes files that contain \"assistant-ui\" to optimize performance\n */\nexport function getRelevantFiles(cwd: string): string[] {\n const pattern = \"**/*.{js,jsx,ts,tsx}\";\n const files = globSync(pattern, {\n cwd,\n ignore: [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/*.min.js\",\n \"**/*.bundle.js\",\n ],\n });\n\n // Filter files to only include those containing \"assistant-ui\"\n const relevantFiles = files.filter((file) => {\n try {\n const content = fs.readFileSync(path.join(cwd, file), \"utf8\");\n return content.includes(\"assistant-ui\");\n } catch {\n return false;\n }\n });\n\n return relevantFiles.map((file) => path.join(cwd, file));\n}\n\n/**\n * Counts the number of files that need to be processed\n */\nexport function countFilesToProcess(cwd: string): number {\n return getRelevantFiles(cwd).length;\n}\n\nfunction buildCommand(\n codemodPath: string,\n targetFiles: string[],\n options: TransformOptions,\n): string[] {\n const command = [\n \"npx\",\n \"jscodeshift\",\n \"-t\",\n codemodPath,\n ...targetFiles,\n \"--parser\",\n \"tsx\",\n ];\n\n if (options.dry) {\n command.push(\"--dry\");\n }\n\n if (options.print) {\n command.push(\"--print\");\n }\n\n if (options.verbose) {\n command.push(\"--verbose\");\n }\n\n if (options.jscodeshift) {\n command.push(options.jscodeshift);\n }\n\n return command;\n}\n\nexport type TransformErrors = {\n transform: string;\n filename: string;\n summary: string;\n}[];\n\nfunction parseErrors(transform: string, output: string): TransformErrors {\n const errors: TransformErrors = [];\n const errorRegex = /ERR (.+) Transformation error/g;\n const syntaxErrorRegex = /SyntaxError: .+/g;\n\n for (const match of output.matchAll(errorRegex)) {\n const filename = match[1]!;\n const syntaxErrorMatch = syntaxErrorRegex.exec(output);\n if (syntaxErrorMatch) {\n const summary = syntaxErrorMatch[0];\n errors.push({ transform, filename, summary });\n }\n }\n\n return errors;\n}\n\nexport function transform(\n codemod: string,\n source: string,\n transformOptions: TransformOptions,\n options: {\n logStatus: boolean;\n onProgress?: (processedFiles: number) => void;\n relevantFiles?: string[];\n } = { logStatus: true },\n): TransformErrors {\n if (options.logStatus) {\n log(`Applying codemod '${codemod}': ${source}`);\n }\n const codemodPath = path.resolve(__dirname, `../codemods/${codemod}.js`);\n\n // Use pre-computed relevant files if provided, otherwise get them\n const targetFiles = options.relevantFiles || getRelevantFiles(source);\n\n if (targetFiles.length === 0) {\n log(`No relevant files found for codemod '${codemod}'`);\n return [];\n }\n\n log(`Found ${targetFiles.length} relevant files for codemod '${codemod}'`);\n\n const command = buildCommand(codemodPath, targetFiles, transformOptions);\n\n // Use spawn instead of execFileSync to capture output in real-time\n if (options.onProgress) {\n const result = spawnSync(command[0]!, command.slice(1), {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n const stdout = result.stdout || \"\";\n\n // Count the number of processed files from the output\n const processedFiles = (stdout.match(/Processing file/g) || []).length;\n if (options.onProgress) {\n options.onProgress(processedFiles);\n }\n\n const errors = parseErrors(codemod, stdout);\n if (options.logStatus && errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(\n `Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`,\n );\n });\n }\n return errors;\n } else {\n // Use the original synchronous approach if no progress callback\n const stdout = execFileSync(command[0]!, command.slice(1), {\n encoding: \"utf8\",\n stdio: \"pipe\",\n });\n const errors = parseErrors(codemod, stdout);\n if (options.logStatus && errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(\n `Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`,\n );\n });\n }\n return errors;\n }\n}\n"],"mappings":";;;;;;;AAQA,MAAM,MAAM,MAAM,mBAAmB;AACrC,MAAM,QAAQ,MAAM,yBAAyB;AAE7C,MAAM,aAAa,cAAc,YAAY,GAAG;AAChD,MAAM,YAAY,KAAK,QAAQ,UAAU;;;;;AAMzC,SAAgB,iBAAiB,KAAuB;CAuBtD,OArBcA,KAAS,wBAAS;EAC9B;EACA,QAAQ;GACN;GACA;GACA;GACA;GACA;EACF;CACF,CAG0B,CAAC,CAAC,QAAQ,SAAS;EAC3C,IAAI;GAEF,OADgBC,KAAG,aAAa,KAAK,KAAK,KAAK,IAAI,GAAG,MACzC,CAAC,C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,gBAAgB;CAGvE,IAAI,QAAQ,YAAY;EAMtB,MAAM,SALS,UAAU,QAAQ,IAAK,QAAQ,MAAM,CAAC,GAAG;GACtD,UAAU;GACV,OAAO;IAAC;IAAU;IAAQ;GAAM;EAClC,CAEoB,CAAC,CAAC,UAAU;EAGhC,MAAM,kBAAkB,OAAO,MAAM,kBAAkB,KAAK,CAAC,EAAA,CAAG;EAChE,IAAI,QAAQ,YACV,QAAQ,WAAW,cAAc;EAGnC,MAAM,SAAS,YAAY,SAAS,MAAM;EAC1C,IAAI,QAAQ,aAAa,OAAO,SAAS,GACvC,OAAO,SAAS,EAAE,WAAW,UAAU,cAAc;GACnD,MACE,mCAAmC,UAAU,SAAS,SAAS,YAAY,QAAQ,EACrF;EACF,CAAC;EAEH,OAAO;CACT,OAAO;EAML,MAAM,SAAS,YAAY,SAJZ,aAAa,QAAQ,IAAK,QAAQ,MAAM,CAAC,GAAG;GACzD,UAAU;GACV,OAAO;EACT,CACyC,CAAC;EAC1C,IAAI,QAAQ,aAAa,OAAO,SAAS,GACvC,OAAO,SAAS,EAAE,WAAW,UAAU,cAAc;GACnD,MACE,mCAAmC,UAAU,SAAS,SAAS,YAAY,QAAQ,EACrF;EACF,CAAC;EAEH,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade.d.ts","names":[],"sources":["../../src/lib/upgrade.ts"],"mappings":";;;;;;;;iBA2BsB,QAAQ,SAAS,mBAAgB"}
1
+ {"version":3,"file":"upgrade.d.ts","names":[],"sources":["../../src/lib/upgrade.ts"],"mappings":";;;;;;;;iBA4BsB,QAAQ,SAAS,mBAAgB"}
@@ -12,7 +12,8 @@ const bundle = [
12
12
  "v0-11/content-part-to-message-part",
13
13
  "v0-12/assistant-api-to-aui",
14
14
  "v0-12/event-names-to-camelcase",
15
- "v0-12/primitive-if-to-aui-if"
15
+ "v0-12/primitive-if-to-aui-if",
16
+ "v0-15/aui-accessor-calls-to-properties"
16
17
  ];
17
18
  const log = debug("codemod:upgrade");
18
19
  const error = debug("codemod:upgrade:error");
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade.js","names":[],"sources":["../../src/lib/upgrade.ts"],"sourcesContent":["import debug from \"debug\";\nimport { transform, type TransformErrors, getRelevantFiles } from \"./transform\";\nimport type { TransformOptions } from \"./transform-options\";\nimport { SingleBar, Presets } from \"cli-progress\";\nimport installReactUILib from \"./install-ui-lib\";\nimport installEdgeLib from \"./install-edge-lib\";\nimport installAiSdkLib from \"./install-ai-sdk-lib\";\nimport { logger } from \"./utils/logger\";\n\nconst bundle = [\n \"v0-8/ui-package-split\",\n \"v0-9/edge-package-split\",\n \"v0-11/content-part-to-message-part\",\n \"v0-12/assistant-api-to-aui\",\n \"v0-12/event-names-to-camelcase\",\n \"v0-12/primitive-if-to-aui-if\",\n];\n\nconst log = debug(\"codemod:upgrade\");\nconst error = debug(\"codemod:upgrade:error\");\n\n/**\n * Runs the upgrade cycle:\n * - Runs each codemod in the bundle.\n * - Displays progress using cli-progress.\n * - After codemods run, checks if any file now imports from the new packages and prompts for install.\n */\nexport async function upgrade(options: TransformOptions) {\n const cwd = process.cwd();\n log(\"Starting upgrade...\");\n\n // Find relevant files once to avoid duplicate work\n logger.info(\"Analyzing codebase...\");\n const relevantFiles = getRelevantFiles(cwd);\n const fileCount = relevantFiles.length;\n logger.info(`Found ${fileCount} files to process.`);\n\n // Calculate total work units (files × codemods)\n const totalWork = fileCount * bundle.length;\n let completedWork = 0;\n\n const bar = new SingleBar(\n {\n format: \"Progress |{bar}| {percentage}% | ETA: {eta}s || {status}\",\n hideCursor: true,\n },\n Presets.shades_classic,\n );\n\n bar.start(totalWork, 0, { status: \"Starting...\" });\n const allErrors: TransformErrors = [];\n\n for (const codemod of bundle) {\n bar.update(completedWork, { status: `Running ${codemod}...` });\n\n // Use a custom progress callback to update the progress bar\n const errors = transform(codemod, cwd, options, {\n logStatus: false,\n onProgress: (processedFiles: number) => {\n completedWork = bundle.indexOf(codemod) * fileCount + processedFiles;\n bar.update(Math.min(completedWork, totalWork), {\n status: `Running ${codemod} (${processedFiles}/${fileCount} files)`,\n });\n },\n relevantFiles, // Pass the pre-computed relevant files\n });\n\n allErrors.push(...errors);\n completedWork = (bundle.indexOf(codemod) + 1) * fileCount;\n bar.update(completedWork, { status: `Completed ${codemod}` });\n }\n\n bar.update(totalWork, { status: \"Checking dependencies...\" });\n bar.stop();\n\n if (allErrors.length > 0) {\n log(\"Some codemods did not apply successfully to all files. Details:\");\n allErrors.forEach(({ transform, filename, summary }) => {\n error(`codemod=${transform}, path=${filename}, summary=${summary}`);\n });\n }\n\n // After codemods run, check if files import from the new packages and prompt for install.\n logger.info(\"Checking for package dependencies...\");\n await installReactUILib();\n await installEdgeLib();\n await installAiSdkLib();\n\n log(\"Upgrade complete.\");\n logger.success(\"Upgrade complete!\");\n}\n"],"mappings":";;;;;;;;AASA,MAAM,SAAS;CACb;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,MAAM,MAAM,iBAAiB;AACnC,MAAM,QAAQ,MAAM,uBAAuB;;;;;;;AAQ3C,eAAsB,QAAQ,SAA2B;CACvD,MAAM,MAAM,QAAQ,IAAI;CACxB,IAAI,qBAAqB;CAGzB,OAAO,KAAK,uBAAuB;CACnC,MAAM,gBAAgB,iBAAiB,GAAG;CAC1C,MAAM,YAAY,cAAc;CAChC,OAAO,KAAK,SAAS,UAAU,mBAAmB;CAGlD,MAAM,YAAY,YAAY,OAAO;CACrC,IAAI,gBAAgB;CAEpB,MAAM,MAAM,IAAI,UACd;EACE,QAAQ;EACR,YAAY;CACd,GACA,QAAQ,cACV;CAEA,IAAI,MAAM,WAAW,GAAG,EAAE,QAAQ,cAAc,CAAC;CACjD,MAAM,YAA6B,CAAC;CAEpC,KAAK,MAAM,WAAW,QAAQ;EAC5B,IAAI,OAAO,eAAe,EAAE,QAAQ,WAAW,QAAQ,KAAK,CAAC;EAG7D,MAAM,SAAS,UAAU,SAAS,KAAK,SAAS;GAC9C,WAAW;GACX,aAAa,mBAA2B;IACtC,gBAAgB,OAAO,QAAQ,OAAO,IAAI,YAAY;IACtD,IAAI,OAAO,KAAK,IAAI,eAAe,SAAS,GAAG,EAC7C,QAAQ,WAAW,QAAQ,IAAI,eAAe,GAAG,UAAU,SAC7D,CAAC;GACH;GACA;EACF,CAAC;EAED,UAAU,KAAK,GAAG,MAAM;EACxB,iBAAiB,OAAO,QAAQ,OAAO,IAAI,KAAK;EAChD,IAAI,OAAO,eAAe,EAAE,QAAQ,aAAa,UAAU,CAAC;CAC9D;CAEA,IAAI,OAAO,WAAW,EAAE,QAAQ,2BAA2B,CAAC;CAC5D,IAAI,KAAK;CAET,IAAI,UAAU,SAAS,GAAG;EACxB,IAAI,iEAAiE;EACrE,UAAU,SAAS,EAAE,WAAW,UAAU,cAAc;GACtD,MAAM,WAAW,UAAU,SAAS,SAAS,YAAY,SAAS;EACpE,CAAC;CACH;CAGA,OAAO,KAAK,sCAAsC;CAClD,MAAM,kBAAkB;CACxB,MAAM,eAAe;CACrB,MAAM,gBAAgB;CAEtB,IAAI,mBAAmB;CACvB,OAAO,QAAQ,mBAAmB;AACpC"}
1
+ {"version":3,"file":"upgrade.js","names":[],"sources":["../../src/lib/upgrade.ts"],"sourcesContent":["import debug from \"debug\";\nimport { transform, type TransformErrors, getRelevantFiles } from \"./transform\";\nimport type { TransformOptions } from \"./transform-options\";\nimport { SingleBar, Presets } from \"cli-progress\";\nimport installReactUILib from \"./install-ui-lib\";\nimport installEdgeLib from \"./install-edge-lib\";\nimport installAiSdkLib from \"./install-ai-sdk-lib\";\nimport { logger } from \"./utils/logger\";\n\nconst bundle = [\n \"v0-8/ui-package-split\",\n \"v0-9/edge-package-split\",\n \"v0-11/content-part-to-message-part\",\n \"v0-12/assistant-api-to-aui\",\n \"v0-12/event-names-to-camelcase\",\n \"v0-12/primitive-if-to-aui-if\",\n \"v0-15/aui-accessor-calls-to-properties\",\n];\n\nconst log = debug(\"codemod:upgrade\");\nconst error = debug(\"codemod:upgrade:error\");\n\n/**\n * Runs the upgrade cycle:\n * - Runs each codemod in the bundle.\n * - Displays progress using cli-progress.\n * - After codemods run, checks if any file now imports from the new packages and prompts for install.\n */\nexport async function upgrade(options: TransformOptions) {\n const cwd = process.cwd();\n log(\"Starting upgrade...\");\n\n // Find relevant files once to avoid duplicate work\n logger.info(\"Analyzing codebase...\");\n const relevantFiles = getRelevantFiles(cwd);\n const fileCount = relevantFiles.length;\n logger.info(`Found ${fileCount} files to process.`);\n\n // Calculate total work units (files × codemods)\n const totalWork = fileCount * bundle.length;\n let completedWork = 0;\n\n const bar = new SingleBar(\n {\n format: \"Progress |{bar}| {percentage}% | ETA: {eta}s || {status}\",\n hideCursor: true,\n },\n Presets.shades_classic,\n );\n\n bar.start(totalWork, 0, { status: \"Starting...\" });\n const allErrors: TransformErrors = [];\n\n for (const codemod of bundle) {\n bar.update(completedWork, { status: `Running ${codemod}...` });\n\n // Use a custom progress callback to update the progress bar\n const errors = transform(codemod, cwd, options, {\n logStatus: false,\n onProgress: (processedFiles: number) => {\n completedWork = bundle.indexOf(codemod) * fileCount + processedFiles;\n bar.update(Math.min(completedWork, totalWork), {\n status: `Running ${codemod} (${processedFiles}/${fileCount} files)`,\n });\n },\n relevantFiles, // Pass the pre-computed relevant files\n });\n\n allErrors.push(...errors);\n completedWork = (bundle.indexOf(codemod) + 1) * fileCount;\n bar.update(completedWork, { status: `Completed ${codemod}` });\n }\n\n bar.update(totalWork, { status: \"Checking dependencies...\" });\n bar.stop();\n\n if (allErrors.length > 0) {\n log(\"Some codemods did not apply successfully to all files. Details:\");\n allErrors.forEach(({ transform, filename, summary }) => {\n error(`codemod=${transform}, path=${filename}, summary=${summary}`);\n });\n }\n\n // After codemods run, check if files import from the new packages and prompt for install.\n logger.info(\"Checking for package dependencies...\");\n await installReactUILib();\n await installEdgeLib();\n await installAiSdkLib();\n\n log(\"Upgrade complete.\");\n logger.success(\"Upgrade complete!\");\n}\n"],"mappings":";;;;;;;;AASA,MAAM,SAAS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,CAAC;CACH;CAGA,OAAO,KAAK,sCAAsC;CAClD,MAAM,kBAAkB;CACxB,MAAM,eAAe;CACrB,MAAM,gBAAgB;CAEtB,IAAI,mBAAmB;CACvB,OAAO,QAAQ,mBAAmB;AACpC"}
@@ -4,13 +4,15 @@ import { sync } from "glob";
4
4
  //#region src/lib/utils/file-scanner.ts
5
5
  function scanForImport(importPattern, options = {}) {
6
6
  const cwd = options.cwd || process.cwd();
7
- const files = sync(options.pattern || "**/*.{js,jsx,ts,tsx}", {
7
+ const pattern = options.pattern || "**/*.{js,jsx,ts,tsx}";
8
+ const ignore = options.ignore || [
9
+ "**/node_modules/**",
10
+ "**/dist/**",
11
+ "**/build/**"
12
+ ];
13
+ const files = sync(pattern, {
8
14
  cwd,
9
- ignore: options.ignore || [
10
- "**/node_modules/**",
11
- "**/dist/**",
12
- "**/build/**"
13
- ]
15
+ ignore
14
16
  });
15
17
  const patterns = Array.isArray(importPattern) ? importPattern : [importPattern];
16
18
  for (const file of files) {
@@ -24,13 +26,15 @@ function scanForImport(importPattern, options = {}) {
24
26
  }
25
27
  function getFilesContaining(searchString, options = {}) {
26
28
  const cwd = options.cwd || process.cwd();
27
- const files = sync(options.pattern || "**/*.{js,jsx,ts,tsx}", {
29
+ const pattern = options.pattern || "**/*.{js,jsx,ts,tsx}";
30
+ const ignore = options.ignore || [
31
+ "**/node_modules/**",
32
+ "**/dist/**",
33
+ "**/build/**"
34
+ ];
35
+ const files = sync(pattern, {
28
36
  cwd,
29
- ignore: options.ignore || [
30
- "**/node_modules/**",
31
- "**/dist/**",
32
- "**/build/**"
33
- ]
37
+ ignore
34
38
  });
35
39
  const result = [];
36
40
  for (const file of files) {
@@ -1 +1 @@
1
- {"version":3,"file":"file-scanner.js","names":["globSync","path","fs"],"sources":["../../../src/lib/utils/file-scanner.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { sync as globSync } from \"glob\";\n\nexport interface ScanOptions {\n cwd?: string;\n pattern?: string;\n ignore?: string[];\n}\n\nexport function scanForImport(\n importPattern: string | string[],\n options: ScanOptions = {},\n): boolean {\n const cwd = options.cwd || process.cwd();\n const pattern = options.pattern || \"**/*.{js,jsx,ts,tsx}\";\n const ignore = options.ignore || [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n ];\n\n const files = globSync(pattern, { cwd, ignore });\n const patterns = Array.isArray(importPattern)\n ? importPattern\n : [importPattern];\n\n for (const file of files) {\n const fullPath = path.join(cwd, file);\n try {\n const content = fs.readFileSync(fullPath, \"utf8\");\n if (patterns.some((p) => content.includes(p))) {\n return true;\n }\n } catch {\n // Ignore files that cannot be read\n }\n }\n\n return false;\n}\n\nexport function getFilesContaining(\n searchString: string,\n options: ScanOptions = {},\n): string[] {\n const cwd = options.cwd || process.cwd();\n const pattern = options.pattern || \"**/*.{js,jsx,ts,tsx}\";\n const ignore = options.ignore || [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n ];\n\n const files = globSync(pattern, { cwd, ignore });\n const result: string[] = [];\n\n for (const file of files) {\n const fullPath = path.join(cwd, file);\n try {\n const content = fs.readFileSync(fullPath, \"utf8\");\n if (content.includes(searchString)) {\n result.push(fullPath);\n }\n } catch {\n // Ignore files that cannot be read\n }\n }\n\n return result;\n}\n"],"mappings":";;;;AAUA,SAAgB,cACd,eACA,UAAuB,CAAC,GACf;CACT,MAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;CAQvC,MAAM,QAAQA,KAPE,QAAQ,WAAW,wBAOH;EAAE;EAAK,QANxB,QAAQ,UAAU;GAC/B;GACA;GACA;EACF;CAE8C,CAAC;CAC/C,MAAM,WAAW,MAAM,QAAQ,aAAa,IACxC,gBACA,CAAC,aAAa;CAElB,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAWC,OAAK,KAAK,KAAK,IAAI;EACpC,IAAI;GACF,MAAM,UAAUC,KAAG,aAAa,UAAU,MAAM;GAChD,IAAI,SAAS,MAAM,MAAM,QAAQ,SAAS,CAAC,CAAC,GAC1C,OAAO;EAEX,QAAQ,CAER;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,mBACd,cACA,UAAuB,CAAC,GACd;CACV,MAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;CAQvC,MAAM,QAAQF,KAPE,QAAQ,WAAW,wBAOH;EAAE;EAAK,QANxB,QAAQ,UAAU;GAC/B;GACA;GACA;EACF;CAE8C,CAAC;CAC/C,MAAM,SAAmB,CAAC;CAE1B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAWC,OAAK,KAAK,KAAK,IAAI;EACpC,IAAI;GAEF,IADgBC,KAAG,aAAa,UAAU,MAChC,CAAC,CAAC,SAAS,YAAY,GAC/B,OAAO,KAAK,QAAQ;EAExB,QAAQ,CAER;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"file-scanner.js","names":["globSync","path","fs"],"sources":["../../../src/lib/utils/file-scanner.ts"],"sourcesContent":["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { sync as globSync } from \"glob\";\n\nexport interface ScanOptions {\n cwd?: string;\n pattern?: string;\n ignore?: string[];\n}\n\nexport function scanForImport(\n importPattern: string | string[],\n options: ScanOptions = {},\n): boolean {\n const cwd = options.cwd || process.cwd();\n const pattern = options.pattern || \"**/*.{js,jsx,ts,tsx}\";\n const ignore = options.ignore || [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n ];\n\n const files = globSync(pattern, { cwd, ignore });\n const patterns = Array.isArray(importPattern)\n ? importPattern\n : [importPattern];\n\n for (const file of files) {\n const fullPath = path.join(cwd, file);\n try {\n const content = fs.readFileSync(fullPath, \"utf8\");\n if (patterns.some((p) => content.includes(p))) {\n return true;\n }\n } catch {\n // Ignore files that cannot be read\n }\n }\n\n return false;\n}\n\nexport function getFilesContaining(\n searchString: string,\n options: ScanOptions = {},\n): string[] {\n const cwd = options.cwd || process.cwd();\n const pattern = options.pattern || \"**/*.{js,jsx,ts,tsx}\";\n const ignore = options.ignore || [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n ];\n\n const files = globSync(pattern, { cwd, ignore });\n const result: string[] = [];\n\n for (const file of files) {\n const fullPath = path.join(cwd, file);\n try {\n const content = fs.readFileSync(fullPath, \"utf8\");\n if (content.includes(searchString)) {\n result.push(fullPath);\n }\n } catch {\n // Ignore files that cannot be read\n }\n }\n\n return result;\n}\n"],"mappings":";;;;AAUA,SAAgB,cACd,eACA,UAAuB,CAAC,GACf;CACT,MAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;CACvC,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,SAAS,QAAQ,UAAU;EAC/B;EACA;EACA;CACF;CAEA,MAAM,QAAQA,KAAS,SAAS;EAAE;EAAK;CAAO,CAAC;CAC/C,MAAM,WAAW,MAAM,QAAQ,aAAa,IACxC,gBACA,CAAC,aAAa;CAElB,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAWC,OAAK,KAAK,KAAK,IAAI;EACpC,IAAI;GACF,MAAM,UAAUC,KAAG,aAAa,UAAU,MAAM;GAChD,IAAI,SAAS,MAAM,MAAM,QAAQ,SAAS,CAAC,CAAC,GAC1C,OAAO;EAEX,QAAQ,CAER;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,mBACd,cACA,UAAuB,CAAC,GACd;CACV,MAAM,MAAM,QAAQ,OAAO,QAAQ,IAAI;CACvC,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,SAAS,QAAQ,UAAU;EAC/B;EACA;EACA;CACF;CAEA,MAAM,QAAQF,KAAS,SAAS;EAAE;EAAK;CAAO,CAAC;CAC/C,MAAM,SAAmB,CAAC;CAE1B,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAWC,OAAK,KAAK,KAAK,IAAI;EACpC,IAAI;GAEF,IADgBC,KAAG,aAAa,UAAU,MAChC,CAAC,CAAC,SAAS,YAAY,GAC/B,OAAO,KAAK,QAAQ;EAExB,QAAQ,CAER;CACF;CAEA,OAAO;AACT"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ //#region src/run.d.ts
2
+ declare function runCli(): Promise<void>;
3
+ //#endregion
4
+ export { runCli };
5
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","names":[],"sources":["../src/run.ts"],"mappings":";iBAEsB,UAAU"}
package/dist/run.js ADDED
@@ -0,0 +1,9 @@
1
+ import { buildProgram } from "./program.js";
2
+ //#region src/run.ts
3
+ async function runCli() {
4
+ await buildProgram().parseAsync();
5
+ }
6
+ //#endregion
7
+ export { runCli };
8
+
9
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","names":[],"sources":["../src/run.ts"],"sourcesContent":["import { buildProgram } from \"./program\";\n\nexport async function runCli(): Promise<void> {\n await buildProgram().parseAsync();\n}\n"],"mappings":";;AAEA,eAAsB,SAAwB;CAC5C,MAAM,aAAa,CAAC,CAAC,WAAW;AAClC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistant-ui",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
4
4
  "description": "CLI for assistant-ui",
5
5
  "keywords": [
6
6
  "cli",
@@ -27,7 +27,7 @@
27
27
  "sideEffects": false,
28
28
  "dependencies": {
29
29
  "@clack/prompts": "^1.7.0",
30
- "chalk": "^5.6.2",
30
+ "chalk": "^6.0.0",
31
31
  "cli-progress": "^3.12.0",
32
32
  "commander": "^15.0.0",
33
33
  "cross-spawn": "^7.0.6",
@@ -38,18 +38,18 @@
38
38
  "jscodeshift": "^17.4.0",
39
39
  "jsonc-parser": "^3.3.1",
40
40
  "semver": "^7.8.5",
41
- "@assistant-ui/agent-launcher": "0.1.9"
41
+ "@assistant-ui/agent-launcher": "0.1.10"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/cli-progress": "^3.11.6",
45
45
  "@types/cross-spawn": "^6.0.6",
46
46
  "@types/debug": "^4.1.13",
47
47
  "@types/jscodeshift": "^17.3.0",
48
- "@types/node": "^26.1.1",
49
- "@types/semver": "^7.7.1",
48
+ "@types/node": "^26.1.2",
49
+ "@types/semver": "^7.8.0",
50
50
  "@vitest/coverage-v8": "^4.1.10",
51
51
  "vitest": "^4.1.10",
52
- "@assistant-ui/x-buildutils": "0.0.19"
52
+ "@assistant-ui/x-buildutils": "0.0.22"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public",
@@ -0,0 +1,109 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import jscodeshift, { type API } from "jscodeshift";
3
+ import transform from "../aui-accessor-calls-to-properties";
4
+
5
+ const j = jscodeshift.withParser("tsx");
6
+
7
+ function applyTransform(source: string): string | null {
8
+ const fileInfo = {
9
+ path: "test.tsx",
10
+ source,
11
+ };
12
+
13
+ const api: API = {
14
+ jscodeshift: j,
15
+ j,
16
+ stats: () => {},
17
+ report: () => {},
18
+ };
19
+
20
+ return transform(fileInfo, api, {});
21
+ }
22
+
23
+ describe("aui-accessor-calls-to-properties", () => {
24
+ it("rewrites nullary accessor calls on a useAui variable", () => {
25
+ const input = `
26
+ const client = useAui();
27
+ client.thread().cancelRun();
28
+ const state = client.composer().getState();
29
+ `;
30
+ const expected = `
31
+ const client = useAui();
32
+ client.thread.cancelRun();
33
+ const state = client.composer.getState();
34
+ `;
35
+ expect(applyTransform(input)?.trim()).toBe(expected.trim());
36
+ });
37
+
38
+ it("rewrites only the accessor call in chained expressions", () => {
39
+ const input = `
40
+ const aui = useAui();
41
+ const part = aui.message().part({ index: 0 });
42
+ aui.message().composer().send();
43
+ `;
44
+ const expected = `
45
+ const aui = useAui();
46
+ const part = aui.message.part({ index: 0 });
47
+ aui.message.composer().send();
48
+ `;
49
+ expect(applyTransform(input)?.trim()).toBe(expected.trim());
50
+ });
51
+
52
+ it("rewrites identifiers named aui without a declaration", () => {
53
+ const input = `
54
+ const Derived = {
55
+ get: (aui) => aui.thread().message({ index: 0 }),
56
+ };
57
+ `;
58
+ const expected = `
59
+ const Derived = {
60
+ get: (aui) => aui.thread.message({ index: 0 }),
61
+ };
62
+ `;
63
+ expect(applyTransform(input)?.trim()).toBe(expected.trim());
64
+ });
65
+
66
+ it("rewrites parameters typed AssistantClient", () => {
67
+ const input = `
68
+ const getItem = (client: AssistantClient) => client.threadListItem().getState();
69
+ `;
70
+ const expected = `
71
+ const getItem = (client: AssistantClient) => client.threadListItem.getState();
72
+ `;
73
+ expect(applyTransform(input)?.trim()).toBe(expected.trim());
74
+ });
75
+
76
+ it("leaves calls with arguments untouched", () => {
77
+ const input = `
78
+ const aui = useAui();
79
+ const t = aui.threads().thread({ id: "t1" });
80
+ `;
81
+ const expected = `
82
+ const aui = useAui();
83
+ const t = aui.threads.thread({ id: "t1" });
84
+ `;
85
+ expect(applyTransform(input)?.trim()).toBe(expected.trim());
86
+ });
87
+
88
+ it("does not rewrite unknown receivers", () => {
89
+ const input = `
90
+ toolkit.tools();
91
+ message.composer().send();
92
+ ref.current.thread().getState();
93
+ `;
94
+ expect(applyTransform(input)).toBeNull();
95
+ });
96
+
97
+ it("does not rewrite non-scope member calls on aui", () => {
98
+ const input = `
99
+ const aui = useAui();
100
+ aui.subscribe(() => {});
101
+ aui.on("thread.updated", () => {});
102
+ `;
103
+ expect(applyTransform(input)).toBeNull();
104
+ });
105
+
106
+ it("returns null when nothing changes", () => {
107
+ expect(applyTransform(`const x = 1;`)).toBeNull();
108
+ });
109
+ });
@@ -0,0 +1,83 @@
1
+ import { createTransformer } from "../utils/createTransformer";
2
+
3
+ // Nullary scope accessors that became properties in v0.15. Parameterized
4
+ // lookups (e.g. `aui.thread.message({ id })`) stay as real calls.
5
+ const NULLARY_SCOPES = new Set([
6
+ "threads",
7
+ "threadListItem",
8
+ "thread",
9
+ "message",
10
+ "part",
11
+ "composer",
12
+ "attachment",
13
+ "modelContext",
14
+ "suggestions",
15
+ "suggestion",
16
+ "chainOfThought",
17
+ "queueItem",
18
+ "tools",
19
+ "dataRenderers",
20
+ "interactables",
21
+ "unstable_interactables",
22
+ "mcp",
23
+ "mcpServer",
24
+ "span",
25
+ ]);
26
+
27
+ const AUI_HOOKS = new Set(["useAui", "useAssistantApi"]);
28
+
29
+ const auiAccessorCallsToProperties = createTransformer(
30
+ ({ j, root, markAsChanged }) => {
31
+ const auiNames = new Set(["aui"]);
32
+
33
+ root.find(j.VariableDeclarator).forEach((path: any) => {
34
+ const { id, init } = path.value;
35
+ if (
36
+ j.Identifier.check(id) &&
37
+ init &&
38
+ j.CallExpression.check(init) &&
39
+ j.Identifier.check(init.callee) &&
40
+ AUI_HOOKS.has(init.callee.name)
41
+ ) {
42
+ auiNames.add(id.name);
43
+ }
44
+ });
45
+
46
+ const collectParam = (param: any) => {
47
+ const annotation = param?.typeAnnotation?.typeAnnotation;
48
+ if (
49
+ j.Identifier.check(param) &&
50
+ annotation &&
51
+ j.TSTypeReference.check(annotation) &&
52
+ j.Identifier.check(annotation.typeName) &&
53
+ annotation.typeName.name === "AssistantClient"
54
+ ) {
55
+ auiNames.add(param.name);
56
+ }
57
+ };
58
+ for (const fnType of [
59
+ j.FunctionDeclaration,
60
+ j.FunctionExpression,
61
+ j.ArrowFunctionExpression,
62
+ ] as const) {
63
+ root.find(fnType as typeof j.FunctionDeclaration).forEach((path: any) => {
64
+ path.value.params.forEach(collectParam);
65
+ });
66
+ }
67
+
68
+ root.find(j.CallExpression).forEach((path: any) => {
69
+ const node = path.value;
70
+ if (node.arguments.length !== 0) return;
71
+ const callee = node.callee;
72
+ if (!j.MemberExpression.check(callee) || callee.computed) return;
73
+ if (!j.Identifier.check(callee.property)) return;
74
+ if (!NULLARY_SCOPES.has(callee.property.name)) return;
75
+ if (!j.Identifier.check(callee.object)) return;
76
+ if (!auiNames.has(callee.object.name)) return;
77
+ j(path).replaceWith(callee);
78
+ markAsChanged();
79
+ });
80
+ },
81
+ );
82
+
83
+ export default auiAccessorCallsToProperties;
@@ -48,9 +48,9 @@ export const upgradeCommand = addTransformOptions(
48
48
  new Command()
49
49
  .command("upgrade")
50
50
  .description("Upgrade ai package dependencies and apply codemods"),
51
- ).action((options: TransformOptions) => {
51
+ ).action(async (options: TransformOptions) => {
52
52
  try {
53
- upgrade(options);
53
+ await upgrade(options);
54
54
  } catch (err) {
55
55
  const errorMessage = err instanceof Error ? err.message : String(err);
56
56
  const errorStack = err instanceof Error ? err.stack : undefined;
package/src/index.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { buildProgram } from "./program";
3
+ import { runCli } from "./run";
4
4
 
5
5
  process.on("SIGINT", () => process.exit(0));
6
6
  process.on("SIGTERM", () => process.exit(0));
7
7
 
8
- function main() {
9
- buildProgram().parse();
10
- }
11
-
12
- main();
8
+ void runCli().catch((error: unknown) => {
9
+ console.error(error);
10
+ process.exitCode = 1;
11
+ });
@@ -14,6 +14,7 @@ const bundle = [
14
14
  "v0-12/assistant-api-to-aui",
15
15
  "v0-12/event-names-to-camelcase",
16
16
  "v0-12/primitive-if-to-aui-if",
17
+ "v0-15/aui-accessor-calls-to-properties",
17
18
  ];
18
19
 
19
20
  const log = debug("codemod:upgrade");
@@ -0,0 +1,27 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ const mocks = vi.hoisted(() => ({
4
+ parseAsync: vi.fn(),
5
+ }));
6
+
7
+ vi.mock("./program", () => ({
8
+ buildProgram: () => ({
9
+ parseAsync: mocks.parseAsync,
10
+ }),
11
+ }));
12
+
13
+ import { runCli } from "./run";
14
+
15
+ describe("runCli", () => {
16
+ beforeEach(() => {
17
+ vi.clearAllMocks();
18
+ });
19
+
20
+ it("awaits and propagates asynchronous command failures", async () => {
21
+ const error = new Error("command failed");
22
+ mocks.parseAsync.mockRejectedValue(error);
23
+
24
+ await expect(runCli()).rejects.toBe(error);
25
+ expect(mocks.parseAsync).toHaveBeenCalledOnce();
26
+ });
27
+ });
package/src/run.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { buildProgram } from "./program";
2
+
3
+ export async function runCli(): Promise<void> {
4
+ await buildProgram().parseAsync();
5
+ }