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

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 (127) hide show
  1. package/CHANGELOG.md +13 -26
  2. package/README.md +161 -522
  3. package/README.md.bak +144 -449
  4. package/{examples → agents}/ask_agent.js +5 -5
  5. package/{examples → agents}/codeserver.sh +14 -14
  6. package/{examples → agents}/daisy_agent.js +5 -5
  7. package/{examples → agents}/docs_agent.js +5 -5
  8. package/{examples → agents}/gpt_agent.js +5 -5
  9. package/{examples → agents}/grok_agent.js +5 -5
  10. package/agents/memory_agent.js +263 -0
  11. package/{examples → agents}/npm_agent.js +5 -5
  12. package/{examples → agents}/prompt_agent.js +5 -5
  13. package/agents/spawn_agent.js +137 -0
  14. package/{examples → agents}/test_agent.js +6 -8
  15. package/{examples → agents}/todo_agent.js +5 -5
  16. package/bin/codeDave +58 -0
  17. package/bin/dave.js +114 -96
  18. package/lib/AgentClient.js +111 -67
  19. package/lib/AgentManager.js +111 -80
  20. package/lib/AgentServer.js +144 -104
  21. package/lib/Cli.js +126 -93
  22. package/lib/Prompt.js +38 -5
  23. package/lib/Session.js +102 -79
  24. package/lib/ToolSet.js +79 -60
  25. package/lib/fafs.js +54 -19
  26. package/lib/genericToolset.js +109 -213
  27. package/lib/wsCli.js +50 -19
  28. package/lib/wsIO.js +11 -17
  29. package/package.json +2 -2
  30. package/types/AgentClient.d.ts +69 -35
  31. package/types/AgentManager.d.ts +50 -56
  32. package/types/AgentServer.d.ts +63 -16
  33. package/types/Cli.d.ts +56 -10
  34. package/types/Prompt.d.ts +36 -4
  35. package/types/Session.d.ts +23 -9
  36. package/types/ToolSet.d.ts +49 -32
  37. package/types/fafs.d.ts +68 -25
  38. package/types/wsCli.d.ts +14 -0
  39. package/types/wsIO.d.ts +9 -5
  40. package/utils/search_sessions.sh +100 -53
  41. package/README.md.backup +0 -269
  42. package/README.md.bak.1774780058 +0 -338
  43. package/README.md.bak2 +0 -531
  44. package/bin/spawn_agent.js +0 -293
  45. package/docs.bak.1774780058/agent-manager.md +0 -167
  46. package/docs.bak.1774780058/agent-manager.md.bak +0 -137
  47. package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
  48. package/docs.bak.1774780058/codeserver-pattern.md +0 -191
  49. package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
  50. package/docs.bak.1774780058/project-overview.md +0 -67
  51. package/docs.bak.1774780058/project-overview.md.bak +0 -67
  52. package/docs.bak.1774780058/prompt-class.md +0 -141
  53. package/docs.bak.1774780058/prompt-class.md.bak +0 -142
  54. package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
  55. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
  56. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
  57. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
  58. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
  59. package/docs.bak.1774780058/toolset.md +0 -164
  60. package/docs.bak.1774780058/toolset.md.bak +0 -94
  61. package/docs.bak.1774780058/toolset.md.bak3 +0 -161
  62. package/docs.bak.1774780058/toolset.md.bak4 +0 -161
  63. package/docs.bak.1774780058/toolset.md.bak5 +0 -161
  64. package/docs.bak.1774780058/toolset.md.bak6 +0 -163
  65. package/docs.bak.1774780058/toolset.md.bak_path +0 -163
  66. package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
  67. package/docs.bak.1774780058/xai-responses.md +0 -111
  68. package/docs.bak.1774780058/xai-responses.md.bak +0 -107
  69. package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
  70. package/docs.bak.1774780058/xai_collections.md +0 -106
  71. package/examples/memory_agent.js +0 -152
  72. package/examples.bak.1774780058/ask_agent.js +0 -114
  73. package/examples.bak.1774780058/code_agent.js +0 -149
  74. package/examples.bak.1774780058/coderev_agent.js +0 -72
  75. package/examples.bak.1774780058/codeserver.sh +0 -47
  76. package/examples.bak.1774780058/daisy_agent.js +0 -177
  77. package/examples.bak.1774780058/docs_agent.js +0 -119
  78. package/examples.bak.1774780058/gpt_agent.js +0 -109
  79. package/examples.bak.1774780058/grok_agent.js +0 -98
  80. package/examples.bak.1774780058/memory_agent.js +0 -112
  81. package/examples.bak.1774780058/npm_agent.js +0 -175
  82. package/examples.bak.1774780058/prompt_agent.js +0 -112
  83. package/examples.bak.1774780058/readme_agent.js +0 -144
  84. package/examples.bak.1774780058/spawn_agent.js +0 -263
  85. package/examples.bak.1774780058/test_agent.js +0 -162
  86. package/examples.bak.1774780058/todo_agent.js +0 -138
  87. package/lib/genericToolset.js.bak_syntax +0 -402
  88. package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
  89. package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
  90. package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
  91. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
  92. package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
  93. package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
  94. package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
  95. package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
  96. package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
  97. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
  98. package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
  99. package/scenarios.bak.1774780058/environment.js +0 -10
  100. package/scenarios.bak.1774780058/example.js +0 -17
  101. package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
  102. package/scenarios.bak.1774780058/grok.js +0 -113
  103. package/scenarios.bak.1774780058/memory-tools.js +0 -51
  104. package/scenarios.bak.1774780058/openai-o3.js +0 -137
  105. package/scenarios.bak.1774780058/openai-prompt.js +0 -155
  106. package/scenarios.bak.1774780058/openai-session.js +0 -148
  107. package/scenarios.bak.1774780058/openai.js +0 -102
  108. package/scenarios.bak.1774780058/prompt.js +0 -118
  109. package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
  110. package/scenarios.bak.1774780058/search.brave.com.js +0 -25
  111. package/scenarios.bak.1774780058/sh.js +0 -15
  112. package/scenarios.bak.1774780058/test-wsio.js +0 -26
  113. package/scenarios.bak.1774780058/testToolset.js +0 -42
  114. package/scenarios.bak.1774780058/toolset.js +0 -16
  115. package/scenarios.bak.1774780058/toolset.test.js +0 -141
  116. package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
  117. package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
  118. package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
  119. package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
  120. package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
  121. package/scenarios.bak.1774780058/wsClient.js +0 -69
  122. package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
  123. package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
  124. package/scenarios.bak.1774780058/xaicoll.js +0 -50
  125. package/scenarios.bak.1774780058/xaifiles.js +0 -48
  126. /package/{examples → agents}/code_agent.js +0 -0
  127. /package/{examples → agents}/readme_agent.js +0 -0
@@ -1,113 +0,0 @@
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]);
@@ -1,51 +0,0 @@
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.');
@@ -1,137 +0,0 @@
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]);
@@ -1,155 +0,0 @@
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]);
@@ -1,148 +0,0 @@
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 Session from '../lib/Session.js';
6
- import ToolSet from '../lib/ToolSet.js'
7
- import Cli from '../lib/Cli.js';
8
- const SNAME = 'o3TestsSession'
9
-
10
- const tools = new ToolSet('auto');
11
- tools.add(
12
- 'get_current_weather', // name
13
- 'Get the current weather in a given location', // desciption
14
- {
15
- type: 'object',
16
- properties: {
17
- location: {
18
- type: 'string',
19
- description: 'The city and country'
20
- }
21
- },
22
- required: ["location"]
23
- },
24
- async (params) => {
25
- const records = [];
26
- const response = {
27
- location: params.location,
28
- temperature: 24,
29
- }
30
- return { records, 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 records = [];
44
- const response = {
45
- date_time: 'Friday 12 May, 2025. 12:45',
46
- }
47
- return { records, response };
48
- }
49
- );
50
-
51
- const test = new Test(true);
52
- test.add('parse response, toolset roundtrip', async () => {
53
- // Load a fake reponse
54
- const session = new Session(SNAME);
55
- session.empty();
56
- session.setAdaptor(request, tools, null);
57
- session.add('system', 'Respond precise and concise', true);
58
- session.on('message', (m) => {
59
- console.log('*** message event **');
60
- console.log(JSON.stringify(m, null, ' '));
61
- });
62
- session.on('truncated', (m) => {
63
- console.log('*** truncated event **');
64
- console.log(JSON.stringify(m, null, ' '));
65
- });
66
- const mes = await session.call('What day is today and what is the weather forecast in Amsterdam, The Netherlands');
67
- console.log(mes);
68
- const mesw = await session.call('What day is today and what is the weather forecast in Madrid');
69
- console.log(mesw);
70
- // const duration = 1500;
71
- // const { url, headers, body } = generateRequest(prompt, tools);
72
- // console.log(body);
73
- // Create response
74
- // ----- const res = await doRequest(url, 'POST', headers, body);
75
- // ----- console.log(JSON.stringify(res, null, ' '));
76
- // Use response
77
- // const res = JSON.parse((await SH`cat scenarios/data/o3_response1.json`.run()));
78
- // // console.log(res);
79
- // const previousId = res.response.id;
80
- // await parseResponse(duration, prompt, res, tools);
81
- // console.log(JSON.stringify(prompt.messages, null, ' '));
82
- // const lastMessage = prompt.getLastMessage();
83
- // if (lastMessage.role === 'tool') {
84
- // // @ts-ignorer
85
- // const { url, headers, body } = generateRequest(prompt, tools, {previous_response_id: previousId});
86
- // console.log('------ REQUEST -----');
87
- // console.log(JSON.stringify(body, null, ' '));
88
- // const res = await doRequest(url, 'POST', headers, body);
89
- // console.log('------ RESPONSE -----');
90
- // console.log(JSON.stringify(res, null, ' '));
91
- // } else {
92
- // throw new Error('Should have a tool call')
93
- // }
94
- });
95
-
96
- test.add('Spin up a CLI', async () => {
97
- const session = new Session(SNAME);
98
- // prompt.empty();
99
- session.setAdaptor(request, null, null);
100
- session.add('system', 'Respond precise and concise', true);
101
- const cli = new Cli({session})
102
- cli.start();
103
- })
104
-
105
- // @TODO add tools
106
- test.add('Basic create request body FAKE', async () => {
107
- const session = new Session(SNAME);
108
- session.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
109
- session.add('user', 'What is your task?');
110
- // Create simple toolset
111
- const { url, headers, body } = generateRequest(session);
112
- const res = await doRequest(url, 'POST', headers, body);
113
- console.log(JSON.stringify(res, null, ' '));
114
- })
115
-
116
- test.add('Add a complete toolcall, a real request', async () => {
117
- const prompt = new Session(SNAME);
118
- prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
119
- prompt.add('user', 'What is your task?');
120
- const options = {
121
- model: 'o3-mini',
122
- reasoning: {
123
- "effort": "medium",
124
- "summary": "auto"
125
- }
126
- }
127
- // prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
128
- // prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
129
- const message = await request(prompt, null, options);
130
- console.log(message);
131
- })
132
-
133
- test.add('Parse reasoning into the prompt', async () => {
134
-
135
- const res = JSON.parse((await SH`cat scenarios/data/oa_reasoning_parse.json`.run()));
136
- const prompt = new Session(SNAME);
137
- prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
138
- prompt.add('user', 'What is your task?');
139
- prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
140
- prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
141
- const duration = 1500
142
- await parseResponse(duration, prompt, res, tools);
143
- // const { url, headers, body } = generateRequest(prompt, tools);
144
- // console.log( JSON.stringify(body, null, ' '));
145
- console.log( JSON.stringify(prompt.messages, null, ' '));
146
- });
147
-
148
- await test.run([1]);