supercompat 3.9.5 → 3.10.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 +899 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +851 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1859,7 +1859,7 @@ var models6 = function(param) {
|
|
|
1859
1859
|
};
|
|
1860
1860
|
};
|
|
1861
1861
|
// src/adapters/client/anthropicClientAdapter/completions/post.ts
|
|
1862
|
-
var
|
|
1862
|
+
var import_radash4 = require("radash");
|
|
1863
1863
|
// src/lib/messages/nonEmptyMessages.ts
|
|
1864
1864
|
var nonEmptyContent = function(param) {
|
|
1865
1865
|
var message = param.message;
|
|
@@ -1914,7 +1914,9 @@ var serializeTools = function(param) {
|
|
|
1914
1914
|
}
|
|
1915
1915
|
};
|
|
1916
1916
|
}
|
|
1917
|
-
return
|
|
1917
|
+
return _object_spread({
|
|
1918
|
+
type: tool.type
|
|
1919
|
+
}, tool[tool.type] || {});
|
|
1918
1920
|
});
|
|
1919
1921
|
};
|
|
1920
1922
|
// src/adapters/client/anthropicClientAdapter/completions/serializeMessages/serializeMessage.ts
|
|
@@ -1967,18 +1969,485 @@ var serializeMessages = function(param) {
|
|
|
1967
1969
|
});
|
|
1968
1970
|
});
|
|
1969
1971
|
};
|
|
1972
|
+
// src/adapters/client/anthropicClientAdapter/completions/serializeBetas.ts
|
|
1973
|
+
var serializeBetas = function(param) {
|
|
1974
|
+
var _param_tools = param.tools, tools = _param_tools === void 0 ? [] : _param_tools;
|
|
1975
|
+
var betas = [];
|
|
1976
|
+
if (tools.some(function(tool) {
|
|
1977
|
+
return tool.type === "computer_20250124";
|
|
1978
|
+
})) {
|
|
1979
|
+
betas.push("computer-use-2025-01-24");
|
|
1980
|
+
}
|
|
1981
|
+
if (tools.some(function(tool) {
|
|
1982
|
+
return tool.type === "code_execution_20250825";
|
|
1983
|
+
})) {
|
|
1984
|
+
betas.push("code-execution-2025-08-25");
|
|
1985
|
+
}
|
|
1986
|
+
if (!betas.length) {
|
|
1987
|
+
return {};
|
|
1988
|
+
}
|
|
1989
|
+
return {
|
|
1990
|
+
betas: betas
|
|
1991
|
+
};
|
|
1992
|
+
};
|
|
1993
|
+
// src/adapters/client/anthropicClientAdapter/normalizeComputerToolCallPayload.ts
|
|
1994
|
+
var import_radash3 = require("radash");
|
|
1995
|
+
var coordinateKeys = [
|
|
1996
|
+
"coordinate",
|
|
1997
|
+
"coordinates",
|
|
1998
|
+
"coordinate_start",
|
|
1999
|
+
"coordinate_end",
|
|
2000
|
+
"start",
|
|
2001
|
+
"end",
|
|
2002
|
+
"from",
|
|
2003
|
+
"to",
|
|
2004
|
+
"target",
|
|
2005
|
+
"point",
|
|
2006
|
+
"position",
|
|
2007
|
+
"cursor_position",
|
|
2008
|
+
"path"
|
|
2009
|
+
];
|
|
2010
|
+
var clickButtonMap = {
|
|
2011
|
+
left_click: "left",
|
|
2012
|
+
right_click: "right",
|
|
2013
|
+
middle_click: "wheel",
|
|
2014
|
+
double_click: "left",
|
|
2015
|
+
triple_click: "left",
|
|
2016
|
+
left_mouse_down: "left",
|
|
2017
|
+
left_mouse_up: "left"
|
|
2018
|
+
};
|
|
2019
|
+
var keyAliasMap = {
|
|
2020
|
+
ctrl: "ctrl",
|
|
2021
|
+
control: "ctrl",
|
|
2022
|
+
cmd: "meta",
|
|
2023
|
+
command: "meta",
|
|
2024
|
+
meta: "meta",
|
|
2025
|
+
win: "meta",
|
|
2026
|
+
option: "alt",
|
|
2027
|
+
alt: "alt",
|
|
2028
|
+
shift: "shift",
|
|
2029
|
+
enter: "enter",
|
|
2030
|
+
return: "enter",
|
|
2031
|
+
esc: "escape",
|
|
2032
|
+
escape: "escape",
|
|
2033
|
+
tab: "tab",
|
|
2034
|
+
space: "space",
|
|
2035
|
+
spacebar: "space",
|
|
2036
|
+
backspace: "backspace",
|
|
2037
|
+
del: "delete",
|
|
2038
|
+
delete: "delete",
|
|
2039
|
+
pageup: "pageup",
|
|
2040
|
+
pagedown: "pagedown",
|
|
2041
|
+
up: "up",
|
|
2042
|
+
down: "down",
|
|
2043
|
+
left: "left",
|
|
2044
|
+
right: "right"
|
|
2045
|
+
};
|
|
2046
|
+
var sanitizeNumber = function(value) {
|
|
2047
|
+
return typeof value === "number" ? value : void 0;
|
|
2048
|
+
};
|
|
2049
|
+
var toCoordinate = function(value) {
|
|
2050
|
+
if (!value) return void 0;
|
|
2051
|
+
if (Array.isArray(value)) {
|
|
2052
|
+
if (value.length === 2 && typeof value[0] === "number" && typeof value[1] === "number") {
|
|
2053
|
+
return {
|
|
2054
|
+
x: value[0],
|
|
2055
|
+
y: value[1]
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
if (value.length > 0 && Array.isArray(value[0])) {
|
|
2059
|
+
var tuple = value[0];
|
|
2060
|
+
if (tuple.length === 2 && typeof tuple[0] === "number" && typeof tuple[1] === "number") {
|
|
2061
|
+
return {
|
|
2062
|
+
x: tuple[0],
|
|
2063
|
+
y: tuple[1]
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
2069
|
+
var maybe = value;
|
|
2070
|
+
var x = sanitizeNumber(maybe.x);
|
|
2071
|
+
var y = sanitizeNumber(maybe.y);
|
|
2072
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
2073
|
+
return {
|
|
2074
|
+
x: x,
|
|
2075
|
+
y: y
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
if (typeof value === "string") {
|
|
2080
|
+
var parts = value.split(/[, ]+/).map(Number).filter(Number.isFinite);
|
|
2081
|
+
if (parts.length >= 2) {
|
|
2082
|
+
return {
|
|
2083
|
+
x: parts[0],
|
|
2084
|
+
y: parts[1]
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
return void 0;
|
|
2089
|
+
};
|
|
2090
|
+
var findCoordinatesInDetails = function(details) {
|
|
2091
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2092
|
+
try {
|
|
2093
|
+
for(var _iterator = coordinateKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2094
|
+
var key = _step.value;
|
|
2095
|
+
var value = details[key];
|
|
2096
|
+
var coords = toCoordinate(value);
|
|
2097
|
+
if (coords) {
|
|
2098
|
+
return coords;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
} catch (err) {
|
|
2102
|
+
_didIteratorError = true;
|
|
2103
|
+
_iteratorError = err;
|
|
2104
|
+
} finally{
|
|
2105
|
+
try {
|
|
2106
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2107
|
+
_iterator.return();
|
|
2108
|
+
}
|
|
2109
|
+
} finally{
|
|
2110
|
+
if (_didIteratorError) {
|
|
2111
|
+
throw _iteratorError;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
return void 0;
|
|
2116
|
+
};
|
|
2117
|
+
var buildDragPath = function(details) {
|
|
2118
|
+
var path = [];
|
|
2119
|
+
if (Array.isArray(details.path)) {
|
|
2120
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2121
|
+
try {
|
|
2122
|
+
for(var _iterator = details.path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2123
|
+
var point = _step.value;
|
|
2124
|
+
var coords = toCoordinate(point);
|
|
2125
|
+
if (coords) {
|
|
2126
|
+
path.push(coords);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
} catch (err) {
|
|
2130
|
+
_didIteratorError = true;
|
|
2131
|
+
_iteratorError = err;
|
|
2132
|
+
} finally{
|
|
2133
|
+
try {
|
|
2134
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2135
|
+
_iterator.return();
|
|
2136
|
+
}
|
|
2137
|
+
} finally{
|
|
2138
|
+
if (_didIteratorError) {
|
|
2139
|
+
throw _iteratorError;
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
if (!path.length) {
|
|
2145
|
+
var start = toCoordinate(details.coordinate_start) || toCoordinate(details.start) || toCoordinate(details.from);
|
|
2146
|
+
if (start) {
|
|
2147
|
+
path.push(start);
|
|
2148
|
+
}
|
|
2149
|
+
var end = toCoordinate(details.coordinate_end) || toCoordinate(details.end) || toCoordinate(details.to) || toCoordinate(details.target);
|
|
2150
|
+
if (end) {
|
|
2151
|
+
path.push(end);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
if (!path.length) {
|
|
2155
|
+
var coords1 = findCoordinatesInDetails(details);
|
|
2156
|
+
if (coords1) {
|
|
2157
|
+
path.push(coords1);
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
if (!path.length) {
|
|
2161
|
+
path.push({
|
|
2162
|
+
x: 0,
|
|
2163
|
+
y: 0
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
return path;
|
|
2167
|
+
};
|
|
2168
|
+
var parseKeys = function(input) {
|
|
2169
|
+
if (Array.isArray(input)) {
|
|
2170
|
+
return input.map(String).map(function(key) {
|
|
2171
|
+
return key.trim();
|
|
2172
|
+
}).filter(Boolean);
|
|
2173
|
+
}
|
|
2174
|
+
if (typeof input === "string") {
|
|
2175
|
+
return input.split(RegExp("(?:(?<!\\\\)\\+|\\s+)")).map(function(key) {
|
|
2176
|
+
return key.replace(/\\\+/g, "+");
|
|
2177
|
+
}).map(function(key) {
|
|
2178
|
+
return key.trim();
|
|
2179
|
+
}).filter(Boolean);
|
|
2180
|
+
}
|
|
2181
|
+
return [];
|
|
2182
|
+
};
|
|
2183
|
+
var normalizeKeys = function(keys) {
|
|
2184
|
+
return keys.map(function(key) {
|
|
2185
|
+
var lowerKey = key.toLowerCase();
|
|
2186
|
+
var _keyAliasMap_lowerKey;
|
|
2187
|
+
return (_keyAliasMap_lowerKey = keyAliasMap[lowerKey]) !== null && _keyAliasMap_lowerKey !== void 0 ? _keyAliasMap_lowerKey : lowerKey;
|
|
2188
|
+
});
|
|
2189
|
+
};
|
|
2190
|
+
var normalizeScroll = function(details) {
|
|
2191
|
+
var _sanitizeNumber;
|
|
2192
|
+
var scrollX = (_sanitizeNumber = sanitizeNumber(details.scroll_x)) !== null && _sanitizeNumber !== void 0 ? _sanitizeNumber : 0;
|
|
2193
|
+
var _sanitizeNumber1;
|
|
2194
|
+
var scrollY = (_sanitizeNumber1 = sanitizeNumber(details.scroll_y)) !== null && _sanitizeNumber1 !== void 0 ? _sanitizeNumber1 : 0;
|
|
2195
|
+
var _sanitizeNumber2, _ref;
|
|
2196
|
+
var amount = (_ref = (_sanitizeNumber2 = sanitizeNumber(details.scroll_amount)) !== null && _sanitizeNumber2 !== void 0 ? _sanitizeNumber2 : sanitizeNumber(details.amount)) !== null && _ref !== void 0 ? _ref : 0;
|
|
2197
|
+
var direction = typeof details.scroll_direction === "string" ? details.scroll_direction.toLowerCase() : typeof details.direction === "string" ? details.direction.toLowerCase() : void 0;
|
|
2198
|
+
if (!scrollX && !scrollY && direction && amount) {
|
|
2199
|
+
switch(direction){
|
|
2200
|
+
case "up":
|
|
2201
|
+
scrollY = -amount;
|
|
2202
|
+
break;
|
|
2203
|
+
case "down":
|
|
2204
|
+
scrollY = amount;
|
|
2205
|
+
break;
|
|
2206
|
+
case "left":
|
|
2207
|
+
scrollX = -amount;
|
|
2208
|
+
break;
|
|
2209
|
+
case "right":
|
|
2210
|
+
scrollX = amount;
|
|
2211
|
+
break;
|
|
2212
|
+
default:
|
|
2213
|
+
break;
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
return {
|
|
2217
|
+
scroll_x: scrollX,
|
|
2218
|
+
scroll_y: scrollY
|
|
2219
|
+
};
|
|
2220
|
+
};
|
|
2221
|
+
var normalizeActionString = function(action, details) {
|
|
2222
|
+
var coords = findCoordinatesInDetails(details);
|
|
2223
|
+
switch(action){
|
|
2224
|
+
case "screenshot":
|
|
2225
|
+
return {
|
|
2226
|
+
type: "screenshot"
|
|
2227
|
+
};
|
|
2228
|
+
case "left_click":
|
|
2229
|
+
case "right_click":
|
|
2230
|
+
case "middle_click":
|
|
2231
|
+
{
|
|
2232
|
+
var _coords_x, _coords_y;
|
|
2233
|
+
return {
|
|
2234
|
+
type: "click",
|
|
2235
|
+
button: clickButtonMap[action],
|
|
2236
|
+
x: (_coords_x = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x !== void 0 ? _coords_x : 0,
|
|
2237
|
+
y: (_coords_y = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y !== void 0 ? _coords_y : 0
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2240
|
+
case "double_click":
|
|
2241
|
+
var _coords_x1, _coords_y1;
|
|
2242
|
+
return {
|
|
2243
|
+
type: "double_click",
|
|
2244
|
+
x: (_coords_x1 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x1 !== void 0 ? _coords_x1 : 0,
|
|
2245
|
+
y: (_coords_y1 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y1 !== void 0 ? _coords_y1 : 0
|
|
2246
|
+
};
|
|
2247
|
+
case "triple_click":
|
|
2248
|
+
var _coords_x2, _coords_y2;
|
|
2249
|
+
return {
|
|
2250
|
+
type: "double_click",
|
|
2251
|
+
x: (_coords_x2 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x2 !== void 0 ? _coords_x2 : 0,
|
|
2252
|
+
y: (_coords_y2 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y2 !== void 0 ? _coords_y2 : 0,
|
|
2253
|
+
repetitions: 3
|
|
2254
|
+
};
|
|
2255
|
+
case "left_mouse_down":
|
|
2256
|
+
var _coords_x3, _coords_y3;
|
|
2257
|
+
return {
|
|
2258
|
+
type: "click",
|
|
2259
|
+
button: clickButtonMap[action],
|
|
2260
|
+
state: "down",
|
|
2261
|
+
x: (_coords_x3 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x3 !== void 0 ? _coords_x3 : 0,
|
|
2262
|
+
y: (_coords_y3 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y3 !== void 0 ? _coords_y3 : 0
|
|
2263
|
+
};
|
|
2264
|
+
case "left_mouse_up":
|
|
2265
|
+
var _coords_x4, _coords_y4;
|
|
2266
|
+
return {
|
|
2267
|
+
type: "click",
|
|
2268
|
+
button: clickButtonMap[action],
|
|
2269
|
+
state: "up",
|
|
2270
|
+
x: (_coords_x4 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x4 !== void 0 ? _coords_x4 : 0,
|
|
2271
|
+
y: (_coords_y4 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y4 !== void 0 ? _coords_y4 : 0
|
|
2272
|
+
};
|
|
2273
|
+
case "left_click_drag":
|
|
2274
|
+
{
|
|
2275
|
+
var path = buildDragPath(details).map(function(param) {
|
|
2276
|
+
var x = param.x, y = param.y;
|
|
2277
|
+
return {
|
|
2278
|
+
x: x,
|
|
2279
|
+
y: y
|
|
2280
|
+
};
|
|
2281
|
+
});
|
|
2282
|
+
return {
|
|
2283
|
+
type: "drag",
|
|
2284
|
+
path: path
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
case "mouse_move":
|
|
2288
|
+
case "cursor_position":
|
|
2289
|
+
var _coords_x5, _coords_y5;
|
|
2290
|
+
return {
|
|
2291
|
+
type: "move",
|
|
2292
|
+
x: (_coords_x5 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x5 !== void 0 ? _coords_x5 : 0,
|
|
2293
|
+
y: (_coords_y5 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y5 !== void 0 ? _coords_y5 : 0
|
|
2294
|
+
};
|
|
2295
|
+
case "scroll":
|
|
2296
|
+
{
|
|
2297
|
+
var _normalizeScroll = normalizeScroll(details), scroll_x = _normalizeScroll.scroll_x, scroll_y = _normalizeScroll.scroll_y;
|
|
2298
|
+
var _coords_x6, _coords_y6;
|
|
2299
|
+
return _object_spread({
|
|
2300
|
+
type: "scroll",
|
|
2301
|
+
x: (_coords_x6 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x6 !== void 0 ? _coords_x6 : 0,
|
|
2302
|
+
y: (_coords_y6 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y6 !== void 0 ? _coords_y6 : 0,
|
|
2303
|
+
scroll_x: scroll_x,
|
|
2304
|
+
scroll_y: scroll_y
|
|
2305
|
+
}, typeof details.scroll_direction === "string" ? {
|
|
2306
|
+
direction: details.scroll_direction
|
|
2307
|
+
} : typeof details.direction === "string" ? {
|
|
2308
|
+
direction: details.direction
|
|
2309
|
+
} : {}, typeof details.scroll_amount === "number" ? {
|
|
2310
|
+
amount: details.scroll_amount
|
|
2311
|
+
} : typeof details.amount === "number" ? {
|
|
2312
|
+
amount: details.amount
|
|
2313
|
+
} : {});
|
|
2314
|
+
}
|
|
2315
|
+
case "type":
|
|
2316
|
+
{
|
|
2317
|
+
var text = typeof details.text === "string" ? details.text : typeof details.input === "string" ? details.input : "";
|
|
2318
|
+
return {
|
|
2319
|
+
type: "type",
|
|
2320
|
+
text: text
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
case "key":
|
|
2324
|
+
case "hold_key":
|
|
2325
|
+
{
|
|
2326
|
+
var _details_text, _ref;
|
|
2327
|
+
var keys = normalizeKeys(parseKeys((_ref = (_details_text = details.text) !== null && _details_text !== void 0 ? _details_text : details.keys) !== null && _ref !== void 0 ? _ref : details.key));
|
|
2328
|
+
var normalized = {
|
|
2329
|
+
type: "keypress",
|
|
2330
|
+
keys: keys
|
|
2331
|
+
};
|
|
2332
|
+
if (action === "hold_key") {
|
|
2333
|
+
var duration = sanitizeNumber(details.duration);
|
|
2334
|
+
if (typeof duration === "number") {
|
|
2335
|
+
normalized.hold_duration_ms = Math.round(duration * 1e3);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
return normalized;
|
|
2339
|
+
}
|
|
2340
|
+
case "wait":
|
|
2341
|
+
{
|
|
2342
|
+
var duration1 = sanitizeNumber(details.duration);
|
|
2343
|
+
return _object_spread({
|
|
2344
|
+
type: "wait"
|
|
2345
|
+
}, typeof duration1 === "number" ? {
|
|
2346
|
+
duration_ms: Math.round(duration1 * 1e3)
|
|
2347
|
+
} : {});
|
|
2348
|
+
}
|
|
2349
|
+
default:
|
|
2350
|
+
{
|
|
2351
|
+
return _object_spread({
|
|
2352
|
+
type: action
|
|
2353
|
+
}, coords ? {
|
|
2354
|
+
x: coords.x,
|
|
2355
|
+
y: coords.y
|
|
2356
|
+
} : {}, (0, import_radash3.omit)(details, _to_consumable_array(coordinateKeys).concat([
|
|
2357
|
+
"text",
|
|
2358
|
+
"scroll_direction",
|
|
2359
|
+
"direction",
|
|
2360
|
+
"scroll_amount",
|
|
2361
|
+
"amount",
|
|
2362
|
+
"scroll_x",
|
|
2363
|
+
"scroll_y",
|
|
2364
|
+
"keys",
|
|
2365
|
+
"duration"
|
|
2366
|
+
])));
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
2370
|
+
var normalizeAction = function(payload) {
|
|
2371
|
+
if (payload && (typeof payload === "undefined" ? "undefined" : _type_of(payload)) === "object") {
|
|
2372
|
+
var rawAction = payload.action;
|
|
2373
|
+
if (typeof rawAction === "string") {
|
|
2374
|
+
var parsedAction = parseJson(rawAction);
|
|
2375
|
+
if (parsedAction && (typeof parsedAction === "undefined" ? "undefined" : _type_of(parsedAction)) === "object") {
|
|
2376
|
+
rawAction = parsedAction;
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
if (rawAction && (typeof rawAction === "undefined" ? "undefined" : _type_of(rawAction)) === "object" && typeof rawAction.type === "string") {
|
|
2380
|
+
return rawAction;
|
|
2381
|
+
}
|
|
2382
|
+
if (typeof rawAction === "string") {
|
|
2383
|
+
var details = (0, import_radash3.omit)(payload, [
|
|
2384
|
+
"action",
|
|
2385
|
+
"pending_safety_checks",
|
|
2386
|
+
"status"
|
|
2387
|
+
]);
|
|
2388
|
+
return normalizeActionString(rawAction, details);
|
|
2389
|
+
}
|
|
2390
|
+
if (typeof payload.type === "string") {
|
|
2391
|
+
return payload;
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
if (typeof payload === "string") {
|
|
2395
|
+
var parsed = parseJson(payload);
|
|
2396
|
+
if (parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === "object") {
|
|
2397
|
+
return normalizeAction(parsed);
|
|
2398
|
+
}
|
|
2399
|
+
return {
|
|
2400
|
+
type: payload
|
|
2401
|
+
};
|
|
2402
|
+
}
|
|
2403
|
+
return {
|
|
2404
|
+
type: "unknown",
|
|
2405
|
+
value: payload
|
|
2406
|
+
};
|
|
2407
|
+
};
|
|
2408
|
+
var normalizeComputerToolCallPayload = function(payload) {
|
|
2409
|
+
var normalizedPayload = payload;
|
|
2410
|
+
if (typeof payload === "string") {
|
|
2411
|
+
var parsed = parseJson(payload);
|
|
2412
|
+
if (parsed !== void 0) {
|
|
2413
|
+
normalizedPayload = parsed;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
var pendingSafetyChecksRaw = normalizedPayload && (typeof normalizedPayload === "undefined" ? "undefined" : _type_of(normalizedPayload)) === "object" ? normalizedPayload.pending_safety_checks : void 0;
|
|
2417
|
+
if (typeof pendingSafetyChecksRaw === "string") {
|
|
2418
|
+
var parsed1 = parseJson(pendingSafetyChecksRaw);
|
|
2419
|
+
pendingSafetyChecksRaw = Array.isArray(parsed1) ? parsed1 : [];
|
|
2420
|
+
}
|
|
2421
|
+
var pendingSafetyChecks = Array.isArray(pendingSafetyChecksRaw) ? pendingSafetyChecksRaw : [];
|
|
2422
|
+
var normalizedAction = normalizeAction(normalizedPayload);
|
|
2423
|
+
var result = {
|
|
2424
|
+
action: normalizedAction,
|
|
2425
|
+
pending_safety_checks: pendingSafetyChecks
|
|
2426
|
+
};
|
|
2427
|
+
if (normalizedPayload && (typeof normalizedPayload === "undefined" ? "undefined" : _type_of(normalizedPayload)) === "object" && "status" in normalizedPayload) {
|
|
2428
|
+
result.status = normalizedPayload.status;
|
|
2429
|
+
}
|
|
2430
|
+
return result;
|
|
2431
|
+
};
|
|
2432
|
+
var parseJson = function(value) {
|
|
2433
|
+
try {
|
|
2434
|
+
return JSON.parse(value);
|
|
2435
|
+
} catch (e) {
|
|
2436
|
+
return void 0;
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
1970
2439
|
// src/adapters/client/anthropicClientAdapter/completions/post.ts
|
|
1971
2440
|
var post5 = function(param) {
|
|
1972
2441
|
var anthropic = param.anthropic;
|
|
1973
2442
|
return /*#__PURE__*/ function() {
|
|
1974
2443
|
var _ref = _async_to_generator(function(_url, options) {
|
|
1975
|
-
var body, messages4, _ref, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, error;
|
|
2444
|
+
var body, messages4, _ref, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, normalizedContent, normalizedData, error;
|
|
1976
2445
|
return _ts_generator(this, function(_state) {
|
|
1977
2446
|
switch(_state.label){
|
|
1978
2447
|
case 0:
|
|
1979
2448
|
body = JSON.parse(options.body);
|
|
1980
2449
|
messages4 = body.messages;
|
|
1981
|
-
_ref = _sliced_to_array((0,
|
|
2450
|
+
_ref = _sliced_to_array((0, import_radash4.fork)(messages4, function(message) {
|
|
1982
2451
|
return message.role === "system";
|
|
1983
2452
|
}), 2), systemMessages = _ref[0], otherMessages = _ref[1];
|
|
1984
2453
|
system = systemMessages.map(function(message) {
|
|
@@ -1991,10 +2460,14 @@ var post5 = function(param) {
|
|
|
1991
2460
|
})
|
|
1992
2461
|
})
|
|
1993
2462
|
});
|
|
1994
|
-
resultOptions = _object_spread_props(_object_spread({}, (0,
|
|
2463
|
+
resultOptions = _object_spread_props(_object_spread(_object_spread_props(_object_spread({}, (0, import_radash4.omit)(body, [
|
|
1995
2464
|
"response_format"
|
|
1996
2465
|
])), {
|
|
1997
|
-
|
|
2466
|
+
model: body.model
|
|
2467
|
+
}), serializeBetas({
|
|
2468
|
+
tools: body.tools
|
|
2469
|
+
})), {
|
|
2470
|
+
stream: body.stream,
|
|
1998
2471
|
system: system,
|
|
1999
2472
|
messages: serializeMessages({
|
|
2000
2473
|
messages: chatMessages
|
|
@@ -2004,23 +2477,98 @@ var post5 = function(param) {
|
|
|
2004
2477
|
tools: body.tools
|
|
2005
2478
|
})
|
|
2006
2479
|
});
|
|
2007
|
-
if (!
|
|
2480
|
+
if (!resultOptions.stream) return [
|
|
2008
2481
|
3,
|
|
2009
2482
|
2
|
|
2010
2483
|
];
|
|
2011
2484
|
return [
|
|
2012
2485
|
4,
|
|
2013
|
-
anthropic.messages.
|
|
2486
|
+
anthropic.beta.messages.create(resultOptions)
|
|
2014
2487
|
];
|
|
2015
2488
|
case 1:
|
|
2016
2489
|
response = _state.sent();
|
|
2017
2490
|
stream = new ReadableStream({
|
|
2018
2491
|
start: function start(controller) {
|
|
2019
2492
|
return _async_to_generator(function() {
|
|
2020
|
-
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, messageDelta, delta1, messageDelta1, messageDelta2, err;
|
|
2493
|
+
var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex, parseJson2, getOrCreateIndexForToolUseId, assignBlockToToolUse, markComputerToolUse, getToolUseIdFromBlock, emitNormalizedToolCall, getOrCreateIndexForBlock, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _ref, chunk, toolUseId, _toolUseIdArgumentBuffer_get, buffered, parsed, normalized, toolCallIndex, chunkIndex, delta, toolUseId1, _toolUseIdArgumentBuffer_get1, existing, _chunk_delta_partial_json, updated, parsed1, normalized1, toolCallIndex1, chunkIndex1, _toolUseIdArgumentBuffer_get2, existing1, _chunk_delta_partial_json1, index, messageDelta, delta1, toolName, normalizedToolName, index1, index2, _chunk_content_block_content, outputPayload, _getToolUseIdFromBlock, toolCallId, index3, _getToolUseIdFromBlock1, toolCallId1, _chunk_content_block, _toolUseId, _type, _id, rest, index4, _chunk_content_block_content1, outputPayload1, messageDelta1, messageDelta2, err;
|
|
2021
2494
|
return _ts_generator(this, function(_state) {
|
|
2022
2495
|
switch(_state.label){
|
|
2023
2496
|
case 0:
|
|
2497
|
+
blockIndexToToolUseId = /* @__PURE__ */ new Map();
|
|
2498
|
+
toolUseIdToIndex = /* @__PURE__ */ new Map();
|
|
2499
|
+
toolUseIdArgumentBuffer = /* @__PURE__ */ new Map();
|
|
2500
|
+
computerToolUseIds = /* @__PURE__ */ new Set();
|
|
2501
|
+
normalizedComputerCalls = /* @__PURE__ */ new Set();
|
|
2502
|
+
nextToolCallIndex = 0;
|
|
2503
|
+
parseJson2 = function(value) {
|
|
2504
|
+
try {
|
|
2505
|
+
return JSON.parse(value);
|
|
2506
|
+
} catch (e) {
|
|
2507
|
+
return void 0;
|
|
2508
|
+
}
|
|
2509
|
+
};
|
|
2510
|
+
getOrCreateIndexForToolUseId = function(toolUseId) {
|
|
2511
|
+
if (!toolUseId) {
|
|
2512
|
+
return 0;
|
|
2513
|
+
}
|
|
2514
|
+
if (!toolUseIdToIndex.has(toolUseId)) {
|
|
2515
|
+
toolUseIdToIndex.set(toolUseId, nextToolCallIndex++);
|
|
2516
|
+
}
|
|
2517
|
+
var _toolUseIdToIndex_get;
|
|
2518
|
+
return (_toolUseIdToIndex_get = toolUseIdToIndex.get(toolUseId)) !== null && _toolUseIdToIndex_get !== void 0 ? _toolUseIdToIndex_get : 0;
|
|
2519
|
+
};
|
|
2520
|
+
assignBlockToToolUse = function(param) {
|
|
2521
|
+
var blockIndex = param.blockIndex, toolUseId = param.toolUseId;
|
|
2522
|
+
if (typeof blockIndex === "number" && toolUseId) {
|
|
2523
|
+
blockIndexToToolUseId.set(blockIndex, toolUseId);
|
|
2524
|
+
}
|
|
2525
|
+
};
|
|
2526
|
+
markComputerToolUse = function(toolUseId) {
|
|
2527
|
+
if (!toolUseId) return;
|
|
2528
|
+
computerToolUseIds.add(toolUseId);
|
|
2529
|
+
normalizedComputerCalls.delete(toolUseId);
|
|
2530
|
+
toolUseIdArgumentBuffer.set(toolUseId, "");
|
|
2531
|
+
};
|
|
2532
|
+
getToolUseIdFromBlock = function(block) {
|
|
2533
|
+
if (!block || (typeof block === "undefined" ? "undefined" : _type_of(block)) !== "object") return void 0;
|
|
2534
|
+
if (typeof block.tool_use_id === "string") {
|
|
2535
|
+
return block.tool_use_id;
|
|
2536
|
+
}
|
|
2537
|
+
if (typeof block.id === "string") {
|
|
2538
|
+
return block.id;
|
|
2539
|
+
}
|
|
2540
|
+
return void 0;
|
|
2541
|
+
};
|
|
2542
|
+
emitNormalizedToolCall = function(param) {
|
|
2543
|
+
var normalized = param.normalized, toolCallIndex = param.toolCallIndex, chunkIndex = param.chunkIndex;
|
|
2544
|
+
var messageDelta = {
|
|
2545
|
+
id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
|
|
2546
|
+
object: "chat.completion.chunk",
|
|
2547
|
+
choices: [
|
|
2548
|
+
{
|
|
2549
|
+
index: chunkIndex,
|
|
2550
|
+
delta: {
|
|
2551
|
+
tool_calls: [
|
|
2552
|
+
{
|
|
2553
|
+
index: toolCallIndex,
|
|
2554
|
+
function: {
|
|
2555
|
+
arguments: JSON.stringify(normalized)
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
]
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
]
|
|
2562
|
+
};
|
|
2563
|
+
controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
|
|
2564
|
+
};
|
|
2565
|
+
getOrCreateIndexForBlock = function(blockIndex) {
|
|
2566
|
+
if (typeof blockIndex !== "number") {
|
|
2567
|
+
return 0;
|
|
2568
|
+
}
|
|
2569
|
+
var toolUseId = blockIndexToToolUseId.get(blockIndex);
|
|
2570
|
+
return getOrCreateIndexForToolUseId(toolUseId);
|
|
2571
|
+
};
|
|
2024
2572
|
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
2025
2573
|
_state.label = 1;
|
|
2026
2574
|
case 1:
|
|
@@ -2043,14 +2591,79 @@ var post5 = function(param) {
|
|
|
2043
2591
|
5
|
|
2044
2592
|
];
|
|
2045
2593
|
_value = _step.value;
|
|
2046
|
-
|
|
2594
|
+
_ref = _value;
|
|
2595
|
+
chunk = _ref;
|
|
2596
|
+
if (chunk.type === "content_block_stop") {
|
|
2597
|
+
toolUseId = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
|
|
2598
|
+
if (toolUseId && computerToolUseIds.has(toolUseId) && !normalizedComputerCalls.has(toolUseId)) {
|
|
2599
|
+
;
|
|
2600
|
+
buffered = (_toolUseIdArgumentBuffer_get = toolUseIdArgumentBuffer.get(toolUseId)) !== null && _toolUseIdArgumentBuffer_get !== void 0 ? _toolUseIdArgumentBuffer_get : "";
|
|
2601
|
+
parsed = buffered ? parseJson2(buffered) : void 0;
|
|
2602
|
+
if (parsed !== void 0) {
|
|
2603
|
+
normalized = normalizeComputerToolCallPayload(parsed);
|
|
2604
|
+
toolCallIndex = getOrCreateIndexForToolUseId(toolUseId);
|
|
2605
|
+
chunkIndex = typeof chunk.index === "number" ? chunk.index : 0;
|
|
2606
|
+
emitNormalizedToolCall({
|
|
2607
|
+
normalized: normalized,
|
|
2608
|
+
toolCallIndex: toolCallIndex,
|
|
2609
|
+
chunkIndex: chunkIndex
|
|
2610
|
+
});
|
|
2611
|
+
normalizedComputerCalls.add(toolUseId);
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
if (toolUseId) {
|
|
2615
|
+
toolUseIdArgumentBuffer.delete(toolUseId);
|
|
2616
|
+
computerToolUseIds.delete(toolUseId);
|
|
2617
|
+
normalizedComputerCalls.delete(toolUseId);
|
|
2618
|
+
}
|
|
2619
|
+
if (typeof chunk.index === "number") {
|
|
2620
|
+
blockIndexToToolUseId.delete(chunk.index);
|
|
2621
|
+
}
|
|
2622
|
+
return [
|
|
2623
|
+
3,
|
|
2624
|
+
4
|
|
2625
|
+
];
|
|
2626
|
+
}
|
|
2047
2627
|
if (chunk.type === "content_block_delta") {
|
|
2048
2628
|
delta = void 0;
|
|
2049
2629
|
if (chunk.delta.type === "input_json_delta") {
|
|
2630
|
+
toolUseId1 = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
|
|
2631
|
+
if (toolUseId1 && computerToolUseIds.has(toolUseId1)) {
|
|
2632
|
+
;
|
|
2633
|
+
existing = (_toolUseIdArgumentBuffer_get1 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get1 !== void 0 ? _toolUseIdArgumentBuffer_get1 : "";
|
|
2634
|
+
;
|
|
2635
|
+
updated = "".concat(existing).concat((_chunk_delta_partial_json = chunk.delta.partial_json) !== null && _chunk_delta_partial_json !== void 0 ? _chunk_delta_partial_json : "");
|
|
2636
|
+
toolUseIdArgumentBuffer.set(toolUseId1, updated);
|
|
2637
|
+
if (!normalizedComputerCalls.has(toolUseId1)) {
|
|
2638
|
+
parsed1 = parseJson2(updated);
|
|
2639
|
+
if (parsed1 !== void 0) {
|
|
2640
|
+
normalized1 = normalizeComputerToolCallPayload(parsed1);
|
|
2641
|
+
toolCallIndex1 = getOrCreateIndexForToolUseId(toolUseId1);
|
|
2642
|
+
chunkIndex1 = typeof chunk.index === "number" ? chunk.index : 0;
|
|
2643
|
+
emitNormalizedToolCall({
|
|
2644
|
+
normalized: normalized1,
|
|
2645
|
+
toolCallIndex: toolCallIndex1,
|
|
2646
|
+
chunkIndex: chunkIndex1
|
|
2647
|
+
});
|
|
2648
|
+
normalizedComputerCalls.add(toolUseId1);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
return [
|
|
2652
|
+
3,
|
|
2653
|
+
4
|
|
2654
|
+
];
|
|
2655
|
+
}
|
|
2656
|
+
if (toolUseId1) {
|
|
2657
|
+
;
|
|
2658
|
+
existing1 = (_toolUseIdArgumentBuffer_get2 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get2 !== void 0 ? _toolUseIdArgumentBuffer_get2 : "";
|
|
2659
|
+
;
|
|
2660
|
+
toolUseIdArgumentBuffer.set(toolUseId1, "".concat(existing1).concat((_chunk_delta_partial_json1 = chunk.delta.partial_json) !== null && _chunk_delta_partial_json1 !== void 0 ? _chunk_delta_partial_json1 : ""));
|
|
2661
|
+
}
|
|
2662
|
+
index = getOrCreateIndexForBlock(chunk.index);
|
|
2050
2663
|
delta = {
|
|
2051
2664
|
tool_calls: [
|
|
2052
2665
|
{
|
|
2053
|
-
index:
|
|
2666
|
+
index: index,
|
|
2054
2667
|
function: {
|
|
2055
2668
|
arguments: chunk.delta.partial_json
|
|
2056
2669
|
}
|
|
@@ -2067,7 +2680,7 @@ var post5 = function(param) {
|
|
|
2067
2680
|
};
|
|
2068
2681
|
}
|
|
2069
2682
|
messageDelta = {
|
|
2070
|
-
id: "chatcmpl-".concat((0,
|
|
2683
|
+
id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
|
|
2071
2684
|
object: "chat.completion.chunk",
|
|
2072
2685
|
choices: [
|
|
2073
2686
|
{
|
|
@@ -2080,11 +2693,46 @@ var post5 = function(param) {
|
|
|
2080
2693
|
} else if (chunk.type === "content_block_start") {
|
|
2081
2694
|
delta1 = void 0;
|
|
2082
2695
|
if (chunk.content_block.type === "tool_use") {
|
|
2696
|
+
toolName = chunk.content_block.name;
|
|
2697
|
+
normalizedToolName = toolName === "computer" ? "computer_call" : toolName;
|
|
2698
|
+
index1 = getOrCreateIndexForToolUseId(chunk.content_block.id);
|
|
2699
|
+
assignBlockToToolUse({
|
|
2700
|
+
blockIndex: chunk.index,
|
|
2701
|
+
toolUseId: chunk.content_block.id
|
|
2702
|
+
});
|
|
2703
|
+
if (normalizedToolName === "computer_call") {
|
|
2704
|
+
markComputerToolUse(chunk.content_block.id);
|
|
2705
|
+
} else if (!toolUseIdArgumentBuffer.has(chunk.content_block.id)) {
|
|
2706
|
+
toolUseIdArgumentBuffer.set(chunk.content_block.id, "");
|
|
2707
|
+
}
|
|
2708
|
+
delta1 = {
|
|
2709
|
+
content: null,
|
|
2710
|
+
tool_calls: [
|
|
2711
|
+
{
|
|
2712
|
+
index: index1,
|
|
2713
|
+
id: chunk.content_block.id,
|
|
2714
|
+
type: "function",
|
|
2715
|
+
function: {
|
|
2716
|
+
name: normalizedToolName,
|
|
2717
|
+
arguments: ""
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
]
|
|
2721
|
+
};
|
|
2722
|
+
} else if (chunk.content_block.type === "server_tool_use") {
|
|
2723
|
+
index2 = getOrCreateIndexForToolUseId(chunk.content_block.id);
|
|
2724
|
+
assignBlockToToolUse({
|
|
2725
|
+
blockIndex: chunk.index,
|
|
2726
|
+
toolUseId: chunk.content_block.id
|
|
2727
|
+
});
|
|
2728
|
+
if (!toolUseIdArgumentBuffer.has(chunk.content_block.id)) {
|
|
2729
|
+
toolUseIdArgumentBuffer.set(chunk.content_block.id, "");
|
|
2730
|
+
}
|
|
2083
2731
|
delta1 = {
|
|
2084
2732
|
content: null,
|
|
2085
2733
|
tool_calls: [
|
|
2086
2734
|
{
|
|
2087
|
-
index:
|
|
2735
|
+
index: index2,
|
|
2088
2736
|
id: chunk.content_block.id,
|
|
2089
2737
|
type: "function",
|
|
2090
2738
|
function: {
|
|
@@ -2094,6 +2742,65 @@ var post5 = function(param) {
|
|
|
2094
2742
|
}
|
|
2095
2743
|
]
|
|
2096
2744
|
};
|
|
2745
|
+
} else if (chunk.content_block.type === "web_search_tool_result") {
|
|
2746
|
+
;
|
|
2747
|
+
outputPayload = {
|
|
2748
|
+
content: (_chunk_content_block_content = chunk.content_block.content) !== null && _chunk_content_block_content !== void 0 ? _chunk_content_block_content : []
|
|
2749
|
+
};
|
|
2750
|
+
;
|
|
2751
|
+
toolCallId = (_getToolUseIdFromBlock = getToolUseIdFromBlock(chunk.content_block)) !== null && _getToolUseIdFromBlock !== void 0 ? _getToolUseIdFromBlock : "";
|
|
2752
|
+
index3 = getOrCreateIndexForToolUseId(toolCallId);
|
|
2753
|
+
assignBlockToToolUse({
|
|
2754
|
+
blockIndex: chunk.index,
|
|
2755
|
+
toolUseId: toolCallId
|
|
2756
|
+
});
|
|
2757
|
+
delta1 = {
|
|
2758
|
+
content: null,
|
|
2759
|
+
tool_calls: [
|
|
2760
|
+
{
|
|
2761
|
+
index: index3,
|
|
2762
|
+
id: toolCallId,
|
|
2763
|
+
type: "function",
|
|
2764
|
+
function: {
|
|
2765
|
+
output: JSON.stringify(outputPayload)
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
]
|
|
2769
|
+
};
|
|
2770
|
+
} else if ([
|
|
2771
|
+
"code_execution_tool_result",
|
|
2772
|
+
"bash_code_execution_tool_result",
|
|
2773
|
+
"python_code_execution_tool_result"
|
|
2774
|
+
].includes(chunk.content_block.type)) {
|
|
2775
|
+
;
|
|
2776
|
+
toolCallId1 = (_getToolUseIdFromBlock1 = getToolUseIdFromBlock(chunk.content_block)) !== null && _getToolUseIdFromBlock1 !== void 0 ? _getToolUseIdFromBlock1 : "";
|
|
2777
|
+
_chunk_content_block = chunk.content_block, _toolUseId = _chunk_content_block.tool_use_id, _type = _chunk_content_block.type, _id = _chunk_content_block.id, rest = _object_without_properties(_chunk_content_block, [
|
|
2778
|
+
"tool_use_id",
|
|
2779
|
+
"type",
|
|
2780
|
+
"id"
|
|
2781
|
+
]);
|
|
2782
|
+
index4 = getOrCreateIndexForToolUseId(toolCallId1);
|
|
2783
|
+
assignBlockToToolUse({
|
|
2784
|
+
blockIndex: chunk.index,
|
|
2785
|
+
toolUseId: toolCallId1
|
|
2786
|
+
});
|
|
2787
|
+
;
|
|
2788
|
+
outputPayload1 = Object.keys(rest).length > 0 ? rest : {
|
|
2789
|
+
content: (_chunk_content_block_content1 = chunk.content_block.content) !== null && _chunk_content_block_content1 !== void 0 ? _chunk_content_block_content1 : {}
|
|
2790
|
+
};
|
|
2791
|
+
delta1 = {
|
|
2792
|
+
content: null,
|
|
2793
|
+
tool_calls: [
|
|
2794
|
+
{
|
|
2795
|
+
index: index4,
|
|
2796
|
+
id: toolCallId1,
|
|
2797
|
+
type: "function",
|
|
2798
|
+
function: {
|
|
2799
|
+
output: JSON.stringify(outputPayload1)
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
]
|
|
2803
|
+
};
|
|
2097
2804
|
} else if ("text" in chunk.content_block) {
|
|
2098
2805
|
delta1 = {
|
|
2099
2806
|
content: chunk.content_block.text
|
|
@@ -2104,7 +2811,7 @@ var post5 = function(param) {
|
|
|
2104
2811
|
};
|
|
2105
2812
|
}
|
|
2106
2813
|
messageDelta1 = {
|
|
2107
|
-
id: "chatcmpl-".concat((0,
|
|
2814
|
+
id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
|
|
2108
2815
|
object: "chat.completion.chunk",
|
|
2109
2816
|
choices: [
|
|
2110
2817
|
{
|
|
@@ -2116,7 +2823,7 @@ var post5 = function(param) {
|
|
|
2116
2823
|
controller.enqueue("data: ".concat(JSON.stringify(messageDelta1), "\n\n"));
|
|
2117
2824
|
} else if (chunk.type === "message_start") {
|
|
2118
2825
|
messageDelta2 = {
|
|
2119
|
-
id: "chatcmpl-".concat((0,
|
|
2826
|
+
id: "chatcmpl-".concat((0, import_radash4.uid)(29)),
|
|
2120
2827
|
object: "chat.completion.chunk",
|
|
2121
2828
|
choices: [
|
|
2122
2829
|
{
|
|
@@ -2214,10 +2921,22 @@ var post5 = function(param) {
|
|
|
2214
2921
|
];
|
|
2215
2922
|
case 3:
|
|
2216
2923
|
data = _state.sent();
|
|
2924
|
+
normalizedContent = Array.isArray(data === null || data === void 0 ? void 0 : data.content) ? data.content.map(function(block) {
|
|
2925
|
+
if ((block === null || block === void 0 ? void 0 : block.type) === "tool_use" && (block === null || block === void 0 ? void 0 : block.name) === "computer") {
|
|
2926
|
+
var _block_input;
|
|
2927
|
+
return _object_spread_props(_object_spread({}, block), {
|
|
2928
|
+
input: normalizeComputerToolCallPayload((_block_input = block.input) !== null && _block_input !== void 0 ? _block_input : {})
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
return block;
|
|
2932
|
+
}) : data === null || data === void 0 ? void 0 : data.content;
|
|
2933
|
+
normalizedData = _object_spread({}, data, normalizedContent ? {
|
|
2934
|
+
content: normalizedContent
|
|
2935
|
+
} : {});
|
|
2217
2936
|
return [
|
|
2218
2937
|
2,
|
|
2219
2938
|
new Response(JSON.stringify({
|
|
2220
|
-
data:
|
|
2939
|
+
data: normalizedData
|
|
2221
2940
|
}), {
|
|
2222
2941
|
status: 200,
|
|
2223
2942
|
headers: {
|
|
@@ -3287,21 +4006,21 @@ var ollamaClientAdapter = function(param) {
|
|
|
3287
4006
|
};
|
|
3288
4007
|
// src/adapters/run/completionsRunAdapter/index.ts
|
|
3289
4008
|
var import_lodash = __toESM(require("lodash"), 1);
|
|
3290
|
-
var
|
|
4009
|
+
var import_radash7 = require("radash");
|
|
3291
4010
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
3292
4011
|
// src/adapters/run/completionsRunAdapter/messages/index.ts
|
|
3293
|
-
var
|
|
4012
|
+
var import_radash6 = require("radash");
|
|
3294
4013
|
// src/adapters/run/completionsRunAdapter/messages/serializeMessage.ts
|
|
3295
|
-
var
|
|
4014
|
+
var import_radash5 = require("radash");
|
|
3296
4015
|
var validToolCallContentTypes = [
|
|
3297
4016
|
"image",
|
|
3298
4017
|
"text"
|
|
3299
4018
|
];
|
|
3300
4019
|
var serializeToolContent = function(param) {
|
|
3301
4020
|
var toolCall = param.toolCall;
|
|
3302
|
-
if ((0,
|
|
4021
|
+
if ((0, import_radash5.isArray)(toolCall.function.output)) {
|
|
3303
4022
|
var isEveryToolPartValid = toolCall.function.output.every(function(toolPart) {
|
|
3304
|
-
if (!(0,
|
|
4023
|
+
if (!(0, import_radash5.isObject)(toolPart)) return false;
|
|
3305
4024
|
return validToolCallContentTypes.includes(toolPart.type);
|
|
3306
4025
|
});
|
|
3307
4026
|
if (isEveryToolPartValid) {
|
|
@@ -3389,7 +4108,7 @@ var messages = /*#__PURE__*/ function() {
|
|
|
3389
4108
|
content: run3.instructions
|
|
3390
4109
|
}
|
|
3391
4110
|
] : [])).concat;
|
|
3392
|
-
_2 = (0,
|
|
4111
|
+
_2 = (0, import_radash6.flat);
|
|
3393
4112
|
return [
|
|
3394
4113
|
4,
|
|
3395
4114
|
getMessages2()
|
|
@@ -3419,7 +4138,7 @@ var messages = /*#__PURE__*/ function() {
|
|
|
3419
4138
|
// src/adapters/run/completionsRunAdapter/index.ts
|
|
3420
4139
|
var updatedToolCall = function(param) {
|
|
3421
4140
|
var toolCall = param.toolCall, delta = param.delta;
|
|
3422
|
-
if (!toolCall) return (0,
|
|
4141
|
+
if (!toolCall) return (0, import_radash7.omit)(delta, [
|
|
3423
4142
|
"index"
|
|
3424
4143
|
]);
|
|
3425
4144
|
var result = import_lodash.default.cloneDeep(toolCall);
|
|
@@ -3450,10 +4169,11 @@ var toolCallsData = function(param) {
|
|
|
3450
4169
|
var prevToolCalls = param.prevToolCalls, delta = param.delta;
|
|
3451
4170
|
if (!prevToolCalls) {
|
|
3452
4171
|
return delta.tool_calls.map(function(tc) {
|
|
4172
|
+
var _tc_type;
|
|
3453
4173
|
return _object_spread({
|
|
3454
|
-
id: (0,
|
|
3455
|
-
type: "function"
|
|
3456
|
-
}, (0,
|
|
4174
|
+
id: (0, import_radash7.uid)(24),
|
|
4175
|
+
type: (_tc_type = tc.type) !== null && _tc_type !== void 0 ? _tc_type : "function"
|
|
4176
|
+
}, (0, import_radash7.omit)(tc, [
|
|
3457
4177
|
"index"
|
|
3458
4178
|
]));
|
|
3459
4179
|
});
|
|
@@ -3488,7 +4208,7 @@ var completionsRunAdapter = function() {
|
|
|
3488
4208
|
return {
|
|
3489
4209
|
handleRun: /*#__PURE__*/ function() {
|
|
3490
4210
|
var _ref = _async_to_generator(function(param) {
|
|
3491
|
-
var client, run3, onEvent2, getMessages2, 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;
|
|
4211
|
+
var client, run3, onEvent2, getMessages2, 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, _message_toolCalls, messageToolCalls, functionToolCalls, pendingFunctionToolCalls, requiredToolCalls;
|
|
3492
4212
|
return _ts_generator(this, function(_state) {
|
|
3493
4213
|
switch(_state.label){
|
|
3494
4214
|
case 0:
|
|
@@ -3513,7 +4233,7 @@ var completionsRunAdapter = function() {
|
|
|
3513
4233
|
case 1:
|
|
3514
4234
|
opts = _object_spread.apply(void 0, [
|
|
3515
4235
|
(_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
|
|
3516
|
-
(0,
|
|
4236
|
+
(0, import_radash7.isEmpty)(run3.tools) ? {} : {
|
|
3517
4237
|
tools: run3.tools
|
|
3518
4238
|
}
|
|
3519
4239
|
]);
|
|
@@ -3695,9 +4415,10 @@ var completionsRunAdapter = function() {
|
|
|
3695
4415
|
step_details: {
|
|
3696
4416
|
type: "tool_calls",
|
|
3697
4417
|
tool_calls: delta.tool_calls.map(function(tc) {
|
|
4418
|
+
var _tc_type;
|
|
3698
4419
|
return _object_spread({
|
|
3699
|
-
id: (0,
|
|
3700
|
-
type: "function"
|
|
4420
|
+
id: (0, import_radash7.uid)(24),
|
|
4421
|
+
type: (_tc_type = tc.type) !== null && _tc_type !== void 0 ? _tc_type : "function"
|
|
3701
4422
|
}, tc);
|
|
3702
4423
|
})
|
|
3703
4424
|
}
|
|
@@ -3805,18 +4526,83 @@ var completionsRunAdapter = function() {
|
|
|
3805
4526
|
];
|
|
3806
4527
|
case 22:
|
|
3807
4528
|
message = _state.sent();
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
4529
|
+
messageToolCalls = (_message_toolCalls = message.toolCalls) !== null && _message_toolCalls !== void 0 ? _message_toolCalls : [];
|
|
4530
|
+
functionToolCalls = messageToolCalls.filter(function(toolCall) {
|
|
4531
|
+
return toolCall.type === "function";
|
|
4532
|
+
});
|
|
4533
|
+
pendingFunctionToolCalls = functionToolCalls.filter(function(toolCall) {
|
|
4534
|
+
var _toolCall_function;
|
|
4535
|
+
return !((_toolCall_function = toolCall.function) === null || _toolCall_function === void 0 ? void 0 : _toolCall_function.output);
|
|
4536
|
+
});
|
|
4537
|
+
if (!(0, import_radash7.isEmpty)(pendingFunctionToolCalls)) return [
|
|
4538
|
+
3,
|
|
4539
|
+
25
|
|
4540
|
+
];
|
|
4541
|
+
if (!toolCallsRunStep) return [
|
|
4542
|
+
3,
|
|
4543
|
+
24
|
|
4544
|
+
];
|
|
4545
|
+
return [
|
|
4546
|
+
4,
|
|
4547
|
+
onEvent2({
|
|
4548
|
+
event: "thread.run.step.completed",
|
|
4549
|
+
data: _object_spread_props(_object_spread({}, toolCallsRunStep), {
|
|
4550
|
+
status: "completed",
|
|
4551
|
+
completed_at: (0, import_dayjs.default)().unix(),
|
|
4552
|
+
step_details: {
|
|
4553
|
+
type: "tool_calls",
|
|
4554
|
+
tool_calls: currentToolCalls !== null && currentToolCalls !== void 0 ? currentToolCalls : []
|
|
4555
|
+
}
|
|
3817
4556
|
})
|
|
3818
|
-
|
|
3819
|
-
|
|
4557
|
+
})
|
|
4558
|
+
];
|
|
4559
|
+
case 23:
|
|
4560
|
+
toolCallsRunStep = _state.sent();
|
|
4561
|
+
_state.label = 24;
|
|
4562
|
+
case 24:
|
|
4563
|
+
return [
|
|
4564
|
+
2,
|
|
4565
|
+
onEvent2({
|
|
4566
|
+
event: "thread.run.completed",
|
|
4567
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
4568
|
+
status: "completed",
|
|
4569
|
+
completed_at: (0, import_dayjs.default)().unix()
|
|
4570
|
+
})
|
|
4571
|
+
})
|
|
4572
|
+
];
|
|
4573
|
+
case 25:
|
|
4574
|
+
requiredToolCalls = pendingFunctionToolCalls.map(function(toolCall) {
|
|
4575
|
+
var _toolCall_function, _toolCall_function1, _toolCall_function2;
|
|
4576
|
+
var _toolCall_function_arguments;
|
|
4577
|
+
var args = (_toolCall_function_arguments = (_toolCall_function = toolCall.function) === null || _toolCall_function === void 0 ? void 0 : _toolCall_function.arguments) !== null && _toolCall_function_arguments !== void 0 ? _toolCall_function_arguments : "";
|
|
4578
|
+
if (((_toolCall_function1 = toolCall.function) === null || _toolCall_function1 === void 0 ? void 0 : _toolCall_function1.name) === "computer_call") {
|
|
4579
|
+
var parsedArguments = {};
|
|
4580
|
+
try {
|
|
4581
|
+
parsedArguments = JSON.parse(args || "{}");
|
|
4582
|
+
} catch (e) {
|
|
4583
|
+
parsedArguments = {};
|
|
4584
|
+
}
|
|
4585
|
+
var _parsedArguments_action, _ref;
|
|
4586
|
+
var computerCall = {
|
|
4587
|
+
action: (_ref = (_parsedArguments_action = parsedArguments === null || parsedArguments === void 0 ? void 0 : parsedArguments.action) !== null && _parsedArguments_action !== void 0 ? _parsedArguments_action : parsedArguments) !== null && _ref !== void 0 ? _ref : {},
|
|
4588
|
+
pending_safety_checks: Array.isArray(parsedArguments === null || parsedArguments === void 0 ? void 0 : parsedArguments.pending_safety_checks) ? parsedArguments.pending_safety_checks : []
|
|
4589
|
+
};
|
|
4590
|
+
return {
|
|
4591
|
+
id: toolCall.id,
|
|
4592
|
+
type: "computer_call",
|
|
4593
|
+
computer_call: computerCall
|
|
4594
|
+
};
|
|
4595
|
+
}
|
|
4596
|
+
var _toolCall_function_name;
|
|
4597
|
+
return {
|
|
4598
|
+
id: toolCall.id,
|
|
4599
|
+
type: "function",
|
|
4600
|
+
function: {
|
|
4601
|
+
name: (_toolCall_function_name = (_toolCall_function2 = toolCall.function) === null || _toolCall_function2 === void 0 ? void 0 : _toolCall_function2.name) !== null && _toolCall_function_name !== void 0 ? _toolCall_function_name : "",
|
|
4602
|
+
arguments: args
|
|
4603
|
+
}
|
|
4604
|
+
};
|
|
4605
|
+
});
|
|
3820
4606
|
return [
|
|
3821
4607
|
2,
|
|
3822
4608
|
onEvent2({
|
|
@@ -3826,7 +4612,7 @@ var completionsRunAdapter = function() {
|
|
|
3826
4612
|
required_action: {
|
|
3827
4613
|
type: "submit_tool_outputs",
|
|
3828
4614
|
submit_tool_outputs: {
|
|
3829
|
-
tool_calls:
|
|
4615
|
+
tool_calls: requiredToolCalls
|
|
3830
4616
|
}
|
|
3831
4617
|
}
|
|
3832
4618
|
})
|
|
@@ -3952,10 +4738,10 @@ var threads = function(param) {
|
|
|
3952
4738
|
};
|
|
3953
4739
|
};
|
|
3954
4740
|
// src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
|
|
3955
|
-
var
|
|
4741
|
+
var import_radash9 = require("radash");
|
|
3956
4742
|
// src/adapters/storage/prismaStorageAdapter/threads/messages/serializeMessage.ts
|
|
3957
4743
|
var import_dayjs4 = __toESM(require("dayjs"), 1);
|
|
3958
|
-
var
|
|
4744
|
+
var import_radash8 = require("radash");
|
|
3959
4745
|
var serializeMessage4 = function(param) {
|
|
3960
4746
|
var message = param.message;
|
|
3961
4747
|
var _message_metadata;
|
|
@@ -3973,7 +4759,7 @@ var serializeMessage4 = function(param) {
|
|
|
3973
4759
|
run_id: message.runId,
|
|
3974
4760
|
attachments: message.attachments,
|
|
3975
4761
|
status: message.status.toLowerCase(),
|
|
3976
|
-
metadata: (0,
|
|
4762
|
+
metadata: (0, import_radash8.assign)((_message_metadata = message.metadata) !== null && _message_metadata !== void 0 ? _message_metadata : {}, message.toolCalls ? {
|
|
3977
4763
|
toolCalls: message.toolCalls
|
|
3978
4764
|
} : {})
|
|
3979
4765
|
};
|
|
@@ -3981,7 +4767,7 @@ var serializeMessage4 = function(param) {
|
|
|
3981
4767
|
// src/adapters/storage/prismaStorageAdapter/threads/messages/post.ts
|
|
3982
4768
|
var messageContentBlocks = function(param) {
|
|
3983
4769
|
var content = param.content;
|
|
3984
|
-
if ((0,
|
|
4770
|
+
if ((0, import_radash9.isArray)(content)) {
|
|
3985
4771
|
return content.map(function(item) {
|
|
3986
4772
|
if (item.type === "text") {
|
|
3987
4773
|
var _item_text;
|
|
@@ -4056,7 +4842,7 @@ var post11 = function(param) {
|
|
|
4056
4842
|
}();
|
|
4057
4843
|
};
|
|
4058
4844
|
// src/adapters/storage/prismaStorageAdapter/threads/messages/get.ts
|
|
4059
|
-
var
|
|
4845
|
+
var import_radash10 = require("radash");
|
|
4060
4846
|
var get10 = function(param) {
|
|
4061
4847
|
var prisma = param.prisma;
|
|
4062
4848
|
return /*#__PURE__*/ function() {
|
|
@@ -4067,7 +4853,7 @@ var get10 = function(param) {
|
|
|
4067
4853
|
case 0:
|
|
4068
4854
|
url = new URL(urlString);
|
|
4069
4855
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
4070
|
-
_ref = (0,
|
|
4856
|
+
_ref = (0, import_radash10.assign)({
|
|
4071
4857
|
limit: "20",
|
|
4072
4858
|
order: "desc"
|
|
4073
4859
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -4101,7 +4887,7 @@ var get10 = function(param) {
|
|
|
4101
4887
|
});
|
|
4102
4888
|
}),
|
|
4103
4889
|
has_more: messagesPlusOne.length > pageSize,
|
|
4104
|
-
last_id: (_id = (_this = (0,
|
|
4890
|
+
last_id: (_id = (_this = (0, import_radash10.last)(messages4)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
|
|
4105
4891
|
}), {
|
|
4106
4892
|
status: 200,
|
|
4107
4893
|
headers: {
|
|
@@ -4130,7 +4916,7 @@ var messages2 = function(param) {
|
|
|
4130
4916
|
};
|
|
4131
4917
|
};
|
|
4132
4918
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
|
|
4133
|
-
var
|
|
4919
|
+
var import_radash11 = require("radash");
|
|
4134
4920
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
|
|
4135
4921
|
var import_dayjs5 = __toESM(require("dayjs"), 1);
|
|
4136
4922
|
var serializeRun = function(param) {
|
|
@@ -4205,7 +4991,7 @@ var get11 = function(param) {
|
|
|
4205
4991
|
case 0:
|
|
4206
4992
|
url = new URL(urlString);
|
|
4207
4993
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
|
|
4208
|
-
_ref = (0,
|
|
4994
|
+
_ref = (0, import_radash11.assign)({
|
|
4209
4995
|
limit: "20",
|
|
4210
4996
|
order: "desc"
|
|
4211
4997
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -4257,7 +5043,7 @@ var get11 = function(param) {
|
|
|
4257
5043
|
};
|
|
4258
5044
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/post.ts
|
|
4259
5045
|
var import_dayjs7 = __toESM(require("dayjs"), 1);
|
|
4260
|
-
var
|
|
5046
|
+
var import_radash12 = require("radash");
|
|
4261
5047
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunInProgress.ts
|
|
4262
5048
|
var threadRunInProgress = function(param) {
|
|
4263
5049
|
var prisma = param.prisma, event = param.event, controller = param.controller;
|
|
@@ -4399,6 +5185,40 @@ var threadRunStepDelta = function(param) {
|
|
|
4399
5185
|
var event = param.event, controller = param.controller;
|
|
4400
5186
|
return controller.enqueue(event);
|
|
4401
5187
|
};
|
|
5188
|
+
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunStepCompleted.ts
|
|
5189
|
+
var threadRunStepCompleted = /*#__PURE__*/ function() {
|
|
5190
|
+
var _ref = _async_to_generator(function(param) {
|
|
5191
|
+
var prisma, event, controller;
|
|
5192
|
+
return _ts_generator(this, function(_state) {
|
|
5193
|
+
switch(_state.label){
|
|
5194
|
+
case 0:
|
|
5195
|
+
prisma = param.prisma, event = param.event, controller = param.controller;
|
|
5196
|
+
controller.enqueue(event);
|
|
5197
|
+
return [
|
|
5198
|
+
4,
|
|
5199
|
+
prisma.runStep.update({
|
|
5200
|
+
where: {
|
|
5201
|
+
id: event.data.id
|
|
5202
|
+
},
|
|
5203
|
+
data: {
|
|
5204
|
+
status: "COMPLETED" /* COMPLETED */ ,
|
|
5205
|
+
stepDetails: event.data.step_details,
|
|
5206
|
+
completedAt: event.data.completed_at
|
|
5207
|
+
}
|
|
5208
|
+
})
|
|
5209
|
+
];
|
|
5210
|
+
case 1:
|
|
5211
|
+
_state.sent();
|
|
5212
|
+
return [
|
|
5213
|
+
2
|
|
5214
|
+
];
|
|
5215
|
+
}
|
|
5216
|
+
});
|
|
5217
|
+
});
|
|
5218
|
+
return function threadRunStepCompleted(_) {
|
|
5219
|
+
return _ref.apply(this, arguments);
|
|
5220
|
+
};
|
|
5221
|
+
}();
|
|
4402
5222
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadMessageCreated.ts
|
|
4403
5223
|
var status2 = function(event) {
|
|
4404
5224
|
if (event.data.status === "completed") return "COMPLETED" /* COMPLETED */ ;
|
|
@@ -4529,6 +5349,7 @@ var handlers = {
|
|
|
4529
5349
|
"thread.run.requires_action": threadRunRequiresAction,
|
|
4530
5350
|
"thread.run.step.created": threadRunStepCreated,
|
|
4531
5351
|
"thread.run.step.delta": threadRunStepDelta,
|
|
5352
|
+
"thread.run.step.completed": threadRunStepCompleted,
|
|
4532
5353
|
"thread.message.created": threadMessageCreated,
|
|
4533
5354
|
"thread.message.delta": threadMessageDelta,
|
|
4534
5355
|
"thread.message.completed": threadMessageCompleted
|
|
@@ -4650,7 +5471,7 @@ var post12 = function(param) {
|
|
|
4650
5471
|
if (!assistant) {
|
|
4651
5472
|
throw new Error("Assistant not found");
|
|
4652
5473
|
}
|
|
4653
|
-
_ref = (0,
|
|
5474
|
+
_ref = (0, import_radash12.assign)({
|
|
4654
5475
|
model: assistant.modelSlug,
|
|
4655
5476
|
instructions: "",
|
|
4656
5477
|
additional_instructions: null,
|
|
@@ -4872,7 +5693,7 @@ var run = function(param) {
|
|
|
4872
5693
|
};
|
|
4873
5694
|
};
|
|
4874
5695
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/steps/get.ts
|
|
4875
|
-
var
|
|
5696
|
+
var import_radash13 = require("radash");
|
|
4876
5697
|
var get13 = function(param) {
|
|
4877
5698
|
var prisma = param.prisma;
|
|
4878
5699
|
return /*#__PURE__*/ function() {
|
|
@@ -4883,7 +5704,7 @@ var get13 = function(param) {
|
|
|
4883
5704
|
case 0:
|
|
4884
5705
|
url = new URL(urlString);
|
|
4885
5706
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
4886
|
-
_ref = (0,
|
|
5707
|
+
_ref = (0, import_radash13.assign)({
|
|
4887
5708
|
limit: "20",
|
|
4888
5709
|
order: "desc"
|
|
4889
5710
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -5466,9 +6287,9 @@ var threads2 = function(param) {
|
|
|
5466
6287
|
};
|
|
5467
6288
|
// src/adapters/storage/responsesStorageAdapter/threads/messages/post.ts
|
|
5468
6289
|
var import_dayjs10 = __toESM(require("dayjs"), 1);
|
|
5469
|
-
var
|
|
6290
|
+
var import_radash15 = require("radash");
|
|
5470
6291
|
// src/lib/items/serializeItemAsMessage.ts
|
|
5471
|
-
var
|
|
6292
|
+
var import_radash14 = require("radash");
|
|
5472
6293
|
var serializeContent2 = function(param) {
|
|
5473
6294
|
var item = param.item;
|
|
5474
6295
|
if (item.type === "message") {
|
|
@@ -5544,7 +6365,7 @@ var serializeMetadata = function(param) {
|
|
|
5544
6365
|
var serializeItemAsMessage = function(param) {
|
|
5545
6366
|
var item = param.item, threadId = param.threadId, openaiAssistant = param.openaiAssistant, createdAt = param.createdAt, _param_runId = param.runId, runId = _param_runId === void 0 ? null : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp;
|
|
5546
6367
|
return {
|
|
5547
|
-
id: item.id || (0,
|
|
6368
|
+
id: item.id || (0, import_radash14.uid)(24),
|
|
5548
6369
|
object: "thread.message",
|
|
5549
6370
|
created_at: createdAt,
|
|
5550
6371
|
thread_id: threadId,
|
|
@@ -5569,7 +6390,7 @@ var serializeItemAsMessage = function(param) {
|
|
|
5569
6390
|
// src/adapters/storage/responsesStorageAdapter/threads/messages/post.ts
|
|
5570
6391
|
var contentBlocksFromContent = function(param) {
|
|
5571
6392
|
var content = param.content;
|
|
5572
|
-
if ((0,
|
|
6393
|
+
if ((0, import_radash15.isArray)(content)) {
|
|
5573
6394
|
return content.map(function(item) {
|
|
5574
6395
|
if (item.type === "text") {
|
|
5575
6396
|
return {
|
|
@@ -5680,7 +6501,7 @@ var post16 = function(param) {
|
|
|
5680
6501
|
}();
|
|
5681
6502
|
};
|
|
5682
6503
|
// src/adapters/storage/responsesStorageAdapter/threads/messages/get.ts
|
|
5683
|
-
var
|
|
6504
|
+
var import_radash16 = require("radash");
|
|
5684
6505
|
// src/lib/items/responseId.ts
|
|
5685
6506
|
function responseId(param) {
|
|
5686
6507
|
var conversation = param.conversation, itemId = param.itemId;
|
|
@@ -5728,7 +6549,7 @@ var get14 = function(param) {
|
|
|
5728
6549
|
case 0:
|
|
5729
6550
|
url = new URL(urlString);
|
|
5730
6551
|
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
5731
|
-
_ref = (0,
|
|
6552
|
+
_ref = (0, import_radash16.assign)({
|
|
5732
6553
|
limit: "20",
|
|
5733
6554
|
order: "desc"
|
|
5734
6555
|
}, Object.fromEntries(url.searchParams)), limit = _ref.limit, order = _ref.order, after = _ref.after;
|
|
@@ -5972,9 +6793,9 @@ var get15 = function() {
|
|
|
5972
6793
|
}();
|
|
5973
6794
|
};
|
|
5974
6795
|
// src/adapters/storage/responsesStorageAdapter/threads/runs/post.ts
|
|
5975
|
-
var import_radash16 = require("radash");
|
|
5976
|
-
var import_dayjs11 = __toESM(require("dayjs"), 1);
|
|
5977
6796
|
var import_radash17 = require("radash");
|
|
6797
|
+
var import_dayjs11 = __toESM(require("dayjs"), 1);
|
|
6798
|
+
var import_radash18 = require("radash");
|
|
5978
6799
|
// src/lib/responses/serializeResponseAsRun.ts
|
|
5979
6800
|
var serializeStatus = function(param) {
|
|
5980
6801
|
var response = param.response;
|
|
@@ -6462,7 +7283,7 @@ var post17 = function(param) {
|
|
|
6462
7283
|
}
|
|
6463
7284
|
body = JSON.parse(options.body);
|
|
6464
7285
|
assistant_id = body.assistant_id, stream = body.stream;
|
|
6465
|
-
_ = (0,
|
|
7286
|
+
_ = (0, import_radash18.assign);
|
|
6466
7287
|
_tmp = [
|
|
6467
7288
|
{},
|
|
6468
7289
|
defaultAssistant
|
|
@@ -6545,7 +7366,7 @@ var post17 = function(param) {
|
|
|
6545
7366
|
event = {
|
|
6546
7367
|
event: "thread.run.failed",
|
|
6547
7368
|
data: {
|
|
6548
|
-
id: (0,
|
|
7369
|
+
id: (0, import_radash17.uid)(24),
|
|
6549
7370
|
failed_at: (0, import_dayjs11.default)().unix(),
|
|
6550
7371
|
last_error: {
|
|
6551
7372
|
code: "server_error",
|
|
@@ -6701,13 +7522,13 @@ var run2 = function(param) {
|
|
|
6701
7522
|
};
|
|
6702
7523
|
};
|
|
6703
7524
|
// src/adapters/storage/responsesStorageAdapter/threads/runs/steps/get.ts
|
|
6704
|
-
var
|
|
7525
|
+
var import_radash22 = require("radash");
|
|
6705
7526
|
// src/lib/items/serializeItemAsMessageCreationRunStep.ts
|
|
6706
7527
|
var import_dayjs12 = __toESM(require("dayjs"), 1);
|
|
6707
|
-
var
|
|
7528
|
+
var import_radash19 = require("radash");
|
|
6708
7529
|
function serializeItemAsMessageCreationRunStep(param) {
|
|
6709
|
-
var item = param.item, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0,
|
|
6710
|
-
var itemId = typeof item.id === "string" ? item.id : "item_".concat((0,
|
|
7530
|
+
var item = param.item, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash19.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs12.default)().unix() : _param_completedAt;
|
|
7531
|
+
var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash19.uid)(18));
|
|
6711
7532
|
var base = {
|
|
6712
7533
|
id: itemId,
|
|
6713
7534
|
object: "thread.run.step",
|
|
@@ -6770,7 +7591,7 @@ function serializeItemAsMessageCreationRunStep(param) {
|
|
|
6770
7591
|
}
|
|
6771
7592
|
// src/lib/items/serializeItemAsFunctionCallRunStep.ts
|
|
6772
7593
|
var import_dayjs13 = __toESM(require("dayjs"), 1);
|
|
6773
|
-
var
|
|
7594
|
+
var import_radash20 = require("radash");
|
|
6774
7595
|
var serializeFunctionCallOutput = function(param) {
|
|
6775
7596
|
var functionCallOutput = param.functionCallOutput;
|
|
6776
7597
|
if (!functionCallOutput) return null;
|
|
@@ -6780,8 +7601,8 @@ var serializeFunctionCallOutput = function(param) {
|
|
|
6780
7601
|
return JSON.stringify(functionCallOutput.output);
|
|
6781
7602
|
};
|
|
6782
7603
|
var serializeItemAsFunctionCallRunStep = function(param) {
|
|
6783
|
-
var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0,
|
|
6784
|
-
var itemId = typeof item.id === "string" ? item.id : "item_".concat((0,
|
|
7604
|
+
var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash20.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs13.default)().unix() : _param_completedAt;
|
|
7605
|
+
var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash20.uid)(18));
|
|
6785
7606
|
var base = {
|
|
6786
7607
|
id: itemId,
|
|
6787
7608
|
object: "thread.run.step",
|
|
@@ -7111,10 +7932,10 @@ var serializeItemAsCodeInterpreterCallRunStep = function(param) {
|
|
|
7111
7932
|
};
|
|
7112
7933
|
// src/lib/items/serializeItemAsComputerCallRunStep.ts
|
|
7113
7934
|
var import_dayjs19 = __toESM(require("dayjs"), 1);
|
|
7114
|
-
var
|
|
7935
|
+
var import_radash21 = require("radash");
|
|
7115
7936
|
var serializeItemAsComputerCallRunStep = function(param) {
|
|
7116
|
-
var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0,
|
|
7117
|
-
var itemId = typeof item.id === "string" ? item.id : "item_".concat((0,
|
|
7937
|
+
var item = param.item, items = param.items, threadId = param.threadId, openaiAssistant = param.openaiAssistant, _param_runId = param.runId, runId = _param_runId === void 0 ? "run_".concat((0, import_radash21.uid)(24)) : _param_runId, tmp = param.status, status3 = tmp === void 0 ? "completed" : tmp, _param_completedAt = param.completedAt, completedAt = _param_completedAt === void 0 ? (0, import_dayjs19.default)().unix() : _param_completedAt;
|
|
7938
|
+
var itemId = typeof item.id === "string" ? item.id : "item_".concat((0, import_radash21.uid)(18));
|
|
7118
7939
|
var base = {
|
|
7119
7940
|
id: itemId,
|
|
7120
7941
|
object: "thread.run.step",
|
|
@@ -7367,7 +8188,7 @@ var get17 = function(param) {
|
|
|
7367
8188
|
new Response(JSON.stringify({
|
|
7368
8189
|
data: data,
|
|
7369
8190
|
has_more: false,
|
|
7370
|
-
last_id: (_id = (_this = (0,
|
|
8191
|
+
last_id: (_id = (_this = (0, import_radash22.last)(response.output)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
|
|
7371
8192
|
}), {
|
|
7372
8193
|
status: 200,
|
|
7373
8194
|
headers: {
|
|
@@ -7734,7 +8555,7 @@ var responsesStorageAdapter = function() {
|
|
|
7734
8555
|
};
|
|
7735
8556
|
// src/adapters/run/responsesRunAdapter/index.ts
|
|
7736
8557
|
var import_dayjs21 = __toESM(require("dayjs"), 1);
|
|
7737
|
-
var
|
|
8558
|
+
var import_radash23 = require("radash");
|
|
7738
8559
|
var serializeToolCalls2 = function(param) {
|
|
7739
8560
|
var toolCalls = param.toolCalls;
|
|
7740
8561
|
return toolCalls.map(function(toolCall) {
|
|
@@ -9675,7 +10496,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9675
10496
|
event: "thread.run.failed"
|
|
9676
10497
|
};
|
|
9677
10498
|
_tmp102 = {
|
|
9678
|
-
id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0,
|
|
10499
|
+
id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash23.uid)(18)),
|
|
9679
10500
|
object: "thread.run",
|
|
9680
10501
|
thread_id: threadId
|
|
9681
10502
|
};
|