@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,107 @@
1
+ # xAI Responses API Integration (`lib/API/x.ai/responses.js`)
2
+
3
+ ## Overview
4
+ This module provides a seamless wrapper for the [xAI Responses API](https://docs.x.ai/docs/api-reference#create-new-response) (formerly Grok API), adapted for the hello-dave framework. It integrates directly with `Prompt.js` and `ToolSet.js`, enabling tool-using agents via `AgentManager`.
5
+
6
+ Key adaptations:
7
+ - **Unified Interface**: Uses `Prompt` messages/history for input; parses `output` into assistant/tool responses.
8
+ - **Recursive Tool Calls**: Automatically handles `function_call` → execute tools → `function_call_output` loops (up to `GLOBAL.max_recursive_requests`).
9
+ - **Tool Support**: Converts `ToolSet` to xAI `function` tools; supports native xAI tools like `web_search`, `x_search`.
10
+ - **Reasoning & Search**: Configurable `reasoning.effort` (`low`/`medium`/`high`), `search_parameters`.
11
+ - **Streaming**: Not yet implemented (future).
12
+ - **Auth**: Requires `XAIKEY` env var.
13
+
14
+ Default model: `grok-4-fast-reasoning`. Supports: `grok-4-fast-reasoning`, `grok-4-fast-non-reasoning`, etc.
15
+
16
+ ## Usage in AgentManager
17
+ ```javascript
18
+ import AgentManager from '../lib/AgentManager.js';
19
+
20
+ const agent = new AgentManager({ name: 'weather-agent', secret: 'optional-ws-secret' });
21
+ agent.setup({
22
+ prompt: 'You are a precise weather expert. Use tools for real-time data.',
23
+ api: 'xai',
24
+ options: { model: 'grok-4-fast-reasoning', reasoning: { effort: 'high' } },
25
+ toolsetMode: 'auto', // Adds generic tools like web_search
26
+ contextWindow: 128000
27
+ });
28
+ agent.addGenericToolcall('web_search'); // Optional: Add extras
29
+
30
+ // CLI mode
31
+ agent.start(); // Interactive chat
32
+
33
+ // Or direct call
34
+ const response = await agent.directCall('Weather in Amsterdam today?');
35
+ console.log(response); // Handles search/tools automatically
36
+ ```
37
+
38
+ Under the hood:
39
+ 1. `Prompt.setAdaptor(API.text['xai'], toolset, options)` → uses `responses.request()`.
40
+ 2. Converts history to xAI `input[]` (system/user/assistant/tool).
41
+ 3. POST to `https://api.x.ai/v1/responses`.
42
+ 4. Parses `output` → adds text/reasoning/tools to `Prompt`.
43
+ 5. If tools needed, `ToolSet.execute()` → recurse until complete.
44
+
45
+ ## Options (XAIOptions)
46
+ | Property | Type | Default | Description |
47
+ |----------|------|---------|-------------|
48
+ | `model` | string | `'grok-4-fast-non-reasoning'` | e.g., `'grok-4-fast-reasoning'` |
49
+ | `input` | `XAIInput[]` | `[{role: 'system', content: 'Be precise'}]` | Messages/history |
50
+ | `reasoning.effort` | `'low'\|'medium'\|'high'` | `'medium'` | Reasoning depth |
51
+ | `reasoning.summary` | `'auto'\|'concise'\|'detailed'` | `'auto'` | Reasoning output style |
52
+ | `temperature` | number | `1` (0-2) | Sampling |
53
+ | `parallel_tool_calls` | boolean | `true` | Parallel functions |
54
+ | `tool_choice` | `'auto'` | `'auto'` | Tool selection |
55
+ | `tools` | `XAIFunctionTool[]` | `[]` | From `ToolSet` |
56
+ | `store` | boolean | `false` | Persist response (still bills tokens) |
57
+ | `max_output_tokens` | number | `4000` | Limit |
58
+ | `search_parameters` | object | - | `{max_search_results: 4, mode: 'auto', return_citations: true}` |
59
+
60
+ **Tool Types**:
61
+ - `function`: From `ToolSet` (name, description, parameters JSONSchema).
62
+ - Native: `web_search`, `x_search` (filters: dates, domains, etc.).
63
+
64
+ ## Example Request (Generated Internally)
65
+ ```json
66
+ {
67
+ \"model\": \"grok-4-fast-reasoning\",
68
+ \"input\": [
69
+ {\"role\": \"system\", \"content\": \"You are a precise weather expert.\"},
70
+ {\"role\": \"user\", \"content\": \"Weather in Amsterdam today?\"}
71
+ ],
72
+ \"parallel_tool_calls\": true,
73
+ \"reasoning\": {\"effort\": \"high\"},
74
+ \"search_parameters\": {\"mode\": \"auto\", \"return_citations\": true},
75
+ \"tools\": [{"type\": "function", "name": "web_search", ...}]
76
+ }
77
+ ```
78
+
79
+ ## Example Response (Parsed to Prompt)
80
+ - **Text + Citations**: Added as `assistant` text + `log` annotations (URLs).
81
+ - **Function Calls**: `assistant` with `function_request` → `ToolSet.execute()`.
82
+ - **Reasoning**: Prepended as `reasoning` multimodal text.
83
+
84
+ Sample parsed:
85
+ ```
86
+ Today is [date]. Weather: Cloudy, 5°C... [citations]
87
+ ```
88
+ Tokens: `input_tokens`, `output_tokens` (incl. `reasoning_tokens`) logged in `Prompt.records`.
89
+
90
+ ## Advanced: Custom Tools
91
+ Extend `ToolSet` before `setup()`:
92
+ ```javascript
93
+ const ts = new ToolSet('required');
94
+ ts.add('get_weather', 'Get weather for a location', {
95
+ type: 'object',
96
+ properties: { location: {type: 'string'} },
97
+ required: ['location']
98
+ }, async (params) => `Weather: ${params.location} - 20°C`); // Handler
99
+ agent.setup({ ..., toolsetMode: ts });
100
+ ```
101
+
102
+ ## Errors & Limits
103
+ - `Max recursive calls`: `GLOBAL.max_recursive_requests`.
104
+ - Missing `XAIKEY`: Throws.
105
+ - Invalid last message: Must end in `user`/`tool`.
106
+
107
+ See `lib/API/x.ai/responses.js` source for full JSDoc/types. Cross-links: [Prompt](../prompt-class.md), [ToolSet](../toolset.md), [AgentManager](agent-manager.md) (TBD)."
@@ -0,0 +1,107 @@
1
+ # xAI Responses API Integration (`lib/API/x.ai/responses.js`)
2
+
3
+ ## Overview
4
+ This module provides a seamless wrapper for the [xAI Responses API](https://docs.x.ai/docs/api-reference#create-new-response) (formerly Grok API), adapted for the hello-dave framework. It integrates directly with `Prompt.js` and `ToolSet.js`, enabling tool-using agents via `AgentManager`.
5
+
6
+ Key adaptations:
7
+ - **Unified Interface**: Uses `Prompt` messages/history for input; parses `output` into assistant/tool responses.
8
+ - **Recursive Tool Calls**: Automatically handles `function_call` → execute tools → `function_call_output` loops (up to `GLOBAL.max_recursive_requests`).
9
+ - **Tool Support**: Converts `ToolSet` to xAI `function` tools; supports native xAI tools like `web_search`, `x_search`.
10
+ - **Reasoning & Search**: Configurable `reasoning.effort` (`low`/`medium`/`high`), `search_parameters`.
11
+ - **Streaming**: Not yet implemented (future).
12
+ - **Auth**: Requires `XAIKEY` env var.
13
+
14
+ Default model: `grok-4-fast-reasoning`. Supports: `grok-4-fast-reasoning`, `grok-4-fast-non-reasoning`, etc.
15
+
16
+ ## Usage in AgentManager
17
+ ```javascript
18
+ import AgentManager from '../lib/AgentManager.js';
19
+
20
+ const agent = new AgentManager({ name: 'weatheragent', secret: 'optional-ws-secret' });
21
+ agent.setup({
22
+ prompt: 'You are a precise weather expert. Use tools for real-time data.',
23
+ api: 'xai',
24
+ options: { model: 'grok-4-fast-reasoning', reasoning: { effort: 'high' } },
25
+ toolsetMode: 'auto', // Adds generic tools like web_search
26
+ contextWindow: 128000
27
+ });
28
+ agent.addGenericToolcall('web_search'); // Optional: Add extras
29
+
30
+ // CLI mode
31
+ agent.start(); // Interactive chat
32
+
33
+ // Or direct call
34
+ const response = await agent.directCall('Weather in Amsterdam today?');
35
+ console.log(response); // Handles search/tools automatically
36
+ ```
37
+
38
+ Under the hood:
39
+ 1. `Prompt.setAdaptor(API.text['xai'], toolset, options)` → uses `responses.request()`.
40
+ 2. Converts history to xAI `input[]` (system/user/assistant/tool).
41
+ 3. POST to `https://api.x.ai/v1/responses`.
42
+ 4. Parses `output` → adds text/reasoning/tools to `Prompt`.
43
+ 5. If tools needed, `ToolSet.execute()` → recurse until complete.
44
+
45
+ ## Options (XAIOptions)
46
+ | Property | Type | Default | Description |
47
+ |----------|------|---------|-------------|
48
+ | `model` | string | `'grok-4-fast-non-reasoning'` | e.g., `'grok-4-fast-reasoning'` |
49
+ | `input` | `XAIInput[]` | `[{role: 'system', content: 'Be precise'}]` | Messages/history |
50
+ | `reasoning.effort` | `'low'\|'medium'\|'high'` | `'medium'` | Reasoning depth |
51
+ | `reasoning.summary` | `'auto'\|'concise'\|'detailed'` | `'auto'` | Reasoning output style |
52
+ | `temperature` | number | `1` (0-2) | Sampling |
53
+ | `parallel_tool_calls` | boolean | `true` | Parallel functions |
54
+ | `tool_choice` | `'auto'` | `'auto'` | Tool selection |
55
+ | `tools` | `XAIFunctionTool[]` | `[]` | From `ToolSet` |
56
+ | `store` | boolean | `false` | Persist response (still bills tokens) |
57
+ | `max_output_tokens` | number | `4000` | Limit |
58
+ | `search_parameters` | object | - | `{max_search_results: 4, mode: 'auto', return_citations: true}` |
59
+
60
+ **Tool Types**:
61
+ - `function`: From `ToolSet` (name, description, parameters JSONSchema).
62
+ - Native: `web_search`, `x_search` (filters: dates, domains, etc.).
63
+
64
+ ## Example Request (Generated Internally)
65
+ ```json
66
+ {
67
+ "model": "grok-4-fast-reasoning",
68
+ "input": [
69
+ {"role": "system", "content": "You are a precise weather expert."},
70
+ {"role": "user", "content": "Weather in Amsterdam today?"}
71
+ ],
72
+ "parallel_tool_calls": true,
73
+ "reasoning": {"effort": "high"},
74
+ "search_parameters": {"mode": "auto", "return_citations": true},
75
+ "tools": [{"type": "function", "name": "web_search", ...}]
76
+ }
77
+ ```
78
+
79
+ ## Example Response (Parsed to Prompt)
80
+ - **Text + Citations**: Added as `assistant` text + `log` annotations (URLs).
81
+ - **Function Calls**: `assistant` with `function_request` → `ToolSet.execute()`.
82
+ - **Reasoning**: Prepended as `reasoning` multimodal text.
83
+
84
+ Sample parsed:
85
+ ```
86
+ Today is [date]. Weather: Cloudy, 5°C... [citations]
87
+ ```
88
+ Tokens: `input_tokens`, `output_tokens` (incl. `reasoning_tokens`) logged in `Prompt.records`.
89
+
90
+ ## Advanced: Custom Tools
91
+ Extend `ToolSet` before `setup()`:
92
+ ```javascript
93
+ const ts = new ToolSet('required');
94
+ ts.add('get_weather', 'Get weather for a location', {
95
+ type: 'object',
96
+ properties: { location: {type: 'string'} },
97
+ required: ['location']
98
+ }, async (params) => `Weather: ${params.location} - 20°C`); // Handler
99
+ agent.setup({ ..., toolsetMode: ts });
100
+ ```
101
+
102
+ ## Errors & Limits
103
+ - `Max recursive calls`: `GLOBAL.max_recursive_requests`.
104
+ - Missing `XAIKEY`: Throws.
105
+ - Invalid last message: Must end in `user`/`tool`.
106
+
107
+ See `lib/API/x.ai/responses.js` source for full JSDoc/types. Cross-links: [Prompt](../prompt-class.md), [ToolSet](../toolset.md), [AgentManager](agent-manager.md) (TBD).
@@ -0,0 +1,106 @@
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
+ ```
@@ -0,0 +1,137 @@
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 = 'ask_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
+ const options = { tools: [] };
21
+ options.tools.push({
22
+ type: 'web_search'
23
+ });
24
+ options.tools.push({
25
+ type: 'x_search'
26
+ });
27
+
28
+ if (args['secret']) {
29
+ secret = args['secret'];
30
+ }
31
+ if (args['model'] || true) {
32
+ options.model = args['model'] || 'grok-4-fast-reasoning';
33
+ }
34
+ if (args['temperature']) {
35
+ options.temperature = parseFloat(args['temperature']);
36
+ }
37
+ if (args['tokens']) {
38
+ options.max_output_tokens = parseInt(args['tokens']);
39
+ }
40
+ if (args['top_p']) {
41
+ options.top_p = parseFloat(args['top_p']);
42
+ }
43
+ const reasoning = true;
44
+ if (reasoning) {
45
+ options.reasoning = {
46
+ effort: 'medium',
47
+ summary: 'auto'
48
+ }
49
+ }
50
+ const toolsetMode = 'auto';
51
+ const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
52
+
53
+ function printHelp() {
54
+ console.log(`'${name} --help' You are looking at it.
55
+
56
+ ## USAGE MODES:
57
+
58
+ ### 1. Direct Call (One-Shot, Positional ONLY):
59
+ ./examples/${name}.js "Your query here" [--options]
60
+
61
+ ### 2. Interactive CLI (no positional arg):
62
+ ./examples/${name}.js [--options]
63
+
64
+ ### 3. WS Server (no positional arg):
65
+ ./examples/${name}.js --serve 8080 [--secret mysecret] [--options]
66
+
67
+ ### 4. WS Client (no positional arg):
68
+ ./examples/${name}.js --connect ws://127.0.0.1:8080/ws --secret mysecret [--options]
69
+
70
+ ### 5. Hybrid (Server + Client, no positional arg):
71
+ ./examples/${name}.js --serve 8081 --connect ws://other:8080/ws [--secret ...] [--options]
72
+
73
+ ## SERVER OPTIONS EXPLAINED:
74
+ --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., 'search_agent'). Runs indefinitely until Ctrl+C.
75
+
76
+ --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.
77
+
78
+ --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.
79
+
80
+ Note: Server/Client/Hybrid IGNORES positional input arg (use CLI modes instead). Hybrid: This agent serves AND uses remote tools.
81
+
82
+ ## OPTIONS:
83
+ --model [grok-4-fast-reasoning|...] (default: grok-4-fast-reasoning)
84
+ --temperature [float] (-2 to +2)
85
+ --tokens [number] (max output tokens)
86
+ --top_p [float]
87
+ --context [number] (default: 250000)
88
+
89
+ ## SERVER TOOLS (when no input):
90
+ Exposes as 'search_agent' tool for chaining.
91
+ `);
92
+ process.exit();
93
+ }
94
+
95
+ if (help) {
96
+ printHelp();
97
+ }
98
+
99
+ const tool_call_name = 'search_agent';
100
+ const tool_call_description = `Guide for this smart online AI Agent:
101
+ - query: Formulate ONE efficient, comprehensive search query in natural language, combining multiple sources/subjects/domains; mention optional sources if needed. Avoid multiple queries—consolidate into a single one.`.trim();
102
+
103
+ const prompt = `**CRITICAL: STRICT NO-CODING RULE** - You are a smart search agent. Stick to web_search, x_search, open_link, history_search ONLY. NEVER use or request:
104
+ - Coding tools (javascript_interpreter, execute_bash_script, write_file, read_file, execute_remote_script).
105
+ - Generate or edit code.
106
+ If coding request, decline politely and suggest code_agent.js.
107
+
108
+ 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.
109
+
110
+ Current date: April 01, 2026.`.trim();
111
+
112
+ const agent = new AgentManager({ name, secret });
113
+ agent.setup({
114
+ prompt,
115
+ api,
116
+ options,
117
+ toolsetMode,
118
+ contextWindow
119
+ });
120
+ const toolset = agent.getToolset();
121
+ if (toolset) {
122
+ agent.addGenericToolcall('open_link');
123
+ agent.addGenericToolcall('send_email');
124
+ agent.addGenericToolcall('history_search');
125
+ // Removed conditional coding tools (javascript, bash, ssh) for NO-CODING compliance
126
+ }
127
+
128
+ const cliIntro = `${name} ${options.model}.
129
+ - context: ${contextWindow}
130
+ ${tool_call_name}`.trim();
131
+
132
+ if (input) {
133
+ const RES = await agent.directCall(input);
134
+ console.log(RES);
135
+ } else {
136
+ await agent.start(serve, connect, cliIntro, tool_call_name, tool_call_description);
137
+ }
@@ -0,0 +1,149 @@
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 = 'code_agent';
6
+ const api = 'xai';
7
+ let secret = '';
8
+
9
+ const args = parseArgs();
10
+ const help = args['help'] || false;
11
+ const connect = args['connect'] ? args['connect'] : undefined;
12
+ const serve = args['serve'] ? parseInt(args['serve']) : undefined;
13
+
14
+ /** @type {import('lib/API/x.ai/responses.js').XAIOptions} */
15
+ const options = {
16
+ tools: []
17
+ }
18
+ options.tools.push({
19
+ type: 'web_search'
20
+ });
21
+ if (args['secret']) {
22
+ secret= args['secret'];
23
+ }
24
+ // Set properties only if provided via command line (except model which has default)
25
+ if (args['model'] || true) { // model gets default value
26
+ // @ts-ignore
27
+ options.model = args['model'] || 'grok-4-1-fast-reasoning';
28
+ }
29
+ // if (args['temperature']) {
30
+ options.temperature = 0.2;
31
+ // }
32
+ if (args['tokens']) {
33
+ options.max_output_tokens = parseInt(args['tokens']);
34
+ }
35
+ if (args['top_p']) {
36
+ options.top_p = parseFloat(args['top_p']);
37
+ }
38
+ const reasoning = args['reasoning'] ? args['reasoning'] : 'medium';
39
+ if (reasoning) {
40
+ options.reasoning = {
41
+ // @ts-ignore
42
+ effort:reasoning,
43
+ summary: 'auto'
44
+ }
45
+ }
46
+ const toolsetMode = 'auto';
47
+ const contextWindow = args['context'] ? parseInt(args['context']) : 2565000;
48
+
49
+ function printHelp() {
50
+ console.log(`
51
+ '${name} --help' You are looking at it.
52
+ '
53
+ OPTIONS:
54
+ --tokens [number]: max generated tokens
55
+ --context [number] : truncate message history to context-windows size default 130000
56
+ --temperature [float] : -2 / +2
57
+ --model [string] : model name
58
+ --top_p [float]: number > 0, 0.1 means no top_p
59
+ --reasoning [low|medium|high]
60
+ --tools [javascript,bash,nushell,ssh] comma seperated list
61
+
62
+ SERVER TOOLS:
63
+ --serve [number]: create a Agent server on port number ws://127.0.0.1:[serve]/ws
64
+ --connect [url]: connect to a Server Agent e.g ws://127.0.0.1:8080/ws (https://my.domain/ws) ...
65
+ --secret [string] : limit access to websocket server with a secret
66
+
67
+ `);
68
+ process.exit()
69
+ }
70
+
71
+ if (help) {
72
+ printHelp();
73
+ }
74
+
75
+ const agent = new AgentManager({ name, secret});
76
+ const sys = (await agent.environment()).system;
77
+ const prompt = `
78
+ You are a coding assistant specializing in Bash and JavaScript (ESM/ESNext), with support for other languages. Assist by executing, reading, creating, querying, explaining, or helping with code. Use tools like 'execute_bash_script' for code execution and for writing and reading files, stay in the current working folder. Provide clear, step-by-step responses, examples, and ensure safety compliance.
79
+ ---env
80
+ \${sys}
81
+ ---
82
+
83
+ **MANDATORY MEMORY PROTOCOL (For EVERY query/task - NO EXCEPTIONS):**
84
+
85
+ Connected clients (todo_agent, readme_agent, npm_agent, docs_agent, **memory_agent**) are available as tools. **ALWAYS** use **memory_agent** FIRST and LAST:
86
+
87
+ 1. **RECALL PHASE (Step 1 of EVERY response)**:
88
+ - Call \`memory_agent "Recall relevant memories: tasks, errors, prefs for [keywords from user query]. List recent if empty."\`
89
+ - Incorporate recalled info (e.g., avoid known errors, resume tasks, apply prefs like temp=0.2).
90
+
91
+ 2. **CORE ACTION**:
92
+ - Perform coding assistance (tools: execute_bash_script, javascript_interpreter, read_file/write_file, web_search, etc.).
93
+ - Delegate to specialists if relevant:
94
+ - todo_agent: Tasks/TODO.md
95
+ - readme_agent: README.md
96
+ - npm_agent: NPM modules/package.json
97
+ - docs_agent: Documentation
98
+ - memory_agent: Persistent storage
99
+
100
+ 3. **WRITE PHASE (Step 3 of EVERY response)**:
101
+ - Call \`memory_agent "Store updates: [new tasks/errors/prefs/decisions from this interaction]. E.g., 'Task: [next step]', 'Error: [issue]', 'Pref: [setting]'"\`
102
+ - This ensures persistence across sessions/agents, prevents loops/token burn.
103
+
104
+ **EXAMPLE FLOW**:
105
+ User: "Fix bug in main.js"
106
+ - 1. memory_agent "Recall: tasks errors code bugs main.js"
107
+ - 2. read_file main.js → analyze/fix → write_file
108
+ - 3. memory_agent "Write: Task completed: fixed main.js bug. New task: add tests."
109
+
110
+ **PRIORITIES**:
111
+ - Safety: CWD-only, no escapes, validate before write.
112
+ - Efficiency: Use memories to skip repeats (e.g., "Known error: git conflict → skip").
113
+ - Step-by-step: Clear responses with code blocks.
114
+ - Current date: March 27, 2026.
115
+
116
+ FOLLOW MEMORY PROTOCOL RIGIDLY - it's how multi-agent coordination works!
117
+ `.trim();
118
+ agent.setup({
119
+ prompt,
120
+ api,
121
+ options,
122
+ toolsetMode,
123
+ contextWindow
124
+ });
125
+
126
+ const toolset = agent.getToolset();
127
+ if (toolset) {
128
+ agent.addGenericToolcall('history_search');
129
+ agent.addGenericToolcall('javascript_interpreter');
130
+ agent.addGenericToolcall('execute_bash_script');
131
+ agent.addGenericToolcall('read_file');
132
+ agent.addGenericToolcall('write_file');
133
+
134
+ const addTools = (args['tools']) ? args['tools'].split(',') : [''];
135
+ if (addTools.includes('ssh')) {
136
+ agent.addGenericToolcall('execute_remote_script');
137
+ }
138
+ }
139
+ const cliIntro = `
140
+ ${name} ${options.model}
141
+ - context: ${contextWindow}
142
+ - **Memory Protocol ACTIVE**: Auto-recalls/writes via memory_agent for every query!
143
+ `.trim();
144
+ const description = `
145
+ Main CodeServer hub: Coding expert + delegates to todo/readme/npm/docs/memory agents.
146
+ ALWAYS uses memory_agent for persistent tasks/errors/prefs.
147
+ `.trim();
148
+
149
+ await agent.start(serve, connect, cliIntro, "code_agent", description);