assistant-ui 0.0.91 → 0.0.93
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 +32 -108
- package/dist/codemods/utils/createTransformer.d.ts +17 -13
- package/dist/codemods/utils/createTransformer.d.ts.map +1 -1
- package/dist/codemods/utils/createTransformer.js +18 -15
- package/dist/codemods/utils/createTransformer.js.map +1 -1
- package/dist/codemods/v0-11/content-part-to-message-part.d.ts +3 -1
- package/dist/codemods/v0-11/content-part-to-message-part.d.ts.map +1 -1
- package/dist/codemods/v0-11/content-part-to-message-part.js +98 -135
- package/dist/codemods/v0-11/content-part-to-message-part.js.map +1 -1
- package/dist/codemods/v0-12/assistant-api-to-aui.d.ts +3 -1
- package/dist/codemods/v0-12/assistant-api-to-aui.d.ts.map +1 -1
- package/dist/codemods/v0-12/assistant-api-to-aui.js +126 -213
- package/dist/codemods/v0-12/assistant-api-to-aui.js.map +1 -1
- package/dist/codemods/v0-12/event-names-to-camelcase.d.ts +3 -1
- package/dist/codemods/v0-12/event-names-to-camelcase.d.ts.map +1 -1
- package/dist/codemods/v0-12/event-names-to-camelcase.js +33 -38
- package/dist/codemods/v0-12/event-names-to-camelcase.js.map +1 -1
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts +3 -1
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts.map +1 -1
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js +212 -297
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js.map +1 -1
- package/dist/codemods/v0-8/ui-package-split.d.ts +3 -1
- package/dist/codemods/v0-8/ui-package-split.d.ts.map +1 -1
- package/dist/codemods/v0-8/ui-package-split.js +121 -164
- package/dist/codemods/v0-8/ui-package-split.js.map +1 -1
- package/dist/codemods/v0-9/edge-package-split.d.ts +3 -1
- package/dist/codemods/v0-9/edge-package-split.d.ts.map +1 -1
- package/dist/codemods/v0-9/edge-package-split.js +96 -140
- package/dist/codemods/v0-9/edge-package-split.js.map +1 -1
- package/dist/commands/add.d.ts +18 -1
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +54 -49
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/agent.d.ts +5 -1
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +16 -25
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/create.d.ts +36 -26
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +458 -519
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/info.d.ts +5 -1
- package/dist/commands/info.d.ts.map +1 -1
- package/dist/commands/info.js +233 -314
- package/dist/commands/info.js.map +1 -1
- package/dist/commands/init.d.ts +12 -9
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +98 -136
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/mcp.d.ts +5 -1
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +175 -214
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/update.d.ts +5 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +46 -55
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/upgrade.d.ts +11 -7
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +26 -38
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +15 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/create-project.d.ts +27 -10
- package/dist/lib/create-project.d.ts.map +1 -1
- package/dist/lib/create-project.js +239 -277
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/install-ai-sdk-lib.d.ts +4 -1
- package/dist/lib/install-ai-sdk-lib.d.ts.map +1 -1
- package/dist/lib/install-ai-sdk-lib.js +12 -8
- package/dist/lib/install-ai-sdk-lib.js.map +1 -1
- package/dist/lib/install-edge-lib.d.ts +4 -1
- package/dist/lib/install-edge-lib.d.ts.map +1 -1
- package/dist/lib/install-edge-lib.js +16 -12
- package/dist/lib/install-edge-lib.js.map +1 -1
- package/dist/lib/install-ui-lib.d.ts +4 -1
- package/dist/lib/install-ui-lib.d.ts.map +1 -1
- package/dist/lib/install-ui-lib.js +12 -8
- package/dist/lib/install-ui-lib.js.map +1 -1
- package/dist/lib/run-spawn.d.ts +9 -0
- package/dist/lib/run-spawn.d.ts.map +1 -0
- package/dist/lib/run-spawn.js +26 -0
- package/dist/lib/run-spawn.js.map +1 -0
- package/dist/lib/transform-options.d.ts +8 -5
- package/dist/lib/transform-options.d.ts.map +1 -1
- package/dist/lib/transform-options.js +0 -2
- package/dist/lib/transform.d.ts +15 -11
- package/dist/lib/transform.d.ts.map +1 -1
- package/dist/lib/transform.js +97 -114
- package/dist/lib/transform.js.map +1 -1
- package/dist/lib/upgrade.d.ts +6 -2
- package/dist/lib/upgrade.d.ts.map +1 -1
- package/dist/lib/upgrade.js +62 -64
- package/dist/lib/upgrade.js.map +1 -1
- package/dist/lib/utils/config.d.ts +21 -18
- package/dist/lib/utils/config.d.ts.map +1 -1
- package/dist/lib/utils/config.js +24 -28
- package/dist/lib/utils/config.js.map +1 -1
- package/dist/lib/utils/file-scanner.d.ts +9 -6
- package/dist/lib/utils/file-scanner.d.ts.map +1 -1
- package/dist/lib/utils/file-scanner.js +44 -51
- package/dist/lib/utils/file-scanner.js.map +1 -1
- package/dist/lib/utils/logger.d.ts +10 -7
- package/dist/lib/utils/logger.d.ts.map +1 -1
- package/dist/lib/utils/logger.js +23 -19
- package/dist/lib/utils/logger.js.map +1 -1
- package/dist/lib/utils/package-installer.d.ts +10 -7
- package/dist/lib/utils/package-installer.d.ts.map +1 -1
- package/dist/lib/utils/package-installer.js +18 -19
- package/dist/lib/utils/package-installer.js.map +1 -1
- package/dist/lib/utils/package-manager.d.ts +10 -7
- package/dist/lib/utils/package-manager.d.ts.map +1 -1
- package/dist/lib/utils/package-manager.js +68 -59
- package/dist/lib/utils/package-manager.js.map +1 -1
- package/package.json +7 -7
- package/plugin/skills/assistant-ui/SKILL.md +2 -2
- package/src/commands/add.ts +67 -30
- package/src/commands/create.ts +116 -84
- package/src/commands/init.ts +9 -42
- package/src/lib/create-project.ts +123 -74
- package/src/lib/run-spawn.ts +32 -0
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/transform-options.js.map +0 -1
|
@@ -1,170 +1,127 @@
|
|
|
1
1
|
import { createTransformer } from "../utils/createTransformer.js";
|
|
2
|
+
//#region src/codemods/v0-8/ui-package-split.ts
|
|
2
3
|
const reactUIExports = [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
"ThreadConfigProvider",
|
|
5
|
+
"useThreadConfig",
|
|
6
|
+
"ThreadConfig",
|
|
7
|
+
"ThreadWelcomeConfig",
|
|
8
|
+
"UserMessageConfig",
|
|
9
|
+
"AssistantMessageConfig",
|
|
10
|
+
"StringsConfig",
|
|
11
|
+
"SuggestionConfig",
|
|
12
|
+
"ThreadConfigProviderProps",
|
|
13
|
+
"AssistantActionBar",
|
|
14
|
+
"AssistantMessage",
|
|
15
|
+
"AssistantModal",
|
|
16
|
+
"BranchPicker",
|
|
17
|
+
"Composer",
|
|
18
|
+
"MessagePart",
|
|
19
|
+
"AttachmentUI",
|
|
20
|
+
"EditComposer",
|
|
21
|
+
"Thread",
|
|
22
|
+
"ThreadList",
|
|
23
|
+
"ThreadListItem",
|
|
24
|
+
"ThreadWelcome",
|
|
25
|
+
"UserMessage",
|
|
26
|
+
"makeMarkdownText",
|
|
27
|
+
"MakeMarkdownTextProps",
|
|
28
|
+
"CodeHeader"
|
|
28
29
|
];
|
|
29
30
|
const migrateAssistantUI = createTransformer(({ j, root, markAsChanged }) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
j(varDecl).remove();
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
varDecl.value.declarations = varDecl.value.declarations.filter((decl) => decl !== parent.value);
|
|
126
|
-
}
|
|
127
|
-
markAsChanged();
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
j(path).remove();
|
|
131
|
-
markAsChanged();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
root
|
|
135
|
-
.find(j.CallExpression, { callee: { name: "require" } })
|
|
136
|
-
.filter((path) => {
|
|
137
|
-
const arg = path.value.arguments[0];
|
|
138
|
-
return (arg &&
|
|
139
|
-
(arg.type === "Literal" || arg.type === "StringLiteral") &&
|
|
140
|
-
arg.value === "@assistant-ui/react/tailwindcss");
|
|
141
|
-
})
|
|
142
|
-
.forEach((path) => {
|
|
143
|
-
path.value.arguments[0].value = "@assistant-ui/react-ui/tailwindcss";
|
|
144
|
-
markAsChanged();
|
|
145
|
-
if (removedMarkdownPlugin) {
|
|
146
|
-
if (path.parentPath?.value &&
|
|
147
|
-
path.parentPath.value.type === "CallExpression" &&
|
|
148
|
-
path.parentPath.value.arguments.length > 0) {
|
|
149
|
-
const configObj = path.parentPath.value.arguments[0];
|
|
150
|
-
if (configObj && configObj.type === "ObjectExpression") {
|
|
151
|
-
const componentsProp = configObj.properties.find((prop) => {
|
|
152
|
-
return ((prop.key.name === "components" ||
|
|
153
|
-
prop.key.value === "components") &&
|
|
154
|
-
prop.value.type === "ArrayExpression");
|
|
155
|
-
});
|
|
156
|
-
if (componentsProp) {
|
|
157
|
-
const componentsArray = componentsProp.value.elements;
|
|
158
|
-
const hasMarkdown = componentsArray.some((el) => el.type === "Literal" && el.value === "markdown");
|
|
159
|
-
if (!hasMarkdown) {
|
|
160
|
-
componentsArray.push(j.literal("markdown"));
|
|
161
|
-
markAsChanged();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
31
|
+
const sourcesToMigrate = ["@assistant-ui/react", "@assistant-ui/react-markdown"];
|
|
32
|
+
const movedSpecifiers = [];
|
|
33
|
+
let lastMigratedImportPath = null;
|
|
34
|
+
root.find(j.ImportDeclaration).filter((path) => sourcesToMigrate.includes(path.value.source.value)).forEach((path) => {
|
|
35
|
+
let hadMigratedSpecifiers = false;
|
|
36
|
+
const remainingSpecifiers = [];
|
|
37
|
+
path.value.specifiers.forEach((specifier) => {
|
|
38
|
+
if (j.ImportSpecifier.check(specifier) && reactUIExports.includes(specifier.imported.name)) {
|
|
39
|
+
movedSpecifiers.push(specifier);
|
|
40
|
+
hadMigratedSpecifiers = true;
|
|
41
|
+
} else remainingSpecifiers.push(specifier);
|
|
42
|
+
});
|
|
43
|
+
if (hadMigratedSpecifiers) lastMigratedImportPath = path;
|
|
44
|
+
if (remainingSpecifiers.length === 0) {
|
|
45
|
+
j(path).remove();
|
|
46
|
+
markAsChanged();
|
|
47
|
+
} else if (remainingSpecifiers.length !== path.value.specifiers.length) {
|
|
48
|
+
path.value.specifiers = remainingSpecifiers;
|
|
49
|
+
markAsChanged();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (movedSpecifiers.length > 0) {
|
|
53
|
+
const existingReactUIImport = root.find(j.ImportDeclaration, { source: { value: "@assistant-ui/react-ui" } });
|
|
54
|
+
if (existingReactUIImport.size() > 0) existingReactUIImport.forEach((path) => {
|
|
55
|
+
movedSpecifiers.forEach((specifier) => {
|
|
56
|
+
if (!path.value.specifiers.some((s) => s.imported.name === specifier.imported.name)) path.value.specifiers.push(specifier);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
else {
|
|
60
|
+
const newImport = j.importDeclaration(movedSpecifiers, j.literal("@assistant-ui/react-ui"));
|
|
61
|
+
if (lastMigratedImportPath) j(lastMigratedImportPath).insertAfter(newImport);
|
|
62
|
+
else {
|
|
63
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
64
|
+
if (firstImport.size() > 0) firstImport.insertBefore(newImport);
|
|
65
|
+
else root.get().node.program.body.unshift(newImport);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
markAsChanged();
|
|
69
|
+
}
|
|
70
|
+
const cssReplacements = {
|
|
71
|
+
"@assistant-ui/react/styles/index.css": "@assistant-ui/react-ui/styles/index.css",
|
|
72
|
+
"@assistant-ui/react/styles/modal.css": "@assistant-ui/react-ui/styles/modal.css",
|
|
73
|
+
"@assistant-ui/react-markdown/styles/markdown.css": "@assistant-ui/react-ui/styles/markdown.css"
|
|
74
|
+
};
|
|
75
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
76
|
+
const sourceValue = path.value.source.value;
|
|
77
|
+
if (cssReplacements[sourceValue]) {
|
|
78
|
+
path.value.source = j.literal(cssReplacements[sourceValue]);
|
|
79
|
+
markAsChanged();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
let removedMarkdownPlugin = false;
|
|
83
|
+
root.find(j.CallExpression, { callee: { name: "require" } }).filter((path) => {
|
|
84
|
+
const arg = path.value.arguments[0];
|
|
85
|
+
return arg && (arg.type === "Literal" || arg.type === "StringLiteral") && arg.value === "@assistant-ui/react-markdown/tailwindcss";
|
|
86
|
+
}).forEach((path) => {
|
|
87
|
+
removedMarkdownPlugin = true;
|
|
88
|
+
const parent = path.parentPath;
|
|
89
|
+
if (parent?.value && parent.value.type === "VariableDeclarator") {
|
|
90
|
+
const varDecl = parent.parentPath;
|
|
91
|
+
if (varDecl?.value.declarations && varDecl.value.declarations.length === 1) j(varDecl).remove();
|
|
92
|
+
else varDecl.value.declarations = varDecl.value.declarations.filter((decl) => decl !== parent.value);
|
|
93
|
+
markAsChanged();
|
|
94
|
+
} else {
|
|
95
|
+
j(path).remove();
|
|
96
|
+
markAsChanged();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
root.find(j.CallExpression, { callee: { name: "require" } }).filter((path) => {
|
|
100
|
+
const arg = path.value.arguments[0];
|
|
101
|
+
return arg && (arg.type === "Literal" || arg.type === "StringLiteral") && arg.value === "@assistant-ui/react/tailwindcss";
|
|
102
|
+
}).forEach((path) => {
|
|
103
|
+
path.value.arguments[0].value = "@assistant-ui/react-ui/tailwindcss";
|
|
104
|
+
markAsChanged();
|
|
105
|
+
if (removedMarkdownPlugin) {
|
|
106
|
+
if (path.parentPath?.value && path.parentPath.value.type === "CallExpression" && path.parentPath.value.arguments.length > 0) {
|
|
107
|
+
const configObj = path.parentPath.value.arguments[0];
|
|
108
|
+
if (configObj && configObj.type === "ObjectExpression") {
|
|
109
|
+
const componentsProp = configObj.properties.find((prop) => {
|
|
110
|
+
return (prop.key.name === "components" || prop.key.value === "components") && prop.value.type === "ArrayExpression";
|
|
111
|
+
});
|
|
112
|
+
if (componentsProp) {
|
|
113
|
+
const componentsArray = componentsProp.value.elements;
|
|
114
|
+
if (!componentsArray.some((el) => el.type === "Literal" && el.value === "markdown")) {
|
|
115
|
+
componentsArray.push(j.literal("markdown"));
|
|
116
|
+
markAsChanged();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
168
123
|
});
|
|
169
|
-
|
|
124
|
+
//#endregion
|
|
125
|
+
export { migrateAssistantUI as default };
|
|
126
|
+
|
|
170
127
|
//# sourceMappingURL=ui-package-split.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-package-split.js","
|
|
1
|
+
{"version":3,"file":"ui-package-split.js","names":[],"sources":["../../../src/codemods/v0-8/ui-package-split.ts"],"sourcesContent":["import { createTransformer } from \"../utils/createTransformer\";\n\nconst reactUIExports: string[] = [\n \"ThreadConfigProvider\",\n \"useThreadConfig\",\n \"ThreadConfig\",\n \"ThreadWelcomeConfig\",\n \"UserMessageConfig\",\n \"AssistantMessageConfig\",\n \"StringsConfig\",\n \"SuggestionConfig\",\n \"ThreadConfigProviderProps\",\n \"AssistantActionBar\",\n \"AssistantMessage\",\n \"AssistantModal\",\n \"BranchPicker\",\n \"Composer\",\n \"MessagePart\",\n \"AttachmentUI\",\n \"EditComposer\",\n \"Thread\",\n \"ThreadList\",\n \"ThreadListItem\",\n \"ThreadWelcome\",\n \"UserMessage\",\n \"makeMarkdownText\",\n \"MakeMarkdownTextProps\",\n \"CodeHeader\",\n];\n\nconst migrateAssistantUI = createTransformer(({ j, root, markAsChanged }) => {\n const sourcesToMigrate: string[] = [\n \"@assistant-ui/react\",\n \"@assistant-ui/react-markdown\",\n ];\n const movedSpecifiers: any[] = [];\n let lastMigratedImportPath: any = null;\n\n root\n .find(j.ImportDeclaration)\n .filter((path: any) => sourcesToMigrate.includes(path.value.source.value))\n .forEach((path: any) => {\n let hadMigratedSpecifiers = false;\n const remainingSpecifiers: any[] = [];\n path.value.specifiers.forEach((specifier: any) => {\n if (\n j.ImportSpecifier.check(specifier) &&\n reactUIExports.includes(specifier.imported.name as string)\n ) {\n movedSpecifiers.push(specifier);\n hadMigratedSpecifiers = true;\n } else {\n remainingSpecifiers.push(specifier);\n }\n });\n if (hadMigratedSpecifiers) {\n lastMigratedImportPath = path;\n }\n if (remainingSpecifiers.length === 0) {\n j(path).remove();\n markAsChanged();\n } else if (remainingSpecifiers.length !== path.value.specifiers.length) {\n path.value.specifiers = remainingSpecifiers;\n markAsChanged();\n }\n });\n\n if (movedSpecifiers.length > 0) {\n const existingReactUIImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-ui\" },\n });\n if (existingReactUIImport.size() > 0) {\n existingReactUIImport.forEach((path: any) => {\n movedSpecifiers.forEach((specifier: any) => {\n if (\n !path.value.specifiers.some(\n (s: any) => s.imported.name === specifier.imported.name,\n )\n ) {\n path.value.specifiers.push(specifier);\n }\n });\n });\n } else {\n const newImport = j.importDeclaration(\n movedSpecifiers,\n j.literal(\"@assistant-ui/react-ui\"),\n );\n if (lastMigratedImportPath) {\n j(lastMigratedImportPath).insertAfter(newImport);\n } else {\n const firstImport = root.find(j.ImportDeclaration).at(0);\n if (firstImport.size() > 0) {\n firstImport.insertBefore(newImport);\n } else {\n root.get().node.program.body.unshift(newImport);\n }\n }\n }\n markAsChanged();\n }\n\n const cssReplacements: Record<string, string> = {\n \"@assistant-ui/react/styles/index.css\":\n \"@assistant-ui/react-ui/styles/index.css\",\n \"@assistant-ui/react/styles/modal.css\":\n \"@assistant-ui/react-ui/styles/modal.css\",\n \"@assistant-ui/react-markdown/styles/markdown.css\":\n \"@assistant-ui/react-ui/styles/markdown.css\",\n };\n\n root.find(j.ImportDeclaration).forEach((path: any) => {\n const sourceValue: string = path.value.source.value;\n if (cssReplacements[sourceValue]) {\n path.value.source = j.literal(cssReplacements[sourceValue]);\n markAsChanged();\n }\n });\n\n let removedMarkdownPlugin = false;\n root\n .find(j.CallExpression, { callee: { name: \"require\" } })\n .filter((path: any) => {\n const arg = path.value.arguments[0];\n return (\n arg &&\n (arg.type === \"Literal\" || arg.type === \"StringLiteral\") &&\n arg.value === \"@assistant-ui/react-markdown/tailwindcss\"\n );\n })\n .forEach((path: any) => {\n removedMarkdownPlugin = true;\n const parent = path.parentPath;\n if (parent?.value && parent.value.type === \"VariableDeclarator\") {\n const varDecl = parent.parentPath;\n if (\n varDecl?.value.declarations &&\n varDecl.value.declarations.length === 1\n ) {\n j(varDecl).remove();\n } else {\n varDecl.value.declarations = varDecl.value.declarations.filter(\n (decl: any) => decl !== parent.value,\n );\n }\n markAsChanged();\n } else {\n j(path).remove();\n markAsChanged();\n }\n });\n\n root\n .find(j.CallExpression, { callee: { name: \"require\" } })\n .filter((path: any) => {\n const arg = path.value.arguments[0];\n return (\n arg &&\n (arg.type === \"Literal\" || arg.type === \"StringLiteral\") &&\n arg.value === \"@assistant-ui/react/tailwindcss\"\n );\n })\n .forEach((path: any) => {\n path.value.arguments[0].value = \"@assistant-ui/react-ui/tailwindcss\";\n markAsChanged();\n if (removedMarkdownPlugin) {\n if (\n path.parentPath?.value &&\n path.parentPath.value.type === \"CallExpression\" &&\n path.parentPath.value.arguments.length > 0\n ) {\n const configObj = path.parentPath.value.arguments[0];\n if (configObj && configObj.type === \"ObjectExpression\") {\n const componentsProp = configObj.properties.find((prop: any) => {\n return (\n (prop.key.name === \"components\" ||\n prop.key.value === \"components\") &&\n prop.value.type === \"ArrayExpression\"\n );\n });\n if (componentsProp) {\n const componentsArray = componentsProp.value.elements;\n const hasMarkdown = componentsArray.some(\n (el: any) => el.type === \"Literal\" && el.value === \"markdown\",\n );\n if (!hasMarkdown) {\n componentsArray.push(j.literal(\"markdown\"));\n markAsChanged();\n }\n }\n }\n }\n }\n });\n});\n\nexport default migrateAssistantUI;\n"],"mappings":";;AAEA,MAAM,iBAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,qBAAqB,mBAAmB,EAAE,GAAG,MAAM,oBAAoB;CAC3E,MAAM,mBAA6B,CACjC,uBACA,8BACF;CACA,MAAM,kBAAyB,CAAC;CAChC,IAAI,yBAA8B;CAElC,KACG,KAAK,EAAE,iBAAiB,EACxB,QAAQ,SAAc,iBAAiB,SAAS,KAAK,MAAM,OAAO,KAAK,CAAC,EACxE,SAAS,SAAc;EACtB,IAAI,wBAAwB;EAC5B,MAAM,sBAA6B,CAAC;EACpC,KAAK,MAAM,WAAW,SAAS,cAAmB;GAChD,IACE,EAAE,gBAAgB,MAAM,SAAS,KACjC,eAAe,SAAS,UAAU,SAAS,IAAc,GACzD;IACA,gBAAgB,KAAK,SAAS;IAC9B,wBAAwB;GAC1B,OACE,oBAAoB,KAAK,SAAS;EAEtC,CAAC;EACD,IAAI,uBACF,yBAAyB;EAE3B,IAAI,oBAAoB,WAAW,GAAG;GACpC,EAAE,IAAI,EAAE,OAAO;GACf,cAAc;EAChB,OAAO,IAAI,oBAAoB,WAAW,KAAK,MAAM,WAAW,QAAQ;GACtE,KAAK,MAAM,aAAa;GACxB,cAAc;EAChB;CACF,CAAC;CAEH,IAAI,gBAAgB,S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import("jscodeshift/src/core").FileInfo, api: import("jscodeshift/src/core").API, options: any) => string | null;
|
|
2
|
-
|
|
3
|
+
//#endregion
|
|
4
|
+
export { migrateToEdgePackage as default };
|
|
3
5
|
//# sourceMappingURL=edge-package-split.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-package-split.d.ts","
|
|
1
|
+
{"version":3,"file":"edge-package-split.d.ts","names":[],"sources":["../../../src/codemods/v0-9/edge-package-split.ts"],"mappings":";cA8BM,oBAAA,GAAoB,QAAA,iCAAA,QAAA,EAAA,GAAA,iCAAA,GAAA,EAAA,OAAA"}
|
|
@@ -1,146 +1,102 @@
|
|
|
1
1
|
import { createTransformer } from "../utils/createTransformer.js";
|
|
2
|
-
|
|
2
|
+
//#region src/codemods/v0-9/edge-package-split.ts
|
|
3
3
|
const reactAiSdkExports = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"toLanguageModelTools",
|
|
22
|
-
"fromLanguageModelMessages",
|
|
23
|
-
"fromLanguageModelTools",
|
|
24
|
-
"useDangerousInBrowserRuntime",
|
|
4
|
+
"useChatRuntime",
|
|
5
|
+
"CoreMessage",
|
|
6
|
+
"CoreUserMessage",
|
|
7
|
+
"CoreAssistantMessage",
|
|
8
|
+
"CoreSystemMessage",
|
|
9
|
+
"CoreUserMessagePart",
|
|
10
|
+
"CoreAssistantMessagePart",
|
|
11
|
+
"CoreToolCallMessagePart",
|
|
12
|
+
"fromCoreMessages",
|
|
13
|
+
"fromCoreMessage",
|
|
14
|
+
"toCoreMessages",
|
|
15
|
+
"toCoreMessage",
|
|
16
|
+
"toLanguageModelMessages",
|
|
17
|
+
"toLanguageModelTools",
|
|
18
|
+
"fromLanguageModelMessages",
|
|
19
|
+
"fromLanguageModelTools",
|
|
20
|
+
"useDangerousInBrowserRuntime"
|
|
25
21
|
];
|
|
26
22
|
const migrateToEdgePackage = createTransformer(({ j, root, markAsChanged }) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (sourceValue === "@assistant-ui/react-edge" ||
|
|
103
|
-
sourceValue === "@assistant-ui/react") {
|
|
104
|
-
let hasLanguageModelConverters = false;
|
|
105
|
-
const remainingSpecifiers = [];
|
|
106
|
-
const aiSdkSpecifiers = [];
|
|
107
|
-
path.value.specifiers.forEach((specifier) => {
|
|
108
|
-
if (j.ImportSpecifier.check(specifier) &&
|
|
109
|
-
reactAiSdkExports.includes(specifier.imported.name)) {
|
|
110
|
-
aiSdkSpecifiers.push(specifier);
|
|
111
|
-
hasLanguageModelConverters = true;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
remainingSpecifiers.push(specifier);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
if (hasLanguageModelConverters) {
|
|
118
|
-
if (remainingSpecifiers.length === 0) {
|
|
119
|
-
j(path).remove();
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
path.value.specifiers = remainingSpecifiers;
|
|
123
|
-
}
|
|
124
|
-
const existingAiSdkImport = root.find(j.ImportDeclaration, {
|
|
125
|
-
source: { value: "@assistant-ui/react-ai-sdk" },
|
|
126
|
-
});
|
|
127
|
-
if (existingAiSdkImport.size() > 0) {
|
|
128
|
-
existingAiSdkImport.forEach((importPath) => {
|
|
129
|
-
aiSdkSpecifiers.forEach((specifier) => {
|
|
130
|
-
if (!importPath.value.specifiers.some((s) => s.imported.name === specifier.imported.name)) {
|
|
131
|
-
importPath.value.specifiers.push(specifier);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
const newImport = j.importDeclaration(aiSdkSpecifiers, j.literal("@assistant-ui/react-ai-sdk"));
|
|
138
|
-
j(path).insertAfter(newImport);
|
|
139
|
-
}
|
|
140
|
-
markAsChanged();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
23
|
+
const sourcesToMigrate = ["@assistant-ui/react"];
|
|
24
|
+
const movedAiSdkSpecifiers = [];
|
|
25
|
+
let lastMigratedImportPath = null;
|
|
26
|
+
root.find(j.ImportDeclaration).filter((path) => sourcesToMigrate.includes(path.value.source.value)).forEach((path) => {
|
|
27
|
+
let hadMigratedSpecifiers = false;
|
|
28
|
+
const remainingSpecifiers = [];
|
|
29
|
+
path.value.specifiers.forEach((specifier) => {
|
|
30
|
+
if (j.ImportSpecifier.check(specifier) && reactAiSdkExports.includes(specifier.imported.name)) {
|
|
31
|
+
movedAiSdkSpecifiers.push(specifier);
|
|
32
|
+
hadMigratedSpecifiers = true;
|
|
33
|
+
} else remainingSpecifiers.push(specifier);
|
|
34
|
+
});
|
|
35
|
+
if (hadMigratedSpecifiers) lastMigratedImportPath = path;
|
|
36
|
+
if (remainingSpecifiers.length === 0) {
|
|
37
|
+
j(path).remove();
|
|
38
|
+
markAsChanged();
|
|
39
|
+
} else if (remainingSpecifiers.length !== path.value.specifiers.length) {
|
|
40
|
+
path.value.specifiers = remainingSpecifiers;
|
|
41
|
+
markAsChanged();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (movedAiSdkSpecifiers.length > 0) {
|
|
45
|
+
const existingAiSdkImport = root.find(j.ImportDeclaration, { source: { value: "@assistant-ui/react-ai-sdk" } });
|
|
46
|
+
if (existingAiSdkImport.size() > 0) existingAiSdkImport.forEach((path) => {
|
|
47
|
+
movedAiSdkSpecifiers.forEach((specifier) => {
|
|
48
|
+
if (!path.value.specifiers.some((s) => s.imported.name === specifier.imported.name)) path.value.specifiers.push(specifier);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
else {
|
|
52
|
+
const newImport = j.importDeclaration(movedAiSdkSpecifiers, j.literal("@assistant-ui/react-ai-sdk"));
|
|
53
|
+
if (lastMigratedImportPath) j(lastMigratedImportPath).insertAfter(newImport);
|
|
54
|
+
else {
|
|
55
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
56
|
+
if (firstImport.size() > 0) firstImport.insertBefore(newImport);
|
|
57
|
+
else root.get().node.program.body.unshift(newImport);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
markAsChanged();
|
|
61
|
+
}
|
|
62
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
63
|
+
const sourceValue = path.value.source.value;
|
|
64
|
+
if (sourceValue.startsWith("@assistant-ui/react/") && (sourceValue.includes("edge/") || sourceValue.includes("dangerous-in-browser/"))) {
|
|
65
|
+
path.value.source = j.literal(sourceValue.replace("@assistant-ui/react/", "@assistant-ui/react-ai-sdk/"));
|
|
66
|
+
markAsChanged();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
70
|
+
const sourceValue = path.value.source.value;
|
|
71
|
+
if (sourceValue === "@assistant-ui/react-edge" || sourceValue === "@assistant-ui/react") {
|
|
72
|
+
let hasLanguageModelConverters = false;
|
|
73
|
+
const remainingSpecifiers = [];
|
|
74
|
+
const aiSdkSpecifiers = [];
|
|
75
|
+
path.value.specifiers.forEach((specifier) => {
|
|
76
|
+
if (j.ImportSpecifier.check(specifier) && reactAiSdkExports.includes(specifier.imported.name)) {
|
|
77
|
+
aiSdkSpecifiers.push(specifier);
|
|
78
|
+
hasLanguageModelConverters = true;
|
|
79
|
+
} else remainingSpecifiers.push(specifier);
|
|
80
|
+
});
|
|
81
|
+
if (hasLanguageModelConverters) {
|
|
82
|
+
if (remainingSpecifiers.length === 0) j(path).remove();
|
|
83
|
+
else path.value.specifiers = remainingSpecifiers;
|
|
84
|
+
const existingAiSdkImport = root.find(j.ImportDeclaration, { source: { value: "@assistant-ui/react-ai-sdk" } });
|
|
85
|
+
if (existingAiSdkImport.size() > 0) existingAiSdkImport.forEach((importPath) => {
|
|
86
|
+
aiSdkSpecifiers.forEach((specifier) => {
|
|
87
|
+
if (!importPath.value.specifiers.some((s) => s.imported.name === specifier.imported.name)) importPath.value.specifiers.push(specifier);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
else {
|
|
91
|
+
const newImport = j.importDeclaration(aiSdkSpecifiers, j.literal("@assistant-ui/react-ai-sdk"));
|
|
92
|
+
j(path).insertAfter(newImport);
|
|
93
|
+
}
|
|
94
|
+
markAsChanged();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
144
98
|
});
|
|
145
|
-
|
|
99
|
+
//#endregion
|
|
100
|
+
export { migrateToEdgePackage as default };
|
|
101
|
+
|
|
146
102
|
//# sourceMappingURL=edge-package-split.js.map
|