@dainprotocol/cli 1.2.36 → 1.3.1

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/utils.js CHANGED
@@ -1,164 +1,89 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
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 (_a) {
17
+ catch {
89
18
  return trimmed.replace(/\/+$/, "");
90
19
  }
91
20
  }
92
- function joinUrl(baseUrl, pathname) {
93
- return "".concat(normalizeBaseUrl(baseUrl), "/").concat(pathname.replace(/^\/+/, ""));
21
+ export function joinUrl(baseUrl, pathname) {
22
+ return `${normalizeBaseUrl(baseUrl)}/${pathname.replace(/^\/+/, "")}`;
94
23
  }
95
- function normalizeTunnelPublicUrl(tunnelUrl) {
96
- var trimmed = tunnelUrl.trim();
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
- var likelyLocalhost = /^localhost[:/]|^127\./i.test(trimmed);
102
- var protocol = likelyLocalhost ? "http://" : "https://";
103
- return normalizeBaseUrl("".concat(protocol).concat(trimmed.replace(/^\/+/, "")));
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(dotenv_1.default.parse(envContent))
107
- .map(function (_a) {
108
- var name = _a[0], value = _a[1];
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 (!(apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith("sk_agent_")))
40
+ if (!apiKey?.startsWith("sk_agent_"))
115
41
  return null;
116
- var parts = apiKey.split("_");
42
+ const parts = apiKey.split("_");
117
43
  if (parts.length < 5)
118
44
  return null;
119
- var isOrgFormat = parts[2] === "org";
45
+ const isOrgFormat = parts[2] === "org";
120
46
  if (isOrgFormat) {
121
- var orgId_1 = parts[3];
122
- var isAgentKeyword = parts[4] === "agent";
123
- var agentId_1 = parts[5];
124
- var secret_1 = parts.slice(6).join("_");
125
- if (!orgId_1 || !isAgentKeyword || !agentId_1 || !secret_1)
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: agentId_1, orgId: orgId_1, secret: secret_1 };
53
+ return { agentId, orgId, secret };
128
54
  }
129
- var agentId = parts[2];
130
- var orgId = parts[3];
131
- var secret = parts.slice(4).join("_");
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: agentId, orgId: orgId, secret: secret };
60
+ return { agentId, orgId, secret };
135
61
  }
136
62
  function loadEnvFiles() {
137
- var envFiles = [".env.local", ".env", ".env.development", ".env.production"];
138
- for (var _i = 0, envFiles_1 = envFiles; _i < envFiles_1.length; _i++) {
139
- var file = envFiles_1[_i];
140
- var envPath = path_1.default.join(process.cwd(), file);
141
- if (fs_1.default.existsSync(envPath)) {
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
- var configPath = path_1.default.join(process.cwd(), configFile || "dain.json");
149
- if (!fs_1.default.existsSync(configPath)) {
150
- logError("Configuration file not found: ".concat(configPath));
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
- var config = JSON.parse(fs_1.default.readFileSync(configPath, "utf8"));
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 || (config.environment = "development");
158
- config.version || (config.version = "1.0.0");
159
- config["out-dir"] || (config["out-dir"] = "dist");
160
- config.runtime || (config.runtime = "node");
161
- config["tunnel-base-url"] = normalizeBaseUrl(config["tunnel-base-url"] || exports.DEFAULT_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("Error reading or parsing configuration file: ".concat(error));
99
+ throw new Error(`Error reading or parsing configuration file: ${error}`);
175
100
  }
176
101
  }
177
- function displayTunnelUrl(tunnelUrl) {
178
- console.log("\n".concat(chalk_1.default.green("------------------------------------------------------------"), "\n").concat(chalk_1.default.green("Your service is available publicly at:"), "\n").concat(chalk_1.default.cyan.underline(tunnelUrl), "\n\n").concat(chalk_1.default.yellow("This service URL can be connected to by a DAIN client or assistant"), "\n").concat(chalk_1.default.yellow("(such as butterfly in development mode)"), "\n\n").concat(chalk_1.default.red("You should not visit this URL directly"), "\n").concat(chalk_1.default.green("------------------------------------------------------------"), "\n"));
179
- }
180
- function setupProxy(port, apiKey, config) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- var spinner, client_2, tunnelUrl, _a, error_1;
183
- return __generator(this, function (_b) {
184
- switch (_b.label) {
185
- case 0:
186
- spinner = (0, ora_1.default)("Setting up proxy...").start();
187
- _b.label = 1;
188
- case 1:
189
- _b.trys.push([1, 3, , 4]);
190
- client_2 = new client_1.DainTunnel(config["tunnel-base-url"] || exports.DEFAULT_TUNNEL_BASE_URL, apiKey);
191
- // Handle tunnel lifecycle events
192
- client_2.on("disconnected", function () {
193
- console.log(chalk_1.default.yellow("\n⚠ Tunnel disconnected. Attempting to reconnect..."));
194
- });
195
- client_2.on("reconnecting", function (_a) {
196
- var attempt = _a.attempt, delay = _a.delay;
197
- console.log(chalk_1.default.yellow(" Reconnection attempt ".concat(attempt, "/10 in ").concat(Math.round(delay / 1000), "s...")));
198
- });
199
- client_2.on("reconnected", function () {
200
- console.log(chalk_1.default.green("✓ Tunnel reconnected successfully"));
201
- });
202
- client_2.on("error", function (error) {
203
- console.error(chalk_1.default.red("\n\u2717 Tunnel error: ".concat(error.message)));
204
- });
205
- client_2.on("max_reconnect_attempts", function () {
206
- console.error(chalk_1.default.red("\n✗ Tunnel failed to reconnect after 10 attempts."));
207
- console.log(chalk_1.default.yellow(" Resetting and trying again..."));
208
- // Reset and try one more time (resetReconnection added in tunnel 1.1.31)
209
- if (typeof client_2.resetReconnection === "function") {
210
- client_2.resetReconnection();
211
- client_2.start(parseInt(port)).catch(function (err) {
212
- console.error(chalk_1.default.red("\n\u2717 Unable to restore tunnel connection: ".concat(err.message)));
213
- console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
214
- });
215
- }
216
- else {
217
- console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
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(chalk_1.default.red("\nError: ".concat(message)));
157
+ export function logError(message, error) {
158
+ console.error(chalk.red(`\nError: ${message}`));
238
159
  if (error)
239
- console.error(chalk_1.default.red(error));
160
+ console.error(chalk.red(error));
240
161
  }
241
- function logSuccess(message) {
242
- console.log(chalk_1.default.green("\nSuccess: ".concat(message)));
162
+ export function logSuccess(message) {
163
+ console.log(chalk.green(`\nSuccess: ${message}`));
243
164
  }
244
- function logInfo(message) {
245
- console.log(chalk_1.default.blue("\nInfo: ".concat(message)));
165
+ export function logInfo(message) {
166
+ console.log(chalk.blue(`\nInfo: ${message}`));
246
167
  }
247
- function getStaticFilesPath() {
248
- return path_1.default.join(process.cwd(), "static");
168
+ export function getStaticFilesPath() {
169
+ return path.join(process.cwd(), "static");
249
170
  }
250
- function extractOrgId(apiKey) {
251
- var _a;
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(url_1, options_1) {
258
- return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
259
- var controller, timeoutId;
260
- if (timeoutMs === void 0) { timeoutMs = 30000; }
261
- return __generator(this, function (_a) {
262
- switch (_a.label) {
263
- case 0:
264
- controller = new AbortController();
265
- timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
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 validatePlatformConfig(config, overrides) {
287
- var orgId = resolveOrgId(config);
288
- var apiKey = config["api-key"];
289
- var deploymentId = (overrides === null || overrides === void 0 ? void 0 : overrides.deploymentId) || config["deployment-id"];
290
- var serviceId = (overrides === null || overrides === void 0 ? void 0 : overrides.serviceId) || config["service-id"];
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: config, orgId: orgId, apiKey: apiKey, deploymentId: deploymentId, serviceId: serviceId };
211
+ return { config, orgId, apiKey, deploymentId, serviceId };
304
212
  }
305
- function platformRequest(ctx_1, endpoint_1) {
306
- return __awaiter(this, arguments, void 0, function (ctx, endpoint, method, overrides) {
307
- var url;
308
- if (method === void 0) { method = "GET"; }
309
- return __generator(this, function (_a) {
310
- url = buildPlatformUrl(ctx.config, ctx.orgId, endpoint, {
311
- deploymentId: ctx.deploymentId,
312
- serviceId: ctx.serviceId,
313
- environment: overrides === null || overrides === void 0 ? void 0 : overrides.environment,
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
- var hasRun = false;
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,11 +1,12 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.2.36",
3
+ "version": "1.3.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "description": "CLI for Dain Protocol",
9
+ "type": "module",
9
10
  "main": "dist/index.js",
10
11
  "bin": {
11
12
  "dain": "./dist/index.js"
@@ -15,7 +16,7 @@
15
16
  "test": "jest",
16
17
  "test:watch": "jest --watch",
17
18
  "test:coverage": "jest --coverage",
18
- "prepublishOnly": "pnpm run build && pnpm test"
19
+ "prepublishOnly": "pnpm run build"
19
20
  },
20
21
  "files": [
21
22
  "dist",
@@ -23,8 +24,8 @@
23
24
  ],
24
25
  "dependencies": {
25
26
  "@ai-sdk/anthropic": "^0.0.50",
26
- "@dainprotocol/service-sdk": "2.0.82",
27
- "@dainprotocol/tunnel": "1.1.35",
27
+ "@dainprotocol/service-sdk": "2.0.88",
28
+ "@dainprotocol/tunnel": "2.0.0",
28
29
  "@types/fs-extra": "^11.0.4",
29
30
  "@types/localtunnel": "^2.0.4",
30
31
  "ai": "^3.3.41",