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.js
ADDED
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
// src/platforms/slack/index.ts
|
|
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 _unsupported_iterable_to_array(o, minLen) {
|
|
141
|
+
if (!o) return;
|
|
142
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
143
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
144
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
145
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
146
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
147
|
+
}
|
|
148
|
+
function _ts_generator(thisArg, body) {
|
|
149
|
+
var f, y, t, g, _ = {
|
|
150
|
+
label: 0,
|
|
151
|
+
sent: function() {
|
|
152
|
+
if (t[0] & 1) throw t[1];
|
|
153
|
+
return t[1];
|
|
154
|
+
},
|
|
155
|
+
trys: [],
|
|
156
|
+
ops: []
|
|
157
|
+
};
|
|
158
|
+
return g = {
|
|
159
|
+
next: verb(0),
|
|
160
|
+
"throw": verb(1),
|
|
161
|
+
"return": verb(2)
|
|
162
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
163
|
+
return this;
|
|
164
|
+
}), g;
|
|
165
|
+
function verb(n) {
|
|
166
|
+
return function(v) {
|
|
167
|
+
return step([
|
|
168
|
+
n,
|
|
169
|
+
v
|
|
170
|
+
]);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function step(op) {
|
|
174
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
175
|
+
while(_)try {
|
|
176
|
+
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;
|
|
177
|
+
if (y = 0, t) op = [
|
|
178
|
+
op[0] & 2,
|
|
179
|
+
t.value
|
|
180
|
+
];
|
|
181
|
+
switch(op[0]){
|
|
182
|
+
case 0:
|
|
183
|
+
case 1:
|
|
184
|
+
t = op;
|
|
185
|
+
break;
|
|
186
|
+
case 4:
|
|
187
|
+
_.label++;
|
|
188
|
+
return {
|
|
189
|
+
value: op[1],
|
|
190
|
+
done: false
|
|
191
|
+
};
|
|
192
|
+
case 5:
|
|
193
|
+
_.label++;
|
|
194
|
+
y = op[1];
|
|
195
|
+
op = [
|
|
196
|
+
0
|
|
197
|
+
];
|
|
198
|
+
continue;
|
|
199
|
+
case 7:
|
|
200
|
+
op = _.ops.pop();
|
|
201
|
+
_.trys.pop();
|
|
202
|
+
continue;
|
|
203
|
+
default:
|
|
204
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
205
|
+
_ = 0;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
209
|
+
_.label = op[1];
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
213
|
+
_.label = t[1];
|
|
214
|
+
t = op;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (t && _.label < t[2]) {
|
|
218
|
+
_.label = t[2];
|
|
219
|
+
_.ops.push(op);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (t[2]) _.ops.pop();
|
|
223
|
+
_.trys.pop();
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
op = body.call(thisArg, _);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
op = [
|
|
229
|
+
6,
|
|
230
|
+
e
|
|
231
|
+
];
|
|
232
|
+
y = 0;
|
|
233
|
+
} finally{
|
|
234
|
+
f = t = 0;
|
|
235
|
+
}
|
|
236
|
+
if (op[0] & 5) throw op[1];
|
|
237
|
+
return {
|
|
238
|
+
value: op[0] ? op[1] : void 0,
|
|
239
|
+
done: true
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function createSlackMessage(taskId, input, config) {
|
|
244
|
+
return _createSlackMessage.apply(this, arguments);
|
|
245
|
+
}
|
|
246
|
+
function _createSlackMessage() {
|
|
247
|
+
_createSlackMessage = _async_to_generator(function(taskId, input, config) {
|
|
248
|
+
return _ts_generator(this, function(_state) {
|
|
249
|
+
console.log("Creating Slack message for task ".concat(taskId));
|
|
250
|
+
console.log("Title: ".concat(config.title));
|
|
251
|
+
console.log("Description: ".concat(config.description));
|
|
252
|
+
return [
|
|
253
|
+
2,
|
|
254
|
+
{
|
|
255
|
+
messageId: "slack-".concat(taskId, "-").concat(Date.now())
|
|
256
|
+
}
|
|
257
|
+
];
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
return _createSlackMessage.apply(this, arguments);
|
|
261
|
+
}
|
|
262
|
+
function getSlackResponse(taskId) {
|
|
263
|
+
return _getSlackResponse.apply(this, arguments);
|
|
264
|
+
}
|
|
265
|
+
function _getSlackResponse() {
|
|
266
|
+
_getSlackResponse = _async_to_generator(function(taskId) {
|
|
267
|
+
return _ts_generator(this, function(_state) {
|
|
268
|
+
console.log("Getting response for Slack task ".concat(taskId));
|
|
269
|
+
return [
|
|
270
|
+
2,
|
|
271
|
+
null
|
|
272
|
+
];
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
return _getSlackResponse.apply(this, arguments);
|
|
276
|
+
}
|
|
277
|
+
var SlackHumanFunction = /*#__PURE__*/ function() {
|
|
278
|
+
"use strict";
|
|
279
|
+
function SlackHumanFunction(config) {
|
|
280
|
+
_class_call_check(this, SlackHumanFunction);
|
|
281
|
+
this.config = config;
|
|
282
|
+
}
|
|
283
|
+
_create_class(SlackHumanFunction, [
|
|
284
|
+
{
|
|
285
|
+
key: "request",
|
|
286
|
+
value: function request(input) {
|
|
287
|
+
var _this = this;
|
|
288
|
+
return _async_to_generator(function() {
|
|
289
|
+
var taskId, messageId;
|
|
290
|
+
return _ts_generator(this, function(_state) {
|
|
291
|
+
switch(_state.label){
|
|
292
|
+
case 0:
|
|
293
|
+
taskId = "task-".concat(Date.now());
|
|
294
|
+
return [
|
|
295
|
+
4,
|
|
296
|
+
createSlackMessage(taskId, input, _this.config)
|
|
297
|
+
];
|
|
298
|
+
case 1:
|
|
299
|
+
messageId = _state.sent().messageId;
|
|
300
|
+
return [
|
|
301
|
+
2,
|
|
302
|
+
{
|
|
303
|
+
taskId: taskId,
|
|
304
|
+
status: "pending",
|
|
305
|
+
messageId: {
|
|
306
|
+
slack: messageId,
|
|
307
|
+
teams: "",
|
|
308
|
+
react: "",
|
|
309
|
+
email: ""
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
})();
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
key: "getResponse",
|
|
320
|
+
value: function getResponse(taskId) {
|
|
321
|
+
return _async_to_generator(function() {
|
|
322
|
+
return _ts_generator(this, function(_state) {
|
|
323
|
+
return [
|
|
324
|
+
2,
|
|
325
|
+
getSlackResponse(taskId)
|
|
326
|
+
];
|
|
327
|
+
});
|
|
328
|
+
})();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
]);
|
|
332
|
+
return SlackHumanFunction;
|
|
333
|
+
}();
|
|
334
|
+
function createTeamsMessage(taskId, input, config) {
|
|
335
|
+
return _createTeamsMessage.apply(this, arguments);
|
|
336
|
+
}
|
|
337
|
+
function _createTeamsMessage() {
|
|
338
|
+
_createTeamsMessage = // src/platforms/teams/index.ts
|
|
339
|
+
_async_to_generator(function(taskId, input, config) {
|
|
340
|
+
return _ts_generator(this, function(_state) {
|
|
341
|
+
console.log("Creating Teams message for task ".concat(taskId));
|
|
342
|
+
console.log("Title: ".concat(config.title));
|
|
343
|
+
console.log("Description: ".concat(config.description));
|
|
344
|
+
return [
|
|
345
|
+
2,
|
|
346
|
+
{
|
|
347
|
+
messageId: "teams-".concat(taskId, "-").concat(Date.now())
|
|
348
|
+
}
|
|
349
|
+
];
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
return _createTeamsMessage.apply(this, arguments);
|
|
353
|
+
}
|
|
354
|
+
function getTeamsResponse(taskId) {
|
|
355
|
+
return _getTeamsResponse.apply(this, arguments);
|
|
356
|
+
}
|
|
357
|
+
function _getTeamsResponse() {
|
|
358
|
+
_getTeamsResponse = _async_to_generator(function(taskId) {
|
|
359
|
+
return _ts_generator(this, function(_state) {
|
|
360
|
+
console.log("Getting response for Teams task ".concat(taskId));
|
|
361
|
+
return [
|
|
362
|
+
2,
|
|
363
|
+
null
|
|
364
|
+
];
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
return _getTeamsResponse.apply(this, arguments);
|
|
368
|
+
}
|
|
369
|
+
var TeamsHumanFunction = /*#__PURE__*/ function() {
|
|
370
|
+
"use strict";
|
|
371
|
+
function TeamsHumanFunction(config) {
|
|
372
|
+
_class_call_check(this, TeamsHumanFunction);
|
|
373
|
+
this.config = config;
|
|
374
|
+
}
|
|
375
|
+
_create_class(TeamsHumanFunction, [
|
|
376
|
+
{
|
|
377
|
+
key: "request",
|
|
378
|
+
value: function request(input) {
|
|
379
|
+
var _this = this;
|
|
380
|
+
return _async_to_generator(function() {
|
|
381
|
+
var taskId, messageId;
|
|
382
|
+
return _ts_generator(this, function(_state) {
|
|
383
|
+
switch(_state.label){
|
|
384
|
+
case 0:
|
|
385
|
+
taskId = "task-".concat(Date.now());
|
|
386
|
+
return [
|
|
387
|
+
4,
|
|
388
|
+
createTeamsMessage(taskId, input, _this.config)
|
|
389
|
+
];
|
|
390
|
+
case 1:
|
|
391
|
+
messageId = _state.sent().messageId;
|
|
392
|
+
return [
|
|
393
|
+
2,
|
|
394
|
+
{
|
|
395
|
+
taskId: taskId,
|
|
396
|
+
status: "pending",
|
|
397
|
+
messageId: {
|
|
398
|
+
slack: "",
|
|
399
|
+
teams: messageId,
|
|
400
|
+
react: "",
|
|
401
|
+
email: ""
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
})();
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
key: "getResponse",
|
|
412
|
+
value: function getResponse(taskId) {
|
|
413
|
+
return _async_to_generator(function() {
|
|
414
|
+
return _ts_generator(this, function(_state) {
|
|
415
|
+
return [
|
|
416
|
+
2,
|
|
417
|
+
getTeamsResponse(taskId)
|
|
418
|
+
];
|
|
419
|
+
});
|
|
420
|
+
})();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
]);
|
|
424
|
+
return TeamsHumanFunction;
|
|
425
|
+
}();
|
|
426
|
+
// src/platforms/react/index.tsx
|
|
427
|
+
import { useState } from "react";
|
|
428
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
429
|
+
function HumanFeedback(param) {
|
|
430
|
+
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;
|
|
431
|
+
var _config_styles, _config_styles1, _config_styles2, _config_styles3, _config_styles4, _config_styles5, _config_styles6;
|
|
432
|
+
var _useState = _sliced_to_array(useState(""), 2), response = _useState[0], setResponse = _useState[1];
|
|
433
|
+
var _useState1 = _sliced_to_array(useState(""), 2), selectedOption = _useState1[0], setSelectedOption = _useState1[1];
|
|
434
|
+
var handleSubmit = function(e) {
|
|
435
|
+
e.preventDefault();
|
|
436
|
+
var responseObj = {};
|
|
437
|
+
if (selectedOption) {
|
|
438
|
+
responseObj.selectedOption = selectedOption;
|
|
439
|
+
}
|
|
440
|
+
if (response) {
|
|
441
|
+
responseObj.freeText = response;
|
|
442
|
+
}
|
|
443
|
+
onSubmit(responseObj);
|
|
444
|
+
};
|
|
445
|
+
var styles = {
|
|
446
|
+
container: _object_spread({
|
|
447
|
+
maxWidth: "500px",
|
|
448
|
+
margin: "0 auto",
|
|
449
|
+
padding: "20px",
|
|
450
|
+
borderRadius: "8px",
|
|
451
|
+
boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)",
|
|
452
|
+
backgroundColor: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#1a1a1a" : "#fff",
|
|
453
|
+
color: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#fff" : "#333"
|
|
454
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles = config.styles) === null || _config_styles === void 0 ? void 0 : _config_styles.container),
|
|
455
|
+
title: _object_spread({
|
|
456
|
+
fontSize: "20px",
|
|
457
|
+
fontWeight: "bold",
|
|
458
|
+
marginBottom: "10px"
|
|
459
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles1 = config.styles) === null || _config_styles1 === void 0 ? void 0 : _config_styles1.title),
|
|
460
|
+
description: _object_spread({
|
|
461
|
+
marginBottom: "20px"
|
|
462
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles2 = config.styles) === null || _config_styles2 === void 0 ? void 0 : _config_styles2.description),
|
|
463
|
+
optionsContainer: _object_spread({
|
|
464
|
+
marginBottom: "20px"
|
|
465
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles3 = config.styles) === null || _config_styles3 === void 0 ? void 0 : _config_styles3.optionsContainer),
|
|
466
|
+
option: _object_spread({
|
|
467
|
+
display: "block",
|
|
468
|
+
margin: "8px 0"
|
|
469
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles4 = config.styles) === null || _config_styles4 === void 0 ? void 0 : _config_styles4.option),
|
|
470
|
+
textarea: _object_spread({
|
|
471
|
+
width: "100%",
|
|
472
|
+
padding: "10px",
|
|
473
|
+
borderRadius: "4px",
|
|
474
|
+
border: "1px solid #ccc",
|
|
475
|
+
minHeight: "100px",
|
|
476
|
+
marginBottom: "20px",
|
|
477
|
+
backgroundColor: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#333" : "#fff",
|
|
478
|
+
color: (config === null || config === void 0 ? void 0 : config.theme) === "dark" ? "#fff" : "#333"
|
|
479
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles5 = config.styles) === null || _config_styles5 === void 0 ? void 0 : _config_styles5.textarea),
|
|
480
|
+
button: _object_spread({
|
|
481
|
+
padding: "10px 20px",
|
|
482
|
+
backgroundColor: "#0070f3",
|
|
483
|
+
color: "white",
|
|
484
|
+
border: "none",
|
|
485
|
+
borderRadius: "4px",
|
|
486
|
+
cursor: "pointer"
|
|
487
|
+
}, config === null || config === void 0 ? void 0 : (_config_styles6 = config.styles) === null || _config_styles6 === void 0 ? void 0 : _config_styles6.button)
|
|
488
|
+
};
|
|
489
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
490
|
+
style: styles.container,
|
|
491
|
+
children: [
|
|
492
|
+
/* @__PURE__ */ jsx("h2", {
|
|
493
|
+
style: styles.title,
|
|
494
|
+
children: title
|
|
495
|
+
}),
|
|
496
|
+
/* @__PURE__ */ jsx("p", {
|
|
497
|
+
style: styles.description,
|
|
498
|
+
children: description
|
|
499
|
+
}),
|
|
500
|
+
/* @__PURE__ */ jsxs("form", {
|
|
501
|
+
onSubmit: handleSubmit,
|
|
502
|
+
children: [
|
|
503
|
+
options && options.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
504
|
+
style: styles.optionsContainer,
|
|
505
|
+
children: options.map(function(option, index) {
|
|
506
|
+
var value = typeof option === "string" ? option : option.value;
|
|
507
|
+
var label = typeof option === "string" ? option : option.label;
|
|
508
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
509
|
+
style: styles.option,
|
|
510
|
+
children: [
|
|
511
|
+
/* @__PURE__ */ jsx("input", {
|
|
512
|
+
type: "radio",
|
|
513
|
+
name: "option",
|
|
514
|
+
value: value,
|
|
515
|
+
checked: selectedOption === value,
|
|
516
|
+
onChange: function() {
|
|
517
|
+
return setSelectedOption(value);
|
|
518
|
+
}
|
|
519
|
+
}),
|
|
520
|
+
" ",
|
|
521
|
+
label
|
|
522
|
+
]
|
|
523
|
+
}, index);
|
|
524
|
+
})
|
|
525
|
+
}),
|
|
526
|
+
freeText && /* @__PURE__ */ jsx("textarea", {
|
|
527
|
+
style: styles.textarea,
|
|
528
|
+
value: response,
|
|
529
|
+
onChange: function(e) {
|
|
530
|
+
return setResponse(e.target.value);
|
|
531
|
+
},
|
|
532
|
+
placeholder: "Enter your response..."
|
|
533
|
+
}),
|
|
534
|
+
/* @__PURE__ */ jsx("button", {
|
|
535
|
+
type: "submit",
|
|
536
|
+
style: styles.button,
|
|
537
|
+
children: "Submit"
|
|
538
|
+
})
|
|
539
|
+
]
|
|
540
|
+
})
|
|
541
|
+
]
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
var responses = /* @__PURE__ */ new Map();
|
|
545
|
+
var tasks = /* @__PURE__ */ new Map();
|
|
546
|
+
var ReactHumanFunction = /*#__PURE__*/ function() {
|
|
547
|
+
"use strict";
|
|
548
|
+
function ReactHumanFunction(config) {
|
|
549
|
+
_class_call_check(this, ReactHumanFunction);
|
|
550
|
+
this.config = config;
|
|
551
|
+
}
|
|
552
|
+
_create_class(ReactHumanFunction, [
|
|
553
|
+
{
|
|
554
|
+
key: "request",
|
|
555
|
+
value: function request(input) {
|
|
556
|
+
return _async_to_generator(function() {
|
|
557
|
+
var taskId;
|
|
558
|
+
return _ts_generator(this, function(_state) {
|
|
559
|
+
taskId = "task-".concat(Date.now());
|
|
560
|
+
tasks.set(taskId, {
|
|
561
|
+
status: "pending"
|
|
562
|
+
});
|
|
563
|
+
return [
|
|
564
|
+
2,
|
|
565
|
+
{
|
|
566
|
+
taskId: taskId,
|
|
567
|
+
status: "pending",
|
|
568
|
+
messageId: {
|
|
569
|
+
slack: "",
|
|
570
|
+
teams: "",
|
|
571
|
+
react: taskId,
|
|
572
|
+
email: ""
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
];
|
|
576
|
+
});
|
|
577
|
+
})();
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
key: "getResponse",
|
|
582
|
+
value: function getResponse(taskId) {
|
|
583
|
+
return _async_to_generator(function() {
|
|
584
|
+
var response;
|
|
585
|
+
return _ts_generator(this, function(_state) {
|
|
586
|
+
response = responses.get(taskId);
|
|
587
|
+
return [
|
|
588
|
+
2,
|
|
589
|
+
response || null
|
|
590
|
+
];
|
|
591
|
+
});
|
|
592
|
+
})();
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
/**
|
|
597
|
+
* Handle a response submission
|
|
598
|
+
*/ key: "handleResponse",
|
|
599
|
+
value: function handleResponse(taskId, response) {
|
|
600
|
+
responses.set(taskId, response);
|
|
601
|
+
tasks.set(taskId, {
|
|
602
|
+
status: "completed"
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
/**
|
|
608
|
+
* Get a React component for this human function
|
|
609
|
+
*/ key: "getComponent",
|
|
610
|
+
value: function getComponent(taskId, input) {
|
|
611
|
+
var _this = this;
|
|
612
|
+
return /* @__PURE__ */ jsx(HumanFeedback, {
|
|
613
|
+
taskId: taskId,
|
|
614
|
+
title: this.config.title,
|
|
615
|
+
description: this.config.description,
|
|
616
|
+
input: input,
|
|
617
|
+
options: this.config.options,
|
|
618
|
+
freeText: this.config.freeText,
|
|
619
|
+
config: this.config,
|
|
620
|
+
onSubmit: function(response) {
|
|
621
|
+
return _this.handleResponse(taskId, response);
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
]);
|
|
627
|
+
return ReactHumanFunction;
|
|
628
|
+
}();
|
|
629
|
+
// src/platforms/email/index.tsx
|
|
630
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
631
|
+
function EmailTemplate(param) {
|
|
632
|
+
var taskId = param.taskId, title = param.title, description = param.description, options = param.options, callbackUrl = param.callbackUrl;
|
|
633
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
634
|
+
children: [
|
|
635
|
+
/* @__PURE__ */ jsx2("h1", {
|
|
636
|
+
children: title
|
|
637
|
+
}),
|
|
638
|
+
/* @__PURE__ */ jsx2("p", {
|
|
639
|
+
children: description
|
|
640
|
+
}),
|
|
641
|
+
options && options.length > 0 && /* @__PURE__ */ jsxs2("div", {
|
|
642
|
+
children: [
|
|
643
|
+
/* @__PURE__ */ jsx2("p", {
|
|
644
|
+
children: "Please select one of the following options:"
|
|
645
|
+
}),
|
|
646
|
+
/* @__PURE__ */ jsx2("ul", {
|
|
647
|
+
children: options.map(function(option, index) {
|
|
648
|
+
var value = typeof option === "string" ? option : option.value;
|
|
649
|
+
var label = typeof option === "string" ? option : option.label;
|
|
650
|
+
var responseUrl = callbackUrl ? "".concat(callbackUrl, "?taskId=").concat(taskId, "&option=").concat(encodeURIComponent(value)) : "#";
|
|
651
|
+
return /* @__PURE__ */ jsx2("li", {
|
|
652
|
+
children: /* @__PURE__ */ jsx2("a", {
|
|
653
|
+
href: responseUrl,
|
|
654
|
+
children: label
|
|
655
|
+
})
|
|
656
|
+
}, index);
|
|
657
|
+
})
|
|
658
|
+
})
|
|
659
|
+
]
|
|
660
|
+
}),
|
|
661
|
+
/* @__PURE__ */ jsx2("p", {
|
|
662
|
+
children: "Or, you can reply to this email with your response."
|
|
663
|
+
})
|
|
664
|
+
]
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
function sendEmail(config) {
|
|
668
|
+
return _sendEmail.apply(this, arguments);
|
|
669
|
+
}
|
|
670
|
+
function _sendEmail() {
|
|
671
|
+
_sendEmail = _async_to_generator(function(config) {
|
|
672
|
+
return _ts_generator(this, function(_state) {
|
|
673
|
+
console.log("Sending email to ".concat(config.to));
|
|
674
|
+
console.log("Title: ".concat(config.title));
|
|
675
|
+
console.log("Description: ".concat(config.description));
|
|
676
|
+
return [
|
|
677
|
+
2,
|
|
678
|
+
{
|
|
679
|
+
messageId: "email-".concat(config.taskId, "-").concat(Date.now())
|
|
680
|
+
}
|
|
681
|
+
];
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
return _sendEmail.apply(this, arguments);
|
|
685
|
+
}
|
|
686
|
+
function getEmailResponse(taskId) {
|
|
687
|
+
return _getEmailResponse.apply(this, arguments);
|
|
688
|
+
}
|
|
689
|
+
function _getEmailResponse() {
|
|
690
|
+
_getEmailResponse = _async_to_generator(function(taskId) {
|
|
691
|
+
return _ts_generator(this, function(_state) {
|
|
692
|
+
console.log("Getting response for email task ".concat(taskId));
|
|
693
|
+
return [
|
|
694
|
+
2,
|
|
695
|
+
null
|
|
696
|
+
];
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
return _getEmailResponse.apply(this, arguments);
|
|
700
|
+
}
|
|
701
|
+
var EmailHumanFunction = /*#__PURE__*/ function() {
|
|
702
|
+
"use strict";
|
|
703
|
+
function EmailHumanFunction(config) {
|
|
704
|
+
_class_call_check(this, EmailHumanFunction);
|
|
705
|
+
this.config = config;
|
|
706
|
+
}
|
|
707
|
+
_create_class(EmailHumanFunction, [
|
|
708
|
+
{
|
|
709
|
+
key: "request",
|
|
710
|
+
value: function request(input) {
|
|
711
|
+
var _this = this;
|
|
712
|
+
return _async_to_generator(function() {
|
|
713
|
+
var taskId, messageId;
|
|
714
|
+
return _ts_generator(this, function(_state) {
|
|
715
|
+
switch(_state.label){
|
|
716
|
+
case 0:
|
|
717
|
+
taskId = "task-".concat(Date.now());
|
|
718
|
+
return [
|
|
719
|
+
4,
|
|
720
|
+
sendEmail(_object_spread_props(_object_spread({}, _this.config), {
|
|
721
|
+
taskId: taskId
|
|
722
|
+
}))
|
|
723
|
+
];
|
|
724
|
+
case 1:
|
|
725
|
+
messageId = _state.sent().messageId;
|
|
726
|
+
return [
|
|
727
|
+
2,
|
|
728
|
+
{
|
|
729
|
+
taskId: taskId,
|
|
730
|
+
status: "pending",
|
|
731
|
+
messageId: {
|
|
732
|
+
slack: "",
|
|
733
|
+
teams: "",
|
|
734
|
+
react: "",
|
|
735
|
+
email: messageId
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
})();
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
key: "getResponse",
|
|
746
|
+
value: function getResponse(taskId) {
|
|
747
|
+
return _async_to_generator(function() {
|
|
748
|
+
return _ts_generator(this, function(_state) {
|
|
749
|
+
return [
|
|
750
|
+
2,
|
|
751
|
+
getEmailResponse(taskId)
|
|
752
|
+
];
|
|
753
|
+
});
|
|
754
|
+
})();
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
/**
|
|
759
|
+
* Get a React component for this email template
|
|
760
|
+
*/ key: "getEmailComponent",
|
|
761
|
+
value: function getEmailComponent(taskId) {
|
|
762
|
+
return /* @__PURE__ */ jsx2(EmailTemplate, {
|
|
763
|
+
taskId: taskId,
|
|
764
|
+
title: this.config.title,
|
|
765
|
+
description: this.config.description,
|
|
766
|
+
options: this.config.options,
|
|
767
|
+
callbackUrl: this.config.callbackUrl
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
]);
|
|
772
|
+
return EmailHumanFunction;
|
|
773
|
+
}();
|
|
774
|
+
// src/core/factory.ts
|
|
775
|
+
function createHumanFunction(options) {
|
|
776
|
+
var platform = options.platform;
|
|
777
|
+
switch(platform){
|
|
778
|
+
case "slack":
|
|
779
|
+
return new SlackHumanFunction(options);
|
|
780
|
+
case "teams":
|
|
781
|
+
return new TeamsHumanFunction(options);
|
|
782
|
+
case "react":
|
|
783
|
+
return new ReactHumanFunction(options);
|
|
784
|
+
case "email":
|
|
785
|
+
if (!options.to) {
|
|
786
|
+
throw new Error('Email platform requires a "to" field in options');
|
|
787
|
+
}
|
|
788
|
+
return new EmailHumanFunction(options);
|
|
789
|
+
default:
|
|
790
|
+
throw new Error("Unsupported platform: ".concat(platform));
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
export { EmailHumanFunction, EmailTemplate, HumanFeedback, ReactHumanFunction, SlackHumanFunction, TeamsHumanFunction, createHumanFunction, createSlackMessage, createTeamsMessage, getEmailResponse, getSlackResponse, getTeamsResponse, sendEmail };
|