@agentcontract/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +112 -0
- package/README.md +106 -0
- package/dist/audit-DNON4W2Q.mjs +7 -0
- package/dist/audit-DNON4W2Q.mjs.map +1 -0
- package/dist/chunk-BVUHPJDU.mjs +50 -0
- package/dist/chunk-BVUHPJDU.mjs.map +1 -0
- package/dist/chunk-UHNX2RBZ.mjs +526 -0
- package/dist/chunk-UHNX2RBZ.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +577 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +105 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +259 -0
- package/dist/index.d.ts +259 -0
- package/dist/index.js +654 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +54 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Zod schemas for the AgentContract specification. */
|
|
4
|
+
|
|
5
|
+
declare const Clause: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
6
|
+
text: z.ZodString;
|
|
7
|
+
judge: z.ZodDefault<z.ZodEnum<{
|
|
8
|
+
deterministic: "deterministic";
|
|
9
|
+
llm: "llm";
|
|
10
|
+
}>>;
|
|
11
|
+
description: z.ZodDefault<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>]>;
|
|
13
|
+
type Clause = z.infer<typeof Clause>;
|
|
14
|
+
declare const Assertion: z.ZodObject<{
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
type: z.ZodEnum<{
|
|
17
|
+
llm: "llm";
|
|
18
|
+
pattern: "pattern";
|
|
19
|
+
schema: "schema";
|
|
20
|
+
cost: "cost";
|
|
21
|
+
latency: "latency";
|
|
22
|
+
custom: "custom";
|
|
23
|
+
}>;
|
|
24
|
+
description: z.ZodDefault<z.ZodString>;
|
|
25
|
+
must_not_match: z.ZodOptional<z.ZodString>;
|
|
26
|
+
must_match: z.ZodOptional<z.ZodString>;
|
|
27
|
+
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
28
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
29
|
+
pass_when: z.ZodOptional<z.ZodString>;
|
|
30
|
+
model: z.ZodOptional<z.ZodString>;
|
|
31
|
+
max_usd: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
max_ms: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
plugin: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, z.core.$loose>;
|
|
35
|
+
type Assertion = z.infer<typeof Assertion>;
|
|
36
|
+
declare const Limits: z.ZodDefault<z.ZodObject<{
|
|
37
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
max_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
max_latency_ms: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
max_cost_usd: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
max_tool_calls: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
max_steps: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
type Limits = z.infer<typeof Limits>;
|
|
45
|
+
declare const OnViolation: z.ZodDefault<z.ZodObject<{
|
|
46
|
+
default: z.ZodDefault<z.ZodEnum<{
|
|
47
|
+
warn: "warn";
|
|
48
|
+
block: "block";
|
|
49
|
+
rollback: "rollback";
|
|
50
|
+
halt_and_alert: "halt_and_alert";
|
|
51
|
+
}>>;
|
|
52
|
+
}, z.core.$catchall<z.ZodString>>>;
|
|
53
|
+
type OnViolation = z.infer<typeof OnViolation>;
|
|
54
|
+
declare const Contract: z.ZodObject<{
|
|
55
|
+
agent: z.ZodString;
|
|
56
|
+
'spec-version': z.ZodString;
|
|
57
|
+
version: z.ZodString;
|
|
58
|
+
description: z.ZodDefault<z.ZodString>;
|
|
59
|
+
author: z.ZodDefault<z.ZodString>;
|
|
60
|
+
created: z.ZodDefault<z.ZodString>;
|
|
61
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
62
|
+
extends: z.ZodOptional<z.ZodString>;
|
|
63
|
+
must: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
64
|
+
text: z.ZodString;
|
|
65
|
+
judge: z.ZodDefault<z.ZodEnum<{
|
|
66
|
+
deterministic: "deterministic";
|
|
67
|
+
llm: "llm";
|
|
68
|
+
}>>;
|
|
69
|
+
description: z.ZodDefault<z.ZodString>;
|
|
70
|
+
}, z.core.$strip>]>>>;
|
|
71
|
+
must_not: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
72
|
+
text: z.ZodString;
|
|
73
|
+
judge: z.ZodDefault<z.ZodEnum<{
|
|
74
|
+
deterministic: "deterministic";
|
|
75
|
+
llm: "llm";
|
|
76
|
+
}>>;
|
|
77
|
+
description: z.ZodDefault<z.ZodString>;
|
|
78
|
+
}, z.core.$strip>]>>>;
|
|
79
|
+
can: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
80
|
+
requires: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
81
|
+
text: z.ZodString;
|
|
82
|
+
judge: z.ZodDefault<z.ZodEnum<{
|
|
83
|
+
deterministic: "deterministic";
|
|
84
|
+
llm: "llm";
|
|
85
|
+
}>>;
|
|
86
|
+
on_fail: z.ZodDefault<z.ZodEnum<{
|
|
87
|
+
warn: "warn";
|
|
88
|
+
block: "block";
|
|
89
|
+
}>>;
|
|
90
|
+
description: z.ZodDefault<z.ZodString>;
|
|
91
|
+
}, z.core.$strip>]>>>;
|
|
92
|
+
ensures: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
93
|
+
text: z.ZodString;
|
|
94
|
+
judge: z.ZodDefault<z.ZodEnum<{
|
|
95
|
+
deterministic: "deterministic";
|
|
96
|
+
llm: "llm";
|
|
97
|
+
}>>;
|
|
98
|
+
description: z.ZodDefault<z.ZodString>;
|
|
99
|
+
}, z.core.$strip>]>>>;
|
|
100
|
+
invariant: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
101
|
+
text: z.ZodString;
|
|
102
|
+
judge: z.ZodDefault<z.ZodEnum<{
|
|
103
|
+
deterministic: "deterministic";
|
|
104
|
+
llm: "llm";
|
|
105
|
+
}>>;
|
|
106
|
+
description: z.ZodDefault<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>]>>>;
|
|
108
|
+
assert: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
109
|
+
name: z.ZodString;
|
|
110
|
+
type: z.ZodEnum<{
|
|
111
|
+
llm: "llm";
|
|
112
|
+
pattern: "pattern";
|
|
113
|
+
schema: "schema";
|
|
114
|
+
cost: "cost";
|
|
115
|
+
latency: "latency";
|
|
116
|
+
custom: "custom";
|
|
117
|
+
}>;
|
|
118
|
+
description: z.ZodDefault<z.ZodString>;
|
|
119
|
+
must_not_match: z.ZodOptional<z.ZodString>;
|
|
120
|
+
must_match: z.ZodOptional<z.ZodString>;
|
|
121
|
+
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
122
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
123
|
+
pass_when: z.ZodOptional<z.ZodString>;
|
|
124
|
+
model: z.ZodOptional<z.ZodString>;
|
|
125
|
+
max_usd: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
max_ms: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
plugin: z.ZodOptional<z.ZodString>;
|
|
128
|
+
}, z.core.$loose>>>;
|
|
129
|
+
limits: z.ZodDefault<z.ZodObject<{
|
|
130
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
131
|
+
max_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
132
|
+
max_latency_ms: z.ZodOptional<z.ZodNumber>;
|
|
133
|
+
max_cost_usd: z.ZodOptional<z.ZodNumber>;
|
|
134
|
+
max_tool_calls: z.ZodOptional<z.ZodNumber>;
|
|
135
|
+
max_steps: z.ZodOptional<z.ZodNumber>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
on_violation: z.ZodDefault<z.ZodObject<{
|
|
138
|
+
default: z.ZodDefault<z.ZodEnum<{
|
|
139
|
+
warn: "warn";
|
|
140
|
+
block: "block";
|
|
141
|
+
rollback: "rollback";
|
|
142
|
+
halt_and_alert: "halt_and_alert";
|
|
143
|
+
}>>;
|
|
144
|
+
}, z.core.$catchall<z.ZodString>>>;
|
|
145
|
+
}, z.core.$strip>;
|
|
146
|
+
type Contract = z.infer<typeof Contract>;
|
|
147
|
+
|
|
148
|
+
/** Contract loading and validation. */
|
|
149
|
+
|
|
150
|
+
declare function loadContract(filePath: string): Contract;
|
|
151
|
+
|
|
152
|
+
/** enforce() — wraps any agent function with contract validation. */
|
|
153
|
+
|
|
154
|
+
interface EnforceOptions {
|
|
155
|
+
audit?: boolean;
|
|
156
|
+
auditPath?: string;
|
|
157
|
+
costFn?: (result: unknown) => number;
|
|
158
|
+
}
|
|
159
|
+
type AgentFn<T extends string | Promise<string>> = (input: string) => T;
|
|
160
|
+
declare function enforce<T extends string | Promise<string>>(contract: Contract, fn: AgentFn<T>, options?: EnforceOptions): AgentFn<Promise<string>>;
|
|
161
|
+
|
|
162
|
+
/** Base validator types. */
|
|
163
|
+
interface RunContext {
|
|
164
|
+
input: string;
|
|
165
|
+
output: string;
|
|
166
|
+
durationMs: number;
|
|
167
|
+
costUsd: number;
|
|
168
|
+
toolCalls: unknown[];
|
|
169
|
+
steps: number;
|
|
170
|
+
metadata: Record<string, unknown>;
|
|
171
|
+
}
|
|
172
|
+
declare function makeContext(partial: Partial<RunContext> & {
|
|
173
|
+
input: string;
|
|
174
|
+
output: string;
|
|
175
|
+
}): RunContext;
|
|
176
|
+
interface ValidationResult {
|
|
177
|
+
passed: boolean;
|
|
178
|
+
clauseName: string;
|
|
179
|
+
clauseText: string;
|
|
180
|
+
clauseType: string;
|
|
181
|
+
judge: 'deterministic' | 'llm';
|
|
182
|
+
details: string;
|
|
183
|
+
}
|
|
184
|
+
interface Validator {
|
|
185
|
+
validate(context: RunContext): ValidationResult | Promise<ValidationResult>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Contract validation runner — orchestrates all validators per spec §6.1. */
|
|
189
|
+
|
|
190
|
+
interface ViolationRecord {
|
|
191
|
+
clauseType: string;
|
|
192
|
+
clauseName: string;
|
|
193
|
+
clauseText: string;
|
|
194
|
+
severity: string;
|
|
195
|
+
actionTaken: string;
|
|
196
|
+
judge: string;
|
|
197
|
+
details: string;
|
|
198
|
+
}
|
|
199
|
+
interface RunResult {
|
|
200
|
+
passed: boolean;
|
|
201
|
+
runId: string;
|
|
202
|
+
agent: string;
|
|
203
|
+
contractVersion: string;
|
|
204
|
+
violations: ViolationRecord[];
|
|
205
|
+
context: RunContext;
|
|
206
|
+
outcome: 'pass' | 'violation';
|
|
207
|
+
}
|
|
208
|
+
declare class ContractRunner {
|
|
209
|
+
private contract;
|
|
210
|
+
constructor(contract: Contract);
|
|
211
|
+
run(context: RunContext, runId?: string): Promise<RunResult>;
|
|
212
|
+
private _checkLimits;
|
|
213
|
+
private _runAssertion;
|
|
214
|
+
private _evaluateClause;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Audit trail — tamper-evident JSONL entries for every run. */
|
|
218
|
+
|
|
219
|
+
declare class AuditWriter {
|
|
220
|
+
private logPath;
|
|
221
|
+
constructor(logPath?: string);
|
|
222
|
+
write(result: RunResult, contractPath?: string): Record<string, unknown>;
|
|
223
|
+
private _buildEntry;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** AgentContract exceptions. */
|
|
227
|
+
declare class ContractError extends Error {
|
|
228
|
+
constructor(message: string);
|
|
229
|
+
}
|
|
230
|
+
declare class ContractLoadError extends ContractError {
|
|
231
|
+
constructor(message: string);
|
|
232
|
+
}
|
|
233
|
+
declare class ContractPreconditionError extends ContractError {
|
|
234
|
+
clause: string;
|
|
235
|
+
details: string;
|
|
236
|
+
constructor(clause: string, details?: string);
|
|
237
|
+
}
|
|
238
|
+
declare class ContractViolation extends ContractError {
|
|
239
|
+
violations: Array<{
|
|
240
|
+
clause_type: string;
|
|
241
|
+
clause_text: string;
|
|
242
|
+
action_taken: string;
|
|
243
|
+
}>;
|
|
244
|
+
constructor(violations: Array<{
|
|
245
|
+
clause_type: string;
|
|
246
|
+
clause_text: string;
|
|
247
|
+
action_taken: string;
|
|
248
|
+
}>);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @agentcontract/core — Behavioral contracts for AI agents.
|
|
253
|
+
* TypeScript reference implementation of the AgentContract specification.
|
|
254
|
+
* https://github.com/agentcontract/spec
|
|
255
|
+
*/
|
|
256
|
+
declare const VERSION = "0.1.0";
|
|
257
|
+
declare const SPEC_VERSION = "0.1.0";
|
|
258
|
+
|
|
259
|
+
export { Assertion, AuditWriter, Clause, Contract, ContractError, ContractLoadError, ContractPreconditionError, ContractRunner, ContractViolation, type EnforceOptions, Limits, OnViolation, type RunContext, type RunResult, SPEC_VERSION, VERSION, type ValidationResult, type Validator, type ViolationRecord, enforce, loadContract, makeContext };
|