# @enclave-vm/types 中文文档

规范地址：https://npmcn.com/package/%40enclave-vm/types/

版本：2\.19\.2
npm 元数据更新时间：2026-11-12T21:33:28.627Z
中文译文更新时间：2026-11-13T16:32:32.228Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40enclave-vm/types
原文对照：https://npmcn.com/package/%40enclave-vm/types/?lang=original
项目主页：https://github.com/agentfront/enclave
源码仓库：https://github.com/agentfront/enclave

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：134 kB，12 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2026-01-28T21:29:03.474Z
- 最新版本发布：2026-11-12T21:33:28.245Z
- 近 30 天下载量：7123（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：23（近 12 个月 23 个）

## 中文简介

EnclaveJS 流线运行时协议的类型定义和 Zod 计划

## 安装

```sh
npm install @enclave-vm/types
```

也可以使用：`pnpm add @enclave-vm/types`、`yarn add @enclave-vm/types`、`bun add @enclave-vm/types`

## README

# @ enclave-vm/ 类型

[![npm version](https://img.shields.io/npm/v/@enclave-vm/types.svg)](https://www.npmjs.com/package/@enclave-vm/types) [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://npmcn.com/package/%40enclave-vm/types/LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)

> EnclaveJS 流线运行时协议的类型定义和 Zod 计划

@enclave-vm/types包提供了TypeScript类型定义和运行时间验证计划,用于EnclaveJS流协议. 它作为EnclaveJS各组件之间进行类型安全通信的基础.

## 特征

-   **类型脚本第一**: 完整类型脚本支持并严格打字
-   **佐德·斯克马斯**: 所有协议消息的运行时间验证
-   **协议类型**: 流出消息的完整类型定义
-   **会话类型**: 会话管理和状态的类型
-   **工具类型**: 工具呼叫和响应的定义类型

## 安装

```bash
npm install @enclave-vm/types
# or
yarn add @enclave-vm/types
# or
pnpm add @enclave-vm/types
```

## 快速启动

```typescript
import { isToolCallEvent, isFinalEvent, type StreamEvent } from '@enclave-vm/types';

// Type-safe event handling
function handleEvent(event: StreamEvent) {
  if (isToolCallEvent(event)) {
    console.log(`Tool: ${event.payload.toolName}, Args:`, event.payload.args);
  } else if (isFinalEvent(event)) {
    console.log(event.payload.ok ? 'Result:' : 'Error:', event.payload.result ?? event.payload.error);
  }
}
```

## 议定书

### 串流事件

每个事件都有 `protocolVersion`, (中文(简体) ), `sessionId`,序列号 `seq`页:1 `type` (单位:千美元) `payload`数字 :

```typescript
import { PROTOCOL_VERSION, type ToolCallEvent, type FinalEvent } from '@enclave-vm/types';

const toolCall: ToolCallEvent = {
  protocolVersion: PROTOCOL_VERSION, // 2
  sessionId: 's_3f0e2f6e-1c1b-4c57-9a55-0a8b5a3d2c11',
  seq: 2,
  type: 'tool_call',
  payload: {
    callId: 'c_9a55e2f6-4c57-1c1b-3f0e-0a8b5a3d2c11',
    toolName: 'getUser',
    args: { userId: 1 },
  },
};

const final: FinalEvent = {
  protocolVersion: PROTOCOL_VERSION,
  sessionId: 's_3f0e2f6e-1c1b-4c57-9a55-0a8b5a3d2c11',
  seq: 4,
  type: 'final',
  payload: {
    ok: true,
    result: { name: 'Alice' },
    stats: { durationMs: 120, toolCallCount: 1, stdoutBytes: 0 },
  },
};
```

活动类型是 `session_init`, (中文(简体) ), `stdout`, (中文(简体) ), `log`, (中文(简体) ), `tool_call`, (中文(简体) ), `tool_result_applied`, (中文(简体) ), `final`, (中文(简体) ), `heartbeat`, (中文(简体) ), `error`,自协议版本2起 `partial_result`, (中文(简体) ), `tool_progress`, (中文(简体) ), `deadline_exceeded` 财务报告和审定财务报表 `catalog_changed`。每个类型(`ToolCallEvent`),一个计划(`ToolCallEventSchema`)和一个类型后卫(`isToolCallEvent`) (中文(简体) ).

### 标识符和会话状态

```typescript
import {
  generateSessionId,
  generateCallId,
  isSessionId,
  SessionState,
  DEFAULT_SESSION_LIMITS,
} from '@enclave-vm/types';

const sessionId = generateSessionId(); // 's_' followed by a UUID
const callId = generateCallId(); // 'c_' followed by a UUID

isSessionId(sessionId); // true

SessionState.Running; // 'running'
// 'starting' | 'running' | 'waiting_for_tool' | 'completed' | 'cancelled' | 'failed'

DEFAULT_SESSION_LIMITS.maxToolCalls; // 50
```

## 佐德·斯克马斯

这些类型都有相应的Zod schemas用于运行时间验证:

```typescript
import { StreamEventSchema, parseStreamEvent } from '@enclave-vm/types';

// Parse and validate
const parsed = StreamEventSchema.safeParse(untrustedData);
if (parsed.success) {
  // parsed.data is typed as StreamEvent
  handleEvent(parsed.data);
} else {
  console.error('Invalid event:', parsed.error);
}

// The same, as a helper
const result = parseStreamEvent(untrustedData);
```

## 软件包不做什么

软件包定义了加密信封和密钥交换器的类型(`EncryptedEnvelope`, (中文(简体) ), `ClientHello`, (中文(简体) ), `ServerHello`) (中文(简体) ). 它们是定义: 此寄存器的客户端或经纪人没有加密一个会话, 他们描述的密钥交换没有认证 。 会话为普通JSON受运输保护.

## 相关软件包

| 软件包 | 说明 |
| --- | --- |
| [@enclave-vm/ 流水](https://npmcn.com/package/%40enclave-vm/stream) | 简化协议的执行 |
| [@enclave-vm/ 经纪人](https://npmcn.com/package/%40enclave-vm/broker) | 工具中介和会话管理 |
| [@enclave-vm/客户端](https://npmcn.com/package/%40enclave-vm/client) | 浏览器/ Node.js 客户端 SDK |
| [@enclave-vm/反应](https://npmcn.com/package/%40enclave-vm/react) | 反应钩和组件 |
| [@enclave-vm/运行时间](https://npmcn.com/package/%40enclave-vm/runtime) | 运行时间工人构件(非可运行服务) |

## 许可证

阿帕奇 - 2.0

## 常见问题

### @enclave-vm/types 是什么？

EnclaveJS 流线运行时协议的类型定义和 Zod 计划

### 如何安装 @enclave-vm/types？

在项目目录运行 npm install @enclave-vm/types，或使用 pnpm add / yarn add / bun add。

### @enclave-vm/types 支持 TypeScript 吗？

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

### @enclave-vm/types 支持 ESM 还是 CommonJS？

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

### @enclave-vm/types 可以商用吗？

@enclave-vm/types 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @enclave-vm/types 的下载量有多少？

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

### @enclave-vm/types 还在维护吗？

最新版本 2\.19\.2 发布于 2026/11/13（今天）；至今共发布 23 个版本，其中过去 12 个月发布了 23 个；首次发布于 2026/01/29。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

