@agent-assistant/surfaces

中文文档
0.4.37发布于 2026/10/04TypeScriptES Module零依赖构建来源已验证近 30 天下载 3.2万

Surface connection registry, inbound normalization, and outbound dispatch for Agent Assistant SDK

原始使用文档
文档目录11 节
  1. Responsibilities
  2. Non-Goals
  3. Installation
  4. Core Concepts
  5. Usage
  6. Registering A Surface
  7. Inbound Flow
  8. Outbound Delivery
  9. Fanout
  10. Package Boundary
  11. Development

@agent-assistant/surfaces

@agent-assistant/surfaces provides the assistant-facing surface layer for Agent Assistant SDK. It owns surface registration, inbound normalization, outbound dispatch, formatting hooks, and multi-surface fanout. It does not implement transport protocols or product-specific surface logic.

Responsibilities

  • register and track SurfaceConnection records
  • expose a single registry that satisfies the inbound and outbound adapter contracts used by @agent-assistant/core
  • normalize raw inbound payloads into the structural InboundMessage shape core expects
  • dispatch outbound events to one surface or fan them out across session-attached surfaces
  • apply optional per-surface formatting hooks before delivery

Non-Goals

  • transport implementation such as HTTP, WebSocket, Slack Events, or desktop IPC
  • authentication, webhook verification, or provider SDK concerns
  • product-specific formatting conventions or UI behavior
  • buffering, retries, or offline queueing

Installation

npm install @agent-assistant/surfaces

Core Concepts

SurfaceConnection describes one registered surface, including its adapter, capabilities, and current state.

SurfaceAdapter is implemented by product code or a transport-facing package. The adapter is responsible only for connection state callbacks and final payload delivery.

createSurfaceRegistry() returns one object that acts as:

  • the surface registry
  • the core inbound adapter
  • the core outbound adapter

That lets products wire one registry instance into the runtime and the relay-facing transport layer.

Usage

import { createAssistant } from '@agent-assistant/core';
import { createSurfaceRegistry } from '@agent-assistant/surfaces';

const surfaces = createSurfaceRegistry();

const runtime = createAssistant(
  {
    id: 'assistant-1',
    name: 'Assistant',
    capabilities: {
      chat: async (message, context) => {
        await context.runtime.emit({
          surfaceId: message.surfaceId,
          text: `echo:${message.text}`,
        });
      },
    },
  },
  {
    inbound: surfaces,
    outbound: surfaces,
  },
);

Registering A Surface

surfaces.register({
  id: 'web-primary',
  type: 'web',
  state: 'registered',
  capabilities: {
    markdown: true,
    richBlocks: false,
    attachments: false,
    streaming: false,
    maxResponseLength: 0,
  },
  adapter: {
    async send(payload) {
      // Deliver payload to your transport layer.
    },
    onConnect(callback) {
      // Store and call when the transport becomes active.
    },
    onDisconnect(callback) {
      // Store and call when the transport becomes inactive.
    },
  },
});

When the adapter reports connect or disconnect events, the registry updates connection.state in place.

Inbound Flow

Relay-facing code pushes raw events into the registry:

surfaces.receiveRaw('web-primary', {
  messageId: 'msg-1',
  userId: 'user-1',
  text: 'hello',
  capability: 'chat',
});

Default normalization extracts:

  • id from messageId or id, otherwise a generated UUID
  • sessionId from sessionId or session.id
  • userId from userId, user.id, or user when it is a string
  • workspaceId from workspaceId or workspace.id
  • text from text, content, or body
  • receivedAt from timestamp or receivedAt, otherwise the current time
  • capability from capability or type, otherwise 'chat'

If userId is missing, the message is dropped and an error is logged. If text is missing, an empty string is used and a warning is logged.

Products with non-standard relay payloads can replace the default normalization logic with normalizationHook.

Outbound Delivery

Targeted delivery uses send(event) and requires event.surfaceId.

await surfaces.send({
  surfaceId: 'web-primary',
  text: 'Hello from the assistant',
});

If a connection has a formatHook, the hook receives the outbound event and the surface capabilities and can return any surface-specific formatted structure. Without a hook, the adapter receives event.text as the formatted output.

Adapter failures are wrapped in SurfaceDeliveryError.

Fanout

When core resolves a session into a set of attached surface IDs, the registry can deliver to all of them:

const result = await surfaces.fanout(
  {
    sessionId: 'session-1',
    text: 'This reaches every attached surface',
  },
  ['web-primary', 'desktop-1'],
);

Fanout behavior:

  • sends concurrently by default
  • skips unknown surfaces
  • skips inactive surfaces by default
  • can continue collecting failures or abort on the first failure
  • returns a FanoutResult with per-surface outcomes

Default fanout behavior can be configured with defaultFanoutPolicy.

Package Boundary

This package is TypeScript-first, runtime-light, and has no cloud assumptions. It does not depend on specific transport stacks, does not import session logic at runtime, and does not contain relay transport implementations.

Development

npm test
npm run build

SURFACES_PACKAGE_IMPLEMENTED

版本与发布记录

@agent-assistant/surfaces 共发布 68 个版本,首次发布于 2026/04/13;过去 12 个月发布了 68 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.37latest2026/10/041 个月前
0.4.362026/10/041 个月前
0.4.352026/05/235 个月前
0.4.332026/05/155 个月前
0.4.322026/05/125 个月前
0.4.312026/05/086 个月前

关于 @agent-assistant/surfaces 的常见问题

@agent-assistant/surfaces 是什么?

Surface connection registry, inbound normalization, and outbound dispatch for Agent Assistant SDK

如何安装 @agent-assistant/surfaces?

在项目目录运行 npm install @agent-assistant/surfaces,或使用 pnpm add / yarn add / bun add。

@agent-assistant/surfaces 支持 TypeScript 吗?

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

@agent-assistant/surfaces 支持 ESM 还是 CommonJS?

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

@agent-assistant/surfaces 可以商用吗?

@agent-assistant/surfaces 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@agent-assistant/surfaces 的下载量有多少?

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

@agent-assistant/surfaces 还在维护吗?

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