agentxjs 2.1.1 → 2.3.0

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,10 @@
1
1
  import { CreateDriver } from '@agentxjs/core/driver';
2
2
  import { AgentXRuntime, AgentXPlatform } from '@agentxjs/core/runtime';
3
3
  import { Message } from '@agentxjs/core/agent';
4
+ import { AgentXError } from '@agentxjs/core/error';
5
+ export { AgentXError, AgentXErrorCategory, AgentXErrorCode, AgentXErrorContext } from '@agentxjs/core/error';
4
6
  import { Unsubscribe, BusEvent, EventBus, BusEventHandler } from '@agentxjs/core/event';
7
+ import { LLMProtocol, LLMProviderRecord } from '@agentxjs/core/persistence';
5
8
  import * as _agentxjs_core_network from '@agentxjs/core/network';
6
9
  import { RpcMethod } from '@agentxjs/core/network';
7
10
 
@@ -327,6 +330,36 @@ interface ContainerListResponse extends BaseResponse {
327
330
  interface MessageSendResponse extends BaseResponse {
328
331
  agentId: string;
329
332
  }
333
+ /**
334
+ * LLM provider create response
335
+ */
336
+ interface LLMProviderCreateResponse extends BaseResponse {
337
+ record: LLMProviderRecord;
338
+ }
339
+ /**
340
+ * LLM provider get response
341
+ */
342
+ interface LLMProviderGetResponse extends BaseResponse {
343
+ record: LLMProviderRecord | null;
344
+ }
345
+ /**
346
+ * LLM provider list response
347
+ */
348
+ interface LLMProviderListResponse extends BaseResponse {
349
+ records: LLMProviderRecord[];
350
+ }
351
+ /**
352
+ * LLM provider update response
353
+ */
354
+ interface LLMProviderUpdateResponse extends BaseResponse {
355
+ record: LLMProviderRecord;
356
+ }
357
+ /**
358
+ * LLM provider default response
359
+ */
360
+ interface LLMProviderDefaultResponse extends BaseResponse {
361
+ record: LLMProviderRecord | null;
362
+ }
330
363
  /**
331
364
  * Container operations namespace
332
365
  */
@@ -425,6 +458,54 @@ interface SessionNamespace {
425
458
  */
426
459
  getMessages(agentId: string): Promise<Message[]>;
427
460
  }
461
+ /**
462
+ * LLM provider operations namespace
463
+ */
464
+ interface LLMNamespace {
465
+ /**
466
+ * Create a new LLM provider configuration
467
+ */
468
+ create(params: {
469
+ containerId: string;
470
+ name: string;
471
+ vendor: string;
472
+ protocol: LLMProtocol;
473
+ apiKey: string;
474
+ baseUrl?: string;
475
+ model?: string;
476
+ }): Promise<LLMProviderCreateResponse>;
477
+ /**
478
+ * Get LLM provider by ID
479
+ */
480
+ get(id: string): Promise<LLMProviderGetResponse>;
481
+ /**
482
+ * List LLM providers for a container
483
+ */
484
+ list(containerId: string): Promise<LLMProviderListResponse>;
485
+ /**
486
+ * Update LLM provider
487
+ */
488
+ update(id: string, updates: {
489
+ name?: string;
490
+ vendor?: string;
491
+ protocol?: LLMProtocol;
492
+ apiKey?: string;
493
+ baseUrl?: string;
494
+ model?: string;
495
+ }): Promise<LLMProviderUpdateResponse>;
496
+ /**
497
+ * Delete LLM provider
498
+ */
499
+ delete(id: string): Promise<BaseResponse>;
500
+ /**
501
+ * Set default LLM provider for a container
502
+ */
503
+ setDefault(id: string): Promise<BaseResponse>;
504
+ /**
505
+ * Get default LLM provider for a container
506
+ */
507
+ getDefault(containerId: string): Promise<LLMProviderDefaultResponse>;
508
+ }
428
509
  /**
429
510
  * Presentation operations namespace
430
511
  */
@@ -462,11 +543,28 @@ interface AgentX {
462
543
  readonly agent: AgentNamespace;
463
544
  readonly session: SessionNamespace;
464
545
  readonly presentation: PresentationNamespace;
546
+ readonly llm: LLMNamespace;
465
547
  on<T extends string>(type: T, handler: BusEventHandler<BusEvent & {
466
548
  type: T;
467
549
  }>): Unsubscribe;
468
550
  onAny(handler: BusEventHandler): Unsubscribe;
469
551
  subscribe(sessionId: string): void;
552
+ /**
553
+ * Top-level error handler — receives all AgentXError instances from any layer.
554
+ *
555
+ * Independent of `on("error", ...)` (stream events) and `presentation.onError` (UI errors).
556
+ *
557
+ * @example
558
+ * ```typescript
559
+ * ax.onError((error) => {
560
+ * console.error(`[${error.category}] ${error.code}: ${error.message}`);
561
+ * if (!error.recoverable) {
562
+ * // Circuit is open, stop sending requests
563
+ * }
564
+ * });
565
+ * ```
566
+ */
567
+ onError(handler: (error: AgentXError) => void): Unsubscribe;
470
568
  /**
471
569
  * Universal JSON-RPC entry point — works in all modes:
472
570
  * - Local: dispatches to CommandHandler directly
@@ -597,6 +695,12 @@ declare class CommandHandler {
597
695
  private handleAgentDestroyAll;
598
696
  private handleAgentInterrupt;
599
697
  private handleMessageSend;
698
+ private handleLLMCreate;
699
+ private handleLLMGet;
700
+ private handleLLMList;
701
+ private handleLLMUpdate;
702
+ private handleLLMDelete;
703
+ private handleLLMDefault;
600
704
  dispose(): void;
601
705
  }
602
706
 
@@ -646,9 +750,9 @@ declare function createServer(config: ServerConfig): Promise<AgentXServer>;
646
750
  * @example Local mode
647
751
  * ```typescript
648
752
  * import { createAgentX } from "agentxjs";
649
- * import { node } from "@agentxjs/node-platform";
753
+ * import { nodePlatform } from "@agentxjs/node-platform";
650
754
  *
651
- * const ax = createAgentX(node({ createDriver }));
755
+ * const ax = createAgentX(nodePlatform({ createDriver }));
652
756
  * await ax.agent.create({ imageId: "..." });
653
757
  * ```
654
758
  *
@@ -660,7 +764,7 @@ declare function createServer(config: ServerConfig): Promise<AgentXServer>;
660
764
  *
661
765
  * @example Server mode
662
766
  * ```typescript
663
- * const ax = createAgentX(node({ createDriver }));
767
+ * const ax = createAgentX(nodePlatform({ createDriver }));
664
768
  * const server = await ax.serve({ port: 5200 });
665
769
  * ```
666
770
  */
@@ -680,4 +784,4 @@ interface PlatformConfig {
680
784
  */
681
785
  declare function createAgentX(config?: PlatformConfig): AgentXBuilder;
682
786
 
683
- 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 };
787
+ 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 LLMNamespace, type LLMProviderCreateResponse, type LLMProviderDefaultResponse, type LLMProviderGetResponse, type LLMProviderListResponse, type LLMProviderUpdateResponse, 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,7 +1,7 @@
1
1
  import {
2
2
  CommandHandler,
3
3
  createServer
4
- } from "./chunk-ZFL27HK7.js";
4
+ } from "./chunk-X44CQZPK.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { createAgentXRuntime } from "@agentxjs/core/runtime";
@@ -251,6 +251,108 @@ function createRemoteImages(rpcClient, subscribeFn) {
251
251
  };
252
252
  }
253
253
 
254
+ // src/namespaces/llm.ts
255
+ import { generateId } from "@deepracticex/id";
256
+ function createLocalLLM(platform) {
257
+ const repo = platform.llmProviderRepository;
258
+ if (!repo) {
259
+ throw new Error("LLM provider repository not available on this platform");
260
+ }
261
+ return {
262
+ async create(params) {
263
+ const now = Date.now();
264
+ const record = {
265
+ id: generateId("llm"),
266
+ containerId: params.containerId,
267
+ name: params.name,
268
+ vendor: params.vendor,
269
+ protocol: params.protocol,
270
+ apiKey: params.apiKey,
271
+ baseUrl: params.baseUrl,
272
+ model: params.model,
273
+ isDefault: false,
274
+ createdAt: now,
275
+ updatedAt: now
276
+ };
277
+ await repo.saveLLMProvider(record);
278
+ return { record, requestId: "" };
279
+ },
280
+ async get(id) {
281
+ const record = await repo.findLLMProviderById(id);
282
+ return { record, requestId: "" };
283
+ },
284
+ async list(containerId) {
285
+ const records = await repo.findLLMProvidersByContainerId(containerId);
286
+ return { records, requestId: "" };
287
+ },
288
+ async update(id, updates) {
289
+ const existing = await repo.findLLMProviderById(id);
290
+ if (!existing) {
291
+ throw new Error(`LLM provider not found: ${id}`);
292
+ }
293
+ const updated = {
294
+ ...existing,
295
+ ...updates,
296
+ id: existing.id,
297
+ containerId: existing.containerId,
298
+ createdAt: existing.createdAt,
299
+ updatedAt: Date.now()
300
+ };
301
+ await repo.saveLLMProvider(updated);
302
+ return { record: updated, requestId: "" };
303
+ },
304
+ async delete(id) {
305
+ await repo.deleteLLMProvider(id);
306
+ return { requestId: "" };
307
+ },
308
+ async setDefault(id) {
309
+ await repo.setDefaultLLMProvider(id);
310
+ return { requestId: "" };
311
+ },
312
+ async getDefault(containerId) {
313
+ const record = await repo.findDefaultLLMProvider(containerId);
314
+ return { record, requestId: "" };
315
+ }
316
+ };
317
+ }
318
+ function createRemoteLLM(rpcClient) {
319
+ return {
320
+ async create(params) {
321
+ const result = await rpcClient.call("llm.create", params);
322
+ return { ...result, requestId: "" };
323
+ },
324
+ async get(id) {
325
+ const result = await rpcClient.call("llm.get", { id });
326
+ return { ...result, requestId: "" };
327
+ },
328
+ async list(containerId) {
329
+ const result = await rpcClient.call("llm.list", { containerId });
330
+ return { ...result, requestId: "" };
331
+ },
332
+ async update(id, updates) {
333
+ const result = await rpcClient.call("llm.update", {
334
+ id,
335
+ updates
336
+ });
337
+ return { ...result, requestId: "" };
338
+ },
339
+ async delete(id) {
340
+ const result = await rpcClient.call("llm.delete", { id });
341
+ return { ...result, requestId: "" };
342
+ },
343
+ async setDefault(id) {
344
+ const result = await rpcClient.call("llm.default", { id });
345
+ return { ...result, requestId: "" };
346
+ },
347
+ async getDefault(containerId) {
348
+ const result = await rpcClient.call("llm.default", {
349
+ containerId
350
+ });
351
+ return { ...result, requestId: "" };
352
+ }
353
+ };
354
+ }
355
+
254
356
  // src/presentation/types.ts
255
357
  var initialPresentationState = {
256
358
  conversations: [],
@@ -735,6 +837,7 @@ var LocalClient = class {
735
837
  agent;
736
838
  session;
737
839
  presentation;
840
+ llm;
738
841
  constructor(runtime) {
739
842
  this.runtime = runtime;
740
843
  const platform = runtime.platform;
@@ -743,6 +846,7 @@ var LocalClient = class {
743
846
  this.agent = createLocalAgents(runtime);
744
847
  this.session = createLocalSessions(runtime);
745
848
  this.presentation = createPresentations(this);
849
+ this.llm = createLocalLLM(platform);
746
850
  logger.info("LocalClient initialized");
747
851
  }
748
852
  // ==================== Properties ====================
@@ -761,6 +865,12 @@ var LocalClient = class {
761
865
  }
762
866
  subscribe(_sessionId) {
763
867
  }
868
+ // ==================== Error Handling ====================
869
+ onError(handler) {
870
+ return this.runtime.platform.eventBus.on("agentx_error", (event) => {
871
+ handler(event.data);
872
+ });
873
+ }
764
874
  // ==================== RPC ====================
765
875
  async rpc(method, params) {
766
876
  if (!this.commandHandler) {
@@ -797,6 +907,7 @@ var RemoteClient = class {
797
907
  agent;
798
908
  session;
799
909
  presentation;
910
+ llm;
800
911
  constructor(config) {
801
912
  this.config = config;
802
913
  this.eventBus = new EventBusImpl();
@@ -817,6 +928,7 @@ var RemoteClient = class {
817
928
  this.agent = createRemoteAgents(this.rpcClient);
818
929
  this.session = createRemoteSessions(this.rpcClient);
819
930
  this.presentation = createPresentations(this);
931
+ this.llm = createRemoteLLM(this.rpcClient);
820
932
  }
821
933
  // ==================== Properties ====================
822
934
  get connected() {
@@ -850,6 +962,12 @@ var RemoteClient = class {
850
962
  this.rpcClient.subscribe(sessionId);
851
963
  logger2.debug("Subscribed to session", { sessionId });
852
964
  }
965
+ // ==================== Error Handling ====================
966
+ onError(handler) {
967
+ return this.eventBus.on("agentx_error", (event) => {
968
+ handler(event.data);
969
+ });
970
+ }
853
971
  // ==================== RPC ====================
854
972
  async rpc(method, params) {
855
973
  return this.rpcClient.call(method, params);
@@ -857,6 +975,7 @@ var RemoteClient = class {
857
975
  };
858
976
 
859
977
  // src/index.ts
978
+ import { AgentXError, AgentXErrorCode } from "@agentxjs/core/error";
860
979
  function createAgentX(config) {
861
980
  let localClient = null;
862
981
  function getLocalClient() {
@@ -895,6 +1014,9 @@ function createAgentX(config) {
895
1014
  get presentation() {
896
1015
  return getLocalClient().presentation;
897
1016
  },
1017
+ get llm() {
1018
+ return getLocalClient().llm;
1019
+ },
898
1020
  on(type, handler) {
899
1021
  return getLocalClient().on(type, handler);
900
1022
  },
@@ -904,6 +1026,9 @@ function createAgentX(config) {
904
1026
  subscribe(sessionId) {
905
1027
  getLocalClient().subscribe(sessionId);
906
1028
  },
1029
+ onError(handler) {
1030
+ return getLocalClient().onError(handler);
1031
+ },
907
1032
  async disconnect() {
908
1033
  await localClient?.disconnect();
909
1034
  },
@@ -932,7 +1057,7 @@ function createAgentX(config) {
932
1057
  "serve() requires platform.channelServer. Ensure your platform supports server mode."
933
1058
  );
934
1059
  }
935
- const { createServer: createServer2 } = await import("./server-IFVYHIJF.js");
1060
+ const { createServer: createServer2 } = await import("./server-BWI5JE4B.js");
936
1061
  return createServer2({
937
1062
  platform: config.platform,
938
1063
  createDriver: config.createDriver,
@@ -948,6 +1073,8 @@ function createAgentX(config) {
948
1073
  };
949
1074
  }
950
1075
  export {
1076
+ AgentXError,
1077
+ AgentXErrorCode,
951
1078
  CommandHandler,
952
1079
  Presentation,
953
1080
  addUserConversation,