@adia-ai/agent 0.8.28 → 0.8.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +384 -11
- package/agent.d.ts +44 -3
- package/agent.d.ts.map +1 -1
- package/agent.js +172 -8
- package/agent.js.map +1 -1
- package/events.d.ts +46 -2
- package/events.d.ts.map +1 -1
- package/events.js +30 -1
- package/events.js.map +1 -1
- package/guardrail.d.ts +68 -0
- package/guardrail.d.ts.map +1 -0
- package/guardrail.js +79 -0
- package/guardrail.js.map +1 -0
- package/index.d.ts +15 -7
- package/index.d.ts.map +1 -1
- package/index.js +7 -3
- package/index.js.map +1 -1
- package/integrations.d.ts +19 -2
- package/integrations.d.ts.map +1 -1
- package/integrations.js +6 -1
- package/integrations.js.map +1 -1
- package/loop.d.ts +19 -8
- package/loop.d.ts.map +1 -1
- package/loop.js +176 -9
- package/loop.js.map +1 -1
- package/mcp-transport.d.ts +128 -0
- package/mcp-transport.d.ts.map +1 -0
- package/mcp-transport.js +361 -0
- package/mcp-transport.js.map +1 -0
- package/mcp.d.ts +120 -0
- package/mcp.d.ts.map +1 -0
- package/mcp.js +264 -0
- package/mcp.js.map +1 -0
- package/package.json +1 -1
- package/resource.d.ts +28 -3
- package/resource.d.ts.map +1 -1
- package/resource.js +43 -5
- package/resource.js.map +1 -1
- package/session.d.ts +18 -0
- package/session.d.ts.map +1 -1
- package/session.js +40 -0
- package/session.js.map +1 -1
- package/stub.d.ts +8 -0
- package/stub.d.ts.map +1 -1
- package/stub.js +13 -0
- package/stub.js.map +1 -1
- package/tools.d.ts +6 -0
- package/tools.d.ts.map +1 -1
- package/tools.js.map +1 -1
- package/trace.d.ts +50 -0
- package/trace.d.ts.map +1 -0
- package/trace.js +60 -0
- package/trace.js.map +1 -0
- package/workflow.d.ts +113 -11
- package/workflow.d.ts.map +1 -1
- package/workflow.js +93 -15
- package/workflow.js.map +1 -1
package/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAuBH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,CAAC,IAAI,mCAAmC,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,CAAC,IAAI,4BAA4B,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,CAAC,IAAI,sCAAsC,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAgB;IACtC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACrB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,WAAW,EAAE,CAAC,CAAC,WAAW;KAC3B,CAAC,CAAC,CAAC;AACN,CAAC;AAED;gDACgD;AAChD,MAAM,UAAU,UAAU,CAAC,MAA+B,EAAE,KAA8B;IACxF,MAAM,QAAQ,GAAG,KAAK,CA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kBAAkB,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACrG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,MAAM,EAAE,SAAS,IAAI,CAAC,IAAI,aAAc,GAAa,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC5F,CAAC;AACH,CAAC"}
|
package/trace.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracing — the harness saying what it DID, not what it said.
|
|
3
|
+
*
|
|
4
|
+
* A transcript proves what was said; only a structured signal proves what
|
|
5
|
+
* happened. Every turn emits records at the points the harness genuinely
|
|
6
|
+
* reaches — prompt assembly, each provider call and its response, each tool
|
|
7
|
+
* execution, each workflow step verdict, each guardrail intervention, and
|
|
8
|
+
* the turn's token usage, and each MCP source connecting — through one
|
|
9
|
+
* closed phase vocabulary.
|
|
10
|
+
*
|
|
11
|
+
* `mcp` covers what a SOURCE does (handshake, what it listed, a failed
|
|
12
|
+
* connect). A tool a server contributed executes under `tool` like any
|
|
13
|
+
* other: once it is a ToolDef, it is not special.
|
|
14
|
+
*
|
|
15
|
+
* Two consumers, one record: a `trace` event on the AgentEvent stream (so a
|
|
16
|
+
* UI can render the turn's mechanics) and a pluggable SINK (so a process can
|
|
17
|
+
* log or export them). Tracing is OFF unless `AgentConfig.trace` is set —
|
|
18
|
+
* absence leaves no event, no console line, and no request difference.
|
|
19
|
+
*
|
|
20
|
+
* No external dependency and no exporter protocol: the sink is a function.
|
|
21
|
+
* An OpenTelemetry (or any other) exporter is a caller-side adapter over
|
|
22
|
+
* that function, deliberately not vendored here.
|
|
23
|
+
*/
|
|
24
|
+
export declare const TRACE_PHASES: readonly ["prompt", "request", "response", "tool", "workflow", "guardrail", "usage", "mcp"];
|
|
25
|
+
export type TracePhase = (typeof TRACE_PHASES)[number];
|
|
26
|
+
export declare function isTracePhase(value: unknown): value is TracePhase;
|
|
27
|
+
export interface TraceRecord {
|
|
28
|
+
phase: TracePhase;
|
|
29
|
+
/** What happened within the phase — `'assembled'`, `'step:verdict'`,
|
|
30
|
+
* `'tool:denied'`. Free-form by design: the PHASE is the closed
|
|
31
|
+
* vocabulary a reader switches on, the name is the detail. */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Epoch ms. */
|
|
34
|
+
at: number;
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
data?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export type TraceSink = (record: TraceRecord) => void;
|
|
39
|
+
/** The default sink — one console line per record, no dependency. */
|
|
40
|
+
export declare const consoleSink: TraceSink;
|
|
41
|
+
export interface Tracer {
|
|
42
|
+
enabled: boolean;
|
|
43
|
+
/** Build a record, hand it to the sink, and return it for the stream.
|
|
44
|
+
* Returns null when tracing is off, so callers emit nothing. */
|
|
45
|
+
record(phase: TracePhase, name: string, data?: Record<string, unknown>): TraceRecord | null;
|
|
46
|
+
}
|
|
47
|
+
/** `true` → the console sink; a function → that sink; falsy → tracing off. */
|
|
48
|
+
export type TraceConfig = boolean | TraceSink | undefined;
|
|
49
|
+
export declare function createTracer(config: TraceConfig, sessionId?: string): Tracer;
|
|
50
|
+
//# sourceMappingURL=trace.d.ts.map
|
package/trace.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["src/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,eAAO,MAAM,YAAY,6FAEf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB;;mEAE+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;AAEtD,qEAAqE;AACrE,eAAO,MAAM,WAAW,EAAE,SAGzB,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB;qEACiE;IACjE,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC;CAC7F;AAED,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAE1D,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAsB5E"}
|
package/trace.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracing — the harness saying what it DID, not what it said.
|
|
3
|
+
*
|
|
4
|
+
* A transcript proves what was said; only a structured signal proves what
|
|
5
|
+
* happened. Every turn emits records at the points the harness genuinely
|
|
6
|
+
* reaches — prompt assembly, each provider call and its response, each tool
|
|
7
|
+
* execution, each workflow step verdict, each guardrail intervention, and
|
|
8
|
+
* the turn's token usage, and each MCP source connecting — through one
|
|
9
|
+
* closed phase vocabulary.
|
|
10
|
+
*
|
|
11
|
+
* `mcp` covers what a SOURCE does (handshake, what it listed, a failed
|
|
12
|
+
* connect). A tool a server contributed executes under `tool` like any
|
|
13
|
+
* other: once it is a ToolDef, it is not special.
|
|
14
|
+
*
|
|
15
|
+
* Two consumers, one record: a `trace` event on the AgentEvent stream (so a
|
|
16
|
+
* UI can render the turn's mechanics) and a pluggable SINK (so a process can
|
|
17
|
+
* log or export them). Tracing is OFF unless `AgentConfig.trace` is set —
|
|
18
|
+
* absence leaves no event, no console line, and no request difference.
|
|
19
|
+
*
|
|
20
|
+
* No external dependency and no exporter protocol: the sink is a function.
|
|
21
|
+
* An OpenTelemetry (or any other) exporter is a caller-side adapter over
|
|
22
|
+
* that function, deliberately not vendored here.
|
|
23
|
+
*/
|
|
24
|
+
export const TRACE_PHASES = [
|
|
25
|
+
'prompt', 'request', 'response', 'tool', 'workflow', 'guardrail', 'usage', 'mcp',
|
|
26
|
+
];
|
|
27
|
+
export function isTracePhase(value) {
|
|
28
|
+
return typeof value === 'string' && TRACE_PHASES.includes(value);
|
|
29
|
+
}
|
|
30
|
+
/** The default sink — one console line per record, no dependency. */
|
|
31
|
+
export const consoleSink = (record) => {
|
|
32
|
+
const detail = record.data ? ` ${JSON.stringify(record.data)}` : '';
|
|
33
|
+
console.debug(`[agent] ${record.phase}/${record.name}${detail}`);
|
|
34
|
+
};
|
|
35
|
+
export function createTracer(config, sessionId) {
|
|
36
|
+
if (!config)
|
|
37
|
+
return { enabled: false, record: () => null };
|
|
38
|
+
const sink = typeof config === 'function' ? config : consoleSink;
|
|
39
|
+
return {
|
|
40
|
+
enabled: true,
|
|
41
|
+
record(phase, name, data) {
|
|
42
|
+
const record = {
|
|
43
|
+
phase,
|
|
44
|
+
name,
|
|
45
|
+
at: Date.now(),
|
|
46
|
+
...(sessionId ? { sessionId } : {}),
|
|
47
|
+
...(data ? { data } : {}),
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
sink(record);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// A broken sink must never take the turn down with it.
|
|
54
|
+
console.warn(`[agent] trace sink threw: ${err.message}`);
|
|
55
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,IAAI;YACtB,MAAM,MAAM,GAAgB;gBAC1B,KAAK;gBACL,IAAI;gBACJ,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;gBACd,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC1B,CAAC;YACF,IAAI,CAAC;gBACH,IAAI,CAAC,MAAM,CAAC,CAAC;YACf,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,uDAAuD;gBACvD,OAAO,CAAC,IAAI,CAAC,6BAA8B,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/workflow.d.ts
CHANGED
|
@@ -7,9 +7,53 @@
|
|
|
7
7
|
* terminal — its result is always accepted. `when` skips a step entirely
|
|
8
8
|
* for this invocation. Scripted pipeline over per-turn re-decision: the
|
|
9
9
|
* sequence is data, so every consuming surface runs the SAME cascade.
|
|
10
|
+
*
|
|
11
|
+
* Four seams the A2UI migration (gh#664) proved were missing, added in
|
|
12
|
+
* gh#665, all additive:
|
|
13
|
+
* - `until` may return a VERDICT (`{accepted, reason, detail, data}`)
|
|
14
|
+
* instead of a bare boolean, so the reason a step was rejected travels
|
|
15
|
+
* with the attempt instead of being recomputed by the consumer.
|
|
16
|
+
* - a workflow-level EXIT GATE, declared once, that every accepted
|
|
17
|
+
* non-terminal result passes through (the per-call `gate` callback each
|
|
18
|
+
* consumer used to carry).
|
|
19
|
+
* - SAME-STEP RETRY: `retry: { maxRounds }` re-runs the same step against
|
|
20
|
+
* the previous round's verdict before falling through.
|
|
21
|
+
* - a SERVICES channel on the context, separate from `input`: what the run
|
|
22
|
+
* may USE (llmAdapter, clients, stores) rather than what it is ABOUT.
|
|
10
23
|
*/
|
|
11
|
-
|
|
24
|
+
/** A step's accept decision. `reason` is a stable code a consumer can
|
|
25
|
+
* switch on (`'schema-invalid'`); `detail` is the human sentence. */
|
|
26
|
+
export interface Verdict {
|
|
27
|
+
accepted: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
detail?: string;
|
|
30
|
+
/** Anything the consumer wants carried on the attempt (feedback entries,
|
|
31
|
+
* validation output) — the retry round sees it as `ctx.feedback.data`. */
|
|
32
|
+
data?: unknown;
|
|
33
|
+
/** Set when the step's own `until` accepted and the WORKFLOW's exit gate
|
|
34
|
+
* rejected — a different diagnosis, and one a retry round needs to see
|
|
35
|
+
* on `ctx.feedback` to know what it is repairing. */
|
|
36
|
+
gateRejected?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** What a predicate may return: a verdict, or any value read for its
|
|
39
|
+
* truthiness (the v0 boolean, and whatever a loose JS predicate returns). */
|
|
40
|
+
export type StepDecision = boolean | Verdict | unknown;
|
|
41
|
+
/** Normalize any predicate return to a Verdict.
|
|
42
|
+
*
|
|
43
|
+
* A Verdict-shaped object (one with a boolean `accepted`) is taken as-is;
|
|
44
|
+
* EVERYTHING else is read for its truthiness, so a predicate written before
|
|
45
|
+
* verdicts existed — `until: r => r.messages.length`, `until: r => r.id` —
|
|
46
|
+
* keeps meaning what it always meant. Treating a non-boolean as a
|
|
47
|
+
* malformed verdict would silently flip those to rejected. */
|
|
48
|
+
export declare function toVerdict(decision: StepDecision): Verdict;
|
|
49
|
+
export interface WorkflowContext<TInput = unknown, TServices = Record<string, unknown>> {
|
|
50
|
+
/** What this run is ABOUT. */
|
|
12
51
|
input: TInput;
|
|
52
|
+
/** What this run may USE — llmAdapter, clients, stores. Always present
|
|
53
|
+
* (`{}` when the caller declared none). Services used to ride `input`;
|
|
54
|
+
* that still works and is not deprecated for consumer-owned shapes, but
|
|
55
|
+
* new code should put dependencies here and keep `input` the subject. */
|
|
56
|
+
services: TServices;
|
|
13
57
|
sessionId: string;
|
|
14
58
|
signal?: AbortSignal;
|
|
15
59
|
/** Step events land here (agent.run forwards them). */
|
|
@@ -19,26 +63,84 @@ export interface WorkflowContext<TInput = unknown> {
|
|
|
19
63
|
step: string;
|
|
20
64
|
data?: unknown;
|
|
21
65
|
}) => void;
|
|
66
|
+
/** Structured trace records (see trace.ts). Absent = tracing off. */
|
|
67
|
+
trace?: (phase: string, name: string, data?: Record<string, unknown>) => void;
|
|
68
|
+
/** 1-based retry round for the step currently running. 1 on a step that
|
|
69
|
+
* declares no `retry`. */
|
|
70
|
+
round?: number;
|
|
71
|
+
/** The verdict that rejected the PREVIOUS round of this same step —
|
|
72
|
+
* present only on retry rounds. This is the feedback channel a step
|
|
73
|
+
* retries against. */
|
|
74
|
+
feedback?: Verdict;
|
|
22
75
|
}
|
|
23
|
-
export interface WorkflowStep<TInput = unknown, TResult = unknown
|
|
76
|
+
export interface WorkflowStep<TInput = unknown, TResult = unknown, TServices = Record<string, unknown>> {
|
|
24
77
|
name?: string;
|
|
25
|
-
run: (ctx: WorkflowContext<TInput>) => TResult | Promise<TResult>;
|
|
26
|
-
/** Accept predicate
|
|
27
|
-
*
|
|
28
|
-
|
|
78
|
+
run: (ctx: WorkflowContext<TInput, TServices>) => TResult | Promise<TResult>;
|
|
79
|
+
/** Accept predicate. Return a Verdict (`{accepted, reason, …}`) to record
|
|
80
|
+
* WHY; return anything else and it is read for truthiness — a truthy
|
|
81
|
+
* return accepts, a falsy one falls the ladder through.
|
|
82
|
+
* Absent → terminal step, always accepted, and the workflow's exit gate
|
|
83
|
+
* does NOT run on it (the floor is the floor — declare `until: () => true`
|
|
84
|
+
* instead if the last step should be gated like the others).
|
|
85
|
+
* May be async: a real acceptance gate reads assets off disk (A2UI's
|
|
86
|
+
* schema + catalog validation), so a sync-only predicate would force
|
|
87
|
+
* every consumer to pre-resolve its gate outside the workflow. */
|
|
88
|
+
until?: (result: TResult, ctx: WorkflowContext<TInput, TServices>) => StepDecision | Promise<StepDecision>;
|
|
29
89
|
/** Skip guard: false → step doesn't run this invocation. */
|
|
30
|
-
when?: (ctx: WorkflowContext<TInput>) => boolean
|
|
90
|
+
when?: (ctx: WorkflowContext<TInput, TServices>) => boolean | Promise<boolean>;
|
|
91
|
+
/** Retry this SAME step against the rejecting verdict before falling
|
|
92
|
+
* through to the next one. `maxRounds` counts TOTAL runs of the step
|
|
93
|
+
* (2 = one retry). Each round sees `ctx.round` and `ctx.feedback`; each
|
|
94
|
+
* round is its own entry in `attempts`. A workflow exit-gate rejection
|
|
95
|
+
* consumes a round exactly like an `until` rejection, and arrives on the
|
|
96
|
+
* next round's `ctx.feedback` carrying `gateRejected: true`. Absent =
|
|
97
|
+
* one round, the v0 behavior. */
|
|
98
|
+
retry?: {
|
|
99
|
+
maxRounds: number;
|
|
100
|
+
};
|
|
31
101
|
}
|
|
32
|
-
export interface
|
|
102
|
+
export interface WorkflowOptions<TInput = unknown, TResult = unknown, TServices = Record<string, unknown>> {
|
|
103
|
+
/** The check EVERY accepted non-terminal result passes through, declared
|
|
104
|
+
* once for the whole workflow instead of restated per step. Runs after
|
|
105
|
+
* the step's own `until` accepted; a rejection falls the ladder through
|
|
106
|
+
* exactly as an `until` rejection does. */
|
|
107
|
+
exitGate?: (result: TResult, ctx: WorkflowContext<TInput, TServices>) => StepDecision | Promise<StepDecision>;
|
|
108
|
+
}
|
|
109
|
+
export interface Workflow<TInput = unknown, TResult = unknown, TServices = Record<string, unknown>> {
|
|
33
110
|
name: string;
|
|
34
|
-
steps: Array<WorkflowStep<TInput, TResult>>;
|
|
111
|
+
steps: Array<WorkflowStep<TInput, TResult, TServices>>;
|
|
112
|
+
exitGate?: WorkflowOptions<TInput, TResult, TServices>['exitGate'];
|
|
113
|
+
}
|
|
114
|
+
export interface WorkflowAttempt<TResult = unknown> {
|
|
115
|
+
step: string;
|
|
116
|
+
accepted: boolean;
|
|
117
|
+
result: TResult;
|
|
118
|
+
/** Rejection (or acceptance) code from a verdict-returning predicate.
|
|
119
|
+
* Absent when the predicate returned a bare boolean. */
|
|
120
|
+
reason?: string;
|
|
121
|
+
detail?: string;
|
|
122
|
+
/** Verdict payload — feedback entries, validation output. */
|
|
123
|
+
data?: unknown;
|
|
124
|
+
/** Which retry round of this step produced the attempt (1-based). */
|
|
125
|
+
round: number;
|
|
126
|
+
/** True when the step's own `until` accepted but the workflow's exit
|
|
127
|
+
* gate rejected — the two rejections are different diagnoses. */
|
|
128
|
+
gateRejected?: boolean;
|
|
35
129
|
}
|
|
36
130
|
export interface WorkflowResult<TResult = unknown> {
|
|
37
131
|
result: TResult | undefined;
|
|
38
132
|
/** Name/index of the accepting step, or null when every step fell through. */
|
|
39
133
|
step: string | null;
|
|
40
134
|
accepted: boolean;
|
|
135
|
+
/** Every step round that actually ran, in order, with its verdict — the
|
|
136
|
+
* escalation trace. Skipped (`when` false) steps don't appear. */
|
|
137
|
+
attempts: Array<WorkflowAttempt<TResult>>;
|
|
41
138
|
}
|
|
42
|
-
export declare function defineWorkflow<TInput = unknown, TResult = unknown
|
|
43
|
-
|
|
139
|
+
export declare function defineWorkflow<TInput = unknown, TResult = unknown, TServices = Record<string, unknown>>(name: string, steps: Array<WorkflowStep<TInput, TResult, TServices>>, options?: WorkflowOptions<TInput, TResult, TServices>): Workflow<TInput, TResult, TServices>;
|
|
140
|
+
/** The context a caller hands `runWorkflow` — `services` is optional here
|
|
141
|
+
* and defaulted to `{}` before any step sees it. */
|
|
142
|
+
export type WorkflowInvocation<TInput, TServices = Record<string, unknown>> = Omit<WorkflowContext<TInput, TServices>, 'services' | 'round' | 'feedback'> & {
|
|
143
|
+
services?: TServices;
|
|
144
|
+
};
|
|
145
|
+
export declare function runWorkflow<TInput, TResult, TServices = Record<string, unknown>>(workflow: Workflow<TInput, TResult, TServices>, invocation: WorkflowInvocation<TInput, TServices>): Promise<WorkflowResult<TResult>>;
|
|
44
146
|
//# sourceMappingURL=workflow.d.ts.map
|
package/workflow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["src/workflow.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["src/workflow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;sEACsE;AACtE,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;+EAC2E;IAC3E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;0DAEsD;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;8EAC8E;AAC9E,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAMvD;;;;;;+DAM+D;AAC/D,wBAAgB,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAEzD;AAED,MAAM,WAAW,eAAe,CAAC,MAAM,GAAG,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpF,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd;;;8EAG0E;IAC1E,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,uDAAuD;IACvD,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACzF,qEAAqE;IACrE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC9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D,MAAM,MAAM,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACxE,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAEzG,wBAAsB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpF,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAC9C,UAAU,EAAE,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,GAChD,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAwElC"}
|
package/workflow.js
CHANGED
|
@@ -7,30 +7,108 @@
|
|
|
7
7
|
* terminal — its result is always accepted. `when` skips a step entirely
|
|
8
8
|
* for this invocation. Scripted pipeline over per-turn re-decision: the
|
|
9
9
|
* sequence is data, so every consuming surface runs the SAME cascade.
|
|
10
|
+
*
|
|
11
|
+
* Four seams the A2UI migration (gh#664) proved were missing, added in
|
|
12
|
+
* gh#665, all additive:
|
|
13
|
+
* - `until` may return a VERDICT (`{accepted, reason, detail, data}`)
|
|
14
|
+
* instead of a bare boolean, so the reason a step was rejected travels
|
|
15
|
+
* with the attempt instead of being recomputed by the consumer.
|
|
16
|
+
* - a workflow-level EXIT GATE, declared once, that every accepted
|
|
17
|
+
* non-terminal result passes through (the per-call `gate` callback each
|
|
18
|
+
* consumer used to carry).
|
|
19
|
+
* - SAME-STEP RETRY: `retry: { maxRounds }` re-runs the same step against
|
|
20
|
+
* the previous round's verdict before falling through.
|
|
21
|
+
* - a SERVICES channel on the context, separate from `input`: what the run
|
|
22
|
+
* may USE (llmAdapter, clients, stores) rather than what it is ABOUT.
|
|
10
23
|
*/
|
|
11
|
-
|
|
24
|
+
function isVerdict(value) {
|
|
25
|
+
return typeof value === 'object' && value !== null && typeof value.accepted === 'boolean';
|
|
26
|
+
}
|
|
27
|
+
/** Normalize any predicate return to a Verdict.
|
|
28
|
+
*
|
|
29
|
+
* A Verdict-shaped object (one with a boolean `accepted`) is taken as-is;
|
|
30
|
+
* EVERYTHING else is read for its truthiness, so a predicate written before
|
|
31
|
+
* verdicts existed — `until: r => r.messages.length`, `until: r => r.id` —
|
|
32
|
+
* keeps meaning what it always meant. Treating a non-boolean as a
|
|
33
|
+
* malformed verdict would silently flip those to rejected. */
|
|
34
|
+
export function toVerdict(decision) {
|
|
35
|
+
return isVerdict(decision) ? decision : { accepted: !!decision };
|
|
36
|
+
}
|
|
37
|
+
export function defineWorkflow(name, steps, options = {}) {
|
|
12
38
|
if (!steps.length)
|
|
13
39
|
throw new Error(`defineWorkflow "${name}": at least one step`);
|
|
14
|
-
|
|
40
|
+
for (const step of steps) {
|
|
41
|
+
if (step.retry && !(step.retry.maxRounds >= 1)) {
|
|
42
|
+
throw new Error(`defineWorkflow "${name}": retry.maxRounds must be >= 1`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { name, steps, ...(options.exitGate ? { exitGate: options.exitGate } : {}) };
|
|
15
46
|
}
|
|
16
|
-
export async function runWorkflow(workflow,
|
|
47
|
+
export async function runWorkflow(workflow, invocation) {
|
|
48
|
+
const base = {
|
|
49
|
+
...invocation,
|
|
50
|
+
services: (invocation.services ?? {}),
|
|
51
|
+
};
|
|
17
52
|
let last;
|
|
53
|
+
const attempts = [];
|
|
18
54
|
for (let i = 0; i < workflow.steps.length; i++) {
|
|
19
55
|
const step = workflow.steps[i];
|
|
20
56
|
const stepName = step.name ?? `step-${i + 1}`;
|
|
21
|
-
if (step.when && !step.when(
|
|
57
|
+
if (step.when && !(await step.when(base)))
|
|
22
58
|
continue;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
59
|
+
const maxRounds = step.retry?.maxRounds ?? 1;
|
|
60
|
+
let feedback;
|
|
61
|
+
for (let round = 1; round <= maxRounds; round++) {
|
|
62
|
+
const ctx = {
|
|
63
|
+
...base,
|
|
64
|
+
round,
|
|
65
|
+
...(feedback ? { feedback } : {}),
|
|
66
|
+
};
|
|
67
|
+
base.trace?.('workflow', 'step:start', { workflow: workflow.name, step: stepName, round });
|
|
68
|
+
last = await step.run(ctx);
|
|
69
|
+
// Terminal step (no `until`): unconditionally accepted, and the exit
|
|
70
|
+
// gate does not run — the floor of a ladder is the answer of last
|
|
71
|
+
// resort, not another thing that can reject.
|
|
72
|
+
let verdict = step.until ? toVerdict(await step.until(last, ctx)) : { accepted: true };
|
|
73
|
+
if (verdict.accepted && step.until && workflow.exitGate) {
|
|
74
|
+
const gate = toVerdict(await workflow.exitGate(last, ctx));
|
|
75
|
+
if (!gate.accepted) {
|
|
76
|
+
// `gateRejected` rides the VERDICT, not just the attempt: a gate
|
|
77
|
+
// rejection consumes a retry round like any other, and the next
|
|
78
|
+
// round reads this off `ctx.feedback` to know it is repairing the
|
|
79
|
+
// gate's objection rather than the step's own.
|
|
80
|
+
verdict = { ...gate, reason: gate.reason ?? 'gate-rejected', gateRejected: true };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
attempts.push({
|
|
84
|
+
step: stepName,
|
|
85
|
+
accepted: verdict.accepted,
|
|
86
|
+
result: last,
|
|
87
|
+
round,
|
|
88
|
+
...(verdict.reason ? { reason: verdict.reason } : {}),
|
|
89
|
+
...(verdict.detail ? { detail: verdict.detail } : {}),
|
|
90
|
+
...(verdict.data !== undefined ? { data: verdict.data } : {}),
|
|
91
|
+
...(verdict.gateRejected ? { gateRejected: true } : {}),
|
|
92
|
+
});
|
|
93
|
+
base.emit?.({
|
|
94
|
+
type: 'step',
|
|
95
|
+
workflow: workflow.name,
|
|
96
|
+
step: stepName,
|
|
97
|
+
data: { accepted: verdict.accepted, round, ...(verdict.reason ? { reason: verdict.reason } : {}) },
|
|
98
|
+
});
|
|
99
|
+
base.trace?.('workflow', 'step:verdict', {
|
|
100
|
+
workflow: workflow.name,
|
|
101
|
+
step: stepName,
|
|
102
|
+
round,
|
|
103
|
+
accepted: verdict.accepted,
|
|
104
|
+
...(verdict.reason ? { reason: verdict.reason } : {}),
|
|
105
|
+
});
|
|
106
|
+
if (verdict.accepted) {
|
|
107
|
+
return { result: last, step: stepName, accepted: true, attempts };
|
|
108
|
+
}
|
|
109
|
+
feedback = verdict;
|
|
110
|
+
}
|
|
33
111
|
}
|
|
34
|
-
return { result: last, step: null, accepted: false };
|
|
112
|
+
return { result: last, step: null, accepted: false, attempts };
|
|
35
113
|
}
|
|
36
114
|
//# sourceMappingURL=workflow.js.map
|
package/workflow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["src/workflow.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["src/workflow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAqBH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAQ,KAAiB,CAAC,QAAQ,KAAK,SAAS,CAAC;AACzG,CAAC;AAED;;;;;;+DAM+D;AAC/D,MAAM,UAAU,SAAS,CAAC,QAAsB;IAC9C,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AACnE,CAAC;AA2FD,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,KAAsD,EACtD,UAAuD,EAAE;IAEzD,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,mBA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