@dainprotocol/cli 1.2.36 → 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 +149 -247
- 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 -335
package/dist/utils.js
CHANGED
|
@@ -1,164 +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.normalizeTunnelPublicUrl = normalizeTunnelPublicUrl;
|
|
57
|
-
exports.parseEnvContent = parseEnvContent;
|
|
58
|
-
exports.getDainConfig = getDainConfig;
|
|
59
|
-
exports.displayTunnelUrl = displayTunnelUrl;
|
|
60
|
-
exports.setupProxy = setupProxy;
|
|
61
|
-
exports.logError = logError;
|
|
62
|
-
exports.logSuccess = logSuccess;
|
|
63
|
-
exports.logInfo = logInfo;
|
|
64
|
-
exports.getStaticFilesPath = getStaticFilesPath;
|
|
65
|
-
exports.extractOrgId = extractOrgId;
|
|
66
|
-
exports.resolveOrgId = resolveOrgId;
|
|
67
|
-
exports.fetchWithTimeout = fetchWithTimeout;
|
|
68
|
-
exports.buildPlatformUrl = buildPlatformUrl;
|
|
69
|
-
exports.validatePlatformConfig = validatePlatformConfig;
|
|
70
|
-
exports.platformRequest = platformRequest;
|
|
71
|
-
exports.createIdempotentCleanup = createIdempotentCleanup;
|
|
72
|
-
var fs_1 = __importDefault(require("fs"));
|
|
73
|
-
var path_1 = __importDefault(require("path"));
|
|
74
|
-
var client_1 = require("@dainprotocol/tunnel/client");
|
|
75
|
-
var ora_1 = __importDefault(require("ora"));
|
|
76
|
-
var chalk_1 = __importDefault(require("chalk"));
|
|
77
|
-
var dotenv_1 = __importDefault(require("dotenv"));
|
|
78
|
-
exports.DEFAULT_TUNNEL_BASE_URL = "wss://tunnel.dain-local.com";
|
|
79
|
-
exports.DEFAULT_PLATFORM_BASE_URL = "https://codegen-deploy-service.dainapp.com";
|
|
80
|
-
exports.DEFAULT_API_BASE_URL = "https://dain-platform-ochre.vercel.app";
|
|
81
|
-
function normalizeBaseUrl(value) {
|
|
82
|
-
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();
|
|
83
12
|
if (!trimmed)
|
|
84
13
|
return trimmed;
|
|
85
14
|
try {
|
|
86
15
|
return new URL(trimmed).toString().replace(/\/+$/, "");
|
|
87
16
|
}
|
|
88
|
-
catch
|
|
17
|
+
catch {
|
|
89
18
|
return trimmed.replace(/\/+$/, "");
|
|
90
19
|
}
|
|
91
20
|
}
|
|
92
|
-
function joinUrl(baseUrl, pathname) {
|
|
93
|
-
return
|
|
21
|
+
export function joinUrl(baseUrl, pathname) {
|
|
22
|
+
return `${normalizeBaseUrl(baseUrl)}/${pathname.replace(/^\/+/, "")}`;
|
|
94
23
|
}
|
|
95
|
-
function normalizeTunnelPublicUrl(tunnelUrl) {
|
|
96
|
-
|
|
24
|
+
export function normalizeTunnelPublicUrl(tunnelUrl) {
|
|
25
|
+
const trimmed = tunnelUrl.trim();
|
|
97
26
|
if (!trimmed)
|
|
98
27
|
return trimmed;
|
|
99
28
|
if (/^https?:\/\//i.test(trimmed))
|
|
100
29
|
return normalizeBaseUrl(trimmed);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return normalizeBaseUrl(
|
|
30
|
+
const likelyLocalhost = /^localhost[:/]|^127\./i.test(trimmed);
|
|
31
|
+
const protocol = likelyLocalhost ? "http://" : "https://";
|
|
32
|
+
return normalizeBaseUrl(`${protocol}${trimmed.replace(/^\/+/, "")}`);
|
|
104
33
|
}
|
|
105
|
-
function parseEnvContent(envContent) {
|
|
106
|
-
return Object.entries(
|
|
107
|
-
.map(
|
|
108
|
-
|
|
109
|
-
return ({ name: name.trim(), value: value });
|
|
110
|
-
})
|
|
111
|
-
.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 !== "");
|
|
112
38
|
}
|
|
113
39
|
function parseDainApiKey(apiKey) {
|
|
114
|
-
if (!
|
|
40
|
+
if (!apiKey?.startsWith("sk_agent_"))
|
|
115
41
|
return null;
|
|
116
|
-
|
|
42
|
+
const parts = apiKey.split("_");
|
|
117
43
|
if (parts.length < 5)
|
|
118
44
|
return null;
|
|
119
|
-
|
|
45
|
+
const isOrgFormat = parts[2] === "org";
|
|
120
46
|
if (isOrgFormat) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
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)
|
|
126
52
|
return null;
|
|
127
|
-
return { agentId
|
|
53
|
+
return { agentId, orgId, secret };
|
|
128
54
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
55
|
+
const agentId = parts[2];
|
|
56
|
+
const orgId = parts[3];
|
|
57
|
+
const secret = parts.slice(4).join("_");
|
|
132
58
|
if (!agentId || !orgId || !secret)
|
|
133
59
|
return null;
|
|
134
|
-
return { agentId
|
|
60
|
+
return { agentId, orgId, secret };
|
|
135
61
|
}
|
|
136
62
|
function loadEnvFiles() {
|
|
137
|
-
|
|
138
|
-
for (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
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 });
|
|
143
68
|
}
|
|
144
69
|
}
|
|
145
70
|
}
|
|
146
|
-
function getDainConfig(configFile) {
|
|
71
|
+
export function getDainConfig(configFile) {
|
|
147
72
|
loadEnvFiles();
|
|
148
|
-
|
|
149
|
-
if (!
|
|
150
|
-
logError(
|
|
73
|
+
const configPath = path.join(process.cwd(), configFile || "dain.json");
|
|
74
|
+
if (!fs.existsSync(configPath)) {
|
|
75
|
+
logError(`Configuration file not found: ${configPath}`);
|
|
151
76
|
process.exit(1);
|
|
152
77
|
}
|
|
153
78
|
try {
|
|
154
|
-
|
|
79
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
155
80
|
if (!config["main-file"])
|
|
156
81
|
throw new Error("Configuration must include 'main-file'");
|
|
157
|
-
config.environment
|
|
158
|
-
config.version
|
|
159
|
-
config["out-dir"]
|
|
160
|
-
config.runtime
|
|
161
|
-
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);
|
|
162
87
|
if (config["platform-base-url"])
|
|
163
88
|
config["platform-base-url"] = normalizeBaseUrl(config["platform-base-url"]);
|
|
164
89
|
if (config["api-base-url"])
|
|
@@ -171,123 +96,106 @@ function getDainConfig(configFile) {
|
|
|
171
96
|
return config;
|
|
172
97
|
}
|
|
173
98
|
catch (error) {
|
|
174
|
-
throw new Error(
|
|
99
|
+
throw new Error(`Error reading or parsing configuration file: ${error}`);
|
|
175
100
|
}
|
|
176
101
|
}
|
|
177
|
-
function displayTunnelUrl(tunnelUrl) {
|
|
178
|
-
console.log(
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
_a = normalizeTunnelPublicUrl;
|
|
221
|
-
return [4 /*yield*/, client_2.start(parseInt(port))];
|
|
222
|
-
case 2:
|
|
223
|
-
tunnelUrl = _a.apply(void 0, [_b.sent()]);
|
|
224
|
-
spinner.succeed("Proxy setup complete");
|
|
225
|
-
return [2 /*return*/, { client: client_2, tunnelUrl: tunnelUrl }];
|
|
226
|
-
case 3:
|
|
227
|
-
error_1 = _b.sent();
|
|
228
|
-
spinner.fail(chalk_1.default.red("Error setting up proxy"));
|
|
229
|
-
console.error(chalk_1.default.red(error_1));
|
|
230
|
-
throw error_1;
|
|
231
|
-
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."));
|
|
232
145
|
}
|
|
233
146
|
});
|
|
234
|
-
|
|
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
|
+
}
|
|
235
156
|
}
|
|
236
|
-
function logError(message, error) {
|
|
237
|
-
console.error(
|
|
157
|
+
export function logError(message, error) {
|
|
158
|
+
console.error(chalk.red(`\nError: ${message}`));
|
|
238
159
|
if (error)
|
|
239
|
-
console.error(
|
|
160
|
+
console.error(chalk.red(error));
|
|
240
161
|
}
|
|
241
|
-
function logSuccess(message) {
|
|
242
|
-
console.log(
|
|
162
|
+
export function logSuccess(message) {
|
|
163
|
+
console.log(chalk.green(`\nSuccess: ${message}`));
|
|
243
164
|
}
|
|
244
|
-
function logInfo(message) {
|
|
245
|
-
console.log(
|
|
165
|
+
export function logInfo(message) {
|
|
166
|
+
console.log(chalk.blue(`\nInfo: ${message}`));
|
|
246
167
|
}
|
|
247
|
-
function getStaticFilesPath() {
|
|
248
|
-
return
|
|
168
|
+
export function getStaticFilesPath() {
|
|
169
|
+
return path.join(process.cwd(), "static");
|
|
249
170
|
}
|
|
250
|
-
function extractOrgId(apiKey) {
|
|
251
|
-
|
|
252
|
-
return ((_a = parseDainApiKey(apiKey)) === null || _a === void 0 ? void 0 : _a.orgId) || "";
|
|
171
|
+
export function extractOrgId(apiKey) {
|
|
172
|
+
return parseDainApiKey(apiKey)?.orgId || "";
|
|
253
173
|
}
|
|
254
|
-
function resolveOrgId(config) {
|
|
174
|
+
export function resolveOrgId(config) {
|
|
255
175
|
return config["org-id"] || process.env.DAIN_ORG_ID || extractOrgId(config["api-key"]);
|
|
256
176
|
}
|
|
257
|
-
function fetchWithTimeout(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
_a.label = 1;
|
|
267
|
-
case 1:
|
|
268
|
-
_a.trys.push([1, , 3, 4]);
|
|
269
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
270
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
271
|
-
case 3:
|
|
272
|
-
clearTimeout(timeoutId);
|
|
273
|
-
return [7 /*endfinally*/];
|
|
274
|
-
case 4: return [2 /*return*/];
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
function buildPlatformUrl(config, orgId, endpoint, overrides) {
|
|
280
|
-
var baseUrl = config["platform-base-url"] || exports.DEFAULT_PLATFORM_BASE_URL;
|
|
281
|
-
var deploymentId = (overrides === null || overrides === void 0 ? void 0 : overrides.deploymentId) || config["deployment-id"];
|
|
282
|
-
var environment = (overrides === null || overrides === void 0 ? void 0 : overrides.environment) || config["environment"];
|
|
283
|
-
var serviceId = (overrides === null || overrides === void 0 ? void 0 : overrides.serviceId) || config["service-id"];
|
|
284
|
-
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
|
+
}
|
|
285
186
|
}
|
|
286
|
-
function
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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"];
|
|
291
199
|
if (!orgId) {
|
|
292
200
|
logError("Org ID not found. Ensure your API key or DAIN_ORG_ID is set.");
|
|
293
201
|
process.exit(1);
|
|
@@ -300,27 +208,21 @@ function validatePlatformConfig(config, overrides) {
|
|
|
300
208
|
logError("API key not found");
|
|
301
209
|
process.exit(1);
|
|
302
210
|
}
|
|
303
|
-
return { config
|
|
211
|
+
return { config, orgId, apiKey, deploymentId, serviceId };
|
|
304
212
|
}
|
|
305
|
-
function platformRequest(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
return [2 /*return*/, fetchWithTimeout(url, {
|
|
316
|
-
method: method,
|
|
317
|
-
headers: { "Content-Type": "application/json", Authorization: "Bearer ".concat(ctx.apiKey) },
|
|
318
|
-
})];
|
|
319
|
-
});
|
|
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}` },
|
|
320
222
|
});
|
|
321
223
|
}
|
|
322
|
-
function createIdempotentCleanup(cleanupFn) {
|
|
323
|
-
|
|
224
|
+
export function createIdempotentCleanup(cleanupFn) {
|
|
225
|
+
let hasRun = false;
|
|
324
226
|
return function idempotentCleanup() {
|
|
325
227
|
if (hasRun)
|
|
326
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",
|