@bagelink/workspace 1.8.5 → 1.8.9
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/bin/bgl.cjs +69 -34
- package/dist/bin/bgl.mjs +69 -34
- package/package.json +1 -1
- package/src/sdk.ts +89 -48
package/dist/bin/bgl.cjs
CHANGED
|
@@ -1097,7 +1097,6 @@ async function generateSDK(root = process__default.cwd()) {
|
|
|
1097
1097
|
node_fs.writeFileSync(apiPath, code);
|
|
1098
1098
|
console.log("\u2705 Generated api.ts");
|
|
1099
1099
|
try {
|
|
1100
|
-
const sdkModule = await import('@bagelink/sdk');
|
|
1101
1100
|
const sdkPath = fileURLToPath(undefined("@bagelink/sdk"));
|
|
1102
1101
|
const sdkDir = dirname(sdkPath);
|
|
1103
1102
|
const streamClientSource = join(sdkDir, "openAPITools", "streamClient.ts");
|
|
@@ -1107,15 +1106,16 @@ async function generateSDK(root = process__default.cwd()) {
|
|
|
1107
1106
|
node_fs.writeFileSync(streamClientPath, streamClientCode);
|
|
1108
1107
|
console.log("\u2705 Generated streamClient.ts");
|
|
1109
1108
|
}
|
|
1109
|
+
const streamControllerSource = join(sdkDir, "openAPITools", "StreamController.ts");
|
|
1110
|
+
if (node_fs.existsSync(streamControllerSource)) {
|
|
1111
|
+
const streamControllerCode = readFileSync(streamControllerSource, "utf-8");
|
|
1112
|
+
const streamControllerPath = node_path.resolve(outputPath, "StreamController.ts");
|
|
1113
|
+
node_fs.writeFileSync(streamControllerPath, streamControllerCode);
|
|
1114
|
+
console.log("\u2705 Generated StreamController.ts");
|
|
1115
|
+
}
|
|
1110
1116
|
} catch (e) {
|
|
1111
|
-
console.log("\u2139\uFE0F
|
|
1117
|
+
console.log("\u2139\uFE0F Stream utilities not found (optional)");
|
|
1112
1118
|
}
|
|
1113
|
-
const indexPath = node_path.resolve(outputPath, "index.ts");
|
|
1114
|
-
node_fs.writeFileSync(
|
|
1115
|
-
indexPath,
|
|
1116
|
-
"export * from './api'\nexport * from './types.d'\n"
|
|
1117
|
-
);
|
|
1118
|
-
console.log("\u2705 Generated index.ts");
|
|
1119
1119
|
if (splitFiles) {
|
|
1120
1120
|
console.log("\n\u{1F500} Splitting into organized files...");
|
|
1121
1121
|
console.log("\u2139\uFE0F File splitting requires @bagelink/sdk bin scripts");
|
|
@@ -1123,8 +1123,9 @@ async function generateSDK(root = process__default.cwd()) {
|
|
|
1123
1123
|
}
|
|
1124
1124
|
console.log("\n\u2705 SDK generated successfully!");
|
|
1125
1125
|
console.log(`
|
|
1126
|
-
Import
|
|
1127
|
-
console.log(` import {
|
|
1126
|
+
Import directly in your code:`);
|
|
1127
|
+
console.log(` import { agents } from '${outputDir.replace("./src/", "./")}/api'`);
|
|
1128
|
+
console.log(` import type { SendMessageRequest } from '${outputDir.replace("./src/", "./")}/types.d'`);
|
|
1128
1129
|
console.log("");
|
|
1129
1130
|
} catch (error) {
|
|
1130
1131
|
console.error("\n\u274C Failed to generate SDK:");
|
|
@@ -1141,37 +1142,71 @@ Import it in your code:`);
|
|
|
1141
1142
|
}
|
|
1142
1143
|
}
|
|
1143
1144
|
async function generateSDKForWorkspace(root = process__default.cwd()) {
|
|
1144
|
-
console.log("\n\u{1F3E2} Generating SDK for workspace
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1145
|
+
console.log("\n\u{1F3E2} Generating SDK for workspace...\n");
|
|
1146
|
+
let config = null;
|
|
1147
|
+
let openApiUrl;
|
|
1148
|
+
try {
|
|
1149
|
+
const configPath = node_path.resolve(root, "bgl.config.ts");
|
|
1150
|
+
if (node_fs.existsSync(configPath)) {
|
|
1151
|
+
const module = await import(`file://${configPath}`);
|
|
1152
|
+
const workspace = module.default;
|
|
1153
|
+
if (typeof workspace === "function") {
|
|
1154
|
+
config = workspace("development");
|
|
1155
|
+
if (config?.openapi_url) {
|
|
1156
|
+
openApiUrl = config.openapi_url;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
} catch {
|
|
1153
1161
|
}
|
|
1154
1162
|
const response = await prompts__default({
|
|
1155
|
-
type: "
|
|
1156
|
-
name: "
|
|
1157
|
-
message: "
|
|
1158
|
-
|
|
1163
|
+
type: openApiUrl !== void 0 ? null : "text",
|
|
1164
|
+
name: "openApiUrl",
|
|
1165
|
+
message: "OpenAPI spec URL:",
|
|
1166
|
+
initial: openApiUrl ?? "http://localhost:8000/openapi.json"
|
|
1159
1167
|
});
|
|
1160
|
-
if (
|
|
1161
|
-
console.log("\n\u274C
|
|
1162
|
-
|
|
1168
|
+
if (response === void 0 || openApiUrl === void 0 && !response.openApiUrl) {
|
|
1169
|
+
console.log("\n\u274C SDK generation cancelled.\n");
|
|
1170
|
+
process__default.exit(1);
|
|
1163
1171
|
}
|
|
1164
|
-
|
|
1172
|
+
const finalUrl = openApiUrl ?? response.openApiUrl;
|
|
1173
|
+
const outputDir = "./shared";
|
|
1174
|
+
console.log(`
|
|
1175
|
+
\u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
|
|
1176
|
+
console.log(`\u{1F4C1} Output directory: ${outputDir}
|
|
1177
|
+
`);
|
|
1178
|
+
try {
|
|
1179
|
+
const { openAPI } = await import('@bagelink/sdk');
|
|
1180
|
+
const { types, code } = await openAPI(finalUrl, "/api");
|
|
1181
|
+
const outputPath = node_path.resolve(root, outputDir);
|
|
1182
|
+
if (!node_fs.existsSync(outputPath)) {
|
|
1183
|
+
node_fs.mkdirSync(outputPath, { recursive: true });
|
|
1184
|
+
}
|
|
1185
|
+
const typesPath = node_path.resolve(outputPath, "types.d.ts");
|
|
1186
|
+
node_fs.writeFileSync(typesPath, types);
|
|
1187
|
+
console.log("\u2705 Generated types.d.ts");
|
|
1188
|
+
const apiPath = node_path.resolve(outputPath, "api.ts");
|
|
1189
|
+
node_fs.writeFileSync(apiPath, code);
|
|
1190
|
+
console.log("\u2705 Generated api.ts");
|
|
1191
|
+
console.log("\n\u2705 SDK generated successfully in shared folder!");
|
|
1165
1192
|
console.log(`
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1193
|
+
Import from shared in your projects:`);
|
|
1194
|
+
console.log(` import { agents } from '../shared/api'`);
|
|
1195
|
+
console.log(` import type { SendMessageRequest } from '../shared/types'`);
|
|
1196
|
+
console.log("");
|
|
1197
|
+
} catch (error) {
|
|
1198
|
+
console.error("\n\u274C Failed to generate SDK:");
|
|
1199
|
+
if (error instanceof Error) {
|
|
1200
|
+
console.error(error.message);
|
|
1201
|
+
} else {
|
|
1202
|
+
console.error(error);
|
|
1172
1203
|
}
|
|
1204
|
+
console.log("\nMake sure:");
|
|
1205
|
+
console.log(" 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk");
|
|
1206
|
+
console.log(" 2. OpenAPI URL is accessible");
|
|
1207
|
+
console.log(" 3. API server is running (if using localhost)");
|
|
1208
|
+
process__default.exit(1);
|
|
1173
1209
|
}
|
|
1174
|
-
console.log("\n\u2705 All SDKs generated!");
|
|
1175
1210
|
}
|
|
1176
1211
|
|
|
1177
1212
|
const [, , command, subcommand, ...args] = process__default.argv;
|
package/dist/bin/bgl.mjs
CHANGED
|
@@ -1090,7 +1090,6 @@ async function generateSDK(root = process.cwd()) {
|
|
|
1090
1090
|
writeFileSync(apiPath, code);
|
|
1091
1091
|
console.log("\u2705 Generated api.ts");
|
|
1092
1092
|
try {
|
|
1093
|
-
const sdkModule = await import('@bagelink/sdk');
|
|
1094
1093
|
const sdkPath = fileURLToPath(import.meta.resolve("@bagelink/sdk"));
|
|
1095
1094
|
const sdkDir = dirname(sdkPath);
|
|
1096
1095
|
const streamClientSource = join(sdkDir, "openAPITools", "streamClient.ts");
|
|
@@ -1100,15 +1099,16 @@ async function generateSDK(root = process.cwd()) {
|
|
|
1100
1099
|
writeFileSync(streamClientPath, streamClientCode);
|
|
1101
1100
|
console.log("\u2705 Generated streamClient.ts");
|
|
1102
1101
|
}
|
|
1102
|
+
const streamControllerSource = join(sdkDir, "openAPITools", "StreamController.ts");
|
|
1103
|
+
if (existsSync(streamControllerSource)) {
|
|
1104
|
+
const streamControllerCode = readFileSync(streamControllerSource, "utf-8");
|
|
1105
|
+
const streamControllerPath = resolve(outputPath, "StreamController.ts");
|
|
1106
|
+
writeFileSync(streamControllerPath, streamControllerCode);
|
|
1107
|
+
console.log("\u2705 Generated StreamController.ts");
|
|
1108
|
+
}
|
|
1103
1109
|
} catch (e) {
|
|
1104
|
-
console.log("\u2139\uFE0F
|
|
1110
|
+
console.log("\u2139\uFE0F Stream utilities not found (optional)");
|
|
1105
1111
|
}
|
|
1106
|
-
const indexPath = resolve(outputPath, "index.ts");
|
|
1107
|
-
writeFileSync(
|
|
1108
|
-
indexPath,
|
|
1109
|
-
"export * from './api'\nexport * from './types.d'\n"
|
|
1110
|
-
);
|
|
1111
|
-
console.log("\u2705 Generated index.ts");
|
|
1112
1112
|
if (splitFiles) {
|
|
1113
1113
|
console.log("\n\u{1F500} Splitting into organized files...");
|
|
1114
1114
|
console.log("\u2139\uFE0F File splitting requires @bagelink/sdk bin scripts");
|
|
@@ -1116,8 +1116,9 @@ async function generateSDK(root = process.cwd()) {
|
|
|
1116
1116
|
}
|
|
1117
1117
|
console.log("\n\u2705 SDK generated successfully!");
|
|
1118
1118
|
console.log(`
|
|
1119
|
-
Import
|
|
1120
|
-
console.log(` import {
|
|
1119
|
+
Import directly in your code:`);
|
|
1120
|
+
console.log(` import { agents } from '${outputDir.replace("./src/", "./")}/api'`);
|
|
1121
|
+
console.log(` import type { SendMessageRequest } from '${outputDir.replace("./src/", "./")}/types.d'`);
|
|
1121
1122
|
console.log("");
|
|
1122
1123
|
} catch (error) {
|
|
1123
1124
|
console.error("\n\u274C Failed to generate SDK:");
|
|
@@ -1134,37 +1135,71 @@ Import it in your code:`);
|
|
|
1134
1135
|
}
|
|
1135
1136
|
}
|
|
1136
1137
|
async function generateSDKForWorkspace(root = process.cwd()) {
|
|
1137
|
-
console.log("\n\u{1F3E2} Generating SDK for workspace
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1138
|
+
console.log("\n\u{1F3E2} Generating SDK for workspace...\n");
|
|
1139
|
+
let config = null;
|
|
1140
|
+
let openApiUrl;
|
|
1141
|
+
try {
|
|
1142
|
+
const configPath = resolve(root, "bgl.config.ts");
|
|
1143
|
+
if (existsSync(configPath)) {
|
|
1144
|
+
const module = await import(`file://${configPath}`);
|
|
1145
|
+
const workspace = module.default;
|
|
1146
|
+
if (typeof workspace === "function") {
|
|
1147
|
+
config = workspace("development");
|
|
1148
|
+
if (config?.openapi_url) {
|
|
1149
|
+
openApiUrl = config.openapi_url;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
} catch {
|
|
1146
1154
|
}
|
|
1147
1155
|
const response = await prompts({
|
|
1148
|
-
type: "
|
|
1149
|
-
name: "
|
|
1150
|
-
message: "
|
|
1151
|
-
|
|
1156
|
+
type: openApiUrl !== void 0 ? null : "text",
|
|
1157
|
+
name: "openApiUrl",
|
|
1158
|
+
message: "OpenAPI spec URL:",
|
|
1159
|
+
initial: openApiUrl ?? "http://localhost:8000/openapi.json"
|
|
1152
1160
|
});
|
|
1153
|
-
if (
|
|
1154
|
-
console.log("\n\u274C
|
|
1155
|
-
|
|
1161
|
+
if (response === void 0 || openApiUrl === void 0 && !response.openApiUrl) {
|
|
1162
|
+
console.log("\n\u274C SDK generation cancelled.\n");
|
|
1163
|
+
process.exit(1);
|
|
1156
1164
|
}
|
|
1157
|
-
|
|
1165
|
+
const finalUrl = openApiUrl ?? response.openApiUrl;
|
|
1166
|
+
const outputDir = "./shared";
|
|
1167
|
+
console.log(`
|
|
1168
|
+
\u{1F4E1} Fetching OpenAPI spec from: ${finalUrl}`);
|
|
1169
|
+
console.log(`\u{1F4C1} Output directory: ${outputDir}
|
|
1170
|
+
`);
|
|
1171
|
+
try {
|
|
1172
|
+
const { openAPI } = await import('@bagelink/sdk');
|
|
1173
|
+
const { types, code } = await openAPI(finalUrl, "/api");
|
|
1174
|
+
const outputPath = resolve(root, outputDir);
|
|
1175
|
+
if (!existsSync(outputPath)) {
|
|
1176
|
+
mkdirSync(outputPath, { recursive: true });
|
|
1177
|
+
}
|
|
1178
|
+
const typesPath = resolve(outputPath, "types.d.ts");
|
|
1179
|
+
writeFileSync(typesPath, types);
|
|
1180
|
+
console.log("\u2705 Generated types.d.ts");
|
|
1181
|
+
const apiPath = resolve(outputPath, "api.ts");
|
|
1182
|
+
writeFileSync(apiPath, code);
|
|
1183
|
+
console.log("\u2705 Generated api.ts");
|
|
1184
|
+
console.log("\n\u2705 SDK generated successfully in shared folder!");
|
|
1158
1185
|
console.log(`
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1186
|
+
Import from shared in your projects:`);
|
|
1187
|
+
console.log(` import { agents } from '../shared/api'`);
|
|
1188
|
+
console.log(` import type { SendMessageRequest } from '../shared/types'`);
|
|
1189
|
+
console.log("");
|
|
1190
|
+
} catch (error) {
|
|
1191
|
+
console.error("\n\u274C Failed to generate SDK:");
|
|
1192
|
+
if (error instanceof Error) {
|
|
1193
|
+
console.error(error.message);
|
|
1194
|
+
} else {
|
|
1195
|
+
console.error(error);
|
|
1165
1196
|
}
|
|
1197
|
+
console.log("\nMake sure:");
|
|
1198
|
+
console.log(" 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk");
|
|
1199
|
+
console.log(" 2. OpenAPI URL is accessible");
|
|
1200
|
+
console.log(" 3. API server is running (if using localhost)");
|
|
1201
|
+
process.exit(1);
|
|
1166
1202
|
}
|
|
1167
|
-
console.log("\n\u2705 All SDKs generated!");
|
|
1168
1203
|
}
|
|
1169
1204
|
|
|
1170
1205
|
const [, , command, subcommand, ...args] = process.argv;
|
package/package.json
CHANGED
package/src/sdk.ts
CHANGED
|
@@ -90,32 +90,33 @@ export async function generateSDK(
|
|
|
90
90
|
writeFileSync(apiPath, code)
|
|
91
91
|
console.log('✅ Generated api.ts')
|
|
92
92
|
|
|
93
|
-
// Copy streamClient
|
|
93
|
+
// Copy streamClient and StreamController from @bagelink/sdk
|
|
94
94
|
try {
|
|
95
|
-
const sdkModule = await import('@bagelink/sdk')
|
|
96
95
|
const sdkPath = fileURLToPath(import.meta.resolve('@bagelink/sdk'))
|
|
97
96
|
const sdkDir = dirname(sdkPath)
|
|
98
|
-
const streamClientSource = join(sdkDir, 'openAPITools', 'streamClient.ts')
|
|
99
97
|
|
|
98
|
+
// Copy streamClient.ts
|
|
99
|
+
const streamClientSource = join(sdkDir, 'openAPITools', 'streamClient.ts')
|
|
100
100
|
if (existsSync(streamClientSource)) {
|
|
101
101
|
const streamClientCode = readFileSync(streamClientSource, 'utf-8')
|
|
102
102
|
const streamClientPath = resolve(outputPath, 'streamClient.ts')
|
|
103
103
|
writeFileSync(streamClientPath, streamClientCode)
|
|
104
104
|
console.log('✅ Generated streamClient.ts')
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
// Copy StreamController.ts
|
|
108
|
+
const streamControllerSource = join(sdkDir, 'openAPITools', 'StreamController.ts')
|
|
109
|
+
if (existsSync(streamControllerSource)) {
|
|
110
|
+
const streamControllerCode = readFileSync(streamControllerSource, 'utf-8')
|
|
111
|
+
const streamControllerPath = resolve(outputPath, 'StreamController.ts')
|
|
112
|
+
writeFileSync(streamControllerPath, streamControllerCode)
|
|
113
|
+
console.log('✅ Generated StreamController.ts')
|
|
114
|
+
}
|
|
106
115
|
} catch (e) {
|
|
107
116
|
// Stream client is optional, don't fail if not found
|
|
108
|
-
console.log('ℹ️
|
|
117
|
+
console.log('ℹ️ Stream utilities not found (optional)')
|
|
109
118
|
}
|
|
110
119
|
|
|
111
|
-
// Write index
|
|
112
|
-
const indexPath = resolve(outputPath, 'index.ts')
|
|
113
|
-
writeFileSync(
|
|
114
|
-
indexPath,
|
|
115
|
-
'export * from \'./api\'\nexport * from \'./types.d\'\n',
|
|
116
|
-
)
|
|
117
|
-
console.log('✅ Generated index.ts')
|
|
118
|
-
|
|
119
120
|
if (splitFiles) {
|
|
120
121
|
console.log('\n🔀 Splitting into organized files...')
|
|
121
122
|
console.log('ℹ️ File splitting requires @bagelink/sdk bin scripts')
|
|
@@ -125,8 +126,9 @@ export async function generateSDK(
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
console.log('\n✅ SDK generated successfully!')
|
|
128
|
-
console.log(`\nImport
|
|
129
|
-
console.log(` import {
|
|
129
|
+
console.log(`\nImport directly in your code:`)
|
|
130
|
+
console.log(` import { agents } from '${outputDir.replace('./src/', './')}/api'`)
|
|
131
|
+
console.log(` import type { SendMessageRequest } from '${outputDir.replace('./src/', './')}/types.d'`)
|
|
130
132
|
console.log('')
|
|
131
133
|
}
|
|
132
134
|
catch (error: unknown) {
|
|
@@ -149,48 +151,87 @@ export async function generateSDK(
|
|
|
149
151
|
* Generate SDK for all projects in workspace
|
|
150
152
|
*/
|
|
151
153
|
export async function generateSDKForWorkspace(root: string = process.cwd()): Promise<void> {
|
|
152
|
-
console.log('\n🏢 Generating SDK for workspace
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
154
|
+
console.log('\n🏢 Generating SDK for workspace...\n')
|
|
155
|
+
|
|
156
|
+
// Try to load config
|
|
157
|
+
let config: WorkspaceConfig | null = null
|
|
158
|
+
let openApiUrl: string | undefined
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const configPath = resolve(root, 'bgl.config.ts')
|
|
162
|
+
if (existsSync(configPath)) {
|
|
163
|
+
const module = await import(`file://${configPath}`)
|
|
164
|
+
const workspace = module.default
|
|
165
|
+
if (typeof workspace === 'function') {
|
|
166
|
+
config = workspace('development')
|
|
167
|
+
if (config?.openapi_url) {
|
|
168
|
+
openApiUrl = config.openapi_url
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// Ignore config load errors
|
|
170
175
|
}
|
|
171
176
|
|
|
177
|
+
// Prompt for OpenAPI URL if not in config
|
|
172
178
|
const response = await prompts({
|
|
173
|
-
type: '
|
|
174
|
-
name: '
|
|
175
|
-
message: '
|
|
176
|
-
|
|
179
|
+
type: openApiUrl !== undefined ? null : 'text',
|
|
180
|
+
name: 'openApiUrl',
|
|
181
|
+
message: 'OpenAPI spec URL:',
|
|
182
|
+
initial: openApiUrl ?? 'http://localhost:8000/openapi.json',
|
|
177
183
|
})
|
|
178
184
|
|
|
179
|
-
if (
|
|
180
|
-
console.log('\n❌
|
|
181
|
-
|
|
185
|
+
if (response === undefined || (openApiUrl === undefined && !response.openApiUrl)) {
|
|
186
|
+
console.log('\n❌ SDK generation cancelled.\n')
|
|
187
|
+
process.exit(1)
|
|
182
188
|
}
|
|
183
189
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
const finalUrl = openApiUrl ?? response.openApiUrl
|
|
191
|
+
const outputDir = './shared'
|
|
192
|
+
|
|
193
|
+
console.log(`\n📡 Fetching OpenAPI spec from: ${finalUrl}`)
|
|
194
|
+
console.log(`📁 Output directory: ${outputDir}\n`)
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
// Dynamic import of @bagelink/sdk
|
|
198
|
+
const { openAPI } = await import('@bagelink/sdk')
|
|
199
|
+
|
|
200
|
+
const { types, code } = await openAPI(finalUrl, '/api')
|
|
201
|
+
|
|
202
|
+
const outputPath = resolve(root, outputDir)
|
|
203
|
+
if (!existsSync(outputPath)) {
|
|
204
|
+
mkdirSync(outputPath, { recursive: true })
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Write types
|
|
208
|
+
const typesPath = resolve(outputPath, 'types.d.ts')
|
|
209
|
+
writeFileSync(typesPath, types)
|
|
210
|
+
console.log('✅ Generated types.d.ts')
|
|
211
|
+
|
|
212
|
+
// Write API client
|
|
213
|
+
const apiPath = resolve(outputPath, 'api.ts')
|
|
214
|
+
writeFileSync(apiPath, code)
|
|
215
|
+
console.log('✅ Generated api.ts')
|
|
216
|
+
|
|
217
|
+
console.log('\n✅ SDK generated successfully in shared folder!')
|
|
218
|
+
console.log(`\nImport from shared in your projects:`)
|
|
219
|
+
console.log(` import { agents } from '../shared/api'`)
|
|
220
|
+
console.log(` import type { SendMessageRequest } from '../shared/types'`)
|
|
221
|
+
console.log('')
|
|
222
|
+
}
|
|
223
|
+
catch (error: unknown) {
|
|
224
|
+
console.error('\n❌ Failed to generate SDK:')
|
|
225
|
+
if (error instanceof Error) {
|
|
226
|
+
console.error(error.message)
|
|
189
227
|
}
|
|
190
|
-
|
|
191
|
-
console.error(
|
|
228
|
+
else {
|
|
229
|
+
console.error(error)
|
|
192
230
|
}
|
|
231
|
+
console.log('\nMake sure:')
|
|
232
|
+
console.log(' 1. @bagelink/sdk is installed: bun add -D @bagelink/sdk')
|
|
233
|
+
console.log(' 2. OpenAPI URL is accessible')
|
|
234
|
+
console.log(' 3. API server is running (if using localhost)')
|
|
235
|
+
process.exit(1)
|
|
193
236
|
}
|
|
194
|
-
|
|
195
|
-
console.log('\n✅ All SDKs generated!')
|
|
196
237
|
}
|