@apo-ai/sdk 0.6.0 → 0.7.1

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 CHANGED
@@ -1,13 +1,16 @@
1
1
  # apo SDK
2
2
 
3
- TypeScript/JavaScript SDK for the [apo](.) backend — an agent testing and
4
- observability platform. The SDK's entry points:
3
+ TypeScript/JavaScript SDK for [apo](https://github.com/samikuikka/apo), the
4
+ testing and engineering system that turns expert knowledge into executable
5
+ capability specifications for agent harnesses. The task API runs a real harness
6
+ against that definition of done; the tracing API preserves the evidence a human
7
+ or coding agent needs to improve it. The SDK's entry points:
5
8
 
6
9
  - **`@apo-ai/sdk/otel`** — OpenTelemetry-native tracing. Wrap your LLM calls and
7
10
  agent steps so they land in apo as structured spans, then attach scores.
8
- - **`@apo-ai/sdk/agent-task`** — the agent-task evaluation framework. Define tasks,
9
- adapters, and checks; run them against an agent and collect structured
10
- results.
11
+ - **`@apo-ai/sdk/agent-task`** — the primary capability-testing surface. Define
12
+ tasks, adapters, and tests; run them against the real harness and collect a
13
+ verdict with structured evidence.
11
14
  - **`@apo-ai/sdk/agent-task/integrations/{ai-sdk,openai,anthropic}`** —
12
15
  per-framework tracing wrappers re-exported for direct import.
13
16
 
@@ -1,4 +1,4 @@
1
- import { A as AgentTaskTraceContext } from '../../tracing-CTmq4PSw.js';
1
+ import { A as AgentTaskTraceContext } from '../../tracing-DVLUqD-i.js';
2
2
 
3
3
  /**
4
4
  * Vercel AI SDK tracing integration for apo.
@@ -2,7 +2,7 @@
2
2
  // Do not edit by hand — edit the src/ originals and rebuild.
3
3
  import {
4
4
  createApoTracer
5
- } from "../../chunk-H7ITLBWU.js";
5
+ } from "../../chunk-QHRWPVPZ.js";
6
6
  import "../../chunk-HWZVL6TS.js";
7
7
  export {
8
8
  createApoTracer
@@ -1,4 +1,4 @@
1
- import { A as AgentTaskTraceContext } from '../../tracing-CTmq4PSw.js';
1
+ import { A as AgentTaskTraceContext } from '../../tracing-DVLUqD-i.js';
2
2
 
3
3
  /**
4
4
  * Anthropic JS SDK tracing integration for apo.
@@ -1,4 +1,4 @@
1
- import { A as AgentTaskTraceContext } from '../../tracing-CTmq4PSw.js';
1
+ import { A as AgentTaskTraceContext } from '../../tracing-DVLUqD-i.js';
2
2
 
3
3
  /**
4
4
  * OpenAI JS SDK tracing integration for apo.
@@ -1,4 +1,4 @@
1
- import { A as AgentTaskTraceContext, a as AgentTaskTraceOptions } from '../tracing-CTmq4PSw.js';
1
+ import { A as AgentTaskTraceContext, a as AgentTaskTraceOptions } from '../tracing-DVLUqD-i.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';
@@ -350,6 +350,102 @@ type JudgeMetadata = {
350
350
  latency_ms?: number;
351
351
  /** Temperature or other sampling parameters, if relevant. */
352
352
  temperature?: number;
353
+ /**
354
+ * Agentic-judge session transcript (`t.agent`). Absent for single-shot
355
+ * `t.judge` calls. Records every investigation step (tool calls with
356
+ * truncated results), the session outcome, per-step usage, and the
357
+ * content-hashed evidence manifest (replay audit backbone).
358
+ */
359
+ session?: AgentJudgeSession;
360
+ /**
361
+ * Second-grader evidence: a typed-decision model (Jev via OpenRouter's
362
+ * `/alpha/decisions`) graded the same deliverable + instruction alongside
363
+ * the primary judge. Opt-in via `APO_SECOND_JUDGE_MODEL`. The primary
364
+ * verdict is never changed by it — the point is agreement and confidence
365
+ * as extra signals per check, not a second vote.
366
+ */
367
+ secondJudge?: SecondJudgeEvidence;
368
+ };
369
+ /**
370
+ * Evidence from the second grader. `error` is set when the decisions
371
+ * endpoint could not be reached — a failed second opinion must never
372
+ * affect the check's verdict.
373
+ */
374
+ type SecondJudgeEvidence = {
375
+ /** Decision-model id that graded, e.g. `typesafe/jev-1.13`. */
376
+ model: string;
377
+ /** The typed verdict the model returned. */
378
+ choice?: "pass" | "fail";
379
+ /** P(pass) from the model's probability distribution over the choice. */
380
+ passProbability?: number;
381
+ /** The model's own confidence in its choice (0-1). */
382
+ confidence?: number;
383
+ /** Input tokens billed for the decision, when the provider reports usage. */
384
+ inputTokens?: number;
385
+ /** Cost in USD, when the provider reports it. */
386
+ costUsd?: number;
387
+ /** Wall-clock latency of the decision call in milliseconds. */
388
+ latencyMs?: number;
389
+ /** Why no verdict was recorded (transport/HTTP/parse failure). */
390
+ error?: string;
391
+ };
392
+ /**
393
+ * One investigation step of an agentic judge session. Tool results are
394
+ * truncated text; the sha256 + byte size are always kept so the full value
395
+ * stays recoverable from the evidence store (the transcript is an index,
396
+ * not a copy).
397
+ */
398
+ type AgentJudgeStep = {
399
+ index: number;
400
+ tool_calls?: {
401
+ name: string;
402
+ input?: string;
403
+ result?: string;
404
+ result_sha256?: string;
405
+ result_bytes?: number;
406
+ }[];
407
+ /** Assistant prose, if the model produced text alongside tool calls. */
408
+ text?: string;
409
+ tokens?: {
410
+ input?: number;
411
+ output?: number;
412
+ cost?: number;
413
+ };
414
+ latency_ms?: number;
415
+ };
416
+ /** How an agentic judge session ended. */
417
+ type AgentJudgeOutcome = "verdict" | "budget_exhausted" | "error";
418
+ /**
419
+ * A fingerprint of one piece of evidence the judge consumed — the
420
+ * content-addressed manifest. Never truncated.
421
+ */
422
+ type EvidenceFingerprint = {
423
+ step: number;
424
+ tool: string;
425
+ args_sha256?: string;
426
+ result_sha256: string;
427
+ result_bytes: number;
428
+ };
429
+ /** Transcript-shaped record of one `t.agent` session. */
430
+ type AgentJudgeSession = {
431
+ /** Tool names offered to the judge. */
432
+ tools?: string[];
433
+ /** Turn-0 context: system briefing and the rubric (user message). */
434
+ briefing?: {
435
+ system?: string;
436
+ rubric?: string;
437
+ };
438
+ /** Ordered investigation steps. */
439
+ steps?: AgentJudgeStep[];
440
+ outcome: AgentJudgeOutcome;
441
+ /** Evidence manifest — what this session consumed, hashed. Never truncated. */
442
+ evidence?: EvidenceFingerprint[];
443
+ usage?: {
444
+ steps?: number;
445
+ input_tokens?: number;
446
+ output_tokens?: number;
447
+ cache_read_tokens?: number;
448
+ };
353
449
  };
354
450
  /**
355
451
  * A source location for a failed code check — lets the dashboard render the
@@ -393,7 +489,7 @@ type AssertionResult = {
393
489
  */
394
490
  received?: unknown;
395
491
  location?: CheckLocation;
396
- evaluator_type?: "llm" | "code";
492
+ evaluator_type?: "llm" | "code" | "agent";
397
493
  judge?: JudgeMetadata;
398
494
  };
399
495
  /**
@@ -423,7 +519,7 @@ type EvaluationItemResult = {
423
519
  * - ``"regex"`` — pattern matching
424
520
  * Older persisted results may still use ``"llm"`` at this level.
425
521
  */
426
- evaluator_type?: "llm" | "code" | "regex";
522
+ evaluator_type?: "llm" | "code" | "agent" | "regex";
427
523
  /**
428
524
  * If this check was judged by an LLM, details about the judge call
429
525
  * (model, prompt, response, tokens, cost, latency). Populated by the
@@ -564,6 +660,101 @@ type JudgePromptBuilder = (ctx: JudgeContext) => {
564
660
  user?: string;
565
661
  };
566
662
 
663
+ /** One prior attempt of this task, as frozen at evaluation start. */
664
+ type FrozenRunSummary = {
665
+ id: string;
666
+ status: string;
667
+ passed: boolean | null;
668
+ started_at?: string;
669
+ primary_model?: string | null;
670
+ passed_checks?: number | null;
671
+ failed_checks?: number | null;
672
+ corrected_tests?: unknown[];
673
+ /** True when this entry IS the run under judgment. */
674
+ is_run_under_judgment?: boolean;
675
+ };
676
+ /** A prior run's full check report (merged view, like the run detail page). */
677
+ type HistoryRunDetail = {
678
+ id: string;
679
+ status: string;
680
+ checks: {
681
+ id: string;
682
+ pass: boolean;
683
+ evaluator: string;
684
+ reasoning?: string;
685
+ assertions?: {
686
+ pass: boolean;
687
+ expected?: string;
688
+ received?: string;
689
+ }[];
690
+ }[];
691
+ /** Human corrections recorded against this run; "none" when empty. */
692
+ human_corrections: unknown[] | "none";
693
+ };
694
+ /** The frozen evidence plane handed to every `t.agent` session. */
695
+ type AgentHistoryPlane = {
696
+ /** Prior attempts of this task, frozen at evaluation start. */
697
+ runs: FrozenRunSummary[];
698
+ /**
699
+ * Fetch one prior run's merged check report. The run-under-judgment id
700
+ * returns an honest "you are deciding this run" answer instead of data
701
+ * whose checks are still being evaluated.
702
+ */
703
+ getRun(runId: string): Promise<HistoryRunDetail | {
704
+ error: string;
705
+ }>;
706
+ /** The backend's id for the run under judgment, when known. */
707
+ selfRunId?: string;
708
+ };
709
+
710
+ /**
711
+ * The agentic judge — `t.agent`. A tool-using LLM session that investigates
712
+ * the run's own evidence (deliverables, trace) before verdicting, powered by
713
+ * a lazy-loaded Vercel AI SDK engine. The judge semantics live here at the
714
+ * call site; the loop itself is engine-level: forced tool choice plus a
715
+ * done-tool verdict means the only exits are a verdict or the budget — every
716
+ * other ending is recorded as a failure with an explanation.
717
+ *
718
+ * Sessions are stateless per check: no memory crosses sessions (upstream
719
+ * ablations showed remembered judgments cascade errors). Everything the
720
+ * session consumed is recorded as a content-hashed manifest
721
+ * ({@link EvidenceFingerprint}) — the transcript is an index, not a copy.
722
+ */
723
+
724
+ /** Hard ceilings for one agentic session. Every field overrides a default. */
725
+ type AgentBudget = {
726
+ /** Max LLM turns (steps). Default 12. */
727
+ maxTurns?: number;
728
+ /** Max total tool executions. Default 24. */
729
+ maxToolCalls?: number;
730
+ /** Wall-clock ceiling. Default 300_000 ms. */
731
+ timeoutMs?: number;
732
+ /** Max cumulative bytes served by read/search tools. Default 2 MiB. */
733
+ maxReadBytes?: number;
734
+ };
735
+ /** Options for `t.agent(instruction, opts)`. */
736
+ type AgentJudgeOptions = {
737
+ /** Pre-staged values rendered into turn 0, like `t.judge` values. */
738
+ exhibits?: unknown | unknown[];
739
+ /** Judge config override for this call only (merges field-by-field). */
740
+ judge?: Partial<JudgeConfig>;
741
+ /** Tool families; deliverables are always on. `trace: false` drops get_trace. */
742
+ tools?: {
743
+ trace?: boolean;
744
+ };
745
+ budget?: AgentBudget;
746
+ label?: string;
747
+ };
748
+ /** The local evidence plane a session can investigate. */
749
+ type AgentEvidence = {
750
+ /** The run's deliverables, by name. */
751
+ deliverables: Record<string, unknown>;
752
+ /** The frozen trace projection; absent = no trace evidence plane. */
753
+ view?: TraceView;
754
+ /** This task's prior runs; absent = history plane unavailable. */
755
+ history?: AgentHistoryPlane;
756
+ };
757
+
567
758
  /**
568
759
  * The assertion surface — `t`. Flat and eve-style: reads the trace (via
569
760
  * {@link TraceView}) for behavioural checks and grades explicit values via
@@ -659,6 +850,21 @@ interface TestContext {
659
850
  label?: string;
660
851
  judge?: Partial<JudgeConfig>;
661
852
  }): Promise<void>;
853
+ /**
854
+ * Agentic judge: a tool-using LLM session that investigates the run's own
855
+ * evidence (deliverables via `read_deliverable`/`search_deliverable`, the
856
+ * trace via `get_trace`) before verdicting with `finish_verdict`. Async —
857
+ * the check function must `await` it. Records a single assertion tagged
858
+ * ``evaluator_type: "agent"`` with the full session transcript attached.
859
+ *
860
+ * Unlike `t.judge`, the author states a rubric and the judge gathers its
861
+ * own evidence; `opts.exhibits` optionally pre-stages values into turn 0.
862
+ * The session is budgeted (defaults: 12 turns / 24 tool calls / 300 s /
863
+ * 2 MiB read) and fail-closed: a session that ends without a verdict is a
864
+ * recorded failure, never a silent pass. Costs more and runs minutes, not
865
+ * seconds — reserve it for rubrics that need investigation.
866
+ */
867
+ agent(instruction: string, opts?: AgentJudgeOptions): Promise<void>;
662
868
  }
663
869
  /**
664
870
  * Canonical names of every assertion method on {@link TestContext}.
@@ -672,7 +878,7 @@ interface TestContext {
672
878
  * adding a method to the interface without registering it here is a type
673
879
  * error, and vice versa. See ``tests/test-context-methods.test.ts``.
674
880
  */
675
- declare const TEST_METHOD_NAMES: readonly ["calledTool", "notCalledTool", "toolOrder", "usedNoTools", "maxToolCalls", "noFailedActions", "loadedSkill", "calledSubagent", "messageIncludes", "maxTurns", "maxDurationMs", "assert", "check", "judge"];
881
+ declare const TEST_METHOD_NAMES: readonly ["calledTool", "notCalledTool", "toolOrder", "usedNoTools", "maxToolCalls", "noFailedActions", "loadedSkill", "calledSubagent", "messageIncludes", "maxTurns", "maxDurationMs", "assert", "check", "judge", "agent"];
676
882
 
677
883
  type TaskDefinition<TAdapterName extends string = string, TDeliverable extends string = string> = {
678
884
  id: string;
@@ -1505,4 +1711,4 @@ declare function canonicalManifestJson(manifest: TaskRevisionManifestV1): string
1505
1711
  /** SHA-256 (lowercase hex) of the canonical manifest JSON's UTF-8 bytes. */
1506
1712
  declare function contentSha256(manifest: TaskRevisionManifestV1): string;
1507
1713
 
1508
- 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 CheckCompaction, 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, JUDGE_SEGMENT_LIMIT, type JudgeConfig, type JudgeContext, type JudgePromptBuilder, type JudgeScope, type LoadedTask, type ManifestFile, type ManifestFileInput, type Matcher, type ModeClass, type NameMatcher, type OpenAIMessage, type PreparedTaskResult, RECEIVED_VALUE_LIMIT, 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, compactChecksForSubmission, 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 };
1714
+ export { type AISDKResult, type AdapterDefinition, type AdapterRuntimeState, type AdapterSession, 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 EvidenceFingerprint, 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 LoadedTask, type ManifestFile, type ManifestFileInput, type Matcher, type ModeClass, type NameMatcher, type OpenAIMessage, type PreparedTaskResult, RECEIVED_VALUE_LIMIT, 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, compactChecksForSubmission, 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 };