@openacp/cli 2026.408.1 → 2026.408.2

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/cli.js CHANGED
@@ -5716,7 +5716,7 @@ var init_openacp = __esm({
5716
5716
  this.startHeartbeat();
5717
5717
  return this.publicUrl;
5718
5718
  }
5719
- async stop(force = false) {
5719
+ async stop(force = false, preserveState = false) {
5720
5720
  this.stopHeartbeat();
5721
5721
  const child = this.child;
5722
5722
  const tunnelId = this.tunnelId;
@@ -5732,7 +5732,7 @@ var init_openacp = __esm({
5732
5732
  child.once("exit", () => clearTimeout(killTimer));
5733
5733
  }
5734
5734
  }
5735
- if (tunnelId) {
5735
+ if (tunnelId && !preserveState) {
5736
5736
  this.deleteFromWorker(tunnelId).catch((err) => {
5737
5737
  log8.warn({ err: err.message }, "Failed to delete tunnel from worker");
5738
5738
  });
@@ -5740,7 +5740,7 @@ var init_openacp = __esm({
5740
5740
  delete all[String(localPort)];
5741
5741
  await this.storage.set(STORAGE_KEY, all);
5742
5742
  }
5743
- log8.info({ localPort }, "OpenACP tunnel stopped");
5743
+ log8.info({ localPort, preserveState }, "OpenACP tunnel stopped");
5744
5744
  }
5745
5745
  getPublicUrl() {
5746
5746
  return this.publicUrl;
@@ -5783,6 +5783,16 @@ var init_openacp = __esm({
5783
5783
  return;
5784
5784
  }
5785
5785
  this.child = child;
5786
+ const onData = (data) => {
5787
+ const line = data.toString();
5788
+ if (/Registered tunnel connection/.test(line)) {
5789
+ clearTimeout(timeout);
5790
+ log8.info({ port }, "cloudflared connection registered");
5791
+ settle(resolve8);
5792
+ }
5793
+ };
5794
+ child.stdout?.on("data", onData);
5795
+ child.stderr?.on("data", onData);
5786
5796
  child.on("error", (err) => {
5787
5797
  clearTimeout(timeout);
5788
5798
  settle(() => reject(new Error(`cloudflared failed to start: ${err.message}`)));
@@ -6059,19 +6069,24 @@ var init_tunnel_registry = __esm({
6059
6069
  }
6060
6070
  }
6061
6071
  async shutdown() {
6072
+ if (this.shuttingDown) return;
6062
6073
  this.keepalive.stop();
6063
6074
  this.shuttingDown = true;
6075
+ if (this.saveTimeout) {
6076
+ clearTimeout(this.saveTimeout);
6077
+ this.saveTimeout = null;
6078
+ }
6064
6079
  const stopPromises = [];
6065
6080
  for (const [, live] of this.entries) {
6066
6081
  if (live.retryTimer) clearTimeout(live.retryTimer);
6067
6082
  if (live.process) {
6068
- stopPromises.push(live.process.stop(true).catch(() => {
6083
+ stopPromises.push(live.process.stop(true, true).catch(() => {
6069
6084
  }));
6070
6085
  }
6071
6086
  }
6072
6087
  await Promise.all(stopPromises);
6088
+ this.save();
6073
6089
  this.entries.clear();
6074
- this.scheduleSave();
6075
6090
  }
6076
6091
  list(includeSystem = false) {
6077
6092
  const entries = Array.from(this.entries.values()).map((l) => l.entry);
@@ -6096,16 +6111,20 @@ var init_tunnel_registry = __esm({
6096
6111
  const raw = JSON.parse(fs16.readFileSync(this.registryPath, "utf-8"));
6097
6112
  log9.info({ count: raw.length }, "Restoring tunnels");
6098
6113
  const userEntries = raw.filter((e) => e.type === "user");
6099
- for (const persisted of userEntries) {
6100
- try {
6101
- await this.add(persisted.port, {
6114
+ const results = await Promise.allSettled(
6115
+ userEntries.map(
6116
+ (persisted) => this.add(persisted.port, {
6102
6117
  type: persisted.type,
6103
6118
  provider: persisted.provider,
6104
- label: persisted.label,
6105
- sessionId: persisted.sessionId
6106
- });
6107
- } catch (err) {
6108
- log9.warn({ port: persisted.port, err: err.message }, "Failed to restore tunnel");
6119
+ label: persisted.label
6120
+ // sessionId intentionally omitted — sessions don't survive restart
6121
+ })
6122
+ )
6123
+ );
6124
+ for (let i = 0; i < results.length; i++) {
6125
+ if (results[i].status === "rejected") {
6126
+ const reason = results[i].reason;
6127
+ log9.warn({ port: userEntries[i].port, err: reason.message }, "Failed to restore tunnel");
6109
6128
  }
6110
6129
  }
6111
6130
  } catch (err) {
@@ -6163,7 +6182,9 @@ var init_tunnel_registry = __esm({
6163
6182
  clearTimeout(this.saveTimeout);
6164
6183
  this.saveTimeout = null;
6165
6184
  }
6166
- this.save();
6185
+ if (!this.shuttingDown) {
6186
+ this.save();
6187
+ }
6167
6188
  }
6168
6189
  };
6169
6190
  }
@@ -8293,7 +8314,9 @@ var init_sessions = __esm({
8293
8314
  sourceAdapterId: z.string().optional(),
8294
8315
  responseAdapterId: z.string().nullable().optional(),
8295
8316
  // Optional file attachments; each decoded and stored via FileService
8296
- attachments: z.array(AttachmentInputSchema).max(10).optional()
8317
+ attachments: z.array(AttachmentInputSchema).max(10).optional(),
8318
+ // Client-provided turnId to avoid SSE echo race condition
8319
+ turnId: z.string().max(64).optional()
8297
8320
  });
8298
8321
  PermissionResponseBodySchema = z.object({
8299
8322
  permissionId: z.string().min(1).max(200),
@@ -8490,7 +8513,7 @@ async function sessionRoutes(app, deps) {
8490
8513
  attachments = await resolveAttachments(fileService, sessionId, body.attachments);
8491
8514
  }
8492
8515
  const sourceAdapterId = body.sourceAdapterId ?? "api";
8493
- const turnId = nanoid2(8);
8516
+ const turnId = body.turnId ?? nanoid2(8);
8494
8517
  deps.core.eventBus.emit(BusEvent.MESSAGE_QUEUED, {
8495
8518
  sessionId,
8496
8519
  turnId,
@@ -19303,6 +19326,12 @@ function resolveAgentCommand(cmd) {
19303
19326
  }
19304
19327
  } catch {
19305
19328
  }
19329
+ if (cmd === "npx" || cmd === "uvx") {
19330
+ const sibling = path44.join(path44.dirname(process.execPath), cmd);
19331
+ if (fs40.existsSync(sibling)) {
19332
+ return { command: sibling, args: [] };
19333
+ }
19334
+ }
19306
19335
  return { command: cmd, args: [] };
19307
19336
  }
19308
19337
  var log31, AgentInstance;