@j-o-r/hello-dave 0.0.2 → 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.
Files changed (161) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +445 -160
  3. package/README.md.backup +269 -0
  4. package/README.md.bak +481 -0
  5. package/README.md.bak.1774780058 +338 -0
  6. package/README.md.bak2 +455 -0
  7. package/bin/dave.js +165 -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/coderev_agent.js +136 -0
  37. package/examples/codeserver.sh +47 -0
  38. package/examples/daisy_agent.js +170 -0
  39. package/examples/docs_agent.js +148 -0
  40. package/examples/gpt_agent.js +125 -0
  41. package/examples/grok_agent.js +132 -0
  42. package/examples/grok_agent.js.bak +98 -0
  43. package/examples/grok_agent.js.bak.2 +99 -0
  44. package/examples/grok_agent.js.bak.3 +1 -0
  45. package/examples/grok_agent.js.bak.4 +124 -0
  46. package/examples/grok_agent.js.bak.5 +1 -0
  47. package/examples/grok_agent.js.bak.6 +1 -0
  48. package/examples/memory_agent.js +152 -0
  49. package/examples/npm_agent.js +202 -0
  50. package/examples/npm_agent.js.bak.3 +2 -0
  51. package/examples/npm_agent.js.bak.4 +205 -0
  52. package/examples/npm_agent.js.bak.5 +1 -0
  53. package/examples/npm_agent.js.bak.6 +1 -0
  54. package/examples/prompt_agent.js +133 -0
  55. package/examples/readme_agent.js +148 -0
  56. package/examples/spawn_agent.js +293 -0
  57. package/examples/test_agent.js +187 -0
  58. package/examples/todo_agent.js +175 -0
  59. package/examples.bak.1774780058/ask_agent.js +114 -0
  60. package/examples.bak.1774780058/code_agent.js +149 -0
  61. package/examples.bak.1774780058/coderev_agent.js +72 -0
  62. package/examples.bak.1774780058/codeserver.sh +47 -0
  63. package/examples.bak.1774780058/daisy_agent.js +177 -0
  64. package/examples.bak.1774780058/docs_agent.js +119 -0
  65. package/{bin/hdAsk.js → examples.bak.1774780058/gpt_agent.js} +46 -40
  66. package/examples.bak.1774780058/grok_agent.js +98 -0
  67. package/examples.bak.1774780058/memory_agent.js +112 -0
  68. package/examples.bak.1774780058/npm_agent.js +175 -0
  69. package/examples.bak.1774780058/prompt_agent.js +112 -0
  70. package/examples.bak.1774780058/readme_agent.js +144 -0
  71. package/examples.bak.1774780058/spawn_agent.js +263 -0
  72. package/examples.bak.1774780058/test_agent.js +162 -0
  73. package/examples.bak.1774780058/todo_agent.js +138 -0
  74. package/lib/API/openai.com/reponses/text.js +12 -18
  75. package/lib/API/x.ai/collections.js +354 -0
  76. package/lib/API/x.ai/files.js +218 -0
  77. package/lib/API/x.ai/responses.js +492 -0
  78. package/lib/API/x.ai/text.js +1 -1
  79. package/lib/AgentClient.js +13 -6
  80. package/lib/AgentManager.js +80 -10
  81. package/lib/AgentServer.js +50 -22
  82. package/lib/Cli.js +7 -1
  83. package/lib/Prompt.js +4 -2
  84. package/lib/ToolSet.js +2 -1
  85. package/lib/genericToolset.js +258 -88
  86. package/lib/genericToolset.js.bak_syntax +402 -0
  87. package/lib/index.js +4 -2
  88. package/lib/wsCli.js +256 -0
  89. package/lib/wsIO.js +96 -0
  90. package/package.json +26 -21
  91. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  92. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  93. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  94. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  95. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  96. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  97. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  98. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  99. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  100. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  101. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  102. package/scenarios.bak.1774780058/environment.js +10 -0
  103. package/scenarios.bak.1774780058/example.js +17 -0
  104. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  105. package/scenarios.bak.1774780058/grok.js +113 -0
  106. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  107. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  108. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  109. package/scenarios.bak.1774780058/openai-session.js +148 -0
  110. package/scenarios.bak.1774780058/openai.js +102 -0
  111. package/scenarios.bak.1774780058/prompt.js +118 -0
  112. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  113. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  114. package/scenarios.bak.1774780058/sh.js +15 -0
  115. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  116. package/scenarios.bak.1774780058/testToolset.js +42 -0
  117. package/scenarios.bak.1774780058/toolset.js +16 -0
  118. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  119. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  120. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  121. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  122. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  123. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  124. package/scenarios.bak.1774780058/wsClient.js +69 -0
  125. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  126. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  127. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  128. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  129. package/types/API/openai.com/reponses/text.d.ts +17 -3
  130. package/types/API/x.ai/collections.d.ts +167 -0
  131. package/types/API/x.ai/files.d.ts +84 -0
  132. package/types/API/x.ai/responses.d.ts +379 -0
  133. package/types/AgentClient.d.ts +5 -0
  134. package/types/AgentManager.d.ts +25 -31
  135. package/types/AgentServer.d.ts +5 -1
  136. package/types/Prompt.d.ts +4 -2
  137. package/types/ToolSet.d.ts +1 -0
  138. package/types/index.d.ts +4 -3
  139. package/types/wsCli.d.ts +3 -0
  140. package/types/wsIO.d.ts +26 -0
  141. package/utils/bars.js +40 -0
  142. package/utils/clear_sessions.sh +54 -0
  143. package/{bin/hdInspect.js → utils/format_log.js} +5 -0
  144. package/utils/list_sessions.sh +46 -0
  145. package/utils/search_sessions.sh +73 -0
  146. package/utils/syntax_check.sh +61 -0
  147. package/utils/test.sh +46 -0
  148. package/bin/hdClear.js +0 -13
  149. package/bin/hdCode.js +0 -115
  150. package/bin/hdConnect.js +0 -230
  151. package/bin/hdNpm.js +0 -114
  152. package/bin/hdPrompt.js +0 -108
  153. package/examples/claude-test.js +0 -89
  154. package/examples/claude.js +0 -143
  155. package/examples/gpt.js +0 -127
  156. package/examples/gpt_code.js +0 -125
  157. package/examples/gpt_note_keeping.js +0 -117
  158. package/examples/grok.js +0 -119
  159. package/examples/grok_code.js +0 -114
  160. package/examples/grok_note_keeping.js +0 -111
  161. package/module.md +0 -189
@@ -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]);
@@ -0,0 +1,148 @@
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]);
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ import { Test, assert, SH } from '@j-o-r/sh'
3
+ import { generateRequest, parseResponse, request } from '../lib/LLMS/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();
64
+ test.add('parse response, create request FAKE ', async () => {
65
+ // Load a fake reponse
66
+ const res = JSON.parse((await SH`cat scenarios/data/tool_oa.json`.run()));
67
+ const prompt = new Prompt();
68
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
69
+ prompt.add('user', 'What is your task?');
70
+ prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
71
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
72
+ const duration = 1500
73
+ await parseResponse(duration, prompt, res, tools);
74
+ const lastMessage = prompt.getLastMessage();
75
+ // console.log(lastMessage);
76
+ const { url, headers, body } = generateRequest(prompt, tools);
77
+ console.log( JSON.stringify(body, null, ' '));
78
+ });
79
+
80
+ // @TODO add tools
81
+ test.add('Basic create request body FAKE', async () => {
82
+ const prompt = new Prompt();
83
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
84
+ prompt.add('user', 'What is your task?');
85
+ // Create simple toolset
86
+ const { url, headers, body } = generateRequest(prompt);
87
+ const res = await doRequest(url, 'POST', headers, body);
88
+ console.log(JSON.stringify(res, null, ' '));
89
+ })
90
+
91
+ test.add('Add a complete toolcall, a real request', async () => {
92
+ const prompt = new Prompt();
93
+ prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
94
+ prompt.add('user', 'What is your task?');
95
+ prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
96
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
97
+ const message = await request(prompt, tools);
98
+ console.log(message);
99
+ })
100
+
101
+
102
+ await test.run([2]);
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ import { assert, Test } from '@j-o-r/sh';
3
+ import Prompt from '../lib/Prompt.js';
4
+
5
+ const isNpm = process.env.npm_lifecycle_event ? true : false;
6
+ const test = new Test(isNpm);
7
+
8
+ test.add('Generic usages', async () => {
9
+ const prompt = new Prompt(6000);
10
+ prompt.add('system', 'systemprompt', true);
11
+ prompt.add('user', 'Hello');
12
+ prompt.add('assistant', 'Hi');
13
+ assert.equal(prompt.length, 3);
14
+ prompt.reset();
15
+ assert.equal(prompt.length, 1);
16
+ });
17
+ test.add('Multimodal', async () => {
18
+ const m = new Prompt(6000);
19
+ assert.equal(m.hasSystemprompt, false, 'Does not have a system prompt');
20
+ m.addMultiModal('system', [{ type: 'text', text: 'This is my sys prompt' }], true)
21
+ assert.equal(m.hasSystemprompt, true, 'Yes, we have');
22
+ m.add('user', 'What is this doing.\nMulti line example\n');
23
+ // Ad a question about an image
24
+ m.addMultiModal('user', [{ type: 'text', text: 'what about this image?' }, { type: 'image_url', url: 'http://www.example.com/image.png' }]);
25
+ assert.equal(m.length, 3, 'We have 2 messages');
26
+ const ar = m.messages;
27
+ const m2 = new Prompt(3000);
28
+ m2.import(ar);
29
+ assert.equal(m2.length, 3, 'We have 3 messages');
30
+ const ar2 = m2.messages;
31
+ // console.log(yam2);
32
+ assert.equal(ar.length, ar2.length);
33
+ assert.equal(m.system_prompt, 'This is my sys prompt');
34
+ });
35
+ test.add('Multimodal errors', async () => {
36
+ const m = new Prompt(4000);
37
+ m.addMultiModal('system', [{ type: 'text', text: 'This is my question' }], true)
38
+ assert.throws(() => {
39
+ // unkown message type 'what'
40
+ m.addMultiModal('user', [{ type: 'text', text: 'This is my question' }, { type: 'what', text: 'This is my question' }]);
41
+ });
42
+ });
43
+
44
+ test.add('Function calls and responses', async () => {
45
+ const prompt = new Prompt(2000);
46
+ prompt.add('system', 'You are an unpolite assistant named Petronela for an administrative office. Respond precise and concise', true);
47
+ prompt.add('user', 'Wat is the temperatuur in Den Haag');
48
+ /** @type {import('../lib/Prompt.js').PRFunctionRequest} */
49
+ const fr = {
50
+ type: 'function_request',
51
+ function_request: {
52
+ name: 'get_current_weather',
53
+ id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
54
+ parameters: "{\"location\":\"Den·Haag\",\"unit\":\"celsius\"}"
55
+ }
56
+ }
57
+ prompt.addMultiModal('assistant', [fr]);
58
+ /** @type {import('../lib/Prompt.js').PRFunctionResponse} */
59
+ const res = {
60
+ type: 'function_response',
61
+ function_response: {
62
+ name: 'get_current_weather',
63
+ id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
64
+ response: "{\"temperature\":24}"
65
+ }
66
+ }
67
+ prompt.addMultiModal('tool', [res]);
68
+ prompt.add('assistant', 'Het is 24 graden Celsius in Den Haag.');
69
+ assert.equal(prompt.length, 5);
70
+ prompt.reset();
71
+ assert.equal(prompt.length, 1);
72
+ });
73
+
74
+ test.add('add records', async () => {
75
+ const prompt = new Prompt();
76
+ /** @type {import('types/Prompt.js').PRRecord} */
77
+ const record = {
78
+ id: 'test 1',
79
+ isoDate: new Date().toISOString(),
80
+ duration: 10,
81
+ model: 'prompt test',
82
+ environment: 'scenario',
83
+ tokensIn: 0,
84
+ tokensOut: 100
85
+ };
86
+ prompt.addRecord(record);
87
+ assert.equal(prompt.records.length, 1);
88
+ const records = prompt.resetRecords();
89
+ assert.equal(prompt.records.length, 0);
90
+ assert.equal(JSON.stringify(record), JSON.stringify(records[0]));
91
+ // register multple records at once
92
+ prompt.addRecords(records);
93
+ assert.equal(prompt.records.length, 1);
94
+ });
95
+
96
+ test.add('invalid record', async () => {
97
+ assert.throws(() => {
98
+ const m = new Prompt();
99
+ // @ts-ignore
100
+ m.addRecord({ id: 'Fake' });
101
+ });
102
+ });
103
+
104
+ test.add('test message Event', () => {
105
+ return new Promise((resolve, _reject) => {
106
+ const prompt = new Prompt(6000);
107
+ prompt.on(prompt.EVENTS.message, (msg) => {
108
+ assert.strictEqual(msg.role, 'system');
109
+ resolve();
110
+ })
111
+ prompt.add('system', 'systemprompt', true);
112
+ })
113
+ })
114
+
115
+ const report = await test.run();
116
+ if (report.errors > 0) {
117
+ process.exit(1);
118
+ }