@solidxai/core 0.1.21-beta.1 → 0.1.22-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 +58 -0
- package/dist/decorators/settings-provider.decorator.d.ts +2 -1
- package/dist/decorators/settings-provider.decorator.d.ts.map +1 -1
- package/dist/decorators/settings-provider.decorator.js +3 -2
- package/dist/decorators/settings-provider.decorator.js.map +1 -1
- package/dist/dtos/create-agent-user-memory.dto.d.ts +1 -1
- package/dist/dtos/create-agent-user-memory.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-user-memory.dto.js +2 -2
- package/dist/dtos/create-agent-user-memory.dto.js.map +1 -1
- package/dist/dtos/update-agent-user-memory.dto.d.ts +1 -1
- package/dist/dtos/update-agent-user-memory.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-user-memory.dto.js +2 -2
- package/dist/dtos/update-agent-user-memory.dto.js.map +1 -1
- package/dist/entities/agent-user-memory.entity.d.ts +1 -1
- package/dist/entities/agent-user-memory.entity.d.ts.map +1 -1
- package/dist/entities/agent-user-memory.entity.js +2 -2
- package/dist/entities/agent-user-memory.entity.js.map +1 -1
- package/dist/helpers/setting-key.helper.d.ts +6 -0
- package/dist/helpers/setting-key.helper.d.ts.map +1 -0
- package/dist/helpers/setting-key.helper.js +28 -0
- package/dist/helpers/setting-key.helper.js.map +1 -0
- package/dist/helpers/setting-key.helper.spec.d.ts +2 -0
- package/dist/helpers/setting-key.helper.spec.d.ts.map +1 -0
- package/dist/helpers/setting-key.helper.spec.js +37 -0
- package/dist/helpers/setting-key.helper.spec.js.map +1 -0
- package/dist/resources/agent-embed/solid-agent-embed.js +42 -19
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +13 -1
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +2 -180
- package/dist/services/agent-tool-registry.service.js +5 -5
- package/dist/services/agent-tool-registry.service.js.map +1 -1
- package/dist/services/mail/smtp-email.service.d.ts.map +1 -1
- package/dist/services/mail/smtp-email.service.js +2 -6
- package/dist/services/mail/smtp-email.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +4 -2
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/setting.service.d.ts +1 -1
- package/dist/services/setting.service.d.ts.map +1 -1
- package/dist/services/setting.service.js +25 -8
- package/dist/services/setting.service.js.map +1 -1
- package/dist/services/setting.service.spec.d.ts +2 -0
- package/dist/services/setting.service.spec.d.ts.map +1 -0
- package/dist/services/setting.service.spec.js +110 -0
- package/dist/services/setting.service.spec.js.map +1 -0
- package/dist/services/settings/default-settings-provider.service.d.ts +146 -6
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +81 -4
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/subscribers/agent-tool-registry.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-tool-registry.subscriber.js +16 -11
- package/dist/subscribers/agent-tool-registry.subscriber.js.map +1 -1
- package/package.json +1 -1
- package/plan.md +480 -0
- package/resources/agent-embed/solid-agent-embed.js +42 -19
- package/src/decorators/settings-provider.decorator.ts +6 -3
- package/src/dtos/create-agent-user-memory.dto.ts +1 -1
- package/src/dtos/update-agent-user-memory.dto.ts +1 -1
- package/src/entities/agent-user-memory.entity.ts +2 -2
- package/src/helpers/setting-key.helper.spec.ts +32 -0
- package/src/helpers/setting-key.helper.ts +30 -0
- package/src/seeders/module-metadata-seeder.service.ts +12 -1
- package/src/seeders/seed-data/solid-core-metadata.json +2 -180
- package/src/services/agent-tool-registry.service.ts +5 -5
- package/src/services/mail/smtp-email.service.ts +3 -6
- package/src/services/model-metadata.service.ts +5 -2
- package/src/services/setting.service.spec.ts +117 -0
- package/src/services/setting.service.ts +29 -9
- package/src/services/settings/default-settings-provider.service.ts +81 -4
- package/src/subscribers/agent-tool-registry.subscriber.ts +16 -9
- package/src/services/1.js +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-tool-registry.subscriber.js","sourceRoot":"","sources":["../../src/subscribers/agent-tool-registry.subscriber.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6CAAmD;AACnD,gDAAkC;AAClC,qCAAuI;AACvI,4CAAuD;AACvD,uFAA4E;AAC5E,8FAAyF;AACzF,qEAA2D;AAC3D,2EAAsE;AAG/D,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAKpC,YACwB,UAAuC,EAC1C,2BAAwD,EACxD,uBAAgD;QAF5B,eAAU,GAAV,UAAU,CAAY;QAC1C,gCAA2B,GAA3B,2BAA2B,CAA6B;QACxD,4BAAuB,GAAvB,uBAAuB,CAAyB;QAPpD,WAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;QACtD,kBAAa,GAAG,IAAI,GAAG,EAAiD,CAAC;QACzE,iBAAY,GAAG,IAAI,GAAG,EAAqE,CAAC;QAOzG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,QAAQ;QACJ,OAAO,8CAAiB,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAqC;QACnD,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,OAAO,CAAC;QACjE,IAAI,eAAe,KAAK,MAAM,EAAE,CAAC;YAC7B,OAAO;QACX,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACjE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS;YA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,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,QAAQ,EAAE,CAAC,CAAC;IAChG,CAAC;CACJ,CAAA;AA3MY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;IAOJ,WAAA,IAAA,0BAAgB,GAAE,CAAA;qCAA8B,oBAAU;QACb,4DAA2B;QAC/B,mDAAuB;GAR5D,2BAA2B,CA2MvC","sourcesContent":["import { Injectable, Logger } from '@nestjs/common';\nimport { InjectDataSource } from '@nestjs/typeorm';\nimport * as fs from 'fs/promises';\nimport { DataSource, EntityManager, EntitySubscriberInterface, InsertEvent, RemoveEvent, SoftRemoveEvent, UpdateEvent } from 'typeorm';\nimport { SOLID_CORE_MODULE_NAME } from 'src/constants';\nimport { AgentToolRegistry } from 'src/entities/agent-tool-registry.entity';\nimport { ModuleMetadataHelperService } from 'src/helpers/module-metadata-helper.service';\nimport { AgentTool } from 'src/entities/agent-tool.entity';\nimport { AgentRegistrySubscriber } from './agent-registry.subscriber';\n\n@Injectable()\nexport class AgentToolRegistrySubscriber implements EntitySubscriberInterface<AgentToolRegistry> {\n private readonly logger = new Logger(AgentToolRegistrySubscriber.name);\n private readonly previousTools = new Map<number, { name: string; moduleName?: string }>();\n private readonly deletedTools = new Map<number, { name: string; moduleName?: string; agentIds: number[] }>();\n\n constructor(\n @InjectDataSource() private readonly dataSource: DataSource,\n private readonly moduleMetadataHelperService: ModuleMetadataHelperService,\n private readonly agentRegistrySubscriber: AgentRegistrySubscriber,\n ) {\n this.dataSource.subscribers.push(this);\n }\n\n listenTo() {\n return AgentToolRegistry;\n }\n\n async afterInsert(event: InsertEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n const tool = await this.getTool(event.manager, event.entity?.id);\n if (tool && !tool.deletedAt) await this.writeTool(tool);\n }\n\n async beforeUpdate(event: UpdateEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n const id = event.entity?.id ?? event.databaseEntity?.id;\n if (!id) return;\n const tool = await event.manager.getRepository(AgentToolRegistry).findOne({\n where: { id },\n relations: { module: true },\n withDeleted: true,\n });\n if (tool) this.previousTools.set(id, { name: tool.name, moduleName: tool.module?.name });\n }\n\n async afterUpdate(event: UpdateEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n const id = event.entity?.id ?? event.databaseEntity?.id;\n if (!id) return;\n const previous = this.previousTools.get(id);\n this.previousTools.delete(id);\n\n const tool = await this.getTool(event.manager, id);\n if (!tool) return;\n if (tool.deletedAt) {\n await this.removeTool(tool.module?.name, tool.name);\n return;\n }\n await this.writeTool(tool);\n\n if (previous && (previous.name !== tool.name || previous.moduleName !== tool.module?.name)) {\n await this.removeTool(previous.moduleName, previous.name);\n }\n }\n\n async beforeRemove(event: RemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.rememberDeletedTool(event.manager, event.entity?.id ?? event.databaseEntity?.id ?? event.entityId);\n }\n\n async beforeSoftRemove(event: SoftRemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.rememberDeletedTool(event.manager, event.entity?.id ?? event.databaseEntity?.id ?? event.entityId);\n }\n\n async afterRemove(event: RemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.removeDeletedTool(event.entity?.id ?? event.databaseEntity?.id ?? event.entityId, event.manager);\n }\n\n async afterSoftRemove(event: SoftRemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.removeDeletedTool(event.entity?.id ?? event.databaseEntity?.id ?? event.entityId, event.manager);\n }\n\n private async getTool(manager: EntityManager, id?: number): Promise<AgentToolRegistry | null> {\n if (!id) return null;\n return manager.getRepository(AgentToolRegistry).findOne({\n where: { id },\n relations: { module: true, tags: true },\n withDeleted: true,\n });\n }\n\n private async rememberDeletedTool(manager: EntityManager, id?: number): Promise<void> {\n if (!id) return;\n const tool = await manager.getRepository(AgentToolRegistry).findOne({\n where: { id },\n relations: { module: true },\n });\n if (!tool) return;\n\n // --- Agent links: capture linked agents now; the DB cascade removes these links on delete ---\n const links = await manager.getRepository(AgentTool).find({\n where: { agentToolRegistry: { id } },\n relations: { agentRegistry: true },\n });\n this.deletedTools.set(id, {\n name: tool.name,\n moduleName: tool.module?.name,\n agentIds: links.map((link) => link.agentRegistry.id),\n });\n }\n\n private async removeDeletedTool(id: number | undefined, manager: EntityManager): Promise<void> {\n if (!id) return;\n const tool = this.deletedTools.get(id);\n this.deletedTools.delete(id);\n if (!tool) return;\n\n // --- Tool update: remove the tool entry ---\n await this.removeTool(tool.moduleName, tool.name);\n\n // --- Agent update: rewrite the tool list of every agent that used it (one at a time) ---\n for (const agentId of tool.agentIds) {\n await this.agentRegistrySubscriber.writeAgentToolsToMetadata(agentId, manager);\n }\n }\n\n private async writeTool(tool: AgentToolRegistry): Promise<void> {\n const moduleName = tool.module?.name;\n if (!moduleName) throw new Error(`Module not found for tool ${tool.name}`);\n if (moduleName === SOLID_CORE_MODULE_NAME) return;\n\n const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);\n let metadata: any;\n try {\n this.logger.warn(`METADATA READ START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n metadata = JSON.parse(await fs.readFile(filePath, 'utf8'));\n this.logger.warn(`METADATA READ END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n } catch (error: any) {\n this.logger.error(`Failed to read module metadata at ${filePath}: ${error?.message ?? error}`);\n return;\n }\n const tools = Array.isArray(metadata.agenthubTools) ? metadata.agenthubTools : [];\n const index = tools.findIndex((item: { name: string }) => item.name === tool.name);\n const entry = {\n name: tool.name,\n type: tool.type,\n iconName: tool.iconName,\n description: tool.description,\n sourceCode: tool.sourceCode,\n checksum: tool.checksum,\n status: tool.status,\n tags: (tool.tags ?? []).map((tag) => tag.name).sort(),\n moduleUserKey: moduleName,\n };\n if (index === -1) tools.push(entry);\n else tools[index] = entry;\n metadata.agenthubTools = tools;\n this.logger.warn(`METADATA WRITE START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n await fs.writeFile(filePath, JSON.stringify(metadata, null, 2));\n this.logger.warn(`METADATA WRITE END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n }\n\n private async removeTool(moduleName: string | undefined, name: string): Promise<void> {\n if (!moduleName || moduleName === SOLID_CORE_MODULE_NAME) return;\n const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);\n let metadata: any;\n try {\n this.logger.warn(`METADATA READ START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n metadata = JSON.parse(await fs.readFile(filePath, 'utf8'));\n this.logger.warn(`METADATA READ END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n } catch (error: any) {\n this.logger.error(`Failed to read module metadata at ${filePath}: ${error?.message ?? error}`);\n return;\n }\n if (!Array.isArray(metadata.agenthubTools)) return;\n const tools = metadata.agenthubTools.filter((tool: { name?: string }) => tool.name !== name);\n if (tools.length === metadata.agenthubTools.length) return;\n metadata.agenthubTools = tools;\n this.logger.warn(`METADATA WRITE START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n await fs.writeFile(filePath, JSON.stringify(metadata, null, 2));\n this.logger.warn(`METADATA WRITE END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent-tool-registry.sub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AE,CAAC;gBACjD,QAAQ,CAAC,aAAa,GAAG,KAAK,CAAC;gBAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,QAAQ,EAAE,CAAC,CAAC;gBAC9F,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;gBAChE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,SAAS,QAAQ,EAAE,CAAC,CAAC;YAChG,CAAC;QACL,CAAC;QACD,MAAM,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5F,CAAC;CACJ,CAAA;AAjNY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;IAOJ,WAAA,IAAA,0BAAgB,GAAE,CAAA;qCAA8B,oBAAU;QACb,4DAA2B;QAC/B,mDAAuB;GAR5D,2BAA2B,CAiNvC","sourcesContent":["import { Injectable, Logger } from '@nestjs/common';\nimport { InjectDataSource } from '@nestjs/typeorm';\nimport * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { DataSource, EntityManager, EntitySubscriberInterface, InsertEvent, RemoveEvent, SoftRemoveEvent, UpdateEvent } from 'typeorm';\nimport { SOLID_CORE_MODULE_NAME } from 'src/constants';\nimport { AgentToolRegistry } from 'src/entities/agent-tool-registry.entity';\nimport { ModuleMetadataHelperService } from 'src/helpers/module-metadata-helper.service';\nimport { AgentTool } from 'src/entities/agent-tool.entity';\nimport { AgentRegistrySubscriber } from './agent-registry.subscriber';\n\n@Injectable()\nexport class AgentToolRegistrySubscriber implements EntitySubscriberInterface<AgentToolRegistry> {\n private readonly logger = new Logger(AgentToolRegistrySubscriber.name);\n private readonly previousTools = new Map<number, { name: string; moduleName?: string }>();\n private readonly deletedTools = new Map<number, { name: string; moduleName?: string; agentIds: number[] }>();\n\n constructor(\n @InjectDataSource() private readonly dataSource: DataSource,\n private readonly moduleMetadataHelperService: ModuleMetadataHelperService,\n private readonly agentRegistrySubscriber: AgentRegistrySubscriber,\n ) {\n this.dataSource.subscribers.push(this);\n }\n\n listenTo() {\n return AgentToolRegistry;\n }\n\n async afterInsert(event: InsertEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n const tool = await this.getTool(event.manager, event.entity?.id);\n if (tool && !tool.deletedAt) await this.writeTool(tool);\n }\n\n async beforeUpdate(event: UpdateEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n const id = event.entity?.id ?? event.databaseEntity?.id;\n if (!id) return;\n const tool = await event.manager.getRepository(AgentToolRegistry).findOne({\n where: { id },\n relations: { module: true },\n withDeleted: true,\n });\n if (tool) this.previousTools.set(id, { name: tool.name, moduleName: tool.module?.name });\n }\n\n async afterUpdate(event: UpdateEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n const id = event.entity?.id ?? event.databaseEntity?.id;\n if (!id) return;\n const previous = this.previousTools.get(id);\n this.previousTools.delete(id);\n\n const tool = await this.getTool(event.manager, id);\n if (!tool) return;\n if (tool.deletedAt) {\n await this.removeTool(tool.module?.name, tool.name);\n return;\n }\n await this.writeTool(tool);\n\n if (previous && (previous.name !== tool.name || previous.moduleName !== tool.module?.name)) {\n await this.removeTool(previous.moduleName, previous.name);\n }\n }\n\n async beforeRemove(event: RemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.rememberDeletedTool(event.manager, event.entity?.id ?? event.databaseEntity?.id ?? event.entityId);\n }\n\n async beforeSoftRemove(event: SoftRemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.rememberDeletedTool(event.manager, event.entity?.id ?? event.databaseEntity?.id ?? event.entityId);\n }\n\n async afterRemove(event: RemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.removeDeletedTool(event.entity?.id ?? event.databaseEntity?.id ?? event.entityId, event.manager);\n }\n\n async afterSoftRemove(event: SoftRemoveEvent<AgentToolRegistry>): Promise<void> {\n const solidCliRunning = process.env.SOLID_CLI_RUNNING || \"false\";\n if (solidCliRunning === \"true\") {\n return;\n }\n\n await this.removeDeletedTool(event.entity?.id ?? event.databaseEntity?.id ?? event.entityId, event.manager);\n }\n\n private async getTool(manager: EntityManager, id?: number): Promise<AgentToolRegistry | null> {\n if (!id) return null;\n return manager.getRepository(AgentToolRegistry).findOne({\n where: { id },\n relations: { module: true, tags: true },\n withDeleted: true,\n });\n }\n\n private async rememberDeletedTool(manager: EntityManager, id?: number): Promise<void> {\n if (!id) return;\n const tool = await manager.getRepository(AgentToolRegistry).findOne({\n where: { id },\n relations: { module: true },\n });\n if (!tool) return;\n\n // --- Agent links: capture linked agents now; the DB cascade removes these links on delete ---\n const links = await manager.getRepository(AgentTool).find({\n where: { agentToolRegistry: { id } },\n relations: { agentRegistry: true },\n });\n this.deletedTools.set(id, {\n name: tool.name,\n moduleName: tool.module?.name,\n agentIds: links.map((link) => link.agentRegistry.id),\n });\n }\n\n private async removeDeletedTool(id: number | undefined, manager: EntityManager): Promise<void> {\n if (!id) return;\n const tool = this.deletedTools.get(id);\n this.deletedTools.delete(id);\n if (!tool) return;\n\n // --- Tool update: remove the tool entry ---\n await this.removeTool(tool.moduleName, tool.name);\n\n // --- Agent update: rewrite the tool list of every agent that used it (one at a time) ---\n for (const agentId of tool.agentIds) {\n await this.agentRegistrySubscriber.writeAgentToolsToMetadata(agentId, manager);\n }\n }\n\n private async writeTool(tool: AgentToolRegistry): Promise<void> {\n const moduleName = tool.module?.name;\n if (!moduleName) throw new Error(`Module not found for tool ${tool.name}`);\n if (moduleName === SOLID_CORE_MODULE_NAME) return;\n\n const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);\n let metadata: any;\n try {\n this.logger.warn(`METADATA READ START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n metadata = JSON.parse(await fs.readFile(filePath, 'utf8'));\n this.logger.warn(`METADATA READ END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n } catch (error: any) {\n this.logger.error(`Failed to read module metadata at ${filePath}: ${error?.message ?? error}`);\n return;\n }\n const tools = Array.isArray(metadata.agenthubTools) ? metadata.agenthubTools : [];\n const index = tools.findIndex((item: { name: string }) => item.name === tool.name);\n const moduleRoot = path.dirname(path.dirname(filePath));\n const sourceDirectory = path.join(moduleRoot, 'agent-hub', 'tools');\n await fs.mkdir(sourceDirectory, { recursive: true });\n await fs.writeFile(path.join(sourceDirectory, `${tool.name}.py`), tool.sourceCode ?? '');\n const entry = {\n name: tool.name,\n type: tool.type,\n iconName: tool.iconName,\n description: tool.description,\n checksum: tool.checksum,\n status: tool.status,\n tags: (tool.tags ?? []).map((tag) => tag.name).sort(),\n moduleUserKey: moduleName,\n };\n if (index === -1) tools.push(entry);\n else tools[index] = entry;\n metadata.agenthubTools = tools;\n this.logger.warn(`METADATA WRITE START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n await fs.writeFile(filePath, JSON.stringify(metadata, null, 2));\n this.logger.warn(`METADATA WRITE END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n }\n\n private async removeTool(moduleName: string | undefined, name: string): Promise<void> {\n if (!moduleName || moduleName === SOLID_CORE_MODULE_NAME) return;\n const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);\n const moduleRoot = path.dirname(path.dirname(filePath));\n let metadata: any;\n try {\n this.logger.warn(`METADATA READ START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n metadata = JSON.parse(await fs.readFile(filePath, 'utf8'));\n this.logger.warn(`METADATA READ END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n } catch (error: any) {\n this.logger.error(`Failed to read module metadata at ${filePath}: ${error?.message ?? error}`);\n }\n if (Array.isArray(metadata?.agenthubTools)) {\n const tools = metadata.agenthubTools.filter((tool: { name?: string }) => tool.name !== name);\n if (tools.length !== metadata.agenthubTools.length) {\n metadata.agenthubTools = tools;\n this.logger.warn(`METADATA WRITE START pid=${process.pid} at=${Date.now()} path=${filePath}`);\n await fs.writeFile(filePath, JSON.stringify(metadata, null, 2));\n this.logger.warn(`METADATA WRITE END pid=${process.pid} at=${Date.now()} path=${filePath}`);\n }\n }\n await fs.rm(path.join(moduleRoot, 'agent-hub', 'tools', `${name}.py`), { force: true });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidxai/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22-beta.0",
|
|
4
4
|
"description": "This module is a NestJS module containing all the required core providers required by a Solid application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/plan.md
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
# Plan: Prevent Setting Key Collisions with a Backward-Compatible Namespace Bridge
|
|
2
|
+
|
|
3
|
+
## Status
|
|
4
|
+
|
|
5
|
+
Proposed implementation plan.
|
|
6
|
+
|
|
7
|
+
## Problem
|
|
8
|
+
|
|
9
|
+
`SettingService.getAllSettingsFromProviders()` currently treats a setting's bare `key` as its global identity. A custom `@SettingsProvider()` can therefore collide with a Solid Core setting when both define a generic key such as `clientID`, `secret`, `callbackURL`, or `audience`.
|
|
10
|
+
|
|
11
|
+
The current duplicate check prevents silent overwrites, but the collision causes settings initialization or cache refresh to fail at runtime.
|
|
12
|
+
|
|
13
|
+
## Goals
|
|
14
|
+
|
|
15
|
+
- Allow different settings providers to use the same local key safely.
|
|
16
|
+
- Preserve all existing Solid Core keys, database rows, callers, APIs, and provider implementations.
|
|
17
|
+
- Avoid a database schema migration.
|
|
18
|
+
- Avoid requiring every provider to maintain a separate `ProviderSettingKeys` object.
|
|
19
|
+
- Keep collision detection deterministic and fail fast for genuine duplicates.
|
|
20
|
+
- Provide a clear migration path for existing custom providers.
|
|
21
|
+
|
|
22
|
+
## Non-goals
|
|
23
|
+
|
|
24
|
+
- Renaming existing Solid Core setting keys.
|
|
25
|
+
- Migrating existing database rows to prefixed keys.
|
|
26
|
+
- Replacing the current `ss_setting.key` unique index with a composite database constraint.
|
|
27
|
+
- Automatically migrating legacy custom providers.
|
|
28
|
+
- Allowing one provider to override another provider's setting silently.
|
|
29
|
+
|
|
30
|
+
## Decision
|
|
31
|
+
|
|
32
|
+
Add an optional, stable namespace to `@SettingsProvider()`.
|
|
33
|
+
|
|
34
|
+
Providers without a namespace retain the current behavior. Providers with a namespace declare local keys, and `SettingService` converts them to canonical keys internally:
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
canonical key = <provider namespace>:<local key>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
@SettingsProvider('acme-payments')
|
|
44
|
+
@Injectable()
|
|
45
|
+
export class AcmePaymentsSettingsProvider implements ISettingsProvider {
|
|
46
|
+
getSettings(): SettingDefinition[] {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
moduleName: 'acme-payments',
|
|
50
|
+
key: 'clientID',
|
|
51
|
+
value: '',
|
|
52
|
+
level: SettingLevel.SystemAdminEditable,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The effective key used by the cache, database, admin API, and update flows is:
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
acme-payments:clientID
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
An existing provider remains unchanged:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
@SettingsProvider()
|
|
69
|
+
export class SolidCoreDefaultSettingsProvider implements ISettingsProvider {
|
|
70
|
+
// Existing bare keys remain unchanged.
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Why this approach
|
|
75
|
+
|
|
76
|
+
This preserves the existing storage and transport model: the resolved key remains the single identifier used throughout the system. The existing unique index on `ss_setting.key` continues to provide database-level protection because canonical keys are globally unique strings.
|
|
77
|
+
|
|
78
|
+
It avoids the wider and riskier changes required by a `(moduleName, key)` composite database identity, including entity migration, nullable legacy rows, DTO changes, module-aware file uploads, repository query changes, and UI contract changes.
|
|
79
|
+
|
|
80
|
+
`moduleName` remains descriptive metadata. The provider namespace is the stable machine identifier used to construct setting identity. Multiple provider classes may share a namespace as long as their effective setting keys are distinct.
|
|
81
|
+
|
|
82
|
+
## Compatibility contract
|
|
83
|
+
|
|
84
|
+
### Legacy providers
|
|
85
|
+
|
|
86
|
+
The following remains valid and behaves exactly as it does today:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
@SettingsProvider()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- Keys are not rewritten.
|
|
93
|
+
- Existing database rows remain valid.
|
|
94
|
+
- Existing `getConfigValue(key)` calls remain valid.
|
|
95
|
+
- Existing admin API payloads remain valid.
|
|
96
|
+
- Existing duplicate-key behavior remains valid.
|
|
97
|
+
|
|
98
|
+
### Namespaced providers
|
|
99
|
+
|
|
100
|
+
New and migrated custom providers use:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
@SettingsProvider('acme-payments')
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- Definitions contain local keys such as `clientID`.
|
|
107
|
+
- The framework resolves them to `acme-payments:clientID`.
|
|
108
|
+
- New database rows use the canonical key.
|
|
109
|
+
- Callers pass the local key and optional namespace to `getConfigValue()`.
|
|
110
|
+
|
|
111
|
+
No existing key is changed automatically.
|
|
112
|
+
|
|
113
|
+
### Important: adding a namespace to an existing provider
|
|
114
|
+
|
|
115
|
+
Adding a namespace to a provider that has already seeded bare keys is a data migration, not a backward-compatible metadata-only change.
|
|
116
|
+
|
|
117
|
+
For example, if the database contains `clientID` and the provider changes to `@SettingsProvider('nbf')`, the next seed looks for `nbf:clientID`. It does not rename `clientID`; it creates `nbf:clientID` with the provider default while the old row remains unused.
|
|
118
|
+
|
|
119
|
+
Before enabling the namespace in production, use an explicit, transactional provider migration that:
|
|
120
|
+
|
|
121
|
+
1. Checks whether both the legacy and canonical rows exist and aborts on conflict.
|
|
122
|
+
2. Verifies ownership using `moduleMetadata.name` where available.
|
|
123
|
+
3. Renames each allowlisted legacy key, for example `clientID` to `nbf:clientID`.
|
|
124
|
+
4. Preserves the existing value, encryption flag, level, type, user, and module relation.
|
|
125
|
+
5. Runs before settings seeding and cache refresh.
|
|
126
|
+
|
|
127
|
+
Deleting and reseeding is acceptable only when resetting values to provider defaults is intentional, such as in a disposable development environment.
|
|
128
|
+
|
|
129
|
+
## Naming rules
|
|
130
|
+
|
|
131
|
+
Provider namespaces must:
|
|
132
|
+
|
|
133
|
+
- Be explicit and stable across releases.
|
|
134
|
+
- Use lowercase letters, digits, hyphens, and optional dot-separated segments.
|
|
135
|
+
- Start with a lowercase letter.
|
|
136
|
+
- Not contain the canonical separator `:`.
|
|
137
|
+
- Not be a user-facing display label.
|
|
138
|
+
- Be stable and intentionally shared only by providers that belong to the same namespace.
|
|
139
|
+
|
|
140
|
+
Recommended validation:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const SETTINGS_NAMESPACE_PATTERN =
|
|
144
|
+
/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*$/;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Examples:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
acme-payments
|
|
151
|
+
library-management
|
|
152
|
+
com.acme.payments
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Local keys:
|
|
156
|
+
|
|
157
|
+
- Must not be empty.
|
|
158
|
+
- Must not contain `:`.
|
|
159
|
+
- Need only be unique within their provider namespace.
|
|
160
|
+
|
|
161
|
+
Reserve `solid-core` for possible future migration of Solid Core settings.
|
|
162
|
+
|
|
163
|
+
## Implementation plan
|
|
164
|
+
|
|
165
|
+
### Phase 1: Extend the provider decorator without breaking discovery
|
|
166
|
+
|
|
167
|
+
**File:** `src/decorators/settings-provider.decorator.ts`
|
|
168
|
+
|
|
169
|
+
Keep the existing boolean marker and add separate namespace metadata:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { applyDecorators, SetMetadata } from '@nestjs/common';
|
|
173
|
+
|
|
174
|
+
export const IS_SETTINGS_PROVIDER = 'IS_SETTINGS_PROVIDER';
|
|
175
|
+
export const SETTINGS_PROVIDER_NAMESPACE =
|
|
176
|
+
'SETTINGS_PROVIDER_NAMESPACE';
|
|
177
|
+
|
|
178
|
+
export const SettingsProvider = (namespace?: string) =>
|
|
179
|
+
applyDecorators(
|
|
180
|
+
SetMetadata(IS_SETTINGS_PROVIDER, true),
|
|
181
|
+
SetMetadata(SETTINGS_PROVIDER_NAMESPACE, namespace),
|
|
182
|
+
);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Keeping `IS_SETTINGS_PROVIDER` unchanged ensures that the existing discovery logic in `SolidIntrospectService` continues to work.
|
|
186
|
+
|
|
187
|
+
### Phase 2: Add a single canonical-key helper
|
|
188
|
+
|
|
189
|
+
Add a shared helper near the settings implementation:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
export const SETTINGS_KEY_SEPARATOR = ':';
|
|
193
|
+
|
|
194
|
+
export function buildSettingKey(
|
|
195
|
+
namespace: string,
|
|
196
|
+
localKey: string,
|
|
197
|
+
): string {
|
|
198
|
+
return `${namespace}${SETTINGS_KEY_SEPARATOR}${localKey}`;
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
All namespaced lookups and transformations must use this helper. Do not manually concatenate canonical keys in multiple places.
|
|
203
|
+
|
|
204
|
+
The helper should validate namespace and local-key input either directly or through provider validation performed before it is called.
|
|
205
|
+
|
|
206
|
+
### Phase 3: Resolve provider settings to canonical keys
|
|
207
|
+
|
|
208
|
+
**File:** `src/services/setting.service.ts`
|
|
209
|
+
|
|
210
|
+
When gathering settings:
|
|
211
|
+
|
|
212
|
+
1. Read optional namespace metadata from the provider class.
|
|
213
|
+
2. Validate each declared namespace.
|
|
214
|
+
3. Convert local keys to canonical keys only for namespaced providers.
|
|
215
|
+
4. Keep legacy-provider keys unchanged.
|
|
216
|
+
5. Run the duplicate check against the effective key.
|
|
217
|
+
|
|
218
|
+
Conceptual flow:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const namespace = this.reflector.get<string | undefined>(
|
|
222
|
+
SETTINGS_PROVIDER_NAMESPACE,
|
|
223
|
+
wrapper.metatype,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const effectiveKey = namespace
|
|
227
|
+
? buildSettingKey(namespace, setting.key)
|
|
228
|
+
: setting.key;
|
|
229
|
+
|
|
230
|
+
const resolvedSetting = {
|
|
231
|
+
...setting,
|
|
232
|
+
key: effectiveKey,
|
|
233
|
+
};
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The settings returned by `getAllSettingsFromProviders()` must contain effective keys. Existing downstream code can then continue using `setting.key` without learning about local keys.
|
|
237
|
+
|
|
238
|
+
Do not mutate the object returned by the provider. Create a resolved copy so repeated cache refreshes cannot double-prefix a key.
|
|
239
|
+
|
|
240
|
+
### Phase 4: Keep the current cache and persistence model
|
|
241
|
+
|
|
242
|
+
Continue indexing resolved settings by their effective key:
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
this.settingsByKey = new Map(
|
|
246
|
+
this.settings.map(setting => [setting.key, setting]),
|
|
247
|
+
);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Examples:
|
|
251
|
+
|
|
252
|
+
```text
|
|
253
|
+
Legacy/core setting: clientID
|
|
254
|
+
Namespaced setting: acme-payments:clientID
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
No entity or schema change is required. The existing unique index on `ss_setting.key` remains correct.
|
|
258
|
+
|
|
259
|
+
Because provider aggregation resolves keys before seeding and cache hydration, existing seeding, encryption, editability checks, admin updates, and file-setting flows continue to operate on one unambiguous key.
|
|
260
|
+
|
|
261
|
+
### Phase 5: Add an optional namespace to `getConfigValue()`
|
|
262
|
+
|
|
263
|
+
**File:** `src/services/setting.service.ts`
|
|
264
|
+
|
|
265
|
+
Extend the existing accessor without breaking one-argument calls:
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
getConfigValue<T = never>(settingKey: NoInfer<T>, namespace?: string)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
When a namespace is supplied, resolve the effective key before lookup:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
getConfigValue<T = never>(settingKey: NoInfer<T>, namespace?: string) {
|
|
275
|
+
const effectiveKey = namespace !== undefined
|
|
276
|
+
? buildSettingKey(namespace, settingKey as string)
|
|
277
|
+
: settingKey as string;
|
|
278
|
+
|
|
279
|
+
return this.settingsByKey.get(effectiveKey)?.value ?? null;
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Usage:
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
this.settingService.getConfigValue<AcmePaymentSetting>(
|
|
287
|
+
'clientID',
|
|
288
|
+
'acme-payments',
|
|
289
|
+
);
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Direct canonical lookup remains possible:
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
this.settingService.getConfigValue(
|
|
296
|
+
'acme-payments:clientID',
|
|
297
|
+
);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
The optional parameter removes the need for a separate `ProviderSettingKeys` object or accessor API.
|
|
301
|
+
|
|
302
|
+
If repeated creation of the accessor becomes relevant, it can later be cached by namespace; it is not necessary for the initial implementation.
|
|
303
|
+
|
|
304
|
+
### Phase 6: Improve diagnostics safely
|
|
305
|
+
|
|
306
|
+
Do not include complete setting definitions or values in collision errors. Default values may contain credentials or other secrets.
|
|
307
|
+
|
|
308
|
+
Required collision error:
|
|
309
|
+
|
|
310
|
+
```text
|
|
311
|
+
Duplicate effective setting key "acme-payments:clientID":
|
|
312
|
+
FirstProvider and SecondProvider.
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Errors should include provider class names for diagnostics but must not use class names as persistent namespaces.
|
|
316
|
+
|
|
317
|
+
### Phase 7: Document adoption
|
|
318
|
+
|
|
319
|
+
Document the following rule:
|
|
320
|
+
|
|
321
|
+
> All new custom settings providers must declare a stable namespace. Existing unnamespaced providers remain supported for backward compatibility.
|
|
322
|
+
|
|
323
|
+
Provide one complete custom-provider example using `@SettingsProvider(namespace)` and `getConfigValue(key, namespace)`.
|
|
324
|
+
|
|
325
|
+
Do not emit warnings for every legacy provider in the first release. That could add noisy logs to existing applications. Deprecation warnings may be introduced later with an explicit migration policy.
|
|
326
|
+
|
|
327
|
+
## Files expected to change
|
|
328
|
+
|
|
329
|
+
- `src/decorators/settings-provider.decorator.ts`
|
|
330
|
+
- `src/services/setting.service.ts`
|
|
331
|
+
- Unit/integration tests for settings providers and `SettingService`
|
|
332
|
+
- Settings-provider documentation or example
|
|
333
|
+
|
|
334
|
+
The following should not require changes:
|
|
335
|
+
|
|
336
|
+
- `src/entities/setting.entity.ts`
|
|
337
|
+
- Existing database migrations
|
|
338
|
+
- Existing settings DTOs
|
|
339
|
+
- Existing admin controller contract
|
|
340
|
+
- Existing Solid Core setting definitions
|
|
341
|
+
- Existing `getConfigValue()` call sites
|
|
342
|
+
|
|
343
|
+
## Test plan
|
|
344
|
+
|
|
345
|
+
### Backward compatibility
|
|
346
|
+
|
|
347
|
+
1. An existing `@SettingsProvider()` returns exactly the same keys as before.
|
|
348
|
+
2. Existing Solid Core keys remain bare.
|
|
349
|
+
3. Existing `getConfigValue<SolidCoreSetting>('clientID')` calls still resolve.
|
|
350
|
+
4. Existing database rows are read without migration.
|
|
351
|
+
5. Existing admin settings requests continue to update the same rows.
|
|
352
|
+
|
|
353
|
+
### Namespaced behavior
|
|
354
|
+
|
|
355
|
+
1. `@SettingsProvider('module-a')` with local key `clientID` resolves to `module-a:clientID`.
|
|
356
|
+
2. `module-a:clientID` and `module-b:clientID` coexist.
|
|
357
|
+
3. A legacy `clientID` and namespaced `module-a:clientID` coexist.
|
|
358
|
+
4. `getConfigValue('clientID', 'module-a')` returns the correct value.
|
|
359
|
+
5. Namespaced settings seed and hydrate from the database correctly.
|
|
360
|
+
6. Namespaced encrypted settings encrypt and decrypt correctly.
|
|
361
|
+
7. Namespaced readonly settings cannot be modified.
|
|
362
|
+
8. Namespaced file settings round-trip through multipart updates.
|
|
363
|
+
9. Admin API returns and accepts the canonical key.
|
|
364
|
+
|
|
365
|
+
### Validation
|
|
366
|
+
|
|
367
|
+
1. Two providers sharing a namespace with different local keys are allowed.
|
|
368
|
+
2. Two providers sharing a namespace and local key are rejected.
|
|
369
|
+
3. A namespaced provider declaring the same local key twice is rejected by effective-key validation.
|
|
370
|
+
4. Two legacy providers declaring the same bare key remain rejected.
|
|
371
|
+
5. Invalid namespaces are rejected.
|
|
372
|
+
6. Local keys containing `:` are rejected for namespaced providers.
|
|
373
|
+
7. Repeated cache refresh does not double-prefix keys.
|
|
374
|
+
8. Provider registration order does not change the result.
|
|
375
|
+
9. Error messages do not contain setting values.
|
|
376
|
+
|
|
377
|
+
## Rollout plan
|
|
378
|
+
|
|
379
|
+
### Release 1
|
|
380
|
+
|
|
381
|
+
- Add optional namespace support.
|
|
382
|
+
- Add canonical-key resolution.
|
|
383
|
+
- Add the optional namespace parameter to `getConfigValue()`.
|
|
384
|
+
- Keep all legacy behavior.
|
|
385
|
+
- Require namespaces in documentation for new custom providers.
|
|
386
|
+
|
|
387
|
+
### Subsequent releases
|
|
388
|
+
|
|
389
|
+
- Migrate existing custom providers individually when desired.
|
|
390
|
+
- Provide a targeted data migration for a provider only when that provider changes from legacy keys to namespaced keys.
|
|
391
|
+
- Consider opt-in warnings for unnamespaced custom providers.
|
|
392
|
+
|
|
393
|
+
### Future major version, only if needed
|
|
394
|
+
|
|
395
|
+
- Consider namespacing Solid Core settings as `solid-core:<key>`.
|
|
396
|
+
- Provide a transactional database migration and compatibility lookup window.
|
|
397
|
+
- Consider making namespaces mandatory.
|
|
398
|
+
|
|
399
|
+
These future changes are not required to solve collisions for new custom providers.
|
|
400
|
+
|
|
401
|
+
## Risks and mitigations
|
|
402
|
+
|
|
403
|
+
### Namespace changes after deployment
|
|
404
|
+
|
|
405
|
+
Changing a namespace changes every canonical key and would disconnect existing database values.
|
|
406
|
+
|
|
407
|
+
**Mitigation:** Treat namespace as an immutable persistence identifier and document that contract.
|
|
408
|
+
|
|
409
|
+
### Double prefixing
|
|
410
|
+
|
|
411
|
+
A developer may supply `acme-payments:clientID` as a local key to a namespaced provider.
|
|
412
|
+
|
|
413
|
+
**Mitigation:** Reject `:` in local keys and resolve copies rather than mutating provider definitions.
|
|
414
|
+
|
|
415
|
+
### Namespace reuse
|
|
416
|
+
|
|
417
|
+
Multiple providers may intentionally share a module namespace.
|
|
418
|
+
|
|
419
|
+
**Mitigation:** Enforce uniqueness of the complete effective key (`namespace:localKey`), not the namespace alone.
|
|
420
|
+
|
|
421
|
+
### Legacy providers remain collision-prone
|
|
422
|
+
|
|
423
|
+
Two unnamespaced legacy providers can still collide.
|
|
424
|
+
|
|
425
|
+
**Mitigation:** Preserve the existing fail-fast duplicate check and require namespaces for all new providers. Migrate legacy custom providers incrementally.
|
|
426
|
+
|
|
427
|
+
## Acceptance criteria
|
|
428
|
+
|
|
429
|
+
- No existing setting key or database row is modified by upgrading.
|
|
430
|
+
- No existing `@SettingsProvider()` implementation must change.
|
|
431
|
+
- No existing Solid Core `getConfigValue()` call must change.
|
|
432
|
+
- A new provider can declare `key: 'clientID'` under its namespace without colliding with Solid Core's `clientID`.
|
|
433
|
+
- Two different namespaces can use the same local key.
|
|
434
|
+
- Duplicate effective keys within one namespace fail deterministically.
|
|
435
|
+
- Namespaced settings work through cache, seeding, database hydration, admin updates, encryption, readonly validation, and file uploads.
|
|
436
|
+
- No setting values are exposed in duplicate or validation errors.
|
|
437
|
+
- No database migration is required for the initial release.
|
|
438
|
+
|
|
439
|
+
## Final example
|
|
440
|
+
|
|
441
|
+
Provider:
|
|
442
|
+
|
|
443
|
+
```ts
|
|
444
|
+
@SettingsProvider('acme-payments')
|
|
445
|
+
@Injectable()
|
|
446
|
+
export class AcmePaymentsSettingsProvider implements ISettingsProvider {
|
|
447
|
+
getSettings(): SettingDefinition[] {
|
|
448
|
+
return [
|
|
449
|
+
{
|
|
450
|
+
moduleName: 'acme-payments',
|
|
451
|
+
key: 'clientID',
|
|
452
|
+
value: '',
|
|
453
|
+
level: SettingLevel.SystemAdminEditable,
|
|
454
|
+
},
|
|
455
|
+
];
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Lookup:
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
const clientID = this.settingService.getConfigValue<string>(
|
|
464
|
+
'clientID',
|
|
465
|
+
'acme-payments',
|
|
466
|
+
);
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
Effective cache/database/API key:
|
|
470
|
+
|
|
471
|
+
```text
|
|
472
|
+
acme-payments:clientID
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
Existing Solid Core lookup remains unchanged:
|
|
476
|
+
|
|
477
|
+
```ts
|
|
478
|
+
const clientID = this.settingService
|
|
479
|
+
.getConfigValue<SolidCoreSetting>('clientID');
|
|
480
|
+
```
|