@agentskit/net

中文文档
0.2.4发布于 2026/10/24MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2.6万

Resilient, bounded and SSRF-safe HTTP for the AgentsKit ecosystem: retry with Retry-After, timeouts, size-limited bodies, SSE parsing and private-address checks. Runs in Node, Bun, Deno, browsers and edge.

原始使用文档
文档目录12 节
  1. Verified proof
  2. How this fits the ecosystem
  3. Install
  4. Quick example
  5. Features
  6. Cancellable waits and deadlines
  7. Ecosystem
  8. Contributors
  9. License
  10. Docs
  11. Maturity and compatibility
  12. Contributing

@agentskit/net

Profile: concise-package

AgentsKit

HTTP plumbing for agents, in one small package: retries with backoff and Retry-After, per-attempt timeouts, bounded body reads, server-sent events, and SSRF address checks. Web APIs only, so it runs on Node, Bun, Deno, browsers and edge runtimes.

npm version npm downloads bundle size license stability GitHub stars

Tags: agentskit · ai-agents · fetch · retry · sse · ssrf · timeout · edge

Verified proof

How this fits the ecosystem

Adapters, tools and the other AgentsKit repositories each carried their own retry loop, Retry-After parsing, SSE line splitter and private-IP check, with different bugs in each. @agentskit/net owns them, built on eventsource-parser and ipaddr.js, so callers import one tested implementation.

  • AgentsKit: @agentskit/adapters (streaming, retries) and @agentskit/tools (fetching user-supplied URLs) are the intended consumers.
  • Registry: ready agents and templates at registry.agentskit.io.
  • Playbook: production patterns at playbook.agentskit.io.

Docs: package guide · agent handoff

Install

npm install @agentskit/net

Quick example

import { assertPublicUrl, fetchWithRetry, parseSSEResponse, readJson } from '@agentskit/net'

// Refuse private, loopback and metadata addresses before fetching a user-supplied URL.
const { url } = await assertPublicUrl('https://api.example.com/v1/models')

// Idempotent requests retry on 429/5xx, honouring Retry-After; each attempt times out.
const models = await readJson(await fetchWithRetry(url, undefined, { timeoutMs: 10_000 }), {
  maxBytes: 1_000_000,
})
console.log(models)

// Server-sent events as an async iterable.
const stream = await fetch('https://api.example.com/v1/stream', { method: 'POST' })
for await (const event of parseSSEResponse(stream)) {
  if (event.data === '[DONE]') break
  console.log(event.event ?? 'message', event.data)
}

Features

AreaAPIReplaces
Retryretry, computeBackoff, parseRetryAfter, isRetryableStatus, RETRYABLE_STATUSEShand-written for loops with fixed sleeps, ignored Retry-After
FetchfetchWithRetryretrying POSTs twice, leaking discarded response bodies, timeouts that span all attempts
TimeoutstimeoutSignal, anySignal, withTimeoutsetTimeout + AbortController boilerplate
BodiesreadBody, readText, readJsonawait res.text() on an unbounded response
SSEparseSSE, parseSSEResponsesplit('\n') + startsWith('data: ') parsers that break on CRLF, multi-line data and chunk boundaries
AddressesassertPublicUrl, isPublicAddress, classifyAddressregexes over 127./10./192.168. that miss IPv6, IPv4-mapped and metadata addresses
  • Idempotent by default: fetchWithRetry retries GET/HEAD/OPTIONS/PUT/DELETE/TRACE; pass retryMethods: 'all' to opt in for POST. Streaming bodies are never retried.

  • Typed errors: NetError with AK_NET_TIMEOUT, AK_NET_BODY_TOO_LARGE, AK_NET_BLOCKED_ADDRESS, AK_NET_INVALID_INPUT, AK_NET_SSE_PARSE_FAILED.

  • DNS is injected: assertPublicUrl takes a lookup function, so the package has no node: imports. Checking before connecting does not stop DNS rebinding; pin the resolved address when that matters.

  • Built on: eventsource-parser, ipaddr.js.

  • Guardrail rules: NET_RULES (readonly NetRule[]) from @agentskit/net/rules detects duplicate HTTP retry, SSE, timeout, address and body handling. Add @agentskit/cross-platform as a dev dependency to run its scanner; pass NET_RULES to scanText(file, source, rules) or scanRepository(options). Both return findings that compareToBaseline(findings, baseline) ratchets. Use <id>-ignore: <reason> for an approved one-rule suppression, for example net-retry-after-ignore: legacy retry handler. The repository check is node scripts/check-net-rules.mjs.

    import { NET_RULES } from '@agentskit/net/rules'
    import { scanText } from '@agentskit/cross-platform'
    
    const findings = scanText('src/http.ts', 'const body = await response.text()', NET_RULES)
    console.log(findings.length)
    

Cancellable waits and deadlines

sleep(ms, signal?) accepts delays from 0 through 2,147,483,647 milliseconds. It uses an abortable timer by default, clears that timer on abort, and rejects with the signal's actual reason. retry uses this public helper by default; its optional sleep callback has the shape (ms, signal?) => Promise<void>. A one-argument callback remains compatible; callbacks that need prompt cancellation should honor the optional signal.

withTimeout(work, ms, parent?) accepts positive deadlines through 2,147,483,647 milliseconds and passes work a signal that aborts on the deadline or when the parent signal aborts. An elapsed deadline rejects with NetError code AK_NET_TIMEOUT; an invalid timeout rejects with AK_NET_INVALID_INPUT. A caller abort preserves its exact reason, and success or an original work failure passes through unchanged. The wrapper rejects on time even if work ignores the signal, but only cooperative work such as fetch can be stopped; arbitrary JavaScript cannot be forcibly cancelled.

import { retry, sleep, withTimeout } from '@agentskit/net'

const parent = new AbortController()
const response = await withTimeout(
  signal => fetch('https://api.example.com/data', { signal }),
  5_000,
  parent.signal,
)

await retry(async () => fetch('https://api.example.com/retry'), {
  sleep: (ms, signal) => sleep(ms, signal),
})

Ecosystem

PackageRole
@agentskit/coreAgentsKitError, the base of NetError
@agentskit/adaptersProvider streaming and retries
@agentskit/toolsFetching user-supplied URLs safely

Contributors

AgentsKit contributors

License

MIT — see LICENSE.

Docs

Full documentation · GitHub

Maturity and compatibility

  • Stability: beta — see docs/STABILITY.md. Not 1.0.
  • Node.js 20+ (20.19+), Bun, Deno, modern browsers and edge runtimes; TypeScript strict mode
  • Published as @agentskit/net

Contributing

See CONTRIBUTING.md and the monorepo LICENSE.

版本与发布记录

@agentskit/net 共发布 7 个版本,首次发布于 2026/09/28;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.4latest2026/10/2412 天前
0.2.32026/10/1026 天前
0.2.22026/10/031 个月前
0.2.12026/10/031 个月前
0.2.02026/10/021 个月前
0.1.02026/09/291 个月前

其他发布通道:bootstrap → 0.0.0。

关于 @agentskit/net 的常见问题

@agentskit/net 是什么?

Resilient, bounded and SSRF-safe HTTP for the AgentsKit ecosystem: retry with Retry-After, timeouts, size-limited bodies, SSE parsing and private-address checks. Runs in Node, Bun, Deno, browsers and edge.

如何安装 @agentskit/net?

在项目目录运行 npm install @agentskit/net,或使用 pnpm add / yarn add / bun add。

@agentskit/net 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agentskit/net 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@agentskit/net 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.19。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@agentskit/net 可以商用吗?

@agentskit/net 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agentskit/net 的下载量有多少?

根据 npm 官方下载统计,@agentskit/net 在 2026/10/05 – 2026/11/03 这 30 天内被下载 25,864 次,日均约 862 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agentskit/net 还在维护吗?

最新版本 0.2.4 发布于 2026/10/24(12 天前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/09/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。