Update README, licensing, and logger implementation
Removed redundant instructions in the README and added a more detailed example. Changed the project's license from MIT to AGPL-3.0-or-later for stronger copyleft and network service provisions. Adjusted logger export and declarations to follow clean coding practices. Upgraded build scripts and distribution settings in package.json for improved module handling and output integrity. Remove pnpm-lock.yaml.
This commit is contained in:
22
src/cli.ts
22
src/cli.ts
@@ -8,22 +8,29 @@ import {
|
||||
NestedManifoldRegion
|
||||
} from './index';
|
||||
import { WorkflowState } from './types';
|
||||
import log from './logger';
|
||||
|
||||
async function demonstrateNestedManifold(): Promise<void> {
|
||||
log.info("Starting demonstration of nested manifold.");
|
||||
|
||||
const nestedIntentService = new DummyIntentMap();
|
||||
const nestedManifold = new WorkflowFunctionManifold(nestedIntentService);
|
||||
|
||||
const validateOp = new WorkflowOperator('validation', async (state: WorkflowState) => {
|
||||
log.debug("Validating state.");
|
||||
return { ...state, validated: true };
|
||||
});
|
||||
|
||||
const cleanOp = new WorkflowOperator('cleaning', async (state: WorkflowState) => {
|
||||
log.debug("Cleaning state.");
|
||||
return { ...state, cleaned: true };
|
||||
});
|
||||
|
||||
const validateRegion = new ManifoldRegion('validation', [validateOp]);
|
||||
const cleanRegion = new ManifoldRegion('cleaning', [cleanOp]);
|
||||
|
||||
validateRegion.connectTo(cleanRegion);
|
||||
|
||||
nestedManifold.addRegion(validateRegion);
|
||||
nestedManifold.addRegion(cleanRegion);
|
||||
|
||||
@@ -31,10 +38,12 @@ async function demonstrateNestedManifold(): Promise<void> {
|
||||
const mainManifold = new WorkflowFunctionManifold(mainIntentService);
|
||||
|
||||
const analysisOp = new WorkflowOperator('analysis', async (state: WorkflowState) => {
|
||||
log.debug("Analyzing state.");
|
||||
return { ...state, analyzed: true };
|
||||
});
|
||||
|
||||
const transformOp = new WorkflowOperator('transformation', async (state: WorkflowState) => {
|
||||
log.debug("Transforming state.");
|
||||
return { ...state, transformed: true };
|
||||
});
|
||||
|
||||
@@ -55,18 +64,25 @@ async function demonstrateNestedManifold(): Promise<void> {
|
||||
{ text: 'analyze the results', description: 'Main: Data Analysis' },
|
||||
{ text: 'transform the output', description: 'Main: Data Transformation' },
|
||||
];
|
||||
|
||||
const errorSink = [];
|
||||
|
||||
for (const { text } of prompts) {
|
||||
try {
|
||||
log.info(`Navigating with prompt: ${text}`);
|
||||
await mainManifold.navigate(text);
|
||||
log.info(`Executing workflow with prompt: ${text}`);
|
||||
await mainManifold.executeWorkflow(text);
|
||||
} catch (error) {
|
||||
log.error(`Error during workflow execution: ${error}`);
|
||||
errorSink.push(error);
|
||||
// Handle errors silently in demo
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Nested manifold demonstration completed.");
|
||||
}
|
||||
|
||||
demonstrateNestedManifold().catch(() => {
|
||||
demonstrateNestedManifold().catch((error) => {
|
||||
log.error(`Unhandled error: ${error}`);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
|
22
src/index.ts
22
src/index.ts
@@ -1,6 +1,6 @@
|
||||
import { log } from './logger';
|
||||
import "./types";
|
||||
import { IntentResult, WorkflowState } from './types';
|
||||
import log from './logger';
|
||||
import { WorkflowState, IntentResult } from './types';
|
||||
|
||||
export class DummyIntentMap {
|
||||
async query(prompt: string): Promise<IntentResult> {
|
||||
log.debug(`Processing intent query for prompt: ${prompt}`);
|
||||
@@ -98,7 +98,7 @@ export class NestedManifoldRegion extends ManifoldRegion {
|
||||
log.debug(`Executing nested workflow in ${this.name} with prompt: ${prompt}`);
|
||||
const result = await this.nestedManifold.executeWorkflow(prompt);
|
||||
if (result) {
|
||||
log.debug(`Nested workflow execution successful, updating state`);
|
||||
log.debug(`Nested workflow execution successful, updating state.`);
|
||||
Object.assign(this.nestedManifold.state, this.nestedManifold.state);
|
||||
}
|
||||
return result;
|
||||
@@ -136,7 +136,6 @@ export class WorkflowFunctionManifold {
|
||||
async navigate(prompt: string): Promise<boolean> {
|
||||
try {
|
||||
log.debug(`Attempting navigation with prompt: ${prompt}`);
|
||||
|
||||
if (this.currentRegion instanceof NestedManifoldRegion) {
|
||||
log.debug('Current region is nested, attempting nested navigation');
|
||||
const nestedNavigated = await this.currentRegion.navigate(prompt);
|
||||
@@ -145,34 +144,28 @@ export class WorkflowFunctionManifold {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const intent = await this.intentMap.query(prompt);
|
||||
if (intent.confidence <= 0.5) {
|
||||
log.warn(`Low confidence intent match: ${intent.confidence}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.currentRegion) {
|
||||
log.error('No current region set');
|
||||
return false;
|
||||
}
|
||||
|
||||
let nextRegion = Array.from(this.currentRegion.adjacentRegions).find(region =>
|
||||
region.name.toLowerCase() === intent.action.toLowerCase()
|
||||
);
|
||||
|
||||
if (!nextRegion) {
|
||||
nextRegion = Array.from(this.currentRegion.adjacentRegions).find(region =>
|
||||
region.name.toLowerCase().includes(intent.action.toLowerCase())
|
||||
);
|
||||
}
|
||||
|
||||
if (nextRegion) {
|
||||
log.info(`Navigating from ${this.currentRegion.name} to ${nextRegion.name}`);
|
||||
this.currentRegion = nextRegion;
|
||||
return true;
|
||||
}
|
||||
|
||||
log.warn(`No valid navigation target found for prompt: ${prompt}`);
|
||||
return false;
|
||||
} catch (error) {
|
||||
@@ -184,7 +177,6 @@ export class WorkflowFunctionManifold {
|
||||
async executeWorkflow(prompt: string): Promise<boolean> {
|
||||
try {
|
||||
log.debug(`Executing workflow with prompt: ${prompt}`);
|
||||
|
||||
if (this.currentRegion instanceof NestedManifoldRegion) {
|
||||
log.debug('Executing nested workflow');
|
||||
const nestedResult = await this.currentRegion.executeWorkflow(prompt);
|
||||
@@ -197,18 +189,15 @@ export class WorkflowFunctionManifold {
|
||||
}
|
||||
return nestedResult;
|
||||
}
|
||||
|
||||
const intent = await this.intentMap.query(prompt);
|
||||
if (!this.currentRegion) {
|
||||
log.error('No current region set for workflow execution');
|
||||
return false;
|
||||
}
|
||||
|
||||
const operators = await this.currentRegion.getValidOperators(this.state);
|
||||
const matchedOperator = operators.find(op =>
|
||||
op.name.toLowerCase() === intent.action.toLowerCase()
|
||||
);
|
||||
|
||||
if (matchedOperator && intent.confidence > 0.5) {
|
||||
log.info(`Executing operator ${matchedOperator.name}`);
|
||||
const newState = await matchedOperator.execute(this.state);
|
||||
@@ -222,7 +211,6 @@ export class WorkflowFunctionManifold {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
log.warn(`No matching operator found for prompt: ${prompt}`);
|
||||
return false;
|
||||
} catch (error) {
|
||||
@@ -230,4 +218,4 @@ export class WorkflowFunctionManifold {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
// src/logger.ts
|
||||
import { Logger, ILogObj } from "tslog";
|
||||
|
||||
export const log: Logger<ILogObj> = new Logger({
|
||||
const log: Logger<ILogObj> = new Logger({
|
||||
name: "workflow-function-manifold",
|
||||
prettyLogTemplate: "{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}} {{logLevelName}} [{{name}}] ",
|
||||
prettyLogTimeZone: "local"
|
||||
});
|
||||
|
||||
export default log;
|
||||
export default log;
|
||||
|
Reference in New Issue
Block a user