@optima-chat/browser-cli 0.1.1 → 0.1.3
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 +16 -3
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -191,9 +191,13 @@ var BrowserAPI = class {
|
|
|
191
191
|
var api = new BrowserAPI();
|
|
192
192
|
|
|
193
193
|
// src/session.ts
|
|
194
|
-
import { readFileSync as readFileSync2, writeFileSync, unlinkSync, existsSync as existsSync2 } from "fs";
|
|
195
|
-
|
|
194
|
+
import { readFileSync as readFileSync2, writeFileSync, unlinkSync, existsSync as existsSync2, mkdirSync } from "fs";
|
|
195
|
+
import { join as join2 } from "path";
|
|
196
|
+
import { homedir as homedir2 } from "os";
|
|
197
|
+
var OPTIMA_DIR = join2(homedir2(), ".optima");
|
|
198
|
+
var SESSION_FILE = join2(OPTIMA_DIR, "browser-session-id");
|
|
196
199
|
function saveSessionId(id) {
|
|
200
|
+
mkdirSync(OPTIMA_DIR, { recursive: true });
|
|
197
201
|
writeFileSync(SESSION_FILE, id, "utf-8");
|
|
198
202
|
}
|
|
199
203
|
function loadSessionId() {
|
|
@@ -281,8 +285,17 @@ function formatTabsInline(tabs) {
|
|
|
281
285
|
|
|
282
286
|
// src/commands/lifecycle.ts
|
|
283
287
|
function registerLifecycleCommands(program2) {
|
|
284
|
-
program2.command("launch").description("Launch a browser session").option("--url <url>", "Navigate to URL after launch").action(async (opts) => {
|
|
288
|
+
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) => {
|
|
285
289
|
try {
|
|
290
|
+
if (opts.force) {
|
|
291
|
+
try {
|
|
292
|
+
const existingId = loadSessionId();
|
|
293
|
+
await api.closeSession(existingId);
|
|
294
|
+
clearSessionId();
|
|
295
|
+
} catch {
|
|
296
|
+
clearSessionId();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
286
299
|
const state = await api.createSession(opts.url);
|
|
287
300
|
saveSessionId(state.session_id);
|
|
288
301
|
console.log(formatLaunch(state));
|