@kenkaiiii/gg-ai 5.97.1 → 5.98.1

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 CHANGED
@@ -10,7 +10,7 @@
10
10
  <a href="https://github.com/KenKaiii/gg-framework/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-AGPL--3.0-blue.svg?style=for-the-badge" alt="AGPL-3.0 License"></a>
11
11
  </p>
12
12
 
13
- gg-ai streams chat, tool calls and reasoning from Anthropic, OpenAI, Gemini, xAI, Moonshot, GLM, MiniMax, Xiaomi, DeepSeek, Sakana, OpenRouter, Hugging Face and local servers. To switch provider, change one string. There are no adapters or wrapper classes. It also does embeddings and reranking.
13
+ gg-ai streams chat, tool calls and reasoning from Anthropic, OpenAI, Gemini, xAI, Moonshot, GLM, MiniMax, Xiaomi, DeepSeek, Sakana, OpenRouter, Hugging Face, OpenCode and local servers. To switch provider, change one string. There are no adapters or wrapper classes. It also does embeddings and reranking.
14
14
 
15
15
  It's the provider layer under [GG Coder](https://github.com/KenKaiii/gg-framework), a desktop coding agent.
16
16
 
@@ -90,6 +90,8 @@ gg-ai makes one model call. To run the tools and send results back until the mod
90
90
  | `sakana` | Fugu, Fugu Max, Fugu Ultra | |
91
91
  | `openrouter` | Qwen3.8 Max, or any OpenRouter model id | Gateway to hundreds of models |
92
92
  | `huggingface` | Kimi K2.7 Code, DeepSeek V4.1 Flash, GPT-OSS 120B | Inference Providers router |
93
+ | `opencode-go` | Kimi K3, GLM-5.3, GLM-5.3-Flash | OpenCode Go subscription, Chat Completions models only. Ids are `opencode-go/<id>` |
94
+ | `opencode` | Kimi K3, GLM-5.3, GLM-5.3-Flash | OpenCode pay-as-you-go, Chat Completions models only. Ids are `opencode/<id>` |
93
95
  | `local` | Whatever your server runs | Ollama, LM Studio, llama.cpp, vLLM or any OpenAI-compatible server. `baseUrl` is required |
94
96
 
95
97
  "Built-in models" are the ones GG Coder lists (from [`@kenkaiiii/gg-core`](https://www.npmjs.com/package/@kenkaiiii/gg-core)). `model` is passed straight to the provider, so any model id the provider accepts works. Every default endpoint can be changed with `baseUrl`, and `providerRegistry.register()` adds your own provider.
package/dist/index.cjs CHANGED
@@ -248,6 +248,8 @@ var PROVIDER_DISPLAY = {
248
248
  sakana: "Sakana",
249
249
  xai: "xAI (Grok)",
250
250
  huggingface: "Hugging Face",
251
+ opencode: "OpenCode",
252
+ "opencode-go": "OpenCode Go",
251
253
  xiaomi: "Xiaomi (MiMo)",
252
254
  minimax: "MiniMax"
253
255
  };
@@ -2918,6 +2920,7 @@ async function* runStream2(options) {
2918
2920
  const endpointKey = reasoningFieldKey(providerName, options.baseUrl, options.model);
2919
2921
  const client = createClient2(options);
2920
2922
  const isLocal = options.provider === "local";
2923
+ const isOpenCode = options.provider === "opencode" || options.provider === "opencode-go";
2921
2924
  const isKimiK3 = options.provider === "moonshot" && (options.model === "kimi-k3" || options.model === "kimi-for-coding");
2922
2925
  const isManagedKimiK3 = isKimiK3 && options.baseUrl?.replace(/\/+$/, "").endsWith("/coding/v1") === true;
2923
2926
  const k3Effort = options.thinking ? toKimiK3Effort(options.thinking) : void 0;
@@ -2941,7 +2944,9 @@ async function* runStream2(options) {
2941
2944
  // official CLI: reasoning is preserved only while thinking is enabled).
2942
2945
  thinking: isKimiK27 || !!options.thinking,
2943
2946
  supportsImages: options.supportsImages,
2944
- reasoningField: getReasoningField(endpointKey)
2947
+ // OpenCode can stream thinking as `reasoning`, but its Kimi backends 400
2948
+ // unless it comes back as `reasoning_content`.
2949
+ reasoningField: isOpenCode ? DEFAULT_REASONING_FIELD : getReasoningField(endpointKey)
2945
2950
  });
2946
2951
  const defaultTemp = options.provider === "glm" ? 0.6 : void 0;
2947
2952
  const effectiveTemp = options.temperature ?? defaultTemp;
@@ -2949,7 +2954,8 @@ async function* runStream2(options) {
2949
2954
  model: options.model,
2950
2955
  messages,
2951
2956
  stream: useStreaming,
2952
- ...options.maxTokens ? options.provider === "deepseek" || options.provider === "glm" || options.provider === "moonshot" ? { max_tokens: options.maxTokens } : { max_completion_tokens: options.maxTokens } : {},
2957
+ ...options.maxTokens ? options.provider === "deepseek" || options.provider === "glm" || options.provider === "moonshot" || // OpenCode's gateway reads only max_tokens and ignores the newer name.
2958
+ isOpenCode ? { max_tokens: options.maxTokens } : { max_completion_tokens: options.maxTokens } : {},
2953
2959
  ...effectiveTemp != null && !options.thinking && !hasFixedKimiSampling ? { temperature: effectiveTemp } : {},
2954
2960
  ...options.topP != null && !hasFixedKimiSampling ? { top_p: options.topP } : {},
2955
2961
  ...options.stop ? { stop: options.stop } : {},
@@ -5509,6 +5515,33 @@ providerRegistry.register("huggingface", {
5509
5515
  baseUrl: options.baseUrl ?? "https://router.huggingface.co/v1"
5510
5516
  })
5511
5517
  });
5518
+ function openCodeWireModelId(id) {
5519
+ const match = /^opencode(?:-go)?\/(.+)$/.exec(id);
5520
+ return match?.[1] ?? id;
5521
+ }
5522
+ var OPENCODE_FALLBACK_SESSION = `ses_${crypto.randomUUID().replace(/-/g, "")}`;
5523
+ function openCodeStream(defaultBaseUrl2) {
5524
+ return (options) => {
5525
+ const session = options.transportSessionId;
5526
+ return streamOpenAI({
5527
+ ...options,
5528
+ baseUrl: options.baseUrl ?? defaultBaseUrl2,
5529
+ model: openCodeWireModelId(options.model),
5530
+ webSearch: false,
5531
+ defaultHeaders: {
5532
+ "User-Agent": GG_CODER_USER_AGENT,
5533
+ "x-opencode-session": session && /^[\w.:-]{1,128}$/.test(session) ? session : OPENCODE_FALLBACK_SESSION,
5534
+ ...options.defaultHeaders
5535
+ }
5536
+ });
5537
+ };
5538
+ }
5539
+ providerRegistry.register("opencode", {
5540
+ stream: openCodeStream("https://opencode.ai/inference/openai/v1")
5541
+ });
5542
+ providerRegistry.register("opencode-go", {
5543
+ stream: openCodeStream("https://opencode.ai/inference/go/openai/v1")
5544
+ });
5512
5545
  providerRegistry.register("sakana", {
5513
5546
  // Sakana Fugu is a multi-agent system exposed as a standard LLM through the
5514
5547
  // OpenAI-compatible Sakana API. We ride the Chat Completions transport (the
@@ -5796,6 +5829,10 @@ function defaultBaseUrl(provider) {
5796
5829
  return "https://api.x.ai/v1";
5797
5830
  case "huggingface":
5798
5831
  return "https://router.huggingface.co/v1";
5832
+ case "opencode":
5833
+ return "https://opencode.ai/inference/openai/v1";
5834
+ case "opencode-go":
5835
+ return "https://opencode.ai/inference/go/openai/v1";
5799
5836
  case "sakana":
5800
5837
  return "https://api.sakana.ai/v1";
5801
5838
  case "local":