@hazeljs/agent 0.2.0-beta.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.
- package/IMPLEMENTATION_SUMMARY.md +400 -0
- package/PERSISTENCE.md +201 -0
- package/PRISMA_INTEGRATION.md +499 -0
- package/PRODUCTION_READINESS.md +264 -0
- package/QUICKSTART.md +135 -0
- package/README.md +427 -0
- package/STATE_VS_MEMORY.md +243 -0
- package/dist/agent.module.d.ts +42 -0
- package/dist/agent.module.d.ts.map +1 -0
- package/dist/agent.module.js +90 -0
- package/dist/agent.module.js.map +1 -0
- package/dist/context/agent.context.d.ts +27 -0
- package/dist/context/agent.context.d.ts.map +1 -0
- package/dist/context/agent.context.js +98 -0
- package/dist/context/agent.context.js.map +1 -0
- package/dist/decorators/agent.decorator.d.ts +21 -0
- package/dist/decorators/agent.decorator.d.ts.map +1 -0
- package/dist/decorators/agent.decorator.js +38 -0
- package/dist/decorators/agent.decorator.js.map +1 -0
- package/dist/decorators/tool.decorator.d.ts +23 -0
- package/dist/decorators/tool.decorator.d.ts.map +1 -0
- package/dist/decorators/tool.decorator.js +61 -0
- package/dist/decorators/tool.decorator.js.map +1 -0
- package/dist/events/event.emitter.d.ts +45 -0
- package/dist/events/event.emitter.d.ts.map +1 -0
- package/dist/events/event.emitter.js +96 -0
- package/dist/events/event.emitter.js.map +1 -0
- package/dist/executor/agent.executor.d.ts +57 -0
- package/dist/executor/agent.executor.d.ts.map +1 -0
- package/dist/executor/agent.executor.js +303 -0
- package/dist/executor/agent.executor.js.map +1 -0
- package/dist/executor/tool.executor.d.ts +53 -0
- package/dist/executor/tool.executor.d.ts.map +1 -0
- package/dist/executor/tool.executor.js +234 -0
- package/dist/executor/tool.executor.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/registry/agent.registry.d.ts +49 -0
- package/dist/registry/agent.registry.d.ts.map +1 -0
- package/dist/registry/agent.registry.js +90 -0
- package/dist/registry/agent.registry.js.map +1 -0
- package/dist/registry/tool.registry.d.ts +54 -0
- package/dist/registry/tool.registry.d.ts.map +1 -0
- package/dist/registry/tool.registry.js +153 -0
- package/dist/registry/tool.registry.js.map +1 -0
- package/dist/runtime/agent.runtime.d.ts +155 -0
- package/dist/runtime/agent.runtime.d.ts.map +1 -0
- package/dist/runtime/agent.runtime.extensions.d.ts +49 -0
- package/dist/runtime/agent.runtime.extensions.d.ts.map +1 -0
- package/dist/runtime/agent.runtime.extensions.js +93 -0
- package/dist/runtime/agent.runtime.extensions.js.map +1 -0
- package/dist/runtime/agent.runtime.js +347 -0
- package/dist/runtime/agent.runtime.js.map +1 -0
- package/dist/state/agent-state.interface.d.ts +63 -0
- package/dist/state/agent-state.interface.d.ts.map +1 -0
- package/dist/state/agent-state.interface.js +7 -0
- package/dist/state/agent-state.interface.js.map +1 -0
- package/dist/state/agent.state.d.ts +67 -0
- package/dist/state/agent.state.d.ts.map +1 -0
- package/dist/state/agent.state.js +172 -0
- package/dist/state/agent.state.js.map +1 -0
- package/dist/state/database-state.manager.d.ts +63 -0
- package/dist/state/database-state.manager.d.ts.map +1 -0
- package/dist/state/database-state.manager.js +282 -0
- package/dist/state/database-state.manager.js.map +1 -0
- package/dist/state/redis-state.manager.d.ts +81 -0
- package/dist/state/redis-state.manager.d.ts.map +1 -0
- package/dist/state/redis-state.manager.js +253 -0
- package/dist/state/redis-state.manager.js.map +1 -0
- package/dist/types/agent.types.d.ts +151 -0
- package/dist/types/agent.types.d.ts.map +1 -0
- package/dist/types/agent.types.js +32 -0
- package/dist/types/agent.types.js.map +1 -0
- package/dist/types/event.types.d.ts +123 -0
- package/dist/types/event.types.d.ts.map +1 -0
- package/dist/types/event.types.js +30 -0
- package/dist/types/event.types.js.map +1 -0
- package/dist/types/llm.types.d.ts +66 -0
- package/dist/types/llm.types.d.ts.map +1 -0
- package/dist/types/llm.types.js +7 -0
- package/dist/types/llm.types.js.map +1 -0
- package/dist/types/rag.types.d.ts +40 -0
- package/dist/types/rag.types.d.ts.map +1 -0
- package/dist/types/rag.types.js +7 -0
- package/dist/types/rag.types.js.map +1 -0
- package/dist/types/tool.types.d.ts +118 -0
- package/dist/types/tool.types.d.ts.map +1 -0
- package/dist/types/tool.types.js +19 -0
- package/dist/types/tool.types.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +69 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +156 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/health-check.d.ts +71 -0
- package/dist/utils/health-check.d.ts.map +1 -0
- package/dist/utils/health-check.js +156 -0
- package/dist/utils/health-check.js.map +1 -0
- package/dist/utils/logger.d.ts +53 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +133 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/metrics.d.ts +90 -0
- package/dist/utils/metrics.d.ts.map +1 -0
- package/dist/utils/metrics.js +186 -0
- package/dist/utils/metrics.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +44 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +82 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/retry.d.ts +42 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +103 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +58 -0
- package/prisma-schema.example.prisma +76 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider Types
|
|
3
|
+
* Defines the interface for LLM providers used by the agent runtime
|
|
4
|
+
*/
|
|
5
|
+
export interface LLMMessage {
|
|
6
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
7
|
+
content: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LLMToolCall {
|
|
11
|
+
id: string;
|
|
12
|
+
type: 'function';
|
|
13
|
+
function: {
|
|
14
|
+
name: string;
|
|
15
|
+
arguments: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface LLMToolDefinition {
|
|
19
|
+
type: 'function';
|
|
20
|
+
function: {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
parameters: {
|
|
24
|
+
type: 'object';
|
|
25
|
+
properties: Record<string, unknown>;
|
|
26
|
+
required?: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface LLMChatRequest {
|
|
31
|
+
messages: LLMMessage[];
|
|
32
|
+
tools?: LLMToolDefinition[];
|
|
33
|
+
temperature?: number;
|
|
34
|
+
maxTokens?: number;
|
|
35
|
+
topP?: number;
|
|
36
|
+
model?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface LLMChatResponse {
|
|
39
|
+
content: string;
|
|
40
|
+
tool_calls?: LLMToolCall[];
|
|
41
|
+
usage?: {
|
|
42
|
+
promptTokens: number;
|
|
43
|
+
completionTokens: number;
|
|
44
|
+
totalTokens: number;
|
|
45
|
+
};
|
|
46
|
+
finishReason?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* LLM Provider Interface
|
|
50
|
+
* All LLM providers must implement this interface
|
|
51
|
+
*/
|
|
52
|
+
export interface LLMProvider {
|
|
53
|
+
/**
|
|
54
|
+
* Send a chat completion request
|
|
55
|
+
*/
|
|
56
|
+
chat(request: LLMChatRequest): Promise<LLMChatResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Optional: Check if the provider is available
|
|
59
|
+
*/
|
|
60
|
+
isAvailable?(): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Optional: Get supported models
|
|
63
|
+
*/
|
|
64
|
+
getSupportedModels?(): string[];
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=llm.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAExD;;OAEG;IACH,WAAW,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjC;;OAEG;IACH,kBAAkB,CAAC,IAAI,MAAM,EAAE,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.types.js","sourceRoot":"","sources":["../../src/types/llm.types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAG Service Types
|
|
3
|
+
* Defines the interface for RAG services used by the agent runtime
|
|
4
|
+
*/
|
|
5
|
+
export interface RAGDocument {
|
|
6
|
+
id: string;
|
|
7
|
+
content: string;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
score?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface RAGSearchRequest {
|
|
12
|
+
query: string;
|
|
13
|
+
topK?: number;
|
|
14
|
+
filter?: Record<string, unknown>;
|
|
15
|
+
minScore?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface RAGSearchResponse {
|
|
18
|
+
documents: RAGDocument[];
|
|
19
|
+
totalResults: number;
|
|
20
|
+
searchTime?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* RAG Service Interface
|
|
24
|
+
* All RAG services must implement this interface
|
|
25
|
+
*/
|
|
26
|
+
export interface RAGService {
|
|
27
|
+
/**
|
|
28
|
+
* Search for relevant documents
|
|
29
|
+
*/
|
|
30
|
+
search(request: RAGSearchRequest): Promise<RAGSearchResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Optional: Add documents to the index
|
|
33
|
+
*/
|
|
34
|
+
addDocuments?(documents: RAGDocument[]): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Optional: Check if the service is available
|
|
37
|
+
*/
|
|
38
|
+
isAvailable?(): Promise<boolean>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=rag.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rag.types.d.ts","sourceRoot":"","sources":["../../src/types/rag.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9D;;OAEG;IACH,YAAY,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvD;;OAEG;IACH,WAAW,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rag.types.js","sourceRoot":"","sources":["../../src/types/rag.types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool System Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Tool execution status
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ToolExecutionStatus {
|
|
8
|
+
PENDING = "pending",
|
|
9
|
+
APPROVED = "approved",
|
|
10
|
+
REJECTED = "rejected",
|
|
11
|
+
EXECUTING = "executing",
|
|
12
|
+
COMPLETED = "completed",
|
|
13
|
+
FAILED = "failed"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Tool configuration
|
|
17
|
+
*/
|
|
18
|
+
export interface ToolConfig {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
parameters?: ToolParameter[];
|
|
22
|
+
requiresApproval?: boolean;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
retries?: number;
|
|
25
|
+
policy?: string;
|
|
26
|
+
metadata?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Tool parameter definition
|
|
30
|
+
*/
|
|
31
|
+
export interface ToolParameter {
|
|
32
|
+
name: string;
|
|
33
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
34
|
+
description: string;
|
|
35
|
+
required?: boolean;
|
|
36
|
+
default?: unknown;
|
|
37
|
+
enum?: unknown[];
|
|
38
|
+
validation?: (value: unknown) => boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Tool metadata stored via decorator
|
|
42
|
+
*/
|
|
43
|
+
export interface ToolMetadata extends ToolConfig {
|
|
44
|
+
target: object;
|
|
45
|
+
propertyKey: string;
|
|
46
|
+
method: Function;
|
|
47
|
+
agentClass?: new (...args: unknown[]) => unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Tool execution context
|
|
51
|
+
*/
|
|
52
|
+
export interface ToolExecutionContext {
|
|
53
|
+
executionId: string;
|
|
54
|
+
toolName: string;
|
|
55
|
+
agentId: string;
|
|
56
|
+
sessionId: string;
|
|
57
|
+
userId?: string;
|
|
58
|
+
input: Record<string, unknown>;
|
|
59
|
+
status: ToolExecutionStatus;
|
|
60
|
+
approvedBy?: string;
|
|
61
|
+
approvedAt?: Date;
|
|
62
|
+
startedAt: Date;
|
|
63
|
+
completedAt?: Date;
|
|
64
|
+
duration?: number;
|
|
65
|
+
metadata?: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Tool execution result
|
|
69
|
+
*/
|
|
70
|
+
export interface ToolExecutionResult {
|
|
71
|
+
success: boolean;
|
|
72
|
+
output?: unknown;
|
|
73
|
+
error?: Error;
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
75
|
+
duration: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Tool approval request
|
|
79
|
+
*/
|
|
80
|
+
export interface ToolApprovalRequest {
|
|
81
|
+
requestId: string;
|
|
82
|
+
executionId: string;
|
|
83
|
+
toolName: string;
|
|
84
|
+
agentId: string;
|
|
85
|
+
input: Record<string, unknown>;
|
|
86
|
+
reason?: string;
|
|
87
|
+
requestedAt: Date;
|
|
88
|
+
expiresAt?: Date;
|
|
89
|
+
metadata?: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Tool approval response
|
|
93
|
+
*/
|
|
94
|
+
export interface ToolApprovalResponse {
|
|
95
|
+
requestId: string;
|
|
96
|
+
approved: boolean;
|
|
97
|
+
approvedBy: string;
|
|
98
|
+
reason?: string;
|
|
99
|
+
approvedAt: Date;
|
|
100
|
+
modifications?: Record<string, unknown>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Tool definition for LLM
|
|
104
|
+
*/
|
|
105
|
+
export interface ToolDefinition {
|
|
106
|
+
name: string;
|
|
107
|
+
description: string;
|
|
108
|
+
parameters: {
|
|
109
|
+
type: 'object';
|
|
110
|
+
properties: Record<string, {
|
|
111
|
+
type: string;
|
|
112
|
+
description: string;
|
|
113
|
+
enum?: unknown[];
|
|
114
|
+
}>;
|
|
115
|
+
required: string[];
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=tool.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.types.d.ts","sourceRoot":"","sources":["../../src/types/tool.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,mBAAmB;IAC7B,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IAEpB,MAAM,EAAE,QAAQ,CAAC;IACjB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,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAChB,MAAM,EACN;YACE,IAAI,EAAE,MAAM,CAAC;YACb,WAAW,EAAE,MAAM,CAAC;YACpB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;SAClB,CACF,CAAC;QACF,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool System Types
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ToolExecutionStatus = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Tool execution status
|
|
9
|
+
*/
|
|
10
|
+
var ToolExecutionStatus;
|
|
11
|
+
(function (ToolExecutionStatus) {
|
|
12
|
+
ToolExecutionStatus["PENDING"] = "pending";
|
|
13
|
+
ToolExecutionStatus["APPROVED"] = "approved";
|
|
14
|
+
ToolExecutionStatus["REJECTED"] = "rejected";
|
|
15
|
+
ToolExecutionStatus["EXECUTING"] = "executing";
|
|
16
|
+
ToolExecutionStatus["COMPLETED"] = "completed";
|
|
17
|
+
ToolExecutionStatus["FAILED"] = "failed";
|
|
18
|
+
})(ToolExecutionStatus || (exports.ToolExecutionStatus = ToolExecutionStatus = {}));
|
|
19
|
+
//# sourceMappingURL=tool.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.types.js","sourceRoot":"","sources":["../../src/types/tool.types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,4CAAqB,CAAA;IACrB,4CAAqB,CAAA;IACrB,8CAAuB,CAAA;IACvB,8CAAuB,CAAA;IACvB,wCAAiB,CAAA;AACnB,CAAC,EAPW,mBAAmB,mCAAnB,mBAAmB,QAO9B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker Pattern
|
|
3
|
+
* Prevents cascading failures by stopping calls to failing services
|
|
4
|
+
*/
|
|
5
|
+
export declare enum CircuitState {
|
|
6
|
+
CLOSED = "CLOSED",
|
|
7
|
+
OPEN = "OPEN",
|
|
8
|
+
HALF_OPEN = "HALF_OPEN"
|
|
9
|
+
}
|
|
10
|
+
export interface CircuitBreakerConfig {
|
|
11
|
+
failureThreshold: number;
|
|
12
|
+
successThreshold: number;
|
|
13
|
+
timeout: number;
|
|
14
|
+
resetTimeout: number;
|
|
15
|
+
onStateChange?: (state: CircuitState) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare class CircuitBreakerError extends Error {
|
|
18
|
+
readonly state: CircuitState;
|
|
19
|
+
constructor(message: string, state: CircuitState);
|
|
20
|
+
}
|
|
21
|
+
export declare class CircuitBreaker {
|
|
22
|
+
private state;
|
|
23
|
+
private failureCount;
|
|
24
|
+
private successCount;
|
|
25
|
+
private nextAttempt;
|
|
26
|
+
private config;
|
|
27
|
+
constructor(config?: Partial<CircuitBreakerConfig>);
|
|
28
|
+
/**
|
|
29
|
+
* Execute a function with circuit breaker protection
|
|
30
|
+
*/
|
|
31
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Handle successful execution
|
|
34
|
+
*/
|
|
35
|
+
private onSuccess;
|
|
36
|
+
/**
|
|
37
|
+
* Handle failed execution
|
|
38
|
+
*/
|
|
39
|
+
private onFailure;
|
|
40
|
+
/**
|
|
41
|
+
* Transition to a new state
|
|
42
|
+
*/
|
|
43
|
+
private transitionTo;
|
|
44
|
+
/**
|
|
45
|
+
* Get current state
|
|
46
|
+
*/
|
|
47
|
+
getState(): CircuitState;
|
|
48
|
+
/**
|
|
49
|
+
* Get failure count
|
|
50
|
+
*/
|
|
51
|
+
getFailureCount(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get success count
|
|
54
|
+
*/
|
|
55
|
+
getSuccessCount(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Manually reset the circuit breaker
|
|
58
|
+
*/
|
|
59
|
+
reset(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get time until next attempt (for OPEN state)
|
|
62
|
+
*/
|
|
63
|
+
getTimeUntilNextAttempt(): number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Decorator for automatic circuit breaker
|
|
67
|
+
*/
|
|
68
|
+
export declare function WithCircuitBreaker(config?: Partial<CircuitBreakerConfig>): MethodDecorator;
|
|
69
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/utils/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,SAAS,cAAc;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CAC/C;AAED,qBAAa,mBAAoB,SAAQ,KAAK;aAG1B,KAAK,EAAE,YAAY;gBADnC,OAAO,EAAE,MAAM,EACC,KAAK,EAAE,YAAY;CAKtC;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,MAAM,CAAiC;gBAEnC,MAAM,GAAE,OAAO,CAAC,oBAAoB,CAAM;IAUtD;;OAEG;IACG,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA+BlD;;OAEG;IACH,OAAO,CAAC,SAAS;IAWjB;;OAEG;IACH,OAAO,CAAC,SAAS;IASjB;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;IACH,QAAQ,IAAI,YAAY;IAIxB;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,uBAAuB,IAAI,MAAM;CAMlC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,eAAe,CAY1F"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Circuit Breaker Pattern
|
|
4
|
+
* Prevents cascading failures by stopping calls to failing services
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CircuitBreaker = exports.CircuitBreakerError = exports.CircuitState = void 0;
|
|
8
|
+
exports.WithCircuitBreaker = WithCircuitBreaker;
|
|
9
|
+
var CircuitState;
|
|
10
|
+
(function (CircuitState) {
|
|
11
|
+
CircuitState["CLOSED"] = "CLOSED";
|
|
12
|
+
CircuitState["OPEN"] = "OPEN";
|
|
13
|
+
CircuitState["HALF_OPEN"] = "HALF_OPEN";
|
|
14
|
+
})(CircuitState || (exports.CircuitState = CircuitState = {}));
|
|
15
|
+
class CircuitBreakerError extends Error {
|
|
16
|
+
constructor(message, state) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.state = state;
|
|
19
|
+
this.name = 'CircuitBreakerError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CircuitBreakerError = CircuitBreakerError;
|
|
23
|
+
class CircuitBreaker {
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.state = CircuitState.CLOSED;
|
|
26
|
+
this.failureCount = 0;
|
|
27
|
+
this.successCount = 0;
|
|
28
|
+
this.nextAttempt = Date.now();
|
|
29
|
+
this.config = {
|
|
30
|
+
failureThreshold: config.failureThreshold ?? 5,
|
|
31
|
+
successThreshold: config.successThreshold ?? 2,
|
|
32
|
+
timeout: config.timeout ?? 60000,
|
|
33
|
+
resetTimeout: config.resetTimeout ?? 30000,
|
|
34
|
+
onStateChange: config.onStateChange ?? (() => { }),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Execute a function with circuit breaker protection
|
|
39
|
+
*/
|
|
40
|
+
async execute(fn) {
|
|
41
|
+
if (this.state === CircuitState.OPEN) {
|
|
42
|
+
if (Date.now() < this.nextAttempt) {
|
|
43
|
+
throw new CircuitBreakerError('Circuit breaker is OPEN - service unavailable', this.state);
|
|
44
|
+
}
|
|
45
|
+
this.transitionTo(CircuitState.HALF_OPEN);
|
|
46
|
+
}
|
|
47
|
+
let timeoutId;
|
|
48
|
+
try {
|
|
49
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
50
|
+
timeoutId = setTimeout(() => reject(new Error('Circuit breaker timeout')), this.config.timeout);
|
|
51
|
+
});
|
|
52
|
+
const result = await Promise.race([fn(), timeoutPromise]);
|
|
53
|
+
this.onSuccess();
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
this.onFailure();
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
if (timeoutId) {
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Handle successful execution
|
|
68
|
+
*/
|
|
69
|
+
onSuccess() {
|
|
70
|
+
this.failureCount = 0;
|
|
71
|
+
if (this.state === CircuitState.HALF_OPEN) {
|
|
72
|
+
this.successCount++;
|
|
73
|
+
if (this.successCount >= this.config.successThreshold) {
|
|
74
|
+
this.transitionTo(CircuitState.CLOSED);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Handle failed execution
|
|
80
|
+
*/
|
|
81
|
+
onFailure() {
|
|
82
|
+
this.failureCount++;
|
|
83
|
+
this.successCount = 0;
|
|
84
|
+
if (this.failureCount >= this.config.failureThreshold) {
|
|
85
|
+
this.transitionTo(CircuitState.OPEN);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Transition to a new state
|
|
90
|
+
*/
|
|
91
|
+
transitionTo(newState) {
|
|
92
|
+
if (this.state === newState) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.state = newState;
|
|
96
|
+
if (newState === CircuitState.OPEN) {
|
|
97
|
+
this.nextAttempt = Date.now() + this.config.resetTimeout;
|
|
98
|
+
}
|
|
99
|
+
else if (newState === CircuitState.CLOSED) {
|
|
100
|
+
this.failureCount = 0;
|
|
101
|
+
this.successCount = 0;
|
|
102
|
+
}
|
|
103
|
+
else if (newState === CircuitState.HALF_OPEN) {
|
|
104
|
+
this.successCount = 0;
|
|
105
|
+
}
|
|
106
|
+
this.config.onStateChange(newState);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get current state
|
|
110
|
+
*/
|
|
111
|
+
getState() {
|
|
112
|
+
return this.state;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get failure count
|
|
116
|
+
*/
|
|
117
|
+
getFailureCount() {
|
|
118
|
+
return this.failureCount;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get success count
|
|
122
|
+
*/
|
|
123
|
+
getSuccessCount() {
|
|
124
|
+
return this.successCount;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Manually reset the circuit breaker
|
|
128
|
+
*/
|
|
129
|
+
reset() {
|
|
130
|
+
this.transitionTo(CircuitState.CLOSED);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get time until next attempt (for OPEN state)
|
|
134
|
+
*/
|
|
135
|
+
getTimeUntilNextAttempt() {
|
|
136
|
+
if (this.state !== CircuitState.OPEN) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
return Math.max(0, this.nextAttempt - Date.now());
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.CircuitBreaker = CircuitBreaker;
|
|
143
|
+
/**
|
|
144
|
+
* Decorator for automatic circuit breaker
|
|
145
|
+
*/
|
|
146
|
+
function WithCircuitBreaker(config) {
|
|
147
|
+
const circuitBreaker = new CircuitBreaker(config);
|
|
148
|
+
return function (target, propertyKey, descriptor) {
|
|
149
|
+
const originalMethod = descriptor.value;
|
|
150
|
+
descriptor.value = async function (...args) {
|
|
151
|
+
return circuitBreaker.execute(() => originalMethod.apply(this, args));
|
|
152
|
+
};
|
|
153
|
+
return descriptor;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../src/utils/circuit-breaker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAuKH,gDAYC;AAjLD,IAAY,YAIX;AAJD,WAAY,YAAY;I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CAAC;CACF;AAxID,wCAwIC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,MAAsC;IACvE,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;IAElD,OAAO,UAAU,MAAc,EAAE,WAA4B,EAAE,UAA8B;QAC3F,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAe;YACnD,OAAO,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACxE,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health Check System
|
|
3
|
+
* Monitor agent runtime health and dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { LLMProvider } from '../types/llm.types';
|
|
6
|
+
import { RAGService } from '../types/rag.types';
|
|
7
|
+
export declare enum HealthStatus {
|
|
8
|
+
HEALTHY = "healthy",
|
|
9
|
+
DEGRADED = "degraded",
|
|
10
|
+
UNHEALTHY = "unhealthy"
|
|
11
|
+
}
|
|
12
|
+
export interface ComponentHealth {
|
|
13
|
+
status: HealthStatus;
|
|
14
|
+
message?: string;
|
|
15
|
+
latencyMs?: number;
|
|
16
|
+
lastCheck?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface HealthCheckResult {
|
|
19
|
+
status: HealthStatus;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
uptime: number;
|
|
22
|
+
components: {
|
|
23
|
+
llmProvider?: ComponentHealth;
|
|
24
|
+
ragService?: ComponentHealth;
|
|
25
|
+
memory?: ComponentHealth;
|
|
26
|
+
};
|
|
27
|
+
metrics?: {
|
|
28
|
+
totalExecutions: number;
|
|
29
|
+
successRate: number;
|
|
30
|
+
averageLatency: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface HealthCheckConfig {
|
|
34
|
+
checkIntervalMs?: number;
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
}
|
|
37
|
+
export declare class HealthChecker {
|
|
38
|
+
private startTime;
|
|
39
|
+
private lastCheck?;
|
|
40
|
+
private config;
|
|
41
|
+
constructor(config?: HealthCheckConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Perform a health check
|
|
44
|
+
*/
|
|
45
|
+
check(llmProvider?: LLMProvider, ragService?: RAGService, metrics?: {
|
|
46
|
+
totalExecutions: number;
|
|
47
|
+
successRate: number;
|
|
48
|
+
averageLatency: number;
|
|
49
|
+
}): Promise<HealthCheckResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Check a single component
|
|
52
|
+
*/
|
|
53
|
+
private checkComponent;
|
|
54
|
+
/**
|
|
55
|
+
* Determine overall status from component statuses
|
|
56
|
+
*/
|
|
57
|
+
private determineOverallStatus;
|
|
58
|
+
/**
|
|
59
|
+
* Get last health check result
|
|
60
|
+
*/
|
|
61
|
+
getLastCheck(): HealthCheckResult | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get uptime in seconds
|
|
64
|
+
*/
|
|
65
|
+
getUptime(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Format health check result as string
|
|
68
|
+
*/
|
|
69
|
+
formatResult(result: HealthCheckResult): string;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=health-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health-check.d.ts","sourceRoot":"","sources":["../../src/utils/health-check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,SAAS,cAAc;CACxB;AAED,MAAM,WAAW,eAAe;I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