@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.
Files changed (127) hide show
  1. package/CHANGELOG.md +13 -26
  2. package/README.md +161 -522
  3. package/README.md.bak +144 -449
  4. package/{examples → agents}/ask_agent.js +5 -5
  5. package/{examples → agents}/codeserver.sh +14 -14
  6. package/{examples → agents}/daisy_agent.js +5 -5
  7. package/{examples → agents}/docs_agent.js +5 -5
  8. package/{examples → agents}/gpt_agent.js +5 -5
  9. package/{examples → agents}/grok_agent.js +5 -5
  10. package/agents/memory_agent.js +263 -0
  11. package/{examples → agents}/npm_agent.js +5 -5
  12. package/{examples → agents}/prompt_agent.js +5 -5
  13. package/agents/spawn_agent.js +137 -0
  14. package/{examples → agents}/test_agent.js +6 -8
  15. package/{examples → agents}/todo_agent.js +5 -5
  16. package/bin/codeDave +58 -0
  17. package/bin/dave.js +114 -96
  18. package/lib/AgentClient.js +111 -67
  19. package/lib/AgentManager.js +111 -80
  20. package/lib/AgentServer.js +144 -104
  21. package/lib/Cli.js +126 -93
  22. package/lib/Prompt.js +38 -5
  23. package/lib/Session.js +102 -79
  24. package/lib/ToolSet.js +79 -60
  25. package/lib/fafs.js +54 -19
  26. package/lib/genericToolset.js +109 -213
  27. package/lib/wsCli.js +50 -19
  28. package/lib/wsIO.js +11 -17
  29. package/package.json +2 -2
  30. package/types/AgentClient.d.ts +69 -35
  31. package/types/AgentManager.d.ts +50 -56
  32. package/types/AgentServer.d.ts +63 -16
  33. package/types/Cli.d.ts +56 -10
  34. package/types/Prompt.d.ts +36 -4
  35. package/types/Session.d.ts +23 -9
  36. package/types/ToolSet.d.ts +49 -32
  37. package/types/fafs.d.ts +68 -25
  38. package/types/wsCli.d.ts +14 -0
  39. package/types/wsIO.d.ts +9 -5
  40. package/utils/search_sessions.sh +100 -53
  41. package/README.md.backup +0 -269
  42. package/README.md.bak.1774780058 +0 -338
  43. package/README.md.bak2 +0 -531
  44. package/bin/spawn_agent.js +0 -293
  45. package/docs.bak.1774780058/agent-manager.md +0 -167
  46. package/docs.bak.1774780058/agent-manager.md.bak +0 -137
  47. package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
  48. package/docs.bak.1774780058/codeserver-pattern.md +0 -191
  49. package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
  50. package/docs.bak.1774780058/project-overview.md +0 -67
  51. package/docs.bak.1774780058/project-overview.md.bak +0 -67
  52. package/docs.bak.1774780058/prompt-class.md +0 -141
  53. package/docs.bak.1774780058/prompt-class.md.bak +0 -142
  54. package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
  55. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
  56. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
  57. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
  58. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
  59. package/docs.bak.1774780058/toolset.md +0 -164
  60. package/docs.bak.1774780058/toolset.md.bak +0 -94
  61. package/docs.bak.1774780058/toolset.md.bak3 +0 -161
  62. package/docs.bak.1774780058/toolset.md.bak4 +0 -161
  63. package/docs.bak.1774780058/toolset.md.bak5 +0 -161
  64. package/docs.bak.1774780058/toolset.md.bak6 +0 -163
  65. package/docs.bak.1774780058/toolset.md.bak_path +0 -163
  66. package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
  67. package/docs.bak.1774780058/xai-responses.md +0 -111
  68. package/docs.bak.1774780058/xai-responses.md.bak +0 -107
  69. package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
  70. package/docs.bak.1774780058/xai_collections.md +0 -106
  71. package/examples/memory_agent.js +0 -152
  72. package/examples.bak.1774780058/ask_agent.js +0 -114
  73. package/examples.bak.1774780058/code_agent.js +0 -149
  74. package/examples.bak.1774780058/coderev_agent.js +0 -72
  75. package/examples.bak.1774780058/codeserver.sh +0 -47
  76. package/examples.bak.1774780058/daisy_agent.js +0 -177
  77. package/examples.bak.1774780058/docs_agent.js +0 -119
  78. package/examples.bak.1774780058/gpt_agent.js +0 -109
  79. package/examples.bak.1774780058/grok_agent.js +0 -98
  80. package/examples.bak.1774780058/memory_agent.js +0 -112
  81. package/examples.bak.1774780058/npm_agent.js +0 -175
  82. package/examples.bak.1774780058/prompt_agent.js +0 -112
  83. package/examples.bak.1774780058/readme_agent.js +0 -144
  84. package/examples.bak.1774780058/spawn_agent.js +0 -263
  85. package/examples.bak.1774780058/test_agent.js +0 -162
  86. package/examples.bak.1774780058/todo_agent.js +0 -138
  87. package/lib/genericToolset.js.bak_syntax +0 -402
  88. package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
  89. package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
  90. package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
  91. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
  92. package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
  93. package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
  94. package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
  95. package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
  96. package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
  97. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
  98. package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
  99. package/scenarios.bak.1774780058/environment.js +0 -10
  100. package/scenarios.bak.1774780058/example.js +0 -17
  101. package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
  102. package/scenarios.bak.1774780058/grok.js +0 -113
  103. package/scenarios.bak.1774780058/memory-tools.js +0 -51
  104. package/scenarios.bak.1774780058/openai-o3.js +0 -137
  105. package/scenarios.bak.1774780058/openai-prompt.js +0 -155
  106. package/scenarios.bak.1774780058/openai-session.js +0 -148
  107. package/scenarios.bak.1774780058/openai.js +0 -102
  108. package/scenarios.bak.1774780058/prompt.js +0 -118
  109. package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
  110. package/scenarios.bak.1774780058/search.brave.com.js +0 -25
  111. package/scenarios.bak.1774780058/sh.js +0 -15
  112. package/scenarios.bak.1774780058/test-wsio.js +0 -26
  113. package/scenarios.bak.1774780058/testToolset.js +0 -42
  114. package/scenarios.bak.1774780058/toolset.js +0 -16
  115. package/scenarios.bak.1774780058/toolset.test.js +0 -141
  116. package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
  117. package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
  118. package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
  119. package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
  120. package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
  121. package/scenarios.bak.1774780058/wsClient.js +0 -69
  122. package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
  123. package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
  124. package/scenarios.bak.1774780058/xaicoll.js +0 -50
  125. package/scenarios.bak.1774780058/xaifiles.js +0 -48
  126. /package/{examples → agents}/code_agent.js +0 -0
  127. /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.5",
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
- "createAgent": "bin/spawn_agent.js"
17
+ "codeDave": "bin/codeDave"
18
18
  },
19
19
  "scripts": {
20
20
  "release": "npm run types && npm pack --pack-destination=release",
@@ -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
- * - The toolset
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: e.g. search, code, os, support.
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
- * - How often to pull one message from the queue.
36
+ * - Polling interval for queue processing (ms).
34
37
  */
35
38
  intervalMs?: number | undefined;
36
39
  };
37
40
  /**
38
- * @typedef {import('./API/openai.com/reponses/text.js').request} OARequest
39
- * @typedef {import('./API/x.ai/text.js').request} XRequest
40
- * @typedef {import('./API/anthropic.com/text.js').request} ANTHRequest
41
- *
42
- * @typedef {import('./API/x.ai/text.js').XOptions} XOptions
43
- * @typedef {import('./API/openai.com/reponses/text.js').OAOptions} OAOptions
44
- * @typedef {import('./API/anthropic.com/text.js').ANTHOptions} ANTHOptions
45
- *
46
- * @typedef {import('./Prompt.js').default} Prompt
47
- * @typedef {import('./ToolSet.js').default} ToolSet
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] - The toolset
53
- * @property {string} description - Custom introduction message.
54
- * @property {string} name - Logical name: e.g. search, code, os, support.
55
- * @property {string} secret - Websocket server access secret.
56
- * @property {string} [url='ws://127.0.0.1:8000/ws?params=1234']
57
- * @property {number} [intervalMs=250] - How often to pull one message from the queue.
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
- * Websocket Client
61
- * Wrapper combining a session and a websocket
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
- * Creates an instance of CLILoader.
66
- * @param {WSOptions} options - The options to configure the CLILoader.
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
- * Enqueue an incoming websocket message and trigger the processor.
72
- */
73
- incoming(e: any): void;
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
  }
@@ -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
- * - Model options
12
+ * - API model options.
13
13
  */
14
14
  options: XAIOptions | OAOptions | XOptions | ANTHOptions;
15
15
  /**
16
- * - AI endpoint to use
16
+ * - AI provider.
17
17
  */
18
18
  api: "gpt" | "xai" | "claude";
19
19
  /**
20
- * - The size in tokens for the context/session
20
+ * - Token limit for context.
21
21
  */
22
22
  contextWindow?: number | undefined;
23
23
  /**
24
- * -
24
+ * - Toolset activation mode.
25
25
  */
26
- toolsetMode?: void | "auto" | "required" | undefined;
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
- * - Secret string for WS access authorisation (server and client secrets should match)
38
+ * - WS auth secret (base64-encoded).
39
39
  */
40
40
  secret: string;
41
41
  /**
42
- * - path to session/record storage
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
- * @param {Options} options
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
- * @param {Setup} setup
74
- */
75
- setup(setup: Setup): this;
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
- * Direct call to the prompt
78
- * @param {string} input
79
- * @returns {Promise<string>}
80
- */
81
- directCall(input: string): Promise<string>;
82
- /** @returns {Prompt} */
65
+ * Direct synchronous call to the underlying Prompt.
66
+ * @param {string} input - User input.
67
+ * @returns {Promise&lt;string&gt;} 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|void} */
85
- getToolset(): ToolSet | void;
86
- /** @returns {Promise<import('./fafs.js').EnvironmentInfo>} */
87
- environment(): Promise<import("./fafs.js").EnvironmentInfo>;
73
+ /** @returns {ToolSet|null} Toolset if configured. */
74
+ getToolset(): ToolSet | null;
75
+ /** @returns {Promise&lt;import('./fafs.js').EnvironmentInfo&gt;} System env info. */
76
+ environment(): Promise<any> & lt;
88
77
  /**
89
- * Adds a pre-defined generic tool from lib/genericToolset.js to this agent's ToolSet.
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 - Valid generic tool name (validated /^[a-z_0-9]{2,}$/).
91
- * @throws {Error} If toolset not initialized or tool not found in pool.
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: Dispatches to CLI/server/attach/direct. Auto-gens cliIntro/desc if empty.
96
- * @param {number} [servePort] - Server port (if no input).
97
- * @param {string} [connectUrl] - WS to attach. e.g. ws://127.0.0.1:8091/ws
98
- * @param {string} [cliIntro=""] - CLI intro (auto-gen if falsy).
99
- * @param {string} [toolName=""] - name /^[a-z_0-9]{2,}$/ Tool name for server/attach (defaults to agent.name).
100
- * @param {string} [toolDescription=""] - Tool desc (auto-gen if falsy).
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&lt;void&gt;}
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<void>;
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';
@@ -1,42 +1,89 @@
1
1
  export default AgentServer;
2
- export type Client = import("../node_modules/@j-o-r/apiserver/types/ClientWrapper.d.ts").ClientWrapper;
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 AuthFunction = (conn: import("@j-o-r/apiserver/types/WebSocketServer.js").WebSocketConnection, req: any) => Promise<boolean>;
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
- * - server access secret
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
- * - default 8000
37
+ * - Custom auth function.
38
+ */
39
+ auth?: AuthFunction;
40
+ /**
41
+ * - Listen port (&gt;=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
- * @param {AgentServerOptions} options
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 &lt; 1024.
72
+ * @example See AgentServerOptions.
73
+ */
27
74
  constructor(options: AgentServerOptions);
28
75
  /**
29
- * @private
30
- * Returns a Dynamic Toolset
31
- * With registered WS clients as toolcalls
32
- * A deamon start on local host 127.0.0.1, always
33
- * @returns {Promise<void>}
34
- */
76
+ * @private
77
+ * Launches the WS server with handlers for messages, connections, closes.
78
+ * Defines HTTP / API index endpoint.
79
+ * @returns {Promise&lt;void&gt;}
80
+ */
35
81
  private _start;
36
82
  /**
37
- * Send a reset messages to all clients
38
- * reset will start a new session
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 prompt session
16
+ * - The Prompt instance for handling AI interactions.
14
17
  */
15
18
  prompt: Prompt;
16
19
  /**
17
- * - Session Cache
20
+ * - The Session instance for managing conversation history.
18
21
  */
19
22
  session: Session;
20
23
  /**
21
- * - The toolset
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
- * CLILoader class for handling CLI-based interactions with AI models.
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
- * Creates an instance of CLILoader.
39
- * @param {CLIOptions} options - The options to configure the CLILoader.
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 interaction.
45
- * @param {string} [s] - optional user string/question
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
- * @fires Prompt#add
142
- * Event: message added
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
- * @event Prompt#add
145
- * @type {Message}
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
  /**
@@ -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 Prompt instance.
9
- * If contextWindow = 0 (defaut) the prompt will have no context building up (ONE_SHOT)
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 prompt
12
- * @param {string} [storage] - The base storage folder, default this is process.cwd()
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
- name: string | undefined;
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
- * Get messages fro, a session
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
- * @return {Message[]}
36
+ * @returns {Message[]} Messages from the session (or []).
23
37
  */
24
38
  set(sess: string): Message[];
25
39
  /**
26
- * Remove all previous sessions and records
40
+ * Empties all caches: sessions, records, logs.
27
41
  */
28
42
  empty(): void;
29
43
  #private;