@openclaw/moonshot-provider 0.0.0 → 2026.6.11-beta.2
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 +12 -2
- package/dist/api.js +3 -0
- package/dist/index.js +67 -0
- package/dist/kimi-web-search-provider-pERL62H1.js +80 -0
- package/dist/kimi-web-search-provider.runtime-DvaZLHkr.js +299 -0
- package/dist/media-understanding-provider.js +66 -0
- package/dist/onboard.js +30 -0
- package/dist/provider-catalog-BGSHIo8D.js +121 -0
- package/dist/provider-catalog.js +2 -0
- package/dist/provider-contract-api.js +27 -0
- package/dist/provider-discovery.js +15 -0
- package/dist/provider-policy-api.js +24 -0
- package/dist/web-search-contract-api.js +29 -0
- package/dist/web-search-provider.js +2 -0
- package/npm-shrinkwrap.json +12 -0
- package/openclaw.plugin.json +232 -0
- package/package.json +44 -7
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Moonshot OpenClaw provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official OpenClaw provider plugin for Moonshot.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
openclaw plugins install @openclaw/moonshot-provider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Docs
|
|
12
|
+
|
|
13
|
+
See `docs/providers/moonshot.md` in the OpenClaw repository, or the published docs at `https://docs.openclaw.ai/providers/moonshot`.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as buildMoonshotProvider, i as applyMoonshotNativeStreamingUsageCompat, n as MOONSHOT_CN_BASE_URL, o as isNativeMoonshotBaseUrl, r as MOONSHOT_DEFAULT_MODEL_ID, t as MOONSHOT_BASE_URL } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
import { MOONSHOT_DEFAULT_MODEL_REF } from "./onboard.js";
|
|
3
|
+
export { MOONSHOT_BASE_URL, MOONSHOT_CN_BASE_URL, MOONSHOT_DEFAULT_MODEL_ID, MOONSHOT_DEFAULT_MODEL_REF, applyMoonshotNativeStreamingUsageCompat, buildMoonshotProvider, isNativeMoonshotBaseUrl };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { a as buildMoonshotProvider, i as applyMoonshotNativeStreamingUsageCompat } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
import { MOONSHOT_DEFAULT_MODEL_REF, applyMoonshotConfig, applyMoonshotConfigCn } from "./onboard.js";
|
|
3
|
+
import "./api.js";
|
|
4
|
+
import { moonshotMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
|
5
|
+
import { KIMI_K2_7_CODE_MODEL_ID, resolveThinkingProfile } from "./provider-policy-api.js";
|
|
6
|
+
import { t as createKimiWebSearchProvider } from "./kimi-web-search-provider-pERL62H1.js";
|
|
7
|
+
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
|
|
8
|
+
import { buildOpenAICompatibleReplayPolicy } from "openclaw/plugin-sdk/provider-model-shared";
|
|
9
|
+
import { MOONSHOT_THINKING_STREAM_HOOKS } from "openclaw/plugin-sdk/provider-stream-family";
|
|
10
|
+
//#region extensions/moonshot/index.ts
|
|
11
|
+
const PROVIDER_ID = "moonshot";
|
|
12
|
+
const moonshotThinkingStreamHooks = MOONSHOT_THINKING_STREAM_HOOKS;
|
|
13
|
+
var moonshot_default = defineSingleProviderPluginEntry({
|
|
14
|
+
id: PROVIDER_ID,
|
|
15
|
+
name: "Moonshot Provider",
|
|
16
|
+
description: "Bundled Moonshot provider plugin",
|
|
17
|
+
provider: {
|
|
18
|
+
label: "Moonshot",
|
|
19
|
+
docsPath: "/providers/moonshot",
|
|
20
|
+
aliases: ["moonshotai", "moonshot-ai"],
|
|
21
|
+
auth: [{
|
|
22
|
+
methodId: "api-key",
|
|
23
|
+
label: "Kimi API key (.ai)",
|
|
24
|
+
hint: "Kimi K2.6 + Kimi",
|
|
25
|
+
optionKey: "moonshotApiKey",
|
|
26
|
+
flagName: "--moonshot-api-key",
|
|
27
|
+
envVar: "MOONSHOT_API_KEY",
|
|
28
|
+
promptMessage: "Enter Moonshot API key",
|
|
29
|
+
defaultModel: MOONSHOT_DEFAULT_MODEL_REF,
|
|
30
|
+
applyConfig: (cfg) => applyMoonshotConfig(cfg),
|
|
31
|
+
wizard: { groupLabel: "Moonshot AI (Kimi K2.6)" }
|
|
32
|
+
}, {
|
|
33
|
+
methodId: "api-key-cn",
|
|
34
|
+
label: "Kimi API key (.cn)",
|
|
35
|
+
hint: "Kimi K2.6 + Kimi",
|
|
36
|
+
optionKey: "moonshotApiKey",
|
|
37
|
+
flagName: "--moonshot-api-key",
|
|
38
|
+
envVar: "MOONSHOT_API_KEY",
|
|
39
|
+
promptMessage: "Enter Moonshot API key (.cn)",
|
|
40
|
+
defaultModel: MOONSHOT_DEFAULT_MODEL_REF,
|
|
41
|
+
applyConfig: (cfg) => applyMoonshotConfigCn(cfg),
|
|
42
|
+
wizard: { groupLabel: "Moonshot AI (Kimi K2.6)" }
|
|
43
|
+
}],
|
|
44
|
+
catalog: {
|
|
45
|
+
buildProvider: buildMoonshotProvider,
|
|
46
|
+
buildStaticProvider: buildMoonshotProvider,
|
|
47
|
+
allowExplicitBaseUrl: true
|
|
48
|
+
},
|
|
49
|
+
applyNativeStreamingUsageCompat: ({ providerConfig }) => applyMoonshotNativeStreamingUsageCompat(providerConfig),
|
|
50
|
+
buildReplayPolicy: ({ modelApi, modelId }) => buildOpenAICompatibleReplayPolicy(modelApi, {
|
|
51
|
+
modelId,
|
|
52
|
+
sanitizeToolCallIds: modelApi === "openai-completions",
|
|
53
|
+
duplicateToolCallIdStyle: "openai",
|
|
54
|
+
dropReasoningFromHistory: false
|
|
55
|
+
}),
|
|
56
|
+
...moonshotThinkingStreamHooks,
|
|
57
|
+
wrapSimpleCompletionStreamFn: (ctx) => ctx.modelId.trim().toLowerCase() === "kimi-k2.7-code" ? moonshotThinkingStreamHooks.wrapStreamFn?.(ctx) : ctx.streamFn,
|
|
58
|
+
resolveThinkingProfile,
|
|
59
|
+
isModernModelRef: ({ modelId }) => modelId.trim().toLowerCase() === KIMI_K2_7_CODE_MODEL_ID
|
|
60
|
+
},
|
|
61
|
+
register(api) {
|
|
62
|
+
api.registerMediaUnderstandingProvider(moonshotMediaUnderstandingProvider);
|
|
63
|
+
api.registerWebSearchProvider(createKimiWebSearchProvider());
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
//#endregion
|
|
67
|
+
export { moonshot_default as default };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createWebSearchProviderContractFields } from "openclaw/plugin-sdk/provider-web-search-config-contract";
|
|
2
|
+
//#region extensions/moonshot/src/kimi-web-search-provider.ts
|
|
3
|
+
const KIMI_CREDENTIAL_PATH = "plugins.entries.moonshot.config.webSearch.apiKey";
|
|
4
|
+
let kimiWebSearchProviderRuntimePromise;
|
|
5
|
+
function loadKimiWebSearchProviderRuntime() {
|
|
6
|
+
kimiWebSearchProviderRuntimePromise ??= import("./kimi-web-search-provider.runtime-DvaZLHkr.js");
|
|
7
|
+
return kimiWebSearchProviderRuntimePromise;
|
|
8
|
+
}
|
|
9
|
+
const KimiSearchSchema = {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
query: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Search query string."
|
|
15
|
+
},
|
|
16
|
+
count: {
|
|
17
|
+
type: "integer",
|
|
18
|
+
description: "Number of results to return (1-10).",
|
|
19
|
+
minimum: 1,
|
|
20
|
+
maximum: 10
|
|
21
|
+
},
|
|
22
|
+
country: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: "Not supported by Kimi."
|
|
25
|
+
},
|
|
26
|
+
language: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Not supported by Kimi."
|
|
29
|
+
},
|
|
30
|
+
freshness: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Not supported by Kimi."
|
|
33
|
+
},
|
|
34
|
+
date_after: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Not supported by Kimi."
|
|
37
|
+
},
|
|
38
|
+
date_before: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Not supported by Kimi."
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
async function runKimiSearchProviderSetup(ctx) {
|
|
45
|
+
return await (await loadKimiWebSearchProviderRuntime()).runKimiSearchProviderSetup(ctx);
|
|
46
|
+
}
|
|
47
|
+
function createKimiWebSearchProvider() {
|
|
48
|
+
return {
|
|
49
|
+
id: "kimi",
|
|
50
|
+
label: "Kimi (Moonshot)",
|
|
51
|
+
hint: "Requires Moonshot / Kimi API key · Moonshot web search",
|
|
52
|
+
onboardingScopes: ["text-inference"],
|
|
53
|
+
credentialLabel: "Moonshot / Kimi API key",
|
|
54
|
+
envVars: ["KIMI_API_KEY", "MOONSHOT_API_KEY"],
|
|
55
|
+
placeholder: "sk-...",
|
|
56
|
+
signupUrl: "https://platform.moonshot.cn/",
|
|
57
|
+
docsUrl: "https://docs.openclaw.ai/tools/web",
|
|
58
|
+
autoDetectOrder: 40,
|
|
59
|
+
credentialPath: KIMI_CREDENTIAL_PATH,
|
|
60
|
+
...createWebSearchProviderContractFields({
|
|
61
|
+
credentialPath: KIMI_CREDENTIAL_PATH,
|
|
62
|
+
searchCredential: {
|
|
63
|
+
type: "scoped",
|
|
64
|
+
scopeId: "kimi"
|
|
65
|
+
},
|
|
66
|
+
configuredCredential: { pluginId: "moonshot" }
|
|
67
|
+
}),
|
|
68
|
+
runSetup: runKimiSearchProviderSetup,
|
|
69
|
+
createTool: (ctx) => ({
|
|
70
|
+
description: "Search the web using Kimi by Moonshot. Returns AI-synthesized answers with citations from native $web_search.",
|
|
71
|
+
parameters: KimiSearchSchema,
|
|
72
|
+
execute: async (args) => {
|
|
73
|
+
const { executeKimiWebSearchProviderTool } = await loadKimiWebSearchProviderRuntime();
|
|
74
|
+
return await executeKimiWebSearchProviderTool(ctx, args);
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createKimiWebSearchProvider as t };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { n as MOONSHOT_CN_BASE_URL, o as isNativeMoonshotBaseUrl, r as MOONSHOT_DEFAULT_MODEL_ID, t as MOONSHOT_BASE_URL } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
import { createProviderHttpError, readProviderJsonObjectResponse } from "openclaw/plugin-sdk/provider-http";
|
|
3
|
+
import { DEFAULT_SEARCH_COUNT, MAX_SEARCH_COUNT, buildSearchCacheKey, buildUnsupportedSearchFilterResponse, mergeScopedSearchConfig, readCachedSearchPayload, readConfiguredSecretString, readPositiveIntegerParam, readProviderEnvValue, readStringParam, resolveProviderWebSearchPluginConfig, resolveSearchCacheTtlMs, resolveSearchCount, resolveSearchTimeoutSeconds, setProviderWebSearchPluginConfigValue, withTrustedWebSearchEndpoint, wrapWebContent, writeCachedSearchPayload } from "openclaw/plugin-sdk/provider-web-search";
|
|
4
|
+
import { isRecord, normalizeOptionalString, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
5
|
+
//#region extensions/moonshot/src/kimi-web-search-provider.runtime.ts
|
|
6
|
+
const DEFAULT_KIMI_BASE_URL = MOONSHOT_BASE_URL;
|
|
7
|
+
const DEFAULT_KIMI_SEARCH_MODEL = MOONSHOT_DEFAULT_MODEL_ID;
|
|
8
|
+
/** Models that require explicit thinking disablement for web search.
|
|
9
|
+
* Reasoning variants (kimi-k2-thinking, kimi-k2-thinking-turbo) are excluded
|
|
10
|
+
* because they default to thinking-enabled and disabling it would defeat their
|
|
11
|
+
* purpose; they are also unlikely to be used for web search. */
|
|
12
|
+
const KIMI_THINKING_MODELS = new Set(["kimi-k2.6", "kimi-k2.5"]);
|
|
13
|
+
const KIMI_WEB_SEARCH_TOOL = {
|
|
14
|
+
type: "builtin_function",
|
|
15
|
+
function: { name: "$web_search" }
|
|
16
|
+
};
|
|
17
|
+
function throwMalformedKimiResponse() {
|
|
18
|
+
throw new Error("Kimi API error: malformed JSON response");
|
|
19
|
+
}
|
|
20
|
+
function resolveKimiConfig(searchConfig) {
|
|
21
|
+
const kimi = searchConfig?.kimi;
|
|
22
|
+
return kimi && typeof kimi === "object" && !Array.isArray(kimi) ? kimi : {};
|
|
23
|
+
}
|
|
24
|
+
function resolveKimiApiKey(kimi) {
|
|
25
|
+
return readConfiguredSecretString(kimi?.apiKey, "tools.web.search.kimi.apiKey") ?? readProviderEnvValue(["KIMI_API_KEY", "MOONSHOT_API_KEY"]);
|
|
26
|
+
}
|
|
27
|
+
function resolveKimiModel(kimi) {
|
|
28
|
+
return (normalizeOptionalString(kimi?.model) ?? "") || DEFAULT_KIMI_SEARCH_MODEL;
|
|
29
|
+
}
|
|
30
|
+
function trimTrailingSlashes(url) {
|
|
31
|
+
return url.replace(/\/+$/, "");
|
|
32
|
+
}
|
|
33
|
+
function resolveKimiBaseUrl(kimi, openClawConfig) {
|
|
34
|
+
const explicitBaseUrl = normalizeOptionalString(kimi?.baseUrl) ?? "";
|
|
35
|
+
if (explicitBaseUrl) return trimTrailingSlashes(explicitBaseUrl) || DEFAULT_KIMI_BASE_URL;
|
|
36
|
+
const moonshotBaseUrl = openClawConfig?.models?.providers?.moonshot?.baseUrl;
|
|
37
|
+
if (typeof moonshotBaseUrl === "string") {
|
|
38
|
+
const normalizedMoonshotBaseUrl = trimTrailingSlashes(moonshotBaseUrl.trim());
|
|
39
|
+
if (normalizedMoonshotBaseUrl && isNativeMoonshotBaseUrl(normalizedMoonshotBaseUrl)) return normalizedMoonshotBaseUrl;
|
|
40
|
+
}
|
|
41
|
+
return DEFAULT_KIMI_BASE_URL;
|
|
42
|
+
}
|
|
43
|
+
function extractKimiMessageText(message) {
|
|
44
|
+
const content = message?.content?.trim();
|
|
45
|
+
if (content) return content;
|
|
46
|
+
return message?.reasoning_content?.trim() || void 0;
|
|
47
|
+
}
|
|
48
|
+
function extractKimiCitations(data) {
|
|
49
|
+
const searchResults = data.search_results ?? [];
|
|
50
|
+
if (!Array.isArray(searchResults)) throwMalformedKimiResponse();
|
|
51
|
+
const citations = searchResults.map((entry) => isRecord(entry) && typeof entry.url === "string" ? entry.url.trim() : "").filter((url) => Boolean(url));
|
|
52
|
+
const choices = data.choices ?? [];
|
|
53
|
+
if (!Array.isArray(choices)) throwMalformedKimiResponse();
|
|
54
|
+
const firstChoice = choices[0];
|
|
55
|
+
const toolCalls = (firstChoice && isRecord(firstChoice.message) ? firstChoice.message : void 0)?.tool_calls ?? [];
|
|
56
|
+
if (!Array.isArray(toolCalls)) throwMalformedKimiResponse();
|
|
57
|
+
for (const toolCall of toolCalls) {
|
|
58
|
+
if (!isRecord(toolCall) || !isRecord(toolCall.function)) continue;
|
|
59
|
+
const rawArguments = toolCall.function.arguments;
|
|
60
|
+
if (typeof rawArguments !== "string" || !rawArguments) continue;
|
|
61
|
+
try {
|
|
62
|
+
const parsed = JSON.parse(rawArguments);
|
|
63
|
+
const parsedUrl = normalizeOptionalString(parsed.url);
|
|
64
|
+
if (parsedUrl) citations.push(parsedUrl);
|
|
65
|
+
for (const result of parsed.search_results ?? []) {
|
|
66
|
+
const resultUrl = normalizeOptionalString(result.url);
|
|
67
|
+
if (resultUrl) citations.push(resultUrl);
|
|
68
|
+
}
|
|
69
|
+
} catch {}
|
|
70
|
+
}
|
|
71
|
+
return uniqueStrings(citations);
|
|
72
|
+
}
|
|
73
|
+
function hasKimiSearchResults(data) {
|
|
74
|
+
const searchResults = data.search_results ?? [];
|
|
75
|
+
if (!Array.isArray(searchResults)) throwMalformedKimiResponse();
|
|
76
|
+
return searchResults.some((entry) => isRecord(entry) && (Boolean(normalizeOptionalString(entry.url)) || Boolean(normalizeOptionalString(entry.title)) || Boolean(normalizeOptionalString(entry.content))));
|
|
77
|
+
}
|
|
78
|
+
function extractKimiToolResultContent(toolCall) {
|
|
79
|
+
const rawArguments = toolCall.function?.arguments;
|
|
80
|
+
if (typeof rawArguments !== "string" || rawArguments.trim().length === 0) return;
|
|
81
|
+
return rawArguments;
|
|
82
|
+
}
|
|
83
|
+
async function runKimiSearch(params) {
|
|
84
|
+
const endpoint = `${params.baseUrl.trim().replace(/\/$/, "")}/chat/completions`;
|
|
85
|
+
const messages = [{
|
|
86
|
+
role: "user",
|
|
87
|
+
content: params.query
|
|
88
|
+
}];
|
|
89
|
+
const collectedCitations = /* @__PURE__ */ new Set();
|
|
90
|
+
let hasGroundingEvidence = false;
|
|
91
|
+
for (let round = 0; round < 3; round += 1) {
|
|
92
|
+
const next = await withTrustedWebSearchEndpoint({
|
|
93
|
+
url: endpoint,
|
|
94
|
+
timeoutSeconds: params.timeoutSeconds,
|
|
95
|
+
init: {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: {
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
Authorization: `Bearer ${params.apiKey}`
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify({
|
|
102
|
+
model: params.model,
|
|
103
|
+
...KIMI_THINKING_MODELS.has(params.model) ? { thinking: { type: "disabled" } } : {},
|
|
104
|
+
messages,
|
|
105
|
+
tools: [KIMI_WEB_SEARCH_TOOL]
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}, async (res) => {
|
|
109
|
+
if (!res.ok) throw await createProviderHttpError(res, "Kimi API error");
|
|
110
|
+
const data = await readProviderJsonObjectResponse(res, "Kimi API error");
|
|
111
|
+
if (!Array.isArray(data.choices)) throwMalformedKimiResponse();
|
|
112
|
+
if (hasKimiSearchResults(data)) hasGroundingEvidence = true;
|
|
113
|
+
for (const citation of extractKimiCitations(data)) collectedCitations.add(citation);
|
|
114
|
+
if (collectedCitations.size > 0) hasGroundingEvidence = true;
|
|
115
|
+
const choice = data.choices?.[0];
|
|
116
|
+
if (!isRecord(choice) || !isRecord(choice.message)) throwMalformedKimiResponse();
|
|
117
|
+
const message = choice?.message;
|
|
118
|
+
const text = extractKimiMessageText(message);
|
|
119
|
+
const toolCalls = message?.tool_calls ?? [];
|
|
120
|
+
if (!Array.isArray(toolCalls)) throwMalformedKimiResponse();
|
|
121
|
+
if (choice?.finish_reason !== "tool_calls" || toolCalls.length === 0) {
|
|
122
|
+
if (!text) throwMalformedKimiResponse();
|
|
123
|
+
return {
|
|
124
|
+
done: true,
|
|
125
|
+
content: text,
|
|
126
|
+
citations: [...collectedCitations]
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
messages.push({
|
|
130
|
+
role: "assistant",
|
|
131
|
+
content: message?.content ?? "",
|
|
132
|
+
...message?.reasoning_content ? { reasoning_content: message.reasoning_content } : {},
|
|
133
|
+
tool_calls: toolCalls
|
|
134
|
+
});
|
|
135
|
+
let pushed = false;
|
|
136
|
+
for (const toolCall of toolCalls) {
|
|
137
|
+
const toolCallId = toolCall.id?.trim();
|
|
138
|
+
const toolCallName = toolCall.function?.name?.trim();
|
|
139
|
+
const toolContent = extractKimiToolResultContent(toolCall);
|
|
140
|
+
if (!toolCallId || !toolCallName || !toolContent) continue;
|
|
141
|
+
if (toolCallName === KIMI_WEB_SEARCH_TOOL.function.name) hasGroundingEvidence = true;
|
|
142
|
+
pushed = true;
|
|
143
|
+
messages.push({
|
|
144
|
+
role: "tool",
|
|
145
|
+
tool_call_id: toolCallId,
|
|
146
|
+
name: toolCallName,
|
|
147
|
+
content: toolContent
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (!pushed) {
|
|
151
|
+
if (!text) throwMalformedKimiResponse();
|
|
152
|
+
return {
|
|
153
|
+
done: true,
|
|
154
|
+
content: text,
|
|
155
|
+
citations: [...collectedCitations]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return { done: false };
|
|
159
|
+
});
|
|
160
|
+
if (next.done) return {
|
|
161
|
+
content: next.content,
|
|
162
|
+
citations: next.citations,
|
|
163
|
+
grounded: hasGroundingEvidence
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
content: "Search completed but no final answer was produced.",
|
|
168
|
+
citations: [...collectedCitations],
|
|
169
|
+
grounded: hasGroundingEvidence
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async function executeKimiWebSearchProviderTool(ctx, args) {
|
|
173
|
+
const searchConfig = mergeScopedSearchConfig(ctx.searchConfig, "kimi", resolveProviderWebSearchPluginConfig(ctx.config, "moonshot"));
|
|
174
|
+
const unsupportedResponse = buildUnsupportedSearchFilterResponse(args, "kimi");
|
|
175
|
+
if (unsupportedResponse) return unsupportedResponse;
|
|
176
|
+
const kimiConfig = resolveKimiConfig(searchConfig);
|
|
177
|
+
const apiKey = resolveKimiApiKey(kimiConfig);
|
|
178
|
+
if (!apiKey) return {
|
|
179
|
+
error: "missing_kimi_api_key",
|
|
180
|
+
message: "web_search (kimi) needs a Moonshot API key. Set KIMI_API_KEY or MOONSHOT_API_KEY in the Gateway environment, or configure tools.web.search.kimi.apiKey. If you do not want to configure a search API key, use web_fetch for a specific URL or the browser tool for interactive pages.",
|
|
181
|
+
docs: "https://docs.openclaw.ai/tools/web"
|
|
182
|
+
};
|
|
183
|
+
const query = readStringParam(args, "query", { required: true });
|
|
184
|
+
const count = readPositiveIntegerParam(args, "count", {
|
|
185
|
+
max: MAX_SEARCH_COUNT,
|
|
186
|
+
message: `count must be an integer from 1 to ${MAX_SEARCH_COUNT}.`
|
|
187
|
+
}) ?? searchConfig?.maxResults ?? void 0;
|
|
188
|
+
const model = resolveKimiModel(kimiConfig);
|
|
189
|
+
const baseUrl = resolveKimiBaseUrl(kimiConfig, ctx.config);
|
|
190
|
+
const cacheKey = buildSearchCacheKey([
|
|
191
|
+
"kimi",
|
|
192
|
+
query,
|
|
193
|
+
resolveSearchCount(count, DEFAULT_SEARCH_COUNT),
|
|
194
|
+
baseUrl,
|
|
195
|
+
model
|
|
196
|
+
]);
|
|
197
|
+
const cached = readCachedSearchPayload(cacheKey);
|
|
198
|
+
if (cached) return cached;
|
|
199
|
+
const start = Date.now();
|
|
200
|
+
const result = await runKimiSearch({
|
|
201
|
+
query,
|
|
202
|
+
apiKey,
|
|
203
|
+
baseUrl,
|
|
204
|
+
model,
|
|
205
|
+
timeoutSeconds: resolveSearchTimeoutSeconds(searchConfig)
|
|
206
|
+
});
|
|
207
|
+
if (!result.grounded) return {
|
|
208
|
+
error: "kimi_web_search_ungrounded",
|
|
209
|
+
message: "Kimi returned a chat completion without native web-search grounding. Retry the query, switch to a structured provider such as Brave, or use web_fetch/browser for a specific URL.",
|
|
210
|
+
query,
|
|
211
|
+
provider: "kimi",
|
|
212
|
+
model,
|
|
213
|
+
docs: "https://docs.openclaw.ai/tools/kimi-search",
|
|
214
|
+
tookMs: Date.now() - start
|
|
215
|
+
};
|
|
216
|
+
const payload = {
|
|
217
|
+
query,
|
|
218
|
+
provider: "kimi",
|
|
219
|
+
model,
|
|
220
|
+
tookMs: Date.now() - start,
|
|
221
|
+
externalContent: {
|
|
222
|
+
untrusted: true,
|
|
223
|
+
source: "web_search",
|
|
224
|
+
provider: "kimi",
|
|
225
|
+
wrapped: true
|
|
226
|
+
},
|
|
227
|
+
content: wrapWebContent(result.content),
|
|
228
|
+
citations: result.citations
|
|
229
|
+
};
|
|
230
|
+
writeCachedSearchPayload(cacheKey, payload, resolveSearchCacheTtlMs(searchConfig));
|
|
231
|
+
return payload;
|
|
232
|
+
}
|
|
233
|
+
async function runKimiSearchProviderSetup(ctx) {
|
|
234
|
+
const existingPluginConfig = resolveProviderWebSearchPluginConfig(ctx.config, "moonshot");
|
|
235
|
+
const normalizedBaseUrl = (normalizeOptionalString(existingPluginConfig?.baseUrl) ?? "").replace(/\/+$/, "");
|
|
236
|
+
const existingModel = normalizeOptionalString(existingPluginConfig?.model) ?? "";
|
|
237
|
+
const isCustomBaseUrl = normalizedBaseUrl && !isNativeMoonshotBaseUrl(normalizedBaseUrl);
|
|
238
|
+
const regionOptions = [];
|
|
239
|
+
if (isCustomBaseUrl) regionOptions.push({
|
|
240
|
+
value: normalizedBaseUrl,
|
|
241
|
+
label: `Keep current (${normalizedBaseUrl})`,
|
|
242
|
+
hint: "custom endpoint"
|
|
243
|
+
});
|
|
244
|
+
regionOptions.push({
|
|
245
|
+
value: MOONSHOT_BASE_URL,
|
|
246
|
+
label: "Moonshot API key (.ai)",
|
|
247
|
+
hint: "api.moonshot.ai"
|
|
248
|
+
}, {
|
|
249
|
+
value: MOONSHOT_CN_BASE_URL,
|
|
250
|
+
label: "Moonshot API key (.cn)",
|
|
251
|
+
hint: "api.moonshot.cn"
|
|
252
|
+
});
|
|
253
|
+
const baseUrl = await ctx.prompter.select({
|
|
254
|
+
message: "Kimi API region",
|
|
255
|
+
options: regionOptions,
|
|
256
|
+
initialValue: normalizedBaseUrl || "https://api.moonshot.ai/v1"
|
|
257
|
+
});
|
|
258
|
+
const currentModelLabel = existingModel ? `Keep current (moonshot/${existingModel})` : `Use default (moonshot/${DEFAULT_KIMI_SEARCH_MODEL})`;
|
|
259
|
+
const modelChoice = await ctx.prompter.select({
|
|
260
|
+
message: "Kimi web search model",
|
|
261
|
+
options: [
|
|
262
|
+
{
|
|
263
|
+
value: "__keep__",
|
|
264
|
+
label: currentModelLabel
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
value: "__custom__",
|
|
268
|
+
label: "Enter model manually"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
value: DEFAULT_KIMI_SEARCH_MODEL,
|
|
272
|
+
label: `moonshot/${DEFAULT_KIMI_SEARCH_MODEL}`
|
|
273
|
+
}
|
|
274
|
+
],
|
|
275
|
+
initialValue: "__keep__"
|
|
276
|
+
});
|
|
277
|
+
let model;
|
|
278
|
+
if (modelChoice === "__keep__") model = existingModel || DEFAULT_KIMI_SEARCH_MODEL;
|
|
279
|
+
else if (modelChoice === "__custom__") model = (await ctx.prompter.text({
|
|
280
|
+
message: "Kimi model name",
|
|
281
|
+
initialValue: existingModel || DEFAULT_KIMI_SEARCH_MODEL,
|
|
282
|
+
placeholder: DEFAULT_KIMI_SEARCH_MODEL
|
|
283
|
+
}))?.trim() || DEFAULT_KIMI_SEARCH_MODEL;
|
|
284
|
+
else model = modelChoice;
|
|
285
|
+
const next = { ...ctx.config };
|
|
286
|
+
setProviderWebSearchPluginConfigValue(next, "moonshot", "baseUrl", baseUrl);
|
|
287
|
+
setProviderWebSearchPluginConfigValue(next, "moonshot", "model", model);
|
|
288
|
+
return next;
|
|
289
|
+
}
|
|
290
|
+
const testing = {
|
|
291
|
+
resolveKimiApiKey,
|
|
292
|
+
resolveKimiModel,
|
|
293
|
+
resolveKimiBaseUrl,
|
|
294
|
+
extractKimiCitations,
|
|
295
|
+
hasKimiSearchResults,
|
|
296
|
+
extractKimiToolResultContent
|
|
297
|
+
};
|
|
298
|
+
//#endregion
|
|
299
|
+
export { testing as __testing, testing, executeKimiWebSearchProviderTool, runKimiSearchProviderSetup };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { r as MOONSHOT_DEFAULT_MODEL_ID } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
import { buildOpenAiCompatibleVideoRequestBody, coerceOpenAiCompatibleVideoText, describeImageWithModel, describeImagesWithModel, resolveMediaUnderstandingString } from "openclaw/plugin-sdk/media-understanding";
|
|
3
|
+
import { assertOkOrThrowHttpError, postJsonRequest, resolveProviderHttpRequestConfig } from "openclaw/plugin-sdk/provider-http";
|
|
4
|
+
//#region extensions/moonshot/media-understanding-provider.ts
|
|
5
|
+
const DEFAULT_MOONSHOT_VIDEO_BASE_URL = "https://api.moonshot.ai/v1";
|
|
6
|
+
const DEFAULT_MOONSHOT_VIDEO_MODEL = MOONSHOT_DEFAULT_MODEL_ID;
|
|
7
|
+
const DEFAULT_MOONSHOT_VIDEO_PROMPT = "Describe the video.";
|
|
8
|
+
async function describeMoonshotVideo(params) {
|
|
9
|
+
const fetchFn = params.fetchFn ?? fetch;
|
|
10
|
+
const model = resolveMediaUnderstandingString(params.model, DEFAULT_MOONSHOT_VIDEO_MODEL);
|
|
11
|
+
const mime = resolveMediaUnderstandingString(params.mime, "video/mp4");
|
|
12
|
+
const prompt = resolveMediaUnderstandingString(params.prompt, DEFAULT_MOONSHOT_VIDEO_PROMPT);
|
|
13
|
+
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
|
|
14
|
+
baseUrl: params.baseUrl,
|
|
15
|
+
defaultBaseUrl: DEFAULT_MOONSHOT_VIDEO_BASE_URL,
|
|
16
|
+
headers: params.headers,
|
|
17
|
+
request: params.request,
|
|
18
|
+
defaultHeaders: {
|
|
19
|
+
"content-type": "application/json",
|
|
20
|
+
authorization: `Bearer ${params.apiKey}`
|
|
21
|
+
},
|
|
22
|
+
provider: "moonshot",
|
|
23
|
+
api: "openai-completions",
|
|
24
|
+
capability: "video",
|
|
25
|
+
transport: "media-understanding"
|
|
26
|
+
});
|
|
27
|
+
const { response: res, release } = await postJsonRequest({
|
|
28
|
+
url: `${baseUrl}/chat/completions`,
|
|
29
|
+
headers,
|
|
30
|
+
body: buildOpenAiCompatibleVideoRequestBody({
|
|
31
|
+
model,
|
|
32
|
+
prompt,
|
|
33
|
+
mime,
|
|
34
|
+
buffer: params.buffer
|
|
35
|
+
}),
|
|
36
|
+
timeoutMs: params.timeoutMs,
|
|
37
|
+
fetchFn,
|
|
38
|
+
allowPrivateNetwork,
|
|
39
|
+
dispatcherPolicy
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
await assertOkOrThrowHttpError(res, "Moonshot video description failed");
|
|
43
|
+
const text = coerceOpenAiCompatibleVideoText(await res.json());
|
|
44
|
+
if (!text) throw new Error("Moonshot video description response missing content");
|
|
45
|
+
return {
|
|
46
|
+
text,
|
|
47
|
+
model
|
|
48
|
+
};
|
|
49
|
+
} finally {
|
|
50
|
+
await release();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const moonshotMediaUnderstandingProvider = {
|
|
54
|
+
id: "moonshot",
|
|
55
|
+
capabilities: ["image", "video"],
|
|
56
|
+
defaultModels: {
|
|
57
|
+
image: MOONSHOT_DEFAULT_MODEL_ID,
|
|
58
|
+
video: DEFAULT_MOONSHOT_VIDEO_MODEL
|
|
59
|
+
},
|
|
60
|
+
autoPriority: { video: 20 },
|
|
61
|
+
describeImage: describeImageWithModel,
|
|
62
|
+
describeImages: describeImagesWithModel,
|
|
63
|
+
describeVideo: describeMoonshotVideo
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { describeMoonshotVideo, moonshotMediaUnderstandingProvider };
|
package/dist/onboard.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { a as buildMoonshotProvider, n as MOONSHOT_CN_BASE_URL, r as MOONSHOT_DEFAULT_MODEL_ID, t as MOONSHOT_BASE_URL } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
import { createDefaultModelPresetAppliers } from "openclaw/plugin-sdk/provider-onboard";
|
|
3
|
+
//#region extensions/moonshot/onboard.ts
|
|
4
|
+
const MOONSHOT_DEFAULT_MODEL_REF = `moonshot/${MOONSHOT_DEFAULT_MODEL_ID}`;
|
|
5
|
+
const moonshotPresetAppliers = createDefaultModelPresetAppliers({
|
|
6
|
+
primaryModelRef: MOONSHOT_DEFAULT_MODEL_REF,
|
|
7
|
+
resolveParams: (_cfg, baseUrl) => {
|
|
8
|
+
const defaultModel = buildMoonshotProvider().models[0];
|
|
9
|
+
if (!defaultModel) return null;
|
|
10
|
+
return {
|
|
11
|
+
providerId: "moonshot",
|
|
12
|
+
api: "openai-completions",
|
|
13
|
+
baseUrl,
|
|
14
|
+
defaultModel,
|
|
15
|
+
defaultModelId: MOONSHOT_DEFAULT_MODEL_ID,
|
|
16
|
+
aliases: [{
|
|
17
|
+
modelRef: MOONSHOT_DEFAULT_MODEL_REF,
|
|
18
|
+
alias: "Kimi"
|
|
19
|
+
}]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
function applyMoonshotConfig(cfg) {
|
|
24
|
+
return moonshotPresetAppliers.applyConfig(cfg, MOONSHOT_BASE_URL);
|
|
25
|
+
}
|
|
26
|
+
function applyMoonshotConfigCn(cfg) {
|
|
27
|
+
return moonshotPresetAppliers.applyConfig(cfg, MOONSHOT_CN_BASE_URL);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { MOONSHOT_DEFAULT_MODEL_REF, applyMoonshotConfig, applyMoonshotConfigCn };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { applyProviderNativeStreamingUsageCompat, buildManifestModelProviderConfig, supportsNativeStreamingUsageCompat } from "openclaw/plugin-sdk/provider-catalog-shared";
|
|
2
|
+
//#region extensions/moonshot/openclaw.plugin.json
|
|
3
|
+
var modelCatalog = {
|
|
4
|
+
"aliases": {
|
|
5
|
+
"moonshotai": { "provider": "moonshot" },
|
|
6
|
+
"moonshot-ai": { "provider": "moonshot" }
|
|
7
|
+
},
|
|
8
|
+
"providers": { "moonshot": {
|
|
9
|
+
"baseUrl": "https://api.moonshot.ai/v1",
|
|
10
|
+
"api": "openai-completions",
|
|
11
|
+
"models": [
|
|
12
|
+
{
|
|
13
|
+
"id": "kimi-k2.6",
|
|
14
|
+
"name": "Kimi K2.6",
|
|
15
|
+
"input": ["text", "image"],
|
|
16
|
+
"contextWindow": 262144,
|
|
17
|
+
"maxTokens": 262144,
|
|
18
|
+
"cost": {
|
|
19
|
+
"input": .95,
|
|
20
|
+
"output": 4,
|
|
21
|
+
"cacheRead": .16,
|
|
22
|
+
"cacheWrite": 0
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "kimi-k2.7-code",
|
|
27
|
+
"name": "Kimi K2.7 Code",
|
|
28
|
+
"reasoning": true,
|
|
29
|
+
"input": ["text", "image"],
|
|
30
|
+
"contextWindow": 262144,
|
|
31
|
+
"maxTokens": 262144,
|
|
32
|
+
"cost": {
|
|
33
|
+
"input": .95,
|
|
34
|
+
"output": 4,
|
|
35
|
+
"cacheRead": .19,
|
|
36
|
+
"cacheWrite": 0
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "kimi-k2.5",
|
|
41
|
+
"name": "Kimi K2.5",
|
|
42
|
+
"input": ["text", "image"],
|
|
43
|
+
"contextWindow": 262144,
|
|
44
|
+
"maxTokens": 262144,
|
|
45
|
+
"cost": {
|
|
46
|
+
"input": .6,
|
|
47
|
+
"output": 3,
|
|
48
|
+
"cacheRead": .1,
|
|
49
|
+
"cacheWrite": 0
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "kimi-k2-thinking",
|
|
54
|
+
"name": "Kimi K2 Thinking",
|
|
55
|
+
"reasoning": true,
|
|
56
|
+
"input": ["text"],
|
|
57
|
+
"contextWindow": 262144,
|
|
58
|
+
"maxTokens": 262144,
|
|
59
|
+
"cost": {
|
|
60
|
+
"input": 0,
|
|
61
|
+
"output": 0,
|
|
62
|
+
"cacheRead": 0,
|
|
63
|
+
"cacheWrite": 0
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "kimi-k2-thinking-turbo",
|
|
68
|
+
"name": "Kimi K2 Thinking Turbo",
|
|
69
|
+
"reasoning": true,
|
|
70
|
+
"input": ["text"],
|
|
71
|
+
"contextWindow": 262144,
|
|
72
|
+
"maxTokens": 262144,
|
|
73
|
+
"cost": {
|
|
74
|
+
"input": 0,
|
|
75
|
+
"output": 0,
|
|
76
|
+
"cacheRead": 0,
|
|
77
|
+
"cacheWrite": 0
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "kimi-k2-turbo",
|
|
82
|
+
"name": "Kimi K2 Turbo",
|
|
83
|
+
"input": ["text"],
|
|
84
|
+
"contextWindow": 256e3,
|
|
85
|
+
"maxTokens": 16384,
|
|
86
|
+
"cost": {
|
|
87
|
+
"input": 0,
|
|
88
|
+
"output": 0,
|
|
89
|
+
"cacheRead": 0,
|
|
90
|
+
"cacheWrite": 0
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
} },
|
|
95
|
+
"discovery": { "moonshot": "static" }
|
|
96
|
+
};
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region extensions/moonshot/provider-catalog.ts
|
|
99
|
+
const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
|
|
100
|
+
const MOONSHOT_CN_BASE_URL = "https://api.moonshot.cn/v1";
|
|
101
|
+
const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2.6";
|
|
102
|
+
function isNativeMoonshotBaseUrl(baseUrl) {
|
|
103
|
+
return supportsNativeStreamingUsageCompat({
|
|
104
|
+
providerId: "moonshot",
|
|
105
|
+
baseUrl
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function applyMoonshotNativeStreamingUsageCompat(provider) {
|
|
109
|
+
return applyProviderNativeStreamingUsageCompat({
|
|
110
|
+
providerId: "moonshot",
|
|
111
|
+
providerConfig: provider
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function buildMoonshotProvider() {
|
|
115
|
+
return buildManifestModelProviderConfig({
|
|
116
|
+
providerId: "moonshot",
|
|
117
|
+
catalog: modelCatalog.providers.moonshot
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
export { buildMoonshotProvider as a, applyMoonshotNativeStreamingUsageCompat as i, MOONSHOT_CN_BASE_URL as n, isNativeMoonshotBaseUrl as o, MOONSHOT_DEFAULT_MODEL_ID as r, MOONSHOT_BASE_URL as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as buildMoonshotProvider, i as applyMoonshotNativeStreamingUsageCompat, n as MOONSHOT_CN_BASE_URL, o as isNativeMoonshotBaseUrl, r as MOONSHOT_DEFAULT_MODEL_ID, t as MOONSHOT_BASE_URL } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
export { MOONSHOT_BASE_URL, MOONSHOT_CN_BASE_URL, MOONSHOT_DEFAULT_MODEL_ID, applyMoonshotNativeStreamingUsageCompat, buildMoonshotProvider, isNativeMoonshotBaseUrl };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region extensions/moonshot/provider-contract-api.ts
|
|
2
|
+
const noopAuth = async () => ({ profiles: [] });
|
|
3
|
+
function createMoonshotProvider() {
|
|
4
|
+
return {
|
|
5
|
+
id: "moonshot",
|
|
6
|
+
label: "Moonshot",
|
|
7
|
+
docsPath: "/providers/moonshot",
|
|
8
|
+
aliases: ["moonshotai", "moonshot-ai"],
|
|
9
|
+
auth: [{
|
|
10
|
+
id: "api-key",
|
|
11
|
+
kind: "api_key",
|
|
12
|
+
label: "Kimi API key (.ai)",
|
|
13
|
+
hint: "Kimi K2.6 + Kimi",
|
|
14
|
+
run: noopAuth,
|
|
15
|
+
wizard: { groupLabel: "Moonshot AI (Kimi K2.6)" }
|
|
16
|
+
}, {
|
|
17
|
+
id: "api-key-cn",
|
|
18
|
+
kind: "api_key",
|
|
19
|
+
label: "Kimi API key (.cn)",
|
|
20
|
+
hint: "Kimi K2.6 + Kimi",
|
|
21
|
+
run: noopAuth,
|
|
22
|
+
wizard: { groupLabel: "Moonshot AI (Kimi K2.6)" }
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { createMoonshotProvider };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { a as buildMoonshotProvider } from "./provider-catalog-BGSHIo8D.js";
|
|
2
|
+
//#region extensions/moonshot/provider-discovery.ts
|
|
3
|
+
const moonshotProviderDiscovery = {
|
|
4
|
+
id: "moonshot",
|
|
5
|
+
label: "Moonshot",
|
|
6
|
+
docsPath: "/providers/moonshot",
|
|
7
|
+
aliases: ["moonshotai", "moonshot-ai"],
|
|
8
|
+
auth: [],
|
|
9
|
+
staticCatalog: {
|
|
10
|
+
order: "simple",
|
|
11
|
+
run: async () => ({ provider: buildMoonshotProvider() })
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { moonshotProviderDiscovery as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region extensions/moonshot/provider-policy-api.ts
|
|
2
|
+
const KIMI_K2_7_CODE_MODEL_ID = "kimi-k2.7-code";
|
|
3
|
+
function resolveThinkingProfile(context) {
|
|
4
|
+
if (context.modelId.trim().toLowerCase() === "kimi-k2.7-code") return {
|
|
5
|
+
levels: [{
|
|
6
|
+
id: "low",
|
|
7
|
+
label: "on"
|
|
8
|
+
}],
|
|
9
|
+
defaultLevel: "low",
|
|
10
|
+
preserveWhenCatalogReasoningFalse: true
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
levels: [{
|
|
14
|
+
id: "off",
|
|
15
|
+
label: "off"
|
|
16
|
+
}, {
|
|
17
|
+
id: "low",
|
|
18
|
+
label: "on"
|
|
19
|
+
}],
|
|
20
|
+
defaultLevel: "off"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { KIMI_K2_7_CODE_MODEL_ID, resolveThinkingProfile };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createWebSearchProviderContractFields } from "openclaw/plugin-sdk/provider-web-search-config-contract";
|
|
2
|
+
//#region extensions/moonshot/web-search-contract-api.ts
|
|
3
|
+
function createKimiWebSearchProvider() {
|
|
4
|
+
const credentialPath = "plugins.entries.moonshot.config.webSearch.apiKey";
|
|
5
|
+
return {
|
|
6
|
+
id: "kimi",
|
|
7
|
+
label: "Kimi (Moonshot)",
|
|
8
|
+
hint: "Requires Moonshot / Kimi API key · Moonshot web search",
|
|
9
|
+
onboardingScopes: ["text-inference"],
|
|
10
|
+
credentialLabel: "Moonshot / Kimi API key",
|
|
11
|
+
envVars: ["KIMI_API_KEY", "MOONSHOT_API_KEY"],
|
|
12
|
+
placeholder: "sk-...",
|
|
13
|
+
signupUrl: "https://platform.moonshot.cn/",
|
|
14
|
+
docsUrl: "https://docs.openclaw.ai/tools/web",
|
|
15
|
+
autoDetectOrder: 40,
|
|
16
|
+
credentialPath,
|
|
17
|
+
...createWebSearchProviderContractFields({
|
|
18
|
+
credentialPath,
|
|
19
|
+
searchCredential: {
|
|
20
|
+
type: "scoped",
|
|
21
|
+
scopeId: "kimi"
|
|
22
|
+
},
|
|
23
|
+
configuredCredential: { pluginId: "moonshot" }
|
|
24
|
+
}),
|
|
25
|
+
createTool: () => null
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createKimiWebSearchProvider };
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "moonshot",
|
|
3
|
+
"activation": {
|
|
4
|
+
"onStartup": false
|
|
5
|
+
},
|
|
6
|
+
"enabledByDefault": true,
|
|
7
|
+
"providerCatalogEntry": "./provider-discovery.ts",
|
|
8
|
+
"providers": ["moonshot"],
|
|
9
|
+
"providerAuthAliases": {
|
|
10
|
+
"moonshotai": "moonshot",
|
|
11
|
+
"moonshot-ai": "moonshot"
|
|
12
|
+
},
|
|
13
|
+
"providerEndpoints": [
|
|
14
|
+
{
|
|
15
|
+
"endpointClass": "moonshot-native",
|
|
16
|
+
"baseUrls": ["https://api.moonshot.ai/v1", "https://api.moonshot.cn/v1"]
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"providerRequest": {
|
|
20
|
+
"providers": {
|
|
21
|
+
"moonshot": {
|
|
22
|
+
"family": "moonshot",
|
|
23
|
+
"compatibilityFamily": "moonshot"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"modelPricing": {
|
|
28
|
+
"providers": {
|
|
29
|
+
"moonshot": {
|
|
30
|
+
"openRouter": {
|
|
31
|
+
"provider": "moonshotai"
|
|
32
|
+
},
|
|
33
|
+
"liteLLM": {
|
|
34
|
+
"provider": "moonshot"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"modelCatalog": {
|
|
40
|
+
"aliases": {
|
|
41
|
+
"moonshotai": {
|
|
42
|
+
"provider": "moonshot"
|
|
43
|
+
},
|
|
44
|
+
"moonshot-ai": {
|
|
45
|
+
"provider": "moonshot"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"providers": {
|
|
49
|
+
"moonshot": {
|
|
50
|
+
"baseUrl": "https://api.moonshot.ai/v1",
|
|
51
|
+
"api": "openai-completions",
|
|
52
|
+
"models": [
|
|
53
|
+
{
|
|
54
|
+
"id": "kimi-k2.6",
|
|
55
|
+
"name": "Kimi K2.6",
|
|
56
|
+
"input": ["text", "image"],
|
|
57
|
+
"contextWindow": 262144,
|
|
58
|
+
"maxTokens": 262144,
|
|
59
|
+
"cost": {
|
|
60
|
+
"input": 0.95,
|
|
61
|
+
"output": 4,
|
|
62
|
+
"cacheRead": 0.16,
|
|
63
|
+
"cacheWrite": 0
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "kimi-k2.7-code",
|
|
68
|
+
"name": "Kimi K2.7 Code",
|
|
69
|
+
"reasoning": true,
|
|
70
|
+
"input": ["text", "image"],
|
|
71
|
+
"contextWindow": 262144,
|
|
72
|
+
"maxTokens": 262144,
|
|
73
|
+
"cost": {
|
|
74
|
+
"input": 0.95,
|
|
75
|
+
"output": 4,
|
|
76
|
+
"cacheRead": 0.19,
|
|
77
|
+
"cacheWrite": 0
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "kimi-k2.5",
|
|
82
|
+
"name": "Kimi K2.5",
|
|
83
|
+
"input": ["text", "image"],
|
|
84
|
+
"contextWindow": 262144,
|
|
85
|
+
"maxTokens": 262144,
|
|
86
|
+
"cost": {
|
|
87
|
+
"input": 0.6,
|
|
88
|
+
"output": 3,
|
|
89
|
+
"cacheRead": 0.1,
|
|
90
|
+
"cacheWrite": 0
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "kimi-k2-thinking",
|
|
95
|
+
"name": "Kimi K2 Thinking",
|
|
96
|
+
"reasoning": true,
|
|
97
|
+
"input": ["text"],
|
|
98
|
+
"contextWindow": 262144,
|
|
99
|
+
"maxTokens": 262144,
|
|
100
|
+
"cost": {
|
|
101
|
+
"input": 0,
|
|
102
|
+
"output": 0,
|
|
103
|
+
"cacheRead": 0,
|
|
104
|
+
"cacheWrite": 0
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "kimi-k2-thinking-turbo",
|
|
109
|
+
"name": "Kimi K2 Thinking Turbo",
|
|
110
|
+
"reasoning": true,
|
|
111
|
+
"input": ["text"],
|
|
112
|
+
"contextWindow": 262144,
|
|
113
|
+
"maxTokens": 262144,
|
|
114
|
+
"cost": {
|
|
115
|
+
"input": 0,
|
|
116
|
+
"output": 0,
|
|
117
|
+
"cacheRead": 0,
|
|
118
|
+
"cacheWrite": 0
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"id": "kimi-k2-turbo",
|
|
123
|
+
"name": "Kimi K2 Turbo",
|
|
124
|
+
"input": ["text"],
|
|
125
|
+
"contextWindow": 256000,
|
|
126
|
+
"maxTokens": 16384,
|
|
127
|
+
"cost": {
|
|
128
|
+
"input": 0,
|
|
129
|
+
"output": 0,
|
|
130
|
+
"cacheRead": 0,
|
|
131
|
+
"cacheWrite": 0
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"discovery": {
|
|
138
|
+
"moonshot": "static"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"setup": {
|
|
142
|
+
"providers": [
|
|
143
|
+
{
|
|
144
|
+
"id": "moonshot",
|
|
145
|
+
"envVars": ["MOONSHOT_API_KEY", "KIMI_API_KEY"]
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
},
|
|
149
|
+
"providerAuthChoices": [
|
|
150
|
+
{
|
|
151
|
+
"provider": "moonshot",
|
|
152
|
+
"method": "api-key",
|
|
153
|
+
"choiceId": "moonshot-api-key",
|
|
154
|
+
"choiceLabel": "Moonshot API key (.ai)",
|
|
155
|
+
"groupId": "moonshot",
|
|
156
|
+
"groupLabel": "Moonshot AI (Kimi K2.6)",
|
|
157
|
+
"groupHint": "Kimi K2.6",
|
|
158
|
+
"optionKey": "moonshotApiKey",
|
|
159
|
+
"cliFlag": "--moonshot-api-key",
|
|
160
|
+
"cliOption": "--moonshot-api-key <key>",
|
|
161
|
+
"cliDescription": "Moonshot API key"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"provider": "moonshot",
|
|
165
|
+
"method": "api-key-cn",
|
|
166
|
+
"choiceId": "moonshot-api-key-cn",
|
|
167
|
+
"choiceLabel": "Moonshot API key (.cn)",
|
|
168
|
+
"groupId": "moonshot",
|
|
169
|
+
"groupLabel": "Moonshot AI (Kimi K2.6)",
|
|
170
|
+
"groupHint": "Kimi K2.6",
|
|
171
|
+
"optionKey": "moonshotApiKey",
|
|
172
|
+
"cliFlag": "--moonshot-api-key",
|
|
173
|
+
"cliOption": "--moonshot-api-key <key>",
|
|
174
|
+
"cliDescription": "Moonshot API key"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"uiHints": {
|
|
178
|
+
"webSearch.apiKey": {
|
|
179
|
+
"label": "Kimi Search API Key",
|
|
180
|
+
"help": "Moonshot/Kimi API key (fallback: KIMI_API_KEY or MOONSHOT_API_KEY env var).",
|
|
181
|
+
"sensitive": true
|
|
182
|
+
},
|
|
183
|
+
"webSearch.baseUrl": {
|
|
184
|
+
"label": "Kimi Search Base URL",
|
|
185
|
+
"help": "Kimi base URL override."
|
|
186
|
+
},
|
|
187
|
+
"webSearch.model": {
|
|
188
|
+
"label": "Kimi Search Model",
|
|
189
|
+
"help": "Kimi model override."
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"contracts": {
|
|
193
|
+
"mediaUnderstandingProviders": ["moonshot"],
|
|
194
|
+
"webSearchProviders": ["kimi"]
|
|
195
|
+
},
|
|
196
|
+
"mediaUnderstandingProviderMetadata": {
|
|
197
|
+
"moonshot": {
|
|
198
|
+
"capabilities": ["image", "video"],
|
|
199
|
+
"defaultModels": {
|
|
200
|
+
"image": "kimi-k2.6",
|
|
201
|
+
"video": "kimi-k2.6"
|
|
202
|
+
},
|
|
203
|
+
"autoPriority": {
|
|
204
|
+
"video": 20
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
"configContracts": {
|
|
209
|
+
"compatibilityRuntimePaths": ["tools.web.search.apiKey"]
|
|
210
|
+
},
|
|
211
|
+
"configSchema": {
|
|
212
|
+
"type": "object",
|
|
213
|
+
"additionalProperties": false,
|
|
214
|
+
"properties": {
|
|
215
|
+
"webSearch": {
|
|
216
|
+
"type": "object",
|
|
217
|
+
"additionalProperties": false,
|
|
218
|
+
"properties": {
|
|
219
|
+
"apiKey": {
|
|
220
|
+
"type": ["string", "object"]
|
|
221
|
+
},
|
|
222
|
+
"baseUrl": {
|
|
223
|
+
"type": "string"
|
|
224
|
+
},
|
|
225
|
+
"model": {
|
|
226
|
+
"type": "string"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/moonshot-provider",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2026.6.11-beta.2",
|
|
4
|
+
"description": "OpenClaw Moonshot provider plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"openclaw": {
|
|
7
|
+
"extensions": [
|
|
8
|
+
"./index.ts"
|
|
9
|
+
],
|
|
10
|
+
"install": {
|
|
11
|
+
"clawhubSpec": "clawhub:@openclaw/moonshot-provider",
|
|
12
|
+
"npmSpec": "@openclaw/moonshot-provider",
|
|
13
|
+
"defaultChoice": "npm",
|
|
14
|
+
"minHostVersion": ">=2026.6.9"
|
|
15
|
+
},
|
|
16
|
+
"compat": {
|
|
17
|
+
"pluginApi": ">=2026.6.11-beta.2"
|
|
18
|
+
},
|
|
19
|
+
"build": {
|
|
20
|
+
"openclawVersion": "2026.6.11-beta.2",
|
|
21
|
+
"bundledDist": false
|
|
22
|
+
},
|
|
23
|
+
"release": {
|
|
24
|
+
"publishToClawHub": true,
|
|
25
|
+
"publishToNpm": true
|
|
26
|
+
},
|
|
27
|
+
"runtimeExtensions": [
|
|
28
|
+
"./dist/index.js"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
5
31
|
"repository": {
|
|
6
32
|
"type": "git",
|
|
7
|
-
"url": "
|
|
33
|
+
"url": "https://github.com/openclaw/openclaw"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/**",
|
|
37
|
+
"openclaw.plugin.json",
|
|
38
|
+
"npm-shrinkwrap.json",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"openclaw": ">=2026.6.11-beta.2"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"openclaw": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
8
48
|
},
|
|
9
|
-
"
|
|
10
|
-
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
12
|
-
}
|
|
49
|
+
"bundledDependencies": []
|
|
13
50
|
}
|