agentxjs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +602 -0
- package/dist/index.cjs +1292 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +1283 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/sse/index.cjs +633 -0
- package/dist/runtime/sse/index.cjs.map +1 -0
- package/dist/runtime/sse/index.d.cts +159 -0
- package/dist/runtime/sse/index.d.ts +159 -0
- package/dist/runtime/sse/index.js +621 -0
- package/dist/runtime/sse/index.js.map +1 -0
- package/dist/server/adapters/express.cjs +81 -0
- package/dist/server/adapters/express.cjs.map +1 -0
- package/dist/server/adapters/express.d.cts +75 -0
- package/dist/server/adapters/express.d.ts +75 -0
- package/dist/server/adapters/express.js +78 -0
- package/dist/server/adapters/express.js.map +1 -0
- package/dist/server/adapters/hono.cjs +32 -0
- package/dist/server/adapters/hono.cjs.map +1 -0
- package/dist/server/adapters/hono.d.cts +96 -0
- package/dist/server/adapters/hono.d.ts +96 -0
- package/dist/server/adapters/hono.js +28 -0
- package/dist/server/adapters/hono.js.map +1 -0
- package/dist/server/adapters/index.cjs +135 -0
- package/dist/server/adapters/index.cjs.map +1 -0
- package/dist/server/adapters/index.d.cts +5 -0
- package/dist/server/adapters/index.d.ts +5 -0
- package/dist/server/adapters/index.js +125 -0
- package/dist/server/adapters/index.js.map +1 -0
- package/dist/server/adapters/next.cjs +30 -0
- package/dist/server/adapters/next.cjs.map +1 -0
- package/dist/server/adapters/next.d.cts +107 -0
- package/dist/server/adapters/next.d.ts +107 -0
- package/dist/server/adapters/next.js +25 -0
- package/dist/server/adapters/next.js.map +1 -0
- package/dist/server/index.cjs +1093 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +131 -0
- package/dist/server/index.d.ts +131 -0
- package/dist/server/index.js +1080 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-Cgfcw91r.d.cts +282 -0
- package/dist/types-Cgfcw91r.d.ts +282 -0
- package/dist/types-OVKV6qpE.d.cts +118 -0
- package/dist/types-OVKV6qpE.d.ts +118 -0
- package/package.json +78 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { StreamEventType, Repository, UserMessage } from '@agentxjs/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Server Types
|
|
5
|
+
*
|
|
6
|
+
* Type definitions for AgentX server module.
|
|
7
|
+
* These are application-level types, not core domain types.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Supported transport types
|
|
12
|
+
*/
|
|
13
|
+
type TransportType = "sse" | "websocket";
|
|
14
|
+
/**
|
|
15
|
+
* Transport connection state
|
|
16
|
+
*/
|
|
17
|
+
type ConnectionState = "connecting" | "open" | "closing" | "closed";
|
|
18
|
+
/**
|
|
19
|
+
* Transport connection interface
|
|
20
|
+
*/
|
|
21
|
+
interface TransportConnection {
|
|
22
|
+
/**
|
|
23
|
+
* Unique connection ID
|
|
24
|
+
*/
|
|
25
|
+
readonly connectionId: string;
|
|
26
|
+
/**
|
|
27
|
+
* Associated agent ID
|
|
28
|
+
*/
|
|
29
|
+
readonly agentId: string;
|
|
30
|
+
/**
|
|
31
|
+
* Connection state
|
|
32
|
+
*/
|
|
33
|
+
readonly state: ConnectionState;
|
|
34
|
+
/**
|
|
35
|
+
* Send a Stream event to the client
|
|
36
|
+
*/
|
|
37
|
+
send(event: StreamEventType): void;
|
|
38
|
+
/**
|
|
39
|
+
* Close the connection
|
|
40
|
+
*/
|
|
41
|
+
close(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Register close handler
|
|
44
|
+
*/
|
|
45
|
+
onClose(handler: () => void): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* AgentX Handler - Framework-agnostic request handler
|
|
49
|
+
*
|
|
50
|
+
* Based on Web Standards (Request/Response).
|
|
51
|
+
* Can be adapted to any framework.
|
|
52
|
+
*/
|
|
53
|
+
interface AgentXHandler {
|
|
54
|
+
/**
|
|
55
|
+
* Handle a web request
|
|
56
|
+
*/
|
|
57
|
+
(request: Request): Promise<Response>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Handler options
|
|
61
|
+
*/
|
|
62
|
+
interface AgentXHandlerOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Transport type (default: "sse")
|
|
65
|
+
*/
|
|
66
|
+
transport?: TransportType;
|
|
67
|
+
/**
|
|
68
|
+
* Base path prefix (default: "")
|
|
69
|
+
*/
|
|
70
|
+
basePath?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Allow dynamic agent creation via API (default: false)
|
|
73
|
+
*/
|
|
74
|
+
allowDynamicCreation?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Allowed definition names for dynamic creation
|
|
77
|
+
*/
|
|
78
|
+
allowedDefinitions?: string[];
|
|
79
|
+
/**
|
|
80
|
+
* Repository for persistence (optional)
|
|
81
|
+
*
|
|
82
|
+
* If provided, enables /images/*, /sessions/*, /messages/* endpoints.
|
|
83
|
+
*/
|
|
84
|
+
repository?: Repository;
|
|
85
|
+
/**
|
|
86
|
+
* CORS configuration
|
|
87
|
+
*/
|
|
88
|
+
cors?: CorsOptions;
|
|
89
|
+
/**
|
|
90
|
+
* Lifecycle hooks
|
|
91
|
+
*/
|
|
92
|
+
hooks?: AgentXHandlerHooks;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* CORS options
|
|
96
|
+
*/
|
|
97
|
+
interface CorsOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Allowed origins
|
|
100
|
+
*/
|
|
101
|
+
origin?: string | string[] | boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Allowed methods
|
|
104
|
+
*/
|
|
105
|
+
methods?: string[];
|
|
106
|
+
/**
|
|
107
|
+
* Allowed headers
|
|
108
|
+
*/
|
|
109
|
+
headers?: string[];
|
|
110
|
+
/**
|
|
111
|
+
* Credentials
|
|
112
|
+
*/
|
|
113
|
+
credentials?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Handler lifecycle hooks
|
|
117
|
+
*/
|
|
118
|
+
interface AgentXHandlerHooks {
|
|
119
|
+
/**
|
|
120
|
+
* Called when a client connects to an agent's SSE
|
|
121
|
+
*/
|
|
122
|
+
onConnect?: (agentId: string, connectionId: string) => void | Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Called when a client disconnects
|
|
125
|
+
*/
|
|
126
|
+
onDisconnect?: (agentId: string, connectionId: string) => void | Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Called before processing a message
|
|
129
|
+
*/
|
|
130
|
+
onMessage?: (agentId: string, message: UserMessage) => void | Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Called on errors
|
|
133
|
+
*/
|
|
134
|
+
onError?: (agentId: string, error: Error) => void | Promise<void>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parsed request info
|
|
138
|
+
*/
|
|
139
|
+
interface ParsedRequest {
|
|
140
|
+
/**
|
|
141
|
+
* Request type
|
|
142
|
+
*/
|
|
143
|
+
type: RequestType;
|
|
144
|
+
/**
|
|
145
|
+
* Agent ID (if applicable)
|
|
146
|
+
*/
|
|
147
|
+
agentId?: string;
|
|
148
|
+
/**
|
|
149
|
+
* Definition name (if applicable)
|
|
150
|
+
*/
|
|
151
|
+
definitionName?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Image ID (if applicable)
|
|
154
|
+
*/
|
|
155
|
+
imageId?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Session ID (if applicable)
|
|
158
|
+
*/
|
|
159
|
+
sessionId?: string;
|
|
160
|
+
/**
|
|
161
|
+
* User ID (if applicable)
|
|
162
|
+
*/
|
|
163
|
+
userId?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Message ID (if applicable)
|
|
166
|
+
*/
|
|
167
|
+
messageId?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Container ID (if applicable)
|
|
170
|
+
*/
|
|
171
|
+
containerId?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Request body (if applicable)
|
|
174
|
+
*/
|
|
175
|
+
body?: unknown;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Request types
|
|
179
|
+
*/
|
|
180
|
+
type RequestType = "platform_info" | "platform_health" | "list_agents" | "create_agent" | "get_agent" | "delete_agent" | "connect_sse" | "send_message" | "interrupt" | "list_definitions" | "get_definition" | "save_definition" | "delete_definition" | "head_definition" | "list_images" | "get_image" | "save_image" | "delete_image" | "head_image" | "list_image_sessions" | "delete_image_sessions" | "run_image" | "list_sessions" | "get_session" | "save_session" | "delete_session" | "head_session" | "list_session_messages" | "delete_session_messages" | "count_session_messages" | "resume_session" | "list_user_sessions" | "get_message" | "save_message" | "delete_message" | "list_containers" | "create_container" | "get_container" | "save_container" | "delete_container" | "head_container" | "not_found";
|
|
181
|
+
/**
|
|
182
|
+
* Platform info response
|
|
183
|
+
*/
|
|
184
|
+
interface PlatformInfoResponse {
|
|
185
|
+
platform: "AgentX";
|
|
186
|
+
version: string;
|
|
187
|
+
agentCount: number;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Health check response
|
|
191
|
+
*/
|
|
192
|
+
interface HealthResponse {
|
|
193
|
+
status: "healthy" | "degraded" | "unhealthy";
|
|
194
|
+
timestamp: number;
|
|
195
|
+
agentCount: number;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Agent list response
|
|
199
|
+
*/
|
|
200
|
+
interface AgentListResponse {
|
|
201
|
+
agents: AgentInfoResponse[];
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Agent info response
|
|
205
|
+
*/
|
|
206
|
+
interface AgentInfoResponse {
|
|
207
|
+
agentId: string;
|
|
208
|
+
name: string;
|
|
209
|
+
description?: string;
|
|
210
|
+
lifecycle: string;
|
|
211
|
+
state: string;
|
|
212
|
+
createdAt: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Create agent request
|
|
216
|
+
*/
|
|
217
|
+
interface CreateAgentRequest {
|
|
218
|
+
/**
|
|
219
|
+
* Definition name (must be registered)
|
|
220
|
+
*/
|
|
221
|
+
definition: string;
|
|
222
|
+
/**
|
|
223
|
+
* Agent configuration
|
|
224
|
+
*/
|
|
225
|
+
config?: Record<string, unknown>;
|
|
226
|
+
/**
|
|
227
|
+
* Optional agent ID (auto-generated if not provided)
|
|
228
|
+
*/
|
|
229
|
+
agentId?: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Create agent response
|
|
233
|
+
*/
|
|
234
|
+
interface CreateAgentResponse {
|
|
235
|
+
agentId: string;
|
|
236
|
+
name: string;
|
|
237
|
+
lifecycle: string;
|
|
238
|
+
state: string;
|
|
239
|
+
createdAt: number;
|
|
240
|
+
endpoints: {
|
|
241
|
+
sse: string;
|
|
242
|
+
messages: string;
|
|
243
|
+
interrupt: string;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Send message request
|
|
248
|
+
*/
|
|
249
|
+
interface SendMessageRequest {
|
|
250
|
+
/**
|
|
251
|
+
* Message content (string or UserMessage)
|
|
252
|
+
*/
|
|
253
|
+
content: string | UserMessage["content"];
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Send message response
|
|
257
|
+
*/
|
|
258
|
+
interface SendMessageResponse {
|
|
259
|
+
status: "processing";
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Interrupt response
|
|
263
|
+
*/
|
|
264
|
+
interface InterruptResponse {
|
|
265
|
+
interrupted: boolean;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Error response
|
|
269
|
+
*/
|
|
270
|
+
interface ErrorResponse {
|
|
271
|
+
error: {
|
|
272
|
+
code: ErrorCode;
|
|
273
|
+
message: string;
|
|
274
|
+
details?: unknown;
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Error codes
|
|
279
|
+
*/
|
|
280
|
+
type ErrorCode = "AGENT_NOT_FOUND" | "AGENT_BUSY" | "AGENT_DESTROYED" | "INVALID_REQUEST" | "DEFINITION_NOT_FOUND" | "IMAGE_NOT_FOUND" | "DYNAMIC_CREATION_DISABLED" | "INTERNAL_ERROR";
|
|
281
|
+
|
|
282
|
+
export type { AgentXHandler as A, ConnectionState as C, ErrorResponse as E, HealthResponse as H, InterruptResponse as I, ParsedRequest as P, RequestType as R, SendMessageRequest as S, TransportConnection as T, AgentXHandlerOptions as a, TransportType as b, AgentXHandlerHooks as c, CorsOptions as d, PlatformInfoResponse as e, AgentListResponse as f, AgentInfoResponse as g, CreateAgentRequest as h, CreateAgentResponse as i, SendMessageResponse as j, ErrorCode as k };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Runtime, Repository, LoggerFactory, AgentIdResolver, Sandbox, AgentDefinition, AgentContext, RuntimeDriver, Logger } from '@agentxjs/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SSERuntime - Browser Runtime implementation
|
|
5
|
+
*
|
|
6
|
+
* "Define Once, Run Anywhere"
|
|
7
|
+
*
|
|
8
|
+
* Provides Runtime for browser that connects to remote AgentX server via SSE.
|
|
9
|
+
* Uses the same API as NodeRuntime, enabling unified code across platforms.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createAgentX } from "agentxjs";
|
|
14
|
+
* import { createSSERuntime } from "agentxjs/client";
|
|
15
|
+
* import { defineAgent } from "agentxjs";
|
|
16
|
+
*
|
|
17
|
+
* const MyAgent = defineAgent({
|
|
18
|
+
* name: "Assistant",
|
|
19
|
+
* systemPrompt: "You are a helpful assistant",
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Browser: connect to remote server
|
|
23
|
+
* const runtime = createSSERuntime({ serverUrl: "http://localhost:5200/agentx" });
|
|
24
|
+
* const agentx = createAgentX(runtime);
|
|
25
|
+
* const agent = agentx.agents.create(MyAgent);
|
|
26
|
+
*
|
|
27
|
+
* // Same API as server-side!
|
|
28
|
+
* agent.on("assistant_message", (event) => {
|
|
29
|
+
* console.log(event.data.content);
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* await agent.receive("Hello!");
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* SSERuntime configuration
|
|
38
|
+
*/
|
|
39
|
+
interface SSERuntimeConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Server base URL (e.g., "http://localhost:5200/agentx")
|
|
42
|
+
*/
|
|
43
|
+
serverUrl: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional request headers (for auth, etc.)
|
|
46
|
+
* Note: These headers are used for HTTP requests (POST, DELETE, etc.)
|
|
47
|
+
* but NOT for SSE connections (EventSource doesn't support headers).
|
|
48
|
+
* For SSE auth, use sseParams to pass token via query string.
|
|
49
|
+
*/
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* Optional query parameters to append to SSE URL.
|
|
53
|
+
* Use this for authentication since EventSource doesn't support headers.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* createSSERuntime({
|
|
58
|
+
* serverUrl: "http://localhost:5200/agentx",
|
|
59
|
+
* headers: { Authorization: "Bearer xxx" }, // For HTTP requests
|
|
60
|
+
* sseParams: { token: "xxx" }, // For SSE connections
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
sseParams?: Record<string, string>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* SSERuntime - Runtime for browser with SSE driver
|
|
68
|
+
*
|
|
69
|
+
* Connects to remote AgentX server via SSE.
|
|
70
|
+
* All resources (LLM, etc.) are provided by the server.
|
|
71
|
+
*
|
|
72
|
+
* Uses RemoteContainer which calls server POST /agents to create agents.
|
|
73
|
+
* This ensures browser and server use the same agentId.
|
|
74
|
+
*/
|
|
75
|
+
declare class SSERuntime implements Runtime {
|
|
76
|
+
readonly name = "sse";
|
|
77
|
+
readonly repository: Repository;
|
|
78
|
+
readonly loggerFactory: LoggerFactory;
|
|
79
|
+
readonly agentIdResolver: AgentIdResolver;
|
|
80
|
+
private readonly serverUrl;
|
|
81
|
+
private readonly headers;
|
|
82
|
+
private readonly sseParams;
|
|
83
|
+
constructor(config: SSERuntimeConfig);
|
|
84
|
+
createSandbox(_containerId: string): Sandbox;
|
|
85
|
+
createDriver(_definition: AgentDefinition, context: AgentContext, _sandbox: Sandbox): RuntimeDriver;
|
|
86
|
+
createLogger(name: string): Logger;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create SSE Runtime for browser
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { createAgentX } from "agentxjs";
|
|
94
|
+
* import { sseRuntime } from "agentxjs/runtime/sse";
|
|
95
|
+
*
|
|
96
|
+
* createAgentX(sseRuntime({
|
|
97
|
+
* serverUrl: "http://localhost:5200/agentx",
|
|
98
|
+
* headers: { Authorization: "Bearer xxx" },
|
|
99
|
+
* }));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function sseRuntime(config: SSERuntimeConfig): Runtime;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use `sseRuntime()` instead for consistency with `nodeRuntime()`
|
|
105
|
+
*/
|
|
106
|
+
declare const createSSERuntime: typeof sseRuntime;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Client Types
|
|
110
|
+
*
|
|
111
|
+
* Type definitions for AgentX client module (browser).
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Connection state
|
|
115
|
+
*/
|
|
116
|
+
type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting" | "error";
|
|
117
|
+
|
|
118
|
+
export { type ConnectionState as C, type SSERuntimeConfig as S, SSERuntime as a, createSSERuntime as c, sseRuntime as s };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Runtime, Repository, LoggerFactory, AgentIdResolver, Sandbox, AgentDefinition, AgentContext, RuntimeDriver, Logger } from '@agentxjs/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SSERuntime - Browser Runtime implementation
|
|
5
|
+
*
|
|
6
|
+
* "Define Once, Run Anywhere"
|
|
7
|
+
*
|
|
8
|
+
* Provides Runtime for browser that connects to remote AgentX server via SSE.
|
|
9
|
+
* Uses the same API as NodeRuntime, enabling unified code across platforms.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createAgentX } from "agentxjs";
|
|
14
|
+
* import { createSSERuntime } from "agentxjs/client";
|
|
15
|
+
* import { defineAgent } from "agentxjs";
|
|
16
|
+
*
|
|
17
|
+
* const MyAgent = defineAgent({
|
|
18
|
+
* name: "Assistant",
|
|
19
|
+
* systemPrompt: "You are a helpful assistant",
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Browser: connect to remote server
|
|
23
|
+
* const runtime = createSSERuntime({ serverUrl: "http://localhost:5200/agentx" });
|
|
24
|
+
* const agentx = createAgentX(runtime);
|
|
25
|
+
* const agent = agentx.agents.create(MyAgent);
|
|
26
|
+
*
|
|
27
|
+
* // Same API as server-side!
|
|
28
|
+
* agent.on("assistant_message", (event) => {
|
|
29
|
+
* console.log(event.data.content);
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* await agent.receive("Hello!");
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* SSERuntime configuration
|
|
38
|
+
*/
|
|
39
|
+
interface SSERuntimeConfig {
|
|
40
|
+
/**
|
|
41
|
+
* Server base URL (e.g., "http://localhost:5200/agentx")
|
|
42
|
+
*/
|
|
43
|
+
serverUrl: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional request headers (for auth, etc.)
|
|
46
|
+
* Note: These headers are used for HTTP requests (POST, DELETE, etc.)
|
|
47
|
+
* but NOT for SSE connections (EventSource doesn't support headers).
|
|
48
|
+
* For SSE auth, use sseParams to pass token via query string.
|
|
49
|
+
*/
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
/**
|
|
52
|
+
* Optional query parameters to append to SSE URL.
|
|
53
|
+
* Use this for authentication since EventSource doesn't support headers.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* createSSERuntime({
|
|
58
|
+
* serverUrl: "http://localhost:5200/agentx",
|
|
59
|
+
* headers: { Authorization: "Bearer xxx" }, // For HTTP requests
|
|
60
|
+
* sseParams: { token: "xxx" }, // For SSE connections
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
sseParams?: Record<string, string>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* SSERuntime - Runtime for browser with SSE driver
|
|
68
|
+
*
|
|
69
|
+
* Connects to remote AgentX server via SSE.
|
|
70
|
+
* All resources (LLM, etc.) are provided by the server.
|
|
71
|
+
*
|
|
72
|
+
* Uses RemoteContainer which calls server POST /agents to create agents.
|
|
73
|
+
* This ensures browser and server use the same agentId.
|
|
74
|
+
*/
|
|
75
|
+
declare class SSERuntime implements Runtime {
|
|
76
|
+
readonly name = "sse";
|
|
77
|
+
readonly repository: Repository;
|
|
78
|
+
readonly loggerFactory: LoggerFactory;
|
|
79
|
+
readonly agentIdResolver: AgentIdResolver;
|
|
80
|
+
private readonly serverUrl;
|
|
81
|
+
private readonly headers;
|
|
82
|
+
private readonly sseParams;
|
|
83
|
+
constructor(config: SSERuntimeConfig);
|
|
84
|
+
createSandbox(_containerId: string): Sandbox;
|
|
85
|
+
createDriver(_definition: AgentDefinition, context: AgentContext, _sandbox: Sandbox): RuntimeDriver;
|
|
86
|
+
createLogger(name: string): Logger;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create SSE Runtime for browser
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { createAgentX } from "agentxjs";
|
|
94
|
+
* import { sseRuntime } from "agentxjs/runtime/sse";
|
|
95
|
+
*
|
|
96
|
+
* createAgentX(sseRuntime({
|
|
97
|
+
* serverUrl: "http://localhost:5200/agentx",
|
|
98
|
+
* headers: { Authorization: "Bearer xxx" },
|
|
99
|
+
* }));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function sseRuntime(config: SSERuntimeConfig): Runtime;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use `sseRuntime()` instead for consistency with `nodeRuntime()`
|
|
105
|
+
*/
|
|
106
|
+
declare const createSSERuntime: typeof sseRuntime;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Client Types
|
|
110
|
+
*
|
|
111
|
+
* Type definitions for AgentX client module (browser).
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Connection state
|
|
115
|
+
*/
|
|
116
|
+
type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting" | "error";
|
|
117
|
+
|
|
118
|
+
export { type ConnectionState as C, type SSERuntimeConfig as S, SSERuntime as a, createSSERuntime as c, sseRuntime as s };
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agentxjs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Define, Run, Scale AI Agents - The Open Source Agent Platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/runtime/sse/index.d.ts",
|
|
17
|
+
"import": "./dist/runtime/sse/index.js",
|
|
18
|
+
"require": "./dist/runtime/sse/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./server": {
|
|
21
|
+
"types": "./dist/server/index.d.ts",
|
|
22
|
+
"import": "./dist/server/index.js",
|
|
23
|
+
"require": "./dist/server/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./server/adapters": {
|
|
26
|
+
"types": "./dist/server/adapters/index.d.ts",
|
|
27
|
+
"import": "./dist/server/adapters/index.js",
|
|
28
|
+
"require": "./dist/server/adapters/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./server/adapters/express": {
|
|
31
|
+
"types": "./dist/server/adapters/express.d.ts",
|
|
32
|
+
"import": "./dist/server/adapters/express.js",
|
|
33
|
+
"require": "./dist/server/adapters/express.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./server/adapters/hono": {
|
|
36
|
+
"types": "./dist/server/adapters/hono.d.ts",
|
|
37
|
+
"import": "./dist/server/adapters/hono.js",
|
|
38
|
+
"require": "./dist/server/adapters/hono.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./server/adapters/next": {
|
|
41
|
+
"types": "./dist/server/adapters/next.d.ts",
|
|
42
|
+
"import": "./dist/server/adapters/next.js",
|
|
43
|
+
"require": "./dist/server/adapters/next.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"ky": "^1.14.0",
|
|
51
|
+
"rxjs": "^7.8.2",
|
|
52
|
+
"@agentxjs/agent": "0.1.0",
|
|
53
|
+
"@agentxjs/types": "0.0.1",
|
|
54
|
+
"@agentxjs/engine": "0.1.0",
|
|
55
|
+
"@agentxjs/common": "0.1.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@deepracticex/vitest-cucumber": "^1.4.3",
|
|
59
|
+
"@types/node": "^24.9.2",
|
|
60
|
+
"@vitest/ui": "^3.2.4",
|
|
61
|
+
"tsup": "^8.3.5",
|
|
62
|
+
"typescript": "^5.7.2",
|
|
63
|
+
"vitest": "^3.2.4"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsup",
|
|
70
|
+
"dev": "tsup --watch",
|
|
71
|
+
"clean": "rm -rf dist test-results",
|
|
72
|
+
"lint": "eslint .",
|
|
73
|
+
"typecheck": "tsc --noEmit",
|
|
74
|
+
"test": "vitest run",
|
|
75
|
+
"test:watch": "vitest",
|
|
76
|
+
"test:ui": "vitest --ui"
|
|
77
|
+
}
|
|
78
|
+
}
|