@optima-chat/browser-cli 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +9 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -155,10 +155,11 @@ async function requestBinary(path) {
155
155
  return Buffer.from(arrayBuffer);
156
156
  }
157
157
  var BrowserAPI = class {
158
- async createSession(url, profileId) {
158
+ async createSession(url, profileId, force) {
159
159
  const body = {};
160
160
  if (url) body.url = url;
161
161
  if (profileId) body.profile_id = profileId;
162
+ if (force) body.force = true;
162
163
  return request("/api/sessions", {
163
164
  method: "POST",
164
165
  body: JSON.stringify(body)
@@ -331,10 +332,12 @@ var BrowserAPI = class {
331
332
  async deleteScript(name) {
332
333
  await request(`/api/scripts/${encodeURIComponent(name)}`, { method: "DELETE" });
333
334
  }
334
- async runScript(scriptName, params = {}) {
335
+ async runScript(scriptName, params = {}, profileId) {
336
+ const payload = { params };
337
+ if (profileId) payload.profile_id = profileId;
335
338
  return request(`/api/scripts/${encodeURIComponent(scriptName)}/run`, {
336
339
  method: "POST",
337
- body: JSON.stringify({ params })
340
+ body: JSON.stringify(payload)
338
341
  });
339
342
  }
340
343
  async getScriptTask(taskId) {
@@ -522,16 +525,7 @@ function formatProfileDelete(profileId) {
522
525
  function registerLifecycleCommands(program2) {
523
526
  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) => {
524
527
  try {
525
- if (opts.force) {
526
- try {
527
- const existingId = loadSessionId();
528
- await api.closeSession(existingId);
529
- clearSessionId();
530
- } catch {
531
- clearSessionId();
532
- }
533
- }
534
- const state = await api.createSession(opts.url, opts.profile);
528
+ const state = await api.createSession(opts.url, opts.profile, opts.force);
535
529
  saveSessionId(state.session_id);
536
530
  console.log(formatLaunch(state));
537
531
  } catch (err) {
@@ -1132,7 +1126,7 @@ function registerScriptCommands(program2) {
1132
1126
  process.exit(1);
1133
1127
  }
1134
1128
  });
1135
- program2.command("runscript").argument("<name>", "Script name").description("Run a script (polls until complete)").option("--param <params...>", "Parameters as key=value").option("--no-poll", "Return immediately without polling").action(async (name, opts) => {
1129
+ program2.command("runscript").argument("<name>", "Script name").description("Run a script (polls until complete)").option("--param <params...>", "Parameters as key=value").option("--profile <id>", "Use a named browser profile").option("--no-poll", "Return immediately without polling").action(async (name, opts) => {
1136
1130
  try {
1137
1131
  const params = {};
1138
1132
  if (opts.param) {
@@ -1142,7 +1136,7 @@ function registerScriptCommands(program2) {
1142
1136
  }
1143
1137
  }
1144
1138
  clearSessionId();
1145
- const task = await api.runScript(name, params);
1139
+ const task = await api.runScript(name, params, opts.profile);
1146
1140
  console.log(`Script started (task: ${task.id})`);
1147
1141
  if (!opts.poll) {
1148
1142
  console.log(`Poll with: browser-cli script-task ${task.id}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {