@optima-chat/browser-cli 0.25.0 → 0.25.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 +19 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -200,7 +200,7 @@ function conversationHeader() {
200
200
  const conv = conversationId();
201
201
  return conv ? { "X-Optima-Conversation": conv } : {};
202
202
  }
203
- async function request(path, options = {}) {
203
+ async function request(path, options = {}, originalTaskConversation) {
204
204
  const url = `${BROWSER_API_URL}${path}`;
205
205
  const auth = authHeader();
206
206
  let response;
@@ -210,7 +210,7 @@ async function request(path, options = {}) {
210
210
  headers: {
211
211
  "Content-Type": "application/json",
212
212
  ...auth,
213
- ...conversationHeader(),
213
+ ...originalTaskConversation === void 0 ? conversationHeader() : originalTaskConversation === null ? {} : { "X-Optima-Conversation": originalTaskConversation },
214
214
  ...options.headers
215
215
  }
216
216
  });
@@ -450,8 +450,20 @@ var BrowserAPI = class {
450
450
  body: JSON.stringify(payload)
451
451
  });
452
452
  }
453
+ async settleScriptTaskSession(taskId) {
454
+ const task = await this.getScriptTask(taskId);
455
+ const proof = task.execution_evidence;
456
+ if (task.id !== taskId || !["failed", "cancelled", "needs_fallback", "completed"].includes(task.status) || !proof || proof.protocol !== "script-execution/v1" || proof.task_id !== taskId || proof.worker_ended !== true || !(proof.conversation === null || typeof proof.conversation === "string")) {
457
+ throw new Error("Original task execution/conversation unresolved; refusing session settlement");
458
+ }
459
+ return request(
460
+ `/api/script-tasks/${encodeURIComponent(taskId)}/settle-session`,
461
+ { method: "POST" },
462
+ proof.conversation
463
+ );
464
+ }
453
465
  async getScriptTask(taskId) {
454
- return request(`/api/script-tasks/${taskId}`);
466
+ return request(`/api/script-tasks/${encodeURIComponent(taskId)}`);
455
467
  }
456
468
  async sourceCapabilities() {
457
469
  return request(`/api/script-source-capabilities`);
@@ -1227,7 +1239,7 @@ ${downloadHint(result)}`);
1227
1239
  process.exit(1);
1228
1240
  }
1229
1241
  });
1230
- program2.command("script-task").argument("<task-id>", "Task ID").description("Check script task status").option("--download [path]", "Save the task's exported file (default: ./<filename>)").option("--json", "Print the raw task (status / error / full output) as JSON").option(
1242
+ program2.command("script-task").argument("<task-id>", "Task ID").description("Check script task status").option("--settle-session", "Read the original task, then settle its ended channel under its server-recorded conversation; keeps the current session and never classifies publication").option("--download [path]", "Save the task's exported file (default: ./<filename>)").option("--json", "Print the raw task (status / error / full output) as JSON").option(
1231
1243
  "--wait",
1232
1244
  `Block until the task finishes (completed / failed / needs_fallback), at most --timeout seconds. Exit code: 0 completed, 2 failed / needs_fallback, 3 still running (call again), 4 waiting for the store owner (e.g. captcha; tell them, then --wait --through-human), 1 error`
1233
1245
  ).option("--through-human", "With --wait: keep waiting while the script waits for the store owner (exit 4 otherwise)").option("--timeout <seconds>", `With --wait: max seconds to wait (default ${WAIT_DEFAULT_TIMEOUT_S}, max ${WAIT_MAX_TIMEOUT_S})`).action(async (taskId, opts) => {
@@ -1237,6 +1249,7 @@ ${downloadHint(result)}`);
1237
1249
  }
1238
1250
  if (opts.timeout !== void 0 && !opts.wait) throw new Error("--timeout \u53EA\u80FD\u548C --wait \u4E00\u8D77\u7528");
1239
1251
  if (opts.throughHuman && !opts.wait) throw new Error("--through-human \u53EA\u80FD\u548C --wait \u4E00\u8D77\u7528");
1252
+ if (opts.settleSession && (opts.wait || opts.download !== void 0)) throw new Error("--settle-session cannot combine with --wait/--download");
1240
1253
  const timeoutS = opts.timeout === void 0 ? WAIT_DEFAULT_TIMEOUT_S : parseWaitTimeout(opts.timeout);
1241
1254
  let task;
1242
1255
  if (opts.wait) {
@@ -1255,12 +1268,12 @@ ${downloadHint(result)}`);
1255
1268
  return;
1256
1269
  }
1257
1270
  } else {
1258
- task = await api.getScriptTask(taskId);
1271
+ task = opts.settleSession ? await api.settleScriptTaskSession(taskId) : await api.getScriptTask(taskId);
1259
1272
  }
1260
1273
  const stoppedExit = () => {
1261
1274
  if (opts.wait && task.status !== "completed") process.exit(EXIT_TASK_STOPPED);
1262
1275
  };
1263
- if (task.status === "needs_fallback" && task.session_id) saveSessionId(task.session_id);
1276
+ if (!opts.settleSession && task.status === "needs_fallback" && task.session_id) saveSessionId(task.session_id);
1264
1277
  if (opts.json) {
1265
1278
  console.log(JSON.stringify(task, null, 2));
1266
1279
  stoppedExit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {