oysterun 1.6.0-beta.37 → 1.6.0-beta.39
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/dev/client/connectivity/diagnostic-error-message.d.mts +1 -0
- package/dev/client/connectivity/diagnostic-error-message.mjs +22 -0
- package/dev/client/connectivity/managed-host-browser.d.mts +3 -0
- package/dev/client/connectivity/managed-host-browser.mjs +271 -19
- package/dev/client/connectivity/phone-chat-swipe.mjs +18 -0
- package/dev/client/connectivity/session-switch-deadline.mjs +203 -0
- package/dev/client/connectivity/stopped-session-token.mjs +82 -0
- package/dev/client/connectivity/test-p508-session-switch-deadline.mjs +343 -0
- package/dev/client/web-chat/dist/assets/{ReactPrism-BQLzibYJ.js → ReactPrism-BMvm_4Sd.js} +1 -1
- package/dev/client/web-chat/dist/assets/{ReactPrism-BQLzibYJ.js.map → ReactPrism-BMvm_4Sd.js.map} +1 -1
- package/dev/client/web-chat/dist/assets/TerminalSurface-83CMtDbQ.js +59 -0
- package/dev/client/web-chat/dist/assets/TerminalSurface-83CMtDbQ.js.map +1 -0
- package/dev/client/web-chat/dist/assets/{index-5kL-BJtt.js → index-BukD9ETd.js} +2 -2
- package/dev/client/web-chat/dist/assets/{index-5kL-BJtt.js.map → index-BukD9ETd.js.map} +1 -1
- package/dev/client/web-chat/dist/assets/index-CDgI-O86.js +1 -0
- package/dev/client/web-chat/dist/assets/index-CDgI-O86.js.map +1 -0
- package/dev/client/web-chat/dist/assets/index-C_po1Kez.js +2 -0
- package/dev/client/web-chat/dist/assets/index-C_po1Kez.js.map +1 -0
- package/dev/client/web-chat/dist/assets/{index-BOITwSCu.js → index-mWzPv7k9.js} +1 -1
- package/dev/client/web-chat/dist/assets/{index-BOITwSCu.js.map → index-mWzPv7k9.js.map} +1 -1
- package/dev/client/web-chat/dist/assets/{matrix-entry-C0de1lFo.css → matrix-entry-6Fxm8R3m.css} +1 -1
- package/dev/client/web-chat/dist/assets/{matrix-entry-BUYlg-cC.js → matrix-entry-C25j0qP9.js} +194 -188
- package/dev/client/web-chat/dist/assets/matrix-entry-C25j0qP9.js.map +1 -0
- package/dev/client/web-chat/dist/assets/{pdf-CMJ22bXX.js → pdf-DyrCAP06.js} +3 -3
- package/dev/client/web-chat/dist/assets/pdf-DyrCAP06.js.map +1 -0
- package/dev/client/web-chat/dist/assets/{web-adGuzdwy.js → web-C0lJ0ykc.js} +1 -1
- package/dev/client/web-chat/dist/assets/{web-adGuzdwy.js.map → web-C0lJ0ykc.js.map} +1 -1
- package/dev/client/web-chat/dist/assets/{web-b6yQ-GX-.js → web-DqF5TOnI.js} +1 -1
- package/dev/client/web-chat/dist/assets/{web-b6yQ-GX-.js.map → web-DqF5TOnI.js.map} +1 -1
- package/dev/client/web-chat/dist/index.html +120 -1
- package/docs/routec/host_setup.md +37 -2
- package/docs/routec/prev_page_map.md +11 -2
- package/host-service/cli/linux-boot-autostart.mjs +69 -0
- package/host-service/cli/run-host-lifecycle.mjs +5 -1
- package/host-service/connectivity/webrtc-signaling-service.mjs +20 -1
- package/host-service/frp-agent.mjs +129 -2
- package/host-service/host-port-resolution.mjs +28 -5
- package/host-service/lifecycle-result.mjs +5 -1
- package/host-service/linux-boot-autostart.mjs +242 -0
- package/host-service/log-retention.mjs +8 -3
- package/host-service/manual-p037-turn-data-plane.mjs +257 -0
- package/host-service/manual-p066-production-copy-qualification.mjs +540 -0
- package/host-service/matrix-facade.mjs +90 -0
- package/host-service/node-npm-runtime-identity.mjs +2 -0
- package/host-service/onboard.mjs +4 -0
- package/host-service/package.json +3 -4
- package/host-service/provider-command-detection.mjs +37 -0
- package/host-service/provider-model-refresh-runner.mjs +41 -0
- package/host-service/refusal-observability.mjs +200 -0
- package/host-service/routec-matrix-media-store.mjs +127 -9
- package/host-service/routec-p135-semantic-bridge-pacing.mjs +77 -0
- package/host-service/server.mjs +243 -73
- package/host-service/session-list-preview-write-helper.mjs +44 -0
- package/host-service/setup-provider-model-defaults.mjs +6 -1
- package/host-service/setup.mjs +11 -0
- package/host-service/telegram-bridge.mjs +2 -1
- package/host-service/test-fixtures/fake-codex-provider.mjs +24 -0
- package/package.json +1 -1
- package/static/site/404/en/index.html +16 -2
- package/static/site/404/zh/index.html +16 -2
- package/static/site/assets/site.css +59 -0
- package/static/site/blog/en/index.html +17 -3
- package/static/site/blog/generated_manifest.json +8 -8
- package/static/site/blog/voice-input-model-experiment/en/index.html +16 -2
- package/static/site/blog/voice-input-model-experiment/zh/index.html +16 -2
- package/static/site/blog/zh/index.html +17 -3
- package/static/site/docs/choose-and-recover-a-provider/en/index.html +19 -5
- package/static/site/docs/choose-and-recover-a-provider/zh/index.html +19 -5
- package/static/site/docs/configure-session-files-and-settings/en/index.html +19 -5
- package/static/site/docs/configure-session-files-and-settings/zh/index.html +19 -5
- package/static/site/docs/generated_manifest.json +58 -72
- package/static/site/docs/host-authentication-and-connection/en/index.html +19 -5
- package/static/site/docs/host-authentication-and-connection/zh/index.html +19 -5
- package/static/site/docs/install-and-use-a-skill/en/index.html +19 -5
- package/static/site/docs/install-and-use-a-skill/zh/index.html +19 -5
- package/static/site/docs/read-large-tool-results/en/index.html +19 -5
- package/static/site/docs/read-large-tool-results/zh/index.html +19 -5
- package/static/site/docs/recover-from-a-host-runtime-error/en/index.html +19 -5
- package/static/site/docs/recover-from-a-host-runtime-error/zh/index.html +19 -5
- package/static/site/docs/restore-work-after-a-host-restart/en/index.html +19 -5
- package/static/site/docs/restore-work-after-a-host-restart/zh/index.html +19 -5
- package/static/site/docs/search-index.json +96 -0
- package/static/site/docs/send-images-and-media/en/index.html +19 -5
- package/static/site/docs/send-images-and-media/zh/index.html +19 -5
- package/static/site/docs/set-up-and-understand-a-host/en/index.html +19 -5
- package/static/site/docs/set-up-and-understand-a-host/zh/index.html +19 -5
- package/static/site/docs/understand-agent-activity/en/index.html +19 -5
- package/static/site/docs/understand-agent-activity/zh/index.html +19 -5
- package/static/site/docs/use-the-oysterun-cli-safely/en/index.html +19 -5
- package/static/site/docs/use-the-oysterun-cli-safely/zh/index.html +19 -5
- package/static/site/en/index.html +17 -3
- package/static/site/en/index.md +2 -2
- package/static/site/faq/en/index.html +17 -3
- package/static/site/faq/en/index.md +1 -1
- package/static/site/faq/zh/index.html +17 -3
- package/static/site/faq/zh/index.md +1 -1
- package/static/site/getting-started/en/index.html +95 -76
- package/static/site/getting-started/en/index.md +18 -18
- package/static/site/getting-started/zh/index.html +100 -58
- package/static/site/getting-started/zh/index.md +47 -16
- package/static/site/guides/en/index.html +148 -0
- package/static/site/guides/en/index.md +1 -0
- package/static/site/guides/example/en/index.html +152 -0
- package/static/site/guides/example/en/index.md +11 -0
- package/static/site/guides/example/en/media/example.mp4 +0 -0
- package/static/site/guides/example/en/media/example.png +0 -0
- package/static/site/guides/example/zh/index.html +152 -0
- package/static/site/guides/example/zh/index.md +11 -0
- package/static/site/guides/example/zh/media/example.mp4 +0 -0
- package/static/site/guides/example/zh/media/example.png +0 -0
- package/static/site/guides/zh/index.html +148 -0
- package/static/site/guides/zh/index.md +1 -0
- package/static/site/install.sh +4 -2
- package/static/site/llms.txt +15 -2
- package/static/site/overview/en/index.html +16 -2
- package/static/site/overview/zh/index.html +16 -2
- package/static/site/privacy/en/index.html +16 -2
- package/static/site/privacy/zh/index.html +16 -2
- package/static/site/reference/example/en/index.html +150 -0
- package/static/site/reference/example/en/index.md +5 -0
- package/static/site/reference/example/zh/index.html +150 -0
- package/static/site/reference/example/zh/index.md +5 -0
- package/static/site/sitemap.xml +50 -10
- package/static/site/tutorials/en/index.html +148 -0
- package/static/site/tutorials/en/index.md +1 -0
- package/static/site/tutorials/example/en/index.html +150 -0
- package/static/site/tutorials/example/en/index.md +5 -0
- package/static/site/tutorials/example/zh/index.html +150 -0
- package/static/site/tutorials/example/zh/index.md +5 -0
- package/static/site/tutorials/zh/index.html +148 -0
- package/static/site/tutorials/zh/index.md +1 -0
- package/static/site/zh/index.html +17 -3
- package/static/site/zh/index.md +2 -2
- package/static/site_source/content/AGENTS.md +36 -1
- package/static/site_source/content/pages/getting-started/start/en.md +117 -0
- package/static/site_source/content/pages/getting-started/start/zh.md +117 -0
- package/static/site_source/content/pages/groups.json +9 -0
- package/static/site_source/content/pages/guides/example/en.md +24 -0
- package/static/site_source/content/pages/guides/example/media/example.mp4 +0 -0
- package/static/site_source/content/pages/guides/example/media/example.png +0 -0
- package/static/site_source/content/pages/guides/example/zh.md +24 -0
- package/static/site_source/content/pages/reference/example/en.md +18 -0
- package/static/site_source/content/pages/reference/example/zh.md +18 -0
- package/static/site_source/content/pages/tutorials/example/en.md +18 -0
- package/static/site_source/content/pages/tutorials/example/zh.md +18 -0
- package/static/site_source/downloads/install.sh +4 -2
- package/static/site_source/manifests/product_site_links.json +12 -0
- package/static/site_source/manifests/public_site.json +36 -3
- package/static/site_source/pages/faq/en.html +1 -1
- package/static/site_source/pages/faq/zh.html +1 -1
- package/static/site_source/pages/home/en.html +1 -1
- package/static/site_source/pages/home/zh.html +1 -1
- package/tool_scripts/install_oysterun_launch_agents.sh +5 -0
- package/tool_scripts/oysterun_npm_package_manifest.mjs +4 -2
- package/tool_scripts/oysterun_release_service.sh +104 -1
- package/tool_scripts/resolve_user_host_port.mjs +6 -3
- package/tool_scripts/start_oysterun.sh +8 -0
- package/tool_scripts/uninstall_oysterun_launch_agents.sh +4 -0
- package/dev/client/web-chat/dist/assets/TerminalSurface-UboWle1Y.js +0 -59
- package/dev/client/web-chat/dist/assets/TerminalSurface-UboWle1Y.js.map +0 -1
- package/dev/client/web-chat/dist/assets/index-1nZeDzD1.js +0 -1
- package/dev/client/web-chat/dist/assets/index-1nZeDzD1.js.map +0 -1
- package/dev/client/web-chat/dist/assets/index-CxVYmVx2.js +0 -2
- package/dev/client/web-chat/dist/assets/index-CxVYmVx2.js.map +0 -1
- package/dev/client/web-chat/dist/assets/matrix-entry-BUYlg-cC.js.map +0 -1
- package/dev/client/web-chat/dist/assets/pdf-CMJ22bXX.js.map +0 -1
- package/static/site/docs/en/index.html +0 -229
- package/static/site/docs/en/index.md +0 -31
- package/static/site/docs/index.html +0 -46
- package/static/site/docs/zh/index.html +0 -229
- package/static/site/docs/zh/index.md +0 -31
- package/static/site_source/pages/getting-started/en.html +0 -76
- package/static/site_source/pages/getting-started/zh.html +0 -53
- /package/tool_scripts/{test_environment_remote_cloud_deprovision.mjs → environment_remote_cloud_deprovision.mjs} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function boundedDiagnosticErrorMessage(value: unknown): string | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// P482: a failed Session switch is reported with its error message so the
|
|
2
|
+
// monitoring can tell authentication, not-permitted and connection errors
|
|
3
|
+
// apart. The message is bounded and scrubbed of anything that can carry a
|
|
4
|
+
// secret: bearer values, JWTs, Oysterun tokens, long opaque strings, query
|
|
5
|
+
// strings and URL credentials. Used by the browser and again by the Host.
|
|
6
|
+
const MAX_LENGTH = 160;
|
|
7
|
+
|
|
8
|
+
export function boundedDiagnosticErrorMessage(value) {
|
|
9
|
+
if (typeof value !== "string") return undefined;
|
|
10
|
+
const scrubbed = value
|
|
11
|
+
.replace(/\bBearer\s+\S+/gi, "Bearer [redacted]")
|
|
12
|
+
.replace(/\b[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, "[redacted]")
|
|
13
|
+
.replace(/\boysterun_[A-Za-z0-9_-]{6,}/gi, "[redacted]")
|
|
14
|
+
.replace(/\/\/[^/\s:@]+:[^/\s@]+@/g, "//[redacted]@")
|
|
15
|
+
.replace(/\?[^\s#]*/g, "?[redacted]")
|
|
16
|
+
.replace(/\b[A-Za-z0-9+/_-]{32,}={0,2}/g, "[redacted]")
|
|
17
|
+
.replace(/[\u0000-\u001f\u007f]+/g, " ")
|
|
18
|
+
.replace(/\s+/g, " ")
|
|
19
|
+
.trim()
|
|
20
|
+
.slice(0, MAX_LENGTH);
|
|
21
|
+
return scrubbed || undefined;
|
|
22
|
+
}
|
|
@@ -61,6 +61,9 @@ export function recordManagedHostMatrixSyncDiagnostic(
|
|
|
61
61
|
export function recordSessionSetupProviderCheckDiagnostic(
|
|
62
62
|
event: Record<string, unknown>
|
|
63
63
|
): void;
|
|
64
|
+
export function recordManagedHostBrowserDiagnostic(
|
|
65
|
+
event: Record<string, unknown>
|
|
66
|
+
): void;
|
|
64
67
|
export function managedHostFetch(
|
|
65
68
|
input: RequestInfo | URL,
|
|
66
69
|
init?: RequestInit,
|
|
@@ -5,8 +5,20 @@ import {
|
|
|
5
5
|
} from "./logical-host-connection.mjs";
|
|
6
6
|
import { createConnectivityRandomId } from "./random-id.mjs";
|
|
7
7
|
import { OysterunWebRtcLogicalTransport } from "./webrtc-logical-transport.mjs";
|
|
8
|
+
import { boundedDiagnosticErrorMessage } from "./diagnostic-error-message.mjs";
|
|
8
9
|
|
|
9
10
|
const DASHBOARD_TOKEN_KEY = "oysterun_token";
|
|
11
|
+
const FAILED_DIAGNOSTIC_BUFFER_KEY = "oysterun_failed_browser_diagnostics_v1";
|
|
12
|
+
const FAILED_DIAGNOSTIC_BUFFER_LIMIT = 20;
|
|
13
|
+
// The Host accepts these without a dashboard token (refusal-observability.mjs).
|
|
14
|
+
const P482_TOKENLESS_DIAGNOSTIC_EVENTS = new Set([
|
|
15
|
+
"session_switch_failed",
|
|
16
|
+
"browser_diagnostic_send_failed",
|
|
17
|
+
"browser_diagnostic_failures_resent",
|
|
18
|
+
"browser_visible_heartbeat",
|
|
19
|
+
"browser_page_frozen",
|
|
20
|
+
"browser_page_resumed",
|
|
21
|
+
]);
|
|
10
22
|
const REQUIRED_CHANNELS = Object.freeze(["control", "events", "bulk"]);
|
|
11
23
|
const SUPPORTED_TRANSPORT_PROTOCOL_VERSIONS = Object.freeze([1]);
|
|
12
24
|
const MANAGED_TRANSPORT_CONTRACT = "oysterun.managed_webrtc.v1";
|
|
@@ -81,6 +93,12 @@ export const REPORTED_DIAGNOSTIC_EVENTS = new Set([
|
|
|
81
93
|
"matrix_sync_loop_state",
|
|
82
94
|
"session_setup_provider_check_request",
|
|
83
95
|
"session_setup_provider_check_summary",
|
|
96
|
+
"session_switch_failed",
|
|
97
|
+
"browser_diagnostic_send_failed",
|
|
98
|
+
"browser_diagnostic_failures_resent",
|
|
99
|
+
"browser_visible_heartbeat",
|
|
100
|
+
"browser_page_frozen",
|
|
101
|
+
"browser_page_resumed",
|
|
84
102
|
]);
|
|
85
103
|
const MANAGED_WEBRTC_STAGE_FAILURE_CODES = Object.freeze({
|
|
86
104
|
configuration_fetch: "managed_webrtc_configuration_fetch_failed",
|
|
@@ -152,6 +170,12 @@ const DIAGNOSTIC_STRING_FIELDS = Object.freeze([
|
|
|
152
170
|
"app_state",
|
|
153
171
|
"page_section",
|
|
154
172
|
"health_failed_check",
|
|
173
|
+
"failure_kind",
|
|
174
|
+
"error_name",
|
|
175
|
+
"source",
|
|
176
|
+
"switch_source",
|
|
177
|
+
"target_session_id_hash",
|
|
178
|
+
"token_state",
|
|
155
179
|
]);
|
|
156
180
|
const DIAGNOSTIC_TIMESTAMP_FIELDS = Object.freeze(["started_at", "finished_at"]);
|
|
157
181
|
const DIAGNOSTIC_NUMBER_FIELDS = Object.freeze([
|
|
@@ -166,6 +190,7 @@ const DIAGNOSTIC_NUMBER_FIELDS = Object.freeze([
|
|
|
166
190
|
"since_app_entry_ms",
|
|
167
191
|
"status_code",
|
|
168
192
|
"request_count",
|
|
193
|
+
"buffered_count",
|
|
169
194
|
...MANAGED_WEBRTC_ATTEMPT_DIAGNOSTIC_FIELDS,
|
|
170
195
|
]);
|
|
171
196
|
|
|
@@ -963,6 +988,8 @@ export function sanitizeBrowserTransportDiagnostic(event) {
|
|
|
963
988
|
sanitized[field] = value;
|
|
964
989
|
}
|
|
965
990
|
}
|
|
991
|
+
const errorMessage = boundedDiagnosticErrorMessage(event.error_message);
|
|
992
|
+
if (errorMessage) sanitized.error_message = errorMessage;
|
|
966
993
|
for (const field of DIAGNOSTIC_NUMBER_FIELDS) {
|
|
967
994
|
const value = event[field];
|
|
968
995
|
if (Number.isInteger(value) && value >= 0 && value <= 2_678_400_000) {
|
|
@@ -972,6 +999,166 @@ export function sanitizeBrowserTransportDiagnostic(event) {
|
|
|
972
999
|
return sanitized;
|
|
973
1000
|
}
|
|
974
1001
|
|
|
1002
|
+
function readFailedDiagnosticBuffer() {
|
|
1003
|
+
try {
|
|
1004
|
+
const parsed = JSON.parse(
|
|
1005
|
+
globalThis.sessionStorage?.getItem(FAILED_DIAGNOSTIC_BUFFER_KEY) || "[]"
|
|
1006
|
+
);
|
|
1007
|
+
return Array.isArray(parsed)
|
|
1008
|
+
? parsed.slice(-FAILED_DIAGNOSTIC_BUFFER_LIMIT).filter((item) =>
|
|
1009
|
+
sanitizeBrowserTransportDiagnostic(item)
|
|
1010
|
+
)
|
|
1011
|
+
: [];
|
|
1012
|
+
} catch {
|
|
1013
|
+
return [];
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function writeFailedDiagnosticBuffer(buffer) {
|
|
1018
|
+
try {
|
|
1019
|
+
globalThis.sessionStorage?.setItem(
|
|
1020
|
+
FAILED_DIAGNOSTIC_BUFFER_KEY,
|
|
1021
|
+
JSON.stringify(buffer.slice(-FAILED_DIAGNOSTIC_BUFFER_LIMIT))
|
|
1022
|
+
);
|
|
1023
|
+
} catch {
|
|
1024
|
+
// Diagnostics never change browser behavior.
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// P482 correction 3: a 4xx the Host will give again (not auth, timeout or rate)
|
|
1029
|
+
// means the record itself is refused; keeping it would block every later resend.
|
|
1030
|
+
function isPermanentDiagnosticRefusal(error) {
|
|
1031
|
+
const status = error?.status;
|
|
1032
|
+
return (
|
|
1033
|
+
Number.isInteger(status) &&
|
|
1034
|
+
status >= 400 &&
|
|
1035
|
+
status < 500 &&
|
|
1036
|
+
![401, 403, 408, 429].includes(status)
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function droppedDiagnosticRecord(report, status) {
|
|
1041
|
+
// A drop record is never replaced by another one, so a refused drop record cannot loop.
|
|
1042
|
+
if (report?.failure_kind === "dropped_refused") return null;
|
|
1043
|
+
return sanitizeBrowserTransportDiagnostic({
|
|
1044
|
+
event_type: "browser_diagnostic_send_failed",
|
|
1045
|
+
failure_kind: "dropped_refused",
|
|
1046
|
+
status_code: status,
|
|
1047
|
+
token_state: getStoredDashboardToken() ? "present" : "absent",
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function classifyDiagnosticSendFailure(error) {
|
|
1052
|
+
if (error?.name === "AbortError") return "aborted";
|
|
1053
|
+
if (Number.isInteger(error?.status)) return "http";
|
|
1054
|
+
return "network";
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
async function postBrowserDiagnostic({ fetchImpl, origin, clientInstanceId, report }) {
|
|
1058
|
+
const token = getStoredDashboardToken();
|
|
1059
|
+
const response = await fetchImpl(`${origin}${SIGNALING_PATH_PREFIX}diagnostic`, {
|
|
1060
|
+
method: "POST",
|
|
1061
|
+
headers: {
|
|
1062
|
+
"Content-Type": "application/json",
|
|
1063
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
1064
|
+
},
|
|
1065
|
+
body: JSON.stringify({ client_instance_id: clientInstanceId, event: report }),
|
|
1066
|
+
credentials: "same-origin",
|
|
1067
|
+
});
|
|
1068
|
+
if (!response?.ok) {
|
|
1069
|
+
const error = new Error("Browser diagnostic endpoint refused the record");
|
|
1070
|
+
error.status = response?.status;
|
|
1071
|
+
throw error;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// Sends run one at a time, so overlapping sends never read and write the
|
|
1076
|
+
// buffer over each other; each resent item leaves the buffer as soon as it is sent.
|
|
1077
|
+
// With nothing in flight the request starts at once, as before.
|
|
1078
|
+
let browserDiagnosticSendChain = null;
|
|
1079
|
+
|
|
1080
|
+
function enqueueBrowserDiagnosticWork(work) {
|
|
1081
|
+
const run = browserDiagnosticSendChain ? browserDiagnosticSendChain.then(work) : work();
|
|
1082
|
+
const tail = Promise.resolve(run).catch(() => {});
|
|
1083
|
+
browserDiagnosticSendChain = tail;
|
|
1084
|
+
void tail.then(() => {
|
|
1085
|
+
if (browserDiagnosticSendChain === tail) browserDiagnosticSendChain = null;
|
|
1086
|
+
});
|
|
1087
|
+
return tail;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
export function sendBrowserDiagnostic(options) {
|
|
1091
|
+
return enqueueBrowserDiagnosticWork(() => sendBrowserDiagnosticNow(options));
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function failedDiagnosticRecord(failureKind, statusCode) {
|
|
1095
|
+
return sanitizeBrowserTransportDiagnostic({
|
|
1096
|
+
event_type: "browser_diagnostic_send_failed",
|
|
1097
|
+
failure_kind: failureKind,
|
|
1098
|
+
status_code: statusCode,
|
|
1099
|
+
token_state: getStoredDashboardToken() ? "present" : "absent",
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// P482 correction 2: while the Managed route is known to be unavailable the
|
|
1104
|
+
// record waits in the buffer, so a down Host gets no extra request.
|
|
1105
|
+
export function bufferBrowserDiagnostic(report) {
|
|
1106
|
+
return enqueueBrowserDiagnosticWork(() => {
|
|
1107
|
+
writeFailedDiagnosticBuffer([
|
|
1108
|
+
...readFailedDiagnosticBuffer(),
|
|
1109
|
+
report,
|
|
1110
|
+
failedDiagnosticRecord("host_unavailable"),
|
|
1111
|
+
].filter(Boolean));
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
async function sendBrowserDiagnosticNow(options) {
|
|
1116
|
+
try {
|
|
1117
|
+
await postBrowserDiagnostic(options);
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
if (isPermanentDiagnosticRefusal(error)) {
|
|
1120
|
+
const dropped = droppedDiagnosticRecord(options.report, error.status);
|
|
1121
|
+
if (dropped) writeFailedDiagnosticBuffer([...readFailedDiagnosticBuffer(), dropped]);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
const failure = sanitizeBrowserTransportDiagnostic({
|
|
1125
|
+
event_type: "browser_diagnostic_send_failed",
|
|
1126
|
+
failure_kind: classifyDiagnosticSendFailure(error),
|
|
1127
|
+
status_code: Number.isInteger(error?.status) ? error.status : undefined,
|
|
1128
|
+
token_state: getStoredDashboardToken() ? "present" : "absent",
|
|
1129
|
+
error_name: typeof error?.name === "string" ? error.name : "Error",
|
|
1130
|
+
});
|
|
1131
|
+
writeFailedDiagnosticBuffer([
|
|
1132
|
+
...readFailedDiagnosticBuffer(),
|
|
1133
|
+
options.report,
|
|
1134
|
+
...(failure ? [failure] : []),
|
|
1135
|
+
]);
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
let buffered = readFailedDiagnosticBuffer();
|
|
1139
|
+
if (buffered.length === 0) return;
|
|
1140
|
+
let resent = 0;
|
|
1141
|
+
while (buffered.length > 0) {
|
|
1142
|
+
const [head, ...rest] = buffered;
|
|
1143
|
+
try {
|
|
1144
|
+
await postBrowserDiagnostic({ ...options, report: head });
|
|
1145
|
+
resent += 1;
|
|
1146
|
+
buffered = rest;
|
|
1147
|
+
} catch (error) {
|
|
1148
|
+
if (!isPermanentDiagnosticRefusal(error)) throw error;
|
|
1149
|
+
const dropped = droppedDiagnosticRecord(head, error.status);
|
|
1150
|
+
buffered = dropped ? [...rest, dropped] : rest;
|
|
1151
|
+
}
|
|
1152
|
+
writeFailedDiagnosticBuffer(buffered);
|
|
1153
|
+
}
|
|
1154
|
+
const summary = sanitizeBrowserTransportDiagnostic({
|
|
1155
|
+
event_type: "browser_diagnostic_failures_resent",
|
|
1156
|
+
buffered_count: resent,
|
|
1157
|
+
token_state: getStoredDashboardToken() ? "present" : "absent",
|
|
1158
|
+
});
|
|
1159
|
+
if (summary) await postBrowserDiagnostic({ ...options, report: summary });
|
|
1160
|
+
}
|
|
1161
|
+
|
|
975
1162
|
function normalizeManagedIceTransportPolicy(value) {
|
|
976
1163
|
if (value === undefined || value === null || value === "") return "all";
|
|
977
1164
|
if (value === "all" || value === "relay") return value;
|
|
@@ -1156,19 +1343,12 @@ export class DirectHostBrowserConnection {
|
|
|
1156
1343
|
const report = sanitizeBrowserTransportDiagnostic(event);
|
|
1157
1344
|
if (!report) return;
|
|
1158
1345
|
this.clientInstanceId ??= getClientInstanceId();
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
},
|
|
1166
|
-
body: JSON.stringify({
|
|
1167
|
-
client_instance_id: this.clientInstanceId,
|
|
1168
|
-
event: report,
|
|
1169
|
-
}),
|
|
1170
|
-
credentials: "same-origin",
|
|
1171
|
-
}).catch(() => {});
|
|
1346
|
+
void sendBrowserDiagnostic({
|
|
1347
|
+
fetchImpl: this.fetchImpl,
|
|
1348
|
+
origin: this.origin,
|
|
1349
|
+
clientInstanceId: this.clientInstanceId,
|
|
1350
|
+
report,
|
|
1351
|
+
});
|
|
1172
1352
|
}
|
|
1173
1353
|
|
|
1174
1354
|
status() {
|
|
@@ -1358,6 +1538,10 @@ export class ManagedHostBrowserConnection {
|
|
|
1358
1538
|
this.managedBackgroundGraceMs = managedBackgroundGraceMs;
|
|
1359
1539
|
this.managedHealthProbeTimeoutMs = managedHealthProbeTimeoutMs;
|
|
1360
1540
|
this.backgroundCloseTimer = null;
|
|
1541
|
+
// Owner walk 2026-11-08: a hidden page does not close the WebRTC path under a media
|
|
1542
|
+
// upload; the close waits until the last upload ends (only if the page is still hidden).
|
|
1543
|
+
this.uploadsInFlight = 0;
|
|
1544
|
+
this.backgroundCloseWaitsForUpload = false;
|
|
1361
1545
|
this.healthProbePromise = null;
|
|
1362
1546
|
this.pageHideHandler = () => this.handlePageHide();
|
|
1363
1547
|
this.visibilityHandler = () => this.handleVisibilityChange();
|
|
@@ -1453,10 +1637,24 @@ export class ManagedHostBrowserConnection {
|
|
|
1453
1637
|
globalThis.__oysterunManagedTransportDiagnostics.splice(0, 50);
|
|
1454
1638
|
}
|
|
1455
1639
|
const report = sanitizeBrowserTransportDiagnostic(diagnostic);
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1640
|
+
// Without a dashboard token only the P482 records are accepted (the Host
|
|
1641
|
+
// answers others with 401), so the others are not sent, as before P482.
|
|
1642
|
+
if (
|
|
1643
|
+
report &&
|
|
1644
|
+
!getStoredDashboardToken() &&
|
|
1645
|
+
!P482_TOKENLESS_DIAGNOSTIC_EVENTS.has(report.event_type)
|
|
1646
|
+
) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
if (report && this.routeUnavailable) {
|
|
1650
|
+
void bufferBrowserDiagnostic(report);
|
|
1651
|
+
} else if (report) {
|
|
1652
|
+
void sendBrowserDiagnostic({
|
|
1653
|
+
fetchImpl: this.fetchImpl,
|
|
1654
|
+
origin: this.origin,
|
|
1655
|
+
clientInstanceId: this.clientInstanceId,
|
|
1656
|
+
report,
|
|
1657
|
+
});
|
|
1460
1658
|
}
|
|
1461
1659
|
}
|
|
1462
1660
|
|
|
@@ -2197,12 +2395,18 @@ export class ManagedHostBrowserConnection {
|
|
|
2197
2395
|
}
|
|
2198
2396
|
this.backgroundCloseTimer ??= setTimeout(() => {
|
|
2199
2397
|
this.backgroundCloseTimer = null;
|
|
2200
|
-
if (document.visibilityState
|
|
2398
|
+
if (document.visibilityState !== "hidden") return;
|
|
2399
|
+
if (this.uploadsInFlight > 0) {
|
|
2400
|
+
this.backgroundCloseWaitsForUpload = true;
|
|
2401
|
+
return;
|
|
2402
|
+
}
|
|
2403
|
+
void this.closeForBackground();
|
|
2201
2404
|
}, this.managedBackgroundGraceMs);
|
|
2202
2405
|
return;
|
|
2203
2406
|
}
|
|
2204
2407
|
clearTimeout(this.backgroundCloseTimer);
|
|
2205
2408
|
this.backgroundCloseTimer = null;
|
|
2409
|
+
this.backgroundCloseWaitsForUpload = false;
|
|
2206
2410
|
void this.handleLifecycleRecovery("page_foregrounded");
|
|
2207
2411
|
}
|
|
2208
2412
|
|
|
@@ -2773,7 +2977,9 @@ export class ManagedHostBrowserConnection {
|
|
|
2773
2977
|
|
|
2774
2978
|
async fetch(input, init = {}, recovery = {}) {
|
|
2775
2979
|
const path = normalizeHostPath(input);
|
|
2980
|
+
const upload = recovery.upload === true;
|
|
2776
2981
|
this.hostRequestsInFlight += 1;
|
|
2982
|
+
if (upload) this.uploadsInFlight += 1;
|
|
2777
2983
|
try {
|
|
2778
2984
|
const response = await this.performFetch(input, init, recovery);
|
|
2779
2985
|
this.markRequestResult(false, path);
|
|
@@ -2783,9 +2989,19 @@ export class ManagedHostBrowserConnection {
|
|
|
2783
2989
|
throw error;
|
|
2784
2990
|
} finally {
|
|
2785
2991
|
this.hostRequestsInFlight -= 1;
|
|
2992
|
+
if (upload) {
|
|
2993
|
+
this.uploadsInFlight -= 1;
|
|
2994
|
+
this.closeForBackgroundAfterUploads();
|
|
2995
|
+
}
|
|
2786
2996
|
}
|
|
2787
2997
|
}
|
|
2788
2998
|
|
|
2999
|
+
closeForBackgroundAfterUploads() {
|
|
3000
|
+
if (this.uploadsInFlight > 0 || !this.backgroundCloseWaitsForUpload) return;
|
|
3001
|
+
this.backgroundCloseWaitsForUpload = false;
|
|
3002
|
+
if (document.visibilityState === "hidden") void this.closeForBackground();
|
|
3003
|
+
}
|
|
3004
|
+
|
|
2789
3005
|
async performFetch(input, init = {}, recovery = {}) {
|
|
2790
3006
|
if (this.closed) {
|
|
2791
3007
|
throw managedHostConnectionClosedError();
|
|
@@ -3073,8 +3289,33 @@ export class ManagedHostBrowserConnection {
|
|
|
3073
3289
|
let singleton = null;
|
|
3074
3290
|
let configuredTicketProvider = null;
|
|
3075
3291
|
let managedHostAvailabilityProbePromise = null;
|
|
3292
|
+
let browserLifecycleDiagnosticsInstalled = false;
|
|
3293
|
+
|
|
3294
|
+
function installBrowserLifecycleDiagnostics() {
|
|
3295
|
+
if (browserLifecycleDiagnosticsInstalled || !globalThis.document?.addEventListener) return;
|
|
3296
|
+
browserLifecycleDiagnosticsInstalled = true;
|
|
3297
|
+
const record = (eventType) =>
|
|
3298
|
+
getManagedHostBrowserConnection().emitDiagnostic({
|
|
3299
|
+
event_type: eventType,
|
|
3300
|
+
token_state: getStoredDashboardToken() ? "present" : "absent",
|
|
3301
|
+
});
|
|
3302
|
+
// The Page Lifecycle events fire at the document and do not bubble.
|
|
3303
|
+
globalThis.document.addEventListener("freeze", () => record("browser_page_frozen"), {
|
|
3304
|
+
capture: true,
|
|
3305
|
+
});
|
|
3306
|
+
globalThis.document.addEventListener("resume", () => record("browser_page_resumed"), {
|
|
3307
|
+
capture: true,
|
|
3308
|
+
});
|
|
3309
|
+
const timer = globalThis.setInterval?.(() => {
|
|
3310
|
+
if (globalThis.document?.visibilityState === "visible") {
|
|
3311
|
+
record("browser_visible_heartbeat");
|
|
3312
|
+
}
|
|
3313
|
+
}, 5 * 60_000);
|
|
3314
|
+
timer?.unref?.();
|
|
3315
|
+
}
|
|
3076
3316
|
|
|
3077
3317
|
export function getManagedHostBrowserConnection() {
|
|
3318
|
+
installBrowserLifecycleDiagnostics();
|
|
3078
3319
|
singleton ??=
|
|
3079
3320
|
classifyManagedHostBrowserOrigin().managed_transport_enabled === true
|
|
3080
3321
|
? new ManagedHostBrowserConnection({
|
|
@@ -3084,6 +3325,15 @@ export function getManagedHostBrowserConnection() {
|
|
|
3084
3325
|
return singleton;
|
|
3085
3326
|
}
|
|
3086
3327
|
|
|
3328
|
+
export function recordManagedHostBrowserDiagnostic(event) {
|
|
3329
|
+
const connection = getManagedHostBrowserConnection();
|
|
3330
|
+
connection.emitDiagnostic({
|
|
3331
|
+
selected_path: connection.status().active_path_kind,
|
|
3332
|
+
token_state: getStoredDashboardToken() ? "present" : "absent",
|
|
3333
|
+
...event,
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3087
3337
|
export function configureManagedHostTicketProvider(ticketProvider) {
|
|
3088
3338
|
configuredTicketProvider = ticketProvider;
|
|
3089
3339
|
singleton?.setTicketProvider(ticketProvider);
|
|
@@ -3128,7 +3378,7 @@ export function managedBlobUpload(
|
|
|
3128
3378
|
return getManagedHostBrowserConnection().fetch(
|
|
3129
3379
|
input,
|
|
3130
3380
|
{ ...init, body },
|
|
3131
|
-
{ onUploadProgress: onProgress }
|
|
3381
|
+
{ onUploadProgress: onProgress, upload: true }
|
|
3132
3382
|
);
|
|
3133
3383
|
}
|
|
3134
3384
|
|
|
@@ -3234,3 +3484,5 @@ export function recordSessionSetupProviderCheckDiagnostic(event) {
|
|
|
3234
3484
|
|
|
3235
3485
|
globalThis.oysterunRecordManagedHostMatrixSyncDiagnostic =
|
|
3236
3486
|
recordManagedHostMatrixSyncDiagnostic;
|
|
3487
|
+
globalThis.oysterunRecordManagedHostBrowserDiagnostic =
|
|
3488
|
+
recordManagedHostBrowserDiagnostic;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const PHONE_CHAT_SWIPE_DISTANCE = 80;
|
|
2
|
+
export const PHONE_CHAT_SWIPE_HORIZONTAL_DOMINANCE = 1.5;
|
|
3
|
+
export const PHONE_BROWSER_EDGE_PX = 24;
|
|
4
|
+
|
|
5
|
+
export function phoneChatSwipeAction({ deltaX, deltaY, sidebarOpen, wide }) {
|
|
6
|
+
if (
|
|
7
|
+
Math.abs(deltaX) <= PHONE_CHAT_SWIPE_DISTANCE ||
|
|
8
|
+
Math.abs(deltaX) <= Math.abs(deltaY) * PHONE_CHAT_SWIPE_HORIZONTAL_DOMINANCE
|
|
9
|
+
) {
|
|
10
|
+
return "none";
|
|
11
|
+
}
|
|
12
|
+
if (deltaX > 0) return sidebarOpen || wide ? "back" : "open";
|
|
13
|
+
return sidebarOpen && !wide ? "close" : "none";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isPhoneBrowserEdgeSwipeStart(startX, nativeApp) {
|
|
17
|
+
return nativeApp !== true && startX <= PHONE_BROWSER_EDGE_PX;
|
|
18
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// P508: a Session switch never waits without a limit (P506 rule: every request
|
|
2
|
+
// has a deadline and is sent again when the connection path changes).
|
|
3
|
+
//
|
|
4
|
+
// The whole pending switch has one deadline, generous enough for a slow
|
|
5
|
+
// residential network (Owner 2026-11-11: a slow but working network must never
|
|
6
|
+
// turn into a failure). The Session's chat credentials request is never aborted
|
|
7
|
+
// for being slow: if it has not answered after a while, one more request is sent
|
|
8
|
+
// next to it and the first answer wins; a lost request (an error) uses that one
|
|
9
|
+
// retry at once. When the connection path changes or recovers, the request is
|
|
10
|
+
// sent again on the new path at once (that does not use the retry). A request
|
|
11
|
+
// that never settles cannot hold the switch: the caller stops waiting when the
|
|
12
|
+
// deadline ends.
|
|
13
|
+
|
|
14
|
+
// About 45–60 s requested by the Owner; 50 s leaves a 40 s answer room for the
|
|
15
|
+
// client start and the first sync. The production 8802 logs hold no client-side
|
|
16
|
+
// timing of this request (see the P508 timing delivery).
|
|
17
|
+
export const SESSION_SWITCH_DEADLINE_MS = 50_000;
|
|
18
|
+
// No answer yet: one more request goes out, the first keeps running.
|
|
19
|
+
export const SESSION_SWITCH_SECOND_REQUEST_MS = 25_000;
|
|
20
|
+
|
|
21
|
+
export class SessionSwitchDeadlineError extends Error {
|
|
22
|
+
constructor(message = "The Session switch ran out of time.") {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "SessionSwitchDeadlineError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function abortReason(signal) {
|
|
29
|
+
return signal.reason ?? new DOMException("Session transition replaced.", "AbortError");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A signal that aborts when `parent` aborts or after `ms`; `expired()` tells which.
|
|
33
|
+
export function createSessionSwitchDeadline(
|
|
34
|
+
parent,
|
|
35
|
+
ms = SESSION_SWITCH_DEADLINE_MS,
|
|
36
|
+
timers = globalThis
|
|
37
|
+
) {
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
let expired = false;
|
|
40
|
+
const onParent = () => controller.abort(abortReason(parent));
|
|
41
|
+
const timer = timers.setTimeout(() => {
|
|
42
|
+
expired = true;
|
|
43
|
+
controller.abort(new SessionSwitchDeadlineError());
|
|
44
|
+
}, ms);
|
|
45
|
+
if (parent.aborted) onParent();
|
|
46
|
+
else parent.addEventListener("abort", onParent, { once: true });
|
|
47
|
+
return {
|
|
48
|
+
signal: controller.signal,
|
|
49
|
+
expired: () => expired,
|
|
50
|
+
dispose() {
|
|
51
|
+
timers.clearTimeout(timer);
|
|
52
|
+
parent.removeEventListener("abort", onParent);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Settles like `promise`, or rejects as soon as `signal` aborts.
|
|
58
|
+
export function untilAborted(promise, signal) {
|
|
59
|
+
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const onAbort = () => reject(abortReason(signal));
|
|
62
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
63
|
+
promise.then(
|
|
64
|
+
(value) => {
|
|
65
|
+
signal.removeEventListener("abort", onAbort);
|
|
66
|
+
resolve(value);
|
|
67
|
+
},
|
|
68
|
+
(error) => {
|
|
69
|
+
signal.removeEventListener("abort", onAbort);
|
|
70
|
+
reject(error);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function connectionPathKey(status) {
|
|
77
|
+
return [status?.active_path_kind || "", status?.connection_id || ""].join("|");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Calls `listener` when the connection moves to another path or connection, or
|
|
81
|
+
// becomes connected again after a failure. The first status only sets the start.
|
|
82
|
+
export function watchConnectionPathChange(subscribe, listener) {
|
|
83
|
+
if (typeof subscribe !== "function") return () => {};
|
|
84
|
+
let key;
|
|
85
|
+
let state;
|
|
86
|
+
return subscribe((status) => {
|
|
87
|
+
const nextKey = connectionPathKey(status);
|
|
88
|
+
const nextState = status?.connection_state || "";
|
|
89
|
+
const changed =
|
|
90
|
+
key !== undefined &&
|
|
91
|
+
(nextKey !== key || (nextState === "connected" && state !== "connected"));
|
|
92
|
+
key = nextKey;
|
|
93
|
+
state = nextState;
|
|
94
|
+
if (changed) listener(status);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function hasHttpStatus(error) {
|
|
99
|
+
return [error?.httpStatus, error?.status].some((value) => Number.isInteger(value));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Runs `request(attemptSignal)` until one attempt succeeds, inside `signal`.
|
|
103
|
+
export function requestWithSwitchRetry({
|
|
104
|
+
request,
|
|
105
|
+
signal,
|
|
106
|
+
secondRequestMs = SESSION_SWITCH_SECOND_REQUEST_MS,
|
|
107
|
+
retries = 1,
|
|
108
|
+
subscribeConnection,
|
|
109
|
+
timers = globalThis,
|
|
110
|
+
}) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
let retriesLeft = retries;
|
|
113
|
+
let settled = false;
|
|
114
|
+
let secondRequestTimer = null;
|
|
115
|
+
const inFlight = new Set();
|
|
116
|
+
const replaced = () => new DOMException("Session switch attempt replaced.", "AbortError");
|
|
117
|
+
let unwatch = () => {};
|
|
118
|
+
const onAbort = () => finish(reject, abortReason(signal));
|
|
119
|
+
function finish(settle, value) {
|
|
120
|
+
if (settled) return;
|
|
121
|
+
settled = true;
|
|
122
|
+
if (secondRequestTimer !== null) timers.clearTimeout(secondRequestTimer);
|
|
123
|
+
signal.removeEventListener("abort", onAbort);
|
|
124
|
+
unwatch();
|
|
125
|
+
// Attempts still running are no longer awaited; cancel them where the path allows.
|
|
126
|
+
for (const attempt of inFlight) attempt.abort(replaced());
|
|
127
|
+
inFlight.clear();
|
|
128
|
+
settle(value);
|
|
129
|
+
}
|
|
130
|
+
function useRetry() {
|
|
131
|
+
if (retriesLeft <= 0) return false;
|
|
132
|
+
retriesLeft -= 1;
|
|
133
|
+
start();
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
function onError(error) {
|
|
137
|
+
// An HTTP answer is the Host's decision, not a lost request.
|
|
138
|
+
if (hasHttpStatus(error)) return finish(reject, error);
|
|
139
|
+
if (inFlight.size > 0) return; // another attempt may still answer
|
|
140
|
+
if (useRetry()) return;
|
|
141
|
+
finish(reject, error);
|
|
142
|
+
}
|
|
143
|
+
function start() {
|
|
144
|
+
const attempt = new AbortController();
|
|
145
|
+
inFlight.add(attempt);
|
|
146
|
+
Promise.resolve()
|
|
147
|
+
.then(() => request(attempt.signal))
|
|
148
|
+
.then(
|
|
149
|
+
(value) => {
|
|
150
|
+
if (settled || !inFlight.delete(attempt)) return;
|
|
151
|
+
finish(resolve, value);
|
|
152
|
+
},
|
|
153
|
+
(error) => {
|
|
154
|
+
if (settled || !inFlight.delete(attempt)) return;
|
|
155
|
+
onError(error);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (signal.aborted) {
|
|
160
|
+
settled = true;
|
|
161
|
+
reject(abortReason(signal));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
165
|
+
unwatch = watchConnectionPathChange(subscribeConnection, () => {
|
|
166
|
+
if (settled) return;
|
|
167
|
+
// The old path is gone: send again on the new one now (the retry stays available).
|
|
168
|
+
for (const attempt of inFlight) attempt.abort(replaced());
|
|
169
|
+
inFlight.clear();
|
|
170
|
+
start();
|
|
171
|
+
});
|
|
172
|
+
start();
|
|
173
|
+
secondRequestTimer = timers.setTimeout(() => {
|
|
174
|
+
secondRequestTimer = null;
|
|
175
|
+
if (!settled) useRetry();
|
|
176
|
+
}, secondRequestMs);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const SESSION_SWITCH_TIMEOUT_MESSAGE =
|
|
181
|
+
"The Host did not answer in time, so the Session did not open.";
|
|
182
|
+
export const SESSION_SWITCH_CONNECTION_MESSAGE =
|
|
183
|
+
"The connection to the Host was interrupted, so the Session did not open.";
|
|
184
|
+
|
|
185
|
+
// A readable message for a switch that failed on the connection, or null to keep
|
|
186
|
+
// the error's own message (an answer from the Host, such as not permitted). The
|
|
187
|
+
// existing Retry (↻, "Retry opening Session") stays next to it.
|
|
188
|
+
export function readableSessionSwitchError(error) {
|
|
189
|
+
if (!error || hasHttpStatus(error)) return null;
|
|
190
|
+
if (error.name === "SessionSwitchDeadlineError" || error.name === "TimeoutError") {
|
|
191
|
+
return SESSION_SWITCH_TIMEOUT_MESSAGE;
|
|
192
|
+
}
|
|
193
|
+
const message = typeof error.message === "string" ? error.message : "";
|
|
194
|
+
if (/timed out/i.test(message)) return SESSION_SWITCH_TIMEOUT_MESSAGE;
|
|
195
|
+
if (
|
|
196
|
+
error.name === "AbortError" ||
|
|
197
|
+
/abort/i.test(message) ||
|
|
198
|
+
/failed to fetch|load failed|network ?error|networkerror|connection (was )?(lost|closed|reset)/i.test(message)
|
|
199
|
+
) {
|
|
200
|
+
return SESSION_SWITCH_CONNECTION_MESSAGE;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|