impel-cli 0.18.8 → 0.18.9
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/pat.js +2 -1
- package/src/http1.js +52 -0
- package/src/tenants.js +2 -1
package/package.json
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/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/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();
|