@superinterface/react 1.1.7 → 2.0.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-CGpJFXMu.d.ts +5 -0
- package/dist/index.cjs +3383 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1220 -0
- package/dist/index.d.ts +852 -211
- package/dist/index.js +3117 -1945
- package/dist/index.js.map +1 -1
- package/dist/mutationFns.cjs +517 -0
- package/dist/mutationFns.cjs.map +1 -0
- package/dist/mutationFns.d.cts +35 -0
- package/dist/mutationFns.d.ts +13 -13
- package/dist/mutationFns.js +434 -159
- package/dist/mutationFns.js.map +1 -1
- package/dist/queryFns.cjs +578 -0
- package/dist/queryFns.cjs.map +1 -0
- package/dist/queryFns.d.cts +18 -0
- package/dist/queryFns.d.ts +5 -5
- package/dist/queryFns.js +495 -200
- package/dist/queryFns.js.map +1 -1
- package/dist/types/index.cjs +45 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +37 -0
- package/dist/types/index.d.ts +10 -6
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +1 -1
- package/dist/utils.cjs +312 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +23 -0
- package/dist/utils.d.ts +3 -4
- package/dist/utils.js +246 -73
- package/dist/utils.js.map +1 -1
- package/package.json +29 -21
- /package/dist/{index-LPUEY9WE.d.ts → index-CGpJFXMu.d.cts} +0 -0
package/dist/queryFns.js
CHANGED
|
@@ -1,209 +1,504 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/queryFns.ts
|
|
31
|
-
var queryFns_exports = {};
|
|
32
|
-
__export(queryFns_exports, {
|
|
33
|
-
messagesQueryFn: () => queryFn,
|
|
34
|
-
runsQueryFn: () => queryFn2
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(queryFns_exports);
|
|
37
|
-
|
|
38
1
|
// src/lib/ai/index.ts
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 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 _define_property(obj, key, value) {
|
|
40
|
+
if (key in obj) {
|
|
41
|
+
Object.defineProperty(obj, key, {
|
|
42
|
+
value: value,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
obj[key] = value;
|
|
49
|
+
}
|
|
50
|
+
return obj;
|
|
51
|
+
}
|
|
52
|
+
function _iterable_to_array(iter) {
|
|
53
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
54
|
+
}
|
|
55
|
+
function _non_iterable_spread() {
|
|
56
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
57
|
+
}
|
|
58
|
+
function _object_spread(target) {
|
|
59
|
+
for(var i = 1; i < arguments.length; i++){
|
|
60
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
61
|
+
var ownKeys = Object.keys(source);
|
|
62
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
63
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
ownKeys.forEach(function(key) {
|
|
68
|
+
_define_property(target, key, source[key]);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return target;
|
|
72
|
+
}
|
|
73
|
+
function ownKeys(object, enumerableOnly) {
|
|
74
|
+
var keys = Object.keys(object);
|
|
75
|
+
if (Object.getOwnPropertySymbols) {
|
|
76
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
77
|
+
if (enumerableOnly) {
|
|
78
|
+
symbols = symbols.filter(function(sym) {
|
|
79
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
keys.push.apply(keys, symbols);
|
|
83
|
+
}
|
|
84
|
+
return keys;
|
|
85
|
+
}
|
|
86
|
+
function _object_spread_props(target, source) {
|
|
87
|
+
source = source != null ? source : {};
|
|
88
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
89
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
90
|
+
} else {
|
|
91
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
92
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return target;
|
|
96
|
+
}
|
|
97
|
+
function _to_consumable_array(arr) {
|
|
98
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
99
|
+
}
|
|
100
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
101
|
+
if (!o) return;
|
|
102
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
103
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
104
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
105
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
106
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
107
|
+
}
|
|
108
|
+
function _ts_generator(thisArg, body) {
|
|
109
|
+
var f, y, t, g, _ = {
|
|
110
|
+
label: 0,
|
|
111
|
+
sent: function() {
|
|
112
|
+
if (t[0] & 1) throw t[1];
|
|
113
|
+
return t[1];
|
|
114
|
+
},
|
|
115
|
+
trys: [],
|
|
116
|
+
ops: []
|
|
117
|
+
};
|
|
118
|
+
return g = {
|
|
119
|
+
next: verb(0),
|
|
120
|
+
"throw": verb(1),
|
|
121
|
+
"return": verb(2)
|
|
122
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
123
|
+
return this;
|
|
124
|
+
}), g;
|
|
125
|
+
function verb(n) {
|
|
126
|
+
return function(v) {
|
|
127
|
+
return step([
|
|
128
|
+
n,
|
|
129
|
+
v
|
|
130
|
+
]);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function step(op) {
|
|
134
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
135
|
+
while(_)try {
|
|
136
|
+
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;
|
|
137
|
+
if (y = 0, t) op = [
|
|
138
|
+
op[0] & 2,
|
|
139
|
+
t.value
|
|
140
|
+
];
|
|
141
|
+
switch(op[0]){
|
|
142
|
+
case 0:
|
|
143
|
+
case 1:
|
|
144
|
+
t = op;
|
|
145
|
+
break;
|
|
146
|
+
case 4:
|
|
147
|
+
_.label++;
|
|
148
|
+
return {
|
|
149
|
+
value: op[1],
|
|
150
|
+
done: false
|
|
151
|
+
};
|
|
152
|
+
case 5:
|
|
153
|
+
_.label++;
|
|
154
|
+
y = op[1];
|
|
155
|
+
op = [
|
|
156
|
+
0
|
|
157
|
+
];
|
|
158
|
+
continue;
|
|
159
|
+
case 7:
|
|
160
|
+
op = _.ops.pop();
|
|
161
|
+
_.trys.pop();
|
|
162
|
+
continue;
|
|
163
|
+
default:
|
|
164
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
165
|
+
_ = 0;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
169
|
+
_.label = op[1];
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
173
|
+
_.label = t[1];
|
|
174
|
+
t = op;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (t && _.label < t[2]) {
|
|
178
|
+
_.label = t[2];
|
|
179
|
+
_.ops.push(op);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
if (t[2]) _.ops.pop();
|
|
183
|
+
_.trys.pop();
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
op = body.call(thisArg, _);
|
|
187
|
+
} catch (e) {
|
|
188
|
+
op = [
|
|
189
|
+
6,
|
|
190
|
+
e
|
|
191
|
+
];
|
|
192
|
+
y = 0;
|
|
193
|
+
} finally{
|
|
194
|
+
f = t = 0;
|
|
195
|
+
}
|
|
196
|
+
if (op[0] & 5) throw op[1];
|
|
197
|
+
return {
|
|
198
|
+
value: op[0] ? op[1] : void 0,
|
|
199
|
+
done: true
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
import OpenAI from "openai";
|
|
204
|
+
var defaultClient = new OpenAI({
|
|
205
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
42
206
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var import_p_map = __toESM(require("p-map"));
|
|
46
|
-
|
|
207
|
+
// src/lib/threadMessages/threadMessagesQueryFn/data/index.ts
|
|
208
|
+
import pMap from "p-map";
|
|
47
209
|
// src/lib/runSteps/getRunSteps/index.ts
|
|
48
|
-
var getRunSteps =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
210
|
+
var getRunSteps = function() {
|
|
211
|
+
var _ref = _async_to_generator(function(param) {
|
|
212
|
+
var threadId, runId, client, runStepsResponse;
|
|
213
|
+
return _ts_generator(this, function(_state) {
|
|
214
|
+
switch(_state.label){
|
|
215
|
+
case 0:
|
|
216
|
+
threadId = param.threadId, runId = param.runId, client = param.client;
|
|
217
|
+
return [
|
|
218
|
+
4,
|
|
219
|
+
client.beta.threads.runs.steps.list(threadId, runId)
|
|
220
|
+
];
|
|
221
|
+
case 1:
|
|
222
|
+
runStepsResponse = _state.sent();
|
|
223
|
+
return [
|
|
224
|
+
2,
|
|
225
|
+
runStepsResponse.data
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
return function getRunSteps(_) {
|
|
231
|
+
return _ref.apply(this, arguments);
|
|
69
232
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
|
|
233
|
+
}();
|
|
234
|
+
// src/lib/threadMessages/extendThreadMessage.ts
|
|
235
|
+
var extendThreadMessage = function() {
|
|
236
|
+
var _ref = _async_to_generator(function(param) {
|
|
237
|
+
var threadMessage, client, _tmp, _tmp1;
|
|
238
|
+
return _ts_generator(this, function(_state) {
|
|
239
|
+
switch(_state.label){
|
|
240
|
+
case 0:
|
|
241
|
+
threadMessage = param.threadMessage, client = param.client;
|
|
242
|
+
if (!threadMessage.run_id) {
|
|
243
|
+
return [
|
|
244
|
+
2,
|
|
245
|
+
_object_spread_props(_object_spread({}, threadMessage), {
|
|
246
|
+
runSteps: []
|
|
247
|
+
})
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
_tmp = [
|
|
251
|
+
_object_spread({}, threadMessage)
|
|
252
|
+
];
|
|
253
|
+
_tmp1 = {};
|
|
254
|
+
return [
|
|
255
|
+
4,
|
|
256
|
+
getRunSteps({
|
|
257
|
+
threadId: threadMessage.thread_id,
|
|
258
|
+
runId: threadMessage.run_id,
|
|
259
|
+
client: client
|
|
260
|
+
})
|
|
261
|
+
];
|
|
262
|
+
case 1:
|
|
263
|
+
return [
|
|
264
|
+
2,
|
|
265
|
+
_object_spread_props.apply(void 0, _tmp.concat([
|
|
266
|
+
(_tmp1.runSteps = _state.sent(), _tmp1)
|
|
267
|
+
]))
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
return function extendThreadMessage(_) {
|
|
273
|
+
return _ref.apply(this, arguments);
|
|
274
|
+
};
|
|
275
|
+
}();
|
|
276
|
+
// src/lib/threadMessages/threadMessagesQueryFn/data/runThreadMessages/getLatestRun.ts
|
|
277
|
+
var getLatestRun = function() {
|
|
278
|
+
var _ref = _async_to_generator(function(param) {
|
|
279
|
+
var threadId, client, runsResponse;
|
|
280
|
+
return _ts_generator(this, function(_state) {
|
|
281
|
+
switch(_state.label){
|
|
282
|
+
case 0:
|
|
283
|
+
threadId = param.threadId, client = param.client;
|
|
284
|
+
return [
|
|
285
|
+
4,
|
|
286
|
+
client.beta.threads.runs.list(threadId, {
|
|
287
|
+
limit: 1
|
|
288
|
+
})
|
|
289
|
+
];
|
|
290
|
+
case 1:
|
|
291
|
+
runsResponse = _state.sent();
|
|
292
|
+
return [
|
|
293
|
+
2,
|
|
294
|
+
runsResponse.data[0]
|
|
295
|
+
];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
return function getLatestRun(_) {
|
|
300
|
+
return _ref.apply(this, arguments);
|
|
301
|
+
};
|
|
302
|
+
}();
|
|
92
303
|
// src/lib/optimistic/optimisticId.ts
|
|
93
|
-
|
|
94
|
-
var optimisticId = ()
|
|
95
|
-
|
|
96
|
-
// src/hooks/messages/useMessages/lib/queryOptions/queryFn/data/runMessages/index.ts
|
|
97
|
-
var runMessages = async ({
|
|
98
|
-
messages,
|
|
99
|
-
threadId,
|
|
100
|
-
client
|
|
101
|
-
}) => {
|
|
102
|
-
const latestRun = await getLatestRun({ threadId, client });
|
|
103
|
-
if (!latestRun) {
|
|
104
|
-
return [];
|
|
105
|
-
}
|
|
106
|
-
const messageFromLatestRun = messages.find((m) => m.run_id === latestRun.id);
|
|
107
|
-
if (messageFromLatestRun) {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
return [
|
|
111
|
-
await extendMessage({
|
|
112
|
-
message: {
|
|
113
|
-
id: optimisticId(),
|
|
114
|
-
role: "assistant",
|
|
115
|
-
created_at: +/* @__PURE__ */ new Date(),
|
|
116
|
-
object: "thread.message",
|
|
117
|
-
content: [],
|
|
118
|
-
run_id: latestRun.id,
|
|
119
|
-
assistant_id: latestRun.assistant_id,
|
|
120
|
-
thread_id: latestRun.thread_id,
|
|
121
|
-
file_ids: [],
|
|
122
|
-
metadata: {}
|
|
123
|
-
},
|
|
124
|
-
client
|
|
125
|
-
})
|
|
126
|
-
];
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// src/hooks/messages/useMessages/lib/queryOptions/queryFn/data/index.ts
|
|
130
|
-
var data = async ({
|
|
131
|
-
messagesResponse,
|
|
132
|
-
pageParam,
|
|
133
|
-
threadId,
|
|
134
|
-
client
|
|
135
|
-
}) => {
|
|
136
|
-
const messages = await (0, import_p_map.default)(messagesResponse.data, (message) => extendMessage({
|
|
137
|
-
client,
|
|
138
|
-
message
|
|
139
|
-
}));
|
|
140
|
-
if (pageParam) {
|
|
141
|
-
return messages;
|
|
142
|
-
}
|
|
143
|
-
return [
|
|
144
|
-
...await runMessages({
|
|
145
|
-
messages,
|
|
146
|
-
threadId,
|
|
147
|
-
client
|
|
148
|
-
}),
|
|
149
|
-
...messages
|
|
150
|
-
];
|
|
304
|
+
import { uid } from "radash";
|
|
305
|
+
var optimisticId = function() {
|
|
306
|
+
return "-".concat(uid(24));
|
|
151
307
|
};
|
|
152
|
-
|
|
153
|
-
|
|
308
|
+
// src/lib/threadMessages/threadMessagesQueryFn/data/runThreadMessages/index.ts
|
|
309
|
+
var runThreadMessages = function() {
|
|
310
|
+
var _ref = _async_to_generator(function(param) {
|
|
311
|
+
var threadMessages, threadId, client, latestRun, threadMessageFromLatestRun;
|
|
312
|
+
return _ts_generator(this, function(_state) {
|
|
313
|
+
switch(_state.label){
|
|
314
|
+
case 0:
|
|
315
|
+
threadMessages = param.threadMessages, threadId = param.threadId, client = param.client;
|
|
316
|
+
return [
|
|
317
|
+
4,
|
|
318
|
+
getLatestRun({
|
|
319
|
+
threadId: threadId,
|
|
320
|
+
client: client
|
|
321
|
+
})
|
|
322
|
+
];
|
|
323
|
+
case 1:
|
|
324
|
+
latestRun = _state.sent();
|
|
325
|
+
if (!latestRun) {
|
|
326
|
+
return [
|
|
327
|
+
2,
|
|
328
|
+
[]
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
threadMessageFromLatestRun = threadMessages.find(function(m) {
|
|
332
|
+
return m.run_id === latestRun.id;
|
|
333
|
+
});
|
|
334
|
+
if (threadMessageFromLatestRun) {
|
|
335
|
+
return [
|
|
336
|
+
2,
|
|
337
|
+
[]
|
|
338
|
+
];
|
|
339
|
+
}
|
|
340
|
+
return [
|
|
341
|
+
4,
|
|
342
|
+
extendThreadMessage({
|
|
343
|
+
threadMessage: {
|
|
344
|
+
id: optimisticId(),
|
|
345
|
+
role: "assistant",
|
|
346
|
+
created_at: +/* @__PURE__ */ new Date(),
|
|
347
|
+
object: "thread.message",
|
|
348
|
+
content: [],
|
|
349
|
+
run_id: latestRun.id,
|
|
350
|
+
assistant_id: latestRun.assistant_id,
|
|
351
|
+
thread_id: latestRun.thread_id,
|
|
352
|
+
file_ids: [],
|
|
353
|
+
metadata: {}
|
|
354
|
+
},
|
|
355
|
+
client: client
|
|
356
|
+
})
|
|
357
|
+
];
|
|
358
|
+
case 2:
|
|
359
|
+
return [
|
|
360
|
+
2,
|
|
361
|
+
[
|
|
362
|
+
_state.sent()
|
|
363
|
+
]
|
|
364
|
+
];
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
return function runThreadMessages(_) {
|
|
369
|
+
return _ref.apply(this, arguments);
|
|
370
|
+
};
|
|
371
|
+
}();
|
|
372
|
+
// src/lib/threadMessages/threadMessagesQueryFn/data/index.ts
|
|
373
|
+
var data = function() {
|
|
374
|
+
var _ref = _async_to_generator(function(param) {
|
|
375
|
+
var threadMessagesResponse, pageParam, threadId, client, threadMessages;
|
|
376
|
+
return _ts_generator(this, function(_state) {
|
|
377
|
+
switch(_state.label){
|
|
378
|
+
case 0:
|
|
379
|
+
threadMessagesResponse = param.threadMessagesResponse, pageParam = param.pageParam, threadId = param.threadId, client = param.client;
|
|
380
|
+
return [
|
|
381
|
+
4,
|
|
382
|
+
pMap(threadMessagesResponse.data, function(threadMessage) {
|
|
383
|
+
return extendThreadMessage({
|
|
384
|
+
client: client,
|
|
385
|
+
threadMessage: threadMessage
|
|
386
|
+
});
|
|
387
|
+
})
|
|
388
|
+
];
|
|
389
|
+
case 1:
|
|
390
|
+
threadMessages = _state.sent();
|
|
391
|
+
if (pageParam) {
|
|
392
|
+
return [
|
|
393
|
+
2,
|
|
394
|
+
threadMessages
|
|
395
|
+
];
|
|
396
|
+
}
|
|
397
|
+
return [
|
|
398
|
+
4,
|
|
399
|
+
runThreadMessages({
|
|
400
|
+
threadMessages: threadMessages,
|
|
401
|
+
threadId: threadId,
|
|
402
|
+
client: client
|
|
403
|
+
})
|
|
404
|
+
];
|
|
405
|
+
case 2:
|
|
406
|
+
return [
|
|
407
|
+
2,
|
|
408
|
+
_to_consumable_array.apply(void 0, [
|
|
409
|
+
_state.sent()
|
|
410
|
+
]).concat(_to_consumable_array(threadMessages))
|
|
411
|
+
];
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
return function data(_) {
|
|
416
|
+
return _ref.apply(this, arguments);
|
|
417
|
+
};
|
|
418
|
+
}();
|
|
419
|
+
// src/lib/threadMessages/threadMessagesQueryFn/messagesLimit.ts
|
|
154
420
|
var messagesLimit = 10;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (messagesResponse.data.length < messagesLimit)
|
|
161
|
-
return false;
|
|
162
|
-
return messagesResponse.hasNextPage();
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// src/hooks/messages/useMessages/lib/queryOptions/queryFn/index.ts
|
|
166
|
-
var queryFn = async ({
|
|
167
|
-
client = defaultClient,
|
|
168
|
-
threadId,
|
|
169
|
-
pageParam
|
|
170
|
-
}) => {
|
|
171
|
-
const messagesResponse = await client.beta.threads.messages.list(threadId, {
|
|
172
|
-
...pageParam ? { after: pageParam } : {},
|
|
173
|
-
limit: messagesLimit
|
|
174
|
-
});
|
|
175
|
-
return {
|
|
176
|
-
data: await data({
|
|
177
|
-
client,
|
|
178
|
-
messagesResponse,
|
|
179
|
-
pageParam,
|
|
180
|
-
threadId
|
|
181
|
-
}),
|
|
182
|
-
hasNextPage: hasNextPage({ messagesResponse }),
|
|
183
|
-
// @ts-ignore-next-line
|
|
184
|
-
lastId: messagesResponse.body.last_id
|
|
185
|
-
};
|
|
421
|
+
// src/lib/threadMessages/threadMessagesQueryFn/hasNextPage.ts
|
|
422
|
+
var hasNextPage = function(param) {
|
|
423
|
+
var threadMessagesResponse = param.threadMessagesResponse;
|
|
424
|
+
if (threadMessagesResponse.data.length < messagesLimit) return false;
|
|
425
|
+
return threadMessagesResponse.hasNextPage();
|
|
186
426
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
427
|
+
// src/lib/threadMessages/threadMessagesQueryFn/index.ts
|
|
428
|
+
var threadMessagesQueryFn = function() {
|
|
429
|
+
var _ref = _async_to_generator(function(param) {
|
|
430
|
+
var _param_client, client, threadId, pageParam, threadMessagesResponse, _tmp;
|
|
431
|
+
return _ts_generator(this, function(_state) {
|
|
432
|
+
switch(_state.label){
|
|
433
|
+
case 0:
|
|
434
|
+
_param_client = param.client, client = _param_client === void 0 ? defaultClient : _param_client, threadId = param.threadId, pageParam = param.pageParam;
|
|
435
|
+
return [
|
|
436
|
+
4,
|
|
437
|
+
client.beta.threads.messages.list(threadId, _object_spread_props(_object_spread({}, pageParam ? {
|
|
438
|
+
after: pageParam
|
|
439
|
+
} : {}), {
|
|
440
|
+
limit: messagesLimit
|
|
441
|
+
}))
|
|
442
|
+
];
|
|
443
|
+
case 1:
|
|
444
|
+
threadMessagesResponse = _state.sent();
|
|
445
|
+
_tmp = {};
|
|
446
|
+
return [
|
|
447
|
+
4,
|
|
448
|
+
data({
|
|
449
|
+
client: client,
|
|
450
|
+
threadMessagesResponse: threadMessagesResponse,
|
|
451
|
+
pageParam: pageParam,
|
|
452
|
+
threadId: threadId
|
|
453
|
+
})
|
|
454
|
+
];
|
|
455
|
+
case 2:
|
|
456
|
+
return [
|
|
457
|
+
2,
|
|
458
|
+
(_tmp.data = _state.sent(), _tmp.hasNextPage = hasNextPage({
|
|
459
|
+
threadMessagesResponse: threadMessagesResponse
|
|
460
|
+
}), _tmp.// @ts-ignore-next-line
|
|
461
|
+
lastId = threadMessagesResponse.body.last_id, _tmp)
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
return function threadMessagesQueryFn(_) {
|
|
467
|
+
return _ref.apply(this, arguments);
|
|
468
|
+
};
|
|
469
|
+
}();
|
|
470
|
+
// src/lib/runs/runsQueryFn.ts
|
|
471
|
+
var runsQueryFn = function() {
|
|
472
|
+
var _ref = _async_to_generator(function(param) {
|
|
473
|
+
var _param_client, client, threadId, response;
|
|
474
|
+
return _ts_generator(this, function(_state) {
|
|
475
|
+
switch(_state.label){
|
|
476
|
+
case 0:
|
|
477
|
+
_param_client = param.client, client = _param_client === void 0 ? defaultClient : _param_client, threadId = param.threadId;
|
|
478
|
+
return [
|
|
479
|
+
4,
|
|
480
|
+
client.beta.threads.runs.list(threadId, {
|
|
481
|
+
limit: 1
|
|
482
|
+
})
|
|
483
|
+
];
|
|
484
|
+
case 1:
|
|
485
|
+
response = _state.sent();
|
|
486
|
+
return [
|
|
487
|
+
2,
|
|
488
|
+
{
|
|
489
|
+
// @ts-ignore-next-line
|
|
490
|
+
data: response.data,
|
|
491
|
+
hasNextPage: response.hasNextPage(),
|
|
492
|
+
// @ts-ignore-next-line
|
|
493
|
+
lastId: response.body.last_id
|
|
494
|
+
}
|
|
495
|
+
];
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
return function runsQueryFn(_) {
|
|
500
|
+
return _ref.apply(this, arguments);
|
|
501
|
+
};
|
|
502
|
+
}();
|
|
503
|
+
export { runsQueryFn, threadMessagesQueryFn };
|
|
209
504
|
//# sourceMappingURL=queryFns.js.map
|