supercompat 2.33.0 → 3.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.cjs +2253 -418
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -39
- package/dist/index.d.ts +42 -39
- package/dist/index.js +2259 -429
- package/dist/index.js.map +1 -1
- package/dist/supercompat.cjs +86 -14
- package/dist/supercompat.cjs.map +1 -1
- package/dist/supercompat.js +86 -14
- package/dist/supercompat.js.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +12 -5
- package/dist/types/index.d.ts +12 -5
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -93,6 +93,13 @@ function _define_property(obj, key, value) {
|
|
|
93
93
|
}
|
|
94
94
|
return obj;
|
|
95
95
|
}
|
|
96
|
+
function _instanceof(left, right) {
|
|
97
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
98
|
+
return !!right[Symbol.hasInstance](left);
|
|
99
|
+
} else {
|
|
100
|
+
return left instanceof right;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
96
103
|
function _iterable_to_array(iter) {
|
|
97
104
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
98
105
|
}
|
|
@@ -407,12 +414,18 @@ __export(index_exports, {
|
|
|
407
414
|
openaiClientAdapter: function() {
|
|
408
415
|
return openaiClientAdapter;
|
|
409
416
|
},
|
|
417
|
+
openaiResponsesStorageAdapter: function() {
|
|
418
|
+
return openaiResponsesStorageAdapter;
|
|
419
|
+
},
|
|
410
420
|
perplexityClientAdapter: function() {
|
|
411
421
|
return perplexityClientAdapter;
|
|
412
422
|
},
|
|
413
423
|
prismaStorageAdapter: function() {
|
|
414
424
|
return prismaStorageAdapter;
|
|
415
425
|
},
|
|
426
|
+
responsesRunAdapter: function() {
|
|
427
|
+
return responsesRunAdapter;
|
|
428
|
+
},
|
|
416
429
|
supercompat: function() {
|
|
417
430
|
return supercompat;
|
|
418
431
|
},
|
|
@@ -456,21 +469,85 @@ var findRequestHandler = function(param) {
|
|
|
456
469
|
}
|
|
457
470
|
};
|
|
458
471
|
// src/supercompatFetch/originalFetch.ts
|
|
459
|
-
var
|
|
460
|
-
var
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
472
|
+
var toRecord = function() {
|
|
473
|
+
var init = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
474
|
+
if (_instanceof(init, Headers)) return Object.fromEntries(init.entries());
|
|
475
|
+
return Object.keys(init).reduce(function(acc, key) {
|
|
476
|
+
return _object_spread_props(_object_spread({}, acc), _define_property({}, key.toLowerCase(), init[key]));
|
|
477
|
+
}, {});
|
|
478
|
+
};
|
|
479
|
+
var getClientHeaders = /*#__PURE__*/ function() {
|
|
480
|
+
var _ref = _async_to_generator(function(client) {
|
|
481
|
+
return _ts_generator(this, function(_state) {
|
|
482
|
+
if (typeof client.client.authHeaders === "function") {
|
|
483
|
+
return [
|
|
484
|
+
2,
|
|
485
|
+
client.client.authHeaders()
|
|
486
|
+
];
|
|
487
|
+
}
|
|
488
|
+
if (typeof client.client.defaultHeaders === "function") {
|
|
489
|
+
return [
|
|
490
|
+
2,
|
|
491
|
+
client.client.defaultHeaders()
|
|
492
|
+
];
|
|
493
|
+
}
|
|
494
|
+
return [
|
|
495
|
+
2,
|
|
496
|
+
{}
|
|
497
|
+
];
|
|
466
498
|
});
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
|
|
499
|
+
});
|
|
500
|
+
return function getClientHeaders(client) {
|
|
501
|
+
return _ref.apply(this, arguments);
|
|
502
|
+
};
|
|
503
|
+
}();
|
|
504
|
+
var normalize = function(headersInit) {
|
|
505
|
+
if (!headersInit) return {};
|
|
506
|
+
if (_instanceof(headersInit, Headers)) {
|
|
507
|
+
return Object.fromEntries(headersInit.entries());
|
|
472
508
|
}
|
|
509
|
+
if (_instanceof(headersInit === null || headersInit === void 0 ? void 0 : headersInit.values, Headers)) {
|
|
510
|
+
return Object.fromEntries(headersInit.values.entries());
|
|
511
|
+
}
|
|
512
|
+
return Object.fromEntries(new Headers(headersInit).entries());
|
|
473
513
|
};
|
|
514
|
+
var originalFetch = /*#__PURE__*/ function() {
|
|
515
|
+
var _ref = _async_to_generator(function(param) {
|
|
516
|
+
var args, client, _client_client, _args, url, options, requestHeaders, clientHeaders, headers;
|
|
517
|
+
return _ts_generator(this, function(_state) {
|
|
518
|
+
switch(_state.label){
|
|
519
|
+
case 0:
|
|
520
|
+
args = param.args, client = param.client;
|
|
521
|
+
if (!((_client_client = client.client) === null || _client_client === void 0 ? void 0 : _client_client.fetch)) {
|
|
522
|
+
return [
|
|
523
|
+
2,
|
|
524
|
+
fetch.apply(void 0, _to_consumable_array(args))
|
|
525
|
+
];
|
|
526
|
+
}
|
|
527
|
+
_args = _sliced_to_array(args, 2), url = _args[0], options = _args[1];
|
|
528
|
+
requestHeaders = toRecord(options === null || options === void 0 ? void 0 : options.headers);
|
|
529
|
+
return [
|
|
530
|
+
4,
|
|
531
|
+
getClientHeaders(client)
|
|
532
|
+
];
|
|
533
|
+
case 1:
|
|
534
|
+
clientHeaders = normalize.apply(void 0, [
|
|
535
|
+
_state.sent()
|
|
536
|
+
]);
|
|
537
|
+
headers = _object_spread({}, requestHeaders, clientHeaders);
|
|
538
|
+
return [
|
|
539
|
+
2,
|
|
540
|
+
client.client.fetch(url, _object_spread_props(_object_spread({}, options), {
|
|
541
|
+
headers: headers
|
|
542
|
+
}))
|
|
543
|
+
];
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
return function originalFetch(_) {
|
|
548
|
+
return _ref.apply(this, arguments);
|
|
549
|
+
};
|
|
550
|
+
}();
|
|
474
551
|
// src/supercompatFetch/index.ts
|
|
475
552
|
var supercompatFetch = function(param) {
|
|
476
553
|
var client = param.client, storage = param.storage, runAdapter = param.runAdapter;
|
|
@@ -480,13 +557,14 @@ var supercompatFetch = function(param) {
|
|
|
480
557
|
runAdapter: runAdapter
|
|
481
558
|
});
|
|
482
559
|
return /*#__PURE__*/ _async_to_generator(function() {
|
|
483
|
-
var _len, args, _key, _args,
|
|
560
|
+
var _len, args, _key, _args, input, options, url, pathHandler, _options_method, method, requestHandler;
|
|
484
561
|
var _arguments = arguments;
|
|
485
562
|
return _ts_generator(this, function(_state) {
|
|
486
563
|
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
487
564
|
args[_key] = _arguments[_key];
|
|
488
565
|
}
|
|
489
|
-
_args = _sliced_to_array(args, 2),
|
|
566
|
+
_args = _sliced_to_array(args, 2), input = _args[0], options = _args[1];
|
|
567
|
+
url = typeof input === "string" ? input : input.toString();
|
|
490
568
|
pathHandler = findRequestHandler({
|
|
491
569
|
url: url,
|
|
492
570
|
requestHandlers: requestHandlers2
|
|
@@ -882,11 +960,11 @@ var isOModel = function(param) {
|
|
|
882
960
|
};
|
|
883
961
|
// src/lib/messages/systemDeveloperMessages.ts
|
|
884
962
|
var systemDeveloperMessages = function(param) {
|
|
885
|
-
var
|
|
963
|
+
var messages5 = param.messages, model = param.model;
|
|
886
964
|
if (isOModel({
|
|
887
965
|
model: model
|
|
888
966
|
})) {
|
|
889
|
-
return
|
|
967
|
+
return messages5.map(function(message) {
|
|
890
968
|
if (message.role === "system") {
|
|
891
969
|
return _object_spread_props(_object_spread({}, message), {
|
|
892
970
|
// TODO: This should be 'developer' but we're using 'user' for now
|
|
@@ -897,7 +975,7 @@ var systemDeveloperMessages = function(param) {
|
|
|
897
975
|
return message;
|
|
898
976
|
});
|
|
899
977
|
}
|
|
900
|
-
return
|
|
978
|
+
return messages5;
|
|
901
979
|
};
|
|
902
980
|
// src/adapters/client/openaiClientAdapter/completions/post.ts
|
|
903
981
|
var omitKeys = function(param) {
|
|
@@ -915,17 +993,17 @@ var post2 = function(param) {
|
|
|
915
993
|
var openai = param.openai;
|
|
916
994
|
return /*#__PURE__*/ function() {
|
|
917
995
|
var _ref = _async_to_generator(function(_url, options) {
|
|
918
|
-
var body,
|
|
996
|
+
var body, messages5, resultOptions, response, stream, data, error;
|
|
919
997
|
return _ts_generator(this, function(_state) {
|
|
920
998
|
switch(_state.label){
|
|
921
999
|
case 0:
|
|
922
1000
|
body = JSON.parse(options.body);
|
|
923
|
-
|
|
1001
|
+
messages5 = body.messages;
|
|
924
1002
|
resultOptions = _object_spread_props(_object_spread({}, (0, import_radash2.omit)(body, omitKeys({
|
|
925
1003
|
model: body.model
|
|
926
1004
|
}))), {
|
|
927
1005
|
messages: systemDeveloperMessages({
|
|
928
|
-
messages:
|
|
1006
|
+
messages: messages5,
|
|
929
1007
|
model: body.model
|
|
930
1008
|
})
|
|
931
1009
|
});
|
|
@@ -1521,11 +1599,11 @@ var agentSideRoles = [
|
|
|
1521
1599
|
"system"
|
|
1522
1600
|
];
|
|
1523
1601
|
var alternatingMessages = function(param) {
|
|
1524
|
-
var
|
|
1602
|
+
var messages5 = param.messages;
|
|
1525
1603
|
var result = [];
|
|
1526
|
-
|
|
1604
|
+
messages5.forEach(function(message, index) {
|
|
1527
1605
|
result.push(message);
|
|
1528
|
-
var nextMessage =
|
|
1606
|
+
var nextMessage = messages5[index + 1];
|
|
1529
1607
|
if (!nextMessage) return;
|
|
1530
1608
|
if (message.role === "user" && nextMessage.role === "user") {
|
|
1531
1609
|
result.push({
|
|
@@ -1546,12 +1624,12 @@ var post4 = function(param) {
|
|
|
1546
1624
|
var perplexity = param.perplexity;
|
|
1547
1625
|
return /*#__PURE__*/ function() {
|
|
1548
1626
|
var _ref = _async_to_generator(function(_url, options) {
|
|
1549
|
-
var body,
|
|
1627
|
+
var body, messages5, response, stream, data, error;
|
|
1550
1628
|
return _ts_generator(this, function(_state) {
|
|
1551
1629
|
switch(_state.label){
|
|
1552
1630
|
case 0:
|
|
1553
1631
|
body = JSON.parse(options.body);
|
|
1554
|
-
|
|
1632
|
+
messages5 = alternatingMessages({
|
|
1555
1633
|
messages: body.messages
|
|
1556
1634
|
});
|
|
1557
1635
|
if (!body.stream) return [
|
|
@@ -1561,7 +1639,7 @@ var post4 = function(param) {
|
|
|
1561
1639
|
return [
|
|
1562
1640
|
4,
|
|
1563
1641
|
perplexity.chat.completions.create(_object_spread_props(_object_spread({}, body), {
|
|
1564
|
-
messages:
|
|
1642
|
+
messages: messages5
|
|
1565
1643
|
}))
|
|
1566
1644
|
];
|
|
1567
1645
|
case 1:
|
|
@@ -1827,9 +1905,9 @@ var nonEmptyContent = function(param) {
|
|
|
1827
1905
|
return message.content;
|
|
1828
1906
|
};
|
|
1829
1907
|
var nonEmptyMessages = function(param) {
|
|
1830
|
-
var
|
|
1908
|
+
var messages5 = param.messages;
|
|
1831
1909
|
var result = [];
|
|
1832
|
-
|
|
1910
|
+
messages5.forEach(function(message) {
|
|
1833
1911
|
return result.push(_object_spread_props(_object_spread({}, message), {
|
|
1834
1912
|
content: nonEmptyContent({
|
|
1835
1913
|
message: message
|
|
@@ -1840,18 +1918,18 @@ var nonEmptyMessages = function(param) {
|
|
|
1840
1918
|
};
|
|
1841
1919
|
// src/lib/messages/firstUserMessages.ts
|
|
1842
1920
|
var firstUserMessages = function(param) {
|
|
1843
|
-
var
|
|
1844
|
-
var firstMessage =
|
|
1845
|
-
if (!firstMessage) return
|
|
1921
|
+
var messages5 = param.messages;
|
|
1922
|
+
var firstMessage = messages5[0];
|
|
1923
|
+
if (!firstMessage) return messages5;
|
|
1846
1924
|
if (firstMessage.role !== "user") {
|
|
1847
1925
|
return [
|
|
1848
1926
|
{
|
|
1849
1927
|
role: "user",
|
|
1850
1928
|
content: "-"
|
|
1851
1929
|
}
|
|
1852
|
-
].concat(_to_consumable_array(
|
|
1930
|
+
].concat(_to_consumable_array(messages5));
|
|
1853
1931
|
}
|
|
1854
|
-
return
|
|
1932
|
+
return messages5;
|
|
1855
1933
|
};
|
|
1856
1934
|
// src/adapters/client/anthropicClientAdapter/completions/serializeTools.ts
|
|
1857
1935
|
var serializeTools = function(param) {
|
|
@@ -1891,8 +1969,8 @@ var serializeMessage2 = function(param) {
|
|
|
1891
1969
|
return {
|
|
1892
1970
|
type: "tool_use",
|
|
1893
1971
|
id: toolCall.id,
|
|
1894
|
-
name: toolCall.function.name,
|
|
1895
|
-
input: toolCall.function.arguments ? JSON.parse(toolCall.function.arguments) : {}
|
|
1972
|
+
name: "function" in toolCall ? toolCall.function.name : "",
|
|
1973
|
+
input: "function" in toolCall && toolCall.function.arguments ? JSON.parse(toolCall.function.arguments) : {}
|
|
1896
1974
|
};
|
|
1897
1975
|
})))
|
|
1898
1976
|
};
|
|
@@ -1911,8 +1989,8 @@ var serializeMessage2 = function(param) {
|
|
|
1911
1989
|
};
|
|
1912
1990
|
// src/adapters/client/anthropicClientAdapter/completions/serializeMessages/index.ts
|
|
1913
1991
|
var serializeMessages = function(param) {
|
|
1914
|
-
var
|
|
1915
|
-
return
|
|
1992
|
+
var messages5 = param.messages;
|
|
1993
|
+
return messages5.map(function(message) {
|
|
1916
1994
|
return serializeMessage2({
|
|
1917
1995
|
message: message
|
|
1918
1996
|
});
|
|
@@ -1923,13 +2001,13 @@ var post5 = function(param) {
|
|
|
1923
2001
|
var anthropic = param.anthropic;
|
|
1924
2002
|
return /*#__PURE__*/ function() {
|
|
1925
2003
|
var _ref = _async_to_generator(function(_url, options) {
|
|
1926
|
-
var body,
|
|
2004
|
+
var body, messages5, _ref, systemMessages, otherMessages, system, chatMessages, serializedMessages, baseOptions, response, stream, data, error;
|
|
1927
2005
|
return _ts_generator(this, function(_state) {
|
|
1928
2006
|
switch(_state.label){
|
|
1929
2007
|
case 0:
|
|
1930
2008
|
body = JSON.parse(options.body);
|
|
1931
|
-
|
|
1932
|
-
_ref = _sliced_to_array((0, import_radash3.fork)(
|
|
2009
|
+
messages5 = body.messages;
|
|
2010
|
+
_ref = _sliced_to_array((0, import_radash3.fork)(messages5, function(message) {
|
|
1933
2011
|
return message.role === "system";
|
|
1934
2012
|
}), 2), systemMessages = _ref[0], otherMessages = _ref[1];
|
|
1935
2013
|
system = systemMessages.map(function(message) {
|
|
@@ -1942,14 +2020,15 @@ var post5 = function(param) {
|
|
|
1942
2020
|
})
|
|
1943
2021
|
})
|
|
1944
2022
|
});
|
|
1945
|
-
|
|
1946
|
-
|
|
2023
|
+
serializedMessages = serializeMessages({
|
|
2024
|
+
messages: chatMessages
|
|
2025
|
+
});
|
|
2026
|
+
baseOptions = _object_spread_props(_object_spread({}, (0, import_radash3.omit)(body, [
|
|
2027
|
+
"response_format",
|
|
2028
|
+
"stream"
|
|
1947
2029
|
])), {
|
|
1948
|
-
stream: body.stream ? (0, import_radash3.isEmpty)(body.tools) : false,
|
|
1949
2030
|
system: system,
|
|
1950
|
-
messages:
|
|
1951
|
-
messages: chatMessages
|
|
1952
|
-
}),
|
|
2031
|
+
messages: serializedMessages,
|
|
1953
2032
|
max_tokens: 4096,
|
|
1954
2033
|
tools: serializeTools({
|
|
1955
2034
|
tools: body.tools
|
|
@@ -1961,7 +2040,7 @@ var post5 = function(param) {
|
|
|
1961
2040
|
];
|
|
1962
2041
|
return [
|
|
1963
2042
|
4,
|
|
1964
|
-
anthropic.messages.stream(
|
|
2043
|
+
anthropic.messages.stream(baseOptions)
|
|
1965
2044
|
];
|
|
1966
2045
|
case 1:
|
|
1967
2046
|
response = _state.sent();
|
|
@@ -1996,18 +2075,28 @@ var post5 = function(param) {
|
|
|
1996
2075
|
_value = _step.value;
|
|
1997
2076
|
chunk = _value;
|
|
1998
2077
|
if (chunk.type === "content_block_delta") {
|
|
1999
|
-
delta =
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2078
|
+
delta = void 0;
|
|
2079
|
+
if (chunk.delta.type === "input_json_delta") {
|
|
2080
|
+
delta = {
|
|
2081
|
+
tool_calls: [
|
|
2082
|
+
{
|
|
2083
|
+
index: 0,
|
|
2084
|
+
function: {
|
|
2085
|
+
arguments: chunk.delta.partial_json
|
|
2086
|
+
}
|
|
2005
2087
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
|
-
|
|
2088
|
+
]
|
|
2089
|
+
};
|
|
2090
|
+
} else if (chunk.delta.type === "text_delta") {
|
|
2091
|
+
delta = {
|
|
2092
|
+
content: chunk.delta.text
|
|
2093
|
+
};
|
|
2094
|
+
} else {
|
|
2095
|
+
return [
|
|
2096
|
+
3,
|
|
2097
|
+
4
|
|
2098
|
+
];
|
|
2099
|
+
}
|
|
2011
2100
|
messageDelta = {
|
|
2012
2101
|
id: "chatcmpl-".concat((0, import_radash3.uid)(29)),
|
|
2013
2102
|
object: "chat.completion.chunk",
|
|
@@ -2020,22 +2109,32 @@ var post5 = function(param) {
|
|
|
2020
2109
|
};
|
|
2021
2110
|
controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
|
|
2022
2111
|
} else if (chunk.type === "content_block_start") {
|
|
2023
|
-
delta1 =
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2112
|
+
delta1 = void 0;
|
|
2113
|
+
if (chunk.content_block.type === "tool_use") {
|
|
2114
|
+
delta1 = {
|
|
2115
|
+
content: null,
|
|
2116
|
+
tool_calls: [
|
|
2117
|
+
{
|
|
2118
|
+
index: 0,
|
|
2119
|
+
id: chunk.content_block.id,
|
|
2120
|
+
type: "function",
|
|
2121
|
+
function: {
|
|
2122
|
+
name: chunk.content_block.name,
|
|
2123
|
+
arguments: ""
|
|
2124
|
+
}
|
|
2033
2125
|
}
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
|
|
2126
|
+
]
|
|
2127
|
+
};
|
|
2128
|
+
} else if (chunk.content_block.type === "text") {
|
|
2129
|
+
delta1 = {
|
|
2130
|
+
content: chunk.content_block.text
|
|
2131
|
+
};
|
|
2132
|
+
} else {
|
|
2133
|
+
return [
|
|
2134
|
+
3,
|
|
2135
|
+
4
|
|
2136
|
+
];
|
|
2137
|
+
}
|
|
2039
2138
|
messageDelta1 = {
|
|
2040
2139
|
id: "chatcmpl-".concat((0, import_radash3.uid)(29)),
|
|
2041
2140
|
object: "chat.completion.chunk",
|
|
@@ -2143,7 +2242,9 @@ var post5 = function(param) {
|
|
|
2143
2242
|
]);
|
|
2144
2243
|
return [
|
|
2145
2244
|
4,
|
|
2146
|
-
anthropic.messages.create(
|
|
2245
|
+
anthropic.messages.create(_object_spread_props(_object_spread({}, baseOptions), {
|
|
2246
|
+
stream: false
|
|
2247
|
+
}))
|
|
2147
2248
|
];
|
|
2148
2249
|
case 3:
|
|
2149
2250
|
data = _state.sent();
|
|
@@ -3235,7 +3336,8 @@ var serializeToolContent = function(param) {
|
|
|
3235
3336
|
if ((0, import_radash4.isArray)(toolCall.function.output)) {
|
|
3236
3337
|
var isEveryToolPartValid = toolCall.function.output.every(function(toolPart) {
|
|
3237
3338
|
if (!(0, import_radash4.isObject)(toolPart)) return false;
|
|
3238
|
-
|
|
3339
|
+
var _toolPart_type;
|
|
3340
|
+
return validToolCallContentTypes.includes((_toolPart_type = toolPart.type) !== null && _toolPart_type !== void 0 ? _toolPart_type : "");
|
|
3239
3341
|
});
|
|
3240
3342
|
if (isEveryToolPartValid) {
|
|
3241
3343
|
return toolCall.function.output;
|
|
@@ -3259,14 +3361,20 @@ var serializeToolCall = function(param) {
|
|
|
3259
3361
|
var serializeMessageWithContent = function(param) {
|
|
3260
3362
|
var message = param.message;
|
|
3261
3363
|
var _message_metadata;
|
|
3262
|
-
|
|
3364
|
+
var content = serializeContent({
|
|
3365
|
+
content: message.content
|
|
3366
|
+
});
|
|
3367
|
+
if (message.role === "assistant" && ((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls)) {
|
|
3368
|
+
return {
|
|
3369
|
+
role: "assistant",
|
|
3370
|
+
content: content,
|
|
3371
|
+
tool_calls: message.metadata.toolCalls
|
|
3372
|
+
};
|
|
3373
|
+
}
|
|
3374
|
+
return {
|
|
3263
3375
|
role: message.role,
|
|
3264
|
-
content:
|
|
3265
|
-
|
|
3266
|
-
})
|
|
3267
|
-
}, (message === null || message === void 0 ? void 0 : (_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) ? {
|
|
3268
|
-
tool_calls: message.metadata.toolCalls
|
|
3269
|
-
} : {});
|
|
3376
|
+
content: content
|
|
3377
|
+
};
|
|
3270
3378
|
};
|
|
3271
3379
|
var serializeContent = function(param) {
|
|
3272
3380
|
var content = param.content;
|
|
@@ -3276,17 +3384,17 @@ var serializeContent = function(param) {
|
|
|
3276
3384
|
};
|
|
3277
3385
|
var serializeMessage3 = function(param) {
|
|
3278
3386
|
var message = param.message;
|
|
3279
|
-
var _message_metadata;
|
|
3387
|
+
var _message_metadata, _message_metadata1;
|
|
3280
3388
|
var result = [
|
|
3281
3389
|
serializeMessageWithContent({
|
|
3282
3390
|
message: message
|
|
3283
3391
|
})
|
|
3284
3392
|
];
|
|
3285
|
-
var
|
|
3286
|
-
if (!
|
|
3287
|
-
var messageToolCalls = ((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) ||
|
|
3288
|
-
messageToolCalls.forEach(function(tc) {
|
|
3289
|
-
var runStep =
|
|
3393
|
+
var run3 = message.run;
|
|
3394
|
+
if (!run3) return result;
|
|
3395
|
+
var messageToolCalls = Array.isArray((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) ? (_message_metadata1 = message.metadata) === null || _message_metadata1 === void 0 ? void 0 : _message_metadata1.toolCalls : void 0;
|
|
3396
|
+
(messageToolCalls || []).forEach(function(tc) {
|
|
3397
|
+
var runStep = run3.runSteps.find(function(rs) {
|
|
3290
3398
|
if (rs.type !== "tool_calls") return false;
|
|
3291
3399
|
return rs.step_details.tool_calls.some(function(rsTc) {
|
|
3292
3400
|
if (rsTc.type !== "function") return false;
|
|
@@ -3307,15 +3415,15 @@ var serializeMessage3 = function(param) {
|
|
|
3307
3415
|
// src/adapters/run/completionsRunAdapter/messages/index.ts
|
|
3308
3416
|
var messages = /*#__PURE__*/ function() {
|
|
3309
3417
|
var _ref = _async_to_generator(function(param) {
|
|
3310
|
-
var
|
|
3418
|
+
var run3, getMessages2, _, _1, _2;
|
|
3311
3419
|
return _ts_generator(this, function(_state) {
|
|
3312
3420
|
switch(_state.label){
|
|
3313
3421
|
case 0:
|
|
3314
|
-
|
|
3315
|
-
_1 = (_ = _to_consumable_array(
|
|
3422
|
+
run3 = param.run, getMessages2 = param.getMessages;
|
|
3423
|
+
_1 = (_ = _to_consumable_array(run3.instructions ? [
|
|
3316
3424
|
{
|
|
3317
3425
|
role: "system",
|
|
3318
|
-
content:
|
|
3426
|
+
content: run3.instructions
|
|
3319
3427
|
}
|
|
3320
3428
|
] : [])).concat;
|
|
3321
3429
|
_2 = (0, import_radash5.flat);
|
|
@@ -3416,12 +3524,12 @@ var toolCallsData = function(param) {
|
|
|
3416
3524
|
var completionsRunAdapter = function() {
|
|
3417
3525
|
return /*#__PURE__*/ function() {
|
|
3418
3526
|
var _ref = _async_to_generator(function(param) {
|
|
3419
|
-
var clientAdapter,
|
|
3527
|
+
var clientAdapter, run3, onEvent2, getMessages2, getThread2, client, opts, _tmp, providerResponse, e, _e_cause, _e_message, _e_cause_message, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, _delta_content, err;
|
|
3420
3528
|
return _ts_generator(this, function(_state) {
|
|
3421
3529
|
switch(_state.label){
|
|
3422
3530
|
case 0:
|
|
3423
|
-
clientAdapter = param.client,
|
|
3424
|
-
if (
|
|
3531
|
+
clientAdapter = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages, getThread2 = param.getThread;
|
|
3532
|
+
if (run3.status !== "queued") return [
|
|
3425
3533
|
2
|
|
3426
3534
|
];
|
|
3427
3535
|
client = supercompat({
|
|
@@ -3429,7 +3537,7 @@ var completionsRunAdapter = function() {
|
|
|
3429
3537
|
});
|
|
3430
3538
|
onEvent2({
|
|
3431
3539
|
event: "thread.run.in_progress",
|
|
3432
|
-
data: _object_spread_props(_object_spread({},
|
|
3540
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
3433
3541
|
status: "in_progress"
|
|
3434
3542
|
})
|
|
3435
3543
|
});
|
|
@@ -3437,15 +3545,15 @@ var completionsRunAdapter = function() {
|
|
|
3437
3545
|
return [
|
|
3438
3546
|
4,
|
|
3439
3547
|
messages({
|
|
3440
|
-
run:
|
|
3548
|
+
run: run3,
|
|
3441
3549
|
getMessages: getMessages2
|
|
3442
3550
|
})
|
|
3443
3551
|
];
|
|
3444
3552
|
case 1:
|
|
3445
3553
|
opts = _object_spread.apply(void 0, [
|
|
3446
|
-
(_tmp.messages = _state.sent(), _tmp.model =
|
|
3447
|
-
(0, import_radash6.isEmpty)(
|
|
3448
|
-
tools:
|
|
3554
|
+
(_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
|
|
3555
|
+
(0, import_radash6.isEmpty)(run3.tools) ? {} : {
|
|
3556
|
+
tools: run3.tools
|
|
3449
3557
|
}
|
|
3450
3558
|
]);
|
|
3451
3559
|
_state.label = 2;
|
|
@@ -3473,7 +3581,7 @@ var completionsRunAdapter = function() {
|
|
|
3473
3581
|
2,
|
|
3474
3582
|
onEvent2({
|
|
3475
3583
|
event: "thread.run.failed",
|
|
3476
|
-
data: _object_spread_props(_object_spread({},
|
|
3584
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
3477
3585
|
failed_at: (0, import_dayjs.default)().unix(),
|
|
3478
3586
|
status: "in_progress",
|
|
3479
3587
|
last_error: {
|
|
@@ -3492,14 +3600,14 @@ var completionsRunAdapter = function() {
|
|
|
3492
3600
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
3493
3601
|
object: "thread.message",
|
|
3494
3602
|
completed_at: null,
|
|
3495
|
-
run_id:
|
|
3603
|
+
run_id: run3.id,
|
|
3496
3604
|
created_at: (0, import_dayjs.default)().unix(),
|
|
3497
|
-
assistant_id:
|
|
3605
|
+
assistant_id: run3.assistant_id,
|
|
3498
3606
|
incomplete_at: null,
|
|
3499
3607
|
incomplete_details: null,
|
|
3500
3608
|
metadata: {},
|
|
3501
3609
|
attachments: [],
|
|
3502
|
-
thread_id:
|
|
3610
|
+
thread_id: run3.thread_id,
|
|
3503
3611
|
content: [
|
|
3504
3612
|
{
|
|
3505
3613
|
text: {
|
|
@@ -3521,9 +3629,9 @@ var completionsRunAdapter = function() {
|
|
|
3521
3629
|
data: {
|
|
3522
3630
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
3523
3631
|
object: "thread.run.step",
|
|
3524
|
-
run_id:
|
|
3525
|
-
assistant_id:
|
|
3526
|
-
thread_id:
|
|
3632
|
+
run_id: run3.id,
|
|
3633
|
+
assistant_id: run3.assistant_id,
|
|
3634
|
+
thread_id: run3.thread_id,
|
|
3527
3635
|
type: "message_creation",
|
|
3528
3636
|
status: "completed",
|
|
3529
3637
|
completed_at: (0, import_dayjs.default)().unix(),
|
|
@@ -3592,9 +3700,9 @@ var completionsRunAdapter = function() {
|
|
|
3592
3700
|
data: {
|
|
3593
3701
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
3594
3702
|
object: "thread.run.step",
|
|
3595
|
-
run_id:
|
|
3596
|
-
assistant_id:
|
|
3597
|
-
thread_id:
|
|
3703
|
+
run_id: run3.id,
|
|
3704
|
+
assistant_id: run3.assistant_id,
|
|
3705
|
+
thread_id: run3.thread_id,
|
|
3598
3706
|
type: "tool_calls",
|
|
3599
3707
|
status: "in_progress",
|
|
3600
3708
|
completed_at: null,
|
|
@@ -3620,7 +3728,7 @@ var completionsRunAdapter = function() {
|
|
|
3620
3728
|
event: "thread.run.step.delta",
|
|
3621
3729
|
data: {
|
|
3622
3730
|
object: "thread.run.step.delta",
|
|
3623
|
-
run_id:
|
|
3731
|
+
run_id: run3.id,
|
|
3624
3732
|
id: toolCallsRunStep.id,
|
|
3625
3733
|
delta: {
|
|
3626
3734
|
step_details: {
|
|
@@ -3736,12 +3844,12 @@ var completionsRunAdapter = function() {
|
|
|
3736
3844
|
];
|
|
3737
3845
|
case 22:
|
|
3738
3846
|
message = _state.sent();
|
|
3739
|
-
if ((0, import_radash6.isEmpty)(
|
|
3847
|
+
if ((0, import_radash6.isEmpty)(currentToolCalls)) {
|
|
3740
3848
|
return [
|
|
3741
3849
|
2,
|
|
3742
3850
|
onEvent2({
|
|
3743
3851
|
event: "thread.run.completed",
|
|
3744
|
-
data: _object_spread_props(_object_spread({},
|
|
3852
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
3745
3853
|
status: "completed",
|
|
3746
3854
|
completed_at: (0, import_dayjs.default)().unix()
|
|
3747
3855
|
})
|
|
@@ -3752,12 +3860,12 @@ var completionsRunAdapter = function() {
|
|
|
3752
3860
|
2,
|
|
3753
3861
|
onEvent2({
|
|
3754
3862
|
event: "thread.run.requires_action",
|
|
3755
|
-
data: _object_spread_props(_object_spread({},
|
|
3863
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
3756
3864
|
status: "requires_action",
|
|
3757
3865
|
required_action: {
|
|
3758
3866
|
type: "submit_tool_outputs",
|
|
3759
3867
|
submit_tool_outputs: {
|
|
3760
|
-
tool_calls:
|
|
3868
|
+
tool_calls: currentToolCalls
|
|
3761
3869
|
}
|
|
3762
3870
|
}
|
|
3763
3871
|
})
|
|
@@ -3771,174 +3879,1740 @@ var completionsRunAdapter = function() {
|
|
|
3771
3879
|
};
|
|
3772
3880
|
}();
|
|
3773
3881
|
};
|
|
3774
|
-
// src/
|
|
3775
|
-
var
|
|
3776
|
-
// src/lib/runs/runsRegexp.ts
|
|
3777
|
-
var runsRegexp = "^/(?:v1|/?openai)/threads/([^/]+)/runs$";
|
|
3778
|
-
// src/lib/runs/runRegexp.ts
|
|
3779
|
-
var runRegexp = "^/(?:v1|/?openai)/threads/([^/]+)/runs/([^/]+)$";
|
|
3780
|
-
// src/lib/runs/submitToolOutputsRegexp.ts
|
|
3781
|
-
var submitToolOutputsRegexp = "^/(?:v1|/?openai)/threads/([^/]+)/runs/([^/]+)/submit_tool_outputs$";
|
|
3782
|
-
// src/lib/steps/stepsRegexp.ts
|
|
3783
|
-
var stepsRegexp = "^/(?:v1|/?openai)/threads/([^/]+)/runs/([^/]+)/steps$";
|
|
3784
|
-
// src/adapters/storage/prismaStorageAdapter/threads/post.ts
|
|
3785
|
-
var import_dayjs3 = __toESM(require("dayjs"), 1);
|
|
3786
|
-
// src/adapters/storage/prismaStorageAdapter/threads/serializeThread.ts
|
|
3882
|
+
// src/adapters/run/responsesRunAdapter/index.ts
|
|
3883
|
+
var import_radash8 = require("radash");
|
|
3787
3884
|
var import_dayjs2 = __toESM(require("dayjs"), 1);
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3885
|
+
// src/adapters/run/responsesRunAdapter/messages/index.ts
|
|
3886
|
+
var import_radash7 = require("radash");
|
|
3887
|
+
// src/adapters/run/responsesRunAdapter/messages/serializeMessage.ts
|
|
3888
|
+
var serializeMessage4 = function(param) {
|
|
3889
|
+
var message = param.message;
|
|
3890
|
+
if (message.role === "tool") {
|
|
3891
|
+
var toolMessage = message;
|
|
3892
|
+
var output = typeof toolMessage.content === "string" ? toolMessage.content : JSON.stringify(toolMessage.content);
|
|
3893
|
+
var _toolMessage_tool_call_id;
|
|
3894
|
+
return [
|
|
3895
|
+
{
|
|
3896
|
+
type: "function_call_output",
|
|
3897
|
+
call_id: (_toolMessage_tool_call_id = toolMessage.tool_call_id) !== null && _toolMessage_tool_call_id !== void 0 ? _toolMessage_tool_call_id : toolMessage.id,
|
|
3898
|
+
output: output
|
|
3899
|
+
}
|
|
3900
|
+
];
|
|
3901
|
+
}
|
|
3902
|
+
if (message.role === "assistant" && message.tool_calls && message.tool_calls.length > 0) {
|
|
3903
|
+
return message.tool_calls.map(function(tc) {
|
|
3904
|
+
return {
|
|
3905
|
+
type: "function_call",
|
|
3906
|
+
id: tc.id,
|
|
3907
|
+
call_id: tc.id,
|
|
3908
|
+
name: tc.function.name,
|
|
3909
|
+
arguments: tc.function.arguments
|
|
3910
|
+
};
|
|
3911
|
+
});
|
|
3912
|
+
}
|
|
3913
|
+
var contentBlocks = message.content;
|
|
3914
|
+
var text = contentBlocks.map(function(c) {
|
|
3915
|
+
return c.text.value;
|
|
3916
|
+
}).join("\n");
|
|
3917
|
+
if (message.role === "assistant") {
|
|
3918
|
+
return [
|
|
3919
|
+
{
|
|
3920
|
+
role: "assistant",
|
|
3921
|
+
content: [
|
|
3922
|
+
{
|
|
3923
|
+
type: "output_text",
|
|
3924
|
+
text: text
|
|
3925
|
+
}
|
|
3926
|
+
],
|
|
3927
|
+
status: "completed",
|
|
3928
|
+
type: "message"
|
|
3929
|
+
}
|
|
3930
|
+
];
|
|
3931
|
+
}
|
|
3932
|
+
return [
|
|
3933
|
+
{
|
|
3934
|
+
role: message.role,
|
|
3935
|
+
content: [
|
|
3936
|
+
{
|
|
3937
|
+
type: "input_text",
|
|
3938
|
+
text: text
|
|
3939
|
+
}
|
|
3940
|
+
],
|
|
3941
|
+
type: "message"
|
|
3942
|
+
}
|
|
3943
|
+
];
|
|
3798
3944
|
};
|
|
3799
|
-
// src/adapters/
|
|
3800
|
-
var
|
|
3801
|
-
var
|
|
3802
|
-
|
|
3803
|
-
var _len, args, _key, body, messages3, metadata, initialCreatedAt, thread;
|
|
3804
|
-
var _arguments = arguments;
|
|
3945
|
+
// src/adapters/run/responsesRunAdapter/messages/index.ts
|
|
3946
|
+
var messages2 = /*#__PURE__*/ function() {
|
|
3947
|
+
var _ref = _async_to_generator(function(param) {
|
|
3948
|
+
var run3, getMessages2, _;
|
|
3805
3949
|
return _ts_generator(this, function(_state) {
|
|
3806
3950
|
switch(_state.label){
|
|
3807
3951
|
case 0:
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
}
|
|
3811
|
-
body = JSON.parse(args[1].body);
|
|
3812
|
-
messages3 = body.messages || [];
|
|
3813
|
-
metadata = body.metadata || {};
|
|
3814
|
-
initialCreatedAt = (0, import_dayjs3.default)().subtract(messages3.length, "seconds").format();
|
|
3952
|
+
run3 = param.run, getMessages2 = param.getMessages;
|
|
3953
|
+
_ = (0, import_radash7.flat);
|
|
3815
3954
|
return [
|
|
3816
3955
|
4,
|
|
3817
|
-
|
|
3818
|
-
data: _object_spread_props(_object_spread({
|
|
3819
|
-
metadata: metadata
|
|
3820
|
-
}, metadata.assistantId ? {
|
|
3821
|
-
assistant: {
|
|
3822
|
-
connect: {
|
|
3823
|
-
id: metadata.assistantId
|
|
3824
|
-
}
|
|
3825
|
-
}
|
|
3826
|
-
} : {}), {
|
|
3827
|
-
messages: {
|
|
3828
|
-
create: messages3.map(function(message, index) {
|
|
3829
|
-
return {
|
|
3830
|
-
role: message.role === "user" ? "USER" : "ASSISTANT",
|
|
3831
|
-
content: [
|
|
3832
|
-
{
|
|
3833
|
-
type: "text",
|
|
3834
|
-
text: {
|
|
3835
|
-
annotations: [],
|
|
3836
|
-
value: message.content
|
|
3837
|
-
}
|
|
3838
|
-
}
|
|
3839
|
-
],
|
|
3840
|
-
attachments: message.attachments,
|
|
3841
|
-
metadata: message.metadata,
|
|
3842
|
-
createdAt: (0, import_dayjs3.default)(initialCreatedAt).add(index, "seconds").toDate()
|
|
3843
|
-
};
|
|
3844
|
-
})
|
|
3845
|
-
}
|
|
3846
|
-
})
|
|
3847
|
-
})
|
|
3956
|
+
getMessages2()
|
|
3848
3957
|
];
|
|
3849
3958
|
case 1:
|
|
3850
|
-
thread = _state.sent();
|
|
3851
3959
|
return [
|
|
3852
3960
|
2,
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
})
|
|
3961
|
+
_.apply(void 0, [
|
|
3962
|
+
_state.sent().map(function(message) {
|
|
3963
|
+
return serializeMessage4({
|
|
3964
|
+
message: message
|
|
3965
|
+
});
|
|
3966
|
+
})
|
|
3967
|
+
])
|
|
3861
3968
|
];
|
|
3862
3969
|
}
|
|
3863
3970
|
});
|
|
3864
3971
|
});
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
var threads = function(param) {
|
|
3868
|
-
var prisma = param.prisma;
|
|
3869
|
-
return {
|
|
3870
|
-
post: post10({
|
|
3871
|
-
prisma: prisma
|
|
3872
|
-
})
|
|
3873
|
-
};
|
|
3874
|
-
};
|
|
3875
|
-
// src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
|
|
3876
|
-
var import_radash8 = require("radash");
|
|
3877
|
-
// src/adapters/storage/prismaStorageAdapter/threads/messages/serializeMessage.ts
|
|
3878
|
-
var import_dayjs4 = __toESM(require("dayjs"), 1);
|
|
3879
|
-
var import_radash7 = require("radash");
|
|
3880
|
-
var serializeMessage4 = function(param) {
|
|
3881
|
-
var message = param.message;
|
|
3882
|
-
var _message_metadata;
|
|
3883
|
-
return {
|
|
3884
|
-
id: message.id,
|
|
3885
|
-
object: "thread.message",
|
|
3886
|
-
created_at: (0, import_dayjs4.default)(message.createdAt).unix(),
|
|
3887
|
-
thread_id: message.threadId,
|
|
3888
|
-
completed_at: message.completedAt ? (0, import_dayjs4.default)(message.completedAt).unix() : null,
|
|
3889
|
-
incomplete_at: message.incompleteAt ? (0, import_dayjs4.default)(message.incompleteAt).unix() : null,
|
|
3890
|
-
incomplete_details: message.incompleteDetails,
|
|
3891
|
-
role: message.role.toLowerCase(),
|
|
3892
|
-
content: message.content,
|
|
3893
|
-
assistant_id: message.assistantId,
|
|
3894
|
-
run_id: message.runId,
|
|
3895
|
-
attachments: message.attachments,
|
|
3896
|
-
status: message.status.toLowerCase(),
|
|
3897
|
-
metadata: (0, import_radash7.assign)((_message_metadata = message.metadata) !== null && _message_metadata !== void 0 ? _message_metadata : {}, message.toolCalls ? {
|
|
3898
|
-
toolCalls: message.toolCalls
|
|
3899
|
-
} : {})
|
|
3972
|
+
return function messages2(_) {
|
|
3973
|
+
return _ref.apply(this, arguments);
|
|
3900
3974
|
};
|
|
3901
|
-
};
|
|
3902
|
-
// src/adapters/
|
|
3903
|
-
var
|
|
3904
|
-
var content = param.content;
|
|
3905
|
-
if ((0, import_radash8.isArray)(content)) {
|
|
3906
|
-
return content.map(function(item) {
|
|
3907
|
-
if (item.type === "text") {
|
|
3908
|
-
var _item_text;
|
|
3909
|
-
return {
|
|
3910
|
-
type: "text",
|
|
3911
|
-
text: {
|
|
3912
|
-
value: (_item_text = item.text) !== null && _item_text !== void 0 ? _item_text : "",
|
|
3913
|
-
annotations: []
|
|
3914
|
-
}
|
|
3915
|
-
};
|
|
3916
|
-
}
|
|
3917
|
-
return item;
|
|
3918
|
-
});
|
|
3919
|
-
}
|
|
3920
|
-
return [
|
|
3921
|
-
{
|
|
3922
|
-
type: "text",
|
|
3923
|
-
text: {
|
|
3924
|
-
value: content !== null && content !== void 0 ? content : "",
|
|
3925
|
-
annotations: []
|
|
3926
|
-
}
|
|
3927
|
-
}
|
|
3928
|
-
];
|
|
3929
|
-
};
|
|
3930
|
-
var post11 = function(param) {
|
|
3931
|
-
var prisma = param.prisma;
|
|
3975
|
+
}();
|
|
3976
|
+
// src/adapters/run/responsesRunAdapter/index.ts
|
|
3977
|
+
var responsesRunAdapter = function() {
|
|
3932
3978
|
return /*#__PURE__*/ function() {
|
|
3933
|
-
var _ref = _async_to_generator(function(
|
|
3934
|
-
var
|
|
3979
|
+
var _ref = _async_to_generator(function(param) {
|
|
3980
|
+
var clientAdapter, run3, onEvent2, getMessages2, getThread2, client, thread, _thread_openaiConversationId, openaiConversationId, input, mappedTools, opts, providerResponse, e, _e_cause, _e_message, _e_cause_message, msg, message, toolCallsRunStep, currentContent, currentToolCalls, toolCallsByItemId, newConversationId, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, _ret, err, _run3_metadata, _run3_metadata1, _message_tool_calls;
|
|
3935
3981
|
return _ts_generator(this, function(_state) {
|
|
3936
3982
|
switch(_state.label){
|
|
3937
3983
|
case 0:
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3984
|
+
clientAdapter = param.client, run3 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages, getThread2 = param.getThread;
|
|
3985
|
+
if (run3.status !== "queued") return [
|
|
3986
|
+
2
|
|
3987
|
+
];
|
|
3988
|
+
client = supercompat({
|
|
3989
|
+
client: clientAdapter
|
|
3990
|
+
});
|
|
3991
|
+
onEvent2({
|
|
3992
|
+
event: "thread.run.in_progress",
|
|
3993
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
3994
|
+
status: "in_progress"
|
|
3995
|
+
})
|
|
3996
|
+
});
|
|
3997
|
+
return [
|
|
3998
|
+
4,
|
|
3999
|
+
getThread2()
|
|
4000
|
+
];
|
|
4001
|
+
case 1:
|
|
4002
|
+
thread = _state.sent();
|
|
4003
|
+
openaiConversationId = (_thread_openaiConversationId = thread === null || thread === void 0 ? void 0 : thread.openaiConversationId) !== null && _thread_openaiConversationId !== void 0 ? _thread_openaiConversationId : void 0;
|
|
4004
|
+
return [
|
|
4005
|
+
4,
|
|
4006
|
+
messages2({
|
|
4007
|
+
run: run3,
|
|
4008
|
+
getMessages: getMessages2
|
|
4009
|
+
})
|
|
4010
|
+
];
|
|
4011
|
+
case 2:
|
|
4012
|
+
input = _state.sent();
|
|
4013
|
+
mappedTools = (run3.tools || []).map(function(t) {
|
|
4014
|
+
return t.type === "function" ? {
|
|
4015
|
+
type: "function",
|
|
4016
|
+
name: t.function.name,
|
|
4017
|
+
description: t.function.description,
|
|
4018
|
+
parameters: t.function.parameters
|
|
4019
|
+
} : t;
|
|
4020
|
+
});
|
|
4021
|
+
opts = _object_spread({
|
|
4022
|
+
model: run3.model,
|
|
4023
|
+
input: input
|
|
4024
|
+
}, run3.instructions ? {
|
|
4025
|
+
instructions: run3.instructions
|
|
4026
|
+
} : {}, (0, import_radash8.isEmpty)(mappedTools) ? {} : {
|
|
4027
|
+
tools: mappedTools
|
|
4028
|
+
}, _type_of(run3.response_format) === "object" && run3.response_format.type && run3.response_format.type !== "text" ? {
|
|
4029
|
+
response_format: run3.response_format
|
|
4030
|
+
} : {});
|
|
4031
|
+
_state.label = 3;
|
|
4032
|
+
case 3:
|
|
4033
|
+
_state.trys.push([
|
|
4034
|
+
3,
|
|
4035
|
+
5,
|
|
4036
|
+
,
|
|
4037
|
+
6
|
|
4038
|
+
]);
|
|
4039
|
+
return [
|
|
4040
|
+
4,
|
|
4041
|
+
client.responses.create(_object_spread_props(_object_spread({}, opts, openaiConversationId ? {
|
|
4042
|
+
conversation: openaiConversationId
|
|
4043
|
+
} : {}), {
|
|
4044
|
+
stream: true
|
|
4045
|
+
}))
|
|
4046
|
+
];
|
|
4047
|
+
case 4:
|
|
4048
|
+
providerResponse = _state.sent();
|
|
4049
|
+
return [
|
|
4050
|
+
3,
|
|
4051
|
+
6
|
|
4052
|
+
];
|
|
4053
|
+
case 5:
|
|
4054
|
+
e = _state.sent();
|
|
4055
|
+
msg = "".concat((_e_message = e === null || e === void 0 ? void 0 : e.message) !== null && _e_message !== void 0 ? _e_message : "", " ").concat((_e_cause_message = e === null || e === void 0 ? void 0 : (_e_cause = e.cause) === null || _e_cause === void 0 ? void 0 : _e_cause.message) !== null && _e_cause_message !== void 0 ? _e_cause_message : "").trim();
|
|
4056
|
+
console.error(e);
|
|
4057
|
+
return [
|
|
4058
|
+
2,
|
|
4059
|
+
onEvent2({
|
|
4060
|
+
event: "thread.run.failed",
|
|
4061
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
4062
|
+
failed_at: (0, import_dayjs2.default)().unix(),
|
|
4063
|
+
status: "in_progress",
|
|
4064
|
+
last_error: {
|
|
4065
|
+
code: "server_error",
|
|
4066
|
+
message: msg
|
|
4067
|
+
}
|
|
4068
|
+
})
|
|
4069
|
+
})
|
|
4070
|
+
];
|
|
4071
|
+
case 6:
|
|
4072
|
+
return [
|
|
4073
|
+
4,
|
|
4074
|
+
onEvent2({
|
|
4075
|
+
event: "thread.message.created",
|
|
4076
|
+
data: {
|
|
4077
|
+
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4078
|
+
object: "thread.message",
|
|
4079
|
+
completed_at: null,
|
|
4080
|
+
run_id: run3.id,
|
|
4081
|
+
created_at: (0, import_dayjs2.default)().unix(),
|
|
4082
|
+
assistant_id: run3.assistant_id,
|
|
4083
|
+
incomplete_at: null,
|
|
4084
|
+
incomplete_details: null,
|
|
4085
|
+
metadata: {},
|
|
4086
|
+
attachments: [],
|
|
4087
|
+
thread_id: run3.thread_id,
|
|
4088
|
+
content: [
|
|
4089
|
+
{
|
|
4090
|
+
text: {
|
|
4091
|
+
value: "",
|
|
4092
|
+
annotations: []
|
|
4093
|
+
},
|
|
4094
|
+
type: "text"
|
|
4095
|
+
}
|
|
4096
|
+
],
|
|
4097
|
+
role: "assistant",
|
|
4098
|
+
status: "in_progress"
|
|
4099
|
+
}
|
|
4100
|
+
})
|
|
4101
|
+
];
|
|
4102
|
+
case 7:
|
|
4103
|
+
message = _state.sent();
|
|
4104
|
+
onEvent2({
|
|
4105
|
+
event: "thread.run.step.created",
|
|
4106
|
+
data: {
|
|
4107
|
+
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4108
|
+
object: "thread.run.step",
|
|
4109
|
+
run_id: run3.id,
|
|
4110
|
+
assistant_id: run3.assistant_id,
|
|
4111
|
+
thread_id: run3.thread_id,
|
|
4112
|
+
type: "message_creation",
|
|
4113
|
+
status: "completed",
|
|
4114
|
+
completed_at: (0, import_dayjs2.default)().unix(),
|
|
4115
|
+
created_at: (0, import_dayjs2.default)().unix(),
|
|
4116
|
+
expired_at: null,
|
|
4117
|
+
last_error: null,
|
|
4118
|
+
metadata: {},
|
|
4119
|
+
failed_at: null,
|
|
4120
|
+
cancelled_at: null,
|
|
4121
|
+
usage: null,
|
|
4122
|
+
step_details: {
|
|
4123
|
+
type: "message_creation",
|
|
4124
|
+
message_creation: {
|
|
4125
|
+
message_id: message.id
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
}
|
|
4129
|
+
});
|
|
4130
|
+
currentContent = "";
|
|
4131
|
+
currentToolCalls = [];
|
|
4132
|
+
toolCallsByItemId = {};
|
|
4133
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
4134
|
+
_state.label = 8;
|
|
4135
|
+
case 8:
|
|
4136
|
+
_state.trys.push([
|
|
4137
|
+
8,
|
|
4138
|
+
14,
|
|
4139
|
+
15,
|
|
4140
|
+
20
|
|
4141
|
+
]);
|
|
4142
|
+
_loop = function() {
|
|
4143
|
+
var _value, event, _, _event_response, _event_response_conversation, _event_response1, _event_response_conversation_id, convId, _event_item_call_id, _ref, callId, newToolCall, _event_item_id, tc, _event_error, _run3_metadata, _event_error_message;
|
|
4144
|
+
return _ts_generator(this, function(_state) {
|
|
4145
|
+
switch(_state.label){
|
|
4146
|
+
case 0:
|
|
4147
|
+
_value = _step.value;
|
|
4148
|
+
event = _value;
|
|
4149
|
+
_ = event.type;
|
|
4150
|
+
switch(_){
|
|
4151
|
+
case "response.created":
|
|
4152
|
+
return [
|
|
4153
|
+
3,
|
|
4154
|
+
1
|
|
4155
|
+
];
|
|
4156
|
+
case "response.output_text.delta":
|
|
4157
|
+
return [
|
|
4158
|
+
3,
|
|
4159
|
+
2
|
|
4160
|
+
];
|
|
4161
|
+
case "response.output_item.added":
|
|
4162
|
+
return [
|
|
4163
|
+
3,
|
|
4164
|
+
3
|
|
4165
|
+
];
|
|
4166
|
+
case "response.function_call_arguments.delta":
|
|
4167
|
+
return [
|
|
4168
|
+
3,
|
|
4169
|
+
7
|
|
4170
|
+
];
|
|
4171
|
+
case "response.error":
|
|
4172
|
+
return [
|
|
4173
|
+
3,
|
|
4174
|
+
8
|
|
4175
|
+
];
|
|
4176
|
+
}
|
|
4177
|
+
return [
|
|
4178
|
+
3,
|
|
4179
|
+
10
|
|
4180
|
+
];
|
|
4181
|
+
case 1:
|
|
4182
|
+
{
|
|
4183
|
+
;
|
|
4184
|
+
;
|
|
4185
|
+
convId = (_event_response_conversation_id = (_event_response = event.response) === null || _event_response === void 0 ? void 0 : _event_response.conversation_id) !== null && _event_response_conversation_id !== void 0 ? _event_response_conversation_id : (_event_response1 = event.response) === null || _event_response1 === void 0 ? void 0 : (_event_response_conversation = _event_response1.conversation) === null || _event_response_conversation === void 0 ? void 0 : _event_response_conversation.id;
|
|
4186
|
+
if (convId) {
|
|
4187
|
+
newConversationId = convId;
|
|
4188
|
+
}
|
|
4189
|
+
return [
|
|
4190
|
+
3,
|
|
4191
|
+
11
|
|
4192
|
+
];
|
|
4193
|
+
}
|
|
4194
|
+
_state.label = 2;
|
|
4195
|
+
case 2:
|
|
4196
|
+
{
|
|
4197
|
+
currentContent = "".concat(currentContent).concat(event.delta);
|
|
4198
|
+
onEvent2({
|
|
4199
|
+
event: "thread.message.delta",
|
|
4200
|
+
data: {
|
|
4201
|
+
id: message.id,
|
|
4202
|
+
delta: {
|
|
4203
|
+
content: [
|
|
4204
|
+
{
|
|
4205
|
+
type: "text",
|
|
4206
|
+
index: 0,
|
|
4207
|
+
text: {
|
|
4208
|
+
value: event.delta
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
]
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
});
|
|
4215
|
+
return [
|
|
4216
|
+
3,
|
|
4217
|
+
11
|
|
4218
|
+
];
|
|
4219
|
+
}
|
|
4220
|
+
_state.label = 3;
|
|
4221
|
+
case 3:
|
|
4222
|
+
if (!(event.item.type === "function_call")) return [
|
|
4223
|
+
3,
|
|
4224
|
+
6
|
|
4225
|
+
];
|
|
4226
|
+
if (!!toolCallsRunStep) return [
|
|
4227
|
+
3,
|
|
4228
|
+
5
|
|
4229
|
+
];
|
|
4230
|
+
return [
|
|
4231
|
+
4,
|
|
4232
|
+
onEvent2({
|
|
4233
|
+
event: "thread.run.step.created",
|
|
4234
|
+
data: {
|
|
4235
|
+
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4236
|
+
object: "thread.run.step",
|
|
4237
|
+
run_id: run3.id,
|
|
4238
|
+
assistant_id: run3.assistant_id,
|
|
4239
|
+
thread_id: run3.thread_id,
|
|
4240
|
+
type: "tool_calls",
|
|
4241
|
+
status: "in_progress",
|
|
4242
|
+
completed_at: null,
|
|
4243
|
+
created_at: (0, import_dayjs2.default)().unix(),
|
|
4244
|
+
expired_at: null,
|
|
4245
|
+
last_error: null,
|
|
4246
|
+
metadata: {},
|
|
4247
|
+
failed_at: null,
|
|
4248
|
+
cancelled_at: null,
|
|
4249
|
+
usage: null,
|
|
4250
|
+
step_details: {
|
|
4251
|
+
type: "tool_calls",
|
|
4252
|
+
tool_calls: []
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4255
|
+
})
|
|
4256
|
+
];
|
|
4257
|
+
case 4:
|
|
4258
|
+
toolCallsRunStep = _state.sent();
|
|
4259
|
+
_state.label = 5;
|
|
4260
|
+
case 5:
|
|
4261
|
+
callId = (_ref = (_event_item_call_id = event.item.call_id) !== null && _event_item_call_id !== void 0 ? _event_item_call_id : event.item.id) !== null && _ref !== void 0 ? _ref : (0, import_radash8.uid)(24);
|
|
4262
|
+
newToolCall = {
|
|
4263
|
+
id: callId,
|
|
4264
|
+
type: "function",
|
|
4265
|
+
function: {
|
|
4266
|
+
name: event.item.name,
|
|
4267
|
+
arguments: ""
|
|
4268
|
+
},
|
|
4269
|
+
index: currentToolCalls.length
|
|
4270
|
+
};
|
|
4271
|
+
currentToolCalls.push(newToolCall);
|
|
4272
|
+
toolCallsByItemId[(_event_item_id = event.item.id) !== null && _event_item_id !== void 0 ? _event_item_id : callId] = newToolCall;
|
|
4273
|
+
onEvent2({
|
|
4274
|
+
event: "thread.run.step.delta",
|
|
4275
|
+
data: {
|
|
4276
|
+
object: "thread.run.step.delta",
|
|
4277
|
+
run_id: run3.id,
|
|
4278
|
+
id: toolCallsRunStep.id,
|
|
4279
|
+
delta: {
|
|
4280
|
+
step_details: {
|
|
4281
|
+
type: "tool_calls",
|
|
4282
|
+
tool_calls: [
|
|
4283
|
+
newToolCall
|
|
4284
|
+
]
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
});
|
|
4289
|
+
_state.label = 6;
|
|
4290
|
+
case 6:
|
|
4291
|
+
return [
|
|
4292
|
+
3,
|
|
4293
|
+
11
|
|
4294
|
+
];
|
|
4295
|
+
case 7:
|
|
4296
|
+
{
|
|
4297
|
+
tc = toolCallsByItemId[event.item_id] || currentToolCalls.find(function(t) {
|
|
4298
|
+
return t.id === event.item_id;
|
|
4299
|
+
});
|
|
4300
|
+
if (tc) {
|
|
4301
|
+
tc.function.arguments = "".concat(tc.function.arguments).concat(event.delta);
|
|
4302
|
+
onEvent2({
|
|
4303
|
+
event: "thread.run.step.delta",
|
|
4304
|
+
data: {
|
|
4305
|
+
object: "thread.run.step.delta",
|
|
4306
|
+
run_id: run3.id,
|
|
4307
|
+
id: toolCallsRunStep.id,
|
|
4308
|
+
delta: {
|
|
4309
|
+
step_details: {
|
|
4310
|
+
type: "tool_calls",
|
|
4311
|
+
tool_calls: [
|
|
4312
|
+
{
|
|
4313
|
+
id: tc.id,
|
|
4314
|
+
type: "function",
|
|
4315
|
+
function: {
|
|
4316
|
+
name: tc.function.name,
|
|
4317
|
+
arguments: tc.function.arguments
|
|
4318
|
+
},
|
|
4319
|
+
index: currentToolCalls.findIndex(function(t) {
|
|
4320
|
+
return t.id === tc.id;
|
|
4321
|
+
})
|
|
4322
|
+
}
|
|
4323
|
+
]
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
});
|
|
4328
|
+
}
|
|
4329
|
+
return [
|
|
4330
|
+
3,
|
|
4331
|
+
11
|
|
4332
|
+
];
|
|
4333
|
+
}
|
|
4334
|
+
_state.label = 8;
|
|
4335
|
+
case 8:
|
|
4336
|
+
return [
|
|
4337
|
+
4,
|
|
4338
|
+
onEvent2({
|
|
4339
|
+
event: "thread.run.failed",
|
|
4340
|
+
data: _object_spread_props(_object_spread({}, run3, newConversationId ? {
|
|
4341
|
+
metadata: _object_spread_props(_object_spread({}, (_run3_metadata = run3.metadata) !== null && _run3_metadata !== void 0 ? _run3_metadata : {}), {
|
|
4342
|
+
openaiConversationId: newConversationId
|
|
4343
|
+
})
|
|
4344
|
+
} : {}), {
|
|
4345
|
+
failed_at: (0, import_dayjs2.default)().unix(),
|
|
4346
|
+
status: "in_progress",
|
|
4347
|
+
last_error: {
|
|
4348
|
+
code: "server_error",
|
|
4349
|
+
message: (_event_error_message = (_event_error = event.error) === null || _event_error === void 0 ? void 0 : _event_error.message) !== null && _event_error_message !== void 0 ? _event_error_message : "unknown_error"
|
|
4350
|
+
}
|
|
4351
|
+
})
|
|
4352
|
+
})
|
|
4353
|
+
];
|
|
4354
|
+
case 9:
|
|
4355
|
+
_state.sent();
|
|
4356
|
+
return [
|
|
4357
|
+
2,
|
|
4358
|
+
{
|
|
4359
|
+
v: void void 0
|
|
4360
|
+
}
|
|
4361
|
+
];
|
|
4362
|
+
case 10:
|
|
4363
|
+
return [
|
|
4364
|
+
3,
|
|
4365
|
+
11
|
|
4366
|
+
];
|
|
4367
|
+
case 11:
|
|
4368
|
+
return [
|
|
4369
|
+
2
|
|
4370
|
+
];
|
|
4371
|
+
}
|
|
4372
|
+
});
|
|
4373
|
+
};
|
|
4374
|
+
_iterator = _async_iterator(providerResponse);
|
|
4375
|
+
_state.label = 9;
|
|
4376
|
+
case 9:
|
|
4377
|
+
return [
|
|
4378
|
+
4,
|
|
4379
|
+
_iterator.next()
|
|
4380
|
+
];
|
|
4381
|
+
case 10:
|
|
4382
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
4383
|
+
3,
|
|
4384
|
+
13
|
|
4385
|
+
];
|
|
4386
|
+
return [
|
|
4387
|
+
5,
|
|
4388
|
+
_ts_values(_loop())
|
|
4389
|
+
];
|
|
4390
|
+
case 11:
|
|
4391
|
+
_ret = _state.sent();
|
|
4392
|
+
if (_type_of(_ret) === "object") return [
|
|
4393
|
+
2,
|
|
4394
|
+
_ret.v
|
|
4395
|
+
];
|
|
4396
|
+
_state.label = 12;
|
|
4397
|
+
case 12:
|
|
4398
|
+
_iteratorAbruptCompletion = false;
|
|
4399
|
+
return [
|
|
4400
|
+
3,
|
|
4401
|
+
9
|
|
4402
|
+
];
|
|
4403
|
+
case 13:
|
|
4404
|
+
return [
|
|
4405
|
+
3,
|
|
4406
|
+
20
|
|
4407
|
+
];
|
|
4408
|
+
case 14:
|
|
4409
|
+
err = _state.sent();
|
|
4410
|
+
_didIteratorError = true;
|
|
4411
|
+
_iteratorError = err;
|
|
4412
|
+
return [
|
|
4413
|
+
3,
|
|
4414
|
+
20
|
|
4415
|
+
];
|
|
4416
|
+
case 15:
|
|
4417
|
+
_state.trys.push([
|
|
4418
|
+
15,
|
|
4419
|
+
,
|
|
4420
|
+
18,
|
|
4421
|
+
19
|
|
4422
|
+
]);
|
|
4423
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
4424
|
+
3,
|
|
4425
|
+
17
|
|
4426
|
+
];
|
|
4427
|
+
return [
|
|
4428
|
+
4,
|
|
4429
|
+
_iterator.return()
|
|
4430
|
+
];
|
|
4431
|
+
case 16:
|
|
4432
|
+
_state.sent();
|
|
4433
|
+
_state.label = 17;
|
|
4434
|
+
case 17:
|
|
4435
|
+
return [
|
|
4436
|
+
3,
|
|
4437
|
+
19
|
|
4438
|
+
];
|
|
4439
|
+
case 18:
|
|
4440
|
+
if (_didIteratorError) {
|
|
4441
|
+
throw _iteratorError;
|
|
4442
|
+
}
|
|
4443
|
+
return [
|
|
4444
|
+
7
|
|
4445
|
+
];
|
|
4446
|
+
case 19:
|
|
4447
|
+
return [
|
|
4448
|
+
7
|
|
4449
|
+
];
|
|
4450
|
+
case 20:
|
|
4451
|
+
if (!((0, import_radash8.isEmpty)(currentToolCalls) && typeof providerResponse.final === "function")) return [
|
|
4452
|
+
3,
|
|
4453
|
+
22
|
|
4454
|
+
];
|
|
4455
|
+
return [
|
|
4456
|
+
4,
|
|
4457
|
+
providerResponse.final().catch(function() {})
|
|
4458
|
+
];
|
|
4459
|
+
case 21:
|
|
4460
|
+
_state.sent();
|
|
4461
|
+
_state.label = 22;
|
|
4462
|
+
case 22:
|
|
4463
|
+
return [
|
|
4464
|
+
4,
|
|
4465
|
+
onEvent2({
|
|
4466
|
+
event: "thread.message.completed",
|
|
4467
|
+
data: _object_spread_props(_object_spread({}, message), {
|
|
4468
|
+
status: "completed",
|
|
4469
|
+
content: [
|
|
4470
|
+
{
|
|
4471
|
+
text: {
|
|
4472
|
+
value: currentContent,
|
|
4473
|
+
annotations: []
|
|
4474
|
+
},
|
|
4475
|
+
type: "text"
|
|
4476
|
+
}
|
|
4477
|
+
],
|
|
4478
|
+
tool_calls: currentToolCalls
|
|
4479
|
+
})
|
|
4480
|
+
})
|
|
4481
|
+
];
|
|
4482
|
+
case 23:
|
|
4483
|
+
message = _state.sent();
|
|
4484
|
+
if ((0, import_radash8.isEmpty)(message.tool_calls)) {
|
|
4485
|
+
;
|
|
4486
|
+
return [
|
|
4487
|
+
2,
|
|
4488
|
+
onEvent2({
|
|
4489
|
+
event: "thread.run.completed",
|
|
4490
|
+
data: _object_spread(_object_spread_props(_object_spread({}, run3), {
|
|
4491
|
+
status: "completed",
|
|
4492
|
+
completed_at: (0, import_dayjs2.default)().unix()
|
|
4493
|
+
}), newConversationId ? {
|
|
4494
|
+
metadata: _object_spread_props(_object_spread({}, (_run3_metadata = run3.metadata) !== null && _run3_metadata !== void 0 ? _run3_metadata : {}), {
|
|
4495
|
+
openaiConversationId: newConversationId
|
|
4496
|
+
})
|
|
4497
|
+
} : {})
|
|
4498
|
+
})
|
|
4499
|
+
];
|
|
4500
|
+
}
|
|
4501
|
+
return [
|
|
4502
|
+
2,
|
|
4503
|
+
onEvent2({
|
|
4504
|
+
event: "thread.run.requires_action",
|
|
4505
|
+
data: _object_spread_props(_object_spread(_object_spread_props(_object_spread({}, run3), {
|
|
4506
|
+
status: "requires_action"
|
|
4507
|
+
}), newConversationId ? {
|
|
4508
|
+
metadata: _object_spread_props(_object_spread({}, (_run3_metadata1 = run3.metadata) !== null && _run3_metadata1 !== void 0 ? _run3_metadata1 : {}), {
|
|
4509
|
+
openaiConversationId: newConversationId
|
|
4510
|
+
})
|
|
4511
|
+
} : {}), {
|
|
4512
|
+
required_action: {
|
|
4513
|
+
type: "submit_tool_outputs",
|
|
4514
|
+
submit_tool_outputs: {
|
|
4515
|
+
tool_calls: (_message_tool_calls = message.tool_calls) !== null && _message_tool_calls !== void 0 ? _message_tool_calls : []
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
})
|
|
4519
|
+
})
|
|
4520
|
+
];
|
|
4521
|
+
}
|
|
4522
|
+
});
|
|
4523
|
+
});
|
|
4524
|
+
return function(_) {
|
|
4525
|
+
return _ref.apply(this, arguments);
|
|
4526
|
+
};
|
|
4527
|
+
}();
|
|
4528
|
+
};
|
|
4529
|
+
// src/lib/messages/messagesRegexp.ts
|
|
4530
|
+
var messagesRegexp = "^/(?:v1/|openai/)?threads/([^/]+)/messages$";
|
|
4531
|
+
// src/lib/runs/runsRegexp.ts
|
|
4532
|
+
var runsRegexp = "^/(?:v1/|openai/)?threads/([^/]+)/runs$";
|
|
4533
|
+
// src/lib/runs/runRegexp.ts
|
|
4534
|
+
var runRegexp = "^/(?:v1/|openai/)?threads/([^/]+)/runs/([^/]+)$";
|
|
4535
|
+
// src/lib/runs/submitToolOutputsRegexp.ts
|
|
4536
|
+
var submitToolOutputsRegexp = "^/(?:v1/|openai/)?threads/([^/]+)/runs/([^/]+)/submit_tool_outputs$";
|
|
4537
|
+
// src/lib/steps/stepsRegexp.ts
|
|
4538
|
+
var stepsRegexp = "^/(?:v1/|openai/)?threads/([^/]+)/runs/([^/]+)/steps$";
|
|
4539
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/post.ts
|
|
4540
|
+
var import_dayjs3 = __toESM(require("dayjs"), 1);
|
|
4541
|
+
var post10 = function(param) {
|
|
4542
|
+
var openai = param.openai;
|
|
4543
|
+
return /*#__PURE__*/ function() {
|
|
4544
|
+
var _ref = _async_to_generator(function(_urlString, options) {
|
|
4545
|
+
var body, oai, conversation, _conversation_created_at, thread;
|
|
4546
|
+
return _ts_generator(this, function(_state) {
|
|
4547
|
+
switch(_state.label){
|
|
4548
|
+
case 0:
|
|
4549
|
+
body = (options === null || options === void 0 ? void 0 : options.body) ? JSON.parse(options.body) : {};
|
|
4550
|
+
oai = openai;
|
|
4551
|
+
return [
|
|
4552
|
+
4,
|
|
4553
|
+
oai.conversations.create({
|
|
4554
|
+
metadata: body.metadata || {}
|
|
4555
|
+
})
|
|
4556
|
+
];
|
|
4557
|
+
case 1:
|
|
4558
|
+
conversation = _state.sent();
|
|
4559
|
+
thread = {
|
|
4560
|
+
id: conversation.id,
|
|
4561
|
+
object: "thread",
|
|
4562
|
+
created_at: (_conversation_created_at = conversation.created_at) !== null && _conversation_created_at !== void 0 ? _conversation_created_at : (0, import_dayjs3.default)().unix(),
|
|
4563
|
+
metadata: conversation.metadata || {},
|
|
4564
|
+
tool_resources: null,
|
|
4565
|
+
openaiConversationId: conversation.id
|
|
4566
|
+
};
|
|
4567
|
+
return [
|
|
4568
|
+
2,
|
|
4569
|
+
new Response(JSON.stringify(thread), {
|
|
4570
|
+
status: 200,
|
|
4571
|
+
headers: {
|
|
4572
|
+
"Content-Type": "application/json"
|
|
4573
|
+
}
|
|
4574
|
+
})
|
|
4575
|
+
];
|
|
4576
|
+
}
|
|
4577
|
+
});
|
|
4578
|
+
});
|
|
4579
|
+
return function(_urlString, options) {
|
|
4580
|
+
return _ref.apply(this, arguments);
|
|
4581
|
+
};
|
|
4582
|
+
}();
|
|
4583
|
+
};
|
|
4584
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/index.ts
|
|
4585
|
+
var threads = function(param) {
|
|
4586
|
+
var openai = param.openai;
|
|
4587
|
+
return {
|
|
4588
|
+
post: post10({
|
|
4589
|
+
openai: openai
|
|
4590
|
+
})
|
|
4591
|
+
};
|
|
4592
|
+
};
|
|
4593
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/messages/post.ts
|
|
4594
|
+
var import_dayjs4 = __toESM(require("dayjs"), 1);
|
|
4595
|
+
var post11 = function(param) {
|
|
4596
|
+
var openai = param.openai;
|
|
4597
|
+
return /*#__PURE__*/ function() {
|
|
4598
|
+
var _ref = _async_to_generator(function(urlString, options) {
|
|
4599
|
+
var url, _url_pathname_match, threadId, body, content, oai;
|
|
4600
|
+
return _ts_generator(this, function(_state) {
|
|
4601
|
+
switch(_state.label){
|
|
4602
|
+
case 0:
|
|
4603
|
+
url = new URL(urlString);
|
|
4604
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
4605
|
+
body = JSON.parse(options.body);
|
|
4606
|
+
content = typeof body.content === "string" ? body.content : "";
|
|
4607
|
+
oai = openai;
|
|
4608
|
+
return [
|
|
4609
|
+
4,
|
|
4610
|
+
oai.conversations.items.create(threadId, {
|
|
4611
|
+
items: [
|
|
4612
|
+
{
|
|
4613
|
+
type: "message",
|
|
4614
|
+
role: body.role,
|
|
4615
|
+
content: [
|
|
4616
|
+
{
|
|
4617
|
+
type: "input_text",
|
|
4618
|
+
text: content
|
|
4619
|
+
}
|
|
4620
|
+
]
|
|
4621
|
+
}
|
|
4622
|
+
]
|
|
4623
|
+
})
|
|
4624
|
+
];
|
|
4625
|
+
case 1:
|
|
4626
|
+
_state.sent();
|
|
4627
|
+
return [
|
|
4628
|
+
2,
|
|
4629
|
+
new Response(JSON.stringify({
|
|
4630
|
+
id: "msg_".concat(Date.now()),
|
|
4631
|
+
object: "thread.message",
|
|
4632
|
+
created_at: (0, import_dayjs4.default)().unix(),
|
|
4633
|
+
thread_id: threadId,
|
|
4634
|
+
role: body.role,
|
|
4635
|
+
content: [
|
|
4636
|
+
{
|
|
4637
|
+
type: "text",
|
|
4638
|
+
text: {
|
|
4639
|
+
value: content,
|
|
4640
|
+
annotations: []
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
],
|
|
4644
|
+
metadata: body.metadata || {},
|
|
4645
|
+
assistant_id: null,
|
|
4646
|
+
run_id: null,
|
|
4647
|
+
attachments: [],
|
|
4648
|
+
status: "completed",
|
|
4649
|
+
completed_at: (0, import_dayjs4.default)().unix(),
|
|
4650
|
+
incomplete_at: null,
|
|
4651
|
+
incomplete_details: null
|
|
4652
|
+
}), {
|
|
4653
|
+
status: 200,
|
|
4654
|
+
headers: {
|
|
4655
|
+
"Content-Type": "application/json"
|
|
4656
|
+
}
|
|
4657
|
+
})
|
|
4658
|
+
];
|
|
4659
|
+
}
|
|
4660
|
+
});
|
|
4661
|
+
});
|
|
4662
|
+
return function(urlString, options) {
|
|
4663
|
+
return _ref.apply(this, arguments);
|
|
4664
|
+
};
|
|
4665
|
+
}();
|
|
4666
|
+
};
|
|
4667
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/messages/list.ts
|
|
4668
|
+
var import_dayjs5 = __toESM(require("dayjs"), 1);
|
|
4669
|
+
var list = function(param) {
|
|
4670
|
+
var openai = param.openai;
|
|
4671
|
+
return /*#__PURE__*/ function() {
|
|
4672
|
+
var _ref = _async_to_generator(function(urlString) {
|
|
4673
|
+
var url, _url_pathname_match, threadId, oai, items, messages5, _items_has_more;
|
|
4674
|
+
return _ts_generator(this, function(_state) {
|
|
4675
|
+
switch(_state.label){
|
|
4676
|
+
case 0:
|
|
4677
|
+
url = new URL(urlString);
|
|
4678
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
4679
|
+
oai = openai;
|
|
4680
|
+
return [
|
|
4681
|
+
4,
|
|
4682
|
+
oai.conversations.items.list(threadId)
|
|
4683
|
+
];
|
|
4684
|
+
case 1:
|
|
4685
|
+
items = _state.sent();
|
|
4686
|
+
messages5 = (items.data || []).filter(function(item) {
|
|
4687
|
+
return item.type === "message";
|
|
4688
|
+
}).map(function(item) {
|
|
4689
|
+
var _item_created_at, _item_completed_at;
|
|
4690
|
+
return {
|
|
4691
|
+
id: item.id,
|
|
4692
|
+
object: "thread.message",
|
|
4693
|
+
created_at: (_item_created_at = item.created_at) !== null && _item_created_at !== void 0 ? _item_created_at : (0, import_dayjs5.default)().unix(),
|
|
4694
|
+
thread_id: threadId,
|
|
4695
|
+
role: item.role,
|
|
4696
|
+
content: (item.content || []).map(function(c) {
|
|
4697
|
+
return {
|
|
4698
|
+
type: "text",
|
|
4699
|
+
text: {
|
|
4700
|
+
value: c.text,
|
|
4701
|
+
annotations: []
|
|
4702
|
+
}
|
|
4703
|
+
};
|
|
4704
|
+
}),
|
|
4705
|
+
metadata: {},
|
|
4706
|
+
assistant_id: null,
|
|
4707
|
+
run_id: null,
|
|
4708
|
+
attachments: [],
|
|
4709
|
+
status: "completed",
|
|
4710
|
+
completed_at: (_item_completed_at = item.completed_at) !== null && _item_completed_at !== void 0 ? _item_completed_at : (0, import_dayjs5.default)().unix(),
|
|
4711
|
+
incomplete_at: null,
|
|
4712
|
+
incomplete_details: null
|
|
4713
|
+
};
|
|
4714
|
+
});
|
|
4715
|
+
return [
|
|
4716
|
+
2,
|
|
4717
|
+
new Response(JSON.stringify({
|
|
4718
|
+
object: "list",
|
|
4719
|
+
data: messages5,
|
|
4720
|
+
has_more: (_items_has_more = items.has_more) !== null && _items_has_more !== void 0 ? _items_has_more : false
|
|
4721
|
+
}), {
|
|
4722
|
+
status: 200,
|
|
4723
|
+
headers: {
|
|
4724
|
+
"Content-Type": "application/json"
|
|
4725
|
+
}
|
|
4726
|
+
})
|
|
4727
|
+
];
|
|
4728
|
+
}
|
|
4729
|
+
});
|
|
4730
|
+
});
|
|
4731
|
+
return function(urlString) {
|
|
4732
|
+
return _ref.apply(this, arguments);
|
|
4733
|
+
};
|
|
4734
|
+
}();
|
|
4735
|
+
};
|
|
4736
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/messages/index.ts
|
|
4737
|
+
var messages3 = function(param) {
|
|
4738
|
+
var openai = param.openai;
|
|
4739
|
+
return {
|
|
4740
|
+
post: post11({
|
|
4741
|
+
openai: openai
|
|
4742
|
+
}),
|
|
4743
|
+
get: list({
|
|
4744
|
+
openai: openai
|
|
4745
|
+
})
|
|
4746
|
+
};
|
|
4747
|
+
};
|
|
4748
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/post.ts
|
|
4749
|
+
var import_dayjs6 = __toESM(require("dayjs"), 1);
|
|
4750
|
+
var import_radash9 = require("radash");
|
|
4751
|
+
var post12 = function(param) {
|
|
4752
|
+
var openai = param.openai, runAdapter = param.runAdapter;
|
|
4753
|
+
return /*#__PURE__*/ function() {
|
|
4754
|
+
var _ref = _async_to_generator(function(urlString, options) {
|
|
4755
|
+
var url, _url_pathname_match, threadId, body, assistant_id, stream, oai, conversation, _conversation_metadata, metadata, openaiConversationId, _conversation_created_at, thread, assistant, run3, runSteps, onEvent2, getThread2, getMessages2, saveRun, readableStream;
|
|
4756
|
+
return _ts_generator(this, function(_state) {
|
|
4757
|
+
switch(_state.label){
|
|
4758
|
+
case 0:
|
|
4759
|
+
url = new URL(urlString);
|
|
4760
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
|
|
4761
|
+
body = JSON.parse(options.body);
|
|
4762
|
+
assistant_id = body.assistant_id, stream = body.stream;
|
|
4763
|
+
oai = openai;
|
|
4764
|
+
return [
|
|
4765
|
+
4,
|
|
4766
|
+
oai.conversations.retrieve(threadId).catch(function() {
|
|
4767
|
+
return null;
|
|
4768
|
+
})
|
|
4769
|
+
];
|
|
4770
|
+
case 1:
|
|
4771
|
+
conversation = _state.sent();
|
|
4772
|
+
if (!conversation) return [
|
|
4773
|
+
2,
|
|
4774
|
+
new Response("Thread not found", {
|
|
4775
|
+
status: 404
|
|
4776
|
+
})
|
|
4777
|
+
];
|
|
4778
|
+
metadata = (_conversation_metadata = conversation.metadata) !== null && _conversation_metadata !== void 0 ? _conversation_metadata : {};
|
|
4779
|
+
openaiConversationId = metadata.openaiConversationId || threadId;
|
|
4780
|
+
thread = {
|
|
4781
|
+
id: threadId,
|
|
4782
|
+
object: "thread",
|
|
4783
|
+
created_at: (_conversation_created_at = conversation.created_at) !== null && _conversation_created_at !== void 0 ? _conversation_created_at : (0, import_dayjs6.default)().unix(),
|
|
4784
|
+
metadata: metadata,
|
|
4785
|
+
tool_resources: null,
|
|
4786
|
+
openaiConversationId: openaiConversationId
|
|
4787
|
+
};
|
|
4788
|
+
return [
|
|
4789
|
+
4,
|
|
4790
|
+
openai.beta.assistants.retrieve(assistant_id)
|
|
4791
|
+
];
|
|
4792
|
+
case 2:
|
|
4793
|
+
assistant = _state.sent();
|
|
4794
|
+
run3 = {
|
|
4795
|
+
id: "run_".concat((0, import_radash9.uid)(24)),
|
|
4796
|
+
object: "thread.run",
|
|
4797
|
+
created_at: (0, import_dayjs6.default)().unix(),
|
|
4798
|
+
thread_id: threadId,
|
|
4799
|
+
assistant_id: assistant_id,
|
|
4800
|
+
model: body.model || assistant.model,
|
|
4801
|
+
instructions: body.instructions || "",
|
|
4802
|
+
status: "queued",
|
|
4803
|
+
tools: body.tools || assistant.tools || [],
|
|
4804
|
+
response_format: body.response_format || {
|
|
4805
|
+
type: "text"
|
|
4806
|
+
},
|
|
4807
|
+
metadata: body.metadata || {}
|
|
4808
|
+
};
|
|
4809
|
+
runSteps = [];
|
|
4810
|
+
onEvent2 = /*#__PURE__*/ function() {
|
|
4811
|
+
var _ref = _async_to_generator(function(event) {
|
|
4812
|
+
var _event_data_metadata, _event_data, step, step1, _delta_step_details, delta, calls, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, conv;
|
|
4813
|
+
return _ts_generator(this, function(_state) {
|
|
4814
|
+
if (event.event === "thread.run.completed") {
|
|
4815
|
+
run3 = _object_spread_props(_object_spread({}, run3), {
|
|
4816
|
+
status: "completed"
|
|
4817
|
+
});
|
|
4818
|
+
} else if (event.event === "thread.run.failed") {
|
|
4819
|
+
run3 = _object_spread_props(_object_spread({}, run3), {
|
|
4820
|
+
status: "failed",
|
|
4821
|
+
last_error: event.data.last_error
|
|
4822
|
+
});
|
|
4823
|
+
} else if (event.event === "thread.run.requires_action") {
|
|
4824
|
+
run3 = _object_spread_props(_object_spread({}, run3), {
|
|
4825
|
+
status: "requires_action",
|
|
4826
|
+
required_action: event.data.required_action
|
|
4827
|
+
});
|
|
4828
|
+
} else if (event.event === "thread.run.step.created") {
|
|
4829
|
+
step = _object_spread_props(_object_spread({}, event.data), {
|
|
4830
|
+
id: "run_step_".concat((0, import_radash9.uid)(24))
|
|
4831
|
+
});
|
|
4832
|
+
runSteps.push(step);
|
|
4833
|
+
return [
|
|
4834
|
+
2,
|
|
4835
|
+
step
|
|
4836
|
+
];
|
|
4837
|
+
} else if (event.event === "thread.run.step.delta") {
|
|
4838
|
+
step1 = runSteps.find(function(s) {
|
|
4839
|
+
return s.id === event.data.id;
|
|
4840
|
+
});
|
|
4841
|
+
if (step1) {
|
|
4842
|
+
;
|
|
4843
|
+
delta = event.data.delta;
|
|
4844
|
+
if (((_delta_step_details = delta.step_details) === null || _delta_step_details === void 0 ? void 0 : _delta_step_details.type) === "tool_calls") {
|
|
4845
|
+
step1.step_details = step1.step_details || {
|
|
4846
|
+
type: "tool_calls",
|
|
4847
|
+
tool_calls: []
|
|
4848
|
+
};
|
|
4849
|
+
calls = delta.step_details.tool_calls || [];
|
|
4850
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
4851
|
+
try {
|
|
4852
|
+
_loop = function() {
|
|
4853
|
+
var call = _step.value;
|
|
4854
|
+
var existingIndex = step1.step_details.tool_calls.findIndex(function(c) {
|
|
4855
|
+
return c.id === call.id;
|
|
4856
|
+
});
|
|
4857
|
+
if (existingIndex === -1) {
|
|
4858
|
+
;
|
|
4859
|
+
step1.step_details.tool_calls.push(call);
|
|
4860
|
+
} else {
|
|
4861
|
+
var existing = step1.step_details.tool_calls[existingIndex];
|
|
4862
|
+
step1.step_details.tool_calls[existingIndex] = _object_spread_props(_object_spread({}, existing, call), {
|
|
4863
|
+
function: _object_spread({}, existing.function, call.function)
|
|
4864
|
+
});
|
|
4865
|
+
}
|
|
4866
|
+
};
|
|
4867
|
+
for(_iterator = calls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
4868
|
+
} catch (err) {
|
|
4869
|
+
_didIteratorError = true;
|
|
4870
|
+
_iteratorError = err;
|
|
4871
|
+
} finally{
|
|
4872
|
+
try {
|
|
4873
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
4874
|
+
_iterator.return();
|
|
4875
|
+
}
|
|
4876
|
+
} finally{
|
|
4877
|
+
if (_didIteratorError) {
|
|
4878
|
+
throw _iteratorError;
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
return [
|
|
4885
|
+
2,
|
|
4886
|
+
event.data
|
|
4887
|
+
];
|
|
4888
|
+
}
|
|
4889
|
+
conv = (_event_data = event.data) === null || _event_data === void 0 ? void 0 : (_event_data_metadata = _event_data.metadata) === null || _event_data_metadata === void 0 ? void 0 : _event_data_metadata.openaiConversationId;
|
|
4890
|
+
if (conv && conv !== thread.openaiConversationId) {
|
|
4891
|
+
thread.openaiConversationId = conv;
|
|
4892
|
+
}
|
|
4893
|
+
return [
|
|
4894
|
+
2,
|
|
4895
|
+
event.data
|
|
4896
|
+
];
|
|
4897
|
+
});
|
|
4898
|
+
});
|
|
4899
|
+
return function onEvent2(event) {
|
|
4900
|
+
return _ref.apply(this, arguments);
|
|
4901
|
+
};
|
|
4902
|
+
}();
|
|
4903
|
+
getThread2 = /*#__PURE__*/ function() {
|
|
4904
|
+
var _ref = _async_to_generator(function() {
|
|
4905
|
+
return _ts_generator(this, function(_state) {
|
|
4906
|
+
return [
|
|
4907
|
+
2,
|
|
4908
|
+
thread
|
|
4909
|
+
];
|
|
4910
|
+
});
|
|
4911
|
+
});
|
|
4912
|
+
return function getThread2() {
|
|
4913
|
+
return _ref.apply(this, arguments);
|
|
4914
|
+
};
|
|
4915
|
+
}();
|
|
4916
|
+
getMessages2 = /*#__PURE__*/ function() {
|
|
4917
|
+
var _ref = _async_to_generator(function() {
|
|
4918
|
+
return _ts_generator(this, function(_state) {
|
|
4919
|
+
return [
|
|
4920
|
+
2,
|
|
4921
|
+
[]
|
|
4922
|
+
];
|
|
4923
|
+
});
|
|
4924
|
+
});
|
|
4925
|
+
return function getMessages2() {
|
|
4926
|
+
return _ref.apply(this, arguments);
|
|
4927
|
+
};
|
|
4928
|
+
}();
|
|
4929
|
+
saveRun = /*#__PURE__*/ function() {
|
|
4930
|
+
var _ref = _async_to_generator(function() {
|
|
4931
|
+
var storedRun, metadata2, storedSteps;
|
|
4932
|
+
return _ts_generator(this, function(_state) {
|
|
4933
|
+
switch(_state.label){
|
|
4934
|
+
case 0:
|
|
4935
|
+
if (run3.status !== "requires_action") {
|
|
4936
|
+
delete run3.required_action;
|
|
4937
|
+
}
|
|
4938
|
+
storedRun = {
|
|
4939
|
+
id: run3.id,
|
|
4940
|
+
assistant_id: run3.assistant_id,
|
|
4941
|
+
thread_id: run3.thread_id,
|
|
4942
|
+
model: run3.model,
|
|
4943
|
+
instructions: run3.instructions,
|
|
4944
|
+
response_format: run3.response_format,
|
|
4945
|
+
status: run3.status
|
|
4946
|
+
};
|
|
4947
|
+
metadata2 = thread.metadata;
|
|
4948
|
+
metadata2["run_".concat(run3.id)] = JSON.stringify(storedRun);
|
|
4949
|
+
if (run3.tools && run3.tools.length > 0) {
|
|
4950
|
+
metadata2["run_".concat(run3.id, "_tools")] = JSON.stringify(run3.tools);
|
|
4951
|
+
}
|
|
4952
|
+
if (runSteps.length > 0) {
|
|
4953
|
+
storedSteps = runSteps.filter(function(s) {
|
|
4954
|
+
return s.type === "tool_calls";
|
|
4955
|
+
}).map(function(s) {
|
|
4956
|
+
var _s_step_details_tool_calls;
|
|
4957
|
+
return {
|
|
4958
|
+
id: s.id,
|
|
4959
|
+
type: s.type,
|
|
4960
|
+
status: s.status,
|
|
4961
|
+
created_at: s.created_at,
|
|
4962
|
+
step_details: {
|
|
4963
|
+
type: "tool_calls",
|
|
4964
|
+
tool_calls: (_s_step_details_tool_calls = s.step_details.tool_calls) === null || _s_step_details_tool_calls === void 0 ? void 0 : _s_step_details_tool_calls.map(function(tc) {
|
|
4965
|
+
return {
|
|
4966
|
+
id: tc.id,
|
|
4967
|
+
type: tc.type,
|
|
4968
|
+
function: {
|
|
4969
|
+
name: tc.function.name
|
|
4970
|
+
}
|
|
4971
|
+
};
|
|
4972
|
+
})
|
|
4973
|
+
}
|
|
4974
|
+
};
|
|
4975
|
+
});
|
|
4976
|
+
metadata2["run_".concat(run3.id, "_steps")] = JSON.stringify(storedSteps);
|
|
4977
|
+
}
|
|
4978
|
+
if (run3.required_action) {
|
|
4979
|
+
metadata2["run_".concat(run3.id, "_required_action")] = JSON.stringify(run3.required_action);
|
|
4980
|
+
}
|
|
4981
|
+
metadata2.openaiConversationId = thread.openaiConversationId;
|
|
4982
|
+
thread.metadata = metadata2;
|
|
4983
|
+
return [
|
|
4984
|
+
4,
|
|
4985
|
+
oai.conversations.update(thread.openaiConversationId, {
|
|
4986
|
+
metadata: metadata2
|
|
4987
|
+
})
|
|
4988
|
+
];
|
|
4989
|
+
case 1:
|
|
4990
|
+
_state.sent();
|
|
4991
|
+
return [
|
|
4992
|
+
2
|
|
4993
|
+
];
|
|
4994
|
+
}
|
|
4995
|
+
});
|
|
4996
|
+
});
|
|
4997
|
+
return function saveRun() {
|
|
4998
|
+
return _ref.apply(this, arguments);
|
|
4999
|
+
};
|
|
5000
|
+
}();
|
|
5001
|
+
if (stream) {
|
|
5002
|
+
readableStream = new ReadableStream({
|
|
5003
|
+
start: function start(controller) {
|
|
5004
|
+
return _async_to_generator(function() {
|
|
5005
|
+
return _ts_generator(this, function(_state) {
|
|
5006
|
+
switch(_state.label){
|
|
5007
|
+
case 0:
|
|
5008
|
+
return [
|
|
5009
|
+
4,
|
|
5010
|
+
runAdapter({
|
|
5011
|
+
run: run3,
|
|
5012
|
+
onEvent: function(event) {
|
|
5013
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
5014
|
+
return onEvent2(event);
|
|
5015
|
+
},
|
|
5016
|
+
getMessages: getMessages2,
|
|
5017
|
+
getThread: getThread2
|
|
5018
|
+
})
|
|
5019
|
+
];
|
|
5020
|
+
case 1:
|
|
5021
|
+
_state.sent();
|
|
5022
|
+
return [
|
|
5023
|
+
4,
|
|
5024
|
+
saveRun()
|
|
5025
|
+
];
|
|
5026
|
+
case 2:
|
|
5027
|
+
_state.sent();
|
|
5028
|
+
controller.close();
|
|
5029
|
+
return [
|
|
5030
|
+
2
|
|
5031
|
+
];
|
|
5032
|
+
}
|
|
5033
|
+
});
|
|
5034
|
+
})();
|
|
5035
|
+
}
|
|
5036
|
+
});
|
|
5037
|
+
return [
|
|
5038
|
+
2,
|
|
5039
|
+
new Response(readableStream, {
|
|
5040
|
+
headers: {
|
|
5041
|
+
"Content-Type": "text/event-stream"
|
|
5042
|
+
}
|
|
5043
|
+
})
|
|
5044
|
+
];
|
|
5045
|
+
}
|
|
5046
|
+
return [
|
|
5047
|
+
4,
|
|
5048
|
+
runAdapter({
|
|
5049
|
+
run: run3,
|
|
5050
|
+
onEvent: onEvent2,
|
|
5051
|
+
getMessages: getMessages2,
|
|
5052
|
+
getThread: getThread2
|
|
5053
|
+
})
|
|
5054
|
+
];
|
|
5055
|
+
case 3:
|
|
5056
|
+
_state.sent();
|
|
5057
|
+
return [
|
|
5058
|
+
4,
|
|
5059
|
+
saveRun()
|
|
5060
|
+
];
|
|
5061
|
+
case 4:
|
|
5062
|
+
_state.sent();
|
|
5063
|
+
return [
|
|
5064
|
+
2,
|
|
5065
|
+
new Response(JSON.stringify(run3), {
|
|
5066
|
+
status: 200,
|
|
5067
|
+
headers: {
|
|
5068
|
+
"Content-Type": "application/json"
|
|
5069
|
+
}
|
|
5070
|
+
})
|
|
5071
|
+
];
|
|
5072
|
+
}
|
|
5073
|
+
});
|
|
5074
|
+
});
|
|
5075
|
+
return function(urlString, options) {
|
|
5076
|
+
return _ref.apply(this, arguments);
|
|
5077
|
+
};
|
|
5078
|
+
}();
|
|
5079
|
+
};
|
|
5080
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/get.ts
|
|
5081
|
+
var get10 = function(param) {
|
|
5082
|
+
var openai = param.openai;
|
|
5083
|
+
return /*#__PURE__*/ function() {
|
|
5084
|
+
var _ref = _async_to_generator(function(_urlString) {
|
|
5085
|
+
return _ts_generator(this, function(_state) {
|
|
5086
|
+
return [
|
|
5087
|
+
2,
|
|
5088
|
+
new Response(JSON.stringify({
|
|
5089
|
+
object: "list",
|
|
5090
|
+
data: [],
|
|
5091
|
+
has_more: false
|
|
5092
|
+
}), {
|
|
5093
|
+
status: 200,
|
|
5094
|
+
headers: {
|
|
5095
|
+
"Content-Type": "application/json"
|
|
5096
|
+
}
|
|
5097
|
+
})
|
|
5098
|
+
];
|
|
5099
|
+
});
|
|
5100
|
+
});
|
|
5101
|
+
return function(_urlString) {
|
|
5102
|
+
return _ref.apply(this, arguments);
|
|
5103
|
+
};
|
|
5104
|
+
}();
|
|
5105
|
+
};
|
|
5106
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/index.ts
|
|
5107
|
+
var runs = function(param) {
|
|
5108
|
+
var openai = param.openai, runAdapter = param.runAdapter;
|
|
5109
|
+
return {
|
|
5110
|
+
post: post12({
|
|
5111
|
+
openai: openai,
|
|
5112
|
+
runAdapter: runAdapter
|
|
5113
|
+
}),
|
|
5114
|
+
get: get10({
|
|
5115
|
+
openai: openai
|
|
5116
|
+
})
|
|
5117
|
+
};
|
|
5118
|
+
};
|
|
5119
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/run/get.ts
|
|
5120
|
+
var get11 = function(param) {
|
|
5121
|
+
var openai = param.openai;
|
|
5122
|
+
return /*#__PURE__*/ function() {
|
|
5123
|
+
var _ref = _async_to_generator(function(urlString) {
|
|
5124
|
+
var url, _url_pathname_match, threadId, runId, conversation, metadata, runStr, toolsStr, raStr, run3;
|
|
5125
|
+
return _ts_generator(this, function(_state) {
|
|
5126
|
+
switch(_state.label){
|
|
5127
|
+
case 0:
|
|
5128
|
+
url = new URL(urlString);
|
|
5129
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
5130
|
+
return [
|
|
5131
|
+
4,
|
|
5132
|
+
openai.conversations.retrieve(threadId).catch(function() {
|
|
5133
|
+
return null;
|
|
5134
|
+
})
|
|
5135
|
+
];
|
|
5136
|
+
case 1:
|
|
5137
|
+
conversation = _state.sent();
|
|
5138
|
+
metadata = conversation === null || conversation === void 0 ? void 0 : conversation.metadata;
|
|
5139
|
+
runStr = metadata === null || metadata === void 0 ? void 0 : metadata["run_".concat(runId)];
|
|
5140
|
+
toolsStr = metadata === null || metadata === void 0 ? void 0 : metadata["run_".concat(runId, "_tools")];
|
|
5141
|
+
raStr = metadata === null || metadata === void 0 ? void 0 : metadata["run_".concat(runId, "_required_action")];
|
|
5142
|
+
run3 = runStr ? _object_spread(_object_spread_props(_object_spread({}, JSON.parse(runStr)), {
|
|
5143
|
+
tools: toolsStr ? JSON.parse(toolsStr) : []
|
|
5144
|
+
}), raStr ? {
|
|
5145
|
+
required_action: JSON.parse(raStr)
|
|
5146
|
+
} : {}) : null;
|
|
5147
|
+
return [
|
|
5148
|
+
2,
|
|
5149
|
+
new Response(JSON.stringify(run3 !== null && run3 !== void 0 ? run3 : null), {
|
|
5150
|
+
status: run3 ? 200 : 404,
|
|
5151
|
+
headers: {
|
|
5152
|
+
"Content-Type": "application/json",
|
|
5153
|
+
"openai-poll-after-ms": "5000"
|
|
5154
|
+
}
|
|
5155
|
+
})
|
|
5156
|
+
];
|
|
5157
|
+
}
|
|
5158
|
+
});
|
|
5159
|
+
});
|
|
5160
|
+
return function(urlString) {
|
|
5161
|
+
return _ref.apply(this, arguments);
|
|
5162
|
+
};
|
|
5163
|
+
}();
|
|
5164
|
+
};
|
|
5165
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/run/index.ts
|
|
5166
|
+
var run = function(param) {
|
|
5167
|
+
var openai = param.openai;
|
|
5168
|
+
return {
|
|
5169
|
+
get: get11({
|
|
5170
|
+
openai: openai
|
|
5171
|
+
})
|
|
5172
|
+
};
|
|
5173
|
+
};
|
|
5174
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
|
|
5175
|
+
var import_dayjs7 = __toESM(require("dayjs"), 1);
|
|
5176
|
+
var post13 = function(param) {
|
|
5177
|
+
var openai = param.openai, runAdapter = param.runAdapter;
|
|
5178
|
+
return /*#__PURE__*/ function() {
|
|
5179
|
+
var _ref = _async_to_generator(function(urlString, options) {
|
|
5180
|
+
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, oai, conversation, _conversation_metadata, metadata, openaiConversationId, _conversation_created_at, thread, runStr, toolsStr, raStr, run3, saveRun, readableStream;
|
|
5181
|
+
return _ts_generator(this, function(_state) {
|
|
5182
|
+
switch(_state.label){
|
|
5183
|
+
case 0:
|
|
5184
|
+
url = new URL(urlString);
|
|
5185
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(submitToolOutputsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
5186
|
+
body = JSON.parse(options.body);
|
|
5187
|
+
tool_outputs = body.tool_outputs, stream = body.stream;
|
|
5188
|
+
oai = openai;
|
|
5189
|
+
return [
|
|
5190
|
+
4,
|
|
5191
|
+
oai.conversations.retrieve(threadId).catch(function() {
|
|
5192
|
+
return null;
|
|
5193
|
+
})
|
|
5194
|
+
];
|
|
5195
|
+
case 1:
|
|
5196
|
+
conversation = _state.sent();
|
|
5197
|
+
if (!conversation) return [
|
|
5198
|
+
2,
|
|
5199
|
+
new Response("Not found", {
|
|
5200
|
+
status: 404
|
|
5201
|
+
})
|
|
5202
|
+
];
|
|
5203
|
+
metadata = (_conversation_metadata = conversation.metadata) !== null && _conversation_metadata !== void 0 ? _conversation_metadata : {};
|
|
5204
|
+
openaiConversationId = metadata.openaiConversationId || threadId;
|
|
5205
|
+
thread = {
|
|
5206
|
+
id: threadId,
|
|
5207
|
+
object: "thread",
|
|
5208
|
+
created_at: (_conversation_created_at = conversation.created_at) !== null && _conversation_created_at !== void 0 ? _conversation_created_at : (0, import_dayjs7.default)().unix(),
|
|
5209
|
+
metadata: metadata,
|
|
5210
|
+
tool_resources: null,
|
|
5211
|
+
openaiConversationId: openaiConversationId
|
|
5212
|
+
};
|
|
5213
|
+
runStr = metadata["run_".concat(runId)];
|
|
5214
|
+
toolsStr = metadata["run_".concat(runId, "_tools")];
|
|
5215
|
+
raStr = metadata["run_".concat(runId, "_required_action")];
|
|
5216
|
+
run3 = runStr ? _object_spread(_object_spread_props(_object_spread({}, JSON.parse(runStr)), {
|
|
5217
|
+
tools: toolsStr ? JSON.parse(toolsStr) : []
|
|
5218
|
+
}), raStr ? {
|
|
5219
|
+
required_action: JSON.parse(raStr)
|
|
5220
|
+
} : {}) : void 0;
|
|
5221
|
+
if (!run3) return [
|
|
5222
|
+
2,
|
|
5223
|
+
new Response("Not found", {
|
|
5224
|
+
status: 404
|
|
5225
|
+
})
|
|
5226
|
+
];
|
|
5227
|
+
run3.status = "completed";
|
|
5228
|
+
run3.required_action = null;
|
|
5229
|
+
run3.last_error = null;
|
|
5230
|
+
if (!(tool_outputs && tool_outputs.length > 0)) return [
|
|
5231
|
+
3,
|
|
5232
|
+
3
|
|
5233
|
+
];
|
|
5234
|
+
return [
|
|
5235
|
+
4,
|
|
5236
|
+
oai.conversations.items.create(thread.openaiConversationId, {
|
|
5237
|
+
items: _to_consumable_array(tool_outputs.map(function(t) {
|
|
5238
|
+
return {
|
|
5239
|
+
type: "function_call_output",
|
|
5240
|
+
call_id: t.tool_call_id,
|
|
5241
|
+
output: typeof t.output === "string" ? t.output : JSON.stringify(t.output)
|
|
5242
|
+
};
|
|
5243
|
+
})).concat([
|
|
5244
|
+
{
|
|
5245
|
+
type: "message",
|
|
5246
|
+
role: "assistant",
|
|
5247
|
+
content: [
|
|
5248
|
+
{
|
|
5249
|
+
type: "output_text",
|
|
5250
|
+
text: tool_outputs[0].output
|
|
5251
|
+
}
|
|
5252
|
+
]
|
|
5253
|
+
}
|
|
5254
|
+
])
|
|
5255
|
+
})
|
|
5256
|
+
];
|
|
5257
|
+
case 2:
|
|
5258
|
+
_state.sent();
|
|
5259
|
+
_state.label = 3;
|
|
5260
|
+
case 3:
|
|
5261
|
+
saveRun = /*#__PURE__*/ function() {
|
|
5262
|
+
var _ref = _async_to_generator(function() {
|
|
5263
|
+
var storedRun;
|
|
5264
|
+
return _ts_generator(this, function(_state) {
|
|
5265
|
+
switch(_state.label){
|
|
5266
|
+
case 0:
|
|
5267
|
+
if (run3.status !== "requires_action") {
|
|
5268
|
+
run3.required_action = null;
|
|
5269
|
+
}
|
|
5270
|
+
storedRun = {
|
|
5271
|
+
id: run3.id,
|
|
5272
|
+
assistant_id: run3.assistant_id,
|
|
5273
|
+
thread_id: run3.thread_id,
|
|
5274
|
+
model: run3.model,
|
|
5275
|
+
instructions: run3.instructions,
|
|
5276
|
+
response_format: run3.response_format,
|
|
5277
|
+
status: run3.status
|
|
5278
|
+
};
|
|
5279
|
+
metadata["run_".concat(run3.id)] = JSON.stringify(storedRun);
|
|
5280
|
+
if (run3.tools && run3.tools.length > 0) {
|
|
5281
|
+
metadata["run_".concat(run3.id, "_tools")] = JSON.stringify(run3.tools);
|
|
5282
|
+
}
|
|
5283
|
+
if (run3.required_action) {
|
|
5284
|
+
metadata["run_".concat(run3.id, "_required_action")] = JSON.stringify(run3.required_action);
|
|
5285
|
+
} else {
|
|
5286
|
+
delete metadata["run_".concat(run3.id, "_required_action")];
|
|
5287
|
+
}
|
|
5288
|
+
metadata.openaiConversationId = thread.openaiConversationId;
|
|
5289
|
+
thread.metadata = metadata;
|
|
5290
|
+
return [
|
|
5291
|
+
4,
|
|
5292
|
+
oai.conversations.update(thread.openaiConversationId, {
|
|
5293
|
+
metadata: metadata
|
|
5294
|
+
})
|
|
5295
|
+
];
|
|
5296
|
+
case 1:
|
|
5297
|
+
_state.sent();
|
|
5298
|
+
return [
|
|
5299
|
+
2
|
|
5300
|
+
];
|
|
5301
|
+
}
|
|
5302
|
+
});
|
|
5303
|
+
});
|
|
5304
|
+
return function saveRun() {
|
|
5305
|
+
return _ref.apply(this, arguments);
|
|
5306
|
+
};
|
|
5307
|
+
}();
|
|
5308
|
+
return [
|
|
5309
|
+
4,
|
|
5310
|
+
saveRun()
|
|
5311
|
+
];
|
|
5312
|
+
case 4:
|
|
5313
|
+
_state.sent();
|
|
5314
|
+
if (stream) {
|
|
5315
|
+
readableStream = new ReadableStream({
|
|
5316
|
+
start: function start(controller) {
|
|
5317
|
+
controller.enqueue("data: ".concat(JSON.stringify({
|
|
5318
|
+
event: "thread.run.completed",
|
|
5319
|
+
data: run3
|
|
5320
|
+
}), "\n\n"));
|
|
5321
|
+
controller.close();
|
|
5322
|
+
}
|
|
5323
|
+
});
|
|
5324
|
+
return [
|
|
5325
|
+
2,
|
|
5326
|
+
new Response(readableStream, {
|
|
5327
|
+
headers: {
|
|
5328
|
+
"Content-Type": "text/event-stream"
|
|
5329
|
+
}
|
|
5330
|
+
})
|
|
5331
|
+
];
|
|
5332
|
+
}
|
|
5333
|
+
return [
|
|
5334
|
+
2,
|
|
5335
|
+
new Response(JSON.stringify(run3), {
|
|
5336
|
+
status: 200,
|
|
5337
|
+
headers: {
|
|
5338
|
+
"Content-Type": "application/json"
|
|
5339
|
+
}
|
|
5340
|
+
})
|
|
5341
|
+
];
|
|
5342
|
+
}
|
|
5343
|
+
});
|
|
5344
|
+
});
|
|
5345
|
+
return function(urlString, options) {
|
|
5346
|
+
return _ref.apply(this, arguments);
|
|
5347
|
+
};
|
|
5348
|
+
}();
|
|
5349
|
+
};
|
|
5350
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/submitToolOutputs/index.ts
|
|
5351
|
+
var submitToolOutputs = function(param) {
|
|
5352
|
+
var openai = param.openai, runAdapter = param.runAdapter;
|
|
5353
|
+
return {
|
|
5354
|
+
post: post13({
|
|
5355
|
+
openai: openai,
|
|
5356
|
+
runAdapter: runAdapter
|
|
5357
|
+
})
|
|
5358
|
+
};
|
|
5359
|
+
};
|
|
5360
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/steps/get.ts
|
|
5361
|
+
var import_radash10 = require("radash");
|
|
5362
|
+
var get12 = function(param) {
|
|
5363
|
+
var openai = param.openai;
|
|
5364
|
+
return /*#__PURE__*/ function() {
|
|
5365
|
+
var _ref = _async_to_generator(function(urlString) {
|
|
5366
|
+
var _page_at, url, _url_pathname_match, threadId, runId, oai, conversation, _conversation_metadata, metadata, stepsStr, allSteps, _ref, limit, order, after, pageSize, steps3, idx, page, _page_at_id;
|
|
5367
|
+
return _ts_generator(this, function(_state) {
|
|
5368
|
+
switch(_state.label){
|
|
5369
|
+
case 0:
|
|
5370
|
+
url = new URL(urlString);
|
|
5371
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
5372
|
+
oai = openai;
|
|
5373
|
+
return [
|
|
5374
|
+
4,
|
|
5375
|
+
oai.conversations.retrieve(threadId).catch(function() {
|
|
5376
|
+
return null;
|
|
5377
|
+
})
|
|
5378
|
+
];
|
|
5379
|
+
case 1:
|
|
5380
|
+
conversation = _state.sent();
|
|
5381
|
+
metadata = (_conversation_metadata = conversation === null || conversation === void 0 ? void 0 : conversation.metadata) !== null && _conversation_metadata !== void 0 ? _conversation_metadata : {};
|
|
5382
|
+
stepsStr = metadata["run_".concat(runId, "_steps")];
|
|
5383
|
+
allSteps = stepsStr ? JSON.parse(stepsStr) : [];
|
|
5384
|
+
_ref = (0, import_radash10.assign)({
|
|
5385
|
+
limit: "20",
|
|
5386
|
+
order: "desc"
|
|
5387
|
+
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
5388
|
+
pageSize = parseInt(limit, 10);
|
|
5389
|
+
steps3 = allSteps.sort(function(a, b) {
|
|
5390
|
+
return order === "asc" ? a.created_at - b.created_at : b.created_at - a.created_at;
|
|
5391
|
+
});
|
|
5392
|
+
if (after) {
|
|
5393
|
+
idx = steps3.findIndex(function(s) {
|
|
5394
|
+
return s.id === after;
|
|
5395
|
+
});
|
|
5396
|
+
if (idx >= 0) steps3 = steps3.slice(idx + 1);
|
|
5397
|
+
}
|
|
5398
|
+
page = steps3.slice(0, pageSize);
|
|
5399
|
+
return [
|
|
5400
|
+
2,
|
|
5401
|
+
new Response(JSON.stringify({
|
|
5402
|
+
data: page,
|
|
5403
|
+
has_more: steps3.length > pageSize,
|
|
5404
|
+
last_id: (_page_at_id = (_page_at = page.at(-1)) === null || _page_at === void 0 ? void 0 : _page_at.id) !== null && _page_at_id !== void 0 ? _page_at_id : null
|
|
5405
|
+
}), {
|
|
5406
|
+
status: 200,
|
|
5407
|
+
headers: {
|
|
5408
|
+
"Content-Type": "application/json"
|
|
5409
|
+
}
|
|
5410
|
+
})
|
|
5411
|
+
];
|
|
5412
|
+
}
|
|
5413
|
+
});
|
|
5414
|
+
});
|
|
5415
|
+
return function(urlString) {
|
|
5416
|
+
return _ref.apply(this, arguments);
|
|
5417
|
+
};
|
|
5418
|
+
}();
|
|
5419
|
+
};
|
|
5420
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/threads/runs/steps/index.ts
|
|
5421
|
+
var steps = function(param) {
|
|
5422
|
+
var openai = param.openai;
|
|
5423
|
+
return {
|
|
5424
|
+
get: get12({
|
|
5425
|
+
openai: openai
|
|
5426
|
+
})
|
|
5427
|
+
};
|
|
5428
|
+
};
|
|
5429
|
+
// src/adapters/storage/openaiResponsesStorageAdapter/index.ts
|
|
5430
|
+
var openaiResponsesStorageAdapter = function(param) {
|
|
5431
|
+
var openai = param.openai;
|
|
5432
|
+
return function(param) {
|
|
5433
|
+
var runAdapter = param.runAdapter;
|
|
5434
|
+
var _obj;
|
|
5435
|
+
return {
|
|
5436
|
+
requestHandlers: (_obj = {
|
|
5437
|
+
"^/(?:v1|/?openai)/threads$": threads({
|
|
5438
|
+
openai: openai
|
|
5439
|
+
})
|
|
5440
|
+
}, _define_property(_obj, messagesRegexp, messages3({
|
|
5441
|
+
openai: openai
|
|
5442
|
+
})), _define_property(_obj, runsRegexp, runs({
|
|
5443
|
+
openai: openai,
|
|
5444
|
+
runAdapter: runAdapter
|
|
5445
|
+
})), _define_property(_obj, runRegexp, run({
|
|
5446
|
+
openai: openai
|
|
5447
|
+
})), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs({
|
|
5448
|
+
openai: openai,
|
|
5449
|
+
runAdapter: runAdapter
|
|
5450
|
+
})), _define_property(_obj, stepsRegexp, steps({
|
|
5451
|
+
openai: openai
|
|
5452
|
+
})), _obj)
|
|
5453
|
+
};
|
|
5454
|
+
};
|
|
5455
|
+
};
|
|
5456
|
+
// src/adapters/storage/prismaStorageAdapter/threads/post.ts
|
|
5457
|
+
var import_dayjs9 = __toESM(require("dayjs"), 1);
|
|
5458
|
+
// src/adapters/storage/prismaStorageAdapter/threads/serializeThread.ts
|
|
5459
|
+
var import_dayjs8 = __toESM(require("dayjs"), 1);
|
|
5460
|
+
var serializeThread = function(param) {
|
|
5461
|
+
var thread = param.thread;
|
|
5462
|
+
var _thread_openaiConversationId;
|
|
5463
|
+
return {
|
|
5464
|
+
id: thread.id,
|
|
5465
|
+
object: "thread",
|
|
5466
|
+
created_at: (0, import_dayjs8.default)(thread.createdAt).unix(),
|
|
5467
|
+
metadata: thread.metadata,
|
|
5468
|
+
openaiConversationId: (_thread_openaiConversationId = thread.openaiConversationId) !== null && _thread_openaiConversationId !== void 0 ? _thread_openaiConversationId : null,
|
|
5469
|
+
// TODO
|
|
5470
|
+
tool_resources: null
|
|
5471
|
+
};
|
|
5472
|
+
};
|
|
5473
|
+
// src/adapters/storage/prismaStorageAdapter/threads/post.ts
|
|
5474
|
+
var post14 = function(param) {
|
|
5475
|
+
var prisma = param.prisma;
|
|
5476
|
+
return /*#__PURE__*/ _async_to_generator(function() {
|
|
5477
|
+
var _len, args, _key, body, messages5, metadata, initialCreatedAt, thread;
|
|
5478
|
+
var _arguments = arguments;
|
|
5479
|
+
return _ts_generator(this, function(_state) {
|
|
5480
|
+
switch(_state.label){
|
|
5481
|
+
case 0:
|
|
5482
|
+
for(_len = _arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
5483
|
+
args[_key] = _arguments[_key];
|
|
5484
|
+
}
|
|
5485
|
+
body = JSON.parse(args[1].body);
|
|
5486
|
+
messages5 = body.messages || [];
|
|
5487
|
+
metadata = body.metadata || {};
|
|
5488
|
+
initialCreatedAt = (0, import_dayjs9.default)().subtract(messages5.length, "seconds").format();
|
|
5489
|
+
return [
|
|
5490
|
+
4,
|
|
5491
|
+
prisma.thread.create({
|
|
5492
|
+
data: _object_spread_props(_object_spread({
|
|
5493
|
+
metadata: metadata
|
|
5494
|
+
}, metadata.assistantId ? {
|
|
5495
|
+
assistant: {
|
|
5496
|
+
connect: {
|
|
5497
|
+
id: metadata.assistantId
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5500
|
+
} : {}), {
|
|
5501
|
+
messages: {
|
|
5502
|
+
create: messages5.map(function(message, index) {
|
|
5503
|
+
return {
|
|
5504
|
+
role: message.role === "user" ? "USER" : "ASSISTANT",
|
|
5505
|
+
content: [
|
|
5506
|
+
{
|
|
5507
|
+
type: "text",
|
|
5508
|
+
text: {
|
|
5509
|
+
annotations: [],
|
|
5510
|
+
value: message.content
|
|
5511
|
+
}
|
|
5512
|
+
}
|
|
5513
|
+
],
|
|
5514
|
+
attachments: message.attachments,
|
|
5515
|
+
metadata: message.metadata,
|
|
5516
|
+
createdAt: (0, import_dayjs9.default)(initialCreatedAt).add(index, "seconds").toDate()
|
|
5517
|
+
};
|
|
5518
|
+
})
|
|
5519
|
+
}
|
|
5520
|
+
})
|
|
5521
|
+
})
|
|
5522
|
+
];
|
|
5523
|
+
case 1:
|
|
5524
|
+
thread = _state.sent();
|
|
5525
|
+
return [
|
|
5526
|
+
2,
|
|
5527
|
+
new Response(JSON.stringify(serializeThread({
|
|
5528
|
+
thread: thread
|
|
5529
|
+
})), {
|
|
5530
|
+
status: 200,
|
|
5531
|
+
headers: {
|
|
5532
|
+
"Content-Type": "application/json"
|
|
5533
|
+
}
|
|
5534
|
+
})
|
|
5535
|
+
];
|
|
5536
|
+
}
|
|
5537
|
+
});
|
|
5538
|
+
});
|
|
5539
|
+
};
|
|
5540
|
+
// src/adapters/storage/prismaStorageAdapter/threads/index.ts
|
|
5541
|
+
var threads2 = function(param) {
|
|
5542
|
+
var prisma = param.prisma;
|
|
5543
|
+
return {
|
|
5544
|
+
post: post14({
|
|
5545
|
+
prisma: prisma
|
|
5546
|
+
})
|
|
5547
|
+
};
|
|
5548
|
+
};
|
|
5549
|
+
// src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
|
|
5550
|
+
var import_radash12 = require("radash");
|
|
5551
|
+
// src/adapters/storage/prismaStorageAdapter/threads/messages/serializeMessage.ts
|
|
5552
|
+
var import_dayjs10 = __toESM(require("dayjs"), 1);
|
|
5553
|
+
var import_radash11 = require("radash");
|
|
5554
|
+
var serializeMessage5 = function(param) {
|
|
5555
|
+
var message = param.message;
|
|
5556
|
+
var _message_metadata;
|
|
5557
|
+
return {
|
|
5558
|
+
id: message.id,
|
|
5559
|
+
object: "thread.message",
|
|
5560
|
+
created_at: (0, import_dayjs10.default)(message.createdAt).unix(),
|
|
5561
|
+
thread_id: message.threadId,
|
|
5562
|
+
completed_at: message.completedAt ? (0, import_dayjs10.default)(message.completedAt).unix() : null,
|
|
5563
|
+
incomplete_at: message.incompleteAt ? (0, import_dayjs10.default)(message.incompleteAt).unix() : null,
|
|
5564
|
+
incomplete_details: message.incompleteDetails,
|
|
5565
|
+
role: message.role.toLowerCase(),
|
|
5566
|
+
content: message.content,
|
|
5567
|
+
assistant_id: message.assistantId,
|
|
5568
|
+
run_id: message.runId,
|
|
5569
|
+
attachments: message.attachments,
|
|
5570
|
+
status: message.status.toLowerCase(),
|
|
5571
|
+
metadata: (0, import_radash11.assign)((_message_metadata = message.metadata) !== null && _message_metadata !== void 0 ? _message_metadata : {}, message.toolCalls ? {
|
|
5572
|
+
toolCalls: message.toolCalls
|
|
5573
|
+
} : {})
|
|
5574
|
+
};
|
|
5575
|
+
};
|
|
5576
|
+
// src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
|
|
5577
|
+
var messageContentBlocks = function(param) {
|
|
5578
|
+
var content = param.content;
|
|
5579
|
+
if ((0, import_radash12.isArray)(content)) {
|
|
5580
|
+
return content.map(function(item) {
|
|
5581
|
+
if (item.type === "text") {
|
|
5582
|
+
var _item_text;
|
|
5583
|
+
return {
|
|
5584
|
+
type: "text",
|
|
5585
|
+
text: {
|
|
5586
|
+
value: (_item_text = item.text) !== null && _item_text !== void 0 ? _item_text : "",
|
|
5587
|
+
annotations: []
|
|
5588
|
+
}
|
|
5589
|
+
};
|
|
5590
|
+
}
|
|
5591
|
+
return item;
|
|
5592
|
+
});
|
|
5593
|
+
}
|
|
5594
|
+
return [
|
|
5595
|
+
{
|
|
5596
|
+
type: "text",
|
|
5597
|
+
text: {
|
|
5598
|
+
value: content !== null && content !== void 0 ? content : "",
|
|
5599
|
+
annotations: []
|
|
5600
|
+
}
|
|
5601
|
+
}
|
|
5602
|
+
];
|
|
5603
|
+
};
|
|
5604
|
+
var post15 = function(param) {
|
|
5605
|
+
var prisma = param.prisma;
|
|
5606
|
+
return /*#__PURE__*/ function() {
|
|
5607
|
+
var _ref = _async_to_generator(function(urlString, options) {
|
|
5608
|
+
var url, _url_pathname_match, threadId, body, role, content, metadata, message;
|
|
5609
|
+
return _ts_generator(this, function(_state) {
|
|
5610
|
+
switch(_state.label){
|
|
5611
|
+
case 0:
|
|
5612
|
+
url = new URL(urlString);
|
|
5613
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
5614
|
+
body = JSON.parse(options.body);
|
|
5615
|
+
role = body.role, content = body.content, metadata = body.metadata;
|
|
3942
5616
|
return [
|
|
3943
5617
|
4,
|
|
3944
5618
|
prisma.message.create({
|
|
@@ -3956,7 +5630,7 @@ var post11 = function(param) {
|
|
|
3956
5630
|
message = _state.sent();
|
|
3957
5631
|
return [
|
|
3958
5632
|
2,
|
|
3959
|
-
new Response(JSON.stringify(
|
|
5633
|
+
new Response(JSON.stringify(serializeMessage5({
|
|
3960
5634
|
message: message
|
|
3961
5635
|
})), {
|
|
3962
5636
|
status: 200,
|
|
@@ -3974,18 +5648,18 @@ var post11 = function(param) {
|
|
|
3974
5648
|
}();
|
|
3975
5649
|
};
|
|
3976
5650
|
// src/adapters/storage/prismaStorageAdapter/threads/messages/get.ts
|
|
3977
|
-
var
|
|
3978
|
-
var
|
|
5651
|
+
var import_radash13 = require("radash");
|
|
5652
|
+
var get13 = function(param) {
|
|
3979
5653
|
var prisma = param.prisma;
|
|
3980
5654
|
return /*#__PURE__*/ function() {
|
|
3981
5655
|
var _ref = _async_to_generator(function(urlString) {
|
|
3982
|
-
var _this, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, messagesPlusOne,
|
|
5656
|
+
var _this, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, messagesPlusOne, messages5, _id;
|
|
3983
5657
|
return _ts_generator(this, function(_state) {
|
|
3984
5658
|
switch(_state.label){
|
|
3985
5659
|
case 0:
|
|
3986
5660
|
url = new URL(urlString);
|
|
3987
5661
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
3988
|
-
_ref = (0,
|
|
5662
|
+
_ref = (0, import_radash13.assign)({
|
|
3989
5663
|
limit: "20",
|
|
3990
5664
|
order: "desc"
|
|
3991
5665
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -4009,17 +5683,17 @@ var get10 = function(param) {
|
|
|
4009
5683
|
];
|
|
4010
5684
|
case 1:
|
|
4011
5685
|
messagesPlusOne = _state.sent();
|
|
4012
|
-
|
|
5686
|
+
messages5 = messagesPlusOne.slice(0, pageSize);
|
|
4013
5687
|
return [
|
|
4014
5688
|
2,
|
|
4015
5689
|
new Response(JSON.stringify({
|
|
4016
|
-
data:
|
|
4017
|
-
return
|
|
5690
|
+
data: messages5.map(function(message) {
|
|
5691
|
+
return serializeMessage5({
|
|
4018
5692
|
message: message
|
|
4019
5693
|
});
|
|
4020
5694
|
}),
|
|
4021
5695
|
has_more: messagesPlusOne.length > pageSize,
|
|
4022
|
-
last_id: (_id = (_this = (0,
|
|
5696
|
+
last_id: (_id = (_this = (0, import_radash13.last)(messages5)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
|
|
4023
5697
|
}), {
|
|
4024
5698
|
status: 200,
|
|
4025
5699
|
headers: {
|
|
@@ -4036,42 +5710,42 @@ var get10 = function(param) {
|
|
|
4036
5710
|
}();
|
|
4037
5711
|
};
|
|
4038
5712
|
// src/adapters/storage/prismaStorageAdapter/threads/messages/index.ts
|
|
4039
|
-
var
|
|
5713
|
+
var messages4 = function(param) {
|
|
4040
5714
|
var prisma = param.prisma;
|
|
4041
5715
|
return {
|
|
4042
|
-
post:
|
|
5716
|
+
post: post15({
|
|
4043
5717
|
prisma: prisma
|
|
4044
5718
|
}),
|
|
4045
|
-
get:
|
|
5719
|
+
get: get13({
|
|
4046
5720
|
prisma: prisma
|
|
4047
5721
|
})
|
|
4048
5722
|
};
|
|
4049
5723
|
};
|
|
4050
5724
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
|
|
4051
|
-
var
|
|
5725
|
+
var import_radash14 = require("radash");
|
|
4052
5726
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
|
|
4053
|
-
var
|
|
5727
|
+
var import_dayjs11 = __toESM(require("dayjs"), 1);
|
|
4054
5728
|
var serializeRun = function(param) {
|
|
4055
|
-
var
|
|
5729
|
+
var run3 = param.run;
|
|
4056
5730
|
return {
|
|
4057
|
-
id:
|
|
5731
|
+
id: run3.id,
|
|
4058
5732
|
object: "thread.run",
|
|
4059
|
-
created_at: (0,
|
|
4060
|
-
thread_id:
|
|
4061
|
-
assistant_id:
|
|
4062
|
-
status:
|
|
4063
|
-
required_action:
|
|
4064
|
-
last_error:
|
|
4065
|
-
expires_at: (0,
|
|
4066
|
-
started_at:
|
|
4067
|
-
cancelled_at:
|
|
4068
|
-
failed_at:
|
|
4069
|
-
completed_at:
|
|
4070
|
-
model:
|
|
4071
|
-
instructions:
|
|
4072
|
-
tools:
|
|
4073
|
-
metadata:
|
|
4074
|
-
usage:
|
|
5733
|
+
created_at: (0, import_dayjs11.default)(run3.createdAt).unix(),
|
|
5734
|
+
thread_id: run3.threadId,
|
|
5735
|
+
assistant_id: run3.assistantId,
|
|
5736
|
+
status: run3.status.toLowerCase(),
|
|
5737
|
+
required_action: run3.requiredAction,
|
|
5738
|
+
last_error: run3.lastError,
|
|
5739
|
+
expires_at: (0, import_dayjs11.default)(run3.expiresAt).unix(),
|
|
5740
|
+
started_at: run3.startedAt ? (0, import_dayjs11.default)(run3.startedAt).unix() : null,
|
|
5741
|
+
cancelled_at: run3.cancelledAt ? (0, import_dayjs11.default)(run3.cancelledAt).unix() : null,
|
|
5742
|
+
failed_at: run3.failedAt ? (0, import_dayjs11.default)(run3.failedAt).unix() : null,
|
|
5743
|
+
completed_at: run3.completedAt ? (0, import_dayjs11.default)(run3.completedAt).unix() : null,
|
|
5744
|
+
model: run3.model,
|
|
5745
|
+
instructions: run3.instructions,
|
|
5746
|
+
tools: run3.tools,
|
|
5747
|
+
metadata: run3.metadata,
|
|
5748
|
+
usage: run3.usage,
|
|
4075
5749
|
truncation_strategy: {
|
|
4076
5750
|
type: "auto"
|
|
4077
5751
|
},
|
|
@@ -4082,22 +5756,21 @@ var serializeRun = function(param) {
|
|
|
4082
5756
|
incomplete_details: null,
|
|
4083
5757
|
max_completion_tokens: null,
|
|
4084
5758
|
max_prompt_tokens: null,
|
|
4085
|
-
tool_choice: "auto",
|
|
4086
5759
|
parallel_tool_calls: true
|
|
4087
5760
|
};
|
|
4088
5761
|
};
|
|
4089
5762
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
|
|
4090
|
-
var
|
|
5763
|
+
var get14 = function(param) {
|
|
4091
5764
|
var prisma = param.prisma;
|
|
4092
5765
|
return /*#__PURE__*/ function() {
|
|
4093
5766
|
var _ref = _async_to_generator(function(urlString) {
|
|
4094
|
-
var
|
|
5767
|
+
var _runs3_at, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, runsPlusOne, runs3, _runs3_at_id;
|
|
4095
5768
|
return _ts_generator(this, function(_state) {
|
|
4096
5769
|
switch(_state.label){
|
|
4097
5770
|
case 0:
|
|
4098
5771
|
url = new URL(urlString);
|
|
4099
5772
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
|
|
4100
|
-
_ref = (0,
|
|
5773
|
+
_ref = (0, import_radash14.assign)({
|
|
4101
5774
|
limit: "20",
|
|
4102
5775
|
order: "desc"
|
|
4103
5776
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -4121,17 +5794,17 @@ var get11 = function(param) {
|
|
|
4121
5794
|
];
|
|
4122
5795
|
case 1:
|
|
4123
5796
|
runsPlusOne = _state.sent();
|
|
4124
|
-
|
|
5797
|
+
runs3 = runsPlusOne.slice(0, pageSize);
|
|
4125
5798
|
return [
|
|
4126
5799
|
2,
|
|
4127
5800
|
new Response(JSON.stringify({
|
|
4128
|
-
data:
|
|
5801
|
+
data: runs3.map(function(run3) {
|
|
4129
5802
|
return serializeRun({
|
|
4130
|
-
run:
|
|
5803
|
+
run: run3
|
|
4131
5804
|
});
|
|
4132
5805
|
}),
|
|
4133
5806
|
has_more: runsPlusOne.length > pageSize,
|
|
4134
|
-
last_id: (
|
|
5807
|
+
last_id: (_runs3_at_id = (_runs3_at = runs3.at(-1)) === null || _runs3_at === void 0 ? void 0 : _runs3_at.id) !== null && _runs3_at_id !== void 0 ? _runs3_at_id : null
|
|
4135
5808
|
}), {
|
|
4136
5809
|
status: 200,
|
|
4137
5810
|
headers: {
|
|
@@ -4148,8 +5821,8 @@ var get11 = function(param) {
|
|
|
4148
5821
|
}();
|
|
4149
5822
|
};
|
|
4150
5823
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
|
|
4151
|
-
var
|
|
4152
|
-
var
|
|
5824
|
+
var import_dayjs13 = __toESM(require("dayjs"), 1);
|
|
5825
|
+
var import_radash15 = require("radash");
|
|
4153
5826
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunInProgress.ts
|
|
4154
5827
|
var threadRunInProgress = function(param) {
|
|
4155
5828
|
var prisma = param.prisma, event = param.event, controller = param.controller;
|
|
@@ -4164,68 +5837,127 @@ var threadRunInProgress = function(param) {
|
|
|
4164
5837
|
});
|
|
4165
5838
|
};
|
|
4166
5839
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunFailed.ts
|
|
4167
|
-
var threadRunFailed = function(
|
|
4168
|
-
var
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
5840
|
+
var threadRunFailed = /*#__PURE__*/ function() {
|
|
5841
|
+
var _ref = _async_to_generator(function(param) {
|
|
5842
|
+
var prisma, event, controller, runRecord;
|
|
5843
|
+
return _ts_generator(this, function(_state) {
|
|
5844
|
+
switch(_state.label){
|
|
5845
|
+
case 0:
|
|
5846
|
+
prisma = param.prisma, event = param.event, controller = param.controller;
|
|
5847
|
+
controller.enqueue(event);
|
|
5848
|
+
return [
|
|
5849
|
+
4,
|
|
5850
|
+
prisma.run.update({
|
|
5851
|
+
where: {
|
|
5852
|
+
id: event.data.id
|
|
5853
|
+
},
|
|
5854
|
+
data: {
|
|
5855
|
+
status: "FAILED" /* FAILED */ ,
|
|
5856
|
+
failedAt: event.data.failed_at,
|
|
5857
|
+
lastError: event.data.last_error
|
|
5858
|
+
}
|
|
5859
|
+
})
|
|
5860
|
+
];
|
|
5861
|
+
case 1:
|
|
5862
|
+
runRecord = _state.sent();
|
|
5863
|
+
return [
|
|
5864
|
+
2,
|
|
5865
|
+
runRecord
|
|
5866
|
+
];
|
|
5867
|
+
}
|
|
5868
|
+
});
|
|
4179
5869
|
});
|
|
4180
|
-
|
|
5870
|
+
return function threadRunFailed(_) {
|
|
5871
|
+
return _ref.apply(this, arguments);
|
|
5872
|
+
};
|
|
5873
|
+
}();
|
|
4181
5874
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunCompleted.ts
|
|
4182
|
-
var threadRunCompleted = function(
|
|
4183
|
-
var
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
5875
|
+
var threadRunCompleted = /*#__PURE__*/ function() {
|
|
5876
|
+
var _ref = _async_to_generator(function(param) {
|
|
5877
|
+
var prisma, event, controller, runRecord;
|
|
5878
|
+
return _ts_generator(this, function(_state) {
|
|
5879
|
+
switch(_state.label){
|
|
5880
|
+
case 0:
|
|
5881
|
+
prisma = param.prisma, event = param.event, controller = param.controller;
|
|
5882
|
+
controller.enqueue(event);
|
|
5883
|
+
return [
|
|
5884
|
+
4,
|
|
5885
|
+
prisma.run.update({
|
|
5886
|
+
where: {
|
|
5887
|
+
id: event.data.id
|
|
5888
|
+
},
|
|
5889
|
+
data: {
|
|
5890
|
+
status: "COMPLETED" /* COMPLETED */ ,
|
|
5891
|
+
requiredAction: void 0
|
|
5892
|
+
}
|
|
5893
|
+
})
|
|
5894
|
+
];
|
|
5895
|
+
case 1:
|
|
5896
|
+
runRecord = _state.sent();
|
|
5897
|
+
return [
|
|
5898
|
+
2,
|
|
5899
|
+
runRecord
|
|
5900
|
+
];
|
|
5901
|
+
}
|
|
5902
|
+
});
|
|
4193
5903
|
});
|
|
4194
|
-
|
|
5904
|
+
return function threadRunCompleted(_) {
|
|
5905
|
+
return _ref.apply(this, arguments);
|
|
5906
|
+
};
|
|
5907
|
+
}();
|
|
4195
5908
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunRequiresAction.ts
|
|
4196
|
-
var threadRunRequiresAction = function(
|
|
4197
|
-
var
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
5909
|
+
var threadRunRequiresAction = /*#__PURE__*/ function() {
|
|
5910
|
+
var _ref = _async_to_generator(function(param) {
|
|
5911
|
+
var prisma, event, controller, runRecord;
|
|
5912
|
+
return _ts_generator(this, function(_state) {
|
|
5913
|
+
switch(_state.label){
|
|
5914
|
+
case 0:
|
|
5915
|
+
prisma = param.prisma, event = param.event, controller = param.controller;
|
|
5916
|
+
controller.enqueue(event);
|
|
5917
|
+
return [
|
|
5918
|
+
4,
|
|
5919
|
+
prisma.run.update({
|
|
5920
|
+
where: {
|
|
5921
|
+
id: event.data.id
|
|
5922
|
+
},
|
|
5923
|
+
data: {
|
|
5924
|
+
status: "REQUIRES_ACTION" /* REQUIRES_ACTION */ ,
|
|
5925
|
+
requiredAction: event.data.required_action
|
|
5926
|
+
}
|
|
5927
|
+
})
|
|
5928
|
+
];
|
|
5929
|
+
case 1:
|
|
5930
|
+
runRecord = _state.sent();
|
|
5931
|
+
return [
|
|
5932
|
+
2,
|
|
5933
|
+
runRecord
|
|
5934
|
+
];
|
|
5935
|
+
}
|
|
5936
|
+
});
|
|
4207
5937
|
});
|
|
4208
|
-
|
|
5938
|
+
return function threadRunRequiresAction(_) {
|
|
5939
|
+
return _ref.apply(this, arguments);
|
|
5940
|
+
};
|
|
5941
|
+
}();
|
|
4209
5942
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/steps/serializeRunStep.ts
|
|
4210
|
-
var
|
|
5943
|
+
var import_dayjs12 = __toESM(require("dayjs"), 1);
|
|
4211
5944
|
var serializeRunStep = function(param) {
|
|
4212
5945
|
var runStep = param.runStep;
|
|
4213
5946
|
return {
|
|
4214
5947
|
id: runStep.id,
|
|
4215
5948
|
object: "thread.run.step",
|
|
4216
|
-
created_at: (0,
|
|
5949
|
+
created_at: (0, import_dayjs12.default)(runStep.createdAt).unix(),
|
|
4217
5950
|
assistant_id: runStep.assistantId,
|
|
4218
5951
|
thread_id: runStep.threadId,
|
|
4219
5952
|
run_id: runStep.runId,
|
|
4220
5953
|
type: runStep.type.toLowerCase(),
|
|
4221
5954
|
status: runStep.status.toLowerCase(),
|
|
4222
|
-
// @ts-ignore-next-line
|
|
4223
5955
|
step_details: runStep.stepDetails,
|
|
4224
5956
|
last_error: runStep.lastError,
|
|
4225
|
-
expired_at: runStep.expiredAt ? (0,
|
|
4226
|
-
cancelled_at: runStep.cancelledAt ? (0,
|
|
4227
|
-
failed_at: runStep.failedAt ? (0,
|
|
4228
|
-
completed_at: runStep.completedAt ? (0,
|
|
5957
|
+
expired_at: runStep.expiredAt ? (0, import_dayjs12.default)(runStep.expiredAt).unix() : null,
|
|
5958
|
+
cancelled_at: runStep.cancelledAt ? (0, import_dayjs12.default)(runStep.cancelledAt).unix() : null,
|
|
5959
|
+
failed_at: runStep.failedAt ? (0, import_dayjs12.default)(runStep.failedAt).unix() : null,
|
|
5960
|
+
completed_at: runStep.completedAt ? (0, import_dayjs12.default)(runStep.completedAt).unix() : null,
|
|
4229
5961
|
metadata: runStep.metadata,
|
|
4230
5962
|
usage: runStep.usage
|
|
4231
5963
|
};
|
|
@@ -4318,7 +6050,7 @@ var threadMessageCreated = /*#__PURE__*/ function() {
|
|
|
4318
6050
|
];
|
|
4319
6051
|
case 1:
|
|
4320
6052
|
message = _state.sent();
|
|
4321
|
-
serializedMessage =
|
|
6053
|
+
serializedMessage = serializeMessage5({
|
|
4322
6054
|
message: message
|
|
4323
6055
|
});
|
|
4324
6056
|
controller.enqueue(_object_spread_props(_object_spread({}, event), {
|
|
@@ -4343,13 +6075,14 @@ var threadMessageDelta = function(param) {
|
|
|
4343
6075
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadMessageCompleted.ts
|
|
4344
6076
|
var threadMessageCompleted = /*#__PURE__*/ function() {
|
|
4345
6077
|
var _ref = _async_to_generator(function(param) {
|
|
4346
|
-
var prisma, event, controller, latestRunStep;
|
|
6078
|
+
var prisma, event, controller, data, latestRunStep;
|
|
4347
6079
|
return _ts_generator(this, function(_state) {
|
|
4348
6080
|
switch(_state.label){
|
|
4349
6081
|
case 0:
|
|
4350
6082
|
prisma = param.prisma, event = param.event, controller = param.controller;
|
|
4351
6083
|
controller.enqueue(event);
|
|
4352
|
-
|
|
6084
|
+
data = event.data;
|
|
6085
|
+
if (!data.tool_calls) return [
|
|
4353
6086
|
3,
|
|
4354
6087
|
3
|
|
4355
6088
|
];
|
|
@@ -4379,7 +6112,7 @@ var threadMessageCompleted = /*#__PURE__*/ function() {
|
|
|
4379
6112
|
data: {
|
|
4380
6113
|
stepDetails: {
|
|
4381
6114
|
type: "tool_calls",
|
|
4382
|
-
tool_calls:
|
|
6115
|
+
tool_calls: data.tool_calls
|
|
4383
6116
|
}
|
|
4384
6117
|
}
|
|
4385
6118
|
})
|
|
@@ -4396,10 +6129,10 @@ var threadMessageCompleted = /*#__PURE__*/ function() {
|
|
|
4396
6129
|
},
|
|
4397
6130
|
data: _object_spread({
|
|
4398
6131
|
status: "COMPLETED" /* COMPLETED */
|
|
4399
|
-
},
|
|
4400
|
-
content:
|
|
4401
|
-
} : {},
|
|
4402
|
-
toolCalls:
|
|
6132
|
+
}, data.content ? {
|
|
6133
|
+
content: data.content
|
|
6134
|
+
} : {}, data.tool_calls ? {
|
|
6135
|
+
toolCalls: data.tool_calls
|
|
4403
6136
|
} : {})
|
|
4404
6137
|
})
|
|
4405
6138
|
];
|
|
@@ -4440,33 +6173,33 @@ var onEvent = function(param) {
|
|
|
4440
6173
|
};
|
|
4441
6174
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/getMessages.ts
|
|
4442
6175
|
var getTake = function(param) {
|
|
4443
|
-
var
|
|
4444
|
-
if (
|
|
6176
|
+
var run3 = param.run;
|
|
6177
|
+
if (run3.truncationStrategy.type === "auto") {
|
|
4445
6178
|
return null;
|
|
4446
6179
|
}
|
|
4447
|
-
if (
|
|
4448
|
-
if (!
|
|
6180
|
+
if (run3.truncationStrategy.type === "last_messages") {
|
|
6181
|
+
if (!run3.truncationStrategy.last_messages) {
|
|
4449
6182
|
throw new Error("Truncation strategy last_messages is required");
|
|
4450
6183
|
}
|
|
4451
|
-
return -
|
|
6184
|
+
return -run3.truncationStrategy.last_messages;
|
|
4452
6185
|
}
|
|
4453
|
-
throw new Error("Unsupported truncation strategy type: ".concat(
|
|
6186
|
+
throw new Error("Unsupported truncation strategy type: ".concat(run3.truncationStrategy.type));
|
|
4454
6187
|
};
|
|
4455
6188
|
var getMessages = function(param) {
|
|
4456
|
-
var prisma = param.prisma,
|
|
6189
|
+
var prisma = param.prisma, run3 = param.run;
|
|
4457
6190
|
return /*#__PURE__*/ _async_to_generator(function() {
|
|
4458
|
-
var take,
|
|
6191
|
+
var take, messages5;
|
|
4459
6192
|
return _ts_generator(this, function(_state) {
|
|
4460
6193
|
switch(_state.label){
|
|
4461
6194
|
case 0:
|
|
4462
6195
|
take = getTake({
|
|
4463
|
-
run:
|
|
6196
|
+
run: run3
|
|
4464
6197
|
});
|
|
4465
6198
|
return [
|
|
4466
6199
|
4,
|
|
4467
6200
|
prisma.message.findMany(_object_spread({
|
|
4468
6201
|
where: {
|
|
4469
|
-
threadId:
|
|
6202
|
+
threadId: run3.threadId
|
|
4470
6203
|
},
|
|
4471
6204
|
include: {
|
|
4472
6205
|
run: {
|
|
@@ -4483,11 +6216,11 @@ var getMessages = function(param) {
|
|
|
4483
6216
|
} : {}))
|
|
4484
6217
|
];
|
|
4485
6218
|
case 1:
|
|
4486
|
-
|
|
6219
|
+
messages5 = _state.sent();
|
|
4487
6220
|
return [
|
|
4488
6221
|
2,
|
|
4489
|
-
|
|
4490
|
-
return _object_spread_props(_object_spread({},
|
|
6222
|
+
messages5.map(function(message) {
|
|
6223
|
+
return _object_spread_props(_object_spread({}, serializeMessage5({
|
|
4491
6224
|
message: message
|
|
4492
6225
|
})), {
|
|
4493
6226
|
run: message.run ? _object_spread_props(_object_spread({}, serializeRun({
|
|
@@ -4506,13 +6239,41 @@ var getMessages = function(param) {
|
|
|
4506
6239
|
});
|
|
4507
6240
|
});
|
|
4508
6241
|
};
|
|
6242
|
+
// src/adapters/storage/prismaStorageAdapter/threads/runs/getThread.ts
|
|
6243
|
+
var getThread = function(param) {
|
|
6244
|
+
var prisma = param.prisma, threadId = param.threadId;
|
|
6245
|
+
return /*#__PURE__*/ _async_to_generator(function() {
|
|
6246
|
+
var thread;
|
|
6247
|
+
return _ts_generator(this, function(_state) {
|
|
6248
|
+
switch(_state.label){
|
|
6249
|
+
case 0:
|
|
6250
|
+
return [
|
|
6251
|
+
4,
|
|
6252
|
+
prisma.thread.findUnique({
|
|
6253
|
+
where: {
|
|
6254
|
+
id: threadId
|
|
6255
|
+
}
|
|
6256
|
+
})
|
|
6257
|
+
];
|
|
6258
|
+
case 1:
|
|
6259
|
+
thread = _state.sent();
|
|
6260
|
+
return [
|
|
6261
|
+
2,
|
|
6262
|
+
thread ? serializeThread({
|
|
6263
|
+
thread: thread
|
|
6264
|
+
}) : null
|
|
6265
|
+
];
|
|
6266
|
+
}
|
|
6267
|
+
});
|
|
6268
|
+
});
|
|
6269
|
+
};
|
|
4509
6270
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
|
|
4510
|
-
var
|
|
6271
|
+
var post16 = function(param) {
|
|
4511
6272
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
4512
6273
|
return /*#__PURE__*/ function() {
|
|
4513
6274
|
var _ref = _async_to_generator(function(urlString, options) {
|
|
4514
6275
|
var url, _url_pathname_match, threadId, body, assistant_id, stream, assistant, _ref, model, instructions, // additional_instructions,
|
|
4515
|
-
tools, metadata, response_format, truncation_strategy,
|
|
6276
|
+
tools, metadata, response_format, truncation_strategy, run3, data, readableStream;
|
|
4516
6277
|
return _ts_generator(this, function(_state) {
|
|
4517
6278
|
switch(_state.label){
|
|
4518
6279
|
case 0:
|
|
@@ -4530,12 +6291,9 @@ var post12 = function(param) {
|
|
|
4530
6291
|
];
|
|
4531
6292
|
case 1:
|
|
4532
6293
|
assistant = _state.sent();
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
_ref = (0, import_radash11.assign)({
|
|
4537
|
-
model: assistant.modelSlug,
|
|
4538
|
-
instructions: "",
|
|
6294
|
+
_ref = (0, import_radash15.assign)({
|
|
6295
|
+
model: (assistant === null || assistant === void 0 ? void 0 : assistant.model) || "gpt-4o-mini",
|
|
6296
|
+
instructions: (assistant === null || assistant === void 0 ? void 0 : assistant.instructions) || "",
|
|
4539
6297
|
additional_instructions: null,
|
|
4540
6298
|
truncation_strategy: {
|
|
4541
6299
|
type: "auto"
|
|
@@ -4549,7 +6307,7 @@ var post12 = function(param) {
|
|
|
4549
6307
|
prisma.run.create({
|
|
4550
6308
|
data: {
|
|
4551
6309
|
status: "QUEUED",
|
|
4552
|
-
expiresAt: (0,
|
|
6310
|
+
expiresAt: (0, import_dayjs13.default)().add(1, "hour").unix(),
|
|
4553
6311
|
model: model,
|
|
4554
6312
|
instructions: instructions,
|
|
4555
6313
|
tools: tools,
|
|
@@ -4570,9 +6328,9 @@ var post12 = function(param) {
|
|
|
4570
6328
|
})
|
|
4571
6329
|
];
|
|
4572
6330
|
case 2:
|
|
4573
|
-
|
|
6331
|
+
run3 = _state.sent();
|
|
4574
6332
|
data = serializeRun({
|
|
4575
|
-
run:
|
|
6333
|
+
run: run3
|
|
4576
6334
|
});
|
|
4577
6335
|
readableStream = new ReadableStream({
|
|
4578
6336
|
start: function start(controller) {
|
|
@@ -4601,7 +6359,11 @@ var post12 = function(param) {
|
|
|
4601
6359
|
}),
|
|
4602
6360
|
getMessages: getMessages({
|
|
4603
6361
|
prisma: prisma,
|
|
4604
|
-
run:
|
|
6362
|
+
run: run3
|
|
6363
|
+
}),
|
|
6364
|
+
getThread: getThread({
|
|
6365
|
+
prisma: prisma,
|
|
6366
|
+
threadId: threadId
|
|
4605
6367
|
})
|
|
4606
6368
|
})
|
|
4607
6369
|
];
|
|
@@ -4624,8 +6386,8 @@ var post12 = function(param) {
|
|
|
4624
6386
|
})({
|
|
4625
6387
|
event: "thread.run.failed",
|
|
4626
6388
|
data: {
|
|
4627
|
-
id:
|
|
4628
|
-
failed_at: (0,
|
|
6389
|
+
id: run3.id,
|
|
6390
|
+
failed_at: (0, import_dayjs13.default)().unix(),
|
|
4629
6391
|
last_error: {
|
|
4630
6392
|
code: "server_error",
|
|
4631
6393
|
message: "".concat((_error_message = error === null || error === void 0 ? void 0 : error.message) !== null && _error_message !== void 0 ? _error_message : "", " ").concat((_error_cause_message = error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) !== null && _error_cause_message !== void 0 ? _error_cause_message : "")
|
|
@@ -4678,24 +6440,24 @@ var post12 = function(param) {
|
|
|
4678
6440
|
}();
|
|
4679
6441
|
};
|
|
4680
6442
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/index.ts
|
|
4681
|
-
var
|
|
6443
|
+
var runs2 = function(param) {
|
|
4682
6444
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
4683
6445
|
return {
|
|
4684
|
-
get:
|
|
6446
|
+
get: get14({
|
|
4685
6447
|
prisma: prisma
|
|
4686
6448
|
}),
|
|
4687
|
-
post:
|
|
6449
|
+
post: post16({
|
|
4688
6450
|
prisma: prisma,
|
|
4689
6451
|
runAdapter: runAdapter
|
|
4690
6452
|
})
|
|
4691
6453
|
};
|
|
4692
6454
|
};
|
|
4693
6455
|
// src/adapters/storage/prismaStorageAdapter/threads/run/get.ts
|
|
4694
|
-
var
|
|
6456
|
+
var get15 = function(param) {
|
|
4695
6457
|
var prisma = param.prisma;
|
|
4696
6458
|
return /*#__PURE__*/ function() {
|
|
4697
6459
|
var _ref = _async_to_generator(function(urlString) {
|
|
4698
|
-
var url, _url_pathname_match, threadId, runId,
|
|
6460
|
+
var url, _url_pathname_match, threadId, runId, run3;
|
|
4699
6461
|
return _ts_generator(this, function(_state) {
|
|
4700
6462
|
switch(_state.label){
|
|
4701
6463
|
case 0:
|
|
@@ -4711,11 +6473,11 @@ var get12 = function(param) {
|
|
|
4711
6473
|
})
|
|
4712
6474
|
];
|
|
4713
6475
|
case 1:
|
|
4714
|
-
|
|
6476
|
+
run3 = _state.sent();
|
|
4715
6477
|
return [
|
|
4716
6478
|
2,
|
|
4717
6479
|
new Response(JSON.stringify(serializeRun({
|
|
4718
|
-
run:
|
|
6480
|
+
run: run3
|
|
4719
6481
|
})), {
|
|
4720
6482
|
status: 200,
|
|
4721
6483
|
headers: {
|
|
@@ -4733,17 +6495,17 @@ var get12 = function(param) {
|
|
|
4733
6495
|
}();
|
|
4734
6496
|
};
|
|
4735
6497
|
// src/adapters/storage/prismaStorageAdapter/threads/run/index.ts
|
|
4736
|
-
var
|
|
6498
|
+
var run2 = function(param) {
|
|
4737
6499
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
4738
6500
|
return {
|
|
4739
|
-
get:
|
|
6501
|
+
get: get15({
|
|
4740
6502
|
prisma: prisma
|
|
4741
6503
|
})
|
|
4742
6504
|
};
|
|
4743
6505
|
};
|
|
4744
6506
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/steps/get.ts
|
|
4745
|
-
var
|
|
4746
|
-
var
|
|
6507
|
+
var import_radash16 = require("radash");
|
|
6508
|
+
var get16 = function(param) {
|
|
4747
6509
|
var prisma = param.prisma;
|
|
4748
6510
|
return /*#__PURE__*/ function() {
|
|
4749
6511
|
var _ref = _async_to_generator(function(urlString) {
|
|
@@ -4753,7 +6515,7 @@ var get13 = function(param) {
|
|
|
4753
6515
|
case 0:
|
|
4754
6516
|
url = new URL(urlString);
|
|
4755
6517
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
4756
|
-
_ref = (0,
|
|
6518
|
+
_ref = (0, import_radash16.assign)({
|
|
4757
6519
|
limit: "20",
|
|
4758
6520
|
order: "desc"
|
|
4759
6521
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -4805,16 +6567,16 @@ var get13 = function(param) {
|
|
|
4805
6567
|
}();
|
|
4806
6568
|
};
|
|
4807
6569
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/steps/index.ts
|
|
4808
|
-
var
|
|
6570
|
+
var steps2 = function(param) {
|
|
4809
6571
|
var prisma = param.prisma;
|
|
4810
6572
|
return {
|
|
4811
|
-
get:
|
|
6573
|
+
get: get16({
|
|
4812
6574
|
prisma: prisma
|
|
4813
6575
|
})
|
|
4814
6576
|
};
|
|
4815
6577
|
};
|
|
4816
6578
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/post/updateRun.ts
|
|
4817
|
-
var
|
|
6579
|
+
var import_dayjs14 = __toESM(require("dayjs"), 1);
|
|
4818
6580
|
var updateRun = /*#__PURE__*/ function() {
|
|
4819
6581
|
var _ref = _async_to_generator(function(param) {
|
|
4820
6582
|
var prisma, runId, threadId, _param_onThreadRunStepCompleted, onThreadRunStepCompleted, tool_outputs;
|
|
@@ -4867,7 +6629,7 @@ var updateRun = /*#__PURE__*/ function() {
|
|
|
4867
6629
|
},
|
|
4868
6630
|
data: {
|
|
4869
6631
|
status: "COMPLETED",
|
|
4870
|
-
completedAt: (0,
|
|
6632
|
+
completedAt: (0, import_dayjs14.default)().unix(),
|
|
4871
6633
|
stepDetails: {
|
|
4872
6634
|
type: "tool_calls",
|
|
4873
6635
|
// @ts-ignore-next-line
|
|
@@ -4982,11 +6744,11 @@ var updateRun = /*#__PURE__*/ function() {
|
|
|
4982
6744
|
};
|
|
4983
6745
|
}();
|
|
4984
6746
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
|
|
4985
|
-
var
|
|
6747
|
+
var post17 = function(param) {
|
|
4986
6748
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
4987
6749
|
return /*#__PURE__*/ function() {
|
|
4988
6750
|
var _ref = _async_to_generator(function(urlString, options) {
|
|
4989
|
-
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream,
|
|
6751
|
+
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream, run3;
|
|
4990
6752
|
return _ts_generator(this, function(_state) {
|
|
4991
6753
|
switch(_state.label){
|
|
4992
6754
|
case 0:
|
|
@@ -5001,7 +6763,7 @@ var post13 = function(param) {
|
|
|
5001
6763
|
readableStream = new ReadableStream({
|
|
5002
6764
|
start: function start(controller) {
|
|
5003
6765
|
return _async_to_generator(function() {
|
|
5004
|
-
var
|
|
6766
|
+
var run3;
|
|
5005
6767
|
return _ts_generator(this, function(_state) {
|
|
5006
6768
|
switch(_state.label){
|
|
5007
6769
|
case 0:
|
|
@@ -5035,12 +6797,12 @@ var post13 = function(param) {
|
|
|
5035
6797
|
})
|
|
5036
6798
|
];
|
|
5037
6799
|
case 1:
|
|
5038
|
-
|
|
6800
|
+
run3 = _state.sent();
|
|
5039
6801
|
return [
|
|
5040
6802
|
4,
|
|
5041
6803
|
runAdapter({
|
|
5042
6804
|
run: serializeRun({
|
|
5043
|
-
run:
|
|
6805
|
+
run: run3
|
|
5044
6806
|
}),
|
|
5045
6807
|
onEvent: onEvent({
|
|
5046
6808
|
controller: _object_spread_props(_object_spread({}, controller), {
|
|
@@ -5052,7 +6814,11 @@ var post13 = function(param) {
|
|
|
5052
6814
|
}),
|
|
5053
6815
|
getMessages: getMessages({
|
|
5054
6816
|
prisma: prisma,
|
|
5055
|
-
run:
|
|
6817
|
+
run: run3
|
|
6818
|
+
}),
|
|
6819
|
+
getThread: getThread({
|
|
6820
|
+
prisma: prisma,
|
|
6821
|
+
threadId: threadId
|
|
5056
6822
|
})
|
|
5057
6823
|
})
|
|
5058
6824
|
];
|
|
@@ -5086,7 +6852,7 @@ var post13 = function(param) {
|
|
|
5086
6852
|
})
|
|
5087
6853
|
];
|
|
5088
6854
|
case 2:
|
|
5089
|
-
|
|
6855
|
+
run3 = _state.sent();
|
|
5090
6856
|
return [
|
|
5091
6857
|
4,
|
|
5092
6858
|
new Promise(function(resolve) {
|
|
@@ -5100,7 +6866,7 @@ var post13 = function(param) {
|
|
|
5100
6866
|
4,
|
|
5101
6867
|
runAdapter({
|
|
5102
6868
|
run: serializeRun({
|
|
5103
|
-
run:
|
|
6869
|
+
run: run3
|
|
5104
6870
|
}),
|
|
5105
6871
|
onEvent: onEvent({
|
|
5106
6872
|
controller: _object_spread_props(_object_spread({}, controller), {
|
|
@@ -5112,7 +6878,11 @@ var post13 = function(param) {
|
|
|
5112
6878
|
}),
|
|
5113
6879
|
getMessages: getMessages({
|
|
5114
6880
|
prisma: prisma,
|
|
5115
|
-
run:
|
|
6881
|
+
run: run3
|
|
6882
|
+
}),
|
|
6883
|
+
getThread: getThread({
|
|
6884
|
+
prisma: prisma,
|
|
6885
|
+
threadId: threadId
|
|
5116
6886
|
})
|
|
5117
6887
|
})
|
|
5118
6888
|
];
|
|
@@ -5134,7 +6904,7 @@ var post13 = function(param) {
|
|
|
5134
6904
|
_state.sent();
|
|
5135
6905
|
return [
|
|
5136
6906
|
2,
|
|
5137
|
-
new Response(JSON.stringify(
|
|
6907
|
+
new Response(JSON.stringify(run3), {
|
|
5138
6908
|
status: 200,
|
|
5139
6909
|
headers: {
|
|
5140
6910
|
"Content-Type": "application/json"
|
|
@@ -5154,16 +6924,76 @@ var post13 = function(param) {
|
|
|
5154
6924
|
}();
|
|
5155
6925
|
};
|
|
5156
6926
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/submitToolOutputs/index.ts
|
|
5157
|
-
var
|
|
6927
|
+
var submitToolOutputs2 = function(param) {
|
|
5158
6928
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
5159
6929
|
return {
|
|
5160
|
-
post:
|
|
6930
|
+
post: post17({
|
|
5161
6931
|
prisma: prisma,
|
|
5162
6932
|
// @ts-ignore-next-line
|
|
5163
6933
|
runAdapter: runAdapter
|
|
5164
6934
|
})
|
|
5165
6935
|
};
|
|
5166
6936
|
};
|
|
6937
|
+
// src/adapters/storage/prismaStorageAdapter/assistants/post.ts
|
|
6938
|
+
var import_dayjs15 = __toESM(require("dayjs"), 1);
|
|
6939
|
+
var post18 = function(param) {
|
|
6940
|
+
var prisma = param.prisma;
|
|
6941
|
+
return /*#__PURE__*/ function() {
|
|
6942
|
+
var _ref = _async_to_generator(function(_url, options) {
|
|
6943
|
+
var body, model, instructions, assistant, data;
|
|
6944
|
+
return _ts_generator(this, function(_state) {
|
|
6945
|
+
switch(_state.label){
|
|
6946
|
+
case 0:
|
|
6947
|
+
body = JSON.parse(options.body);
|
|
6948
|
+
model = body.model, instructions = body.instructions;
|
|
6949
|
+
return [
|
|
6950
|
+
4,
|
|
6951
|
+
prisma.assistant.create({
|
|
6952
|
+
data: {
|
|
6953
|
+
model: model,
|
|
6954
|
+
instructions: instructions
|
|
6955
|
+
}
|
|
6956
|
+
})
|
|
6957
|
+
];
|
|
6958
|
+
case 1:
|
|
6959
|
+
assistant = _state.sent();
|
|
6960
|
+
data = {
|
|
6961
|
+
id: assistant.id,
|
|
6962
|
+
object: "assistant",
|
|
6963
|
+
created_at: (0, import_dayjs15.default)().unix(),
|
|
6964
|
+
name: null,
|
|
6965
|
+
description: null,
|
|
6966
|
+
model: model,
|
|
6967
|
+
instructions: instructions,
|
|
6968
|
+
tools: [],
|
|
6969
|
+
metadata: {}
|
|
6970
|
+
};
|
|
6971
|
+
return [
|
|
6972
|
+
2,
|
|
6973
|
+
new Response(JSON.stringify(data), {
|
|
6974
|
+
status: 200,
|
|
6975
|
+
headers: {
|
|
6976
|
+
"Content-Type": "application/json"
|
|
6977
|
+
}
|
|
6978
|
+
})
|
|
6979
|
+
];
|
|
6980
|
+
}
|
|
6981
|
+
});
|
|
6982
|
+
});
|
|
6983
|
+
return function(_url, options) {
|
|
6984
|
+
return _ref.apply(this, arguments);
|
|
6985
|
+
};
|
|
6986
|
+
}();
|
|
6987
|
+
};
|
|
6988
|
+
// src/adapters/storage/prismaStorageAdapter/assistants/index.ts
|
|
6989
|
+
var assistants = function(param) {
|
|
6990
|
+
var prisma = param.prisma;
|
|
6991
|
+
return {
|
|
6992
|
+
post: post18({
|
|
6993
|
+
prisma: prisma
|
|
6994
|
+
})
|
|
6995
|
+
};
|
|
6996
|
+
};
|
|
5167
6997
|
// src/adapters/storage/prismaStorageAdapter/index.ts
|
|
5168
6998
|
var prismaStorageAdapter = function(param) {
|
|
5169
6999
|
var prisma = param.prisma;
|
|
@@ -5172,20 +7002,23 @@ var prismaStorageAdapter = function(param) {
|
|
|
5172
7002
|
var _obj;
|
|
5173
7003
|
return {
|
|
5174
7004
|
requestHandlers: (_obj = {
|
|
5175
|
-
"^/(?:v1
|
|
7005
|
+
"^/(?:v1/|openai/)?assistants$": assistants({
|
|
7006
|
+
prisma: prisma
|
|
7007
|
+
}),
|
|
7008
|
+
"^/(?:v1/|openai/)?threads$": threads2({
|
|
5176
7009
|
prisma: prisma
|
|
5177
7010
|
})
|
|
5178
|
-
}, _define_property(_obj, messagesRegexp,
|
|
7011
|
+
}, _define_property(_obj, messagesRegexp, messages4({
|
|
5179
7012
|
prisma: prisma
|
|
5180
|
-
})), _define_property(_obj, runsRegexp,
|
|
7013
|
+
})), _define_property(_obj, runsRegexp, runs2({
|
|
5181
7014
|
prisma: prisma,
|
|
5182
7015
|
runAdapter: runAdapter
|
|
5183
|
-
})), _define_property(_obj, runRegexp,
|
|
7016
|
+
})), _define_property(_obj, runRegexp, run2({
|
|
5184
7017
|
prisma: prisma,
|
|
5185
7018
|
runAdapter: runAdapter
|
|
5186
|
-
})), _define_property(_obj, stepsRegexp,
|
|
7019
|
+
})), _define_property(_obj, stepsRegexp, steps2({
|
|
5187
7020
|
prisma: prisma
|
|
5188
|
-
})), _define_property(_obj, submitToolOutputsRegexp,
|
|
7021
|
+
})), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs2({
|
|
5189
7022
|
prisma: prisma,
|
|
5190
7023
|
runAdapter: runAdapter
|
|
5191
7024
|
})), _obj)
|
|
@@ -5203,8 +7036,10 @@ var prismaStorageAdapter = function(param) {
|
|
|
5203
7036
|
mistralClientAdapter: mistralClientAdapter,
|
|
5204
7037
|
ollamaClientAdapter: ollamaClientAdapter,
|
|
5205
7038
|
openaiClientAdapter: openaiClientAdapter,
|
|
7039
|
+
openaiResponsesStorageAdapter: openaiResponsesStorageAdapter,
|
|
5206
7040
|
perplexityClientAdapter: perplexityClientAdapter,
|
|
5207
7041
|
prismaStorageAdapter: prismaStorageAdapter,
|
|
7042
|
+
responsesRunAdapter: responsesRunAdapter,
|
|
5208
7043
|
supercompat: supercompat,
|
|
5209
7044
|
togetherClientAdapter: togetherClientAdapter
|
|
5210
7045
|
});
|