@fabric-harness/sdk

中文文档
6.9.1发布于 2026/11/08Apache-2.0TypeScriptES Module近 30 天下载 1.1万

Headless TypeScript framework for building durable, deployable autonomous agents — core SDK.

原始使用文档
文档目录10 节
  1. Install
  2. Quick start
  3. Minimal — bare import, headless defaults (8 lines)
  4. Complete — same import, more fields
  5. With typed I/O + capability policy + skills (same import)
  6. Persistent agents that evolve
  7. One SDK, one import
  8. What's in the box
  9. Documentation
  10. License

@fabric-harness/sdk

Core SDK for TechFabric Harness — a headless TypeScript framework for building durable, deployable autonomous agents.

Install

npm install @fabric-harness/sdk
# or
pnpm add @fabric-harness/sdk

Quick start

Minimal — bare import, headless defaults (8 lines)

import { defineAgent } from '@fabric-harness/sdk';

export default defineAgent<{ message: string }>({
  name: 'echo',
  triggers: { webhook: true },
  run: async ({ init, input }) => {
    const session = await (await init({ model: 'openai/gpt-5.5' })).session();
    return { reply: await session.prompt<string>(input.message) };
  },
});

Complete — same import, more fields

With typed I/O + capability policy + skills (same import)

import { defineAgent, schema } from '@fabric-harness/sdk';

export default defineAgent({
  name: 'triage',
  input: schema.object({ issueNumber: schema.number(), title: schema.string() }),
  output: schema.object({ severity: schema.enum(['low','medium','high']), summary: schema.string() }),
  model: process.env.FABRIC_MODEL,
  run: async ({ init, input }) => {
    const session = await (await init()).session();
    return await session.prompt('Triage and return the typed result.');
  },
});

Both forms share the same init(), session.prompt() / skill() / task() / shell() APIs. Runtime (stateless, inline, or temporal) is a separate choice configured at init().

Persistent agents that evolve

createAgent() renders per interaction. Hooks let durable state change the current model, tools, skills, subagents, MCP connections, and sandbox without introducing another builder:

import { createAgent, useModel, usePersistentState, useTool } from '@fabric-harness/sdk';

export default createAgent(() => {
  const [level, setLevel] = usePersistentState('level', 0);
  useModel(level < 2 ? 'anthropic/claude-haiku-4-5' : 'anthropic/claude-sonnet-4-6');
  useTool({ name: 'advance', durable: true, run: async ({ step }) => {
    const receipt = await step.do('advance', async () => ({ advanced: true }));
    setLevel((value) => value + 1);
    return receipt;
  }});
  if (level >= 1) useTool(advancedAnalysis);
  return `Current capability level: ${level}.`;
});

One SDK, one import

@fabric-harness/sdk is the single import everyone uses. defineAgent({...}) from the bare import auto-injects headless defaults (runtime: 'stateless', sandbox: 'virtual', loopRuntime: pi-agent-core, compaction: { enabled: true }) on every init() call. Override any of them by passing values to init(). Add typed input/output schemas, policy, artifacts, custom stores, telemetry — they're all options on the same defineAgent({...})/init() shape.

For Temporal-backed durable agents or compliance workloads where no implicit behaviour is wanted, use @fabric-harness/sdk/strict — same call shape, no defaults injected.

Runtime (stateless, inline, or temporal) controls persistence and durability and is configured at init(). The deploy target (node, temporal-worker, docker, cloudflare, …) is chosen via fh build --target.

What's in the box

  • init({ model, sandbox, policy, runtime, sessionRuntime, ... }) — initialize an agent runtime.
  • session.prompt / skill / task / shell — the four agent operations.
  • session.mount(mountAt, source, { mode }) — mount a FilesystemSource into the sandbox at runtime. Read-only by default; writes under the mount are blocked at the policy layer.
  • session.approval.request({ reason, risk?, timeoutMs? }) — custom approval gate. Returns true on approval; throws APPROVAL_DENIED / APPROVAL_REQUIRED on denial / timeout.
  • ApprovalResponse.grant — durable approved responses carry the call/input/principal-bound grant; denied responses never do.
  • defineAgent({...}) — single builder. Same call shape from the bare @fabric-harness/sdk import and from @fabric-harness/sdk/strict; the import you choose controls whether headless defaults are injected at runtime.
  • createAgent() hooks — compose persistent state, delivery and initial data, dynamic resources, lifecycle guards, response metadata/data parts, durable tool steps, MCP, and subagents.
  • defineCommand — bind a privileged CLI (gh, npm, …) with secrets at the command level, never in model context.
  • withFilesystemSources / session.mount() — two ways to mount read-only content into a sandbox; agent's built-in grep / glob / read tools see it as ordinary files.
  • runtime: 'inline' | 'stateless' | 'temporal' + sessionRuntime — pick by persistence needs. Pair runtime: 'temporal' with temporalSessionRuntime({...}) from @fabric-harness/temporal to route every session call through durable workflows.
  • CapabilityPolicy — filesystem read/write globs, command/tool allow-deny-approve, and network: { mode, hosts } allowlist/denylist. policiedFetch(fetch, policy) wraps any fetch-like with policy enforcement.
  • Schemas (schema.object, schema.enum, etc.) — validate inputs/outputs without external deps.
  • MCP — connectMcpServer for remote tool servers.
  • Telemetry — openTelemetryExporter, langfuseExporter, consoleTelemetryExporter adapt the TelemetrySpan shape to OTel / Langfuse / stdout.

Named OpenAI-compatible presets are available as deepseek/<model> (DEEPSEEK_API_KEY), moonshot/<model> or kimi/<model> (MOONSHOT_API_KEY), and xai/<model> (XAI_API_KEY). They use direct provider endpoints and never silently fall back to a gateway or mock model.

Documentation

License

Apache-2.0

版本与发布记录

@fabric-harness/sdk 共发布 81 个版本,首次发布于 2026/05/06;过去 12 个月发布了 81 个版本。

版本发布日期距今
6.9.1latest2026/11/086 天前
6.9.02026/11/0311 天前
6.8.02026/10/3114 天前
6.7.02026/10/1728 天前
6.6.02026/10/131 个月前
6.5.02026/09/301 个月前

关于 @fabric-harness/sdk 的常见问题

@fabric-harness/sdk 是什么?

Headless TypeScript framework for building durable, deployable autonomous agents — core SDK.

如何安装 @fabric-harness/sdk?

在项目目录运行 npm install @fabric-harness/sdk,或使用 pnpm add / yarn add / bun add。

@fabric-harness/sdk 支持 TypeScript 吗?

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

@fabric-harness/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fabric-harness/sdk 需要什么版本的 Node.js?

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

@fabric-harness/sdk 可以商用吗?

@fabric-harness/sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@fabric-harness/sdk 的下载量有多少?

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

@fabric-harness/sdk 还在维护吗?

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