@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/cli.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);
|
|
@@ -9353,10 +9725,18 @@ function parseJson5(input) {
|
|
|
9353
9725
|
return JSON.parse(s);
|
|
9354
9726
|
}
|
|
9355
9727
|
function coerce(value) {
|
|
9356
|
-
if (typeof value !== "string")
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
if (value
|
|
9728
|
+
if (typeof value !== "string") {
|
|
9729
|
+
return value;
|
|
9730
|
+
}
|
|
9731
|
+
if (value === "true") {
|
|
9732
|
+
return true;
|
|
9733
|
+
}
|
|
9734
|
+
if (value === "false") {
|
|
9735
|
+
return false;
|
|
9736
|
+
}
|
|
9737
|
+
if (value !== "" && !isNaN(Number(value))) {
|
|
9738
|
+
return Number(value);
|
|
9739
|
+
}
|
|
9360
9740
|
if (value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")) {
|
|
9361
9741
|
try {
|
|
9362
9742
|
return JSON.parse(value);
|
|
@@ -9372,8 +9752,12 @@ function levenshtein(a, b) {
|
|
|
9372
9752
|
{ length: m + 1 },
|
|
9373
9753
|
() => Array(n + 1).fill(0)
|
|
9374
9754
|
);
|
|
9375
|
-
for (let i = 0; i <= m; i++)
|
|
9376
|
-
|
|
9755
|
+
for (let i = 0; i <= m; i++) {
|
|
9756
|
+
dp[i][0] = i;
|
|
9757
|
+
}
|
|
9758
|
+
for (let j = 0; j <= n; j++) {
|
|
9759
|
+
dp[0][j] = j;
|
|
9760
|
+
}
|
|
9377
9761
|
for (let i = 1; i <= m; i++) {
|
|
9378
9762
|
for (let j = 1; j <= n; j++) {
|
|
9379
9763
|
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]);
|
|
@@ -9400,9 +9784,13 @@ async function readStdin() {
|
|
|
9400
9784
|
return Buffer.concat(chunks).toString("utf-8").trim();
|
|
9401
9785
|
}
|
|
9402
9786
|
function resolveMethodOrFail(name, metadataKeys) {
|
|
9403
|
-
if (metadataKeys.has(name))
|
|
9787
|
+
if (metadataKeys.has(name)) {
|
|
9788
|
+
return name;
|
|
9789
|
+
}
|
|
9404
9790
|
const camel = kebabToCamel2(name);
|
|
9405
|
-
if (metadataKeys.has(camel))
|
|
9791
|
+
if (metadataKeys.has(camel)) {
|
|
9792
|
+
return camel;
|
|
9793
|
+
}
|
|
9406
9794
|
const kebab = name.includes("-") ? name : camelToKebab(name);
|
|
9407
9795
|
let bestDist = Infinity;
|
|
9408
9796
|
let bestMatch = "";
|
|
@@ -9467,12 +9855,16 @@ async function cmdInfo(rawMethod) {
|
|
|
9467
9855
|
out.push("");
|
|
9468
9856
|
out.push(` ${camelToKebab(method)}`);
|
|
9469
9857
|
out.push("");
|
|
9470
|
-
if (meta.description)
|
|
9858
|
+
if (meta.description) {
|
|
9859
|
+
out.push(` ${meta.description}`);
|
|
9860
|
+
}
|
|
9471
9861
|
if (meta.usageNotes) {
|
|
9472
9862
|
out.push("");
|
|
9473
9863
|
for (const line of meta.usageNotes.split("\n")) {
|
|
9474
9864
|
const trimmed = line.trim();
|
|
9475
|
-
if (trimmed)
|
|
9865
|
+
if (trimmed) {
|
|
9866
|
+
out.push(` ${trimmed}`);
|
|
9867
|
+
}
|
|
9476
9868
|
}
|
|
9477
9869
|
}
|
|
9478
9870
|
const schema = meta.inputSchema;
|
|
@@ -9503,12 +9895,18 @@ async function cmdInfo(rawMethod) {
|
|
|
9503
9895
|
process.stderr.write(out.join("\n") + "\n");
|
|
9504
9896
|
}
|
|
9505
9897
|
function formatPropType(prop) {
|
|
9506
|
-
if (prop.enum)
|
|
9898
|
+
if (prop.enum) {
|
|
9507
9899
|
return prop.enum.map((v) => JSON.stringify(v)).join(" | ");
|
|
9508
|
-
|
|
9509
|
-
if (prop.type === "
|
|
9510
|
-
|
|
9900
|
+
}
|
|
9901
|
+
if (prop.type === "array") {
|
|
9902
|
+
return "array";
|
|
9903
|
+
}
|
|
9904
|
+
if (prop.type === "object") {
|
|
9905
|
+
return "object";
|
|
9906
|
+
}
|
|
9907
|
+
if (typeof prop.type === "string") {
|
|
9511
9908
|
return prop.type === "integer" ? "number" : prop.type;
|
|
9909
|
+
}
|
|
9512
9910
|
return "string";
|
|
9513
9911
|
}
|
|
9514
9912
|
async function cmdExec(method, input, options) {
|
|
@@ -9531,15 +9929,18 @@ async function cmdExec(method, input, options) {
|
|
|
9531
9929
|
if (options.jsonLogs) {
|
|
9532
9930
|
onLog = (log) => {
|
|
9533
9931
|
process.stderr.write(
|
|
9534
|
-
JSON.stringify({
|
|
9932
|
+
JSON.stringify({
|
|
9933
|
+
type: "log",
|
|
9934
|
+
value: log.value,
|
|
9935
|
+
tag: log.tag,
|
|
9936
|
+
ts: log.ts
|
|
9937
|
+
}) + "\n"
|
|
9535
9938
|
);
|
|
9536
9939
|
};
|
|
9537
9940
|
} else if (process.stderr.isTTY) {
|
|
9538
9941
|
onLog = (log) => {
|
|
9539
|
-
process.stderr.write(
|
|
9540
|
-
|
|
9541
|
-
`
|
|
9542
|
-
);
|
|
9942
|
+
process.stderr.write(` ${ansi2.cyan("\u27E1")} ${ansi2.gray(log.value)}
|
|
9943
|
+
`);
|
|
9543
9944
|
};
|
|
9544
9945
|
}
|
|
9545
9946
|
const result = await agent.executeStep(meta.stepType, input, {
|
|
@@ -9557,7 +9958,9 @@ async function cmdExec(method, input, options) {
|
|
|
9557
9958
|
} else if (options.noMeta) {
|
|
9558
9959
|
const filtered = {};
|
|
9559
9960
|
for (const [k, v] of Object.entries(result)) {
|
|
9560
|
-
if (!k.startsWith("$"))
|
|
9961
|
+
if (!k.startsWith("$")) {
|
|
9962
|
+
filtered[k] = v;
|
|
9963
|
+
}
|
|
9561
9964
|
}
|
|
9562
9965
|
process.stdout.write(JSON.stringify(filtered, null, 2) + "\n");
|
|
9563
9966
|
} else {
|
|
@@ -9677,7 +10080,9 @@ async function cmdRun(appId, variables, options) {
|
|
|
9677
10080
|
} else if (options.noMeta) {
|
|
9678
10081
|
const filtered = {};
|
|
9679
10082
|
for (const [k, v] of Object.entries(obj)) {
|
|
9680
|
-
if (!k.startsWith("$"))
|
|
10083
|
+
if (!k.startsWith("$")) {
|
|
10084
|
+
filtered[k] = v;
|
|
10085
|
+
}
|
|
9681
10086
|
}
|
|
9682
10087
|
process.stdout.write(JSON.stringify(filtered, null, 2) + "\n");
|
|
9683
10088
|
} else {
|
|
@@ -9703,22 +10108,20 @@ Example: mindstudio batch '[{"stepType":"generateImage","step":{"prompt":"a cat"
|
|
|
9703
10108
|
const metaByName = new Map(
|
|
9704
10109
|
Object.entries(stepMetadata2).map(([name, m]) => [name, m])
|
|
9705
10110
|
);
|
|
9706
|
-
const steps = input.map(
|
|
9707
|
-
(item
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
meta = metaByName.get(camel);
|
|
9715
|
-
}
|
|
9716
|
-
if (meta) {
|
|
9717
|
-
return { stepType: meta.stepType, step: item.step };
|
|
9718
|
-
}
|
|
9719
|
-
return { stepType: item.stepType, step: item.step };
|
|
10111
|
+
const steps = input.map((item, i) => {
|
|
10112
|
+
let meta = metaByName.get(item.stepType);
|
|
10113
|
+
if (!meta) {
|
|
10114
|
+
const camel = item.stepType.replace(
|
|
10115
|
+
/-([a-z])/g,
|
|
10116
|
+
(_, c) => c.toUpperCase()
|
|
10117
|
+
);
|
|
10118
|
+
meta = metaByName.get(camel);
|
|
9720
10119
|
}
|
|
9721
|
-
|
|
10120
|
+
if (meta) {
|
|
10121
|
+
return { stepType: meta.stepType, step: item.step };
|
|
10122
|
+
}
|
|
10123
|
+
return { stepType: item.stepType, step: item.step };
|
|
10124
|
+
});
|
|
9722
10125
|
const agent = await createAgent(options);
|
|
9723
10126
|
const result = await agent.executeStepBatch(steps, {
|
|
9724
10127
|
appId: options.appId,
|
|
@@ -9748,7 +10151,11 @@ var MIME_TYPES2 = {
|
|
|
9748
10151
|
};
|
|
9749
10152
|
async function cmdUpload(filePath, options) {
|
|
9750
10153
|
const ext = extname2(filePath).slice(1).toLowerCase();
|
|
9751
|
-
if (!ext)
|
|
10154
|
+
if (!ext) {
|
|
10155
|
+
fatal(
|
|
10156
|
+
"Cannot determine file extension. Please provide a file with an extension."
|
|
10157
|
+
);
|
|
10158
|
+
}
|
|
9752
10159
|
const content = readFileSync3(filePath);
|
|
9753
10160
|
const mimeType = MIME_TYPES2[ext];
|
|
9754
10161
|
const { MindStudioAgent: MindStudioAgent2 } = await init_client().then(() => client_exports);
|
|
@@ -9780,14 +10187,20 @@ function isNewerVersion(current, latest) {
|
|
|
9780
10187
|
for (let i = 0; i < Math.max(c.length, l.length); i++) {
|
|
9781
10188
|
const cv = c[i] ?? 0;
|
|
9782
10189
|
const lv = l[i] ?? 0;
|
|
9783
|
-
if (lv > cv)
|
|
9784
|
-
|
|
10190
|
+
if (lv > cv) {
|
|
10191
|
+
return true;
|
|
10192
|
+
}
|
|
10193
|
+
if (lv < cv) {
|
|
10194
|
+
return false;
|
|
10195
|
+
}
|
|
9785
10196
|
}
|
|
9786
10197
|
return false;
|
|
9787
10198
|
}
|
|
9788
10199
|
async function checkForUpdate() {
|
|
9789
|
-
const currentVersion = "0.1.
|
|
9790
|
-
if (!currentVersion)
|
|
10200
|
+
const currentVersion = "0.1.130";
|
|
10201
|
+
if (!currentVersion) {
|
|
10202
|
+
return null;
|
|
10203
|
+
}
|
|
9791
10204
|
try {
|
|
9792
10205
|
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
9793
10206
|
const config = loadConfig2();
|
|
@@ -9801,10 +10214,14 @@ async function checkForUpdate() {
|
|
|
9801
10214
|
"https://registry.npmjs.org/@mindstudio-ai/agent/latest",
|
|
9802
10215
|
{ signal: AbortSignal.timeout(5e3) }
|
|
9803
10216
|
);
|
|
9804
|
-
if (!res.ok)
|
|
10217
|
+
if (!res.ok) {
|
|
10218
|
+
return null;
|
|
10219
|
+
}
|
|
9805
10220
|
const data = await res.json();
|
|
9806
10221
|
const latestVersion = data.version;
|
|
9807
|
-
if (!latestVersion)
|
|
10222
|
+
if (!latestVersion) {
|
|
10223
|
+
return null;
|
|
10224
|
+
}
|
|
9808
10225
|
saveConfig2({
|
|
9809
10226
|
...config,
|
|
9810
10227
|
_updateCheck: { latestVersion, checkedAt: Date.now() }
|
|
@@ -9815,7 +10232,7 @@ async function checkForUpdate() {
|
|
|
9815
10232
|
}
|
|
9816
10233
|
}
|
|
9817
10234
|
function printUpdateNotice(latestVersion) {
|
|
9818
|
-
const currentVersion = "0.1.
|
|
10235
|
+
const currentVersion = "0.1.130";
|
|
9819
10236
|
process.stderr.write(
|
|
9820
10237
|
`
|
|
9821
10238
|
${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
|
|
@@ -9828,7 +10245,7 @@ function isStandaloneBinary() {
|
|
|
9828
10245
|
return !argv1.includes("node_modules");
|
|
9829
10246
|
}
|
|
9830
10247
|
async function cmdUpdate() {
|
|
9831
|
-
const currentVersion = "0.1.
|
|
10248
|
+
const currentVersion = "0.1.130";
|
|
9832
10249
|
process.stderr.write(
|
|
9833
10250
|
` ${ansi2.gray("Current version:")} ${currentVersion}
|
|
9834
10251
|
`
|
|
@@ -9918,9 +10335,13 @@ function printLogo() {
|
|
|
9918
10335
|
}
|
|
9919
10336
|
function openBrowser(url) {
|
|
9920
10337
|
try {
|
|
9921
|
-
if (process.platform === "darwin")
|
|
9922
|
-
|
|
9923
|
-
else
|
|
10338
|
+
if (process.platform === "darwin") {
|
|
10339
|
+
execSync(`open "${url}"`);
|
|
10340
|
+
} else if (process.platform === "win32") {
|
|
10341
|
+
execSync(`start "" "${url}"`);
|
|
10342
|
+
} else {
|
|
10343
|
+
execSync(`xdg-open "${url}"`);
|
|
10344
|
+
}
|
|
9924
10345
|
} catch {
|
|
9925
10346
|
}
|
|
9926
10347
|
}
|
|
@@ -9943,7 +10364,9 @@ function waitForKeypress() {
|
|
|
9943
10364
|
});
|
|
9944
10365
|
}
|
|
9945
10366
|
function maskKey(key) {
|
|
9946
|
-
if (key.length <= 8)
|
|
10367
|
+
if (key.length <= 8) {
|
|
10368
|
+
return "****";
|
|
10369
|
+
}
|
|
9947
10370
|
return key.slice(0, 4) + "..." + key.slice(-4);
|
|
9948
10371
|
}
|
|
9949
10372
|
var DEFAULT_BASE_URL3 = "https://v1.mindstudio-api.com";
|
|
@@ -9963,7 +10386,7 @@ async function cmdLogin(options) {
|
|
|
9963
10386
|
process.stderr.write("\n");
|
|
9964
10387
|
printLogo();
|
|
9965
10388
|
process.stderr.write("\n");
|
|
9966
|
-
const ver = "0.1.
|
|
10389
|
+
const ver = "0.1.130";
|
|
9967
10390
|
process.stderr.write(
|
|
9968
10391
|
` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
|
|
9969
10392
|
`
|
|
@@ -10110,7 +10533,9 @@ async function cmdWhoami(options) {
|
|
|
10110
10533
|
}
|
|
10111
10534
|
process.stderr.write(` ${ansi2.gray("Auth:")} ${source}
|
|
10112
10535
|
`);
|
|
10113
|
-
for (const line of detail)
|
|
10536
|
+
for (const line of detail) {
|
|
10537
|
+
process.stderr.write(line + "\n");
|
|
10538
|
+
}
|
|
10114
10539
|
process.stderr.write(` ${ansi2.gray("Verifying...")} `);
|
|
10115
10540
|
try {
|
|
10116
10541
|
const { MindStudioAgent: MindStudioAgent2 } = await init_client().then(() => client_exports);
|
|
@@ -10126,10 +10551,8 @@ async function cmdWhoami(options) {
|
|
|
10126
10551
|
);
|
|
10127
10552
|
process.stderr.write(` ${ansi2.bold("User")}
|
|
10128
10553
|
`);
|
|
10129
|
-
process.stderr.write(
|
|
10130
|
-
|
|
10131
|
-
`
|
|
10132
|
-
);
|
|
10554
|
+
process.stderr.write(` ${ansi2.gray("Name:")} ${info.displayName}
|
|
10555
|
+
`);
|
|
10133
10556
|
process.stderr.write(
|
|
10134
10557
|
` ${ansi2.gray("ID:")} ${ansi2.gray(info.userId)}
|
|
10135
10558
|
`
|
|
@@ -10137,10 +10560,8 @@ async function cmdWhoami(options) {
|
|
|
10137
10560
|
process.stderr.write(`
|
|
10138
10561
|
${ansi2.bold("Organization")}
|
|
10139
10562
|
`);
|
|
10140
|
-
process.stderr.write(
|
|
10141
|
-
|
|
10142
|
-
`
|
|
10143
|
-
);
|
|
10563
|
+
process.stderr.write(` ${ansi2.gray("Name:")} ${info.organizationName}
|
|
10564
|
+
`);
|
|
10144
10565
|
process.stderr.write(
|
|
10145
10566
|
` ${ansi2.gray("ID:")} ${ansi2.gray(info.organizationId)}
|
|
10146
10567
|
`
|
|
@@ -10153,10 +10574,7 @@ async function cmdWhoami(options) {
|
|
|
10153
10574
|
4,
|
|
10154
10575
|
...info.members.map((m) => m.displayName.length)
|
|
10155
10576
|
);
|
|
10156
|
-
const roleWidth = Math.max(
|
|
10157
|
-
4,
|
|
10158
|
-
...info.members.map((m) => m.role.length)
|
|
10159
|
-
);
|
|
10577
|
+
const roleWidth = Math.max(4, ...info.members.map((m) => m.role.length));
|
|
10160
10578
|
process.stderr.write(
|
|
10161
10579
|
` ${ansi2.gray("Name".padEnd(nameWidth))} ${ansi2.gray("Role".padEnd(roleWidth))} ${ansi2.gray("Type")}
|
|
10162
10580
|
`
|
|
@@ -10186,8 +10604,12 @@ function parseStepFlags(argv) {
|
|
|
10186
10604
|
const result = {};
|
|
10187
10605
|
for (let i = 0; i < argv.length; i++) {
|
|
10188
10606
|
const arg = argv[i];
|
|
10189
|
-
if (!arg.startsWith("--"))
|
|
10190
|
-
|
|
10607
|
+
if (!arg.startsWith("--")) {
|
|
10608
|
+
continue;
|
|
10609
|
+
}
|
|
10610
|
+
if (GLOBAL_BOOLEAN_FLAGS.has(arg)) {
|
|
10611
|
+
continue;
|
|
10612
|
+
}
|
|
10191
10613
|
if (GLOBAL_STRING_FLAGS.has(arg)) {
|
|
10192
10614
|
i++;
|
|
10193
10615
|
continue;
|
|
@@ -10221,7 +10643,9 @@ function findMethodSplit(argv) {
|
|
|
10221
10643
|
for (let i = 0; i < argv.length; i++) {
|
|
10222
10644
|
const arg = argv[i];
|
|
10223
10645
|
if (arg.startsWith("--")) {
|
|
10224
|
-
if (GLOBAL_STRING_FLAGS.has(arg))
|
|
10646
|
+
if (GLOBAL_STRING_FLAGS.has(arg)) {
|
|
10647
|
+
i++;
|
|
10648
|
+
}
|
|
10225
10649
|
continue;
|
|
10226
10650
|
}
|
|
10227
10651
|
if (arg === "run") {
|
|
@@ -10235,7 +10659,9 @@ function findMethodSplit(argv) {
|
|
|
10235
10659
|
for (let i = startIdx; i < argv.length; i++) {
|
|
10236
10660
|
const arg = argv[i];
|
|
10237
10661
|
if (arg.startsWith("--")) {
|
|
10238
|
-
if (GLOBAL_STRING_FLAGS.has(arg))
|
|
10662
|
+
if (GLOBAL_STRING_FLAGS.has(arg)) {
|
|
10663
|
+
i++;
|
|
10664
|
+
}
|
|
10239
10665
|
continue;
|
|
10240
10666
|
}
|
|
10241
10667
|
if (hasRun || i === startIdx) {
|
|
@@ -10289,9 +10715,7 @@ async function main() {
|
|
|
10289
10715
|
const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
|
|
10290
10716
|
try {
|
|
10291
10717
|
if (command === "version" || command === "-v") {
|
|
10292
|
-
process.stdout.write(
|
|
10293
|
-
"0.1.128\n"
|
|
10294
|
-
);
|
|
10718
|
+
process.stdout.write("0.1.130\n");
|
|
10295
10719
|
return;
|
|
10296
10720
|
}
|
|
10297
10721
|
if (command === "login") {
|
|
@@ -10415,7 +10839,7 @@ async function main() {
|
|
|
10415
10839
|
}
|
|
10416
10840
|
if (command === "run-agent") {
|
|
10417
10841
|
const appId = positionals[1];
|
|
10418
|
-
if (!appId)
|
|
10842
|
+
if (!appId) {
|
|
10419
10843
|
usageBlock([
|
|
10420
10844
|
"run-agent \u2014 Run a pre-built agent and wait for the result",
|
|
10421
10845
|
"",
|
|
@@ -10435,6 +10859,7 @@ async function main() {
|
|
|
10435
10859
|
"",
|
|
10436
10860
|
'Tip: run "mindstudio agents" to list available agent IDs.'
|
|
10437
10861
|
]);
|
|
10862
|
+
}
|
|
10438
10863
|
const runArgv = process.argv.slice(process.argv.indexOf("run-agent") + 2);
|
|
10439
10864
|
const stepArgs = [];
|
|
10440
10865
|
for (let i = 0; i < runArgv.length; i++) {
|
|
@@ -10482,7 +10907,7 @@ async function main() {
|
|
|
10482
10907
|
}
|
|
10483
10908
|
if (command === "upload" || command === "upload-file") {
|
|
10484
10909
|
const filePath = positionals[1];
|
|
10485
|
-
if (!filePath)
|
|
10910
|
+
if (!filePath) {
|
|
10486
10911
|
usageBlock([
|
|
10487
10912
|
"upload \u2014 Upload a file to the MindStudio CDN (alias: upload-file)",
|
|
10488
10913
|
"",
|
|
@@ -10497,6 +10922,7 @@ async function main() {
|
|
|
10497
10922
|
" mindstudio upload photo.png",
|
|
10498
10923
|
" mindstudio upload-file /path/to/document.pdf"
|
|
10499
10924
|
]);
|
|
10925
|
+
}
|
|
10500
10926
|
await cmdUpload(filePath, {
|
|
10501
10927
|
apiKey: values["api-key"],
|
|
10502
10928
|
baseUrl: values["base-url"]
|
|
@@ -10512,7 +10938,7 @@ async function main() {
|
|
|
10512
10938
|
let summary = false;
|
|
10513
10939
|
if (command === "list-models-by-type" || command === "list-models-summary-by-type") {
|
|
10514
10940
|
type = positionals[1];
|
|
10515
|
-
if (!type)
|
|
10941
|
+
if (!type) {
|
|
10516
10942
|
usageBlock([
|
|
10517
10943
|
`${command} \u2014 List AI models filtered by type`,
|
|
10518
10944
|
"",
|
|
@@ -10527,14 +10953,19 @@ async function main() {
|
|
|
10527
10953
|
` mindstudio ${command} image_generation`,
|
|
10528
10954
|
` mindstudio ${command} llm_chat`
|
|
10529
10955
|
]);
|
|
10956
|
+
}
|
|
10530
10957
|
}
|
|
10531
10958
|
if (command === "list-models-summary" || command === "list-models-summary-by-type") {
|
|
10532
10959
|
summary = true;
|
|
10533
10960
|
}
|
|
10534
10961
|
if (command === "list-models") {
|
|
10535
10962
|
const typeFlag = values.type;
|
|
10536
|
-
if (typeFlag)
|
|
10537
|
-
|
|
10963
|
+
if (typeFlag) {
|
|
10964
|
+
type = typeFlag;
|
|
10965
|
+
}
|
|
10966
|
+
if (values.summary) {
|
|
10967
|
+
summary = true;
|
|
10968
|
+
}
|
|
10538
10969
|
}
|
|
10539
10970
|
await cmdListModels({ ...authOpts, type, summary });
|
|
10540
10971
|
return;
|
|
@@ -10562,7 +10993,7 @@ async function main() {
|
|
|
10562
10993
|
}
|
|
10563
10994
|
if (command === "estimate-cost") {
|
|
10564
10995
|
const stepMethod = positionals[1];
|
|
10565
|
-
if (!stepMethod)
|
|
10996
|
+
if (!stepMethod) {
|
|
10566
10997
|
usageBlock([
|
|
10567
10998
|
"estimate-cost \u2014 Estimate the cost of an action before running it",
|
|
10568
10999
|
"",
|
|
@@ -10575,6 +11006,7 @@ async function main() {
|
|
|
10575
11006
|
"",
|
|
10576
11007
|
'Tip: run "mindstudio list-actions" to see available actions.'
|
|
10577
11008
|
]);
|
|
11009
|
+
}
|
|
10578
11010
|
const allKeys2 = await getAllMethodKeys();
|
|
10579
11011
|
const resolvedMethod = resolveMethodOrFail(stepMethod, allKeys2);
|
|
10580
11012
|
const { stepMetadata: stepMetadata2 } = await Promise.resolve().then(() => (init_metadata(), metadata_exports));
|
|
@@ -10599,7 +11031,7 @@ async function main() {
|
|
|
10599
11031
|
}
|
|
10600
11032
|
if (command === "change-name") {
|
|
10601
11033
|
const name = positionals[1];
|
|
10602
|
-
if (!name)
|
|
11034
|
+
if (!name) {
|
|
10603
11035
|
usageBlock([
|
|
10604
11036
|
"change-name \u2014 Update your display name",
|
|
10605
11037
|
"",
|
|
@@ -10609,6 +11041,7 @@ async function main() {
|
|
|
10609
11041
|
"Examples:",
|
|
10610
11042
|
' mindstudio change-name "My Agent"'
|
|
10611
11043
|
]);
|
|
11044
|
+
}
|
|
10612
11045
|
await cmdChangeName(name, {
|
|
10613
11046
|
apiKey: values["api-key"],
|
|
10614
11047
|
baseUrl: values["base-url"]
|
|
@@ -10617,7 +11050,7 @@ async function main() {
|
|
|
10617
11050
|
}
|
|
10618
11051
|
if (command === "change-profile-picture") {
|
|
10619
11052
|
const url = positionals[1];
|
|
10620
|
-
if (!url)
|
|
11053
|
+
if (!url) {
|
|
10621
11054
|
usageBlock([
|
|
10622
11055
|
"change-profile-picture \u2014 Update your profile picture",
|
|
10623
11056
|
"",
|
|
@@ -10629,6 +11062,7 @@ async function main() {
|
|
|
10629
11062
|
"",
|
|
10630
11063
|
'Tip: use "mindstudio upload" to host an image first.'
|
|
10631
11064
|
]);
|
|
11065
|
+
}
|
|
10632
11066
|
await cmdChangeProfilePicture(url, {
|
|
10633
11067
|
apiKey: values["api-key"],
|
|
10634
11068
|
baseUrl: values["base-url"]
|
|
@@ -10645,7 +11079,7 @@ async function main() {
|
|
|
10645
11079
|
}
|
|
10646
11080
|
if (command === "info") {
|
|
10647
11081
|
const rawMethod2 = positionals[1];
|
|
10648
|
-
if (!rawMethod2)
|
|
11082
|
+
if (!rawMethod2) {
|
|
10649
11083
|
usageBlock([
|
|
10650
11084
|
"info \u2014 Show action details and parameters",
|
|
10651
11085
|
"",
|
|
@@ -10661,11 +11095,12 @@ async function main() {
|
|
|
10661
11095
|
"",
|
|
10662
11096
|
'Tip: run "mindstudio list-actions" to see available actions.'
|
|
10663
11097
|
]);
|
|
11098
|
+
}
|
|
10664
11099
|
await cmdInfo(rawMethod2);
|
|
10665
11100
|
return;
|
|
10666
11101
|
}
|
|
10667
11102
|
const split = findMethodSplit(process.argv.slice(2));
|
|
10668
|
-
if (!split)
|
|
11103
|
+
if (!split) {
|
|
10669
11104
|
usageBlock([
|
|
10670
11105
|
"Run an action directly",
|
|
10671
11106
|
"",
|
|
@@ -10688,6 +11123,7 @@ async function main() {
|
|
|
10688
11123
|
"",
|
|
10689
11124
|
'Tip: run "mindstudio list-actions" to see available actions.'
|
|
10690
11125
|
]);
|
|
11126
|
+
}
|
|
10691
11127
|
const { rawMethod, stepArgv } = split;
|
|
10692
11128
|
const allKeys = await getAllMethodKeys();
|
|
10693
11129
|
const method = resolveMethodOrFail(rawMethod, allKeys);
|
|
@@ -10728,7 +11164,9 @@ async function main() {
|
|
|
10728
11164
|
fatal(message);
|
|
10729
11165
|
} finally {
|
|
10730
11166
|
const latestVersion = await updatePromise;
|
|
10731
|
-
if (latestVersion)
|
|
11167
|
+
if (latestVersion) {
|
|
11168
|
+
printUpdateNotice(latestVersion);
|
|
11169
|
+
}
|
|
10732
11170
|
}
|
|
10733
11171
|
}
|
|
10734
11172
|
main();
|