agentxjs 2.5.0 → 2.6.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-7GW66EMD.js";
4
+ } from "./chunk-JTHR3AK6.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { createAgentXRuntime } from "@agentxjs/core/runtime";
@@ -740,7 +740,7 @@ var Presentation = class {
740
740
  this.state = addUserConversation(this.state, content);
741
741
  this.notify();
742
742
  try {
743
- await this.agentx.instance.session.send(this.agentId, content);
743
+ await this.agentx.runtime.session.send(this.agentId, content);
744
744
  } catch (error) {
745
745
  this.notifyError(error instanceof Error ? error : new Error(String(error)));
746
746
  }
@@ -750,7 +750,7 @@ var Presentation = class {
750
750
  */
751
751
  async interrupt() {
752
752
  try {
753
- await this.agentx.instance.session.interrupt(this.agentId);
753
+ await this.agentx.runtime.session.interrupt(this.agentId);
754
754
  } catch (error) {
755
755
  this.notifyError(error instanceof Error ? error : new Error(String(error)));
756
756
  }
@@ -819,6 +819,103 @@ function createPresentations(agentx, imageNs) {
819
819
  };
820
820
  }
821
821
 
822
+ // src/namespaces/prototypes.ts
823
+ function createLocalPrototypes(platform) {
824
+ return {
825
+ async create(params) {
826
+ const repo = platform.prototypeRepository;
827
+ if (!repo) {
828
+ throw new Error("Prototype repository not available");
829
+ }
830
+ const now = Date.now();
831
+ const random = Math.random().toString(36).slice(2, 8);
832
+ const record = {
833
+ prototypeId: `proto_${now}_${random}`,
834
+ containerId: params.containerId,
835
+ name: params.name,
836
+ description: params.description,
837
+ contextId: params.contextId,
838
+ embody: params.embody,
839
+ customData: params.customData,
840
+ createdAt: now,
841
+ updatedAt: now
842
+ };
843
+ await repo.savePrototype(record);
844
+ return { record, requestId: "" };
845
+ },
846
+ async get(prototypeId) {
847
+ const repo = platform.prototypeRepository;
848
+ if (!repo) {
849
+ throw new Error("Prototype repository not available");
850
+ }
851
+ const record = await repo.findPrototypeById(prototypeId);
852
+ return { record, requestId: "" };
853
+ },
854
+ async list(containerId) {
855
+ const repo = platform.prototypeRepository;
856
+ if (!repo) {
857
+ throw new Error("Prototype repository not available");
858
+ }
859
+ const records = containerId ? await repo.findPrototypesByContainerId(containerId) : await repo.findAllPrototypes();
860
+ return { records, requestId: "" };
861
+ },
862
+ async update(prototypeId, updates) {
863
+ const repo = platform.prototypeRepository;
864
+ if (!repo) {
865
+ throw new Error("Prototype repository not available");
866
+ }
867
+ const existing = await repo.findPrototypeById(prototypeId);
868
+ if (!existing) {
869
+ throw new Error(`Prototype not found: ${prototypeId}`);
870
+ }
871
+ const { embody: embodyUpdates, ...otherUpdates } = updates;
872
+ const updatedRecord = {
873
+ ...existing,
874
+ ...otherUpdates,
875
+ embody: embodyUpdates ? { ...existing.embody, ...embodyUpdates } : existing.embody,
876
+ updatedAt: Date.now()
877
+ };
878
+ await repo.savePrototype(updatedRecord);
879
+ return { record: updatedRecord, requestId: "" };
880
+ },
881
+ async delete(prototypeId) {
882
+ const repo = platform.prototypeRepository;
883
+ if (!repo) {
884
+ throw new Error("Prototype repository not available");
885
+ }
886
+ await repo.deletePrototype(prototypeId);
887
+ return { requestId: "" };
888
+ }
889
+ };
890
+ }
891
+ function createRemotePrototypes(rpcClient) {
892
+ return {
893
+ async create(params) {
894
+ const result = await rpcClient.call("prototype.create", params);
895
+ return { ...result, requestId: "" };
896
+ },
897
+ async get(prototypeId) {
898
+ const result = await rpcClient.call("prototype.get", { prototypeId });
899
+ return { ...result, requestId: "" };
900
+ },
901
+ async list(containerId) {
902
+ const result = await rpcClient.call("prototype.list", { containerId });
903
+ return { ...result, requestId: "" };
904
+ },
905
+ async update(prototypeId, updates) {
906
+ const result = await rpcClient.call("prototype.update", {
907
+ prototypeId,
908
+ updates
909
+ });
910
+ return { ...result, requestId: "" };
911
+ },
912
+ async delete(prototypeId) {
913
+ const result = await rpcClient.call("prototype.delete", { prototypeId });
914
+ return { ...result, requestId: "" };
915
+ }
916
+ };
917
+ }
918
+
822
919
  // src/namespaces/sessions.ts
823
920
  function createLocalSessions(runtime) {
824
921
  return {
@@ -864,22 +961,27 @@ function createRemoteSessions(rpcClient) {
864
961
  // src/LocalClient.ts
865
962
  var logger = createLogger("agentx/LocalClient");
866
963
  var LocalClient = class {
867
- runtime;
964
+ _runtime;
868
965
  commandHandler = null;
869
966
  isDisposed = false;
870
- instance;
967
+ chat;
968
+ runtime;
871
969
  provider;
872
- constructor(runtime) {
873
- this.runtime = runtime;
874
- const platform = runtime.platform;
970
+ prototype;
971
+ constructor(agentxRuntime) {
972
+ this._runtime = agentxRuntime;
973
+ const platform = agentxRuntime.platform;
875
974
  const container = createLocalContainers(platform);
876
975
  const image = createLocalImages(platform);
877
- const agent = createLocalAgents(runtime);
878
- const session = createLocalSessions(runtime);
976
+ const agent = createLocalAgents(agentxRuntime);
977
+ const session = createLocalSessions(agentxRuntime);
879
978
  const llm = createLocalLLM(platform);
979
+ const prototype = createLocalPrototypes(platform);
880
980
  const present = createPresentations(this, image);
881
- this.instance = { container, image, agent, session, present, llm };
981
+ this.runtime = { container, image, agent, session, present, llm, prototype };
882
982
  this.provider = llm;
983
+ this.prototype = prototype;
984
+ this.chat = this.createChatNamespace();
883
985
  logger.info("LocalClient initialized");
884
986
  }
885
987
  // ==================== Properties ====================
@@ -887,59 +989,27 @@ var LocalClient = class {
887
989
  return !this.isDisposed;
888
990
  }
889
991
  get events() {
890
- return this.runtime.platform.eventBus;
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
- );
992
+ return this._runtime.platform.eventBus;
923
993
  }
924
994
  // ==================== Event Subscription ====================
925
995
  on(type, handler) {
926
- return this.runtime.platform.eventBus.on(type, handler);
996
+ return this._runtime.platform.eventBus.on(type, handler);
927
997
  }
928
998
  onAny(handler) {
929
- return this.runtime.platform.eventBus.onAny(handler);
999
+ return this._runtime.platform.eventBus.onAny(handler);
930
1000
  }
931
1001
  subscribe(_sessionId) {
932
1002
  }
933
1003
  // ==================== Error Handling ====================
934
1004
  onError(handler) {
935
- return this.runtime.platform.eventBus.on("agentx_error", (event) => {
1005
+ return this._runtime.platform.eventBus.on("agentx_error", (event) => {
936
1006
  handler(event.data);
937
1007
  });
938
1008
  }
939
1009
  // ==================== RPC ====================
940
1010
  async rpc(method, params) {
941
1011
  if (!this.commandHandler) {
942
- this.commandHandler = new CommandHandler(this.runtime);
1012
+ this.commandHandler = new CommandHandler(this._runtime);
943
1013
  }
944
1014
  const result = await this.commandHandler.handle(method, params);
945
1015
  if (result.success) {
@@ -947,12 +1017,66 @@ var LocalClient = class {
947
1017
  }
948
1018
  throw new Error(result.message);
949
1019
  }
1020
+ // ==================== Private ====================
1021
+ createChatNamespace() {
1022
+ const instance = this.runtime;
1023
+ return {
1024
+ async create(params) {
1025
+ const containerId = "default";
1026
+ let mergedParams = { ...params };
1027
+ if (params.prototypeId) {
1028
+ const protoRes = await instance.prototype.get(params.prototypeId);
1029
+ if (protoRes.record) {
1030
+ const proto = protoRes.record;
1031
+ mergedParams = {
1032
+ name: proto.name,
1033
+ description: proto.description,
1034
+ contextId: proto.contextId,
1035
+ embody: proto.embody,
1036
+ customData: proto.customData,
1037
+ ...params
1038
+ // inline params override prototype
1039
+ };
1040
+ }
1041
+ }
1042
+ const { prototypeId: _pid, ...imageParams } = mergedParams;
1043
+ const imgRes = await instance.image.create({ containerId, ...imageParams });
1044
+ const agentRes = await instance.agent.create({ imageId: imgRes.record.imageId });
1045
+ return new AgentHandleImpl(
1046
+ {
1047
+ agentId: agentRes.agentId,
1048
+ imageId: agentRes.imageId,
1049
+ containerId: agentRes.containerId,
1050
+ sessionId: agentRes.sessionId
1051
+ },
1052
+ instance
1053
+ );
1054
+ },
1055
+ async list() {
1056
+ return instance.image.list();
1057
+ },
1058
+ async get(id) {
1059
+ const res = await instance.image.get(id);
1060
+ if (!res.record) return null;
1061
+ const r = res.record;
1062
+ return new AgentHandleImpl(
1063
+ {
1064
+ agentId: r.imageId,
1065
+ imageId: r.imageId,
1066
+ containerId: r.containerId,
1067
+ sessionId: r.sessionId
1068
+ },
1069
+ instance
1070
+ );
1071
+ }
1072
+ };
1073
+ }
950
1074
  // ==================== Lifecycle ====================
951
1075
  async disconnect() {
952
1076
  }
953
1077
  async dispose() {
954
1078
  if (this.isDisposed) return;
955
- await this.runtime.shutdown();
1079
+ await this._runtime.shutdown();
956
1080
  this.isDisposed = true;
957
1081
  logger.info("LocalClient disposed");
958
1082
  }
@@ -967,8 +1091,10 @@ var RemoteClient = class {
967
1091
  config;
968
1092
  eventBus;
969
1093
  rpcClient;
970
- instance;
1094
+ chat;
1095
+ runtime;
971
1096
  provider;
1097
+ prototype;
972
1098
  constructor(config) {
973
1099
  this.config = config;
974
1100
  this.eventBus = new EventBusImpl();
@@ -989,9 +1115,12 @@ var RemoteClient = class {
989
1115
  const agent = createRemoteAgents(this.rpcClient);
990
1116
  const session = createRemoteSessions(this.rpcClient);
991
1117
  const llm = createRemoteLLM(this.rpcClient);
1118
+ const prototype = createRemotePrototypes(this.rpcClient);
992
1119
  const present = createPresentations(this, image);
993
- this.instance = { container, image, agent, session, present, llm };
1120
+ this.runtime = { container, image, agent, session, present, llm, prototype };
994
1121
  this.provider = llm;
1122
+ this.prototype = prototype;
1123
+ this.chat = this.createChatNamespace();
995
1124
  }
996
1125
  // ==================== Properties ====================
997
1126
  get connected() {
@@ -1000,38 +1129,6 @@ var RemoteClient = class {
1000
1129
  get events() {
1001
1130
  return this.eventBus;
1002
1131
  }
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
- }
1035
1132
  // ==================== Connection ====================
1036
1133
  async connect() {
1037
1134
  await this.rpcClient.connect();
@@ -1067,6 +1164,60 @@ var RemoteClient = class {
1067
1164
  async rpc(method, params) {
1068
1165
  return this.rpcClient.call(method, params);
1069
1166
  }
1167
+ // ==================== Private ====================
1168
+ createChatNamespace() {
1169
+ const instance = this.runtime;
1170
+ return {
1171
+ async create(params) {
1172
+ const containerId = "default";
1173
+ let mergedParams = { ...params };
1174
+ if (params.prototypeId) {
1175
+ const protoRes = await instance.prototype.get(params.prototypeId);
1176
+ if (protoRes.record) {
1177
+ const proto = protoRes.record;
1178
+ mergedParams = {
1179
+ name: proto.name,
1180
+ description: proto.description,
1181
+ contextId: proto.contextId,
1182
+ embody: proto.embody,
1183
+ customData: proto.customData,
1184
+ ...params
1185
+ // inline params override prototype
1186
+ };
1187
+ }
1188
+ }
1189
+ const { prototypeId: _pid, ...imageParams } = mergedParams;
1190
+ const imgRes = await instance.image.create({ containerId, ...imageParams });
1191
+ const agentRes = await instance.agent.create({ imageId: imgRes.record.imageId });
1192
+ return new AgentHandleImpl(
1193
+ {
1194
+ agentId: agentRes.agentId,
1195
+ imageId: agentRes.imageId,
1196
+ containerId: agentRes.containerId,
1197
+ sessionId: agentRes.sessionId
1198
+ },
1199
+ instance
1200
+ );
1201
+ },
1202
+ async list() {
1203
+ return instance.image.list();
1204
+ },
1205
+ async get(id) {
1206
+ const res = await instance.image.get(id);
1207
+ if (!res.record) return null;
1208
+ const r = res.record;
1209
+ return new AgentHandleImpl(
1210
+ {
1211
+ agentId: r.imageId,
1212
+ imageId: r.imageId,
1213
+ containerId: r.containerId,
1214
+ sessionId: r.sessionId
1215
+ },
1216
+ instance
1217
+ );
1218
+ }
1219
+ };
1220
+ }
1070
1221
  };
1071
1222
 
1072
1223
  // src/index.ts
@@ -1094,16 +1245,18 @@ function createAgentX(config) {
1094
1245
  get events() {
1095
1246
  return getLocalClient().events;
1096
1247
  },
1097
- get instance() {
1098
- return getLocalClient().instance;
1248
+ get runtime() {
1249
+ return getLocalClient().runtime;
1099
1250
  },
1100
1251
  get provider() {
1101
1252
  return getLocalClient().provider;
1102
1253
  },
1103
- // Top-level Agent API
1104
- create: (params) => getLocalClient().create(params),
1105
- list: () => getLocalClient().list(),
1106
- get: (agentId) => getLocalClient().get(agentId),
1254
+ get chat() {
1255
+ return getLocalClient().chat;
1256
+ },
1257
+ get prototype() {
1258
+ return getLocalClient().prototype;
1259
+ },
1107
1260
  on(type, handler) {
1108
1261
  return getLocalClient().on(type, handler);
1109
1262
  },
@@ -1144,7 +1297,7 @@ function createAgentX(config) {
1144
1297
  "serve() requires platform.channelServer. Ensure your platform supports server mode."
1145
1298
  );
1146
1299
  }
1147
- const { createServer: createServer2 } = await import("./server-55XTEGMF.js");
1300
+ const { createServer: createServer2 } = await import("./server-UCQISBKH.js");
1148
1301
  return createServer2({
1149
1302
  platform: config.platform,
1150
1303
  createDriver: config.createDriver,