@engini/cli 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/cli.js +1096 -188
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -384,7 +384,10 @@ import {
|
|
|
384
384
|
ENV_TOKEN_VAR,
|
|
385
385
|
EnginiAuthError,
|
|
386
386
|
EnginiError,
|
|
387
|
+
EnginiMcpServerNotFoundError,
|
|
387
388
|
EnginiNotFoundError,
|
|
389
|
+
EnginiOpaAgentTimeoutError,
|
|
390
|
+
EnginiOpaApplicationAmbiguousError,
|
|
388
391
|
EnginiTimeoutError,
|
|
389
392
|
EnginiToolsetNotFoundError,
|
|
390
393
|
EnginiValidationError
|
|
@@ -438,7 +441,7 @@ function saveConfig(config, path = configPath()) {
|
|
|
438
441
|
}
|
|
439
442
|
|
|
440
443
|
// src/version.ts
|
|
441
|
-
var VERSION = true ? "0.
|
|
444
|
+
var VERSION = true ? "0.19.0" : "0.0.0";
|
|
442
445
|
|
|
443
446
|
// src/http.ts
|
|
444
447
|
var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
|
|
@@ -462,7 +465,10 @@ function buildClient(overrides = {}) {
|
|
|
462
465
|
}
|
|
463
466
|
function exitForError(err) {
|
|
464
467
|
if (err instanceof EnginiAuthError) return 3 /* AUTH */;
|
|
468
|
+
if (err instanceof EnginiOpaApplicationAmbiguousError) return 5 /* VALIDATION */;
|
|
469
|
+
if (err instanceof EnginiOpaAgentTimeoutError) return 124 /* TIMEOUT */;
|
|
465
470
|
if (err instanceof EnginiToolsetNotFoundError) return 4 /* NOT_FOUND */;
|
|
471
|
+
if (err instanceof EnginiMcpServerNotFoundError) return 4 /* NOT_FOUND */;
|
|
466
472
|
if (err instanceof EnginiNotFoundError) return 4 /* NOT_FOUND */;
|
|
467
473
|
if (err instanceof EnginiValidationError) return 5 /* VALIDATION */;
|
|
468
474
|
if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
|
|
@@ -1532,8 +1538,9 @@ CONNECTIONS
|
|
|
1532
1538
|
--connection <id> (object selection). No app \u2192 web page.
|
|
1533
1539
|
connections list [--application <slug>] [--kind <kind>]
|
|
1534
1540
|
List your connections. --kind filters on
|
|
1535
|
-
Regular | Key |
|
|
1536
|
-
"Keys" tab is --kind Key.
|
|
1541
|
+
Regular | Key | MCPClient. The web UI's
|
|
1542
|
+
"Keys" tab is --kind Key. On-premise agents are
|
|
1543
|
+
not connections - see ON-PREMISE AGENTS.
|
|
1537
1544
|
connections get <id> Inspect a connection.
|
|
1538
1545
|
connections create <app> --auth <id> --name <n> --field k=v
|
|
1539
1546
|
Create a direct-credential connection.
|
|
@@ -1565,6 +1572,45 @@ TOOLSETS
|
|
|
1565
1572
|
unchanged. --dry-run previews the diff before you commit to it.
|
|
1566
1573
|
toolsets delete <id> [--force] Remove a toolset.
|
|
1567
1574
|
|
|
1575
|
+
MCP SERVERS
|
|
1576
|
+
The MCP endpoints Engini *exposes*, carrying a chosen set of tools and workflows.
|
|
1577
|
+
Not the MCPClient connection kind, which is Engini *consuming* someone else's MCP
|
|
1578
|
+
server. Servers are account-wide, and are created/deleted in the engini.io UI \u2014
|
|
1579
|
+
this group inspects and configures them.
|
|
1580
|
+
mcp list List the account's MCP servers.
|
|
1581
|
+
mcp get <token> Show full detail for one MCP server.
|
|
1582
|
+
mcp activate <token> Turn a server on.
|
|
1583
|
+
mcp deactivate <token> Turn a server off (reversible; it stays listed).
|
|
1584
|
+
mcp connections add <token> --connection <id>[:slugs]
|
|
1585
|
+
Expose a connection (existing ones are kept).
|
|
1586
|
+
mcp connections rm <token> --connection-id <id>
|
|
1587
|
+
Stop exposing a connection.
|
|
1588
|
+
mcp tools list <token> --connection-id <id> List a connection's available tools.
|
|
1589
|
+
mcp tools set <token> --connection-id <id> (--tool <slug> ... | --all)
|
|
1590
|
+
Replace one connection's tool allow-list.
|
|
1591
|
+
mcp workflows add <token> --workflow <workflow_token> [--tool-name <n>] [--tool-description <t>]
|
|
1592
|
+
Expose a workflow as a tool.
|
|
1593
|
+
mcp workflows rm <token> --workflow <workflow_token>
|
|
1594
|
+
Stop exposing a workflow.
|
|
1595
|
+
Note: the server token is part of the server's SSE URL \u2014 treat it as a secret.
|
|
1596
|
+
--dry-run previews every mutating command's resulting set before you commit to it.
|
|
1597
|
+
|
|
1598
|
+
ON-PREMISE AGENTS
|
|
1599
|
+
The Engini component a customer installs behind their firewall to reach SQL Server,
|
|
1600
|
+
Oracle, Priority ERP and file shares. Not connections: connections list never shows them.
|
|
1601
|
+
opa list [--status <s>] [--name <substr>] List the account's on-premise agents.
|
|
1602
|
+
opa get <id> Status, version, last heartbeat, settings.
|
|
1603
|
+
opa create --name <n> [...] Register an agent. PRINTS ITS TOKEN.
|
|
1604
|
+
opa update <id> [...] Change name/description/settings (merges).
|
|
1605
|
+
opa delete <id> [--force] Permanently delete an agent.
|
|
1606
|
+
opa enable <id> | opa disable <id> Toggle whether the agent is marked online.
|
|
1607
|
+
opa token get <id> Read the agent's token (a credential).
|
|
1608
|
+
opa token rotate <id> [--force] New token; the running agent stops until reconfigured.
|
|
1609
|
+
opa logs <id> -o <file> Collect the agent's logs as a zip (agent must be Online).
|
|
1610
|
+
opa download [-o <file>] [--json] Fetch the current installer; --json prints the manifest.
|
|
1611
|
+
Note: an agent polls Engini, so anything that "talks to" it waits for its next poll.
|
|
1612
|
+
A settings update on an offline agent still stores - the response says applied_to_agent: false.
|
|
1613
|
+
|
|
1568
1614
|
OUTPUT & EXIT CODES
|
|
1569
1615
|
Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
|
|
1570
1616
|
JSON with --json. Universal flags on every command:
|
|
@@ -1741,103 +1787,1051 @@ async function askForKey(url) {
|
|
|
1741
1787
|
console.log("");
|
|
1742
1788
|
}
|
|
1743
1789
|
}
|
|
1744
|
-
async function loginBody(opts) {
|
|
1745
|
-
const config = loadConfig();
|
|
1746
|
-
const hadCredentials = Boolean(config.api_key || config.api_token);
|
|
1747
|
-
if (opts.apiUrl) config.api_url = opts.apiUrl;
|
|
1748
|
-
if (opts.identityUrl) config.identity_url = opts.identityUrl;
|
|
1749
|
-
let apiKey = opts.apiKey?.trim();
|
|
1750
|
-
if (opts.apiKey !== void 0) {
|
|
1751
|
-
const problem = keyProblem(apiKey ?? "");
|
|
1752
|
-
if (problem) {
|
|
1753
|
-
fail(
|
|
1754
|
-
2 /* USAGE */,
|
|
1755
|
-
`--api-key ${apiKey ? "is not a valid Engini key" : "was empty"}. ${problem}`,
|
|
1756
|
-
"Pass the key value: engini login --api-key eng_\u2026"
|
|
1757
|
-
);
|
|
1758
|
-
}
|
|
1790
|
+
async function loginBody(opts) {
|
|
1791
|
+
const config = loadConfig();
|
|
1792
|
+
const hadCredentials = Boolean(config.api_key || config.api_token);
|
|
1793
|
+
if (opts.apiUrl) config.api_url = opts.apiUrl;
|
|
1794
|
+
if (opts.identityUrl) config.identity_url = opts.identityUrl;
|
|
1795
|
+
let apiKey = opts.apiKey?.trim();
|
|
1796
|
+
if (opts.apiKey !== void 0) {
|
|
1797
|
+
const problem = keyProblem(apiKey ?? "");
|
|
1798
|
+
if (problem) {
|
|
1799
|
+
fail(
|
|
1800
|
+
2 /* USAGE */,
|
|
1801
|
+
`--api-key ${apiKey ? "is not a valid Engini key" : "was empty"}. ${problem}`,
|
|
1802
|
+
"Pass the key value: engini login --api-key eng_\u2026"
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
if (!apiKey) {
|
|
1807
|
+
if (!isInteractive()) {
|
|
1808
|
+
fail(
|
|
1809
|
+
2 /* USAGE */,
|
|
1810
|
+
"Provide --api-key when running non-interactively.",
|
|
1811
|
+
"Interactive login needs a terminal on both stdin and stdout."
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
const url = keysUrl(config);
|
|
1815
|
+
let hasKey;
|
|
1816
|
+
try {
|
|
1817
|
+
hasKey = await confirm("Do you already have an Engini API key?");
|
|
1818
|
+
} catch (err) {
|
|
1819
|
+
if (err instanceof PromptStreamEnded) {
|
|
1820
|
+
fail(
|
|
1821
|
+
2 /* USAGE */,
|
|
1822
|
+
"Input ended before the question was answered.",
|
|
1823
|
+
"Pass the key directly instead: engini login --api-key eng_\u2026"
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
throw err;
|
|
1827
|
+
}
|
|
1828
|
+
if (!hasKey) {
|
|
1829
|
+
console.log(`Opening ${url} \u2014 create a key there, then paste it below.`);
|
|
1830
|
+
openBrowser(url);
|
|
1831
|
+
}
|
|
1832
|
+
apiKey = await askForKey(url);
|
|
1833
|
+
}
|
|
1834
|
+
config.api_key = apiKey;
|
|
1835
|
+
config.auth_kind = "api-key";
|
|
1836
|
+
const summary6 = {
|
|
1837
|
+
auth_kind: "api-key",
|
|
1838
|
+
credential: maskSecret(apiKey),
|
|
1839
|
+
api_url: config.api_url
|
|
1840
|
+
};
|
|
1841
|
+
if (dryRun()) {
|
|
1842
|
+
printOutput({ would_store: summary6 });
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
if (hadCredentials) {
|
|
1846
|
+
await confirmOrFail("Credentials already exist. Overwrite?", { force: Boolean(opts.force) });
|
|
1847
|
+
}
|
|
1848
|
+
saveConfig(config);
|
|
1849
|
+
printOutput({ stored: summary6 });
|
|
1850
|
+
}
|
|
1851
|
+
function registerLogin(program) {
|
|
1852
|
+
const cmd = program.command("login").description("Store an opaque Engini API key.").option("--api-key <key>", "Opaque Engini key (eng_\u2026)").option("--api-url <url>", "API base URL to persist (e.g. a staging host)").option("--identity-url <url>", "Dashboard base URL to persist (hosts the keys page)").option("--force", "Overwrite existing credentials without confirming");
|
|
1853
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1854
|
+
cmd.action(async (opts, command) => {
|
|
1855
|
+
await runCommand(command, opts, true, () => loginBody(opts));
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// src/logout.ts
|
|
1860
|
+
function logoutBody() {
|
|
1861
|
+
const config = loadConfig();
|
|
1862
|
+
if (!(config.api_key || config.api_token)) {
|
|
1863
|
+
printOutput({ logged_out: false, noop: true });
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
if (dryRun()) {
|
|
1867
|
+
printOutput({ would_logout: true });
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
config.api_key = void 0;
|
|
1871
|
+
config.api_token = void 0;
|
|
1872
|
+
config.company_token = void 0;
|
|
1873
|
+
config.auth_kind = void 0;
|
|
1874
|
+
saveConfig(config);
|
|
1875
|
+
printOutput({ logged_out: true });
|
|
1876
|
+
}
|
|
1877
|
+
function registerLogout(program) {
|
|
1878
|
+
const cmd = program.command("logout").description("Clear the stored credentials.");
|
|
1879
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1880
|
+
cmd.action(async (opts, command) => {
|
|
1881
|
+
await runCommand(command, opts, true, logoutBody);
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
// src/shared/connections.ts
|
|
1886
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
1887
|
+
function collect2(value, previous = []) {
|
|
1888
|
+
return [...previous, value];
|
|
1889
|
+
}
|
|
1890
|
+
function splitSlugs(spec) {
|
|
1891
|
+
const colon = spec.indexOf(":");
|
|
1892
|
+
if (colon < 0) return [spec, void 0];
|
|
1893
|
+
const head = spec.slice(0, colon);
|
|
1894
|
+
const slugs = spec.slice(colon + 1).split(",").map((s) => s.trim()).filter(Boolean);
|
|
1895
|
+
return [head, slugs.length > 0 ? slugs : void 0];
|
|
1896
|
+
}
|
|
1897
|
+
function loadFromFile(spec) {
|
|
1898
|
+
let text;
|
|
1899
|
+
if (spec === "-") {
|
|
1900
|
+
text = readFileSync2(0, "utf8");
|
|
1901
|
+
} else if (spec.startsWith("@")) {
|
|
1902
|
+
try {
|
|
1903
|
+
text = readFileSync2(spec.slice(1), "utf8");
|
|
1904
|
+
} catch (err) {
|
|
1905
|
+
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
1906
|
+
}
|
|
1907
|
+
} else {
|
|
1908
|
+
text = spec;
|
|
1909
|
+
}
|
|
1910
|
+
let data;
|
|
1911
|
+
try {
|
|
1912
|
+
data = JSON.parse(text);
|
|
1913
|
+
} catch (err) {
|
|
1914
|
+
return fail(2 /* USAGE */, `--from-file is not valid JSON: ${err.message}`);
|
|
1915
|
+
}
|
|
1916
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
1917
|
+
return fail(2 /* USAGE */, "--from-file must be a JSON object.");
|
|
1918
|
+
}
|
|
1919
|
+
return data;
|
|
1920
|
+
}
|
|
1921
|
+
function summarizeConnectionDto(c) {
|
|
1922
|
+
return {
|
|
1923
|
+
connection_id: c.connectionId,
|
|
1924
|
+
application_slug: c.applicationSlug,
|
|
1925
|
+
application_name: clean(c.applicationName),
|
|
1926
|
+
tool_slugs: c.toolSlugs
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
function summarizeConnectionRequest(c) {
|
|
1930
|
+
return {
|
|
1931
|
+
connection_id: c.connectionId ?? null,
|
|
1932
|
+
application_slug: c.applicationSlug ?? null,
|
|
1933
|
+
tool_slugs: c.toolSlugs ?? []
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
function connectionKey(c) {
|
|
1937
|
+
return c.connectionId != null ? `id:${c.connectionId}` : `app:${c.applicationSlug}`;
|
|
1938
|
+
}
|
|
1939
|
+
function scopeKey(c) {
|
|
1940
|
+
const slugs = c.toolSlugs ?? [];
|
|
1941
|
+
return slugs.length === 0 ? "*" : [...slugs].sort().join(",");
|
|
1942
|
+
}
|
|
1943
|
+
function diffConnections(current, next) {
|
|
1944
|
+
const currentKeys = new Set(current.map((c) => connectionKey(c)));
|
|
1945
|
+
const nextByKey = new Map(next.map((c) => [connectionKey(c), c]));
|
|
1946
|
+
const nextKeys = new Set(nextByKey.keys());
|
|
1947
|
+
const changed = current.filter((c) => nextKeys.has(connectionKey(c))).filter((c) => scopeKey(c) !== scopeKey(nextByKey.get(connectionKey(c)))).map((c) => {
|
|
1948
|
+
const nextEntry = nextByKey.get(connectionKey(c));
|
|
1949
|
+
return {
|
|
1950
|
+
connection_id: c.connectionId,
|
|
1951
|
+
application_slug: c.applicationSlug,
|
|
1952
|
+
from: summarizeConnectionDto(c),
|
|
1953
|
+
// A bare next-side entry carries no applicationSlug (it is resolved from
|
|
1954
|
+
// the id), but it is still the same connection — falling back to the
|
|
1955
|
+
// known slug avoids a null that reads as "the slug is being cleared".
|
|
1956
|
+
to: {
|
|
1957
|
+
...summarizeConnectionRequest(nextEntry),
|
|
1958
|
+
application_slug: nextEntry.applicationSlug ?? c.applicationSlug
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
});
|
|
1962
|
+
return {
|
|
1963
|
+
current: current.map(summarizeConnectionDto),
|
|
1964
|
+
resulting: next.map(summarizeConnectionRequest),
|
|
1965
|
+
added: next.filter((c) => !currentKeys.has(connectionKey(c))).map(summarizeConnectionRequest),
|
|
1966
|
+
removed: current.filter((c) => !nextKeys.has(connectionKey(c))).map(summarizeConnectionDto),
|
|
1967
|
+
changed
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
function diffWorkflows(current, next) {
|
|
1971
|
+
const currentSet = new Set(current);
|
|
1972
|
+
const nextSet = new Set(next);
|
|
1973
|
+
return {
|
|
1974
|
+
current,
|
|
1975
|
+
resulting: next,
|
|
1976
|
+
added: next.filter((id) => !currentSet.has(id)),
|
|
1977
|
+
removed: current.filter((id) => !nextSet.has(id))
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
// src/mcp/shared.ts
|
|
1982
|
+
function parseMcpServerToken(value) {
|
|
1983
|
+
if (!value) fail(2 /* USAGE */, "Missing required argument 'mcp_server_token'.");
|
|
1984
|
+
return value;
|
|
1985
|
+
}
|
|
1986
|
+
function parseMcpConnectionFlags(specs) {
|
|
1987
|
+
return (specs ?? []).map((spec) => {
|
|
1988
|
+
const [idPart, toolSlugs] = splitSlugs(spec);
|
|
1989
|
+
if (!/^\d+$/.test(idPart)) {
|
|
1990
|
+
fail(2 /* USAGE */, `--connection must be <id> or <id>:slug,slug, got '${spec}'.`);
|
|
1991
|
+
}
|
|
1992
|
+
return { connectionId: Number(idPart), toolSlugs };
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
function parseConnectionIds(specs) {
|
|
1996
|
+
return (specs ?? []).map((spec) => {
|
|
1997
|
+
if (!/^\d+$/.test(spec)) {
|
|
1998
|
+
fail(2 /* USAGE */, `--connection-id must be a positive integer, got '${spec}'.`);
|
|
1999
|
+
}
|
|
2000
|
+
return Number(spec);
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
function connectionsToRequests(current) {
|
|
2004
|
+
return current.map((c) => ({
|
|
2005
|
+
connectionId: c.connectionId,
|
|
2006
|
+
toolSlugs: c.toolSlugs.length > 0 ? c.toolSlugs : void 0
|
|
2007
|
+
}));
|
|
2008
|
+
}
|
|
2009
|
+
function workflowsToRequests(current) {
|
|
2010
|
+
return current.map((w) => ({
|
|
2011
|
+
workflowToken: w.workflowToken,
|
|
2012
|
+
toolName: w.toolName ?? void 0,
|
|
2013
|
+
toolDescription: w.toolDescription ?? void 0
|
|
2014
|
+
}));
|
|
2015
|
+
}
|
|
2016
|
+
function upsertConnections(existing, incoming) {
|
|
2017
|
+
const byId = new Map(existing.map((c) => [c.connectionId, c]));
|
|
2018
|
+
for (const entry of incoming) byId.set(entry.connectionId, entry);
|
|
2019
|
+
return [...byId.values()];
|
|
2020
|
+
}
|
|
2021
|
+
function upsertWorkflows(existing, incoming) {
|
|
2022
|
+
const byToken = new Map(existing.map((w) => [w.workflowToken, w]));
|
|
2023
|
+
for (const entry of incoming) byToken.set(entry.workflowToken, entry);
|
|
2024
|
+
return [...byToken.values()];
|
|
2025
|
+
}
|
|
2026
|
+
function summarizeWorkflow(w) {
|
|
2027
|
+
return {
|
|
2028
|
+
workflow_token: w.workflowToken,
|
|
2029
|
+
workflow_name: clean(w.workflowName),
|
|
2030
|
+
tool_name: clean(w.toolName),
|
|
2031
|
+
tool_description: clean(w.toolDescription)
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
function summarizeMcpConnection(c) {
|
|
2035
|
+
return {
|
|
2036
|
+
...summarizeConnectionDto(c),
|
|
2037
|
+
available_tools_count: c.availableToolsCount,
|
|
2038
|
+
selected_tools_count: c.selectedToolsCount
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
function summarizeMcpServer(s) {
|
|
2042
|
+
return {
|
|
2043
|
+
mcp_server_token: s.mcpServerToken,
|
|
2044
|
+
name: s.name,
|
|
2045
|
+
is_active: s.isActive,
|
|
2046
|
+
is_anonymous_allowed: s.isAnonymousAllowed,
|
|
2047
|
+
connections: s.connections.map(summarizeMcpConnection),
|
|
2048
|
+
workflows: s.workflows.map(summarizeWorkflow),
|
|
2049
|
+
created_date: s.createdDate
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
// src/mcp/connections.ts
|
|
2054
|
+
async function applyConnections(mcpServerToken, next) {
|
|
2055
|
+
const client = buildClient();
|
|
2056
|
+
const current = await apiErrors(async () => client.mcp.get(mcpServerToken));
|
|
2057
|
+
const connections = next(current);
|
|
2058
|
+
if (dryRun()) {
|
|
2059
|
+
printOutput({
|
|
2060
|
+
would_update: {
|
|
2061
|
+
mcp_server_token: mcpServerToken,
|
|
2062
|
+
connections: diffConnections(current.connections, connections)
|
|
2063
|
+
}
|
|
2064
|
+
});
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
const updated = await apiErrors(async () => client.mcp.update(mcpServerToken, { connections }));
|
|
2068
|
+
printOutput(summarizeMcpServer(updated));
|
|
2069
|
+
}
|
|
2070
|
+
function registerAdd(connections) {
|
|
2071
|
+
const cmd = connections.command("add").description(
|
|
2072
|
+
"Add or re-scope connections on an MCP server. Existing connections are preserved; an entry with the same connection id is replaced."
|
|
2073
|
+
).argument("[mcp_server_token]", "MCP server token").option(
|
|
2074
|
+
"--connection <id[:slug,slug]>",
|
|
2075
|
+
"Connection to expose (repeatable); bare id = all its tools",
|
|
2076
|
+
collect2
|
|
2077
|
+
);
|
|
2078
|
+
cmd.addHelpText(
|
|
2079
|
+
"after",
|
|
2080
|
+
"\nExamples:\n engini mcp connections add <token> --connection 2139\n engini mcp connections add <token> --connection 2139:gmail_send_mail --dry-run"
|
|
2081
|
+
);
|
|
2082
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2083
|
+
cmd.action(
|
|
2084
|
+
async (token, opts, command) => {
|
|
2085
|
+
await runCommand(command, opts, true, async () => {
|
|
2086
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2087
|
+
if (!opts.connection?.length) {
|
|
2088
|
+
fail(2 /* USAGE */, "Nothing to add \u2014 pass at least one --connection.");
|
|
2089
|
+
}
|
|
2090
|
+
const incoming = parseMcpConnectionFlags(opts.connection);
|
|
2091
|
+
await applyConnections(
|
|
2092
|
+
mcpServerToken,
|
|
2093
|
+
(current) => upsertConnections(connectionsToRequests(current.connections), incoming)
|
|
2094
|
+
);
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
);
|
|
2098
|
+
}
|
|
2099
|
+
function registerRm(connections) {
|
|
2100
|
+
const cmd = connections.command("rm").description("Remove connections from an MCP server, leaving the rest in place.").argument("[mcp_server_token]", "MCP server token").option("--connection-id <id>", "Connection id to remove (repeatable)", collect2);
|
|
2101
|
+
cmd.addHelpText(
|
|
2102
|
+
"after",
|
|
2103
|
+
"\nExamples:\n engini mcp connections rm <token> --connection-id 2139\n engini mcp connections rm <token> --connection-id 2139 --dry-run"
|
|
2104
|
+
);
|
|
2105
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2106
|
+
cmd.action(
|
|
2107
|
+
async (token, opts, command) => {
|
|
2108
|
+
await runCommand(command, opts, true, async () => {
|
|
2109
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2110
|
+
if (!opts.connectionId?.length) {
|
|
2111
|
+
fail(2 /* USAGE */, "Nothing to remove \u2014 pass at least one --connection-id.");
|
|
2112
|
+
}
|
|
2113
|
+
const removing = new Set(parseConnectionIds(opts.connectionId));
|
|
2114
|
+
await applyConnections(mcpServerToken, (current) => {
|
|
2115
|
+
const present = new Set(current.connections.map((c) => c.connectionId));
|
|
2116
|
+
for (const id of removing) {
|
|
2117
|
+
if (!present.has(id)) {
|
|
2118
|
+
fail(4 /* NOT_FOUND */, `Connection ${id} is not on this MCP server.`);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
return connectionsToRequests(
|
|
2122
|
+
current.connections.filter((c) => !removing.has(c.connectionId))
|
|
2123
|
+
);
|
|
2124
|
+
});
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
function registerMcpConnections(mcp) {
|
|
2130
|
+
const connections = mcp.command("connections").description("Add or remove the connections an MCP server exposes.");
|
|
2131
|
+
registerAdd(connections);
|
|
2132
|
+
registerRm(connections);
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
// src/mcp/get.ts
|
|
2136
|
+
async function getBody3(token) {
|
|
2137
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2138
|
+
const server = await apiErrors(async () => {
|
|
2139
|
+
const client = buildClient();
|
|
2140
|
+
return client.mcp.get(mcpServerToken);
|
|
2141
|
+
});
|
|
2142
|
+
printOutput({
|
|
2143
|
+
...summarizeMcpServer(server),
|
|
2144
|
+
url: clean(server.url),
|
|
2145
|
+
updated_date: clean(server.updatedDate),
|
|
2146
|
+
created_by_account_user_id: clean(server.createdByAccountUserId),
|
|
2147
|
+
updated_by_account_user_id: clean(server.updatedByAccountUserId)
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
function registerMcpGet(mcp) {
|
|
2151
|
+
const cmd = mcp.command("get").description("Show full detail for one MCP server.").argument("[mcp_server_token]", "MCP server token");
|
|
2152
|
+
cmd.addHelpText("after", "\nExamples:\n engini mcp get <mcp_server_token> --json");
|
|
2153
|
+
addUniversalOptions(cmd);
|
|
2154
|
+
cmd.action(async (token, opts, command) => {
|
|
2155
|
+
await runCommand(command, opts, false, () => getBody3(token));
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
// src/mcp/list.ts
|
|
2160
|
+
async function listBody4() {
|
|
2161
|
+
const servers = await apiErrors(async () => {
|
|
2162
|
+
const client = buildClient();
|
|
2163
|
+
return client.mcp.list();
|
|
2164
|
+
});
|
|
2165
|
+
printOutput(servers.map(summarizeMcpServer));
|
|
2166
|
+
}
|
|
2167
|
+
function registerMcpList(mcp) {
|
|
2168
|
+
const cmd = mcp.command("list").description("List the account's MCP servers.");
|
|
2169
|
+
cmd.addHelpText(
|
|
2170
|
+
"after",
|
|
2171
|
+
"\nExamples:\n engini mcp list --json\n engini mcp list --json | jq -r '.[] | select(.is_active == false) | .name'"
|
|
2172
|
+
);
|
|
2173
|
+
addUniversalOptions(cmd);
|
|
2174
|
+
cmd.action(async (opts, command) => {
|
|
2175
|
+
await runCommand(command, opts, false, () => listBody4());
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
// src/mcp/status.ts
|
|
2180
|
+
async function setActiveBody(token, isActive) {
|
|
2181
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2182
|
+
if (dryRun()) {
|
|
2183
|
+
printOutput({ would_update: { mcp_server_token: mcpServerToken, is_active: isActive } });
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
const server = await apiErrors(async () => {
|
|
2187
|
+
const client = buildClient();
|
|
2188
|
+
return isActive ? client.mcp.activate(mcpServerToken) : client.mcp.deactivate(mcpServerToken);
|
|
2189
|
+
});
|
|
2190
|
+
printOutput(summarizeMcpServer(server));
|
|
2191
|
+
}
|
|
2192
|
+
function register(mcp, name, description, isActive) {
|
|
2193
|
+
const cmd = mcp.command(name).description(description).argument("[mcp_server_token]", "MCP server token");
|
|
2194
|
+
cmd.addHelpText("after", `
|
|
2195
|
+
Examples:
|
|
2196
|
+
engini mcp ${name} <mcp_server_token>`);
|
|
2197
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2198
|
+
cmd.action(async (token, opts, command) => {
|
|
2199
|
+
await runCommand(command, opts, true, () => setActiveBody(token, isActive));
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
function registerMcpStatus(mcp) {
|
|
2203
|
+
register(mcp, "activate", "Turn an MCP server on.", true);
|
|
2204
|
+
register(
|
|
2205
|
+
mcp,
|
|
2206
|
+
"deactivate",
|
|
2207
|
+
"Turn an MCP server off. Reversible \u2014 the server stays listed and can be reactivated.",
|
|
2208
|
+
false
|
|
2209
|
+
);
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// src/mcp/tools.ts
|
|
2213
|
+
async function listBody5(token, connectionIdRaw) {
|
|
2214
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2215
|
+
if (!connectionIdRaw) fail(2 /* USAGE */, "Missing required option '--connection-id'.");
|
|
2216
|
+
const [connectionId] = parseConnectionIds([connectionIdRaw]);
|
|
2217
|
+
const tools = await apiErrors(async () => {
|
|
2218
|
+
const client = buildClient();
|
|
2219
|
+
return client.mcp.availableTools(mcpServerToken, connectionId);
|
|
2220
|
+
});
|
|
2221
|
+
printOutput(
|
|
2222
|
+
tools.map((t) => ({
|
|
2223
|
+
tool_name: t.toolName,
|
|
2224
|
+
description: t.description ?? null,
|
|
2225
|
+
is_mandatory: t.isMandatory
|
|
2226
|
+
}))
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
async function setBody2(token, opts) {
|
|
2230
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2231
|
+
if (!opts.connectionId) fail(2 /* USAGE */, "Missing required option '--connection-id'.");
|
|
2232
|
+
const [connectionId] = parseConnectionIds([opts.connectionId]);
|
|
2233
|
+
const selected = opts.tool ?? [];
|
|
2234
|
+
if (opts.all && selected.length > 0) {
|
|
2235
|
+
fail(2 /* USAGE */, "--all cannot be combined with --tool.");
|
|
2236
|
+
}
|
|
2237
|
+
if (!opts.all && selected.length === 0) {
|
|
2238
|
+
fail(2 /* USAGE */, "Pass --tool <slug> (repeatable) to select tools, or --all to expose them all.");
|
|
2239
|
+
}
|
|
2240
|
+
const client = buildClient();
|
|
2241
|
+
const current = await apiErrors(async () => client.mcp.get(mcpServerToken));
|
|
2242
|
+
if (!current.connections.some((c) => c.connectionId === connectionId)) {
|
|
2243
|
+
fail(
|
|
2244
|
+
4 /* NOT_FOUND */,
|
|
2245
|
+
`Connection ${connectionId} is not on this MCP server \u2014 add it first with \`engini mcp connections add\`.`
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
const connections = upsertConnections(connectionsToRequests(current.connections), [
|
|
2249
|
+
{ connectionId, toolSlugs: opts.all ? void 0 : selected }
|
|
2250
|
+
]);
|
|
2251
|
+
if (dryRun()) {
|
|
2252
|
+
printOutput({
|
|
2253
|
+
would_update: {
|
|
2254
|
+
mcp_server_token: mcpServerToken,
|
|
2255
|
+
connections: diffConnections(current.connections, connections)
|
|
2256
|
+
}
|
|
2257
|
+
});
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
2260
|
+
const updated = await apiErrors(async () => client.mcp.update(mcpServerToken, { connections }));
|
|
2261
|
+
printOutput(summarizeMcpServer(updated));
|
|
2262
|
+
}
|
|
2263
|
+
function registerMcpTools(mcp) {
|
|
2264
|
+
const tools = mcp.command("tools").description("Inspect and choose the tools an MCP server's connections expose.");
|
|
2265
|
+
const list = tools.command("list").description("List the tools a connection makes available to this MCP server.").argument("[mcp_server_token]", "MCP server token").option("--connection-id <id>", "Connection whose available tools to list");
|
|
2266
|
+
list.addHelpText(
|
|
2267
|
+
"after",
|
|
2268
|
+
"\nExamples:\n engini mcp tools list <token> --connection-id 2139 --json"
|
|
2269
|
+
);
|
|
2270
|
+
addUniversalOptions(list);
|
|
2271
|
+
list.action(
|
|
2272
|
+
async (token, opts, command) => {
|
|
2273
|
+
await runCommand(
|
|
2274
|
+
command,
|
|
2275
|
+
opts,
|
|
2276
|
+
false,
|
|
2277
|
+
() => listBody5(token, opts.connectionId)
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
);
|
|
2281
|
+
const set = tools.command("set").description(
|
|
2282
|
+
"Replace the tool allow-list for one connection on an MCP server. Other connections are left untouched."
|
|
2283
|
+
).argument("[mcp_server_token]", "MCP server token").option("--connection-id <id>", "Connection to re-scope").option("--tool <slug>", "Tool slug to expose (repeatable)", collect2).option("--all", "Expose every tool of the connection's application");
|
|
2284
|
+
set.addHelpText(
|
|
2285
|
+
"after",
|
|
2286
|
+
"\nExamples:\n engini mcp tools set <token> --connection-id 2139 --tool gmail_send_mail\n engini mcp tools set <token> --connection-id 2139 --all\n engini mcp tools set <token> --connection-id 2139 --tool gmail_send_mail --dry-run"
|
|
2287
|
+
);
|
|
2288
|
+
addUniversalOptions(set, { mutating: true });
|
|
2289
|
+
set.action(async (token, opts, command) => {
|
|
2290
|
+
await runCommand(command, opts, true, () => setBody2(token, opts));
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
// src/mcp/workflows.ts
|
|
2295
|
+
async function applyWorkflows(mcpServerToken, next) {
|
|
2296
|
+
const client = buildClient();
|
|
2297
|
+
const current = await apiErrors(async () => client.mcp.get(mcpServerToken));
|
|
2298
|
+
const workflows = next(current);
|
|
2299
|
+
if (dryRun()) {
|
|
2300
|
+
printOutput({
|
|
2301
|
+
would_update: {
|
|
2302
|
+
mcp_server_token: mcpServerToken,
|
|
2303
|
+
workflows: diffWorkflows(
|
|
2304
|
+
current.workflows.map((w) => w.workflowToken),
|
|
2305
|
+
workflows.map((w) => w.workflowToken)
|
|
2306
|
+
)
|
|
2307
|
+
}
|
|
2308
|
+
});
|
|
2309
|
+
return;
|
|
2310
|
+
}
|
|
2311
|
+
const updated = await apiErrors(async () => client.mcp.update(mcpServerToken, { workflows }));
|
|
2312
|
+
printOutput(summarizeMcpServer(updated));
|
|
2313
|
+
}
|
|
2314
|
+
function registerAdd2(workflows) {
|
|
2315
|
+
const cmd = workflows.command("add").description(
|
|
2316
|
+
"Expose workflows as tools on an MCP server. Existing workflows are preserved; an entry with the same workflow token is replaced."
|
|
2317
|
+
).argument("[mcp_server_token]", "MCP server token").option("--workflow <workflow_token>", "Workflow to expose (repeatable)", collect2).option("--tool-name <name>", "Override the tool name (single --workflow only)").option("--tool-description <text>", "Override the tool description (single --workflow only)");
|
|
2318
|
+
cmd.addHelpText(
|
|
2319
|
+
"after",
|
|
2320
|
+
"\nExamples:\n engini mcp workflows add <token> --workflow <workflow_token>\n engini mcp workflows add <token> --workflow <workflow_token> --tool-name send_report\n engini mcp workflows add <token> --workflow <workflow_token> --dry-run"
|
|
2321
|
+
);
|
|
2322
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2323
|
+
cmd.action(async (token, opts, command) => {
|
|
2324
|
+
await runCommand(command, opts, true, async () => {
|
|
2325
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2326
|
+
const requested = opts.workflow ?? [];
|
|
2327
|
+
if (requested.length === 0) {
|
|
2328
|
+
fail(2 /* USAGE */, "Nothing to add \u2014 pass at least one --workflow.");
|
|
2329
|
+
}
|
|
2330
|
+
const hasOverride = opts.toolName !== void 0 || opts.toolDescription !== void 0;
|
|
2331
|
+
if (hasOverride && requested.length > 1) {
|
|
2332
|
+
fail(
|
|
2333
|
+
2 /* USAGE */,
|
|
2334
|
+
"--tool-name/--tool-description apply to a single --workflow; pass them one workflow at a time."
|
|
2335
|
+
);
|
|
2336
|
+
}
|
|
2337
|
+
const incoming = requested.map((workflowToken) => ({
|
|
2338
|
+
workflowToken,
|
|
2339
|
+
toolName: opts.toolName,
|
|
2340
|
+
toolDescription: opts.toolDescription
|
|
2341
|
+
}));
|
|
2342
|
+
await applyWorkflows(
|
|
2343
|
+
mcpServerToken,
|
|
2344
|
+
(current) => upsertWorkflows(workflowsToRequests(current.workflows), incoming)
|
|
2345
|
+
);
|
|
2346
|
+
});
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
function registerRm2(workflows) {
|
|
2350
|
+
const cmd = workflows.command("rm").description("Stop exposing workflows on an MCP server, leaving the rest in place.").argument("[mcp_server_token]", "MCP server token").option("--workflow <workflow_token>", "Workflow to remove (repeatable)", collect2);
|
|
2351
|
+
cmd.addHelpText(
|
|
2352
|
+
"after",
|
|
2353
|
+
"\nExamples:\n engini mcp workflows rm <token> --workflow <workflow_token>"
|
|
2354
|
+
);
|
|
2355
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2356
|
+
cmd.action(async (token, opts, command) => {
|
|
2357
|
+
await runCommand(command, opts, true, async () => {
|
|
2358
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2359
|
+
if (!opts.workflow?.length) {
|
|
2360
|
+
fail(2 /* USAGE */, "Nothing to remove \u2014 pass at least one --workflow.");
|
|
2361
|
+
}
|
|
2362
|
+
const removing = new Set(opts.workflow);
|
|
2363
|
+
await applyWorkflows(mcpServerToken, (current) => {
|
|
2364
|
+
const present = new Set(current.workflows.map((w) => w.workflowToken));
|
|
2365
|
+
for (const wf of removing) {
|
|
2366
|
+
if (!present.has(wf)) {
|
|
2367
|
+
fail(4 /* NOT_FOUND */, "That workflow is not exposed on this MCP server.");
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
return workflowsToRequests(
|
|
2371
|
+
current.workflows.filter((w) => !removing.has(w.workflowToken))
|
|
2372
|
+
);
|
|
2373
|
+
});
|
|
2374
|
+
});
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
function registerMcpWorkflows(mcp) {
|
|
2378
|
+
const workflows = mcp.command("workflows").description("Add or remove the workflows an MCP server exposes as tools.");
|
|
2379
|
+
registerAdd2(workflows);
|
|
2380
|
+
registerRm2(workflows);
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
// src/mcp/index.ts
|
|
2384
|
+
function registerMcp(program) {
|
|
2385
|
+
const mcp = program.command("mcp").description("List, inspect, activate, and configure the account's MCP servers.");
|
|
2386
|
+
registerMcpList(mcp);
|
|
2387
|
+
registerMcpGet(mcp);
|
|
2388
|
+
registerMcpStatus(mcp);
|
|
2389
|
+
registerMcpConnections(mcp);
|
|
2390
|
+
registerMcpTools(mcp);
|
|
2391
|
+
registerMcpWorkflows(mcp);
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2394
|
+
// src/opa/shared.ts
|
|
2395
|
+
function parseAgentId(raw) {
|
|
2396
|
+
if (raw === void 0 || raw === "") fail(2 /* USAGE */, "An agent id is required.");
|
|
2397
|
+
if (!/^[1-9]\d*$/.test(raw)) {
|
|
2398
|
+
fail(2 /* USAGE */, `'${raw}' is not a valid agent id (expected a positive integer).`);
|
|
2399
|
+
}
|
|
2400
|
+
return Number(raw);
|
|
2401
|
+
}
|
|
2402
|
+
function summarizeAgent(agent) {
|
|
2403
|
+
return {
|
|
2404
|
+
agent_id: agent.agentId,
|
|
2405
|
+
name: clean(agent.name),
|
|
2406
|
+
status: agent.status,
|
|
2407
|
+
version: clean(agent.version),
|
|
2408
|
+
last_seen_at: clean(agent.lastSeenAt)
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
function renderSettings(settings) {
|
|
2412
|
+
return {
|
|
2413
|
+
parallel_tasks: clean(settings?.parallelTasks),
|
|
2414
|
+
pull_period_seconds: clean(settings?.pullPeriodSeconds),
|
|
2415
|
+
log_level: clean(settings?.logLevel)
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
function parseSettingsFlags(flags) {
|
|
2419
|
+
const integer = (raw, flag) => {
|
|
2420
|
+
if (raw === void 0) return void 0;
|
|
2421
|
+
if (!/^\d+$/.test(raw)) {
|
|
2422
|
+
fail(2 /* USAGE */, `${flag} must be a non-negative integer, got '${raw}'.`);
|
|
2423
|
+
}
|
|
2424
|
+
return Number(raw);
|
|
2425
|
+
};
|
|
2426
|
+
const out = {};
|
|
2427
|
+
const parallelTasks = integer(flags.parallelTasks, "--parallel-tasks");
|
|
2428
|
+
const pullPeriodSeconds = integer(flags.pullPeriod, "--pull-period");
|
|
2429
|
+
if (parallelTasks !== void 0) out.parallelTasks = parallelTasks;
|
|
2430
|
+
if (pullPeriodSeconds !== void 0) out.pullPeriodSeconds = pullPeriodSeconds;
|
|
2431
|
+
if (flags.logLevel !== void 0) out.logLevel = flags.logLevel;
|
|
2432
|
+
return out;
|
|
2433
|
+
}
|
|
2434
|
+
function settingsPreview(settings) {
|
|
2435
|
+
return Object.keys(settings).length === 0 ? void 0 : { ...settings };
|
|
2436
|
+
}
|
|
2437
|
+
function addSettingsOptions(cmd) {
|
|
2438
|
+
return cmd.option(
|
|
2439
|
+
"--parallel-tasks <n>",
|
|
2440
|
+
"Concurrent tasks the agent runs (server-declared range, currently 1-100)"
|
|
2441
|
+
).option(
|
|
2442
|
+
"--pull-period <seconds>",
|
|
2443
|
+
"Seconds between task polls (server-declared minimum, currently 10)"
|
|
2444
|
+
).option("--log-level <level>", "Agent log level, e.g. Information, Debug");
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// src/opa/create.ts
|
|
2448
|
+
async function createBody2(opts) {
|
|
2449
|
+
if (opts.name === void 0 || opts.name.trim() === "") fail(2 /* USAGE */, "--name is required.");
|
|
2450
|
+
const settings = parseSettingsFlags(opts);
|
|
2451
|
+
const preview = settingsPreview(settings);
|
|
2452
|
+
if (dryRun()) {
|
|
2453
|
+
printOutput({
|
|
2454
|
+
would_create: {
|
|
2455
|
+
name: opts.name,
|
|
2456
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
2457
|
+
...opts.applicationSlug !== void 0 ? { applicationSlug: opts.applicationSlug } : {},
|
|
2458
|
+
...preview ? { settings: preview } : {}
|
|
2459
|
+
}
|
|
2460
|
+
});
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2463
|
+
const agent = await apiErrors(
|
|
2464
|
+
async () => buildClient().opa.create({
|
|
2465
|
+
name: opts.name,
|
|
2466
|
+
description: opts.description,
|
|
2467
|
+
applicationSlug: opts.applicationSlug,
|
|
2468
|
+
...settings
|
|
2469
|
+
})
|
|
2470
|
+
);
|
|
2471
|
+
printOutput({
|
|
2472
|
+
...summarizeAgent(agent),
|
|
2473
|
+
settings: renderSettings(agent.settings),
|
|
2474
|
+
token: agent.token
|
|
2475
|
+
});
|
|
2476
|
+
}
|
|
2477
|
+
function registerOpaCreate(opa) {
|
|
2478
|
+
const cmd = opa.command("create").description(
|
|
2479
|
+
"Register a new on-premise agent. Prints its token - treat the output as a secret."
|
|
2480
|
+
).option("--name <name>", "Display name (required)").option("--description <text>", "Optional description").option(
|
|
2481
|
+
"--application-slug <slug>",
|
|
2482
|
+
"Only when more than one agent application exists; the 409 lists the candidates"
|
|
2483
|
+
);
|
|
2484
|
+
addSettingsOptions(cmd);
|
|
2485
|
+
cmd.addHelpText(
|
|
2486
|
+
"after",
|
|
2487
|
+
'\nExamples:\n engini opa create --name "Warehouse SQL" --json\n engini opa create --name Backoffice --pull-period 30 --log-level Debug\n engini opa create --name Backoffice --dry-run'
|
|
2488
|
+
);
|
|
2489
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2490
|
+
cmd.action(async (opts, command) => {
|
|
2491
|
+
await runCommand(command, opts, true, () => createBody2(opts));
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
// src/opa/delete.ts
|
|
2496
|
+
async function deleteBody2(raw, opts) {
|
|
2497
|
+
const agentId = parseAgentId(raw);
|
|
2498
|
+
if (dryRun()) {
|
|
2499
|
+
printOutput({ would_delete: agentId });
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
await confirmOrFail(
|
|
2503
|
+
`Delete on-premise agent ${agentId}? Workflows routed through it will stop working.`,
|
|
2504
|
+
{ force: Boolean(opts.force) }
|
|
2505
|
+
);
|
|
2506
|
+
await apiErrors(async () => buildClient().opa.delete(agentId));
|
|
2507
|
+
printOutput({ deleted: agentId });
|
|
2508
|
+
}
|
|
2509
|
+
function registerOpaDelete(opa) {
|
|
2510
|
+
const cmd = opa.command("delete").description("Permanently delete an on-premise agent.").argument("[agent_id]", "Agent id").option("--force", "Delete without confirming");
|
|
2511
|
+
cmd.addHelpText("after", "\nExamples:\n engini opa delete 41 --force");
|
|
2512
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2513
|
+
cmd.action(async (raw, opts, command) => {
|
|
2514
|
+
await runCommand(
|
|
2515
|
+
command,
|
|
2516
|
+
opts,
|
|
2517
|
+
true,
|
|
2518
|
+
() => deleteBody2(raw, opts)
|
|
2519
|
+
);
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
// src/opa/download.ts
|
|
2524
|
+
import { createHash } from "crypto";
|
|
2525
|
+
import { writeFile } from "fs/promises";
|
|
2526
|
+
import { basename } from "path";
|
|
2527
|
+
function targetFromManifest(url) {
|
|
2528
|
+
let name;
|
|
2529
|
+
try {
|
|
2530
|
+
name = basename(new URL(url).pathname);
|
|
2531
|
+
} catch {
|
|
2532
|
+
fail(1 /* GENERIC */, `The release manifest carries an unusable installer URL: ${url}`);
|
|
2533
|
+
}
|
|
2534
|
+
if (name === "" || name === "." || name === ".." || name.includes("/") || name.includes("\\")) {
|
|
2535
|
+
fail(
|
|
2536
|
+
1 /* GENERIC */,
|
|
2537
|
+
`Cannot derive a filename from the manifest URL (${url}). Pass -o <file>.`
|
|
2538
|
+
);
|
|
2539
|
+
}
|
|
2540
|
+
return name;
|
|
2541
|
+
}
|
|
2542
|
+
async function downloadBody(opts) {
|
|
2543
|
+
const manifest = await apiErrors(async () => buildClient().opa.latestRelease());
|
|
2544
|
+
if (outputFlags().forceJson && opts.out === void 0) {
|
|
2545
|
+
printOutput(manifest);
|
|
2546
|
+
return;
|
|
1759
2547
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
2548
|
+
const target = opts.out ?? targetFromManifest(manifest.url);
|
|
2549
|
+
if (dryRun()) {
|
|
2550
|
+
printOutput({
|
|
2551
|
+
would_write: target,
|
|
2552
|
+
version: manifest.version,
|
|
2553
|
+
url: manifest.url,
|
|
2554
|
+
degraded: manifest.degraded
|
|
2555
|
+
});
|
|
2556
|
+
return;
|
|
2557
|
+
}
|
|
2558
|
+
const response = await fetch(manifest.url);
|
|
2559
|
+
if (!response.ok) {
|
|
2560
|
+
fail(
|
|
2561
|
+
1 /* GENERIC */,
|
|
2562
|
+
`Installer download failed: HTTP ${response.status} from ${manifest.url}`
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2565
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
2566
|
+
let verified;
|
|
2567
|
+
if (manifest.sha256) {
|
|
2568
|
+
const actual = createHash("sha256").update(bytes).digest("hex");
|
|
2569
|
+
if (actual !== manifest.sha256.toLowerCase()) {
|
|
1762
2570
|
fail(
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
"Interactive login needs a terminal on both stdin and stdout."
|
|
2571
|
+
5 /* VALIDATION */,
|
|
2572
|
+
`sha256 mismatch: the manifest says ${manifest.sha256}, the download is ${actual}. Nothing written.`
|
|
1766
2573
|
);
|
|
1767
2574
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
2575
|
+
verified = true;
|
|
2576
|
+
} else {
|
|
2577
|
+
verified = false;
|
|
2578
|
+
}
|
|
2579
|
+
await writeFile(target, bytes);
|
|
2580
|
+
printOutput({
|
|
2581
|
+
wrote: target,
|
|
2582
|
+
bytes: bytes.length,
|
|
2583
|
+
version: manifest.version,
|
|
2584
|
+
verified,
|
|
2585
|
+
degraded: manifest.degraded
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
function registerOpaDownload(opa) {
|
|
2589
|
+
const cmd = opa.command("download").description("Download the current on-premise agent installer.").option(
|
|
2590
|
+
"-o, --out <file>",
|
|
2591
|
+
"Where to write the installer (default: the manifest's filename, in the current directory)"
|
|
2592
|
+
);
|
|
2593
|
+
cmd.addHelpText(
|
|
2594
|
+
"after",
|
|
2595
|
+
"\nExamples:\n engini opa download # writes EnginiAgent-<version>.exe here\n engini opa download -o ./agent.exe\n engini opa download --json # print the manifest, download nothing\n engini opa download --dry-run # show where it would land"
|
|
2596
|
+
);
|
|
2597
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2598
|
+
cmd.action(async (opts, command) => {
|
|
2599
|
+
await runCommand(command, opts, true, () => downloadBody(opts));
|
|
2600
|
+
});
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
// src/opa/get.ts
|
|
2604
|
+
async function getBody4(raw) {
|
|
2605
|
+
const agentId = parseAgentId(raw);
|
|
2606
|
+
const agent = await apiErrors(async () => buildClient().opa.get(agentId));
|
|
2607
|
+
printOutput({
|
|
2608
|
+
...summarizeAgent(agent),
|
|
2609
|
+
description: clean(agent.description),
|
|
2610
|
+
settings: renderSettings(agent.settings),
|
|
2611
|
+
created_date: clean(agent.createdDate),
|
|
2612
|
+
updated_date: clean(agent.updatedDate)
|
|
2613
|
+
});
|
|
2614
|
+
}
|
|
2615
|
+
function registerOpaGet(opa) {
|
|
2616
|
+
const cmd = opa.command("get").description("Show full detail for one on-premise agent.").argument("[agent_id]", "Agent id");
|
|
2617
|
+
cmd.addHelpText("after", "\nExamples:\n engini opa get 41 --json");
|
|
2618
|
+
addUniversalOptions(cmd);
|
|
2619
|
+
cmd.action(async (raw, opts, command) => {
|
|
2620
|
+
await runCommand(command, opts, false, () => getBody4(raw));
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
// src/opa/list.ts
|
|
2625
|
+
async function listBody6(opts) {
|
|
2626
|
+
const agents = await apiErrors(
|
|
2627
|
+
async () => buildClient().opa.list({ status: opts.status, name: opts.name })
|
|
2628
|
+
);
|
|
2629
|
+
printOutput(agents.map(summarizeAgent));
|
|
2630
|
+
}
|
|
2631
|
+
function registerOpaList(opa) {
|
|
2632
|
+
const cmd = opa.command("list").description("List the account's on-premise agents.").option(
|
|
2633
|
+
"--status <status>",
|
|
2634
|
+
"Filter: WaitingForConnection | Online | Offline | Disabled (case-insensitive)"
|
|
2635
|
+
).option("--name <substring>", "Filter by name substring");
|
|
2636
|
+
cmd.addHelpText(
|
|
2637
|
+
"after",
|
|
2638
|
+
"\nExamples:\n engini opa list\n engini opa list --status offline --json"
|
|
2639
|
+
);
|
|
2640
|
+
addUniversalOptions(cmd);
|
|
2641
|
+
cmd.action(async (opts, command) => {
|
|
2642
|
+
await runCommand(command, opts, false, () => listBody6(opts));
|
|
2643
|
+
});
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
// src/opa/logs.ts
|
|
2647
|
+
import { writeFile as writeFile2 } from "fs/promises";
|
|
2648
|
+
async function logsBody(raw, opts) {
|
|
2649
|
+
const agentId = parseAgentId(raw);
|
|
2650
|
+
if (opts.out === void 0 || opts.out === "") {
|
|
2651
|
+
fail(2 /* USAGE */, "-o <file> is required: where to write the log archive.");
|
|
1787
2652
|
}
|
|
1788
|
-
config.api_key = apiKey;
|
|
1789
|
-
config.auth_kind = "api-key";
|
|
1790
|
-
const summary6 = {
|
|
1791
|
-
auth_kind: "api-key",
|
|
1792
|
-
credential: maskSecret(apiKey),
|
|
1793
|
-
api_url: config.api_url
|
|
1794
|
-
};
|
|
1795
2653
|
if (dryRun()) {
|
|
1796
|
-
printOutput({
|
|
2654
|
+
printOutput({ would_write: opts.out, agent_id: agentId });
|
|
1797
2655
|
return;
|
|
1798
2656
|
}
|
|
1799
|
-
|
|
1800
|
-
|
|
2657
|
+
const bytes = await apiErrors(async () => buildClient().opa.downloadLogs(agentId));
|
|
2658
|
+
await writeFile2(opts.out, bytes);
|
|
2659
|
+
printOutput({ wrote: opts.out, bytes: bytes.length, agent_id: agentId });
|
|
2660
|
+
}
|
|
2661
|
+
function registerOpaLogs(opa) {
|
|
2662
|
+
const cmd = opa.command("logs").description("Collect an agent's logs as a zip archive. The agent must be Online.").argument("[agent_id]", "Agent id").option("-o, --out <file>", "Where to write the archive (required)");
|
|
2663
|
+
cmd.addHelpText(
|
|
2664
|
+
"after",
|
|
2665
|
+
"\nExamples:\n engini opa logs 41 -o ./opa-41-logs.zip\n engini opa logs 41 -o ./opa-41-logs.zip --json"
|
|
2666
|
+
);
|
|
2667
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2668
|
+
cmd.action(async (raw, opts, command) => {
|
|
2669
|
+
await runCommand(
|
|
2670
|
+
command,
|
|
2671
|
+
opts,
|
|
2672
|
+
true,
|
|
2673
|
+
() => logsBody(raw, opts)
|
|
2674
|
+
);
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
// src/opa/status.ts
|
|
2679
|
+
async function toggleBody(raw, enabled) {
|
|
2680
|
+
const agentId = parseAgentId(raw);
|
|
2681
|
+
if (dryRun()) {
|
|
2682
|
+
printOutput(enabled ? { would_enable: agentId } : { would_disable: agentId });
|
|
2683
|
+
return;
|
|
1801
2684
|
}
|
|
1802
|
-
|
|
1803
|
-
|
|
2685
|
+
const agent = await apiErrors(async () => {
|
|
2686
|
+
const client = buildClient();
|
|
2687
|
+
return enabled ? client.opa.enable(agentId) : client.opa.disable(agentId);
|
|
2688
|
+
});
|
|
2689
|
+
printOutput(summarizeAgent(agent));
|
|
1804
2690
|
}
|
|
1805
|
-
function
|
|
1806
|
-
const cmd =
|
|
2691
|
+
function register2(opa, name, description) {
|
|
2692
|
+
const cmd = opa.command(name).description(description).argument("[agent_id]", "Agent id");
|
|
2693
|
+
cmd.addHelpText("after", `
|
|
2694
|
+
Examples:
|
|
2695
|
+
engini opa ${name} 41`);
|
|
1807
2696
|
addUniversalOptions(cmd, { mutating: true });
|
|
1808
|
-
cmd.action(async (opts, command) => {
|
|
1809
|
-
await runCommand(command, opts, true, () =>
|
|
2697
|
+
cmd.action(async (raw, opts, command) => {
|
|
2698
|
+
await runCommand(command, opts, true, () => toggleBody(raw, name === "enable"));
|
|
1810
2699
|
});
|
|
1811
2700
|
}
|
|
2701
|
+
function registerOpaEnable(opa) {
|
|
2702
|
+
register2(
|
|
2703
|
+
opa,
|
|
2704
|
+
"enable",
|
|
2705
|
+
"Re-enable a disabled agent; it returns to WaitingForConnection. A no-op if it is not disabled."
|
|
2706
|
+
);
|
|
2707
|
+
}
|
|
2708
|
+
function registerOpaDisable(opa) {
|
|
2709
|
+
register2(
|
|
2710
|
+
opa,
|
|
2711
|
+
"disable",
|
|
2712
|
+
"Stop an agent being marked online. Tasks it already holds still complete."
|
|
2713
|
+
);
|
|
2714
|
+
}
|
|
1812
2715
|
|
|
1813
|
-
// src/
|
|
1814
|
-
function
|
|
1815
|
-
const
|
|
1816
|
-
|
|
1817
|
-
|
|
2716
|
+
// src/opa/token.ts
|
|
2717
|
+
async function getBody5(raw) {
|
|
2718
|
+
const agentId = parseAgentId(raw);
|
|
2719
|
+
const token = await apiErrors(async () => buildClient().opa.getToken(agentId));
|
|
2720
|
+
printOutput({ agent_id: token.agentId, token: token.token });
|
|
2721
|
+
}
|
|
2722
|
+
async function rotateBody(raw, opts) {
|
|
2723
|
+
const agentId = parseAgentId(raw);
|
|
2724
|
+
if (dryRun()) {
|
|
2725
|
+
printOutput({ would_rotate_token_for: agentId });
|
|
1818
2726
|
return;
|
|
1819
2727
|
}
|
|
2728
|
+
await confirmOrFail(
|
|
2729
|
+
`Rotate the token for on-premise agent ${agentId}? The running agent stops authenticating immediately and stays down until it is reconfigured with the new token.`,
|
|
2730
|
+
{ force: Boolean(opts.force) }
|
|
2731
|
+
);
|
|
2732
|
+
const token = await apiErrors(async () => buildClient().opa.rotateToken(agentId));
|
|
2733
|
+
printOutput({
|
|
2734
|
+
agent_id: token.agentId,
|
|
2735
|
+
token: token.token,
|
|
2736
|
+
note: "Reconfigure the agent with this token; the previous one no longer works."
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
function registerOpaToken(opa) {
|
|
2740
|
+
const token = opa.command("token").description("Read or rotate an agent's token (a live credential).");
|
|
2741
|
+
const get = token.command("get").description("Print the agent's current token.").argument("[agent_id]", "Agent id");
|
|
2742
|
+
get.addHelpText("after", "\nExamples:\n engini opa token get 41 --json");
|
|
2743
|
+
addUniversalOptions(get);
|
|
2744
|
+
get.action(async (raw, opts, command) => {
|
|
2745
|
+
await runCommand(command, opts, false, () => getBody5(raw));
|
|
2746
|
+
});
|
|
2747
|
+
const rotate = token.command("rotate").description(
|
|
2748
|
+
"Issue a new token, invalidating the current one. Stops the running agent until it is reconfigured."
|
|
2749
|
+
).argument("[agent_id]", "Agent id").option("--force", "Rotate without confirming");
|
|
2750
|
+
rotate.addHelpText("after", "\nExamples:\n engini opa token rotate 41 --force --json");
|
|
2751
|
+
addUniversalOptions(rotate, { mutating: true });
|
|
2752
|
+
rotate.action(
|
|
2753
|
+
async (raw, opts, command) => {
|
|
2754
|
+
await runCommand(
|
|
2755
|
+
command,
|
|
2756
|
+
opts,
|
|
2757
|
+
true,
|
|
2758
|
+
() => rotateBody(raw, opts)
|
|
2759
|
+
);
|
|
2760
|
+
}
|
|
2761
|
+
);
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
// src/opa/update.ts
|
|
2765
|
+
async function updateBody2(raw, opts) {
|
|
2766
|
+
const agentId = parseAgentId(raw);
|
|
2767
|
+
const settings = parseSettingsFlags(opts);
|
|
2768
|
+
const preview = settingsPreview(settings);
|
|
2769
|
+
const changes = {
|
|
2770
|
+
...opts.name !== void 0 ? { name: opts.name } : {},
|
|
2771
|
+
...opts.description !== void 0 ? { description: opts.description } : {},
|
|
2772
|
+
...preview ? { settings: preview } : {}
|
|
2773
|
+
};
|
|
2774
|
+
if (Object.keys(changes).length === 0) {
|
|
2775
|
+
fail(
|
|
2776
|
+
2 /* USAGE */,
|
|
2777
|
+
"Nothing to update - pass at least one of --name, --description, --parallel-tasks, --pull-period, --log-level."
|
|
2778
|
+
);
|
|
2779
|
+
}
|
|
1820
2780
|
if (dryRun()) {
|
|
1821
|
-
printOutput({
|
|
2781
|
+
printOutput({ would_update: agentId, changes });
|
|
1822
2782
|
return;
|
|
1823
2783
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
2784
|
+
const agent = await apiErrors(
|
|
2785
|
+
async () => buildClient().opa.update(agentId, {
|
|
2786
|
+
name: opts.name,
|
|
2787
|
+
description: opts.description,
|
|
2788
|
+
...settings
|
|
2789
|
+
})
|
|
2790
|
+
);
|
|
2791
|
+
printOutput({
|
|
2792
|
+
...summarizeAgent(agent),
|
|
2793
|
+
settings: renderSettings(agent.settings),
|
|
2794
|
+
applied_to_agent: clean(agent.appliedToAgent),
|
|
2795
|
+
dispatched_task_ids: agent.dispatchedTaskIds ?? []
|
|
2796
|
+
});
|
|
1830
2797
|
}
|
|
1831
|
-
function
|
|
1832
|
-
const cmd =
|
|
2798
|
+
function registerOpaUpdate(opa) {
|
|
2799
|
+
const cmd = opa.command("update").description(
|
|
2800
|
+
"Change an agent's name, description or settings. Merges - omitted flags leave the field alone."
|
|
2801
|
+
).argument("[agent_id]", "Agent id").option("--name <name>", "New display name").option("--description <text>", "New description");
|
|
2802
|
+
addSettingsOptions(cmd);
|
|
2803
|
+
cmd.addHelpText(
|
|
2804
|
+
"after",
|
|
2805
|
+
"\nExamples:\n engini opa update 41 --log-level Debug\n engini opa update 41 --parallel-tasks 8 --pull-period 15 --json\n engini opa update 41 --log-level Debug --dry-run"
|
|
2806
|
+
);
|
|
1833
2807
|
addUniversalOptions(cmd, { mutating: true });
|
|
1834
|
-
cmd.action(async (opts, command) => {
|
|
1835
|
-
await runCommand(
|
|
2808
|
+
cmd.action(async (raw, opts, command) => {
|
|
2809
|
+
await runCommand(
|
|
2810
|
+
command,
|
|
2811
|
+
opts,
|
|
2812
|
+
true,
|
|
2813
|
+
() => updateBody2(raw, opts)
|
|
2814
|
+
);
|
|
1836
2815
|
});
|
|
1837
2816
|
}
|
|
1838
2817
|
|
|
2818
|
+
// src/opa/index.ts
|
|
2819
|
+
function registerOpa(program) {
|
|
2820
|
+
const opa = program.command("opa").description("Provision, inspect, configure and credential on-premise agents.");
|
|
2821
|
+
registerOpaList(opa);
|
|
2822
|
+
registerOpaGet(opa);
|
|
2823
|
+
registerOpaCreate(opa);
|
|
2824
|
+
registerOpaUpdate(opa);
|
|
2825
|
+
registerOpaDelete(opa);
|
|
2826
|
+
registerOpaEnable(opa);
|
|
2827
|
+
registerOpaDisable(opa);
|
|
2828
|
+
registerOpaToken(opa);
|
|
2829
|
+
registerOpaLogs(opa);
|
|
2830
|
+
registerOpaDownload(opa);
|
|
2831
|
+
}
|
|
2832
|
+
|
|
1839
2833
|
// src/tools/call.ts
|
|
1840
|
-
import { readFileSync as
|
|
2834
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
1841
2835
|
import {
|
|
1842
2836
|
AnthropicProvider,
|
|
1843
2837
|
File,
|
|
@@ -1849,7 +2843,7 @@ import { randomBytes } from "crypto";
|
|
|
1849
2843
|
import {
|
|
1850
2844
|
existsSync as existsSync2,
|
|
1851
2845
|
mkdirSync as mkdirSync2,
|
|
1852
|
-
readFileSync as
|
|
2846
|
+
readFileSync as readFileSync3,
|
|
1853
2847
|
readdirSync,
|
|
1854
2848
|
rmSync,
|
|
1855
2849
|
statSync,
|
|
@@ -1893,7 +2887,7 @@ function loadResult(handle) {
|
|
|
1893
2887
|
const path = join2(cacheDir(), `${handle}.json`);
|
|
1894
2888
|
if (!existsSync2(path)) return null;
|
|
1895
2889
|
try {
|
|
1896
|
-
const data = JSON.parse(
|
|
2890
|
+
const data = JSON.parse(readFileSync3(path, "utf8"));
|
|
1897
2891
|
return data && typeof data === "object" ? data : null;
|
|
1898
2892
|
} catch {
|
|
1899
2893
|
return null;
|
|
@@ -2081,10 +3075,10 @@ function paginate(value, offset, limit) {
|
|
|
2081
3075
|
function loadArgs(spec) {
|
|
2082
3076
|
let text;
|
|
2083
3077
|
if (spec === "-") {
|
|
2084
|
-
text =
|
|
3078
|
+
text = readFileSync4(0, "utf8");
|
|
2085
3079
|
} else if (spec.startsWith("@")) {
|
|
2086
3080
|
try {
|
|
2087
|
-
text =
|
|
3081
|
+
text = readFileSync4(spec.slice(1), "utf8");
|
|
2088
3082
|
} catch (err) {
|
|
2089
3083
|
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
2090
3084
|
}
|
|
@@ -2258,7 +3252,7 @@ function detail3(schema) {
|
|
|
2258
3252
|
max_sorts: clean(schema.maxSorts)
|
|
2259
3253
|
};
|
|
2260
3254
|
}
|
|
2261
|
-
async function
|
|
3255
|
+
async function getBody6(toolId) {
|
|
2262
3256
|
if (!toolId) {
|
|
2263
3257
|
fail(2 /* USAGE */, "Missing required argument 'tool_id'.");
|
|
2264
3258
|
}
|
|
@@ -2272,7 +3266,7 @@ function registerToolsGet(tools) {
|
|
|
2272
3266
|
const cmd = tools.command("get").description("Show full canonical detail for one tool.").argument("[tool_id]", "Tool slug");
|
|
2273
3267
|
addUniversalOptions(cmd);
|
|
2274
3268
|
cmd.action(async (toolId, opts, command) => {
|
|
2275
|
-
await runCommand(command, opts, false, () =>
|
|
3269
|
+
await runCommand(command, opts, false, () => getBody6(toolId));
|
|
2276
3270
|
});
|
|
2277
3271
|
}
|
|
2278
3272
|
|
|
@@ -2295,7 +3289,7 @@ function parseLimit2(value) {
|
|
|
2295
3289
|
}
|
|
2296
3290
|
return limit;
|
|
2297
3291
|
}
|
|
2298
|
-
async function
|
|
3292
|
+
async function listBody7(opts) {
|
|
2299
3293
|
if (opts.application && opts.toolset) {
|
|
2300
3294
|
fail(2 /* USAGE */, "Pass only one of --application / --toolset.");
|
|
2301
3295
|
}
|
|
@@ -2318,7 +3312,7 @@ function registerToolsList(tools) {
|
|
|
2318
3312
|
const cmd = tools.command("list").description("List available tools, optionally filtered.").option("--application <slug>", "Filter by application slug (e.g. monday)").option("--toolset <id>", "List the tools of a server toolset (by id)").option("--limit <n>", "Cap the number of tools returned");
|
|
2319
3313
|
addUniversalOptions(cmd);
|
|
2320
3314
|
cmd.action(async (opts, command) => {
|
|
2321
|
-
await runCommand(command, opts, false, () =>
|
|
3315
|
+
await runCommand(command, opts, false, () => listBody7(opts));
|
|
2322
3316
|
});
|
|
2323
3317
|
}
|
|
2324
3318
|
|
|
@@ -2402,21 +3396,10 @@ function registerTools(program) {
|
|
|
2402
3396
|
}
|
|
2403
3397
|
|
|
2404
3398
|
// src/toolsets/shared.ts
|
|
2405
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
2406
|
-
function collect2(value, previous = []) {
|
|
2407
|
-
return [...previous, value];
|
|
2408
|
-
}
|
|
2409
3399
|
function parseToolsetId(value) {
|
|
2410
3400
|
if (!value) fail(2 /* USAGE */, "Missing required argument 'toolset_id'.");
|
|
2411
3401
|
return value;
|
|
2412
3402
|
}
|
|
2413
|
-
function splitSlugs(spec) {
|
|
2414
|
-
const colon = spec.indexOf(":");
|
|
2415
|
-
if (colon < 0) return [spec, void 0];
|
|
2416
|
-
const head = spec.slice(0, colon);
|
|
2417
|
-
const slugs = spec.slice(colon + 1).split(",").map((s) => s.trim()).filter(Boolean);
|
|
2418
|
-
return [head, slugs.length > 0 ? slugs : void 0];
|
|
2419
|
-
}
|
|
2420
3403
|
function parseConnectionFlags(specs) {
|
|
2421
3404
|
return (specs ?? []).map((spec) => {
|
|
2422
3405
|
const [idPart, toolSlugs] = splitSlugs(spec);
|
|
@@ -2447,30 +3430,6 @@ function connectionsFromFlagsOrUndefined(opts) {
|
|
|
2447
3430
|
function workflowsFromFlagsOrUndefined(specs) {
|
|
2448
3431
|
return specs && specs.length > 0 ? specs : void 0;
|
|
2449
3432
|
}
|
|
2450
|
-
function loadFromFile(spec) {
|
|
2451
|
-
let text;
|
|
2452
|
-
if (spec === "-") {
|
|
2453
|
-
text = readFileSync4(0, "utf8");
|
|
2454
|
-
} else if (spec.startsWith("@")) {
|
|
2455
|
-
try {
|
|
2456
|
-
text = readFileSync4(spec.slice(1), "utf8");
|
|
2457
|
-
} catch (err) {
|
|
2458
|
-
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
2459
|
-
}
|
|
2460
|
-
} else {
|
|
2461
|
-
text = spec;
|
|
2462
|
-
}
|
|
2463
|
-
let data;
|
|
2464
|
-
try {
|
|
2465
|
-
data = JSON.parse(text);
|
|
2466
|
-
} catch (err) {
|
|
2467
|
-
return fail(2 /* USAGE */, `--from-file is not valid JSON: ${err.message}`);
|
|
2468
|
-
}
|
|
2469
|
-
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
2470
|
-
return fail(2 /* USAGE */, "--from-file must be a JSON object.");
|
|
2471
|
-
}
|
|
2472
|
-
return data;
|
|
2473
|
-
}
|
|
2474
3433
|
var CONNECTION_ENTRY_ALIASES = {
|
|
2475
3434
|
connection_id: "connectionId",
|
|
2476
3435
|
application_slug: "applicationSlug",
|
|
@@ -2502,12 +3461,7 @@ function rejectFromFileCombo(fromFile, opts) {
|
|
|
2502
3461
|
}
|
|
2503
3462
|
}
|
|
2504
3463
|
function summarizeConnection(c) {
|
|
2505
|
-
return
|
|
2506
|
-
connection_id: c.connectionId,
|
|
2507
|
-
application_slug: c.applicationSlug,
|
|
2508
|
-
application_name: clean(c.applicationName),
|
|
2509
|
-
tool_slugs: c.toolSlugs
|
|
2510
|
-
};
|
|
3464
|
+
return summarizeConnectionDto(c);
|
|
2511
3465
|
}
|
|
2512
3466
|
function summarizeToolset(t) {
|
|
2513
3467
|
return {
|
|
@@ -2518,59 +3472,11 @@ function summarizeToolset(t) {
|
|
|
2518
3472
|
created_date: t.createdDate
|
|
2519
3473
|
};
|
|
2520
3474
|
}
|
|
2521
|
-
function
|
|
2522
|
-
return
|
|
2523
|
-
connection_id: c.connectionId ?? null,
|
|
2524
|
-
application_slug: c.applicationSlug ?? null,
|
|
2525
|
-
tool_slugs: c.toolSlugs ?? []
|
|
2526
|
-
};
|
|
2527
|
-
}
|
|
2528
|
-
function connectionKey(c) {
|
|
2529
|
-
return c.connectionId != null ? `id:${c.connectionId}` : `app:${c.applicationSlug}`;
|
|
2530
|
-
}
|
|
2531
|
-
function scopeKey(c) {
|
|
2532
|
-
const slugs = c.toolSlugs ?? [];
|
|
2533
|
-
return slugs.length === 0 ? "*" : [...slugs].sort().join(",");
|
|
2534
|
-
}
|
|
2535
|
-
function diffConnections(current, next) {
|
|
2536
|
-
const currentKeys = new Set(current.map((c) => connectionKey(c)));
|
|
2537
|
-
const nextByKey = new Map(next.map((c) => [connectionKey(c), c]));
|
|
2538
|
-
const nextKeys = new Set(nextByKey.keys());
|
|
2539
|
-
const changed = current.filter((c) => nextKeys.has(connectionKey(c))).filter((c) => scopeKey(c) !== scopeKey(nextByKey.get(connectionKey(c)))).map((c) => {
|
|
2540
|
-
const nextEntry = nextByKey.get(connectionKey(c));
|
|
2541
|
-
return {
|
|
2542
|
-
connection_id: c.connectionId,
|
|
2543
|
-
application_slug: c.applicationSlug,
|
|
2544
|
-
from: summarizeConnection(c),
|
|
2545
|
-
// A bare `--connection <id>` next-side entry carries no
|
|
2546
|
-
// `applicationSlug` (it's resolved server-side from the id), but it's
|
|
2547
|
-
// still the *same* connection as `c` - falling back to `c`'s known
|
|
2548
|
-
// slug avoids a `to.application_slug: null` sitting next to a `from`
|
|
2549
|
-
// that shows the real slug, which reads as "the slug is being
|
|
2550
|
-
// cleared" when nothing about the app binding actually changed.
|
|
2551
|
-
to: {
|
|
2552
|
-
...summarizeConnectionRequest(nextEntry),
|
|
2553
|
-
application_slug: nextEntry.applicationSlug ?? c.applicationSlug
|
|
2554
|
-
}
|
|
2555
|
-
};
|
|
2556
|
-
});
|
|
2557
|
-
return {
|
|
2558
|
-
current: current.map(summarizeConnection),
|
|
2559
|
-
resulting: next.map(summarizeConnectionRequest),
|
|
2560
|
-
added: next.filter((c) => !currentKeys.has(connectionKey(c))).map(summarizeConnectionRequest),
|
|
2561
|
-
removed: current.filter((c) => !nextKeys.has(connectionKey(c))).map(summarizeConnection),
|
|
2562
|
-
changed
|
|
2563
|
-
};
|
|
3475
|
+
function summarizeConnectionRequest2(c) {
|
|
3476
|
+
return summarizeConnectionRequest(c);
|
|
2564
3477
|
}
|
|
2565
|
-
function
|
|
2566
|
-
|
|
2567
|
-
const nextSet = new Set(next);
|
|
2568
|
-
return {
|
|
2569
|
-
current,
|
|
2570
|
-
resulting: next,
|
|
2571
|
-
added: next.filter((id) => !currentSet.has(id)),
|
|
2572
|
-
removed: current.filter((id) => !nextSet.has(id))
|
|
2573
|
-
};
|
|
3478
|
+
function diffConnections2(current, next) {
|
|
3479
|
+
return diffConnections(current, next);
|
|
2574
3480
|
}
|
|
2575
3481
|
|
|
2576
3482
|
// src/toolsets/create.ts
|
|
@@ -2597,13 +3503,13 @@ function buildRequestBody(opts) {
|
|
|
2597
3503
|
workflows: workflowsFromFlagsOrUndefined(opts.workflow)
|
|
2598
3504
|
};
|
|
2599
3505
|
}
|
|
2600
|
-
async function
|
|
3506
|
+
async function createBody3(opts) {
|
|
2601
3507
|
const body = buildRequestBody(opts);
|
|
2602
3508
|
if (dryRun()) {
|
|
2603
3509
|
printOutput({
|
|
2604
3510
|
would_create: {
|
|
2605
3511
|
name: body.name,
|
|
2606
|
-
connections: body.connections.map(
|
|
3512
|
+
connections: body.connections.map(summarizeConnectionRequest2),
|
|
2607
3513
|
workflows: body.workflows ?? []
|
|
2608
3514
|
}
|
|
2609
3515
|
});
|
|
@@ -2631,12 +3537,12 @@ function registerToolsetsCreate(toolsets) {
|
|
|
2631
3537
|
);
|
|
2632
3538
|
addUniversalOptions(cmd, { mutating: true });
|
|
2633
3539
|
cmd.action(async (opts, command) => {
|
|
2634
|
-
await runCommand(command, opts, true, () =>
|
|
3540
|
+
await runCommand(command, opts, true, () => createBody3(opts));
|
|
2635
3541
|
});
|
|
2636
3542
|
}
|
|
2637
3543
|
|
|
2638
3544
|
// src/toolsets/delete.ts
|
|
2639
|
-
async function
|
|
3545
|
+
async function deleteBody3(toolsetId, opts) {
|
|
2640
3546
|
const id = parseToolsetId(toolsetId);
|
|
2641
3547
|
if (dryRun()) {
|
|
2642
3548
|
printOutput({ would_delete: id });
|
|
@@ -2654,12 +3560,12 @@ function registerToolsetsDelete(toolsets) {
|
|
|
2654
3560
|
cmd.addHelpText("after", "\nExamples:\n engini toolsets delete <toolset_id> --force");
|
|
2655
3561
|
addUniversalOptions(cmd, { mutating: true });
|
|
2656
3562
|
cmd.action(async (id, opts, command) => {
|
|
2657
|
-
await runCommand(command, opts, true, () =>
|
|
3563
|
+
await runCommand(command, opts, true, () => deleteBody3(id, opts));
|
|
2658
3564
|
});
|
|
2659
3565
|
}
|
|
2660
3566
|
|
|
2661
3567
|
// src/toolsets/get.ts
|
|
2662
|
-
async function
|
|
3568
|
+
async function getBody7(toolsetId) {
|
|
2663
3569
|
const id = parseToolsetId(toolsetId);
|
|
2664
3570
|
const toolset = await apiErrors(async () => {
|
|
2665
3571
|
const client = buildClient();
|
|
@@ -2677,12 +3583,12 @@ function registerToolsetsGet(toolsets) {
|
|
|
2677
3583
|
cmd.addHelpText("after", "\nExamples:\n engini toolsets get <toolset_id> --json");
|
|
2678
3584
|
addUniversalOptions(cmd);
|
|
2679
3585
|
cmd.action(async (id, opts, command) => {
|
|
2680
|
-
await runCommand(command, opts, false, () =>
|
|
3586
|
+
await runCommand(command, opts, false, () => getBody7(id));
|
|
2681
3587
|
});
|
|
2682
3588
|
}
|
|
2683
3589
|
|
|
2684
3590
|
// src/toolsets/list.ts
|
|
2685
|
-
async function
|
|
3591
|
+
async function listBody8() {
|
|
2686
3592
|
const toolsets = await apiErrors(async () => {
|
|
2687
3593
|
const client = buildClient();
|
|
2688
3594
|
return client.toolsets.list();
|
|
@@ -2697,7 +3603,7 @@ function registerToolsetsList(toolsets) {
|
|
|
2697
3603
|
);
|
|
2698
3604
|
addUniversalOptions(cmd);
|
|
2699
3605
|
cmd.action(async (opts, command) => {
|
|
2700
|
-
await runCommand(command, opts, false, () =>
|
|
3606
|
+
await runCommand(command, opts, false, () => listBody8());
|
|
2701
3607
|
});
|
|
2702
3608
|
}
|
|
2703
3609
|
|
|
@@ -2727,12 +3633,12 @@ async function previewDryRun(toolsetId, body) {
|
|
|
2727
3633
|
would_update: {
|
|
2728
3634
|
toolset_id: toolsetId,
|
|
2729
3635
|
name: body.name === void 0 ? null : { from: current.name, to: body.name },
|
|
2730
|
-
connections: body.connections === void 0 ? null :
|
|
3636
|
+
connections: body.connections === void 0 ? null : diffConnections2(current.connections, body.connections),
|
|
2731
3637
|
workflows: body.workflows === void 0 ? null : diffWorkflows(current.workflows, body.workflows)
|
|
2732
3638
|
}
|
|
2733
3639
|
});
|
|
2734
3640
|
}
|
|
2735
|
-
async function
|
|
3641
|
+
async function updateBody3(toolsetId, opts) {
|
|
2736
3642
|
const id = parseToolsetId(toolsetId);
|
|
2737
3643
|
const body = buildRequestBody2(opts);
|
|
2738
3644
|
if (body.name === void 0 && body.connections === void 0 && body.workflows === void 0) {
|
|
@@ -2769,7 +3675,7 @@ function registerToolsetsUpdate(toolsets) {
|
|
|
2769
3675
|
);
|
|
2770
3676
|
addUniversalOptions(cmd, { mutating: true });
|
|
2771
3677
|
cmd.action(async (id, opts, command) => {
|
|
2772
|
-
await runCommand(command, opts, true, () =>
|
|
3678
|
+
await runCommand(command, opts, true, () => updateBody3(id, opts));
|
|
2773
3679
|
});
|
|
2774
3680
|
}
|
|
2775
3681
|
|
|
@@ -2821,6 +3727,8 @@ function buildProgram() {
|
|
|
2821
3727
|
registerApplications(program);
|
|
2822
3728
|
registerConnections(program);
|
|
2823
3729
|
registerToolsets(program);
|
|
3730
|
+
registerMcp(program);
|
|
3731
|
+
registerOpa(program);
|
|
2824
3732
|
installHelp(program);
|
|
2825
3733
|
return program;
|
|
2826
3734
|
}
|