agentxjs 2.6.1 → 2.8.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/README.md +44 -1
- package/dist/chunk-JUZULVWQ.js +388 -0
- package/dist/chunk-JUZULVWQ.js.map +1 -0
- package/dist/index.d.ts +59 -289
- package/dist/index.js +124 -304
- package/dist/index.js.map +1 -1
- package/dist/server-MVOHQ5ZM.js +184 -0
- package/dist/server-MVOHQ5ZM.js.map +1 -0
- package/package.json +3 -3
- package/src/AgentHandle.ts +16 -14
- package/src/CommandHandler.ts +89 -204
- package/src/LocalClient.ts +21 -51
- package/src/RemoteClient.ts +20 -45
- package/src/index.ts +12 -26
- package/src/namespaces/agents.ts +34 -28
- package/src/namespaces/images.ts +21 -29
- package/src/namespaces/llm.ts +16 -10
- package/src/namespaces/presentations.ts +7 -7
- package/src/namespaces/sessions.ts +16 -14
- package/src/presentation/Presentation.ts +11 -11
- package/src/types.ts +64 -206
- package/dist/chunk-JTHR3AK6.js +0 -652
- package/dist/chunk-JTHR3AK6.js.map +0 -1
- package/dist/server-UCQISBKH.js +0 -7
- package/dist/server-UCQISBKH.js.map +0 -1
- package/src/namespaces/containers.ts +0 -68
- package/src/namespaces/prototypes.ts +0 -136
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CommandHandler
|
|
3
|
-
|
|
4
|
-
} from "./chunk-JTHR3AK6.js";
|
|
2
|
+
CommandHandler
|
|
3
|
+
} from "./chunk-JUZULVWQ.js";
|
|
5
4
|
|
|
6
5
|
// src/index.ts
|
|
7
6
|
import { createAgentXRuntime } from "@agentxjs/core/runtime";
|
|
@@ -11,47 +10,47 @@ import { createLogger } from "commonxjs/logger";
|
|
|
11
10
|
|
|
12
11
|
// src/AgentHandle.ts
|
|
13
12
|
var AgentHandleImpl = class {
|
|
14
|
-
|
|
13
|
+
instanceId;
|
|
15
14
|
imageId;
|
|
16
15
|
containerId;
|
|
17
16
|
sessionId;
|
|
18
17
|
ns;
|
|
19
18
|
constructor(ids, ns) {
|
|
20
|
-
this.
|
|
19
|
+
this.instanceId = ids.instanceId;
|
|
21
20
|
this.imageId = ids.imageId;
|
|
22
21
|
this.containerId = ids.containerId;
|
|
23
22
|
this.sessionId = ids.sessionId;
|
|
24
23
|
this.ns = ns;
|
|
25
24
|
}
|
|
26
25
|
async send(content) {
|
|
27
|
-
return this.ns.session.send(this.
|
|
26
|
+
return this.ns.session.send(this.instanceId, content);
|
|
28
27
|
}
|
|
29
28
|
async interrupt() {
|
|
30
|
-
return this.ns.session.interrupt(this.
|
|
29
|
+
return this.ns.session.interrupt(this.instanceId);
|
|
31
30
|
}
|
|
32
31
|
async history() {
|
|
33
32
|
return this.ns.image.getMessages(this.imageId);
|
|
34
33
|
}
|
|
35
34
|
async present(options) {
|
|
36
|
-
return this.ns.present.create(this.
|
|
35
|
+
return this.ns.present.create(this.instanceId, options);
|
|
37
36
|
}
|
|
38
37
|
async update(updates) {
|
|
39
38
|
await this.ns.image.update(this.imageId, updates);
|
|
40
39
|
}
|
|
41
40
|
async delete() {
|
|
42
|
-
await this.ns.
|
|
41
|
+
await this.ns.instance.destroy(this.instanceId);
|
|
43
42
|
await this.ns.image.delete(this.imageId);
|
|
44
43
|
}
|
|
45
44
|
};
|
|
46
45
|
|
|
47
46
|
// src/namespaces/agents.ts
|
|
48
|
-
function
|
|
47
|
+
function createLocalInstances(runtime) {
|
|
49
48
|
return {
|
|
50
49
|
async create(params) {
|
|
51
50
|
const existingAgent = runtime.getAgents().find((a) => a.imageId === params.imageId && a.lifecycle === "running");
|
|
52
51
|
if (existingAgent) {
|
|
53
52
|
return {
|
|
54
|
-
|
|
53
|
+
instanceId: existingAgent.instanceId,
|
|
55
54
|
imageId: existingAgent.imageId,
|
|
56
55
|
containerId: existingAgent.containerId,
|
|
57
56
|
sessionId: existingAgent.sessionId,
|
|
@@ -60,21 +59,21 @@ function createLocalAgents(runtime) {
|
|
|
60
59
|
}
|
|
61
60
|
const agent = await runtime.createAgent({
|
|
62
61
|
imageId: params.imageId,
|
|
63
|
-
|
|
62
|
+
instanceId: params.instanceId
|
|
64
63
|
});
|
|
65
64
|
return {
|
|
66
|
-
|
|
65
|
+
instanceId: agent.instanceId,
|
|
67
66
|
imageId: agent.imageId,
|
|
68
67
|
containerId: agent.containerId,
|
|
69
68
|
sessionId: agent.sessionId,
|
|
70
69
|
requestId: ""
|
|
71
70
|
};
|
|
72
71
|
},
|
|
73
|
-
async get(
|
|
74
|
-
const agent = runtime.getAgent(
|
|
72
|
+
async get(instanceId) {
|
|
73
|
+
const agent = runtime.getAgent(instanceId);
|
|
75
74
|
return {
|
|
76
75
|
agent: agent ? {
|
|
77
|
-
|
|
76
|
+
instanceId: agent.instanceId,
|
|
78
77
|
imageId: agent.imageId,
|
|
79
78
|
containerId: agent.containerId,
|
|
80
79
|
sessionId: agent.sessionId,
|
|
@@ -84,11 +83,11 @@ function createLocalAgents(runtime) {
|
|
|
84
83
|
requestId: ""
|
|
85
84
|
};
|
|
86
85
|
},
|
|
87
|
-
async list(
|
|
88
|
-
const agents =
|
|
86
|
+
async list() {
|
|
87
|
+
const agents = runtime.getAgents();
|
|
89
88
|
return {
|
|
90
89
|
agents: agents.map((a) => ({
|
|
91
|
-
|
|
90
|
+
instanceId: a.instanceId,
|
|
92
91
|
imageId: a.imageId,
|
|
93
92
|
containerId: a.containerId,
|
|
94
93
|
sessionId: a.sessionId,
|
|
@@ -97,97 +96,53 @@ function createLocalAgents(runtime) {
|
|
|
97
96
|
requestId: ""
|
|
98
97
|
};
|
|
99
98
|
},
|
|
100
|
-
async destroy(
|
|
101
|
-
const agent = runtime.getAgent(
|
|
99
|
+
async destroy(instanceId) {
|
|
100
|
+
const agent = runtime.getAgent(instanceId);
|
|
102
101
|
if (agent) {
|
|
103
|
-
await runtime.destroyAgent(
|
|
102
|
+
await runtime.destroyAgent(instanceId);
|
|
104
103
|
}
|
|
105
104
|
return { requestId: "" };
|
|
106
105
|
}
|
|
107
106
|
};
|
|
108
107
|
}
|
|
109
|
-
function
|
|
108
|
+
function createRemoteInstances(rpcClient) {
|
|
110
109
|
return {
|
|
111
110
|
async create(params) {
|
|
112
111
|
const result = await rpcClient.call("image.run", {
|
|
113
112
|
imageId: params.imageId,
|
|
114
|
-
|
|
113
|
+
instanceId: params.instanceId
|
|
115
114
|
});
|
|
116
115
|
return { ...result, requestId: "" };
|
|
117
116
|
},
|
|
118
|
-
async get(
|
|
119
|
-
const result = await rpcClient.call("
|
|
120
|
-
return { ...result, requestId: "" };
|
|
121
|
-
},
|
|
122
|
-
async list(containerId) {
|
|
123
|
-
const result = await rpcClient.call("agent.list", { containerId });
|
|
124
|
-
return { ...result, requestId: "" };
|
|
125
|
-
},
|
|
126
|
-
async destroy(agentId) {
|
|
127
|
-
const result = await rpcClient.call("agent.destroy", { agentId });
|
|
117
|
+
async get(instanceId) {
|
|
118
|
+
const result = await rpcClient.call("instance.get", { instanceId });
|
|
128
119
|
return { ...result, requestId: "" };
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/namespaces/containers.ts
|
|
134
|
-
function createLocalContainers(platform) {
|
|
135
|
-
return {
|
|
136
|
-
async create(containerId) {
|
|
137
|
-
const { getOrCreateContainer } = await import("@agentxjs/core/container");
|
|
138
|
-
const { containerRepository, imageRepository, sessionRepository } = platform;
|
|
139
|
-
const container = await getOrCreateContainer(containerId, {
|
|
140
|
-
containerRepository,
|
|
141
|
-
imageRepository,
|
|
142
|
-
sessionRepository
|
|
143
|
-
});
|
|
144
|
-
return { containerId: container.containerId, requestId: "" };
|
|
145
|
-
},
|
|
146
|
-
async get(containerId) {
|
|
147
|
-
const exists = await platform.containerRepository.containerExists(containerId);
|
|
148
|
-
return { containerId, exists, requestId: "" };
|
|
149
120
|
},
|
|
150
121
|
async list() {
|
|
151
|
-
const
|
|
152
|
-
return { containerIds: containers.map((c) => c.containerId), requestId: "" };
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function createRemoteContainers(rpcClient) {
|
|
157
|
-
return {
|
|
158
|
-
async create(containerId) {
|
|
159
|
-
const result = await rpcClient.call("container.create", {
|
|
160
|
-
containerId
|
|
161
|
-
});
|
|
162
|
-
return { ...result, requestId: "" };
|
|
163
|
-
},
|
|
164
|
-
async get(containerId) {
|
|
165
|
-
const result = await rpcClient.call("container.get", {
|
|
166
|
-
containerId
|
|
167
|
-
});
|
|
122
|
+
const result = await rpcClient.call("instance.list", {});
|
|
168
123
|
return { ...result, requestId: "" };
|
|
169
124
|
},
|
|
170
|
-
async
|
|
171
|
-
const result = await rpcClient.call("
|
|
125
|
+
async destroy(instanceId) {
|
|
126
|
+
const result = await rpcClient.call("instance.destroy", { instanceId });
|
|
172
127
|
return { ...result, requestId: "" };
|
|
173
128
|
}
|
|
174
129
|
};
|
|
175
130
|
}
|
|
176
131
|
|
|
177
132
|
// src/namespaces/images.ts
|
|
133
|
+
import { DEFAULT_CONTAINER_ID } from "@agentxjs/core/container";
|
|
178
134
|
function createLocalImages(platform) {
|
|
179
135
|
return {
|
|
180
136
|
async create(params) {
|
|
181
137
|
const { imageRepository, sessionRepository } = platform;
|
|
182
138
|
const { createImage } = await import("@agentxjs/core/image");
|
|
139
|
+
const { model, systemPrompt, mcpServers, ...rest } = params;
|
|
140
|
+
const embody = model || systemPrompt || mcpServers ? { model, systemPrompt, mcpServers } : void 0;
|
|
183
141
|
const image = await createImage(
|
|
184
142
|
{
|
|
185
|
-
containerId:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
systemPrompt: params.systemPrompt,
|
|
189
|
-
mcpServers: params.mcpServers,
|
|
190
|
-
customData: params.customData
|
|
143
|
+
containerId: DEFAULT_CONTAINER_ID,
|
|
144
|
+
...rest,
|
|
145
|
+
embody
|
|
191
146
|
},
|
|
192
147
|
{ imageRepository, sessionRepository }
|
|
193
148
|
);
|
|
@@ -205,8 +160,8 @@ function createLocalImages(platform) {
|
|
|
205
160
|
requestId: ""
|
|
206
161
|
};
|
|
207
162
|
},
|
|
208
|
-
async list(
|
|
209
|
-
const records =
|
|
163
|
+
async list() {
|
|
164
|
+
const records = await platform.imageRepository.findAllImages();
|
|
210
165
|
return {
|
|
211
166
|
records,
|
|
212
167
|
__subscriptions: records.map((r) => r.sessionId),
|
|
@@ -242,7 +197,10 @@ function createLocalImages(platform) {
|
|
|
242
197
|
function createRemoteImages(rpcClient, subscribeFn) {
|
|
243
198
|
return {
|
|
244
199
|
async create(params) {
|
|
245
|
-
const result = await rpcClient.call("image.create",
|
|
200
|
+
const result = await rpcClient.call("image.create", {
|
|
201
|
+
...params,
|
|
202
|
+
containerId: DEFAULT_CONTAINER_ID
|
|
203
|
+
});
|
|
246
204
|
if (result.__subscriptions) {
|
|
247
205
|
for (const sessionId of result.__subscriptions) {
|
|
248
206
|
subscribeFn(sessionId);
|
|
@@ -259,8 +217,8 @@ function createRemoteImages(rpcClient, subscribeFn) {
|
|
|
259
217
|
}
|
|
260
218
|
return { ...result, requestId: "" };
|
|
261
219
|
},
|
|
262
|
-
async list(
|
|
263
|
-
const result = await rpcClient.call("image.list", {
|
|
220
|
+
async list() {
|
|
221
|
+
const result = await rpcClient.call("image.list", {});
|
|
264
222
|
if (result.__subscriptions) {
|
|
265
223
|
for (const sessionId of result.__subscriptions) {
|
|
266
224
|
subscribeFn(sessionId);
|
|
@@ -287,6 +245,7 @@ function createRemoteImages(rpcClient, subscribeFn) {
|
|
|
287
245
|
}
|
|
288
246
|
|
|
289
247
|
// src/namespaces/llm.ts
|
|
248
|
+
import { DEFAULT_CONTAINER_ID as DEFAULT_CONTAINER_ID2 } from "@agentxjs/core/container";
|
|
290
249
|
import { generateId } from "@deepracticex/id";
|
|
291
250
|
function createLocalLLM(platform) {
|
|
292
251
|
const repo = platform.llmProviderRepository;
|
|
@@ -298,7 +257,7 @@ function createLocalLLM(platform) {
|
|
|
298
257
|
const now = Date.now();
|
|
299
258
|
const record = {
|
|
300
259
|
id: generateId("llm"),
|
|
301
|
-
containerId:
|
|
260
|
+
containerId: DEFAULT_CONTAINER_ID2,
|
|
302
261
|
name: params.name,
|
|
303
262
|
vendor: params.vendor,
|
|
304
263
|
protocol: params.protocol,
|
|
@@ -316,8 +275,8 @@ function createLocalLLM(platform) {
|
|
|
316
275
|
const record = await repo.findLLMProviderById(id);
|
|
317
276
|
return { record, requestId: "" };
|
|
318
277
|
},
|
|
319
|
-
async list(
|
|
320
|
-
const records = await repo.findLLMProvidersByContainerId(
|
|
278
|
+
async list() {
|
|
279
|
+
const records = await repo.findLLMProvidersByContainerId(DEFAULT_CONTAINER_ID2);
|
|
321
280
|
return { records, requestId: "" };
|
|
322
281
|
},
|
|
323
282
|
async update(id, updates) {
|
|
@@ -344,8 +303,8 @@ function createLocalLLM(platform) {
|
|
|
344
303
|
await repo.setDefaultLLMProvider(id);
|
|
345
304
|
return { requestId: "" };
|
|
346
305
|
},
|
|
347
|
-
async getDefault(
|
|
348
|
-
const record = await repo.findDefaultLLMProvider(
|
|
306
|
+
async getDefault() {
|
|
307
|
+
const record = await repo.findDefaultLLMProvider(DEFAULT_CONTAINER_ID2);
|
|
349
308
|
return { record, requestId: "" };
|
|
350
309
|
}
|
|
351
310
|
};
|
|
@@ -353,15 +312,20 @@ function createLocalLLM(platform) {
|
|
|
353
312
|
function createRemoteLLM(rpcClient) {
|
|
354
313
|
return {
|
|
355
314
|
async create(params) {
|
|
356
|
-
const result = await rpcClient.call("llm.create",
|
|
315
|
+
const result = await rpcClient.call("llm.create", {
|
|
316
|
+
...params,
|
|
317
|
+
containerId: DEFAULT_CONTAINER_ID2
|
|
318
|
+
});
|
|
357
319
|
return { ...result, requestId: "" };
|
|
358
320
|
},
|
|
359
321
|
async get(id) {
|
|
360
322
|
const result = await rpcClient.call("llm.get", { id });
|
|
361
323
|
return { ...result, requestId: "" };
|
|
362
324
|
},
|
|
363
|
-
async list(
|
|
364
|
-
const result = await rpcClient.call("llm.list", {
|
|
325
|
+
async list() {
|
|
326
|
+
const result = await rpcClient.call("llm.list", {
|
|
327
|
+
containerId: DEFAULT_CONTAINER_ID2
|
|
328
|
+
});
|
|
365
329
|
return { ...result, requestId: "" };
|
|
366
330
|
},
|
|
367
331
|
async update(id, updates) {
|
|
@@ -379,9 +343,9 @@ function createRemoteLLM(rpcClient) {
|
|
|
379
343
|
const result = await rpcClient.call("llm.default", { id });
|
|
380
344
|
return { ...result, requestId: "" };
|
|
381
345
|
},
|
|
382
|
-
async getDefault(
|
|
346
|
+
async getDefault() {
|
|
383
347
|
const result = await rpcClient.call("llm.default", {
|
|
384
|
-
containerId
|
|
348
|
+
containerId: DEFAULT_CONTAINER_ID2
|
|
385
349
|
});
|
|
386
350
|
return { ...result, requestId: "" };
|
|
387
351
|
}
|
|
@@ -691,14 +655,14 @@ function messagesToConversations(messages) {
|
|
|
691
655
|
// src/presentation/Presentation.ts
|
|
692
656
|
var Presentation = class {
|
|
693
657
|
agentx;
|
|
694
|
-
|
|
658
|
+
instanceId;
|
|
695
659
|
state;
|
|
696
660
|
updateHandlers = /* @__PURE__ */ new Set();
|
|
697
661
|
errorHandlers = /* @__PURE__ */ new Set();
|
|
698
662
|
eventUnsubscribe = null;
|
|
699
|
-
constructor(agentx,
|
|
663
|
+
constructor(agentx, instanceId, options, initialConversations) {
|
|
700
664
|
this.agentx = agentx;
|
|
701
|
-
this.
|
|
665
|
+
this.instanceId = instanceId;
|
|
702
666
|
this.state = initialConversations?.length ? { ...initialPresentationState, conversations: initialConversations } : createInitialState();
|
|
703
667
|
if (options?.onUpdate) {
|
|
704
668
|
this.updateHandlers.add(options.onUpdate);
|
|
@@ -740,7 +704,7 @@ var Presentation = class {
|
|
|
740
704
|
this.state = addUserConversation(this.state, content);
|
|
741
705
|
this.notify();
|
|
742
706
|
try {
|
|
743
|
-
await this.agentx.runtime.session.send(this.
|
|
707
|
+
await this.agentx.runtime.session.send(this.instanceId, content);
|
|
744
708
|
} catch (error) {
|
|
745
709
|
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
746
710
|
}
|
|
@@ -750,7 +714,7 @@ var Presentation = class {
|
|
|
750
714
|
*/
|
|
751
715
|
async interrupt() {
|
|
752
716
|
try {
|
|
753
|
-
await this.agentx.runtime.session.interrupt(this.
|
|
717
|
+
await this.agentx.runtime.session.interrupt(this.instanceId);
|
|
754
718
|
} catch (error) {
|
|
755
719
|
this.notifyError(error instanceof Error ? error : new Error(String(error)));
|
|
756
720
|
}
|
|
@@ -777,8 +741,8 @@ var Presentation = class {
|
|
|
777
741
|
subscribeToEvents() {
|
|
778
742
|
this.eventUnsubscribe = this.agentx.onAny((event) => {
|
|
779
743
|
const eventWithContext = event;
|
|
780
|
-
const eventAgentId = eventWithContext.context?.
|
|
781
|
-
if (eventAgentId && eventAgentId !== this.
|
|
744
|
+
const eventAgentId = eventWithContext.context?.instanceId;
|
|
745
|
+
if (eventAgentId && eventAgentId !== this.instanceId) {
|
|
782
746
|
return;
|
|
783
747
|
}
|
|
784
748
|
const newState = presentationReducer(this.state, event);
|
|
@@ -809,109 +773,12 @@ var Presentation = class {
|
|
|
809
773
|
};
|
|
810
774
|
|
|
811
775
|
// src/namespaces/presentations.ts
|
|
812
|
-
function createPresentations(agentx,
|
|
776
|
+
function createPresentations(agentx, sessionNs) {
|
|
813
777
|
return {
|
|
814
|
-
async create(
|
|
815
|
-
const messages = await
|
|
778
|
+
async create(instanceId, options) {
|
|
779
|
+
const messages = await sessionNs.getMessages(instanceId);
|
|
816
780
|
const conversations = messagesToConversations(messages);
|
|
817
|
-
return new Presentation(agentx,
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
}
|
|
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: "" };
|
|
781
|
+
return new Presentation(agentx, instanceId, options, conversations);
|
|
915
782
|
}
|
|
916
783
|
};
|
|
917
784
|
}
|
|
@@ -919,16 +786,16 @@ function createRemotePrototypes(rpcClient) {
|
|
|
919
786
|
// src/namespaces/sessions.ts
|
|
920
787
|
function createLocalSessions(runtime) {
|
|
921
788
|
return {
|
|
922
|
-
async send(
|
|
923
|
-
await runtime.receive(
|
|
924
|
-
return {
|
|
789
|
+
async send(instanceId, content) {
|
|
790
|
+
await runtime.receive(instanceId, content);
|
|
791
|
+
return { instanceId, requestId: "" };
|
|
925
792
|
},
|
|
926
|
-
async interrupt(
|
|
927
|
-
runtime.interrupt(
|
|
793
|
+
async interrupt(instanceId) {
|
|
794
|
+
runtime.interrupt(instanceId);
|
|
928
795
|
return { requestId: "" };
|
|
929
796
|
},
|
|
930
|
-
async getMessages(
|
|
931
|
-
const agent = runtime.getAgent(
|
|
797
|
+
async getMessages(instanceId) {
|
|
798
|
+
const agent = runtime.getAgent(instanceId);
|
|
932
799
|
if (!agent) return [];
|
|
933
800
|
return runtime.platform.sessionRepository.getMessages(agent.sessionId);
|
|
934
801
|
}
|
|
@@ -936,19 +803,21 @@ function createLocalSessions(runtime) {
|
|
|
936
803
|
}
|
|
937
804
|
function createRemoteSessions(rpcClient) {
|
|
938
805
|
return {
|
|
939
|
-
async send(
|
|
806
|
+
async send(instanceId, content) {
|
|
940
807
|
const result = await rpcClient.call("message.send", {
|
|
941
|
-
|
|
808
|
+
instanceId,
|
|
942
809
|
content
|
|
943
810
|
});
|
|
944
811
|
return { ...result, requestId: "" };
|
|
945
812
|
},
|
|
946
|
-
async interrupt(
|
|
947
|
-
const result = await rpcClient.call("
|
|
813
|
+
async interrupt(instanceId) {
|
|
814
|
+
const result = await rpcClient.call("instance.interrupt", { instanceId });
|
|
948
815
|
return { ...result, requestId: "" };
|
|
949
816
|
},
|
|
950
|
-
async getMessages(
|
|
951
|
-
const agentRes = await rpcClient.call("
|
|
817
|
+
async getMessages(instanceId) {
|
|
818
|
+
const agentRes = await rpcClient.call("instance.get", {
|
|
819
|
+
instanceId
|
|
820
|
+
});
|
|
952
821
|
if (!agentRes.agent) return [];
|
|
953
822
|
const msgRes = await rpcClient.call("image.messages", {
|
|
954
823
|
imageId: agentRes.agent.imageId
|
|
@@ -967,20 +836,16 @@ var LocalClient = class {
|
|
|
967
836
|
chat;
|
|
968
837
|
runtime;
|
|
969
838
|
provider;
|
|
970
|
-
prototype;
|
|
971
839
|
constructor(agentxRuntime) {
|
|
972
840
|
this._runtime = agentxRuntime;
|
|
973
841
|
const platform = agentxRuntime.platform;
|
|
974
|
-
const container = createLocalContainers(platform);
|
|
975
842
|
const image = createLocalImages(platform);
|
|
976
|
-
const
|
|
843
|
+
const instance = createLocalInstances(agentxRuntime);
|
|
977
844
|
const session = createLocalSessions(agentxRuntime);
|
|
978
845
|
const llm = createLocalLLM(platform);
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
this.runtime = { container, image, agent, session, present, llm, prototype };
|
|
846
|
+
const present = createPresentations(this, session);
|
|
847
|
+
this.runtime = { image, instance, session, present, llm };
|
|
982
848
|
this.provider = llm;
|
|
983
|
-
this.prototype = prototype;
|
|
984
849
|
this.chat = this.createChatNamespace();
|
|
985
850
|
logger.info("LocalClient initialized");
|
|
986
851
|
}
|
|
@@ -1019,55 +884,37 @@ var LocalClient = class {
|
|
|
1019
884
|
}
|
|
1020
885
|
// ==================== Private ====================
|
|
1021
886
|
createChatNamespace() {
|
|
1022
|
-
const
|
|
887
|
+
const rt = this.runtime;
|
|
1023
888
|
return {
|
|
1024
889
|
async create(params) {
|
|
1025
|
-
const
|
|
1026
|
-
|
|
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 });
|
|
890
|
+
const imgRes = await rt.image.create(params);
|
|
891
|
+
const instRes = await rt.instance.create({ imageId: imgRes.record.imageId });
|
|
1045
892
|
return new AgentHandleImpl(
|
|
1046
893
|
{
|
|
1047
|
-
|
|
1048
|
-
imageId:
|
|
1049
|
-
containerId:
|
|
1050
|
-
sessionId:
|
|
894
|
+
instanceId: instRes.instanceId,
|
|
895
|
+
imageId: instRes.imageId,
|
|
896
|
+
containerId: instRes.containerId,
|
|
897
|
+
sessionId: instRes.sessionId
|
|
1051
898
|
},
|
|
1052
|
-
|
|
899
|
+
rt
|
|
1053
900
|
);
|
|
1054
901
|
},
|
|
1055
902
|
async list() {
|
|
1056
|
-
return
|
|
903
|
+
return rt.image.list();
|
|
1057
904
|
},
|
|
1058
905
|
async get(id) {
|
|
1059
|
-
const res = await
|
|
906
|
+
const res = await rt.image.get(id);
|
|
1060
907
|
if (!res.record) return null;
|
|
1061
908
|
const r = res.record;
|
|
1062
|
-
const
|
|
909
|
+
const instRes = await rt.instance.create({ imageId: r.imageId });
|
|
1063
910
|
return new AgentHandleImpl(
|
|
1064
911
|
{
|
|
1065
|
-
|
|
1066
|
-
imageId:
|
|
1067
|
-
containerId:
|
|
1068
|
-
sessionId:
|
|
912
|
+
instanceId: instRes.instanceId,
|
|
913
|
+
imageId: instRes.imageId,
|
|
914
|
+
containerId: instRes.containerId,
|
|
915
|
+
sessionId: instRes.sessionId
|
|
1069
916
|
},
|
|
1070
|
-
|
|
917
|
+
rt
|
|
1071
918
|
);
|
|
1072
919
|
}
|
|
1073
920
|
};
|
|
@@ -1095,7 +942,6 @@ var RemoteClient = class {
|
|
|
1095
942
|
chat;
|
|
1096
943
|
runtime;
|
|
1097
944
|
provider;
|
|
1098
|
-
prototype;
|
|
1099
945
|
constructor(config) {
|
|
1100
946
|
this.config = config;
|
|
1101
947
|
this.eventBus = new EventBusImpl();
|
|
@@ -1111,16 +957,13 @@ var RemoteClient = class {
|
|
|
1111
957
|
logger2.debug("Received stream event", { topic, type: event.type });
|
|
1112
958
|
this.eventBus.emit(event);
|
|
1113
959
|
});
|
|
1114
|
-
const container = createRemoteContainers(this.rpcClient);
|
|
1115
960
|
const image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
|
|
1116
|
-
const
|
|
961
|
+
const instance = createRemoteInstances(this.rpcClient);
|
|
1117
962
|
const session = createRemoteSessions(this.rpcClient);
|
|
1118
963
|
const llm = createRemoteLLM(this.rpcClient);
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1121
|
-
this.runtime = { container, image, agent, session, present, llm, prototype };
|
|
964
|
+
const present = createPresentations(this, session);
|
|
965
|
+
this.runtime = { image, instance, session, present, llm };
|
|
1122
966
|
this.provider = llm;
|
|
1123
|
-
this.prototype = prototype;
|
|
1124
967
|
this.chat = this.createChatNamespace();
|
|
1125
968
|
}
|
|
1126
969
|
// ==================== Properties ====================
|
|
@@ -1167,55 +1010,37 @@ var RemoteClient = class {
|
|
|
1167
1010
|
}
|
|
1168
1011
|
// ==================== Private ====================
|
|
1169
1012
|
createChatNamespace() {
|
|
1170
|
-
const
|
|
1013
|
+
const rt = this.runtime;
|
|
1171
1014
|
return {
|
|
1172
1015
|
async create(params) {
|
|
1173
|
-
const
|
|
1174
|
-
|
|
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 });
|
|
1016
|
+
const imgRes = await rt.image.create(params);
|
|
1017
|
+
const instRes = await rt.instance.create({ imageId: imgRes.record.imageId });
|
|
1193
1018
|
return new AgentHandleImpl(
|
|
1194
1019
|
{
|
|
1195
|
-
|
|
1196
|
-
imageId:
|
|
1197
|
-
containerId:
|
|
1198
|
-
sessionId:
|
|
1020
|
+
instanceId: instRes.instanceId,
|
|
1021
|
+
imageId: instRes.imageId,
|
|
1022
|
+
containerId: instRes.containerId,
|
|
1023
|
+
sessionId: instRes.sessionId
|
|
1199
1024
|
},
|
|
1200
|
-
|
|
1025
|
+
rt
|
|
1201
1026
|
);
|
|
1202
1027
|
},
|
|
1203
1028
|
async list() {
|
|
1204
|
-
return
|
|
1029
|
+
return rt.image.list();
|
|
1205
1030
|
},
|
|
1206
1031
|
async get(id) {
|
|
1207
|
-
const res = await
|
|
1032
|
+
const res = await rt.image.get(id);
|
|
1208
1033
|
if (!res.record) return null;
|
|
1209
1034
|
const r = res.record;
|
|
1210
|
-
const
|
|
1035
|
+
const instRes = await rt.instance.create({ imageId: r.imageId });
|
|
1211
1036
|
return new AgentHandleImpl(
|
|
1212
1037
|
{
|
|
1213
|
-
|
|
1214
|
-
imageId:
|
|
1215
|
-
containerId:
|
|
1216
|
-
sessionId:
|
|
1038
|
+
instanceId: instRes.instanceId,
|
|
1039
|
+
imageId: instRes.imageId,
|
|
1040
|
+
containerId: instRes.containerId,
|
|
1041
|
+
sessionId: instRes.sessionId
|
|
1217
1042
|
},
|
|
1218
|
-
|
|
1043
|
+
rt
|
|
1219
1044
|
);
|
|
1220
1045
|
}
|
|
1221
1046
|
};
|
|
@@ -1256,9 +1081,6 @@ function createAgentX(config) {
|
|
|
1256
1081
|
get chat() {
|
|
1257
1082
|
return getLocalClient().chat;
|
|
1258
1083
|
},
|
|
1259
|
-
get prototype() {
|
|
1260
|
-
return getLocalClient().prototype;
|
|
1261
|
-
},
|
|
1262
1084
|
on(type, handler) {
|
|
1263
1085
|
return getLocalClient().on(type, handler);
|
|
1264
1086
|
},
|
|
@@ -1299,8 +1121,8 @@ function createAgentX(config) {
|
|
|
1299
1121
|
"serve() requires platform.channelServer. Ensure your platform supports server mode."
|
|
1300
1122
|
);
|
|
1301
1123
|
}
|
|
1302
|
-
const { createServer
|
|
1303
|
-
return
|
|
1124
|
+
const { createServer } = await import("./server-MVOHQ5ZM.js");
|
|
1125
|
+
return createServer({
|
|
1304
1126
|
platform: config.platform,
|
|
1305
1127
|
createDriver: config.createDriver,
|
|
1306
1128
|
port: serveConfig?.port,
|
|
@@ -1317,12 +1139,10 @@ function createAgentX(config) {
|
|
|
1317
1139
|
export {
|
|
1318
1140
|
AgentXError,
|
|
1319
1141
|
AgentXErrorCode,
|
|
1320
|
-
CommandHandler,
|
|
1321
1142
|
Presentation,
|
|
1322
1143
|
addUserConversation,
|
|
1323
1144
|
createAgentX,
|
|
1324
1145
|
createInitialState,
|
|
1325
|
-
createServer,
|
|
1326
1146
|
initialPresentationState,
|
|
1327
1147
|
messagesToConversations,
|
|
1328
1148
|
presentationReducer
|