@apo-ai/sdk 0.9.0 → 0.9.2
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/dist/agent-task/integrations/ai-sdk.d.ts +1 -1
- package/dist/agent-task/integrations/anthropic.d.ts +1 -1
- package/dist/agent-task/integrations/openai.d.ts +1 -1
- package/dist/agent-task/public.d.ts +446 -7
- package/dist/agent-task/public.js +1713 -340
- package/dist/agent-task/public.js.map +1 -1
- package/dist/{chunk-KLZLE3VQ.js → chunk-LO343UZO.js} +31 -15
- package/dist/chunk-LO343UZO.js.map +1 -0
- package/dist/otel/index.d.ts +13 -1
- package/dist/otel/index.js +1 -1
- package/dist/{tracing-CevT0hQg.d.ts → tracing-Dqbuc7AK.d.ts} +3 -0
- package/package.json +3 -1
- package/dist/chunk-KLZLE3VQ.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AgentTaskTraceContext, a as AgentTaskTraceOptions } from '../tracing-
|
|
1
|
+
import { A as AgentTaskTraceContext, a as AgentTaskTraceOptions } from '../tracing-Dqbuc7AK.js';
|
|
2
2
|
export { CreateApoTracerOptions, createApoTracer } from './integrations/ai-sdk.js';
|
|
3
3
|
export { CreateApoOpenAIOptions, createApoOpenAI } from './integrations/openai.js';
|
|
4
4
|
export { CreateApoAnthropicOptions, createApoAnthropic } from './integrations/anthropic.js';
|
|
@@ -278,6 +278,61 @@ declare function getTaskTurn(): TurnFn | undefined;
|
|
|
278
278
|
declare function resetTaskTurn(): void;
|
|
279
279
|
declare function resolveTurn(adapterTurn: TurnFn | undefined, taskTurn: TurnFn | undefined): TurnFn;
|
|
280
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Normalized transcript model — the common shape every harness transcript
|
|
283
|
+
* parser produces, and the input to the OTLP translator.
|
|
284
|
+
*
|
|
285
|
+
* The model is deliberately lossy-but-sufficient for trace reconstruction:
|
|
286
|
+
* per turn it keeps the user/assistant text, thinking, tool calls with their
|
|
287
|
+
* results, model identity, and token usage. Anything the projection cannot
|
|
288
|
+
* use (streaming chunk boundaries, harness housekeeping) is folded away.
|
|
289
|
+
*/
|
|
290
|
+
type TranscriptSource = "claude-code" | "codex";
|
|
291
|
+
type TranscriptUsage = {
|
|
292
|
+
inputTokens?: number;
|
|
293
|
+
outputTokens?: number;
|
|
294
|
+
cacheReadTokens?: number;
|
|
295
|
+
cacheWriteTokens?: number;
|
|
296
|
+
reasoningTokens?: number;
|
|
297
|
+
};
|
|
298
|
+
type TranscriptToolCall = {
|
|
299
|
+
callId: string;
|
|
300
|
+
name: string;
|
|
301
|
+
/** Arguments exactly as recorded — parsed object when the harness allows, raw string otherwise. */
|
|
302
|
+
input: unknown;
|
|
303
|
+
/** Rendered result text or the raw output payload; absent when the transcript never recorded one. */
|
|
304
|
+
result?: unknown;
|
|
305
|
+
/** ISO timestamp of the call, when the transcript carries one. */
|
|
306
|
+
startedAt?: string;
|
|
307
|
+
/** ISO timestamp of the matching result, when the transcript carries one. */
|
|
308
|
+
endedAt?: string;
|
|
309
|
+
};
|
|
310
|
+
type TranscriptTurn = {
|
|
311
|
+
/** Zero-based position of the turn within the session. */
|
|
312
|
+
index: number;
|
|
313
|
+
/** ISO timestamp of the user message that opened the turn. */
|
|
314
|
+
startedAt: string;
|
|
315
|
+
/** ISO timestamp of the last observed event in the turn, when known. */
|
|
316
|
+
endedAt?: string;
|
|
317
|
+
model?: string;
|
|
318
|
+
userMessage?: string;
|
|
319
|
+
assistantMessage?: string;
|
|
320
|
+
/** Extended-thinking text (Claude) or reasoning summaries (Codex). */
|
|
321
|
+
thinkingText?: string;
|
|
322
|
+
/** Codex commentary-phase messages (progress narration, not reasoning). */
|
|
323
|
+
commentary?: string[];
|
|
324
|
+
toolCalls: TranscriptToolCall[];
|
|
325
|
+
usage?: TranscriptUsage;
|
|
326
|
+
};
|
|
327
|
+
type ParsedTranscriptSession = {
|
|
328
|
+
source: TranscriptSource;
|
|
329
|
+
sessionId: string;
|
|
330
|
+
cwd?: string;
|
|
331
|
+
turns: TranscriptTurn[];
|
|
332
|
+
/** Non-fatal parse issues: torn lines, unterminated turns, unmatched outputs. */
|
|
333
|
+
warnings: string[];
|
|
334
|
+
};
|
|
335
|
+
|
|
281
336
|
type ValidatableSchemaLike = {
|
|
282
337
|
safeParse: (data: unknown) => {
|
|
283
338
|
success: boolean;
|
|
@@ -343,6 +398,21 @@ type CleanupContext = {
|
|
|
343
398
|
session?: AdapterSession;
|
|
344
399
|
trace: AgentTaskTraceContext;
|
|
345
400
|
};
|
|
401
|
+
/**
|
|
402
|
+
* A harness session transcript the adapter captured on disk.
|
|
403
|
+
*
|
|
404
|
+
* Declaring one opts the run into transcript-replay capture: after the turn
|
|
405
|
+
* loop, the runner parses the session file and replays it into the run —
|
|
406
|
+
* exported spans join the live trace and projection observations join the
|
|
407
|
+
* snapshot — so a harness that cannot emit OTel (Codex CLI, plain Claude
|
|
408
|
+
* Code, anything that only writes session JSONL) still produces a fully
|
|
409
|
+
* assertable trace. The file must exist and be complete when the turn loop
|
|
410
|
+
* ends; a missing file fails the run.
|
|
411
|
+
*/
|
|
412
|
+
type AdapterTranscriptCapture = {
|
|
413
|
+
source: TranscriptSource;
|
|
414
|
+
path: string;
|
|
415
|
+
};
|
|
346
416
|
type AdapterSession = {
|
|
347
417
|
/**
|
|
348
418
|
* The adapter's resolved model/effort for this run. Read by
|
|
@@ -351,6 +421,12 @@ type AdapterSession = {
|
|
|
351
421
|
* that do not report configuration.
|
|
352
422
|
*/
|
|
353
423
|
runConfiguration?: AgentTaskRunConfiguration;
|
|
424
|
+
/**
|
|
425
|
+
* The harness session transcript this run captured. Set as soon as the
|
|
426
|
+
* path is known (typically after the first `sendUserTurn`); the runner
|
|
427
|
+
* reads it once, after the turn loop. See {@link AdapterTranscriptCapture}.
|
|
428
|
+
*/
|
|
429
|
+
transcript?: AdapterTranscriptCapture;
|
|
354
430
|
sendUserTurn: (turn: unknown, context: {
|
|
355
431
|
trace: AgentTaskTraceContext;
|
|
356
432
|
turnNumber: number;
|
|
@@ -622,13 +698,16 @@ type EvaluationItemResult = {
|
|
|
622
698
|
/** Name of the deliverable this check was evaluated against. */
|
|
623
699
|
deliverable?: string;
|
|
624
700
|
/**
|
|
625
|
-
* What kind of evaluator produced this result
|
|
626
|
-
*
|
|
627
|
-
*
|
|
701
|
+
* What kind of evaluator produced this result, derived from the recorded
|
|
702
|
+
* assertions: ``"code"`` for purely deterministic checks, ``"llm"`` when
|
|
703
|
+
* every assertion judged, ``"agent"`` for pure agentic sessions,
|
|
704
|
+
* ``"mixed"`` when a check combines judged and deterministic assertions.
|
|
705
|
+
* LLM-backed assertions also carry ``evaluator_type: "llm"`` in
|
|
706
|
+
* {@link assertions}.
|
|
628
707
|
* - ``"regex"`` — pattern matching
|
|
629
708
|
* Older persisted results may still use ``"llm"`` at this level.
|
|
630
709
|
*/
|
|
631
|
-
evaluator_type?: "llm" | "code" | "agent" | "regex";
|
|
710
|
+
evaluator_type?: "llm" | "code" | "agent" | "regex" | "mixed";
|
|
632
711
|
/**
|
|
633
712
|
* If this check was judged by an LLM, details about the judge call
|
|
634
713
|
* (model, prompt, response, tokens, cost, latency). Populated by the
|
|
@@ -822,6 +901,111 @@ type AgentHistoryPlane = {
|
|
|
822
901
|
selfRunId?: string;
|
|
823
902
|
};
|
|
824
903
|
|
|
904
|
+
/**
|
|
905
|
+
* MCP plumbing for apo's two tool planes. The judge's budgeted toolset
|
|
906
|
+
* (`createMcpToolset`) wraps user-declared MCP servers into `t.agent`
|
|
907
|
+
* sessions under the same budget ledger and evidence-manifest discipline as
|
|
908
|
+
* the built-in evidence tools. `connectMcpServers` is the raw connect core
|
|
909
|
+
* shared with adapters — the agent under test is not apo's to budget, so
|
|
910
|
+
* adapters merge the namespaced `mcp__<server>__<tool>` tools themselves.
|
|
911
|
+
*
|
|
912
|
+
* Judge config layers exactly like the judge model config
|
|
913
|
+
* (`resolveJudgeConfig`): env/file (APO_JUDGE_MCP) ← runTask({ judgeTools })
|
|
914
|
+
* ← task.judgeTools ← per-call `t.agent(..., { tools: { mcp } })` — most
|
|
915
|
+
* specific wins, arrays replace, never concat. Task-level `mcpServers`
|
|
916
|
+
* (adapter plane) is a separate declaration honored by adapters that choose
|
|
917
|
+
* to (see TaskDefinition.mcpServers).
|
|
918
|
+
*
|
|
919
|
+
* The MCP client (`@ai-sdk/mcp`) is lazy-loaded: suites that never configure
|
|
920
|
+
* MCP servers must never pay for the dependency (pinned by the
|
|
921
|
+
* lazy-isolation test in tests/judge-mcp.test.ts).
|
|
922
|
+
*/
|
|
923
|
+
|
|
924
|
+
/** Stdio transport: the judge's machine spawns the server process. */
|
|
925
|
+
type McpStdioTransport = {
|
|
926
|
+
type: "stdio";
|
|
927
|
+
command: string;
|
|
928
|
+
args?: string[];
|
|
929
|
+
/**
|
|
930
|
+
* Environment for the spawned process. Values support `${VAR}` expansion
|
|
931
|
+
* from the judge process's environment at connect time; an unset variable
|
|
932
|
+
* is a load error, never an empty string.
|
|
933
|
+
*/
|
|
934
|
+
env?: Record<string, string>;
|
|
935
|
+
};
|
|
936
|
+
/** HTTP transport: an already-running remote server (Streamable HTTP). */
|
|
937
|
+
type McpHttpTransport = {
|
|
938
|
+
type: "http";
|
|
939
|
+
url: string;
|
|
940
|
+
/** Header values support `${VAR}` expansion like stdio env values. */
|
|
941
|
+
headers?: Record<string, string>;
|
|
942
|
+
};
|
|
943
|
+
/** One user MCP server the judge may call. Mirrors the industry shape. */
|
|
944
|
+
type McpServerConfig = {
|
|
945
|
+
/** Unique server name; its tools are exposed as `mcp__<name>__<tool>`. */
|
|
946
|
+
name: string;
|
|
947
|
+
transport: McpStdioTransport | McpHttpTransport;
|
|
948
|
+
/** Allowlist of raw server tool names (applied before namespacing). */
|
|
949
|
+
tools?: string[];
|
|
950
|
+
/** Denylist applied after the allowlist. */
|
|
951
|
+
excludeTools?: string[];
|
|
952
|
+
/** Per-tool-call timeout in ms. Default 30_000. */
|
|
953
|
+
timeoutMs?: number;
|
|
954
|
+
};
|
|
955
|
+
/** Layered judge-tools config, sibling of `JudgeConfig`. */
|
|
956
|
+
type JudgeToolsConfig = {
|
|
957
|
+
mcp?: McpServerConfig[];
|
|
958
|
+
};
|
|
959
|
+
/**
|
|
960
|
+
* Expand `${VAR}` placeholders in secret-bearing string maps (stdio env,
|
|
961
|
+
* HTTP headers). Unset variables throw naming the variable — a missing
|
|
962
|
+
* credential must fail visibly at load time, never collapse to "".
|
|
963
|
+
*/
|
|
964
|
+
declare function expandSecretPlaceholders(values: Record<string, string>): Record<string, string>;
|
|
965
|
+
/**
|
|
966
|
+
* Narrow, locally-owned view of an MCP client, mirroring the engine-facade
|
|
967
|
+
* discipline in agent-session.ts: never let tsc instantiate the library's
|
|
968
|
+
* generics. The real `@ai-sdk/mcp` client is structurally compatible.
|
|
969
|
+
*/
|
|
970
|
+
type McpRawTool = {
|
|
971
|
+
description?: unknown;
|
|
972
|
+
inputSchema?: unknown;
|
|
973
|
+
execute?: unknown;
|
|
974
|
+
};
|
|
975
|
+
type McpClientLike = {
|
|
976
|
+
tools: () => Promise<Record<string, McpRawTool>>;
|
|
977
|
+
close: () => Promise<void>;
|
|
978
|
+
};
|
|
979
|
+
type McpClientFactory = (args: {
|
|
980
|
+
server: McpServerConfig;
|
|
981
|
+
timeoutMs: number;
|
|
982
|
+
}) => Promise<McpClientLike>;
|
|
983
|
+
/**
|
|
984
|
+
* Resolve path-like stdio values against a base directory (the task dir):
|
|
985
|
+
* absolute values, "./" and "../" prefixes resolve; bare names stay bare so
|
|
986
|
+
* the spawn resolves them from PATH. Applied to TaskDefinition.mcpServers
|
|
987
|
+
* by adapters AND to layered judgeTools by runTask — "./mcp/server.mjs"
|
|
988
|
+
* means the same thing on both planes, independent of the runner's cwd.
|
|
989
|
+
*/
|
|
990
|
+
declare function resolveMcpServerPaths(servers: McpServerConfig[], baseDir: string): McpServerConfig[];
|
|
991
|
+
/**
|
|
992
|
+
* Connects one client per declared server and returns the RAW namespaced
|
|
993
|
+
* tools — no budget wrapping, because the agent under test is not apo's to
|
|
994
|
+
* budget (that discipline is judge-only, in `createMcpToolset` below).
|
|
995
|
+
* Adapters that drive an AI-SDK agent loop merge `tools` into their own tool
|
|
996
|
+
* record; `byServer` maps each server name to its exposed raw tool names.
|
|
997
|
+
*
|
|
998
|
+
* Connect failures throw naming the server after closing what already
|
|
999
|
+
* connected. Duplicate server names throw before anything spawns.
|
|
1000
|
+
*/
|
|
1001
|
+
declare function connectMcpServers(servers: McpServerConfig[], opts?: {
|
|
1002
|
+
clientFactory?: McpClientFactory;
|
|
1003
|
+
}): Promise<{
|
|
1004
|
+
tools: Record<string, unknown>;
|
|
1005
|
+
byServer: Record<string, string[]>;
|
|
1006
|
+
cleanup: () => Promise<void>;
|
|
1007
|
+
}>;
|
|
1008
|
+
|
|
825
1009
|
/**
|
|
826
1010
|
* The agentic judge — `t.agent`. A tool-using LLM session that investigates
|
|
827
1011
|
* the run's own evidence (deliverables, trace) before verdicting, powered by
|
|
@@ -856,6 +1040,7 @@ type AgentJudgeOptions = {
|
|
|
856
1040
|
/** Tool families; deliverables are always on. `trace: false` drops get_trace. */
|
|
857
1041
|
tools?: {
|
|
858
1042
|
trace?: boolean;
|
|
1043
|
+
mcp?: McpServerConfig[];
|
|
859
1044
|
};
|
|
860
1045
|
budget?: AgentBudget;
|
|
861
1046
|
label?: string;
|
|
@@ -1042,6 +1227,21 @@ type TaskDefinition<TAdapterName extends string = string, TDeliverable extends s
|
|
|
1042
1227
|
* `prompt` that tells the judge what it is grading.
|
|
1043
1228
|
*/
|
|
1044
1229
|
judge?: Partial<JudgeConfig>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Task-level judge-tools layer: MCP evidence servers for `t.agent` sessions
|
|
1232
|
+
* in this task. Overrides `runTask({ judgeTools })`, is overridden per
|
|
1233
|
+
* `t.agent(..., { tools: { mcp } })` call. Arrays replace, never concat.
|
|
1234
|
+
*/
|
|
1235
|
+
judgeTools?: JudgeToolsConfig;
|
|
1236
|
+
/**
|
|
1237
|
+
* MCP servers declared for the AGENT UNDER TEST (the adapter plane — a
|
|
1238
|
+
* separate declaration from `judgeTools`). Adapters that honor it resolve
|
|
1239
|
+
* relative `command`/`args` paths against the task directory and expose
|
|
1240
|
+
* the tools as `mcp__<server>__<tool>`; trace assertions can match those
|
|
1241
|
+
* stable names. Declaring the harness's tool surface here keeps the task
|
|
1242
|
+
* portable across harnesses.
|
|
1243
|
+
*/
|
|
1244
|
+
mcpServers?: McpServerConfig[];
|
|
1045
1245
|
};
|
|
1046
1246
|
type TaskConfig<TDeliverable extends string = string> = Omit<TaskDefinition<string, TDeliverable>, "adapter">;
|
|
1047
1247
|
type FileEntry = {
|
|
@@ -1204,6 +1404,16 @@ declare function loadTask(taskDir: string): Promise<LoadedTask>;
|
|
|
1204
1404
|
|
|
1205
1405
|
declare function defineAdapter<const TName extends string, const TDeliverables extends Record<string, DeliverableDefinition>, TCollected extends CollectedDeliverables>(adapter: TypedAdapterDefinition<TName, TDeliverables, TCollected>): TypedAdapterDefinition<TName, TDeliverables, TCollected>;
|
|
1206
1406
|
|
|
1407
|
+
/**
|
|
1408
|
+
* Env-only auth headers for apo backends: the runner's credential contract
|
|
1409
|
+
* (`APO_PUBLIC_KEY`+`APO_SECRET_KEY` → Basic, `APO_AUTH_TOKEN` → Bearer)
|
|
1410
|
+
* resolved with no arguments. Same name as the otel entry's builder, but
|
|
1411
|
+
* that one accepts explicit keys and returns `{}` when unauthenticated —
|
|
1412
|
+
* this variant reports "no headers" as `undefined` instead. Both share one
|
|
1413
|
+
* implementation in `apo-auth.ts`.
|
|
1414
|
+
*/
|
|
1415
|
+
declare function buildApoAuthHeaders(): Record<string, string> | undefined;
|
|
1416
|
+
|
|
1207
1417
|
/**
|
|
1208
1418
|
* file Artifact declaration helper.
|
|
1209
1419
|
*
|
|
@@ -1486,6 +1696,11 @@ type RunTaskOptions = {
|
|
|
1486
1696
|
tracing?: AgentTaskTraceOptions;
|
|
1487
1697
|
/** LLM judge model config for `t.judge(...)` calls in the task checks. */
|
|
1488
1698
|
judge?: JudgeConfig;
|
|
1699
|
+
/**
|
|
1700
|
+
* Judge tool config for `t.agent(...)` sessions (MCP evidence servers).
|
|
1701
|
+
* Layered under `TaskDefinition.judgeTools` and per-call `tools.mcp`.
|
|
1702
|
+
*/
|
|
1703
|
+
judgeTools?: JudgeToolsConfig;
|
|
1489
1704
|
onTurn?: (turnNumber: number, userAction: TaskTranscriptTurn["userAction"], agentResponse: unknown) => void;
|
|
1490
1705
|
/**
|
|
1491
1706
|
* Skip the internal `loadTask(taskDir)` call and reuse an already-loaded
|
|
@@ -1609,6 +1824,7 @@ declare function discoverAgentTaskDirs(rootDir: string): string[];
|
|
|
1609
1824
|
|
|
1610
1825
|
type AgentTaskRuntime = {
|
|
1611
1826
|
judge?: JudgeConfig;
|
|
1827
|
+
judgeTools?: JudgeToolsConfig;
|
|
1612
1828
|
};
|
|
1613
1829
|
type AgentTaskRunSummary = {
|
|
1614
1830
|
taskDir: string;
|
|
@@ -1629,7 +1845,16 @@ type AgentTaskRunSummary = {
|
|
|
1629
1845
|
runConfiguration?: AgentTaskRunConfiguration;
|
|
1630
1846
|
};
|
|
1631
1847
|
declare function loadTaskRuntime(_taskDir: string): Promise<AgentTaskRuntime>;
|
|
1632
|
-
|
|
1848
|
+
type RunTaskDirOptions = {
|
|
1849
|
+
/**
|
|
1850
|
+
* Receives a handle that ends the active run's root span as cancelled and
|
|
1851
|
+
* flushes it. Callers that can be terminated by a signal (the CLI task
|
|
1852
|
+
* child, `apo task run`) register it so the run's trace and linkage survive
|
|
1853
|
+
* their own death instead of dying with the process.
|
|
1854
|
+
*/
|
|
1855
|
+
registerCancel?: (cancel: (reason?: string) => Promise<void>) => void;
|
|
1856
|
+
};
|
|
1857
|
+
declare function runTaskDir(taskDir: string, options?: RunTaskDirOptions): Promise<AgentTaskRunSummary>;
|
|
1633
1858
|
|
|
1634
1859
|
type DeliverableValidationResult = {
|
|
1635
1860
|
results: EvaluationItemResult[];
|
|
@@ -1870,4 +2095,218 @@ declare function canonicalManifestJson(manifest: TaskRevisionManifestV1): string
|
|
|
1870
2095
|
/** SHA-256 (lowercase hex) of the canonical manifest JSON's UTF-8 bytes. */
|
|
1871
2096
|
declare function contentSha256(manifest: TaskRevisionManifestV1): string;
|
|
1872
2097
|
|
|
1873
|
-
|
|
2098
|
+
/**
|
|
2099
|
+
* Claude Code session-transcript parser.
|
|
2100
|
+
*
|
|
2101
|
+
* Claude Code appends one JSON object per line to
|
|
2102
|
+
* ``~/.claude/projects/<project>/<session-id>.jsonl`` for every session:
|
|
2103
|
+
*
|
|
2104
|
+
* { type: "user" | "assistant", timestamp, requestId?, sessionId?, cwd?,
|
|
2105
|
+
* toolUseResult?, message: { id?, role, model?, usage?, stop_reason?,
|
|
2106
|
+
* content: string | Array<text | thinking | tool_use | tool_result> } }
|
|
2107
|
+
*
|
|
2108
|
+
* Two grouping rules do the real work:
|
|
2109
|
+
* - Streamed assistant chunks of one API response share ``message.id``; they
|
|
2110
|
+
* are one logical message, and usage is read from the most complete chunk
|
|
2111
|
+
* (the first chunk's snapshot undercounts the request).
|
|
2112
|
+
* - A user line whose content is a ``tool_result`` block array is the harness
|
|
2113
|
+
* feeding a tool result back to the model, not a new turn.
|
|
2114
|
+
*/
|
|
2115
|
+
|
|
2116
|
+
declare function parseClaudeCodeTranscript(content: string): ParsedTranscriptSession;
|
|
2117
|
+
|
|
2118
|
+
/**
|
|
2119
|
+
* Codex CLI session-transcript parser.
|
|
2120
|
+
*
|
|
2121
|
+
* Codex writes rollout files under ``~/.codex/sessions/YYYY/MM/DD/``, one
|
|
2122
|
+
* JSON object per line:
|
|
2123
|
+
*
|
|
2124
|
+
* { type: "session_meta" | "turn_context" | "event_msg" | "response_item",
|
|
2125
|
+
* timestamp, payload }
|
|
2126
|
+
*
|
|
2127
|
+
* - ``event_msg`` payloads: ``task_started``, ``task_complete``,
|
|
2128
|
+
* ``user_message``, ``agent_message`` (phase ``final_answer`` |
|
|
2129
|
+
* ``commentary``), ``token_count`` (``info.last_token_usage``).
|
|
2130
|
+
* - ``response_item`` payloads: ``function_call`` / ``custom_tool_call`` and
|
|
2131
|
+
* their ``*_output`` counterparts (paired by ``call_id``), ``reasoning``
|
|
2132
|
+
* (summary parts), ``web_search_call``.
|
|
2133
|
+
*
|
|
2134
|
+
* A turn is bracketed by ``task_started`` … ``task_complete``. A rollout that
|
|
2135
|
+
* ends mid-turn (harness killed, crash) still yields its turn — the activity
|
|
2136
|
+
* happened, the trace should show it — with a warning.
|
|
2137
|
+
*/
|
|
2138
|
+
|
|
2139
|
+
declare function parseCodexTranscript(content: string): ParsedTranscriptSession;
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* Transcript source detection.
|
|
2143
|
+
*
|
|
2144
|
+
* Guesses which harness wrote a JSONL transcript from its leading lines —
|
|
2145
|
+
* blank, torn, or non-object lines are scanned past until one is decisive —
|
|
2146
|
+
* so `apo traces import <file>` needs no `--source` in the common case:
|
|
2147
|
+
*
|
|
2148
|
+
* - Codex rollouts are uniformly ``{ type: session_meta|turn_context|
|
|
2149
|
+
* event_msg|response_item, timestamp, payload }``.
|
|
2150
|
+
* - Claude Code transcripts are ``{ type: "user"|"assistant", message, … }``
|
|
2151
|
+
* with the session's identity fields (``sessionId``/``cwd``) on the lines.
|
|
2152
|
+
*/
|
|
2153
|
+
|
|
2154
|
+
declare function detectTranscriptSource(content: string): TranscriptSource | undefined;
|
|
2155
|
+
|
|
2156
|
+
/**
|
|
2157
|
+
* Transcript → OTLP/JSON translator.
|
|
2158
|
+
*
|
|
2159
|
+
* Converts a parsed session into exactly the span vocabulary apo's receiver
|
|
2160
|
+
* already normalizes best. Two rules make replayed traces indistinguishable
|
|
2161
|
+
* from live-OTel ones in the projection:
|
|
2162
|
+
*
|
|
2163
|
+
* 1. Every span carries an explicit ``apo.observation.type`` override — the
|
|
2164
|
+
* priority-1 mapper — so typing (AGENT / GENERATION / TOOL / SPAN) never
|
|
2165
|
+
* depends on the backend's registry guessing from attributes.
|
|
2166
|
+
* 2. Attributes use apo's established GenAI keys (``gen_ai.request.model``,
|
|
2167
|
+
* ``gen_ai.usage.*`` incl. the cache/reasoning buckets the pricing path
|
|
2168
|
+
* reads, ``gen_ai.tool.*``, ``gen_ai.input/output.messages``) — not a
|
|
2169
|
+
* replay-specific dialect.
|
|
2170
|
+
*
|
|
2171
|
+
* IDs are SHA-256-derived from the session identity, so re-exporting the same
|
|
2172
|
+
* transcript is idempotent: the receiver upserts on
|
|
2173
|
+
* ``(project_id, trace_id, span_id)``.
|
|
2174
|
+
*/
|
|
2175
|
+
|
|
2176
|
+
type OtlpAttributeValue = {
|
|
2177
|
+
stringValue: string;
|
|
2178
|
+
} | {
|
|
2179
|
+
intValue: string;
|
|
2180
|
+
} | {
|
|
2181
|
+
boolValue: boolean;
|
|
2182
|
+
};
|
|
2183
|
+
type OtlpAttribute = {
|
|
2184
|
+
key: string;
|
|
2185
|
+
value: OtlpAttributeValue;
|
|
2186
|
+
};
|
|
2187
|
+
type OtlpSpan = {
|
|
2188
|
+
traceId: string;
|
|
2189
|
+
spanId: string;
|
|
2190
|
+
parentSpanId?: string;
|
|
2191
|
+
name: string;
|
|
2192
|
+
kind: number;
|
|
2193
|
+
startTimeUnixNano: string;
|
|
2194
|
+
endTimeUnixNano: string;
|
|
2195
|
+
attributes: OtlpAttribute[];
|
|
2196
|
+
status: {
|
|
2197
|
+
code: number;
|
|
2198
|
+
};
|
|
2199
|
+
};
|
|
2200
|
+
type OtlpTracesPayload = {
|
|
2201
|
+
resourceSpans: Array<{
|
|
2202
|
+
resource: {
|
|
2203
|
+
attributes: OtlpAttribute[];
|
|
2204
|
+
};
|
|
2205
|
+
scopeSpans: Array<{
|
|
2206
|
+
scope: {
|
|
2207
|
+
name: string;
|
|
2208
|
+
version: string;
|
|
2209
|
+
};
|
|
2210
|
+
spans: OtlpSpan[];
|
|
2211
|
+
}>;
|
|
2212
|
+
}>;
|
|
2213
|
+
};
|
|
2214
|
+
type TranscriptReplayOptions = {
|
|
2215
|
+
/** Trace id (32 lowercase hex). Default: deterministic from source + session id. */
|
|
2216
|
+
traceId?: string;
|
|
2217
|
+
/** Parent for the first turn's interaction span — adapter capture mode nests it under the live task.turn span. */
|
|
2218
|
+
parentSpanId?: string;
|
|
2219
|
+
/** Run list label (`apo.run.flow_name`). Default: "<source> session <id prefix>". */
|
|
2220
|
+
flowName?: string;
|
|
2221
|
+
/** Run tags (`apo.run.tags`). Default: ["transcript-replay", source]. */
|
|
2222
|
+
tags?: string[];
|
|
2223
|
+
};
|
|
2224
|
+
declare function transcriptSessionToOtlp(session: ParsedTranscriptSession, options?: TranscriptReplayOptions): OtlpTracesPayload;
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* OTLP export for replayed transcripts.
|
|
2228
|
+
*
|
|
2229
|
+
* Posts an OTLP/JSON traces payload to apo's public OTLP endpoint using the
|
|
2230
|
+
* same auth the live exporters use. Auth mode decides what the trace becomes:
|
|
2231
|
+
*
|
|
2232
|
+
* - API key (CLI import): the trace lands as an unclaimed project run.
|
|
2233
|
+
* - Attempt/service token (adapter capture): the replayed spans join the live
|
|
2234
|
+
* task run's trace — the runner's root span already carries the claim.
|
|
2235
|
+
*
|
|
2236
|
+
* 5xx, 429, and network failures are retried — apo's admission controller
|
|
2237
|
+
* 429s OTLP ingest under per-key concurrency pressure, which the runner's own
|
|
2238
|
+
* simple-processor exports can create while a replay POST is in flight. Any
|
|
2239
|
+
* other 4xx is a caller bug (bad token, malformed payload) and fails fast
|
|
2240
|
+
* with the response body excerpt.
|
|
2241
|
+
*/
|
|
2242
|
+
|
|
2243
|
+
declare class TranscriptReplayError extends Error {
|
|
2244
|
+
readonly status?: number;
|
|
2245
|
+
constructor(message: string, status?: number);
|
|
2246
|
+
}
|
|
2247
|
+
type ExportOtlpTracesOptions = {
|
|
2248
|
+
/** apo base URL (e.g. http://localhost:8000); a full …/v1/traces URL is accepted verbatim. */
|
|
2249
|
+
endpoint: string;
|
|
2250
|
+
/** Attempt/service token — sent as the OTLP Authorization bearer. */
|
|
2251
|
+
token?: string;
|
|
2252
|
+
/** Complete headers override (e.g. buildApoAuthHeaders() for Basic API-key auth). */
|
|
2253
|
+
headers?: Record<string, string>;
|
|
2254
|
+
/** Per-request timeout. Default 30s. */
|
|
2255
|
+
timeoutMs?: number;
|
|
2256
|
+
/** Extra attempts after the first on 5xx/network failure. Default 2. */
|
|
2257
|
+
retries?: number;
|
|
2258
|
+
};
|
|
2259
|
+
/** Normalize an apo base URL into the public OTLP traces endpoint. */
|
|
2260
|
+
declare function resolveOtlpTracesUrl(base: string): string;
|
|
2261
|
+
declare function exportOtlpTraces(payload: OtlpTracesPayload, options: ExportOtlpTracesOptions): Promise<void>;
|
|
2262
|
+
|
|
2263
|
+
/**
|
|
2264
|
+
* Adapter capture mode — replay a harness session transcript into a live
|
|
2265
|
+
* Task Run.
|
|
2266
|
+
*
|
|
2267
|
+
* The adapter contract this serves: a harness that cannot emit OTel (Codex
|
|
2268
|
+
* CLI, plain Claude Code, anything that only writes a session JSONL) declares
|
|
2269
|
+
* its transcript on the session (`AdapterSession.transcript`), and the runner
|
|
2270
|
+
* calls {@link replayAdapterTranscript} after the turn loop. One call does
|
|
2271
|
+
* two things with the same parse:
|
|
2272
|
+
*
|
|
2273
|
+
* 1. **Local:** converts the translated spans into projection observations and
|
|
2274
|
+
* returns them, so the runner can inject them into the local snapshot —
|
|
2275
|
+
* `t.calledTool` / budget assertions work even on offline, unrecorded runs.
|
|
2276
|
+
* 2. **Remote:** when the run has a live trace id and backend credentials, the
|
|
2277
|
+
* OTLP payload joins the run's trace (same traceId, interactions parented
|
|
2278
|
+
* under the run root) and the backend projects it exactly like native OTel
|
|
2279
|
+
* spans — the read-back snapshot the recorded path evaluates against is
|
|
2280
|
+
* indistinguishable from an instrumented run.
|
|
2281
|
+
*
|
|
2282
|
+
* Failure semantics are strict on purpose: the adapter *declared* a
|
|
2283
|
+
* transcript, so a missing file or a failed export on a recorded run fails
|
|
2284
|
+
* the run loudly — otherwise checks would starve on a projection that
|
|
2285
|
+
* silently lacks the agent's activity.
|
|
2286
|
+
*/
|
|
2287
|
+
|
|
2288
|
+
type ReplayAdapterTranscriptOptions = {
|
|
2289
|
+
/** The live run's root span id — replayed interactions nest under it. */
|
|
2290
|
+
rootSpanId: string;
|
|
2291
|
+
/**
|
|
2292
|
+
* The live trace id. Present only when the run has a real trace (a noop
|
|
2293
|
+
* trace context yields sentinel ids); when absent the replay stays local.
|
|
2294
|
+
*/
|
|
2295
|
+
liveTraceId?: string;
|
|
2296
|
+
/** apo base URL (AGENT_TASK_TRACE_ENDPOINT). Required for remote export. */
|
|
2297
|
+
endpoint?: string;
|
|
2298
|
+
};
|
|
2299
|
+
type TranscriptCaptureResult = {
|
|
2300
|
+
/** Projection observations for the replayed spans (already snapshot-sorted). */
|
|
2301
|
+
observations: TraceProjectionObservation[];
|
|
2302
|
+
/** Total OTLP spans the translation produced (observations + resource meta). */
|
|
2303
|
+
spanCount: number;
|
|
2304
|
+
/** Whether the payload was exported to the backend. */
|
|
2305
|
+
exported: boolean;
|
|
2306
|
+
/** Parser warnings (torn lines, unterminated turns). */
|
|
2307
|
+
warnings: string[];
|
|
2308
|
+
turns: number;
|
|
2309
|
+
};
|
|
2310
|
+
declare function replayAdapterTranscript(capture: AdapterTranscriptCapture, options: ReplayAdapterTranscriptOptions): Promise<TranscriptCaptureResult>;
|
|
2311
|
+
|
|
2312
|
+
export { type AISDKResult, type AdapterDefinition, type AdapterRuntimeState, type AdapterSession, type AdapterTranscriptCapture, type AgentBudget, type AgentEvidence, type AgentJudgeOptions, type AgentJudgeOutcome, type AgentJudgeSession, type AgentJudgeStep, type AgentTaskCliOptions, type AgentTaskRunConfiguration, AgentTaskRunError, type AgentTaskRunSummary, type AgentTaskRuntime, AgentTaskTraceContext, AgentTaskTraceOptions, type AgentTurnResult, type AnthropicMessage, type ApoRunContext, ApoSpanProcessor, type ArtifactUploadConfig, type CheckCompaction, type CheckContext, type CheckGroup, type CleanupContext, type CollectDeliverablesContext, type CollectedDeliverables, type DeliverableDefinition, type DeliverableSummary, type DeliverableValidationResult, type DescribeRegistration, type DurationBudgetOptions, type EvidenceFingerprint, type ExportOtlpTracesOptions, type FileArtifact, type FileArtifactOptions, type FileEntry, type Flow, type FlowEvent, FlowView, type InitializeContext, JUDGE_SEGMENT_LIMIT, type JudgeConfig, type JudgeContext, type JudgePromptBuilder, type JudgeScope, type JudgeToolsConfig, type LoadedTask, type ManifestFile, type ManifestFileInput, type Matcher, type McpHttpTransport, type McpServerConfig, type McpStdioTransport, type ModeClass, type NameMatcher, type OpenAIMessage, type OtlpAttribute, type OtlpAttributeValue, type OtlpSpan, type OtlpTracesPayload, type ParsedTranscriptSession, type PreparedTaskResult, RECEIVED_VALUE_LIMIT, type RegisterApoTracingOptions, type RejudgeCheckStability, type RejudgeEndpoints, RejudgeError, type RejudgeOptions, type RejudgeOutcome, type ReplayAdapterTranscriptOptions, 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 TokenBudgetOptions, type ToolCallOptions, type ToolCallStatus, type TranscriptCaptureResult, TranscriptReplayError, type TranscriptReplayOptions, type TranscriptSource, type TranscriptToolCall, type TranscriptTurn, type TranscriptUsage, type TurnContext, type TurnFn, type TurnRecord, type TypedAdapterDefinition, type ValueMatcher, buildApoAuthHeaders, buildManifest, canonicalManifestJson, compactChecksForSubmission, connectMcpServers, contentSha256, defineAdapter, defineTask, describe, detectTranscriptSource, discoverAgentTaskDirs, equals, expandSecretPlaceholders, exportOtlpTraces, fileArtifact, filePaths, fromAISDK, fromAnthropicMessages, fromOpenAIMessages, getActiveApoRun, getTaskTurn, includes, isFileArtifact, loadTask, loadTaskRuntime, matchValue, matches, normalizeManifestPath, parseAgentTaskCliArgs, parseClaudeCodeTranscript, parseCodexTranscript, persistFileArtifacts, registerApoTracing, rejudgeTaskRun, replayAdapterTranscript, resetApoTracing, resetFlowChecks, resetTaskRegistry, resetTaskTurn, resolveMcpServerPaths, resolveOtlpTracesUrl, resolveTurn, runAgentTaskCli, runTask, runTaskDir, satisfies, sha256Hex, similarity, task, defineCheck as test, transcriptSessionToOtlp, turn, withApoRun, withApoRunSync };
|