@push.rocks/smartagent 1.7.0 → 3.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 (81) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/index.d.ts +9 -12
  3. package/dist_ts/index.js +9 -20
  4. package/dist_ts/plugins.d.ts +8 -9
  5. package/dist_ts/plugins.js +10 -12
  6. package/dist_ts/smartagent.classes.agent.d.ts +2 -0
  7. package/dist_ts/smartagent.classes.agent.js +173 -0
  8. package/dist_ts/smartagent.classes.toolregistry.d.ts +12 -0
  9. package/dist_ts/smartagent.classes.toolregistry.js +17 -0
  10. package/dist_ts/smartagent.interfaces.d.ts +47 -231
  11. package/dist_ts/smartagent.interfaces.js +6 -7
  12. package/dist_ts/smartagent.utils.truncation.d.ts +10 -0
  13. package/dist_ts/smartagent.utils.truncation.js +26 -0
  14. package/dist_ts_compaction/index.d.ts +1 -0
  15. package/dist_ts_compaction/index.js +2 -0
  16. package/dist_ts_compaction/plugins.d.ts +4 -0
  17. package/dist_ts_compaction/plugins.js +3 -0
  18. package/dist_ts_compaction/smartagent.compaction.d.ts +10 -0
  19. package/dist_ts_compaction/smartagent.compaction.js +46 -0
  20. package/dist_ts_tools/index.d.ts +8 -0
  21. package/dist_ts_tools/index.js +6 -0
  22. package/dist_ts_tools/plugins.d.ts +15 -0
  23. package/dist_ts_tools/plugins.js +19 -0
  24. package/dist_ts_tools/tool.filesystem.d.ts +6 -0
  25. package/dist_ts_tools/tool.filesystem.js +102 -0
  26. package/dist_ts_tools/tool.http.d.ts +2 -0
  27. package/dist_ts_tools/tool.http.js +65 -0
  28. package/dist_ts_tools/tool.json.d.ts +2 -0
  29. package/dist_ts_tools/tool.json.js +47 -0
  30. package/dist_ts_tools/tool.shell.d.ts +8 -0
  31. package/dist_ts_tools/tool.shell.js +40 -0
  32. package/npmextra.json +1 -1
  33. package/package.json +30 -18
  34. package/readme.hints.md +43 -42
  35. package/readme.md +257 -526
  36. package/ts/00_commitinfo_data.ts +2 -2
  37. package/ts/index.ts +11 -31
  38. package/ts/plugins.ts +22 -21
  39. package/ts/smartagent.classes.agent.ts +198 -0
  40. package/ts/smartagent.classes.toolregistry.ts +20 -0
  41. package/ts/smartagent.interfaces.ts +51 -303
  42. package/ts/smartagent.utils.truncation.ts +39 -0
  43. package/ts_compaction/index.ts +1 -0
  44. package/ts_compaction/plugins.ts +6 -0
  45. package/ts_compaction/smartagent.compaction.ts +51 -0
  46. package/ts_tools/index.ts +8 -0
  47. package/ts_tools/plugins.ts +30 -0
  48. package/ts_tools/tool.filesystem.ts +131 -0
  49. package/ts_tools/tool.http.ts +78 -0
  50. package/ts_tools/tool.json.ts +53 -0
  51. package/ts_tools/tool.shell.ts +62 -0
  52. package/dist_ts/smartagent.classes.driveragent.d.ts +0 -134
  53. package/dist_ts/smartagent.classes.driveragent.js +0 -671
  54. package/dist_ts/smartagent.classes.dualagent.d.ts +0 -79
  55. package/dist_ts/smartagent.classes.dualagent.js +0 -583
  56. package/dist_ts/smartagent.classes.guardianagent.d.ts +0 -46
  57. package/dist_ts/smartagent.classes.guardianagent.js +0 -201
  58. package/dist_ts/smartagent.tools.base.d.ts +0 -52
  59. package/dist_ts/smartagent.tools.base.js +0 -42
  60. package/dist_ts/smartagent.tools.browser.d.ts +0 -17
  61. package/dist_ts/smartagent.tools.browser.js +0 -229
  62. package/dist_ts/smartagent.tools.deno.d.ts +0 -21
  63. package/dist_ts/smartagent.tools.deno.js +0 -191
  64. package/dist_ts/smartagent.tools.filesystem.d.ts +0 -40
  65. package/dist_ts/smartagent.tools.filesystem.js +0 -801
  66. package/dist_ts/smartagent.tools.http.d.ts +0 -16
  67. package/dist_ts/smartagent.tools.http.js +0 -264
  68. package/dist_ts/smartagent.tools.json.d.ts +0 -24
  69. package/dist_ts/smartagent.tools.json.js +0 -202
  70. package/dist_ts/smartagent.tools.shell.d.ts +0 -17
  71. package/dist_ts/smartagent.tools.shell.js +0 -202
  72. package/ts/smartagent.classes.driveragent.ts +0 -775
  73. package/ts/smartagent.classes.dualagent.ts +0 -657
  74. package/ts/smartagent.classes.guardianagent.ts +0 -241
  75. package/ts/smartagent.tools.base.ts +0 -83
  76. package/ts/smartagent.tools.browser.ts +0 -253
  77. package/ts/smartagent.tools.deno.ts +0 -230
  78. package/ts/smartagent.tools.filesystem.ts +0 -885
  79. package/ts/smartagent.tools.http.ts +0 -283
  80. package/ts/smartagent.tools.json.ts +0 -224
  81. package/ts/smartagent.tools.shell.ts +0 -230
@@ -0,0 +1,39 @@
1
+ // Truncation logic derived from opencode (MIT) — https://github.com/sst/opencode
2
+
3
+ const MAX_LINES = 2000;
4
+ const MAX_BYTES = 50 * 1024; // 50 KB
5
+
6
+ export interface ITruncateResult {
7
+ content: string;
8
+ truncated: boolean;
9
+ /** Set when truncated: describes what was dropped */
10
+ notice?: string;
11
+ }
12
+
13
+ export function truncateOutput(
14
+ text: string,
15
+ options?: { maxLines?: number; maxBytes?: number },
16
+ ): ITruncateResult {
17
+ const maxLines = options?.maxLines ?? MAX_LINES;
18
+ const maxBytes = options?.maxBytes ?? MAX_BYTES;
19
+ const lines = text.split('\n');
20
+ const totalBytes = Buffer.byteLength(text, 'utf-8');
21
+
22
+ if (lines.length <= maxLines && totalBytes <= maxBytes) {
23
+ return { content: text, truncated: false };
24
+ }
25
+
26
+ const out: string[] = [];
27
+ let bytes = 0;
28
+ for (let i = 0; i < lines.length && i < maxLines; i++) {
29
+ const size = Buffer.byteLength(lines[i], 'utf-8') + (i > 0 ? 1 : 0);
30
+ if (bytes + size > maxBytes) break;
31
+ out.push(lines[i]);
32
+ bytes += size;
33
+ }
34
+
35
+ const kept = out.length;
36
+ const dropped = lines.length - kept;
37
+ const notice = `\n[Output truncated: showing ${kept}/${lines.length} lines. ${dropped} lines omitted.]`;
38
+ return { content: out.join('\n') + notice, truncated: true, notice };
39
+ }
@@ -0,0 +1 @@
1
+ export { compactMessages } from './smartagent.compaction.js';
@@ -0,0 +1,6 @@
1
+ import { generateText } from 'ai';
2
+
3
+ export { generateText };
4
+
5
+ export type { ModelMessage } from 'ai';
6
+ export type { LanguageModelV3 } from '@push.rocks/smartai';
@@ -0,0 +1,51 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ const COMPACTION_PROMPT = `Provide a detailed prompt for continuing our conversation above.
4
+ Focus on information that would be helpful for continuing the conversation, including what we did, what we're doing, which files we're working on, and what we're going to do next.
5
+ The summary that you construct will be used so that another agent can read it and continue the work.
6
+
7
+ When constructing the summary, try to stick to this template:
8
+ ---
9
+ ## Goal
10
+ [What goal(s) is the user trying to accomplish?]
11
+
12
+ ## Instructions
13
+ - [What important instructions did the user give you that are relevant]
14
+
15
+ ## Discoveries
16
+ [What notable things were learned during this conversation that would be useful for the next agent to know]
17
+
18
+ ## Accomplished
19
+ [What work has been completed, what work is still in progress, and what work is left?]
20
+
21
+ ## Relevant files / directories
22
+ [A structured list of relevant files that have been read, edited, or created]
23
+ ---`;
24
+
25
+ /**
26
+ * Compacts a message history into a summary.
27
+ * Pass this as the onContextOverflow handler in IAgentRunOptions.
28
+ *
29
+ * @param model The same model used by runAgent, or a cheaper small model
30
+ * @param messages The full message history that overflowed
31
+ * @returns A minimal ModelMessage[] containing the summary as context
32
+ */
33
+ export async function compactMessages(
34
+ model: plugins.LanguageModelV3,
35
+ messages: plugins.ModelMessage[],
36
+ ): Promise<plugins.ModelMessage[]> {
37
+ const result = await plugins.generateText({
38
+ model,
39
+ messages: [
40
+ ...messages,
41
+ { role: 'user', content: COMPACTION_PROMPT },
42
+ ],
43
+ });
44
+
45
+ return [
46
+ {
47
+ role: 'user',
48
+ content: `[Previous conversation summary]\n\n${result.text}\n\n[End of summary. Continue from here.]`,
49
+ },
50
+ ];
51
+ }
@@ -0,0 +1,8 @@
1
+ export { filesystemTool } from './tool.filesystem.js';
2
+ export type { IFilesystemToolOptions } from './tool.filesystem.js';
3
+ export { shellTool } from './tool.shell.js';
4
+ export type { IShellToolOptions } from './tool.shell.js';
5
+ export { httpTool } from './tool.http.js';
6
+ export { jsonTool } from './tool.json.js';
7
+ export { truncateOutput } from './plugins.js';
8
+ export type { ITruncateResult } from './plugins.js';
@@ -0,0 +1,30 @@
1
+ // node native
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+
5
+ export { path, fs };
6
+
7
+ // zod
8
+ import { z } from 'zod';
9
+
10
+ export { z };
11
+
12
+ // ai-sdk
13
+ import { tool } from '@push.rocks/smartai';
14
+
15
+ export { tool };
16
+
17
+ export type { ToolSet } from 'ai';
18
+
19
+ // @push.rocks scope
20
+ import * as smartfs from '@push.rocks/smartfs';
21
+ import * as smartshell from '@push.rocks/smartshell';
22
+ import * as smartrequest from '@push.rocks/smartrequest';
23
+
24
+ export { smartfs, smartshell, smartrequest };
25
+
26
+ // cross-folder import
27
+ import { truncateOutput } from '../ts/smartagent.utils.truncation.js';
28
+
29
+ export { truncateOutput };
30
+ export type { ITruncateResult } from '../ts/smartagent.utils.truncation.js';
@@ -0,0 +1,131 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ export interface IFilesystemToolOptions {
4
+ /** Restrict file access to this directory. Default: process.cwd() */
5
+ rootDir?: string;
6
+ }
7
+
8
+ function validatePath(filePath: string, rootDir?: string): string {
9
+ const resolved = plugins.path.resolve(filePath);
10
+ if (rootDir) {
11
+ const resolvedRoot = plugins.path.resolve(rootDir);
12
+ if (!resolved.startsWith(resolvedRoot + plugins.path.sep) && resolved !== resolvedRoot) {
13
+ throw new Error(`Access denied: "${filePath}" is outside allowed root "${rootDir}"`);
14
+ }
15
+ }
16
+ return resolved;
17
+ }
18
+
19
+ export function filesystemTool(options?: IFilesystemToolOptions): plugins.ToolSet {
20
+ const rootDir = options?.rootDir;
21
+
22
+ return {
23
+ read_file: plugins.tool({
24
+ description:
25
+ 'Read file contents. Returns the full text or a specified line range.',
26
+ inputSchema: plugins.z.object({
27
+ path: plugins.z.string().describe('Absolute path to the file'),
28
+ startLine: plugins.z
29
+ .number()
30
+ .optional()
31
+ .describe('First line (1-indexed, inclusive)'),
32
+ endLine: plugins.z
33
+ .number()
34
+ .optional()
35
+ .describe('Last line (1-indexed, inclusive)'),
36
+ }),
37
+ execute: async ({
38
+ path: filePath,
39
+ startLine,
40
+ endLine,
41
+ }: {
42
+ path: string;
43
+ startLine?: number;
44
+ endLine?: number;
45
+ }) => {
46
+ const resolved = validatePath(filePath, rootDir);
47
+ const content = plugins.fs.readFileSync(resolved, 'utf-8');
48
+
49
+ if (startLine !== undefined || endLine !== undefined) {
50
+ const lines = content.split('\n');
51
+ const start = (startLine ?? 1) - 1;
52
+ const end = endLine ?? lines.length;
53
+ const sliced = lines.slice(start, end).join('\n');
54
+ return plugins.truncateOutput(sliced).content;
55
+ }
56
+
57
+ return plugins.truncateOutput(content).content;
58
+ },
59
+ }),
60
+
61
+ write_file: plugins.tool({
62
+ description:
63
+ 'Write content to a file (creates parent dirs if needed, overwrites existing).',
64
+ inputSchema: plugins.z.object({
65
+ path: plugins.z.string().describe('Absolute path to the file'),
66
+ content: plugins.z.string().describe('Content to write'),
67
+ }),
68
+ execute: async ({ path: filePath, content }: { path: string; content: string }) => {
69
+ const resolved = validatePath(filePath, rootDir);
70
+ const dir = plugins.path.dirname(resolved);
71
+ plugins.fs.mkdirSync(dir, { recursive: true });
72
+ plugins.fs.writeFileSync(resolved, content, 'utf-8');
73
+ return `Written ${content.length} characters to ${filePath}`;
74
+ },
75
+ }),
76
+
77
+ list_directory: plugins.tool({
78
+ description: 'List files and directories at the given path.',
79
+ inputSchema: plugins.z.object({
80
+ path: plugins.z.string().describe('Directory path to list'),
81
+ recursive: plugins.z
82
+ .boolean()
83
+ .optional()
84
+ .describe('List recursively (default: false)'),
85
+ }),
86
+ execute: async ({
87
+ path: dirPath,
88
+ recursive,
89
+ }: {
90
+ path: string;
91
+ recursive?: boolean;
92
+ }) => {
93
+ const resolved = validatePath(dirPath, rootDir);
94
+
95
+ function listDir(dir: string, prefix: string = ''): string[] {
96
+ const entries = plugins.fs.readdirSync(dir, { withFileTypes: true });
97
+ const result: string[] = [];
98
+ for (const entry of entries) {
99
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
100
+ const indicator = entry.isDirectory() ? '/' : '';
101
+ result.push(`${rel}${indicator}`);
102
+ if (recursive && entry.isDirectory()) {
103
+ result.push(...listDir(plugins.path.join(dir, entry.name), rel));
104
+ }
105
+ }
106
+ return result;
107
+ }
108
+
109
+ const entries = listDir(resolved);
110
+ return plugins.truncateOutput(entries.join('\n')).content;
111
+ },
112
+ }),
113
+
114
+ delete_file: plugins.tool({
115
+ description: 'Delete a file or empty directory.',
116
+ inputSchema: plugins.z.object({
117
+ path: plugins.z.string().describe('Path to delete'),
118
+ }),
119
+ execute: async ({ path: filePath }: { path: string }) => {
120
+ const resolved = validatePath(filePath, rootDir);
121
+ const stat = plugins.fs.statSync(resolved);
122
+ if (stat.isDirectory()) {
123
+ plugins.fs.rmdirSync(resolved);
124
+ } else {
125
+ plugins.fs.unlinkSync(resolved);
126
+ }
127
+ return `Deleted ${filePath}`;
128
+ },
129
+ }),
130
+ };
131
+ }
@@ -0,0 +1,78 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ export function httpTool(): plugins.ToolSet {
4
+ return {
5
+ http_get: plugins.tool({
6
+ description: 'Make an HTTP GET request and return the response.',
7
+ inputSchema: plugins.z.object({
8
+ url: plugins.z.string().describe('URL to request'),
9
+ headers: plugins.z
10
+ .record(plugins.z.string())
11
+ .optional()
12
+ .describe('Request headers'),
13
+ }),
14
+ execute: async ({
15
+ url,
16
+ headers,
17
+ }: {
18
+ url: string;
19
+ headers?: Record<string, string>;
20
+ }) => {
21
+ let req = plugins.smartrequest.default.create().url(url);
22
+ if (headers) {
23
+ req = req.headers(headers);
24
+ }
25
+ const response = await req.get();
26
+ let body: string;
27
+ try {
28
+ const json = await response.json();
29
+ body = JSON.stringify(json, null, 2);
30
+ } catch {
31
+ body = await response.text();
32
+ }
33
+ return plugins.truncateOutput(`HTTP ${response.status}\n${body}`).content;
34
+ },
35
+ }),
36
+
37
+ http_post: plugins.tool({
38
+ description: 'Make an HTTP POST request with a JSON body.',
39
+ inputSchema: plugins.z.object({
40
+ url: plugins.z.string().describe('URL to request'),
41
+ body: plugins.z
42
+ .record(plugins.z.unknown())
43
+ .optional()
44
+ .describe('JSON body to send'),
45
+ headers: plugins.z
46
+ .record(plugins.z.string())
47
+ .optional()
48
+ .describe('Request headers'),
49
+ }),
50
+ execute: async ({
51
+ url,
52
+ body,
53
+ headers,
54
+ }: {
55
+ url: string;
56
+ body?: Record<string, unknown>;
57
+ headers?: Record<string, string>;
58
+ }) => {
59
+ let req = plugins.smartrequest.default.create().url(url);
60
+ if (headers) {
61
+ req = req.headers(headers);
62
+ }
63
+ if (body) {
64
+ req = req.json(body);
65
+ }
66
+ const response = await req.post();
67
+ let responseBody: string;
68
+ try {
69
+ const json = await response.json();
70
+ responseBody = JSON.stringify(json, null, 2);
71
+ } catch {
72
+ responseBody = await response.text();
73
+ }
74
+ return plugins.truncateOutput(`HTTP ${response.status}\n${responseBody}`).content;
75
+ },
76
+ }),
77
+ };
78
+ }
@@ -0,0 +1,53 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ export function jsonTool(): plugins.ToolSet {
4
+ return {
5
+ json_validate: plugins.tool({
6
+ description:
7
+ 'Validate a JSON string and optionally check for required fields.',
8
+ inputSchema: plugins.z.object({
9
+ jsonString: plugins.z.string().describe('JSON string to validate'),
10
+ requiredFields: plugins.z
11
+ .array(plugins.z.string())
12
+ .optional()
13
+ .describe('Fields that must exist at the top level'),
14
+ }),
15
+ execute: async ({
16
+ jsonString,
17
+ requiredFields,
18
+ }: {
19
+ jsonString: string;
20
+ requiredFields?: string[];
21
+ }) => {
22
+ try {
23
+ const parsed = JSON.parse(jsonString);
24
+ if (requiredFields?.length) {
25
+ const missing = requiredFields.filter((f) => !(f in parsed));
26
+ if (missing.length) {
27
+ return `Invalid: missing required fields: ${missing.join(', ')}`;
28
+ }
29
+ }
30
+ const type = Array.isArray(parsed) ? 'array' : typeof parsed;
31
+ return `Valid JSON (${type})`;
32
+ } catch (e) {
33
+ return `Invalid JSON: ${(e as Error).message}`;
34
+ }
35
+ },
36
+ }),
37
+
38
+ json_transform: plugins.tool({
39
+ description: 'Parse a JSON string and return it pretty-printed.',
40
+ inputSchema: plugins.z.object({
41
+ jsonString: plugins.z.string().describe('JSON string to format'),
42
+ }),
43
+ execute: async ({ jsonString }: { jsonString: string }) => {
44
+ try {
45
+ const parsed = JSON.parse(jsonString);
46
+ return JSON.stringify(parsed, null, 2);
47
+ } catch (e) {
48
+ return `Error parsing JSON: ${(e as Error).message}`;
49
+ }
50
+ },
51
+ }),
52
+ };
53
+ }
@@ -0,0 +1,62 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ export interface IShellToolOptions {
4
+ /** Allowed commands whitelist. If empty, all commands are allowed. */
5
+ allowedCommands?: string[];
6
+ /** Working directory for shell execution */
7
+ cwd?: string;
8
+ }
9
+
10
+ export function shellTool(options?: IShellToolOptions): plugins.ToolSet {
11
+ const smartshell = new plugins.smartshell.Smartshell({ executor: 'bash' });
12
+
13
+ return {
14
+ run_command: plugins.tool({
15
+ description:
16
+ 'Execute a shell command. Provide the full command string. stdout and stderr are returned.',
17
+ inputSchema: plugins.z.object({
18
+ command: plugins.z.string().describe('The shell command to execute'),
19
+ cwd: plugins.z
20
+ .string()
21
+ .optional()
22
+ .describe('Working directory for the command'),
23
+ timeout: plugins.z
24
+ .number()
25
+ .optional()
26
+ .describe('Timeout in milliseconds'),
27
+ }),
28
+ execute: async ({
29
+ command,
30
+ cwd,
31
+ timeout,
32
+ }: {
33
+ command: string;
34
+ cwd?: string;
35
+ timeout?: number;
36
+ }) => {
37
+ // Validate against allowed commands whitelist
38
+ if (options?.allowedCommands?.length) {
39
+ const baseCommand = command.split(/\s+/)[0];
40
+ if (!options.allowedCommands.includes(baseCommand)) {
41
+ return `Command "${baseCommand}" is not in the allowed commands list: ${options.allowedCommands.join(', ')}`;
42
+ }
43
+ }
44
+
45
+ // Build full command string with cd prefix if cwd specified
46
+ const effectiveCwd = cwd ?? options?.cwd;
47
+ const fullCommand = effectiveCwd
48
+ ? `cd ${JSON.stringify(effectiveCwd)} && ${command}`
49
+ : command;
50
+
51
+ const execResult = await smartshell.exec(fullCommand);
52
+
53
+ const output =
54
+ execResult.exitCode === 0
55
+ ? execResult.stdout
56
+ : `Exit code: ${execResult.exitCode}\nstdout:\n${execResult.stdout}\nstderr:\n${execResult.stderr ?? ''}`;
57
+
58
+ return plugins.truncateOutput(output).content;
59
+ },
60
+ }),
61
+ };
62
+ }
@@ -1,134 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import * as interfaces from './smartagent.interfaces.js';
3
- import type { BaseToolWrapper } from './smartagent.tools.base.js';
4
- /**
5
- * Options for configuring the DriverAgent
6
- */
7
- export interface IDriverAgentOptions {
8
- /** Custom system message for the driver */
9
- systemMessage?: string;
10
- /** Maximum history messages to pass to API (default: 20). Set to 0 for unlimited. */
11
- maxHistoryMessages?: number;
12
- /** Callback fired for each token during LLM generation */
13
- onToken?: (token: string) => void;
14
- }
15
- /**
16
- * DriverAgent - Executes tasks by reasoning and proposing tool calls
17
- * Works in conjunction with GuardianAgent for approval
18
- */
19
- export declare class DriverAgent {
20
- private provider;
21
- private systemMessage;
22
- private maxHistoryMessages;
23
- private messageHistory;
24
- private tools;
25
- private onToken?;
26
- private isInThinkingMode;
27
- constructor(provider: plugins.smartai.MultiModalModel, options?: IDriverAgentOptions | string);
28
- /**
29
- * Set the token callback for streaming mode
30
- * @param callback Function to call for each generated token
31
- */
32
- setOnToken(callback: (token: string) => void): void;
33
- /**
34
- * Register a tool for use by the driver
35
- */
36
- registerTool(tool: BaseToolWrapper): void;
37
- /**
38
- * Get all registered tools
39
- */
40
- getTools(): Map<string, BaseToolWrapper>;
41
- /**
42
- * Initialize a new conversation for a task
43
- * @param task The task description
44
- * @param images Optional base64-encoded images for vision tasks
45
- */
46
- startTask(task: string, images?: string[]): Promise<interfaces.IAgentMessage>;
47
- /**
48
- * Continue the conversation with feedback or results
49
- */
50
- continueWithMessage(message: string): Promise<interfaces.IAgentMessage>;
51
- /**
52
- * Parse tool call proposals from assistant response
53
- */
54
- parseToolCallProposals(response: string): interfaces.IToolCallProposal[];
55
- /**
56
- * Parse the content inside a tool_call block
57
- */
58
- private parseToolCallContent;
59
- /**
60
- * Extract parameters from XML-like format when JSON parsing fails
61
- */
62
- private extractParamsFromXml;
63
- /**
64
- * Check if the response indicates task completion
65
- */
66
- isTaskComplete(response: string): boolean;
67
- /**
68
- * Check if the response needs clarification or user input
69
- */
70
- needsClarification(response: string): boolean;
71
- /**
72
- * Extract the final result from a completed task
73
- */
74
- extractTaskResult(response: string): string | null;
75
- /**
76
- * Build tool descriptions for the system message
77
- */
78
- private buildToolDescriptions;
79
- /**
80
- * Generate a unique proposal ID
81
- */
82
- private generateProposalId;
83
- /**
84
- * Get the default system message for the driver
85
- */
86
- private getDefaultSystemMessage;
87
- /**
88
- * Get the system message when no tools are available
89
- * Used for direct task completion without tool usage
90
- */
91
- private getNoToolsSystemMessage;
92
- /**
93
- * Reset the conversation state
94
- */
95
- reset(): void;
96
- /**
97
- * Start a task with native tool calling support
98
- * Uses Ollama's native tool calling API instead of XML parsing
99
- * @param task The task description
100
- * @param images Optional base64-encoded images for vision tasks
101
- * @returns Response with content, reasoning, and any tool calls
102
- */
103
- startTaskWithNativeTools(task: string, images?: string[]): Promise<{
104
- message: interfaces.IAgentMessage;
105
- toolCalls?: interfaces.INativeToolCall[];
106
- }>;
107
- /**
108
- * Continue conversation with native tool calling support
109
- * @param message The message to continue with (e.g., tool result)
110
- * @param toolName Optional tool name - when provided, message is added as role: 'tool' instead of 'user'
111
- * @returns Response with content, reasoning, and any tool calls
112
- */
113
- continueWithNativeTools(message: string, toolName?: string): Promise<{
114
- message: interfaces.IAgentMessage;
115
- toolCalls?: interfaces.INativeToolCall[];
116
- }>;
117
- /**
118
- * Get system message for native tool calling mode
119
- * Simplified prompt that lets the model use tools naturally
120
- */
121
- private getNativeToolsSystemMessage;
122
- /**
123
- * Convert registered tools to Ollama JSON Schema format for native tool calling
124
- * Each tool action becomes a separate function with name format: "toolName_actionName"
125
- * @returns Array of IOllamaTool compatible tool definitions
126
- */
127
- getToolsAsJsonSchema(): plugins.smartai.IOllamaTool[];
128
- /**
129
- * Parse native tool calls from provider response into IToolCallProposal format
130
- * @param toolCalls Array of native tool calls from the provider
131
- * @returns Array of IToolCallProposal ready for execution
132
- */
133
- parseNativeToolCalls(toolCalls: interfaces.INativeToolCall[]): interfaces.IToolCallProposal[];
134
- }