@j-o-r/hello-dave 0.0.2 → 0.0.3

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 (60) hide show
  1. package/README.md +288 -163
  2. package/README.md.backup +269 -0
  3. package/bin/dave.js +165 -0
  4. package/examples/CodeServer +43 -0
  5. package/{bin/hdAsk.js → examples/askDave.js} +50 -39
  6. package/{bin/hdCode.js → examples/codeDave.js} +47 -47
  7. package/examples/coderev.js +72 -0
  8. package/examples/daisy.js +177 -0
  9. package/examples/docsDave.js +119 -0
  10. package/examples/gpt.js +54 -72
  11. package/examples/grok.js +47 -68
  12. package/examples/npmDave.js +175 -0
  13. package/examples/promptDave.js +112 -0
  14. package/examples/readmeDave.js +144 -0
  15. package/examples/spawndave.js +240 -0
  16. package/examples/todoDave.js +132 -0
  17. package/lib/API/openai.com/reponses/text.js +12 -18
  18. package/lib/API/x.ai/collections.js +354 -0
  19. package/lib/API/x.ai/files.js +218 -0
  20. package/lib/API/x.ai/responses.js +494 -0
  21. package/lib/API/x.ai/text.js +1 -1
  22. package/lib/AgentClient.js +13 -6
  23. package/lib/AgentManager.js +79 -10
  24. package/lib/AgentServer.js +45 -21
  25. package/lib/Cli.js +7 -1
  26. package/lib/Prompt.js +4 -2
  27. package/lib/ToolSet.js +2 -1
  28. package/lib/genericToolset.js +124 -87
  29. package/lib/index.js +4 -2
  30. package/lib/wsCli.js +257 -0
  31. package/lib/wsIO.js +96 -0
  32. package/package.json +26 -20
  33. package/types/API/openai.com/reponses/text.d.ts +17 -3
  34. package/types/API/x.ai/collections.d.ts +167 -0
  35. package/types/API/x.ai/files.d.ts +84 -0
  36. package/types/API/x.ai/responses.d.ts +379 -0
  37. package/types/AgentClient.d.ts +5 -0
  38. package/types/AgentManager.d.ts +24 -31
  39. package/types/AgentServer.d.ts +5 -1
  40. package/types/Prompt.d.ts +4 -2
  41. package/types/ToolSet.d.ts +1 -0
  42. package/types/index.d.ts +4 -3
  43. package/types/wsCli.d.ts +3 -0
  44. package/types/wsIO.d.ts +26 -0
  45. package/utils/bars.js +40 -0
  46. package/utils/clear_sessions.sh +54 -0
  47. package/{bin/hdInspect.js → utils/format_log.js} +5 -0
  48. package/utils/list_sessions.sh +46 -0
  49. package/utils/search_sessions.sh +73 -0
  50. package/bin/hdClear.js +0 -13
  51. package/bin/hdConnect.js +0 -230
  52. package/bin/hdNpm.js +0 -114
  53. package/bin/hdPrompt.js +0 -108
  54. package/examples/claude-test.js +0 -89
  55. package/examples/claude.js +0 -143
  56. package/examples/gpt_code.js +0 -125
  57. package/examples/gpt_note_keeping.js +0 -117
  58. package/examples/grok_code.js +0 -114
  59. package/examples/grok_note_keeping.js +0 -111
  60. package/module.md +0 -189
@@ -1,111 +0,0 @@
1
- #!/usr/bin/env node
2
- import { fileURLToPath } from 'url';
3
- import path from 'path';
4
- import AgentManager from '../lib/AgentManager.js';
5
- import { systemInfo } from '../lib/fafs.js';
6
- import { parseArgs, readIn } from '@j-o-r/sh';
7
- import toolsPool from '../lib/genericToolset.js';
8
-
9
- const name = path.basename(fileURLToPath(import.meta.url), path.extname(fileURLToPath(import.meta.url)));
10
- const api = 'grok'; // Using GPT API for general AI assistance, adjust if needed
11
-
12
- const input = await readIn();
13
- const args = parseArgs();
14
- const help = args['help'] || false;
15
- const connect = args['connect'] ? args['connect'] : undefined;
16
- const serve = args['serve'] ? parseInt(args['serve']) : undefined;
17
-
18
- /** @type {import('../lib/API/x.ai/text.js').XOptions} */ // Assuming GPT uses OpenAI API
19
- const options = {}
20
- // Set properties only if provided via command line
21
- if (args['model'] || true) {
22
- // @ts-ignore
23
- options.model = args['model'] || 'grok-4';
24
- }
25
- if (args['temperature']) {
26
- options.temperature = parseFloat(args['temperature']);
27
- }
28
- if (args['tokens']) {
29
- options.max_completion_tokens = parseInt(args['tokens']);
30
- }
31
- if (args['top_p']) {
32
- options.top_p = parseFloat(args['top_p']);
33
- }
34
-
35
- options.search_parameters = {mode:'auto'}
36
-
37
- const reasoning = args['reasoning'] ? args['reasoning'] : null;
38
- if (reasoning) {
39
- // @ts-ignore
40
- options.reasoning_effort = reasoning
41
- }
42
-
43
- const toolsetMode = 'auto';
44
- const contextWindow = args['context'] ? parseInt(args['context']) : 250000;
45
-
46
- // Copy from the generic toolset
47
- function printHelp() {
48
- console.log(`
49
- '${name} --help' You are looking at it.
50
-
51
- OPTIONS:
52
- --tokens [number]: max generated tokens
53
- --context [number] : truncate message history to context-windows size default 250000
54
- --temperature [float] : -2 / +2
55
- --model [gpt-4o|gpt-4o-mini|etc] // Adjust based on available models
56
- --top_p [float]: number > 0, 0.1 means no top_p
57
- --reasoning [low|high]
58
- --tools [javascript,bash] comma separated list
59
- e.g.
60
- note_keeping.js --model gpt-4o-mini --tokens 4000 --context 10000
61
-
62
- `);
63
- process.exit()
64
- }
65
-
66
- if (help) {
67
- printHelp();
68
- }
69
- const sys = await systemInfo();
70
- const prompt = `
71
- You are an AI note-keeping assistant for Markdown notes in extended context. Use/create 'notes' folder in cwd. Search via tools like grep. Create/update/delete .md files safely. Goals: track progress, manage todos, capture requirements, document processes, store links/bookmarks/remarks. Respond concisely, step-by-step, no unnecessary follow-ups.
72
- ---env
73
- ${sys}
74
- ---
75
- `.trim();
76
- const agent = new AgentManager({ name });
77
- agent.setup({
78
- prompt,
79
- api,
80
- options,
81
- toolsetMode,
82
- contextWindow
83
- });
84
- const toolset = agent.getToolset();
85
-
86
- if (toolset) {
87
- let tool = toolsPool.get('execute_bash_script');
88
- if (tool) {
89
- toolset.add('execute_bash_script', tool.description, tool.parameters, tool.method);
90
- }
91
- }
92
- const cliIntro = `
93
- ${options.model}.
94
- - search ${options.search_parameters.mode}
95
- `.trim();
96
- const description = `
97
- AI-assisted note-keeping tool for managing Markdown notes, including search, creation, updates, and deletion. Supports progress tracking, todos, requirements, docs, links, bookmarks, and remarks.
98
- `.trim();
99
-
100
- if (input === '' && serve) {
101
- agent.enableServer('memory', description, serve);
102
- }
103
- if (input !== '') {
104
- // Direct input output
105
- const res = await agent.directCall(input);
106
- console.log(res);
107
- } else if(connect) {
108
- agent.attach('memory', description, connect)
109
- } else {
110
- agent.startCli(cliIntro);
111
- }
package/module.md DELETED
@@ -1,189 +0,0 @@
1
- # @j-o-r/hello-dave Module Documentation
2
-
3
- ## Overview
4
- **Name:** @j-o-r/hello-dave
5
- **Version:** 0.0.0
6
- **Description:** API to various endpoints mainly focused on AI
7
-
8
- This is a small, ESM-only Node.js toolkit for building AI "agents" with:
9
- - One unified Prompt abstraction across multiple LLM providers (x.ai Grok, OpenAI, Anthropic)
10
- - First-class function calling via a simple ToolSet
11
- - A tiny AgentManager that wires everything together (CLI, direct calls, WS server/client)
12
- - Optional persisted sessions and records on disk
13
-
14
- Key features include:
15
- - Support for multiple AI providers: x.ai (Grok), OpenAI, Anthropic
16
- - ToolSet for function calling with JSON schema
17
- - AgentManager for easy integration
18
- - CLI tools for interactive use
19
- - WebSocket-based agent servers and clients for distributed setups
20
- - Session persistence under ./.cache/hello-dave/<agent-name>/
21
- - Built-in tools like JavaScript interpreter and bash execution
22
-
23
- Note: This is a personal project, created for convenience and exclusively used and tested on Debian/Ubuntu. 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. Prompt injection is a risk so use with care.
24
-
25
- ## Installation Notes
26
- The module is already installed in the current working directory. For manual installation in your project:
27
- ```bash
28
- npm install @j-o-r/hello-dave
29
- ```
30
-
31
- Requirements:
32
- - Node.js >= 20 (ESM only)
33
- - API keys via environment variables (set only what you use):
34
- - XAIKEY for x.ai (Grok)
35
- - OPENAIKEY for OpenAI
36
- - ANTHKEY for Anthropic
37
- - BRAVESEARCHKEY for Brave Search tool (optional)
38
-
39
- After installation, use either the programmatic API (AgentManager) or the provided CLIs.
40
-
41
- For development from repo:
42
- - npm install
43
- - export keys
44
- - node examples/grok.js # or add ./bin to PATH
45
-
46
- ## API Usage Examples
47
-
48
- ### Minimal Direct Call
49
- ```js
50
- import AgentManager from '@j-o-r/hello-dave';
51
-
52
- const agent = new AgentManager({ name: 'grok' });
53
- agent.setup({
54
- prompt: 'Be precise and concise.',
55
- api: 'grok',
56
- options: {
57
- model: 'grok-4',
58
- search_parameters: { mode: 'auto' }
59
- },
60
- toolsetMode: 'auto',
61
- contextWindow: 250_000
62
- });
63
-
64
- const answer = await agent.directCall('Two bullet points on tail recursion.');
65
- console.log(answer);
66
- ```
67
-
68
- ### Adding Custom Tools
69
- ```js
70
- const toolset = agent.getToolset();
71
- if (toolset) {
72
- toolset.add(
73
- 'say_hello',
74
- 'Return a friendly greeting',
75
- {
76
- type: 'object',
77
- properties: { name: { type: 'string', description: 'Who to greet' } },
78
- required: ['name']
79
- },
80
- async ({ name }) => `Hello, ${name}!`
81
- );
82
- }
83
- ```
84
-
85
- ### Running as Tool Server
86
- ```js
87
- agent.enableServer('search', 'General-purpose search interface', 8000);
88
- // WS on ws://127.0.0.1:8000/ws; connected clients become callable tools.
89
- ```
90
-
91
- ### Attaching as WS Client
92
- ```js
93
- agent.attach(
94
- 'code',
95
- 'Run JavaScript snippets safely and return output',
96
- 'ws://127.0.0.1:8000/ws'
97
- );
98
- ```
99
-
100
- ### CLI Example (from examples/grok.js)
101
- - Interactive: node examples/grok.js
102
- - One-shot: echo "question" | node examples/grok.js
103
- - With tools: node examples/grok.js --tools javascript,bash
104
- - Server: node examples/grok.js --serve 8000 --tools javascript,bash
105
- - Client: node examples/grok.js --connect ws://127.0.0.1:8000/ws
106
-
107
- ### Utils
108
- ```bash
109
- npx hdClear # Clear sessions and logs
110
- npx hdInspect [file.ndjson] # Read ndjson files
111
- npx hdPrompt # Design prompts (needs x.ai key)
112
- npx hdAsk # Ask generic question to GPT (needs OpenAI key)
113
- npx hdConnect [ws://url] # Connect to WS agent server
114
- ```
115
-
116
- ## Full API Reference
117
-
118
- ### AgentManager (main entry point)
119
- From types/AgentManager.d.ts
120
-
121
- **Constructor:**
122
- - `new AgentManager(options: Options)`: Create agent with name and optional cachePath.
123
-
124
- **Methods:**
125
- - `setup(setup: Setup): this`: Configure prompt, api, options, etc.
126
- - `startCli(description: string): void`: Start CLI for local usage.
127
- - `attach(name: string, description: string, url?: string): AgentClient`: Attach to WS server as client.
128
- - `enableServer(name: string, description?: string, port?: number): void`: Start WS server on localhost.
129
- - `directCall(input: string): Promise<string>`: Direct call to the prompt.
130
- - `getPrompt(): Prompt`: Get the Prompt instance.
131
- - `getToolset(): ToolSet | void`: Get the ToolSet if enabled.
132
- - `environment(): Promise<EnvironmentInfo>`: Get environment info.
133
- - `addGenericToolcall(name: string): void`: Add a generic tool call.
134
-
135
- **Types:**
136
- - `Options`: { name: string, cachePath?: string }
137
- - `Setup`: { prompt: string, options: OAOptions | XOptions | ANTHOptions, api: 'gpt' | 'grok' | 'claude', contextWindow?: number, toolsetMode?: 'auto' | 'required' | void, debug?: boolean }
138
-
139
- ### ToolSet
140
- From types/ToolSet.d.ts
141
-
142
- **Constructor:**
143
- - `new ToolSet(choice?: string)`: 'auto' | 'none' | 'required'
144
-
145
- **Properties:**
146
- - `length: number`: Number of registered functions.
147
- - `toolChoice: string`
148
-
149
- **Methods:**
150
- - `add(name: string, description: string, parameters: TSSchema, method: (arg0: object) => Promise<any>): void`: Register a tool.
151
- - `get(name: string): TSTool`: Get a tool.
152
- - `delete(name: string): void`: Remove a tool.
153
- - `has(name: string): boolean`: Check if tool exists.
154
- - `list(): TSToolListItem[]`: List all tools.
155
- - `call(name: string, params: object): Promise<any>`: Execute a tool.
156
- - `execute(prompt: Prompt): Promise<void>`: Execute tool calls from prompt.
157
-
158
- **Types:**
159
- - `TSSchema`: { type: string, properties: object, required?: string[] }
160
- - `TSTool`: { description: string, parameters: TSSchema, method: (arg0: object) => Promise<any> }
161
- - `TSToolListItem`: { name: string, description: string, parameters: TSSchema }
162
-
163
- ### Prompt
164
- From types/Prompt.d.ts (partial, large file)
165
-
166
- Handles uniform message format, function-call plumbing, truncation, provider-neutral calls.
167
-
168
- ### Other Classes
169
- - `AgentClient`: WS client for processing requests.
170
- - `AgentServer`: WS server that turns clients into ToolSet functions.
171
- - `Cli`: TUI with history, shortcuts (uses @j-o-r/cli internally).
172
- - `Session`: On-disk persistence for sessions, logs, records.
173
-
174
- ### API Adaptors
175
- - API/x.ai: For Grok
176
- - API/openai.com: For GPT
177
- - API/anthropic.com: For Claude
178
- - API/brave.com: For search tool
179
-
180
- ## Dependencies
181
- - **@j-o-r/apiserver**: ^2.1.5 - For HTTP/WS server functionality (see its module.md for details).
182
- - **@j-o-r/cli**: * - For CLI interface (interactive TUI with modes, questions, shortcuts).
183
- - **gpt-3-encoder**: * - For token encoding.
184
-
185
- Relevant dependency info:
186
- - @j-o-r/cli: Interactive CLI framework with mode-based output, command parsing, key mappings, spinners. Used for the built-in CLI tools.
187
- - @j-o-r/apiserver: Lightweight HTTP/WS server for API controllers, streaming, file serving. Used for WS agent servers.
188
-
189
- All dependencies are scoped under @j-o-r, personal modules.