Compare commits
1 Commits
feat/ms23-
...
chore/ms23
| Author | SHA1 | Date | |
|---|---|---|---|
| d913d37071 |
@@ -25,14 +25,14 @@ export class AgentIngestionService {
|
|||||||
where: { sessionId: agentId },
|
where: { sessionId: agentId },
|
||||||
create: {
|
create: {
|
||||||
sessionId: agentId,
|
sessionId: agentId,
|
||||||
parentSessionId: parentAgentId ?? null,
|
parentSessionId: parentAgentId,
|
||||||
missionId,
|
missionId,
|
||||||
taskId,
|
taskId,
|
||||||
agentType,
|
agentType,
|
||||||
status: "spawning",
|
status: "spawning",
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
parentSessionId: parentAgentId ?? null,
|
parentSessionId: parentAgentId,
|
||||||
missionId,
|
missionId,
|
||||||
taskId,
|
taskId,
|
||||||
agentType,
|
agentType,
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
||||||
import { AgentControlService } from "./agent-control.service";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
|
|
||||||
describe("AgentControlService", () => {
|
|
||||||
let service: AgentControlService;
|
|
||||||
let prisma: {
|
|
||||||
agentSessionTree: {
|
|
||||||
findUnique: ReturnType<typeof vi.fn>;
|
|
||||||
updateMany: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
agentConversationMessage: {
|
|
||||||
create: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
operatorAuditLog: {
|
|
||||||
create: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
prisma = {
|
|
||||||
agentSessionTree: {
|
|
||||||
findUnique: vi.fn(),
|
|
||||||
updateMany: vi.fn().mockResolvedValue({ count: 1 }),
|
|
||||||
},
|
|
||||||
agentConversationMessage: {
|
|
||||||
create: vi.fn().mockResolvedValue(undefined),
|
|
||||||
},
|
|
||||||
operatorAuditLog: {
|
|
||||||
create: vi.fn().mockResolvedValue(undefined),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
service = new AgentControlService(prisma as unknown as PrismaService);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("injectMessage", () => {
|
|
||||||
it("creates conversation message and audit log when tree entry exists", async () => {
|
|
||||||
prisma.agentSessionTree.findUnique.mockResolvedValue({ id: "tree-1" });
|
|
||||||
|
|
||||||
await service.injectMessage("agent-123", "operator-abc", "Please continue");
|
|
||||||
|
|
||||||
expect(prisma.agentSessionTree.findUnique).toHaveBeenCalledWith({
|
|
||||||
where: { sessionId: "agent-123" },
|
|
||||||
select: { id: true },
|
|
||||||
});
|
|
||||||
expect(prisma.agentConversationMessage.create).toHaveBeenCalledWith({
|
|
||||||
data: {
|
|
||||||
sessionId: "agent-123",
|
|
||||||
role: "operator",
|
|
||||||
content: "Please continue",
|
|
||||||
provider: "internal",
|
|
||||||
metadata: {},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(prisma.operatorAuditLog.create).toHaveBeenCalledWith({
|
|
||||||
data: {
|
|
||||||
sessionId: "agent-123",
|
|
||||||
userId: "operator-abc",
|
|
||||||
provider: "internal",
|
|
||||||
action: "inject",
|
|
||||||
metadata: {
|
|
||||||
payload: {
|
|
||||||
message: "Please continue",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("creates only audit log when no tree entry exists", async () => {
|
|
||||||
prisma.agentSessionTree.findUnique.mockResolvedValue(null);
|
|
||||||
|
|
||||||
await service.injectMessage("agent-456", "operator-def", "Nudge message");
|
|
||||||
|
|
||||||
expect(prisma.agentConversationMessage.create).not.toHaveBeenCalled();
|
|
||||||
expect(prisma.operatorAuditLog.create).toHaveBeenCalledWith({
|
|
||||||
data: {
|
|
||||||
sessionId: "agent-456",
|
|
||||||
userId: "operator-def",
|
|
||||||
provider: "internal",
|
|
||||||
action: "inject",
|
|
||||||
metadata: {
|
|
||||||
payload: {
|
|
||||||
message: "Nudge message",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("pauseAgent", () => {
|
|
||||||
it("updates tree status to paused and creates audit log", async () => {
|
|
||||||
await service.pauseAgent("agent-789", "operator-pause");
|
|
||||||
|
|
||||||
expect(prisma.agentSessionTree.updateMany).toHaveBeenCalledWith({
|
|
||||||
where: { sessionId: "agent-789" },
|
|
||||||
data: { status: "paused" },
|
|
||||||
});
|
|
||||||
expect(prisma.operatorAuditLog.create).toHaveBeenCalledWith({
|
|
||||||
data: {
|
|
||||||
sessionId: "agent-789",
|
|
||||||
userId: "operator-pause",
|
|
||||||
provider: "internal",
|
|
||||||
action: "pause",
|
|
||||||
metadata: {
|
|
||||||
payload: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("resumeAgent", () => {
|
|
||||||
it("updates tree status to running and creates audit log", async () => {
|
|
||||||
await service.resumeAgent("agent-321", "operator-resume");
|
|
||||||
|
|
||||||
expect(prisma.agentSessionTree.updateMany).toHaveBeenCalledWith({
|
|
||||||
where: { sessionId: "agent-321" },
|
|
||||||
data: { status: "running" },
|
|
||||||
});
|
|
||||||
expect(prisma.operatorAuditLog.create).toHaveBeenCalledWith({
|
|
||||||
data: {
|
|
||||||
sessionId: "agent-321",
|
|
||||||
userId: "operator-resume",
|
|
||||||
provider: "internal",
|
|
||||||
action: "resume",
|
|
||||||
metadata: {
|
|
||||||
payload: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
|
||||||
import type { Prisma } from "@prisma/client";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AgentControlService {
|
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
|
||||||
|
|
||||||
private toJsonValue(value: Record<string, unknown>): Prisma.InputJsonValue {
|
|
||||||
return value as Prisma.InputJsonValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createOperatorAuditLog(
|
|
||||||
agentId: string,
|
|
||||||
operatorId: string,
|
|
||||||
action: "inject" | "pause" | "resume",
|
|
||||||
payload: Record<string, unknown>
|
|
||||||
): Promise<void> {
|
|
||||||
await this.prisma.operatorAuditLog.create({
|
|
||||||
data: {
|
|
||||||
sessionId: agentId,
|
|
||||||
userId: operatorId,
|
|
||||||
provider: "internal",
|
|
||||||
action,
|
|
||||||
metadata: this.toJsonValue({ payload }),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async injectMessage(agentId: string, operatorId: string, message: string): Promise<void> {
|
|
||||||
const treeEntry = await this.prisma.agentSessionTree.findUnique({
|
|
||||||
where: { sessionId: agentId },
|
|
||||||
select: { id: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (treeEntry) {
|
|
||||||
await this.prisma.agentConversationMessage.create({
|
|
||||||
data: {
|
|
||||||
sessionId: agentId,
|
|
||||||
role: "operator",
|
|
||||||
content: message,
|
|
||||||
provider: "internal",
|
|
||||||
metadata: this.toJsonValue({}),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.createOperatorAuditLog(agentId, operatorId, "inject", { message });
|
|
||||||
}
|
|
||||||
|
|
||||||
async pauseAgent(agentId: string, operatorId: string): Promise<void> {
|
|
||||||
await this.prisma.agentSessionTree.updateMany({
|
|
||||||
where: { sessionId: agentId },
|
|
||||||
data: { status: "paused" },
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.createOperatorAuditLog(agentId, operatorId, "pause", {});
|
|
||||||
}
|
|
||||||
|
|
||||||
async resumeAgent(agentId: string, operatorId: string): Promise<void> {
|
|
||||||
await this.prisma.agentSessionTree.updateMany({
|
|
||||||
where: { sessionId: agentId },
|
|
||||||
data: { status: "running" },
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.createOperatorAuditLog(agentId, operatorId, "resume", {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
||||||
import { AgentMessagesService } from "./agent-messages.service";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
|
|
||||||
describe("AgentMessagesService", () => {
|
|
||||||
let service: AgentMessagesService;
|
|
||||||
let prisma: {
|
|
||||||
agentConversationMessage: {
|
|
||||||
findMany: ReturnType<typeof vi.fn>;
|
|
||||||
count: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
prisma = {
|
|
||||||
agentConversationMessage: {
|
|
||||||
findMany: vi.fn(),
|
|
||||||
count: vi.fn(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
service = new AgentMessagesService(prisma as unknown as PrismaService);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getMessages", () => {
|
|
||||||
it("returns paginated messages from Prisma", async () => {
|
|
||||||
const sessionId = "agent-123";
|
|
||||||
const messages = [
|
|
||||||
{
|
|
||||||
id: "msg-1",
|
|
||||||
sessionId,
|
|
||||||
provider: "internal",
|
|
||||||
role: "assistant",
|
|
||||||
content: "First message",
|
|
||||||
timestamp: new Date("2026-03-07T16:00:00.000Z"),
|
|
||||||
metadata: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "msg-2",
|
|
||||||
sessionId,
|
|
||||||
provider: "internal",
|
|
||||||
role: "user",
|
|
||||||
content: "Second message",
|
|
||||||
timestamp: new Date("2026-03-07T15:59:00.000Z"),
|
|
||||||
metadata: {},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
prisma.agentConversationMessage.findMany.mockResolvedValue(messages);
|
|
||||||
prisma.agentConversationMessage.count.mockResolvedValue(2);
|
|
||||||
|
|
||||||
const result = await service.getMessages(sessionId, 50, 0);
|
|
||||||
|
|
||||||
expect(prisma.agentConversationMessage.findMany).toHaveBeenCalledWith({
|
|
||||||
where: { sessionId },
|
|
||||||
orderBy: { timestamp: "desc" },
|
|
||||||
take: 50,
|
|
||||||
skip: 0,
|
|
||||||
});
|
|
||||||
expect(prisma.agentConversationMessage.count).toHaveBeenCalledWith({ where: { sessionId } });
|
|
||||||
expect(result).toEqual({
|
|
||||||
messages,
|
|
||||||
total: 2,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("applies limit and cursor (skip) correctly", async () => {
|
|
||||||
const sessionId = "agent-456";
|
|
||||||
const limit = 10;
|
|
||||||
const cursor = 20;
|
|
||||||
|
|
||||||
prisma.agentConversationMessage.findMany.mockResolvedValue([]);
|
|
||||||
prisma.agentConversationMessage.count.mockResolvedValue(42);
|
|
||||||
|
|
||||||
await service.getMessages(sessionId, limit, cursor);
|
|
||||||
|
|
||||||
expect(prisma.agentConversationMessage.findMany).toHaveBeenCalledWith({
|
|
||||||
where: { sessionId },
|
|
||||||
orderBy: { timestamp: "desc" },
|
|
||||||
take: limit,
|
|
||||||
skip: cursor,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns empty messages array when no messages exist", async () => {
|
|
||||||
const sessionId = "agent-empty";
|
|
||||||
|
|
||||||
prisma.agentConversationMessage.findMany.mockResolvedValue([]);
|
|
||||||
prisma.agentConversationMessage.count.mockResolvedValue(0);
|
|
||||||
|
|
||||||
const result = await service.getMessages(sessionId, 25, 0);
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
messages: [],
|
|
||||||
total: 0,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
||||||
import { AgentTreeService } from "./agent-tree.service";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
|
|
||||||
describe("AgentTreeService", () => {
|
|
||||||
let service: AgentTreeService;
|
|
||||||
let prisma: {
|
|
||||||
agentSessionTree: {
|
|
||||||
findMany: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
prisma = {
|
|
||||||
agentSessionTree: {
|
|
||||||
findMany: vi.fn(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
service = new AgentTreeService(prisma as unknown as PrismaService);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getTree", () => {
|
|
||||||
it("returns mapped entries from Prisma", async () => {
|
|
||||||
prisma.agentSessionTree.findMany.mockResolvedValue([
|
|
||||||
{
|
|
||||||
id: "tree-1",
|
|
||||||
sessionId: "agent-1",
|
|
||||||
parentSessionId: "agent-root",
|
|
||||||
provider: "internal",
|
|
||||||
missionId: "mission-1",
|
|
||||||
taskId: "task-1",
|
|
||||||
taskSource: "queue",
|
|
||||||
agentType: "worker",
|
|
||||||
status: "running",
|
|
||||||
spawnedAt: new Date("2026-03-07T10:00:00.000Z"),
|
|
||||||
completedAt: new Date("2026-03-07T11:00:00.000Z"),
|
|
||||||
metadata: {},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await service.getTree();
|
|
||||||
|
|
||||||
expect(prisma.agentSessionTree.findMany).toHaveBeenCalledWith({
|
|
||||||
orderBy: { spawnedAt: "desc" },
|
|
||||||
take: 200,
|
|
||||||
});
|
|
||||||
expect(result).toEqual([
|
|
||||||
{
|
|
||||||
sessionId: "agent-1",
|
|
||||||
parentSessionId: "agent-root",
|
|
||||||
status: "running",
|
|
||||||
agentType: "worker",
|
|
||||||
taskSource: "queue",
|
|
||||||
spawnedAt: "2026-03-07T10:00:00.000Z",
|
|
||||||
completedAt: "2026-03-07T11:00:00.000Z",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns empty array when no entries exist", async () => {
|
|
||||||
prisma.agentSessionTree.findMany.mockResolvedValue([]);
|
|
||||||
|
|
||||||
const result = await service.getTree();
|
|
||||||
|
|
||||||
expect(result).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("maps null parentSessionId and completedAt correctly", async () => {
|
|
||||||
prisma.agentSessionTree.findMany.mockResolvedValue([
|
|
||||||
{
|
|
||||||
id: "tree-2",
|
|
||||||
sessionId: "agent-root",
|
|
||||||
parentSessionId: null,
|
|
||||||
provider: "internal",
|
|
||||||
missionId: null,
|
|
||||||
taskId: null,
|
|
||||||
taskSource: null,
|
|
||||||
agentType: null,
|
|
||||||
status: "spawning",
|
|
||||||
spawnedAt: new Date("2026-03-07T09:00:00.000Z"),
|
|
||||||
completedAt: null,
|
|
||||||
metadata: {},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const result = await service.getTree();
|
|
||||||
|
|
||||||
expect(result).toEqual([
|
|
||||||
{
|
|
||||||
sessionId: "agent-root",
|
|
||||||
parentSessionId: null,
|
|
||||||
status: "spawning",
|
|
||||||
agentType: null,
|
|
||||||
taskSource: null,
|
|
||||||
spawnedAt: "2026-03-07T09:00:00.000Z",
|
|
||||||
completedAt: null,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
import { AgentTreeResponseDto } from "./dto/agent-tree-response.dto";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AgentTreeService {
|
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
|
||||||
|
|
||||||
async getTree(): Promise<AgentTreeResponseDto[]> {
|
|
||||||
const entries = await this.prisma.agentSessionTree.findMany({
|
|
||||||
orderBy: { spawnedAt: "desc" },
|
|
||||||
take: 200,
|
|
||||||
});
|
|
||||||
|
|
||||||
const response: AgentTreeResponseDto[] = [];
|
|
||||||
for (const entry of entries) {
|
|
||||||
response.push({
|
|
||||||
sessionId: entry.sessionId,
|
|
||||||
parentSessionId: entry.parentSessionId ?? null,
|
|
||||||
status: entry.status,
|
|
||||||
agentType: entry.agentType ?? null,
|
|
||||||
taskSource: entry.taskSource ?? null,
|
|
||||||
spawnedAt: entry.spawnedAt.toISOString(),
|
|
||||||
completedAt: entry.completedAt?.toISOString() ?? null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,8 +6,6 @@ import { AgentLifecycleService } from "../../spawner/agent-lifecycle.service";
|
|||||||
import { KillswitchService } from "../../killswitch/killswitch.service";
|
import { KillswitchService } from "../../killswitch/killswitch.service";
|
||||||
import { AgentEventsService } from "./agent-events.service";
|
import { AgentEventsService } from "./agent-events.service";
|
||||||
import { AgentMessagesService } from "./agent-messages.service";
|
import { AgentMessagesService } from "./agent-messages.service";
|
||||||
import { AgentControlService } from "./agent-control.service";
|
|
||||||
import { AgentTreeService } from "./agent-tree.service";
|
|
||||||
import type { KillAllResult } from "../../killswitch/killswitch.service";
|
import type { KillAllResult } from "../../killswitch/killswitch.service";
|
||||||
|
|
||||||
describe("AgentsController - Killswitch Endpoints", () => {
|
describe("AgentsController - Killswitch Endpoints", () => {
|
||||||
@@ -37,14 +35,6 @@ describe("AgentsController - Killswitch Endpoints", () => {
|
|||||||
getReplayMessages: ReturnType<typeof vi.fn>;
|
getReplayMessages: ReturnType<typeof vi.fn>;
|
||||||
getMessagesAfter: ReturnType<typeof vi.fn>;
|
getMessagesAfter: ReturnType<typeof vi.fn>;
|
||||||
};
|
};
|
||||||
let mockControlService: {
|
|
||||||
injectMessage: ReturnType<typeof vi.fn>;
|
|
||||||
pauseAgent: ReturnType<typeof vi.fn>;
|
|
||||||
resumeAgent: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
let mockTreeService: {
|
|
||||||
getTree: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockKillswitchService = {
|
mockKillswitchService = {
|
||||||
@@ -87,25 +77,13 @@ describe("AgentsController - Killswitch Endpoints", () => {
|
|||||||
getMessagesAfter: vi.fn().mockResolvedValue([]),
|
getMessagesAfter: vi.fn().mockResolvedValue([]),
|
||||||
};
|
};
|
||||||
|
|
||||||
mockControlService = {
|
|
||||||
injectMessage: vi.fn().mockResolvedValue(undefined),
|
|
||||||
pauseAgent: vi.fn().mockResolvedValue(undefined),
|
|
||||||
resumeAgent: vi.fn().mockResolvedValue(undefined),
|
|
||||||
};
|
|
||||||
|
|
||||||
mockTreeService = {
|
|
||||||
getTree: vi.fn().mockResolvedValue([]),
|
|
||||||
};
|
|
||||||
|
|
||||||
controller = new AgentsController(
|
controller = new AgentsController(
|
||||||
mockQueueService as unknown as QueueService,
|
mockQueueService as unknown as QueueService,
|
||||||
mockSpawnerService as unknown as AgentSpawnerService,
|
mockSpawnerService as unknown as AgentSpawnerService,
|
||||||
mockLifecycleService as unknown as AgentLifecycleService,
|
mockLifecycleService as unknown as AgentLifecycleService,
|
||||||
mockKillswitchService as unknown as KillswitchService,
|
mockKillswitchService as unknown as KillswitchService,
|
||||||
mockEventsService as unknown as AgentEventsService,
|
mockEventsService as unknown as AgentEventsService,
|
||||||
mockMessagesService as unknown as AgentMessagesService,
|
mockMessagesService as unknown as AgentMessagesService
|
||||||
mockControlService as unknown as AgentControlService,
|
|
||||||
mockTreeService as unknown as AgentTreeService
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { AgentLifecycleService } from "../../spawner/agent-lifecycle.service";
|
|||||||
import { KillswitchService } from "../../killswitch/killswitch.service";
|
import { KillswitchService } from "../../killswitch/killswitch.service";
|
||||||
import { AgentEventsService } from "./agent-events.service";
|
import { AgentEventsService } from "./agent-events.service";
|
||||||
import { AgentMessagesService } from "./agent-messages.service";
|
import { AgentMessagesService } from "./agent-messages.service";
|
||||||
import { AgentControlService } from "./agent-control.service";
|
|
||||||
import { AgentTreeService } from "./agent-tree.service";
|
|
||||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||||
|
|
||||||
describe("AgentsController", () => {
|
describe("AgentsController", () => {
|
||||||
@@ -38,14 +36,6 @@ describe("AgentsController", () => {
|
|||||||
getReplayMessages: ReturnType<typeof vi.fn>;
|
getReplayMessages: ReturnType<typeof vi.fn>;
|
||||||
getMessagesAfter: ReturnType<typeof vi.fn>;
|
getMessagesAfter: ReturnType<typeof vi.fn>;
|
||||||
};
|
};
|
||||||
let controlService: {
|
|
||||||
injectMessage: ReturnType<typeof vi.fn>;
|
|
||||||
pauseAgent: ReturnType<typeof vi.fn>;
|
|
||||||
resumeAgent: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
let treeService: {
|
|
||||||
getTree: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Create mock services
|
// Create mock services
|
||||||
@@ -91,16 +81,6 @@ describe("AgentsController", () => {
|
|||||||
getMessagesAfter: vi.fn().mockResolvedValue([]),
|
getMessagesAfter: vi.fn().mockResolvedValue([]),
|
||||||
};
|
};
|
||||||
|
|
||||||
controlService = {
|
|
||||||
injectMessage: vi.fn().mockResolvedValue(undefined),
|
|
||||||
pauseAgent: vi.fn().mockResolvedValue(undefined),
|
|
||||||
resumeAgent: vi.fn().mockResolvedValue(undefined),
|
|
||||||
};
|
|
||||||
|
|
||||||
treeService = {
|
|
||||||
getTree: vi.fn().mockResolvedValue([]),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create controller with mocked services
|
// Create controller with mocked services
|
||||||
controller = new AgentsController(
|
controller = new AgentsController(
|
||||||
queueService as unknown as QueueService,
|
queueService as unknown as QueueService,
|
||||||
@@ -108,9 +88,7 @@ describe("AgentsController", () => {
|
|||||||
lifecycleService as unknown as AgentLifecycleService,
|
lifecycleService as unknown as AgentLifecycleService,
|
||||||
killswitchService as unknown as KillswitchService,
|
killswitchService as unknown as KillswitchService,
|
||||||
eventsService as unknown as AgentEventsService,
|
eventsService as unknown as AgentEventsService,
|
||||||
messagesService as unknown as AgentMessagesService,
|
messagesService as unknown as AgentMessagesService
|
||||||
controlService as unknown as AgentControlService,
|
|
||||||
treeService as unknown as AgentTreeService
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,27 +100,6 @@ describe("AgentsController", () => {
|
|||||||
expect(controller).toBeDefined();
|
expect(controller).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getAgentTree", () => {
|
|
||||||
it("should return tree entries", async () => {
|
|
||||||
const entries = [
|
|
||||||
{
|
|
||||||
sessionId: "agent-1",
|
|
||||||
parentSessionId: null,
|
|
||||||
status: "running",
|
|
||||||
agentType: "worker",
|
|
||||||
taskSource: "internal",
|
|
||||||
spawnedAt: "2026-03-07T00:00:00.000Z",
|
|
||||||
completedAt: null,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
treeService.getTree.mockResolvedValue(entries);
|
|
||||||
|
|
||||||
await expect(controller.getAgentTree()).resolves.toEqual(entries);
|
|
||||||
expect(treeService.getTree).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("listAgents", () => {
|
describe("listAgents", () => {
|
||||||
it("should return empty array when no agents exist", () => {
|
it("should return empty array when no agents exist", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -421,47 +378,6 @@ describe("AgentsController", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("agent control endpoints", () => {
|
|
||||||
const agentId = "0b64079f-4487-42b9-92eb-cf8ea0042a64";
|
|
||||||
|
|
||||||
it("should inject an operator message", async () => {
|
|
||||||
const req = { apiKey: "control-key" };
|
|
||||||
|
|
||||||
const result = await controller.injectAgentMessage(
|
|
||||||
agentId,
|
|
||||||
{ message: "pause and summarize" },
|
|
||||||
req
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(controlService.injectMessage).toHaveBeenCalledWith(
|
|
||||||
agentId,
|
|
||||||
"control-key",
|
|
||||||
"pause and summarize"
|
|
||||||
);
|
|
||||||
expect(result).toEqual({ message: `Message injected into agent ${agentId}` });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should default operator id when request api key is missing", async () => {
|
|
||||||
await controller.injectAgentMessage(agentId, { message: "continue" }, {});
|
|
||||||
|
|
||||||
expect(controlService.injectMessage).toHaveBeenCalledWith(agentId, "operator", "continue");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should pause an agent", async () => {
|
|
||||||
const result = await controller.pauseAgent(agentId, {}, { apiKey: "ops-user" });
|
|
||||||
|
|
||||||
expect(controlService.pauseAgent).toHaveBeenCalledWith(agentId, "ops-user");
|
|
||||||
expect(result).toEqual({ message: `Agent ${agentId} paused` });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should resume an agent", async () => {
|
|
||||||
const result = await controller.resumeAgent(agentId, {}, { apiKey: "ops-user" });
|
|
||||||
|
|
||||||
expect(controlService.resumeAgent).toHaveBeenCalledWith(agentId, "ops-user");
|
|
||||||
expect(result).toEqual({ message: `Agent ${agentId} resumed` });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getAgentMessages", () => {
|
describe("getAgentMessages", () => {
|
||||||
it("should return paginated message history", async () => {
|
it("should return paginated message history", async () => {
|
||||||
const agentId = "0b64079f-4487-42b9-92eb-cf8ea0042a64";
|
const agentId = "0b64079f-4487-42b9-92eb-cf8ea0042a64";
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
Sse,
|
Sse,
|
||||||
MessageEvent,
|
MessageEvent,
|
||||||
Query,
|
Query,
|
||||||
Request,
|
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import type { AgentConversationMessage } from "@prisma/client";
|
import type { AgentConversationMessage } from "@prisma/client";
|
||||||
import { Throttle } from "@nestjs/throttler";
|
import { Throttle } from "@nestjs/throttler";
|
||||||
@@ -29,11 +28,6 @@ import { OrchestratorThrottlerGuard } from "../../common/guards/throttler.guard"
|
|||||||
import { AgentEventsService } from "./agent-events.service";
|
import { AgentEventsService } from "./agent-events.service";
|
||||||
import { GetMessagesQueryDto } from "./dto/get-messages-query.dto";
|
import { GetMessagesQueryDto } from "./dto/get-messages-query.dto";
|
||||||
import { AgentMessagesService } from "./agent-messages.service";
|
import { AgentMessagesService } from "./agent-messages.service";
|
||||||
import { AgentControlService } from "./agent-control.service";
|
|
||||||
import { AgentTreeService } from "./agent-tree.service";
|
|
||||||
import { AgentTreeResponseDto } from "./dto/agent-tree-response.dto";
|
|
||||||
import { InjectAgentDto } from "./dto/inject-agent.dto";
|
|
||||||
import { PauseAgentDto, ResumeAgentDto } from "./dto/control-agent.dto";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for agent management endpoints
|
* Controller for agent management endpoints
|
||||||
@@ -57,9 +51,7 @@ export class AgentsController {
|
|||||||
private readonly lifecycleService: AgentLifecycleService,
|
private readonly lifecycleService: AgentLifecycleService,
|
||||||
private readonly killswitchService: KillswitchService,
|
private readonly killswitchService: KillswitchService,
|
||||||
private readonly eventsService: AgentEventsService,
|
private readonly eventsService: AgentEventsService,
|
||||||
private readonly messagesService: AgentMessagesService,
|
private readonly messagesService: AgentMessagesService
|
||||||
private readonly agentControlService: AgentControlService,
|
|
||||||
private readonly agentTreeService: AgentTreeService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,7 +73,6 @@ export class AgentsController {
|
|||||||
// Spawn agent using spawner service
|
// Spawn agent using spawner service
|
||||||
const spawnResponse = this.spawnerService.spawnAgent({
|
const spawnResponse = this.spawnerService.spawnAgent({
|
||||||
taskId: dto.taskId,
|
taskId: dto.taskId,
|
||||||
...(dto.parentAgentId !== undefined ? { parentAgentId: dto.parentAgentId } : {}),
|
|
||||||
agentType: dto.agentType,
|
agentType: dto.agentType,
|
||||||
context: dto.context,
|
context: dto.context,
|
||||||
});
|
});
|
||||||
@@ -156,13 +147,6 @@ export class AgentsController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("tree")
|
|
||||||
@UseGuards(OrchestratorApiKeyGuard)
|
|
||||||
@Throttle({ default: { limit: 200, ttl: 60000 } })
|
|
||||||
async getAgentTree(): Promise<AgentTreeResponseDto[]> {
|
|
||||||
return this.agentTreeService.getTree();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all agents
|
* List all agents
|
||||||
* @returns Array of all agent sessions with their status
|
* @returns Array of all agent sessions with their status
|
||||||
@@ -390,57 +374,6 @@ export class AgentsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(":agentId/inject")
|
|
||||||
@Throttle({ default: { limit: 10, ttl: 60000 } })
|
|
||||||
@HttpCode(200)
|
|
||||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
||||||
async injectAgentMessage(
|
|
||||||
@Param("agentId", ParseUUIDPipe) agentId: string,
|
|
||||||
@Body() dto: InjectAgentDto,
|
|
||||||
@Request() req: { apiKey?: string }
|
|
||||||
): Promise<{ message: string }> {
|
|
||||||
const operatorId = req.apiKey ?? "operator";
|
|
||||||
await this.agentControlService.injectMessage(agentId, operatorId, dto.message);
|
|
||||||
|
|
||||||
return {
|
|
||||||
message: `Message injected into agent ${agentId}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post(":agentId/pause")
|
|
||||||
@Throttle({ default: { limit: 10, ttl: 60000 } })
|
|
||||||
@HttpCode(200)
|
|
||||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
||||||
async pauseAgent(
|
|
||||||
@Param("agentId", ParseUUIDPipe) agentId: string,
|
|
||||||
@Body() _dto: PauseAgentDto,
|
|
||||||
@Request() req: { apiKey?: string }
|
|
||||||
): Promise<{ message: string }> {
|
|
||||||
const operatorId = req.apiKey ?? "operator";
|
|
||||||
await this.agentControlService.pauseAgent(agentId, operatorId);
|
|
||||||
|
|
||||||
return {
|
|
||||||
message: `Agent ${agentId} paused`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post(":agentId/resume")
|
|
||||||
@Throttle({ default: { limit: 10, ttl: 60000 } })
|
|
||||||
@HttpCode(200)
|
|
||||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
||||||
async resumeAgent(
|
|
||||||
@Param("agentId", ParseUUIDPipe) agentId: string,
|
|
||||||
@Body() _dto: ResumeAgentDto,
|
|
||||||
@Request() req: { apiKey?: string }
|
|
||||||
): Promise<{ message: string }> {
|
|
||||||
const operatorId = req.apiKey ?? "operator";
|
|
||||||
await this.agentControlService.resumeAgent(agentId, operatorId);
|
|
||||||
|
|
||||||
return {
|
|
||||||
message: `Agent ${agentId} resumed`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kill all active agents
|
* Kill all active agents
|
||||||
* @returns Summary of kill operation
|
* @returns Summary of kill operation
|
||||||
|
|||||||
@@ -8,18 +8,10 @@ import { OrchestratorApiKeyGuard } from "../../common/guards/api-key.guard";
|
|||||||
import { AgentEventsService } from "./agent-events.service";
|
import { AgentEventsService } from "./agent-events.service";
|
||||||
import { PrismaModule } from "../../prisma/prisma.module";
|
import { PrismaModule } from "../../prisma/prisma.module";
|
||||||
import { AgentMessagesService } from "./agent-messages.service";
|
import { AgentMessagesService } from "./agent-messages.service";
|
||||||
import { AgentControlService } from "./agent-control.service";
|
|
||||||
import { AgentTreeService } from "./agent-tree.service";
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [QueueModule, SpawnerModule, KillswitchModule, ValkeyModule, PrismaModule],
|
imports: [QueueModule, SpawnerModule, KillswitchModule, ValkeyModule, PrismaModule],
|
||||||
controllers: [AgentsController],
|
controllers: [AgentsController],
|
||||||
providers: [
|
providers: [OrchestratorApiKeyGuard, AgentEventsService, AgentMessagesService],
|
||||||
OrchestratorApiKeyGuard,
|
|
||||||
AgentEventsService,
|
|
||||||
AgentMessagesService,
|
|
||||||
AgentControlService,
|
|
||||||
AgentTreeService,
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class AgentsModule {}
|
export class AgentsModule {}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
export class AgentTreeResponseDto {
|
|
||||||
sessionId!: string;
|
|
||||||
parentSessionId!: string | null;
|
|
||||||
status!: string;
|
|
||||||
agentType!: string | null;
|
|
||||||
taskSource!: string | null;
|
|
||||||
spawnedAt!: string;
|
|
||||||
completedAt!: string | null;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export class PauseAgentDto {}
|
|
||||||
|
|
||||||
export class ResumeAgentDto {}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import { IsNotEmpty, IsString } from "class-validator";
|
|
||||||
|
|
||||||
export class InjectAgentDto {
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
message!: string;
|
|
||||||
}
|
|
||||||
@@ -116,10 +116,6 @@ export class SpawnAgentDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsIn(["strict", "standard", "minimal", "custom"])
|
@IsIn(["strict", "standard", "minimal", "custom"])
|
||||||
gateProfile?: GateProfileType;
|
gateProfile?: GateProfileType;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
parentAgentId?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -115,13 +115,7 @@ export class AgentSpawnerService implements OnModuleDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void this.agentIngestionService
|
void this.agentIngestionService
|
||||||
.recordAgentSpawned(
|
.recordAgentSpawned(agentId, undefined, undefined, request.taskId, request.agentType)
|
||||||
agentId,
|
|
||||||
request.parentAgentId,
|
|
||||||
undefined,
|
|
||||||
request.taskId,
|
|
||||||
request.agentType
|
|
||||||
)
|
|
||||||
.catch((error: unknown) => {
|
.catch((error: unknown) => {
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
this.logger.error(`Failed to record spawned ingestion for ${agentId}: ${errorMessage}`);
|
this.logger.error(`Failed to record spawned ingestion for ${agentId}: ${errorMessage}`);
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ export interface SpawnAgentOptions {
|
|||||||
export interface SpawnAgentRequest {
|
export interface SpawnAgentRequest {
|
||||||
/** Unique task identifier */
|
/** Unique task identifier */
|
||||||
taskId: string;
|
taskId: string;
|
||||||
/** Optional parent session identifier for subagent lineage */
|
|
||||||
parentAgentId?: string;
|
|
||||||
/** Type of agent to spawn */
|
/** Type of agent to spawn */
|
||||||
agentType: AgentType;
|
agentType: AgentType;
|
||||||
/** Context for task execution */
|
/** Context for task execution */
|
||||||
|
|||||||
@@ -124,9 +124,9 @@ Target version: `v0.0.23`
|
|||||||
| MS23-P0-001 | done | p0-foundation | Prisma schema: AgentConversationMessage, AgentSessionTree, AgentProviderConfig, OperatorAuditLog | #693 | api | feat/ms23-p0-schema | — | MS23-P0-002,MS23-P0-003,MS23-P0-004,MS23-P0-005,MS23-P1-001 | codex | 2026-03-06 | 2026-03-06 | 15K | — | taskSource field per mosaic-queue note in PRD |
|
| MS23-P0-001 | done | p0-foundation | Prisma schema: AgentConversationMessage, AgentSessionTree, AgentProviderConfig, OperatorAuditLog | #693 | api | feat/ms23-p0-schema | — | MS23-P0-002,MS23-P0-003,MS23-P0-004,MS23-P0-005,MS23-P1-001 | codex | 2026-03-06 | 2026-03-06 | 15K | — | taskSource field per mosaic-queue note in PRD |
|
||||||
| MS23-P0-002 | done | p0-foundation | Agent message ingestion: wire spawner/lifecycle to write messages to DB | #693 | orchestrator | feat/ms23-p0-ingestion | MS23-P0-001 | MS23-P0-006 | codex | 2026-03-06 | 2026-03-07 | 20K | — | |
|
| MS23-P0-002 | done | p0-foundation | Agent message ingestion: wire spawner/lifecycle to write messages to DB | #693 | orchestrator | feat/ms23-p0-ingestion | MS23-P0-001 | MS23-P0-006 | codex | 2026-03-06 | 2026-03-07 | 20K | — | |
|
||||||
| MS23-P0-003 | done | p0-foundation | Orchestrator API: GET /agents/:id/messages + SSE stream endpoint | #693 | orchestrator | feat/ms23-p0-stream | MS23-P0-001 | MS23-P0-006 | codex | 2026-03-06 | 2026-03-07 | 20K | — | |
|
| MS23-P0-003 | done | p0-foundation | Orchestrator API: GET /agents/:id/messages + SSE stream endpoint | #693 | orchestrator | feat/ms23-p0-stream | MS23-P0-001 | MS23-P0-006 | codex | 2026-03-06 | 2026-03-07 | 20K | — | |
|
||||||
| MS23-P0-004 | done | p0-foundation | Orchestrator API: POST /agents/:id/inject + pause/resume endpoints | #693 | orchestrator | feat/ms23-p0-controls | MS23-P0-001 | MS23-P0-006 | codex | 2026-03-07 | 2026-03-07 | 15K | — | |
|
| MS23-P0-004 | in-progress | p0-foundation | Orchestrator API: POST /agents/:id/inject + pause/resume endpoints | #693 | orchestrator | feat/ms23-p0-controls | MS23-P0-001 | MS23-P0-006 | codex | 2026-03-07 | — | 15K | — | |
|
||||||
| MS23-P0-005 | done | p0-foundation | Subagent tree: parentAgentId on spawn registration + GET /agents/tree | #693 | orchestrator | feat/ms23-p0-tree | MS23-P0-001 | MS23-P0-006 | — | — | — | 15K | — | |
|
| MS23-P0-005 | not-started | p0-foundation | Subagent tree: parentAgentId on spawn registration + GET /agents/tree | #693 | orchestrator | feat/ms23-p0-tree | MS23-P0-001 | MS23-P0-006 | — | — | — | 15K | — | |
|
||||||
| MS23-P0-006 | done | p0-foundation | Unit + integration tests for all P0 orchestrator endpoints | #693 | orchestrator | test/ms23-p0 | MS23-P0-002,MS23-P0-003,MS23-P0-004,MS23-P0-005 | MS23-P1-001 | codex | 2026-03-07 | 2026-03-07 | 20K | — | Phase 0 gate: SSE stream verified via curl |
|
| MS23-P0-006 | not-started | p0-foundation | Unit + integration tests for all P0 orchestrator endpoints | #693 | orchestrator | test/ms23-p0 | MS23-P0-002,MS23-P0-003,MS23-P0-004,MS23-P0-005 | MS23-P1-001 | — | — | — | 20K | — | Phase 0 gate: SSE stream verified via curl |
|
||||||
|
|
||||||
### Phase 1 — Provider Interface (Plugin Architecture)
|
### Phase 1 — Provider Interface (Plugin Architecture)
|
||||||
|
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
// Agent message roles
|
|
||||||
export type AgentMessageRole = "user" | "assistant" | "system" | "tool";
|
|
||||||
|
|
||||||
// A single message in an agent conversation
|
|
||||||
export interface AgentMessage {
|
|
||||||
id: string;
|
|
||||||
sessionId: string;
|
|
||||||
role: AgentMessageRole;
|
|
||||||
content: string;
|
|
||||||
timestamp: Date;
|
|
||||||
metadata?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Session lifecycle status
|
|
||||||
export type AgentSessionStatus = "active" | "paused" | "completed" | "failed" | "idle";
|
|
||||||
|
|
||||||
// An agent session (conversation thread)
|
|
||||||
export interface AgentSession {
|
|
||||||
id: string;
|
|
||||||
providerId: string; // which provider owns this session
|
|
||||||
providerType: string; // "internal" | "openclaw" | etc.
|
|
||||||
label?: string;
|
|
||||||
status: AgentSessionStatus;
|
|
||||||
parentSessionId?: string; // for subagent trees
|
|
||||||
createdAt: Date;
|
|
||||||
updatedAt: Date;
|
|
||||||
metadata?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Result of listing sessions
|
|
||||||
export interface AgentSessionList {
|
|
||||||
sessions: AgentSession[];
|
|
||||||
total: number;
|
|
||||||
cursor?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Result of injecting a message
|
|
||||||
export interface InjectResult {
|
|
||||||
accepted: boolean;
|
|
||||||
messageId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The IAgentProvider interface — every provider (internal, OpenClaw, future) implements this
|
|
||||||
export interface IAgentProvider {
|
|
||||||
readonly providerId: string;
|
|
||||||
readonly providerType: string;
|
|
||||||
readonly displayName: string;
|
|
||||||
|
|
||||||
// Session management
|
|
||||||
listSessions(cursor?: string, limit?: number): Promise<AgentSessionList>;
|
|
||||||
getSession(sessionId: string): Promise<AgentSession | null>;
|
|
||||||
getMessages(sessionId: string, limit?: number, before?: string): Promise<AgentMessage[]>;
|
|
||||||
|
|
||||||
// Control operations
|
|
||||||
injectMessage(sessionId: string, content: string): Promise<InjectResult>;
|
|
||||||
pauseSession(sessionId: string): Promise<void>;
|
|
||||||
resumeSession(sessionId: string): Promise<void>;
|
|
||||||
killSession(sessionId: string, force?: boolean): Promise<void>;
|
|
||||||
|
|
||||||
// SSE streaming — returns an AsyncIterable of AgentMessage events
|
|
||||||
streamMessages(sessionId: string): AsyncIterable<AgentMessage>;
|
|
||||||
|
|
||||||
// Health
|
|
||||||
isAvailable(): Promise<boolean>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provider configuration stored in DB (AgentProviderConfig model from P0 schema)
|
|
||||||
export interface AgentProviderConfig {
|
|
||||||
id: string;
|
|
||||||
providerId: string;
|
|
||||||
providerType: string;
|
|
||||||
displayName: string;
|
|
||||||
baseUrl?: string;
|
|
||||||
apiToken?: string;
|
|
||||||
enabled: boolean;
|
|
||||||
createdAt: Date;
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
|
||||||
@@ -134,6 +134,3 @@ export * from "./widget.types";
|
|||||||
|
|
||||||
// Export WebSocket types
|
// Export WebSocket types
|
||||||
export * from "./websocket.types";
|
export * from "./websocket.types";
|
||||||
|
|
||||||
// Export agent provider types
|
|
||||||
export * from "./agent-provider.types";
|
|
||||||
|
|||||||
Reference in New Issue
Block a user