@solidxai/core 0.1.19-beta.5 → 0.1.20-beta.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/CHANGELOG.md +73 -0
- package/dist/controllers/agent-hub-tag.controller.d.ts +24 -0
- package/dist/controllers/agent-hub-tag.controller.d.ts.map +1 -0
- package/dist/controllers/agent-hub-tag.controller.js +175 -0
- package/dist/controllers/agent-hub-tag.controller.js.map +1 -0
- package/dist/controllers/agent-tool-registry.controller.d.ts +18 -0
- package/dist/controllers/agent-tool-registry.controller.d.ts.map +1 -1
- package/dist/controllers/agent-tool-registry.controller.js +13 -0
- package/dist/controllers/agent-tool-registry.controller.js.map +1 -1
- package/dist/dtos/create-agent-hub-tag.dto.d.ts +16 -0
- package/dist/dtos/create-agent-hub-tag.dto.d.ts.map +1 -0
- package/dist/dtos/create-agent-hub-tag.dto.js +98 -0
- package/dist/dtos/create-agent-hub-tag.dto.js.map +1 -0
- package/dist/dtos/create-agent-registry.dto.d.ts +4 -0
- package/dist/dtos/create-agent-registry.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-registry.dto.js +24 -1
- package/dist/dtos/create-agent-registry.dto.js.map +1 -1
- package/dist/dtos/create-agent-skill-registry.dto.d.ts +4 -1
- package/dist/dtos/create-agent-skill-registry.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-skill-registry.dto.js +21 -5
- package/dist/dtos/create-agent-skill-registry.dto.js.map +1 -1
- package/dist/dtos/create-agent-tool-registry.dto.d.ts +4 -1
- package/dist/dtos/create-agent-tool-registry.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-tool-registry.dto.js +24 -8
- package/dist/dtos/create-agent-tool-registry.dto.js.map +1 -1
- package/dist/dtos/update-agent-hub-tag.dto.d.ts +17 -0
- package/dist/dtos/update-agent-hub-tag.dto.d.ts.map +1 -0
- package/dist/dtos/update-agent-hub-tag.dto.js +104 -0
- package/dist/dtos/update-agent-hub-tag.dto.js.map +1 -0
- package/dist/dtos/update-agent-registry.dto.d.ts +4 -0
- package/dist/dtos/update-agent-registry.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-registry.dto.js +24 -1
- package/dist/dtos/update-agent-registry.dto.js.map +1 -1
- package/dist/dtos/update-agent-skill-registry.dto.d.ts +4 -1
- package/dist/dtos/update-agent-skill-registry.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-skill-registry.dto.js +20 -4
- package/dist/dtos/update-agent-skill-registry.dto.js.map +1 -1
- package/dist/dtos/update-agent-tool-registry.dto.d.ts +4 -1
- package/dist/dtos/update-agent-tool-registry.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-tool-registry.dto.js +24 -8
- package/dist/dtos/update-agent-tool-registry.dto.js.map +1 -1
- package/dist/entities/agent-hub-tag.entity.d.ts +11 -0
- package/dist/entities/agent-hub-tag.entity.d.ts.map +1 -0
- package/dist/entities/agent-hub-tag.entity.js +45 -0
- package/dist/entities/agent-hub-tag.entity.js.map +1 -0
- package/dist/entities/agent-registry.entity.d.ts +2 -0
- package/dist/entities/agent-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-registry.entity.js +7 -1
- package/dist/entities/agent-registry.entity.js.map +1 -1
- package/dist/entities/agent-skill-registry.entity.d.ts +2 -1
- package/dist/entities/agent-skill-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-skill-registry.entity.js +5 -4
- package/dist/entities/agent-skill-registry.entity.js.map +1 -1
- package/dist/entities/agent-tool-registry.entity.d.ts +2 -1
- package/dist/entities/agent-tool-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-tool-registry.entity.js +7 -6
- package/dist/entities/agent-tool-registry.entity.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/repository/agent-hub-tag.repository.d.ts +12 -0
- package/dist/repository/agent-hub-tag.repository.d.ts.map +1 -0
- package/dist/repository/agent-hub-tag.repository.js +39 -0
- package/dist/repository/agent-hub-tag.repository.js.map +1 -0
- package/dist/seeders/seed-data/solid-core-metadata.json +344 -30
- package/dist/services/agent-hub-tag.service.d.ts +12 -0
- package/dist/services/agent-hub-tag.service.d.ts.map +1 -0
- package/dist/services/agent-hub-tag.service.js +38 -0
- package/dist/services/agent-hub-tag.service.js.map +1 -0
- package/dist/services/agent-tool-registry.service.d.ts +23 -1
- package/dist/services/agent-tool-registry.service.d.ts.map +1 -1
- package/dist/services/agent-tool-registry.service.js +168 -4
- package/dist/services/agent-tool-registry.service.js.map +1 -1
- package/dist/services/agent-tool-registry.service.spec.js +1 -1
- package/dist/services/agent-tool-registry.service.spec.js.map +1 -1
- package/dist/services/secret.service.d.ts +1 -0
- package/dist/services/secret.service.d.ts.map +1 -1
- package/dist/services/secret.service.js +10 -0
- package/dist/services/secret.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +8 -0
- package/dist/solid-core.module.js.map +1 -1
- package/package.json +1 -1
- package/src/controllers/agent-hub-tag.controller.ts +86 -0
- package/src/controllers/agent-tool-registry.controller.ts +6 -0
- package/src/dtos/create-agent-hub-tag.dto.ts +70 -0
- package/src/dtos/create-agent-registry.dto.ts +20 -0
- package/src/dtos/create-agent-skill-registry.dto.ts +19 -4
- package/src/dtos/create-agent-tool-registry.dto.ts +21 -6
- package/src/dtos/update-agent-hub-tag.dto.ts +75 -0
- package/src/dtos/update-agent-registry.dto.ts +20 -0
- package/src/dtos/update-agent-skill-registry.dto.ts +17 -3
- package/src/dtos/update-agent-tool-registry.dto.ts +20 -6
- package/src/entities/agent-hub-tag.entity.ts +21 -0
- package/src/entities/agent-registry.entity.ts +6 -1
- package/src/entities/agent-skill-registry.entity.ts +5 -3
- package/src/entities/agent-tool-registry.entity.ts +6 -4
- package/src/index.ts +6 -0
- package/src/repository/agent-hub-tag.repository.ts +19 -0
- package/src/seeders/seed-data/solid-core-metadata.json +344 -30
- package/src/services/agent-hub-tag.service.ts +19 -0
- package/src/services/agent-tool-registry.service.spec.ts +1 -1
- package/src/services/agent-tool-registry.service.ts +161 -1
- package/src/services/secret.service.ts +10 -0
- package/src/solid-core.module.ts +8 -0
|
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var AgentToolRegistryService_1;
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
16
|
exports.AgentToolRegistryService = void 0;
|
|
16
17
|
const common_1 = require("@nestjs/common");
|
|
@@ -18,15 +19,22 @@ const typeorm_1 = require("@nestjs/typeorm");
|
|
|
18
19
|
const core_1 = require("@nestjs/core");
|
|
19
20
|
const typeorm_2 = require("typeorm");
|
|
20
21
|
const node_crypto_1 = require("node:crypto");
|
|
22
|
+
const node_child_process_1 = require("node:child_process");
|
|
23
|
+
const node_fs_1 = require("node:fs");
|
|
24
|
+
const node_os_1 = require("node:os");
|
|
25
|
+
const node_path_1 = require("node:path");
|
|
26
|
+
const secret_service_1 = require("./secret.service");
|
|
21
27
|
const agent_tool_entity_1 = require("../entities/agent-tool.entity");
|
|
22
28
|
const agent_config_version_service_1 = require("./agent-config-version.service");
|
|
23
29
|
const agent_tool_registry_repository_1 = require("../repository/agent-tool-registry.repository");
|
|
24
|
-
let AgentToolRegistryService = class AgentToolRegistryService extends agent_config_version_service_1.AgentConfigCatalogService {
|
|
25
|
-
constructor(entityManager, repo, moduleRef) {
|
|
30
|
+
let AgentToolRegistryService = AgentToolRegistryService_1 = class AgentToolRegistryService extends agent_config_version_service_1.AgentConfigCatalogService {
|
|
31
|
+
constructor(entityManager, repo, moduleRef, secretService) {
|
|
26
32
|
super(entityManager, repo, 'agentToolRegistry', moduleRef, agent_tool_entity_1.AgentTool, 'agentToolRegistry');
|
|
27
33
|
this.entityManager = entityManager;
|
|
28
34
|
this.repo = repo;
|
|
29
35
|
this.moduleRef = moduleRef;
|
|
36
|
+
this.secretService = secretService;
|
|
37
|
+
this.logger = new common_1.Logger(AgentToolRegistryService_1.name);
|
|
30
38
|
}
|
|
31
39
|
withChecksum(dto, existing) {
|
|
32
40
|
if (!['custom', 'thirdparty'].includes(dto.type ?? existing?.type))
|
|
@@ -39,6 +47,161 @@ let AgentToolRegistryService = class AgentToolRegistryService extends agent_conf
|
|
|
39
47
|
checksum: (0, node_crypto_1.createHash)('sha256').update(sourceCode, 'utf8').digest('hex'),
|
|
40
48
|
};
|
|
41
49
|
}
|
|
50
|
+
lifecycleRunner() {
|
|
51
|
+
const binary = process.platform === 'win32' ? 'python.exe' : 'python';
|
|
52
|
+
const configuredSourceRoot = process.env.SOLIDX_AGENTHUB_RUNTIME_PATH;
|
|
53
|
+
const sourceRoot = configuredSourceRoot
|
|
54
|
+
&& (0, node_fs_1.existsSync)((0, node_path_1.join)(configuredSourceRoot, 'src', 'agenthub', 'tools', 'tool_lifecycle_check.py'))
|
|
55
|
+
? configuredSourceRoot
|
|
56
|
+
: undefined;
|
|
57
|
+
const candidates = [
|
|
58
|
+
{ root: (0, node_path_1.join)((0, node_os_1.homedir)(), '.solidx', 'agenthub-venv'), sourceRoot },
|
|
59
|
+
...(process.env.SOLIDX_AGENTHUB_RUNTIME_PATH
|
|
60
|
+
? [{ root: (0, node_path_1.join)(process.env.SOLIDX_AGENTHUB_RUNTIME_PATH, '.venv'), sourceRoot }]
|
|
61
|
+
: []),
|
|
62
|
+
];
|
|
63
|
+
for (const candidate of candidates) {
|
|
64
|
+
const python = (0, node_path_1.join)(candidate.root, process.platform === 'win32' ? 'Scripts' : 'bin', binary);
|
|
65
|
+
if ((0, node_fs_1.existsSync)(python))
|
|
66
|
+
return { python, runtimeRoot: candidate.root, sourceRoot: candidate.sourceRoot };
|
|
67
|
+
}
|
|
68
|
+
throw new common_1.ServiceUnavailableException('AgentHub runtime virtual environment was not found.');
|
|
69
|
+
}
|
|
70
|
+
lifecycleDatabaseUrl() {
|
|
71
|
+
const options = this.entityManager.connection.options;
|
|
72
|
+
if (options.type !== 'postgres') {
|
|
73
|
+
throw new common_1.ServiceUnavailableException('Tool checks require Core to use PostgreSQL.');
|
|
74
|
+
}
|
|
75
|
+
if (options.url)
|
|
76
|
+
return options.url;
|
|
77
|
+
const host = String(options.host ?? 'localhost');
|
|
78
|
+
const formattedHost = host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;
|
|
79
|
+
const credentials = options.username
|
|
80
|
+
? `${encodeURIComponent(String(options.username))}:${encodeURIComponent(String(options.password ?? ''))}@`
|
|
81
|
+
: '';
|
|
82
|
+
const ssl = options.ssl ? '?sslmode=require' : '';
|
|
83
|
+
return `postgresql://${credentials}${formattedHost}:${options.port ?? 5432}/${encodeURIComponent(String(options.database))}${ssl}`;
|
|
84
|
+
}
|
|
85
|
+
async runLifecycleScript(request) {
|
|
86
|
+
const runner = this.lifecycleRunner();
|
|
87
|
+
const requestJson = JSON.stringify(request);
|
|
88
|
+
const childEnv = {
|
|
89
|
+
PATH: process.env.PATH ?? '',
|
|
90
|
+
VIRTUAL_ENV: runner.runtimeRoot,
|
|
91
|
+
HOME: (0, node_os_1.homedir)(),
|
|
92
|
+
DATABASE_URL: this.lifecycleDatabaseUrl(),
|
|
93
|
+
...(process.env.SYSTEMROOT ? { SYSTEMROOT: process.env.SYSTEMROOT } : {}),
|
|
94
|
+
...(runner.sourceRoot ? { PYTHONPATH: (0, node_path_1.join)(runner.sourceRoot, 'src') } : {}),
|
|
95
|
+
};
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
const child = (0, node_child_process_1.spawn)(runner.python, ['-m', 'agenthub.tools.tool_lifecycle_check'], {
|
|
98
|
+
cwd: runner.sourceRoot ?? (0, node_os_1.tmpdir)(),
|
|
99
|
+
env: childEnv,
|
|
100
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
101
|
+
});
|
|
102
|
+
let stdout = '';
|
|
103
|
+
let stderr = '';
|
|
104
|
+
let settled = false;
|
|
105
|
+
const finish = (callback) => {
|
|
106
|
+
if (settled)
|
|
107
|
+
return;
|
|
108
|
+
settled = true;
|
|
109
|
+
clearTimeout(timeout);
|
|
110
|
+
callback();
|
|
111
|
+
};
|
|
112
|
+
const timeout = setTimeout(() => {
|
|
113
|
+
child.kill('SIGKILL');
|
|
114
|
+
finish(() => reject(new common_1.ServiceUnavailableException('Tool check exceeded the 20 second limit.')));
|
|
115
|
+
}, 20_000);
|
|
116
|
+
child.stdout.setEncoding('utf8');
|
|
117
|
+
child.stderr.setEncoding('utf8');
|
|
118
|
+
child.stdout.on('data', (chunk) => {
|
|
119
|
+
stdout += chunk;
|
|
120
|
+
if (stdout.length > 2_000_000)
|
|
121
|
+
child.kill('SIGKILL');
|
|
122
|
+
});
|
|
123
|
+
child.stderr.on('data', (chunk) => {
|
|
124
|
+
if (stderr.length < 2_000_000)
|
|
125
|
+
stderr += chunk.slice(0, 2_000_000 - stderr.length);
|
|
126
|
+
});
|
|
127
|
+
child.on('error', (error) => finish(() => reject(new common_1.ServiceUnavailableException(`Could not start AgentHub tool checker: ${error.message}`))));
|
|
128
|
+
child.on('close', (code) => finish(() => {
|
|
129
|
+
if (stdout.length > 2_000_000) {
|
|
130
|
+
reject(new common_1.BadRequestException('Tool check response was too large.'));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const result = JSON.parse(stdout.trim());
|
|
135
|
+
if (!result || typeof result !== 'object' || Array.isArray(result))
|
|
136
|
+
throw new Error('Invalid response');
|
|
137
|
+
resolve(result);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
reject(new common_1.ServiceUnavailableException(`AgentHub tool checker returned an invalid response${code === 0 ? '' : ` (exit ${code})`}. ${stderr.slice(0, 500)}`));
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
child.stdin.end(requestJson);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async readToolConfig(tool, checksum) {
|
|
147
|
+
const result = await this.runLifecycleScript({ tool_id: tool.id, checksum, phase: 'config' });
|
|
148
|
+
const requiredSecrets = result.required_secrets;
|
|
149
|
+
if (result.success !== true || !Array.isArray(requiredSecrets)
|
|
150
|
+
|| requiredSecrets.some((key) => typeof key !== 'string' || !key.trim())
|
|
151
|
+
|| new Set(requiredSecrets).size !== requiredSecrets.length) {
|
|
152
|
+
return { success: false, message: String(result.message ?? 'The tool returned an invalid configuration.'), requiredSecrets: [] };
|
|
153
|
+
}
|
|
154
|
+
return { success: true, message: String(result.message ?? 'Configuration declaration checked.'), requiredSecrets };
|
|
155
|
+
}
|
|
156
|
+
async checkTool(id, phase, checksum) {
|
|
157
|
+
if (phase !== 'config' && phase !== 'init')
|
|
158
|
+
throw new common_1.BadRequestException('Phase must be config or init.');
|
|
159
|
+
const tool = await this.repo.findOne({ where: { id } });
|
|
160
|
+
if (!tool)
|
|
161
|
+
throw new common_1.NotFoundException(`Tool ${id} was not found.`);
|
|
162
|
+
if (!['custom', 'thirdparty'].includes(tool.type))
|
|
163
|
+
throw new common_1.BadRequestException('Only custom and third-party tools can be checked.');
|
|
164
|
+
const currentChecksum = (0, node_crypto_1.createHash)('sha256').update(tool.sourceCode ?? '', 'utf8').digest('hex');
|
|
165
|
+
if (!checksum || checksum !== currentChecksum)
|
|
166
|
+
throw new common_1.ConflictException('Tool source changed. Save the tool again before running checks.');
|
|
167
|
+
const config = await this.readToolConfig(tool, currentChecksum);
|
|
168
|
+
if (!config.success) {
|
|
169
|
+
return {
|
|
170
|
+
toolId: id, checksum, phase,
|
|
171
|
+
config: { status: 'failed', message: config.message, requiredSecrets: [], missingSecrets: [] },
|
|
172
|
+
init: { status: 'skipped', message: 'Configuration must pass before initialization can run.' },
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const resolvedSecrets = phase === 'init'
|
|
176
|
+
? await this.secretService.resolveAvailable(config.requiredSecrets)
|
|
177
|
+
: undefined;
|
|
178
|
+
const available = phase === 'config'
|
|
179
|
+
? await this.secretService.findAvailableKeys(config.requiredSecrets)
|
|
180
|
+
: Object.keys(resolvedSecrets ?? {});
|
|
181
|
+
const missingSecrets = config.requiredSecrets.filter((key) => !available.includes(key));
|
|
182
|
+
const configStep = {
|
|
183
|
+
status: missingSecrets.length ? 'failed' : 'passed',
|
|
184
|
+
message: missingSecrets.length ? 'Configure all required active secrets before initializing this tool.' : config.message,
|
|
185
|
+
requiredSecrets: config.requiredSecrets,
|
|
186
|
+
missingSecrets,
|
|
187
|
+
};
|
|
188
|
+
if (missingSecrets.length || phase === 'config') {
|
|
189
|
+
return {
|
|
190
|
+
toolId: id, checksum, phase, config: configStep,
|
|
191
|
+
init: { status: 'skipped', message: missingSecrets.length ? 'Required secrets must be configured first.' : 'Run initialization after configuration passes.' },
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const secretValues = Object.fromEntries(Object.entries(resolvedSecrets ?? {}).map(([key, value]) => [
|
|
195
|
+
key, typeof value === 'string' ? value : JSON.stringify(value),
|
|
196
|
+
]));
|
|
197
|
+
const init = await this.runLifecycleScript({
|
|
198
|
+
tool_id: id, checksum, phase: 'init', secret_values: secretValues,
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
toolId: id, checksum, phase, config: configStep,
|
|
202
|
+
init: { status: init.success === true ? 'passed' : 'failed', message: String(init.message ?? (init.success ? 'Initialization check passed.' : 'Initialization check failed.')) },
|
|
203
|
+
};
|
|
204
|
+
}
|
|
42
205
|
async create(createDto, files = [], solidRequestContext = {}) {
|
|
43
206
|
return super.create(this.withChecksum({ ...createDto, status: 'inactive', lastLoadError: null }), files, solidRequestContext);
|
|
44
207
|
}
|
|
@@ -63,11 +226,12 @@ let AgentToolRegistryService = class AgentToolRegistryService extends agent_conf
|
|
|
63
226
|
}
|
|
64
227
|
};
|
|
65
228
|
exports.AgentToolRegistryService = AgentToolRegistryService;
|
|
66
|
-
exports.AgentToolRegistryService = AgentToolRegistryService = __decorate([
|
|
229
|
+
exports.AgentToolRegistryService = AgentToolRegistryService = AgentToolRegistryService_1 = __decorate([
|
|
67
230
|
(0, common_1.Injectable)(),
|
|
68
231
|
__param(0, (0, typeorm_1.InjectEntityManager)("default")),
|
|
69
232
|
__metadata("design:paramtypes", [typeorm_2.EntityManager,
|
|
70
233
|
agent_tool_registry_repository_1.AgentToolRegistryRepository,
|
|
71
|
-
core_1.ModuleRef
|
|
234
|
+
core_1.ModuleRef,
|
|
235
|
+
secret_service_1.SecretService])
|
|
72
236
|
], AgentToolRegistryService);
|
|
73
237
|
//# sourceMappingURL=agent-tool-registry.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-tool-registry.service.js","sourceRoot":"","sources":["../../src/services/agent-tool-registry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA+D;AAC/D,6CAAsD;AACtD,uCAAyC;AACzC,qCAAwC;AACxC,6CAAyC;AACzC,qEAA0D;AAC1D,iFAA2E;AAE3E,iGAA2F;AAKpF,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,wDAA4C;IACxF,YAEW,aAA4B,EAC5B,IAAiC,EACjC,SAAoB;QAE9B,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,mBAAmB,EAAE,SAAS,EAAE,6BAAS,EAAE,mBAAmB,CAAC,CAAC;QAJjF,kBAAa,GAAb,aAAa,CAAe;QAC5B,SAAI,GAAJ,IAAI,CAA6B;QACjC,cAAS,GAAT,SAAS,CAAW;IAGhC,CAAC;IAEQ,YAAY,CAAsE,GAAM,EAAE,QAA4B;QAC5H,IAAI,CAAC,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,QAAQ,EAAE,IAAI,CAAC;YAAE,OAAO,GAAG,CAAC;QAE/E,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,QAAQ,EAAE,UAAU,CAAC;QAC1D,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C;CAGF,CAAA;AA1DY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAA;qCACP,uBAAa;QACtB,4DAA2B;QACtB,gBAAS;GALpB,wBAAwB,CA0DpC","sourcesContent":["import { ConflictException, Injectable } from '@nestjs/common';\nimport { InjectEntityManager } from '@nestjs/typeorm';\nimport { ModuleRef } from '@nestjs/core';\nimport { EntityManager } from 'typeorm';\nimport { createHash } from 'node:crypto';\nimport { AgentTool } from '../entities/agent-tool.entity';\nimport { AgentConfigCatalogService } from './agent-config-version.service';\nimport { AgentToolRegistry } from '../entities/agent-tool-registry.entity';\nimport { AgentToolRegistryRepository } from '../repository/agent-tool-registry.repository';\nimport { CreateAgentToolRegistryDto } from '../dtos/create-agent-tool-registry.dto';\nimport { UpdateAgentToolRegistryDto } from '../dtos/update-agent-tool-registry.dto';\n\n@Injectable()\nexport class AgentToolRegistryService extends AgentConfigCatalogService<AgentToolRegistry>{\n constructor(\n @InjectEntityManager(\"default\")\n readonly entityManager: EntityManager,\n readonly repo: AgentToolRegistryRepository,\n readonly moduleRef: ModuleRef,\n ) {\n super(entityManager, repo, 'agentToolRegistry', moduleRef, AgentTool, 'agentToolRegistry');\n }\n\n private withChecksum<T extends { type?: string; sourceCode?: string; checksum?: string }>(dto: T, existing?: AgentToolRegistry): T {\n if (!['custom', 'thirdparty'].includes(dto.type ?? existing?.type)) return dto;\n\n const sourceCode = dto.sourceCode ?? existing?.sourceCode;\n if (typeof sourceCode !== 'string') return dto;\n\n return {\n ...dto,\n checksum: createHash('sha256').update(sourceCode, 'utf8').digest('hex'),\n };\n }\n\n override async create(createDto: CreateAgentToolRegistryDto, files: Express.Multer.File[] = [], solidRequestContext: any = {}): Promise<AgentToolRegistry> {\n return super.create(this.withChecksum({ ...createDto, status: 'inactive', lastLoadError: null }), files, solidRequestContext);\n }\n\n override async createMany(createDtos: CreateAgentToolRegistryDto[], solidRequestContext: any = {}): Promise<AgentToolRegistry[]> {\n return super.createMany(createDtos.map((dto) => this.withChecksum({ ...dto, status: 'inactive', lastLoadError: null })), solidRequestContext);\n }\n\n override async insertMany(createDtos: CreateAgentToolRegistryDto[], filesArray: Express.Multer.File[][] = [], solidRequestContext: any = {}): Promise<AgentToolRegistry[]> {\n return super.insertMany(createDtos.map((dto) => this.withChecksum({ ...dto, status: 'inactive', lastLoadError: null })), filesArray, solidRequestContext);\n }\n\n override async update(\n id: number,\n updateDto: UpdateAgentToolRegistryDto,\n files: Express.Multer.File[] = [],\n isPartialUpdate = false,\n solidRequestContext: any = {},\n isUpdate = false,\n ): Promise<AgentToolRegistry> {\n const existing = await this.repo.findOne({ where: { id } });\n const changed = existing && ['sourceCode', 'name', 'type'].some(\n (key) => updateDto[key] !== undefined && updateDto[key] !== existing[key],\n );\n if (!changed && updateDto.status === 'active' && existing?.status !== 'active'\n && existing && ['custom', 'thirdparty'].includes(existing.type)) {\n const checkedChecksum = createHash('sha256').update(existing.sourceCode ?? '', 'utf8').digest('hex');\n if (updateDto.checksum !== checkedChecksum) {\n throw new ConflictException('Tool source changed after checks. Run configuration and initialization again.');\n }\n }\n const dto = changed ? { ...updateDto, status: 'inactive', lastLoadError: null } : updateDto;\n return super.update(id, this.withChecksum(dto, existing ?? undefined), files, isPartialUpdate, solidRequestContext, isUpdate);\n }\n\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-tool-registry.service.js","sourceRoot":"","sources":["../../src/services/agent-tool-registry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4I;AAC5I,6CAAsD;AACtD,uCAAyC;AACzC,qCAAwC;AACxC,6CAAyC;AACzC,2DAA2C;AAC3C,qCAAqC;AACrC,qCAA0C;AAC1C,yCAAiC;AACjC,qDAAiD;AACjD,qEAA0D;AAC1D,iFAA2E;AAE3E,iGAA2F;AAKpF,IAAM,wBAAwB,gCAA9B,MAAM,wBAAyB,SAAQ,wDAA4C;IAGx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EAAE,GAAG,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5F,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IAChI,CAAC;CAGF,CAAA;AArNY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAA;qCACP,uBAAa;QACtB,4DAA2B;QACtB,gBAAS;QACL,8BAAa;GAR5B,wBAAwB,CAqNpC","sourcesContent":["import { BadRequestException, ConflictException, Injectable, Logger, NotFoundException, ServiceUnavailableException } from '@nestjs/common';\nimport { InjectEntityManager } from '@nestjs/typeorm';\nimport { ModuleRef } from '@nestjs/core';\nimport { EntityManager } from 'typeorm';\nimport { createHash } from 'node:crypto';\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { homedir, tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { SecretService } from './secret.service';\nimport { AgentTool } from '../entities/agent-tool.entity';\nimport { AgentConfigCatalogService } from './agent-config-version.service';\nimport { AgentToolRegistry } from '../entities/agent-tool-registry.entity';\nimport { AgentToolRegistryRepository } from '../repository/agent-tool-registry.repository';\nimport { CreateAgentToolRegistryDto } from '../dtos/create-agent-tool-registry.dto';\nimport { UpdateAgentToolRegistryDto } from '../dtos/update-agent-tool-registry.dto';\n\n@Injectable()\nexport class AgentToolRegistryService extends AgentConfigCatalogService<AgentToolRegistry>{\n private readonly logger = new Logger(AgentToolRegistryService.name);\n\n constructor(\n @InjectEntityManager(\"default\")\n readonly entityManager: EntityManager,\n readonly repo: AgentToolRegistryRepository,\n readonly moduleRef: ModuleRef,\n readonly secretService: SecretService,\n ) {\n super(entityManager, repo, 'agentToolRegistry', moduleRef, AgentTool, 'agentToolRegistry');\n }\n\n private withChecksum<T extends { type?: string; sourceCode?: string; checksum?: string }>(dto: T, existing?: AgentToolRegistry): T {\n if (!['custom', 'thirdparty'].includes(dto.type ?? existing?.type)) return dto;\n\n const sourceCode = dto.sourceCode ?? existing?.sourceCode;\n if (typeof sourceCode !== 'string') return dto;\n\n return {\n ...dto,\n checksum: createHash('sha256').update(sourceCode, 'utf8').digest('hex'),\n };\n }\n\n private lifecycleRunner(): { python: string; runtimeRoot: string; sourceRoot?: string } {\n const binary = process.platform === 'win32' ? 'python.exe' : 'python';\n const configuredSourceRoot = process.env.SOLIDX_AGENTHUB_RUNTIME_PATH;\n const sourceRoot = configuredSourceRoot\n && existsSync(join(configuredSourceRoot, 'src', 'agenthub', 'tools', 'tool_lifecycle_check.py'))\n ? configuredSourceRoot\n : undefined;\n const candidates = [\n { root: join(homedir(), '.solidx', 'agenthub-venv'), sourceRoot },\n ...(process.env.SOLIDX_AGENTHUB_RUNTIME_PATH\n ? [{ root: join(process.env.SOLIDX_AGENTHUB_RUNTIME_PATH, '.venv'), sourceRoot }]\n : []),\n ];\n for (const candidate of candidates) {\n const python = join(candidate.root, process.platform === 'win32' ? 'Scripts' : 'bin', binary);\n if (existsSync(python)) return { python, runtimeRoot: candidate.root, sourceRoot: candidate.sourceRoot };\n }\n throw new ServiceUnavailableException('AgentHub runtime virtual environment was not found.');\n }\n\n private lifecycleDatabaseUrl(): string {\n const options = this.entityManager.connection.options as any;\n if (options.type !== 'postgres') {\n throw new ServiceUnavailableException('Tool checks require Core to use PostgreSQL.');\n }\n if (options.url) return options.url;\n const host = String(options.host ?? 'localhost');\n const formattedHost = host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;\n const credentials = options.username\n ? `${encodeURIComponent(String(options.username))}:${encodeURIComponent(String(options.password ?? ''))}@`\n : '';\n const ssl = options.ssl ? '?sslmode=require' : '';\n return `postgresql://${credentials}${formattedHost}:${options.port ?? 5432}/${encodeURIComponent(String(options.database))}${ssl}`;\n }\n\n private async runLifecycleScript(request: Record<string, unknown>): Promise<Record<string, any>> {\n const runner = this.lifecycleRunner();\n const requestJson = JSON.stringify(request);\n const childEnv = {\n PATH: process.env.PATH ?? '',\n VIRTUAL_ENV: runner.runtimeRoot,\n HOME: homedir(),\n DATABASE_URL: this.lifecycleDatabaseUrl(),\n ...(process.env.SYSTEMROOT ? { SYSTEMROOT: process.env.SYSTEMROOT } : {}),\n ...(runner.sourceRoot ? { PYTHONPATH: join(runner.sourceRoot, 'src') } : {}),\n };\n return new Promise((resolve, reject) => {\n const child = spawn(runner.python, ['-m', 'agenthub.tools.tool_lifecycle_check'], {\n cwd: runner.sourceRoot ?? tmpdir(),\n env: childEnv,\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n let stdout = '';\n let stderr = '';\n let settled = false;\n const finish = (callback: () => void) => {\n if (settled) return;\n settled = true;\n clearTimeout(timeout);\n callback();\n };\n const timeout = setTimeout(() => {\n child.kill('SIGKILL');\n finish(() => reject(new ServiceUnavailableException('Tool check exceeded the 20 second limit.')));\n }, 20_000);\n child.stdout.setEncoding('utf8');\n child.stderr.setEncoding('utf8');\n child.stdout.on('data', (chunk: string) => {\n stdout += chunk;\n if (stdout.length > 2_000_000) child.kill('SIGKILL');\n });\n child.stderr.on('data', (chunk: string) => {\n if (stderr.length < 2_000_000) stderr += chunk.slice(0, 2_000_000 - stderr.length);\n });\n child.on('error', (error) => finish(() => reject(new ServiceUnavailableException(`Could not start AgentHub tool checker: ${error.message}`))));\n child.on('close', (code) => finish(() => {\n if (stdout.length > 2_000_000) {\n reject(new BadRequestException('Tool check response was too large.'));\n return;\n }\n try {\n const result = JSON.parse(stdout.trim());\n if (!result || typeof result !== 'object' || Array.isArray(result)) throw new Error('Invalid response');\n resolve(result);\n } catch {\n reject(new ServiceUnavailableException(`AgentHub tool checker returned an invalid response${code === 0 ? '' : ` (exit ${code})`}. ${stderr.slice(0, 500)}`));\n }\n }));\n child.stdin.end(requestJson);\n });\n }\n\n private async readToolConfig(tool: AgentToolRegistry, checksum: string): Promise<{ success: boolean; message: string; requiredSecrets: string[] }> {\n const result = await this.runLifecycleScript({ tool_id: tool.id, checksum, phase: 'config' });\n const requiredSecrets = result.required_secrets;\n if (result.success !== true || !Array.isArray(requiredSecrets)\n || requiredSecrets.some((key) => typeof key !== 'string' || !key.trim())\n || new Set(requiredSecrets).size !== requiredSecrets.length) {\n return { success: false, message: String(result.message ?? 'The tool returned an invalid configuration.'), requiredSecrets: [] };\n }\n return { success: true, message: String(result.message ?? 'Configuration declaration checked.'), requiredSecrets };\n }\n\n async checkTool(id: number, phase: string, checksum: string) {\n if (phase !== 'config' && phase !== 'init') throw new BadRequestException('Phase must be config or init.');\n const tool = await this.repo.findOne({ where: { id } });\n if (!tool) throw new NotFoundException(`Tool ${id} was not found.`);\n if (!['custom', 'thirdparty'].includes(tool.type)) throw new BadRequestException('Only custom and third-party tools can be checked.');\n const currentChecksum = createHash('sha256').update(tool.sourceCode ?? '', 'utf8').digest('hex');\n if (!checksum || checksum !== currentChecksum) throw new ConflictException('Tool source changed. Save the tool again before running checks.');\n\n const config = await this.readToolConfig(tool, currentChecksum);\n if (!config.success) {\n return {\n toolId: id, checksum, phase,\n config: { status: 'failed', message: config.message, requiredSecrets: [], missingSecrets: [] },\n init: { status: 'skipped', message: 'Configuration must pass before initialization can run.' },\n };\n }\n\n const resolvedSecrets = phase === 'init'\n ? await this.secretService.resolveAvailable(config.requiredSecrets)\n : undefined;\n const available = phase === 'config'\n ? await this.secretService.findAvailableKeys(config.requiredSecrets)\n : Object.keys(resolvedSecrets ?? {});\n const missingSecrets = config.requiredSecrets.filter((key) => !available.includes(key));\n const configStep = {\n status: missingSecrets.length ? 'failed' : 'passed',\n message: missingSecrets.length ? 'Configure all required active secrets before initializing this tool.' : config.message,\n requiredSecrets: config.requiredSecrets,\n missingSecrets,\n };\n if (missingSecrets.length || phase === 'config') {\n return {\n toolId: id, checksum, phase, config: configStep,\n init: { status: 'skipped', message: missingSecrets.length ? 'Required secrets must be configured first.' : 'Run initialization after configuration passes.' },\n };\n }\n\n const secretValues = Object.fromEntries(Object.entries(resolvedSecrets ?? {}).map(([key, value]) => [\n key, typeof value === 'string' ? value : JSON.stringify(value),\n ]));\n const init = await this.runLifecycleScript({\n tool_id: id, checksum, phase: 'init', secret_values: secretValues,\n });\n return {\n toolId: id, checksum, phase, config: configStep,\n init: { status: init.success === true ? 'passed' : 'failed', message: String(init.message ?? (init.success ? 'Initialization check passed.' : 'Initialization check failed.')) },\n };\n }\n\n override async create(createDto: CreateAgentToolRegistryDto, files: Express.Multer.File[] = [], solidRequestContext: any = {}): Promise<AgentToolRegistry> {\n return super.create(this.withChecksum({ ...createDto, status: 'inactive', lastLoadError: null }), files, solidRequestContext);\n }\n\n override async createMany(createDtos: CreateAgentToolRegistryDto[], solidRequestContext: any = {}): Promise<AgentToolRegistry[]> {\n return super.createMany(createDtos.map((dto) => this.withChecksum({ ...dto, status: 'inactive', lastLoadError: null })), solidRequestContext);\n }\n\n override async insertMany(createDtos: CreateAgentToolRegistryDto[], filesArray: Express.Multer.File[][] = [], solidRequestContext: any = {}): Promise<AgentToolRegistry[]> {\n return super.insertMany(createDtos.map((dto) => this.withChecksum({ ...dto, status: 'inactive', lastLoadError: null })), filesArray, solidRequestContext);\n }\n\n override async update(\n id: number,\n updateDto: UpdateAgentToolRegistryDto,\n files: Express.Multer.File[] = [],\n isPartialUpdate = false,\n solidRequestContext: any = {},\n isUpdate = false,\n ): Promise<AgentToolRegistry> {\n const existing = await this.repo.findOne({ where: { id } });\n const changed = existing && ['sourceCode', 'name', 'type'].some(\n (key) => updateDto[key] !== undefined && updateDto[key] !== existing[key],\n );\n if (!changed && updateDto.status === 'active' && existing?.status !== 'active'\n && existing && ['custom', 'thirdparty'].includes(existing.type)) {\n const checkedChecksum = createHash('sha256').update(existing.sourceCode ?? '', 'utf8').digest('hex');\n if (updateDto.checksum !== checkedChecksum) {\n throw new ConflictException('Tool source changed after checks. Run configuration and initialization again.');\n }\n }\n const dto = changed ? { ...updateDto, status: 'inactive', lastLoadError: null } : updateDto;\n return super.update(id, this.withChecksum(dto, existing ?? undefined), files, isPartialUpdate, solidRequestContext, isUpdate);\n }\n\n\n}\n"]}
|
|
@@ -22,7 +22,7 @@ function fixture() {
|
|
|
22
22
|
const repo = { findOne: jest.fn(async () => ({ ...row })) };
|
|
23
23
|
const transaction = { findOne: jest.fn(async () => ({ ...row })), save: jest.fn(async (_entity, saved) => saved) };
|
|
24
24
|
const entityManager = { transaction: jest.fn(async (fn) => fn(transaction)) };
|
|
25
|
-
const service = new agent_tool_registry_service_1.AgentToolRegistryService(entityManager, repo, {});
|
|
25
|
+
const service = new agent_tool_registry_service_1.AgentToolRegistryService(entityManager, repo, {}, {});
|
|
26
26
|
return { row, repo, transaction, entityManager, service };
|
|
27
27
|
}
|
|
28
28
|
afterEach(() => jest.restoreAllMocks());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-tool-registry.service.spec.js","sourceRoot":"","sources":["../../src/services/agent-tool-registry.service.spec.ts"],"names":[],"mappings":";;AAAA,6CAAyC;AACzC,+EAAyE;AAGzE,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,yBAAyB,EAAE;QACzB,KAAK,CAAC,MAAM,CAAC,GAAQ,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC;QACtC,KAAK,CAAC,UAAU,CAAC,IAAW,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC;QAC9C,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,GAAQ,IAAI,OAAO,EAAE,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;KAC9D;CACF,CAAC,CAAC,CAAC;AACJ,IAAI,CAAC,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE;KAAQ,EAAE,CAAC,C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M,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3F,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,4DAA4D,EAAE,KAAK,IAAI,EAAE;IAC1E,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;IACnC,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC;IACtB,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,EAAE,QAAQ,EAAS,CAAC,CAAC;IACvG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC,CAAC,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\nimport { AgentToolRegistryService } from './agent-tool-registry.service';\nimport { AgentConfigCatalogService } from './agent-config-version.service';\n\njest.mock('./agent-config-version.service', () => ({\n AgentConfigCatalogService: class {\n async create(dto: any) { return dto; }\n async createMany(dtos: any[]) { return dtos; }\n async update(id: number, dto: any) { return { id, ...dto }; }\n },\n}));\njest.mock('../entities/agent-tool-registry.entity', () => ({ AgentToolRegistry: class {} }));\njest.mock('../entities/agent-tool.entity', () => ({ AgentTool: class {} }));\njest.mock('../repository/agent-tool-registry.repository', () => ({ AgentToolRegistryRepository: class {} }));\n\nconst checksum = createHash('sha256').update('saved source').digest('hex');\n\nfunction fixture() {\n const row: any = { id: 1, name: 'probe', type: 'custom', sourceCode: 'saved source', checksum,\n status: 'inactive', updatedAt: new Date('2026-10-07T00:00:00Z') };\n const repo = { findOne: jest.fn(async () => ({ ...row })) };\n const transaction = { findOne: jest.fn(async () => ({ ...row })), save: jest.fn(async (_entity, saved) => saved) };\n const entityManager = { transaction: jest.fn(async (fn) => fn(transaction)) };\n const service = new AgentToolRegistryService(entityManager as any, repo as any, {} as any, {} as any);\n return { row, repo, transaction, entityManager, service };\n}\n\nafterEach(() => jest.restoreAllMocks());\n\nit('creates new tools inactive even when active was requested', async () => {\n const { service } = fixture();\n const saved = await service.create({ type: 'custom', sourceCode: 'saved source', status: 'active' } as any);\n expect(saved.status).toBe('inactive');\n expect(saved.checksum).toBe(checksum);\n});\n\nit('creates bulk tools inactive', async () => {\n const { service } = fixture();\n const saved = await service.createMany([{ type: 'custom', sourceCode: 'saved source', status: 'active' } as any]);\n expect(saved[0].status).toBe('inactive');\n});\n\nit('allows activation through the existing update endpoint', async () => {\n const { service } = fixture();\n const saved = await service.update(1, { status: 'active', checksum } as any);\n expect(saved.status).toBe('active');\n});\n\nit('deactivates an active tool when its source changes', async () => {\n const { service, row } = fixture();\n row.status = 'active';\n const saved = await service.update(1, { sourceCode: 'changed source', status: 'active' } as any);\n expect(saved.status).toBe('inactive');\n expect(saved.checksum).toBe(createHash('sha256').update('changed source').digest('hex'));\n});\n\nit('preserves existing active tools during metadata-only saves', async () => {\n const { service, row } = fixture();\n row.status = 'active';\n const saved = await service.update(1, { description: 'Updated description', status: 'active' } as any);\n expect(saved.status).toBe('active');\n});\n"]}
|
|
@@ -20,6 +20,7 @@ export declare class SecretService extends CRUDService<Secret> {
|
|
|
20
20
|
getSecretsContext(): Promise<Record<string, any>>;
|
|
21
21
|
resolve(key: string): Promise<any>;
|
|
22
22
|
resolveAvailable(keys: string[]): Promise<Record<string, any>>;
|
|
23
|
+
findAvailableKeys(keys: string[]): Promise<string[]>;
|
|
23
24
|
resolveMany(keys: string[]): Promise<Record<string, any>>;
|
|
24
25
|
private prepareSecretForSave;
|
|
25
26
|
private encrypt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret.service.d.ts","sourceRoot":"","sources":["../../src/services/secret.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAM,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2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AQ,EAC7B,QAAQ,UAAQ,GACf,OAAO,CAAC,MAAM,CAAC;IAOH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,mBAAmB,GAAE,GAAQ;IAOhD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,mBAAmB,GAAE,GAAQ;IAOhE,UAAU,CAAC,UAAU,EAAE,GAAG,EAAE,EAAE,mBAAmB,GAAE,GAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAM/E,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,mBAAmB,GAAE,GAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAQtE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,GAAE,GAAQ,EAAE,mBAAmB,GAAE,GAAQ;IAKlE,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IA4BjD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAgBlC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAgB9D,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkBpD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAa/D,OAAO,CAAC,oBAAoB;IAmB5B,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,UAAU;CAMnB"}
|
|
@@ -112,6 +112,16 @@ let SecretService = SecretService_1 = class SecretService extends crud_service_1
|
|
|
112
112
|
return resolved;
|
|
113
113
|
}, {});
|
|
114
114
|
}
|
|
115
|
+
async findAvailableKeys(keys) {
|
|
116
|
+
const uniqueKeys = Array.from(new Set((keys ?? []).filter(Boolean)));
|
|
117
|
+
if (uniqueKeys.length === 0)
|
|
118
|
+
return [];
|
|
119
|
+
const secrets = await this.repo.find({
|
|
120
|
+
where: { key: (0, typeorm_2.In)(uniqueKeys), status: "active" },
|
|
121
|
+
select: { key: true },
|
|
122
|
+
});
|
|
123
|
+
return secrets.map((secret) => secret.key);
|
|
124
|
+
}
|
|
115
125
|
async resolveMany(keys) {
|
|
116
126
|
const resolved = await this.resolveAvailable(keys);
|
|
117
127
|
const missing = Array.from(new Set((keys ?? []).filter(Boolean))).filter((key) => !(key in resolved));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret.service.js","sourceRoot":"","sources":["../../src/services/secret.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4F;AAC5F,6CAAsD;AACtD,uCAAyC;AACzC,qCAA4C;AAC5C,iDAAwD;AAExD,uEAAmE;AACnE,6DAAyD;AACzD,yEAA8D;AAC9D,iFAA6F;AAE7F,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAGhC,IAAM,aAAa,qBAAnB,MAAM,aAAc,SAAQ,0BAAmB;IAIpD,YAEE,aAAqC,EAC5B,IAAsB,EACtB,SAAoB;QAE7B,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QAJrD,kBAAa,GAAb,aAAa,CAAe;QAC5B,SAAI,GAAJ,IAAI,CAAkB;QACtB,cAAS,GAAT,SAAS,CAAW;QAPd,WAAM,GAAG,IAAI,eAAM,CAAC,eAAa,CAAC,IAAI,CAAC,CAAC;QAUvD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,sCAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACvE,IAAI,CAAC,MAAM,EAAE,CA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;IAC1C,CAAC;IAEO,UAAU,CAAC,MAAc;QAC/B,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,GAAG,mBAAmB,CAAC;QACrC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA9NY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAA;qCACP,uBAAa;QACtB,oCAAgB;QACX,gBAAS;GARpB,aAAa,CA8NzB","sourcesContent":["import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';\nimport { InjectEntityManager } from '@nestjs/typeorm';\nimport { ModuleRef } from \"@nestjs/core\";\nimport { EntityManager, In } from 'typeorm';\nimport { CRUDService } from 'src/services/crud.service';\nimport { Secret } from '../entities/secret.entity';\nimport { SecretRepository } from '../repository/secret.repository';\nimport { EncryptionService } from './encryption.service';\nimport { AgentSecret } from '../entities/agent-secret.entity';\nimport { agentIdsForCatalog, bumpAgentConfigVersions } from './agent-config-version.service';\n\nconst MASKED_SECRET_VALUE = \"********\";\n\n@Injectable()\nexport class SecretService extends CRUDService<Secret> {\n private readonly logger = new Logger(SecretService.name);\n private readonly encryptionService: EncryptionService | null;\n\n constructor(\n @InjectEntityManager(\"default\")\n readonly entityManager: EntityManager,\n readonly repo: SecretRepository,\n readonly moduleRef: ModuleRef,\n ) {\n super(entityManager, repo, 'secret', 'solid-core', moduleRef);\n const encKey = process.env.APP_ENCRYPTION_KEY;\n this.encryptionService = encKey ? new EncryptionService(encKey) : null;\n if (!encKey) {\n this.logger.warn('APP_ENCRYPTION_KEY is not set — secrets cannot be encrypted or decrypted');\n }\n }\n\n async create(createDto: any, files: Express.Multer.File[] = [], solidRequestContext: any = {}): Promise<Secret> {\n const preparedDto = this.prepareSecretForSave(createDto, true);\n const saved = await super.create(preparedDto, files, solidRequestContext);\n return this.maskSecret(saved);\n }\n\n async update(\n id: number,\n updateDto: any,\n files: Express.Multer.File[] = [],\n isPartialUpdate = false,\n solidRequestContext: any = {},\n isUpdate = false,\n ): Promise<Secret> {\n const preparedDto = this.prepareSecretForSave(updateDto, false);\n const saved = await super.update(id, preparedDto, files, isPartialUpdate, solidRequestContext, isUpdate);\n await bumpAgentConfigVersions(this.entityManager, await agentIdsForCatalog(this.entityManager, AgentSecret, 'secret', [id]));\n return this.maskSecret(saved);\n }\n\n override async delete(id: number, solidRequestContext: any = {}) {\n const agentIds = await agentIdsForCatalog(this.entityManager, AgentSecret, 'secret', [id]);\n const result = await super.delete(id, solidRequestContext);\n await bumpAgentConfigVersions(this.entityManager, agentIds);\n return result;\n }\n\n override async deleteMany(ids: number[], solidRequestContext: any = {}) {\n const agentIds = await agentIdsForCatalog(this.entityManager, AgentSecret, 'secret', ids);\n const result = await super.deleteMany(ids, solidRequestContext);\n await bumpAgentConfigVersions(this.entityManager, agentIds);\n return result;\n }\n\n async createMany(createDtos: any[], solidRequestContext: any = {}): Promise<Secret[]> {\n const preparedDtos = createDtos.map((dto) => this.prepareSecretForSave(dto, true));\n const saved = await super.createMany(preparedDtos, solidRequestContext);\n return saved.map((secret) => this.maskSecret(secret));\n }\n\n async find(basicFilterDto: any, solidRequestContext: any = {}): Promise<any> {\n const response = await super.find(basicFilterDto, solidRequestContext);\n return {\n ...response,\n records: (response.records ?? []).map((secret: Secret) => this.maskSecret(secret)),\n };\n }\n\n async findOne(id: number, query: any = {}, solidRequestContext: any = {}) {\n const secret = await super.findOne(id, query, solidRequestContext);\n return this.maskSecret(secret);\n }\n\n async getSecretsContext(): Promise<Record<string, any>> {\n const secrets = await this.repo.find({\n where: { status: \"active\" } as any,\n });\n\n const context: Record<string, any> = {};\n for (const secret of secrets) {\n try {\n this.assignSecretPath(context, secret.key, this.decryptAndCoerce(secret));\n secret.lastAccessedAt = new Date();\n } catch (error) {\n this.logger.warn(`Failed to resolve secret \"${secret.key}\": ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n if (secrets.length > 0) {\n await this.repo.save(secrets);\n }\n\n return context;\n }\n\n /**\n * Resolves one secret to its decrypted, type-coerced value.\n *\n * `key` is the literal key column value — \"smtp.password\" is one row, not a path.\n * Callers must resolve at point of use and must not cache the result.\n */\n async resolve(key: string): Promise<any> {\n const resolved = await this.resolveMany([key]);\n return resolved[key];\n }\n\n /**\n * Resolves whatever of `keys` exists and is active, in a single query, omitting the\n * rest. Returns a flat map keyed by the literal keys requested.\n *\n * For callers that can report a missing key better than this service can — the test\n * runner lets an unresolved key surface at the step that references it, which names\n * the token and locates the failure. Prefer resolveMany elsewhere.\n *\n * Still fail-closed on infrastructure: an absent APP_ENCRYPTION_KEY or a failed\n * decrypt throws rather than yielding a partial map.\n */\n async resolveAvailable(keys: string[]): Promise<Record<string, any>> {\n const uniqueKeys = Array.from(new Set((keys ?? []).filter(Boolean)));\n if (uniqueKeys.length === 0) {\n return {};\n }\n\n const secrets = await this.repo.find({\n where: { key: In(uniqueKeys), status: \"active\" } as any,\n });\n\n return secrets.reduce((resolved, secret) => {\n resolved[secret.key] = this.decryptAndCoerce(secret);\n return resolved;\n }, {} as Record<string, any>);\n }\n\n /**\n * Resolves several secrets in a single query, returning a flat map keyed by the\n * literal keys requested.\n *\n * Fail-closed: throws for a key that is missing, inactive or undecryptable rather\n * than omitting it from the result. A credential that silently resolves to undefined\n * becomes an empty password on an outbound request.\n */\n async resolveMany(keys: string[]): Promise<Record<string, any>> {\n const resolved = await this.resolveAvailable(keys);\n\n const missing = Array.from(new Set((keys ?? []).filter(Boolean))).filter(\n (key) => !(key in resolved),\n );\n if (missing.length > 0) {\n throw new NotFoundException(`No active secret found for: ${missing.join(', ')}`);\n }\n\n return resolved;\n }\n\n private prepareSecretForSave(dto: any, requireValue: boolean): any {\n const preparedDto = { ...dto };\n const rawValue = preparedDto.value;\n const hasNewValue = rawValue !== undefined && rawValue !== null && rawValue !== MASKED_SECRET_VALUE;\n\n if (requireValue && !hasNewValue) {\n throw new BadRequestException('Secret value is required.');\n }\n\n if (hasNewValue) {\n preparedDto.value = this.encrypt(String(rawValue));\n preparedDto.lastRotatedAt = new Date();\n } else {\n delete preparedDto.value;\n }\n\n return preparedDto;\n }\n\n private encrypt(value: string): string {\n if (!this.encryptionService) {\n throw new BadRequestException('APP_ENCRYPTION_KEY must be set before secrets can be saved.');\n }\n\n return this.encryptionService.isEncrypted(value) ? value : this.encryptionService.encrypt(value);\n }\n\n private decryptAndCoerce(secret: Secret): any {\n if (!this.encryptionService) {\n throw new BadRequestException('APP_ENCRYPTION_KEY must be set before secrets can be used.');\n }\n\n const decryptedValue = this.encryptionService.decrypt(secret.value);\n switch (secret.valueType) {\n case 'json':\n return JSON.parse(decryptedValue);\n case 'number':\n return Number(decryptedValue);\n case 'boolean':\n return decryptedValue === 'true' || decryptedValue === '1';\n case 'string':\n default:\n return decryptedValue;\n }\n }\n\n private assignSecretPath(target: Record<string, any>, key: string, value: any): void {\n const parts = String(key)\n .split('.')\n .map((part) => part.trim())\n .filter(Boolean);\n\n if (parts.length === 0) {\n return;\n }\n\n let cursor = target;\n parts.slice(0, -1).forEach((part) => {\n cursor[part] = cursor[part] && typeof cursor[part] === 'object' ? cursor[part] : {};\n cursor = cursor[part];\n });\n cursor[parts[parts.length - 1]] = value;\n }\n\n private maskSecret(secret: Secret): Secret {\n if (secret) {\n secret.value = MASKED_SECRET_VALUE;\n }\n return secret;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"secret.service.js","sourceRoot":"","sources":["../../src/services/secret.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4F;AAC5F,6CAAsD;AACtD,uCAAyC;AACzC,qCAA4C;AAC5C,iDAAwD;AAExD,uEAAmE;AACnE,6DAAyD;AACzD,yEAA8D;AAC9D,iFAA6F;AAE7F,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAGhC,IAAM,aAAa,qBAAnB,MAAM,aAAc,SAAQ,0BAAmB;IAIpD,YAEE,aAAqC,EAC5B,IAAsB,EACtB,SAA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Y,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAA;qCACP,uBAAa;QACtB,oCAAgB;QACX,gBAAS;GARpB,aAAa,CAwOzB","sourcesContent":["import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';\nimport { InjectEntityManager } from '@nestjs/typeorm';\nimport { ModuleRef } from \"@nestjs/core\";\nimport { EntityManager, In } from 'typeorm';\nimport { CRUDService } from 'src/services/crud.service';\nimport { Secret } from '../entities/secret.entity';\nimport { SecretRepository } from '../repository/secret.repository';\nimport { EncryptionService } from './encryption.service';\nimport { AgentSecret } from '../entities/agent-secret.entity';\nimport { agentIdsForCatalog, bumpAgentConfigVersions } from './agent-config-version.service';\n\nconst MASKED_SECRET_VALUE = \"********\";\n\n@Injectable()\nexport class SecretService extends CRUDService<Secret> {\n private readonly logger = new Logger(SecretService.name);\n private readonly encryptionService: EncryptionService | null;\n\n constructor(\n @InjectEntityManager(\"default\")\n readonly entityManager: EntityManager,\n readonly repo: SecretRepository,\n readonly moduleRef: ModuleRef,\n ) {\n super(entityManager, repo, 'secret', 'solid-core', moduleRef);\n const encKey = process.env.APP_ENCRYPTION_KEY;\n this.encryptionService = encKey ? new EncryptionService(encKey) : null;\n if (!encKey) {\n this.logger.warn('APP_ENCRYPTION_KEY is not set — secrets cannot be encrypted or decrypted');\n }\n }\n\n async create(createDto: any, files: Express.Multer.File[] = [], solidRequestContext: any = {}): Promise<Secret> {\n const preparedDto = this.prepareSecretForSave(createDto, true);\n const saved = await super.create(preparedDto, files, solidRequestContext);\n return this.maskSecret(saved);\n }\n\n async update(\n id: number,\n updateDto: any,\n files: Express.Multer.File[] = [],\n isPartialUpdate = false,\n solidRequestContext: any = {},\n isUpdate = false,\n ): Promise<Secret> {\n const preparedDto = this.prepareSecretForSave(updateDto, false);\n const saved = await super.update(id, preparedDto, files, isPartialUpdate, solidRequestContext, isUpdate);\n await bumpAgentConfigVersions(this.entityManager, await agentIdsForCatalog(this.entityManager, AgentSecret, 'secret', [id]));\n return this.maskSecret(saved);\n }\n\n override async delete(id: number, solidRequestContext: any = {}) {\n const agentIds = await agentIdsForCatalog(this.entityManager, AgentSecret, 'secret', [id]);\n const result = await super.delete(id, solidRequestContext);\n await bumpAgentConfigVersions(this.entityManager, agentIds);\n return result;\n }\n\n override async deleteMany(ids: number[], solidRequestContext: any = {}) {\n const agentIds = await agentIdsForCatalog(this.entityManager, AgentSecret, 'secret', ids);\n const result = await super.deleteMany(ids, solidRequestContext);\n await bumpAgentConfigVersions(this.entityManager, agentIds);\n return result;\n }\n\n async createMany(createDtos: any[], solidRequestContext: any = {}): Promise<Secret[]> {\n const preparedDtos = createDtos.map((dto) => this.prepareSecretForSave(dto, true));\n const saved = await super.createMany(preparedDtos, solidRequestContext);\n return saved.map((secret) => this.maskSecret(secret));\n }\n\n async find(basicFilterDto: any, solidRequestContext: any = {}): Promise<any> {\n const response = await super.find(basicFilterDto, solidRequestContext);\n return {\n ...response,\n records: (response.records ?? []).map((secret: Secret) => this.maskSecret(secret)),\n };\n }\n\n async findOne(id: number, query: any = {}, solidRequestContext: any = {}) {\n const secret = await super.findOne(id, query, solidRequestContext);\n return this.maskSecret(secret);\n }\n\n async getSecretsContext(): Promise<Record<string, any>> {\n const secrets = await this.repo.find({\n where: { status: \"active\" } as any,\n });\n\n const context: Record<string, any> = {};\n for (const secret of secrets) {\n try {\n this.assignSecretPath(context, secret.key, this.decryptAndCoerce(secret));\n secret.lastAccessedAt = new Date();\n } catch (error) {\n this.logger.warn(`Failed to resolve secret \"${secret.key}\": ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n if (secrets.length > 0) {\n await this.repo.save(secrets);\n }\n\n return context;\n }\n\n /**\n * Resolves one secret to its decrypted, type-coerced value.\n *\n * `key` is the literal key column value — \"smtp.password\" is one row, not a path.\n * Callers must resolve at point of use and must not cache the result.\n */\n async resolve(key: string): Promise<any> {\n const resolved = await this.resolveMany([key]);\n return resolved[key];\n }\n\n /**\n * Resolves whatever of `keys` exists and is active, in a single query, omitting the\n * rest. Returns a flat map keyed by the literal keys requested.\n *\n * For callers that can report a missing key better than this service can — the test\n * runner lets an unresolved key surface at the step that references it, which names\n * the token and locates the failure. Prefer resolveMany elsewhere.\n *\n * Still fail-closed on infrastructure: an absent APP_ENCRYPTION_KEY or a failed\n * decrypt throws rather than yielding a partial map.\n */\n async resolveAvailable(keys: string[]): Promise<Record<string, any>> {\n const uniqueKeys = Array.from(new Set((keys ?? []).filter(Boolean)));\n if (uniqueKeys.length === 0) {\n return {};\n }\n\n const secrets = await this.repo.find({\n where: { key: In(uniqueKeys), status: \"active\" } as any,\n });\n\n return secrets.reduce((resolved, secret) => {\n resolved[secret.key] = this.decryptAndCoerce(secret);\n return resolved;\n }, {} as Record<string, any>);\n }\n\n async findAvailableKeys(keys: string[]): Promise<string[]> {\n const uniqueKeys = Array.from(new Set((keys ?? []).filter(Boolean)));\n if (uniqueKeys.length === 0) return [];\n const secrets = await this.repo.find({\n where: { key: In(uniqueKeys), status: \"active\" } as any,\n select: { key: true } as any,\n });\n return secrets.map((secret) => secret.key);\n }\n\n /**\n * Resolves several secrets in a single query, returning a flat map keyed by the\n * literal keys requested.\n *\n * Fail-closed: throws for a key that is missing, inactive or undecryptable rather\n * than omitting it from the result. A credential that silently resolves to undefined\n * becomes an empty password on an outbound request.\n */\n async resolveMany(keys: string[]): Promise<Record<string, any>> {\n const resolved = await this.resolveAvailable(keys);\n\n const missing = Array.from(new Set((keys ?? []).filter(Boolean))).filter(\n (key) => !(key in resolved),\n );\n if (missing.length > 0) {\n throw new NotFoundException(`No active secret found for: ${missing.join(', ')}`);\n }\n\n return resolved;\n }\n\n private prepareSecretForSave(dto: any, requireValue: boolean): any {\n const preparedDto = { ...dto };\n const rawValue = preparedDto.value;\n const hasNewValue = rawValue !== undefined && rawValue !== null && rawValue !== MASKED_SECRET_VALUE;\n\n if (requireValue && !hasNewValue) {\n throw new BadRequestException('Secret value is required.');\n }\n\n if (hasNewValue) {\n preparedDto.value = this.encrypt(String(rawValue));\n preparedDto.lastRotatedAt = new Date();\n } else {\n delete preparedDto.value;\n }\n\n return preparedDto;\n }\n\n private encrypt(value: string): string {\n if (!this.encryptionService) {\n throw new BadRequestException('APP_ENCRYPTION_KEY must be set before secrets can be saved.');\n }\n\n return this.encryptionService.isEncrypted(value) ? value : this.encryptionService.encrypt(value);\n }\n\n private decryptAndCoerce(secret: Secret): any {\n if (!this.encryptionService) {\n throw new BadRequestException('APP_ENCRYPTION_KEY must be set before secrets can be used.');\n }\n\n const decryptedValue = this.encryptionService.decrypt(secret.value);\n switch (secret.valueType) {\n case 'json':\n return JSON.parse(decryptedValue);\n case 'number':\n return Number(decryptedValue);\n case 'boolean':\n return decryptedValue === 'true' || decryptedValue === '1';\n case 'string':\n default:\n return decryptedValue;\n }\n }\n\n private assignSecretPath(target: Record<string, any>, key: string, value: any): void {\n const parts = String(key)\n .split('.')\n .map((part) => part.trim())\n .filter(Boolean);\n\n if (parts.length === 0) {\n return;\n }\n\n let cursor = target;\n parts.slice(0, -1).forEach((part) => {\n cursor[part] = cursor[part] && typeof cursor[part] === 'object' ? cursor[part] : {};\n cursor = cursor[part];\n });\n cursor[parts[parts.length - 1]] = value;\n }\n\n private maskSecret(secret: Secret): Secret {\n if (secret) {\n secret.value = MASKED_SECRET_VALUE;\n }\n return secret;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-core.module.d.ts","sourceRoot":"","sources":["../src/solid-core.module.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"solid-core.module.d.ts","sourceRoot":"","sources":["../src/solid-core.module.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;AA8gBhB,qBAiqBa,eAAe;CAAI"}
|
|
@@ -438,6 +438,7 @@ const switch_node_1 = require("./services/workflow/nodes/switch.node");
|
|
|
438
438
|
const agent_registry_entity_1 = require("./entities/agent-registry.entity");
|
|
439
439
|
const agent_tool_registry_entity_1 = require("./entities/agent-tool-registry.entity");
|
|
440
440
|
const agent_skill_registry_entity_1 = require("./entities/agent-skill-registry.entity");
|
|
441
|
+
const agent_hub_tag_entity_1 = require("./entities/agent-hub-tag.entity");
|
|
441
442
|
const agent_tool_entity_1 = require("./entities/agent-tool.entity");
|
|
442
443
|
const agent_skill_entity_1 = require("./entities/agent-skill.entity");
|
|
443
444
|
const agent_secret_entity_1 = require("./entities/agent-secret.entity");
|
|
@@ -451,6 +452,7 @@ const agent_registry_controller_1 = require("./controllers/agent-registry.contro
|
|
|
451
452
|
const agent_embed_controller_1 = require("./controllers/agent-embed.controller");
|
|
452
453
|
const agent_tool_registry_controller_1 = require("./controllers/agent-tool-registry.controller");
|
|
453
454
|
const agent_skill_registry_controller_1 = require("./controllers/agent-skill-registry.controller");
|
|
455
|
+
const agent_hub_tag_controller_1 = require("./controllers/agent-hub-tag.controller");
|
|
454
456
|
const agent_tool_controller_1 = require("./controllers/agent-tool.controller");
|
|
455
457
|
const agent_skill_controller_1 = require("./controllers/agent-skill.controller");
|
|
456
458
|
const agent_role_controller_1 = require("./controllers/agent-role.controller");
|
|
@@ -473,6 +475,7 @@ const agent_secret_repository_1 = require("./repository/agent-secret.repository"
|
|
|
473
475
|
const agent_skill_repository_1 = require("./repository/agent-skill.repository");
|
|
474
476
|
const agent_tool_repository_1 = require("./repository/agent-tool.repository");
|
|
475
477
|
const agent_skill_registry_repository_1 = require("./repository/agent-skill-registry.repository");
|
|
478
|
+
const agent_hub_tag_repository_1 = require("./repository/agent-hub-tag.repository");
|
|
476
479
|
const agent_tool_registry_repository_1 = require("./repository/agent-tool-registry.repository");
|
|
477
480
|
const agent_session_service_1 = require("./services/agent-session.service");
|
|
478
481
|
const agent_job_service_1 = require("./services/agent-job.service");
|
|
@@ -484,6 +487,7 @@ const agent_secret_service_1 = require("./services/agent-secret.service");
|
|
|
484
487
|
const agent_skill_service_1 = require("./services/agent-skill.service");
|
|
485
488
|
const agent_tool_service_1 = require("./services/agent-tool.service");
|
|
486
489
|
const agent_skill_registry_service_1 = require("./services/agent-skill-registry.service");
|
|
490
|
+
const agent_hub_tag_service_1 = require("./services/agent-hub-tag.service");
|
|
487
491
|
const agent_tool_registry_service_1 = require("./services/agent-tool-registry.service");
|
|
488
492
|
let SolidCoreModule = class SolidCoreModule {
|
|
489
493
|
};
|
|
@@ -538,6 +542,7 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
|
|
|
538
542
|
agent_registry_entity_1.AgentRegistry,
|
|
539
543
|
agent_tool_registry_entity_1.AgentToolRegistry,
|
|
540
544
|
agent_skill_registry_entity_1.AgentSkillRegistry,
|
|
545
|
+
agent_hub_tag_entity_1.AgentHubTag,
|
|
541
546
|
agent_tool_entity_1.AgentTool,
|
|
542
547
|
agent_skill_entity_1.AgentSkill,
|
|
543
548
|
agent_role_entity_1.AgentRole,
|
|
@@ -653,6 +658,7 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
|
|
|
653
658
|
agent_embed_controller_1.AgentEmbedController,
|
|
654
659
|
agent_tool_registry_controller_1.AgentToolRegistryController,
|
|
655
660
|
agent_skill_registry_controller_1.AgentSkillRegistryController,
|
|
661
|
+
agent_hub_tag_controller_1.AgentHubTagController,
|
|
656
662
|
agent_tool_controller_1.AgentToolController,
|
|
657
663
|
agent_skill_controller_1.AgentSkillController,
|
|
658
664
|
agent_role_controller_1.AgentRoleController,
|
|
@@ -1018,6 +1024,8 @@ exports.SolidCoreModule = SolidCoreModule = __decorate([
|
|
|
1018
1024
|
agent_tool_registry_repository_1.AgentToolRegistryRepository,
|
|
1019
1025
|
agent_skill_registry_service_1.AgentSkillRegistryService,
|
|
1020
1026
|
agent_skill_registry_repository_1.AgentSkillRegistryRepository,
|
|
1027
|
+
agent_hub_tag_service_1.AgentHubTagService,
|
|
1028
|
+
agent_hub_tag_repository_1.AgentHubTagRepository,
|
|
1021
1029
|
agent_tool_service_1.AgentToolService,
|
|
1022
1030
|
agent_tool_repository_1.AgentToolRepository,
|
|
1023
1031
|
agent_skill_service_1.AgentSkillService,
|