@solidstarters/solid-core 1.2.173 → 1.2.175
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/dev-grooming-docs/ozzy-prompts.txt +13 -0
- package/dist/config/iam.config.js +2 -2
- package/dist/config/iam.config.js.map +1 -1
- package/dist/constants/chatter-message.constants.d.ts +11 -0
- package/dist/constants/chatter-message.constants.d.ts.map +1 -0
- package/dist/constants/chatter-message.constants.js +14 -0
- package/dist/constants/chatter-message.constants.js.map +1 -0
- package/dist/controllers/ai-interaction.controller.js +1 -1
- package/dist/controllers/ai-interaction.controller.js.map +1 -1
- package/dist/controllers/authentication.controller.d.ts +1 -2
- package/dist/controllers/authentication.controller.d.ts.map +1 -1
- package/dist/controllers/chatter-message-details.controller.d.ts +0 -16
- package/dist/controllers/chatter-message-details.controller.d.ts.map +1 -1
- package/dist/controllers/chatter-message-details.controller.js +0 -109
- package/dist/controllers/chatter-message-details.controller.js.map +1 -1
- package/dist/controllers/chatter-message.controller.d.ts +10 -13
- package/dist/controllers/chatter-message.controller.d.ts.map +1 -1
- package/dist/controllers/chatter-message.controller.js +19 -88
- package/dist/controllers/chatter-message.controller.js.map +1 -1
- package/dist/controllers/service.controller.js +2 -1
- package/dist/controllers/service.controller.js.map +1 -1
- package/dist/dtos/invoke-ai-prompt.dto.d.ts +1 -0
- package/dist/dtos/invoke-ai-prompt.dto.d.ts.map +1 -1
- package/dist/dtos/invoke-ai-prompt.dto.js +6 -1
- package/dist/dtos/invoke-ai-prompt.dto.js.map +1 -1
- package/dist/entities/chatter-message-details.entity.d.ts +1 -0
- package/dist/entities/chatter-message-details.entity.d.ts.map +1 -1
- package/dist/entities/chatter-message-details.entity.js +5 -1
- package/dist/entities/chatter-message-details.entity.js.map +1 -1
- package/dist/entities/chatter-message.entity.d.ts +4 -0
- package/dist/entities/chatter-message.entity.d.ts.map +1 -1
- package/dist/entities/chatter-message.entity.js +14 -1
- package/dist/entities/chatter-message.entity.js.map +1 -1
- package/dist/entities/user.entity.d.ts +1 -0
- package/dist/entities/user.entity.d.ts.map +1 -1
- package/dist/entities/user.entity.js +5 -1
- package/dist/entities/user.entity.js.map +1 -1
- package/dist/interfaces.d.ts +2 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts +3 -2
- package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js +61 -22
- package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js.map +1 -1
- package/dist/repository/chatter-message-details.repository.d.ts.map +1 -1
- package/dist/repository/chatter-message-details.repository.js +7 -3
- package/dist/repository/chatter-message-details.repository.js.map +1 -1
- package/dist/repository/chatter-message.repository.d.ts.map +1 -1
- package/dist/repository/chatter-message.repository.js +4 -0
- package/dist/repository/chatter-message.repository.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +78 -5
- package/dist/services/ai-interaction.service.d.ts +2 -1
- package/dist/services/ai-interaction.service.d.ts.map +1 -1
- package/dist/services/ai-interaction.service.js +15 -3
- package/dist/services/ai-interaction.service.js.map +1 -1
- package/dist/services/authentication.service.d.ts +2 -3
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +4 -4
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/chatter-message.service.d.ts +16 -3
- package/dist/services/chatter-message.service.d.ts.map +1 -1
- package/dist/services/chatter-message.service.js +120 -25
- package/dist/services/chatter-message.service.js.map +1 -1
- package/dist/services/refresh-token-ids-storage.service.d.ts +2 -1
- package/dist/services/refresh-token-ids-storage.service.d.ts.map +1 -1
- package/dist/services/refresh-token-ids-storage.service.js +6 -7
- package/dist/services/refresh-token-ids-storage.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config/iam.config.ts +2 -2
- package/src/constants/chatter-message.constants.ts +11 -0
- package/src/controllers/ai-interaction.controller.ts +1 -1
- package/src/controllers/chatter-message-details.controller.ts +44 -44
- package/src/controllers/chatter-message.controller.ts +58 -38
- package/src/controllers/service.controller.ts +2 -2
- package/src/dtos/invoke-ai-prompt.dto.ts +5 -1
- package/src/entities/chatter-message-details.entity.ts +3 -0
- package/src/entities/chatter-message.entity.ts +9 -2
- package/src/entities/user.entity.ts +2 -0
- package/src/interfaces.ts +2 -1
- package/src/jobs/database/trigger-mcp-client-subscriber-database.service.ts +108 -25
- package/src/repository/chatter-message-details.repository.ts +6 -5
- package/src/repository/chatter-message.repository.ts +2 -0
- package/src/seeders/seed-data/solid-core-metadata.json +78 -5
- package/src/services/ai-interaction.service.ts +24 -3
- package/src/services/authentication.service.ts +9 -4
- package/src/services/chatter-message.service.ts +143 -24
- package/src/services/refresh-token-ids-storage.service.ts +11 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-mcp-client-subscriber-database.service.js","sourceRoot":"","sources":["../../../src/jobs/database/trigger-mcp-client-subscriber-database.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AAGpD,0EAAqE;AACrE,sFAAgF;AAEhF,mGAAqF;AACrF,0GAA8E;AAC9E,kFAA2E;AAC3E,kEAA4D;AAGrD,IAAM,kCAAkC,0CAAxC,MAAM,kCAAmC,SAAQ,gDAA2C;IAG/F,YACa,gBAAkC,EAClC,qBAA4C,EAC5C,MAAqB,EACrB,oBAA0C;QAEnD,KAAK,CAAC,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,CAAC,CAAC;QAL9C,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,WAAM,GAAN,MAAM,CAAe;QACrB,yBAAoB,GAApB,oBAAoB,CAAsB;QANtC,qCAAgC,GAAG,IAAI,eAAM,CAAC,oCAAkC,CAAC,IAAI,CAAC,CAAC;IASxG,CAAC;IA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AC;YAGH,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC;gBAC5B,IAAI,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;YAC3E,CAAC;QACL,CAAC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ,CAAA;AA3FY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,mBAAU,GAAE;qCAKsB,qCAAgB;QACX,gDAAqB;QACpC,8BAAa;QACC,6CAAoB;GAP9C,kCAAkC,CA2F9C","sourcesContent":["import { Injectable, Logger } from '@nestjs/common';\n\nimport { QueueMessage } from 'src/interfaces/mq';\nimport { MqMessageService } from '../../services/mq-message.service';\nimport { MqMessageQueueService } from '../../services/mq-message-queue.service';\nimport { QueuesModuleOptions, TriggerMcpClientOptions } from \"../../interfaces\";\nimport { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';\nimport triggerMcpClientQueueOptions from \"./trigger-mcp-client-queue-options\";\nimport { AiInteractionService } from 'src/services/ai-interaction.service';\nimport { PollerService } from 'src/services/poller.service';\n\n@Injectable()\nexport class TriggerMcpClientSubscriberDatabase extends DatabaseSubscriber<TriggerMcpClientOptions> {\n private readonly triggerMcpClientSubscriberLogger = new Logger(TriggerMcpClientSubscriberDatabase.name);\n\n constructor(\n readonly mqMessageService: MqMessageService,\n readonly mqMessageQueueService: MqMessageQueueService,\n readonly poller: PollerService,\n readonly aiInteractionService: AiInteractionService,\n ) {\n super(mqMessageService, mqMessageQueueService, poller);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...triggerMcpClientQueueOptions\n }\n }\n\n async subscribe(message: QueueMessage<TriggerMcpClientOptions>) {\n this.triggerMcpClientSubscriberLogger.debug(`Received message: ${JSON.stringify(message)}`);\n\n const codeGnerationOptions = message.payload;\n\n const aiInteraction = await this.aiInteractionService.findOne(codeGnerationOptions.aiInteractionId, {\n populate: ['user']\n });\n if (!aiInteraction) {\n const m = `Unable to identified the aiInteraction entry that triggered this job... using id: ${codeGnerationOptions.aiInteractionId}`\n this.triggerMcpClientSubscriberLogger.log(m);\n throw new Error(m);\n }\n\n // The message contains the users prompt.\n const prompt = aiInteraction.message;\n\n // Use this to invoke our mcp client\n // TODO: try / catch ... \n // Handle the rejection gracefully...\n const aiResponse = await this.aiInteractionService.runMcpPrompt(prompt);\n this.triggerMcpClientSubscriberLogger.log(`aiResponse: `);\n this.triggerMcpClientSubscriberLogger.log(JSON.stringify(aiResponse));\n\n if (!aiResponse.success) {\n this.triggerMcpClientSubscriberLogger.log(`Gen ai has returned with a false status code`);\n\n const errorsStr = aiResponse.errors.join('; ');\n\n await this.aiInteractionService.create({\n userId: aiInteraction.user.id,\n threadId: aiInteraction.threadId,\n parentInteractionId: aiInteraction.id,\n role: 'gen-ai',\n message: '-',\n contentType: aiResponse.content_type,\n errorMessage: errorsStr,\n modelUsed: aiResponse.model,\n responseTimeMs: aiResponse.duration_ms,\n metadata: JSON.stringify(aiResponse, null, 2),\n isApplied: aiInteraction.isApplied,\n status: aiResponse.success ? 'succeeded' : 'failed'\n });\n\n // update the job entry with failure... raising an error will lead the job to be marked as failed...\n throw new Error(errorsStr);\n }\n else {\n let nestedResponse = aiResponse.response.trim();\n\n const genAiInteraction = await this.aiInteractionService.create({\n userId: aiInteraction.user.id,\n threadId: aiInteraction.threadId,\n parentInteractionId: aiInteraction.id,\n role: 'gen-ai',\n message: nestedResponse,\n contentType: aiResponse.content_type,\n errorMessage: '',\n modelUsed: aiResponse.model,\n responseTimeMs: aiResponse.duration_ms,\n metadata: JSON.stringify(aiResponse, null, 2),\n isApplied: aiInteraction.isApplied,\n status: aiResponse.success ? 'succeeded' : 'failed'\n });\n\n // If the human interaction was with isAutoApply=true, then we can go ahead and autoApply.\n if (aiInteraction.isAutoApply) {\n this.aiInteractionService.applySolidAiInteraction(genAiInteraction.id);\n }\n }\n\n return aiResponse;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"trigger-mcp-client-subscriber-database.service.js","sourceR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AAC,EAAE,EAAE;gBAExD,YAAY,EAAE,EAAE;gBAEhB,SAAS,EAAE,UAAU,CAAC,KAAK;gBAC3B,cAAc,EAAE,UAAU,CAAC,WAAW;gBACtC,SAAS,EAAE,aAAa,CAAC,SAAS;gBAClC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;aACtD,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;YAGb,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC;gBAC5B,IAAI,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;YAC3E,CAAC;QACL,CAAC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ,CAAA;AA9KY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,mBAAU,GAAE;qCAKsB,qCAAgB;QACX,gDAAqB;QACpC,8BAAa;QACC,6CAAoB;GAP9C,kCAAkC,CA8K9C","sourcesContent":["import { Injectable, Logger } from '@nestjs/common';\n\nimport { QueueMessage } from 'src/interfaces/mq';\nimport { MqMessageService } from '../../services/mq-message.service';\nimport { MqMessageQueueService } from '../../services/mq-message-queue.service';\nimport { McpResponse, QueuesModuleOptions, TriggerMcpClientOptions } from \"../../interfaces\";\nimport { DatabaseSubscriber } from 'src/services/queues/database-subscriber.service';\nimport triggerMcpClientQueueOptions from \"./trigger-mcp-client-queue-options\";\nimport { AiInteractionService } from 'src/services/ai-interaction.service';\nimport { PollerService } from 'src/services/poller.service';\n\n@Injectable()\nexport class TriggerMcpClientSubscriberDatabase extends DatabaseSubscriber<TriggerMcpClientOptions> {\n private readonly triggerMcpClientSubscriberLogger = new Logger(TriggerMcpClientSubscriberDatabase.name);\n\n constructor(\n readonly mqMessageService: MqMessageService,\n readonly mqMessageQueueService: MqMessageQueueService,\n readonly poller: PollerService,\n readonly aiInteractionService: AiInteractionService,\n ) {\n super(mqMessageService, mqMessageQueueService, poller);\n }\n\n options(): QueuesModuleOptions {\n return {\n ...triggerMcpClientQueueOptions\n }\n }\n\n cleanNestedResponse(aiResponse: McpResponse) {\n let nestedResponse: any;\n\n try {\n let raw = aiResponse.response;\n\n if (typeof raw === \"string\") {\n raw = raw.trim();\n try {\n // Try to parse as JSON\n nestedResponse = JSON.parse(raw);\n } catch {\n // Not JSON, just keep as string\n nestedResponse = raw;\n }\n } else if (typeof raw === \"object\" && raw !== null) {\n // Already JSON\n nestedResponse = raw;\n } else {\n // Fallback\n nestedResponse = String(raw);\n }\n } catch (err) {\n this.triggerMcpClientSubscriberLogger.error(\"Error processing AI response:\", err);\n nestedResponse = `Error handling response: ${err?.message || String(err)}`;\n }\n\n return nestedResponse;\n }\n\n async subscribe(message: QueueMessage<TriggerMcpClientOptions>) {\n this.triggerMcpClientSubscriberLogger.debug(`Received message: ${JSON.stringify(message)}`);\n\n const codeGnerationOptions = message.payload;\n\n const aiInteraction = await this.aiInteractionService.findOne(codeGnerationOptions.aiInteractionId, {\n populate: ['user']\n });\n if (!aiInteraction) {\n const m = `Unable to identified the aiInteraction entry that triggered this job... using id: ${codeGnerationOptions.aiInteractionId}`\n this.triggerMcpClientSubscriberLogger.log(m);\n throw new Error(m);\n }\n\n // The message contains the users prompt.\n const prompt = aiInteraction.message;\n\n // Use this to invoke our mcp client\n // TODO: try / catch ... \n // Handle the rejection gracefully...\n\n // We create the aiInteraction entry first \n const genAiInteraction = await this.aiInteractionService.create({\n userId: aiInteraction.user.id,\n threadId: aiInteraction.threadId,\n parentInteractionId: aiInteraction.id,\n role: 'gen-ai',\n message: '...', // Updated in the tool\n contentType: '', // Updated in the tool\n errorMessage: '', // Updated after we receive the response\n modelUsed: '', // Updated after we receive the response\n responseTimeMs: 0, // Updated after we receive the response\n metadata: '', // Updated in the tool\n isApplied: false, // Updated after we receive the response\n status: '' // Updated after we receive the response\n });\n\n const finalPrompt = `\n # User Prompt: \n ${prompt}\n \n # System Instructions:\n - aiInteractionId: ${genAiInteraction.id}\n - moduleName:${message.payload.moduleName}\n - You will be invoking tools if needed.\n - If a tool is invoked, you must return **exactly** the raw output from the tool, without any additional formatting, commentary, or text.\n - Do not wrap the result in quotes, JSON, or markdown fences.\n - Do not explain what the result means.\n - Your final response must be identical to the tool output.\n `\n\n const aiResponse = await this.aiInteractionService.runMcpPrompt(finalPrompt);\n this.triggerMcpClientSubscriberLogger.log(`aiResponse: `);\n this.triggerMcpClientSubscriberLogger.log(JSON.stringify(aiResponse));\n\n if (!aiResponse.success) {\n this.triggerMcpClientSubscriberLogger.log(`Gen ai has returned with a false status code`);\n\n const errorsStr = aiResponse.errors.join('\\n ');\n const errorTrace = aiResponse.error_trace.join('\\n');\n\n // await this.aiInteractionService.create({\n // userId: aiInteraction.user.id,\n // threadId: aiInteraction.threadId,\n // parentInteractionId: aiInteraction.id,\n // role: 'gen-ai',\n // message: '-',\n // contentType: aiResponse.content_type,\n // errorMessage: errorsStr,\n // modelUsed: aiResponse.model,\n // responseTimeMs: aiResponse.duration_ms,\n // metadata: JSON.stringify(aiResponse, null, 2),\n // isApplied: aiInteraction.isApplied,\n // status: aiResponse.success ? 'succeeded' : 'failed'\n // });\n\n // TODO: Update the previously created genAiInteraction record with the respective error fields and save to DB\n await this.aiInteractionService.update(genAiInteraction.id, {\n // contentType: aiResponse.content_type,\n errorMessage: `${errorsStr}\\n\\n${errorTrace}`,\n modelUsed: aiResponse.model,\n responseTimeMs: aiResponse.duration_ms,\n isApplied: aiInteraction.isApplied,\n status: aiResponse.success ? 'succeeded' : 'failed'\n }, [], true);\n\n // update the job entry with failure... raising an error will lead the job to be marked as failed...\n throw new Error(errorsStr);\n }\n else {\n // let nestedResponse = this.cleanNestedResponse(aiResponse);\n\n // const genAiInteraction = await this.aiInteractionService.create({\n // userId: aiInteraction.user.id,\n // threadId: aiInteraction.threadId,\n // parentInteractionId: aiInteraction.id,\n // role: 'gen-ai',\n // message: nestedResponse,\n // contentType: aiResponse.content_type,\n // errorMessage: '',\n // modelUsed: aiResponse.model,\n // responseTimeMs: aiResponse.duration_ms,\n // metadata: JSON.stringify(aiResponse, null, 2),\n // isApplied: aiInteraction.isApplied,\n // status: aiResponse.success ? 'succeeded' : 'failed'\n // });\n\n // TODO: Update the previously created genAiInteraction record with the respective success fields and save to DB\n await this.aiInteractionService.update(genAiInteraction.id, {\n // contentType: aiResponse.content_type,\n errorMessage: '',\n // message: nestedResponse,\n modelUsed: aiResponse.model,\n responseTimeMs: aiResponse.duration_ms,\n isApplied: aiInteraction.isApplied,\n status: aiResponse.success ? 'succeeded' : 'failed'\n }, [], true);\n\n // If the human interaction was with isAutoApply=true, then we can go ahead and autoApply.\n if (aiInteraction.isAutoApply) {\n this.aiInteractionService.applySolidAiInteraction(genAiInteraction.id);\n }\n }\n\n return aiResponse;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatter-message-details.repository.d.ts","sourceRoot":"","sources":["../../src/repository/chatter-message-details.repository.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,WAAW,EACX,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAEpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAI9D,qBACa,+BAAgC,SAAQ,mBAAmB,CAAC,qBAAqB,CAAC;IAE3F,QAAQ,CAAC,UAAU,EAAE,UAAU;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IACrD,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB;gBAF9C,UAAU,EAAE,UAAU,EACtB,qBAAqB,EAAE,qBAAqB,EAC5C,sBAAsB,EAAE,sBAAsB;IAIvD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4C;IAQxE,kBAAkB,CACzB,KAAK,SAAW,EAChB,WAAW,CAAC,EAAE,WAAW,GACxB,kBAAkB,CAAC,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"chatter-message-details.repository.d.ts","sourceRoot":"","sources":["../../src/repository/chatter-message-details.repository.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,WAAW,EACX,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAEpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAI9D,qBACa,+BAAgC,SAAQ,mBAAmB,CAAC,qBAAqB,CAAC;IAE3F,QAAQ,CAAC,UAAU,EAAE,UAAU;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IACrD,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB;gBAF9C,UAAU,EAAE,UAAU,EACtB,qBAAqB,EAAE,qBAAqB,EAC5C,sBAAsB,EAAE,sBAAsB;IAIvD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4C;IAQxE,kBAAkB,CACzB,KAAK,SAAW,EAChB,WAAW,CAAC,EAAE,WAAW,GACxB,kBAAkB,CAAC,qBAAqB,CAAC;IAqC5C,eAAe,CAAC,CAAC,EACf,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EACzB,WAAW,EAAE,MAAM,EACnB,YAAY,GAAE,MAAkB,GAC/B,kBAAkB,CAAC,CAAC,CAAC;IAqBxB,OAAO,CAAC,sBAAsB;CAW/B"}
|
|
@@ -29,11 +29,13 @@ let ChatterMessageDetailsRepository = class ChatterMessageDetailsRepository exte
|
|
|
29
29
|
createQueryBuilder(alias = 'detail', queryRunner) {
|
|
30
30
|
const activeUser = this.requestContextService.getActiveUser();
|
|
31
31
|
let qb = super.createQueryBuilder(alias, queryRunner);
|
|
32
|
-
qb = qb.leftJoin(`${alias}.chatterMessage`, 'chatterMessage');
|
|
33
|
-
const [coModelName, coModelAlias] = this.getCoModelNameAndAlias();
|
|
34
|
-
qb = this.leftJoinCoModel(qb, coModelName, 'chatterMessage');
|
|
35
32
|
if (!activeUser)
|
|
36
33
|
return qb;
|
|
34
|
+
const [coModelName, coModelAlias] = this.getCoModelNameAndAlias();
|
|
35
|
+
if (!coModelName)
|
|
36
|
+
return qb;
|
|
37
|
+
qb = qb.leftJoin(`${alias}.chatterMessage`, 'chatterMessage');
|
|
38
|
+
qb = this.leftJoinCoModel(qb, coModelName, 'chatterMessage');
|
|
37
39
|
return this.securityRuleRepository.applySecurityRules(qb, coModelName, activeUser, coModelAlias);
|
|
38
40
|
}
|
|
39
41
|
leftJoinCoModel(qb, coModelName, messageAlias = 'message') {
|
|
@@ -48,6 +50,8 @@ let ChatterMessageDetailsRepository = class ChatterMessageDetailsRepository exte
|
|
|
48
50
|
if (!requestFilter)
|
|
49
51
|
return [undefined, undefined];
|
|
50
52
|
const coModelName = (0, lodash_1.get)(requestFilter, this.CO_MODEL_NAME_PATH);
|
|
53
|
+
if (!coModelName)
|
|
54
|
+
return [undefined, undefined];
|
|
51
55
|
const alias = (0, strings_1.camelize)(coModelName);
|
|
52
56
|
return [coModelName, alias];
|
|
53
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatter-message-details.repository.js","sourceRoot":"","sources":["../../src/repository/chatter-message-details.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAIiB;AACjB,oEAA4E;AAE5E,+FAAoF;AAEpF,iFAA6E;AAC7E,yEAAoE;AACpE,mEAA8D;AAC9D,mCAA0B;AAInB,IAAM,+BAA+B,GAArC,MAAM,+BAAgC,SAAQ,2CAA0C;IAC7F,YACW,UAAsB,EACtB,qBAA4C,EAC5C,sBAA8C;QAEvD,KAAK,CAAC,sDAAqB,EAAE,UAAU,EAAE,qBAAqB,EAAE,sBAAsB,CAAC,CAAC;QAJ/E,eAAU,GAAV,UAAU,CAAY;QACtB,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,2BAAsB,GAAtB,sBAAsB,CAAwB;QAItC,uBAAkB,GAAG,wCAAwC,CAAC;IADjF,CAAC;IASQ,kBAAkB,CACzB,KAAK,GAAG,QAAQ,EAChB,WAAyB;QAEzB,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,aAAa,EAAE,CAAC;QAC9D,IAAI,EAAE,GAAG,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"chatter-message-details.repository.js","sourceRoot":"","sources":["../../src/repository/chatter-message-details.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAIiB;AACjB,oEAA4E;AAE5E,+FAAoF;AAEpF,iFAA6E;AAC7E,yEAAoE;AACpE,mEAA8D;AAC9D,mCAA0B;AAInB,IAAM,+BAA+B,GAArC,MAAM,+BAAgC,SAAQ,2CAA0C;IAC7F,YACW,UAAsB,EACtB,qBAA4C,EAC5C,sBAA8C;QAEvD,KAAK,CAAC,sDAAqB,EAAE,UAAU,EAAE,qBAAqB,EAAE,sBAAsB,CAAC,CAAC;QAJ/E,eAAU,GAAV,UAAU,CAAY;QACtB,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,2BAAsB,GAAtB,sBAAsB,CAAwB;QAItC,uBAAkB,GAAG,wCAAwC,CAAC;IADjF,CAAC;IASQ,kBAAkB,CACzB,KAAK,GAAG,QAAQ,EAChB,WAAyB;QAEzB,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,aAAa,EAAE,CAAC;QAC9D,IAAI,EAAE,GAAG,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU;YAAE,OAA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,KAAK,GAAG,IAAA,kBAAQ,EAAC,WAAW,CAAC,CAAC;QACpC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;CAEF,CAAA;AA5FY,0EAA+B;0CAA/B,+BAA+B;IAD3C,IAAA,mBAAU,GAAE;qCAGY,oBAAU;QACC,+CAAqB;QACpB,iDAAsB;GAJ9C,+BAA+B,CA4F3C","sourcesContent":["import { Injectable } from '@nestjs/common';\nimport {\n DataSource,\n QueryRunner,\n SelectQueryBuilder,\n} from 'typeorm';\nimport { camelize, classify } from '@angular-devkit/core/src/utils/strings';\n\nimport { ChatterMessageDetails } from 'src/entities/chatter-message-details.entity';\nimport { ActiveUserData } from 'src/interfaces/active-user-data.interface';\nimport { RequestContextService } from 'src/services/request-context.service';\nimport { SecurityRuleRepository } from './security-rule.repository';\nimport { SolidBaseRepository } from './solid-base.repository';\nimport {get} from \"lodash\"\n\n\n@Injectable()\nexport class ChatterMessageDetailsRepository extends SolidBaseRepository<ChatterMessageDetails> {\n constructor(\n readonly dataSource: DataSource,\n readonly requestContextService: RequestContextService,\n readonly securityRuleRepository: SecurityRuleRepository,\n ) {\n super(ChatterMessageDetails, dataSource, requestContextService, securityRuleRepository);\n }\n private readonly CO_MODEL_NAME_PATH = 'filters.chatterMessage.coModelName.$eq';\n\n /**\n * Build a security-aware QB:\n * - join the real relation to ChatterMessage (alias: \"message\")\n * - left join the polymorphic co-model table using message.co_model_* fields\n * - (optionally) apply security rules on the co-model alias\n */\n override createQueryBuilder(\n alias = 'detail',\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<ChatterMessageDetails> {\n const activeUser = this.requestContextService.getActiveUser();\n let qb = super.createQueryBuilder(alias, queryRunner);\n if (!activeUser) return qb;\n\n // Example: join the \"client\" co-model (pass whatever co-model name you need)\n const [coModelName, coModelAlias] = this.getCoModelNameAndAlias();\n if (!coModelName) return qb;\n\n // Join the real relation so we can access co_model_* fields\n qb = qb.leftJoin(`${alias}.chatterMessage`, 'chatterMessage');\n qb = this.leftJoinCoModel(qb, coModelName, 'chatterMessage');\n\n // If your security rules should apply to the co-model rows, pass the co-model alias.\n // Here we use the co-model name \"client\" both as model key and alias base for consistency.\n return this.securityRuleRepository.applySecurityRules(\n qb,\n coModelName, // modelSingularName (or whatever your rules expect)\n activeUser as ActiveUserData,\n coModelAlias, // the alias we used inside leftJoinCoModel\n );\n }\n\n /**\n * Left-join the polymorphic co-model table, matching:\n * <coModelAlias>.id = <messageAlias>.co_model_entity_id\n * AND <messageAlias>.co_model_name = :model\n *\n * @param qb QB built on ChatterMessageDetails\n * @param coModelName e.g. \"client\" | \"invoice\" | ...\n * @param messageAlias alias used for joined ChatterMessage (default: \"message\")\n *\n * Notes:\n * - We resolve the entity metadata from the classified name (e.g., \"Client\"),\n * then use metadata.tablePath to get schema-qualified table.\n * - We build a stable alias from metadata.name (camelized).\n */\n leftJoinCoModel<T>(\n qb: SelectQueryBuilder<T>,\n coModelName: string,\n messageAlias: string = 'message',\n ): SelectQueryBuilder<T> {\n // Resolve entity metadata from your naming convention\n const entityName = classify(coModelName); // \"client\" -> \"Client\"\n const meta = this.dataSource.getMetadata(entityName); // throws if not registered\n // const table = meta.tablePath; // schema-qualified\n const coAlias = camelize(meta.name); // stable alias, e.g., \"client\"\n\n // LEFT JOIN \"<schema>\".\"<table>\" \"<coAlias>\"\n // ON \"<coAlias>\".\"id\" = \"message\".\"co_model_entity_id\"\n // AND \"message\".\"co_model_name\" = :model\n qb.leftJoin(\n entityName,\n coAlias,\n `\"${coAlias}\".\"id\" = \"${messageAlias}\".\"co_model_entity_id\" AND \"${messageAlias}\".\"co_model_name\" = :model`,\n { model: coModelName },\n );\n\n return qb;\n }\n\n // This uses the requestContextService.getRequestFilter method and extracts the coModelName and creates the alias and returns the name and alias tuple\n private getCoModelNameAndAlias() {\n const requestFilter = this.requestContextService.getRequestFilter();\n if (!requestFilter) return [undefined, undefined];\n\n const coModelName = get(requestFilter, this.CO_MODEL_NAME_PATH);\n if (!coModelName) return [undefined, undefined];\n\n const alias = camelize(coModelName);\n return [coModelName, alias];\n }\n\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatter-message.repository.d.ts","sourceRoot":"","sources":["../../src/repository/chatter-message.repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,qBACa,wBAAyB,SAAQ,mBAAmB,CAAC,cAAc,CAAC;IAEzE,QAAQ,CAAC,UAAU,EAAE,UAAU;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IACrD,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB;gBAF9C,UAAU,EAAE,UAAU,EACtB,qBAAqB,EAAE,qBAAqB,EAC5C,sBAAsB,EAAE,sBAAsB;IAK3D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA6B;IACvD,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"chatter-message.repository.d.ts","sourceRoot":"","sources":["../../src/repository/chatter-message.repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,qBACa,wBAAyB,SAAQ,mBAAmB,CAAC,cAAc,CAAC;IAEzE,QAAQ,CAAC,UAAU,EAAE,UAAU;IAC/B,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB;IACrD,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB;gBAF9C,UAAU,EAAE,UAAU,EACtB,qBAAqB,EAAE,qBAAqB,EAC5C,sBAAsB,EAAE,sBAAsB;IAK3D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA6B;IACvD,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAAC,cAAc,CAAC;IAkB1G,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,sBAAsB;CAUjC"}
|
|
@@ -32,6 +32,8 @@ let ChatterMessageRepository = class ChatterMessageRepository extends solid_base
|
|
|
32
32
|
if (!activeUserOrUndefined)
|
|
33
33
|
return qb;
|
|
34
34
|
const [coModelName, coModelAlias] = this.getCoModelNameAndAlias();
|
|
35
|
+
if (!coModelName)
|
|
36
|
+
return qb;
|
|
35
37
|
qb = this.leftJoinCoModel(qb, coModelName);
|
|
36
38
|
return this.securityRuleRepository.applySecurityRules(qb, coModelName, activeUserOrUndefined, coModelAlias);
|
|
37
39
|
}
|
|
@@ -47,6 +49,8 @@ let ChatterMessageRepository = class ChatterMessageRepository extends solid_base
|
|
|
47
49
|
if (!requestFilter)
|
|
48
50
|
return [undefined, undefined];
|
|
49
51
|
const coModelName = (0, lodash_1.get)(requestFilter, this.CO_MODEL_NAME_PATH);
|
|
52
|
+
if (!coModelName)
|
|
53
|
+
return [undefined, undefined];
|
|
50
54
|
const alias = (0, strings_1.camelize)(coModelName);
|
|
51
55
|
return [coModelName, alias];
|
|
52
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatter-message.repository.js","sourceRoot":"","sources":["../../src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AA,kBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,EAAE,CAAC,QAAQ,CACP,UAAU,EACV,KAAK,EAEL,GAAG,KAAK,mEAAmE,EAC3E,EAAE,KAAK,EAAE,WAAW,EAAE,CACzB,CAAC;QACF,OAAO,EAAE,CAAC;IAEd,CAAC;IAGO,sBAAsB;QAC1B,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;QACpE,IAAI,CAAC,aAAa;YAAE,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAElD,MAAM,WAAW,GAAG,IAAA,YAAG,EAAC,aAAa,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAChE,MAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,WAAW,CAAC,CAAC;QACpC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;CAEJ,CAAA;
|
|
1
|
+
{"version":3,"file":"chatter-message.repository.js","sourceRoot":"","sources":["../../src/repository/chatter-message.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oEAA4E;AAC5E,2CAA4C;AAC5C,+EAAqE;AAErE,iFAA6E;AAC7E,qCAAsE;AACtE,yEAAoE;AACpE,mEAA8D;AAC9D,mCAA0B;AAGnB,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,2CAAmC;IAC7E,YACa,UAAsB,EACtB,qBAA4C,EAC5C,sBAA8C;QAEvD,KAAK,CAAC,uCAAc,EAAE,UAAU,EAAE,qBAAqB,EAAE,sBAAsB,CAAC,CAAC;QAJxE,eAAU,GAAV,UAAU,CAAY;QACtB,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,2BAAsB,GAAtB,sBAAsB,CAAwB;QAK1C,uBAAkB,GAAG,yBAAyB,CAAC;IAFhE,CAAC;IAGQ,kBAAkB,CAAC,KAAc,EAAE,WAAyB;QACjE,MAAM,qBAAqB,GAAG,IAAI,CAA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AK,GAAG,IAAA,kBAAQ,EAAC,WAAW,CAAC,CAAC;QACpC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;CAEJ,CAAA;AA1DY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAGgB,oBAAU;QACC,+CAAqB;QACpB,iDAAsB;GAJlD,wBAAwB,CA0DpC","sourcesContent":["import { camelize, classify } from \"@angular-devkit/core/src/utils/strings\";\nimport { Injectable } from \"@nestjs/common\";\nimport { ChatterMessage } from \"src/entities/chatter-message.entity\";\nimport { ActiveUserData } from \"src/interfaces/active-user-data.interface\";\nimport { RequestContextService } from \"src/services/request-context.service\";\nimport { DataSource, QueryRunner, SelectQueryBuilder } from \"typeorm\";\nimport { SecurityRuleRepository } from \"./security-rule.repository\";\nimport { SolidBaseRepository } from \"./solid-base.repository\";\nimport {get} from \"lodash\"\n\n@Injectable()\nexport class ChatterMessageRepository extends SolidBaseRepository<ChatterMessage> {\n constructor(\n readonly dataSource: DataSource,\n readonly requestContextService: RequestContextService,\n readonly securityRuleRepository: SecurityRuleRepository,\n ) {\n super(ChatterMessage, dataSource, requestContextService, securityRuleRepository);\n }\n\n private readonly CO_MODEL_NAME_PATH = 'filters.coModelName.$eq';\n override createQueryBuilder(alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<ChatterMessage> {\n const activeUserOrUndefined = this.requestContextService.getActiveUser();\n let qb = super.createQueryBuilder(alias, queryRunner);\n if (!activeUserOrUndefined) return qb;\n \n //Left join on the associated chatter model entity\n const [coModelName, coModelAlias] = this.getCoModelNameAndAlias();\n if (!coModelName) return qb;\n qb = this.leftJoinCoModel(qb, coModelName);\n \n return this.securityRuleRepository.applySecurityRules(\n qb,\n coModelName,\n activeUserOrUndefined as ActiveUserData,\n coModelAlias\n );\n }\n\n private leftJoinCoModel<ChatterMessage>(\n qb: SelectQueryBuilder<ChatterMessage>,\n coModelName: string\n ) {\n // const Target = resolveEntityFromCoModelName(coModelName); // your mapping\n const entityName = classify(coModelName)\n const meta = this.dataSource.getMetadata(entityName);\n const alias = camelize(meta.name);\n qb.leftJoin(\n entityName,\n alias,\n // `${alias}.id = entity.co_model_entity_id`,\n `${alias}.id = entity.co_model_entity_id AND entity.co_model_name = :model`,\n { model: coModelName }\n );\n return qb;\n // return qb.leftJoin(Target, alias, `${alias}.id = entity.co_model_entity_id`);\n }\n\n // This uses the requestContextService.getRequestFilter method and extracts the coModelName and creates the alias and returns the name and alias tuple\n private getCoModelNameAndAlias() {\n const requestFilter = this.requestContextService.getRequestFilter();\n if (!requestFilter) return [undefined, undefined];\n\n const coModelName = get(requestFilter, this.CO_MODEL_NAME_PATH);\n if (!coModelName) return [undefined, undefined];\n const alias = camelize(coModelName);\n return [coModelName, alias];\n }\n\n}"]}
|
|
@@ -3748,7 +3748,8 @@
|
|
|
3748
3748
|
"selectionStaticValues": [
|
|
3749
3749
|
"audit_insert:audit_insert",
|
|
3750
3750
|
"audit_update:audit_update",
|
|
3751
|
-
"audit_delete:audit_delete"
|
|
3751
|
+
"audit_delete:audit_delete",
|
|
3752
|
+
"custom:custom"
|
|
3752
3753
|
]
|
|
3753
3754
|
},
|
|
3754
3755
|
{
|
|
@@ -3835,6 +3836,30 @@
|
|
|
3835
3836
|
"columnName": null,
|
|
3836
3837
|
"relationJoinTableName": "",
|
|
3837
3838
|
"isRelationManyToManyOwner": null
|
|
3839
|
+
},
|
|
3840
|
+
{
|
|
3841
|
+
"name": "modelDisplayName",
|
|
3842
|
+
"displayName": "Model Display Name",
|
|
3843
|
+
"type": "shortText",
|
|
3844
|
+
"ormType": "text",
|
|
3845
|
+
"required": false,
|
|
3846
|
+
"unique": false,
|
|
3847
|
+
"index": false,
|
|
3848
|
+
"private": false,
|
|
3849
|
+
"encrypt": false,
|
|
3850
|
+
"isSystem": false
|
|
3851
|
+
},
|
|
3852
|
+
{
|
|
3853
|
+
"name": "modelUserKey",
|
|
3854
|
+
"displayName": "Model User Key",
|
|
3855
|
+
"type": "shortText",
|
|
3856
|
+
"ormType": "text",
|
|
3857
|
+
"required": false,
|
|
3858
|
+
"unique": false,
|
|
3859
|
+
"index": false,
|
|
3860
|
+
"private": false,
|
|
3861
|
+
"encrypt": false,
|
|
3862
|
+
"isSystem": false
|
|
3838
3863
|
}
|
|
3839
3864
|
]
|
|
3840
3865
|
},
|
|
@@ -3910,6 +3935,19 @@
|
|
|
3910
3935
|
"encrypt": false,
|
|
3911
3936
|
"isSystem": false
|
|
3912
3937
|
},
|
|
3938
|
+
{
|
|
3939
|
+
"name": "fieldDisplayName",
|
|
3940
|
+
"displayName": "Field Display Name",
|
|
3941
|
+
"type": "shortText",
|
|
3942
|
+
"ormType": "varchar",
|
|
3943
|
+
"length": 512,
|
|
3944
|
+
"required": false,
|
|
3945
|
+
"unique": false,
|
|
3946
|
+
"index": false,
|
|
3947
|
+
"private": false,
|
|
3948
|
+
"encrypt": false,
|
|
3949
|
+
"isSystem": false
|
|
3950
|
+
},
|
|
3913
3951
|
{
|
|
3914
3952
|
"name": "chatterMessage",
|
|
3915
3953
|
"displayName": "Chatter Message",
|
|
@@ -12059,7 +12097,7 @@
|
|
|
12059
12097
|
{
|
|
12060
12098
|
"type": "field",
|
|
12061
12099
|
"attrs": {
|
|
12062
|
-
"name": "
|
|
12100
|
+
"name": "contentType"
|
|
12063
12101
|
}
|
|
12064
12102
|
},
|
|
12065
12103
|
{
|
|
@@ -12067,6 +12105,24 @@
|
|
|
12067
12105
|
"attrs": {
|
|
12068
12106
|
"name": "responseTimeMs"
|
|
12069
12107
|
}
|
|
12108
|
+
},
|
|
12109
|
+
{
|
|
12110
|
+
"type": "field",
|
|
12111
|
+
"attrs": {
|
|
12112
|
+
"name": "inputTokens"
|
|
12113
|
+
}
|
|
12114
|
+
},
|
|
12115
|
+
{
|
|
12116
|
+
"type": "field",
|
|
12117
|
+
"attrs": {
|
|
12118
|
+
"name": "outputTokens"
|
|
12119
|
+
}
|
|
12120
|
+
},
|
|
12121
|
+
{
|
|
12122
|
+
"type": "field",
|
|
12123
|
+
"attrs": {
|
|
12124
|
+
"name": "totalTokens"
|
|
12125
|
+
}
|
|
12070
12126
|
}
|
|
12071
12127
|
]
|
|
12072
12128
|
}
|
|
@@ -12184,6 +12240,24 @@
|
|
|
12184
12240
|
"attrs": {
|
|
12185
12241
|
"name": "parentInteraction"
|
|
12186
12242
|
}
|
|
12243
|
+
},
|
|
12244
|
+
{
|
|
12245
|
+
"type": "field",
|
|
12246
|
+
"attrs": {
|
|
12247
|
+
"name": "inputTokens"
|
|
12248
|
+
}
|
|
12249
|
+
},
|
|
12250
|
+
{
|
|
12251
|
+
"type": "field",
|
|
12252
|
+
"attrs": {
|
|
12253
|
+
"name": "outputTokens"
|
|
12254
|
+
}
|
|
12255
|
+
},
|
|
12256
|
+
{
|
|
12257
|
+
"type": "field",
|
|
12258
|
+
"attrs": {
|
|
12259
|
+
"name": "totalTokens"
|
|
12260
|
+
}
|
|
12187
12261
|
}
|
|
12188
12262
|
]
|
|
12189
12263
|
}
|
|
@@ -12249,7 +12323,7 @@
|
|
|
12249
12323
|
"type": "column",
|
|
12250
12324
|
"attrs": {
|
|
12251
12325
|
"name": "col-meta",
|
|
12252
|
-
"label": "
|
|
12326
|
+
"label": "",
|
|
12253
12327
|
"className": "col-12"
|
|
12254
12328
|
},
|
|
12255
12329
|
"children": [
|
|
@@ -12257,8 +12331,7 @@
|
|
|
12257
12331
|
"type": "field",
|
|
12258
12332
|
"attrs": {
|
|
12259
12333
|
"name": "metadata",
|
|
12260
|
-
"
|
|
12261
|
-
"editorLanguage": "json"
|
|
12334
|
+
"height": "80vh"
|
|
12262
12335
|
}
|
|
12263
12336
|
}
|
|
12264
12337
|
]
|
|
@@ -10,6 +10,7 @@ import { AiInteraction } from '../entities/ai-interaction.entity';
|
|
|
10
10
|
import { McpResponse, TriggerMcpClientOptions } from 'src/interfaces';
|
|
11
11
|
import { PublisherFactory } from './queues/publisher-factory.service';
|
|
12
12
|
import { McpToolResponseHandlerFactory } from './mcp-tool-response-handlers/mcp-tool-response-handler-factory.service';
|
|
13
|
+
import { InvokeAiPromptDto } from 'src/dtos/invoke-ai-prompt.dto';
|
|
13
14
|
export declare class AiInteractionService extends CRUDService<AiInteraction> {
|
|
14
15
|
readonly modelMetadataService: ModelMetadataService;
|
|
15
16
|
readonly moduleMetadataService: ModuleMetadataService;
|
|
@@ -24,7 +25,7 @@ export declare class AiInteractionService extends CRUDService<AiInteraction> {
|
|
|
24
25
|
readonly mcpToolResponseHandlerFactory: McpToolResponseHandlerFactory;
|
|
25
26
|
private readonly logger;
|
|
26
27
|
constructor(modelMetadataService: ModelMetadataService, moduleMetadataService: ModuleMetadataService, configService: ConfigService, fileService: FileService, discoveryService: DiscoveryService, crudHelperService: CrudHelperService, entityManager: EntityManager, repo: Repository<AiInteraction>, moduleRef: ModuleRef, publisherFactory: PublisherFactory<TriggerMcpClientOptions>, mcpToolResponseHandlerFactory: McpToolResponseHandlerFactory);
|
|
27
|
-
triggerMcpClientJob(
|
|
28
|
+
triggerMcpClientJob(dto: InvokeAiPromptDto, userId: number, isAutoApply?: boolean, threadId?: string): Promise<any>;
|
|
28
29
|
runMcpPrompt(prompt: string): Promise<McpResponse>;
|
|
29
30
|
cleanResponse(response: string): string;
|
|
30
31
|
applySolidAiInteraction(id: number): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-interaction.service.d.ts","sourceRoot":"","sources":["../../src/services/ai-interaction.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EA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
|
79
79
|
this.mcpToolResponseHandlerFactory = mcpToolResponseHandlerFactory;
|
|
80
80
|
this.logger = new common_1.Logger(AiInteractionService_1.name);
|
|
81
81
|
}
|
|
82
|
-
async triggerMcpClientJob(
|
|
82
|
+
async triggerMcpClientJob(dto, userId, isAutoApply = false, threadId = null) {
|
|
83
83
|
const aiInteraction = await this.create({
|
|
84
84
|
userId: userId,
|
|
85
85
|
threadId: threadId ? threadId : `thread-${userId}`,
|
|
86
86
|
role: 'human',
|
|
87
|
-
message: prompt,
|
|
87
|
+
message: dto.prompt,
|
|
88
88
|
contentType: '',
|
|
89
89
|
errorMessage: '',
|
|
90
90
|
modelUsed: '',
|
|
@@ -95,6 +95,7 @@ let AiInteractionService = AiInteractionService_1 = class AiInteractionService e
|
|
|
95
95
|
const m = {
|
|
96
96
|
payload: {
|
|
97
97
|
aiInteractionId: aiInteraction.id,
|
|
98
|
+
moduleName: dto.moduleName
|
|
98
99
|
},
|
|
99
100
|
parentEntity: 'aiInteraction',
|
|
100
101
|
parentEntityId: aiInteraction.id,
|
|
@@ -147,7 +148,18 @@ let AiInteractionService = AiInteractionService_1 = class AiInteractionService e
|
|
|
147
148
|
try {
|
|
148
149
|
this.logger.log(`Python script exited with zero exit code: ${stdout}`);
|
|
149
150
|
const raw = JSON.parse(stdout);
|
|
150
|
-
|
|
151
|
+
let parsedResponse = raw.response;
|
|
152
|
+
try {
|
|
153
|
+
parsedResponse = JSON.parse(raw.response);
|
|
154
|
+
}
|
|
155
|
+
catch (ex) {
|
|
156
|
+
this.logger.warn(`Attempting to parse mcp client response assuming it is JSON, however it is not: ${parsedResponse}`);
|
|
157
|
+
}
|
|
158
|
+
const enrichedRaw = {
|
|
159
|
+
...raw,
|
|
160
|
+
response: parsedResponse,
|
|
161
|
+
};
|
|
162
|
+
resolve(enrichedRaw);
|
|
151
163
|
}
|
|
152
164
|
catch (err) {
|
|
153
165
|
reject(new Error(`Mcp Invocation Failed: ${err.message}`));
|
|
@@ -1 +1 @@
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EnE,OAAO,0BAA0B,CAAC;IACpC,CAAC;CACF,CAAA;AAtMY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,6BAAmB,GAAE,CAAA;IAErB,WAAA,IAAA,0BAAgB,EAAC,qCAAa,EAAE,SAAS,CAAC,CAAA;qCARZ,6CAAoB;QACnB,+CAAqB;QAC7B,sBAAa;QACf,0BAAW;QACN,uBAAgB;QACf,uCAAiB;QAErB,uBAAa;QAEtB,oBAAU;QACL,gBAAS;QACF,4CAAgB;QAEH,yEAA6B;GAjB5D,oBAAoB,CAsMhC","sourcesContent":["import { BadRequestException, Logger, Injectable } from '@nestjs/common';\nimport { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';\nimport { DiscoveryService, ModuleRef } from \"@nestjs/core\";\nimport { EntityManager, Repository } from 'typeorm';\n\nimport { CRUDService } from 'src/services/crud.service';\nimport { ModelMetadataService } from 'src/services/model-metadata.service';\nimport { ModuleMetadataService } from 'src/services/module-metadata.service';\nimport { ConfigService } from '@nestjs/config';\nimport { FileService } from 'src/services/file.service';\nimport { CrudHelperService } from 'src/services/crud-helper.service';\nimport { spawn } from 'child_process';\nimport { AiInteraction } from '../entities/ai-interaction.entity';\nimport * as fs from 'fs/promises';\nimport { McpResponse, TriggerMcpClientOptions } from 'src/interfaces';\nimport { PublisherFactory } from './queues/publisher-factory.service';\nimport { RequestContextService } from './request-context.service';\nimport { ActiveUserData } from 'src/interfaces/active-user-data.interface';\nimport { McpToolResponseHandlerFactory } from './mcp-tool-response-handlers/mcp-tool-response-handler-factory.service';\nimport { ERROR_MESSAGES } from 'src/constants/error-messages';\n\n@Injectable()\nexport class AiInteractionService extends CRUDService<AiInteraction> {\n private readonly logger = new Logger(AiInteractionService.name);\n\n constructor(\n readonly modelMetadataService: ModelMetadataService,\n readonly moduleMetadataService: ModuleMetadataService,\n readonly configService: ConfigService,\n readonly fileService: FileService,\n readonly discoveryService: DiscoveryService,\n readonly crudHelperService: CrudHelperService,\n @InjectEntityManager()\n readonly entityManager: EntityManager,\n @InjectRepository(AiInteraction, 'default')\n readonly repo: Repository<AiInteraction>,\n readonly moduleRef: ModuleRef,\n readonly publisherFactory: PublisherFactory<TriggerMcpClientOptions>,\n // readonly requestContextService: RequestContextService,\n readonly mcpToolResponseHandlerFactory: McpToolResponseHandlerFactory,\n\n ) {\n super(modelMetadataService, moduleMetadataService, configService, fileService, discoveryService, crudHelperService, entityManager, repo, 'aiInteraction', 'solid-core', moduleRef);\n }\n\n async triggerMcpClientJob(prompt: string, userId: number, isAutoApply: boolean = false, threadId: string = null): Promise<any> {\n // const activeUser: ActiveUserData = this.requestContextService.getActiveUser();\n\n const aiInteraction = await this.create({\n userId: userId,\n threadId: threadId ? threadId : `thread-${userId}`,\n role: 'human',\n message: prompt,\n contentType: '',\n errorMessage: '',\n modelUsed: '',\n responseTimeMs: 0,\n metadata: '',\n isAutoApply: isAutoApply\n });\n const m = {\n payload: {\n aiInteractionId: aiInteraction.id,\n },\n parentEntity: 'aiInteraction',\n parentEntityId: aiInteraction.id,\n };\n\n const queueMessageId = await this.publisherFactory.publish(m, 'TriggerMcpClientPublisher');\n\n return {\n queueMessageId: queueMessageId,\n aiInteractionId: aiInteraction.id\n }\n }\n\n /**\n * Runs the Python MCP client with a prompt and returns the parsed JSON embedded in the 'response'.\n * @param prompt - The question or instruction to send to the MCP client.\n * @returns The parsed object inside the 'response' field of the JSON output.\n */\n async runMcpPrompt(prompt: string): Promise<McpResponse> {\n const pythonExecutable = process.env.MCP_PYTHON_EXECUTABLE;\n const mcpClient = process.env.MCP_CLIENT;\n\n // TODO: We can return an error if the above env variables are not properly setup...\n if (!pythonExecutable || !mcpClient) {\n throw new BadRequestException(ERROR_MESSAGES.PYTHON_EXECUTABLE_NOT_CONFIGURED);\n }\n\n // Check if both paths are valid and accessible\n try {\n const [pyStat, clientStat] = await Promise.all([\n fs.stat(pythonExecutable),\n fs.stat(mcpClient),\n ]);\n\n if (!pyStat.isFile()) {\n throw new BadRequestException(`MCP_PYTHON_EXECUTABLE path is not a file: ${pythonExecutable}`);\n }\n\n if (!clientStat.isFile()) {\n throw new BadRequestException(`MCP_CLIENT path is not a file: ${mcpClient}`);\n }\n\n } catch (err: any) {\n throw new BadRequestException(`Invalid MCP executable or client path: ${err.message}`);\n }\n\n // TODO: Refactor to use the command.service.ts instead...\n return new Promise((resolve, reject) => {\n this.logger.log(`Attempting to run command:`)\n this.logger.log(`${pythonExecutable} ${mcpClient} \"${prompt}\"`);\n\n const python = spawn(pythonExecutable, [mcpClient, `\"${prompt}\"`]);\n\n let stdout = '';\n let stderr = '';\n\n python.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n python.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n python.on('close', (code) => {\n this.logger.log(`Python script exited with code ${code}`);\n\n if (code !== 0) {\n this.logger.error(`Python script exited with a non-zero exit code: ${stderr}`);\n return reject(new Error(`Python script exited with a non-zero exit code: ${stderr}`));\n }\n\n try {\n this.logger.log(`Python script exited with zero exit code: ${stdout}`);\n const raw: McpResponse = JSON.parse(stdout);\n\n // if (!raw.success) {\n // return reject(new Error(`MCP error: ${raw.errors?.join(', ')}`));\n // }\n // let cleaned = raw.response.trim();\n\n // Don't need to re-parse this...\n // const parsed = JSON.parse(cleaned);\n // resolve(cleaned);\n\n resolve(raw);\n } catch (err: any) {\n reject(new Error(`Mcp Invocation Failed: ${err.message}`));\n }\n });\n });\n }\n\n cleanResponse(response: string) {\n this.logger.log(`mcp server response is: ${response}`);\n\n // Remove markdown-style code block wrapper\n if (response.startsWith('```json')) {\n response = response.replace(/^```json/, '').trim();\n }\n if (response.endsWith('```')) {\n response = response.replace(/```$/, '').trim();\n }\n this.logger.log(`mcp server response after removing doc tags is: ${response}`);\n\n return response;\n }\n\n async applySolidAiInteraction(id: number) {\n // Fetch the aiInteraction\n const aiInteraction = await this.findOne(id, {\n populate: ['user']\n });\n if (!aiInteraction) {\n const m = `Unable to identified the aiInteraction entry that triggered this job... using id: ${id}`\n\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(m);\n }\n\n // TODO: Validation: Check if JSON.parse(metadata).tools_invoked starts with solid_\n let metadata = {};\n try {\n metadata = JSON.parse(aiInteraction.metadata);\n }\n catch (e) {\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(e);\n }\n\n const toolsInvoked = metadata['tools_invoked'];\n if (!toolsInvoked) {\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(ERROR_MESSAGES.UNABLE_TO_RESOLVE_SOLID_COMMAND);\n }\n\n // TODO: OPTIMISATION for chained tool invocation, for now we are assuming only 1 tool was used.\n const toolInvoked = toolsInvoked[0];\n\n // TODO: use the toolInvoked to identify a service using some convention.\n // TODO: Eg. if toolInvoked is solid_create_module <> SolidCreateModuleMcpToolHandler ... create a factory class to do this mapping and identify the relevant provider. \n const mcpToolHandler = this.mcpToolResponseHandlerFactory.getInstance(toolInvoked);\n if (!mcpToolHandler) {\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(ERROR_MESSAGES.UNABLE_TO_RESOLVE_MCP_HANDLER);\n }\n\n const handlerApplicationResponse = await mcpToolHandler.apply(aiInteraction);\n\n // TODO: This provider to implement an interface - IMcpToolResponseHandler ... apply(aiInteraction: AiInteraction)\n // throw new Error('Method not implemented.');\n\n // Mark the interaction as applied\n await this.update(aiInteraction.id, { isApplied: true }, [], true);\n\n return handlerApplicationResponse;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ai-interaction.service.js","sourceRoot":"","sources":["../../src/services/ai-interaction.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyE;AACzE,6CAAwE;AACxE,uCAA2D;AAC3D,qCAAoD;AAEpD,iDAAwD;AACxD,qEAA2E;AAC3E,uEAA6E;AAC7E,2CAA+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Aa,CAAC,CAAC;QAM7E,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QAEnE,OAAO,0BAA0B,CAAC;IACpC,CAAC;CACF,CAAA;AA1NY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAWR,WAAA,IAAA,6BAAmB,GAAE,CAAA;IAErB,WAAA,IAAA,0BAAgB,EAAC,qCAAa,EAAE,SAAS,CAAC,CAAA;qCARZ,6CAAoB;QACnB,+CAAqB;QAC7B,sBAAa;QACf,0BAAW;QACN,uBAAgB;QACf,uCAAiB;QAErB,uBAAa;QAEtB,oBAAU;QACL,gBAAS;QACF,4CAAgB;QAEH,yEAA6B;GAjB5D,oBAAoB,CA0NhC","sourcesContent":["import { BadRequestException, Logger, Injectable } from '@nestjs/common';\nimport { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';\nimport { DiscoveryService, ModuleRef } from \"@nestjs/core\";\nimport { EntityManager, Repository } from 'typeorm';\n\nimport { CRUDService } from 'src/services/crud.service';\nimport { ModelMetadataService } from 'src/services/model-metadata.service';\nimport { ModuleMetadataService } from 'src/services/module-metadata.service';\nimport { ConfigService } from '@nestjs/config';\nimport { FileService } from 'src/services/file.service';\nimport { CrudHelperService } from 'src/services/crud-helper.service';\nimport { spawn } from 'child_process';\nimport { AiInteraction } from '../entities/ai-interaction.entity';\nimport * as fs from 'fs/promises';\nimport { McpResponse, TriggerMcpClientOptions } from 'src/interfaces';\nimport { PublisherFactory } from './queues/publisher-factory.service';\nimport { RequestContextService } from './request-context.service';\nimport { ActiveUserData } from 'src/interfaces/active-user-data.interface';\nimport { McpToolResponseHandlerFactory } from './mcp-tool-response-handlers/mcp-tool-response-handler-factory.service';\nimport { ERROR_MESSAGES } from 'src/constants/error-messages';\nimport { InvokeAiPromptDto } from 'src/dtos/invoke-ai-prompt.dto';\n\n@Injectable()\nexport class AiInteractionService extends CRUDService<AiInteraction> {\n private readonly logger = new Logger(AiInteractionService.name);\n\n constructor(\n readonly modelMetadataService: ModelMetadataService,\n readonly moduleMetadataService: ModuleMetadataService,\n readonly configService: ConfigService,\n readonly fileService: FileService,\n readonly discoveryService: DiscoveryService,\n readonly crudHelperService: CrudHelperService,\n @InjectEntityManager()\n readonly entityManager: EntityManager,\n @InjectRepository(AiInteraction, 'default')\n readonly repo: Repository<AiInteraction>,\n readonly moduleRef: ModuleRef,\n readonly publisherFactory: PublisherFactory<TriggerMcpClientOptions>,\n // readonly requestContextService: RequestContextService,\n readonly mcpToolResponseHandlerFactory: McpToolResponseHandlerFactory,\n\n ) {\n super(modelMetadataService, moduleMetadataService, configService, fileService, discoveryService, crudHelperService, entityManager, repo, 'aiInteraction', 'solid-core', moduleRef);\n }\n\n async triggerMcpClientJob(dto: InvokeAiPromptDto, userId: number, isAutoApply: boolean = false, threadId: string = null): Promise<any> {\n // const activeUser: ActiveUserData = this.requestContextService.getActiveUser();\n\n const aiInteraction = await this.create({\n userId: userId,\n threadId: threadId ? threadId : `thread-${userId}`,\n role: 'human',\n message: dto.prompt,\n contentType: '',\n errorMessage: '',\n modelUsed: '',\n responseTimeMs: 0,\n metadata: '',\n isAutoApply: isAutoApply\n });\n const m = {\n payload: {\n aiInteractionId: aiInteraction.id,\n moduleName:dto.moduleName\n },\n parentEntity: 'aiInteraction',\n parentEntityId: aiInteraction.id,\n };\n\n const queueMessageId = await this.publisherFactory.publish(m, 'TriggerMcpClientPublisher');\n\n return {\n queueMessageId: queueMessageId,\n aiInteractionId: aiInteraction.id\n }\n }\n\n /**\n * Runs the Python MCP client with a prompt and returns the parsed JSON embedded in the 'response'.\n * @param prompt - The question or instruction to send to the MCP client.\n * @returns The parsed object inside the 'response' field of the JSON output.\n */\n async runMcpPrompt(prompt: string): Promise<McpResponse> {\n const pythonExecutable = process.env.MCP_PYTHON_EXECUTABLE;\n const mcpClient = process.env.MCP_CLIENT;\n\n // TODO: We can return an error if the above env variables are not properly setup...\n if (!pythonExecutable || !mcpClient) {\n throw new BadRequestException(ERROR_MESSAGES.PYTHON_EXECUTABLE_NOT_CONFIGURED);\n }\n\n // Check if both paths are valid and accessible\n try {\n const [pyStat, clientStat] = await Promise.all([\n fs.stat(pythonExecutable),\n fs.stat(mcpClient),\n ]);\n\n if (!pyStat.isFile()) {\n throw new BadRequestException(`MCP_PYTHON_EXECUTABLE path is not a file: ${pythonExecutable}`);\n }\n\n if (!clientStat.isFile()) {\n throw new BadRequestException(`MCP_CLIENT path is not a file: ${mcpClient}`);\n }\n\n } catch (err: any) {\n throw new BadRequestException(`Invalid MCP executable or client path: ${err.message}`);\n }\n\n // TODO: Refactor to use the command.service.ts instead...\n return new Promise((resolve, reject) => {\n this.logger.log(`Attempting to run command:`)\n this.logger.log(`${pythonExecutable} ${mcpClient} \"${prompt}\"`);\n\n const python = spawn(pythonExecutable, [mcpClient, `\"${prompt}\"`]);\n\n let stdout = '';\n let stderr = '';\n\n python.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n python.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n python.on('close', (code) => {\n this.logger.log(`Python script exited with code ${code}`);\n\n if (code !== 0) {\n this.logger.error(`Python script exited with a non-zero exit code: ${stderr}`);\n return reject(new Error(`Python script exited with a non-zero exit code: ${stderr}`));\n }\n\n try {\n this.logger.log(`Python script exited with zero exit code: ${stdout}`);\n const raw: McpResponse = JSON.parse(stdout);\n\n // Sometimes the raw.response might not be a valid json\n // TODO: examine the content type of the raw response..\n // if (raw.content_type==='json') {\n // }\n let parsedResponse = raw.response;\n try {\n parsedResponse = JSON.parse(raw.response);\n }\n catch (ex) {\n this.logger.warn(`Attempting to parse mcp client response assuming it is JSON, however it is not: ${parsedResponse}`);\n }\n // Parse the response string into an object\n // const parsedResponse = JSON.parse(raw.response);\n\n // Replace the string with the parsed object\n const enrichedRaw = {\n ...raw,\n response: parsedResponse,\n };\n // if (!raw.success) {\n // return reject(new Error(`MCP error: ${raw.errors?.join(', ')}`));\n // }\n // let cleaned = raw.response.trim();\n\n // Don't need to re-parse this...\n // const parsed = JSON.parse(cleaned);\n // resolve(cleaned);\n\n resolve(enrichedRaw);\n } catch (err: any) {\n reject(new Error(`Mcp Invocation Failed: ${err.message}`));\n }\n });\n });\n }\n\n cleanResponse(response: string) {\n this.logger.log(`mcp server response is: ${response}`);\n\n // Remove markdown-style code block wrapper\n if (response.startsWith('```json')) {\n response = response.replace(/^```json/, '').trim();\n }\n if (response.endsWith('```')) {\n response = response.replace(/```$/, '').trim();\n }\n this.logger.log(`mcp server response after removing doc tags is: ${response}`);\n\n return response;\n }\n\n async applySolidAiInteraction(id: number) {\n // Fetch the aiInteraction\n const aiInteraction = await this.findOne(id, {\n populate: ['user']\n });\n if (!aiInteraction) {\n const m = `Unable to identified the aiInteraction entry that triggered this job... using id: ${id}`\n\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(m);\n }\n\n // TODO: Validation: Check if JSON.parse(metadata).tools_invoked starts with solid_\n let metadata = {};\n try {\n metadata = JSON.parse(aiInteraction.metadata);\n }\n catch (e) {\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(e);\n }\n\n const toolsInvoked = metadata['tools_invoked'];\n if (!toolsInvoked) {\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(ERROR_MESSAGES.UNABLE_TO_RESOLVE_SOLID_COMMAND);\n }\n\n // TODO: OPTIMISATION for chained tool invocation, for now we are assuming only 1 tool was used.\n const toolInvoked = toolsInvoked[0];\n\n // TODO: use the toolInvoked to identify a service using some convention.\n // TODO: Eg. if toolInvoked is solid_create_module <> SolidCreateModuleMcpToolHandler ... create a factory class to do this mapping and identify the relevant provider. \n const mcpToolHandler = this.mcpToolResponseHandlerFactory.getInstance(toolInvoked);\n if (!mcpToolHandler) {\n // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....\n throw new Error(ERROR_MESSAGES.UNABLE_TO_RESOLVE_MCP_HANDLER);\n }\n\n const handlerApplicationResponse = await mcpToolHandler.apply(aiInteraction);\n\n // TODO: This provider to implement an interface - IMcpToolResponseHandler ... apply(aiInteraction: AiInteraction)\n // throw new Error('Method not implemented.');\n\n // Mark the interaction as applied\n await this.update(aiInteraction.id, { isApplied: true }, [], true);\n\n return handlerApplicationResponse;\n }\n}\n"]}
|
|
@@ -127,7 +127,7 @@ export declare class AuthenticationService {
|
|
|
127
127
|
refreshToken: string;
|
|
128
128
|
}>;
|
|
129
129
|
generateAccessToken(user: User): Promise<string>;
|
|
130
|
-
generateRefreshToken(user: User): Promise<string>;
|
|
130
|
+
generateRefreshToken(user: User, previousRefreshToken?: string): Promise<string>;
|
|
131
131
|
refreshTokens(refreshTokenDto: RefreshTokenDto): Promise<{
|
|
132
132
|
accessToken: string;
|
|
133
133
|
refreshToken: string;
|
|
@@ -151,8 +151,6 @@ export declare class AuthenticationService {
|
|
|
151
151
|
}>;
|
|
152
152
|
activateUser(userId: number): Promise<void>;
|
|
153
153
|
me(activeUser: ActiveUserData): Promise<{
|
|
154
|
-
accessToken: string;
|
|
155
|
-
refreshToken: string;
|
|
156
154
|
user: {
|
|
157
155
|
email: string;
|
|
158
156
|
mobile: string;
|
|
@@ -160,6 +158,7 @@ export declare class AuthenticationService {
|
|
|
160
158
|
id: number;
|
|
161
159
|
roles: string[];
|
|
162
160
|
};
|
|
161
|
+
refreshToken: any;
|
|
163
162
|
}>;
|
|
164
163
|
}
|
|
165
164
|
//# sourceMappingURL=authentication.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../src/services/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAW5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAA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= AuthenticationService_1 = class AuthenticationServic
|
|
|
747
747
|
const accessToken = await this.signToken(user.id, this.jwtConfiguration.accessTokenTtl, { username: user.username, email: user.email, roles: userRoleNames });
|
|
748
748
|
return accessToken;
|
|
749
749
|
}
|
|
750
|
-
async generateRefreshToken(user) {
|
|
750
|
+
async generateRefreshToken(user, previousRefreshToken) {
|
|
751
751
|
const refreshTokenId = (0, crypto_1.randomUUID)();
|
|
752
752
|
const refreshToken = await this.signToken(user.id, this.jwtConfiguration.refreshTokenTtl, {
|
|
753
753
|
refreshTokenId,
|
|
754
754
|
});
|
|
755
|
-
await this.refreshTokenIdsStorage.insert(user.id, refreshToken);
|
|
755
|
+
await this.refreshTokenIdsStorage.insert(user.id, refreshToken, previousRefreshToken);
|
|
756
756
|
return refreshToken;
|
|
757
757
|
}
|
|
758
758
|
async refreshTokens(refreshTokenDto) {
|
|
@@ -874,7 +874,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
874
874
|
roles: true
|
|
875
875
|
}
|
|
876
876
|
});
|
|
877
|
-
const
|
|
877
|
+
const refreshTokenState = await this.refreshTokenIdsStorage.getCurrentRefreshTokenState(user.id);
|
|
878
878
|
const response = {
|
|
879
879
|
user: {
|
|
880
880
|
email: user.email,
|
|
@@ -883,7 +883,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
883
883
|
id: user.id,
|
|
884
884
|
roles: user.roles.map((role) => role.name)
|
|
885
885
|
},
|
|
886
|
-
|
|
886
|
+
refreshToken: refreshTokenState.currentRefreshToken,
|
|
887
887
|
};
|
|
888
888
|
return response;
|
|
889
889
|
}
|