@opena2a/oasb 0.2.0 → 0.3.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.
Files changed (52) hide show
  1. package/README.md +61 -18
  2. package/dist/harness/adapter.d.ts +205 -0
  3. package/dist/harness/adapter.js +18 -0
  4. package/dist/harness/arp-wrapper.d.ts +25 -20
  5. package/dist/harness/arp-wrapper.js +137 -28
  6. package/dist/harness/capabilities.d.ts +26 -0
  7. package/dist/harness/capabilities.js +76 -0
  8. package/dist/harness/create-adapter.d.ts +16 -0
  9. package/dist/harness/create-adapter.js +40 -0
  10. package/dist/harness/event-collector.d.ts +1 -1
  11. package/dist/harness/llm-guard-wrapper.d.ts +32 -0
  12. package/dist/harness/llm-guard-wrapper.js +325 -0
  13. package/dist/harness/mock-llm-adapter.d.ts +2 -2
  14. package/dist/harness/mock-llm-adapter.js +6 -5
  15. package/dist/harness/rebuff-wrapper.d.ts +32 -0
  16. package/dist/harness/rebuff-wrapper.js +325 -0
  17. package/dist/harness/types.d.ts +4 -38
  18. package/package.json +15 -7
  19. package/src/atomic/ai-layer/AT-AI-001.prompt-input-scan.test.ts +18 -42
  20. package/src/atomic/ai-layer/AT-AI-002.prompt-output-scan.test.ts +13 -32
  21. package/src/atomic/ai-layer/AT-AI-003.mcp-tool-scan.test.ts +18 -42
  22. package/src/atomic/ai-layer/AT-AI-004.a2a-message-scan.test.ts +14 -36
  23. package/src/atomic/ai-layer/AT-AI-005.pattern-coverage.test.ts +11 -5
  24. package/src/atomic/enforcement/AT-ENF-001.log-action.test.ts +4 -4
  25. package/src/atomic/enforcement/AT-ENF-002.alert-callback.test.ts +5 -5
  26. package/src/atomic/enforcement/AT-ENF-003.pause-sigstop.test.ts +4 -4
  27. package/src/atomic/enforcement/AT-ENF-004.kill-sigterm.test.ts +5 -5
  28. package/src/atomic/enforcement/AT-ENF-005.resume-sigcont.test.ts +4 -4
  29. package/src/atomic/intelligence/AT-INT-001.l0-rule-match.test.ts +1 -1
  30. package/src/atomic/intelligence/AT-INT-002.l1-anomaly-score.test.ts +10 -8
  31. package/src/atomic/intelligence/AT-INT-003.l2-escalation.test.ts +1 -1
  32. package/src/atomic/intelligence/AT-INT-004.budget-exhaustion.test.ts +8 -6
  33. package/src/atomic/intelligence/AT-INT-005.baseline-learning.test.ts +9 -9
  34. package/src/baseline/BL-002.anomaly-injection.test.ts +6 -6
  35. package/src/baseline/BL-003.baseline-persistence.test.ts +9 -9
  36. package/src/harness/adapter.ts +261 -0
  37. package/src/harness/arp-wrapper.ts +175 -42
  38. package/src/harness/capabilities.ts +79 -0
  39. package/src/harness/create-adapter.ts +53 -0
  40. package/src/harness/event-collector.ts +1 -1
  41. package/src/harness/llm-guard-wrapper.ts +345 -0
  42. package/src/harness/mock-llm-adapter.ts +7 -6
  43. package/src/harness/rebuff-wrapper.ts +343 -0
  44. package/src/harness/types.ts +33 -39
  45. package/src/integration/INT-001.data-exfil-detection.test.ts +1 -1
  46. package/src/integration/INT-002.mcp-tool-abuse.test.ts +1 -1
  47. package/src/integration/INT-003.prompt-injection-response.test.ts +1 -1
  48. package/src/integration/INT-004.a2a-trust-exploitation.test.ts +1 -1
  49. package/src/integration/INT-005.baseline-then-attack.test.ts +1 -1
  50. package/src/integration/INT-006.multi-monitor-correlation.test.ts +1 -1
  51. package/src/integration/INT-007.budget-exhaustion-attack.test.ts +8 -8
  52. package/src/integration/INT-008.kill-switch-recovery.test.ts +6 -6
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Capability-aware test helpers.
3
+ *
4
+ * Tests call requireCapability() to skip gracefully when the
5
+ * adapter under test doesn't support a given feature. This produces
6
+ * an honest scorecard: N/A instead of FAIL.
7
+ *
8
+ * @example
9
+ * import { requireCapability } from '../harness/capabilities';
10
+ *
11
+ * describe('MCP Tool Scanning', () => {
12
+ * requireCapability('mcp-scanning');
13
+ * // tests only run if adapter has mcp-scanning
14
+ * });
15
+ */
16
+ import { describe } from 'vitest';
17
+ import { createAdapter } from './create-adapter';
18
+ import type { Capability, CapabilityMatrix } from './adapter';
19
+
20
+ let _matrix: CapabilityMatrix | null = null;
21
+
22
+ function getMatrix(): CapabilityMatrix {
23
+ if (!_matrix) {
24
+ const adapter = createAdapter();
25
+ _matrix = adapter.getCapabilities();
26
+ }
27
+ return _matrix;
28
+ }
29
+
30
+ /**
31
+ * Check if the current adapter has a capability.
32
+ */
33
+ export function hasCapability(cap: Capability): boolean {
34
+ return getMatrix().capabilities.has(cap);
35
+ }
36
+
37
+ /**
38
+ * Call at the top of a describe() block to skip the entire suite
39
+ * if the adapter lacks the required capability.
40
+ *
41
+ * Uses describe.skipIf() so the tests show as skipped, not failed.
42
+ */
43
+ export function requireCapability(cap: Capability): void {
44
+ const has = hasCapability(cap);
45
+ if (!has) {
46
+ // Can't use describe.skipIf at this point, but we can use
47
+ // a beforeAll that throws a skip. The caller should use
48
+ // describeWithCapability instead for cleaner skip behavior.
49
+ }
50
+ }
51
+
52
+ /**
53
+ * A describe() wrapper that skips the entire suite if the adapter
54
+ * lacks the required capability. Produces N/A in the scorecard.
55
+ *
56
+ * @example
57
+ * describeWithCapability('mcp-scanning', 'MCP Tool Scanning', () => {
58
+ * it('should detect path traversal', () => { ... });
59
+ * });
60
+ */
61
+ export const describeWithCapability = (
62
+ cap: Capability,
63
+ name: string,
64
+ fn: () => void,
65
+ ) => {
66
+ const has = hasCapability(cap);
67
+ if (has) {
68
+ describe(name, fn);
69
+ } else {
70
+ describe.skip(`${name} [requires: ${cap}]`, fn);
71
+ }
72
+ };
73
+
74
+ /**
75
+ * Get the full capability matrix for reporting.
76
+ */
77
+ export function getCapabilityMatrix(): CapabilityMatrix {
78
+ return getMatrix();
79
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Adapter factory — selects which security product adapter to use.
3
+ *
4
+ * Set OASB_ADAPTER env var to choose:
5
+ * - "arp" (default) — uses arp-guard (must be installed)
6
+ * - "llm-guard" — uses theRizwan/llm-guard
7
+ * - path to a JS/TS module that exports a class implementing SecurityProductAdapter
8
+ *
9
+ * All test files import from here instead of instantiating adapters directly.
10
+ */
11
+ import type { SecurityProductAdapter, LabConfig } from './adapter';
12
+
13
+ // Eagerly resolve the adapter class at import time.
14
+ // This file is only imported by tests that need the adapter,
15
+ // so the cost is acceptable. Each wrapper handles lazy loading internally.
16
+ import { ArpWrapper } from './arp-wrapper';
17
+ import { LLMGuardWrapper } from './llm-guard-wrapper';
18
+ import { RebuffWrapper } from './rebuff-wrapper';
19
+
20
+ let AdapterClass: new (config?: LabConfig) => SecurityProductAdapter;
21
+
22
+ const adapterName = process.env.OASB_ADAPTER || 'arp';
23
+
24
+ switch (adapterName) {
25
+ case 'arp':
26
+ AdapterClass = ArpWrapper;
27
+ break;
28
+ case 'llm-guard':
29
+ AdapterClass = LLMGuardWrapper;
30
+ break;
31
+ case 'rebuff':
32
+ AdapterClass = RebuffWrapper;
33
+ break;
34
+ default: {
35
+ // Custom adapter — loaded at module level
36
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
37
+ const mod = require(adapterName);
38
+ const Cls = mod.default || mod.Adapter || mod[Object.keys(mod)[0]];
39
+ if (!Cls || typeof Cls !== 'function') {
40
+ throw new Error(`Module "${adapterName}" does not export an adapter class`);
41
+ }
42
+ AdapterClass = Cls;
43
+ break;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Create a configured adapter instance.
49
+ * Uses OASB_ADAPTER env var to select the product under test.
50
+ */
51
+ export function createAdapter(config?: LabConfig): SecurityProductAdapter {
52
+ return new AdapterClass(config);
53
+ }
@@ -1,4 +1,4 @@
1
- import type { ARPEvent, EnforcementResult } from '@opena2a/arp';
1
+ import type { SecurityEvent as ARPEvent, EnforcementResult } from './adapter';
2
2
 
3
3
  /**
4
4
  * Collects ARP events and enforcement results for test assertions.
@@ -0,0 +1,345 @@
1
+ /**
2
+ * llm-guard Adapter — Third-party benchmark comparison
3
+ *
4
+ * Wraps theRizwan/llm-guard (npm: llm-guard) for OASB evaluation.
5
+ * This is a prompt-level scanner only — it does NOT provide:
6
+ * - Process/network/filesystem monitoring
7
+ * - MCP tool call validation
8
+ * - A2A message scanning
9
+ * - Anomaly detection / intelligence layers
10
+ * - Enforcement actions (pause/kill/resume)
11
+ *
12
+ * Tests that require these capabilities will get no-op implementations
13
+ * that return empty/negative results, documenting the coverage gap.
14
+ */
15
+ import * as fs from 'fs';
16
+ import * as os from 'os';
17
+ import * as path from 'path';
18
+ import { EventCollector } from './event-collector';
19
+ import type {
20
+ SecurityProductAdapter,
21
+ SecurityEvent,
22
+ EnforcementResult,
23
+ EnforcementAction,
24
+ LabConfig,
25
+ PromptScanner,
26
+ MCPScanner,
27
+ A2AScanner,
28
+ PatternScanner,
29
+ BudgetManager,
30
+ AnomalyScorer,
31
+ EventEngine,
32
+ EnforcementEngine,
33
+ ScanResult,
34
+ ThreatPattern,
35
+ AlertRule,
36
+ CapabilityMatrix,
37
+ } from './adapter';
38
+
39
+ // Lazy-loaded llm-guard
40
+ let _LLMGuard: any;
41
+ function getLLMGuard(): any {
42
+ if (!_LLMGuard) {
43
+ _LLMGuard = require('llm-guard').LLMGuard;
44
+ }
45
+ return _LLMGuard;
46
+ }
47
+
48
+ /** Convert llm-guard result to OASB ScanResult */
49
+ function toScanResult(guardResult: any): ScanResult {
50
+ const matches: ScanResult['matches'] = [];
51
+
52
+ if (guardResult.results) {
53
+ for (const r of guardResult.results) {
54
+ if (!r.valid && r.details) {
55
+ for (const d of r.details) {
56
+ matches.push({
57
+ pattern: {
58
+ id: d.rule || 'LLM-GUARD',
59
+ category: d.rule?.includes('jailbreak') ? 'jailbreak'
60
+ : d.rule?.includes('pii') ? 'data-exfiltration'
61
+ : d.rule?.includes('injection') ? 'prompt-injection'
62
+ : 'unknown',
63
+ description: d.message || '',
64
+ pattern: /./,
65
+ severity: guardResult.score <= 0.3 ? 'high' : 'medium',
66
+ },
67
+ matchedText: d.matched || '',
68
+ });
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ return {
75
+ detected: !guardResult.isValid,
76
+ matches,
77
+ };
78
+ }
79
+
80
+ /** Simple event engine that stores and emits events */
81
+ class SimpleEventEngine implements EventEngine {
82
+ private handlers: Array<(event: SecurityEvent) => void | Promise<void>> = [];
83
+ private idCounter = 0;
84
+
85
+ emit(event: Omit<SecurityEvent, 'id' | 'timestamp' | 'classifiedBy'>): SecurityEvent {
86
+ const full: SecurityEvent = {
87
+ ...event,
88
+ id: `llmg-${++this.idCounter}`,
89
+ timestamp: new Date().toISOString(),
90
+ classifiedBy: 'llm-guard',
91
+ };
92
+ for (const h of this.handlers) {
93
+ h(full);
94
+ }
95
+ return full;
96
+ }
97
+
98
+ onEvent(handler: (event: SecurityEvent) => void | Promise<void>): void {
99
+ this.handlers.push(handler);
100
+ }
101
+ }
102
+
103
+ /** Simple enforcement engine — llm-guard doesn't have enforcement */
104
+ class SimpleEnforcementEngine implements EnforcementEngine {
105
+ private pausedPids = new Set<number>();
106
+ private alertCallback?: (event: SecurityEvent, rule: AlertRule) => void;
107
+
108
+ async execute(action: EnforcementAction, event: SecurityEvent): Promise<EnforcementResult> {
109
+ return { action, success: true, reason: 'llm-guard-enforcement', event };
110
+ }
111
+
112
+ pause(pid: number): boolean {
113
+ this.pausedPids.add(pid);
114
+ return true;
115
+ }
116
+
117
+ resume(pid: number): boolean {
118
+ return this.pausedPids.delete(pid);
119
+ }
120
+
121
+ kill(pid: number): boolean {
122
+ this.pausedPids.delete(pid);
123
+ return true;
124
+ }
125
+
126
+ getPausedPids(): number[] {
127
+ return [...this.pausedPids];
128
+ }
129
+
130
+ setAlertCallback(callback: (event: SecurityEvent, rule: AlertRule) => void): void {
131
+ this.alertCallback = callback;
132
+ }
133
+ }
134
+
135
+ export class LLMGuardWrapper implements SecurityProductAdapter {
136
+ private _dataDir: string;
137
+ private engine: SimpleEventEngine;
138
+ private enforcement: SimpleEnforcementEngine;
139
+ private rules: AlertRule[];
140
+ readonly collector: EventCollector;
141
+
142
+ constructor(labConfig?: LabConfig) {
143
+ this._dataDir = labConfig?.dataDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'llmg-lab-'));
144
+ this.engine = new SimpleEventEngine();
145
+ this.enforcement = new SimpleEnforcementEngine();
146
+ this.rules = labConfig?.rules ?? [];
147
+ this.collector = new EventCollector();
148
+
149
+ this.engine.onEvent(async (event) => {
150
+ this.collector.eventHandler(event);
151
+
152
+ // Check rules for enforcement
153
+ for (const rule of this.rules) {
154
+ const cond = rule.condition;
155
+ if (cond.category && cond.category !== event.category) continue;
156
+ if (cond.source && cond.source !== event.source) continue;
157
+ if (cond.minSeverity) {
158
+ const sevOrder = ['info', 'low', 'medium', 'high', 'critical'];
159
+ if (sevOrder.indexOf(event.severity) < sevOrder.indexOf(cond.minSeverity)) continue;
160
+ }
161
+ const result = await this.enforcement.execute(rule.action, event);
162
+ result.reason = rule.name;
163
+ this.collector.enforcementHandler(result);
164
+ }
165
+ });
166
+ }
167
+
168
+ getCapabilities(): CapabilityMatrix {
169
+ return {
170
+ product: 'llm-guard',
171
+ version: '0.1.8',
172
+ capabilities: new Set([
173
+ 'prompt-input-scanning',
174
+ 'pattern-scanning',
175
+ ]),
176
+ };
177
+ }
178
+
179
+ async start(): Promise<void> {}
180
+
181
+ async stop(): Promise<void> {
182
+ this.collector.reset();
183
+ try {
184
+ fs.rmSync(this._dataDir, { recursive: true, force: true });
185
+ } catch {}
186
+ }
187
+
188
+ async injectEvent(event: Omit<SecurityEvent, 'id' | 'timestamp' | 'classifiedBy'>): Promise<SecurityEvent> {
189
+ return this.engine.emit(event);
190
+ }
191
+
192
+ waitForEvent(predicate: (event: SecurityEvent) => boolean, timeoutMs: number = 10000): Promise<SecurityEvent> {
193
+ return this.collector.waitForEvent(predicate, timeoutMs);
194
+ }
195
+
196
+ getEvents(): SecurityEvent[] { return this.collector.getEvents(); }
197
+ getEventsByCategory(category: string): SecurityEvent[] { return this.collector.eventsByCategory(category); }
198
+ getEnforcements(): EnforcementResult[] { return this.collector.getEnforcements() as EnforcementResult[]; }
199
+ getEnforcementsByAction(action: string): EnforcementResult[] { return this.collector.enforcementsByAction(action) as EnforcementResult[]; }
200
+ resetCollector(): void { this.collector.reset(); }
201
+
202
+ getEventEngine(): EventEngine { return this.engine; }
203
+ getEnforcementEngine(): EnforcementEngine { return this.enforcement; }
204
+
205
+ get dataDir(): string { return this._dataDir; }
206
+
207
+ // ─── Factory Methods ────────────────────────────────────────────
208
+
209
+ createPromptScanner(): PromptScanner {
210
+ const LLMGuard = getLLMGuard();
211
+ const guard = new LLMGuard({
212
+ promptInjection: { enabled: true },
213
+ jailbreak: { enabled: true },
214
+ pii: { enabled: true },
215
+ });
216
+
217
+ return {
218
+ start: async () => {},
219
+ stop: async () => {},
220
+ scanInput: (text: string) => {
221
+ // llm-guard is async, but OASB scanner interface is sync.
222
+ // We run synchronously by checking patterns manually.
223
+ // This is a limitation — real usage would be async.
224
+ const result = scanWithPatterns(text, 'input');
225
+ return result;
226
+ },
227
+ scanOutput: (text: string) => {
228
+ return scanWithPatterns(text, 'output');
229
+ },
230
+ };
231
+ }
232
+
233
+ createMCPScanner(_allowedTools?: string[]): MCPScanner {
234
+ // llm-guard has no MCP scanning capability
235
+ return {
236
+ start: async () => {},
237
+ stop: async () => {},
238
+ scanToolCall: () => ({ detected: false, matches: [] }),
239
+ };
240
+ }
241
+
242
+ createA2AScanner(_trustedAgents?: string[]): A2AScanner {
243
+ // llm-guard has no A2A scanning capability
244
+ return {
245
+ start: async () => {},
246
+ stop: async () => {},
247
+ scanMessage: () => ({ detected: false, matches: [] }),
248
+ };
249
+ }
250
+
251
+ createPatternScanner(): PatternScanner {
252
+ // llm-guard uses its own internal patterns, not the OASB ThreatPattern format.
253
+ // We expose what we can via regex approximation.
254
+ const patterns = getLLMGuardPatterns();
255
+ return {
256
+ scanText: (text: string, pats: readonly ThreatPattern[]) => scanWithPatterns(text, 'input'),
257
+ getAllPatterns: () => patterns,
258
+ getPatternSets: () => ({
259
+ inputPatterns: patterns.filter(p => p.category !== 'output-leak'),
260
+ outputPatterns: patterns.filter(p => p.category === 'output-leak'),
261
+ mcpPatterns: [],
262
+ a2aPatterns: [],
263
+ }),
264
+ };
265
+ }
266
+
267
+ createBudgetManager(dataDir: string, config?: { budgetUsd?: number; maxCallsPerHour?: number }): BudgetManager {
268
+ // llm-guard has no budget management — implement a simple one
269
+ let spent = 0;
270
+ let totalCalls = 0;
271
+ let callsThisHour = 0;
272
+ const budgetUsd = config?.budgetUsd ?? 5;
273
+ const maxCallsPerHour = config?.maxCallsPerHour ?? 20;
274
+
275
+ return {
276
+ canAfford: (cost: number) => spent + cost <= budgetUsd && callsThisHour < maxCallsPerHour,
277
+ record: (cost: number, _tokens: number) => { spent += cost; totalCalls++; callsThisHour++; },
278
+ getStatus: () => ({
279
+ spent,
280
+ budget: budgetUsd,
281
+ remaining: budgetUsd - spent,
282
+ percentUsed: Math.round((spent / budgetUsd) * 100),
283
+ callsThisHour,
284
+ maxCallsPerHour,
285
+ totalCalls,
286
+ }),
287
+ reset: () => { spent = 0; totalCalls = 0; callsThisHour = 0; },
288
+ };
289
+ }
290
+
291
+ createAnomalyScorer(): AnomalyScorer {
292
+ // llm-guard has no anomaly detection — implement a stub
293
+ const baselines = new Map<string, { mean: number; stddev: number; count: number }>();
294
+ const observations = new Map<string, number[]>();
295
+
296
+ return {
297
+ score: () => 0,
298
+ record: (event: SecurityEvent) => {
299
+ const key = event.source;
300
+ if (!observations.has(key)) observations.set(key, []);
301
+ observations.get(key)!.push(1);
302
+ const vals = observations.get(key)!;
303
+ const mean = vals.length;
304
+ baselines.set(key, { mean, stddev: 0, count: 1 });
305
+ },
306
+ getBaseline: (source: string) => baselines.get(source) ?? null,
307
+ reset: () => { baselines.clear(); observations.clear(); },
308
+ };
309
+ }
310
+ }
311
+
312
+ // ─── Internal pattern-based scanning (sync approximation of llm-guard) ───
313
+
314
+ function getLLMGuardPatterns(): ThreatPattern[] {
315
+ return [
316
+ { id: 'LLMG-PI-001', category: 'prompt-injection', description: 'Instruction override', pattern: /(?:ignore|disregard|forget)\s+(?:all\s+)?(?:previous\s+)?(?:instructions?|prompts?|rules?)/i, severity: 'high' },
317
+ { id: 'LLMG-PI-002', category: 'prompt-injection', description: 'System prompt extraction', pattern: /(?:system\s+prompt|repeat\s+(?:your|the)\s+(?:instructions?|prompt))/i, severity: 'high' },
318
+ { id: 'LLMG-PI-003', category: 'prompt-injection', description: 'Persona override', pattern: /(?:you\s+are\s+now|pretend\s+you\s+are|act\s+as\s+if)/i, severity: 'medium' },
319
+ { id: 'LLMG-JB-001', category: 'jailbreak', description: 'DAN jailbreak', pattern: /(?:DAN|do\s+anything\s+now)/i, severity: 'high' },
320
+ { id: 'LLMG-JB-002', category: 'jailbreak', description: 'Roleplay bypass', pattern: /(?:pretend|imagine|roleplay)\s+(?:you\s+are|as)\s+(?:an?\s+)?(?:evil|unrestricted|unfiltered)/i, severity: 'high' },
321
+ { id: 'LLMG-PII-001', category: 'data-exfiltration', description: 'SSN detection', pattern: /\b\d{3}-\d{2}-\d{4}\b/, severity: 'high' },
322
+ { id: 'LLMG-PII-002', category: 'data-exfiltration', description: 'Credit card detection', pattern: /\b(?:\d{4}[- ]?){3}\d{4}\b/, severity: 'high' },
323
+ { id: 'LLMG-PII-003', category: 'data-exfiltration', description: 'API key detection', pattern: /(?:sk-[a-zA-Z0-9]{20,}|AKIA[A-Z0-9]{12,})/i, severity: 'critical' },
324
+ ];
325
+ }
326
+
327
+ function scanWithPatterns(text: string, _direction: 'input' | 'output'): ScanResult {
328
+ const patterns = getLLMGuardPatterns();
329
+ const matches: ScanResult['matches'] = [];
330
+
331
+ for (const pattern of patterns) {
332
+ const match = pattern.pattern.exec(text);
333
+ if (match) {
334
+ matches.push({
335
+ pattern,
336
+ matchedText: match[0].slice(0, 200),
337
+ });
338
+ }
339
+ }
340
+
341
+ return {
342
+ detected: matches.length > 0,
343
+ matches,
344
+ };
345
+ }
@@ -1,4 +1,4 @@
1
- import type { LLMAdapter, LLMResponse } from '@opena2a/arp';
1
+ import type { LLMAdapter, LLMResponse } from './adapter';
2
2
 
3
3
  interface MockCall {
4
4
  prompt: string;
@@ -21,8 +21,8 @@ export class MockLLMAdapter implements LLMAdapter {
21
21
  this.costPerCall = options?.costPerCall ?? 0.001;
22
22
  }
23
23
 
24
- async assess(prompt: string, maxTokens: number): Promise<LLMResponse> {
25
- this.calls.push({ prompt, maxTokens, timestamp: Date.now() });
24
+ async assess(prompt: string): Promise<LLMResponse> {
25
+ this.calls.push({ prompt, maxTokens: 300, timestamp: Date.now() });
26
26
 
27
27
  if (this.latencyMs > 0) {
28
28
  await new Promise((r) => setTimeout(r, this.latencyMs));
@@ -32,9 +32,10 @@ export class MockLLMAdapter implements LLMAdapter {
32
32
 
33
33
  return {
34
34
  content: response,
35
- inputTokens: Math.ceil(prompt.length / 4),
36
- outputTokens: Math.ceil(response.length / 4),
37
- model: 'mock-llm',
35
+ usage: {
36
+ inputTokens: Math.ceil(prompt.length / 4),
37
+ outputTokens: Math.ceil(response.length / 4),
38
+ },
38
39
  };
39
40
  }
40
41