human-in-the-loop 0.1.0
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/README.md +222 -0
- package/TODO.md +53 -0
- package/dist/index.cjs +899 -0
- package/dist/index.d.cts +344 -0
- package/dist/index.d.ts +344 -0
- package/dist/index.js +793 -0
- package/package.json +65 -0
- package/src/core/factory.test.ts +69 -0
- package/src/core/factory.ts +30 -0
- package/src/core/types.ts +191 -0
- package/src/index.ts +7 -0
- package/src/platforms/email/index.tsx +137 -0
- package/src/platforms/react/index.tsx +218 -0
- package/src/platforms/slack/index.ts +84 -0
- package/src/platforms/teams/index.ts +84 -0
- package/tsconfig.json +14 -0
- package/vitest.config.ts +15 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_with_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
|
+
try {
|
|
12
|
+
var info = gen[key](arg);
|
|
13
|
+
var value = info.value;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
reject(error);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (info.done) {
|
|
19
|
+
resolve(value);
|
|
20
|
+
} else {
|
|
21
|
+
Promise.resolve(value).then(_next, _throw);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _async_to_generator(fn) {
|
|
25
|
+
return function() {
|
|
26
|
+
var self = this, args = arguments;
|
|
27
|
+
return new Promise(function(resolve, reject) {
|
|
28
|
+
var gen = fn.apply(self, args);
|
|
29
|
+
function _next(value) {
|
|
30
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
31
|
+
}
|
|
32
|
+
function _throw(err) {
|
|
33
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
34
|
+
}
|
|
35
|
+
_next(undefined);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _class_call_check(instance, Constructor) {
|
|
40
|
+
if (!(instance instanceof Constructor)) {
|
|
41
|
+
throw new TypeError("Cannot call a class as a function");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _defineProperties(target, props) {
|
|
45
|
+
for(var i = 0; i < props.length; i++){
|
|
46
|
+
var descriptor = props[i];
|
|
47
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
48
|
+
descriptor.configurable = true;
|
|
49
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
50
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
54
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
55
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
56
|
+
return Constructor;
|
|
57
|
+
}
|
|
58
|
+
function _define_property(obj, key, value) {
|
|
59
|
+
if (key in obj) {
|
|
60
|
+
Object.defineProperty(obj, key, {
|
|
61
|
+
value: value,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
obj[key] = value;
|
|
68
|
+
}
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
function _iterable_to_array_limit(arr, i) {
|
|
72
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
73
|
+
if (_i == null) return;
|
|
74
|
+
var _arr = [];
|
|
75
|
+
var _n = true;
|
|
76
|
+
var _d = false;
|
|
77
|
+
var _s, _e;
|
|
78
|
+
try {
|
|
79
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
80
|
+
_arr.push(_s.value);
|
|
81
|
+
if (i && _arr.length === i) break;
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
_d = true;
|
|
85
|
+
_e = err;
|
|
86
|
+
} finally{
|
|
87
|
+
try {
|
|
88
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
89
|
+
} finally{
|
|
90
|
+
if (_d) throw _e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return _arr;
|
|
94
|
+
}
|
|
95
|
+
function _non_iterable_rest() {
|
|
96
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
97
|
+
}
|
|
98
|
+
function _object_spread(target) {
|
|
99
|
+
for(var i = 1; i < arguments.length; i++){
|
|
100
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
101
|
+
var ownKeys = Object.keys(source);
|
|
102
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
103
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
104
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
ownKeys.forEach(function(key) {
|
|
108
|
+
_define_property(target, key, source[key]);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return target;
|
|
112
|
+
}
|
|
113
|
+
function ownKeys(object, enumerableOnly) {
|
|
114
|
+
var keys = Object.keys(object);
|
|
115
|
+
if (Object.getOwnPropertySymbols) {
|
|
116
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
117
|
+
if (enumerableOnly) {
|
|
118
|
+
symbols = symbols.filter(function(sym) {
|
|
119
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
keys.push.apply(keys, symbols);
|
|
123
|
+
}
|
|
124
|
+
return keys;
|
|
125
|
+
}
|
|
126
|
+
function _object_spread_props(target, source) {
|
|
127
|
+
source = source != null ? source : {};
|
|
128
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
129
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
130
|
+
} else {
|
|
131
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
132
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return target;
|
|
136
|
+
}
|
|
137
|
+
function _sliced_to_array(arr, i) {
|
|
138
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
139
|
+
}
|
|
140
|
+
function _type_of(obj) {
|
|
141
|
+
"@swc/helpers - typeof";
|
|
142
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
143
|
+
}
|
|
144
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
145
|
+
if (!o) return;
|
|
146
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
147
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
148
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
149
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
150
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
151
|
+
}
|
|
152
|
+
function _ts_generator(thisArg, body) {
|
|
153
|
+
var f, y, t, g, _ = {
|
|
154
|
+
label: 0,
|
|
155
|
+
sent: function() {
|
|
156
|
+
if (t[0] & 1) throw t[1];
|
|
157
|
+
return t[1];
|
|
158
|
+
},
|
|
159
|
+
trys: [],
|
|
160
|
+
ops: []
|
|
161
|
+
};
|
|
162
|
+
return g = {
|
|
163
|
+
next: verb(0),
|
|
164
|
+
"throw": verb(1),
|
|
165
|
+
"return": verb(2)
|
|
166
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
167
|
+
return this;
|
|
168
|
+
}), g;
|
|
169
|
+
function verb(n) {
|
|
170
|
+
return function(v) {
|
|
171
|
+
return step([
|
|
172
|
+
n,
|
|
173
|
+
v
|
|
174
|
+
]);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function step(op) {
|
|
178
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
179
|
+
while(_)try {
|
|
180
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
181
|
+
if (y = 0, t) op = [
|
|
182
|
+
op[0] & 2,
|
|
183
|
+
t.value
|
|
184
|
+
];
|
|
185
|
+
switch(op[0]){
|
|
186
|
+
case 0:
|
|
187
|
+
case 1:
|
|
188
|
+
t = op;
|
|
189
|
+
break;
|
|
190
|
+
case 4:
|
|
191
|
+
_.label++;
|
|
192
|
+
return {
|
|
193
|
+
value: op[1],
|
|
194
|
+
done: false
|
|
195
|
+
};
|
|
196
|
+
case 5:
|
|
197
|
+
_.label++;
|
|
198
|
+
y = op[1];
|
|
199
|
+
op = [
|
|
200
|
+
0
|
|
201
|
+
];
|
|
202
|
+
continue;
|
|
203
|
+
case 7:
|
|
204
|
+
op = _.ops.pop();
|
|
205
|
+
_.trys.pop();
|
|
206
|
+
continue;
|
|
207
|
+
default:
|
|
208
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
209
|
+
_ = 0;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
213
|
+
_.label = op[1];
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
217
|
+
_.label = t[1];
|
|
218
|
+
t = op;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
if (t && _.label < t[2]) {
|
|
222
|
+
_.label = t[2];
|
|
223
|
+
_.ops.push(op);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (t[2]) _.ops.pop();
|
|
227
|
+
_.trys.pop();
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
op = body.call(thisArg, _);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
op = [
|
|
233
|
+
6,
|
|
234
|
+
e
|
|
235
|
+
];
|
|
236
|
+
y = 0;
|
|
237
|
+
} finally{
|
|
238
|
+
f = t = 0;
|
|
239
|
+
}
|
|
240
|
+
if (op[0] & 5) throw op[1];
|
|
241
|
+
return {
|
|
242
|
+
value: op[0] ? op[1] : void 0,
|
|
243
|
+
done: true
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
var __defProp = Object.defineProperty;
|
|
248
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
249
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
250
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
251
|
+
var __export = function(target, all) {
|
|
252
|
+
for(var name in all)__defProp(target, name, {
|
|
253
|
+
get: all[name],
|
|
254
|
+
enumerable: true
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
var __copyProps = function(to, from, except, desc) {
|
|
258
|
+
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
259
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
260
|
+
try {
|
|
261
|
+
var _loop = function() {
|
|
262
|
+
var key = _step.value;
|
|
263
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
264
|
+
get: function() {
|
|
265
|
+
return from[key];
|
|
266
|
+
},
|
|
267
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
271
|
+
} catch (err) {
|
|
272
|
+
_didIteratorError = true;
|
|
273
|
+
_iteratorError = err;
|
|
274
|
+
} finally{
|
|
275
|
+
try {
|
|
276
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
277
|
+
_iterator.return();
|
|
278
|
+
}
|
|
279
|
+
} finally{
|
|
280
|
+
if (_didIteratorError) {
|
|
281
|
+
throw _iteratorError;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return to;
|
|
287
|
+
};
|
|
288
|
+
var __toCommonJS = function(mod) {
|
|
289
|
+
return __copyProps(__defProp({}, "__esModule", {
|
|
290
|
+
value: true
|
|
291
|
+
}), mod);
|
|
292
|
+
};
|
|
293
|
+
// src/index.ts
|
|
294
|
+
var index_exports = {};
|
|
295
|
+
__export(index_exports, {
|
|
296
|
+
EmailHumanFunction: function() {
|
|
297
|
+
return EmailHumanFunction;
|
|
298
|
+
},
|
|
299
|
+
EmailTemplate: function() {
|
|
300
|
+
return EmailTemplate;
|
|
301
|
+
},
|
|
302
|
+
HumanFeedback: function() {
|
|
303
|
+
return HumanFeedback;
|
|
304
|
+
},
|
|
305
|
+
ReactHumanFunction: function() {
|
|
306
|
+
return ReactHumanFunction;
|
|
307
|
+
},
|
|
308
|
+
SlackHumanFunction: function() {
|
|
309
|
+
return SlackHumanFunction;
|
|
310
|
+
},
|
|
311
|
+
TeamsHumanFunction: function() {
|
|
312
|
+
return TeamsHumanFunction;
|
|
313
|
+
},
|
|
314
|
+
createHumanFunction: function() {
|
|
315
|
+
return createHumanFunction;
|
|
316
|
+
},
|
|
317
|
+
createSlackMessage: function() {
|
|
318
|
+
return createSlackMessage;
|
|
319
|
+
},
|
|
320
|
+
createTeamsMessage: function() {
|
|
321
|
+
return createTeamsMessage;
|
|
322
|
+
},
|
|
323
|
+
getEmailResponse: function() {
|
|
324
|
+
return getEmailResponse;
|
|
325
|
+
},
|
|
326
|
+
getSlackResponse: function() {
|
|
327
|
+
return getSlackResponse;
|
|
328
|
+
},
|
|
329
|
+
getTeamsResponse: function() {
|
|
330
|
+
return getTeamsResponse;
|
|
331
|
+
},
|
|
332
|
+
sendEmail: function() {
|
|
333
|
+
return sendEmail;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
module.exports = __toCommonJS(index_exports);
|
|
337
|
+
function createSlackMessage(taskId, input, config) {
|
|
338
|
+
return _createSlackMessage.apply(this, arguments);
|
|
339
|
+
}
|
|
340
|
+
function _createSlackMessage() {
|
|
341
|
+
_createSlackMessage = // src/platforms/slack/index.ts
|
|
342
|
+
_async_to_generator(function(taskId, input, config) {
|
|
343
|
+
return _ts_generator(this, function(_state) {
|
|
344
|
+
console.log("Creating Slack message for task ".concat(taskId));
|
|
345
|
+
console.log("Title: ".concat(config.title));
|
|
346
|
+
console.log("Description: ".concat(config.description));
|
|
347
|
+
return [
|
|
348
|
+
2,
|
|
349
|
+
{
|
|
350
|
+
messageId: "slack-".concat(taskId, "-").concat(Date.now())
|
|
351
|
+
}
|
|
352
|
+
];
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
return _createSlackMessage.apply(this, arguments);
|
|
356
|
+
}
|
|
357
|
+
function getSlackResponse(taskId) {
|
|
358
|
+
return _getSlackResponse.apply(this, arguments);
|
|
359
|
+
}
|
|
360
|
+
function _getSlackResponse() {
|
|
361
|
+
_getSlackResponse = _async_to_generator(function(taskId) {
|
|
362
|
+
return _ts_generator(this, function(_state) {
|
|
363
|
+
console.log("Getting response for Slack task ".concat(taskId));
|
|
364
|
+
return [
|
|
365
|
+
2,
|
|
366
|
+
null
|
|
367
|
+
];
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
return _getSlackResponse.apply(this, arguments);
|
|
371
|
+
}
|
|
372
|
+
var SlackHumanFunction = /*#__PURE__*/ function() {
|
|
373
|
+
function SlackHumanFunction(config) {
|
|
374
|
+
_class_call_check(this, SlackHumanFunction);
|
|
375
|
+
this.config = config;
|
|
376
|
+
}
|
|
377
|
+
_create_class(SlackHumanFunction, [
|
|
378
|
+
{
|
|
379
|
+
key: "request",
|
|
380
|
+
value: function request(input) {
|
|
381
|
+
var _this = this;
|
|
382
|
+
return _async_to_generator(function() {
|
|
383
|
+
var taskId, messageId;
|
|
384
|
+
return _ts_generator(this, function(_state) {
|
|
385
|
+
switch(_state.label){
|
|
386
|
+
case 0:
|
|
387
|
+
taskId = "task-".concat(Date.now());
|
|
388
|
+
return [
|
|
389
|
+
4,
|
|
390
|
+
createSlackMessage(taskId, input, _this.config)
|
|
391
|
+
];
|
|
392
|
+
case 1:
|
|
393
|
+
messageId = _state.sent().messageId;
|
|
394
|
+
return [
|
|
395
|
+
2,
|
|
396
|
+
{
|
|
397
|
+
taskId: taskId,
|
|
398
|
+
status: "pending",
|
|
399
|
+
messageId: {
|
|
400
|
+
slack: messageId,
|
|
401
|
+
teams: "",
|
|
402
|
+
react: "",
|
|
403
|
+
email: ""
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
];
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
})();
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
key: "getResponse",
|
|
414
|
+
value: function getResponse(taskId) {
|
|
415
|
+
return _async_to_generator(function() {
|
|
416
|
+
return _ts_generator(this, function(_state) {
|
|
417
|
+
return [
|
|
418
|
+
2,
|
|
419
|
+
getSlackResponse(taskId)
|
|
420
|
+
];
|
|
421
|
+
});
|
|
422
|
+
})();
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
]);
|
|
426
|
+
return SlackHumanFunction;
|
|
427
|
+
}();
|
|
428
|
+
function createTeamsMessage(taskId, input, config) {
|
|
429
|
+
return _createTeamsMessage.apply(this, arguments);
|
|
430
|
+
}
|
|
431
|
+
function _createTeamsMessage() {
|
|
432
|
+
_createTeamsMessage = // src/platforms/teams/index.ts
|
|
433
|
+
_async_to_generator(function(taskId, input, config) {
|
|
434
|
+
return _ts_generator(this, function(_state) {
|
|
435
|
+
console.log("Creating Teams message for task ".concat(taskId));
|
|
436
|
+
console.log("Title: ".concat(config.title));
|
|
437
|
+
console.log("Description: ".concat(config.description));
|
|
438
|
+
return [
|
|
439
|
+
2,
|
|
440
|
+
{
|
|
441
|
+
messageId: "teams-".concat(taskId, "-").concat(Date.now())
|
|
442
|
+
}
|
|
443
|
+
];
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
return _createTeamsMessage.apply(this, arguments);
|
|
447
|
+
}
|
|
448
|
+
function getTeamsResponse(taskId) {
|
|
449
|
+
return _getTeamsResponse.apply(this, arguments);
|
|
450
|
+
}
|
|
451
|
+
function _getTeamsResponse() {
|
|
452
|
+
_getTeamsResponse = _async_to_generator(function(taskId) {
|
|
453
|
+
return _ts_generator(this, function(_state) {
|
|
454
|
+
console.log("Getting response for Teams task ".concat(taskId));
|
|
455
|
+
return [
|
|
456
|
+
2,
|
|
457
|
+
null
|
|
458
|
+
];
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
return _getTeamsResponse.apply(this, arguments);
|
|
462
|
+
}
|
|
463
|
+
var TeamsHumanFunction = /*#__PURE__*/ function() {
|
|
464
|
+
function TeamsHumanFunction(config) {
|
|
465
|
+
_class_call_check(this, TeamsHumanFunction);
|
|
466
|
+
this.config = config;
|
|
467
|
+
}
|
|
468
|
+
_create_class(TeamsHumanFunction, [
|
|
469
|
+
{
|
|
470
|
+
key: "request",
|
|
471
|
+
value: function request(input) {
|
|
472
|
+
var _this = this;
|
|
473
|
+
return _async_to_generator(function() {
|
|
474
|
+
var taskId, messageId;
|
|
475
|
+
return _ts_generator(this, function(_state) {
|
|
476
|
+
switch(_state.label){
|
|
477
|
+
case 0:
|
|
478
|
+
taskId = "task-".concat(Date.now());
|
|
479
|
+
return [
|
|
480
|
+
4,
|
|
481
|
+
createTeamsMessage(taskId, input, _this.config)
|
|
482
|
+
];
|
|
483
|
+
case 1:
|
|
484
|
+
messageId = _state.sent().messageId;
|
|
485
|
+
return [
|
|
486
|
+
2,
|
|
487
|
+
{
|
|
488
|
+
taskId: taskId,
|
|
489
|
+
status: "pending",
|
|
490
|
+
messageId: {
|
|
491
|
+
slack: "",
|
|
492
|
+
teams: messageId,
|
|
493
|
+
react: "",
|
|
494
|
+
email: ""
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
];
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
})();
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
key: "getResponse",
|
|
505
|
+
value: function getResponse(taskId) {
|
|
506
|
+
return _async_to_generator(function() {
|
|
507
|
+
return _ts_generator(this, function(_state) {
|
|
508
|
+
return [
|
|
509
|
+
2,
|
|
510
|
+
getTeamsResponse(taskId)
|
|
511
|
+
];
|
|
512
|
+
});
|
|
513
|
+
})();
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
]);
|
|
517
|
+
return TeamsHumanFunction;
|
|
518
|
+
}();
|
|
519
|
+
// src/platforms/react/index.tsx
|
|
520
|
+
var import_react = require("react");
|
|
521
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
522
|
+
function HumanFeedback(param) {
|
|
523
|
+
var taskId = param.taskId, title = param.title, description = param.description, input = param.input, options = param.options, freeText = param.freeText, onSubmit = param.onSubmit, config = param.config;
|
|
524
|
+
var _config_styles, _config_styles1, _config_styles2, _config_styles3, _config_styles4, _config_styles5, _config_styles6;
|
|
525
|
+
var _ref = _sliced_to_array((0, import_react.useState)(""), 2), response = _ref[0], setResponse = _ref[1];
|
|
526
|
+
var _ref1 = _sliced_to_array((0, import_react.useState)(""), 2), selectedOption = _ref1[0], setSelectedOption = _ref1[1];
|
|
527
|
+
var handleSubmit = function(e) {
|
|
528
|
+
e.preventDefault();
|
|
529
|
+
var responseObj = {};
|
|
530
|
+
if (selectedOption) {
|
|
531
|
+
responseObj.selectedOption = selectedOption;
|
|
532
|
+
}
|
|
533
|
+
if (response) {
|
|
534
|
+
responseObj.freeText = response;
|
|
535
|
+
}
|
|
536
|
+
onSubmit(responseObj);
|
|
537
|
+
};
|
|
538
|
+
var styles = {
|
|
539
|
+
container: _object_spread({
|
|
540
|
+
maxWidth: "500px",
|
|
541
|
+
margin: "0 auto",
|
|
542
|
+
padding: "20px",
|
|
543
|
+
borderRadius: "8px",
|
|
544
|
+
boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)",
|
|
545
|
+
backgroundColor: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#1a1a1a" : "#fff",
|
|
546
|
+
color: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#fff" : "#333"
|
|
547
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles = config.styles) === null || _config_styles === void 0 ? void 0 : _config_styles.container),
|
|
548
|
+
title: _object_spread({
|
|
549
|
+
fontSize: "20px",
|
|
550
|
+
fontWeight: "bold",
|
|
551
|
+
marginBottom: "10px"
|
|
552
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles1 = config.styles) === null || _config_styles1 === void 0 ? void 0 : _config_styles1.title),
|
|
553
|
+
description: _object_spread({
|
|
554
|
+
marginBottom: "20px"
|
|
555
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles2 = config.styles) === null || _config_styles2 === void 0 ? void 0 : _config_styles2.description),
|
|
556
|
+
optionsContainer: _object_spread({
|
|
557
|
+
marginBottom: "20px"
|
|
558
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles3 = config.styles) === null || _config_styles3 === void 0 ? void 0 : _config_styles3.optionsContainer),
|
|
559
|
+
option: _object_spread({
|
|
560
|
+
display: "block",
|
|
561
|
+
margin: "8px 0"
|
|
562
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles4 = config.styles) === null || _config_styles4 === void 0 ? void 0 : _config_styles4.option),
|
|
563
|
+
textarea: _object_spread({
|
|
564
|
+
width: "100%",
|
|
565
|
+
padding: "10px",
|
|
566
|
+
borderRadius: "4px",
|
|
567
|
+
border: "1px solid #ccc",
|
|
568
|
+
minHeight: "100px",
|
|
569
|
+
marginBottom: "20px",
|
|
570
|
+
backgroundColor: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#333" : "#fff",
|
|
571
|
+
color: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#fff" : "#333"
|
|
572
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles5 = config.styles) === null || _config_styles5 === void 0 ? void 0 : _config_styles5.textarea),
|
|
573
|
+
button: _object_spread({
|
|
574
|
+
padding: "10px 20px",
|
|
575
|
+
backgroundColor: "#0070f3",
|
|
576
|
+
color: "white",
|
|
577
|
+
border: "none",
|
|
578
|
+
borderRadius: "4px",
|
|
579
|
+
cursor: "pointer"
|
|
580
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles6 = config.styles) === null || _config_styles6 === void 0 ? void 0 : _config_styles6.button)
|
|
581
|
+
};
|
|
582
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
583
|
+
style: styles.container,
|
|
584
|
+
children: [
|
|
585
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
|
|
586
|
+
style: styles.title,
|
|
587
|
+
children: title
|
|
588
|
+
}),
|
|
589
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
590
|
+
style: styles.description,
|
|
591
|
+
children: description
|
|
592
|
+
}),
|
|
593
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
|
|
594
|
+
onSubmit: handleSubmit,
|
|
595
|
+
children: [
|
|
596
|
+
options && options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
597
|
+
style: styles.optionsContainer,
|
|
598
|
+
children: options.map(function(option, index) {
|
|
599
|
+
var value = typeof option === "string" ? option : option.value;
|
|
600
|
+
var label = typeof option === "string" ? option : option.label;
|
|
601
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
|
|
602
|
+
style: styles.option,
|
|
603
|
+
children: [
|
|
604
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
|
|
605
|
+
type: "radio",
|
|
606
|
+
name: "option",
|
|
607
|
+
value: value,
|
|
608
|
+
checked: selectedOption === value,
|
|
609
|
+
onChange: function() {
|
|
610
|
+
return setSelectedOption(value);
|
|
611
|
+
}
|
|
612
|
+
}),
|
|
613
|
+
" ",
|
|
614
|
+
label
|
|
615
|
+
]
|
|
616
|
+
}, index);
|
|
617
|
+
})
|
|
618
|
+
}),
|
|
619
|
+
freeText && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
|
|
620
|
+
style: styles.textarea,
|
|
621
|
+
value: response,
|
|
622
|
+
onChange: function(e) {
|
|
623
|
+
return setResponse(e.target.value);
|
|
624
|
+
},
|
|
625
|
+
placeholder: "Enter your response..."
|
|
626
|
+
}),
|
|
627
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
628
|
+
type: "submit",
|
|
629
|
+
style: styles.button,
|
|
630
|
+
children: "Submit"
|
|
631
|
+
})
|
|
632
|
+
]
|
|
633
|
+
})
|
|
634
|
+
]
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
var responses = /* @__PURE__ */ new Map();
|
|
638
|
+
var tasks = /* @__PURE__ */ new Map();
|
|
639
|
+
var ReactHumanFunction = /*#__PURE__*/ function() {
|
|
640
|
+
function ReactHumanFunction(config) {
|
|
641
|
+
_class_call_check(this, ReactHumanFunction);
|
|
642
|
+
this.config = config;
|
|
643
|
+
}
|
|
644
|
+
_create_class(ReactHumanFunction, [
|
|
645
|
+
{
|
|
646
|
+
key: "request",
|
|
647
|
+
value: function request(input) {
|
|
648
|
+
return _async_to_generator(function() {
|
|
649
|
+
var taskId;
|
|
650
|
+
return _ts_generator(this, function(_state) {
|
|
651
|
+
taskId = "task-".concat(Date.now());
|
|
652
|
+
tasks.set(taskId, {
|
|
653
|
+
status: "pending"
|
|
654
|
+
});
|
|
655
|
+
return [
|
|
656
|
+
2,
|
|
657
|
+
{
|
|
658
|
+
taskId: taskId,
|
|
659
|
+
status: "pending",
|
|
660
|
+
messageId: {
|
|
661
|
+
slack: "",
|
|
662
|
+
teams: "",
|
|
663
|
+
react: taskId,
|
|
664
|
+
email: ""
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
];
|
|
668
|
+
});
|
|
669
|
+
})();
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
key: "getResponse",
|
|
674
|
+
value: function getResponse(taskId) {
|
|
675
|
+
return _async_to_generator(function() {
|
|
676
|
+
var response;
|
|
677
|
+
return _ts_generator(this, function(_state) {
|
|
678
|
+
response = responses.get(taskId);
|
|
679
|
+
return [
|
|
680
|
+
2,
|
|
681
|
+
response || null
|
|
682
|
+
];
|
|
683
|
+
});
|
|
684
|
+
})();
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
/**
|
|
689
|
+
* Handle a response submission
|
|
690
|
+
*/ key: "handleResponse",
|
|
691
|
+
value: function handleResponse(taskId, response) {
|
|
692
|
+
responses.set(taskId, response);
|
|
693
|
+
tasks.set(taskId, {
|
|
694
|
+
status: "completed"
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
/**
|
|
700
|
+
* Get a React component for this human function
|
|
701
|
+
*/ key: "getComponent",
|
|
702
|
+
value: function getComponent(taskId, input) {
|
|
703
|
+
var _this = this;
|
|
704
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HumanFeedback, {
|
|
705
|
+
taskId: taskId,
|
|
706
|
+
title: this.config.title,
|
|
707
|
+
description: this.config.description,
|
|
708
|
+
input: input,
|
|
709
|
+
options: this.config.options,
|
|
710
|
+
freeText: this.config.freeText,
|
|
711
|
+
config: this.config,
|
|
712
|
+
onSubmit: function(response) {
|
|
713
|
+
return _this.handleResponse(taskId, response);
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
]);
|
|
719
|
+
return ReactHumanFunction;
|
|
720
|
+
}();
|
|
721
|
+
// src/platforms/email/index.tsx
|
|
722
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
723
|
+
function EmailTemplate(param) {
|
|
724
|
+
var taskId = param.taskId, title = param.title, description = param.description, options = param.options, callbackUrl = param.callbackUrl;
|
|
725
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", {
|
|
726
|
+
children: [
|
|
727
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h1", {
|
|
728
|
+
children: title
|
|
729
|
+
}),
|
|
730
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", {
|
|
731
|
+
children: description
|
|
732
|
+
}),
|
|
733
|
+
options && options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", {
|
|
734
|
+
children: [
|
|
735
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", {
|
|
736
|
+
children: "Please select one of the following options:"
|
|
737
|
+
}),
|
|
738
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", {
|
|
739
|
+
children: options.map(function(option, index) {
|
|
740
|
+
var value = typeof option === "string" ? option : option.value;
|
|
741
|
+
var label = typeof option === "string" ? option : option.label;
|
|
742
|
+
var responseUrl = callbackUrl ? "".concat(callbackUrl, "?taskId=").concat(taskId, "&option=").concat(encodeURIComponent(value)) : "#";
|
|
743
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", {
|
|
744
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
|
|
745
|
+
href: responseUrl,
|
|
746
|
+
children: label
|
|
747
|
+
})
|
|
748
|
+
}, index);
|
|
749
|
+
})
|
|
750
|
+
})
|
|
751
|
+
]
|
|
752
|
+
}),
|
|
753
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", {
|
|
754
|
+
children: "Or, you can reply to this email with your response."
|
|
755
|
+
})
|
|
756
|
+
]
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
function sendEmail(config) {
|
|
760
|
+
return _sendEmail.apply(this, arguments);
|
|
761
|
+
}
|
|
762
|
+
function _sendEmail() {
|
|
763
|
+
_sendEmail = _async_to_generator(function(config) {
|
|
764
|
+
return _ts_generator(this, function(_state) {
|
|
765
|
+
console.log("Sending email to ".concat(config.to));
|
|
766
|
+
console.log("Title: ".concat(config.title));
|
|
767
|
+
console.log("Description: ".concat(config.description));
|
|
768
|
+
return [
|
|
769
|
+
2,
|
|
770
|
+
{
|
|
771
|
+
messageId: "email-".concat(config.taskId, "-").concat(Date.now())
|
|
772
|
+
}
|
|
773
|
+
];
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
return _sendEmail.apply(this, arguments);
|
|
777
|
+
}
|
|
778
|
+
function getEmailResponse(taskId) {
|
|
779
|
+
return _getEmailResponse.apply(this, arguments);
|
|
780
|
+
}
|
|
781
|
+
function _getEmailResponse() {
|
|
782
|
+
_getEmailResponse = _async_to_generator(function(taskId) {
|
|
783
|
+
return _ts_generator(this, function(_state) {
|
|
784
|
+
console.log("Getting response for email task ".concat(taskId));
|
|
785
|
+
return [
|
|
786
|
+
2,
|
|
787
|
+
null
|
|
788
|
+
];
|
|
789
|
+
});
|
|
790
|
+
});
|
|
791
|
+
return _getEmailResponse.apply(this, arguments);
|
|
792
|
+
}
|
|
793
|
+
var EmailHumanFunction = /*#__PURE__*/ function() {
|
|
794
|
+
function EmailHumanFunction(config) {
|
|
795
|
+
_class_call_check(this, EmailHumanFunction);
|
|
796
|
+
this.config = config;
|
|
797
|
+
}
|
|
798
|
+
_create_class(EmailHumanFunction, [
|
|
799
|
+
{
|
|
800
|
+
key: "request",
|
|
801
|
+
value: function request(input) {
|
|
802
|
+
var _this = this;
|
|
803
|
+
return _async_to_generator(function() {
|
|
804
|
+
var taskId, messageId;
|
|
805
|
+
return _ts_generator(this, function(_state) {
|
|
806
|
+
switch(_state.label){
|
|
807
|
+
case 0:
|
|
808
|
+
taskId = "task-".concat(Date.now());
|
|
809
|
+
return [
|
|
810
|
+
4,
|
|
811
|
+
sendEmail(_object_spread_props(_object_spread({}, _this.config), {
|
|
812
|
+
taskId: taskId
|
|
813
|
+
}))
|
|
814
|
+
];
|
|
815
|
+
case 1:
|
|
816
|
+
messageId = _state.sent().messageId;
|
|
817
|
+
return [
|
|
818
|
+
2,
|
|
819
|
+
{
|
|
820
|
+
taskId: taskId,
|
|
821
|
+
status: "pending",
|
|
822
|
+
messageId: {
|
|
823
|
+
slack: "",
|
|
824
|
+
teams: "",
|
|
825
|
+
react: "",
|
|
826
|
+
email: messageId
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
];
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
})();
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
key: "getResponse",
|
|
837
|
+
value: function getResponse(taskId) {
|
|
838
|
+
return _async_to_generator(function() {
|
|
839
|
+
return _ts_generator(this, function(_state) {
|
|
840
|
+
return [
|
|
841
|
+
2,
|
|
842
|
+
getEmailResponse(taskId)
|
|
843
|
+
];
|
|
844
|
+
});
|
|
845
|
+
})();
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
/**
|
|
850
|
+
* Get a React component for this email template
|
|
851
|
+
*/ key: "getEmailComponent",
|
|
852
|
+
value: function getEmailComponent(taskId) {
|
|
853
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmailTemplate, {
|
|
854
|
+
taskId: taskId,
|
|
855
|
+
title: this.config.title,
|
|
856
|
+
description: this.config.description,
|
|
857
|
+
options: this.config.options,
|
|
858
|
+
callbackUrl: this.config.callbackUrl
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
]);
|
|
863
|
+
return EmailHumanFunction;
|
|
864
|
+
}();
|
|
865
|
+
// src/core/factory.ts
|
|
866
|
+
function createHumanFunction(options) {
|
|
867
|
+
var platform = options.platform;
|
|
868
|
+
switch(platform){
|
|
869
|
+
case "slack":
|
|
870
|
+
return new SlackHumanFunction(options);
|
|
871
|
+
case "teams":
|
|
872
|
+
return new TeamsHumanFunction(options);
|
|
873
|
+
case "react":
|
|
874
|
+
return new ReactHumanFunction(options);
|
|
875
|
+
case "email":
|
|
876
|
+
if (!options.to) {
|
|
877
|
+
throw new Error('Email platform requires a "to" field in options');
|
|
878
|
+
}
|
|
879
|
+
return new EmailHumanFunction(options);
|
|
880
|
+
default:
|
|
881
|
+
throw new Error("Unsupported platform: ".concat(platform));
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
885
|
+
0 && (module.exports = {
|
|
886
|
+
EmailHumanFunction: EmailHumanFunction,
|
|
887
|
+
EmailTemplate: EmailTemplate,
|
|
888
|
+
HumanFeedback: HumanFeedback,
|
|
889
|
+
ReactHumanFunction: ReactHumanFunction,
|
|
890
|
+
SlackHumanFunction: SlackHumanFunction,
|
|
891
|
+
TeamsHumanFunction: TeamsHumanFunction,
|
|
892
|
+
createHumanFunction: createHumanFunction,
|
|
893
|
+
createSlackMessage: createSlackMessage,
|
|
894
|
+
createTeamsMessage: createTeamsMessage,
|
|
895
|
+
getEmailResponse: getEmailResponse,
|
|
896
|
+
getSlackResponse: getSlackResponse,
|
|
897
|
+
getTeamsResponse: getTeamsResponse,
|
|
898
|
+
sendEmail: sendEmail
|
|
899
|
+
});
|