agentxjs 2.0.2 → 2.0.4
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 +181 -140
- package/dist/index.js +115 -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/presentations.ts +1 -1
- package/src/presentation/Presentation.ts +2 -2
- package/src/server.ts +346 -0
- package/src/types.ts +84 -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
|
*/
|
|
@@ -509,7 +430,7 @@ interface PresentationNamespace {
|
|
|
509
430
|
*
|
|
510
431
|
* @example
|
|
511
432
|
* ```typescript
|
|
512
|
-
* const pres = agentx.
|
|
433
|
+
* const pres = agentx.presentation.create(agentId, {
|
|
513
434
|
* onUpdate: (state) => renderUI(state),
|
|
514
435
|
* onError: (error) => console.error(error),
|
|
515
436
|
* });
|
|
@@ -521,106 +442,226 @@ interface PresentationNamespace {
|
|
|
521
442
|
create(agentId: string, options?: PresentationOptions): Promise<Presentation>;
|
|
522
443
|
}
|
|
523
444
|
/**
|
|
524
|
-
* AgentX Client SDK
|
|
445
|
+
* AgentX Client SDK — unified interface for local, remote, and server modes
|
|
525
446
|
*/
|
|
526
447
|
interface AgentX {
|
|
527
448
|
/**
|
|
528
|
-
* Check if connected
|
|
449
|
+
* Check if connected/active
|
|
529
450
|
*/
|
|
530
451
|
readonly connected: boolean;
|
|
531
452
|
/**
|
|
532
453
|
* Event bus for subscribing to events
|
|
533
454
|
*/
|
|
534
455
|
readonly events: EventBus;
|
|
456
|
+
readonly container: ContainerNamespace;
|
|
457
|
+
readonly image: ImageNamespace;
|
|
458
|
+
readonly agent: AgentNamespace;
|
|
459
|
+
readonly session: SessionNamespace;
|
|
460
|
+
readonly presentation: PresentationNamespace;
|
|
461
|
+
on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
|
|
462
|
+
type: T;
|
|
463
|
+
}>): Unsubscribe;
|
|
464
|
+
onAny(handler: BusEventHandler): Unsubscribe;
|
|
465
|
+
subscribe(sessionId: string): void;
|
|
466
|
+
disconnect(): Promise<void>;
|
|
467
|
+
dispose(): Promise<void>;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Options for connecting to a remote AgentX server
|
|
471
|
+
*/
|
|
472
|
+
interface ConnectOptions {
|
|
473
|
+
/** Authentication headers */
|
|
474
|
+
headers?: MaybeAsync<Record<string, string>>;
|
|
475
|
+
/** Business context injected into requests */
|
|
476
|
+
context?: MaybeAsync<Record<string, unknown>>;
|
|
477
|
+
/** Request timeout in ms (default: 30000) */
|
|
478
|
+
timeout?: number;
|
|
479
|
+
/** Auto reconnect on disconnect (default: true) */
|
|
480
|
+
autoReconnect?: boolean;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Configuration for serving as an AgentX server
|
|
484
|
+
*/
|
|
485
|
+
interface ServeConfig {
|
|
486
|
+
/** Port to listen on (default: 5200) */
|
|
487
|
+
port?: number;
|
|
488
|
+
/** Host to bind to (default: "0.0.0.0") */
|
|
489
|
+
host?: string;
|
|
490
|
+
/** Existing HTTP server to attach to */
|
|
491
|
+
server?: unknown;
|
|
492
|
+
/** WebSocket path when attached (default: "/ws") */
|
|
493
|
+
wsPath?: string;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Server instance returned by serve()
|
|
497
|
+
*/
|
|
498
|
+
interface AgentXServer {
|
|
499
|
+
listen(port?: number, host?: string): Promise<void>;
|
|
500
|
+
close(): Promise<void>;
|
|
501
|
+
dispose(): Promise<void>;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* AgentXBuilder — fluent API entry point
|
|
505
|
+
*
|
|
506
|
+
* Created by `createAgentX(platform?)`. The builder itself is an AgentX
|
|
507
|
+
* instance (local mode). Call `.connect()` to get a remote client,
|
|
508
|
+
* or `.serve()` to start a server.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```typescript
|
|
512
|
+
* const ax = createAgentX(node({ createDriver }))
|
|
513
|
+
*
|
|
514
|
+
* // Local use
|
|
515
|
+
* await ax.agent.create({ imageId: "..." })
|
|
516
|
+
*
|
|
517
|
+
* // Connect to remote server
|
|
518
|
+
* const client = await ax.connect("wss://...")
|
|
519
|
+
*
|
|
520
|
+
* // Serve as server
|
|
521
|
+
* const server = await ax.serve({ port: 3100 })
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
interface AgentXBuilder extends AgentX {
|
|
535
525
|
/**
|
|
536
|
-
*
|
|
537
|
-
*/
|
|
538
|
-
readonly containers: ContainerNamespace;
|
|
539
|
-
/**
|
|
540
|
-
* Image operations
|
|
526
|
+
* Connect to a remote AgentX server
|
|
541
527
|
*/
|
|
542
|
-
|
|
528
|
+
connect(serverUrl: string, options?: ConnectOptions): Promise<AgentX>;
|
|
543
529
|
/**
|
|
544
|
-
*
|
|
530
|
+
* Start serving as an AgentX server
|
|
545
531
|
*/
|
|
546
|
-
|
|
532
|
+
serve(config?: ServeConfig): Promise<AgentXServer>;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* CommandHandler - Handles JSON-RPC requests directly
|
|
537
|
+
*
|
|
538
|
+
* No longer uses EventBus for request/response. Instead:
|
|
539
|
+
* - Receives RPC requests directly
|
|
540
|
+
* - Returns RPC responses directly
|
|
541
|
+
* - EventBus is only used for stream events (notifications)
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* RPC Result type
|
|
546
|
+
*/
|
|
547
|
+
interface RpcResult<T = unknown> {
|
|
548
|
+
success: true;
|
|
549
|
+
data: T;
|
|
550
|
+
}
|
|
551
|
+
interface RpcError {
|
|
552
|
+
success: false;
|
|
553
|
+
code: number;
|
|
554
|
+
message: string;
|
|
555
|
+
}
|
|
556
|
+
type RpcResponse<T = unknown> = RpcResult<T> | RpcError;
|
|
557
|
+
/**
|
|
558
|
+
* CommandHandler - Processes RPC requests directly
|
|
559
|
+
*/
|
|
560
|
+
declare class CommandHandler {
|
|
561
|
+
private readonly runtime;
|
|
562
|
+
constructor(runtime: AgentXRuntime);
|
|
563
|
+
/**
|
|
564
|
+
* Handle an RPC request and return response
|
|
565
|
+
*/
|
|
566
|
+
handle(method: RpcMethod, params: unknown): Promise<RpcResponse>;
|
|
567
|
+
private handleContainerCreate;
|
|
568
|
+
private handleContainerGet;
|
|
569
|
+
private handleContainerList;
|
|
570
|
+
private handleImageCreate;
|
|
571
|
+
private handleImageGet;
|
|
572
|
+
private handleImageList;
|
|
573
|
+
private handleImageDelete;
|
|
574
|
+
private handleImageRun;
|
|
575
|
+
private handleImageStop;
|
|
576
|
+
private handleImageUpdate;
|
|
577
|
+
private handleImageMessages;
|
|
578
|
+
private handleAgentGet;
|
|
579
|
+
private handleAgentList;
|
|
580
|
+
private handleAgentDestroy;
|
|
581
|
+
private handleAgentDestroyAll;
|
|
582
|
+
private handleAgentInterrupt;
|
|
583
|
+
private handleMessageSend;
|
|
584
|
+
dispose(): void;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Server configuration (supports both immediate and deferred platforms)
|
|
589
|
+
*/
|
|
590
|
+
interface ServerConfig {
|
|
547
591
|
/**
|
|
548
|
-
*
|
|
592
|
+
* AgentX Platform — must provide `channelServer` for accepting WebSocket connections.
|
|
549
593
|
*/
|
|
550
|
-
|
|
594
|
+
platform: AgentXPlatform;
|
|
551
595
|
/**
|
|
552
|
-
*
|
|
596
|
+
* LLM Driver factory function - creates Driver per Agent
|
|
553
597
|
*/
|
|
554
|
-
|
|
598
|
+
createDriver: CreateDriver;
|
|
555
599
|
/**
|
|
556
|
-
*
|
|
600
|
+
* Port to listen on (standalone mode)
|
|
557
601
|
*/
|
|
558
|
-
|
|
559
|
-
type: T;
|
|
560
|
-
}>): Unsubscribe;
|
|
602
|
+
port?: number;
|
|
561
603
|
/**
|
|
562
|
-
*
|
|
604
|
+
* Host to bind to (default: "0.0.0.0")
|
|
563
605
|
*/
|
|
564
|
-
|
|
606
|
+
host?: string;
|
|
565
607
|
/**
|
|
566
|
-
*
|
|
608
|
+
* Existing HTTP server to attach to (attached mode)
|
|
567
609
|
*/
|
|
568
|
-
|
|
610
|
+
server?: _agentxjs_core_network.MinimalHTTPServer;
|
|
569
611
|
/**
|
|
570
|
-
*
|
|
612
|
+
* WebSocket path when attached (default: "/ws")
|
|
571
613
|
*/
|
|
572
|
-
|
|
614
|
+
wsPath?: string;
|
|
573
615
|
/**
|
|
574
|
-
*
|
|
616
|
+
* Enable debug logging
|
|
575
617
|
*/
|
|
576
|
-
|
|
618
|
+
debug?: boolean;
|
|
577
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Create an AgentX server
|
|
622
|
+
*/
|
|
623
|
+
declare function createServer(config: ServerConfig): Promise<AgentXServer>;
|
|
578
624
|
|
|
579
625
|
/**
|
|
580
626
|
* agentxjs - AgentX Client SDK
|
|
581
627
|
*
|
|
582
|
-
*
|
|
628
|
+
* Fluent API supporting local, remote, and server modes.
|
|
583
629
|
*
|
|
584
|
-
* @example Local mode
|
|
630
|
+
* @example Local mode
|
|
585
631
|
* ```typescript
|
|
586
632
|
* import { createAgentX } from "agentxjs";
|
|
633
|
+
* import { node } from "@agentxjs/node-platform";
|
|
587
634
|
*
|
|
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!");
|
|
635
|
+
* const ax = createAgentX(node({ createDriver }));
|
|
636
|
+
* await ax.agent.create({ imageId: "..." });
|
|
602
637
|
* ```
|
|
603
638
|
*
|
|
604
|
-
* @example Remote mode
|
|
639
|
+
* @example Remote mode
|
|
605
640
|
* ```typescript
|
|
606
|
-
*
|
|
641
|
+
* const ax = createAgentX();
|
|
642
|
+
* const client = await ax.connect("ws://localhost:5200");
|
|
643
|
+
* ```
|
|
607
644
|
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
* });
|
|
645
|
+
* @example Server mode
|
|
646
|
+
* ```typescript
|
|
647
|
+
* const ax = createAgentX(node({ createDriver }));
|
|
648
|
+
* const server = await ax.serve({ port: 5200 });
|
|
611
649
|
* ```
|
|
612
650
|
*/
|
|
613
651
|
|
|
614
652
|
/**
|
|
615
|
-
*
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
653
|
+
* Platform configuration for createAgentX
|
|
654
|
+
*/
|
|
655
|
+
interface PlatformConfig {
|
|
656
|
+
platform: AgentXPlatform;
|
|
657
|
+
createDriver: CreateDriver;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Create an AgentX builder
|
|
620
661
|
*
|
|
621
|
-
* @param config -
|
|
622
|
-
* @returns
|
|
662
|
+
* @param config - Platform configuration (optional). Without it, only connect() is available.
|
|
663
|
+
* @returns AgentXBuilder — local AgentX + connect() + serve()
|
|
623
664
|
*/
|
|
624
|
-
declare function createAgentX(config
|
|
665
|
+
declare function createAgentX(config?: PlatformConfig): AgentXBuilder;
|
|
625
666
|
|
|
626
|
-
export { type AgentCreateResponse, type AgentGetResponse, type AgentInfo, type AgentListResponse, type AgentNamespace, type AgentX, type
|
|
667
|
+
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
|
|
|
@@ -586,7 +594,7 @@ var Presentation = class {
|
|
|
586
594
|
this.state = addUserConversation(this.state, content);
|
|
587
595
|
this.notify();
|
|
588
596
|
try {
|
|
589
|
-
await this.agentx.
|
|
597
|
+
await this.agentx.session.send(this.agentId, content);
|
|
590
598
|
} catch (error) {
|
|
591
599
|
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
592
600
|
}
|
|
@@ -596,7 +604,7 @@ var Presentation = class {
|
|
|
596
604
|
*/
|
|
597
605
|
async interrupt() {
|
|
598
606
|
try {
|
|
599
|
-
await this.agentx.
|
|
607
|
+
await this.agentx.session.interrupt(this.agentId);
|
|
600
608
|
} catch (error) {
|
|
601
609
|
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
602
610
|
}
|
|
@@ -658,7 +666,7 @@ var Presentation = class {
|
|
|
658
666
|
function createPresentations(agentx) {
|
|
659
667
|
return {
|
|
660
668
|
async create(agentId, options) {
|
|
661
|
-
const messages = await agentx.
|
|
669
|
+
const messages = await agentx.session.getMessages(agentId);
|
|
662
670
|
const conversations = messagesToConversations(messages);
|
|
663
671
|
return new Presentation(agentx, agentId, options, conversations);
|
|
664
672
|
}
|
|
@@ -712,19 +720,19 @@ var logger = createLogger("agentx/LocalClient");
|
|
|
712
720
|
var LocalClient = class {
|
|
713
721
|
runtime;
|
|
714
722
|
isDisposed = false;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
723
|
+
container;
|
|
724
|
+
image;
|
|
725
|
+
agent;
|
|
726
|
+
session;
|
|
727
|
+
presentation;
|
|
720
728
|
constructor(runtime) {
|
|
721
729
|
this.runtime = runtime;
|
|
722
730
|
const platform = runtime.platform;
|
|
723
|
-
this.
|
|
724
|
-
this.
|
|
725
|
-
this.
|
|
726
|
-
this.
|
|
727
|
-
this.
|
|
731
|
+
this.container = createLocalContainers(platform);
|
|
732
|
+
this.image = createLocalImages(platform);
|
|
733
|
+
this.agent = createLocalAgents(runtime);
|
|
734
|
+
this.session = createLocalSessions(runtime);
|
|
735
|
+
this.presentation = createPresentations(this);
|
|
728
736
|
logger.info("LocalClient initialized");
|
|
729
737
|
}
|
|
730
738
|
// ==================== Properties ====================
|
|
@@ -763,11 +771,11 @@ var RemoteClient = class {
|
|
|
763
771
|
config;
|
|
764
772
|
eventBus;
|
|
765
773
|
rpcClient;
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
774
|
+
container;
|
|
775
|
+
image;
|
|
776
|
+
agent;
|
|
777
|
+
session;
|
|
778
|
+
presentation;
|
|
771
779
|
constructor(config) {
|
|
772
780
|
this.config = config;
|
|
773
781
|
this.eventBus = new EventBusImpl();
|
|
@@ -783,11 +791,11 @@ var RemoteClient = class {
|
|
|
783
791
|
logger2.debug("Received stream event", { topic, type: event.type });
|
|
784
792
|
this.eventBus.emit(event);
|
|
785
793
|
});
|
|
786
|
-
this.
|
|
787
|
-
this.
|
|
788
|
-
this.
|
|
789
|
-
this.
|
|
790
|
-
this.
|
|
794
|
+
this.container = createRemoteContainers(this.rpcClient);
|
|
795
|
+
this.image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
|
|
796
|
+
this.agent = createRemoteAgents(this.rpcClient);
|
|
797
|
+
this.session = createRemoteSessions(this.rpcClient);
|
|
798
|
+
this.presentation = createPresentations(this);
|
|
791
799
|
}
|
|
792
800
|
// ==================== Properties ====================
|
|
793
801
|
get connected() {
|
|
@@ -824,77 +832,100 @@ var RemoteClient = class {
|
|
|
824
832
|
};
|
|
825
833
|
|
|
826
834
|
// 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;
|
|
835
|
+
function createAgentX(config) {
|
|
836
|
+
let localClient = null;
|
|
837
|
+
function getLocalClient() {
|
|
838
|
+
if (localClient) return localClient;
|
|
839
|
+
if (!config) {
|
|
840
|
+
throw new Error(
|
|
841
|
+
"Local mode requires a platform. Pass a PlatformConfig to createAgentX(), or use connect() for remote mode."
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
const runtime = createAgentXRuntime(config.platform, config.createDriver);
|
|
845
|
+
localClient = new LocalClient(runtime);
|
|
846
|
+
return localClient;
|
|
844
847
|
}
|
|
845
|
-
if (
|
|
846
|
-
|
|
848
|
+
if (config) {
|
|
849
|
+
getLocalClient();
|
|
847
850
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
851
|
+
return {
|
|
852
|
+
get connected() {
|
|
853
|
+
return localClient?.connected ?? false;
|
|
854
|
+
},
|
|
855
|
+
get events() {
|
|
856
|
+
return getLocalClient().events;
|
|
857
|
+
},
|
|
858
|
+
get container() {
|
|
859
|
+
return getLocalClient().container;
|
|
860
|
+
},
|
|
861
|
+
get image() {
|
|
862
|
+
return getLocalClient().image;
|
|
863
|
+
},
|
|
864
|
+
get agent() {
|
|
865
|
+
return getLocalClient().agent;
|
|
866
|
+
},
|
|
867
|
+
get session() {
|
|
868
|
+
return getLocalClient().session;
|
|
869
|
+
},
|
|
870
|
+
get presentation() {
|
|
871
|
+
return getLocalClient().presentation;
|
|
872
|
+
},
|
|
873
|
+
on(type, handler) {
|
|
874
|
+
return getLocalClient().on(type, handler);
|
|
875
|
+
},
|
|
876
|
+
onAny(handler) {
|
|
877
|
+
return getLocalClient().onAny(handler);
|
|
878
|
+
},
|
|
879
|
+
subscribe(sessionId) {
|
|
880
|
+
getLocalClient().subscribe(sessionId);
|
|
881
|
+
},
|
|
882
|
+
async disconnect() {
|
|
883
|
+
await localClient?.disconnect();
|
|
884
|
+
},
|
|
885
|
+
async dispose() {
|
|
886
|
+
await localClient?.dispose();
|
|
887
|
+
localClient = null;
|
|
888
|
+
},
|
|
889
|
+
async connect(serverUrl, options) {
|
|
890
|
+
const remoteClient = new RemoteClient({
|
|
891
|
+
serverUrl,
|
|
892
|
+
headers: options?.headers,
|
|
893
|
+
context: options?.context,
|
|
894
|
+
timeout: options?.timeout,
|
|
895
|
+
autoReconnect: options?.autoReconnect,
|
|
896
|
+
customPlatform: config?.platform
|
|
897
|
+
});
|
|
898
|
+
await remoteClient.connect();
|
|
899
|
+
return remoteClient;
|
|
900
|
+
},
|
|
901
|
+
async serve(serveConfig) {
|
|
902
|
+
if (!config) {
|
|
903
|
+
throw new Error("serve() requires a platform. Pass a PlatformConfig to createAgentX().");
|
|
855
904
|
}
|
|
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
|
-
}
|
|
905
|
+
if (!config.platform.channelServer) {
|
|
906
|
+
throw new Error(
|
|
907
|
+
"serve() requires platform.channelServer. Ensure your platform supports server mode."
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
const { createServer: createServer2 } = await import("./server-IFVYHIJF.js");
|
|
911
|
+
return createServer2({
|
|
912
|
+
platform: config.platform,
|
|
913
|
+
createDriver: config.createDriver,
|
|
914
|
+
port: serveConfig?.port,
|
|
915
|
+
host: serveConfig?.host,
|
|
916
|
+
server: serveConfig?.server,
|
|
917
|
+
wsPath: serveConfig?.wsPath
|
|
887
918
|
});
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
const runtime = createAgentXRuntime(platform, createDriver);
|
|
891
|
-
return new LocalClient(runtime);
|
|
919
|
+
}
|
|
920
|
+
};
|
|
892
921
|
}
|
|
893
922
|
export {
|
|
923
|
+
CommandHandler,
|
|
894
924
|
Presentation,
|
|
895
925
|
addUserConversation,
|
|
896
926
|
createAgentX,
|
|
897
927
|
createInitialState,
|
|
928
|
+
createServer,
|
|
898
929
|
initialPresentationState,
|
|
899
930
|
messagesToConversations,
|
|
900
931
|
presentationReducer
|