@j-o-r/hello-dave 0.1.1 → 0.1.5

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 -1
  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 +593 -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 +10 -4
  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 -1
  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 +250 -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 -17
  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
@@ -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 to use.
9
- * @param {number} [options.n=1] - Number of images to generate (1–10).
10
- * @param {string} [options.response_format='url'] - `'url'` or `'b64_json'`.
11
- * @returns {Promise<Object>} Result containing `local_path`, `url` (or `base64`), and metadata.
12
- * @throws {Error} On missing prompt or API errors.
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
- * Supports up to 3 reference images for compositing, style transfer, or multi-subject scenes.
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 - Description of the desired edit.
30
- * @param {string|Buffer|Blob|Array<string|Buffer|Blob>} imageInputs - One or more images (URL, path, base64, Buffer, or Blob).
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
- * @returns {Promise<Object>} Result with edited image.
36
- * @throws {Error} If more than 3 images are provided or on API error.
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 image edit
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 these two people into one scene",
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 and text prompt.
56
- * This function is fully automatic — it submits the request and polls internally
57
- * until the video is ready before returning.
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 {number} [options.duration=8] - Video duration in seconds.
65
- * @param {string} [options.aspect_ratio='16:9'] - Aspect ratio.
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` and `url` of the generated video.
68
- * @throws {Error} On missing inputs or generation failure.
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>;
@@ -0,0 +1,3 @@
1
+ export default tools;
2
+ declare const tools: ToolSet;
3
+ import ToolSet from '../../ToolSet.js';
@@ -4,4 +4,4 @@ declare namespace _default {
4
4
  }
5
5
  export default _default;
6
6
  import * as image from './image.js';
7
- import imageToolset from './ImageToolset.js';
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-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning" | "grok-code-fast-1" | "grok-4-fast-reasoning" | "grok-4-fast-non-reasoning" | undefined;
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" | "high" | "medium" | undefined;
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 reponse_id to validate tool calls on the next request
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" | "high" | "medium" | null | undefined;
147
+ search_context_size?: "low" | "medium" | "high" | null | undefined;
148
148
  /**
149
149
  * - User location; for OpenAI compatibility (reject if set).
150
150
  */
@@ -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,250 @@
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
+ * Directly assign an already-created Agent instance as the active agent.
201
+ *
202
+ * This is the programmatic alternative to `load()`. Use it when the caller
203
+ * has constructed an agent manually, or when testing an agent module that is
204
+ * outside the configured agent loader search paths.
205
+ *
206
+ * The previous active agent, if any, is cleaned up via `destructor()`. The new
207
+ * agent becomes the launcher's active agent and has the launcher's
208
+ * `agent:handoff` listener attached to its Prompt, just like agents loaded via
209
+ * `load()`.
210
+ *
211
+ * The supplied agent is assumed to be a valid `Agent` instance. Unlike
212
+ * `load()`, this method does not resolve, import, or validate an agent module
213
+ * through the configured agent loader.
214
+ *
215
+ * @param {Agent} newAgent - Existing Agent instance to make active.
216
+ * @returns {AgentLauncher} Returns `this` for chaining.
217
+ *
218
+ * @example
219
+ * const launcher = new AgentLauncher();
220
+ * launcher.setActiveAgent(agent);
221
+ * await launcher.run();
222
+ *
223
+ * @see #load
224
+ * @see #getActiveAgent
225
+ */
226
+ setActiveAgent(newAgent: Agent): AgentLauncher;
227
+ /**
228
+ * Returns the Prompt belonging to the active agent (or null).
229
+ *
230
+ * Useful for advanced scenarios where you need direct access to the
231
+ * underlying prompt (e.g. to listen to events manually).
232
+ *
233
+ * @returns {import('./Prompt.js').default|null}
234
+ */
235
+ getPrompt(): import("./Prompt.js").default | null;
236
+ /**
237
+ * Returns the Session belonging to the active agent (or null).
238
+ *
239
+ * @returns {import('./Session.js').default|null}
240
+ */
241
+ getSession(): import("./Session.js").default | null;
242
+ /**
243
+ * The name of the currently active agent (or 'no_name' if none loaded).
244
+ *
245
+ * @type {string}
246
+ */
247
+ get name(): string;
248
+ #private;
249
+ }
250
+ import Agent from './Agent.js';