@j-o-r/hello-dave 0.0.0
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.
- package/LICENSE +73 -0
- package/README.md +207 -0
- package/bin/hdAsk.js +103 -0
- package/bin/hdClear.js +13 -0
- package/bin/hdCode.js +110 -0
- package/bin/hdConnect.js +230 -0
- package/bin/hdInspect.js +28 -0
- package/bin/hdNpm.js +114 -0
- package/bin/hdPrompt.js +108 -0
- package/examples/claude-test.js +89 -0
- package/examples/claude.js +143 -0
- package/examples/gpt.js +127 -0
- package/examples/gpt_code.js +125 -0
- package/examples/gpt_note_keeping.js +117 -0
- package/examples/grok.js +119 -0
- package/examples/grok_code.js +114 -0
- package/examples/grok_note_keeping.js +111 -0
- package/lib/API/anthropic.com/text.js +402 -0
- package/lib/API/brave.com/search.js +239 -0
- package/lib/API/openai.com/README.md +1 -0
- package/lib/API/openai.com/reponses/MESSAGES.md +69 -0
- package/lib/API/openai.com/reponses/text.js +416 -0
- package/lib/API/x.ai/text.js +415 -0
- package/lib/AgentClient.js +197 -0
- package/lib/AgentManager.js +144 -0
- package/lib/AgentServer.js +336 -0
- package/lib/Cli.js +256 -0
- package/lib/Prompt.js +728 -0
- package/lib/Session.js +231 -0
- package/lib/ToolSet.js +186 -0
- package/lib/fafs.js +93 -0
- package/lib/genericToolset.js +170 -0
- package/lib/index.js +34 -0
- package/lib/promptHelpers.js +132 -0
- package/lib/testToolset.js +42 -0
- package/module.md +189 -0
- package/package.json +49 -0
- package/types/API/anthropic.com/text.d.ts +207 -0
- package/types/API/brave.com/search.d.ts +156 -0
- package/types/API/openai.com/reponses/text.d.ts +225 -0
- package/types/API/x.ai/text.d.ts +286 -0
- package/types/AgentClient.d.ts +70 -0
- package/types/AgentManager.d.ts +112 -0
- package/types/AgentServer.d.ts +38 -0
- package/types/Cli.d.ts +52 -0
- package/types/Prompt.d.ts +298 -0
- package/types/Session.d.ts +31 -0
- package/types/ToolSet.d.ts +95 -0
- package/types/fafs.d.ts +47 -0
- package/types/genericToolset.d.ts +3 -0
- package/types/index.d.ts +23 -0
- package/types/promptHelpers.d.ts +1 -0
- package/types/testToolset.d.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
58
|
+
|
|
59
|
+
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
|
60
|
+
|
|
61
|
+
Copyright 2024 j-o-r Jorrit duin https://duin.xyz
|
|
62
|
+
|
|
63
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
64
|
+
you may not use this file except in compliance with the License.
|
|
65
|
+
You may obtain a copy of the License at
|
|
66
|
+
|
|
67
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
68
|
+
|
|
69
|
+
Unless required by applicable law or agreed to in writing, software
|
|
70
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
71
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
72
|
+
See the License for the specific language governing permissions and
|
|
73
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# hello-dave (ALPHA)
|
|
2
|
+
|
|
3
|
+
A small, ESM-only Node.js toolkit for building AI “agents” with:
|
|
4
|
+
- one unified Prompt abstraction across multiple LLM providers (x.ai Grok, OpenAI, Anthropic)
|
|
5
|
+
- first-class function calling via a simple ToolSet
|
|
6
|
+
- a tiny AgentManager that wires everything together (CLI, direct calls, WS server/client)
|
|
7
|
+
- optional persisted sessions and records on disk
|
|
8
|
+
|
|
9
|
+
> **Note:**
|
|
10
|
+
> This is a personal project, created for my own convenience and exclusively used and tested on Debian/Ubuntu.
|
|
11
|
+
> It can be used to create, use and combine Agents. It has great potential and is very powerful; e.g., `hdCode` has full access to the user environment and is able to execute any command or code.
|
|
12
|
+
> Prompt injection is a RISK so use with care and only if you know what you're doing.
|
|
13
|
+
>
|
|
14
|
+
> How-tos and documentation are not finished; you may find rough edges.
|
|
15
|
+
>
|
|
16
|
+
> There are no fancy interfaces; everything is kept minimal and functional.
|
|
17
|
+
>
|
|
18
|
+
> It is not yet able to connect to MCP servers; however, it is possible to connect Agents to the main Agent-server and so build a network of Agents.
|
|
19
|
+
> `This is achieved by using function calls and WebSockets.
|
|
20
|
+
>
|
|
21
|
+
> It is, e.g., possible to run a 'root' Agent with shell access and extend the Agent-server with it.
|
|
22
|
+
>
|
|
23
|
+
> Also, it is not tied to localhost. All Agents can run anywhere as long as they can make a connection to the Agent-server.
|
|
24
|
+
>
|
|
25
|
+
> The Agent-server can also connect to another Agent-server, running multiple hubs (from different nodes) each with their own specialty.
|
|
26
|
+
|
|
27
|
+
This repo also ships example CLIs. The most compact example is examples/grok.js which shows how to use:
|
|
28
|
+
- lib/AgentManager.js
|
|
29
|
+
- lib/AgentServer.js
|
|
30
|
+
- lib/AgentClient.js
|
|
31
|
+
- lib/Cli.js
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
- Node.js >= 20 (package is ESM only: "type": "module")
|
|
35
|
+
- API keys via environment variables (only set what you use):
|
|
36
|
+
- XAIKEY for x.ai (Grok)
|
|
37
|
+
- OPENAIKEY for OpenAI
|
|
38
|
+
- ANTHKEY for Anthropic
|
|
39
|
+
- BRAVESEARCHKEY for the Brave Search tool (optional tool)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
- As a dependency in your project:
|
|
45
|
+
- npm i @j-o-r/hello-dave
|
|
46
|
+
- then use either the programmatic API (AgentManager) or the provided CLIs.
|
|
47
|
+
|
|
48
|
+
### Bonus (when installed)
|
|
49
|
+
|
|
50
|
+
Use the AI right away. Make sure you have an x.ai api key available.
|
|
51
|
+
(Grok gives very good result)
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export XAIKEY=.....
|
|
55
|
+
```
|
|
56
|
+
Now you can run the hello-dave code AI and the generic hello-dave 'ask' ai from within the current folder.
|
|
57
|
+
Make sure to create a '.cache' folder first.
|
|
58
|
+
```bash
|
|
59
|
+
mkdir .cache
|
|
60
|
+
```
|
|
61
|
+
(I am used to run Agents within tmux sessions)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Code AI with direct shell access (CAREFULL)
|
|
65
|
+
npx hdCode
|
|
66
|
+
|
|
67
|
+
# Ask Cli
|
|
68
|
+
npx hdAsk
|
|
69
|
+
# Ask One shot
|
|
70
|
+
echo "Current date time" | npx hdAsk
|
|
71
|
+
|
|
72
|
+
# Inspect a ndjson log/session file
|
|
73
|
+
npx hdInspect .cache/hello-dave/...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- Interactive mode (no stdin):
|
|
77
|
+
- Use keys inside the TUI:
|
|
78
|
+
- ALT+d: exit
|
|
79
|
+
- ALT+r: reset conversation
|
|
80
|
+
- ALT+s: load a previous session
|
|
81
|
+
- ALT+k: show shortcuts/help
|
|
82
|
+
|
|
83
|
+
- One-shot (pipe stdin):
|
|
84
|
+
- echo "explain sse vs websocket in 2 lines" | npx hdAsk
|
|
85
|
+
|
|
86
|
+
- Switch parameters:
|
|
87
|
+
- node examples/grok.js --model grok-3-mini --tokens 4000 --context 10000 --temperature 0.3 --top_p 0.9
|
|
88
|
+
- node examples/grok.js --reasoning high
|
|
89
|
+
|
|
90
|
+
- Enable tools (function calling):
|
|
91
|
+
- node examples/grok.js --tools javascript,bash
|
|
92
|
+
- javascript adds javascript_interpreter
|
|
93
|
+
- bash adds execute_bash_script
|
|
94
|
+
|
|
95
|
+
- Run as a local dynamic tool server and connect a client:
|
|
96
|
+
- Terminal A: node examples/grok.js --serve 8000 --tools javascript,bash
|
|
97
|
+
- Terminal B: node examples/grok.js --connect ws://127.0.0.1:8000/ws
|
|
98
|
+
|
|
99
|
+
Notes
|
|
100
|
+
- With --serve, the agent starts a WS server on 127.0.0.1:PORT and exposes any connected clients as callable tools.
|
|
101
|
+
- With --connect, an agent registers itself on that WS and will handle queries routed to its tool name.
|
|
102
|
+
|
|
103
|
+
## Where data is stored
|
|
104
|
+
|
|
105
|
+
Conversations, logs and request records are written under ./.cache/hello-dave/<agent-name>/
|
|
106
|
+
- sessions/ incremental ndjson of messages
|
|
107
|
+
- records/ per-day ndjson of timing/token/billing metadata
|
|
108
|
+
- logs/ per-day ndjson of internal events
|
|
109
|
+
|
|
110
|
+
These are managed by lib/Session.js and used by lib/Cli.js (ALT+s to load older sessions).
|
|
111
|
+
|
|
112
|
+
## Programmatic use (AgentManager)
|
|
113
|
+
|
|
114
|
+
AgentManager is the easiest way to embed the library in your own code. It creates a Prompt, optional ToolSet, session persistence, and can run as CLI or server/client.
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
// ESM
|
|
118
|
+
import AgentManager from '@j-o-r/hello-dave';
|
|
119
|
+
|
|
120
|
+
// Minimal: direct call against Grok
|
|
121
|
+
const agent = new AgentManager({ name: 'grok' });
|
|
122
|
+
agent.setup({
|
|
123
|
+
prompt: 'Be precise and concise.',
|
|
124
|
+
api: 'grok', // 'gpt' | 'grok' | 'claude'
|
|
125
|
+
options: { // forwarded to the provider adapter
|
|
126
|
+
model: 'grok-4',
|
|
127
|
+
search_parameters: { mode: 'auto' }
|
|
128
|
+
},
|
|
129
|
+
toolsetMode: 'auto', // 'auto' | 'required' | undefined
|
|
130
|
+
contextWindow: 250_000
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const answer = await agent.directCall('Two bullet points on tail recursion.');
|
|
134
|
+
console.log(answer);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Adding your own tools (function calling)
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
const toolset = agent.getToolset();
|
|
141
|
+
if (toolset) {
|
|
142
|
+
toolset.add(
|
|
143
|
+
'say_hello',
|
|
144
|
+
'Return a friendly greeting',
|
|
145
|
+
{
|
|
146
|
+
type: 'object',
|
|
147
|
+
properties: { name: { type: 'string', description: 'Who to greet' } },
|
|
148
|
+
required: ['name']
|
|
149
|
+
},
|
|
150
|
+
async ({ name }) => `Hello, ${name}!`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Now the model can call say_hello when appropriate.
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Running an agent as a tool server
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
agent.enableServer('search', 'General-purpose search interface', 8000);
|
|
161
|
+
// WS on ws://127.0.0.1:8000/ws; connected clients become callable tools.
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Attaching an agent as a WS client (remote tool)
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
agent.attach(
|
|
168
|
+
'code',
|
|
169
|
+
'Run JavaScript snippets safely and return output',
|
|
170
|
+
'ws://127.0.0.1:8000/ws'
|
|
171
|
+
);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Library building blocks (how grok.js uses them)
|
|
175
|
+
|
|
176
|
+
- lib/AgentManager.js: façade that composes Prompt, ToolSet, Session and the provider adaptor (API.text[api]). Also starts CLI, WS server, or WS client.
|
|
177
|
+
- lib/Cli.js: a small TUI with history, session loading, and handy shortcuts; it listens to Prompt events.
|
|
178
|
+
- lib/AgentServer.js: local WS server that turns each attached client into a ToolSet function. Calls are routed over WS and responses returned as tool outputs.
|
|
179
|
+
- lib/AgentClient.js: WS client that introduces itself (name + description) and processes queued requests exactly one at a time.
|
|
180
|
+
|
|
181
|
+
Under the hood:
|
|
182
|
+
- lib/Prompt.js: uniform message format (system, user, assistant, tool, reasoning, log), function-call plumbing, truncation, and provider-neutral calls.
|
|
183
|
+
- lib/ToolSet.js: dead-simple JSON-schema + async method registry powering function calling.
|
|
184
|
+
- lib/API/*: adaptors for x.ai (Grok), OpenAI Responses API, Anthropic Messages API, Brave Search tool.
|
|
185
|
+
- lib/Session.js: on-disk persistence for sessions, logs and records.
|
|
186
|
+
|
|
187
|
+
## TypeScript
|
|
188
|
+
- Types are bundled. Main types for AgentManager are available via types/AgentManager.d.ts.
|
|
189
|
+
|
|
190
|
+
## Utils
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# Clear all session and log files
|
|
194
|
+
npx hdClear
|
|
195
|
+
# Read an ndjson file (session, log etc.)
|
|
196
|
+
npx hdInspect [path/to/file.ndjson]
|
|
197
|
+
# Design / create a prompt. (AI prompt, x.ai key needed)
|
|
198
|
+
npx hdPrompt
|
|
199
|
+
# Ask a generic quesion to openai gpt-5-nano (openai key needed)
|
|
200
|
+
npx hdAsk
|
|
201
|
+
# Cli Connect to a websocket agent server
|
|
202
|
+
npx hdConnect [ws://127.0.0.1:8000/ws]
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
Apache-2.0
|
package/bin/hdAsk.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import AgentManager from '../lib/AgentManager.js';
|
|
3
|
+
import { parseArgs, readIn } from '@j-o-r/sh';
|
|
4
|
+
|
|
5
|
+
const name = 'hdAsk';
|
|
6
|
+
const api = 'grok';
|
|
7
|
+
|
|
8
|
+
const input = await readIn();
|
|
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/text.js').XOptions} */
|
|
15
|
+
const options = {}
|
|
16
|
+
// Set properties only if provided via command line (except model which has default)
|
|
17
|
+
if (args['model'] || true) { // model gets default value
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
options.model = args['model'] || 'grok-4-fast';
|
|
20
|
+
}
|
|
21
|
+
if (args['temperature']) {
|
|
22
|
+
options.temperature = parseFloat(args['temperature']);
|
|
23
|
+
}
|
|
24
|
+
if (args['tokens']) {
|
|
25
|
+
options.max_completion_tokens = parseInt(args['tokens']);
|
|
26
|
+
}
|
|
27
|
+
if (args['top_p']) {
|
|
28
|
+
options.top_p = parseFloat(args['top_p']);
|
|
29
|
+
}
|
|
30
|
+
options.search_parameters = { mode: 'auto' }
|
|
31
|
+
const reasoning = args['reasoning'] ? args['reasoning'] : null;
|
|
32
|
+
if (reasoning) {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
options.reasoning_effort = reasoning
|
|
35
|
+
}
|
|
36
|
+
// Large context on grok-4-fast
|
|
37
|
+
const contextWindow = args['context'] ? parseInt(args['context']) : 1900000;
|
|
38
|
+
const toolsetMode = 'auto';
|
|
39
|
+
|
|
40
|
+
function printHelp() {
|
|
41
|
+
console.log(`
|
|
42
|
+
'${name} --help' You are looking at it.
|
|
43
|
+
'
|
|
44
|
+
OPTIONS:
|
|
45
|
+
--tokens [number]: max generated tokens
|
|
46
|
+
--context [number] : truncate message history to context-windows size default 130000
|
|
47
|
+
--temperature [float] : -2 / +2
|
|
48
|
+
--model [grok-4|grok-3|grok-3-mini|grok-3-mini-fast|grok-code-fast-1]
|
|
49
|
+
--top_p [float]: number > 0, 0.1 means no top_p
|
|
50
|
+
--reasoning [low|high]
|
|
51
|
+
--tools [javascript,bash] comma seperated list
|
|
52
|
+
e.g.
|
|
53
|
+
grok.js --model grok-3-mini --tokens 4000 --context 10000
|
|
54
|
+
|
|
55
|
+
`);
|
|
56
|
+
process.exit()
|
|
57
|
+
}
|
|
58
|
+
if (help) {
|
|
59
|
+
printHelp();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const prompt = `
|
|
63
|
+
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.
|
|
64
|
+
- open_link: [url] — open in local browser.
|
|
65
|
+
- send_email: send to [email_address]; message: [message].
|
|
66
|
+
`.trim();
|
|
67
|
+
|
|
68
|
+
const agent = new AgentManager({ name });
|
|
69
|
+
agent.setup({
|
|
70
|
+
prompt,
|
|
71
|
+
api,
|
|
72
|
+
options,
|
|
73
|
+
toolsetMode,
|
|
74
|
+
contextWindow
|
|
75
|
+
});
|
|
76
|
+
agent.addGenericToolcall('open_link');
|
|
77
|
+
agent.addGenericToolcall('send_email');
|
|
78
|
+
|
|
79
|
+
const cliIntro = `
|
|
80
|
+
${name} ${options.model}.
|
|
81
|
+
- search ${options.search_parameters.mode}
|
|
82
|
+
- context: ${contextWindow}
|
|
83
|
+
`.trim();
|
|
84
|
+
const description = `
|
|
85
|
+
Guide for this smart online AI Agent:
|
|
86
|
+
- query: Formulate ONE efficient, comprehensive search query in natural language, combining multiple sources/subjects/domains; mention optional sources if needed. Avoid multiple queries—conso
|
|
87
|
+
lidate into a single one.
|
|
88
|
+
- open_link: [URL] — Open in local browser.
|
|
89
|
+
- send_email: Send to [email_address]; Message: [message].
|
|
90
|
+
`.trim();
|
|
91
|
+
|
|
92
|
+
if (input === '' && serve) {
|
|
93
|
+
agent.enableServer(name, description, serve);
|
|
94
|
+
}
|
|
95
|
+
if (input !== '') {
|
|
96
|
+
// Direct input output
|
|
97
|
+
const res = await agent.directCall(input);
|
|
98
|
+
console.log(res);
|
|
99
|
+
} else if(connect) {
|
|
100
|
+
agent.attach('online_agent', description, connect)
|
|
101
|
+
} else {
|
|
102
|
+
agent.startCli(cliIntro);
|
|
103
|
+
}
|
package/bin/hdClear.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env -S node
|
|
2
|
+
|
|
3
|
+
// clear .cache/hello-dave if it exsists
|
|
4
|
+
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { SH } from '@j-o-r/sh';
|
|
7
|
+
|
|
8
|
+
const folder = path.resolve('.cache', 'hello-dave');
|
|
9
|
+
const res = await SH`[ -d "${folder}" ] && echo "yes" || echo "no"`.run();
|
|
10
|
+
if (res === 'yes') {
|
|
11
|
+
console.log(`rm -fr ${folder}/*`);
|
|
12
|
+
await SH`rm -fr ${folder}/*`.run()
|
|
13
|
+
}
|
package/bin/hdCode.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import AgentManager from '../lib/AgentManager.js';
|
|
3
|
+
import { parseArgs, readIn } from '@j-o-r/sh';
|
|
4
|
+
import { systemInfo } from '../lib/fafs.js';
|
|
5
|
+
|
|
6
|
+
const name = 'hdCode';
|
|
7
|
+
const api = 'grok';
|
|
8
|
+
|
|
9
|
+
const input = await readIn();
|
|
10
|
+
const args = parseArgs();
|
|
11
|
+
const help = args['help'] || false;
|
|
12
|
+
const connect = args['connect'] ? args['connect'] : undefined;
|
|
13
|
+
const serve = args['serve'] ? parseInt(args['serve']) : undefined;
|
|
14
|
+
|
|
15
|
+
/** @type {import('lib/API/x.ai/text.js').XOptions} */
|
|
16
|
+
const options = {}
|
|
17
|
+
// Set properties only if provided via command line (except model which has default)
|
|
18
|
+
if (args['model'] || true) { // model gets default value
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
options.model = args['model'] || 'grok-code-fast-1';
|
|
21
|
+
}
|
|
22
|
+
if (args['temperature']) {
|
|
23
|
+
options.temperature = parseFloat(args['temperature']);
|
|
24
|
+
}
|
|
25
|
+
if (args['tokens']) {
|
|
26
|
+
options.max_completion_tokens = parseInt(args['tokens']);
|
|
27
|
+
}
|
|
28
|
+
if (args['top_p']) {
|
|
29
|
+
options.top_p = parseFloat(args['top_p']);
|
|
30
|
+
}
|
|
31
|
+
options.search_parameters = { mode: 'auto' }
|
|
32
|
+
const reasoning = args['reasoning'] ? args['reasoning'] : null;
|
|
33
|
+
if (reasoning) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
options.reasoning_effort = reasoning
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const toolsetMode = 'auto';
|
|
39
|
+
const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
|
|
40
|
+
|
|
41
|
+
function printHelp() {
|
|
42
|
+
console.log(`
|
|
43
|
+
'${name} --help' You are looking at it.
|
|
44
|
+
'
|
|
45
|
+
OPTIONS:
|
|
46
|
+
--tokens [number]: max generated tokens
|
|
47
|
+
--context [number] : truncate message history to context-windows size default 130000
|
|
48
|
+
--temperature [float] : -2 / +2
|
|
49
|
+
--model [grok-4|grok-3|grok-3-mini|grok-3-mini-fast|grok-code-fast-1]
|
|
50
|
+
--top_p [float]: number > 0, 0.1 means no top_p
|
|
51
|
+
--reasoning [low|high]
|
|
52
|
+
--tools [javascript,bash] comma seperated list
|
|
53
|
+
e.g.
|
|
54
|
+
grok.js --model grok-3-mini --tokens 4000 --context 10000
|
|
55
|
+
|
|
56
|
+
`);
|
|
57
|
+
process.exit()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (help) {
|
|
61
|
+
printHelp();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const sys = await systemInfo();
|
|
65
|
+
const prompt = `
|
|
66
|
+
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 safe Bash execution. For writing and reading files, stay in the current working folder. Provide clear, step-by-step responses, examples, and ensure safety compliance.
|
|
67
|
+
Update your 'memory' frequently.
|
|
68
|
+
---env
|
|
69
|
+
${sys}
|
|
70
|
+
---
|
|
71
|
+
`.trim();
|
|
72
|
+
const agent = new AgentManager({ name });
|
|
73
|
+
agent.setup({
|
|
74
|
+
prompt,
|
|
75
|
+
api,
|
|
76
|
+
options,
|
|
77
|
+
toolsetMode,
|
|
78
|
+
contextWindow
|
|
79
|
+
});
|
|
80
|
+
const toolset = agent.getToolset();
|
|
81
|
+
if (toolset) {
|
|
82
|
+
const addTools = (args['tools']) ? args['tools'].split(',') : ['bash'];
|
|
83
|
+
if (addTools.includes('javascript')) {
|
|
84
|
+
agent.addGenericToolcall('javascript_interpreter');
|
|
85
|
+
}
|
|
86
|
+
if (addTools.includes('bash')) {
|
|
87
|
+
agent.addGenericToolcall('execute_bash_script');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const cliIntro = `
|
|
91
|
+
${name} ${options.model}.
|
|
92
|
+
- search ${options.search_parameters.mode}
|
|
93
|
+
- context: ${contextWindow}
|
|
94
|
+
`.trim();
|
|
95
|
+
const description = `
|
|
96
|
+
Gateway to a specialized coding assistant for Bash, JavaScript (ESM/ESNext), and other languages. Handles execution, reading, creation, querying, explaining, and code help, with safety and folder restrictions.
|
|
97
|
+
`.trim();
|
|
98
|
+
|
|
99
|
+
if (input === '' && serve) {
|
|
100
|
+
agent.enableServer('code', description, serve);
|
|
101
|
+
}
|
|
102
|
+
if (input !== '') {
|
|
103
|
+
// Direct input output
|
|
104
|
+
const res = await agent.directCall(input);
|
|
105
|
+
console.log(res);
|
|
106
|
+
} else if (connect) {
|
|
107
|
+
agent.attach('code', description, connect)
|
|
108
|
+
} else {
|
|
109
|
+
agent.startCli(cliIntro);
|
|
110
|
+
}
|