@alwith/api

中文文档
0.6.0发布于 2026/11/03MIT OR Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 4959

Public Runtime transports and application state for ALwith

原始使用文档
文档目录4 节
  1. Migration
  2. Rust SDK
  3. License and redistribution
  4. Isolated test Runtime

@alwith/api

Public Runtime transport and framework-independent application state. ACP requests, capabilities, session projection, replay and extension fields belong to the engine adapter. For Codex, import those capabilities from @nyssance/codex-acp-v2/client.

EntryContents
@alwith/api or /runtimeRuntime transport types, WebSocketRuntimeClient, run-state observation
/nodeProcessRuntimeClient, spawning the managed Runtime
/tauriTauriRuntimeClient, connecting to the host relay
/clientGeneric createStore and UpdateScheduler
/moduleModule transport
/toolsModule tool declarations

All transports extend FrameRuntimeClient. Runtime owns processes, run states and read acknowledgement. Raw request envelopes remain opaque transport payloads; this package does not interpret or construct engine extension fields.

import { WebSocketRuntimeClient, observeRunStates } from "@alwith/api"
import { CodexClient } from "@nyssance/codex-acp-v2/client"

const port = new WebSocketRuntimeClient(url, token)
const client = new CodexClient(async () => port, {
  agentId: "codex", launch: { engine: "codex" }
})
const observer = observeRunStates(port, (records, source) =>
  client.applyRunStates(records, source === "snapshot" ? "snapshot" : undefined)
)
await observer.ready
// On teardown:
observer.dispose()

Observation subscribes before reading the snapshot and discards snapshots superseded by newer events. Disposal handles late subscription registration and is idempotent.

Migration

ACP agent/session exports and the protocol SessionClient moved to the adapter's /client entry; there are no compatibility re-exports from this package. The generic store remains at /client. For extension-bearing calls use the adapter, which encodes the request through the opaque Runtime request transport. The basic Runtime convenience methods accept only their standard arguments.

Rust SDK

The Rust SDK is the alwith-api crate on crates.io, versioned with this package: the protocol types, the Runtime client and process helpers.

[dependencies]
alwith-api = { version = "0.6", features = ["client"] }

Use default-features = false if you only need the types.

License and redistribution

Licensed under either of MIT (LICENSE-MIT) or Apache-2.0 (LICENSE-APACHE) at your option; third-party notices are in THIRD_PARTY_NOTICES.md. Versions published before 0.6.0 keep the license they were released under.

Isolated test Runtime

Use startTestRuntime from @alwith/api/node for test scripts, including temporary probes. It owns a private temporary Codex home, workspace, journal and attention state for either stdio or ws. Process, engine and launch environments are fenced to that home. It never mutates the caller's environment or original credentials.

import { startTestRuntime } from "@alwith/api/node"
await using runtime = await startTestRuntime({
  binary: runtimeBinary,
  engines: { mock: mockEngine },
  transport: "stdio"
})
await runtime.client.start("test", { engine: "mock" })

The default home is empty. Only an explicitly requested live test supplies authFrom: existingCodexHome, copying only auth.json with owner-only permissions. The fixture removes the copy and all test state after the process exits, including startup failures. Use try/finally with await runtime.dispose() when the host does not support await using. Never point a test's CODEX_HOME at the original directory.

版本与发布记录

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

版本发布日期距今
0.6.0latest2026/11/032 天前
0.5.42026/10/288 天前
0.5.32026/10/279 天前
0.5.22026/10/279 天前
0.5.12026/10/279 天前
0.5.02026/10/279 天前

关于 @alwith/api 的常见问题

@alwith/api 是什么?

Public Runtime transports and application state for ALwith

如何安装 @alwith/api?

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

@alwith/api 支持 TypeScript 吗?

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

@alwith/api 支持 ESM 还是 CommonJS?

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

@alwith/api 可以商用吗?

@alwith/api 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alwith/api 的下载量有多少?

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

@alwith/api 还在维护吗?

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