@mindstudio-ai/agent 0.1.128 → 0.1.130
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/cli.js +758 -320
- package/dist/index.js +612 -217
- package/dist/index.js.map +1 -1
- package/dist/postinstall.js +758 -320
- package/package.json +1 -5
package/dist/postinstall.js
CHANGED
|
@@ -1213,16 +1213,22 @@ async function requestWithRetry(config, method, url, body, attempt) {
|
|
|
1213
1213
|
const body2 = JSON.parse(text);
|
|
1214
1214
|
details = body2;
|
|
1215
1215
|
const errMsg = (typeof body2.errorMessage === "string" ? body2.errorMessage : void 0) ?? (typeof body2.errorString === "string" ? body2.errorString : void 0) ?? (typeof body2.error === "string" ? body2.error : void 0) ?? (typeof body2.message === "string" ? body2.message : void 0) ?? (typeof body2.details === "string" ? body2.details : void 0);
|
|
1216
|
-
if (errMsg)
|
|
1217
|
-
|
|
1216
|
+
if (errMsg) {
|
|
1217
|
+
message = errMsg;
|
|
1218
|
+
} else if (body2.error || body2.message || body2.details) {
|
|
1218
1219
|
message = JSON.stringify(body2.error ?? body2.message ?? body2.details);
|
|
1219
1220
|
}
|
|
1220
|
-
if (body2.code)
|
|
1221
|
-
|
|
1221
|
+
if (body2.code) {
|
|
1222
|
+
code = String(body2.code);
|
|
1223
|
+
} else if (typeof body2.errorString === "string") {
|
|
1224
|
+
code = body2.errorString;
|
|
1225
|
+
}
|
|
1222
1226
|
} catch {
|
|
1223
1227
|
if (text) {
|
|
1224
1228
|
const stripped = text.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
1225
|
-
if (stripped)
|
|
1229
|
+
if (stripped) {
|
|
1230
|
+
message = stripped.slice(0, 200);
|
|
1231
|
+
}
|
|
1226
1232
|
}
|
|
1227
1233
|
}
|
|
1228
1234
|
} catch {
|
|
@@ -1600,7 +1606,9 @@ var init_rate_limit = __esm({
|
|
|
1600
1606
|
release() {
|
|
1601
1607
|
this.inflight--;
|
|
1602
1608
|
const next = this.queue.shift();
|
|
1603
|
-
if (next)
|
|
1609
|
+
if (next) {
|
|
1610
|
+
next();
|
|
1611
|
+
}
|
|
1604
1612
|
}
|
|
1605
1613
|
/** Update limits from response headers. */
|
|
1606
1614
|
updateFromHeaders(headers) {
|
|
@@ -1747,7 +1755,9 @@ var init_auth = __esm({
|
|
|
1747
1755
|
{},
|
|
1748
1756
|
{
|
|
1749
1757
|
get(_, prop) {
|
|
1750
|
-
if (typeof prop === "string")
|
|
1758
|
+
if (typeof prop === "string") {
|
|
1759
|
+
return prop;
|
|
1760
|
+
}
|
|
1751
1761
|
return void 0;
|
|
1752
1762
|
}
|
|
1753
1763
|
}
|
|
@@ -1757,9 +1767,15 @@ var init_auth = __esm({
|
|
|
1757
1767
|
|
|
1758
1768
|
// src/db/sql.ts
|
|
1759
1769
|
function serializeParam(val) {
|
|
1760
|
-
if (val === null || val === void 0)
|
|
1761
|
-
|
|
1762
|
-
|
|
1770
|
+
if (val === null || val === void 0) {
|
|
1771
|
+
return null;
|
|
1772
|
+
}
|
|
1773
|
+
if (typeof val === "boolean") {
|
|
1774
|
+
return val ? 1 : 0;
|
|
1775
|
+
}
|
|
1776
|
+
if (typeof val === "number" || typeof val === "string") {
|
|
1777
|
+
return val;
|
|
1778
|
+
}
|
|
1763
1779
|
return JSON.stringify(val);
|
|
1764
1780
|
}
|
|
1765
1781
|
function serializeColumnParam(val, columnName, columns) {
|
|
@@ -1770,15 +1786,25 @@ function serializeColumnParam(val, columnName, columns) {
|
|
|
1770
1786
|
return serializeParam(val);
|
|
1771
1787
|
}
|
|
1772
1788
|
function escapeValue(val) {
|
|
1773
|
-
if (val === null || val === void 0)
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
if (typeof val === "
|
|
1789
|
+
if (val === null || val === void 0) {
|
|
1790
|
+
return "NULL";
|
|
1791
|
+
}
|
|
1792
|
+
if (typeof val === "boolean") {
|
|
1793
|
+
return val ? "1" : "0";
|
|
1794
|
+
}
|
|
1795
|
+
if (typeof val === "number") {
|
|
1796
|
+
return String(val);
|
|
1797
|
+
}
|
|
1798
|
+
if (typeof val === "string") {
|
|
1799
|
+
return `'${val.replace(/'/g, "''")}'`;
|
|
1800
|
+
}
|
|
1777
1801
|
const json = JSON.stringify(val);
|
|
1778
1802
|
return `'${json.replace(/'/g, "''")}'`;
|
|
1779
1803
|
}
|
|
1780
1804
|
function deserializeRow(row, columns) {
|
|
1781
|
-
if (row == null)
|
|
1805
|
+
if (row == null) {
|
|
1806
|
+
return row;
|
|
1807
|
+
}
|
|
1782
1808
|
const result = {};
|
|
1783
1809
|
for (const [key, value] of Object.entries(row)) {
|
|
1784
1810
|
const col = columns.find((c) => c.name === key);
|
|
@@ -1812,11 +1838,19 @@ function buildSelect(table, options = {}) {
|
|
|
1812
1838
|
const params = [];
|
|
1813
1839
|
if (options.where) {
|
|
1814
1840
|
sql += ` WHERE ${options.where}`;
|
|
1815
|
-
if (options.whereParams)
|
|
1841
|
+
if (options.whereParams) {
|
|
1842
|
+
params.push(...options.whereParams);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
if (options.orderBy) {
|
|
1846
|
+
sql += ` ORDER BY ${options.orderBy}${options.desc ? " DESC" : " ASC"}`;
|
|
1847
|
+
}
|
|
1848
|
+
if (options.limit != null) {
|
|
1849
|
+
sql += ` LIMIT ${options.limit}`;
|
|
1850
|
+
}
|
|
1851
|
+
if (options.offset != null) {
|
|
1852
|
+
sql += ` OFFSET ${options.offset}`;
|
|
1816
1853
|
}
|
|
1817
|
-
if (options.orderBy) sql += ` ORDER BY ${options.orderBy}${options.desc ? " DESC" : " ASC"}`;
|
|
1818
|
-
if (options.limit != null) sql += ` LIMIT ${options.limit}`;
|
|
1819
|
-
if (options.offset != null) sql += ` OFFSET ${options.offset}`;
|
|
1820
1854
|
return { sql, params: params.length > 0 ? params : void 0 };
|
|
1821
1855
|
}
|
|
1822
1856
|
function assertSqlIdentifier(name, context) {
|
|
@@ -1845,27 +1879,47 @@ function aggregateExpr(fn, column) {
|
|
|
1845
1879
|
}
|
|
1846
1880
|
}
|
|
1847
1881
|
function buildScalarAggregate(table, fn, column, where, whereParams) {
|
|
1848
|
-
if (column != null)
|
|
1882
|
+
if (column != null) {
|
|
1883
|
+
assertSqlIdentifier(column, "aggregate column");
|
|
1884
|
+
}
|
|
1849
1885
|
let sql = `SELECT ${aggregateExpr(fn, column ?? void 0)} AS value FROM ${table}`;
|
|
1850
|
-
if (where)
|
|
1886
|
+
if (where) {
|
|
1887
|
+
sql += ` WHERE ${where}`;
|
|
1888
|
+
}
|
|
1851
1889
|
return { sql, params: whereParams?.length ? whereParams : void 0 };
|
|
1852
1890
|
}
|
|
1853
1891
|
function buildGroupedAggregate(table, options) {
|
|
1854
|
-
for (const col of options.by)
|
|
1892
|
+
for (const col of options.by) {
|
|
1893
|
+
assertSqlIdentifier(col, "group-by column");
|
|
1894
|
+
}
|
|
1855
1895
|
for (const term of options.select) {
|
|
1856
1896
|
assertSqlIdentifier(term.alias, "aggregate alias");
|
|
1857
|
-
if (term.column != null)
|
|
1897
|
+
if (term.column != null) {
|
|
1898
|
+
assertSqlIdentifier(term.column, "aggregate column");
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
if (options.orderBy != null) {
|
|
1902
|
+
assertSqlIdentifier(options.orderBy, "aggregate order key");
|
|
1858
1903
|
}
|
|
1859
|
-
if (options.orderBy != null) assertSqlIdentifier(options.orderBy, "aggregate order key");
|
|
1860
1904
|
const selectList = [
|
|
1861
1905
|
...options.by,
|
|
1862
|
-
...options.select.map(
|
|
1906
|
+
...options.select.map(
|
|
1907
|
+
(t) => `${aggregateExpr(t.fn, t.column)} AS ${t.alias}`
|
|
1908
|
+
)
|
|
1863
1909
|
].join(", ");
|
|
1864
1910
|
let sql = `SELECT ${selectList} FROM ${table}`;
|
|
1865
|
-
if (options.where)
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
if (options.
|
|
1911
|
+
if (options.where) {
|
|
1912
|
+
sql += ` WHERE ${options.where}`;
|
|
1913
|
+
}
|
|
1914
|
+
if (options.by.length > 0) {
|
|
1915
|
+
sql += ` GROUP BY ${options.by.join(", ")}`;
|
|
1916
|
+
}
|
|
1917
|
+
if (options.orderBy) {
|
|
1918
|
+
sql += ` ORDER BY ${options.orderBy}${options.desc ? " DESC" : " ASC"}`;
|
|
1919
|
+
}
|
|
1920
|
+
if (options.limit != null) {
|
|
1921
|
+
sql += ` LIMIT ${options.limit}`;
|
|
1922
|
+
}
|
|
1869
1923
|
return {
|
|
1870
1924
|
sql,
|
|
1871
1925
|
params: options.whereParams?.length ? options.whereParams : void 0
|
|
@@ -1874,7 +1928,10 @@ function buildGroupedAggregate(table, options) {
|
|
|
1874
1928
|
function buildExists(table, where, whereParams, negate) {
|
|
1875
1929
|
const inner = where ? `SELECT 1 FROM ${table} WHERE ${where}` : `SELECT 1 FROM ${table}`;
|
|
1876
1930
|
const fn = negate ? "NOT EXISTS" : "EXISTS";
|
|
1877
|
-
return {
|
|
1931
|
+
return {
|
|
1932
|
+
sql: `SELECT ${fn}(${inner}) as result`,
|
|
1933
|
+
params: whereParams?.length ? whereParams : void 0
|
|
1934
|
+
};
|
|
1878
1935
|
}
|
|
1879
1936
|
function buildInsert(table, data, columns) {
|
|
1880
1937
|
const filtered = stripSystemColumns(data);
|
|
@@ -1904,9 +1961,7 @@ function buildUpsert(table, data, conflictColumns, columns) {
|
|
|
1904
1961
|
const filtered = stripSystemColumns(data);
|
|
1905
1962
|
const keys = Object.keys(filtered);
|
|
1906
1963
|
const placeholders = keys.map(() => "?").join(", ");
|
|
1907
|
-
const params = keys.map(
|
|
1908
|
-
(k) => serializeColumnParam(filtered[k], k, columns)
|
|
1909
|
-
);
|
|
1964
|
+
const params = keys.map((k) => serializeColumnParam(filtered[k], k, columns));
|
|
1910
1965
|
const updateKeys = keys.filter((k) => !conflictColumns.includes(k));
|
|
1911
1966
|
const conflict = conflictColumns.join(", ");
|
|
1912
1967
|
const sql = updateKeys.length > 0 ? `INSERT INTO ${table} (${keys.join(", ")}) VALUES (${placeholders}) ON CONFLICT(${conflict}) DO UPDATE SET ${updateKeys.map((k) => `${k} = excluded.${k}`).join(", ")} RETURNING *` : `INSERT INTO ${table} (${keys.join(", ")}) VALUES (${placeholders}) ON CONFLICT(${conflict}) DO NOTHING RETURNING *`;
|
|
@@ -1914,7 +1969,9 @@ function buildUpsert(table, data, conflictColumns, columns) {
|
|
|
1914
1969
|
}
|
|
1915
1970
|
function buildDelete(table, where, whereParams) {
|
|
1916
1971
|
let sql = `DELETE FROM ${table}`;
|
|
1917
|
-
if (where)
|
|
1972
|
+
if (where) {
|
|
1973
|
+
sql += ` WHERE ${where}`;
|
|
1974
|
+
}
|
|
1918
1975
|
return { sql, params: whereParams?.length ? whereParams : void 0 };
|
|
1919
1976
|
}
|
|
1920
1977
|
function stripSystemColumns(data) {
|
|
@@ -1950,37 +2007,65 @@ function compilePredicate(fn, bindings) {
|
|
|
1950
2007
|
try {
|
|
1951
2008
|
const source = fn.toString();
|
|
1952
2009
|
const names = extractParamNames(source);
|
|
1953
|
-
if (!names)
|
|
2010
|
+
if (!names) {
|
|
2011
|
+
return { type: "js", fn, reason: "could not extract parameter name" };
|
|
2012
|
+
}
|
|
1954
2013
|
const body = extractBody(source);
|
|
1955
|
-
if (!body)
|
|
2014
|
+
if (!body) {
|
|
2015
|
+
return { type: "js", fn, reason: "could not extract function body" };
|
|
2016
|
+
}
|
|
1956
2017
|
const tokens = tokenize(body);
|
|
1957
|
-
if (tokens.length === 0)
|
|
2018
|
+
if (tokens.length === 0) {
|
|
2019
|
+
return { type: "js", fn, reason: "empty token stream" };
|
|
2020
|
+
}
|
|
1958
2021
|
const parser = new Parser(tokens, names.row, names.bindings, bindings, fn);
|
|
1959
2022
|
const ast = parser.parseExpression();
|
|
1960
|
-
if (!ast)
|
|
1961
|
-
|
|
2023
|
+
if (!ast) {
|
|
2024
|
+
return { type: "js", fn, reason: "could not parse expression" };
|
|
2025
|
+
}
|
|
2026
|
+
if (parser.pos < tokens.length) {
|
|
2027
|
+
return { type: "js", fn, reason: "unexpected tokens after expression" };
|
|
2028
|
+
}
|
|
1962
2029
|
const where = compileNode(ast);
|
|
1963
|
-
if (!where)
|
|
2030
|
+
if (!where) {
|
|
2031
|
+
return { type: "js", fn, reason: "could not compile to SQL" };
|
|
2032
|
+
}
|
|
1964
2033
|
return { type: "sql", where };
|
|
1965
2034
|
} catch (err) {
|
|
1966
|
-
return {
|
|
2035
|
+
return {
|
|
2036
|
+
type: "js",
|
|
2037
|
+
fn,
|
|
2038
|
+
reason: `compilation error: ${err?.message || "unknown"}`
|
|
2039
|
+
};
|
|
1967
2040
|
}
|
|
1968
2041
|
}
|
|
1969
2042
|
function extractParamNames(source) {
|
|
1970
2043
|
const arrowIdx = source.indexOf("=>");
|
|
1971
|
-
if (arrowIdx === -1)
|
|
2044
|
+
if (arrowIdx === -1) {
|
|
2045
|
+
return null;
|
|
2046
|
+
}
|
|
1972
2047
|
let paramList = source.slice(0, arrowIdx).trim();
|
|
1973
2048
|
if (paramList.startsWith("(") && paramList.endsWith(")")) {
|
|
1974
2049
|
paramList = paramList.slice(1, -1).trim();
|
|
1975
2050
|
}
|
|
1976
|
-
if (paramList.length === 0)
|
|
2051
|
+
if (paramList.length === 0) {
|
|
2052
|
+
return null;
|
|
2053
|
+
}
|
|
1977
2054
|
const parts = splitParams(paramList);
|
|
1978
|
-
if (parts.length === 0 || parts.length > 2)
|
|
2055
|
+
if (parts.length === 0 || parts.length > 2) {
|
|
2056
|
+
return null;
|
|
2057
|
+
}
|
|
1979
2058
|
const row = stripTypeAnnotation(parts[0]);
|
|
1980
|
-
if (!row)
|
|
1981
|
-
|
|
2059
|
+
if (!row) {
|
|
2060
|
+
return null;
|
|
2061
|
+
}
|
|
2062
|
+
if (parts.length === 1) {
|
|
2063
|
+
return { row };
|
|
2064
|
+
}
|
|
1982
2065
|
const bindings = stripTypeAnnotation(parts[1]);
|
|
1983
|
-
if (!bindings)
|
|
2066
|
+
if (!bindings) {
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
1984
2069
|
return { row, bindings };
|
|
1985
2070
|
}
|
|
1986
2071
|
function splitParams(input) {
|
|
@@ -1988,8 +2073,11 @@ function splitParams(input) {
|
|
|
1988
2073
|
let depth = 0;
|
|
1989
2074
|
let current = "";
|
|
1990
2075
|
for (const ch of input) {
|
|
1991
|
-
if (ch === "<" || ch === "(")
|
|
1992
|
-
|
|
2076
|
+
if (ch === "<" || ch === "(") {
|
|
2077
|
+
depth++;
|
|
2078
|
+
} else if (ch === ">" || ch === ")") {
|
|
2079
|
+
depth--;
|
|
2080
|
+
}
|
|
1993
2081
|
if (ch === "," && depth === 0) {
|
|
1994
2082
|
parts.push(current.trim());
|
|
1995
2083
|
current = "";
|
|
@@ -1997,7 +2085,9 @@ function splitParams(input) {
|
|
|
1997
2085
|
current += ch;
|
|
1998
2086
|
}
|
|
1999
2087
|
}
|
|
2000
|
-
if (current.trim())
|
|
2088
|
+
if (current.trim()) {
|
|
2089
|
+
parts.push(current.trim());
|
|
2090
|
+
}
|
|
2001
2091
|
return parts;
|
|
2002
2092
|
}
|
|
2003
2093
|
function stripTypeAnnotation(part) {
|
|
@@ -2007,11 +2097,15 @@ function stripTypeAnnotation(part) {
|
|
|
2007
2097
|
}
|
|
2008
2098
|
function extractBody(source) {
|
|
2009
2099
|
const arrowIdx = source.indexOf("=>");
|
|
2010
|
-
if (arrowIdx === -1)
|
|
2100
|
+
if (arrowIdx === -1) {
|
|
2101
|
+
return null;
|
|
2102
|
+
}
|
|
2011
2103
|
let body = source.slice(arrowIdx + 2).trim();
|
|
2012
2104
|
if (body.startsWith("{")) {
|
|
2013
2105
|
const match = body.match(/^\{\s*return\s+([\s\S]+?)\s*;?\s*\}$/);
|
|
2014
|
-
if (!match)
|
|
2106
|
+
if (!match) {
|
|
2107
|
+
return null;
|
|
2108
|
+
}
|
|
2015
2109
|
body = match[1];
|
|
2016
2110
|
}
|
|
2017
2111
|
return body.trim() || null;
|
|
@@ -2032,18 +2126,24 @@ function tokenize(expr) {
|
|
|
2032
2126
|
while (i < expr.length && expr[i] !== quote) {
|
|
2033
2127
|
if (expr[i] === "\\") {
|
|
2034
2128
|
i++;
|
|
2035
|
-
if (i < expr.length)
|
|
2129
|
+
if (i < expr.length) {
|
|
2130
|
+
str += expr[i];
|
|
2131
|
+
}
|
|
2036
2132
|
} else {
|
|
2037
2133
|
str += expr[i];
|
|
2038
2134
|
}
|
|
2039
2135
|
i++;
|
|
2040
2136
|
}
|
|
2041
|
-
if (i >= expr.length)
|
|
2137
|
+
if (i >= expr.length) {
|
|
2138
|
+
return [];
|
|
2139
|
+
}
|
|
2042
2140
|
i++;
|
|
2043
2141
|
tokens.push({ type: "string", value: str });
|
|
2044
2142
|
continue;
|
|
2045
2143
|
}
|
|
2046
|
-
if (ch === "`")
|
|
2144
|
+
if (ch === "`") {
|
|
2145
|
+
return [];
|
|
2146
|
+
}
|
|
2047
2147
|
if (/[0-9]/.test(ch) || ch === "-" && i + 1 < expr.length && /[0-9]/.test(expr[i + 1])) {
|
|
2048
2148
|
let num = ch;
|
|
2049
2149
|
i++;
|
|
@@ -2120,7 +2220,9 @@ function compileNode(node) {
|
|
|
2120
2220
|
case "nullCheck":
|
|
2121
2221
|
return `${node.field} ${node.isNull ? "IS NULL" : "IS NOT NULL"}`;
|
|
2122
2222
|
case "in": {
|
|
2123
|
-
if (node.values.length === 0)
|
|
2223
|
+
if (node.values.length === 0) {
|
|
2224
|
+
return "0";
|
|
2225
|
+
}
|
|
2124
2226
|
const vals = node.values.map(escapeValue).join(", ");
|
|
2125
2227
|
return `${node.field} IN (${vals})`;
|
|
2126
2228
|
}
|
|
@@ -2131,12 +2233,16 @@ function compileNode(node) {
|
|
|
2131
2233
|
case "logical": {
|
|
2132
2234
|
const left = compileNode(node.left);
|
|
2133
2235
|
const right = compileNode(node.right);
|
|
2134
|
-
if (!left || !right)
|
|
2236
|
+
if (!left || !right) {
|
|
2237
|
+
return null;
|
|
2238
|
+
}
|
|
2135
2239
|
return `(${left} ${node.operator} ${right})`;
|
|
2136
2240
|
}
|
|
2137
2241
|
case "not": {
|
|
2138
2242
|
const inner = compileNode(node.operand);
|
|
2139
|
-
if (!inner)
|
|
2243
|
+
if (!inner) {
|
|
2244
|
+
return null;
|
|
2245
|
+
}
|
|
2140
2246
|
return `NOT (${inner})`;
|
|
2141
2247
|
}
|
|
2142
2248
|
default:
|
|
@@ -2171,9 +2277,15 @@ var init_predicate = __esm({
|
|
|
2171
2277
|
/** Check if the current token matches an expected type and value. */
|
|
2172
2278
|
match(type, value) {
|
|
2173
2279
|
const t = this.peek();
|
|
2174
|
-
if (!t)
|
|
2175
|
-
|
|
2176
|
-
|
|
2280
|
+
if (!t) {
|
|
2281
|
+
return false;
|
|
2282
|
+
}
|
|
2283
|
+
if (t.type !== type) {
|
|
2284
|
+
return false;
|
|
2285
|
+
}
|
|
2286
|
+
if (value !== void 0 && t.value !== value) {
|
|
2287
|
+
return false;
|
|
2288
|
+
}
|
|
2177
2289
|
return true;
|
|
2178
2290
|
}
|
|
2179
2291
|
/** Consume a token if it matches, otherwise return false. */
|
|
@@ -2192,11 +2304,15 @@ var init_predicate = __esm({
|
|
|
2192
2304
|
/** or_expr → and_expr ( '||' and_expr )* */
|
|
2193
2305
|
parseOr() {
|
|
2194
2306
|
let left = this.parseAnd();
|
|
2195
|
-
if (!left)
|
|
2307
|
+
if (!left) {
|
|
2308
|
+
return null;
|
|
2309
|
+
}
|
|
2196
2310
|
while (this.match("operator", "||")) {
|
|
2197
2311
|
this.advance();
|
|
2198
2312
|
const right = this.parseAnd();
|
|
2199
|
-
if (!right)
|
|
2313
|
+
if (!right) {
|
|
2314
|
+
return null;
|
|
2315
|
+
}
|
|
2200
2316
|
left = { kind: "logical", operator: "OR", left, right };
|
|
2201
2317
|
}
|
|
2202
2318
|
return left;
|
|
@@ -2204,11 +2320,15 @@ var init_predicate = __esm({
|
|
|
2204
2320
|
/** and_expr → not_expr ( '&&' not_expr )* */
|
|
2205
2321
|
parseAnd() {
|
|
2206
2322
|
let left = this.parseNot();
|
|
2207
|
-
if (!left)
|
|
2323
|
+
if (!left) {
|
|
2324
|
+
return null;
|
|
2325
|
+
}
|
|
2208
2326
|
while (this.match("operator", "&&")) {
|
|
2209
2327
|
this.advance();
|
|
2210
2328
|
const right = this.parseNot();
|
|
2211
|
-
if (!right)
|
|
2329
|
+
if (!right) {
|
|
2330
|
+
return null;
|
|
2331
|
+
}
|
|
2212
2332
|
left = { kind: "logical", operator: "AND", left, right };
|
|
2213
2333
|
}
|
|
2214
2334
|
return left;
|
|
@@ -2220,12 +2340,18 @@ var init_predicate = __esm({
|
|
|
2220
2340
|
if (this.match("lparen")) {
|
|
2221
2341
|
this.advance();
|
|
2222
2342
|
const inner2 = this.parseExpression();
|
|
2223
|
-
if (!inner2)
|
|
2224
|
-
|
|
2343
|
+
if (!inner2) {
|
|
2344
|
+
return null;
|
|
2345
|
+
}
|
|
2346
|
+
if (!this.eat("rparen")) {
|
|
2347
|
+
return null;
|
|
2348
|
+
}
|
|
2225
2349
|
return { kind: "not", operand: inner2 };
|
|
2226
2350
|
}
|
|
2227
2351
|
const inner = this.parsePrimary();
|
|
2228
|
-
if (!inner)
|
|
2352
|
+
if (!inner) {
|
|
2353
|
+
return null;
|
|
2354
|
+
}
|
|
2229
2355
|
if (inner.kind === "booleanField") {
|
|
2230
2356
|
return { ...inner, negated: !inner.negated };
|
|
2231
2357
|
}
|
|
@@ -2243,8 +2369,12 @@ var init_predicate = __esm({
|
|
|
2243
2369
|
if (this.match("lparen")) {
|
|
2244
2370
|
this.advance();
|
|
2245
2371
|
const inner = this.parseExpression();
|
|
2246
|
-
if (!inner)
|
|
2247
|
-
|
|
2372
|
+
if (!inner) {
|
|
2373
|
+
return null;
|
|
2374
|
+
}
|
|
2375
|
+
if (!this.eat("rparen")) {
|
|
2376
|
+
return null;
|
|
2377
|
+
}
|
|
2248
2378
|
return inner;
|
|
2249
2379
|
}
|
|
2250
2380
|
if (this.match("lbracket")) {
|
|
@@ -2273,7 +2403,9 @@ var init_predicate = __esm({
|
|
|
2273
2403
|
parseFieldExpression() {
|
|
2274
2404
|
this.advance();
|
|
2275
2405
|
const field = this.parseFieldPath();
|
|
2276
|
-
if (!field)
|
|
2406
|
+
if (!field) {
|
|
2407
|
+
return null;
|
|
2408
|
+
}
|
|
2277
2409
|
const next = this.peek();
|
|
2278
2410
|
if (next?.type === "dot" && this.lookAheadForIncludes()) {
|
|
2279
2411
|
return this.parseFieldIncludes(field);
|
|
@@ -2288,11 +2420,17 @@ var init_predicate = __esm({
|
|
|
2288
2420
|
* `o.status` → `"status"`, `o.address.city` → `"json_extract(address, '$.city')"`.
|
|
2289
2421
|
*/
|
|
2290
2422
|
parseFieldPath() {
|
|
2291
|
-
if (!this.eat("dot"))
|
|
2292
|
-
|
|
2423
|
+
if (!this.eat("dot")) {
|
|
2424
|
+
return null;
|
|
2425
|
+
}
|
|
2426
|
+
if (!this.match("identifier")) {
|
|
2427
|
+
return null;
|
|
2428
|
+
}
|
|
2293
2429
|
const parts = [this.advance().value];
|
|
2294
2430
|
while (this.match("dot") && this.tokens[this.pos + 1]?.type === "identifier") {
|
|
2295
|
-
if (this.tokens[this.pos + 2]?.type === "lparen")
|
|
2431
|
+
if (this.tokens[this.pos + 2]?.type === "lparen") {
|
|
2432
|
+
break;
|
|
2433
|
+
}
|
|
2296
2434
|
this.advance();
|
|
2297
2435
|
parts.push(this.advance().value);
|
|
2298
2436
|
}
|
|
@@ -2311,7 +2449,9 @@ var init_predicate = __esm({
|
|
|
2311
2449
|
const opToken = this.advance();
|
|
2312
2450
|
const jsOp = opToken.value;
|
|
2313
2451
|
const value = this.parseValue();
|
|
2314
|
-
if (value === PARSE_FAILED)
|
|
2452
|
+
if (value === PARSE_FAILED) {
|
|
2453
|
+
return null;
|
|
2454
|
+
}
|
|
2315
2455
|
if (value === null || value === void 0) {
|
|
2316
2456
|
if (jsOp === "===" || jsOp === "==") {
|
|
2317
2457
|
return { kind: "nullCheck", field, isNull: true };
|
|
@@ -2322,7 +2462,9 @@ var init_predicate = __esm({
|
|
|
2322
2462
|
return null;
|
|
2323
2463
|
}
|
|
2324
2464
|
const sqlOp = JS_TO_SQL_OP[jsOp];
|
|
2325
|
-
if (!sqlOp)
|
|
2465
|
+
if (!sqlOp) {
|
|
2466
|
+
return null;
|
|
2467
|
+
}
|
|
2326
2468
|
return { kind: "comparison", field, operator: sqlOp, value };
|
|
2327
2469
|
}
|
|
2328
2470
|
/**
|
|
@@ -2332,10 +2474,16 @@ var init_predicate = __esm({
|
|
|
2332
2474
|
parseFieldIncludes(field) {
|
|
2333
2475
|
this.advance();
|
|
2334
2476
|
this.advance();
|
|
2335
|
-
if (!this.eat("lparen"))
|
|
2477
|
+
if (!this.eat("lparen")) {
|
|
2478
|
+
return null;
|
|
2479
|
+
}
|
|
2336
2480
|
const value = this.parseValue();
|
|
2337
|
-
if (value === PARSE_FAILED || typeof value !== "string")
|
|
2338
|
-
|
|
2481
|
+
if (value === PARSE_FAILED || typeof value !== "string") {
|
|
2482
|
+
return null;
|
|
2483
|
+
}
|
|
2484
|
+
if (!this.eat("rparen")) {
|
|
2485
|
+
return null;
|
|
2486
|
+
}
|
|
2339
2487
|
const escaped = value.replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
2340
2488
|
return { kind: "like", field, pattern: `%${escaped}%` };
|
|
2341
2489
|
}
|
|
@@ -2348,22 +2496,38 @@ var init_predicate = __esm({
|
|
|
2348
2496
|
const values = [];
|
|
2349
2497
|
while (!this.match("rbracket")) {
|
|
2350
2498
|
if (values.length > 0) {
|
|
2351
|
-
if (!this.eat("comma"))
|
|
2499
|
+
if (!this.eat("comma")) {
|
|
2500
|
+
return null;
|
|
2501
|
+
}
|
|
2352
2502
|
}
|
|
2353
2503
|
const val = this.parseValue();
|
|
2354
|
-
if (val === PARSE_FAILED)
|
|
2504
|
+
if (val === PARSE_FAILED) {
|
|
2505
|
+
return null;
|
|
2506
|
+
}
|
|
2355
2507
|
values.push(val);
|
|
2356
2508
|
}
|
|
2357
2509
|
this.advance();
|
|
2358
|
-
if (!this.eat("dot"))
|
|
2359
|
-
|
|
2510
|
+
if (!this.eat("dot")) {
|
|
2511
|
+
return null;
|
|
2512
|
+
}
|
|
2513
|
+
if (!this.match("identifier", "includes")) {
|
|
2514
|
+
return null;
|
|
2515
|
+
}
|
|
2360
2516
|
this.advance();
|
|
2361
|
-
if (!this.eat("lparen"))
|
|
2362
|
-
|
|
2517
|
+
if (!this.eat("lparen")) {
|
|
2518
|
+
return null;
|
|
2519
|
+
}
|
|
2520
|
+
if (!this.match("identifier", this.paramName)) {
|
|
2521
|
+
return null;
|
|
2522
|
+
}
|
|
2363
2523
|
this.advance();
|
|
2364
2524
|
const field = this.parseFieldPath();
|
|
2365
|
-
if (!field)
|
|
2366
|
-
|
|
2525
|
+
if (!field) {
|
|
2526
|
+
return null;
|
|
2527
|
+
}
|
|
2528
|
+
if (!this.eat("rparen")) {
|
|
2529
|
+
return null;
|
|
2530
|
+
}
|
|
2367
2531
|
return { kind: "in", field, values };
|
|
2368
2532
|
}
|
|
2369
2533
|
/**
|
|
@@ -2374,7 +2538,9 @@ var init_predicate = __esm({
|
|
|
2374
2538
|
*/
|
|
2375
2539
|
parseNonParamExpression() {
|
|
2376
2540
|
const ident = this.peek().value;
|
|
2377
|
-
if (ident === "true" || ident === "false")
|
|
2541
|
+
if (ident === "true" || ident === "false") {
|
|
2542
|
+
return null;
|
|
2543
|
+
}
|
|
2378
2544
|
return null;
|
|
2379
2545
|
}
|
|
2380
2546
|
/**
|
|
@@ -2386,17 +2552,33 @@ var init_predicate = __esm({
|
|
|
2386
2552
|
*/
|
|
2387
2553
|
parseBindingsArrayIncludes() {
|
|
2388
2554
|
const bound = this.tryResolveBindingsValue();
|
|
2389
|
-
if (bound === PARSE_FAILED)
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
if (!
|
|
2555
|
+
if (bound === PARSE_FAILED) {
|
|
2556
|
+
return null;
|
|
2557
|
+
}
|
|
2558
|
+
if (!Array.isArray(bound)) {
|
|
2559
|
+
return null;
|
|
2560
|
+
}
|
|
2561
|
+
if (!this.eat("dot")) {
|
|
2562
|
+
return null;
|
|
2563
|
+
}
|
|
2564
|
+
if (!this.match("identifier", "includes")) {
|
|
2565
|
+
return null;
|
|
2566
|
+
}
|
|
2393
2567
|
this.advance();
|
|
2394
|
-
if (!this.eat("lparen"))
|
|
2395
|
-
|
|
2568
|
+
if (!this.eat("lparen")) {
|
|
2569
|
+
return null;
|
|
2570
|
+
}
|
|
2571
|
+
if (!this.match("identifier", this.paramName)) {
|
|
2572
|
+
return null;
|
|
2573
|
+
}
|
|
2396
2574
|
this.advance();
|
|
2397
2575
|
const field = this.parseFieldPath();
|
|
2398
|
-
if (!field)
|
|
2399
|
-
|
|
2576
|
+
if (!field) {
|
|
2577
|
+
return null;
|
|
2578
|
+
}
|
|
2579
|
+
if (!this.eat("rparen")) {
|
|
2580
|
+
return null;
|
|
2581
|
+
}
|
|
2400
2582
|
return { kind: "in", field, values: bound };
|
|
2401
2583
|
}
|
|
2402
2584
|
/**
|
|
@@ -2410,14 +2592,22 @@ var init_predicate = __esm({
|
|
|
2410
2592
|
* Restores `pos` on failure so callers can fall through cleanly.
|
|
2411
2593
|
*/
|
|
2412
2594
|
tryResolveBindingsValue() {
|
|
2413
|
-
if (!this.bindingsName)
|
|
2414
|
-
|
|
2415
|
-
|
|
2595
|
+
if (!this.bindingsName) {
|
|
2596
|
+
return PARSE_FAILED;
|
|
2597
|
+
}
|
|
2598
|
+
if (!this.match("identifier", this.bindingsName)) {
|
|
2599
|
+
return PARSE_FAILED;
|
|
2600
|
+
}
|
|
2601
|
+
if (this.bindingsValue == null) {
|
|
2602
|
+
return PARSE_FAILED;
|
|
2603
|
+
}
|
|
2416
2604
|
const startPos = this.pos;
|
|
2417
2605
|
this.advance();
|
|
2418
2606
|
const path = [];
|
|
2419
2607
|
while (this.match("dot") && this.tokens[this.pos + 1]?.type === "identifier") {
|
|
2420
|
-
if (this.tokens[this.pos + 2]?.type === "lparen")
|
|
2608
|
+
if (this.tokens[this.pos + 2]?.type === "lparen") {
|
|
2609
|
+
break;
|
|
2610
|
+
}
|
|
2421
2611
|
this.advance();
|
|
2422
2612
|
path.push(this.advance().value);
|
|
2423
2613
|
}
|
|
@@ -2447,7 +2637,9 @@ var init_predicate = __esm({
|
|
|
2447
2637
|
*/
|
|
2448
2638
|
parseValue() {
|
|
2449
2639
|
const t = this.peek();
|
|
2450
|
-
if (!t)
|
|
2640
|
+
if (!t) {
|
|
2641
|
+
return PARSE_FAILED;
|
|
2642
|
+
}
|
|
2451
2643
|
if (t.type === "string") {
|
|
2452
2644
|
this.advance();
|
|
2453
2645
|
return t.value;
|
|
@@ -2475,7 +2667,9 @@ var init_predicate = __esm({
|
|
|
2475
2667
|
}
|
|
2476
2668
|
if (this.bindingsName && t.value === this.bindingsName) {
|
|
2477
2669
|
const bound = this.tryResolveBindingsValue();
|
|
2478
|
-
if (bound !== PARSE_FAILED)
|
|
2670
|
+
if (bound !== PARSE_FAILED) {
|
|
2671
|
+
return bound;
|
|
2672
|
+
}
|
|
2479
2673
|
}
|
|
2480
2674
|
return this.resolveClosureVariable();
|
|
2481
2675
|
}
|
|
@@ -2644,11 +2838,21 @@ function aggregateValues(fn, values) {
|
|
|
2644
2838
|
}
|
|
2645
2839
|
}
|
|
2646
2840
|
function compareForOrder(a, b) {
|
|
2647
|
-
if (a == null && b == null)
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
if (a
|
|
2651
|
-
|
|
2841
|
+
if (a == null && b == null) {
|
|
2842
|
+
return 0;
|
|
2843
|
+
}
|
|
2844
|
+
if (a == null) {
|
|
2845
|
+
return -1;
|
|
2846
|
+
}
|
|
2847
|
+
if (b == null) {
|
|
2848
|
+
return 1;
|
|
2849
|
+
}
|
|
2850
|
+
if (a < b) {
|
|
2851
|
+
return -1;
|
|
2852
|
+
}
|
|
2853
|
+
if (a > b) {
|
|
2854
|
+
return 1;
|
|
2855
|
+
}
|
|
2652
2856
|
return 0;
|
|
2653
2857
|
}
|
|
2654
2858
|
function computeAggregateInJs(rows, spec) {
|
|
@@ -2656,8 +2860,11 @@ function computeAggregateInJs(rows, spec) {
|
|
|
2656
2860
|
for (const row of rows) {
|
|
2657
2861
|
const key = JSON.stringify(spec.by.map((col) => row[col]));
|
|
2658
2862
|
const group = groups.get(key);
|
|
2659
|
-
if (group)
|
|
2660
|
-
|
|
2863
|
+
if (group) {
|
|
2864
|
+
group.push(row);
|
|
2865
|
+
} else {
|
|
2866
|
+
groups.set(key, [row]);
|
|
2867
|
+
}
|
|
2661
2868
|
}
|
|
2662
2869
|
if (spec.by.length === 0 && groups.size === 0) {
|
|
2663
2870
|
groups.set("[]", []);
|
|
@@ -2678,7 +2885,9 @@ function computeAggregateInJs(rows, spec) {
|
|
|
2678
2885
|
if (spec.orderBy) {
|
|
2679
2886
|
const key = spec.orderBy;
|
|
2680
2887
|
out.sort((a, b) => compareForOrder(a[key], b[key]));
|
|
2681
|
-
if (spec.desc)
|
|
2888
|
+
if (spec.desc) {
|
|
2889
|
+
out.reverse();
|
|
2890
|
+
}
|
|
2682
2891
|
}
|
|
2683
2892
|
if (spec.limit != null) {
|
|
2684
2893
|
out = out.slice(0, spec.limit);
|
|
@@ -2833,7 +3042,11 @@ var init_query = __esm({
|
|
|
2833
3042
|
*/
|
|
2834
3043
|
sum(accessor) {
|
|
2835
3044
|
return this._clone({
|
|
2836
|
-
aggregate: {
|
|
3045
|
+
aggregate: {
|
|
3046
|
+
kind: "scalar",
|
|
3047
|
+
fn: "sum",
|
|
3048
|
+
accessor
|
|
3049
|
+
},
|
|
2837
3050
|
postProcess: (rows) => rows.reduce((total, row) => {
|
|
2838
3051
|
const value = accessor(row);
|
|
2839
3052
|
return value == null ? total : total + value;
|
|
@@ -2847,7 +3060,11 @@ var init_query = __esm({
|
|
|
2847
3060
|
*/
|
|
2848
3061
|
avg(accessor) {
|
|
2849
3062
|
return this._clone({
|
|
2850
|
-
aggregate: {
|
|
3063
|
+
aggregate: {
|
|
3064
|
+
kind: "scalar",
|
|
3065
|
+
fn: "avg",
|
|
3066
|
+
accessor
|
|
3067
|
+
},
|
|
2851
3068
|
postProcess: (rows) => {
|
|
2852
3069
|
const values = rows.map((row) => accessor(row)).filter((v) => v != null);
|
|
2853
3070
|
return values.length === 0 ? null : values.reduce((s, v) => s + v, 0) / values.length;
|
|
@@ -2870,10 +3087,7 @@ var init_query = __esm({
|
|
|
2870
3087
|
);
|
|
2871
3088
|
return this._clone({
|
|
2872
3089
|
aggregate: { kind: "grouped", spec: normalized },
|
|
2873
|
-
postProcess: (rows) => computeAggregateInJs(
|
|
2874
|
-
rows,
|
|
2875
|
-
normalized
|
|
2876
|
-
)
|
|
3090
|
+
postProcess: (rows) => computeAggregateInJs(rows, normalized)
|
|
2877
3091
|
});
|
|
2878
3092
|
}
|
|
2879
3093
|
some() {
|
|
@@ -2895,7 +3109,9 @@ var init_query = __esm({
|
|
|
2895
3109
|
const row = results[0]?.rows[0];
|
|
2896
3110
|
return row?.result === 1;
|
|
2897
3111
|
}
|
|
2898
|
-
if (this._predicates.length === 0)
|
|
3112
|
+
if (this._predicates.length === 0) {
|
|
3113
|
+
return true;
|
|
3114
|
+
}
|
|
2899
3115
|
const allRows = await this._fetchAllRows();
|
|
2900
3116
|
return allRows.every(
|
|
2901
3117
|
(row) => this._predicates.every((p) => p.fn(row, p.bindings))
|
|
@@ -2914,8 +3130,11 @@ var init_query = __esm({
|
|
|
2914
3130
|
for (const row of rows) {
|
|
2915
3131
|
const key = accessor(row);
|
|
2916
3132
|
const group = map.get(key);
|
|
2917
|
-
if (group)
|
|
2918
|
-
|
|
3133
|
+
if (group) {
|
|
3134
|
+
group.push(row);
|
|
3135
|
+
} else {
|
|
3136
|
+
map.set(key, [row]);
|
|
3137
|
+
}
|
|
2919
3138
|
}
|
|
2920
3139
|
return map;
|
|
2921
3140
|
}
|
|
@@ -2941,14 +3160,26 @@ var init_query = __esm({
|
|
|
2941
3160
|
limit: this._limit,
|
|
2942
3161
|
offset: this._offset
|
|
2943
3162
|
});
|
|
2944
|
-
return {
|
|
3163
|
+
return {
|
|
3164
|
+
type: "query",
|
|
3165
|
+
query,
|
|
3166
|
+
fallbackQuery: null,
|
|
3167
|
+
config: this._config,
|
|
3168
|
+
postProcess: this._postProcess
|
|
3169
|
+
};
|
|
2945
3170
|
}
|
|
2946
3171
|
const compiled = this._compilePredicates();
|
|
2947
3172
|
const sortField = this._sortAccessor ? extractFieldName(this._sortAccessor) : void 0;
|
|
2948
3173
|
if (compiled.allSql) {
|
|
2949
3174
|
const agg = this._compileAggregateSql(compiled.sqlWhere);
|
|
2950
3175
|
if (agg) {
|
|
2951
|
-
return {
|
|
3176
|
+
return {
|
|
3177
|
+
type: "query",
|
|
3178
|
+
query: agg.query,
|
|
3179
|
+
fallbackQuery: null,
|
|
3180
|
+
config: this._config,
|
|
3181
|
+
processRaw: agg.processRaw
|
|
3182
|
+
};
|
|
2952
3183
|
}
|
|
2953
3184
|
const query = buildSelect(this._config.tableName, {
|
|
2954
3185
|
where: compiled.sqlWhere || void 0,
|
|
@@ -2957,7 +3188,13 @@ var init_query = __esm({
|
|
|
2957
3188
|
limit: this._limit,
|
|
2958
3189
|
offset: this._offset
|
|
2959
3190
|
});
|
|
2960
|
-
return {
|
|
3191
|
+
return {
|
|
3192
|
+
type: "query",
|
|
3193
|
+
query,
|
|
3194
|
+
fallbackQuery: null,
|
|
3195
|
+
config: this._config,
|
|
3196
|
+
postProcess: this._postProcess
|
|
3197
|
+
};
|
|
2961
3198
|
}
|
|
2962
3199
|
const fallbackQuery = buildSelect(this._config.tableName);
|
|
2963
3200
|
return {
|
|
@@ -2993,15 +3230,21 @@ var init_query = __esm({
|
|
|
2993
3230
|
if (compiled.query) {
|
|
2994
3231
|
return compiled.postProcess ? compiled.postProcess(rows) : rows;
|
|
2995
3232
|
}
|
|
2996
|
-
let filtered = compiled.predicates ? rows.filter(
|
|
3233
|
+
let filtered = compiled.predicates ? rows.filter(
|
|
3234
|
+
(row) => compiled.predicates.every((p) => p.fn(row, p.bindings))
|
|
3235
|
+
) : rows;
|
|
2997
3236
|
if (compiled.sortAccessor) {
|
|
2998
3237
|
const accessor = compiled.sortAccessor;
|
|
2999
3238
|
const reversed = compiled.reversed ?? false;
|
|
3000
3239
|
filtered.sort((a, b) => {
|
|
3001
3240
|
const aVal = accessor(a);
|
|
3002
3241
|
const bVal = accessor(b);
|
|
3003
|
-
if (aVal < bVal)
|
|
3004
|
-
|
|
3242
|
+
if (aVal < bVal) {
|
|
3243
|
+
return reversed ? 1 : -1;
|
|
3244
|
+
}
|
|
3245
|
+
if (aVal > bVal) {
|
|
3246
|
+
return reversed ? -1 : 1;
|
|
3247
|
+
}
|
|
3005
3248
|
return 0;
|
|
3006
3249
|
});
|
|
3007
3250
|
}
|
|
@@ -3138,8 +3381,12 @@ var init_query = __esm({
|
|
|
3138
3381
|
rows.sort((a, b) => {
|
|
3139
3382
|
const aVal = accessor(a);
|
|
3140
3383
|
const bVal = accessor(b);
|
|
3141
|
-
if (aVal < bVal)
|
|
3142
|
-
|
|
3384
|
+
if (aVal < bVal) {
|
|
3385
|
+
return this._reversed ? 1 : -1;
|
|
3386
|
+
}
|
|
3387
|
+
if (aVal > bVal) {
|
|
3388
|
+
return this._reversed ? -1 : 1;
|
|
3389
|
+
}
|
|
3143
3390
|
return 0;
|
|
3144
3391
|
});
|
|
3145
3392
|
}
|
|
@@ -3154,7 +3401,9 @@ var init_query = __esm({
|
|
|
3154
3401
|
if (this._predicates.length === 0) {
|
|
3155
3402
|
return { allSql: true, sqlWhere: "", compiled: [] };
|
|
3156
3403
|
}
|
|
3157
|
-
const compiled = this._predicates.map(
|
|
3404
|
+
const compiled = this._predicates.map(
|
|
3405
|
+
(p) => compilePredicate(p.fn, p.bindings)
|
|
3406
|
+
);
|
|
3158
3407
|
const allSql = compiled.every((c) => c.type === "sql");
|
|
3159
3408
|
let sqlWhere = "";
|
|
3160
3409
|
if (allSql) {
|
|
@@ -3308,7 +3557,9 @@ var init_table = __esm({
|
|
|
3308
3557
|
return this.filter(predicate, bindings).first();
|
|
3309
3558
|
}
|
|
3310
3559
|
count(predicate, bindings) {
|
|
3311
|
-
if (predicate)
|
|
3560
|
+
if (predicate) {
|
|
3561
|
+
return this.filter(predicate, bindings).count();
|
|
3562
|
+
}
|
|
3312
3563
|
return this.toArray().count();
|
|
3313
3564
|
}
|
|
3314
3565
|
some(predicate, bindings) {
|
|
@@ -3319,7 +3570,12 @@ var init_table = __esm({
|
|
|
3319
3570
|
}
|
|
3320
3571
|
/** True if the table has zero rows. */
|
|
3321
3572
|
async isEmpty() {
|
|
3322
|
-
const query = buildExists(
|
|
3573
|
+
const query = buildExists(
|
|
3574
|
+
this._config.tableName,
|
|
3575
|
+
void 0,
|
|
3576
|
+
void 0,
|
|
3577
|
+
true
|
|
3578
|
+
);
|
|
3323
3579
|
const results = await this._config.executeBatch([query]);
|
|
3324
3580
|
const row = results[0]?.rows[0];
|
|
3325
3581
|
return row?.result === 1;
|
|
@@ -3368,7 +3624,10 @@ var init_table = __esm({
|
|
|
3368
3624
|
return new Query(this._config);
|
|
3369
3625
|
}
|
|
3370
3626
|
filter(predicate, bindings) {
|
|
3371
|
-
return new Query(this._config).filter(
|
|
3627
|
+
return new Query(this._config).filter(
|
|
3628
|
+
predicate,
|
|
3629
|
+
bindings
|
|
3630
|
+
);
|
|
3372
3631
|
}
|
|
3373
3632
|
/** Sort rows by a field. Returns a chainable Query. */
|
|
3374
3633
|
sortBy(accessor) {
|
|
@@ -3436,25 +3695,29 @@ var init_table = __esm({
|
|
|
3436
3695
|
results[0].rows[0],
|
|
3437
3696
|
this._config.columns
|
|
3438
3697
|
);
|
|
3439
|
-
this._syncRolesIfNeeded(
|
|
3440
|
-
[data],
|
|
3441
|
-
result,
|
|
3442
|
-
false
|
|
3443
|
-
);
|
|
3698
|
+
this._syncRolesIfNeeded([data], result, false);
|
|
3444
3699
|
return result;
|
|
3445
3700
|
});
|
|
3446
3701
|
}
|
|
3447
3702
|
remove(id) {
|
|
3448
3703
|
const query = buildDelete(this._config.tableName, `id = ?`, [id]);
|
|
3449
|
-
return new Mutation(
|
|
3450
|
-
|
|
3451
|
-
|
|
3704
|
+
return new Mutation(
|
|
3705
|
+
this._config,
|
|
3706
|
+
[query],
|
|
3707
|
+
(results) => ({
|
|
3708
|
+
deleted: results[0].changes > 0
|
|
3709
|
+
})
|
|
3710
|
+
);
|
|
3452
3711
|
}
|
|
3453
3712
|
removeAll(predicate, bindings) {
|
|
3454
3713
|
const compiled = compilePredicate(predicate, bindings);
|
|
3455
3714
|
if (compiled.type === "sql") {
|
|
3456
3715
|
const query = buildDelete(this._config.tableName, compiled.where);
|
|
3457
|
-
return new Mutation(
|
|
3716
|
+
return new Mutation(
|
|
3717
|
+
this._config,
|
|
3718
|
+
[query],
|
|
3719
|
+
(results) => results[0].changes
|
|
3720
|
+
);
|
|
3458
3721
|
}
|
|
3459
3722
|
return Mutation.fromExecutor(this._config, async () => {
|
|
3460
3723
|
console.warn(
|
|
@@ -3469,8 +3732,12 @@ var init_table = __esm({
|
|
|
3469
3732
|
)
|
|
3470
3733
|
);
|
|
3471
3734
|
const matching = allRows.filter((row) => predicate(row, bindings));
|
|
3472
|
-
if (matching.length === 0)
|
|
3473
|
-
|
|
3735
|
+
if (matching.length === 0) {
|
|
3736
|
+
return 0;
|
|
3737
|
+
}
|
|
3738
|
+
const deleteQueries = matching.filter((row) => row.id).map(
|
|
3739
|
+
(row) => buildDelete(this._config.tableName, `id = ?`, [row.id])
|
|
3740
|
+
);
|
|
3474
3741
|
if (deleteQueries.length > 0) {
|
|
3475
3742
|
await this._config.executeBatch(deleteQueries);
|
|
3476
3743
|
}
|
|
@@ -3479,7 +3746,11 @@ var init_table = __esm({
|
|
|
3479
3746
|
}
|
|
3480
3747
|
clear() {
|
|
3481
3748
|
const query = buildDelete(this._config.tableName);
|
|
3482
|
-
return new Mutation(
|
|
3749
|
+
return new Mutation(
|
|
3750
|
+
this._config,
|
|
3751
|
+
[query],
|
|
3752
|
+
(results) => results[0].changes
|
|
3753
|
+
);
|
|
3483
3754
|
}
|
|
3484
3755
|
/**
|
|
3485
3756
|
* Insert a row, or update it if a row with the same unique key already
|
|
@@ -3534,7 +3805,9 @@ var init_table = __esm({
|
|
|
3534
3805
|
/** @internal Throw if data includes a platform-managed read-only column. */
|
|
3535
3806
|
_checkManagedColumns(data) {
|
|
3536
3807
|
const mc = this._config.managedColumns;
|
|
3537
|
-
if (!mc)
|
|
3808
|
+
if (!mc) {
|
|
3809
|
+
return;
|
|
3810
|
+
}
|
|
3538
3811
|
const keys = Object.keys(data);
|
|
3539
3812
|
for (const key of keys) {
|
|
3540
3813
|
if (mc.email && key === mc.email || mc.phone && key === mc.phone || mc.apiKey && key === mc.apiKey) {
|
|
@@ -3555,8 +3828,12 @@ var init_table = __esm({
|
|
|
3555
3828
|
_syncRolesIfNeeded(inputItems, result, isArray) {
|
|
3556
3829
|
const rolesCol = this._config.managedColumns?.roles;
|
|
3557
3830
|
const syncRoles = this._config.syncRoles;
|
|
3558
|
-
if (!rolesCol || !syncRoles)
|
|
3559
|
-
|
|
3831
|
+
if (!rolesCol || !syncRoles) {
|
|
3832
|
+
return;
|
|
3833
|
+
}
|
|
3834
|
+
if (!inputItems.some((item) => rolesCol in item)) {
|
|
3835
|
+
return;
|
|
3836
|
+
}
|
|
3560
3837
|
if (isArray) {
|
|
3561
3838
|
for (const row of result) {
|
|
3562
3839
|
if (row?.id) {
|
|
@@ -3715,7 +3992,9 @@ function createDb(databases, executeBatch, authConfig, syncRoles) {
|
|
|
3715
3992
|
for (let i = 0; i < compiled.length; i++) {
|
|
3716
3993
|
const c = compiled[i];
|
|
3717
3994
|
const dbId = c.config.databaseId;
|
|
3718
|
-
if (!groups.has(dbId))
|
|
3995
|
+
if (!groups.has(dbId)) {
|
|
3996
|
+
groups.set(dbId, []);
|
|
3997
|
+
}
|
|
3719
3998
|
if (c.type === "query") {
|
|
3720
3999
|
const sqlQuery = c.query ?? c.fallbackQuery;
|
|
3721
4000
|
groups.get(dbId).push({ opIndex: i, sqlQueries: [sqlQuery] });
|
|
@@ -3788,9 +4067,7 @@ function resolveDatabase(databases, hint) {
|
|
|
3788
4067
|
);
|
|
3789
4068
|
}
|
|
3790
4069
|
if (hint) {
|
|
3791
|
-
const targetDb = databases.find(
|
|
3792
|
-
(db) => db.id === hint || db.name === hint
|
|
3793
|
-
);
|
|
4070
|
+
const targetDb = databases.find((db) => db.id === hint || db.name === hint);
|
|
3794
4071
|
if (!targetDb) {
|
|
3795
4072
|
const available = databases.map((db) => db.name || db.id).join(", ");
|
|
3796
4073
|
throw new MindStudioError(
|
|
@@ -3947,7 +4224,10 @@ var init_store = __esm({
|
|
|
3947
4224
|
);
|
|
3948
4225
|
form.append(
|
|
3949
4226
|
"file",
|
|
3950
|
-
new Blob(
|
|
4227
|
+
new Blob(
|
|
4228
|
+
[view],
|
|
4229
|
+
options.contentType ? { type: options.contentType } : void 0
|
|
4230
|
+
)
|
|
3951
4231
|
);
|
|
3952
4232
|
const upload = await fetch(res.uploadUrl, {
|
|
3953
4233
|
method: "POST",
|
|
@@ -4644,9 +4924,13 @@ var init_events = __esm({
|
|
|
4644
4924
|
|
|
4645
4925
|
// src/task/schema.ts
|
|
4646
4926
|
function describe(value) {
|
|
4647
|
-
if (value === void 0)
|
|
4927
|
+
if (value === void 0) {
|
|
4928
|
+
return "undefined";
|
|
4929
|
+
}
|
|
4648
4930
|
const json = JSON.stringify(value);
|
|
4649
|
-
if (json === void 0)
|
|
4931
|
+
if (json === void 0) {
|
|
4932
|
+
return String(value);
|
|
4933
|
+
}
|
|
4650
4934
|
return json.length > 60 ? `${json.slice(0, 57)}...` : json;
|
|
4651
4935
|
}
|
|
4652
4936
|
function matchesTypeName(value, name) {
|
|
@@ -4745,7 +5029,9 @@ function assertSupportedSchema(schema) {
|
|
|
4745
5029
|
}
|
|
4746
5030
|
function assertSupportedNode(schema, path) {
|
|
4747
5031
|
for (const key of Object.keys(schema)) {
|
|
4748
|
-
if (SUPPORTED_KEYWORDS.has(key))
|
|
5032
|
+
if (SUPPORTED_KEYWORDS.has(key)) {
|
|
5033
|
+
continue;
|
|
5034
|
+
}
|
|
4749
5035
|
const hint = key === "nullable" ? ' Use a type array instead: type: ["string", "null"].' : key === "oneOf" || key === "anyOf" || key === "allOf" ? " Model alternatives with an enum, a type array, or a discriminating property instead." : "";
|
|
4750
5036
|
throw new MindStudioError(
|
|
4751
5037
|
`[task] Unsupported JSON Schema keyword "${key}" at ${path} in outputSchema. Supported: type, properties, required, additionalProperties, items, enum, const.${hint}`,
|
|
@@ -4763,17 +5049,18 @@ function assertSupportedNode(schema, path) {
|
|
|
4763
5049
|
}
|
|
4764
5050
|
}
|
|
4765
5051
|
function buildExampleFromSchema(schema) {
|
|
4766
|
-
if (schema.const !== void 0)
|
|
4767
|
-
|
|
5052
|
+
if (schema.const !== void 0) {
|
|
5053
|
+
return schema.const;
|
|
5054
|
+
}
|
|
5055
|
+
if (schema.enum !== void 0 && schema.enum.length > 0) {
|
|
4768
5056
|
return schema.enum[0];
|
|
5057
|
+
}
|
|
4769
5058
|
const names = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
4770
5059
|
const name = names.find((n) => n !== "null") ?? names[0];
|
|
4771
5060
|
switch (name) {
|
|
4772
5061
|
case "object": {
|
|
4773
5062
|
const example = {};
|
|
4774
|
-
for (const [key, propSchema] of Object.entries(
|
|
4775
|
-
schema.properties ?? {}
|
|
4776
|
-
)) {
|
|
5063
|
+
for (const [key, propSchema] of Object.entries(schema.properties ?? {})) {
|
|
4777
5064
|
example[key] = buildExampleFromSchema(propSchema);
|
|
4778
5065
|
}
|
|
4779
5066
|
return example;
|
|
@@ -4872,7 +5159,9 @@ function isDevMode() {
|
|
|
4872
5159
|
return !!(process.env.CALLBACK_TOKEN || getRequestContext()?.callbackToken);
|
|
4873
5160
|
}
|
|
4874
5161
|
function logTaskResult(result) {
|
|
4875
|
-
if (!isDevMode())
|
|
5162
|
+
if (!isDevMode()) {
|
|
5163
|
+
return;
|
|
5164
|
+
}
|
|
4876
5165
|
const toolSummary = result.toolCalls.map((tc) => `${tc.name} (${tc.durationMs}ms) ${tc.success ? "\u2713" : "\u2717"}`).join(", ");
|
|
4877
5166
|
console.log(
|
|
4878
5167
|
`[task] ${result.turns} turn${result.turns === 1 ? "" : "s"}` + (toolSummary ? `: ${toolSummary}` : "") + ` | ${result.parsedSuccessfully ? "output OK" : "\u26A0 output not valid JSON"} | cost: ${result.usage.totalBillingCost}`
|
|
@@ -4894,8 +5183,9 @@ async function runTaskPoll(httpConfig, body) {
|
|
|
4894
5183
|
const res = await fetch(pollUrl, {
|
|
4895
5184
|
headers: { "User-Agent": "@mindstudio-ai/agent" }
|
|
4896
5185
|
});
|
|
4897
|
-
if (res.status === 502 || res.status === 503 || res.status === 504)
|
|
5186
|
+
if (res.status === 502 || res.status === 503 || res.status === 504) {
|
|
4898
5187
|
continue;
|
|
5188
|
+
}
|
|
4899
5189
|
if (res.status === 404) {
|
|
4900
5190
|
throw new MindStudioError(
|
|
4901
5191
|
"Task poll token not found or expired.",
|
|
@@ -4968,11 +5258,17 @@ async function runTaskStream(httpConfig, body, onEvent) {
|
|
|
4968
5258
|
const errBody = JSON.parse(text);
|
|
4969
5259
|
details = errBody;
|
|
4970
5260
|
const errMsg = (typeof errBody.error === "string" ? errBody.error : void 0) ?? (typeof errBody.message === "string" ? errBody.message : void 0);
|
|
4971
|
-
if (errMsg)
|
|
4972
|
-
|
|
5261
|
+
if (errMsg) {
|
|
5262
|
+
message = errMsg;
|
|
5263
|
+
}
|
|
5264
|
+
if (errBody.code) {
|
|
5265
|
+
code = errBody.code;
|
|
5266
|
+
}
|
|
4973
5267
|
} catch {
|
|
4974
5268
|
const stripped = text.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
4975
|
-
if (stripped)
|
|
5269
|
+
if (stripped) {
|
|
5270
|
+
message = stripped.slice(0, 200);
|
|
5271
|
+
}
|
|
4976
5272
|
}
|
|
4977
5273
|
} catch {
|
|
4978
5274
|
}
|
|
@@ -4984,12 +5280,16 @@ async function runTaskStream(httpConfig, body, onEvent) {
|
|
|
4984
5280
|
let result = null;
|
|
4985
5281
|
while (true) {
|
|
4986
5282
|
const { done, value } = await reader.read();
|
|
4987
|
-
if (done)
|
|
5283
|
+
if (done) {
|
|
5284
|
+
break;
|
|
5285
|
+
}
|
|
4988
5286
|
buffer += decoder.decode(value, { stream: true });
|
|
4989
5287
|
const lines = buffer.split("\n");
|
|
4990
5288
|
buffer = lines.pop() ?? "";
|
|
4991
5289
|
for (const line of lines) {
|
|
4992
|
-
if (!line.startsWith("data: "))
|
|
5290
|
+
if (!line.startsWith("data: ")) {
|
|
5291
|
+
continue;
|
|
5292
|
+
}
|
|
4993
5293
|
try {
|
|
4994
5294
|
const event = JSON.parse(line.slice(6));
|
|
4995
5295
|
onEvent(event);
|
|
@@ -5016,7 +5316,9 @@ async function runTaskStream(httpConfig, body, onEvent) {
|
|
|
5016
5316
|
};
|
|
5017
5317
|
}
|
|
5018
5318
|
} catch (err) {
|
|
5019
|
-
if (err instanceof MindStudioError)
|
|
5319
|
+
if (err instanceof MindStudioError) {
|
|
5320
|
+
throw err;
|
|
5321
|
+
}
|
|
5020
5322
|
}
|
|
5021
5323
|
}
|
|
5022
5324
|
}
|
|
@@ -5047,7 +5349,9 @@ async function runTaskStream(httpConfig, body, onEvent) {
|
|
|
5047
5349
|
};
|
|
5048
5350
|
}
|
|
5049
5351
|
} catch (err) {
|
|
5050
|
-
if (err instanceof MindStudioError)
|
|
5352
|
+
if (err instanceof MindStudioError) {
|
|
5353
|
+
throw err;
|
|
5354
|
+
}
|
|
5051
5355
|
}
|
|
5052
5356
|
}
|
|
5053
5357
|
if (!result) {
|
|
@@ -5125,8 +5429,12 @@ async function attemptTurn(httpConfig, body) {
|
|
|
5125
5429
|
try {
|
|
5126
5430
|
const errBody = await res.json();
|
|
5127
5431
|
const errMsg = (typeof errBody.errorMessage === "string" ? errBody.errorMessage : void 0) ?? (typeof errBody.errorString === "string" ? errBody.errorString : void 0) ?? (typeof errBody.error === "string" ? errBody.error : void 0);
|
|
5128
|
-
if (errMsg)
|
|
5129
|
-
|
|
5432
|
+
if (errMsg) {
|
|
5433
|
+
message = errMsg;
|
|
5434
|
+
}
|
|
5435
|
+
if (typeof errBody.errorString === "string") {
|
|
5436
|
+
code = errBody.errorString;
|
|
5437
|
+
}
|
|
5130
5438
|
} catch {
|
|
5131
5439
|
}
|
|
5132
5440
|
const retryable = res.status >= 500 || res.status === 429;
|
|
@@ -5254,7 +5562,9 @@ async function runTaskLocal(deps, options) {
|
|
|
5254
5562
|
const { httpConfig } = deps;
|
|
5255
5563
|
const onEvent = options.onEvent;
|
|
5256
5564
|
const outputSchema = options.outputSchema;
|
|
5257
|
-
if (outputSchema)
|
|
5565
|
+
if (outputSchema) {
|
|
5566
|
+
assertSupportedSchema(outputSchema);
|
|
5567
|
+
}
|
|
5258
5568
|
let system;
|
|
5259
5569
|
if (outputSchema) {
|
|
5260
5570
|
system = `${options.prompt}
|
|
@@ -5282,12 +5592,16 @@ ${structuredOutputExample}
|
|
|
5282
5592
|
for (const t of wireTools) {
|
|
5283
5593
|
if ("appMethod" in t) {
|
|
5284
5594
|
toolKinds.set(t.appMethod, "method");
|
|
5285
|
-
if (t.defaults)
|
|
5595
|
+
if (t.defaults) {
|
|
5596
|
+
toolDefaults.set(t.appMethod, t.defaults);
|
|
5597
|
+
}
|
|
5286
5598
|
} else if ("name" in t) {
|
|
5287
5599
|
toolKinds.set(t.name, "function");
|
|
5288
5600
|
} else {
|
|
5289
5601
|
toolKinds.set(t.stepType, "step");
|
|
5290
|
-
if (t.defaults)
|
|
5602
|
+
if (t.defaults) {
|
|
5603
|
+
toolDefaults.set(t.stepType, t.defaults);
|
|
5604
|
+
}
|
|
5291
5605
|
}
|
|
5292
5606
|
}
|
|
5293
5607
|
const maxTurns = Math.min(
|
|
@@ -5420,7 +5734,11 @@ ${structuredOutputExample}
|
|
|
5420
5734
|
const output3 = await functionTools.get(toolCall.name)(
|
|
5421
5735
|
mergedInput
|
|
5422
5736
|
);
|
|
5423
|
-
result = {
|
|
5737
|
+
result = {
|
|
5738
|
+
output: output3 ?? null,
|
|
5739
|
+
billingCost: 0,
|
|
5740
|
+
isError: false
|
|
5741
|
+
};
|
|
5424
5742
|
} catch (err) {
|
|
5425
5743
|
result = {
|
|
5426
5744
|
output: {
|
|
@@ -5468,7 +5786,9 @@ ${structuredOutputExample}
|
|
|
5468
5786
|
let output2;
|
|
5469
5787
|
let parseOk = true;
|
|
5470
5788
|
try {
|
|
5471
|
-
output2 = JSON.parse(
|
|
5789
|
+
output2 = JSON.parse(
|
|
5790
|
+
outputSchema ? stripCodeFences(turn.text) : turn.text
|
|
5791
|
+
);
|
|
5472
5792
|
} catch {
|
|
5473
5793
|
parseOk = false;
|
|
5474
5794
|
}
|
|
@@ -6064,14 +6384,21 @@ function resolveStepType2(name) {
|
|
|
6064
6384
|
}
|
|
6065
6385
|
function resolveToken(provided, config) {
|
|
6066
6386
|
const rctx = getRequestContext();
|
|
6067
|
-
if (rctx?.callbackToken)
|
|
6387
|
+
if (rctx?.callbackToken) {
|
|
6068
6388
|
return { token: rctx.callbackToken, authType: "internal" };
|
|
6069
|
-
|
|
6389
|
+
}
|
|
6390
|
+
if (process.env.CALLBACK_TOKEN) {
|
|
6070
6391
|
return { token: process.env.CALLBACK_TOKEN, authType: "internal" };
|
|
6071
|
-
|
|
6072
|
-
if (
|
|
6392
|
+
}
|
|
6393
|
+
if (provided) {
|
|
6394
|
+
return { token: provided, authType: "apiKey" };
|
|
6395
|
+
}
|
|
6396
|
+
if (process.env.MINDSTUDIO_API_KEY) {
|
|
6073
6397
|
return { token: process.env.MINDSTUDIO_API_KEY, authType: "apiKey" };
|
|
6074
|
-
|
|
6398
|
+
}
|
|
6399
|
+
if (config?.apiKey) {
|
|
6400
|
+
return { token: config.apiKey, authType: "apiKey" };
|
|
6401
|
+
}
|
|
6075
6402
|
throw new MindStudioError(
|
|
6076
6403
|
"No API key provided. Run `mindstudio login`, pass `apiKey` to the constructor, or set the MINDSTUDIO_API_KEY environment variable.",
|
|
6077
6404
|
"missing_api_key",
|
|
@@ -6153,7 +6480,9 @@ var init_client = __esm({
|
|
|
6153
6480
|
*/
|
|
6154
6481
|
get _token() {
|
|
6155
6482
|
const rctx = getRequestContext();
|
|
6156
|
-
if (rctx?.callbackToken)
|
|
6483
|
+
if (rctx?.callbackToken) {
|
|
6484
|
+
return rctx.callbackToken;
|
|
6485
|
+
}
|
|
6157
6486
|
if (this._authType === "internal" && process.env.CALLBACK_TOKEN) {
|
|
6158
6487
|
return process.env.CALLBACK_TOKEN;
|
|
6159
6488
|
}
|
|
@@ -6258,8 +6587,9 @@ var init_client = __esm({
|
|
|
6258
6587
|
const res = await fetch(pollUrl, {
|
|
6259
6588
|
headers: { "User-Agent": "@mindstudio-ai/agent" }
|
|
6260
6589
|
});
|
|
6261
|
-
if (res.status === 502 || res.status === 503 || res.status === 504)
|
|
6590
|
+
if (res.status === 502 || res.status === 503 || res.status === 504) {
|
|
6262
6591
|
continue;
|
|
6592
|
+
}
|
|
6263
6593
|
if (res.status === 404) {
|
|
6264
6594
|
throw new MindStudioError(
|
|
6265
6595
|
`[${stepType}] Execution token expired.`,
|
|
@@ -6277,7 +6607,9 @@ var init_client = __esm({
|
|
|
6277
6607
|
);
|
|
6278
6608
|
}
|
|
6279
6609
|
const poll = await res.json();
|
|
6280
|
-
if (poll.status === "pending")
|
|
6610
|
+
if (poll.status === "pending") {
|
|
6611
|
+
continue;
|
|
6612
|
+
}
|
|
6281
6613
|
if (poll.status === "error") {
|
|
6282
6614
|
throw new MindStudioError(
|
|
6283
6615
|
`[${stepType}] ${poll.error ?? "Step execution failed."}`,
|
|
@@ -6358,16 +6690,21 @@ var init_client = __esm({
|
|
|
6358
6690
|
const body2 = JSON.parse(text);
|
|
6359
6691
|
details = body2;
|
|
6360
6692
|
const errMsg = (typeof body2.error === "string" ? body2.error : void 0) ?? (typeof body2.message === "string" ? body2.message : void 0) ?? (typeof body2.details === "string" ? body2.details : void 0);
|
|
6361
|
-
if (errMsg)
|
|
6362
|
-
|
|
6693
|
+
if (errMsg) {
|
|
6694
|
+
message = errMsg;
|
|
6695
|
+
} else if (body2.error || body2.message || body2.details) {
|
|
6363
6696
|
message = JSON.stringify(
|
|
6364
6697
|
body2.error ?? body2.message ?? body2.details
|
|
6365
6698
|
);
|
|
6366
6699
|
}
|
|
6367
|
-
if (body2.code)
|
|
6700
|
+
if (body2.code) {
|
|
6701
|
+
code = body2.code;
|
|
6702
|
+
}
|
|
6368
6703
|
} catch {
|
|
6369
6704
|
const stripped = text.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
6370
|
-
if (stripped)
|
|
6705
|
+
if (stripped) {
|
|
6706
|
+
message = stripped.slice(0, 200);
|
|
6707
|
+
}
|
|
6371
6708
|
}
|
|
6372
6709
|
} catch {
|
|
6373
6710
|
}
|
|
@@ -6386,12 +6723,16 @@ var init_client = __esm({
|
|
|
6386
6723
|
let doneEvent = null;
|
|
6387
6724
|
while (true) {
|
|
6388
6725
|
const { done, value } = await reader.read();
|
|
6389
|
-
if (done)
|
|
6726
|
+
if (done) {
|
|
6727
|
+
break;
|
|
6728
|
+
}
|
|
6390
6729
|
buffer += decoder.decode(value, { stream: true });
|
|
6391
6730
|
const lines = buffer.split("\n");
|
|
6392
6731
|
buffer = lines.pop() ?? "";
|
|
6393
6732
|
for (const line of lines) {
|
|
6394
|
-
if (!line.startsWith("data: "))
|
|
6733
|
+
if (!line.startsWith("data: ")) {
|
|
6734
|
+
continue;
|
|
6735
|
+
}
|
|
6395
6736
|
try {
|
|
6396
6737
|
const event = JSON.parse(line.slice(6));
|
|
6397
6738
|
if (event.type === "log") {
|
|
@@ -6415,7 +6756,9 @@ var init_client = __esm({
|
|
|
6415
6756
|
);
|
|
6416
6757
|
}
|
|
6417
6758
|
} catch (err) {
|
|
6418
|
-
if (err instanceof MindStudioError)
|
|
6759
|
+
if (err instanceof MindStudioError) {
|
|
6760
|
+
throw err;
|
|
6761
|
+
}
|
|
6419
6762
|
}
|
|
6420
6763
|
}
|
|
6421
6764
|
}
|
|
@@ -6443,7 +6786,9 @@ var init_client = __esm({
|
|
|
6443
6786
|
});
|
|
6444
6787
|
}
|
|
6445
6788
|
} catch (err) {
|
|
6446
|
-
if (err instanceof MindStudioError)
|
|
6789
|
+
if (err instanceof MindStudioError) {
|
|
6790
|
+
throw err;
|
|
6791
|
+
}
|
|
6447
6792
|
}
|
|
6448
6793
|
}
|
|
6449
6794
|
if (!doneEvent) {
|
|
@@ -6527,8 +6872,9 @@ var init_client = __esm({
|
|
|
6527
6872
|
const res = await fetch(pollUrl, {
|
|
6528
6873
|
headers: { "User-Agent": "@mindstudio-ai/agent" }
|
|
6529
6874
|
});
|
|
6530
|
-
if (res.status === 502 || res.status === 503 || res.status === 504)
|
|
6875
|
+
if (res.status === 502 || res.status === 503 || res.status === 504) {
|
|
6531
6876
|
continue;
|
|
6877
|
+
}
|
|
6532
6878
|
if (res.status === 404) {
|
|
6533
6879
|
throw new MindStudioError(
|
|
6534
6880
|
"Batch poll token not found or expired.",
|
|
@@ -6822,8 +7168,9 @@ var init_client = __esm({
|
|
|
6822
7168
|
const res = await fetch(pollUrl, {
|
|
6823
7169
|
headers: { "User-Agent": "@mindstudio-ai/agent" }
|
|
6824
7170
|
});
|
|
6825
|
-
if (res.status === 502 || res.status === 503 || res.status === 504)
|
|
7171
|
+
if (res.status === 502 || res.status === 503 || res.status === 504) {
|
|
6826
7172
|
continue;
|
|
7173
|
+
}
|
|
6827
7174
|
if (res.status === 404) {
|
|
6828
7175
|
throw new MindStudioError(
|
|
6829
7176
|
"Poll token not found or expired.",
|
|
@@ -6841,7 +7188,9 @@ var init_client = __esm({
|
|
|
6841
7188
|
);
|
|
6842
7189
|
}
|
|
6843
7190
|
const poll = await res.json();
|
|
6844
|
-
if (poll.status === "pending")
|
|
7191
|
+
if (poll.status === "pending") {
|
|
7192
|
+
continue;
|
|
7193
|
+
}
|
|
6845
7194
|
if (poll.status === "error") {
|
|
6846
7195
|
throw new MindStudioError(
|
|
6847
7196
|
poll.error ?? "Agent run failed.",
|
|
@@ -6984,7 +7333,9 @@ var init_client = __esm({
|
|
|
6984
7333
|
*/
|
|
6985
7334
|
stream = async (data) => {
|
|
6986
7335
|
const streamId = this._currentStreamId;
|
|
6987
|
-
if (!streamId)
|
|
7336
|
+
if (!streamId) {
|
|
7337
|
+
return;
|
|
7338
|
+
}
|
|
6988
7339
|
const url = `${this._currentHttpConfig.baseUrl}/_internal/v2/stream-chunk`;
|
|
6989
7340
|
const body = typeof data === "string" ? { streamId, type: "token", text: data } : { streamId, type: "data", data };
|
|
6990
7341
|
const res = await fetch(url, {
|
|
@@ -7068,7 +7419,9 @@ var init_client = __esm({
|
|
|
7068
7419
|
if (!this._db) {
|
|
7069
7420
|
this._trySandboxHydration();
|
|
7070
7421
|
}
|
|
7071
|
-
if (this._db)
|
|
7422
|
+
if (this._db) {
|
|
7423
|
+
return this._db;
|
|
7424
|
+
}
|
|
7072
7425
|
return this._createLazyDb();
|
|
7073
7426
|
}
|
|
7074
7427
|
/**
|
|
@@ -7093,8 +7446,12 @@ var init_client = __esm({
|
|
|
7093
7446
|
* ```
|
|
7094
7447
|
*/
|
|
7095
7448
|
async ensureContext() {
|
|
7096
|
-
if (this._getContext())
|
|
7097
|
-
|
|
7449
|
+
if (this._getContext()) {
|
|
7450
|
+
return;
|
|
7451
|
+
}
|
|
7452
|
+
if (this._context) {
|
|
7453
|
+
return;
|
|
7454
|
+
}
|
|
7098
7455
|
if (!this._contextPromise) {
|
|
7099
7456
|
this._contextPromise = this._hydrateContext();
|
|
7100
7457
|
}
|
|
@@ -7140,7 +7497,9 @@ var init_client = __esm({
|
|
|
7140
7497
|
* - `ai.databases`: [{ id, name, tables[] }]
|
|
7141
7498
|
*/
|
|
7142
7499
|
_trySandboxHydration() {
|
|
7143
|
-
if (getRequestContext())
|
|
7500
|
+
if (getRequestContext()) {
|
|
7501
|
+
return;
|
|
7502
|
+
}
|
|
7144
7503
|
const ai = globalThis.ai;
|
|
7145
7504
|
if (ai?.auth && ai?.databases) {
|
|
7146
7505
|
this._applyContext({
|
|
@@ -7300,7 +7659,9 @@ var init_client = __esm({
|
|
|
7300
7659
|
try {
|
|
7301
7660
|
const errBody = await res.json();
|
|
7302
7661
|
details = errBody;
|
|
7303
|
-
if (typeof errBody.errorString === "string")
|
|
7662
|
+
if (typeof errBody.errorString === "string") {
|
|
7663
|
+
code = errBody.errorString;
|
|
7664
|
+
}
|
|
7304
7665
|
message = typeof errBody.errorMessage === "string" && errBody.errorMessage || typeof errBody.errorString === "string" && errBody.errorString || message;
|
|
7305
7666
|
} catch {
|
|
7306
7667
|
}
|
|
@@ -7502,15 +7863,20 @@ var init_client = __esm({
|
|
|
7502
7863
|
try {
|
|
7503
7864
|
const body = JSON.parse(text);
|
|
7504
7865
|
const errMsg = (typeof body.error === "string" ? body.error : void 0) ?? (typeof body.message === "string" ? body.message : void 0) ?? (typeof body.details === "string" ? body.details : void 0);
|
|
7505
|
-
if (errMsg)
|
|
7506
|
-
|
|
7866
|
+
if (errMsg) {
|
|
7867
|
+
message = errMsg;
|
|
7868
|
+
} else if (body.error || body.message || body.details) {
|
|
7507
7869
|
message = JSON.stringify(
|
|
7508
7870
|
body.error ?? body.message ?? body.details
|
|
7509
7871
|
);
|
|
7510
7872
|
}
|
|
7511
|
-
if (body.code)
|
|
7873
|
+
if (body.code) {
|
|
7874
|
+
code = body.code;
|
|
7875
|
+
}
|
|
7512
7876
|
} catch {
|
|
7513
|
-
if (text && text.length < 500)
|
|
7877
|
+
if (text && text.length < 500) {
|
|
7878
|
+
message = text;
|
|
7879
|
+
}
|
|
7514
7880
|
}
|
|
7515
7881
|
} catch {
|
|
7516
7882
|
}
|
|
@@ -7773,7 +8139,9 @@ var init_client = __esm({
|
|
|
7773
8139
|
try {
|
|
7774
8140
|
const body = await res.json();
|
|
7775
8141
|
details = body;
|
|
7776
|
-
if (typeof body.errorString === "string")
|
|
8142
|
+
if (typeof body.errorString === "string") {
|
|
8143
|
+
code = body.errorString;
|
|
8144
|
+
}
|
|
7777
8145
|
message = typeof body.errorMessage === "string" && body.errorMessage || typeof body.errorString === "string" && body.errorString || message;
|
|
7778
8146
|
} catch {
|
|
7779
8147
|
}
|
|
@@ -7817,7 +8185,9 @@ var init_client = __esm({
|
|
|
7817
8185
|
try {
|
|
7818
8186
|
const body = await res.json();
|
|
7819
8187
|
details = body;
|
|
7820
|
-
if (typeof body.errorString === "string")
|
|
8188
|
+
if (typeof body.errorString === "string") {
|
|
8189
|
+
code = body.errorString;
|
|
8190
|
+
}
|
|
7821
8191
|
message = typeof body.errorMessage === "string" && body.errorMessage || typeof body.errorString === "string" && body.errorString || message;
|
|
7822
8192
|
} catch {
|
|
7823
8193
|
}
|
|
@@ -7888,7 +8258,9 @@ var init_client = __esm({
|
|
|
7888
8258
|
const filename = options.filename ?? `upload.${options.extension}`;
|
|
7889
8259
|
const { data } = await request(this._currentHttpConfig, "POST", "/account/upload", { filename });
|
|
7890
8260
|
const form = new FormData();
|
|
7891
|
-
for (const [k, v] of Object.entries(data.fields))
|
|
8261
|
+
for (const [k, v] of Object.entries(data.fields)) {
|
|
8262
|
+
form.append(k, v);
|
|
8263
|
+
}
|
|
7892
8264
|
const buf = content.buffer.slice(
|
|
7893
8265
|
content.byteOffset,
|
|
7894
8266
|
content.byteOffset + content.byteLength
|
|
@@ -7944,8 +8316,12 @@ async function* streamChat(params) {
|
|
|
7944
8316
|
let errorMessage = `HTTP ${res.status}`;
|
|
7945
8317
|
try {
|
|
7946
8318
|
const body2 = await res.json();
|
|
7947
|
-
if (body2.error)
|
|
7948
|
-
|
|
8319
|
+
if (body2.error) {
|
|
8320
|
+
errorMessage = body2.error;
|
|
8321
|
+
}
|
|
8322
|
+
if (body2.errorMessage) {
|
|
8323
|
+
errorMessage = body2.errorMessage;
|
|
8324
|
+
}
|
|
7949
8325
|
} catch {
|
|
7950
8326
|
}
|
|
7951
8327
|
yield { type: "error", error: errorMessage };
|
|
@@ -7956,12 +8332,16 @@ async function* streamChat(params) {
|
|
|
7956
8332
|
let buffer = "";
|
|
7957
8333
|
while (true) {
|
|
7958
8334
|
const { done, value } = await reader.read();
|
|
7959
|
-
if (done)
|
|
8335
|
+
if (done) {
|
|
8336
|
+
break;
|
|
8337
|
+
}
|
|
7960
8338
|
buffer += decoder.decode(value, { stream: true });
|
|
7961
8339
|
const lines = buffer.split("\n");
|
|
7962
8340
|
buffer = lines.pop() ?? "";
|
|
7963
8341
|
for (const line of lines) {
|
|
7964
|
-
if (!line.startsWith("data: "))
|
|
8342
|
+
if (!line.startsWith("data: ")) {
|
|
8343
|
+
continue;
|
|
8344
|
+
}
|
|
7965
8345
|
try {
|
|
7966
8346
|
const event = JSON.parse(line.slice(6));
|
|
7967
8347
|
if (event.type === "text" || event.type === "tool_use" || event.type === "done" || event.type === "error") {
|
|
@@ -8780,15 +9160,15 @@ async function startMcpServer(options) {
|
|
|
8780
9160
|
return agent;
|
|
8781
9161
|
}
|
|
8782
9162
|
async function buildTools() {
|
|
8783
|
-
if (tools)
|
|
9163
|
+
if (tools) {
|
|
9164
|
+
return tools;
|
|
9165
|
+
}
|
|
8784
9166
|
const meta = await getMetadata();
|
|
8785
|
-
const stepTools = Object.entries(meta).map(
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
})
|
|
8791
|
-
);
|
|
9167
|
+
const stepTools = Object.entries(meta).map(([name, step]) => ({
|
|
9168
|
+
name,
|
|
9169
|
+
description: step.description + (step.usageNotes ? "\n\n" + step.usageNotes : ""),
|
|
9170
|
+
inputSchema: step.inputSchema
|
|
9171
|
+
}));
|
|
8792
9172
|
tools = [ASK_TOOL, ...stepTools, ...HELPER_TOOLS];
|
|
8793
9173
|
return tools;
|
|
8794
9174
|
}
|
|
@@ -8801,7 +9181,7 @@ async function startMcpServer(options) {
|
|
|
8801
9181
|
capabilities: { tools: {} },
|
|
8802
9182
|
serverInfo: {
|
|
8803
9183
|
name: "mindstudio-agent",
|
|
8804
|
-
version: "0.1.
|
|
9184
|
+
version: "0.1.130"
|
|
8805
9185
|
},
|
|
8806
9186
|
instructions: 'Welcome to MindStudio \u2014 a platform with 200+ AI models, 850+ third-party integrations, and pre-built agents.\n\nGetting started:\n1. Call `ask` with any question about the SDK \u2014 it knows every action, model, and connector and returns working code with real model IDs and config options. Examples: ask("generate an image with FLUX"), ask("what models support vision?"), ask("how do I send a Slack message?").\n2. Call `changeName` to set your display name \u2014 use your name or whatever your user calls you. This is how you\'ll appear in MindStudio request logs.\n3. If you have a profile picture, pass its public image URL to `changeProfilePicture`.\n4. For manual browsing, call `listActions` to discover all available actions.\n\nThen use the tools to generate text, images, video, audio, search the web, work with data sources, run agents, and more.\n\nImportant:\n- AI-powered actions (text generation, image generation, video, audio, etc.) cost money. Before running these, call `estimateActionCost` and confirm with the user before proceeding \u2014 unless they\'ve explicitly told you to go ahead.\n- Not all agents from `listAgents` are configured for API use. Do not try to run an agent just because it appears in the list \u2014 it will likely fail. Only run agents the user specifically asks you to run.'
|
|
8807
9187
|
});
|
|
@@ -8818,19 +9198,14 @@ async function startMcpServer(options) {
|
|
|
8818
9198
|
let result;
|
|
8819
9199
|
if (toolName === "ask") {
|
|
8820
9200
|
const { runAsk: runAsk2 } = await init_ask().then(() => ask_exports);
|
|
8821
|
-
result = await runAsk2(
|
|
8822
|
-
args.question,
|
|
8823
|
-
options
|
|
8824
|
-
);
|
|
9201
|
+
result = await runAsk2(args.question, options);
|
|
8825
9202
|
} else if (toolName === "listActions") {
|
|
8826
9203
|
const meta = await getMetadata();
|
|
8827
9204
|
const summary = {};
|
|
8828
9205
|
for (const [name, step] of Object.entries(meta)) {
|
|
8829
9206
|
summary[name] = step.description;
|
|
8830
9207
|
}
|
|
8831
|
-
for (const [name, desc] of Object.entries(
|
|
8832
|
-
HELPER_DESCRIPTIONS
|
|
8833
|
-
)) {
|
|
9208
|
+
for (const [name, desc] of Object.entries(HELPER_DESCRIPTIONS)) {
|
|
8834
9209
|
summary[name] = desc;
|
|
8835
9210
|
}
|
|
8836
9211
|
result = summary;
|
|
@@ -8874,9 +9249,7 @@ async function startMcpServer(options) {
|
|
|
8874
9249
|
}
|
|
8875
9250
|
);
|
|
8876
9251
|
} else if (toolName === "changeName") {
|
|
8877
|
-
await getAgent().changeName(
|
|
8878
|
-
args.displayName
|
|
8879
|
-
);
|
|
9252
|
+
await getAgent().changeName(args.displayName);
|
|
8880
9253
|
result = { success: true };
|
|
8881
9254
|
} else if (toolName === "changeProfilePicture") {
|
|
8882
9255
|
await getAgent().changeProfilePicture(
|
|
@@ -8886,7 +9259,9 @@ async function startMcpServer(options) {
|
|
|
8886
9259
|
} else if (toolName === "uploadFile") {
|
|
8887
9260
|
const filePath = args.filePath;
|
|
8888
9261
|
const ext = extname(filePath).slice(1).toLowerCase();
|
|
8889
|
-
if (!ext)
|
|
9262
|
+
if (!ext) {
|
|
9263
|
+
throw new Error("Cannot determine file extension from path.");
|
|
9264
|
+
}
|
|
8890
9265
|
const content = readFileSync2(filePath);
|
|
8891
9266
|
const mimeType = MIME_TYPES[ext];
|
|
8892
9267
|
result = await getAgent().uploadFile(content, {
|
|
@@ -8914,15 +9289,10 @@ async function startMcpServer(options) {
|
|
|
8914
9289
|
sendError(id, -32602, `Unknown tool: ${toolName}`);
|
|
8915
9290
|
return;
|
|
8916
9291
|
}
|
|
8917
|
-
result = await getAgent().executeStep(
|
|
8918
|
-
step.stepType,
|
|
8919
|
-
args
|
|
8920
|
-
);
|
|
9292
|
+
result = await getAgent().executeStep(step.stepType, args);
|
|
8921
9293
|
}
|
|
8922
9294
|
sendResult(id, {
|
|
8923
|
-
content: [
|
|
8924
|
-
{ type: "text", text: JSON.stringify(result, null, 2) }
|
|
8925
|
-
]
|
|
9295
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
8926
9296
|
});
|
|
8927
9297
|
} catch (err) {
|
|
8928
9298
|
const message = err instanceof MindStudioError ? `${err.code}: ${err.message}` : err instanceof Error ? err.message : String(err);
|
|
@@ -8943,7 +9313,9 @@ async function startMcpServer(options) {
|
|
|
8943
9313
|
console.log = console.warn;
|
|
8944
9314
|
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
8945
9315
|
for await (const line of rl) {
|
|
8946
|
-
if (!line.trim())
|
|
9316
|
+
if (!line.trim()) {
|
|
9317
|
+
continue;
|
|
9318
|
+
}
|
|
8947
9319
|
try {
|
|
8948
9320
|
const msg = JSON.parse(line);
|
|
8949
9321
|
await handleMessage(msg);
|
|
@@ -9283,10 +9655,18 @@ function parseJson5(input) {
|
|
|
9283
9655
|
return JSON.parse(s);
|
|
9284
9656
|
}
|
|
9285
9657
|
function coerce(value) {
|
|
9286
|
-
if (typeof value !== "string")
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
if (value
|
|
9658
|
+
if (typeof value !== "string") {
|
|
9659
|
+
return value;
|
|
9660
|
+
}
|
|
9661
|
+
if (value === "true") {
|
|
9662
|
+
return true;
|
|
9663
|
+
}
|
|
9664
|
+
if (value === "false") {
|
|
9665
|
+
return false;
|
|
9666
|
+
}
|
|
9667
|
+
if (value !== "" && !isNaN(Number(value))) {
|
|
9668
|
+
return Number(value);
|
|
9669
|
+
}
|
|
9290
9670
|
if (value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")) {
|
|
9291
9671
|
try {
|
|
9292
9672
|
return JSON.parse(value);
|
|
@@ -9302,8 +9682,12 @@ function levenshtein(a, b) {
|
|
|
9302
9682
|
{ length: m + 1 },
|
|
9303
9683
|
() => Array(n + 1).fill(0)
|
|
9304
9684
|
);
|
|
9305
|
-
for (let i = 0; i <= m; i++)
|
|
9306
|
-
|
|
9685
|
+
for (let i = 0; i <= m; i++) {
|
|
9686
|
+
dp[i][0] = i;
|
|
9687
|
+
}
|
|
9688
|
+
for (let j = 0; j <= n; j++) {
|
|
9689
|
+
dp[0][j] = j;
|
|
9690
|
+
}
|
|
9307
9691
|
for (let i = 1; i <= m; i++) {
|
|
9308
9692
|
for (let j = 1; j <= n; j++) {
|
|
9309
9693
|
dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
@@ -9330,9 +9714,13 @@ async function readStdin() {
|
|
|
9330
9714
|
return Buffer.concat(chunks).toString("utf-8").trim();
|
|
9331
9715
|
}
|
|
9332
9716
|
function resolveMethodOrFail(name, metadataKeys) {
|
|
9333
|
-
if (metadataKeys.has(name))
|
|
9717
|
+
if (metadataKeys.has(name)) {
|
|
9718
|
+
return name;
|
|
9719
|
+
}
|
|
9334
9720
|
const camel = kebabToCamel2(name);
|
|
9335
|
-
if (metadataKeys.has(camel))
|
|
9721
|
+
if (metadataKeys.has(camel)) {
|
|
9722
|
+
return camel;
|
|
9723
|
+
}
|
|
9336
9724
|
const kebab = name.includes("-") ? name : camelToKebab(name);
|
|
9337
9725
|
let bestDist = Infinity;
|
|
9338
9726
|
let bestMatch = "";
|
|
@@ -9397,12 +9785,16 @@ async function cmdInfo(rawMethod) {
|
|
|
9397
9785
|
out.push("");
|
|
9398
9786
|
out.push(` ${camelToKebab(method)}`);
|
|
9399
9787
|
out.push("");
|
|
9400
|
-
if (meta.description)
|
|
9788
|
+
if (meta.description) {
|
|
9789
|
+
out.push(` ${meta.description}`);
|
|
9790
|
+
}
|
|
9401
9791
|
if (meta.usageNotes) {
|
|
9402
9792
|
out.push("");
|
|
9403
9793
|
for (const line of meta.usageNotes.split("\n")) {
|
|
9404
9794
|
const trimmed = line.trim();
|
|
9405
|
-
if (trimmed)
|
|
9795
|
+
if (trimmed) {
|
|
9796
|
+
out.push(` ${trimmed}`);
|
|
9797
|
+
}
|
|
9406
9798
|
}
|
|
9407
9799
|
}
|
|
9408
9800
|
const schema = meta.inputSchema;
|
|
@@ -9433,12 +9825,18 @@ async function cmdInfo(rawMethod) {
|
|
|
9433
9825
|
process.stderr.write(out.join("\n") + "\n");
|
|
9434
9826
|
}
|
|
9435
9827
|
function formatPropType(prop) {
|
|
9436
|
-
if (prop.enum)
|
|
9828
|
+
if (prop.enum) {
|
|
9437
9829
|
return prop.enum.map((v) => JSON.stringify(v)).join(" | ");
|
|
9438
|
-
|
|
9439
|
-
if (prop.type === "
|
|
9440
|
-
|
|
9830
|
+
}
|
|
9831
|
+
if (prop.type === "array") {
|
|
9832
|
+
return "array";
|
|
9833
|
+
}
|
|
9834
|
+
if (prop.type === "object") {
|
|
9835
|
+
return "object";
|
|
9836
|
+
}
|
|
9837
|
+
if (typeof prop.type === "string") {
|
|
9441
9838
|
return prop.type === "integer" ? "number" : prop.type;
|
|
9839
|
+
}
|
|
9442
9840
|
return "string";
|
|
9443
9841
|
}
|
|
9444
9842
|
async function cmdExec(method, input, options) {
|
|
@@ -9461,15 +9859,18 @@ async function cmdExec(method, input, options) {
|
|
|
9461
9859
|
if (options.jsonLogs) {
|
|
9462
9860
|
onLog = (log) => {
|
|
9463
9861
|
process.stderr.write(
|
|
9464
|
-
JSON.stringify({
|
|
9862
|
+
JSON.stringify({
|
|
9863
|
+
type: "log",
|
|
9864
|
+
value: log.value,
|
|
9865
|
+
tag: log.tag,
|
|
9866
|
+
ts: log.ts
|
|
9867
|
+
}) + "\n"
|
|
9465
9868
|
);
|
|
9466
9869
|
};
|
|
9467
9870
|
} else if (process.stderr.isTTY) {
|
|
9468
9871
|
onLog = (log) => {
|
|
9469
|
-
process.stderr.write(
|
|
9470
|
-
|
|
9471
|
-
`
|
|
9472
|
-
);
|
|
9872
|
+
process.stderr.write(` ${ansi2.cyan("\u27E1")} ${ansi2.gray(log.value)}
|
|
9873
|
+
`);
|
|
9473
9874
|
};
|
|
9474
9875
|
}
|
|
9475
9876
|
const result = await agent.executeStep(meta.stepType, input, {
|
|
@@ -9487,7 +9888,9 @@ async function cmdExec(method, input, options) {
|
|
|
9487
9888
|
} else if (options.noMeta) {
|
|
9488
9889
|
const filtered = {};
|
|
9489
9890
|
for (const [k, v] of Object.entries(result)) {
|
|
9490
|
-
if (!k.startsWith("$"))
|
|
9891
|
+
if (!k.startsWith("$")) {
|
|
9892
|
+
filtered[k] = v;
|
|
9893
|
+
}
|
|
9491
9894
|
}
|
|
9492
9895
|
process.stdout.write(JSON.stringify(filtered, null, 2) + "\n");
|
|
9493
9896
|
} else {
|
|
@@ -9607,7 +10010,9 @@ async function cmdRun(appId, variables, options) {
|
|
|
9607
10010
|
} else if (options.noMeta) {
|
|
9608
10011
|
const filtered = {};
|
|
9609
10012
|
for (const [k, v] of Object.entries(obj)) {
|
|
9610
|
-
if (!k.startsWith("$"))
|
|
10013
|
+
if (!k.startsWith("$")) {
|
|
10014
|
+
filtered[k] = v;
|
|
10015
|
+
}
|
|
9611
10016
|
}
|
|
9612
10017
|
process.stdout.write(JSON.stringify(filtered, null, 2) + "\n");
|
|
9613
10018
|
} else {
|
|
@@ -9633,22 +10038,20 @@ Example: mindstudio batch '[{"stepType":"generateImage","step":{"prompt":"a cat"
|
|
|
9633
10038
|
const metaByName = new Map(
|
|
9634
10039
|
Object.entries(stepMetadata2).map(([name, m]) => [name, m])
|
|
9635
10040
|
);
|
|
9636
|
-
const steps = input.map(
|
|
9637
|
-
(item
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
meta = metaByName.get(camel);
|
|
9645
|
-
}
|
|
9646
|
-
if (meta) {
|
|
9647
|
-
return { stepType: meta.stepType, step: item.step };
|
|
9648
|
-
}
|
|
9649
|
-
return { stepType: item.stepType, step: item.step };
|
|
10041
|
+
const steps = input.map((item, i) => {
|
|
10042
|
+
let meta = metaByName.get(item.stepType);
|
|
10043
|
+
if (!meta) {
|
|
10044
|
+
const camel = item.stepType.replace(
|
|
10045
|
+
/-([a-z])/g,
|
|
10046
|
+
(_, c) => c.toUpperCase()
|
|
10047
|
+
);
|
|
10048
|
+
meta = metaByName.get(camel);
|
|
9650
10049
|
}
|
|
9651
|
-
|
|
10050
|
+
if (meta) {
|
|
10051
|
+
return { stepType: meta.stepType, step: item.step };
|
|
10052
|
+
}
|
|
10053
|
+
return { stepType: item.stepType, step: item.step };
|
|
10054
|
+
});
|
|
9652
10055
|
const agent = await createAgent(options);
|
|
9653
10056
|
const result = await agent.executeStepBatch(steps, {
|
|
9654
10057
|
appId: options.appId,
|
|
@@ -9662,7 +10065,11 @@ Example: mindstudio batch '[{"stepType":"generateImage","step":{"prompt":"a cat"
|
|
|
9662
10065
|
}
|
|
9663
10066
|
async function cmdUpload(filePath, options) {
|
|
9664
10067
|
const ext = extname2(filePath).slice(1).toLowerCase();
|
|
9665
|
-
if (!ext)
|
|
10068
|
+
if (!ext) {
|
|
10069
|
+
fatal(
|
|
10070
|
+
"Cannot determine file extension. Please provide a file with an extension."
|
|
10071
|
+
);
|
|
10072
|
+
}
|
|
9666
10073
|
const content = readFileSync3(filePath);
|
|
9667
10074
|
const mimeType = MIME_TYPES2[ext];
|
|
9668
10075
|
const { MindStudioAgent: MindStudioAgent2 } = await init_client().then(() => client_exports);
|
|
@@ -9683,14 +10090,20 @@ function isNewerVersion(current, latest) {
|
|
|
9683
10090
|
for (let i = 0; i < Math.max(c.length, l.length); i++) {
|
|
9684
10091
|
const cv = c[i] ?? 0;
|
|
9685
10092
|
const lv = l[i] ?? 0;
|
|
9686
|
-
if (lv > cv)
|
|
9687
|
-
|
|
10093
|
+
if (lv > cv) {
|
|
10094
|
+
return true;
|
|
10095
|
+
}
|
|
10096
|
+
if (lv < cv) {
|
|
10097
|
+
return false;
|
|
10098
|
+
}
|
|
9688
10099
|
}
|
|
9689
10100
|
return false;
|
|
9690
10101
|
}
|
|
9691
10102
|
async function checkForUpdate() {
|
|
9692
|
-
const currentVersion = "0.1.
|
|
9693
|
-
if (!currentVersion)
|
|
10103
|
+
const currentVersion = "0.1.130";
|
|
10104
|
+
if (!currentVersion) {
|
|
10105
|
+
return null;
|
|
10106
|
+
}
|
|
9694
10107
|
try {
|
|
9695
10108
|
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
9696
10109
|
const config = loadConfig2();
|
|
@@ -9704,10 +10117,14 @@ async function checkForUpdate() {
|
|
|
9704
10117
|
"https://registry.npmjs.org/@mindstudio-ai/agent/latest",
|
|
9705
10118
|
{ signal: AbortSignal.timeout(5e3) }
|
|
9706
10119
|
);
|
|
9707
|
-
if (!res.ok)
|
|
10120
|
+
if (!res.ok) {
|
|
10121
|
+
return null;
|
|
10122
|
+
}
|
|
9708
10123
|
const data = await res.json();
|
|
9709
10124
|
const latestVersion = data.version;
|
|
9710
|
-
if (!latestVersion)
|
|
10125
|
+
if (!latestVersion) {
|
|
10126
|
+
return null;
|
|
10127
|
+
}
|
|
9711
10128
|
saveConfig2({
|
|
9712
10129
|
...config,
|
|
9713
10130
|
_updateCheck: { latestVersion, checkedAt: Date.now() }
|
|
@@ -9718,7 +10135,7 @@ async function checkForUpdate() {
|
|
|
9718
10135
|
}
|
|
9719
10136
|
}
|
|
9720
10137
|
function printUpdateNotice(latestVersion) {
|
|
9721
|
-
const currentVersion = "0.1.
|
|
10138
|
+
const currentVersion = "0.1.130";
|
|
9722
10139
|
process.stderr.write(
|
|
9723
10140
|
`
|
|
9724
10141
|
${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
|
|
@@ -9731,7 +10148,7 @@ function isStandaloneBinary() {
|
|
|
9731
10148
|
return !argv1.includes("node_modules");
|
|
9732
10149
|
}
|
|
9733
10150
|
async function cmdUpdate() {
|
|
9734
|
-
const currentVersion = "0.1.
|
|
10151
|
+
const currentVersion = "0.1.130";
|
|
9735
10152
|
process.stderr.write(
|
|
9736
10153
|
` ${ansi2.gray("Current version:")} ${currentVersion}
|
|
9737
10154
|
`
|
|
@@ -9812,9 +10229,13 @@ function printLogo() {
|
|
|
9812
10229
|
}
|
|
9813
10230
|
function openBrowser(url) {
|
|
9814
10231
|
try {
|
|
9815
|
-
if (process.platform === "darwin")
|
|
9816
|
-
|
|
9817
|
-
else
|
|
10232
|
+
if (process.platform === "darwin") {
|
|
10233
|
+
execSync(`open "${url}"`);
|
|
10234
|
+
} else if (process.platform === "win32") {
|
|
10235
|
+
execSync(`start "" "${url}"`);
|
|
10236
|
+
} else {
|
|
10237
|
+
execSync(`xdg-open "${url}"`);
|
|
10238
|
+
}
|
|
9818
10239
|
} catch {
|
|
9819
10240
|
}
|
|
9820
10241
|
}
|
|
@@ -9837,7 +10258,9 @@ function waitForKeypress() {
|
|
|
9837
10258
|
});
|
|
9838
10259
|
}
|
|
9839
10260
|
function maskKey(key) {
|
|
9840
|
-
if (key.length <= 8)
|
|
10261
|
+
if (key.length <= 8) {
|
|
10262
|
+
return "****";
|
|
10263
|
+
}
|
|
9841
10264
|
return key.slice(0, 4) + "..." + key.slice(-4);
|
|
9842
10265
|
}
|
|
9843
10266
|
async function cmdLogin(options) {
|
|
@@ -9846,7 +10269,7 @@ async function cmdLogin(options) {
|
|
|
9846
10269
|
process.stderr.write("\n");
|
|
9847
10270
|
printLogo();
|
|
9848
10271
|
process.stderr.write("\n");
|
|
9849
|
-
const ver = "0.1.
|
|
10272
|
+
const ver = "0.1.130";
|
|
9850
10273
|
process.stderr.write(
|
|
9851
10274
|
` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
|
|
9852
10275
|
`
|
|
@@ -9993,7 +10416,9 @@ async function cmdWhoami(options) {
|
|
|
9993
10416
|
}
|
|
9994
10417
|
process.stderr.write(` ${ansi2.gray("Auth:")} ${source}
|
|
9995
10418
|
`);
|
|
9996
|
-
for (const line of detail)
|
|
10419
|
+
for (const line of detail) {
|
|
10420
|
+
process.stderr.write(line + "\n");
|
|
10421
|
+
}
|
|
9997
10422
|
process.stderr.write(` ${ansi2.gray("Verifying...")} `);
|
|
9998
10423
|
try {
|
|
9999
10424
|
const { MindStudioAgent: MindStudioAgent2 } = await init_client().then(() => client_exports);
|
|
@@ -10009,10 +10434,8 @@ async function cmdWhoami(options) {
|
|
|
10009
10434
|
);
|
|
10010
10435
|
process.stderr.write(` ${ansi2.bold("User")}
|
|
10011
10436
|
`);
|
|
10012
|
-
process.stderr.write(
|
|
10013
|
-
|
|
10014
|
-
`
|
|
10015
|
-
);
|
|
10437
|
+
process.stderr.write(` ${ansi2.gray("Name:")} ${info.displayName}
|
|
10438
|
+
`);
|
|
10016
10439
|
process.stderr.write(
|
|
10017
10440
|
` ${ansi2.gray("ID:")} ${ansi2.gray(info.userId)}
|
|
10018
10441
|
`
|
|
@@ -10020,10 +10443,8 @@ async function cmdWhoami(options) {
|
|
|
10020
10443
|
process.stderr.write(`
|
|
10021
10444
|
${ansi2.bold("Organization")}
|
|
10022
10445
|
`);
|
|
10023
|
-
process.stderr.write(
|
|
10024
|
-
|
|
10025
|
-
`
|
|
10026
|
-
);
|
|
10446
|
+
process.stderr.write(` ${ansi2.gray("Name:")} ${info.organizationName}
|
|
10447
|
+
`);
|
|
10027
10448
|
process.stderr.write(
|
|
10028
10449
|
` ${ansi2.gray("ID:")} ${ansi2.gray(info.organizationId)}
|
|
10029
10450
|
`
|
|
@@ -10036,10 +10457,7 @@ async function cmdWhoami(options) {
|
|
|
10036
10457
|
4,
|
|
10037
10458
|
...info.members.map((m) => m.displayName.length)
|
|
10038
10459
|
);
|
|
10039
|
-
const roleWidth = Math.max(
|
|
10040
|
-
4,
|
|
10041
|
-
...info.members.map((m) => m.role.length)
|
|
10042
|
-
);
|
|
10460
|
+
const roleWidth = Math.max(4, ...info.members.map((m) => m.role.length));
|
|
10043
10461
|
process.stderr.write(
|
|
10044
10462
|
` ${ansi2.gray("Name".padEnd(nameWidth))} ${ansi2.gray("Role".padEnd(roleWidth))} ${ansi2.gray("Type")}
|
|
10045
10463
|
`
|
|
@@ -10069,8 +10487,12 @@ function parseStepFlags(argv) {
|
|
|
10069
10487
|
const result = {};
|
|
10070
10488
|
for (let i = 0; i < argv.length; i++) {
|
|
10071
10489
|
const arg = argv[i];
|
|
10072
|
-
if (!arg.startsWith("--"))
|
|
10073
|
-
|
|
10490
|
+
if (!arg.startsWith("--")) {
|
|
10491
|
+
continue;
|
|
10492
|
+
}
|
|
10493
|
+
if (GLOBAL_BOOLEAN_FLAGS.has(arg)) {
|
|
10494
|
+
continue;
|
|
10495
|
+
}
|
|
10074
10496
|
if (GLOBAL_STRING_FLAGS.has(arg)) {
|
|
10075
10497
|
i++;
|
|
10076
10498
|
continue;
|
|
@@ -10088,7 +10510,9 @@ function findMethodSplit(argv) {
|
|
|
10088
10510
|
for (let i = 0; i < argv.length; i++) {
|
|
10089
10511
|
const arg = argv[i];
|
|
10090
10512
|
if (arg.startsWith("--")) {
|
|
10091
|
-
if (GLOBAL_STRING_FLAGS.has(arg))
|
|
10513
|
+
if (GLOBAL_STRING_FLAGS.has(arg)) {
|
|
10514
|
+
i++;
|
|
10515
|
+
}
|
|
10092
10516
|
continue;
|
|
10093
10517
|
}
|
|
10094
10518
|
if (arg === "run") {
|
|
@@ -10102,7 +10526,9 @@ function findMethodSplit(argv) {
|
|
|
10102
10526
|
for (let i = startIdx; i < argv.length; i++) {
|
|
10103
10527
|
const arg = argv[i];
|
|
10104
10528
|
if (arg.startsWith("--")) {
|
|
10105
|
-
if (GLOBAL_STRING_FLAGS.has(arg))
|
|
10529
|
+
if (GLOBAL_STRING_FLAGS.has(arg)) {
|
|
10530
|
+
i++;
|
|
10531
|
+
}
|
|
10106
10532
|
continue;
|
|
10107
10533
|
}
|
|
10108
10534
|
if (hasRun || i === startIdx) {
|
|
@@ -10156,9 +10582,7 @@ async function main() {
|
|
|
10156
10582
|
const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
|
|
10157
10583
|
try {
|
|
10158
10584
|
if (command === "version" || command === "-v") {
|
|
10159
|
-
process.stdout.write(
|
|
10160
|
-
"0.1.128\n"
|
|
10161
|
-
);
|
|
10585
|
+
process.stdout.write("0.1.130\n");
|
|
10162
10586
|
return;
|
|
10163
10587
|
}
|
|
10164
10588
|
if (command === "login") {
|
|
@@ -10282,7 +10706,7 @@ async function main() {
|
|
|
10282
10706
|
}
|
|
10283
10707
|
if (command === "run-agent") {
|
|
10284
10708
|
const appId = positionals[1];
|
|
10285
|
-
if (!appId)
|
|
10709
|
+
if (!appId) {
|
|
10286
10710
|
usageBlock([
|
|
10287
10711
|
"run-agent \u2014 Run a pre-built agent and wait for the result",
|
|
10288
10712
|
"",
|
|
@@ -10302,6 +10726,7 @@ async function main() {
|
|
|
10302
10726
|
"",
|
|
10303
10727
|
'Tip: run "mindstudio agents" to list available agent IDs.'
|
|
10304
10728
|
]);
|
|
10729
|
+
}
|
|
10305
10730
|
const runArgv = process.argv.slice(process.argv.indexOf("run-agent") + 2);
|
|
10306
10731
|
const stepArgs = [];
|
|
10307
10732
|
for (let i = 0; i < runArgv.length; i++) {
|
|
@@ -10349,7 +10774,7 @@ async function main() {
|
|
|
10349
10774
|
}
|
|
10350
10775
|
if (command === "upload" || command === "upload-file") {
|
|
10351
10776
|
const filePath = positionals[1];
|
|
10352
|
-
if (!filePath)
|
|
10777
|
+
if (!filePath) {
|
|
10353
10778
|
usageBlock([
|
|
10354
10779
|
"upload \u2014 Upload a file to the MindStudio CDN (alias: upload-file)",
|
|
10355
10780
|
"",
|
|
@@ -10364,6 +10789,7 @@ async function main() {
|
|
|
10364
10789
|
" mindstudio upload photo.png",
|
|
10365
10790
|
" mindstudio upload-file /path/to/document.pdf"
|
|
10366
10791
|
]);
|
|
10792
|
+
}
|
|
10367
10793
|
await cmdUpload(filePath, {
|
|
10368
10794
|
apiKey: values["api-key"],
|
|
10369
10795
|
baseUrl: values["base-url"]
|
|
@@ -10379,7 +10805,7 @@ async function main() {
|
|
|
10379
10805
|
let summary = false;
|
|
10380
10806
|
if (command === "list-models-by-type" || command === "list-models-summary-by-type") {
|
|
10381
10807
|
type = positionals[1];
|
|
10382
|
-
if (!type)
|
|
10808
|
+
if (!type) {
|
|
10383
10809
|
usageBlock([
|
|
10384
10810
|
`${command} \u2014 List AI models filtered by type`,
|
|
10385
10811
|
"",
|
|
@@ -10394,14 +10820,19 @@ async function main() {
|
|
|
10394
10820
|
` mindstudio ${command} image_generation`,
|
|
10395
10821
|
` mindstudio ${command} llm_chat`
|
|
10396
10822
|
]);
|
|
10823
|
+
}
|
|
10397
10824
|
}
|
|
10398
10825
|
if (command === "list-models-summary" || command === "list-models-summary-by-type") {
|
|
10399
10826
|
summary = true;
|
|
10400
10827
|
}
|
|
10401
10828
|
if (command === "list-models") {
|
|
10402
10829
|
const typeFlag = values.type;
|
|
10403
|
-
if (typeFlag)
|
|
10404
|
-
|
|
10830
|
+
if (typeFlag) {
|
|
10831
|
+
type = typeFlag;
|
|
10832
|
+
}
|
|
10833
|
+
if (values.summary) {
|
|
10834
|
+
summary = true;
|
|
10835
|
+
}
|
|
10405
10836
|
}
|
|
10406
10837
|
await cmdListModels({ ...authOpts, type, summary });
|
|
10407
10838
|
return;
|
|
@@ -10429,7 +10860,7 @@ async function main() {
|
|
|
10429
10860
|
}
|
|
10430
10861
|
if (command === "estimate-cost") {
|
|
10431
10862
|
const stepMethod = positionals[1];
|
|
10432
|
-
if (!stepMethod)
|
|
10863
|
+
if (!stepMethod) {
|
|
10433
10864
|
usageBlock([
|
|
10434
10865
|
"estimate-cost \u2014 Estimate the cost of an action before running it",
|
|
10435
10866
|
"",
|
|
@@ -10442,6 +10873,7 @@ async function main() {
|
|
|
10442
10873
|
"",
|
|
10443
10874
|
'Tip: run "mindstudio list-actions" to see available actions.'
|
|
10444
10875
|
]);
|
|
10876
|
+
}
|
|
10445
10877
|
const allKeys2 = await getAllMethodKeys();
|
|
10446
10878
|
const resolvedMethod = resolveMethodOrFail(stepMethod, allKeys2);
|
|
10447
10879
|
const { stepMetadata: stepMetadata2 } = await Promise.resolve().then(() => (init_metadata(), metadata_exports));
|
|
@@ -10466,7 +10898,7 @@ async function main() {
|
|
|
10466
10898
|
}
|
|
10467
10899
|
if (command === "change-name") {
|
|
10468
10900
|
const name = positionals[1];
|
|
10469
|
-
if (!name)
|
|
10901
|
+
if (!name) {
|
|
10470
10902
|
usageBlock([
|
|
10471
10903
|
"change-name \u2014 Update your display name",
|
|
10472
10904
|
"",
|
|
@@ -10476,6 +10908,7 @@ async function main() {
|
|
|
10476
10908
|
"Examples:",
|
|
10477
10909
|
' mindstudio change-name "My Agent"'
|
|
10478
10910
|
]);
|
|
10911
|
+
}
|
|
10479
10912
|
await cmdChangeName(name, {
|
|
10480
10913
|
apiKey: values["api-key"],
|
|
10481
10914
|
baseUrl: values["base-url"]
|
|
@@ -10484,7 +10917,7 @@ async function main() {
|
|
|
10484
10917
|
}
|
|
10485
10918
|
if (command === "change-profile-picture") {
|
|
10486
10919
|
const url = positionals[1];
|
|
10487
|
-
if (!url)
|
|
10920
|
+
if (!url) {
|
|
10488
10921
|
usageBlock([
|
|
10489
10922
|
"change-profile-picture \u2014 Update your profile picture",
|
|
10490
10923
|
"",
|
|
@@ -10496,6 +10929,7 @@ async function main() {
|
|
|
10496
10929
|
"",
|
|
10497
10930
|
'Tip: use "mindstudio upload" to host an image first.'
|
|
10498
10931
|
]);
|
|
10932
|
+
}
|
|
10499
10933
|
await cmdChangeProfilePicture(url, {
|
|
10500
10934
|
apiKey: values["api-key"],
|
|
10501
10935
|
baseUrl: values["base-url"]
|
|
@@ -10512,7 +10946,7 @@ async function main() {
|
|
|
10512
10946
|
}
|
|
10513
10947
|
if (command === "info") {
|
|
10514
10948
|
const rawMethod2 = positionals[1];
|
|
10515
|
-
if (!rawMethod2)
|
|
10949
|
+
if (!rawMethod2) {
|
|
10516
10950
|
usageBlock([
|
|
10517
10951
|
"info \u2014 Show action details and parameters",
|
|
10518
10952
|
"",
|
|
@@ -10528,11 +10962,12 @@ async function main() {
|
|
|
10528
10962
|
"",
|
|
10529
10963
|
'Tip: run "mindstudio list-actions" to see available actions.'
|
|
10530
10964
|
]);
|
|
10965
|
+
}
|
|
10531
10966
|
await cmdInfo(rawMethod2);
|
|
10532
10967
|
return;
|
|
10533
10968
|
}
|
|
10534
10969
|
const split = findMethodSplit(process.argv.slice(2));
|
|
10535
|
-
if (!split)
|
|
10970
|
+
if (!split) {
|
|
10536
10971
|
usageBlock([
|
|
10537
10972
|
"Run an action directly",
|
|
10538
10973
|
"",
|
|
@@ -10555,6 +10990,7 @@ async function main() {
|
|
|
10555
10990
|
"",
|
|
10556
10991
|
'Tip: run "mindstudio list-actions" to see available actions.'
|
|
10557
10992
|
]);
|
|
10993
|
+
}
|
|
10558
10994
|
const { rawMethod, stepArgv } = split;
|
|
10559
10995
|
const allKeys = await getAllMethodKeys();
|
|
10560
10996
|
const method = resolveMethodOrFail(rawMethod, allKeys);
|
|
@@ -10595,7 +11031,9 @@ async function main() {
|
|
|
10595
11031
|
fatal(message);
|
|
10596
11032
|
} finally {
|
|
10597
11033
|
const latestVersion = await updatePromise;
|
|
10598
|
-
if (latestVersion)
|
|
11034
|
+
if (latestVersion) {
|
|
11035
|
+
printUpdateNotice(latestVersion);
|
|
11036
|
+
}
|
|
10599
11037
|
}
|
|
10600
11038
|
}
|
|
10601
11039
|
var HELP, MIME_TYPES2, ansi2, UPDATE_CHECK_INTERVAL, LOGO, DEFAULT_BASE_URL3, SPINNER_FRAMES, GLOBAL_STRING_FLAGS, GLOBAL_BOOLEAN_FLAGS;
|