@agent-assistant/connectivity

中文文档
0.4.37发布于 2026/10/04MITTypeScriptES Module构建来源已验证近 30 天下载 2.5万

Typed in-process connectivity signals for Agent Assistant SDK

原始使用文档
文档目录17 节
  1. Scope
  2. Install Shape
  3. Signal Model
  4. Constants
  5. Core API
  6. createConnectivityLayer(config?)
  7. emit(input)
  8. resolve(signalId)
  9. get(signalId) and query(query)
  10. advanceStep(threadId)
  11. registerSelectedResolver(resolver)
  12. onSignal(callback) / offSignal(callback)
  13. Lifecycle and Convergence
  14. Suppression
  15. Routing Boundary
  16. Example
  17. Development

@agent-assistant/connectivity

@agent-assistant/connectivity implements the v1 in-process signaling layer for internal assistant coordination. It provides a bounded signal vocabulary, validation, suppression, lifecycle management, audience resolution hooks, and an escalation hook that routing can implement without handing routing ownership to this package.

Scope

This package owns:

  • the canonical ConnectivitySignal envelope and supporting TypeScript types
  • synchronous emit() with validation, ID assignment, timestamps, suppression, and supersession
  • an in-memory per-thread signal log with get() and query()
  • lifecycle transitions for resolved, superseded, and expired
  • audience semantics for self, coordinator, selected, and all
  • callback subscriptions through onSignal() and offSignal()
  • escalation hook interfaces that routing may implement

This package does not own:

  • routing decisions or mode application
  • coordinator work assignment or synthesis policy
  • transport, queues, or cross-process delivery
  • cloud telemetry or persistence
  • product-specific signal classes beyond the v1 catalog

Install Shape

The package is TypeScript-first and builds to dist/.

import {
  createConnectivityLayer,
  type ConnectivitySignal,
  type EmitSignalInput,
} from '@agent-assistant/connectivity';

Signal Model

v1 includes five message classes and eleven signal classes:

  • attention.raise
  • confidence.high
  • confidence.medium
  • confidence.low
  • confidence.blocker
  • conflict.active
  • conflict.resolved
  • handoff.ready
  • handoff.partial
  • escalation.interrupt
  • escalation.uncertainty

confidence is numeric and bounded to 0.0..1.0 when present. It is required for all confidence.* and conflict.* signals, and class-specific ranges are enforced for the confidence signal classes:

  • confidence.high: 0.8..1.0
  • confidence.medium: 0.4..0.79
  • confidence.low: 0.1..0.39
  • confidence.blocker: 0.0

Optional fields follow exact optional property semantics in TypeScript. Omit confidence, details, replaces, and expiresAtStep when they do not apply instead of passing them as explicit undefined values.

Constants

The package intentionally exports the runtime constant catalogs alongside the union types:

  • MESSAGE_CLASSES
  • MESSAGE_CLASS_TO_SIGNAL_PREFIX
  • SIGNAL_AUDIENCES
  • SIGNAL_CLASSES
  • SIGNAL_EVENTS
  • SIGNAL_PRIORITIES
  • SIGNAL_STATES
  • TERMINAL_STATES

These are part of the intended v1 surface so downstream packages can share the same canonical vocabulary for exhaustive checks, switch guards, and test fixtures without duplicating local arrays.

Core API

createConnectivityLayer(config?)

Creates a thread-aware in-memory layer.

const layer = createConnectivityLayer({
  suppressionConfig: { basis: 'step' },
  routingEscalationHook: {
    onEscalation(signal) {
      if (signal.signalClass === 'escalation.uncertainty') {
        return 'deep';
      }
    },
  },
});

emit(input)

Creates a validated signal, assigns id, emittedAt, and initial state, then stores it in the thread log.

Key behaviors:

  • validates required fields and class consistency
  • suppresses duplicates within the configured suppression window
  • bypasses suppression for priority='critical'
  • bypasses suppression for high-priority escalation signals when the summary changes
  • supersedes the target of replaces before storing the new signal
  • invokes the routing escalation hook for escalation.interrupt and escalation.uncertainty
  • fires onSignal(signal, 'emitted') synchronously

resolve(signalId)

Moves a signal to resolved. It is idempotent for already-resolved signals and throws for expired or superseded signals.

get(signalId) and query(query)

get() returns a single signal or null. query() reads a thread slice with filters for source, class, priority, state, and time boundaries. By default, query() returns only emitted and active signals.

advanceStep(threadId)

Increments the thread step counter. Signals with expiresAtStep <= currentStep become expired, and onSignal(signal, 'expired') fires for each.

registerSelectedResolver(resolver)

Registers the coordination-owned resolver used for audience='selected'. The resolver is invoked during emit. Connectivity computes the audience result but does not deliver or persist recipients.

onSignal(callback) / offSignal(callback)

Registers or removes synchronous callbacks for:

  • emitted
  • superseded
  • resolved
  • expired

If one callback throws, the error is logged and later callbacks still run.

Lifecycle and Convergence

Signals move through:

emitted -> active -> superseded
                  -> expired
                  -> resolved

active is reached after at least one onSignal callback fires for a newly emitted signal. Convergence stays intentionally lightweight in v1: the package gives coordination the primitives it needs to converge a thread without taking coordination ownership itself.

Those primitives are:

  • replaces for supersession when a newer signal obsoletes an older one
  • resolve() for explicit closure after synthesis or arbitration
  • advanceStep() plus expiresAtStep for stale transient signals
  • query() for checking unresolved conflicts, escalations, and current confidence state

Suppression

Duplicate detection uses the logical key:

threadId + source + signalClass + audience

Duplicates are suppressed only when the existing signal is still non-terminal.

Supported suppression modes:

  • basis: 'step' advanceStep() resets the suppression window
  • basis: 'time' uses a sliding windowMs, defaulting to 5000

Routing Boundary

Connectivity exposes a local routing hook interface only:

interface RoutingEscalationHook {
  onEscalation(signal: ConnectivitySignal): 'cheap' | 'fast' | 'deep' | void;
}

The hook type is defined by @agent-assistant/connectivity itself so published consumers do not need @agent-assistant/routing installed just to typecheck this package. Routing can still implement the same structural contract. Connectivity does not store the returned mode, does not choose routing modes, and does not import a routing implementation. The hook exists so routing can react to escalation signals without blurring package ownership.

Example

import { createConnectivityLayer } from '@agent-assistant/connectivity';

const layer = createConnectivityLayer();

layer.onSignal((signal, event) => {
  console.log(event, signal.signalClass, signal.summary);
});

const confidence = layer.emit({
  threadId: 'thread-42',
  source: 'specialist:reviewer',
  audience: 'coordinator',
  messageClass: 'confidence',
  signalClass: 'confidence.high',
  priority: 'normal',
  confidence: 0.92,
  summary: 'Review completed with stable evidence',
});

layer.emit({
  threadId: 'thread-42',
  source: 'specialist:reviewer',
  audience: 'selected',
  messageClass: 'handoff',
  signalClass: 'handoff.ready',
  priority: 'normal',
  summary: 'Downstream writer can synthesize the reviewed draft',
});

layer.resolve(confidence.id);

Development

Run inside packages/connectivity:

npm install
npm test
npm run build

The test suite covers the intended first workflows:

  • narrowcast attention
  • reviewer conflict
  • specialist handoff
  • blocker uncertainty routing escalation

CONNECTIVITY_PACKAGE_IMPLEMENTED

版本与发布记录

@agent-assistant/connectivity 共发布 59 个版本,首次发布于 2026/04/14;过去 12 个月发布了 59 个版本。最新版本附带 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/connectivity 的常见问题

@agent-assistant/connectivity 是什么?

Typed in-process connectivity signals for Agent Assistant SDK

如何安装 @agent-assistant/connectivity?

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

@agent-assistant/connectivity 支持 TypeScript 吗?

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

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

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

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

@agent-assistant/connectivity 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

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

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

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

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