codex-agent-view 0.3.2 → 0.4.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.
@@ -126,6 +126,19 @@ export async function startMonitorServer({
126
126
  return;
127
127
  }
128
128
 
129
+ if (
130
+ request.method === "POST" &&
131
+ requestUrl.pathname === "/api/internal/shutdown"
132
+ ) {
133
+ response.once("finish", () => {
134
+ queueMicrotask(() => {
135
+ void close().catch(() => {});
136
+ });
137
+ });
138
+ sendJson(response, 202, { status: "shutting_down" });
139
+ return;
140
+ }
141
+
129
142
  const asset = request.method === "GET" ? STATIC_FILES.get(requestUrl.pathname) : null;
130
143
  if (asset) {
131
144
  const body = await readFile(fileURLToPath(asset.url));
@@ -181,16 +194,19 @@ export async function startMonitorServer({
181
194
  throw error;
182
195
  }
183
196
 
184
- let closed = false;
197
+ let closePromise = null;
185
198
  async function close() {
186
- if (closed) {
187
- return;
199
+ if (closePromise) {
200
+ return closePromise;
188
201
  }
189
- closed = true;
190
- await new Promise((resolve, reject) => {
191
- server.close((error) => (error ? reject(error) : resolve()));
192
- });
193
- await removeRuntimeInfo(token, env);
202
+ closePromise = (async () => {
203
+ await new Promise((resolve, reject) => {
204
+ server.close((error) => (error ? reject(error) : resolve()));
205
+ server.closeIdleConnections?.();
206
+ });
207
+ await removeRuntimeInfo(token, env);
208
+ })();
209
+ return closePromise;
194
210
  }
195
211
 
196
212
  return {