@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.
- package/CHANGELOG.md +42 -25
- package/README.md +81 -221
- package/TODO.md +173 -35
- package/agents/agent_creator.js +105 -0
- package/agents/agent_creator.prompt.md +371 -0
- package/agents/ask_agent.js +64 -127
- package/agents/claude_agent.js +68 -0
- package/agents/code_agent.js +55 -135
- package/agents/code_agent.prompt.md +50 -0
- package/agents/echo_agent.js +76 -0
- package/agents/financial_expert.js +75 -0
- package/agents/gpt_agent.js +52 -103
- package/agents/gpt_code.js +81 -0
- package/agents/grok_agent.js +58 -114
- package/agents/minimax_agent.js +92 -0
- package/agents/mureka_agent.js +77 -0
- package/agents/planner_agent.js +172 -0
- package/agents/stability_agent.js +87 -0
- package/agents/test_agent.js +75 -157
- package/agents/weather_agent.js +73 -0
- package/agents/workflow_agent.js +189 -0
- package/bin/dave.js +436 -184
- package/docs/bin-dave.md +85 -35
- package/docs/cdn-ssh.md +100 -0
- package/docs/creating-agents.md +301 -0
- package/docs/creating-toolsets.md +336 -0
- package/docs/docs-organization.md +48 -0
- package/docs/project-overview.md +86 -51
- package/lib/API/elevenlabs.io/music.compose.md +441 -0
- package/lib/API/elevenlabs.io/music.create-composition-plan.md +370 -0
- package/lib/API/elevenlabs.io/music.stream.md +425 -0
- package/lib/API/lalal.ai/lalal.js +445 -0
- package/lib/API/lalal.ai/openapi.json +2614 -0
- package/lib/API/minimax/ImageToolset.js +82 -37
- package/lib/API/minimax/MusicToolset.js +125 -79
- package/lib/API/minimax/VideoToolset.js +170 -167
- package/lib/API/minimax/image.js +5 -1
- package/lib/API/minimax/music.js +210 -23
- package/lib/API/minimax/video.js +242 -53
- package/lib/API/mureka/MusicToolset.js +646 -0
- package/lib/API/mureka/README.md +41 -0
- package/lib/API/mureka/index.js +7 -0
- package/lib/API/mureka/music.js +658 -0
- package/lib/API/openai.com/index.js +7 -0
- package/lib/API/openai.com/{reponses/text.js → responses.js} +64 -18
- package/lib/API/openai.com/video.create.character.md +40 -0
- package/lib/API/openai.com/video.create.md +219 -0
- package/lib/API/openai.com/video.delete.md +44 -0
- package/lib/API/openai.com/video.download.md +31 -0
- package/lib/API/openai.com/video.edit.md +155 -0
- package/lib/API/openai.com/video.extend.md +166 -0
- package/lib/API/openai.com/video.fetch.character.md +43 -0
- package/lib/API/openai.com/video.js +784 -0
- package/lib/API/openai.com/video.list.md +201 -0
- package/lib/API/openai.com/video.remix.md +175 -0
- package/lib/API/openai.com/video.retrieve.md +139 -0
- package/lib/API/openai.com/videoToolset.js +616 -0
- package/lib/API/stability.ai/ImageToolset.js +131 -40
- package/lib/API/stability.ai/MusicToolset.js +79 -47
- package/lib/API/stability.ai/audio.js +63 -131
- package/lib/API/x.ai/chat.responses.md +1040 -0
- package/lib/API/x.ai/image.js +229 -59
- package/lib/API/x.ai/imageToolset.js +376 -0
- package/lib/API/x.ai/index.js +1 -3
- package/lib/API/x.ai/responses.js +9 -18
- package/lib/Agent.js +271 -0
- package/lib/Agent.js.old +284 -0
- package/lib/AgentLauncher.js +562 -0
- package/lib/Cli.js +87 -13
- package/lib/Prompt.js +23 -1
- package/lib/Session.js +5 -4
- package/lib/ToolSet.js +102 -6
- package/lib/agentLoader.js +369 -0
- package/lib/cdn.js +67 -231
- package/lib/{CdnToolset.js → cdnToolset.js} +47 -64
- package/lib/defaultToolsets.js +43 -0
- package/lib/fafs.js +1 -1
- package/lib/genericToolset.js +442 -119
- package/lib/handOffToolset.js +179 -0
- package/lib/index.js +34 -27
- package/lib/toolsetLoader.js +248 -0
- package/package.json +11 -5
- package/types/API/lalal.ai/lalal.d.ts +116 -0
- package/types/API/minimax/image.d.ts +2 -1
- package/types/API/minimax/music.d.ts +189 -26
- package/types/API/minimax/video.d.ts +100 -31
- package/types/API/mureka/index.d.ts +7 -0
- package/types/API/mureka/music.d.ts +472 -0
- package/types/API/openai.com/index.d.ts +7 -0
- package/types/API/openai.com/{reponses/text.d.ts → responses.d.ts} +11 -11
- package/types/API/openai.com/video.d.ts +409 -0
- package/types/API/openai.com/videoToolset.d.ts +24 -0
- package/types/API/stability.ai/audio.d.ts +14 -103
- package/types/API/stability.ai/image.d.ts +2 -2
- package/types/API/x.ai/image.d.ts +138 -26
- package/types/API/x.ai/imageToolset.d.ts +3 -0
- package/types/API/x.ai/index.d.ts +1 -3
- package/types/API/x.ai/responses.d.ts +4 -4
- package/types/Agent.d.ts +123 -0
- package/types/AgentLauncher.d.ts +222 -0
- package/types/Cli.d.ts +28 -8
- package/types/Prompt.d.ts +23 -5
- package/types/Session.d.ts +1 -1
- package/types/ToolSet.d.ts +10 -0
- package/types/agentLoader.d.ts +78 -0
- package/types/cdn.d.ts +15 -90
- package/types/defaultToolsets.d.ts +9 -0
- package/types/fafs.d.ts +1 -1
- package/types/genericToolset.d.ts +1 -1
- package/types/handOffToolset.d.ts +28 -0
- package/types/index.d.ts +19 -16
- package/types/toolsetLoader.d.ts +114 -0
- package/utils/format_log.js +101 -23
- package/utils/launch_agent.js +18 -0
- package/utils/list_sessions.sh +13 -5
- package/utils/search_sessions.sh +65 -29
- package/utils/toolsets.js +33 -0
- package/README.md.bak.1779452127 +0 -240
- package/agents/codeserver.sh +0 -47
- package/agents/daisy_agent.js +0 -173
- package/agents/docs_agent.js +0 -148
- package/agents/memory_agent.js +0 -263
- package/agents/minimax.js +0 -173
- package/agents/npm_agent.js +0 -202
- package/agents/prompt_agent.js +0 -133
- package/agents/readme_agent.js +0 -148
- package/agents/spawn_agent.js +0 -160
- package/agents/stability.js +0 -173
- package/agents/todo_agent.js +0 -175
- package/bin/codeDave +0 -58
- package/docs/agent-dave-websocket-protocol.md +0 -180
- package/docs/agent-manager.md +0 -244
- package/docs/codeserver-pattern.md +0 -191
- package/docs/generic-toolset.md +0 -326
- package/docs/howtos/agent-networking.md +0 -253
- package/docs/howtos/spawn-agents.md.bak +0 -200
- package/docs/howtos/spawn-agents.md.bak_new +0 -200
- package/docs/multi-agent-clusters.md +0 -265
- package/docs/music-toolsets.md +0 -137
- package/docs/path-resolution-best-practices.md +0 -104
- package/docs/plans/minimax-music-generation.md +0 -80
- package/docs/plans/unified-agent-architecture.md +0 -146
- package/docs/plans/websocket-streaming-plan.md.bak +0 -317
- package/docs/prompt/spawn_agent.md +0 -175
- package/docs/prompt/spawn_agent.md.bak +0 -201
- package/docs/prompt/task_clarification_and_documentation.md +0 -35
- package/docs/prompt-class.md +0 -141
- package/docs/todo-archive-infra-2026-04-21.md +0 -15
- package/docs/todo-archive-v0.0.8.md +0 -1
- package/docs/todo-archive-v0.1.0.md +0 -32
- package/docs/todo-archive.md +0 -44
- package/docs/tools-syntax-validation.md +0 -121
- package/docs/toolset.md +0 -164
- package/docs/xai-responses.md +0 -111
- package/docs/xai_collections.md +0 -106
- package/lib/API/x.ai/ImageToolset.js +0 -165
- package/lib/API/x.ai/text.js +0 -415
- package/lib/AgentClient.js +0 -248
- package/lib/AgentManager.js +0 -245
- package/lib/AgentServer.js +0 -404
- package/lib/wsCli.js +0 -287
- package/lib/wsIO.js +0 -90
- package/types/API/x.ai/text.d.ts +0 -286
- package/types/AgentClient.d.ts +0 -109
- package/types/AgentManager.d.ts +0 -100
- package/types/AgentServer.d.ts +0 -89
- package/types/wsCli.d.ts +0 -17
- package/types/wsIO.d.ts +0 -30
- package/utils/test.sh +0 -46
- /package/docs/{suggestions.md → _notes/token-counts.md} +0 -0
- /package/lib/API/openai.com/{reponses/MESSAGES.md → MESSAGES.md} +0 -0
- /package/types/API/{x.ai/ImageToolset.d.ts → mureka/MusicToolset.d.ts} +0 -0
- /package/types/{CdnToolset.d.ts → cdnToolset.d.ts} +0 -0
|
@@ -1,48 +1,107 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generates one or more images from a text prompt using Grok Imagine.
|
|
2
|
+
* Generates one or more images from a text prompt using Grok Imagine models.
|
|
3
|
+
*
|
|
4
|
+
* **Supported models** (current):
|
|
5
|
+
* - `grok-imagine-image-quality` — Recommended primary model.
|
|
6
|
+
* - `grok-imagine-image` — Alternative image model.
|
|
7
|
+
*
|
|
8
|
+
* Default: `grok-imagine-image-quality`.
|
|
9
|
+
*
|
|
10
|
+
* Supported features:
|
|
11
|
+
* - Up to 10 images per request (`n`)
|
|
12
|
+
* - Custom aspect ratios (see `image.to.generation.md` for the full table)
|
|
13
|
+
* - Resolutions: `1k` or `2k`
|
|
14
|
+
* - Response formats: `url` (temporary public URL) or `b64_json` (base64)
|
|
15
|
+
*
|
|
16
|
+
* All generated images are automatically saved to the local `.cache/xai/` directory.
|
|
17
|
+
* The function returns both the local path and the original API response data.
|
|
3
18
|
*
|
|
4
19
|
* @async
|
|
5
20
|
* @function generateImage
|
|
6
|
-
* @param {string} prompt - Detailed text prompt describing the desired image.
|
|
21
|
+
* @param {string} prompt - Detailed text prompt describing the desired image(s). Required.
|
|
7
22
|
* @param {Object} [options={}] - Optional generation parameters.
|
|
8
|
-
* @param {string} [options.model='grok-imagine-image-quality'] - Model
|
|
9
|
-
* @param {number} [options.n=1] - Number of images to generate
|
|
10
|
-
* @param {string} [options.response_format='url'] - `'url'` or `'b64_json'`.
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
23
|
+
* @param {string} [options.model='grok-imagine-image-quality'] - Model identifier. Supported values: `grok-imagine-image-quality` (recommended) or `grok-imagine-image`.
|
|
24
|
+
* @param {number} [options.n=1] - Number of images to generate. Range: 1–10. Default: 1.
|
|
25
|
+
* @param {string} [options.response_format='url'] - `'url'` (default) or `'b64_json'`.
|
|
26
|
+
* @param {string} [options.aspect_ratio] - Desired aspect ratio (e.g. `'16:9'`, `'1:1'`, `'auto'`).
|
|
27
|
+
* @param {string} [options.resolution] - Output resolution (`'1k'` or `'2k'`).
|
|
28
|
+
* @returns {Promise<Object>} Result object containing:
|
|
29
|
+
* - `local_path` (string) – absolute path to the saved file
|
|
30
|
+
* - `url` (string, if response_format=url) – temporary public URL
|
|
31
|
+
* - `base64` (string, if response_format=b64_json)
|
|
32
|
+
* - `revised_prompt` (string) – model-revised version of the prompt (if provided)
|
|
33
|
+
* - `raw` (Object) – full original API response
|
|
34
|
+
* @throws {Error} If `prompt` is missing/invalid, or on any API/network error.
|
|
13
35
|
*
|
|
14
36
|
* @example
|
|
37
|
+
* // Basic usage (uses recommended model)
|
|
15
38
|
* const result = await generateImage("A futuristic city at night");
|
|
16
39
|
* console.log(result.local_path);
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Multiple images with custom aspect ratio and resolution
|
|
43
|
+
* const results = await generateImage("Mountain landscape at sunrise", {
|
|
44
|
+
* n: 4,
|
|
45
|
+
* aspect_ratio: "16:9",
|
|
46
|
+
* resolution: "2k"
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Using the alternative model
|
|
51
|
+
* const result = await generateImage("...", { model: "grok-imagine-image" });
|
|
17
52
|
*/
|
|
18
53
|
export function generateImage(prompt: string, options?: {
|
|
19
54
|
model?: string | undefined;
|
|
20
55
|
n?: number | undefined;
|
|
21
56
|
response_format?: string | undefined;
|
|
57
|
+
aspect_ratio?: string | undefined;
|
|
58
|
+
resolution?: string | undefined;
|
|
22
59
|
}): Promise<Object>;
|
|
23
60
|
/**
|
|
24
61
|
* Edits one or more images using a natural language prompt.
|
|
25
|
-
*
|
|
62
|
+
*
|
|
63
|
+
* Supports up to 3 reference images for advanced compositing, style transfer,
|
|
64
|
+
* multi-subject scenes, or object insertion/removal.
|
|
65
|
+
*
|
|
66
|
+
* The model analyzes the provided image(s) and applies the edits described in the prompt.
|
|
67
|
+
*
|
|
68
|
+
* **Official API payload (per current xAI Inference API spec)**:
|
|
69
|
+
* - Single image: `"image": { "url": "...", "type": "image_url" }`
|
|
70
|
+
* - Multiple images (up to 3): `"images": [ { "url": "...", "type": "image_url" }, ... ]`
|
|
71
|
+
* (array of objects — **not** `image_urls`)
|
|
72
|
+
*
|
|
73
|
+
* When using multiple images, refer to them in the prompt as <IMAGE_0>, <IMAGE_1>, <IMAGE_2>, etc.
|
|
74
|
+
*
|
|
75
|
+
* **Supported models** (same as generation):
|
|
76
|
+
* - `grok-imagine-image-quality` (recommended)
|
|
77
|
+
* - `grok-imagine-image`
|
|
78
|
+
*
|
|
79
|
+
* All output images are automatically saved locally.
|
|
26
80
|
*
|
|
27
81
|
* @async
|
|
28
82
|
* @function editImage
|
|
29
|
-
* @param {string} prompt -
|
|
30
|
-
* @param {string|Buffer|Blob|Array<string|Buffer|Blob>} imageInputs - One or more images
|
|
83
|
+
* @param {string} prompt - Natural language description of the desired edit(s). Required.
|
|
84
|
+
* @param {string|Buffer|Blob|Array<string|Buffer|Blob>} imageInputs - One or more reference images.
|
|
85
|
+
* Accepts URLs, local paths, base64, Buffers, or Blobs. **Maximum: 3 images**.
|
|
31
86
|
* @param {Object} [options={}] - Optional parameters.
|
|
32
|
-
* @param {string} [options.model='grok-imagine-image-quality']
|
|
33
|
-
* @param {number} [options.n=1]
|
|
34
|
-
* @param {string} [options.response_format='url']
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
87
|
+
* @param {string} [options.model='grok-imagine-image-quality'] - Model identifier. Supported values: `grok-imagine-image-quality` (recommended) or `grok-imagine-image`.
|
|
88
|
+
* @param {number} [options.n=1] - Number of output images. Range: 1–10. Default: 1.
|
|
89
|
+
* @param {string} [options.response_format='url'] - `'url'` or `'b64_json'`.
|
|
90
|
+
* @param {string} [options.aspect_ratio] - Desired aspect ratio for output.
|
|
91
|
+
* @param {string} [options.resolution] - Output resolution (`'1k'` or `'2k'`).
|
|
92
|
+
* @returns {Promise<Object>} Result object (same shape as `generateImage`):
|
|
93
|
+
* - `local_path`, `url`/`base64`, `revised_prompt`, `raw`
|
|
94
|
+
* @throws {Error} If prompt or imageInputs are missing, more than 3 images are supplied,
|
|
95
|
+
* or on API/network error.
|
|
37
96
|
*
|
|
38
97
|
* @example
|
|
39
|
-
* // Single
|
|
98
|
+
* // Single-image edit (recommended model)
|
|
40
99
|
* const result = await editImage("Make this a pencil sketch", "./photo.png");
|
|
41
100
|
*
|
|
42
101
|
* @example
|
|
43
102
|
* // Multi-image editing (up to 3)
|
|
44
103
|
* const result = await editImage(
|
|
45
|
-
* "Combine
|
|
104
|
+
* "Combine <IMAGE_0> and <IMAGE_1> into one scene with a city background",
|
|
46
105
|
* ["./person1.png", "./person2.png"]
|
|
47
106
|
* );
|
|
48
107
|
*/
|
|
@@ -50,33 +109,86 @@ export function editImage(prompt: string, imageInputs: string | Buffer | Blob |
|
|
|
50
109
|
model?: string | undefined;
|
|
51
110
|
n?: number | undefined;
|
|
52
111
|
response_format?: string | undefined;
|
|
112
|
+
aspect_ratio?: string | undefined;
|
|
113
|
+
resolution?: string | undefined;
|
|
53
114
|
}): Promise<Object>;
|
|
54
115
|
/**
|
|
55
|
-
* Generates a video from a still image
|
|
56
|
-
*
|
|
57
|
-
*
|
|
116
|
+
* Generates a video from a still image + text motion prompt.
|
|
117
|
+
*
|
|
118
|
+
* This function is **fully automatic**: it posts to `/videos/generations` and then
|
|
119
|
+
* internally calls `pollVideoResult()` until the video is ready.
|
|
120
|
+
*
|
|
121
|
+
* **Supported model**: Only `grok-imagine-video` (the sole model for image-to-video generation).
|
|
122
|
+
*
|
|
123
|
+
* The provided image becomes the first frame; the prompt describes the desired motion/animation.
|
|
124
|
+
* Supports public URLs or base64 data URIs for the source image.
|
|
125
|
+
*
|
|
126
|
+
* Video parameters (from official docs):
|
|
127
|
+
* - `duration`: 1–15 seconds (affects pricing)
|
|
128
|
+
* - `aspect_ratio`, `resolution`
|
|
129
|
+
*
|
|
130
|
+
* **Important**: Video generation can take a long time and is prone to polling timeouts.
|
|
131
|
+
* Use the exported `pollVideoResult()` directly with higher `intervalMs`/`maxAttempts`
|
|
132
|
+
* if you encounter frequent timeouts.
|
|
58
133
|
*
|
|
59
134
|
* @async
|
|
60
135
|
* @function generateVideo
|
|
61
|
-
* @param {string} prompt - Description of the desired motion or animation.
|
|
62
|
-
* @param {string|Buffer|Blob} imageInput - Source image (URL, path, base64, Buffer, or Blob).
|
|
136
|
+
* @param {string} prompt - Description of the desired motion or animation. Required.
|
|
137
|
+
* @param {string|Buffer|Blob} imageInput - Source image (URL, local path, base64, Buffer, or Blob). Required.
|
|
63
138
|
* @param {Object} [options={}] - Optional video parameters.
|
|
64
|
-
* @param {
|
|
65
|
-
* @param {
|
|
139
|
+
* @param {string} [options.model='grok-imagine-video'] - Model identifier (only `grok-imagine-video` is supported).
|
|
140
|
+
* @param {number} [options.duration=8] - Video length in seconds (1–15). Default: 8.
|
|
141
|
+
* @param {string} [options.aspect_ratio='16:9'] - Aspect ratio for the video.
|
|
66
142
|
* @param {string} [options.resolution='720p'] - Output resolution.
|
|
67
|
-
* @returns {Promise<Object>} Result containing `local_path
|
|
68
|
-
* @throws {Error}
|
|
143
|
+
* @returns {Promise<Object>} Result containing `local_path`, `url`, `status: 'done'`, and `raw`.
|
|
144
|
+
* @throws {Error} If prompt or imageInput is missing, or on generation failure/timeout.
|
|
69
145
|
*
|
|
70
146
|
* @example
|
|
147
|
+
* // Basic usage with public image URL
|
|
71
148
|
* const result = await generateVideo(
|
|
72
149
|
* "Make the water crash down and slowly pan out",
|
|
73
150
|
* "https://example.com/waterfall.png",
|
|
74
151
|
* { duration: 12 }
|
|
75
152
|
* );
|
|
76
153
|
* console.log(result.local_path);
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Using a local file with custom aspect ratio
|
|
157
|
+
* const result = await generateVideo(
|
|
158
|
+
* "Animate the character walking forward",
|
|
159
|
+
* "./character.png",
|
|
160
|
+
* { duration: 10, aspect_ratio: "9:16" }
|
|
161
|
+
* );
|
|
77
162
|
*/
|
|
78
163
|
export function generateVideo(prompt: string, imageInput: string | Buffer | Blob, options?: {
|
|
164
|
+
model?: string | undefined;
|
|
79
165
|
duration?: number | undefined;
|
|
80
166
|
aspect_ratio?: string | undefined;
|
|
81
167
|
resolution?: string | undefined;
|
|
82
168
|
}): Promise<Object>;
|
|
169
|
+
/**
|
|
170
|
+
* Polls the xAI video status endpoint until generation completes or fails.
|
|
171
|
+
*
|
|
172
|
+
* This is an internal helper used by `generateVideo()`, but it is exported for
|
|
173
|
+
* advanced use cases where you want manual control over polling parameters.
|
|
174
|
+
*
|
|
175
|
+
* The xAI video endpoint returns `status: 'done'`, `'failed'`, or `'expired'`.
|
|
176
|
+
* On success it also provides `video.url`.
|
|
177
|
+
*
|
|
178
|
+
* **Timeout note**: Video generation can be slow. The default `intervalMs` was
|
|
179
|
+
* increased (and the function exported) to give callers more flexibility.
|
|
180
|
+
* Recommended values: `intervalMs` 15000–30000, `maxAttempts` 60+ for longer videos.
|
|
181
|
+
*
|
|
182
|
+
* @async
|
|
183
|
+
* @function pollVideoResult
|
|
184
|
+
* @param {string} requestId - The `request_id` returned from a `/videos/generations` call. Required.
|
|
185
|
+
* @param {number} [maxAttempts=60] - Maximum number of polling attempts. Default: 60.
|
|
186
|
+
* @param {number} [intervalMs=15000] - Milliseconds to wait between polls. Default: 15000.
|
|
187
|
+
* @returns {Promise<Object>} Result containing:
|
|
188
|
+
* - `local_path` (string) – path to the saved MP4
|
|
189
|
+
* - `url` (string) – public video URL
|
|
190
|
+
* - `status: 'done'`
|
|
191
|
+
* - `raw` (Object) – full response
|
|
192
|
+
* @throws {Error} On failure/expiration status, missing request_id, or polling timeout.
|
|
193
|
+
*/
|
|
194
|
+
export function pollVideoResult(requestId: string, maxAttempts?: number, intervalMs?: number): Promise<Object>;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
|
-
export let music: any;
|
|
3
|
-
export let musicToolset: any;
|
|
4
2
|
export { image };
|
|
5
3
|
export { imageToolset };
|
|
6
4
|
}
|
|
7
5
|
export default _default;
|
|
8
6
|
import * as image from './image.js';
|
|
9
|
-
import imageToolset from './
|
|
7
|
+
import imageToolset from './imageToolset.js';
|
|
@@ -29,7 +29,7 @@ export type XAIOptions = {
|
|
|
29
29
|
/**
|
|
30
30
|
* - Model version to use.
|
|
31
31
|
*/
|
|
32
|
-
model?: "grok-
|
|
32
|
+
model?: "grok-build-0.1" | "grok-4.3" | "grok-4.20" | "grok-4.20-multi-agent" | "grok-4.20-non-reasoning" | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* - Reusable prompt string.
|
|
35
35
|
*/
|
|
@@ -47,7 +47,7 @@ export type XAIOptions = {
|
|
|
47
47
|
*/
|
|
48
48
|
summary: "auto" | "concise" | "detailed";
|
|
49
49
|
} | undefined;
|
|
50
|
-
search?: "low" | "
|
|
50
|
+
search?: "low" | "medium" | "high" | undefined;
|
|
51
51
|
/**
|
|
52
52
|
* - Service tier option, default is auto-selected.
|
|
53
53
|
*/
|
|
@@ -94,7 +94,7 @@ export type XAIOptions = {
|
|
|
94
94
|
*/
|
|
95
95
|
top_p?: number | null | undefined;
|
|
96
96
|
/**
|
|
97
|
-
* - Needed
|
|
97
|
+
* - Needed response_id to validate tool calls on the next request
|
|
98
98
|
*/
|
|
99
99
|
previous_response_id?: string | null | undefined;
|
|
100
100
|
};
|
|
@@ -144,7 +144,7 @@ export type WebSearchFilters = {
|
|
|
144
144
|
/**
|
|
145
145
|
* - Context size; for OpenAI compatibility (reject if set).
|
|
146
146
|
*/
|
|
147
|
-
search_context_size?: "low" | "
|
|
147
|
+
search_context_size?: "low" | "medium" | "high" | null | undefined;
|
|
148
148
|
/**
|
|
149
149
|
* - User location; for OpenAI compatibility (reject if set).
|
|
150
150
|
*/
|
package/types/Agent.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export default Agent;
|
|
2
|
+
export type XAIOptions = import("./API/x.ai/responses.js").XAIOptions;
|
|
3
|
+
export type OAOptions = any;
|
|
4
|
+
export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
5
|
+
export type AgentConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* - Initial system prompt (can be loaded via Agent.loadPrompt for extended agents)
|
|
8
|
+
*/
|
|
9
|
+
prompt: string;
|
|
10
|
+
/**
|
|
11
|
+
* - Chat adaptor function from API.chat.* (e.g. API.chat.xai)
|
|
12
|
+
*/
|
|
13
|
+
api: Function;
|
|
14
|
+
/**
|
|
15
|
+
* - Model options
|
|
16
|
+
*/
|
|
17
|
+
options?: XAIOptions | OAOptions | Object;
|
|
18
|
+
contextWindow?: number | undefined;
|
|
19
|
+
toolsetMode?: "auto" | "required" | null | undefined;
|
|
20
|
+
debug?: boolean | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* - Plain text secret (will be base64 encoded internally)
|
|
23
|
+
*/
|
|
24
|
+
secret?: string | undefined;
|
|
25
|
+
cachePath?: string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* - Agent/tool name (required). Must match /^[a-z0-9_]{2,}$/. Recommended: derive via Agent.deriveCallName(import.meta.url)
|
|
28
|
+
*/
|
|
29
|
+
call_name: string;
|
|
30
|
+
/**
|
|
31
|
+
* - Description for the tool (required, non-empty string)
|
|
32
|
+
*/
|
|
33
|
+
call_description: string;
|
|
34
|
+
/**
|
|
35
|
+
* - CLI intro message (stored for future use)
|
|
36
|
+
*/
|
|
37
|
+
cliIntro?: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
declare class Agent {
|
|
40
|
+
/**
|
|
41
|
+
* Derives the canonical `call_name` from the agent's own filename.
|
|
42
|
+
* This makes the **filename the single source of truth** for the agent name.
|
|
43
|
+
*
|
|
44
|
+
* Recommended usage in every agent:
|
|
45
|
+
* const call_name = Agent.deriveCallName(import.meta.url);
|
|
46
|
+
*
|
|
47
|
+
* @param {string} importMetaUrl - Always pass `import.meta.url` from the agent module.
|
|
48
|
+
* @returns {string} The derived call_name (basename without extension)
|
|
49
|
+
* @throws {Error} If the derived name is invalid.
|
|
50
|
+
*/
|
|
51
|
+
static deriveCallName(importMetaUrl: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Loads the external system prompt for "extended" agents.
|
|
54
|
+
*
|
|
55
|
+
* Looks for a pure Markdown sibling prompt file in the same directory as the
|
|
56
|
+
* calling agent. The filename is always `<call_name>.prompt.md`, where
|
|
57
|
+
* `call_name` is derived from the calling agent filename.
|
|
58
|
+
*
|
|
59
|
+
* Two common patterns:
|
|
60
|
+
*
|
|
61
|
+
* 1. Simple one-file agent (internal prompt):
|
|
62
|
+
* const prompt = `You are ...`; // define inline
|
|
63
|
+
*
|
|
64
|
+
* 2. Extended agent (external Markdown prompt):
|
|
65
|
+
* const prompt = await Agent.loadPrompt(import.meta.url);
|
|
66
|
+
* // Automatically loads ./<call_name>.prompt.md as UTF-8 text.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} importMetaUrl - Pass `import.meta.url` from the agent module.
|
|
69
|
+
* @param {Object} [options]
|
|
70
|
+
* @param {boolean} [options.required=true] - If true, throws when no external prompt file is found.
|
|
71
|
+
* @param {string|null} [options.fallback=null] - Prompt to return if no external file is found and required=false.
|
|
72
|
+
* @returns {Promise<string>} The Markdown prompt content (trimmed).
|
|
73
|
+
* @throws {Error} When required=true and no prompt file can be found, or when the prompt file cannot be read.
|
|
74
|
+
*/
|
|
75
|
+
static loadPrompt(importMetaUrl: string, options?: {
|
|
76
|
+
required?: boolean | undefined;
|
|
77
|
+
fallback?: string | null | undefined;
|
|
78
|
+
}): Promise<string>;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new Agent instance.
|
|
81
|
+
* Minimal core skeleton (no run(), no CLI parsing, no server/client logic).
|
|
82
|
+
* All configuration is passed via the constructor.
|
|
83
|
+
* Designed to be used by AgentLauncher and for clean handoff support.
|
|
84
|
+
*
|
|
85
|
+
* @param {AgentConfig} config
|
|
86
|
+
*/
|
|
87
|
+
constructor(config?: AgentConfig);
|
|
88
|
+
/**
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
info(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Direct synchronous call to the underlying Prompt.
|
|
94
|
+
* @param {string} input - User input.
|
|
95
|
+
* @returns {Promise<string>} Response.
|
|
96
|
+
*/
|
|
97
|
+
directCall(input: string): Promise<string>;
|
|
98
|
+
/** @returns {Prompt} Underlying Prompt instance. */
|
|
99
|
+
getPrompt(): Prompt;
|
|
100
|
+
/** @returns {Session} Underlying Session instance (for CLI and handoff support). */
|
|
101
|
+
getSession(): Session;
|
|
102
|
+
/** @returns {ToolSet|null} Toolset if configured. */
|
|
103
|
+
getToolset(): ToolSet | null;
|
|
104
|
+
/** @returns {string} Agent name (from call_name). */
|
|
105
|
+
get name(): string;
|
|
106
|
+
/** @returns {string} Agent description. */
|
|
107
|
+
get description(): string;
|
|
108
|
+
/** @returns {string} CLI intro (if provided). */
|
|
109
|
+
get cliIntro(): string;
|
|
110
|
+
/** @returns {string} Base64-encoded secret (if provided). */
|
|
111
|
+
get secret(): string;
|
|
112
|
+
/** @returns {string} Cache path. */
|
|
113
|
+
get cachePath(): string;
|
|
114
|
+
/** @returns {number} Context window size. */
|
|
115
|
+
get contextWindow(): number;
|
|
116
|
+
/** @returns {string} Model name (if set via options). */
|
|
117
|
+
get model(): string;
|
|
118
|
+
destructor(): void;
|
|
119
|
+
#private;
|
|
120
|
+
}
|
|
121
|
+
import Prompt from './Prompt.js';
|
|
122
|
+
import Session from './Session.js';
|
|
123
|
+
import ToolSet from './ToolSet.js';
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
export default AgentLauncher;
|
|
2
|
+
/**
|
|
3
|
+
* @module AgentLauncher
|
|
4
|
+
*
|
|
5
|
+
* AgentLauncher provides a clean, reusable way to discover, load, run, and
|
|
6
|
+
* hand-off between "clean" Agent instances (those built with the unified
|
|
7
|
+
* Agent class and exported via `export default agent;`).
|
|
8
|
+
*
|
|
9
|
+
* Primary responsibilities:
|
|
10
|
+
* - Discovery: `list()` returns all agents found in the standard locations
|
|
11
|
+
* without importing them (now includes a short `desc`).
|
|
12
|
+
* - Loading: `load(name)` resolves, imports, and validates a clean Agent.
|
|
13
|
+
* - Execution: `run()` handles CLI argument parsing, one-shot calls,
|
|
14
|
+
* --help/--info, and interactive CLI startup.
|
|
15
|
+
* - In-process handoff: Listens for the 'agent:handoff' event on the active
|
|
16
|
+
* Prompt and seamlessly swaps the active agent (including rebinding the
|
|
17
|
+
* single long-lived Cli instance when in interactive mode).
|
|
18
|
+
*
|
|
19
|
+
* Design highlights:
|
|
20
|
+
* - A single Cli instance is kept for the lifetime of the launcher in
|
|
21
|
+
* interactive mode. On handoff we call `cli.rebind(...)` instead of
|
|
22
|
+
* creating a new Cli (which would duplicate global key handlers).
|
|
23
|
+
* - Handoffs are always "fresh": the new agent starts with only its own
|
|
24
|
+
* system prompt + the provided context. No conversation history is copied.
|
|
25
|
+
* - Same-name "handoff" (self-reset) is supported as a deliberate fresh-start
|
|
26
|
+
* / token-reduction mechanism. The current agent is fully replaced with a
|
|
27
|
+
* newly loaded instance of itself + the new focused context.
|
|
28
|
+
* - Old agents are cleaned up via `destructor()` (removes listeners, aids GC).
|
|
29
|
+
* - Works for both interactive CLI and non-interactive / one-shot usage.
|
|
30
|
+
*
|
|
31
|
+
* Typical usage (from user code or a thin launcher script):
|
|
32
|
+
* ```js
|
|
33
|
+
* import { AgentLauncher } from '@j-o-r/hello-dave';
|
|
34
|
+
*
|
|
35
|
+
* const launcher = new AgentLauncher();
|
|
36
|
+
* const agents = await launcher.list();
|
|
37
|
+
* await launcher.load('code_agent');
|
|
38
|
+
* await launcher.run(); // handles argv, one-shot, or interactive CLI
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Thin launcher example (agents/code_launcher.js style):
|
|
42
|
+
* ```js
|
|
43
|
+
* import AgentLauncher from '../lib/AgentLauncher.js';
|
|
44
|
+
* const launcher = new AgentLauncher();
|
|
45
|
+
* await launcher.load('code_agent');
|
|
46
|
+
* await launcher.run();
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Handoff support is automatic once an agent registers the hand_over / load_agent
|
|
50
|
+
* tools (see lib/handOffToolset.js and agents that call
|
|
51
|
+
* `toolset.addFrom(API.toolset.generic.handoff, 'hand_over')`).
|
|
52
|
+
*
|
|
53
|
+
* @see Agent
|
|
54
|
+
* @see agentLoader
|
|
55
|
+
* @see handOffToolset
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* The main launcher for clean Agent-based agents.
|
|
59
|
+
*
|
|
60
|
+
* @class AgentLauncher
|
|
61
|
+
*/
|
|
62
|
+
declare class AgentLauncher {
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new AgentLauncher.
|
|
65
|
+
*
|
|
66
|
+
* Pass `{ from: import.meta.url }` from the consuming project to resolve
|
|
67
|
+
* project-local agents relative to that project's nearest package.json.
|
|
68
|
+
*
|
|
69
|
+
* @constructor
|
|
70
|
+
* @param {import('./agentLoader.js').AgentLoaderOptions} [options={}] - Loader options.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const launcher = new AgentLauncher({ from: import.meta.url });
|
|
74
|
+
* await launcher.load('weather_agent');
|
|
75
|
+
* await launcher.run();
|
|
76
|
+
*/
|
|
77
|
+
constructor(options?: import("./agentLoader.js").AgentLoaderOptions);
|
|
78
|
+
/**
|
|
79
|
+
* List all discoverable agents without loading or executing any of them.
|
|
80
|
+
*
|
|
81
|
+
* Performs a lightweight filesystem scan of the configured agent directory.
|
|
82
|
+
* For each agent it attempts a safe import to extract
|
|
83
|
+
* a short description (`desc`). Incompatible agents or agents that throw
|
|
84
|
+
* on import (side effects, top-level `await agent.run()`, missing exports, etc.)
|
|
85
|
+
* receive `desc: '[ERROR]'`.
|
|
86
|
+
*
|
|
87
|
+
* Search location when constructed with `{ from: import.meta.url }`:
|
|
88
|
+
* 1. <nearest-package-root-from-from>/agents/
|
|
89
|
+
*
|
|
90
|
+
* Only files whose basename matches the valid agent name pattern are returned.
|
|
91
|
+
* See `lib/agentLoader.js` for the exact regex (`validAgentNameRegex`).
|
|
92
|
+
*
|
|
93
|
+
* @async
|
|
94
|
+
* @returns {Promise<Array<{name: string, path: string, desc: string}>>}
|
|
95
|
+
* Array of discovered agents. Each object contains:
|
|
96
|
+
* - `name`: the agent identifier (basename without `.js`)
|
|
97
|
+
* - `path`: absolute path to the agent module on disk
|
|
98
|
+
* - `desc`: short description (from the agent's `description` / `call_description`),
|
|
99
|
+
* or the literal string `'[ERROR]'` when the agent is incompatible or fails to load
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const launcher = new AgentLauncher();
|
|
103
|
+
* const list = await launcher.list();
|
|
104
|
+
* console.log(list);
|
|
105
|
+
* // [
|
|
106
|
+
* // { name: 'code_agent', path: '/.../agents/code_agent.js', desc: 'Main coding expert. Handles implementation...' },
|
|
107
|
+
* // { name: 'weather_agent', path: '/.../agents/weather_agent.js', desc: 'Weather Agent: Specialized in current weather...' },
|
|
108
|
+
* // { name: 'test_agent', path: '/.../agents/test_agent.js', desc: '[ERROR]' },
|
|
109
|
+
* // ...
|
|
110
|
+
* // ]
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* // Just the names + descriptions
|
|
114
|
+
* const summary = (await launcher.list()).map(a => `${a.name}: ${a.desc}`);
|
|
115
|
+
*
|
|
116
|
+
* @see module:agentLoader#listAgents
|
|
117
|
+
*/
|
|
118
|
+
list(): Promise<Array<{
|
|
119
|
+
name: string;
|
|
120
|
+
path: string;
|
|
121
|
+
desc: string;
|
|
122
|
+
}>>;
|
|
123
|
+
/**
|
|
124
|
+
* Load a clean Agent by name and make it the active agent.
|
|
125
|
+
*
|
|
126
|
+
* If `agentName` is omitted, it is read from the first non-flag positional
|
|
127
|
+
* argument in `process.argv` (after the script name).
|
|
128
|
+
*
|
|
129
|
+
* Internally delegates to `loadAgent()` from the agent loader, which:
|
|
130
|
+
* - Resolves the module path (same configured directory as `list()`)
|
|
131
|
+
* - Dynamically imports the module
|
|
132
|
+
* - Extracts the default export (or factory function)
|
|
133
|
+
* - Validates that the result is a proper Agent instance
|
|
134
|
+
*
|
|
135
|
+
* After successful load, the previous active agent (if any) is cleaned up
|
|
136
|
+
* via its `destructor()` method, and the new agent's 'agent:handoff' listener
|
|
137
|
+
* is attached.
|
|
138
|
+
*
|
|
139
|
+
* @async
|
|
140
|
+
* @param {string} [agentName] - Name of the agent to load (e.g. "code_agent").
|
|
141
|
+
* Must be a valid agent name (see agentLoader.js for the pattern).
|
|
142
|
+
* If omitted, read from process.argv.
|
|
143
|
+
* @param {Array<any>} [extraArgs=[]] - Optional arguments passed through to
|
|
144
|
+
* the agent module if it exports a factory function instead of an instance.
|
|
145
|
+
* @returns {Promise<AgentLauncher>} Returns `this` for chaining.
|
|
146
|
+
* @throws {Error} If no agent name can be determined, or if loading/validation fails.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const launcher = new AgentLauncher();
|
|
150
|
+
* await launcher.load('code_agent');
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // Load from argv (typical when used from a thin launcher script)
|
|
154
|
+
* await launcher.load(); // reads first positional from process.argv
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* // With extra args for a factory-style agent
|
|
158
|
+
* await launcher.load('my_agent', ['--debug']);
|
|
159
|
+
*
|
|
160
|
+
* @see module:agentLoader#loadAgent
|
|
161
|
+
* @see #_setActiveAgent
|
|
162
|
+
*/
|
|
163
|
+
load(agentName?: string, extraArgs?: Array<any>): Promise<AgentLauncher>;
|
|
164
|
+
/**
|
|
165
|
+
* Main entry point. Orchestrates argument parsing and execution mode.
|
|
166
|
+
*
|
|
167
|
+
* Behavior (checked in this order):
|
|
168
|
+
* 1. `--help` → Print usage and return.
|
|
169
|
+
* 2. `--info` → Print agent.info() (or raw agent) and return.
|
|
170
|
+
* 3. If no active agent → automatically call `load()` (reads from argv).
|
|
171
|
+
* 4. One-shot mode: if a second positional argument exists after the agent
|
|
172
|
+
* name, treat the rest of the line as a message and call
|
|
173
|
+
* `activeAgent.directCall(message)`.
|
|
174
|
+
* 5. Default: start interactive CLI via `#startCli()`.
|
|
175
|
+
*
|
|
176
|
+
* @async
|
|
177
|
+
* @returns {Promise<any>} In one-shot mode, returns the result of directCall.
|
|
178
|
+
* In other modes, returns undefined.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* // From a thin launcher script that already called load()
|
|
182
|
+
* await launcher.run();
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* // One-shot usage (message after agent name)
|
|
186
|
+
* // node ... code_agent "Refactor the Session class"
|
|
187
|
+
* const result = await launcher.run();
|
|
188
|
+
*
|
|
189
|
+
* @see #load
|
|
190
|
+
* @see #_startCli
|
|
191
|
+
*/
|
|
192
|
+
run(): Promise<any>;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the currently active Agent instance (or null if none loaded).
|
|
195
|
+
*
|
|
196
|
+
* @returns {Agent|null}
|
|
197
|
+
*/
|
|
198
|
+
getActiveAgent(): Agent | null;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the Prompt belonging to the active agent (or null).
|
|
201
|
+
*
|
|
202
|
+
* Useful for advanced scenarios where you need direct access to the
|
|
203
|
+
* underlying prompt (e.g. to listen to events manually).
|
|
204
|
+
*
|
|
205
|
+
* @returns {import('./Prompt.js').default|null}
|
|
206
|
+
*/
|
|
207
|
+
getPrompt(): import("./Prompt.js").default | null;
|
|
208
|
+
/**
|
|
209
|
+
* Returns the Session belonging to the active agent (or null).
|
|
210
|
+
*
|
|
211
|
+
* @returns {import('./Session.js').default|null}
|
|
212
|
+
*/
|
|
213
|
+
getSession(): import("./Session.js").default | null;
|
|
214
|
+
/**
|
|
215
|
+
* The name of the currently active agent (or 'no_name' if none loaded).
|
|
216
|
+
*
|
|
217
|
+
* @type {string}
|
|
218
|
+
*/
|
|
219
|
+
get name(): string;
|
|
220
|
+
#private;
|
|
221
|
+
}
|
|
222
|
+
import Agent from './Agent.js';
|