@reactive-agents/core 0.1.0
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 +21 -0
- package/README.md +50 -0
- package/dist/index.d.ts +421 -0
- package/dist/index.js +555 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tyler Buell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @reactive-agents/core
|
|
2
|
+
|
|
3
|
+
Core services and types for the [Reactive Agents](https://tylerjrbuell.github.io/reactive-agents-ts/) framework.
|
|
4
|
+
|
|
5
|
+
Provides the foundational building blocks that all other packages depend on: the EventBus, AgentService, TaskService, and shared schemas.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @reactive-agents/core effect
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install everything at once:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add reactive-agents effect
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What's Included
|
|
20
|
+
|
|
21
|
+
| Export | Description |
|
|
22
|
+
|--------|-------------|
|
|
23
|
+
| `EventBusLive` | Publish/subscribe event bus layer |
|
|
24
|
+
| `AgentServiceLive` | Create and manage agent instances |
|
|
25
|
+
| `TaskServiceLive` | Create, track, and cancel tasks |
|
|
26
|
+
| `CoreServicesLive` | Composite layer wiring all three above |
|
|
27
|
+
| `AgentId`, `TaskId` | Branded ID types |
|
|
28
|
+
| `AgentConfig`, `TaskInput` | Validated schemas |
|
|
29
|
+
| `AgentError`, `TaskError` | Tagged error types |
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Effect } from "effect";
|
|
35
|
+
import { CoreServicesLive, AgentService } from "@reactive-agents/core";
|
|
36
|
+
|
|
37
|
+
const program = Effect.gen(function* () {
|
|
38
|
+
const agents = yield* AgentService;
|
|
39
|
+
const agent = yield* agents.create({ name: "my-agent", capabilities: [] });
|
|
40
|
+
return agent;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const result = await Effect.runPromise(
|
|
44
|
+
program.pipe(Effect.provide(CoreServicesLive))
|
|
45
|
+
);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
|
|
50
|
+
Full documentation at [tylerjrbuell.github.io/reactive-agents-ts](https://tylerjrbuell.github.io/reactive-agents-ts/)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { Schema, Context, Effect, Layer } from 'effect';
|
|
2
|
+
import * as effect_Cause from 'effect/Cause';
|
|
3
|
+
import * as effect_Types from 'effect/Types';
|
|
4
|
+
|
|
5
|
+
declare const AgentId: Schema.brand<typeof Schema.String, "AgentId">;
|
|
6
|
+
type AgentId = typeof AgentId.Type;
|
|
7
|
+
declare const CapabilityType: Schema.Literal<["tool", "skill", "reasoning", "memory"]>;
|
|
8
|
+
type CapabilityType = typeof CapabilityType.Type;
|
|
9
|
+
declare const CapabilitySchema: Schema.Struct<{
|
|
10
|
+
type: Schema.Literal<["tool", "skill", "reasoning", "memory"]>;
|
|
11
|
+
name: typeof Schema.String;
|
|
12
|
+
}>;
|
|
13
|
+
type Capability = typeof CapabilitySchema.Type;
|
|
14
|
+
declare const ReasoningStrategy: Schema.Literal<["reactive", "plan-execute-reflect", "tree-of-thought", "reflexion", "adaptive"]>;
|
|
15
|
+
type ReasoningStrategy = typeof ReasoningStrategy.Type;
|
|
16
|
+
declare const MemoryType: Schema.Literal<["semantic", "episodic", "procedural", "working"]>;
|
|
17
|
+
type MemoryType = typeof MemoryType.Type;
|
|
18
|
+
declare const AgentSchema: Schema.Struct<{
|
|
19
|
+
id: Schema.brand<typeof Schema.String, "AgentId">;
|
|
20
|
+
name: typeof Schema.String;
|
|
21
|
+
description: Schema.optional<typeof Schema.String>;
|
|
22
|
+
capabilities: Schema.Array$<Schema.Struct<{
|
|
23
|
+
type: Schema.Literal<["tool", "skill", "reasoning", "memory"]>;
|
|
24
|
+
name: typeof Schema.String;
|
|
25
|
+
}>>;
|
|
26
|
+
config: typeof Schema.Unknown;
|
|
27
|
+
state: typeof Schema.Unknown;
|
|
28
|
+
createdAt: typeof Schema.DateFromSelf;
|
|
29
|
+
updatedAt: typeof Schema.DateFromSelf;
|
|
30
|
+
}>;
|
|
31
|
+
type Agent = typeof AgentSchema.Type;
|
|
32
|
+
declare const AgentConfigSchema: Schema.Struct<{
|
|
33
|
+
name: typeof Schema.String;
|
|
34
|
+
description: Schema.optional<typeof Schema.String>;
|
|
35
|
+
capabilities: Schema.Array$<Schema.Struct<{
|
|
36
|
+
type: Schema.Literal<["tool", "skill", "reasoning", "memory"]>;
|
|
37
|
+
name: typeof Schema.String;
|
|
38
|
+
}>>;
|
|
39
|
+
config: Schema.optional<typeof Schema.Unknown>;
|
|
40
|
+
initialState: Schema.optional<typeof Schema.Unknown>;
|
|
41
|
+
}>;
|
|
42
|
+
type AgentConfig = typeof AgentConfigSchema.Type;
|
|
43
|
+
|
|
44
|
+
declare const TaskId: Schema.brand<typeof Schema.String, "TaskId">;
|
|
45
|
+
type TaskId = typeof TaskId.Type;
|
|
46
|
+
declare const TaskType: Schema.Literal<["query", "action", "workflow", "research", "delegation"]>;
|
|
47
|
+
type TaskType = typeof TaskType.Type;
|
|
48
|
+
declare const Priority: Schema.Literal<["low", "medium", "high", "critical"]>;
|
|
49
|
+
type Priority = typeof Priority.Type;
|
|
50
|
+
declare const TaskStatus: Schema.Literal<["pending", "running", "paused", "completed", "failed", "cancelled"]>;
|
|
51
|
+
type TaskStatus = typeof TaskStatus.Type;
|
|
52
|
+
declare const TaskMetadataSchema: Schema.Struct<{
|
|
53
|
+
maxDuration: Schema.optional<typeof Schema.Number>;
|
|
54
|
+
maxCost: Schema.optional<typeof Schema.Number>;
|
|
55
|
+
requiresApproval: Schema.optional<typeof Schema.Boolean>;
|
|
56
|
+
tags: Schema.optional<Schema.Array$<typeof Schema.String>>;
|
|
57
|
+
context: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
58
|
+
}>;
|
|
59
|
+
type TaskMetadata = typeof TaskMetadataSchema.Type;
|
|
60
|
+
declare const TaskSchema: Schema.Struct<{
|
|
61
|
+
id: Schema.brand<typeof Schema.String, "TaskId">;
|
|
62
|
+
agentId: Schema.brand<typeof Schema.String, "AgentId">;
|
|
63
|
+
type: Schema.Literal<["query", "action", "workflow", "research", "delegation"]>;
|
|
64
|
+
input: typeof Schema.Unknown;
|
|
65
|
+
priority: Schema.Literal<["low", "medium", "high", "critical"]>;
|
|
66
|
+
status: Schema.Literal<["pending", "running", "paused", "completed", "failed", "cancelled"]>;
|
|
67
|
+
metadata: Schema.Struct<{
|
|
68
|
+
maxDuration: Schema.optional<typeof Schema.Number>;
|
|
69
|
+
maxCost: Schema.optional<typeof Schema.Number>;
|
|
70
|
+
requiresApproval: Schema.optional<typeof Schema.Boolean>;
|
|
71
|
+
tags: Schema.optional<Schema.Array$<typeof Schema.String>>;
|
|
72
|
+
context: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
73
|
+
}>;
|
|
74
|
+
createdAt: typeof Schema.DateFromSelf;
|
|
75
|
+
startedAt: Schema.optional<typeof Schema.DateFromSelf>;
|
|
76
|
+
completedAt: Schema.optional<typeof Schema.DateFromSelf>;
|
|
77
|
+
}>;
|
|
78
|
+
type Task = typeof TaskSchema.Type;
|
|
79
|
+
declare const TaskConfigSchema: Schema.Struct<{
|
|
80
|
+
agentId: Schema.brand<typeof Schema.String, "AgentId">;
|
|
81
|
+
type: Schema.Literal<["query", "action", "workflow", "research", "delegation"]>;
|
|
82
|
+
input: typeof Schema.Unknown;
|
|
83
|
+
priority: Schema.optional<Schema.Literal<["low", "medium", "high", "critical"]>>;
|
|
84
|
+
metadata: Schema.optional<Schema.Struct<{
|
|
85
|
+
maxDuration: Schema.optional<typeof Schema.Number>;
|
|
86
|
+
maxCost: Schema.optional<typeof Schema.Number>;
|
|
87
|
+
requiresApproval: Schema.optional<typeof Schema.Boolean>;
|
|
88
|
+
tags: Schema.optional<Schema.Array$<typeof Schema.String>>;
|
|
89
|
+
context: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
90
|
+
}>>;
|
|
91
|
+
}>;
|
|
92
|
+
type TaskConfig = typeof TaskConfigSchema.Type;
|
|
93
|
+
|
|
94
|
+
declare const StepType: Schema.Literal<["thought", "action", "observation", "plan", "reflection", "critique"]>;
|
|
95
|
+
type StepType = typeof StepType.Type;
|
|
96
|
+
declare const ReasoningStepSchema: Schema.Struct<{
|
|
97
|
+
id: typeof Schema.String;
|
|
98
|
+
type: Schema.Literal<["thought", "action", "observation", "plan", "reflection", "critique"]>;
|
|
99
|
+
content: typeof Schema.String;
|
|
100
|
+
timestamp: typeof Schema.DateFromSelf;
|
|
101
|
+
metadata: Schema.optional<Schema.Struct<{
|
|
102
|
+
confidence: Schema.optional<typeof Schema.Number>;
|
|
103
|
+
toolUsed: Schema.optional<typeof Schema.String>;
|
|
104
|
+
cost: Schema.optional<typeof Schema.Number>;
|
|
105
|
+
duration: Schema.optional<typeof Schema.Number>;
|
|
106
|
+
}>>;
|
|
107
|
+
}>;
|
|
108
|
+
type ReasoningStep = typeof ReasoningStepSchema.Type;
|
|
109
|
+
declare const ResultMetadataSchema: Schema.Struct<{
|
|
110
|
+
duration: typeof Schema.Number;
|
|
111
|
+
cost: typeof Schema.Number;
|
|
112
|
+
tokensUsed: typeof Schema.Number;
|
|
113
|
+
confidence: Schema.optional<Schema.filter<typeof Schema.Number>>;
|
|
114
|
+
strategyUsed: Schema.optional<typeof Schema.String>;
|
|
115
|
+
stepsCount: Schema.optional<typeof Schema.Number>;
|
|
116
|
+
}>;
|
|
117
|
+
type ResultMetadata = typeof ResultMetadataSchema.Type;
|
|
118
|
+
declare const TaskResultSchema: Schema.Struct<{
|
|
119
|
+
taskId: Schema.brand<typeof Schema.String, "TaskId">;
|
|
120
|
+
agentId: Schema.brand<typeof Schema.String, "AgentId">;
|
|
121
|
+
output: typeof Schema.Unknown;
|
|
122
|
+
success: typeof Schema.Boolean;
|
|
123
|
+
error: Schema.optional<typeof Schema.String>;
|
|
124
|
+
metadata: Schema.Struct<{
|
|
125
|
+
duration: typeof Schema.Number;
|
|
126
|
+
cost: typeof Schema.Number;
|
|
127
|
+
tokensUsed: typeof Schema.Number;
|
|
128
|
+
confidence: Schema.optional<Schema.filter<typeof Schema.Number>>;
|
|
129
|
+
strategyUsed: Schema.optional<typeof Schema.String>;
|
|
130
|
+
stepsCount: Schema.optional<typeof Schema.Number>;
|
|
131
|
+
}>;
|
|
132
|
+
completedAt: typeof Schema.DateFromSelf;
|
|
133
|
+
}>;
|
|
134
|
+
type TaskResult = typeof TaskResultSchema.Type;
|
|
135
|
+
|
|
136
|
+
declare const MessageId: Schema.brand<typeof Schema.String, "MessageId">;
|
|
137
|
+
type MessageId = typeof MessageId.Type;
|
|
138
|
+
declare const MessageType: Schema.Literal<["request", "response", "notification", "delegation", "query"]>;
|
|
139
|
+
type MessageType = typeof MessageType.Type;
|
|
140
|
+
declare const MessageSchema: Schema.Struct<{
|
|
141
|
+
id: Schema.brand<typeof Schema.String, "MessageId">;
|
|
142
|
+
fromAgentId: Schema.brand<typeof Schema.String, "AgentId">;
|
|
143
|
+
toAgentId: Schema.brand<typeof Schema.String, "AgentId">;
|
|
144
|
+
type: Schema.Literal<["request", "response", "notification", "delegation", "query"]>;
|
|
145
|
+
content: typeof Schema.Unknown;
|
|
146
|
+
timestamp: typeof Schema.DateFromSelf;
|
|
147
|
+
metadata: Schema.optional<Schema.Struct<{
|
|
148
|
+
correlationId: Schema.optional<typeof Schema.String>;
|
|
149
|
+
causationId: Schema.optional<typeof Schema.String>;
|
|
150
|
+
context: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
|
|
151
|
+
}>>;
|
|
152
|
+
}>;
|
|
153
|
+
type Message = typeof MessageSchema.Type;
|
|
154
|
+
|
|
155
|
+
declare const LogLevel: Schema.Literal<["debug", "info", "warn", "error"]>;
|
|
156
|
+
type LogLevel = typeof LogLevel.Type;
|
|
157
|
+
declare const TelemetryConfigSchema: Schema.Struct<{
|
|
158
|
+
enabled: typeof Schema.Boolean;
|
|
159
|
+
endpoint: Schema.optional<typeof Schema.String>;
|
|
160
|
+
serviceName: typeof Schema.String;
|
|
161
|
+
sampleRate: Schema.filter<typeof Schema.Number>;
|
|
162
|
+
}>;
|
|
163
|
+
type TelemetryConfig = typeof TelemetryConfigSchema.Type;
|
|
164
|
+
declare const RuntimeConfigSchema: Schema.Struct<{
|
|
165
|
+
maxConcurrentTasks: typeof Schema.Number;
|
|
166
|
+
taskTimeout: typeof Schema.Number;
|
|
167
|
+
maxRetries: typeof Schema.Number;
|
|
168
|
+
retryDelay: typeof Schema.Number;
|
|
169
|
+
logLevel: Schema.Literal<["debug", "info", "warn", "error"]>;
|
|
170
|
+
telemetry: Schema.Struct<{
|
|
171
|
+
enabled: typeof Schema.Boolean;
|
|
172
|
+
endpoint: Schema.optional<typeof Schema.String>;
|
|
173
|
+
serviceName: typeof Schema.String;
|
|
174
|
+
sampleRate: Schema.filter<typeof Schema.Number>;
|
|
175
|
+
}>;
|
|
176
|
+
}>;
|
|
177
|
+
type RuntimeConfig = typeof RuntimeConfigSchema.Type;
|
|
178
|
+
declare const defaultRuntimeConfig: RuntimeConfig;
|
|
179
|
+
declare const ContextControllerSchema: Schema.Struct<{
|
|
180
|
+
prioritization: Schema.optional<Schema.Literal<["semantic", "recency", "importance"]>>;
|
|
181
|
+
pruning: Schema.optional<Schema.Literal<["adaptive", "sliding-window", "fifo"]>>;
|
|
182
|
+
retention: Schema.optional<Schema.Array$<typeof Schema.String>>;
|
|
183
|
+
compression: Schema.optional<Schema.Literal<["none", "aggressive", "adaptive"]>>;
|
|
184
|
+
}>;
|
|
185
|
+
type ContextController = typeof ContextControllerSchema.Type;
|
|
186
|
+
declare const CircuitBreakerConfigSchema: Schema.Struct<{
|
|
187
|
+
errorThreshold: Schema.filter<typeof Schema.Number>;
|
|
188
|
+
timeout: typeof Schema.Number;
|
|
189
|
+
resetTimeout: typeof Schema.Number;
|
|
190
|
+
}>;
|
|
191
|
+
type CircuitBreakerConfig = typeof CircuitBreakerConfigSchema.Type;
|
|
192
|
+
declare const TokenBudgetConfigSchema: Schema.Struct<{
|
|
193
|
+
total: typeof Schema.Number;
|
|
194
|
+
allocation: Schema.optional<Schema.Struct<{
|
|
195
|
+
system: Schema.optional<typeof Schema.Number>;
|
|
196
|
+
context: Schema.optional<typeof Schema.Number>;
|
|
197
|
+
reasoning: Schema.optional<typeof Schema.Number>;
|
|
198
|
+
output: Schema.optional<typeof Schema.Number>;
|
|
199
|
+
}>>;
|
|
200
|
+
enforcement: Schema.Literal<["hard", "soft"]>;
|
|
201
|
+
}>;
|
|
202
|
+
type TokenBudgetConfig = typeof TokenBudgetConfigSchema.Type;
|
|
203
|
+
declare const UncertaintySignalSchema: Schema.Struct<{
|
|
204
|
+
taskId: typeof Schema.String;
|
|
205
|
+
agentId: typeof Schema.String;
|
|
206
|
+
confidence: typeof Schema.Number;
|
|
207
|
+
phase: typeof Schema.String;
|
|
208
|
+
context: typeof Schema.String;
|
|
209
|
+
}>;
|
|
210
|
+
type UncertaintySignal = typeof UncertaintySignalSchema.Type;
|
|
211
|
+
declare const AgentDecisionSchema: Schema.Struct<{
|
|
212
|
+
type: Schema.Literal<["tool_call", "strategy_switch", "output"]>;
|
|
213
|
+
importance: typeof Schema.Number;
|
|
214
|
+
content: typeof Schema.Unknown;
|
|
215
|
+
}>;
|
|
216
|
+
type AgentDecision = typeof AgentDecisionSchema.Type;
|
|
217
|
+
|
|
218
|
+
declare const AgentError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
219
|
+
readonly _tag: "AgentError";
|
|
220
|
+
} & Readonly<A>;
|
|
221
|
+
/**
|
|
222
|
+
* Base agent error — catch-all for unexpected agent failures.
|
|
223
|
+
*/
|
|
224
|
+
declare class AgentError extends AgentError_base<{
|
|
225
|
+
readonly message: string;
|
|
226
|
+
readonly cause?: unknown;
|
|
227
|
+
}> {
|
|
228
|
+
}
|
|
229
|
+
declare const AgentNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
230
|
+
readonly _tag: "AgentNotFoundError";
|
|
231
|
+
} & Readonly<A>;
|
|
232
|
+
/**
|
|
233
|
+
* Agent not found in registry.
|
|
234
|
+
*/
|
|
235
|
+
declare class AgentNotFoundError extends AgentNotFoundError_base<{
|
|
236
|
+
readonly agentId: string;
|
|
237
|
+
readonly message: string;
|
|
238
|
+
}> {
|
|
239
|
+
}
|
|
240
|
+
declare const TaskError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
241
|
+
readonly _tag: "TaskError";
|
|
242
|
+
} & Readonly<A>;
|
|
243
|
+
/**
|
|
244
|
+
* Task execution failure.
|
|
245
|
+
*/
|
|
246
|
+
declare class TaskError extends TaskError_base<{
|
|
247
|
+
readonly taskId: string;
|
|
248
|
+
readonly message: string;
|
|
249
|
+
readonly cause?: unknown;
|
|
250
|
+
}> {
|
|
251
|
+
}
|
|
252
|
+
declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
253
|
+
readonly _tag: "ValidationError";
|
|
254
|
+
} & Readonly<A>;
|
|
255
|
+
/**
|
|
256
|
+
* Schema validation failure.
|
|
257
|
+
*/
|
|
258
|
+
declare class ValidationError extends ValidationError_base<{
|
|
259
|
+
readonly field: string;
|
|
260
|
+
readonly message: string;
|
|
261
|
+
readonly value?: unknown;
|
|
262
|
+
}> {
|
|
263
|
+
}
|
|
264
|
+
declare const RuntimeError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
265
|
+
readonly _tag: "RuntimeError";
|
|
266
|
+
} & Readonly<A>;
|
|
267
|
+
/**
|
|
268
|
+
* Runtime failure (fiber crash, timeout, etc.).
|
|
269
|
+
*/
|
|
270
|
+
declare class RuntimeError extends RuntimeError_base<{
|
|
271
|
+
readonly message: string;
|
|
272
|
+
readonly cause?: unknown;
|
|
273
|
+
}> {
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
type AgentEvent = {
|
|
277
|
+
readonly _tag: "TaskCreated";
|
|
278
|
+
readonly taskId: string;
|
|
279
|
+
} | {
|
|
280
|
+
readonly _tag: "TaskCompleted";
|
|
281
|
+
readonly taskId: string;
|
|
282
|
+
readonly success: boolean;
|
|
283
|
+
} | {
|
|
284
|
+
readonly _tag: "TaskFailed";
|
|
285
|
+
readonly taskId: string;
|
|
286
|
+
readonly error: string;
|
|
287
|
+
} | {
|
|
288
|
+
readonly _tag: "AgentCreated";
|
|
289
|
+
readonly agentId: string;
|
|
290
|
+
} | {
|
|
291
|
+
readonly _tag: "MessageSent";
|
|
292
|
+
readonly message: Message;
|
|
293
|
+
} | {
|
|
294
|
+
readonly _tag: "ExecutionPhaseEntered";
|
|
295
|
+
readonly taskId: string;
|
|
296
|
+
readonly phase: string;
|
|
297
|
+
} | {
|
|
298
|
+
readonly _tag: "ExecutionHookFired";
|
|
299
|
+
readonly taskId: string;
|
|
300
|
+
readonly phase: string;
|
|
301
|
+
readonly timing: string;
|
|
302
|
+
} | {
|
|
303
|
+
readonly _tag: "ExecutionLoopIteration";
|
|
304
|
+
readonly taskId: string;
|
|
305
|
+
readonly iteration: number;
|
|
306
|
+
} | {
|
|
307
|
+
readonly _tag: "ExecutionCancelled";
|
|
308
|
+
readonly taskId: string;
|
|
309
|
+
} | {
|
|
310
|
+
readonly _tag: "MemoryBootstrapped";
|
|
311
|
+
readonly agentId: string;
|
|
312
|
+
readonly tier: string;
|
|
313
|
+
} | {
|
|
314
|
+
readonly _tag: "MemoryFlushed";
|
|
315
|
+
readonly agentId: string;
|
|
316
|
+
} | {
|
|
317
|
+
readonly _tag: "MemorySnapshotSaved";
|
|
318
|
+
readonly agentId: string;
|
|
319
|
+
readonly sessionId: string;
|
|
320
|
+
} | {
|
|
321
|
+
readonly _tag: "Custom";
|
|
322
|
+
readonly type: string;
|
|
323
|
+
readonly payload: unknown;
|
|
324
|
+
};
|
|
325
|
+
type EventHandler = (event: AgentEvent) => Effect.Effect<void, never>;
|
|
326
|
+
declare const EventBus_base: Context.TagClass<EventBus, "EventBus", {
|
|
327
|
+
/** Publish an event to all subscribers. */
|
|
328
|
+
readonly publish: (event: AgentEvent) => Effect.Effect<void, never>;
|
|
329
|
+
/** Subscribe a handler for all events. Returns unsubscribe function. */
|
|
330
|
+
readonly subscribe: (handler: EventHandler) => Effect.Effect<() => void, never>;
|
|
331
|
+
/** Subscribe only to events matching a tag. */
|
|
332
|
+
readonly on: (tag: AgentEvent["_tag"], handler: EventHandler) => Effect.Effect<() => void, never>;
|
|
333
|
+
}>;
|
|
334
|
+
declare class EventBus extends EventBus_base {
|
|
335
|
+
}
|
|
336
|
+
declare const EventBusLive: Layer.Layer<EventBus, never, never>;
|
|
337
|
+
|
|
338
|
+
declare const AgentService_base: Context.TagClass<AgentService, "AgentService", {
|
|
339
|
+
/** Create a new agent from config. */
|
|
340
|
+
readonly create: (config: AgentConfig) => Effect.Effect<Agent, AgentError>;
|
|
341
|
+
/** Retrieve an agent by ID. */
|
|
342
|
+
readonly get: (id: AgentId) => Effect.Effect<Agent, AgentNotFoundError>;
|
|
343
|
+
/** List all registered agents. */
|
|
344
|
+
readonly list: () => Effect.Effect<readonly Agent[], never>;
|
|
345
|
+
/** Delete an agent by ID. */
|
|
346
|
+
readonly delete: (id: AgentId) => Effect.Effect<void, AgentNotFoundError>;
|
|
347
|
+
}>;
|
|
348
|
+
declare class AgentService extends AgentService_base {
|
|
349
|
+
}
|
|
350
|
+
declare const AgentServiceLive: Layer.Layer<AgentService, never, EventBus>;
|
|
351
|
+
|
|
352
|
+
declare const TaskService_base: Context.TagClass<TaskService, "TaskService", {
|
|
353
|
+
/** Create a new task (status: pending). */
|
|
354
|
+
readonly create: (config: TaskConfig) => Effect.Effect<Task, TaskError>;
|
|
355
|
+
/** Get task by ID. */
|
|
356
|
+
readonly get: (id: TaskId) => Effect.Effect<Task, TaskError>;
|
|
357
|
+
/** Update task status. */
|
|
358
|
+
readonly updateStatus: (id: TaskId, status: Task["status"]) => Effect.Effect<Task, TaskError>;
|
|
359
|
+
/** Cancel a running task. */
|
|
360
|
+
readonly cancel: (id: TaskId) => Effect.Effect<void, TaskError>;
|
|
361
|
+
}>;
|
|
362
|
+
declare class TaskService extends TaskService_base {
|
|
363
|
+
}
|
|
364
|
+
declare const TaskServiceLive: Layer.Layer<TaskService, never, EventBus>;
|
|
365
|
+
|
|
366
|
+
type TruncationStrategy = "drop-oldest" | "drop-middle" | "summarize-oldest";
|
|
367
|
+
declare const ContextError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
368
|
+
readonly _tag: "ContextError";
|
|
369
|
+
} & Readonly<A>;
|
|
370
|
+
declare class ContextError extends ContextError_base<{
|
|
371
|
+
readonly message: string;
|
|
372
|
+
readonly cause?: unknown;
|
|
373
|
+
}> {
|
|
374
|
+
}
|
|
375
|
+
declare const ContextWindowManager_base: Context.TagClass<ContextWindowManager, "ContextWindowManager", {
|
|
376
|
+
/**
|
|
377
|
+
* Build a context-window-safe message array.
|
|
378
|
+
* Injects memory context as a system message and truncates if needed.
|
|
379
|
+
*/
|
|
380
|
+
readonly buildContext: (options: {
|
|
381
|
+
systemPrompt: string;
|
|
382
|
+
messages: readonly unknown[];
|
|
383
|
+
memoryContext?: string;
|
|
384
|
+
maxTokens: number;
|
|
385
|
+
reserveOutputTokens: number;
|
|
386
|
+
}) => Effect.Effect<readonly unknown[], ContextError>;
|
|
387
|
+
/**
|
|
388
|
+
* Estimate token count for a string.
|
|
389
|
+
* Uses character-based heuristic (1 token ~ 4 chars) when no tokenizer available.
|
|
390
|
+
*/
|
|
391
|
+
readonly estimateTokens: (text: string) => Effect.Effect<number, never>;
|
|
392
|
+
/**
|
|
393
|
+
* Check if a message array fits within the context limit.
|
|
394
|
+
*/
|
|
395
|
+
readonly fitsInContext: (messages: readonly unknown[], maxTokens: number) => Effect.Effect<boolean, never>;
|
|
396
|
+
/**
|
|
397
|
+
* Truncate messages to fit within targetTokens.
|
|
398
|
+
*/
|
|
399
|
+
readonly truncate: (messages: readonly unknown[], targetTokens: number, strategy: TruncationStrategy) => Effect.Effect<readonly unknown[], ContextError>;
|
|
400
|
+
}>;
|
|
401
|
+
declare class ContextWindowManager extends ContextWindowManager_base {
|
|
402
|
+
}
|
|
403
|
+
declare const ContextWindowManagerLive: Layer.Layer<ContextWindowManager, never, never>;
|
|
404
|
+
|
|
405
|
+
/** Generate a new AgentId (ULID — sortable, globally unique). */
|
|
406
|
+
declare const generateAgentId: () => AgentId;
|
|
407
|
+
/** Generate a new TaskId. */
|
|
408
|
+
declare const generateTaskId: () => TaskId;
|
|
409
|
+
/** Generate a new MessageId. */
|
|
410
|
+
declare const generateMessageId: () => MessageId;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Complete core services layer.
|
|
414
|
+
* Provides: EventBus, AgentService, TaskService, ContextWindowManager
|
|
415
|
+
*
|
|
416
|
+
* Usage:
|
|
417
|
+
* myProgram.pipe(Effect.provide(CoreServicesLive))
|
|
418
|
+
*/
|
|
419
|
+
declare const CoreServicesLive: Layer.Layer<AgentService | TaskService | ContextWindowManager, never, never>;
|
|
420
|
+
|
|
421
|
+
export { type Agent, type AgentConfig, AgentConfigSchema, type AgentDecision, AgentDecisionSchema, AgentError, type AgentEvent, AgentId, AgentNotFoundError, AgentSchema, AgentService, AgentServiceLive, type Capability, CapabilitySchema, CapabilityType, type CircuitBreakerConfig, CircuitBreakerConfigSchema, type ContextController, ContextControllerSchema, ContextError, ContextWindowManager, ContextWindowManagerLive, CoreServicesLive, EventBus, EventBusLive, type EventHandler, LogLevel, MemoryType, type Message, MessageId, MessageSchema, MessageType, Priority, type ReasoningStep, ReasoningStepSchema, ReasoningStrategy, type ResultMetadata, ResultMetadataSchema, type RuntimeConfig, RuntimeConfigSchema, RuntimeError, StepType, type Task, type TaskConfig, TaskConfigSchema, TaskError, TaskId, type TaskMetadata, TaskMetadataSchema, type TaskResult, TaskResultSchema, TaskSchema, TaskService, TaskServiceLive, TaskStatus, TaskType, type TelemetryConfig, TelemetryConfigSchema, type TokenBudgetConfig, TokenBudgetConfigSchema, type TruncationStrategy, type UncertaintySignal, UncertaintySignalSchema, ValidationError, defaultRuntimeConfig, generateAgentId, generateMessageId, generateTaskId };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
// src/types/agent.ts
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
var AgentId = Schema.String.pipe(Schema.brand("AgentId"));
|
|
4
|
+
var CapabilityType = Schema.Literal(
|
|
5
|
+
"tool",
|
|
6
|
+
"skill",
|
|
7
|
+
"reasoning",
|
|
8
|
+
"memory"
|
|
9
|
+
);
|
|
10
|
+
var CapabilitySchema = Schema.Struct({
|
|
11
|
+
type: CapabilityType,
|
|
12
|
+
name: Schema.String
|
|
13
|
+
});
|
|
14
|
+
var ReasoningStrategy = Schema.Literal(
|
|
15
|
+
"reactive",
|
|
16
|
+
"plan-execute-reflect",
|
|
17
|
+
"tree-of-thought",
|
|
18
|
+
"reflexion",
|
|
19
|
+
"adaptive"
|
|
20
|
+
);
|
|
21
|
+
var MemoryType = Schema.Literal(
|
|
22
|
+
"semantic",
|
|
23
|
+
// Long-term knowledge (SQLite + memory.md)
|
|
24
|
+
"episodic",
|
|
25
|
+
// Daily logs + session snapshots
|
|
26
|
+
"procedural",
|
|
27
|
+
// Learned workflows and patterns
|
|
28
|
+
"working"
|
|
29
|
+
// In-process Ref, capacity 7
|
|
30
|
+
);
|
|
31
|
+
var AgentSchema = Schema.Struct({
|
|
32
|
+
id: AgentId,
|
|
33
|
+
name: Schema.String,
|
|
34
|
+
description: Schema.optional(Schema.String),
|
|
35
|
+
capabilities: Schema.Array(CapabilitySchema),
|
|
36
|
+
config: Schema.Unknown,
|
|
37
|
+
state: Schema.Unknown,
|
|
38
|
+
createdAt: Schema.DateFromSelf,
|
|
39
|
+
updatedAt: Schema.DateFromSelf
|
|
40
|
+
});
|
|
41
|
+
var AgentConfigSchema = Schema.Struct({
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
description: Schema.optional(Schema.String),
|
|
44
|
+
capabilities: Schema.Array(CapabilitySchema),
|
|
45
|
+
config: Schema.optional(Schema.Unknown),
|
|
46
|
+
initialState: Schema.optional(Schema.Unknown)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// src/types/task.ts
|
|
50
|
+
import { Schema as Schema2 } from "effect";
|
|
51
|
+
var TaskId = Schema2.String.pipe(Schema2.brand("TaskId"));
|
|
52
|
+
var TaskType = Schema2.Literal(
|
|
53
|
+
"query",
|
|
54
|
+
"action",
|
|
55
|
+
"workflow",
|
|
56
|
+
"research",
|
|
57
|
+
"delegation"
|
|
58
|
+
);
|
|
59
|
+
var Priority = Schema2.Literal("low", "medium", "high", "critical");
|
|
60
|
+
var TaskStatus = Schema2.Literal(
|
|
61
|
+
"pending",
|
|
62
|
+
"running",
|
|
63
|
+
"paused",
|
|
64
|
+
"completed",
|
|
65
|
+
"failed",
|
|
66
|
+
"cancelled"
|
|
67
|
+
);
|
|
68
|
+
var TaskMetadataSchema = Schema2.Struct({
|
|
69
|
+
maxDuration: Schema2.optional(Schema2.Number),
|
|
70
|
+
maxCost: Schema2.optional(Schema2.Number),
|
|
71
|
+
requiresApproval: Schema2.optional(Schema2.Boolean),
|
|
72
|
+
tags: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
73
|
+
context: Schema2.optional(
|
|
74
|
+
Schema2.Record({ key: Schema2.String, value: Schema2.Unknown })
|
|
75
|
+
)
|
|
76
|
+
});
|
|
77
|
+
var TaskSchema = Schema2.Struct({
|
|
78
|
+
id: TaskId,
|
|
79
|
+
agentId: AgentId,
|
|
80
|
+
type: TaskType,
|
|
81
|
+
input: Schema2.Unknown,
|
|
82
|
+
priority: Priority,
|
|
83
|
+
status: TaskStatus,
|
|
84
|
+
metadata: TaskMetadataSchema,
|
|
85
|
+
createdAt: Schema2.DateFromSelf,
|
|
86
|
+
startedAt: Schema2.optional(Schema2.DateFromSelf),
|
|
87
|
+
completedAt: Schema2.optional(Schema2.DateFromSelf)
|
|
88
|
+
});
|
|
89
|
+
var TaskConfigSchema = Schema2.Struct({
|
|
90
|
+
agentId: AgentId,
|
|
91
|
+
type: TaskType,
|
|
92
|
+
input: Schema2.Unknown,
|
|
93
|
+
priority: Schema2.optional(Priority),
|
|
94
|
+
metadata: Schema2.optional(TaskMetadataSchema)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// src/types/result.ts
|
|
98
|
+
import { Schema as Schema3 } from "effect";
|
|
99
|
+
var StepType = Schema3.Literal(
|
|
100
|
+
"thought",
|
|
101
|
+
"action",
|
|
102
|
+
"observation",
|
|
103
|
+
"plan",
|
|
104
|
+
"reflection",
|
|
105
|
+
"critique"
|
|
106
|
+
);
|
|
107
|
+
var ReasoningStepSchema = Schema3.Struct({
|
|
108
|
+
id: Schema3.String,
|
|
109
|
+
type: StepType,
|
|
110
|
+
content: Schema3.String,
|
|
111
|
+
timestamp: Schema3.DateFromSelf,
|
|
112
|
+
metadata: Schema3.optional(
|
|
113
|
+
Schema3.Struct({
|
|
114
|
+
confidence: Schema3.optional(Schema3.Number),
|
|
115
|
+
toolUsed: Schema3.optional(Schema3.String),
|
|
116
|
+
cost: Schema3.optional(Schema3.Number),
|
|
117
|
+
duration: Schema3.optional(Schema3.Number)
|
|
118
|
+
})
|
|
119
|
+
)
|
|
120
|
+
});
|
|
121
|
+
var ResultMetadataSchema = Schema3.Struct({
|
|
122
|
+
duration: Schema3.Number,
|
|
123
|
+
cost: Schema3.Number,
|
|
124
|
+
tokensUsed: Schema3.Number,
|
|
125
|
+
confidence: Schema3.optional(Schema3.Number.pipe(Schema3.between(0, 1))),
|
|
126
|
+
strategyUsed: Schema3.optional(Schema3.String),
|
|
127
|
+
stepsCount: Schema3.optional(Schema3.Number)
|
|
128
|
+
});
|
|
129
|
+
var TaskResultSchema = Schema3.Struct({
|
|
130
|
+
taskId: TaskId,
|
|
131
|
+
agentId: AgentId,
|
|
132
|
+
output: Schema3.Unknown,
|
|
133
|
+
success: Schema3.Boolean,
|
|
134
|
+
error: Schema3.optional(Schema3.String),
|
|
135
|
+
metadata: ResultMetadataSchema,
|
|
136
|
+
completedAt: Schema3.DateFromSelf
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// src/types/message.ts
|
|
140
|
+
import { Schema as Schema4 } from "effect";
|
|
141
|
+
var MessageId = Schema4.String.pipe(Schema4.brand("MessageId"));
|
|
142
|
+
var MessageType = Schema4.Literal(
|
|
143
|
+
"request",
|
|
144
|
+
"response",
|
|
145
|
+
"notification",
|
|
146
|
+
"delegation",
|
|
147
|
+
"query"
|
|
148
|
+
);
|
|
149
|
+
var MessageSchema = Schema4.Struct({
|
|
150
|
+
id: MessageId,
|
|
151
|
+
fromAgentId: AgentId,
|
|
152
|
+
toAgentId: AgentId,
|
|
153
|
+
type: MessageType,
|
|
154
|
+
content: Schema4.Unknown,
|
|
155
|
+
timestamp: Schema4.DateFromSelf,
|
|
156
|
+
metadata: Schema4.optional(
|
|
157
|
+
Schema4.Struct({
|
|
158
|
+
correlationId: Schema4.optional(Schema4.String),
|
|
159
|
+
causationId: Schema4.optional(Schema4.String),
|
|
160
|
+
context: Schema4.optional(
|
|
161
|
+
Schema4.Record({ key: Schema4.String, value: Schema4.Unknown })
|
|
162
|
+
)
|
|
163
|
+
})
|
|
164
|
+
)
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// src/types/config.ts
|
|
168
|
+
import { Schema as Schema5 } from "effect";
|
|
169
|
+
var LogLevel = Schema5.Literal("debug", "info", "warn", "error");
|
|
170
|
+
var TelemetryConfigSchema = Schema5.Struct({
|
|
171
|
+
enabled: Schema5.Boolean,
|
|
172
|
+
endpoint: Schema5.optional(Schema5.String),
|
|
173
|
+
serviceName: Schema5.String,
|
|
174
|
+
sampleRate: Schema5.Number.pipe(Schema5.between(0, 1))
|
|
175
|
+
});
|
|
176
|
+
var RuntimeConfigSchema = Schema5.Struct({
|
|
177
|
+
maxConcurrentTasks: Schema5.Number,
|
|
178
|
+
taskTimeout: Schema5.Number,
|
|
179
|
+
maxRetries: Schema5.Number,
|
|
180
|
+
retryDelay: Schema5.Number,
|
|
181
|
+
logLevel: LogLevel,
|
|
182
|
+
telemetry: TelemetryConfigSchema
|
|
183
|
+
});
|
|
184
|
+
var defaultRuntimeConfig = {
|
|
185
|
+
maxConcurrentTasks: 10,
|
|
186
|
+
taskTimeout: 3e5,
|
|
187
|
+
maxRetries: 3,
|
|
188
|
+
retryDelay: 1e3,
|
|
189
|
+
logLevel: "info",
|
|
190
|
+
telemetry: {
|
|
191
|
+
enabled: true,
|
|
192
|
+
serviceName: "reactive-agents",
|
|
193
|
+
sampleRate: 1
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var ContextControllerSchema = Schema5.Struct({
|
|
197
|
+
prioritization: Schema5.optional(
|
|
198
|
+
Schema5.Literal("semantic", "recency", "importance")
|
|
199
|
+
),
|
|
200
|
+
pruning: Schema5.optional(
|
|
201
|
+
Schema5.Literal("adaptive", "sliding-window", "fifo")
|
|
202
|
+
),
|
|
203
|
+
retention: Schema5.optional(Schema5.Array(Schema5.String)),
|
|
204
|
+
compression: Schema5.optional(
|
|
205
|
+
Schema5.Literal("none", "aggressive", "adaptive")
|
|
206
|
+
)
|
|
207
|
+
});
|
|
208
|
+
var CircuitBreakerConfigSchema = Schema5.Struct({
|
|
209
|
+
errorThreshold: Schema5.Number.pipe(Schema5.between(0, 1)),
|
|
210
|
+
timeout: Schema5.Number,
|
|
211
|
+
// ms: max execution time before trip
|
|
212
|
+
resetTimeout: Schema5.Number
|
|
213
|
+
// ms: time before attempting reset
|
|
214
|
+
});
|
|
215
|
+
var TokenBudgetConfigSchema = Schema5.Struct({
|
|
216
|
+
total: Schema5.Number,
|
|
217
|
+
allocation: Schema5.optional(
|
|
218
|
+
Schema5.Struct({
|
|
219
|
+
system: Schema5.optional(Schema5.Number),
|
|
220
|
+
context: Schema5.optional(Schema5.Number),
|
|
221
|
+
reasoning: Schema5.optional(Schema5.Number),
|
|
222
|
+
output: Schema5.optional(Schema5.Number)
|
|
223
|
+
})
|
|
224
|
+
),
|
|
225
|
+
enforcement: Schema5.Literal("hard", "soft")
|
|
226
|
+
});
|
|
227
|
+
var UncertaintySignalSchema = Schema5.Struct({
|
|
228
|
+
taskId: Schema5.String,
|
|
229
|
+
agentId: Schema5.String,
|
|
230
|
+
confidence: Schema5.Number,
|
|
231
|
+
phase: Schema5.String,
|
|
232
|
+
context: Schema5.String
|
|
233
|
+
});
|
|
234
|
+
var AgentDecisionSchema = Schema5.Struct({
|
|
235
|
+
type: Schema5.Literal("tool_call", "strategy_switch", "output"),
|
|
236
|
+
importance: Schema5.Number,
|
|
237
|
+
content: Schema5.Unknown
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/services/agent-service.ts
|
|
241
|
+
import { Effect as Effect2, Context as Context2, Layer as Layer2, Ref as Ref2 } from "effect";
|
|
242
|
+
|
|
243
|
+
// src/id.ts
|
|
244
|
+
import { ulid } from "ulid";
|
|
245
|
+
var generateAgentId = () => ulid();
|
|
246
|
+
var generateTaskId = () => ulid();
|
|
247
|
+
var generateMessageId = () => ulid();
|
|
248
|
+
|
|
249
|
+
// src/errors/errors.ts
|
|
250
|
+
import { Data } from "effect";
|
|
251
|
+
var AgentError = class extends Data.TaggedError("AgentError") {
|
|
252
|
+
};
|
|
253
|
+
var AgentNotFoundError = class extends Data.TaggedError("AgentNotFoundError") {
|
|
254
|
+
};
|
|
255
|
+
var TaskError = class extends Data.TaggedError("TaskError") {
|
|
256
|
+
};
|
|
257
|
+
var ValidationError = class extends Data.TaggedError("ValidationError") {
|
|
258
|
+
};
|
|
259
|
+
var RuntimeError = class extends Data.TaggedError("RuntimeError") {
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// src/services/event-bus.ts
|
|
263
|
+
import { Effect, Context, Layer, Ref } from "effect";
|
|
264
|
+
var EventBus = class extends Context.Tag("EventBus")() {
|
|
265
|
+
};
|
|
266
|
+
var EventBusLive = Layer.effect(
|
|
267
|
+
EventBus,
|
|
268
|
+
Effect.gen(function* () {
|
|
269
|
+
const handlers = yield* Ref.make([]);
|
|
270
|
+
return {
|
|
271
|
+
publish: (event) => Effect.gen(function* () {
|
|
272
|
+
const hs = yield* Ref.get(handlers);
|
|
273
|
+
yield* Effect.all(
|
|
274
|
+
hs.map((h) => h(event)),
|
|
275
|
+
{ concurrency: "unbounded" }
|
|
276
|
+
);
|
|
277
|
+
}),
|
|
278
|
+
subscribe: (handler) => Effect.gen(function* () {
|
|
279
|
+
yield* Ref.update(handlers, (hs) => [...hs, handler]);
|
|
280
|
+
return () => {
|
|
281
|
+
Effect.runSync(
|
|
282
|
+
Ref.update(handlers, (hs) => hs.filter((h) => h !== handler))
|
|
283
|
+
);
|
|
284
|
+
};
|
|
285
|
+
}),
|
|
286
|
+
on: (tag, handler) => Effect.gen(function* () {
|
|
287
|
+
const filtered = (event) => event._tag === tag ? handler(event) : Effect.void;
|
|
288
|
+
yield* Ref.update(handlers, (hs) => [...hs, filtered]);
|
|
289
|
+
return () => {
|
|
290
|
+
Effect.runSync(
|
|
291
|
+
Ref.update(handlers, (hs) => hs.filter((h) => h !== filtered))
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
})
|
|
295
|
+
};
|
|
296
|
+
})
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// src/services/agent-service.ts
|
|
300
|
+
var AgentService = class extends Context2.Tag("AgentService")() {
|
|
301
|
+
};
|
|
302
|
+
var AgentServiceLive = Layer2.effect(
|
|
303
|
+
AgentService,
|
|
304
|
+
Effect2.gen(function* () {
|
|
305
|
+
const eventBus = yield* EventBus;
|
|
306
|
+
const store = yield* Ref2.make(/* @__PURE__ */ new Map());
|
|
307
|
+
return {
|
|
308
|
+
create: (config) => Effect2.gen(function* () {
|
|
309
|
+
const now = /* @__PURE__ */ new Date();
|
|
310
|
+
const agent = {
|
|
311
|
+
id: generateAgentId(),
|
|
312
|
+
name: config.name,
|
|
313
|
+
description: config.description,
|
|
314
|
+
capabilities: config.capabilities ?? [],
|
|
315
|
+
config: config.config ?? {},
|
|
316
|
+
state: config.initialState ?? {},
|
|
317
|
+
createdAt: now,
|
|
318
|
+
updatedAt: now
|
|
319
|
+
};
|
|
320
|
+
yield* Ref2.update(store, (m) => new Map(m).set(agent.id, agent));
|
|
321
|
+
yield* eventBus.publish({ _tag: "AgentCreated", agentId: agent.id });
|
|
322
|
+
return agent;
|
|
323
|
+
}),
|
|
324
|
+
get: (id) => Effect2.gen(function* () {
|
|
325
|
+
const m = yield* Ref2.get(store);
|
|
326
|
+
const agent = m.get(id);
|
|
327
|
+
if (!agent) {
|
|
328
|
+
return yield* Effect2.fail(
|
|
329
|
+
new AgentNotFoundError({
|
|
330
|
+
agentId: id,
|
|
331
|
+
message: `Agent ${id} not found`
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
return agent;
|
|
336
|
+
}),
|
|
337
|
+
list: () => Effect2.gen(function* () {
|
|
338
|
+
const m = yield* Ref2.get(store);
|
|
339
|
+
return Array.from(m.values());
|
|
340
|
+
}),
|
|
341
|
+
delete: (id) => Effect2.gen(function* () {
|
|
342
|
+
const m = yield* Ref2.get(store);
|
|
343
|
+
if (!m.has(id)) {
|
|
344
|
+
return yield* Effect2.fail(
|
|
345
|
+
new AgentNotFoundError({
|
|
346
|
+
agentId: id,
|
|
347
|
+
message: `Agent ${id} not found`
|
|
348
|
+
})
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
yield* Ref2.update(store, (m2) => {
|
|
352
|
+
const next = new Map(m2);
|
|
353
|
+
next.delete(id);
|
|
354
|
+
return next;
|
|
355
|
+
});
|
|
356
|
+
})
|
|
357
|
+
};
|
|
358
|
+
})
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
// src/services/task-service.ts
|
|
362
|
+
import { Effect as Effect3, Context as Context3, Layer as Layer3, Ref as Ref3 } from "effect";
|
|
363
|
+
var TaskService = class extends Context3.Tag("TaskService")() {
|
|
364
|
+
};
|
|
365
|
+
var TaskServiceLive = Layer3.effect(
|
|
366
|
+
TaskService,
|
|
367
|
+
Effect3.gen(function* () {
|
|
368
|
+
const eventBus = yield* EventBus;
|
|
369
|
+
const store = yield* Ref3.make(/* @__PURE__ */ new Map());
|
|
370
|
+
return {
|
|
371
|
+
create: (config) => Effect3.gen(function* () {
|
|
372
|
+
const task = {
|
|
373
|
+
id: generateTaskId(),
|
|
374
|
+
agentId: config.agentId,
|
|
375
|
+
type: config.type,
|
|
376
|
+
input: config.input,
|
|
377
|
+
priority: config.priority ?? "medium",
|
|
378
|
+
status: "pending",
|
|
379
|
+
metadata: config.metadata ?? {},
|
|
380
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
381
|
+
};
|
|
382
|
+
yield* Ref3.update(store, (m) => new Map(m).set(task.id, task));
|
|
383
|
+
yield* eventBus.publish({ _tag: "TaskCreated", taskId: task.id });
|
|
384
|
+
return task;
|
|
385
|
+
}),
|
|
386
|
+
get: (id) => Effect3.gen(function* () {
|
|
387
|
+
const m = yield* Ref3.get(store);
|
|
388
|
+
const task = m.get(id);
|
|
389
|
+
if (!task) {
|
|
390
|
+
return yield* Effect3.fail(
|
|
391
|
+
new TaskError({ taskId: id, message: `Task ${id} not found` })
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
return task;
|
|
395
|
+
}),
|
|
396
|
+
updateStatus: (id, status) => Effect3.gen(function* () {
|
|
397
|
+
const m = yield* Ref3.get(store);
|
|
398
|
+
const task = m.get(id);
|
|
399
|
+
if (!task) {
|
|
400
|
+
return yield* Effect3.fail(
|
|
401
|
+
new TaskError({ taskId: id, message: `Task ${id} not found` })
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
const updated = { ...task, status };
|
|
405
|
+
yield* Ref3.update(store, (m2) => new Map(m2).set(id, updated));
|
|
406
|
+
if (status === "completed") {
|
|
407
|
+
yield* eventBus.publish({
|
|
408
|
+
_tag: "TaskCompleted",
|
|
409
|
+
taskId: id,
|
|
410
|
+
success: true
|
|
411
|
+
});
|
|
412
|
+
} else if (status === "failed") {
|
|
413
|
+
yield* eventBus.publish({
|
|
414
|
+
_tag: "TaskFailed",
|
|
415
|
+
taskId: id,
|
|
416
|
+
error: "Task failed"
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return updated;
|
|
420
|
+
}),
|
|
421
|
+
cancel: (id) => Effect3.gen(function* () {
|
|
422
|
+
const m = yield* Ref3.get(store);
|
|
423
|
+
if (!m.has(id)) {
|
|
424
|
+
return yield* Effect3.fail(
|
|
425
|
+
new TaskError({ taskId: id, message: `Task ${id} not found` })
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
yield* Ref3.update(store, (m2) => {
|
|
429
|
+
const next = new Map(m2);
|
|
430
|
+
next.set(id, { ...next.get(id), status: "cancelled" });
|
|
431
|
+
return next;
|
|
432
|
+
});
|
|
433
|
+
})
|
|
434
|
+
};
|
|
435
|
+
})
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
// src/services/context-window-manager.ts
|
|
439
|
+
import { Effect as Effect4, Context as Context4, Layer as Layer4, Data as Data2 } from "effect";
|
|
440
|
+
var ContextError = class extends Data2.TaggedError("ContextError") {
|
|
441
|
+
};
|
|
442
|
+
var ContextWindowManager = class extends Context4.Tag("ContextWindowManager")() {
|
|
443
|
+
};
|
|
444
|
+
var estimateTokensImpl = (text) => Math.ceil(text.length / 4);
|
|
445
|
+
var fitsInContextImpl = (messages, maxTokens) => {
|
|
446
|
+
const text = JSON.stringify(messages);
|
|
447
|
+
const estimated = estimateTokensImpl(text);
|
|
448
|
+
return estimated <= maxTokens;
|
|
449
|
+
};
|
|
450
|
+
var ContextWindowManagerLive = Layer4.succeed(ContextWindowManager, {
|
|
451
|
+
estimateTokens: (text) => Effect4.succeed(estimateTokensImpl(text)),
|
|
452
|
+
fitsInContext: (messages, maxTokens) => Effect4.succeed(fitsInContextImpl(messages, maxTokens)),
|
|
453
|
+
truncate: (messages, targetTokens, strategy) => Effect4.gen(function* () {
|
|
454
|
+
const arr = [...messages];
|
|
455
|
+
if (arr.length <= 1) return arr;
|
|
456
|
+
switch (strategy) {
|
|
457
|
+
case "drop-oldest": {
|
|
458
|
+
while (arr.length > 1) {
|
|
459
|
+
if (fitsInContextImpl(arr, targetTokens)) break;
|
|
460
|
+
arr.shift();
|
|
461
|
+
}
|
|
462
|
+
return arr;
|
|
463
|
+
}
|
|
464
|
+
case "drop-middle": {
|
|
465
|
+
while (arr.length > 2) {
|
|
466
|
+
if (fitsInContextImpl(arr, targetTokens)) break;
|
|
467
|
+
const mid = Math.floor(arr.length / 2);
|
|
468
|
+
arr.splice(mid, 1);
|
|
469
|
+
}
|
|
470
|
+
return arr;
|
|
471
|
+
}
|
|
472
|
+
default:
|
|
473
|
+
return yield* Effect4.fail(
|
|
474
|
+
new ContextError({
|
|
475
|
+
message: `Truncation strategy '${strategy}' not implemented in Phase 1`
|
|
476
|
+
})
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}),
|
|
480
|
+
buildContext: (options) => Effect4.gen(function* () {
|
|
481
|
+
const budget = options.maxTokens - options.reserveOutputTokens;
|
|
482
|
+
const systemContent = options.memoryContext ? `${options.systemPrompt}
|
|
483
|
+
|
|
484
|
+
## Agent Memory
|
|
485
|
+
${options.memoryContext}` : options.systemPrompt;
|
|
486
|
+
const systemMsg = { role: "system", content: systemContent };
|
|
487
|
+
const systemTokens = estimateTokensImpl(systemContent);
|
|
488
|
+
const conversationBudget = budget - systemTokens;
|
|
489
|
+
const arr = [...options.messages];
|
|
490
|
+
while (arr.length > 1) {
|
|
491
|
+
if (fitsInContextImpl(arr, conversationBudget)) break;
|
|
492
|
+
arr.shift();
|
|
493
|
+
}
|
|
494
|
+
return [systemMsg, ...arr];
|
|
495
|
+
})
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
// src/runtime.ts
|
|
499
|
+
import { Layer as Layer5 } from "effect";
|
|
500
|
+
var CoreServicesLive = Layer5.mergeAll(
|
|
501
|
+
AgentServiceLive,
|
|
502
|
+
TaskServiceLive,
|
|
503
|
+
ContextWindowManagerLive
|
|
504
|
+
).pipe(Layer5.provide(EventBusLive));
|
|
505
|
+
export {
|
|
506
|
+
AgentConfigSchema,
|
|
507
|
+
AgentDecisionSchema,
|
|
508
|
+
AgentError,
|
|
509
|
+
AgentId,
|
|
510
|
+
AgentNotFoundError,
|
|
511
|
+
AgentSchema,
|
|
512
|
+
AgentService,
|
|
513
|
+
AgentServiceLive,
|
|
514
|
+
CapabilitySchema,
|
|
515
|
+
CapabilityType,
|
|
516
|
+
CircuitBreakerConfigSchema,
|
|
517
|
+
ContextControllerSchema,
|
|
518
|
+
ContextError,
|
|
519
|
+
ContextWindowManager,
|
|
520
|
+
ContextWindowManagerLive,
|
|
521
|
+
CoreServicesLive,
|
|
522
|
+
EventBus,
|
|
523
|
+
EventBusLive,
|
|
524
|
+
LogLevel,
|
|
525
|
+
MemoryType,
|
|
526
|
+
MessageId,
|
|
527
|
+
MessageSchema,
|
|
528
|
+
MessageType,
|
|
529
|
+
Priority,
|
|
530
|
+
ReasoningStepSchema,
|
|
531
|
+
ReasoningStrategy,
|
|
532
|
+
ResultMetadataSchema,
|
|
533
|
+
RuntimeConfigSchema,
|
|
534
|
+
RuntimeError,
|
|
535
|
+
StepType,
|
|
536
|
+
TaskConfigSchema,
|
|
537
|
+
TaskError,
|
|
538
|
+
TaskId,
|
|
539
|
+
TaskMetadataSchema,
|
|
540
|
+
TaskResultSchema,
|
|
541
|
+
TaskSchema,
|
|
542
|
+
TaskService,
|
|
543
|
+
TaskServiceLive,
|
|
544
|
+
TaskStatus,
|
|
545
|
+
TaskType,
|
|
546
|
+
TelemetryConfigSchema,
|
|
547
|
+
TokenBudgetConfigSchema,
|
|
548
|
+
UncertaintySignalSchema,
|
|
549
|
+
ValidationError,
|
|
550
|
+
defaultRuntimeConfig,
|
|
551
|
+
generateAgentId,
|
|
552
|
+
generateMessageId,
|
|
553
|
+
generateTaskId
|
|
554
|
+
};
|
|
555
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/agent.ts","../src/types/task.ts","../src/types/result.ts","../src/types/message.ts","../src/types/config.ts","../src/services/agent-service.ts","../src/id.ts","../src/errors/errors.ts","../src/services/event-bus.ts","../src/services/task-service.ts","../src/services/context-window-manager.ts","../src/runtime.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n// ─── Agent ID (branded string) ───\n\nexport const AgentId = Schema.String.pipe(Schema.brand(\"AgentId\"));\nexport type AgentId = typeof AgentId.Type;\n\n// ─── Capability ───\n\nexport const CapabilityType = Schema.Literal(\n \"tool\",\n \"skill\",\n \"reasoning\",\n \"memory\",\n);\nexport type CapabilityType = typeof CapabilityType.Type;\n\nexport const CapabilitySchema = Schema.Struct({\n type: CapabilityType,\n name: Schema.String,\n});\nexport type Capability = typeof CapabilitySchema.Type;\n\n// ─── Reasoning Strategy (shared across layers) ───\n\nexport const ReasoningStrategy = Schema.Literal(\n \"reactive\",\n \"plan-execute-reflect\",\n \"tree-of-thought\",\n \"reflexion\",\n \"adaptive\",\n);\nexport type ReasoningStrategy = typeof ReasoningStrategy.Type;\n\n// ─── Memory Type ───\n// Updated: \"factual\" replaced by \"semantic\" + \"procedural\" (see 02-layer-memory.md)\n\nexport const MemoryType = Schema.Literal(\n \"semantic\", // Long-term knowledge (SQLite + memory.md)\n \"episodic\", // Daily logs + session snapshots\n \"procedural\", // Learned workflows and patterns\n \"working\", // In-process Ref, capacity 7\n);\nexport type MemoryType = typeof MemoryType.Type;\n\n// ─── Agent Schema ───\n\nexport const AgentSchema = Schema.Struct({\n id: AgentId,\n name: Schema.String,\n description: Schema.optional(Schema.String),\n capabilities: Schema.Array(CapabilitySchema),\n config: Schema.Unknown,\n state: Schema.Unknown,\n createdAt: Schema.DateFromSelf,\n updatedAt: Schema.DateFromSelf,\n});\nexport type Agent = typeof AgentSchema.Type;\n\n// ─── Agent Config (input for creating agents) ───\n\nexport const AgentConfigSchema = Schema.Struct({\n name: Schema.String,\n description: Schema.optional(Schema.String),\n capabilities: Schema.Array(CapabilitySchema),\n config: Schema.optional(Schema.Unknown),\n initialState: Schema.optional(Schema.Unknown),\n});\nexport type AgentConfig = typeof AgentConfigSchema.Type;\n","import { Schema } from \"effect\";\nimport { AgentId } from \"./agent.js\";\n\n// ─── Task ID (branded string) ───\n\nexport const TaskId = Schema.String.pipe(Schema.brand(\"TaskId\"));\nexport type TaskId = typeof TaskId.Type;\n\n// ─── Task Type ───\n\nexport const TaskType = Schema.Literal(\n \"query\",\n \"action\",\n \"workflow\",\n \"research\",\n \"delegation\",\n);\nexport type TaskType = typeof TaskType.Type;\n\n// ─── Priority ───\n\nexport const Priority = Schema.Literal(\"low\", \"medium\", \"high\", \"critical\");\nexport type Priority = typeof Priority.Type;\n\n// ─── Task Status ───\n\nexport const TaskStatus = Schema.Literal(\n \"pending\",\n \"running\",\n \"paused\",\n \"completed\",\n \"failed\",\n \"cancelled\",\n);\nexport type TaskStatus = typeof TaskStatus.Type;\n\n// ─── Task Metadata ───\n\nexport const TaskMetadataSchema = Schema.Struct({\n maxDuration: Schema.optional(Schema.Number),\n maxCost: Schema.optional(Schema.Number),\n requiresApproval: Schema.optional(Schema.Boolean),\n tags: Schema.optional(Schema.Array(Schema.String)),\n context: Schema.optional(\n Schema.Record({ key: Schema.String, value: Schema.Unknown }),\n ),\n});\nexport type TaskMetadata = typeof TaskMetadataSchema.Type;\n\n// ─── Task Schema ───\n\nexport const TaskSchema = Schema.Struct({\n id: TaskId,\n agentId: AgentId,\n type: TaskType,\n input: Schema.Unknown,\n priority: Priority,\n status: TaskStatus,\n metadata: TaskMetadataSchema,\n createdAt: Schema.DateFromSelf,\n startedAt: Schema.optional(Schema.DateFromSelf),\n completedAt: Schema.optional(Schema.DateFromSelf),\n});\nexport type Task = typeof TaskSchema.Type;\n\n// ─── Task Config (input for creating tasks) ───\n\nexport const TaskConfigSchema = Schema.Struct({\n agentId: AgentId,\n type: TaskType,\n input: Schema.Unknown,\n priority: Schema.optional(Priority),\n metadata: Schema.optional(TaskMetadataSchema),\n});\nexport type TaskConfig = typeof TaskConfigSchema.Type;\n","import { Schema } from \"effect\";\nimport { AgentId } from \"./agent.js\";\nimport { TaskId } from \"./task.js\";\n\n// ─── Reasoning Step ───\n\nexport const StepType = Schema.Literal(\n \"thought\",\n \"action\",\n \"observation\",\n \"plan\",\n \"reflection\",\n \"critique\",\n);\nexport type StepType = typeof StepType.Type;\n\nexport const ReasoningStepSchema = Schema.Struct({\n id: Schema.String,\n type: StepType,\n content: Schema.String,\n timestamp: Schema.DateFromSelf,\n metadata: Schema.optional(\n Schema.Struct({\n confidence: Schema.optional(Schema.Number),\n toolUsed: Schema.optional(Schema.String),\n cost: Schema.optional(Schema.Number),\n duration: Schema.optional(Schema.Number),\n }),\n ),\n});\nexport type ReasoningStep = typeof ReasoningStepSchema.Type;\n\n// ─── Result Metadata ───\n\nexport const ResultMetadataSchema = Schema.Struct({\n duration: Schema.Number,\n cost: Schema.Number,\n tokensUsed: Schema.Number,\n confidence: Schema.optional(Schema.Number.pipe(Schema.between(0, 1))),\n strategyUsed: Schema.optional(Schema.String),\n stepsCount: Schema.optional(Schema.Number),\n});\nexport type ResultMetadata = typeof ResultMetadataSchema.Type;\n\n// ─── Task Result ───\n\nexport const TaskResultSchema = Schema.Struct({\n taskId: TaskId,\n agentId: AgentId,\n output: Schema.Unknown,\n success: Schema.Boolean,\n error: Schema.optional(Schema.String),\n metadata: ResultMetadataSchema,\n completedAt: Schema.DateFromSelf,\n});\nexport type TaskResult = typeof TaskResultSchema.Type;\n","import { Schema } from \"effect\";\nimport { AgentId } from \"./agent.js\";\n\n// ─── Message ID (branded string) ───\n\nexport const MessageId = Schema.String.pipe(Schema.brand(\"MessageId\"));\nexport type MessageId = typeof MessageId.Type;\n\n// ─── Message Type ───\n\nexport const MessageType = Schema.Literal(\n \"request\",\n \"response\",\n \"notification\",\n \"delegation\",\n \"query\",\n);\nexport type MessageType = typeof MessageType.Type;\n\n// ─── Message Schema ───\n\nexport const MessageSchema = Schema.Struct({\n id: MessageId,\n fromAgentId: AgentId,\n toAgentId: AgentId,\n type: MessageType,\n content: Schema.Unknown,\n timestamp: Schema.DateFromSelf,\n metadata: Schema.optional(\n Schema.Struct({\n correlationId: Schema.optional(Schema.String),\n causationId: Schema.optional(Schema.String),\n context: Schema.optional(\n Schema.Record({ key: Schema.String, value: Schema.Unknown }),\n ),\n }),\n ),\n});\nexport type Message = typeof MessageSchema.Type;\n","import { Schema } from \"effect\";\n\n// ─── Log Level ───\n\nexport const LogLevel = Schema.Literal(\"debug\", \"info\", \"warn\", \"error\");\nexport type LogLevel = typeof LogLevel.Type;\n\n// ─── Telemetry Config ───\n\nexport const TelemetryConfigSchema = Schema.Struct({\n enabled: Schema.Boolean,\n endpoint: Schema.optional(Schema.String),\n serviceName: Schema.String,\n sampleRate: Schema.Number.pipe(Schema.between(0, 1)),\n});\nexport type TelemetryConfig = typeof TelemetryConfigSchema.Type;\n\n// ─── Runtime Config ───\n\nexport const RuntimeConfigSchema = Schema.Struct({\n maxConcurrentTasks: Schema.Number,\n taskTimeout: Schema.Number,\n maxRetries: Schema.Number,\n retryDelay: Schema.Number,\n logLevel: LogLevel,\n telemetry: TelemetryConfigSchema,\n});\nexport type RuntimeConfig = typeof RuntimeConfigSchema.Type;\n\n// ─── Default Config ───\n\nexport const defaultRuntimeConfig: RuntimeConfig = {\n maxConcurrentTasks: 10,\n taskTimeout: 300_000,\n maxRetries: 3,\n retryDelay: 1_000,\n logLevel: \"info\",\n telemetry: {\n enabled: true,\n serviceName: \"reactive-agents\",\n sampleRate: 1.0,\n },\n};\n\n// ─── Context Controller (Vision Pillar: Control) ───\n\nexport const ContextControllerSchema = Schema.Struct({\n prioritization: Schema.optional(\n Schema.Literal(\"semantic\", \"recency\", \"importance\"),\n ),\n pruning: Schema.optional(\n Schema.Literal(\"adaptive\", \"sliding-window\", \"fifo\"),\n ),\n retention: Schema.optional(Schema.Array(Schema.String)),\n compression: Schema.optional(\n Schema.Literal(\"none\", \"aggressive\", \"adaptive\"),\n ),\n});\nexport type ContextController = typeof ContextControllerSchema.Type;\n\n// ─── Circuit Breaker (Vision Pillar: Reliability) ───\n\nexport const CircuitBreakerConfigSchema = Schema.Struct({\n errorThreshold: Schema.Number.pipe(Schema.between(0, 1)),\n timeout: Schema.Number, // ms: max execution time before trip\n resetTimeout: Schema.Number, // ms: time before attempting reset\n});\nexport type CircuitBreakerConfig = typeof CircuitBreakerConfigSchema.Type;\n\n// ─── Token Budget (Vision Pillar: Efficiency) ───\n\nexport const TokenBudgetConfigSchema = Schema.Struct({\n total: Schema.Number,\n allocation: Schema.optional(\n Schema.Struct({\n system: Schema.optional(Schema.Number),\n context: Schema.optional(Schema.Number),\n reasoning: Schema.optional(Schema.Number),\n output: Schema.optional(Schema.Number),\n }),\n ),\n enforcement: Schema.Literal(\"hard\", \"soft\"),\n});\nexport type TokenBudgetConfig = typeof TokenBudgetConfigSchema.Type;\n\n// ─── Decision & Uncertainty Signals (Vision Pillar: Control) ───\n\nexport const UncertaintySignalSchema = Schema.Struct({\n taskId: Schema.String,\n agentId: Schema.String,\n confidence: Schema.Number,\n phase: Schema.String,\n context: Schema.String,\n});\nexport type UncertaintySignal = typeof UncertaintySignalSchema.Type;\n\nexport const AgentDecisionSchema = Schema.Struct({\n type: Schema.Literal(\"tool_call\", \"strategy_switch\", \"output\"),\n importance: Schema.Number,\n content: Schema.Unknown,\n});\nexport type AgentDecision = typeof AgentDecisionSchema.Type;\n","import { Effect, Context, Layer, Ref } from \"effect\";\nimport type { Agent, AgentConfig, AgentId } from \"../types/agent.js\";\nimport { generateAgentId } from \"../id.js\";\nimport { AgentError, AgentNotFoundError } from \"../errors/errors.js\";\nimport { EventBus } from \"./event-bus.js\";\n\n// ─── Service Tag ───\n\nexport class AgentService extends Context.Tag(\"AgentService\")<\n AgentService,\n {\n /** Create a new agent from config. */\n readonly create: (config: AgentConfig) => Effect.Effect<Agent, AgentError>;\n\n /** Retrieve an agent by ID. */\n readonly get: (id: AgentId) => Effect.Effect<Agent, AgentNotFoundError>;\n\n /** List all registered agents. */\n readonly list: () => Effect.Effect<readonly Agent[], never>;\n\n /** Delete an agent by ID. */\n readonly delete: (id: AgentId) => Effect.Effect<void, AgentNotFoundError>;\n }\n>() {}\n\n// ─── Live Implementation ───\n\nexport const AgentServiceLive = Layer.effect(\n AgentService,\n Effect.gen(function* () {\n const eventBus = yield* EventBus;\n const store = yield* Ref.make<Map<string, Agent>>(new Map());\n\n return {\n create: (config: AgentConfig) =>\n Effect.gen(function* () {\n const now = new Date();\n const agent: Agent = {\n id: generateAgentId(),\n name: config.name,\n description: config.description,\n capabilities: config.capabilities ?? [],\n config: config.config ?? {},\n state: config.initialState ?? {},\n createdAt: now,\n updatedAt: now,\n };\n yield* Ref.update(store, (m) => new Map(m).set(agent.id, agent));\n yield* eventBus.publish({ _tag: \"AgentCreated\", agentId: agent.id });\n return agent;\n }),\n\n get: (id: AgentId) =>\n Effect.gen(function* () {\n const m = yield* Ref.get(store);\n const agent = m.get(id);\n if (!agent) {\n return yield* Effect.fail(\n new AgentNotFoundError({\n agentId: id,\n message: `Agent ${id} not found`,\n }),\n );\n }\n return agent;\n }),\n\n list: () =>\n Effect.gen(function* () {\n const m = yield* Ref.get(store);\n return Array.from(m.values());\n }),\n\n delete: (id: AgentId) =>\n Effect.gen(function* () {\n const m = yield* Ref.get(store);\n if (!m.has(id)) {\n return yield* Effect.fail(\n new AgentNotFoundError({\n agentId: id,\n message: `Agent ${id} not found`,\n }),\n );\n }\n yield* Ref.update(store, (m) => {\n const next = new Map(m);\n next.delete(id);\n return next;\n });\n }),\n };\n }),\n);\n","import { ulid } from \"ulid\";\nimport type { AgentId } from \"./types/agent.js\";\nimport type { TaskId } from \"./types/task.js\";\nimport type { MessageId } from \"./types/message.js\";\n\n/** Generate a new AgentId (ULID — sortable, globally unique). */\nexport const generateAgentId = (): AgentId => ulid() as AgentId;\n\n/** Generate a new TaskId. */\nexport const generateTaskId = (): TaskId => ulid() as TaskId;\n\n/** Generate a new MessageId. */\nexport const generateMessageId = (): MessageId => ulid() as MessageId;\n","import { Data } from \"effect\";\n\n/**\n * Base agent error — catch-all for unexpected agent failures.\n */\nexport class AgentError extends Data.TaggedError(\"AgentError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\n/**\n * Agent not found in registry.\n */\nexport class AgentNotFoundError extends Data.TaggedError(\"AgentNotFoundError\")<{\n readonly agentId: string;\n readonly message: string;\n}> {}\n\n/**\n * Task execution failure.\n */\nexport class TaskError extends Data.TaggedError(\"TaskError\")<{\n readonly taskId: string;\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\n/**\n * Schema validation failure.\n */\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n readonly field: string;\n readonly message: string;\n readonly value?: unknown;\n}> {}\n\n/**\n * Runtime failure (fiber crash, timeout, etc.).\n */\nexport class RuntimeError extends Data.TaggedError(\"RuntimeError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n","import { Effect, Context, Layer, Ref } from \"effect\";\nimport type { Message } from \"../types/message.js\";\n\n// ─── Event Types ───\n\nexport type AgentEvent =\n // ─── Core task/agent events ───\n | { readonly _tag: \"TaskCreated\"; readonly taskId: string }\n | {\n readonly _tag: \"TaskCompleted\";\n readonly taskId: string;\n readonly success: boolean;\n }\n | {\n readonly _tag: \"TaskFailed\";\n readonly taskId: string;\n readonly error: string;\n }\n | { readonly _tag: \"AgentCreated\"; readonly agentId: string }\n | { readonly _tag: \"MessageSent\"; readonly message: Message }\n // ─── Execution Engine events (from @reactive-agents/runtime) ───\n | {\n readonly _tag: \"ExecutionPhaseEntered\";\n readonly taskId: string;\n readonly phase: string;\n }\n | {\n readonly _tag: \"ExecutionHookFired\";\n readonly taskId: string;\n readonly phase: string;\n readonly timing: string;\n }\n | {\n readonly _tag: \"ExecutionLoopIteration\";\n readonly taskId: string;\n readonly iteration: number;\n }\n | { readonly _tag: \"ExecutionCancelled\"; readonly taskId: string }\n // ─── Memory events (from @reactive-agents/memory) ───\n | {\n readonly _tag: \"MemoryBootstrapped\";\n readonly agentId: string;\n readonly tier: string;\n }\n | { readonly _tag: \"MemoryFlushed\"; readonly agentId: string }\n | {\n readonly _tag: \"MemorySnapshotSaved\";\n readonly agentId: string;\n readonly sessionId: string;\n }\n // ─── Custom/extension events ───\n | {\n readonly _tag: \"Custom\";\n readonly type: string;\n readonly payload: unknown;\n };\n\nexport type EventHandler = (event: AgentEvent) => Effect.Effect<void, never>;\n\n// ─── Service Tag ───\n\nexport class EventBus extends Context.Tag(\"EventBus\")<\n EventBus,\n {\n /** Publish an event to all subscribers. */\n readonly publish: (event: AgentEvent) => Effect.Effect<void, never>;\n\n /** Subscribe a handler for all events. Returns unsubscribe function. */\n readonly subscribe: (\n handler: EventHandler,\n ) => Effect.Effect<() => void, never>;\n\n /** Subscribe only to events matching a tag. */\n readonly on: (\n tag: AgentEvent[\"_tag\"],\n handler: EventHandler,\n ) => Effect.Effect<() => void, never>;\n }\n>() {}\n\n// ─── Live Implementation ───\n\nexport const EventBusLive = Layer.effect(\n EventBus,\n Effect.gen(function* () {\n const handlers = yield* Ref.make<EventHandler[]>([]);\n\n return {\n publish: (event: AgentEvent) =>\n Effect.gen(function* () {\n const hs = yield* Ref.get(handlers);\n yield* Effect.all(\n hs.map((h) => h(event)),\n { concurrency: \"unbounded\" },\n );\n }),\n\n subscribe: (handler: EventHandler) =>\n Effect.gen(function* () {\n yield* Ref.update(handlers, (hs) => [...hs, handler]);\n return () => {\n Effect.runSync(\n Ref.update(handlers, (hs) => hs.filter((h) => h !== handler)),\n );\n };\n }),\n\n on: (tag: AgentEvent[\"_tag\"], handler: EventHandler) =>\n Effect.gen(function* () {\n const filtered: EventHandler = (event) =>\n event._tag === tag ? handler(event) : Effect.void;\n yield* Ref.update(handlers, (hs) => [...hs, filtered]);\n return () => {\n Effect.runSync(\n Ref.update(handlers, (hs) => hs.filter((h) => h !== filtered)),\n );\n };\n }),\n };\n }),\n);\n","import { Effect, Context, Layer, Ref } from \"effect\";\nimport type { Task, TaskConfig, TaskId } from \"../types/task.js\";\nimport { generateTaskId } from \"../id.js\";\nimport { TaskError } from \"../errors/errors.js\";\nimport { EventBus } from \"./event-bus.js\";\n\n// ─── Service Tag ───\n\nexport class TaskService extends Context.Tag(\"TaskService\")<\n TaskService,\n {\n /** Create a new task (status: pending). */\n readonly create: (config: TaskConfig) => Effect.Effect<Task, TaskError>;\n\n /** Get task by ID. */\n readonly get: (id: TaskId) => Effect.Effect<Task, TaskError>;\n\n /** Update task status. */\n readonly updateStatus: (\n id: TaskId,\n status: Task[\"status\"],\n ) => Effect.Effect<Task, TaskError>;\n\n /** Cancel a running task. */\n readonly cancel: (id: TaskId) => Effect.Effect<void, TaskError>;\n }\n>() {}\n\n// ─── Live Implementation ───\n\nexport const TaskServiceLive = Layer.effect(\n TaskService,\n Effect.gen(function* () {\n const eventBus = yield* EventBus;\n const store = yield* Ref.make<Map<string, Task>>(new Map());\n\n return {\n create: (config: TaskConfig) =>\n Effect.gen(function* () {\n const task: Task = {\n id: generateTaskId(),\n agentId: config.agentId,\n type: config.type,\n input: config.input,\n priority: config.priority ?? \"medium\",\n status: \"pending\",\n metadata: config.metadata ?? {},\n createdAt: new Date(),\n };\n yield* Ref.update(store, (m) => new Map(m).set(task.id, task));\n yield* eventBus.publish({ _tag: \"TaskCreated\", taskId: task.id });\n return task;\n }),\n\n get: (id: TaskId) =>\n Effect.gen(function* () {\n const m = yield* Ref.get(store);\n const task = m.get(id);\n if (!task) {\n return yield* Effect.fail(\n new TaskError({ taskId: id, message: `Task ${id} not found` }),\n );\n }\n return task;\n }),\n\n updateStatus: (id: TaskId, status: Task[\"status\"]) =>\n Effect.gen(function* () {\n const m = yield* Ref.get(store);\n const task = m.get(id);\n if (!task) {\n return yield* Effect.fail(\n new TaskError({ taskId: id, message: `Task ${id} not found` }),\n );\n }\n const updated: Task = { ...task, status };\n yield* Ref.update(store, (m) => new Map(m).set(id, updated));\n if (status === \"completed\") {\n yield* eventBus.publish({\n _tag: \"TaskCompleted\",\n taskId: id,\n success: true,\n });\n } else if (status === \"failed\") {\n yield* eventBus.publish({\n _tag: \"TaskFailed\",\n taskId: id,\n error: \"Task failed\",\n });\n }\n return updated;\n }),\n\n cancel: (id: TaskId) =>\n Effect.gen(function* () {\n const m = yield* Ref.get(store);\n if (!m.has(id)) {\n return yield* Effect.fail(\n new TaskError({ taskId: id, message: `Task ${id} not found` }),\n );\n }\n yield* Ref.update(store, (m) => {\n const next = new Map(m);\n next.set(id, { ...next.get(id)!, status: \"cancelled\" as const });\n return next;\n });\n }),\n };\n }),\n);\n","import { Effect, Context, Layer, Data } from \"effect\";\n\n// ─── Truncation Strategy ───\n\nexport type TruncationStrategy =\n | \"drop-oldest\" // Remove oldest messages first\n | \"drop-middle\" // Keep first + last, drop middle\n | \"summarize-oldest\"; // Summarize oldest messages (requires LLM — future Phase 2)\n\n// ─── Context Error ───\n\nexport class ContextError extends Data.TaggedError(\"ContextError\")<{\n readonly message: string;\n readonly cause?: unknown;\n}> {}\n\n// ─── Service Tag ───\n\nexport class ContextWindowManager extends Context.Tag(\"ContextWindowManager\")<\n ContextWindowManager,\n {\n /**\n * Build a context-window-safe message array.\n * Injects memory context as a system message and truncates if needed.\n */\n readonly buildContext: (options: {\n systemPrompt: string;\n messages: readonly unknown[];\n memoryContext?: string;\n maxTokens: number;\n reserveOutputTokens: number;\n }) => Effect.Effect<readonly unknown[], ContextError>;\n\n /**\n * Estimate token count for a string.\n * Uses character-based heuristic (1 token ~ 4 chars) when no tokenizer available.\n */\n readonly estimateTokens: (text: string) => Effect.Effect<number, never>;\n\n /**\n * Check if a message array fits within the context limit.\n */\n readonly fitsInContext: (\n messages: readonly unknown[],\n maxTokens: number,\n ) => Effect.Effect<boolean, never>;\n\n /**\n * Truncate messages to fit within targetTokens.\n */\n readonly truncate: (\n messages: readonly unknown[],\n targetTokens: number,\n strategy: TruncationStrategy,\n ) => Effect.Effect<readonly unknown[], ContextError>;\n }\n>() {}\n\n// ─── Helper functions (avoid self-referencing the service tag) ───\n\nconst estimateTokensImpl = (text: string): number =>\n Math.ceil(text.length / 4);\n\nconst fitsInContextImpl = (\n messages: readonly unknown[],\n maxTokens: number,\n): boolean => {\n const text = JSON.stringify(messages);\n const estimated = estimateTokensImpl(text);\n return estimated <= maxTokens;\n};\n\n// ─── Live Implementation ───\n\nexport const ContextWindowManagerLive = Layer.succeed(ContextWindowManager, {\n estimateTokens: (text) => Effect.succeed(estimateTokensImpl(text)),\n\n fitsInContext: (messages, maxTokens) =>\n Effect.succeed(fitsInContextImpl(messages, maxTokens)),\n\n truncate: (messages, targetTokens, strategy) =>\n Effect.gen(function* () {\n const arr = [...messages] as unknown[];\n\n if (arr.length <= 1) return arr;\n\n switch (strategy) {\n case \"drop-oldest\": {\n while (arr.length > 1) {\n if (fitsInContextImpl(arr, targetTokens)) break;\n arr.shift(); // Remove oldest\n }\n return arr;\n }\n case \"drop-middle\": {\n while (arr.length > 2) {\n if (fitsInContextImpl(arr, targetTokens)) break;\n const mid = Math.floor(arr.length / 2);\n arr.splice(mid, 1); // Remove middle message\n }\n return arr;\n }\n default:\n return yield* Effect.fail(\n new ContextError({\n message: `Truncation strategy '${strategy}' not implemented in Phase 1`,\n }),\n );\n }\n }),\n\n buildContext: (options) =>\n Effect.gen(function* () {\n const budget = options.maxTokens - options.reserveOutputTokens;\n\n // Build system message with memory context injected\n const systemContent = options.memoryContext\n ? `${options.systemPrompt}\\n\\n## Agent Memory\\n${options.memoryContext}`\n : options.systemPrompt;\n\n const systemMsg = { role: \"system\", content: systemContent };\n const systemTokens = estimateTokensImpl(systemContent);\n const conversationBudget = budget - systemTokens;\n\n // Truncate conversation to fit budget\n const arr = [...options.messages] as unknown[];\n while (arr.length > 1) {\n if (fitsInContextImpl(arr, conversationBudget)) break;\n arr.shift();\n }\n\n return [systemMsg, ...arr];\n }),\n});\n","import { Layer } from \"effect\";\nimport { EventBusLive } from \"./services/event-bus.js\";\nimport { AgentServiceLive } from \"./services/agent-service.js\";\nimport { TaskServiceLive } from \"./services/task-service.js\";\nimport { ContextWindowManagerLive } from \"./services/context-window-manager.js\";\n\n/**\n * Complete core services layer.\n * Provides: EventBus, AgentService, TaskService, ContextWindowManager\n *\n * Usage:\n * myProgram.pipe(Effect.provide(CoreServicesLive))\n */\nexport const CoreServicesLive = Layer.mergeAll(\n AgentServiceLive,\n TaskServiceLive,\n ContextWindowManagerLive,\n).pipe(Layer.provide(EventBusLive));\n"],"mappings":";AAAA,SAAS,cAAc;AAIhB,IAAM,UAAU,OAAO,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAK1D,IAAM,iBAAiB,OAAO;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,IAAM,mBAAmB,OAAO,OAAO;AAAA,EAC5C,MAAM;AAAA,EACN,MAAM,OAAO;AACf,CAAC;AAKM,IAAM,oBAAoB,OAAO;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAMO,IAAM,aAAa,OAAO;AAAA,EAC/B;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACF;AAKO,IAAM,cAAc,OAAO,OAAO;AAAA,EACvC,IAAI;AAAA,EACJ,MAAM,OAAO;AAAA,EACb,aAAa,OAAO,SAAS,OA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AAO,IAAI,SAAS,GAAG;AACrB,UAAI,kBAAkB,KAAK,kBAAkB,EAAG;AAChD,UAAI,MAAM;AAAA,IACZ;AAEA,WAAO,CAAC,WAAW,GAAG,GAAG;AAAA,EAC3B,CAAC;AACL,CAAC;;;ACrID,SAAS,SAAAI,cAAa;AAaf,IAAM,mBAAmBC,OAAM;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAKA,OAAM,QAAQ,YAAY,CAAC;","names":["Schema","Schema","Schema","Schema","Schema","Schema","Schema","Effect","Context","Layer","Ref","Context","Layer","Effect","Ref","m","Effect","Context","Layer","Ref","Context","Layer","Effect","Ref","m","Effect","Context","Layer","Data","Layer","Layer"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reactive-agents/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsup --config ../../tsup.config.base.ts",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
10
|
+
"test": "bun test",
|
|
11
|
+
"test:watch": "bun test --watch"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"effect": "^3.10.0",
|
|
15
|
+
"ulid": "^2.3.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0",
|
|
19
|
+
"bun-types": "latest"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/tylerjrbuell/reactive-agents-ts.git",
|
|
25
|
+
"directory": "packages/core"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"description": "Core services for Reactive Agents — EventBus, AgentService, TaskService, and shared types",
|
|
43
|
+
"homepage": "https://tylerjrbuell.github.io/reactive-agents-ts/",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/tylerjrbuell/reactive-agents-ts/issues"
|
|
46
|
+
}
|
|
47
|
+
}
|