chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:24:08 +08:00
commit 0d3cb498a3
5438 changed files with 1316560 additions and 0 deletions
+138
View File
@@ -0,0 +1,138 @@
# provider-opencode-sdk (OpenCode SDK Examples)
The OpenCode SDK provider runs agentic evals through OpenCode, an open-source coding agent with support for hosted and local model providers.
```bash
npx promptfoo@latest init --example provider-opencode-sdk
cd provider-opencode-sdk
```
## Setup
### 1. Install OpenCode CLI
```bash
curl -fsSL https://opencode.ai/install | bash
```
### 2. Install OpenCode SDK
```bash
npm install @opencode-ai/sdk
```
Configure provider credentials in your shell or `.env`. For example:
```bash
export OPENAI_API_KEY=your_api_key_here
```
If promptfoo starts the OpenCode server for you, you can also set `config.apiKey` together with `config.provider_id`. If you use `baseUrl`, the target OpenCode server must already be authenticated.
If you are validating changes inside this repository, use `npm run local -- eval ...` from the repo root. If you initialized an example with `npx promptfoo@latest init --example provider-opencode-sdk`, run `npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache` from the example directory.
The shipped examples use OpenAI for reproducible QA, but the provider itself is not OpenAI-specific. OpenCode can route to Anthropic, Google, Ollama, LM Studio, and other providers configured in OpenCode.
## Examples
### Basic Usage
Chat-only usage in a temporary directory with no filesystem tools.
**Location**: `./basic/`
**Usage**:
```bash
cd basic
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache
```
### Working Directory
Read-only filesystem access with `working_dir`, using the default `read`, `grep`, `glob`, and `list` tools.
**Location**: `./working-dir/`
**Usage**:
```bash
cd working-dir
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache
```
### Structured Output
Provider-enforced JSON Schema output using the OpenCode `format` request option.
**Location**: `./structured-output/`
**Usage**:
```bash
cd structured-output
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache
```
### Permissions
Session-level permission rules mixing simple and pattern-based entries. Promptfoo converts the object config into the `PermissionRuleset` array the OpenCode v2 API expects.
**Location**: `./permissions/`
**Usage**:
```bash
cd permissions
npx promptfoo@latest eval -c promptfooconfig.yaml --no-cache
```
## Provider Configuration
The provider supports these high-value options:
```yaml
providers:
- id: opencode:sdk
config:
provider_id: openai
model: gpt-4o-mini
# Optional: pass credentials directly when promptfoo starts the server
apiKey: '{{env.OPENAI_API_KEY}}'
# Read-only local repo access
working_dir: ./basic
workspace: feature-branch
# Structured output
format:
type: json_schema
schema:
type: object
properties:
answer:
type: string
required: [answer]
# Reuse the same OpenCode session for repeated calls
persist_sessions: true
```
## Supported Providers
OpenCode can route requests to the provider ecosystem it already supports, including:
- Anthropic
- OpenAI
- Google
- Ollama
- LM Studio
- Other providers configured in OpenCode
## Learn More
- [OpenCode SDK Provider Documentation](/docs/providers/opencode-sdk/)
- [OpenCode Documentation](https://opencode.ai/docs/)
- [OpenCode SDK Reference](https://opencode.ai/docs/sdk/)
- [Claude Agent SDK Provider](/docs/providers/claude-agent-sdk/) - Alternative agentic provider
@@ -0,0 +1,20 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: 'OpenCode SDK basic usage - temp directory with no tools'
prompts:
- 'Output a Python function that prints the first 10 numbers in the Fibonacci sequence. Do not create any files. Just output the code.'
providers:
# Use opencode:sdk with explicit model configuration
- id: opencode:sdk
config:
provider_id: openai
model: gpt-4o-mini
tests:
- vars: {}
assert:
- type: contains
value: 'def'
- type: contains
value: 'print'
@@ -0,0 +1,31 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: 'OpenCode SDK session-level permission rules'
prompts:
- 'Summarize in one sentence what provider_id is configured in the local promptfooconfig.yaml.'
providers:
- id: opencode:sdk
config:
provider_id: openai
model: gpt-4o-mini
working_dir: ../basic
# Exercise both simple and pattern-based permission shapes.
# Promptfoo converts these into the ruleset the OpenCode v2 API expects.
permission:
read: allow
grep: allow
glob: allow
list: allow
edit: deny
bash:
'git status': allow
'*': deny
webfetch: deny
external_directory: deny
tests:
- vars: {}
assert:
- type: contains
value: openai
@@ -0,0 +1,41 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: 'OpenCode SDK structured JSON output'
prompts:
- 'Return JSON only with two keys: "language" and "task". Use "python" for language and describe the task as generating Fibonacci output.'
providers:
- id: opencode:sdk
config:
apiKey: '{{env.OPENAI_API_KEY}}'
provider_id: openai
model: gpt-4o-mini
format:
type: json_schema
schema:
type: object
additionalProperties: false
properties:
language:
type: string
task:
type: string
required:
- language
- task
tests:
- vars: {}
assert:
- type: is-json
value:
type: object
additionalProperties: false
properties:
language:
type: string
task:
type: string
required:
- language
- task
@@ -0,0 +1,20 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: 'OpenCode SDK working_dir with default read-only tools'
prompts:
- 'Read the local promptfooconfig.yaml in the working directory and report the configured provider_id and model in one sentence.'
providers:
- id: opencode:sdk
config:
provider_id: openai
model: gpt-4o-mini
working_dir: ../basic
tests:
- vars: {}
assert:
- type: contains
value: openai
- type: contains
value: gpt-4o-mini