@agentxjs/core 1.9.1-dev
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/package.json +31 -0
- package/src/agent/AgentStateMachine.ts +151 -0
- package/src/agent/README.md +296 -0
- package/src/agent/__tests__/AgentStateMachine.test.ts +346 -0
- package/src/agent/__tests__/createAgent.test.ts +728 -0
- package/src/agent/__tests__/engine/internal/messageAssemblerProcessor.test.ts +567 -0
- package/src/agent/__tests__/engine/internal/stateEventProcessor.test.ts +315 -0
- package/src/agent/__tests__/engine/internal/turnTrackerProcessor.test.ts +340 -0
- package/src/agent/__tests__/engine/mealy/Mealy.test.ts +370 -0
- package/src/agent/__tests__/engine/mealy/Store.test.ts +123 -0
- package/src/agent/__tests__/engine/mealy/combinators.test.ts +322 -0
- package/src/agent/createAgent.ts +467 -0
- package/src/agent/engine/AgentProcessor.ts +106 -0
- package/src/agent/engine/MealyMachine.ts +184 -0
- package/src/agent/engine/internal/index.ts +35 -0
- package/src/agent/engine/internal/messageAssemblerProcessor.ts +550 -0
- package/src/agent/engine/internal/stateEventProcessor.ts +313 -0
- package/src/agent/engine/internal/turnTrackerProcessor.ts +239 -0
- package/src/agent/engine/mealy/Mealy.ts +308 -0
- package/src/agent/engine/mealy/Processor.ts +70 -0
- package/src/agent/engine/mealy/Sink.ts +56 -0
- package/src/agent/engine/mealy/Source.ts +51 -0
- package/src/agent/engine/mealy/Store.ts +98 -0
- package/src/agent/engine/mealy/combinators.ts +176 -0
- package/src/agent/engine/mealy/index.ts +45 -0
- package/src/agent/index.ts +106 -0
- package/src/agent/types/engine.ts +395 -0
- package/src/agent/types/event.ts +478 -0
- package/src/agent/types/index.ts +197 -0
- package/src/agent/types/message.ts +387 -0
- package/src/common/index.ts +8 -0
- package/src/common/logger/ConsoleLogger.ts +137 -0
- package/src/common/logger/LoggerFactoryImpl.ts +123 -0
- package/src/common/logger/index.ts +26 -0
- package/src/common/logger/types.ts +98 -0
- package/src/container/Container.ts +185 -0
- package/src/container/index.ts +44 -0
- package/src/container/types.ts +71 -0
- package/src/driver/index.ts +42 -0
- package/src/driver/types.ts +363 -0
- package/src/event/EventBus.ts +260 -0
- package/src/event/README.md +237 -0
- package/src/event/__tests__/EventBus.test.ts +251 -0
- package/src/event/index.ts +46 -0
- package/src/event/types/agent.ts +512 -0
- package/src/event/types/base.ts +241 -0
- package/src/event/types/bus.ts +429 -0
- package/src/event/types/command.ts +749 -0
- package/src/event/types/container.ts +471 -0
- package/src/event/types/driver.ts +452 -0
- package/src/event/types/index.ts +26 -0
- package/src/event/types/session.ts +314 -0
- package/src/image/Image.ts +203 -0
- package/src/image/index.ts +36 -0
- package/src/image/types.ts +77 -0
- package/src/index.ts +20 -0
- package/src/mq/OffsetGenerator.ts +48 -0
- package/src/mq/README.md +166 -0
- package/src/mq/__tests__/OffsetGenerator.test.ts +121 -0
- package/src/mq/index.ts +18 -0
- package/src/mq/types.ts +172 -0
- package/src/network/RpcClient.ts +455 -0
- package/src/network/index.ts +76 -0
- package/src/network/jsonrpc.ts +336 -0
- package/src/network/protocol.ts +90 -0
- package/src/network/types.ts +284 -0
- package/src/persistence/index.ts +27 -0
- package/src/persistence/types.ts +226 -0
- package/src/runtime/AgentXRuntime.ts +501 -0
- package/src/runtime/index.ts +56 -0
- package/src/runtime/types.ts +236 -0
- package/src/session/Session.ts +71 -0
- package/src/session/index.ts +25 -0
- package/src/session/types.ts +77 -0
- package/src/workspace/index.ts +27 -0
- package/src/workspace/types.ts +131 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence Module
|
|
3
|
+
*
|
|
4
|
+
* Provides standard interfaces for data persistence:
|
|
5
|
+
* - ContainerRepository: Container CRUD operations
|
|
6
|
+
* - ImageRepository: Image (conversation) CRUD operations
|
|
7
|
+
* - SessionRepository: Session and message operations
|
|
8
|
+
*
|
|
9
|
+
* Implementations are provided by platform packages:
|
|
10
|
+
* - @agentxjs/node: SQLite-based repositories
|
|
11
|
+
* - @agentxjs/cloudflare: Durable Objects-based repositories
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
// Config types
|
|
16
|
+
McpServerConfig,
|
|
17
|
+
ContainerConfig,
|
|
18
|
+
ImageMetadata,
|
|
19
|
+
// Record types
|
|
20
|
+
ContainerRecord,
|
|
21
|
+
ImageRecord,
|
|
22
|
+
SessionRecord,
|
|
23
|
+
// Repository interfaces
|
|
24
|
+
ContainerRepository,
|
|
25
|
+
ImageRepository,
|
|
26
|
+
SessionRepository,
|
|
27
|
+
} from "./types";
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistence Types - Repository interfaces and record types
|
|
3
|
+
*
|
|
4
|
+
* Defines standard interfaces for data persistence.
|
|
5
|
+
* Implementations are provided by platform packages (node, cloudflare).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Message } from "../agent/types";
|
|
9
|
+
import type { McpServerConfig } from "../driver/types";
|
|
10
|
+
|
|
11
|
+
// Re-export McpServerConfig for convenience
|
|
12
|
+
export type { McpServerConfig } from "../driver/types";
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Container Record
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Container configuration (extensible)
|
|
20
|
+
*/
|
|
21
|
+
export interface ContainerConfig {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ContainerRecord - Persistent container data
|
|
27
|
+
*
|
|
28
|
+
* Represents a logical container (resource isolation unit).
|
|
29
|
+
* Each container provides an isolated environment for running Agents.
|
|
30
|
+
*/
|
|
31
|
+
export interface ContainerRecord {
|
|
32
|
+
/** Unique container identifier */
|
|
33
|
+
containerId: string;
|
|
34
|
+
|
|
35
|
+
/** Container creation timestamp (Unix milliseconds) */
|
|
36
|
+
createdAt: number;
|
|
37
|
+
|
|
38
|
+
/** Last update timestamp (Unix milliseconds) */
|
|
39
|
+
updatedAt: number;
|
|
40
|
+
|
|
41
|
+
/** Container configuration (extensible) */
|
|
42
|
+
config?: ContainerConfig;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Image Record
|
|
47
|
+
// ============================================================================
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Image metadata for storing provider-specific data
|
|
51
|
+
*/
|
|
52
|
+
export interface ImageMetadata {
|
|
53
|
+
/** Claude SDK session ID for conversation resume */
|
|
54
|
+
claudeSdkSessionId?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* ImageRecord - Persistent representation of a conversation
|
|
59
|
+
*
|
|
60
|
+
* Image is the primary entity users interact with (displayed as "conversation").
|
|
61
|
+
* Agent is a transient runtime instance created from Image.
|
|
62
|
+
*
|
|
63
|
+
* Lifecycle:
|
|
64
|
+
* - image_create → ImageRecord (persistent)
|
|
65
|
+
* - image_run → Agent (runtime, in-memory)
|
|
66
|
+
* - image_stop / server restart → Agent destroyed, Image remains
|
|
67
|
+
*/
|
|
68
|
+
export interface ImageRecord {
|
|
69
|
+
/** Unique image identifier (pattern: `img_${nanoid()}`) */
|
|
70
|
+
imageId: string;
|
|
71
|
+
|
|
72
|
+
/** Container ID (user isolation boundary) */
|
|
73
|
+
containerId: string;
|
|
74
|
+
|
|
75
|
+
/** Session ID for message storage */
|
|
76
|
+
sessionId: string;
|
|
77
|
+
|
|
78
|
+
/** Conversation name (displayed to user) */
|
|
79
|
+
name: string;
|
|
80
|
+
|
|
81
|
+
/** Conversation description (optional) */
|
|
82
|
+
description?: string;
|
|
83
|
+
|
|
84
|
+
/** System prompt - controls agent behavior */
|
|
85
|
+
systemPrompt?: string;
|
|
86
|
+
|
|
87
|
+
/** Parent image ID (for fork/branch feature) */
|
|
88
|
+
parentImageId?: string;
|
|
89
|
+
|
|
90
|
+
/** MCP servers configuration */
|
|
91
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
92
|
+
|
|
93
|
+
/** Provider-specific metadata */
|
|
94
|
+
metadata?: ImageMetadata;
|
|
95
|
+
|
|
96
|
+
/** Creation timestamp (Unix milliseconds) */
|
|
97
|
+
createdAt: number;
|
|
98
|
+
|
|
99
|
+
/** Last update timestamp (Unix milliseconds) */
|
|
100
|
+
updatedAt: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// Session Record
|
|
105
|
+
// ============================================================================
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* SessionRecord - Storage schema for Session persistence
|
|
109
|
+
*
|
|
110
|
+
* Session stores conversation messages for an Image.
|
|
111
|
+
* Each Image has exactly one Session.
|
|
112
|
+
*/
|
|
113
|
+
export interface SessionRecord {
|
|
114
|
+
/** Unique session identifier */
|
|
115
|
+
sessionId: string;
|
|
116
|
+
|
|
117
|
+
/** Associated image ID (owner of this session) */
|
|
118
|
+
imageId: string;
|
|
119
|
+
|
|
120
|
+
/** Container this session belongs to */
|
|
121
|
+
containerId: string;
|
|
122
|
+
|
|
123
|
+
/** Creation timestamp (Unix milliseconds) */
|
|
124
|
+
createdAt: number;
|
|
125
|
+
|
|
126
|
+
/** Last update timestamp (Unix milliseconds) */
|
|
127
|
+
updatedAt: number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// Container Repository
|
|
132
|
+
// ============================================================================
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* ContainerRepository - Storage operations for containers
|
|
136
|
+
*/
|
|
137
|
+
export interface ContainerRepository {
|
|
138
|
+
/** Save a container record (create or update) */
|
|
139
|
+
saveContainer(record: ContainerRecord): Promise<void>;
|
|
140
|
+
|
|
141
|
+
/** Find container by ID */
|
|
142
|
+
findContainerById(containerId: string): Promise<ContainerRecord | null>;
|
|
143
|
+
|
|
144
|
+
/** Find all containers */
|
|
145
|
+
findAllContainers(): Promise<ContainerRecord[]>;
|
|
146
|
+
|
|
147
|
+
/** Delete container by ID */
|
|
148
|
+
deleteContainer(containerId: string): Promise<void>;
|
|
149
|
+
|
|
150
|
+
/** Check if container exists */
|
|
151
|
+
containerExists(containerId: string): Promise<boolean>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ============================================================================
|
|
155
|
+
// Image Repository
|
|
156
|
+
// ============================================================================
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* ImageRepository - Storage operations for images
|
|
160
|
+
*/
|
|
161
|
+
export interface ImageRepository {
|
|
162
|
+
/** Save an image record (create or update) */
|
|
163
|
+
saveImage(record: ImageRecord): Promise<void>;
|
|
164
|
+
|
|
165
|
+
/** Find image by ID */
|
|
166
|
+
findImageById(imageId: string): Promise<ImageRecord | null>;
|
|
167
|
+
|
|
168
|
+
/** Find all images */
|
|
169
|
+
findAllImages(): Promise<ImageRecord[]>;
|
|
170
|
+
|
|
171
|
+
/** Find images by agent name */
|
|
172
|
+
findImagesByName(name: string): Promise<ImageRecord[]>;
|
|
173
|
+
|
|
174
|
+
/** Find images by container ID */
|
|
175
|
+
findImagesByContainerId(containerId: string): Promise<ImageRecord[]>;
|
|
176
|
+
|
|
177
|
+
/** Delete image by ID */
|
|
178
|
+
deleteImage(imageId: string): Promise<void>;
|
|
179
|
+
|
|
180
|
+
/** Check if image exists */
|
|
181
|
+
imageExists(imageId: string): Promise<boolean>;
|
|
182
|
+
|
|
183
|
+
/** Update image metadata (merges with existing) */
|
|
184
|
+
updateMetadata(imageId: string, metadata: Partial<ImageMetadata>): Promise<void>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// Session Repository
|
|
189
|
+
// ============================================================================
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* SessionRepository - Storage operations for sessions
|
|
193
|
+
*/
|
|
194
|
+
export interface SessionRepository {
|
|
195
|
+
/** Save a session record (create or update) */
|
|
196
|
+
saveSession(record: SessionRecord): Promise<void>;
|
|
197
|
+
|
|
198
|
+
/** Find session by ID */
|
|
199
|
+
findSessionById(sessionId: string): Promise<SessionRecord | null>;
|
|
200
|
+
|
|
201
|
+
/** Find session by image ID */
|
|
202
|
+
findSessionByImageId(imageId: string): Promise<SessionRecord | null>;
|
|
203
|
+
|
|
204
|
+
/** Find all sessions for a container */
|
|
205
|
+
findSessionsByContainerId(containerId: string): Promise<SessionRecord[]>;
|
|
206
|
+
|
|
207
|
+
/** Find all sessions */
|
|
208
|
+
findAllSessions(): Promise<SessionRecord[]>;
|
|
209
|
+
|
|
210
|
+
/** Delete session by ID */
|
|
211
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
212
|
+
|
|
213
|
+
/** Check if session exists */
|
|
214
|
+
sessionExists(sessionId: string): Promise<boolean>;
|
|
215
|
+
|
|
216
|
+
// ==================== Message Operations ====================
|
|
217
|
+
|
|
218
|
+
/** Add a message to a session */
|
|
219
|
+
addMessage(sessionId: string, message: Message): Promise<void>;
|
|
220
|
+
|
|
221
|
+
/** Get all messages for a session */
|
|
222
|
+
getMessages(sessionId: string): Promise<Message[]>;
|
|
223
|
+
|
|
224
|
+
/** Clear all messages for a session */
|
|
225
|
+
clearMessages(sessionId: string): Promise<void>;
|
|
226
|
+
}
|