@push.rocks/smartagent 1.8.0 → 3.0.1

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 (87) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/index.d.ts +8 -14
  3. package/dist_ts/index.js +8 -24
  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 +7 -70
  9. package/dist_ts/smartagent.classes.toolregistry.js +11 -155
  10. package/dist_ts/smartagent.interfaces.d.ts +47 -283
  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 +38 -84
  35. package/readme.md +254 -682
  36. package/ts/00_commitinfo_data.ts +2 -2
  37. package/ts/index.ts +10 -37
  38. package/ts/plugins.ts +22 -21
  39. package/ts/smartagent.classes.agent.ts +198 -0
  40. package/ts/smartagent.classes.toolregistry.ts +11 -179
  41. package/ts/smartagent.interfaces.ts +51 -363
  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 -93
  55. package/dist_ts/smartagent.classes.dualagent.js +0 -614
  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.expert.d.ts +0 -27
  65. package/dist_ts/smartagent.tools.expert.js +0 -126
  66. package/dist_ts/smartagent.tools.filesystem.d.ts +0 -40
  67. package/dist_ts/smartagent.tools.filesystem.js +0 -801
  68. package/dist_ts/smartagent.tools.http.d.ts +0 -16
  69. package/dist_ts/smartagent.tools.http.js +0 -264
  70. package/dist_ts/smartagent.tools.json.d.ts +0 -24
  71. package/dist_ts/smartagent.tools.json.js +0 -202
  72. package/dist_ts/smartagent.tools.search.d.ts +0 -29
  73. package/dist_ts/smartagent.tools.search.js +0 -215
  74. package/dist_ts/smartagent.tools.shell.d.ts +0 -17
  75. package/dist_ts/smartagent.tools.shell.js +0 -202
  76. package/ts/smartagent.classes.driveragent.ts +0 -775
  77. package/ts/smartagent.classes.dualagent.ts +0 -692
  78. package/ts/smartagent.classes.guardianagent.ts +0 -241
  79. package/ts/smartagent.tools.base.ts +0 -83
  80. package/ts/smartagent.tools.browser.ts +0 -253
  81. package/ts/smartagent.tools.deno.ts +0 -230
  82. package/ts/smartagent.tools.expert.ts +0 -144
  83. package/ts/smartagent.tools.filesystem.ts +0 -885
  84. package/ts/smartagent.tools.http.ts +0 -283
  85. package/ts/smartagent.tools.json.ts +0 -224
  86. package/ts/smartagent.tools.search.ts +0 -237
  87. package/ts/smartagent.tools.shell.ts +0 -230
@@ -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
- }