@auroraflow/code 0.0.11 → 0.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auroraflow/code",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "type": "module",
5
5
  "description": "Aurora launcher and sidecar for official Codex and Claude Code clients.",
6
6
  "repository": {
@@ -15,6 +15,20 @@ const CODEX_MODEL_CAPABILITIES_PATH = join(CODEX_HOME, "model_capabilities.json"
15
15
  const GATEWAY_HEADER_TIMEOUT_MS = 60000;
16
16
  const GATEWAY_IDLE_TIMEOUT_MS = 120000;
17
17
 
18
+ // Keep the sidecar->gateway TLS connection warm. The expensive part of a cold
19
+ // request is the ~1s TLS handshake to the gateway edge; undici pools the
20
+ // connection but drops it after ~4s idle, so every think-pause re-handshakes
21
+ // ("时快时慢"). A lightweight heartbeat under that idle window keeps one pooled
22
+ // connection alive so real requests reuse a warm socket. It only runs within a
23
+ // window after real activity, so an idle/abandoned sidecar stops chattering.
24
+ const GATEWAY_KEEPALIVE_INTERVAL_MS = 3000;
25
+ const GATEWAY_KEEPWARM_WINDOW_MS = 10 * 60 * 1000;
26
+ let lastActivityAt = 0;
27
+
28
+ function markActivity() {
29
+ lastActivityAt = Date.now();
30
+ }
31
+
18
32
  // ensureSidecarIdentity generates the local token once and persists it so the
19
33
  // OS service, the launcher, and the running client all agree on a stable
20
34
  // token/port across restarts and node upgrades. Random-per-run tokens broke
@@ -79,9 +93,35 @@ export async function startSidecar(options = {}) {
79
93
  server.listen(port, AURORA_LOCALHOST, async () => {
80
94
  await writeSidecarInfo({ port, token, baseURL: `http://${AURORA_LOCALHOST}:${port}` });
81
95
  console.error(`Aurora sidecar listening on http://${AURORA_LOCALHOST}:${port}`);
96
+ // Open the warm window and pre-warm the gateway connection so the very
97
+ // first client request reuses an established TLS socket.
98
+ markActivity();
99
+ startGatewayKeepAlive();
82
100
  });
83
101
  }
84
102
 
103
+ function startGatewayKeepAlive() {
104
+ const beat = async () => {
105
+ if (Date.now() - lastActivityAt > GATEWAY_KEEPWARM_WINDOW_MS) return;
106
+ try {
107
+ const state = await readState();
108
+ const gatewayURL = trimSlash(state.gatewayURL ?? "https://auroramos.com");
109
+ // Same origin as proxyRuntime → same undici pool, so this keeps the edge
110
+ // TLS handshake amortized for real requests. The body MUST be drained:
111
+ // undici destroys (does not pool) a connection whose response body was
112
+ // left unconsumed, which silently defeats the warm-up. Result ignored.
113
+ const response = await fetch(gatewayURL, { signal: AbortSignal.timeout(GATEWAY_HEADER_TIMEOUT_MS) });
114
+ await response.text();
115
+ } catch {
116
+ // Best effort; a failed heartbeat just means the next real request pays
117
+ // a cold handshake, which is the pre-fix behaviour.
118
+ }
119
+ };
120
+ const timer = setInterval(beat, GATEWAY_KEEPALIVE_INTERVAL_MS);
121
+ timer.unref();
122
+ beat();
123
+ }
124
+
85
125
  async function pingLocalSidecar(port, token) {
86
126
  try {
87
127
  const response = await fetch(`http://${AURORA_LOCALHOST}:${port}/aurora/status`, {
@@ -134,6 +174,7 @@ async function handle(request, response, token) {
134
174
  }
135
175
 
136
176
  async function proxyModels(response, incomingURL) {
177
+ markActivity();
137
178
  const state = await readState();
138
179
  const gatewayURL = trimSlash(state.gatewayURL ?? "https://auroramos.com");
139
180
  const clientVersion = incomingURL.searchParams.get("client_version");
@@ -159,6 +200,7 @@ async function proxyModels(response, incomingURL) {
159
200
  }
160
201
 
161
202
  async function proxyRuntime(request, response, path) {
203
+ markActivity();
162
204
  const state = await readState();
163
205
  const body = await readBody(request);
164
206
  const capabilitiesByAlias = await readCodexModelCapabilities();