# @agent-assistant/continuation 中文文档

规范地址：https://npmcn.com/package/%40agent-assistant/continuation/

版本：0\.4\.37
npm 元数据更新时间：2026-10-04T06:50:37.552Z
中文译文更新时间：2026-11-06T02:46:48.570Z
软件包许可：未声明

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

原始 npm 页面：https://www.npmjs.com/package/%40agent-assistant/continuation
原文对照：https://npmcn.com/package/%40agent-assistant/continuation/?lang=original
项目主页：https://github.com/AgentWorkforce/agent-assistant#readme
源码仓库：https://github.com/AgentWorkforce/agent-assistant

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

- 包体积（解压后）：53 kB，10 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2026-04-14T18:09:07.729Z
- 最新版本发布：2026-10-04T06:50:37.205Z
- 近 30 天下载量：6092（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：64（近 12 个月 64 个）

## 中文简介

基础延续原始——将可恢复的利用成果转化为明确状态,验证恢复触发器,以及真正的后续交付

## 安装

```sh
npm install @agent-assistant/continuation
```

也可以使用：`pnpm add @agent-assistant/continuation`、`yarn add @agent-assistant/continuation`、`bun add @agent-assistant/continuation`

## README

# `@agent-assistant/continuation`

> 限定运行时间的原始方式,将可恢复的利用结果转化为明确状态,验证恢复触发,以及真正的后续交付.

## 概览

续作从 `@agent-assistant/harness` 这名助理诚实地但最后地提出了澄清问题,一项行动正在等待批准,或者由于外部程序仍未完成而推迟工作。 续作包拥有该站后发生的一切:

-   将可恢复的转折状态作为已键入 `ContinuationRecord`
-   接受一个与续作中等待的匹配的明确恢复触发器
-   验证活性( 未过期, 尚未终止, 在最大尝试范围内)
-   以新的有界限的转弯重新入手
-   记录后续执行状态

**它不拥有的东西:**

-   限定的回合执行 + `@agent-assistant/harness`
-   段 次 页 次 `@agent-assistant/sessions`
-   (a) 运输 `@agent-assistant/surfaces`
-   核准/风险决定 `@agent-assistant/policy`
-   长期记忆 `@agent-assistant/memory`
-   通用排行榜 `@agent-assistant/proactive`

* * *

## 安装

```sh
npm install @agent-assistant/continuation
```

* * *

## 快开始

```ts
import { createContinuationRuntime, InMemoryContinuationStore } from '@agent-assistant/continuation';

const runtime = createContinuationRuntime({
  store: new InMemoryContinuationStore(),
  harness: myHarnessAdapter,    // implements ContinuationHarnessAdapter
  delivery: myDeliveryAdapter,  // optional: implements ContinuationDeliveryAdapter
});

// 1. After harness returns needs_clarification:
const { continuation } = await runtime.create({
  assistantId: 'sage',
  sessionId: 'session-123',
  originTurnId: 'turn-abc',
  harnessResult,  // the HarnessResult with outcome: 'needs_clarification'
});
// continuation.status === 'pending'
// continuation.waitFor.type === 'user_reply'

// 2. When the user replies:
const result = await runtime.resume({
  continuationId: continuation.id,
  trigger: {
    type: 'user_reply',
    message: { id: 'msg-2', text: 'London', receivedAt: new Date().toISOString() },
    receivedAt: new Date().toISOString(),
  },
});
// result.continuation.status === 'completed'
// result.harnessResult — the result of the resumed bounded turn

// 3. Cancel when no longer needed:
await runtime.stop({
  continuationId: continuation.id,
  reason: 'cancelled_by_user',
});
```

* * *

## API 参考

### `createContinuationRuntime(config)`

回返a `ContinuationRuntime` 绑在提供配置.

```ts
interface ContinuationConfig {
  store: ContinuationStore;
  harness: ContinuationHarnessAdapter;
  delivery?: ContinuationDeliveryAdapter;
  scheduler?: ContinuationSchedulerAdapter;
  clock?: ContinuationClock;
  trace?: ContinuationTraceSink;
  defaults?: ContinuationDefaults;
}
```

### `ContinuationRuntime`

| 方法 | 说明 |
| --- | --- |
| `create(input)` | 利用可更新的牵引结果创建续作 |
| `resume(input)` | 以明确触发方式恢复待续 |
| `stop(input)` | 以真实的理由终止续作 |
| `get({ continuationId })` | 通过 id 检索续作记录 |

### `create(input)`

接受一个可恢复的 `HarnessResult` (单位:千美元)`needs_clarification`, (中文(简体) ), `awaiting_approval`, (中文(简体) ), `deferred`返回 a `ContinuationCreateResult` 包含新的 `ContinuationRecord`。 。 。 .

**拒绝不可恢复的结果** (单位:千美元)`completed`, (中文(简体) ), `failed`与 `ContinuationInvalidInputError`。 。 。 .

等待条件源于结果:

| 结果 | 等待条件 |
| --- | --- |
| `needs_clarification` | `user_reply` |
| `awaiting_approval` | `approval_resolution` 要求 `approvalId` 状态或元数据 |
| `deferred` (默认) | `external_result` 要求 `operationId` 状态或元数据 |
| `deferred` + 键 `metadata.scheduledWake: true` | `scheduled_wake` |

### `resume(input)`

接受一个 `ContinuationResumeTrigger` 如果所有验证都通过,则重新使用:

1.  记录存在
2.  记录状态为 `pending`
3.  现在的时间是以前 `expiresAt`
4.  触发类型匹配 `waitFor.type`
5.  关联标识符匹配( 核准Id, 操作) (d) 国家
6.  `resumeAttempts < maxResumeAttempts`

**拒绝批准:** 如果触发是 `approval_resolution` 与 `decision: 'denied'`,不调用并标出记录 `cancelled` 有理无据 `approval_denied`。 。 。 .

**转帐:** 如果调用返回另一个可重复的结果,则记录会以新的等待条件(而不是新的记录)被重新修改.

### `stop(input)`

状态的终端原因映射 :

| 原因 | 状态 |
| --- | --- |
| `completed` | `completed` |
| `cancelled_by_user`, (中文(简体) ), `cancelled_by_product`, (中文(简体) ), `approval_denied` | `cancelled` |
| `superseded_by_newer_turn` | `superseded` |
| `expired_ttl` | `expired` |
| 所有其他国家 | `failed` |

停下来 **专有**: 调用一个已死记录的停止返回它不变.

* * *

## 连续生命周期

```
                    ┌─────────────┐
                    │   pending    │
                    └──────┬───────┘
                           │
         ┌─────────────────┼─────────────────┐
         │                 │                  │
         ▼                 ▼                  ▼
  ┌────────────┐  ┌────────────────┐  ┌──────────────┐
  │  resuming   │  │    expired     │  │  cancelled/  │
  └──────┬─────┘  └────────────────┘  │  superseded  │
         │                            └──────────────┘
  ┌──────┼──────┐
  │      │      │
  ▼      ▼      ▼
completed failed pending (re-pend)
```

* * *

## 等待条件和触发

| 等待条件 | 继续触发 |
| --- | --- |
| `user_reply` | `{ type: 'user_reply', message, receivedAt }` |
| `approval_resolution` | `{ type: 'approval_resolution', approvalId, decision, resolvedAt }` |
| `external_result` | `{ type: 'external_result', operationId, resolvedAt, payload? }` |
| `scheduled_wake` | `{ type: 'scheduled_wake', wakeUpId?, firedAt }` |

* * *

## TTL 默认

| 结果 | 默认 TTL |
| --- | --- |
| `needs_clarification` | 1小时(3 600 000毫秒) |
| `awaiting_approval` | 24小时(86 400 000毫秒) |
| `deferred` | 1小时 |
| `scheduled_wake` | 1小时 |

通过 `config.defaults` 或通过 `create({ bounds })`。 。 。 .

* * *

## 适配器

### `ContinuationHarnessAdapter`

```ts
interface ContinuationHarnessAdapter {
  runResumedTurn(input: ContinuationResumedTurnInput): Promise<HarnessResult>;
}
```

产品在调用绳索之前就用它来连接转折文本组装.

### `ContinuationDeliveryAdapter`

```ts
interface ContinuationDeliveryAdapter {
  deliver(input: ContinuationDeliveryInput): Promise<ContinuationDeliveryResult>;
}
```

可选的 当出现时,在恢复转弯后呼叫,会产生一个用户可见的终端结果.

### `ContinuationSchedulerAdapter`

```ts
interface ContinuationSchedulerAdapter {
  scheduleWake(input: { continuationId: string; wakeAtMs: number }): Promise<{ wakeUpId: string }>;
  cancelWake?(wakeUpId: string): Promise<void>;
}
```

可选的 仅限 `scheduled_wake` 续行.

### `ContinuationStore`

```ts
interface ContinuationStore {
  put(record: ContinuationRecord): Promise<void>;
  get(continuationId: string): Promise<ContinuationRecord | null>;
  delete?(continuationId: string): Promise<void>;
  listBySession?(sessionId: string): Promise<ContinuationRecord[]>;
}
```

仅 `put` 财务报告和审定财务报表 `get` 需要这样做。 使用 `InMemoryContinuationStore` 用于测试和开发.

* * *

## 交货状态

| 状态 | 含义 |
| --- | --- |
| `not_applicable` | 没有配置送出适配器 |
| `pending_delivery` | 交付适配器存在;尚未尝试交付 |
| `delivered` | 后续行动成功交付 |
| `suppressed_session_reengaged` | 用户重新参与; 后续行动被压制 |
| `suppressed_superseded` | 交货前继续替换 |
| `suppressed_expired` | 继续交货前过期 |
| `delivery_failed` | 交付适配器返回失败 |

* * *

## 错误类型

| 错误 | 掷出时 |
| --- | --- |
| `ContinuationNotFoundError` | 未保存的记录 ID |
| `ContinuationExpiredError` | 记录 TTL 已经通过 |
| `ContinuationAlreadyTerminalError` | 恢复未用记录 |
| `ContinuationTriggerMismatchError` | 触发类型或关联性 ID 不匹配 |
| `ContinuationInvalidInputError` | 无效的创建输入( 不良结果, 缺少所需的字段) |

* * *

## 边界

-   **利用性释放出可恢复的结果。 继续运作.** 这个套件不会影响机能.
-   **主动对接续 :** 如果没有原生的 停止转动的ID,它是主动的。 如果该助手正在恢复已知的未完成的转折行系,则继续.
-   **继续不是排程.** 预定的守夜是触发器 _类型_,而非调度器执行.
-   **继续不是一个记忆系统.** 它只保存一个未完成的转折线的短寿命运行状态.
-   **v1 范围 :** 一个现场记录每个源转。 多分支接续图明显超出范围.

## 常见问题

### @agent-assistant/continuation 是什么？

基础延续原始——将可恢复的利用成果转化为明确状态,验证恢复触发器,以及真正的后续交付

### 如何安装 @agent-assistant/continuation？

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

### @agent-assistant/continuation 支持 TypeScript 吗？

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

### @agent-assistant/continuation 支持 ESM 还是 CommonJS？

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

### @agent-assistant/continuation 可以商用吗？

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

### @agent-assistant/continuation 的下载量有多少？

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

### @agent-assistant/continuation 还在维护吗？

最新版本 0\.4\.37 发布于 2026/10/04（1 个月前）；至今共发布 64 个版本，其中过去 12 个月发布了 64 个；首次发布于 2026/04/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

