@solidstarters/solid-core 1.2.179 → 1.2.180

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.
Files changed (34) hide show
  1. package/dist/controllers/service.controller.d.ts +8 -1
  2. package/dist/controllers/service.controller.d.ts.map +1 -1
  3. package/dist/controllers/service.controller.js +39 -2
  4. package/dist/controllers/service.controller.js.map +1 -1
  5. package/dist/helpers/date.helper.d.ts +2 -0
  6. package/dist/helpers/date.helper.d.ts.map +1 -0
  7. package/dist/helpers/date.helper.js +18 -0
  8. package/dist/helpers/date.helper.js.map +1 -0
  9. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.d.ts.map +1 -1
  10. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js +18 -14
  11. package/dist/jobs/database/trigger-mcp-client-subscriber-database.service.js.map +1 -1
  12. package/dist/services/ai-interaction.service.d.ts.map +1 -1
  13. package/dist/services/ai-interaction.service.js +11 -4
  14. package/dist/services/ai-interaction.service.js.map +1 -1
  15. package/dist/services/excel.service.js +2 -2
  16. package/dist/services/excel.service.js.map +1 -1
  17. package/dist/services/import-transaction.service.d.ts.map +1 -1
  18. package/dist/services/import-transaction.service.js +6 -3
  19. package/dist/services/import-transaction.service.js.map +1 -1
  20. package/dist/services/mcp-tool-response-handlers/solid-create-model-with-fields-mcp-tool-response-handler.service.d.ts.map +1 -1
  21. package/dist/services/mcp-tool-response-handlers/solid-create-model-with-fields-mcp-tool-response-handler.service.js +2 -2
  22. package/dist/services/mcp-tool-response-handlers/solid-create-model-with-fields-mcp-tool-response-handler.service.js.map +1 -1
  23. package/dist/services/mcp-tool-response-handlers/solid-create-module-mcp-tool-response-handler.service.js +2 -2
  24. package/dist/services/mcp-tool-response-handlers/solid-create-module-mcp-tool-response-handler.service.js.map +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +3 -2
  27. package/src/controllers/service.controller.ts +40 -2
  28. package/src/helpers/date.helper.ts +13 -0
  29. package/src/jobs/database/trigger-mcp-client-subscriber-database.service.ts +18 -14
  30. package/src/services/ai-interaction.service.ts +14 -8
  31. package/src/services/excel.service.ts +2 -2
  32. package/src/services/import-transaction.service.ts +12 -4
  33. package/src/services/mcp-tool-response-handlers/solid-create-model-with-fields-mcp-tool-response-handler.service.ts +3 -2
  34. package/src/services/mcp-tool-response-handlers/solid-create-module-mcp-tool-response-handler.service.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.179",
3
+ "version": "1.2.180",
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",
@@ -49,6 +49,7 @@
49
49
  "cache-manager-redis-store": "^3.0.1",
50
50
  "class-transformer": "^0.5.1",
51
51
  "class-validator": "^0.14.1",
52
+ "dayjs": "^1.11.18",
52
53
  "exceljs": "^4.4.0",
53
54
  "fast-csv": "^5.0.2",
54
55
  "handlebars": "^4.7.8",
@@ -69,7 +70,7 @@
69
70
  "pluralize": "^8.0.0",
70
71
  "puppeteer": "^23.2.0",
71
72
  "r2r-js": "^0.4.43",
72
- "reflect-metadata": "^0.1.13",
73
+ "reflect-metadata": "^0.2.2",
73
74
  "rxjs": "^7.8.1",
74
75
  "swagger-ui-express": "^5.0.0",
75
76
  "twilio": "^5.8.0",
@@ -5,10 +5,14 @@ import { Public } from 'src/decorators/public.decorator';
5
5
  import { ErrorMapperService } from 'src/helpers/error-mapper.service';
6
6
  import { ActiveUserData } from 'src/interfaces/active-user-data.interface';
7
7
  import { AiInteractionService } from 'src/services/ai-interaction.service';
8
+ import { IngestMetadataService } from 'src/services/genai/ingest-metadata.service';
8
9
  import { MqMessageService } from 'src/services/mq-message.service';
9
10
  import { SolidRegistry } from '../helpers/solid-registry';
10
11
 
11
-
12
+ export interface PostProcessCodeGenConfig {
13
+ runModuleMetadataSeeder?: boolean; // If true, regenerate module metadata
14
+ runSolidIngestion?: boolean; // If true, run solid ingestion command
15
+ }
12
16
  @Controller('')
13
17
  @ApiTags("Common")
14
18
  // @UseGuards(ThrottlerGuard)
@@ -20,7 +24,9 @@ export class ServiceController {
20
24
  private readonly solidRegistry: SolidRegistry,
21
25
  private readonly aiInteractionService: AiInteractionService,
22
26
  private readonly mqMessageService: MqMessageService,
23
- private readonly errorMapper: ErrorMapperService
27
+ private readonly errorMapper: ErrorMapperService,
28
+ private readonly ingestMetadataService: IngestMetadataService,
29
+
24
30
  ) { }
25
31
 
26
32
  @Public()
@@ -103,6 +109,38 @@ export class ServiceController {
103
109
  return { message: `seed data for ${seedData.seeder}` };
104
110
  }
105
111
 
112
+ @ApiBearerAuth("jwt")
113
+ @Post('code-generation/post-process')
114
+ async postProcessCodeGeneration(@Body() config : PostProcessCodeGenConfig) {
115
+ // Set defaults if not provided
116
+ config.runModuleMetadataSeeder = config.runModuleMetadataSeeder ?? true;
117
+ config.runSolidIngestion = config.runSolidIngestion ?? true;
118
+
119
+ // Run the Module Metadata Seeder Service
120
+ if (config.runModuleMetadataSeeder) {
121
+ this.logger.debug(`Running the Module Metadata Seeder Service as part of post-process code generation`);
122
+ const seeder = this.solidRegistry
123
+ .getSeeders()
124
+ .filter((seeder) => seeder.name === 'ModuleMetadataSeederService')
125
+ .map((seeder) => seeder.instance)
126
+ .pop();
127
+ if (!seeder) {
128
+ this.logger.error(`Seeder service ModuleMetadataSeederService not found. Does your service have a seed() method?`);
129
+ } else {
130
+ await seeder.seed();
131
+ }
132
+ } else {
133
+ this.logger.debug(`Skipping the Module Metadata Seeder Service as part of post-process code generation`);
134
+ }
135
+
136
+ // Run the Solid ingestion command
137
+ if (config.runSolidIngestion) {
138
+ this.logger.debug(`Running the Solid ingestion command as part of post-process code generation`);
139
+ await this.ingestMetadataService.ingest();
140
+ }
141
+ }
142
+
143
+
106
144
  // @Public()
107
145
  // @Get('play')
108
146
  // play() {
@@ -0,0 +1,13 @@
1
+ import dayjs from 'dayjs';
2
+
3
+
4
+ export function parseFlexibleDate(value: string): Date | null {
5
+ if (!value) return null;
6
+ const formats = ['DD-MM-YYYY', 'YYYY-MM-DD'];
7
+ const parsed = dayjs(value, formats, true); // true = strict parsing
8
+ if (!parsed.isValid()) {
9
+ return null;
10
+ }
11
+ return parsed.toDate();
12
+ }
13
+
@@ -96,18 +96,22 @@ export class TriggerMcpClientSubscriberDatabase extends DatabaseSubscriber<Trigg
96
96
  });
97
97
 
98
98
  const finalPrompt = `
99
- # User Prompt:
100
- ${prompt}
101
-
102
- # System Instructions:
103
- - aiInteractionId: ${genAiInteraction.id}
104
- - moduleName:${message.payload.moduleName}
105
- - You will be invoking tools if needed.
106
- - If a tool is invoked, you must return **exactly** the raw output from the tool, without any additional formatting, commentary, or text.
107
- - Do not wrap the result in quotes, JSON, or markdown fences.
108
- - Do not explain what the result means.
109
- - Your final response must be identical to the tool output.
110
- `
99
+ # User Prompt:
100
+ ${prompt}
101
+
102
+ # System Instructions:
103
+ - aiInteractionId: ${genAiInteraction.id}
104
+ - moduleName:${message.payload.moduleName}
105
+ - You will be invoking tools if needed.
106
+ - If a tool is invoked, you must return **exactly** the raw output from the tool, without any json envelopes, additional formatting, commentary, or text.
107
+ - Do not wrap the result in quotes, JSON, or markdown fences.
108
+ - Do not explain what the result means.
109
+
110
+ # Past Interactions:
111
+ This section contains the last 10 interactions done between the human and LLM. These are sorted by oldest first.
112
+ Use these interactions to further identify concerns based on the current User Prompt.
113
+
114
+ `
111
115
 
112
116
  const aiResponse = await this.aiInteractionService.runMcpPrompt(finalPrompt);
113
117
  this.triggerMcpClientSubscriberLogger.log(`aiResponse: `);
@@ -116,8 +120,8 @@ export class TriggerMcpClientSubscriberDatabase extends DatabaseSubscriber<Trigg
116
120
  if (!aiResponse.success) {
117
121
  this.triggerMcpClientSubscriberLogger.log(`Gen ai has returned with a false status code`);
118
122
 
119
- const errorsStr = aiResponse.errors.join('\n ');
120
- const errorTrace = aiResponse.error_trace.join('\n');
123
+ const errorsStr = aiResponse.errors?.join('\n ');
124
+ const errorTrace = aiResponse.error_trace?.join('\n');
121
125
 
122
126
  // await this.aiInteractionService.create({
123
127
  // userId: aiInteraction.user.id,
@@ -62,7 +62,7 @@ export class AiInteractionService extends CRUDService<AiInteraction> {
62
62
  const m = {
63
63
  payload: {
64
64
  aiInteractionId: aiInteraction.id,
65
- moduleName:dto.moduleName
65
+ moduleName: dto.moduleName
66
66
  },
67
67
  parentEntity: 'aiInteraction',
68
68
  parentEntityId: aiInteraction.id,
@@ -149,7 +149,7 @@ export class AiInteractionService extends CRUDService<AiInteraction> {
149
149
  }
150
150
  catch (ex) {
151
151
  this.logger.warn(`Attempting to parse mcp client response assuming it is JSON, however it is not: ${parsedResponse}`);
152
- raw.success = false
152
+ // raw.success = false
153
153
  }
154
154
  // Parse the response string into an object
155
155
  // const parsedResponse = JSON.parse(raw.response);
@@ -204,16 +204,22 @@ export class AiInteractionService extends CRUDService<AiInteraction> {
204
204
  }
205
205
 
206
206
  // TODO: Validation: Check if JSON.parse(metadata).tools_invoked starts with solid_
207
- let metadata = {};
207
+ let metadata: any = {};
208
208
  try {
209
- metadata = JSON.parse(aiInteraction.metadata);
210
- }
211
- catch (e) {
209
+ if (typeof aiInteraction.metadata === "string") {
210
+ metadata = JSON.parse(aiInteraction.metadata);
211
+ } else if (typeof aiInteraction.metadata === "object" && aiInteraction.metadata !== null) {
212
+ metadata = aiInteraction.metadata;
213
+ } else {
214
+ // optional fallback
215
+ metadata = {};
216
+ }
217
+ } catch (e) {
212
218
  // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....
213
- throw new Error(e);
219
+ throw new Error(`Invalid metadata JSON: ${e}`);
214
220
  }
215
221
 
216
- const toolsInvoked = metadata['tools_invoked'];
222
+ const toolsInvoked = metadata['toolsInvoked'];
217
223
  if (!toolsInvoked) {
218
224
  // TODO: RESPONSE SHAPE ALERT Check if we want to control the shape of the response....
219
225
  throw new Error(ERROR_MESSAGES.UNABLE_TO_RESOLVE_SOLID_COMMAND);
@@ -59,7 +59,7 @@ export class ExcelService {
59
59
  // headers.reduce((acc, header) => ({ ...acc, [header]: '' }), {})
60
60
  // ).commit(); // Write a dummy record with headers
61
61
 
62
- await workbook.commit();
62
+ workbook.commit();
63
63
  return passThrough;
64
64
  }
65
65
 
@@ -86,7 +86,7 @@ export class ExcelService {
86
86
  this.logger.debug(`✅ Chunk ${chunkIndex} written to Excel`);
87
87
  }
88
88
 
89
- await workbook.commit();
89
+ workbook.commit();
90
90
  // passThrough.end(); // ✅ Properly close the stream
91
91
  } catch (error) {
92
92
  this.logger.error(`❌ Error writing Excel: ${error.message}`);
@@ -26,6 +26,7 @@ import { CsvService } from './csv.service';
26
26
  import { ExcelService } from './excel.service';
27
27
  import { SolidIntrospectService } from './solid-introspect.service';
28
28
  import { ERROR_MESSAGES } from 'src/constants/error-messages';
29
+ import { parseFlexibleDate } from 'src/helpers/date.helper';
29
30
 
30
31
  interface ImportTemplateFileInfo {
31
32
  stream: NodeJS.ReadableStream;
@@ -657,10 +658,17 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
657
658
  dtoRecord[fieldMetadata.name] = null; // If the cell is empty, set the field to null
658
659
  return dtoRecord;
659
660
  }
660
- const dateValue = new Date(cellValue);
661
- if (isNaN(dateValue.getTime())) {
662
- throw new Error(`Invalid date value for cell ${key} with value ${record[key]}`);
663
- }
661
+ // Use flexible date parser
662
+ console.log(cellValue,'cellValue');
663
+
664
+ const dateValue = parseFlexibleDate(cellValue);
665
+ console.log(dateValue,'dateValue');
666
+
667
+ if (!dateValue) {
668
+ throw new Error(
669
+ `Invalid date value for cell ${key} with value ${cellValue}`
670
+ );
671
+ }
664
672
  dtoRecord[fieldMetadata.name] = dateValue;
665
673
  return dtoRecord;
666
674
  }
@@ -5,6 +5,7 @@ import { SolidRegistry } from "src/helpers/solid-registry";
5
5
  import { ModelMetadataService } from "../model-metadata.service";
6
6
  import { CreateModelMetadataDto } from "src/dtos/create-model-metadata.dto";
7
7
  import { ModuleMetadataService } from "../module-metadata.service";
8
+ import { model } from "mongoose";
8
9
 
9
10
  @Injectable()
10
11
  export class SolidCreateModelWithFieldsMcpToolResponseHandler implements IMcpToolResponseHandler {
@@ -19,9 +20,9 @@ export class SolidCreateModelWithFieldsMcpToolResponseHandler implements IMcpToo
19
20
  async apply(aiInteraction: AiInteraction) {
20
21
  // const aiResponse = JSON.parse(aiInteraction.message);
21
22
  const escapedMessage = aiInteraction.message.replace(/\\'/g, "'");
22
- const aiResponse = JSON.parse(escapedMessage);
23
+ const aiResponseMessage = JSON.parse(escapedMessage);
23
24
 
24
- const { moduleUserKey, modelSchema } = aiResponse;
25
+ const { moduleUserKey, ...modelSchema } = aiResponseMessage;
25
26
  const moduleMetadata = await this.moduleMetadataService.findOneByUserKey(moduleUserKey);
26
27
  if (!moduleMetadata) {
27
28
  throw new Error(`Module with user key ${moduleUserKey} not found.`);
@@ -16,9 +16,9 @@ export class SolidCreateModuleMcpToolResponseHandler implements IMcpToolResponse
16
16
  }
17
17
 
18
18
  async apply(aiInteraction: AiInteraction) {
19
- const aiResponse = JSON.parse(aiInteraction.message);
19
+ const aiResponseMessage = JSON.parse(aiInteraction.message);
20
20
 
21
- const moduleMetadata = aiResponse?.data?.moduleMetadata ?? {};
21
+ const moduleMetadata = aiResponseMessage?.moduleMetadata ?? {};
22
22
 
23
23
  // TODO: Validate if another module with same name exists, if it does then raise an error...
24
24