assistant-ui 0.0.40 → 0.0.41
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/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 +209 -0
- package/dist/codemods/v0-9/edge-package-split.js.map +1 -0
- package/dist/codemods/v0-9/edge-package-split.mjs +188 -0
- package/dist/codemods/v0-9/edge-package-split.mjs.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 +121 -0
- package/dist/lib/install-ai-sdk-lib.js.map +1 -0
- package/dist/lib/install-ai-sdk-lib.mjs +90 -0
- package/dist/lib/install-ai-sdk-lib.mjs.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 +121 -0
- package/dist/lib/install-edge-lib.js.map +1 -0
- package/dist/lib/install-edge-lib.mjs +90 -0
- package/dist/lib/install-edge-lib.mjs.map +1 -0
- package/dist/lib/transform.d.ts +11 -0
- package/dist/lib/transform.d.ts.map +1 -1
- package/dist/lib/transform.js +67 -22
- package/dist/lib/transform.js.map +1 -1
- package/dist/lib/transform.mjs +66 -23
- package/dist/lib/transform.mjs.map +1 -1
- package/dist/lib/upgrade.d.ts +1 -2
- package/dist/lib/upgrade.d.ts.map +1 -1
- package/dist/lib/upgrade.js +30 -6
- package/dist/lib/upgrade.js.map +1 -1
- package/dist/lib/upgrade.mjs +31 -7
- package/dist/lib/upgrade.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge-package-split.d.ts","sourceRoot":"","sources":["../../../src/codemods/v0-9/edge-package-split.ts"],"names":[],"mappings":"AAqCA,QAAA,MAAM,oBAAoB,6HA0LxB,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/codemods/v0-9/edge-package-split.ts
|
|
21
|
+
var edge_package_split_exports = {};
|
|
22
|
+
__export(edge_package_split_exports, {
|
|
23
|
+
default: () => edge_package_split_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(edge_package_split_exports);
|
|
26
|
+
var import_createTransformer = require("../utils/createTransformer.js");
|
|
27
|
+
var reactEdgeExports = [
|
|
28
|
+
// Edge Runtime
|
|
29
|
+
"useEdgeRuntime",
|
|
30
|
+
"EdgeRuntimeOptions",
|
|
31
|
+
"EdgeModelAdapter",
|
|
32
|
+
"EdgeChatAdapter",
|
|
33
|
+
"EdgeRuntimeRequestOptions",
|
|
34
|
+
"createEdgeRuntimeAPI",
|
|
35
|
+
"getEdgeRuntimeResponse",
|
|
36
|
+
// Core Types
|
|
37
|
+
"CoreMessage",
|
|
38
|
+
"CoreUserMessage",
|
|
39
|
+
"CoreAssistantMessage",
|
|
40
|
+
"CoreSystemMessage",
|
|
41
|
+
"CoreUserContentPart",
|
|
42
|
+
"CoreAssistantContentPart",
|
|
43
|
+
"CoreToolCallContentPart",
|
|
44
|
+
// Core message converters
|
|
45
|
+
"fromCoreMessages",
|
|
46
|
+
"fromCoreMessage",
|
|
47
|
+
"toCoreMessages",
|
|
48
|
+
"toCoreMessage"
|
|
49
|
+
];
|
|
50
|
+
var reactAiSdkExports = [
|
|
51
|
+
"toLanguageModelMessages",
|
|
52
|
+
"toLanguageModelTools",
|
|
53
|
+
"fromLanguageModelMessages",
|
|
54
|
+
"fromLanguageModelTools",
|
|
55
|
+
"useDangerousInBrowserRuntime"
|
|
56
|
+
];
|
|
57
|
+
var migrateToEdgePackage = (0, import_createTransformer.createTransformer)(({ j, root, markAsChanged }) => {
|
|
58
|
+
const sourcesToMigrate = ["@assistant-ui/react"];
|
|
59
|
+
const movedEdgeSpecifiers = [];
|
|
60
|
+
const movedAiSdkSpecifiers = [];
|
|
61
|
+
let lastMigratedImportPath = null;
|
|
62
|
+
root.find(j.ImportDeclaration).filter((path) => sourcesToMigrate.includes(path.value.source.value)).forEach((path) => {
|
|
63
|
+
let hadMigratedSpecifiers = false;
|
|
64
|
+
const remainingSpecifiers = [];
|
|
65
|
+
path.value.specifiers.forEach((specifier) => {
|
|
66
|
+
if (j.ImportSpecifier.check(specifier) && reactEdgeExports.includes(specifier.imported.name)) {
|
|
67
|
+
movedEdgeSpecifiers.push(specifier);
|
|
68
|
+
hadMigratedSpecifiers = true;
|
|
69
|
+
} else if (j.ImportSpecifier.check(specifier) && reactAiSdkExports.includes(specifier.imported.name)) {
|
|
70
|
+
movedAiSdkSpecifiers.push(specifier);
|
|
71
|
+
hadMigratedSpecifiers = true;
|
|
72
|
+
} else {
|
|
73
|
+
remainingSpecifiers.push(specifier);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (hadMigratedSpecifiers) {
|
|
77
|
+
lastMigratedImportPath = path;
|
|
78
|
+
}
|
|
79
|
+
if (remainingSpecifiers.length === 0) {
|
|
80
|
+
j(path).remove();
|
|
81
|
+
markAsChanged();
|
|
82
|
+
} else if (remainingSpecifiers.length !== path.value.specifiers.length) {
|
|
83
|
+
path.value.specifiers = remainingSpecifiers;
|
|
84
|
+
markAsChanged();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (movedEdgeSpecifiers.length > 0) {
|
|
88
|
+
const existingEdgeImport = root.find(j.ImportDeclaration, {
|
|
89
|
+
source: { value: "@assistant-ui/react-edge" }
|
|
90
|
+
});
|
|
91
|
+
if (existingEdgeImport.size() > 0) {
|
|
92
|
+
existingEdgeImport.forEach((path) => {
|
|
93
|
+
movedEdgeSpecifiers.forEach((specifier) => {
|
|
94
|
+
if (!path.value.specifiers.some(
|
|
95
|
+
(s) => s.imported.name === specifier.imported.name
|
|
96
|
+
)) {
|
|
97
|
+
path.value.specifiers.push(specifier);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
const newImport = j.importDeclaration(
|
|
103
|
+
movedEdgeSpecifiers,
|
|
104
|
+
j.literal("@assistant-ui/react-edge")
|
|
105
|
+
);
|
|
106
|
+
if (lastMigratedImportPath) {
|
|
107
|
+
j(lastMigratedImportPath).insertAfter(newImport);
|
|
108
|
+
} else {
|
|
109
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
110
|
+
if (firstImport.size() > 0) {
|
|
111
|
+
firstImport.insertBefore(newImport);
|
|
112
|
+
} else {
|
|
113
|
+
root.get().node.program.body.unshift(newImport);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
markAsChanged();
|
|
118
|
+
}
|
|
119
|
+
if (movedAiSdkSpecifiers.length > 0) {
|
|
120
|
+
const existingAiSdkImport = root.find(j.ImportDeclaration, {
|
|
121
|
+
source: { value: "@assistant-ui/react-ai-sdk" }
|
|
122
|
+
});
|
|
123
|
+
if (existingAiSdkImport.size() > 0) {
|
|
124
|
+
existingAiSdkImport.forEach((path) => {
|
|
125
|
+
movedAiSdkSpecifiers.forEach((specifier) => {
|
|
126
|
+
if (!path.value.specifiers.some(
|
|
127
|
+
(s) => s.imported.name === specifier.imported.name
|
|
128
|
+
)) {
|
|
129
|
+
path.value.specifiers.push(specifier);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
const newImport = j.importDeclaration(
|
|
135
|
+
movedAiSdkSpecifiers,
|
|
136
|
+
j.literal("@assistant-ui/react-ai-sdk")
|
|
137
|
+
);
|
|
138
|
+
if (lastMigratedImportPath) {
|
|
139
|
+
j(lastMigratedImportPath).insertAfter(newImport);
|
|
140
|
+
} else {
|
|
141
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
142
|
+
if (firstImport.size() > 0) {
|
|
143
|
+
firstImport.insertBefore(newImport);
|
|
144
|
+
} else {
|
|
145
|
+
root.get().node.program.body.unshift(newImport);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
markAsChanged();
|
|
150
|
+
}
|
|
151
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
152
|
+
const sourceValue = path.value.source.value;
|
|
153
|
+
if (sourceValue.startsWith("@assistant-ui/react/") && (sourceValue.includes("edge/") || sourceValue.includes("dangerous-in-browser/"))) {
|
|
154
|
+
path.value.source = j.literal(
|
|
155
|
+
sourceValue.replace(
|
|
156
|
+
"@assistant-ui/react/",
|
|
157
|
+
"@assistant-ui/react-edge/"
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
markAsChanged();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
164
|
+
const sourceValue = path.value.source.value;
|
|
165
|
+
if (sourceValue === "@assistant-ui/react-edge") {
|
|
166
|
+
let hasLanguageModelConverters = false;
|
|
167
|
+
const remainingSpecifiers = [];
|
|
168
|
+
const aiSdkSpecifiers = [];
|
|
169
|
+
path.value.specifiers.forEach((specifier) => {
|
|
170
|
+
if (j.ImportSpecifier.check(specifier) && reactAiSdkExports.includes(specifier.imported.name)) {
|
|
171
|
+
aiSdkSpecifiers.push(specifier);
|
|
172
|
+
hasLanguageModelConverters = true;
|
|
173
|
+
} else {
|
|
174
|
+
remainingSpecifiers.push(specifier);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (hasLanguageModelConverters) {
|
|
178
|
+
if (remainingSpecifiers.length === 0) {
|
|
179
|
+
j(path).remove();
|
|
180
|
+
} else {
|
|
181
|
+
path.value.specifiers = remainingSpecifiers;
|
|
182
|
+
}
|
|
183
|
+
const existingAiSdkImport = root.find(j.ImportDeclaration, {
|
|
184
|
+
source: { value: "@assistant-ui/react-ai-sdk" }
|
|
185
|
+
});
|
|
186
|
+
if (existingAiSdkImport.size() > 0) {
|
|
187
|
+
existingAiSdkImport.forEach((importPath) => {
|
|
188
|
+
aiSdkSpecifiers.forEach((specifier) => {
|
|
189
|
+
if (!importPath.value.specifiers.some(
|
|
190
|
+
(s) => s.imported.name === specifier.imported.name
|
|
191
|
+
)) {
|
|
192
|
+
importPath.value.specifiers.push(specifier);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
const newImport = j.importDeclaration(
|
|
198
|
+
aiSdkSpecifiers,
|
|
199
|
+
j.literal("@assistant-ui/react-ai-sdk")
|
|
200
|
+
);
|
|
201
|
+
j(path).insertAfter(newImport);
|
|
202
|
+
}
|
|
203
|
+
markAsChanged();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
var edge_package_split_default = migrateToEdgePackage;
|
|
209
|
+
//# sourceMappingURL=edge-package-split.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/codemods/v0-9/edge-package-split.ts"],"sourcesContent":["import { createTransformer } from \"../utils/createTransformer\";\n\nconst reactEdgeExports: string[] = [\n // Edge Runtime\n \"useEdgeRuntime\",\n \"EdgeRuntimeOptions\",\n \"EdgeModelAdapter\",\n \"EdgeChatAdapter\",\n \"EdgeRuntimeRequestOptions\",\n \"createEdgeRuntimeAPI\",\n \"getEdgeRuntimeResponse\",\n\n // Core Types\n \"CoreMessage\",\n \"CoreUserMessage\",\n \"CoreAssistantMessage\",\n \"CoreSystemMessage\",\n \"CoreUserContentPart\",\n \"CoreAssistantContentPart\",\n \"CoreToolCallContentPart\",\n\n // Core message converters\n \"fromCoreMessages\",\n \"fromCoreMessage\",\n \"toCoreMessages\",\n \"toCoreMessage\",\n];\n\n// Language model converters to be moved to react-ai-sdk\nconst reactAiSdkExports: string[] = [\n \"toLanguageModelMessages\",\n \"toLanguageModelTools\",\n \"fromLanguageModelMessages\",\n \"fromLanguageModelTools\",\n \"useDangerousInBrowserRuntime\",\n];\n\nconst migrateToEdgePackage = createTransformer(({ j, root, markAsChanged }) => {\n const sourcesToMigrate: string[] = [\"@assistant-ui/react\"];\n const movedEdgeSpecifiers: any[] = [];\n const movedAiSdkSpecifiers: 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 reactEdgeExports.includes(specifier.imported.name as string)\n ) {\n movedEdgeSpecifiers.push(specifier);\n hadMigratedSpecifiers = true;\n } else if (\n j.ImportSpecifier.check(specifier) &&\n reactAiSdkExports.includes(specifier.imported.name as string)\n ) {\n movedAiSdkSpecifiers.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 // Add imports for react-edge\n if (movedEdgeSpecifiers.length > 0) {\n const existingEdgeImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-edge\" },\n });\n if (existingEdgeImport.size() > 0) {\n existingEdgeImport.forEach((path: any) => {\n movedEdgeSpecifiers.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 movedEdgeSpecifiers,\n j.literal(\"@assistant-ui/react-edge\"),\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 // Add imports for react-ai-sdk\n if (movedAiSdkSpecifiers.length > 0) {\n const existingAiSdkImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-ai-sdk\" },\n });\n if (existingAiSdkImport.size() > 0) {\n existingAiSdkImport.forEach((path: any) => {\n movedAiSdkSpecifiers.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 movedAiSdkSpecifiers,\n j.literal(\"@assistant-ui/react-ai-sdk\"),\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 // Migrate imports from edge/converters\n root.find(j.ImportDeclaration).forEach((path: any) => {\n const sourceValue: string = path.value.source.value;\n if (\n sourceValue.startsWith(\"@assistant-ui/react/\") &&\n (sourceValue.includes(\"edge/\") ||\n sourceValue.includes(\"dangerous-in-browser/\"))\n ) {\n path.value.source = j.literal(\n sourceValue.replace(\n \"@assistant-ui/react/\",\n \"@assistant-ui/react-edge/\",\n ),\n );\n markAsChanged();\n }\n });\n\n // Migrate language model converter imports from react-edge to react-ai-sdk\n root.find(j.ImportDeclaration).forEach((path: any) => {\n const sourceValue: string = path.value.source.value;\n if (sourceValue === \"@assistant-ui/react-edge\") {\n let hasLanguageModelConverters = false;\n const remainingSpecifiers: any[] = [];\n const aiSdkSpecifiers: any[] = [];\n\n path.value.specifiers.forEach((specifier: any) => {\n if (\n j.ImportSpecifier.check(specifier) &&\n reactAiSdkExports.includes(specifier.imported.name as string)\n ) {\n aiSdkSpecifiers.push(specifier);\n hasLanguageModelConverters = true;\n } else {\n remainingSpecifiers.push(specifier);\n }\n });\n\n if (hasLanguageModelConverters) {\n if (remainingSpecifiers.length === 0) {\n j(path).remove();\n } else {\n path.value.specifiers = remainingSpecifiers;\n }\n\n const existingAiSdkImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-ai-sdk\" },\n });\n\n if (existingAiSdkImport.size() > 0) {\n existingAiSdkImport.forEach((importPath: any) => {\n aiSdkSpecifiers.forEach((specifier: any) => {\n if (\n !importPath.value.specifiers.some(\n (s: any) => s.imported.name === specifier.imported.name,\n )\n ) {\n importPath.value.specifiers.push(specifier);\n }\n });\n });\n } else {\n const newImport = j.importDeclaration(\n aiSdkSpecifiers,\n j.literal(\"@assistant-ui/react-ai-sdk\"),\n );\n j(path).insertAfter(newImport);\n }\n\n markAsChanged();\n }\n }\n });\n});\n\nexport default migrateToEdgePackage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA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AAC9B,uCAA6B;AAAA,QAC/B,OAAO;AACL,8BAAoB,KAAK,SAAS;AAAA,QACpC;AAAA,MACF,CAAC;AAED,UAAI,4BAA4B;AAC9B,YAAI,oBAAoB,WAAW,GAAG;AACpC,YAAE,IAAI,EAAE,OAAO;AAAA,QACjB,OAAO;AACL,eAAK,MAAM,aAAa;AAAA,QAC1B;AAEA,cAAM,sBAAsB,KAAK,KAAK,EAAE,mBAAmB;AAAA,UACzD,QAAQ,EAAE,OAAO,6BAA6B;AAAA,QAChD,CAAC;AAED,YAAI,oBAAoB,KAAK,IAAI,GAAG;AAClC,8BAAoB,QAAQ,CAAC,eAAoB;AAC/C,4BAAgB,QAAQ,CAAC,cAAmB;AAC1C,kBACE,CAAC,WAAW,MAAM,WAAW;AAAA,gBAC3B,CAAC,MAAW,EAAE,SAAS,SAAS,UAAU,SAAS;AAAA,cACrD,GACA;AACA,2BAAW,MAAM,WAAW,KAAK,SAAS;AAAA,cAC5C;AAAA,YACF,CAAC;AAAA,UACH,CAAC;AAAA,QACH,OAAO;AACL,gBAAM,YAAY,EAAE;AAAA,YAClB;AAAA,YACA,EAAE,QAAQ,4BAA4B;AAAA,UACxC;AACA,YAAE,IAAI,EAAE,YAAY,SAAS;AAAA,QAC/B;AAEA,sBAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;AAED,IAAO,6BAAQ;","names":[]}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// src/codemods/v0-9/edge-package-split.ts
|
|
2
|
+
import { createTransformer } from "../utils/createTransformer.mjs";
|
|
3
|
+
var reactEdgeExports = [
|
|
4
|
+
// Edge Runtime
|
|
5
|
+
"useEdgeRuntime",
|
|
6
|
+
"EdgeRuntimeOptions",
|
|
7
|
+
"EdgeModelAdapter",
|
|
8
|
+
"EdgeChatAdapter",
|
|
9
|
+
"EdgeRuntimeRequestOptions",
|
|
10
|
+
"createEdgeRuntimeAPI",
|
|
11
|
+
"getEdgeRuntimeResponse",
|
|
12
|
+
// Core Types
|
|
13
|
+
"CoreMessage",
|
|
14
|
+
"CoreUserMessage",
|
|
15
|
+
"CoreAssistantMessage",
|
|
16
|
+
"CoreSystemMessage",
|
|
17
|
+
"CoreUserContentPart",
|
|
18
|
+
"CoreAssistantContentPart",
|
|
19
|
+
"CoreToolCallContentPart",
|
|
20
|
+
// Core message converters
|
|
21
|
+
"fromCoreMessages",
|
|
22
|
+
"fromCoreMessage",
|
|
23
|
+
"toCoreMessages",
|
|
24
|
+
"toCoreMessage"
|
|
25
|
+
];
|
|
26
|
+
var reactAiSdkExports = [
|
|
27
|
+
"toLanguageModelMessages",
|
|
28
|
+
"toLanguageModelTools",
|
|
29
|
+
"fromLanguageModelMessages",
|
|
30
|
+
"fromLanguageModelTools",
|
|
31
|
+
"useDangerousInBrowserRuntime"
|
|
32
|
+
];
|
|
33
|
+
var migrateToEdgePackage = createTransformer(({ j, root, markAsChanged }) => {
|
|
34
|
+
const sourcesToMigrate = ["@assistant-ui/react"];
|
|
35
|
+
const movedEdgeSpecifiers = [];
|
|
36
|
+
const movedAiSdkSpecifiers = [];
|
|
37
|
+
let lastMigratedImportPath = null;
|
|
38
|
+
root.find(j.ImportDeclaration).filter((path) => sourcesToMigrate.includes(path.value.source.value)).forEach((path) => {
|
|
39
|
+
let hadMigratedSpecifiers = false;
|
|
40
|
+
const remainingSpecifiers = [];
|
|
41
|
+
path.value.specifiers.forEach((specifier) => {
|
|
42
|
+
if (j.ImportSpecifier.check(specifier) && reactEdgeExports.includes(specifier.imported.name)) {
|
|
43
|
+
movedEdgeSpecifiers.push(specifier);
|
|
44
|
+
hadMigratedSpecifiers = true;
|
|
45
|
+
} else if (j.ImportSpecifier.check(specifier) && reactAiSdkExports.includes(specifier.imported.name)) {
|
|
46
|
+
movedAiSdkSpecifiers.push(specifier);
|
|
47
|
+
hadMigratedSpecifiers = true;
|
|
48
|
+
} else {
|
|
49
|
+
remainingSpecifiers.push(specifier);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (hadMigratedSpecifiers) {
|
|
53
|
+
lastMigratedImportPath = path;
|
|
54
|
+
}
|
|
55
|
+
if (remainingSpecifiers.length === 0) {
|
|
56
|
+
j(path).remove();
|
|
57
|
+
markAsChanged();
|
|
58
|
+
} else if (remainingSpecifiers.length !== path.value.specifiers.length) {
|
|
59
|
+
path.value.specifiers = remainingSpecifiers;
|
|
60
|
+
markAsChanged();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (movedEdgeSpecifiers.length > 0) {
|
|
64
|
+
const existingEdgeImport = root.find(j.ImportDeclaration, {
|
|
65
|
+
source: { value: "@assistant-ui/react-edge" }
|
|
66
|
+
});
|
|
67
|
+
if (existingEdgeImport.size() > 0) {
|
|
68
|
+
existingEdgeImport.forEach((path) => {
|
|
69
|
+
movedEdgeSpecifiers.forEach((specifier) => {
|
|
70
|
+
if (!path.value.specifiers.some(
|
|
71
|
+
(s) => s.imported.name === specifier.imported.name
|
|
72
|
+
)) {
|
|
73
|
+
path.value.specifiers.push(specifier);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
const newImport = j.importDeclaration(
|
|
79
|
+
movedEdgeSpecifiers,
|
|
80
|
+
j.literal("@assistant-ui/react-edge")
|
|
81
|
+
);
|
|
82
|
+
if (lastMigratedImportPath) {
|
|
83
|
+
j(lastMigratedImportPath).insertAfter(newImport);
|
|
84
|
+
} else {
|
|
85
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
86
|
+
if (firstImport.size() > 0) {
|
|
87
|
+
firstImport.insertBefore(newImport);
|
|
88
|
+
} else {
|
|
89
|
+
root.get().node.program.body.unshift(newImport);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
markAsChanged();
|
|
94
|
+
}
|
|
95
|
+
if (movedAiSdkSpecifiers.length > 0) {
|
|
96
|
+
const existingAiSdkImport = root.find(j.ImportDeclaration, {
|
|
97
|
+
source: { value: "@assistant-ui/react-ai-sdk" }
|
|
98
|
+
});
|
|
99
|
+
if (existingAiSdkImport.size() > 0) {
|
|
100
|
+
existingAiSdkImport.forEach((path) => {
|
|
101
|
+
movedAiSdkSpecifiers.forEach((specifier) => {
|
|
102
|
+
if (!path.value.specifiers.some(
|
|
103
|
+
(s) => s.imported.name === specifier.imported.name
|
|
104
|
+
)) {
|
|
105
|
+
path.value.specifiers.push(specifier);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
const newImport = j.importDeclaration(
|
|
111
|
+
movedAiSdkSpecifiers,
|
|
112
|
+
j.literal("@assistant-ui/react-ai-sdk")
|
|
113
|
+
);
|
|
114
|
+
if (lastMigratedImportPath) {
|
|
115
|
+
j(lastMigratedImportPath).insertAfter(newImport);
|
|
116
|
+
} else {
|
|
117
|
+
const firstImport = root.find(j.ImportDeclaration).at(0);
|
|
118
|
+
if (firstImport.size() > 0) {
|
|
119
|
+
firstImport.insertBefore(newImport);
|
|
120
|
+
} else {
|
|
121
|
+
root.get().node.program.body.unshift(newImport);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
markAsChanged();
|
|
126
|
+
}
|
|
127
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
128
|
+
const sourceValue = path.value.source.value;
|
|
129
|
+
if (sourceValue.startsWith("@assistant-ui/react/") && (sourceValue.includes("edge/") || sourceValue.includes("dangerous-in-browser/"))) {
|
|
130
|
+
path.value.source = j.literal(
|
|
131
|
+
sourceValue.replace(
|
|
132
|
+
"@assistant-ui/react/",
|
|
133
|
+
"@assistant-ui/react-edge/"
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
markAsChanged();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
root.find(j.ImportDeclaration).forEach((path) => {
|
|
140
|
+
const sourceValue = path.value.source.value;
|
|
141
|
+
if (sourceValue === "@assistant-ui/react-edge") {
|
|
142
|
+
let hasLanguageModelConverters = false;
|
|
143
|
+
const remainingSpecifiers = [];
|
|
144
|
+
const aiSdkSpecifiers = [];
|
|
145
|
+
path.value.specifiers.forEach((specifier) => {
|
|
146
|
+
if (j.ImportSpecifier.check(specifier) && reactAiSdkExports.includes(specifier.imported.name)) {
|
|
147
|
+
aiSdkSpecifiers.push(specifier);
|
|
148
|
+
hasLanguageModelConverters = true;
|
|
149
|
+
} else {
|
|
150
|
+
remainingSpecifiers.push(specifier);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (hasLanguageModelConverters) {
|
|
154
|
+
if (remainingSpecifiers.length === 0) {
|
|
155
|
+
j(path).remove();
|
|
156
|
+
} else {
|
|
157
|
+
path.value.specifiers = remainingSpecifiers;
|
|
158
|
+
}
|
|
159
|
+
const existingAiSdkImport = root.find(j.ImportDeclaration, {
|
|
160
|
+
source: { value: "@assistant-ui/react-ai-sdk" }
|
|
161
|
+
});
|
|
162
|
+
if (existingAiSdkImport.size() > 0) {
|
|
163
|
+
existingAiSdkImport.forEach((importPath) => {
|
|
164
|
+
aiSdkSpecifiers.forEach((specifier) => {
|
|
165
|
+
if (!importPath.value.specifiers.some(
|
|
166
|
+
(s) => s.imported.name === specifier.imported.name
|
|
167
|
+
)) {
|
|
168
|
+
importPath.value.specifiers.push(specifier);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
const newImport = j.importDeclaration(
|
|
174
|
+
aiSdkSpecifiers,
|
|
175
|
+
j.literal("@assistant-ui/react-ai-sdk")
|
|
176
|
+
);
|
|
177
|
+
j(path).insertAfter(newImport);
|
|
178
|
+
}
|
|
179
|
+
markAsChanged();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
var edge_package_split_default = migrateToEdgePackage;
|
|
185
|
+
export {
|
|
186
|
+
edge_package_split_default as default
|
|
187
|
+
};
|
|
188
|
+
//# sourceMappingURL=edge-package-split.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/codemods/v0-9/edge-package-split.ts"],"sourcesContent":["import { createTransformer } from \"../utils/createTransformer\";\n\nconst reactEdgeExports: string[] = [\n // Edge Runtime\n \"useEdgeRuntime\",\n \"EdgeRuntimeOptions\",\n \"EdgeModelAdapter\",\n \"EdgeChatAdapter\",\n \"EdgeRuntimeRequestOptions\",\n \"createEdgeRuntimeAPI\",\n \"getEdgeRuntimeResponse\",\n\n // Core Types\n \"CoreMessage\",\n \"CoreUserMessage\",\n \"CoreAssistantMessage\",\n \"CoreSystemMessage\",\n \"CoreUserContentPart\",\n \"CoreAssistantContentPart\",\n \"CoreToolCallContentPart\",\n\n // Core message converters\n \"fromCoreMessages\",\n \"fromCoreMessage\",\n \"toCoreMessages\",\n \"toCoreMessage\",\n];\n\n// Language model converters to be moved to react-ai-sdk\nconst reactAiSdkExports: string[] = [\n \"toLanguageModelMessages\",\n \"toLanguageModelTools\",\n \"fromLanguageModelMessages\",\n \"fromLanguageModelTools\",\n \"useDangerousInBrowserRuntime\",\n];\n\nconst migrateToEdgePackage = createTransformer(({ j, root, markAsChanged }) => {\n const sourcesToMigrate: string[] = [\"@assistant-ui/react\"];\n const movedEdgeSpecifiers: any[] = [];\n const movedAiSdkSpecifiers: 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 reactEdgeExports.includes(specifier.imported.name as string)\n ) {\n movedEdgeSpecifiers.push(specifier);\n hadMigratedSpecifiers = true;\n } else if (\n j.ImportSpecifier.check(specifier) &&\n reactAiSdkExports.includes(specifier.imported.name as string)\n ) {\n movedAiSdkSpecifiers.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 // Add imports for react-edge\n if (movedEdgeSpecifiers.length > 0) {\n const existingEdgeImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-edge\" },\n });\n if (existingEdgeImport.size() > 0) {\n existingEdgeImport.forEach((path: any) => {\n movedEdgeSpecifiers.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 movedEdgeSpecifiers,\n j.literal(\"@assistant-ui/react-edge\"),\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 // Add imports for react-ai-sdk\n if (movedAiSdkSpecifiers.length > 0) {\n const existingAiSdkImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-ai-sdk\" },\n });\n if (existingAiSdkImport.size() > 0) {\n existingAiSdkImport.forEach((path: any) => {\n movedAiSdkSpecifiers.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 movedAiSdkSpecifiers,\n j.literal(\"@assistant-ui/react-ai-sdk\"),\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 // Migrate imports from edge/converters\n root.find(j.ImportDeclaration).forEach((path: any) => {\n const sourceValue: string = path.value.source.value;\n if (\n sourceValue.startsWith(\"@assistant-ui/react/\") &&\n (sourceValue.includes(\"edge/\") ||\n sourceValue.includes(\"dangerous-in-browser/\"))\n ) {\n path.value.source = j.literal(\n sourceValue.replace(\n \"@assistant-ui/react/\",\n \"@assistant-ui/react-edge/\",\n ),\n );\n markAsChanged();\n }\n });\n\n // Migrate language model converter imports from react-edge to react-ai-sdk\n root.find(j.ImportDeclaration).forEach((path: any) => {\n const sourceValue: string = path.value.source.value;\n if (sourceValue === \"@assistant-ui/react-edge\") {\n let hasLanguageModelConverters = false;\n const remainingSpecifiers: any[] = [];\n const aiSdkSpecifiers: any[] = [];\n\n path.value.specifiers.forEach((specifier: any) => {\n if (\n j.ImportSpecifier.check(specifier) &&\n reactAiSdkExports.includes(specifier.imported.name as string)\n ) {\n aiSdkSpecifiers.push(specifier);\n hasLanguageModelConverters = true;\n } else {\n remainingSpecifiers.push(specifier);\n }\n });\n\n if (hasLanguageModelConverters) {\n if (remainingSpecifiers.length === 0) {\n j(path).remove();\n } else {\n path.value.specifiers = remainingSpecifiers;\n }\n\n const existingAiSdkImport = root.find(j.ImportDeclaration, {\n source: { value: \"@assistant-ui/react-ai-sdk\" },\n });\n\n if (existingAiSdkImport.size() > 0) {\n existingAiSdkImport.forEach((importPath: any) => {\n aiSdkSpecifiers.forEach((specifier: any) => {\n if (\n !importPath.value.specifiers.some(\n (s: any) => s.imported.name === specifier.imported.name,\n )\n ) {\n importPath.value.specifiers.push(specifier);\n }\n });\n });\n } else {\n const newImport = j.importDeclaration(\n aiSdkSpecifiers,\n j.literal(\"@assistant-ui/react-ai-sdk\"),\n );\n j(path).insertAfter(newImport);\n }\n\n markAsChanged();\n }\n }\n });\n});\n\n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,GAC5D;AACA,0BAAgB,KAAK,SAAS;AAC9B,uCAA6B;AAAA,QAC/B,OAAO;AACL,8BAAoB,KAAK,SAAS;AAAA,QACpC;AAAA,MACF,CAAC;AAED,UAAI,4BAA4B;AAC9B,YAAI,oBAAoB,WAAW,GAAG;AACpC,YAAE,IAAI,EAAE,OAAO;AAAA,QACjB,OAAO;AACL,eAAK,MAAM,aAAa;AAAA,QAC1B;AAEA,cAAM,sBAAsB,KAAK,KAAK,EAAE,mBAAmB;AAAA,UACzD,QAAQ,EAAE,OAAO,6BAA6B;AAAA,QAChD,CAAC;AAED,YAAI,oBAAoB,KAAK,IAAI,GAAG;AAClC,8BAAoB,QAAQ,CAAC,eAAoB;AAC/C,4BAAgB,QAAQ,CAAC,cAAmB;AAC1C,kBACE,CAAC,WAAW,MAAM,WAAW;AAAA,gBAC3B,CAAC,MAAW,EAAE,SAAS,SAAS,UAAU,SAAS;AAAA,cACrD,GACA;AACA,2BAAW,MAAM,WAAW,KAAK,SAAS;AAAA,cAC5C;AAAA,YACF,CAAC;AAAA,UACH,CAAC;AAAA,QACH,OAAO;AACL,gBAAM,YAAY,EAAE;AAAA,YAClB;AAAA,YACA,EAAE,QAAQ,4BAA4B;AAAA,UACxC;AACA,YAAE,IAAI,EAAE,YAAY,SAAS;AAAA,QAC/B;AAEA,sBAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;AAED,IAAO,6BAAQ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-ai-sdk-lib.d.ts","sourceRoot":"","sources":["../../src/lib/install-ai-sdk-lib.ts"],"names":[],"mappings":"AAuCA,wBAA8B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAoD7D"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/lib/install-ai-sdk-lib.ts
|
|
31
|
+
var install_ai_sdk_lib_exports = {};
|
|
32
|
+
__export(install_ai_sdk_lib_exports, {
|
|
33
|
+
default: () => installAiSdkLib
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(install_ai_sdk_lib_exports);
|
|
36
|
+
var fs = __toESM(require("fs"));
|
|
37
|
+
var path = __toESM(require("path"));
|
|
38
|
+
var import_child_process = require("child_process");
|
|
39
|
+
var import_glob = require("glob");
|
|
40
|
+
var readline = __toESM(require("readline"));
|
|
41
|
+
var import_detect_package_manager = require("detect-package-manager");
|
|
42
|
+
function askQuestion(query) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout
|
|
47
|
+
});
|
|
48
|
+
rl.question(query, (answer) => {
|
|
49
|
+
rl.close();
|
|
50
|
+
resolve(answer);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function isPackageInstalled(pkg) {
|
|
55
|
+
const cwd = process.cwd();
|
|
56
|
+
try {
|
|
57
|
+
const pkgJsonPath = path.join(cwd, "package.json");
|
|
58
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
59
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
60
|
+
const deps = pkgJson.dependencies || {};
|
|
61
|
+
const devDeps = pkgJson.devDependencies || {};
|
|
62
|
+
if (deps[pkg] || devDeps[pkg]) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
}
|
|
68
|
+
const modulePath = path.join(cwd, "node_modules", ...pkg.split("/"));
|
|
69
|
+
return fs.existsSync(modulePath);
|
|
70
|
+
}
|
|
71
|
+
async function installAiSdkLib() {
|
|
72
|
+
const cwd = process.cwd();
|
|
73
|
+
const pattern = "**/*.{js,jsx,ts,tsx}";
|
|
74
|
+
const files = (0, import_glob.sync)(pattern, {
|
|
75
|
+
cwd,
|
|
76
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/build/**"]
|
|
77
|
+
});
|
|
78
|
+
let found = false;
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
const fullPath = path.join(cwd, file);
|
|
81
|
+
const content = fs.readFileSync(fullPath, "utf8");
|
|
82
|
+
if (content.includes("@assistant-ui/react-ai-sdk")) {
|
|
83
|
+
found = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (found) {
|
|
88
|
+
if (isPackageInstalled("@assistant-ui/react-ai-sdk")) {
|
|
89
|
+
console.log(
|
|
90
|
+
"@assistant-ui/react-ai-sdk is already installed. Skipping installation."
|
|
91
|
+
);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const answer = await askQuestion(
|
|
95
|
+
"AI SDK imports were added but @assistant-ui/react-ai-sdk is not installed. Do you want to install it? (Y/n) "
|
|
96
|
+
);
|
|
97
|
+
if (answer === "" || answer.toLowerCase().startsWith("y")) {
|
|
98
|
+
const pm = await (0, import_detect_package_manager.detect)();
|
|
99
|
+
let cmd = "";
|
|
100
|
+
if (pm === "yarn") {
|
|
101
|
+
cmd = "yarn add @assistant-ui/react-ai-sdk";
|
|
102
|
+
} else if (pm === "pnpm") {
|
|
103
|
+
cmd = "pnpm add @assistant-ui/react-ai-sdk";
|
|
104
|
+
} else if (pm === "bun") {
|
|
105
|
+
cmd = "bun add @assistant-ui/react-ai-sdk";
|
|
106
|
+
} else {
|
|
107
|
+
cmd = "npm install @assistant-ui/react-ai-sdk";
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
(0, import_child_process.execSync)(cmd, { stdio: "inherit" });
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.error("Installation failed:", e);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
console.log("Skipping installation.");
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
console.log("No AI SDK imports found; skipping installation.");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=install-ai-sdk-lib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/install-ai-sdk-lib.ts"],"sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\nimport { execSync } from \"child_process\";\nimport { sync as globSync } from \"glob\";\nimport * as readline from \"readline\";\nimport { detect } from \"detect-package-manager\";\n\nfunction askQuestion(query: string): Promise<string> {\n return new Promise((resolve) => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n rl.question(query, (answer) => {\n rl.close();\n resolve(answer);\n });\n });\n}\n\nfunction isPackageInstalled(pkg: string): boolean {\n const cwd = process.cwd();\n try {\n const pkgJsonPath = path.join(cwd, \"package.json\");\n if (fs.existsSync(pkgJsonPath)) {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, \"utf8\"));\n const deps = pkgJson.dependencies || {};\n const devDeps = pkgJson.devDependencies || {};\n if (deps[pkg] || devDeps[pkg]) {\n return true;\n }\n }\n } catch (e) {\n // Fall back to node_modules check below.\n }\n const modulePath = path.join(cwd, \"node_modules\", ...pkg.split(\"/\"));\n return fs.existsSync(modulePath);\n}\n\nexport default async function installAiSdkLib(): Promise<void> {\n const cwd = process.cwd();\n const pattern = \"**/*.{js,jsx,ts,tsx}\";\n const files = globSync(pattern, {\n cwd,\n ignore: [\"**/node_modules/**\", \"**/dist/**\", \"**/build/**\"],\n });\n\n let found = false;\n for (const file of files) {\n const fullPath = path.join(cwd, file);\n const content = fs.readFileSync(fullPath, \"utf8\");\n if (content.includes(\"@assistant-ui/react-ai-sdk\")) {\n found = true;\n break;\n }\n }\n\n if (found) {\n if (isPackageInstalled(\"@assistant-ui/react-ai-sdk\")) {\n console.log(\n \"@assistant-ui/react-ai-sdk is already installed. Skipping installation.\",\n );\n return;\n }\n\n const answer = await askQuestion(\n \"AI SDK imports were added but @assistant-ui/react-ai-sdk is not installed. Do you want to install it? (Y/n) \",\n );\n if (answer === \"\" || answer.toLowerCase().startsWith(\"y\")) {\n const pm = await detect();\n let cmd = \"\";\n if (pm === \"yarn\") {\n cmd = \"yarn add @assistant-ui/react-ai-sdk\";\n } else if (pm === \"pnpm\") {\n cmd = \"pnpm add @assistant-ui/react-ai-sdk\";\n } else if (pm === \"bun\") {\n cmd = \"bun add @assistant-ui/react-ai-sdk\";\n } else {\n cmd = \"npm install @assistant-ui/react-ai-sdk\";\n }\n try {\n execSync(cmd, { stdio: \"inherit\" });\n } catch (e) {\n console.error(\"Installation failed:\", e);\n }\n } else {\n console.log(\"Skipping installation.\");\n }\n } else {\n console.log(\"No AI SDK imports found; skipping installation.\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,WAAsB;AACtB,2BAAyB;AACzB,kBAAiC;AACjC,eAA0B;AAC1B,oCAAuB;AAEvB,SAAS,YAAY,OAAgC;AACnD,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,KAAc,yBAAgB;AAAA,MAClC,OAAO,QAAQ;AAAA,MACf,QAAQ,QAAQ;AAAA,IAClB,CAAC;AACD,OAAG,SAAS,OAAO,CAAC,WAAW;AAC7B,SAAG,MAAM;AACT,cAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AACH;AAEA,SAAS,mBAAmB,KAAsB;AAChD,QAAM,MAAM,QAAQ,IAAI;AACxB,MAAI;AACF,UAAM,cAAmB,UAAK,KAAK,cAAc;AACjD,QAAO,cAAW,WAAW,GAAG;AAC9B,YAAM,UAAU,KAAK,MAAS,gBAAa,aAAa,MAAM,CAAC;AAC/D,YAAM,OAAO,QAAQ,gBAAgB,CAAC;AACtC,YAAM,UAAU,QAAQ,mBAAmB,CAAC;AAC5C,UAAI,KAAK,GAAG,KAAK,QAAQ,GAAG,GAAG;AAC7B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,SAAS,GAAG;AAAA,EAEZ;AACA,QAAM,aAAkB,UAAK,KAAK,gBAAgB,GAAG,IAAI,MAAM,GAAG,CAAC;AACnE,SAAU,cAAW,UAAU;AACjC;AAEA,eAAO,kBAAwD;AAC7D,QAAM,MAAM,QAAQ,IAAI;AACxB,QAAM,UAAU;AAChB,QAAM,YAAQ,YAAAA,MAAS,SAAS;AAAA,IAC9B;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