@brett_lamy/ui 5.10.0 → 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-connect.d.ts.map +1 -1
- package/dist/lib/tailscale-connect.js +97 -62
- package/dist/lib/tailscale-policy.d.ts +11 -2
- package/dist/lib/tailscale-policy.d.ts.map +1 -1
- package/dist/lib/tailscale-policy.js +27 -18
- 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 +237 -12
- package/package.json +21 -3
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region src/lib/open-code-host.ts
|
|
2
|
+
function e(e, t = {}) {
|
|
3
|
+
let n = e.vfs, r = (t.directory ?? `/workspaces/${e.id}`).replace(/\/+$/, "");
|
|
4
|
+
if (!r.startsWith("/") || r.split("/").some((e) => e === ".." || e === ".")) throw Error("OpenCode needs an absolute workspace directory below /.");
|
|
5
|
+
n.mkdirSync(r, { recursive: !0 });
|
|
6
|
+
let i = (e) => {
|
|
7
|
+
let t = [];
|
|
8
|
+
for (let n of e.split("/")) n === ".." ? t.pop() : n && n !== "." && t.push(n);
|
|
9
|
+
let n = "/" + t.join("/");
|
|
10
|
+
if (n !== r && !n.startsWith(r + "/")) throw Error("OpenCode path is outside its workspace: " + e);
|
|
11
|
+
return n;
|
|
12
|
+
}, a = (e = r) => n.readdirSync(i(e)).flatMap((t) => {
|
|
13
|
+
let r = `${e}/${t}`;
|
|
14
|
+
return n.statSync(r).isDirectory() ? a(r) : [r];
|
|
15
|
+
}), o = (e, t = !1) => {
|
|
16
|
+
let r = i(e);
|
|
17
|
+
if (n.statSync(r).isDirectory()) {
|
|
18
|
+
if (t) for (let e of n.readdirSync(r)) o(`${r}/${e}`, !0);
|
|
19
|
+
n.rmdirSync(r);
|
|
20
|
+
} else n.unlinkSync(r);
|
|
21
|
+
}, s = (e) => `'${e.replaceAll("'", "'\\''")}'`, c = /* @__PURE__ */ new Set(), l = () => {
|
|
22
|
+
for (let e of c) e();
|
|
23
|
+
}, u, d = "", f = () => e.serverBridge.getServerPorts().flatMap((t) => {
|
|
24
|
+
let n = e.serverBridge.getServerMetadata(t);
|
|
25
|
+
return n?.ownerId !== e.id || n.purpose === "auxiliary" ? [] : [{
|
|
26
|
+
port: t,
|
|
27
|
+
url: e.serverBridge.getServerUrl(t) + "/",
|
|
28
|
+
name: n.name
|
|
29
|
+
}];
|
|
30
|
+
}), p = () => {
|
|
31
|
+
u !== void 0 && clearInterval(u), u = void 0, e.serverBridge.off("server-ready", l);
|
|
32
|
+
}, m = !1;
|
|
33
|
+
return {
|
|
34
|
+
id: e.id,
|
|
35
|
+
directory: r,
|
|
36
|
+
workspaceBridge: {
|
|
37
|
+
exists: (e) => n.existsSync(i(e)),
|
|
38
|
+
mkdir: (e) => n.mkdirSync(i(e), { recursive: !0 }),
|
|
39
|
+
readFile: (e) => n.existsSync(i(e)) ? n.readFileSync(i(e), "utf8") : void 0,
|
|
40
|
+
writeFile: (e, t) => n.writeFileSync(i(e), t),
|
|
41
|
+
stat: (e) => n.existsSync(i(e)) ? n.statSync(i(e)) : void 0,
|
|
42
|
+
readdir: (e) => n.readdirSync(i(e)).map((t) => {
|
|
43
|
+
let r = n.statSync(`${e}/${t}`);
|
|
44
|
+
return {
|
|
45
|
+
name: t,
|
|
46
|
+
isDirectory: () => r.isDirectory(),
|
|
47
|
+
isFile: () => r.isFile()
|
|
48
|
+
};
|
|
49
|
+
}),
|
|
50
|
+
listFiles: a,
|
|
51
|
+
remove: (e, t) => o(e, t?.recursive),
|
|
52
|
+
rename: (e, t) => n.renameSync(i(e), i(t))
|
|
53
|
+
},
|
|
54
|
+
processBridge: { async exec(t) {
|
|
55
|
+
if (m) throw Error("OpenCode host has been disposed.");
|
|
56
|
+
if (t.stdin) throw Error("This container adapter does not support piped stdin. Use a shell pipe or supply a custom processBridge.");
|
|
57
|
+
let n = /(?:^|\/)(?:ba|z|da)?sh$/.test(t.command) && t.args[0] === "-c" ? t.args[1] : t.shell ? [t.command, ...t.args.map(s)].join(" ") : [t.command, ...t.args].map(s).join(" "), a = await e.run(n ?? "", {
|
|
58
|
+
cwd: i(t.cwd ?? r),
|
|
59
|
+
env: t.env,
|
|
60
|
+
signal: t.signal
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
stdout: a.stdout,
|
|
64
|
+
stderr: a.stderr,
|
|
65
|
+
code: a.exitCode
|
|
66
|
+
};
|
|
67
|
+
} },
|
|
68
|
+
previews: {
|
|
69
|
+
ready: () => t.serviceWorkerUrl ? e.serverBridge.ensureServiceWorkerReady({
|
|
70
|
+
swUrl: t.serviceWorkerUrl,
|
|
71
|
+
reloadOnFirstControl: !1
|
|
72
|
+
}) : Promise.resolve(),
|
|
73
|
+
async fetch(t, n) {
|
|
74
|
+
if (!f().some((e) => e.port === t)) return new Response("This app port is closed.", { status: 503 });
|
|
75
|
+
let r = new URL(n.url), i = await e.serverBridge.handleRequest(t, n.method, r.pathname + r.search, Object.fromEntries(n.headers), n.method === "GET" || n.method === "HEAD" ? void 0 : await n.arrayBuffer()), a = new Headers(i.headers);
|
|
76
|
+
return a.delete("set-cookie"), new Response(n.method === "HEAD" || [
|
|
77
|
+
204,
|
|
78
|
+
205,
|
|
79
|
+
304
|
|
80
|
+
].includes(i.statusCode) ? null : new Uint8Array(i.body), {
|
|
81
|
+
status: i.statusCode,
|
|
82
|
+
statusText: i.statusMessage,
|
|
83
|
+
headers: a
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
list: f,
|
|
87
|
+
subscribe(t) {
|
|
88
|
+
return c.add(t), c.size === 1 && (d = JSON.stringify(f()), e.serverBridge.on("server-ready", l), u = setInterval(() => {
|
|
89
|
+
let e = JSON.stringify(f());
|
|
90
|
+
e !== d && (d = e, l());
|
|
91
|
+
}, 500)), () => {
|
|
92
|
+
c.delete(t), c.size || p();
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
setTarget: (t, n) => e.setHMRTargetForPort?.(t, n)
|
|
96
|
+
},
|
|
97
|
+
dispose() {
|
|
98
|
+
m || (m = !0, p(), c.clear(), t.disposeContainer && e.dispose());
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var t = e, n = "https://blamy.github.io/opencode/runtime.js";
|
|
103
|
+
async function r(e = n) {
|
|
104
|
+
let t = await import(
|
|
105
|
+
/* @vite-ignore */
|
|
106
|
+
e
|
|
107
|
+
);
|
|
108
|
+
if (typeof t.mount != "function") throw Error("The OpenCode runtime must export mount().");
|
|
109
|
+
return t;
|
|
110
|
+
}
|
|
111
|
+
function i(e, t) {
|
|
112
|
+
if (!Number.isInteger(e.port) || e.port < 1 || e.port > 65535) throw Error("Invalid OpenCode preview port.");
|
|
113
|
+
let n = new URL(t), r = new URL(e.url, n);
|
|
114
|
+
if (r.origin !== n.origin || !r.pathname.endsWith(`/__virtual__/${e.port}/`) || r.search || r.hash) throw Error("OpenCode previews must use the host service worker on this origin.");
|
|
115
|
+
return r.href;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
export { n as DEFAULT_OPENCODE_RUNTIME_URL, t as createAgentWasmOpenCodeHost, e as createAlmostNodeOpenCodeHost, r as loadOpenCodeRuntime, i as openCodePreviewUrl };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OpenCodeKeychainStore } from './open-code-host';
|
|
2
|
+
import { Vault } from './vault';
|
|
3
|
+
export declare const OPENCODE_CREDENTIAL_SLOT = "opencode-provider-credentials";
|
|
4
|
+
export declare const OPENCODE_CONNECTION_SLOT = "opencode-connection";
|
|
5
|
+
type Keychain = Pick<Vault, 'status' | 'get' | 'put' | 'subscribe'>;
|
|
6
|
+
/** Reuses the Passwords passkey-PRF/AES-GCM vault. Never prompts, enrolls or falls back to plaintext storage. */
|
|
7
|
+
export declare function createVaultOpenCodeCredentialStore(vault: Keychain): OpenCodeKeychainStore;
|
|
8
|
+
/** Saves the runtime's connection choice, Tailscale node keys and exit node in a separate encrypted slot. */
|
|
9
|
+
export declare function createVaultOpenCodeConnectionStore(vault: Keychain): OpenCodeKeychainStore;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=open-code-keychain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-code-keychain.d.ts","sourceRoot":"","sources":["../../src/lib/open-code-keychain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,wBAAwB,kCAAkC,CAAC;AACxE,eAAO,MAAM,wBAAwB,wBAAwB,CAAC;AAE9D,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC;AAEpE,iHAAiH;AACjH,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,QAAQ,GACd,qBAAqB,CAEvB;AAED,6GAA6G;AAC7G,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,QAAQ,GACd,qBAAqB,CAEvB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/lib/open-code-keychain.ts
|
|
2
|
+
var e = "opencode-provider-credentials", t = "opencode-connection";
|
|
3
|
+
function n(t) {
|
|
4
|
+
return i(t, e, []);
|
|
5
|
+
}
|
|
6
|
+
function r(e) {
|
|
7
|
+
return i(e, t, null);
|
|
8
|
+
}
|
|
9
|
+
function i(e, t, n) {
|
|
10
|
+
return {
|
|
11
|
+
version: 1,
|
|
12
|
+
unlocked: () => e.status === "unlocked",
|
|
13
|
+
load: async () => await e.get(t) ?? n,
|
|
14
|
+
save: (n) => e.put(t, n),
|
|
15
|
+
subscribe: (t) => e.subscribe(t)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { t as OPENCODE_CONNECTION_SLOT, e as OPENCODE_CREDENTIAL_SLOT, r as createVaultOpenCodeConnectionStore, n as createVaultOpenCodeCredentialStore };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OpenCodeHostBridge } from './open-code-host';
|
|
2
|
+
import { OpenCodeBrowser } from './open-code-browser';
|
|
3
|
+
export declare const DEFAULT_OPENCODE_PREVIEW_URL = "https://bl-cors-proxy.brett-lamy.workers.dev/opencode-preview/";
|
|
4
|
+
export declare function openCodePreviewFrameUrl(base: string, session: string, port: number, hostUrl: string, path?: string): string;
|
|
5
|
+
/** Connect the unchanged AlmostNode worker protocol directly to this container. No app payload goes to Cloudflare. */
|
|
6
|
+
export declare function connectOpenCodePreview(options: {
|
|
7
|
+
frame: HTMLIFrameElement;
|
|
8
|
+
host: OpenCodeHostBridge;
|
|
9
|
+
session: string;
|
|
10
|
+
port: number;
|
|
11
|
+
url: string;
|
|
12
|
+
onError(message: string): void;
|
|
13
|
+
browser?: OpenCodeBrowser;
|
|
14
|
+
onNavigate?(path: string): void;
|
|
15
|
+
}): () => void;
|
|
16
|
+
//# sourceMappingURL=open-code-preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-code-preview.d.ts","sourceRoot":"","sources":["../../src/lib/open-code-preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,eAAO,MAAM,4BAA4B,mEACyB,CAAC;AAEnE,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,SAAM,GACT,MAAM,CAcR;AASD,sHAAsH;AACtH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,KAAK,EAAE,iBAAiB,CAAC;IACzB,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,UAAU,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC,GAAG,MAAM,IAAI,CAyJb"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { injectOpenCodeBrowserAgent as e } from "./open-code-browser-agent.js";
|
|
2
|
+
//#region src/lib/open-code-preview.ts
|
|
3
|
+
var t = "https://bl-cors-proxy.brett-lamy.workers.dev/opencode-preview/";
|
|
4
|
+
function n(e, t, n, r, i = "/") {
|
|
5
|
+
let a = new URL(e, r);
|
|
6
|
+
if (a.origin === new URL(r).origin) throw Error("OpenCode app previews need a separate origin from the host page.");
|
|
7
|
+
if (!/^https?:$/.test(a.protocol) || !/^[a-f\d-]{36}$/.test(t)) throw Error("Invalid OpenCode preview host.");
|
|
8
|
+
if (a.pathname = a.pathname.replace(/\/?$/, "/") + t + "/host.html", !i.startsWith("/") || i.startsWith("//")) throw Error("Invalid app preview path.");
|
|
9
|
+
return a.search = new URLSearchParams({ port: String(n) }).toString(), a.hash = i === "/" ? "" : new URLSearchParams({ path: i }).toString(), a.href;
|
|
10
|
+
}
|
|
11
|
+
function r(e) {
|
|
12
|
+
let t = "";
|
|
13
|
+
for (let n = 0; n < e.length; n += 8192) t += String.fromCharCode(...e.subarray(n, n + 8192));
|
|
14
|
+
return btoa(t);
|
|
15
|
+
}
|
|
16
|
+
function i(t) {
|
|
17
|
+
let n = new URL(t.url).origin, i = t.browser?.connect({
|
|
18
|
+
...t,
|
|
19
|
+
navigate: t.onNavigate
|
|
20
|
+
}), a, o = setTimeout(() => t.onError("The AlmostNode preview service worker did not connect. Reload the app preview."), 2e4), s = setInterval(() => a?.port1.postMessage({ type: "keepalive" }), 15e3), c = !1, l = (i) => {
|
|
21
|
+
if (i.source !== t.frame.contentWindow || i.origin !== n || i.data?.session !== t.session) return;
|
|
22
|
+
if (i.data.type === "bl-opencode-preview:error") {
|
|
23
|
+
clearTimeout(o), t.onError(String(i.data.message));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (i.data.type === "bl-opencode-preview:connected") {
|
|
27
|
+
clearTimeout(o);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (i.data.type !== "bl-opencode-preview:ready" || a) return;
|
|
31
|
+
a = new MessageChannel();
|
|
32
|
+
let s = a.port1;
|
|
33
|
+
s.onmessage = async (n) => {
|
|
34
|
+
let i = n.data;
|
|
35
|
+
if (!(c || !i || i.type !== "request" || !["string", "number"].includes(typeof i.id))) try {
|
|
36
|
+
let n = i.data;
|
|
37
|
+
if (n?.port !== t.port || typeof n.url != "string" || !n.url.startsWith("/") || n.url.startsWith("//") || typeof n.method != "string" || !n.headers || typeof n.headers != "object") throw Error("Invalid AlmostNode preview request.");
|
|
38
|
+
if (!t.host.previews?.list().some((e) => e.port === t.port)) throw Error("The app port is closed.");
|
|
39
|
+
let a = new Headers(n.headers);
|
|
40
|
+
a.delete("cookie");
|
|
41
|
+
let o = await t.host.previews.fetch(t.port, new Request("https://preview.internal" + n.url, {
|
|
42
|
+
method: n.method,
|
|
43
|
+
headers: a,
|
|
44
|
+
body: n.method === "GET" || n.method === "HEAD" ? void 0 : n.body
|
|
45
|
+
}));
|
|
46
|
+
if (c) return;
|
|
47
|
+
let l = new Headers(o.headers), u = t.browser && o.body !== null && o.headers.get("content-type")?.includes("text/html") && n.method !== "HEAD", d = u ? new TextEncoder().encode(e(await o.text(), t.session, window.location.origin)) : new Uint8Array(await o.arrayBuffer());
|
|
48
|
+
u && l.delete("content-length");
|
|
49
|
+
let f = {
|
|
50
|
+
statusCode: o.status,
|
|
51
|
+
statusMessage: o.statusText,
|
|
52
|
+
headers: Object.fromEntries(l)
|
|
53
|
+
};
|
|
54
|
+
n.streaming ? (s.postMessage({
|
|
55
|
+
type: "stream-start",
|
|
56
|
+
id: i.id,
|
|
57
|
+
data: f
|
|
58
|
+
}), d.length && s.postMessage({
|
|
59
|
+
type: "stream-chunk",
|
|
60
|
+
id: i.id,
|
|
61
|
+
data: { chunkBase64: r(d) }
|
|
62
|
+
}), s.postMessage({
|
|
63
|
+
type: "stream-end",
|
|
64
|
+
id: i.id
|
|
65
|
+
})) : s.postMessage({
|
|
66
|
+
type: "response",
|
|
67
|
+
id: i.id,
|
|
68
|
+
data: {
|
|
69
|
+
...f,
|
|
70
|
+
bodyBase64: r(d)
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
} catch (e) {
|
|
74
|
+
if (c) return;
|
|
75
|
+
i.data?.streaming ? (s.postMessage({
|
|
76
|
+
type: "stream-start",
|
|
77
|
+
id: i.id,
|
|
78
|
+
data: {
|
|
79
|
+
statusCode: 502,
|
|
80
|
+
statusMessage: "Preview unavailable",
|
|
81
|
+
headers: { "content-type": "text/plain" }
|
|
82
|
+
}
|
|
83
|
+
}), s.postMessage({
|
|
84
|
+
type: "stream-chunk",
|
|
85
|
+
id: i.id,
|
|
86
|
+
data: { chunkBase64: r(new TextEncoder().encode(String(e))) }
|
|
87
|
+
}), s.postMessage({
|
|
88
|
+
type: "stream-end",
|
|
89
|
+
id: i.id
|
|
90
|
+
})) : s.postMessage({
|
|
91
|
+
type: "response",
|
|
92
|
+
id: i.id,
|
|
93
|
+
error: String(e)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}, s.postMessage({
|
|
97
|
+
type: "server-registered",
|
|
98
|
+
data: {
|
|
99
|
+
port: t.port,
|
|
100
|
+
hostname: "0.0.0.0"
|
|
101
|
+
}
|
|
102
|
+
}), t.frame.contentWindow?.postMessage({
|
|
103
|
+
type: "bl-opencode-preview:connect",
|
|
104
|
+
session: t.session
|
|
105
|
+
}, n, [a.port2]);
|
|
106
|
+
};
|
|
107
|
+
return window.addEventListener("message", l), () => {
|
|
108
|
+
c = !0, clearTimeout(o), clearInterval(s), window.removeEventListener("message", l), a?.port1.close(), i?.();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { t as DEFAULT_OPENCODE_PREVIEW_URL, i as connectOpenCodePreview, n as openCodePreviewFrameUrl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tailscale-connect.d.ts","sourceRoot":"","sources":["../../src/lib/tailscale-connect.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAwD,MAAM,iBAAiB,CAAC;AAEnI,uGAAuG;AACvG,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,SAAS,EAAE;QACb,WAAW,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;QACnD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;QACvC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;QACzC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;K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
|
|
32
32
|
blocks: Math.ceil(t.length / 512),
|
|
33
33
|
atimeMs: e,
|
|
34
34
|
mtimeMs: e,
|
|
35
|
-
ctimeMs: e
|
|
35
|
+
ctimeMs: e,
|
|
36
|
+
isDirectory: () => !1,
|
|
37
|
+
isFile: () => !0,
|
|
38
|
+
isSymbolicLink: () => !1
|
|
36
39
|
};
|
|
37
40
|
}, c = (e) => e === "/etc/ssl/cert.pem" && t !== null;
|
|
38
41
|
r.fs = Object.assign(Object.create(i), {
|
|
@@ -140,9 +143,9 @@ function u(e) {
|
|
|
140
143
|
return t.includes(".") && !l.test(t) && !t.includes(":") && !t.startsWith("[") && !t.endsWith(".ts.net") && t !== "localhost" && !t.endsWith(".localhost");
|
|
141
144
|
}
|
|
142
145
|
function d(e) {
|
|
143
|
-
let t = null, d = !1,
|
|
144
|
-
async function
|
|
145
|
-
let r =
|
|
146
|
+
let t = null, d = !1, m = null, h = () => {}, g = /* @__PURE__ */ new Map(), _ = {};
|
|
147
|
+
async function v(n) {
|
|
148
|
+
let r = g.get(n);
|
|
146
149
|
if (r && r.until > Date.now()) return r.ip;
|
|
147
150
|
let i = e.dnsVia === "exit-node", a = new URL(e.dohUrl ?? (i ? "https://1.1.1.1/dns-query" : "https://cloudflare-dns.com/dns-query"));
|
|
148
151
|
a.searchParams.set("name", n), a.searchParams.set("type", "A");
|
|
@@ -161,14 +164,14 @@ function d(e) {
|
|
|
161
164
|
if (o !== 200) throw Error(`DNS lookup for ${n} failed (HTTP ${o}).`);
|
|
162
165
|
let u = JSON.parse(c).Answer?.find((e) => e.type === 1 && typeof e.data == "string" && l.test(e.data));
|
|
163
166
|
if (!u?.data) throw Error(`${n} has no address to look up.`);
|
|
164
|
-
return
|
|
167
|
+
return g.set(n, {
|
|
165
168
|
ip: u.data,
|
|
166
169
|
until: Date.now() + Math.min(Math.max(u.TTL ?? 60, 30), 300) * 1e3
|
|
167
170
|
}), u.data;
|
|
168
171
|
}
|
|
169
|
-
let
|
|
170
|
-
...c(
|
|
171
|
-
...Object.keys(
|
|
172
|
+
let y = () => t?.configure?.({
|
|
173
|
+
...c(m),
|
|
174
|
+
...Object.keys(_).length ? { ipMap: { ..._ } } : {}
|
|
172
175
|
});
|
|
173
176
|
return {
|
|
174
177
|
async start(o) {
|
|
@@ -176,8 +179,8 @@ function d(e) {
|
|
|
176
179
|
let [s, l] = await Promise.all([(e.load ?? (() => import("@agent-wasm/tailscale-connect")))(), typeof e.caCertificates == "string" ? e.caCertificates : e.caCertificates ? e.caCertificates() : import("./tailscale-roots.js").then((e) => e.default)]);
|
|
177
180
|
n(l);
|
|
178
181
|
let u = new Map(Object.entries(o.state ?? {}));
|
|
179
|
-
o.exitNodeId && (
|
|
180
|
-
let
|
|
182
|
+
o.exitNodeId && (m = o.exitNodeId), h = r();
|
|
183
|
+
let f = await s.createIPN({
|
|
181
184
|
authKey: o.authKey ?? "",
|
|
182
185
|
controlURL: o.controlUrl,
|
|
183
186
|
hostname: o.hostname,
|
|
@@ -189,24 +192,24 @@ function d(e) {
|
|
|
189
192
|
}
|
|
190
193
|
},
|
|
191
194
|
panicHandler: (e) => {
|
|
192
|
-
|
|
195
|
+
h(), o.onEvent({ error: e });
|
|
193
196
|
},
|
|
194
197
|
...a(e.acceptDns !== !1),
|
|
195
|
-
...
|
|
198
|
+
...m ? c(m) : {}
|
|
196
199
|
});
|
|
197
|
-
d || (t =
|
|
200
|
+
d || (t = f, f.run({
|
|
198
201
|
notifyState: (e) => o.onEvent({ state: e }),
|
|
199
202
|
notifyNetMap: (e) => {
|
|
200
203
|
try {
|
|
201
204
|
let t = JSON.parse(e);
|
|
202
|
-
t.selectedExitNodeId !== void 0 && (
|
|
205
|
+
t.selectedExitNodeId !== void 0 && (m = t.selectedExitNodeId), o.onEvent({ netMap: t });
|
|
203
206
|
} catch {
|
|
204
207
|
o.onEvent({ netMap: null });
|
|
205
208
|
}
|
|
206
209
|
},
|
|
207
210
|
notifyBrowseToURL: (e) => o.onEvent({ loginUrl: e }),
|
|
208
211
|
notifyPanicRecover: (e) => {
|
|
209
|
-
|
|
212
|
+
h(), o.onEvent({ error: e });
|
|
210
213
|
}
|
|
211
214
|
}));
|
|
212
215
|
},
|
|
@@ -219,60 +222,92 @@ function d(e) {
|
|
|
219
222
|
async setExitNode(e) {
|
|
220
223
|
if (!t) throw Error("The Tailscale client is not running.");
|
|
221
224
|
if (!t.configure) throw Error("This build of the Tailscale client cannot change its exit node.");
|
|
222
|
-
|
|
225
|
+
m = e, await y(), g.clear();
|
|
223
226
|
},
|
|
224
|
-
async fetch(
|
|
227
|
+
async fetch(e) {
|
|
225
228
|
if (!t) throw Error("The Tailscale client is not running.");
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
bodyBase64: n.body ? o(n.body) : void 0,
|
|
231
|
-
redirect: n.redirect,
|
|
232
|
-
...t
|
|
233
|
-
}), p;
|
|
234
|
-
if (a) {
|
|
235
|
-
let r = await g(i.hostname), a = (e) => e instanceof Error ? e.message : typeof e == "string" ? e : e?.message ?? String(e), o = () => {
|
|
236
|
-
let e = new URL(n.url);
|
|
237
|
-
e.hostname = r;
|
|
238
|
-
let a = { ...l };
|
|
239
|
-
for (let e of Object.keys(a)) e.toLowerCase() === "host" && delete a[e];
|
|
240
|
-
return a.Host = i.host, t.fetch({
|
|
241
|
-
...d(e.href),
|
|
242
|
-
headers: a,
|
|
243
|
-
...i.protocol === "https:" ? { tlsServerName: i.hostname } : {}
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
|
-
if (e.exitNodeDial === "name") {
|
|
247
|
-
h[i.hostname] !== r && (h[i.hostname] = r, await _());
|
|
248
|
-
try {
|
|
249
|
-
p = await t.fetch(d(n.url));
|
|
250
|
-
} catch (e) {
|
|
251
|
-
try {
|
|
252
|
-
p = await o();
|
|
253
|
-
} catch (t) {
|
|
254
|
-
throw Error(`${i.hostname} (${r}) could not be fetched through the exit node. Fetching the name: ${a(e)}. Fetching the address: ${a(t)}.`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
} else try {
|
|
258
|
-
p = await o();
|
|
259
|
-
} catch (e) {
|
|
260
|
-
throw Error(`${i.hostname} (${r}) could not be fetched through the exit node: ${a(e)}.`);
|
|
261
|
-
}
|
|
262
|
-
} else p = await t.fetch(c ? n.url : d(n.url));
|
|
263
|
-
let m = p.bodyBase64 === void 0 ? p.text ? new TextEncoder().encode(await p.text()) : null : s(p.bodyBase64);
|
|
264
|
-
return {
|
|
265
|
-
url: a ? n.url : p.url ?? n.url,
|
|
266
|
-
status: p.status,
|
|
267
|
-
statusText: p.statusText ?? "",
|
|
268
|
-
headers: Object.entries(p.headers ?? {}),
|
|
269
|
-
body: m
|
|
229
|
+
if (m === null || (e.redirect ?? "follow") !== "follow" || !u(new URL(e.url).hostname)) return b(e);
|
|
230
|
+
let n = {
|
|
231
|
+
...e,
|
|
232
|
+
redirect: "manual"
|
|
270
233
|
};
|
|
234
|
+
for (let t = 0;; t++) {
|
|
235
|
+
let r = await b(n), i = f.has(r.status) ? r.headers.find(([e]) => e.toLowerCase() === "location")?.[1] : void 0;
|
|
236
|
+
if (!i) return r;
|
|
237
|
+
if (t >= p) throw Error(`${e.url} redirected more than ${p} times.`);
|
|
238
|
+
let a = new URL(i, n.url);
|
|
239
|
+
if (a.protocol !== "http:" && a.protocol !== "https:") return r;
|
|
240
|
+
n = (r.status === 303 ? (n.method ?? "GET").toUpperCase() !== "HEAD" : (r.status === 301 || r.status === 302) && (n.method ?? "GET").toUpperCase() === "POST") ? {
|
|
241
|
+
...n,
|
|
242
|
+
url: a.href,
|
|
243
|
+
method: "GET",
|
|
244
|
+
body: null,
|
|
245
|
+
headers: n.headers?.filter(([e]) => !/^content-/i.test(e))
|
|
246
|
+
} : {
|
|
247
|
+
...n,
|
|
248
|
+
url: a.href
|
|
249
|
+
};
|
|
250
|
+
}
|
|
271
251
|
},
|
|
272
252
|
dispose() {
|
|
273
|
-
d = !0, t = null,
|
|
253
|
+
d = !0, t = null, h();
|
|
274
254
|
}
|
|
275
255
|
};
|
|
256
|
+
async function b(n) {
|
|
257
|
+
if (!t) throw Error("The Tailscale client is not running.");
|
|
258
|
+
let r = (n.method ?? "GET").toUpperCase(), i = new URL(n.url), a = m !== null && u(i.hostname), c = !a && r === "GET" && !n.body && !n.headers?.length && (n.redirect ?? "follow") === "follow", l = Object.fromEntries(n.headers ?? []), d = (e, t = {}) => ({
|
|
259
|
+
url: e,
|
|
260
|
+
method: r,
|
|
261
|
+
headers: l,
|
|
262
|
+
bodyBase64: n.body ? o(n.body) : void 0,
|
|
263
|
+
redirect: n.redirect,
|
|
264
|
+
...t
|
|
265
|
+
}), f;
|
|
266
|
+
if (a) {
|
|
267
|
+
let r = await v(i.hostname), a = (e) => e instanceof Error ? e.message : typeof e == "string" ? e : e?.message ?? String(e), o = () => {
|
|
268
|
+
let e = new URL(n.url);
|
|
269
|
+
e.hostname = r;
|
|
270
|
+
let a = { ...l };
|
|
271
|
+
for (let e of Object.keys(a)) e.toLowerCase() === "host" && delete a[e];
|
|
272
|
+
return a.Host = i.host, t.fetch({
|
|
273
|
+
...d(e.href),
|
|
274
|
+
headers: a,
|
|
275
|
+
...i.protocol === "https:" ? { tlsServerName: i.hostname } : {}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
if (e.exitNodeDial === "name") {
|
|
279
|
+
_[i.hostname] !== r && (_[i.hostname] = r, await y());
|
|
280
|
+
try {
|
|
281
|
+
f = await t.fetch(d(n.url));
|
|
282
|
+
} catch (e) {
|
|
283
|
+
try {
|
|
284
|
+
f = await o();
|
|
285
|
+
} catch (t) {
|
|
286
|
+
throw Error(`${i.hostname} (${r}) could not be fetched through the exit node. Fetching the name: ${a(e)}. Fetching the address: ${a(t)}.`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
} else try {
|
|
290
|
+
f = await o();
|
|
291
|
+
} catch (e) {
|
|
292
|
+
throw Error(`${i.hostname} (${r}) could not be fetched through the exit node: ${a(e)}.`);
|
|
293
|
+
}
|
|
294
|
+
} else f = await t.fetch(c ? n.url : d(n.url));
|
|
295
|
+
let p = f.bodyBase64 === void 0 ? f.text ? new TextEncoder().encode(await f.text()) : null : s(f.bodyBase64);
|
|
296
|
+
return {
|
|
297
|
+
url: a ? n.url : f.url ?? n.url,
|
|
298
|
+
status: f.status,
|
|
299
|
+
statusText: f.statusText ?? "",
|
|
300
|
+
headers: Object.entries(f.headers ?? {}),
|
|
301
|
+
body: p
|
|
302
|
+
};
|
|
303
|
+
}
|
|
276
304
|
}
|
|
305
|
+
var f = /* @__PURE__ */ new Set([
|
|
306
|
+
301,
|
|
307
|
+
302,
|
|
308
|
+
303,
|
|
309
|
+
307,
|
|
310
|
+
308
|
|
311
|
+
]), p = 20;
|
|
277
312
|
//#endregion
|
|
278
313
|
export { e as TAILSCALE_CERT_FILE, d as createTailscaleConnectClient, c as exitNodeSettings, n as installTailscaleRoots, u as isPublicName, i as keepCorpDns };
|
|
@@ -25,6 +25,10 @@ export interface TailscalePolicy {
|
|
|
25
25
|
maxBodyBytes?: number;
|
|
26
26
|
/** How long the worker waits for the tailnet client's response headers (ms). Default 60 000. */
|
|
27
27
|
timeoutMs?: number;
|
|
28
|
+
/** Serve whole sites through the tailnet under this path of the worker's scope, e.g. `__tailnet/`: a frame opened at
|
|
29
|
+
* `<scope>__tailnet/https/example.com/a?b` loads https://example.com/a?b, its scripts run, and every request it makes (its
|
|
30
|
+
* relative URLs included) is routed, whatever the rest of the policy says. Default none. See `tailscaleProxyUrl`. */
|
|
31
|
+
proxyPath?: string;
|
|
28
32
|
}
|
|
29
33
|
export interface ResolvedTailscalePolicy {
|
|
30
34
|
v: 1;
|
|
@@ -40,8 +44,9 @@ export interface ResolvedTailscalePolicy {
|
|
|
40
44
|
whenUnavailable: TailscaleUnavailable;
|
|
41
45
|
maxBodyBytes: number;
|
|
42
46
|
timeoutMs: number;
|
|
47
|
+
proxyPath: string | null;
|
|
43
48
|
}
|
|
44
|
-
export type TailscaleMatchReason = 'tailnet-name' | 'tailnet-address' | 'host' | 'cidr' | 'short-name' | 'all' | 'invalid-url' | 'scheme' | 'same-origin' | 'loopback' | 'method' | 'excluded' | 'no-match';
|
|
49
|
+
export type TailscaleMatchReason = 'tailnet-name' | 'tailnet-address' | 'host' | 'cidr' | 'short-name' | 'all' | 'invalid-url' | 'scheme' | 'same-origin' | 'loopback' | 'tailscale' | 'method' | 'excluded' | 'no-match';
|
|
45
50
|
export interface TailscaleMatch {
|
|
46
51
|
route: boolean;
|
|
47
52
|
reason: TailscaleMatchReason;
|
|
@@ -56,10 +61,14 @@ export declare function isTailnetAddress(host: string): boolean;
|
|
|
56
61
|
export declare function isTailnetHost(host: string): boolean;
|
|
57
62
|
/** Fills in the defaults and checks the lists. Throws `TailscalePolicyError` for a host or range that cannot be read. */
|
|
58
63
|
export declare function resolveTailscalePolicy(policy?: TailscalePolicy): ResolvedTailscalePolicy;
|
|
64
|
+
/** The address a frame opens to load `target` through the tailnet: `<scope><proxyPath><scheme>/<host><path>`. */
|
|
65
|
+
export declare function tailscaleProxyUrl(target: string | URL, scope: string, path?: string): string;
|
|
66
|
+
/** The inverse of `tailscaleProxyUrl`: the site a proxy address loads, or null when `url` is not one. */
|
|
67
|
+
export declare function tailscaleProxyTarget(url: string, scope: string, path?: string): string | null;
|
|
59
68
|
/**
|
|
60
69
|
* Would a request for `url` be routed? `origin` is the page's origin (to leave its own requests alone).
|
|
61
70
|
* Decisions are made in a fixed order, so `reason` says which rule decided: not a URL, scheme, same origin, loopback,
|
|
62
|
-
* method, `exclude`, then the inclusions.
|
|
71
|
+
* Tailscale's own services, method, `exclude`, then the inclusions.
|
|
63
72
|
*/
|
|
64
73
|
export declare function matchTailscalePolicy(url: string | URL, method: string, policy: ResolvedTailscalePolicy, origin?: string): TailscaleMatch;
|
|
65
74
|
/** The resolved policy as the `p` query parameter of the worker's script URL (the worker reads it back, so it cannot be changed by a message). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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