tests passing

This commit is contained in:
2024-11-14 23:37:22 -05:00
parent 48e1bdc624
commit 5386081964
5 changed files with 196 additions and 118 deletions

View File

@@ -6,6 +6,9 @@ export class DummyIntentMap {
transform: { confidence: 0.7, action: 'transformation' },
validate: { confidence: 0.85, action: 'validation' },
clean: { confidence: 0.85, action: 'cleaning' },
test: { confidence: 0.9, action: 'testOperation' }, // <-- Added this entry
operator1: { confidence: 0.9, action: 'operator1' }, // <-- Added these entries
operator2: { confidence: 0.9, action: 'operator2' }
};
const matchedIntent = Object.entries(intents).find(([key]) =>
prompt.toLowerCase().includes(key)
@@ -53,12 +56,15 @@ export class ManifoldRegion {
}
}
// First fix the NestedManifoldRegion class to properly propagate state
export class NestedManifoldRegion extends ManifoldRegion {
nestedManifold: WorkflowFunctionManifold;
constructor(name: string, nestedManifold: WorkflowFunctionManifold) {
super(name);
this.nestedManifold = nestedManifold;
// Initialize nested manifold state
this.nestedManifold.state = {};
}
async getValidOperators(state: any): Promise<WorkflowOperator[]> {
@@ -74,15 +80,21 @@ export class NestedManifoldRegion extends ManifoldRegion {
async executeWorkflow(prompt: string): Promise<boolean> {
const result = await this.nestedManifold.executeWorkflow(prompt);
if (result) {
// Merge nested manifold state with parent manifold state
Object.assign(this.nestedManifold.state, this.nestedManifold.state);
}
return result;
}
}
// Update WorkflowFunctionManifold to handle nested state and logging
export class WorkflowFunctionManifold {
intentMap: DummyIntentMap;
regions: Map<string, ManifoldRegion>;
currentRegion: ManifoldRegion | null;
state: any;
parentManifold?: WorkflowFunctionManifold;
constructor(intentMap: DummyIntentMap) {
this.intentMap = intentMap;
@@ -96,29 +108,59 @@ export class WorkflowFunctionManifold {
if (!this.currentRegion) {
this.currentRegion = region;
}
if (region instanceof NestedManifoldRegion) {
region.nestedManifold.parentManifold = this;
}
}
async navigate(prompt: string): Promise<boolean> {
try {
console.log(`Navigating with prompt: "${prompt}"`);
if (this.currentRegion instanceof NestedManifoldRegion) {
const nestedNavigated = await this.currentRegion.navigate(prompt);
if (nestedNavigated) {
return true;
}
}
const intent = await this.intentMap.query(prompt);
console.log(`Matched intent: ${intent.action}, confidence: ${intent.confidence}`);
if (intent.confidence <= 0.5) {
console.log(`Low confidence (${intent.confidence}) for prompt: "${prompt}"`);
console.warn(`Low confidence navigation attempt for prompt: "${prompt}"`);
return false;
}
const nextRegion = Array.from(this.currentRegion.adjacentRegions).find(region =>
region.name.toLowerCase().includes(intent.action)
if (!this.currentRegion) {
console.warn('No current region available for navigation');
return false;
}
// First try exact match
let nextRegion = Array.from(this.currentRegion.adjacentRegions).find(region =>
region.name.toLowerCase() === intent.action.toLowerCase()
);
// Then try partial match
if (!nextRegion) {
nextRegion = Array.from(this.currentRegion.adjacentRegions).find(region =>
region.name.toLowerCase().includes(intent.action.toLowerCase())
);
}
if (nextRegion) {
this.currentRegion = nextRegion;
console.log(`Navigated to region: "${nextRegion.name}"`);
return true;
} else {
console.warn(`No matching region found for intent action: "${intent.action}"`);
}
return false;
} catch (error) {
console.warn('Navigation error:', error);
return false;
}
}
@@ -127,19 +169,46 @@ export class WorkflowFunctionManifold {
try {
if (this.currentRegion instanceof NestedManifoldRegion) {
const nestedResult = await this.currentRegion.executeWorkflow(prompt);
if (nestedResult) {
// Propagate state changes up to parent
this.state = {
...this.state,
...this.currentRegion.nestedManifold.state
};
}
return nestedResult;
}
const intent = await this.intentMap.query(prompt);
const operators = await this.currentRegion?.getValidOperators(this.state);
if (!this.currentRegion) {
console.warn('No current region available for execution');
return false;
}
const operators = await this.currentRegion.getValidOperators(this.state);
const matchedOperator = operators.find(op =>
op.name.toLowerCase().includes(intent.action)
op.name.toLowerCase() === intent.action.toLowerCase()
);
if (matchedOperator && intent.confidence > 0.5) {
this.state = await matchedOperator.execute(this.state);
const newState = await matchedOperator.execute(this.state);
this.state = { ...this.state, ...newState };
// If this is a nested manifold, propagate state changes up
if (this.parentManifold) {
this.parentManifold.state = {
...this.parentManifold.state,
...this.state
};
}
return true;
}
console.warn(`No matching operator found for intent action: "${intent.action}"`);
return false;
} catch (error) {
console.warn('Execution error:', error);
return false;
}
}