@ohos-ports/assistant-ui 0.0.0-stage → 0.0.136-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -2
- package/bin/assistant-ui.js +2 -0
- package/dist/codemods/utils/createTransformer.d.ts +15 -0
- package/dist/codemods/utils/createTransformer.d.ts.map +1 -0
- package/dist/codemods/utils/createTransformer.js +19 -0
- package/dist/codemods/utils/createTransformer.js.map +1 -0
- package/dist/codemods/utils/resolveBinding.d.ts +3 -0
- package/dist/codemods/utils/resolveBinding.d.ts.map +1 -0
- package/dist/codemods/utils/resolveBinding.js +77 -0
- package/dist/codemods/utils/resolveBinding.js.map +1 -0
- package/dist/codemods/v0-11/content-part-to-message-part.d.ts +3 -0
- package/dist/codemods/v0-11/content-part-to-message-part.d.ts.map +1 -0
- package/dist/codemods/v0-11/content-part-to-message-part.js +189 -0
- package/dist/codemods/v0-11/content-part-to-message-part.js.map +1 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.d.ts +3 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.d.ts.map +1 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.js +117 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.js.map +1 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.d.ts +3 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.d.ts.map +1 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.js +38 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.js.map +1 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts +3 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts.map +1 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js +226 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js.map +1 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.d.ts +3 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.d.ts.map +1 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.js +85 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.js.map +1 -0
- package/dist/codemods/v0-8/ui-package-split.d.ts +3 -0
- package/dist/codemods/v0-8/ui-package-split.d.ts.map +1 -0
- package/dist/codemods/v0-8/ui-package-split.js +102 -0
- package/dist/codemods/v0-8/ui-package-split.js.map +1 -0
- package/dist/codemods/v0-9/edge-package-split.d.ts +3 -0
- package/dist/codemods/v0-9/edge-package-split.d.ts.map +1 -0
- package/dist/codemods/v0-9/edge-package-split.js +47 -0
- package/dist/codemods/v0-9/edge-package-split.js.map +1 -0
- package/dist/commands/add.d.ts +17 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +63 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/agent.d.ts +3 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +27 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/cloud.d.ts +25 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +239 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/create.d.ts +58 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +626 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/doctor.d.ts +22 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +255 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/info.d.ts +6 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +288 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +100 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +279 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/setup.d.ts +24 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +136 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/update.d.ts +3 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +58 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/upgrade.d.ts +10 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +38 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/agent-gate.d.ts +66 -0
- package/dist/lib/agent-gate.d.ts.map +1 -0
- package/dist/lib/agent-gate.js +180 -0
- package/dist/lib/agent-gate.js.map +1 -0
- package/dist/lib/agent-setup-hint.d.ts +20 -0
- package/dist/lib/agent-setup-hint.d.ts.map +1 -0
- package/dist/lib/agent-setup-hint.js +33 -0
- package/dist/lib/agent-setup-hint.js.map +1 -0
- package/dist/lib/agent-skill.d.ts +14 -0
- package/dist/lib/agent-skill.d.ts.map +1 -0
- package/dist/lib/agent-skill.js +83 -0
- package/dist/lib/agent-skill.js.map +1 -0
- package/dist/lib/cloud-abort.d.ts +2 -0
- package/dist/lib/cloud-abort.d.ts.map +1 -0
- package/dist/lib/cloud-abort.js +12 -0
- package/dist/lib/cloud-abort.js.map +1 -0
- package/dist/lib/cloud-auth.d.ts +30 -0
- package/dist/lib/cloud-auth.d.ts.map +1 -0
- package/dist/lib/cloud-auth.js +179 -0
- package/dist/lib/cloud-auth.js.map +1 -0
- package/dist/lib/cloud-config.d.ts +31 -0
- package/dist/lib/cloud-config.d.ts.map +1 -0
- package/dist/lib/cloud-config.js +128 -0
- package/dist/lib/cloud-config.js.map +1 -0
- package/dist/lib/cloud-organizations.d.ts +17 -0
- package/dist/lib/cloud-organizations.d.ts.map +1 -0
- package/dist/lib/cloud-organizations.js +36 -0
- package/dist/lib/cloud-organizations.js.map +1 -0
- package/dist/lib/cloud-provision.d.ts +20 -0
- package/dist/lib/cloud-provision.d.ts.map +1 -0
- package/dist/lib/cloud-provision.js +59 -0
- package/dist/lib/cloud-provision.js.map +1 -0
- package/dist/lib/cloud-remote.d.ts +37 -0
- package/dist/lib/cloud-remote.d.ts.map +1 -0
- package/dist/lib/cloud-remote.js +118 -0
- package/dist/lib/cloud-remote.js.map +1 -0
- package/dist/lib/cloud-setup-login.d.ts +9 -0
- package/dist/lib/cloud-setup-login.d.ts.map +1 -0
- package/dist/lib/cloud-setup-login.js +136 -0
- package/dist/lib/cloud-setup-login.js.map +1 -0
- package/dist/lib/cloud-url.d.ts +3 -0
- package/dist/lib/cloud-url.d.ts.map +1 -0
- package/dist/lib/cloud-url.js +10 -0
- package/dist/lib/cloud-url.js.map +1 -0
- package/dist/lib/create-project.d.ts +51 -0
- package/dist/lib/create-project.d.ts.map +1 -0
- package/dist/lib/create-project.js +458 -0
- package/dist/lib/create-project.js.map +1 -0
- package/dist/lib/handle-cli-error.d.ts +2 -0
- package/dist/lib/handle-cli-error.d.ts.map +1 -0
- package/dist/lib/handle-cli-error.js +16 -0
- package/dist/lib/handle-cli-error.js.map +1 -0
- package/dist/lib/init-finish.d.ts +46 -0
- package/dist/lib/init-finish.d.ts.map +1 -0
- package/dist/lib/init-finish.js +187 -0
- package/dist/lib/init-finish.js.map +1 -0
- package/dist/lib/install-ai-sdk-lib.d.ts +2 -0
- package/dist/lib/install-ai-sdk-lib.d.ts.map +1 -0
- package/dist/lib/install-ai-sdk-lib.js +21 -0
- package/dist/lib/install-ai-sdk-lib.js.map +1 -0
- package/dist/lib/install-edge-lib.d.ts +2 -0
- package/dist/lib/install-edge-lib.d.ts.map +1 -0
- package/dist/lib/install-edge-lib.js +14 -0
- package/dist/lib/install-edge-lib.js.map +1 -0
- package/dist/lib/run-spawn.d.ts +21 -0
- package/dist/lib/run-spawn.d.ts.map +1 -0
- package/dist/lib/run-spawn.js +118 -0
- package/dist/lib/run-spawn.js.map +1 -0
- package/dist/lib/safe-project-file.d.ts +2 -0
- package/dist/lib/safe-project-file.d.ts.map +1 -0
- package/dist/lib/safe-project-file.js +25 -0
- package/dist/lib/safe-project-file.js.map +1 -0
- package/dist/lib/setup-session.d.ts +44 -0
- package/dist/lib/setup-session.d.ts.map +1 -0
- package/dist/lib/setup-session.js +122 -0
- package/dist/lib/setup-session.js.map +1 -0
- package/dist/lib/transform-options.d.ts +7 -0
- package/dist/lib/transform-options.d.ts.map +1 -0
- package/dist/lib/transform-options.js +0 -0
- package/dist/lib/transform.d.ts +17 -0
- package/dist/lib/transform.d.ts.map +1 -0
- package/dist/lib/transform.js +75 -0
- package/dist/lib/transform.js.map +1 -0
- package/dist/lib/upgrade.d.ts +9 -0
- package/dist/lib/upgrade.d.ts.map +1 -0
- package/dist/lib/upgrade.js +68 -0
- package/dist/lib/upgrade.js.map +1 -0
- package/dist/lib/utils/config.d.ts +20 -0
- package/dist/lib/utils/config.d.ts.map +1 -0
- package/dist/lib/utils/config.js +28 -0
- package/dist/lib/utils/config.js.map +1 -0
- package/dist/lib/utils/download.d.ts +5 -0
- package/dist/lib/utils/download.d.ts.map +1 -0
- package/dist/lib/utils/download.js +40 -0
- package/dist/lib/utils/download.js.map +1 -0
- package/dist/lib/utils/file-scanner.d.ts +15 -0
- package/dist/lib/utils/file-scanner.d.ts.map +1 -0
- package/dist/lib/utils/file-scanner.js +37 -0
- package/dist/lib/utils/file-scanner.js.map +1 -0
- package/dist/lib/utils/logger.d.ts +9 -0
- package/dist/lib/utils/logger.d.ts.map +1 -0
- package/dist/lib/utils/logger.js +25 -0
- package/dist/lib/utils/logger.js.map +1 -0
- package/dist/lib/utils/package-installer.d.ts +9 -0
- package/dist/lib/utils/package-installer.d.ts.map +1 -0
- package/dist/lib/utils/package-installer.js +21 -0
- package/dist/lib/utils/package-installer.js.map +1 -0
- package/dist/lib/utils/package-json.d.ts +2 -0
- package/dist/lib/utils/package-json.d.ts.map +1 -0
- package/dist/lib/utils/package-json.js +10 -0
- package/dist/lib/utils/package-json.js.map +1 -0
- package/dist/lib/utils/package-manager.d.ts +24 -0
- package/dist/lib/utils/package-manager.d.ts.map +1 -0
- package/dist/lib/utils/package-manager.js +117 -0
- package/dist/lib/utils/package-manager.js.map +1 -0
- package/dist/lib/utils/registry.d.ts +6 -0
- package/dist/lib/utils/registry.d.ts.map +1 -0
- package/dist/lib/utils/registry.js +35 -0
- package/dist/lib/utils/registry.js.map +1 -0
- package/dist/lib/utils/workspace.d.ts +3 -0
- package/dist/lib/utils/workspace.d.ts.map +1 -0
- package/dist/lib/utils/workspace.js +27 -0
- package/dist/lib/utils/workspace.js.map +1 -0
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +22 -0
- package/dist/program.js.map +1 -0
- package/dist/run.d.ts +2 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +8 -0
- package/dist/run.js.map +1 -0
- package/package.json +76 -4
- package/src/codemods/utils/createTransformer.ts +41 -0
- package/src/codemods/utils/resolveBinding.test.ts +107 -0
- package/src/codemods/utils/resolveBinding.ts +130 -0
- package/src/codemods/v0-11/README.md +246 -0
- package/src/codemods/v0-11/__tests__/content-part-to-message-part.test.ts +496 -0
- package/src/codemods/v0-11/content-part-to-message-part.ts +302 -0
- package/src/codemods/v0-12/__tests__/assistant-api-to-aui.test.ts +1220 -0
- package/src/codemods/v0-12/__tests__/event-names-to-camelcase.test.ts +150 -0
- package/src/codemods/v0-12/__tests__/primitive-if-to-aui-if.test.ts +1166 -0
- package/src/codemods/v0-12/assistant-api-to-aui.ts +270 -0
- package/src/codemods/v0-12/event-names-to-camelcase.ts +47 -0
- package/src/codemods/v0-12/primitive-if-to-aui-if.ts +372 -0
- package/src/codemods/v0-15/__tests__/aui-accessor-calls-to-properties.test.ts +210 -0
- package/src/codemods/v0-15/aui-accessor-calls-to-properties.ts +138 -0
- package/src/codemods/v0-8/__tests__/ui-package-split.test.ts +83 -0
- package/src/codemods/v0-8/ui-package-split.ts +159 -0
- package/src/codemods/v0-9/edge-package-split.test.ts +100 -0
- package/src/codemods/v0-9/edge-package-split.ts +70 -0
- package/src/commands/add.ts +111 -0
- package/src/commands/agent.ts +31 -0
- package/src/commands/cloud.test.ts +477 -0
- package/src/commands/cloud.ts +523 -0
- package/src/commands/create.ts +914 -0
- package/src/commands/doctor.ts +425 -0
- package/src/commands/info.ts +481 -0
- package/src/commands/init.ts +156 -0
- package/src/commands/mcp.test.ts +123 -0
- package/src/commands/mcp.ts +475 -0
- package/src/commands/setup.test.ts +285 -0
- package/src/commands/setup.ts +240 -0
- package/src/commands/update.ts +86 -0
- package/src/commands/upgrade.ts +66 -0
- package/src/index.ts +6 -0
- package/src/lib/agent-gate.test.ts +435 -0
- package/src/lib/agent-gate.ts +271 -0
- package/src/lib/agent-setup-hint.test.ts +134 -0
- package/src/lib/agent-setup-hint.ts +56 -0
- package/src/lib/agent-skill.ts +107 -0
- package/src/lib/cloud-abort.ts +12 -0
- package/src/lib/cloud-auth.test.ts +536 -0
- package/src/lib/cloud-auth.ts +299 -0
- package/src/lib/cloud-config.test.ts +220 -0
- package/src/lib/cloud-config.ts +217 -0
- package/src/lib/cloud-organizations.test.ts +76 -0
- package/src/lib/cloud-organizations.ts +55 -0
- package/src/lib/cloud-provision.test.ts +157 -0
- package/src/lib/cloud-provision.ts +96 -0
- package/src/lib/cloud-remote.test.ts +252 -0
- package/src/lib/cloud-remote.ts +236 -0
- package/src/lib/cloud-setup-login.test.ts +361 -0
- package/src/lib/cloud-setup-login.ts +240 -0
- package/src/lib/cloud-url.ts +21 -0
- package/src/lib/create-project-format.test.ts +122 -0
- package/src/lib/create-project.test.ts +158 -0
- package/src/lib/create-project.ts +717 -0
- package/src/lib/handle-cli-error.test.ts +67 -0
- package/src/lib/handle-cli-error.ts +17 -0
- package/src/lib/init-finish.ts +293 -0
- package/src/lib/install-ai-sdk-lib.ts +25 -0
- package/src/lib/install-edge-lib.ts +16 -0
- package/src/lib/run-spawn.test.ts +194 -0
- package/src/lib/run-spawn.ts +154 -0
- package/src/lib/safe-project-file.ts +31 -0
- package/src/lib/setup-session.test.ts +184 -0
- package/src/lib/setup-session.ts +179 -0
- package/src/lib/transform-files.test.ts +69 -0
- package/src/lib/transform-options.ts +6 -0
- package/src/lib/transform.test.ts +155 -0
- package/src/lib/transform.ts +131 -0
- package/src/lib/upgrade.ts +89 -0
- package/src/lib/utils/config.ts +60 -0
- package/src/lib/utils/download.ts +57 -0
- package/src/lib/utils/file-scanner.ts +51 -0
- package/src/lib/utils/logger.ts +22 -0
- package/src/lib/utils/package-installer.test.ts +39 -0
- package/src/lib/utils/package-installer.ts +40 -0
- package/src/lib/utils/package-json.ts +12 -0
- package/src/lib/utils/package-manager.ts +160 -0
- package/src/lib/utils/registry.test.ts +164 -0
- package/src/lib/utils/registry.ts +78 -0
- package/src/lib/utils/workspace.ts +34 -0
- package/src/program.ts +37 -0
- package/src/run.test.ts +23 -0
- package/src/run.ts +5 -0
- package/templates/cloud-harness/.assistant-ui/template.json +3 -0
- package/templates/cloud-harness/.env.example +1 -0
- package/templates/cloud-harness/.oxfmtrc.json +32 -0
- package/templates/cloud-harness/README.md +28 -0
- package/templates/cloud-harness/app/api/chat/route.ts +22 -0
- package/templates/cloud-harness/app/api/credential/route.ts +14 -0
- package/templates/cloud-harness/app/api/request-context.ts +16 -0
- package/templates/cloud-harness/app/assistant.tsx +83 -0
- package/templates/cloud-harness/app/favicon.ico +0 -0
- package/templates/cloud-harness/app/globals.css +139 -0
- package/templates/cloud-harness/app/layout.tsx +37 -0
- package/templates/cloud-harness/app/page.tsx +5 -0
- package/templates/cloud-harness/components/assistant-ui/elements/attachment-state.ts +59 -0
- package/templates/cloud-harness/components/assistant-ui/elements/attachment.aui.tsx +246 -0
- package/templates/cloud-harness/components/assistant-ui/elements/collapsible-root.tsx +19 -0
- package/templates/cloud-harness/components/assistant-ui/elements/markdown-text.tsx +238 -0
- package/templates/cloud-harness/components/assistant-ui/elements/thread.aui.tsx +521 -0
- package/templates/cloud-harness/components/assistant-ui/elements/tool-fallback.aui.tsx +1336 -0
- package/templates/cloud-harness/components/assistant-ui/elements/tooltip-icon-button.tsx +49 -0
- package/templates/cloud-harness/components/ui/avatar.tsx +109 -0
- package/templates/cloud-harness/components/ui/button.tsx +58 -0
- package/templates/cloud-harness/components/ui/collapsible.tsx +21 -0
- package/templates/cloud-harness/components/ui/dialog.tsx +159 -0
- package/templates/cloud-harness/components/ui/textarea.tsx +18 -0
- package/templates/cloud-harness/components/ui/tooltip.tsx +69 -0
- package/templates/cloud-harness/components.json +24 -0
- package/templates/cloud-harness/hooks/use-attachment-src.ts +46 -0
- package/templates/cloud-harness/hooks/use-copy-to-clipboard.ts +54 -0
- package/templates/cloud-harness/lib/utils.ts +1 -0
- package/templates/cloud-harness/next.config.ts +6 -0
- package/templates/cloud-harness/package.json +51 -0
- package/templates/cloud-harness/postcss.config.mjs +5 -0
- package/templates/cloud-harness/tsconfig.json +33 -0
- package/templates/cloud-harness/vendor/LICENSE +21 -0
- package/templates/cloud-harness/vendor/README.md +13 -0
- package/templates/cloud-harness/vendor/assistant-ui-react-harness-sdk-0.0.2.tgz +0 -0
- package/templates/cloud-harness/vendor/harness-sdk-0.3.1.tgz +0 -0
- package/templates/cloud-harness/vendor/provenance.json +38 -0
- package/templates/cloud-harness/vendor/statewire-0.19.3.tgz +0 -0
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
parse as parseJsonc,
|
|
6
|
+
printParseErrorCode,
|
|
7
|
+
type ParseError,
|
|
8
|
+
} from "jsonc-parser";
|
|
9
|
+
import { logger } from "./utils/logger";
|
|
10
|
+
import { runSpawn, SpawnExitError, SpawnSignalError } from "./run-spawn";
|
|
11
|
+
import {
|
|
12
|
+
dlxCommand,
|
|
13
|
+
SHADCN_PACKAGE,
|
|
14
|
+
type PackageManagerName,
|
|
15
|
+
} from "./utils/package-manager";
|
|
16
|
+
import { resolveGitHubAuthToken, withStagedDownload } from "./utils/download";
|
|
17
|
+
import { readProjectFiles } from "./utils/file-scanner";
|
|
18
|
+
import {
|
|
19
|
+
detectRegistryPlatform,
|
|
20
|
+
resolveRegistryItemUrl,
|
|
21
|
+
} from "./utils/registry";
|
|
22
|
+
|
|
23
|
+
export interface TransformOptions {
|
|
24
|
+
hasLocalComponents: boolean;
|
|
25
|
+
skipInstall?: boolean;
|
|
26
|
+
packageManager: PackageManagerName;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type ProjectSource =
|
|
30
|
+
| {
|
|
31
|
+
kind: "github";
|
|
32
|
+
ref: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
kind: "local";
|
|
36
|
+
rootDir: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const LOCAL_PROJECT_ARTIFACT_DIRS: readonly string[] = [
|
|
40
|
+
"node_modules",
|
|
41
|
+
".next",
|
|
42
|
+
"dist",
|
|
43
|
+
"build",
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES = LOCAL_PROJECT_ARTIFACT_DIRS.map(
|
|
47
|
+
(dir) => `**/${dir}/**`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
function toBearerAuthHeader(token: string): string {
|
|
51
|
+
return token.toLowerCase().startsWith("bearer ") ? token : `Bearer ${token}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function resolveLatestReleaseRef(): Promise<string | undefined> {
|
|
55
|
+
try {
|
|
56
|
+
const authToken = resolveGitHubAuthToken();
|
|
57
|
+
const res = await fetch(
|
|
58
|
+
"https://api.github.com/repos/assistant-ui/assistant-ui/releases/latest",
|
|
59
|
+
authToken
|
|
60
|
+
? { headers: { Authorization: toBearerAuthHeader(authToken) } }
|
|
61
|
+
: undefined,
|
|
62
|
+
);
|
|
63
|
+
if (!res.ok) return undefined;
|
|
64
|
+
const release = (await res.json()) as { tag_name: string };
|
|
65
|
+
return release.tag_name || undefined;
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const pendingDownloadCleanups = new Set<() => void>();
|
|
72
|
+
|
|
73
|
+
export function cleanupPendingProjectDownloads(): void {
|
|
74
|
+
for (const cleanup of pendingDownloadCleanups) {
|
|
75
|
+
pendingDownloadCleanups.delete(cleanup);
|
|
76
|
+
process.removeListener("exit", cleanup);
|
|
77
|
+
cleanup();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function downloadProject(
|
|
82
|
+
repoPath: string,
|
|
83
|
+
destDir: string,
|
|
84
|
+
ref?: string,
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
const source = ref
|
|
87
|
+
? `gh:assistant-ui/assistant-ui/${repoPath}#${ref}`
|
|
88
|
+
: `gh:assistant-ui/assistant-ui/${repoPath}`;
|
|
89
|
+
|
|
90
|
+
let destinationCreated = false;
|
|
91
|
+
let stagingDir: string | undefined;
|
|
92
|
+
let downloadStarted = false;
|
|
93
|
+
let downloadCommitted = false;
|
|
94
|
+
let cleanupRequested = false;
|
|
95
|
+
const removeCleanupListeners = () => {
|
|
96
|
+
process.removeListener("exit", cleanupOnExit);
|
|
97
|
+
pendingDownloadCleanups.delete(cleanupOnExit);
|
|
98
|
+
};
|
|
99
|
+
const attemptSyncCleanup = (cleanup: () => void) => {
|
|
100
|
+
try {
|
|
101
|
+
cleanup();
|
|
102
|
+
} catch {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const cleanupOnExit = () => {
|
|
107
|
+
cleanupRequested = true;
|
|
108
|
+
const currentStagingDir = stagingDir;
|
|
109
|
+
if (currentStagingDir) {
|
|
110
|
+
attemptSyncCleanup(() => {
|
|
111
|
+
fs.rmSync(currentStagingDir, { recursive: true, force: true });
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (destinationCreated && !downloadCommitted) {
|
|
115
|
+
attemptSyncCleanup(() => {
|
|
116
|
+
fs.rmdirSync(destDir);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const removeStagingDir = async () => {
|
|
121
|
+
if (stagingDir) {
|
|
122
|
+
await fs.promises
|
|
123
|
+
.rm(stagingDir, { recursive: true, force: true })
|
|
124
|
+
.catch(() => undefined);
|
|
125
|
+
}
|
|
126
|
+
removeCleanupListeners();
|
|
127
|
+
if (destinationCreated && !downloadCommitted) {
|
|
128
|
+
await fs.promises.rmdir(destDir).catch(() => undefined);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
try {
|
|
132
|
+
await fs.promises.mkdir(path.dirname(destDir), { recursive: true });
|
|
133
|
+
try {
|
|
134
|
+
stagingDir = await fs.promises.mkdtemp(
|
|
135
|
+
path.join(path.dirname(destDir), ".assistant-ui-download-"),
|
|
136
|
+
);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
139
|
+
if (code !== "EACCES" && code !== "EPERM" && code !== "EROFS") {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
stagingDir = await fs.promises.mkdtemp(
|
|
143
|
+
path.join(os.tmpdir(), ".assistant-ui-download-"),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
process.once("exit", cleanupOnExit);
|
|
147
|
+
pendingDownloadCleanups.add(cleanupOnExit);
|
|
148
|
+
|
|
149
|
+
const currentStagingDir = stagingDir;
|
|
150
|
+
downloadStarted = true;
|
|
151
|
+
await withStagedDownload(
|
|
152
|
+
source,
|
|
153
|
+
{ dir: currentStagingDir, force: true, silent: true },
|
|
154
|
+
"Download timed out. This may be due to GitHub rate limiting or a network issue. Try again in a few minutes.",
|
|
155
|
+
removeStagingDir,
|
|
156
|
+
async (download) => {
|
|
157
|
+
await download;
|
|
158
|
+
if (cleanupRequested) throw new Error("Download was interrupted.");
|
|
159
|
+
destinationCreated = !fs.existsSync(destDir);
|
|
160
|
+
await fs.promises.mkdir(destDir, { recursive: true });
|
|
161
|
+
for (const entry of await fs.promises.readdir(currentStagingDir)) {
|
|
162
|
+
const target = path.join(destDir, entry);
|
|
163
|
+
const sourceEntry = path.join(currentStagingDir, entry);
|
|
164
|
+
await fs.promises.rm(target, { recursive: true, force: true });
|
|
165
|
+
try {
|
|
166
|
+
await fs.promises.rename(sourceEntry, target);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if ((error as NodeJS.ErrnoException).code !== "EXDEV") throw error;
|
|
169
|
+
await fs.promises.cp(sourceEntry, target, {
|
|
170
|
+
recursive: true,
|
|
171
|
+
force: true,
|
|
172
|
+
});
|
|
173
|
+
await fs.promises.rm(sourceEntry, { recursive: true, force: true });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
downloadCommitted = true;
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
} finally {
|
|
180
|
+
if (!downloadStarted) await removeStagingDir();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function shouldCopyLocalProjectPath(src: string, projectDir: string): boolean {
|
|
185
|
+
const relative = path.relative(projectDir, src);
|
|
186
|
+
if (!relative) return true;
|
|
187
|
+
|
|
188
|
+
const segments = relative.split(path.sep);
|
|
189
|
+
return !segments.some((segment) =>
|
|
190
|
+
LOCAL_PROJECT_ARTIFACT_DIRS.includes(segment),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export async function scaffoldProject(
|
|
195
|
+
repoPath: string,
|
|
196
|
+
destDir: string,
|
|
197
|
+
source: ProjectSource,
|
|
198
|
+
): Promise<void> {
|
|
199
|
+
if (source.kind === "github") {
|
|
200
|
+
await downloadProject(repoPath, destDir, source.ref);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const localProjectDir = path.resolve(source.rootDir, repoPath);
|
|
205
|
+
try {
|
|
206
|
+
fs.cpSync(localProjectDir, destDir, {
|
|
207
|
+
recursive: true,
|
|
208
|
+
force: true,
|
|
209
|
+
filter: (src) => shouldCopyLocalProjectPath(src, localProjectDir),
|
|
210
|
+
});
|
|
211
|
+
} catch (error) {
|
|
212
|
+
const code =
|
|
213
|
+
error instanceof Error
|
|
214
|
+
? (error as NodeJS.ErrnoException).code
|
|
215
|
+
: undefined;
|
|
216
|
+
if (code === "ENOENT") {
|
|
217
|
+
throw new Error(
|
|
218
|
+
`Local project source does not exist: ${localProjectDir}`,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface TransformResult {
|
|
226
|
+
registryInstallFailure?: { retryCommand: string };
|
|
227
|
+
registryInstallCommand?: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export async function transformProject(
|
|
231
|
+
projectDir: string,
|
|
232
|
+
opts: TransformOptions,
|
|
233
|
+
): Promise<TransformResult> {
|
|
234
|
+
logger.step("Transforming package.json...");
|
|
235
|
+
transformPackageJson(projectDir);
|
|
236
|
+
|
|
237
|
+
logger.step("Transforming project files...");
|
|
238
|
+
transformTsConfig(projectDir);
|
|
239
|
+
transformCssFiles(projectDir);
|
|
240
|
+
|
|
241
|
+
const components = opts.hasLocalComponents
|
|
242
|
+
? undefined
|
|
243
|
+
: resolveRegistryComponents(projectDir, scanRequiredComponents(projectDir));
|
|
244
|
+
|
|
245
|
+
const pm = opts.packageManager;
|
|
246
|
+
if (opts.skipInstall) {
|
|
247
|
+
if (!components) return {};
|
|
248
|
+
const [cmd, dlxArgs] = dlxCommand(pm);
|
|
249
|
+
return {
|
|
250
|
+
registryInstallCommand: `${cmd} ${[...dlxArgs, SHADCN_PACKAGE, "add", ...components].join(" ")}`,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
logger.step("Installing dependencies...");
|
|
255
|
+
await installDependencies(projectDir, pm);
|
|
256
|
+
|
|
257
|
+
if (components) {
|
|
258
|
+
logger.step(`Installing components: ${components.join(", ")}...`);
|
|
259
|
+
const failure = await installShadcnRegistry(
|
|
260
|
+
projectDir,
|
|
261
|
+
components,
|
|
262
|
+
"components",
|
|
263
|
+
pm,
|
|
264
|
+
);
|
|
265
|
+
if (failure) return { registryInstallFailure: failure };
|
|
266
|
+
await reconcileAssistantUIImportLayout(projectDir);
|
|
267
|
+
}
|
|
268
|
+
return {};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function resolveRegistryComponents(
|
|
272
|
+
projectDir: string,
|
|
273
|
+
{ assistantUI, shadcnUI }: RequiredComponents,
|
|
274
|
+
): string[] {
|
|
275
|
+
if (detectRegistryPlatform(projectDir) === "native") {
|
|
276
|
+
return ["utils", ...shadcnUI, ...assistantUI].map((component) =>
|
|
277
|
+
resolveRegistryItemUrl(component, undefined, "native"),
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return [
|
|
281
|
+
"@assistant-ui/utils",
|
|
282
|
+
...shadcnUI,
|
|
283
|
+
...assistantUI.map((component) => `@assistant-ui/${component}`),
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function transformPackageJson(projectDir: string): void {
|
|
288
|
+
const pkgPath = path.join(projectDir, "package.json");
|
|
289
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
290
|
+
|
|
291
|
+
// Remove @assistant-ui/ui dependency
|
|
292
|
+
if (pkg.dependencies?.["@assistant-ui/ui"]) {
|
|
293
|
+
delete pkg.dependencies["@assistant-ui/ui"];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Transform workspace dependencies to latest
|
|
297
|
+
for (const depType of ["dependencies", "devDependencies"] as const) {
|
|
298
|
+
const deps = pkg[depType];
|
|
299
|
+
if (!deps) continue;
|
|
300
|
+
|
|
301
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
302
|
+
if (String(version).includes("workspace:")) {
|
|
303
|
+
deps[name] = "latest";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Remove devDependencies that are workspace-only
|
|
309
|
+
if (pkg.devDependencies?.["@assistant-ui/x-buildutils"]) {
|
|
310
|
+
delete pkg.devDependencies["@assistant-ui/x-buildutils"];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Update package name to be unique
|
|
314
|
+
const dirName = path.basename(projectDir);
|
|
315
|
+
pkg.name = dirName;
|
|
316
|
+
|
|
317
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function parseTsConfig(content: string): any {
|
|
321
|
+
const errors: ParseError[] = [];
|
|
322
|
+
const tsconfig = parseJsonc(content, errors, { allowTrailingComma: true });
|
|
323
|
+
const error = errors[0];
|
|
324
|
+
if (error) {
|
|
325
|
+
throw new SyntaxError(
|
|
326
|
+
`Invalid tsconfig.json: ${printParseErrorCode(error.error)} at offset ${error.offset}`,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
return tsconfig;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function transformTsConfig(projectDir: string): void {
|
|
333
|
+
const tsconfigPath = path.join(projectDir, "tsconfig.json");
|
|
334
|
+
|
|
335
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const content = fs.readFileSync(tsconfigPath, "utf-8");
|
|
340
|
+
const tsconfig = parseTsConfig(content);
|
|
341
|
+
|
|
342
|
+
// Remove workspace paths
|
|
343
|
+
if (tsconfig.compilerOptions?.paths) {
|
|
344
|
+
const workspaceKeys = new Set([
|
|
345
|
+
"@/components/assistant-ui/*",
|
|
346
|
+
"@/components/icons/*",
|
|
347
|
+
"@/components/ui/*",
|
|
348
|
+
"@/components/ui/radix/*",
|
|
349
|
+
"@/hooks/*",
|
|
350
|
+
"@/lib/utils",
|
|
351
|
+
"@assistant-ui/ui/*",
|
|
352
|
+
]);
|
|
353
|
+
for (const [key, targets] of Object.entries(
|
|
354
|
+
tsconfig.compilerOptions.paths as Record<string, unknown>,
|
|
355
|
+
)) {
|
|
356
|
+
const targetsWorkspace =
|
|
357
|
+
Array.isArray(targets) &&
|
|
358
|
+
targets.some(
|
|
359
|
+
(target) =>
|
|
360
|
+
typeof target === "string" &&
|
|
361
|
+
(target.includes("packages/ui/") || target.startsWith("../")),
|
|
362
|
+
);
|
|
363
|
+
if (workspaceKeys.has(key) || targetsWorkspace) {
|
|
364
|
+
delete tsconfig.compilerOptions.paths[key];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (Object.keys(tsconfig.compilerOptions.paths).length === 0) {
|
|
369
|
+
delete tsconfig.compilerOptions.paths;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// If extends uses @assistant-ui/x-buildutils, replace with inline config
|
|
374
|
+
if (tsconfig.extends?.includes("@assistant-ui/x-buildutils")) {
|
|
375
|
+
const isNext = tsconfig.extends.includes("ts/next");
|
|
376
|
+
delete tsconfig.extends;
|
|
377
|
+
|
|
378
|
+
const inlinedCompilerOptions = {
|
|
379
|
+
target: "ESNext",
|
|
380
|
+
lib: ["dom", "dom.iterable", "ES2023"],
|
|
381
|
+
skipLibCheck: true,
|
|
382
|
+
strict: true,
|
|
383
|
+
noEmit: true,
|
|
384
|
+
esModuleInterop: true,
|
|
385
|
+
module: "ESNext",
|
|
386
|
+
moduleResolution: "bundler",
|
|
387
|
+
resolveJsonModule: true,
|
|
388
|
+
isolatedModules: true,
|
|
389
|
+
jsx: "react-jsx",
|
|
390
|
+
...(isNext ? { plugins: [{ name: "next" }] } : {}),
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
tsconfig.compilerOptions = {
|
|
394
|
+
...inlinedCompilerOptions,
|
|
395
|
+
...tsconfig.compilerOptions,
|
|
396
|
+
paths: {
|
|
397
|
+
"@/*": ["./*"],
|
|
398
|
+
...(tsconfig.compilerOptions?.paths || {}),
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
fs.writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\n`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function transformCssFiles(projectDir: string): void {
|
|
407
|
+
for (const { fullPath, content } of readProjectFiles("**/*.css", {
|
|
408
|
+
cwd: projectDir,
|
|
409
|
+
ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,
|
|
410
|
+
})) {
|
|
411
|
+
try {
|
|
412
|
+
const newContent = content.replace(
|
|
413
|
+
/@source\s+["'][^"']*packages\/ui\/src[^"']*["'];\s*\n?/g,
|
|
414
|
+
"",
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
if (newContent !== content) {
|
|
418
|
+
fs.writeFileSync(fullPath, newContent);
|
|
419
|
+
}
|
|
420
|
+
} catch {
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
interface RequiredComponents {
|
|
427
|
+
assistantUI: string[];
|
|
428
|
+
shadcnUI: string[];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function stripImportExtension(component: string): string {
|
|
432
|
+
return component.replace(/\.[cm]?[tj]sx?$/, "");
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const ASSISTANT_UI_OWNED_UI = new Set([
|
|
436
|
+
"accordion",
|
|
437
|
+
"badge",
|
|
438
|
+
"diff-viewer",
|
|
439
|
+
"direction",
|
|
440
|
+
"dot-matrix",
|
|
441
|
+
"number-roll",
|
|
442
|
+
"select",
|
|
443
|
+
"tabs",
|
|
444
|
+
]);
|
|
445
|
+
|
|
446
|
+
const BARE_ELEMENT_ITEMS = new Set([
|
|
447
|
+
"file",
|
|
448
|
+
"generative-ui",
|
|
449
|
+
"heat-graph",
|
|
450
|
+
"image",
|
|
451
|
+
"logos",
|
|
452
|
+
"markdown-text",
|
|
453
|
+
"syntax-highlighter",
|
|
454
|
+
"tooltip-icon-button",
|
|
455
|
+
]);
|
|
456
|
+
|
|
457
|
+
function toAssistantUIItem(specifier: string): string | null {
|
|
458
|
+
let name = stripImportExtension(specifier);
|
|
459
|
+
const inElements = name.startsWith("elements/");
|
|
460
|
+
if (inElements) {
|
|
461
|
+
name = name.slice("elements/".length);
|
|
462
|
+
} else if (name.includes("/")) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
if (name.endsWith(".aui")) {
|
|
466
|
+
return name.slice(0, -".aui".length);
|
|
467
|
+
}
|
|
468
|
+
return inElements && !BARE_ELEMENT_ITEMS.has(name)
|
|
469
|
+
? `elements-${name}`
|
|
470
|
+
: name;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Example snapshots are downloaded at a release tag while the shadcn registry
|
|
475
|
+
* is live, so a snapshot may import components at the legacy flat path
|
|
476
|
+
* (`@/components/assistant-ui/<name>`) after the registry has moved the file
|
|
477
|
+
* to `components/assistant-ui/elements/<name>.aui.tsx`. Resolve each legacy
|
|
478
|
+
* specifier against the files the registry actually installed and rewrite it
|
|
479
|
+
* only when the legacy path is absent and the elements layout has it.
|
|
480
|
+
*/
|
|
481
|
+
export async function reconcileAssistantUIImportLayout(
|
|
482
|
+
projectDir: string,
|
|
483
|
+
): Promise<void> {
|
|
484
|
+
const componentRoots = ["components", "src/components"]
|
|
485
|
+
.map((dir) => path.join(projectDir, dir, "assistant-ui"))
|
|
486
|
+
.filter((dir) => fs.existsSync(dir));
|
|
487
|
+
if (componentRoots.length === 0) return;
|
|
488
|
+
|
|
489
|
+
const resolvesAtLegacyPath = (name: string) =>
|
|
490
|
+
componentRoots.some((root) =>
|
|
491
|
+
[".tsx", ".ts", "/index.tsx", "/index.ts"].some((suffix) =>
|
|
492
|
+
fs.existsSync(path.join(root, `${name}${suffix}`)),
|
|
493
|
+
),
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
// Index the installed tree by import name so the rewrite follows whatever
|
|
497
|
+
// layout the registry delivered — some items install as
|
|
498
|
+
// elements/<name>.aui.tsx, others as elements/<name>.tsx, and a future
|
|
499
|
+
// layout move should not require new knowledge here.
|
|
500
|
+
const installedByName = new Map<string, string>();
|
|
501
|
+
for (const root of componentRoots) {
|
|
502
|
+
for (const { file } of readProjectFiles("**/*.{ts,tsx}", { cwd: root })) {
|
|
503
|
+
const normalized = file.split(path.sep).join("/");
|
|
504
|
+
if (!normalized.includes("/")) continue;
|
|
505
|
+
const specifier = normalized.replace(/\.[cm]?[tj]sx?$/, "");
|
|
506
|
+
const name = path.posix.basename(specifier).replace(/\.aui$/, "");
|
|
507
|
+
// A flat legacy import maps to the registry's `<name>` item, which is
|
|
508
|
+
// the `.aui` file; a colliding bare file with the same basename belongs
|
|
509
|
+
// to the distinct `elements-<name>` item, so the `.aui` variant wins.
|
|
510
|
+
const existing = installedByName.get(name);
|
|
511
|
+
if (
|
|
512
|
+
existing === undefined ||
|
|
513
|
+
(!existing.endsWith(".aui") && specifier.endsWith(".aui"))
|
|
514
|
+
) {
|
|
515
|
+
installedByName.set(name, specifier);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (installedByName.size === 0) return;
|
|
520
|
+
|
|
521
|
+
const { default: jscodeshift } = await import("jscodeshift");
|
|
522
|
+
const parsers = {
|
|
523
|
+
ts: jscodeshift.withParser("ts"),
|
|
524
|
+
tsx: jscodeshift.withParser("tsx"),
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
for (const { fullPath, content } of readProjectFiles("**/*.{ts,tsx}", {
|
|
528
|
+
cwd: projectDir,
|
|
529
|
+
ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,
|
|
530
|
+
})) {
|
|
531
|
+
if (!content.includes("@/components/assistant-ui/")) continue;
|
|
532
|
+
|
|
533
|
+
const replacements: Array<{ start: number; end: number; value: string }> =
|
|
534
|
+
[];
|
|
535
|
+
const collectReplacement = (source: {
|
|
536
|
+
value?: unknown;
|
|
537
|
+
start?: number | null;
|
|
538
|
+
end?: number | null;
|
|
539
|
+
}) => {
|
|
540
|
+
if (
|
|
541
|
+
typeof source.value !== "string" ||
|
|
542
|
+
source.start == null ||
|
|
543
|
+
source.end == null
|
|
544
|
+
) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const prefix = "@/components/assistant-ui/";
|
|
549
|
+
if (!source.value.startsWith(prefix)) return;
|
|
550
|
+
const specifier = source.value.slice(prefix.length);
|
|
551
|
+
if (specifier.includes("/")) return;
|
|
552
|
+
|
|
553
|
+
const name = stripImportExtension(specifier);
|
|
554
|
+
const installed = installedByName.get(name);
|
|
555
|
+
if (resolvesAtLegacyPath(name) || installed === undefined) return;
|
|
556
|
+
|
|
557
|
+
const raw = content.slice(source.start, source.end);
|
|
558
|
+
const quote = raw[0];
|
|
559
|
+
if ((quote !== '"' && quote !== "'") || raw.at(-1) !== quote) return;
|
|
560
|
+
replacements.push({
|
|
561
|
+
start: source.start,
|
|
562
|
+
end: source.end,
|
|
563
|
+
value: `${quote}@/components/assistant-ui/${installed}${quote}`,
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const j = fullPath.endsWith(".tsx") ? parsers.tsx : parsers.ts;
|
|
568
|
+
let root;
|
|
569
|
+
try {
|
|
570
|
+
root = j(content);
|
|
571
|
+
} catch {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
root
|
|
575
|
+
.find(j.ImportDeclaration)
|
|
576
|
+
.forEach(({ node }) => collectReplacement(node.source));
|
|
577
|
+
root
|
|
578
|
+
.find(j.ExportNamedDeclaration)
|
|
579
|
+
.forEach(({ node }) => node.source && collectReplacement(node.source));
|
|
580
|
+
root
|
|
581
|
+
.find(j.ExportAllDeclaration)
|
|
582
|
+
.forEach(({ node }) => collectReplacement(node.source));
|
|
583
|
+
|
|
584
|
+
let next = content;
|
|
585
|
+
for (const replacement of replacements.sort((a, b) => b.start - a.start)) {
|
|
586
|
+
next =
|
|
587
|
+
next.slice(0, replacement.start) +
|
|
588
|
+
replacement.value +
|
|
589
|
+
next.slice(replacement.end);
|
|
590
|
+
}
|
|
591
|
+
if (next !== content) fs.writeFileSync(fullPath, next);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export function scanRequiredComponents(projectDir: string): RequiredComponents {
|
|
596
|
+
const assistantUIComponents = new Set<string>();
|
|
597
|
+
const shadcnUIComponents = new Set<string>();
|
|
598
|
+
|
|
599
|
+
for (const { content } of readProjectFiles("**/*.{ts,tsx}", {
|
|
600
|
+
cwd: projectDir,
|
|
601
|
+
ignore: LOCAL_PROJECT_ARTIFACT_GLOB_IGNORES,
|
|
602
|
+
})) {
|
|
603
|
+
const assistantUIRegex =
|
|
604
|
+
/from\s+["']@\/components\/assistant-ui\/([^"']+)["']/g;
|
|
605
|
+
for (const match of content.matchAll(assistantUIRegex)) {
|
|
606
|
+
const item = toAssistantUIItem(match[1]!);
|
|
607
|
+
if (item) assistantUIComponents.add(item);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const uiRegex = /from\s+["']@\/components\/ui\/([^"']+)["']/g;
|
|
611
|
+
for (const match of content.matchAll(uiRegex)) {
|
|
612
|
+
const name = stripImportExtension(match[1]!);
|
|
613
|
+
if (ASSISTANT_UI_OWNED_UI.has(name)) {
|
|
614
|
+
assistantUIComponents.add(name);
|
|
615
|
+
} else {
|
|
616
|
+
shadcnUIComponents.add(name);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return {
|
|
622
|
+
assistantUI: Array.from(assistantUIComponents),
|
|
623
|
+
shadcnUI: Array.from(shadcnUIComponents),
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
async function installDependencies(
|
|
628
|
+
projectDir: string,
|
|
629
|
+
pm: PackageManagerName,
|
|
630
|
+
): Promise<void> {
|
|
631
|
+
const args = pm === "yarn" ? [] : ["install"];
|
|
632
|
+
try {
|
|
633
|
+
await runSpawn(pm, args, projectDir);
|
|
634
|
+
} catch (error) {
|
|
635
|
+
if (error instanceof SpawnSignalError) {
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
if (error instanceof SpawnExitError) {
|
|
639
|
+
throw new Error(`${pm} install exited with code ${error.code}`);
|
|
640
|
+
}
|
|
641
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
642
|
+
throw new Error(`Failed to install dependencies: ${message}`);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
async function installShadcnRegistry(
|
|
647
|
+
projectDir: string,
|
|
648
|
+
components: string[],
|
|
649
|
+
label: string,
|
|
650
|
+
pm: PackageManagerName,
|
|
651
|
+
): Promise<{ retryCommand: string } | undefined> {
|
|
652
|
+
const [cmd, dlxArgs] = dlxCommand(pm);
|
|
653
|
+
// For npm, dlxArgs may already include `--yes` for npx auto-install.
|
|
654
|
+
// The trailing `--yes` is for shadcn's own confirmation prompt.
|
|
655
|
+
const retryArgs = [...dlxArgs, SHADCN_PACKAGE, "add", ...components];
|
|
656
|
+
const addArgs = [...retryArgs, "--yes"];
|
|
657
|
+
|
|
658
|
+
try {
|
|
659
|
+
await runSpawn(cmd, addArgs, projectDir);
|
|
660
|
+
return undefined;
|
|
661
|
+
} catch (error) {
|
|
662
|
+
if (error instanceof SpawnSignalError) {
|
|
663
|
+
throw error;
|
|
664
|
+
}
|
|
665
|
+
if (error instanceof SpawnExitError) {
|
|
666
|
+
logger.warn(`shadcn exited with code ${error.code}.`);
|
|
667
|
+
return { retryCommand: `${cmd} ${retryArgs.join(" ")}` };
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
671
|
+
throw new Error(`Failed to install ${label}: ${message}`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const FORMAT_FIX_SCRIPT = "format:fix";
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Returns the command that runs the project's own `format:fix` script, or
|
|
679
|
+
* undefined when the scaffolded package.json does not define one.
|
|
680
|
+
*/
|
|
681
|
+
export function resolveFormatCommand(
|
|
682
|
+
projectDir: string,
|
|
683
|
+
pm: PackageManagerName,
|
|
684
|
+
): [string, string[]] | undefined {
|
|
685
|
+
try {
|
|
686
|
+
const pkg = JSON.parse(
|
|
687
|
+
fs.readFileSync(path.join(projectDir, "package.json"), "utf-8"),
|
|
688
|
+
);
|
|
689
|
+
if (typeof pkg.scripts?.[FORMAT_FIX_SCRIPT] !== "string") return undefined;
|
|
690
|
+
} catch {
|
|
691
|
+
return undefined;
|
|
692
|
+
}
|
|
693
|
+
return [pm, ["run", FORMAT_FIX_SCRIPT]];
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Runs the project's formatter so files written by the CLI and by shadcn
|
|
698
|
+
* (registry components, tsconfig.json) match the template's formatter config
|
|
699
|
+
* and `lint` passes on a fresh project. A formatter failure only warns.
|
|
700
|
+
*/
|
|
701
|
+
export async function formatProject(
|
|
702
|
+
projectDir: string,
|
|
703
|
+
pm: PackageManagerName,
|
|
704
|
+
): Promise<void> {
|
|
705
|
+
const command = resolveFormatCommand(projectDir, pm);
|
|
706
|
+
if (!command) return;
|
|
707
|
+
const [cmd, args] = command;
|
|
708
|
+
logger.step("Formatting project files...");
|
|
709
|
+
try {
|
|
710
|
+
await runSpawn(cmd, args, projectDir);
|
|
711
|
+
} catch (error) {
|
|
712
|
+
if (error instanceof SpawnSignalError) throw error;
|
|
713
|
+
logger.warn(
|
|
714
|
+
`Could not format project files. You can run the formatter later with:\n ${cmd} ${args.join(" ")}`,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
}
|