@j-o-r/hello-dave 0.0.3 → 0.0.5

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +337 -68
  3. package/README.md.bak +523 -0
  4. package/README.md.bak.1774780058 +338 -0
  5. package/README.md.bak2 +531 -0
  6. package/bin/dave.js +33 -22
  7. package/bin/spawn_agent.js +293 -0
  8. package/docs.bak.1774780058/agent-manager.md +167 -0
  9. package/docs.bak.1774780058/agent-manager.md.bak +137 -0
  10. package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
  11. package/docs.bak.1774780058/codeserver-pattern.md +191 -0
  12. package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
  13. package/docs.bak.1774780058/project-overview.md +67 -0
  14. package/docs.bak.1774780058/project-overview.md.bak +67 -0
  15. package/docs.bak.1774780058/prompt-class.md +141 -0
  16. package/docs.bak.1774780058/prompt-class.md.bak +142 -0
  17. package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
  18. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
  19. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
  20. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
  21. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
  22. package/docs.bak.1774780058/toolset.md +164 -0
  23. package/docs.bak.1774780058/toolset.md.bak +94 -0
  24. package/docs.bak.1774780058/toolset.md.bak3 +161 -0
  25. package/docs.bak.1774780058/toolset.md.bak4 +161 -0
  26. package/docs.bak.1774780058/toolset.md.bak5 +161 -0
  27. package/docs.bak.1774780058/toolset.md.bak6 +163 -0
  28. package/docs.bak.1774780058/toolset.md.bak_path +163 -0
  29. package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
  30. package/docs.bak.1774780058/xai-responses.md +111 -0
  31. package/docs.bak.1774780058/xai-responses.md.bak +107 -0
  32. package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
  33. package/docs.bak.1774780058/xai_collections.md +106 -0
  34. package/examples/ask_agent.js +137 -0
  35. package/examples/code_agent.js +149 -0
  36. package/examples/codeserver.sh +47 -0
  37. package/examples/daisy_agent.js +170 -0
  38. package/examples/docs_agent.js +148 -0
  39. package/examples/gpt_agent.js +122 -0
  40. package/examples/grok_agent.js +132 -0
  41. package/examples/memory_agent.js +152 -0
  42. package/examples/npm_agent.js +202 -0
  43. package/examples/prompt_agent.js +133 -0
  44. package/examples/readme_agent.js +148 -0
  45. package/examples/test_agent.js +187 -0
  46. package/examples/todo_agent.js +175 -0
  47. package/{examples/codeDave.js → examples.bak.1774780058/code_agent.js} +40 -6
  48. package/{examples/CodeServer → examples.bak.1774780058/codeserver.sh} +9 -5
  49. package/examples.bak.1774780058/memory_agent.js +112 -0
  50. package/{examples/spawndave.js → examples.bak.1774780058/spawn_agent.js} +29 -6
  51. package/examples.bak.1774780058/test_agent.js +162 -0
  52. package/{examples/todoDave.js → examples.bak.1774780058/todo_agent.js} +8 -2
  53. package/lib/API/x.ai/responses.js +7 -9
  54. package/lib/AgentManager.js +3 -2
  55. package/lib/AgentServer.js +23 -19
  56. package/lib/ToolSet.js +4 -1
  57. package/lib/genericToolset.js +159 -26
  58. package/lib/genericToolset.js.bak_syntax +402 -0
  59. package/lib/index.js +5 -1
  60. package/lib/wsCli.js +0 -1
  61. package/package.json +5 -6
  62. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  63. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  64. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  65. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  66. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  67. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  68. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  69. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  70. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  71. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  72. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  73. package/scenarios.bak.1774780058/environment.js +10 -0
  74. package/scenarios.bak.1774780058/example.js +17 -0
  75. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  76. package/scenarios.bak.1774780058/grok.js +113 -0
  77. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  78. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  79. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  80. package/scenarios.bak.1774780058/openai-session.js +148 -0
  81. package/scenarios.bak.1774780058/openai.js +102 -0
  82. package/scenarios.bak.1774780058/prompt.js +118 -0
  83. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  84. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  85. package/scenarios.bak.1774780058/sh.js +15 -0
  86. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  87. package/scenarios.bak.1774780058/testToolset.js +42 -0
  88. package/scenarios.bak.1774780058/toolset.js +16 -0
  89. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  90. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  91. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  92. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  93. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  94. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  95. package/scenarios.bak.1774780058/wsClient.js +69 -0
  96. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  97. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  98. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  99. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  100. package/types/AgentManager.d.ts +4 -3
  101. package/types/index.d.ts +3 -1
  102. package/utils/syntax_check.sh +61 -0
  103. package/utils/test.sh +46 -0
  104. /package/{examples/askDave.js → examples.bak.1774780058/ask_agent.js} +0 -0
  105. /package/{examples/coderev.js → examples.bak.1774780058/coderev_agent.js} +0 -0
  106. /package/{examples/daisy.js → examples.bak.1774780058/daisy_agent.js} +0 -0
  107. /package/{examples/docsDave.js → examples.bak.1774780058/docs_agent.js} +0 -0
  108. /package/{examples/gpt.js → examples.bak.1774780058/gpt_agent.js} +0 -0
  109. /package/{examples/grok.js → examples.bak.1774780058/grok_agent.js} +0 -0
  110. /package/{examples/npmDave.js → examples.bak.1774780058/npm_agent.js} +0 -0
  111. /package/{examples/promptDave.js → examples.bak.1774780058/prompt_agent.js} +0 -0
  112. /package/{examples/readmeDave.js → examples.bak.1774780058/readme_agent.js} +0 -0
@@ -0,0 +1,58 @@
1
+ {
2
+ "status": 200,
3
+ "responseType": "js",
4
+ "response": {
5
+ "id": "f964eed9-95b6-5d95-2383-d25be743d8e6",
6
+ "object": "chat.completion",
7
+ "created": 1751456496,
8
+ "model": "grok-3-mini",
9
+ "choices": [
10
+ {
11
+ "index": 0,
12
+ "message": {
13
+ "role": "assistant",
14
+ "content": "To install a Language Server Protocol (LSP) for JavaScript on the Helix editor, follow these steps based on Helix documentation and community guides:\n\n### 1. **Install a JavaScript Language Server**\n - The most common LSP for JavaScript is the TypeScript Language Server (tsserver), which also supports JavaScript.\n - Install it via npm (Node.js package manager):\n ```\n npm install -g typescript\n ```\n - Ensure Node.js and npm are installed first (download from the official Node.js website if needed).\n - Alternatively, other LSPs like ESLint or Volar can be used for specific features; install them via npm or their respective methods.\n\n### 2. **Configure Helix Editor**\n - Helix uses a `languages.toml` file for language server settings.\n - Locate or create a `languages.toml` file in one of these locations (as per Helix docs):\n - User config: `~/.config/helix/languages.toml`\n - Project-specific: In your project directory.\n - Add or update the JavaScript section. For example, add this to your `languages.toml`:\n ```\n [language.javascript]\n language-server = { command = \"typescript-language-server\", args = [\"--stdio\"] }\n ```\n - This assumes `typescript-language-server` is installed (it comes with the TypeScript global install).\n - Save the file and restart Helix.\n\n### 3. **Verify and Test**\n - Run `hx --health` in your terminal to check language server support.\n - Open a JavaScript file in Helix (e.g., `.js` or `.ts`) and test features like autocompletion or diagnostics.\n\nFor more details, refer to the Helix documentation on language support (e.g., docs.helix-editor.com/lang-support.html) or a guide on installing Helix language servers. If you encounter issues, ensure your Helix version is up to date. If this doesn't work, posts on platforms like X suggest checking npm installations for compatibility.",
15
+ "reasoning_content": "First, the user is asking: \"How to install an LSP for JavaScript on the Helix editor.\" This matches the search query I have context for: \"Install Language Server Protocol for JavaScript on Helix editor.\"\n\nI need to respond precisely and concisely, as per my system prompt. I'm an assistant for searches on the internet, so I should base my answer on the provided web results, news results, and X posts, but only if relevant.\n\nKey relevant information from the web results:\n\n- From ‽web:0 (docs.helix-editor.com/lang-support.html): Helix supports languages and Language Servers. You need to configure the appropriate Language Server.\n\n- From ‽web:1 (docs.helix-editor.com/languages.html): Language-specific settings are in languages.toml files.\n\n- From ‽web:2 (ar.al/2022/11/14/...): There's a script for installing Language Servers for web development in Helix.\n\n- From ‽web:3 (batsov.com/articles/2025/02/21/...): A basic Helix setup for JavaScript, which likely includes LSP setup.\n\n- From ‽web:4 (github.com/helix-editor/helix): The languages.toml file, which is key for configuration.\n\nFrom news results:\n\n- ‽web:3 (volarjs.dev/guides/first-server/): This is about Volar, which is a Language Server for Vue.js but might be adaptable for JavaScript.\n\n- ‽web:4 (guillermoap.medium.com/...): Turning Helix into an IDE, which could involve LSP setup.\n\nFrom X posts:\n\n- There's a post about IntelliJ supporting LSP, but that's not directly related.\n\n- Astro post mentions building on LSP and using it for JS.\n\n- A post by Alisher mentions installing with npm, which could be relevant for JavaScript LSP.\n\nThe most directly relevant is the script from Aral Balkan's blog (‽web:2) and the Helix documentation.\n\nSteps to install LSP for JavaScript in Helix:\n\n1. Identify the Language Server for JavaScript. Common ones are like TypeScript Language Server (tsserver) since JavaScript is handled by TypeScript tools.\n\n2. Configure it in Helix via languages.toml.\n\nFrom the results, users need to install the Language Server first, then configure it in Helix.\n\nA concise answer should include:\n\n- Install a JavaScript Language Server, e.g., via npm (like typescript, which includes tsserver).\n\n- Configure it in Helix's languages.toml file.\n\nMention sources briefly if it makes sense, like referring to Helix documentation.\n\nFinally, structure the response: Be precise, use bullet points or numbered steps for clarity, and keep it concise.",
16
+ "refusal": null
17
+ },
18
+ "finish_reason": "stop"
19
+ }
20
+ ],
21
+ "usage": {
22
+ "prompt_tokens": 2434,
23
+ "completion_tokens": 411,
24
+ "total_tokens": 3393,
25
+ "prompt_tokens_details": {
26
+ "text_tokens": 2434,
27
+ "audio_tokens": 0,
28
+ "image_tokens": 0,
29
+ "cached_tokens": 6
30
+ },
31
+ "completion_tokens_details": {
32
+ "reasoning_tokens": 548,
33
+ "audio_tokens": 0,
34
+ "accepted_prediction_tokens": 0,
35
+ "rejected_prediction_tokens": 0
36
+ },
37
+ "num_sources_used": 3
38
+ },
39
+ "system_fingerprint": "fp_2e0c052777",
40
+ "citations": [
41
+ "https://docs.helix-editor.com/lang-support.html",
42
+ "https://docs.helix-editor.com/languages.html",
43
+ "https://ar.al/2022/11/14/installing-helix-editor-language-servers/",
44
+ "https://batsov.com/articles/2025/02/21/a-basic-helix-setup-for-javascript/",
45
+ "https://github.com/helix-editor/helix/blob/master/languages.toml",
46
+ "https://herecomesthemoon.net/2025/06/i-like-helix/",
47
+ "https://freecodecamp.org/news/how-to-build-a-custom-mcp-server-with-typescript-a-handbook-for-developers",
48
+ "https://infoworld.com/article/3849654/typescript-gets-go-faster-stripes.html",
49
+ "https://volarjs.dev/guides/first-server/",
50
+ "https://guillermoap.medium.com/turning-helix-into-an-ide-with-the-help-of-zellij-03c4e52524da",
51
+ "https://x.com/JBPlatform/status/1677320230534561793",
52
+ "https://x.com/sawaba/status/1061673555652472833",
53
+ "https://x.com/0xMert_/status/1748394502073520405",
54
+ "https://x.com/astrodotbuild/status/1760709773589188811",
55
+ "https://x.com/JavaScriptDaily/status/1264628987592093697"
56
+ ]
57
+ }
58
+ }
@@ -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]);