@gotza02/mathinking 1.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.
@@ -0,0 +1,158 @@
1
+ import { thinkingManager } from './tools/sequential-thinking.js';
2
+ import { orchestratorManager } from './tools/orchestrator.js';
3
+ async function runTests() {
4
+ console.log('๐Ÿงช Starting System Tests...\n');
5
+ // ==========================================
6
+ // Test 1: Sequential Thinking (The Brain)
7
+ // ==========================================
8
+ console.log('๐Ÿง  Testing Sequential Thinking Manager...');
9
+ try {
10
+ // 1. Start Session
11
+ console.log(' 1. Starting Session...');
12
+ const startResult = await thinkingManager.process({
13
+ action: 'start_session',
14
+ problemStatement: 'How to test this system?',
15
+ totalThoughts: 3
16
+ });
17
+ if (!startResult.success || !startResult.sessionId)
18
+ throw new Error('Failed to start session');
19
+ const sessionId = startResult.sessionId;
20
+ console.log(' โœ… Session started:', sessionId);
21
+ // 2. Add Thought
22
+ console.log(' 2. Adding Thought...');
23
+ const thoughtResult = await thinkingManager.process({
24
+ action: 'add_thought',
25
+ sessionId,
26
+ thought: 'We should create a test script.',
27
+ thoughtType: 'initial_analysis'
28
+ });
29
+ if (!thoughtResult.success)
30
+ throw new Error('Failed to add thought');
31
+ console.log(' โœ… Thought added');
32
+ // 3. Set Hypothesis
33
+ console.log(' 3. Setting Hypothesis...');
34
+ const hypResult = await thinkingManager.process({
35
+ action: 'set_hypothesis',
36
+ sessionId,
37
+ hypothesis: 'The orchestrator works correctly.'
38
+ });
39
+ if (!hypResult.success)
40
+ throw new Error('Failed to set hypothesis');
41
+ console.log(' โœ… Hypothesis set');
42
+ // 4. Verify Hypothesis
43
+ console.log(' 4. Verifying Hypothesis...');
44
+ const verifyResult = await thinkingManager.process({
45
+ action: 'verify_hypothesis',
46
+ sessionId,
47
+ verificationStatus: 'verified',
48
+ verificationEvidence: 'Tests passed.'
49
+ });
50
+ if (!verifyResult.success)
51
+ throw new Error('Failed to verify hypothesis');
52
+ console.log(' โœ… Hypothesis verified');
53
+ // 5. Conclude
54
+ console.log(' 5. Concluding...');
55
+ const endResult = await thinkingManager.process({
56
+ action: 'conclude',
57
+ sessionId,
58
+ thought: 'The system is testable.'
59
+ });
60
+ if (!endResult.success)
61
+ throw new Error('Failed to conclude');
62
+ console.log(' โœ… Session concluded');
63
+ }
64
+ catch (error) {
65
+ console.error(' โŒ Thinking Test Failed:', error);
66
+ process.exit(1);
67
+ }
68
+ console.log('\n');
69
+ // ==========================================
70
+ // Test 2: Orchestrator (The Body)
71
+ // ==========================================
72
+ console.log('๐Ÿค– Testing Orchestrator Manager...');
73
+ try {
74
+ const plan = {
75
+ planId: 'test-plan-1',
76
+ name: 'Test Plan',
77
+ tasks: [
78
+ {
79
+ id: 'task1',
80
+ name: 'Generate Data',
81
+ toolName: 'echo',
82
+ toolInput: { message: 'hello world' },
83
+ dependencies: []
84
+ },
85
+ {
86
+ id: 'task2',
87
+ name: 'Process Data',
88
+ toolName: 'transform',
89
+ toolInput: {
90
+ data: '${task1.message}',
91
+ operation: 'uppercase'
92
+ },
93
+ dependencies: ['task1']
94
+ },
95
+ {
96
+ id: 'task3',
97
+ name: 'Wait',
98
+ toolName: 'delay',
99
+ toolInput: { milliseconds: 200 },
100
+ dependencies: []
101
+ },
102
+ {
103
+ id: 'task4',
104
+ name: 'Calculate',
105
+ toolName: 'compute',
106
+ toolInput: {
107
+ expression: 'length * 2',
108
+ variables: {
109
+ length: '${task2.result.length}'
110
+ }
111
+ },
112
+ dependencies: ['task2']
113
+ }
114
+ ]
115
+ };
116
+ console.log(' 1. Validating Plan...');
117
+ const valResult = await orchestratorManager.process({
118
+ action: 'validate_plan',
119
+ planId: 'test-plan-1',
120
+ plan
121
+ });
122
+ if (!valResult.success)
123
+ throw new Error(`Validation failed: ${valResult.message}`);
124
+ console.log(' โœ… Plan valid');
125
+ console.log(' 2. Executing Plan...');
126
+ const execResult = await orchestratorManager.process({
127
+ action: 'execute_plan',
128
+ planId: 'test-plan-1',
129
+ plan
130
+ });
131
+ if (!execResult.success)
132
+ throw new Error(`Execution failed: ${execResult.message}`);
133
+ // Verify results
134
+ const results = execResult.result?.aggregatedResults;
135
+ // Task 1: Echo
136
+ if (results.task1.message !== 'hello world')
137
+ throw new Error('Task 1 failed');
138
+ // Task 2: Uppercase
139
+ if (results.task2.result !== 'HELLO WORLD')
140
+ throw new Error('Task 2 failed');
141
+ // Task 3: Delay (just check existence)
142
+ if (!results.task3.delayed)
143
+ throw new Error('Task 3 failed');
144
+ // Task 4: Compute (Length of "HELLO WORLD" is 11, * 2 = 22)
145
+ if (results.task4.result !== 22)
146
+ throw new Error(`Task 4 failed. Expected 22, got ${results.task4.result}`);
147
+ console.log(' โœ… Execution successful');
148
+ console.log(' โœ… Dependencies resolved correctly');
149
+ console.log(' โœ… Parallel execution handled');
150
+ }
151
+ catch (error) {
152
+ console.error(' โŒ Orchestrator Test Failed:', error);
153
+ process.exit(1);
154
+ }
155
+ console.log('\n๐ŸŽ‰ ALL TESTS PASSED!');
156
+ }
157
+ runTests().catch(console.error);
158
+ //# sourceMappingURL=test-all.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-all.js","sourceRoot":"","sources":["../src/test-all.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,KAAK,UAAU,QAAQ;IACrB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAE7C,6CAA6C;IAC7C,0CAA0C;IAC1C,6CAA6C;IAC7C,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IAEzD,IAAI,CAAC;QACH,mBAAmB;QACnB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxC,MAAM,WAAW,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC;YAChD,MAAM,EAAE,eAAe;YACvB,gBAAgB,EAAE,0BAA0B;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AC9E,oBAAoB;QACpB,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,aAAa;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QAC7E,uCAAuC;QACvC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QAC7D,4DAA4D;QAC5D,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAE5G,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAEnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AACxC,CAAC;AAED,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { OrchestratorInput, OrchestratorOutput, ToolDefinition } from '../types/index.js';
2
+ /**
3
+ * Orchestrator Manager (The Body)
4
+ *
5
+ * Provides DAG-based task execution with:
6
+ * - Topological sorting for dependency resolution
7
+ * - Parallel execution of independent tasks
8
+ * - Tool orchestration via registry
9
+ * - Graceful error handling
10
+ * - Result aggregation
11
+ */
12
+ export declare class OrchestratorManager {
13
+ private toolRegistry;
14
+ private executionHistory;
15
+ constructor();
16
+ /**
17
+ * Register built-in tools for testing and common operations
18
+ */
19
+ private registerBuiltInTools;
20
+ /**
21
+ * Register a custom tool
22
+ */
23
+ registerTool(tool: ToolDefinition): void;
24
+ /**
25
+ * Get list of registered tools
26
+ */
27
+ getRegisteredTools(): string[];
28
+ /**
29
+ * Process an orchestrator action
30
+ */
31
+ process(input: OrchestratorInput): Promise<OrchestratorOutput>;
32
+ /**
33
+ * Validate an execution plan
34
+ */
35
+ private validatePlan;
36
+ /**
37
+ * Execute a plan with parallel processing
38
+ */
39
+ private executePlan;
40
+ /**
41
+ * Execute a single task with error handling and retries
42
+ */
43
+ private executeTask;
44
+ /**
45
+ * Resolve input placeholders with outputs from previous tasks
46
+ * Supports syntax: "${taskId.property}" or "${taskId}"
47
+ */
48
+ private resolveInput;
49
+ private resolveValue;
50
+ private resolvePlaceholder;
51
+ /**
52
+ * Execute a promise with timeout
53
+ */
54
+ private executeWithTimeout;
55
+ /**
56
+ * Get execution status for a plan
57
+ */
58
+ private getExecutionStatus;
59
+ /**
60
+ * Format execution summary for display
61
+ */
62
+ private formatExecutionSummary;
63
+ }
64
+ export declare const orchestratorManager: OrchestratorManager;
65
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/tools/orchestrator.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAMV,iBAAiB,EACjB,kBAAkB,EAElB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;GASG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,gBAAgB,CAA2C;;IAMnE;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAmH5B;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAIxC;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;OAEG;IACG,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgBpE;;OAEG;IACH,OAAO,CAAC,YAAY;IAsCpB;;OAEG;YACW,WAAW;IAmGzB;;OAEG;YACW,WAAW;IAsGzB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,kBAAkB;IA2B1B;;OAEG;YACW,kBAAkB;IAShC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAuB1B;;OAEG;IACH,OAAO,CAAC,sBAAsB;CA4B/B;AAGD,eAAO,MAAM,mBAAmB,qBAA4B,CAAC"}