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.js
CHANGED
|
@@ -1750,7 +1750,7 @@ var models6 = function(param) {
|
|
|
1750
1750
|
};
|
|
1751
1751
|
};
|
|
1752
1752
|
// src/adapters/client/anthropicClientAdapter/completions/post.ts
|
|
1753
|
-
import { uid, fork, omit as
|
|
1753
|
+
import { uid, fork, omit as omit3 } from "radash";
|
|
1754
1754
|
// src/lib/messages/nonEmptyMessages.ts
|
|
1755
1755
|
var nonEmptyContent = function(param) {
|
|
1756
1756
|
var message = param.message;
|
|
@@ -1805,7 +1805,9 @@ var serializeTools = function(param) {
|
|
|
1805
1805
|
}
|
|
1806
1806
|
};
|
|
1807
1807
|
}
|
|
1808
|
-
return
|
|
1808
|
+
return _object_spread({
|
|
1809
|
+
type: tool.type
|
|
1810
|
+
}, tool[tool.type] || {});
|
|
1809
1811
|
});
|
|
1810
1812
|
};
|
|
1811
1813
|
// src/adapters/client/anthropicClientAdapter/completions/serializeMessages/serializeMessage.ts
|
|
@@ -1858,12 +1860,479 @@ var serializeMessages = function(param) {
|
|
|
1858
1860
|
});
|
|
1859
1861
|
});
|
|
1860
1862
|
};
|
|
1863
|
+
// src/adapters/client/anthropicClientAdapter/completions/serializeBetas.ts
|
|
1864
|
+
var serializeBetas = function(param) {
|
|
1865
|
+
var _param_tools = param.tools, tools = _param_tools === void 0 ? [] : _param_tools;
|
|
1866
|
+
var betas = [];
|
|
1867
|
+
if (tools.some(function(tool) {
|
|
1868
|
+
return tool.type === "computer_20250124";
|
|
1869
|
+
})) {
|
|
1870
|
+
betas.push("computer-use-2025-01-24");
|
|
1871
|
+
}
|
|
1872
|
+
if (tools.some(function(tool) {
|
|
1873
|
+
return tool.type === "code_execution_20250825";
|
|
1874
|
+
})) {
|
|
1875
|
+
betas.push("code-execution-2025-08-25");
|
|
1876
|
+
}
|
|
1877
|
+
if (!betas.length) {
|
|
1878
|
+
return {};
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
betas: betas
|
|
1882
|
+
};
|
|
1883
|
+
};
|
|
1884
|
+
// src/adapters/client/anthropicClientAdapter/normalizeComputerToolCallPayload.ts
|
|
1885
|
+
import { omit as omit2 } from "radash";
|
|
1886
|
+
var coordinateKeys = [
|
|
1887
|
+
"coordinate",
|
|
1888
|
+
"coordinates",
|
|
1889
|
+
"coordinate_start",
|
|
1890
|
+
"coordinate_end",
|
|
1891
|
+
"start",
|
|
1892
|
+
"end",
|
|
1893
|
+
"from",
|
|
1894
|
+
"to",
|
|
1895
|
+
"target",
|
|
1896
|
+
"point",
|
|
1897
|
+
"position",
|
|
1898
|
+
"cursor_position",
|
|
1899
|
+
"path"
|
|
1900
|
+
];
|
|
1901
|
+
var clickButtonMap = {
|
|
1902
|
+
left_click: "left",
|
|
1903
|
+
right_click: "right",
|
|
1904
|
+
middle_click: "wheel",
|
|
1905
|
+
double_click: "left",
|
|
1906
|
+
triple_click: "left",
|
|
1907
|
+
left_mouse_down: "left",
|
|
1908
|
+
left_mouse_up: "left"
|
|
1909
|
+
};
|
|
1910
|
+
var keyAliasMap = {
|
|
1911
|
+
ctrl: "ctrl",
|
|
1912
|
+
control: "ctrl",
|
|
1913
|
+
cmd: "meta",
|
|
1914
|
+
command: "meta",
|
|
1915
|
+
meta: "meta",
|
|
1916
|
+
win: "meta",
|
|
1917
|
+
option: "alt",
|
|
1918
|
+
alt: "alt",
|
|
1919
|
+
shift: "shift",
|
|
1920
|
+
enter: "enter",
|
|
1921
|
+
return: "enter",
|
|
1922
|
+
esc: "escape",
|
|
1923
|
+
escape: "escape",
|
|
1924
|
+
tab: "tab",
|
|
1925
|
+
space: "space",
|
|
1926
|
+
spacebar: "space",
|
|
1927
|
+
backspace: "backspace",
|
|
1928
|
+
del: "delete",
|
|
1929
|
+
delete: "delete",
|
|
1930
|
+
pageup: "pageup",
|
|
1931
|
+
pagedown: "pagedown",
|
|
1932
|
+
up: "up",
|
|
1933
|
+
down: "down",
|
|
1934
|
+
left: "left",
|
|
1935
|
+
right: "right"
|
|
1936
|
+
};
|
|
1937
|
+
var sanitizeNumber = function(value) {
|
|
1938
|
+
return typeof value === "number" ? value : void 0;
|
|
1939
|
+
};
|
|
1940
|
+
var toCoordinate = function(value) {
|
|
1941
|
+
if (!value) return void 0;
|
|
1942
|
+
if (Array.isArray(value)) {
|
|
1943
|
+
if (value.length === 2 && typeof value[0] === "number" && typeof value[1] === "number") {
|
|
1944
|
+
return {
|
|
1945
|
+
x: value[0],
|
|
1946
|
+
y: value[1]
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
if (value.length > 0 && Array.isArray(value[0])) {
|
|
1950
|
+
var tuple = value[0];
|
|
1951
|
+
if (tuple.length === 2 && typeof tuple[0] === "number" && typeof tuple[1] === "number") {
|
|
1952
|
+
return {
|
|
1953
|
+
x: tuple[0],
|
|
1954
|
+
y: tuple[1]
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
1960
|
+
var maybe = value;
|
|
1961
|
+
var x = sanitizeNumber(maybe.x);
|
|
1962
|
+
var y = sanitizeNumber(maybe.y);
|
|
1963
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
1964
|
+
return {
|
|
1965
|
+
x: x,
|
|
1966
|
+
y: y
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
if (typeof value === "string") {
|
|
1971
|
+
var parts = value.split(/[, ]+/).map(Number).filter(Number.isFinite);
|
|
1972
|
+
if (parts.length >= 2) {
|
|
1973
|
+
return {
|
|
1974
|
+
x: parts[0],
|
|
1975
|
+
y: parts[1]
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
return void 0;
|
|
1980
|
+
};
|
|
1981
|
+
var findCoordinatesInDetails = function(details) {
|
|
1982
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1983
|
+
try {
|
|
1984
|
+
for(var _iterator = coordinateKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1985
|
+
var key = _step.value;
|
|
1986
|
+
var value = details[key];
|
|
1987
|
+
var coords = toCoordinate(value);
|
|
1988
|
+
if (coords) {
|
|
1989
|
+
return coords;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
} catch (err) {
|
|
1993
|
+
_didIteratorError = true;
|
|
1994
|
+
_iteratorError = err;
|
|
1995
|
+
} finally{
|
|
1996
|
+
try {
|
|
1997
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1998
|
+
_iterator.return();
|
|
1999
|
+
}
|
|
2000
|
+
} finally{
|
|
2001
|
+
if (_didIteratorError) {
|
|
2002
|
+
throw _iteratorError;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
return void 0;
|
|
2007
|
+
};
|
|
2008
|
+
var buildDragPath = function(details) {
|
|
2009
|
+
var path = [];
|
|
2010
|
+
if (Array.isArray(details.path)) {
|
|
2011
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2012
|
+
try {
|
|
2013
|
+
for(var _iterator = details.path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2014
|
+
var point = _step.value;
|
|
2015
|
+
var coords = toCoordinate(point);
|
|
2016
|
+
if (coords) {
|
|
2017
|
+
path.push(coords);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
} catch (err) {
|
|
2021
|
+
_didIteratorError = true;
|
|
2022
|
+
_iteratorError = err;
|
|
2023
|
+
} finally{
|
|
2024
|
+
try {
|
|
2025
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2026
|
+
_iterator.return();
|
|
2027
|
+
}
|
|
2028
|
+
} finally{
|
|
2029
|
+
if (_didIteratorError) {
|
|
2030
|
+
throw _iteratorError;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (!path.length) {
|
|
2036
|
+
var start = toCoordinate(details.coordinate_start) || toCoordinate(details.start) || toCoordinate(details.from);
|
|
2037
|
+
if (start) {
|
|
2038
|
+
path.push(start);
|
|
2039
|
+
}
|
|
2040
|
+
var end = toCoordinate(details.coordinate_end) || toCoordinate(details.end) || toCoordinate(details.to) || toCoordinate(details.target);
|
|
2041
|
+
if (end) {
|
|
2042
|
+
path.push(end);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
if (!path.length) {
|
|
2046
|
+
var coords1 = findCoordinatesInDetails(details);
|
|
2047
|
+
if (coords1) {
|
|
2048
|
+
path.push(coords1);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
if (!path.length) {
|
|
2052
|
+
path.push({
|
|
2053
|
+
x: 0,
|
|
2054
|
+
y: 0
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
return path;
|
|
2058
|
+
};
|
|
2059
|
+
var parseKeys = function(input) {
|
|
2060
|
+
if (Array.isArray(input)) {
|
|
2061
|
+
return input.map(String).map(function(key) {
|
|
2062
|
+
return key.trim();
|
|
2063
|
+
}).filter(Boolean);
|
|
2064
|
+
}
|
|
2065
|
+
if (typeof input === "string") {
|
|
2066
|
+
return input.split(RegExp("(?:(?<!\\\\)\\+|\\s+)")).map(function(key) {
|
|
2067
|
+
return key.replace(/\\\+/g, "+");
|
|
2068
|
+
}).map(function(key) {
|
|
2069
|
+
return key.trim();
|
|
2070
|
+
}).filter(Boolean);
|
|
2071
|
+
}
|
|
2072
|
+
return [];
|
|
2073
|
+
};
|
|
2074
|
+
var normalizeKeys = function(keys) {
|
|
2075
|
+
return keys.map(function(key) {
|
|
2076
|
+
var lowerKey = key.toLowerCase();
|
|
2077
|
+
var _keyAliasMap_lowerKey;
|
|
2078
|
+
return (_keyAliasMap_lowerKey = keyAliasMap[lowerKey]) !== null && _keyAliasMap_lowerKey !== void 0 ? _keyAliasMap_lowerKey : lowerKey;
|
|
2079
|
+
});
|
|
2080
|
+
};
|
|
2081
|
+
var normalizeScroll = function(details) {
|
|
2082
|
+
var _sanitizeNumber;
|
|
2083
|
+
var scrollX = (_sanitizeNumber = sanitizeNumber(details.scroll_x)) !== null && _sanitizeNumber !== void 0 ? _sanitizeNumber : 0;
|
|
2084
|
+
var _sanitizeNumber1;
|
|
2085
|
+
var scrollY = (_sanitizeNumber1 = sanitizeNumber(details.scroll_y)) !== null && _sanitizeNumber1 !== void 0 ? _sanitizeNumber1 : 0;
|
|
2086
|
+
var _sanitizeNumber2, _ref;
|
|
2087
|
+
var amount = (_ref = (_sanitizeNumber2 = sanitizeNumber(details.scroll_amount)) !== null && _sanitizeNumber2 !== void 0 ? _sanitizeNumber2 : sanitizeNumber(details.amount)) !== null && _ref !== void 0 ? _ref : 0;
|
|
2088
|
+
var direction = typeof details.scroll_direction === "string" ? details.scroll_direction.toLowerCase() : typeof details.direction === "string" ? details.direction.toLowerCase() : void 0;
|
|
2089
|
+
if (!scrollX && !scrollY && direction && amount) {
|
|
2090
|
+
switch(direction){
|
|
2091
|
+
case "up":
|
|
2092
|
+
scrollY = -amount;
|
|
2093
|
+
break;
|
|
2094
|
+
case "down":
|
|
2095
|
+
scrollY = amount;
|
|
2096
|
+
break;
|
|
2097
|
+
case "left":
|
|
2098
|
+
scrollX = -amount;
|
|
2099
|
+
break;
|
|
2100
|
+
case "right":
|
|
2101
|
+
scrollX = amount;
|
|
2102
|
+
break;
|
|
2103
|
+
default:
|
|
2104
|
+
break;
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
return {
|
|
2108
|
+
scroll_x: scrollX,
|
|
2109
|
+
scroll_y: scrollY
|
|
2110
|
+
};
|
|
2111
|
+
};
|
|
2112
|
+
var normalizeActionString = function(action, details) {
|
|
2113
|
+
var coords = findCoordinatesInDetails(details);
|
|
2114
|
+
switch(action){
|
|
2115
|
+
case "screenshot":
|
|
2116
|
+
return {
|
|
2117
|
+
type: "screenshot"
|
|
2118
|
+
};
|
|
2119
|
+
case "left_click":
|
|
2120
|
+
case "right_click":
|
|
2121
|
+
case "middle_click":
|
|
2122
|
+
{
|
|
2123
|
+
var _coords_x, _coords_y;
|
|
2124
|
+
return {
|
|
2125
|
+
type: "click",
|
|
2126
|
+
button: clickButtonMap[action],
|
|
2127
|
+
x: (_coords_x = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x !== void 0 ? _coords_x : 0,
|
|
2128
|
+
y: (_coords_y = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y !== void 0 ? _coords_y : 0
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
case "double_click":
|
|
2132
|
+
var _coords_x1, _coords_y1;
|
|
2133
|
+
return {
|
|
2134
|
+
type: "double_click",
|
|
2135
|
+
x: (_coords_x1 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x1 !== void 0 ? _coords_x1 : 0,
|
|
2136
|
+
y: (_coords_y1 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y1 !== void 0 ? _coords_y1 : 0
|
|
2137
|
+
};
|
|
2138
|
+
case "triple_click":
|
|
2139
|
+
var _coords_x2, _coords_y2;
|
|
2140
|
+
return {
|
|
2141
|
+
type: "double_click",
|
|
2142
|
+
x: (_coords_x2 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x2 !== void 0 ? _coords_x2 : 0,
|
|
2143
|
+
y: (_coords_y2 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y2 !== void 0 ? _coords_y2 : 0,
|
|
2144
|
+
repetitions: 3
|
|
2145
|
+
};
|
|
2146
|
+
case "left_mouse_down":
|
|
2147
|
+
var _coords_x3, _coords_y3;
|
|
2148
|
+
return {
|
|
2149
|
+
type: "click",
|
|
2150
|
+
button: clickButtonMap[action],
|
|
2151
|
+
state: "down",
|
|
2152
|
+
x: (_coords_x3 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x3 !== void 0 ? _coords_x3 : 0,
|
|
2153
|
+
y: (_coords_y3 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y3 !== void 0 ? _coords_y3 : 0
|
|
2154
|
+
};
|
|
2155
|
+
case "left_mouse_up":
|
|
2156
|
+
var _coords_x4, _coords_y4;
|
|
2157
|
+
return {
|
|
2158
|
+
type: "click",
|
|
2159
|
+
button: clickButtonMap[action],
|
|
2160
|
+
state: "up",
|
|
2161
|
+
x: (_coords_x4 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x4 !== void 0 ? _coords_x4 : 0,
|
|
2162
|
+
y: (_coords_y4 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y4 !== void 0 ? _coords_y4 : 0
|
|
2163
|
+
};
|
|
2164
|
+
case "left_click_drag":
|
|
2165
|
+
{
|
|
2166
|
+
var path = buildDragPath(details).map(function(param) {
|
|
2167
|
+
var x = param.x, y = param.y;
|
|
2168
|
+
return {
|
|
2169
|
+
x: x,
|
|
2170
|
+
y: y
|
|
2171
|
+
};
|
|
2172
|
+
});
|
|
2173
|
+
return {
|
|
2174
|
+
type: "drag",
|
|
2175
|
+
path: path
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
case "mouse_move":
|
|
2179
|
+
case "cursor_position":
|
|
2180
|
+
var _coords_x5, _coords_y5;
|
|
2181
|
+
return {
|
|
2182
|
+
type: "move",
|
|
2183
|
+
x: (_coords_x5 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x5 !== void 0 ? _coords_x5 : 0,
|
|
2184
|
+
y: (_coords_y5 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y5 !== void 0 ? _coords_y5 : 0
|
|
2185
|
+
};
|
|
2186
|
+
case "scroll":
|
|
2187
|
+
{
|
|
2188
|
+
var _normalizeScroll = normalizeScroll(details), scroll_x = _normalizeScroll.scroll_x, scroll_y = _normalizeScroll.scroll_y;
|
|
2189
|
+
var _coords_x6, _coords_y6;
|
|
2190
|
+
return _object_spread({
|
|
2191
|
+
type: "scroll",
|
|
2192
|
+
x: (_coords_x6 = coords === null || coords === void 0 ? void 0 : coords.x) !== null && _coords_x6 !== void 0 ? _coords_x6 : 0,
|
|
2193
|
+
y: (_coords_y6 = coords === null || coords === void 0 ? void 0 : coords.y) !== null && _coords_y6 !== void 0 ? _coords_y6 : 0,
|
|
2194
|
+
scroll_x: scroll_x,
|
|
2195
|
+
scroll_y: scroll_y
|
|
2196
|
+
}, typeof details.scroll_direction === "string" ? {
|
|
2197
|
+
direction: details.scroll_direction
|
|
2198
|
+
} : typeof details.direction === "string" ? {
|
|
2199
|
+
direction: details.direction
|
|
2200
|
+
} : {}, typeof details.scroll_amount === "number" ? {
|
|
2201
|
+
amount: details.scroll_amount
|
|
2202
|
+
} : typeof details.amount === "number" ? {
|
|
2203
|
+
amount: details.amount
|
|
2204
|
+
} : {});
|
|
2205
|
+
}
|
|
2206
|
+
case "type":
|
|
2207
|
+
{
|
|
2208
|
+
var text = typeof details.text === "string" ? details.text : typeof details.input === "string" ? details.input : "";
|
|
2209
|
+
return {
|
|
2210
|
+
type: "type",
|
|
2211
|
+
text: text
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
case "key":
|
|
2215
|
+
case "hold_key":
|
|
2216
|
+
{
|
|
2217
|
+
var _details_text, _ref;
|
|
2218
|
+
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));
|
|
2219
|
+
var normalized = {
|
|
2220
|
+
type: "keypress",
|
|
2221
|
+
keys: keys
|
|
2222
|
+
};
|
|
2223
|
+
if (action === "hold_key") {
|
|
2224
|
+
var duration = sanitizeNumber(details.duration);
|
|
2225
|
+
if (typeof duration === "number") {
|
|
2226
|
+
normalized.hold_duration_ms = Math.round(duration * 1e3);
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
return normalized;
|
|
2230
|
+
}
|
|
2231
|
+
case "wait":
|
|
2232
|
+
{
|
|
2233
|
+
var duration1 = sanitizeNumber(details.duration);
|
|
2234
|
+
return _object_spread({
|
|
2235
|
+
type: "wait"
|
|
2236
|
+
}, typeof duration1 === "number" ? {
|
|
2237
|
+
duration_ms: Math.round(duration1 * 1e3)
|
|
2238
|
+
} : {});
|
|
2239
|
+
}
|
|
2240
|
+
default:
|
|
2241
|
+
{
|
|
2242
|
+
return _object_spread({
|
|
2243
|
+
type: action
|
|
2244
|
+
}, coords ? {
|
|
2245
|
+
x: coords.x,
|
|
2246
|
+
y: coords.y
|
|
2247
|
+
} : {}, omit2(details, _to_consumable_array(coordinateKeys).concat([
|
|
2248
|
+
"text",
|
|
2249
|
+
"scroll_direction",
|
|
2250
|
+
"direction",
|
|
2251
|
+
"scroll_amount",
|
|
2252
|
+
"amount",
|
|
2253
|
+
"scroll_x",
|
|
2254
|
+
"scroll_y",
|
|
2255
|
+
"keys",
|
|
2256
|
+
"duration"
|
|
2257
|
+
])));
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
var normalizeAction = function(payload) {
|
|
2262
|
+
if (payload && (typeof payload === "undefined" ? "undefined" : _type_of(payload)) === "object") {
|
|
2263
|
+
var rawAction = payload.action;
|
|
2264
|
+
if (typeof rawAction === "string") {
|
|
2265
|
+
var parsedAction = parseJson(rawAction);
|
|
2266
|
+
if (parsedAction && (typeof parsedAction === "undefined" ? "undefined" : _type_of(parsedAction)) === "object") {
|
|
2267
|
+
rawAction = parsedAction;
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
if (rawAction && (typeof rawAction === "undefined" ? "undefined" : _type_of(rawAction)) === "object" && typeof rawAction.type === "string") {
|
|
2271
|
+
return rawAction;
|
|
2272
|
+
}
|
|
2273
|
+
if (typeof rawAction === "string") {
|
|
2274
|
+
var details = omit2(payload, [
|
|
2275
|
+
"action",
|
|
2276
|
+
"pending_safety_checks",
|
|
2277
|
+
"status"
|
|
2278
|
+
]);
|
|
2279
|
+
return normalizeActionString(rawAction, details);
|
|
2280
|
+
}
|
|
2281
|
+
if (typeof payload.type === "string") {
|
|
2282
|
+
return payload;
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
if (typeof payload === "string") {
|
|
2286
|
+
var parsed = parseJson(payload);
|
|
2287
|
+
if (parsed && (typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === "object") {
|
|
2288
|
+
return normalizeAction(parsed);
|
|
2289
|
+
}
|
|
2290
|
+
return {
|
|
2291
|
+
type: payload
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
return {
|
|
2295
|
+
type: "unknown",
|
|
2296
|
+
value: payload
|
|
2297
|
+
};
|
|
2298
|
+
};
|
|
2299
|
+
var normalizeComputerToolCallPayload = function(payload) {
|
|
2300
|
+
var normalizedPayload = payload;
|
|
2301
|
+
if (typeof payload === "string") {
|
|
2302
|
+
var parsed = parseJson(payload);
|
|
2303
|
+
if (parsed !== void 0) {
|
|
2304
|
+
normalizedPayload = parsed;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
var pendingSafetyChecksRaw = normalizedPayload && (typeof normalizedPayload === "undefined" ? "undefined" : _type_of(normalizedPayload)) === "object" ? normalizedPayload.pending_safety_checks : void 0;
|
|
2308
|
+
if (typeof pendingSafetyChecksRaw === "string") {
|
|
2309
|
+
var parsed1 = parseJson(pendingSafetyChecksRaw);
|
|
2310
|
+
pendingSafetyChecksRaw = Array.isArray(parsed1) ? parsed1 : [];
|
|
2311
|
+
}
|
|
2312
|
+
var pendingSafetyChecks = Array.isArray(pendingSafetyChecksRaw) ? pendingSafetyChecksRaw : [];
|
|
2313
|
+
var normalizedAction = normalizeAction(normalizedPayload);
|
|
2314
|
+
var result = {
|
|
2315
|
+
action: normalizedAction,
|
|
2316
|
+
pending_safety_checks: pendingSafetyChecks
|
|
2317
|
+
};
|
|
2318
|
+
if (normalizedPayload && (typeof normalizedPayload === "undefined" ? "undefined" : _type_of(normalizedPayload)) === "object" && "status" in normalizedPayload) {
|
|
2319
|
+
result.status = normalizedPayload.status;
|
|
2320
|
+
}
|
|
2321
|
+
return result;
|
|
2322
|
+
};
|
|
2323
|
+
var parseJson = function(value) {
|
|
2324
|
+
try {
|
|
2325
|
+
return JSON.parse(value);
|
|
2326
|
+
} catch (e) {
|
|
2327
|
+
return void 0;
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
1861
2330
|
// src/adapters/client/anthropicClientAdapter/completions/post.ts
|
|
1862
2331
|
var post5 = function(param) {
|
|
1863
2332
|
var anthropic = param.anthropic;
|
|
1864
2333
|
return /*#__PURE__*/ function() {
|
|
1865
2334
|
var _ref = _async_to_generator(function(_url, options) {
|
|
1866
|
-
var body, messages4, _fork, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, error;
|
|
2335
|
+
var body, messages4, _fork, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, normalizedContent, normalizedData, error;
|
|
1867
2336
|
return _ts_generator(this, function(_state) {
|
|
1868
2337
|
switch(_state.label){
|
|
1869
2338
|
case 0:
|
|
@@ -1882,10 +2351,14 @@ var post5 = function(param) {
|
|
|
1882
2351
|
})
|
|
1883
2352
|
})
|
|
1884
2353
|
});
|
|
1885
|
-
resultOptions = _object_spread_props(_object_spread({},
|
|
2354
|
+
resultOptions = _object_spread_props(_object_spread(_object_spread_props(_object_spread({}, omit3(body, [
|
|
1886
2355
|
"response_format"
|
|
1887
2356
|
])), {
|
|
1888
|
-
|
|
2357
|
+
model: body.model
|
|
2358
|
+
}), serializeBetas({
|
|
2359
|
+
tools: body.tools
|
|
2360
|
+
})), {
|
|
2361
|
+
stream: body.stream,
|
|
1889
2362
|
system: system,
|
|
1890
2363
|
messages: serializeMessages({
|
|
1891
2364
|
messages: chatMessages
|
|
@@ -1895,23 +2368,98 @@ var post5 = function(param) {
|
|
|
1895
2368
|
tools: body.tools
|
|
1896
2369
|
})
|
|
1897
2370
|
});
|
|
1898
|
-
if (!
|
|
2371
|
+
if (!resultOptions.stream) return [
|
|
1899
2372
|
3,
|
|
1900
2373
|
2
|
|
1901
2374
|
];
|
|
1902
2375
|
return [
|
|
1903
2376
|
4,
|
|
1904
|
-
anthropic.messages.
|
|
2377
|
+
anthropic.beta.messages.create(resultOptions)
|
|
1905
2378
|
];
|
|
1906
2379
|
case 1:
|
|
1907
2380
|
response = _state.sent();
|
|
1908
2381
|
stream = new ReadableStream({
|
|
1909
2382
|
start: function start(controller) {
|
|
1910
2383
|
return _async_to_generator(function() {
|
|
1911
|
-
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, delta, messageDelta, delta1, messageDelta1, messageDelta2, err;
|
|
2384
|
+
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;
|
|
1912
2385
|
return _ts_generator(this, function(_state) {
|
|
1913
2386
|
switch(_state.label){
|
|
1914
2387
|
case 0:
|
|
2388
|
+
blockIndexToToolUseId = /* @__PURE__ */ new Map();
|
|
2389
|
+
toolUseIdToIndex = /* @__PURE__ */ new Map();
|
|
2390
|
+
toolUseIdArgumentBuffer = /* @__PURE__ */ new Map();
|
|
2391
|
+
computerToolUseIds = /* @__PURE__ */ new Set();
|
|
2392
|
+
normalizedComputerCalls = /* @__PURE__ */ new Set();
|
|
2393
|
+
nextToolCallIndex = 0;
|
|
2394
|
+
parseJson2 = function(value) {
|
|
2395
|
+
try {
|
|
2396
|
+
return JSON.parse(value);
|
|
2397
|
+
} catch (e) {
|
|
2398
|
+
return void 0;
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
getOrCreateIndexForToolUseId = function(toolUseId) {
|
|
2402
|
+
if (!toolUseId) {
|
|
2403
|
+
return 0;
|
|
2404
|
+
}
|
|
2405
|
+
if (!toolUseIdToIndex.has(toolUseId)) {
|
|
2406
|
+
toolUseIdToIndex.set(toolUseId, nextToolCallIndex++);
|
|
2407
|
+
}
|
|
2408
|
+
var _toolUseIdToIndex_get;
|
|
2409
|
+
return (_toolUseIdToIndex_get = toolUseIdToIndex.get(toolUseId)) !== null && _toolUseIdToIndex_get !== void 0 ? _toolUseIdToIndex_get : 0;
|
|
2410
|
+
};
|
|
2411
|
+
assignBlockToToolUse = function(param) {
|
|
2412
|
+
var blockIndex = param.blockIndex, toolUseId = param.toolUseId;
|
|
2413
|
+
if (typeof blockIndex === "number" && toolUseId) {
|
|
2414
|
+
blockIndexToToolUseId.set(blockIndex, toolUseId);
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
markComputerToolUse = function(toolUseId) {
|
|
2418
|
+
if (!toolUseId) return;
|
|
2419
|
+
computerToolUseIds.add(toolUseId);
|
|
2420
|
+
normalizedComputerCalls.delete(toolUseId);
|
|
2421
|
+
toolUseIdArgumentBuffer.set(toolUseId, "");
|
|
2422
|
+
};
|
|
2423
|
+
getToolUseIdFromBlock = function(block) {
|
|
2424
|
+
if (!block || (typeof block === "undefined" ? "undefined" : _type_of(block)) !== "object") return void 0;
|
|
2425
|
+
if (typeof block.tool_use_id === "string") {
|
|
2426
|
+
return block.tool_use_id;
|
|
2427
|
+
}
|
|
2428
|
+
if (typeof block.id === "string") {
|
|
2429
|
+
return block.id;
|
|
2430
|
+
}
|
|
2431
|
+
return void 0;
|
|
2432
|
+
};
|
|
2433
|
+
emitNormalizedToolCall = function(param) {
|
|
2434
|
+
var normalized = param.normalized, toolCallIndex = param.toolCallIndex, chunkIndex = param.chunkIndex;
|
|
2435
|
+
var messageDelta = {
|
|
2436
|
+
id: "chatcmpl-".concat(uid(29)),
|
|
2437
|
+
object: "chat.completion.chunk",
|
|
2438
|
+
choices: [
|
|
2439
|
+
{
|
|
2440
|
+
index: chunkIndex,
|
|
2441
|
+
delta: {
|
|
2442
|
+
tool_calls: [
|
|
2443
|
+
{
|
|
2444
|
+
index: toolCallIndex,
|
|
2445
|
+
function: {
|
|
2446
|
+
arguments: JSON.stringify(normalized)
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
]
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
]
|
|
2453
|
+
};
|
|
2454
|
+
controller.enqueue("data: ".concat(JSON.stringify(messageDelta), "\n\n"));
|
|
2455
|
+
};
|
|
2456
|
+
getOrCreateIndexForBlock = function(blockIndex) {
|
|
2457
|
+
if (typeof blockIndex !== "number") {
|
|
2458
|
+
return 0;
|
|
2459
|
+
}
|
|
2460
|
+
var toolUseId = blockIndexToToolUseId.get(blockIndex);
|
|
2461
|
+
return getOrCreateIndexForToolUseId(toolUseId);
|
|
2462
|
+
};
|
|
1915
2463
|
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
1916
2464
|
_state.label = 1;
|
|
1917
2465
|
case 1:
|
|
@@ -1934,14 +2482,79 @@ var post5 = function(param) {
|
|
|
1934
2482
|
5
|
|
1935
2483
|
];
|
|
1936
2484
|
_value = _step.value;
|
|
1937
|
-
|
|
2485
|
+
_ref = _value;
|
|
2486
|
+
chunk = _ref;
|
|
2487
|
+
if (chunk.type === "content_block_stop") {
|
|
2488
|
+
toolUseId = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
|
|
2489
|
+
if (toolUseId && computerToolUseIds.has(toolUseId) && !normalizedComputerCalls.has(toolUseId)) {
|
|
2490
|
+
;
|
|
2491
|
+
buffered = (_toolUseIdArgumentBuffer_get = toolUseIdArgumentBuffer.get(toolUseId)) !== null && _toolUseIdArgumentBuffer_get !== void 0 ? _toolUseIdArgumentBuffer_get : "";
|
|
2492
|
+
parsed = buffered ? parseJson2(buffered) : void 0;
|
|
2493
|
+
if (parsed !== void 0) {
|
|
2494
|
+
normalized = normalizeComputerToolCallPayload(parsed);
|
|
2495
|
+
toolCallIndex = getOrCreateIndexForToolUseId(toolUseId);
|
|
2496
|
+
chunkIndex = typeof chunk.index === "number" ? chunk.index : 0;
|
|
2497
|
+
emitNormalizedToolCall({
|
|
2498
|
+
normalized: normalized,
|
|
2499
|
+
toolCallIndex: toolCallIndex,
|
|
2500
|
+
chunkIndex: chunkIndex
|
|
2501
|
+
});
|
|
2502
|
+
normalizedComputerCalls.add(toolUseId);
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
if (toolUseId) {
|
|
2506
|
+
toolUseIdArgumentBuffer.delete(toolUseId);
|
|
2507
|
+
computerToolUseIds.delete(toolUseId);
|
|
2508
|
+
normalizedComputerCalls.delete(toolUseId);
|
|
2509
|
+
}
|
|
2510
|
+
if (typeof chunk.index === "number") {
|
|
2511
|
+
blockIndexToToolUseId.delete(chunk.index);
|
|
2512
|
+
}
|
|
2513
|
+
return [
|
|
2514
|
+
3,
|
|
2515
|
+
4
|
|
2516
|
+
];
|
|
2517
|
+
}
|
|
1938
2518
|
if (chunk.type === "content_block_delta") {
|
|
1939
2519
|
delta = void 0;
|
|
1940
2520
|
if (chunk.delta.type === "input_json_delta") {
|
|
2521
|
+
toolUseId1 = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
|
|
2522
|
+
if (toolUseId1 && computerToolUseIds.has(toolUseId1)) {
|
|
2523
|
+
;
|
|
2524
|
+
existing = (_toolUseIdArgumentBuffer_get1 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get1 !== void 0 ? _toolUseIdArgumentBuffer_get1 : "";
|
|
2525
|
+
;
|
|
2526
|
+
updated = "".concat(existing).concat((_chunk_delta_partial_json = chunk.delta.partial_json) !== null && _chunk_delta_partial_json !== void 0 ? _chunk_delta_partial_json : "");
|
|
2527
|
+
toolUseIdArgumentBuffer.set(toolUseId1, updated);
|
|
2528
|
+
if (!normalizedComputerCalls.has(toolUseId1)) {
|
|
2529
|
+
parsed1 = parseJson2(updated);
|
|
2530
|
+
if (parsed1 !== void 0) {
|
|
2531
|
+
normalized1 = normalizeComputerToolCallPayload(parsed1);
|
|
2532
|
+
toolCallIndex1 = getOrCreateIndexForToolUseId(toolUseId1);
|
|
2533
|
+
chunkIndex1 = typeof chunk.index === "number" ? chunk.index : 0;
|
|
2534
|
+
emitNormalizedToolCall({
|
|
2535
|
+
normalized: normalized1,
|
|
2536
|
+
toolCallIndex: toolCallIndex1,
|
|
2537
|
+
chunkIndex: chunkIndex1
|
|
2538
|
+
});
|
|
2539
|
+
normalizedComputerCalls.add(toolUseId1);
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
return [
|
|
2543
|
+
3,
|
|
2544
|
+
4
|
|
2545
|
+
];
|
|
2546
|
+
}
|
|
2547
|
+
if (toolUseId1) {
|
|
2548
|
+
;
|
|
2549
|
+
existing1 = (_toolUseIdArgumentBuffer_get2 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get2 !== void 0 ? _toolUseIdArgumentBuffer_get2 : "";
|
|
2550
|
+
;
|
|
2551
|
+
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 : ""));
|
|
2552
|
+
}
|
|
2553
|
+
index = getOrCreateIndexForBlock(chunk.index);
|
|
1941
2554
|
delta = {
|
|
1942
2555
|
tool_calls: [
|
|
1943
2556
|
{
|
|
1944
|
-
index:
|
|
2557
|
+
index: index,
|
|
1945
2558
|
function: {
|
|
1946
2559
|
arguments: chunk.delta.partial_json
|
|
1947
2560
|
}
|
|
@@ -1971,11 +2584,46 @@ var post5 = function(param) {
|
|
|
1971
2584
|
} else if (chunk.type === "content_block_start") {
|
|
1972
2585
|
delta1 = void 0;
|
|
1973
2586
|
if (chunk.content_block.type === "tool_use") {
|
|
2587
|
+
toolName = chunk.content_block.name;
|
|
2588
|
+
normalizedToolName = toolName === "computer" ? "computer_call" : toolName;
|
|
2589
|
+
index1 = getOrCreateIndexForToolUseId(chunk.content_block.id);
|
|
2590
|
+
assignBlockToToolUse({
|
|
2591
|
+
blockIndex: chunk.index,
|
|
2592
|
+
toolUseId: chunk.content_block.id
|
|
2593
|
+
});
|
|
2594
|
+
if (normalizedToolName === "computer_call") {
|
|
2595
|
+
markComputerToolUse(chunk.content_block.id);
|
|
2596
|
+
} else if (!toolUseIdArgumentBuffer.has(chunk.content_block.id)) {
|
|
2597
|
+
toolUseIdArgumentBuffer.set(chunk.content_block.id, "");
|
|
2598
|
+
}
|
|
2599
|
+
delta1 = {
|
|
2600
|
+
content: null,
|
|
2601
|
+
tool_calls: [
|
|
2602
|
+
{
|
|
2603
|
+
index: index1,
|
|
2604
|
+
id: chunk.content_block.id,
|
|
2605
|
+
type: "function",
|
|
2606
|
+
function: {
|
|
2607
|
+
name: normalizedToolName,
|
|
2608
|
+
arguments: ""
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
]
|
|
2612
|
+
};
|
|
2613
|
+
} else if (chunk.content_block.type === "server_tool_use") {
|
|
2614
|
+
index2 = getOrCreateIndexForToolUseId(chunk.content_block.id);
|
|
2615
|
+
assignBlockToToolUse({
|
|
2616
|
+
blockIndex: chunk.index,
|
|
2617
|
+
toolUseId: chunk.content_block.id
|
|
2618
|
+
});
|
|
2619
|
+
if (!toolUseIdArgumentBuffer.has(chunk.content_block.id)) {
|
|
2620
|
+
toolUseIdArgumentBuffer.set(chunk.content_block.id, "");
|
|
2621
|
+
}
|
|
1974
2622
|
delta1 = {
|
|
1975
2623
|
content: null,
|
|
1976
2624
|
tool_calls: [
|
|
1977
2625
|
{
|
|
1978
|
-
index:
|
|
2626
|
+
index: index2,
|
|
1979
2627
|
id: chunk.content_block.id,
|
|
1980
2628
|
type: "function",
|
|
1981
2629
|
function: {
|
|
@@ -1985,6 +2633,65 @@ var post5 = function(param) {
|
|
|
1985
2633
|
}
|
|
1986
2634
|
]
|
|
1987
2635
|
};
|
|
2636
|
+
} else if (chunk.content_block.type === "web_search_tool_result") {
|
|
2637
|
+
;
|
|
2638
|
+
outputPayload = {
|
|
2639
|
+
content: (_chunk_content_block_content = chunk.content_block.content) !== null && _chunk_content_block_content !== void 0 ? _chunk_content_block_content : []
|
|
2640
|
+
};
|
|
2641
|
+
;
|
|
2642
|
+
toolCallId = (_getToolUseIdFromBlock = getToolUseIdFromBlock(chunk.content_block)) !== null && _getToolUseIdFromBlock !== void 0 ? _getToolUseIdFromBlock : "";
|
|
2643
|
+
index3 = getOrCreateIndexForToolUseId(toolCallId);
|
|
2644
|
+
assignBlockToToolUse({
|
|
2645
|
+
blockIndex: chunk.index,
|
|
2646
|
+
toolUseId: toolCallId
|
|
2647
|
+
});
|
|
2648
|
+
delta1 = {
|
|
2649
|
+
content: null,
|
|
2650
|
+
tool_calls: [
|
|
2651
|
+
{
|
|
2652
|
+
index: index3,
|
|
2653
|
+
id: toolCallId,
|
|
2654
|
+
type: "function",
|
|
2655
|
+
function: {
|
|
2656
|
+
output: JSON.stringify(outputPayload)
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
]
|
|
2660
|
+
};
|
|
2661
|
+
} else if ([
|
|
2662
|
+
"code_execution_tool_result",
|
|
2663
|
+
"bash_code_execution_tool_result",
|
|
2664
|
+
"python_code_execution_tool_result"
|
|
2665
|
+
].includes(chunk.content_block.type)) {
|
|
2666
|
+
;
|
|
2667
|
+
toolCallId1 = (_getToolUseIdFromBlock1 = getToolUseIdFromBlock(chunk.content_block)) !== null && _getToolUseIdFromBlock1 !== void 0 ? _getToolUseIdFromBlock1 : "";
|
|
2668
|
+
_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, [
|
|
2669
|
+
"tool_use_id",
|
|
2670
|
+
"type",
|
|
2671
|
+
"id"
|
|
2672
|
+
]);
|
|
2673
|
+
index4 = getOrCreateIndexForToolUseId(toolCallId1);
|
|
2674
|
+
assignBlockToToolUse({
|
|
2675
|
+
blockIndex: chunk.index,
|
|
2676
|
+
toolUseId: toolCallId1
|
|
2677
|
+
});
|
|
2678
|
+
;
|
|
2679
|
+
outputPayload1 = Object.keys(rest).length > 0 ? rest : {
|
|
2680
|
+
content: (_chunk_content_block_content1 = chunk.content_block.content) !== null && _chunk_content_block_content1 !== void 0 ? _chunk_content_block_content1 : {}
|
|
2681
|
+
};
|
|
2682
|
+
delta1 = {
|
|
2683
|
+
content: null,
|
|
2684
|
+
tool_calls: [
|
|
2685
|
+
{
|
|
2686
|
+
index: index4,
|
|
2687
|
+
id: toolCallId1,
|
|
2688
|
+
type: "function",
|
|
2689
|
+
function: {
|
|
2690
|
+
output: JSON.stringify(outputPayload1)
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
]
|
|
2694
|
+
};
|
|
1988
2695
|
} else if ("text" in chunk.content_block) {
|
|
1989
2696
|
delta1 = {
|
|
1990
2697
|
content: chunk.content_block.text
|
|
@@ -2105,10 +2812,22 @@ var post5 = function(param) {
|
|
|
2105
2812
|
];
|
|
2106
2813
|
case 3:
|
|
2107
2814
|
data = _state.sent();
|
|
2815
|
+
normalizedContent = Array.isArray(data === null || data === void 0 ? void 0 : data.content) ? data.content.map(function(block) {
|
|
2816
|
+
if ((block === null || block === void 0 ? void 0 : block.type) === "tool_use" && (block === null || block === void 0 ? void 0 : block.name) === "computer") {
|
|
2817
|
+
var _block_input;
|
|
2818
|
+
return _object_spread_props(_object_spread({}, block), {
|
|
2819
|
+
input: normalizeComputerToolCallPayload((_block_input = block.input) !== null && _block_input !== void 0 ? _block_input : {})
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
return block;
|
|
2823
|
+
}) : data === null || data === void 0 ? void 0 : data.content;
|
|
2824
|
+
normalizedData = _object_spread({}, data, normalizedContent ? {
|
|
2825
|
+
content: normalizedContent
|
|
2826
|
+
} : {});
|
|
2108
2827
|
return [
|
|
2109
2828
|
2,
|
|
2110
2829
|
new Response(JSON.stringify({
|
|
2111
|
-
data:
|
|
2830
|
+
data: normalizedData
|
|
2112
2831
|
}), {
|
|
2113
2832
|
status: 200,
|
|
2114
2833
|
headers: {
|
|
@@ -3178,7 +3897,7 @@ var ollamaClientAdapter = function(param) {
|
|
|
3178
3897
|
};
|
|
3179
3898
|
// src/adapters/run/completionsRunAdapter/index.ts
|
|
3180
3899
|
import _ from "lodash";
|
|
3181
|
-
import { uid as uid2, omit as
|
|
3900
|
+
import { uid as uid2, omit as omit4, isEmpty as isEmpty2 } from "radash";
|
|
3182
3901
|
import dayjs from "dayjs";
|
|
3183
3902
|
// src/adapters/run/completionsRunAdapter/messages/index.ts
|
|
3184
3903
|
import { flat } from "radash";
|
|
@@ -3309,7 +4028,7 @@ var messages = /*#__PURE__*/ function() {
|
|
|
3309
4028
|
// src/adapters/run/completionsRunAdapter/index.ts
|
|
3310
4029
|
var updatedToolCall = function(param) {
|
|
3311
4030
|
var toolCall = param.toolCall, delta = param.delta;
|
|
3312
|
-
if (!toolCall) return
|
|
4031
|
+
if (!toolCall) return omit4(delta, [
|
|
3313
4032
|
"index"
|
|
3314
4033
|
]);
|
|
3315
4034
|
var result = _.cloneDeep(toolCall);
|
|
@@ -3340,10 +4059,11 @@ var toolCallsData = function(param) {
|
|
|
3340
4059
|
var prevToolCalls = param.prevToolCalls, delta = param.delta;
|
|
3341
4060
|
if (!prevToolCalls) {
|
|
3342
4061
|
return delta.tool_calls.map(function(tc) {
|
|
4062
|
+
var _tc_type;
|
|
3343
4063
|
return _object_spread({
|
|
3344
4064
|
id: uid2(24),
|
|
3345
|
-
type: "function"
|
|
3346
|
-
},
|
|
4065
|
+
type: (_tc_type = tc.type) !== null && _tc_type !== void 0 ? _tc_type : "function"
|
|
4066
|
+
}, omit4(tc, [
|
|
3347
4067
|
"index"
|
|
3348
4068
|
]));
|
|
3349
4069
|
});
|
|
@@ -3378,7 +4098,7 @@ var completionsRunAdapter = function() {
|
|
|
3378
4098
|
return {
|
|
3379
4099
|
handleRun: /*#__PURE__*/ function() {
|
|
3380
4100
|
var _ref = _async_to_generator(function(param) {
|
|
3381
|
-
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;
|
|
4101
|
+
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;
|
|
3382
4102
|
return _ts_generator(this, function(_state) {
|
|
3383
4103
|
switch(_state.label){
|
|
3384
4104
|
case 0:
|
|
@@ -3585,9 +4305,10 @@ var completionsRunAdapter = function() {
|
|
|
3585
4305
|
step_details: {
|
|
3586
4306
|
type: "tool_calls",
|
|
3587
4307
|
tool_calls: delta.tool_calls.map(function(tc) {
|
|
4308
|
+
var _tc_type;
|
|
3588
4309
|
return _object_spread({
|
|
3589
4310
|
id: uid2(24),
|
|
3590
|
-
type: "function"
|
|
4311
|
+
type: (_tc_type = tc.type) !== null && _tc_type !== void 0 ? _tc_type : "function"
|
|
3591
4312
|
}, tc);
|
|
3592
4313
|
})
|
|
3593
4314
|
}
|
|
@@ -3695,18 +4416,83 @@ var completionsRunAdapter = function() {
|
|
|
3695
4416
|
];
|
|
3696
4417
|
case 22:
|
|
3697
4418
|
message = _state.sent();
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
4419
|
+
messageToolCalls = (_message_toolCalls = message.toolCalls) !== null && _message_toolCalls !== void 0 ? _message_toolCalls : [];
|
|
4420
|
+
functionToolCalls = messageToolCalls.filter(function(toolCall) {
|
|
4421
|
+
return toolCall.type === "function";
|
|
4422
|
+
});
|
|
4423
|
+
pendingFunctionToolCalls = functionToolCalls.filter(function(toolCall) {
|
|
4424
|
+
var _toolCall_function;
|
|
4425
|
+
return !((_toolCall_function = toolCall.function) === null || _toolCall_function === void 0 ? void 0 : _toolCall_function.output);
|
|
4426
|
+
});
|
|
4427
|
+
if (!isEmpty2(pendingFunctionToolCalls)) return [
|
|
4428
|
+
3,
|
|
4429
|
+
25
|
|
4430
|
+
];
|
|
4431
|
+
if (!toolCallsRunStep) return [
|
|
4432
|
+
3,
|
|
4433
|
+
24
|
|
4434
|
+
];
|
|
4435
|
+
return [
|
|
4436
|
+
4,
|
|
4437
|
+
onEvent2({
|
|
4438
|
+
event: "thread.run.step.completed",
|
|
4439
|
+
data: _object_spread_props(_object_spread({}, toolCallsRunStep), {
|
|
4440
|
+
status: "completed",
|
|
4441
|
+
completed_at: dayjs().unix(),
|
|
4442
|
+
step_details: {
|
|
4443
|
+
type: "tool_calls",
|
|
4444
|
+
tool_calls: currentToolCalls !== null && currentToolCalls !== void 0 ? currentToolCalls : []
|
|
4445
|
+
}
|
|
3707
4446
|
})
|
|
3708
|
-
|
|
3709
|
-
|
|
4447
|
+
})
|
|
4448
|
+
];
|
|
4449
|
+
case 23:
|
|
4450
|
+
toolCallsRunStep = _state.sent();
|
|
4451
|
+
_state.label = 24;
|
|
4452
|
+
case 24:
|
|
4453
|
+
return [
|
|
4454
|
+
2,
|
|
4455
|
+
onEvent2({
|
|
4456
|
+
event: "thread.run.completed",
|
|
4457
|
+
data: _object_spread_props(_object_spread({}, run3), {
|
|
4458
|
+
status: "completed",
|
|
4459
|
+
completed_at: dayjs().unix()
|
|
4460
|
+
})
|
|
4461
|
+
})
|
|
4462
|
+
];
|
|
4463
|
+
case 25:
|
|
4464
|
+
requiredToolCalls = pendingFunctionToolCalls.map(function(toolCall) {
|
|
4465
|
+
var _toolCall_function, _toolCall_function1, _toolCall_function2;
|
|
4466
|
+
var _toolCall_function_arguments;
|
|
4467
|
+
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 : "";
|
|
4468
|
+
if (((_toolCall_function1 = toolCall.function) === null || _toolCall_function1 === void 0 ? void 0 : _toolCall_function1.name) === "computer_call") {
|
|
4469
|
+
var parsedArguments = {};
|
|
4470
|
+
try {
|
|
4471
|
+
parsedArguments = JSON.parse(args || "{}");
|
|
4472
|
+
} catch (e) {
|
|
4473
|
+
parsedArguments = {};
|
|
4474
|
+
}
|
|
4475
|
+
var _parsedArguments_action, _ref;
|
|
4476
|
+
var computerCall = {
|
|
4477
|
+
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 : {},
|
|
4478
|
+
pending_safety_checks: Array.isArray(parsedArguments === null || parsedArguments === void 0 ? void 0 : parsedArguments.pending_safety_checks) ? parsedArguments.pending_safety_checks : []
|
|
4479
|
+
};
|
|
4480
|
+
return {
|
|
4481
|
+
id: toolCall.id,
|
|
4482
|
+
type: "computer_call",
|
|
4483
|
+
computer_call: computerCall
|
|
4484
|
+
};
|
|
4485
|
+
}
|
|
4486
|
+
var _toolCall_function_name;
|
|
4487
|
+
return {
|
|
4488
|
+
id: toolCall.id,
|
|
4489
|
+
type: "function",
|
|
4490
|
+
function: {
|
|
4491
|
+
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 : "",
|
|
4492
|
+
arguments: args
|
|
4493
|
+
}
|
|
4494
|
+
};
|
|
4495
|
+
});
|
|
3710
4496
|
return [
|
|
3711
4497
|
2,
|
|
3712
4498
|
onEvent2({
|
|
@@ -3716,7 +4502,7 @@ var completionsRunAdapter = function() {
|
|
|
3716
4502
|
required_action: {
|
|
3717
4503
|
type: "submit_tool_outputs",
|
|
3718
4504
|
submit_tool_outputs: {
|
|
3719
|
-
tool_calls:
|
|
4505
|
+
tool_calls: requiredToolCalls
|
|
3720
4506
|
}
|
|
3721
4507
|
}
|
|
3722
4508
|
})
|
|
@@ -4289,6 +5075,40 @@ var threadRunStepDelta = function(param) {
|
|
|
4289
5075
|
var event = param.event, controller = param.controller;
|
|
4290
5076
|
return controller.enqueue(event);
|
|
4291
5077
|
};
|
|
5078
|
+
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadRunStepCompleted.ts
|
|
5079
|
+
var threadRunStepCompleted = /*#__PURE__*/ function() {
|
|
5080
|
+
var _ref = _async_to_generator(function(param) {
|
|
5081
|
+
var prisma, event, controller;
|
|
5082
|
+
return _ts_generator(this, function(_state) {
|
|
5083
|
+
switch(_state.label){
|
|
5084
|
+
case 0:
|
|
5085
|
+
prisma = param.prisma, event = param.event, controller = param.controller;
|
|
5086
|
+
controller.enqueue(event);
|
|
5087
|
+
return [
|
|
5088
|
+
4,
|
|
5089
|
+
prisma.runStep.update({
|
|
5090
|
+
where: {
|
|
5091
|
+
id: event.data.id
|
|
5092
|
+
},
|
|
5093
|
+
data: {
|
|
5094
|
+
status: "COMPLETED" /* COMPLETED */ ,
|
|
5095
|
+
stepDetails: event.data.step_details,
|
|
5096
|
+
completedAt: event.data.completed_at
|
|
5097
|
+
}
|
|
5098
|
+
})
|
|
5099
|
+
];
|
|
5100
|
+
case 1:
|
|
5101
|
+
_state.sent();
|
|
5102
|
+
return [
|
|
5103
|
+
2
|
|
5104
|
+
];
|
|
5105
|
+
}
|
|
5106
|
+
});
|
|
5107
|
+
});
|
|
5108
|
+
return function threadRunStepCompleted(_) {
|
|
5109
|
+
return _ref.apply(this, arguments);
|
|
5110
|
+
};
|
|
5111
|
+
}();
|
|
4292
5112
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/onEvent/handlers/threadMessageCreated.ts
|
|
4293
5113
|
var status2 = function(event) {
|
|
4294
5114
|
if (event.data.status === "completed") return "COMPLETED" /* COMPLETED */ ;
|
|
@@ -4419,6 +5239,7 @@ var handlers = {
|
|
|
4419
5239
|
"thread.run.requires_action": threadRunRequiresAction,
|
|
4420
5240
|
"thread.run.step.created": threadRunStepCreated,
|
|
4421
5241
|
"thread.run.step.delta": threadRunStepDelta,
|
|
5242
|
+
"thread.run.step.completed": threadRunStepCompleted,
|
|
4422
5243
|
"thread.message.created": threadMessageCreated,
|
|
4423
5244
|
"thread.message.delta": threadMessageDelta,
|
|
4424
5245
|
"thread.message.completed": threadMessageCompleted
|