@qelos/plugins-cli 0.0.21 → 0.0.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qelos/plugins-cli",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "CLI to manage QELOS plugins",
5
5
  "main": "cli.mjs",
6
6
  "bin": {
@@ -134,26 +134,33 @@ export function extractIntegrationContent(integration, integrationPath, fileName
134
134
 
135
135
  // Extract the first pre_message content
136
136
  const preMessage = updatedIntegration.target.details.pre_messages[0];
137
- if (preMessage && preMessage.content && typeof preMessage.content === 'string') {
138
- const content = preMessage.content;
139
-
140
- // Skip if content is empty or just whitespace
141
- if (!content.trim()) {
137
+ if (preMessage && preMessage.content) {
138
+ // Check if content is already a $ref
139
+ if (typeof preMessage.content === 'object' && preMessage.content.$ref) {
142
140
  return updatedIntegration;
143
141
  }
142
+
143
+ // Only extract if content is a string
144
+ if (typeof preMessage.content === 'string') {
145
+ const content = preMessage.content;
146
+
147
+ // Skip if content is empty or just whitespace
148
+ if (!content.trim()) {
149
+ return updatedIntegration;
150
+ }
144
151
 
145
- // Generate filename
146
- const baseName = path.basename(fileName, '.integration.json');
147
- const mdFileName = `${baseName}.md`;
148
- const mdFilePath = path.join(extractDir, mdFileName);
149
- const relativeRef = `./prompts/${mdFileName}`;
152
+ // Generate filename
153
+ const baseName = path.basename(fileName, '.integration.json');
154
+ const mdFileName = `${baseName}.md`;
155
+ const mdFilePath = path.join(extractDir, mdFileName);
156
+ const relativeRef = `./prompts/${mdFileName}`;
150
157
 
151
- // Write content to file
152
- fs.writeFileSync(mdFilePath, content, 'utf-8');
153
- logger.debug(`Extracted pre_message content to: ${relativeRef}`);
158
+ // Write content to file
159
+ fs.writeFileSync(mdFilePath, content, 'utf-8');
154
160
 
155
- // Replace with $ref
156
- updatedIntegration.target.details.pre_messages[0].content = { $ref: relativeRef };
161
+ // Replace with $ref
162
+ updatedIntegration.target.details.pre_messages[0].content = { $ref: relativeRef };
163
+ }
157
164
  }
158
165
 
159
166
  return updatedIntegration;
@@ -76,6 +76,24 @@ function sanitizeIntegrationForFile(integration) {
76
76
  delete sanitized[field];
77
77
  }
78
78
  });
79
+
80
+ // Remove _id from internal objects
81
+ if (sanitized.trigger && sanitized.trigger._id) {
82
+ delete sanitized.trigger._id;
83
+ }
84
+
85
+ if (sanitized.target && sanitized.target._id) {
86
+ delete sanitized.target._id;
87
+ }
88
+
89
+ if (Array.isArray(sanitized.dataManipulation)) {
90
+ sanitized.dataManipulation.forEach(item => {
91
+ if (item._id) {
92
+ delete item._id;
93
+ }
94
+ });
95
+ }
96
+
79
97
  return sanitized;
80
98
  }
81
99
 
@@ -177,8 +195,13 @@ export async function pushIntegrations(sdk, path, options = {}) {
177
195
  logger.success(`Created: ${displayName}`);
178
196
  }
179
197
 
198
+ // Re-extract content to files to maintain $ref structure
199
+ // This ensures pre_messages are stored as prompt md files after pushing
200
+ const processedResponse = extractIntegrationContent(response, path, file);
201
+
180
202
  // Persist returned integration (with _id) back to disk
181
- writeIntegrationFile(filePath, sanitizeIntegrationForFile(response));
203
+ writeIntegrationFile(filePath, sanitizeIntegrationForFile(processedResponse));
204
+
182
205
  results.push({ status: 'fulfilled' });
183
206
  } catch (error) {
184
207
  logger.error(`Failed to push integration file ${file}`, error);
@@ -4,6 +4,48 @@ import { join } from 'node:path';
4
4
  import { logger } from './logger.mjs';
5
5
  import { extractMicroFrontendStructures, resolveMicroFrontendStructures } from './micro-frontends.mjs';
6
6
 
7
+ function sanitizePluginForFile(plugin) {
8
+ const sanitized = JSON.parse(JSON.stringify(plugin));
9
+
10
+ // Remove _id from internal objects in arrays
11
+ if (Array.isArray(sanitized.subscribedEvents)) {
12
+ sanitized.subscribedEvents.forEach(item => {
13
+ if (item._id) delete item._id;
14
+ });
15
+ }
16
+
17
+ if (Array.isArray(sanitized.microFrontends)) {
18
+ sanitized.microFrontends.forEach(mfe => {
19
+ if (mfe._id) delete mfe._id;
20
+ if (Array.isArray(mfe.requires)) {
21
+ mfe.requires.forEach(item => {
22
+ if (item._id) delete item._id;
23
+ });
24
+ }
25
+ });
26
+ }
27
+
28
+ if (Array.isArray(sanitized.injectables)) {
29
+ sanitized.injectables.forEach(item => {
30
+ if (item._id) delete item._id;
31
+ });
32
+ }
33
+
34
+ if (Array.isArray(sanitized.navBarGroups)) {
35
+ sanitized.navBarGroups.forEach(item => {
36
+ if (item._id) delete item._id;
37
+ });
38
+ }
39
+
40
+ if (Array.isArray(sanitized.cruds)) {
41
+ sanitized.cruds.forEach(item => {
42
+ if (item._id) delete item._id;
43
+ });
44
+ }
45
+
46
+ return sanitized;
47
+ }
48
+
7
49
  /**
8
50
  * Push plugins from local directory to remote
9
51
  * @param {Object} sdk - Initialized SDK instance
@@ -179,7 +221,10 @@ export async function pullPlugins(sdk, targetPath) {
179
221
  cruds: (fullPlugin.cruds || []).map(removeIdFromObject),
180
222
  }
181
223
 
182
- fs.writeFileSync(filePath, JSON.stringify(relevantFields, null, 2), 'utf-8');
224
+ // Sanitize the plugin to remove any remaining _id fields from internal objects
225
+ const sanitizedPlugin = sanitizePluginForFile(relevantFields);
226
+
227
+ fs.writeFileSync(filePath, JSON.stringify(sanitizedPlugin, null, 2), 'utf-8');
183
228
  logger.step(`Pulled: ${plugin.apiPath}`);
184
229
  }));
185
230