agentxjs 2.3.1 → 2.5.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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CommandHandler,
3
3
  createServer
4
- } from "./chunk-X44CQZPK.js";
4
+ } from "./chunk-7GW66EMD.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { createAgentXRuntime } from "@agentxjs/core/runtime";
@@ -9,6 +9,41 @@ import { createAgentXRuntime } from "@agentxjs/core/runtime";
9
9
  // src/LocalClient.ts
10
10
  import { createLogger } from "commonxjs/logger";
11
11
 
12
+ // src/AgentHandle.ts
13
+ var AgentHandleImpl = class {
14
+ agentId;
15
+ imageId;
16
+ containerId;
17
+ sessionId;
18
+ ns;
19
+ constructor(ids, ns) {
20
+ this.agentId = ids.agentId;
21
+ this.imageId = ids.imageId;
22
+ this.containerId = ids.containerId;
23
+ this.sessionId = ids.sessionId;
24
+ this.ns = ns;
25
+ }
26
+ async send(content) {
27
+ return this.ns.session.send(this.agentId, content);
28
+ }
29
+ async interrupt() {
30
+ return this.ns.session.interrupt(this.agentId);
31
+ }
32
+ async history() {
33
+ return this.ns.image.getMessages(this.imageId);
34
+ }
35
+ async present(options) {
36
+ return this.ns.present.create(this.agentId, options);
37
+ }
38
+ async update(updates) {
39
+ await this.ns.image.update(this.imageId, updates);
40
+ }
41
+ async delete() {
42
+ await this.ns.agent.destroy(this.agentId);
43
+ await this.ns.image.delete(this.imageId);
44
+ }
45
+ };
46
+
12
47
  // src/namespaces/agents.ts
13
48
  function createLocalAgents(runtime) {
14
49
  return {
@@ -705,7 +740,7 @@ var Presentation = class {
705
740
  this.state = addUserConversation(this.state, content);
706
741
  this.notify();
707
742
  try {
708
- await this.agentx.session.send(this.agentId, content);
743
+ await this.agentx.instance.session.send(this.agentId, content);
709
744
  } catch (error) {
710
745
  this.notifyError(error instanceof Error ? error : new Error(String(error)));
711
746
  }
@@ -715,7 +750,7 @@ var Presentation = class {
715
750
  */
716
751
  async interrupt() {
717
752
  try {
718
- await this.agentx.session.interrupt(this.agentId);
753
+ await this.agentx.instance.session.interrupt(this.agentId);
719
754
  } catch (error) {
720
755
  this.notifyError(error instanceof Error ? error : new Error(String(error)));
721
756
  }
@@ -774,10 +809,10 @@ var Presentation = class {
774
809
  };
775
810
 
776
811
  // src/namespaces/presentations.ts
777
- function createPresentations(agentx) {
812
+ function createPresentations(agentx, imageNs) {
778
813
  return {
779
814
  async create(agentId, options) {
780
- const messages = await agentx.session.getMessages(agentId);
815
+ const messages = await imageNs.getMessages(agentId);
781
816
  const conversations = messagesToConversations(messages);
782
817
  return new Presentation(agentx, agentId, options, conversations);
783
818
  }
@@ -832,21 +867,19 @@ var LocalClient = class {
832
867
  runtime;
833
868
  commandHandler = null;
834
869
  isDisposed = false;
835
- container;
836
- image;
837
- agent;
838
- session;
839
- presentation;
840
- llm;
870
+ instance;
871
+ provider;
841
872
  constructor(runtime) {
842
873
  this.runtime = runtime;
843
874
  const platform = runtime.platform;
844
- this.container = createLocalContainers(platform);
845
- this.image = createLocalImages(platform);
846
- this.agent = createLocalAgents(runtime);
847
- this.session = createLocalSessions(runtime);
848
- this.presentation = createPresentations(this);
849
- this.llm = createLocalLLM(platform);
875
+ const container = createLocalContainers(platform);
876
+ const image = createLocalImages(platform);
877
+ const agent = createLocalAgents(runtime);
878
+ const session = createLocalSessions(runtime);
879
+ const llm = createLocalLLM(platform);
880
+ const present = createPresentations(this, image);
881
+ this.instance = { container, image, agent, session, present, llm };
882
+ this.provider = llm;
850
883
  logger.info("LocalClient initialized");
851
884
  }
852
885
  // ==================== Properties ====================
@@ -856,6 +889,38 @@ var LocalClient = class {
856
889
  get events() {
857
890
  return this.runtime.platform.eventBus;
858
891
  }
892
+ // ==================== Top-level Agent API ====================
893
+ async create(params) {
894
+ const containerId = "default";
895
+ const imgRes = await this.instance.image.create({ containerId, ...params });
896
+ const agentRes = await this.instance.agent.create({ imageId: imgRes.record.imageId });
897
+ return new AgentHandleImpl(
898
+ {
899
+ agentId: agentRes.agentId,
900
+ imageId: agentRes.imageId,
901
+ containerId: agentRes.containerId,
902
+ sessionId: agentRes.sessionId
903
+ },
904
+ this.instance
905
+ );
906
+ }
907
+ async list() {
908
+ return this.instance.image.list();
909
+ }
910
+ async get(agentId) {
911
+ const res = await this.instance.image.get(agentId);
912
+ if (!res.record) return null;
913
+ const r = res.record;
914
+ return new AgentHandleImpl(
915
+ {
916
+ agentId: r.imageId,
917
+ imageId: r.imageId,
918
+ containerId: r.containerId,
919
+ sessionId: r.sessionId
920
+ },
921
+ this.instance
922
+ );
923
+ }
859
924
  // ==================== Event Subscription ====================
860
925
  on(type, handler) {
861
926
  return this.runtime.platform.eventBus.on(type, handler);
@@ -902,12 +967,8 @@ var RemoteClient = class {
902
967
  config;
903
968
  eventBus;
904
969
  rpcClient;
905
- container;
906
- image;
907
- agent;
908
- session;
909
- presentation;
910
- llm;
970
+ instance;
971
+ provider;
911
972
  constructor(config) {
912
973
  this.config = config;
913
974
  this.eventBus = new EventBusImpl();
@@ -923,12 +984,14 @@ var RemoteClient = class {
923
984
  logger2.debug("Received stream event", { topic, type: event.type });
924
985
  this.eventBus.emit(event);
925
986
  });
926
- this.container = createRemoteContainers(this.rpcClient);
927
- this.image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
928
- this.agent = createRemoteAgents(this.rpcClient);
929
- this.session = createRemoteSessions(this.rpcClient);
930
- this.presentation = createPresentations(this);
931
- this.llm = createRemoteLLM(this.rpcClient);
987
+ const container = createRemoteContainers(this.rpcClient);
988
+ const image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
989
+ const agent = createRemoteAgents(this.rpcClient);
990
+ const session = createRemoteSessions(this.rpcClient);
991
+ const llm = createRemoteLLM(this.rpcClient);
992
+ const present = createPresentations(this, image);
993
+ this.instance = { container, image, agent, session, present, llm };
994
+ this.provider = llm;
932
995
  }
933
996
  // ==================== Properties ====================
934
997
  get connected() {
@@ -937,6 +1000,38 @@ var RemoteClient = class {
937
1000
  get events() {
938
1001
  return this.eventBus;
939
1002
  }
1003
+ // ==================== Top-level Agent API ====================
1004
+ async create(params) {
1005
+ const containerId = "default";
1006
+ const imgRes = await this.instance.image.create({ containerId, ...params });
1007
+ const agentRes = await this.instance.agent.create({ imageId: imgRes.record.imageId });
1008
+ return new AgentHandleImpl(
1009
+ {
1010
+ agentId: agentRes.agentId,
1011
+ imageId: agentRes.imageId,
1012
+ containerId: agentRes.containerId,
1013
+ sessionId: agentRes.sessionId
1014
+ },
1015
+ this.instance
1016
+ );
1017
+ }
1018
+ async list() {
1019
+ return this.instance.image.list();
1020
+ }
1021
+ async get(agentId) {
1022
+ const res = await this.instance.image.get(agentId);
1023
+ if (!res.record) return null;
1024
+ const r = res.record;
1025
+ return new AgentHandleImpl(
1026
+ {
1027
+ agentId: r.imageId,
1028
+ imageId: r.imageId,
1029
+ containerId: r.containerId,
1030
+ sessionId: r.sessionId
1031
+ },
1032
+ this.instance
1033
+ );
1034
+ }
940
1035
  // ==================== Connection ====================
941
1036
  async connect() {
942
1037
  await this.rpcClient.connect();
@@ -999,24 +1094,16 @@ function createAgentX(config) {
999
1094
  get events() {
1000
1095
  return getLocalClient().events;
1001
1096
  },
1002
- get container() {
1003
- return getLocalClient().container;
1004
- },
1005
- get image() {
1006
- return getLocalClient().image;
1007
- },
1008
- get agent() {
1009
- return getLocalClient().agent;
1010
- },
1011
- get session() {
1012
- return getLocalClient().session;
1013
- },
1014
- get presentation() {
1015
- return getLocalClient().presentation;
1097
+ get instance() {
1098
+ return getLocalClient().instance;
1016
1099
  },
1017
- get llm() {
1018
- return getLocalClient().llm;
1100
+ get provider() {
1101
+ return getLocalClient().provider;
1019
1102
  },
1103
+ // Top-level Agent API
1104
+ create: (params) => getLocalClient().create(params),
1105
+ list: () => getLocalClient().list(),
1106
+ get: (agentId) => getLocalClient().get(agentId),
1020
1107
  on(type, handler) {
1021
1108
  return getLocalClient().on(type, handler);
1022
1109
  },
@@ -1057,7 +1144,7 @@ function createAgentX(config) {
1057
1144
  "serve() requires platform.channelServer. Ensure your platform supports server mode."
1058
1145
  );
1059
1146
  }
1060
- const { createServer: createServer2 } = await import("./server-BWI5JE4B.js");
1147
+ const { createServer: createServer2 } = await import("./server-55XTEGMF.js");
1061
1148
  return createServer2({
1062
1149
  platform: config.platform,
1063
1150
  createDriver: config.createDriver,