@autonomaai/agent-core 1.0.2
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/dist/base-agent.d.ts +112 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +173 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/core.d.ts +81 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +633 -0
- package/dist/core.js.map +1 -0
- package/dist/error-handler.d.ts +78 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +129 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/factory.d.ts +60 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +621 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/streaming.d.ts +24 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +36 -0
- package/dist/streaming.js.map +1 -0
- package/dist/trading/formatters.d.ts +167 -0
- package/dist/trading/formatters.d.ts.map +1 -0
- package/dist/trading/formatters.js +271 -0
- package/dist/trading/formatters.js.map +1 -0
- package/dist/trading/index.d.ts +9 -0
- package/dist/trading/index.d.ts.map +1 -0
- package/dist/trading/index.js +10 -0
- package/dist/trading/index.js.map +1 -0
- package/dist/trading/types.d.ts +205 -0
- package/dist/trading/types.d.ts.map +1 -0
- package/dist/trading/types.js +7 -0
- package/dist/trading/types.js.map +1 -0
- package/dist/trading/utils.d.ts +120 -0
- package/dist/trading/utils.d.ts.map +1 -0
- package/dist/trading/utils.js +291 -0
- package/dist/trading/utils.js.map +1 -0
- package/dist/trading/validation.d.ts +40 -0
- package/dist/trading/validation.d.ts.map +1 -0
- package/dist/trading/validation.js +247 -0
- package/dist/trading/validation.js.map +1 -0
- package/dist/types.d.ts +282 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/src/base-agent.ts +263 -0
- package/src/core.ts +792 -0
- package/src/error-handler.ts +166 -0
- package/src/factory.ts +687 -0
- package/src/global.d.ts +12 -0
- package/src/index.ts +24 -0
- package/src/streaming.ts +50 -0
- package/src/trading/formatters.ts +363 -0
- package/src/trading/index.ts +10 -0
- package/src/trading/types.ts +263 -0
- package/src/trading/utils.ts +355 -0
- package/src/trading/validation.ts +321 -0
- package/src/types.ts +402 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardized Error Handling for autonoma Agents
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent error handling, logging, and user-friendly messages
|
|
5
|
+
* across all agent implementations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface ErrorMetadata {
|
|
9
|
+
executionTime: number;
|
|
10
|
+
errorType: string;
|
|
11
|
+
agentName: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface StandardErrorResponse {
|
|
16
|
+
error: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
metadata?: ErrorMetadata;
|
|
19
|
+
statusCode?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for agent-specific error messages
|
|
24
|
+
*/
|
|
25
|
+
export const AGENT_ERROR_CONFIGS = {
|
|
26
|
+
'market-maker': {
|
|
27
|
+
name: 'Market Maker Agent',
|
|
28
|
+
defaultMessage: "I'm sorry, I encountered an error while processing your trading request. Please check your connection and try again.",
|
|
29
|
+
errorPrefix: "Trading Error"
|
|
30
|
+
},
|
|
31
|
+
'apy': {
|
|
32
|
+
name: 'DeFi Yield Agent',
|
|
33
|
+
defaultMessage: "I'm sorry, I encountered an error while processing your DeFi request. Please check your connection and try again.",
|
|
34
|
+
errorPrefix: "DeFi Error"
|
|
35
|
+
},
|
|
36
|
+
'portfolio-manager': {
|
|
37
|
+
name: 'Portfolio Manager Agent',
|
|
38
|
+
defaultMessage: "I'm sorry, I encountered an error while processing your portfolio request. Please check your connection and try again.",
|
|
39
|
+
errorPrefix: "Portfolio Error"
|
|
40
|
+
},
|
|
41
|
+
'memecoin': {
|
|
42
|
+
name: 'Memecoin Agent',
|
|
43
|
+
defaultMessage: "I'm sorry, I encountered an error while analyzing memecoins. Please check your connection and try again.",
|
|
44
|
+
errorPrefix: "Memecoin Error"
|
|
45
|
+
},
|
|
46
|
+
'orchestrator': {
|
|
47
|
+
name: 'Agent Orchestrator',
|
|
48
|
+
defaultMessage: "I'm sorry, I encountered an error while coordinating agents. Please check your connection and try again.",
|
|
49
|
+
errorPrefix: "Orchestrator Error"
|
|
50
|
+
}
|
|
51
|
+
} as const;
|
|
52
|
+
|
|
53
|
+
export type AgentType = keyof typeof AGENT_ERROR_CONFIGS;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Standardized error handler for all autonoma agents
|
|
57
|
+
*/
|
|
58
|
+
export class AgentErrorHandler {
|
|
59
|
+
private agentType: AgentType;
|
|
60
|
+
private startTime: number;
|
|
61
|
+
|
|
62
|
+
constructor(agentType: AgentType, startTime: number = Date.now()) {
|
|
63
|
+
this.agentType = agentType;
|
|
64
|
+
this.startTime = startTime;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Handle and format errors with consistent logging and user messages
|
|
69
|
+
*/
|
|
70
|
+
handleError(error: unknown, customMessage?: string): StandardErrorResponse {
|
|
71
|
+
const config = AGENT_ERROR_CONFIGS[this.agentType];
|
|
72
|
+
const timestamp = new Date().toISOString();
|
|
73
|
+
const executionTime = Date.now() - this.startTime;
|
|
74
|
+
|
|
75
|
+
// Enhanced error logging for debugging
|
|
76
|
+
const errorDetails = {
|
|
77
|
+
agent: config.name,
|
|
78
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
79
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
80
|
+
timestamp,
|
|
81
|
+
executionTime
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
console.error(`${config.errorPrefix}:`, errorDetails);
|
|
85
|
+
|
|
86
|
+
// User-friendly error message
|
|
87
|
+
const userMessage = customMessage || config.defaultMessage;
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
error: userMessage,
|
|
91
|
+
timestamp,
|
|
92
|
+
statusCode: 500,
|
|
93
|
+
metadata: {
|
|
94
|
+
executionTime,
|
|
95
|
+
errorType: error instanceof Error ? error.constructor.name : 'UnknownError',
|
|
96
|
+
agentName: config.name,
|
|
97
|
+
timestamp
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Handle validation errors specifically
|
|
104
|
+
*/
|
|
105
|
+
handleValidationError(field: string, issue: string): StandardErrorResponse {
|
|
106
|
+
const config = AGENT_ERROR_CONFIGS[this.agentType];
|
|
107
|
+
const timestamp = new Date().toISOString();
|
|
108
|
+
const executionTime = Date.now() - this.startTime;
|
|
109
|
+
|
|
110
|
+
console.error(`${config.errorPrefix} - Validation:`, { field, issue, timestamp });
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
error: `Invalid request: ${field} ${issue}`,
|
|
114
|
+
timestamp,
|
|
115
|
+
statusCode: 400,
|
|
116
|
+
metadata: {
|
|
117
|
+
executionTime,
|
|
118
|
+
errorType: 'ValidationError',
|
|
119
|
+
agentName: config.name,
|
|
120
|
+
timestamp
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Handle service unavailable errors (like MCP servers down)
|
|
127
|
+
*/
|
|
128
|
+
handleServiceUnavailable(serviceName: string): StandardErrorResponse {
|
|
129
|
+
const config = AGENT_ERROR_CONFIGS[this.agentType];
|
|
130
|
+
const timestamp = new Date().toISOString();
|
|
131
|
+
const executionTime = Date.now() - this.startTime;
|
|
132
|
+
|
|
133
|
+
console.warn(`${config.errorPrefix} - Service Unavailable:`, { serviceName, timestamp });
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
error: `I'm currently unable to access the ${serviceName} service. I can still help with general questions and guidance. Please try again later for advanced features.`,
|
|
137
|
+
timestamp,
|
|
138
|
+
statusCode: 503,
|
|
139
|
+
metadata: {
|
|
140
|
+
executionTime,
|
|
141
|
+
errorType: 'ServiceUnavailableError',
|
|
142
|
+
agentName: config.name,
|
|
143
|
+
timestamp
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Quick factory function for creating error handlers
|
|
151
|
+
*/
|
|
152
|
+
export function createErrorHandler(agentType: AgentType, startTime?: number): AgentErrorHandler {
|
|
153
|
+
return new AgentErrorHandler(agentType, startTime);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Simple error response for cases where we don't need the full handler
|
|
158
|
+
*/
|
|
159
|
+
export function createErrorResponse(
|
|
160
|
+
agentType: AgentType,
|
|
161
|
+
error: unknown,
|
|
162
|
+
customMessage?: string
|
|
163
|
+
): StandardErrorResponse {
|
|
164
|
+
const handler = new AgentErrorHandler(agentType);
|
|
165
|
+
return handler.handleError(error, customMessage);
|
|
166
|
+
}
|