@postalsys/email-ai-tools 1.1.2 → 1.1.3
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/lib/generate-summary.js +42 -2
- package/package.json +1 -1
package/lib/generate-summary.js
CHANGED
|
@@ -136,7 +136,8 @@ async function generateSummary(message, apiToken, opts) {
|
|
|
136
136
|
promptText = promptText.substr(0, MAX_ALLOWED_TEXT_LENGTH);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
// eslint-disable-next-line no-constant-condition
|
|
140
|
+
while (true) {
|
|
140
141
|
content.text = promptText;
|
|
141
142
|
prompt = `${USER_PROMPT}
|
|
142
143
|
|
|
@@ -202,7 +203,6 @@ ${JSON.stringify(content)}`;
|
|
|
202
203
|
});
|
|
203
204
|
|
|
204
205
|
data = await res.json();
|
|
205
|
-
|
|
206
206
|
if (!res.ok) {
|
|
207
207
|
if (res.status === 429 && ++retries < 5) {
|
|
208
208
|
// try again
|
|
@@ -255,6 +255,7 @@ ${JSON.stringify(content)}`;
|
|
|
255
255
|
if (typeof values.shouldReply !== 'undefined' && typeof values.shouldReply !== 'boolean') {
|
|
256
256
|
delete values.shouldReply;
|
|
257
257
|
}
|
|
258
|
+
|
|
258
259
|
if (values && values.events) {
|
|
259
260
|
values.events = []
|
|
260
261
|
.concat(values.events || [])
|
|
@@ -262,6 +263,20 @@ ${JSON.stringify(content)}`;
|
|
|
262
263
|
.map(event => {
|
|
263
264
|
let result = {};
|
|
264
265
|
for (let key of Object.keys(event)) {
|
|
266
|
+
switch (key) {
|
|
267
|
+
case 'startTime':
|
|
268
|
+
case 'endTime':
|
|
269
|
+
{
|
|
270
|
+
if (event[key]) {
|
|
271
|
+
let parsedDate = new Date(event[key]);
|
|
272
|
+
if (parsedDate.toString() === 'Invalid Date') {
|
|
273
|
+
event[key] = '';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
|
|
265
280
|
if (event[key] !== '' && event[key] !== null) {
|
|
266
281
|
result[key] = event[key];
|
|
267
282
|
}
|
|
@@ -269,6 +284,31 @@ ${JSON.stringify(content)}`;
|
|
|
269
284
|
return result;
|
|
270
285
|
});
|
|
271
286
|
}
|
|
287
|
+
|
|
288
|
+
if (values && values.actions) {
|
|
289
|
+
values.actions = [].concat(values.actions || []).map(action => {
|
|
290
|
+
let result = {};
|
|
291
|
+
for (let key of Object.keys(action)) {
|
|
292
|
+
switch (key) {
|
|
293
|
+
case 'dueDate':
|
|
294
|
+
{
|
|
295
|
+
if (action[key]) {
|
|
296
|
+
let parsedDate = new Date(action[key]);
|
|
297
|
+
if (parsedDate.toString() === 'Invalid Date') {
|
|
298
|
+
action[key] = '';
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (action[key] !== '' && action[key] !== null) {
|
|
306
|
+
result[key] = action[key];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
272
312
|
} catch (err) {
|
|
273
313
|
let error = new Error('Failed to parse output from OpenAI API');
|
|
274
314
|
error.textContent = output;
|