@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/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 +5 -4
- 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
|
@@ -1,204 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
-
var ownKeys = function(o) {
|
|
31
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
-
var ar = [];
|
|
33
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
-
return ar;
|
|
35
|
-
};
|
|
36
|
-
return ownKeys(o);
|
|
37
|
-
};
|
|
38
|
-
return function (mod) {
|
|
39
|
-
if (mod && mod.__esModule) return mod;
|
|
40
|
-
var result = {};
|
|
41
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
-
__setModuleDefault(result, mod);
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
})();
|
|
46
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
47
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
56
|
-
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);
|
|
57
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
-
function step(op) {
|
|
60
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
62
|
-
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;
|
|
63
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
-
switch (op[0]) {
|
|
65
|
-
case 0: case 1: t = op; break;
|
|
66
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
-
default:
|
|
70
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
-
if (t[2]) _.ops.pop();
|
|
75
|
-
_.trys.pop(); continue;
|
|
76
|
-
}
|
|
77
|
-
op = body.call(thisArg, _);
|
|
78
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
-
exports.default = testchat;
|
|
84
|
-
var anthropic_1 = require("@ai-sdk/anthropic");
|
|
85
|
-
var ai_1 = require("ai");
|
|
86
|
-
require("dotenv/config");
|
|
87
|
-
var readline = __importStar(require("node:readline/promises"));
|
|
88
|
-
var client_1 = require("@dainprotocol/service-sdk/client");
|
|
89
|
-
var utils_1 = require("../utils");
|
|
90
|
-
var terminal = readline.createInterface({
|
|
1
|
+
import { anthropic } from "@ai-sdk/anthropic";
|
|
2
|
+
import { generateText } from "ai";
|
|
3
|
+
import "dotenv/config";
|
|
4
|
+
import * as readline from "node:readline/promises";
|
|
5
|
+
import { DainClientAuth, DainServiceConnection, } from "@dainprotocol/service-sdk/client";
|
|
6
|
+
import { getDainConfig } from "../utils.js";
|
|
7
|
+
const terminal = readline.createInterface({
|
|
91
8
|
input: process.stdin,
|
|
92
9
|
output: process.stdout,
|
|
93
10
|
});
|
|
94
|
-
function chat(dainConnection) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case 3:
|
|
113
|
-
toolBoxTools = _f.sent();
|
|
114
|
-
allTools = __assign(__assign({}, allTools), toolBoxTools);
|
|
115
|
-
_f.label = 4;
|
|
116
|
-
case 4:
|
|
117
|
-
_i++;
|
|
118
|
-
return [3 /*break*/, 2];
|
|
119
|
-
case 5:
|
|
120
|
-
messages = [];
|
|
121
|
-
toolResponseAvailable = false;
|
|
122
|
-
_f.label = 6;
|
|
123
|
-
case 6:
|
|
124
|
-
if (!true) return [3 /*break*/, 12];
|
|
125
|
-
if (!!toolResponseAvailable) return [3 /*break*/, 8];
|
|
126
|
-
return [4 /*yield*/, terminal.question("You: ")];
|
|
127
|
-
case 7:
|
|
128
|
-
userInput = _f.sent();
|
|
129
|
-
if (userInput.toLowerCase() === "exit") {
|
|
130
|
-
console.log("Goodbye!");
|
|
131
|
-
terminal.close();
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
}
|
|
134
|
-
messages.push({ role: "user", content: userInput });
|
|
135
|
-
_f.label = 8;
|
|
136
|
-
case 8:
|
|
137
|
-
_f.trys.push([8, 10, , 11]);
|
|
138
|
-
return [4 /*yield*/, (0, ai_1.generateText)({
|
|
139
|
-
model: (0, anthropic_1.anthropic)("claude-3-5-sonnet-20240620"),
|
|
140
|
-
system: " Keep your responses brief but insightful.\n use lots of emojis, to show your enthusiasm!\n Your name is Butterfly, Built by the team at Dain. \n You are given tools only use them if they ask for it or if it helps you accomplish the task.\n when explaining topics you can use diagrams to help visualize the concepts.\n if the user asks for a tool, you can use it to help them\n You always answer the with markdown formatting. use markdown when it would be possible.\n You support the following markdown headings, bold, italic, links, tables, lists, code blocks, and blockquotes.\n You do not support images and never include images. You can also use emojis to show enthusiasm!\n Tools often have UI components that directly display to the user, once they are displayed you dont need to repeat the tool name or what it does or what its supposed to output, assume the user can already see the output.\n",
|
|
141
|
-
tools: allTools,
|
|
142
|
-
messages: messages,
|
|
143
|
-
maxSteps: 5,
|
|
144
|
-
})];
|
|
145
|
-
case 9:
|
|
146
|
-
_a = _f.sent(), text = _a.text, toolCalls = _a.toolCalls, toolResults = _a.toolResults, responseMessages = _a.responseMessages;
|
|
147
|
-
toolResponseAvailable = false;
|
|
148
|
-
if (text) {
|
|
149
|
-
process.stdout.write("\nAssistant: ".concat(text));
|
|
150
|
-
}
|
|
151
|
-
for (_b = 0, toolCalls_1 = toolCalls; _b < toolCalls_1.length; _b++) {
|
|
152
|
-
_c = toolCalls_1[_b], toolName = _c.toolName, args = _c.args;
|
|
153
|
-
process.stdout.write("\nTool call: '".concat(toolName, "' ").concat(JSON.stringify(args)));
|
|
154
|
-
}
|
|
155
|
-
for (_d = 0, toolResults_1 = toolResults; _d < toolResults_1.length; _d++) {
|
|
156
|
-
_e = toolResults_1[_d], toolName = _e.toolName, result = _e.result;
|
|
157
|
-
process.stdout.write("\nTool response: '".concat(toolName, "' ").concat(JSON.stringify(result)));
|
|
158
|
-
}
|
|
159
|
-
process.stdout.write("\n\n");
|
|
160
|
-
messages.push.apply(messages, responseMessages);
|
|
161
|
-
toolResponseAvailable = toolCalls.length > 0;
|
|
162
|
-
return [3 /*break*/, 11];
|
|
163
|
-
case 10:
|
|
164
|
-
error_1 = _f.sent();
|
|
165
|
-
console.error("Error generating response:", error_1);
|
|
166
|
-
return [3 /*break*/, 11];
|
|
167
|
-
case 11: return [3 /*break*/, 6];
|
|
168
|
-
case 12: return [2 /*return*/];
|
|
11
|
+
async function chat(dainConnection) {
|
|
12
|
+
let allTools = {};
|
|
13
|
+
const toolBoxes = await dainConnection.getToolboxes();
|
|
14
|
+
for (const toolBox of toolBoxes) {
|
|
15
|
+
if (!toolBox.id)
|
|
16
|
+
continue;
|
|
17
|
+
const toolBoxTools = await dainConnection.loadToolbox(toolBox.id, true);
|
|
18
|
+
allTools = { ...allTools, ...toolBoxTools };
|
|
19
|
+
}
|
|
20
|
+
const messages = [];
|
|
21
|
+
let toolResponseAvailable = false;
|
|
22
|
+
while (true) {
|
|
23
|
+
if (!toolResponseAvailable) {
|
|
24
|
+
const userInput = await terminal.question("You: ");
|
|
25
|
+
if (userInput.toLowerCase() === "exit") {
|
|
26
|
+
console.log("Goodbye!");
|
|
27
|
+
terminal.close();
|
|
28
|
+
return;
|
|
169
29
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
apiKey: config["api-key"],
|
|
194
|
-
});
|
|
195
|
-
dainConnection = new client_1.DainServiceConnection(url, agentAuth);
|
|
196
|
-
console.log('Starting chat session. Type "exit" to end the conversation.');
|
|
197
|
-
return [4 /*yield*/, chat(dainConnection)];
|
|
198
|
-
case 1:
|
|
199
|
-
_a.sent();
|
|
200
|
-
return [2 /*return*/];
|
|
30
|
+
messages.push({ role: "user", content: userInput });
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const { text, toolCalls, toolResults, responseMessages } = await generateText({
|
|
34
|
+
model: anthropic("claude-3-5-sonnet-20240620"),
|
|
35
|
+
system: ` Keep your responses brief but insightful.
|
|
36
|
+
use lots of emojis, to show your enthusiasm!
|
|
37
|
+
Your name is Butterfly, Built by the team at Dain.
|
|
38
|
+
You are given tools only use them if they ask for it or if it helps you accomplish the task.
|
|
39
|
+
when explaining topics you can use diagrams to help visualize the concepts.
|
|
40
|
+
if the user asks for a tool, you can use it to help them
|
|
41
|
+
You always answer the with markdown formatting. use markdown when it would be possible.
|
|
42
|
+
You support the following markdown headings, bold, italic, links, tables, lists, code blocks, and blockquotes.
|
|
43
|
+
You do not support images and never include images. You can also use emojis to show enthusiasm!
|
|
44
|
+
Tools often have UI components that directly display to the user, once they are displayed you dont need to repeat the tool name or what it does or what its supposed to output, assume the user can already see the output.
|
|
45
|
+
`,
|
|
46
|
+
tools: allTools,
|
|
47
|
+
messages,
|
|
48
|
+
maxSteps: 5,
|
|
49
|
+
});
|
|
50
|
+
toolResponseAvailable = false;
|
|
51
|
+
if (text) {
|
|
52
|
+
process.stdout.write(`\nAssistant: ${text}`);
|
|
201
53
|
}
|
|
202
|
-
|
|
54
|
+
for (const { toolName, args } of toolCalls) {
|
|
55
|
+
process.stdout.write(`\nTool call: '${toolName}' ${JSON.stringify(args)}`);
|
|
56
|
+
}
|
|
57
|
+
for (const { toolName, result } of toolResults) {
|
|
58
|
+
process.stdout.write(`\nTool response: '${toolName}' ${JSON.stringify(result)}`);
|
|
59
|
+
}
|
|
60
|
+
process.stdout.write("\n\n");
|
|
61
|
+
messages.push(...responseMessages);
|
|
62
|
+
toolResponseAvailable = toolCalls.length > 0;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error("Error generating response:", error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export default async function testchat(options) {
|
|
70
|
+
const config = getDainConfig(options.config);
|
|
71
|
+
const url = options.url || process.env.TEST_CHAT_URL;
|
|
72
|
+
if (!url) {
|
|
73
|
+
console.error("Error: Please provide a URL using --url option or set TEST_CHAT_URL in your .env file");
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
if (!process.env.ANTHROPIC_API_KEY) {
|
|
77
|
+
console.error("Error: ANTHROPIC_API_KEY is not set in your .env file");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (!config["api-key"]) {
|
|
81
|
+
throw new Error("'api-key' is required when using development proxy");
|
|
82
|
+
}
|
|
83
|
+
const agentAuth = new DainClientAuth({
|
|
84
|
+
apiKey: config["api-key"],
|
|
203
85
|
});
|
|
86
|
+
const dainConnection = new DainServiceConnection(url, agentAuth);
|
|
87
|
+
console.log('Starting chat session. Type "exit" to end the conversation.');
|
|
88
|
+
await chat(dainConnection);
|
|
204
89
|
}
|
|
@@ -1,76 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { getDainConfig, logError, platformRequest, validatePlatformConfig, } from "../utils.js";
|
|
3
|
+
export default async function undeploy(options) {
|
|
4
|
+
const config = getDainConfig(options.config);
|
|
5
|
+
const ctx = validatePlatformConfig(config);
|
|
6
|
+
const spinner = ora(`Undeploying deployment ${ctx.deploymentId}...`).start();
|
|
7
|
+
try {
|
|
8
|
+
const response = await platformRequest(ctx, "undeploy", "DELETE");
|
|
9
|
+
if (!response.ok) {
|
|
10
|
+
throw new Error(`Undeployment failed: ${response.status} ${response.statusText}`);
|
|
11
|
+
}
|
|
12
|
+
spinner.succeed("Undeployment completed successfully.");
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
spinner.fail("Failed to undeploy project.");
|
|
17
|
+
logError("Error during undeployment", error);
|
|
18
|
+
process.exit(1);
|
|
36
19
|
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.default = undeploy;
|
|
43
|
-
var ora_1 = __importDefault(require("ora"));
|
|
44
|
-
var utils_1 = require("../utils");
|
|
45
|
-
function undeploy(options) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var config, ctx, spinner, response, error_1;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
-
ctx = (0, utils_1.validatePlatformConfig)(config);
|
|
53
|
-
spinner = (0, ora_1.default)("Undeploying deployment ".concat(ctx.deploymentId, "...")).start();
|
|
54
|
-
_a.label = 1;
|
|
55
|
-
case 1:
|
|
56
|
-
_a.trys.push([1, 3, , 4]);
|
|
57
|
-
return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "undeploy", "DELETE")];
|
|
58
|
-
case 2:
|
|
59
|
-
response = _a.sent();
|
|
60
|
-
if (!response.ok) {
|
|
61
|
-
throw new Error("Undeployment failed: ".concat(response.status, " ").concat(response.statusText));
|
|
62
|
-
}
|
|
63
|
-
spinner.succeed("Undeployment completed successfully.");
|
|
64
|
-
process.exit(0);
|
|
65
|
-
return [3 /*break*/, 4];
|
|
66
|
-
case 3:
|
|
67
|
-
error_1 = _a.sent();
|
|
68
|
-
spinner.fail("Failed to undeploy project.");
|
|
69
|
-
(0, utils_1.logError)("Error during undeployment", error_1);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
return [3 /*break*/, 4];
|
|
72
|
-
case 4: return [2 /*return*/];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
20
|
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var undeploy_1 = __importDefault(require("./commands/undeploy"));
|
|
16
|
-
var logs_1 = __importDefault(require("./commands/logs"));
|
|
17
|
-
var program = new commander_1.Command();
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import init from './commands/init.js';
|
|
5
|
+
import dev from './commands/dev.js';
|
|
6
|
+
import deploy from './commands/deploy.js';
|
|
7
|
+
import build from './commands/build.js';
|
|
8
|
+
import start from './commands/start.js';
|
|
9
|
+
import testchat from './commands/testchat.js';
|
|
10
|
+
import status from './commands/status.js';
|
|
11
|
+
import undeploy from './commands/undeploy.js';
|
|
12
|
+
import logs from './commands/logs.js';
|
|
13
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
14
|
+
const program = new Command();
|
|
18
15
|
program
|
|
19
16
|
.name('dain')
|
|
20
17
|
.description('CLI for Dain Protocol')
|
|
21
|
-
.version(
|
|
18
|
+
.version(pkg.version);
|
|
22
19
|
program
|
|
23
20
|
.command('init <projectName>')
|
|
24
21
|
.description('Initialize a new Dain project')
|
|
25
|
-
.action(
|
|
22
|
+
.action((projectName) => {
|
|
26
23
|
if (!projectName) {
|
|
27
24
|
console.error('Error: Project name is required');
|
|
28
25
|
process.exit(1);
|
|
29
26
|
}
|
|
30
|
-
(
|
|
27
|
+
init(projectName);
|
|
31
28
|
});
|
|
32
29
|
program
|
|
33
30
|
.command('dev')
|
|
@@ -35,64 +32,64 @@ program
|
|
|
35
32
|
.option('--port <port>', 'Set the port number')
|
|
36
33
|
.option('--noproxy', 'Disable localtunnel proxy')
|
|
37
34
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
38
|
-
.option('--runtime <runtime>', 'Specify the runtime (node or workers)')
|
|
39
|
-
.action(
|
|
40
|
-
(
|
|
35
|
+
.option('--runtime <runtime>', 'Specify the runtime (node, bun, or workers)')
|
|
36
|
+
.action((options) => {
|
|
37
|
+
dev(options);
|
|
41
38
|
});
|
|
42
39
|
program
|
|
43
40
|
.command('deploy')
|
|
44
41
|
.description('Deploy the project')
|
|
45
42
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
46
|
-
.action(
|
|
47
|
-
(
|
|
43
|
+
.action((options) => {
|
|
44
|
+
deploy(options);
|
|
48
45
|
});
|
|
49
46
|
program
|
|
50
47
|
.command('build')
|
|
51
48
|
.description('Build the project')
|
|
52
49
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
53
|
-
.option('--runtime <runtime>', 'Specify the runtime (node or workers)', 'node')
|
|
54
|
-
.action(
|
|
55
|
-
(
|
|
50
|
+
.option('--runtime <runtime>', 'Specify the runtime (node, bun, or workers)', 'node')
|
|
51
|
+
.action((options) => {
|
|
52
|
+
build(options);
|
|
56
53
|
});
|
|
57
54
|
program
|
|
58
55
|
.command('start')
|
|
59
56
|
.description('Start the project')
|
|
60
57
|
.option('--port <port>', 'Set the port number', '2022')
|
|
61
|
-
.action(
|
|
62
|
-
(
|
|
58
|
+
.action((options) => {
|
|
59
|
+
start(options);
|
|
63
60
|
});
|
|
64
61
|
program
|
|
65
62
|
.command('testchat')
|
|
66
63
|
.description('Start a chat session with a DAIN service')
|
|
67
64
|
.option('--url <url>', 'The URL of the DAIN service')
|
|
68
|
-
.action(
|
|
69
|
-
(
|
|
65
|
+
.action((options) => {
|
|
66
|
+
testchat(options);
|
|
70
67
|
});
|
|
71
68
|
program
|
|
72
69
|
.command('undeploy')
|
|
73
70
|
.description('Undeploy the project')
|
|
74
71
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
75
|
-
.action(
|
|
76
|
-
(
|
|
72
|
+
.action((options) => {
|
|
73
|
+
undeploy(options);
|
|
77
74
|
});
|
|
78
75
|
program
|
|
79
76
|
.command('status')
|
|
80
77
|
.description('Check the status of the project')
|
|
81
78
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
82
|
-
.action(
|
|
83
|
-
(
|
|
79
|
+
.action((options) => {
|
|
80
|
+
status(options);
|
|
84
81
|
});
|
|
85
82
|
program
|
|
86
83
|
.command('logs')
|
|
87
84
|
.description('Check the logs of the project')
|
|
88
85
|
.option('-c, --config <path>', 'Path to custom configuration file')
|
|
89
86
|
.option('-w, --watch', 'Keep watching the logs')
|
|
90
|
-
.action(
|
|
91
|
-
(
|
|
87
|
+
.action((options) => {
|
|
88
|
+
logs(options);
|
|
92
89
|
});
|
|
93
90
|
program.parse(process.argv);
|
|
94
91
|
// Add a catch-all command for unknown commands
|
|
95
|
-
program.on('command:*',
|
|
92
|
+
program.on('command:*', () => {
|
|
96
93
|
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
|
|
97
94
|
process.exit(1);
|
|
98
95
|
});
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DainTunnel } from "@dainprotocol/tunnel/client";
|
|
2
|
+
export declare const DEFAULT_TUNNEL_BASE_URL = "wss://tunnel.dain-local.com";
|
|
3
|
+
export declare const DEFAULT_PLATFORM_BASE_URL = "https://codegen-deploy-service.dainapp.com";
|
|
4
|
+
export declare const DEFAULT_API_BASE_URL = "https://dain-platform-ochre.vercel.app";
|
|
5
|
+
export interface DainConfig {
|
|
6
|
+
"main-file": string;
|
|
7
|
+
"static-dir"?: string;
|
|
8
|
+
"api-key"?: string;
|
|
9
|
+
"project-id"?: string;
|
|
10
|
+
"org-id"?: string;
|
|
11
|
+
environment?: "development" | "production";
|
|
12
|
+
version?: string;
|
|
13
|
+
"out-dir"?: string;
|
|
14
|
+
"tunnel-base-url"?: string;
|
|
15
|
+
"platform-base-url"?: string;
|
|
16
|
+
runtime?: "node" | "bun" | "workers";
|
|
17
|
+
"deployment-id"?: string;
|
|
18
|
+
"api-base-url"?: string;
|
|
19
|
+
"environment-name"?: string;
|
|
20
|
+
"service-id"?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function normalizeBaseUrl(value: string): string;
|
|
23
|
+
export declare function joinUrl(baseUrl: string, pathname: string): string;
|
|
24
|
+
export declare function normalizeTunnelPublicUrl(tunnelUrl: string): string;
|
|
25
|
+
export declare function parseEnvContent(envContent: string): {
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
}[];
|
|
29
|
+
export declare function getDainConfig(configFile?: string): DainConfig;
|
|
30
|
+
export declare function displayTunnelUrl(tunnelUrl: string): void;
|
|
31
|
+
export declare function setupProxy(port: string, apiKey: string, config: DainConfig): Promise<{
|
|
32
|
+
client: DainTunnel;
|
|
33
|
+
tunnelUrl: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function logError(message: string, error?: unknown): void;
|
|
36
|
+
export declare function logSuccess(message: string): void;
|
|
37
|
+
export declare function logInfo(message: string): void;
|
|
38
|
+
export declare function getStaticFilesPath(): string;
|
|
39
|
+
export declare function extractOrgId(apiKey: string | undefined): string;
|
|
40
|
+
export declare function resolveOrgId(config: DainConfig): string;
|
|
41
|
+
export declare function fetchWithTimeout(url: string, options: RequestInit, timeoutMs?: number): Promise<Response>;
|
|
42
|
+
export type PlatformEndpoint = "status" | "logs" | "undeploy";
|
|
43
|
+
export declare function buildPlatformUrl(config: DainConfig, orgId: string, endpoint: PlatformEndpoint, overrides?: {
|
|
44
|
+
deploymentId?: string;
|
|
45
|
+
environment?: string;
|
|
46
|
+
serviceId?: string;
|
|
47
|
+
}): string;
|
|
48
|
+
export interface PlatformContext {
|
|
49
|
+
config: DainConfig;
|
|
50
|
+
orgId: string;
|
|
51
|
+
apiKey: string;
|
|
52
|
+
deploymentId: string;
|
|
53
|
+
serviceId: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function validatePlatformConfig(config: DainConfig, overrides?: {
|
|
56
|
+
deploymentId?: string;
|
|
57
|
+
serviceId?: string;
|
|
58
|
+
}): PlatformContext;
|
|
59
|
+
export declare function platformRequest(ctx: PlatformContext, endpoint: PlatformEndpoint, method?: "GET" | "DELETE", overrides?: {
|
|
60
|
+
environment?: string;
|
|
61
|
+
}): Promise<Response>;
|
|
62
|
+
export declare function createIdempotentCleanup(cleanupFn: () => void): () => void;
|