@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/utils.js CHANGED
@@ -1,153 +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.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 (_a) {
17
+ catch {
88
18
  return trimmed.replace(/\/+$/, "");
89
19
  }
90
20
  }
91
- function joinUrl(baseUrl, pathname) {
92
- return "".concat(normalizeBaseUrl(baseUrl), "/").concat(pathname.replace(/^\/+/, ""));
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(dotenv_1.default.parse(envContent))
96
- .map(function (_a) {
97
- var name = _a[0], value = _a[1];
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 (!(apiKey === null || apiKey === void 0 ? void 0 : apiKey.startsWith("sk_agent_")))
40
+ if (!apiKey?.startsWith("sk_agent_"))
104
41
  return null;
105
- var parts = apiKey.split("_");
42
+ const parts = apiKey.split("_");
106
43
  if (parts.length < 5)
107
44
  return null;
108
- var isOrgFormat = parts[2] === "org";
45
+ const isOrgFormat = parts[2] === "org";
109
46
  if (isOrgFormat) {
110
- var orgId_1 = parts[3];
111
- var isAgentKeyword = parts[4] === "agent";
112
- var agentId_1 = parts[5];
113
- var secret_1 = parts.slice(6).join("_");
114
- 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)
115
52
  return null;
116
- return { agentId: agentId_1, orgId: orgId_1, secret: secret_1 };
53
+ return { agentId, orgId, secret };
117
54
  }
118
- var agentId = parts[2];
119
- var orgId = parts[3];
120
- var secret = parts.slice(4).join("_");
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: agentId, orgId: orgId, secret: secret };
60
+ return { agentId, orgId, secret };
124
61
  }
125
62
  function loadEnvFiles() {
126
- var envFiles = [".env.local", ".env", ".env.development", ".env.production"];
127
- for (var _i = 0, envFiles_1 = envFiles; _i < envFiles_1.length; _i++) {
128
- var file = envFiles_1[_i];
129
- var envPath = path_1.default.join(process.cwd(), file);
130
- if (fs_1.default.existsSync(envPath)) {
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
- var configPath = path_1.default.join(process.cwd(), configFile || "dain.json");
138
- if (!fs_1.default.existsSync(configPath)) {
139
- 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}`);
140
76
  process.exit(1);
141
77
  }
142
78
  try {
143
- var config = JSON.parse(fs_1.default.readFileSync(configPath, "utf8"));
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 || (config.environment = "development");
147
- config.version || (config.version = "1.0.0");
148
- config["out-dir"] || (config["out-dir"] = "dist");
149
- config.runtime || (config.runtime = "node");
150
- 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);
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("Error reading or parsing configuration file: ".concat(error));
99
+ throw new Error(`Error reading or parsing configuration file: ${error}`);
164
100
  }
165
101
  }
166
- function displayTunnelUrl(tunnelUrl) {
167
- 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"));
168
- }
169
- function setupProxy(port, apiKey, config) {
170
- return __awaiter(this, void 0, void 0, function () {
171
- var spinner, client_2, tunnelUrl, error_1;
172
- return __generator(this, function (_a) {
173
- switch (_a.label) {
174
- case 0:
175
- spinner = (0, ora_1.default)("Setting up proxy...").start();
176
- _a.label = 1;
177
- case 1:
178
- _a.trys.push([1, 3, , 4]);
179
- client_2 = new client_1.DainTunnel(config["tunnel-base-url"] || exports.DEFAULT_TUNNEL_BASE_URL, apiKey);
180
- // Handle tunnel lifecycle events
181
- client_2.on("disconnected", function () {
182
- console.log(chalk_1.default.yellow("\n⚠ Tunnel disconnected. Attempting to reconnect..."));
183
- });
184
- client_2.on("reconnecting", function (_a) {
185
- var attempt = _a.attempt, delay = _a.delay;
186
- console.log(chalk_1.default.yellow(" Reconnection attempt ".concat(attempt, "/10 in ").concat(Math.round(delay / 1000), "s...")));
187
- });
188
- client_2.on("reconnected", function () {
189
- console.log(chalk_1.default.green("✓ Tunnel reconnected successfully"));
190
- });
191
- client_2.on("error", function (error) {
192
- console.error(chalk_1.default.red("\n\u2717 Tunnel error: ".concat(error.message)));
193
- });
194
- client_2.on("max_reconnect_attempts", function () {
195
- console.error(chalk_1.default.red("\n✗ Tunnel failed to reconnect after 10 attempts."));
196
- console.log(chalk_1.default.yellow(" Resetting and trying again..."));
197
- // Reset and try one more time (resetReconnection added in tunnel 1.1.31)
198
- if (typeof client_2.resetReconnection === "function") {
199
- client_2.resetReconnection();
200
- client_2.start(parseInt(port)).catch(function (err) {
201
- console.error(chalk_1.default.red("\n\u2717 Unable to restore tunnel connection: ".concat(err.message)));
202
- console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
203
- });
204
- }
205
- else {
206
- console.log(chalk_1.default.yellow(" Please restart the dev server manually."));
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(chalk_1.default.red("\nError: ".concat(message)));
157
+ export function logError(message, error) {
158
+ console.error(chalk.red(`\nError: ${message}`));
226
159
  if (error)
227
- console.error(chalk_1.default.red(error));
160
+ console.error(chalk.red(error));
228
161
  }
229
- function logSuccess(message) {
230
- console.log(chalk_1.default.green("\nSuccess: ".concat(message)));
162
+ export function logSuccess(message) {
163
+ console.log(chalk.green(`\nSuccess: ${message}`));
231
164
  }
232
- function logInfo(message) {
233
- console.log(chalk_1.default.blue("\nInfo: ".concat(message)));
165
+ export function logInfo(message) {
166
+ console.log(chalk.blue(`\nInfo: ${message}`));
234
167
  }
235
- function getStaticFilesPath() {
236
- return path_1.default.join(process.cwd(), "static");
168
+ export function getStaticFilesPath() {
169
+ return path.join(process.cwd(), "static");
237
170
  }
238
- function extractOrgId(apiKey) {
239
- var _a;
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(url_1, options_1) {
246
- return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
247
- var controller, timeoutId;
248
- if (timeoutMs === void 0) { timeoutMs = 30000; }
249
- return __generator(this, function (_a) {
250
- switch (_a.label) {
251
- case 0:
252
- controller = new AbortController();
253
- timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
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 validatePlatformConfig(config, overrides) {
275
- var orgId = resolveOrgId(config);
276
- var apiKey = config["api-key"];
277
- var deploymentId = (overrides === null || overrides === void 0 ? void 0 : overrides.deploymentId) || config["deployment-id"];
278
- 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"];
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: config, orgId: orgId, apiKey: apiKey, deploymentId: deploymentId, serviceId: serviceId };
211
+ return { config, orgId, apiKey, deploymentId, serviceId };
292
212
  }
293
- function platformRequest(ctx_1, endpoint_1) {
294
- return __awaiter(this, arguments, void 0, function (ctx, endpoint, method, overrides) {
295
- var url;
296
- if (method === void 0) { method = "GET"; }
297
- return __generator(this, function (_a) {
298
- url = buildPlatformUrl(ctx.config, ctx.orgId, endpoint, {
299
- deploymentId: ctx.deploymentId,
300
- serviceId: ctx.serviceId,
301
- environment: overrides === null || overrides === void 0 ? void 0 : overrides.environment,
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
- var hasRun = false;
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.2.34",
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.80",
27
- "@dainprotocol/tunnel": "1.1.33",
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",