@dainprotocol/cli 1.2.34 → 1.3.0
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/commands/build.d.ts +9 -0
- package/dist/commands/build.js +108 -260
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.js +37 -96
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.js +123 -267
- package/dist/commands/dev.d.ts +6 -0
- package/dist/commands/dev.js +202 -314
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +28 -31
- package/dist/commands/logs.d.ts +4 -0
- package/dist/commands/logs.js +53 -143
- package/dist/commands/start.d.ts +3 -0
- package/dist/commands/start.js +16 -22
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.js +26 -83
- package/dist/commands/testchat.d.ts +5 -0
- package/dist/commands/testchat.js +82 -197
- package/dist/commands/undeploy.d.ts +3 -0
- package/dist/commands/undeploy.js +18 -74
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -38
- package/dist/templates/default/package.json +1 -1
- package/dist/templates/default/tsconfig.json +3 -3
- package/dist/utils.d.ts +62 -0
- package/dist/utils.js +154 -240
- package/package.json +3 -3
- package/dist/__tests__/build.test.js +0 -289
- package/dist/__tests__/deploy.test.js +0 -126
- package/dist/__tests__/dev.test.js +0 -321
- package/dist/__tests__/init.test.js +0 -290
- package/dist/__tests__/integration.test.js +0 -134
- package/dist/__tests__/logs.test.js +0 -135
- package/dist/__tests__/testchat.test.js +0 -214
- package/dist/__tests__/utils.test.js +0 -324
package/dist/utils.js
CHANGED
|
@@ -1,153 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.DEFAULT_API_BASE_URL = exports.DEFAULT_PLATFORM_BASE_URL = exports.DEFAULT_TUNNEL_BASE_URL = void 0;
|
|
54
|
-
exports.normalizeBaseUrl = normalizeBaseUrl;
|
|
55
|
-
exports.joinUrl = joinUrl;
|
|
56
|
-
exports.parseEnvContent = parseEnvContent;
|
|
57
|
-
exports.getDainConfig = getDainConfig;
|
|
58
|
-
exports.displayTunnelUrl = displayTunnelUrl;
|
|
59
|
-
exports.setupProxy = setupProxy;
|
|
60
|
-
exports.logError = logError;
|
|
61
|
-
exports.logSuccess = logSuccess;
|
|
62
|
-
exports.logInfo = logInfo;
|
|
63
|
-
exports.getStaticFilesPath = getStaticFilesPath;
|
|
64
|
-
exports.extractOrgId = extractOrgId;
|
|
65
|
-
exports.resolveOrgId = resolveOrgId;
|
|
66
|
-
exports.fetchWithTimeout = fetchWithTimeout;
|
|
67
|
-
exports.buildPlatformUrl = buildPlatformUrl;
|
|
68
|
-
exports.validatePlatformConfig = validatePlatformConfig;
|
|
69
|
-
exports.platformRequest = platformRequest;
|
|
70
|
-
exports.createIdempotentCleanup = createIdempotentCleanup;
|
|
71
|
-
var fs_1 = __importDefault(require("fs"));
|
|
72
|
-
var path_1 = __importDefault(require("path"));
|
|
73
|
-
var client_1 = require("@dainprotocol/tunnel/client");
|
|
74
|
-
var ora_1 = __importDefault(require("ora"));
|
|
75
|
-
var chalk_1 = __importDefault(require("chalk"));
|
|
76
|
-
var dotenv_1 = __importDefault(require("dotenv"));
|
|
77
|
-
exports.DEFAULT_TUNNEL_BASE_URL = "wss://tunnel.dain-local.com";
|
|
78
|
-
exports.DEFAULT_PLATFORM_BASE_URL = "https://codegen-deploy-service.dainapp.com";
|
|
79
|
-
exports.DEFAULT_API_BASE_URL = "https://dain-platform-ochre.vercel.app";
|
|
80
|
-
function normalizeBaseUrl(value) {
|
|
81
|
-
var trimmed = value.trim();
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { DainTunnel } from "@dainprotocol/tunnel/client";
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import dotenv from "dotenv";
|
|
7
|
+
export const DEFAULT_TUNNEL_BASE_URL = "wss://tunnel.dain-local.com";
|
|
8
|
+
export const DEFAULT_PLATFORM_BASE_URL = "https://codegen-deploy-service.dainapp.com";
|
|
9
|
+
export const DEFAULT_API_BASE_URL = "https://dain-platform-ochre.vercel.app";
|
|
10
|
+
export function normalizeBaseUrl(value) {
|
|
11
|
+
const trimmed = value.trim();
|
|
82
12
|
if (!trimmed)
|
|
83
13
|
return trimmed;
|
|
84
14
|
try {
|
|
85
15
|
return new URL(trimmed).toString().replace(/\/+$/, "");
|
|
86
16
|
}
|
|
87
|
-
catch
|
|
17
|
+
catch {
|
|
88
18
|
return trimmed.replace(/\/+$/, "");
|
|
89
19
|
}
|
|
90
20
|
}
|
|
91
|
-
function joinUrl(baseUrl, pathname) {
|
|
92
|
-
return
|
|
21
|
+
export function joinUrl(baseUrl, pathname) {
|
|
22
|
+
return `${normalizeBaseUrl(baseUrl)}/${pathname.replace(/^\/+/, "")}`;
|
|
23
|
+
}
|
|
24
|
+
export function normalizeTunnelPublicUrl(tunnelUrl) {
|
|
25
|
+
const trimmed = tunnelUrl.trim();
|
|
26
|
+
if (!trimmed)
|
|
27
|
+
return trimmed;
|
|
28
|
+
if (/^https?:\/\//i.test(trimmed))
|
|
29
|
+
return normalizeBaseUrl(trimmed);
|
|
30
|
+
const likelyLocalhost = /^localhost[:/]|^127\./i.test(trimmed);
|
|
31
|
+
const protocol = likelyLocalhost ? "http://" : "https://";
|
|
32
|
+
return normalizeBaseUrl(`${protocol}${trimmed.replace(/^\/+/, "")}`);
|
|
93
33
|
}
|
|
94
|
-
function parseEnvContent(envContent) {
|
|
95
|
-
return Object.entries(
|
|
96
|
-
.map(
|
|
97
|
-
|
|
98
|
-
return ({ name: name.trim(), value: value });
|
|
99
|
-
})
|
|
100
|
-
.filter(function (env) { return env.name !== "" && env.value !== ""; });
|
|
34
|
+
export function parseEnvContent(envContent) {
|
|
35
|
+
return Object.entries(dotenv.parse(envContent))
|
|
36
|
+
.map(([name, value]) => ({ name: name.trim(), value }))
|
|
37
|
+
.filter((env) => env.name !== "" && env.value !== "");
|
|
101
38
|
}
|
|
102
39
|
function parseDainApiKey(apiKey) {
|
|
103
|
-
if (!
|
|
40
|
+
if (!apiKey?.startsWith("sk_agent_"))
|
|
104
41
|
return null;
|
|
105
|
-
|
|
42
|
+
const parts = apiKey.split("_");
|
|
106
43
|
if (parts.length < 5)
|
|
107
44
|
return null;
|
|
108
|
-
|
|
45
|
+
const isOrgFormat = parts[2] === "org";
|
|
109
46
|
if (isOrgFormat) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (!
|
|
47
|
+
const orgId = parts[3];
|
|
48
|
+
const isAgentKeyword = parts[4] === "agent";
|
|
49
|
+
const agentId = parts[5];
|
|
50
|
+
const secret = parts.slice(6).join("_");
|
|
51
|
+
if (!orgId || !isAgentKeyword || !agentId || !secret)
|
|
115
52
|
return null;
|
|
116
|
-
return { agentId
|
|
53
|
+
return { agentId, orgId, secret };
|
|
117
54
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
55
|
+
const agentId = parts[2];
|
|
56
|
+
const orgId = parts[3];
|
|
57
|
+
const secret = parts.slice(4).join("_");
|
|
121
58
|
if (!agentId || !orgId || !secret)
|
|
122
59
|
return null;
|
|
123
|
-
return { agentId
|
|
60
|
+
return { agentId, orgId, secret };
|
|
124
61
|
}
|
|
125
62
|
function loadEnvFiles() {
|
|
126
|
-
|
|
127
|
-
for (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
dotenv_1.default.config({ path: envPath });
|
|
63
|
+
const envFiles = [".env.local", ".env", ".env.development", ".env.production"];
|
|
64
|
+
for (const file of envFiles) {
|
|
65
|
+
const envPath = path.join(process.cwd(), file);
|
|
66
|
+
if (fs.existsSync(envPath)) {
|
|
67
|
+
dotenv.config({ path: envPath });
|
|
132
68
|
}
|
|
133
69
|
}
|
|
134
70
|
}
|
|
135
|
-
function getDainConfig(configFile) {
|
|
71
|
+
export function getDainConfig(configFile) {
|
|
136
72
|
loadEnvFiles();
|
|
137
|
-
|
|
138
|
-
if (!
|
|
139
|
-
logError(
|
|
73
|
+
const configPath = path.join(process.cwd(), configFile || "dain.json");
|
|
74
|
+
if (!fs.existsSync(configPath)) {
|
|
75
|
+
logError(`Configuration file not found: ${configPath}`);
|
|
140
76
|
process.exit(1);
|
|
141
77
|
}
|
|
142
78
|
try {
|
|
143
|
-
|
|
79
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
144
80
|
if (!config["main-file"])
|
|
145
81
|
throw new Error("Configuration must include 'main-file'");
|
|
146
|
-
config.environment
|
|
147
|
-
config.version
|
|
148
|
-
config["out-dir"]
|
|
149
|
-
config.runtime
|
|
150
|
-
config["tunnel-base-url"] = normalizeBaseUrl(config["tunnel-base-url"] ||
|
|
82
|
+
config.environment ||= "development";
|
|
83
|
+
config.version ||= "1.0.0";
|
|
84
|
+
config["out-dir"] ||= "dist";
|
|
85
|
+
config.runtime ||= "node";
|
|
86
|
+
config["tunnel-base-url"] = normalizeBaseUrl(config["tunnel-base-url"] || DEFAULT_TUNNEL_BASE_URL);
|
|
151
87
|
if (config["platform-base-url"])
|
|
152
88
|
config["platform-base-url"] = normalizeBaseUrl(config["platform-base-url"]);
|
|
153
89
|
if (config["api-base-url"])
|
|
@@ -160,122 +96,106 @@ function getDainConfig(configFile) {
|
|
|
160
96
|
return config;
|
|
161
97
|
}
|
|
162
98
|
catch (error) {
|
|
163
|
-
throw new Error(
|
|
99
|
+
throw new Error(`Error reading or parsing configuration file: ${error}`);
|
|
164
100
|
}
|
|
165
101
|
}
|
|
166
|
-
function displayTunnelUrl(tunnelUrl) {
|
|
167
|
-
console.log(
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return [4 /*yield*/, client_2.start(parseInt(port))];
|
|
210
|
-
case 2:
|
|
211
|
-
tunnelUrl = _a.sent();
|
|
212
|
-
spinner.succeed("Proxy setup complete");
|
|
213
|
-
return [2 /*return*/, { client: client_2, tunnelUrl: tunnelUrl }];
|
|
214
|
-
case 3:
|
|
215
|
-
error_1 = _a.sent();
|
|
216
|
-
spinner.fail(chalk_1.default.red("Error setting up proxy"));
|
|
217
|
-
console.error(chalk_1.default.red(error_1));
|
|
218
|
-
throw error_1;
|
|
219
|
-
case 4: return [2 /*return*/];
|
|
102
|
+
export function displayTunnelUrl(tunnelUrl) {
|
|
103
|
+
console.log(`
|
|
104
|
+
${chalk.green("------------------------------------------------------------")}
|
|
105
|
+
${chalk.green("Your service is available publicly at:")}
|
|
106
|
+
${chalk.cyan.underline(tunnelUrl)}
|
|
107
|
+
|
|
108
|
+
${chalk.yellow("This service URL can be connected to by a DAIN client or assistant")}
|
|
109
|
+
${chalk.yellow("(such as butterfly in development mode)")}
|
|
110
|
+
|
|
111
|
+
${chalk.red("You should not visit this URL directly")}
|
|
112
|
+
${chalk.green("------------------------------------------------------------")}
|
|
113
|
+
`);
|
|
114
|
+
}
|
|
115
|
+
export async function setupProxy(port, apiKey, config) {
|
|
116
|
+
const spinner = ora("Setting up proxy...").start();
|
|
117
|
+
try {
|
|
118
|
+
const client = new DainTunnel(config["tunnel-base-url"] || DEFAULT_TUNNEL_BASE_URL, apiKey);
|
|
119
|
+
// Handle tunnel lifecycle events
|
|
120
|
+
client.on("disconnected", () => {
|
|
121
|
+
console.log(chalk.yellow("\n⚠ Tunnel disconnected. Attempting to reconnect..."));
|
|
122
|
+
});
|
|
123
|
+
client.on("reconnecting", ({ attempt, delay }) => {
|
|
124
|
+
console.log(chalk.yellow(` Reconnection attempt ${attempt}/10 in ${Math.round(delay / 1000)}s...`));
|
|
125
|
+
});
|
|
126
|
+
client.on("reconnected", () => {
|
|
127
|
+
console.log(chalk.green("✓ Tunnel reconnected successfully"));
|
|
128
|
+
});
|
|
129
|
+
client.on("error", (error) => {
|
|
130
|
+
console.error(chalk.red(`\n✗ Tunnel error: ${error.message}`));
|
|
131
|
+
});
|
|
132
|
+
client.on("max_reconnect_attempts", () => {
|
|
133
|
+
console.error(chalk.red("\n✗ Tunnel failed to reconnect after 10 attempts."));
|
|
134
|
+
console.log(chalk.yellow(" Resetting and trying again..."));
|
|
135
|
+
// Reset and try one more time (resetReconnection added in tunnel 1.1.31)
|
|
136
|
+
if (typeof client.resetReconnection === "function") {
|
|
137
|
+
client.resetReconnection();
|
|
138
|
+
client.start(parseInt(port)).catch((err) => {
|
|
139
|
+
console.error(chalk.red(`\n✗ Unable to restore tunnel connection: ${err.message}`));
|
|
140
|
+
console.log(chalk.yellow(" Please restart the dev server manually."));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
console.log(chalk.yellow(" Please restart the dev server manually."));
|
|
220
145
|
}
|
|
221
146
|
});
|
|
222
|
-
|
|
147
|
+
const tunnelUrl = normalizeTunnelPublicUrl(await client.start(parseInt(port)));
|
|
148
|
+
spinner.succeed("Proxy setup complete");
|
|
149
|
+
return { client, tunnelUrl };
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
spinner.fail(chalk.red("Error setting up proxy"));
|
|
153
|
+
console.error(chalk.red(error));
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
223
156
|
}
|
|
224
|
-
function logError(message, error) {
|
|
225
|
-
console.error(
|
|
157
|
+
export function logError(message, error) {
|
|
158
|
+
console.error(chalk.red(`\nError: ${message}`));
|
|
226
159
|
if (error)
|
|
227
|
-
console.error(
|
|
160
|
+
console.error(chalk.red(error));
|
|
228
161
|
}
|
|
229
|
-
function logSuccess(message) {
|
|
230
|
-
console.log(
|
|
162
|
+
export function logSuccess(message) {
|
|
163
|
+
console.log(chalk.green(`\nSuccess: ${message}`));
|
|
231
164
|
}
|
|
232
|
-
function logInfo(message) {
|
|
233
|
-
console.log(
|
|
165
|
+
export function logInfo(message) {
|
|
166
|
+
console.log(chalk.blue(`\nInfo: ${message}`));
|
|
234
167
|
}
|
|
235
|
-
function getStaticFilesPath() {
|
|
236
|
-
return
|
|
168
|
+
export function getStaticFilesPath() {
|
|
169
|
+
return path.join(process.cwd(), "static");
|
|
237
170
|
}
|
|
238
|
-
function extractOrgId(apiKey) {
|
|
239
|
-
|
|
240
|
-
return ((_a = parseDainApiKey(apiKey)) === null || _a === void 0 ? void 0 : _a.orgId) || "";
|
|
171
|
+
export function extractOrgId(apiKey) {
|
|
172
|
+
return parseDainApiKey(apiKey)?.orgId || "";
|
|
241
173
|
}
|
|
242
|
-
function resolveOrgId(config) {
|
|
174
|
+
export function resolveOrgId(config) {
|
|
243
175
|
return config["org-id"] || process.env.DAIN_ORG_ID || extractOrgId(config["api-key"]);
|
|
244
176
|
}
|
|
245
|
-
function fetchWithTimeout(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
_a.label = 1;
|
|
255
|
-
case 1:
|
|
256
|
-
_a.trys.push([1, , 3, 4]);
|
|
257
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
258
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
259
|
-
case 3:
|
|
260
|
-
clearTimeout(timeoutId);
|
|
261
|
-
return [7 /*endfinally*/];
|
|
262
|
-
case 4: return [2 /*return*/];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
function buildPlatformUrl(config, orgId, endpoint, overrides) {
|
|
268
|
-
var baseUrl = config["platform-base-url"] || exports.DEFAULT_PLATFORM_BASE_URL;
|
|
269
|
-
var deploymentId = (overrides === null || overrides === void 0 ? void 0 : overrides.deploymentId) || config["deployment-id"];
|
|
270
|
-
var environment = (overrides === null || overrides === void 0 ? void 0 : overrides.environment) || config["environment"];
|
|
271
|
-
var serviceId = (overrides === null || overrides === void 0 ? void 0 : overrides.serviceId) || config["service-id"];
|
|
272
|
-
return joinUrl(baseUrl, "/codegen-deploy/".concat(endpoint, "/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment));
|
|
177
|
+
export async function fetchWithTimeout(url, options, timeoutMs = 30000) {
|
|
178
|
+
const controller = new AbortController();
|
|
179
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
180
|
+
try {
|
|
181
|
+
return await fetch(url, { ...options, signal: controller.signal });
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
clearTimeout(timeoutId);
|
|
185
|
+
}
|
|
273
186
|
}
|
|
274
|
-
function
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
187
|
+
export function buildPlatformUrl(config, orgId, endpoint, overrides) {
|
|
188
|
+
const baseUrl = config["platform-base-url"] || DEFAULT_PLATFORM_BASE_URL;
|
|
189
|
+
const deploymentId = overrides?.deploymentId || config["deployment-id"];
|
|
190
|
+
const environment = overrides?.environment || config["environment"];
|
|
191
|
+
const serviceId = overrides?.serviceId || config["service-id"];
|
|
192
|
+
return joinUrl(baseUrl, `/codegen-deploy/${endpoint}/${orgId}/${serviceId}/${deploymentId}/${environment}`);
|
|
193
|
+
}
|
|
194
|
+
export function validatePlatformConfig(config, overrides) {
|
|
195
|
+
const orgId = resolveOrgId(config);
|
|
196
|
+
const apiKey = config["api-key"];
|
|
197
|
+
const deploymentId = overrides?.deploymentId || config["deployment-id"];
|
|
198
|
+
const serviceId = overrides?.serviceId || config["service-id"];
|
|
279
199
|
if (!orgId) {
|
|
280
200
|
logError("Org ID not found. Ensure your API key or DAIN_ORG_ID is set.");
|
|
281
201
|
process.exit(1);
|
|
@@ -288,27 +208,21 @@ function validatePlatformConfig(config, overrides) {
|
|
|
288
208
|
logError("API key not found");
|
|
289
209
|
process.exit(1);
|
|
290
210
|
}
|
|
291
|
-
return { config
|
|
211
|
+
return { config, orgId, apiKey, deploymentId, serviceId };
|
|
292
212
|
}
|
|
293
|
-
function platformRequest(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
});
|
|
303
|
-
return [2 /*return*/, fetchWithTimeout(url, {
|
|
304
|
-
method: method,
|
|
305
|
-
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(ctx.apiKey) },
|
|
306
|
-
})];
|
|
307
|
-
});
|
|
213
|
+
export async function platformRequest(ctx, endpoint, method = "GET", overrides) {
|
|
214
|
+
const url = buildPlatformUrl(ctx.config, ctx.orgId, endpoint, {
|
|
215
|
+
deploymentId: ctx.deploymentId,
|
|
216
|
+
serviceId: ctx.serviceId,
|
|
217
|
+
environment: overrides?.environment,
|
|
218
|
+
});
|
|
219
|
+
return fetchWithTimeout(url, {
|
|
220
|
+
method,
|
|
221
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${ctx.apiKey}` },
|
|
308
222
|
});
|
|
309
223
|
}
|
|
310
|
-
function createIdempotentCleanup(cleanupFn) {
|
|
311
|
-
|
|
224
|
+
export function createIdempotentCleanup(cleanupFn) {
|
|
225
|
+
let hasRun = false;
|
|
312
226
|
return function idempotentCleanup() {
|
|
313
227
|
if (hasRun)
|
|
314
228
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dainprotocol/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ai-sdk/anthropic": "^0.0.50",
|
|
26
|
-
"@dainprotocol/service-sdk": "2.0.
|
|
27
|
-
"@dainprotocol/tunnel": "
|
|
26
|
+
"@dainprotocol/service-sdk": "2.0.88",
|
|
27
|
+
"@dainprotocol/tunnel": "2.0.0",
|
|
28
28
|
"@types/fs-extra": "^11.0.4",
|
|
29
29
|
"@types/localtunnel": "^2.0.4",
|
|
30
30
|
"ai": "^3.3.41",
|