@kenkaiiii/gg-ai 5.97.1 → 5.98.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 +3 -1
- package/dist/index.cjs +39 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +39 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,10 @@ import OpenAI from 'openai';
|
|
|
5
5
|
type Provider = "anthropic" | "xiaomi" | "openai" | "gemini" | "glm" | "moonshot" | "minimax" | "deepseek" | "openrouter" | "sakana" | "xai" | "palsu"
|
|
6
6
|
/** Hugging Face Inference Providers router (OpenAI-compatible). */
|
|
7
7
|
| "huggingface"
|
|
8
|
+
/** OpenCode Console gateway, pay-as-you-go (opencode.ai/inference). */
|
|
9
|
+
| "opencode"
|
|
10
|
+
/** OpenCode Go subscription gateway (opencode.ai/inference/go). */
|
|
11
|
+
| "opencode-go"
|
|
8
12
|
/** Locally hosted OpenAI-compatible server (Ollama, LM Studio, llama.cpp, vLLM). */
|
|
9
13
|
| "local";
|
|
10
14
|
type ThinkingLevel = "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ import OpenAI from 'openai';
|
|
|
5
5
|
type Provider = "anthropic" | "xiaomi" | "openai" | "gemini" | "glm" | "moonshot" | "minimax" | "deepseek" | "openrouter" | "sakana" | "xai" | "palsu"
|
|
6
6
|
/** Hugging Face Inference Providers router (OpenAI-compatible). */
|
|
7
7
|
| "huggingface"
|
|
8
|
+
/** OpenCode Console gateway, pay-as-you-go (opencode.ai/inference). */
|
|
9
|
+
| "opencode"
|
|
10
|
+
/** OpenCode Go subscription gateway (opencode.ai/inference/go). */
|
|
11
|
+
| "opencode-go"
|
|
8
12
|
/** Locally hosted OpenAI-compatible server (Ollama, LM Studio, llama.cpp, vLLM). */
|
|
9
13
|
| "local";
|
|
10
14
|
type ThinkingLevel = "low" | "medium" | "high" | "xhigh" | "max" | "ultra";
|
package/dist/index.js
CHANGED
|
@@ -158,6 +158,8 @@ var PROVIDER_DISPLAY = {
|
|
|
158
158
|
sakana: "Sakana",
|
|
159
159
|
xai: "xAI (Grok)",
|
|
160
160
|
huggingface: "Hugging Face",
|
|
161
|
+
opencode: "OpenCode",
|
|
162
|
+
"opencode-go": "OpenCode Go",
|
|
161
163
|
xiaomi: "Xiaomi (MiMo)",
|
|
162
164
|
minimax: "MiniMax"
|
|
163
165
|
};
|
|
@@ -2828,6 +2830,7 @@ async function* runStream2(options) {
|
|
|
2828
2830
|
const endpointKey = reasoningFieldKey(providerName, options.baseUrl, options.model);
|
|
2829
2831
|
const client = createClient2(options);
|
|
2830
2832
|
const isLocal = options.provider === "local";
|
|
2833
|
+
const isOpenCode = options.provider === "opencode" || options.provider === "opencode-go";
|
|
2831
2834
|
const isKimiK3 = options.provider === "moonshot" && (options.model === "kimi-k3" || options.model === "kimi-for-coding");
|
|
2832
2835
|
const isManagedKimiK3 = isKimiK3 && options.baseUrl?.replace(/\/+$/, "").endsWith("/coding/v1") === true;
|
|
2833
2836
|
const k3Effort = options.thinking ? toKimiK3Effort(options.thinking) : void 0;
|
|
@@ -2851,7 +2854,9 @@ async function* runStream2(options) {
|
|
|
2851
2854
|
// official CLI: reasoning is preserved only while thinking is enabled).
|
|
2852
2855
|
thinking: isKimiK27 || !!options.thinking,
|
|
2853
2856
|
supportsImages: options.supportsImages,
|
|
2854
|
-
|
|
2857
|
+
// OpenCode can stream thinking as `reasoning`, but its Kimi backends 400
|
|
2858
|
+
// unless it comes back as `reasoning_content`.
|
|
2859
|
+
reasoningField: isOpenCode ? DEFAULT_REASONING_FIELD : getReasoningField(endpointKey)
|
|
2855
2860
|
});
|
|
2856
2861
|
const defaultTemp = options.provider === "glm" ? 0.6 : void 0;
|
|
2857
2862
|
const effectiveTemp = options.temperature ?? defaultTemp;
|
|
@@ -2859,7 +2864,8 @@ async function* runStream2(options) {
|
|
|
2859
2864
|
model: options.model,
|
|
2860
2865
|
messages,
|
|
2861
2866
|
stream: useStreaming,
|
|
2862
|
-
...options.maxTokens ? options.provider === "deepseek" || options.provider === "glm" || options.provider === "moonshot"
|
|
2867
|
+
...options.maxTokens ? options.provider === "deepseek" || options.provider === "glm" || options.provider === "moonshot" || // OpenCode's gateway reads only max_tokens and ignores the newer name.
|
|
2868
|
+
isOpenCode ? { max_tokens: options.maxTokens } : { max_completion_tokens: options.maxTokens } : {},
|
|
2863
2869
|
...effectiveTemp != null && !options.thinking && !hasFixedKimiSampling ? { temperature: effectiveTemp } : {},
|
|
2864
2870
|
...options.topP != null && !hasFixedKimiSampling ? { top_p: options.topP } : {},
|
|
2865
2871
|
...options.stop ? { stop: options.stop } : {},
|
|
@@ -5419,6 +5425,33 @@ providerRegistry.register("huggingface", {
|
|
|
5419
5425
|
baseUrl: options.baseUrl ?? "https://router.huggingface.co/v1"
|
|
5420
5426
|
})
|
|
5421
5427
|
});
|
|
5428
|
+
function openCodeWireModelId(id) {
|
|
5429
|
+
const match = /^opencode(?:-go)?\/(.+)$/.exec(id);
|
|
5430
|
+
return match?.[1] ?? id;
|
|
5431
|
+
}
|
|
5432
|
+
var OPENCODE_FALLBACK_SESSION = `ses_${crypto.randomUUID().replace(/-/g, "")}`;
|
|
5433
|
+
function openCodeStream(defaultBaseUrl2) {
|
|
5434
|
+
return (options) => {
|
|
5435
|
+
const session = options.transportSessionId;
|
|
5436
|
+
return streamOpenAI({
|
|
5437
|
+
...options,
|
|
5438
|
+
baseUrl: options.baseUrl ?? defaultBaseUrl2,
|
|
5439
|
+
model: openCodeWireModelId(options.model),
|
|
5440
|
+
webSearch: false,
|
|
5441
|
+
defaultHeaders: {
|
|
5442
|
+
"User-Agent": GG_CODER_USER_AGENT,
|
|
5443
|
+
"x-opencode-session": session && /^[\w.:-]{1,128}$/.test(session) ? session : OPENCODE_FALLBACK_SESSION,
|
|
5444
|
+
...options.defaultHeaders
|
|
5445
|
+
}
|
|
5446
|
+
});
|
|
5447
|
+
};
|
|
5448
|
+
}
|
|
5449
|
+
providerRegistry.register("opencode", {
|
|
5450
|
+
stream: openCodeStream("https://opencode.ai/inference/openai/v1")
|
|
5451
|
+
});
|
|
5452
|
+
providerRegistry.register("opencode-go", {
|
|
5453
|
+
stream: openCodeStream("https://opencode.ai/inference/go/openai/v1")
|
|
5454
|
+
});
|
|
5422
5455
|
providerRegistry.register("sakana", {
|
|
5423
5456
|
// Sakana Fugu is a multi-agent system exposed as a standard LLM through the
|
|
5424
5457
|
// OpenAI-compatible Sakana API. We ride the Chat Completions transport (the
|
|
@@ -5706,6 +5739,10 @@ function defaultBaseUrl(provider) {
|
|
|
5706
5739
|
return "https://api.x.ai/v1";
|
|
5707
5740
|
case "huggingface":
|
|
5708
5741
|
return "https://router.huggingface.co/v1";
|
|
5742
|
+
case "opencode":
|
|
5743
|
+
return "https://opencode.ai/inference/openai/v1";
|
|
5744
|
+
case "opencode-go":
|
|
5745
|
+
return "https://opencode.ai/inference/go/openai/v1";
|
|
5709
5746
|
case "sakana":
|
|
5710
5747
|
return "https://api.sakana.ai/v1";
|
|
5711
5748
|
case "local":
|