@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/mutationFns.cjs
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3
|
-
try {
|
|
4
|
-
var info = gen[key](arg);
|
|
5
|
-
var value = info.value;
|
|
6
|
-
} catch (error) {
|
|
7
|
-
reject(error);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (info.done) {
|
|
11
|
-
resolve(value);
|
|
12
|
-
} else {
|
|
13
|
-
Promise.resolve(value).then(_next, _throw);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function _async_to_generator(fn) {
|
|
17
|
-
return function() {
|
|
18
|
-
var self = this, args = arguments;
|
|
19
|
-
return new Promise(function(resolve, reject) {
|
|
20
|
-
var gen = fn.apply(self, args);
|
|
21
|
-
function _next(value) {
|
|
22
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
23
|
-
}
|
|
24
|
-
function _throw(err) {
|
|
25
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
26
|
-
}
|
|
27
|
-
_next(undefined);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function _define_property(obj, key, value) {
|
|
32
|
-
if (key in obj) {
|
|
33
|
-
Object.defineProperty(obj, key, {
|
|
34
|
-
value: value,
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
obj[key] = value;
|
|
41
|
-
}
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
function _object_spread(target) {
|
|
45
|
-
for(var i = 1; i < arguments.length; i++){
|
|
46
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
47
|
-
var ownKeys = Object.keys(source);
|
|
48
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
49
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
50
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
ownKeys.forEach(function(key) {
|
|
54
|
-
_define_property(target, key, source[key]);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return target;
|
|
58
|
-
}
|
|
59
|
-
function ownKeys(object, enumerableOnly) {
|
|
60
|
-
var keys = Object.keys(object);
|
|
61
|
-
if (Object.getOwnPropertySymbols) {
|
|
62
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
63
|
-
if (enumerableOnly) {
|
|
64
|
-
symbols = symbols.filter(function(sym) {
|
|
65
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
keys.push.apply(keys, symbols);
|
|
69
|
-
}
|
|
70
|
-
return keys;
|
|
71
|
-
}
|
|
72
|
-
function _object_spread_props(target, source) {
|
|
73
|
-
source = source != null ? source : {};
|
|
74
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
75
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
76
|
-
} else {
|
|
77
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
78
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return target;
|
|
82
|
-
}
|
|
83
|
-
function _ts_generator(thisArg, body) {
|
|
84
|
-
var f, y, t, g, _ = {
|
|
85
|
-
label: 0,
|
|
86
|
-
sent: function() {
|
|
87
|
-
if (t[0] & 1) throw t[1];
|
|
88
|
-
return t[1];
|
|
89
|
-
},
|
|
90
|
-
trys: [],
|
|
91
|
-
ops: []
|
|
92
|
-
};
|
|
93
|
-
return g = {
|
|
94
|
-
next: verb(0),
|
|
95
|
-
"throw": verb(1),
|
|
96
|
-
"return": verb(2)
|
|
97
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
98
|
-
return this;
|
|
99
|
-
}), g;
|
|
100
|
-
function verb(n) {
|
|
101
|
-
return function(v) {
|
|
102
|
-
return step([
|
|
103
|
-
n,
|
|
104
|
-
v
|
|
105
|
-
]);
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function step(op) {
|
|
109
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
110
|
-
while(_)try {
|
|
111
|
-
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;
|
|
112
|
-
if (y = 0, t) op = [
|
|
113
|
-
op[0] & 2,
|
|
114
|
-
t.value
|
|
115
|
-
];
|
|
116
|
-
switch(op[0]){
|
|
117
|
-
case 0:
|
|
118
|
-
case 1:
|
|
119
|
-
t = op;
|
|
120
|
-
break;
|
|
121
|
-
case 4:
|
|
122
|
-
_.label++;
|
|
123
|
-
return {
|
|
124
|
-
value: op[1],
|
|
125
|
-
done: false
|
|
126
|
-
};
|
|
127
|
-
case 5:
|
|
128
|
-
_.label++;
|
|
129
|
-
y = op[1];
|
|
130
|
-
op = [
|
|
131
|
-
0
|
|
132
|
-
];
|
|
133
|
-
continue;
|
|
134
|
-
case 7:
|
|
135
|
-
op = _.ops.pop();
|
|
136
|
-
_.trys.pop();
|
|
137
|
-
continue;
|
|
138
|
-
default:
|
|
139
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
140
|
-
_ = 0;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
144
|
-
_.label = op[1];
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
148
|
-
_.label = t[1];
|
|
149
|
-
t = op;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
if (t && _.label < t[2]) {
|
|
153
|
-
_.label = t[2];
|
|
154
|
-
_.ops.push(op);
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
if (t[2]) _.ops.pop();
|
|
158
|
-
_.trys.pop();
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
op = body.call(thisArg, _);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
op = [
|
|
164
|
-
6,
|
|
165
|
-
e
|
|
166
|
-
];
|
|
167
|
-
y = 0;
|
|
168
|
-
} finally{
|
|
169
|
-
f = t = 0;
|
|
170
|
-
}
|
|
171
|
-
if (op[0] & 5) throw op[1];
|
|
172
|
-
return {
|
|
173
|
-
value: op[0] ? op[1] : void 0,
|
|
174
|
-
done: true
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
var __create = Object.create;
|
|
179
|
-
var __defProp = Object.defineProperty;
|
|
180
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
181
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
182
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
183
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
184
|
-
var __export = function(target, all) {
|
|
185
|
-
for(var name in all)__defProp(target, name, {
|
|
186
|
-
get: all[name],
|
|
187
|
-
enumerable: true
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
var __copyProps = function(to, from, except, desc) {
|
|
191
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
192
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
193
|
-
try {
|
|
194
|
-
var _loop = function() {
|
|
195
|
-
var key = _step.value;
|
|
196
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
197
|
-
get: function() {
|
|
198
|
-
return from[key];
|
|
199
|
-
},
|
|
200
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
204
|
-
} catch (err) {
|
|
205
|
-
_didIteratorError = true;
|
|
206
|
-
_iteratorError = err;
|
|
207
|
-
} finally{
|
|
208
|
-
try {
|
|
209
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
210
|
-
_iterator.return();
|
|
211
|
-
}
|
|
212
|
-
} finally{
|
|
213
|
-
if (_didIteratorError) {
|
|
214
|
-
throw _iteratorError;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return to;
|
|
220
|
-
};
|
|
221
|
-
var __toESM = function(mod, isNodeMode, target) {
|
|
222
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
223
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
224
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
225
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
226
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
227
|
-
value: mod,
|
|
228
|
-
enumerable: true
|
|
229
|
-
}) : target, mod);
|
|
230
|
-
};
|
|
231
|
-
var __toCommonJS = function(mod) {
|
|
232
|
-
return __copyProps(__defProp({}, "__esModule", {
|
|
233
|
-
value: true
|
|
234
|
-
}), mod);
|
|
235
|
-
};
|
|
236
|
-
// src/mutationFns.ts
|
|
237
|
-
var mutationFns_exports = {};
|
|
238
|
-
__export(mutationFns_exports, {
|
|
239
|
-
createMessageMutationFn: function() {
|
|
240
|
-
return createMessageMutationFn;
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
module.exports = __toCommonJS(mutationFns_exports);
|
|
244
|
-
// src/lib/ai/index.ts
|
|
245
|
-
var import_openai = __toESM(require("openai"), 1);
|
|
246
|
-
var defaultClient = new import_openai.default({
|
|
247
|
-
apiKey: process.env.OPENAI_API_KEY
|
|
248
|
-
});
|
|
249
|
-
// src/lib/runSteps/getRunSteps/index.ts
|
|
250
|
-
var getRunSteps = function() {
|
|
251
|
-
var _ref = _async_to_generator(function(param) {
|
|
252
|
-
var threadId, runId, client, runStepsResponse;
|
|
253
|
-
return _ts_generator(this, function(_state) {
|
|
254
|
-
switch(_state.label){
|
|
255
|
-
case 0:
|
|
256
|
-
threadId = param.threadId, runId = param.runId, client = param.client;
|
|
257
|
-
return [
|
|
258
|
-
4,
|
|
259
|
-
client.beta.threads.runs.steps.list(threadId, runId)
|
|
260
|
-
];
|
|
261
|
-
case 1:
|
|
262
|
-
runStepsResponse = _state.sent();
|
|
263
|
-
return [
|
|
264
|
-
2,
|
|
265
|
-
runStepsResponse.data
|
|
266
|
-
];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
return function getRunSteps(_) {
|
|
271
|
-
return _ref.apply(this, arguments);
|
|
272
|
-
};
|
|
273
|
-
}();
|
|
274
|
-
// src/lib/messages/extendMessage.ts
|
|
275
|
-
var extendMessage = function() {
|
|
276
|
-
var _ref = _async_to_generator(function(param) {
|
|
277
|
-
var message, client, _tmp, _tmp1;
|
|
278
|
-
return _ts_generator(this, function(_state) {
|
|
279
|
-
switch(_state.label){
|
|
280
|
-
case 0:
|
|
281
|
-
message = param.message, client = param.client;
|
|
282
|
-
if (!message.run_id) {
|
|
283
|
-
return [
|
|
284
|
-
2,
|
|
285
|
-
_object_spread_props(_object_spread({}, message), {
|
|
286
|
-
runSteps: []
|
|
287
|
-
})
|
|
288
|
-
];
|
|
289
|
-
}
|
|
290
|
-
_tmp = [
|
|
291
|
-
_object_spread({}, message)
|
|
292
|
-
];
|
|
293
|
-
_tmp1 = {};
|
|
294
|
-
return [
|
|
295
|
-
4,
|
|
296
|
-
getRunSteps({
|
|
297
|
-
threadId: message.thread_id,
|
|
298
|
-
runId: message.run_id,
|
|
299
|
-
client: client
|
|
300
|
-
})
|
|
301
|
-
];
|
|
302
|
-
case 1:
|
|
303
|
-
return [
|
|
304
|
-
2,
|
|
305
|
-
_object_spread_props.apply(void 0, _tmp.concat([
|
|
306
|
-
(_tmp1.runSteps = _state.sent(), _tmp1)
|
|
307
|
-
]))
|
|
308
|
-
];
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
return function extendMessage(_) {
|
|
313
|
-
return _ref.apply(this, arguments);
|
|
314
|
-
};
|
|
315
|
-
}();
|
|
316
|
-
// src/lib/messages/createMessageMutationFn.ts
|
|
317
|
-
var createMessageMutationFn = function() {
|
|
318
|
-
var _ref = _async_to_generator(function(param) {
|
|
319
|
-
var _param_client, client, content, threadId, message, _tmp;
|
|
320
|
-
return _ts_generator(this, function(_state) {
|
|
321
|
-
switch(_state.label){
|
|
322
|
-
case 0:
|
|
323
|
-
_param_client = param.client, client = _param_client === void 0 ? defaultClient : _param_client, content = param.content, threadId = param.threadId;
|
|
324
|
-
return [
|
|
325
|
-
4,
|
|
326
|
-
client.beta.threads.messages.create(threadId, {
|
|
327
|
-
content: content,
|
|
328
|
-
role: "user"
|
|
329
|
-
})
|
|
330
|
-
];
|
|
331
|
-
case 1:
|
|
332
|
-
message = _state.sent();
|
|
333
|
-
_tmp = {};
|
|
334
|
-
return [
|
|
335
|
-
4,
|
|
336
|
-
extendMessage({
|
|
337
|
-
message: message,
|
|
338
|
-
client: client
|
|
339
|
-
})
|
|
340
|
-
];
|
|
341
|
-
case 2:
|
|
342
|
-
return [
|
|
343
|
-
2,
|
|
344
|
-
(_tmp.message = _state.sent(), _tmp)
|
|
345
|
-
];
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
return function createMessageMutationFn(_) {
|
|
350
|
-
return _ref.apply(this, arguments);
|
|
351
|
-
};
|
|
352
|
-
}();
|
|
353
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
354
|
-
0 && (module.exports = {
|
|
355
|
-
createMessageMutationFn: createMessageMutationFn
|
|
356
|
-
});
|
|
357
|
-
//# sourceMappingURL=mutationFns.cjs.map
|
package/dist/mutationFns.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mutationFns.ts","../src/lib/ai/index.ts","../src/lib/runSteps/getRunSteps/index.ts","../src/lib/messages/extendMessage.ts","../src/lib/messages/createMessageMutationFn.ts"],"names":["OpenAI"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAmB;AAEZ,IAAM,gBAAgB,IAAI,cAAAA,QAAO;AAAA,EACtC,QAAQ,QAAQ,IAAI;AACtB,CAAC;;;ACIM,IAAM,cAAc,OAAO;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,MAAY;AACV,QAAM,mBAAmB,MAAM,OAAO,KAAK,QAAQ,KAAK,MAAM;AAAA,IAC5D;AAAA,IACA;AAAA,EACF;AAEA,SAAO,iBAAiB;AAC1B;;;ACXO,IAAM,gBAAgB,OAAO;AAAA,EAClC;AAAA,EACA;AACF,MAAY;AACV,MAAI,CAAC,QAAQ,QAAQ;AACnB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,MAAM,YAAY;AAAA,MAC1B,UAAU,QAAQ;AAAA,MAClB,OAAO,QAAQ;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACbO,IAAM,0BAA0B,OAAO;AAAA,EAC5C,SAAS;AAAA,EACT;AAAA,EACA;AACF,MAA+B;AAC7B,QAAM,UAAU,MAAM,OAAO,KAAK,QAAQ,SAAS,OAAO,UAAU;AAAA,IAClE;AAAA,IACA,MAAM;AAAA,EACR,CAAC;AAED,SAAO;AAAA,IACL,SAAS,MAAM,cAAc;AAAA,MAC3B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF","sourcesContent":["export { createMessageMutationFn } from '@/lib/messages/createMessageMutationFn'\n","import OpenAI from 'openai'\n\nexport const defaultClient = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY!,\n})\n","import OpenAI from 'openai'\n\ntype Args = {\n threadId: string\n runId: string\n client: OpenAI\n}\n\nexport const getRunSteps = async ({\n threadId,\n runId,\n client,\n}: Args) => {\n const runStepsResponse = await client.beta.threads.runs.steps.list(\n threadId,\n runId,\n )\n\n return runStepsResponse.data\n}\n","import OpenAI from 'openai'\nimport { getRunSteps } from '@/lib/runSteps/getRunSteps'\n\ntype Args = {\n message: OpenAI.Beta.Threads.Messages.Message\n client: OpenAI\n}\n\nexport const extendMessage = async ({\n message,\n client,\n}: Args) => {\n if (!message.run_id) {\n return {\n ...message,\n runSteps: [],\n }\n }\n\n return {\n ...message,\n runSteps: await getRunSteps({\n threadId: message.thread_id,\n runId: message.run_id,\n client,\n }),\n }\n}\n","import { defaultClient } from '@/lib/ai'\nimport { Message } from '@/types'\nimport { extendMessage } from '@/lib/messages/extendMessage'\n\nexport type Args = {\n client?: typeof defaultClient\n content: string\n threadId: string\n}\n\nexport type Response = {\n message: Message\n}\n\nexport const createMessageMutationFn = async ({\n client = defaultClient,\n content,\n threadId,\n}: Args): Promise<Response> => {\n const message = await client.beta.threads.messages.create(threadId, {\n content: content,\n role: 'user',\n })\n\n return {\n message: await extendMessage({\n message,\n client,\n }),\n }\n}\n"]}
|
package/dist/mutationFns.d.cts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { d as defaultClient } from './index-CGpJFXMu.cjs';
|
|
2
|
-
import { Message } from './types/index.cjs';
|
|
3
|
-
import 'openai';
|
|
4
|
-
|
|
5
|
-
type Args = {
|
|
6
|
-
client?: typeof defaultClient;
|
|
7
|
-
content: string;
|
|
8
|
-
threadId: string;
|
|
9
|
-
};
|
|
10
|
-
type Response = {
|
|
11
|
-
message: Message;
|
|
12
|
-
};
|
|
13
|
-
declare const createMessageMutationFn: ({ client, content, threadId, }: Args) => Promise<Response>;
|
|
14
|
-
|
|
15
|
-
export { createMessageMutationFn };
|
package/dist/mutationFns.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { d as defaultClient } from './index-CGpJFXMu.js';
|
|
2
|
-
import { Message } from './types/index.js';
|
|
3
|
-
import 'openai';
|
|
4
|
-
|
|
5
|
-
type Args = {
|
|
6
|
-
client?: typeof defaultClient;
|
|
7
|
-
content: string;
|
|
8
|
-
threadId: string;
|
|
9
|
-
};
|
|
10
|
-
type Response = {
|
|
11
|
-
message: Message;
|
|
12
|
-
};
|
|
13
|
-
declare const createMessageMutationFn: ({ client, content, threadId, }: Args) => Promise<Response>;
|
|
14
|
-
|
|
15
|
-
export { createMessageMutationFn };
|
package/dist/mutationFns.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
// src/lib/ai/index.ts
|
|
2
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3
|
-
try {
|
|
4
|
-
var info = gen[key](arg);
|
|
5
|
-
var value = info.value;
|
|
6
|
-
} catch (error) {
|
|
7
|
-
reject(error);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (info.done) {
|
|
11
|
-
resolve(value);
|
|
12
|
-
} else {
|
|
13
|
-
Promise.resolve(value).then(_next, _throw);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function _async_to_generator(fn) {
|
|
17
|
-
return function() {
|
|
18
|
-
var self = this, args = arguments;
|
|
19
|
-
return new Promise(function(resolve, reject) {
|
|
20
|
-
var gen = fn.apply(self, args);
|
|
21
|
-
function _next(value) {
|
|
22
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
23
|
-
}
|
|
24
|
-
function _throw(err) {
|
|
25
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
26
|
-
}
|
|
27
|
-
_next(undefined);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function _define_property(obj, key, value) {
|
|
32
|
-
if (key in obj) {
|
|
33
|
-
Object.defineProperty(obj, key, {
|
|
34
|
-
value: value,
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
obj[key] = value;
|
|
41
|
-
}
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
function _object_spread(target) {
|
|
45
|
-
for(var i = 1; i < arguments.length; i++){
|
|
46
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
47
|
-
var ownKeys = Object.keys(source);
|
|
48
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
49
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
50
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
ownKeys.forEach(function(key) {
|
|
54
|
-
_define_property(target, key, source[key]);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return target;
|
|
58
|
-
}
|
|
59
|
-
function ownKeys(object, enumerableOnly) {
|
|
60
|
-
var keys = Object.keys(object);
|
|
61
|
-
if (Object.getOwnPropertySymbols) {
|
|
62
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
63
|
-
if (enumerableOnly) {
|
|
64
|
-
symbols = symbols.filter(function(sym) {
|
|
65
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
keys.push.apply(keys, symbols);
|
|
69
|
-
}
|
|
70
|
-
return keys;
|
|
71
|
-
}
|
|
72
|
-
function _object_spread_props(target, source) {
|
|
73
|
-
source = source != null ? source : {};
|
|
74
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
75
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
76
|
-
} else {
|
|
77
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
78
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return target;
|
|
82
|
-
}
|
|
83
|
-
function _ts_generator(thisArg, body) {
|
|
84
|
-
var f, y, t, g, _ = {
|
|
85
|
-
label: 0,
|
|
86
|
-
sent: function() {
|
|
87
|
-
if (t[0] & 1) throw t[1];
|
|
88
|
-
return t[1];
|
|
89
|
-
},
|
|
90
|
-
trys: [],
|
|
91
|
-
ops: []
|
|
92
|
-
};
|
|
93
|
-
return g = {
|
|
94
|
-
next: verb(0),
|
|
95
|
-
"throw": verb(1),
|
|
96
|
-
"return": verb(2)
|
|
97
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
98
|
-
return this;
|
|
99
|
-
}), g;
|
|
100
|
-
function verb(n) {
|
|
101
|
-
return function(v) {
|
|
102
|
-
return step([
|
|
103
|
-
n,
|
|
104
|
-
v
|
|
105
|
-
]);
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function step(op) {
|
|
109
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
110
|
-
while(_)try {
|
|
111
|
-
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;
|
|
112
|
-
if (y = 0, t) op = [
|
|
113
|
-
op[0] & 2,
|
|
114
|
-
t.value
|
|
115
|
-
];
|
|
116
|
-
switch(op[0]){
|
|
117
|
-
case 0:
|
|
118
|
-
case 1:
|
|
119
|
-
t = op;
|
|
120
|
-
break;
|
|
121
|
-
case 4:
|
|
122
|
-
_.label++;
|
|
123
|
-
return {
|
|
124
|
-
value: op[1],
|
|
125
|
-
done: false
|
|
126
|
-
};
|
|
127
|
-
case 5:
|
|
128
|
-
_.label++;
|
|
129
|
-
y = op[1];
|
|
130
|
-
op = [
|
|
131
|
-
0
|
|
132
|
-
];
|
|
133
|
-
continue;
|
|
134
|
-
case 7:
|
|
135
|
-
op = _.ops.pop();
|
|
136
|
-
_.trys.pop();
|
|
137
|
-
continue;
|
|
138
|
-
default:
|
|
139
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
140
|
-
_ = 0;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
144
|
-
_.label = op[1];
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
148
|
-
_.label = t[1];
|
|
149
|
-
t = op;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
if (t && _.label < t[2]) {
|
|
153
|
-
_.label = t[2];
|
|
154
|
-
_.ops.push(op);
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
if (t[2]) _.ops.pop();
|
|
158
|
-
_.trys.pop();
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
op = body.call(thisArg, _);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
op = [
|
|
164
|
-
6,
|
|
165
|
-
e
|
|
166
|
-
];
|
|
167
|
-
y = 0;
|
|
168
|
-
} finally{
|
|
169
|
-
f = t = 0;
|
|
170
|
-
}
|
|
171
|
-
if (op[0] & 5) throw op[1];
|
|
172
|
-
return {
|
|
173
|
-
value: op[0] ? op[1] : void 0,
|
|
174
|
-
done: true
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
import OpenAI from "openai";
|
|
179
|
-
var defaultClient = new OpenAI({
|
|
180
|
-
apiKey: process.env.OPENAI_API_KEY
|
|
181
|
-
});
|
|
182
|
-
// src/lib/runSteps/getRunSteps/index.ts
|
|
183
|
-
var getRunSteps = function() {
|
|
184
|
-
var _ref = _async_to_generator(function(param) {
|
|
185
|
-
var threadId, runId, client, runStepsResponse;
|
|
186
|
-
return _ts_generator(this, function(_state) {
|
|
187
|
-
switch(_state.label){
|
|
188
|
-
case 0:
|
|
189
|
-
threadId = param.threadId, runId = param.runId, client = param.client;
|
|
190
|
-
return [
|
|
191
|
-
4,
|
|
192
|
-
client.beta.threads.runs.steps.list(threadId, runId)
|
|
193
|
-
];
|
|
194
|
-
case 1:
|
|
195
|
-
runStepsResponse = _state.sent();
|
|
196
|
-
return [
|
|
197
|
-
2,
|
|
198
|
-
runStepsResponse.data
|
|
199
|
-
];
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
return function getRunSteps(_) {
|
|
204
|
-
return _ref.apply(this, arguments);
|
|
205
|
-
};
|
|
206
|
-
}();
|
|
207
|
-
// src/lib/messages/extendMessage.ts
|
|
208
|
-
var extendMessage = function() {
|
|
209
|
-
var _ref = _async_to_generator(function(param) {
|
|
210
|
-
var message, client, _tmp, _tmp1;
|
|
211
|
-
return _ts_generator(this, function(_state) {
|
|
212
|
-
switch(_state.label){
|
|
213
|
-
case 0:
|
|
214
|
-
message = param.message, client = param.client;
|
|
215
|
-
if (!message.run_id) {
|
|
216
|
-
return [
|
|
217
|
-
2,
|
|
218
|
-
_object_spread_props(_object_spread({}, message), {
|
|
219
|
-
runSteps: []
|
|
220
|
-
})
|
|
221
|
-
];
|
|
222
|
-
}
|
|
223
|
-
_tmp = [
|
|
224
|
-
_object_spread({}, message)
|
|
225
|
-
];
|
|
226
|
-
_tmp1 = {};
|
|
227
|
-
return [
|
|
228
|
-
4,
|
|
229
|
-
getRunSteps({
|
|
230
|
-
threadId: message.thread_id,
|
|
231
|
-
runId: message.run_id,
|
|
232
|
-
client: client
|
|
233
|
-
})
|
|
234
|
-
];
|
|
235
|
-
case 1:
|
|
236
|
-
return [
|
|
237
|
-
2,
|
|
238
|
-
_object_spread_props.apply(void 0, _tmp.concat([
|
|
239
|
-
(_tmp1.runSteps = _state.sent(), _tmp1)
|
|
240
|
-
]))
|
|
241
|
-
];
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
return function extendMessage(_) {
|
|
246
|
-
return _ref.apply(this, arguments);
|
|
247
|
-
};
|
|
248
|
-
}();
|
|
249
|
-
// src/lib/messages/createMessageMutationFn.ts
|
|
250
|
-
var createMessageMutationFn = function() {
|
|
251
|
-
var _ref = _async_to_generator(function(param) {
|
|
252
|
-
var _param_client, client, content, threadId, message, _tmp;
|
|
253
|
-
return _ts_generator(this, function(_state) {
|
|
254
|
-
switch(_state.label){
|
|
255
|
-
case 0:
|
|
256
|
-
_param_client = param.client, client = _param_client === void 0 ? defaultClient : _param_client, content = param.content, threadId = param.threadId;
|
|
257
|
-
return [
|
|
258
|
-
4,
|
|
259
|
-
client.beta.threads.messages.create(threadId, {
|
|
260
|
-
content: content,
|
|
261
|
-
role: "user"
|
|
262
|
-
})
|
|
263
|
-
];
|
|
264
|
-
case 1:
|
|
265
|
-
message = _state.sent();
|
|
266
|
-
_tmp = {};
|
|
267
|
-
return [
|
|
268
|
-
4,
|
|
269
|
-
extendMessage({
|
|
270
|
-
message: message,
|
|
271
|
-
client: client
|
|
272
|
-
})
|
|
273
|
-
];
|
|
274
|
-
case 2:
|
|
275
|
-
return [
|
|
276
|
-
2,
|
|
277
|
-
(_tmp.message = _state.sent(), _tmp)
|
|
278
|
-
];
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
return function createMessageMutationFn(_) {
|
|
283
|
-
return _ref.apply(this, arguments);
|
|
284
|
-
};
|
|
285
|
-
}();
|
|
286
|
-
export { createMessageMutationFn };
|
|
287
|
-
//# sourceMappingURL=mutationFns.js.map
|
package/dist/mutationFns.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/ai/index.ts","../src/lib/runSteps/getRunSteps/index.ts","../src/lib/messages/extendMessage.ts","../src/lib/messages/createMessageMutationFn.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY;AAEZ,IAAM,gBAAgB,IAAI,OAAO;AAAA,EACtC,QAAQ,QAAQ,IAAI;AACtB,CAAC;;;ACIM,IAAM,cAAc,OAAO;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,MAAY;AACV,QAAM,mBAAmB,MAAM,OAAO,KAAK,QAAQ,KAAK,MAAM;AAAA,IAC5D;AAAA,IACA;AAAA,EACF;AAEA,SAAO,iBAAiB;AAC1B;;;ACXO,IAAM,gBAAgB,OAAO;AAAA,EAClC;AAAA,EACA;AACF,MAAY;AACV,MAAI,CAAC,QAAQ,QAAQ;AACnB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,UAAU,MAAM,YAAY;AAAA,MAC1B,UAAU,QAAQ;AAAA,MAClB,OAAO,QAAQ;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACbO,IAAM,0BAA0B,OAAO;AAAA,EAC5C,SAAS;AAAA,EACT;AAAA,EACA;AACF,MAA+B;AAC7B,QAAM,UAAU,MAAM,OAAO,KAAK,QAAQ,SAAS,OAAO,UAAU;AAAA,IAClE;AAAA,IACA,MAAM;AAAA,EACR,CAAC;AAED,SAAO;AAAA,IACL,SAAS,MAAM,cAAc;AAAA,MAC3B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF","sourcesContent":["import OpenAI from 'openai'\n\nexport const defaultClient = new OpenAI({\n apiKey: process.env.OPENAI_API_KEY!,\n})\n","import OpenAI from 'openai'\n\ntype Args = {\n threadId: string\n runId: string\n client: OpenAI\n}\n\nexport const getRunSteps = async ({\n threadId,\n runId,\n client,\n}: Args) => {\n const runStepsResponse = await client.beta.threads.runs.steps.list(\n threadId,\n runId,\n )\n\n return runStepsResponse.data\n}\n","import OpenAI from 'openai'\nimport { getRunSteps } from '@/lib/runSteps/getRunSteps'\n\ntype Args = {\n message: OpenAI.Beta.Threads.Messages.Message\n client: OpenAI\n}\n\nexport const extendMessage = async ({\n message,\n client,\n}: Args) => {\n if (!message.run_id) {\n return {\n ...message,\n runSteps: [],\n }\n }\n\n return {\n ...message,\n runSteps: await getRunSteps({\n threadId: message.thread_id,\n runId: message.run_id,\n client,\n }),\n }\n}\n","import { defaultClient } from '@/lib/ai'\nimport { Message } from '@/types'\nimport { extendMessage } from '@/lib/messages/extendMessage'\n\nexport type Args = {\n client?: typeof defaultClient\n content: string\n threadId: string\n}\n\nexport type Response = {\n message: Message\n}\n\nexport const createMessageMutationFn = async ({\n client = defaultClient,\n content,\n threadId,\n}: Args): Promise<Response> => {\n const message = await client.beta.threads.messages.create(threadId, {\n content: content,\n role: 'user',\n })\n\n return {\n message: await extendMessage({\n message,\n client,\n }),\n }\n}\n"]}
|