evidential-protocol 1.0.0 → 2.0.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 (42) hide show
  1. package/dist/agent-wrapper.d.ts +142 -0
  2. package/dist/agent-wrapper.d.ts.map +1 -0
  3. package/dist/agent-wrapper.js +247 -0
  4. package/dist/agent-wrapper.js.map +1 -0
  5. package/dist/content.d.ts +83 -0
  6. package/dist/content.d.ts.map +1 -0
  7. package/dist/content.js +218 -0
  8. package/dist/content.js.map +1 -0
  9. package/dist/dashboard.d.ts +47 -0
  10. package/dist/dashboard.d.ts.map +1 -0
  11. package/dist/dashboard.js +264 -0
  12. package/dist/dashboard.js.map +1 -0
  13. package/dist/index.d.ts +5 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +9 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp-wrapper.d.ts +120 -0
  18. package/dist/mcp-wrapper.d.ts.map +1 -0
  19. package/dist/mcp-wrapper.js +225 -0
  20. package/dist/mcp-wrapper.js.map +1 -0
  21. package/dist/middleware.d.ts.map +1 -1
  22. package/dist/middleware.js +19 -3
  23. package/dist/middleware.js.map +1 -1
  24. package/dist/tests/agent-wrapper.test.d.ts +2 -0
  25. package/dist/tests/agent-wrapper.test.d.ts.map +1 -0
  26. package/dist/tests/agent-wrapper.test.js +159 -0
  27. package/dist/tests/agent-wrapper.test.js.map +1 -0
  28. package/dist/tests/content.test.d.ts +2 -0
  29. package/dist/tests/content.test.d.ts.map +1 -0
  30. package/dist/tests/content.test.js +122 -0
  31. package/dist/tests/content.test.js.map +1 -0
  32. package/dist/tests/dashboard.test.d.ts +2 -0
  33. package/dist/tests/dashboard.test.d.ts.map +1 -0
  34. package/dist/tests/dashboard.test.js +104 -0
  35. package/dist/tests/dashboard.test.js.map +1 -0
  36. package/dist/tests/mcp-wrapper.test.d.ts +2 -0
  37. package/dist/tests/mcp-wrapper.test.d.ts.map +1 -0
  38. package/dist/tests/mcp-wrapper.test.js +146 -0
  39. package/dist/tests/mcp-wrapper.test.js.map +1 -0
  40. package/dist/tests/protocol.test.js +4 -2
  41. package/dist/tests/protocol.test.js.map +1 -1
  42. package/package.json +17 -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-wrapper.d.ts","sourceRoot":"","sources":["../src/agent-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AAsBpB,sBAAsB;AACtB,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;CACd;AAOD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,MAAM,CAAyB;gBAE3B,KAAK,EAAE,aAAa;IAIhC,mCAAmC;IACnC,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,E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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 @@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AI,YAAY,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,UAAU,MAAM,CAAC,CAAC,QAAQ,KAAK,CAAC,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"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * EP-1 Phase 4: Content Pipeline Integration
3
+ *
4
+ * Tags generated content with inline evidence markers,
5
+ * computes content trust scores, and gates publishing.
6
+ */
7
+ import { type EvidenceClass, type ContentEvidenceMarker, type TrustScore } from "./types.js";
8
+ /** A tagged sentence within content. */
9
+ export interface TaggedSentence {
10
+ /** Original sentence text. */
11
+ text: string;
12
+ /** Evidence marker if tagged. */
13
+ marker?: ContentEvidenceMarker;
14
+ /** Whether this sentence makes a claim that should be tagged. */
15
+ isClaim: boolean;
16
+ }
17
+ /** Result of content analysis. */
18
+ export interface ContentAnalysis {
19
+ /** All sentences in the content. */
20
+ sentences: TaggedSentence[];
21
+ /** Extracted evidence markers. */
22
+ markers: ContentEvidenceMarker[];
23
+ /** Trust score based on markers. */
24
+ trust: TrustScore;
25
+ /** Display string. */
26
+ display: string;
27
+ /** Sentences that appear to be claims but lack markers. */
28
+ untagged_claims: string[];
29
+ /** Content with markers stripped (clean version). */
30
+ clean_text: string;
31
+ /** Whether content passes the publish gate. */
32
+ publishable: boolean;
33
+ }
34
+ /**
35
+ * Detect if a sentence contains a factual claim that should be evidentially tagged.
36
+ */
37
+ export declare function isClaim(sentence: string): boolean;
38
+ /**
39
+ * Strip evidence markers from content, returning clean text.
40
+ */
41
+ export declare function stripMarkers(content: string): string;
42
+ /**
43
+ * Analyze content for evidential completeness.
44
+ */
45
+ export declare function analyzeContent(content: string): ContentAnalysis;
46
+ /**
47
+ * Tag a sentence with an evidence marker.
48
+ */
49
+ export declare function tagSentence(sentence: string, cls: EvidenceClass, source: string, confidence?: number): string;
50
+ /**
51
+ * Auto-tag content by applying evidence markers to detected claims.
52
+ * Uses a default classification function to guess the evidence class.
53
+ */
54
+ export declare function autoTag(content: string, classifier: (sentence: string) => ContentEvidenceMarker | null): string;
55
+ /** Publish gate result. */
56
+ export interface PublishGateResult {
57
+ /** Whether content is approved for publishing. */
58
+ approved: boolean;
59
+ /** Reason if blocked. */
60
+ reason?: string;
61
+ /** Trust score. */
62
+ trust: TrustScore;
63
+ /** Number of untagged claims (claims without evidence). */
64
+ untagged_claims: number;
65
+ /** Recommendations for improvement. */
66
+ recommendations: string[];
67
+ }
68
+ /**
69
+ * Check if content passes the publish gate.
70
+ *
71
+ * Rules:
72
+ * 1. Trust score must be >= threshold (default 0.5)
73
+ * 2. No more than max_untagged claims without evidence markers
74
+ * 3. No conjecture claims without explicit reasoning
75
+ */
76
+ export declare function publishGate(content: string, opts?: {
77
+ trust_threshold?: number;
78
+ max_untagged?: number;
79
+ require_all_tagged?: boolean;
80
+ }): PublishGateResult;
81
+ /** Render content with visual evidence indicators for human review. */
82
+ export declare function renderForReview(content: string): string;
83
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAGhB,MAAM,YAAY,CAAC;AAepB,wCAAwC;AACxC,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,iEAAiE;IACjE,OAAO,EAAE,O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