evidential-protocol 1.0.0 → 1.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/dist/agent-wrapper.d.ts +142 -0
- package/dist/agent-wrapper.d.ts.map +1 -0
- package/dist/agent-wrapper.js +247 -0
- package/dist/agent-wrapper.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-wrapper.d.ts +120 -0
- package/dist/mcp-wrapper.d.ts.map +1 -0
- package/dist/mcp-wrapper.js +225 -0
- package/dist/mcp-wrapper.js.map +1 -0
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +19 -3
- package/dist/middleware.js.map +1 -1
- package/dist/tests/agent-wrapper.test.d.ts +2 -0
- package/dist/tests/agent-wrapper.test.d.ts.map +1 -0
- package/dist/tests/agent-wrapper.test.js +159 -0
- package/dist/tests/agent-wrapper.test.js.map +1 -0
- package/dist/tests/mcp-wrapper.test.d.ts +2 -0
- package/dist/tests/mcp-wrapper.test.d.ts.map +1 -0
- package/dist/tests/mcp-wrapper.test.js +146 -0
- package/dist/tests/mcp-wrapper.test.js.map +1 -0
- package/dist/tests/protocol.test.js +4 -2
- package/dist/tests/protocol.test.js.map +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EP-1 Phase 3: Agent Team Integration
|
|
3
|
+
*
|
|
4
|
+
* Wraps agent team outputs in EvidentialResponse format.
|
|
5
|
+
* Enforces inter-agent propagation rules.
|
|
6
|
+
*/
|
|
7
|
+
import { type EvidentialClaim, type EvidentialResponse, type TrustScore } from "./types.js";
|
|
8
|
+
/** Agent identity. */
|
|
9
|
+
export interface AgentIdentity {
|
|
10
|
+
/** Team name (e.g., "security-team"). */
|
|
11
|
+
team: string;
|
|
12
|
+
/** Agent role within team (e.g., "credential-auditor"). */
|
|
13
|
+
role: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Fluent builder for agent team outputs that enforces EP-1.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const output = new AgentOutputBuilder({
|
|
21
|
+
* team: "security-team",
|
|
22
|
+
* role: "credential-auditor",
|
|
23
|
+
* })
|
|
24
|
+
* .direct("EXPO_TOKEN expires in 12 days", "expo-api:token-info")
|
|
25
|
+
* .inferred("SHOPIFY_KEY may be revoked", "shopify-api:401", "3 consecutive 401s")
|
|
26
|
+
* .conjecture("RENDER_TOKEN likely expired", "file-mtime", "94 days old, typical TTL 90")
|
|
27
|
+
* .build({ expired_keys: 3 });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class AgentOutputBuilder {
|
|
31
|
+
private agent;
|
|
32
|
+
private claims;
|
|
33
|
+
constructor(agent: AgentIdentity);
|
|
34
|
+
/** Add a direct-evidence claim. */
|
|
35
|
+
direct(text: string, source: string, opts?: {
|
|
36
|
+
confidence?: number;
|
|
37
|
+
ttl?: number;
|
|
38
|
+
refs?: string[];
|
|
39
|
+
}): this;
|
|
40
|
+
/** Add an inferred-evidence claim. */
|
|
41
|
+
inferred(text: string, source: string, reasoning: string, opts?: {
|
|
42
|
+
confidence?: number;
|
|
43
|
+
refs?: string[];
|
|
44
|
+
}): this;
|
|
45
|
+
/** Add a reported-evidence claim. */
|
|
46
|
+
reported(text: string, source: string, opts?: {
|
|
47
|
+
confidence?: number;
|
|
48
|
+
refs?: string[];
|
|
49
|
+
}): this;
|
|
50
|
+
/** Add a conjecture claim. */
|
|
51
|
+
conjecture(text: string, source: string, reasoning: string, opts?: {
|
|
52
|
+
confidence?: number;
|
|
53
|
+
refs?: string[];
|
|
54
|
+
}): this;
|
|
55
|
+
/** Add a raw claim (for advanced use). */
|
|
56
|
+
addClaim(claim: EvidentialClaim): this;
|
|
57
|
+
/** Inherit claims from another agent's output (never upgrades class). */
|
|
58
|
+
inherit(upstream: EvidentialResponse): this;
|
|
59
|
+
/** Inherit specific claims by index from another agent's output. */
|
|
60
|
+
inheritClaims(upstream: EvidentialResponse, indices: number[]): this;
|
|
61
|
+
/** Build the EvidentialResponse. Validates before returning. */
|
|
62
|
+
build<T>(data: T): EvidentialResponse<T>;
|
|
63
|
+
/** Build without validation (use in tests only). */
|
|
64
|
+
buildUnsafe<T>(data: T): EvidentialResponse<T>;
|
|
65
|
+
/** Get trust score for current claims. */
|
|
66
|
+
trustScore(): TrustScore;
|
|
67
|
+
/** Get display-formatted trust score. */
|
|
68
|
+
trustDisplay(): string;
|
|
69
|
+
/** Get current claim count. */
|
|
70
|
+
get claimCount(): number;
|
|
71
|
+
/** Reset builder for reuse. */
|
|
72
|
+
reset(): this;
|
|
73
|
+
}
|
|
74
|
+
/** Result of an agent team run including evidential metadata. */
|
|
75
|
+
export interface TeamRunResult<T = unknown> {
|
|
76
|
+
response: EvidentialResponse<T>;
|
|
77
|
+
trust: TrustScore;
|
|
78
|
+
display: string;
|
|
79
|
+
degradations: number;
|
|
80
|
+
requiresReview: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Run an agent team function and wrap the output with evidential metadata.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const result = await runAgentTeam(
|
|
88
|
+
* { team: "ops-team", role: "dns-checker" },
|
|
89
|
+
* async (builder) => {
|
|
90
|
+
* const records = await checkDns("purplesquirrelmedia.io");
|
|
91
|
+
* builder.direct(`DNS has ${records.length} records`, "dns-api:query");
|
|
92
|
+
*
|
|
93
|
+
* if (records.some(r => r.expiring)) {
|
|
94
|
+
* builder.inferred("SSL cert expiring soon", "cert-check", "Expires in < 30 days");
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* return { records, healthy: true };
|
|
98
|
+
* }
|
|
99
|
+
* );
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function runAgentTeam<T>(agent: AgentIdentity, fn: (builder: AgentOutputBuilder) => Promise<T>): Promise<TeamRunResult<T>>;
|
|
103
|
+
/** A step in a multi-agent pipeline. */
|
|
104
|
+
export interface PipelineStep<TIn = unknown, TOut = unknown> {
|
|
105
|
+
agent: AgentIdentity;
|
|
106
|
+
run: (input: TIn, builder: AgentOutputBuilder) => Promise<TOut>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Run a multi-agent pipeline where each step can inherit from the previous.
|
|
110
|
+
* Evidence classes degrade through the chain — they never upgrade.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const result = await runPipeline(initialData, [
|
|
115
|
+
* {
|
|
116
|
+
* agent: { team: "data-team", role: "fetcher" },
|
|
117
|
+
* run: async (input, builder) => {
|
|
118
|
+
* const data = await fetchData(input);
|
|
119
|
+
* builder.direct("Fetched 100 records", "api:fetch");
|
|
120
|
+
* return data;
|
|
121
|
+
* }
|
|
122
|
+
* },
|
|
123
|
+
* {
|
|
124
|
+
* agent: { team: "analysis-team", role: "scorer" },
|
|
125
|
+
* run: async (data, builder) => {
|
|
126
|
+
* const scores = analyze(data);
|
|
127
|
+
* builder.inferred("Average score is 0.85", "analysis:model", "Statistical");
|
|
128
|
+
* return scores;
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* ]);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function runPipeline<T>(initialInput: unknown, steps: PipelineStep[]): Promise<{
|
|
135
|
+
results: EvidentialResponse[];
|
|
136
|
+
finalData: T;
|
|
137
|
+
aggregateTrust: TrustScore;
|
|
138
|
+
display: string;
|
|
139
|
+
}>;
|
|
140
|
+
/** Generate a human-readable evidential report from an agent response. */
|
|
141
|
+
export declare function generateReport(resp: EvidentialResponse): string;
|
|
142
|
+
//# sourceMappingURL=agent-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-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AK,EAAE,aAAa,CAAC;IACrB,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,YAAY,EAAE,GACpB,OAAO,CAAC;IACT,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,SAAS,EAAE,CAAC,CAAC;IACb,cAAc,EAAE,UAAU,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CA4BD;AAMD,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CA8D/D"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EP-1 Phase 3: Agent Team Integration
|
|
3
|
+
*
|
|
4
|
+
* Wraps agent team outputs in EvidentialResponse format.
|
|
5
|
+
* Enforces inter-agent propagation rules.
|
|
6
|
+
*/
|
|
7
|
+
import { response, computeTrustScore, formatTrustDisplay, } from "./schema.js";
|
|
8
|
+
import { directClaim, inferredClaim, reportedClaim, conjectureClaim, inheritClaim, checkDegradation, } from "./middleware.js";
|
|
9
|
+
import { validateResponse } from "./validate.js";
|
|
10
|
+
/** Format agent identity as producer string. */
|
|
11
|
+
function formatProducer(agent) {
|
|
12
|
+
return `${agent.team}:${agent.role}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Fluent builder for agent team outputs that enforces EP-1.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const output = new AgentOutputBuilder({
|
|
20
|
+
* team: "security-team",
|
|
21
|
+
* role: "credential-auditor",
|
|
22
|
+
* })
|
|
23
|
+
* .direct("EXPO_TOKEN expires in 12 days", "expo-api:token-info")
|
|
24
|
+
* .inferred("SHOPIFY_KEY may be revoked", "shopify-api:401", "3 consecutive 401s")
|
|
25
|
+
* .conjecture("RENDER_TOKEN likely expired", "file-mtime", "94 days old, typical TTL 90")
|
|
26
|
+
* .build({ expired_keys: 3 });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class AgentOutputBuilder {
|
|
30
|
+
agent;
|
|
31
|
+
claims = [];
|
|
32
|
+
constructor(agent) {
|
|
33
|
+
this.agent = agent;
|
|
34
|
+
}
|
|
35
|
+
/** Add a direct-evidence claim. */
|
|
36
|
+
direct(text, source, opts) {
|
|
37
|
+
this.claims.push(directClaim(text, source, opts));
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/** Add an inferred-evidence claim. */
|
|
41
|
+
inferred(text, source, reasoning, opts) {
|
|
42
|
+
this.claims.push(inferredClaim(text, source, reasoning, opts));
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/** Add a reported-evidence claim. */
|
|
46
|
+
reported(text, source, opts) {
|
|
47
|
+
this.claims.push(reportedClaim(text, source, opts));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/** Add a conjecture claim. */
|
|
51
|
+
conjecture(text, source, reasoning, opts) {
|
|
52
|
+
this.claims.push(conjectureClaim(text, source, reasoning, opts));
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/** Add a raw claim (for advanced use). */
|
|
56
|
+
addClaim(claim) {
|
|
57
|
+
this.claims.push(claim);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/** Inherit claims from another agent's output (never upgrades class). */
|
|
61
|
+
inherit(upstream) {
|
|
62
|
+
for (const claim of upstream.claims) {
|
|
63
|
+
this.claims.push(inheritClaim(claim, formatProducer(this.agent)));
|
|
64
|
+
}
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/** Inherit specific claims by index from another agent's output. */
|
|
68
|
+
inheritClaims(upstream, indices) {
|
|
69
|
+
for (const i of indices) {
|
|
70
|
+
if (upstream.claims[i]) {
|
|
71
|
+
this.claims.push(inheritClaim(upstream.claims[i], formatProducer(this.agent)));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/** Build the EvidentialResponse. Validates before returning. */
|
|
77
|
+
build(data) {
|
|
78
|
+
const resp = response(formatProducer(this.agent), data, this.claims);
|
|
79
|
+
const validation = validateResponse(resp);
|
|
80
|
+
if (!validation.valid) {
|
|
81
|
+
const errorMessages = validation.errors.map((e) => e.message).join("; ");
|
|
82
|
+
throw new Error(`EP-1 validation failed: ${errorMessages}`);
|
|
83
|
+
}
|
|
84
|
+
return resp;
|
|
85
|
+
}
|
|
86
|
+
/** Build without validation (use in tests only). */
|
|
87
|
+
buildUnsafe(data) {
|
|
88
|
+
return response(formatProducer(this.agent), data, this.claims);
|
|
89
|
+
}
|
|
90
|
+
/** Get trust score for current claims. */
|
|
91
|
+
trustScore() {
|
|
92
|
+
return computeTrustScore(this.claims);
|
|
93
|
+
}
|
|
94
|
+
/** Get display-formatted trust score. */
|
|
95
|
+
trustDisplay() {
|
|
96
|
+
return formatTrustDisplay(this.trustScore());
|
|
97
|
+
}
|
|
98
|
+
/** Get current claim count. */
|
|
99
|
+
get claimCount() {
|
|
100
|
+
return this.claims.length;
|
|
101
|
+
}
|
|
102
|
+
/** Reset builder for reuse. */
|
|
103
|
+
reset() {
|
|
104
|
+
this.claims = [];
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Run an agent team function and wrap the output with evidential metadata.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const result = await runAgentTeam(
|
|
114
|
+
* { team: "ops-team", role: "dns-checker" },
|
|
115
|
+
* async (builder) => {
|
|
116
|
+
* const records = await checkDns("purplesquirrelmedia.io");
|
|
117
|
+
* builder.direct(`DNS has ${records.length} records`, "dns-api:query");
|
|
118
|
+
*
|
|
119
|
+
* if (records.some(r => r.expiring)) {
|
|
120
|
+
* builder.inferred("SSL cert expiring soon", "cert-check", "Expires in < 30 days");
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* return { records, healthy: true };
|
|
124
|
+
* }
|
|
125
|
+
* );
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export async function runAgentTeam(agent, fn) {
|
|
129
|
+
const builder = new AgentOutputBuilder(agent);
|
|
130
|
+
const data = await fn(builder);
|
|
131
|
+
const resp = builder.build(data);
|
|
132
|
+
const trust = computeTrustScore(resp.claims);
|
|
133
|
+
const degradations = checkDegradation(resp);
|
|
134
|
+
return {
|
|
135
|
+
response: resp,
|
|
136
|
+
trust,
|
|
137
|
+
display: formatTrustDisplay(trust),
|
|
138
|
+
degradations: degradations.length,
|
|
139
|
+
requiresReview: trust.requires_review,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Run a multi-agent pipeline where each step can inherit from the previous.
|
|
144
|
+
* Evidence classes degrade through the chain — they never upgrade.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* const result = await runPipeline(initialData, [
|
|
149
|
+
* {
|
|
150
|
+
* agent: { team: "data-team", role: "fetcher" },
|
|
151
|
+
* run: async (input, builder) => {
|
|
152
|
+
* const data = await fetchData(input);
|
|
153
|
+
* builder.direct("Fetched 100 records", "api:fetch");
|
|
154
|
+
* return data;
|
|
155
|
+
* }
|
|
156
|
+
* },
|
|
157
|
+
* {
|
|
158
|
+
* agent: { team: "analysis-team", role: "scorer" },
|
|
159
|
+
* run: async (data, builder) => {
|
|
160
|
+
* const scores = analyze(data);
|
|
161
|
+
* builder.inferred("Average score is 0.85", "analysis:model", "Statistical");
|
|
162
|
+
* return scores;
|
|
163
|
+
* }
|
|
164
|
+
* }
|
|
165
|
+
* ]);
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export async function runPipeline(initialInput, steps) {
|
|
169
|
+
const results = [];
|
|
170
|
+
let currentInput = initialInput;
|
|
171
|
+
for (const step of steps) {
|
|
172
|
+
const builder = new AgentOutputBuilder(step.agent);
|
|
173
|
+
// Inherit claims from previous step
|
|
174
|
+
if (results.length > 0) {
|
|
175
|
+
builder.inherit(results[results.length - 1]);
|
|
176
|
+
}
|
|
177
|
+
const data = await step.run(currentInput, builder);
|
|
178
|
+
const resp = builder.build(data);
|
|
179
|
+
results.push(resp);
|
|
180
|
+
currentInput = data;
|
|
181
|
+
}
|
|
182
|
+
// Aggregate trust across all pipeline steps
|
|
183
|
+
const allClaims = results.flatMap((r) => r.claims);
|
|
184
|
+
const trust = computeTrustScore(allClaims);
|
|
185
|
+
return {
|
|
186
|
+
results,
|
|
187
|
+
finalData: currentInput,
|
|
188
|
+
aggregateTrust: trust,
|
|
189
|
+
display: formatTrustDisplay(trust),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// Report Generator
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
/** Generate a human-readable evidential report from an agent response. */
|
|
196
|
+
export function generateReport(resp) {
|
|
197
|
+
const trust = computeTrustScore(resp.claims);
|
|
198
|
+
const lines = [];
|
|
199
|
+
lines.push(`# Evidential Report — ${resp.producer}`);
|
|
200
|
+
lines.push(`Generated: ${resp.produced_at}`);
|
|
201
|
+
lines.push(`Protocol: EP-1 v${resp.ep_version}`);
|
|
202
|
+
lines.push("");
|
|
203
|
+
lines.push(`## Trust Score`);
|
|
204
|
+
lines.push(formatTrustDisplay(trust));
|
|
205
|
+
lines.push(`Aggregate class: **${resp.aggregate_class}**`);
|
|
206
|
+
lines.push(`Aggregate confidence: **${resp.aggregate_confidence}**`);
|
|
207
|
+
if (trust.requires_review) {
|
|
208
|
+
lines.push(`**WARNING: Trust score below 0.5 — human review required**`);
|
|
209
|
+
}
|
|
210
|
+
lines.push("");
|
|
211
|
+
lines.push(`## Claims (${resp.claims.length})`);
|
|
212
|
+
const classIcons = {
|
|
213
|
+
direct: "●",
|
|
214
|
+
inferred: "◐",
|
|
215
|
+
reported: "○",
|
|
216
|
+
conjecture: "◌",
|
|
217
|
+
};
|
|
218
|
+
for (let i = 0; i < resp.claims.length; i++) {
|
|
219
|
+
const c = resp.claims[i];
|
|
220
|
+
const icon = classIcons[c.evidence.class];
|
|
221
|
+
lines.push(`${i + 1}. ${icon} [${c.evidence.class}] ${c.claim}`);
|
|
222
|
+
lines.push(` Source: ${c.evidence.source} | Confidence: ${c.evidence.confidence}`);
|
|
223
|
+
if (c.evidence.reasoning) {
|
|
224
|
+
lines.push(` Reasoning: ${c.evidence.reasoning}`);
|
|
225
|
+
}
|
|
226
|
+
if (c.evidence.ttl) {
|
|
227
|
+
lines.push(` TTL: ${c.evidence.ttl}s`);
|
|
228
|
+
}
|
|
229
|
+
if (c.refs?.length) {
|
|
230
|
+
lines.push(` Refs: ${c.refs.join(", ")}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Degradation check
|
|
234
|
+
const degradations = checkDegradation(resp);
|
|
235
|
+
if (degradations.length > 0) {
|
|
236
|
+
lines.push("");
|
|
237
|
+
lines.push(`## Degradation Warnings (${degradations.length})`);
|
|
238
|
+
for (const d of degradations) {
|
|
239
|
+
lines.push(`- ${d.claim_id}: ${d.from_class} → ${d.to_class} (${d.reason})`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
lines.push("");
|
|
243
|
+
lines.push("---");
|
|
244
|
+
lines.push("*Generated by Evidential Protocol v1.0*");
|
|
245
|
+
return lines.join("\n");
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=agent-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-wrapper.js","sourceRoot":"","sources":["../src/agent-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EACL,QAAQ,EACR,iBAAiB,EAC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AAC,CAAC,MAAM,GAAG,CACjE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,KAAK,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;IAEtD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* evidential-protocol — EP-1
|
|
3
3
|
*
|
|
4
4
|
* Matsés-inspired evidential metadata for AI agent systems.
|
|
5
5
|
* Every claim must declare its epistemic basis.
|
|
@@ -10,4 +10,6 @@ export { type EvidenceClass, type Evidence, type EvidenceSource, type Evidential
|
|
|
10
10
|
export { weakerClass, strongerClass, isExpired, degradedClass, computeTrustScore, aggregateClass, aggregateConfidence, evidence, claim, response, mcpTag, parseContentMarker, formatContentMarker, extractMarkers, formatTrustDisplay, classifyTool, DEFAULT_TOOL_CLASSIFICATIONS, } from "./schema.js";
|
|
11
11
|
export { validateEvidence, validateClaim, validateResponse, validateMcpTag, type ValidationError, type ValidationResult, } from "./validate.js";
|
|
12
12
|
export { wrapToolResult, buildAgentResponse, directClaim, inferredClaim, reportedClaim, conjectureClaim, inheritClaim, verifyClaim, checkDegradation, applyDegradation, type McpMiddlewareOptions, type EvidentialToolResult, type AgentResponseOptions, } from "./middleware.js";
|
|
13
|
+
export { McpEvidenceWrapper, EvidenceCache, createMcpMiddleware, type ToolHandler, type WrappedToolResult, type WrapperConfig, type McpToolCall, type McpToolResponse, } from "./mcp-wrapper.js";
|
|
14
|
+
export { AgentOutputBuilder, runAgentTeam, runPipeline, generateReport, type AgentIdentity, type TeamRunResult, type PipelineStep, } from "./agent-wrapper.js";
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* evidential-protocol — EP-1
|
|
3
3
|
*
|
|
4
4
|
* Matsés-inspired evidential metadata for AI agent systems.
|
|
5
5
|
* Every claim must declare its epistemic basis.
|
|
@@ -14,4 +14,8 @@ export { weakerClass, strongerClass, isExpired, degradedClass, computeTrustScore
|
|
|
14
14
|
export { validateEvidence, validateClaim, validateResponse, validateMcpTag, } from "./validate.js";
|
|
15
15
|
// Middleware
|
|
16
16
|
export { wrapToolResult, buildAgentResponse, directClaim, inferredClaim, reportedClaim, conjectureClaim, inheritClaim, verifyClaim, checkDegradation, applyDegradation, } from "./middleware.js";
|
|
17
|
+
// MCP Wrapper (Phase 2)
|
|
18
|
+
export { McpEvidenceWrapper, EvidenceCache, createMcpMiddleware, } from "./mcp-wrapper.js";
|
|
19
|
+
// Agent Team Integration (Phase 3)
|
|
20
|
+
export { AgentOutputBuilder, runAgentTeam, runPipeline, generateReport, } from "./agent-wrapper.js";
|
|
17
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,aAAa;AACb,OAAO,EAWL,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,8BAA8B;AAC9B,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,aAAa;AACb,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,GAGf,MAAM,eAAe,CAAC;AAEvB,aAAa;AACb,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GAIjB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,aAAa;AACb,OAAO,EAWL,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,YAAY,CAAC;AAEpB,8BAA8B;AAC9B,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,MAAM,EACN,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,aAAa;AACb,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,GAGf,MAAM,eAAe,CAAC;AAEvB,aAAa;AACb,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,GAIjB,MAAM,iBAAiB,CAAC;AAEzB,wBAAwB;AACxB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,mBAAmB,GAMpB,MAAM,kBAAkB,CAAC;AAE1B,mCAAmC;AACnC,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,cAAc,GAIf,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EP-1 Phase 2: MCP Tool Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Higher-level integration that wraps MCP tool handlers with automatic
|
|
5
|
+
* evidential tagging. Drop-in middleware for any MCP server.
|
|
6
|
+
*/
|
|
7
|
+
import { type EvidenceClass, type McpEvidenceTag, type ToolClassification, type DegradationEvent } from "./types.js";
|
|
8
|
+
/** Generic MCP tool handler function. */
|
|
9
|
+
export type ToolHandler<TArgs = unknown, TResult = unknown> = (args: TArgs) => Promise<TResult>;
|
|
10
|
+
/** Wrapped tool result with evidence metadata. */
|
|
11
|
+
export interface WrappedToolResult<T = unknown> {
|
|
12
|
+
result: T;
|
|
13
|
+
_evidence: McpEvidenceTag;
|
|
14
|
+
}
|
|
15
|
+
/** Configuration for the MCP evidence wrapper. */
|
|
16
|
+
export interface WrapperConfig {
|
|
17
|
+
/** Additional tool classifications to merge with defaults. */
|
|
18
|
+
classifications?: ToolClassification[];
|
|
19
|
+
/** Global TTL override (seconds). */
|
|
20
|
+
defaultTtl?: number;
|
|
21
|
+
/** Called when a cached result has degraded. */
|
|
22
|
+
onDegradation?: (event: DegradationEvent) => void;
|
|
23
|
+
/** Whether to include evidence in error responses. */
|
|
24
|
+
tagErrors?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class EvidenceCache {
|
|
27
|
+
private entries;
|
|
28
|
+
/** Store an evidence tag for a tool+args combination. */
|
|
29
|
+
set(key: string, tag: McpEvidenceTag): void;
|
|
30
|
+
/** Check if a cached entry has degraded. Returns degradation event or null. */
|
|
31
|
+
check(key: string): DegradationEvent | null;
|
|
32
|
+
/** Get all degraded entries. */
|
|
33
|
+
checkAll(): DegradationEvent[];
|
|
34
|
+
/** Remove expired entries. */
|
|
35
|
+
prune(): number;
|
|
36
|
+
get size(): number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Wraps an MCP tool handler to automatically attach evidential metadata.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const wrapper = new McpEvidenceWrapper();
|
|
44
|
+
*
|
|
45
|
+
* // Wrap a tool handler
|
|
46
|
+
* const getBalance = wrapper.wrap("solana-rpc:getBalance", async (args) => {
|
|
47
|
+
* return await rpc.getBalance(args.pubkey);
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Result now includes _evidence
|
|
51
|
+
* const result = await getBalance({ pubkey: "abc..." });
|
|
52
|
+
* // result._evidence.class === "direct"
|
|
53
|
+
* // result._evidence.ttl === 30
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare class McpEvidenceWrapper {
|
|
57
|
+
private config;
|
|
58
|
+
private classifications;
|
|
59
|
+
private cache;
|
|
60
|
+
constructor(config?: WrapperConfig);
|
|
61
|
+
/**
|
|
62
|
+
* Wrap a tool handler with automatic evidence tagging.
|
|
63
|
+
*/
|
|
64
|
+
wrap<TArgs, TResult>(toolName: string, handler: ToolHandler<TArgs, TResult>, overrides?: Partial<{
|
|
65
|
+
class: EvidenceClass;
|
|
66
|
+
ttl: number;
|
|
67
|
+
}>): ToolHandler<TArgs, WrappedToolResult<TResult>>;
|
|
68
|
+
/**
|
|
69
|
+
* Tag an already-computed result (for tools that don't use the wrap pattern).
|
|
70
|
+
*/
|
|
71
|
+
tag<T>(toolName: string, result: T, overrides?: Partial<{
|
|
72
|
+
class: EvidenceClass;
|
|
73
|
+
ttl: number;
|
|
74
|
+
}>): WrappedToolResult<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Batch-tag multiple results from different tools.
|
|
77
|
+
*/
|
|
78
|
+
tagBatch(items: Array<{
|
|
79
|
+
toolName: string;
|
|
80
|
+
result: unknown;
|
|
81
|
+
}>): WrappedToolResult[];
|
|
82
|
+
/** Check all cached results for degradation. */
|
|
83
|
+
checkDegradation(): DegradationEvent[];
|
|
84
|
+
/** Prune stale cache entries. */
|
|
85
|
+
prune(): number;
|
|
86
|
+
/** Get cache size. */
|
|
87
|
+
get cacheSize(): number;
|
|
88
|
+
/** Register additional tool classifications at runtime. */
|
|
89
|
+
registerTool(classification: ToolClassification): void;
|
|
90
|
+
/** Register multiple tool classifications. */
|
|
91
|
+
registerTools(classifications: ToolClassification[]): void;
|
|
92
|
+
}
|
|
93
|
+
/** MCP tool call context. */
|
|
94
|
+
export interface McpToolCall {
|
|
95
|
+
name: string;
|
|
96
|
+
arguments: unknown;
|
|
97
|
+
}
|
|
98
|
+
/** MCP tool response. */
|
|
99
|
+
export interface McpToolResponse {
|
|
100
|
+
content: Array<{
|
|
101
|
+
type: string;
|
|
102
|
+
text?: string;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
}>;
|
|
105
|
+
isError?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates middleware that intercepts MCP tool responses and injects evidence.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const evidenceMiddleware = createMcpMiddleware();
|
|
113
|
+
*
|
|
114
|
+
* // In your MCP server's tool handler:
|
|
115
|
+
* const rawResult = await handleTool(call);
|
|
116
|
+
* const taggedResult = evidenceMiddleware(call, rawResult);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function createMcpMiddleware(config?: WrapperConfig): (call: McpToolCall, response: McpToolResponse) => McpToolResponse;
|
|
120
|
+
//# sourceMappingURL=mcp-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-wrapper.d.ts","sourceRoot":"","sources":["../src/mcp-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAWpB,yCAAyC;AACzC,MAAM,MAAM,WAAW,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,CAC5D,IAAI,EAAE,KAAK,KACR,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,kDAAkD;AAClD,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAC5C,MAAM,EAAE,CAAC,CAAC;IACV,SAAS,EAAE,cAAc,CAAC;CAC3B;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,eAAe,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACvC,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gDA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