@brett_lamy/ui 5.10.1 → 5.13.0
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/components/avatar.d.ts +4 -1
- package/dist/components/avatar.d.ts.map +1 -1
- package/dist/components/avatar.js +55 -47
- package/dist/components/canvas.d.ts +18 -0
- package/dist/components/canvas.d.ts.map +1 -1
- package/dist/components/canvas.js +79 -11
- package/dist/components/command-menu.js +1 -1
- package/dist/components/floating-chat.d.ts +1 -1
- package/dist/components/floating-sheet.d.ts +1 -1
- package/dist/components/hover-card.d.ts +69 -0
- package/dist/components/hover-card.d.ts.map +1 -0
- package/dist/components/hover-card.js +164 -0
- package/dist/components/list.d.ts +3 -0
- package/dist/components/list.d.ts.map +1 -1
- package/dist/components/list.js +265 -250
- package/dist/components/markdown-view.d.ts +3 -1
- package/dist/components/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view.js +12 -11
- package/dist/components/open-code.d.ts +31 -0
- package/dist/components/open-code.d.ts.map +1 -0
- package/dist/components/open-code.js +253 -0
- package/dist/components/replay-preview.d.ts +2 -2
- package/dist/components/replay-preview.d.ts.map +1 -1
- package/dist/components/replay-preview.js +3 -3
- package/dist/components/sql-console.js +1 -1
- package/dist/components/tree.d.ts +4 -1
- package/dist/components/tree.d.ts.map +1 -1
- package/dist/components/tree.js +229 -202
- package/dist/components/tui-preview.d.ts +3 -0
- package/dist/components/tui-preview.d.ts.map +1 -0
- package/dist/components/tui-preview.js +3 -0
- package/dist/components/workspace.d.ts +11 -0
- package/dist/components/workspace.d.ts.map +1 -0
- package/dist/components/workspace.js +74 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +163 -156
- package/dist/lib/canvas-math.d.ts +1 -1
- package/dist/lib/canvas-math.d.ts.map +1 -1
- package/dist/lib/canvas-math.js +1 -1
- package/dist/lib/open-code-browser-agent.d.ts +7 -0
- package/dist/lib/open-code-browser-agent.d.ts.map +1 -0
- package/dist/lib/open-code-browser-agent.js +161 -0
- package/dist/lib/open-code-browser.d.ts +17 -0
- package/dist/lib/open-code-browser.d.ts.map +1 -0
- package/dist/lib/open-code-browser.js +252 -0
- package/dist/lib/open-code-host.d.ts +182 -0
- package/dist/lib/open-code-host.d.ts.map +1 -0
- package/dist/lib/open-code-host.js +118 -0
- package/dist/lib/open-code-keychain.d.ts +11 -0
- package/dist/lib/open-code-keychain.d.ts.map +1 -0
- package/dist/lib/open-code-keychain.js +19 -0
- package/dist/lib/open-code-preview.d.ts +16 -0
- package/dist/lib/open-code-preview.d.ts.map +1 -0
- package/dist/lib/open-code-preview.js +112 -0
- package/dist/lib/tailscale-policy.d.ts +9 -0
- package/dist/lib/tailscale-policy.d.ts.map +1 -1
- package/dist/lib/tailscale-policy.js +25 -19
- package/dist/lib/tailscale-router/bridge.d.ts +7 -2
- package/dist/lib/tailscale-router/bridge.d.ts.map +1 -1
- package/dist/lib/tailscale-router/bridge.js +64 -57
- package/dist/lib/theme.d.ts.map +1 -1
- package/dist/lib/theme.js +8 -5
- package/dist/opencode.d.ts +7 -0
- package/dist/opencode.d.ts.map +1 -0
- package/dist/opencode.js +6 -0
- package/dist/tailscale-sw.js +236 -12
- package/package.json +21 -3
|
@@ -13,48 +13,50 @@ var a = /* @__PURE__ */ new Set([
|
|
|
13
13
|
204,
|
|
14
14
|
205,
|
|
15
15
|
304
|
|
16
|
-
]);
|
|
17
|
-
function
|
|
18
|
-
let
|
|
16
|
+
]), o = /* @__PURE__ */ new WeakMap(), s = 1e3;
|
|
17
|
+
function c(e) {
|
|
18
|
+
let c = n(e.policy), l = /* @__PURE__ */ new Set(), u = {
|
|
19
19
|
status: "registering",
|
|
20
20
|
detail: null,
|
|
21
21
|
routed: 0,
|
|
22
|
-
policy:
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
...
|
|
22
|
+
policy: c
|
|
23
|
+
}, d = (e) => {
|
|
24
|
+
u = {
|
|
25
|
+
...u,
|
|
26
26
|
...e
|
|
27
|
-
},
|
|
28
|
-
},
|
|
27
|
+
}, l.forEach((e) => e());
|
|
28
|
+
}, f = i(e.env), p = e.env?.serviceWorker === void 0 ? typeof navigator < "u" ? navigator.serviceWorker : null : e.env.serviceWorker, m = !1, h = null, g = null, _ = /* @__PURE__ */ new Map(), v = () => e.tailscale.getSnapshot().status === "connected", y = typeof location < "u" ? location.origin : void 0;
|
|
29
|
+
p && o.set(p, (o.get(p) ?? 0) + 1);
|
|
30
|
+
let b = e.tailscale.subscribe(() => h?.postMessage({
|
|
29
31
|
type: "status",
|
|
30
|
-
connected:
|
|
32
|
+
connected: v()
|
|
31
33
|
}));
|
|
32
|
-
async function
|
|
34
|
+
async function x(n, r) {
|
|
33
35
|
let i = new AbortController();
|
|
34
|
-
|
|
36
|
+
_.set(r.id, i);
|
|
35
37
|
try {
|
|
36
|
-
let
|
|
38
|
+
let o = {
|
|
37
39
|
url: r.url,
|
|
38
40
|
method: r.method,
|
|
39
41
|
headers: r.headers,
|
|
40
42
|
destination: r.destination,
|
|
41
43
|
mode: r.mode
|
|
42
44
|
};
|
|
43
|
-
if (!t(r.url, r.method,
|
|
45
|
+
if (!r.proxied && (!t(r.url, r.method, c, y).route || e.shouldRoute && !await e.shouldRoute(o))) {
|
|
44
46
|
n.postMessage({
|
|
45
47
|
type: "passthrough",
|
|
46
48
|
id: r.id
|
|
47
49
|
});
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
50
|
-
if (!
|
|
52
|
+
if (!v()) {
|
|
51
53
|
n.postMessage({
|
|
52
54
|
type: "unavailable",
|
|
53
55
|
id: r.id
|
|
54
56
|
});
|
|
55
57
|
return;
|
|
56
58
|
}
|
|
57
|
-
let
|
|
59
|
+
let s = await e.respond?.(o) ?? await e.tailscale.fetch({
|
|
58
60
|
url: r.url,
|
|
59
61
|
method: r.method,
|
|
60
62
|
headers: r.headers,
|
|
@@ -62,29 +64,31 @@ function o(e) {
|
|
|
62
64
|
redirect: r.redirect,
|
|
63
65
|
signal: i.signal
|
|
64
66
|
});
|
|
65
|
-
if (r.redirect === "error" &&
|
|
67
|
+
if (r.redirect === "error" && s.status >= 300 && s.status < 400) throw TypeError("Redirect refused (redirect: \"error\").");
|
|
68
|
+
let l = r.proxied && (r.destination === "iframe" || r.destination === "document") && globalThis.crossOriginIsolated ? [...s.headers, ["document-isolation-policy", "isolate-and-credentialless"]] : s.headers;
|
|
66
69
|
if (n.postMessage({
|
|
67
70
|
type: "head",
|
|
68
71
|
id: r.id,
|
|
69
|
-
status:
|
|
70
|
-
statusText:
|
|
71
|
-
headers:
|
|
72
|
-
|
|
72
|
+
status: s.status,
|
|
73
|
+
statusText: s.statusText ?? "",
|
|
74
|
+
headers: l,
|
|
75
|
+
url: s.url ?? r.url
|
|
76
|
+
}), d({ routed: u.routed + 1 }), a.has(s.status) || r.method === "HEAD" || !s.body) {
|
|
73
77
|
n.postMessage({
|
|
74
78
|
type: "end",
|
|
75
79
|
id: r.id
|
|
76
80
|
});
|
|
77
81
|
return;
|
|
78
82
|
}
|
|
79
|
-
if (
|
|
80
|
-
let e =
|
|
83
|
+
if (s.body instanceof Uint8Array) {
|
|
84
|
+
let e = s.body.slice().buffer;
|
|
81
85
|
n.postMessage({
|
|
82
86
|
type: "chunk",
|
|
83
87
|
id: r.id,
|
|
84
88
|
data: e
|
|
85
89
|
}, [e]);
|
|
86
90
|
} else {
|
|
87
|
-
let e =
|
|
91
|
+
let e = s.body.getReader();
|
|
88
92
|
for (;;) {
|
|
89
93
|
if (i.signal.aborted) {
|
|
90
94
|
await e.cancel();
|
|
@@ -111,55 +115,55 @@ function o(e) {
|
|
|
111
115
|
message: e instanceof Error ? e.message : String(e)
|
|
112
116
|
});
|
|
113
117
|
} finally {
|
|
114
|
-
|
|
118
|
+
_.delete(r.id);
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
|
-
function
|
|
118
|
-
if (
|
|
119
|
-
|
|
121
|
+
function S(e) {
|
|
122
|
+
if (m || !e) return;
|
|
123
|
+
h?.close();
|
|
120
124
|
let t = new MessageChannel();
|
|
121
|
-
|
|
125
|
+
h = t.port1;
|
|
122
126
|
let n = t.port1;
|
|
123
127
|
n.onmessage = (e) => {
|
|
124
128
|
let t = e.data;
|
|
125
|
-
t.type === "request" ?
|
|
129
|
+
t.type === "request" ? x(n, t) : t.type === "cancel" && typeof t.id == "number" && _.get(t.id)?.abort();
|
|
126
130
|
}, e.postMessage({
|
|
127
131
|
type: "bl-ts/attach",
|
|
128
132
|
v: 1,
|
|
129
|
-
connected:
|
|
133
|
+
connected: v()
|
|
130
134
|
}, [t.port2]);
|
|
131
135
|
}
|
|
132
|
-
let
|
|
133
|
-
e.data?.type === "bl-ts/needs-attach" &&
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
+
let C = (e) => {
|
|
137
|
+
e.data?.type === "bl-ts/needs-attach" && S(p?.controller ?? g?.active ?? null);
|
|
138
|
+
}, w = () => {
|
|
139
|
+
p?.controller && (S(p.controller), u.status === "uncontrolled" && d({
|
|
136
140
|
status: "active",
|
|
137
141
|
detail: null
|
|
138
142
|
}));
|
|
139
|
-
},
|
|
140
|
-
if (
|
|
143
|
+
}, T = (async () => {
|
|
144
|
+
if (f || !p) return d({
|
|
141
145
|
status: "unsupported",
|
|
142
|
-
detail:
|
|
143
|
-
}),
|
|
146
|
+
detail: f
|
|
147
|
+
}), u;
|
|
144
148
|
try {
|
|
145
|
-
let t = r(
|
|
146
|
-
|
|
149
|
+
let t = r(c, e.serviceWorkerUrl);
|
|
150
|
+
p.addEventListener("message", C), p.addEventListener("controllerchange", w), g = await p.register(t, {
|
|
147
151
|
scope: e.scope,
|
|
148
152
|
updateViaCache: "none"
|
|
149
153
|
});
|
|
150
|
-
let n =
|
|
154
|
+
let n = g.active ?? g.waiting ?? g.installing;
|
|
151
155
|
if (n && n.state !== "activated" && await new Promise((e) => {
|
|
152
156
|
let t = () => {
|
|
153
157
|
(n.state === "activated" || n.state === "redundant") && (n.removeEventListener("statechange", t), e());
|
|
154
158
|
};
|
|
155
159
|
n.addEventListener("statechange", t), t();
|
|
156
|
-
}),
|
|
160
|
+
}), m || (p.controller || await new Promise((e) => {
|
|
157
161
|
let t = setTimeout(e, 3e3);
|
|
158
|
-
|
|
162
|
+
p.addEventListener("controllerchange", () => {
|
|
159
163
|
clearTimeout(t), e();
|
|
160
164
|
}, { once: !0 });
|
|
161
|
-
}),
|
|
162
|
-
|
|
165
|
+
}), m)) return u;
|
|
166
|
+
S(p.controller ?? g.active), d(p.controller ? {
|
|
163
167
|
status: "active",
|
|
164
168
|
detail: null
|
|
165
169
|
} : {
|
|
@@ -167,32 +171,35 @@ function o(e) {
|
|
|
167
171
|
detail: "This page is not controlled by the worker (a hard reload bypasses it). Reload normally."
|
|
168
172
|
});
|
|
169
173
|
} catch (e) {
|
|
170
|
-
|
|
174
|
+
d({
|
|
171
175
|
status: "error",
|
|
172
176
|
detail: e instanceof Error ? e.message : String(e)
|
|
173
177
|
});
|
|
174
178
|
}
|
|
175
|
-
return
|
|
179
|
+
return u;
|
|
176
180
|
})();
|
|
177
181
|
return {
|
|
178
|
-
getState: () =>
|
|
182
|
+
getState: () => u,
|
|
179
183
|
subscribe(e) {
|
|
180
|
-
return
|
|
184
|
+
return l.add(e), () => l.delete(e);
|
|
181
185
|
},
|
|
182
|
-
ready:
|
|
186
|
+
ready: T,
|
|
183
187
|
async dispose() {
|
|
184
|
-
if (!
|
|
185
|
-
|
|
188
|
+
if (!m) {
|
|
189
|
+
m = !0, b(), _.forEach((e) => e.abort()), p?.removeEventListener("message", C), p?.removeEventListener("controllerchange", w);
|
|
186
190
|
try {
|
|
187
|
-
(
|
|
191
|
+
(p?.controller ?? g?.active)?.postMessage({ type: "bl-ts/detach" });
|
|
188
192
|
} catch {}
|
|
189
|
-
|
|
193
|
+
if (h?.close(), h = null, p && o.set(p, (o.get(p) ?? 1) - 1), e.unregisterOnDispose) {
|
|
194
|
+
if (await T, await new Promise((e) => setTimeout(e, s)), p && (o.get(p) ?? 0) > 0) return;
|
|
195
|
+
await g?.unregister();
|
|
196
|
+
}
|
|
190
197
|
}
|
|
191
198
|
},
|
|
192
199
|
async unregister() {
|
|
193
|
-
return await
|
|
200
|
+
return await T, g ? g.unregister() : !1;
|
|
194
201
|
}
|
|
195
202
|
};
|
|
196
203
|
}
|
|
197
204
|
//#endregion
|
|
198
|
-
export {
|
|
205
|
+
export { c as registerTailscaleRouter, i as tailscaleRouterUnsupportedReason, r as tailscaleServiceWorkerUrl };
|
package/dist/lib/theme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/lib/theme.tsx"],"names":[],"mappings":"AACA,OAAO,EAA8F,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG5K,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,CAAC;AAKrC,eAAO,MAAM,WAAW;;kBAEJ,OAAO,KAAK,IAAI;WAC3B,OAAO;CACf,CAAC;AAEF,wBAAgB,eAAe,YAQ9B;AAID,eAAO,MAAM,SAAS,iCAAmB,CAAC;AAK1C,eAAO,MAAM,WAAW,iCAAmB,CAAC;AAC5C,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,QAAQ,OAAO,WAA6C,CAAC;AAMvG,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAC1C,eAAO,MAAM,iBAAiB,iDAAmD,CAAC;AAClF,wBAAgB,kBAAkB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAAE,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,2CAE9G;AAUD,wBAAgB,aAAa,IAAI,UAAU,GAAG,SAAS,CAIt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,OAAO,GAAG,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,eAAe,2CAmCxG"}
|
package/dist/lib/theme.js
CHANGED
|
@@ -121,11 +121,14 @@ function A({ dark: e, tint: n, safeTop: i, children: a, className: o, style: c }
|
|
|
121
121
|
"--bl-safe-top": h + "px",
|
|
122
122
|
...c
|
|
123
123
|
},
|
|
124
|
-
children: [/* @__PURE__ */ l(
|
|
125
|
-
|
|
126
|
-
children: /* @__PURE__ */ l(
|
|
127
|
-
|
|
128
|
-
children:
|
|
124
|
+
children: [/* @__PURE__ */ l(E.Provider, {
|
|
125
|
+
value: null,
|
|
126
|
+
children: /* @__PURE__ */ l(d, {
|
|
127
|
+
getContainer: v,
|
|
128
|
+
children: /* @__PURE__ */ l(m.Provider, {
|
|
129
|
+
value: h,
|
|
130
|
+
children: a
|
|
131
|
+
})
|
|
129
132
|
})
|
|
130
133
|
}), h ? /* @__PURE__ */ l("div", {
|
|
131
134
|
className: "pointer-events-none absolute left-1/2 z-400 h-[35px] w-[118px] -translate-x-1/2 rounded-[18px] bg-black",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { OpenCode } from './components/open-code';
|
|
2
|
+
export type { OpenCodeProps, OpenCodeState } from './components/open-code';
|
|
3
|
+
export { DEFAULT_OPENCODE_PREVIEW_URL } from './lib/open-code-preview';
|
|
4
|
+
export { createAlmostNodeOpenCodeHost, createAgentWasmOpenCodeHost, loadOpenCodeRuntime, DEFAULT_OPENCODE_RUNTIME_URL, } from './lib/open-code-host';
|
|
5
|
+
export type { OpenCodeHostBridge, OpenCodeCredentialStore, OpenCodeConnectionStore, OpenCodeKeychainStore, OpenCodePort, OpenCodeWorkspaceBridge, OpenCodeProcessBridge, OpenCodeCommand, OpenCodeMcpServer, OpenCodeRuntime, OpenCodeRuntimeSession, AlmostNodeOpenCodeContainer, AlmostNodeOpenCodeOptions, } from './lib/open-code-host';
|
|
6
|
+
export { createVaultOpenCodeCredentialStore, createVaultOpenCodeConnectionStore, OPENCODE_CREDENTIAL_SLOT, OPENCODE_CONNECTION_SLOT, } from './lib/open-code-keychain';
|
|
7
|
+
//# sourceMappingURL=opencode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode.d.ts","sourceRoot":"","sources":["../src/opencode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,YAAY,EACZ,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC"}
|
package/dist/opencode.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DEFAULT_OPENCODE_PREVIEW_URL as e } from "./lib/open-code-preview.js";
|
|
3
|
+
import { DEFAULT_OPENCODE_RUNTIME_URL as t, createAgentWasmOpenCodeHost as n, createAlmostNodeOpenCodeHost as r, loadOpenCodeRuntime as i } from "./lib/open-code-host.js";
|
|
4
|
+
import { OpenCode as a } from "./components/open-code.js";
|
|
5
|
+
import { OPENCODE_CONNECTION_SLOT as o, OPENCODE_CREDENTIAL_SLOT as s, createVaultOpenCodeConnectionStore as c, createVaultOpenCodeCredentialStore as l } from "./lib/open-code-keychain.js";
|
|
6
|
+
export { e as DEFAULT_OPENCODE_PREVIEW_URL, t as DEFAULT_OPENCODE_RUNTIME_URL, o as OPENCODE_CONNECTION_SLOT, s as OPENCODE_CREDENTIAL_SLOT, a as OpenCode, n as createAgentWasmOpenCodeHost, r as createAlmostNodeOpenCodeHost, c as createVaultOpenCodeConnectionStore, l as createVaultOpenCodeCredentialStore, i as loadOpenCodeRuntime };
|
package/dist/tailscale-sw.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
const DEFAULT_POLICY = {
|
|
23
23
|
v: 1, intercept: 'tailnet', hosts: [], cidrs: [], shortNames: false, exclude: [], schemes: ['http', 'https'], methods: null,
|
|
24
|
-
sameOrigin: false, whenUnavailable: 'network', maxBodyBytes: 32 * 1024 * 1024, timeoutMs: 60000,
|
|
24
|
+
sameOrigin: false, whenUnavailable: 'network', maxBodyBytes: 32 * 1024 * 1024, timeoutMs: 60000, proxyPath: null,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
function parseIPv4(text) {
|
|
@@ -142,6 +142,7 @@
|
|
|
142
142
|
for (const k in DEFAULT_POLICY) out[k] = parsed[k] !== undefined ? parsed[k] : DEFAULT_POLICY[k];
|
|
143
143
|
if (out.intercept !== 'all') out.intercept = 'tailnet';
|
|
144
144
|
if (out.whenUnavailable !== 'error') out.whenUnavailable = 'network';
|
|
145
|
+
if (typeof out.proxyPath !== 'string' || !/^[A-Za-z0-9_-]+\/$/.test(out.proxyPath)) out.proxyPath = null;
|
|
145
146
|
return out;
|
|
146
147
|
} catch {
|
|
147
148
|
return DEFAULT_POLICY;
|
|
@@ -226,6 +227,164 @@
|
|
|
226
227
|
}
|
|
227
228
|
});
|
|
228
229
|
|
|
230
|
+
/* ── proxied sites (policy.proxyPath) ── */
|
|
231
|
+
|
|
232
|
+
const PROXY_PREFIX = policy.proxyPath && sw.registration ? new URL(policy.proxyPath, sw.registration.scope).href : null;
|
|
233
|
+
// Response headers that would stop a proxied page from being framed here or from running its scripts on this origin.
|
|
234
|
+
const STRIPPED = {
|
|
235
|
+
'content-security-policy': 1, 'content-security-policy-report-only': 1, 'x-frame-options': 1, 'set-cookie': 1,
|
|
236
|
+
'cross-origin-opener-policy': 1, 'cross-origin-embedder-policy': 1, 'cross-origin-resource-policy': 1, 'strict-transport-security': 1,
|
|
237
|
+
};
|
|
238
|
+
const tailscaleHost = function (host) { return /(^|\.)tailscale\.(com|io)$/.test(host); };
|
|
239
|
+
|
|
240
|
+
/** The site a proxy address loads (`<scope><proxyPath>https/example.com/a` → `https://example.com/a`), or null. */
|
|
241
|
+
function proxyTarget(url) {
|
|
242
|
+
if (!PROXY_PREFIX || url.indexOf(PROXY_PREFIX) !== 0) return null;
|
|
243
|
+
const m = /^(https?)\/([^/?#]+)(.*)$/.exec(url.slice(PROXY_PREFIX.length));
|
|
244
|
+
if (!m) return null;
|
|
245
|
+
const rest = m[3] || '';
|
|
246
|
+
return m[1] + '://' + m[2] + (rest.charAt(0) === '/' ? rest : '/' + rest);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** A URL on this origin as the proxied site would have it (`/watch?v=1` → `https://www.youtube.com/watch?v=1`). */
|
|
250
|
+
function siteUrl(url, origin) {
|
|
251
|
+
try {
|
|
252
|
+
const u = new URL(url);
|
|
253
|
+
const site = proxyTarget(u.href);
|
|
254
|
+
if (site) return site;
|
|
255
|
+
return u.origin === sw.location.origin ? origin + u.pathname + u.search : u.href;
|
|
256
|
+
} catch { return null; }
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Which clients (frames) show which site. Kept in the Cache API too: the browser stops an idle worker, and the frame lives on.
|
|
260
|
+
const frames = new Map();
|
|
261
|
+
const notFrames = new Set();
|
|
262
|
+
const FRAME_CACHE = 'bl-ts-frames-v1';
|
|
263
|
+
let hasFrameCache = false;
|
|
264
|
+
const frameKey = function (id) { return new Request(sw.location.origin + '/__bl-ts-frame/' + encodeURIComponent(id)); };
|
|
265
|
+
if (PROXY_PREFIX && typeof caches !== 'undefined') caches.has(FRAME_CACHE).then(function (yes) { hasFrameCache = yes; }, function () { /* no Cache API here */ });
|
|
266
|
+
|
|
267
|
+
function rememberFrame(id, origin) {
|
|
268
|
+
if (!id) return;
|
|
269
|
+
frames.set(id, origin);
|
|
270
|
+
notFrames.delete(id);
|
|
271
|
+
if (typeof caches === 'undefined') return;
|
|
272
|
+
hasFrameCache = true;
|
|
273
|
+
caches.open(FRAME_CACHE).then(function (c) { return c.put(frameKey(id), new Response(origin)); }).catch(function () { /* kept in memory only */ });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function lookupFrame(id) {
|
|
277
|
+
if (!id) return Promise.resolve(null);
|
|
278
|
+
if (frames.has(id)) return Promise.resolve(frames.get(id));
|
|
279
|
+
if (typeof caches === 'undefined') return Promise.resolve(null);
|
|
280
|
+
return caches.open(FRAME_CACHE)
|
|
281
|
+
.then(function (c) { return c.match(frameKey(id)); })
|
|
282
|
+
.then(function (r) { return r ? r.text() : null; })
|
|
283
|
+
.then(function (origin) { if (origin) frames.set(id, origin); return origin; })
|
|
284
|
+
.catch(function () { return null; });
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
sw.addEventListener('activate', function (event) {
|
|
288
|
+
// Forget frames whose windows are gone.
|
|
289
|
+
if (typeof caches === 'undefined') return;
|
|
290
|
+
event.waitUntil(caches.open(FRAME_CACHE).then(function (c) {
|
|
291
|
+
return Promise.all([c.keys(), sw.clients.matchAll({ includeUncontrolled: true })]).then(function (got) {
|
|
292
|
+
const live = {};
|
|
293
|
+
got[1].forEach(function (cl) { live[cl.id] = 1; });
|
|
294
|
+
return Promise.all(got[0].map(function (req) {
|
|
295
|
+
const id = decodeURIComponent(req.url.split('/__bl-ts-frame/')[1] || '');
|
|
296
|
+
return live[id] ? null : c.delete(req);
|
|
297
|
+
}));
|
|
298
|
+
});
|
|
299
|
+
}).catch(function () { /* nothing to forget */ }));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
/** A value as a JavaScript literal that is safe inside an inline <script> (no "</script>" can end it early). */
|
|
303
|
+
const literal = function (v) { return JSON.stringify(v).replace(/</g, '\\u003c'); };
|
|
304
|
+
|
|
305
|
+
/** An error page for a proxied frame (a document) or a plain error response (anything else). */
|
|
306
|
+
function failed(proxy, status, message) {
|
|
307
|
+
if (!proxy.document) return new Response(message, { status: status, headers: { 'content-type': 'text/plain; charset=utf-8', 'x-bl-tailscale': 'error' } });
|
|
308
|
+
const esc = function (text) { return String(text).replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); };
|
|
309
|
+
const html = '<!doctype html><meta charset="utf-8"><title>Can\u2019t open the page</title><body style="font:15px system-ui;margin:3em;color:#555">'
|
|
310
|
+
+ '<h1 style="font-size:20px;color:#222">Can\u2019t open ' + esc(proxy.url) + '</h1><p>' + esc(message) + '</p>'
|
|
311
|
+
+ '<script>parent.postMessage({ type: "bl-tailnet-frame", url: ' + literal(proxy.url) + ', title: document.title, error: ' + literal(String(message)) + ' }, location.origin)</script>';
|
|
312
|
+
return new Response(html, { status: status, headers: { 'content-type': 'text/html; charset=utf-8', 'x-bl-tailscale': 'error' } });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Runs first in every proxied page: the page sees its own path (not the proxy address), its links and forms stay in the
|
|
316
|
+
* proxy, and the embedding page hears where it is and what it is called. Its origin stays this one: that is the limit. */
|
|
317
|
+
function frameScript(PREFIX, START) {
|
|
318
|
+
const here = location.origin;
|
|
319
|
+
const site = new URL(START).origin;
|
|
320
|
+
const real = function (u) {
|
|
321
|
+
const x = new URL(u, location.href);
|
|
322
|
+
if (x.origin !== here) return x.href;
|
|
323
|
+
if (x.href.indexOf(PREFIX) === 0) return null;
|
|
324
|
+
return site + x.pathname + x.search + x.hash;
|
|
325
|
+
};
|
|
326
|
+
const proxy = function (u) { const x = new URL(u); return PREFIX + x.protocol.slice(0, -1) + '/' + x.host + x.pathname + x.search + x.hash; };
|
|
327
|
+
const start = new URL(START);
|
|
328
|
+
try { history.replaceState(history.state, '', start.pathname + start.search + (location.hash || start.hash)); } catch (e) { /* keep the proxy address */ }
|
|
329
|
+
let last = '';
|
|
330
|
+
const report = function () {
|
|
331
|
+
const url = real(location.href) || START;
|
|
332
|
+
const key = url + '\n' + document.title;
|
|
333
|
+
if (key === last) return;
|
|
334
|
+
last = key;
|
|
335
|
+
try { parent.postMessage({ type: 'bl-tailnet-frame', url: url, title: document.title }, here); } catch (e) { /* no parent */ }
|
|
336
|
+
};
|
|
337
|
+
['pushState', 'replaceState'].forEach(function (k) {
|
|
338
|
+
const f = history[k];
|
|
339
|
+
history[k] = function (...args) { const r = f.apply(this, args); report(); return r; };
|
|
340
|
+
});
|
|
341
|
+
addEventListener('popstate', report);
|
|
342
|
+
addEventListener('hashchange', report);
|
|
343
|
+
addEventListener('DOMContentLoaded', report);
|
|
344
|
+
addEventListener('load', report);
|
|
345
|
+
setInterval(report, 1000);
|
|
346
|
+
const http = function (u) { return u && /^https?:/i.test(u); };
|
|
347
|
+
addEventListener('click', function (e) {
|
|
348
|
+
if (e.defaultPrevented || e.button !== 0) return;
|
|
349
|
+
const a = e.target && e.target.closest ? e.target.closest('a[href]') : null;
|
|
350
|
+
if (!a || a.hasAttribute('download')) return;
|
|
351
|
+
const href = a.getAttribute('href') || '';
|
|
352
|
+
if (href.charAt(0) === '#' || /^(javascript|mailto|tel):/i.test(href)) return;
|
|
353
|
+
const r = real(a.href);
|
|
354
|
+
if (!http(r)) return;
|
|
355
|
+
e.preventDefault();
|
|
356
|
+
if (a.target === '_blank' || e.metaKey || e.ctrlKey || e.shiftKey) parent.postMessage({ type: 'bl-tailnet-open', url: r }, here);
|
|
357
|
+
else if (a.target === '_top' || a.target === '_parent') parent.postMessage({ type: 'bl-tailnet-go', url: r }, here);
|
|
358
|
+
else location.href = proxy(r);
|
|
359
|
+
});
|
|
360
|
+
addEventListener('submit', function (e) {
|
|
361
|
+
const f = e.target;
|
|
362
|
+
if (!f || !f.getAttribute) return;
|
|
363
|
+
const r = real(f.getAttribute('action') ? f.action : location.href);
|
|
364
|
+
if (http(r)) f.setAttribute('action', proxy(r));
|
|
365
|
+
f.removeAttribute('target');
|
|
366
|
+
}, true);
|
|
367
|
+
window.open = function (u) {
|
|
368
|
+
if (u) { const r = real(String(u)); if (http(r)) parent.postMessage({ type: 'bl-tailnet-open', url: r }, here); }
|
|
369
|
+
return null;
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The document's bytes with the frame script as the first thing in it. */
|
|
374
|
+
function withFrameScript(chunks, url) {
|
|
375
|
+
let size = 0;
|
|
376
|
+
chunks.forEach(function (c) { size += c.byteLength; });
|
|
377
|
+
const all = new Uint8Array(size);
|
|
378
|
+
let at = 0;
|
|
379
|
+
chunks.forEach(function (c) { all.set(c, at); at += c.byteLength; });
|
|
380
|
+
const text = new TextDecoder().decode(all);
|
|
381
|
+
const tag = '<script>(' + frameScript.toString() + ')(' + literal(PROXY_PREFIX) + ',' + literal(url) + ')</script>';
|
|
382
|
+
const head = /<head[^>]*>/i.exec(text);
|
|
383
|
+
const doctype = /^\s*<!doctype[^>]*>/i.exec(text);
|
|
384
|
+
const at2 = head ? head.index + head[0].length : doctype ? doctype[0].length : 0;
|
|
385
|
+
return text.slice(0, at2) + tag + text.slice(at2);
|
|
386
|
+
}
|
|
387
|
+
|
|
229
388
|
/* ── requests ── */
|
|
230
389
|
|
|
231
390
|
const NULL_BODY = { 101: 1, 103: 1, 204: 1, 205: 1, 304: 1 };
|
|
@@ -251,17 +410,25 @@
|
|
|
251
410
|
headers.append('vary', 'Origin');
|
|
252
411
|
}
|
|
253
412
|
|
|
254
|
-
function route(event) {
|
|
413
|
+
function route(event, proxy) {
|
|
255
414
|
const request = event.request;
|
|
415
|
+
const target = proxy ? proxy.url : request.url;
|
|
256
416
|
const bodyPromise = request.method === 'GET' || request.method === 'HEAD' ? Promise.resolve(null) : request.clone().arrayBuffer();
|
|
257
417
|
return Promise.all([bodyPromise, waitForOwner(1500)]).then(function (got) {
|
|
258
418
|
const body = got[0];
|
|
259
419
|
const owner = got[1];
|
|
260
|
-
|
|
261
|
-
if (
|
|
420
|
+
// A proxied page has no public network to fall back to: its relative URLs only mean something on the site it shows.
|
|
421
|
+
if (body && body.byteLength > policy.maxBodyBytes) return proxy ? failed(proxy, 413, 'The request body is too large to send through the tailnet.') : unavailable(request, 'request body too large');
|
|
422
|
+
if (!owner) return proxy ? failed(proxy, 503, 'No tab is connected to Tailscale.') : unavailable(request, 'no connected page');
|
|
262
423
|
const id = nextId++;
|
|
263
424
|
const headers = [];
|
|
264
425
|
request.headers.forEach(function (v, k) { if (k !== 'cookie') headers.push([k, v]); });
|
|
426
|
+
if (proxy) {
|
|
427
|
+
// The site sees itself as the origin and referrer, not this page.
|
|
428
|
+
const ref = request.referrer && request.referrer !== 'about:client' ? siteUrl(request.referrer, proxy.frameOrigin) : null;
|
|
429
|
+
if (ref) headers.push(['referer', ref]);
|
|
430
|
+
if (request.mode === 'cors' || (request.method !== 'GET' && request.method !== 'HEAD')) headers.push(['origin', proxy.frameOrigin]);
|
|
431
|
+
}
|
|
265
432
|
return new Promise(function (resolve, reject) {
|
|
266
433
|
let controller = null;
|
|
267
434
|
let settled = false;
|
|
@@ -278,16 +445,30 @@
|
|
|
278
445
|
owner.port.postMessage({ type: 'cancel', id: id });
|
|
279
446
|
};
|
|
280
447
|
if (request.signal) request.signal.addEventListener('abort', cancel);
|
|
448
|
+
let page = null; // a proxied HTML document, gathered whole so the frame script can go in first
|
|
281
449
|
pending.set(id, {
|
|
282
450
|
handle: function (m) {
|
|
283
451
|
if (m.type === 'head') {
|
|
284
452
|
settled = true;
|
|
285
453
|
clearTimeout(timer);
|
|
286
454
|
const h = new Headers();
|
|
287
|
-
(m.headers || []).forEach(function (pair) {
|
|
455
|
+
(m.headers || []).forEach(function (pair) {
|
|
456
|
+
if (proxy && STRIPPED[pair[0].toLowerCase()]) return;
|
|
457
|
+
try { h.append(pair[0], pair[1]); } catch { /* forbidden */ }
|
|
458
|
+
});
|
|
288
459
|
h.set('x-bl-tailscale', 'routed');
|
|
289
460
|
withCors(h, request);
|
|
290
461
|
const status = m.status >= 200 && m.status <= 599 ? m.status : 502;
|
|
462
|
+
if (proxy && proxy.document) {
|
|
463
|
+
const finalUrl = typeof m.url === 'string' && /^https?:/.test(m.url) ? m.url : proxy.url;
|
|
464
|
+
rememberFrame(event.resultingClientId, new URL(finalUrl).origin);
|
|
465
|
+
if (/html/i.test(h.get('content-type') || '') || !h.get('content-type')) {
|
|
466
|
+
h.set('content-type', 'text/html; charset=utf-8');
|
|
467
|
+
h.delete('content-length');
|
|
468
|
+
page = { chunks: [], status: status, statusText: m.statusText || '', headers: h, url: finalUrl, resolve: resolve };
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
291
472
|
const stream = NULL_BODY[status] || request.method === 'HEAD' ? null : new ReadableStream({
|
|
292
473
|
start: function (c) { controller = c; },
|
|
293
474
|
cancel: cancel,
|
|
@@ -295,25 +476,30 @@
|
|
|
295
476
|
if (!stream) pending.delete(id);
|
|
296
477
|
resolve(new Response(stream, { status: status, statusText: m.statusText || '', headers: h }));
|
|
297
478
|
} else if (m.type === 'chunk') {
|
|
298
|
-
if (
|
|
479
|
+
if (page && m.data) page.chunks.push(new Uint8Array(m.data));
|
|
480
|
+
else if (controller && m.data) controller.enqueue(new Uint8Array(m.data));
|
|
299
481
|
} else if (m.type === 'end') {
|
|
300
482
|
pending.delete(id);
|
|
301
|
-
if (
|
|
483
|
+
if (page) page.resolve(new Response(withFrameScript(page.chunks, page.url), { status: page.status, statusText: page.statusText, headers: page.headers }));
|
|
484
|
+
else if (controller) controller.close();
|
|
302
485
|
} else if (m.type === 'error') {
|
|
303
486
|
pending.delete(id);
|
|
304
487
|
clearTimeout(timer);
|
|
305
|
-
if (
|
|
306
|
-
else if (
|
|
488
|
+
if (page) page.resolve(failed(proxy, 502, m.message || 'Tailscale request failed'));
|
|
489
|
+
else if (controller) controller.error(new TypeError(m.message || 'Tailscale request failed'));
|
|
490
|
+
else if (!settled) { settled = true; resolve(proxy && proxy.document ? failed(proxy, 502, m.message || 'Tailscale request failed') : Promise.reject(new TypeError(m.message || 'Tailscale request failed'))); }
|
|
307
491
|
} else if (m.type === 'passthrough' || m.type === 'unavailable') {
|
|
308
492
|
pending.delete(id);
|
|
309
493
|
clearTimeout(timer);
|
|
310
|
-
if (!settled) { settled = true; resolve(m.type === 'passthrough' ? fetch(request) : unavailable(request, 'disconnected')); }
|
|
494
|
+
if (!settled) { settled = true; resolve(proxy ? failed(proxy, 503, 'Tailscale is not connected.') : m.type === 'passthrough' ? fetch(request) : unavailable(request, 'disconnected')); }
|
|
311
495
|
}
|
|
312
496
|
},
|
|
313
497
|
});
|
|
314
498
|
const message = {
|
|
315
|
-
type: 'request', id: id, url:
|
|
316
|
-
|
|
499
|
+
type: 'request', id: id, url: target, method: request.method, headers: headers, body: body,
|
|
500
|
+
// A document is fetched as GET by the frame; redirects are followed in the page so the frame learns where it ended up.
|
|
501
|
+
redirect: proxy && proxy.document ? 'follow' : request.redirect, credentials: request.credentials, mode: request.mode, destination: request.destination,
|
|
502
|
+
proxied: !!proxy,
|
|
317
503
|
};
|
|
318
504
|
owner.port.postMessage(message, body ? [body] : []);
|
|
319
505
|
});
|
|
@@ -322,6 +508,44 @@
|
|
|
322
508
|
|
|
323
509
|
sw.addEventListener('fetch', function (event) {
|
|
324
510
|
const request = event.request;
|
|
511
|
+
if (PROXY_PREFIX) {
|
|
512
|
+
const site = proxyTarget(request.url);
|
|
513
|
+
if (site) {
|
|
514
|
+
// A frame opening a site through the tailnet (or a resource asked for by its proxy address).
|
|
515
|
+
const isDocument = request.mode === 'navigate' || request.destination === 'iframe' || request.destination === 'document';
|
|
516
|
+
event.respondWith(lookupFrame(event.clientId).then(function (origin) {
|
|
517
|
+
return route(event, { url: site, frameOrigin: isDocument ? new URL(site).origin : origin || new URL(site).origin, document: isDocument });
|
|
518
|
+
}));
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (request.mode !== 'navigate' && event.clientId && !notFrames.has(event.clientId)) {
|
|
522
|
+
// Is this request from a proxied page? Everything it asks for goes through the tailnet; its own-origin URLs mean its site.
|
|
523
|
+
const known = frames.get(event.clientId);
|
|
524
|
+
const forFrame = function (origin) {
|
|
525
|
+
if (!origin) {
|
|
526
|
+
notFrames.add(event.clientId);
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
const u = new URL(request.url);
|
|
530
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return null;
|
|
531
|
+
const url = u.origin === sw.location.origin ? origin + u.pathname + u.search : u.href;
|
|
532
|
+
if (tailscaleHost(new URL(url).hostname)) return null;
|
|
533
|
+
return { url: url, frameOrigin: origin, document: false };
|
|
534
|
+
};
|
|
535
|
+
if (known) {
|
|
536
|
+
const proxy = forFrame(known);
|
|
537
|
+
if (proxy) { event.respondWith(route(event, proxy)); return; }
|
|
538
|
+
} else if (frames.size || hasFrameCache) {
|
|
539
|
+
// Not seen since this worker started: ask the cache (it outlives the worker), else let the request through untouched.
|
|
540
|
+
event.respondWith(lookupFrame(event.clientId).then(function (origin) {
|
|
541
|
+
const proxy = forFrame(origin);
|
|
542
|
+
if (proxy) return route(event, proxy);
|
|
543
|
+
return match(request.url, request.method, policy, sw.location.origin).route ? route(event) : fetch(request);
|
|
544
|
+
}));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
325
549
|
if (request.mode === 'navigate') return; // a navigation is the page itself, never the tailnet's
|
|
326
550
|
const m = match(request.url, request.method, policy, sw.location.origin);
|
|
327
551
|
if (!m.route) return; // not ours: the browser handles it as if there were no worker
|