agentxjs 1.9.2-dev → 1.9.4-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.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Presentation Class
3
+ *
4
+ * High-level API for UI integration.
5
+ * Wraps AgentX client and provides presentation state management.
6
+ */
7
+ import type { AgentX } from "../types";
8
+ import type { Unsubscribe } from "@agentxjs/core/event";
9
+ import type { PresentationState } from "./types";
10
+ /**
11
+ * Presentation update handler
12
+ */
13
+ export type PresentationUpdateHandler = (state: PresentationState) => void;
14
+ /**
15
+ * Presentation error handler
16
+ */
17
+ export type PresentationErrorHandler = (error: Error) => void;
18
+ /**
19
+ * Presentation options
20
+ */
21
+ export interface PresentationOptions {
22
+ /**
23
+ * Called on every state update
24
+ */
25
+ onUpdate?: PresentationUpdateHandler;
26
+ /**
27
+ * Called on errors
28
+ */
29
+ onError?: PresentationErrorHandler;
30
+ }
31
+ /**
32
+ * Presentation - UI-friendly wrapper for AgentX
33
+ */
34
+ export declare class Presentation {
35
+ private agentx;
36
+ private agentId;
37
+ private state;
38
+ private updateHandlers;
39
+ private errorHandlers;
40
+ private eventUnsubscribe;
41
+ constructor(agentx: AgentX, agentId: string, options?: PresentationOptions);
42
+ /**
43
+ * Get current state
44
+ */
45
+ getState(): PresentationState;
46
+ /**
47
+ * Subscribe to state updates
48
+ */
49
+ onUpdate(handler: PresentationUpdateHandler): Unsubscribe;
50
+ /**
51
+ * Subscribe to errors
52
+ */
53
+ onError(handler: PresentationErrorHandler): Unsubscribe;
54
+ /**
55
+ * Send a message
56
+ */
57
+ send(content: string): Promise<void>;
58
+ /**
59
+ * Interrupt current response
60
+ */
61
+ interrupt(): Promise<void>;
62
+ /**
63
+ * Reset state
64
+ */
65
+ reset(): void;
66
+ /**
67
+ * Dispose and cleanup
68
+ */
69
+ dispose(): void;
70
+ private subscribeToEvents;
71
+ private notify;
72
+ private notifyError;
73
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Presentation Module
3
+ *
4
+ * UI-friendly data model and state management.
5
+ */
6
+ export type { Block, TextBlock, ToolBlock, ImageBlock, Conversation, UserConversation, AssistantConversation, ErrorConversation, PresentationState, } from "./types";
7
+ export { initialPresentationState } from "./types";
8
+ export { presentationReducer, addUserConversation, createInitialState, } from "./reducer";
9
+ export { Presentation, type PresentationOptions, type PresentationUpdateHandler, type PresentationErrorHandler, } from "./Presentation";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Presentation Reducer
3
+ *
4
+ * Aggregates stream events into PresentationState.
5
+ * Pure function: (state, event) => newState
6
+ */
7
+ import type { BusEvent } from "@agentxjs/core/event";
8
+ import type { PresentationState } from "./types";
9
+ /**
10
+ * Reduce a stream event into presentation state
11
+ */
12
+ export declare function presentationReducer(state: PresentationState, event: BusEvent): PresentationState;
13
+ /**
14
+ * Add a user conversation to state
15
+ */
16
+ export declare function addUserConversation(state: PresentationState, content: string): PresentationState;
17
+ /**
18
+ * Create initial state
19
+ */
20
+ export declare function createInitialState(): PresentationState;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Presentation Types
3
+ *
4
+ * UI-friendly data model aggregated from stream events.
5
+ * This implements the Presentation Model pattern.
6
+ */
7
+ /**
8
+ * Text block
9
+ */
10
+ export interface TextBlock {
11
+ type: "text";
12
+ content: string;
13
+ }
14
+ /**
15
+ * Tool block - represents a tool call and its result
16
+ */
17
+ export interface ToolBlock {
18
+ type: "tool";
19
+ toolUseId: string;
20
+ toolName: string;
21
+ toolInput: Record<string, unknown>;
22
+ toolResult?: string;
23
+ status: "pending" | "running" | "completed" | "error";
24
+ }
25
+ /**
26
+ * Image block
27
+ */
28
+ export interface ImageBlock {
29
+ type: "image";
30
+ url: string;
31
+ alt?: string;
32
+ }
33
+ /**
34
+ * All block types
35
+ */
36
+ export type Block = TextBlock | ToolBlock | ImageBlock;
37
+ /**
38
+ * User conversation
39
+ */
40
+ export interface UserConversation {
41
+ role: "user";
42
+ blocks: Block[];
43
+ }
44
+ /**
45
+ * Assistant conversation
46
+ */
47
+ export interface AssistantConversation {
48
+ role: "assistant";
49
+ blocks: Block[];
50
+ isStreaming: boolean;
51
+ }
52
+ /**
53
+ * Error conversation
54
+ */
55
+ export interface ErrorConversation {
56
+ role: "error";
57
+ message: string;
58
+ }
59
+ /**
60
+ * All conversation types
61
+ */
62
+ export type Conversation = UserConversation | AssistantConversation | ErrorConversation;
63
+ /**
64
+ * Presentation state - the complete UI state
65
+ */
66
+ export interface PresentationState {
67
+ /**
68
+ * All completed conversations
69
+ */
70
+ conversations: Conversation[];
71
+ /**
72
+ * Current streaming conversation (null if not streaming)
73
+ */
74
+ streaming: AssistantConversation | null;
75
+ /**
76
+ * Current status
77
+ */
78
+ status: "idle" | "thinking" | "responding" | "executing";
79
+ }
80
+ /**
81
+ * Initial presentation state
82
+ */
83
+ export declare const initialPresentationState: PresentationState;
@@ -0,0 +1,264 @@
1
+ /**
2
+ * AgentX Client SDK Types
3
+ */
4
+ import type { BusEvent, EventBus, Unsubscribe, BusEventHandler } from "@agentxjs/core/event";
5
+ import type { Presentation, PresentationOptions } from "./presentation";
6
+ /**
7
+ * Static or dynamic value
8
+ */
9
+ export type MaybeAsync<T> = T | (() => T) | (() => Promise<T>);
10
+ /**
11
+ * AgentX client configuration
12
+ */
13
+ export interface AgentXConfig {
14
+ /**
15
+ * WebSocket server URL
16
+ */
17
+ serverUrl: string;
18
+ /**
19
+ * Headers for authentication (static or dynamic)
20
+ * In Node.js: sent during WebSocket handshake
21
+ * In browsers: sent as first auth message (WebSocket API limitation)
22
+ */
23
+ headers?: MaybeAsync<Record<string, string>>;
24
+ /**
25
+ * Business context injected into all requests
26
+ * Useful for passing userId, tenantId, permissions, etc.
27
+ */
28
+ context?: MaybeAsync<Record<string, unknown>>;
29
+ /**
30
+ * Request timeout in milliseconds (default: 30000)
31
+ */
32
+ timeout?: number;
33
+ /**
34
+ * Enable debug logging
35
+ */
36
+ debug?: boolean;
37
+ /**
38
+ * Auto reconnect on connection loss (default: true)
39
+ */
40
+ autoReconnect?: boolean;
41
+ }
42
+ /**
43
+ * Agent info returned from server
44
+ */
45
+ export interface AgentInfo {
46
+ agentId: string;
47
+ imageId: string;
48
+ containerId: string;
49
+ sessionId: string;
50
+ lifecycle?: string;
51
+ }
52
+ /**
53
+ * Image record from server
54
+ */
55
+ export interface ImageRecord {
56
+ imageId: string;
57
+ containerId: string;
58
+ sessionId: string;
59
+ name?: string;
60
+ description?: string;
61
+ systemPrompt?: string;
62
+ createdAt: number;
63
+ updatedAt: number;
64
+ }
65
+ /**
66
+ * Container info
67
+ */
68
+ export interface ContainerInfo {
69
+ containerId: string;
70
+ }
71
+ /**
72
+ * Base response with requestId
73
+ */
74
+ export interface BaseResponse {
75
+ requestId: string;
76
+ error?: string;
77
+ }
78
+ /**
79
+ * Agent create response
80
+ */
81
+ export interface AgentCreateResponse extends BaseResponse {
82
+ agentId: string;
83
+ imageId: string;
84
+ containerId: string;
85
+ sessionId: string;
86
+ }
87
+ /**
88
+ * Agent get response
89
+ */
90
+ export interface AgentGetResponse extends BaseResponse {
91
+ agent: AgentInfo | null;
92
+ exists: boolean;
93
+ }
94
+ /**
95
+ * Agent list response
96
+ */
97
+ export interface AgentListResponse extends BaseResponse {
98
+ agents: AgentInfo[];
99
+ }
100
+ /**
101
+ * Image create response
102
+ */
103
+ export interface ImageCreateResponse extends BaseResponse {
104
+ record: ImageRecord;
105
+ __subscriptions?: string[];
106
+ }
107
+ /**
108
+ * Image get response
109
+ */
110
+ export interface ImageGetResponse extends BaseResponse {
111
+ record: ImageRecord | null;
112
+ __subscriptions?: string[];
113
+ }
114
+ /**
115
+ * Image list response
116
+ */
117
+ export interface ImageListResponse extends BaseResponse {
118
+ records: ImageRecord[];
119
+ __subscriptions?: string[];
120
+ }
121
+ /**
122
+ * Container create response
123
+ */
124
+ export interface ContainerCreateResponse extends BaseResponse {
125
+ containerId: string;
126
+ }
127
+ /**
128
+ * Container get response
129
+ */
130
+ export interface ContainerGetResponse extends BaseResponse {
131
+ containerId: string;
132
+ exists: boolean;
133
+ }
134
+ /**
135
+ * Container list response
136
+ */
137
+ export interface ContainerListResponse extends BaseResponse {
138
+ containerIds: string[];
139
+ }
140
+ /**
141
+ * Message send response
142
+ */
143
+ export interface MessageSendResponse extends BaseResponse {
144
+ agentId: string;
145
+ }
146
+ /**
147
+ * AgentX Client SDK
148
+ */
149
+ export interface AgentX {
150
+ /**
151
+ * Check if connected to server
152
+ */
153
+ readonly connected: boolean;
154
+ /**
155
+ * Event bus for subscribing to events
156
+ */
157
+ readonly events: EventBus;
158
+ /**
159
+ * Create a new agent
160
+ */
161
+ createAgent(params: {
162
+ imageId: string;
163
+ agentId?: string;
164
+ }): Promise<AgentCreateResponse>;
165
+ /**
166
+ * Get agent by ID
167
+ */
168
+ getAgent(agentId: string): Promise<AgentGetResponse>;
169
+ /**
170
+ * List agents
171
+ */
172
+ listAgents(containerId?: string): Promise<AgentListResponse>;
173
+ /**
174
+ * Destroy an agent
175
+ */
176
+ destroyAgent(agentId: string): Promise<BaseResponse>;
177
+ /**
178
+ * Send message to agent
179
+ */
180
+ sendMessage(agentId: string, content: string | unknown[]): Promise<MessageSendResponse>;
181
+ /**
182
+ * Interrupt agent
183
+ */
184
+ interrupt(agentId: string): Promise<BaseResponse>;
185
+ /**
186
+ * Create a new image
187
+ */
188
+ createImage(params: {
189
+ containerId: string;
190
+ name?: string;
191
+ description?: string;
192
+ systemPrompt?: string;
193
+ mcpServers?: Record<string, unknown>;
194
+ }): Promise<ImageCreateResponse>;
195
+ /**
196
+ * Get image by ID
197
+ */
198
+ getImage(imageId: string): Promise<ImageGetResponse>;
199
+ /**
200
+ * List images
201
+ */
202
+ listImages(containerId?: string): Promise<ImageListResponse>;
203
+ /**
204
+ * Delete image
205
+ */
206
+ deleteImage(imageId: string): Promise<BaseResponse>;
207
+ /**
208
+ * Create or get container
209
+ */
210
+ createContainer(containerId: string): Promise<ContainerCreateResponse>;
211
+ /**
212
+ * Get container
213
+ */
214
+ getContainer(containerId: string): Promise<ContainerGetResponse>;
215
+ /**
216
+ * List containers
217
+ */
218
+ listContainers(): Promise<ContainerListResponse>;
219
+ /**
220
+ * Subscribe to specific event type
221
+ */
222
+ on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
223
+ type: T;
224
+ }>): Unsubscribe;
225
+ /**
226
+ * Subscribe to all events
227
+ */
228
+ onAny(handler: BusEventHandler): Unsubscribe;
229
+ /**
230
+ * Subscribe to session events
231
+ */
232
+ subscribe(sessionId: string): void;
233
+ /**
234
+ * Create a presentation for UI integration
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * const presentation = agentx.presentation(agentId);
239
+ *
240
+ * presentation.onUpdate((state) => {
241
+ * render(state.conversations);
242
+ * });
243
+ *
244
+ * await presentation.send("Hello!");
245
+ * ```
246
+ */
247
+ presentation(agentId: string, options?: PresentationOptions): Presentation;
248
+ /**
249
+ * Disconnect from server
250
+ */
251
+ disconnect(): Promise<void>;
252
+ /**
253
+ * Dispose and cleanup
254
+ */
255
+ dispose(): Promise<void>;
256
+ }
257
+ /**
258
+ * Pending request entry
259
+ */
260
+ export interface PendingRequest {
261
+ resolve: (response: BusEvent) => void;
262
+ reject: (error: Error) => void;
263
+ timeout: ReturnType<typeof setTimeout>;
264
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentxjs",
3
- "version": "1.9.2-dev",
3
+ "version": "1.9.4-dev",
4
4
  "description": "AgentX Client SDK - Connect to AgentX servers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,17 +8,22 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./src/index.ts",
12
- "default": "./src/index.ts"
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
13
14
  }
14
15
  },
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
15
20
  "scripts": {
16
21
  "build": "bun run build.ts",
17
22
  "typecheck": "tsc --noEmit",
18
23
  "test": "bun test"
19
24
  },
20
25
  "dependencies": {
21
- "@agentxjs/core": "workspace:*",
26
+ "@agentxjs/core": "1.9.3-dev",
22
27
  "reconnecting-websocket": "^4.4.0",
23
28
  "ws": "^8.18.0"
24
29
  },
package/src/index.ts CHANGED
@@ -90,9 +90,6 @@ export type {
90
90
  BaseResponse,
91
91
  } from "./types";
92
92
 
93
- // Re-export RemoteClient for advanced use
94
- export { RemoteClient } from "./RemoteClient";
95
-
96
93
  // Re-export Presentation types and classes
97
94
  export type {
98
95
  Block,
package/build.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Build script for agentxjs
3
- *
4
- * Generates dist/ with JS and .d.ts files
5
- */
6
-
7
- import { $ } from "bun";
8
-
9
- console.log("Building agentxjs...");
10
-
11
- // Clean dist
12
- await $`rm -rf dist`;
13
-
14
- // Generate .d.ts using tsc
15
- await $`tsc --emitDeclarationOnly --outDir dist`;
16
-
17
- // Build with bun
18
- await Bun.build({
19
- entrypoints: ["./src/index.ts"],
20
- outdir: "./dist",
21
- format: "esm",
22
- target: "node",
23
- sourcemap: "external",
24
- });
25
-
26
- console.log("Build complete!");
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "outDir": "./dist",
6
- "rootDir": "./src",
7
- "lib": ["ESNext", "DOM"]
8
- },
9
- "include": ["src/**/*"],
10
- "exclude": ["node_modules", "dist"]
11
- }