DeliveryOptions
KIT · interface · Type contract
Pipeline construction options.
Import
ts
import type { DeliveryOptions } from '@jangts/agent-core/kits/delivery';1
js
/** @typedef {import('@jangts/agent-core/kits/delivery').DeliveryOptions} DeliveryOptions */1
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>1
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | — |
State | — | — |
Result | — | — |
StageId | string | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
createState | (input: Input, context: ExecutionContext) => State | Required | Read-only. Creates the mutable per-run state; must return synchronously. |
stages | readonly DeliveryStage<Input, State, Result, StageId>[] | Required | Read-only. Stages in execution order; ids must be unique. |
beforeStage | ((input: { stageId: StageId; state: State; }, context: OperationContext<Input>) => void) | undefined | Optional | Read-only. Observes every stage before it runs, including stages without a handler. |
missingResult | () => Error | Required | Read-only. Builds the error thrown when every stage returned continue. |
Member index
| Member | Purpose |
|---|---|
createState | Creates the mutable per-run state; must return synchronously. |
missingResult | Builds 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): State1
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | Input | Required | — |
context | ExecutionContext | Required | — |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-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(): Error1
No call parameters.
Returns: Error.
Examples
- Delivery: sequential delivery with an explicit end: Each delivery stage explicitly continues or completes; once a stage completes, the run ends immediately.
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 }));1
2
3
4
5
6
7
2
3
4
5
6
7
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 }));1
2
3
4
5
6
7
2
3
4
5
6
7
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 }));1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15