@opencode/browse 0.0.11-dev.71 → 0.0.11-dev.73

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  opencodeBrowserVersion2,
3
3
  opencodeBrowserBuildId2
4
- } from "./main-gss8ctxx.mjs";
4
+ } from "./main-wyynrqg7.mjs";
5
5
  import {
6
6
  dataRoot,
7
7
  oldStoreMarker,
@@ -19,7 +19,7 @@ import {
19
19
  setStoredMode,
20
20
  autoUpdateStatus,
21
21
  createAutoUpdater
22
- } from "./main-srh04zzr.mjs";
22
+ } from "./main-rm734baq.mjs";
23
23
  import {
24
24
  extensionProtocolVersion,
25
25
  minExtensionProtocolVersion,
@@ -44,7 +44,7 @@ import {
44
44
  relayToken,
45
45
  secretsEqual,
46
46
  ensurePrivateDirectory
47
- } from "./main-ha41fhf2.mjs";
47
+ } from "./main-2v53xfxr.mjs";
48
48
  import {
49
49
  withDefault,
50
50
  option,
@@ -98,7 +98,7 @@ import {
98
98
  isRestrictedTarget2,
99
99
  isRestrictedUrl2,
100
100
  dataUrlDocument2
101
- } from "./main-3hpn75c3.mjs";
101
+ } from "./main-gcmshzpr.mjs";
102
102
  import {
103
103
  relayHostname,
104
104
  isLocalPeer,
@@ -120,7 +120,7 @@ import {
120
120
  wrapToken,
121
121
  installedDevExtension,
122
122
  syncDevExtension
123
- } from "./main-jfqp0hfn.mjs";
123
+ } from "./main-6nwq3ezr.mjs";
124
124
  import {
125
125
  makeUnsafe,
126
126
  SettingsInputError,
@@ -148,16 +148,16 @@ import {
148
148
  checkNavigationUrl,
149
149
  readSecret,
150
150
  secretText
151
- } from "./main-f7j9dybj.mjs";
151
+ } from "./main-rnc3f5wr.mjs";
152
152
  import {
153
153
  defaultJournalBaseDir,
154
154
  makeJournalEntry,
155
155
  appendJournalEntry,
156
156
  startJournalRetention
157
- } from "./main-7j6g3ehy.mjs";
157
+ } from "./main-5fwb3tjm.mjs";
158
158
  import {
159
159
  createUpdateWatcher2
160
- } from "./main-hn9dbnbe.mjs";
160
+ } from "./main-mkt65nqy.mjs";
161
161
  import {
162
162
  isNone,
163
163
  isSome,
@@ -397,7 +397,7 @@ class ExtensionRpc {
397
397
  const replies = this.replies;
398
398
  const message = { ...command, id };
399
399
  let completed = false;
400
- const timeoutMs = awaitsPagePromise(command) ? undefined : command.method === "ping" ? 4000 : command.method === "debugger.sendCommand" ? this.timeouts.debuggerCommandTimeoutMs ?? 60000 : this.timeouts.commandTimeoutMs ?? 15000;
400
+ const timeoutMs = awaitsPagePromise(command) ? this.timeouts.awaitPromiseTimeoutMs ?? 5 * 60000 : command.method === "ping" ? 4000 : command.method === "debugger.sendCommand" ? this.timeouts.debuggerCommandTimeoutMs ?? 60000 : this.timeouts.commandTimeoutMs ?? 15000;
401
401
  const finish = (effect) => {
402
402
  if (completed) {
403
403
  return;
@@ -407,7 +407,7 @@ class ExtensionRpc {
407
407
  this.pendingRequests.delete(id);
408
408
  resume(effect);
409
409
  };
410
- const timeout = timeoutMs === undefined ? undefined : setTimeout(() => {
410
+ const timeout = setTimeout(() => {
411
411
  if (command.method === "ping") {
412
412
  if (this.replies !== replies)
413
413
  return finish(succeed6({}));
@@ -11272,7 +11272,10 @@ class RelayShutdown {
11272
11272
  yield* all([control.options.drain, control.idle.await], { concurrency: "unbounded" });
11273
11273
  yield* control.idle.await;
11274
11274
  yield* control.options.settle;
11275
- });
11275
+ }).pipe(timeoutOrElse({
11276
+ duration: control.options.timeoutMs ?? 1e4,
11277
+ orElse: () => fail4(control.busyError("timeout"))
11278
+ }));
11276
11279
  }
11277
11280
  close() {
11278
11281
  const control = this;
@@ -11902,6 +11905,14 @@ function executeInSession(ctx, options) {
11902
11905
  }
11903
11906
 
11904
11907
  // src/session-manager.ts
11908
+ var mcpSessionPattern = /^mcp-[0-9a-f]{8}$/i;
11909
+ function isMcpSession(id) {
11910
+ return mcpSessionPattern.test(id);
11911
+ }
11912
+ function isAutoNamedSession(id) {
11913
+ return isMcpSession(id) || /^[a-z]+-[a-z]+-\d{3}$/.test(id) || id.startsWith("oc-");
11914
+ }
11915
+
11905
11916
  class OpenCodeBrowserSessions {
11906
11917
  endpointUrl;
11907
11918
  sessions = new Map;
@@ -12230,6 +12241,8 @@ class OpenCodeBrowserSessions {
12230
12241
  session.allowedOrigins = existing.allowedOrigins;
12231
12242
  if (existing.browser)
12232
12243
  session.browser = existing.browser;
12244
+ if (existing.clientPid !== undefined)
12245
+ session.clientPid = existing.clientPid;
12233
12246
  manager.sessions.set(id, session);
12234
12247
  yield* manager.admission.commitPersistence(() => sync2(() => {
12235
12248
  manager.sessions.set(id, existing);
@@ -12333,6 +12346,8 @@ class OpenCodeBrowserSessions {
12333
12346
  const now = options.now ?? Date.now();
12334
12347
  const reaped = [];
12335
12348
  for (const session of Array.from(manager.sessions.values())) {
12349
+ if (!isAutoNamedSession(session.id))
12350
+ continue;
12336
12351
  if (manager.isExecuting(session.id) || manager.hasPendingWork(session.id) || session.sandbox.networkStatus().active) {
12337
12352
  continue;
12338
12353
  }
@@ -12345,8 +12360,7 @@ class OpenCodeBrowserSessions {
12345
12360
  targetIds.add(session.target.id);
12346
12361
  if (Array.from(targetIds).some((id) => options.isTargetBusy?.(id)))
12347
12362
  continue;
12348
- const autoNamed = /^mcp-[0-9a-f]{6,}$/i.test(session.id) || /^[a-z]+-[a-z]+-\d{3}$/.test(session.id) || session.id.startsWith("oc-");
12349
- const done = yield* (autoNamed ? manager.delete(session.id).pipe(map5((r) => r.deleted)) : manager.reset(session.id).pipe(map5(Boolean))).pipe(orElseSucceed(() => false));
12363
+ const done = yield* manager.delete(session.id).pipe(map5((result) => result.deleted), orElseSucceed(() => false));
12350
12364
  if (done)
12351
12365
  reaped.push(session.id);
12352
12366
  }
@@ -12473,10 +12487,9 @@ class OpenCodeBrowserSessions {
12473
12487
  const pending = Array.from(sessionRelayTargetIds(this.hooks, session)).filter((id) => !closed.has(id));
12474
12488
  if (pending.length === 0)
12475
12489
  return;
12476
- for (const targetId of pending) {
12477
- yield* this.closeRelayTarget(targetId).pipe(ignore);
12490
+ yield* forEach(pending, (targetId) => this.closeRelayTarget(targetId).pipe(ignore, andThen(sync2(() => {
12478
12491
  closed.add(targetId);
12479
- }
12492
+ }))), { concurrency: 4, discard: true });
12480
12493
  }
12481
12494
  });
12482
12495
  }
@@ -15912,6 +15925,17 @@ class ExtensionHandshake {
15912
15925
  }
15913
15926
 
15914
15927
  // src/relay/housekeeping.ts
15928
+ function tabIsBusy(tabId, deps) {
15929
+ if (deps.handoffs.pendingForTab(tabId) !== undefined || deps.isTabRecorded(tabId))
15930
+ return true;
15931
+ const sessionId = deps.registry.getRootTargetByTabId(tabId)?.opencodeBrowserSessionId;
15932
+ if (sessionId === undefined)
15933
+ return false;
15934
+ const session = deps.sessions.sessions.get(sessionId);
15935
+ if (!session)
15936
+ return false;
15937
+ return deps.sessions.isExecuting(sessionId) || deps.sessions.hasPendingWork(sessionId) || session.sandbox.networkStatus().active;
15938
+ }
15915
15939
  function createRelayHousekeeping(options) {
15916
15940
  const {
15917
15941
  instanceId,
@@ -15952,18 +15976,19 @@ function createRelayHousekeeping(options) {
15952
15976
  sendToEveryBrowser({ method: "update.notice", ...notice ? { params: { summary: notice.summary, command: notice.command } } : {} });
15953
15977
  };
15954
15978
  const releaseRelayTarget = fnUntraced(function* (targetId) {
15979
+ const first = registry.targetsByTargetId.get(targetId);
15980
+ if (!first || first.owner !== "relay")
15981
+ return;
15955
15982
  const deadline = (yield* currentTimeMillis2) + releaseTargetGraceMs;
15956
15983
  while (true) {
15957
15984
  const target = registry.targetsByTargetId.get(targetId);
15958
- const link = target ? browsers.browserTab(target.tabId)?.link : undefined;
15959
- if (target && link && (link.rpc.connected || link.rpc.protocolLegacy === true)) {
15960
- if (target.owner !== "relay")
15961
- return;
15985
+ if (!target || target.owner !== "relay")
15986
+ return;
15987
+ const link = browsers.browserTab(target.tabId)?.link;
15988
+ if (link && (link.rpc.connected || link.rpc.protocolLegacy === true)) {
15962
15989
  yield* sendToExtension({ method: "tabs.remove", params: { tabId: target.tabId } });
15963
15990
  return;
15964
15991
  }
15965
- if (link?.rpc.connected && link.rpc.protocolLegacy === false)
15966
- return;
15967
15992
  const remaining = deadline - (yield* currentTimeMillis2);
15968
15993
  if (remaining <= 0)
15969
15994
  return;
@@ -16028,7 +16053,7 @@ function createRelayHousekeeping(options) {
16028
16053
  runPromise(gen(function* () {
16029
16054
  if (yield* sessions.networkEnd(id, `its client (process ${pid}) exited`))
16030
16055
  relayLog("session.capture.ended", { session: id, reason: "client gone", pid });
16031
- if (!/^mcp-[0-9a-f]{8}$/.test(id) || sessions.isExecuting(id) || sessions.hasPendingWork(id))
16056
+ if (!isMcpSession(id) || sessions.isExecuting(id) || sessions.hasPendingWork(id))
16032
16057
  return;
16033
16058
  const tabs = registry.listRootTargets().filter((target) => target.opencodeBrowserSessionId === id).map((target) => target.tabId);
16034
16059
  if (tabs.some((tabId) => handoffs.pendingForTab(tabId) || isTabRecorded(tabId)))
@@ -16048,9 +16073,7 @@ function createRelayHousekeeping(options) {
16048
16073
  const noteAgentActivity = () => {
16049
16074
  lastAgentActivity = Date.now();
16050
16075
  };
16051
- function isTabBusy(tabId) {
16052
- return handoffs.pendingForTab(tabId) !== undefined || isTabRecorded(tabId) || Array.from(sessions.sessions.keys()).some((id) => sessions.isExecuting(id) || sessions.hasPendingWork(id) || sessions.sessions.get(id)?.sandbox.networkStatus().active);
16053
- }
16076
+ const isTabBusy = (tabId) => tabIsBusy(tabId, { registry, sessions, handoffs, isTabRecorded });
16054
16077
  const detachIdleUserTarget = fnUntraced(function* (targetId) {
16055
16078
  const target = registry.targetsByTargetId.get(targetId);
16056
16079
  if (!target || target.owner !== "user" || isTabBusy(target.tabId))
@@ -16944,7 +16967,14 @@ class SessionCatalog {
16944
16967
  return sessions;
16945
16968
  } catch (error) {
16946
16969
  const detail = error instanceof Error && error.message ? `: ${error.message}` : "";
16947
- throw new Error(`Could not decode browse session catalog at ${this.filePath}${detail}`, { cause: error });
16970
+ const corruptPath = `${this.filePath}.corrupt-${Date.now()}`;
16971
+ try {
16972
+ await fs14.rename(this.filePath, corruptPath);
16973
+ console.error(`Browse session catalog at ${this.filePath} was unreadable${detail}; moved it to ${corruptPath} and started with no saved sessions`);
16974
+ } catch (moveError) {
16975
+ console.error(`Browse session catalog at ${this.filePath} was unreadable${detail}; could not move it aside (${moveError instanceof Error ? moveError.message : String(moveError)}), starting with no saved sessions`);
16976
+ }
16977
+ return [];
16948
16978
  }
16949
16979
  }
16950
16980
  async save(sessions) {
@@ -1,4 +1,4 @@
1
- import"./main-gss8ctxx.mjs";
1
+ import"./main-wyynrqg7.mjs";
2
2
  import {
3
3
  cliCommand,
4
4
  installCommand,
@@ -18,15 +18,15 @@ import {
18
18
  installVersion,
19
19
  pruneVersions,
20
20
  switchVersion
21
- } from "./main-srh04zzr.mjs";
21
+ } from "./main-rm734baq.mjs";
22
22
  import"./main-mrew6jy8.mjs";
23
23
  import {
24
24
  Service,
25
25
  layerFetch,
26
26
  restartRelay,
27
27
  startManagedRelay
28
- } from "./main-3hpn75c3.mjs";
29
- import"./main-ha41fhf2.mjs";
28
+ } from "./main-gcmshzpr.mjs";
29
+ import"./main-2v53xfxr.mjs";
30
30
  import {
31
31
  succeed6,
32
32
  suspend2,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  opencodeBrowserVersion2,
3
3
  opencodeBrowserBuildId2
4
- } from "./main-gss8ctxx.mjs";
4
+ } from "./main-wyynrqg7.mjs";
5
5
  import {
6
6
  dataRoot,
7
7
  oldStoreMarker,
@@ -26,10 +26,10 @@ import {
26
26
  installVersion,
27
27
  pruneVersions,
28
28
  switchVersion
29
- } from "./main-srh04zzr.mjs";
29
+ } from "./main-rm734baq.mjs";
30
30
  import {
31
31
  relayAuthorization
32
- } from "./main-ha41fhf2.mjs";
32
+ } from "./main-2v53xfxr.mjs";
33
33
  import {
34
34
  parseHostname,
35
35
  readRelayConfig,
@@ -46,7 +46,7 @@ import {
46
46
  legacyPairingCode,
47
47
  removeLegacyPairingCode,
48
48
  syncDevExtension
49
- } from "./main-jfqp0hfn.mjs";
49
+ } from "./main-6nwq3ezr.mjs";
50
50
  import {
51
51
  unpackedExtensionId,
52
52
  extensionProtocolSkew,
@@ -12147,7 +12147,7 @@ async function runSetup(command, args) {
12147
12147
  if (command === "set")
12148
12148
  return set(args);
12149
12149
  if (command === "rollback") {
12150
- const { runRollback } = await import("./runtime-update-nj2y79eq.mjs");
12150
+ const { runRollback } = await import("./runtime-update-5p996ppb.mjs");
12151
12151
  return runRollback(args);
12152
12152
  }
12153
12153
  }