@enclave-vm/types

中文文档
2.19.2发布于 2026/11/13Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 7123

Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol

原始使用文档
文档目录10 节
  1. Features
  2. Installation
  3. Quick Start
  4. Protocol
  5. Stream Events
  6. Identifiers and Session State
  7. Zod Schemas
  8. What the Package Does Not Do
  9. Related Packages
  10. License

@enclave-vm/types

npm version License TypeScript

Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol

The @enclave-vm/types package provides TypeScript type definitions and runtime validation schemas for the EnclaveJS streaming protocol. It serves as the foundation for type-safe communication between EnclaveJS components.

Features

  • TypeScript-First: Full TypeScript support with strict typing
  • Zod Schemas: Runtime validation for all protocol messages
  • Protocol Types: Complete type definitions for streaming messages
  • Session Types: Types for session management and state
  • Tool Types: Type definitions for tool calls and responses

Installation

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

Quick Start

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);
  }
}

Protocol

Stream Events

Every event has protocolVersion, sessionId, a sequence number seq, a type and a payload:

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 },
  },
};

The event types are session_init, stdout, log, tool_call, tool_result_applied, final, heartbeat, error, and since protocol version 2 partial_result, tool_progress, deadline_exceeded and catalog_changed. Each has a type (ToolCallEvent), a schema (ToolCallEventSchema) and a type guard (isToolCallEvent).

Identifiers and Session State

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

The types have corresponding Zod schemas for runtime validation:

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);

What the Package Does Not Do

The package defines types for an encrypted envelope and a key exchange (EncryptedEnvelope, ClientHello, ServerHello). They are definitions: no client or broker of this repository encrypts a session, and the key exchange they describe is not authenticated. Sessions are plain JSON protected by the transport.

PackageDescription
@enclave-vm/streamStreaming protocol implementation
@enclave-vm/brokerTool broker and session management
@enclave-vm/clientBrowser/Node.js client SDK
@enclave-vm/reactReact hooks and components
@enclave-vm/runtimeRuntime worker building blocks (not a runnable service)

License

Apache-2.0

版本与发布记录

@enclave-vm/types 共发布 23 个版本,首次发布于 2026/01/29;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.19.2latest2026/11/13今天
2.19.12026/11/121 天前
2.19.02026/11/121 天前
2.18.02026/11/094 天前
2.17.02026/10/2123 天前
2.16.02026/10/041 个月前

关于 @enclave-vm/types 的常见问题

@enclave-vm/types 是什么?

Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol

如何安装 @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 和提交记录判断。