@j-o-r/hello-dave 0.1.1 → 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 -1
- 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 -1
- 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 -17
- 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
package/lib/wsCli.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Interactive WebSocket CLI client for hello-dave agent servers.
|
|
4
|
-
* Features: auto-reconnect, keyboard shortcuts (ALT-C/R/I/S/M, CTRL-K),
|
|
5
|
-
* session management, message history, clipboard copy.
|
|
6
|
-
*
|
|
7
|
-
* Depends on @j-o-r/cli for terminal UI, @j-o-r/apiserver WebSocketClient, @j-o-r/sh for shell.
|
|
8
|
-
*/
|
|
9
|
-
import cli from '@j-o-r/cli';
|
|
10
|
-
import { WebSocketClient } from "@j-o-r/apiserver";
|
|
11
|
-
import { SH } from '@j-o-r/sh';
|
|
12
|
-
|
|
13
|
-
const OPEN = 1; // WebSocket.OPEN
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {Object} WsMessage
|
|
17
|
-
* @property {string} action - Action type (e.g., 'user_request')
|
|
18
|
-
* @property {string} content - Message content
|
|
19
|
-
* @property {number} id - Unique message ID
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Copy text to the clipboard using xclip.
|
|
24
|
-
* @param {string} text - Text to copy
|
|
25
|
-
* @returns {Promise<void>}
|
|
26
|
-
*/
|
|
27
|
-
const copyToClipboard = async (text) => {
|
|
28
|
-
if (typeof text !== 'string') return;
|
|
29
|
-
if (text === '') text = ' ';
|
|
30
|
-
const prams = ['-selection', 'clipboard'];
|
|
31
|
-
await SH`xclip ${prams}`.options({ stdio: 'inherit' }).run(text);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Launches an interactive CLI client connected to a hello-dave agent server via WebSocket.
|
|
36
|
-
* Establishes persistent connection with auto-reconnect, handles user input,
|
|
37
|
-
* keyboard shortcuts for common actions, and displays responses.
|
|
38
|
-
*
|
|
39
|
-
* Keyboard shortcuts:
|
|
40
|
-
* - ALT-C: Clear screen
|
|
41
|
-
* - ALT-R: Reset session
|
|
42
|
-
* - ALT-S: List/load sessions
|
|
43
|
-
* - ALT-I: Server info
|
|
44
|
-
* - ALT-M: Copy last message to clipboard
|
|
45
|
-
* - CTRL-K: Show help
|
|
46
|
-
* - CTRL-D: Exit (standard)
|
|
47
|
-
*
|
|
48
|
-
* @param {string} connectUrl - WebSocket server endpoint (e.g., 'ws://localhost:8080')
|
|
49
|
-
* @param {string} [secret=''] - Optional base64 secret for authenticated connections
|
|
50
|
-
* @returns {void}
|
|
51
|
-
* @example
|
|
52
|
-
* import wsCli from './lib/wsCli.js';
|
|
53
|
-
* wsCli('ws://localhost:8080', 'mysecret');
|
|
54
|
-
*/
|
|
55
|
-
export default (connectUrl, secret = '') => {
|
|
56
|
-
let ws;
|
|
57
|
-
let busy = false;
|
|
58
|
-
let lastMessage = '';
|
|
59
|
-
const pendingRequests = new Map();
|
|
60
|
-
if (secret !== '') {
|
|
61
|
-
secret = Buffer.from(secret).toString('base64');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Connects (or reconnects) to the WebSocket server.
|
|
66
|
-
* Sets up event handlers for messages, close (auto-reconnect), errors.
|
|
67
|
-
* Sends user_introduction on open.
|
|
68
|
-
*
|
|
69
|
-
* @private
|
|
70
|
-
* @returns {void}
|
|
71
|
-
*/
|
|
72
|
-
const connect = () => {
|
|
73
|
-
if (ws && ws.readyState === OPEN) {
|
|
74
|
-
console.log('Already connected');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const url = connectUrl + '?wssrc_id=' + secret;
|
|
78
|
-
console.log(`Connecting to ${url}`);
|
|
79
|
-
ws = new WebSocketClient(url);
|
|
80
|
-
|
|
81
|
-
ws.onopen = () => {
|
|
82
|
-
console.log('Connected to server');
|
|
83
|
-
// Send introduction (no pending request for this)
|
|
84
|
-
const id = Date.now();
|
|
85
|
-
ws.send(JSON.stringify({
|
|
86
|
-
action: 'user_introduction',
|
|
87
|
-
content: '',
|
|
88
|
-
id
|
|
89
|
-
}));
|
|
90
|
-
cli.focus('user', true);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
ws.onmessage = (m) => {
|
|
94
|
-
try {
|
|
95
|
-
const data = JSON.parse(m.data);
|
|
96
|
-
const msgId = data.id;
|
|
97
|
-
if (msgId && pendingRequests.has(msgId)) {
|
|
98
|
-
const { resolve, timeout } = pendingRequests.get(msgId);
|
|
99
|
-
clearTimeout(timeout);
|
|
100
|
-
pendingRequests.delete(msgId);
|
|
101
|
-
resolve(data);
|
|
102
|
-
}
|
|
103
|
-
// Ignore unsolicited messages for now
|
|
104
|
-
} catch (e) {
|
|
105
|
-
console.error('Error parsing WebSocket message:', e, m.data);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
ws.onclose = (event) => {
|
|
110
|
-
console.log('Connection closed (reconnecting in 5s):', event.code, event.reason || 'No reason');
|
|
111
|
-
// Reject all pending requests
|
|
112
|
-
for (const [id, { reject, timeout }] of pendingRequests) {
|
|
113
|
-
clearTimeout(timeout);
|
|
114
|
-
reject(new Error(`Connection closed (${event.code})`));
|
|
115
|
-
pendingRequests.delete(id);
|
|
116
|
-
}
|
|
117
|
-
// Auto-reconnect
|
|
118
|
-
setTimeout(connect, 5000);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
ws.onerror = (event) => {
|
|
122
|
-
console.error('WebSocket error:', event.toString());
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Sends a message and awaits response by ID.
|
|
128
|
-
* Handles special response actions (e.g., server_response updates UI).
|
|
129
|
-
* Manages busy state and spinner.
|
|
130
|
-
*
|
|
131
|
-
* @private
|
|
132
|
-
* @param {WsMessage} message - Message to send (id auto-added)
|
|
133
|
-
* @returns {Promise<WsMessage>} Response data
|
|
134
|
-
* @throws {Error} If not connected, timeout (12h), or connection error
|
|
135
|
-
*/
|
|
136
|
-
const sendMessage = async (message) => {
|
|
137
|
-
if (!ws || ws.readyState !== OPEN) {
|
|
138
|
-
throw new Error('WebSocket not connected');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const id = Date.now();
|
|
142
|
-
message.id = id;
|
|
143
|
-
busy = true;
|
|
144
|
-
cli.startSpinner();
|
|
145
|
-
|
|
146
|
-
const promise = new Promise((resolve, reject) => {
|
|
147
|
-
const timeout = setTimeout(() => {
|
|
148
|
-
if (pendingRequests.has(id)) {
|
|
149
|
-
pendingRequests.delete(id);
|
|
150
|
-
reject(new Error('Request timeout (12 hours)'));
|
|
151
|
-
}
|
|
152
|
-
}, 1000 * 60 * 60 * 12); // 12 hours
|
|
153
|
-
pendingRequests.set(id, { resolve, reject, timeout });
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
ws.send(JSON.stringify(message));
|
|
158
|
-
const response = await promise;
|
|
159
|
-
|
|
160
|
-
// Handle specific response actions
|
|
161
|
-
if (response.action === 'server_response') {
|
|
162
|
-
cli.focus('assistant');
|
|
163
|
-
cli.write(response.content);
|
|
164
|
-
lastMessage = response.content;
|
|
165
|
-
} else if (response.action === 'server_info') {
|
|
166
|
-
cli.focus('util');
|
|
167
|
-
cli.write(response.content);
|
|
168
|
-
} else if (response.action === 'server_reset') {
|
|
169
|
-
cli.clear();
|
|
170
|
-
} else if (response.action === 'server_sessionlist') {
|
|
171
|
-
const list = response.content;
|
|
172
|
-
const selected = await cli.select('Select your session: ', list);
|
|
173
|
-
if (selected && selected !== 'NONE') {
|
|
174
|
-
await sendMessage({ action: 'user_loadsession', content: selected });
|
|
175
|
-
}
|
|
176
|
-
} else if (response.action === 'server_sessionloaded') {
|
|
177
|
-
cli.clear();
|
|
178
|
-
const messages = response.content;
|
|
179
|
-
messages.forEach((msg) => {
|
|
180
|
-
cli.focus(msg.role);
|
|
181
|
-
cli.write(msg.content);
|
|
182
|
-
lastMessage = msg.content;
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
// Other actions ignored
|
|
186
|
-
return response;
|
|
187
|
-
} catch (e) {
|
|
188
|
-
console.error('Request error:', e.message);
|
|
189
|
-
} finally {
|
|
190
|
-
if (pendingRequests.has(id)) {
|
|
191
|
-
const { timeout } = pendingRequests.get(id);
|
|
192
|
-
clearTimeout(timeout);
|
|
193
|
-
pendingRequests.delete(id);
|
|
194
|
-
}
|
|
195
|
-
busy = false;
|
|
196
|
-
cli.stopSpinner();
|
|
197
|
-
cli.focus('user', true);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
// Register key mappings
|
|
202
|
-
cli.registerKeyMappings([
|
|
203
|
-
// ALT-C: Clear screen
|
|
204
|
-
{
|
|
205
|
-
name: 'c', ctrl: false, meta: true, shift: false,
|
|
206
|
-
handler: async () => {
|
|
207
|
-
if (!busy) {
|
|
208
|
-
cli.clear();
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
// ALT-R: Reset session
|
|
213
|
-
{
|
|
214
|
-
name: 'r', ctrl: false, meta: true, shift: false,
|
|
215
|
-
handler: async () => {
|
|
216
|
-
if (!busy) {
|
|
217
|
-
await sendMessage({ action: 'user_reset', content: '' });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
// ALT-S: Session list
|
|
222
|
-
{
|
|
223
|
-
name: 's', ctrl: false, meta: true, shift: false,
|
|
224
|
-
handler: async () => {
|
|
225
|
-
if (!busy) {
|
|
226
|
-
await sendMessage({ action: 'user_sessionlist', content: '' });
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
// ALT-I: Server info
|
|
231
|
-
{
|
|
232
|
-
name: 'i', ctrl: false, meta: true, shift: false,
|
|
233
|
-
handler: async () => {
|
|
234
|
-
if (!busy) {
|
|
235
|
-
await sendMessage({ action: 'user_info', content: '' });
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
// ALT-M: Copy last message
|
|
240
|
-
{
|
|
241
|
-
name: 'm', ctrl: false, meta: true, shift: false,
|
|
242
|
-
handler: async () => {
|
|
243
|
-
if (!busy && lastMessage) {
|
|
244
|
-
await copyToClipboard(lastMessage);
|
|
245
|
-
cli.focus('util');
|
|
246
|
-
cli.write('Copied last message to clipboard');
|
|
247
|
-
cli.focus('user', true);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
// CTRL-K: Help
|
|
252
|
-
{
|
|
253
|
-
name: 'k', ctrl: true, meta: false, shift: false,
|
|
254
|
-
handler: async () => {
|
|
255
|
-
cli.focus('util');
|
|
256
|
-
cli.write(`
|
|
257
|
-
Available keys:
|
|
258
|
-
• ALT-C: Clear screen
|
|
259
|
-
• ALT-R: Reset session
|
|
260
|
-
• ALT-I: Server info
|
|
261
|
-
• ALT-S: List/load sessions
|
|
262
|
-
• ALT-M: Copy last message
|
|
263
|
-
• CTRL-K: Show help
|
|
264
|
-
• CTRL-D: Exit
|
|
265
|
-
`.trim());
|
|
266
|
-
cli.focus('user', true);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
]);
|
|
270
|
-
|
|
271
|
-
// Input handler for user messages
|
|
272
|
-
cli.inputHandler = async (s) => {
|
|
273
|
-
if (busy || !s || !s.trim()) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
await sendMessage({
|
|
277
|
-
action: 'user_request',
|
|
278
|
-
content: s.trim()
|
|
279
|
-
});
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
// Initialize
|
|
283
|
-
cli.focus('log');
|
|
284
|
-
cli.write('Connecting... (ALT-I for info, CTRL-K for keys, CTRL-D to exit)');
|
|
285
|
-
|
|
286
|
-
connect();
|
|
287
|
-
};
|
package/lib/wsIO.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
/*
|
|
3
|
-
* Oneshot direct write response to/from a Agent server
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {object} wsResponse
|
|
7
|
-
* @property {string} action
|
|
8
|
-
* @property {string} content
|
|
9
|
-
* @property {number} id - message id
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* One-shot WebSocket client for hello-dave server using standard 'ws' library.
|
|
13
|
-
* Connects directly to pure WS endpoint (no HTTP upgrade).
|
|
14
|
-
* Sends intro + action, awaits matching response by ID, closes, returns response.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} connectUrl - Websocket server endpoint to connect to
|
|
17
|
-
* @param {string} [secret=''] - Secret websocket connection key
|
|
18
|
-
* @param {'user_request'|'user_info'|'user_reset'} action - Action to perform
|
|
19
|
-
* @param {string} [input=''] - Input content (required for 'user_request')
|
|
20
|
-
* @returns {Promise<wsResponse>}
|
|
21
|
-
* @throws {Error} Invalid action or missing input for user_request
|
|
22
|
-
* @example
|
|
23
|
-
* const response = await wsio('ws://localhost:8080', 'secret', 'user_request', 'Hello!');
|
|
24
|
-
* console.log(response.content);
|
|
25
|
-
*/
|
|
26
|
-
export default async function wsio(connectUrl, secret = '', action, input = '') {
|
|
27
|
-
if (!['user_request', 'user_reset', 'user_info'].includes(action)) {
|
|
28
|
-
throw new Error(`Invalid action: ${action}. Must be one of: user_request, user_reset, user_info`);
|
|
29
|
-
}
|
|
30
|
-
if (action === 'user_request' && (!input || typeof input !== 'string' || input.trim() === '')) {
|
|
31
|
-
throw new Error('Non-empty string input required for "user_request"');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let b64secret = '';
|
|
35
|
-
if (secret !== '') {
|
|
36
|
-
b64secret = Buffer.from(secret).toString('base64');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const url = `${connectUrl}${connectUrl.includes('?') ? '&' : '?'}wssrc_id=${b64secret}`;
|
|
40
|
-
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
const ws = new WebSocket(url);
|
|
43
|
-
|
|
44
|
-
let resolved = false;
|
|
45
|
-
|
|
46
|
-
const actionId = Date.now();
|
|
47
|
-
|
|
48
|
-
ws.on('open', () => {
|
|
49
|
-
// Send introduction first (matches wsConnect.js protocol)
|
|
50
|
-
const introId = Date.now() - 1;
|
|
51
|
-
ws.send(JSON.stringify({
|
|
52
|
-
action: 'user_introduction',
|
|
53
|
-
content: '',
|
|
54
|
-
id: introId
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
// Send the action immediately after
|
|
58
|
-
ws.send(JSON.stringify({
|
|
59
|
-
action,
|
|
60
|
-
content: input,
|
|
61
|
-
id: actionId
|
|
62
|
-
}));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
ws.on('message', (data) => {
|
|
66
|
-
try {
|
|
67
|
-
const parsed = JSON.parse(data.toString());
|
|
68
|
-
if (parsed.id === actionId) {
|
|
69
|
-
resolved = true;
|
|
70
|
-
ws.close(1000, 'Request complete');
|
|
71
|
-
resolve(parsed);
|
|
72
|
-
}
|
|
73
|
-
} catch (e) {
|
|
74
|
-
// Ignore non-JSON or non-matching messages (e.g., intro response)
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
ws.on('close', (code, reason) => {
|
|
79
|
-
if (!resolved) {
|
|
80
|
-
reject(new Error(`Connection closed (${code}): ${reason || 'Unknown reason'}`));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
ws.on('error', (error) => {
|
|
85
|
-
if (!resolved) {
|
|
86
|
-
reject(new Error(`WebSocket error: ${error.message}`));
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
package/types/API/x.ai/text.d.ts
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
export type Prompt = import("../../Prompt.js").default;
|
|
2
|
-
export type ToolSet = import("../../ToolSet.js").default;
|
|
3
|
-
export type grokModels = "grok-4" | "grok-3" | "grok-3-mini" | "grok-3-fast" | "grok-3-mini-fast";
|
|
4
|
-
export type grokReason = "low" | "high";
|
|
5
|
-
export type SearchParameters = {
|
|
6
|
-
mode: "on" | "auto";
|
|
7
|
-
/**
|
|
8
|
-
* ISO-8601 date (YYYY-MM-DD)
|
|
9
|
-
*/
|
|
10
|
-
from_date?: string | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* ISO-8601 date (YYYY-MM-DD)
|
|
13
|
-
*/
|
|
14
|
-
to_date?: string | undefined;
|
|
15
|
-
sources?: (RssSource | WebSource | NewsSource | XSource)[] | undefined;
|
|
16
|
-
};
|
|
17
|
-
export type RssSource = {
|
|
18
|
-
type: "rss";
|
|
19
|
-
links: string[];
|
|
20
|
-
};
|
|
21
|
-
export type WebSource = {
|
|
22
|
-
type: "web";
|
|
23
|
-
/**
|
|
24
|
-
* ISO-3166-1 alpha-2
|
|
25
|
-
*/
|
|
26
|
-
country?: string | undefined;
|
|
27
|
-
safe_search?: boolean | undefined;
|
|
28
|
-
allowed_websites?: string[] | undefined;
|
|
29
|
-
excluded_websites?: string[] | undefined;
|
|
30
|
-
};
|
|
31
|
-
export type NewsSource = {
|
|
32
|
-
type: "news";
|
|
33
|
-
country?: string | undefined;
|
|
34
|
-
safe_search?: boolean | undefined;
|
|
35
|
-
allowed_websites?: string[] | undefined;
|
|
36
|
-
excluded_websites?: string[] | undefined;
|
|
37
|
-
};
|
|
38
|
-
export type XSource = {
|
|
39
|
-
type: "x";
|
|
40
|
-
};
|
|
41
|
-
export type XRequest = {
|
|
42
|
-
body: XOptions;
|
|
43
|
-
headers: Headers;
|
|
44
|
-
/**
|
|
45
|
-
* -
|
|
46
|
-
*/
|
|
47
|
-
url: string;
|
|
48
|
-
};
|
|
49
|
-
export type XFunctionCall = {
|
|
50
|
-
/**
|
|
51
|
-
* - The name of the function to call.
|
|
52
|
-
*/
|
|
53
|
-
name: string;
|
|
54
|
-
/**
|
|
55
|
-
* - The arguments for the function call in JSON string format.
|
|
56
|
-
*/
|
|
57
|
-
arguments: string;
|
|
58
|
-
};
|
|
59
|
-
export type XToolCall = {
|
|
60
|
-
/**
|
|
61
|
-
* - The unique identifier for the tool call.
|
|
62
|
-
*/
|
|
63
|
-
id: string;
|
|
64
|
-
/**
|
|
65
|
-
* - The type of the tool call, e.g., "function".
|
|
66
|
-
*/
|
|
67
|
-
type: string;
|
|
68
|
-
/**
|
|
69
|
-
* - The function call details.
|
|
70
|
-
*/
|
|
71
|
-
function: XFunctionCall;
|
|
72
|
-
};
|
|
73
|
-
export type XFunctionResponse = {
|
|
74
|
-
/**
|
|
75
|
-
* - must be 'tool'
|
|
76
|
-
*/
|
|
77
|
-
role: string;
|
|
78
|
-
/**
|
|
79
|
-
* - The arguments for the function call in JSON string format.
|
|
80
|
-
*/
|
|
81
|
-
content: string;
|
|
82
|
-
/**
|
|
83
|
-
* - The unique identifier for the tool call.
|
|
84
|
-
*/
|
|
85
|
-
tool_call_id: string;
|
|
86
|
-
};
|
|
87
|
-
export type XMessageResponse = {
|
|
88
|
-
/**
|
|
89
|
-
* - The index of the message.
|
|
90
|
-
*/
|
|
91
|
-
index: number;
|
|
92
|
-
/**
|
|
93
|
-
* - The message details.
|
|
94
|
-
*/
|
|
95
|
-
message: {
|
|
96
|
-
role: string;
|
|
97
|
-
content: string;
|
|
98
|
-
reasoning_content?: string | undefined;
|
|
99
|
-
refusal: string | null;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* - The reason for finishing (e.g., "stop").
|
|
103
|
-
*/
|
|
104
|
-
finish_reason: string;
|
|
105
|
-
/**
|
|
106
|
-
* - The reason for finishing (e.g., "stop").
|
|
107
|
-
*/
|
|
108
|
-
tools_calls: XToolCall[];
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* https://docs.x.ai/api/endpoints#chat-completions
|
|
112
|
-
*/
|
|
113
|
-
export type XOptions = {
|
|
114
|
-
/**
|
|
115
|
-
* - What model to use
|
|
116
|
-
*/
|
|
117
|
-
model?: grokModels | undefined;
|
|
118
|
-
/**
|
|
119
|
-
* - the actual prompt
|
|
120
|
-
*/
|
|
121
|
-
messages?: any[] | undefined;
|
|
122
|
-
/**
|
|
123
|
-
* , callable functions
|
|
124
|
-
*/
|
|
125
|
-
tools?: XToolCall[] | undefined;
|
|
126
|
-
/**
|
|
127
|
-
* - Default 'none' when no function, 'auto' when present, or required
|
|
128
|
-
*/
|
|
129
|
-
tool_choice?: string | undefined;
|
|
130
|
-
/**
|
|
131
|
-
* - Response format
|
|
132
|
-
*/
|
|
133
|
-
response_format?: {
|
|
134
|
-
/**
|
|
135
|
-
* - The role of the sender (e.g., "assistant").
|
|
136
|
-
*/
|
|
137
|
-
type?: string | undefined;
|
|
138
|
-
} | undefined;
|
|
139
|
-
/**
|
|
140
|
-
* - What sampling temperature to use, between 0 and 2.
|
|
141
|
-
*/
|
|
142
|
-
temperature?: number | undefined;
|
|
143
|
-
/**
|
|
144
|
-
* - The maximum number of tokens allowed for the generated answer.
|
|
145
|
-
*/
|
|
146
|
-
max_completion_tokens?: number | undefined;
|
|
147
|
-
/**
|
|
148
|
-
* - Number between -2.0 and 2.0.
|
|
149
|
-
*/
|
|
150
|
-
presence_penalty?: number | undefined;
|
|
151
|
-
/**
|
|
152
|
-
* - Number between -2.0 and 2.0.
|
|
153
|
-
*/
|
|
154
|
-
frequency_penalty?: number | undefined;
|
|
155
|
-
/**
|
|
156
|
-
* - Number between -2.0 and 2.0.
|
|
157
|
-
*/
|
|
158
|
-
top_p?: number | undefined;
|
|
159
|
-
/**
|
|
160
|
-
* - How many chat completion choices to generate for each input message. default 1
|
|
161
|
-
*/
|
|
162
|
-
n?: number | undefined;
|
|
163
|
-
/**
|
|
164
|
-
* - Chunk/stream request default null
|
|
165
|
-
*/
|
|
166
|
-
stream?: boolean | undefined;
|
|
167
|
-
/**
|
|
168
|
-
* - Multiple calls at once
|
|
169
|
-
*/
|
|
170
|
-
parallel_tool_calls?: boolean | undefined;
|
|
171
|
-
/**
|
|
172
|
-
* - Who i am
|
|
173
|
-
*/
|
|
174
|
-
reasoning_effort?: grokReason | undefined;
|
|
175
|
-
/**
|
|
176
|
-
* - Who i am
|
|
177
|
-
*/
|
|
178
|
-
user?: string | undefined;
|
|
179
|
-
/**
|
|
180
|
-
* - see options
|
|
181
|
-
*/
|
|
182
|
-
seed?: number | undefined;
|
|
183
|
-
/**
|
|
184
|
-
* - live search
|
|
185
|
-
*/
|
|
186
|
-
search_parameters?: SearchParameters | undefined;
|
|
187
|
-
/**
|
|
188
|
-
* - Up to 4 sequences where the API will stop generating further tokens.
|
|
189
|
-
*/
|
|
190
|
-
stop?: string[] | undefined;
|
|
191
|
-
};
|
|
192
|
-
export type XResponse = {
|
|
193
|
-
/**
|
|
194
|
-
* - The unique identifier for the response.
|
|
195
|
-
*/
|
|
196
|
-
id: string;
|
|
197
|
-
/**
|
|
198
|
-
* - The type of object returned, typically "chat.completion".
|
|
199
|
-
*/
|
|
200
|
-
object: string;
|
|
201
|
-
/**
|
|
202
|
-
* - The timestamp of when the response was created.
|
|
203
|
-
*/
|
|
204
|
-
created: number;
|
|
205
|
-
/**
|
|
206
|
-
* - The model used to generate the response.
|
|
207
|
-
*/
|
|
208
|
-
model: string;
|
|
209
|
-
/**
|
|
210
|
-
* - An array of choice objects containing the response details.
|
|
211
|
-
*/
|
|
212
|
-
choices: Array<XChoice>;
|
|
213
|
-
/**
|
|
214
|
-
* - An object containing token usage information.
|
|
215
|
-
*/
|
|
216
|
-
usage: XUsage;
|
|
217
|
-
/**
|
|
218
|
-
* - The system fingerprint for the response.
|
|
219
|
-
*/
|
|
220
|
-
system_fingerprint: string;
|
|
221
|
-
/**
|
|
222
|
-
* - HTTP headers associated with the response.
|
|
223
|
-
*/
|
|
224
|
-
http_headers: Object;
|
|
225
|
-
};
|
|
226
|
-
export type XChoice = {
|
|
227
|
-
/**
|
|
228
|
-
* - The index of the choice in the response.
|
|
229
|
-
*/
|
|
230
|
-
index: number;
|
|
231
|
-
/**
|
|
232
|
-
* - The message object containing the role and content.
|
|
233
|
-
*/
|
|
234
|
-
message: XMessageResponse;
|
|
235
|
-
/**
|
|
236
|
-
* - Log probabilities, typically null.
|
|
237
|
-
*/
|
|
238
|
-
logprobs: null;
|
|
239
|
-
/**
|
|
240
|
-
* - The reason why the response finished.
|
|
241
|
-
*/
|
|
242
|
-
finish_reason: string;
|
|
243
|
-
};
|
|
244
|
-
export type XUsage = {
|
|
245
|
-
/**
|
|
246
|
-
* - The number of tokens in the prompt.
|
|
247
|
-
*/
|
|
248
|
-
prompt_tokens: number;
|
|
249
|
-
/**
|
|
250
|
-
* - The number of tokens in the completion.
|
|
251
|
-
*/
|
|
252
|
-
completion_tokens: number;
|
|
253
|
-
/**
|
|
254
|
-
* - The total number of tokens used.
|
|
255
|
-
*/
|
|
256
|
-
total_tokens: number;
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* Create an anthropic request
|
|
260
|
-
* @param {Prompt} prompt
|
|
261
|
-
* @param {ToolSet|void} [tools]
|
|
262
|
-
* @param {XOptions} [opts] overwrite default request settings
|
|
263
|
-
* @param {object} [hdrs] - optional headers to pass
|
|
264
|
-
* @returns {XRequest}
|
|
265
|
-
* @throws {Error}
|
|
266
|
-
*/
|
|
267
|
-
export function generateRequest(prompt: Prompt, tools?: void | import("../../ToolSet.js").default | undefined, opts?: XOptions, hdrs?: object): XRequest;
|
|
268
|
-
/**
|
|
269
|
-
* Process an openai response
|
|
270
|
-
* @param {number} duration - the time is MS before and after the request
|
|
271
|
-
* @param {import('@j-o-r/apiserver/types/request.js').FetchResponseObject} res
|
|
272
|
-
* @param {Prompt} prompt
|
|
273
|
-
* @param {ToolSet} [toolset]
|
|
274
|
-
* @returns {Promise<void>}
|
|
275
|
-
* @throws {Error}
|
|
276
|
-
*/
|
|
277
|
-
export function parseResponse(duration: number, prompt: Prompt, res: import("@j-o-r/apiserver/types/request.js").FetchResponseObject, toolset?: ToolSet): Promise<void>;
|
|
278
|
-
/**
|
|
279
|
-
* Do a request
|
|
280
|
-
* @param {Prompt} prompt
|
|
281
|
-
* @param {ToolSet|null} toolset
|
|
282
|
-
* @param {XOptions} [options]:
|
|
283
|
-
* @param {number} [counter] - leave empty this counts the number of requests when doing recursive request calls
|
|
284
|
-
* @return {Promise<import('../../Session.js').Message>}
|
|
285
|
-
*/
|
|
286
|
-
export function request(prompt: Prompt, toolset?: ToolSet | null, options?: XOptions, counter?: number): Promise<import("../../Session.js").Message>;
|