@factory/droid-sdk

中文文档
0.11.0发布于 2026/11/13Apache-2.0TypeScriptESM + CJS近 30 天下载 8.6万

TypeScript SDK for the Factory Droid CLI

原始使用文档
文档目录10 节
  1. Installation
  2. Entrypoints
  3. Quick start
  4. Documentation
  5. Custom transport migration
  6. Shared display messages
  7. Open status values (0.11.0)
  8. Machine template list (0.11.0)
  9. Browser security
  10. License

@factory/droid-sdk

The Factory TypeScript SDK lets applications run Droid, continue conversations, stream work, control tools, and connect to a running Droid daemon.

Installation

npm install @factory/droid-sdk

The SDK requires Node.js 18 or later.

Entrypoints

ImportRuntimePurpose
@factory/droid-sdk/nodeNodeStart Droid subprocesses, run prompts, manage local sessions, and define SDK MCP tools
@factory/droid-sdkBrowser or NodeConnect to an existing Droid daemon and use browser-safe schemas, types, and REST helpers
@factory/droid-sdk/apiBrowser or NodeCall any Factory REST API operation through a client generated from the public API spec

By default, Node session APIs start the droid CLI from PATH and read FACTORY_API_KEY. A custom executable, API key, or transport can be supplied through session options.

Quick start

import { run } from '@factory/droid-sdk/node';

const result = await run('Summarize this repository.');

if (!result.success) {
  throw new Error(result.error?.message ?? 'The run did not complete.');
}

console.log(result.text);

Use createSession() for multi-turn Node conversations. Use connectToDaemon() from the root entrypoint to manage sessions through an existing daemon.

Documentation

The TypeScript SDK documentation is the canonical user-facing guide to:

  • Node and daemon runtimes
  • Runs, sessions, streaming, attachments, and structured output
  • Permissions, AskUser, tools, skills, MCP, and hooks
  • Session replacement and cleanup behavior
  • Browser and daemon integration
  • Observability, REST helpers, advanced resources, and the public API

Runnable examples are available under examples/node and examples/browser.

Custom transport migration

  • Breaking agent-client change: DroidClientOptions.transport and custom session transports now require DroidClientTransport, which exchanges JsonRpcMessage objects through send and onMessage. No format marker or runtime detection is needed.
  • Built-in ProcessTransport owns its stdio JSON codec. Its direct send and onMessage callers must now pass and receive objects rather than strings. In-process implementations exchange snapshots without codecs.
  • For an existing custom StringFramedDroidClientTransport, explicitly pass withJsonRpcCodec(stringTransport) to DroidClient or session options. The adapter and both interfaces are exported from @factory/droid-sdk/node. Do not wrap an already typed transport.
  • Breaking daemon-client change: replace DaemonClient.onMessage with onTransportMessage and remove JSON.parse from callbacks. Custom DaemonClientTransport.send and message listeners now exchange JsonRpcMessage objects. Put codecs inside transports that cross a serialized boundary. External wire formats are unchanged.

Shared display messages

  • filterMessagesForUI no longer copies messages. A message with nothing to hide comes back as the same object, and a stripped message as a projection that later calls return again. Treat the results as read-only: mutating one changes your input or what later calls return. Replace a message instead of editing it.

Open status values (0.11.0)

  • RemoteSession['status'], MachineTemplateBuildStatus['status'], and MachineTemplateBuildStatus['failureReason'] now accept values a newer server adds instead of failing the response. An exhaustive switch over one of them needs a branch for an unknown value.
  • Those fields of RemoteSessionSchema and MachineTemplateBuildStatusSchema are unions now, not enums: .enum on them is gone, and .options lists the union's member schemas rather than the known values.

Machine template list (0.11.0)

  • listMachineTemplates no longer takes limit or cursor. The API returns every template in one response, with pagination.hasMore always false and pagination.nextCursor always null.
  • ListMachineTemplatesOptions drops limit and cursor but stays an interface over FactoryApiOptions, so declaration merging into it keeps compiling. An options object literal that passes either field fails typecheck; a variable typed with extra properties compiles, and the helper does not send them.

The canonical SDK guide remains the full API reference.

Browser security

The daemon client currently authenticates with a Factory API key. Browser integration is intended for trusted local tools. Do not ship a Factory API key in a public website, commit it to source control, or put it in a URL.

License

Apache 2.0

版本与发布记录

@factory/droid-sdk 共发布 16 个版本,首次发布于 2026/03/26;过去 12 个月发布了 16 个版本。

版本发布日期距今
0.11.0latest2026/11/131 天前
0.10.02026/10/2025 天前
0.9.12026/09/052 个月前
0.9.02026/09/012 个月前
0.8.02026/08/262 个月前
0.7.02026/08/063 个月前

关于 @factory/droid-sdk 的常见问题

@factory/droid-sdk 是什么?

TypeScript SDK for the Factory Droid CLI

如何安装 @factory/droid-sdk?

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

@factory/droid-sdk 支持 TypeScript 吗?

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

@factory/droid-sdk 支持 ESM 还是 CommonJS?

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

@factory/droid-sdk 需要什么版本的 Node.js?

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

@factory/droid-sdk 可以商用吗?

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

@factory/droid-sdk 的下载量有多少?

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

@factory/droid-sdk 还在维护吗?

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