oysterun 1.6.0-beta.38 → 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 +247 -17
- 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-Ut1t0ay2.js → ReactPrism-BMvm_4Sd.js} +1 -1
- package/dev/client/web-chat/dist/assets/{ReactPrism-Ut1t0ay2.js.map → ReactPrism-BMvm_4Sd.js.map} +1 -1
- package/dev/client/web-chat/dist/assets/{TerminalSurface-DcH4WvVE.js → TerminalSurface-83CMtDbQ.js} +19 -19
- package/dev/client/web-chat/dist/assets/TerminalSurface-83CMtDbQ.js.map +1 -0
- package/dev/client/web-chat/dist/assets/{index-D4_BFppX.js → index-BukD9ETd.js} +2 -2
- package/dev/client/web-chat/dist/assets/{index-D4_BFppX.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-DoO049dA.js → index-mWzPv7k9.js} +1 -1
- package/dev/client/web-chat/dist/assets/{index-DoO049dA.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-CN3ae4-n.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-D8op4ZAO.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-D5ZlSBA-.js → web-C0lJ0ykc.js} +1 -1
- package/dev/client/web-chat/dist/assets/{web-D5ZlSBA-.js.map → web-C0lJ0ykc.js.map} +1 -1
- package/dev/client/web-chat/dist/assets/{web-BcveD4s1.js → web-DqF5TOnI.js} +1 -1
- package/dev/client/web-chat/dist/assets/{web-BcveD4s1.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/matrix-facade.mjs +44 -0
- package/host-service/onboard.mjs +4 -0
- package/host-service/package.json +1 -1
- package/host-service/refusal-observability.mjs +200 -0
- package/host-service/server.mjs +201 -32
- package/host-service/setup.mjs +11 -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/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/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 +2 -0
- 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-DcH4WvVE.js.map +0 -1
- package/dev/client/web-chat/dist/assets/index-Dxi0xwNV.js +0 -1
- package/dev/client/web-chat/dist/assets/index-Dxi0xwNV.js.map +0 -1
- package/dev/client/web-chat/dist/assets/index-lnWBihc5.js +0 -2
- package/dev/client/web-chat/dist/assets/index-lnWBihc5.js.map +0 -1
- package/dev/client/web-chat/dist/assets/matrix-entry-CN3ae4-n.js.map +0 -1
- package/dev/client/web-chat/dist/assets/pdf-D8op4ZAO.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
|
@@ -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() {
|
|
@@ -1457,10 +1637,24 @@ export class ManagedHostBrowserConnection {
|
|
|
1457
1637
|
globalThis.__oysterunManagedTransportDiagnostics.splice(0, 50);
|
|
1458
1638
|
}
|
|
1459
1639
|
const report = sanitizeBrowserTransportDiagnostic(diagnostic);
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
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
|
+
});
|
|
1464
1658
|
}
|
|
1465
1659
|
}
|
|
1466
1660
|
|
|
@@ -3095,8 +3289,33 @@ export class ManagedHostBrowserConnection {
|
|
|
3095
3289
|
let singleton = null;
|
|
3096
3290
|
let configuredTicketProvider = null;
|
|
3097
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
|
+
}
|
|
3098
3316
|
|
|
3099
3317
|
export function getManagedHostBrowserConnection() {
|
|
3318
|
+
installBrowserLifecycleDiagnostics();
|
|
3100
3319
|
singleton ??=
|
|
3101
3320
|
classifyManagedHostBrowserOrigin().managed_transport_enabled === true
|
|
3102
3321
|
? new ManagedHostBrowserConnection({
|
|
@@ -3106,6 +3325,15 @@ export function getManagedHostBrowserConnection() {
|
|
|
3106
3325
|
return singleton;
|
|
3107
3326
|
}
|
|
3108
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
|
+
|
|
3109
3337
|
export function configureManagedHostTicketProvider(ticketProvider) {
|
|
3110
3338
|
configuredTicketProvider = ticketProvider;
|
|
3111
3339
|
singleton?.setTicketProvider(ticketProvider);
|
|
@@ -3256,3 +3484,5 @@ export function recordSessionSetupProviderCheckDiagnostic(event) {
|
|
|
3256
3484
|
|
|
3257
3485
|
globalThis.oysterunRecordManagedHostMatrixSyncDiagnostic =
|
|
3258
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
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// P491: a Session which becomes stopped cannot keep using the live Matrix
|
|
2
|
+
// facade token cached while it was running. Keep this policy independent of
|
|
3
|
+
// React so both the list transition and the /sync failure are cheap to test.
|
|
4
|
+
|
|
5
|
+
export function reconcileStoppedSessionTokens(rows, { forget, retainLive }) {
|
|
6
|
+
const liveSessionIds = [];
|
|
7
|
+
for (const row of rows) {
|
|
8
|
+
if (row?.running === true) {
|
|
9
|
+
liveSessionIds.push(row.session_id);
|
|
10
|
+
} else if (row?.running === false) {
|
|
11
|
+
forget(row.session_id);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
retainLive(liveSessionIds);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isStoppedSessionForbiddenSyncError(error) {
|
|
18
|
+
if (!error || typeof error !== "object") return false;
|
|
19
|
+
const status = error.httpStatus ?? error.status;
|
|
20
|
+
return status === 403 && error.errcode === "M_FORBIDDEN";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Correction 3: every entry point (Sessions page, sidebar Stopped row, message
|
|
24
|
+
// search, browser history) opens a Session through ClientRoot. A target the
|
|
25
|
+
// ready list does not show running is stopped: listed with running=false, or
|
|
26
|
+
// only in the Stopped history. Its cached live bootstrap and warm client are
|
|
27
|
+
// retired before any cache or warm-pool lookup, so the open starts with a fresh
|
|
28
|
+
// bootstrap instead of a /sync on the old live token.
|
|
29
|
+
export function isStoppedSessionTarget(rows, sessionId) {
|
|
30
|
+
if (!sessionId) return false;
|
|
31
|
+
return !rows.some((row) => row?.session_id === sessionId && row?.running === true);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function retireStoppedSessionTarget({ rows, sessionId, forgetToken, forgetCommitted, dropWarmClient }) {
|
|
35
|
+
if (!isStoppedSessionTarget(rows, sessionId)) return false;
|
|
36
|
+
forgetToken(sessionId);
|
|
37
|
+
forgetCommitted(sessionId);
|
|
38
|
+
dropWarmClient(sessionId);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// P493: the other direction. A read-only bootstrap belongs to a Session that was
|
|
43
|
+
// stopped when it was fetched; the Session may have been resumed elsewhere since
|
|
44
|
+
// (CLI, another page or device). It is never reused: the next open asks the Host
|
|
45
|
+
// for a new bootstrap, and the Host answers live or read-only.
|
|
46
|
+
export function isReusableMatrixBootstrap(bootstrap) {
|
|
47
|
+
return Boolean(bootstrap) && bootstrap.read_only !== true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// P493: the shown read-only Chat becomes live when its Session is resumed
|
|
51
|
+
// elsewhere. The signal is the Sessions collection the Host already pushes (the
|
|
52
|
+
// resume admits the Session as a running row); the page-visible / App-foreground
|
|
53
|
+
// re-check asks the Host directly. One rebuild per resume: a Session seen
|
|
54
|
+
// running again is not rebuilt a second time until it is seen not running.
|
|
55
|
+
export function createReadOnlyResumeWatch() {
|
|
56
|
+
let rebuiltForSessionId = null;
|
|
57
|
+
return {
|
|
58
|
+
/** True when the shown read-only Session's row is running and no rebuild was started for it yet. */
|
|
59
|
+
shouldRebuild({ readOnly, sessionId, rows }) {
|
|
60
|
+
if (!readOnly || !sessionId) return false;
|
|
61
|
+
const running = rows.some((row) => row?.session_id === sessionId && row?.kind === "running");
|
|
62
|
+
if (!running) {
|
|
63
|
+
if (rebuiltForSessionId === sessionId) rebuiltForSessionId = null;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (rebuiltForSessionId === sessionId) return false;
|
|
67
|
+
rebuiltForSessionId = sessionId;
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
/** The shown Chat is live: a later stop and resume is a new resume. */
|
|
71
|
+
reset() {
|
|
72
|
+
rebuiltForSessionId = null;
|
|
73
|
+
},
|
|
74
|
+
/** The Host said the shown read-only Session is live (re-check on visible / foreground). */
|
|
75
|
+
shouldRebuildFromHostStatus({ readOnly, sessionId, status }) {
|
|
76
|
+
if (!readOnly || !sessionId || status?.session_id !== sessionId || status?.alive !== true) return false;
|
|
77
|
+
if (rebuiltForSessionId === sessionId) return false;
|
|
78
|
+
rebuiltForSessionId = sessionId;
|
|
79
|
+
return true;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|