Skip to content
English

DeliveryOptions ​

KIT · interface · 类型合同

Pipeline construction options.

导入 ​

ts
import type { DeliveryOptions } from '@jangts/agent-core/kits/delivery';
js
/** @typedef {import('@jangts/agent-core/kits/delivery').DeliveryOptions} DeliveryOptions */

其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits/delivery、@jangts/agent-core/kits。

定义 ​

ts
interface DeliveryOptions<Input, State, Result, StageId>

泛型参数 ​

类型参数约束默认类型
Input——
State——
Result——
StageIdstring—

字段结构 ​

字段类型必需说明
createState(input: Input, context: ExecutionContext) => State必需只读。Creates the mutable per-run state; must return synchronously.
stagesreadonly DeliveryStage<Input, State, Result, StageId>[]必需只读。Stages in execution order; ids must be unique.
beforeStage((input: { stageId: StageId; state: State; }, context: OperationContext<Input>) => void) | undefined可省略只读。Observes every stage before it runs, including stages without a handler.
missingResult() => Error必需只读。Builds the error thrown when every stage returned continue.

成员目录 ​

成员用途
createStateCreates the mutable per-run state; must return synchronously.
missingResultBuilds the error thrown when every stage returned continue.

成员详情 ​

createState ​

Creates the mutable per-run state; must return synchronously.

ts
DeliveryOptions.createState(input: Input, context: ExecutionContext): State
参数类型传递说明
inputInput必需—
contextExecutionContext必需—
context 的字段
字段类型必需说明
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.

返回: State。

等待后的值: Awaited<State>。

missingResult ​

Builds the error thrown when every stage returned continue.

ts
DeliveryOptions.missingResult(): Error

无调用参数。

返回: Error。

使用示例 ​

交付一段已经确认的文本 ​

入门 · Node.js

ts
import { Delivery } from '@jangts/agent-core/kits/delivery';
const delivery = Delivery.defineDelivery({
  createState: (input: string) => ({ text: input }),
  stages: [{ id: 'publish', handle: (state: { text: string }) => ({ type: 'complete' as const, value: state.text }) }],
  missingResult: () => new Error('没有可交付结果'),
});
console.log(delivery.deliver('已完成的答复', { signal: new AbortController().signal }));
js
import { Delivery } from '@jangts/agent-core/kits/delivery';
const delivery = Delivery.defineDelivery({
    createState: (input) => ({ text: input }),
    stages: [{ id: 'publish', handle: (state) => ({ type: 'complete', value: state.text }) }],
    missingResult: () => new Error('没有可交付结果'),
});
console.log(delivery.deliver('已完成的答复', { signal: new AbortController().signal }));

增加校验阶段,保留同一个 deliver ​

配置 · Node.js

ts
import { Delivery } from '@jangts/agent-core/kits/delivery';
const delivery = Delivery.defineDelivery({
  createState: (input: string) => ({ text: input.trim() }),
  stages: [
    { id: 'check', handle(state: { text: string }) {
      if (!state.text) throw new Error('答复为空');
      return { type: 'continue' as const };
    } },
    { id: 'publish', handle: (state: { text: string }) => ({ type: 'complete' as const, value: state.text }) },
  ],
  beforeStage: ({ stageId }: { stageId: string }) => { console.log('阶段', stageId); },
  missingResult: () => new Error('没有可交付结果'),
});
console.log(delivery.deliver(' 已完成的答复 ', { signal: new AbortController().signal }));
js
import { Delivery } from '@jangts/agent-core/kits/delivery';
const delivery = Delivery.defineDelivery({
    createState: (input) => ({ text: input.trim() }),
    stages: [
        { id: 'check', handle(state) {
                if (!state.text)
                    throw new Error('答复为空');
                return { type: 'continue' };
            } },
        { id: 'publish', handle: (state) => ({ type: 'complete', value: state.text }) },
    ],
    beforeStage: ({ stageId }) => { console.log('阶段', stageId); },
    missingResult: () => new Error('没有可交付结果'),
});
console.log(delivery.deliver(' 已完成的答复 ', { signal: new AbortController().signal }));

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。