@humain/terminal 0.1.1 → 0.2.2
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/CHANGELOG.md +22 -0
- package/dist/bundle/chunks/{anthropic-messages-XULXUBIG.js → anthropic-messages-QFCEKGI3.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-JEG2XOYC.js → azure-openai-responses-G4ZMHV37.js} +1 -1
- package/dist/bundle/chunks/chunk-7T6XCLJF.js +22 -0
- package/dist/bundle/chunks/{chunk-LYAMSPR2.js → chunk-ADQYVZ6A.js} +483 -506
- package/dist/bundle/chunks/chunk-D6HHRSB5.js +103 -0
- package/dist/bundle/chunks/{chunk-JUPSJTFQ.js → chunk-K4JAZYQH.js} +1 -1
- package/dist/bundle/chunks/{chunk-HPPQHK3J.js → chunk-KKIB2TVR.js} +1 -1
- package/dist/bundle/chunks/chunk-LI2YVPWP.js +2 -0
- package/dist/bundle/chunks/chunk-NMPIM7MN.js +2 -0
- package/dist/bundle/chunks/{chunk-BZQ53VGE.js → chunk-XSR434CO.js} +1 -1
- package/dist/bundle/chunks/compat-CN7WN6DA.js +2 -0
- package/dist/bundle/chunks/dist-PRPIUY3U.js +2 -0
- package/dist/bundle/chunks/esm-E7UVEYTO.js +4 -0
- package/dist/bundle/chunks/{extract-TRW5FBY6.js → extract-CTIFQZDJ.js} +15 -14
- package/dist/bundle/chunks/{google-generative-ai-OX6VSCA6.js → google-generative-ai-RSUU4MWO.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-GW76GSS2.js → google-vertex-CKQPOITO.js} +1 -1
- package/dist/bundle/chunks/host-WP3MVKS2.js +2 -0
- package/dist/bundle/chunks/{node-KOIP55YZ.js → node-NF43OPII.js} +1 -1
- package/dist/bundle/chunks/{node-XY3CBY3C.js → node-UMFM7CDZ.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-NPLWP6ZC.js → openai-codex-responses-S34V5ZSD.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-OT2GTJKC.js → openai-completions-T2IGVUEI.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-5A6CR7GI.js → openai-responses-GYZODCT3.js} +1 -1
- package/dist/bundle/chunks/readability-LAGF34IB.js +3 -0
- package/dist/bundle/chunks/turndown.cjs-HRMZVRUL.js +2 -0
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/model-runtime.d.ts +21 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +34 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +21 -8
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/subagent-env.d.ts +20 -0
- package/dist/core/tools/subagent-env.d.ts.map +1 -0
- package/dist/core/tools/subagent-env.js +47 -0
- package/dist/core/tools/subagent-env.js.map +1 -0
- package/dist/core/tools/subagent-scheduler.d.ts +36 -0
- package/dist/core/tools/subagent-scheduler.d.ts.map +1 -0
- package/dist/core/tools/subagent-scheduler.js +213 -0
- package/dist/core/tools/subagent-scheduler.js.map +1 -0
- package/dist/core/tools/subagent.d.ts +83 -3
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +215 -76
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +78 -0
- package/dist/humain/mcp-adapter/vendor/README.md +125 -19
- package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +69 -30
- package/dist/humain/mcp-adapter/vendor/agent-plugin-provenance.ts +36 -0
- package/dist/humain/mcp-adapter/vendor/claude-plugin-loader.ts +365 -0
- package/dist/humain/mcp-adapter/vendor/commands.ts +13 -15
- package/dist/humain/mcp-adapter/vendor/config.ts +198 -30
- package/dist/humain/mcp-adapter/vendor/consent-manager.ts +40 -9
- package/dist/humain/mcp-adapter/vendor/direct-tool-surface.ts +250 -0
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +9 -228
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js +74 -32
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.d.ts +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.js +31 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.d.ts +9 -0
- package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.js +362 -0
- package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/config.d.ts +3 -1
- package/dist/humain/mcp-adapter/vendor/dist/config.js +189 -27
- package/dist/humain/mcp-adapter/vendor/dist/config.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js +7 -16
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js +5 -17
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/types.d.ts +30 -4
- package/dist/humain/mcp-adapter/vendor/dist/types.js +26 -0
- package/dist/humain/mcp-adapter/vendor/dist/types.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/utils.d.ts +6 -0
- package/dist/humain/mcp-adapter/vendor/dist/utils.js +65 -6
- package/dist/humain/mcp-adapter/vendor/dist/utils.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/host-html-template.ts +20 -19
- package/dist/humain/mcp-adapter/vendor/http-ca.ts +84 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +37102 -15103
- package/dist/humain/mcp-adapter/vendor/index.ts +828 -164
- package/dist/humain/mcp-adapter/vendor/init.ts +48 -10
- package/dist/humain/mcp-adapter/vendor/lazy-loader.ts +7 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-fetch.ts +113 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +256 -77
- package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +316 -54
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +45 -18
- package/dist/humain/mcp-adapter/vendor/mcp-install.ts +60 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +70 -6
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +53 -42
- package/dist/humain/mcp-adapter/vendor/mcp-panel-theme.ts +105 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +366 -331
- package/dist/humain/mcp-adapter/vendor/mcp-references.ts +9 -14
- package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +3 -1
- package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +383 -341
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +5 -0
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +7 -16
- package/dist/humain/mcp-adapter/vendor/namespace-tools.ts +61 -3
- package/dist/humain/mcp-adapter/vendor/oauth.ts +6 -2
- package/dist/humain/mcp-adapter/vendor/package-mcp-loader.ts +5 -17
- package/dist/humain/mcp-adapter/vendor/package.json +13 -3
- package/dist/humain/mcp-adapter/vendor/prompts.ts +35 -3
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +108 -7
- package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +16 -1
- package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +9 -32
- package/dist/humain/mcp-adapter/vendor/sandbox-proxy-template.ts +20 -93
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +227 -40
- package/dist/humain/mcp-adapter/vendor/session-approvals.ts +187 -0
- package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +9 -1
- package/dist/humain/mcp-adapter/vendor/state.ts +10 -1
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +10 -22
- package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +14 -0
- package/dist/humain/mcp-adapter/vendor/types.ts +57 -4
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +36 -28
- package/dist/humain/mcp-adapter/vendor/utils.ts +64 -6
- package/dist/humain/web-access/vendor/abortable.d.ts +3 -0
- package/dist/humain/web-access/vendor/abortable.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/abortable.js +22 -0
- package/dist/humain/web-access/vendor/abortable.js.map +1 -0
- package/dist/humain/web-access/vendor/crawl4ai.d.ts +9 -0
- package/dist/humain/web-access/vendor/crawl4ai.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/crawl4ai.js +187 -0
- package/dist/humain/web-access/vendor/crawl4ai.js.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.js +1 -0
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +20 -2
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-run.d.ts +11 -0
- package/dist/humain/web-access/vendor/curator-run.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-run.js +38 -0
- package/dist/humain/web-access/vendor/curator-run.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +58 -11
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +2 -2
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +12 -5
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +23 -19
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.js +40 -14
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +6 -2
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +6 -2
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.d.ts +4 -0
- package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpapi.js +215 -0
- package/dist/humain/web-access/vendor/serpapi.js.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +5 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/storage.js +9 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +35 -24
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +5 -3
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/modes/json-event.d.ts +8 -0
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +17 -0
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +3 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/docs/environment-variables.md +9 -0
- package/docs/json.md +16 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/src/humain/mcp-adapter/UPSTREAM.md +56 -7
- package/src/humain/mcp-adapter/upstream.json +6 -4
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +78 -0
- package/src/humain/web-access/UPSTREAM.md +18 -8
- package/src/humain/web-access/upstream.json +6 -5
- package/dist/bundle/chunks/chunk-2LC3S3VV.js +0 -105
|
@@ -8,7 +8,6 @@ const APP_INNER_SANDBOX = APP_PROXY_SANDBOX;
|
|
|
8
8
|
|
|
9
9
|
export interface HostHtmlTemplateInput {
|
|
10
10
|
sessionToken: string;
|
|
11
|
-
uiResourceToken: string;
|
|
12
11
|
serverName: string;
|
|
13
12
|
toolName: string;
|
|
14
13
|
toolArgs: Record<string, unknown>;
|
|
@@ -25,7 +24,6 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
25
24
|
const hostContext = input.hostContext ?? {};
|
|
26
25
|
|
|
27
26
|
const sessionToken = safeInlineJSON(input.sessionToken);
|
|
28
|
-
const uiResourceToken = safeInlineJSON(input.uiResourceToken);
|
|
29
27
|
const toolArgs = safeInlineJSON(input.toolArgs);
|
|
30
28
|
const serverName = safeInlineJSON(input.serverName);
|
|
31
29
|
const toolName = safeInlineJSON(input.toolName);
|
|
@@ -136,7 +134,6 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
136
134
|
import { AppBridge, PostMessageTransport } from ${moduleUrl};
|
|
137
135
|
|
|
138
136
|
const SESSION_TOKEN = ${sessionToken};
|
|
139
|
-
const UI_RESOURCE_TOKEN = ${uiResourceToken};
|
|
140
137
|
const SERVER_NAME = ${serverName};
|
|
141
138
|
const TOOL_NAME = ${toolName};
|
|
142
139
|
const TOOL_ARGS = ${toolArgs};
|
|
@@ -231,24 +228,19 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
231
228
|
);
|
|
232
229
|
|
|
233
230
|
let sandboxResourceSent = false;
|
|
234
|
-
bridge.onsandboxready =
|
|
231
|
+
bridge.onsandboxready = () => {
|
|
235
232
|
if (sandboxResourceSent) return;
|
|
236
233
|
sandboxResourceSent = true;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
sandbox: INNER_SANDBOX,
|
|
246
|
-
...(RESOURCE_CSP ? { csp: RESOURCE_CSP } : {}),
|
|
247
|
-
...(RESOURCE_PERMISSIONS ? { permissions: RESOURCE_PERMISSIONS } : {}),
|
|
248
|
-
});
|
|
249
|
-
} catch (error) {
|
|
234
|
+
void bridge.sendSandboxResourceReady({
|
|
235
|
+
// The proxy performs a normal HTTP navigation to its session-bound
|
|
236
|
+
// resource route. Provider HTML never crosses this trusted document.
|
|
237
|
+
html: "",
|
|
238
|
+
sandbox: INNER_SANDBOX,
|
|
239
|
+
...(RESOURCE_CSP ? { csp: RESOURCE_CSP } : {}),
|
|
240
|
+
...(RESOURCE_PERMISSIONS ? { permissions: RESOURCE_PERMISSIONS } : {}),
|
|
241
|
+
}).catch((error) => {
|
|
250
242
|
showError("Failed to load MCP App resource: " + String(error));
|
|
251
|
-
}
|
|
243
|
+
});
|
|
252
244
|
};
|
|
253
245
|
|
|
254
246
|
bridge.oncalltool = async (params) => {
|
|
@@ -448,6 +440,15 @@ export function buildHostHtmlTemplate(input: HostHtmlTemplateInput): string {
|
|
|
448
440
|
}
|
|
449
441
|
|
|
450
442
|
export function buildCspMetaContent(csp: UiResourceCsp | undefined): string {
|
|
443
|
+
return buildCspContent(csp, APP_SANDBOX);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** CSP for provider HTML navigated on the isolated proxy origin. */
|
|
447
|
+
export function buildSandboxResourceCsp(csp: UiResourceCsp | undefined): string {
|
|
448
|
+
return buildCspContent(csp, APP_INNER_SANDBOX);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function buildCspContent(csp: UiResourceCsp | undefined, sandbox: string): string {
|
|
451
452
|
const resourceDomains = sanitizeCspDomains(csp?.resourceDomains);
|
|
452
453
|
const connectDomains = sanitizeCspDomains(csp?.connectDomains);
|
|
453
454
|
const frameDomains = sanitizeCspDomains(csp?.frameDomains);
|
|
@@ -455,7 +456,7 @@ export function buildCspMetaContent(csp: UiResourceCsp | undefined): string {
|
|
|
455
456
|
|
|
456
457
|
return [
|
|
457
458
|
"default-src 'none'",
|
|
458
|
-
`sandbox ${
|
|
459
|
+
`sandbox ${sandbox}`,
|
|
459
460
|
toDirective("script-src", ["'self'", "'unsafe-inline'"], resourceDomains),
|
|
460
461
|
toDirective("style-src", ["'self'", "'unsafe-inline'"], resourceDomains),
|
|
461
462
|
toDirective("font-src", ["'self'"], resourceDomains),
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { X509Certificate } from "node:crypto";
|
|
3
|
+
import { Agent, Request as UndiciRequest, fetch as undiciFetch } from "undici";
|
|
4
|
+
import type { RequestInit as UndiciRequestInit } from "undici";
|
|
5
|
+
import type { ServerEntry } from "./types.ts";
|
|
6
|
+
import { getMissingEnvVars, resolveConfigPath, resolveServerUrl } from "./utils.ts";
|
|
7
|
+
|
|
8
|
+
/** Validate at the connection boundary, including callers that bypass JSON config. */
|
|
9
|
+
export function validateCaFile(definition: ServerEntry): void {
|
|
10
|
+
if (definition.caFile === undefined) return;
|
|
11
|
+
if (typeof definition.caFile !== "string" || !definition.caFile.trim()) {
|
|
12
|
+
throw new Error("MCP caFile must be a non-empty path string");
|
|
13
|
+
}
|
|
14
|
+
if (definition.command !== undefined || definition.socket !== undefined
|
|
15
|
+
|| !definition.url || new URL(resolveServerUrl(definition)!).protocol !== "https:") {
|
|
16
|
+
throw new Error("MCP caFile is only supported for HTTPS HTTP servers");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** One connection owner, shared across transport/auth retries; never process-wide. */
|
|
21
|
+
export function createCaFetch(definition: ServerEntry): { fetch: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>; close: () => Promise<void> } | undefined {
|
|
22
|
+
validateCaFile(definition);
|
|
23
|
+
if (definition.caFile === undefined) return undefined;
|
|
24
|
+
const origin = new URL(resolveServerUrl(definition)!).origin;
|
|
25
|
+
if (getMissingEnvVars(definition.caFile).length) throw new Error("Missing environment variable in MCP caFile");
|
|
26
|
+
let ca: string;
|
|
27
|
+
try {
|
|
28
|
+
ca = readFileSync(resolveConfigPath(definition.caFile)!, "utf8");
|
|
29
|
+
const certificates = ca.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g);
|
|
30
|
+
if (!certificates?.length || ca.replace(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g, "").trim()) {
|
|
31
|
+
throw new Error("expected a PEM certificate bundle");
|
|
32
|
+
}
|
|
33
|
+
for (const certificate of certificates) new X509Certificate(certificate);
|
|
34
|
+
} catch (cause) {
|
|
35
|
+
throw new Error("Failed to load MCP caFile PEM certificate bundle", { cause });
|
|
36
|
+
}
|
|
37
|
+
const dispatcher = new Agent({ connect: { ca } });
|
|
38
|
+
let closed: Promise<void> | undefined;
|
|
39
|
+
return {
|
|
40
|
+
fetch: (input, init) => {
|
|
41
|
+
const url = new URL(input instanceof Request ? input.url : input.toString());
|
|
42
|
+
if (url.origin !== origin) return globalThis.fetch(input, init);
|
|
43
|
+
// The Agent comes from the bundled undici copy, whose internals do not
|
|
44
|
+
// match the global fetch dispatcher contract on newer Node releases
|
|
45
|
+
// (Node 26 ships undici v8; the dependency pins undici v6). Route
|
|
46
|
+
// same-origin requests through the bundled fetch so dispatcher and
|
|
47
|
+
// Agent share an implementation. Never follow a redirect with this
|
|
48
|
+
// dispatcher, even to the same origin (no trust-bearing redirect hops).
|
|
49
|
+
// Attach after header-command Request reconstruction.
|
|
50
|
+
try {
|
|
51
|
+
const bundledInput = input instanceof Request
|
|
52
|
+
? new UndiciRequest(input.url, {
|
|
53
|
+
method: input.method,
|
|
54
|
+
headers: [...input.headers],
|
|
55
|
+
// Defer acquiring the source stream until bundled Request validation
|
|
56
|
+
// succeeds. An overriding body never consumes the original body.
|
|
57
|
+
...(init?.body == null && input.body ? { body: (async function* () {
|
|
58
|
+
yield* input.body!;
|
|
59
|
+
})(), duplex: "half" as const } : {}),
|
|
60
|
+
cache: input.cache,
|
|
61
|
+
credentials: input.credentials,
|
|
62
|
+
integrity: input.integrity,
|
|
63
|
+
keepalive: input.keepalive,
|
|
64
|
+
mode: input.mode,
|
|
65
|
+
redirect: input.redirect,
|
|
66
|
+
referrer: input.referrer,
|
|
67
|
+
referrerPolicy: input.referrerPolicy,
|
|
68
|
+
signal: input.signal,
|
|
69
|
+
} as unknown as UndiciRequestInit)
|
|
70
|
+
: input;
|
|
71
|
+
const options = {
|
|
72
|
+
...init,
|
|
73
|
+
...(init?.headers !== undefined ? { headers: [...new Headers(init.headers)] } : {}),
|
|
74
|
+
dispatcher,
|
|
75
|
+
redirect: "error" as const,
|
|
76
|
+
} as unknown as UndiciRequestInit;
|
|
77
|
+
return undiciFetch(bundledInput, options) as unknown as Promise<Response>;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return Promise.reject(error);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
close: () => closed ??= dispatcher.destroy(),
|
|
83
|
+
};
|
|
84
|
+
}
|