okit-cli 2.1.0 → 2.1.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/auth.d.ts +4 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +134 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +122 -29
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/menu.d.ts.map +1 -1
- package/dist/commands/menu.js +5 -0
- package/dist/commands/menu.js.map +1 -1
- package/dist/commands/profile.d.ts +18 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +409 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/relay.d.ts +13 -0
- package/dist/commands/relay.d.ts.map +1 -0
- package/dist/commands/relay.js +208 -0
- package/dist/commands/relay.js.map +1 -0
- package/dist/commands/repo.js +0 -16
- package/dist/commands/repo.js.map +1 -1
- package/dist/commands/uninstall.d.ts.map +1 -1
- package/dist/commands/uninstall.js +21 -72
- package/dist/commands/uninstall.js.map +1 -1
- package/dist/commands/upgrade.d.ts +1 -3
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +45 -110
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/vault.d.ts +14 -0
- package/dist/commands/vault.d.ts.map +1 -0
- package/dist/commands/vault.js +255 -0
- package/dist/commands/vault.js.map +1 -0
- package/dist/config/i18n.d.ts +71 -0
- package/dist/config/i18n.d.ts.map +1 -1
- package/dist/config/i18n.js +150 -0
- package/dist/config/i18n.js.map +1 -1
- package/dist/config/registry.d.ts +14 -6
- package/dist/config/registry.d.ts.map +1 -1
- package/dist/config/registry.js +638 -68
- package/dist/config/registry.js.map +1 -1
- package/dist/config/user.d.ts +4 -0
- package/dist/config/user.d.ts.map +1 -1
- package/dist/config/user.js +1 -0
- package/dist/config/user.js.map +1 -1
- package/dist/executor/deps/BrewDependencyProvider.d.ts.map +1 -1
- package/dist/executor/deps/BrewDependencyProvider.js +4 -2
- package/dist/executor/deps/BrewDependencyProvider.js.map +1 -1
- package/dist/executor/deps/NpmDependencyProvider.d.ts.map +1 -1
- package/dist/executor/deps/NpmDependencyProvider.js +4 -2
- package/dist/executor/deps/NpmDependencyProvider.js.map +1 -1
- package/dist/executor/deps/PipxDependencyProvider.d.ts.map +1 -1
- package/dist/executor/deps/PipxDependencyProvider.js +4 -2
- package/dist/executor/deps/PipxDependencyProvider.js.map +1 -1
- package/dist/executor/deps/UvToolDependencyProvider.d.ts.map +1 -1
- package/dist/executor/deps/UvToolDependencyProvider.js +4 -2
- package/dist/executor/deps/UvToolDependencyProvider.js.map +1 -1
- package/dist/executor/plan/registryDeps.d.ts.map +1 -1
- package/dist/executor/plan/registryDeps.js +13 -5
- package/dist/executor/plan/registryDeps.js.map +1 -1
- package/dist/executor/runner.d.ts.map +1 -1
- package/dist/executor/runner.js +11 -9
- package/dist/executor/runner.js.map +1 -1
- package/dist/main.js +188 -4
- package/dist/main.js.map +1 -1
- package/dist/utils/semver.d.ts +12 -0
- package/dist/utils/semver.d.ts.map +1 -0
- package/dist/utils/semver.js +71 -0
- package/dist/utils/semver.js.map +1 -0
- package/dist/vault/store.d.ts +51 -0
- package/dist/vault/store.d.ts.map +1 -0
- package/dist/vault/store.js +260 -0
- package/dist/vault/store.js.map +1 -0
- package/package.json +8 -3
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.listProfiles = listProfiles;
|
|
40
|
+
exports.getProfile = getProfile;
|
|
41
|
+
exports.saveProfile = saveProfile;
|
|
42
|
+
exports.deleteProfile = deleteProfile;
|
|
43
|
+
exports.createProfile = createProfile;
|
|
44
|
+
exports.applyProfile = applyProfile;
|
|
45
|
+
exports.showProfiles = showProfiles;
|
|
46
|
+
exports.showProfileDetail = showProfileDetail;
|
|
47
|
+
exports.removeProfile = removeProfile;
|
|
48
|
+
exports.exportProfile = exportProfile;
|
|
49
|
+
exports.importProfile = importProfile;
|
|
50
|
+
exports.showProfileMenu = showProfileMenu;
|
|
51
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
52
|
+
const kleur_1 = __importDefault(require("kleur"));
|
|
53
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
54
|
+
const path_1 = __importDefault(require("path"));
|
|
55
|
+
const registry_1 = require("../config/registry");
|
|
56
|
+
const runner_1 = require("../executor/runner");
|
|
57
|
+
const i18n_1 = require("../config/i18n");
|
|
58
|
+
const PROFILES_DIR = path_1.default.join(registry_1.OKIT_DIR, "profiles");
|
|
59
|
+
async function ensureProfilesDir() {
|
|
60
|
+
await fs_extra_1.default.ensureDir(PROFILES_DIR);
|
|
61
|
+
}
|
|
62
|
+
function profilePath(name) {
|
|
63
|
+
return path_1.default.join(PROFILES_DIR, `${name}.json`);
|
|
64
|
+
}
|
|
65
|
+
async function listProfiles() {
|
|
66
|
+
await ensureProfilesDir();
|
|
67
|
+
const files = await fs_extra_1.default.readdir(PROFILES_DIR);
|
|
68
|
+
const profiles = [];
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
if (!file.endsWith(".json"))
|
|
71
|
+
continue;
|
|
72
|
+
try {
|
|
73
|
+
const content = await fs_extra_1.default.readFile(path_1.default.join(PROFILES_DIR, file), "utf-8");
|
|
74
|
+
profiles.push(JSON.parse(content));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// skip invalid files
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return profiles;
|
|
81
|
+
}
|
|
82
|
+
async function getProfile(name) {
|
|
83
|
+
const fp = profilePath(name);
|
|
84
|
+
if (!(await fs_extra_1.default.pathExists(fp)))
|
|
85
|
+
return null;
|
|
86
|
+
try {
|
|
87
|
+
const content = await fs_extra_1.default.readFile(fp, "utf-8");
|
|
88
|
+
return JSON.parse(content);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function saveProfile(profile) {
|
|
95
|
+
await ensureProfilesDir();
|
|
96
|
+
await fs_extra_1.default.writeFile(profilePath(profile.name), JSON.stringify(profile, null, 2));
|
|
97
|
+
}
|
|
98
|
+
async function deleteProfile(name) {
|
|
99
|
+
const fp = profilePath(name);
|
|
100
|
+
if (!(await fs_extra_1.default.pathExists(fp)))
|
|
101
|
+
return false;
|
|
102
|
+
await fs_extra_1.default.remove(fp);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
// okit profile create - interactive
|
|
106
|
+
async function createProfile() {
|
|
107
|
+
const registry = await (0, registry_1.loadRegistry)();
|
|
108
|
+
const availableTools = registry.steps
|
|
109
|
+
.filter((s) => (0, registry_1.resolveCmd)(s.install) !== undefined)
|
|
110
|
+
.map((s) => s.name);
|
|
111
|
+
const nameRes = await (0, prompts_1.default)({
|
|
112
|
+
type: "text",
|
|
113
|
+
name: "name",
|
|
114
|
+
message: (0, i18n_1.t)("profileName"),
|
|
115
|
+
validate: (v) => (v.trim().length > 0 ? true : (0, i18n_1.t)("profileNameRequired")),
|
|
116
|
+
});
|
|
117
|
+
if (!nameRes.name)
|
|
118
|
+
return;
|
|
119
|
+
const existing = await getProfile(nameRes.name);
|
|
120
|
+
if (existing) {
|
|
121
|
+
const overwrite = await (0, prompts_1.default)({
|
|
122
|
+
type: "confirm",
|
|
123
|
+
name: "yes",
|
|
124
|
+
message: (0, i18n_1.t)("profileExists"),
|
|
125
|
+
initial: false,
|
|
126
|
+
});
|
|
127
|
+
if (!overwrite.yes)
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const descRes = await (0, prompts_1.default)({
|
|
131
|
+
type: "text",
|
|
132
|
+
name: "desc",
|
|
133
|
+
message: (0, i18n_1.t)("profileDesc"),
|
|
134
|
+
});
|
|
135
|
+
const toolRes = await (0, prompts_1.default)({
|
|
136
|
+
type: "autocompleteMultiselect",
|
|
137
|
+
name: "tools",
|
|
138
|
+
message: (0, i18n_1.t)("profileSelectTools"),
|
|
139
|
+
choices: availableTools.map((name) => ({ title: name, value: name })),
|
|
140
|
+
suggest: (input, choices) => Promise.resolve(choices.filter((c) => c.title.toLowerCase().includes(input.toLowerCase()))),
|
|
141
|
+
});
|
|
142
|
+
if (!toolRes.tools || toolRes.tools.length === 0) {
|
|
143
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("profileNoTools")));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const profile = {
|
|
147
|
+
name: nameRes.name.trim(),
|
|
148
|
+
description: descRes.desc?.trim() || undefined,
|
|
149
|
+
tools: toolRes.tools,
|
|
150
|
+
};
|
|
151
|
+
await saveProfile(profile);
|
|
152
|
+
console.log(kleur_1.default.green(`\n${(0, i18n_1.t)("profileCreated")} ${profile.name} (${profile.tools.length} ${(0, i18n_1.t)("profileToolCount")})`));
|
|
153
|
+
}
|
|
154
|
+
// okit profile apply <name> - install all tools in profile
|
|
155
|
+
async function applyProfile(name) {
|
|
156
|
+
const profiles = await listProfiles();
|
|
157
|
+
if (profiles.length === 0) {
|
|
158
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("profileEmpty")));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let targetName = name;
|
|
162
|
+
if (!targetName) {
|
|
163
|
+
const res = await (0, prompts_1.default)({
|
|
164
|
+
type: "select",
|
|
165
|
+
name: "profile",
|
|
166
|
+
message: (0, i18n_1.t)("profileSelectApply"),
|
|
167
|
+
choices: profiles.map((p) => ({
|
|
168
|
+
title: `${p.name}${p.description ? kleur_1.default.gray(` - ${p.description}`) : ""} (${p.tools.length})`,
|
|
169
|
+
value: p.name,
|
|
170
|
+
})),
|
|
171
|
+
});
|
|
172
|
+
if (!res.profile)
|
|
173
|
+
return;
|
|
174
|
+
targetName = res.profile;
|
|
175
|
+
}
|
|
176
|
+
const profile = await getProfile(targetName);
|
|
177
|
+
if (!profile) {
|
|
178
|
+
console.log(kleur_1.default.red(`${(0, i18n_1.t)("profileNotFound")} ${targetName}`));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const registry = await (0, registry_1.loadRegistry)();
|
|
182
|
+
const steps = registry.steps.filter((s) => profile.tools.includes(s.name));
|
|
183
|
+
const missing = profile.tools.filter((name) => !registry.steps.find((s) => s.name === name));
|
|
184
|
+
console.log(kleur_1.default.cyan(`\n${(0, i18n_1.t)("profileApplying")} ${profile.name}`));
|
|
185
|
+
if (profile.description) {
|
|
186
|
+
console.log(kleur_1.default.gray(` ${profile.description}`));
|
|
187
|
+
}
|
|
188
|
+
console.log(kleur_1.default.gray(` ${(0, i18n_1.t)("profileToolCount")}: ${steps.length}`));
|
|
189
|
+
if (missing.length > 0) {
|
|
190
|
+
console.log(kleur_1.default.yellow(` ${(0, i18n_1.t)("profileMissingTools")}: ${missing.join(", ")}`));
|
|
191
|
+
}
|
|
192
|
+
console.log();
|
|
193
|
+
// Show tools list
|
|
194
|
+
for (const step of steps) {
|
|
195
|
+
console.log(kleur_1.default.gray(` - ${step.name}`));
|
|
196
|
+
}
|
|
197
|
+
const confirm = await (0, prompts_1.default)({
|
|
198
|
+
type: "confirm",
|
|
199
|
+
name: "yes",
|
|
200
|
+
message: (0, i18n_1.t)("profileConfirmApply"),
|
|
201
|
+
initial: true,
|
|
202
|
+
});
|
|
203
|
+
if (!confirm.yes)
|
|
204
|
+
return;
|
|
205
|
+
console.log();
|
|
206
|
+
const results = await (0, runner_1.executeSteps)(steps, "install", registry);
|
|
207
|
+
const succeeded = results.filter((r) => r.success && r.action !== "skip").length;
|
|
208
|
+
const failed = results.filter((r) => !r.success && r.action !== "skip").length;
|
|
209
|
+
const skipped = results.filter((r) => r.action === "skip").length;
|
|
210
|
+
console.log(kleur_1.default.cyan(`\n${(0, i18n_1.t)("profileApplyResult")}`));
|
|
211
|
+
console.log(kleur_1.default.green(` ${(0, i18n_1.t)("success")}: ${succeeded}`));
|
|
212
|
+
if (failed > 0)
|
|
213
|
+
console.log(kleur_1.default.red(` ${(0, i18n_1.t)("failed")}: ${failed}`));
|
|
214
|
+
if (skipped > 0)
|
|
215
|
+
console.log(kleur_1.default.gray(` ${(0, i18n_1.t)("skipped")}: ${skipped}`));
|
|
216
|
+
}
|
|
217
|
+
// okit profile list
|
|
218
|
+
async function showProfiles() {
|
|
219
|
+
const profiles = await listProfiles();
|
|
220
|
+
if (profiles.length === 0) {
|
|
221
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("profileEmpty")));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
console.log(kleur_1.default.cyan(`\n${(0, i18n_1.t)("profileListTitle")}\n`));
|
|
225
|
+
for (const p of profiles) {
|
|
226
|
+
console.log(` ${kleur_1.default.bold(p.name)}${p.description ? kleur_1.default.gray(` - ${p.description}`) : ""}`);
|
|
227
|
+
console.log(kleur_1.default.gray(` ${p.tools.join(", ")}`));
|
|
228
|
+
console.log();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// okit profile show <name>
|
|
232
|
+
async function showProfileDetail(name) {
|
|
233
|
+
const profile = await getProfile(name);
|
|
234
|
+
if (!profile) {
|
|
235
|
+
console.log(kleur_1.default.red(`${(0, i18n_1.t)("profileNotFound")} ${name}`));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const registry = await (0, registry_1.loadRegistry)();
|
|
239
|
+
console.log(kleur_1.default.cyan(`\n ${kleur_1.default.bold(profile.name)}`));
|
|
240
|
+
if (profile.description) {
|
|
241
|
+
console.log(kleur_1.default.gray(` ${profile.description}`));
|
|
242
|
+
}
|
|
243
|
+
console.log();
|
|
244
|
+
for (const toolName of profile.tools) {
|
|
245
|
+
const step = registry.steps.find((s) => s.name === toolName);
|
|
246
|
+
if (!step) {
|
|
247
|
+
console.log(` ${kleur_1.default.red("?")} ${toolName} ${kleur_1.default.gray("(not in registry)")}`);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
// Quick check if installed
|
|
251
|
+
const checkCmd = (0, registry_1.resolveCmd)(step.check);
|
|
252
|
+
if (checkCmd) {
|
|
253
|
+
try {
|
|
254
|
+
const { execSync } = await Promise.resolve().then(() => __importStar(require("child_process")));
|
|
255
|
+
execSync(checkCmd, { stdio: "ignore" });
|
|
256
|
+
console.log(` ${kleur_1.default.green("\u2713")} ${toolName}`);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
console.log(` ${kleur_1.default.red("\u2717")} ${toolName} ${kleur_1.default.gray("(" + (0, i18n_1.t)("checkNotInstalled") + ")")}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
console.log(` ${kleur_1.default.gray("-")} ${toolName}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
console.log();
|
|
267
|
+
}
|
|
268
|
+
// okit profile delete
|
|
269
|
+
async function removeProfile(name) {
|
|
270
|
+
if (!name) {
|
|
271
|
+
const profiles = await listProfiles();
|
|
272
|
+
if (profiles.length === 0) {
|
|
273
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("profileEmpty")));
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const res = await (0, prompts_1.default)({
|
|
277
|
+
type: "select",
|
|
278
|
+
name: "profile",
|
|
279
|
+
message: (0, i18n_1.t)("profileSelectDelete"),
|
|
280
|
+
choices: profiles.map((p) => ({ title: p.name, value: p.name })),
|
|
281
|
+
});
|
|
282
|
+
if (!res.profile)
|
|
283
|
+
return;
|
|
284
|
+
name = res.profile;
|
|
285
|
+
}
|
|
286
|
+
const confirm = await (0, prompts_1.default)({
|
|
287
|
+
type: "confirm",
|
|
288
|
+
name: "yes",
|
|
289
|
+
message: `${(0, i18n_1.t)("profileConfirmDelete")} ${name}?`,
|
|
290
|
+
initial: false,
|
|
291
|
+
});
|
|
292
|
+
if (!confirm.yes)
|
|
293
|
+
return;
|
|
294
|
+
if (await deleteProfile(name)) {
|
|
295
|
+
console.log(kleur_1.default.green(`${(0, i18n_1.t)("profileDeleted")} ${name}`));
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
console.log(kleur_1.default.red(`${(0, i18n_1.t)("profileNotFound")} ${name}`));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// okit profile export <name>
|
|
302
|
+
async function exportProfile(name, outputPath) {
|
|
303
|
+
if (!name) {
|
|
304
|
+
const profiles = await listProfiles();
|
|
305
|
+
if (profiles.length === 0) {
|
|
306
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("profileEmpty")));
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const res = await (0, prompts_1.default)({
|
|
310
|
+
type: "select",
|
|
311
|
+
name: "profile",
|
|
312
|
+
message: (0, i18n_1.t)("profileSelectExport"),
|
|
313
|
+
choices: profiles.map((p) => ({ title: p.name, value: p.name })),
|
|
314
|
+
});
|
|
315
|
+
if (!res.profile)
|
|
316
|
+
return;
|
|
317
|
+
name = res.profile;
|
|
318
|
+
}
|
|
319
|
+
const profile = await getProfile(name);
|
|
320
|
+
if (!profile) {
|
|
321
|
+
console.log(kleur_1.default.red(`${(0, i18n_1.t)("profileNotFound")} ${name}`));
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const dest = outputPath || `okit-profile-${profile.name}.json`;
|
|
325
|
+
await fs_extra_1.default.writeFile(dest, JSON.stringify(profile, null, 2));
|
|
326
|
+
console.log(kleur_1.default.green(`${(0, i18n_1.t)("profileExported")} ${dest}`));
|
|
327
|
+
}
|
|
328
|
+
// okit profile import <file>
|
|
329
|
+
async function importProfile(filePath) {
|
|
330
|
+
if (!(await fs_extra_1.default.pathExists(filePath))) {
|
|
331
|
+
console.log(kleur_1.default.red(`${(0, i18n_1.t)("profileFileNotFound")} ${filePath}`));
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
const content = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
336
|
+
const profile = JSON.parse(content);
|
|
337
|
+
if (!profile.name || !Array.isArray(profile.tools)) {
|
|
338
|
+
console.log(kleur_1.default.red((0, i18n_1.t)("profileInvalidFormat")));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const existing = await getProfile(profile.name);
|
|
342
|
+
if (existing) {
|
|
343
|
+
const overwrite = await (0, prompts_1.default)({
|
|
344
|
+
type: "confirm",
|
|
345
|
+
name: "yes",
|
|
346
|
+
message: `${(0, i18n_1.t)("profileExists")} (${profile.name})`,
|
|
347
|
+
initial: false,
|
|
348
|
+
});
|
|
349
|
+
if (!overwrite.yes)
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
await saveProfile(profile);
|
|
353
|
+
console.log(kleur_1.default.green(`${(0, i18n_1.t)("profileImported")} ${profile.name} (${profile.tools.length} ${(0, i18n_1.t)("profileToolCount")})`));
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
console.log(kleur_1.default.red((0, i18n_1.t)("profileInvalidFormat")));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
// Interactive profile menu
|
|
360
|
+
async function showProfileMenu() {
|
|
361
|
+
while (true) {
|
|
362
|
+
const profiles = await listProfiles();
|
|
363
|
+
const res = await (0, prompts_1.default)({
|
|
364
|
+
type: "select",
|
|
365
|
+
name: "action",
|
|
366
|
+
message: (0, i18n_1.t)("profileMenu"),
|
|
367
|
+
choices: [
|
|
368
|
+
{ title: (0, i18n_1.t)("profileActionCreate"), value: "create" },
|
|
369
|
+
{ title: `${(0, i18n_1.t)("profileActionApply")}${profiles.length > 0 ? ` (${profiles.length})` : ""}`, value: "apply" },
|
|
370
|
+
{ title: (0, i18n_1.t)("profileActionList"), value: "list" },
|
|
371
|
+
{ title: (0, i18n_1.t)("profileActionDelete"), value: "delete" },
|
|
372
|
+
{ title: (0, i18n_1.t)("profileActionExport"), value: "export" },
|
|
373
|
+
{ title: (0, i18n_1.t)("profileActionImport"), value: "import" },
|
|
374
|
+
{ title: (0, i18n_1.t)("back"), value: "back" },
|
|
375
|
+
],
|
|
376
|
+
});
|
|
377
|
+
switch (res.action) {
|
|
378
|
+
case "create":
|
|
379
|
+
await createProfile();
|
|
380
|
+
break;
|
|
381
|
+
case "apply":
|
|
382
|
+
await applyProfile();
|
|
383
|
+
break;
|
|
384
|
+
case "list":
|
|
385
|
+
await showProfiles();
|
|
386
|
+
break;
|
|
387
|
+
case "delete":
|
|
388
|
+
await removeProfile();
|
|
389
|
+
break;
|
|
390
|
+
case "export":
|
|
391
|
+
await exportProfile();
|
|
392
|
+
break;
|
|
393
|
+
case "import": {
|
|
394
|
+
const fileRes = await (0, prompts_1.default)({
|
|
395
|
+
type: "text",
|
|
396
|
+
name: "path",
|
|
397
|
+
message: (0, i18n_1.t)("profileImportPath"),
|
|
398
|
+
});
|
|
399
|
+
if (fileRes.path)
|
|
400
|
+
await importProfile(fileRes.path);
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
case "back":
|
|
404
|
+
default:
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/commands/profile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,oCAcC;AAED,gCASC;AAED,kCAGC;AAED,sCAKC;AAGD,sCAsDC;AAGD,oCAkEC;AAGD,oCAaC;AAGD,8CAoCC;AAGD,sCA8BC;AAGD,sCA0BC;AAGD,sCA+BC;AAGD,0CAgDC;AArYD,sDAA8B;AAC9B,kDAA0B;AAC1B,wDAA0B;AAC1B,gDAAwB;AACxB,iDAAwE;AACxE,+CAAkD;AAClD,yCAAmC;AAEnC,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,mBAAQ,EAAE,UAAU,CAAC,CAAC;AAQrD,KAAK,UAAU,iBAAiB;IAC9B,MA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AAE,QAAQ,EAAE;gBACpD,EAAE,KAAK,EAAE,IAAA,QAAC,EAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE;aACpC;SACF,CAAC,CAAC;QAEH,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;YACnB,KAAK,QAAQ;gBACX,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM;YACR,KAAK,OAAO;gBACV,MAAM,YAAY,EAAE,CAAC;gBACrB,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,YAAY,EAAE,CAAC;gBACrB,MAAM;YACR,KAAK,QAAQ;gBACX,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM;YACR,KAAK,QAAQ;gBACX,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM;YACR,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACd,MAAM,OAAO,GAAG,MAAM,IAAA,iBAAO,EAAC;oBAC5B,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,IAAA,QAAC,EAAC,mBAAmB,CAAC;iBAChC,CAAC,CAAC;gBACH,IAAI,OAAO,CAAC,IAAI;oBAAE,MAAM,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACpD,MAAM;YACR,CAAC;YACD,KAAK,MAAM,CAAC;YACZ;gBACE,OAAO;QACX,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function relayConfig(options: {
|
|
2
|
+
url?: string;
|
|
3
|
+
token?: string;
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function relayConnect(options: {
|
|
6
|
+
tunnel: string;
|
|
7
|
+
agent: string;
|
|
8
|
+
target?: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
export declare function relayStatus(tunnel: string): Promise<void>;
|
|
11
|
+
export declare function relayCreate(tunnel?: string): Promise<void>;
|
|
12
|
+
export declare function relayAgents(): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/commands/relay.ts"],"names":[],"mappings":"AAuBA,wBAAsB,WAAW,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAwC1F;AAGD,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2ChB;AAGD,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB/D;AAGD,wBAAsB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BhE;AAGD,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CA8BjD"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.relayConfig = relayConfig;
|
|
7
|
+
exports.relayConnect = relayConnect;
|
|
8
|
+
exports.relayStatus = relayStatus;
|
|
9
|
+
exports.relayCreate = relayCreate;
|
|
10
|
+
exports.relayAgents = relayAgents;
|
|
11
|
+
const kleur_1 = __importDefault(require("kleur"));
|
|
12
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const user_1 = require("../config/user");
|
|
16
|
+
const i18n_1 = require("../config/i18n");
|
|
17
|
+
const RELAY_PROJECT = path_1.default.join(process.env.HOME || "~", "Desktop/Dolphin/relay");
|
|
18
|
+
async function getRelayConfig() {
|
|
19
|
+
const config = await (0, user_1.loadUserConfig)();
|
|
20
|
+
if (!config.relay?.url || !config.relay?.token) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return { url: config.relay.url, token: config.relay.token };
|
|
24
|
+
}
|
|
25
|
+
function printConfigHint() {
|
|
26
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("relayNotConfigured")));
|
|
27
|
+
console.log(kleur_1.default.gray(" okit relay config --url <relay-url> --token <auth-token>"));
|
|
28
|
+
}
|
|
29
|
+
// okit relay config
|
|
30
|
+
async function relayConfig(options) {
|
|
31
|
+
let url = options.url;
|
|
32
|
+
let token = options.token;
|
|
33
|
+
if (!url && !token) {
|
|
34
|
+
// Interactive mode
|
|
35
|
+
const current = await (0, user_1.loadUserConfig)();
|
|
36
|
+
const res = await (0, prompts_1.default)([
|
|
37
|
+
{
|
|
38
|
+
type: "text",
|
|
39
|
+
name: "url",
|
|
40
|
+
message: (0, i18n_1.t)("relayConfigUrl"),
|
|
41
|
+
initial: current.relay?.url || "",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: "password",
|
|
45
|
+
name: "token",
|
|
46
|
+
message: (0, i18n_1.t)("relayConfigToken"),
|
|
47
|
+
initial: current.relay?.token || "",
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
url = res.url;
|
|
51
|
+
token = res.token;
|
|
52
|
+
}
|
|
53
|
+
if (url || token) {
|
|
54
|
+
const patch = {};
|
|
55
|
+
if (url)
|
|
56
|
+
patch.url = url;
|
|
57
|
+
if (token)
|
|
58
|
+
patch.token = token;
|
|
59
|
+
await (0, user_1.updateUserConfig)({ relay: patch });
|
|
60
|
+
console.log(kleur_1.default.green((0, i18n_1.t)("relayConfigSaved")));
|
|
61
|
+
const config = await (0, user_1.loadUserConfig)();
|
|
62
|
+
if (config.relay?.url) {
|
|
63
|
+
console.log(kleur_1.default.gray(` url: ${config.relay.url}`));
|
|
64
|
+
}
|
|
65
|
+
if (config.relay?.token) {
|
|
66
|
+
console.log(kleur_1.default.gray(` token: ${"*".repeat(8)}`));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// okit relay connect
|
|
71
|
+
async function relayConnect(options) {
|
|
72
|
+
const config = await getRelayConfig();
|
|
73
|
+
if (!config) {
|
|
74
|
+
printConfigHint();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const target = options.target || "http://localhost:3000";
|
|
78
|
+
console.log(kleur_1.default.cyan(`\n[relay] Connecting`));
|
|
79
|
+
console.log(kleur_1.default.gray(` agent: ${options.agent}`));
|
|
80
|
+
console.log(kleur_1.default.gray(` tunnel: ${options.tunnel}`));
|
|
81
|
+
console.log(kleur_1.default.gray(` target: ${target}`));
|
|
82
|
+
console.log(kleur_1.default.gray(` external: ${config.url}/agent/${options.agent}/\n`));
|
|
83
|
+
const child = (0, child_process_1.spawn)("npx", [
|
|
84
|
+
"tsx", "src/client.ts",
|
|
85
|
+
"--relay", config.url,
|
|
86
|
+
"--tunnel", options.tunnel,
|
|
87
|
+
"--agent", options.agent,
|
|
88
|
+
"--target", target,
|
|
89
|
+
"--token", config.token,
|
|
90
|
+
], {
|
|
91
|
+
cwd: RELAY_PROJECT,
|
|
92
|
+
stdio: "inherit",
|
|
93
|
+
env: { ...process.env },
|
|
94
|
+
});
|
|
95
|
+
const cleanup = () => { child.kill("SIGTERM"); };
|
|
96
|
+
process.on("SIGINT", cleanup);
|
|
97
|
+
process.on("SIGTERM", cleanup);
|
|
98
|
+
return new Promise((resolve) => {
|
|
99
|
+
child.on("close", () => {
|
|
100
|
+
process.removeListener("SIGINT", cleanup);
|
|
101
|
+
process.removeListener("SIGTERM", cleanup);
|
|
102
|
+
resolve();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// okit relay status
|
|
107
|
+
async function relayStatus(tunnel) {
|
|
108
|
+
const config = await getRelayConfig();
|
|
109
|
+
if (!config) {
|
|
110
|
+
printConfigHint();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const resp = await fetch(`${config.url}/tunnel/${tunnel}/status`, {
|
|
115
|
+
headers: { Authorization: `Bearer ${config.token}` },
|
|
116
|
+
});
|
|
117
|
+
const data = await resp.json();
|
|
118
|
+
console.log(kleur_1.default.cyan(`\n[relay] Tunnel: ${tunnel}`));
|
|
119
|
+
console.log(` connected: ${data.connected ? kleur_1.default.green("yes") : kleur_1.default.red("no")}`);
|
|
120
|
+
console.log(` pendingRequests: ${data.pendingRequests}`);
|
|
121
|
+
console.log(` logSubscribers: ${data.logSubscribers}`);
|
|
122
|
+
console.log();
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
console.log(kleur_1.default.red(`[relay] Failed: ${err.message}`));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// okit relay create
|
|
129
|
+
async function relayCreate(tunnel) {
|
|
130
|
+
const config = await getRelayConfig();
|
|
131
|
+
if (!config) {
|
|
132
|
+
printConfigHint();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const body = tunnel ? JSON.stringify({ id: tunnel }) : "{}";
|
|
137
|
+
const resp = await fetch(`${config.url}/tunnel`, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: {
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
Authorization: `Bearer ${config.token}`,
|
|
142
|
+
},
|
|
143
|
+
body,
|
|
144
|
+
});
|
|
145
|
+
const data = await resp.json();
|
|
146
|
+
if (data.error) {
|
|
147
|
+
console.log(kleur_1.default.red(`[relay] ${data.error}`));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
console.log(kleur_1.default.cyan(`\n[relay] Tunnel created: ${data.tunnelId}\n`));
|
|
151
|
+
console.log(` proxy: ${kleur_1.default.gray(data.endpoints.proxy)}`);
|
|
152
|
+
console.log(` agent: ${kleur_1.default.gray(data.endpoints.agent)}`);
|
|
153
|
+
console.log(` status: ${kleur_1.default.gray(data.endpoints.status)}`);
|
|
154
|
+
console.log();
|
|
155
|
+
console.log(kleur_1.default.gray(` okit relay connect --tunnel ${data.tunnelId} --agent my-agent`));
|
|
156
|
+
console.log();
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
console.log(kleur_1.default.red(`[relay] Failed: ${err.message}`));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// okit relay agents — list all online agents
|
|
163
|
+
async function relayAgents() {
|
|
164
|
+
const config = await getRelayConfig();
|
|
165
|
+
if (!config) {
|
|
166
|
+
printConfigHint();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const resp = await fetch(`${config.url}/registry/agents`, {
|
|
171
|
+
headers: { Authorization: `Bearer ${config.token}` },
|
|
172
|
+
});
|
|
173
|
+
const data = await resp.json();
|
|
174
|
+
if (data.count === 0) {
|
|
175
|
+
console.log(kleur_1.default.yellow((0, i18n_1.t)("relayNoAgents")));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
console.log(kleur_1.default.cyan(`\n${(0, i18n_1.t)("relayAgentList")} (${data.count})\n`));
|
|
179
|
+
for (const agent of data.agents) {
|
|
180
|
+
const uptime = timeSince(agent.connectedAt);
|
|
181
|
+
const lastSeen = timeSince(agent.lastSeen);
|
|
182
|
+
console.log(` ${kleur_1.default.green("\u2713")} ${kleur_1.default.bold(agent.agentId)}`);
|
|
183
|
+
console.log(kleur_1.default.gray(` tunnel: ${agent.tunnelId} uptime: ${uptime} last: ${lastSeen} ago`));
|
|
184
|
+
if (agent.metadata) {
|
|
185
|
+
const meta = Object.entries(agent.metadata).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
186
|
+
console.log(kleur_1.default.gray(` ${meta}`));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
console.log();
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
console.log(kleur_1.default.red(`[relay] Failed: ${err.message}`));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function timeSince(isoDate) {
|
|
196
|
+
const diff = Date.now() - new Date(isoDate).getTime();
|
|
197
|
+
const secs = Math.floor(diff / 1000);
|
|
198
|
+
if (secs < 60)
|
|
199
|
+
return `${secs}s`;
|
|
200
|
+
const mins = Math.floor(secs / 60);
|
|
201
|
+
if (mins < 60)
|
|
202
|
+
return `${mins}m`;
|
|
203
|
+
const hours = Math.floor(mins / 60);
|
|
204
|
+
if (hours < 24)
|
|
205
|
+
return `${hours}h`;
|
|
206
|
+
return `${Math.floor(hours / 24)}d`;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=relay.js.map
|