import { type ResultFailure } from "../runtime/result.js"; import type { RuntimeContext } from "../runtime/state/context.js"; import type { StateStack } from "../runtime/state/stateStack.js"; import type { ThreadStore } from "../runtime/state/threadStore.js"; /** How long a fetch may take, headers and body together, when the caller * names no limit. */ export declare const DEFAULT_FETCH_TIMEOUT_MS = 30000; /** * Read a response body into bytes with a hard size cap and abort safety. On * abort we cancel the reader to unblock the pending `read()`, then * `throwIfAborted()` turns that into an `AbortError` rather than resolving to the * partial prefix. The cap and abort policy live here once; the text reader and * the AWS pipeline both decode this primitive. */ export declare function readBodyBytesCapped(response: Response, url: string, signal: AbortSignal): Promise; /** Collapse whitespace and truncate a response body into a failure snippet. */ export declare function normalizeSnippet(body: string, max?: number): string; /** * Run an HTTP request, translating any abort-shaped error into the * runtime's `AgencyCancelledError`. Node's `fetch` surfaces an * aborted request as a `DOMException` with `name === "AbortError"`, * which `isAbortError` matches. Translating to `AgencyCancelledError` * lets `__tryCall` re-throw it (alongside `GuardExceededError`) so * the agency-side `try` wrapper doesn't silently convert it into a * `Failure` value — the cancellation propagates to the runner the * same way an aborted LLM call does. * * Exported so other stdlib JS modules that do their own `fetch` * (oauth.ts token exchange, speech.ts whisper upload, browserUse.ts * session creation/polling) can share the same abort-error translation * without each one re-implementing it. Each caller still has to thread * the `AbortSignal` from `ctx.getAbortSignal(stack)` into its `fetch` * call — this helper only handles the catch side. `signal` is that same * signal, read here only to recover the abort cause. `timeoutMs` is the * limit the signal carries, named in the failure when it is what fired. */ export declare function runHttp(fn: () => Promise, url: string, signal: AbortSignal | undefined, timeoutMs?: number): Promise; /** Deprecated context-injected wrapper kept during the ALS migration; * see `_fetch`. */ export declare function __internal_fetch(ctx: RuntimeContext, stack: StateStack, _threads: ThreadStore, baseUrl: string, urlPath: string, headers: Record, allowedDomains: string[], method?: string, body?: any, timeoutMs?: number): Promise; /** * The stored result a fetch tool returns instead of fetching, when this * conversation already fetched the URL, or null when the fetch should * run. Called by the Agency fetch functions before they raise their * interrupt, so a cache hit asks no one. `tool` is the function's name, * for the record. See lib/runtime/fetchCache.ts. */ export declare function _cachedFetch(baseUrl: string, urlPath: string, method: string, body: unknown, headers: Record, refresh: boolean, tool: string): { value: unknown; } | null; /** ALS-reading replacement for `__internal_fetch`. */ export declare function _fetch(baseUrl: string, urlPath: string, headers: Record, allowedDomains: string[], method: string, body: any, timeoutMs?: number): Promise; /** Deprecated; see `_fetchJSON`. */ export declare function __internal_fetchJSON(ctx: RuntimeContext, stack: StateStack, _threads: ThreadStore, baseUrl: string, urlPath: string, headers: Record, allowedDomains: string[], method?: string, body?: any, timeoutMs?: number): Promise; /** ALS-reading replacement for `__internal_fetchJSON`. */ export declare function _fetchJSON(baseUrl: string, urlPath: string, headers: Record, allowedDomains: string[], method: string, body: any, timeoutMs?: number): Promise; /** Deprecated; see `_fetchMarkdown`. */ export declare function __internal_fetchMarkdown(ctx: RuntimeContext, stack: StateStack, _threads: ThreadStore, baseUrl: string, urlPath: string, headers: Record, allowedDomains: string[], method?: string, body?: any, timeoutMs?: number): Promise; /** ALS-reading replacement for `__internal_fetchMarkdown`. */ export declare function _fetchMarkdown(baseUrl: string, urlPath: string, headers: Record, allowedDomains: string[], method: string, body: any, timeoutMs?: number): Promise; export declare function resolveUrl(baseUrl: string, path: string): string; /** Where a request goes, as two plain words a policy rule can match: * the URL's scheme, and whether the host is on the public internet or * on this machine or its network. `network` is "local" for loopback, * unspecified, link-local, private, and carrier-grade NAT addresses * (IPv4 and IPv6, an IPv4 address inside IPv6 included) and for * `localhost`, `.localhost`, and `.local` names, with or without a * trailing dot; "public" for any * other host; "unknown" when the string is not a URL. A rule that * approves a read of the web says `scheme: "https", network: "public"`, * which keeps a local admin page or the cloud metadata address out of * its reach (docs/dev/agents/approval-policies.md). Names are judged as * written, not resolved: a public name that resolves to a private * address is not caught here. */ export type FetchTarget = { scheme: string; network: "public" | "local" | "unknown"; }; export declare function _fetchTarget(baseUrl: string, urlPath: string): FetchTarget; export declare function networkOf(hostname: string): "public" | "local"; export declare function checkAllowedDomains(url: string, allowedDomains: string[]): string | null;