multicorn-shield 1.11.0 → 1.12.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.
@@ -33,9 +33,11 @@ metadata:
33
33
  > "entries": {
34
34
  > "multicorn-shield": {
35
35
  > "enabled": true,
36
- > "env": {
37
- > "MULTICORN_API_KEY": "mcs_your_key_here",
38
- > "MULTICORN_BASE_URL": "https://api.multicorn.ai"
36
+ > "config": {
37
+ > "apiKey": "${MULTICORN_API_KEY}",
38
+ > "baseUrl": "https://api.multicorn.ai",
39
+ > "agentName": "openclaw",
40
+ > "failMode": "closed"
39
41
  > }
40
42
  > }
41
43
  > }
@@ -184,7 +184,7 @@ function handleHttpError(status, logger, retryDelaySeconds) {
184
184
  if (status === 401 || status === 403) {
185
185
  if (!authErrorLogged) {
186
186
  authErrorLogged = true;
187
- const errorMsg = "[multicorn-shield] ERROR: Authentication failed. Your MULTICORN_API_KEY is invalid or expired. Check the key in your OpenClaw config (~/.openclaw/openclaw.json \u2192 plugins.entries.multicorn-shield.env.MULTICORN_API_KEY). Get a valid key from your Multicorn dashboard (Settings \u2192 API Keys).";
187
+ const errorMsg = "[multicorn-shield] ERROR: Authentication failed. Your MULTICORN_API_KEY is invalid or expired. Check the key in ~/.multicorn/config.json (from npx multicorn-shield init) or ~/.openclaw/openclaw.json \u2192 plugins.entries.multicorn-shield.config.apiKey. Get a valid key from your Multicorn dashboard (Settings \u2192 API Keys).";
188
188
  process.stderr.write(`${errorMsg}
189
189
  `);
190
190
  }
@@ -189,7 +189,7 @@ function handleHttpError(status, logger, retryDelaySeconds) {
189
189
  if (status === 401 || status === 403) {
190
190
  if (!authErrorLogged) {
191
191
  authErrorLogged = true;
192
- const errorMsg = "[multicorn-shield] ERROR: Authentication failed. Your MULTICORN_API_KEY is invalid or expired. Check the key in your OpenClaw config (~/.openclaw/openclaw.json \u2192 plugins.entries.multicorn-shield.env.MULTICORN_API_KEY). Get a valid key from your Multicorn dashboard (Settings \u2192 API Keys).";
192
+ const errorMsg = "[multicorn-shield] ERROR: Authentication failed. Your MULTICORN_API_KEY is invalid or expired. Check the key in ~/.multicorn/config.json (from npx multicorn-shield init) or ~/.openclaw/openclaw.json \u2192 plugins.entries.multicorn-shield.config.apiKey. Get a valid key from your Multicorn dashboard (Settings \u2192 API Keys).";
193
193
  logger?.error(errorMsg);
194
194
  process.stderr.write(`${errorMsg}
195
195
  `);
@@ -491,20 +491,41 @@ function agentNameFromOpenclawPlatform(cfg) {
491
491
  }
492
492
  return void 0;
493
493
  }
494
+ var ENV_REF_PATTERN = /^\$\{([A-Z_][A-Z0-9_]*)\}$/;
495
+ function resolveConfigString(value) {
496
+ const raw = asString(value);
497
+ if (raw === void 0) return void 0;
498
+ const match = ENV_REF_PATTERN.exec(raw.trim());
499
+ if (match === null) return raw;
500
+ const envName = match[1];
501
+ if (envName === void 0) return void 0;
502
+ const fromEnv = process.env[envName];
503
+ return typeof fromEnv === "string" && fromEnv.length > 0 ? fromEnv : void 0;
504
+ }
505
+ function parseFailMode(value) {
506
+ if (value === "open") return "open";
507
+ if (value === "closed") return "closed";
508
+ return "closed";
509
+ }
494
510
  function readConfig() {
495
511
  const pc = pluginConfig ?? {};
496
- const resolvedApiKey = asString(cachedMulticornConfig?.apiKey) ?? asString(process.env["MULTICORN_API_KEY"]) ?? "";
497
- const resolvedBaseUrl = asString(cachedMulticornConfig?.baseUrl) ?? asString(process.env["MULTICORN_BASE_URL"]) ?? "https://api.multicorn.ai";
512
+ const fromFileKey = asString(cachedMulticornConfig?.apiKey);
513
+ const fromPluginKey = resolveConfigString(pc["apiKey"]);
514
+ const fromEnvKey = asString(process.env["MULTICORN_API_KEY"]);
515
+ let apiKey = fromFileKey ?? fromPluginKey ?? fromEnvKey ?? "";
516
+ const fromPluginBase = resolveConfigString(pc["baseUrl"]);
517
+ const fromFileBase = asString(cachedMulticornConfig?.baseUrl);
518
+ const fromEnvBase = asString(process.env["MULTICORN_BASE_URL"]);
519
+ const baseUrl = fromPluginBase ?? fromFileBase ?? fromEnvBase ?? "https://api.multicorn.ai";
498
520
  const agentName = asString(pc["agentName"]) ?? process.env["MULTICORN_AGENT_NAME"] ?? agentNameFromOpenclawPlatform(cachedMulticornConfig) ?? asString(cachedMulticornConfig?.agentName) ?? null;
499
- const failMode = "closed";
500
- let apiKey = resolvedApiKey;
521
+ const failMode = parseFailMode(pc["failMode"]);
501
522
  if (apiKey.length > 0 && (!apiKey.startsWith("mcs_") || apiKey.length < 16)) {
502
523
  pluginLogger?.error(
503
524
  "Invalid API key format. Key must start with mcs_ and be at least 16 characters."
504
525
  );
505
526
  apiKey = "";
506
527
  }
507
- return { apiKey, baseUrl: resolvedBaseUrl, agentName, failMode };
528
+ return { apiKey, baseUrl, agentName, failMode };
508
529
  }
509
530
  function asString(value) {
510
531
  return typeof value === "string" && value.length > 0 ? value : void 0;
@@ -919,4 +940,4 @@ function resetState() {
919
940
  hasLoggedFirstAction = false;
920
941
  }
921
942
 
922
- export { afterToolCall, beforeToolCall, plugin, readConfig, register, resetState, resolveAgentName };
943
+ export { afterToolCall, beforeToolCall, plugin, readConfig, register, resetState, resolveAgentName, resolveConfigString };
@@ -9,7 +9,7 @@
9
9
  "properties": {
10
10
  "apiKey": {
11
11
  "type": "string",
12
- "pattern": "^mcs_.{12,}$",
12
+ "pattern": "^(mcs_.{12,}|\\$\\{MULTICORN_API_KEY\\})$",
13
13
  "minLength": 16
14
14
  },
15
15
  "baseUrl": {