viveworker 0.8.3 → 0.8.4

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/README.md CHANGED
@@ -284,6 +284,8 @@ Typical commands:
284
284
  - `npx viveworker share upload report.pdf --password "hunter2" --expires-days 7`
285
285
  - `npx viveworker share upload deck_standalone.html --no-optimize`
286
286
  - `npx viveworker share list`
287
+ - `npx viveworker share replace <slug> updated-report.html`
288
+ - `npx viveworker share update <slug> --file updated-report.html`
287
289
  - `npx viveworker share update <slug> --password "hunter2"`
288
290
  - `npx viveworker share update <slug> --expires-days 7`
289
291
  - `npx viveworker share link <slug>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viveworker",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Open mobile control surface for Codex, Claude, Thread Sharing, File Share, Moltbook, and A2A tasks on your trusted LAN.",
5
5
  "author": "Yuta Hoshino <hoshino.lireneo@gmail.com>",
6
6
  "license": "MIT",
@@ -9,7 +9,8 @@
9
9
  * Commands:
10
10
  * viveworker share upload <file> [--password <pw>] [--price <usd> --pay-to <0x…>] [--expires-days <n>] [--no-optimize] [--json]
11
11
  * viveworker share list [--json]
12
- * viveworker share update <slug> [--password <pw>] [--no-password] [--price <usd>] [--no-price] [--pay-to <0x…>] [--expires-days <n>] [--json]
12
+ * viveworker share update <slug> [--file <file>] [--password <pw>] [--no-password] [--price <usd>] [--no-price] [--pay-to <0x…>] [--expires-days <n>] [--no-optimize] [--json]
13
+ * viveworker share replace <slug> <file> [--expires-days <n>] [--no-optimize] [--json]
13
14
  * viveworker share link <slug> --password <pw> [--ttl-hours <n>] [--json]
14
15
  * viveworker share pay <url> [--output <file>] [--dry-run] [--wallet eoa|hazbase] [--no-approval] [--json]
15
16
  * viveworker share delete <slug>
@@ -80,6 +81,8 @@ export async function runShareCli(args) {
80
81
  return handleList(args.slice(1));
81
82
  case "update":
82
83
  return handleUpdate(args.slice(1));
84
+ case "replace":
85
+ return handleReplace(args.slice(1));
83
86
  case "link":
84
87
  return handleLink(args.slice(1));
85
88
  case "pay":
@@ -99,7 +102,8 @@ function printHelp() {
99
102
  console.log("Commands:");
100
103
  console.log(" viveworker share upload <file> [--password <pw>] [--price <usd> --pay-to <0x…>] [--expires-days <n>] [--no-optimize] [--json]");
101
104
  console.log(" viveworker share list [--metrics] [--json]");
102
- console.log(" viveworker share update <slug> [--password <pw>] [--no-password] [--price <usd>] [--no-price] [--pay-to <0x…>] [--expires-days <n>] [--json]");
105
+ console.log(" viveworker share update <slug> [--file <file>] [--password <pw>] [--no-password] [--price <usd>] [--no-price] [--pay-to <0x…>] [--expires-days <n>] [--no-optimize] [--json]");
106
+ console.log(" viveworker share replace <slug> <file> [--expires-days <n>] [--no-optimize] [--json]");
103
107
  console.log(" viveworker share link <slug> --password <pw> [--ttl-hours <n>] [--json]");
104
108
  console.log(" viveworker share pay <url> [--output <file>] [--dry-run] [--no-approval] [--json]");
105
109
  console.log(" viveworker share delete <slug>");
@@ -133,28 +137,6 @@ async function handleUpload(args) {
133
137
  throw new Error("Usage: viveworker share upload <file> [--password <pw>] [--expires-days <n>]");
134
138
  }
135
139
 
136
- const absolute = path.resolve(filePath);
137
- let stat;
138
- try {
139
- stat = await fs.stat(absolute);
140
- } catch {
141
- throw new Error(`File not found: ${filePath}`);
142
- }
143
- if (!stat.isFile()) {
144
- throw new Error(`Not a regular file: ${filePath}`);
145
- }
146
- if (stat.size === 0) {
147
- throw new Error(`File is empty: ${filePath}`);
148
- }
149
- const ext = path.extname(absolute).toLowerCase();
150
- if (!ALLOWED_EXTENSIONS.includes(ext)) {
151
- throw new Error(
152
- `Accepted file types: ${ALLOWED_EXTENSIONS.join(" / ")}. ` +
153
- `Got: ${ext || "(no extension)"}`
154
- );
155
- }
156
- const { mime } = SHARE_TYPES[ext];
157
-
158
140
  const password = flags["password"] || "";
159
141
  const expiresDays = flags["expires-days"] || flags["expiresDays"] || "";
160
142
  const price = flags["price"] || "";
@@ -190,21 +172,10 @@ async function handleUpload(args) {
190
172
 
191
173
  const { apiKey, userId, shareUrl } = await resolveCredentials();
192
174
 
193
- const originalBytes = await fs.readFile(absolute);
194
- const optimization =
195
- flags["no-optimize"] || flags["noOptimize"]
196
- ? { bytes: originalBytes, info: null }
197
- : maybeOptimizeUpload({ absolute, ext, bytes: originalBytes });
198
- const bytes = optimization.bytes;
199
- if (bytes.length > MAX_FILE_SIZE) {
200
- const detail = optimization.info
201
- ? ` after optimization to ${formatSize(bytes.length)}`
202
- : "";
203
- throw new Error(`File too large (${originalBytes.length} bytes, max ${MAX_FILE_SIZE})${detail}`);
204
- }
175
+ const preparedFile = await prepareShareFile(filePath, flags);
205
176
  const form = new FormData();
206
- const blob = new Blob([bytes], { type: mime });
207
- const file = new File([blob], path.basename(absolute), { type: mime });
177
+ const blob = new Blob([preparedFile.bytes], { type: preparedFile.mime });
178
+ const file = new File([blob], path.basename(preparedFile.absolute), { type: preparedFile.mime });
208
179
  form.set("file", file);
209
180
  if (password) form.set("password", password);
210
181
  if (expiresDays) form.set("expiresDays", String(expiresDays));
@@ -233,14 +204,14 @@ async function handleUpload(args) {
233
204
  }
234
205
 
235
206
  console.log("");
236
- console.log(`✅ Uploaded ${body.originalName || path.basename(absolute)} (${formatSize(body.size)})`);
207
+ console.log(`✅ Uploaded ${body.originalName || path.basename(preparedFile.absolute)} (${formatSize(body.size)})`);
237
208
  console.log("");
238
- if (optimization.info) {
209
+ if (preparedFile.optimization.info) {
239
210
  console.log(
240
- ` Optimized HTML: ${formatSize(optimization.info.originalBytes)} → ${formatSize(optimization.info.optimizedBytes)}`
211
+ ` Optimized HTML: ${formatSize(preparedFile.optimization.info.originalBytes)} → ${formatSize(preparedFile.optimization.info.optimizedBytes)}`
241
212
  );
242
213
  console.log(
243
- ` Removed embedded fonts: ${optimization.info.removedFonts}`
214
+ ` Removed embedded fonts: ${preparedFile.optimization.info.removedFonts}`
244
215
  );
245
216
  console.log("");
246
217
  }
@@ -262,6 +233,44 @@ async function handleUpload(args) {
262
233
  console.log("");
263
234
  }
264
235
 
236
+ async function prepareShareFile(filePath, flags = {}) {
237
+ const absolute = path.resolve(String(filePath || ""));
238
+ let stat;
239
+ try {
240
+ stat = await fs.stat(absolute);
241
+ } catch {
242
+ throw new Error(`File not found: ${filePath}`);
243
+ }
244
+ if (!stat.isFile()) {
245
+ throw new Error(`Not a regular file: ${filePath}`);
246
+ }
247
+ if (stat.size === 0) {
248
+ throw new Error(`File is empty: ${filePath}`);
249
+ }
250
+ const ext = path.extname(absolute).toLowerCase();
251
+ if (!ALLOWED_EXTENSIONS.includes(ext)) {
252
+ throw new Error(
253
+ `Accepted file types: ${ALLOWED_EXTENSIONS.join(" / ")}. ` +
254
+ `Got: ${ext || "(no extension)"}`
255
+ );
256
+ }
257
+ const { mime } = SHARE_TYPES[ext];
258
+ const originalBytes = await fs.readFile(absolute);
259
+ const optimization =
260
+ flags["no-optimize"] || flags["noOptimize"]
261
+ ? { bytes: originalBytes, info: null }
262
+ : maybeOptimizeUpload({ absolute, ext, bytes: originalBytes });
263
+ const bytes = optimization.bytes;
264
+ if (bytes.length > MAX_FILE_SIZE) {
265
+ const detail = optimization.info
266
+ ? ` after optimization to ${formatSize(bytes.length)}`
267
+ : "";
268
+ throw new Error(`File too large (${originalBytes.length} bytes, max ${MAX_FILE_SIZE})${detail}`);
269
+ }
270
+
271
+ return { absolute, ext, mime, bytes, optimization };
272
+ }
273
+
265
274
  function maybeOptimizeUpload({ absolute, ext, bytes }) {
266
275
  if (ext !== ".html" && ext !== ".htm") {
267
276
  return { bytes, info: null };
@@ -506,15 +515,34 @@ function printMetricsSection(metrics, err) {
506
515
 
507
516
  async function handleUpdate(args) {
508
517
  const flags = parseFlags(args);
518
+ return handleUpdateWithFlags(flags, "update");
519
+ }
520
+
521
+ async function handleReplace(args) {
522
+ const flags = parseFlags(args);
523
+ const slug = flags._[0];
524
+ const filePath = flags._[1] || flags.file || flags.f;
525
+ if (!slug || !filePath || flags._.length > 2) {
526
+ throw new Error("Usage: viveworker share replace <slug> <file> [--expires-days <n>] [--no-optimize] [--json]");
527
+ }
528
+ flags._ = [slug];
529
+ flags.file = filePath;
530
+ return handleUpdateWithFlags(flags, "replace");
531
+ }
532
+
533
+ async function handleUpdateWithFlags(flags, mode = "update") {
509
534
  const slug = flags._[0];
510
535
  if (!slug) {
511
536
  throw new Error(
512
- "Usage: viveworker share update <slug> [--password <pw>] [--no-password] [--price <usd>] [--no-price] [--pay-to <0x…>] [--expires-days <n>]"
537
+ "Usage: viveworker share update <slug> [--file <file>] [--password <pw>] [--no-password] [--price <usd>] [--no-price] [--pay-to <0x…>] [--expires-days <n>] [--no-optimize]"
513
538
  );
514
539
  }
515
540
  if (!/^[A-Za-z0-9]+$/.test(slug)) {
516
541
  throw new Error(`Invalid slug: ${slug}`);
517
542
  }
543
+ if (flags._.length > 1) {
544
+ throw new Error("Unexpected positional argument. Use `share replace <slug> <file>` or `share update <slug> --file <file>`.");
545
+ }
518
546
 
519
547
  const hasPassword = Object.prototype.hasOwnProperty.call(flags, "password");
520
548
  const hasNoPassword = Object.prototype.hasOwnProperty.call(flags, "no-password");
@@ -525,6 +553,9 @@ async function handleUpdate(args) {
525
553
  Object.prototype.hasOwnProperty.call(flags, "noPrice");
526
554
  const hasPayTo = Object.prototype.hasOwnProperty.call(flags, "pay-to") ||
527
555
  Object.prototype.hasOwnProperty.call(flags, "payTo");
556
+ const hasFile = Object.prototype.hasOwnProperty.call(flags, "file") ||
557
+ Object.prototype.hasOwnProperty.call(flags, "f");
558
+ const filePath = flags.file || flags.f || "";
528
559
 
529
560
  if (hasPassword && hasNoPassword) {
530
561
  throw new Error("Pass either --password OR --no-password, not both");
@@ -535,9 +566,12 @@ async function handleUpdate(args) {
535
566
  if (hasPrice && hasPassword) {
536
567
  throw new Error("--price and --password cannot be combined on a single share");
537
568
  }
538
- if (!hasPassword && !hasNoPassword && !hasExpires && !hasPrice && !hasNoPrice && !hasPayTo) {
569
+ if (hasFile && (typeof filePath !== "string" || filePath.length === 0)) {
570
+ throw new Error("--file requires a path");
571
+ }
572
+ if (!hasPassword && !hasNoPassword && !hasExpires && !hasPrice && !hasNoPrice && !hasPayTo && !hasFile) {
539
573
  throw new Error(
540
- "Nothing to update — specify at least one of --password <pw>, --no-password, --price <usd>, --no-price, --pay-to <0x…>, --expires-days <n>"
574
+ "Nothing to update — specify at least one of --file <file>, --password <pw>, --no-password, --price <usd>, --no-price, --pay-to <0x…>, --expires-days <n>"
541
575
  );
542
576
  }
543
577
 
@@ -603,19 +637,44 @@ async function handleUpdate(args) {
603
637
 
604
638
  const { apiKey, userId, shareUrl } = await resolveCredentials();
605
639
 
606
- const res = await fetchWithTimeout(`${shareUrl}/api/share/${encodeURIComponent(slug)}`, {
607
- method: "PATCH",
608
- headers: {
640
+ let preparedFile = null;
641
+ let requestBody;
642
+ let requestHeaders;
643
+ let timeoutMs;
644
+ if (hasFile) {
645
+ preparedFile = await prepareShareFile(filePath, flags);
646
+ const form = new FormData();
647
+ const blob = new Blob([preparedFile.bytes], { type: preparedFile.mime });
648
+ const file = new File([blob], path.basename(preparedFile.absolute), { type: preparedFile.mime });
649
+ form.set("file", file);
650
+ for (const [key, value] of Object.entries(body)) {
651
+ form.set(key, value === null ? "" : String(value));
652
+ }
653
+ requestBody = form;
654
+ requestHeaders = {
655
+ "x-a2a-user": userId,
656
+ "x-a2a-key": apiKey,
657
+ };
658
+ timeoutMs = 60_000;
659
+ } else {
660
+ requestBody = JSON.stringify(body);
661
+ requestHeaders = {
609
662
  "content-type": "application/json",
610
663
  "x-a2a-user": userId,
611
664
  "x-a2a-key": apiKey,
612
- },
613
- body: JSON.stringify(body),
614
- }, 30_000);
665
+ };
666
+ timeoutMs = 30_000;
667
+ }
668
+
669
+ const res = await fetchWithTimeout(`${shareUrl}/api/share/${encodeURIComponent(slug)}`, {
670
+ method: "PATCH",
671
+ headers: requestHeaders,
672
+ body: requestBody,
673
+ }, timeoutMs);
615
674
 
616
675
  const respBody = await readJson(res);
617
676
  if (!res.ok || respBody.error) {
618
- throw new Error(formatApiError("Update", res.status, respBody));
677
+ throw new Error(formatApiError(mode === "replace" ? "Replace" : "Update", res.status, respBody));
619
678
  }
620
679
 
621
680
  if (flags.json) {
@@ -624,17 +683,25 @@ async function handleUpdate(args) {
624
683
  }
625
684
 
626
685
  console.log("");
627
- console.log(`✅ Updated ${slug}`);
686
+ console.log(hasFile ? `✅ Replaced file for ${slug}` : `✅ Updated ${slug}`);
628
687
  console.log("");
629
688
  console.log(` ${respBody.url}`);
630
689
  console.log("");
690
+ if (hasFile) {
691
+ console.log(` File: ${respBody.originalName || path.basename(preparedFile.absolute)} (${formatSize(respBody.size || preparedFile.bytes.length)})`);
692
+ if (preparedFile.optimization.info) {
693
+ console.log(
694
+ ` Optimized HTML: ${formatSize(preparedFile.optimization.info.originalBytes)} → ${formatSize(preparedFile.optimization.info.optimizedBytes)}`
695
+ );
696
+ }
697
+ }
631
698
  if (respBody.hasPassword) {
632
699
  console.log(` 🔒 Password-protected${hasPassword ? " (existing unlock cookies invalidated)" : ""}`);
633
700
  } else if (hasNoPassword) {
634
701
  console.log(` 🔓 Password removed`);
635
702
  }
636
703
  if (respBody.price && respBody.payTo) {
637
- const rotated = hasPrice ? " (paid sessions invalidated)" : "";
704
+ const rotated = hasPrice || respBody.paymentSessionsInvalidated ? " (paid sessions invalidated)" : "";
638
705
  console.log(
639
706
  ` 💰 Paid — ${formatUsdc(respBody.price)} USDC on ${respBody.network || "?"} → ${respBody.payTo}${rotated}`
640
707
  );
@@ -1181,6 +1248,12 @@ function formatApiError(op, status, body) {
1181
1248
  return `${op} failed (${status}): file count exceeded — ${body.current}/${body.max}. Delete something first.`;
1182
1249
  case "file-too-large":
1183
1250
  return `${op} failed (${status}): file too large (max ${formatSize(body.maxBytes)})`;
1251
+ case "empty-file":
1252
+ return `${op} failed (${status}): file is empty`;
1253
+ case "invalid-form-data":
1254
+ return `${op} failed (${status}): invalid multipart form data`;
1255
+ case "invalid-file-field":
1256
+ return `${op} failed (${status}): invalid file field`;
1184
1257
  case "unsupported-extension":
1185
1258
  return `${op} failed (${status}): unsupported file type. Accepted: ${(body.allowed || []).join(" / ") || "n/a"}`;
1186
1259
  case "unsupported-content-type":
@@ -9631,6 +9631,15 @@ function isStartTurnAckTimeout(errorValue) {
9631
9631
  message === "turn/start-timeout";
9632
9632
  }
9633
9633
 
9634
+ function isIpcNoClientFoundError(errorValue) {
9635
+ const message = normalizeIpcErrorMessage(errorValue).toLowerCase();
9636
+ return message === "no-client-found" ||
9637
+ message === "client-not-found" ||
9638
+ message === "target-client-not-found" ||
9639
+ message.includes("no client found") ||
9640
+ message.includes("client not found");
9641
+ }
9642
+
9634
9643
  function buildDefaultCollaborationMode(threadState) {
9635
9644
  // Fallback turns must leave Plan mode unless the caller explicitly opts in.
9636
9645
  return buildRequestedCollaborationMode(threadState, "default");
@@ -9749,14 +9758,36 @@ class NativeIpcClient {
9749
9758
  );
9750
9759
  }
9751
9760
 
9752
- sendThreadFollowerRequest(method, params, conversationId, ownerClientId = null, options = {}) {
9753
- return this.sendRequest(method, params, {
9754
- targetClientId:
9755
- ownerClientId ??
9756
- this.runtime.threadOwnerClientIds.get(conversationId) ??
9757
- null,
9758
- ...options,
9759
- });
9761
+ async sendThreadFollowerRequest(method, params, conversationId, ownerClientId = null, options = {}) {
9762
+ const targetClientId =
9763
+ ownerClientId ??
9764
+ this.runtime.threadOwnerClientIds.get(conversationId) ??
9765
+ null;
9766
+
9767
+ try {
9768
+ return await this.sendRequest(method, params, {
9769
+ targetClientId,
9770
+ ...options,
9771
+ });
9772
+ } catch (error) {
9773
+ if (!targetClientId || !isIpcNoClientFoundError(error)) {
9774
+ throw error;
9775
+ }
9776
+
9777
+ const mappedOwner = this.runtime.threadOwnerClientIds.get(conversationId) ?? null;
9778
+ if (mappedOwner === targetClientId) {
9779
+ this.runtime.threadOwnerClientIds.delete(conversationId);
9780
+ }
9781
+ console.warn(
9782
+ `[ipc] stale owner client for thread=${cleanText(conversationId || "") || "unknown"} ` +
9783
+ `target=${cleanText(targetClientId || "") || "unknown"} method=${cleanText(method || "") || "unknown"}; retrying without target`
9784
+ );
9785
+
9786
+ return this.sendRequest(method, params, {
9787
+ ...options,
9788
+ targetClientId: null,
9789
+ });
9790
+ }
9760
9791
  }
9761
9792
 
9762
9793
  sendRequest(method, params, options = {}) {
@@ -19041,6 +19072,9 @@ if (url.pathname === "/api/hazbase/logout" && req.method === "POST") {
19041
19072
  if (error.message === "codex-ipc-not-connected") {
19042
19073
  return writeJson(res, 503, { error: error.message });
19043
19074
  }
19075
+ if (isIpcNoClientFoundError(error)) {
19076
+ return writeJson(res, 503, { error: "codex-client-not-found" });
19077
+ }
19044
19078
  return writeJson(res, 500, { error: error.message });
19045
19079
  }
19046
19080
  }
package/web/app.js CHANGED
@@ -43,6 +43,7 @@ const DETAIL_REFRESH_FALLBACK_TIMEOUT_MS = 2_500;
43
43
  const DETAIL_STICKY_LAN_PROBE_TIMEOUT_MS = 350;
44
44
  const COMPLETION_REPLY_SEND_TIMEOUT_MS = 22_000;
45
45
  const COMPLETION_REPLY_OPTIMISTIC_SENT_MS = 1_600;
46
+ const LAN_FETCH_TIMEOUT_MESSAGE = "LAN fetch timed out";
46
47
  const TIMELINE_REFRESH_TIMEOUT_MS = 8_000;
47
48
  const TIMELINE_POLL_TIMEOUT_MS = 4_500;
48
49
  const FAST_POLL_STEP_TIMEOUT_MS = 4_500;
@@ -2755,6 +2756,11 @@ function completionReplyWarningMatchesSentText(error, text, attachmentCount = 0)
2755
2756
  return Boolean(warningText && sentText && warningText === sentText);
2756
2757
  }
2757
2758
 
2759
+ function isCompletionReplyLateNetworkResult(error) {
2760
+ return error?.errorKey === "request-timeout" ||
2761
+ error?.message === LAN_FETCH_TIMEOUT_MESSAGE;
2762
+ }
2763
+
2758
2764
  function normalizeCompletionReplyAttachments(values) {
2759
2765
  const rawValues = Array.isArray(values)
2760
2766
  ? values
@@ -10027,7 +10033,7 @@ for (const button of document.querySelectorAll("[data-wallet-address-copy]")) {
10027
10033
  } catch (error) {
10028
10034
  const optimisticDraft = getCompletionReplyDraft(token);
10029
10035
  if (
10030
- error.errorKey === "request-timeout" &&
10036
+ isCompletionReplyLateNetworkResult(error) &&
10031
10037
  optimisticDraft.collapsedAfterSend &&
10032
10038
  optimisticDraft.sentText === text
10033
10039
  ) {
@@ -11504,6 +11510,7 @@ function localizeApiError(value) {
11504
11510
  "completion-reply-image-limit": "error.completionReplyImageLimit",
11505
11511
  "completion-reply-image-invalid-upload": "error.completionReplyImageInvalidUpload",
11506
11512
  "codex-ipc-not-connected": "error.codexIpcNotConnected",
11513
+ "codex-client-not-found": "error.codexClientNotFound",
11507
11514
  "approval-not-found": "error.approvalNotFound",
11508
11515
  "approval-already-handled": "error.approvalAlreadyHandled",
11509
11516
  "plan-request-not-found": "error.planRequestNotFound",
package/web/build-id.js CHANGED
@@ -1 +1 @@
1
- export const APP_BUILD_ID = "20260509-remote-lan-relay-guard";
1
+ export const APP_BUILD_ID = "20260514-lan-timeout-reply-ack";
package/web/i18n.js CHANGED
@@ -758,6 +758,7 @@ const translations = {
758
758
  "error.completionReplyImageLimit": "Attach up to {count} images at a time.",
759
759
  "error.completionReplyImageInvalidUpload": "That image could not be uploaded.",
760
760
  "error.codexIpcNotConnected": "Codex desktop is not connected right now.",
761
+ "error.codexClientNotFound": "Codex changed its active client. Reopen the thread on your PC and try again.",
761
762
  "error.approvalNotFound": "This approval is no longer available.",
762
763
  "error.approvalAlreadyHandled": "This approval was already handled.",
763
764
  "error.planRequestNotFound": "This plan request is no longer available.",
@@ -1835,6 +1836,7 @@ const translations = {
1835
1836
  "error.completionReplyImageLimit": "画像は最大 {count} 枚まで添付できます。",
1836
1837
  "error.completionReplyImageInvalidUpload": "この画像はアップロードできませんでした。",
1837
1838
  "error.codexIpcNotConnected": "いまは Codex desktop に接続できていません。",
1839
+ "error.codexClientNotFound": "Codex 側の接続先が切り替わりました。PC で対象スレッドを開き直して、もう一度送信してください。",
1838
1840
  "error.approvalNotFound": "この承認はもう利用できません。",
1839
1841
  "error.approvalAlreadyHandled": "この承認はすでに処理済みです。",
1840
1842
  "error.planRequestNotFound": "このプラン確認はもう利用できません。",
@@ -88,6 +88,7 @@ const DEFAULT_FAILURE_WINDOW_MS = 60_000;
88
88
  const DEFAULT_FAILURE_THRESHOLD = 4;
89
89
  const DEFAULT_CIRCUIT_BREAKER_MS = 60_000;
90
90
  const DEFAULT_MAX_CIRCUIT_BREAKER_MS = 10 * 60_000;
91
+ const DEFAULT_STABLE_CONNECTION_MS = 15_000;
91
92
  const DEFAULT_PROLOGUE = new TextEncoder().encode("viveworker/remote-pairing/v1");
92
93
 
93
94
  // CloseEvent codes we emit. 1000 is normal; 4xxx is application-defined.
@@ -121,6 +122,7 @@ const CLOSE_RELAY_RESET_SESSION = 4004;
121
122
  * @property {number} [failureThreshold]
122
123
  * @property {number} [circuitBreakerMs]
123
124
  * @property {number} [maxCircuitBreakerMs]
125
+ * @property {number} [stableConnectionMs]
124
126
  * @property {typeof WebSocket} [WebSocketImpl] injectable for Node-side tests
125
127
  * @property {{debug?: Function, warn?: Function}} [logger]
126
128
  */
@@ -166,6 +168,7 @@ export class RemotePairingTransport {
166
168
  this._failureThreshold = opts.failureThreshold ?? DEFAULT_FAILURE_THRESHOLD;
167
169
  this._circuitBreakerMs = opts.circuitBreakerMs ?? DEFAULT_CIRCUIT_BREAKER_MS;
168
170
  this._maxCircuitBreakerMs = opts.maxCircuitBreakerMs ?? DEFAULT_MAX_CIRCUIT_BREAKER_MS;
171
+ this._stableConnectionMs = opts.stableConnectionMs ?? DEFAULT_STABLE_CONNECTION_MS;
169
172
 
170
173
  this._WebSocketImpl = opts.WebSocketImpl ?? globalThis.WebSocket;
171
174
  if (typeof this._WebSocketImpl !== "function") {
@@ -200,6 +203,8 @@ export class RemotePairingTransport {
200
203
  this._pingTimer = null;
201
204
  /** @type {ReturnType<typeof setTimeout> | null} */
202
205
  this._handshakeTimer = null;
206
+ /** @type {ReturnType<typeof setTimeout> | null} */
207
+ this._stableConnectionTimer = null;
203
208
  /** @type {number[]} recent reconnect-triggering failures. */
204
209
  this._recentFailureAtMs = [];
205
210
  /** If > Date.now(), reconnect attempts are intentionally delayed. */
@@ -317,6 +322,7 @@ export class RemotePairingTransport {
317
322
  this._closed = true;
318
323
  this._started = false;
319
324
  this._cancelReconnectTimer();
325
+ this._cancelStableConnectionTimer();
320
326
  this._stopPing();
321
327
  this._stopHandshakeTimer();
322
328
  if (this._ws) {
@@ -682,6 +688,24 @@ export class RemotePairingTransport {
682
688
  }
683
689
  }
684
690
 
691
+ _scheduleStableConnectionReset() {
692
+ const delay = Math.max(0, Number(this._stableConnectionMs) || 0);
693
+ this._stableConnectionTimer = setTimeout(() => {
694
+ this._stableConnectionTimer = null;
695
+ if (this._closed || this._state !== STATE.CONNECTED) return;
696
+ this._recentFailureAtMs = [];
697
+ this._circuitOpenUntilMs = 0;
698
+ this._circuitOpenCount = 0;
699
+ }, delay);
700
+ }
701
+
702
+ _cancelStableConnectionTimer() {
703
+ if (this._stableConnectionTimer != null) {
704
+ clearTimeout(this._stableConnectionTimer);
705
+ this._stableConnectionTimer = null;
706
+ }
707
+ }
708
+
685
709
  _startPing() {
686
710
  this._stopPing();
687
711
  this._pingTimer = setInterval(() => {
@@ -742,11 +766,10 @@ export class RemotePairingTransport {
742
766
  if (this._state === newState) return;
743
767
  const prev = this._state;
744
768
  this._state = newState;
769
+ this._cancelStableConnectionTimer();
745
770
  if (newState === STATE.CONNECTED) {
746
771
  this._reconnectAttempt = 0;
747
- this._recentFailureAtMs = [];
748
- this._circuitOpenUntilMs = 0;
749
- this._circuitOpenCount = 0;
772
+ this._scheduleStableConnectionReset();
750
773
  }
751
774
  try {
752
775
  this._onStateChange(newState, prev, info);
@@ -771,6 +794,7 @@ export class RemotePairingTransport {
771
794
  this._stopPing();
772
795
  this._stopHandshakeTimer();
773
796
  this._cancelReconnectTimer();
797
+ this._cancelStableConnectionTimer();
774
798
  if (this._ws) {
775
799
  try { this._ws.close(CLOSE_FATAL, "fatal-error"); } catch {}
776
800
  this._ws = null;