@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,102 +0,0 @@
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]);
@@ -1,118 +0,0 @@
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
- }
@@ -1,76 +0,0 @@
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
- const createText = (text, nr) => {
8
- let result = '';
9
- const len = nr;
10
- let i = 0;
11
- for(;i < len; i++) {
12
- result += `${text} `;
13
- }
14
- return result;
15
- }
16
-
17
- test.add('Create a 500 tokens prompt', async () => {
18
- const prompt = new Prompt(500);
19
- prompt.add('system', createText('system', 50), true); // 0
20
- prompt.add('user', createText('user', 50), true); // 1
21
- prompt.add('assistant', 'yes', true); // 2
22
- prompt.add('user', createText('user2', 50)); // 3
23
- prompt.add('assistant', createText('assistant 2', 100)); // 4
24
- prompt.add('user', createText('user3', 50)); // 5
25
- prompt.add('assistant', createText('assistant 3', 100)); // 6
26
- prompt.add('user', createText('user 4', 50)); // 7
27
- prompt.add('assistant', createText('assistant 4', 100)); // 8
28
- assert.equal(prompt.length, 9);
29
- const reduced = prompt.truncate();
30
- assert.equal(prompt.length, 5);
31
- assert.equal(reduced, true);
32
- assert.equal(prompt.contextLength, 500);
33
- });
34
-
35
-
36
- test.add('Create a 500 tokens prompt with function calls',async () => {
37
- const prompt = new Prompt(500);
38
- prompt.add('system', createText('system', 50), true); // 0
39
- prompt.add('user', createText('user', 50), true); // 1
40
- prompt.add('assistant', 'yes', true); // 2
41
- prompt.add('user', 'Wat is the temperatuur in Den Haag');
42
- /** @type {import('../lib/Prompt.js').PRFunctionRequest} */
43
- const fr = {
44
- type: 'function_request',
45
- function_request: {
46
- name: 'get_current_weather',
47
- id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
48
- parameters: "{\"location\":\"Den·Haag\",\"unit\":\"celsius\"}"
49
- }
50
- }
51
- prompt.addMultiModal('assistant', [fr]);
52
- /** @type {import('../lib/Prompt.js').PRFunctionResponse} */
53
- const res = {
54
- type: 'function_response',
55
- function_response: {
56
- name: 'get_current_weather',
57
- id: 'call_zXFv3espCtpa3zfEu9ElOkJw',
58
- response: "{\"temperature\":24}"
59
- }
60
- }
61
- prompt.addMultiModal('tool', [res]);
62
- prompt.add('assistant', 'Het is 24 graden Celsius in Den Haag.');
63
- prompt.add('user', createText('user2', 50)); // 3
64
- prompt.add('assistant', createText('assistant 2', 100)); // 4
65
- prompt.add('user', createText('user3', 50)); // 5
66
- prompt.add('assistant', createText('assistant 3', 100)); // 6
67
- prompt.add('user', createText('user 4', 50)); // 7
68
- prompt.add('assistant', createText('assistant 4', 100)); // 8
69
- prompt.truncate();
70
- assert.equal(prompt.length, 5);
71
- });
72
-
73
- const report = await test.run();
74
- if (report.errors > 0) {
75
- process.exit(1);
76
- }
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Test, assert } from '@j-o-r/sh'
3
- import {request} from '../lib/API/brave.com/search.js';
4
-
5
- const test = new Test();
6
-
7
- test.add('simple brave search', async () => {
8
- /** @type {import('../lib/search/brave.com/index.js').BRSearchOptions} */
9
- const options = {search_lang: 'nl', summary: 1, count: 3};
10
- const res = await request('What is the most populair behringer synth?', options);
11
- console.log(res);
12
- })
13
-
14
- test.add('extended simple brave search', async () => {
15
- /** @type {import('../lib/search/brave.com/search.js').BRSearchOptions} */
16
- // const options = {
17
- // summary: 1,
18
- // count: 6,
19
- // freshness: 'py',
20
- // result_filter: ''
21
- // }
22
- const res = await request('"openapi doc" "openai response models" API calls');
23
- console.log(res);
24
- })
25
- await test.run([0]);
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- import {SH} from '@j-o-r/sh'; // Note: relative path
3
-
4
-
5
- async function main() {
6
- try {
7
- const res = await SH`node --check bin/dave.js`.run()
8
- console.log(res);
9
- } catch (error) {
10
- console.log('------ error ------');
11
- console.error(error)
12
- }
13
- }
14
-
15
- main();
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
- import wsio from './lib/wsIO.js'; // Note: relative path
3
-
4
- const connectionUrl = 'ws://localhost:8080/ws'; // Your server
5
- const secret = '123'; // Or your secret
6
-
7
- async function main() {
8
- try {
9
- console.log('=== User Input ===');
10
- const inputResp = await wsio(connectionUrl, secret, 'user_request', 'Hello, what is the date?');
11
- console.log(inputResp);
12
-
13
- console.log('\n=== Server Info ===');
14
- const infoResp = await wsio(connectionUrl, secret, 'user_info');
15
- console.log(infoResp);
16
-
17
- console.log('\n=== Reset ===');
18
- const resetResp = await wsio(connectionUrl, secret, 'user_reset');
19
- console.log(resetResp);
20
- } catch (error) {
21
- console.error('Error:', error.message);
22
- process.exit(1);
23
- }
24
- }
25
-
26
- main();
@@ -1,42 +0,0 @@
1
- import ToolSet from '../lib/ToolSet.js'
2
- // Generic TEST toolset
3
- const tools = new ToolSet('auto');
4
- tools.add(
5
- 'get_current_weather', // name
6
- 'Get the current weather in a given location', // desciption
7
- {
8
- type: 'object',
9
- properties: {
10
- location: {
11
- type: 'string',
12
- description: 'The city and country'
13
- }
14
- },
15
- required: ["location"]
16
- },
17
- async (params) => {
18
- if (params.location.trim() === '') {
19
- throw new Error('Missing location.');
20
- // return { records, response };
21
- }
22
- const response = {current_weather:'24 C, Cloudy'};
23
- return response;
24
- }
25
- );
26
- tools.add(
27
- 'get_date_time', // name
28
- 'Get the current date and time', // desciption
29
- {
30
- type: 'object',
31
- properties: {
32
- }
33
- },
34
- async (_params) => {
35
- const response = {
36
- date_time: new Date().toISOString(),
37
- }
38
- return response;
39
- }
40
- );
41
-
42
- export default tools;
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Test , assert} from '@j-o-r/sh'
3
- // import ToolSet from '../lib/ToolSet.js'
4
- import tools from './testToolset.js';
5
- const test = new Test();
6
- test.add('Basic', async () => {
7
- assert.equal(tools.has('get_current_weather'), true);
8
- assert.equal(tools.has('i_am_not_here'), false);
9
- const ob = await tools.call('get_current_weather', { location: 'Den haag' })
10
- assert.equal(ob.current_weather, '24 C, Cloudy')
11
- const list = tools.list();
12
- assert.equal(list.length, 2);
13
- assert.equal(list[0].name, 'get_current_weather');;
14
- });
15
-
16
- await test.run();
@@ -1,141 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Test, assert, jsType } from '@j-o-r/sh';
3
- import ToolSet from '../lib/ToolSet.js';
4
-
5
- const t = new Test();
6
-
7
- // Constructor
8
- t.add('Constructor default auto', () => {
9
- const ts = new ToolSet();
10
- assert.strictEqual(ts.toolChoice, 'auto');
11
- assert.strictEqual(ts.length, 0);
12
- assert.strictEqual(jsType(ts), 'ToolSet');
13
- });
14
-
15
- t.add('Constructor valid choices', () => {
16
- ['auto', 'none', 'required'].forEach(choice => {
17
- const ts = new ToolSet(choice);
18
- assert.strictEqual(ts.toolChoice, choice);
19
- });
20
- });
21
-
22
- t.add('Constructor invalid choice throws', () => {
23
- try {
24
- new ToolSet('invalid');
25
- assert.fail('Should throw on invalid choice');
26
- } catch (e) {
27
- assert.ok(e.message.includes('Tool choice not defined'));
28
- }
29
- });
30
-
31
- // add method
32
- t.add('add invalid name throws', () => {
33
- const ts = new ToolSet();
34
- try {
35
- ts.add('a', 'desc', { type: 'object' }, async () => {});
36
- assert.fail('Should throw invalid name');
37
- } catch (e) {
38
- assert.ok(e.message.includes('Invalid name'));
39
- }
40
- });
41
-
42
- t.add('add valid tool', () => {
43
- const ts = new ToolSet();
44
- const mockMethod = async (params) => ({ received: params });
45
- ts.add('valid_tool', 'Valid tool description', {
46
- type: 'object',
47
- properties: { foo: { type: 'string' } },
48
- required: ['foo']
49
- }, mockMethod);
50
- assert.strictEqual(ts.length, 1);
51
- assert.strictEqual(ts.has('valid_tool'), true);
52
- });
53
-
54
- t.add('add duplicate no throw, overwrites', () => {
55
- const ts = new ToolSet();
56
- const method1 = async () => 'first';
57
- const method2 = async () => 'second';
58
- ts.add('dup', 'desc', { type: 'object' }, method1);
59
- ts.add('dup', 'desc', { type: 'object' }, method2);
60
- assert.strictEqual(ts.length, 1);
61
- const tool = ts.get('dup');
62
- assert.strictEqual(tool.description, 'desc'); // last one
63
- });
64
-
65
- t.add('get throws not found', () => {
66
- const ts = new ToolSet();
67
- try {
68
- ts.get('missing');
69
- assert.fail('Should throw');
70
- } catch (e) {
71
- assert.ok(e.message.includes('Function not found'));
72
- }
73
- });
74
-
75
- t.add('get existing tool', () => {
76
- const ts = new ToolSet();
77
- ts.add('gettool', 'desc', { type: 'object' }, async () => {});
78
- const tool = ts.get('gettool');
79
- assert.strictEqual(jsType(tool), 'Object');
80
- assert.strictEqual(tool.description, 'desc');
81
- assert.strictEqual(jsType(tool.parameters), 'Object');
82
- assert.strictEqual(jsType(tool.method), 'AsyncFunction');
83
- });
84
-
85
- // delete
86
- t.add('delete reduces length', () => {
87
- const ts = new ToolSet();
88
- ts.add('to_delete', 'desc', { type: 'object' }, async () => {});
89
- assert.strictEqual(ts.length, 1);
90
- ts.delete('to_delete');
91
- assert.strictEqual(ts.length, 0);
92
- assert.strictEqual(ts.has('to_delete'), false);
93
- });
94
-
95
- t.add('delete non-existing no error', () => {
96
- const ts = new ToolSet();
97
- ts.delete('nonexistent');
98
- assert.strictEqual(ts.length, 0);
99
- });
100
-
101
- // list
102
- t.add('list empty', () => {
103
- const ts = new ToolSet();
104
- const list = ts.list();
105
- assert.strictEqual(list.length, 0);
106
- assert.strictEqual(jsType(list), 'Array');
107
- });
108
-
109
- t.add('list sorted by name', () => {
110
- const ts = new ToolSet();
111
- ts.add('b_tool', 'b desc', { type: 'object' }, async () => {});
112
- ts.add('a_tool', 'a desc', { type: 'object' }, async () => {});
113
- ts.add('c_tool', 'c desc', { type: 'object' }, async () => {});
114
- const list = ts.list();
115
- assert.strictEqual(list.length, 3);
116
- assert.strictEqual(list[0].name, 'a_tool');
117
- assert.strictEqual(list[1].name, 'b_tool');
118
- assert.strictEqual(list[2].name, 'c_tool');
119
- });
120
-
121
- // call
122
- t.add('call success', async () => {
123
- const ts = new ToolSet();
124
- const expected = { result: 42 };
125
- ts.add('calc', 'calc', { type: 'object' }, async () => expected);
126
- const res = await ts.call('calc', {});
127
- assert.deepStrictEqual(res, expected);
128
- });
129
-
130
- t.add('call not found throws', async () => {
131
- const ts = new ToolSet();
132
- try {
133
- await ts.call('missing', {});
134
- assert.fail('Should throw');
135
- } catch (e) {
136
- assert.ok(e.message.includes('Function not found'));
137
- }
138
- });
139
-
140
- const report = await t.run();
141
- process.exit(report.errors > 0 ? 1 : 0);