@sakikotgw/pad-gateway-jump 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/lib/index.js +57 -13
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -62,6 +62,59 @@ function apply(ctx, config = {}) {
62
62
  });
63
63
  const handleJump = createJumpHttpHandler({ store: jumpStore, token });
64
64
  let server;
65
+ let listenPort;
66
+ let webUrl;
67
+ const adUrl = () => `http://127.0.0.1:${listenPort ?? 0}/api`;
68
+ /**
69
+ * Rewrite the ad. Once the host web listener is bound, `webUrl` points at it:
70
+ * 0.2.x serves the same `client-request` gateway protocol under `/api/<method>`,
71
+ * so PAD can read sessions directly instead of having them proxied here.
72
+ */
73
+ const writeAd = () => {
74
+ if (listenPort === undefined) return;
75
+ const ad = {
76
+ schema: GATEWAY_SCHEMA,
77
+ url: adUrl(),
78
+ token,
79
+ pid: process.pid,
80
+ capabilities: { jump: true, api: false },
81
+ ...(webUrl ? { webUrl, apiStyle: "dsh-0.2" } : {}),
82
+ ...(process.env.DSH_PROFILE ? { profile: process.env.DSH_PROFILE } : {}),
83
+ };
84
+ writeFileSync(file, `${JSON.stringify(ad, null, 2)}\n`, { encoding: "utf8", mode: 384 });
85
+ try {
86
+ chmodSync(file, 384);
87
+ } catch {}
88
+ };
89
+ /** Learn the web listener origin from the host service and publish it in the ad. */
90
+ const attachWebUrl = () => {
91
+ try {
92
+ ctx.inject?.(["webServer"], (services) => {
93
+ const webServer = services?.webServer;
94
+ if (typeof webServer?.getOrigin !== "function") return;
95
+ const publish = () => {
96
+ try {
97
+ const origin = webServer.getOrigin();
98
+ if (typeof origin !== "string" || origin.length === 0) return false;
99
+ webUrl = origin;
100
+ writeAd();
101
+ trace(`web api origin attached: ${origin}`);
102
+ return true;
103
+ } catch {
104
+ return false;
105
+ }
106
+ };
107
+ if (publish()) return;
108
+ const timer = setInterval(() => {
109
+ if (publish()) clearInterval(timer);
110
+ }, 300);
111
+ timer.unref?.();
112
+ ctx.on?.("dispose", () => clearInterval(timer));
113
+ });
114
+ } catch (err) {
115
+ trace(`webServer injection failed: ${err instanceof Error ? err.message : String(err)}`);
116
+ }
117
+ };
65
118
  trace(`apply() in pid ${process.pid}`);
66
119
  const boot = async () => {
67
120
  server = createServer((req, res) => {
@@ -101,19 +154,10 @@ function apply(ctx, config = {}) {
101
154
  });
102
155
  const addr = server.address();
103
156
  if (!addr || typeof addr === "string") throw new Error("pad gateway-jump failed to bind");
104
- const ad = {
105
- schema: GATEWAY_SCHEMA,
106
- url: `http://127.0.0.1:${addr.port}/api`,
107
- token,
108
- pid: process.pid,
109
- capabilities: { jump: true, api: false },
110
- ...(process.env.DSH_PROFILE ? { profile: process.env.DSH_PROFILE } : {}),
111
- };
112
- writeFileSync(file, `${JSON.stringify(ad, null, 2)}\n`, { encoding: "utf8", mode: 384 });
113
- try {
114
- chmodSync(file, 384);
115
- } catch {}
116
- trace(`listening on ${ad.url} (jump channel ready, api disabled)`);
157
+ listenPort = addr.port;
158
+ writeAd();
159
+ trace(`listening on ${adUrl()} (jump channel ready, /api served from the web listener when available)`);
160
+ attachWebUrl();
117
161
  };
118
162
  boot().catch((err) => {
119
163
  const detail = err instanceof Error ? `${err.message}\n${err.stack ?? ""}` : String(err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sakikotgw/pad-gateway-jump",
3
- "version": "0.1.0",
4
- "description": "PAD jump-only loopback carrier for DeepSeek Harness 0.2.x: session jump events over the same pad-gateway.json contract (no apiproxy).",
3
+ "version": "0.1.1",
4
+ "description": "PAD jump-only loopback carrier for DeepSeek Harness 0.2.x: session jump events over the same pad-gateway.json contract (no apiproxy; publishes the host web API origin for PAD).",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
7
7
  "exports": {