agentxjs 2.5.0 → 2.6.1
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/README.md +22 -12
- package/dist/{chunk-7GW66EMD.js → chunk-JTHR3AK6.js} +82 -1
- package/dist/chunk-JTHR3AK6.js.map +1 -0
- package/dist/index.d.ts +112 -24
- package/dist/index.js +245 -90
- package/dist/index.js.map +1 -1
- package/dist/server-UCQISBKH.js +7 -0
- package/package.json +3 -3
- package/src/AgentHandle.ts +3 -3
- package/src/CommandHandler.ts +117 -0
- package/src/LocalClient.ts +80 -60
- package/src/RemoteClient.ts +68 -48
- package/src/index.ts +17 -8
- package/src/namespaces/prototypes.ts +136 -0
- package/src/presentation/Presentation.ts +2 -2
- package/src/types.ts +130 -23
- package/dist/chunk-7GW66EMD.js.map +0 -1
- package/dist/server-55XTEGMF.js +0 -7
- /package/dist/{server-55XTEGMF.js.map → server-UCQISBKH.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommandHandler,
|
|
3
3
|
createServer
|
|
4
|
-
} from "./chunk-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
964
|
+
_runtime;
|
|
868
965
|
commandHandler = null;
|
|
869
966
|
isDisposed = false;
|
|
870
|
-
|
|
967
|
+
chat;
|
|
968
|
+
runtime;
|
|
871
969
|
provider;
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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(
|
|
878
|
-
const session = createLocalSessions(
|
|
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.
|
|
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.
|
|
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.
|
|
996
|
+
return this._runtime.platform.eventBus.on(type, handler);
|
|
927
997
|
}
|
|
928
998
|
onAny(handler) {
|
|
929
|
-
return this.
|
|
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.
|
|
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.
|
|
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,67 @@ 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
|
+
const agentRes = await instance.agent.create({ imageId: r.imageId });
|
|
1063
|
+
return new AgentHandleImpl(
|
|
1064
|
+
{
|
|
1065
|
+
agentId: agentRes.agentId,
|
|
1066
|
+
imageId: agentRes.imageId,
|
|
1067
|
+
containerId: agentRes.containerId,
|
|
1068
|
+
sessionId: agentRes.sessionId
|
|
1069
|
+
},
|
|
1070
|
+
instance
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
950
1075
|
// ==================== Lifecycle ====================
|
|
951
1076
|
async disconnect() {
|
|
952
1077
|
}
|
|
953
1078
|
async dispose() {
|
|
954
1079
|
if (this.isDisposed) return;
|
|
955
|
-
await this.
|
|
1080
|
+
await this._runtime.shutdown();
|
|
956
1081
|
this.isDisposed = true;
|
|
957
1082
|
logger.info("LocalClient disposed");
|
|
958
1083
|
}
|
|
@@ -967,8 +1092,10 @@ var RemoteClient = class {
|
|
|
967
1092
|
config;
|
|
968
1093
|
eventBus;
|
|
969
1094
|
rpcClient;
|
|
970
|
-
|
|
1095
|
+
chat;
|
|
1096
|
+
runtime;
|
|
971
1097
|
provider;
|
|
1098
|
+
prototype;
|
|
972
1099
|
constructor(config) {
|
|
973
1100
|
this.config = config;
|
|
974
1101
|
this.eventBus = new EventBusImpl();
|
|
@@ -989,9 +1116,12 @@ var RemoteClient = class {
|
|
|
989
1116
|
const agent = createRemoteAgents(this.rpcClient);
|
|
990
1117
|
const session = createRemoteSessions(this.rpcClient);
|
|
991
1118
|
const llm = createRemoteLLM(this.rpcClient);
|
|
1119
|
+
const prototype = createRemotePrototypes(this.rpcClient);
|
|
992
1120
|
const present = createPresentations(this, image);
|
|
993
|
-
this.
|
|
1121
|
+
this.runtime = { container, image, agent, session, present, llm, prototype };
|
|
994
1122
|
this.provider = llm;
|
|
1123
|
+
this.prototype = prototype;
|
|
1124
|
+
this.chat = this.createChatNamespace();
|
|
995
1125
|
}
|
|
996
1126
|
// ==================== Properties ====================
|
|
997
1127
|
get connected() {
|
|
@@ -1000,38 +1130,6 @@ var RemoteClient = class {
|
|
|
1000
1130
|
get events() {
|
|
1001
1131
|
return this.eventBus;
|
|
1002
1132
|
}
|
|
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
1133
|
// ==================== Connection ====================
|
|
1036
1134
|
async connect() {
|
|
1037
1135
|
await this.rpcClient.connect();
|
|
@@ -1067,6 +1165,61 @@ var RemoteClient = class {
|
|
|
1067
1165
|
async rpc(method, params) {
|
|
1068
1166
|
return this.rpcClient.call(method, params);
|
|
1069
1167
|
}
|
|
1168
|
+
// ==================== Private ====================
|
|
1169
|
+
createChatNamespace() {
|
|
1170
|
+
const instance = this.runtime;
|
|
1171
|
+
return {
|
|
1172
|
+
async create(params) {
|
|
1173
|
+
const containerId = "default";
|
|
1174
|
+
let mergedParams = { ...params };
|
|
1175
|
+
if (params.prototypeId) {
|
|
1176
|
+
const protoRes = await instance.prototype.get(params.prototypeId);
|
|
1177
|
+
if (protoRes.record) {
|
|
1178
|
+
const proto = protoRes.record;
|
|
1179
|
+
mergedParams = {
|
|
1180
|
+
name: proto.name,
|
|
1181
|
+
description: proto.description,
|
|
1182
|
+
contextId: proto.contextId,
|
|
1183
|
+
embody: proto.embody,
|
|
1184
|
+
customData: proto.customData,
|
|
1185
|
+
...params
|
|
1186
|
+
// inline params override prototype
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
const { prototypeId: _pid, ...imageParams } = mergedParams;
|
|
1191
|
+
const imgRes = await instance.image.create({ containerId, ...imageParams });
|
|
1192
|
+
const agentRes = await instance.agent.create({ imageId: imgRes.record.imageId });
|
|
1193
|
+
return new AgentHandleImpl(
|
|
1194
|
+
{
|
|
1195
|
+
agentId: agentRes.agentId,
|
|
1196
|
+
imageId: agentRes.imageId,
|
|
1197
|
+
containerId: agentRes.containerId,
|
|
1198
|
+
sessionId: agentRes.sessionId
|
|
1199
|
+
},
|
|
1200
|
+
instance
|
|
1201
|
+
);
|
|
1202
|
+
},
|
|
1203
|
+
async list() {
|
|
1204
|
+
return instance.image.list();
|
|
1205
|
+
},
|
|
1206
|
+
async get(id) {
|
|
1207
|
+
const res = await instance.image.get(id);
|
|
1208
|
+
if (!res.record) return null;
|
|
1209
|
+
const r = res.record;
|
|
1210
|
+
const agentRes = await instance.agent.create({ imageId: r.imageId });
|
|
1211
|
+
return new AgentHandleImpl(
|
|
1212
|
+
{
|
|
1213
|
+
agentId: agentRes.agentId,
|
|
1214
|
+
imageId: agentRes.imageId,
|
|
1215
|
+
containerId: agentRes.containerId,
|
|
1216
|
+
sessionId: agentRes.sessionId
|
|
1217
|
+
},
|
|
1218
|
+
instance
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1070
1223
|
};
|
|
1071
1224
|
|
|
1072
1225
|
// src/index.ts
|
|
@@ -1094,16 +1247,18 @@ function createAgentX(config) {
|
|
|
1094
1247
|
get events() {
|
|
1095
1248
|
return getLocalClient().events;
|
|
1096
1249
|
},
|
|
1097
|
-
get
|
|
1098
|
-
return getLocalClient().
|
|
1250
|
+
get runtime() {
|
|
1251
|
+
return getLocalClient().runtime;
|
|
1099
1252
|
},
|
|
1100
1253
|
get provider() {
|
|
1101
1254
|
return getLocalClient().provider;
|
|
1102
1255
|
},
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
get
|
|
1256
|
+
get chat() {
|
|
1257
|
+
return getLocalClient().chat;
|
|
1258
|
+
},
|
|
1259
|
+
get prototype() {
|
|
1260
|
+
return getLocalClient().prototype;
|
|
1261
|
+
},
|
|
1107
1262
|
on(type, handler) {
|
|
1108
1263
|
return getLocalClient().on(type, handler);
|
|
1109
1264
|
},
|
|
@@ -1144,7 +1299,7 @@ function createAgentX(config) {
|
|
|
1144
1299
|
"serve() requires platform.channelServer. Ensure your platform supports server mode."
|
|
1145
1300
|
);
|
|
1146
1301
|
}
|
|
1147
|
-
const { createServer: createServer2 } = await import("./server-
|
|
1302
|
+
const { createServer: createServer2 } = await import("./server-UCQISBKH.js");
|
|
1148
1303
|
return createServer2({
|
|
1149
1304
|
platform: config.platform,
|
|
1150
1305
|
createDriver: config.createDriver,
|