@j-o-r/hello-dave 0.1.0 → 0.1.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 (173) hide show
  1. package/CHANGELOG.md +42 -25
  2. package/README.md +81 -221
  3. package/TODO.md +173 -35
  4. package/agents/agent_creator.js +105 -0
  5. package/agents/agent_creator.prompt.md +371 -0
  6. package/agents/ask_agent.js +64 -127
  7. package/agents/claude_agent.js +68 -0
  8. package/agents/code_agent.js +55 -135
  9. package/agents/code_agent.prompt.md +50 -0
  10. package/agents/echo_agent.js +76 -0
  11. package/agents/financial_expert.js +75 -0
  12. package/agents/gpt_agent.js +52 -103
  13. package/agents/gpt_code.js +81 -0
  14. package/agents/grok_agent.js +58 -114
  15. package/agents/minimax_agent.js +92 -0
  16. package/agents/mureka_agent.js +77 -0
  17. package/agents/planner_agent.js +172 -0
  18. package/agents/stability_agent.js +87 -0
  19. package/agents/test_agent.js +75 -157
  20. package/agents/weather_agent.js +73 -0
  21. package/agents/workflow_agent.js +189 -0
  22. package/bin/dave.js +436 -184
  23. package/docs/bin-dave.md +85 -35
  24. package/docs/cdn-ssh.md +100 -0
  25. package/docs/creating-agents.md +301 -0
  26. package/docs/creating-toolsets.md +336 -0
  27. package/docs/docs-organization.md +48 -0
  28. package/docs/project-overview.md +86 -51
  29. package/lib/API/elevenlabs.io/music.compose.md +441 -0
  30. package/lib/API/elevenlabs.io/music.create-composition-plan.md +370 -0
  31. package/lib/API/elevenlabs.io/music.stream.md +425 -0
  32. package/lib/API/lalal.ai/lalal.js +445 -0
  33. package/lib/API/lalal.ai/openapi.json +2614 -0
  34. package/lib/API/minimax/ImageToolset.js +82 -37
  35. package/lib/API/minimax/MusicToolset.js +125 -79
  36. package/lib/API/minimax/VideoToolset.js +170 -167
  37. package/lib/API/minimax/image.js +5 -1
  38. package/lib/API/minimax/music.js +210 -23
  39. package/lib/API/minimax/video.js +242 -53
  40. package/lib/API/mureka/MusicToolset.js +646 -0
  41. package/lib/API/mureka/README.md +41 -0
  42. package/lib/API/mureka/index.js +7 -0
  43. package/lib/API/mureka/music.js +658 -0
  44. package/lib/API/openai.com/index.js +7 -0
  45. package/lib/API/openai.com/{reponses/text.js → responses.js} +64 -18
  46. package/lib/API/openai.com/video.create.character.md +40 -0
  47. package/lib/API/openai.com/video.create.md +219 -0
  48. package/lib/API/openai.com/video.delete.md +44 -0
  49. package/lib/API/openai.com/video.download.md +31 -0
  50. package/lib/API/openai.com/video.edit.md +155 -0
  51. package/lib/API/openai.com/video.extend.md +166 -0
  52. package/lib/API/openai.com/video.fetch.character.md +43 -0
  53. package/lib/API/openai.com/video.js +784 -0
  54. package/lib/API/openai.com/video.list.md +201 -0
  55. package/lib/API/openai.com/video.remix.md +175 -0
  56. package/lib/API/openai.com/video.retrieve.md +139 -0
  57. package/lib/API/openai.com/videoToolset.js +616 -0
  58. package/lib/API/stability.ai/ImageToolset.js +131 -40
  59. package/lib/API/stability.ai/MusicToolset.js +79 -47
  60. package/lib/API/stability.ai/audio.js +63 -131
  61. package/lib/API/x.ai/chat.responses.md +1040 -0
  62. package/lib/API/x.ai/image.js +229 -59
  63. package/lib/API/x.ai/imageToolset.js +376 -0
  64. package/lib/API/x.ai/index.js +1 -3
  65. package/lib/API/x.ai/responses.js +9 -18
  66. package/lib/Agent.js +271 -0
  67. package/lib/Agent.js.old +284 -0
  68. package/lib/AgentLauncher.js +562 -0
  69. package/lib/Cli.js +87 -13
  70. package/lib/Prompt.js +23 -1
  71. package/lib/Session.js +5 -4
  72. package/lib/ToolSet.js +102 -6
  73. package/lib/agentLoader.js +369 -0
  74. package/lib/cdn.js +67 -231
  75. package/lib/{CdnToolset.js → cdnToolset.js} +47 -64
  76. package/lib/defaultToolsets.js +43 -0
  77. package/lib/fafs.js +1 -1
  78. package/lib/genericToolset.js +442 -119
  79. package/lib/handOffToolset.js +179 -0
  80. package/lib/index.js +34 -27
  81. package/lib/toolsetLoader.js +248 -0
  82. package/package.json +11 -5
  83. package/types/API/lalal.ai/lalal.d.ts +116 -0
  84. package/types/API/minimax/image.d.ts +2 -1
  85. package/types/API/minimax/music.d.ts +189 -26
  86. package/types/API/minimax/video.d.ts +100 -31
  87. package/types/API/mureka/index.d.ts +7 -0
  88. package/types/API/mureka/music.d.ts +472 -0
  89. package/types/API/openai.com/index.d.ts +7 -0
  90. package/types/API/openai.com/{reponses/text.d.ts → responses.d.ts} +11 -11
  91. package/types/API/openai.com/video.d.ts +409 -0
  92. package/types/API/openai.com/videoToolset.d.ts +24 -0
  93. package/types/API/stability.ai/audio.d.ts +14 -103
  94. package/types/API/stability.ai/image.d.ts +2 -2
  95. package/types/API/x.ai/image.d.ts +138 -26
  96. package/types/API/x.ai/imageToolset.d.ts +3 -0
  97. package/types/API/x.ai/index.d.ts +1 -3
  98. package/types/API/x.ai/responses.d.ts +4 -4
  99. package/types/Agent.d.ts +123 -0
  100. package/types/AgentLauncher.d.ts +222 -0
  101. package/types/Cli.d.ts +28 -8
  102. package/types/Prompt.d.ts +23 -5
  103. package/types/Session.d.ts +1 -1
  104. package/types/ToolSet.d.ts +10 -0
  105. package/types/agentLoader.d.ts +78 -0
  106. package/types/cdn.d.ts +15 -90
  107. package/types/defaultToolsets.d.ts +9 -0
  108. package/types/fafs.d.ts +1 -1
  109. package/types/genericToolset.d.ts +1 -1
  110. package/types/handOffToolset.d.ts +28 -0
  111. package/types/index.d.ts +19 -16
  112. package/types/toolsetLoader.d.ts +114 -0
  113. package/utils/format_log.js +101 -23
  114. package/utils/launch_agent.js +18 -0
  115. package/utils/list_sessions.sh +13 -5
  116. package/utils/search_sessions.sh +65 -29
  117. package/utils/toolsets.js +33 -0
  118. package/README.md.bak.1779452127 +0 -240
  119. package/agents/codeserver.sh +0 -47
  120. package/agents/daisy_agent.js +0 -173
  121. package/agents/docs_agent.js +0 -148
  122. package/agents/memory_agent.js +0 -263
  123. package/agents/minimax.js +0 -173
  124. package/agents/npm_agent.js +0 -202
  125. package/agents/prompt_agent.js +0 -133
  126. package/agents/readme_agent.js +0 -148
  127. package/agents/spawn_agent.js +0 -160
  128. package/agents/stability.js +0 -173
  129. package/agents/todo_agent.js +0 -175
  130. package/bin/codeDave +0 -58
  131. package/docs/agent-dave-websocket-protocol.md +0 -180
  132. package/docs/agent-manager.md +0 -244
  133. package/docs/codeserver-pattern.md +0 -191
  134. package/docs/generic-toolset.md +0 -326
  135. package/docs/howtos/agent-networking.md +0 -253
  136. package/docs/howtos/spawn-agents.md.bak +0 -200
  137. package/docs/howtos/spawn-agents.md.bak_new +0 -200
  138. package/docs/multi-agent-clusters.md +0 -265
  139. package/docs/music-toolsets.md +0 -137
  140. package/docs/path-resolution-best-practices.md +0 -104
  141. package/docs/plans/minimax-music-generation.md +0 -80
  142. package/docs/plans/unified-agent-architecture.md +0 -146
  143. package/docs/plans/websocket-streaming-plan.md.bak +0 -317
  144. package/docs/prompt/spawn_agent.md +0 -175
  145. package/docs/prompt/spawn_agent.md.bak +0 -201
  146. package/docs/prompt/task_clarification_and_documentation.md +0 -35
  147. package/docs/prompt-class.md +0 -141
  148. package/docs/todo-archive-infra-2026-04-21.md +0 -15
  149. package/docs/todo-archive-v0.0.8.md +0 -1
  150. package/docs/todo-archive-v0.1.0.md +0 -32
  151. package/docs/todo-archive.md +0 -44
  152. package/docs/tools-syntax-validation.md +0 -121
  153. package/docs/toolset.md +0 -164
  154. package/docs/xai-responses.md +0 -111
  155. package/docs/xai_collections.md +0 -106
  156. package/lib/API/x.ai/ImageToolset.js +0 -165
  157. package/lib/API/x.ai/text.js +0 -415
  158. package/lib/AgentClient.js +0 -248
  159. package/lib/AgentManager.js +0 -245
  160. package/lib/AgentServer.js +0 -404
  161. package/lib/wsCli.js +0 -287
  162. package/lib/wsIO.js +0 -90
  163. package/types/API/x.ai/text.d.ts +0 -286
  164. package/types/AgentClient.d.ts +0 -109
  165. package/types/AgentManager.d.ts +0 -100
  166. package/types/AgentServer.d.ts +0 -89
  167. package/types/wsCli.d.ts +0 -17
  168. package/types/wsIO.d.ts +0 -30
  169. package/utils/test.sh +0 -46
  170. /package/docs/{suggestions.md → _notes/token-counts.md} +0 -0
  171. /package/lib/API/openai.com/{reponses/MESSAGES.md → MESSAGES.md} +0 -0
  172. /package/types/API/{x.ai/ImageToolset.d.ts → mureka/MusicToolset.d.ts} +0 -0
  173. /package/types/{CdnToolset.d.ts → cdnToolset.d.ts} +0 -0
package/docs/toolset.md DELETED
@@ -1,164 +0,0 @@
1
- # ToolSet (\`lib/ToolSet.js\`)
2
-
3
- ## Overview
4
- **ToolSet** manages LLM function calls (tools): registration, execution, listing. Integrates with \`Prompt.js\` (via \`execute(prompt)\`) and \`AgentManager.js\` (pre-configured modes, generics). Supports JSON Schema params, async methods. Exports from \`lib/genericToolset.js\`: \`toolsPool\` (11 pre-built tools).
5
-
6
- **Uses named exports from \`lib/index.js\` - NO default export.**
7
-
8
- Key Features:
9
- - **Modes**: \`toolChoice: 'auto'|'none'|'required'\` (default \`'auto'\`).
10
- - **Validation**: Name regex \`/^\[#![a-z_0-9]{2,}$/\`.
11
- - **Events** (via \`Prompt\`): \`tool_request\`, \`tool_error\`, \`tool_response\`.
12
- - **Execution**: \`execute(prompt)\` processes \`function_request\`s from last message → calls → adds \`function_response\`s.
13
-
14
- ## Constructor
15
- \`\`\`javascript
16
- import { ToolSet } from '@j-o-r/hello-dave';
17
-
18
- new ToolSet(choice = 'auto'); // 'auto'|'none'|'required'
19
- \`\`\`
20
-
21
- ## Methods
22
- | Method | Args | Returns | Description |
23
- |--------|------|---------|-------------|
24
- | \`add(name, desc, params, method)\` | \`string\`, \`string\`, \`TSSchema\`, \`async (params) => *\` | \`void\` | Register tool. Overwrites if exists. |
25
- | \`get(name)\` | \`string\` | \`TSTool\` | Get tool details. |
26
- | \`delete(name)\` | \`string\` | \`void\` | Remove tool. |
27
- | \`has(name)\` | \`string\` | \`boolean\` | Exists? |
28
- | \`list()\` | - | \`TSToolListItem[]\` (sorted) | All tools (name/desc/params). |
29
- | \`call(name, params)\` | \`string\`, \`object\` | \`Promise<*\>\` | Execute tool. |
30
- | \`execute(prompt)\` | \`Prompt\` | \`Promise<void>\` | Process last message \`function_request\`s → execute → add \`function_response\`s to \`tool\` role. |
31
- | \`length\` | - | \`number\` | Tool count. |
32
- | \`toolChoice\` | - | \`string\` | Getter for mode. |
33
-
34
- **TSTool**: \`{description: string, parameters: TSSchema, method: async (params) => *}\`
35
- **TSSchema**: OpenAI-style JSON Schema (\`{type: 'object', properties: {...}, required: [...]}\`).
36
-
37
- ## Generic Tools (\`lib/genericToolset.js\` → \`toolsPool\`)
38
- | `syntax_check` | Validate syntax (JS/Py/Bash/JSON) via utils/syntax_check.sh. |\n|-----|-----|
39
- Pre-built \`ToolSet('auto')\` with **11 tools**. Copied via \`AgentManager.addGenericToolcall(name)\` or \`toolsetMode: 'auto'\`.
40
-
41
- | Tool Name | Description |
42
- |----------------------------|-------------|
43
- | \`javascript_interpreter\` | Execute ESM ES6 JavaScript on \`node\`. \`console.log\` captures output. cwd: \`~/devpri/js/hello-dave\`. |
44
- | \`get_user_env\` | Get user environment (name, system, city/region/country/timezone, external IP). |
45
- | \`execute_bash_script\` | Execute raw Bash script/command (no escaping; verbatim \`$\| < > & " ' \\\\` newlines \`$(())\` \`[[ ]]\`. Heredoc-safe). Ubuntu 25.10. |
46
- | \`send_email\` | Send email via \`msmtp\` (to, subject, body). |
47
- | \`open_link\` | Open URL/file with \`xdg-open\`. |
48
- | \`execute_remote_script\` | Execute raw Bash on remote via SSH (\`ssh://user@host[:port]\`). |
49
- | \`history_search\` | Search chat sessions: \`"(todo\\|task)"\` or \`"package.json"\`. Regex in \`.cache/[app]/[prompt]/sessions/*.ndjson\`. |
50
- | \`read_file\` | Read raw file in CWD (relative path, no \`/\` \`..\` \`\\\\\`). |
51
- | \`write_file\` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
52
- | \`memory_recall\` | Recall persistent memory entries from agent-specific storage (\`.cache/[agent]/memory.ndjson\`). |
53
- | \`memory_write\` | Write/update persistent memory entries for long-term state (\`.cache/[agent]/memory.ndjson\`). |
54
-
55
- ## Memory Tools (New)
56
- These tools provide persistent, agent-specific memory storage in NDJSON format (\`.cache/[agent-name]/memory.ndjson\`). Append-only; latest value per key. Ideal for token efficiency by offloading state/decisions from context.
57
-
58
- ### \`memory_recall\`
59
- **Description**: Retrieve the latest values for specified keys from memory file. Returns JSON: \`{key: value, ...}\` or \`{}\` if missing.
60
-
61
- **Parameters**:
62
- \`\`\`json
63
- {
64
- "type": "object",
65
- "properties": {
66
- "keys": {
67
- "type": "array",
68
- "items": { "type": "string" },
69
- "description": "List of memory keys to recall, e.g., ['current_task', 'last_decision']"
70
- }
71
- },
72
- "required": ["keys"]
73
- }
74
- \`\`\`
75
-
76
- **Example Usage in Agent Prompt**:
77
- \`\`\`
78
- Before proceeding, recall your current task and previous decision:
79
- - Call memory_recall with keys: ["current_task", "last_decision"]
80
- Then, use the recalled info to avoid repetition.
81
- \`\`\`
82
-
83
- **Token Efficiency**: Stores tasks/decisions externally. Recall only needed state (e.g., 100 tokens) vs. full history (10k+ tokens), preventing loops/re-reasoning.
84
-
85
- ### \`memory_write\`
86
- **Description**: Append/update key-value pairs to memory (overwrites prior same-key entries). Returns confirmation with stored entries.
87
-
88
- **Parameters**:
89
- \`\`\`json
90
- {
91
- "type": "object",
92
- "properties": {
93
- "entries": {
94
- "type": "array",
95
- "items": {
96
- "type": "object",
97
- "properties": {
98
- "key": { "type": "string", "description": "Unique key (e.g., 'current_task')" },
99
- "value": { "type": "string", "description": "JSON-stringifiable value" }
100
- },
101
- "required": ["key", "value"]
102
- },
103
- "description": "List of {key, value} pairs to store"
104
- }
105
- },
106
- "required": ["entries"]
107
- }
108
- \`\`\`
109
-
110
- **Example Usage in Agent Prompt**:
111
- \`\`\`
112
- After analyzing, store the plan:
113
- - Call memory_write with entries: [{"key": "current_task", "value": "Implement login feature"}, {"key": "step", "value": "1/5"}]
114
- \`\`\`
115
-
116
- **Token Efficiency**: Persist intermediate results across calls/sessions. Avoids context explosion/loops by recalling compact state instead of regenerating.
117
-
118
- ## Integration with AgentManager
119
- In \`setup()\`:
120
- \`\`\`javascript
121
- agent.setup({
122
- toolsetMode: 'auto', // Loads all 11 generic tools
123
- // or 'required': Empty ToolSet (add manually)
124
- });
125
- agent.addGenericToolcall('memory_recall'); // Selective copy post-setup
126
- \`\`\`
127
-
128
- **Custom Tools**:
129
- \`\`\`javascript
130
- import { AgentManager } from '@j-o-r/hello-dave';
131
-
132
- agent.setup({ toolsetMode: 'required' });
133
- const ts = agent.getToolset();
134
- ts.add('math', 'Add numbers', {
135
- type: 'object',
136
- properties: {a: {type: 'number'}, b: {type: 'number'}},
137
- required: ['a', 'b']
138
- }, async ({a, b}) => a + b);
139
- \`\`\`
140
-
141
- **Workflow** (in \`Prompt.call()\` / API adapters):
142
- 1. LLM → \`function_request\`s (assistant message).
143
- 2. \`ToolSet.execute(prompt)\` → parallel \`call()\` → \`function_response\`s (tool message).
144
- 3. Recurse until text response.
145
-
146
- ## Examples
147
- ### Standalone ToolSet
148
- \`\`\`javascript
149
- import { ToolSet } from '@j-o-r/hello-dave';
150
-
151
- const ts = new ToolSet('required');
152
- ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
153
- async ({name}) => \`Hello, \${name}!\`);
154
- console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
155
- \`\`\`
156
-
157
- ### With Prompt/AgentManager
158
- See [AgentManager](./agent-manager.md#custom-tools--generics), [Prompt](./prompt-class.md).
159
-
160
- **Updated:** March 26, 2026 (11 generics from \`lib/genericToolset.js\`).
161
-
162
- See also: [GenericToolset Source](./generic-toolset.md).
163
- \n## Syntax Validation\nSee [tools-syntax-validation.md](tools-syntax-validation.md) for `write_file` JS checks + `syntax_check` tool.
164
- \n## Path Resolution\nSee [path-resolution-best-practices.md](path-resolution-best-practices.md) for __dirname vs cwd() in tools (e.g., syntax_check.sh).\\n
@@ -1,111 +0,0 @@
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
- **Uses named exports from `lib/index.js` - NO default export.**
7
-
8
- Key adaptations:
9
- - **Unified Interface**: Uses `Prompt` messages/history for input; parses `output` into assistant/tool responses.
10
- - **Recursive Tool Calls**: Automatically handles `function_call` → execute tools → `function_call_output` loops (up to `GLOBAL.max_recursive_requests`).
11
- - **Tool Support**: Converts `ToolSet` to xAI `function` tools; supports native xAI tools like `web_search`, `x_search`.
12
- - **Reasoning & Search**: Configurable `reasoning.effort` (`low`/`medium`/`high`), `search_parameters`.
13
- - **Streaming**: Not yet implemented (future).
14
- - **Auth**: Requires `XAIKEY` env var.
15
-
16
- Default model: `grok-4-fast-reasoning`. Supports: `grok-4-fast-reasoning`, `grok-4-fast-non-reasoning`, etc.
17
-
18
- ## Usage in AgentManager
19
- ```javascript
20
- import { AgentManager } from '@j-o-r/hello-dave';
21
-
22
- const agent = new AgentManager({ name: 'weatheragent', secret: 'optional-ws-secret' });
23
- agent.setup({
24
- prompt: 'You are a precise weather expert. Use tools for real-time data.',
25
- api: 'xai',
26
- options: { model: 'grok-4-fast-reasoning', reasoning: { effort: 'high' } },
27
- toolsetMode: 'auto', // Adds generic tools like web_search
28
- contextWindow: 128000
29
- });
30
- agent.addGenericToolcall('web_search'); // Optional: Add extras
31
-
32
- // CLI mode
33
- agent.start(); // Interactive chat
34
-
35
- // Or direct call
36
- const response = await agent.directCall('Weather in Amsterdam today?');
37
- console.log(response); // Handles search/tools automatically
38
- ```
39
-
40
- Under the hood:
41
- 1. `Prompt.setAdaptor(API.text['xai'], toolset, options)` → uses `responses.request()`.
42
- 2. Converts history to xAI `input[]` (system/user/assistant/tool).
43
- 3. POST to `https://api.x.ai/v1/responses`.
44
- 4. Parses `output` → adds text/reasoning/tools to `Prompt`.
45
- 5. If tools needed, `ToolSet.execute()` → recurse until complete.
46
-
47
- ## Options (XAIOptions)
48
- | Property | Type | Default | Description |
49
- |----------|------|---------|-------------|
50
- | `model` | string | `'grok-4-fast-non-reasoning'` | e.g., `'grok-4-fast-reasoning'` |
51
- | `input` | `XAIInput[]` | `[{role: 'system', content: 'Be precise'}]` | Messages/history |
52
- | `reasoning.effort` | `'low'\|'medium'\|'high'` | `'medium'` | Reasoning depth |
53
- | `reasoning.summary` | `'auto'\|'concise'\|'detailed'` | `'auto'` | Reasoning output style |
54
- | `temperature` | number | `1` (0-2) | Sampling |
55
- | `parallel_tool_calls` | boolean | `true` | Parallel functions |
56
- | `tool_choice` | `'auto'` | `'auto'` | Tool selection |
57
- | `tools` | `XAIFunctionTool[]` | `[]` | From `ToolSet` |
58
- | `store` | boolean | `false` | Persist response (still bills tokens) |
59
- | `max_output_tokens` | number | `4000` | Limit |
60
- | `search_parameters` | object | - | `{max_search_results: 4, mode: 'auto', return_citations: true}` |
61
-
62
- **Tool Types**:
63
- - `function`: From `ToolSet` (name, description, parameters JSONSchema).
64
- - Native: `web_search`, `x_search` (filters: dates, domains, etc.).
65
-
66
- ## Example Request (Generated Internally)
67
- ```json
68
- {
69
- "model": "grok-4-fast-reasoning",
70
- "input": [
71
- {"role": "system", "content": "You are a precise weather expert."},
72
- {"role": "user", "content": "Weather in Amsterdam today?"}
73
- ],
74
- "parallel_tool_calls": true,
75
- "reasoning": {"effort": "high"},
76
- "search_parameters": {"mode": "auto", "return_citations": true},
77
- "tools": [{"type": "function", "name": "web_search", ...}]
78
- }
79
- ```
80
-
81
- ## Example Response (Parsed to Prompt)
82
- - **Text + Citations**: Added as `assistant` text + `log` annotations (URLs).
83
- - **Function Calls**: `assistant` with `function_request` → `ToolSet.execute()`.
84
- - **Reasoning**: Prepended as `reasoning` multimodal text.
85
-
86
- Sample parsed:
87
- ```
88
- Today is [date]. Weather: Cloudy, 5°C... [citations]
89
- ```
90
- Tokens: `input_tokens`, `output_tokens` (incl. `reasoning_tokens`) logged in `Prompt.records`.
91
-
92
- ## Advanced: Custom Tools
93
- Extend `ToolSet` before `setup()`:
94
- ```javascript
95
- import { ToolSet } from '@j-o-r/hello-dave';
96
-
97
- const ts = new ToolSet('required');
98
- ts.add('get_weather', 'Get weather for a location', {
99
- type: 'object',
100
- properties: { location: {type: 'string'} },
101
- required: ['location']
102
- }, async (params) => `Weather: ${params.location} - 20°C`); // Handler
103
- agent.setup({ ..., toolsetMode: ts });
104
- ```
105
-
106
- ## Errors & Limits
107
- - `Max recursive calls`: `GLOBAL.max_recursive_requests`.
108
- - Missing `XAIKEY`: Throws.
109
- - Invalid last message: Must end in `user`/`tool`.
110
-
111
- 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).
@@ -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,165 +0,0 @@
1
- /**
2
- * @file lib/API/x.ai/ImageToolset.js
3
- * @module x.ai/ImageToolset
4
- * @description Comprehensive ToolSet for the xAI Grok Imagine API.
5
- *
6
- * Exposes high-level tools for:
7
- * - generate_image → Text-to-image generation
8
- * - edit_image → Natural language image editing (supports up to 3 reference images)
9
- * - generate_video → Image-to-video generation (fully automatic)
10
- *
11
- * Designed for AI agents and LLMs. Each tool includes rich descriptions and JSON schemas.
12
- *
13
- * @see ./image.js for the underlying implementation
14
- * @see ./image.md for the full API specification
15
- */
16
-
17
- import ToolSet from '../../ToolSet.js';
18
- import * as xai from './image.js';
19
-
20
- const tools = new ToolSet('auto');
21
-
22
- /* ============================================================
23
- GENERATE IMAGE
24
- ============================================================ */
25
-
26
- tools.add(
27
- 'generate_image',
28
- 'Generate high-quality images from a text prompt using Grok Imagine. ' +
29
- 'Supports configurable number of images and output format. ' +
30
- 'Returns the local file path of the generated image(s).',
31
- {
32
- type: 'object',
33
- properties: {
34
- prompt: {
35
- type: 'string',
36
- description: 'Detailed English prompt describing the desired image. ' +
37
- 'Be specific about style, lighting, composition, and subject.'
38
- },
39
- n: {
40
- type: 'integer',
41
- minimum: 1,
42
- maximum: 10,
43
- default: 1,
44
- description: 'Number of images to generate in one request.'
45
- },
46
- output_format: {
47
- type: 'string',
48
- enum: ['png', 'jpeg', 'webp'],
49
- default: 'png',
50
- description: 'Preferred output format.'
51
- }
52
- },
53
- required: ['prompt']
54
- },
55
- async (params) => {
56
- const result = await xai.generateImage(params.prompt, params);
57
-
58
- return JSON.stringify({
59
- local_path: result.local_path,
60
- url: result.url,
61
- revised_prompt: result.revised_prompt,
62
- note: 'Image generated successfully with generate_image.'
63
- }, null, 2);
64
- }
65
- );
66
-
67
- /* ============================================================
68
- EDIT IMAGE
69
- ============================================================ */
70
-
71
- tools.add(
72
- 'edit_image',
73
- 'Edit one or more images using natural language instructions. ' +
74
- 'Supports up to 3 reference images for compositing, style transfer, or multi-subject editing. ' +
75
- 'Provide image URLs, local paths, or base64 data.',
76
- {
77
- type: 'object',
78
- properties: {
79
- prompt: {
80
- type: 'string',
81
- description: 'Natural language description of the edit you want to apply.'
82
- },
83
- image_url: {
84
- type: 'string',
85
- description: 'Single image URL or path to edit.'
86
- },
87
- image_urls: {
88
- type: 'array',
89
- items: { type: 'string' },
90
- description: 'Array of up to 3 image URLs or paths for multi-image editing.'
91
- },
92
- output_format: {
93
- type: 'string',
94
- enum: ['png', 'jpeg', 'webp'],
95
- default: 'png'
96
- }
97
- },
98
- required: ['prompt']
99
- },
100
- async (params) => {
101
- const images = params.image_urls || (params.image_url ? [params.image_url] : []);
102
-
103
- const result = await xai.editImage(params.prompt, images, params);
104
-
105
- return JSON.stringify({
106
- local_path: result.local_path,
107
- url: result.url,
108
- revised_prompt: result.revised_prompt,
109
- note: 'Image edited successfully with edit_image.'
110
- }, null, 2);
111
- }
112
- );
113
-
114
- /* ============================================================
115
- GENERATE VIDEO
116
- ============================================================ */
117
-
118
- tools.add(
119
- 'generate_video',
120
- 'Generate a video from a still image and text prompt using Grok Imagine Video. ' +
121
- 'This tool is fully automatic — it submits the request and waits internally until the video is ready. ' +
122
- 'Returns the local file path of the generated video.',
123
- {
124
- type: 'object',
125
- properties: {
126
- prompt: {
127
- type: 'string',
128
- description: 'Description of the desired motion, camera movement, or animation.'
129
- },
130
- image_url: {
131
- type: 'string',
132
- description: 'Source image URL or local path.'
133
- },
134
- duration: {
135
- type: 'number',
136
- minimum: 1,
137
- maximum: 15,
138
- default: 8,
139
- description: 'Video duration in seconds.'
140
- },
141
- aspect_ratio: {
142
- type: 'string',
143
- default: '16:9',
144
- description: 'Aspect ratio of the output video.'
145
- },
146
- resolution: {
147
- type: 'string',
148
- default: '720p',
149
- description: 'Output resolution.'
150
- }
151
- },
152
- required: ['prompt', 'image_url']
153
- },
154
- async (params) => {
155
- const result = await xai.generateVideo(params.prompt, params.image_url, params);
156
-
157
- return JSON.stringify({
158
- local_path: result.local_path,
159
- url: result.url,
160
- note: 'Video generated successfully with generate_video.'
161
- }, null, 2);
162
- }
163
- );
164
-
165
- export default tools;