@rpalegacy/opencode 0.1.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 ADDED
@@ -0,0 +1,91 @@
1
+ # @rpalegacy/opencode
2
+
3
+ OpenClaw provider package for [opencode](https://opencode.ai).
4
+
5
+ Exposes Claude (claude-local) models — Claude Opus 4.6, Claude Sonnet 4.6, and Claude Haiku 4 — via the OpenClaw local proxy at `localhost:3456`.
6
+
7
+ ## Requirements
8
+
9
+ - [OpenClaw](https://docs.openclaw.ai) running with `openclaw-claude-proxy` active
10
+ - `OPENCLAW_API_KEY` environment variable set (get it from your OpenClaw config)
11
+ - Node.js >= 18
12
+
13
+ ## Setup
14
+
15
+ ### 1. Install OpenClaw's Claude proxy
16
+
17
+ ```bash
18
+ # Install the openclaw-claude-proxy if you haven't already
19
+ npm install -g openclaw-claude-proxy
20
+ openclaw-claude-proxy
21
+ ```
22
+
23
+ The proxy runs at `http://localhost:3456` and handles OAuth with your Claude Pro subscription.
24
+
25
+ ### 2. Configure opencode
26
+
27
+ Add to your `opencode.json`:
28
+
29
+ ```json
30
+ {
31
+ "$schema": "https://opencode.ai/config.json",
32
+ "provider": {
33
+ "openclaw": {
34
+ "npm": "@rpalegacy/opencode",
35
+ "env": ["OPENCLAW_API_KEY"]
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ Or use the `/connect` command in opencode's TUI and enter:
42
+ - **Provider ID**: `openclaw`
43
+ - **Base URL**: `http://localhost:3456/v1`
44
+ - **API Key**: `OPENCLAW_API_KEY` (or set the env var directly)
45
+
46
+ ### 3. Use it
47
+
48
+ ```bash
49
+ # Set your API key
50
+ export OPENCLAW_API_KEY="sk-ant-..."
51
+
52
+ # Run opencode with the OpenClaw provider
53
+ opencode --provider openclaw --model claude-opus-4-6
54
+
55
+ # Or in opencode's TUI
56
+ /models # then select a Claude model
57
+ ```
58
+
59
+ ## Available Models
60
+
61
+ | Model | Context | Reasoning | Tool Call | Vision | Cost |
62
+ |-------|---------|-----------|-----------|--------|------|
63
+ | Claude Opus 4.6 | 200K | ✅ | ✅ | ✅ | Free* |
64
+ | Claude Sonnet 4.6 | 200K | ✅ | ✅ | ✅ | Free* |
65
+ | Claude Haiku 4 | 200K | ✅ | ✅ | ✅ | Free* |
66
+
67
+ *Free via your Claude Pro subscription through the local proxy.带宽
68
+
69
+ ## How it works
70
+
71
+ `@rpalegacy/opencode` wraps the `@ai-sdk/openai-compatible` provider and configures it to point at OpenClaw's local proxy (`localhost:3456`). The proxy handles:
72
+
73
+ - OAuth authentication with your Claude Pro account
74
+ - Model routing (claude-opus-4-6, claude-sonnet-4-6, claude-haiku-4)
75
+ - API compatibility (converts between OpenAI-compatible and Anthropic APIs)
76
+
77
+ ## Troubleshooting
78
+
79
+ **"Model not found" errors**
80
+ - Make sure `openclaw-claude-proxy` is running
81
+ - Verify `http://localhost:3456` is accessible
82
+ - Check that `OPENCLAW_API_KEY` is set correctly
83
+
84
+ **Authentication errors**
85
+ - The proxy uses OAuth with your Claude Pro account
86
+ - Make sure your Claude Pro subscription is active
87
+ - Try restarting the proxy: `pkill -f openclaw-claude-proxy && openclaw-claude-proxy`
88
+
89
+ ## License
90
+
91
+ MIT
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @openclaw/opencode
3
+ *
4
+ * OpenClaw provider package for opencode.
5
+ * Exposes Claude (claude-local) models via the OpenClaw proxy at localhost:3456.
6
+ *
7
+ * Usage in opencode config (opencode.json):
8
+ * {
9
+ * "provider": {
10
+ * "openclaw": {
11
+ * "npm": "@openclaw/opencode",
12
+ * "env": ["OPENCLAW_API_KEY"]
13
+ * }
14
+ * }
15
+ * }
16
+ *
17
+ * Then run: OPENCLAW_API_KEY=<key> opencode --provider openclaw
18
+ */
19
+ import { type OpenAICompatibleProviderSettings } from "@ai-sdk/openai-compatible";
20
+ export interface OpenClawOptions extends Partial<OpenAICompatibleProviderSettings> {
21
+ /**
22
+ * Override the base URL for the OpenClaw proxy.
23
+ * Defaults to http://localhost:3456/v1
24
+ */
25
+ baseURL?: string;
26
+ /**
27
+ * Override the API key. Defaults to OPENCLAW_API_KEY env var.
28
+ */
29
+ apiKey?: string;
30
+ }
31
+ export interface OpenClawModel {
32
+ id: string;
33
+ name: string;
34
+ /** Context window size */
35
+ contextWindow: number;
36
+ /** Max output tokens (0 = unknown/unlimited) */
37
+ maxOutputTokens: number;
38
+ /** Supports reasoning (extended thinking) */
39
+ reasoning: boolean;
40
+ /** Supports tool calling */
41
+ toolCall: boolean;
42
+ /** Supports image input */
43
+ vision: boolean;
44
+ /** Input cost per 1M tokens (0 = free) */
45
+ inputCost: number;
46
+ /** Output cost per 1M tokens (0 = free) */
47
+ outputCost: number;
48
+ }
49
+ /**
50
+ * All OpenClaw models registered by this provider.
51
+ * Updated to reflect claude-local models from the RPAA-365 schema.
52
+ */
53
+ export declare const OPENCLAW_MODELS: Record<string, OpenClawModel>;
54
+ /**
55
+ * Provider ID used in opencode config.
56
+ */
57
+ export declare const PROVIDER_ID = "openclaw";
58
+ /**
59
+ * Provider display name.
60
+ */
61
+ export declare const PROVIDER_NAME = "OpenClaw";
62
+ /**
63
+ * Required environment variables.
64
+ */
65
+ export declare const PROVIDER_ENV: string[];
66
+ /**
67
+ * Default proxy base URL.
68
+ */
69
+ export declare const DEFAULT_BASE_URL = "http://localhost:3456/v1";
70
+ /**
71
+ * Create the OpenClaw provider for opencode.
72
+ *
73
+ * This function is the main export that opencode will call.
74
+ * opencode looks for an export starting with "create".
75
+ *
76
+ * @param name - Provider name (opencode passes the provider ID from config)
77
+ * @param options - Provider options from opencode config
78
+ */
79
+ export declare function createOpenClaw(name?: string, options?: OpenClawOptions): import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>;
80
+ /**
81
+ * Alias for createOpenClaw — opencode uses the first export starting with "create".
82
+ */
83
+ export declare const create: typeof createOpenClaw;
84
+ /**
85
+ * Convenience: default export matches the opencode provider package convention.
86
+ */
87
+ export default createOpenClaw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ACH,eAAe,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @openclaw/opencode
3
+ *
4
+ * OpenClaw provider package for opencode.
5
+ * Exposes Claude (claude-local) models via the OpenClaw proxy at localhost:3456.
6
+ *
7
+ * Usage in opencode config (opencode.json):
8
+ * {
9
+ * "provider": {
10
+ * "openclaw": {
11
+ * "npm": "@openclaw/opencode",
12
+ * "env": ["OPENCLAW_API_KEY"]
13
+ * }
14
+ * }
15
+ * }
16
+ *
17
+ * Then run: OPENCLAW_API_KEY=<key> opencode --provider openclaw
18
+ */
19
+ import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
20
+ /**
21
+ * All OpenClaw models registered by this provider.
22
+ * Updated to reflect claude-local models from the RPAA-365 schema.
23
+ */
24
+ export const OPENCLAW_MODELS = {
25
+ "claude-opus-4-6": {
26
+ id: "claude-opus-4-6",
27
+ name: "Claude Opus 4.6",
28
+ contextWindow: 200000,
29
+ maxOutputTokens: 8192,
30
+ reasoning: true,
31
+ toolCall: true,
32
+ vision: true,
33
+ inputCost: 0, // free via claude-local proxy
34
+ outputCost: 0,
35
+ },
36
+ "claude-sonnet-4-6": {
37
+ id: "claude-sonnet-4-6",
38
+ name: "Claude Sonnet 4.6",
39
+ contextWindow: 200000,
40
+ maxOutputTokens: 8192,
41
+ reasoning: true,
42
+ toolCall: true,
43
+ vision: true,
44
+ inputCost: 0,
45
+ outputCost: 0,
46
+ },
47
+ "claude-haiku-4": {
48
+ id: "claude-haiku-4",
49
+ name: "Claude Haiku 4",
50
+ contextWindow: 200000,
51
+ maxOutputTokens: 8192,
52
+ reasoning: true,
53
+ toolCall: true,
54
+ vision: true,
55
+ inputCost: 0,
56
+ outputCost: 0,
57
+ },
58
+ };
59
+ /**
60
+ * Provider ID used in opencode config.
61
+ */
62
+ export const PROVIDER_ID = "openclaw";
63
+ /**
64
+ * Provider display name.
65
+ */
66
+ export const PROVIDER_NAME = "OpenClaw";
67
+ /**
68
+ * Required environment variables.
69
+ */
70
+ export const PROVIDER_ENV = ["OPENCLAW_API_KEY"];
71
+ /**
72
+ * Default proxy base URL.
73
+ */
74
+ export const DEFAULT_BASE_URL = "http://localhost:3456/v1";
75
+ /**
76
+ * Create the OpenClaw provider for opencode.
77
+ *
78
+ * This function is the main export that opencode will call.
79
+ * opencode looks for an export starting with "create".
80
+ *
81
+ * @param name - Provider name (opencode passes the provider ID from config)
82
+ * @param options - Provider options from opencode config
83
+ */
84
+ export function createOpenClaw(name = PROVIDER_ID, options = {}) {
85
+ const baseURL = options.baseURL ?? DEFAULT_BASE_URL;
86
+ const apiKey = options.apiKey ?? process.env.OPENCLAW_API_KEY ?? "not-set";
87
+ const provider = createOpenAICompatible({
88
+ name,
89
+ baseURL,
90
+ apiKey,
91
+ // Pass through any additional options
92
+ ...options,
93
+ });
94
+ return provider;
95
+ }
96
+ /**
97
+ * Alias for createOpenClaw — opencode uses the first export starting with "create".
98
+ */
99
+ export const create = createOpenClaw;
100
+ /**
101
+ * Convenience: default export matches the opencode provider package convention.
102
+ */
103
+ export default createOpenClaw;
104
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,sBAAsB,EAAyC,MAAM,2BAA2B,CAAC;AAqC1G;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAkC;IAC5D,iBAAiB,EAAE;QACjB,EAAE,EAAE,iBAAiB;QACrB,IAAI,EAAE,iBAAiB;QACvB,aAAa,EAAE,MAAM;QACrB,eAAe,EAAE,IAAI;QACrB,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,CAAC,EAAE,8BAA8B;QAC5C,UAAU,EAAE,CAAC;KACd;IACD,mBAAmB,EAAE;QACnB,EAAE,EAAE,mBAAmB;QACvB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-0,0 +1,43 @@
1
+ {
2
+ "name": "@rpalegacy/opencode",
3
+ "version": "0.1.0",
4
+ "description": "OpenClaw provider for opencode — exposes Claude (claude-local) models via the OpenClaw proxy",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "dependencies": {
22
+ "@ai-sdk/openai-compatible": "^1.0.0",
23
+ "ai": "^3.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^25.5.2",
27
+ "typescript": "^5.0.0"
28
+ },
29
+ "peerDependencies": {
30
+ "ai": "^3.0.0"
31
+ },
32
+ "keywords": [
33
+ "opencode",
34
+ "openclaw",
35
+ "claude",
36
+ "anthropic",
37
+ "ai-sdk"
38
+ ],
39
+ "engines": {
40
+ "node": ">=18.0.0"
41
+ },
42
+ "license": "MIT"
43
+ }