@superinterface/react 2.4.4 → 2.5.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/dist/index.cjs +9 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -20
- package/dist/index.d.ts +29 -20
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/{queryFns.cjs → server.cjs} +437 -172
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +39 -0
- package/dist/server.d.ts +39 -0
- package/dist/server.js +879 -0
- package/dist/server.js.map +1 -0
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +17 -21
- package/dist/types/index.d.ts +17 -21
- package/dist/utils.cjs +41 -248
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +15 -19
- package/dist/utils.d.ts +15 -19
- package/dist/utils.js +37 -244
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-CGpJFXMu.d.cts +0 -5
- package/dist/index-CGpJFXMu.d.ts +0 -5
- package/dist/index-u67QcaWg.d.cts +0 -11
- package/dist/index-u67QcaWg.d.ts +0 -11
- package/dist/mutationFns.cjs +0 -357
- package/dist/mutationFns.cjs.map +0 -1
- package/dist/mutationFns.d.cts +0 -15
- package/dist/mutationFns.d.ts +0 -15
- package/dist/mutationFns.js +0 -287
- package/dist/mutationFns.js.map +0 -1
- package/dist/queryFns.cjs.map +0 -1
- package/dist/queryFns.d.cts +0 -26
- package/dist/queryFns.d.ts +0 -26
- package/dist/queryFns.js +0 -618
- package/dist/queryFns.js.map +0 -1
package/dist/server.js
ADDED
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
// src/lib/runSteps/serializeRunStep.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_without_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
9
|
+
}
|
|
10
|
+
function _async_iterator(iterable) {
|
|
11
|
+
var method, async, sync, retry = 2;
|
|
12
|
+
for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
|
|
13
|
+
if (async && null != (method = iterable[async])) return method.call(iterable);
|
|
14
|
+
if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
|
|
15
|
+
async = "@@asyncIterator", sync = "@@iterator";
|
|
16
|
+
}
|
|
17
|
+
throw new TypeError("Object is not async iterable");
|
|
18
|
+
}
|
|
19
|
+
function AsyncFromSyncIterator(s) {
|
|
20
|
+
function AsyncFromSyncIteratorContinuation(r) {
|
|
21
|
+
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
22
|
+
var done = r.done;
|
|
23
|
+
return Promise.resolve(r.value).then(function(value) {
|
|
24
|
+
return {
|
|
25
|
+
value: value,
|
|
26
|
+
done: done
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return AsyncFromSyncIterator = function(s) {
|
|
31
|
+
this.s = s, this.n = s.next;
|
|
32
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
33
|
+
s: null,
|
|
34
|
+
n: null,
|
|
35
|
+
next: function() {
|
|
36
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
37
|
+
},
|
|
38
|
+
return: function(value) {
|
|
39
|
+
var ret = this.s.return;
|
|
40
|
+
return void 0 === ret ? Promise.resolve({
|
|
41
|
+
value: value,
|
|
42
|
+
done: !0
|
|
43
|
+
}) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
|
44
|
+
},
|
|
45
|
+
throw: function(value) {
|
|
46
|
+
var thr = this.s.return;
|
|
47
|
+
return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
|
48
|
+
}
|
|
49
|
+
}, new AsyncFromSyncIterator(s);
|
|
50
|
+
}
|
|
51
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
52
|
+
try {
|
|
53
|
+
var info = gen[key](arg);
|
|
54
|
+
var value = info.value;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
reject(error);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (info.done) {
|
|
60
|
+
resolve(value);
|
|
61
|
+
} else {
|
|
62
|
+
Promise.resolve(value).then(_next, _throw);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function _async_to_generator(fn) {
|
|
66
|
+
return function() {
|
|
67
|
+
var self = this, args = arguments;
|
|
68
|
+
return new Promise(function(resolve, reject) {
|
|
69
|
+
var gen = fn.apply(self, args);
|
|
70
|
+
function _next(value) {
|
|
71
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
72
|
+
}
|
|
73
|
+
function _throw(err) {
|
|
74
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
75
|
+
}
|
|
76
|
+
_next(undefined);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function _define_property(obj, key, value) {
|
|
81
|
+
if (key in obj) {
|
|
82
|
+
Object.defineProperty(obj, key, {
|
|
83
|
+
value: value,
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
obj[key] = value;
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
function _iterable_to_array(iter) {
|
|
94
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
95
|
+
}
|
|
96
|
+
function _non_iterable_spread() {
|
|
97
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
98
|
+
}
|
|
99
|
+
function _object_spread(target) {
|
|
100
|
+
for(var i = 1; i < arguments.length; i++){
|
|
101
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
102
|
+
var ownKeys = Object.keys(source);
|
|
103
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
104
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
105
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
ownKeys.forEach(function(key) {
|
|
109
|
+
_define_property(target, key, source[key]);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return target;
|
|
113
|
+
}
|
|
114
|
+
function ownKeys(object, enumerableOnly) {
|
|
115
|
+
var keys = Object.keys(object);
|
|
116
|
+
if (Object.getOwnPropertySymbols) {
|
|
117
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
118
|
+
if (enumerableOnly) {
|
|
119
|
+
symbols = symbols.filter(function(sym) {
|
|
120
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
keys.push.apply(keys, symbols);
|
|
124
|
+
}
|
|
125
|
+
return keys;
|
|
126
|
+
}
|
|
127
|
+
function _object_spread_props(target, source) {
|
|
128
|
+
source = source != null ? source : {};
|
|
129
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
130
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
131
|
+
} else {
|
|
132
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
133
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return target;
|
|
137
|
+
}
|
|
138
|
+
function _to_consumable_array(arr) {
|
|
139
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
140
|
+
}
|
|
141
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
142
|
+
if (!o) return;
|
|
143
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
144
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
145
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
146
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
147
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
148
|
+
}
|
|
149
|
+
function _ts_generator(thisArg, body) {
|
|
150
|
+
var f, y, t, g, _ = {
|
|
151
|
+
label: 0,
|
|
152
|
+
sent: function() {
|
|
153
|
+
if (t[0] & 1) throw t[1];
|
|
154
|
+
return t[1];
|
|
155
|
+
},
|
|
156
|
+
trys: [],
|
|
157
|
+
ops: []
|
|
158
|
+
};
|
|
159
|
+
return g = {
|
|
160
|
+
next: verb(0),
|
|
161
|
+
"throw": verb(1),
|
|
162
|
+
"return": verb(2)
|
|
163
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
164
|
+
return this;
|
|
165
|
+
}), g;
|
|
166
|
+
function verb(n) {
|
|
167
|
+
return function(v) {
|
|
168
|
+
return step([
|
|
169
|
+
n,
|
|
170
|
+
v
|
|
171
|
+
]);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function step(op) {
|
|
175
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
176
|
+
while(_)try {
|
|
177
|
+
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;
|
|
178
|
+
if (y = 0, t) op = [
|
|
179
|
+
op[0] & 2,
|
|
180
|
+
t.value
|
|
181
|
+
];
|
|
182
|
+
switch(op[0]){
|
|
183
|
+
case 0:
|
|
184
|
+
case 1:
|
|
185
|
+
t = op;
|
|
186
|
+
break;
|
|
187
|
+
case 4:
|
|
188
|
+
_.label++;
|
|
189
|
+
return {
|
|
190
|
+
value: op[1],
|
|
191
|
+
done: false
|
|
192
|
+
};
|
|
193
|
+
case 5:
|
|
194
|
+
_.label++;
|
|
195
|
+
y = op[1];
|
|
196
|
+
op = [
|
|
197
|
+
0
|
|
198
|
+
];
|
|
199
|
+
continue;
|
|
200
|
+
case 7:
|
|
201
|
+
op = _.ops.pop();
|
|
202
|
+
_.trys.pop();
|
|
203
|
+
continue;
|
|
204
|
+
default:
|
|
205
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
206
|
+
_ = 0;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
210
|
+
_.label = op[1];
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
214
|
+
_.label = t[1];
|
|
215
|
+
t = op;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
if (t && _.label < t[2]) {
|
|
219
|
+
_.label = t[2];
|
|
220
|
+
_.ops.push(op);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
if (t[2]) _.ops.pop();
|
|
224
|
+
_.trys.pop();
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
op = body.call(thisArg, _);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
op = [
|
|
230
|
+
6,
|
|
231
|
+
e
|
|
232
|
+
];
|
|
233
|
+
y = 0;
|
|
234
|
+
} finally{
|
|
235
|
+
f = t = 0;
|
|
236
|
+
}
|
|
237
|
+
if (op[0] & 5) throw op[1];
|
|
238
|
+
return {
|
|
239
|
+
value: op[0] ? op[1] : void 0,
|
|
240
|
+
done: true
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
import { pick } from "radash";
|
|
245
|
+
var serializeRunStep = function(param) {
|
|
246
|
+
var runStep = param.runStep;
|
|
247
|
+
return pick(runStep, [
|
|
248
|
+
"id",
|
|
249
|
+
"run_id",
|
|
250
|
+
"step_details",
|
|
251
|
+
"completed_at",
|
|
252
|
+
"cancelled_at",
|
|
253
|
+
"failed_at",
|
|
254
|
+
"status"
|
|
255
|
+
]);
|
|
256
|
+
};
|
|
257
|
+
// src/lib/messages/serializeMessage.ts
|
|
258
|
+
var serializeMessage = function(param) {
|
|
259
|
+
var message = param.message;
|
|
260
|
+
var _message_runSteps;
|
|
261
|
+
return {
|
|
262
|
+
id: message.id,
|
|
263
|
+
role: message.role,
|
|
264
|
+
created_at: message.created_at,
|
|
265
|
+
content: message.content,
|
|
266
|
+
run_id: message.run_id,
|
|
267
|
+
assistant_id: message.assistant_id,
|
|
268
|
+
thread_id: message.thread_id,
|
|
269
|
+
file_ids: message.file_ids,
|
|
270
|
+
metadata: message.metadata,
|
|
271
|
+
runSteps: ((_message_runSteps = message.runSteps) !== null && _message_runSteps !== void 0 ? _message_runSteps : []).map(function(runStep) {
|
|
272
|
+
return serializeRunStep({
|
|
273
|
+
runStep: runStep
|
|
274
|
+
});
|
|
275
|
+
}),
|
|
276
|
+
status: message.status
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
// src/lib/messages/messagesResponse/data/messages/index.ts
|
|
280
|
+
import pMap from "p-map";
|
|
281
|
+
// src/lib/runSteps/getRunSteps/index.ts
|
|
282
|
+
var getRunSteps = function() {
|
|
283
|
+
var _ref = _async_to_generator(function(param) {
|
|
284
|
+
var threadId, runId, client, runStepsResponse;
|
|
285
|
+
return _ts_generator(this, function(_state) {
|
|
286
|
+
switch(_state.label){
|
|
287
|
+
case 0:
|
|
288
|
+
threadId = param.threadId, runId = param.runId, client = param.client;
|
|
289
|
+
return [
|
|
290
|
+
4,
|
|
291
|
+
client.beta.threads.runs.steps.list(threadId, runId)
|
|
292
|
+
];
|
|
293
|
+
case 1:
|
|
294
|
+
runStepsResponse = _state.sent();
|
|
295
|
+
return [
|
|
296
|
+
2,
|
|
297
|
+
runStepsResponse.data
|
|
298
|
+
];
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
return function getRunSteps(_) {
|
|
303
|
+
return _ref.apply(this, arguments);
|
|
304
|
+
};
|
|
305
|
+
}();
|
|
306
|
+
// src/lib/messages/extendMessage.ts
|
|
307
|
+
var extendMessage = function() {
|
|
308
|
+
var _ref = _async_to_generator(function(param) {
|
|
309
|
+
var message, client, _tmp, _tmp1;
|
|
310
|
+
return _ts_generator(this, function(_state) {
|
|
311
|
+
switch(_state.label){
|
|
312
|
+
case 0:
|
|
313
|
+
message = param.message, client = param.client;
|
|
314
|
+
if (!message.run_id) {
|
|
315
|
+
return [
|
|
316
|
+
2,
|
|
317
|
+
_object_spread_props(_object_spread({}, message), {
|
|
318
|
+
runSteps: []
|
|
319
|
+
})
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
_tmp = [
|
|
323
|
+
_object_spread({}, message)
|
|
324
|
+
];
|
|
325
|
+
_tmp1 = {};
|
|
326
|
+
return [
|
|
327
|
+
4,
|
|
328
|
+
getRunSteps({
|
|
329
|
+
threadId: message.thread_id,
|
|
330
|
+
runId: message.run_id,
|
|
331
|
+
client: client
|
|
332
|
+
})
|
|
333
|
+
];
|
|
334
|
+
case 1:
|
|
335
|
+
return [
|
|
336
|
+
2,
|
|
337
|
+
_object_spread_props.apply(void 0, _tmp.concat([
|
|
338
|
+
(_tmp1.runSteps = _state.sent(), _tmp1)
|
|
339
|
+
]))
|
|
340
|
+
];
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
return function extendMessage(_) {
|
|
345
|
+
return _ref.apply(this, arguments);
|
|
346
|
+
};
|
|
347
|
+
}();
|
|
348
|
+
// src/lib/messages/messagesResponse/data/messages/runMessages/index.ts
|
|
349
|
+
import dayjs from "dayjs";
|
|
350
|
+
// src/lib/messages/messagesResponse/data/messages/runMessages/getLatestRun.ts
|
|
351
|
+
var getLatestRun = function() {
|
|
352
|
+
var _ref = _async_to_generator(function(param) {
|
|
353
|
+
var threadId, client, runsResponse;
|
|
354
|
+
return _ts_generator(this, function(_state) {
|
|
355
|
+
switch(_state.label){
|
|
356
|
+
case 0:
|
|
357
|
+
threadId = param.threadId, client = param.client;
|
|
358
|
+
return [
|
|
359
|
+
4,
|
|
360
|
+
client.beta.threads.runs.list(threadId, {
|
|
361
|
+
limit: 1
|
|
362
|
+
})
|
|
363
|
+
];
|
|
364
|
+
case 1:
|
|
365
|
+
runsResponse = _state.sent();
|
|
366
|
+
return [
|
|
367
|
+
2,
|
|
368
|
+
runsResponse.data[0]
|
|
369
|
+
];
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
return function getLatestRun(_) {
|
|
374
|
+
return _ref.apply(this, arguments);
|
|
375
|
+
};
|
|
376
|
+
}();
|
|
377
|
+
// src/lib/optimistic/optimisticId.ts
|
|
378
|
+
import { uid } from "radash";
|
|
379
|
+
var optimisticId = function() {
|
|
380
|
+
return "-".concat(uid(24));
|
|
381
|
+
};
|
|
382
|
+
// src/lib/messages/messagesResponse/data/messages/runMessages/index.ts
|
|
383
|
+
var progressStatuses = [
|
|
384
|
+
"queued",
|
|
385
|
+
"in_progress",
|
|
386
|
+
"requires_action",
|
|
387
|
+
"cancelling"
|
|
388
|
+
];
|
|
389
|
+
var runMessages = function() {
|
|
390
|
+
var _ref = _async_to_generator(function(param) {
|
|
391
|
+
var result, threadId, client, latestRun, messageFromLatestRun;
|
|
392
|
+
return _ts_generator(this, function(_state) {
|
|
393
|
+
switch(_state.label){
|
|
394
|
+
case 0:
|
|
395
|
+
result = param.result, threadId = param.threadId, client = param.client;
|
|
396
|
+
return [
|
|
397
|
+
4,
|
|
398
|
+
getLatestRun({
|
|
399
|
+
threadId: threadId,
|
|
400
|
+
client: client
|
|
401
|
+
})
|
|
402
|
+
];
|
|
403
|
+
case 1:
|
|
404
|
+
latestRun = _state.sent();
|
|
405
|
+
if (!latestRun) {
|
|
406
|
+
return [
|
|
407
|
+
2,
|
|
408
|
+
[]
|
|
409
|
+
];
|
|
410
|
+
}
|
|
411
|
+
messageFromLatestRun = result.find(function(m) {
|
|
412
|
+
return m.run_id === latestRun.id;
|
|
413
|
+
});
|
|
414
|
+
if (messageFromLatestRun) {
|
|
415
|
+
return [
|
|
416
|
+
2,
|
|
417
|
+
[]
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
if (!progressStatuses.includes(latestRun.status)) {
|
|
421
|
+
return [
|
|
422
|
+
2,
|
|
423
|
+
[]
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
return [
|
|
427
|
+
4,
|
|
428
|
+
extendMessage({
|
|
429
|
+
message: {
|
|
430
|
+
id: optimisticId(),
|
|
431
|
+
role: "assistant",
|
|
432
|
+
created_at: dayjs().unix(),
|
|
433
|
+
object: "thread.message",
|
|
434
|
+
incomplete_details: null,
|
|
435
|
+
completed_at: dayjs().unix(),
|
|
436
|
+
incomplete_at: null,
|
|
437
|
+
status: "completed",
|
|
438
|
+
content: [],
|
|
439
|
+
run_id: latestRun.id,
|
|
440
|
+
assistant_id: latestRun.assistant_id,
|
|
441
|
+
thread_id: latestRun.thread_id,
|
|
442
|
+
file_ids: [],
|
|
443
|
+
metadata: {}
|
|
444
|
+
},
|
|
445
|
+
client: client
|
|
446
|
+
})
|
|
447
|
+
];
|
|
448
|
+
case 2:
|
|
449
|
+
return [
|
|
450
|
+
2,
|
|
451
|
+
[
|
|
452
|
+
_state.sent()
|
|
453
|
+
]
|
|
454
|
+
];
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
return function runMessages(_) {
|
|
459
|
+
return _ref.apply(this, arguments);
|
|
460
|
+
};
|
|
461
|
+
}();
|
|
462
|
+
// src/lib/messages/messagesResponse/data/messages/index.ts
|
|
463
|
+
var messages = function() {
|
|
464
|
+
var _ref = _async_to_generator(function(param) {
|
|
465
|
+
var messagesResponse2, pageParam, threadId, client, result;
|
|
466
|
+
return _ts_generator(this, function(_state) {
|
|
467
|
+
switch(_state.label){
|
|
468
|
+
case 0:
|
|
469
|
+
messagesResponse2 = param.messagesResponse, pageParam = param.pageParam, threadId = param.threadId, client = param.client;
|
|
470
|
+
return [
|
|
471
|
+
4,
|
|
472
|
+
pMap(messagesResponse2.data, function(message) {
|
|
473
|
+
return extendMessage({
|
|
474
|
+
client: client,
|
|
475
|
+
message: message
|
|
476
|
+
});
|
|
477
|
+
})
|
|
478
|
+
];
|
|
479
|
+
case 1:
|
|
480
|
+
result = _state.sent();
|
|
481
|
+
if (pageParam) {
|
|
482
|
+
return [
|
|
483
|
+
2,
|
|
484
|
+
result
|
|
485
|
+
];
|
|
486
|
+
}
|
|
487
|
+
return [
|
|
488
|
+
4,
|
|
489
|
+
runMessages({
|
|
490
|
+
result: result,
|
|
491
|
+
threadId: threadId,
|
|
492
|
+
client: client
|
|
493
|
+
})
|
|
494
|
+
];
|
|
495
|
+
case 2:
|
|
496
|
+
return [
|
|
497
|
+
2,
|
|
498
|
+
_to_consumable_array.apply(void 0, [
|
|
499
|
+
_state.sent()
|
|
500
|
+
]).concat(_to_consumable_array(result))
|
|
501
|
+
];
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
return function messages(_) {
|
|
506
|
+
return _ref.apply(this, arguments);
|
|
507
|
+
};
|
|
508
|
+
}();
|
|
509
|
+
// src/lib/messages/messagesResponse/data/index.ts
|
|
510
|
+
var data = function() {
|
|
511
|
+
var _ref = _async_to_generator(function(param) {
|
|
512
|
+
var messagesResponse2, pageParam, threadId, client;
|
|
513
|
+
return _ts_generator(this, function(_state) {
|
|
514
|
+
switch(_state.label){
|
|
515
|
+
case 0:
|
|
516
|
+
messagesResponse2 = param.messagesResponse, pageParam = param.pageParam, threadId = param.threadId, client = param.client;
|
|
517
|
+
return [
|
|
518
|
+
4,
|
|
519
|
+
messages({
|
|
520
|
+
messagesResponse: messagesResponse2,
|
|
521
|
+
pageParam: pageParam,
|
|
522
|
+
threadId: threadId,
|
|
523
|
+
client: client
|
|
524
|
+
})
|
|
525
|
+
];
|
|
526
|
+
case 1:
|
|
527
|
+
return [
|
|
528
|
+
2,
|
|
529
|
+
_state.sent().map(function(message) {
|
|
530
|
+
return serializeMessage({
|
|
531
|
+
message: message
|
|
532
|
+
});
|
|
533
|
+
})
|
|
534
|
+
];
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
return function data(_) {
|
|
539
|
+
return _ref.apply(this, arguments);
|
|
540
|
+
};
|
|
541
|
+
}();
|
|
542
|
+
// src/lib/messages/messagesResponse/limit.ts
|
|
543
|
+
var limit = 10;
|
|
544
|
+
// src/lib/messages/messagesResponse/hasNextPage.ts
|
|
545
|
+
var hasNextPage = function(param) {
|
|
546
|
+
var messagesResponse2 = param.messagesResponse;
|
|
547
|
+
if (messagesResponse2.data.length < limit) return false;
|
|
548
|
+
return messagesResponse2.hasNextPage();
|
|
549
|
+
};
|
|
550
|
+
// src/lib/messages/messagesResponse/index.ts
|
|
551
|
+
var messagesResponse = function() {
|
|
552
|
+
var _ref = _async_to_generator(function(param) {
|
|
553
|
+
var client, threadId, pageParam, messagesResponse2, _tmp;
|
|
554
|
+
return _ts_generator(this, function(_state) {
|
|
555
|
+
switch(_state.label){
|
|
556
|
+
case 0:
|
|
557
|
+
client = param.client, threadId = param.threadId, pageParam = param.pageParam;
|
|
558
|
+
return [
|
|
559
|
+
4,
|
|
560
|
+
client.beta.threads.messages.list(threadId, _object_spread_props(_object_spread({}, pageParam ? {
|
|
561
|
+
after: pageParam
|
|
562
|
+
} : {}), {
|
|
563
|
+
limit: limit
|
|
564
|
+
}))
|
|
565
|
+
];
|
|
566
|
+
case 1:
|
|
567
|
+
messagesResponse2 = _state.sent();
|
|
568
|
+
_tmp = {};
|
|
569
|
+
return [
|
|
570
|
+
4,
|
|
571
|
+
data({
|
|
572
|
+
client: client,
|
|
573
|
+
messagesResponse: messagesResponse2,
|
|
574
|
+
pageParam: pageParam,
|
|
575
|
+
threadId: threadId
|
|
576
|
+
})
|
|
577
|
+
];
|
|
578
|
+
case 2:
|
|
579
|
+
return [
|
|
580
|
+
2,
|
|
581
|
+
(_tmp.data = _state.sent(), _tmp.hasNextPage = hasNextPage({
|
|
582
|
+
messagesResponse: messagesResponse2
|
|
583
|
+
}), _tmp.// @ts-ignore-next-line
|
|
584
|
+
lastId = messagesResponse2.body.last_id, _tmp)
|
|
585
|
+
];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
return function messagesResponse(_) {
|
|
590
|
+
return _ref.apply(this, arguments);
|
|
591
|
+
};
|
|
592
|
+
}();
|
|
593
|
+
// src/lib/runs/serializeRun.ts
|
|
594
|
+
import { pick as pick2 } from "radash";
|
|
595
|
+
var serializeRun = function(param) {
|
|
596
|
+
var run = param.run;
|
|
597
|
+
return pick2(run, [
|
|
598
|
+
"id",
|
|
599
|
+
"thread_id",
|
|
600
|
+
"assistant_id",
|
|
601
|
+
"created_at"
|
|
602
|
+
]);
|
|
603
|
+
};
|
|
604
|
+
// src/lib/messages/createMessageResponse/actionsStream.ts
|
|
605
|
+
import pMap2 from "p-map";
|
|
606
|
+
var actionsStream = function() {
|
|
607
|
+
var _ref = _async_to_generator(function(param) {
|
|
608
|
+
var client, run, handleToolCall, toolCalls, _, _1, _tmp, _tmp1;
|
|
609
|
+
return _ts_generator(this, function(_state) {
|
|
610
|
+
switch(_state.label){
|
|
611
|
+
case 0:
|
|
612
|
+
client = param.client, run = param.run, handleToolCall = param.handleToolCall;
|
|
613
|
+
if (!run.required_action) {
|
|
614
|
+
throw new Error("Run does not have a required action");
|
|
615
|
+
}
|
|
616
|
+
toolCalls = run.required_action.submit_tool_outputs.tool_calls;
|
|
617
|
+
_1 = (_ = client.beta.threads.runs).submitToolOutputsStream;
|
|
618
|
+
_tmp = [
|
|
619
|
+
run.thread_id,
|
|
620
|
+
run.id
|
|
621
|
+
];
|
|
622
|
+
_tmp1 = {};
|
|
623
|
+
return [
|
|
624
|
+
4,
|
|
625
|
+
pMap2(toolCalls, function(toolCall) {
|
|
626
|
+
return handleToolCall({
|
|
627
|
+
toolCall: toolCall,
|
|
628
|
+
run: run
|
|
629
|
+
});
|
|
630
|
+
})
|
|
631
|
+
];
|
|
632
|
+
case 1:
|
|
633
|
+
return [
|
|
634
|
+
2,
|
|
635
|
+
_1.apply(_, _tmp.concat([
|
|
636
|
+
(_tmp1.tool_outputs = _state.sent(), _tmp1)
|
|
637
|
+
]))
|
|
638
|
+
];
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
return function actionsStream(_) {
|
|
643
|
+
return _ref.apply(this, arguments);
|
|
644
|
+
};
|
|
645
|
+
}();
|
|
646
|
+
// src/lib/messages/createMessageResponse/handleStream.ts
|
|
647
|
+
var handleStream = function() {
|
|
648
|
+
var _ref = _async_to_generator(function(param) {
|
|
649
|
+
var client, stream, controller, handleToolCall, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, value, _tmp, err;
|
|
650
|
+
return _ts_generator(this, function(_state) {
|
|
651
|
+
switch(_state.label){
|
|
652
|
+
case 0:
|
|
653
|
+
client = param.client, stream = param.stream, controller = param.controller, handleToolCall = param.handleToolCall;
|
|
654
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
655
|
+
_state.label = 1;
|
|
656
|
+
case 1:
|
|
657
|
+
_state.trys.push([
|
|
658
|
+
1,
|
|
659
|
+
13,
|
|
660
|
+
14,
|
|
661
|
+
19
|
|
662
|
+
]);
|
|
663
|
+
_iterator = _async_iterator(stream);
|
|
664
|
+
_state.label = 2;
|
|
665
|
+
case 2:
|
|
666
|
+
return [
|
|
667
|
+
4,
|
|
668
|
+
_iterator.next()
|
|
669
|
+
];
|
|
670
|
+
case 3:
|
|
671
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
672
|
+
3,
|
|
673
|
+
12
|
|
674
|
+
];
|
|
675
|
+
_value = _step.value;
|
|
676
|
+
value = _value;
|
|
677
|
+
if (![
|
|
678
|
+
"thread.message.created",
|
|
679
|
+
"thread.message.completed"
|
|
680
|
+
].includes(value.event)) return [
|
|
681
|
+
3,
|
|
682
|
+
4
|
|
683
|
+
];
|
|
684
|
+
controller.enqueue(JSON.stringify({
|
|
685
|
+
event: value.event,
|
|
686
|
+
data: serializeMessage({
|
|
687
|
+
message: value.data
|
|
688
|
+
})
|
|
689
|
+
}));
|
|
690
|
+
return [
|
|
691
|
+
3,
|
|
692
|
+
11
|
|
693
|
+
];
|
|
694
|
+
case 4:
|
|
695
|
+
if (![
|
|
696
|
+
"thread.message.delta",
|
|
697
|
+
"thread.run.step.delta"
|
|
698
|
+
].includes(value.event)) return [
|
|
699
|
+
3,
|
|
700
|
+
5
|
|
701
|
+
];
|
|
702
|
+
controller.enqueue(JSON.stringify(value));
|
|
703
|
+
return [
|
|
704
|
+
3,
|
|
705
|
+
11
|
|
706
|
+
];
|
|
707
|
+
case 5:
|
|
708
|
+
if (!(value.event === "thread.run.created")) return [
|
|
709
|
+
3,
|
|
710
|
+
6
|
|
711
|
+
];
|
|
712
|
+
controller.enqueue(JSON.stringify({
|
|
713
|
+
event: value.event,
|
|
714
|
+
data: serializeRun({
|
|
715
|
+
run: value.data
|
|
716
|
+
})
|
|
717
|
+
}));
|
|
718
|
+
return [
|
|
719
|
+
3,
|
|
720
|
+
11
|
|
721
|
+
];
|
|
722
|
+
case 6:
|
|
723
|
+
if (![
|
|
724
|
+
"thread.run.step.created",
|
|
725
|
+
"thread.run.step.completed"
|
|
726
|
+
].includes(value.event)) return [
|
|
727
|
+
3,
|
|
728
|
+
7
|
|
729
|
+
];
|
|
730
|
+
controller.enqueue(JSON.stringify({
|
|
731
|
+
event: value.event,
|
|
732
|
+
data: serializeRunStep({
|
|
733
|
+
runStep: value.data
|
|
734
|
+
})
|
|
735
|
+
}));
|
|
736
|
+
return [
|
|
737
|
+
3,
|
|
738
|
+
11
|
|
739
|
+
];
|
|
740
|
+
case 7:
|
|
741
|
+
if (!(value.event === "thread.run.requires_action")) return [
|
|
742
|
+
3,
|
|
743
|
+
10
|
|
744
|
+
];
|
|
745
|
+
controller.enqueue(JSON.stringify(value));
|
|
746
|
+
console.log("starting to handle in handleStream");
|
|
747
|
+
console.dir({
|
|
748
|
+
value: value
|
|
749
|
+
}, {
|
|
750
|
+
depth: null
|
|
751
|
+
});
|
|
752
|
+
_tmp = {
|
|
753
|
+
client: client
|
|
754
|
+
};
|
|
755
|
+
return [
|
|
756
|
+
4,
|
|
757
|
+
actionsStream({
|
|
758
|
+
client: client,
|
|
759
|
+
run: value.data,
|
|
760
|
+
handleToolCall: handleToolCall
|
|
761
|
+
})
|
|
762
|
+
];
|
|
763
|
+
case 8:
|
|
764
|
+
return [
|
|
765
|
+
4,
|
|
766
|
+
handleStream.apply(void 0, [
|
|
767
|
+
(_tmp.stream = _state.sent(), _tmp.controller = controller, _tmp.handleToolCall = handleToolCall, _tmp)
|
|
768
|
+
])
|
|
769
|
+
];
|
|
770
|
+
case 9:
|
|
771
|
+
_state.sent();
|
|
772
|
+
return [
|
|
773
|
+
3,
|
|
774
|
+
11
|
|
775
|
+
];
|
|
776
|
+
case 10:
|
|
777
|
+
console.dir({
|
|
778
|
+
value: value
|
|
779
|
+
}, {
|
|
780
|
+
depth: null
|
|
781
|
+
});
|
|
782
|
+
_state.label = 11;
|
|
783
|
+
case 11:
|
|
784
|
+
_iteratorAbruptCompletion = false;
|
|
785
|
+
return [
|
|
786
|
+
3,
|
|
787
|
+
2
|
|
788
|
+
];
|
|
789
|
+
case 12:
|
|
790
|
+
return [
|
|
791
|
+
3,
|
|
792
|
+
19
|
|
793
|
+
];
|
|
794
|
+
case 13:
|
|
795
|
+
err = _state.sent();
|
|
796
|
+
_didIteratorError = true;
|
|
797
|
+
_iteratorError = err;
|
|
798
|
+
return [
|
|
799
|
+
3,
|
|
800
|
+
19
|
|
801
|
+
];
|
|
802
|
+
case 14:
|
|
803
|
+
_state.trys.push([
|
|
804
|
+
14,
|
|
805
|
+
,
|
|
806
|
+
17,
|
|
807
|
+
18
|
|
808
|
+
]);
|
|
809
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
810
|
+
3,
|
|
811
|
+
16
|
|
812
|
+
];
|
|
813
|
+
return [
|
|
814
|
+
4,
|
|
815
|
+
_iterator.return()
|
|
816
|
+
];
|
|
817
|
+
case 15:
|
|
818
|
+
_state.sent();
|
|
819
|
+
_state.label = 16;
|
|
820
|
+
case 16:
|
|
821
|
+
return [
|
|
822
|
+
3,
|
|
823
|
+
18
|
|
824
|
+
];
|
|
825
|
+
case 17:
|
|
826
|
+
if (_didIteratorError) {
|
|
827
|
+
throw _iteratorError;
|
|
828
|
+
}
|
|
829
|
+
return [
|
|
830
|
+
7
|
|
831
|
+
];
|
|
832
|
+
case 18:
|
|
833
|
+
return [
|
|
834
|
+
7
|
|
835
|
+
];
|
|
836
|
+
case 19:
|
|
837
|
+
return [
|
|
838
|
+
2
|
|
839
|
+
];
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
});
|
|
843
|
+
return function handleStream(_) {
|
|
844
|
+
return _ref.apply(this, arguments);
|
|
845
|
+
};
|
|
846
|
+
}();
|
|
847
|
+
// src/lib/messages/createMessageResponse/index.ts
|
|
848
|
+
var createMessageResponse = function(param) {
|
|
849
|
+
var client = param.client, createRunStream = param.createRunStream, handleToolCall = param.handleToolCall;
|
|
850
|
+
return new ReadableStream({
|
|
851
|
+
start: function start(controller) {
|
|
852
|
+
return _async_to_generator(function() {
|
|
853
|
+
return _ts_generator(this, function(_state) {
|
|
854
|
+
switch(_state.label){
|
|
855
|
+
case 0:
|
|
856
|
+
return [
|
|
857
|
+
4,
|
|
858
|
+
handleStream({
|
|
859
|
+
client: client,
|
|
860
|
+
stream: createRunStream,
|
|
861
|
+
controller: controller,
|
|
862
|
+
handleToolCall: handleToolCall
|
|
863
|
+
})
|
|
864
|
+
];
|
|
865
|
+
case 1:
|
|
866
|
+
_state.sent();
|
|
867
|
+
console.log("Stream ended");
|
|
868
|
+
controller.close();
|
|
869
|
+
return [
|
|
870
|
+
2
|
|
871
|
+
];
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
})();
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
};
|
|
878
|
+
export { createMessageResponse, extendMessage, messagesResponse };
|
|
879
|
+
//# sourceMappingURL=server.js.map
|