@apo-ai/sdk 0.3.0 → 0.4.0
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/README.md +11 -0
- package/dist/agent-task/public.d.ts +257 -195
- package/dist/agent-task/public.js +140 -61
- package/dist/agent-task/public.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -286,6 +286,17 @@ with `runTask(dir, { judge: { model, apiKey?, baseURL? } })`, or set
|
|
|
286
286
|
same recorder and result format as code assertions, including model, prompt,
|
|
287
287
|
response, token usage, and latency metadata.
|
|
288
288
|
|
|
289
|
+
A task can also set its own judge layer (`task("id", { judge: { model?, prompt? } })`)
|
|
290
|
+
that overrides the run-level config and is itself overridden per `t.judge`
|
|
291
|
+
call — resolution is `run-level ← task-level ← per-call`, field by field.
|
|
292
|
+
`prompt` is a builder `(ctx) => ({ system?, user? })` that receives what the
|
|
293
|
+
judge is grading (`taskId`, `taskDescription?`, `checkName`, `instruction`,
|
|
294
|
+
`deliverableNames?`) so the briefing can say what a bare deliverable + rubric
|
|
295
|
+
never revealed. The SDK appends its JSON response contract to any custom
|
|
296
|
+
`system` — a builder customizes the briefing, never the response format. Keep
|
|
297
|
+
`system` constant per task and vary only `user` to preserve the cached prompt
|
|
298
|
+
prefix across a task's criteria (issue #161).
|
|
299
|
+
|
|
289
300
|
**Testing agents not built on apo's adapter.** Build a `Flow` from the
|
|
290
301
|
framework's own output with a normalizer, then run the same checks:
|
|
291
302
|
|
|
@@ -3,20 +3,184 @@ export { CreateApoTracerOptions, createApoTracer } from './integrations/ai-sdk.j
|
|
|
3
3
|
export { CreateApoOpenAIOptions, createApoOpenAI } from './integrations/openai.js';
|
|
4
4
|
export { CreateApoAnthropicOptions, createApoAnthropic } from './integrations/anthropic.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Trace Projection snapshot contract.
|
|
8
|
+
*
|
|
9
|
+
* This is the immutable transport/read snapshot of a Trace Projection — the
|
|
10
|
+
* query-optimized representation shared by the dashboard and agent-task
|
|
11
|
+
* assertions. It is NOT a new domain entity and never a source of truth; the
|
|
12
|
+
* canonical OpenTelemetry spans remain authoritative.
|
|
13
|
+
*
|
|
14
|
+
* Both the Python backend and the TypeScript SDK MUST serialize to this exact
|
|
15
|
+
* lower-camel-case JSON contract, so assertions read the same shape whether
|
|
16
|
+
* the snapshot came from the canonical repository, a local/offline recorder,
|
|
17
|
+
* or a legacy-Flow compatibility adapter.
|
|
18
|
+
*
|
|
19
|
+
* Rules:
|
|
20
|
+
* - `schemaVersion` versions the JSON contract.
|
|
21
|
+
* - `projectionVersion` identifies the normalizer/projector interpretation.
|
|
22
|
+
* - `source` is diagnostic; only `"canonical"` represents a durably projected
|
|
23
|
+
* Trace.
|
|
24
|
+
* - `complete` means the task execution root ended and every span in the
|
|
25
|
+
* acknowledged export was projected. It does not promise no unrelated
|
|
26
|
+
* service will ever export a late span.
|
|
27
|
+
* - Missing evidence is represented through `capabilities`, never converted to
|
|
28
|
+
* empty arrays, zero duration, or successful status.
|
|
29
|
+
* - Observations are immutable and sorted deterministically by invocation
|
|
30
|
+
* time, then span ID. Missing timestamps sort after timestamped ones.
|
|
31
|
+
*/
|
|
32
|
+
/** Whether a category of evidence is present in the projection. */
|
|
33
|
+
type EvidenceAvailability = "available" | "partial" | "unavailable";
|
|
34
|
+
/** Lifecycle status of an observation. `unset` = the source had no status. */
|
|
35
|
+
type ObservationStatus = "unset" | "ok" | "error";
|
|
36
|
+
/** What kind of Span an Observation was derived from. */
|
|
37
|
+
type ObservationType = "SPAN" | "GENERATION" | "TOOL" | "AGENT" | "SKILL" | "CHAIN" | "RETRIEVER" | "EMBEDDING" | "GUARDRAIL";
|
|
38
|
+
/**
|
|
39
|
+
* Per-category evidence availability. Every category must declare honestly
|
|
40
|
+
* what it carries so assertions can fail closed when evidence is missing
|
|
41
|
+
* instead of vacuously passing.
|
|
42
|
+
*/
|
|
43
|
+
interface TraceProjectionCapabilities {
|
|
44
|
+
messages: EvidenceAvailability;
|
|
45
|
+
tools: EvidenceAvailability;
|
|
46
|
+
errors: EvidenceAvailability;
|
|
47
|
+
timing: EvidenceAvailability;
|
|
48
|
+
skills: EvidenceAvailability;
|
|
49
|
+
subagents: EvidenceAvailability;
|
|
50
|
+
}
|
|
51
|
+
/** One chat message reconstructed from a generation observation. */
|
|
52
|
+
interface TraceProjectionMessage {
|
|
53
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
54
|
+
content: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A derived interpretation of one Span, as shown by the dashboard and read by
|
|
58
|
+
* assertions. Unknown span kinds survive as `SPAN`; hierarchy is preserved via
|
|
59
|
+
* `parentSpanId`.
|
|
60
|
+
*/
|
|
61
|
+
interface TraceProjectionObservation {
|
|
62
|
+
spanId: string;
|
|
63
|
+
parentSpanId?: string;
|
|
64
|
+
type: ObservationType;
|
|
65
|
+
name: string;
|
|
66
|
+
startedAt?: string;
|
|
67
|
+
endedAt?: string;
|
|
68
|
+
durationMs?: number;
|
|
69
|
+
status: ObservationStatus;
|
|
70
|
+
errorMessage?: string;
|
|
71
|
+
input?: unknown;
|
|
72
|
+
output?: unknown;
|
|
73
|
+
model?: string;
|
|
74
|
+
toolName?: string;
|
|
75
|
+
toolParameters?: unknown;
|
|
76
|
+
toolResult?: unknown;
|
|
77
|
+
messages?: readonly TraceProjectionMessage[];
|
|
78
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
79
|
+
}
|
|
80
|
+
/** Trace-level facts. All timing is optional; absence is honest. */
|
|
81
|
+
interface TraceProjectionTrace {
|
|
82
|
+
traceId: string;
|
|
83
|
+
taskRunId?: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
startedAt?: string;
|
|
86
|
+
endedAt?: string;
|
|
87
|
+
durationMs?: number;
|
|
88
|
+
complete: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The immutable read snapshot. Identical JSON shape across canonical, local,
|
|
92
|
+
* and legacy-flow sources — only `source` and `capabilities` differ.
|
|
93
|
+
*/
|
|
94
|
+
interface TraceProjectionSnapshot {
|
|
95
|
+
schemaVersion: 1;
|
|
96
|
+
projectionVersion: number;
|
|
97
|
+
source: "canonical" | "local" | "legacy-flow";
|
|
98
|
+
trace: TraceProjectionTrace;
|
|
99
|
+
capabilities: TraceProjectionCapabilities;
|
|
100
|
+
observations: readonly TraceProjectionObservation[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* TraceView — typed, capability-gated, derived access over a
|
|
105
|
+
* {@link TraceProjectionSnapshot}. This is the read model the projection-first
|
|
106
|
+
* assertion surface queries. It is the projection analogue of `FlowView`.
|
|
107
|
+
*
|
|
108
|
+
* The defining difference from `FlowView` is **capability honesty**: when the
|
|
109
|
+
* snapshot declares a category of evidence `unavailable`, the derived numeric
|
|
110
|
+
* facts (`durationMs`, `failedActions`, `turnCount`) return `undefined` rather
|
|
111
|
+
* than zero — so an assertion like `t.maxDurationMs` can record an explicit
|
|
112
|
+
* `unsupported` outcome instead of vacuously passing against a fabricated 0ms.
|
|
113
|
+
*
|
|
114
|
+
* `toolNamesInOrder` sorts by observation invocation time (`startedAt`) with a
|
|
115
|
+
* deterministic span-ID tie-breaker — NOT array/completion order. This fixes
|
|
116
|
+
* the drift where concurrent tools appeared in completion order.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
/** A tool call derived from a `TOOL` observation. */
|
|
120
|
+
interface TraceToolCall {
|
|
121
|
+
spanId: string;
|
|
122
|
+
name: string;
|
|
123
|
+
input?: unknown;
|
|
124
|
+
output?: unknown;
|
|
125
|
+
status: ObservationStatus;
|
|
126
|
+
startedAt?: string;
|
|
127
|
+
}
|
|
128
|
+
/** A skill load derived from a `SKILL` observation. */
|
|
129
|
+
interface TraceSkillLoad {
|
|
130
|
+
spanId: string;
|
|
131
|
+
skill: string;
|
|
132
|
+
startedAt?: string;
|
|
133
|
+
}
|
|
134
|
+
/** A subagent delegation derived from an `AGENT` observation. */
|
|
135
|
+
interface TraceSubagentCall {
|
|
136
|
+
spanId: string;
|
|
137
|
+
agent: string;
|
|
138
|
+
output?: unknown;
|
|
139
|
+
status: ObservationStatus;
|
|
140
|
+
startedAt?: string;
|
|
141
|
+
}
|
|
142
|
+
declare class TraceView {
|
|
143
|
+
readonly snapshot: TraceProjectionSnapshot;
|
|
144
|
+
constructor(snapshot: TraceProjectionSnapshot);
|
|
145
|
+
/** Evidence availability for a capability. */
|
|
146
|
+
requireCapability(capability: keyof TraceProjectionCapabilities): EvidenceAvailability;
|
|
147
|
+
/** Whether a capability is reported as available (not partial/unavailable). */
|
|
148
|
+
private isAvailable;
|
|
149
|
+
/** All chat messages flattened across generation observations, in order. */
|
|
150
|
+
get messages(): readonly TraceProjectionMessage[];
|
|
151
|
+
/** Tool calls derived from `TOOL` observations, in invocation order. */
|
|
152
|
+
get toolCalls(): readonly TraceToolCall[];
|
|
153
|
+
/** Tool names in invocation order with deterministic span-ID tie-breaking. */
|
|
154
|
+
get toolNamesInOrder(): readonly string[];
|
|
155
|
+
/** Skill loads derived from `SKILL` observations, in invocation order. */
|
|
156
|
+
get skillLoads(): readonly TraceSkillLoad[];
|
|
157
|
+
/** Subagent delegations derived from `AGENT` observations, in invocation order. */
|
|
158
|
+
get subagentCalls(): readonly TraceSubagentCall[];
|
|
159
|
+
/** Last assistant message content — the agent's "reply". Empty if none. */
|
|
160
|
+
get reply(): string;
|
|
161
|
+
/**
|
|
162
|
+
* Number of completed assistant turns, or `undefined` when message evidence
|
|
163
|
+
* is unavailable (capability honesty).
|
|
164
|
+
*/
|
|
165
|
+
get turnCount(): number | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Number of tool/subagent observations that reported an error, or `undefined`
|
|
168
|
+
* when error evidence is unavailable (capability honesty).
|
|
169
|
+
*/
|
|
170
|
+
get failedActions(): number | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* Total execution duration in milliseconds, or `undefined` when timing
|
|
173
|
+
* evidence is unavailable (capability honesty). Uses trace-level
|
|
174
|
+
* startedAt/endedAt when present.
|
|
175
|
+
*/
|
|
176
|
+
get durationMs(): number | undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Observations sorted deterministically by invocation time then span ID.
|
|
179
|
+
* Memoized per TraceView instance since the snapshot is immutable.
|
|
180
|
+
*/
|
|
181
|
+
private get sortedObservations();
|
|
182
|
+
private _sorted;
|
|
183
|
+
}
|
|
20
184
|
|
|
21
185
|
declare class TaskFiles {
|
|
22
186
|
private entries;
|
|
@@ -138,103 +302,6 @@ type TypedAdapterDefinition<TName extends string, TDeliverables extends Record<s
|
|
|
138
302
|
collectDeliverables: (ctx: CollectDeliverablesContext) => Promise<TCollected>;
|
|
139
303
|
};
|
|
140
304
|
|
|
141
|
-
/**
|
|
142
|
-
* Trace Projection snapshot contract.
|
|
143
|
-
*
|
|
144
|
-
* This is the immutable transport/read snapshot of a Trace Projection — the
|
|
145
|
-
* query-optimized representation shared by the dashboard and agent-task
|
|
146
|
-
* assertions. It is NOT a new domain entity and never a source of truth; the
|
|
147
|
-
* canonical OpenTelemetry spans remain authoritative.
|
|
148
|
-
*
|
|
149
|
-
* Both the Python backend and the TypeScript SDK MUST serialize to this exact
|
|
150
|
-
* lower-camel-case JSON contract, so assertions read the same shape whether
|
|
151
|
-
* the snapshot came from the canonical repository, a local/offline recorder,
|
|
152
|
-
* or a legacy-Flow compatibility adapter.
|
|
153
|
-
*
|
|
154
|
-
* Rules:
|
|
155
|
-
* - `schemaVersion` versions the JSON contract.
|
|
156
|
-
* - `projectionVersion` identifies the normalizer/projector interpretation.
|
|
157
|
-
* - `source` is diagnostic; only `"canonical"` represents a durably projected
|
|
158
|
-
* Trace.
|
|
159
|
-
* - `complete` means the task execution root ended and every span in the
|
|
160
|
-
* acknowledged export was projected. It does not promise no unrelated
|
|
161
|
-
* service will ever export a late span.
|
|
162
|
-
* - Missing evidence is represented through `capabilities`, never converted to
|
|
163
|
-
* empty arrays, zero duration, or successful status.
|
|
164
|
-
* - Observations are immutable and sorted deterministically by invocation
|
|
165
|
-
* time, then span ID. Missing timestamps sort after timestamped ones.
|
|
166
|
-
*/
|
|
167
|
-
/** Whether a category of evidence is present in the projection. */
|
|
168
|
-
type EvidenceAvailability = "available" | "partial" | "unavailable";
|
|
169
|
-
/** Lifecycle status of an observation. `unset` = the source had no status. */
|
|
170
|
-
type ObservationStatus = "unset" | "ok" | "error";
|
|
171
|
-
/** What kind of Span an Observation was derived from. */
|
|
172
|
-
type ObservationType = "SPAN" | "GENERATION" | "TOOL" | "AGENT" | "SKILL" | "CHAIN" | "RETRIEVER" | "EMBEDDING" | "GUARDRAIL";
|
|
173
|
-
/**
|
|
174
|
-
* Per-category evidence availability. Every category must declare honestly
|
|
175
|
-
* what it carries so assertions can fail closed when evidence is missing
|
|
176
|
-
* instead of vacuously passing.
|
|
177
|
-
*/
|
|
178
|
-
interface TraceProjectionCapabilities {
|
|
179
|
-
messages: EvidenceAvailability;
|
|
180
|
-
tools: EvidenceAvailability;
|
|
181
|
-
errors: EvidenceAvailability;
|
|
182
|
-
timing: EvidenceAvailability;
|
|
183
|
-
skills: EvidenceAvailability;
|
|
184
|
-
subagents: EvidenceAvailability;
|
|
185
|
-
}
|
|
186
|
-
/** One chat message reconstructed from a generation observation. */
|
|
187
|
-
interface TraceProjectionMessage {
|
|
188
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
189
|
-
content: string;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* A derived interpretation of one Span, as shown by the dashboard and read by
|
|
193
|
-
* assertions. Unknown span kinds survive as `SPAN`; hierarchy is preserved via
|
|
194
|
-
* `parentSpanId`.
|
|
195
|
-
*/
|
|
196
|
-
interface TraceProjectionObservation {
|
|
197
|
-
spanId: string;
|
|
198
|
-
parentSpanId?: string;
|
|
199
|
-
type: ObservationType;
|
|
200
|
-
name: string;
|
|
201
|
-
startedAt?: string;
|
|
202
|
-
endedAt?: string;
|
|
203
|
-
durationMs?: number;
|
|
204
|
-
status: ObservationStatus;
|
|
205
|
-
errorMessage?: string;
|
|
206
|
-
input?: unknown;
|
|
207
|
-
output?: unknown;
|
|
208
|
-
model?: string;
|
|
209
|
-
toolName?: string;
|
|
210
|
-
toolParameters?: unknown;
|
|
211
|
-
toolResult?: unknown;
|
|
212
|
-
messages?: readonly TraceProjectionMessage[];
|
|
213
|
-
metadata?: Readonly<Record<string, unknown>>;
|
|
214
|
-
}
|
|
215
|
-
/** Trace-level facts. All timing is optional; absence is honest. */
|
|
216
|
-
interface TraceProjectionTrace {
|
|
217
|
-
traceId: string;
|
|
218
|
-
taskRunId?: string;
|
|
219
|
-
name?: string;
|
|
220
|
-
startedAt?: string;
|
|
221
|
-
endedAt?: string;
|
|
222
|
-
durationMs?: number;
|
|
223
|
-
complete: boolean;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* The immutable read snapshot. Identical JSON shape across canonical, local,
|
|
227
|
-
* and legacy-flow sources — only `source` and `capabilities` differ.
|
|
228
|
-
*/
|
|
229
|
-
interface TraceProjectionSnapshot {
|
|
230
|
-
schemaVersion: 1;
|
|
231
|
-
projectionVersion: number;
|
|
232
|
-
source: "canonical" | "local" | "legacy-flow";
|
|
233
|
-
trace: TraceProjectionTrace;
|
|
234
|
-
capabilities: TraceProjectionCapabilities;
|
|
235
|
-
observations: readonly TraceProjectionObservation[];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
305
|
/**
|
|
239
306
|
* The outcome of a single assertion.
|
|
240
307
|
*
|
|
@@ -423,88 +490,6 @@ type TaskRunResult = {
|
|
|
423
490
|
runConfiguration?: AgentTaskRunConfiguration;
|
|
424
491
|
};
|
|
425
492
|
|
|
426
|
-
/**
|
|
427
|
-
* TraceView — typed, capability-gated, derived access over a
|
|
428
|
-
* {@link TraceProjectionSnapshot}. This is the read model the projection-first
|
|
429
|
-
* assertion surface queries. It is the projection analogue of `FlowView`.
|
|
430
|
-
*
|
|
431
|
-
* The defining difference from `FlowView` is **capability honesty**: when the
|
|
432
|
-
* snapshot declares a category of evidence `unavailable`, the derived numeric
|
|
433
|
-
* facts (`durationMs`, `failedActions`, `turnCount`) return `undefined` rather
|
|
434
|
-
* than zero — so an assertion like `t.maxDurationMs` can record an explicit
|
|
435
|
-
* `unsupported` outcome instead of vacuously passing against a fabricated 0ms.
|
|
436
|
-
*
|
|
437
|
-
* `toolNamesInOrder` sorts by observation invocation time (`startedAt`) with a
|
|
438
|
-
* deterministic span-ID tie-breaker — NOT array/completion order. This fixes
|
|
439
|
-
* the drift where concurrent tools appeared in completion order.
|
|
440
|
-
*/
|
|
441
|
-
|
|
442
|
-
/** A tool call derived from a `TOOL` observation. */
|
|
443
|
-
interface TraceToolCall {
|
|
444
|
-
spanId: string;
|
|
445
|
-
name: string;
|
|
446
|
-
input?: unknown;
|
|
447
|
-
output?: unknown;
|
|
448
|
-
status: ObservationStatus;
|
|
449
|
-
startedAt?: string;
|
|
450
|
-
}
|
|
451
|
-
/** A skill load derived from a `SKILL` observation. */
|
|
452
|
-
interface TraceSkillLoad {
|
|
453
|
-
spanId: string;
|
|
454
|
-
skill: string;
|
|
455
|
-
startedAt?: string;
|
|
456
|
-
}
|
|
457
|
-
/** A subagent delegation derived from an `AGENT` observation. */
|
|
458
|
-
interface TraceSubagentCall {
|
|
459
|
-
spanId: string;
|
|
460
|
-
agent: string;
|
|
461
|
-
output?: unknown;
|
|
462
|
-
status: ObservationStatus;
|
|
463
|
-
startedAt?: string;
|
|
464
|
-
}
|
|
465
|
-
declare class TraceView {
|
|
466
|
-
readonly snapshot: TraceProjectionSnapshot;
|
|
467
|
-
constructor(snapshot: TraceProjectionSnapshot);
|
|
468
|
-
/** Evidence availability for a capability. */
|
|
469
|
-
requireCapability(capability: keyof TraceProjectionCapabilities): EvidenceAvailability;
|
|
470
|
-
/** Whether a capability is reported as available (not partial/unavailable). */
|
|
471
|
-
private isAvailable;
|
|
472
|
-
/** All chat messages flattened across generation observations, in order. */
|
|
473
|
-
get messages(): readonly TraceProjectionMessage[];
|
|
474
|
-
/** Tool calls derived from `TOOL` observations, in invocation order. */
|
|
475
|
-
get toolCalls(): readonly TraceToolCall[];
|
|
476
|
-
/** Tool names in invocation order with deterministic span-ID tie-breaking. */
|
|
477
|
-
get toolNamesInOrder(): readonly string[];
|
|
478
|
-
/** Skill loads derived from `SKILL` observations, in invocation order. */
|
|
479
|
-
get skillLoads(): readonly TraceSkillLoad[];
|
|
480
|
-
/** Subagent delegations derived from `AGENT` observations, in invocation order. */
|
|
481
|
-
get subagentCalls(): readonly TraceSubagentCall[];
|
|
482
|
-
/** Last assistant message content — the agent's "reply". Empty if none. */
|
|
483
|
-
get reply(): string;
|
|
484
|
-
/**
|
|
485
|
-
* Number of completed assistant turns, or `undefined` when message evidence
|
|
486
|
-
* is unavailable (capability honesty).
|
|
487
|
-
*/
|
|
488
|
-
get turnCount(): number | undefined;
|
|
489
|
-
/**
|
|
490
|
-
* Number of tool/subagent observations that reported an error, or `undefined`
|
|
491
|
-
* when error evidence is unavailable (capability honesty).
|
|
492
|
-
*/
|
|
493
|
-
get failedActions(): number | undefined;
|
|
494
|
-
/**
|
|
495
|
-
* Total execution duration in milliseconds, or `undefined` when timing
|
|
496
|
-
* evidence is unavailable (capability honesty). Uses trace-level
|
|
497
|
-
* startedAt/endedAt when present.
|
|
498
|
-
*/
|
|
499
|
-
get durationMs(): number | undefined;
|
|
500
|
-
/**
|
|
501
|
-
* Observations sorted deterministically by invocation time then span ID.
|
|
502
|
-
* Memoized per TraceView instance since the snapshot is immutable.
|
|
503
|
-
*/
|
|
504
|
-
private get sortedObservations();
|
|
505
|
-
private _sorted;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
493
|
/**
|
|
509
494
|
* Value matchers for `t.check(value, matcher)`. Small, composable, and the
|
|
510
495
|
* single way to assert on deliverables/values (replaces the old `expect`).
|
|
@@ -536,6 +521,42 @@ declare function matchValue<T>(actual: T, matcher: ValueMatcher<T>): boolean;
|
|
|
536
521
|
/** Normalized Levenshtein similarity. Pass when score ≥ threshold (default 0.8). */
|
|
537
522
|
declare function similarity(expected: string, threshold?: number): Matcher<unknown>;
|
|
538
523
|
|
|
524
|
+
/**
|
|
525
|
+
* LLM-as-judge call. Used by `t.judge(values, instruction)` to evaluate
|
|
526
|
+
* deliverables against a natural-language rubric. Calls an OpenAI-compatible
|
|
527
|
+
* endpoint (OpenRouter, OpenAI, etc.) via fetch and parses the verdict.
|
|
528
|
+
*/
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* What a judge call is grading — everything the SDK knows that a bare
|
|
532
|
+
* (deliverable, instruction) pair withholds (#161). Threaded automatically
|
|
533
|
+
* from the task definition and the check registry; consumed by
|
|
534
|
+
* {@link JudgePromptBuilder}.
|
|
535
|
+
*/
|
|
536
|
+
type JudgeContext = {
|
|
537
|
+
/** The task being graded (`TaskDefinition.id`). */
|
|
538
|
+
taskId: string;
|
|
539
|
+
/** `TaskDefinition.description`, when the task sets one. */
|
|
540
|
+
taskDescription?: string;
|
|
541
|
+
/** The name of the check invoking the judge (the `test(...)` id). */
|
|
542
|
+
checkName: string;
|
|
543
|
+
/** The rubric instruction for this call. */
|
|
544
|
+
instruction: string;
|
|
545
|
+
/** Deliverable keys the check read before judging, in read order. */
|
|
546
|
+
deliverableNames?: string[];
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Builds the judge *briefing* — not the whole prompt. The SDK appends its
|
|
550
|
+
* own response contract to whatever `system` comes back and keeps
|
|
551
|
+
* `response_format`, so a builder cannot break verdict parsing. Keep the
|
|
552
|
+
* returned `system` constant per task (vary only `user`) to preserve the
|
|
553
|
+
* cached prompt prefix across a task's criteria.
|
|
554
|
+
*/
|
|
555
|
+
type JudgePromptBuilder = (ctx: JudgeContext) => {
|
|
556
|
+
system?: string;
|
|
557
|
+
user?: string;
|
|
558
|
+
};
|
|
559
|
+
|
|
539
560
|
/**
|
|
540
561
|
* The assertion surface — `t`. Flat and eve-style: reads the trace (via
|
|
541
562
|
* {@link TraceView}) for behavioural checks and grades explicit values via
|
|
@@ -559,7 +580,8 @@ type ToolCallOptions = {
|
|
|
559
580
|
/**
|
|
560
581
|
* LLM judge model config for `t.judge(...)` calls in checks.ts. Threaded
|
|
561
582
|
* through `runTask({ judge })` from the caller — the runner has no opinion
|
|
562
|
-
* about which model grades a deliverable.
|
|
583
|
+
* about which model grades a deliverable. A task definition may also set a
|
|
584
|
+
* `judge` layer of its own; see {@link resolveJudgeConfig} for precedence.
|
|
563
585
|
*/
|
|
564
586
|
type JudgeConfig = {
|
|
565
587
|
/** Model id, e.g. ``"google/gemini-2.5-flash-lite"``. */
|
|
@@ -568,6 +590,24 @@ type JudgeConfig = {
|
|
|
568
590
|
baseURL?: string;
|
|
569
591
|
/** Override the API key (defaults to env). */
|
|
570
592
|
apiKey?: string;
|
|
593
|
+
/**
|
|
594
|
+
* Build a custom judge briefing from the threaded context (#161). The SDK
|
|
595
|
+
* keeps ownership of the JSON response contract — see
|
|
596
|
+
* {@link JudgePromptBuilder}.
|
|
597
|
+
*/
|
|
598
|
+
prompt?: JudgePromptBuilder;
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* What a check knows about its scope when it invokes the judge — the
|
|
602
|
+
* task-level frame threaded from the runner plus the deliverables the check
|
|
603
|
+
* has read so far.
|
|
604
|
+
*/
|
|
605
|
+
type JudgeScope = {
|
|
606
|
+
taskId: string;
|
|
607
|
+
taskDescription?: string;
|
|
608
|
+
checkName: string;
|
|
609
|
+
/** Deliverable keys read so far, recorded by the check runner. */
|
|
610
|
+
readDeliverableNames?: () => string[];
|
|
571
611
|
};
|
|
572
612
|
interface TestContext {
|
|
573
613
|
/** Asserts a matching tool was called. Pass `{ count }` for an exact count. */
|
|
@@ -627,6 +667,28 @@ interface TestContext {
|
|
|
627
667
|
*/
|
|
628
668
|
declare const TEST_METHOD_NAMES: readonly ["calledTool", "notCalledTool", "toolOrder", "usedNoTools", "maxToolCalls", "noFailedActions", "loadedSkill", "calledSubagent", "messageIncludes", "maxTurns", "maxDurationMs", "assert", "check", "judge"];
|
|
629
669
|
|
|
670
|
+
type TaskDefinition<TAdapterName extends string = string, TDeliverable extends string = string> = {
|
|
671
|
+
id: string;
|
|
672
|
+
adapter: TAdapterName;
|
|
673
|
+
description?: string;
|
|
674
|
+
deliverables: TDeliverable[];
|
|
675
|
+
maxTurns?: number;
|
|
676
|
+
metadata?: Record<string, unknown>;
|
|
677
|
+
checks?: string | false;
|
|
678
|
+
/**
|
|
679
|
+
* Task-level judge layer (#161): overrides the run-level `runTask({ judge })`
|
|
680
|
+
* config and is itself overridden per `t.judge` call. Lets a task grade
|
|
681
|
+
* differently from its suite — a stronger model, or a custom briefing via
|
|
682
|
+
* `prompt` that tells the judge what it is grading.
|
|
683
|
+
*/
|
|
684
|
+
judge?: Partial<JudgeConfig>;
|
|
685
|
+
};
|
|
686
|
+
type TaskConfig<TDeliverable extends string = string> = Omit<TaskDefinition<string, TDeliverable>, "adapter">;
|
|
687
|
+
type FileEntry = {
|
|
688
|
+
relativePath: string;
|
|
689
|
+
absolutePath: string;
|
|
690
|
+
};
|
|
691
|
+
|
|
630
692
|
/**
|
|
631
693
|
* Check runner — builds a {@link TestContext} (`t`) per registered check from
|
|
632
694
|
* a {@link TraceProjectionSnapshot}, runs it, and aggregates every recorded
|
|
@@ -1403,4 +1465,4 @@ declare function canonicalManifestJson(manifest: TaskRevisionManifestV1): string
|
|
|
1403
1465
|
/** SHA-256 (lowercase hex) of the canonical manifest JSON's UTF-8 bytes. */
|
|
1404
1466
|
declare function contentSha256(manifest: TaskRevisionManifestV1): string;
|
|
1405
1467
|
|
|
1406
|
-
export { type AISDKResult, type AdapterDefinition, type AdapterRuntimeState, type AdapterSession, type AgentTaskCliOptions, type AgentTaskRunConfiguration, AgentTaskRunError, type AgentTaskRunSummary, type AgentTaskRuntime, AgentTaskTraceContext, AgentTaskTraceOptions, type AgentTurnResult, type AnthropicMessage, type ApoRunContext, ApoSpanProcessor, type ArtifactUploadConfig, type CheckContext, type CheckGroup, type CleanupContext, type CollectDeliverablesContext, type CollectedDeliverables, type DeliverableDefinition, type DeliverableSummary, type DeliverableValidationResult, type DescribeRegistration, type FileArtifact, type FileArtifactOptions, type FileEntry, type Flow, type FlowEvent, FlowView, type InitializeContext, type JudgeConfig, type LoadedTask, type ManifestFile, type ManifestFileInput, type Matcher, type ModeClass, type NameMatcher, type OpenAIMessage, type PreparedTaskResult, type RegisterApoTracingOptions, type RejudgeCheckStability, type RejudgeEndpoints, RejudgeError, type RejudgeOptions, type RejudgeOutcome, type RunTaskOptions, type StartSessionContext, TEST_METHOD_NAMES, type TaskConfig, type TaskDefinition, type TaskEvaluationResult, TaskFiles, type TaskRevisionManifestV1, type TaskRunResult, type TaskScope, type TaskTranscript, type TaskTranscriptTurn, type TestContext, type TestRegistration, type ToolCallOptions, type ToolCallStatus, type TurnContext, type TurnFn, type TurnRecord, type TypedAdapterDefinition, type ValueMatcher, buildManifest, canonicalManifestJson, contentSha256, defineAdapter, defineTask, describe, discoverAgentTaskDirs, equals, fileArtifact, filePaths, fromAISDK, fromAnthropicMessages, fromOpenAIMessages, getActiveApoRun, getTaskTurn, includes, isFileArtifact, loadTask, loadTaskRuntime, matchValue, matches, normalizeManifestPath, parseAgentTaskCliArgs, persistFileArtifacts, registerApoTracing, rejudgeTaskRun, resetApoTracing, resetFlowChecks, resetTaskRegistry, resetTaskTurn, resolveTurn, runAgentTaskCli, runTask, runTaskDir, satisfies, sha256Hex, similarity, task, defineCheck as test, turn, withApoRun, withApoRunSync };
|
|
1468
|
+
export { type AISDKResult, type AdapterDefinition, type AdapterRuntimeState, type AdapterSession, type AgentTaskCliOptions, type AgentTaskRunConfiguration, AgentTaskRunError, type AgentTaskRunSummary, type AgentTaskRuntime, AgentTaskTraceContext, AgentTaskTraceOptions, type AgentTurnResult, type AnthropicMessage, type ApoRunContext, ApoSpanProcessor, type ArtifactUploadConfig, type CheckContext, type CheckGroup, type CleanupContext, type CollectDeliverablesContext, type CollectedDeliverables, type DeliverableDefinition, type DeliverableSummary, type DeliverableValidationResult, type DescribeRegistration, type FileArtifact, type FileArtifactOptions, type FileEntry, type Flow, type FlowEvent, FlowView, type InitializeContext, type JudgeConfig, type JudgeContext, type JudgePromptBuilder, type JudgeScope, type LoadedTask, type ManifestFile, type ManifestFileInput, type Matcher, type ModeClass, type NameMatcher, type OpenAIMessage, type PreparedTaskResult, type RegisterApoTracingOptions, type RejudgeCheckStability, type RejudgeEndpoints, RejudgeError, type RejudgeOptions, type RejudgeOutcome, type RunTaskOptions, type StartSessionContext, TEST_METHOD_NAMES, type TaskConfig, type TaskDefinition, type TaskEvaluationResult, TaskFiles, type TaskRevisionManifestV1, type TaskRunResult, type TaskScope, type TaskTranscript, type TaskTranscriptTurn, type TestContext, type TestRegistration, type ToolCallOptions, type ToolCallStatus, type TurnContext, type TurnFn, type TurnRecord, type TypedAdapterDefinition, type ValueMatcher, buildManifest, canonicalManifestJson, contentSha256, defineAdapter, defineTask, describe, discoverAgentTaskDirs, equals, fileArtifact, filePaths, fromAISDK, fromAnthropicMessages, fromOpenAIMessages, getActiveApoRun, getTaskTurn, includes, isFileArtifact, loadTask, loadTaskRuntime, matchValue, matches, normalizeManifestPath, parseAgentTaskCliArgs, persistFileArtifacts, registerApoTracing, rejudgeTaskRun, resetApoTracing, resetFlowChecks, resetTaskRegistry, resetTaskTurn, resolveTurn, runAgentTaskCli, runTask, runTaskDir, satisfies, sha256Hex, similarity, task, defineCheck as test, turn, withApoRun, withApoRunSync };
|