@j-o-r/hello-dave 0.0.5 → 0.0.7
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 +13 -26
- package/README.md +161 -522
- package/README.md.bak +144 -449
- package/{examples → agents}/ask_agent.js +5 -5
- package/{examples → agents}/codeserver.sh +14 -14
- package/{examples → agents}/daisy_agent.js +5 -5
- package/{examples → agents}/docs_agent.js +5 -5
- package/{examples → agents}/gpt_agent.js +5 -5
- package/{examples → agents}/grok_agent.js +5 -5
- package/agents/memory_agent.js +263 -0
- package/{examples → agents}/npm_agent.js +5 -5
- package/{examples → agents}/prompt_agent.js +5 -5
- package/agents/spawn_agent.js +137 -0
- package/{examples → agents}/test_agent.js +6 -8
- package/{examples → agents}/todo_agent.js +5 -5
- package/bin/codeDave +58 -0
- package/bin/dave.js +114 -96
- package/lib/AgentClient.js +111 -67
- package/lib/AgentManager.js +111 -80
- package/lib/AgentServer.js +144 -104
- package/lib/Cli.js +126 -93
- package/lib/Prompt.js +38 -5
- package/lib/Session.js +102 -79
- package/lib/ToolSet.js +79 -60
- package/lib/fafs.js +54 -19
- package/lib/genericToolset.js +109 -213
- package/lib/wsCli.js +50 -19
- package/lib/wsIO.js +11 -17
- package/package.json +2 -2
- package/types/AgentClient.d.ts +69 -35
- package/types/AgentManager.d.ts +50 -56
- package/types/AgentServer.d.ts +63 -16
- package/types/Cli.d.ts +56 -10
- package/types/Prompt.d.ts +36 -4
- package/types/Session.d.ts +23 -9
- package/types/ToolSet.d.ts +49 -32
- package/types/fafs.d.ts +68 -25
- package/types/wsCli.d.ts +14 -0
- package/types/wsIO.d.ts +9 -5
- package/utils/search_sessions.sh +100 -53
- package/README.md.backup +0 -269
- package/README.md.bak.1774780058 +0 -338
- package/README.md.bak2 +0 -531
- package/bin/spawn_agent.js +0 -293
- package/docs.bak.1774780058/agent-manager.md +0 -167
- package/docs.bak.1774780058/agent-manager.md.bak +0 -137
- package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
- package/docs.bak.1774780058/codeserver-pattern.md +0 -191
- package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
- package/docs.bak.1774780058/project-overview.md +0 -67
- package/docs.bak.1774780058/project-overview.md.bak +0 -67
- package/docs.bak.1774780058/prompt-class.md +0 -141
- package/docs.bak.1774780058/prompt-class.md.bak +0 -142
- package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
- package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
- package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
- package/docs.bak.1774780058/toolset.md +0 -164
- package/docs.bak.1774780058/toolset.md.bak +0 -94
- package/docs.bak.1774780058/toolset.md.bak3 +0 -161
- package/docs.bak.1774780058/toolset.md.bak4 +0 -161
- package/docs.bak.1774780058/toolset.md.bak5 +0 -161
- package/docs.bak.1774780058/toolset.md.bak6 +0 -163
- package/docs.bak.1774780058/toolset.md.bak_path +0 -163
- package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
- package/docs.bak.1774780058/xai-responses.md +0 -111
- package/docs.bak.1774780058/xai-responses.md.bak +0 -107
- package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
- package/docs.bak.1774780058/xai_collections.md +0 -106
- package/examples/memory_agent.js +0 -152
- package/examples.bak.1774780058/ask_agent.js +0 -114
- package/examples.bak.1774780058/code_agent.js +0 -149
- package/examples.bak.1774780058/coderev_agent.js +0 -72
- package/examples.bak.1774780058/codeserver.sh +0 -47
- package/examples.bak.1774780058/daisy_agent.js +0 -177
- package/examples.bak.1774780058/docs_agent.js +0 -119
- package/examples.bak.1774780058/gpt_agent.js +0 -109
- package/examples.bak.1774780058/grok_agent.js +0 -98
- package/examples.bak.1774780058/memory_agent.js +0 -112
- package/examples.bak.1774780058/npm_agent.js +0 -175
- package/examples.bak.1774780058/prompt_agent.js +0 -112
- package/examples.bak.1774780058/readme_agent.js +0 -144
- package/examples.bak.1774780058/spawn_agent.js +0 -263
- package/examples.bak.1774780058/test_agent.js +0 -162
- package/examples.bak.1774780058/todo_agent.js +0 -138
- package/lib/genericToolset.js.bak_syntax +0 -402
- package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
- package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
- package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
- package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
- package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
- package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
- package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
- package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
- package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
- package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
- package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
- package/scenarios.bak.1774780058/environment.js +0 -10
- package/scenarios.bak.1774780058/example.js +0 -17
- package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
- package/scenarios.bak.1774780058/grok.js +0 -113
- package/scenarios.bak.1774780058/memory-tools.js +0 -51
- package/scenarios.bak.1774780058/openai-o3.js +0 -137
- package/scenarios.bak.1774780058/openai-prompt.js +0 -155
- package/scenarios.bak.1774780058/openai-session.js +0 -148
- package/scenarios.bak.1774780058/openai.js +0 -102
- package/scenarios.bak.1774780058/prompt.js +0 -118
- package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
- package/scenarios.bak.1774780058/search.brave.com.js +0 -25
- package/scenarios.bak.1774780058/sh.js +0 -15
- package/scenarios.bak.1774780058/test-wsio.js +0 -26
- package/scenarios.bak.1774780058/testToolset.js +0 -42
- package/scenarios.bak.1774780058/toolset.js +0 -16
- package/scenarios.bak.1774780058/toolset.test.js +0 -141
- package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
- package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
- package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
- package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
- package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
- package/scenarios.bak.1774780058/wsClient.js +0 -69
- package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
- package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
- package/scenarios.bak.1774780058/xaicoll.js +0 -50
- package/scenarios.bak.1774780058/xaifiles.js +0 -48
- /package/{examples → agents}/code_agent.js +0 -0
- /package/{examples → agents}/readme_agent.js +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j-o-r/hello-dave",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "ESM toolkit for building AI agents with unified access to Grok (XAI), OpenAI, and Anthropic endpoints",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
16
|
"dave": "bin/dave.js",
|
|
17
|
-
"
|
|
17
|
+
"codeDave": "bin/codeDave"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"release": "npm run types && npm pack --pack-destination=release",
|
package/types/AgentClient.d.ts
CHANGED
|
@@ -9,67 +9,101 @@ export type Prompt = import("./Prompt.js").default;
|
|
|
9
9
|
export type ToolSet = import("./ToolSet.js").default;
|
|
10
10
|
export type WSOptions = {
|
|
11
11
|
/**
|
|
12
|
-
* - The prompt session
|
|
12
|
+
* - The prompt session instance.
|
|
13
13
|
*/
|
|
14
14
|
prompt: Prompt;
|
|
15
15
|
/**
|
|
16
|
-
* -
|
|
16
|
+
* - Optional toolset for the prompt.
|
|
17
17
|
*/
|
|
18
18
|
toolset?: import("./ToolSet.js").default | undefined;
|
|
19
19
|
/**
|
|
20
|
-
* - Custom introduction message.
|
|
20
|
+
* - Custom introduction message for the agent.
|
|
21
21
|
*/
|
|
22
22
|
description: string;
|
|
23
23
|
/**
|
|
24
|
-
* - Logical name
|
|
24
|
+
* - Logical name (e.g., 'search', 'code', 'os').
|
|
25
25
|
*/
|
|
26
26
|
name: string;
|
|
27
27
|
/**
|
|
28
|
-
* - Websocket server access secret.
|
|
28
|
+
* - Websocket server access secret (must match server).
|
|
29
29
|
*/
|
|
30
30
|
secret: string;
|
|
31
|
+
/**
|
|
32
|
+
* - WebSocket URL.
|
|
33
|
+
*/
|
|
31
34
|
url?: string | undefined;
|
|
32
35
|
/**
|
|
33
|
-
* -
|
|
36
|
+
* - Polling interval for queue processing (ms).
|
|
34
37
|
*/
|
|
35
38
|
intervalMs?: number | undefined;
|
|
36
39
|
};
|
|
37
40
|
/**
|
|
38
|
-
* @
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @typedef {import('./API/openai.com/reponses/text.js').
|
|
44
|
-
* @typedef {import('./API/
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @typedef {import('./
|
|
48
|
-
|
|
41
|
+
* @module lib/AgentClient
|
|
42
|
+
* @exports default AgentClient
|
|
43
|
+
* Websocket client for AI agent sessions, wrapping a Prompt/ToolSet instance with robust queue-based message handling, auto-reconnect, and epoch-based resets.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {import('./API/openai.com/reponses/text.js').request} OARequest
|
|
47
|
+
* @typedef {import('./API/x.ai/text.js').request} XRequest
|
|
48
|
+
* @typedef {import('./API/anthropic.com/text.js').request} ANTHRequest
|
|
49
|
+
*
|
|
50
|
+
* @typedef {import('./API/x.ai/text.js').XOptions} XOptions
|
|
51
|
+
* @typedef {import('./API/openai.com/reponses/text.js').OAOptions} OAOptions
|
|
52
|
+
* @typedef {import('./API/anthropic.com/text.js').ANTHOptions} ANTHOptions
|
|
53
|
+
*
|
|
54
|
+
* @typedef {import('./Prompt.js').default} Prompt
|
|
55
|
+
* @typedef {import('./ToolSet.js').default} ToolSet
|
|
56
|
+
*/
|
|
49
57
|
/**
|
|
50
|
-
* @typedef {Object} WSOptions
|
|
51
|
-
* @property {Prompt} prompt - The prompt session
|
|
52
|
-
* @property {ToolSet} [toolset] -
|
|
53
|
-
* @property {string} description - Custom introduction message.
|
|
54
|
-
* @property {string} name - Logical name
|
|
55
|
-
* @property {string} secret - Websocket server access secret.
|
|
56
|
-
* @property {string} [url='ws://127.0.0.1:8000/ws
|
|
57
|
-
* @property {number} [intervalMs=
|
|
58
|
-
|
|
58
|
+
* @typedef {Object} WSOptions
|
|
59
|
+
* @property {Prompt} prompt - The prompt session instance.
|
|
60
|
+
* @property {ToolSet} [toolset] - Optional toolset for the prompt.
|
|
61
|
+
* @property {string} description - Custom introduction message for the agent.
|
|
62
|
+
* @property {string} name - Logical name (e.g., 'search', 'code', 'os').
|
|
63
|
+
* @property {string} secret - Websocket server access secret (must match server).
|
|
64
|
+
* @property {string} [url='ws://127.0.0.1:8000/ws'] - WebSocket URL.
|
|
65
|
+
* @property {number} [intervalMs=2000] - Polling interval for queue processing (ms).
|
|
66
|
+
* @example { prompt, name: 'code-agent', secret: 'abc123', url: 'ws://localhost:8001/ws' }
|
|
67
|
+
*/
|
|
59
68
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
69
|
+
* AgentClient: WebSocket client wrapper for AI agent sessions.
|
|
70
|
+
* Combines Prompt/ToolSet with WS communication for bidirectional queries, responses, tool calls, and resets.
|
|
71
|
+
* Features: Sequential message queue (one-at-a-time processing), auto-reconnect on close, epoch invalidation for resets.
|
|
72
|
+
* Logs events via console; emits via underlying Prompt (tool_request, tool_error, etc.).
|
|
73
|
+
* @emits tool_request - When tools are requested (via #prompt).
|
|
74
|
+
* @emits tool_error - When tools fail (via #prompt).
|
|
75
|
+
* @example
|
|
76
|
+
* const client = new AgentClient({
|
|
77
|
+
* prompt: myPrompt,
|
|
78
|
+
* name: 'code',
|
|
79
|
+
* description: 'Code execution agent',
|
|
80
|
+
* secret: 'mysecret',
|
|
81
|
+
* intervalMs: 1000
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
63
84
|
declare class AgentClient {
|
|
64
85
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
86
|
+
* Initializes the AgentClient with configuration options.
|
|
87
|
+
* Registers Prompt events for logging and starts the WebSocket connection.
|
|
88
|
+
* @param {WSOptions} options - Configuration object.
|
|
89
|
+
* @throws {TypeError} If required options (e.g., prompt, secret) are invalid/missing.
|
|
90
|
+
* @example See WSOptions.
|
|
67
91
|
*/
|
|
68
92
|
constructor(options: WSOptions);
|
|
69
|
-
_start(): void;
|
|
70
93
|
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
94
|
+
* @private
|
|
95
|
+
* Starts the WebSocket connection, sends introduction, sets up handlers.
|
|
96
|
+
* Auto-retries on close after 5s.
|
|
97
|
+
* @returns {void}
|
|
98
|
+
*/
|
|
99
|
+
private _start;
|
|
100
|
+
/**
|
|
101
|
+
* Enqueues an incoming WebSocket message and starts interval processing if needed.
|
|
102
|
+
* Immediately handles 'reset' actions (clears queue, resets prompt, increments epoch).
|
|
103
|
+
* @param {MessageEvent} e - Raw WebSocket message event.
|
|
104
|
+
* @returns {void}
|
|
105
|
+
* @throws {SyntaxError} If JSON parse fails.
|
|
106
|
+
*/
|
|
107
|
+
incoming(e: MessageEvent): void;
|
|
74
108
|
#private;
|
|
75
109
|
}
|
package/types/AgentManager.d.ts
CHANGED
|
@@ -5,101 +5,95 @@ export type OAOptions = import("./API/openai.com/reponses/text.js").OAOptions;
|
|
|
5
5
|
export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
6
6
|
export type Setup = {
|
|
7
7
|
/**
|
|
8
|
-
* - Initial system prompt
|
|
8
|
+
* - Initial system prompt.
|
|
9
9
|
*/
|
|
10
10
|
prompt: string;
|
|
11
11
|
/**
|
|
12
|
-
* -
|
|
12
|
+
* - API model options.
|
|
13
13
|
*/
|
|
14
14
|
options: XAIOptions | OAOptions | XOptions | ANTHOptions;
|
|
15
15
|
/**
|
|
16
|
-
* - AI
|
|
16
|
+
* - AI provider.
|
|
17
17
|
*/
|
|
18
18
|
api: "gpt" | "xai" | "claude";
|
|
19
19
|
/**
|
|
20
|
-
* -
|
|
20
|
+
* - Token limit for context.
|
|
21
21
|
*/
|
|
22
22
|
contextWindow?: number | undefined;
|
|
23
23
|
/**
|
|
24
|
-
* -
|
|
24
|
+
* - Toolset activation mode.
|
|
25
25
|
*/
|
|
26
|
-
toolsetMode?:
|
|
26
|
+
toolsetMode?: "auto" | "required" | null | undefined;
|
|
27
27
|
/**
|
|
28
|
-
* - verbose output
|
|
28
|
+
* - Enable verbose output.
|
|
29
29
|
*/
|
|
30
30
|
debug?: boolean | undefined;
|
|
31
31
|
};
|
|
32
32
|
export type Options = {
|
|
33
33
|
/**
|
|
34
|
-
* - Agent name
|
|
34
|
+
* - Agent name (validated /^[a-z_0-9]{2,}$/).
|
|
35
35
|
*/
|
|
36
36
|
name: string;
|
|
37
37
|
/**
|
|
38
|
-
* -
|
|
38
|
+
* - WS auth secret (base64-encoded).
|
|
39
39
|
*/
|
|
40
40
|
secret: string;
|
|
41
41
|
/**
|
|
42
|
-
* -
|
|
42
|
+
* - Session cache directory.
|
|
43
43
|
*/
|
|
44
44
|
cachePath?: string | undefined;
|
|
45
45
|
};
|
|
46
|
-
/**
|
|
47
|
-
* @typedef {import('./API/x.ai/text.js').XOptions} XOptions
|
|
48
|
-
* @typedef {import('./API/x.ai/responses.js').XAIOptions} XAIOptions
|
|
49
|
-
* @typedef {import('./API/openai.com/reponses/text.js').OAOptions} OAOptions
|
|
50
|
-
* @typedef {import('./API/anthropic.com/text.js').ANTHOptions} ANTHOptions
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* @typedef {Object} Setup
|
|
54
|
-
* @property {string} prompt - Initial system prompt
|
|
55
|
-
* @property {XAIOptions|OAOptions|XOptions|ANTHOptions} options - Model options
|
|
56
|
-
* @property {'gpt'|'xai'|'claude'} api - AI endpoint to use
|
|
57
|
-
* @property {number} [contextWindow] - The size in tokens for the context/session
|
|
58
|
-
* @property {'auto'|'required'|void} [toolsetMode] -
|
|
59
|
-
* @property {boolean} [debug] - verbose output
|
|
60
|
-
*/
|
|
61
|
-
/**
|
|
62
|
-
* @typedef {Object} Options
|
|
63
|
-
* @property {string} name - Agent name
|
|
64
|
-
* @property {string} secret - Secret string for WS access authorisation (server and client secrets should match)
|
|
65
|
-
* @property {string} [cachePath] - path to session/record storage
|
|
66
|
-
*/
|
|
67
46
|
declare class AgentManager {
|
|
68
47
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
48
|
+
* Initializes AgentManager with base options.
|
|
49
|
+
* Validates name regex; encodes secret.
|
|
50
|
+
* @param {Options} options - Base configuration.
|
|
51
|
+
* @throws {Error} Invalid name (regex) or options.
|
|
52
|
+
* @chainable
|
|
53
|
+
*/
|
|
71
54
|
constructor(options: Options);
|
|
72
55
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
* Configures the Prompt/Session/ToolSet with API adaptor.
|
|
57
|
+
* Adds system prompt; chains to start().
|
|
58
|
+
* @param {Setup} setup - AI setup details.
|
|
59
|
+
* @returns {AgentManager} This instance (chainable).
|
|
60
|
+
* @throws {Error} Invalid setup.
|
|
61
|
+
* @example mgr.setup({ prompt: 'You are a coder...', api: 'gpt', options: { model: 'gpt-4o' } });
|
|
62
|
+
*/
|
|
63
|
+
setup(setup: Setup): AgentManager;
|
|
76
64
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
65
|
+
* Direct synchronous call to the underlying Prompt.
|
|
66
|
+
* @param {string} input - User input.
|
|
67
|
+
* @returns {Promise<string>} Response.
|
|
68
|
+
* @throws {Error} No setup.
|
|
69
|
+
*/
|
|
70
|
+
directCall(input: string): Promise<any> & lt;
|
|
71
|
+
/** @returns {Prompt} Underlying Prompt instance. */
|
|
83
72
|
getPrompt(): Prompt;
|
|
84
|
-
/** @returns {ToolSet|
|
|
85
|
-
getToolset(): ToolSet |
|
|
86
|
-
/** @returns {Promise
|
|
87
|
-
environment(): Promise<
|
|
73
|
+
/** @returns {ToolSet|null} Toolset if configured. */
|
|
74
|
+
getToolset(): ToolSet | null;
|
|
75
|
+
/** @returns {Promise<import('./fafs.js').EnvironmentInfo>} System env info. */
|
|
76
|
+
environment(): Promise<any> & lt;
|
|
88
77
|
/**
|
|
89
|
-
* Adds a pre-defined generic tool from
|
|
90
|
-
* @param {'execute_bash_script'|'execute_remote_script'|'get_user_env'|'history_search'|'javascript_interpreter'|'memory_recall'|'memory_write'|'open_link'|'read_file'|'send_email'|'syntax_check'|'write_file'} name -
|
|
91
|
-
* @throws {Error}
|
|
78
|
+
* Adds a pre-defined generic tool from toolsPool to this agent's ToolSet.
|
|
79
|
+
* @param {'execute_bash_script'|'execute_remote_script'|'get_user_env'|'history_search'|'javascript_interpreter'|'memory_recall'|'memory_write'|'open_link'|'read_file'|'send_email'|'syntax_check'|'write_file'} name - Tool name.
|
|
80
|
+
* @throws {Error} Invalid name, no toolset, or tool missing.
|
|
81
|
+
* @example mgr.addGenericToolcall('read_file');
|
|
92
82
|
*/
|
|
93
83
|
addGenericToolcall(name: "execute_bash_script" | "execute_remote_script" | "get_user_env" | "history_search" | "javascript_interpreter" | "memory_recall" | "memory_write" | "open_link" | "read_file" | "send_email" | "syntax_check" | "write_file"): void;
|
|
94
84
|
/**
|
|
95
|
-
* Smart launcher:
|
|
96
|
-
*
|
|
97
|
-
* @param {
|
|
98
|
-
* @param {string} [
|
|
99
|
-
* @param {string} [
|
|
100
|
-
* @param {string} [
|
|
85
|
+
* Smart launcher: CLI (default), server (servePort), or client (connectUrl).
|
|
86
|
+
* Auto-generates intros/descriptions if empty.
|
|
87
|
+
* @param {number} [servePort] - Launch server on port.
|
|
88
|
+
* @param {string} [connectUrl] - Connect as client to WS.
|
|
89
|
+
* @param {string} [cliIntro=""] - CLI intro text.
|
|
90
|
+
* @param {string} [toolName=""] - Tool/server name (falls back to #name).
|
|
91
|
+
* @param {string} [toolDescription=""] - Tool desc.
|
|
92
|
+
* @returns {Promise<void>}
|
|
93
|
+
* @throws {Error} No setup; invalid names/ports.
|
|
94
|
+
* @example mgr.start(8000); // Server\nmgr.start(undefined, 'ws://other:8001/ws'); // Client\nmgr.start(); // CLI
|
|
101
95
|
*/
|
|
102
|
-
start(servePort?: number, connectUrl?: string, cliIntro?: string, toolName?: string, toolDescription?: string): Promise<
|
|
96
|
+
start(servePort?: number, connectUrl?: string, cliIntro?: string, toolName?: string, toolDescription?: string): Promise<any> & lt;
|
|
103
97
|
#private;
|
|
104
98
|
}
|
|
105
99
|
import { Prompt } from './index.js';
|
package/types/AgentServer.d.ts
CHANGED
|
@@ -1,42 +1,89 @@
|
|
|
1
1
|
export default AgentServer;
|
|
2
|
-
export type Client = import("
|
|
2
|
+
export type Client = import("@j-o-r/apiserver/types/ClientWrapper.d.ts").ClientWrapper;
|
|
3
3
|
export type Prompt = import("./Prompt.js").default;
|
|
4
4
|
export type ToolSet = import("./ToolSet.js").default;
|
|
5
5
|
export type Session = import("./Session.js").default;
|
|
6
|
-
export type
|
|
6
|
+
export type MessageContent = string | object;
|
|
7
|
+
export type Message = {
|
|
8
|
+
/**
|
|
9
|
+
* - Action type (must be in ACTIONS).
|
|
10
|
+
*/
|
|
11
|
+
action: string;
|
|
12
|
+
content?: MessageContent | undefined;
|
|
13
|
+
id?: string | undefined;
|
|
14
|
+
};
|
|
7
15
|
export type AgentServerOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* - Server/agent name.
|
|
18
|
+
*/
|
|
8
19
|
name: string;
|
|
9
20
|
/**
|
|
10
|
-
* -
|
|
21
|
+
* - Access secret (matches client secrets).
|
|
11
22
|
*/
|
|
12
23
|
secret: string;
|
|
24
|
+
/**
|
|
25
|
+
* - Server description.
|
|
26
|
+
*/
|
|
13
27
|
description: string;
|
|
28
|
+
/**
|
|
29
|
+
* - Prompt instance.
|
|
30
|
+
*/
|
|
14
31
|
prompt: Prompt;
|
|
32
|
+
/**
|
|
33
|
+
* - Session manager.
|
|
34
|
+
*/
|
|
15
35
|
session: Session;
|
|
16
|
-
auth?: AuthFunction | undefined;
|
|
17
36
|
/**
|
|
18
|
-
* -
|
|
37
|
+
* - Custom auth function.
|
|
38
|
+
*/
|
|
39
|
+
auth?: AuthFunction;
|
|
40
|
+
/**
|
|
41
|
+
* - Listen port (>=1024).
|
|
19
42
|
*/
|
|
20
43
|
port?: number | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* - Verbose logging.
|
|
46
|
+
*/
|
|
21
47
|
debug?: boolean | undefined;
|
|
22
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* AgentServer: Core WebSocket server class.
|
|
51
|
+
* Exposes connected agents as tools; handles user CLI/WS interactions, auth, sessions.
|
|
52
|
+
* Starts on localhost; broadcasts resets.
|
|
53
|
+
* Logs events via console; emits via Prompt.
|
|
54
|
+
* @emits tool_request - Tool calls (via #prompt).
|
|
55
|
+
* @emits tool_error - Tool failures (via #prompt).
|
|
56
|
+
* @example
|
|
57
|
+
* const server = new AgentServer({
|
|
58
|
+
* name: 'main',
|
|
59
|
+
* prompt: myPrompt,
|
|
60
|
+
* session: mySession,
|
|
61
|
+
* secret: 'abc',
|
|
62
|
+
* port: 8000,
|
|
63
|
+
* debug: true
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
23
66
|
declare class AgentServer {
|
|
24
67
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
68
|
+
* Initializes and starts the AgentServer.
|
|
69
|
+
* Validates port, sets up Prompt event logging, launches WS server.
|
|
70
|
+
* @param {AgentServerOptions} options - Server configuration.
|
|
71
|
+
* @throws {Error} If port < 1024.
|
|
72
|
+
* @example See AgentServerOptions.
|
|
73
|
+
*/
|
|
27
74
|
constructor(options: AgentServerOptions);
|
|
28
75
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
76
|
+
* @private
|
|
77
|
+
* Launches the WS server with handlers for messages, connections, closes.
|
|
78
|
+
* Defines HTTP / API index endpoint.
|
|
79
|
+
* @returns {Promise<void>}
|
|
80
|
+
*/
|
|
35
81
|
private _start;
|
|
36
82
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
83
|
+
* Broadcasts a reset message to all connected clients (starts new sessions).
|
|
84
|
+
* @returns {void}
|
|
85
|
+
* @fires reset - Via underlying prompt/clients.
|
|
86
|
+
*/
|
|
40
87
|
resetAll(): void;
|
|
41
88
|
#private;
|
|
42
89
|
}
|
package/types/Cli.d.ts
CHANGED
|
@@ -8,45 +8,91 @@ export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
|
8
8
|
export type Prompt = import("./Prompt.js").default;
|
|
9
9
|
export type Session = import("./Session.js").default;
|
|
10
10
|
export type ToolSet = import("./ToolSet.js").default;
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for initializing the Cli class.
|
|
13
|
+
*/
|
|
11
14
|
export type CLIOptions = {
|
|
12
15
|
/**
|
|
13
|
-
* - The
|
|
16
|
+
* - The Prompt instance for handling AI interactions.
|
|
14
17
|
*/
|
|
15
18
|
prompt: Prompt;
|
|
16
19
|
/**
|
|
17
|
-
* - Session
|
|
20
|
+
* - The Session instance for managing conversation history.
|
|
18
21
|
*/
|
|
19
22
|
session: Session;
|
|
20
23
|
/**
|
|
21
|
-
* -
|
|
24
|
+
* - Optional ToolSet for tool integrations.
|
|
22
25
|
*/
|
|
23
26
|
toolset?: import("./ToolSet.js").default | undefined;
|
|
24
27
|
/**
|
|
25
|
-
* - Custom introduction message.
|
|
28
|
+
* - Custom introduction message (appended to default INTRO).
|
|
26
29
|
*/
|
|
27
30
|
description?: string | undefined;
|
|
28
31
|
/**
|
|
29
|
-
* - Custom help message.
|
|
32
|
+
* - Custom help message (overrides default HELP).
|
|
30
33
|
*/
|
|
31
34
|
help?: string | undefined;
|
|
32
35
|
};
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
37
|
+
* CLI Interface for interactive AI conversations.
|
|
38
|
+
*
|
|
39
|
+
* Integrates with {@link Prompt}, {@link Session}, and optionally {@link ToolSet} to provide a terminal-based chat interface.
|
|
40
|
+
* Supports keyboard shortcuts (Alt + key), session management, error handling, and real-time message streaming.
|
|
41
|
+
*
|
|
42
|
+
* Key features:
|
|
43
|
+
* - Rich text output with roles (user/assistant/util/error/log).
|
|
44
|
+
* - Event-driven updates from Prompt (messages, truncated, finished).
|
|
45
|
+
* - Built-in help, reset, load session, copy last message (Alt+m).
|
|
46
|
+
* - Customizable intro/help via options.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const cli = new Cli({ prompt: myPrompt, session: mySession });
|
|
50
|
+
* await cli.start('Hello, AI!');
|
|
51
|
+
*
|
|
52
|
+
* @fires Prompt#message
|
|
53
|
+
* @fires Prompt#truncated
|
|
54
|
+
* @fires Prompt#finished
|
|
35
55
|
*/
|
|
36
56
|
declare class Cli {
|
|
37
57
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
58
|
+
* Initializes the Cli instance with required Prompt and Session.
|
|
59
|
+
* Sets up CLI roles, key mappings, and event listeners on Prompt.
|
|
60
|
+
* @param {CLIOptions} options - Configuration options.
|
|
61
|
+
* @throws {Error} If required prompt or session is missing.
|
|
40
62
|
*/
|
|
41
63
|
constructor(options: CLIOptions);
|
|
64
|
+
/**
|
|
65
|
+
* Prints detailed info about current session and prompt, plus description.
|
|
66
|
+
* Triggered by Alt+i.
|
|
67
|
+
*/
|
|
42
68
|
printInfo(): void;
|
|
43
69
|
/**
|
|
44
|
-
* Starts the CLI
|
|
45
|
-
* @param {string} [s] -
|
|
70
|
+
* Starts the CLI: Shows intro/description, focuses user input, optionally processes initial message.
|
|
71
|
+
* @param {string} [s] - Optional initial user message to process.
|
|
46
72
|
* @returns {Promise<void>}
|
|
73
|
+
* @example
|
|
74
|
+
* await cli.start(); // Interactive mode
|
|
75
|
+
* await cli.start('What is the weather?'); // Start with query
|
|
47
76
|
*/
|
|
48
77
|
start(s?: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Loads a previous session by user selection, replays non-sticky messages, and triggers request.
|
|
80
|
+
* Lists sessions in reverse chronological order + 'NONE'.
|
|
81
|
+
* Triggered by Alt+s.
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
*/
|
|
49
84
|
loadSession(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Resets the prompt (clears context), reprints info, triggered by Alt+r.
|
|
87
|
+
* @returns {Promise<void>}
|
|
88
|
+
*/
|
|
50
89
|
reset(): Promise<void>;
|
|
51
90
|
#private;
|
|
52
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Copies text to the system clipboard using xclip.
|
|
94
|
+
* @param {string} text - Text to copy (non-empty string).
|
|
95
|
+
* @returns {Promise<void>}
|
|
96
|
+
* @throws {Error} If xclip fails or invalid input.
|
|
97
|
+
*/
|
|
98
|
+
export function copyToClipboard(text: string): Promise<void>;
|
package/types/Prompt.d.ts
CHANGED
|
@@ -137,12 +137,44 @@ export type Message = {
|
|
|
137
137
|
ts?: number | undefined;
|
|
138
138
|
};
|
|
139
139
|
/**
|
|
140
|
+
* Manages a conversation history of standardized AI messages (text, image, audio, tool calls/responses)
|
|
141
|
+
* across different LLM providers (OpenAI, xAI, Anthropic). Inspired by OpenAI's chat format but extended.
|
|
140
142
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
+
* Key features:
|
|
144
|
+
* - Message validation and ordering (roles: system, user, assistant, tool, reasoning, log)
|
|
145
|
+
* - Context window management with automatic truncation (preserves sticky base prompts)
|
|
146
|
+
* - ToolSet integration via adapters for function calls
|
|
147
|
+
* - Token counting, records for billing/optimization
|
|
148
|
+
* - Event-driven lifecycle (e.g., 'message', 'start', 'finished', tool events)
|
|
143
149
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
150
|
+
* Typical usage:
|
|
151
|
+
* const prompt = new Prompt(4096);
|
|
152
|
+
* prompt.setAdaptor(openaiHandler, toolset, options);
|
|
153
|
+
* prompt.add('system', 'You are helpful.', true);
|
|
154
|
+
* const response = await prompt.call('Hello!');
|
|
155
|
+
*
|
|
156
|
+
* @extends {EventEmitter}
|
|
157
|
+
* @property {number} contextLength - Maximum token limit (getter)
|
|
158
|
+
* @property {Message[]} messages - Copy of conversation history (getter/setter)
|
|
159
|
+
* @property {ToolSet|null} toolset - Current toolset (getter)
|
|
160
|
+
* @property {boolean} hasSystemprompt - Whether system prompt exists (getter)
|
|
161
|
+
* @property {string} system_prompt - System prompt text (getter)
|
|
162
|
+
*
|
|
163
|
+
* @fires Prompt#start - Emitted when a request starts
|
|
164
|
+
* @fires Prompt#retrigger - Retrigger after message import
|
|
165
|
+
* @fires Prompt#finished - Request completed
|
|
166
|
+
* @fires Prompt#message - New message added to history
|
|
167
|
+
* @fires Prompt#record - Token usage record added
|
|
168
|
+
* @fires Prompt#truncated - Messages truncated due to context limit
|
|
169
|
+
* @fires Prompt#reset - Non-sticky messages cleared
|
|
170
|
+
* @fires Prompt#ready - Call/trigger ready
|
|
171
|
+
* @fires Prompt#error - Error occurred
|
|
172
|
+
* @fires Prompt#warning - Warning issued (e.g., token overflow)
|
|
173
|
+
* @fires Prompt#tool_request - Tool call initiated
|
|
174
|
+
* @fires Prompt#tool_response - Tool call completed
|
|
175
|
+
* @fires Prompt#tool_error - Tool call failed
|
|
176
|
+
* @fires Prompt#http_request - HTTP tool request starts
|
|
177
|
+
* @fires Prompt#http_response - HTTP tool response received
|
|
146
178
|
*/
|
|
147
179
|
declare class Prompt {
|
|
148
180
|
/**
|
package/types/Session.d.ts
CHANGED
|
@@ -2,28 +2,42 @@ export default Session;
|
|
|
2
2
|
export type Message = import("./Prompt.js").Message;
|
|
3
3
|
export type Record = import("./Prompt.js").Record;
|
|
4
4
|
/**
|
|
5
|
-
|
|
5
|
+
* Session class for managing persistent chat sessions with Prompt.
|
|
6
|
+
*/
|
|
6
7
|
declare class Session {
|
|
7
8
|
/**
|
|
8
|
-
* Constructs a new
|
|
9
|
-
* If contextWindow = 0 (
|
|
9
|
+
* Constructs a new Session instance.
|
|
10
|
+
* If contextWindow = 0 (default) the prompt will have no context building up (ONE_SHOT).
|
|
11
|
+
*
|
|
10
12
|
* @param {string} name - The name of the prompt.
|
|
11
|
-
* @param {Prompt} prompt - The
|
|
12
|
-
* @param {string} [storage] - The base storage folder
|
|
13
|
+
* @param {Prompt} prompt - The Prompt instance.
|
|
14
|
+
* @param {string} [storage] - The base storage folder; defaults to process.cwd()/.cache/hello-dave.
|
|
13
15
|
*/
|
|
14
16
|
constructor(name: string, prompt: Prompt, storage?: string);
|
|
15
|
-
|
|
17
|
+
/** @type {string} Sanitized prompt name (public readonly). */
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns current session information.
|
|
21
|
+
*
|
|
22
|
+
* @returns {string} Formatted info: Name, Session, SessionCount, Path.
|
|
23
|
+
*/
|
|
16
24
|
info(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Lists unique session names (processed: remove _\d+, _ → space).
|
|
27
|
+
*
|
|
28
|
+
* @returns {string[]} Array of unique session names.
|
|
29
|
+
*/
|
|
17
30
|
sessionList(): string[];
|
|
18
31
|
/**
|
|
19
|
-
*
|
|
32
|
+
* Sets/advances to a session and loads its messages.
|
|
33
|
+
* Updates counter to last version if exists.
|
|
20
34
|
*
|
|
21
35
|
* @param {string} sess - The session name.
|
|
22
|
-
* @
|
|
36
|
+
* @returns {Message[]} Messages from the session (or []).
|
|
23
37
|
*/
|
|
24
38
|
set(sess: string): Message[];
|
|
25
39
|
/**
|
|
26
|
-
*
|
|
40
|
+
* Empties all caches: sessions, records, logs.
|
|
27
41
|
*/
|
|
28
42
|
empty(): void;
|
|
29
43
|
#private;
|