impel-cli 0.18.8 → 0.18.10
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 +1 -1
- package/src/commands/doctor.js +0 -1
- package/src/commands/pat.js +2 -1
- package/src/commands/sessions.js +1 -1
- package/src/http1.js +52 -0
- package/src/sessionCollector.js +3 -5
- package/src/tenants.js +2 -1
package/package.json
CHANGED
package/src/commands/doctor.js
CHANGED
package/src/commands/pat.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
PAT_SCOPE_CODEX,
|
|
13
13
|
PAT_SCOPE_TASKS,
|
|
14
14
|
} from "../tenants.js";
|
|
15
|
+
import { fetchHttp1 } from "../http1.js";
|
|
15
16
|
import { RUNTIME_BRAND } from "../runtimeBrand.js";
|
|
16
17
|
|
|
17
18
|
const AGENT_PAT_LABEL_PREFIX = "Agent · ";
|
|
@@ -267,7 +268,7 @@ async function requestControlPlane({ appUrl, currentPat, path, method, body, fea
|
|
|
267
268
|
const timeout = setTimeout(() => controller.abort(), 10_000);
|
|
268
269
|
let response;
|
|
269
270
|
try {
|
|
270
|
-
response = await
|
|
271
|
+
response = await fetchHttp1(new URL(path, appUrl), {
|
|
271
272
|
method,
|
|
272
273
|
headers: {
|
|
273
274
|
accept: "application/json",
|
package/src/commands/sessions.js
CHANGED
|
@@ -21,7 +21,7 @@ import { brandedEnvironmentName, RUNTIME_BRAND } from "../runtimeBrand.js";
|
|
|
21
21
|
const MANAGED_SESSION_HOOK_FLAG = `${RUNTIME_BRAND.cli.command}-managed-session-hook-v1`;
|
|
22
22
|
|
|
23
23
|
function environmentValue(suffix) {
|
|
24
|
-
return process.env[brandedEnvironmentName(suffix)]
|
|
24
|
+
return process.env[brandedEnvironmentName(suffix)];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const SPEC = {
|
package/src/http1.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import https from "node:https";
|
|
3
|
+
|
|
4
|
+
const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
5
|
+
|
|
6
|
+
// Node 26's bundled Undici negotiates HTTP/2 automatically. Some ALB/Lambda
|
|
7
|
+
// response paths reject that stream before an HTTP status is delivered. CLI
|
|
8
|
+
// control-plane calls are small JSON exchanges, so use the stable HTTP/1.1
|
|
9
|
+
// transport explicitly without changing inference or streaming traffic.
|
|
10
|
+
export function fetchHttp1(input, init = {}) {
|
|
11
|
+
const url = input instanceof URL ? input : new URL(input);
|
|
12
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
13
|
+
return Promise.reject(new TypeError(`unsupported protocol ${url.protocol}`));
|
|
14
|
+
}
|
|
15
|
+
const transport = url.protocol === "https:" ? https : http;
|
|
16
|
+
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const request = transport.request(url, {
|
|
19
|
+
method: init.method || "GET",
|
|
20
|
+
headers: { "user-agent": "impel-cli", ...init.headers },
|
|
21
|
+
signal: init.signal,
|
|
22
|
+
...(url.protocol === "https:" ? { ALPNProtocols: ["http/1.1"] } : {}),
|
|
23
|
+
}, (response) => {
|
|
24
|
+
const chunks = [];
|
|
25
|
+
let size = 0;
|
|
26
|
+
response.on("data", (chunk) => {
|
|
27
|
+
size += chunk.length;
|
|
28
|
+
if (size > MAX_RESPONSE_BYTES) {
|
|
29
|
+
request.destroy(new Error("control-plane response exceeded 2 MiB"));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
chunks.push(chunk);
|
|
33
|
+
});
|
|
34
|
+
response.on("error", reject);
|
|
35
|
+
response.on("end", () => {
|
|
36
|
+
const body = Buffer.concat(chunks).toString("utf8");
|
|
37
|
+
const status = response.statusCode || 0;
|
|
38
|
+
resolve({
|
|
39
|
+
ok: status >= 200 && status < 300,
|
|
40
|
+
status,
|
|
41
|
+
statusText: response.statusMessage || "",
|
|
42
|
+
headers: response.headers,
|
|
43
|
+
async json() { return JSON.parse(body); },
|
|
44
|
+
async text() { return body; },
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
request.on("error", reject);
|
|
49
|
+
if (init.body !== undefined) request.write(init.body);
|
|
50
|
+
request.end();
|
|
51
|
+
});
|
|
52
|
+
}
|
package/src/sessionCollector.js
CHANGED
|
@@ -24,9 +24,7 @@ const SAFE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u;
|
|
|
24
24
|
const TASK_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
25
25
|
|
|
26
26
|
function brandedEnvironmentValue(suffix) {
|
|
27
|
-
|
|
28
|
-
if (branded !== undefined) return branded;
|
|
29
|
-
return process.env[`IMPEL_${suffix}`];
|
|
27
|
+
return process.env[brandedEnvironmentName(suffix)];
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
function stateRoot() {
|
|
@@ -509,7 +507,7 @@ function repositoryMetadata(cwd) {
|
|
|
509
507
|
};
|
|
510
508
|
}
|
|
511
509
|
|
|
512
|
-
function
|
|
510
|
+
export function resolveSessionsUrl(config) {
|
|
513
511
|
return String(
|
|
514
512
|
brandedEnvironmentValue("SESSIONS_URL")
|
|
515
513
|
|| config?.sessionsUrl
|
|
@@ -545,7 +543,7 @@ async function apiRequest(config, tenantId, route, options = {}) {
|
|
|
545
543
|
const controller = new AbortController();
|
|
546
544
|
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
547
545
|
try {
|
|
548
|
-
const response = await fetch(`${
|
|
546
|
+
const response = await fetch(`${resolveSessionsUrl(config)}${route}`, {
|
|
549
547
|
...options,
|
|
550
548
|
headers: requestHeaders(config, tenantId, options.headers),
|
|
551
549
|
signal: controller.signal,
|
package/src/tenants.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
resolveDefaultAppUrl,
|
|
5
5
|
saveConfig,
|
|
6
6
|
} from "./config.js";
|
|
7
|
+
import { fetchHttp1 } from "./http1.js";
|
|
7
8
|
import { RUNTIME_BRAND } from "./runtimeBrand.js";
|
|
8
9
|
|
|
9
10
|
export const TENANT_CREDENTIAL_PREFIX = RUNTIME_BRAND.auth.tenantPrefix;
|
|
@@ -93,7 +94,7 @@ export function tenantCredential(pat, tenantId) {
|
|
|
93
94
|
return `${TENANT_CREDENTIAL_PREFIX}${encodedTenant}.${pat}`;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
export async function fetchTenants(config, fetchImpl =
|
|
97
|
+
export async function fetchTenants(config, fetchImpl = fetchHttp1) {
|
|
97
98
|
if (!config?.pat) throw new Error(`not authenticated; run \`${RUNTIME_BRAND.cli.command} setup\` (or \`${RUNTIME_BRAND.cli.command} auth\`) first`);
|
|
98
99
|
const appUrl = normalizeGatewayUrl(config.appUrl || resolveDefaultAppUrl());
|
|
99
100
|
const controller = new AbortController();
|