erosolar-cli 2.1.231 → 2.1.235
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/agents/erosolar-security.rules.json +84 -0
- package/config/security-deployment.json +10 -9
- package/dist/bin/cliMode.d.ts +12 -0
- package/dist/bin/cliMode.d.ts.map +1 -0
- package/dist/bin/cliMode.js +27 -0
- package/dist/bin/cliMode.js.map +1 -0
- package/dist/bin/erosolar.js +47 -46
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/capabilities/index.d.ts +1 -0
- package/dist/capabilities/index.d.ts.map +1 -1
- package/dist/capabilities/index.js +1 -0
- package/dist/capabilities/index.js.map +1 -1
- package/dist/capabilities/taoCapability.d.ts +13 -0
- package/dist/capabilities/taoCapability.d.ts.map +1 -0
- package/dist/capabilities/taoCapability.js +20 -0
- package/dist/capabilities/taoCapability.js.map +1 -0
- package/dist/contracts/agent-profiles.schema.json +16 -0
- package/dist/contracts/tools.schema.json +12 -0
- package/dist/core/agent.d.ts +6 -0
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +22 -0
- package/dist/core/agent.js.map +1 -1
- package/dist/core/agentOrchestrator.d.ts +9 -13
- package/dist/core/agentOrchestrator.d.ts.map +1 -1
- package/dist/core/agentOrchestrator.js +237 -107
- package/dist/core/agentOrchestrator.js.map +1 -1
- package/dist/core/baseToolFactory.d.ts +187 -0
- package/dist/core/baseToolFactory.d.ts.map +1 -0
- package/dist/core/baseToolFactory.js +352 -0
- package/dist/core/baseToolFactory.js.map +1 -0
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +5 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/errors/index.d.ts +50 -0
- package/dist/core/errors/index.d.ts.map +1 -0
- package/dist/core/errors/index.js +156 -0
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/errors/safetyValidator.d.ts.map +1 -1
- package/dist/core/errors/safetyValidator.js +6 -137
- package/dist/core/errors/safetyValidator.js.map +1 -1
- package/dist/headless/headlessApp.d.ts.map +1 -1
- package/dist/headless/headlessApp.js +2 -15
- package/dist/headless/headlessApp.js.map +1 -1
- package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
- package/dist/plugins/tools/nodeDefaults.js +2 -0
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/plugins/tools/tao/taoPlugin.d.ts +3 -0
- package/dist/plugins/tools/tao/taoPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/tao/taoPlugin.js +14 -0
- package/dist/plugins/tools/tao/taoPlugin.js.map +1 -0
- package/dist/providers/baseProvider.d.ts +148 -0
- package/dist/providers/baseProvider.d.ts.map +1 -0
- package/dist/providers/baseProvider.js +284 -0
- package/dist/providers/baseProvider.js.map +1 -0
- package/dist/shell/commandRegistry.d.ts +122 -0
- package/dist/shell/commandRegistry.d.ts.map +1 -0
- package/dist/shell/commandRegistry.js +371 -0
- package/dist/shell/commandRegistry.js.map +1 -0
- package/dist/shell/shellApp.d.ts.map +1 -1
- package/dist/shell/shellApp.js +2 -15
- package/dist/shell/shellApp.js.map +1 -1
- package/dist/tools/bashTools.d.ts.map +1 -1
- package/dist/tools/bashTools.js +2 -13
- package/dist/tools/bashTools.js.map +1 -1
- package/dist/tools/tao/index.d.ts +28 -0
- package/dist/tools/tao/index.d.ts.map +1 -0
- package/dist/tools/tao/index.js +33 -0
- package/dist/tools/tao/index.js.map +1 -0
- package/dist/tools/tao/intentParser.d.ts +9 -0
- package/dist/tools/tao/intentParser.d.ts.map +1 -0
- package/dist/tools/tao/intentParser.js +163 -0
- package/dist/tools/tao/intentParser.js.map +1 -0
- package/dist/tools/tao/rlEngine.d.ts +40 -0
- package/dist/tools/tao/rlEngine.d.ts.map +1 -0
- package/dist/tools/tao/rlEngine.js +237 -0
- package/dist/tools/tao/rlEngine.js.map +1 -0
- package/dist/tools/tao/sessionState.d.ts +9 -0
- package/dist/tools/tao/sessionState.d.ts.map +1 -0
- package/dist/tools/tao/sessionState.js +18 -0
- package/dist/tools/tao/sessionState.js.map +1 -0
- package/dist/tools/tao/types.d.ts +109 -0
- package/dist/tools/tao/types.d.ts.map +1 -0
- package/dist/tools/tao/types.js +5 -0
- package/dist/tools/tao/types.js.map +1 -0
- package/dist/tools/tao/verification.d.ts +23 -0
- package/dist/tools/tao/verification.d.ts.map +1 -0
- package/dist/tools/tao/verification.js +211 -0
- package/dist/tools/tao/verification.js.map +1 -0
- package/dist/tools/taoTools.d.ts +23 -0
- package/dist/tools/taoTools.d.ts.map +1 -0
- package/dist/tools/taoTools.js +14501 -0
- package/dist/tools/taoTools.js.map +1 -0
- package/dist/ui/UnifiedUIRenderer.d.ts +5 -0
- package/dist/ui/UnifiedUIRenderer.d.ts.map +1 -1
- package/dist/ui/UnifiedUIRenderer.js +49 -21
- package/dist/ui/UnifiedUIRenderer.js.map +1 -1
- package/dist/ui/animation/AnimationScheduler.d.ts +5 -0
- package/dist/ui/animation/AnimationScheduler.d.ts.map +1 -1
- package/dist/ui/animation/AnimationScheduler.js +9 -1
- package/dist/ui/animation/AnimationScheduler.js.map +1 -1
- package/dist/ui/index.d.ts +102 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +120 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/interrupts/InterruptManager.d.ts +16 -1
- package/dist/ui/interrupts/InterruptManager.d.ts.map +1 -1
- package/dist/ui/interrupts/InterruptManager.js +68 -6
- package/dist/ui/interrupts/InterruptManager.js.map +1 -1
- package/dist/ui/orchestration/UIUpdateCoordinator.d.ts +18 -0
- package/dist/ui/orchestration/UIUpdateCoordinator.d.ts.map +1 -1
- package/dist/ui/orchestration/UIUpdateCoordinator.js +64 -5
- package/dist/ui/orchestration/UIUpdateCoordinator.js.map +1 -1
- package/dist/utils/packageInfo.d.ts +14 -0
- package/dist/utils/packageInfo.d.ts.map +1 -0
- package/dist/utils/packageInfo.js +45 -0
- package/dist/utils/packageInfo.js.map +1 -0
- package/package.json +3 -3
- package/scripts/deploy-security-capabilities.js +157 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Tool Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities and patterns for creating tools with consistent:
|
|
5
|
+
* - Error handling
|
|
6
|
+
* - JSON schema generation
|
|
7
|
+
* - Result formatting
|
|
8
|
+
* - Progress reporting
|
|
9
|
+
* - Timeout handling
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createTool, ToolBuilder, commonSchemas } from '../core/baseToolFactory.js';
|
|
14
|
+
*
|
|
15
|
+
* const myTool = createTool({
|
|
16
|
+
* name: 'MyTool',
|
|
17
|
+
* description: 'Does something useful',
|
|
18
|
+
* parameters: {
|
|
19
|
+
* input: { type: 'string', required: true, description: 'Input value' },
|
|
20
|
+
* },
|
|
21
|
+
* handler: async (args) => {
|
|
22
|
+
* // Implementation
|
|
23
|
+
* return { success: true, data: args.input };
|
|
24
|
+
* },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import type { ToolDefinition, ToolSuite } from './toolRuntime.js';
|
|
29
|
+
/**
|
|
30
|
+
* Common schema fragments for reuse across tools
|
|
31
|
+
*/
|
|
32
|
+
export declare const commonSchemas: {
|
|
33
|
+
/** File path parameter */
|
|
34
|
+
filePath: {
|
|
35
|
+
type: "string";
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
/** Directory path parameter */
|
|
39
|
+
directoryPath: {
|
|
40
|
+
type: "string";
|
|
41
|
+
description: string;
|
|
42
|
+
};
|
|
43
|
+
/** Timeout in milliseconds */
|
|
44
|
+
timeout: {
|
|
45
|
+
type: "number";
|
|
46
|
+
description: string;
|
|
47
|
+
default: number;
|
|
48
|
+
};
|
|
49
|
+
/** Boolean flag */
|
|
50
|
+
flag: (description: string, defaultValue?: boolean) => {
|
|
51
|
+
type: "boolean";
|
|
52
|
+
description: string;
|
|
53
|
+
default: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** String with enum options */
|
|
56
|
+
enum: (description: string, values: string[], defaultValue?: string) => {
|
|
57
|
+
default?: string | undefined;
|
|
58
|
+
type: "string";
|
|
59
|
+
description: string;
|
|
60
|
+
enum: string[];
|
|
61
|
+
};
|
|
62
|
+
/** Array of strings */
|
|
63
|
+
stringArray: (description: string) => {
|
|
64
|
+
type: "array";
|
|
65
|
+
items: {
|
|
66
|
+
type: "string";
|
|
67
|
+
};
|
|
68
|
+
description: string;
|
|
69
|
+
};
|
|
70
|
+
/** Optional string */
|
|
71
|
+
optionalString: (description: string) => {
|
|
72
|
+
type: "string";
|
|
73
|
+
description: string;
|
|
74
|
+
};
|
|
75
|
+
/** Required string */
|
|
76
|
+
requiredString: (description: string) => {
|
|
77
|
+
type: "string";
|
|
78
|
+
description: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export interface ToolResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
data?: unknown;
|
|
84
|
+
error?: string;
|
|
85
|
+
warnings?: string[];
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Format a tool result to a consistent JSON string
|
|
90
|
+
*/
|
|
91
|
+
export declare function formatToolResult(result: ToolResult): string;
|
|
92
|
+
/**
|
|
93
|
+
* Create a successful tool result
|
|
94
|
+
*/
|
|
95
|
+
export declare function successResult(data: unknown, metadata?: Record<string, unknown>): string;
|
|
96
|
+
/**
|
|
97
|
+
* Create a failed tool result
|
|
98
|
+
*/
|
|
99
|
+
export declare function errorResult(error: string | Error, metadata?: Record<string, unknown>): string;
|
|
100
|
+
/**
|
|
101
|
+
* Create a result with warnings
|
|
102
|
+
*/
|
|
103
|
+
export declare function warningResult(data: unknown, warnings: string[], metadata?: Record<string, unknown>): string;
|
|
104
|
+
export interface SimpleParameterDef {
|
|
105
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
106
|
+
description: string;
|
|
107
|
+
required?: boolean;
|
|
108
|
+
default?: unknown;
|
|
109
|
+
enum?: string[];
|
|
110
|
+
items?: {
|
|
111
|
+
type: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export interface CreateToolOptions<T extends Record<string, unknown>> {
|
|
115
|
+
name: string;
|
|
116
|
+
description: string;
|
|
117
|
+
parameters?: Record<string, SimpleParameterDef>;
|
|
118
|
+
handler: (args: T) => Promise<unknown> | unknown;
|
|
119
|
+
cacheable?: boolean;
|
|
120
|
+
formatResult?: (result: unknown) => string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a tool definition with simplified parameter handling
|
|
124
|
+
*/
|
|
125
|
+
export declare function createTool<T extends Record<string, unknown>>(options: CreateToolOptions<T>): ToolDefinition<T>;
|
|
126
|
+
/**
|
|
127
|
+
* Fluent builder for creating tools
|
|
128
|
+
*
|
|
129
|
+
* Usage:
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const tool = new ToolBuilder('MyTool')
|
|
132
|
+
* .description('Does something useful')
|
|
133
|
+
* .param('input', 'string', 'The input value', true)
|
|
134
|
+
* .param('verbose', 'boolean', 'Enable verbose output', false, false)
|
|
135
|
+
* .handler(async (args) => {
|
|
136
|
+
* return { data: args.input };
|
|
137
|
+
* })
|
|
138
|
+
* .build();
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare class ToolBuilder<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
142
|
+
private _name;
|
|
143
|
+
private _description;
|
|
144
|
+
private _parameters;
|
|
145
|
+
private _handler?;
|
|
146
|
+
private _cacheable;
|
|
147
|
+
private _formatResult?;
|
|
148
|
+
constructor(name: string);
|
|
149
|
+
description(desc: string): this;
|
|
150
|
+
param(name: string, type: SimpleParameterDef['type'], description: string, required?: boolean, defaultValue?: unknown): this;
|
|
151
|
+
enumParam(name: string, description: string, values: string[], required?: boolean, defaultValue?: string): this;
|
|
152
|
+
arrayParam(name: string, description: string, itemType?: string, required?: boolean): this;
|
|
153
|
+
handler(fn: (args: T) => Promise<unknown> | unknown): this;
|
|
154
|
+
cacheable(value?: boolean): this;
|
|
155
|
+
formatResult(fn: (result: unknown) => string): this;
|
|
156
|
+
build(): ToolDefinition<T>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Builder for creating tool suites
|
|
160
|
+
*/
|
|
161
|
+
export declare class ToolSuiteBuilder {
|
|
162
|
+
private _id;
|
|
163
|
+
private _description?;
|
|
164
|
+
private _tools;
|
|
165
|
+
constructor(id: string);
|
|
166
|
+
description(desc: string): this;
|
|
167
|
+
addTool(tool: ToolDefinition): this;
|
|
168
|
+
addTools(tools: ToolDefinition[]): this;
|
|
169
|
+
build(): ToolSuite;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Execute with timeout
|
|
173
|
+
*/
|
|
174
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, errorMessage?: string): Promise<T>;
|
|
175
|
+
/**
|
|
176
|
+
* Execute with progress reporting for long operations
|
|
177
|
+
*/
|
|
178
|
+
export declare function withProgress<T>(operation: (report: (current: number, total?: number, message?: string) => void) => Promise<T>): Promise<T>;
|
|
179
|
+
/**
|
|
180
|
+
* Retry an operation with exponential backoff
|
|
181
|
+
*/
|
|
182
|
+
export declare function withRetry<T>(operation: () => Promise<T>, options?: {
|
|
183
|
+
maxRetries?: number;
|
|
184
|
+
baseDelayMs?: number;
|
|
185
|
+
shouldRetry?: (error: unknown) => boolean;
|
|
186
|
+
}): Promise<T>;
|
|
187
|
+
//# sourceMappingURL=baseToolFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseToolFactory.d.ts","sourceRoot":"","sources":["../../src/core/baseToolFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,cAAc,E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AY,CAAC,CAAC,EAClC,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAC7F,OAAO,CAAC,CAAC,CAAC,CAMZ;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAAO,GACrG,OAAO,CAAC,CAAC,CAAC,CAqBZ"}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Tool Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities and patterns for creating tools with consistent:
|
|
5
|
+
* - Error handling
|
|
6
|
+
* - JSON schema generation
|
|
7
|
+
* - Result formatting
|
|
8
|
+
* - Progress reporting
|
|
9
|
+
* - Timeout handling
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createTool, ToolBuilder, commonSchemas } from '../core/baseToolFactory.js';
|
|
14
|
+
*
|
|
15
|
+
* const myTool = createTool({
|
|
16
|
+
* name: 'MyTool',
|
|
17
|
+
* description: 'Does something useful',
|
|
18
|
+
* parameters: {
|
|
19
|
+
* input: { type: 'string', required: true, description: 'Input value' },
|
|
20
|
+
* },
|
|
21
|
+
* handler: async (args) => {
|
|
22
|
+
* // Implementation
|
|
23
|
+
* return { success: true, data: args.input };
|
|
24
|
+
* },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { reportToolProgress } from './toolRuntime.js';
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
30
|
+
// Common Schema Fragments
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
32
|
+
/**
|
|
33
|
+
* Common schema fragments for reuse across tools
|
|
34
|
+
*/
|
|
35
|
+
export const commonSchemas = {
|
|
36
|
+
/** File path parameter */
|
|
37
|
+
filePath: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
description: 'Absolute path to the file',
|
|
40
|
+
},
|
|
41
|
+
/** Directory path parameter */
|
|
42
|
+
directoryPath: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
description: 'Absolute path to the directory',
|
|
45
|
+
},
|
|
46
|
+
/** Timeout in milliseconds */
|
|
47
|
+
timeout: {
|
|
48
|
+
type: 'number',
|
|
49
|
+
description: 'Timeout in milliseconds',
|
|
50
|
+
default: 30000,
|
|
51
|
+
},
|
|
52
|
+
/** Boolean flag */
|
|
53
|
+
flag: (description, defaultValue = false) => ({
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
description,
|
|
56
|
+
default: defaultValue,
|
|
57
|
+
}),
|
|
58
|
+
/** String with enum options */
|
|
59
|
+
enum: (description, values, defaultValue) => ({
|
|
60
|
+
type: 'string',
|
|
61
|
+
description,
|
|
62
|
+
enum: values,
|
|
63
|
+
...(defaultValue !== undefined && { default: defaultValue }),
|
|
64
|
+
}),
|
|
65
|
+
/** Array of strings */
|
|
66
|
+
stringArray: (description) => ({
|
|
67
|
+
type: 'array',
|
|
68
|
+
items: { type: 'string' },
|
|
69
|
+
description,
|
|
70
|
+
}),
|
|
71
|
+
/** Optional string */
|
|
72
|
+
optionalString: (description) => ({
|
|
73
|
+
type: 'string',
|
|
74
|
+
description,
|
|
75
|
+
}),
|
|
76
|
+
/** Required string */
|
|
77
|
+
requiredString: (description) => ({
|
|
78
|
+
type: 'string',
|
|
79
|
+
description,
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Format a tool result to a consistent JSON string
|
|
84
|
+
*/
|
|
85
|
+
export function formatToolResult(result) {
|
|
86
|
+
return JSON.stringify(result, null, 2);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a successful tool result
|
|
90
|
+
*/
|
|
91
|
+
export function successResult(data, metadata) {
|
|
92
|
+
return formatToolResult({
|
|
93
|
+
success: true,
|
|
94
|
+
data,
|
|
95
|
+
...(metadata && { metadata }),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create a failed tool result
|
|
100
|
+
*/
|
|
101
|
+
export function errorResult(error, metadata) {
|
|
102
|
+
const message = error instanceof Error ? error.message : error;
|
|
103
|
+
return formatToolResult({
|
|
104
|
+
success: false,
|
|
105
|
+
error: message,
|
|
106
|
+
...(metadata && { metadata }),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a result with warnings
|
|
111
|
+
*/
|
|
112
|
+
export function warningResult(data, warnings, metadata) {
|
|
113
|
+
return formatToolResult({
|
|
114
|
+
success: true,
|
|
115
|
+
data,
|
|
116
|
+
warnings,
|
|
117
|
+
...(metadata && { metadata }),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a tool definition with simplified parameter handling
|
|
122
|
+
*/
|
|
123
|
+
export function createTool(options) {
|
|
124
|
+
const { name, description, parameters, handler, cacheable, formatResult } = options;
|
|
125
|
+
// Build JSON schema from simple parameter definitions
|
|
126
|
+
const jsonSchema = parameters
|
|
127
|
+
? buildJsonSchema(parameters)
|
|
128
|
+
: undefined;
|
|
129
|
+
return {
|
|
130
|
+
name,
|
|
131
|
+
description,
|
|
132
|
+
parameters: jsonSchema,
|
|
133
|
+
cacheable,
|
|
134
|
+
handler: async (args) => {
|
|
135
|
+
try {
|
|
136
|
+
const result = await handler(args);
|
|
137
|
+
// Use custom formatter if provided
|
|
138
|
+
if (formatResult) {
|
|
139
|
+
return formatResult(result);
|
|
140
|
+
}
|
|
141
|
+
// Default: JSON stringify
|
|
142
|
+
if (typeof result === 'string') {
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
return JSON.stringify(result, null, 2);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return errorResult(error instanceof Error ? error : String(error));
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Build a JSON schema from simplified parameter definitions
|
|
155
|
+
*/
|
|
156
|
+
function buildJsonSchema(parameters) {
|
|
157
|
+
const properties = {};
|
|
158
|
+
const required = [];
|
|
159
|
+
for (const [key, def] of Object.entries(parameters)) {
|
|
160
|
+
const prop = {
|
|
161
|
+
type: def.type,
|
|
162
|
+
description: def.description,
|
|
163
|
+
};
|
|
164
|
+
if (def.default !== undefined) {
|
|
165
|
+
prop['default'] = def.default;
|
|
166
|
+
}
|
|
167
|
+
if (def.enum) {
|
|
168
|
+
prop['enum'] = def.enum;
|
|
169
|
+
}
|
|
170
|
+
if (def.items) {
|
|
171
|
+
prop['items'] = def.items;
|
|
172
|
+
}
|
|
173
|
+
properties[key] = prop;
|
|
174
|
+
if (def.required) {
|
|
175
|
+
required.push(key);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties,
|
|
181
|
+
...(required.length > 0 && { required }),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
185
|
+
// Tool Builder (Fluent API)
|
|
186
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
187
|
+
/**
|
|
188
|
+
* Fluent builder for creating tools
|
|
189
|
+
*
|
|
190
|
+
* Usage:
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const tool = new ToolBuilder('MyTool')
|
|
193
|
+
* .description('Does something useful')
|
|
194
|
+
* .param('input', 'string', 'The input value', true)
|
|
195
|
+
* .param('verbose', 'boolean', 'Enable verbose output', false, false)
|
|
196
|
+
* .handler(async (args) => {
|
|
197
|
+
* return { data: args.input };
|
|
198
|
+
* })
|
|
199
|
+
* .build();
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export class ToolBuilder {
|
|
203
|
+
_name;
|
|
204
|
+
_description = '';
|
|
205
|
+
_parameters = {};
|
|
206
|
+
_handler;
|
|
207
|
+
_cacheable = false;
|
|
208
|
+
_formatResult;
|
|
209
|
+
constructor(name) {
|
|
210
|
+
this._name = name;
|
|
211
|
+
}
|
|
212
|
+
description(desc) {
|
|
213
|
+
this._description = desc;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
param(name, type, description, required = false, defaultValue) {
|
|
217
|
+
this._parameters[name] = {
|
|
218
|
+
type,
|
|
219
|
+
description,
|
|
220
|
+
required,
|
|
221
|
+
...(defaultValue !== undefined && { default: defaultValue }),
|
|
222
|
+
};
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
enumParam(name, description, values, required = false, defaultValue) {
|
|
226
|
+
this._parameters[name] = {
|
|
227
|
+
type: 'string',
|
|
228
|
+
description,
|
|
229
|
+
required,
|
|
230
|
+
enum: values,
|
|
231
|
+
...(defaultValue !== undefined && { default: defaultValue }),
|
|
232
|
+
};
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
arrayParam(name, description, itemType = 'string', required = false) {
|
|
236
|
+
this._parameters[name] = {
|
|
237
|
+
type: 'array',
|
|
238
|
+
description,
|
|
239
|
+
required,
|
|
240
|
+
items: { type: itemType },
|
|
241
|
+
};
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
handler(fn) {
|
|
245
|
+
this._handler = fn;
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
cacheable(value = true) {
|
|
249
|
+
this._cacheable = value;
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
formatResult(fn) {
|
|
253
|
+
this._formatResult = fn;
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
build() {
|
|
257
|
+
if (!this._handler) {
|
|
258
|
+
throw new Error(`Tool ${this._name} requires a handler`);
|
|
259
|
+
}
|
|
260
|
+
return createTool({
|
|
261
|
+
name: this._name,
|
|
262
|
+
description: this._description,
|
|
263
|
+
parameters: Object.keys(this._parameters).length > 0 ? this._parameters : undefined,
|
|
264
|
+
handler: this._handler,
|
|
265
|
+
cacheable: this._cacheable,
|
|
266
|
+
formatResult: this._formatResult,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
271
|
+
// Tool Suite Builder
|
|
272
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
273
|
+
/**
|
|
274
|
+
* Builder for creating tool suites
|
|
275
|
+
*/
|
|
276
|
+
export class ToolSuiteBuilder {
|
|
277
|
+
_id;
|
|
278
|
+
_description;
|
|
279
|
+
_tools = [];
|
|
280
|
+
constructor(id) {
|
|
281
|
+
this._id = id;
|
|
282
|
+
}
|
|
283
|
+
description(desc) {
|
|
284
|
+
this._description = desc;
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
addTool(tool) {
|
|
288
|
+
this._tools.push(tool);
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
addTools(tools) {
|
|
292
|
+
this._tools.push(...tools);
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
build() {
|
|
296
|
+
return {
|
|
297
|
+
id: this._id,
|
|
298
|
+
description: this._description,
|
|
299
|
+
tools: this._tools,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
304
|
+
// Async Utilities for Tools
|
|
305
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
306
|
+
/**
|
|
307
|
+
* Execute with timeout
|
|
308
|
+
*/
|
|
309
|
+
export async function withTimeout(promise, timeoutMs, errorMessage = 'Operation timed out') {
|
|
310
|
+
let timeoutId;
|
|
311
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
312
|
+
timeoutId = setTimeout(() => reject(new Error(errorMessage)), timeoutMs);
|
|
313
|
+
});
|
|
314
|
+
try {
|
|
315
|
+
return await Promise.race([promise, timeoutPromise]);
|
|
316
|
+
}
|
|
317
|
+
finally {
|
|
318
|
+
clearTimeout(timeoutId);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Execute with progress reporting for long operations
|
|
323
|
+
*/
|
|
324
|
+
export async function withProgress(operation) {
|
|
325
|
+
const report = (current, total, message) => {
|
|
326
|
+
reportToolProgress({ current, total, message });
|
|
327
|
+
};
|
|
328
|
+
return operation(report);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Retry an operation with exponential backoff
|
|
332
|
+
*/
|
|
333
|
+
export async function withRetry(operation, options = {}) {
|
|
334
|
+
const { maxRetries = 3, baseDelayMs = 1000, shouldRetry = () => true } = options;
|
|
335
|
+
let lastError;
|
|
336
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
337
|
+
try {
|
|
338
|
+
return await operation();
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
lastError = error;
|
|
342
|
+
if (attempt === maxRetries || !shouldRetry(error)) {
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
// Exponential backoff
|
|
346
|
+
const delayMs = baseDelayMs * Math.pow(2, attempt);
|
|
347
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
throw lastError;
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=baseToolFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseToolFactory.js","sourceRoot":"","sources":["../../src/core/baseToolFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAA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EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Error Handling System
|
|
3
|
+
*
|
|
4
|
+
* This module consolidates all error-related exports into a single entry point.
|
|
5
|
+
* Use this module for all error handling needs instead of importing from
|
|
6
|
+
* individual files.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* - errorTypes.ts: Base classes and structured error types
|
|
10
|
+
* - apiKeyErrors.ts: API key and authentication errors
|
|
11
|
+
* - networkErrors.ts: Network connectivity errors
|
|
12
|
+
* - safetyValidator.ts: Input validation and safety checks
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import {
|
|
17
|
+
* StructuredError,
|
|
18
|
+
* ErrorSeverity,
|
|
19
|
+
* ErrorCategory,
|
|
20
|
+
* DangerousOperationError,
|
|
21
|
+
* detectApiKeyError,
|
|
22
|
+
* detectNetworkError,
|
|
23
|
+
* } from '../core/errors/index.js';
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export { ErrorSeverity, ErrorCategory, type ErrorSuggestion, type StructuredErrorDetails, StructuredError, DangerousOperationError, BlockedOperationError, ContextOverflowError, ResourceLimitError, ValidationError, toStructuredError, } from './errorTypes.js';
|
|
27
|
+
export { type ApiKeyErrorType, type ApiKeyErrorInfo, detectApiKeyError, } from './apiKeyErrors.js';
|
|
28
|
+
export { type NetworkErrorInfo, detectNetworkError, } from './networkErrors.js';
|
|
29
|
+
export * from './safetyValidator.js';
|
|
30
|
+
export { type ErrorContextValue, type ErrorContext, buildError, } from '../errors.js';
|
|
31
|
+
/**
|
|
32
|
+
* Detect and classify any error into a structured format
|
|
33
|
+
*/
|
|
34
|
+
export declare function detectError(error: unknown, provider?: string): {
|
|
35
|
+
type: 'api_key' | 'network' | 'structured' | 'unknown';
|
|
36
|
+
info: unknown;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Check if an error is recoverable
|
|
40
|
+
*/
|
|
41
|
+
export declare function isRecoverableError(error: unknown): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get a user-friendly error message
|
|
44
|
+
*/
|
|
45
|
+
export declare function getUserFriendlyMessage(error: unknown): string;
|
|
46
|
+
/**
|
|
47
|
+
* Format error for logging (includes full details)
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatForLogging(error: unknown, context?: Record<string, unknown>): string;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,OAAO,EAEL,aAAa,EACb,aAAa,EAGb,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAG3B,eAAe,EAGf,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EAGf,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,KAAK,gBAAgB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAM5B,cAAc,sBAAsB,CAAC;AAMrC,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,UAAU,GACX,MAAM,cAAc,CAAC;AAatB;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG;IAC9D,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;IACvD,IAAI,EAAE,OAAO,CAAC;CACf,CA0BA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAa1D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAuB7D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CA2B1F"}
|