@superinterface/react 1.1.8 → 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.
@@ -0,0 +1,517 @@
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 _object_without_properties(source, excluded) {
84
+ if (source == null) return {};
85
+ var target = _object_without_properties_loose(source, excluded);
86
+ var key, i;
87
+ if (Object.getOwnPropertySymbols) {
88
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
89
+ for(i = 0; i < sourceSymbolKeys.length; i++){
90
+ key = sourceSymbolKeys[i];
91
+ if (excluded.indexOf(key) >= 0) continue;
92
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
93
+ target[key] = source[key];
94
+ }
95
+ }
96
+ return target;
97
+ }
98
+ function _object_without_properties_loose(source, excluded) {
99
+ if (source == null) return {};
100
+ var target = {};
101
+ var sourceKeys = Object.keys(source);
102
+ var key, i;
103
+ for(i = 0; i < sourceKeys.length; i++){
104
+ key = sourceKeys[i];
105
+ if (excluded.indexOf(key) >= 0) continue;
106
+ target[key] = source[key];
107
+ }
108
+ return target;
109
+ }
110
+ function _ts_generator(thisArg, body) {
111
+ var f, y, t, g, _ = {
112
+ label: 0,
113
+ sent: function() {
114
+ if (t[0] & 1) throw t[1];
115
+ return t[1];
116
+ },
117
+ trys: [],
118
+ ops: []
119
+ };
120
+ return g = {
121
+ next: verb(0),
122
+ "throw": verb(1),
123
+ "return": verb(2)
124
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
125
+ return this;
126
+ }), g;
127
+ function verb(n) {
128
+ return function(v) {
129
+ return step([
130
+ n,
131
+ v
132
+ ]);
133
+ };
134
+ }
135
+ function step(op) {
136
+ if (f) throw new TypeError("Generator is already executing.");
137
+ while(_)try {
138
+ 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;
139
+ if (y = 0, t) op = [
140
+ op[0] & 2,
141
+ t.value
142
+ ];
143
+ switch(op[0]){
144
+ case 0:
145
+ case 1:
146
+ t = op;
147
+ break;
148
+ case 4:
149
+ _.label++;
150
+ return {
151
+ value: op[1],
152
+ done: false
153
+ };
154
+ case 5:
155
+ _.label++;
156
+ y = op[1];
157
+ op = [
158
+ 0
159
+ ];
160
+ continue;
161
+ case 7:
162
+ op = _.ops.pop();
163
+ _.trys.pop();
164
+ continue;
165
+ default:
166
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
167
+ _ = 0;
168
+ continue;
169
+ }
170
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
171
+ _.label = op[1];
172
+ break;
173
+ }
174
+ if (op[0] === 6 && _.label < t[1]) {
175
+ _.label = t[1];
176
+ t = op;
177
+ break;
178
+ }
179
+ if (t && _.label < t[2]) {
180
+ _.label = t[2];
181
+ _.ops.push(op);
182
+ break;
183
+ }
184
+ if (t[2]) _.ops.pop();
185
+ _.trys.pop();
186
+ continue;
187
+ }
188
+ op = body.call(thisArg, _);
189
+ } catch (e) {
190
+ op = [
191
+ 6,
192
+ e
193
+ ];
194
+ y = 0;
195
+ } finally{
196
+ f = t = 0;
197
+ }
198
+ if (op[0] & 5) throw op[1];
199
+ return {
200
+ value: op[0] ? op[1] : void 0,
201
+ done: true
202
+ };
203
+ }
204
+ }
205
+ var __create = Object.create;
206
+ var __defProp = Object.defineProperty;
207
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
208
+ var __getOwnPropNames = Object.getOwnPropertyNames;
209
+ var __getProtoOf = Object.getPrototypeOf;
210
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
211
+ var __export = function(target, all) {
212
+ for(var name in all)__defProp(target, name, {
213
+ get: all[name],
214
+ enumerable: true
215
+ });
216
+ };
217
+ var __copyProps = function(to, from, except, desc) {
218
+ if (from && typeof from === "object" || typeof from === "function") {
219
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
220
+ try {
221
+ var _loop = function() {
222
+ var key = _step.value;
223
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
224
+ get: function() {
225
+ return from[key];
226
+ },
227
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
228
+ });
229
+ };
230
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
231
+ } catch (err) {
232
+ _didIteratorError = true;
233
+ _iteratorError = err;
234
+ } finally{
235
+ try {
236
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
237
+ _iterator.return();
238
+ }
239
+ } finally{
240
+ if (_didIteratorError) {
241
+ throw _iteratorError;
242
+ }
243
+ }
244
+ }
245
+ }
246
+ return to;
247
+ };
248
+ var __toESM = function(mod, isNodeMode, target) {
249
+ return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
250
+ // file that has been converted to a CommonJS file using a Babel-
251
+ // compatible transform (i.e. "__esModule" has not been set), then set
252
+ // "default" to the CommonJS "module.exports" for node compatibility.
253
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
254
+ value: mod,
255
+ enumerable: true
256
+ }) : target, mod);
257
+ };
258
+ var __toCommonJS = function(mod) {
259
+ return __copyProps(__defProp({}, "__esModule", {
260
+ value: true
261
+ }), mod);
262
+ };
263
+ // src/mutationFns.ts
264
+ var mutationFns_exports = {};
265
+ __export(mutationFns_exports, {
266
+ createRunMutationFn: function() {
267
+ return createRunMutationFn;
268
+ },
269
+ createThreadMessageMutationFn: function() {
270
+ return createThreadMessageMutationFn;
271
+ },
272
+ handleActionMutationFn: function() {
273
+ return handleActionMutationFn;
274
+ }
275
+ });
276
+ module.exports = __toCommonJS(mutationFns_exports);
277
+ // src/lib/ai/index.ts
278
+ var import_openai = __toESM(require("openai"), 1);
279
+ var defaultClient = new import_openai.default({
280
+ apiKey: process.env.OPENAI_API_KEY
281
+ });
282
+ // src/lib/runSteps/getRunSteps/index.ts
283
+ var getRunSteps = function() {
284
+ var _ref = _async_to_generator(function(param) {
285
+ var threadId, runId, client, runStepsResponse;
286
+ return _ts_generator(this, function(_state) {
287
+ switch(_state.label){
288
+ case 0:
289
+ threadId = param.threadId, runId = param.runId, client = param.client;
290
+ return [
291
+ 4,
292
+ client.beta.threads.runs.steps.list(threadId, runId)
293
+ ];
294
+ case 1:
295
+ runStepsResponse = _state.sent();
296
+ return [
297
+ 2,
298
+ runStepsResponse.data
299
+ ];
300
+ }
301
+ });
302
+ });
303
+ return function getRunSteps(_) {
304
+ return _ref.apply(this, arguments);
305
+ };
306
+ }();
307
+ // src/lib/threadMessages/extendThreadMessage.ts
308
+ var extendThreadMessage = function() {
309
+ var _ref = _async_to_generator(function(param) {
310
+ var threadMessage, client, _tmp, _tmp1;
311
+ return _ts_generator(this, function(_state) {
312
+ switch(_state.label){
313
+ case 0:
314
+ threadMessage = param.threadMessage, client = param.client;
315
+ if (!threadMessage.run_id) {
316
+ return [
317
+ 2,
318
+ _object_spread_props(_object_spread({}, threadMessage), {
319
+ runSteps: []
320
+ })
321
+ ];
322
+ }
323
+ _tmp = [
324
+ _object_spread({}, threadMessage)
325
+ ];
326
+ _tmp1 = {};
327
+ return [
328
+ 4,
329
+ getRunSteps({
330
+ threadId: threadMessage.thread_id,
331
+ runId: threadMessage.run_id,
332
+ client: client
333
+ })
334
+ ];
335
+ case 1:
336
+ return [
337
+ 2,
338
+ _object_spread_props.apply(void 0, _tmp.concat([
339
+ (_tmp1.runSteps = _state.sent(), _tmp1)
340
+ ]))
341
+ ];
342
+ }
343
+ });
344
+ });
345
+ return function extendThreadMessage(_) {
346
+ return _ref.apply(this, arguments);
347
+ };
348
+ }();
349
+ // src/lib/threadMessages/createThreadMessageMutationFn.ts
350
+ var createThreadMessageMutationFn = function() {
351
+ var _ref = _async_to_generator(function(param) {
352
+ var _param_client, client, content, threadId, threadMessage, _tmp;
353
+ return _ts_generator(this, function(_state) {
354
+ switch(_state.label){
355
+ case 0:
356
+ _param_client = param.client, client = _param_client === void 0 ? defaultClient : _param_client, content = param.content, threadId = param.threadId;
357
+ return [
358
+ 4,
359
+ client.beta.threads.messages.create(threadId, {
360
+ content: content,
361
+ role: "user"
362
+ })
363
+ ];
364
+ case 1:
365
+ threadMessage = _state.sent();
366
+ _tmp = {};
367
+ return [
368
+ 4,
369
+ extendThreadMessage({
370
+ threadMessage: threadMessage,
371
+ client: client
372
+ })
373
+ ];
374
+ case 2:
375
+ return [
376
+ 2,
377
+ (_tmp.threadMessage = _state.sent(), _tmp)
378
+ ];
379
+ }
380
+ });
381
+ });
382
+ return function createThreadMessageMutationFn(_) {
383
+ return _ref.apply(this, arguments);
384
+ };
385
+ }();
386
+ // src/lib/runs/createRunMutationFn.ts
387
+ var createRunMutationFn = function() {
388
+ var _ref = _async_to_generator(function(_param) {
389
+ var _param_client, client, threadId, assistantId, rest, run;
390
+ return _ts_generator(this, function(_state) {
391
+ switch(_state.label){
392
+ case 0:
393
+ _param_client = _param.client, client = _param_client === void 0 ? defaultClient : _param_client, threadId = _param.threadId, assistantId = _param.assistantId, rest = _object_without_properties(_param, [
394
+ "client",
395
+ "threadId",
396
+ "assistantId"
397
+ ]);
398
+ return [
399
+ 4,
400
+ client.beta.threads.runs.create(threadId, _object_spread_props(_object_spread({}, rest), {
401
+ assistant_id: assistantId
402
+ }))
403
+ ];
404
+ case 1:
405
+ run = _state.sent();
406
+ return [
407
+ 2,
408
+ {
409
+ run: run
410
+ }
411
+ ];
412
+ }
413
+ });
414
+ });
415
+ return function createRunMutationFn(_param) {
416
+ return _ref.apply(this, arguments);
417
+ };
418
+ }();
419
+ // src/lib/actions/handleActionMutationFn/index.ts
420
+ var import_p_map = __toESM(require("p-map"), 1);
421
+ // src/lib/actions/handleActionMutationFn/toolOutput/index.ts
422
+ var toolOutput = function() {
423
+ var _ref = _async_to_generator(function(param) {
424
+ var toolCall, latestRun, functions, fn, _tmp;
425
+ return _ts_generator(this, function(_state) {
426
+ switch(_state.label){
427
+ case 0:
428
+ toolCall = param.toolCall, latestRun = param.latestRun, functions = param.functions;
429
+ fn = functions[toolCall.function.name];
430
+ if (!fn) {
431
+ console.log({
432
+ toolCall: toolCall
433
+ });
434
+ throw new Error("No function for ".concat(toolCall.function.name));
435
+ }
436
+ _tmp = {
437
+ tool_call_id: toolCall.id
438
+ };
439
+ return [
440
+ 4,
441
+ fn({
442
+ toolCall: toolCall,
443
+ latestRun: latestRun
444
+ })
445
+ ];
446
+ case 1:
447
+ return [
448
+ 2,
449
+ (_tmp.output = _state.sent(), _tmp)
450
+ ];
451
+ }
452
+ });
453
+ });
454
+ return function toolOutput(_) {
455
+ return _ref.apply(this, arguments);
456
+ };
457
+ }();
458
+ // src/lib/actions/handleActionMutationFn/index.ts
459
+ var handleActionMutationFn = function() {
460
+ var _ref = _async_to_generator(function(param) {
461
+ var _param_client, client, latestRun, _param_functions, functions, toolCalls, run, _, _1, _tmp, _tmp1;
462
+ return _ts_generator(this, function(_state) {
463
+ switch(_state.label){
464
+ case 0:
465
+ _param_client = param.client, client = _param_client === void 0 ? defaultClient : _param_client, latestRun = param.latestRun, _param_functions = param.functions, functions = _param_functions === void 0 ? {} : _param_functions;
466
+ if (!latestRun.required_action) {
467
+ throw new Error("No required_action for run ${latestRun.id} with status ${latestRun.status}");
468
+ }
469
+ console.log("handleActions", {
470
+ latestRun: latestRun
471
+ });
472
+ toolCalls = latestRun.required_action.submit_tool_outputs.tool_calls;
473
+ _1 = (_ = client.beta.threads.runs).submitToolOutputs;
474
+ _tmp = [
475
+ latestRun.thread_id,
476
+ latestRun.id
477
+ ];
478
+ _tmp1 = {};
479
+ return [
480
+ 4,
481
+ (0, import_p_map.default)(toolCalls, function(toolCall) {
482
+ return toolOutput({
483
+ toolCall: toolCall,
484
+ latestRun: latestRun,
485
+ functions: functions
486
+ });
487
+ })
488
+ ];
489
+ case 1:
490
+ return [
491
+ 4,
492
+ _1.apply(_, _tmp.concat([
493
+ (_tmp1.tool_outputs = _state.sent(), _tmp1)
494
+ ]))
495
+ ];
496
+ case 2:
497
+ run = _state.sent();
498
+ return [
499
+ 2,
500
+ {
501
+ run: run
502
+ }
503
+ ];
504
+ }
505
+ });
506
+ });
507
+ return function handleActionMutationFn(_) {
508
+ return _ref.apply(this, arguments);
509
+ };
510
+ }();
511
+ // Annotate the CommonJS export names for ESM import in node:
512
+ 0 && (module.exports = {
513
+ createRunMutationFn: createRunMutationFn,
514
+ createThreadMessageMutationFn: createThreadMessageMutationFn,
515
+ handleActionMutationFn: handleActionMutationFn
516
+ });
517
+ //# sourceMappingURL=mutationFns.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mutationFns.ts","../src/lib/ai/index.ts","../src/lib/runSteps/getRunSteps/index.ts","../src/lib/threadMessages/extendThreadMessage.ts","../src/lib/threadMessages/createThreadMessageMutationFn.ts","../src/lib/runs/createRunMutationFn.ts","../src/lib/actions/handleActionMutationFn/index.ts","../src/lib/actions/handleActionMutationFn/toolOutput/index.ts"],"names":["OpenAI","pMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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,sBAAsB,OAAO;AAAA,EACxC;AAAA,EACA;AACF,MAAY;AACV,MAAI,CAAC,cAAc,QAAQ;AACzB,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,cAAc;AAAA,MACxB,OAAO,cAAc;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ACbO,IAAM,gCAAgC,OAAO;AAAA,EAClD,SAAS;AAAA,EACT;AAAA,EACA;AACF,MAA+B;AAC7B,QAAM,gBAAgB,MAAM,OAAO,KAAK,QAAQ,SAAS,OAAO,UAAU;AAAA,IACxE;AAAA,IACA,MAAM;AAAA,EACR,CAAC;AAED,SAAO;AAAA,IACL,eAAe,MAAM,oBAAoB;AAAA,MACvC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;AChBO,IAAM,sBAAsB,OAAO;AAAA,EACxC,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAA+B;AAC7B,QAAM,MAAM,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,UAAU;AAAA,IAC1D,GAAG;AAAA,IACH,cAAc;AAAA,EAChB,CAAC;AAED,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;AC3BA,mBAAiB;;;ACQV,IAAM,aAAa,OAAO;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,MAAY;AACV,QAAM,KAAK,UAAU,SAAS,SAAS,IAAI;AAE3C,MAAI,CAAC,IAAI;AACP,YAAQ,IAAI,EAAE,SAAS,CAAC;AACxB,UAAM,IAAI,MAAM,mBAAmB,SAAS,SAAS,IAAI,EAAE;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL,cAAc,SAAS;AAAA,IACvB,QAAQ,MAAM,GAAG;AAAA,MACf;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;;;ADbO,IAAM,yBAAyB,OAAO;AAAA,EAC3C,SAAS;AAAA,EACT;AAAA,EACA,YAAY,CAAC;AACf,MAA+B;AAC7B,MAAI,CAAC,UAAU,iBAAiB;AAC9B,UAAM,IAAI,MAAM,4EAA4E;AAAA,EAC9F;AAEA,UAAQ,IAAI,iBAAiB,EAAE,UAAU,CAAC;AAE1C,QAAM,YAAY,UAAU,gBAAgB,oBAAoB;AAEhE,QAAM,MAAM,MAAM,OAAO,KAAK,QAAQ,KAAK;AAAA,IACzC,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,MACE,cAAc,UAAM,aAAAC,SAAK,WAAW,CAAC,aAAa,WAAW,EAAE,UAAU,WAAW,UAAU,CAAC,CAAC;AAAA,IAClG;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF","sourcesContent":["export { createThreadMessageMutationFn } from '@/lib/threadMessages/createThreadMessageMutationFn'\nexport { createRunMutationFn } from '@/lib/runs/createRunMutationFn'\nexport { handleActionMutationFn } from '@/lib/actions/handleActionMutationFn'\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 threadMessage: OpenAI.Beta.Threads.Messages.ThreadMessage\n client: OpenAI\n}\n\nexport const extendThreadMessage = async ({\n threadMessage,\n client,\n}: Args) => {\n if (!threadMessage.run_id) {\n return {\n ...threadMessage,\n runSteps: [],\n }\n }\n\n return {\n ...threadMessage,\n runSteps: await getRunSteps({\n threadId: threadMessage.thread_id,\n runId: threadMessage.run_id,\n client,\n }),\n }\n}\n","import { defaultClient } from '@/lib/ai'\nimport { ThreadMessage } from '@/types'\nimport { extendThreadMessage } from '@/lib/threadMessages/extendThreadMessage'\n\nexport type Args = {\n client?: typeof defaultClient\n content: string\n threadId: string\n}\n\nexport type Response = {\n threadMessage: ThreadMessage\n}\n\nexport const createThreadMessageMutationFn = async ({\n client = defaultClient,\n content,\n threadId,\n}: Args): Promise<Response> => {\n const threadMessage = await client.beta.threads.messages.create(threadId, {\n content: content,\n role: 'user',\n })\n\n return {\n threadMessage: await extendThreadMessage({\n threadMessage,\n client,\n }),\n }\n}\n","import OpenAI from 'openai'\nimport { Run } from '@/types'\nimport { defaultClient } from '@/lib/ai'\n\nexport type Args = {\n client?: typeof defaultClient\n threadId: string\n assistantId: string\n} & (OpenAI.Beta.Threads.Runs.RunCreateParams | {})\n\nexport type Response = {\n run: Run\n}\n\nexport const createRunMutationFn = async ({\n client = defaultClient,\n threadId,\n assistantId,\n ...rest\n}: Args): Promise<Response> => {\n const run = await client.beta.threads.runs.create(threadId, {\n ...rest,\n assistant_id: assistantId,\n })\n\n return {\n run,\n }\n}\n","import { Run, Functions } from '@/types'\nimport pMap from 'p-map'\nimport { defaultClient } from '@/lib/ai'\nimport { toolOutput } from './toolOutput'\n\nexport type Args = {\n client?: typeof defaultClient\n latestRun: Run\n functions?: Functions\n}\n\nexport type Response = {\n run: Run\n}\n\nexport const handleActionMutationFn = async ({\n client = defaultClient,\n latestRun,\n functions = {},\n}: Args): Promise<Response> => {\n if (!latestRun.required_action) {\n throw new Error('No required_action for run ${latestRun.id} with status ${latestRun.status}')\n }\n\n console.log('handleActions', { latestRun })\n\n const toolCalls = latestRun.required_action.submit_tool_outputs.tool_calls\n\n const run = await client.beta.threads.runs.submitToolOutputs(\n latestRun.thread_id,\n latestRun.id,\n {\n tool_outputs: await pMap(toolCalls, (toolCall) => toolOutput({ toolCall, latestRun, functions })),\n },\n )\n\n return {\n run,\n }\n}\n","import OpenAI from 'openai'\nimport { Functions } from '@/types'\n\ntype Args = {\n toolCall: OpenAI.Beta.Threads.Runs.RequiredActionFunctionToolCall\n latestRun: OpenAI.Beta.Threads.Runs.Run\n functions: Functions\n}\n\nexport const toolOutput = async ({\n toolCall,\n latestRun,\n functions,\n}: Args) => {\n const fn = functions[toolCall.function.name]\n\n if (!fn) {\n console.log({ toolCall })\n throw new Error(`No function for ${toolCall.function.name}`)\n }\n\n return {\n tool_call_id: toolCall.id,\n output: await fn({\n toolCall,\n latestRun,\n }),\n }\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { d as defaultClient } from './index-CGpJFXMu.cjs';
2
+ import { ThreadMessage, Run, Functions } from './types/index.cjs';
3
+ import OpenAI from 'openai';
4
+
5
+ type Args$2 = {
6
+ client?: typeof defaultClient;
7
+ content: string;
8
+ threadId: string;
9
+ };
10
+ type Response$2 = {
11
+ threadMessage: ThreadMessage;
12
+ };
13
+ declare const createThreadMessageMutationFn: ({ client, content, threadId, }: Args$2) => Promise<Response$2>;
14
+
15
+ type Args$1 = {
16
+ client?: typeof defaultClient;
17
+ threadId: string;
18
+ assistantId: string;
19
+ } & (OpenAI.Beta.Threads.Runs.RunCreateParams | {});
20
+ type Response$1 = {
21
+ run: Run;
22
+ };
23
+ declare const createRunMutationFn: ({ client, threadId, assistantId, ...rest }: Args$1) => Promise<Response$1>;
24
+
25
+ type Args = {
26
+ client?: typeof defaultClient;
27
+ latestRun: Run;
28
+ functions?: Functions;
29
+ };
30
+ type Response = {
31
+ run: Run;
32
+ };
33
+ declare const handleActionMutationFn: ({ client, latestRun, functions, }: Args) => Promise<Response>;
34
+
35
+ export { createRunMutationFn, createThreadMessageMutationFn, handleActionMutationFn };
@@ -1,5 +1,5 @@
1
- import { d as defaultClient } from './index-LPUEY9WE.js';
2
- import { Message, Run, Functions } from './types/index.js';
1
+ import { d as defaultClient } from './index-CGpJFXMu.js';
2
+ import { ThreadMessage, Run, Functions } from './types/index.js';
3
3
  import OpenAI from 'openai';
4
4
 
5
5
  type Args$2 = {
@@ -8,28 +8,28 @@ type Args$2 = {
8
8
  threadId: string;
9
9
  };
10
10
  type Response$2 = {
11
- message: Message;
11
+ threadMessage: ThreadMessage;
12
12
  };
13
- declare const mutationFn$2: ({ client, content, threadId, }: Args$2) => Promise<Response$2>;
13
+ declare const createThreadMessageMutationFn: ({ client, content, threadId, }: Args$2) => Promise<Response$2>;
14
14
 
15
15
  type Args$1 = {
16
16
  client?: typeof defaultClient;
17
- latestRun: Run;
18
- functions?: Functions;
19
- };
17
+ threadId: string;
18
+ assistantId: string;
19
+ } & (OpenAI.Beta.Threads.Runs.RunCreateParams | {});
20
20
  type Response$1 = {
21
21
  run: Run;
22
22
  };
23
- declare const mutationFn$1: ({ client, latestRun, functions, }: Args$1) => Promise<Response$1>;
23
+ declare const createRunMutationFn: ({ client, threadId, assistantId, ...rest }: Args$1) => Promise<Response$1>;
24
24
 
25
25
  type Args = {
26
26
  client?: typeof defaultClient;
27
- threadId: string;
28
- assistantId: string;
29
- } & (OpenAI.Beta.Threads.Runs.RunCreateParams | {});
27
+ latestRun: Run;
28
+ functions?: Functions;
29
+ };
30
30
  type Response = {
31
31
  run: Run;
32
32
  };
33
- declare const mutationFn: ({ client, threadId, assistantId, ...rest }: Args) => Promise<Response>;
33
+ declare const handleActionMutationFn: ({ client, latestRun, functions, }: Args) => Promise<Response>;
34
34
 
35
- export { type Response$2 as CreateMessageResponse, mutationFn$2 as createMessageMutationFn, mutationFn as createRunMutationFn, mutationFn$1 as handleActionMutationFn };
35
+ export { createRunMutationFn, createThreadMessageMutationFn, handleActionMutationFn };