@agentxjs/core 1.9.9-dev → 2.0.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/README.md +342 -0
- package/dist/RpcClient-BcJ_zAGu.d.ts +304 -0
- package/dist/agent/engine/internal/index.d.ts +20 -15
- package/dist/agent/engine/internal/index.js +1 -2
- package/dist/agent/engine/mealy/index.js +0 -1
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.js +6 -6
- package/dist/agent/types/index.d.ts +4 -4
- package/dist/agent/types/index.js +1 -2
- package/dist/bash/index.d.ts +29 -0
- package/dist/bash/index.js +7 -0
- package/dist/{bus-uF1DM2ox.d.ts → bus-C9FLWIu8.d.ts} +3 -1
- package/dist/{chunk-K6WXQ2RW.js → chunk-23UUBQXR.js} +1 -2
- package/dist/chunk-23UUBQXR.js.map +1 -0
- package/dist/chunk-BHOD5PKR.js +55 -0
- package/dist/chunk-BHOD5PKR.js.map +1 -0
- package/dist/{chunk-I7GYR3MN.js → chunk-DEAR6N3O.js} +77 -91
- package/dist/chunk-DEAR6N3O.js.map +1 -0
- package/dist/chunk-FI7WQFGV.js +37 -0
- package/dist/chunk-FI7WQFGV.js.map +1 -0
- package/dist/{chunk-TBU7FFZT.js → chunk-JTKCV7IS.js} +4 -4
- package/dist/chunk-JTKCV7IS.js.map +1 -0
- package/dist/{chunk-E5FPOAPO.js → chunk-LTVNPHST.js} +1 -1
- package/dist/chunk-LTVNPHST.js.map +1 -0
- package/dist/chunk-SKS7S2RY.js +1 -0
- package/dist/common/logger/index.js +0 -2
- package/dist/common/logger/index.js.map +1 -1
- package/dist/container/index.d.ts +3 -4
- package/dist/container/index.js +0 -2
- package/dist/container/index.js.map +1 -1
- package/dist/driver/index.d.ts +2 -310
- package/dist/event/index.d.ts +4 -4
- package/dist/event/index.js +1 -2
- package/dist/event/types/index.d.ts +4 -10
- package/dist/event/types/index.js +1 -2
- package/dist/{event-CDuTzs__.d.ts → event-DNWOBSBO.d.ts} +3 -4
- package/dist/image/index.d.ts +9 -5
- package/dist/image/index.js +5 -2
- package/dist/image/index.js.map +1 -1
- package/dist/index-CuS1i5V-.d.ts +609 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/{message-BMrMm1pq.d.ts → message-03TJzvIX.d.ts} +10 -33
- package/dist/mq/index.js +0 -2
- package/dist/mq/index.js.map +1 -1
- package/dist/network/index.d.ts +3 -291
- package/dist/network/index.js +3 -14
- package/dist/network/index.js.map +1 -1
- package/dist/persistence/index.d.ts +2 -155
- package/dist/platform/index.d.ts +76 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/runtime/index.d.ts +26 -59
- package/dist/runtime/index.js +117 -33
- package/dist/runtime/index.js.map +1 -1
- package/dist/session/index.d.ts +4 -52
- package/dist/session/index.js +4 -51
- package/dist/session/index.js.map +1 -1
- package/dist/types-aE74Eo6G.d.ts +90 -0
- package/package.json +10 -5
- package/src/agent/__tests__/engine/internal/messageAssemblerProcessor.test.ts +291 -87
- package/src/agent/__tests__/engine/internal/turnTrackerProcessor.test.ts +56 -75
- package/src/agent/engine/MealyMachine.ts +1 -1
- package/src/agent/engine/internal/messageAssemblerProcessor.ts +99 -114
- package/src/agent/engine/internal/turnTrackerProcessor.ts +23 -27
- package/src/agent/types/event.ts +0 -4
- package/src/agent/types/index.ts +1 -3
- package/src/agent/types/message.ts +9 -43
- package/src/bash/index.ts +21 -0
- package/src/bash/tool.ts +57 -0
- package/src/bash/types.ts +108 -0
- package/src/driver/index.ts +1 -0
- package/src/driver/types.ts +122 -4
- package/src/event/__tests__/EventBus.test.ts +1 -1
- package/src/event/types/agent.ts +0 -11
- package/src/event/types/command.ts +3 -1
- package/src/image/Image.ts +11 -1
- package/src/image/types.ts +8 -2
- package/src/network/RpcClient.ts +21 -20
- package/src/network/index.ts +1 -1
- package/src/persistence/types.ts +5 -2
- package/src/platform/index.ts +21 -0
- package/src/platform/types.ts +84 -0
- package/src/runtime/AgentXRuntime.ts +184 -57
- package/src/runtime/__tests__/AgentXRuntime.test.ts +343 -0
- package/src/runtime/index.ts +7 -19
- package/src/runtime/types.ts +10 -62
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-E5FPOAPO.js.map +0 -1
- package/dist/chunk-I7GYR3MN.js.map +0 -1
- package/dist/chunk-K6WXQ2RW.js.map +0 -1
- package/dist/chunk-TBU7FFZT.js.map +0 -1
- package/dist/workspace/index.d.ts +0 -111
- package/dist/wrapper-Y3UTVU2E.js +0 -3635
- package/dist/wrapper-Y3UTVU2E.js.map +0 -1
- package/src/workspace/index.ts +0 -27
- package/src/workspace/types.ts +0 -131
- /package/dist/{workspace → bash}/index.js.map +0 -0
- /package/dist/{chunk-7D4SUZUM.js.map → chunk-SKS7S2RY.js.map} +0 -0
- /package/dist/{workspace → platform}/index.js +0 -0
|
@@ -1,155 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Persistence Types - Repository interfaces and record types
|
|
6
|
-
*
|
|
7
|
-
* Defines standard interfaces for data persistence.
|
|
8
|
-
* Implementations are provided by platform packages (node, cloudflare).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Container configuration (extensible)
|
|
13
|
-
*/
|
|
14
|
-
interface ContainerConfig {
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* ContainerRecord - Persistent container data
|
|
19
|
-
*
|
|
20
|
-
* Represents a logical container (resource isolation unit).
|
|
21
|
-
* Each container provides an isolated environment for running Agents.
|
|
22
|
-
*/
|
|
23
|
-
interface ContainerRecord {
|
|
24
|
-
/** Unique container identifier */
|
|
25
|
-
containerId: string;
|
|
26
|
-
/** Container creation timestamp (Unix milliseconds) */
|
|
27
|
-
createdAt: number;
|
|
28
|
-
/** Last update timestamp (Unix milliseconds) */
|
|
29
|
-
updatedAt: number;
|
|
30
|
-
/** Container configuration (extensible) */
|
|
31
|
-
config?: ContainerConfig;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Image metadata for storing provider-specific data
|
|
35
|
-
*/
|
|
36
|
-
interface ImageMetadata {
|
|
37
|
-
/** Claude SDK session ID for conversation resume */
|
|
38
|
-
claudeSdkSessionId?: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* ImageRecord - Persistent representation of a conversation
|
|
42
|
-
*
|
|
43
|
-
* Image is the primary entity users interact with (displayed as "conversation").
|
|
44
|
-
* Agent is a transient runtime instance created from Image.
|
|
45
|
-
*
|
|
46
|
-
* Lifecycle:
|
|
47
|
-
* - image_create → ImageRecord (persistent)
|
|
48
|
-
* - image_run → Agent (runtime, in-memory)
|
|
49
|
-
* - image_stop / server restart → Agent destroyed, Image remains
|
|
50
|
-
*/
|
|
51
|
-
interface ImageRecord {
|
|
52
|
-
/** Unique image identifier (pattern: `img_${nanoid()}`) */
|
|
53
|
-
imageId: string;
|
|
54
|
-
/** Container ID (user isolation boundary) */
|
|
55
|
-
containerId: string;
|
|
56
|
-
/** Session ID for message storage */
|
|
57
|
-
sessionId: string;
|
|
58
|
-
/** Conversation name (displayed to user) */
|
|
59
|
-
name: string;
|
|
60
|
-
/** Conversation description (optional) */
|
|
61
|
-
description?: string;
|
|
62
|
-
/** System prompt - controls agent behavior */
|
|
63
|
-
systemPrompt?: string;
|
|
64
|
-
/** Parent image ID (for fork/branch feature) */
|
|
65
|
-
parentImageId?: string;
|
|
66
|
-
/** MCP servers configuration */
|
|
67
|
-
mcpServers?: Record<string, McpServerConfig>;
|
|
68
|
-
/** Provider-specific metadata */
|
|
69
|
-
metadata?: ImageMetadata;
|
|
70
|
-
/** Creation timestamp (Unix milliseconds) */
|
|
71
|
-
createdAt: number;
|
|
72
|
-
/** Last update timestamp (Unix milliseconds) */
|
|
73
|
-
updatedAt: number;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* SessionRecord - Storage schema for Session persistence
|
|
77
|
-
*
|
|
78
|
-
* Session stores conversation messages for an Image.
|
|
79
|
-
* Each Image has exactly one Session.
|
|
80
|
-
*/
|
|
81
|
-
interface SessionRecord {
|
|
82
|
-
/** Unique session identifier */
|
|
83
|
-
sessionId: string;
|
|
84
|
-
/** Associated image ID (owner of this session) */
|
|
85
|
-
imageId: string;
|
|
86
|
-
/** Container this session belongs to */
|
|
87
|
-
containerId: string;
|
|
88
|
-
/** Creation timestamp (Unix milliseconds) */
|
|
89
|
-
createdAt: number;
|
|
90
|
-
/** Last update timestamp (Unix milliseconds) */
|
|
91
|
-
updatedAt: number;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* ContainerRepository - Storage operations for containers
|
|
95
|
-
*/
|
|
96
|
-
interface ContainerRepository {
|
|
97
|
-
/** Save a container record (create or update) */
|
|
98
|
-
saveContainer(record: ContainerRecord): Promise<void>;
|
|
99
|
-
/** Find container by ID */
|
|
100
|
-
findContainerById(containerId: string): Promise<ContainerRecord | null>;
|
|
101
|
-
/** Find all containers */
|
|
102
|
-
findAllContainers(): Promise<ContainerRecord[]>;
|
|
103
|
-
/** Delete container by ID */
|
|
104
|
-
deleteContainer(containerId: string): Promise<void>;
|
|
105
|
-
/** Check if container exists */
|
|
106
|
-
containerExists(containerId: string): Promise<boolean>;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* ImageRepository - Storage operations for images
|
|
110
|
-
*/
|
|
111
|
-
interface ImageRepository {
|
|
112
|
-
/** Save an image record (create or update) */
|
|
113
|
-
saveImage(record: ImageRecord): Promise<void>;
|
|
114
|
-
/** Find image by ID */
|
|
115
|
-
findImageById(imageId: string): Promise<ImageRecord | null>;
|
|
116
|
-
/** Find all images */
|
|
117
|
-
findAllImages(): Promise<ImageRecord[]>;
|
|
118
|
-
/** Find images by agent name */
|
|
119
|
-
findImagesByName(name: string): Promise<ImageRecord[]>;
|
|
120
|
-
/** Find images by container ID */
|
|
121
|
-
findImagesByContainerId(containerId: string): Promise<ImageRecord[]>;
|
|
122
|
-
/** Delete image by ID */
|
|
123
|
-
deleteImage(imageId: string): Promise<void>;
|
|
124
|
-
/** Check if image exists */
|
|
125
|
-
imageExists(imageId: string): Promise<boolean>;
|
|
126
|
-
/** Update image metadata (merges with existing) */
|
|
127
|
-
updateMetadata(imageId: string, metadata: Partial<ImageMetadata>): Promise<void>;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* SessionRepository - Storage operations for sessions
|
|
131
|
-
*/
|
|
132
|
-
interface SessionRepository {
|
|
133
|
-
/** Save a session record (create or update) */
|
|
134
|
-
saveSession(record: SessionRecord): Promise<void>;
|
|
135
|
-
/** Find session by ID */
|
|
136
|
-
findSessionById(sessionId: string): Promise<SessionRecord | null>;
|
|
137
|
-
/** Find session by image ID */
|
|
138
|
-
findSessionByImageId(imageId: string): Promise<SessionRecord | null>;
|
|
139
|
-
/** Find all sessions for a container */
|
|
140
|
-
findSessionsByContainerId(containerId: string): Promise<SessionRecord[]>;
|
|
141
|
-
/** Find all sessions */
|
|
142
|
-
findAllSessions(): Promise<SessionRecord[]>;
|
|
143
|
-
/** Delete session by ID */
|
|
144
|
-
deleteSession(sessionId: string): Promise<void>;
|
|
145
|
-
/** Check if session exists */
|
|
146
|
-
sessionExists(sessionId: string): Promise<boolean>;
|
|
147
|
-
/** Add a message to a session */
|
|
148
|
-
addMessage(sessionId: string, message: Message): Promise<void>;
|
|
149
|
-
/** Get all messages for a session */
|
|
150
|
-
getMessages(sessionId: string): Promise<Message[]>;
|
|
151
|
-
/** Clear all messages for a session */
|
|
152
|
-
clearMessages(sessionId: string): Promise<void>;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { type ContainerConfig, type ContainerRecord, type ContainerRepository, type ImageMetadata, type ImageRecord, type ImageRepository, McpServerConfig, type SessionRecord, type SessionRepository };
|
|
1
|
+
export { e as ContainerConfig, C as ContainerRecord, d as ContainerRepository, g as ImageMetadata, f as ImageRecord, I as ImageRepository, M as McpServerConfig, b as SessionRecord, c as SessionRepository } from '../index-CuS1i5V-.js';
|
|
2
|
+
import '../message-03TJzvIX.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { d as ContainerRepository, I as ImageRepository, c as SessionRepository } from '../index-CuS1i5V-.js';
|
|
2
|
+
import { E as EventBus } from '../bus-C9FLWIu8.js';
|
|
3
|
+
import { B as BashProvider } from '../types-aE74Eo6G.js';
|
|
4
|
+
import { W as WebSocketFactory } from '../RpcClient-BcJ_zAGu.js';
|
|
5
|
+
import '../message-03TJzvIX.js';
|
|
6
|
+
import '../base-m40r3Qgu.js';
|
|
7
|
+
import 'jsonrpc-lite';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Platform Types
|
|
11
|
+
*
|
|
12
|
+
* AgentXPlatform - Dependency injection container for platform capabilities.
|
|
13
|
+
* Platform packages (node-platform, etc.) provide implementations.
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* ┌─────────────────────────────────────────────────────────────┐
|
|
17
|
+
* │ AgentXPlatform │
|
|
18
|
+
* │ (Dependency Injection - Platform provides implementations) │
|
|
19
|
+
* │ │
|
|
20
|
+
* │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
21
|
+
* │ │ Repositories│ │ EventBus │ │ Providers │ │
|
|
22
|
+
* │ │ Container │ │ │ │ Bash (opt) │ │
|
|
23
|
+
* │ │ Image │ │ │ │ │ │
|
|
24
|
+
* │ │ Session │ │ │ │ │ │
|
|
25
|
+
* │ └─────────────┘ └─────────────┘ └─────────────┘ │
|
|
26
|
+
* └─────────────────────────────────────────────────────────────┘
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* AgentXPlatform - Collects all dependencies for runtime
|
|
32
|
+
*
|
|
33
|
+
* Platform packages provide implementations of these interfaces.
|
|
34
|
+
* The platform is passed to AgentXRuntime for integration.
|
|
35
|
+
*
|
|
36
|
+
* Required capabilities:
|
|
37
|
+
* - containerRepository, imageRepository, sessionRepository — persistence
|
|
38
|
+
* - eventBus — pub/sub
|
|
39
|
+
*
|
|
40
|
+
* Optional capabilities:
|
|
41
|
+
* - bashProvider — command execution (not all platforms support this)
|
|
42
|
+
*/
|
|
43
|
+
interface AgentXPlatform {
|
|
44
|
+
/**
|
|
45
|
+
* Container repository for persistence
|
|
46
|
+
*/
|
|
47
|
+
readonly containerRepository: ContainerRepository;
|
|
48
|
+
/**
|
|
49
|
+
* Image repository for persistence
|
|
50
|
+
*/
|
|
51
|
+
readonly imageRepository: ImageRepository;
|
|
52
|
+
/**
|
|
53
|
+
* Session repository for persistence
|
|
54
|
+
*/
|
|
55
|
+
readonly sessionRepository: SessionRepository;
|
|
56
|
+
/**
|
|
57
|
+
* Event bus for pub/sub
|
|
58
|
+
*/
|
|
59
|
+
readonly eventBus: EventBus;
|
|
60
|
+
/**
|
|
61
|
+
* Bash provider for command execution
|
|
62
|
+
*
|
|
63
|
+
* Optional — not all platforms support shell execution.
|
|
64
|
+
* Node.js platform provides child_process based implementation.
|
|
65
|
+
*/
|
|
66
|
+
readonly bashProvider?: BashProvider;
|
|
67
|
+
/**
|
|
68
|
+
* WebSocket factory for creating client connections
|
|
69
|
+
*
|
|
70
|
+
* Optional — browser uses native WebSocket by default.
|
|
71
|
+
* Node.js platform provides ws-based implementation.
|
|
72
|
+
*/
|
|
73
|
+
readonly webSocketFactory?: WebSocketFactory;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type { AgentXPlatform };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as UserContentPart } from '../message-BMrMm1pq.js';
|
|
4
|
-
import { WorkspaceProvider } from '../workspace/index.js';
|
|
1
|
+
import { AgentXPlatform } from '../platform/index.js';
|
|
2
|
+
import { b as UserContentPart } from '../message-03TJzvIX.js';
|
|
5
3
|
import { B as BusEvent } from '../base-m40r3Qgu.js';
|
|
6
|
-
import {
|
|
4
|
+
import { h as CreateDriver } from '../index-CuS1i5V-.js';
|
|
5
|
+
import '../bus-C9FLWIu8.js';
|
|
6
|
+
import '../types-aE74Eo6G.js';
|
|
7
|
+
import '../RpcClient-BcJ_zAGu.js';
|
|
8
|
+
import 'jsonrpc-lite';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Runtime Types
|
|
10
12
|
*
|
|
11
|
-
* AgentXProvider - Dependency injection container
|
|
12
13
|
* AgentXRuntime - Runtime integration layer
|
|
13
14
|
*
|
|
14
15
|
* Architecture:
|
|
15
16
|
* ```
|
|
16
17
|
* ┌─────────────────────────────────────────────────────────────┐
|
|
17
|
-
* │
|
|
18
|
-
* │
|
|
19
|
-
* │ │
|
|
20
|
-
* │ ┌─────────────┐ ┌─────────────┐ ┌───────────────┐ │
|
|
21
|
-
* │ │ Repositories│ │ Workspace │ │ DriverFactory │ │
|
|
22
|
-
* │ │ Container │ │ Provider │ │ (per-Agent) │ │
|
|
23
|
-
* │ │ Image │ │ │ │ │ │
|
|
24
|
-
* │ │ Session │ │ │ │ │ │
|
|
25
|
-
* │ └─────────────┘ └─────────────┘ └─────────────┘ │
|
|
18
|
+
* │ AgentXPlatform │
|
|
19
|
+
* │ (see @agentxjs/core/platform) │
|
|
26
20
|
* └─────────────────────────────────────────────────────────────┘
|
|
27
21
|
* │
|
|
28
22
|
* ▼
|
|
29
23
|
* ┌─────────────────────────────────────────────────────────────┐
|
|
30
24
|
* │ AgentXRuntime │
|
|
31
|
-
* │ (Integration - Uses
|
|
25
|
+
* │ (Integration - Uses Platform dependencies) │
|
|
32
26
|
* │ │
|
|
33
27
|
* │ ┌─────────────────────────────────────────────────────┐ │
|
|
34
28
|
* │ │ Agent Lifecycle: create / get / destroy │ │
|
|
@@ -55,38 +49,6 @@ interface RuntimeAgent {
|
|
|
55
49
|
readonly lifecycle: AgentLifecycle;
|
|
56
50
|
readonly createdAt: number;
|
|
57
51
|
}
|
|
58
|
-
/**
|
|
59
|
-
* AgentXProvider - Collects all dependencies for runtime
|
|
60
|
-
*
|
|
61
|
-
* Platform packages provide implementations of these interfaces.
|
|
62
|
-
* The provider is passed to AgentXRuntime for integration.
|
|
63
|
-
*/
|
|
64
|
-
interface AgentXProvider {
|
|
65
|
-
/**
|
|
66
|
-
* Container repository for persistence
|
|
67
|
-
*/
|
|
68
|
-
readonly containerRepository: ContainerRepository;
|
|
69
|
-
/**
|
|
70
|
-
* Image repository for persistence
|
|
71
|
-
*/
|
|
72
|
-
readonly imageRepository: ImageRepository;
|
|
73
|
-
/**
|
|
74
|
-
* Session repository for persistence
|
|
75
|
-
*/
|
|
76
|
-
readonly sessionRepository: SessionRepository;
|
|
77
|
-
/**
|
|
78
|
-
* Workspace provider for isolated environments
|
|
79
|
-
*/
|
|
80
|
-
readonly workspaceProvider: WorkspaceProvider;
|
|
81
|
-
/**
|
|
82
|
-
* LLM Driver factory function - creates Driver per Agent
|
|
83
|
-
*/
|
|
84
|
-
readonly createDriver: CreateDriver;
|
|
85
|
-
/**
|
|
86
|
-
* Event bus for pub/sub
|
|
87
|
-
*/
|
|
88
|
-
readonly eventBus: EventBus;
|
|
89
|
-
}
|
|
90
52
|
/**
|
|
91
53
|
* Agent creation options
|
|
92
54
|
*/
|
|
@@ -118,9 +80,9 @@ interface Subscription {
|
|
|
118
80
|
*/
|
|
119
81
|
interface AgentXRuntime {
|
|
120
82
|
/**
|
|
121
|
-
* The
|
|
83
|
+
* The platform containing all dependencies
|
|
122
84
|
*/
|
|
123
|
-
readonly
|
|
85
|
+
readonly platform: AgentXPlatform;
|
|
124
86
|
/**
|
|
125
87
|
* Create and start an agent from an image
|
|
126
88
|
*/
|
|
@@ -176,7 +138,7 @@ interface AgentXRuntime {
|
|
|
176
138
|
* Configuration for creating AgentXRuntime
|
|
177
139
|
*/
|
|
178
140
|
interface AgentXRuntimeConfig {
|
|
179
|
-
|
|
141
|
+
platform: AgentXPlatform;
|
|
180
142
|
}
|
|
181
143
|
/**
|
|
182
144
|
* Factory function type for creating AgentXRuntime
|
|
@@ -187,23 +149,25 @@ type CreateAgentXRuntime = (config: AgentXRuntimeConfig) => AgentXRuntime;
|
|
|
187
149
|
* AgentXRuntimeImpl - Runtime integration implementation
|
|
188
150
|
*
|
|
189
151
|
* Integrates all components to provide agent lifecycle management.
|
|
190
|
-
* Uses
|
|
152
|
+
* Uses Platform dependencies to coordinate Session, Image, Container, etc.
|
|
191
153
|
*
|
|
192
|
-
*
|
|
154
|
+
* Architecture:
|
|
193
155
|
* - Driver.receive() returns AsyncIterable<DriverStreamEvent>
|
|
194
|
-
* - Runtime
|
|
195
|
-
* -
|
|
156
|
+
* - Runtime emits raw stream events to EventBus
|
|
157
|
+
* - Runtime pushes events through AgentEngine (MealyMachine → Presenter)
|
|
158
|
+
* - Presenter emits message/state/turn events and persists messages
|
|
196
159
|
*/
|
|
197
160
|
|
|
198
161
|
/**
|
|
199
162
|
* AgentXRuntimeImpl - Runtime implementation
|
|
200
163
|
*/
|
|
201
164
|
declare class AgentXRuntimeImpl implements AgentXRuntime {
|
|
202
|
-
readonly
|
|
165
|
+
readonly platform: AgentXPlatform;
|
|
166
|
+
private readonly createDriver;
|
|
203
167
|
private agents;
|
|
204
168
|
private globalSubscriptions;
|
|
205
169
|
private isShutdown;
|
|
206
|
-
constructor(
|
|
170
|
+
constructor(platform: AgentXPlatform, createDriver: CreateDriver);
|
|
207
171
|
createAgent(options: CreateAgentOptions): Promise<RuntimeAgent>;
|
|
208
172
|
getAgent(agentId: string): RuntimeAgent | undefined;
|
|
209
173
|
getAgents(): RuntimeAgent[];
|
|
@@ -234,7 +198,10 @@ declare class AgentXRuntimeImpl implements AgentXRuntime {
|
|
|
234
198
|
}
|
|
235
199
|
/**
|
|
236
200
|
* Create an AgentXRuntime instance
|
|
201
|
+
*
|
|
202
|
+
* @param platform - AgentXPlatform with repositories and event bus
|
|
203
|
+
* @param createDriver - Factory function for creating Driver instances per Agent
|
|
237
204
|
*/
|
|
238
|
-
declare function createAgentXRuntime(
|
|
205
|
+
declare function createAgentXRuntime(platform: AgentXPlatform, createDriver: CreateDriver): AgentXRuntime;
|
|
239
206
|
|
|
240
|
-
export { type AgentEventHandler, type AgentLifecycle,
|
|
207
|
+
export { type AgentEventHandler, type AgentLifecycle, AgentXPlatform, type AgentXRuntime, type AgentXRuntimeConfig, AgentXRuntimeImpl, type CreateAgentOptions, type CreateAgentXRuntime, type RuntimeAgent, type Subscription, createAgentXRuntime };
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
createSession
|
|
3
|
+
} from "../chunk-BHOD5PKR.js";
|
|
4
|
+
import {
|
|
5
|
+
createAgent
|
|
6
|
+
} from "../chunk-JTKCV7IS.js";
|
|
7
|
+
import "../chunk-DEAR6N3O.js";
|
|
8
|
+
import "../chunk-EKHT54KN.js";
|
|
9
|
+
import "../chunk-23UUBQXR.js";
|
|
10
|
+
import {
|
|
11
|
+
createBashTool
|
|
12
|
+
} from "../chunk-FI7WQFGV.js";
|
|
13
|
+
import "../chunk-7ZDX3O6I.js";
|
|
14
|
+
import "../chunk-LTVNPHST.js";
|
|
2
15
|
|
|
3
16
|
// src/runtime/AgentXRuntime.ts
|
|
4
17
|
import { createLogger } from "commonxjs/logger";
|
|
5
18
|
var logger = createLogger("runtime/AgentXRuntime");
|
|
6
19
|
var AgentXRuntimeImpl = class {
|
|
7
|
-
|
|
20
|
+
platform;
|
|
21
|
+
createDriver;
|
|
8
22
|
agents = /* @__PURE__ */ new Map();
|
|
9
23
|
globalSubscriptions = /* @__PURE__ */ new Set();
|
|
10
24
|
isShutdown = false;
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
25
|
+
constructor(platform, createDriver) {
|
|
26
|
+
this.platform = platform;
|
|
27
|
+
this.createDriver = createDriver;
|
|
13
28
|
logger.info("AgentXRuntime initialized");
|
|
14
29
|
}
|
|
15
30
|
// ==================== Agent Lifecycle ====================
|
|
@@ -18,36 +33,85 @@ var AgentXRuntimeImpl = class {
|
|
|
18
33
|
throw new Error("Runtime is shutdown");
|
|
19
34
|
}
|
|
20
35
|
const { imageId } = options;
|
|
21
|
-
const imageRecord = await this.
|
|
36
|
+
const imageRecord = await this.platform.imageRepository.findImageById(imageId);
|
|
22
37
|
if (!imageRecord) {
|
|
23
38
|
throw new Error(`Image not found: ${imageId}`);
|
|
24
39
|
}
|
|
25
40
|
const agentId = options.agentId ?? this.generateAgentId();
|
|
26
|
-
const containerExists = await this.
|
|
41
|
+
const containerExists = await this.platform.containerRepository.containerExists(
|
|
27
42
|
imageRecord.containerId
|
|
28
43
|
);
|
|
29
44
|
if (!containerExists) {
|
|
30
45
|
throw new Error(`Container not found: ${imageRecord.containerId}`);
|
|
31
46
|
}
|
|
32
|
-
const
|
|
47
|
+
const session = createSession({
|
|
48
|
+
sessionId: imageRecord.sessionId,
|
|
49
|
+
imageId,
|
|
33
50
|
containerId: imageRecord.containerId,
|
|
34
|
-
|
|
51
|
+
repository: this.platform.sessionRepository
|
|
35
52
|
});
|
|
36
|
-
|
|
53
|
+
const defaultTools = [];
|
|
54
|
+
if (this.platform.bashProvider) {
|
|
55
|
+
defaultTools.push(createBashTool(this.platform.bashProvider));
|
|
56
|
+
}
|
|
37
57
|
const driverConfig = {
|
|
38
|
-
apiKey:
|
|
39
|
-
baseUrl: process.env.ANTHROPIC_BASE_URL,
|
|
58
|
+
apiKey: "",
|
|
40
59
|
agentId,
|
|
41
60
|
systemPrompt: imageRecord.systemPrompt,
|
|
42
|
-
cwd: workspace.path,
|
|
43
61
|
mcpServers: imageRecord.mcpServers,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
62
|
+
tools: defaultTools.length > 0 ? defaultTools : void 0,
|
|
63
|
+
session,
|
|
64
|
+
// Inject Session for stateless drivers
|
|
65
|
+
resumeSessionId: imageRecord.metadata?.driverSessionId,
|
|
66
|
+
onSessionIdCaptured: async (driverSessionId) => {
|
|
67
|
+
await this.platform.imageRepository.updateMetadata(imageId, { driverSessionId });
|
|
47
68
|
}
|
|
48
69
|
};
|
|
49
|
-
const driver = this.
|
|
70
|
+
const driver = this.createDriver(driverConfig);
|
|
50
71
|
await driver.initialize();
|
|
72
|
+
const noopSource = {
|
|
73
|
+
name: "RuntimeSource",
|
|
74
|
+
connect: () => {
|
|
75
|
+
},
|
|
76
|
+
disconnect: () => {
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const sessionId = imageRecord.sessionId;
|
|
80
|
+
const sessionRepository = this.platform.sessionRepository;
|
|
81
|
+
const eventBus = this.platform.eventBus;
|
|
82
|
+
const runtimePresenter = {
|
|
83
|
+
name: "RuntimePresenter",
|
|
84
|
+
present: (_agentId, output) => {
|
|
85
|
+
const category = categorizeAgentOutput(output.type);
|
|
86
|
+
if (category === "stream") return;
|
|
87
|
+
eventBus.emit({
|
|
88
|
+
type: output.type,
|
|
89
|
+
timestamp: output.timestamp,
|
|
90
|
+
source: "agent",
|
|
91
|
+
category,
|
|
92
|
+
intent: "notification",
|
|
93
|
+
data: output.data,
|
|
94
|
+
context: {
|
|
95
|
+
agentId,
|
|
96
|
+
imageId,
|
|
97
|
+
containerId: imageRecord.containerId,
|
|
98
|
+
sessionId
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (category === "message" && output.type !== "user_message") {
|
|
102
|
+
const message = output.data;
|
|
103
|
+
sessionRepository.addMessage(sessionId, message).catch((err) => {
|
|
104
|
+
logger.error("Failed to persist message", { type: output.type, error: err });
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const engine = createAgent({
|
|
110
|
+
agentId,
|
|
111
|
+
bus: this.platform.eventBus,
|
|
112
|
+
source: noopSource,
|
|
113
|
+
presenter: runtimePresenter
|
|
114
|
+
});
|
|
51
115
|
const agent = {
|
|
52
116
|
agentId,
|
|
53
117
|
imageId,
|
|
@@ -62,10 +126,11 @@ var AgentXRuntimeImpl = class {
|
|
|
62
126
|
lifecycle: "running",
|
|
63
127
|
subscriptions: /* @__PURE__ */ new Set(),
|
|
64
128
|
driver,
|
|
129
|
+
engine,
|
|
65
130
|
isReceiving: false
|
|
66
131
|
};
|
|
67
132
|
this.agents.set(agentId, state);
|
|
68
|
-
this.
|
|
133
|
+
this.platform.eventBus.emit({
|
|
69
134
|
type: "agent_created",
|
|
70
135
|
timestamp: Date.now(),
|
|
71
136
|
source: "runtime",
|
|
@@ -109,7 +174,7 @@ var AgentXRuntimeImpl = class {
|
|
|
109
174
|
throw new Error(`Agent already destroyed: ${agentId}`);
|
|
110
175
|
}
|
|
111
176
|
state.lifecycle = "stopped";
|
|
112
|
-
this.
|
|
177
|
+
this.platform.eventBus.emit({
|
|
113
178
|
type: "agent_stopped",
|
|
114
179
|
timestamp: Date.now(),
|
|
115
180
|
source: "runtime",
|
|
@@ -134,7 +199,7 @@ var AgentXRuntimeImpl = class {
|
|
|
134
199
|
throw new Error(`Cannot resume destroyed agent: ${agentId}`);
|
|
135
200
|
}
|
|
136
201
|
state.lifecycle = "running";
|
|
137
|
-
this.
|
|
202
|
+
this.platform.eventBus.emit({
|
|
138
203
|
type: "agent_resumed",
|
|
139
204
|
timestamp: Date.now(),
|
|
140
205
|
source: "runtime",
|
|
@@ -156,12 +221,13 @@ var AgentXRuntimeImpl = class {
|
|
|
156
221
|
throw new Error(`Agent not found: ${agentId}`);
|
|
157
222
|
}
|
|
158
223
|
await state.driver.dispose();
|
|
224
|
+
await state.engine.destroy();
|
|
159
225
|
for (const unsub of state.subscriptions) {
|
|
160
226
|
unsub();
|
|
161
227
|
}
|
|
162
228
|
state.subscriptions.clear();
|
|
163
229
|
state.lifecycle = "destroyed";
|
|
164
|
-
this.
|
|
230
|
+
this.platform.eventBus.emit({
|
|
165
231
|
type: "agent_destroyed",
|
|
166
232
|
timestamp: Date.now(),
|
|
167
233
|
source: "runtime",
|
|
@@ -198,12 +264,12 @@ var AgentXRuntimeImpl = class {
|
|
|
198
264
|
content,
|
|
199
265
|
timestamp: Date.now()
|
|
200
266
|
};
|
|
201
|
-
await this.
|
|
267
|
+
await this.platform.sessionRepository.addMessage(state.agent.sessionId, userMessage);
|
|
202
268
|
this.emitEvent(state, "user_message", userMessage, actualRequestId);
|
|
203
269
|
logger.debug("User message sent", {
|
|
204
270
|
agentId,
|
|
205
271
|
requestId: actualRequestId,
|
|
206
|
-
contentPreview: typeof content === "string" ? content.substring(0, 50) : `[${content.length} parts]`
|
|
272
|
+
contentPreview: typeof content === "string" ? content.substring(0, 50) : Array.isArray(content) ? `[${content.length} parts]` : `[${typeof content}]`
|
|
207
273
|
});
|
|
208
274
|
state.isReceiving = true;
|
|
209
275
|
try {
|
|
@@ -231,12 +297,7 @@ var AgentXRuntimeImpl = class {
|
|
|
231
297
|
throw new Error(`Agent not found: ${agentId}`);
|
|
232
298
|
}
|
|
233
299
|
state.driver.interrupt();
|
|
234
|
-
this.emitEvent(
|
|
235
|
-
state,
|
|
236
|
-
"interrupt",
|
|
237
|
-
{ agentId },
|
|
238
|
-
requestId ?? this.generateRequestId()
|
|
239
|
-
);
|
|
300
|
+
this.emitEvent(state, "interrupt", { agentId }, requestId ?? this.generateRequestId());
|
|
240
301
|
logger.debug("Interrupt sent", { agentId, requestId });
|
|
241
302
|
}
|
|
242
303
|
// ==================== Event Subscription ====================
|
|
@@ -245,7 +306,7 @@ var AgentXRuntimeImpl = class {
|
|
|
245
306
|
if (!state) {
|
|
246
307
|
throw new Error(`Agent not found: ${agentId}`);
|
|
247
308
|
}
|
|
248
|
-
const unsub = this.
|
|
309
|
+
const unsub = this.platform.eventBus.onAny((event) => {
|
|
249
310
|
const context = event.context;
|
|
250
311
|
if (context?.agentId === agentId) {
|
|
251
312
|
handler(event);
|
|
@@ -260,7 +321,7 @@ var AgentXRuntimeImpl = class {
|
|
|
260
321
|
};
|
|
261
322
|
}
|
|
262
323
|
subscribeAll(handler) {
|
|
263
|
-
const unsub = this.
|
|
324
|
+
const unsub = this.platform.eventBus.onAny(handler);
|
|
264
325
|
this.globalSubscriptions.add(unsub);
|
|
265
326
|
return {
|
|
266
327
|
unsubscribe: () => {
|
|
@@ -290,12 +351,14 @@ var AgentXRuntimeImpl = class {
|
|
|
290
351
|
*/
|
|
291
352
|
handleDriverEvent(state, event, requestId) {
|
|
292
353
|
this.emitEvent(state, event.type, event.data, requestId);
|
|
354
|
+
const streamEvent = toStreamEvent(event);
|
|
355
|
+
state.engine.handleStreamEvent(streamEvent);
|
|
293
356
|
}
|
|
294
357
|
/**
|
|
295
358
|
* Emit an event to the EventBus
|
|
296
359
|
*/
|
|
297
360
|
emitEvent(state, type, data, requestId) {
|
|
298
|
-
this.
|
|
361
|
+
this.platform.eventBus.emit({
|
|
299
362
|
type,
|
|
300
363
|
timestamp: Date.now(),
|
|
301
364
|
source: "runtime",
|
|
@@ -337,8 +400,29 @@ var AgentXRuntimeImpl = class {
|
|
|
337
400
|
return `msg_${timestamp}_${random}`;
|
|
338
401
|
}
|
|
339
402
|
};
|
|
340
|
-
function
|
|
341
|
-
|
|
403
|
+
function toStreamEvent(event) {
|
|
404
|
+
const type = event.type === "error" ? "error_received" : event.type;
|
|
405
|
+
return { type, data: event.data, timestamp: Date.now() };
|
|
406
|
+
}
|
|
407
|
+
function categorizeAgentOutput(type) {
|
|
408
|
+
const streamTypes = [
|
|
409
|
+
"message_start",
|
|
410
|
+
"message_delta",
|
|
411
|
+
"message_stop",
|
|
412
|
+
"text_delta",
|
|
413
|
+
"tool_use_start",
|
|
414
|
+
"input_json_delta",
|
|
415
|
+
"tool_use_stop",
|
|
416
|
+
"tool_result",
|
|
417
|
+
"error_received"
|
|
418
|
+
];
|
|
419
|
+
if (streamTypes.includes(type)) return "stream";
|
|
420
|
+
if (type.endsWith("_message")) return "message";
|
|
421
|
+
if (type.startsWith("turn_")) return "turn";
|
|
422
|
+
return "state";
|
|
423
|
+
}
|
|
424
|
+
function createAgentXRuntime(platform, createDriver) {
|
|
425
|
+
return new AgentXRuntimeImpl(platform, createDriver);
|
|
342
426
|
}
|
|
343
427
|
export {
|
|
344
428
|
AgentXRuntimeImpl,
|