@attest-ai/core 0.5.0 → 0.6.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.
Files changed (121) hide show
  1. package/dist/cjs/index.cjs +113 -2
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +33 -7
  4. package/dist/cjs/proto/index.cjs.map +1 -1
  5. package/dist/cjs/proto/index.d.cts +44 -3
  6. package/dist/esm/cli.js +1 -1
  7. package/dist/esm/cli.js.map +1 -1
  8. package/dist/esm/index.d.ts +33 -7
  9. package/dist/esm/index.js +107 -2
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/proto/index.d.ts +44 -3
  12. package/dist/esm/proto/index.js.map +1 -1
  13. package/package.json +4 -4
  14. package/dist/adapters/anthropic.d.ts +0 -31
  15. package/dist/adapters/anthropic.d.ts.map +0 -1
  16. package/dist/adapters/anthropic.js +0 -42
  17. package/dist/adapters/anthropic.js.map +0 -1
  18. package/dist/adapters/gemini.d.ts +0 -30
  19. package/dist/adapters/gemini.d.ts.map +0 -1
  20. package/dist/adapters/gemini.js +0 -41
  21. package/dist/adapters/gemini.js.map +0 -1
  22. package/dist/adapters/index.d.ts +0 -11
  23. package/dist/adapters/index.d.ts.map +0 -1
  24. package/dist/adapters/index.js +0 -7
  25. package/dist/adapters/index.js.map +0 -1
  26. package/dist/adapters/manual.d.ts +0 -9
  27. package/dist/adapters/manual.d.ts.map +0 -1
  28. package/dist/adapters/manual.js +0 -16
  29. package/dist/adapters/manual.js.map +0 -1
  30. package/dist/adapters/ollama.d.ts +0 -19
  31. package/dist/adapters/ollama.d.ts.map +0 -1
  32. package/dist/adapters/ollama.js +0 -30
  33. package/dist/adapters/ollama.js.map +0 -1
  34. package/dist/adapters/openai.d.ts +0 -34
  35. package/dist/adapters/openai.d.ts.map +0 -1
  36. package/dist/adapters/openai.js +0 -42
  37. package/dist/adapters/openai.js.map +0 -1
  38. package/dist/adapters/otel.d.ts +0 -25
  39. package/dist/adapters/otel.d.ts.map +0 -1
  40. package/dist/adapters/otel.js +0 -133
  41. package/dist/adapters/otel.js.map +0 -1
  42. package/dist/agent.d.ts +0 -14
  43. package/dist/agent.d.ts.map +0 -1
  44. package/dist/agent.js +0 -54
  45. package/dist/agent.js.map +0 -1
  46. package/dist/client.d.ts +0 -23
  47. package/dist/client.d.ts.map +0 -1
  48. package/dist/client.js +0 -171
  49. package/dist/client.js.map +0 -1
  50. package/dist/config.d.ts +0 -21
  51. package/dist/config.d.ts.map +0 -1
  52. package/dist/config.js +0 -31
  53. package/dist/config.js.map +0 -1
  54. package/dist/context.d.ts +0 -4
  55. package/dist/context.d.ts.map +0 -1
  56. package/dist/context.js +0 -3
  57. package/dist/context.js.map +0 -1
  58. package/dist/delegate.d.ts +0 -3
  59. package/dist/delegate.d.ts.map +0 -1
  60. package/dist/delegate.js +0 -24
  61. package/dist/delegate.js.map +0 -1
  62. package/dist/engine-downloader.d.ts +0 -7
  63. package/dist/engine-downloader.d.ts.map +0 -1
  64. package/dist/engine-downloader.js +0 -136
  65. package/dist/engine-downloader.js.map +0 -1
  66. package/dist/engine-manager.d.ts +0 -26
  67. package/dist/engine-manager.d.ts.map +0 -1
  68. package/dist/engine-manager.js +0 -172
  69. package/dist/engine-manager.js.map +0 -1
  70. package/dist/expect.d.ts +0 -133
  71. package/dist/expect.d.ts.map +0 -1
  72. package/dist/expect.js +0 -330
  73. package/dist/expect.js.map +0 -1
  74. package/dist/index.d.ts +0 -16
  75. package/dist/index.d.ts.map +0 -1
  76. package/dist/index.js +0 -15
  77. package/dist/index.js.map +0 -1
  78. package/dist/proto/codec.d.ts +0 -20
  79. package/dist/proto/codec.d.ts.map +0 -1
  80. package/dist/proto/codec.js +0 -71
  81. package/dist/proto/codec.js.map +0 -1
  82. package/dist/proto/constants.d.ts +0 -21
  83. package/dist/proto/constants.d.ts.map +0 -1
  84. package/dist/proto/constants.js +0 -25
  85. package/dist/proto/constants.js.map +0 -1
  86. package/dist/proto/errors.d.ts +0 -13
  87. package/dist/proto/errors.d.ts.map +0 -1
  88. package/dist/proto/errors.js +0 -24
  89. package/dist/proto/errors.js.map +0 -1
  90. package/dist/proto/index.d.ts +0 -5
  91. package/dist/proto/index.d.ts.map +0 -1
  92. package/dist/proto/index.js +0 -5
  93. package/dist/proto/index.js.map +0 -1
  94. package/dist/proto/types.d.ts +0 -104
  95. package/dist/proto/types.d.ts.map +0 -1
  96. package/dist/proto/types.js +0 -2
  97. package/dist/proto/types.js.map +0 -1
  98. package/dist/result.d.ts +0 -15
  99. package/dist/result.d.ts.map +0 -1
  100. package/dist/result.js +0 -32
  101. package/dist/result.js.map +0 -1
  102. package/dist/simulation.d.ts +0 -8
  103. package/dist/simulation.d.ts.map +0 -1
  104. package/dist/simulation.js +0 -21
  105. package/dist/simulation.js.map +0 -1
  106. package/dist/tier.d.ts +0 -5
  107. package/dist/tier.d.ts.map +0 -1
  108. package/dist/tier.js +0 -10
  109. package/dist/tier.js.map +0 -1
  110. package/dist/trace-tree.d.ts +0 -20
  111. package/dist/trace-tree.d.ts.map +0 -1
  112. package/dist/trace-tree.js +0 -92
  113. package/dist/trace-tree.js.map +0 -1
  114. package/dist/trace.d.ts +0 -41
  115. package/dist/trace.d.ts.map +0 -1
  116. package/dist/trace.js +0 -88
  117. package/dist/trace.js.map +0 -1
  118. package/dist/version.d.ts +0 -3
  119. package/dist/version.d.ts.map +0 -1
  120. package/dist/version.js +0 -3
  121. package/dist/version.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { InitializeResult, Trace, Assertion, EvaluateBatchResult, Step, AssertionResult } from './proto/index.cjs';
2
- export { AgentId, AssertionId, AssertionSpec, ConstraintSpec, ContentSpec, ERR_ASSERTION_ERROR, ERR_ENGINE_ERROR, ERR_INVALID_TRACE, ERR_PROVIDER_ERROR, ERR_SESSION_ERROR, ERR_TIMEOUT, EmbeddingSpec, EngineTimeoutError, ErrorData, EvaluateBatchParams, InitializeParams, LlmJudgeSpec, PluginSpec, ProtocolError, RPCError, RPCRequest, RPCResponse, STATUS_HARD_FAIL, STATUS_PASS, STATUS_SOFT_FAIL, STEP_AGENT_CALL, STEP_LLM_CALL, STEP_RETRIEVAL, STEP_TOOL_CALL, SchemaSpec, ShutdownResult, SubmitPluginResultParams, TYPE_CONSTRAINT, TYPE_CONTENT, TYPE_EMBEDDING, TYPE_LLM_JUDGE, TYPE_PLUGIN, TYPE_SCHEMA, TYPE_TRACE, TYPE_TRACE_TREE, TraceId, TraceMetadata, TraceSpec, TraceTreeSpec, agentId, assertionId, decodeResponse, encodeRequest, extractId, extractResult, traceId } from './proto/index.cjs';
1
+ import { InitializeResult, Trace, Assertion, EvaluateBatchResult, DriftReport, SimulatePersona, ConversationMessage, SimulateFaultConfig, Step, AssertionResult } from './proto/index.cjs';
2
+ export { AgentId, AssertionId, AssertionSpec, ConstraintSpec, ContentSpec, ERR_ASSERTION_ERROR, ERR_ENGINE_ERROR, ERR_INVALID_TRACE, ERR_PROVIDER_ERROR, ERR_SESSION_ERROR, ERR_TIMEOUT, EmbeddingSpec, EngineTimeoutError, ErrorData, EvaluateBatchParams, GenerateUserMessageParams, GenerateUserMessageResult, InitializeParams, LlmJudgeSpec, PluginSpec, ProtocolError, QueryDriftParams, QueryDriftResult, RPCError, RPCRequest, RPCResponse, STATUS_HARD_FAIL, STATUS_PASS, STATUS_SOFT_FAIL, STEP_AGENT_CALL, STEP_LLM_CALL, STEP_RETRIEVAL, STEP_TOOL_CALL, SchemaSpec, ShutdownResult, SubmitPluginResultParams, TYPE_CONSTRAINT, TYPE_CONTENT, TYPE_EMBEDDING, TYPE_LLM_JUDGE, TYPE_PLUGIN, TYPE_SCHEMA, TYPE_TRACE, TYPE_TRACE_TREE, TraceId, TraceMetadata, TraceSpec, TraceTreeSpec, agentId, assertionId, decodeResponse, encodeRequest, extractId, extractResult, traceId } from './proto/index.cjs';
3
3
  import { ChildProcess } from 'node:child_process';
4
4
  import { Interface } from 'node:readline';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
6
6
  import { EventEmitter } from 'node:events';
7
7
 
8
- declare const VERSION = "0.5.0";
9
- declare const ENGINE_VERSION = "0.5.0";
8
+ declare const VERSION = "0.6.0";
9
+ declare const ENGINE_VERSION = "0.6.0";
10
10
 
11
11
  declare class EngineManager {
12
12
  private enginePath;
@@ -50,6 +50,12 @@ declare class AttestClient {
50
50
  submitPluginResult(traceId: string, pluginName: string, assertionId: string, status: string, score: number, explanation: string, options?: {
51
51
  timeout?: number;
52
52
  }): Promise<boolean>;
53
+ queryDrift(assertionId: string, windowSize?: number, options?: {
54
+ timeout?: number;
55
+ }): Promise<DriftReport>;
56
+ generateUserMessage(persona: SimulatePersona, conversationHistory: readonly ConversationMessage[], faultConfig?: SimulateFaultConfig, options?: {
57
+ timeout?: number;
58
+ }): Promise<string>;
53
59
  }
54
60
 
55
61
  declare class TraceBuilder {
@@ -517,7 +523,7 @@ declare class ExpectChain {
517
523
  * ```
518
524
  */
519
525
  outputSimilarTo(reference: string, opts?: {
520
- threshold?: number;
526
+ threshold?: number | "dynamic";
521
527
  model?: string;
522
528
  soft?: boolean;
523
529
  }): this;
@@ -538,7 +544,7 @@ declare class ExpectChain {
538
544
  */
539
545
  passesJudge(criteria: string, opts?: {
540
546
  rubric?: string;
541
- threshold?: number;
547
+ threshold?: number | "dynamic";
542
548
  model?: string;
543
549
  soft?: boolean;
544
550
  }): this;
@@ -805,21 +811,36 @@ declare function tier(level: number): <T extends (...args: never[]) => unknown>(
805
811
  * @param options.simulation - Enable simulation mode. All `evaluateBatch` calls
806
812
  * return deterministic pass results without spawning the engine or calling any
807
813
  * LLM. Equivalent to setting `ATTEST_SIMULATION=1` in the environment.
814
+ * @param options.sampleRate - Sampling rate for continuous evaluation (0.0–1.0).
815
+ * Equivalent to setting `ATTEST_SAMPLE_RATE` in the environment.
808
816
  */
809
817
  declare function config(options: {
810
818
  simulation?: boolean;
819
+ sampleRate?: number;
811
820
  }): void;
812
821
  /**
813
822
  * Returns true when simulation mode is active via either the programmatic API
814
823
  * or the `ATTEST_SIMULATION` environment variable.
815
824
  */
816
825
  declare function isSimulationMode(): boolean;
826
+ /**
827
+ * Returns the sampling rate for continuous evaluation. Priority:
828
+ * programmatic `config({ sampleRate })` > `ATTEST_SAMPLE_RATE` env var > 0.
829
+ */
830
+ declare function getSampleRate(): number;
817
831
  /**
818
832
  * Reset all programmatic config to defaults. Primarily for use in tests.
819
833
  * Environment variables are not affected.
820
834
  */
821
835
  declare function resetConfig(): void;
822
836
 
837
+ /**
838
+ * Return a deterministic all-pass result for every assertion without
839
+ * contacting the engine or any LLM provider. Used when simulation mode
840
+ * is active (`ATTEST_SIMULATION=1` or `config({ simulation: true })`).
841
+ */
842
+ declare function simulationEvaluateBatch(assertions: readonly Assertion[]): EvaluateBatchResult;
843
+
823
844
  interface PluginResult {
824
845
  readonly status: string;
825
846
  readonly score: number;
@@ -882,6 +903,11 @@ declare class ContinuousEvalRunner {
882
903
  private scheduleNext;
883
904
  }
884
905
 
906
+ declare const FRIENDLY_USER: SimulatePersona;
907
+ declare const ADVERSARIAL_USER: SimulatePersona;
908
+ declare const CONFUSED_USER: SimulatePersona;
909
+ declare const COOPERATIVE_USER: SimulatePersona;
910
+
885
911
  declare class ManualAdapter {
886
912
  private readonly agentId;
887
913
  constructor(agentId?: string);
@@ -1082,4 +1108,4 @@ interface TraceAdapter {
1082
1108
  traceFromResponse(response: unknown, options?: Record<string, unknown>): Trace;
1083
1109
  }
1084
1110
 
1085
- export { Agent, AgentResult, AlertDispatcher, type AlertPayload, AnthropicAdapter, Assertion, AssertionResult, AttestClient, type AttestPlugin, ContinuousEvalRunner, ENGINE_VERSION, EngineManager, EvaluateBatchResult, ExpectChain, GeminiAdapter, InitializeResult, LangChainAdapter, ManualAdapter, OTelAdapter, OllamaAdapter, OpenAIAdapter, PluginRegistry, type PluginResult, Sampler, Step, TIER_1, TIER_2, TIER_3, Trace, type TraceAdapter, TraceBuilder, TraceTree, VERSION, activeBuilder, agent, attestExpect, config, delegate, executePluginAssertion, isSimulationMode, resetConfig, tier };
1111
+ export { ADVERSARIAL_USER, Agent, AgentResult, AlertDispatcher, type AlertPayload, AnthropicAdapter, Assertion, AssertionResult, AttestClient, type AttestPlugin, CONFUSED_USER, COOPERATIVE_USER, ContinuousEvalRunner, ConversationMessage, DriftReport, ENGINE_VERSION, EngineManager, EvaluateBatchResult, ExpectChain, FRIENDLY_USER, GeminiAdapter, InitializeResult, LangChainAdapter, ManualAdapter, OTelAdapter, OllamaAdapter, OpenAIAdapter, PluginRegistry, type PluginResult, Sampler, SimulateFaultConfig, SimulatePersona, Step, TIER_1, TIER_2, TIER_3, Trace, type TraceAdapter, TraceBuilder, TraceTree, VERSION, activeBuilder, agent, attestExpect, config, delegate, executePluginAssertion, getSampleRate, isSimulationMode, resetConfig, simulationEvaluateBatch, tier };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/proto/index.ts","../../../src/proto/constants.ts","../../../src/proto/types.ts","../../../src/proto/errors.ts","../../../src/proto/codec.ts"],"sourcesContent":["export * from \"./constants.js\";\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport { encodeRequest, decodeResponse, extractResult, extractId } from \"./codec.js\";\n","// Step type constants\nexport const STEP_LLM_CALL = \"llm_call\" as const;\nexport const STEP_TOOL_CALL = \"tool_call\" as const;\nexport const STEP_RETRIEVAL = \"retrieval\" as const;\nexport const STEP_AGENT_CALL = \"agent_call\" as const;\n\n// Status constants\nexport const STATUS_PASS = \"pass\" as const;\nexport const STATUS_SOFT_FAIL = \"soft_fail\" as const;\nexport const STATUS_HARD_FAIL = \"hard_fail\" as const;\n\n// Assertion type constants\nexport const TYPE_SCHEMA = \"schema\" as const;\nexport const TYPE_CONSTRAINT = \"constraint\" as const;\nexport const TYPE_TRACE = \"trace\" as const;\nexport const TYPE_CONTENT = \"content\" as const;\nexport const TYPE_EMBEDDING = \"embedding\" as const;\nexport const TYPE_LLM_JUDGE = \"llm_judge\" as const;\nexport const TYPE_TRACE_TREE = \"trace_tree\" as const;\nexport const TYPE_PLUGIN = \"plugin\" as const;\n\n// Error code constants\nexport const ERR_INVALID_TRACE = 1001 as const;\nexport const ERR_ASSERTION_ERROR = 1002 as const;\nexport const ERR_PROVIDER_ERROR = 2001 as const;\nexport const ERR_ENGINE_ERROR = 3001 as const;\nexport const ERR_TIMEOUT = 3002 as const;\nexport const ERR_SESSION_ERROR = 3003 as const;\n","// ---------------------------------------------------------------------------\n// Branded ID types (T6)\n// ---------------------------------------------------------------------------\n\ndeclare const __brand: unique symbol;\ntype Brand<T, B extends string> = T & { readonly [__brand]: B };\n\nexport type TraceId = Brand<string, \"TraceId\">;\nexport type AssertionId = Brand<string, \"AssertionId\">;\nexport type AgentId = Brand<string, \"AgentId\">;\n\nexport function traceId(id: string): TraceId {\n return id as TraceId;\n}\n\nexport function assertionId(id: string): AssertionId {\n return id as AssertionId;\n}\n\nexport function agentId(id: string): AgentId {\n return id as AgentId;\n}\n\n// ---------------------------------------------------------------------------\n// Assertion spec discriminated unions (T5)\n// ---------------------------------------------------------------------------\n\nexport interface SchemaSpec {\n readonly type: \"schema\";\n readonly target: string;\n readonly schema: Record<string, unknown>;\n}\n\nexport interface ConstraintSpec {\n readonly type: \"constraint\";\n readonly field: string;\n readonly operator: string;\n readonly value?: number;\n readonly min?: number;\n readonly max?: number;\n readonly soft: boolean;\n}\n\nexport interface TraceSpec {\n readonly type: \"trace\";\n readonly check: string;\n readonly tools?: string[];\n readonly tool?: string;\n readonly max_repetitions?: number;\n readonly soft: boolean;\n}\n\nexport interface ContentSpec {\n readonly type: \"content\";\n readonly target: string;\n readonly check: string;\n readonly value?: string;\n readonly values?: string[];\n readonly case_sensitive?: boolean;\n readonly soft?: boolean;\n}\n\nexport interface EmbeddingSpec {\n readonly type: \"embedding\";\n readonly target: string;\n readonly reference: string;\n readonly threshold: number;\n readonly model?: string;\n readonly soft: boolean;\n}\n\nexport interface LlmJudgeSpec {\n readonly type: \"llm_judge\";\n readonly target: string;\n readonly criteria: string;\n readonly rubric: string;\n readonly threshold: number;\n readonly model?: string;\n readonly soft: boolean;\n}\n\nexport interface TraceTreeSpec {\n readonly type: \"trace_tree\";\n readonly check: string;\n readonly [key: string]: unknown;\n}\n\nexport interface PluginSpec {\n readonly type: \"plugin\";\n readonly plugin_id: string;\n readonly config?: Record<string, unknown>;\n readonly soft: boolean;\n}\n\nexport type AssertionSpec =\n | SchemaSpec\n | ConstraintSpec\n | TraceSpec\n | ContentSpec\n | EmbeddingSpec\n | LlmJudgeSpec\n | TraceTreeSpec\n | PluginSpec;\n\n// ---------------------------------------------------------------------------\n// Core protocol types\n// ---------------------------------------------------------------------------\n\nexport interface TraceMetadata {\n readonly total_tokens?: number;\n readonly cost_usd?: number;\n readonly latency_ms?: number;\n readonly model?: string;\n readonly timestamp?: string;\n}\n\nexport interface Step {\n readonly type: string;\n readonly name: string;\n readonly args?: Record<string, unknown>;\n readonly result?: Record<string, unknown>;\n readonly sub_trace?: Trace;\n readonly metadata?: Record<string, unknown>;\n readonly started_at_ms?: number;\n readonly ended_at_ms?: number;\n readonly agent_id?: string;\n readonly agent_role?: string;\n}\n\nexport interface Trace {\n readonly trace_id: string;\n readonly output: Record<string, unknown>;\n readonly schema_version?: number;\n readonly agent_id?: string;\n readonly input?: Record<string, unknown>;\n readonly steps: readonly Step[];\n readonly metadata?: TraceMetadata;\n readonly parent_trace_id?: string;\n}\n\nexport interface Assertion {\n readonly assertion_id: string;\n readonly type: string;\n readonly spec: Record<string, unknown>;\n readonly request_id?: string;\n}\n\nexport interface AssertionResult {\n readonly assertion_id: string;\n readonly status: string;\n readonly score: number;\n readonly explanation: string;\n readonly cost?: number;\n readonly duration_ms?: number;\n readonly request_id?: string;\n}\n\nexport interface ErrorData {\n readonly error_type: string;\n readonly retryable: boolean;\n readonly detail: string;\n}\n\nexport interface RPCError {\n readonly code: number;\n readonly message: string;\n readonly data?: ErrorData;\n}\n\nexport interface RPCRequest {\n readonly jsonrpc: \"2.0\";\n readonly id: number;\n readonly method: string;\n readonly params: Record<string, unknown>;\n}\n\nexport interface RPCResponse {\n readonly jsonrpc: \"2.0\";\n readonly id: number;\n readonly result?: unknown;\n readonly error?: RPCError;\n}\n\nexport interface InitializeParams {\n readonly sdk_name: string;\n readonly sdk_version: string;\n readonly protocol_version: number;\n readonly required_capabilities: readonly string[];\n readonly preferred_encoding?: string;\n}\n\nexport interface InitializeResult {\n readonly engine_version: string;\n readonly protocol_version: number;\n readonly capabilities: readonly string[];\n readonly missing: readonly string[];\n readonly compatible: boolean;\n readonly encoding?: string;\n readonly max_concurrent_requests?: number;\n readonly max_trace_size_bytes?: number;\n readonly max_steps_per_trace?: number;\n}\n\nexport interface EvaluateBatchParams {\n readonly trace: Trace;\n readonly assertions: readonly Assertion[];\n}\n\nexport interface EvaluateBatchResult {\n readonly results: readonly AssertionResult[];\n readonly total_cost?: number;\n readonly total_duration_ms?: number;\n}\n\nexport interface ShutdownResult {\n readonly sessions_completed: number;\n readonly assertions_evaluated: number;\n}\n\nexport interface SubmitPluginResultParams {\n readonly trace_id: string;\n readonly plugin_name: string;\n readonly assertion_id: string;\n readonly result: AssertionResult;\n}\n","import type { ErrorData } from \"./types.js\";\n\nexport class ProtocolError extends Error {\n readonly code: number;\n readonly errorMessage: string;\n readonly data: ErrorData | undefined;\n\n constructor(code: number, message: string, data?: ErrorData) {\n super(message);\n this.name = \"ProtocolError\";\n this.code = code;\n this.errorMessage = message;\n this.data = data;\n }\n}\n\nexport class EngineTimeoutError extends Error {\n readonly method: string;\n readonly timeoutMs: number;\n\n constructor(method: string, timeoutMs: number) {\n super(\n `Engine request '${method}' timed out after ${timeoutMs}ms. ` +\n \"Set ATTEST_ENGINE_TIMEOUT to increase the limit.\",\n );\n this.name = \"EngineTimeoutError\";\n this.method = method;\n this.timeoutMs = timeoutMs;\n }\n}\n","import type { ErrorData, RPCResponse } from \"./types.js\";\nimport { ProtocolError } from \"./errors.js\";\n\n/**\n * Encode a JSON-RPC 2.0 request as an NDJSON line.\n */\nexport function encodeRequest(\n id: number,\n method: string,\n params: Record<string, unknown>,\n): string {\n const msg = {\n jsonrpc: \"2.0\" as const,\n id,\n method,\n params,\n };\n return JSON.stringify(msg) + \"\\n\";\n}\n\n/**\n * Decode a JSON-RPC 2.0 response from an NDJSON line.\n * Throws ProtocolError if the response contains an error.\n * Throws Error for malformed JSON or invalid responses.\n */\nexport function decodeResponse(line: string): RPCResponse {\n const text = line.trim();\n if (!text) {\n throw new Error(\"empty response line\");\n }\n\n let data: unknown;\n try {\n data = JSON.parse(text);\n } catch (e) {\n throw new Error(`malformed JSON response: ${e instanceof Error ? e.message : String(e)}`);\n }\n\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) {\n throw new Error(`expected JSON object, got ${Array.isArray(data) ? \"array\" : typeof data}`);\n }\n\n const obj = data as Record<string, unknown>;\n\n if (obj.jsonrpc !== \"2.0\") {\n throw new Error(`invalid jsonrpc version: ${String(obj.jsonrpc)}`);\n }\n\n if (obj.error != null) {\n const err = obj.error as Record<string, unknown>;\n let errorData: ErrorData | undefined;\n\n if (err.data != null) {\n const raw = err.data as Record<string, unknown>;\n errorData = {\n error_type: (raw.error_type as string) ?? \"\",\n retryable: (raw.retryable as boolean) ?? false,\n detail: (raw.detail as string) ?? \"\",\n };\n }\n\n throw new ProtocolError(\n (err.code as number) ?? -1,\n (err.message as string) ?? \"unknown error\",\n errorData,\n );\n }\n\n return obj as unknown as RPCResponse;\n}\n\n/**\n * Extract the result field from a decoded response.\n */\nexport function extractResult(response: RPCResponse): unknown {\n if (response.result === undefined) {\n throw new Error(\"response missing 'result' field\");\n }\n return response.result;\n}\n\n/**\n * Extract the request ID from a decoded response.\n */\nexport function extractId(response: RPCResponse): number {\n if (response.id === undefined) {\n throw new Error(\"response missing 'id' field\");\n }\n return Number(response.id);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAO,OAAO,SAAS,EAAE;AAC3B;","names":[]}
1
+ {"version":3,"sources":["../../../src/proto/index.ts","../../../src/proto/constants.ts","../../../src/proto/types.ts","../../../src/proto/errors.ts","../../../src/proto/codec.ts"],"sourcesContent":["export * from \"./constants.js\";\nexport * from \"./types.js\";\nexport * from \"./errors.js\";\nexport { encodeRequest, decodeResponse, extractResult, extractId } from \"./codec.js\";\n","// Step type constants\nexport const STEP_LLM_CALL = \"llm_call\" as const;\nexport const STEP_TOOL_CALL = \"tool_call\" as const;\nexport const STEP_RETRIEVAL = \"retrieval\" as const;\nexport const STEP_AGENT_CALL = \"agent_call\" as const;\n\n// Status constants\nexport const STATUS_PASS = \"pass\" as const;\nexport const STATUS_SOFT_FAIL = \"soft_fail\" as const;\nexport const STATUS_HARD_FAIL = \"hard_fail\" as const;\n\n// Assertion type constants\nexport const TYPE_SCHEMA = \"schema\" as const;\nexport const TYPE_CONSTRAINT = \"constraint\" as const;\nexport const TYPE_TRACE = \"trace\" as const;\nexport const TYPE_CONTENT = \"content\" as const;\nexport const TYPE_EMBEDDING = \"embedding\" as const;\nexport const TYPE_LLM_JUDGE = \"llm_judge\" as const;\nexport const TYPE_TRACE_TREE = \"trace_tree\" as const;\nexport const TYPE_PLUGIN = \"plugin\" as const;\n\n// Error code constants\nexport const ERR_INVALID_TRACE = 1001 as const;\nexport const ERR_ASSERTION_ERROR = 1002 as const;\nexport const ERR_PROVIDER_ERROR = 2001 as const;\nexport const ERR_ENGINE_ERROR = 3001 as const;\nexport const ERR_TIMEOUT = 3002 as const;\nexport const ERR_SESSION_ERROR = 3003 as const;\n","// ---------------------------------------------------------------------------\n// Branded ID types (T6)\n// ---------------------------------------------------------------------------\n\ndeclare const __brand: unique symbol;\ntype Brand<T, B extends string> = T & { readonly [__brand]: B };\n\nexport type TraceId = Brand<string, \"TraceId\">;\nexport type AssertionId = Brand<string, \"AssertionId\">;\nexport type AgentId = Brand<string, \"AgentId\">;\n\nexport function traceId(id: string): TraceId {\n return id as TraceId;\n}\n\nexport function assertionId(id: string): AssertionId {\n return id as AssertionId;\n}\n\nexport function agentId(id: string): AgentId {\n return id as AgentId;\n}\n\n// ---------------------------------------------------------------------------\n// Assertion spec discriminated unions (T5)\n// ---------------------------------------------------------------------------\n\nexport interface SchemaSpec {\n readonly type: \"schema\";\n readonly target: string;\n readonly schema: Record<string, unknown>;\n}\n\nexport interface ConstraintSpec {\n readonly type: \"constraint\";\n readonly field: string;\n readonly operator: string;\n readonly value?: number;\n readonly min?: number;\n readonly max?: number;\n readonly soft: boolean;\n}\n\nexport interface TraceSpec {\n readonly type: \"trace\";\n readonly check: string;\n readonly tools?: string[];\n readonly tool?: string;\n readonly max_repetitions?: number;\n readonly soft: boolean;\n}\n\nexport interface ContentSpec {\n readonly type: \"content\";\n readonly target: string;\n readonly check: string;\n readonly value?: string;\n readonly values?: string[];\n readonly case_sensitive?: boolean;\n readonly soft?: boolean;\n}\n\nexport interface EmbeddingSpec {\n readonly type: \"embedding\";\n readonly target: string;\n readonly reference: string;\n readonly threshold: number | \"dynamic\";\n readonly model?: string;\n readonly soft: boolean;\n}\n\nexport interface LlmJudgeSpec {\n readonly type: \"llm_judge\";\n readonly target: string;\n readonly criteria: string;\n readonly rubric: string;\n readonly threshold: number | \"dynamic\";\n readonly model?: string;\n readonly soft: boolean;\n}\n\nexport interface TraceTreeSpec {\n readonly type: \"trace_tree\";\n readonly check: string;\n readonly [key: string]: unknown;\n}\n\nexport interface PluginSpec {\n readonly type: \"plugin\";\n readonly plugin_id: string;\n readonly config?: Record<string, unknown>;\n readonly soft: boolean;\n}\n\nexport type AssertionSpec =\n | SchemaSpec\n | ConstraintSpec\n | TraceSpec\n | ContentSpec\n | EmbeddingSpec\n | LlmJudgeSpec\n | TraceTreeSpec\n | PluginSpec;\n\n// ---------------------------------------------------------------------------\n// Core protocol types\n// ---------------------------------------------------------------------------\n\nexport interface TraceMetadata {\n readonly total_tokens?: number;\n readonly cost_usd?: number;\n readonly latency_ms?: number;\n readonly model?: string;\n readonly timestamp?: string;\n}\n\nexport interface Step {\n readonly type: string;\n readonly name: string;\n readonly args?: Record<string, unknown>;\n readonly result?: Record<string, unknown>;\n readonly sub_trace?: Trace;\n readonly metadata?: Record<string, unknown>;\n readonly started_at_ms?: number;\n readonly ended_at_ms?: number;\n readonly agent_id?: string;\n readonly agent_role?: string;\n}\n\nexport interface Trace {\n readonly trace_id: string;\n readonly output: Record<string, unknown>;\n readonly schema_version?: number;\n readonly agent_id?: string;\n readonly input?: Record<string, unknown>;\n readonly steps: readonly Step[];\n readonly metadata?: TraceMetadata;\n readonly parent_trace_id?: string;\n}\n\nexport interface Assertion {\n readonly assertion_id: string;\n readonly type: string;\n readonly spec: Record<string, unknown>;\n readonly request_id?: string;\n}\n\nexport interface AssertionResult {\n readonly assertion_id: string;\n readonly status: string;\n readonly score: number;\n readonly explanation: string;\n readonly cost?: number;\n readonly duration_ms?: number;\n readonly request_id?: string;\n}\n\nexport interface ErrorData {\n readonly error_type: string;\n readonly retryable: boolean;\n readonly detail: string;\n}\n\nexport interface RPCError {\n readonly code: number;\n readonly message: string;\n readonly data?: ErrorData;\n}\n\nexport interface RPCRequest {\n readonly jsonrpc: \"2.0\";\n readonly id: number;\n readonly method: string;\n readonly params: Record<string, unknown>;\n}\n\nexport interface RPCResponse {\n readonly jsonrpc: \"2.0\";\n readonly id: number;\n readonly result?: unknown;\n readonly error?: RPCError;\n}\n\nexport interface InitializeParams {\n readonly sdk_name: string;\n readonly sdk_version: string;\n readonly protocol_version: number;\n readonly required_capabilities: readonly string[];\n readonly preferred_encoding?: string;\n}\n\nexport interface InitializeResult {\n readonly engine_version: string;\n readonly protocol_version: number;\n readonly capabilities: readonly string[];\n readonly missing: readonly string[];\n readonly compatible: boolean;\n readonly encoding?: string;\n readonly max_concurrent_requests?: number;\n readonly max_trace_size_bytes?: number;\n readonly max_steps_per_trace?: number;\n}\n\nexport interface EvaluateBatchParams {\n readonly trace: Trace;\n readonly assertions: readonly Assertion[];\n}\n\nexport interface EvaluateBatchResult {\n readonly results: readonly AssertionResult[];\n readonly total_cost?: number;\n readonly total_duration_ms?: number;\n}\n\nexport interface ShutdownResult {\n readonly sessions_completed: number;\n readonly assertions_evaluated: number;\n}\n\nexport interface SubmitPluginResultParams {\n readonly trace_id: string;\n readonly plugin_name: string;\n readonly assertion_id: string;\n readonly result: AssertionResult;\n}\n\n// ---------------------------------------------------------------------------\n// Drift detection types\n// ---------------------------------------------------------------------------\n\nexport interface DriftReport {\n readonly assertion_id: string;\n readonly mean: number;\n readonly stddev: number;\n readonly count: number;\n readonly latest_score: number;\n readonly deviation: number;\n readonly status: string;\n}\n\nexport interface QueryDriftParams {\n readonly assertion_id: string;\n readonly window_size: number;\n}\n\nexport interface QueryDriftResult {\n readonly report: DriftReport;\n}\n\n// ---------------------------------------------------------------------------\n// Simulation types\n// ---------------------------------------------------------------------------\n\nexport interface SimulatePersona {\n readonly name: string;\n readonly system_prompt: string;\n readonly style: string;\n readonly temperature: number;\n readonly max_tokens?: number;\n}\n\nexport interface SimulateFaultConfig {\n readonly error_rate: number;\n readonly latency_jitter_ms: number;\n readonly content_corruption: boolean;\n readonly timeout_after_ms: number;\n}\n\nexport interface ConversationMessage {\n readonly role: string;\n readonly content: string;\n}\n\nexport interface GenerateUserMessageParams {\n readonly persona: SimulatePersona;\n readonly conversation_history: readonly ConversationMessage[];\n readonly fault_config?: SimulateFaultConfig;\n}\n\nexport interface GenerateUserMessageResult {\n readonly message: string;\n}\n","import type { ErrorData } from \"./types.js\";\n\nexport class ProtocolError extends Error {\n readonly code: number;\n readonly errorMessage: string;\n readonly data: ErrorData | undefined;\n\n constructor(code: number, message: string, data?: ErrorData) {\n super(message);\n this.name = \"ProtocolError\";\n this.code = code;\n this.errorMessage = message;\n this.data = data;\n }\n}\n\nexport class EngineTimeoutError extends Error {\n readonly method: string;\n readonly timeoutMs: number;\n\n constructor(method: string, timeoutMs: number) {\n super(\n `Engine request '${method}' timed out after ${timeoutMs}ms. ` +\n \"Set ATTEST_ENGINE_TIMEOUT to increase the limit.\",\n );\n this.name = \"EngineTimeoutError\";\n this.method = method;\n this.timeoutMs = timeoutMs;\n }\n}\n","import type { ErrorData, RPCResponse } from \"./types.js\";\nimport { ProtocolError } from \"./errors.js\";\n\n/**\n * Encode a JSON-RPC 2.0 request as an NDJSON line.\n */\nexport function encodeRequest(\n id: number,\n method: string,\n params: Record<string, unknown>,\n): string {\n const msg = {\n jsonrpc: \"2.0\" as const,\n id,\n method,\n params,\n };\n return JSON.stringify(msg) + \"\\n\";\n}\n\n/**\n * Decode a JSON-RPC 2.0 response from an NDJSON line.\n * Throws ProtocolError if the response contains an error.\n * Throws Error for malformed JSON or invalid responses.\n */\nexport function decodeResponse(line: string): RPCResponse {\n const text = line.trim();\n if (!text) {\n throw new Error(\"empty response line\");\n }\n\n let data: unknown;\n try {\n data = JSON.parse(text);\n } catch (e) {\n throw new Error(`malformed JSON response: ${e instanceof Error ? e.message : String(e)}`);\n }\n\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) {\n throw new Error(`expected JSON object, got ${Array.isArray(data) ? \"array\" : typeof data}`);\n }\n\n const obj = data as Record<string, unknown>;\n\n if (obj.jsonrpc !== \"2.0\") {\n throw new Error(`invalid jsonrpc version: ${String(obj.jsonrpc)}`);\n }\n\n if (obj.error != null) {\n const err = obj.error as Record<string, unknown>;\n let errorData: ErrorData | undefined;\n\n if (err.data != null) {\n const raw = err.data as Record<string, unknown>;\n errorData = {\n error_type: (raw.error_type as string) ?? \"\",\n retryable: (raw.retryable as boolean) ?? false,\n detail: (raw.detail as string) ?? \"\",\n };\n }\n\n throw new ProtocolError(\n (err.code as number) ?? -1,\n (err.message as string) ?? \"unknown error\",\n errorData,\n );\n }\n\n return obj as unknown as RPCResponse;\n}\n\n/**\n * Extract the result field from a decoded response.\n */\nexport function extractResult(response: RPCResponse): unknown {\n if (response.result === undefined) {\n throw new Error(\"response missing 'result' field\");\n }\n return response.result;\n}\n\n/**\n * Extract the request ID from a decoded response.\n */\nexport function extractId(response: RPCResponse): number {\n if (response.id === undefined) {\n throw new Error(\"response missing 'id' field\");\n }\n return Number(response.id);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AAGxB,IAAM,cAAc;AACpB,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AAGzB,IAAM,cAAc;AACpB,IAAM,kBAAkB;AACxB,IAAM,aAAa;AACnB,IAAM,eAAe;AACrB,IAAM,iBAAiB;AACvB,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AACxB,IAAM,cAAc;AAGpB,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAC5B,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,cAAc;AACpB,IAAM,oBAAoB;;;AChB1B,SAAS,QAAQ,IAAqB;AAC3C,SAAO;AACT;AAEO,SAAS,YAAY,IAAyB;AACnD,SAAO;AACT;AAEO,SAAS,QAAQ,IAAqB;AAC3C,SAAO;AACT;;;ACnBO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAAc,SAAiB,MAAkB;AAC3D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,eAAe;AACpB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACnC;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,WAAmB;AAC7C;AAAA,MACE,mBAAmB,MAAM,qBAA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MAAI,SAAS,WAAW,QAAW;AACjC,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,SAAO,SAAS;AAClB;AAKO,SAAS,UAAU,UAA+B;AACvD,MAAI,SAAS,OAAO,QAAW;AAC7B,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACA,SAAO,OAAO,SAAS,EAAE;AAC3B;","names":[]}
@@ -65,7 +65,7 @@ interface EmbeddingSpec {
65
65
  readonly type: "embedding";
66
66
  readonly target: string;
67
67
  readonly reference: string;
68
- readonly threshold: number;
68
+ readonly threshold: number | "dynamic";
69
69
  readonly model?: string;
70
70
  readonly soft: boolean;
71
71
  }
@@ -74,7 +74,7 @@ interface LlmJudgeSpec {
74
74
  readonly target: string;
75
75
  readonly criteria: string;
76
76
  readonly rubric: string;
77
- readonly threshold: number;
77
+ readonly threshold: number | "dynamic";
78
78
  readonly model?: string;
79
79
  readonly soft: boolean;
80
80
  }
@@ -193,6 +193,47 @@ interface SubmitPluginResultParams {
193
193
  readonly assertion_id: string;
194
194
  readonly result: AssertionResult;
195
195
  }
196
+ interface DriftReport {
197
+ readonly assertion_id: string;
198
+ readonly mean: number;
199
+ readonly stddev: number;
200
+ readonly count: number;
201
+ readonly latest_score: number;
202
+ readonly deviation: number;
203
+ readonly status: string;
204
+ }
205
+ interface QueryDriftParams {
206
+ readonly assertion_id: string;
207
+ readonly window_size: number;
208
+ }
209
+ interface QueryDriftResult {
210
+ readonly report: DriftReport;
211
+ }
212
+ interface SimulatePersona {
213
+ readonly name: string;
214
+ readonly system_prompt: string;
215
+ readonly style: string;
216
+ readonly temperature: number;
217
+ readonly max_tokens?: number;
218
+ }
219
+ interface SimulateFaultConfig {
220
+ readonly error_rate: number;
221
+ readonly latency_jitter_ms: number;
222
+ readonly content_corruption: boolean;
223
+ readonly timeout_after_ms: number;
224
+ }
225
+ interface ConversationMessage {
226
+ readonly role: string;
227
+ readonly content: string;
228
+ }
229
+ interface GenerateUserMessageParams {
230
+ readonly persona: SimulatePersona;
231
+ readonly conversation_history: readonly ConversationMessage[];
232
+ readonly fault_config?: SimulateFaultConfig;
233
+ }
234
+ interface GenerateUserMessageResult {
235
+ readonly message: string;
236
+ }
196
237
 
197
238
  declare class ProtocolError extends Error {
198
239
  readonly code: number;
@@ -225,4 +266,4 @@ declare function extractResult(response: RPCResponse): unknown;
225
266
  */
226
267
  declare function extractId(response: RPCResponse): number;
227
268
 
228
- export { type AgentId, type Assertion, type AssertionId, type AssertionResult, type AssertionSpec, type ConstraintSpec, type ContentSpec, ERR_ASSERTION_ERROR, ERR_ENGINE_ERROR, ERR_INVALID_TRACE, ERR_PROVIDER_ERROR, ERR_SESSION_ERROR, ERR_TIMEOUT, type EmbeddingSpec, EngineTimeoutError, type ErrorData, type EvaluateBatchParams, type EvaluateBatchResult, type InitializeParams, type InitializeResult, type LlmJudgeSpec, type PluginSpec, ProtocolError, type RPCError, type RPCRequest, type RPCResponse, STATUS_HARD_FAIL, STATUS_PASS, STATUS_SOFT_FAIL, STEP_AGENT_CALL, STEP_LLM_CALL, STEP_RETRIEVAL, STEP_TOOL_CALL, type SchemaSpec, type ShutdownResult, type Step, type SubmitPluginResultParams, TYPE_CONSTRAINT, TYPE_CONTENT, TYPE_EMBEDDING, TYPE_LLM_JUDGE, TYPE_PLUGIN, TYPE_SCHEMA, TYPE_TRACE, TYPE_TRACE_TREE, type Trace, type TraceId, type TraceMetadata, type TraceSpec, type TraceTreeSpec, agentId, assertionId, decodeResponse, encodeRequest, extractId, extractResult, traceId };
269
+ export { type AgentId, type Assertion, type AssertionId, type AssertionResult, type AssertionSpec, type ConstraintSpec, type ContentSpec, type ConversationMessage, type DriftReport, ERR_ASSERTION_ERROR, ERR_ENGINE_ERROR, ERR_INVALID_TRACE, ERR_PROVIDER_ERROR, ERR_SESSION_ERROR, ERR_TIMEOUT, type EmbeddingSpec, EngineTimeoutError, type ErrorData, type EvaluateBatchParams, type EvaluateBatchResult, type GenerateUserMessageParams, type GenerateUserMessageResult, type InitializeParams, type InitializeResult, type LlmJudgeSpec, type PluginSpec, ProtocolError, type QueryDriftParams, type QueryDriftResult, type RPCError, type RPCRequest, type RPCResponse, STATUS_HARD_FAIL, STATUS_PASS, STATUS_SOFT_FAIL, STEP_AGENT_CALL, STEP_LLM_CALL, STEP_RETRIEVAL, STEP_TOOL_CALL, type SchemaSpec, type ShutdownResult, type SimulateFaultConfig, type SimulatePersona, type Step, type SubmitPluginResultParams, TYPE_CONSTRAINT, TYPE_CONTENT, TYPE_EMBEDDING, TYPE_LLM_JUDGE, TYPE_PLUGIN, TYPE_SCHEMA, TYPE_TRACE, TYPE_TRACE_TREE, type Trace, type TraceId, type TraceMetadata, type TraceSpec, type TraceTreeSpec, agentId, assertionId, decodeResponse, encodeRequest, extractId, extractResult, traceId };
package/dist/esm/cli.js CHANGED
@@ -6,7 +6,7 @@ import * as path from "path";
6
6
  import * as os from "os";
7
7
 
8
8
  // src/version.ts
9
- var VERSION = "0.5.0";
9
+ var VERSION = "0.6.0";
10
10
 
11
11
  // src/cli.ts
12
12
  function cacheDir() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli.ts","../../src/version.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * CLI entry point for Attest: npx attest or attest (after global install).\n *\n * Ported from Python sdks/python/src/attest/__main__.py\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nimport { VERSION } from \"./version.js\";\n\nfunction cacheDir(): string {\n const envOverride = process.env[\"ATTEST_CACHE_DIR\"];\n if (envOverride) return envOverride;\n return path.join(os.homedir(), \".attest\", \"cache\");\n}\n\nfunction cacheDbPath(): string {\n return path.join(cacheDir(), \"attest.db\");\n}\n\nfunction cmdCacheStats(): void {\n const dbPath = cacheDbPath();\n const exists = fs.existsSync(dbPath);\n let fileSize = 0;\n if (exists) {\n fileSize = fs.statSync(dbPath).size;\n }\n const stats = { exists, file_size: fileSize, path: dbPath };\n process.stdout.write(JSON.stringify(stats) + \"\\n\");\n}\n\nfunction cmdCacheClear(): void {\n const dbPath = cacheDbPath();\n if (fs.existsSync(dbPath)) {\n fs.unlinkSync(dbPath);\n process.stdout.write(`Cleared cache: ${dbPath}\\n`);\n } else {\n process.stdout.write(`No cache to clear: ${dbPath}\\n`);\n }\n}\n\nconst CONFTEST_TEMPLATE = `import { describe, it, expect } from \"vitest\";\nimport { attestExpect, TraceBuilder } from \"@attest-ai/core\";\n\ndescribe(\"my agent\", () => {\n it(\"returns expected output\", async () => {\n const trace = new TraceBuilder(\"my-agent\")\n .setInput({ user_message: \"hello\" })\n .setOutput({ message: \"world\" })\n .build();\n\n attestExpect(trace).outputContains(\"world\");\n });\n});\n`;\n\nfunction cmdInit(targetDir: string): void {\n const testsDir = path.join(targetDir, \"tests\");\n fs.mkdirSync(testsDir, { recursive: true });\n process.stdout.write(`Directory: ${testsDir}\\n`);\n\n const sampleTestPath = path.join(testsDir, \"test_my_agent.test.ts\");\n if (fs.existsSync(sampleTestPath)) {\n process.stderr.write(`Skipped (exists): ${sampleTestPath}\\n`);\n } else {\n fs.writeFileSync(sampleTestPath, CONFTEST_TEMPLATE);\n process.stdout.write(`Created: ${sampleTestPath}\\n`);\n }\n}\n\nfunction cmdValidate(targetDir: string): void {\n const testsDir = path.join(targetDir, \"tests\");\n\n let testFiles: string[] = [];\n if (fs.existsSync(testsDir)) {\n testFiles = fs\n .readdirSync(testsDir)\n .filter((f) => f.endsWith(\".test.ts\") || f.endsWith(\".test.js\"));\n }\n\n if (testFiles.length === 0) {\n process.stderr.write(\n `Warning: no test files (*.test.ts / *.test.js) found in ${testsDir}.\\n`,\n );\n } else {\n process.stdout.write(`Found ${testFiles.length} test file(s) in ${testsDir}\\n`);\n }\n\n // Check for stale golden traces\n const STALE_DAYS = 30;\n const now = Date.now();\n const goldenFiles = findGoldenFiles(targetDir);\n for (const golden of goldenFiles) {\n const mtime = fs.statSync(golden).mtimeMs;\n const ageDays = Math.floor((now - mtime) / (1000 * 60 * 60 * 24));\n if (ageDays > STALE_DAYS) {\n process.stderr.write(\n `Warning: golden trace ${golden} is ${ageDays} days old (>${STALE_DAYS} days). Consider regenerating.\\n`,\n );\n }\n }\n}\n\nfunction findGoldenFiles(dir: string): string[] {\n const results: string[] = [];\n if (!fs.existsSync(dir)) return results;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory() && entry.name !== \"node_modules\") {\n results.push(...findGoldenFiles(fullPath));\n } else if (entry.isFile() && entry.name.endsWith(\".golden\")) {\n results.push(fullPath);\n }\n }\n return results;\n}\n\nexport function main(argv: string[] = process.argv.slice(2)): void {\n const args = argv;\n\n if (args[0] === \"--version\") {\n process.stdout.write(`attest ${VERSION}\\n`);\n process.exit(0);\n }\n\n if (args[0] === \"cache\" && args.length >= 2) {\n if (args[1] === \"stats\") {\n cmdCacheStats();\n process.exit(0);\n } else if (args[1] === \"clear\") {\n cmdCacheClear();\n process.exit(0);\n } else {\n process.stderr.write(`Unknown cache subcommand: ${args[1]}\\n`);\n process.stderr.write(\"Available: cache stats, cache clear\\n\");\n process.exit(1);\n }\n }\n\n if (args[0] === \"init\") {\n cmdInit(process.cwd());\n process.exit(0);\n }\n\n if (args[0] === \"validate\") {\n cmdValidate(process.cwd());\n process.exit(0);\n }\n\n process.stderr.write(\n \"Usage: attest <command>\\n\\n\" +\n \"Commands:\\n\" +\n \" --version Print version\\n\" +\n \" init Scaffold a test project\\n\" +\n \" validate Validate test suite\\n\" +\n \" cache stats Show cache statistics\\n\" +\n \" cache clear Clear cache database\\n\",\n );\n process.exit(args.length === 0 ? 0 : 1);\n}\n\n// Run when executed directly\nconst isDirectExecution =\n typeof import.meta.url === \"string\" &&\n import.meta.url.startsWith(\"file:\") &&\n process.argv[1] !== undefined &&\n import.meta.url.endsWith(path.basename(process.argv[1]));\n\nif (isDirectExecution) {\n main();\n}\n","export const VERSION = \"0.5.0\";\nexport const ENGINE_VERSION = \"0.5.0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bin/env node\n/**\n * CLI entry point for Attest: npx attest or attest (after global install).\n *\n * Ported from Python sdks/python/src/attest/__main__.py\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nimport { VERSION } from \"./version.js\";\n\nfunction cacheDir(): string {\n const envOverride = process.env[\"ATTEST_CACHE_DIR\"];\n if (envOverride) return envOverride;\n return path.join(os.homedir(), \".attest\", \"cache\");\n}\n\nfunction cacheDbPath(): string {\n return path.join(cacheDir(), \"attest.db\");\n}\n\nfunction cmdCacheStats(): void {\n const dbPath = cacheDbPath();\n const exists = fs.existsSync(dbPath);\n let fileSize = 0;\n if (exists) {\n fileSize = fs.statSync(dbPath).size;\n }\n const stats = { exists, file_size: fileSize, path: dbPath };\n process.stdout.write(JSON.stringify(stats) + \"\\n\");\n}\n\nfunction cmdCacheClear(): void {\n const dbPath = cacheDbPath();\n if (fs.existsSync(dbPath)) {\n fs.unlinkSync(dbPath);\n process.stdout.write(`Cleared cache: ${dbPath}\\n`);\n } else {\n process.stdout.write(`No cache to clear: ${dbPath}\\n`);\n }\n}\n\nconst CONFTEST_TEMPLATE = `import { describe, it, expect } from \"vitest\";\nimport { attestExpect, TraceBuilder } from \"@attest-ai/core\";\n\ndescribe(\"my agent\", () => {\n it(\"returns expected output\", async () => {\n const trace = new TraceBuilder(\"my-agent\")\n .setInput({ user_message: \"hello\" })\n .setOutput({ message: \"world\" })\n .build();\n\n attestExpect(trace).outputContains(\"world\");\n });\n});\n`;\n\nfunction cmdInit(targetDir: string): void {\n const testsDir = path.join(targetDir, \"tests\");\n fs.mkdirSync(testsDir, { recursive: true });\n process.stdout.write(`Directory: ${testsDir}\\n`);\n\n const sampleTestPath = path.join(testsDir, \"test_my_agent.test.ts\");\n if (fs.existsSync(sampleTestPath)) {\n process.stderr.write(`Skipped (exists): ${sampleTestPath}\\n`);\n } else {\n fs.writeFileSync(sampleTestPath, CONFTEST_TEMPLATE);\n process.stdout.write(`Created: ${sampleTestPath}\\n`);\n }\n}\n\nfunction cmdValidate(targetDir: string): void {\n const testsDir = path.join(targetDir, \"tests\");\n\n let testFiles: string[] = [];\n if (fs.existsSync(testsDir)) {\n testFiles = fs\n .readdirSync(testsDir)\n .filter((f) => f.endsWith(\".test.ts\") || f.endsWith(\".test.js\"));\n }\n\n if (testFiles.length === 0) {\n process.stderr.write(\n `Warning: no test files (*.test.ts / *.test.js) found in ${testsDir}.\\n`,\n );\n } else {\n process.stdout.write(`Found ${testFiles.length} test file(s) in ${testsDir}\\n`);\n }\n\n // Check for stale golden traces\n const STALE_DAYS = 30;\n const now = Date.now();\n const goldenFiles = findGoldenFiles(targetDir);\n for (const golden of goldenFiles) {\n const mtime = fs.statSync(golden).mtimeMs;\n const ageDays = Math.floor((now - mtime) / (1000 * 60 * 60 * 24));\n if (ageDays > STALE_DAYS) {\n process.stderr.write(\n `Warning: golden trace ${golden} is ${ageDays} days old (>${STALE_DAYS} days). Consider regenerating.\\n`,\n );\n }\n }\n}\n\nfunction findGoldenFiles(dir: string): string[] {\n const results: string[] = [];\n if (!fs.existsSync(dir)) return results;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory() && entry.name !== \"node_modules\") {\n results.push(...findGoldenFiles(fullPath));\n } else if (entry.isFile() && entry.name.endsWith(\".golden\")) {\n results.push(fullPath);\n }\n }\n return results;\n}\n\nexport function main(argv: string[] = process.argv.slice(2)): void {\n const args = argv;\n\n if (args[0] === \"--version\") {\n process.stdout.write(`attest ${VERSION}\\n`);\n process.exit(0);\n }\n\n if (args[0] === \"cache\" && args.length >= 2) {\n if (args[1] === \"stats\") {\n cmdCacheStats();\n process.exit(0);\n } else if (args[1] === \"clear\") {\n cmdCacheClear();\n process.exit(0);\n } else {\n process.stderr.write(`Unknown cache subcommand: ${args[1]}\\n`);\n process.stderr.write(\"Available: cache stats, cache clear\\n\");\n process.exit(1);\n }\n }\n\n if (args[0] === \"init\") {\n cmdInit(process.cwd());\n process.exit(0);\n }\n\n if (args[0] === \"validate\") {\n cmdValidate(process.cwd());\n process.exit(0);\n }\n\n process.stderr.write(\n \"Usage: attest <command>\\n\\n\" +\n \"Commands:\\n\" +\n \" --version Print version\\n\" +\n \" init Scaffold a test project\\n\" +\n \" validate Validate test suite\\n\" +\n \" cache stats Show cache statistics\\n\" +\n \" cache clear Clear cache database\\n\",\n );\n process.exit(args.length === 0 ? 0 : 1);\n}\n\n// Run when executed directly\nconst isDirectExecution =\n typeof import.meta.url === \"string\" &&\n import.meta.url.startsWith(\"file:\") &&\n process.argv[1] !== undefined &&\n import.meta.url.endsWith(path.basename(process.argv[1]));\n\nif (isDirectExecution) {\n main();\n}\n","export const VERSION = \"0.6.0\";\nexport const ENGINE_VERSION = \"0.6.0\";\n"],"mappings":";;;AAOA,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;;;ACTb,IAAM,UAAU;;;ADYvB,SAAS,WAAmB;AAC1B,QAAM,cAAc,QAAQ,IAAI,kBAAkB;AAClD,MAAI,YAAa,QAAO;AACxB,SAAY,UAAQ,WAAQ,GAAG,WAAW,OAAO;AACnD;AAEA,SAAS,cAAsB;AAC7B,SAAY,UAAK,SAAS,GAAG,WAAW;AAC1C;AAEA,SAAS,gBAAsB;AAC7B,QAAM,SAAS,YAAY;AAC3B,QAAM,SAAY,cAAW,MAAM;AACnC,MAAI,WAAW;AACf,MAAI,QAAQ;AACV,eAAc,YAAS,MAAM,EAAE;AAAA,EACjC;AACA,QAAM,QAAQ,EAAE,QAAQ,WAAW,UAAU,MAAM,OAAO;AAC1D,UAAQ,OAAO,MAAM,KAAK,UAAU,KAAK,IAAI,IAAI;AACnD;AAEA,SAAS,gBAAsB;AAC7B,QAAM,SAAS,YAAY;AAC3B,MAAO,cAAW,MAAM,GAAG;AACzB,IAAG,cAAW,MAAM;AACpB,YAAQ,OAAO,MAAM,kBAAkB,MAAM;AAAA,CAAI;AAAA,EACnD,O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,KAAK,CAAC;AAAA,EAChB;AAEA,MAAI,KAAK,CAAC,MAAM,YAAY;AAC1B,gBAAY,QAAQ,IAAI,CAAC;AACzB,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,UAAQ,OAAO;AAAA,IACb;AAAA,EAOF;AACA,UAAQ,KAAK,KAAK,WAAW,IAAI,IAAI,CAAC;AACxC;AAGA,IAAM,oBACJ,OAAO,YAAY,QAAQ,YAC3B,YAAY,IAAI,WAAW,OAAO,KAClC,QAAQ,KAAK,CAAC,MAAM,UACpB,YAAY,IAAI,SAAc,cAAS,QAAQ,KAAK,CAAC,CAAC,CAAC;AAEzD,IAAI,mBAAmB;AACrB,OAAK;AACP;","names":[]}
@@ -1,12 +1,12 @@
1
- import { InitializeResult, Trace, Assertion, EvaluateBatchResult, Step, AssertionResult } from './proto/index.js';
2
- export { AgentId, AssertionId, AssertionSpec, ConstraintSpec, ContentSpec, ERR_ASSERTION_ERROR, ERR_ENGINE_ERROR, ERR_INVALID_TRACE, ERR_PROVIDER_ERROR, ERR_SESSION_ERROR, ERR_TIMEOUT, EmbeddingSpec, EngineTimeoutError, ErrorData, EvaluateBatchParams, InitializeParams, LlmJudgeSpec, PluginSpec, ProtocolError, RPCError, RPCRequest, RPCResponse, STATUS_HARD_FAIL, STATUS_PASS, STATUS_SOFT_FAIL, STEP_AGENT_CALL, STEP_LLM_CALL, STEP_RETRIEVAL, STEP_TOOL_CALL, SchemaSpec, ShutdownResult, SubmitPluginResultParams, TYPE_CONSTRAINT, TYPE_CONTENT, TYPE_EMBEDDING, TYPE_LLM_JUDGE, TYPE_PLUGIN, TYPE_SCHEMA, TYPE_TRACE, TYPE_TRACE_TREE, TraceId, TraceMetadata, TraceSpec, TraceTreeSpec, agentId, assertionId, decodeResponse, encodeRequest, extractId, extractResult, traceId } from './proto/index.js';
1
+ import { InitializeResult, Trace, Assertion, EvaluateBatchResult, DriftReport, SimulatePersona, ConversationMessage, SimulateFaultConfig, Step, AssertionResult } from './proto/index.js';
2
+ export { AgentId, AssertionId, AssertionSpec, ConstraintSpec, ContentSpec, ERR_ASSERTION_ERROR, ERR_ENGINE_ERROR, ERR_INVALID_TRACE, ERR_PROVIDER_ERROR, ERR_SESSION_ERROR, ERR_TIMEOUT, EmbeddingSpec, EngineTimeoutError, ErrorData, EvaluateBatchParams, GenerateUserMessageParams, GenerateUserMessageResult, InitializeParams, LlmJudgeSpec, PluginSpec, ProtocolError, QueryDriftParams, QueryDriftResult, RPCError, RPCRequest, RPCResponse, STATUS_HARD_FAIL, STATUS_PASS, STATUS_SOFT_FAIL, STEP_AGENT_CALL, STEP_LLM_CALL, STEP_RETRIEVAL, STEP_TOOL_CALL, SchemaSpec, ShutdownResult, SubmitPluginResultParams, TYPE_CONSTRAINT, TYPE_CONTENT, TYPE_EMBEDDING, TYPE_LLM_JUDGE, TYPE_PLUGIN, TYPE_SCHEMA, TYPE_TRACE, TYPE_TRACE_TREE, TraceId, TraceMetadata, TraceSpec, TraceTreeSpec, agentId, assertionId, decodeResponse, encodeRequest, extractId, extractResult, traceId } from './proto/index.js';
3
3
  import { ChildProcess } from 'node:child_process';
4
4
  import { Interface } from 'node:readline';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
6
6
  import { EventEmitter } from 'node:events';
7
7
 
8
- declare const VERSION = "0.5.0";
9
- declare const ENGINE_VERSION = "0.5.0";
8
+ declare const VERSION = "0.6.0";
9
+ declare const ENGINE_VERSION = "0.6.0";
10
10
 
11
11
  declare class EngineManager {
12
12
  private enginePath;
@@ -50,6 +50,12 @@ declare class AttestClient {
50
50
  submitPluginResult(traceId: string, pluginName: string, assertionId: string, status: string, score: number, explanation: string, options?: {
51
51
  timeout?: number;
52
52
  }): Promise<boolean>;
53
+ queryDrift(assertionId: string, windowSize?: number, options?: {
54
+ timeout?: number;
55
+ }): Promise<DriftReport>;
56
+ generateUserMessage(persona: SimulatePersona, conversationHistory: readonly ConversationMessage[], faultConfig?: SimulateFaultConfig, options?: {
57
+ timeout?: number;
58
+ }): Promise<string>;
53
59
  }
54
60
 
55
61
  declare class TraceBuilder {
@@ -517,7 +523,7 @@ declare class ExpectChain {
517
523
  * ```
518
524
  */
519
525
  outputSimilarTo(reference: string, opts?: {
520
- threshold?: number;
526
+ threshold?: number | "dynamic";
521
527
  model?: string;
522
528
  soft?: boolean;
523
529
  }): this;
@@ -538,7 +544,7 @@ declare class ExpectChain {
538
544
  */
539
545
  passesJudge(criteria: string, opts?: {
540
546
  rubric?: string;
541
- threshold?: number;
547
+ threshold?: number | "dynamic";
542
548
  model?: string;
543
549
  soft?: boolean;
544
550
  }): this;
@@ -805,21 +811,36 @@ declare function tier(level: number): <T extends (...args: never[]) => unknown>(
805
811
  * @param options.simulation - Enable simulation mode. All `evaluateBatch` calls
806
812
  * return deterministic pass results without spawning the engine or calling any
807
813
  * LLM. Equivalent to setting `ATTEST_SIMULATION=1` in the environment.
814
+ * @param options.sampleRate - Sampling rate for continuous evaluation (0.0–1.0).
815
+ * Equivalent to setting `ATTEST_SAMPLE_RATE` in the environment.
808
816
  */
809
817
  declare function config(options: {
810
818
  simulation?: boolean;
819
+ sampleRate?: number;
811
820
  }): void;
812
821
  /**
813
822
  * Returns true when simulation mode is active via either the programmatic API
814
823
  * or the `ATTEST_SIMULATION` environment variable.
815
824
  */
816
825
  declare function isSimulationMode(): boolean;
826
+ /**
827
+ * Returns the sampling rate for continuous evaluation. Priority:
828
+ * programmatic `config({ sampleRate })` > `ATTEST_SAMPLE_RATE` env var > 0.
829
+ */
830
+ declare function getSampleRate(): number;
817
831
  /**
818
832
  * Reset all programmatic config to defaults. Primarily for use in tests.
819
833
  * Environment variables are not affected.
820
834
  */
821
835
  declare function resetConfig(): void;
822
836
 
837
+ /**
838
+ * Return a deterministic all-pass result for every assertion without
839
+ * contacting the engine or any LLM provider. Used when simulation mode
840
+ * is active (`ATTEST_SIMULATION=1` or `config({ simulation: true })`).
841
+ */
842
+ declare function simulationEvaluateBatch(assertions: readonly Assertion[]): EvaluateBatchResult;
843
+
823
844
  interface PluginResult {
824
845
  readonly status: string;
825
846
  readonly score: number;
@@ -882,6 +903,11 @@ declare class ContinuousEvalRunner {
882
903
  private scheduleNext;
883
904
  }
884
905
 
906
+ declare const FRIENDLY_USER: SimulatePersona;
907
+ declare const ADVERSARIAL_USER: SimulatePersona;
908
+ declare const CONFUSED_USER: SimulatePersona;
909
+ declare const COOPERATIVE_USER: SimulatePersona;
910
+
885
911
  declare class ManualAdapter {
886
912
  private readonly agentId;
887
913
  constructor(agentId?: string);
@@ -1082,4 +1108,4 @@ interface TraceAdapter {
1082
1108
  traceFromResponse(response: unknown, options?: Record<string, unknown>): Trace;
1083
1109
  }
1084
1110
 
1085
- export { Agent, AgentResult, AlertDispatcher, type AlertPayload, AnthropicAdapter, Assertion, AssertionResult, AttestClient, type AttestPlugin, ContinuousEvalRunner, ENGINE_VERSION, EngineManager, EvaluateBatchResult, ExpectChain, GeminiAdapter, InitializeResult, LangChainAdapter, ManualAdapter, OTelAdapter, OllamaAdapter, OpenAIAdapter, PluginRegistry, type PluginResult, Sampler, Step, TIER_1, TIER_2, TIER_3, Trace, type TraceAdapter, TraceBuilder, TraceTree, VERSION, activeBuilder, agent, attestExpect, config, delegate, executePluginAssertion, isSimulationMode, resetConfig, tier };
1111
+ export { ADVERSARIAL_USER, Agent, AgentResult, AlertDispatcher, type AlertPayload, AnthropicAdapter, Assertion, AssertionResult, AttestClient, type AttestPlugin, CONFUSED_USER, COOPERATIVE_USER, ContinuousEvalRunner, ConversationMessage, DriftReport, ENGINE_VERSION, EngineManager, EvaluateBatchResult, ExpectChain, FRIENDLY_USER, GeminiAdapter, InitializeResult, LangChainAdapter, ManualAdapter, OTelAdapter, OllamaAdapter, OpenAIAdapter, PluginRegistry, type PluginResult, Sampler, SimulateFaultConfig, SimulatePersona, Step, TIER_1, TIER_2, TIER_3, Trace, type TraceAdapter, TraceBuilder, TraceTree, VERSION, activeBuilder, agent, attestExpect, config, delegate, executePluginAssertion, getSampleRate, isSimulationMode, resetConfig, simulationEvaluateBatch, tier };
package/dist/esm/index.js CHANGED
@@ -119,8 +119,8 @@ function extractId(response) {
119
119
  }
120
120
 
121
121
  // src/version.ts
122
- var VERSION = "0.5.0";
123
- var ENGINE_VERSION = "0.5.0";
122
+ var VERSION = "0.6.0";
123
+ var ENGINE_VERSION = "0.6.0";
124
124
 
125
125
  // src/engine-manager.ts
126
126
  import { spawn, execSync } from "child_process";
@@ -423,16 +423,40 @@ var EngineManager = class {
423
423
 
424
424
  // src/config.ts
425
425
  var _simulationMode = false;
426
+ var _sampleRate = 0;
426
427
  function config(options) {
427
428
  if (options.simulation !== void 0) {
428
429
  _simulationMode = options.simulation;
429
430
  }
431
+ if (options.sampleRate !== void 0) {
432
+ if (options.sampleRate < 0 || options.sampleRate > 1) {
433
+ throw new RangeError(
434
+ `sampleRate must be between 0.0 and 1.0, got ${options.sampleRate}`
435
+ );
436
+ }
437
+ _sampleRate = options.sampleRate;
438
+ }
430
439
  }
431
440
  function isSimulationMode() {
432
441
  return _simulationMode || process.env["ATTEST_SIMULATION"] === "1" || process.env["ATTEST_SIMULATION"] === "true" || process.env["ATTEST_SIMULATION"] === "yes";
433
442
  }
443
+ function getSampleRate() {
444
+ if (_sampleRate > 0) return _sampleRate;
445
+ const env = process.env["ATTEST_SAMPLE_RATE"];
446
+ if (env !== void 0 && env !== "") {
447
+ const parsed = Number(env);
448
+ if (!Number.isFinite(parsed) || parsed < 0 || parsed > 1) {
449
+ throw new RangeError(
450
+ `ATTEST_SAMPLE_RATE must be between 0.0 and 1.0, got '${env}'`
451
+ );
452
+ }
453
+ return parsed;
454
+ }
455
+ return 0;
456
+ }
434
457
  function resetConfig() {
435
458
  _simulationMode = false;
459
+ _sampleRate = 0;
436
460
  }
437
461
 
438
462
  // src/simulation.ts
@@ -617,6 +641,43 @@ var AttestClient = class {
617
641
  );
618
642
  return Boolean(raw?.accepted ?? false);
619
643
  }
644
+ async queryDrift(assertionId2, windowSize = 50, options) {
645
+ if (isSimulationMode()) {
646
+ return {
647
+ assertion_id: assertionId2,
648
+ mean: 1,
649
+ stddev: 0,
650
+ count: 0,
651
+ latest_score: 1,
652
+ deviation: 0,
653
+ status: "no_data"
654
+ };
655
+ }
656
+ const raw = await this.sendRequest(
657
+ "query_drift",
658
+ { assertion_id: assertionId2, window_size: windowSize },
659
+ options?.timeout
660
+ );
661
+ return raw.report;
662
+ }
663
+ async generateUserMessage(persona, conversationHistory, faultConfig, options) {
664
+ if (isSimulationMode()) {
665
+ return `[simulation] Hello from ${persona.name}`;
666
+ }
667
+ const params = {
668
+ persona,
669
+ conversation_history: conversationHistory
670
+ };
671
+ if (faultConfig !== void 0) {
672
+ params.fault_config = faultConfig;
673
+ }
674
+ const raw = await this.sendRequest(
675
+ "generate_user_message",
676
+ params,
677
+ options?.timeout
678
+ );
679
+ return String(raw.message);
680
+ }
620
681
  };
621
682
 
622
683
  // src/trace.ts
@@ -1943,6 +2004,44 @@ var ContinuousEvalRunner = class {
1943
2004
  }
1944
2005
  };
1945
2006
 
2007
+ // src/personas.ts
2008
+ var FRIENDLY_USER = {
2009
+ name: "FriendlyUser",
2010
+ system_prompt: `You are a friendly, cooperative user interacting with an AI assistant.
2011
+ You make clear, well-formed requests. You respond positively to helpful answers and
2012
+ ask straightforward follow-up questions. Keep responses concise (1-3 sentences).`,
2013
+ style: "friendly",
2014
+ temperature: 0.7,
2015
+ max_tokens: 200
2016
+ };
2017
+ var ADVERSARIAL_USER = {
2018
+ name: "AdversarialUser",
2019
+ system_prompt: `You are an adversarial user testing the limits of an AI assistant.
2020
+ You ask edge case questions, make ambiguous requests, and probe boundary conditions.
2021
+ Try to find inconsistencies or unexpected behaviors. Keep responses concise (1-3 sentences).`,
2022
+ style: "adversarial",
2023
+ temperature: 0.9,
2024
+ max_tokens: 200
2025
+ };
2026
+ var CONFUSED_USER = {
2027
+ name: "ConfusedUser",
2028
+ system_prompt: `You are a confused user who has trouble articulating what you want.
2029
+ You make vague requests, sometimes contradict yourself, and frequently ask for clarification.
2030
+ You may misunderstand the assistant's responses. Keep responses concise (1-3 sentences).`,
2031
+ style: "confused",
2032
+ temperature: 0.8,
2033
+ max_tokens: 200
2034
+ };
2035
+ var COOPERATIVE_USER = {
2036
+ name: "CooperativeUser",
2037
+ system_prompt: `You are a cooperative user who actively helps the AI assistant succeed.
2038
+ You provide clear context, answer clarifying questions thoroughly, and confirm when
2039
+ the assistant's response meets your needs. Keep responses concise (1-3 sentences).`,
2040
+ style: "cooperative",
2041
+ temperature: 0.6,
2042
+ max_tokens: 200
2043
+ };
2044
+
1946
2045
  // src/adapters/manual.ts
1947
2046
  var ManualAdapter = class {
1948
2047
  agentId;
@@ -2319,11 +2418,14 @@ var LangChainAdapter = class {
2319
2418
  }
2320
2419
  };
2321
2420
  export {
2421
+ ADVERSARIAL_USER,
2322
2422
  Agent,
2323
2423
  AgentResult,
2324
2424
  AlertDispatcher,
2325
2425
  AnthropicAdapter,
2326
2426
  AttestClient,
2427
+ CONFUSED_USER,
2428
+ COOPERATIVE_USER,
2327
2429
  ContinuousEvalRunner,
2328
2430
  ENGINE_VERSION,
2329
2431
  ERR_ASSERTION_ERROR,
@@ -2335,6 +2437,7 @@ export {
2335
2437
  EngineManager,
2336
2438
  EngineTimeoutError,
2337
2439
  ExpectChain,
2440
+ FRIENDLY_USER,
2338
2441
  GeminiAdapter,
2339
2442
  LangChainAdapter,
2340
2443
  ManualAdapter,
@@ -2377,8 +2480,10 @@ export {
2377
2480
  executePluginAssertion,
2378
2481
  extractId,
2379
2482
  extractResult,
2483
+ getSampleRate,
2380
2484
  isSimulationMode,
2381
2485
  resetConfig,
2486
+ simulationEvaluateBatch,
2382
2487
  tier,
2383
2488
  traceId
2384
2489
  };