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/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 { AgentXPlatform } from '@agentxjs/core/runtime';
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.presentations.create(agentId, {
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 to server
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
- * Container operations
537
- */
538
- readonly containers: ContainerNamespace;
539
- /**
540
- * Image operations
530
+ * Connect to a remote AgentX server
541
531
  */
542
- readonly images: ImageNamespace;
532
+ connect(serverUrl: string, options?: ConnectOptions): Promise<AgentX>;
543
533
  /**
544
- * Agent operations
534
+ * Start serving as an AgentX server
545
535
  */
546
- readonly agents: AgentNamespace;
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
- * Session operations (messaging)
596
+ * AgentX Platform — must provide `channelServer` for accepting WebSocket connections.
549
597
  */
550
- readonly sessions: SessionNamespace;
598
+ platform: AgentXPlatform;
551
599
  /**
552
- * Presentation operations (UI integration)
600
+ * LLM Driver factory function - creates Driver per Agent
553
601
  */
554
- readonly presentations: PresentationNamespace;
602
+ createDriver: CreateDriver;
555
603
  /**
556
- * Subscribe to specific event type
604
+ * Port to listen on (standalone mode)
557
605
  */
558
- on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
559
- type: T;
560
- }>): Unsubscribe;
606
+ port?: number;
561
607
  /**
562
- * Subscribe to all events
608
+ * Host to bind to (default: "0.0.0.0")
563
609
  */
564
- onAny(handler: BusEventHandler): Unsubscribe;
610
+ host?: string;
565
611
  /**
566
- * Subscribe to session events
612
+ * Existing HTTP server to attach to (attached mode)
567
613
  */
568
- subscribe(sessionId: string): void;
614
+ server?: _agentxjs_core_network.MinimalHTTPServer;
569
615
  /**
570
- * Disconnect from server
616
+ * WebSocket path when attached (default: "/ws")
571
617
  */
572
- disconnect(): Promise<void>;
618
+ wsPath?: string;
573
619
  /**
574
- * Dispose and cleanup
620
+ * Enable debug logging
575
621
  */
576
- dispose(): Promise<void>;
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
- * Unified entry point supporting local and remote modes.
632
+ * Fluent API supporting local, remote, and server modes.
583
633
  *
584
- * @example Local mode (embedded runtime)
634
+ * @example Local mode
585
635
  * ```typescript
586
636
  * import { createAgentX } from "agentxjs";
637
+ * import { node } from "@agentxjs/node-platform";
587
638
  *
588
- * const agentx = await createAgentX({
589
- * apiKey: process.env.ANTHROPIC_API_KEY,
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 (WebSocket client)
643
+ * @example Remote mode
605
644
  * ```typescript
606
- * import { createAgentX } from "agentxjs";
645
+ * const ax = createAgentX();
646
+ * const client = await ax.connect("ws://localhost:5200");
647
+ * ```
607
648
  *
608
- * const agentx = await createAgentX({
609
- * serverUrl: "ws://localhost:5200",
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
- * Create an AgentX client
616
- *
617
- * Mode detection:
618
- * - `serverUrl` present → **Remote mode** (WebSocket client)
619
- * - `apiKey` present → **Local mode** (embedded Runtime + MonoDriver)
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 - Client configuration
622
- * @returns Connected AgentX client
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: AgentXConfig): Promise<AgentX>;
669
+ declare function createAgentX(config?: PlatformConfig): AgentXBuilder;
625
670
 
626
- export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentNamespace, type AgentX, type AgentXConfig, type AssistantConversation, type BaseResponse, type Block, 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 LLMProvider, type MaybeAsync, type MessageSendResponse, Presentation, type PresentationErrorHandler, type PresentationNamespace, type PresentationOptions, type PresentationState, type PresentationUpdateHandler, type SessionNamespace, type TextBlock, type ToolBlock, type UserConversation, addUserConversation, createAgentX, createInitialState, initialPresentationState, messagesToConversations, presentationReducer };
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.sessions.send(this.agentId, content);
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.sessions.interrupt(this.agentId);
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.sessions.getMessages(agentId);
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
- containers;
716
- images;
717
- agents;
718
- sessions;
719
- presentations;
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.containers = createLocalContainers(platform);
724
- this.images = createLocalImages(platform);
725
- this.agents = createLocalAgents(runtime);
726
- this.sessions = createLocalSessions(runtime);
727
- this.presentations = createPresentations(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
- containers;
767
- images;
768
- agents;
769
- sessions;
770
- presentations;
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.containers = createRemoteContainers(this.rpcClient);
787
- this.images = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
788
- this.agents = createRemoteAgents(this.rpcClient);
789
- this.sessions = createRemoteSessions(this.rpcClient);
790
- this.presentations = createPresentations(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
- async function createAgentX(config) {
828
- if (config.serverUrl) {
829
- const resolvedConfig = await resolvePlatformForRemote(config);
830
- const client = new RemoteClient(resolvedConfig);
831
- await client.connect();
832
- return client;
833
- }
834
- if (config.apiKey || config.createDriver || config.customPlatform) {
835
- return createLocalClient(config);
836
- }
837
- throw new Error(
838
- "Invalid AgentX config: provide either 'serverUrl' (remote mode) or 'apiKey' (local mode)"
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 (typeof globalThis !== "undefined" && globalThis.window?.document !== void 0) {
846
- return config;
857
+ if (config) {
858
+ getLocalClient();
847
859
  }
848
- try {
849
- const { createNodeWebSocket } = await import("@agentxjs/node-platform/network");
850
- return {
851
- ...config,
852
- customPlatform: {
853
- ...config.customPlatform,
854
- channelClient: createNodeWebSocket
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
- } catch {
858
- return config;
859
- }
860
- }
861
- async function createLocalClient(config) {
862
- const { createAgentXRuntime } = await import("@agentxjs/core/runtime");
863
- let platform;
864
- if (config.customPlatform) {
865
- platform = config.customPlatform;
866
- } else {
867
- const { createNodePlatform } = await import("@agentxjs/node-platform");
868
- platform = await createNodePlatform({
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