plazbot-cli 0.2.18 → 0.2.19

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.
@@ -26,22 +26,145 @@ const VALID_AGENT_FIELDS = new Set([
26
26
  'fUseAutomationFlowWidget', 'iconWidget',
27
27
  'enableAvatarWidget', 'avatarGender', 'avatarVoiceId', 'avatarLanguage',
28
28
  ]);
29
+ // Campos que el schema espera como string (no pueden ser null)
30
+ const STRING_FIELDS = new Set([
31
+ 'name', 'description', 'prompt', 'zone', 'timezone', 'color',
32
+ 'question', 'responseMode', 'iconWidget', 'avatarGender',
33
+ 'avatarVoiceId', 'avatarLanguage', 'urlWhatsappWidget', 'nameWidget',
34
+ ]);
35
+ // Campos que el schema espera como array (no pueden ser null)
36
+ const ARRAY_FIELDS = new Set([
37
+ 'tags', 'examples', 'channels', 'services', 'actions', 'aiProviders',
38
+ ]);
39
+ function cleanRequiredFields(fields) {
40
+ if (!fields || !Array.isArray(fields))
41
+ return [];
42
+ return fields.map((f) => {
43
+ const clean = {};
44
+ if (f.name)
45
+ clean.name = f.name;
46
+ if (f.description)
47
+ clean.description = f.description;
48
+ if (f.promptHint)
49
+ clean.promptHint = f.promptHint;
50
+ if (f.type)
51
+ clean.type = f.type;
52
+ // properties debe ser array o no existir
53
+ if (f.properties && Array.isArray(f.properties)) {
54
+ clean.properties = f.properties.map((p) => ({
55
+ name: p.name || '',
56
+ type: p.type || 'string',
57
+ }));
58
+ }
59
+ // Si properties es null o no es array, no incluirlo
60
+ return clean;
61
+ });
62
+ }
63
+ function cleanServices(services) {
64
+ if (!services || !Array.isArray(services))
65
+ return [];
66
+ return services.map((svc) => {
67
+ const clean = {
68
+ intent: svc.intent || '',
69
+ reference: svc.reference || '',
70
+ enabled: svc.enabled ?? true,
71
+ method: svc.method || 'GET',
72
+ endpoint: svc.endpoint || '',
73
+ requiredFields: cleanRequiredFields(svc.requiredFields),
74
+ };
75
+ if (svc.tags && Array.isArray(svc.tags))
76
+ clean.tags = svc.tags;
77
+ if (svc.headers && typeof svc.headers === 'object')
78
+ clean.headers = svc.headers;
79
+ if (svc.bodyTemplate && typeof svc.bodyTemplate === 'object')
80
+ clean.bodyTemplate = svc.bodyTemplate;
81
+ if (svc.bodySchema && typeof svc.bodySchema === 'object')
82
+ clean.bodySchema = svc.bodySchema;
83
+ if (svc.responseMapping && typeof svc.responseMapping === 'object')
84
+ clean.responseMapping = svc.responseMapping;
85
+ if (typeof svc.responseMessage === 'string')
86
+ clean.responseMessage = svc.responseMessage;
87
+ if (svc.responseConditions && Array.isArray(svc.responseConditions)) {
88
+ clean.responseConditions = svc.responseConditions.map((rc) => {
89
+ const c = { condition: rc.condition || '' };
90
+ if (typeof rc.message === 'string')
91
+ c.message = rc.message;
92
+ if (typeof rc.nextService === 'string')
93
+ c.nextService = rc.nextService;
94
+ return c;
95
+ });
96
+ }
97
+ if (typeof svc.action === 'string')
98
+ clean.action = svc.action;
99
+ return clean;
100
+ });
101
+ }
102
+ function cleanActions(actions) {
103
+ if (!actions || !Array.isArray(actions))
104
+ return [];
105
+ return actions.map((act) => {
106
+ const clean = {
107
+ intent: act.intent || '',
108
+ reference: act.reference || '',
109
+ enabled: act.enabled ?? true,
110
+ action: Array.isArray(act.action) ? act.action.map((a) => ({
111
+ type: a.type || '',
112
+ value: a.value ?? '',
113
+ })) : [],
114
+ };
115
+ if (act.tags && Array.isArray(act.tags))
116
+ clean.tags = act.tags;
117
+ clean.requiredFields = cleanRequiredFields(act.requiredFields);
118
+ if (typeof act.responseMessage === 'string')
119
+ clean.responseMessage = act.responseMessage;
120
+ if (typeof act.responseJson === 'boolean')
121
+ clean.responseJson = act.responseJson;
122
+ return clean;
123
+ });
124
+ }
29
125
  function cleanAgentForExport(agentData) {
30
126
  const cleaned = {};
31
127
  for (const key of Object.keys(agentData)) {
32
- if (VALID_AGENT_FIELDS.has(key)) {
33
- cleaned[key] = agentData[key];
128
+ if (!VALID_AGENT_FIELDS.has(key))
129
+ continue;
130
+ const value = agentData[key];
131
+ // Eliminar campos null en campos string
132
+ if (STRING_FIELDS.has(key)) {
133
+ if (value !== null && value !== undefined) {
134
+ cleaned[key] = String(value);
135
+ }
136
+ continue;
137
+ }
138
+ // Asegurar que campos array sean arrays
139
+ if (ARRAY_FIELDS.has(key)) {
140
+ if (key === 'services') {
141
+ cleaned[key] = cleanServices(value);
142
+ }
143
+ else if (key === 'actions') {
144
+ cleaned[key] = cleanActions(value);
145
+ }
146
+ else if (Array.isArray(value)) {
147
+ cleaned[key] = value;
148
+ }
149
+ else {
150
+ cleaned[key] = [];
151
+ }
152
+ continue;
153
+ }
154
+ // Eliminar nulls genericos
155
+ if (value !== null && value !== undefined) {
156
+ cleaned[key] = value;
34
157
  }
35
158
  }
36
- // Limpiar channels (quitar keys especificas del workspace origen)
159
+ // Limpiar channels
37
160
  if (cleaned.channels && Array.isArray(cleaned.channels)) {
38
161
  cleaned.channels = cleaned.channels.map((ch) => ({
39
- channel: ch.channel,
40
- key: ch.key,
162
+ channel: ch.channel || '',
163
+ key: ch.key || '',
41
164
  multianswer: ch.multianswer || false,
42
165
  }));
43
166
  }
44
- // Limpiar aiProviders (quitar tokens sensibles opcionalmente)
167
+ // Limpiar aiProviders
45
168
  if (cleaned.aiProviders && Array.isArray(cleaned.aiProviders)) {
46
169
  cleaned.aiProviders = cleaned.aiProviders.map((ai) => ({
47
170
  provider: ai.provider,
@@ -52,6 +175,13 @@ function cleanAgentForExport(agentData) {
52
175
  isDefault: ai.isDefault,
53
176
  }));
54
177
  }
178
+ // Limpiar examples
179
+ if (cleaned.examples && Array.isArray(cleaned.examples)) {
180
+ cleaned.examples = cleaned.examples.map((ex) => ({
181
+ value: ex.value || '',
182
+ color: ex.color || 'blue',
183
+ }));
184
+ }
55
185
  return cleaned;
56
186
  }
57
187
  exports.exportCommand = new commander_1.Command('export')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plazbot-cli",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "CLI para Plazbot SDK",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {
@@ -22,25 +22,134 @@ const VALID_AGENT_FIELDS = new Set([
22
22
  'enableAvatarWidget', 'avatarGender', 'avatarVoiceId', 'avatarLanguage',
23
23
  ]);
24
24
 
25
+ // Campos que el schema espera como string (no pueden ser null)
26
+ const STRING_FIELDS = new Set([
27
+ 'name', 'description', 'prompt', 'zone', 'timezone', 'color',
28
+ 'question', 'responseMode', 'iconWidget', 'avatarGender',
29
+ 'avatarVoiceId', 'avatarLanguage', 'urlWhatsappWidget', 'nameWidget',
30
+ ]);
31
+
32
+ // Campos que el schema espera como array (no pueden ser null)
33
+ const ARRAY_FIELDS = new Set([
34
+ 'tags', 'examples', 'channels', 'services', 'actions', 'aiProviders',
35
+ ]);
36
+
37
+ function cleanRequiredFields(fields: any): any[] {
38
+ if (!fields || !Array.isArray(fields)) return [];
39
+ return fields.map((f: any) => {
40
+ const clean: any = {};
41
+ if (f.name) clean.name = f.name;
42
+ if (f.description) clean.description = f.description;
43
+ if (f.promptHint) clean.promptHint = f.promptHint;
44
+ if (f.type) clean.type = f.type;
45
+ // properties debe ser array o no existir
46
+ if (f.properties && Array.isArray(f.properties)) {
47
+ clean.properties = f.properties.map((p: any) => ({
48
+ name: p.name || '',
49
+ type: p.type || 'string',
50
+ }));
51
+ }
52
+ // Si properties es null o no es array, no incluirlo
53
+ return clean;
54
+ });
55
+ }
56
+
57
+ function cleanServices(services: any): any[] {
58
+ if (!services || !Array.isArray(services)) return [];
59
+ return services.map((svc: any) => {
60
+ const clean: any = {
61
+ intent: svc.intent || '',
62
+ reference: svc.reference || '',
63
+ enabled: svc.enabled ?? true,
64
+ method: svc.method || 'GET',
65
+ endpoint: svc.endpoint || '',
66
+ requiredFields: cleanRequiredFields(svc.requiredFields),
67
+ };
68
+ if (svc.tags && Array.isArray(svc.tags)) clean.tags = svc.tags;
69
+ if (svc.headers && typeof svc.headers === 'object') clean.headers = svc.headers;
70
+ if (svc.bodyTemplate && typeof svc.bodyTemplate === 'object') clean.bodyTemplate = svc.bodyTemplate;
71
+ if (svc.bodySchema && typeof svc.bodySchema === 'object') clean.bodySchema = svc.bodySchema;
72
+ if (svc.responseMapping && typeof svc.responseMapping === 'object') clean.responseMapping = svc.responseMapping;
73
+ if (typeof svc.responseMessage === 'string') clean.responseMessage = svc.responseMessage;
74
+ if (svc.responseConditions && Array.isArray(svc.responseConditions)) {
75
+ clean.responseConditions = svc.responseConditions.map((rc: any) => {
76
+ const c: any = { condition: rc.condition || '' };
77
+ if (typeof rc.message === 'string') c.message = rc.message;
78
+ if (typeof rc.nextService === 'string') c.nextService = rc.nextService;
79
+ return c;
80
+ });
81
+ }
82
+ if (typeof svc.action === 'string') clean.action = svc.action;
83
+ return clean;
84
+ });
85
+ }
86
+
87
+ function cleanActions(actions: any): any[] {
88
+ if (!actions || !Array.isArray(actions)) return [];
89
+ return actions.map((act: any) => {
90
+ const clean: any = {
91
+ intent: act.intent || '',
92
+ reference: act.reference || '',
93
+ enabled: act.enabled ?? true,
94
+ action: Array.isArray(act.action) ? act.action.map((a: any) => ({
95
+ type: a.type || '',
96
+ value: a.value ?? '',
97
+ })) : [],
98
+ };
99
+ if (act.tags && Array.isArray(act.tags)) clean.tags = act.tags;
100
+ clean.requiredFields = cleanRequiredFields(act.requiredFields);
101
+ if (typeof act.responseMessage === 'string') clean.responseMessage = act.responseMessage;
102
+ if (typeof act.responseJson === 'boolean') clean.responseJson = act.responseJson;
103
+ return clean;
104
+ });
105
+ }
106
+
25
107
  function cleanAgentForExport(agentData: any): any {
26
108
  const cleaned: any = {};
27
109
 
28
110
  for (const key of Object.keys(agentData)) {
29
- if (VALID_AGENT_FIELDS.has(key)) {
30
- cleaned[key] = agentData[key];
111
+ if (!VALID_AGENT_FIELDS.has(key)) continue;
112
+
113
+ const value = agentData[key];
114
+
115
+ // Eliminar campos null en campos string
116
+ if (STRING_FIELDS.has(key)) {
117
+ if (value !== null && value !== undefined) {
118
+ cleaned[key] = String(value);
119
+ }
120
+ continue;
121
+ }
122
+
123
+ // Asegurar que campos array sean arrays
124
+ if (ARRAY_FIELDS.has(key)) {
125
+ if (key === 'services') {
126
+ cleaned[key] = cleanServices(value);
127
+ } else if (key === 'actions') {
128
+ cleaned[key] = cleanActions(value);
129
+ } else if (Array.isArray(value)) {
130
+ cleaned[key] = value;
131
+ } else {
132
+ cleaned[key] = [];
133
+ }
134
+ continue;
135
+ }
136
+
137
+ // Eliminar nulls genericos
138
+ if (value !== null && value !== undefined) {
139
+ cleaned[key] = value;
31
140
  }
32
141
  }
33
142
 
34
- // Limpiar channels (quitar keys especificas del workspace origen)
143
+ // Limpiar channels
35
144
  if (cleaned.channels && Array.isArray(cleaned.channels)) {
36
145
  cleaned.channels = cleaned.channels.map((ch: any) => ({
37
- channel: ch.channel,
38
- key: ch.key,
146
+ channel: ch.channel || '',
147
+ key: ch.key || '',
39
148
  multianswer: ch.multianswer || false,
40
149
  }));
41
150
  }
42
151
 
43
- // Limpiar aiProviders (quitar tokens sensibles opcionalmente)
152
+ // Limpiar aiProviders
44
153
  if (cleaned.aiProviders && Array.isArray(cleaned.aiProviders)) {
45
154
  cleaned.aiProviders = cleaned.aiProviders.map((ai: any) => ({
46
155
  provider: ai.provider,
@@ -52,6 +161,14 @@ function cleanAgentForExport(agentData: any): any {
52
161
  }));
53
162
  }
54
163
 
164
+ // Limpiar examples
165
+ if (cleaned.examples && Array.isArray(cleaned.examples)) {
166
+ cleaned.examples = cleaned.examples.map((ex: any) => ({
167
+ value: ex.value || '',
168
+ color: ex.color || 'blue',
169
+ }));
170
+ }
171
+
55
172
  return cleaned;
56
173
  }
57
174