agentxjs 2.0.3 → 2.0.5
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/dist/chunk-ZFL27HK7.js +467 -0
- package/dist/chunk-ZFL27HK7.js.map +1 -0
- package/dist/index.d.ts +185 -140
- package/dist/index.js +124 -84
- package/dist/index.js.map +1 -1
- package/dist/server-IFVYHIJF.js +7 -0
- package/dist/server-IFVYHIJF.js.map +1 -0
- package/package.json +4 -6
- package/src/CommandHandler.ts +424 -0
- package/src/LocalClient.ts +10 -10
- package/src/RemoteClient.ts +14 -14
- package/src/index.ts +125 -110
- package/src/namespaces/images.ts +12 -0
- package/src/namespaces/presentations.ts +1 -1
- package/src/presentation/Presentation.ts +2 -2
- package/src/server.ts +346 -0
- package/src/types.ts +89 -137
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Message } from '@agentxjs/core/agent';
|
|
2
1
|
import { CreateDriver } from '@agentxjs/core/driver';
|
|
2
|
+
import { AgentXRuntime, AgentXPlatform } from '@agentxjs/core/runtime';
|
|
3
|
+
import { Message } from '@agentxjs/core/agent';
|
|
3
4
|
import { Unsubscribe, BusEvent, EventBus, BusEventHandler } from '@agentxjs/core/event';
|
|
4
|
-
import
|
|
5
|
+
import * as _agentxjs_core_network from '@agentxjs/core/network';
|
|
6
|
+
import { RpcMethod } from '@agentxjs/core/network';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Presentation Types
|
|
@@ -214,87 +216,6 @@ declare function messagesToConversations(messages: Message[]): Conversation[];
|
|
|
214
216
|
* Static or dynamic value
|
|
215
217
|
*/
|
|
216
218
|
type MaybeAsync<T> = T | (() => T) | (() => Promise<T>);
|
|
217
|
-
/**
|
|
218
|
-
* LLM provider identifier
|
|
219
|
-
*/
|
|
220
|
-
type LLMProvider = "anthropic" | "openai" | "google" | "xai" | "deepseek" | "mistral";
|
|
221
|
-
/**
|
|
222
|
-
* AgentX unified configuration
|
|
223
|
-
*
|
|
224
|
-
* Supports two modes:
|
|
225
|
-
* - **Local mode**: `apiKey` present → embedded Runtime + MonoDriver
|
|
226
|
-
* - **Remote mode**: `serverUrl` present → WebSocket client
|
|
227
|
-
*/
|
|
228
|
-
interface AgentXConfig {
|
|
229
|
-
/**
|
|
230
|
-
* API key for LLM provider (local mode)
|
|
231
|
-
* If present, enables local mode with embedded Runtime
|
|
232
|
-
*/
|
|
233
|
-
apiKey?: string;
|
|
234
|
-
/**
|
|
235
|
-
* LLM provider (local mode)
|
|
236
|
-
* @default "anthropic"
|
|
237
|
-
*/
|
|
238
|
-
provider?: LLMProvider;
|
|
239
|
-
/**
|
|
240
|
-
* Model ID (local mode)
|
|
241
|
-
*/
|
|
242
|
-
model?: string;
|
|
243
|
-
/**
|
|
244
|
-
* Base URL for API endpoint (local mode, for proxy/private deployments)
|
|
245
|
-
*/
|
|
246
|
-
baseUrl?: string;
|
|
247
|
-
/**
|
|
248
|
-
* Data storage path (local mode)
|
|
249
|
-
* @default ":memory:" (in-memory storage)
|
|
250
|
-
*/
|
|
251
|
-
dataPath?: string;
|
|
252
|
-
/**
|
|
253
|
-
* Custom CreateDriver factory (local mode, advanced)
|
|
254
|
-
* If provided, overrides the default MonoDriver
|
|
255
|
-
*/
|
|
256
|
-
createDriver?: CreateDriver;
|
|
257
|
-
/**
|
|
258
|
-
* Custom AgentXPlatform (local mode, advanced)
|
|
259
|
-
* If provided, overrides the default NodePlatform
|
|
260
|
-
*/
|
|
261
|
-
customPlatform?: AgentXPlatform;
|
|
262
|
-
/**
|
|
263
|
-
* WebSocket server URL (remote mode)
|
|
264
|
-
* If present, enables remote mode
|
|
265
|
-
*/
|
|
266
|
-
serverUrl?: string;
|
|
267
|
-
/**
|
|
268
|
-
* Headers for authentication (remote mode, static or dynamic)
|
|
269
|
-
* In Node.js: sent during WebSocket handshake
|
|
270
|
-
* In browsers: sent as first auth message (WebSocket API limitation)
|
|
271
|
-
*/
|
|
272
|
-
headers?: MaybeAsync<Record<string, string>>;
|
|
273
|
-
/**
|
|
274
|
-
* Business context injected into all requests (remote mode)
|
|
275
|
-
* Useful for passing userId, tenantId, permissions, etc.
|
|
276
|
-
*/
|
|
277
|
-
context?: MaybeAsync<Record<string, unknown>>;
|
|
278
|
-
/**
|
|
279
|
-
* Log level for AgentX runtime
|
|
280
|
-
* Controls verbosity of console/file logging.
|
|
281
|
-
* @default "info"
|
|
282
|
-
*/
|
|
283
|
-
logLevel?: "debug" | "info" | "warn" | "error" | "silent";
|
|
284
|
-
/**
|
|
285
|
-
* Request timeout in milliseconds (default: 30000)
|
|
286
|
-
*/
|
|
287
|
-
timeout?: number;
|
|
288
|
-
/**
|
|
289
|
-
* Enable debug logging
|
|
290
|
-
* @deprecated Use `logLevel: "debug"` instead
|
|
291
|
-
*/
|
|
292
|
-
debug?: boolean;
|
|
293
|
-
/**
|
|
294
|
-
* Auto reconnect on connection loss (default: true, remote mode only)
|
|
295
|
-
*/
|
|
296
|
-
autoReconnect?: boolean;
|
|
297
|
-
}
|
|
298
219
|
/**
|
|
299
220
|
* Agent info returned from server
|
|
300
221
|
*/
|
|
@@ -458,6 +379,10 @@ interface ImageNamespace {
|
|
|
458
379
|
* Delete image
|
|
459
380
|
*/
|
|
460
381
|
delete(imageId: string): Promise<BaseResponse>;
|
|
382
|
+
/**
|
|
383
|
+
* Get message history for an image
|
|
384
|
+
*/
|
|
385
|
+
getMessages(imageId: string): Promise<Message[]>;
|
|
461
386
|
}
|
|
462
387
|
/**
|
|
463
388
|
* Agent operations namespace
|
|
@@ -509,7 +434,7 @@ interface PresentationNamespace {
|
|
|
509
434
|
*
|
|
510
435
|
* @example
|
|
511
436
|
* ```typescript
|
|
512
|
-
* const pres = agentx.
|
|
437
|
+
* const pres = agentx.presentation.create(agentId, {
|
|
513
438
|
* onUpdate: (state) => renderUI(state),
|
|
514
439
|
* onError: (error) => console.error(error),
|
|
515
440
|
* });
|
|
@@ -521,106 +446,226 @@ interface PresentationNamespace {
|
|
|
521
446
|
create(agentId: string, options?: PresentationOptions): Promise<Presentation>;
|
|
522
447
|
}
|
|
523
448
|
/**
|
|
524
|
-
* AgentX Client SDK
|
|
449
|
+
* AgentX Client SDK — unified interface for local, remote, and server modes
|
|
525
450
|
*/
|
|
526
451
|
interface AgentX {
|
|
527
452
|
/**
|
|
528
|
-
* Check if connected
|
|
453
|
+
* Check if connected/active
|
|
529
454
|
*/
|
|
530
455
|
readonly connected: boolean;
|
|
531
456
|
/**
|
|
532
457
|
* Event bus for subscribing to events
|
|
533
458
|
*/
|
|
534
459
|
readonly events: EventBus;
|
|
460
|
+
readonly container: ContainerNamespace;
|
|
461
|
+
readonly image: ImageNamespace;
|
|
462
|
+
readonly agent: AgentNamespace;
|
|
463
|
+
readonly session: SessionNamespace;
|
|
464
|
+
readonly presentation: PresentationNamespace;
|
|
465
|
+
on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
|
|
466
|
+
type: T;
|
|
467
|
+
}>): Unsubscribe;
|
|
468
|
+
onAny(handler: BusEventHandler): Unsubscribe;
|
|
469
|
+
subscribe(sessionId: string): void;
|
|
470
|
+
disconnect(): Promise<void>;
|
|
471
|
+
dispose(): Promise<void>;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Options for connecting to a remote AgentX server
|
|
475
|
+
*/
|
|
476
|
+
interface ConnectOptions {
|
|
477
|
+
/** Authentication headers */
|
|
478
|
+
headers?: MaybeAsync<Record<string, string>>;
|
|
479
|
+
/** Business context injected into requests */
|
|
480
|
+
context?: MaybeAsync<Record<string, unknown>>;
|
|
481
|
+
/** Request timeout in ms (default: 30000) */
|
|
482
|
+
timeout?: number;
|
|
483
|
+
/** Auto reconnect on disconnect (default: true) */
|
|
484
|
+
autoReconnect?: boolean;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Configuration for serving as an AgentX server
|
|
488
|
+
*/
|
|
489
|
+
interface ServeConfig {
|
|
490
|
+
/** Port to listen on (default: 5200) */
|
|
491
|
+
port?: number;
|
|
492
|
+
/** Host to bind to (default: "0.0.0.0") */
|
|
493
|
+
host?: string;
|
|
494
|
+
/** Existing HTTP server to attach to */
|
|
495
|
+
server?: unknown;
|
|
496
|
+
/** WebSocket path when attached (default: "/ws") */
|
|
497
|
+
wsPath?: string;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Server instance returned by serve()
|
|
501
|
+
*/
|
|
502
|
+
interface AgentXServer {
|
|
503
|
+
listen(port?: number, host?: string): Promise<void>;
|
|
504
|
+
close(): Promise<void>;
|
|
505
|
+
dispose(): Promise<void>;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* AgentXBuilder — fluent API entry point
|
|
509
|
+
*
|
|
510
|
+
* Created by `createAgentX(platform?)`. The builder itself is an AgentX
|
|
511
|
+
* instance (local mode). Call `.connect()` to get a remote client,
|
|
512
|
+
* or `.serve()` to start a server.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* const ax = createAgentX(node({ createDriver }))
|
|
517
|
+
*
|
|
518
|
+
* // Local use
|
|
519
|
+
* await ax.agent.create({ imageId: "..." })
|
|
520
|
+
*
|
|
521
|
+
* // Connect to remote server
|
|
522
|
+
* const client = await ax.connect("wss://...")
|
|
523
|
+
*
|
|
524
|
+
* // Serve as server
|
|
525
|
+
* const server = await ax.serve({ port: 3100 })
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
interface AgentXBuilder extends AgentX {
|
|
535
529
|
/**
|
|
536
|
-
*
|
|
537
|
-
*/
|
|
538
|
-
readonly containers: ContainerNamespace;
|
|
539
|
-
/**
|
|
540
|
-
* Image operations
|
|
530
|
+
* Connect to a remote AgentX server
|
|
541
531
|
*/
|
|
542
|
-
|
|
532
|
+
connect(serverUrl: string, options?: ConnectOptions): Promise<AgentX>;
|
|
543
533
|
/**
|
|
544
|
-
*
|
|
534
|
+
* Start serving as an AgentX server
|
|
545
535
|
*/
|
|
546
|
-
|
|
536
|
+
serve(config?: ServeConfig): Promise<AgentXServer>;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* CommandHandler - Handles JSON-RPC requests directly
|
|
541
|
+
*
|
|
542
|
+
* No longer uses EventBus for request/response. Instead:
|
|
543
|
+
* - Receives RPC requests directly
|
|
544
|
+
* - Returns RPC responses directly
|
|
545
|
+
* - EventBus is only used for stream events (notifications)
|
|
546
|
+
*/
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* RPC Result type
|
|
550
|
+
*/
|
|
551
|
+
interface RpcResult<T = unknown> {
|
|
552
|
+
success: true;
|
|
553
|
+
data: T;
|
|
554
|
+
}
|
|
555
|
+
interface RpcError {
|
|
556
|
+
success: false;
|
|
557
|
+
code: number;
|
|
558
|
+
message: string;
|
|
559
|
+
}
|
|
560
|
+
type RpcResponse<T = unknown> = RpcResult<T> | RpcError;
|
|
561
|
+
/**
|
|
562
|
+
* CommandHandler - Processes RPC requests directly
|
|
563
|
+
*/
|
|
564
|
+
declare class CommandHandler {
|
|
565
|
+
private readonly runtime;
|
|
566
|
+
constructor(runtime: AgentXRuntime);
|
|
567
|
+
/**
|
|
568
|
+
* Handle an RPC request and return response
|
|
569
|
+
*/
|
|
570
|
+
handle(method: RpcMethod, params: unknown): Promise<RpcResponse>;
|
|
571
|
+
private handleContainerCreate;
|
|
572
|
+
private handleContainerGet;
|
|
573
|
+
private handleContainerList;
|
|
574
|
+
private handleImageCreate;
|
|
575
|
+
private handleImageGet;
|
|
576
|
+
private handleImageList;
|
|
577
|
+
private handleImageDelete;
|
|
578
|
+
private handleImageRun;
|
|
579
|
+
private handleImageStop;
|
|
580
|
+
private handleImageUpdate;
|
|
581
|
+
private handleImageMessages;
|
|
582
|
+
private handleAgentGet;
|
|
583
|
+
private handleAgentList;
|
|
584
|
+
private handleAgentDestroy;
|
|
585
|
+
private handleAgentDestroyAll;
|
|
586
|
+
private handleAgentInterrupt;
|
|
587
|
+
private handleMessageSend;
|
|
588
|
+
dispose(): void;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Server configuration (supports both immediate and deferred platforms)
|
|
593
|
+
*/
|
|
594
|
+
interface ServerConfig {
|
|
547
595
|
/**
|
|
548
|
-
*
|
|
596
|
+
* AgentX Platform — must provide `channelServer` for accepting WebSocket connections.
|
|
549
597
|
*/
|
|
550
|
-
|
|
598
|
+
platform: AgentXPlatform;
|
|
551
599
|
/**
|
|
552
|
-
*
|
|
600
|
+
* LLM Driver factory function - creates Driver per Agent
|
|
553
601
|
*/
|
|
554
|
-
|
|
602
|
+
createDriver: CreateDriver;
|
|
555
603
|
/**
|
|
556
|
-
*
|
|
604
|
+
* Port to listen on (standalone mode)
|
|
557
605
|
*/
|
|
558
|
-
|
|
559
|
-
type: T;
|
|
560
|
-
}>): Unsubscribe;
|
|
606
|
+
port?: number;
|
|
561
607
|
/**
|
|
562
|
-
*
|
|
608
|
+
* Host to bind to (default: "0.0.0.0")
|
|
563
609
|
*/
|
|
564
|
-
|
|
610
|
+
host?: string;
|
|
565
611
|
/**
|
|
566
|
-
*
|
|
612
|
+
* Existing HTTP server to attach to (attached mode)
|
|
567
613
|
*/
|
|
568
|
-
|
|
614
|
+
server?: _agentxjs_core_network.MinimalHTTPServer;
|
|
569
615
|
/**
|
|
570
|
-
*
|
|
616
|
+
* WebSocket path when attached (default: "/ws")
|
|
571
617
|
*/
|
|
572
|
-
|
|
618
|
+
wsPath?: string;
|
|
573
619
|
/**
|
|
574
|
-
*
|
|
620
|
+
* Enable debug logging
|
|
575
621
|
*/
|
|
576
|
-
|
|
622
|
+
debug?: boolean;
|
|
577
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* Create an AgentX server
|
|
626
|
+
*/
|
|
627
|
+
declare function createServer(config: ServerConfig): Promise<AgentXServer>;
|
|
578
628
|
|
|
579
629
|
/**
|
|
580
630
|
* agentxjs - AgentX Client SDK
|
|
581
631
|
*
|
|
582
|
-
*
|
|
632
|
+
* Fluent API supporting local, remote, and server modes.
|
|
583
633
|
*
|
|
584
|
-
* @example Local mode
|
|
634
|
+
* @example Local mode
|
|
585
635
|
* ```typescript
|
|
586
636
|
* import { createAgentX } from "agentxjs";
|
|
637
|
+
* import { node } from "@agentxjs/node-platform";
|
|
587
638
|
*
|
|
588
|
-
* const
|
|
589
|
-
*
|
|
590
|
-
* provider: "anthropic",
|
|
591
|
-
* });
|
|
592
|
-
*
|
|
593
|
-
* await agentx.containers.create("my-app");
|
|
594
|
-
* const { record: image } = await agentx.images.create({
|
|
595
|
-
* containerId: "my-app",
|
|
596
|
-
* systemPrompt: "You are helpful",
|
|
597
|
-
* });
|
|
598
|
-
* const { agentId } = await agentx.agents.create({ imageId: image.imageId });
|
|
599
|
-
*
|
|
600
|
-
* agentx.on("text_delta", (e) => process.stdout.write(e.data.text));
|
|
601
|
-
* await agentx.sessions.send(agentId, "Hello!");
|
|
639
|
+
* const ax = createAgentX(node({ createDriver }));
|
|
640
|
+
* await ax.agent.create({ imageId: "..." });
|
|
602
641
|
* ```
|
|
603
642
|
*
|
|
604
|
-
* @example Remote mode
|
|
643
|
+
* @example Remote mode
|
|
605
644
|
* ```typescript
|
|
606
|
-
*
|
|
645
|
+
* const ax = createAgentX();
|
|
646
|
+
* const client = await ax.connect("ws://localhost:5200");
|
|
647
|
+
* ```
|
|
607
648
|
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
* });
|
|
649
|
+
* @example Server mode
|
|
650
|
+
* ```typescript
|
|
651
|
+
* const ax = createAgentX(node({ createDriver }));
|
|
652
|
+
* const server = await ax.serve({ port: 5200 });
|
|
611
653
|
* ```
|
|
612
654
|
*/
|
|
613
655
|
|
|
614
656
|
/**
|
|
615
|
-
*
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
657
|
+
* Platform configuration for createAgentX
|
|
658
|
+
*/
|
|
659
|
+
interface PlatformConfig {
|
|
660
|
+
platform: AgentXPlatform;
|
|
661
|
+
createDriver: CreateDriver;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Create an AgentX builder
|
|
620
665
|
*
|
|
621
|
-
* @param config -
|
|
622
|
-
* @returns
|
|
666
|
+
* @param config - Platform configuration (optional). Without it, only connect() is available.
|
|
667
|
+
* @returns AgentXBuilder — local AgentX + connect() + serve()
|
|
623
668
|
*/
|
|
624
|
-
declare function createAgentX(config
|
|
669
|
+
declare function createAgentX(config?: PlatformConfig): AgentXBuilder;
|
|
625
670
|
|
|
626
|
-
export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentNamespace, type AgentX, type
|
|
671
|
+
export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentNamespace, type AgentX, type AgentXBuilder, type AgentXServer, type AssistantConversation, type BaseResponse, type Block, CommandHandler, type ConnectOptions, type ContainerCreateResponse, type ContainerGetResponse, type ContainerInfo, type ContainerListResponse, type ContainerNamespace, type Conversation, type ErrorConversation, type ImageBlock, type ImageCreateResponse, type ImageGetResponse, type ImageListResponse, type ImageNamespace, type ImageRecord, type MaybeAsync, type MessageSendResponse, type PlatformConfig, Presentation, type PresentationErrorHandler, type PresentationNamespace, type PresentationOptions, type PresentationState, type PresentationUpdateHandler, type ServeConfig, type ServerConfig, type SessionNamespace, type TextBlock, type ToolBlock, type UserConversation, addUserConversation, createAgentX, createInitialState, createServer, initialPresentationState, messagesToConversations, presentationReducer };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommandHandler,
|
|
3
|
+
createServer
|
|
4
|
+
} from "./chunk-ZFL27HK7.js";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
import { createAgentXRuntime } from "@agentxjs/core/runtime";
|
|
8
|
+
|
|
1
9
|
// src/LocalClient.ts
|
|
2
10
|
import { createLogger } from "commonxjs/logger";
|
|
3
11
|
|
|
@@ -188,6 +196,11 @@ function createLocalImages(platform) {
|
|
|
188
196
|
await image.delete();
|
|
189
197
|
}
|
|
190
198
|
return { requestId: "" };
|
|
199
|
+
},
|
|
200
|
+
async getMessages(imageId) {
|
|
201
|
+
const imageRecord = await platform.imageRepository.findImageById(imageId);
|
|
202
|
+
if (!imageRecord) return [];
|
|
203
|
+
return platform.sessionRepository.getMessages(imageRecord.sessionId);
|
|
191
204
|
}
|
|
192
205
|
};
|
|
193
206
|
}
|
|
@@ -230,6 +243,10 @@ function createRemoteImages(rpcClient, subscribeFn) {
|
|
|
230
243
|
async delete(imageId) {
|
|
231
244
|
const result = await rpcClient.call("image.delete", { imageId });
|
|
232
245
|
return { ...result, requestId: "" };
|
|
246
|
+
},
|
|
247
|
+
async getMessages(imageId) {
|
|
248
|
+
const result = await rpcClient.call("image.messages", { imageId });
|
|
249
|
+
return result.messages ?? [];
|
|
233
250
|
}
|
|
234
251
|
};
|
|
235
252
|
}
|
|
@@ -586,7 +603,7 @@ var Presentation = class {
|
|
|
586
603
|
this.state = addUserConversation(this.state, content);
|
|
587
604
|
this.notify();
|
|
588
605
|
try {
|
|
589
|
-
await this.agentx.
|
|
606
|
+
await this.agentx.session.send(this.agentId, content);
|
|
590
607
|
} catch (error) {
|
|
591
608
|
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
592
609
|
}
|
|
@@ -596,7 +613,7 @@ var Presentation = class {
|
|
|
596
613
|
*/
|
|
597
614
|
async interrupt() {
|
|
598
615
|
try {
|
|
599
|
-
await this.agentx.
|
|
616
|
+
await this.agentx.session.interrupt(this.agentId);
|
|
600
617
|
} catch (error) {
|
|
601
618
|
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
602
619
|
}
|
|
@@ -658,7 +675,7 @@ var Presentation = class {
|
|
|
658
675
|
function createPresentations(agentx) {
|
|
659
676
|
return {
|
|
660
677
|
async create(agentId, options) {
|
|
661
|
-
const messages = await agentx.
|
|
678
|
+
const messages = await agentx.session.getMessages(agentId);
|
|
662
679
|
const conversations = messagesToConversations(messages);
|
|
663
680
|
return new Presentation(agentx, agentId, options, conversations);
|
|
664
681
|
}
|
|
@@ -712,19 +729,19 @@ var logger = createLogger("agentx/LocalClient");
|
|
|
712
729
|
var LocalClient = class {
|
|
713
730
|
runtime;
|
|
714
731
|
isDisposed = false;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
732
|
+
container;
|
|
733
|
+
image;
|
|
734
|
+
agent;
|
|
735
|
+
session;
|
|
736
|
+
presentation;
|
|
720
737
|
constructor(runtime) {
|
|
721
738
|
this.runtime = runtime;
|
|
722
739
|
const platform = runtime.platform;
|
|
723
|
-
this.
|
|
724
|
-
this.
|
|
725
|
-
this.
|
|
726
|
-
this.
|
|
727
|
-
this.
|
|
740
|
+
this.container = createLocalContainers(platform);
|
|
741
|
+
this.image = createLocalImages(platform);
|
|
742
|
+
this.agent = createLocalAgents(runtime);
|
|
743
|
+
this.session = createLocalSessions(runtime);
|
|
744
|
+
this.presentation = createPresentations(this);
|
|
728
745
|
logger.info("LocalClient initialized");
|
|
729
746
|
}
|
|
730
747
|
// ==================== Properties ====================
|
|
@@ -763,11 +780,11 @@ var RemoteClient = class {
|
|
|
763
780
|
config;
|
|
764
781
|
eventBus;
|
|
765
782
|
rpcClient;
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
783
|
+
container;
|
|
784
|
+
image;
|
|
785
|
+
agent;
|
|
786
|
+
session;
|
|
787
|
+
presentation;
|
|
771
788
|
constructor(config) {
|
|
772
789
|
this.config = config;
|
|
773
790
|
this.eventBus = new EventBusImpl();
|
|
@@ -783,11 +800,11 @@ var RemoteClient = class {
|
|
|
783
800
|
logger2.debug("Received stream event", { topic, type: event.type });
|
|
784
801
|
this.eventBus.emit(event);
|
|
785
802
|
});
|
|
786
|
-
this.
|
|
787
|
-
this.
|
|
788
|
-
this.
|
|
789
|
-
this.
|
|
790
|
-
this.
|
|
803
|
+
this.container = createRemoteContainers(this.rpcClient);
|
|
804
|
+
this.image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
|
|
805
|
+
this.agent = createRemoteAgents(this.rpcClient);
|
|
806
|
+
this.session = createRemoteSessions(this.rpcClient);
|
|
807
|
+
this.presentation = createPresentations(this);
|
|
791
808
|
}
|
|
792
809
|
// ==================== Properties ====================
|
|
793
810
|
get connected() {
|
|
@@ -824,77 +841,100 @@ var RemoteClient = class {
|
|
|
824
841
|
};
|
|
825
842
|
|
|
826
843
|
// src/index.ts
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
async function resolvePlatformForRemote(config) {
|
|
842
|
-
if (config.customPlatform?.channelClient) {
|
|
843
|
-
return config;
|
|
844
|
+
function createAgentX(config) {
|
|
845
|
+
let localClient = null;
|
|
846
|
+
function getLocalClient() {
|
|
847
|
+
if (localClient) return localClient;
|
|
848
|
+
if (!config) {
|
|
849
|
+
throw new Error(
|
|
850
|
+
"Local mode requires a platform. Pass a PlatformConfig to createAgentX(), or use connect() for remote mode."
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
const runtime = createAgentXRuntime(config.platform, config.createDriver);
|
|
854
|
+
localClient = new LocalClient(runtime);
|
|
855
|
+
return localClient;
|
|
844
856
|
}
|
|
845
|
-
if (
|
|
846
|
-
|
|
857
|
+
if (config) {
|
|
858
|
+
getLocalClient();
|
|
847
859
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
860
|
+
return {
|
|
861
|
+
get connected() {
|
|
862
|
+
return localClient?.connected ?? false;
|
|
863
|
+
},
|
|
864
|
+
get events() {
|
|
865
|
+
return getLocalClient().events;
|
|
866
|
+
},
|
|
867
|
+
get container() {
|
|
868
|
+
return getLocalClient().container;
|
|
869
|
+
},
|
|
870
|
+
get image() {
|
|
871
|
+
return getLocalClient().image;
|
|
872
|
+
},
|
|
873
|
+
get agent() {
|
|
874
|
+
return getLocalClient().agent;
|
|
875
|
+
},
|
|
876
|
+
get session() {
|
|
877
|
+
return getLocalClient().session;
|
|
878
|
+
},
|
|
879
|
+
get presentation() {
|
|
880
|
+
return getLocalClient().presentation;
|
|
881
|
+
},
|
|
882
|
+
on(type, handler) {
|
|
883
|
+
return getLocalClient().on(type, handler);
|
|
884
|
+
},
|
|
885
|
+
onAny(handler) {
|
|
886
|
+
return getLocalClient().onAny(handler);
|
|
887
|
+
},
|
|
888
|
+
subscribe(sessionId) {
|
|
889
|
+
getLocalClient().subscribe(sessionId);
|
|
890
|
+
},
|
|
891
|
+
async disconnect() {
|
|
892
|
+
await localClient?.disconnect();
|
|
893
|
+
},
|
|
894
|
+
async dispose() {
|
|
895
|
+
await localClient?.dispose();
|
|
896
|
+
localClient = null;
|
|
897
|
+
},
|
|
898
|
+
async connect(serverUrl, options) {
|
|
899
|
+
const remoteClient = new RemoteClient({
|
|
900
|
+
serverUrl,
|
|
901
|
+
headers: options?.headers,
|
|
902
|
+
context: options?.context,
|
|
903
|
+
timeout: options?.timeout,
|
|
904
|
+
autoReconnect: options?.autoReconnect,
|
|
905
|
+
customPlatform: config?.platform
|
|
906
|
+
});
|
|
907
|
+
await remoteClient.connect();
|
|
908
|
+
return remoteClient;
|
|
909
|
+
},
|
|
910
|
+
async serve(serveConfig) {
|
|
911
|
+
if (!config) {
|
|
912
|
+
throw new Error("serve() requires a platform. Pass a PlatformConfig to createAgentX().");
|
|
855
913
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
dataPath: config.dataPath ?? ":memory:",
|
|
870
|
-
logLevel: config.logLevel ?? (config.debug ? "debug" : void 0)
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
let createDriver = config.createDriver;
|
|
874
|
-
if (!createDriver) {
|
|
875
|
-
const { createMonoDriver } = await import("@agentxjs/mono-driver");
|
|
876
|
-
createDriver = (driverConfig) => {
|
|
877
|
-
const existingOptions = driverConfig.options ?? {};
|
|
878
|
-
return createMonoDriver({
|
|
879
|
-
...driverConfig,
|
|
880
|
-
apiKey: config.apiKey ?? driverConfig.apiKey,
|
|
881
|
-
baseUrl: config.baseUrl ?? driverConfig.baseUrl,
|
|
882
|
-
model: config.model ?? driverConfig.model,
|
|
883
|
-
options: {
|
|
884
|
-
...existingOptions,
|
|
885
|
-
provider: config.provider ?? existingOptions.provider ?? "anthropic"
|
|
886
|
-
}
|
|
914
|
+
if (!config.platform.channelServer) {
|
|
915
|
+
throw new Error(
|
|
916
|
+
"serve() requires platform.channelServer. Ensure your platform supports server mode."
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
const { createServer: createServer2 } = await import("./server-IFVYHIJF.js");
|
|
920
|
+
return createServer2({
|
|
921
|
+
platform: config.platform,
|
|
922
|
+
createDriver: config.createDriver,
|
|
923
|
+
port: serveConfig?.port,
|
|
924
|
+
host: serveConfig?.host,
|
|
925
|
+
server: serveConfig?.server,
|
|
926
|
+
wsPath: serveConfig?.wsPath
|
|
887
927
|
});
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
const runtime = createAgentXRuntime(platform, createDriver);
|
|
891
|
-
return new LocalClient(runtime);
|
|
928
|
+
}
|
|
929
|
+
};
|
|
892
930
|
}
|
|
893
931
|
export {
|
|
932
|
+
CommandHandler,
|
|
894
933
|
Presentation,
|
|
895
934
|
addUserConversation,
|
|
896
935
|
createAgentX,
|
|
897
936
|
createInitialState,
|
|
937
|
+
createServer,
|
|
898
938
|
initialPresentationState,
|
|
899
939
|
messagesToConversations,
|
|
900
940
|
presentationReducer
|