openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
114 lines (113 loc) • 5.14 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { d as formatProviderHttpErrorMessage, h as readProviderJsonResponse, s as createProviderHttpError } from "./provider-http-errors-Dtgw3x-5.mjs";
import { o as wrapWebContent } from "./external-content-CGL7l-3s.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { C as withTrustedWebSearchEndpoint, _ as resolveSearchCacheTtlMs, b as resolveSiteName, g as readWebSearchQueryAndCount, h as readWebSearchApiKey, i as buildSearchCacheKey, o as externalContentStamp, p as readCachedSearchPayload, t as DEFAULT_SEARCH_COUNT, v as resolveSearchCount, w as writeCachedSearchPayload, y as resolveSearchTimeoutSeconds } from "./web-search-provider-common-BIurMuHZ.mjs";
import "./provider-http-LcawLneq.mjs";
import { r as mergeScopedSearchConfig, s as resolvePluginWebSearchConfig } from "./web-search-provider-config-CYzD1DF7.mjs";
import "./provider-web-search-hr4kzF3y.mjs";
//#region extensions/minimax/src/minimax-web-search-provider.runtime.ts
const MINIMAX_SEARCH_ENDPOINT_GLOBAL = "https://api.minimax.io/v1/coding_plan/search";
const MINIMAX_SEARCH_ENDPOINT_CN = "https://api.minimaxi.com/v1/coding_plan/search";
const MINIMAX_TOKEN_PLAN_ENV_VARS = [
"MINIMAX_CODE_PLAN_KEY",
"MINIMAX_CODING_API_KEY",
"MINIMAX_OAUTH_TOKEN"
];
function isMiniMaxCnHost(e) {
const t = normalizeOptionalString(e);
if (!t) return false;
return URL.parse(t)?.hostname.endsWith("minimaxi.com") ?? t.includes("minimaxi.com");
}
function resolveMiniMaxRegion(e, t) {
const n = asOptionalRecord(e?.minimax);
const r = normalizeOptionalString(n?.region);
if (r) return r === "cn" ? "cn" : "global";
if (isMiniMaxCnHost(process.env.MINIMAX_API_HOST)) return "cn";
const i = (t?.models)?.providers;
const a = i?.minimax;
const o = i?.["minimax-portal"];
const s = typeof a?.baseUrl === "string" ? a.baseUrl : "";
const c = typeof o?.baseUrl === "string" ? o.baseUrl : "";
if (isMiniMaxCnHost(s) || isMiniMaxCnHost(c)) return "cn";
return "global";
}
function missingMiniMaxKeyPayload() {
return {
error: "missing_minimax_api_key",
message: `web_search (minimax) needs a MiniMax Token Plan key or OAuth token. Run \`${formatCliCommand("openclaw configure --section web")}\` to store it, or set MINIMAX_CODE_PLAN_KEY, MINIMAX_CODING_API_KEY, MINIMAX_OAUTH_TOKEN, or MINIMAX_API_KEY in the Gateway environment.`,
docs: "https://docs.openclaw.ai/tools/web"
};
}
async function executeMiniMaxWebSearchProviderTool(e, t, n) {
const r = mergeScopedSearchConfig(e.searchConfig, "minimax", resolvePluginWebSearchConfig(e.config, "minimax"), { mirrorApiKeyToTopLevel: true });
const i = readWebSearchApiKey(r?.apiKey, "plugins.entries.minimax.config.webSearch.apiKey", [...MINIMAX_TOKEN_PLAN_ENV_VARS, "MINIMAX_API_KEY"]);
if (!i) return missingMiniMaxKeyPayload();
const { query: a, count: o } = readWebSearchQueryAndCount(t, r);
const s = resolveSearchCount(o, 5);
const c = resolveMiniMaxRegion(r, e.config) === "cn" ? MINIMAX_SEARCH_ENDPOINT_CN : MINIMAX_SEARCH_ENDPOINT_GLOBAL;
const l = buildSearchCacheKey([
"minimax",
c,
a,
s
]);
const u = resolveSearchCacheTtlMs(r);
const d = readCachedSearchPayload(l, u);
if (d) return d;
const f = Date.now();
const p = resolveSearchTimeoutSeconds(r);
const { results: m, relatedSearches: h } = await withTrustedWebSearchEndpoint({
url: c,
timeoutSeconds: p,
signal: n,
init: {
method: "POST",
headers: {
Authorization: `Bearer ${i}`,
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify({ q: a })
}
}, async (e) => {
if (!e.ok) throw await createProviderHttpError(e, "MiniMax Search API error");
const t = await readProviderJsonResponse(e, "MiniMax Search API error");
if (t.base_resp?.status_code && t.base_resp.status_code !== 0) throw new Error(formatProviderHttpErrorMessage({
label: "MiniMax Search API error",
status: t.base_resp.status_code,
detail: t.base_resp.status_msg || "unknown error"
}));
return {
results: (Array.isArray(t.organic) ? t.organic : []).slice(0, s).map((e) => {
const t = e.title ?? "";
const n = e.link ?? "";
const r = e.snippet ?? "";
return {
title: t ? wrapWebContent(t, "web_search") : "",
url: n,
description: r ? wrapWebContent(r, "web_search") : "",
published: e.date || void 0,
siteName: resolveSiteName(n) || void 0
};
}),
relatedSearches: Array.isArray(t.related_searches) ? t.related_searches.map((e) => e.query).filter((e) => typeof e === "string" && e.length > 0).map((e) => wrapWebContent(e, "web_search")) : void 0
};
});
n?.throwIfAborted();
const g = {
query: a,
provider: "minimax",
count: m.length,
tookMs: Date.now() - f,
externalContent: externalContentStamp("minimax"),
results: m
};
if (h && h.length > 0) g.relatedSearches = h;
writeCachedSearchPayload(l, g, u);
return g;
}
//#endregion
export { executeMiniMaxWebSearchProviderTool };