@j-o-r/hello-dave 0.0.0
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/LICENSE +73 -0
- package/README.md +207 -0
- package/bin/hdAsk.js +103 -0
- package/bin/hdClear.js +13 -0
- package/bin/hdCode.js +110 -0
- package/bin/hdConnect.js +230 -0
- package/bin/hdInspect.js +28 -0
- package/bin/hdNpm.js +114 -0
- package/bin/hdPrompt.js +108 -0
- package/examples/claude-test.js +89 -0
- package/examples/claude.js +143 -0
- package/examples/gpt.js +127 -0
- package/examples/gpt_code.js +125 -0
- package/examples/gpt_note_keeping.js +117 -0
- package/examples/grok.js +119 -0
- package/examples/grok_code.js +114 -0
- package/examples/grok_note_keeping.js +111 -0
- package/lib/API/anthropic.com/text.js +402 -0
- package/lib/API/brave.com/search.js +239 -0
- package/lib/API/openai.com/README.md +1 -0
- package/lib/API/openai.com/reponses/MESSAGES.md +69 -0
- package/lib/API/openai.com/reponses/text.js +416 -0
- package/lib/API/x.ai/text.js +415 -0
- package/lib/AgentClient.js +197 -0
- package/lib/AgentManager.js +144 -0
- package/lib/AgentServer.js +336 -0
- package/lib/Cli.js +256 -0
- package/lib/Prompt.js +728 -0
- package/lib/Session.js +231 -0
- package/lib/ToolSet.js +186 -0
- package/lib/fafs.js +93 -0
- package/lib/genericToolset.js +170 -0
- package/lib/index.js +34 -0
- package/lib/promptHelpers.js +132 -0
- package/lib/testToolset.js +42 -0
- package/module.md +189 -0
- package/package.json +49 -0
- package/types/API/anthropic.com/text.d.ts +207 -0
- package/types/API/brave.com/search.d.ts +156 -0
- package/types/API/openai.com/reponses/text.d.ts +225 -0
- package/types/API/x.ai/text.d.ts +286 -0
- package/types/AgentClient.d.ts +70 -0
- package/types/AgentManager.d.ts +112 -0
- package/types/AgentServer.d.ts +38 -0
- package/types/Cli.d.ts +52 -0
- package/types/Prompt.d.ts +298 -0
- package/types/Session.d.ts +31 -0
- package/types/ToolSet.d.ts +95 -0
- package/types/fafs.d.ts +47 -0
- package/types/genericToolset.d.ts +3 -0
- package/types/index.d.ts +23 -0
- package/types/promptHelpers.d.ts +1 -0
- package/types/testToolset.d.ts +3 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export default AgentClient;
|
|
2
|
+
export type OARequest = typeof import("./API/openai.com/reponses/text.js").request;
|
|
3
|
+
export type XRequest = typeof import("./API/x.ai/text.js").request;
|
|
4
|
+
export type ANTHRequest = typeof import("./API/anthropic.com/text.js").request;
|
|
5
|
+
export type XOptions = import("./API/x.ai/text.js").XOptions;
|
|
6
|
+
export type OAOptions = import("./API/openai.com/reponses/text.js").OAOptions;
|
|
7
|
+
export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
8
|
+
export type Prompt = import("./Prompt.js").default;
|
|
9
|
+
export type ToolSet = import("./ToolSet.js").default;
|
|
10
|
+
export type WSOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* - The prompt session
|
|
13
|
+
*/
|
|
14
|
+
prompt: Prompt;
|
|
15
|
+
/**
|
|
16
|
+
* - The toolset
|
|
17
|
+
*/
|
|
18
|
+
toolset?: import("./ToolSet.js").default | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* - Custom introduction message.
|
|
21
|
+
*/
|
|
22
|
+
description: string;
|
|
23
|
+
/**
|
|
24
|
+
* - Logical name: e.g. search, code, os, support.
|
|
25
|
+
*/
|
|
26
|
+
name: string;
|
|
27
|
+
url?: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* - How often to pull one message from the queue.
|
|
30
|
+
*/
|
|
31
|
+
intervalMs?: number | undefined;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {import('./API/openai.com/reponses/text.js').request} OARequest
|
|
35
|
+
* @typedef {import('./API/x.ai/text.js').request} XRequest
|
|
36
|
+
* @typedef {import('./API/anthropic.com/text.js').request} ANTHRequest
|
|
37
|
+
*
|
|
38
|
+
* @typedef {import('./API/x.ai/text.js').XOptions} XOptions
|
|
39
|
+
* @typedef {import('./API/openai.com/reponses/text.js').OAOptions} OAOptions
|
|
40
|
+
* @typedef {import('./API/anthropic.com/text.js').ANTHOptions} ANTHOptions
|
|
41
|
+
*
|
|
42
|
+
* @typedef {import('./Prompt.js').default} Prompt
|
|
43
|
+
* @typedef {import('./ToolSet.js').default} ToolSet
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {Object} WSOptions
|
|
47
|
+
* @property {Prompt} prompt - The prompt session
|
|
48
|
+
* @property {ToolSet} [toolset] - The toolset
|
|
49
|
+
* @property {string} description - Custom introduction message.
|
|
50
|
+
* @property {string} name - Logical name: e.g. search, code, os, support.
|
|
51
|
+
* @property {string} [url='ws://127.0.0.1:8000/ws?params=1234']
|
|
52
|
+
* @property {number} [intervalMs=250] - How often to pull one message from the queue.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Websocket Client
|
|
56
|
+
* Wrapper combining a session and a websocket
|
|
57
|
+
*/
|
|
58
|
+
declare class AgentClient {
|
|
59
|
+
/**
|
|
60
|
+
* Creates an instance of CLILoader.
|
|
61
|
+
* @param {WSOptions} options - The options to configure the CLILoader.
|
|
62
|
+
*/
|
|
63
|
+
constructor(options: WSOptions);
|
|
64
|
+
_start(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Enqueue an incoming websocket message and trigger the processor.
|
|
67
|
+
*/
|
|
68
|
+
incoming(e: any): void;
|
|
69
|
+
#private;
|
|
70
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export default AgentManager;
|
|
2
|
+
export type XOptions = import("./API/x.ai/text.js").XOptions;
|
|
3
|
+
export type OAOptions = import("./API/openai.com/reponses/text.js").OAOptions;
|
|
4
|
+
export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
5
|
+
export type Setup = {
|
|
6
|
+
/**
|
|
7
|
+
* - Initial system prompt
|
|
8
|
+
*/
|
|
9
|
+
prompt: string;
|
|
10
|
+
/**
|
|
11
|
+
* - Model options
|
|
12
|
+
*/
|
|
13
|
+
options: OAOptions | XOptions | ANTHOptions;
|
|
14
|
+
/**
|
|
15
|
+
* - AI endpoint to use
|
|
16
|
+
*/
|
|
17
|
+
api: "gpt" | "grok" | "claude";
|
|
18
|
+
/**
|
|
19
|
+
* - The size in tokens for the context/session
|
|
20
|
+
*/
|
|
21
|
+
contextWindow?: number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* -
|
|
24
|
+
*/
|
|
25
|
+
toolsetMode?: void | "auto" | "required" | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* - verbose output
|
|
28
|
+
*/
|
|
29
|
+
debug?: boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
export type Options = {
|
|
32
|
+
/**
|
|
33
|
+
* - Agent name
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* - path to session/record storage
|
|
38
|
+
*/
|
|
39
|
+
cachePath?: string | undefined;
|
|
40
|
+
};
|
|
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
|
+
/**
|
|
47
|
+
* @typedef {Object} Setup
|
|
48
|
+
* @property {string} prompt - Initial system prompt
|
|
49
|
+
* @property {OAOptions|XOptions|ANTHOptions} options - Model options
|
|
50
|
+
* @property {'gpt'|'grok'|'claude'} api - AI endpoint to use
|
|
51
|
+
* @property {number} [contextWindow] - The size in tokens for the context/session
|
|
52
|
+
* @property {'auto'|'required'|void} [toolsetMode] -
|
|
53
|
+
* @property {boolean} [debug] - verbose output
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {Object} Options
|
|
57
|
+
* @property {string} name - Agent name
|
|
58
|
+
* @property {string} [cachePath] - path to session/record storage
|
|
59
|
+
*/
|
|
60
|
+
declare class AgentManager {
|
|
61
|
+
/**
|
|
62
|
+
* @param {Options} options
|
|
63
|
+
*/
|
|
64
|
+
constructor(options: Options);
|
|
65
|
+
/**
|
|
66
|
+
* @param {Setup} setup
|
|
67
|
+
*/
|
|
68
|
+
setup(setup: Setup): this;
|
|
69
|
+
/**
|
|
70
|
+
* Start a CLI for local usage
|
|
71
|
+
* @param {string} description - introduction message for the CLI user
|
|
72
|
+
*/
|
|
73
|
+
startCli(description: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Attach a session to an AgentServer
|
|
76
|
+
* DO NOT ATTACH TO SELF, however, when in server mode
|
|
77
|
+
* An AgentServer can attach as client to another server
|
|
78
|
+
* @param {string} name - function_call name
|
|
79
|
+
* @param {string} description - function_call description
|
|
80
|
+
* @param {string} [url='ws://127.0.0.1:8000/ws'] - ws URL
|
|
81
|
+
*/
|
|
82
|
+
attach(name: string, description: string, url?: string): AgentClient;
|
|
83
|
+
/**
|
|
84
|
+
* Start the Agent in server mode.
|
|
85
|
+
* A server is always started on localhost
|
|
86
|
+
* Clients can attach now and are accesible as via function_calls (toolset)
|
|
87
|
+
* @param {string} name - function_call name
|
|
88
|
+
* @param {string} description - function_call description
|
|
89
|
+
* @param {number} [port=8000] - Start the dynamic toolset server on this port
|
|
90
|
+
*/
|
|
91
|
+
enableServer(name: string, description?: string, port?: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* Direct call to the prompt
|
|
94
|
+
* @param {string} input
|
|
95
|
+
* @returns {Promise<string>}
|
|
96
|
+
*/
|
|
97
|
+
directCall(input: string): Promise<string>;
|
|
98
|
+
/** @returns {Prompt} */
|
|
99
|
+
getPrompt(): Prompt;
|
|
100
|
+
/** @returns {ToolSet|void} */
|
|
101
|
+
getToolset(): ToolSet | void;
|
|
102
|
+
/** @returns {Promise<import('./fafs.js').EnvironmentInfo>} */
|
|
103
|
+
environment(): Promise<import("./fafs.js").EnvironmentInfo>;
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} name - the toolname
|
|
106
|
+
*/
|
|
107
|
+
addGenericToolcall(name: string): void;
|
|
108
|
+
#private;
|
|
109
|
+
}
|
|
110
|
+
import { AgentClient } from './index.js';
|
|
111
|
+
import { Prompt } from './index.js';
|
|
112
|
+
import { ToolSet } from './index.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export default AgentServer;
|
|
2
|
+
export type Client = import("../node_modules/@j-o-r/apiserver/types/ClientWrapper.d.ts").ClientWrapper;
|
|
3
|
+
export type Prompt = import("./Prompt.js").default;
|
|
4
|
+
export type ToolSet = import("./ToolSet.js").default;
|
|
5
|
+
export type Session = import("./Session.js").default;
|
|
6
|
+
export type AuthFunction = (conn: import("@j-o-r/apiserver/types/WebSocketServer.js").WebSocketConnection) => Promise<boolean>;
|
|
7
|
+
export type AgentServerOptions = {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
prompt: Prompt;
|
|
11
|
+
session: Session;
|
|
12
|
+
auth?: AuthFunction | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* - default 8000
|
|
15
|
+
*/
|
|
16
|
+
port?: number | undefined;
|
|
17
|
+
debug?: boolean | undefined;
|
|
18
|
+
};
|
|
19
|
+
declare class AgentServer {
|
|
20
|
+
/**
|
|
21
|
+
* @param {AgentServerOptions} options
|
|
22
|
+
*/
|
|
23
|
+
constructor(options: AgentServerOptions);
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* Returns a Dynamic Toolset
|
|
27
|
+
* With registered WS clients as toolcalls
|
|
28
|
+
* A deamon start on local host 127.0.0.1, always
|
|
29
|
+
* @returns {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
private _start;
|
|
32
|
+
/**
|
|
33
|
+
* Send a reset messages to all clients
|
|
34
|
+
* reset will start a new session
|
|
35
|
+
*/
|
|
36
|
+
resetAll(): void;
|
|
37
|
+
#private;
|
|
38
|
+
}
|
package/types/Cli.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export default Cli;
|
|
2
|
+
export type OARequest = typeof import("./API/openai.com/reponses/text.js").request;
|
|
3
|
+
export type XRequest = typeof import("./API/x.ai/text.js").request;
|
|
4
|
+
export type ANTHRequest = typeof import("./API/anthropic.com/text.js").request;
|
|
5
|
+
export type XOptions = import("./API/x.ai/text.js").XOptions;
|
|
6
|
+
export type OAOptions = import("./API/openai.com/reponses/text.js").OAOptions;
|
|
7
|
+
export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
8
|
+
export type Prompt = import("./Prompt.js").default;
|
|
9
|
+
export type Session = import("./Session.js").default;
|
|
10
|
+
export type ToolSet = import("./ToolSet.js").default;
|
|
11
|
+
export type CLIOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* - The prompt session
|
|
14
|
+
*/
|
|
15
|
+
prompt: Prompt;
|
|
16
|
+
/**
|
|
17
|
+
* - Session Cache
|
|
18
|
+
*/
|
|
19
|
+
session: Session;
|
|
20
|
+
/**
|
|
21
|
+
* - The toolset
|
|
22
|
+
*/
|
|
23
|
+
toolset?: import("./ToolSet.js").default | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* - Custom introduction message.
|
|
26
|
+
*/
|
|
27
|
+
description?: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* - Custom help message.
|
|
30
|
+
*/
|
|
31
|
+
help?: string | undefined;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* CLILoader class for handling CLI-based interactions with AI models.
|
|
35
|
+
*/
|
|
36
|
+
declare class Cli {
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of CLILoader.
|
|
39
|
+
* @param {CLIOptions} options - The options to configure the CLILoader.
|
|
40
|
+
*/
|
|
41
|
+
constructor(options: CLIOptions);
|
|
42
|
+
printInfo(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Starts the CLI interaction.
|
|
45
|
+
* @param {string} [s] - optional user string/question
|
|
46
|
+
* @returns {Promise<void>}
|
|
47
|
+
*/
|
|
48
|
+
start(s?: string): Promise<void>;
|
|
49
|
+
loadSession(): Promise<void>;
|
|
50
|
+
reset(): Promise<void>;
|
|
51
|
+
#private;
|
|
52
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
export default Prompt;
|
|
2
|
+
export type OARequest = typeof import("./API/openai.com/reponses/text.js").request;
|
|
3
|
+
export type XRequest = typeof import("./API/x.ai/text.js").request;
|
|
4
|
+
export type ANTHRequest = typeof import("./API/anthropic.com/text.js").request;
|
|
5
|
+
export type XOptions = import("./API/x.ai/text.js").XOptions;
|
|
6
|
+
export type OAOptions = import("./API/openai.com/reponses/text.js").OAOptions;
|
|
7
|
+
export type ANTHOptions = import("./API/anthropic.com/text.js").ANTHOptions;
|
|
8
|
+
export type ToolSet = import("./ToolSet.js").default;
|
|
9
|
+
/**
|
|
10
|
+
* - The AI model to use for chat functionality.
|
|
11
|
+
*/
|
|
12
|
+
export type request = OARequest | XRequest | ANTHRequest;
|
|
13
|
+
/**
|
|
14
|
+
* - Model options
|
|
15
|
+
*/
|
|
16
|
+
export type options = OAOptions | XOptions | ANTHOptions;
|
|
17
|
+
export type Roles = "system" | "assistant" | "user" | "tool" | "log" | "reasoning";
|
|
18
|
+
export type Record = {
|
|
19
|
+
/**
|
|
20
|
+
* - remote request id or generated requestId
|
|
21
|
+
*/
|
|
22
|
+
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* - Date in ISO string format
|
|
25
|
+
*/
|
|
26
|
+
isoDate: string;
|
|
27
|
+
/**
|
|
28
|
+
* - Execution time in MS of the model / method
|
|
29
|
+
*/
|
|
30
|
+
duration: number;
|
|
31
|
+
/**
|
|
32
|
+
* - Execution context endpoint_name / server_name / interpreter_name
|
|
33
|
+
*/
|
|
34
|
+
environment: string;
|
|
35
|
+
/**
|
|
36
|
+
* - LLM model, method , funtion name
|
|
37
|
+
*/
|
|
38
|
+
model: string;
|
|
39
|
+
/**
|
|
40
|
+
* - Number of tokens to process
|
|
41
|
+
*/
|
|
42
|
+
tokensIn: number;
|
|
43
|
+
/**
|
|
44
|
+
* - Number of tokens in the response
|
|
45
|
+
*/
|
|
46
|
+
tokensOut: number;
|
|
47
|
+
};
|
|
48
|
+
export type TextMessage = {
|
|
49
|
+
/**
|
|
50
|
+
* ="text" - The type of the message, should be "text".
|
|
51
|
+
*/
|
|
52
|
+
type: string;
|
|
53
|
+
/**
|
|
54
|
+
* - The content of the text message.
|
|
55
|
+
*/
|
|
56
|
+
text: string;
|
|
57
|
+
};
|
|
58
|
+
export type ImageMessage = {
|
|
59
|
+
/**
|
|
60
|
+
* ="image_url" - The type of the message, should be "image_url".
|
|
61
|
+
*/
|
|
62
|
+
type: string;
|
|
63
|
+
/**
|
|
64
|
+
* - URL or "data:image/png;base64,{base64_image}"
|
|
65
|
+
*/
|
|
66
|
+
url: string;
|
|
67
|
+
};
|
|
68
|
+
export type AudioMessage = {
|
|
69
|
+
/**
|
|
70
|
+
* ="url" - The type of the message, should be "image_url".
|
|
71
|
+
*/
|
|
72
|
+
type: string;
|
|
73
|
+
/**
|
|
74
|
+
* - URL or "data:image/png;base64,{base64_image}"
|
|
75
|
+
*/
|
|
76
|
+
url: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The `PRMessagerole.role` must be 'assistant'
|
|
80
|
+
*/
|
|
81
|
+
export type FunctionRequest = {
|
|
82
|
+
/**
|
|
83
|
+
* - The type of the message, should be "function_request".
|
|
84
|
+
*/
|
|
85
|
+
type: "function_request";
|
|
86
|
+
/**
|
|
87
|
+
* - Function object with properties
|
|
88
|
+
*/
|
|
89
|
+
function_request: {
|
|
90
|
+
name: string;
|
|
91
|
+
id: string;
|
|
92
|
+
call_id: string;
|
|
93
|
+
parameters: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The `PRMessage.role` must 'tool'
|
|
98
|
+
*/
|
|
99
|
+
export type FunctionResponse = {
|
|
100
|
+
/**
|
|
101
|
+
* - The type of the message, should be "function_response".
|
|
102
|
+
*/
|
|
103
|
+
type: "function_response";
|
|
104
|
+
/**
|
|
105
|
+
* - Function object with properties
|
|
106
|
+
*/
|
|
107
|
+
function_response: {
|
|
108
|
+
name: string;
|
|
109
|
+
id: string;
|
|
110
|
+
call_id: string;
|
|
111
|
+
response: string;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export type Content = TextMessage | ImageMessage | AudioMessage | FunctionRequest | FunctionResponse;
|
|
115
|
+
export type Message = {
|
|
116
|
+
/**
|
|
117
|
+
* - Message role
|
|
118
|
+
*/
|
|
119
|
+
role: Roles;
|
|
120
|
+
/**
|
|
121
|
+
* -
|
|
122
|
+
*/
|
|
123
|
+
content: Content[];
|
|
124
|
+
/**
|
|
125
|
+
* - optional author name
|
|
126
|
+
*/
|
|
127
|
+
name?: string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* - This message object is part of the base prompt (reuse after reset) and is not truncated
|
|
130
|
+
*/
|
|
131
|
+
sticky?: boolean | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* - A timestamp in MS for reconstruction truncated prompts (for creating large context embeddings)
|
|
134
|
+
*/
|
|
135
|
+
ts?: number | undefined;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @fires Prompt#add
|
|
140
|
+
* Event: message added
|
|
141
|
+
*
|
|
142
|
+
* @event Prompt#add
|
|
143
|
+
* @type {Message}
|
|
144
|
+
*/
|
|
145
|
+
declare class Prompt {
|
|
146
|
+
/**
|
|
147
|
+
* Constructs a new Prompt instance.
|
|
148
|
+
* If contextWindow = 0 (defaut) the prompt will have no context building up (ONE_SHOT)
|
|
149
|
+
* @param {number} [contextWindow] - The max size of a total prompt in tokens. (context)
|
|
150
|
+
*/
|
|
151
|
+
constructor(contextWindow?: number);
|
|
152
|
+
EVENTS: Readonly<{
|
|
153
|
+
start: string;
|
|
154
|
+
retrigger: string;
|
|
155
|
+
finished: string;
|
|
156
|
+
message: string;
|
|
157
|
+
record: string;
|
|
158
|
+
truncated: string;
|
|
159
|
+
reset: string;
|
|
160
|
+
ready: string;
|
|
161
|
+
error: string;
|
|
162
|
+
warning: string;
|
|
163
|
+
tool_request: string;
|
|
164
|
+
tool_response: string;
|
|
165
|
+
tool_error: string;
|
|
166
|
+
http_request: string;
|
|
167
|
+
http_response: string;
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* @param {request} handler
|
|
171
|
+
* @param {ToolSet} toolset
|
|
172
|
+
* @param {options} options
|
|
173
|
+
*/
|
|
174
|
+
setAdaptor(handler: request, toolset: ToolSet, options: options): void;
|
|
175
|
+
/**
|
|
176
|
+
* Get the names of the available funtion calls
|
|
177
|
+
* @returns {string[]}
|
|
178
|
+
*/
|
|
179
|
+
toolsetFunctions(): string[];
|
|
180
|
+
/**
|
|
181
|
+
* @returns {ToolSet|void}
|
|
182
|
+
*/
|
|
183
|
+
get toolset(): ToolSet | void;
|
|
184
|
+
/**
|
|
185
|
+
* Start a requests
|
|
186
|
+
* @param {string|Content} content
|
|
187
|
+
* @returns {Promise<string>}
|
|
188
|
+
*/
|
|
189
|
+
call(content: string | Content): Promise<string>;
|
|
190
|
+
/**
|
|
191
|
+
* Trigger a request when the last added message is a user or tool message
|
|
192
|
+
* Exit on error
|
|
193
|
+
*/
|
|
194
|
+
triggerRequest(): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Get the maximum token length for this prompt
|
|
197
|
+
* @returns {number}
|
|
198
|
+
*/
|
|
199
|
+
get contextLength(): number;
|
|
200
|
+
/**
|
|
201
|
+
* Imports messages.
|
|
202
|
+
* Bypasses the event emitter
|
|
203
|
+
* @param {Message[]} messages
|
|
204
|
+
* @throws {Error} If the input string is invalid.
|
|
205
|
+
*/
|
|
206
|
+
set messages(messages: Message[]);
|
|
207
|
+
/**
|
|
208
|
+
* Returns a copy of the messages array.
|
|
209
|
+
* @returns {Message[]} - A copy of the messages array.
|
|
210
|
+
*/
|
|
211
|
+
get messages(): Message[];
|
|
212
|
+
/**
|
|
213
|
+
* Return the most recent, the LAST message added
|
|
214
|
+
* @returns {Message|void}
|
|
215
|
+
*/
|
|
216
|
+
getLastMessage(): Message | void;
|
|
217
|
+
/**
|
|
218
|
+
* Return the readable content (type == text)
|
|
219
|
+
* @param {Content[]} content
|
|
220
|
+
* @return {string}
|
|
221
|
+
*/
|
|
222
|
+
contentToString(content: Content[]): string;
|
|
223
|
+
/**
|
|
224
|
+
* Count the number of tokens on a given string
|
|
225
|
+
* Or the recorded tokencount of the last roundtrip
|
|
226
|
+
* @param {string} [str] - the string to count
|
|
227
|
+
* @param returns {number}
|
|
228
|
+
*/
|
|
229
|
+
countTokens(str?: string): number;
|
|
230
|
+
/**
|
|
231
|
+
* reduce the prompt length to fit in the contextWindow
|
|
232
|
+
* or simply reset when there is no contextWindow
|
|
233
|
+
* @returns {boolean} true when the prompt has been altered/reduced
|
|
234
|
+
*/
|
|
235
|
+
truncate(): boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Gets the length of the messages array.
|
|
238
|
+
* @returns {number} - The length of the messages array.
|
|
239
|
+
*/
|
|
240
|
+
get length(): number;
|
|
241
|
+
/**
|
|
242
|
+
* Gets the system prompt from the messages.
|
|
243
|
+
* @returns {string} - The system prompt.
|
|
244
|
+
* @throws {Error} If no system prompt is available.
|
|
245
|
+
*/
|
|
246
|
+
get system_prompt(): string;
|
|
247
|
+
/**
|
|
248
|
+
* Checks if a system prompt is available.
|
|
249
|
+
* @returns {boolean} - True if a system prompt is available, false otherwise.
|
|
250
|
+
*/
|
|
251
|
+
get hasSystemprompt(): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Adds a text message to the messages array.
|
|
254
|
+
* @param {Roles} role - The role of the message.
|
|
255
|
+
* @param {string} message - The text message.
|
|
256
|
+
* @param {boolean} [sticky] - Whether the message is part of the base prompt.
|
|
257
|
+
* @fires Prompt#message
|
|
258
|
+
* @throws {Error} If the message order is invalid or the message is invalid.
|
|
259
|
+
*/
|
|
260
|
+
add(role: Roles, message: string, sticky?: boolean): void;
|
|
261
|
+
/**
|
|
262
|
+
* Adds a multi-modal message to the messages array.
|
|
263
|
+
* @param {Roles} role - The role of the message.
|
|
264
|
+
* @param {Content[]} messages - The actual messages with multi-modal content.
|
|
265
|
+
* @param {boolean} [sticky] - Whether the message is part of the base prompt.
|
|
266
|
+
* @fires Prompt#add
|
|
267
|
+
* @throws {Error} If the message order is invalid or the messages are invalid.
|
|
268
|
+
*/
|
|
269
|
+
addMultiModal(role: Roles, messages: Content[], sticky?: boolean): void;
|
|
270
|
+
/**
|
|
271
|
+
* Removes all non-sticky messages and returns them
|
|
272
|
+
* Keeps the 'base' (sticky) prompt/messages.
|
|
273
|
+
* @returns {Message[]}
|
|
274
|
+
*/
|
|
275
|
+
reset(): Message[];
|
|
276
|
+
/**
|
|
277
|
+
* Register a record from the adapter
|
|
278
|
+
* @param {Record} record - Records for billing and optimizing
|
|
279
|
+
* @throws {Error} If the record is invalid.
|
|
280
|
+
*/
|
|
281
|
+
addRecord(record: Record): void;
|
|
282
|
+
/**
|
|
283
|
+
* Add a list of records (with multiple prompts to maintain a full history of events)
|
|
284
|
+
* @param {Record[]} records - Records for billing and optimizing
|
|
285
|
+
* @throws {Error} If the record is invalid.
|
|
286
|
+
*/
|
|
287
|
+
addRecords(records: Record[]): void;
|
|
288
|
+
/**
|
|
289
|
+
* Template record
|
|
290
|
+
* @returns {Record}
|
|
291
|
+
*/
|
|
292
|
+
templateRecord(): Record;
|
|
293
|
+
/**
|
|
294
|
+
* Gather metrics as info
|
|
295
|
+
*/
|
|
296
|
+
info(): string;
|
|
297
|
+
#private;
|
|
298
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default Session;
|
|
2
|
+
export type Message = import("./Prompt.js").Message;
|
|
3
|
+
export type Record = import("./Prompt.js").Record;
|
|
4
|
+
/**
|
|
5
|
+
*/
|
|
6
|
+
declare class Session {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new Prompt instance.
|
|
9
|
+
* If contextWindow = 0 (defaut) the prompt will have no context building up (ONE_SHOT)
|
|
10
|
+
* @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
|
+
*/
|
|
14
|
+
constructor(name: string, prompt: Prompt, storage?: string);
|
|
15
|
+
name: string | undefined;
|
|
16
|
+
info(): string;
|
|
17
|
+
sessionList(): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Get messages fro, a session
|
|
20
|
+
*
|
|
21
|
+
* @param {string} sess - The session name.
|
|
22
|
+
* @return {Message[]}
|
|
23
|
+
*/
|
|
24
|
+
set(sess: string): Message[];
|
|
25
|
+
/**
|
|
26
|
+
* Remove all previous sessions and records
|
|
27
|
+
*/
|
|
28
|
+
empty(): void;
|
|
29
|
+
#private;
|
|
30
|
+
}
|
|
31
|
+
import Prompt from './Prompt.js';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export default ToolSet;
|
|
2
|
+
export type TSSchema = {
|
|
3
|
+
/**
|
|
4
|
+
* - Type of the object
|
|
5
|
+
*/
|
|
6
|
+
type: string;
|
|
7
|
+
/**
|
|
8
|
+
* - Description of properties
|
|
9
|
+
*/
|
|
10
|
+
properties: object;
|
|
11
|
+
/**
|
|
12
|
+
* - Required properties
|
|
13
|
+
*/
|
|
14
|
+
required?: string[] | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type TSTool = {
|
|
17
|
+
/**
|
|
18
|
+
* - Command description
|
|
19
|
+
*/
|
|
20
|
+
description: string;
|
|
21
|
+
/**
|
|
22
|
+
* - JS JSON schema
|
|
23
|
+
*/
|
|
24
|
+
parameters: TSSchema;
|
|
25
|
+
method: (arg0: object) => Promise<any>;
|
|
26
|
+
};
|
|
27
|
+
export type TSToolListItem = {
|
|
28
|
+
/**
|
|
29
|
+
* - Command name
|
|
30
|
+
*/
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* - Command description
|
|
34
|
+
*/
|
|
35
|
+
description: string;
|
|
36
|
+
/**
|
|
37
|
+
* - JS JSON schema
|
|
38
|
+
*/
|
|
39
|
+
parameters: TSSchema;
|
|
40
|
+
};
|
|
41
|
+
declare class ToolSet {
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} [choice] - Default 'auto' auto|none|required
|
|
44
|
+
*/
|
|
45
|
+
constructor(choice?: string);
|
|
46
|
+
/**
|
|
47
|
+
* How many functions have we registered
|
|
48
|
+
* @returns {number}
|
|
49
|
+
*/
|
|
50
|
+
get length(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Register a Tool/Command/Function
|
|
53
|
+
* @param {string} name - [a-z_0-9]{2,} The lowercase string name of the callback e.g. 'get_node_version'
|
|
54
|
+
* @param {string} description - What does it do
|
|
55
|
+
* @param {TSSchema} parameters - SCHEMA object describing the function's input parameters
|
|
56
|
+
* @param {function(object): Promise<*>} method - Async function to call
|
|
57
|
+
*/
|
|
58
|
+
add(name: string, description: string, parameters: TSSchema, method: (arg0: object) => Promise<any>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get a tool from the toolset
|
|
61
|
+
* @param {string} name
|
|
62
|
+
* @returns {TSTool}
|
|
63
|
+
*/
|
|
64
|
+
get(name: string): TSTool;
|
|
65
|
+
/**
|
|
66
|
+
* Delete a function_call
|
|
67
|
+
* @param {string} name
|
|
68
|
+
*/
|
|
69
|
+
delete(name: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Is 'name' already registered
|
|
72
|
+
* @param {string} name
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
has(name: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Get a list of tools available
|
|
78
|
+
* @returns {TSToolListItem[]}
|
|
79
|
+
*/
|
|
80
|
+
list(): TSToolListItem[];
|
|
81
|
+
get toolChoice(): string;
|
|
82
|
+
/**
|
|
83
|
+
* Execute a method
|
|
84
|
+
* @param {string} name
|
|
85
|
+
* @param {object} params
|
|
86
|
+
*/
|
|
87
|
+
call(name: string, params: object): Promise<any>;
|
|
88
|
+
/**
|
|
89
|
+
* Execute function requests from the last message.
|
|
90
|
+
* @param {Prompt} prompt - Handle tool calls.
|
|
91
|
+
*/
|
|
92
|
+
execute(prompt: Prompt): Promise<void>;
|
|
93
|
+
#private;
|
|
94
|
+
}
|
|
95
|
+
import Prompt from "./Prompt.js";
|