@agimon-ai/po-remote 0.0.0-alpha.186 → 0.0.0-alpha.187
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/README.md +4 -0
- package/dist/index.cjs +34 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +34 -13
- package/dist/index.mjs.map +1 -1
- package/dist/po-runtime-identity.json +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ Each listener owns its pairing codes, sessions, channels, timers, and failures.
|
|
|
23
23
|
|
|
24
24
|
`dualRemote.test.ts` exercises both connections with an isolated host and fake carriers. This does not demonstrate a live public tunnel, staging pairing, or physical-device acceptance. Private relay pairing in the host dialog uses the Po app; Cloud browser bootstrap is a separate acceptance requirement.
|
|
25
25
|
|
|
26
|
+
## Tailscale Serve
|
|
27
|
+
|
|
28
|
+
Set `PO_TAILSCALE_SERVE_HOSTNAME` to the exact `device.tailnet.ts.net` name in the host service environment. When the operator turns on the tunnel connection, Po uses the existing origin-pinned paired gateway on `127.0.0.1:7543` instead of starting a Cloudflare connector. It does not auto-restore named Cloudflare intent in this mode. The normal loopback presentation and headless listeners are unchanged. The operator manages the Serve proxy, certificates and tailnet grants separately; Po does not enable Funnel or treat forwarded identity headers as device authorization. See the [VPS setup guide](../../../templates/po-selfhost-vps/README.md#optional-private-https-with-tailscale-serve).
|
|
29
|
+
|
|
26
30
|
## Help and authoring
|
|
27
31
|
|
|
28
32
|
The package publishes `src/prompts/help-how-to-remote/SKILL.md` through a named resource route and `llms.txt`. Keep additional guides package-owned and in the publish allowlist; do not export Markdown or copy it into `dist`.
|
package/dist/index.cjs
CHANGED
|
@@ -5804,6 +5804,8 @@ const TUNNEL_REQUEST_TIMEOUT_MS = 1e4;
|
|
|
5804
5804
|
const TUNNEL_CONNECTION_LIMIT = 64;
|
|
5805
5805
|
const TUNNEL_REQUESTS_PER_SOCKET = 100;
|
|
5806
5806
|
const SEALED_HTTP_VERSION = 1;
|
|
5807
|
+
const INTERNAL_ORIGIN = "http://po.local";
|
|
5808
|
+
const HTTP_ERROR_MIN = 400;
|
|
5807
5809
|
/**
|
|
5808
5810
|
* The relay carrier's streamed form of a sealed request. This header holds the sealed envelope `{v, n, c}` whose
|
|
5809
5811
|
* plaintext is the inner request's JSON (v, method, target, headers, no body), sealed with the device's HTTP channel
|
|
@@ -5871,8 +5873,8 @@ function sealedRequest(value) {
|
|
|
5871
5873
|
if (typeof value !== "object" || value === null) return void 0;
|
|
5872
5874
|
const request = value;
|
|
5873
5875
|
if (request.v !== SEALED_HTTP_VERSION || typeof request.method !== "string" || !SEALED_HTTP_METHODS.has(request.method) || typeof request.target !== "string" || !request.target.startsWith("/") || request.target.startsWith("//") || /[\\#\u0000-\u0020]/u.test(request.target) || !Array.isArray(request.headers) || !request.headers.every((header) => Array.isArray(header) && header.length === 2 && header.every((part) => typeof part === "string")) || request.body !== void 0 && typeof request.body !== "string") return void 0;
|
|
5874
|
-
const parsed = new URL(request.target,
|
|
5875
|
-
if (parsed.origin !==
|
|
5876
|
+
const parsed = new URL(request.target, INTERNAL_ORIGIN);
|
|
5877
|
+
if (parsed.origin !== INTERNAL_ORIGIN || parsed.pathname + parsed.search !== request.target || parsed.pathname === _agimon_ai_po_core_remoteContract.REMOTE_HTTP_ROUTE || parsed.pathname === _agimon_ai_po_core_remoteContract.REMOTE_CHANNEL_ROUTE) return void 0;
|
|
5876
5878
|
return request;
|
|
5877
5879
|
}
|
|
5878
5880
|
function decodedBody(value) {
|
|
@@ -5941,7 +5943,9 @@ function framedWire(input) {
|
|
|
5941
5943
|
closed = true;
|
|
5942
5944
|
try {
|
|
5943
5945
|
controller.close();
|
|
5944
|
-
} catch {
|
|
5946
|
+
} catch {
|
|
5947
|
+
reason ??= "client closed";
|
|
5948
|
+
}
|
|
5945
5949
|
reader.cancel().catch(() => void 0);
|
|
5946
5950
|
if (reason !== void 0) endListener?.(reason);
|
|
5947
5951
|
};
|
|
@@ -6079,13 +6083,22 @@ async function writeResponse(response, result) {
|
|
|
6079
6083
|
}
|
|
6080
6084
|
await (0, node_stream_promises.pipeline)(node_stream.Readable.fromWeb(result.body), response);
|
|
6081
6085
|
}
|
|
6082
|
-
/** One
|
|
6086
|
+
/** One local control plane and a second socket dedicated to remote traffic. */
|
|
6083
6087
|
function createRemoteRuntime(options) {
|
|
6084
6088
|
const lanTls = options.lanTls;
|
|
6085
6089
|
const privateRelay = options.privateRelay === void 0 ? void 0 : validatePrivateRelay(options.privateRelay);
|
|
6086
6090
|
const relaySetup = options.privateRelaySetup;
|
|
6087
6091
|
let activeRelay;
|
|
6088
6092
|
if (lanTls !== void 0 && (privateRelay !== void 0 || relaySetup !== void 0)) throw new Error("Private network and private relay exposure cannot both be on.");
|
|
6093
|
+
const serveHostname = options.environment?.PO_TAILSCALE_SERVE_HOSTNAME;
|
|
6094
|
+
const servePort = 7543;
|
|
6095
|
+
let serveOrigin;
|
|
6096
|
+
if (serveHostname !== void 0) {
|
|
6097
|
+
const label = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
|
|
6098
|
+
if (!new RegExp(`^${label}\\.${label}\\.ts\\.net$`, "u").test(serveHostname) || /\s/u.test(serveHostname)) throw new Error("PO_TAILSCALE_SERVE_HOSTNAME must be the exact device DNS name (device.tailnet.ts.net).");
|
|
6099
|
+
if (lanTls !== void 0 || privateRelay !== void 0) throw new Error("Tailscale Serve cannot be used with the private LAN or environment-configured relay.");
|
|
6100
|
+
serveOrigin = `https://${serveHostname}`;
|
|
6101
|
+
}
|
|
6089
6102
|
const store = createRemoteAccessStore({
|
|
6090
6103
|
stateDir: defaultRemoteStateDir(options.homeDirectory, options.environment),
|
|
6091
6104
|
onNotice: (message) => options.onNotice(message)
|
|
@@ -6131,6 +6144,7 @@ function createRemoteRuntime(options) {
|
|
|
6131
6144
|
let lastIntent;
|
|
6132
6145
|
let frontendOrigin;
|
|
6133
6146
|
const tunnelIntent = () => {
|
|
6147
|
+
if (serveOrigin !== void 0) return void 0;
|
|
6134
6148
|
const access = remote.instance("tunnel");
|
|
6135
6149
|
const state = access.state();
|
|
6136
6150
|
const tunnel = access.settings().tunnel;
|
|
@@ -6173,11 +6187,12 @@ function createRemoteRuntime(options) {
|
|
|
6173
6187
|
const rawPath = context.env.incoming?.url?.split("?")[0];
|
|
6174
6188
|
const publicGatewayPeer = context.env.listener === "tunnel" && context.req.header("x-po-host-proof") !== void 0 && (context.req.method === "GET" && rawPath === "/api/plugins/gateway/catalog" || context.req.method === "POST" && rawPath === "/api/plugins/gateway/calls");
|
|
6175
6189
|
const computerNetwork = context.req.path.startsWith("/api/network/") || /^\/api\/networks\/[^/]+\/network\//u.test(context.req.path);
|
|
6176
|
-
|
|
6190
|
+
const allowRawFederation = serveOrigin === void 0 || context.env.incoming === void 0;
|
|
6191
|
+
if (allowRawFederation && computerNetwork) {
|
|
6177
6192
|
const result = await defaultFederation?.requestNetwork(context.req.raw);
|
|
6178
6193
|
if (result) return result;
|
|
6179
6194
|
}
|
|
6180
|
-
if (!publicGatewayPeer && context.req.header("x-po-federation-envelope") && context.req.path.includes("/plugins/")) {
|
|
6195
|
+
if (allowRawFederation && !publicGatewayPeer && context.req.header("x-po-federation-envelope") && context.req.path.includes("/plugins/")) {
|
|
6181
6196
|
const request = context.req.raw;
|
|
6182
6197
|
if (!await options.federationPlatform?.resolve(request.clone())) return context.json({
|
|
6183
6198
|
status: "unavailable",
|
|
@@ -6360,7 +6375,11 @@ function createRemoteRuntime(options) {
|
|
|
6360
6375
|
publishIntent();
|
|
6361
6376
|
},
|
|
6362
6377
|
onDeviceDropped: options.onDeviceDropped,
|
|
6363
|
-
launchTunnel: transport === "tunnel" && lanTls === void 0 && privateRelay === void 0 ?
|
|
6378
|
+
launchTunnel: transport === "tunnel" && lanTls === void 0 && privateRelay === void 0 ? serveOrigin !== void 0 ? async () => ({
|
|
6379
|
+
ok: true,
|
|
6380
|
+
publicOrigin: serveOrigin,
|
|
6381
|
+
stop: async () => void 0
|
|
6382
|
+
}) : options.launchTunnel ?? createTunnelLauncher({
|
|
6364
6383
|
stateDir: store.directory,
|
|
6365
6384
|
onNotice: (message) => options.onNotice(message),
|
|
6366
6385
|
onExit: (message) => {
|
|
@@ -6407,6 +6426,7 @@ function createRemoteRuntime(options) {
|
|
|
6407
6426
|
const url = new URL(incoming.url ?? "/", `http://${incoming.headers.host ?? "localhost"}`);
|
|
6408
6427
|
const headers = new Headers();
|
|
6409
6428
|
for (const [name, value] of Object.entries(incoming.headers)) if (value !== void 0) headers.set(name, Array.isArray(value) ? value.join(", ") : value);
|
|
6429
|
+
if (serveOrigin !== void 0) headers.delete("cf-connecting-ip");
|
|
6410
6430
|
const body = incoming.method === "GET" || incoming.method === "HEAD" ? void 0 : await readBody(incoming);
|
|
6411
6431
|
const request = new Request(url, {
|
|
6412
6432
|
method: incoming.method,
|
|
@@ -6438,7 +6458,7 @@ function createRemoteRuntime(options) {
|
|
|
6438
6458
|
return;
|
|
6439
6459
|
}
|
|
6440
6460
|
const url = new URL(incoming.url ?? "/", `http://${incoming.headers.host ?? "localhost"}`);
|
|
6441
|
-
if (/^\/api\/networks\/[^/]+\/relay$/.test(url.pathname)) {
|
|
6461
|
+
if (serveOrigin === void 0 && /^\/api\/networks\/[^/]+\/relay$/.test(url.pathname)) {
|
|
6442
6462
|
webSockets.handleUpgrade(incoming, socket, head, (client) => {
|
|
6443
6463
|
const peer = {
|
|
6444
6464
|
get isOpen() {
|
|
@@ -6536,7 +6556,7 @@ function createRemoteRuntime(options) {
|
|
|
6536
6556
|
server.maxRequestsPerSocket = TUNNEL_REQUESTS_PER_SOCKET;
|
|
6537
6557
|
await new Promise((resolve, reject) => {
|
|
6538
6558
|
server.once("error", reject);
|
|
6539
|
-
server.listen(lan?.port ?? 0, lan?.address ?? "127.0.0.1", resolve);
|
|
6559
|
+
server.listen(lan?.port ?? (serveOrigin === void 0 ? 0 : servePort), lan?.address ?? "127.0.0.1", resolve);
|
|
6540
6560
|
});
|
|
6541
6561
|
const address = server.address();
|
|
6542
6562
|
if (!address || typeof address === "string") throw new Error("The tunnel listener has no TCP address.");
|
|
@@ -6659,6 +6679,7 @@ function createRemoteRuntime(options) {
|
|
|
6659
6679
|
listenerOf: (context) => context.env.listener,
|
|
6660
6680
|
reservedPorts: () => [
|
|
6661
6681
|
remote.tunnelPort(),
|
|
6682
|
+
serveOrigin === void 0 ? void 0 : servePort,
|
|
6662
6683
|
frontendOrigin === void 0 ? void 0 : Number(new URL(frontendOrigin).port),
|
|
6663
6684
|
...options.reservedPorts?.() ?? []
|
|
6664
6685
|
],
|
|
@@ -6696,7 +6717,7 @@ function createRemoteRuntime(options) {
|
|
|
6696
6717
|
*/
|
|
6697
6718
|
const dispatchSealed = async (input) => {
|
|
6698
6719
|
const { context, device, inner, body, stream, relay } = input;
|
|
6699
|
-
const target = new URL(inner.target,
|
|
6720
|
+
const target = new URL(inner.target, INTERNAL_ORIGIN);
|
|
6700
6721
|
const headers = new Headers();
|
|
6701
6722
|
for (const [name, value] of inner.headers) {
|
|
6702
6723
|
const normalized = name.toLowerCase();
|
|
@@ -6923,7 +6944,7 @@ function createRemoteRuntime(options) {
|
|
|
6923
6944
|
const sealed = channel.seal(plaintext);
|
|
6924
6945
|
const sealMs = performance.now() - sealStartedAt;
|
|
6925
6946
|
const durationMs = performance.now() - startedAt;
|
|
6926
|
-
if (options.telemetry && (response.status >=
|
|
6947
|
+
if (options.telemetry && (response.status >= HTTP_ERROR_MIN || durationMs >= _agimon_ai_po_core_packageApiServer.COMPLETION_SPAN_MIN_DURATION_MS || responseBody.byteLength >= _agimon_ai_po_core_packageApiServer.COMPLETION_SPAN_MIN_BYTES || body.byteLength >= _agimon_ai_po_core_packageApiServer.COMPLETION_SPAN_MIN_BYTES)) {
|
|
6927
6948
|
const segments = target.pathname.split("/");
|
|
6928
6949
|
(0, _agimon_ai_po_core_serverTelemetry.observe)(options.telemetry.recordEvent("po_server.sealed_http", {
|
|
6929
6950
|
route_name: segments[2] === "plugins" ? `plugins.${segments[3] ?? ""}` : segments[2] ?? "",
|
|
@@ -6995,7 +7016,7 @@ function createRemoteRuntime(options) {
|
|
|
6995
7016
|
if (context.req.path === "/" && remote.authorize((0, hono_cookie.getCookie)(context, _agimon_ai_po_core_remoteContract.DEVICE_COOKIE, "host")) === void 0) return context.redirect("/pair");
|
|
6996
7017
|
if (context.req.path === "/bundle-manifest.json" || context.req.path.startsWith("/bundle-assets/")) {
|
|
6997
7018
|
const from = new URL(context.req.url);
|
|
6998
|
-
return await options.forward(new Request(new URL(`${from.pathname}${from.search}`,
|
|
7019
|
+
return await options.forward(new Request(new URL(`${from.pathname}${from.search}`, INTERNAL_ORIGIN), { method: context.req.method }));
|
|
6999
7020
|
}
|
|
7000
7021
|
if (!frontendOrigin) return context.json({ error: "The web presentation server is unavailable." }, 503);
|
|
7001
7022
|
const from = new URL(context.req.url);
|
|
@@ -7165,7 +7186,7 @@ function createRemoteRuntime(options) {
|
|
|
7165
7186
|
restoreTunnel: async (intent) => {
|
|
7166
7187
|
const parsed = store.settingsForRestore();
|
|
7167
7188
|
const tunnel = parsed?.settings.tunnel;
|
|
7168
|
-
if (closing || lanTls !== void 0 || privateRelay !== void 0 || typeof intent?.hostname !== "string" || tunnel?.kind !== "named" || tunnel.hostname !== intent.hostname || parsed?.warnings.length !== 0 || remote.settings().tunnel.kind !== "named" || intent.closesAt !== void 0 && (!Number.isFinite(intent.closesAt) || intent.closesAt <= Date.now())) return {
|
|
7189
|
+
if (closing || serveOrigin !== void 0 || lanTls !== void 0 || privateRelay !== void 0 || typeof intent?.hostname !== "string" || tunnel?.kind !== "named" || tunnel.hostname !== intent.hostname || parsed?.warnings.length !== 0 || remote.settings().tunnel.kind !== "named" || intent.closesAt !== void 0 && (!Number.isFinite(intent.closesAt) || intent.closesAt <= Date.now())) return {
|
|
7169
7190
|
ok: false,
|
|
7170
7191
|
error: "The named tunnel intent is no longer valid for automatic restore."
|
|
7171
7192
|
};
|