@j-o-r/hello-dave 0.0.4 → 0.0.6

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 (107) hide show
  1. package/CHANGELOG.md +35 -17
  2. package/bin/dave.js +105 -74
  3. package/examples/gpt_agent.js +3 -6
  4. package/examples/memory_agent.js +134 -23
  5. package/examples/test_agent.js +0 -2
  6. package/lib/ToolSet.js +4 -1
  7. package/lib/genericToolset.js +4 -88
  8. package/lib/index.js +5 -1
  9. package/lib/wsIO.js +1 -11
  10. package/package.json +4 -4
  11. package/types/index.d.ts +3 -1
  12. package/README.md +0 -492
  13. package/README.md.backup +0 -269
  14. package/README.md.bak +0 -481
  15. package/README.md.bak.1774780058 +0 -338
  16. package/README.md.bak2 +0 -455
  17. package/docs.bak.1774780058/agent-manager.md +0 -167
  18. package/docs.bak.1774780058/agent-manager.md.bak +0 -137
  19. package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
  20. package/docs.bak.1774780058/codeserver-pattern.md +0 -191
  21. package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
  22. package/docs.bak.1774780058/project-overview.md +0 -67
  23. package/docs.bak.1774780058/project-overview.md.bak +0 -67
  24. package/docs.bak.1774780058/prompt-class.md +0 -141
  25. package/docs.bak.1774780058/prompt-class.md.bak +0 -142
  26. package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
  27. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
  28. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
  29. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
  30. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
  31. package/docs.bak.1774780058/toolset.md +0 -164
  32. package/docs.bak.1774780058/toolset.md.bak +0 -94
  33. package/docs.bak.1774780058/toolset.md.bak3 +0 -161
  34. package/docs.bak.1774780058/toolset.md.bak4 +0 -161
  35. package/docs.bak.1774780058/toolset.md.bak5 +0 -161
  36. package/docs.bak.1774780058/toolset.md.bak6 +0 -163
  37. package/docs.bak.1774780058/toolset.md.bak_path +0 -163
  38. package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
  39. package/docs.bak.1774780058/xai-responses.md +0 -111
  40. package/docs.bak.1774780058/xai-responses.md.bak +0 -107
  41. package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
  42. package/docs.bak.1774780058/xai_collections.md +0 -106
  43. package/examples/coderev_agent.js +0 -136
  44. package/examples/grok_agent.js.bak +0 -98
  45. package/examples/grok_agent.js.bak.2 +0 -99
  46. package/examples/grok_agent.js.bak.3 +0 -1
  47. package/examples/grok_agent.js.bak.4 +0 -124
  48. package/examples/grok_agent.js.bak.5 +0 -1
  49. package/examples/grok_agent.js.bak.6 +0 -1
  50. package/examples/npm_agent.js.bak.3 +0 -2
  51. package/examples/npm_agent.js.bak.4 +0 -205
  52. package/examples/npm_agent.js.bak.5 +0 -1
  53. package/examples/npm_agent.js.bak.6 +0 -1
  54. package/examples.bak.1774780058/ask_agent.js +0 -114
  55. package/examples.bak.1774780058/code_agent.js +0 -149
  56. package/examples.bak.1774780058/coderev_agent.js +0 -72
  57. package/examples.bak.1774780058/codeserver.sh +0 -47
  58. package/examples.bak.1774780058/daisy_agent.js +0 -177
  59. package/examples.bak.1774780058/docs_agent.js +0 -119
  60. package/examples.bak.1774780058/gpt_agent.js +0 -109
  61. package/examples.bak.1774780058/grok_agent.js +0 -98
  62. package/examples.bak.1774780058/memory_agent.js +0 -112
  63. package/examples.bak.1774780058/npm_agent.js +0 -175
  64. package/examples.bak.1774780058/prompt_agent.js +0 -112
  65. package/examples.bak.1774780058/readme_agent.js +0 -144
  66. package/examples.bak.1774780058/spawn_agent.js +0 -263
  67. package/examples.bak.1774780058/test_agent.js +0 -162
  68. package/examples.bak.1774780058/todo_agent.js +0 -138
  69. package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
  70. package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
  71. package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
  72. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
  73. package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
  74. package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
  75. package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
  76. package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
  77. package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
  78. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
  79. package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
  80. package/scenarios.bak.1774780058/environment.js +0 -10
  81. package/scenarios.bak.1774780058/example.js +0 -17
  82. package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
  83. package/scenarios.bak.1774780058/grok.js +0 -113
  84. package/scenarios.bak.1774780058/memory-tools.js +0 -51
  85. package/scenarios.bak.1774780058/openai-o3.js +0 -137
  86. package/scenarios.bak.1774780058/openai-prompt.js +0 -155
  87. package/scenarios.bak.1774780058/openai-session.js +0 -148
  88. package/scenarios.bak.1774780058/openai.js +0 -102
  89. package/scenarios.bak.1774780058/prompt.js +0 -118
  90. package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
  91. package/scenarios.bak.1774780058/search.brave.com.js +0 -25
  92. package/scenarios.bak.1774780058/sh.js +0 -15
  93. package/scenarios.bak.1774780058/test-wsio.js +0 -26
  94. package/scenarios.bak.1774780058/testToolset.js +0 -42
  95. package/scenarios.bak.1774780058/toolset.js +0 -16
  96. package/scenarios.bak.1774780058/toolset.test.js +0 -141
  97. package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
  98. package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
  99. package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
  100. package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
  101. package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
  102. package/scenarios.bak.1774780058/wsClient.js +0 -69
  103. package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
  104. package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
  105. package/scenarios.bak.1774780058/xaicoll.js +0 -50
  106. package/scenarios.bak.1774780058/xaifiles.js +0 -48
  107. /package/{examples → bin}/spawn_agent.js +0 -0
@@ -1,106 +0,0 @@
1
- [x.ai collections](https://docs.x.ai/docs/guides/using-collections/api)
2
-
3
-
4
- Creating a collection:
5
-
6
- ```bash
7
- curl https://management-api.x.ai/v1/collections \
8
- -X POST \
9
- -H "Content-Type: application/json" \
10
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY" \
11
- -d '{"collection_name": "SEC Filings"}'
12
- ```
13
-
14
- Listing collections:
15
- ```bash
16
- curl https://management-api.x.ai/v1/collections \
17
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
18
- ```
19
-
20
- Viewing collection configuration:
21
- ```bash
22
- 'curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d \
23
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
24
- ```
25
-
26
- Updating collection configuration
27
- ```bash
28
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d \
29
- -X PUT \
30
- -H "Content-Type: application/json" \
31
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY" \
32
- -d '{"collection_name": "SEC Filings (New)"}'
33
- ```
34
-
35
- Uploading documents:
36
-
37
- ```bash
38
- # Step 1: Upload file
39
- curl https://api.x.ai/v1/files \
40
- -H "Authorization: Bearer $XAI_API_KEY" \
41
- -F file=@tesla-20241231.html
42
-
43
- # Step 2: Add file to collection (use file_id from step 1)
44
- curl -X POST https://management-api.x.ai/v1/collections/$COLLECTION_ID/documents/$FILE_ID \
45
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
46
-
47
- ```
48
-
49
- Uploading with metadata fields
50
-
51
- ```bash
52
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d/documents \
53
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY" \
54
- -F "name=paper.pdf" \
55
- -F "data=@paper.pdf" \
56
- -F "content_type=application/pdf" \
57
- -F 'fields={"author": "Sandra Kim", "year": "2024", "title": "Q3 Revenue Analysis"}'
58
-
59
- ```
60
-
61
- Searching documents
62
-
63
- ```bash
64
- curl https://api.x.ai/v1/documents/search \
65
- -H "Content-Type: application/json" \
66
- -H "Authorization: Bearer $XAI_API_KEY" \
67
- -d '{
68
- "query": "What were the key revenue drivers based on the SEC filings?",
69
- "source": {
70
- "collection_ids": ["collection_dbc087b1-6c99-493d-86c6-b401fee34a9d"]
71
- }
72
- }'
73
- ```
74
-
75
- ```bash
76
- curl https://api.x.ai/v1/documents/search \
77
- -H "Content-Type: application/json" \
78
- -H "Authorization: Bearer $XAI_API_KEY" \
79
- -d '{
80
- "query": "What were the key revenue drivers based on the SEC filings?",
81
- "source": {
82
- "collection_ids": [
83
- "collection_dbc087b1-6c99-493d-86c6-b401fee34a9d"
84
- ]
85
- },
86
- "retrieval_mode": {"type": "hybrid"}
87
- }'
88
- ```
89
-
90
-
91
- Deleting a document:
92
-
93
- ```bash
94
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d/documents/file_55a709d4-8edc-4f83-84d9-9f04fe49f832 \
95
- -X DELETE \
96
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
97
-
98
- ```
99
-
100
- Deleting a collection
101
-
102
- ```bash
103
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d \
104
- -X DELETE \
105
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
106
- ```
@@ -1,136 +0,0 @@
1
- #!/usr/bin/env node
2
- import { AgentManager } from '@j-o-r/hello-dave';
3
- import { parseArgs } from '@j-o-r/sh';
4
-
5
- const name = 'coderev_agent';
6
- const api = 'xai';
7
- let secret = '';
8
-
9
- const args = parseArgs();
10
-
11
- let input;
12
- if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
13
- input = args._[0].trim();
14
- }
15
-
16
- const help = args['help'] || false;
17
- const connect = args['connect'] ? args['connect'] : undefined;
18
- const serve = args['serve'] ? parseInt(args['serve']) : undefined;
19
-
20
- /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
21
- const options = { tools: [] };
22
- options.tools.push({
23
- type: 'web_search'
24
- });
25
-
26
- if (args['secret']) {
27
- secret = args['secret'];
28
- }
29
- if (args['model'] || true) {
30
- options.model = args['model'] || 'grok-4-fast-reasoning';
31
- }
32
- if (args['temperature']) {
33
- options.temperature = parseFloat(args['temperature']);
34
- }
35
- if (args['tokens']) {
36
- options.max_output_tokens = parseInt(args['tokens']);
37
- }
38
- if (args['top_p']) {
39
- options.top_p = parseFloat(args['top_p']);
40
- }
41
- const reasoning = true;
42
- if (reasoning) {
43
- options.reasoning = {
44
- effort: 'medium',
45
- summary: 'auto'
46
- }
47
- }
48
- const toolsetMode = 'auto';
49
- const contextWindow = args['context'] ? parseInt(args['context']) : 500000;
50
-
51
- function printHelp() {
52
- console.log(`
53
- '${name} --help' You are looking at it.
54
-
55
- ## USAGE MODES:
56
-
57
- ### 1. Direct Call (One-Shot, Positional ONLY):
58
- ./examples/${name}.js "Paste git diff here" [--options]
59
-
60
- ### 2. Interactive CLI (no positional arg):
61
- ./examples/${name}.js [--options]
62
-
63
- ### 3. WS Server (no positional arg):
64
- ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
65
-
66
- ### 4. WS Client (no positional arg):
67
- ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
68
-
69
- ### 5. Hybrid (Server + Client, no positional arg):
70
- ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
71
-
72
- ## SERVER OPTIONS EXPLAINED:
73
- --serve [port]: Starts WebSocket SERVER at ws://127.0.0.1:[port]/ws. Allows other agents (--connect) to connect and use this agent as a remote TOOL (e.g., 'coderev_agent'). Runs indefinitely until Ctrl+C.
74
-
75
- --connect [ws_url]: Connects as CLIENT to remote WS server at [ws_url] (e.g., ws://127.0.0.1:8080/ws). Gains access to remote agent's tools. Interactive CLI available.
76
-
77
- --secret [string]: SHARED AUTH TOKEN (min 3 chars). SERVER rejects clients without matching --secret. CLIENTS must provide server's secret to connect. Use same secret for chains.
78
-
79
- Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
80
-
81
- ## OPTIONS:
82
- --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
83
- --temperature [float] (-2 to +2)
84
- --tokens [number] (max output tokens)
85
- --top_p [float]
86
- --context [number] (default: 500000)
87
-
88
- ## SERVER TOOLS (when no input):
89
- Exposes as 'coderev_agent' tool for chaining.
90
- `);
91
- process.exit();
92
- }
93
-
94
- if (help) {
95
- printHelp();
96
- }
97
-
98
- const tool_call_name = 'coderev_agent';
99
- const tool_call_description = `
100
- Git diff analyzer. Supports WS chaining.
101
- `.trim();
102
-
103
- const prompt = `
104
- You are coderev, a Git diff analyzer.
105
-
106
- Analyze git diffs provided in queries, review code changes for bugs, improvements, best practices, security issues, and provide actionable suggestions. Use read_file to access specific files, execute_bash_script for git commands or other shell tasks, and web_search for looking up coding standards or references if needed. Be thorough, constructive, and reference specific lines in diffs when possible.
107
-
108
- Respond in a structured format: Summary, Issues Found, Suggestions, Overall Rating (1-10).
109
- `.trim();
110
-
111
- const agent = new AgentManager({ name, secret });
112
- agent.setup({
113
- prompt,
114
- api,
115
- options,
116
- toolsetMode,
117
- contextWindow
118
- });
119
- const toolset = agent.getToolset();
120
- if (toolset) {
121
- agent.addGenericToolcall('read_file');
122
- agent.addGenericToolcall('execute_bash_script');
123
- }
124
-
125
- const cliIntro = `
126
- ${name} ${options.model}.
127
- - context: ${contextWindow}
128
- ${tool_call_name}
129
- `.trim();
130
-
131
- if (input) {
132
- const RES = await agent.directCall(input);
133
- console.log(RES);
134
- } else {
135
- await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
136
- }
@@ -1,98 +0,0 @@
1
- #!/usr/bin/env node
2
- /*
3
- * ONE SHOT , direct call example
4
- * ```bash
5
- * echo "What is your task?" | examples/grok.js
6
- * ```
7
- */
8
- import { AgentManager } from '@j-o-r/hello-dave';
9
- import { parseArgs, readIn } from '@j-o-r/sh';
10
-
11
- const name = 'ask_grok';
12
- const api = 'xai';
13
- let secret = '';
14
-
15
- const input = await readIn();
16
- const args = parseArgs();
17
- const help = args['help'] || false;
18
-
19
- /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
20
- const options = {
21
- tools: []
22
- }
23
- options.tools.push({
24
- type: 'web_search'
25
- });
26
- options.tools.push({
27
- type: 'x_search'
28
- });
29
-
30
- // Set properties only if provided via command line (except model which has default)
31
- if (args['model'] || true) { // model gets default value
32
- // @ts-ignore || grok-4-1-fast-non-reasoning
33
- options.model = args['model'] || 'grok-4.20-multi-agent-0309';
34
- }
35
- if (args['temperature']) {
36
- options.temperature = parseFloat(args['temperature']);
37
- }
38
- if (args['tokens']) {
39
- options.max_output_tokens = parseInt(args['tokens']);
40
- }
41
- if (args['top_p']) {
42
- options.top_p = parseFloat(args['top_p']);
43
- }
44
- const reasoning = true // args['reasoning'] ? args['reasoning'] : null;
45
- if (reasoning) {
46
- options.reasoning = {
47
- effort: 'medium',
48
- summary: 'auto'
49
- }
50
- }
51
- // Large context on grok-4-fast
52
- const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
53
- const toolsetMode = 'auto';
54
-
55
- function printHelp() {
56
- console.log(`
57
- '${name} --help' You are looking at it.
58
- '
59
- OPTIONS:
60
- --tokens [number]: max generated tokens
61
- --context [number] : truncate message history to context-windows size default 130000
62
- --temperature [float] : -2 / +2
63
- --model ['grok-4-1-fast-reasoning'|'grok-4-1-fast-non-reasoning'|'grok-code-fast-1'|'grok-4-fast-reasoning'|'grok-4-fast-non-reasoning']
64
- --top_p [float]: number > 0, 0.1 means no top_p
65
- --reasoning [low|high]
66
-
67
- USAGE:
68
-
69
- \`\`\`bash
70
- echo "What is ..." | grok.js
71
- \`\`\`
72
-
73
- `);
74
- process.exit()
75
- }
76
- if (help) {
77
- printHelp();
78
- }
79
-
80
- if (!input || input.trim() === '') {
81
- printHelp();
82
- }
83
-
84
- const prompt = `
85
- Respond briefly and directly, using minimal words. Reason step-by-step first. Focus solely on core point; avoid elaboration or follow-ups. If unclear, ask clarifying questions before proceeding.
86
- `.trim();
87
-
88
- const agent = new AgentManager({ name, secret });
89
- agent.setup({
90
- prompt,
91
- api,
92
- options,
93
- toolsetMode,
94
- contextWindow
95
- });
96
-
97
- const res = await agent.directCall(input);
98
- console.log(res);
@@ -1,99 +0,0 @@
1
- # Backup of current grok_agent.js before fix
2
- #!/usr/bin/env node
3
- /*
4
- * ONE SHOT , direct call example
5
- * ```bash
6
- * echo \"What is your task?\" | examples/grok_agent.js
7
- * ```
8
- */
9
- import { AgentManager } from '@j-o-r/hello-dave';
10
- import { parseArgs, readIn } from '@j-o-r/sh';
11
-
12
- const name = 'grok_agent';
13
- const api = 'xai';
14
- let secret = '';
15
-
16
- const input = await readIn();
17
- const args = parseArgs();
18
- const help = args['help'] || false;
19
-
20
- /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
21
- const options = {
22
- tools: []
23
- }
24
- options.tools.push({
25
- type: 'web_search'
26
- });
27
- options.tools.push({
28
- type: 'x_search'
29
- });
30
-
31
- // Set properties only if provided via command line (except model which has default)
32
- if (args['model'] || true) { // model gets default value
33
- // @ts-ignore || grok-4-1-fast-non-reasoning
34
- options.model = args['model'] || 'grok-4.20-multi-agent-0309';
35
- }
36
- if (args['temperature']) {
37
- options.temperature = parseFloat(args['temperature']);
38
- }
39
- if (args['tokens']) {
40
- options.max_output_tokens = parseInt(args['tokens']);
41
- }
42
- if (args['top_p']) {
43
- options.top_p = parseFloat(args['top_p']);
44
- }
45
- const reasoning = true // args['reasoning'] ? args['reasoning'] : null;
46
- if (reasoning) {
47
- options.reasoning = {
48
- effort: 'medium',
49
- summary: 'auto'
50
- }
51
- }
52
- // Large context on grok-4-fast
53
- const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
54
- const toolsetMode = 'auto';
55
-
56
- function printHelp() {
57
- console.log(`
58
- '${name} --help' You are looking at it.
59
- '
60
- OPTIONS:
61
- --tokens [number]: max generated tokens
62
- --context [number] : truncate message history to context-windows size default 130000
63
- --temperature [float] : -2 / +2
64
- --model ['grok-4-1-fast-reasoning'|'grok-4-1-fast-non-reasoning'|'grok-code-fast-1'|'grok-4-fast-reasoning'|'grok-4-fast-non-reasoning']
65
- --top_p [float]: number > 0, 0.1 means no top_p
66
- --reasoning [low|high]
67
-
68
- USAGE:
69
-
70
- \`\`\`bash
71
- echo \"What is ...\" | grok_agent.js
72
- \`\`\`
73
-
74
- `);
75
- process.exit()
76
- }
77
- if (help) {
78
- printHelp();
79
- }
80
-
81
- if (!input || input.trim() === '') {
82
- printHelp();
83
- }
84
-
85
- const prompt = `
86
- Respond briefly and directly, using minimal words. Reason step-by-step first. Focus solely on core point; avoid elaboration or follow-ups. If unclear, ask clarifying questions before proceeding.
87
- `.trim();
88
-
89
- const agent = new AgentManager({ name, secret });
90
- agent.setup({
91
- prompt,
92
- api,
93
- options,
94
- toolsetMode,
95
- contextWindow
96
- });
97
-
98
- const res = await agent.directCall(input);
99
- console.log(res);
@@ -1 +0,0 @@
1
- # Full backup of grok_agent.js before printHelp clarity update
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env node
2
- /*
3
- * Full modes: Direct call (one-shot), CLI interactive, WS Server (--serve), Client (--connect).
4
- * Direct: grok_agent.js "What is your task?"
5
- * Pipe/Stdin: echo "What is your task?" | grok_agent.js
6
- * CLI: grok_agent.js
7
- * Server: grok_agent.js --serve 8080
8
- */
9
- import { AgentManager } from '@j-o-r/hello-dave';
10
- import { parseArgs } from '@j-o-r/sh';
11
-
12
- const name = 'grok_agent';
13
- const api = 'xai';
14
- let secret = '';
15
-
16
- let input; // Directcall input (positional or fallback to readIn for pipe)
17
- const args = parseArgs();
18
-
19
- if (args._.length === 1 && typeof args._[0] === 'string' && args._[0].trim() !== '') {
20
- input = args._[0].trim();
21
- } else {
22
- // Fallback for piped stdin (async readIn)
23
- const { readIn } = await import('@j-o-r/sh');
24
- input = await readIn();
25
- }
26
-
27
- const help = args['help'] || false;
28
- const connect = args['connect'] ? args['connect'] : undefined;
29
- const serve = args['serve'] ? parseInt(args['serve']) : undefined;
30
-
31
- /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
32
- const options = { tools: [] };
33
- options.tools.push({
34
- type: 'web_search'
35
- });
36
- options.tools.push({
37
- type: 'x_search'
38
- });
39
-
40
- if (args['secret']) {
41
- secret = args['secret'];
42
- }
43
- if (args['model'] || true) {
44
- options.model = args['model'] || 'grok-4-fast-reasoning';
45
- }
46
- if (args['temperature']) {
47
- options.temperature = parseFloat(args['temperature']);
48
- }
49
- if (args['tokens']) {
50
- options.max_output_tokens = parseInt(args['tokens']);
51
- }
52
- if (args['top_p']) {
53
- options.top_p = parseFloat(args['top_p']);
54
- }
55
- const reasoning = true;
56
- if (reasoning) {
57
- options.reasoning = {
58
- effort: 'medium',
59
- summary: 'auto'
60
- }
61
- }
62
- const toolsetMode = 'auto';
63
- const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
64
-
65
- function printHelp() {
66
- console.log(`
67
- '${name} --help' You are looking at it.
68
-
69
- ## Direct call mode, one shot:
70
- grok_agent.js "What is your task?" --[options]
71
- echo "What is your task?" | grok_agent.js
72
-
73
- ## Cli mode (interactive)
74
- grok_agent.js --[options]
75
-
76
- ## SERVER TOOLS (server mode): (only when no input is provided)
77
- --serve [number]: create a Agent server on port number ws://127.0.0.1:[serve]/ws
78
- --connect [url]: connect to a Server Agent e.g ws://127.0.0.1:8080/ws (https://my.domain/ws) ...
79
- --secret [string] : limit access to websocket server with a secret
80
-
81
- OPTIONS:
82
- --tokens [number]: max generated tokens
83
- --context [number] : truncate message history to context-windows size default 250000
84
- --temperature [float] : -2 / +2
85
- --model [grok-4-fast-reasoning|grok-beta|...]
86
- --top_p [float]: number > 0, 0.1 means no top_p
87
- --reasoning
88
- `);
89
- process.exit()
90
- }
91
-
92
- if (help) {
93
- printHelp();
94
- }
95
-
96
- if (!input || input.trim() === '') {
97
- printHelp();
98
- }
99
-
100
- const prompt = `
101
- Respond briefly and directly, using minimal words. Reason step-by-step first. Focus solely on core point; avoid elaboration or follow-ups. If unclear, ask clarifying questions before proceeding.
102
- `.trim();
103
-
104
- const agent = new AgentManager({ name, secret });
105
- agent.setup({
106
- prompt,
107
- api,
108
- options,
109
- toolsetMode,
110
- contextWindow
111
- });
112
-
113
- const cliIntro = `
114
- ${name} ${options.model}.
115
- - context: ${contextWindow}. Tools: web_search, x_search.
116
- Brief responder ready for CLI/Server/Client modes.
117
- `.trim();
118
-
119
- if (input) {
120
- const RES = await agent.directCall(input);
121
- console.log(RES);
122
- } else {
123
- await agent.start(serve, connect, cliIntro);
124
- }
@@ -1 +0,0 @@
1
- Full backup before CLI no-args fix
@@ -1 +0,0 @@
1
- # Backup before adding serve/connect/secret explanations to printHelp
@@ -1,2 +0,0 @@
1
- # Full backup of npm_agent.js before printHelp clarity update + stdin fallback
2
- [Full original content here - omitted for brevity, but would paste the read content]