@cogitator-ai/core 0.3.0 → 0.5.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/README.md +117 -0
- package/dist/causal/capabilities/causal-explainer.d.ts +33 -0
- package/dist/causal/capabilities/causal-explainer.d.ts.map +1 -0
- package/dist/causal/capabilities/causal-explainer.js +334 -0
- package/dist/causal/capabilities/causal-explainer.js.map +1 -0
- package/dist/causal/capabilities/causal-planner.d.ts +42 -0
- package/dist/causal/capabilities/causal-planner.d.ts.map +1 -0
- package/dist/causal/capabilities/causal-planner.js +291 -0
- package/dist/causal/capabilities/causal-planner.js.map +1 -0
- package/dist/causal/capabilities/effect-predictor.d.ts +30 -0
- package/dist/causal/capabilities/effect-predictor.d.ts.map +1 -0
- package/dist/causal/capabilities/effect-predictor.js +266 -0
- package/dist/causal/capabilities/effect-predictor.js.map +1 -0
- package/dist/causal/causal-reasoner.d.ts +63 -0
- package/dist/causal/causal-reasoner.d.ts.map +1 -0
- package/dist/causal/causal-reasoner.js +328 -0
- package/dist/causal/causal-reasoner.js.map +1 -0
- package/dist/causal/discovery/causal-extractor.d.ts +46 -0
- package/dist/causal/discovery/causal-extractor.d.ts.map +1 -0
- package/dist/causal/discovery/causal-extractor.js +154 -0
- package/dist/causal/discovery/causal-extractor.js.map +1 -0
- package/dist/causal/discovery/causal-validator.d.ts +50 -0
- package/dist/causal/discovery/causal-validator.d.ts.map +1 -0
- package/dist/causal/discovery/causal-validator.js +237 -0
- package/dist/causal/discovery/causal-validator.js.map +1 -0
- package/dist/causal/discovery/hypothesis-generator.d.ts +37 -0
- package/dist/causal/discovery/hypothesis-generator.d.ts.map +1 -0
- package/dist/causal/discovery/hypothesis-generator.js +228 -0
- package/dist/causal/discovery/hypothesis-generator.js.map +1 -0
- package/dist/causal/discovery/prompts.d.ts +99 -0
- package/dist/causal/discovery/prompts.d.ts.map +1 -0
- package/dist/causal/discovery/prompts.js +265 -0
- package/dist/causal/discovery/prompts.js.map +1 -0
- package/dist/causal/graph/causal-graph.d.ts +38 -0
- package/dist/causal/graph/causal-graph.d.ts.map +1 -0
- package/dist/causal/graph/causal-graph.js +321 -0
- package/dist/causal/graph/causal-graph.js.map +1 -0
- package/dist/causal/graph/graph-builder.d.ts +68 -0
- package/dist/causal/graph/graph-builder.d.ts.map +1 -0
- package/dist/causal/graph/graph-builder.js +128 -0
- package/dist/causal/graph/graph-builder.js.map +1 -0
- package/dist/causal/index.d.ts +28 -0
- package/dist/causal/index.d.ts.map +1 -0
- package/dist/causal/index.js +18 -0
- package/dist/causal/index.js.map +1 -0
- package/dist/causal/inference/adjustment.d.ts +5 -0
- package/dist/causal/inference/adjustment.d.ts.map +1 -0
- package/dist/causal/inference/adjustment.js +188 -0
- package/dist/causal/inference/adjustment.js.map +1 -0
- package/dist/causal/inference/counterfactual.d.ts +24 -0
- package/dist/causal/inference/counterfactual.d.ts.map +1 -0
- package/dist/causal/inference/counterfactual.js +198 -0
- package/dist/causal/inference/counterfactual.js.map +1 -0
- package/dist/causal/inference/d-separation.d.ts +4 -0
- package/dist/causal/inference/d-separation.d.ts.map +1 -0
- package/dist/causal/inference/d-separation.js +168 -0
- package/dist/causal/inference/d-separation.js.map +1 -0
- package/dist/causal/inference/inference-engine.d.ts +33 -0
- package/dist/causal/inference/inference-engine.d.ts.map +1 -0
- package/dist/causal/inference/inference-engine.js +252 -0
- package/dist/causal/inference/inference-engine.js.map +1 -0
- package/dist/causal/stores/causal-graph-store.d.ts +12 -0
- package/dist/causal/stores/causal-graph-store.d.ts.map +1 -0
- package/dist/causal/stores/causal-graph-store.js +60 -0
- package/dist/causal/stores/causal-graph-store.js.map +1 -0
- package/dist/causal/stores/causal-pattern-store.d.ts +19 -0
- package/dist/causal/stores/causal-pattern-store.d.ts.map +1 -0
- package/dist/causal/stores/causal-pattern-store.js +117 -0
- package/dist/causal/stores/causal-pattern-store.js.map +1 -0
- package/dist/causal/stores/intervention-log.d.ts +16 -0
- package/dist/causal/stores/intervention-log.d.ts.map +1 -0
- package/dist/causal/stores/intervention-log.js +113 -0
- package/dist/causal/stores/intervention-log.js.map +1 -0
- package/dist/cogitator.d.ts.map +1 -1
- package/dist/cogitator.js +10 -5
- package/dist/cogitator.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/learning/ab-testing.d.ts.map +1 -1
- package/dist/learning/ab-testing.js +6 -5
- package/dist/learning/ab-testing.js.map +1 -1
- package/dist/learning/auto-optimizer.d.ts.map +1 -1
- package/dist/learning/auto-optimizer.js +4 -2
- package/dist/learning/auto-optimizer.js.map +1 -1
- package/dist/learning/postgres-trace-store.d.ts.map +1 -1
- package/dist/learning/postgres-trace-store.js +15 -5
- package/dist/learning/postgres-trace-store.js.map +1 -1
- package/dist/learning/prompt-monitor.d.ts.map +1 -1
- package/dist/learning/prompt-monitor.js.map +1 -1
- package/dist/learning/rollback-manager.d.ts.map +1 -1
- package/dist/learning/rollback-manager.js.map +1 -1
- package/dist/llm/google.d.ts.map +1 -1
- package/dist/llm/google.js +5 -3
- package/dist/llm/google.js.map +1 -1
- package/package.json +5 -5
- package/dist/__tests__/agent.test.d.ts +0 -2
- package/dist/__tests__/agent.test.d.ts.map +0 -1
- package/dist/__tests__/agent.test.js +0 -91
- package/dist/__tests__/agent.test.js.map +0 -1
- package/dist/__tests__/base64.test.d.ts +0 -2
- package/dist/__tests__/base64.test.d.ts.map +0 -1
- package/dist/__tests__/base64.test.js +0 -62
- package/dist/__tests__/base64.test.js.map +0 -1
- package/dist/__tests__/calculator.test.d.ts +0 -2
- package/dist/__tests__/calculator.test.d.ts.map +0 -1
- package/dist/__tests__/calculator.test.js +0 -146
- package/dist/__tests__/calculator.test.js.map +0 -1
- package/dist/__tests__/cogitator-memory.test.d.ts +0 -2
- package/dist/__tests__/cogitator-memory.test.d.ts.map +0 -1
- package/dist/__tests__/cogitator-memory.test.js +0 -176
- package/dist/__tests__/cogitator-memory.test.js.map +0 -1
- package/dist/__tests__/datetime.test.d.ts +0 -2
- package/dist/__tests__/datetime.test.d.ts.map +0 -1
- package/dist/__tests__/datetime.test.js +0 -87
- package/dist/__tests__/datetime.test.js.map +0 -1
- package/dist/__tests__/exec.test.d.ts +0 -2
- package/dist/__tests__/exec.test.d.ts.map +0 -1
- package/dist/__tests__/exec.test.js +0 -59
- package/dist/__tests__/exec.test.js.map +0 -1
- package/dist/__tests__/filesystem.test.d.ts +0 -2
- package/dist/__tests__/filesystem.test.d.ts.map +0 -1
- package/dist/__tests__/filesystem.test.js +0 -148
- package/dist/__tests__/filesystem.test.js.map +0 -1
- package/dist/__tests__/google-backend.test.d.ts +0 -5
- package/dist/__tests__/google-backend.test.d.ts.map +0 -1
- package/dist/__tests__/google-backend.test.js +0 -429
- package/dist/__tests__/google-backend.test.js.map +0 -1
- package/dist/__tests__/hash.test.d.ts +0 -2
- package/dist/__tests__/hash.test.d.ts.map +0 -1
- package/dist/__tests__/hash.test.js +0 -50
- package/dist/__tests__/hash.test.js.map +0 -1
- package/dist/__tests__/http.test.d.ts +0 -2
- package/dist/__tests__/http.test.d.ts.map +0 -1
- package/dist/__tests__/http.test.js +0 -64
- package/dist/__tests__/http.test.js.map +0 -1
- package/dist/__tests__/json.test.d.ts +0 -2
- package/dist/__tests__/json.test.d.ts.map +0 -1
- package/dist/__tests__/json.test.js +0 -65
- package/dist/__tests__/json.test.js.map +0 -1
- package/dist/__tests__/logger.test.d.ts +0 -2
- package/dist/__tests__/logger.test.d.ts.map +0 -1
- package/dist/__tests__/logger.test.js +0 -186
- package/dist/__tests__/logger.test.js.map +0 -1
- package/dist/__tests__/random.test.d.ts +0 -2
- package/dist/__tests__/random.test.d.ts.map +0 -1
- package/dist/__tests__/random.test.js +0 -81
- package/dist/__tests__/random.test.js.map +0 -1
- package/dist/__tests__/regex.test.d.ts +0 -2
- package/dist/__tests__/regex.test.d.ts.map +0 -1
- package/dist/__tests__/regex.test.js +0 -75
- package/dist/__tests__/regex.test.js.map +0 -1
- package/dist/__tests__/registry.test.d.ts +0 -2
- package/dist/__tests__/registry.test.d.ts.map +0 -1
- package/dist/__tests__/registry.test.js +0 -102
- package/dist/__tests__/registry.test.js.map +0 -1
- package/dist/__tests__/sleep.test.d.ts +0 -2
- package/dist/__tests__/sleep.test.d.ts.map +0 -1
- package/dist/__tests__/sleep.test.js +0 -29
- package/dist/__tests__/sleep.test.js.map +0 -1
- package/dist/__tests__/tool.test.d.ts +0 -2
- package/dist/__tests__/tool.test.d.ts.map +0 -1
- package/dist/__tests__/tool.test.js +0 -103
- package/dist/__tests__/tool.test.js.map +0 -1
- package/dist/__tests__/uuid.test.d.ts +0 -2
- package/dist/__tests__/uuid.test.d.ts.map +0 -1
- package/dist/__tests__/uuid.test.js +0 -37
- package/dist/__tests__/uuid.test.js.map +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CausalHypothesis, CausalEvidence, ExecutionTrace, LLMBackend } from '@cogitator-ai/types';
|
|
2
|
+
export interface CausalValidatorOptions {
|
|
3
|
+
llmBackend: LLMBackend;
|
|
4
|
+
model?: string;
|
|
5
|
+
validationThreshold?: number;
|
|
6
|
+
maxForksPerHypothesis?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ValidationContext {
|
|
9
|
+
originalTrace: ExecutionTrace;
|
|
10
|
+
forkResults: Array<{
|
|
11
|
+
intervention: Record<string, unknown>;
|
|
12
|
+
trace: ExecutionTrace;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export interface ForkRequest {
|
|
16
|
+
hypothesisId: string;
|
|
17
|
+
checkpointId: string;
|
|
18
|
+
intervention: Record<string, unknown>;
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class CausalValidator {
|
|
22
|
+
private llm;
|
|
23
|
+
private model;
|
|
24
|
+
private validationThreshold;
|
|
25
|
+
private maxForksPerHypothesis;
|
|
26
|
+
constructor(options: CausalValidatorOptions);
|
|
27
|
+
validateHypothesis(hypothesis: CausalHypothesis, context: ValidationContext): Promise<{
|
|
28
|
+
validated: boolean;
|
|
29
|
+
adjustedStrength: number;
|
|
30
|
+
adjustedConfidence: number;
|
|
31
|
+
evidence: CausalEvidence[];
|
|
32
|
+
reasoning: string;
|
|
33
|
+
}>;
|
|
34
|
+
validateFromObservations(hypothesis: CausalHypothesis, traces: ExecutionTrace[]): Promise<{
|
|
35
|
+
validated: boolean;
|
|
36
|
+
adjustedStrength: number;
|
|
37
|
+
adjustedConfidence: number;
|
|
38
|
+
evidence: CausalEvidence[];
|
|
39
|
+
}>;
|
|
40
|
+
generateForkRequests(hypothesis: CausalHypothesis, checkpointId: string): ForkRequest[];
|
|
41
|
+
private analyzeTraceForHypothesis;
|
|
42
|
+
private variablePresentInTrace;
|
|
43
|
+
private summarizeTrace;
|
|
44
|
+
private summarizeOutcome;
|
|
45
|
+
private compareTaces;
|
|
46
|
+
private describeStep;
|
|
47
|
+
private getStepResult;
|
|
48
|
+
private isStepSuccessful;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=causal-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"causal-validator.d.ts","sourceRoot":"","sources":["../../../src/causal/discovery/causal-validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,cAAc,EAEd,UAAU,EACX,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,cAAc,CAAC;IAC9B,WAAW,EAAE,KAAK,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACt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1,237 @@
|
|
|
1
|
+
import { buildCausalValidationPrompt, parseValidationResponse } from './prompts';
|
|
2
|
+
export class CausalValidator {
|
|
3
|
+
llm;
|
|
4
|
+
model;
|
|
5
|
+
validationThreshold;
|
|
6
|
+
maxForksPerHypothesis;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.llm = options.llmBackend;
|
|
9
|
+
this.model = options.model ?? 'gpt-4';
|
|
10
|
+
this.validationThreshold = options.validationThreshold ?? 0.7;
|
|
11
|
+
this.maxForksPerHypothesis = options.maxForksPerHypothesis ?? 3;
|
|
12
|
+
}
|
|
13
|
+
async validateHypothesis(hypothesis, context) {
|
|
14
|
+
const originalSummary = this.summarizeTrace(context.originalTrace);
|
|
15
|
+
const forkSummaries = context.forkResults.map((fork) => ({
|
|
16
|
+
intervention: JSON.stringify(fork.intervention),
|
|
17
|
+
outcome: this.summarizeOutcome(fork.trace),
|
|
18
|
+
diffFromOriginal: this.compareTaces(context.originalTrace, fork.trace),
|
|
19
|
+
}));
|
|
20
|
+
const prompt = buildCausalValidationPrompt(hypothesis, {
|
|
21
|
+
id: context.originalTrace.id,
|
|
22
|
+
summary: originalSummary,
|
|
23
|
+
outcome: this.summarizeOutcome(context.originalTrace),
|
|
24
|
+
}, forkSummaries);
|
|
25
|
+
const response = await this.llm.chat({
|
|
26
|
+
model: this.model,
|
|
27
|
+
messages: [{ role: 'user', content: prompt }],
|
|
28
|
+
temperature: 0.3,
|
|
29
|
+
});
|
|
30
|
+
const parsed = parseValidationResponse(response.content);
|
|
31
|
+
if (!parsed) {
|
|
32
|
+
return {
|
|
33
|
+
validated: false,
|
|
34
|
+
adjustedStrength: hypothesis.strength,
|
|
35
|
+
adjustedConfidence: hypothesis.confidence * 0.5,
|
|
36
|
+
evidence: [],
|
|
37
|
+
reasoning: 'Failed to parse validation response',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const validated = parsed.verdict === 'validated' && parsed.confidence >= this.validationThreshold;
|
|
41
|
+
const newEvidence = parsed.evidence.map((e) => ({
|
|
42
|
+
type: 'counterfactual',
|
|
43
|
+
description: e.description,
|
|
44
|
+
strength: e.type === 'supporting' ? parsed.adjustedStrength : 0,
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
}));
|
|
47
|
+
return {
|
|
48
|
+
validated,
|
|
49
|
+
adjustedStrength: parsed.adjustedStrength,
|
|
50
|
+
adjustedConfidence: parsed.confidence,
|
|
51
|
+
evidence: newEvidence,
|
|
52
|
+
reasoning: parsed.reasoning,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async validateFromObservations(hypothesis, traces) {
|
|
56
|
+
let supportingCount = 0;
|
|
57
|
+
let refutingCount = 0;
|
|
58
|
+
const evidence = [];
|
|
59
|
+
for (const trace of traces) {
|
|
60
|
+
const analysis = this.analyzeTraceForHypothesis(hypothesis, trace);
|
|
61
|
+
if (analysis.supports) {
|
|
62
|
+
supportingCount++;
|
|
63
|
+
evidence.push({
|
|
64
|
+
type: 'observational',
|
|
65
|
+
description: analysis.reasoning,
|
|
66
|
+
strength: analysis.strength,
|
|
67
|
+
traceId: trace.id,
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else if (analysis.refutes) {
|
|
72
|
+
refutingCount++;
|
|
73
|
+
evidence.push({
|
|
74
|
+
type: 'observational',
|
|
75
|
+
description: analysis.reasoning,
|
|
76
|
+
strength: -analysis.strength,
|
|
77
|
+
traceId: trace.id,
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const total = supportingCount + refutingCount;
|
|
83
|
+
if (total === 0) {
|
|
84
|
+
return {
|
|
85
|
+
validated: false,
|
|
86
|
+
adjustedStrength: hypothesis.strength,
|
|
87
|
+
adjustedConfidence: hypothesis.confidence,
|
|
88
|
+
evidence: [],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const supportRatio = supportingCount / total;
|
|
92
|
+
const adjustedStrength = hypothesis.strength * supportRatio;
|
|
93
|
+
const adjustedConfidence = Math.min(0.95, hypothesis.confidence + (supportRatio - 0.5) * 0.3);
|
|
94
|
+
return {
|
|
95
|
+
validated: supportRatio >= 0.7 && adjustedConfidence >= this.validationThreshold,
|
|
96
|
+
adjustedStrength,
|
|
97
|
+
adjustedConfidence,
|
|
98
|
+
evidence,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
generateForkRequests(hypothesis, checkpointId) {
|
|
102
|
+
const requests = [];
|
|
103
|
+
requests.push({
|
|
104
|
+
hypothesisId: hypothesis.id,
|
|
105
|
+
checkpointId,
|
|
106
|
+
intervention: { [hypothesis.cause]: null },
|
|
107
|
+
description: `Remove ${hypothesis.cause} to test if ${hypothesis.effect} still occurs`,
|
|
108
|
+
});
|
|
109
|
+
if (hypothesis.relationType === 'causes' || hypothesis.relationType === 'enables') {
|
|
110
|
+
requests.push({
|
|
111
|
+
hypothesisId: hypothesis.id,
|
|
112
|
+
checkpointId,
|
|
113
|
+
intervention: { [hypothesis.cause]: 'amplified' },
|
|
114
|
+
description: `Amplify ${hypothesis.cause} to test if ${hypothesis.effect} increases`,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (hypothesis.relationType === 'prevents') {
|
|
118
|
+
requests.push({
|
|
119
|
+
hypothesisId: hypothesis.id,
|
|
120
|
+
checkpointId,
|
|
121
|
+
intervention: { [hypothesis.cause]: 'removed' },
|
|
122
|
+
description: `Remove prevention to test if ${hypothesis.effect} occurs`,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return requests.slice(0, this.maxForksPerHypothesis);
|
|
126
|
+
}
|
|
127
|
+
analyzeTraceForHypothesis(hypothesis, trace) {
|
|
128
|
+
const causePresent = this.variablePresentInTrace(hypothesis.cause, trace);
|
|
129
|
+
const effectPresent = this.variablePresentInTrace(hypothesis.effect, trace);
|
|
130
|
+
if (hypothesis.relationType === 'causes' || hypothesis.relationType === 'enables') {
|
|
131
|
+
if (causePresent && effectPresent) {
|
|
132
|
+
return {
|
|
133
|
+
supports: true,
|
|
134
|
+
refutes: false,
|
|
135
|
+
strength: 0.6,
|
|
136
|
+
reasoning: `Both ${hypothesis.cause} and ${hypothesis.effect} present`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (causePresent && !effectPresent) {
|
|
140
|
+
return {
|
|
141
|
+
supports: false,
|
|
142
|
+
refutes: true,
|
|
143
|
+
strength: 0.4,
|
|
144
|
+
reasoning: `${hypothesis.cause} present but ${hypothesis.effect} absent`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (hypothesis.relationType === 'prevents') {
|
|
149
|
+
if (causePresent && !effectPresent) {
|
|
150
|
+
return {
|
|
151
|
+
supports: true,
|
|
152
|
+
refutes: false,
|
|
153
|
+
strength: 0.6,
|
|
154
|
+
reasoning: `${hypothesis.cause} present and ${hypothesis.effect} prevented`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (causePresent && effectPresent) {
|
|
158
|
+
return {
|
|
159
|
+
supports: false,
|
|
160
|
+
refutes: true,
|
|
161
|
+
strength: 0.5,
|
|
162
|
+
reasoning: `${hypothesis.cause} present but ${hypothesis.effect} still occurred`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
supports: false,
|
|
168
|
+
refutes: false,
|
|
169
|
+
strength: 0,
|
|
170
|
+
reasoning: 'Insufficient evidence in trace',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
variablePresentInTrace(variable, trace) {
|
|
174
|
+
const searchTerm = variable.toLowerCase();
|
|
175
|
+
for (const step of trace.steps) {
|
|
176
|
+
const action = this.describeStep(step).toLowerCase();
|
|
177
|
+
if (action.includes(searchTerm)) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
const result = this.getStepResult(step)?.toLowerCase();
|
|
181
|
+
if (result?.includes(searchTerm)) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
summarizeTrace(trace) {
|
|
188
|
+
const steps = trace.steps.slice(-5);
|
|
189
|
+
return steps
|
|
190
|
+
.map((s) => `${this.describeStep(s)} → ${this.isStepSuccessful(s) ? 'OK' : 'FAIL'}`)
|
|
191
|
+
.join('; ');
|
|
192
|
+
}
|
|
193
|
+
summarizeOutcome(trace) {
|
|
194
|
+
const lastStep = trace.steps[trace.steps.length - 1];
|
|
195
|
+
const success = trace.metrics?.success ?? (lastStep ? this.isStepSuccessful(lastStep) : false);
|
|
196
|
+
const result = lastStep ? this.getStepResult(lastStep) : null;
|
|
197
|
+
return `${success ? 'Success' : 'Failure'}: ${result?.substring(0, 100) || 'No result'}`;
|
|
198
|
+
}
|
|
199
|
+
compareTaces(original, fork) {
|
|
200
|
+
const originalSuccess = original.metrics?.success ?? true;
|
|
201
|
+
const forkSuccess = fork.metrics?.success ?? true;
|
|
202
|
+
if (originalSuccess !== forkSuccess) {
|
|
203
|
+
return `Outcome changed from ${originalSuccess ? 'success' : 'failure'} to ${forkSuccess ? 'success' : 'failure'}`;
|
|
204
|
+
}
|
|
205
|
+
const originalSteps = original.steps.length;
|
|
206
|
+
const forkSteps = fork.steps.length;
|
|
207
|
+
if (originalSteps !== forkSteps) {
|
|
208
|
+
return `Step count changed from ${originalSteps} to ${forkSteps}`;
|
|
209
|
+
}
|
|
210
|
+
let differences = 0;
|
|
211
|
+
for (let i = 0; i < Math.min(originalSteps, forkSteps); i++) {
|
|
212
|
+
if (this.describeStep(original.steps[i]) !== this.describeStep(fork.steps[i])) {
|
|
213
|
+
differences++;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (differences > 0) {
|
|
217
|
+
return `${differences} steps differed in actions`;
|
|
218
|
+
}
|
|
219
|
+
return 'No significant differences observed';
|
|
220
|
+
}
|
|
221
|
+
describeStep(step) {
|
|
222
|
+
if (step.toolCall) {
|
|
223
|
+
return `${step.toolCall.name}(${JSON.stringify(step.toolCall.arguments)})`;
|
|
224
|
+
}
|
|
225
|
+
return step.type;
|
|
226
|
+
}
|
|
227
|
+
getStepResult(step) {
|
|
228
|
+
if (step.toolResult) {
|
|
229
|
+
return String(step.toolResult.result);
|
|
230
|
+
}
|
|
231
|
+
return step.response || null;
|
|
232
|
+
}
|
|
233
|
+
isStepSuccessful(step) {
|
|
234
|
+
return !step.toolResult?.error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=causal-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"causal-validator.js","sourceRoot":"","sources":["../../../src/causal/discovery/causal-validator.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAwBjF,MAAM,OAAO,eAAe;IAClB,GAAG,CAAa;IAChB,KAAK,CAAS;IACd,mBAAmB,CAAS;IAC5B,qBAAqB,CAAS;IAEtC,YAAY,OAA+B;QACzC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC;QACtC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,GAAG,CAAC;QAC9D,IAAI,CAAC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,IAAI,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,UAA4B,EAC5B,OAA0B;QAQ1B,MAAM,eAAe,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAEnE,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACvD,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAA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AAC,IAAI,CAAC;IACnB,CAAC;IAEO,aAAa,CAAC,IAAmB;QACvC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC;IAC/B,CAAC;IAEO,gBAAgB,CAAC,IAAmB;QAC1C,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CausalHypothesis, CausalPattern, ExecutionTrace, LLMBackend } from '@cogitator-ai/types';
|
|
2
|
+
export interface HypothesisGeneratorOptions {
|
|
3
|
+
llmBackend: LLMBackend;
|
|
4
|
+
model?: string;
|
|
5
|
+
maxHypothesesPerBatch?: number;
|
|
6
|
+
minExpectedStrength?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class CausalHypothesisGenerator {
|
|
9
|
+
private llm;
|
|
10
|
+
private model;
|
|
11
|
+
private maxHypothesesPerBatch;
|
|
12
|
+
private minExpectedStrength;
|
|
13
|
+
private pendingHypotheses;
|
|
14
|
+
constructor(options: HypothesisGeneratorOptions);
|
|
15
|
+
generateHypotheses(patterns: CausalPattern[], traces: ExecutionTrace[], context: {
|
|
16
|
+
agentId: string;
|
|
17
|
+
goal?: string;
|
|
18
|
+
}): Promise<CausalHypothesis[]>;
|
|
19
|
+
generateFromFailure(trace: ExecutionTrace, context: {
|
|
20
|
+
agentId: string;
|
|
21
|
+
errorMessage?: string;
|
|
22
|
+
}): Promise<CausalHypothesis[]>;
|
|
23
|
+
generateFromSuccess(trace: ExecutionTrace, context: {
|
|
24
|
+
agentId: string;
|
|
25
|
+
outcome: string;
|
|
26
|
+
}): Promise<CausalHypothesis[]>;
|
|
27
|
+
getNextHypothesisToTest(agentId: string): CausalHypothesis | null;
|
|
28
|
+
markHypothesisValidated(hypothesisId: string, adjustedStrength: number, adjustedConfidence: number): void;
|
|
29
|
+
markHypothesisRejected(hypothesisId: string, reason: string): void;
|
|
30
|
+
getPendingHypotheses(agentId: string): CausalHypothesis[];
|
|
31
|
+
getValidatedHypotheses(agentId: string): CausalHypothesis[];
|
|
32
|
+
clearHypotheses(agentId: string): void;
|
|
33
|
+
private createHypothesis;
|
|
34
|
+
private mapRelationType;
|
|
35
|
+
private summarizeTrace;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=hypothesis-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypothesis-generator.d.ts","sourceRoot":"","sources":["../../../src/causal/discovery/hypothesis-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EAEb,cAAc,EACd,UAAU,EACX,MAAM,qBAAqB,CAAC;AAO7B,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAID,qBAAa,yBAAyB;IACpC,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,iBAAiB,CAAyC;gBAEtD,OAAO,EAAE,0BAA0B;IAOzC,kBAAkB,CACtB,QAAQ,EAAE,aAAa,EAAE,EACzB,MAAM,EAAE,cAAc,EAAE,EACxB,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAC1C,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAsCxB,mBAAmB,CACvB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAClD,OAAO,CAAC,gBAAgB,EAAE,CAAC;IA2DxB,mBAAmB,CACvB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAiD9B,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAoBjE,uBAAuB,CACrB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,EAAE,MAAM,GACzB,IAAI;IAaP,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAiBlE,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAIzD,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAI3D,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAItC,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,cAAc;CAQvB"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { buildHypothesisGenerationPrompt, parseHypothesisResponse, } from './prompts';
|
|
2
|
+
let hypothesisIdCounter = 0;
|
|
3
|
+
export class CausalHypothesisGenerator {
|
|
4
|
+
llm;
|
|
5
|
+
model;
|
|
6
|
+
maxHypothesesPerBatch;
|
|
7
|
+
minExpectedStrength;
|
|
8
|
+
pendingHypotheses = new Map();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.llm = options.llmBackend;
|
|
11
|
+
this.model = options.model ?? 'gpt-4';
|
|
12
|
+
this.maxHypothesesPerBatch = options.maxHypothesesPerBatch ?? 5;
|
|
13
|
+
this.minExpectedStrength = options.minExpectedStrength ?? 0.3;
|
|
14
|
+
}
|
|
15
|
+
async generateHypotheses(patterns, traces, context) {
|
|
16
|
+
const patternSummaries = patterns.map((p) => ({
|
|
17
|
+
trigger: p.pattern.trigger,
|
|
18
|
+
effect: p.pattern.effect,
|
|
19
|
+
occurrences: p.occurrences,
|
|
20
|
+
}));
|
|
21
|
+
const traceSummaries = traces.slice(-10).map((t) => ({
|
|
22
|
+
id: t.id,
|
|
23
|
+
summary: this.summarizeTrace(t),
|
|
24
|
+
success: t.metrics?.success ?? true,
|
|
25
|
+
}));
|
|
26
|
+
const prompt = buildHypothesisGenerationPrompt(patternSummaries, traceSummaries, context);
|
|
27
|
+
const response = await this.llm.chat({
|
|
28
|
+
model: this.model,
|
|
29
|
+
messages: [{ role: 'user', content: prompt }],
|
|
30
|
+
temperature: 0.5,
|
|
31
|
+
});
|
|
32
|
+
const parsed = parseHypothesisResponse(response.content);
|
|
33
|
+
if (!parsed) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const hypotheses = parsed.hypotheses
|
|
37
|
+
.filter((h) => h.expectedStrength >= this.minExpectedStrength)
|
|
38
|
+
.slice(0, this.maxHypothesesPerBatch)
|
|
39
|
+
.map((h) => this.createHypothesis(h, context.agentId));
|
|
40
|
+
const existing = this.pendingHypotheses.get(context.agentId) || [];
|
|
41
|
+
this.pendingHypotheses.set(context.agentId, [...existing, ...hypotheses]);
|
|
42
|
+
return hypotheses;
|
|
43
|
+
}
|
|
44
|
+
async generateFromFailure(trace, context) {
|
|
45
|
+
const failedSteps = trace.steps.filter((s) => s.toolResult?.error);
|
|
46
|
+
if (failedSteps.length === 0) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const describeStep = (s) => s.toolCall ? `${s.toolCall.name}(${JSON.stringify(s.toolCall.arguments)})` : s.type;
|
|
50
|
+
const prompt = `Analyze this failed execution and generate causal hypotheses about what caused the failure.
|
|
51
|
+
|
|
52
|
+
Failed steps:
|
|
53
|
+
${failedSteps.map((s) => `- ${describeStep(s)}: ${s.toolResult?.error || 'Unknown error'}`).join('\n')}
|
|
54
|
+
|
|
55
|
+
Error: ${context.errorMessage || 'Unknown'}
|
|
56
|
+
|
|
57
|
+
Recent successful steps before failure:
|
|
58
|
+
${trace.steps
|
|
59
|
+
.filter((s) => !s.toolResult?.error)
|
|
60
|
+
.slice(-5)
|
|
61
|
+
.map((s) => `- ${describeStep(s)}`)
|
|
62
|
+
.join('\n')}
|
|
63
|
+
|
|
64
|
+
Generate hypotheses about:
|
|
65
|
+
1. What actions or conditions caused the failure
|
|
66
|
+
2. What confounders might have influenced the outcome
|
|
67
|
+
3. What preventive measures could avoid this failure
|
|
68
|
+
|
|
69
|
+
Respond in JSON format:
|
|
70
|
+
{
|
|
71
|
+
"hypotheses": [
|
|
72
|
+
{
|
|
73
|
+
"cause": "cause_variable",
|
|
74
|
+
"effect": "failure_effect",
|
|
75
|
+
"relationType": "causes|enables|prevents",
|
|
76
|
+
"expectedStrength": 0.8,
|
|
77
|
+
"rationale": "Why this caused the failure",
|
|
78
|
+
"testable": true,
|
|
79
|
+
"testStrategy": "How to test this hypothesis"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}`;
|
|
83
|
+
const response = await this.llm.chat({
|
|
84
|
+
model: this.model,
|
|
85
|
+
messages: [{ role: 'user', content: prompt }],
|
|
86
|
+
temperature: 0.4,
|
|
87
|
+
});
|
|
88
|
+
const parsed = parseHypothesisResponse(response.content);
|
|
89
|
+
if (!parsed) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
return parsed.hypotheses.map((h) => this.createHypothesis(h, context.agentId));
|
|
93
|
+
}
|
|
94
|
+
async generateFromSuccess(trace, context) {
|
|
95
|
+
const describeStep = (s) => s.toolCall ? `${s.toolCall.name}(${JSON.stringify(s.toolCall.arguments)})` : s.type;
|
|
96
|
+
const prompt = `Analyze this successful execution and generate causal hypotheses about what led to success.
|
|
97
|
+
|
|
98
|
+
Outcome: ${context.outcome}
|
|
99
|
+
|
|
100
|
+
Key steps:
|
|
101
|
+
${trace.steps
|
|
102
|
+
.slice(-10)
|
|
103
|
+
.map((s) => `- [${!s.toolResult?.error ? 'OK' : 'FAIL'}] ${describeStep(s)}`)
|
|
104
|
+
.join('\n')}
|
|
105
|
+
|
|
106
|
+
Generate hypotheses about:
|
|
107
|
+
1. What actions were critical for success
|
|
108
|
+
2. What enabling conditions made success possible
|
|
109
|
+
3. What patterns could be reused in future tasks
|
|
110
|
+
|
|
111
|
+
Respond in JSON format:
|
|
112
|
+
{
|
|
113
|
+
"hypotheses": [
|
|
114
|
+
{
|
|
115
|
+
"cause": "successful_action",
|
|
116
|
+
"effect": "positive_outcome",
|
|
117
|
+
"relationType": "causes|enables",
|
|
118
|
+
"expectedStrength": 0.7,
|
|
119
|
+
"rationale": "Why this contributed to success",
|
|
120
|
+
"testable": true,
|
|
121
|
+
"testStrategy": "How to verify this pattern"
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}`;
|
|
125
|
+
const response = await this.llm.chat({
|
|
126
|
+
model: this.model,
|
|
127
|
+
messages: [{ role: 'user', content: prompt }],
|
|
128
|
+
temperature: 0.4,
|
|
129
|
+
});
|
|
130
|
+
const parsed = parseHypothesisResponse(response.content);
|
|
131
|
+
if (!parsed) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
return parsed.hypotheses.map((h) => this.createHypothesis(h, context.agentId));
|
|
135
|
+
}
|
|
136
|
+
getNextHypothesisToTest(agentId) {
|
|
137
|
+
const hypotheses = this.pendingHypotheses.get(agentId) || [];
|
|
138
|
+
const pending = hypotheses.filter((h) => h.status === 'pending');
|
|
139
|
+
if (pending.length === 0) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
pending.sort((a, b) => {
|
|
143
|
+
const scoreA = a.strength * a.confidence;
|
|
144
|
+
const scoreB = b.strength * b.confidence;
|
|
145
|
+
return scoreB - scoreA;
|
|
146
|
+
});
|
|
147
|
+
const selected = pending[0];
|
|
148
|
+
selected.status = 'testing';
|
|
149
|
+
return selected;
|
|
150
|
+
}
|
|
151
|
+
markHypothesisValidated(hypothesisId, adjustedStrength, adjustedConfidence) {
|
|
152
|
+
for (const [, hypotheses] of this.pendingHypotheses) {
|
|
153
|
+
const hypothesis = hypotheses.find((h) => h.id === hypothesisId);
|
|
154
|
+
if (hypothesis) {
|
|
155
|
+
hypothesis.status = 'validated';
|
|
156
|
+
hypothesis.strength = adjustedStrength;
|
|
157
|
+
hypothesis.confidence = adjustedConfidence;
|
|
158
|
+
hypothesis.testedAt = Date.now();
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
markHypothesisRejected(hypothesisId, reason) {
|
|
164
|
+
for (const [, hypotheses] of this.pendingHypotheses) {
|
|
165
|
+
const hypothesis = hypotheses.find((h) => h.id === hypothesisId);
|
|
166
|
+
if (hypothesis) {
|
|
167
|
+
hypothesis.status = 'rejected';
|
|
168
|
+
hypothesis.testedAt = Date.now();
|
|
169
|
+
hypothesis.evidence.push({
|
|
170
|
+
type: 'counterfactual',
|
|
171
|
+
description: `Rejected: ${reason}`,
|
|
172
|
+
strength: 0,
|
|
173
|
+
timestamp: Date.now(),
|
|
174
|
+
});
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
getPendingHypotheses(agentId) {
|
|
180
|
+
return (this.pendingHypotheses.get(agentId) || []).filter((h) => h.status === 'pending');
|
|
181
|
+
}
|
|
182
|
+
getValidatedHypotheses(agentId) {
|
|
183
|
+
return (this.pendingHypotheses.get(agentId) || []).filter((h) => h.status === 'validated');
|
|
184
|
+
}
|
|
185
|
+
clearHypotheses(agentId) {
|
|
186
|
+
this.pendingHypotheses.delete(agentId);
|
|
187
|
+
}
|
|
188
|
+
createHypothesis(generated, _agentId) {
|
|
189
|
+
return {
|
|
190
|
+
id: `hypothesis-${++hypothesisIdCounter}-${Date.now()}`,
|
|
191
|
+
cause: generated.cause,
|
|
192
|
+
effect: generated.effect,
|
|
193
|
+
relationType: this.mapRelationType(generated.relationType),
|
|
194
|
+
strength: generated.expectedStrength,
|
|
195
|
+
confidence: 0.5,
|
|
196
|
+
source: 'extraction',
|
|
197
|
+
evidence: [
|
|
198
|
+
{
|
|
199
|
+
type: 'observational',
|
|
200
|
+
description: generated.rationale,
|
|
201
|
+
strength: generated.expectedStrength,
|
|
202
|
+
timestamp: Date.now(),
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
status: 'pending',
|
|
206
|
+
createdAt: Date.now(),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
mapRelationType(type) {
|
|
210
|
+
const mapping = {
|
|
211
|
+
causes: 'causes',
|
|
212
|
+
enables: 'enables',
|
|
213
|
+
prevents: 'prevents',
|
|
214
|
+
mediates: 'mediates',
|
|
215
|
+
confounds: 'confounds',
|
|
216
|
+
moderates: 'moderates',
|
|
217
|
+
};
|
|
218
|
+
return mapping[type.toLowerCase()] ?? 'causes';
|
|
219
|
+
}
|
|
220
|
+
summarizeTrace(trace) {
|
|
221
|
+
const stepCount = trace.steps.length;
|
|
222
|
+
const successCount = trace.steps.filter((s) => !s.toolResult?.error).length;
|
|
223
|
+
const lastStep = trace.steps[trace.steps.length - 1];
|
|
224
|
+
const lastAction = lastStep?.toolCall?.name || lastStep?.type || 'Unknown';
|
|
225
|
+
return `${stepCount} steps (${successCount} successful), last: ${lastAction}`;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=hypothesis-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypothesis-generator.js","sourceRoot":"","sources":["../../../src/causal/discovery/hypothesis-generator.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,GAExB,MAAM,WAAW,CAAC;AASnB,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B,MAAM,OAAO,yBAAyB;IAC5B,GAAG,CAAa;IAChB,KAAK,CAAS;IACd,q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