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/README.md +44 -1
- package/dist/{chunk-JTHR3AK6.js → chunk-NPRCFKO5.js} +39 -39
- package/dist/chunk-NPRCFKO5.js.map +1 -0
- package/dist/index.d.ts +25 -25
- package/dist/index.js +92 -88
- package/dist/index.js.map +1 -1
- package/dist/server-3BCYHXYA.js +7 -0
- package/package.json +3 -3
- package/src/AgentHandle.ts +7 -7
- package/src/CommandHandler.ts +41 -41
- package/src/LocalClient.ts +21 -20
- package/src/RemoteClient.ts +21 -20
- package/src/index.ts +5 -5
- package/src/namespaces/agents.ts +33 -27
- 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 +21 -21
- package/dist/chunk-JTHR3AK6.js.map +0 -1
- package/dist/server-UCQISBKH.js +0 -7
- /package/dist/{server-UCQISBKH.js.map → server-3BCYHXYA.js.map} +0 -0
package/src/CommandHandler.ts
CHANGED
|
@@ -89,16 +89,16 @@ export class CommandHandler {
|
|
|
89
89
|
case "image.messages":
|
|
90
90
|
return await this.handleImageMessages(params);
|
|
91
91
|
|
|
92
|
-
//
|
|
93
|
-
case "
|
|
92
|
+
// Instance
|
|
93
|
+
case "instance.get":
|
|
94
94
|
return await this.handleAgentGet(params);
|
|
95
|
-
case "
|
|
95
|
+
case "instance.list":
|
|
96
96
|
return await this.handleAgentList(params);
|
|
97
|
-
case "
|
|
97
|
+
case "instance.destroy":
|
|
98
98
|
return await this.handleAgentDestroy(params);
|
|
99
|
-
case "
|
|
99
|
+
case "instance.destroyAll":
|
|
100
100
|
return await this.handleAgentDestroyAll(params);
|
|
101
|
-
case "
|
|
101
|
+
case "instance.interrupt":
|
|
102
102
|
return await this.handleAgentInterrupt(params);
|
|
103
103
|
|
|
104
104
|
// Message
|
|
@@ -228,9 +228,9 @@ export class CommandHandler {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
private async handleImageRun(params: unknown): Promise<RpcResponse> {
|
|
231
|
-
const { imageId,
|
|
231
|
+
const { imageId, instanceId: requestedInstanceId } = params as {
|
|
232
232
|
imageId: string;
|
|
233
|
-
|
|
233
|
+
instanceId?: string;
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
// Check if already have a running agent for this image
|
|
@@ -241,30 +241,30 @@ export class CommandHandler {
|
|
|
241
241
|
if (existingAgent) {
|
|
242
242
|
logger.debug("Reusing existing agent for image", {
|
|
243
243
|
imageId,
|
|
244
|
-
|
|
244
|
+
instanceId: existingAgent.instanceId,
|
|
245
245
|
});
|
|
246
246
|
return ok({
|
|
247
247
|
imageId,
|
|
248
|
-
|
|
248
|
+
instanceId: existingAgent.instanceId,
|
|
249
249
|
sessionId: existingAgent.sessionId,
|
|
250
250
|
containerId: existingAgent.containerId,
|
|
251
251
|
reused: true,
|
|
252
252
|
});
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
// Create new agent (with optional custom
|
|
255
|
+
// Create new agent (with optional custom instanceId)
|
|
256
256
|
const agent = await this.runtime.createAgent({
|
|
257
257
|
imageId,
|
|
258
|
-
|
|
258
|
+
instanceId: requestedInstanceId,
|
|
259
259
|
});
|
|
260
260
|
logger.info("Created new agent for image", {
|
|
261
261
|
imageId,
|
|
262
|
-
|
|
262
|
+
instanceId: agent.instanceId,
|
|
263
263
|
});
|
|
264
264
|
|
|
265
265
|
return ok({
|
|
266
266
|
imageId,
|
|
267
|
-
|
|
267
|
+
instanceId: agent.instanceId,
|
|
268
268
|
sessionId: agent.sessionId,
|
|
269
269
|
containerId: agent.containerId,
|
|
270
270
|
reused: false,
|
|
@@ -280,8 +280,8 @@ export class CommandHandler {
|
|
|
280
280
|
.find((a) => a.imageId === imageId && a.lifecycle === "running");
|
|
281
281
|
|
|
282
282
|
if (agent) {
|
|
283
|
-
await this.runtime.stopAgent(agent.
|
|
284
|
-
logger.info("Stopped agent for image", { imageId,
|
|
283
|
+
await this.runtime.stopAgent(agent.instanceId);
|
|
284
|
+
logger.info("Stopped agent for image", { imageId, instanceId: agent.instanceId });
|
|
285
285
|
} else {
|
|
286
286
|
logger.debug("No running agent found for image", { imageId });
|
|
287
287
|
}
|
|
@@ -344,13 +344,13 @@ export class CommandHandler {
|
|
|
344
344
|
// ==================== Agent Commands ====================
|
|
345
345
|
|
|
346
346
|
private async handleAgentGet(params: unknown): Promise<RpcResponse> {
|
|
347
|
-
const {
|
|
348
|
-
const agent = this.runtime.getAgent(
|
|
347
|
+
const { instanceId } = params as { instanceId: string };
|
|
348
|
+
const agent = this.runtime.getAgent(instanceId);
|
|
349
349
|
|
|
350
350
|
return ok({
|
|
351
351
|
agent: agent
|
|
352
352
|
? {
|
|
353
|
-
|
|
353
|
+
instanceId: agent.instanceId,
|
|
354
354
|
imageId: agent.imageId,
|
|
355
355
|
containerId: agent.containerId,
|
|
356
356
|
sessionId: agent.sessionId,
|
|
@@ -369,7 +369,7 @@ export class CommandHandler {
|
|
|
369
369
|
|
|
370
370
|
return ok({
|
|
371
371
|
agents: agents.map((a) => ({
|
|
372
|
-
|
|
372
|
+
instanceId: a.instanceId,
|
|
373
373
|
imageId: a.imageId,
|
|
374
374
|
containerId: a.containerId,
|
|
375
375
|
sessionId: a.sessionId,
|
|
@@ -379,47 +379,47 @@ export class CommandHandler {
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
private async handleAgentDestroy(params: unknown): Promise<RpcResponse> {
|
|
382
|
-
const {
|
|
382
|
+
const { instanceId } = params as { instanceId: string };
|
|
383
383
|
|
|
384
384
|
// Check if agent exists first
|
|
385
|
-
const agent = this.runtime.getAgent(
|
|
385
|
+
const agent = this.runtime.getAgent(instanceId);
|
|
386
386
|
if (!agent) {
|
|
387
|
-
return ok({
|
|
387
|
+
return ok({ instanceId, success: false });
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
-
await this.runtime.destroyAgent(
|
|
391
|
-
return ok({
|
|
390
|
+
await this.runtime.destroyAgent(instanceId);
|
|
391
|
+
return ok({ instanceId, success: true });
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
private async handleAgentDestroyAll(params: unknown): Promise<RpcResponse> {
|
|
395
395
|
const { containerId } = params as { containerId: string };
|
|
396
396
|
const agents = this.runtime.getAgentsByContainer(containerId);
|
|
397
397
|
for (const agent of agents) {
|
|
398
|
-
await this.runtime.destroyAgent(agent.
|
|
398
|
+
await this.runtime.destroyAgent(agent.instanceId);
|
|
399
399
|
}
|
|
400
400
|
return ok({ containerId });
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
private async handleAgentInterrupt(params: unknown): Promise<RpcResponse> {
|
|
404
|
-
const {
|
|
405
|
-
this.runtime.interrupt(
|
|
406
|
-
return ok({
|
|
404
|
+
const { instanceId } = params as { instanceId: string };
|
|
405
|
+
this.runtime.interrupt(instanceId);
|
|
406
|
+
return ok({ instanceId });
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
// ==================== Message Commands ====================
|
|
410
410
|
|
|
411
411
|
private async handleMessageSend(params: unknown): Promise<RpcResponse> {
|
|
412
|
-
const {
|
|
413
|
-
|
|
412
|
+
const { instanceId, imageId, content } = params as {
|
|
413
|
+
instanceId?: string;
|
|
414
414
|
imageId?: string;
|
|
415
415
|
content: string | UserContentPart[];
|
|
416
416
|
};
|
|
417
417
|
|
|
418
|
-
let
|
|
418
|
+
let targetInstanceId: string;
|
|
419
419
|
|
|
420
|
-
if (
|
|
420
|
+
if (instanceId) {
|
|
421
421
|
// Direct agent reference
|
|
422
|
-
|
|
422
|
+
targetInstanceId = instanceId;
|
|
423
423
|
} else if (imageId) {
|
|
424
424
|
// Auto-activate image: find or create agent
|
|
425
425
|
const existingAgent = this.runtime
|
|
@@ -427,26 +427,26 @@ export class CommandHandler {
|
|
|
427
427
|
.find((a) => a.imageId === imageId && a.lifecycle === "running");
|
|
428
428
|
|
|
429
429
|
if (existingAgent) {
|
|
430
|
-
|
|
430
|
+
targetInstanceId = existingAgent.instanceId;
|
|
431
431
|
logger.debug("Using existing agent for message", {
|
|
432
432
|
imageId,
|
|
433
|
-
|
|
433
|
+
instanceId: targetInstanceId,
|
|
434
434
|
});
|
|
435
435
|
} else {
|
|
436
436
|
// Create new agent for this image
|
|
437
437
|
const agent = await this.runtime.createAgent({ imageId });
|
|
438
|
-
|
|
438
|
+
targetInstanceId = agent.instanceId;
|
|
439
439
|
logger.info("Auto-created agent for message", {
|
|
440
440
|
imageId,
|
|
441
|
-
|
|
441
|
+
instanceId: targetInstanceId,
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
} else {
|
|
445
|
-
return err(-32602, "Either
|
|
445
|
+
return err(-32602, "Either instanceId or imageId is required");
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
-
await this.runtime.receive(
|
|
449
|
-
return ok({
|
|
448
|
+
await this.runtime.receive(targetInstanceId, content);
|
|
449
|
+
return ok({ instanceId: targetInstanceId, imageId });
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
// ==================== Prototype Commands ====================
|
package/src/LocalClient.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { AgentXRuntime } from "@agentxjs/core/runtime";
|
|
|
12
12
|
import { createLogger } from "commonxjs/logger";
|
|
13
13
|
import { AgentHandleImpl } from "./AgentHandle";
|
|
14
14
|
import { CommandHandler } from "./CommandHandler";
|
|
15
|
-
import {
|
|
15
|
+
import { createLocalInstances } from "./namespaces/agents";
|
|
16
16
|
import { createLocalContainers } from "./namespaces/containers";
|
|
17
17
|
import { createLocalImages } from "./namespaces/images";
|
|
18
18
|
import { createLocalLLM } from "./namespaces/llm";
|
|
@@ -48,13 +48,13 @@ export class LocalClient implements AgentX {
|
|
|
48
48
|
|
|
49
49
|
const container = createLocalContainers(platform);
|
|
50
50
|
const image = createLocalImages(platform);
|
|
51
|
-
const
|
|
51
|
+
const instance = createLocalInstances(agentxRuntime);
|
|
52
52
|
const session = createLocalSessions(agentxRuntime);
|
|
53
53
|
const llm = createLocalLLM(platform);
|
|
54
54
|
const prototype = createLocalPrototypes(platform);
|
|
55
|
-
const present = createPresentations(this,
|
|
55
|
+
const present = createPresentations(this, session);
|
|
56
56
|
|
|
57
|
-
this.runtime = { container, image,
|
|
57
|
+
this.runtime = { container, image, instance, session, present, llm, prototype };
|
|
58
58
|
this.provider = llm;
|
|
59
59
|
this.prototype = prototype;
|
|
60
60
|
this.chat = this.createChatNamespace();
|
|
@@ -110,14 +110,14 @@ export class LocalClient implements AgentX {
|
|
|
110
110
|
// ==================== Private ====================
|
|
111
111
|
|
|
112
112
|
private createChatNamespace(): ChatNamespace {
|
|
113
|
-
const
|
|
113
|
+
const rt = this.runtime;
|
|
114
114
|
return {
|
|
115
115
|
async create(params) {
|
|
116
116
|
const containerId = "default";
|
|
117
117
|
// If prototypeId is provided, merge prototype config into params
|
|
118
118
|
let mergedParams = { ...params };
|
|
119
119
|
if (params.prototypeId) {
|
|
120
|
-
const protoRes = await
|
|
120
|
+
const protoRes = await rt.prototype.get(params.prototypeId);
|
|
121
121
|
if (protoRes.record) {
|
|
122
122
|
const proto = protoRes.record;
|
|
123
123
|
mergedParams = {
|
|
@@ -131,33 +131,34 @@ export class LocalClient implements AgentX {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
const { prototypeId: _pid, ...imageParams } = mergedParams;
|
|
134
|
-
const imgRes = await
|
|
135
|
-
const
|
|
134
|
+
const imgRes = await rt.image.create({ containerId, ...imageParams });
|
|
135
|
+
const instRes = await rt.instance.create({ imageId: imgRes.record.imageId });
|
|
136
136
|
return new AgentHandleImpl(
|
|
137
137
|
{
|
|
138
|
-
|
|
139
|
-
imageId:
|
|
140
|
-
containerId:
|
|
141
|
-
sessionId:
|
|
138
|
+
instanceId: instRes.instanceId,
|
|
139
|
+
imageId: instRes.imageId,
|
|
140
|
+
containerId: instRes.containerId,
|
|
141
|
+
sessionId: instRes.sessionId,
|
|
142
142
|
},
|
|
143
|
-
|
|
143
|
+
rt
|
|
144
144
|
);
|
|
145
145
|
},
|
|
146
146
|
async list() {
|
|
147
|
-
return
|
|
147
|
+
return rt.image.list();
|
|
148
148
|
},
|
|
149
149
|
async get(id) {
|
|
150
|
-
const res = await
|
|
150
|
+
const res = await rt.image.get(id);
|
|
151
151
|
if (!res.record) return null;
|
|
152
152
|
const r = res.record;
|
|
153
|
+
const instRes = await rt.instance.create({ imageId: r.imageId });
|
|
153
154
|
return new AgentHandleImpl(
|
|
154
155
|
{
|
|
155
|
-
|
|
156
|
-
imageId:
|
|
157
|
-
containerId:
|
|
158
|
-
sessionId:
|
|
156
|
+
instanceId: instRes.instanceId,
|
|
157
|
+
imageId: instRes.imageId,
|
|
158
|
+
containerId: instRes.containerId,
|
|
159
|
+
sessionId: instRes.sessionId,
|
|
159
160
|
},
|
|
160
|
-
|
|
161
|
+
rt
|
|
161
162
|
);
|
|
162
163
|
},
|
|
163
164
|
};
|
package/src/RemoteClient.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { EventBusImpl } from "@agentxjs/core/event";
|
|
|
11
11
|
import { RpcClient, type RpcMethod } from "@agentxjs/core/network";
|
|
12
12
|
import { createLogger } from "commonxjs/logger";
|
|
13
13
|
import { AgentHandleImpl } from "./AgentHandle";
|
|
14
|
-
import {
|
|
14
|
+
import { createRemoteInstances } from "./namespaces/agents";
|
|
15
15
|
import { createRemoteContainers } from "./namespaces/containers";
|
|
16
16
|
import { createRemoteImages } from "./namespaces/images";
|
|
17
17
|
import { createRemoteLLM } from "./namespaces/llm";
|
|
@@ -65,13 +65,13 @@ export class RemoteClient implements AgentX {
|
|
|
65
65
|
// Assemble namespaces
|
|
66
66
|
const container = createRemoteContainers(this.rpcClient);
|
|
67
67
|
const image = createRemoteImages(this.rpcClient, (sessionId) => this.subscribe(sessionId));
|
|
68
|
-
const
|
|
68
|
+
const instance = createRemoteInstances(this.rpcClient);
|
|
69
69
|
const session = createRemoteSessions(this.rpcClient);
|
|
70
70
|
const llm = createRemoteLLM(this.rpcClient);
|
|
71
71
|
const prototype = createRemotePrototypes(this.rpcClient);
|
|
72
|
-
const present = createPresentations(this,
|
|
72
|
+
const present = createPresentations(this, session);
|
|
73
73
|
|
|
74
|
-
this.runtime = { container, image,
|
|
74
|
+
this.runtime = { container, image, instance, session, present, llm, prototype };
|
|
75
75
|
this.provider = llm;
|
|
76
76
|
this.prototype = prototype;
|
|
77
77
|
this.chat = this.createChatNamespace();
|
|
@@ -137,14 +137,14 @@ export class RemoteClient implements AgentX {
|
|
|
137
137
|
// ==================== Private ====================
|
|
138
138
|
|
|
139
139
|
private createChatNamespace(): ChatNamespace {
|
|
140
|
-
const
|
|
140
|
+
const rt = this.runtime;
|
|
141
141
|
return {
|
|
142
142
|
async create(params) {
|
|
143
143
|
const containerId = "default";
|
|
144
144
|
// If prototypeId is provided, merge prototype config into params
|
|
145
145
|
let mergedParams = { ...params };
|
|
146
146
|
if (params.prototypeId) {
|
|
147
|
-
const protoRes = await
|
|
147
|
+
const protoRes = await rt.prototype.get(params.prototypeId);
|
|
148
148
|
if (protoRes.record) {
|
|
149
149
|
const proto = protoRes.record;
|
|
150
150
|
mergedParams = {
|
|
@@ -158,33 +158,34 @@ export class RemoteClient implements AgentX {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
const { prototypeId: _pid, ...imageParams } = mergedParams;
|
|
161
|
-
const imgRes = await
|
|
162
|
-
const
|
|
161
|
+
const imgRes = await rt.image.create({ containerId, ...imageParams });
|
|
162
|
+
const instRes = await rt.instance.create({ imageId: imgRes.record.imageId });
|
|
163
163
|
return new AgentHandleImpl(
|
|
164
164
|
{
|
|
165
|
-
|
|
166
|
-
imageId:
|
|
167
|
-
containerId:
|
|
168
|
-
sessionId:
|
|
165
|
+
instanceId: instRes.instanceId,
|
|
166
|
+
imageId: instRes.imageId,
|
|
167
|
+
containerId: instRes.containerId,
|
|
168
|
+
sessionId: instRes.sessionId,
|
|
169
169
|
},
|
|
170
|
-
|
|
170
|
+
rt
|
|
171
171
|
);
|
|
172
172
|
},
|
|
173
173
|
async list() {
|
|
174
|
-
return
|
|
174
|
+
return rt.image.list();
|
|
175
175
|
},
|
|
176
176
|
async get(id) {
|
|
177
|
-
const res = await
|
|
177
|
+
const res = await rt.image.get(id);
|
|
178
178
|
if (!res.record) return null;
|
|
179
179
|
const r = res.record;
|
|
180
|
+
const instRes = await rt.instance.create({ imageId: r.imageId });
|
|
180
181
|
return new AgentHandleImpl(
|
|
181
182
|
{
|
|
182
|
-
|
|
183
|
-
imageId:
|
|
184
|
-
containerId:
|
|
185
|
-
sessionId:
|
|
183
|
+
instanceId: instRes.instanceId,
|
|
184
|
+
imageId: instRes.imageId,
|
|
185
|
+
containerId: instRes.containerId,
|
|
186
|
+
sessionId: instRes.sessionId,
|
|
186
187
|
},
|
|
187
|
-
|
|
188
|
+
rt
|
|
188
189
|
);
|
|
189
190
|
},
|
|
190
191
|
};
|
package/src/index.ts
CHANGED
|
@@ -187,12 +187,7 @@ export {
|
|
|
187
187
|
export { createServer, type ServerConfig } from "./server";
|
|
188
188
|
// Re-export types
|
|
189
189
|
export type {
|
|
190
|
-
AgentCreateResponse,
|
|
191
|
-
AgentGetResponse,
|
|
192
190
|
AgentHandle,
|
|
193
|
-
AgentInfo,
|
|
194
|
-
AgentListResponse,
|
|
195
|
-
AgentNamespace,
|
|
196
191
|
AgentX,
|
|
197
192
|
AgentXBuilder,
|
|
198
193
|
AgentXServer,
|
|
@@ -210,6 +205,11 @@ export type {
|
|
|
210
205
|
ImageListResponse,
|
|
211
206
|
ImageNamespace,
|
|
212
207
|
ImageRecord,
|
|
208
|
+
InstanceCreateResponse,
|
|
209
|
+
InstanceGetResponse,
|
|
210
|
+
InstanceInfo,
|
|
211
|
+
InstanceListResponse,
|
|
212
|
+
InstanceNamespace,
|
|
213
213
|
LLMNamespace,
|
|
214
214
|
LLMProviderCreateResponse,
|
|
215
215
|
LLMProviderDefaultResponse,
|
package/src/namespaces/agents.ts
CHANGED
|
@@ -5,19 +5,22 @@
|
|
|
5
5
|
import type { RpcClient, RpcMethod } from "@agentxjs/core/network";
|
|
6
6
|
import type { AgentXRuntime } from "@agentxjs/core/runtime";
|
|
7
7
|
import type {
|
|
8
|
-
AgentCreateResponse,
|
|
9
|
-
AgentGetResponse,
|
|
10
|
-
AgentListResponse,
|
|
11
|
-
AgentNamespace,
|
|
12
8
|
BaseResponse,
|
|
9
|
+
InstanceCreateResponse,
|
|
10
|
+
InstanceGetResponse,
|
|
11
|
+
InstanceListResponse,
|
|
12
|
+
InstanceNamespace,
|
|
13
13
|
} from "../types";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Create local agent namespace backed by embedded runtime
|
|
17
17
|
*/
|
|
18
|
-
export function
|
|
18
|
+
export function createLocalInstances(runtime: AgentXRuntime): InstanceNamespace {
|
|
19
19
|
return {
|
|
20
|
-
async create(params: {
|
|
20
|
+
async create(params: {
|
|
21
|
+
imageId: string;
|
|
22
|
+
instanceId?: string;
|
|
23
|
+
}): Promise<InstanceCreateResponse> {
|
|
21
24
|
// Reuse existing running agent for this image
|
|
22
25
|
const existingAgent = runtime
|
|
23
26
|
.getAgents()
|
|
@@ -25,7 +28,7 @@ export function createLocalAgents(runtime: AgentXRuntime): AgentNamespace {
|
|
|
25
28
|
|
|
26
29
|
if (existingAgent) {
|
|
27
30
|
return {
|
|
28
|
-
|
|
31
|
+
instanceId: existingAgent.instanceId,
|
|
29
32
|
imageId: existingAgent.imageId,
|
|
30
33
|
containerId: existingAgent.containerId,
|
|
31
34
|
sessionId: existingAgent.sessionId,
|
|
@@ -35,11 +38,11 @@ export function createLocalAgents(runtime: AgentXRuntime): AgentNamespace {
|
|
|
35
38
|
|
|
36
39
|
const agent = await runtime.createAgent({
|
|
37
40
|
imageId: params.imageId,
|
|
38
|
-
|
|
41
|
+
instanceId: params.instanceId,
|
|
39
42
|
});
|
|
40
43
|
|
|
41
44
|
return {
|
|
42
|
-
|
|
45
|
+
instanceId: agent.instanceId,
|
|
43
46
|
imageId: agent.imageId,
|
|
44
47
|
containerId: agent.containerId,
|
|
45
48
|
sessionId: agent.sessionId,
|
|
@@ -47,12 +50,12 @@ export function createLocalAgents(runtime: AgentXRuntime): AgentNamespace {
|
|
|
47
50
|
};
|
|
48
51
|
},
|
|
49
52
|
|
|
50
|
-
async get(
|
|
51
|
-
const agent = runtime.getAgent(
|
|
53
|
+
async get(instanceId: string): Promise<InstanceGetResponse> {
|
|
54
|
+
const agent = runtime.getAgent(instanceId);
|
|
52
55
|
return {
|
|
53
56
|
agent: agent
|
|
54
57
|
? {
|
|
55
|
-
|
|
58
|
+
instanceId: agent.instanceId,
|
|
56
59
|
imageId: agent.imageId,
|
|
57
60
|
containerId: agent.containerId,
|
|
58
61
|
sessionId: agent.sessionId,
|
|
@@ -64,12 +67,12 @@ export function createLocalAgents(runtime: AgentXRuntime): AgentNamespace {
|
|
|
64
67
|
};
|
|
65
68
|
},
|
|
66
69
|
|
|
67
|
-
async list(containerId?: string): Promise<
|
|
70
|
+
async list(containerId?: string): Promise<InstanceListResponse> {
|
|
68
71
|
const agents = containerId ? runtime.getAgentsByContainer(containerId) : runtime.getAgents();
|
|
69
72
|
|
|
70
73
|
return {
|
|
71
74
|
agents: agents.map((a) => ({
|
|
72
|
-
|
|
75
|
+
instanceId: a.instanceId,
|
|
73
76
|
imageId: a.imageId,
|
|
74
77
|
containerId: a.containerId,
|
|
75
78
|
sessionId: a.sessionId,
|
|
@@ -79,10 +82,10 @@ export function createLocalAgents(runtime: AgentXRuntime): AgentNamespace {
|
|
|
79
82
|
};
|
|
80
83
|
},
|
|
81
84
|
|
|
82
|
-
async destroy(
|
|
83
|
-
const agent = runtime.getAgent(
|
|
85
|
+
async destroy(instanceId: string): Promise<BaseResponse> {
|
|
86
|
+
const agent = runtime.getAgent(instanceId);
|
|
84
87
|
if (agent) {
|
|
85
|
-
await runtime.destroyAgent(
|
|
88
|
+
await runtime.destroyAgent(instanceId);
|
|
86
89
|
}
|
|
87
90
|
return { requestId: "" };
|
|
88
91
|
},
|
|
@@ -92,29 +95,32 @@ export function createLocalAgents(runtime: AgentXRuntime): AgentNamespace {
|
|
|
92
95
|
/**
|
|
93
96
|
* Create remote agent namespace backed by RPC client
|
|
94
97
|
*/
|
|
95
|
-
export function
|
|
98
|
+
export function createRemoteInstances(rpcClient: RpcClient): InstanceNamespace {
|
|
96
99
|
return {
|
|
97
|
-
async create(params: {
|
|
100
|
+
async create(params: {
|
|
101
|
+
imageId: string;
|
|
102
|
+
instanceId?: string;
|
|
103
|
+
}): Promise<InstanceCreateResponse> {
|
|
98
104
|
// Agent creation via image.run RPC
|
|
99
|
-
const result = await rpcClient.call<
|
|
105
|
+
const result = await rpcClient.call<InstanceCreateResponse>("image.run" as RpcMethod, {
|
|
100
106
|
imageId: params.imageId,
|
|
101
|
-
|
|
107
|
+
instanceId: params.instanceId,
|
|
102
108
|
});
|
|
103
109
|
return { ...result, requestId: "" };
|
|
104
110
|
},
|
|
105
111
|
|
|
106
|
-
async get(
|
|
107
|
-
const result = await rpcClient.call<
|
|
112
|
+
async get(instanceId: string): Promise<InstanceGetResponse> {
|
|
113
|
+
const result = await rpcClient.call<InstanceGetResponse>("instance.get", { instanceId });
|
|
108
114
|
return { ...result, requestId: "" };
|
|
109
115
|
},
|
|
110
116
|
|
|
111
|
-
async list(containerId?: string): Promise<
|
|
112
|
-
const result = await rpcClient.call<
|
|
117
|
+
async list(containerId?: string): Promise<InstanceListResponse> {
|
|
118
|
+
const result = await rpcClient.call<InstanceListResponse>("instance.list", { containerId });
|
|
113
119
|
return { ...result, requestId: "" };
|
|
114
120
|
},
|
|
115
121
|
|
|
116
|
-
async destroy(
|
|
117
|
-
const result = await rpcClient.call<BaseResponse>("
|
|
122
|
+
async destroy(instanceId: string): Promise<BaseResponse> {
|
|
123
|
+
const result = await rpcClient.call<BaseResponse>("instance.destroy", { instanceId });
|
|
118
124
|
return { ...result, requestId: "" };
|
|
119
125
|
},
|
|
120
126
|
};
|
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { messagesToConversations, Presentation, type PresentationOptions } from "../presentation";
|
|
8
|
-
import type { AgentX,
|
|
8
|
+
import type { AgentX, PresentationNamespace, SessionNamespace } from "../types";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Create presentation namespace.
|
|
12
12
|
*
|
|
13
|
-
* Takes the full AgentX (for Presentation event wiring) and the
|
|
14
|
-
* (for message history
|
|
13
|
+
* Takes the full AgentX (for Presentation event wiring) and the SessionNamespace
|
|
14
|
+
* (for message history via instanceId).
|
|
15
15
|
*/
|
|
16
16
|
export function createPresentations(
|
|
17
17
|
agentx: AgentX,
|
|
18
|
-
|
|
18
|
+
sessionNs: SessionNamespace
|
|
19
19
|
): PresentationNamespace {
|
|
20
20
|
return {
|
|
21
|
-
async create(
|
|
22
|
-
const messages = await
|
|
21
|
+
async create(instanceId: string, options?: PresentationOptions): Promise<Presentation> {
|
|
22
|
+
const messages = await sessionNs.getMessages(instanceId);
|
|
23
23
|
const conversations = messagesToConversations(messages);
|
|
24
|
-
return new Presentation(agentx,
|
|
24
|
+
return new Presentation(agentx, instanceId, options, conversations);
|
|
25
25
|
},
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -5,25 +5,25 @@
|
|
|
5
5
|
import type { Message, UserContentPart } from "@agentxjs/core/agent";
|
|
6
6
|
import type { RpcClient } from "@agentxjs/core/network";
|
|
7
7
|
import type { AgentXRuntime } from "@agentxjs/core/runtime";
|
|
8
|
-
import type {
|
|
8
|
+
import type { BaseResponse, InstanceInfo, MessageSendResponse, SessionNamespace } from "../types";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Create local session namespace backed by embedded runtime
|
|
12
12
|
*/
|
|
13
13
|
export function createLocalSessions(runtime: AgentXRuntime): SessionNamespace {
|
|
14
14
|
return {
|
|
15
|
-
async send(
|
|
16
|
-
await runtime.receive(
|
|
17
|
-
return {
|
|
15
|
+
async send(instanceId: string, content: string | unknown[]): Promise<MessageSendResponse> {
|
|
16
|
+
await runtime.receive(instanceId, content as string | UserContentPart[]);
|
|
17
|
+
return { instanceId, requestId: "" };
|
|
18
18
|
},
|
|
19
19
|
|
|
20
|
-
async interrupt(
|
|
21
|
-
runtime.interrupt(
|
|
20
|
+
async interrupt(instanceId: string): Promise<BaseResponse> {
|
|
21
|
+
runtime.interrupt(instanceId);
|
|
22
22
|
return { requestId: "" };
|
|
23
23
|
},
|
|
24
24
|
|
|
25
|
-
async getMessages(
|
|
26
|
-
const agent = runtime.getAgent(
|
|
25
|
+
async getMessages(instanceId: string): Promise<Message[]> {
|
|
26
|
+
const agent = runtime.getAgent(instanceId);
|
|
27
27
|
if (!agent) return [];
|
|
28
28
|
return runtime.platform.sessionRepository.getMessages(agent.sessionId);
|
|
29
29
|
},
|
|
@@ -35,21 +35,23 @@ export function createLocalSessions(runtime: AgentXRuntime): SessionNamespace {
|
|
|
35
35
|
*/
|
|
36
36
|
export function createRemoteSessions(rpcClient: RpcClient): SessionNamespace {
|
|
37
37
|
return {
|
|
38
|
-
async send(
|
|
38
|
+
async send(instanceId: string, content: string | unknown[]): Promise<MessageSendResponse> {
|
|
39
39
|
const result = await rpcClient.call<MessageSendResponse>("message.send", {
|
|
40
|
-
|
|
40
|
+
instanceId,
|
|
41
41
|
content,
|
|
42
42
|
});
|
|
43
43
|
return { ...result, requestId: "" };
|
|
44
44
|
},
|
|
45
45
|
|
|
46
|
-
async interrupt(
|
|
47
|
-
const result = await rpcClient.call<BaseResponse>("
|
|
46
|
+
async interrupt(instanceId: string): Promise<BaseResponse> {
|
|
47
|
+
const result = await rpcClient.call<BaseResponse>("instance.interrupt", { instanceId });
|
|
48
48
|
return { ...result, requestId: "" };
|
|
49
49
|
},
|
|
50
50
|
|
|
51
|
-
async getMessages(
|
|
52
|
-
const agentRes = await rpcClient.call<{ agent:
|
|
51
|
+
async getMessages(instanceId: string): Promise<Message[]> {
|
|
52
|
+
const agentRes = await rpcClient.call<{ agent: InstanceInfo | null }>("instance.get", {
|
|
53
|
+
instanceId,
|
|
54
|
+
});
|
|
53
55
|
if (!agentRes.agent) return [];
|
|
54
56
|
const msgRes = await rpcClient.call<{ messages: Message[] }>("image.messages", {
|
|
55
57
|
imageId: agentRes.agent.imageId,
|