@opencode/browse 0.0.17-dev.180 → 0.0.17-dev.181
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Runtime-jrg7sc9p.mjs → Runtime-xss8qan1.mjs} +1 -1
- package/dist/{cli-dbb5bjne.mjs → cli-1bdh4p0a.mjs} +37 -38
- package/dist/cli.mjs +14 -14
- package/dist/{helpers-mbetgbwv.mjs → helpers-bbaa1vjs.mjs} +1 -3
- package/dist/{index-j79y2me1.mjs → index-gjq7chrk.mjs} +2 -2
- package/dist/{legacy-runtime-eky6yenx.mjs → legacy-runtime-yjsm0xpg.mjs} +30 -17
- package/dist/{main-44rp8pxg.mjs → main-32bwyqja.mjs} +4 -4
- package/dist/{main-f98q5tcf.mjs → main-6hvv25x8.mjs} +27 -29
- package/dist/{main-v2a390e1.mjs → main-6qfvnjxc.mjs} +7 -9
- package/dist/{main-3mhynene.mjs → main-9frwnsnf.mjs} +3 -5
- package/dist/{main-048kx59h.mjs → main-akpa411k.mjs} +6 -8
- package/dist/main-bt237ys7.mjs +1012 -0
- package/dist/main-d5ke1bpm.mjs +4 -0
- package/dist/{main-s3g4jwx5.mjs → main-jeta10c6.mjs} +23 -25
- package/dist/{main-wpt5ha44.mjs → main-m45zegrn.mjs} +371 -167
- package/dist/{main-fpn564ph.mjs → main-pq962g72.mjs} +7 -4
- package/dist/main-q4typx7c.mjs +213 -0
- package/dist/{main-r8g3xydm.mjs → main-qccyxwg8.mjs} +3 -5
- package/dist/{main-awaqqre9.mjs → main-rb7dermc.mjs} +117 -4
- package/dist/{main-46wtkfsd.mjs → main-reh7k0hv.mjs} +199 -989
- package/dist/{main-jwss6gk9.mjs → main-rvn834gn.mjs} +2 -2
- package/dist/{main-wfmad10p.mjs → main-sfxkq31s.mjs} +16 -18
- package/dist/{main-q2d5bd1e.mjs → main-tg0r67xj.mjs} +8 -10
- package/dist/{main-g1frnq76.mjs → main-tk2thty0.mjs} +8 -7
- package/dist/{mcp-amxrbrbd.mjs → mcp-rjpmt73q.mjs} +31 -32
- package/dist/{migrate-07f3f3yp.mjs → migrate-hggn66v2.mjs} +5 -6
- package/dist/{relay-e7fx469h.mjs → relay-fm6q9hnx.mjs} +87 -60
- package/dist/{runtime-update-xt7x7j6c.mjs → runtime-update-vdw1eajx.mjs} +9 -9
- package/dist/{setup-m85mamg6.mjs → setup-wyrpwq4c.mjs} +196 -129
- package/dist/{supervisor-6zbwkkpt.mjs → supervisor-nbce8yhg.mjs} +10 -6
- package/dist/{update-drswqt2m.mjs → update-be8dfw51.mjs} +3 -4
- package/dist/{version-v3heqz8b.mjs → version-6j8cdg2k.mjs} +1 -1
- package/package.json +1 -1
- package/dist/main-4h7rfhhr.mjs +0 -61
- package/dist/main-amkq7v9m.mjs +0 -4
- package/dist/main-gg7f12gg.mjs +0 -114
- package/dist/main-qazf3bhk.mjs +0 -223
|
@@ -1,13 +1,49 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
stateRoot,
|
|
3
|
+
compiledBinary,
|
|
4
|
+
scriptEntry,
|
|
5
|
+
cliCommand,
|
|
6
|
+
installCommand,
|
|
3
7
|
browserUnresponsive,
|
|
4
8
|
extensionReconnectAlarmPeriodMs,
|
|
5
9
|
extensionProtocolAdvice,
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
compareVersions,
|
|
11
|
+
installedRuntime2,
|
|
12
|
+
installedVersion
|
|
13
|
+
} from "./main-rb7dermc.mjs";
|
|
8
14
|
import {
|
|
9
|
-
ensurePrivateDirectorySync
|
|
10
|
-
|
|
15
|
+
ensurePrivateDirectorySync,
|
|
16
|
+
SessionContainer,
|
|
17
|
+
SessionsContainer,
|
|
18
|
+
SessionDeleted,
|
|
19
|
+
SessionResetResponse,
|
|
20
|
+
SessionAdoptResponse,
|
|
21
|
+
ExecuteResponse,
|
|
22
|
+
AuthenticatedJsonOutcome,
|
|
23
|
+
TargetSummaries,
|
|
24
|
+
ExtensionStatus,
|
|
25
|
+
RelayVersion,
|
|
26
|
+
RelayShutdownRequest,
|
|
27
|
+
RelayShutdownResponse,
|
|
28
|
+
NetworkStatusResponse,
|
|
29
|
+
AuthProfileSummary,
|
|
30
|
+
NetworkStopResponse,
|
|
31
|
+
NetworkCancelResponse,
|
|
32
|
+
AuthRunResponse,
|
|
33
|
+
RecordingStartResponse,
|
|
34
|
+
RecordingStopResponse,
|
|
35
|
+
RecordingStatusResponse,
|
|
36
|
+
TabsCleanupResponse,
|
|
37
|
+
SettingsGetResponse,
|
|
38
|
+
SettingsSetResponse,
|
|
39
|
+
RecordingCancelResponse,
|
|
40
|
+
FlightRecorderStatusResponse,
|
|
41
|
+
FlightRecorderSaveResponse,
|
|
42
|
+
FlightRecorderCancelResponse,
|
|
43
|
+
RelayErrorCode,
|
|
44
|
+
ErrorEnvelope,
|
|
45
|
+
defaultPort2
|
|
46
|
+
} from "./main-bt237ys7.mjs";
|
|
11
47
|
import {
|
|
12
48
|
get,
|
|
13
49
|
post,
|
|
@@ -15,23 +51,21 @@ import {
|
|
|
15
51
|
bodyJson,
|
|
16
52
|
HttpClient,
|
|
17
53
|
layerNodeHttp
|
|
18
|
-
} from "./main-
|
|
54
|
+
} from "./main-jeta10c6.mjs";
|
|
19
55
|
import {
|
|
20
56
|
opencodeBrowserBuildId2
|
|
21
|
-
} from "./main-
|
|
22
|
-
import {
|
|
23
|
-
stateRoot,
|
|
24
|
-
compiledBinary,
|
|
25
|
-
scriptEntry,
|
|
26
|
-
cliCommand,
|
|
27
|
-
installCommand,
|
|
28
|
-
compareVersions,
|
|
29
|
-
installedRuntime2,
|
|
30
|
-
installedVersion
|
|
31
|
-
} from "./main-awaqqre9.mjs";
|
|
57
|
+
} from "./main-d5ke1bpm.mjs";
|
|
32
58
|
import {
|
|
33
59
|
relayAuthorization
|
|
34
|
-
} from "./main-
|
|
60
|
+
} from "./main-rvn834gn.mjs";
|
|
61
|
+
import {
|
|
62
|
+
endpointForPort,
|
|
63
|
+
configuredRelayPort,
|
|
64
|
+
relayPortPinned,
|
|
65
|
+
readRelayState,
|
|
66
|
+
processAlive,
|
|
67
|
+
resolveRelayPort
|
|
68
|
+
} from "./main-q4typx7c.mjs";
|
|
35
69
|
import {
|
|
36
70
|
Pointer,
|
|
37
71
|
passthrough,
|
|
@@ -48,43 +82,27 @@ import {
|
|
|
48
82
|
decodeUnknownOption,
|
|
49
83
|
make8,
|
|
50
84
|
optionalKey,
|
|
51
|
-
Literal,
|
|
52
|
-
Unknown,
|
|
53
85
|
String3,
|
|
54
86
|
Number2,
|
|
55
87
|
Boolean3,
|
|
56
88
|
Struct,
|
|
57
|
-
fieldsAssign,
|
|
58
|
-
Record,
|
|
59
|
-
ArraySchema,
|
|
60
|
-
Union,
|
|
61
|
-
Literals,
|
|
62
89
|
NullOr,
|
|
63
90
|
BooleanLiterals,
|
|
64
|
-
TaggedUnion,
|
|
65
|
-
makeFilter,
|
|
66
|
-
isPattern,
|
|
67
|
-
isGreaterThan,
|
|
68
|
-
isGreaterThanOrEqualTo,
|
|
69
|
-
isBetween,
|
|
70
|
-
isInt,
|
|
71
91
|
Int2,
|
|
72
|
-
isMaxLength,
|
|
73
|
-
NonEmptyString,
|
|
74
92
|
Defect,
|
|
75
93
|
TaggedError2,
|
|
76
|
-
toCodecStringTree
|
|
77
|
-
|
|
78
|
-
} from "./main-f98q5tcf.mjs";
|
|
94
|
+
toCodecStringTree
|
|
95
|
+
} from "./main-6hvv25x8.mjs";
|
|
79
96
|
import {
|
|
97
|
+
dual,
|
|
98
|
+
memoize,
|
|
99
|
+
isTagged,
|
|
80
100
|
assignProperty,
|
|
81
101
|
PipeInspectableProto,
|
|
82
|
-
|
|
102
|
+
Prototype2,
|
|
83
103
|
none,
|
|
84
104
|
some,
|
|
85
|
-
isNone,
|
|
86
105
|
isSome,
|
|
87
|
-
match,
|
|
88
106
|
getOrElse,
|
|
89
107
|
map2,
|
|
90
108
|
Service2,
|
|
@@ -102,7 +120,6 @@ import {
|
|
|
102
120
|
suspend2,
|
|
103
121
|
sync2,
|
|
104
122
|
void_3,
|
|
105
|
-
callback2,
|
|
106
123
|
fail6,
|
|
107
124
|
die3,
|
|
108
125
|
try_2,
|
|
@@ -112,6 +129,7 @@ import {
|
|
|
112
129
|
tap,
|
|
113
130
|
result,
|
|
114
131
|
map6,
|
|
132
|
+
asVoid2,
|
|
115
133
|
catch_,
|
|
116
134
|
catchDefect,
|
|
117
135
|
mapError2,
|
|
@@ -127,15 +145,7 @@ import {
|
|
|
127
145
|
mapEager,
|
|
128
146
|
flatMapEager,
|
|
129
147
|
catchEager
|
|
130
|
-
} from "./main-
|
|
131
|
-
import {
|
|
132
|
-
dual,
|
|
133
|
-
memoize,
|
|
134
|
-
isString,
|
|
135
|
-
isNumber,
|
|
136
|
-
isObject,
|
|
137
|
-
isTagged
|
|
138
|
-
} from "./main-qazf3bhk.mjs";
|
|
148
|
+
} from "./main-m45zegrn.mjs";
|
|
139
149
|
import {
|
|
140
150
|
__require
|
|
141
151
|
} from "./main-j98fzrvv.mjs";
|
|
@@ -260,7 +270,7 @@ class ConfigError {
|
|
|
260
270
|
}
|
|
261
271
|
}
|
|
262
272
|
var Proto2 = {
|
|
263
|
-
.../* @__PURE__ */
|
|
273
|
+
.../* @__PURE__ */ Prototype2({
|
|
264
274
|
label: "Config",
|
|
265
275
|
evaluate(fiber) {
|
|
266
276
|
return this.parse(fiber.getRef(ConfigProvider));
|
|
@@ -415,925 +425,15 @@ function Boolean2(name) {
|
|
|
415
425
|
return schema(BooleanLiterals, name);
|
|
416
426
|
}
|
|
417
427
|
|
|
418
|
-
// src/relay/schema.ts
|
|
419
|
-
var SessionSummary = Struct({
|
|
420
|
-
id: String3,
|
|
421
|
-
createdAt: String3,
|
|
422
|
-
updatedAt: String3,
|
|
423
|
-
connected: Boolean3,
|
|
424
|
-
pageUrl: NullOr(String3),
|
|
425
|
-
stateKeys: ArraySchema(String3),
|
|
426
|
-
readOnly: optionalKey(Boolean3),
|
|
427
|
-
allowedOrigins: optionalKey(ArraySchema(String3)),
|
|
428
|
-
browser: optionalKey(String3)
|
|
429
|
-
});
|
|
430
|
-
var ExecuteSessionSummary = SessionSummary.pipe(fieldsAssign({
|
|
431
|
-
created: optionalKey(Boolean3)
|
|
432
|
-
}));
|
|
433
|
-
var SessionContainer = Struct({
|
|
434
|
-
session: SessionSummary
|
|
435
|
-
});
|
|
436
|
-
var SessionsContainer = Struct({
|
|
437
|
-
sessions: ArraySchema(SessionSummary)
|
|
438
|
-
});
|
|
439
|
-
var SessionStopReport = Struct({
|
|
440
|
-
execute: Boolean3,
|
|
441
|
-
handoff: Boolean3,
|
|
442
|
-
forced: Boolean3
|
|
443
|
-
});
|
|
444
|
-
var SessionDeleted = Struct({
|
|
445
|
-
deleted: Boolean3,
|
|
446
|
-
id: String3,
|
|
447
|
-
stopped: optionalKey(SessionStopReport)
|
|
448
|
-
});
|
|
449
|
-
var SessionResetResponse = Struct({
|
|
450
|
-
session: SessionSummary,
|
|
451
|
-
stopped: optionalKey(SessionStopReport)
|
|
452
|
-
});
|
|
453
|
-
var TargetSelection = Struct({
|
|
454
|
-
urlIncludes: optionalKey(NonEmptyString),
|
|
455
|
-
index: optionalKey(Int2.check(isGreaterThanOrEqualTo(0)))
|
|
456
|
-
}).check(makeFilter((selection) => {
|
|
457
|
-
const hasUrl = selection.urlIncludes !== undefined;
|
|
458
|
-
const hasIndex = selection.index !== undefined;
|
|
459
|
-
return hasUrl !== hasIndex ? undefined : "targetSelection must contain exactly one of urlIncludes or index";
|
|
460
|
-
}));
|
|
461
|
-
var ExecuteRequest = Struct({
|
|
462
|
-
sessionId: optionalKey(String3),
|
|
463
|
-
code: String3,
|
|
464
|
-
createIfMissing: Boolean3,
|
|
465
|
-
browser: optionalKey(String3),
|
|
466
|
-
removeAfterExecute: optionalKey(Boolean3),
|
|
467
|
-
timeoutMs: optionalKey(Int2.check(isGreaterThanOrEqualTo(0))),
|
|
468
|
-
targetSelection: optionalKey(TargetSelection)
|
|
469
|
-
});
|
|
470
|
-
var SessionAdoptRequest = Struct({
|
|
471
|
-
sessionId: optionalKey(String3),
|
|
472
|
-
createIfMissing: Boolean3,
|
|
473
|
-
targetSelection: optionalKey(TargetSelection),
|
|
474
|
-
tabId: optionalKey(Int2)
|
|
475
|
-
});
|
|
476
|
-
var SessionNewRequest = Struct({
|
|
477
|
-
id: optionalKey(String3),
|
|
478
|
-
readOnly: optionalKey(Boolean3),
|
|
479
|
-
allowedOrigins: optionalKey(ArraySchema(String3)),
|
|
480
|
-
browser: optionalKey(String3)
|
|
481
|
-
});
|
|
482
|
-
var SessionEnsureRequest = Struct({
|
|
483
|
-
id: NonEmptyString,
|
|
484
|
-
readOnly: optionalKey(Boolean3)
|
|
485
|
-
});
|
|
486
|
-
var SessionIdRequest = Struct({
|
|
487
|
-
id: String3
|
|
488
|
-
});
|
|
489
|
-
var SessionAllowlistRequest = Struct({
|
|
490
|
-
id: String3,
|
|
491
|
-
allowedOrigins: ArraySchema(String3)
|
|
492
|
-
});
|
|
493
|
-
var SessionAdoptResponse = Struct({
|
|
494
|
-
session: ExecuteSessionSummary,
|
|
495
|
-
adoptedUrl: String3,
|
|
496
|
-
adoptedTargetId: String3
|
|
497
|
-
});
|
|
498
|
-
var ExecuteLogLocation = Struct({
|
|
499
|
-
url: String3,
|
|
500
|
-
lineNumber: Number2,
|
|
501
|
-
columnNumber: Number2
|
|
502
|
-
});
|
|
503
|
-
var ExecuteLogEntry = Struct({
|
|
504
|
-
source: Literals(["script", "page"]),
|
|
505
|
-
type: String3,
|
|
506
|
-
text: String3,
|
|
507
|
-
location: optionalKey(ExecuteLogLocation),
|
|
508
|
-
repeatCount: optionalKey(Number2)
|
|
509
|
-
});
|
|
510
|
-
var ExecuteLogSummary = Struct({
|
|
511
|
-
totalCount: Number2,
|
|
512
|
-
returnedCount: Number2,
|
|
513
|
-
repeatedCount: Number2,
|
|
514
|
-
omittedCount: Number2
|
|
515
|
-
});
|
|
516
|
-
var ExecuteAftermath = Struct({
|
|
517
|
-
startUrl: NullOr(String3),
|
|
518
|
-
endUrl: NullOr(String3),
|
|
519
|
-
navigations: ArraySchema(String3),
|
|
520
|
-
consoleErrorCount: Number2,
|
|
521
|
-
pageErrorCount: Number2,
|
|
522
|
-
handoffs: Number2,
|
|
523
|
-
challenge: optionalKey(Struct({
|
|
524
|
-
vendor: String3,
|
|
525
|
-
kind: Literals(["non-interactive", "interactive", "block"]),
|
|
526
|
-
status: Literals(["cleared", "blocked"]),
|
|
527
|
-
signal: String3,
|
|
528
|
-
url: String3,
|
|
529
|
-
waitedMs: Number2,
|
|
530
|
-
recommendation: Literals(["continue", "handoff", "stop"])
|
|
531
|
-
}))
|
|
532
|
-
});
|
|
533
|
-
var ExecuteMedia = Struct({
|
|
534
|
-
type: Literal("image"),
|
|
535
|
-
mimeType: String3,
|
|
536
|
-
data: String3,
|
|
537
|
-
size: Number2
|
|
538
|
-
});
|
|
539
|
-
var ExecuteResponse = Struct({
|
|
540
|
-
text: String3,
|
|
541
|
-
value: optionalKey(Unknown),
|
|
542
|
-
media: optionalKey(ArraySchema(ExecuteMedia)),
|
|
543
|
-
isError: Boolean3,
|
|
544
|
-
logs: ArraySchema(ExecuteLogEntry),
|
|
545
|
-
logSummary: optionalKey(ExecuteLogSummary),
|
|
546
|
-
warnings: optionalKey(ArraySchema(String3)),
|
|
547
|
-
diagnostic: optionalKey(String3),
|
|
548
|
-
aftermath: optionalKey(ExecuteAftermath),
|
|
549
|
-
session: ExecuteSessionSummary
|
|
550
|
-
});
|
|
551
|
-
var AuthenticatedJsonMethod = Literals(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
552
|
-
var AuthenticatedJsonRequest = Struct({
|
|
553
|
-
sessionId: NonEmptyString,
|
|
554
|
-
origin: NonEmptyString,
|
|
555
|
-
startUrl: optionalKey(NonEmptyString),
|
|
556
|
-
method: AuthenticatedJsonMethod,
|
|
557
|
-
path: NonEmptyString,
|
|
558
|
-
headers: optionalKey(Record(String3, String3)),
|
|
559
|
-
body: optionalKey(Json),
|
|
560
|
-
sensitive: optionalKey(Boolean3),
|
|
561
|
-
handoffOnAuthFailure: optionalKey(Boolean3),
|
|
562
|
-
handoffMessage: optionalKey(String3),
|
|
563
|
-
timeoutMs: optionalKey(Int2.check(isBetween({ minimum: 1, maximum: 120000 }))),
|
|
564
|
-
maxResponseBytes: optionalKey(Int2.check(isBetween({ minimum: 1, maximum: 1e7 })))
|
|
565
|
-
});
|
|
566
|
-
var AuthenticatedJsonOutcome = TaggedUnion({
|
|
567
|
-
Success: {
|
|
568
|
-
status: Int2,
|
|
569
|
-
value: Json
|
|
570
|
-
},
|
|
571
|
-
OriginMismatch: {
|
|
572
|
-
expectedOrigin: String3,
|
|
573
|
-
actualOrigin: String3
|
|
574
|
-
},
|
|
575
|
-
RequestFailed: {
|
|
576
|
-
outcome: Literals(["not-sent", "unknown"])
|
|
577
|
-
},
|
|
578
|
-
HttpError: {
|
|
579
|
-
status: Int2
|
|
580
|
-
},
|
|
581
|
-
ResponseTooLarge: {
|
|
582
|
-
status: Int2,
|
|
583
|
-
maxResponseBytes: Int2
|
|
584
|
-
},
|
|
585
|
-
InvalidJson: {
|
|
586
|
-
status: Int2
|
|
587
|
-
},
|
|
588
|
-
SensitiveCaptureActive: {}
|
|
589
|
-
});
|
|
590
|
-
var TargetSummary = Struct({
|
|
591
|
-
id: String3,
|
|
592
|
-
type: String3,
|
|
593
|
-
title: String3,
|
|
594
|
-
url: String3,
|
|
595
|
-
tabId: optionalKey(Number2),
|
|
596
|
-
sessionId: optionalKey(String3),
|
|
597
|
-
opencodeBrowserSessionId: optionalKey(String3),
|
|
598
|
-
owner: optionalKey(Literals(["relay", "user"])),
|
|
599
|
-
crashed: optionalKey(Boolean3),
|
|
600
|
-
protectedUi: optionalKey(Boolean3)
|
|
601
|
-
});
|
|
602
|
-
var TargetSummaries = ArraySchema(TargetSummary);
|
|
603
|
-
var ConnectedBrowser = Struct({
|
|
604
|
-
id: String3,
|
|
605
|
-
name: String3,
|
|
606
|
-
default: Boolean3,
|
|
607
|
-
connected: Boolean3,
|
|
608
|
-
unresponsive: optionalKey(Boolean3),
|
|
609
|
-
version: NullOr(String3),
|
|
610
|
-
tabs: Int2.check(isGreaterThanOrEqualTo(0))
|
|
611
|
-
});
|
|
612
|
-
var ExtensionStatus = Struct({
|
|
613
|
-
connected: Boolean3,
|
|
614
|
-
pairingState: optionalKey(Literals(["connected", "incompatible", "refused", "unpaired", "paired-offline", "not-seen"])),
|
|
615
|
-
nextStep: optionalKey(String3),
|
|
616
|
-
version: NullOr(String3),
|
|
617
|
-
build: optionalKey(NullOr(String3)),
|
|
618
|
-
origin: optionalKey(NullOr(String3)),
|
|
619
|
-
protocolVersion: optionalKey(NullOr(Number2)),
|
|
620
|
-
protocolCompatible: optionalKey(NullOr(Boolean3)),
|
|
621
|
-
protocolLegacy: optionalKey(NullOr(Boolean3)),
|
|
622
|
-
browsers: optionalKey(ArraySchema(ConnectedBrowser)),
|
|
623
|
-
rejectedConnections: optionalKey(Int2.check(isGreaterThanOrEqualTo(0))),
|
|
624
|
-
pairingFailures: optionalKey(Int2.check(isGreaterThanOrEqualTo(0))),
|
|
625
|
-
processFaults: optionalKey(Struct({
|
|
626
|
-
suppressed: Int2.check(isGreaterThanOrEqualTo(0)),
|
|
627
|
-
lastAt: optionalKey(String3),
|
|
628
|
-
lastMessage: optionalKey(String3)
|
|
629
|
-
})),
|
|
630
|
-
activeTargets: Number2,
|
|
631
|
-
childTargets: optionalKey(Number2),
|
|
632
|
-
cdpClients: optionalKey(Number2),
|
|
633
|
-
sessions: optionalKey(ArraySchema(SessionSummary)),
|
|
634
|
-
targets: optionalKey(TargetSummaries)
|
|
635
|
-
});
|
|
636
|
-
var RelayVersion = Struct({
|
|
637
|
-
version: String3,
|
|
638
|
-
buildId: optionalKey(String3),
|
|
639
|
-
instanceId: optionalKey(String3),
|
|
640
|
-
startedAt: optionalKey(String3),
|
|
641
|
-
pid: optionalKey(Number2),
|
|
642
|
-
managed: optionalKey(Boolean3),
|
|
643
|
-
shutdownProtocol: optionalKey(Literal(2))
|
|
644
|
-
});
|
|
645
|
-
var RelayIdentity = String3.check(isPattern(/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}(?![\s\S])/));
|
|
646
|
-
var RelayBuildId = String3.check(isPattern(/^[A-Za-z0-9][A-Za-z0-9._:+-]{0,255}(?![\s\S])/));
|
|
647
|
-
var RelayShutdownRequest = Struct({
|
|
648
|
-
instanceId: RelayIdentity,
|
|
649
|
-
requestId: RelayIdentity,
|
|
650
|
-
reason: Literal("explicit-restart"),
|
|
651
|
-
client: Struct({
|
|
652
|
-
kind: Literals(["cli", "mcp", "sdk"]),
|
|
653
|
-
instanceId: RelayIdentity,
|
|
654
|
-
buildId: RelayBuildId
|
|
655
|
-
}),
|
|
656
|
-
force: optionalKey(Boolean3)
|
|
657
|
-
});
|
|
658
|
-
var RelayShutdownResponse = Struct({
|
|
659
|
-
stopping: Literal(true)
|
|
660
|
-
});
|
|
661
|
-
var NetworkContentMode = Literals(["omit", "embed"]);
|
|
662
|
-
var NetworkStartRequest = Struct({
|
|
663
|
-
sessionId: NonEmptyString,
|
|
664
|
-
urlFilter: optionalKey(String3),
|
|
665
|
-
resourceTypes: optionalKey(ArraySchema(NonEmptyString).check(isMaxLength(50))),
|
|
666
|
-
content: optionalKey(NetworkContentMode),
|
|
667
|
-
maxBodyBytes: optionalKey(Int2.check(isBetween({ minimum: 1, maximum: 1e7 }))),
|
|
668
|
-
maxTotalBodyBytes: optionalKey(Int2.check(isBetween({ minimum: 1, maximum: 1e8 }))),
|
|
669
|
-
maxEntries: optionalKey(Int2.check(isBetween({ minimum: 1, maximum: 1e4 }))),
|
|
670
|
-
maxDurationMs: optionalKey(Int2.check(isBetween({ minimum: 1, maximum: 86400000 })))
|
|
671
|
-
});
|
|
672
|
-
var NetworkSessionRequest = Struct({ sessionId: NonEmptyString });
|
|
673
|
-
var NetworkStopRequest = NetworkSessionRequest.pipe(fieldsAssign({
|
|
674
|
-
outputPath: optionalKey(String3),
|
|
675
|
-
secrets: optionalKey(NonEmptyString)
|
|
676
|
-
}));
|
|
677
|
-
var NetworkStatusResponse = Struct({
|
|
678
|
-
active: Boolean3,
|
|
679
|
-
startedAt: optionalKey(String3),
|
|
680
|
-
entryCount: Number2,
|
|
681
|
-
responseCount: Number2,
|
|
682
|
-
failureCount: Number2,
|
|
683
|
-
capturedBodyBytes: Number2,
|
|
684
|
-
truncatedBodyCount: Number2,
|
|
685
|
-
droppedEntryCount: Number2,
|
|
686
|
-
urlFilter: optionalKey(String3),
|
|
687
|
-
resourceTypes: optionalKey(ArraySchema(String3)),
|
|
688
|
-
content: optionalKey(NetworkContentMode),
|
|
689
|
-
secrets: optionalKey(String3),
|
|
690
|
-
endsAt: optionalKey(String3),
|
|
691
|
-
ended: optionalKey(String3)
|
|
692
|
-
});
|
|
693
|
-
var AuthProfileSlotSummary = Struct({
|
|
694
|
-
ref: String3,
|
|
695
|
-
sources: ArraySchema(String3),
|
|
696
|
-
expiresAt: optionalKey(String3),
|
|
697
|
-
expired: Boolean3
|
|
698
|
-
});
|
|
699
|
-
var AuthProfileSummary = Struct({
|
|
700
|
-
name: String3,
|
|
701
|
-
createdAt: String3,
|
|
702
|
-
updatedAt: String3,
|
|
703
|
-
slotCount: Number2,
|
|
704
|
-
slots: ArraySchema(AuthProfileSlotSummary)
|
|
705
|
-
});
|
|
706
|
-
var NetworkEndpointDigest = Struct({
|
|
707
|
-
method: String3,
|
|
708
|
-
url: String3,
|
|
709
|
-
status: optionalKey(Number2),
|
|
710
|
-
count: Number2,
|
|
711
|
-
requestHeaders: optionalKey(ArraySchema(String3)),
|
|
712
|
-
requestKeys: optionalKey(ArraySchema(String3)),
|
|
713
|
-
responseKeys: optionalKey(ArraySchema(String3))
|
|
714
|
-
});
|
|
715
|
-
var NetworkStopResponse = NetworkStatusResponse.pipe(fieldsAssign({
|
|
716
|
-
active: Literal(false),
|
|
717
|
-
stoppedAt: String3,
|
|
718
|
-
outputPath: optionalKey(String3),
|
|
719
|
-
authProfile: optionalKey(AuthProfileSummary),
|
|
720
|
-
updatedSecretRefs: ArraySchema(String3),
|
|
721
|
-
observedSecretRefs: ArraySchema(String3),
|
|
722
|
-
endpoints: optionalKey(ArraySchema(NetworkEndpointDigest))
|
|
723
|
-
}));
|
|
724
|
-
var NetworkCancelResponse = Struct({ cancelled: Boolean3 });
|
|
725
|
-
var AuthProfileRequest = Struct({ name: NonEmptyString });
|
|
726
|
-
var AuthRefreshRequest = Struct({
|
|
727
|
-
sessionId: NonEmptyString,
|
|
728
|
-
name: NonEmptyString,
|
|
729
|
-
urlFilter: optionalKey(String3),
|
|
730
|
-
timeoutMs: optionalKey(Int2.check(isGreaterThan(0)))
|
|
731
|
-
});
|
|
732
|
-
var AuthRunRequest = Struct({
|
|
733
|
-
name: NonEmptyString,
|
|
734
|
-
command: NonEmptyString,
|
|
735
|
-
args: optionalKey(ArraySchema(String3)),
|
|
736
|
-
cwd: optionalKey(String3),
|
|
737
|
-
timeoutMs: optionalKey(Int2.check(isGreaterThan(0)))
|
|
738
|
-
});
|
|
739
|
-
var AuthRunResponse = Struct({
|
|
740
|
-
exitCode: Number2,
|
|
741
|
-
signal: NullOr(String3),
|
|
742
|
-
stdout: String3,
|
|
743
|
-
stderr: String3,
|
|
744
|
-
stdoutTruncated: Boolean3,
|
|
745
|
-
stderrTruncated: Boolean3,
|
|
746
|
-
durationMs: Number2
|
|
747
|
-
});
|
|
748
|
-
var RecordingMode = Literals(["tab-capture", "cdp"]);
|
|
749
|
-
var RecordingRequestedMode = Literals(["auto", "tab-capture", "cdp"]);
|
|
750
|
-
var RecordingFrameRate = Number2.check(isInt(), isBetween({ minimum: 1, maximum: 60 }));
|
|
751
|
-
var RecordingQuality = Struct({
|
|
752
|
-
width: Number2,
|
|
753
|
-
height: Number2,
|
|
754
|
-
frameRate: Number2,
|
|
755
|
-
sourceFrameCount: Number2,
|
|
756
|
-
encodedSourceFrameCount: Number2,
|
|
757
|
-
coalescedFrameCount: Number2,
|
|
758
|
-
droppedFrameCount: Number2,
|
|
759
|
-
achievedSourceFrameRate: Number2,
|
|
760
|
-
achievedEncodedSourceFrameRate: Number2,
|
|
761
|
-
screenshotFallback: Boolean3,
|
|
762
|
-
sourceWidth: optionalKey(Number2),
|
|
763
|
-
sourceHeight: optionalKey(Number2)
|
|
764
|
-
});
|
|
765
|
-
var RecordingTargetRequest = Struct({
|
|
766
|
-
sessionId: optionalKey(String3),
|
|
767
|
-
tabId: optionalKey(Number2)
|
|
768
|
-
});
|
|
769
|
-
var RecordingStartRequest = RecordingTargetRequest.pipe(fieldsAssign({
|
|
770
|
-
outputPath: String3,
|
|
771
|
-
mode: optionalKey(RecordingRequestedMode),
|
|
772
|
-
audio: optionalKey(Boolean3),
|
|
773
|
-
frameRate: optionalKey(RecordingFrameRate),
|
|
774
|
-
videoBitsPerSecond: optionalKey(Number2),
|
|
775
|
-
audioBitsPerSecond: optionalKey(Number2),
|
|
776
|
-
maxDurationMs: optionalKey(Number2),
|
|
777
|
-
cursor: optionalKey(Boolean3)
|
|
778
|
-
}));
|
|
779
|
-
var RecordingArtifactType = Literals(["webm", "mp4"]);
|
|
780
|
-
var RecordingStartResponse = Struct({
|
|
781
|
-
success: Boolean3,
|
|
782
|
-
tabId: optionalKey(Number2),
|
|
783
|
-
startedAt: optionalKey(Number2),
|
|
784
|
-
path: optionalKey(String3),
|
|
785
|
-
mimeType: optionalKey(String3),
|
|
786
|
-
mode: optionalKey(RecordingMode),
|
|
787
|
-
artifactType: optionalKey(RecordingArtifactType),
|
|
788
|
-
frameRate: optionalKey(Number2),
|
|
789
|
-
error: optionalKey(String3)
|
|
790
|
-
});
|
|
791
|
-
var RecordingStopResponse = Struct({
|
|
792
|
-
success: Boolean3,
|
|
793
|
-
tabId: optionalKey(Number2),
|
|
794
|
-
duration: optionalKey(Number2),
|
|
795
|
-
path: optionalKey(String3),
|
|
796
|
-
size: optionalKey(Number2),
|
|
797
|
-
mode: optionalKey(RecordingMode),
|
|
798
|
-
artifactType: optionalKey(RecordingArtifactType),
|
|
799
|
-
frameCount: optionalKey(Number2),
|
|
800
|
-
quality: optionalKey(RecordingQuality),
|
|
801
|
-
error: optionalKey(String3)
|
|
802
|
-
});
|
|
803
|
-
var RecordingStatusResponse = Struct({
|
|
804
|
-
isRecording: Boolean3,
|
|
805
|
-
tabId: optionalKey(Number2),
|
|
806
|
-
startedAt: optionalKey(Number2),
|
|
807
|
-
path: optionalKey(String3),
|
|
808
|
-
size: optionalKey(Number2),
|
|
809
|
-
mode: optionalKey(RecordingMode),
|
|
810
|
-
artifactType: optionalKey(RecordingArtifactType),
|
|
811
|
-
frameCount: optionalKey(Number2),
|
|
812
|
-
quality: optionalKey(RecordingQuality)
|
|
813
|
-
});
|
|
814
|
-
var TabsCleanupResponse = Struct({
|
|
815
|
-
closed: ArraySchema(Struct({ tabId: Number2, title: String3, idleMinutes: Number2 }))
|
|
816
|
-
});
|
|
817
|
-
var SettingValue = Union([String3, Number2]);
|
|
818
|
-
var SettingReport = Struct({
|
|
819
|
-
value: SettingValue,
|
|
820
|
-
effective: SettingValue,
|
|
821
|
-
allowed: ArraySchema(SettingValue),
|
|
822
|
-
description: String3,
|
|
823
|
-
overriddenBy: optionalKey(String3)
|
|
824
|
-
});
|
|
825
|
-
var SettingsGetResponse = Struct({
|
|
826
|
-
settings: Record(String3, SettingReport),
|
|
827
|
-
note: String3
|
|
828
|
-
});
|
|
829
|
-
var SettingsSetResponse = Struct({
|
|
830
|
-
changed: ArraySchema(Struct({ key: String3, from: SettingValue, to: SettingValue })),
|
|
831
|
-
unchanged: ArraySchema(String3),
|
|
832
|
-
overridden: ArraySchema(Struct({ key: String3, requested: SettingValue, variable: String3, effective: SettingValue })),
|
|
833
|
-
settings: Record(String3, SettingReport),
|
|
834
|
-
message: String3
|
|
835
|
-
});
|
|
836
|
-
var RecordingCancelResponse = Struct({
|
|
837
|
-
success: Boolean3,
|
|
838
|
-
error: optionalKey(String3)
|
|
839
|
-
});
|
|
840
|
-
var FlightRecorderStartRequest = RecordingTargetRequest.pipe(fieldsAssign({
|
|
841
|
-
retentionMs: optionalKey(Number2.check(isInt(), isBetween({ minimum: 1000, maximum: 120000 }))),
|
|
842
|
-
frameRate: optionalKey(RecordingFrameRate),
|
|
843
|
-
cursor: optionalKey(Boolean3)
|
|
844
|
-
}));
|
|
845
|
-
var FlightRecorderStatusResponse = Struct({
|
|
846
|
-
active: Boolean3,
|
|
847
|
-
tabId: optionalKey(Number2),
|
|
848
|
-
sessionId: optionalKey(String3),
|
|
849
|
-
startedAt: optionalKey(Number2),
|
|
850
|
-
retentionMs: optionalKey(Number2),
|
|
851
|
-
retainedDurationMs: optionalKey(Number2),
|
|
852
|
-
frameRate: optionalKey(Number2),
|
|
853
|
-
bufferedFrames: optionalKey(Number2),
|
|
854
|
-
bufferedBytes: optionalKey(Number2),
|
|
855
|
-
sourceFrameCount: optionalKey(Number2),
|
|
856
|
-
droppedFrameCount: optionalKey(Number2),
|
|
857
|
-
saving: optionalKey(Boolean3)
|
|
858
|
-
});
|
|
859
|
-
var FlightRecorderSaveRequest = RecordingTargetRequest.pipe(fieldsAssign({
|
|
860
|
-
outputPath: String3,
|
|
861
|
-
durationMs: optionalKey(Number2.check(isInt(), isGreaterThan(0)))
|
|
862
|
-
}));
|
|
863
|
-
var FlightRecorderSaveResponse = Struct({
|
|
864
|
-
path: String3,
|
|
865
|
-
durationMs: Number2,
|
|
866
|
-
frameCount: Number2,
|
|
867
|
-
sourceFrameCount: Number2,
|
|
868
|
-
droppedFrameCount: Number2
|
|
869
|
-
});
|
|
870
|
-
var FlightRecorderCancelResponse = Struct({ cancelled: Boolean3 });
|
|
871
|
-
var RelayErrorCode = Literals([
|
|
872
|
-
"browser-unavailable",
|
|
873
|
-
"invalid-request",
|
|
874
|
-
"unauthorized",
|
|
875
|
-
"relay-starting",
|
|
876
|
-
"relay-busy",
|
|
877
|
-
"auth-profile-not-found",
|
|
878
|
-
"capture-conflict",
|
|
879
|
-
"session-already-exists",
|
|
880
|
-
"session-inactive",
|
|
881
|
-
"session-not-found",
|
|
882
|
-
"session-timeout",
|
|
883
|
-
"setup-failed",
|
|
884
|
-
"target-ambiguous",
|
|
885
|
-
"target-changed",
|
|
886
|
-
"target-not-found",
|
|
887
|
-
"target-owned",
|
|
888
|
-
"internal"
|
|
889
|
-
]);
|
|
890
|
-
var ErrorEnvelope = Struct({
|
|
891
|
-
error: String3,
|
|
892
|
-
code: optionalKey(RelayErrorCode)
|
|
893
|
-
});
|
|
894
|
-
|
|
895
|
-
// src/relay/http.ts
|
|
896
|
-
var maxCliBodyBytes = 1e6;
|
|
897
|
-
|
|
898
|
-
class HttpRouteError2 extends TaggedError2()("HttpApi.HttpRouteError", { message: String3, status: Number2, code: RelayErrorCode }) {
|
|
899
|
-
}
|
|
900
|
-
function formatHostForUrl2(host) {
|
|
901
|
-
if (host.includes(":") && !host.startsWith("[")) {
|
|
902
|
-
return `[${host}]`;
|
|
903
|
-
}
|
|
904
|
-
return host;
|
|
905
|
-
}
|
|
906
|
-
function listenHttpServer2(options) {
|
|
907
|
-
return callback2((resume) => {
|
|
908
|
-
const onError = (error) => {
|
|
909
|
-
resume(fail6(error));
|
|
910
|
-
};
|
|
911
|
-
options.server.once("error", onError);
|
|
912
|
-
options.server.listen(options.port, options.host, () => {
|
|
913
|
-
options.server.off("error", onError);
|
|
914
|
-
resume(void_3);
|
|
915
|
-
});
|
|
916
|
-
return sync2(() => {
|
|
917
|
-
options.server.off("error", onError);
|
|
918
|
-
});
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
function closeHttpServer2(server) {
|
|
922
|
-
if (!server.listening) {
|
|
923
|
-
return void_3;
|
|
924
|
-
}
|
|
925
|
-
return callback2((resume) => {
|
|
926
|
-
server.close((error) => {
|
|
927
|
-
if (error) {
|
|
928
|
-
resume(fail6(new Error("close http server", { cause: error })));
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
resume(void_3);
|
|
932
|
-
});
|
|
933
|
-
server.closeAllConnections();
|
|
934
|
-
return void_3;
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
function closeWebSocketServer2(server) {
|
|
938
|
-
return callback2((resume) => {
|
|
939
|
-
server.close((error) => {
|
|
940
|
-
const nodeError = error;
|
|
941
|
-
if (nodeError?.code === "ERR_SERVER_NOT_RUNNING") {
|
|
942
|
-
resume(void_3);
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
if (error) {
|
|
946
|
-
resume(fail6(new Error("close websocket server", { cause: error })));
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
resume(void_3);
|
|
950
|
-
});
|
|
951
|
-
return void_3;
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
function logCloseError2(message) {
|
|
955
|
-
return (effect) => {
|
|
956
|
-
return catch_(effect, (error) => {
|
|
957
|
-
return sync2(() => {
|
|
958
|
-
console.error(message, error);
|
|
959
|
-
});
|
|
960
|
-
});
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
function sendJson2(response, value, status = 200) {
|
|
964
|
-
response.writeHead(status, { "content-type": "application/json" });
|
|
965
|
-
response.end(JSON.stringify(value));
|
|
966
|
-
}
|
|
967
|
-
function readJsonBody2(request) {
|
|
968
|
-
const contentType = request.headers["content-type"];
|
|
969
|
-
const contentTypeValue = Array.isArray(contentType) ? contentType[0] : contentType;
|
|
970
|
-
if (!contentTypeValue?.toLowerCase().includes("application/json")) {
|
|
971
|
-
return fail6(new HttpRouteError2({ message: "Content-Type must be application/json", status: 415, code: "invalid-request" }));
|
|
972
|
-
}
|
|
973
|
-
return callback2((resume) => {
|
|
974
|
-
const chunks = [];
|
|
975
|
-
let totalBytes = 0;
|
|
976
|
-
let completed = false;
|
|
977
|
-
const onData = (chunk) => {
|
|
978
|
-
if (completed) {
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
totalBytes += chunk.byteLength;
|
|
982
|
-
if (totalBytes > maxCliBodyBytes) {
|
|
983
|
-
completed = true;
|
|
984
|
-
request.destroy(new Error(`Request body exceeds ${maxCliBodyBytes} bytes`));
|
|
985
|
-
resume(fail6(new HttpRouteError2({ message: `Request body exceeds ${maxCliBodyBytes} bytes`, status: 413, code: "invalid-request" })));
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
chunks.push(chunk);
|
|
989
|
-
};
|
|
990
|
-
const onError = (error) => {
|
|
991
|
-
if (completed) {
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
completed = true;
|
|
995
|
-
resume(fail6(new Error("read request body", { cause: error })));
|
|
996
|
-
};
|
|
997
|
-
const onAbort = () => {
|
|
998
|
-
if (completed) {
|
|
999
|
-
return;
|
|
1000
|
-
}
|
|
1001
|
-
completed = true;
|
|
1002
|
-
resume(fail6(new Error("request body aborted")));
|
|
1003
|
-
};
|
|
1004
|
-
const onClose = () => {
|
|
1005
|
-
if (completed || request.complete) {
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
completed = true;
|
|
1009
|
-
resume(fail6(new Error("request closed before body completed")));
|
|
1010
|
-
};
|
|
1011
|
-
const onEnd = () => {
|
|
1012
|
-
if (completed) {
|
|
1013
|
-
return;
|
|
1014
|
-
}
|
|
1015
|
-
completed = true;
|
|
1016
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
1017
|
-
if (!text.trim()) {
|
|
1018
|
-
resume(succeed6({}));
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
try {
|
|
1022
|
-
resume(succeed6(parseJsonObject(text)));
|
|
1023
|
-
} catch (error) {
|
|
1024
|
-
resume(fail6(new HttpRouteError2({ message: "Invalid JSON body", status: 400, code: "invalid-request" })));
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
request.on("data", onData);
|
|
1028
|
-
request.on("error", onError);
|
|
1029
|
-
request.on("aborted", onAbort);
|
|
1030
|
-
request.on("close", onClose);
|
|
1031
|
-
request.on("end", onEnd);
|
|
1032
|
-
return sync2(() => {
|
|
1033
|
-
request.off("data", onData);
|
|
1034
|
-
request.off("error", onError);
|
|
1035
|
-
request.off("aborted", onAbort);
|
|
1036
|
-
request.off("close", onClose);
|
|
1037
|
-
request.off("end", onEnd);
|
|
1038
|
-
});
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// src/relay/origins.ts
|
|
1043
|
-
import crypto from "node:crypto";
|
|
1044
|
-
var stableUnpackedExtensionOrigin2 = `chrome-extension://${unpackedExtensionId}`;
|
|
1045
|
-
function chromeExtensionOriginForPath2(extensionPath, platform = process.platform) {
|
|
1046
|
-
const normalizedPath = platform === "win32" && /^[a-z]:/.test(extensionPath) ? extensionPath.charAt(0).toUpperCase() + extensionPath.slice(1) : extensionPath;
|
|
1047
|
-
const pathBytes = platform === "win32" ? Buffer.from(normalizedPath, "utf16le") : normalizedPath;
|
|
1048
|
-
const digest = crypto.createHash("sha256").update(pathBytes).digest();
|
|
1049
|
-
let extensionId = "";
|
|
1050
|
-
for (const byte of digest.subarray(0, 16)) {
|
|
1051
|
-
extensionId += String.fromCharCode(97 + (byte >> 4), 97 + (byte & 15));
|
|
1052
|
-
}
|
|
1053
|
-
return `chrome-extension://${extensionId}`;
|
|
1054
|
-
}
|
|
1055
|
-
var chromeExtensionOriginPattern = /^chrome-extension:\/\/[a-p]+$/;
|
|
1056
|
-
function parseAdditionalExtensionOrigins2(raw) {
|
|
1057
|
-
if (!raw) {
|
|
1058
|
-
return [];
|
|
1059
|
-
}
|
|
1060
|
-
const seen = new Set;
|
|
1061
|
-
const origins = [];
|
|
1062
|
-
for (const token of raw.split(/[\s,]+/)) {
|
|
1063
|
-
const value = token.trim();
|
|
1064
|
-
if (!value || !chromeExtensionOriginPattern.test(value) || seen.has(value)) {
|
|
1065
|
-
continue;
|
|
1066
|
-
}
|
|
1067
|
-
seen.add(value);
|
|
1068
|
-
origins.push(value);
|
|
1069
|
-
}
|
|
1070
|
-
return origins;
|
|
1071
|
-
}
|
|
1072
|
-
function validateHostHeader2(options) {
|
|
1073
|
-
const parsed = parseHostHeader(options.hostHeader);
|
|
1074
|
-
if (!parsed) {
|
|
1075
|
-
return "Invalid Host header";
|
|
1076
|
-
}
|
|
1077
|
-
if (parsed.port !== undefined && parsed.port !== options.port) {
|
|
1078
|
-
return "Invalid Host header port";
|
|
1079
|
-
}
|
|
1080
|
-
const allowedHosts = new Set(["localhost", "127.0.0.1", "::1", normalizeHostname(options.host)]);
|
|
1081
|
-
if (!allowedHosts.has(parsed.hostname)) {
|
|
1082
|
-
return "Invalid Host header";
|
|
1083
|
-
}
|
|
1084
|
-
return;
|
|
1085
|
-
}
|
|
1086
|
-
function validateBrowserFetchSite2(request) {
|
|
1087
|
-
const secFetchSite = request.headers["sec-fetch-site"];
|
|
1088
|
-
const value = Array.isArray(secFetchSite) ? secFetchSite[0] : secFetchSite;
|
|
1089
|
-
if (!value || value === "same-origin" || value === "none") {
|
|
1090
|
-
return;
|
|
1091
|
-
}
|
|
1092
|
-
return "Cross-origin browser requests are not allowed";
|
|
1093
|
-
}
|
|
1094
|
-
function validateWebSocketOrigin2(options) {
|
|
1095
|
-
if (!options.origin) {
|
|
1096
|
-
return options.requireChromeExtension ? "Extension WebSocket origin is required" : undefined;
|
|
1097
|
-
}
|
|
1098
|
-
if (options.origin === stableUnpackedExtensionOrigin2 || options.additionalChromeExtensionOrigins?.has(options.origin)) {
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
if (options.requireChromeExtension) {
|
|
1102
|
-
return "Extension WebSocket origin is not allowed";
|
|
1103
|
-
}
|
|
1104
|
-
return "WebSocket origin is not allowed";
|
|
1105
|
-
}
|
|
1106
|
-
function normalizeHostname(host) {
|
|
1107
|
-
const value = host.trim().toLowerCase();
|
|
1108
|
-
if (value.startsWith("[") && value.endsWith("]")) {
|
|
1109
|
-
return value.slice(1, -1);
|
|
1110
|
-
}
|
|
1111
|
-
return value;
|
|
1112
|
-
}
|
|
1113
|
-
function parseHostHeader(hostHeader) {
|
|
1114
|
-
const value = hostHeader?.trim().toLowerCase();
|
|
1115
|
-
if (!value) {
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
if (value.startsWith("[")) {
|
|
1119
|
-
const closingBracket = value.indexOf("]");
|
|
1120
|
-
if (closingBracket === -1) {
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
const hostname = value.slice(1, closingBracket);
|
|
1124
|
-
const rest = value.slice(closingBracket + 1);
|
|
1125
|
-
if (!hostname) {
|
|
1126
|
-
return;
|
|
1127
|
-
}
|
|
1128
|
-
if (!rest) {
|
|
1129
|
-
return { hostname };
|
|
1130
|
-
}
|
|
1131
|
-
if (!rest.startsWith(":")) {
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
const port = parsePort(rest.slice(1));
|
|
1135
|
-
return port === undefined ? undefined : { hostname, port };
|
|
1136
|
-
}
|
|
1137
|
-
if (value === "::1") {
|
|
1138
|
-
return { hostname: "::1" };
|
|
1139
|
-
}
|
|
1140
|
-
const colonCount = value.split(":").length - 1;
|
|
1141
|
-
if (colonCount > 1) {
|
|
1142
|
-
return;
|
|
1143
|
-
}
|
|
1144
|
-
if (colonCount === 0) {
|
|
1145
|
-
return { hostname: value };
|
|
1146
|
-
}
|
|
1147
|
-
const [hostname, portText] = value.split(":");
|
|
1148
|
-
if (!hostname || portText === undefined) {
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
const port = parsePort(portText);
|
|
1152
|
-
return port === undefined ? undefined : { hostname, port };
|
|
1153
|
-
}
|
|
1154
|
-
function parsePort(value) {
|
|
1155
|
-
if (!/^\d+$/.test(value)) {
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
const port = Number(value);
|
|
1159
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
1160
|
-
return;
|
|
1161
|
-
}
|
|
1162
|
-
return port;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
// src/relay/helpers.ts
|
|
1166
|
-
var defaultHost2 = "127.0.0.1";
|
|
1167
|
-
var defaultPort2 = 19988;
|
|
1168
|
-
var RawTargetSelection = Struct({
|
|
1169
|
-
urlIncludes: optionalKey(String3),
|
|
1170
|
-
index: optionalKey(Int2.check(isGreaterThanOrEqualTo(0)))
|
|
1171
|
-
});
|
|
1172
|
-
var decodeRawTargetSelection = decodeUnknownOption(RawTargetSelection);
|
|
1173
|
-
var RawTargetInfo = Struct({
|
|
1174
|
-
targetId: String3,
|
|
1175
|
-
type: Literals(["page", "iframe", "worker"]),
|
|
1176
|
-
title: optionalKey(String3),
|
|
1177
|
-
url: String3,
|
|
1178
|
-
canAccessOpener: optionalKey(Boolean3),
|
|
1179
|
-
browserContextId: optionalKey(String3),
|
|
1180
|
-
openerId: optionalKey(String3),
|
|
1181
|
-
parentFrameId: optionalKey(String3)
|
|
1182
|
-
});
|
|
1183
|
-
var decodeRawTargetInfo = decodeUnknownOption(RawTargetInfo);
|
|
1184
|
-
function optionalSessionId2(value) {
|
|
1185
|
-
if (!isString(value) || !value.trim()) {
|
|
1186
|
-
return;
|
|
1187
|
-
}
|
|
1188
|
-
const id = value.trim();
|
|
1189
|
-
if (!isValidSessionId2(id)) {
|
|
1190
|
-
throw new HttpRouteError2({
|
|
1191
|
-
message: "Session ids must use lowercase letters, numbers, and dashes, and be at most 63 characters",
|
|
1192
|
-
status: 400,
|
|
1193
|
-
code: "invalid-request"
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
return id;
|
|
1197
|
-
}
|
|
1198
|
-
function isValidSessionId2(id) {
|
|
1199
|
-
if (id.length < 1 || id.length > 63 || id === "." || id === "..")
|
|
1200
|
-
return false;
|
|
1201
|
-
if (/[A-Z/\\:\0-\x1f\x7f]/.test(id))
|
|
1202
|
-
return false;
|
|
1203
|
-
return /^(?:[\p{Extended_Pictographic}\u200d\ufe0f]+\s*)?[a-z0-9][a-z0-9\p{Extended_Pictographic}\u200d\ufe0f\s_-]*$/u.test(id);
|
|
1204
|
-
}
|
|
1205
|
-
function requiredSessionId2(value) {
|
|
1206
|
-
const id = optionalSessionId2(value);
|
|
1207
|
-
if (!id) {
|
|
1208
|
-
throw new HttpRouteError2({ message: "sessionId is required", status: 400, code: "invalid-request" });
|
|
1209
|
-
}
|
|
1210
|
-
return id;
|
|
1211
|
-
}
|
|
1212
|
-
function parseTargetSelection2(value) {
|
|
1213
|
-
if (value === undefined) {
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
if (!getObject2(value)) {
|
|
1217
|
-
throw new HttpRouteError2({ message: "targetSelection must be an object", status: 400, code: "invalid-request" });
|
|
1218
|
-
}
|
|
1219
|
-
const decoded = decodeRawTargetSelection(value);
|
|
1220
|
-
if (isNone(decoded)) {
|
|
1221
|
-
throw new HttpRouteError2({ message: "targetSelection.index must be a non-negative integer", status: 400, code: "invalid-request" });
|
|
1222
|
-
}
|
|
1223
|
-
const urlIncludes = decoded.value.urlIncludes ? decoded.value.urlIncludes : undefined;
|
|
1224
|
-
const index = decoded.value.index;
|
|
1225
|
-
if (urlIncludes && index !== undefined) {
|
|
1226
|
-
throw new HttpRouteError2({ message: "Use only one target selector", status: 400, code: "invalid-request" });
|
|
1227
|
-
}
|
|
1228
|
-
return {
|
|
1229
|
-
...urlIncludes ? { urlIncludes } : {},
|
|
1230
|
-
...index !== undefined ? { index } : {}
|
|
1231
|
-
};
|
|
1232
|
-
}
|
|
1233
|
-
function generateSessionId2(existing) {
|
|
1234
|
-
const adjectives = ["amber", "brisk", "calm", "clever", "cosmic", "gentle", "lucky", "quiet", "rapid", "tidy"];
|
|
1235
|
-
const nouns = ["badger", "comet", "falcon", "otter", "panda", "raven", "sparrow", "tiger", "walrus", "wombat"];
|
|
1236
|
-
for (let attempt = 0;attempt < 100; attempt++) {
|
|
1237
|
-
const adjective = adjectives[Math.floor(Math.random() * adjectives.length)] ?? "calm";
|
|
1238
|
-
const noun = nouns[Math.floor(Math.random() * nouns.length)] ?? "otter";
|
|
1239
|
-
const suffix = String(Math.floor(Math.random() * 1000)).padStart(3, "0");
|
|
1240
|
-
const id = `${adjective}-${noun}-${suffix}`;
|
|
1241
|
-
if (!existing.has(id)) {
|
|
1242
|
-
return id;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
return `session-${Date.now().toString(36)}`;
|
|
1246
|
-
}
|
|
1247
|
-
function sendCdpResponse2(socket, response) {
|
|
1248
|
-
socket.send(JSON.stringify(response));
|
|
1249
|
-
}
|
|
1250
|
-
function sendCdpEvent2(socket, event) {
|
|
1251
|
-
socket.send(JSON.stringify(event));
|
|
1252
|
-
}
|
|
1253
|
-
function getObject2(value) {
|
|
1254
|
-
return isObject(value) ? value : undefined;
|
|
1255
|
-
}
|
|
1256
|
-
function getString2(object, key) {
|
|
1257
|
-
const value = object?.[key];
|
|
1258
|
-
return isString(value) ? value : undefined;
|
|
1259
|
-
}
|
|
1260
|
-
function createTargetUrl2(params) {
|
|
1261
|
-
const url = getString2(params, "url");
|
|
1262
|
-
return url === undefined || url === "" ? "about:blank" : url;
|
|
1263
|
-
}
|
|
1264
|
-
function getNumber2(object, key) {
|
|
1265
|
-
const value = object?.[key];
|
|
1266
|
-
return isNumber(value) ? value : undefined;
|
|
1267
|
-
}
|
|
1268
|
-
function getIdText2(object, key) {
|
|
1269
|
-
const value = object?.[key];
|
|
1270
|
-
return isNumber(value) || isString(value) ? String(value) : undefined;
|
|
1271
|
-
}
|
|
1272
|
-
function headerValue2(value) {
|
|
1273
|
-
if (!isString(value) || !value)
|
|
1274
|
-
return;
|
|
1275
|
-
try {
|
|
1276
|
-
return decodeURIComponent(value);
|
|
1277
|
-
} catch {
|
|
1278
|
-
return value;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
function getTargetInfo2(value) {
|
|
1282
|
-
return match(decodeRawTargetInfo(value), {
|
|
1283
|
-
onNone: () => {
|
|
1284
|
-
return;
|
|
1285
|
-
},
|
|
1286
|
-
onSome: (info) => ({
|
|
1287
|
-
targetId: info.targetId,
|
|
1288
|
-
type: info.type,
|
|
1289
|
-
title: info.title ?? info.url,
|
|
1290
|
-
url: info.url,
|
|
1291
|
-
attached: true,
|
|
1292
|
-
canAccessOpener: info.canAccessOpener ?? false,
|
|
1293
|
-
...info.browserContextId === undefined ? {} : { browserContextId: info.browserContextId },
|
|
1294
|
-
...info.openerId === undefined ? {} : { openerId: info.openerId },
|
|
1295
|
-
...info.parentFrameId === undefined ? {} : { parentFrameId: info.parentFrameId }
|
|
1296
|
-
})
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
function isRestrictedTarget2(targetInfo) {
|
|
1300
|
-
if (targetInfo.type !== "page" && targetInfo.type !== "iframe" && targetInfo.type !== "worker") {
|
|
1301
|
-
return true;
|
|
1302
|
-
}
|
|
1303
|
-
return isRestrictedUrl2(targetInfo.url);
|
|
1304
|
-
}
|
|
1305
|
-
var restrictedUrlPrefixes = ["chrome://", "chrome-extension://", "chrome-untrusted://", "devtools://", "edge://", "brave://"];
|
|
1306
|
-
function isRestrictedUrl2(url) {
|
|
1307
|
-
if (!url) {
|
|
1308
|
-
return false;
|
|
1309
|
-
}
|
|
1310
|
-
return restrictedUrlPrefixes.some((prefix) => url.startsWith(prefix));
|
|
1311
|
-
}
|
|
1312
|
-
async function dataUrlDocument2(url) {
|
|
1313
|
-
const response = await fetch(url);
|
|
1314
|
-
const type = (response.headers.get("content-type") ?? "text/plain").split(";")[0]?.trim().toLowerCase() ?? "text/plain";
|
|
1315
|
-
if (type === "text/html" || type === "application/xhtml+xml")
|
|
1316
|
-
return await response.text();
|
|
1317
|
-
if (type.startsWith("text/") || type === "application/json" || type.endsWith("+json") || type === "application/javascript") {
|
|
1318
|
-
const text = (await response.text()).replace(/[&<>]/g, (char) => ({ "&": "&", "<": "<", ">": ">" })[char] ?? char);
|
|
1319
|
-
return `<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">${text}</pre></body></html>`;
|
|
1320
|
-
}
|
|
1321
|
-
if (type.startsWith("image/")) {
|
|
1322
|
-
return `<html><body style="margin: 0; display: grid; place-items: center; min-height: 100vh;"><img src="${url.replace(/"/g, "%22")}"></body></html>`;
|
|
1323
|
-
}
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
428
|
// src/relay/lifecycle.ts
|
|
1328
429
|
import { execFileSync, spawn } from "node:child_process";
|
|
1329
|
-
import
|
|
430
|
+
import crypto from "node:crypto";
|
|
1330
431
|
import path3 from "node:path";
|
|
1331
432
|
import process3 from "node:process";
|
|
1332
433
|
import { fileURLToPath } from "node:url";
|
|
1333
434
|
// src/relay/client.ts
|
|
1334
435
|
var portConfig = Int("OPENCODE_BROWSER_PORT").pipe(withDefault(defaultPort2));
|
|
1335
436
|
var extensionOriginsConfig = String2("OPENCODE_BROWSER_EXTENSION_ORIGINS").pipe(withDefault(""));
|
|
1336
|
-
var endpointForPort = (port) => `http://127.0.0.1:${port}`;
|
|
1337
437
|
var unknownRelayReadSeconds = 5;
|
|
1338
438
|
var busyRelayReadSeconds = 30;
|
|
1339
439
|
|
|
@@ -1381,11 +481,12 @@ class Service extends Service2()("opencode-browser-cli/RelayClient") {
|
|
|
1381
481
|
var decodeErrorEnvelope = decodeUnknownOption(ErrorEnvelope);
|
|
1382
482
|
var decodeErrorMessage = decodeUnknownOption(Struct({ error: String3 }));
|
|
1383
483
|
var make3 = fn("RelayClient.make")(function* (options) {
|
|
1384
|
-
|
|
484
|
+
yield* portConfig.pipe(mapError2((cause) => new RelayConfigInvalid({
|
|
1385
485
|
message: `Invalid OPENCODE_BROWSER_PORT configuration: ${cause.message}`,
|
|
1386
486
|
cause
|
|
1387
487
|
})));
|
|
1388
|
-
const
|
|
488
|
+
const currentEndpoint = () => options?.endpoint ?? endpointForPort(resolveRelayPort());
|
|
489
|
+
const relayPort = configuredRelayPort();
|
|
1389
490
|
const httpClient = yield* HttpClient;
|
|
1390
491
|
const readBody = (response, path) => response.json.pipe(mapError2((cause) => new RelayDecodeFailed({
|
|
1391
492
|
message: `Relay returned an unreadable response for ${path}`,
|
|
@@ -1409,12 +510,16 @@ var make3 = fn("RelayClient.make")(function* (options) {
|
|
|
1409
510
|
cause
|
|
1410
511
|
})));
|
|
1411
512
|
}));
|
|
1412
|
-
const transportError = (path) => (cause) =>
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
513
|
+
const transportError = (path) => (cause) => {
|
|
514
|
+
const endpoint = currentEndpoint();
|
|
515
|
+
return new RelayUnreachable({
|
|
516
|
+
message: `browse relay is not reachable at ${endpoint}. Relay-backed CLI commands start it automatically; use \`${cliCommand("serve")}\` only for foreground debugging.`,
|
|
517
|
+
endpoint,
|
|
518
|
+
path,
|
|
519
|
+
cause
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
const isRelayClientError = (error) => error instanceof RelayUnreachable || error instanceof RelayRejected || error instanceof RelayDecodeFailed || error instanceof RelayEncodeFailed || error instanceof RelayTimedOut;
|
|
1418
523
|
let authorization;
|
|
1419
524
|
const authorize = (request) => {
|
|
1420
525
|
try {
|
|
@@ -1426,22 +531,98 @@ var make3 = fn("RelayClient.make")(function* (options) {
|
|
|
1426
531
|
return options?.clientPid === undefined ? authorized : setHeader(authorized, "opencode-browser-client-pid", String(options.clientPid));
|
|
1427
532
|
};
|
|
1428
533
|
let relayAnswered = false;
|
|
1429
|
-
const
|
|
534
|
+
const executeUnauthorized = (path, request) => httpClient.execute(request).pipe(mapError2(transportError(path)), tap(() => sync2(() => {
|
|
1430
535
|
relayAnswered = true;
|
|
1431
536
|
})));
|
|
1432
|
-
|
|
537
|
+
let verified;
|
|
538
|
+
const notBrowse = (endpoint, cause) => new RelayDecodeFailed({
|
|
539
|
+
message: `Relay port ${new URL(endpoint).port} is in use by another program (not a browse /version response).`,
|
|
540
|
+
path: "/version",
|
|
541
|
+
cause
|
|
542
|
+
});
|
|
543
|
+
const liveRelayState = () => {
|
|
544
|
+
try {
|
|
545
|
+
const state = readRelayState(stateRoot(), relayPort);
|
|
546
|
+
return state && state.configuredPort === relayPort && processAlive(state.pid) ? state : undefined;
|
|
547
|
+
} catch {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
const sameLiveState = (left, right) => left === undefined ? right === undefined : right !== undefined && left.port === right.port && left.instanceId === right.instanceId;
|
|
552
|
+
const verifyEndpoint = (endpoint, state = liveRelayState()) => suspend2(() => {
|
|
1433
553
|
const seconds = relayAnswered ? busyRelayReadSeconds : unknownRelayReadSeconds;
|
|
1434
|
-
return
|
|
554
|
+
return executeUnauthorized("/version", get(new URL("/version", endpoint))).pipe(flatMap3((response) => readBody(response, "/version").pipe(map6((body) => ({ response, body })))), flatMap3(({ response, body }) => {
|
|
555
|
+
const reply = typeof body === "object" && body !== null ? body : undefined;
|
|
556
|
+
if (response.status === 503 && reply?.code === "relay-starting") {
|
|
557
|
+
const envelope = decodeErrorEnvelope(body);
|
|
558
|
+
return fail6(new RelayRejected({
|
|
559
|
+
message: isSome(envelope) ? envelope.value.error : "Relay responded with HTTP 503 for /version",
|
|
560
|
+
status: 503,
|
|
561
|
+
path: "/version",
|
|
562
|
+
code: "relay-starting"
|
|
563
|
+
}));
|
|
564
|
+
}
|
|
565
|
+
if (response.status !== 200 || typeof reply?.version !== "string" || typeof reply.instanceId !== "string")
|
|
566
|
+
return fail6(notBrowse(endpoint, body));
|
|
567
|
+
const after = liveRelayState();
|
|
568
|
+
if (state !== undefined && !sameLiveState(state, after))
|
|
569
|
+
return fail6(notBrowse(endpoint, body));
|
|
570
|
+
if (after !== undefined && (after.port !== Number(new URL(endpoint).port) || after.instanceId !== reply.instanceId))
|
|
571
|
+
return fail6(notBrowse(endpoint, body));
|
|
572
|
+
return succeed6({ endpoint, instanceId: reply.instanceId, recorded: after?.instanceId });
|
|
573
|
+
}), timeoutOrElse({
|
|
574
|
+
duration: `${seconds} seconds`,
|
|
575
|
+
orElse: () => fail6(new RelayTimedOut({
|
|
576
|
+
message: `The relay on port ${new URL(endpoint).port} isn't answering (/version timed out after ${seconds}s).`,
|
|
577
|
+
path: "/version"
|
|
578
|
+
}))
|
|
579
|
+
}));
|
|
580
|
+
});
|
|
581
|
+
const ensureVerified = (endpoint) => {
|
|
582
|
+
const state = liveRelayState();
|
|
583
|
+
const port = Number(new URL(endpoint).port);
|
|
584
|
+
if (verified?.endpoint === endpoint && (state !== undefined && state.port === port && state.instanceId === verified.instanceId || state === undefined && verified.recorded === undefined))
|
|
585
|
+
return void_3;
|
|
586
|
+
return verifyEndpoint(endpoint, state).pipe(tap((value) => sync2(() => {
|
|
587
|
+
verified = value;
|
|
588
|
+
})), asVoid2);
|
|
589
|
+
};
|
|
590
|
+
const executeAuthorized = (endpoint, path, request) => suspend2(() => {
|
|
591
|
+
const target = new URL(request.url).origin;
|
|
592
|
+
if (target !== new URL(endpoint).origin) {
|
|
593
|
+
return fail6(new RelayDecodeFailed({
|
|
594
|
+
message: `Refusing to send the relay request for ${path} to ${target}: it was built for ${endpoint}.`,
|
|
595
|
+
path,
|
|
596
|
+
cause: request.url
|
|
597
|
+
}));
|
|
598
|
+
}
|
|
599
|
+
return ensureVerified(target).pipe(flatMap3(() => httpClient.execute(authorize(request))), mapError2((error) => isRelayClientError(error) ? error : transportError(path)(error)), tap(() => sync2(() => {
|
|
600
|
+
relayAnswered = true;
|
|
601
|
+
})), tapError((error) => sync2(() => {
|
|
602
|
+
if (error instanceof RelayUnreachable && verified?.endpoint === target)
|
|
603
|
+
verified = undefined;
|
|
604
|
+
})));
|
|
605
|
+
});
|
|
606
|
+
const requestJson = (path, schema) => suspend2(() => {
|
|
607
|
+
const endpoint = currentEndpoint();
|
|
608
|
+
const seconds = relayAnswered ? busyRelayReadSeconds : unknownRelayReadSeconds;
|
|
609
|
+
const request = get(new URL(path, endpoint));
|
|
610
|
+
const send = path === "/version" ? executeUnauthorized(path, request) : executeAuthorized(endpoint, path, request);
|
|
611
|
+
return send.pipe(flatMap3((response) => handleResponse(response, path, schema).pipe(map6((value) => ({ value, endpoint })))), timeoutOrElse({ duration: `${seconds} seconds`, orElse: () => fail6(new RelayTimedOut({
|
|
1435
612
|
message: `The relay on port ${new URL(endpoint).port} isn't answering (${path} timed out after ${seconds}s).`,
|
|
1436
613
|
path
|
|
1437
614
|
})) }));
|
|
1438
615
|
});
|
|
616
|
+
const getJson = (path, schema) => requestJson(path, schema).pipe(map6(({ value }) => value));
|
|
1439
617
|
const checkWhileWaiting = sleep(30000).pipe(andThen2(getJson("/version", RelayVersion)), forever);
|
|
1440
|
-
const postJson = (path, body, schema) =>
|
|
1441
|
-
|
|
1442
|
-
path,
|
|
1443
|
-
|
|
1444
|
-
|
|
618
|
+
const postJson = (path, body, schema) => suspend2(() => {
|
|
619
|
+
const endpoint = currentEndpoint();
|
|
620
|
+
return post(new URL(path, endpoint)).pipe(bodyJson(body), mapError2((cause) => new RelayEncodeFailed({
|
|
621
|
+
message: `Could not encode relay request for ${path}`,
|
|
622
|
+
path,
|
|
623
|
+
cause
|
|
624
|
+
})), flatMap3((request) => executeAuthorized(endpoint, path, request).pipe(flatMap3((response) => handleResponse(response, path, schema)), raceFirst(checkWhileWaiting))));
|
|
625
|
+
});
|
|
1445
626
|
const recordingTargetBody = (target) => ({
|
|
1446
627
|
...target.sessionId ? { sessionId: target.sessionId } : {},
|
|
1447
628
|
...target.tabId === undefined ? {} : { tabId: target.tabId }
|
|
@@ -1458,8 +639,26 @@ var make3 = fn("RelayClient.make")(function* (options) {
|
|
|
1458
639
|
return text ? `?${text}` : "";
|
|
1459
640
|
};
|
|
1460
641
|
return Service.of({
|
|
1461
|
-
endpoint
|
|
1462
|
-
|
|
642
|
+
get endpoint() {
|
|
643
|
+
return currentEndpoint();
|
|
644
|
+
},
|
|
645
|
+
version: suspend2(() => {
|
|
646
|
+
const state = liveRelayState();
|
|
647
|
+
return requestJson("/version", RelayVersion).pipe(flatMap3(({ value: version, endpoint }) => {
|
|
648
|
+
const instanceId = version.instanceId;
|
|
649
|
+
if (typeof instanceId !== "string")
|
|
650
|
+
return fail6(notBrowse(endpoint, version));
|
|
651
|
+
const after = liveRelayState();
|
|
652
|
+
if (state !== undefined && !sameLiveState(state, after))
|
|
653
|
+
return fail6(notBrowse(endpoint, version));
|
|
654
|
+
if (after !== undefined && (after.port !== Number(new URL(endpoint).port) || after.instanceId !== instanceId))
|
|
655
|
+
return fail6(notBrowse(endpoint, version));
|
|
656
|
+
return sync2(() => {
|
|
657
|
+
verified = { endpoint, instanceId, recorded: after?.instanceId };
|
|
658
|
+
return version;
|
|
659
|
+
});
|
|
660
|
+
}), mapError2((error) => error instanceof RelayDecodeFailed || error instanceof RelayRejected && !error.code && error.status === 404 ? new RelayDecodeFailed({ message: `Relay port ${new URL(currentEndpoint()).port} is in use by another program (not a browse /version response).`, path: "/version", cause: error }) : error));
|
|
661
|
+
}),
|
|
1463
662
|
shutdown: (request) => postJson("/shutdown", { ...request }, RelayShutdownResponse),
|
|
1464
663
|
extensionStatus: getJson("/extension/status", ExtensionStatus),
|
|
1465
664
|
targets: getJson("/json/list", TargetSummaries),
|
|
@@ -1685,7 +884,7 @@ function wideZ(value) {
|
|
|
1685
884
|
|
|
1686
885
|
// src/relay/lifecycle.ts
|
|
1687
886
|
var loadedCliEntrypoint = compiledBinary() ? process3.execPath : fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "../main.ts" : "./cli.mjs", import.meta.url));
|
|
1688
|
-
var clientInstanceId =
|
|
887
|
+
var clientInstanceId = crypto.randomUUID();
|
|
1689
888
|
function shouldWaitForExtensionReconnect(readiness) {
|
|
1690
889
|
return readiness.started || readiness.waitForReconnect === true;
|
|
1691
890
|
}
|
|
@@ -1743,7 +942,7 @@ var ensureRelay = fn("RelayLifecycle.ensureRelay")(function* (options) {
|
|
|
1743
942
|
...buildProblem ? { buildProblem } : {}
|
|
1744
943
|
};
|
|
1745
944
|
}
|
|
1746
|
-
const relayWasAbsent = isRelayUnreachable(initial.failure);
|
|
945
|
+
const relayWasAbsent = isRelayUnreachable(initial.failure) || isForeignListener(initial.failure, options.pinned);
|
|
1747
946
|
if (!relayWasAbsent && !isRelayStarting(initial.failure)) {
|
|
1748
947
|
return yield* initial.failure;
|
|
1749
948
|
}
|
|
@@ -1760,11 +959,12 @@ var ensureRelay = fn("RelayLifecycle.ensureRelay")(function* (options) {
|
|
|
1760
959
|
return { version, started: relayWasAbsent, ...buildProblem ? { buildProblem } : {} };
|
|
1761
960
|
});
|
|
1762
961
|
function waitForRelayReady(options) {
|
|
962
|
+
const retry2 = (error) => isRelayStartingOrUnreachable(error) || isForeignListener(error, options.pinned);
|
|
1763
963
|
return options.relay.version.pipe(retry({
|
|
1764
964
|
times: options.retryTimes ?? 200,
|
|
1765
965
|
schedule: spaced(options.retryDelayMs ?? 50),
|
|
1766
|
-
while:
|
|
1767
|
-
}), mapError2((error) =>
|
|
966
|
+
while: retry2
|
|
967
|
+
}), mapError2((error) => retry2(error) ? new RelayStartFailed({
|
|
1768
968
|
message: `browse relay did not start at ${options.relay.endpoint}`,
|
|
1769
969
|
endpoint: options.relay.endpoint,
|
|
1770
970
|
cause: error
|
|
@@ -1772,6 +972,7 @@ function waitForRelayReady(options) {
|
|
|
1772
972
|
}
|
|
1773
973
|
var restartRelay = fn("RelayLifecycle.restartRelay")(function* (options) {
|
|
1774
974
|
const buildId = options.buildId ?? opencodeBrowserBuildId2;
|
|
975
|
+
const absent = (error) => isRelayUnreachable(error) || isForeignListener(error, options.pinned);
|
|
1775
976
|
const initial = yield* result(options.relay.version);
|
|
1776
977
|
let original;
|
|
1777
978
|
let replacement;
|
|
@@ -1780,7 +981,7 @@ var restartRelay = fn("RelayLifecycle.restartRelay")(function* (options) {
|
|
|
1780
981
|
original = initial.success;
|
|
1781
982
|
} else if (isRelayStarting(initial.failure)) {
|
|
1782
983
|
original = yield* waitForRelayReady(options);
|
|
1783
|
-
} else if (!
|
|
984
|
+
} else if (!absent(initial.failure)) {
|
|
1784
985
|
return yield* initial.failure;
|
|
1785
986
|
}
|
|
1786
987
|
if (original) {
|
|
@@ -1798,7 +999,7 @@ var restartRelay = fn("RelayLifecycle.restartRelay")(function* (options) {
|
|
|
1798
999
|
}
|
|
1799
1000
|
const confirmed = yield* result(options.relay.version);
|
|
1800
1001
|
if (isFailure(confirmed)) {
|
|
1801
|
-
if (!
|
|
1002
|
+
if (!absent(confirmed.failure))
|
|
1802
1003
|
return yield* confirmed.failure;
|
|
1803
1004
|
} else if (!isSameRelayInstance(original, confirmed.success)) {
|
|
1804
1005
|
replacement = confirmed.success;
|
|
@@ -1808,7 +1009,7 @@ var restartRelay = fn("RelayLifecycle.restartRelay")(function* (options) {
|
|
|
1808
1009
|
}
|
|
1809
1010
|
const request = yield* RelayShutdownRequest.makeEffect({
|
|
1810
1011
|
instanceId: original.instanceId,
|
|
1811
|
-
requestId:
|
|
1012
|
+
requestId: crypto.randomUUID(),
|
|
1812
1013
|
reason: "explicit-restart",
|
|
1813
1014
|
client: { kind: options.clientKind ?? "sdk", instanceId: clientInstanceId, buildId },
|
|
1814
1015
|
...options.force ? { force: true } : {}
|
|
@@ -1838,7 +1039,11 @@ var restartRelay = fn("RelayLifecycle.restartRelay")(function* (options) {
|
|
|
1838
1039
|
return { version: replacement, started, waitForReconnect: true };
|
|
1839
1040
|
});
|
|
1840
1041
|
function waitForRelayExitOrReplacement(options) {
|
|
1841
|
-
|
|
1042
|
+
const stillRecorded = () => {
|
|
1043
|
+
const state = readRelayState();
|
|
1044
|
+
return state !== undefined && state.configuredPort === configuredRelayPort() && state.instanceId === options.version.instanceId && processAlive(state.pid);
|
|
1045
|
+
};
|
|
1046
|
+
return options.relay.version.pipe(flatMap3((version) => isSameRelayInstance(options.version, version) ? fail6(new RelayStillRunning("browse relay is still draining; no replacement was started")) : succeed6(version)), catch_((error) => isRelayUnreachable(error) ? succeed6(undefined) : isForeignListener(error, options.pinned) ? stillRecorded() ? fail6(new RelayStillRunning("browse relay is still draining; no replacement was started")) : succeed6(undefined) : fail6(error)), retry({
|
|
1842
1047
|
times: options.retryTimes ?? 200,
|
|
1843
1048
|
schedule: spaced(options.retryDelayMs ?? 50),
|
|
1844
1049
|
while: (error) => error instanceof RelayStillRunning || isRelayStarting(error)
|
|
@@ -2010,5 +1215,10 @@ function isRelayStarting(error) {
|
|
|
2010
1215
|
function isRelayStartingOrUnreachable(error) {
|
|
2011
1216
|
return isRelayStarting(error) || isRelayUnreachable(error);
|
|
2012
1217
|
}
|
|
1218
|
+
function isForeignListener(error, pinned) {
|
|
1219
|
+
if (pinned ?? relayPortPinned())
|
|
1220
|
+
return false;
|
|
1221
|
+
return error instanceof RelayDecodeFailed;
|
|
1222
|
+
}
|
|
2013
1223
|
|
|
2014
|
-
export { map, withDefault, option, String2, Int, Boolean2,
|
|
1224
|
+
export { map, withDefault, option, String2, Int, Boolean2, portConfig, extensionOriginsConfig, RelayUnreachable, RelayRejected, Service, layerFetch, layerFetchMcp, appendManagedRelayProcessLog, relayLog, shouldWaitForExtensionReconnect, relayBuildProblem, ensureRelay, restartRelay, extensionReconnectWaitMs, ensureExtensionConnected, stoppedRelayStatus, statusCollections, startManagedRelay };
|