@optima-chat/browser-cli 0.3.0 → 0.4.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/index.js +52 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var ENV_CONFIG = {
|
|
|
16
16
|
apiUrl: "https://browser-api.stage.optima.onl"
|
|
17
17
|
},
|
|
18
18
|
development: {
|
|
19
|
-
apiUrl: "http://
|
|
19
|
+
apiUrl: "http://127.0.0.1:7292"
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
var OPTIMA_TOKEN_FILE = join(homedir(), ".optima", "token.json");
|
|
@@ -155,13 +155,23 @@ async function requestBinary(path) {
|
|
|
155
155
|
return Buffer.from(arrayBuffer);
|
|
156
156
|
}
|
|
157
157
|
var BrowserAPI = class {
|
|
158
|
-
async createSession(url) {
|
|
159
|
-
const body =
|
|
158
|
+
async createSession(url, profileId) {
|
|
159
|
+
const body = {};
|
|
160
|
+
if (url) body.url = url;
|
|
161
|
+
if (profileId) body.profile_id = profileId;
|
|
160
162
|
return request("/api/sessions", {
|
|
161
163
|
method: "POST",
|
|
162
164
|
body: JSON.stringify(body)
|
|
163
165
|
});
|
|
164
166
|
}
|
|
167
|
+
async listProfiles() {
|
|
168
|
+
return request("/api/profiles");
|
|
169
|
+
}
|
|
170
|
+
async deleteProfile(profileId) {
|
|
171
|
+
return request("/api/profiles/" + encodeURIComponent(profileId), {
|
|
172
|
+
method: "DELETE"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
165
175
|
async closeSession(sessionId) {
|
|
166
176
|
await request(`/api/sessions/${sessionId}`, { method: "DELETE" });
|
|
167
177
|
}
|
|
@@ -493,10 +503,24 @@ function formatWorkflowTask(task) {
|
|
|
493
503
|
function formatWorkflowDeleted(name) {
|
|
494
504
|
return `\u2713 Workflow '${name}' deleted`;
|
|
495
505
|
}
|
|
506
|
+
function formatProfiles(result) {
|
|
507
|
+
if (result.profiles.length === 0) {
|
|
508
|
+
return "No browser profiles found.";
|
|
509
|
+
}
|
|
510
|
+
const lines = result.profiles.map((p) => {
|
|
511
|
+
const sizeMb = (p.size_bytes / (1024 * 1024)).toFixed(1);
|
|
512
|
+
return ` ${p.profile_id} (${sizeMb} MB)`;
|
|
513
|
+
});
|
|
514
|
+
return `Browser profiles:
|
|
515
|
+
${lines.join("\n")}`;
|
|
516
|
+
}
|
|
517
|
+
function formatProfileDelete(profileId) {
|
|
518
|
+
return `Profile '${profileId}' deleted.`;
|
|
519
|
+
}
|
|
496
520
|
|
|
497
521
|
// src/commands/lifecycle.ts
|
|
498
522
|
function registerLifecycleCommands(program2) {
|
|
499
|
-
program2.command("launch").description("Launch a browser session").option("--url <url>", "Navigate to URL after launch").option("--force", "Close existing session before launching").action(async (opts) => {
|
|
523
|
+
program2.command("launch").description("Launch a browser session").option("--url <url>", "Navigate to URL after launch").option("--profile <id>", "Use a named browser profile").option("--force", "Close existing session before launching").action(async (opts) => {
|
|
500
524
|
try {
|
|
501
525
|
if (opts.force) {
|
|
502
526
|
try {
|
|
@@ -507,7 +531,7 @@ function registerLifecycleCommands(program2) {
|
|
|
507
531
|
clearSessionId();
|
|
508
532
|
}
|
|
509
533
|
}
|
|
510
|
-
const state = await api.createSession(opts.url);
|
|
534
|
+
const state = await api.createSession(opts.url, opts.profile);
|
|
511
535
|
saveSessionId(state.session_id);
|
|
512
536
|
console.log(formatLaunch(state));
|
|
513
537
|
} catch (err) {
|
|
@@ -1158,6 +1182,28 @@ function sleep(ms) {
|
|
|
1158
1182
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1159
1183
|
}
|
|
1160
1184
|
|
|
1185
|
+
// src/commands/profile.ts
|
|
1186
|
+
function registerProfileCommands(program2) {
|
|
1187
|
+
program2.command("profiles").description("List browser profiles").action(async () => {
|
|
1188
|
+
try {
|
|
1189
|
+
const result = await api.listProfiles();
|
|
1190
|
+
console.log(formatProfiles(result));
|
|
1191
|
+
} catch (err) {
|
|
1192
|
+
console.error(formatError(err));
|
|
1193
|
+
process.exit(1);
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
program2.command("delete-profile").description("Delete a named browser profile").argument("<profile-id>", "Profile ID to delete").action(async (profileId) => {
|
|
1197
|
+
try {
|
|
1198
|
+
const result = await api.deleteProfile(profileId);
|
|
1199
|
+
console.log(formatProfileDelete(result.profile_id));
|
|
1200
|
+
} catch (err) {
|
|
1201
|
+
console.error(formatError(err));
|
|
1202
|
+
process.exit(1);
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1161
1207
|
// src/index.ts
|
|
1162
1208
|
var require2 = createRequire(import.meta.url);
|
|
1163
1209
|
var { version } = require2("../package.json");
|
|
@@ -1176,4 +1222,5 @@ registerInfoCommands(program);
|
|
|
1176
1222
|
registerTabCommands(program);
|
|
1177
1223
|
registerWorkflowCommands(program);
|
|
1178
1224
|
registerScriptCommands(program);
|
|
1225
|
+
registerProfileCommands(program);
|
|
1179
1226
|
program.parse();
|