agentxjs 2.6.0 → 2.7.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-JTHR3AK6.js";
4
+ } from "./chunk-NPRCFKO5.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { createAgentXRuntime } from "@agentxjs/core/runtime";
@@ -11,47 +11,47 @@ import { createLogger } from "commonxjs/logger";
11
11
 
12
12
  // src/AgentHandle.ts
13
13
  var AgentHandleImpl = class {
14
- agentId;
14
+ instanceId;
15
15
  imageId;
16
16
  containerId;
17
17
  sessionId;
18
18
  ns;
19
19
  constructor(ids, ns) {
20
- this.agentId = ids.agentId;
20
+ this.instanceId = ids.instanceId;
21
21
  this.imageId = ids.imageId;
22
22
  this.containerId = ids.containerId;
23
23
  this.sessionId = ids.sessionId;
24
24
  this.ns = ns;
25
25
  }
26
26
  async send(content) {
27
- return this.ns.session.send(this.agentId, content);
27
+ return this.ns.session.send(this.instanceId, content);
28
28
  }
29
29
  async interrupt() {
30
- return this.ns.session.interrupt(this.agentId);
30
+ return this.ns.session.interrupt(this.instanceId);
31
31
  }
32
32
  async history() {
33
33
  return this.ns.image.getMessages(this.imageId);
34
34
  }
35
35
  async present(options) {
36
- return this.ns.present.create(this.agentId, options);
36
+ return this.ns.present.create(this.instanceId, options);
37
37
  }
38
38
  async update(updates) {
39
39
  await this.ns.image.update(this.imageId, updates);
40
40
  }
41
41
  async delete() {
42
- await this.ns.agent.destroy(this.agentId);
42
+ await this.ns.instance.destroy(this.instanceId);
43
43
  await this.ns.image.delete(this.imageId);
44
44
  }
45
45
  };
46
46
 
47
47
  // src/namespaces/agents.ts
48
- function createLocalAgents(runtime) {
48
+ function createLocalInstances(runtime) {
49
49
  return {
50
50
  async create(params) {
51
51
  const existingAgent = runtime.getAgents().find((a) => a.imageId === params.imageId && a.lifecycle === "running");
52
52
  if (existingAgent) {
53
53
  return {
54
- agentId: existingAgent.agentId,
54
+ instanceId: existingAgent.instanceId,
55
55
  imageId: existingAgent.imageId,
56
56
  containerId: existingAgent.containerId,
57
57
  sessionId: existingAgent.sessionId,
@@ -60,21 +60,21 @@ function createLocalAgents(runtime) {
60
60
  }
61
61
  const agent = await runtime.createAgent({
62
62
  imageId: params.imageId,
63
- agentId: params.agentId
63
+ instanceId: params.instanceId
64
64
  });
65
65
  return {
66
- agentId: agent.agentId,
66
+ instanceId: agent.instanceId,
67
67
  imageId: agent.imageId,
68
68
  containerId: agent.containerId,
69
69
  sessionId: agent.sessionId,
70
70
  requestId: ""
71
71
  };
72
72
  },
73
- async get(agentId) {
74
- const agent = runtime.getAgent(agentId);
73
+ async get(instanceId) {
74
+ const agent = runtime.getAgent(instanceId);
75
75
  return {
76
76
  agent: agent ? {
77
- agentId: agent.agentId,
77
+ instanceId: agent.instanceId,
78
78
  imageId: agent.imageId,
79
79
  containerId: agent.containerId,
80
80
  sessionId: agent.sessionId,
@@ -88,7 +88,7 @@ function createLocalAgents(runtime) {
88
88
  const agents = containerId ? runtime.getAgentsByContainer(containerId) : runtime.getAgents();
89
89
  return {
90
90
  agents: agents.map((a) => ({
91
- agentId: a.agentId,
91
+ instanceId: a.instanceId,
92
92
  imageId: a.imageId,
93
93
  containerId: a.containerId,
94
94
  sessionId: a.sessionId,
@@ -97,34 +97,34 @@ function createLocalAgents(runtime) {
97
97
  requestId: ""
98
98
  };
99
99
  },
100
- async destroy(agentId) {
101
- const agent = runtime.getAgent(agentId);
100
+ async destroy(instanceId) {
101
+ const agent = runtime.getAgent(instanceId);
102
102
  if (agent) {
103
- await runtime.destroyAgent(agentId);
103
+ await runtime.destroyAgent(instanceId);
104
104
  }
105
105
  return { requestId: "" };
106
106
  }
107
107
  };
108
108
  }
109
- function createRemoteAgents(rpcClient) {
109
+ function createRemoteInstances(rpcClient) {
110
110
  return {
111
111
  async create(params) {
112
112
  const result = await rpcClient.call("image.run", {
113
113
  imageId: params.imageId,
114
- agentId: params.agentId
114
+ instanceId: params.instanceId
115
115
  });
116
116
  return { ...result, requestId: "" };
117
117
  },
118
- async get(agentId) {
119
- const result = await rpcClient.call("agent.get", { agentId });
118
+ async get(instanceId) {
119
+ const result = await rpcClient.call("instance.get", { instanceId });
120
120
  return { ...result, requestId: "" };
121
121
  },
122
122
  async list(containerId) {
123
- const result = await rpcClient.call("agent.list", { containerId });
123
+ const result = await rpcClient.call("instance.list", { containerId });
124
124
  return { ...result, requestId: "" };
125
125
  },
126
- async destroy(agentId) {
127
- const result = await rpcClient.call("agent.destroy", { agentId });
126
+ async destroy(instanceId) {
127
+ const result = await rpcClient.call("instance.destroy", { instanceId });
128
128
  return { ...result, requestId: "" };
129
129
  }
130
130
  };
@@ -691,14 +691,14 @@ function messagesToConversations(messages) {
691
691
  // src/presentation/Presentation.ts
692
692
  var Presentation = class {
693
693
  agentx;
694
- agentId;
694
+ instanceId;
695
695
  state;
696
696
  updateHandlers = /* @__PURE__ */ new Set();
697
697
  errorHandlers = /* @__PURE__ */ new Set();
698
698
  eventUnsubscribe = null;
699
- constructor(agentx, agentId, options, initialConversations) {
699
+ constructor(agentx, instanceId, options, initialConversations) {
700
700
  this.agentx = agentx;
701
- this.agentId = agentId;
701
+ this.instanceId = instanceId;
702
702
  this.state = initialConversations?.length ? { ...initialPresentationState, conversations: initialConversations } : createInitialState();
703
703
  if (options?.onUpdate) {
704
704
  this.updateHandlers.add(options.onUpdate);
@@ -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.runtime.session.send(this.agentId, content);
743
+ await this.agentx.runtime.session.send(this.instanceId, 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.runtime.session.interrupt(this.agentId);
753
+ await this.agentx.runtime.session.interrupt(this.instanceId);
754
754
  } catch (error) {
755
755
  this.notifyError(error instanceof Error ? error : new Error(String(error)));
756
756
  }
@@ -777,8 +777,8 @@ var Presentation = class {
777
777
  subscribeToEvents() {
778
778
  this.eventUnsubscribe = this.agentx.onAny((event) => {
779
779
  const eventWithContext = event;
780
- const eventAgentId = eventWithContext.context?.agentId;
781
- if (eventAgentId && eventAgentId !== this.agentId) {
780
+ const eventAgentId = eventWithContext.context?.instanceId;
781
+ if (eventAgentId && eventAgentId !== this.instanceId) {
782
782
  return;
783
783
  }
784
784
  const newState = presentationReducer(this.state, event);
@@ -809,12 +809,12 @@ var Presentation = class {
809
809
  };
810
810
 
811
811
  // src/namespaces/presentations.ts
812
- function createPresentations(agentx, imageNs) {
812
+ function createPresentations(agentx, sessionNs) {
813
813
  return {
814
- async create(agentId, options) {
815
- const messages = await imageNs.getMessages(agentId);
814
+ async create(instanceId, options) {
815
+ const messages = await sessionNs.getMessages(instanceId);
816
816
  const conversations = messagesToConversations(messages);
817
- return new Presentation(agentx, agentId, options, conversations);
817
+ return new Presentation(agentx, instanceId, options, conversations);
818
818
  }
819
819
  };
820
820
  }
@@ -919,16 +919,16 @@ function createRemotePrototypes(rpcClient) {
919
919
  // src/namespaces/sessions.ts
920
920
  function createLocalSessions(runtime) {
921
921
  return {
922
- async send(agentId, content) {
923
- await runtime.receive(agentId, content);
924
- return { agentId, requestId: "" };
922
+ async send(instanceId, content) {
923
+ await runtime.receive(instanceId, content);
924
+ return { instanceId, requestId: "" };
925
925
  },
926
- async interrupt(agentId) {
927
- runtime.interrupt(agentId);
926
+ async interrupt(instanceId) {
927
+ runtime.interrupt(instanceId);
928
928
  return { requestId: "" };
929
929
  },
930
- async getMessages(agentId) {
931
- const agent = runtime.getAgent(agentId);
930
+ async getMessages(instanceId) {
931
+ const agent = runtime.getAgent(instanceId);
932
932
  if (!agent) return [];
933
933
  return runtime.platform.sessionRepository.getMessages(agent.sessionId);
934
934
  }
@@ -936,19 +936,21 @@ function createLocalSessions(runtime) {
936
936
  }
937
937
  function createRemoteSessions(rpcClient) {
938
938
  return {
939
- async send(agentId, content) {
939
+ async send(instanceId, content) {
940
940
  const result = await rpcClient.call("message.send", {
941
- agentId,
941
+ instanceId,
942
942
  content
943
943
  });
944
944
  return { ...result, requestId: "" };
945
945
  },
946
- async interrupt(agentId) {
947
- const result = await rpcClient.call("agent.interrupt", { agentId });
946
+ async interrupt(instanceId) {
947
+ const result = await rpcClient.call("instance.interrupt", { instanceId });
948
948
  return { ...result, requestId: "" };
949
949
  },
950
- async getMessages(agentId) {
951
- const agentRes = await rpcClient.call("agent.get", { agentId });
950
+ async getMessages(instanceId) {
951
+ const agentRes = await rpcClient.call("instance.get", {
952
+ instanceId
953
+ });
952
954
  if (!agentRes.agent) return [];
953
955
  const msgRes = await rpcClient.call("image.messages", {
954
956
  imageId: agentRes.agent.imageId
@@ -973,12 +975,12 @@ var LocalClient = class {
973
975
  const platform = agentxRuntime.platform;
974
976
  const container = createLocalContainers(platform);
975
977
  const image = createLocalImages(platform);
976
- const agent = createLocalAgents(agentxRuntime);
978
+ const instance = createLocalInstances(agentxRuntime);
977
979
  const session = createLocalSessions(agentxRuntime);
978
980
  const llm = createLocalLLM(platform);
979
981
  const prototype = createLocalPrototypes(platform);
980
- const present = createPresentations(this, image);
981
- this.runtime = { container, image, agent, session, present, llm, prototype };
982
+ const present = createPresentations(this, session);
983
+ this.runtime = { container, image, instance, session, present, llm, prototype };
982
984
  this.provider = llm;
983
985
  this.prototype = prototype;
984
986
  this.chat = this.createChatNamespace();
@@ -1019,13 +1021,13 @@ var LocalClient = class {
1019
1021
  }
1020
1022
  // ==================== Private ====================
1021
1023
  createChatNamespace() {
1022
- const instance = this.runtime;
1024
+ const rt = this.runtime;
1023
1025
  return {
1024
1026
  async create(params) {
1025
1027
  const containerId = "default";
1026
1028
  let mergedParams = { ...params };
1027
1029
  if (params.prototypeId) {
1028
- const protoRes = await instance.prototype.get(params.prototypeId);
1030
+ const protoRes = await rt.prototype.get(params.prototypeId);
1029
1031
  if (protoRes.record) {
1030
1032
  const proto = protoRes.record;
1031
1033
  mergedParams = {
@@ -1040,33 +1042,34 @@ var LocalClient = class {
1040
1042
  }
1041
1043
  }
1042
1044
  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
+ const imgRes = await rt.image.create({ containerId, ...imageParams });
1046
+ const instRes = await rt.instance.create({ imageId: imgRes.record.imageId });
1045
1047
  return new AgentHandleImpl(
1046
1048
  {
1047
- agentId: agentRes.agentId,
1048
- imageId: agentRes.imageId,
1049
- containerId: agentRes.containerId,
1050
- sessionId: agentRes.sessionId
1049
+ instanceId: instRes.instanceId,
1050
+ imageId: instRes.imageId,
1051
+ containerId: instRes.containerId,
1052
+ sessionId: instRes.sessionId
1051
1053
  },
1052
- instance
1054
+ rt
1053
1055
  );
1054
1056
  },
1055
1057
  async list() {
1056
- return instance.image.list();
1058
+ return rt.image.list();
1057
1059
  },
1058
1060
  async get(id) {
1059
- const res = await instance.image.get(id);
1061
+ const res = await rt.image.get(id);
1060
1062
  if (!res.record) return null;
1061
1063
  const r = res.record;
1064
+ const instRes = await rt.instance.create({ imageId: r.imageId });
1062
1065
  return new AgentHandleImpl(
1063
1066
  {
1064
- agentId: r.imageId,
1065
- imageId: r.imageId,
1066
- containerId: r.containerId,
1067
- sessionId: r.sessionId
1067
+ instanceId: instRes.instanceId,
1068
+ imageId: instRes.imageId,
1069
+ containerId: instRes.containerId,
1070
+ sessionId: instRes.sessionId
1068
1071
  },
1069
- instance
1072
+ rt
1070
1073
  );
1071
1074
  }
1072
1075
  };
@@ -1112,12 +1115,12 @@ var RemoteClient = class {
1112
1115
  });
1113
1116
  const container = createRemoteContainers(this.rpcClient);
1114
1117
  const image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
1115
- const agent = createRemoteAgents(this.rpcClient);
1118
+ const instance = createRemoteInstances(this.rpcClient);
1116
1119
  const session = createRemoteSessions(this.rpcClient);
1117
1120
  const llm = createRemoteLLM(this.rpcClient);
1118
1121
  const prototype = createRemotePrototypes(this.rpcClient);
1119
- const present = createPresentations(this, image);
1120
- this.runtime = { container, image, agent, session, present, llm, prototype };
1122
+ const present = createPresentations(this, session);
1123
+ this.runtime = { container, image, instance, session, present, llm, prototype };
1121
1124
  this.provider = llm;
1122
1125
  this.prototype = prototype;
1123
1126
  this.chat = this.createChatNamespace();
@@ -1166,13 +1169,13 @@ var RemoteClient = class {
1166
1169
  }
1167
1170
  // ==================== Private ====================
1168
1171
  createChatNamespace() {
1169
- const instance = this.runtime;
1172
+ const rt = this.runtime;
1170
1173
  return {
1171
1174
  async create(params) {
1172
1175
  const containerId = "default";
1173
1176
  let mergedParams = { ...params };
1174
1177
  if (params.prototypeId) {
1175
- const protoRes = await instance.prototype.get(params.prototypeId);
1178
+ const protoRes = await rt.prototype.get(params.prototypeId);
1176
1179
  if (protoRes.record) {
1177
1180
  const proto = protoRes.record;
1178
1181
  mergedParams = {
@@ -1187,33 +1190,34 @@ var RemoteClient = class {
1187
1190
  }
1188
1191
  }
1189
1192
  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 });
1193
+ const imgRes = await rt.image.create({ containerId, ...imageParams });
1194
+ const instRes = await rt.instance.create({ imageId: imgRes.record.imageId });
1192
1195
  return new AgentHandleImpl(
1193
1196
  {
1194
- agentId: agentRes.agentId,
1195
- imageId: agentRes.imageId,
1196
- containerId: agentRes.containerId,
1197
- sessionId: agentRes.sessionId
1197
+ instanceId: instRes.instanceId,
1198
+ imageId: instRes.imageId,
1199
+ containerId: instRes.containerId,
1200
+ sessionId: instRes.sessionId
1198
1201
  },
1199
- instance
1202
+ rt
1200
1203
  );
1201
1204
  },
1202
1205
  async list() {
1203
- return instance.image.list();
1206
+ return rt.image.list();
1204
1207
  },
1205
1208
  async get(id) {
1206
- const res = await instance.image.get(id);
1209
+ const res = await rt.image.get(id);
1207
1210
  if (!res.record) return null;
1208
1211
  const r = res.record;
1212
+ const instRes = await rt.instance.create({ imageId: r.imageId });
1209
1213
  return new AgentHandleImpl(
1210
1214
  {
1211
- agentId: r.imageId,
1212
- imageId: r.imageId,
1213
- containerId: r.containerId,
1214
- sessionId: r.sessionId
1215
+ instanceId: instRes.instanceId,
1216
+ imageId: instRes.imageId,
1217
+ containerId: instRes.containerId,
1218
+ sessionId: instRes.sessionId
1215
1219
  },
1216
- instance
1220
+ rt
1217
1221
  );
1218
1222
  }
1219
1223
  };
@@ -1297,7 +1301,7 @@ function createAgentX(config) {
1297
1301
  "serve() requires platform.channelServer. Ensure your platform supports server mode."
1298
1302
  );
1299
1303
  }
1300
- const { createServer: createServer2 } = await import("./server-UCQISBKH.js");
1304
+ const { createServer: createServer2 } = await import("./server-3BCYHXYA.js");
1301
1305
  return createServer2({
1302
1306
  platform: config.platform,
1303
1307
  createDriver: config.createDriver,