npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-jinguobyte-adapter

v1.0.0

Published

OpenCode plugin adapter for JinguoByte New API proxy, fixing tool-call compatibility issues

Readme

OpenCode JinguoByte Adapter

Fix compatibility issues when using OpenCode with JinguoByte (New API) proxy for Claude models.

Problem

When using JinguoByte's New API proxy with OpenCode, two common errors occur:

  1. Third-party apps now draw from your extra usage - Provider rejects requests with long system prompts and extensive tool descriptions
  2. messages: text content blocks must be non-empty - Provider rejects assistant messages with empty content field when tool_calls are present

This plugin provides a local adapter that fixes both issues.

Installation

Method 1: From npm

npm install -g opencode-jinguobyte-adapter

Then install as an OpenCode plugin:

opencode plugin opencode-jinguobyte-adapter

Method 2: Manual Setup (Recommended)

  1. Clone or download this repository:

    git clone https://github.com/tao/opencode-jinguobyte-adapter.git
    cd opencode-jinguobyte-adapter
  2. Copy the plugin file to OpenCode's plugins directory:

    mkdir -p ~/.config/opencode/plugins
    cp index.js ~/.config/opencode/plugins/opencode-jinguobyte-adapter.js
  3. Copy the proxy script:

    cp proxy.js ~/.config/opencode/jinguobyte-proxy.mjs

Note: The plugin file must export JinguobyteAdapterPlugin. The proxy script is referenced by the shell wrapper (see Step 2 in Configuration) as ~/.config/opencode/jinguobyte-proxy.mjs.

Configuration

Step 1: Add to OpenCode config

Edit your ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "jinguobyte/claude-opus-4-7",
  "small_model": "jinguobyte/claude-haiku-4-5-20251001",
  "permission": {
    "external_directory": "allow",
    "doom_loop": "allow"
  },
  "tools": {
    "todowrite": false
  },
  "provider": {
    "jinguobyte": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "JinguoByte New API",
      "options": {
        "baseURL": "http://127.0.0.1:4141/v1",
        "apiKey": "{env:OPENCODE_JINGUOBYTE_API_KEY}"
      },
      "models": {
        "claude-haiku-4-5-20251001": {
          "name": "Claude Haiku 4.5"
        },
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6"
        },
        "claude-opus-4-6": {
          "name": "Claude Opus 4.6"
        },
        "claude-opus-4-7": {
          "name": "Claude Opus 4.7"
        }
      }
    }
  }
}

Step 2: Add to your shell config

Add to ~/.zshrc or ~/.bashrc:

# Ensure proxy is running before opencode starts
ensure_opencode_jinguobyte_proxy() {
  local proxy_port="${OPENCODE_JINGUOBYTE_PROXY_PORT:-4141}"
  local proxy_script="$HOME/.config/opencode/jinguobyte-proxy.mjs"
  local proxy_log="$HOME/.local/share/opencode/jinguobyte-proxy.log"

  if command -v lsof >/dev/null 2>&1 && lsof -iTCP:"$proxy_port" -sTCP:LISTEN >/dev/null 2>&1; then
    return 0
  fi

  mkdir -p "$HOME/.local/share/opencode"
  nohup node "$proxy_script" >>"$proxy_log" 2>&1 &
  sleep 0.4
}

# Wrap opencode to auto-start proxy
opencode() {
  ensure_opencode_jinguobyte_proxy
  command opencode "$@"
}

# Aliases
alias ocj="opencode"
alias oc='OPENCODE_CONFIG="$HOME/.config/opencode/opencode.full-tools.json" opencode'

Then reload your shell:

source ~/.zshrc

Step 3: Set environment variables

Add your API key to ~/.zshrc or ~/.bashrc:

export OPENCODE_JINGUOBYTE_API_KEY="your-api-key-here"

Important: You must also map this environment variable in your OpenCode provider config via "apiKey": "{env:OPENCODE_JINGUOBYTE_API_KEY}" (already included in the config above). Simply exporting the variable is not enough -- OpenCode needs the options.apiKey field to know where to read it from.

Or configure interactively in OpenCode via the /connect command.

How It Works

1. System Prompt Transformation

The plugin intercepts outgoing requests and replaces OpenCode's default long system prompt with a minimal one for JinguoByte provider:

"You are a careful coding assistant for software engineering tasks. Read relevant files before editing, prefer minimal correct changes, verify results, and keep responses concise."

This avoids the "Third-party apps" error by not sending tool-heavy descriptions.

2. Empty Content Fix

When assistant messages contain tool_calls but have empty content, the proxy automatically injects a placeholder:

// Before (rejected by JinguoByte)
{
  "role": "assistant",
  "content": "",
  "tool_calls": [...]
}

// After (accepted)
{
  "role": "assistant",
  "content": ".",
  "tool_calls": [...]
}

3. Local Proxy

The adapter runs a local HTTP proxy at 127.0.0.1:4141 that:

  • Receives requests from OpenCode
  • Rewrites problematic message formats
  • Forwards to JinguoByte API
  • Returns responses back to OpenCode

Usage

Quick Start

# Start OpenCode with JinguoByte adapter
ocj

# Or use full name
opencode

Using Different Models

# Use Sonnet model
opencode --model jinguobyte/claude-sonnet-4-6

# Use Opus model (recommended for complex tasks)
opencode --model jinguobyte/claude-opus-4-7

# Use Haiku for quick tasks
opencode --model jinguobyte/claude-haiku-4-5-20251001

CLI Mode

# Run a single command
opencode run "explain this code" --agent build --model jinguobyte/claude-opus-4-7

# Continue last session
opencode --continue

# List available models
opencode models jinguobyte

Full Tools Configuration (Optional)

For other providers that support full tool set, create ~/.config/opencode/opencode.full-tools.json:

{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-4",
  "permission": {
    "*": "allow",
    "external_directory": "allow",
    "doom_loop": "allow"
  },
  "tools": {
    "todowrite": true
  }
}

Then use:

oc

Environment Variables

| Variable | Default | Description | |----------|---------|-------------| | OPENCODE_JINGUOBYTE_PROXY_PORT | 4141 | Local proxy port | | OPENCODE_JINGUOBYTE_PROXY_TARGET | https://token.jinguobyte.com | Upstream API URL | | OPENCODE_JINGUOBYTE_API_KEY | - | Your JinguoByte API key |

Troubleshooting

Connection Refused

Make sure the proxy is running:

lsof -iTCP:4141 -sTCP:LISTEN

If not running, restart:

source ~/.zshrc  # Re-load the opencode wrapper

API Key Issues

Configure via OpenCode:

/connect
# Select "Other"
# Provider ID: jinguobyte
# Paste your API key

Empty Content Error Still Occurs

Check proxy logs:

tail -f ~/.local/share/opencode/jinguobyte-proxy.log

License

MIT

Contributing

Issues and PRs welcome at https://github.com/tao/opencode-jinguobyte-adapter