@hazeljs/agent 0.2.0-beta.8 → 0.2.0-beta.81
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/LICENSE +192 -21
- package/README.md +372 -258
- package/coverage/clover.xml +853 -576
- package/coverage/lcov-report/index.html +107 -62
- package/coverage/lcov.info +1428 -945
- package/dist/agent.module.d.ts +16 -1
- package/dist/agent.module.d.ts.map +1 -1
- package/dist/agent.module.js +14 -5
- package/dist/agent.module.js.map +1 -1
- package/dist/decorators/delegate.decorator.d.ts +66 -0
- package/dist/decorators/delegate.decorator.d.ts.map +1 -0
- package/dist/decorators/delegate.decorator.js +108 -0
- package/dist/decorators/delegate.decorator.js.map +1 -0
- package/dist/executor/agent.executor.d.ts +1 -0
- package/dist/executor/agent.executor.d.ts.map +1 -1
- package/dist/executor/agent.executor.js +19 -10
- package/dist/executor/agent.executor.js.map +1 -1
- package/dist/executor/tool.executor.d.ts +3 -1
- package/dist/executor/tool.executor.d.ts.map +1 -1
- package/dist/executor/tool.executor.js +33 -2
- package/dist/executor/tool.executor.js.map +1 -1
- package/dist/graph/agent-graph.d.ts +131 -0
- package/dist/graph/agent-graph.d.ts.map +1 -0
- package/dist/graph/agent-graph.js +462 -0
- package/dist/graph/agent-graph.js.map +1 -0
- package/dist/graph/agent-graph.types.d.ts +210 -0
- package/dist/graph/agent-graph.types.d.ts.map +1 -0
- package/dist/graph/agent-graph.types.js +12 -0
- package/dist/graph/agent-graph.types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/prompts/agent-system.prompt.d.ts +10 -0
- package/dist/prompts/agent-system.prompt.d.ts.map +1 -0
- package/dist/prompts/agent-system.prompt.js +18 -0
- package/dist/prompts/agent-system.prompt.js.map +1 -0
- package/dist/prompts/index.d.ts +4 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +20 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/supervisor-routing.prompt.d.ts +9 -0
- package/dist/prompts/supervisor-routing.prompt.d.ts.map +1 -0
- package/dist/prompts/supervisor-routing.prompt.js +22 -0
- package/dist/prompts/supervisor-routing.prompt.js.map +1 -0
- package/dist/prompts/supervisor-system.prompt.d.ts +9 -0
- package/dist/prompts/supervisor-system.prompt.d.ts.map +1 -0
- package/dist/prompts/supervisor-system.prompt.js +21 -0
- package/dist/prompts/supervisor-system.prompt.js.map +1 -0
- package/dist/runtime/agent.runtime.d.ts +65 -2
- package/dist/runtime/agent.runtime.d.ts.map +1 -1
- package/dist/runtime/agent.runtime.js +105 -4
- package/dist/runtime/agent.runtime.js.map +1 -1
- package/dist/supervisor/supervisor.d.ts +81 -0
- package/dist/supervisor/supervisor.d.ts.map +1 -0
- package/dist/supervisor/supervisor.js +220 -0
- package/dist/supervisor/supervisor.js.map +1 -0
- package/dist/types/agent.types.d.ts +15 -0
- package/dist/types/agent.types.d.ts.map +1 -1
- package/dist/types/agent.types.js.map +1 -1
- package/dist/types/event.types.d.ts +76 -1
- package/dist/types/event.types.d.ts.map +1 -1
- package/dist/types/event.types.js +16 -0
- package/dist/types/event.types.js.map +1 -1
- package/dist/utils/circuit-breaker.d.ts +5 -65
- package/dist/utils/circuit-breaker.d.ts.map +1 -1
- package/dist/utils/circuit-breaker.js +10 -150
- package/dist/utils/circuit-breaker.js.map +1 -1
- package/logs/combined.log +1 -1
- package/package.json +23 -8
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.types.d.ts","sourceRoot":"","sources":["../../src/types/event.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,cAAc;IACxB,iBAAiB,4BAA4B;IAC7C,mBAAmB,8BAA8B;IACjD,gBAAgB,2BAA2B;IAC3C,YAAY,uBAAuB;IACnC,cAAc,yBAAyB;IACvC,WAAW,sBAAsB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MEMORY_UPDATED"] = "agent.memory.updated";
|
|
28
28
|
AgentEventType["RAG_QUERY_EXECUTED"] = "agent.rag.executed";
|
|
29
|
+
// Graph orchestration events
|
|
30
|
+
AgentEventType["GRAPH_STARTED"] = "graph.started";
|
|
31
|
+
AgentEventType["GRAPH_COMPLETED"] = "graph.completed";
|
|
32
|
+
AgentEventType["GRAPH_FAILED"] = "graph.failed";
|
|
33
|
+
AgentEventType["GRAPH_NODE_STARTED"] = "graph.node.started";
|
|
34
|
+
AgentEventType["GRAPH_NODE_COMPLETED"] = "graph.node.completed";
|
|
35
|
+
AgentEventType["GRAPH_NODE_FAILED"] = "graph.node.failed";
|
|
36
|
+
AgentEventType["GRAPH_PARALLEL_STARTED"] = "graph.parallel.started";
|
|
37
|
+
AgentEventType["GRAPH_PARALLEL_COMPLETED"] = "graph.parallel.completed";
|
|
38
|
+
// Supervisor events
|
|
39
|
+
AgentEventType["SUPERVISOR_ROUND_STARTED"] = "supervisor.round.started";
|
|
40
|
+
AgentEventType["SUPERVISOR_DELEGATED"] = "supervisor.delegated";
|
|
41
|
+
AgentEventType["SUPERVISOR_FINISHED"] = "supervisor.finished";
|
|
42
|
+
// Agent delegation events (agent-as-tool)
|
|
43
|
+
AgentEventType["DELEGATE_STARTED"] = "agent.delegate.started";
|
|
44
|
+
AgentEventType["DELEGATE_COMPLETED"] = "agent.delegate.completed";
|
|
29
45
|
})(AgentEventType || (exports.AgentEventType = AgentEventType = {}));
|
|
30
46
|
//# sourceMappingURL=event.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.types.js","sourceRoot":"","sources":["../../src/types/event.types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,IAAY,
|
|
1
|
+
{"version":3,"file":"event.types.js","sourceRoot":"","sources":["../../src/types/event.types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,IAAY,cAqCX;AArCD,WAAY,cAAc;IACxB,+DAA6C,CAAA;IAC7C,mEAAiD,CAAA;IACjD,6DAA2C,CAAA;IAC3C,qDAAmC,CAAA;IACnC,yDAAuC,CAAA;IACvC,mDAAiC,CAAA;IACjC,uDAAqC,CAAA;IACrC,mEAAiD,CAAA;IACjD,uEAAqD,CAAA;IACrD,iEAA+C,CAAA;IAC/C,qEAAmD,CAAA;IACnD,iEAA+C,CAAA;IAC/C,+DAA6C,CAAA;IAC7C,gEAA8C,CAAA;IAC9C,8DAA4C,CAAA;IAC5C,yDAAuC,CAAA;IACvC,2DAAyC,CAAA;IAEzC,6BAA6B;IAC7B,iDAA+B,CAAA;IAC/B,qDAAmC,CAAA;IACnC,+CAA6B,CAAA;IAC7B,2DAAyC,CAAA;IACzC,+DAA6C,CAAA;IAC7C,yDAAuC,CAAA;IACvC,mEAAiD,CAAA;IACjD,uEAAqD,CAAA;IAErD,oBAAoB;IACpB,uEAAqD,CAAA;IACrD,+DAA6C,CAAA;IAC7C,6DAA2C,CAAA;IAE3C,0CAA0C;IAC1C,6DAA2C,CAAA;IAC3C,iEAA+C,CAAA;AACjD,CAAC,EArCW,cAAc,8BAAd,cAAc,QAqCzB"}
|
|
@@ -1,69 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Circuit Breaker Pattern
|
|
3
|
-
*
|
|
3
|
+
* Re-exports from @hazeljs/resilience for backward compatibility.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Import directly from '@hazeljs/resilience' instead.
|
|
6
|
+
* This module is kept for backward compatibility with existing agent code.
|
|
4
7
|
*/
|
|
5
|
-
export
|
|
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;
|
|
8
|
+
export { CircuitState, CircuitBreakerError, CircuitBreaker, CircuitBreakerConfig, WithCircuitBreaker, } from '@hazeljs/resilience';
|
|
69
9
|
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/utils/circuit-breaker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/utils/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,156 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Circuit Breaker Pattern
|
|
4
|
-
*
|
|
4
|
+
* Re-exports from @hazeljs/resilience for backward compatibility.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Import directly from '@hazeljs/resilience' instead.
|
|
7
|
+
* This module is kept for backward compatibility with existing agent code.
|
|
5
8
|
*/
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.CircuitBreaker = exports.CircuitBreakerError = exports.CircuitState = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(function (
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
}
|
|
10
|
+
exports.WithCircuitBreaker = exports.CircuitBreaker = exports.CircuitBreakerError = exports.CircuitState = void 0;
|
|
11
|
+
var resilience_1 = require("@hazeljs/resilience");
|
|
12
|
+
Object.defineProperty(exports, "CircuitState", { enumerable: true, get: function () { return resilience_1.CircuitState; } });
|
|
13
|
+
Object.defineProperty(exports, "CircuitBreakerError", { enumerable: true, get: function () { return resilience_1.CircuitBreakerError; } });
|
|
14
|
+
Object.defineProperty(exports, "CircuitBreaker", { enumerable: true, get: function () { return resilience_1.CircuitBreaker; } });
|
|
15
|
+
Object.defineProperty(exports, "WithCircuitBreaker", { enumerable: true, get: function () { return resilience_1.WithCircuitBreaker; } });
|
|
156
16
|
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../src/utils/circuit-breaker.ts"],"names":[],"mappings":";AAAA;;;
|
|
1
|
+
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../src/utils/circuit-breaker.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,kDAM6B;AAL3B,0GAAA,YAAY,OAAA;AACZ,iHAAA,mBAAmB,OAAA;AACnB,4GAAA,cAAc,OAAA;AAEd,gHAAA,kBAAkB,OAAA"}
|
package/logs/combined.log
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2026-
|
|
1
|
+
2026-03-08 00:20:08 [INFO] Application started | {"service":"hazeljs","version":"0.1.0","environment":"test"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/agent",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.81",
|
|
4
4
|
"description": "AI-native Agent Runtime for HazelJS - stateful, long-running agents with tools, memory, and human-in-the-loop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,16 +22,21 @@
|
|
|
22
22
|
"memory",
|
|
23
23
|
"human-in-the-loop"
|
|
24
24
|
],
|
|
25
|
-
"author": "
|
|
26
|
-
"license": "
|
|
25
|
+
"author": "Muhammad Arslan <muhammad.arslan@hazeljs.com>",
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
29
|
"url": "https://github.com/hazeljs/hazeljs",
|
|
30
30
|
"directory": "packages/agent"
|
|
31
31
|
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@hazeljs/core": "^0.2.0-beta.
|
|
34
|
-
"@hazeljs/
|
|
36
|
+
"@hazeljs/core": "^0.2.0-beta.81",
|
|
37
|
+
"@hazeljs/prompts": "^0.2.0-beta.81",
|
|
38
|
+
"@hazeljs/rag": "^0.2.0-beta.81",
|
|
39
|
+
"@hazeljs/resilience": "^0.2.0-beta.81",
|
|
35
40
|
"reflect-metadata": "^0.2.1"
|
|
36
41
|
},
|
|
37
42
|
"devDependencies": {
|
|
@@ -42,8 +47,10 @@
|
|
|
42
47
|
"typescript": "^5.3.3"
|
|
43
48
|
},
|
|
44
49
|
"peerDependencies": {
|
|
45
|
-
"@hazeljs/core": ">=0.2.0",
|
|
46
|
-
"@hazeljs/
|
|
50
|
+
"@hazeljs/core": ">=0.2.0-beta.0",
|
|
51
|
+
"@hazeljs/guardrails": ">=0.2.0-beta.0",
|
|
52
|
+
"@hazeljs/rag": ">=0.1.0",
|
|
53
|
+
"redis": ">=4.0.0"
|
|
47
54
|
},
|
|
48
55
|
"peerDependenciesMeta": {
|
|
49
56
|
"redis": {
|
|
@@ -53,7 +60,15 @@
|
|
|
53
60
|
"@prisma/client": {
|
|
54
61
|
"optional": true,
|
|
55
62
|
"description": "Required for DatabaseStateManager"
|
|
63
|
+
},
|
|
64
|
+
"@hazeljs/guardrails": {
|
|
65
|
+
"optional": true,
|
|
66
|
+
"description": "Optional guardrails for tool input/output validation"
|
|
56
67
|
}
|
|
57
68
|
},
|
|
58
|
-
"
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
71
|
+
},
|
|
72
|
+
"homepage": "https://hazeljs.com",
|
|
73
|
+
"gitHead": "1054f957451360f973469d436a1d58e57cc9231a"
|
|
59
74
|
}
|