@solidxai/core 0.1.23-beta.0 → 0.1.23-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +803 -0
- package/dist/controllers/agent-config-version.controller.d.ts +29 -0
- package/dist/controllers/agent-config-version.controller.d.ts.map +1 -1
- package/dist/controllers/agent-config-version.controller.js +1 -1
- package/dist/controllers/agent-config-version.controller.js.map +1 -1
- package/dist/dtos/create-sms-template.dto.d.ts +1 -0
- package/dist/dtos/create-sms-template.dto.d.ts.map +1 -1
- package/dist/dtos/create-sms-template.dto.js +8 -1
- package/dist/dtos/create-sms-template.dto.js.map +1 -1
- package/dist/dtos/update-sms-template.dto.d.ts +1 -0
- package/dist/dtos/update-sms-template.dto.d.ts.map +1 -1
- package/dist/dtos/update-sms-template.dto.js +7 -1
- package/dist/dtos/update-sms-template.dto.js.map +1 -1
- package/dist/entities/sms-template.entity.d.ts +1 -0
- package/dist/entities/sms-template.entity.d.ts.map +1 -1
- package/dist/entities/sms-template.entity.js +6 -1
- package/dist/entities/sms-template.entity.js.map +1 -1
- package/dist/helpers/agent-general-config-comparison.d.ts +35 -0
- package/dist/helpers/agent-general-config-comparison.d.ts.map +1 -0
- package/dist/helpers/agent-general-config-comparison.js +27 -0
- package/dist/helpers/agent-general-config-comparison.js.map +1 -0
- package/dist/helpers/agent-general-config-comparison.spec.d.ts +2 -0
- package/dist/helpers/agent-general-config-comparison.spec.d.ts.map +1 -0
- package/dist/helpers/agent-general-config-comparison.spec.js +42 -0
- package/dist/helpers/agent-general-config-comparison.spec.js.map +1 -0
- package/dist/helpers/agent-tool-comparison.d.ts +40 -0
- package/dist/helpers/agent-tool-comparison.d.ts.map +1 -0
- package/dist/helpers/agent-tool-comparison.js +78 -0
- package/dist/helpers/agent-tool-comparison.js.map +1 -0
- package/dist/helpers/agent-tool-comparison.spec.d.ts +2 -0
- package/dist/helpers/agent-tool-comparison.spec.d.ts.map +1 -0
- package/dist/helpers/agent-tool-comparison.spec.js +61 -0
- package/dist/helpers/agent-tool-comparison.spec.js.map +1 -0
- package/dist/seeders/seed-data/solid-core-metadata.json +30 -0
- package/dist/services/agent-config-version-record.service.d.ts +30 -0
- package/dist/services/agent-config-version-record.service.d.ts.map +1 -1
- package/dist/services/agent-config-version-record.service.js +112 -7
- package/dist/services/agent-config-version-record.service.js.map +1 -1
- package/dist/services/agent-config-version-record.service.spec.d.ts +2 -0
- package/dist/services/agent-config-version-record.service.spec.d.ts.map +1 -0
- package/dist/services/agent-config-version-record.service.spec.js +56 -0
- package/dist/services/agent-config-version-record.service.spec.js.map +1 -0
- package/dist/services/agent-registry-deployment.spec.d.ts +2 -0
- package/dist/services/agent-registry-deployment.spec.d.ts.map +1 -0
- package/dist/services/agent-registry-deployment.spec.js +41 -0
- package/dist/services/agent-registry-deployment.spec.js.map +1 -0
- package/dist/services/agent-registry.service.d.ts.map +1 -1
- package/dist/services/agent-registry.service.js +3 -2
- package/dist/services/agent-registry.service.js.map +1 -1
- package/package.json +1 -1
- package/src/controllers/agent-config-version.controller.ts +1 -1
- package/src/dtos/create-sms-template.dto.ts +5 -0
- package/src/dtos/update-sms-template.dto.ts +5 -0
- package/src/entities/sms-template.entity.ts +2 -0
- package/src/helpers/agent-general-config-comparison.spec.ts +42 -0
- package/src/helpers/agent-general-config-comparison.ts +27 -0
- package/src/helpers/agent-tool-comparison.spec.ts +61 -0
- package/src/helpers/agent-tool-comparison.ts +71 -0
- package/src/seeders/seed-data/solid-core-metadata.json +30 -0
- package/src/services/agent-config-version-record.service.spec.ts +54 -0
- package/src/services/agent-config-version-record.service.ts +114 -9
- package/src/services/agent-registry-deployment.spec.ts +37 -0
- package/src/services/agent-registry.service.ts +5 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Lifecycle status and configVersion are deliberately excluded: activation changes
|
|
2
|
+
// them automatically, rather than changing the agent's configuration.
|
|
3
|
+
export const AGENT_GENERAL_CONFIG_FIELDS = {
|
|
4
|
+
runner: 'Runner', minProcesses: 'Minimum processes', maxProcesses: 'Maximum processes',
|
|
5
|
+
processCpu: 'Process CPU (units)', processMemory: 'Process memory (MiB)',
|
|
6
|
+
stepLimit: 'Step limit', turnStepLimit: 'Turn step limit', costLimit: 'Cost limit',
|
|
7
|
+
name: 'Name', title: 'Title', description: 'Description', iconName: 'Icon', requiredInputs: 'Required inputs',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type ConfigAudit = { fieldName: string; createdAt: Date; oldValue: unknown; newValue: unknown };
|
|
11
|
+
const scalar = (value: unknown): string | null => value === null || value === undefined || value === '' ? null : String(value);
|
|
12
|
+
|
|
13
|
+
export function compareAgentGeneralConfig(current: Record<string, unknown>, entries: ConfigAudit[], older: Date, newer: Date) {
|
|
14
|
+
const fields = Object.entries(AGENT_GENERAL_CONFIG_FIELDS).map(([key, label]) => {
|
|
15
|
+
const history = entries.filter((entry) => entry.fieldName === key);
|
|
16
|
+
const values = [older, newer].map((at) => {
|
|
17
|
+
const before = history.filter((entry) => entry.createdAt <= at);
|
|
18
|
+
return scalar(before.length ? before[before.length - 1].newValue : history.length ? history[0].oldValue : current[key]);
|
|
19
|
+
});
|
|
20
|
+
const changed = values[0] !== values[1] || history.some((entry) => entry.createdAt > older && entry.createdAt <= newer);
|
|
21
|
+
const emptyLabel = key === 'runner' ? 'Installation default'
|
|
22
|
+
: key === 'maxProcesses' ? 'Installation limit'
|
|
23
|
+
: ['processCpu', 'processMemory'].includes(key) ? 'Task definition default' : 'Not set';
|
|
24
|
+
return { key, label, status: changed ? 'changed' : 'matched', left: values[0], right: values[1], emptyLabel };
|
|
25
|
+
});
|
|
26
|
+
return { title: 'General configuration', status: fields.some((field) => field.status === 'changed') ? 'changed' : 'matched', fields };
|
|
27
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { toolFieldAt, toolLinksAt, ToolLinkAudit, ToolLinkState } from './agent-tool-comparison';
|
|
2
|
+
|
|
3
|
+
const at = (day: number) => new Date(`2026-11-${day}T12:00:00Z`);
|
|
4
|
+
const link: ToolLinkState = { id: 10, agentId: 1, toolId: 2, requiresApproval: true, createdAt: at(10) };
|
|
5
|
+
const audit = (overrides: Partial<ToolLinkAudit>): ToolLinkAudit => ({
|
|
6
|
+
messageId: 1, linkId: 10, eventType: 'audit_update', createdAt: at(15),
|
|
7
|
+
fieldName: 'requiresApproval', oldValue: 'false', newValue: 'true', ...overrides,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('toolLinksAt', () => {
|
|
11
|
+
it('resolves approval before and at the edit boundary', () => {
|
|
12
|
+
expect(toolLinksAt(1, at(14), [link], [audit({})]).get(2)?.requiresApproval).toBe(false);
|
|
13
|
+
expect(toolLinksAt(1, at(15), [link], [audit({})]).get(2)?.requiresApproval).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
it('excludes links created after a version even without audit history', () => {
|
|
16
|
+
expect(toolLinksAt(1, at(11), [{ ...link, createdAt: at(12) }], []).size).toBe(0);
|
|
17
|
+
});
|
|
18
|
+
it('restores soft and hard deleted links from complete delete messages', () => {
|
|
19
|
+
const entries = [
|
|
20
|
+
audit({ eventType: 'audit_delete', fieldName: 'agentRegistry', oldValue: '1', newValue: null }),
|
|
21
|
+
audit({ eventType: 'audit_delete', fieldName: 'agentToolRegistry', oldValue: '2', newValue: null }),
|
|
22
|
+
audit({ eventType: 'audit_delete', oldValue: 'true', newValue: null }),
|
|
23
|
+
];
|
|
24
|
+
const current = [{ ...link, deletedAt: at(15) }];
|
|
25
|
+
expect(toolLinksAt(1, at(14), current, entries).get(2)?.requiresApproval).toBe(true);
|
|
26
|
+
expect(toolLinksAt(1, at(15), current, entries).size).toBe(0);
|
|
27
|
+
expect(toolLinksAt(1, at(14), [], entries).has(2)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
it('keeps delete and re-add events on different links independent', () => {
|
|
30
|
+
const current = [{ ...link, deletedAt: at(14) }, { ...link, id: 11, createdAt: at(16), requiresApproval: false }];
|
|
31
|
+
const entries = [
|
|
32
|
+
audit({ eventType: 'audit_delete', createdAt: at(14), oldValue: 'true', newValue: null }),
|
|
33
|
+
audit({ messageId: 2, linkId: 11, eventType: 'audit_insert', createdAt: at(16), oldValue: null, newValue: 'false' }),
|
|
34
|
+
];
|
|
35
|
+
expect(toolLinksAt(1, at(13), current, entries).get(2)?.requiresApproval).toBe(true);
|
|
36
|
+
expect(toolLinksAt(1, at(15), current, entries).size).toBe(0);
|
|
37
|
+
expect(toolLinksAt(1, at(17), current, entries).get(2)?.requiresApproval).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
it('resolves tool and agent reassignments', () => {
|
|
40
|
+
const entries = [audit({ fieldName: 'agentToolRegistry', oldValue: '2', newValue: '3' }),
|
|
41
|
+
audit({ messageId: 2, createdAt: at(17), fieldName: 'agentRegistry', oldValue: '1', newValue: '4' })];
|
|
42
|
+
const current = [{ ...link, agentId: 4, toolId: 3 }];
|
|
43
|
+
expect([...toolLinksAt(1, at(14), current, entries).keys()]).toEqual([2]);
|
|
44
|
+
expect([...toolLinksAt(1, at(16), current, entries).keys()]).toEqual([3]);
|
|
45
|
+
expect(toolLinksAt(1, at(18), current, entries).size).toBe(0);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('toolFieldAt', () => {
|
|
50
|
+
const entries = [audit({ fieldName: 'sourceCode', oldValue: 'original', newValue: 'version two' }),
|
|
51
|
+
audit({ messageId: 2, createdAt: at(19), fieldName: 'sourceCode', oldValue: 'version two', newValue: 'later edit' })];
|
|
52
|
+
it('resolves historical source, ignoring edits after the selected versions', () => {
|
|
53
|
+
expect(toolFieldAt(entries, 'sourceCode', at(14), 'current')).toBe('original');
|
|
54
|
+
expect(toolFieldAt(entries, 'sourceCode', at(15), 'current')).toBe('version two');
|
|
55
|
+
expect(toolFieldAt(entries, 'sourceCode', at(20), 'current')).toBe('later edit');
|
|
56
|
+
});
|
|
57
|
+
it('falls back to current values only for fields without history', () => {
|
|
58
|
+
expect(toolFieldAt(entries, 'name', at(14), 'tool')).toBe('tool');
|
|
59
|
+
expect(toolFieldAt(entries, 'description', at(14), null)).toBe('');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type ToolLinkAudit = {
|
|
2
|
+
messageId: number; linkId: number; eventType: string; key?: string;
|
|
3
|
+
createdAt: Date; fieldName: string; oldValue: any; newValue: any;
|
|
4
|
+
};
|
|
5
|
+
export type ToolLinkState = {
|
|
6
|
+
id: number; agentId: number; toolId: number; requiresApproval: boolean;
|
|
7
|
+
createdAt: Date; deletedAt?: Date | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const positiveId = (value: unknown) => Number.isSafeInteger(Number(value)) && Number(value) > 0 ? Number(value) : undefined;
|
|
11
|
+
const flag = (value: unknown) => [true, 'true', 1, '1'].includes(value as any);
|
|
12
|
+
|
|
13
|
+
// Reverse complete messages rather than individual fields: delete/insert details
|
|
14
|
+
// describe one lifecycle event, and links can be reassigned to another tool/agent.
|
|
15
|
+
export function toolLinksAt(agentId: number, at: Date, current: ToolLinkState[], entries: ToolLinkAudit[]) {
|
|
16
|
+
const result = new Map<number, { requiresApproval: boolean }>();
|
|
17
|
+
const ids = new Set([...current.map((link) => link.id), ...entries.map((entry) => entry.linkId)]);
|
|
18
|
+
for (const id of ids) {
|
|
19
|
+
const link = current.find((item) => item.id === id);
|
|
20
|
+
const history = entries.filter((entry) => entry.linkId === id);
|
|
21
|
+
let owner = link?.agentId;
|
|
22
|
+
let tool = link?.toolId;
|
|
23
|
+
let approval = link?.requiresApproval ?? false;
|
|
24
|
+
let present = Boolean(link && (!link.deletedAt || link.deletedAt > at));
|
|
25
|
+
// Audits also retain hard-deleted links. Seed their last known identity.
|
|
26
|
+
const latest = history[history.length - 1];
|
|
27
|
+
if (!link && latest) {
|
|
28
|
+
const key = latest.key?.split(':');
|
|
29
|
+
owner = positiveId(key?.[0]); tool = positiveId(key?.[1]);
|
|
30
|
+
present = latest.eventType !== 'audit_delete';
|
|
31
|
+
for (const entry of history) {
|
|
32
|
+
const value = entry.eventType === 'audit_delete' ? entry.oldValue : entry.newValue;
|
|
33
|
+
if (entry.fieldName === 'agentRegistry') owner = positiveId(value);
|
|
34
|
+
if (entry.fieldName === 'agentToolRegistry') tool = positiveId(value);
|
|
35
|
+
if (entry.fieldName === 'requiresApproval') approval = flag(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const messages = new Map<number, ToolLinkAudit[]>();
|
|
39
|
+
for (const entry of history) messages.set(entry.messageId, [...(messages.get(entry.messageId) ?? []), entry]);
|
|
40
|
+
for (const message of [...messages.values()].reverse()) {
|
|
41
|
+
if (message[0].createdAt <= at) continue;
|
|
42
|
+
const event = message[0].eventType;
|
|
43
|
+
if (event === 'audit_insert') { present = false; continue; }
|
|
44
|
+
if (event === 'audit_delete') present = true;
|
|
45
|
+
for (const entry of message) {
|
|
46
|
+
if (entry.fieldName === 'agentRegistry') owner = positiveId(entry.oldValue);
|
|
47
|
+
if (entry.fieldName === 'agentToolRegistry') tool = positiveId(entry.oldValue);
|
|
48
|
+
if (entry.fieldName === 'agentToolKey' && typeof entry.oldValue === 'string') {
|
|
49
|
+
const key = entry.oldValue.split(':');
|
|
50
|
+
owner = positiveId(key[0]); tool = positiveId(key[1]);
|
|
51
|
+
}
|
|
52
|
+
if (entry.fieldName === 'requiresApproval') approval = flag(entry.oldValue);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (link && link.createdAt > at) present = false;
|
|
56
|
+
if (present && owner === agentId && tool) result.set(tool, { requiresApproval: approval });
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function toolFieldAt(entries: { createdAt: Date; fieldName: string; oldValue: any; newValue: any }[], field: string, at: Date, fallback: unknown): string {
|
|
62
|
+
const history = entries.filter((entry) => entry.fieldName === field);
|
|
63
|
+
const before = history.filter((entry) => entry.createdAt <= at);
|
|
64
|
+
return String((before.length ? before[before.length - 1].newValue : history.length ? history[0].oldValue : fallback) ?? '');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const TOOL_COMPARISON_FIELDS = {
|
|
68
|
+
name: 'Name', description: 'Description', type: 'Type', sourceCode: 'Source code',
|
|
69
|
+
status: 'Status', module: 'Module ID', tags: 'Tag IDs', iconName: 'Icon',
|
|
70
|
+
checksum: 'Checksum', lastLoadError: 'Last load error',
|
|
71
|
+
};
|
|
@@ -4371,6 +4371,20 @@
|
|
|
4371
4371
|
"html:HTML"
|
|
4372
4372
|
]
|
|
4373
4373
|
},
|
|
4374
|
+
{
|
|
4375
|
+
"name": "isTransactional",
|
|
4376
|
+
"displayName": "Is Transactional",
|
|
4377
|
+
"type": "boolean",
|
|
4378
|
+
"ormType": "boolean",
|
|
4379
|
+
"defaultValue": "false",
|
|
4380
|
+
"required": false,
|
|
4381
|
+
"unique": false,
|
|
4382
|
+
"index": false,
|
|
4383
|
+
"private": false,
|
|
4384
|
+
"encrypt": false,
|
|
4385
|
+
"columnName": "is_transactional",
|
|
4386
|
+
"isSystem": true
|
|
4387
|
+
},
|
|
4374
4388
|
{
|
|
4375
4389
|
"name": "smsProviderTemplateId",
|
|
4376
4390
|
"displayName": "SMS Provider Template Id",
|
|
@@ -20764,6 +20778,15 @@
|
|
|
20764
20778
|
"isSearchable": false
|
|
20765
20779
|
}
|
|
20766
20780
|
},
|
|
20781
|
+
{
|
|
20782
|
+
"type": "field",
|
|
20783
|
+
"attrs": {
|
|
20784
|
+
"name": "isTransactional",
|
|
20785
|
+
"label": "Is Transactional",
|
|
20786
|
+
"sortable": true,
|
|
20787
|
+
"isSearchable": false
|
|
20788
|
+
}
|
|
20789
|
+
},
|
|
20767
20790
|
{
|
|
20768
20791
|
"type": "field",
|
|
20769
20792
|
"attrs": {
|
|
@@ -20877,6 +20900,13 @@
|
|
|
20877
20900
|
"label": "Sms Provider Template Id"
|
|
20878
20901
|
}
|
|
20879
20902
|
},
|
|
20903
|
+
{
|
|
20904
|
+
"type": "field",
|
|
20905
|
+
"attrs": {
|
|
20906
|
+
"name": "isTransactional",
|
|
20907
|
+
"label": "Is Transactional"
|
|
20908
|
+
}
|
|
20909
|
+
},
|
|
20880
20910
|
{
|
|
20881
20911
|
"type": "field",
|
|
20882
20912
|
"attrs": {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BadRequestException, ForbiddenException, NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { AgentConfigVersionRecordService } from './agent-config-version-record.service';
|
|
3
|
+
import { ChatterMessageRepository } from '../repository/chatter-message.repository';
|
|
4
|
+
|
|
5
|
+
describe('agent tool comparison diffs', () => {
|
|
6
|
+
let service: AgentConfigVersionRecordService;
|
|
7
|
+
let row: any;
|
|
8
|
+
let query: any;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
row = { id: '7', status: 'changed', left: { label: 'Tool', summary: 'No approval required' }, right: { label: 'Tool', summary: 'Requires approval' } };
|
|
11
|
+
query = {};
|
|
12
|
+
for (const method of ['innerJoin', 'andWhere', 'select', 'addSelect', 'orderBy', 'addOrderBy']) query[method] = jest.fn(() => query);
|
|
13
|
+
query.getRawMany = jest.fn(async () => [
|
|
14
|
+
{ createdAt: new Date('2026-11-15T12:00:00Z'), fieldName: 'sourceCode', oldValue: 'original', newValue: 'updated' },
|
|
15
|
+
{ createdAt: new Date('2026-11-20T12:00:00Z'), fieldName: 'sourceCode', oldValue: 'updated', newValue: 'later edit' },
|
|
16
|
+
]);
|
|
17
|
+
service = Object.create(AgentConfigVersionRecordService.prototype);
|
|
18
|
+
Object.assign(service, { moduleRef: { get: (token: any) => token === ChatterMessageRepository
|
|
19
|
+
? { createSecurityRuleAwareQueryBuilder: async () => query }
|
|
20
|
+
: { findOne: async () => ({ id: 7, sourceCode: 'later edit', name: 'Tool' }) } } });
|
|
21
|
+
jest.spyOn(service, 'getComparison').mockImplementation(async () => ({
|
|
22
|
+
versions: { left: { createdAt: '2026-11-14T12:00:00Z' }, right: { createdAt: '2026-11-16T12:00:00Z' } },
|
|
23
|
+
sections: { tools: { rows: [row] } },
|
|
24
|
+
} as any));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('returns approval and historical source differences, excluding later edits', async () => {
|
|
28
|
+
const diff = await service.getComparisonDiff(1, 2, 3, 'tool:7');
|
|
29
|
+
expect(diff.rows).toEqual(expect.arrayContaining([
|
|
30
|
+
{ id: 'requiresApproval', title: 'Requires approval', oldValue: 'false', newValue: 'true' },
|
|
31
|
+
{ id: 'sourceCode', title: 'Source code', oldValue: 'original', newValue: 'updated' },
|
|
32
|
+
]));
|
|
33
|
+
});
|
|
34
|
+
it.each(['left', 'right'])('leaves the %s side empty when the tool is absent', async (side) => {
|
|
35
|
+
row[side] = null;
|
|
36
|
+
row.status = side === 'left' ? 'added' : 'removed';
|
|
37
|
+
const diff = await service.getComparisonDiff(1, 2, 3, 'tool:7');
|
|
38
|
+
expect(diff.rows.find((item) => item.id === 'sourceCode')[side === 'left' ? 'oldValue' : 'newValue']).toBe('');
|
|
39
|
+
});
|
|
40
|
+
it.each(['tool:8', 'tool:7'])('rejects unrelated or unchanged tools before loading content (%s)', async (key) => {
|
|
41
|
+
row.status = 'matched';
|
|
42
|
+
await expect(service.getComparisonDiff(1, 2, 3, key)).rejects.toBeInstanceOf(NotFoundException);
|
|
43
|
+
expect(query.getRawMany).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
it('preserves comparison authorization before loading tool content', async () => {
|
|
46
|
+
jest.mocked(service.getComparison).mockRejectedValue(new ForbiddenException());
|
|
47
|
+
await expect(service.getComparisonDiff(1, 2, 3, 'tool:7')).rejects.toBeInstanceOf(ForbiddenException);
|
|
48
|
+
expect(query.getRawMany).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
it.each(['tool:0', 'tool:-1', 'tool:9007199254740992', 'other:7'])('rejects invalid diff key %s', async (key) => {
|
|
51
|
+
await expect(service.getComparisonDiff(1, 2, 3, key)).rejects.toBeInstanceOf(BadRequestException);
|
|
52
|
+
expect(service.getComparison).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -6,6 +6,10 @@ import { CRUDService } from './crud.service';
|
|
|
6
6
|
import { AgentConfigVersion } from '../entities/agent-config-version.entity';
|
|
7
7
|
import { AgentConfigVersionRepository } from '../repository/agent-config-version.repository';
|
|
8
8
|
import { AgentRegistryRepository } from '../repository/agent-registry.repository';
|
|
9
|
+
import { AgentToolRepository } from '../repository/agent-tool.repository';
|
|
10
|
+
import { AgentToolRegistryRepository } from '../repository/agent-tool-registry.repository';
|
|
11
|
+
import { toolLinksAt, toolFieldAt, TOOL_COMPARISON_FIELDS, ToolLinkAudit } from '../helpers/agent-tool-comparison';
|
|
12
|
+
import { AGENT_GENERAL_CONFIG_FIELDS, compareAgentGeneralConfig } from '../helpers/agent-general-config-comparison';
|
|
9
13
|
import { AgentSkillRepository } from '../repository/agent-skill.repository';
|
|
10
14
|
import { AgentSkillRegistryRepository } from '../repository/agent-skill-registry.repository';
|
|
11
15
|
import { ChatterMessageRepository } from '../repository/chatter-message.repository';
|
|
@@ -28,7 +32,7 @@ export class AgentConfigVersionRecordService extends CRUDService<AgentConfigVers
|
|
|
28
32
|
throw new BadRequestException('Provide a positive agent ID and two different config-version IDs.');
|
|
29
33
|
}
|
|
30
34
|
const activeUser = this.moduleRef.get(RequestContextService, { strict: false }).getActiveUser();
|
|
31
|
-
const models = ['agentRegistry', 'agentConfigVersion', 'agentSkill', 'agentSkillRegistry', 'chatterMessage', 'chatterMessageDetails'];
|
|
35
|
+
const models = ['agentRegistry', 'agentConfigVersion', 'agentSkill', 'agentSkillRegistry', 'agentTool', 'agentToolRegistry', 'chatterMessage', 'chatterMessageDetails'];
|
|
32
36
|
if (!activeUser || models.some((model) => !this.crudHelperService.hasReadPermissionOnModel(activeUser, model))) {
|
|
33
37
|
throw new ForbiddenException('You do not have permission to compare these configurations.');
|
|
34
38
|
}
|
|
@@ -41,7 +45,8 @@ export class AgentConfigVersionRecordService extends CRUDService<AgentConfigVers
|
|
|
41
45
|
order: { createdAt: 'ASC', id: 'ASC' },
|
|
42
46
|
}),
|
|
43
47
|
this.moduleRef.get(AgentRegistryRepository, { strict: false }).findOne({
|
|
44
|
-
where: { id: agentId }, select: { id: true,
|
|
48
|
+
where: { id: agentId }, select: { id: true, reasoningModelKey: true, fastModelKey: true,
|
|
49
|
+
...Object.fromEntries(Object.keys(AGENT_GENERAL_CONFIG_FIELDS).map((field) => [field, true])) },
|
|
45
50
|
}),
|
|
46
51
|
]);
|
|
47
52
|
if (!agent || versions.length !== 2) {
|
|
@@ -49,19 +54,20 @@ export class AgentConfigVersionRecordService extends CRUDService<AgentConfigVers
|
|
|
49
54
|
}
|
|
50
55
|
const [older, newer] = versions;
|
|
51
56
|
|
|
52
|
-
// 3. Fetch prompt changes in the range and
|
|
53
|
-
//
|
|
57
|
+
// 3. Fetch prompt changes in the range and configuration history, oldest first.
|
|
58
|
+
// History outside the range resolves values for historical versions.
|
|
54
59
|
// Prompt values are reserved for the actual-diff endpoint.
|
|
55
60
|
const chatter = this.moduleRef.get(ChatterMessageRepository, { strict: false });
|
|
56
61
|
const query = await chatter.createSecurityRuleAwareQueryBuilder('entity');
|
|
57
|
-
const
|
|
62
|
+
const historicalFields = ['reasoningModelKey', 'fastModelKey', ...Object.keys(AGENT_GENERAL_CONFIG_FIELDS)];
|
|
63
|
+
const fields = ['systemPrompt', ...historicalFields];
|
|
58
64
|
const agentRegistryEntries = await query.innerJoin('entity.chatterMessageDetails', 'detail')
|
|
59
65
|
.andWhere('entity.messageType = :messageType', { messageType: 'audit' })
|
|
60
66
|
.andWhere('entity.coModelName = :modelName', { modelName: 'agentRegistry' })
|
|
61
67
|
.andWhere('entity.coModelEntityId = :agentId', { agentId })
|
|
62
68
|
.andWhere('detail.fieldName IN (:...fields)', { fields })
|
|
63
69
|
.andWhere(new Brackets((where) => {
|
|
64
|
-
where.where('detail.fieldName IN (:...
|
|
70
|
+
where.where('detail.fieldName IN (:...historicalFields)', { historicalFields })
|
|
65
71
|
.orWhere("detail.fieldName = 'systemPrompt' AND entity.createdAt > :start AND entity.createdAt <= :end");
|
|
66
72
|
}))
|
|
67
73
|
.setParameters({ start: LocalDateTimeTransformer.to(older.createdAt), end: LocalDateTimeTransformer.to(newer.createdAt) })
|
|
@@ -76,7 +82,7 @@ export class AgentConfigVersionRecordService extends CRUDService<AgentConfigVers
|
|
|
76
82
|
.getRawMany();
|
|
77
83
|
|
|
78
84
|
// 4. Group entries and identify whether the persona changed in the window.
|
|
79
|
-
const agentRegistryChanges
|
|
85
|
+
const agentRegistryChanges: Record<string, any[]> = Object.fromEntries(fields.map((field) => [field, []]));
|
|
80
86
|
for (const entry of agentRegistryEntries) {
|
|
81
87
|
agentRegistryChanges[entry.fieldName].push({
|
|
82
88
|
...entry,
|
|
@@ -225,6 +231,8 @@ export class AgentConfigVersionRecordService extends CRUDService<AgentConfigVers
|
|
|
225
231
|
});
|
|
226
232
|
}
|
|
227
233
|
|
|
234
|
+
const toolRows = await this.getToolComparison(agentId, older.createdAt, newer.createdAt);
|
|
235
|
+
|
|
228
236
|
// 11. Return the UI contract without loading persona or skill content.
|
|
229
237
|
const headers = versions.map((version) => ({ id: version.id, versionNumber: version.versionNumber,
|
|
230
238
|
name: version.name ?? null, description: version.description ?? null, createdAt: version.createdAt.toISOString() }));
|
|
@@ -235,21 +243,118 @@ export class AgentConfigVersionRecordService extends CRUDService<AgentConfigVers
|
|
|
235
243
|
left: { label: 'System prompt', summary: promptChanged ? 'Previous instructions' : 'No recorded changes' },
|
|
236
244
|
right: { label: 'System prompt', summary: promptChanged ? 'Updated instructions' : 'No recorded changes' } },
|
|
237
245
|
skills: { title: 'Skills', status: skillRows.some((row) => row.status !== 'matched') ? 'changed' : 'matched', rows: skillRows },
|
|
246
|
+
tools: { title: 'Tools', status: toolRows.some((row) => row.status !== 'matched') ? 'changed' : 'matched', rows: toolRows },
|
|
247
|
+
generalConfiguration: compareAgentGeneralConfig(agent as unknown as Record<string, unknown>,
|
|
248
|
+
Object.values(agentRegistryChanges).flat(), older.createdAt, newer.createdAt),
|
|
238
249
|
modelConfiguration: { title: 'Model configuration', status: groups.some((group) => group.status === 'changed') ? 'changed' : 'matched', groups },
|
|
239
250
|
},
|
|
240
251
|
};
|
|
241
252
|
}
|
|
242
253
|
|
|
254
|
+
private async getToolComparison(agentId: number, older: Date, newer: Date) {
|
|
255
|
+
const chatter = this.moduleRef.get(ChatterMessageRepository, { strict: false });
|
|
256
|
+
const links = await this.moduleRef.get(AgentToolRepository, { strict: false }).find({
|
|
257
|
+
where: { agentRegistry: { id: agentId } }, withDeleted: true,
|
|
258
|
+
relations: { agentToolRegistry: true },
|
|
259
|
+
select: { id: true, createdAt: true, deletedAt: true, requiresApproval: true, agentToolRegistry: { id: true } },
|
|
260
|
+
});
|
|
261
|
+
const currentIds = links.map((link) => link.id);
|
|
262
|
+
const query = await chatter.createSecurityRuleAwareQueryBuilder('entity');
|
|
263
|
+
query.andWhere('entity.messageType = :messageType', { messageType: 'audit' })
|
|
264
|
+
.andWhere('entity.coModelName = :modelName', { modelName: 'agentTool' });
|
|
265
|
+
// Include historical, deleted and reassigned links, plus updates without a user key.
|
|
266
|
+
const identities = query.clone().leftJoin('entity.chatterMessageDetails', 'identityDetail')
|
|
267
|
+
.select('entity.coModelEntityId').distinct(true)
|
|
268
|
+
.andWhere(new Brackets((where) => {
|
|
269
|
+
where.where('entity.modelUserKey LIKE :agentKey')
|
|
270
|
+
.orWhere("identityDetail.fieldName = 'agentToolKey' AND (identityDetail.oldValue LIKE :agentKey OR identityDetail.newValue LIKE :agentKey)")
|
|
271
|
+
.orWhere("identityDetail.fieldName = 'agentRegistry' AND (identityDetail.oldValue = :agentValue OR identityDetail.newValue = :agentValue)");
|
|
272
|
+
if (currentIds.length) where.orWhere('entity.coModelEntityId IN (:...currentIds)', { currentIds });
|
|
273
|
+
})).setParameters({ agentKey: `${agentId}:%`, agentValue: String(agentId) });
|
|
274
|
+
const raw = await query.leftJoin('entity.chatterMessageDetails', 'detail')
|
|
275
|
+
.andWhere(`entity.coModelEntityId IN (${identities.getQuery()})`).setParameters(identities.getParameters())
|
|
276
|
+
.select('entity.id', 'messageId').addSelect('entity.coModelEntityId', 'linkId')
|
|
277
|
+
.addSelect('entity.messageSubType', 'eventType').addSelect('entity.modelUserKey', 'key')
|
|
278
|
+
.addSelect('entity.createdAt', 'createdAt').addSelect('detail.fieldName', 'fieldName')
|
|
279
|
+
.addSelect('detail.oldValue', 'oldValue').addSelect('detail.newValue', 'newValue')
|
|
280
|
+
.orderBy('entity.createdAt', 'ASC').addOrderBy('entity.id', 'ASC').addOrderBy('detail.id', 'ASC').getRawMany();
|
|
281
|
+
const entries: ToolLinkAudit[] = raw.map((entry) => ({ ...entry, messageId: Number(entry.messageId), linkId: Number(entry.linkId), createdAt: LocalDateTimeTransformer.from(entry.createdAt) }));
|
|
282
|
+
const current = links.map((link) => ({ ...link, agentId, toolId: link.agentToolRegistry.id }));
|
|
283
|
+
const left = toolLinksAt(agentId, older, current, entries);
|
|
284
|
+
const right = toolLinksAt(agentId, newer, current, entries);
|
|
285
|
+
const ids = [...new Set([...left.keys(), ...right.keys()])].sort((a, b) => a - b);
|
|
286
|
+
if (!ids.length) return [];
|
|
287
|
+
const catalog = await this.moduleRef.get(AgentToolRegistryRepository, { strict: false }).find({
|
|
288
|
+
where: { id: In(ids) }, withDeleted: true, select: { id: true, name: true },
|
|
289
|
+
});
|
|
290
|
+
const catalogQuery = await chatter.createSecurityRuleAwareQueryBuilder('entity');
|
|
291
|
+
// Only names are loaded here; source and other values are fetched on demand.
|
|
292
|
+
const changes = await catalogQuery.innerJoin('entity.chatterMessageDetails', 'detail')
|
|
293
|
+
.andWhere('entity.messageType = :messageType', { messageType: 'audit' })
|
|
294
|
+
.andWhere('entity.coModelName = :modelName', { modelName: 'agentToolRegistry' })
|
|
295
|
+
.andWhere('entity.coModelEntityId IN (:...ids)', { ids })
|
|
296
|
+
.andWhere('detail.fieldName IN (:...fields)', { fields: Object.keys(TOOL_COMPARISON_FIELDS) })
|
|
297
|
+
.select('entity.coModelEntityId', 'toolId').addSelect('entity.createdAt', 'createdAt')
|
|
298
|
+
.addSelect('detail.fieldName', 'fieldName')
|
|
299
|
+
.addSelect("CASE WHEN detail.fieldName = 'name' THEN detail.oldValue ELSE NULL END", 'oldValue')
|
|
300
|
+
.addSelect("CASE WHEN detail.fieldName = 'name' THEN detail.newValue ELSE NULL END", 'newValue')
|
|
301
|
+
.orderBy('entity.createdAt', 'ASC').addOrderBy('entity.id', 'ASC').addOrderBy('detail.id', 'ASC').getRawMany();
|
|
302
|
+
for (const entry of changes) entry.createdAt = LocalDateTimeTransformer.from(entry.createdAt);
|
|
303
|
+
return ids.map((id) => {
|
|
304
|
+
const before = left.get(id), after = right.get(id);
|
|
305
|
+
const history = changes.filter((entry) => Number(entry.toolId) === id);
|
|
306
|
+
const changed = history.some((entry) => entry.createdAt > older && entry.createdAt <= newer);
|
|
307
|
+
const status = !before ? 'added' : !after ? 'removed' : changed || before.requiresApproval !== after.requiresApproval ? 'changed' : 'matched';
|
|
308
|
+
const sides = [before, after].map((link, index) => link ? {
|
|
309
|
+
label: toolFieldAt(history, 'name', index === 0 ? older : newer, catalog.find((tool) => tool.id === id)?.name) || `Tool ${id}`,
|
|
310
|
+
summary: link.requiresApproval ? 'Requires approval' : 'No approval required',
|
|
311
|
+
} : null);
|
|
312
|
+
return { id: String(id), status, diffKey: status === 'matched' ? null : `tool:${id}`, left: sides[0], right: sides[1] };
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
243
316
|
async getComparisonDiff(agentId: number, leftVersionId: number, rightVersionId: number, diffKey = 'systemPrompt') {
|
|
244
317
|
const skillId = /^skill:[1-9]\d*$/.test(diffKey) ? Number(diffKey.slice(6)) : null;
|
|
245
|
-
|
|
246
|
-
|
|
318
|
+
const toolId = /^tool:[1-9]\d*$/.test(diffKey) ? Number(diffKey.slice(5)) : null;
|
|
319
|
+
if (diffKey !== 'systemPrompt' && ![skillId, toolId].some((id) => Number.isSafeInteger(id) && id > 0)) {
|
|
320
|
+
throw new BadRequestException('Provide systemPrompt, skill:<id>, or tool:<id> as the diff key.');
|
|
247
321
|
}
|
|
248
322
|
|
|
249
323
|
// 1. Reuse the same access checks, version ownership and date ordering.
|
|
250
324
|
const comparison = await this.getComparison(agentId, leftVersionId, rightVersionId);
|
|
251
325
|
const { left, right } = comparison.versions;
|
|
252
326
|
|
|
327
|
+
if (toolId !== null) {
|
|
328
|
+
const row = comparison.sections.tools.rows.find((item) => item.id === String(toolId));
|
|
329
|
+
if (!row || row.status === 'matched') throw new NotFoundException('There are no recorded changes for this tool in the comparison.');
|
|
330
|
+
const query = await this.moduleRef.get(ChatterMessageRepository, { strict: false }).createSecurityRuleAwareQueryBuilder('entity');
|
|
331
|
+
const [rawEntries, tool] = await Promise.all([
|
|
332
|
+
query.innerJoin('entity.chatterMessageDetails', 'detail')
|
|
333
|
+
.andWhere('entity.messageType = :messageType', { messageType: 'audit' })
|
|
334
|
+
.andWhere('entity.coModelName = :modelName', { modelName: 'agentToolRegistry' })
|
|
335
|
+
.andWhere('entity.coModelEntityId = :toolId', { toolId })
|
|
336
|
+
.andWhere('detail.fieldName IN (:...fields)', { fields: Object.keys(TOOL_COMPARISON_FIELDS) })
|
|
337
|
+
.select('entity.createdAt', 'createdAt').addSelect('detail.fieldName', 'fieldName')
|
|
338
|
+
.addSelect('detail.oldValue', 'oldValue').addSelect('detail.newValue', 'newValue')
|
|
339
|
+
.orderBy('entity.createdAt', 'ASC').addOrderBy('entity.id', 'ASC').addOrderBy('detail.id', 'ASC').getRawMany(),
|
|
340
|
+
this.moduleRef.get(AgentToolRegistryRepository, { strict: false }).findOne({
|
|
341
|
+
where: { id: toolId }, withDeleted: true, relations: { module: true, tags: true },
|
|
342
|
+
}),
|
|
343
|
+
]);
|
|
344
|
+
if (!tool && !rawEntries.length) throw new NotFoundException('The historical configuration for this tool is unavailable.');
|
|
345
|
+
const entries = rawEntries.map((entry) => ({ ...entry, createdAt: LocalDateTimeTransformer.from(entry.createdAt) }));
|
|
346
|
+
const settings = [row.left, row.right].map((side) => side ? String(side.summary === 'Requires approval') : '');
|
|
347
|
+
const rows = [{ id: 'requiresApproval', title: 'Requires approval', oldValue: settings[0], newValue: settings[1] }];
|
|
348
|
+
for (const [field, title] of Object.entries(TOOL_COMPARISON_FIELDS)) {
|
|
349
|
+
const fallback = field === 'module' ? tool?.module?.id : field === 'tags' ? tool?.tags?.map((tag) => tag.id).join(', ') : tool?.[field];
|
|
350
|
+
const values = [left, right].map((version, index) => (index === 0 ? row.left : row.right)
|
|
351
|
+
? toolFieldAt(entries, field, new Date(version.createdAt), fallback) : '');
|
|
352
|
+
const changed = entries.some((entry) => entry.fieldName === field && entry.createdAt > new Date(left.createdAt) && entry.createdAt <= new Date(right.createdAt));
|
|
353
|
+
if (changed || values[0] !== values[1]) rows.push({ id: field, title, oldValue: values[0], newValue: values[1] });
|
|
354
|
+
}
|
|
355
|
+
return { diffKey, title: row.right?.label || row.left?.label || `Tool ${toolId}`, language: 'text', oldValue: '', newValue: '', rows };
|
|
356
|
+
}
|
|
357
|
+
|
|
253
358
|
if (skillId !== null) {
|
|
254
359
|
// 2. Only expose skills included in this comparison with recorded changes.
|
|
255
360
|
const row = comparison.sections.skills.rows.find((item) => item.id === String(skillId));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AgentRegistryService } from './agent-registry.service';
|
|
2
|
+
|
|
3
|
+
describe('agent deployment audit persistence', () => {
|
|
4
|
+
let service: AgentRegistryService;
|
|
5
|
+
let repository: any;
|
|
6
|
+
let draftUpdate: any;
|
|
7
|
+
let agent: any;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
agent = { id: 1, name: 'agent', status: 'active', runner: 'docker', minProcesses: 0, maxProcesses: null, processCpu: null, processMemory: null };
|
|
10
|
+
repository = { findOne: jest.fn(async () => agent), save: jest.fn(async (value) => value), update: jest.fn() };
|
|
11
|
+
const toolsQuery: any = { getRawMany: async () => [] };
|
|
12
|
+
for (const method of ['innerJoin', 'select', 'where']) toolsQuery[method] = () => toolsQuery;
|
|
13
|
+
repository.createQueryBuilder = () => toolsQuery;
|
|
14
|
+
draftUpdate = {};
|
|
15
|
+
for (const method of ['update', 'set', 'whereInIds', 'andWhere']) draftUpdate[method] = jest.fn(() => draftUpdate);
|
|
16
|
+
draftUpdate.execute = jest.fn(async () => { agent.status = 'draft'; });
|
|
17
|
+
const manager = { getRepository: () => repository, createQueryBuilder: () => draftUpdate };
|
|
18
|
+
service = Object.create(AgentRegistryService.prototype);
|
|
19
|
+
Object.assign(service, { entityManager: { transaction: (callback: any) => callback(manager) } });
|
|
20
|
+
});
|
|
21
|
+
it('saves the identified entity so subscribers receive before/after snapshots', async () => {
|
|
22
|
+
const result = await service.updateDeployment(1, { runner: 'local', processCpu: 512 });
|
|
23
|
+
expect(repository.save).toHaveBeenCalledWith(expect.objectContaining({ id: 1, runner: 'local', processCpu: 512 }));
|
|
24
|
+
expect(repository.update).not.toHaveBeenCalled();
|
|
25
|
+
expect(draftUpdate.execute).toHaveBeenCalledTimes(1);
|
|
26
|
+
expect(result.status).toBe('draft');
|
|
27
|
+
});
|
|
28
|
+
it('does not save or mark Draft for an unchanged deployment', async () => {
|
|
29
|
+
await service.updateDeployment(1, { runner: 'docker' });
|
|
30
|
+
expect(repository.save).not.toHaveBeenCalled();
|
|
31
|
+
expect(draftUpdate.execute).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
it('preserves explicit resets to installation defaults', async () => {
|
|
34
|
+
await service.updateDeployment(1, { runner: null, maxProcesses: null });
|
|
35
|
+
expect(repository.save).toHaveBeenCalledWith(expect.objectContaining({ runner: null, maxProcesses: null, minProcesses: 0 }));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -84,8 +84,11 @@ export class AgentRegistryService extends CRUDService<AgentRegistry>{
|
|
|
84
84
|
const deployment = { runner, minProcesses, maxProcesses, processCpu, processMemory };
|
|
85
85
|
const changed = agent.runner !== runner || agent.minProcesses !== minProcesses || agent.maxProcesses !== maxProcesses ||
|
|
86
86
|
agent.processCpu !== processCpu || agent.processMemory !== processMemory;
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (changed) {
|
|
88
|
+
// save() supplies the before/after entity snapshots used by Chatter audit.
|
|
89
|
+
await repository.save(Object.assign(agent, deployment));
|
|
90
|
+
await markActiveAgentsDraft(manager, [id]);
|
|
91
|
+
}
|
|
89
92
|
return repository.findOne({ where: { id } });
|
|
90
93
|
});
|
|
91
94
|
}
|