@j-o-r/hello-dave 0.0.3 → 0.0.4
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/CHANGELOG.md +21 -0
- package/README.md +216 -56
- package/README.md.bak +481 -0
- package/README.md.bak.1774780058 +338 -0
- package/README.md.bak2 +455 -0
- package/docs.bak.1774780058/agent-manager.md +167 -0
- package/docs.bak.1774780058/agent-manager.md.bak +137 -0
- package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
- package/docs.bak.1774780058/codeserver-pattern.md +191 -0
- package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
- package/docs.bak.1774780058/project-overview.md +67 -0
- package/docs.bak.1774780058/project-overview.md.bak +67 -0
- package/docs.bak.1774780058/prompt-class.md +141 -0
- package/docs.bak.1774780058/prompt-class.md.bak +142 -0
- package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
- package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
- package/docs.bak.1774780058/toolset.md +164 -0
- package/docs.bak.1774780058/toolset.md.bak +94 -0
- package/docs.bak.1774780058/toolset.md.bak3 +161 -0
- package/docs.bak.1774780058/toolset.md.bak4 +161 -0
- package/docs.bak.1774780058/toolset.md.bak5 +161 -0
- package/docs.bak.1774780058/toolset.md.bak6 +163 -0
- package/docs.bak.1774780058/toolset.md.bak_path +163 -0
- package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
- package/docs.bak.1774780058/xai-responses.md +111 -0
- package/docs.bak.1774780058/xai-responses.md.bak +107 -0
- package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
- package/docs.bak.1774780058/xai_collections.md +106 -0
- package/examples/ask_agent.js +137 -0
- package/examples/code_agent.js +149 -0
- package/examples/coderev_agent.js +136 -0
- package/examples/codeserver.sh +47 -0
- package/examples/daisy_agent.js +170 -0
- package/examples/docs_agent.js +148 -0
- package/examples/gpt_agent.js +125 -0
- package/examples/grok_agent.js +132 -0
- package/examples/grok_agent.js.bak +98 -0
- package/examples/grok_agent.js.bak.2 +99 -0
- package/examples/grok_agent.js.bak.3 +1 -0
- package/examples/grok_agent.js.bak.4 +124 -0
- package/examples/grok_agent.js.bak.5 +1 -0
- package/examples/grok_agent.js.bak.6 +1 -0
- package/examples/memory_agent.js +152 -0
- package/examples/npm_agent.js +202 -0
- package/examples/npm_agent.js.bak.3 +2 -0
- package/examples/npm_agent.js.bak.4 +205 -0
- package/examples/npm_agent.js.bak.5 +1 -0
- package/examples/npm_agent.js.bak.6 +1 -0
- package/examples/prompt_agent.js +133 -0
- package/examples/readme_agent.js +148 -0
- package/examples/spawn_agent.js +293 -0
- package/examples/test_agent.js +187 -0
- package/examples/todo_agent.js +175 -0
- package/{examples/codeDave.js → examples.bak.1774780058/code_agent.js} +40 -6
- package/{examples/CodeServer → examples.bak.1774780058/codeserver.sh} +9 -5
- package/examples.bak.1774780058/memory_agent.js +112 -0
- package/{examples/spawndave.js → examples.bak.1774780058/spawn_agent.js} +29 -6
- package/examples.bak.1774780058/test_agent.js +162 -0
- package/{examples/todoDave.js → examples.bak.1774780058/todo_agent.js} +8 -2
- package/lib/API/x.ai/responses.js +7 -9
- package/lib/AgentManager.js +3 -2
- package/lib/AgentServer.js +23 -19
- package/lib/genericToolset.js +159 -26
- package/lib/genericToolset.js.bak_syntax +402 -0
- package/lib/wsCli.js +0 -1
- package/package.json +4 -5
- package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
- package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
- package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
- package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
- package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
- package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
- package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
- package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
- package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
- package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
- package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
- package/scenarios.bak.1774780058/environment.js +10 -0
- package/scenarios.bak.1774780058/example.js +17 -0
- package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
- package/scenarios.bak.1774780058/grok.js +113 -0
- package/scenarios.bak.1774780058/memory-tools.js +51 -0
- package/scenarios.bak.1774780058/openai-o3.js +137 -0
- package/scenarios.bak.1774780058/openai-prompt.js +155 -0
- package/scenarios.bak.1774780058/openai-session.js +148 -0
- package/scenarios.bak.1774780058/openai.js +102 -0
- package/scenarios.bak.1774780058/prompt.js +118 -0
- package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
- package/scenarios.bak.1774780058/search.brave.com.js +25 -0
- package/scenarios.bak.1774780058/sh.js +15 -0
- package/scenarios.bak.1774780058/test-wsio.js +26 -0
- package/scenarios.bak.1774780058/testToolset.js +42 -0
- package/scenarios.bak.1774780058/toolset.js +16 -0
- package/scenarios.bak.1774780058/toolset.test.js +141 -0
- package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
- package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
- package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
- package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
- package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
- package/scenarios.bak.1774780058/wsClient.js +69 -0
- package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
- package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
- package/scenarios.bak.1774780058/xaicoll.js +50 -0
- package/scenarios.bak.1774780058/xaifiles.js +48 -0
- package/types/AgentManager.d.ts +4 -3
- package/utils/syntax_check.sh +61 -0
- package/utils/test.sh +46 -0
- /package/{examples/askDave.js → examples.bak.1774780058/ask_agent.js} +0 -0
- /package/{examples/coderev.js → examples.bak.1774780058/coderev_agent.js} +0 -0
- /package/{examples/daisy.js → examples.bak.1774780058/daisy_agent.js} +0 -0
- /package/{examples/docsDave.js → examples.bak.1774780058/docs_agent.js} +0 -0
- /package/{examples/gpt.js → examples.bak.1774780058/gpt_agent.js} +0 -0
- /package/{examples/grok.js → examples.bak.1774780058/grok_agent.js} +0 -0
- /package/{examples/npmDave.js → examples.bak.1774780058/npm_agent.js} +0 -0
- /package/{examples/promptDave.js → examples.bak.1774780058/prompt_agent.js} +0 -0
- /package/{examples/readmeDave.js → examples.bak.1774780058/readme_agent.js} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Test , assert} from '@j-o-r/sh';
|
|
3
|
+
import {env} from '../lib/fafs.js';
|
|
4
|
+
const test = new Test();
|
|
5
|
+
test.add('Test enviroment caching', async () => {
|
|
6
|
+
const user = await env();
|
|
7
|
+
console.log(user);
|
|
8
|
+
assert.strictEqual(typeof user, 'object');
|
|
9
|
+
});
|
|
10
|
+
await test.run();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
/**
|
|
4
|
+
* Create a async callstack
|
|
5
|
+
* @param {function} callback - async function
|
|
6
|
+
*/
|
|
7
|
+
const test = (callback) => {
|
|
8
|
+
(async () => {
|
|
9
|
+
return await callback()
|
|
10
|
+
})()
|
|
11
|
+
}
|
|
12
|
+
test(async () => {
|
|
13
|
+
assert.equal(true, true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Test, assert, jsType } from '@j-o-r/sh';
|
|
3
|
+
import tools from '../lib/genericToolset.js'; // Import the ToolSet instance to test
|
|
4
|
+
|
|
5
|
+
const t = new Test();
|
|
6
|
+
|
|
7
|
+
// Test 1: get_user_env - Should return a string with environment details
|
|
8
|
+
t.add('get_user_env returns environment info', async () => {
|
|
9
|
+
const result = await tools.call('get_user_env', {});
|
|
10
|
+
assert.ok(typeof result === 'string' && result.includes('Name:') && result.includes('System:'));
|
|
11
|
+
console.log('Environment snippet:', result.slice(0, 100));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Test 2: javascript_interpreter - Execute a simple JS script
|
|
15
|
+
t.add('javascript_interpreter executes basic math', async () => {
|
|
16
|
+
const script = "console.log(2 + 2);";
|
|
17
|
+
const result = await tools.call('javascript_interpreter', { script });
|
|
18
|
+
assert.ok(result.includes('4'));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Test 3: execute_bash_script - Run pwd (flexible path check)
|
|
22
|
+
t.add('execute_bash_script runs pwd', async () => {
|
|
23
|
+
const bash_script = 'pwd';
|
|
24
|
+
const result = await tools.call('execute_bash_script', { bash_script });
|
|
25
|
+
assert.ok(result && result.includes('hello-dave'));
|
|
26
|
+
console.log('Current dir:', result.trim());
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Test 4: history_search - Empty query lists sessions (no error)
|
|
30
|
+
t.add('history_search empty query lists sessions', async () => {
|
|
31
|
+
const result = await tools.call('history_search', { query: '' });
|
|
32
|
+
assert.ok(typeof result === 'string' && result.length > 10); // Expect non-trivial output from list_sessions.sh
|
|
33
|
+
console.log('History search snippet:', result.slice(0, 200));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Test 5: ToolSet basics - Verify key tools exist (flexible, subset + min count)
|
|
37
|
+
t.add('ToolSet has expected tools', () => {
|
|
38
|
+
const toolList = tools.list();
|
|
39
|
+
const expectedTools = [
|
|
40
|
+
'execute_bash_script', 'execute_remote_script', 'get_user_env', 'history_search',
|
|
41
|
+
'javascript_interpreter', 'memory_recall', 'memory_write', 'open_link',
|
|
42
|
+
'read_file', 'send_email', 'syntax_check', 'write_file'
|
|
43
|
+
];
|
|
44
|
+
const actualNames = toolList.map(t => t.name).sort();
|
|
45
|
+
assert.ok(toolList.length >= 12, `Expected at least 12 tools, got ${toolList.length}`);
|
|
46
|
+
assert.ok(expectedTools.every(name => actualNames.includes(name)),
|
|
47
|
+
`Missing tools. Expected: ${expectedTools.join(', ')}. Got: ${actualNames.join(', ')}`);
|
|
48
|
+
console.log(`Tool count: ${toolList.length}, names: ${actualNames.slice(0,5).join(', ')}...`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Test 6: javascript_interpreter - Complex JS with backticks (template literal)
|
|
52
|
+
t.add('javascript_interpreter handles backticks/templates', async () => {
|
|
53
|
+
const script = `
|
|
54
|
+
const name = 'Dave';
|
|
55
|
+
const greeting = \`Hello \${name}!\`;
|
|
56
|
+
console.log(greeting);
|
|
57
|
+
console.log(\`2 + 2 = \${2 + 2}\`);
|
|
58
|
+
`.trim();
|
|
59
|
+
const result = await tools.call('javascript_interpreter', { script });
|
|
60
|
+
assert.ok(result.includes('Hello Dave!') && result.includes('2 + 2 = 4'));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Test 7: javascript_interpreter - Arrow functions & async/await
|
|
64
|
+
t.add('javascript_interpreter handles ESNext features', async () => {
|
|
65
|
+
const script = `
|
|
66
|
+
const add = async (a, b) => a + b;
|
|
67
|
+
console.log(await add(3, 4));
|
|
68
|
+
`.trim();
|
|
69
|
+
const result = await tools.call('javascript_interpreter', { script });
|
|
70
|
+
assert.ok(result.includes('7'));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Test 8: javascript_interpreter - Error handling
|
|
74
|
+
t.add('javascript_interpreter reports JS errors', async () => {
|
|
75
|
+
const script = 'console.log("ok"); invalidSyntaxHere();';
|
|
76
|
+
const result = await tools.call('javascript_interpreter', { script });
|
|
77
|
+
assert.ok(result.includes('invalidSyntaxHere') || result.includes('ReferenceError'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Test 9: read_file - Read package.json
|
|
81
|
+
t.add('read_file reads package.json', async () => {
|
|
82
|
+
const result = await tools.call('read_file', { file: 'package.json' });
|
|
83
|
+
assert.ok(result.includes('@j-o-r/hello-dave') && result.includes('"tests":'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Test 10: write_file + read_file roundtrip (temp file, cleanup)
|
|
87
|
+
t.add('write_file + read_file roundtrip', async () => {
|
|
88
|
+
const tempFile = 'scenarios/temp.test.txt';
|
|
89
|
+
const testContent = 'Test content: ' + Date.now();
|
|
90
|
+
|
|
91
|
+
// Write
|
|
92
|
+
const writeRes = await tools.call('write_file', {
|
|
93
|
+
file: tempFile,
|
|
94
|
+
content: testContent
|
|
95
|
+
});
|
|
96
|
+
assert.ok(writeRes.includes('Successfully wrote'));
|
|
97
|
+
|
|
98
|
+
// Read back
|
|
99
|
+
const readRes = await tools.call('read_file', { file: tempFile });
|
|
100
|
+
assert.strictEqual(readRes.trim(), testContent);
|
|
101
|
+
|
|
102
|
+
// Cleanup
|
|
103
|
+
await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` });
|
|
104
|
+
console.log('Temp file roundtrip OK');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Test 11: memory_write + memory_recall
|
|
108
|
+
t.add('memory_write and recall', async () => {
|
|
109
|
+
const cat = 'tasks';
|
|
110
|
+
const content = 'Test task from genericToolset.test.js';
|
|
111
|
+
|
|
112
|
+
// Write
|
|
113
|
+
await tools.call('memory_write', { category: cat, content });
|
|
114
|
+
|
|
115
|
+
// Recall
|
|
116
|
+
const recall = await tools.call('memory_recall', { query: cat });
|
|
117
|
+
assert.ok(recall.includes(cat) && recall.includes('Test task'));
|
|
118
|
+
|
|
119
|
+
console.log('Memory test OK');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Test 12: write_file rejects invalid JS syntax (unclosed string)
|
|
123
|
+
t.add('write_file rejects invalid JS syntax', async () => {
|
|
124
|
+
const ts = Date.now().toString();
|
|
125
|
+
const tempFile = `scenarios/temp_invalid_${ts}.js`;
|
|
126
|
+
const invalidJS = `console.log("unclosed quote`;
|
|
127
|
+
await assert.rejects(
|
|
128
|
+
() => tools.call('write_file', { file: tempFile, content: invalidJS }),
|
|
129
|
+
(err) => {
|
|
130
|
+
assert.strictEqual(jsType(err), 'Error');
|
|
131
|
+
assert.ok(err.message.includes('❌ SYNTAX ERROR'));
|
|
132
|
+
assert.ok(err.message.includes('syntax error') || err.message.includes('SyntaxError'));
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
// Cleanup if exists (write happens before check)
|
|
137
|
+
await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` }).catch(() => {});
|
|
138
|
+
console.log('Invalid JS rejection OK');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Test 13: write_file rejects invalid Python syntax (unclosed string)
|
|
142
|
+
t.add('write_file rejects invalid Python syntax', async () => {
|
|
143
|
+
const ts = Date.now().toString();
|
|
144
|
+
const tempFile = `scenarios/temp_invalid_${ts}.py`;
|
|
145
|
+
const invalidPy = `print("unclosed quote`;
|
|
146
|
+
await assert.rejects(
|
|
147
|
+
() => tools.call('write_file', { file: tempFile, content: invalidPy }),
|
|
148
|
+
(err) => {
|
|
149
|
+
assert.strictEqual(jsType(err), 'Error');
|
|
150
|
+
assert.ok(err.message.includes('❌ SYNTAX ERROR'));
|
|
151
|
+
assert.ok(err.message.includes('syntax error') || err.message.includes('SyntaxError'));
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
// Cleanup
|
|
156
|
+
await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` }).catch(() => {});
|
|
157
|
+
console.log('Invalid Python rejection OK');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Test 14: write_file rejects invalid Bash syntax (unclosed string)
|
|
161
|
+
t.add('write_file rejects invalid Bash syntax', async () => {
|
|
162
|
+
const ts = Date.now().toString();
|
|
163
|
+
const tempFile = `scenarios/temp_invalid_${ts}.sh`;
|
|
164
|
+
const invalidBash = `echo "unclosed quote`;
|
|
165
|
+
await assert.rejects(
|
|
166
|
+
() => tools.call('write_file', { file: tempFile, content: invalidBash }),
|
|
167
|
+
(err) => {
|
|
168
|
+
assert.strictEqual(jsType(err), 'Error');
|
|
169
|
+
assert.ok(err.message.includes('❌ SYNTAX ERROR'));
|
|
170
|
+
assert.ok(err.message.includes('syntax error') || err.message.includes('SyntaxError') || err.message.includes('unexpected EOF'));
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
// Cleanup
|
|
175
|
+
await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` }).catch(() => {});
|
|
176
|
+
console.log('Invalid Bash rejection OK');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Run tests
|
|
180
|
+
const report = await t.run();
|
|
181
|
+
console.log('\n=== Final Report ===', report);
|
|
182
|
+
process.exit(report.errors > 0 ? 1 : 0);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Test, assert, SH } from '@j-o-r/sh'
|
|
3
|
+
import { generateRequest, parseResponse, request } from '../lib/API/x.ai/text.js';
|
|
4
|
+
import { request as doRequest } from '@j-o-r/apiserver';
|
|
5
|
+
|
|
6
|
+
import Prompt from '../lib/Prompt.js';
|
|
7
|
+
import tools from './testToolset.js';
|
|
8
|
+
|
|
9
|
+
function LOG (me) {
|
|
10
|
+
console.log(JSON.stringify(me, null, ' '));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const test = new Test();
|
|
14
|
+
// test.add('0: parse response, create request FAKE ', async () => {
|
|
15
|
+
// // Load a fake reponse
|
|
16
|
+
// const resLocal = JSON.parse((await SH`cat scenarios/data/tool_xai.json`.run()));
|
|
17
|
+
// const prompt = new Prompt();
|
|
18
|
+
// prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
19
|
+
// prompt.add('user', 'What is your task?');
|
|
20
|
+
// prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
|
|
21
|
+
// prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
22
|
+
// // // const { url, headers, body } = generateRequest(prompt, tools);
|
|
23
|
+
// // await parseResponse(1100, prompt, resLocal, tools);
|
|
24
|
+
// // let lastMessage = prompt.getLastMessage();
|
|
25
|
+
// // assert.strictEqual(lastMessage.role, 'tool', 'Last message has role tool');
|
|
26
|
+
// // assert.strictEqual(lastMessage.content.length, 2, '2 toolcalls')
|
|
27
|
+
// // const { url, headers, body } = generateRequest(prompt, tools);
|
|
28
|
+
// // assert.equal(body.messages.length, 6);
|
|
29
|
+
//
|
|
30
|
+
// const res2 = JSON.parse((await SH`cat scenarios/data/tool_xai2.json`.run()));
|
|
31
|
+
// // const res2 = await doRequest(url, 'POST', headers, body);
|
|
32
|
+
// await parseResponse(1000, prompt, res2, tools);
|
|
33
|
+
// // console.log(JSON.stringify(res2, null, ' '));
|
|
34
|
+
// console.log(JSON.stringify(prompt.messages, null, ' '));
|
|
35
|
+
// // console.log({retrigger, lastMessage})
|
|
36
|
+
// });
|
|
37
|
+
//
|
|
38
|
+
// // @TODO add tools
|
|
39
|
+
// test.add('1: Full tool call with reasoning', async () => {
|
|
40
|
+
// const prompt = new Prompt();
|
|
41
|
+
// prompt.add('system', 'You are an assistant that can answer questions and help with tasks. Respond precise and concise.', true);
|
|
42
|
+
// prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
43
|
+
// // Create simple toolset
|
|
44
|
+
// /**
|
|
45
|
+
// * @type {import('../lib/API/x.ai/text.js').XOptions}
|
|
46
|
+
// */
|
|
47
|
+
// const options = {
|
|
48
|
+
// model: 'grok-3-mini-fast-latest',
|
|
49
|
+
// reasoning_effort: 'low'
|
|
50
|
+
// }
|
|
51
|
+
// const { url, headers, body } = generateRequest(prompt, tools, options);
|
|
52
|
+
// const res = await doRequest(url, 'POST', headers, body);
|
|
53
|
+
// // console.log(JSON.stringify(res, null, ' '));
|
|
54
|
+
//
|
|
55
|
+
// await parseResponse(1000, prompt, res, tools);
|
|
56
|
+
// const lastMessage = prompt.getLastMessage();
|
|
57
|
+
// console.log(lastMessage);
|
|
58
|
+
// })
|
|
59
|
+
//
|
|
60
|
+
// test.add('2: Add a complete toolcall, a real request', async () => {
|
|
61
|
+
// const prompt = new Prompt();
|
|
62
|
+
// prompt.add('system', 'Respond precise and concise', true);
|
|
63
|
+
// prompt.add('user', 'What is your task?');
|
|
64
|
+
// prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
|
|
65
|
+
// prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
66
|
+
// const message = await request(prompt, tools);
|
|
67
|
+
// console.log(message);
|
|
68
|
+
// })
|
|
69
|
+
//
|
|
70
|
+
// test.add('3: Add a search XAI tool', async () => {
|
|
71
|
+
// const res2 = JSON.parse((await SH`cat scenarios/data/xai_search_response.json`.run()));
|
|
72
|
+
// /**
|
|
73
|
+
// * @type {import('../lib//API/x.ai/text.js').XOptions}
|
|
74
|
+
// */
|
|
75
|
+
// const options = {
|
|
76
|
+
// model: 'grok-3-mini',
|
|
77
|
+
// reasoning_effort: 'low',
|
|
78
|
+
// search_parameters: {
|
|
79
|
+
// mode: 'on'
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
// const prompt = new Prompt();
|
|
83
|
+
// prompt.add('system', 'You are an assistant for an searches on the internet. Respond precise and concise', true);
|
|
84
|
+
// prompt.add('user', 'How to install an LSP for javascript on the helix editor');
|
|
85
|
+
// parseResponse(1000, prompt, res2)
|
|
86
|
+
// // const message = await request(prompt, null, options);
|
|
87
|
+
// // console.log(message);
|
|
88
|
+
// console.log(JSON.stringify(prompt.messages, null, ' '));
|
|
89
|
+
// });
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
test.add('4 REFACTOR TOOLCALLS and message history', async () => {
|
|
93
|
+
const prompt = new Prompt();
|
|
94
|
+
prompt.add('system', 'Respond precise and concise', true);
|
|
95
|
+
prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
96
|
+
const req1 = generateRequest(prompt, tools)
|
|
97
|
+
const { url, headers, body } = generateRequest(prompt, tools);
|
|
98
|
+
const res = await doRequest(url, 'POST', headers, body);
|
|
99
|
+
LOG(res);
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test.add('Parse reponse 1', async () => {
|
|
103
|
+
const prompt = new Prompt();
|
|
104
|
+
prompt.add('system', 'Respond precise and concise', true);
|
|
105
|
+
prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
106
|
+
const res1 = JSON.parse((await SH`cat scenarios/data/xai-response-1.json`.run()));
|
|
107
|
+
await parseResponse(1000, prompt, res1, tools);
|
|
108
|
+
const { url, headers, body } = generateRequest(prompt, tools);
|
|
109
|
+
const res = await doRequest(url, 'POST', headers, body);
|
|
110
|
+
LOG(body);
|
|
111
|
+
|
|
112
|
+
});
|
|
113
|
+
await test.run([1]);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import tools from '../lib/genericToolset.js';
|
|
2
|
+
import { promises as fs } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
const memoryPath = path.join(process.cwd(), '.cache', 'memory.ndjson');
|
|
6
|
+
|
|
7
|
+
// Cleanup previous test data
|
|
8
|
+
try {
|
|
9
|
+
await fs.unlink(memoryPath);
|
|
10
|
+
console.log('🧹 Cleared previous memory.ndjson');
|
|
11
|
+
} catch (e) {
|
|
12
|
+
// No previous file, fine
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
console.log('🧠 Testing memory_write & memory_recall from lib/genericToolset.js...\n');
|
|
16
|
+
|
|
17
|
+
const testWrites = [
|
|
18
|
+
{ category: 'tasks', content: 'Test task 1: Optimize runWithMemory loop using memory tools.' },
|
|
19
|
+
{ category: 'errors', content: 'Test error: Infinite loop detected in prior agent run; suggest human handoff.' },
|
|
20
|
+
{ category: 'prefs', content: 'User preference: Use temperature=0.2 for decision-making tasks.' },
|
|
21
|
+
{ category: 'tasks', content: 'Test task 2: Update system prompts in spawndave.js to include memory instructions.' }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// Write memories
|
|
25
|
+
for (const data of testWrites) {
|
|
26
|
+
const result = await tools.call('memory_write', data);
|
|
27
|
+
console.log(result);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log('\n📖 Test Recalls:\n');
|
|
31
|
+
|
|
32
|
+
console.log('1. Recent memories (empty query):');
|
|
33
|
+
console.log(await tools.call('memory_recall', {}));
|
|
34
|
+
|
|
35
|
+
console.log('\n2. Filter by "tasks":');
|
|
36
|
+
console.log(await tools.call('memory_recall', { query: 'tasks' }));
|
|
37
|
+
|
|
38
|
+
console.log('\n3. Filter by "errors":');
|
|
39
|
+
console.log(await tools.call('memory_recall', { query: 'errors' }));
|
|
40
|
+
|
|
41
|
+
console.log('\n4. Filter by "prefs":');
|
|
42
|
+
console.log(await tools.call('memory_recall', { query: 'prefs' }));
|
|
43
|
+
|
|
44
|
+
console.log('\n5. No matches (nonexistent):');
|
|
45
|
+
console.log(await tools.call('memory_recall', { query: 'foobar' }));
|
|
46
|
+
|
|
47
|
+
// Verify file exists and has content
|
|
48
|
+
const content = await fs.readFile(memoryPath, 'utf8');
|
|
49
|
+
console.log(`\n📁 Raw .cache/memory.ndjson (${content.split('\\n').length - 1} entries):\n${content}`);
|
|
50
|
+
|
|
51
|
+
console.log('\n✅ All tests passed! Tools work as expected.');
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Test, assert, SH } from '@j-o-r/sh'
|
|
3
|
+
import { generateRequest, parseResponse, request } from '../lib/API/openai.com/reponses/text.js';
|
|
4
|
+
import doRequest from '../lib/request.js';
|
|
5
|
+
import Prompt from '../lib/Prompt.js';
|
|
6
|
+
import ToolSet from '../lib/ToolSet.js'
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
|
|
10
|
+
## TODO
|
|
11
|
+
|
|
12
|
+
* try out a vision model
|
|
13
|
+
- Prompt an image
|
|
14
|
+
* try audio transcription
|
|
15
|
+
- Extend prompt with AUDIO messages
|
|
16
|
+
|
|
17
|
+
* try openai websearch (internal toolcall)
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// Generic TEST toolset
|
|
22
|
+
const tools = new ToolSet('auto');
|
|
23
|
+
tools.add(
|
|
24
|
+
'get_current_weather', // name
|
|
25
|
+
'Get the current weather in a given location', // desciption
|
|
26
|
+
{
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
location: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'The city and country'
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
required: ["location"]
|
|
35
|
+
},
|
|
36
|
+
async (params) => {
|
|
37
|
+
const records = [];
|
|
38
|
+
const response = {
|
|
39
|
+
location: params.location,
|
|
40
|
+
temperature: 24,
|
|
41
|
+
}
|
|
42
|
+
return { records, response };
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
tools.add(
|
|
47
|
+
'get_date_time', // name
|
|
48
|
+
'Get the current date and time', // desciption
|
|
49
|
+
{
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
async (_params) => {
|
|
55
|
+
const records = [];
|
|
56
|
+
const response = {
|
|
57
|
+
date_time: 'Friday 12 May, 2025. 12:45',
|
|
58
|
+
}
|
|
59
|
+
return { records, response };
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const test = new Test(true);
|
|
64
|
+
test.add('parse response, toolset roundtrip', async () => {
|
|
65
|
+
// Load a fake reponse
|
|
66
|
+
const prompt = new Prompt();
|
|
67
|
+
prompt.add('system', 'Respond precise and concise', true);
|
|
68
|
+
prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
69
|
+
const duration = 1500;
|
|
70
|
+
const { url, headers, body } = generateRequest(prompt, tools);
|
|
71
|
+
// Create response
|
|
72
|
+
// ----- const res = await doRequest(url, 'POST', headers, body);
|
|
73
|
+
// ----- console.log(JSON.stringify(res, null, ' '));
|
|
74
|
+
// Use response
|
|
75
|
+
const res = JSON.parse((await SH`cat scenarios/data/o3_response1.json`.run()));
|
|
76
|
+
// console.log(res);
|
|
77
|
+
const previousId = res.response.id;
|
|
78
|
+
await parseResponse(duration, prompt, res, tools);
|
|
79
|
+
console.log(JSON.stringify(prompt.messages, null, ' '));
|
|
80
|
+
const lastMessage = prompt.getLastMessage();
|
|
81
|
+
if (lastMessage.role === 'tool') {
|
|
82
|
+
// @ts-ignorer
|
|
83
|
+
const { url, headers, body } = generateRequest(prompt, tools, {previous_response_id: previousId});
|
|
84
|
+
console.log('------ REQUEST -----');
|
|
85
|
+
console.log(JSON.stringify(body, null, ' '));
|
|
86
|
+
const res = await doRequest(url, 'POST', headers, body);
|
|
87
|
+
console.log('------ RESPONSE -----');
|
|
88
|
+
console.log(JSON.stringify(res, null, ' '));
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error('Should have a tool call')
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// @TODO add tools
|
|
95
|
+
test.add('Basic create request body FAKE', async () => {
|
|
96
|
+
const prompt = new Prompt();
|
|
97
|
+
prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
98
|
+
prompt.add('user', 'What is your task?');
|
|
99
|
+
// Create simple toolset
|
|
100
|
+
const { url, headers, body } = generateRequest(prompt);
|
|
101
|
+
const res = await doRequest(url, 'POST', headers, body);
|
|
102
|
+
console.log(JSON.stringify(res, null, ' '));
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test.add('Add a complete toolcall, a real request', async () => {
|
|
106
|
+
const prompt = new Prompt();
|
|
107
|
+
prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
108
|
+
prompt.add('user', 'What is your task?');
|
|
109
|
+
const options = {
|
|
110
|
+
model: 'o3-mini',
|
|
111
|
+
reasoning: {
|
|
112
|
+
"effort": "medium",
|
|
113
|
+
"summary": "auto"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
|
|
117
|
+
// prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
118
|
+
const message = await request(prompt, null, options);
|
|
119
|
+
console.log(message);
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test.add('Parse reasoning into the prompt', async () => {
|
|
123
|
+
|
|
124
|
+
const res = JSON.parse((await SH`cat scenarios/data/oa_reasoning_parse.json`.run()));
|
|
125
|
+
const prompt = new Prompt();
|
|
126
|
+
prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
127
|
+
prompt.add('user', 'What is your task?');
|
|
128
|
+
prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
|
|
129
|
+
prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
130
|
+
const duration = 1500
|
|
131
|
+
await parseResponse(duration, prompt, res, tools);
|
|
132
|
+
// const { url, headers, body } = generateRequest(prompt, tools);
|
|
133
|
+
// console.log( JSON.stringify(body, null, ' '));
|
|
134
|
+
console.log( JSON.stringify(prompt.messages, null, ' '));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
await test.run([0]);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Cli, API, ToolSet, Prompt, Session} from '../lib/index.js';
|
|
3
|
+
import { Test, assert, SH } from '@j-o-r/sh'
|
|
4
|
+
// import { generateRequest, parseResponse, request } from '../lib/API/openai.com/reponses/text.js';
|
|
5
|
+
// import doRequest from '../lib/request.js';
|
|
6
|
+
// import Session from '../lib/Session.js';
|
|
7
|
+
// import ToolSet from '../lib/ToolSet.js'
|
|
8
|
+
// import Cli from '../lib/Cli.js';
|
|
9
|
+
// const SNAME = 'o3TestsSession'
|
|
10
|
+
|
|
11
|
+
const tools = new ToolSet('auto');
|
|
12
|
+
tools.add(
|
|
13
|
+
'get_current_weather', // name
|
|
14
|
+
'Get the current weather in a given location', // desciption
|
|
15
|
+
{
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
location: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'The city and country'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
required: ["location"]
|
|
24
|
+
},
|
|
25
|
+
async (params) => {
|
|
26
|
+
const response = {
|
|
27
|
+
location: params.location,
|
|
28
|
+
temperature: 24,
|
|
29
|
+
}
|
|
30
|
+
return response ;
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
tools.add(
|
|
35
|
+
'get_date_time', // name
|
|
36
|
+
'Get the current date and time', // desciption
|
|
37
|
+
{
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async (_params) => {
|
|
43
|
+
const response = {
|
|
44
|
+
date_time: 'Friday 12 May, 2025. 12:45',
|
|
45
|
+
}
|
|
46
|
+
return response ;
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const test = new Test(true);
|
|
51
|
+
test.add('parse response, toolset roundtrip', async () => {
|
|
52
|
+
//
|
|
53
|
+
const prompt = new Prompt();
|
|
54
|
+
// session.empty();
|
|
55
|
+
prompt.setAdaptor(API.text.gpt, tools, null);
|
|
56
|
+
prompt.add('system', 'Respond precise and concise', true);
|
|
57
|
+
const events = Object.keys(prompt.EVENTS);
|
|
58
|
+
events.forEach((evt) => {
|
|
59
|
+
prompt.on(evt, (m) => {
|
|
60
|
+
console.log(`*** ${evt} event **`);
|
|
61
|
+
console.log(JSON.stringify(m, null, ' '));
|
|
62
|
+
});
|
|
63
|
+
})
|
|
64
|
+
const mes = await prompt.call('What day is today and what is the weather forecast in Amsterdam, The Netherlands');
|
|
65
|
+
console.log(mes);
|
|
66
|
+
const mesw = await prompt.call('What day is today and what is the weather forecast in Madrid');
|
|
67
|
+
console.log(mesw);
|
|
68
|
+
// const duration = 1500;
|
|
69
|
+
// const { url, headers, body } = generateRequest(prompt, tools);
|
|
70
|
+
// console.log(body);
|
|
71
|
+
// Create response
|
|
72
|
+
// ----- const res = await doRequest(url, 'POST', headers, body);
|
|
73
|
+
// ----- console.log(JSON.stringify(res, null, ' '));
|
|
74
|
+
// Use response
|
|
75
|
+
// const res = JSON.parse((await SH`cat scenarios/data/o3_response1.json`.run()));
|
|
76
|
+
// // console.log(res);
|
|
77
|
+
// const previousId = res.response.id;
|
|
78
|
+
// await parseResponse(duration, prompt, res, tools);
|
|
79
|
+
// console.log(JSON.stringify(prompt.messages, null, ' '));
|
|
80
|
+
// const lastMessage = prompt.getLastMessage();
|
|
81
|
+
// if (lastMessage.role === 'tool') {
|
|
82
|
+
// // @ts-ignorer
|
|
83
|
+
// const { url, headers, body } = generateRequest(prompt, tools, {previous_response_id: previousId});
|
|
84
|
+
// console.log('------ REQUEST -----');
|
|
85
|
+
// console.log(JSON.stringify(body, null, ' '));
|
|
86
|
+
// const res = await doRequest(url, 'POST', headers, body);
|
|
87
|
+
// console.log('------ RESPONSE -----');
|
|
88
|
+
// console.log(JSON.stringify(res, null, ' '));
|
|
89
|
+
// } else {
|
|
90
|
+
// throw new Error('Should have a tool call')
|
|
91
|
+
// }
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test.add('Spin up a CLI', async () => {
|
|
95
|
+
const prompt = new Prompt(20000);
|
|
96
|
+
const session = new Session('pipo', prompt, '.hello-dave');
|
|
97
|
+
prompt.setAdaptor(API.text.gpt, null, null);
|
|
98
|
+
prompt.add('system', 'Respond precise and concise', true);
|
|
99
|
+
const cli = new Cli({prompt, session})
|
|
100
|
+
cli.start();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test.add('Spin up a CLI, one shot', async () => {
|
|
104
|
+
const prompt = new Prompt(0);
|
|
105
|
+
const session = new Session('pipo', prompt, '.hello-dave');
|
|
106
|
+
prompt.setAdaptor(API.text.gpt, null, null);
|
|
107
|
+
prompt.add('system', 'Respond precise and concise', true);
|
|
108
|
+
const cli = new Cli({prompt, session})
|
|
109
|
+
cli.start();
|
|
110
|
+
});
|
|
111
|
+
//
|
|
112
|
+
// // @TODO add tools
|
|
113
|
+
// test.add('Basic create request body FAKE', async () => {
|
|
114
|
+
// const session = new Session(SNAME);
|
|
115
|
+
// session.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
116
|
+
// session.add('user', 'What is your task?');
|
|
117
|
+
// // Create simple toolset
|
|
118
|
+
// const { url, headers, body } = generateRequest(session);
|
|
119
|
+
// const res = await doRequest(url, 'POST', headers, body);
|
|
120
|
+
// console.log(JSON.stringify(res, null, ' '));
|
|
121
|
+
// })
|
|
122
|
+
//
|
|
123
|
+
// test.add('Add a complete toolcall, a real request', async () => {
|
|
124
|
+
// const prompt = new Session(SNAME);
|
|
125
|
+
// prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
126
|
+
// prompt.add('user', 'What is your task?');
|
|
127
|
+
// const options = {
|
|
128
|
+
// model: 'o3-mini',
|
|
129
|
+
// reasoning: {
|
|
130
|
+
// "effort": "medium",
|
|
131
|
+
// "summary": "auto"
|
|
132
|
+
// }
|
|
133
|
+
// }
|
|
134
|
+
// // prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
|
|
135
|
+
// // prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
136
|
+
// const message = await request(prompt, null, options);
|
|
137
|
+
// console.log(message);
|
|
138
|
+
// })
|
|
139
|
+
//
|
|
140
|
+
// test.add('Parse reasoning into the prompt', async () => {
|
|
141
|
+
//
|
|
142
|
+
// const res = JSON.parse((await SH`cat scenarios/data/oa_reasoning_parse.json`.run()));
|
|
143
|
+
// const prompt = new Session(SNAME);
|
|
144
|
+
// prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
|
|
145
|
+
// prompt.add('user', 'What is your task?');
|
|
146
|
+
// prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
|
|
147
|
+
// prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
|
|
148
|
+
// const duration = 1500
|
|
149
|
+
// await parseResponse(duration, prompt, res, tools);
|
|
150
|
+
// // const { url, headers, body } = generateRequest(prompt, tools);
|
|
151
|
+
// // console.log( JSON.stringify(body, null, ' '));
|
|
152
|
+
// console.log( JSON.stringify(prompt.messages, null, ' '));
|
|
153
|
+
// });
|
|
154
|
+
|
|
155
|
+
await test.run([2]);
|