@blockrun/clawrouter 0.12.150 → 0.12.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -106
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -80655,60 +80655,18 @@ Usage:
|
|
|
80655
80655
|
|
|
80656
80656
|
// src/mcp-config.ts
|
|
80657
80657
|
var BLOCKRUN_MCP_SERVER_NAME = "blockrun";
|
|
80658
|
-
var BLOCKRUN_MCP_NPM_SPEC = "@blockrun/mcp@latest";
|
|
80659
|
-
var BLOCKRUN_MCP_DEFAULT_TIMEOUT_MS = 3e4;
|
|
80660
80658
|
function isRecord(value) {
|
|
80661
80659
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80662
80660
|
}
|
|
80663
80661
|
function isStringArray(value) {
|
|
80664
80662
|
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
80665
80663
|
}
|
|
80666
|
-
function normalizeStringRecord(value) {
|
|
80667
|
-
if (!isRecord(value)) return void 0;
|
|
80668
|
-
const entries = Object.entries(value).filter((entry) => {
|
|
80669
|
-
return typeof entry[1] === "string";
|
|
80670
|
-
});
|
|
80671
|
-
if (entries.length === 0) return void 0;
|
|
80672
|
-
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
80673
|
-
return Object.fromEntries(entries);
|
|
80674
|
-
}
|
|
80675
|
-
function normalizeServerDefinition(server) {
|
|
80676
|
-
const normalized = {};
|
|
80677
|
-
for (const key of ["command", "url", "transport", "cwd", "connectionTimeoutMs"]) {
|
|
80678
|
-
const value = server[key];
|
|
80679
|
-
if (value !== void 0) normalized[key] = value;
|
|
80680
|
-
}
|
|
80681
|
-
if (isStringArray(server.args)) {
|
|
80682
|
-
normalized.args = [...server.args];
|
|
80683
|
-
}
|
|
80684
|
-
const env = normalizeStringRecord(server.env);
|
|
80685
|
-
if (env) normalized.env = env;
|
|
80686
|
-
const headers = normalizeStringRecord(server.headers);
|
|
80687
|
-
if (headers) normalized.headers = headers;
|
|
80688
|
-
return normalized;
|
|
80689
|
-
}
|
|
80690
80664
|
function looksLikeBlockrunPackageArgs(args) {
|
|
80691
80665
|
return args.some((arg) => arg.startsWith("@blockrun/mcp"));
|
|
80692
80666
|
}
|
|
80693
80667
|
function looksLikeLocalBlockrunDistArgs(args) {
|
|
80694
80668
|
return args.some((arg) => arg.replaceAll("\\", "/").endsWith("/blockrun-mcp/dist/index.js"));
|
|
80695
80669
|
}
|
|
80696
|
-
function createBlockrunMcpServerDefinition(opts) {
|
|
80697
|
-
const connectionTimeoutMs = opts?.connectionTimeoutMs ?? BLOCKRUN_MCP_DEFAULT_TIMEOUT_MS;
|
|
80698
|
-
if (opts?.localDistPath) {
|
|
80699
|
-
return {
|
|
80700
|
-
command: opts.nodeCommand ?? process.execPath,
|
|
80701
|
-
args: [opts.localDistPath],
|
|
80702
|
-
cwd: opts.cwd,
|
|
80703
|
-
connectionTimeoutMs
|
|
80704
|
-
};
|
|
80705
|
-
}
|
|
80706
|
-
return {
|
|
80707
|
-
command: "npx",
|
|
80708
|
-
args: ["-y", BLOCKRUN_MCP_NPM_SPEC],
|
|
80709
|
-
connectionTimeoutMs
|
|
80710
|
-
};
|
|
80711
|
-
}
|
|
80712
80670
|
function isManagedBlockrunMcpServerDefinition(value) {
|
|
80713
80671
|
if (!isRecord(value)) return false;
|
|
80714
80672
|
const args = isStringArray(value.args) ? value.args : [];
|
|
@@ -80717,35 +80675,6 @@ function isManagedBlockrunMcpServerDefinition(value) {
|
|
|
80717
80675
|
}
|
|
80718
80676
|
return looksLikeLocalBlockrunDistArgs(args);
|
|
80719
80677
|
}
|
|
80720
|
-
function ensureBlockrunMcpServerConfig(config, desiredServer) {
|
|
80721
|
-
if (!config.mcp || typeof config.mcp !== "object" || Array.isArray(config.mcp)) {
|
|
80722
|
-
config.mcp = {};
|
|
80723
|
-
}
|
|
80724
|
-
const mcp = config.mcp;
|
|
80725
|
-
if (!mcp.servers || typeof mcp.servers !== "object" || Array.isArray(mcp.servers)) {
|
|
80726
|
-
mcp.servers = {};
|
|
80727
|
-
}
|
|
80728
|
-
const servers = mcp.servers;
|
|
80729
|
-
const existing = servers[BLOCKRUN_MCP_SERVER_NAME];
|
|
80730
|
-
if (!existing) {
|
|
80731
|
-
servers[BLOCKRUN_MCP_SERVER_NAME] = desiredServer;
|
|
80732
|
-
return { changed: true, status: "added" };
|
|
80733
|
-
}
|
|
80734
|
-
if (!isRecord(existing)) {
|
|
80735
|
-
servers[BLOCKRUN_MCP_SERVER_NAME] = desiredServer;
|
|
80736
|
-
return { changed: true, status: "updated" };
|
|
80737
|
-
}
|
|
80738
|
-
if (!isManagedBlockrunMcpServerDefinition(existing)) {
|
|
80739
|
-
return { changed: false, status: "preserved" };
|
|
80740
|
-
}
|
|
80741
|
-
const existingNormalized = JSON.stringify(normalizeServerDefinition(existing));
|
|
80742
|
-
const desiredNormalized = JSON.stringify(normalizeServerDefinition(desiredServer));
|
|
80743
|
-
if (existingNormalized === desiredNormalized) {
|
|
80744
|
-
return { changed: false, status: "unchanged" };
|
|
80745
|
-
}
|
|
80746
|
-
servers[BLOCKRUN_MCP_SERVER_NAME] = desiredServer;
|
|
80747
|
-
return { changed: true, status: "updated" };
|
|
80748
|
-
}
|
|
80749
80678
|
function removeManagedBlockrunMcpServerConfig(config) {
|
|
80750
80679
|
if (!config.mcp || typeof config.mcp !== "object" || Array.isArray(config.mcp)) {
|
|
80751
80680
|
return false;
|
|
@@ -81146,26 +81075,7 @@ function isGatewayMode() {
|
|
|
81146
81075
|
const args = process.argv;
|
|
81147
81076
|
return args.includes("gateway");
|
|
81148
81077
|
}
|
|
81149
|
-
function
|
|
81150
|
-
const packageRoot = getPackageRoot();
|
|
81151
|
-
const siblingRepoRoot = join10(packageRoot, "..", "blockrun-mcp");
|
|
81152
|
-
const siblingDistEntry = join10(siblingRepoRoot, "dist", "index.js");
|
|
81153
|
-
if (existsSync3(siblingDistEntry)) {
|
|
81154
|
-
return {
|
|
81155
|
-
definition: createBlockrunMcpServerDefinition({
|
|
81156
|
-
localDistPath: siblingDistEntry,
|
|
81157
|
-
cwd: siblingRepoRoot,
|
|
81158
|
-
nodeCommand: process.execPath
|
|
81159
|
-
}),
|
|
81160
|
-
source: "local"
|
|
81161
|
-
};
|
|
81162
|
-
}
|
|
81163
|
-
return {
|
|
81164
|
-
definition: createBlockrunMcpServerDefinition(),
|
|
81165
|
-
source: "npm"
|
|
81166
|
-
};
|
|
81167
|
-
}
|
|
81168
|
-
function injectModelsConfig(logger, blockrunMcpServer) {
|
|
81078
|
+
function injectModelsConfig(logger) {
|
|
81169
81079
|
const configDir = join10(homedir7(), ".openclaw");
|
|
81170
81080
|
const configPath = join10(configDir, "openclaw.json");
|
|
81171
81081
|
let config = {};
|
|
@@ -81370,11 +81280,10 @@ function injectModelsConfig(logger, blockrunMcpServer) {
|
|
|
81370
81280
|
search.enabled = true;
|
|
81371
81281
|
needsWrite = true;
|
|
81372
81282
|
}
|
|
81373
|
-
|
|
81374
|
-
if (mcpResult.changed) {
|
|
81283
|
+
if (removeManagedBlockrunMcpServerConfig(config)) {
|
|
81375
81284
|
needsWrite = true;
|
|
81376
81285
|
logger.info(
|
|
81377
|
-
|
|
81286
|
+
`Removed bundled BlockRun MCP server config (${BLOCKRUN_MCP_SERVER_NAME}) \u2014 restart the gateway to free any leaked processes`
|
|
81378
81287
|
);
|
|
81379
81288
|
}
|
|
81380
81289
|
if (needsWrite) {
|
|
@@ -82104,7 +82013,6 @@ var plugin = {
|
|
|
82104
82013
|
api.registerProvider(blockrunProvider);
|
|
82105
82014
|
api.registerImageGenerationProvider(buildImageGenerationProvider());
|
|
82106
82015
|
api.registerMusicGenerationProvider(buildMusicGenerationProvider());
|
|
82107
|
-
const blockrunMcpServer = resolveBlockrunMcpServerDefinition();
|
|
82108
82016
|
if (typeof api.registerWebSearchProvider === "function") {
|
|
82109
82017
|
api.registerWebSearchProvider(blockrunExaWebSearchProvider);
|
|
82110
82018
|
} else {
|
|
@@ -82112,7 +82020,7 @@ var plugin = {
|
|
|
82112
82020
|
"OpenClaw runtime does not expose registerWebSearchProvider(); blockrun-exa search is unavailable on this version."
|
|
82113
82021
|
);
|
|
82114
82022
|
}
|
|
82115
|
-
injectModelsConfig(api.logger
|
|
82023
|
+
injectModelsConfig(api.logger);
|
|
82116
82024
|
injectAuthProfile(api.logger);
|
|
82117
82025
|
const runtimePort = getProxyPort();
|
|
82118
82026
|
if (!api.config.models) {
|
|
@@ -82139,10 +82047,7 @@ var plugin = {
|
|
|
82139
82047
|
}
|
|
82140
82048
|
api.config.tools.web.search.provider = BLOCKRUN_EXA_PROVIDER_ID;
|
|
82141
82049
|
api.config.tools.web.search.enabled = true;
|
|
82142
|
-
const
|
|
82143
|
-
api.config,
|
|
82144
|
-
blockrunMcpServer.definition
|
|
82145
|
-
);
|
|
82050
|
+
const runtimeMcpRemoved = removeManagedBlockrunMcpServerConfig(api.config);
|
|
82146
82051
|
const shouldLogRegistration = !proc.__clawrouterRegistrationLogged;
|
|
82147
82052
|
proc.__clawrouterRegistrationLogged = true;
|
|
82148
82053
|
if (shouldLogRegistration) {
|
|
@@ -82150,13 +82055,9 @@ var plugin = {
|
|
|
82150
82055
|
if (typeof api.registerWebSearchProvider === "function") {
|
|
82151
82056
|
api.logger.info(`Registered BlockRun web_search provider (${BLOCKRUN_EXA_PROVIDER_ID})`);
|
|
82152
82057
|
}
|
|
82153
|
-
if (
|
|
82154
|
-
api.logger.info(
|
|
82155
|
-
blockrunMcpServer.source === "local" ? `Configured BlockRun MCP server (${BLOCKRUN_MCP_SERVER_NAME}) from local blockrun-mcp build` : `Configured BlockRun MCP server (${BLOCKRUN_MCP_SERVER_NAME}) via npx @blockrun/mcp@latest`
|
|
82156
|
-
);
|
|
82157
|
-
} else if (runtimeMcpResult.status === "preserved") {
|
|
82058
|
+
if (runtimeMcpRemoved) {
|
|
82158
82059
|
api.logger.info(
|
|
82159
|
-
`
|
|
82060
|
+
`Removed bundled BlockRun MCP server config (${BLOCKRUN_MCP_SERVER_NAME}) \u2014 restart the gateway to free any leaked processes`
|
|
82160
82061
|
);
|
|
82161
82062
|
}
|
|
82162
82063
|
}
|