@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.
Files changed (53) hide show
  1. package/LICENSE +73 -0
  2. package/README.md +207 -0
  3. package/bin/hdAsk.js +103 -0
  4. package/bin/hdClear.js +13 -0
  5. package/bin/hdCode.js +110 -0
  6. package/bin/hdConnect.js +230 -0
  7. package/bin/hdInspect.js +28 -0
  8. package/bin/hdNpm.js +114 -0
  9. package/bin/hdPrompt.js +108 -0
  10. package/examples/claude-test.js +89 -0
  11. package/examples/claude.js +143 -0
  12. package/examples/gpt.js +127 -0
  13. package/examples/gpt_code.js +125 -0
  14. package/examples/gpt_note_keeping.js +117 -0
  15. package/examples/grok.js +119 -0
  16. package/examples/grok_code.js +114 -0
  17. package/examples/grok_note_keeping.js +111 -0
  18. package/lib/API/anthropic.com/text.js +402 -0
  19. package/lib/API/brave.com/search.js +239 -0
  20. package/lib/API/openai.com/README.md +1 -0
  21. package/lib/API/openai.com/reponses/MESSAGES.md +69 -0
  22. package/lib/API/openai.com/reponses/text.js +416 -0
  23. package/lib/API/x.ai/text.js +415 -0
  24. package/lib/AgentClient.js +197 -0
  25. package/lib/AgentManager.js +144 -0
  26. package/lib/AgentServer.js +336 -0
  27. package/lib/Cli.js +256 -0
  28. package/lib/Prompt.js +728 -0
  29. package/lib/Session.js +231 -0
  30. package/lib/ToolSet.js +186 -0
  31. package/lib/fafs.js +93 -0
  32. package/lib/genericToolset.js +170 -0
  33. package/lib/index.js +34 -0
  34. package/lib/promptHelpers.js +132 -0
  35. package/lib/testToolset.js +42 -0
  36. package/module.md +189 -0
  37. package/package.json +49 -0
  38. package/types/API/anthropic.com/text.d.ts +207 -0
  39. package/types/API/brave.com/search.d.ts +156 -0
  40. package/types/API/openai.com/reponses/text.d.ts +225 -0
  41. package/types/API/x.ai/text.d.ts +286 -0
  42. package/types/AgentClient.d.ts +70 -0
  43. package/types/AgentManager.d.ts +112 -0
  44. package/types/AgentServer.d.ts +38 -0
  45. package/types/Cli.d.ts +52 -0
  46. package/types/Prompt.d.ts +298 -0
  47. package/types/Session.d.ts +31 -0
  48. package/types/ToolSet.d.ts +95 -0
  49. package/types/fafs.d.ts +47 -0
  50. package/types/genericToolset.d.ts +3 -0
  51. package/types/index.d.ts +23 -0
  52. package/types/promptHelpers.d.ts +1 -0
  53. package/types/testToolset.d.ts +3 -0
@@ -0,0 +1,132 @@
1
+ // Helper utilities for Prompt: pruning resolved tool IO and truncation
2
+ // ESM module
3
+
4
+ const MESSAGE_TYPES = {
5
+ TEXT: 'text',
6
+ IMAGE_URL: 'image_url',
7
+ AUDIO_URL: 'audio_url',
8
+ FUNCTION_REQUEST: 'function_request',
9
+ FUNCTION_RESPONSE: 'function_response'
10
+ };
11
+
12
+ function lastAssistantTextIndex(messages) {
13
+ for (let i = messages.length - 1; i >= 0; i--) {
14
+ const m = messages[i];
15
+ if (m.sticky) continue;
16
+ if (m.role === 'assistant' && Array.isArray(m.content) && m.content.some(c => c.type === MESSAGE_TYPES.TEXT)) {
17
+ return i;
18
+ }
19
+ }
20
+ return -1;
21
+ }
22
+
23
+ function lastUserIndexBefore(messages, cutoff) {
24
+ for (let i = cutoff - 1; i >= 0; i--) {
25
+ const m = messages[i];
26
+ if (m.sticky) continue;
27
+ if (m.role === 'user') return i;
28
+ }
29
+ return -1;
30
+ }
31
+
32
+ function getCallKey(obj) {
33
+ if (!obj) return undefined;
34
+ const cid = obj.call_id || obj.id;
35
+ if (typeof cid === 'string' && cid.trim()) return cid;
36
+ return undefined;
37
+ }
38
+
39
+ export function pruneResolvedToolIOByCallIdExceptLast(messages, keepMode = 'lastCall') {
40
+ if (!Array.isArray(messages) || messages.length === 0) return false;
41
+
42
+ // Gather requests/responses by call id
43
+ const requests = new Map(); // id -> [{msgIndex, contentIndex}]
44
+ const responses = new Map();
45
+
46
+ for (let i = 0; i < messages.length; i++) {
47
+ const m = messages[i];
48
+ if (!Array.isArray(m.content)) continue;
49
+ for (let j = 0; j < m.content.length; j++) {
50
+ const c = m.content[j];
51
+ if (c && c.type === MESSAGE_TYPES.FUNCTION_REQUEST) {
52
+ const key = getCallKey(c.function_request);
53
+ if (key) {
54
+ if (!requests.has(key)) requests.set(key, []);
55
+ requests.get(key).push({ msgIndex: i, contentIndex: j });
56
+ }
57
+ } else if (c && c.type === MESSAGE_TYPES.FUNCTION_RESPONSE) {
58
+ const key = getCallKey(c.function_response);
59
+ if (key) {
60
+ if (!responses.has(key)) responses.set(key, []);
61
+ responses.get(key).push({ msgIndex: i, contentIndex: j });
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+ // Determine resolved calls (have both request and response)
68
+ const resolved = [];
69
+ for (const [key, resArr] of responses.entries()) {
70
+ if (requests.has(key)) {
71
+ // use last response index to order recency
72
+ const lastResp = resArr[resArr.length - 1];
73
+ resolved.push({ key, lastRespIndex: lastResp.msgIndex });
74
+ }
75
+ }
76
+ if (resolved.length <= 1) return false; // nothing or only one to keep
77
+
78
+ // Cutoff = last assistant text; if none, use end
79
+ const cutoff = (() => {
80
+ const idx = lastAssistantTextIndex(messages);
81
+ return idx === -1 ? messages.length : idx;
82
+ })();
83
+
84
+ // Only consider resolved whose last response is before cutoff
85
+ const eligible = resolved.filter(r => r.lastRespIndex < cutoff);
86
+ if (eligible.length <= 1) return false;
87
+
88
+ let keepKeys = new Set();
89
+ if (keepMode === 'lastTurn') {
90
+ const userIdx = lastUserIndexBefore(messages, cutoff);
91
+ for (const r of eligible) {
92
+ if (r.lastRespIndex > userIdx) keepKeys.add(r.key);
93
+ }
94
+ } else {
95
+ // keep only most recent response (highest index before cutoff)
96
+ let latest = eligible[0];
97
+ for (const r of eligible) {
98
+ if (r.lastRespIndex > latest.lastRespIndex) latest = r;
99
+ }
100
+ keepKeys.add(latest.key);
101
+ }
102
+
103
+ const pruneKeys = new Set(eligible.map(e => e.key).filter(k => !keepKeys.has(k)));
104
+ if (pruneKeys.size === 0) return false;
105
+
106
+ // Remove matching content items; delete empty messages
107
+ let changed = false;
108
+ for (let i = messages.length - 1; i >= 0; i--) {
109
+ const m = messages[i];
110
+ if (!Array.isArray(m.content) || m.content.length === 0) continue;
111
+ const newContent = [];
112
+ for (let j = 0; j < m.content.length; j++) {
113
+ const c = m.content[j];
114
+ if (c && c.type === MESSAGE_TYPES.FUNCTION_REQUEST) {
115
+ const key = getCallKey(c.function_request);
116
+ if (key && pruneKeys.has(key)) { changed = true; continue; }
117
+ } else if (c && c.type === MESSAGE_TYPES.FUNCTION_RESPONSE) {
118
+ const key = getCallKey(c.function_response);
119
+ if (key && pruneKeys.has(key)) { changed = true; continue; }
120
+ }
121
+ newContent.push(c);
122
+ }
123
+ if (newContent.length !== m.content.length) {
124
+ m.content = newContent;
125
+ }
126
+ if (m.content.length === 0) {
127
+ messages.splice(i, 1);
128
+ }
129
+ }
130
+ return changed;
131
+ }
132
+
@@ -0,0 +1,42 @@
1
+ import ToolSet from '../lib/ToolSet.js'
2
+ // Generic TEST toolset
3
+ const tools = new ToolSet('auto');
4
+ tools.add(
5
+ 'get_current_weather', // name
6
+ 'Get the current weather in a given location', // desciption
7
+ {
8
+ type: 'object',
9
+ properties: {
10
+ location: {
11
+ type: 'string',
12
+ description: 'The city and country'
13
+ }
14
+ },
15
+ required: ["location"]
16
+ },
17
+ async (params) => {
18
+ if (params.location.trim() === '') {
19
+ throw new Error('Missing location.');
20
+ // return { records, response };
21
+ }
22
+ const response = {current_weather:'24 C, Cloudy'};
23
+ return response ;
24
+ }
25
+ );
26
+ tools.add(
27
+ 'get_date_time', // name
28
+ 'Get the current date and time', // desciption
29
+ {
30
+ type: 'object',
31
+ properties: {
32
+ }
33
+ },
34
+ async (_params) => {
35
+ const response = {
36
+ date_time: new Date().toISOString(),
37
+ }
38
+ return response ;
39
+ }
40
+ );
41
+
42
+ export default tools;
package/module.md ADDED
@@ -0,0 +1,189 @@
1
+ # @j-o-r/hello-dave Module Documentation
2
+
3
+ ## Overview
4
+ **Name:** @j-o-r/hello-dave
5
+ **Version:** 0.0.0
6
+ **Description:** API to various endpoints mainly focused on AI
7
+
8
+ This is a small, ESM-only Node.js toolkit for building AI "agents" with:
9
+ - One unified Prompt abstraction across multiple LLM providers (x.ai Grok, OpenAI, Anthropic)
10
+ - First-class function calling via a simple ToolSet
11
+ - A tiny AgentManager that wires everything together (CLI, direct calls, WS server/client)
12
+ - Optional persisted sessions and records on disk
13
+
14
+ Key features include:
15
+ - Support for multiple AI providers: x.ai (Grok), OpenAI, Anthropic
16
+ - ToolSet for function calling with JSON schema
17
+ - AgentManager for easy integration
18
+ - CLI tools for interactive use
19
+ - WebSocket-based agent servers and clients for distributed setups
20
+ - Session persistence under ./.cache/hello-dave/<agent-name>/
21
+ - Built-in tools like JavaScript interpreter and bash execution
22
+
23
+ Note: This is a personal project, created for convenience and exclusively used and tested on Debian/Ubuntu. It can be used to create, use and combine Agents. It has great potential and is very powerful; e.g., `hdCode` has full access to the user environment and is able to execute any command or code. Prompt injection is a risk so use with care.
24
+
25
+ ## Installation Notes
26
+ The module is already installed in the current working directory. For manual installation in your project:
27
+ ```bash
28
+ npm install @j-o-r/hello-dave
29
+ ```
30
+
31
+ Requirements:
32
+ - Node.js >= 20 (ESM only)
33
+ - API keys via environment variables (set only what you use):
34
+ - XAIKEY for x.ai (Grok)
35
+ - OPENAIKEY for OpenAI
36
+ - ANTHKEY for Anthropic
37
+ - BRAVESEARCHKEY for Brave Search tool (optional)
38
+
39
+ After installation, use either the programmatic API (AgentManager) or the provided CLIs.
40
+
41
+ For development from repo:
42
+ - npm install
43
+ - export keys
44
+ - node examples/grok.js # or add ./bin to PATH
45
+
46
+ ## API Usage Examples
47
+
48
+ ### Minimal Direct Call
49
+ ```js
50
+ import AgentManager from '@j-o-r/hello-dave';
51
+
52
+ const agent = new AgentManager({ name: 'grok' });
53
+ agent.setup({
54
+ prompt: 'Be precise and concise.',
55
+ api: 'grok',
56
+ options: {
57
+ model: 'grok-4',
58
+ search_parameters: { mode: 'auto' }
59
+ },
60
+ toolsetMode: 'auto',
61
+ contextWindow: 250_000
62
+ });
63
+
64
+ const answer = await agent.directCall('Two bullet points on tail recursion.');
65
+ console.log(answer);
66
+ ```
67
+
68
+ ### Adding Custom Tools
69
+ ```js
70
+ const toolset = agent.getToolset();
71
+ if (toolset) {
72
+ toolset.add(
73
+ 'say_hello',
74
+ 'Return a friendly greeting',
75
+ {
76
+ type: 'object',
77
+ properties: { name: { type: 'string', description: 'Who to greet' } },
78
+ required: ['name']
79
+ },
80
+ async ({ name }) => `Hello, ${name}!`
81
+ );
82
+ }
83
+ ```
84
+
85
+ ### Running as Tool Server
86
+ ```js
87
+ agent.enableServer('search', 'General-purpose search interface', 8000);
88
+ // WS on ws://127.0.0.1:8000/ws; connected clients become callable tools.
89
+ ```
90
+
91
+ ### Attaching as WS Client
92
+ ```js
93
+ agent.attach(
94
+ 'code',
95
+ 'Run JavaScript snippets safely and return output',
96
+ 'ws://127.0.0.1:8000/ws'
97
+ );
98
+ ```
99
+
100
+ ### CLI Example (from examples/grok.js)
101
+ - Interactive: node examples/grok.js
102
+ - One-shot: echo "question" | node examples/grok.js
103
+ - With tools: node examples/grok.js --tools javascript,bash
104
+ - Server: node examples/grok.js --serve 8000 --tools javascript,bash
105
+ - Client: node examples/grok.js --connect ws://127.0.0.1:8000/ws
106
+
107
+ ### Utils
108
+ ```bash
109
+ npx hdClear # Clear sessions and logs
110
+ npx hdInspect [file.ndjson] # Read ndjson files
111
+ npx hdPrompt # Design prompts (needs x.ai key)
112
+ npx hdAsk # Ask generic question to GPT (needs OpenAI key)
113
+ npx hdConnect [ws://url] # Connect to WS agent server
114
+ ```
115
+
116
+ ## Full API Reference
117
+
118
+ ### AgentManager (main entry point)
119
+ From types/AgentManager.d.ts
120
+
121
+ **Constructor:**
122
+ - `new AgentManager(options: Options)`: Create agent with name and optional cachePath.
123
+
124
+ **Methods:**
125
+ - `setup(setup: Setup): this`: Configure prompt, api, options, etc.
126
+ - `startCli(description: string): void`: Start CLI for local usage.
127
+ - `attach(name: string, description: string, url?: string): AgentClient`: Attach to WS server as client.
128
+ - `enableServer(name: string, description?: string, port?: number): void`: Start WS server on localhost.
129
+ - `directCall(input: string): Promise<string>`: Direct call to the prompt.
130
+ - `getPrompt(): Prompt`: Get the Prompt instance.
131
+ - `getToolset(): ToolSet | void`: Get the ToolSet if enabled.
132
+ - `environment(): Promise<EnvironmentInfo>`: Get environment info.
133
+ - `addGenericToolcall(name: string): void`: Add a generic tool call.
134
+
135
+ **Types:**
136
+ - `Options`: { name: string, cachePath?: string }
137
+ - `Setup`: { prompt: string, options: OAOptions | XOptions | ANTHOptions, api: 'gpt' | 'grok' | 'claude', contextWindow?: number, toolsetMode?: 'auto' | 'required' | void, debug?: boolean }
138
+
139
+ ### ToolSet
140
+ From types/ToolSet.d.ts
141
+
142
+ **Constructor:**
143
+ - `new ToolSet(choice?: string)`: 'auto' | 'none' | 'required'
144
+
145
+ **Properties:**
146
+ - `length: number`: Number of registered functions.
147
+ - `toolChoice: string`
148
+
149
+ **Methods:**
150
+ - `add(name: string, description: string, parameters: TSSchema, method: (arg0: object) => Promise<any>): void`: Register a tool.
151
+ - `get(name: string): TSTool`: Get a tool.
152
+ - `delete(name: string): void`: Remove a tool.
153
+ - `has(name: string): boolean`: Check if tool exists.
154
+ - `list(): TSToolListItem[]`: List all tools.
155
+ - `call(name: string, params: object): Promise<any>`: Execute a tool.
156
+ - `execute(prompt: Prompt): Promise<void>`: Execute tool calls from prompt.
157
+
158
+ **Types:**
159
+ - `TSSchema`: { type: string, properties: object, required?: string[] }
160
+ - `TSTool`: { description: string, parameters: TSSchema, method: (arg0: object) => Promise<any> }
161
+ - `TSToolListItem`: { name: string, description: string, parameters: TSSchema }
162
+
163
+ ### Prompt
164
+ From types/Prompt.d.ts (partial, large file)
165
+
166
+ Handles uniform message format, function-call plumbing, truncation, provider-neutral calls.
167
+
168
+ ### Other Classes
169
+ - `AgentClient`: WS client for processing requests.
170
+ - `AgentServer`: WS server that turns clients into ToolSet functions.
171
+ - `Cli`: TUI with history, shortcuts (uses @j-o-r/cli internally).
172
+ - `Session`: On-disk persistence for sessions, logs, records.
173
+
174
+ ### API Adaptors
175
+ - API/x.ai: For Grok
176
+ - API/openai.com: For GPT
177
+ - API/anthropic.com: For Claude
178
+ - API/brave.com: For search tool
179
+
180
+ ## Dependencies
181
+ - **@j-o-r/apiserver**: ^2.1.5 - For HTTP/WS server functionality (see its module.md for details).
182
+ - **@j-o-r/cli**: * - For CLI interface (interactive TUI with modes, questions, shortcuts).
183
+ - **gpt-3-encoder**: * - For token encoding.
184
+
185
+ Relevant dependency info:
186
+ - @j-o-r/cli: Interactive CLI framework with mode-based output, command parsing, key mappings, spinners. Used for the built-in CLI tools.
187
+ - @j-o-r/apiserver: Lightweight HTTP/WS server for API controllers, streaming, file serving. Used for WS agent servers.
188
+
189
+ All dependencies are scoped under @j-o-r, personal modules.
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@j-o-r/hello-dave",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "ESM toolkit for building AI agents with unified access to Grok, OpenAI, and Anthropic endpoints",
6
+ "main": "lib/AgentManager.js",
7
+ "types": "types/AgentManager.d.ts",
8
+ "bin": {
9
+ "hdPrompt": "bin/hdPrompt.js",
10
+ "hdNpm": "bin/hdNpm.js",
11
+ "hdAsk": "bin/hdAsk.js",
12
+ "hdCode": "bin/hdCode.js",
13
+ "hdConnect": "bin/hdConnect.js",
14
+ "hdInspect": "bin/hdInspect.js",
15
+ "hdClear": "bin/hdClear.js"
16
+ },
17
+ "scripts": {
18
+ "hdPrompt": "bin/hdPrompt.js",
19
+ "hdAsk": "bin/hdAsk.js",
20
+ "hdCode": "bin/hdCode.js",
21
+ "hdNpm": "bin/hdNpm.js",
22
+ "hdConnect": "bin/hdConnect.js",
23
+ "hdInspect": "bin/hdInspect.js",
24
+ "hdClear": "bin/hdClear.js",
25
+ "test": "scenarios/grok.js",
26
+ "release": "npm run types && npm pack --pack-destination=release",
27
+ "types": "rm -fr types/* && tsc -p tsc.json",
28
+ "publish": "npm run release && npm publish --access public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://codeberg.org/duin/hello-dave"
33
+ },
34
+ "dependencies": {
35
+ "@j-o-r/apiserver": "^2.1.5",
36
+ "@j-o-r/cli": "*",
37
+ "gpt-3-encoder": "*"
38
+ },
39
+ "author": "Jorrit Duin <j-o-r@duin.work>",
40
+ "bugs": {
41
+ "url": "https://codeberg.org/duin/hello-dave/issues"
42
+ },
43
+ "license": "Apache-2.0",
44
+ "keywords": [],
45
+ "homepage": "https://codeberg.org/duin",
46
+ "engines": {
47
+ "node": ">=20"
48
+ }
49
+ }
@@ -0,0 +1,207 @@
1
+ export type Prompt = import("../../Prompt.js").default;
2
+ export type ToolSet = import("../../ToolSet.js").default;
3
+ /**
4
+ * Search-tool configuration options.
5
+ */
6
+ export type SearchOptions = {
7
+ /**
8
+ * Engine identifier (constant).
9
+ */
10
+ type: "web_search_20250305";
11
+ /**
12
+ * Human-readable tool name.
13
+ */
14
+ name: "web_search";
15
+ /**
16
+ * Maximum searches the caller may perform in a single request.
17
+ */
18
+ max_uses?: number | undefined;
19
+ /**
20
+ * Domains that are explicitly allowed in the results.
21
+ */
22
+ allowed_domains?: string[] | undefined;
23
+ /**
24
+ * Domains that must never appear in the results.
25
+ */
26
+ blocked_domains?: string[] | undefined;
27
+ /**
28
+ * Hints for localizing search results.
29
+ */
30
+ user_location?: UserLocation | undefined;
31
+ };
32
+ /**
33
+ * Geographic context supplied to the search tool.
34
+ */
35
+ export type UserLocation = {
36
+ /**
37
+ * How exact the location is.
38
+ */
39
+ type: "approximate" | "precise";
40
+ /**
41
+ * City name (e.g., "San Francisco").
42
+ */
43
+ city: string;
44
+ /**
45
+ * First-level region or state (e.g., "California").
46
+ */
47
+ region: string;
48
+ /**
49
+ * ISO-3166-1 alpha-2 country code (e.g., "US").
50
+ */
51
+ country: string;
52
+ /**
53
+ * IANA time-zone identifier (e.g., "America/Los_Angeles").
54
+ */
55
+ timezone: string;
56
+ };
57
+ export type ANTHContent = {
58
+ /**
59
+ * - The type of content.
60
+ */
61
+ type: string;
62
+ /**
63
+ * - The text content.
64
+ */
65
+ text: string;
66
+ };
67
+ export type ANTHOptions = {
68
+ /**
69
+ * - What model to use
70
+ */
71
+ model?: string | undefined;
72
+ /**
73
+ * - System prompt
74
+ */
75
+ system?: string | undefined;
76
+ /**
77
+ * - Prompt / conversation
78
+ */
79
+ messages?: ANTHContent[] | undefined;
80
+ /**
81
+ * - Prompt / conversation
82
+ */
83
+ tools?: (ANTHTool | SearchOptions)[] | undefined;
84
+ /**
85
+ * - ..
86
+ */
87
+ tool_choice?: ANTHToolChoice | undefined;
88
+ /**
89
+ * - ..
90
+ */
91
+ metadata?: object | undefined;
92
+ /**
93
+ * - What sampling temperature to use, between 0 and 2.
94
+ */
95
+ temperature?: number | undefined;
96
+ /**
97
+ * - The maximum number of tokens allowed for the generated answer.
98
+ */
99
+ max_tokens?: number | undefined;
100
+ /**
101
+ * - Number between > 0 0.1 is NO top_p
102
+ */
103
+ top_p?: number | undefined;
104
+ /**
105
+ * - Number between > 0 < 2048
106
+ */
107
+ top_k?: number | undefined;
108
+ /**
109
+ * - embedded search
110
+ */
111
+ search?: SearchOptions | undefined;
112
+ /**
113
+ * - Chunk/stream request default null
114
+ */
115
+ stream?: boolean | undefined;
116
+ /**
117
+ * - Reasoning
118
+ */
119
+ thinking?: {
120
+ /**
121
+ * -
122
+ */
123
+ type?: "enabled" | undefined;
124
+ /**
125
+ * -
126
+ */
127
+ budget_tokens?: number | undefined;
128
+ } | undefined;
129
+ };
130
+ export type ANTHRequest = {
131
+ body: ANTHOptions;
132
+ headers: Headers;
133
+ /**
134
+ * -
135
+ */
136
+ url: string;
137
+ };
138
+ export type ANTHTool = {
139
+ /**
140
+ * - The name of the tool.
141
+ */
142
+ name: string;
143
+ /**
144
+ * - A brief description of the tool's functionality.
145
+ */
146
+ description: string;
147
+ /**
148
+ * - The JSON schema defining the input parameters for the tool.
149
+ */
150
+ input_schema: Object;
151
+ };
152
+ /**
153
+ * Represents a tool usage event.
154
+ */
155
+ export type ANTHToolUse = {
156
+ /**
157
+ * - The type of the tool usage event, in this case "tool_use".
158
+ */
159
+ type: string;
160
+ /**
161
+ * - The unique identifier for the tool usage event.
162
+ */
163
+ id: string;
164
+ /**
165
+ * - The name of the tool used.
166
+ */
167
+ name: string;
168
+ /**
169
+ * - The input data for the tool usage.
170
+ */
171
+ input: Object;
172
+ };
173
+ export type ANTHToolChoice = {
174
+ /**
175
+ * -
176
+ */
177
+ type: string;
178
+ };
179
+ /**
180
+ * Create an anthropic request
181
+ * @param {Prompt} prompt
182
+ * @param {ToolSet} [tools]
183
+ * @param {ANTHOptions} [opts] overwrite default request settings
184
+ * @param {Headers|object} [hdrs] - optional headers to pass
185
+ * @returns {ANTHRequest}
186
+ * @throws {Error}
187
+ */
188
+ export function generateRequest(prompt: Prompt, tools?: ToolSet, opts?: ANTHOptions, hdrs?: Headers | object): ANTHRequest;
189
+ /**
190
+ * Process an openai response
191
+ * @param {number} duration - the time is MS before and after the request
192
+ * @param {import('lib/request.js').FetchResponse} res
193
+ * @param {Prompt} prompt
194
+ * @param {ToolSet} [toolset]
195
+ * @returns {Promise<void>}
196
+ * @throws {Error}
197
+ */
198
+ export function parseResponse(duration: number, prompt: Prompt, res: any, toolset?: ToolSet): Promise<void>;
199
+ /**
200
+ * Do a request
201
+ * @param {Prompt} prompt
202
+ * @param {ToolSet|null} toolset
203
+ * @param {ANTHOptions} [options]:
204
+ * @param {number} [counter] - leave empty this counts the number of requests when doing recursive request calls
205
+ * @return {Promise<import('../../Session.js').Message>}
206
+ */
207
+ export function request(prompt: Prompt, toolset?: ToolSet | null, options?: ANTHOptions, counter?: number): Promise<import("../../Session.js").Message>;