Skip to content
中文

DeliveryOptions ​

KIT · interface · Type contract

Pipeline construction options.

Import ​

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

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/delivery, @jangts/agent-core/kits.

Definition ​

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

Type parameters ​

Type parameterConstraintDefault type
Input——
State——
Result——
StageIdstring—

Field structure ​

FieldTypeRequiredDescription
createState(input: Input, context: ExecutionContext) => StateRequiredRead-only. Creates the mutable per-run state; must return synchronously.
stagesreadonly DeliveryStage<Input, State, Result, StageId>[]RequiredRead-only. Stages in execution order; ids must be unique.
beforeStage((input: { stageId: StageId; state: State; }, context: OperationContext<Input>) => void) | undefinedOptionalRead-only. Observes every stage before it runs, including stages without a handler.
missingResult() => ErrorRequiredRead-only. Builds the error thrown when every stage returned continue.

Member index ​

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

Member details ​

createState ​

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

ts
DeliveryOptions.createState(input: Input, context: ExecutionContext): State
ParameterTypePassingDescription
inputInputRequired—
contextExecutionContextRequired—
Fields of context
FieldTypeRequiredDescription
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: State.

Awaited value: Awaited<State>.

missingResult ​

Builds the error thrown when every stage returned continue.

ts
DeliveryOptions.missingResult(): Error

No call parameters.

Returns: Error.

Examples ​

Deliver a piece of text that is already confirmed ​

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

Add a validation stage while keeping the same deliver ​

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

API reference, usage examples and developer guides.