@app-vitals/agent-admin 1.41.0 → 1.43.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/package.json +2 -2
- package/prisma/client/internal/class.ts +3 -3
- package/prisma/client/internal/prismaNamespace.ts +1 -0
- package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
- package/prisma/client/models/AgentEnv.ts +36 -1
- package/prisma/migrations/20261114000000_add_agent_env_enabled/migration.sql +3 -0
- package/prisma/schema/schema.prisma +1 -0
- package/src/admin-boot.ts +7 -5
- package/src/admin-ui-github-enterprise-pages.ts +1 -1
- package/src/admin-ui-templates-pages.ts +155 -0
- package/src/admin-ui-templates-pages.unit.test.ts +54 -0
- package/src/admin-ui-templates.smoke.test.ts +292 -0
- package/src/admin-ui-templates.ts +316 -0
- package/src/admin-ui.ts +24 -0
- package/src/agent-cron-jobs.integration.test.ts +77 -0
- package/src/agent-cron-jobs.ts +66 -10
- package/src/agent-deletion.ts +2 -2
- package/src/agent-envs.integration.test.ts +108 -0
- package/src/agent-envs.ts +95 -19
- package/src/agent-plugins.integration.test.ts +52 -0
- package/src/agent-plugins.ts +51 -4
- package/src/agent-tools.integration.test.ts +55 -0
- package/src/agent-tools.ts +35 -4
- package/src/agents-api.smoke.test.ts +1 -0
- package/src/agents.ts +1 -1
|
@@ -126,4 +126,59 @@ describeOrSkip("AgentToolService (integration)", () => {
|
|
|
126
126
|
service.updatePattern(agentId, "nonexistent", "Read"),
|
|
127
127
|
).rejects.toBeInstanceOf(NotFoundError);
|
|
128
128
|
});
|
|
129
|
+
|
|
130
|
+
// ─── ATP-1.2: source / tombstones ──────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
it("add() stamps source=custom, including on a template row", async () => {
|
|
133
|
+
const agentId = await createAgent(prisma);
|
|
134
|
+
const fresh = await service.add(agentId, "Read");
|
|
135
|
+
expect(fresh.source).toBe("custom");
|
|
136
|
+
await service.addFromTemplate(agentId, "Bash");
|
|
137
|
+
const edited = await service.add(agentId, "Bash");
|
|
138
|
+
expect(edited.source).toBe("custom");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("addFromTemplate() writes source=template and keeps it on re-run", async () => {
|
|
142
|
+
const agentId = await createAgent(prisma);
|
|
143
|
+
const first = await service.addFromTemplate(agentId, "Read");
|
|
144
|
+
expect(first.source).toBe("template");
|
|
145
|
+
expect(first.enabled).toBe(true);
|
|
146
|
+
const again = await service.addFromTemplate(agentId, "Read");
|
|
147
|
+
expect(again.source).toBe("template");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("addFromTemplate() does not resurrect a tombstone or reclaim a custom row", async () => {
|
|
151
|
+
const agentId = await createAgent(prisma);
|
|
152
|
+
const t = await service.addFromTemplate(agentId, "Read");
|
|
153
|
+
await service.remove(agentId, t.id);
|
|
154
|
+
const after = await service.addFromTemplate(agentId, "Read");
|
|
155
|
+
expect(after.enabled).toBe(false);
|
|
156
|
+
expect(after.source).toBe("custom");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("toggle() and updatePattern() turn a template row custom", async () => {
|
|
160
|
+
const agentId = await createAgent(prisma);
|
|
161
|
+
const a = await service.addFromTemplate(agentId, "Read");
|
|
162
|
+
expect((await service.toggle(agentId, a.id, false)).source).toBe("custom");
|
|
163
|
+
const b = await service.addFromTemplate(agentId, "Bash");
|
|
164
|
+
const updated = await service.updatePattern(agentId, b.id, "Bash(ls)");
|
|
165
|
+
expect(updated.source).toBe("custom");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("remove() of a template row leaves a disabled custom tombstone", async () => {
|
|
169
|
+
const agentId = await createAgent(prisma);
|
|
170
|
+
const t = await service.addFromTemplate(agentId, "Read");
|
|
171
|
+
await service.remove(agentId, t.id);
|
|
172
|
+
const rows = await prisma.agentTool.findMany({ where: { agentId } });
|
|
173
|
+
expect(rows).toHaveLength(1);
|
|
174
|
+
expect(rows[0]?.enabled).toBe(false);
|
|
175
|
+
expect(rows[0]?.source).toBe("custom");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("remove() of a custom row deletes it", async () => {
|
|
179
|
+
const agentId = await createAgent(prisma);
|
|
180
|
+
const t = await service.add(agentId, "Read");
|
|
181
|
+
await service.remove(agentId, t.id);
|
|
182
|
+
expect(await prisma.agentTool.findMany({ where: { agentId } })).toEqual([]);
|
|
183
|
+
});
|
|
129
184
|
});
|
package/src/agent-tools.ts
CHANGED
|
@@ -41,8 +41,30 @@ export class AgentToolService {
|
|
|
41
41
|
): Promise<AgentTool> {
|
|
42
42
|
return client.agentTool.upsert({
|
|
43
43
|
where: { agentId_pattern: { agentId, pattern } },
|
|
44
|
-
create: { agentId, pattern, enabled: true },
|
|
45
|
-
update: { enabled: true },
|
|
44
|
+
create: { agentId, pattern, enabled: true, source: "custom" },
|
|
45
|
+
update: { enabled: true, source: "custom" },
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Internal reconcile write path (ATP-1.2); never exposed over HTTP.
|
|
51
|
+
* Creates a template-sourced pattern, or refreshes one that is still
|
|
52
|
+
* template-owned. A custom row (user edit or tombstone) is returned
|
|
53
|
+
* untouched so a reconcile neither overrides nor resurrects it.
|
|
54
|
+
*/
|
|
55
|
+
async addFromTemplate(
|
|
56
|
+
agentId: string,
|
|
57
|
+
pattern: string,
|
|
58
|
+
client: PrismaTransactionClient = this.prisma,
|
|
59
|
+
): Promise<AgentTool> {
|
|
60
|
+
const existing = await client.agentTool.findUnique({
|
|
61
|
+
where: { agentId_pattern: { agentId, pattern } },
|
|
62
|
+
});
|
|
63
|
+
if (existing?.source === "custom") return existing;
|
|
64
|
+
return client.agentTool.upsert({
|
|
65
|
+
where: { agentId_pattern: { agentId, pattern } },
|
|
66
|
+
create: { agentId, pattern, enabled: true, source: "template" },
|
|
67
|
+
update: { enabled: true, source: "template" },
|
|
46
68
|
});
|
|
47
69
|
}
|
|
48
70
|
|
|
@@ -59,6 +81,15 @@ export class AgentToolService {
|
|
|
59
81
|
throw new NotFoundError(`tool ${toolId} not found`);
|
|
60
82
|
}
|
|
61
83
|
|
|
84
|
+
// ATP-1.2: deleting a template row writes a tombstone so a later
|
|
85
|
+
// reconcile does not re-add it.
|
|
86
|
+
if (existing.source === "template") {
|
|
87
|
+
await this.prisma.agentTool.update({
|
|
88
|
+
where: { id: toolId },
|
|
89
|
+
data: { enabled: false, source: "custom" },
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
62
93
|
await this.prisma.agentTool.delete({ where: { id: toolId } });
|
|
63
94
|
}
|
|
64
95
|
|
|
@@ -81,7 +112,7 @@ export class AgentToolService {
|
|
|
81
112
|
|
|
82
113
|
return this.prisma.agentTool.update({
|
|
83
114
|
where: { id: toolId },
|
|
84
|
-
data: { enabled },
|
|
115
|
+
data: { enabled, source: "custom" },
|
|
85
116
|
});
|
|
86
117
|
}
|
|
87
118
|
|
|
@@ -105,7 +136,7 @@ export class AgentToolService {
|
|
|
105
136
|
|
|
106
137
|
return this.prisma.agentTool.update({
|
|
107
138
|
where: { id: toolId },
|
|
108
|
-
data: { pattern },
|
|
139
|
+
data: { pattern, source: "custom" },
|
|
109
140
|
});
|
|
110
141
|
}
|
|
111
142
|
}
|
|
@@ -5778,6 +5778,7 @@ describe("admin API — Anthropic credential guards (WIF-2.1)", () => {
|
|
|
5778
5778
|
findUnique: async () => ({ id: AGENT_ID, selfHosted: opts.selfHosted }),
|
|
5779
5779
|
},
|
|
5780
5780
|
agentEnv: {
|
|
5781
|
+
updateMany: async () => ({ count: 0 }),
|
|
5781
5782
|
deleteMany: async () => ({ count: 0 }),
|
|
5782
5783
|
create: async ({ data }: { data: { key: string } }) => {
|
|
5783
5784
|
writes.push(data.key);
|
package/src/agents.ts
CHANGED
|
@@ -441,7 +441,7 @@ export class AgentService {
|
|
|
441
441
|
|
|
442
442
|
// Key names only — never select/decrypt AgentEnv.value here.
|
|
443
443
|
const presentEnvRows = await client.agentEnv.findMany({
|
|
444
|
-
where: { agentId },
|
|
444
|
+
where: { agentId, enabled: true },
|
|
445
445
|
select: { key: true },
|
|
446
446
|
});
|
|
447
447
|
const presentKeys = new Set(presentEnvRows.map((r) => r.key));
|