opencode-anthropic-fix 2.1.1 → 2.2.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/NOTICE +53 -0
- package/README.md +72 -4
- package/docs/opencode-v2-architecture.md +148 -0
- package/docs/opencode-v2.md +198 -0
- package/index.mjs +13 -6578
- package/lib/accounts.mjs +46 -0
- package/lib/host/command-args.mjs +18 -0
- package/lib/host/command-rpc.mjs +192 -0
- package/lib/host/runtime.mjs +6902 -0
- package/lib/host/tool-names.mjs +62 -0
- package/lib/host/v2-context.mjs +45 -0
- package/lib/host/v2-language.mjs +58 -0
- package/lib/host/v2-sdk.mjs +4 -0
- package/lib/host/v2-transport.mjs +415 -0
- package/lib/host/v2.mjs +343 -0
- package/lib/mimicry/request-body.mjs +99 -33
- package/lib/mimicry/request-helpers.mjs +6 -5
- package/lib/mimicry/response-stream.mjs +27 -22
- package/lib/oauth.mjs +29 -9
- package/lib/refresh-lock.mjs +18 -4
- package/lib/session-metrics.mjs +5 -8
- package/lib/unicode-text.mjs +9 -13
- package/licenses/Apache-2.0.txt +201 -0
- package/package.json +21 -1
- package/server.mjs +15 -0
- package/tui.mjs +93 -0
|
@@ -143,30 +143,32 @@ export function stripMcpPrefixFromSSE(text) {
|
|
|
143
143
|
* Built from the outgoing OC_TO_CC_TOOL_NAMES map (defined in transformRequestBody).
|
|
144
144
|
* Must stay in sync with that map.
|
|
145
145
|
*/
|
|
146
|
-
export const CC_TO_OC_TOOL_NAMES =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
export const CC_TO_OC_TOOL_NAMES = new Map(
|
|
147
|
+
Object.entries({
|
|
148
|
+
Bash: "bash",
|
|
149
|
+
Read: "read",
|
|
150
|
+
Glob: "glob",
|
|
151
|
+
Grep: "grep",
|
|
152
|
+
Edit: "edit",
|
|
153
|
+
Write: "write",
|
|
154
|
+
WebFetch: "webfetch",
|
|
155
|
+
TodoWrite: "todowrite",
|
|
156
|
+
Skill: "skill",
|
|
157
|
+
Task: "task",
|
|
158
|
+
Compress: "compress",
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
159
161
|
|
|
160
162
|
/**
|
|
161
163
|
* Reverse-map a tool name from CC PascalCase back to opencode lowercase,
|
|
162
164
|
* and strip `mcp_` prefix if present. Returns the original name if no mapping exists.
|
|
163
165
|
* @param {string} name
|
|
166
|
+
* @param {Map<string, string>} [toolNameMap] - Per-request restoration of host tool names.
|
|
164
167
|
* @returns {string}
|
|
165
168
|
*/
|
|
166
|
-
export function reverseMapToolName(name) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return name;
|
|
169
|
+
export function reverseMapToolName(name, toolNameMap) {
|
|
170
|
+
const mapped = CC_TO_OC_TOOL_NAMES.get(name) ?? (name.startsWith("mcp_") ? name.slice(4) : name);
|
|
171
|
+
return toolNameMap?.get(mapped) ?? mapped;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
/**
|
|
@@ -175,9 +177,10 @@ export function reverseMapToolName(name) {
|
|
|
175
177
|
* Returns true if any modification was made.
|
|
176
178
|
*
|
|
177
179
|
* @param {any} parsed
|
|
180
|
+
* @param {Map<string, string>} [toolNameMap]
|
|
178
181
|
* @returns {boolean}
|
|
179
182
|
*/
|
|
180
|
-
export function stripMcpPrefixFromParsedEvent(parsed) {
|
|
183
|
+
export function stripMcpPrefixFromParsedEvent(parsed, toolNameMap) {
|
|
181
184
|
if (!parsed || typeof parsed !== "object") return false;
|
|
182
185
|
|
|
183
186
|
let modified = false;
|
|
@@ -188,7 +191,7 @@ export function stripMcpPrefixFromParsedEvent(parsed) {
|
|
|
188
191
|
(parsed.content_block.type === "tool_use" || parsed.content_block.type === "tool_reference") &&
|
|
189
192
|
typeof parsed.content_block.name === "string"
|
|
190
193
|
) {
|
|
191
|
-
const mapped = reverseMapToolName(parsed.content_block.name);
|
|
194
|
+
const mapped = reverseMapToolName(parsed.content_block.name, toolNameMap);
|
|
192
195
|
if (mapped !== parsed.content_block.name) {
|
|
193
196
|
parsed.content_block.name = mapped;
|
|
194
197
|
modified = true;
|
|
@@ -199,7 +202,7 @@ export function stripMcpPrefixFromParsedEvent(parsed) {
|
|
|
199
202
|
if (parsed.message && Array.isArray(parsed.message.content)) {
|
|
200
203
|
for (const block of parsed.message.content) {
|
|
201
204
|
if ((block.type === "tool_use" || block.type === "tool_reference") && typeof block.name === "string") {
|
|
202
|
-
const mapped = reverseMapToolName(block.name);
|
|
205
|
+
const mapped = reverseMapToolName(block.name, toolNameMap);
|
|
203
206
|
if (mapped !== block.name) {
|
|
204
207
|
block.name = mapped;
|
|
205
208
|
modified = true;
|
|
@@ -212,7 +215,7 @@ export function stripMcpPrefixFromParsedEvent(parsed) {
|
|
|
212
215
|
if (Array.isArray(parsed.content)) {
|
|
213
216
|
for (const block of parsed.content) {
|
|
214
217
|
if ((block.type === "tool_use" || block.type === "tool_reference") && typeof block.name === "string") {
|
|
215
|
-
const mapped = reverseMapToolName(block.name);
|
|
218
|
+
const mapped = reverseMapToolName(block.name, toolNameMap);
|
|
216
219
|
if (mapped !== block.name) {
|
|
217
220
|
block.name = mapped;
|
|
218
221
|
modified = true;
|
|
@@ -803,6 +806,7 @@ function createPassthroughStream(reader, idleTimeoutMs) {
|
|
|
803
806
|
*
|
|
804
807
|
* @param {Response} response
|
|
805
808
|
* @param {object} options
|
|
809
|
+
* @param {Map<string, string>} [options.toolNameMap] - Host aliases specific to this request.
|
|
806
810
|
* @param {((stats: UsageStats) => void) | null} [options.onUsage]
|
|
807
811
|
* @param {((details: {reason: import('../backoff.mjs').RateLimitReason, invalidateToken: boolean}) => void) | null} [options.onAccountError]
|
|
808
812
|
* @param {((stats: {blockTypeFallbacks: number, deltasDropped: number, eventsDropped: number, dryRun?: boolean}) => void) | null} [options.onHostCompatShim]
|
|
@@ -839,6 +843,7 @@ export function createTransformedSSEStream(
|
|
|
839
843
|
onAccountError,
|
|
840
844
|
onHostCompatShim,
|
|
841
845
|
hostCompatShim = true,
|
|
846
|
+
toolNameMap,
|
|
842
847
|
correlationId,
|
|
843
848
|
idleTimeoutMs,
|
|
844
849
|
captureEnabled,
|
|
@@ -939,7 +944,7 @@ export function createTransformedSSEStream(
|
|
|
939
944
|
}
|
|
940
945
|
if (shimAction === "drop") return [];
|
|
941
946
|
|
|
942
|
-
const mcpModified = stripMcpPrefixFromParsedEvent(parsed);
|
|
947
|
+
const mcpModified = stripMcpPrefixFromParsedEvent(parsed, toolNameMap);
|
|
943
948
|
if (shimAction === "rewrite" || mcpModified) {
|
|
944
949
|
// Re-serialize only the `data:` line(s) this event actually changed;
|
|
945
950
|
// every other line in the block (event:, id:, comments) is untouched.
|
package/lib/oauth.mjs
CHANGED
|
@@ -179,9 +179,21 @@ function buildTokenHeaders() {
|
|
|
179
179
|
* @param {number} ms
|
|
180
180
|
* @returns {Promise<void>}
|
|
181
181
|
*/
|
|
182
|
-
function sleep(ms) {
|
|
182
|
+
function sleep(ms, signal) {
|
|
183
|
+
signal?.throwIfAborted();
|
|
183
184
|
if (ms <= 0) return Promise.resolve();
|
|
184
|
-
return new Promise((resolve) =>
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
const abort = () => {
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
signal.removeEventListener("abort", abort);
|
|
189
|
+
reject(signal.reason);
|
|
190
|
+
};
|
|
191
|
+
const timer = setTimeout(() => {
|
|
192
|
+
signal?.removeEventListener("abort", abort);
|
|
193
|
+
resolve();
|
|
194
|
+
}, ms);
|
|
195
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
196
|
+
});
|
|
185
197
|
}
|
|
186
198
|
|
|
187
199
|
/**
|
|
@@ -442,7 +454,7 @@ export function parseOAuthCallback(input) {
|
|
|
442
454
|
* Exchange an authorization code for tokens.
|
|
443
455
|
* @param {string} code
|
|
444
456
|
* @param {string} verifier
|
|
445
|
-
* @param {{ sdkTokenUserAgent?: boolean }} [options] - `sdkTokenUserAgent` is
|
|
457
|
+
* @param {{ sdkTokenUserAgent?: boolean, signal?: AbortSignal }} [options] - `sdkTokenUserAgent` is
|
|
446
458
|
* accepted and ignored. It is retained so existing call sites keep type-
|
|
447
459
|
* checking; there is only one token fingerprint. See §7 divergence D2.
|
|
448
460
|
* @returns {Promise<
|
|
@@ -458,7 +470,7 @@ export function parseOAuthCallback(input) {
|
|
|
458
470
|
* }
|
|
459
471
|
* >}
|
|
460
472
|
*/
|
|
461
|
-
export async function exchange(code, verifier,
|
|
473
|
+
export async function exchange(code, verifier, options = {}) {
|
|
462
474
|
const tokenHeaders = buildTokenHeaders();
|
|
463
475
|
const fail = (status, rawText = "", cooldownHint = { retryAfterMs: null }) => {
|
|
464
476
|
const { errorCode, reason } = parseOAuthErrorBody(rawText);
|
|
@@ -486,6 +498,7 @@ export async function exchange(code, verifier, _options = {}) {
|
|
|
486
498
|
const { code: authCode, state: authState } = parseOAuthCallback(code);
|
|
487
499
|
let result;
|
|
488
500
|
for (let attempt = 0; attempt <= OAUTH_MAX_RETRIES; attempt++) {
|
|
501
|
+
options.signal?.throwIfAborted();
|
|
489
502
|
try {
|
|
490
503
|
// SHAPE IS INPUT-DEPENDENT (D8). `state` is present only when the pasted
|
|
491
504
|
// callback carried one, so this body is five keys for a bare code and six
|
|
@@ -504,11 +517,16 @@ export async function exchange(code, verifier, _options = {}) {
|
|
|
504
517
|
method: "POST",
|
|
505
518
|
headers: tokenHeaders,
|
|
506
519
|
body: JSON.stringify(exchangeBody),
|
|
507
|
-
|
|
520
|
+
// Match the runtime's AbortSignal.any baseline; a caller signal must
|
|
521
|
+
// not replace the independent per-attempt network deadline.
|
|
522
|
+
signal: options.signal
|
|
523
|
+
? AbortSignal.any([options.signal, AbortSignal.timeout(15_000)])
|
|
524
|
+
: AbortSignal.timeout(15_000),
|
|
508
525
|
});
|
|
509
526
|
} catch (err) {
|
|
527
|
+
options.signal?.throwIfAborted();
|
|
510
528
|
if (attempt < OAUTH_MAX_RETRIES) {
|
|
511
|
-
await sleep(Math.min(500 * 2 ** attempt, 2000));
|
|
529
|
+
await sleep(Math.min(500 * 2 ** attempt, 2000), options.signal);
|
|
512
530
|
continue;
|
|
513
531
|
}
|
|
514
532
|
return fail(undefined, err instanceof Error ? err.message : String(err));
|
|
@@ -524,7 +542,7 @@ export async function exchange(code, verifier, _options = {}) {
|
|
|
524
542
|
: "";
|
|
525
543
|
|
|
526
544
|
if (attempt < OAUTH_MAX_RETRIES && isRetryableTokenStatus(result.status)) {
|
|
527
|
-
await sleep(getRetryDelayMs(result, attempt));
|
|
545
|
+
await sleep(getRetryDelayMs(result, attempt), options.signal);
|
|
528
546
|
continue;
|
|
529
547
|
}
|
|
530
548
|
|
|
@@ -638,6 +656,7 @@ export async function refreshToken(refreshTokenValue, options = {}) {
|
|
|
638
656
|
const tokenHeaders = buildTokenHeaders();
|
|
639
657
|
|
|
640
658
|
for (let attempt = 0; attempt <= OAUTH_MAX_RETRIES; attempt++) {
|
|
659
|
+
options.signal?.throwIfAborted();
|
|
641
660
|
let resp;
|
|
642
661
|
// A single AbortSignal.timeout() created outside the loop starts counting at
|
|
643
662
|
// creation, so a slow first attempt would leave the retries with no budget
|
|
@@ -658,8 +677,9 @@ export async function refreshToken(refreshTokenValue, options = {}) {
|
|
|
658
677
|
signal,
|
|
659
678
|
});
|
|
660
679
|
} catch (err) {
|
|
680
|
+
options.signal?.throwIfAborted();
|
|
661
681
|
if (attempt < OAUTH_MAX_RETRIES) {
|
|
662
|
-
await sleep(Math.min(500 * 2 ** attempt, 2000));
|
|
682
|
+
await sleep(Math.min(500 * 2 ** attempt, 2000), options.signal);
|
|
663
683
|
continue;
|
|
664
684
|
}
|
|
665
685
|
throw err;
|
|
@@ -670,7 +690,7 @@ export async function refreshToken(refreshTokenValue, options = {}) {
|
|
|
670
690
|
const retryAfterMs = getRetryDelayMs(resp, attempt);
|
|
671
691
|
|
|
672
692
|
if (attempt < OAUTH_MAX_RETRIES && isRetryableTokenStatus(resp.status)) {
|
|
673
|
-
await sleep(retryAfterMs);
|
|
693
|
+
await sleep(retryAfterMs, options.signal);
|
|
674
694
|
continue;
|
|
675
695
|
}
|
|
676
696
|
|
package/lib/refresh-lock.mjs
CHANGED
|
@@ -11,8 +11,20 @@ const DEFAULT_STALE_LOCK_MS = 20_000;
|
|
|
11
11
|
* @param {number} ms
|
|
12
12
|
* @returns {Promise<void>}
|
|
13
13
|
*/
|
|
14
|
-
function delay(ms) {
|
|
15
|
-
|
|
14
|
+
function delay(ms, signal) {
|
|
15
|
+
signal?.throwIfAborted();
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const abort = () => {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
signal.removeEventListener("abort", abort);
|
|
20
|
+
reject(signal.reason);
|
|
21
|
+
};
|
|
22
|
+
const timer = setTimeout(() => {
|
|
23
|
+
signal?.removeEventListener("abort", abort);
|
|
24
|
+
resolve();
|
|
25
|
+
}, ms);
|
|
26
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
27
|
+
});
|
|
16
28
|
}
|
|
17
29
|
|
|
18
30
|
/**
|
|
@@ -27,10 +39,11 @@ function getLockPath(accountId) {
|
|
|
27
39
|
/**
|
|
28
40
|
* Try to acquire a per-account cross-process lock.
|
|
29
41
|
* @param {string} accountId
|
|
30
|
-
* @param {{ timeoutMs?: number, backoffMs?: number, staleMs?: number }} [options]
|
|
42
|
+
* @param {{ timeoutMs?: number, backoffMs?: number, staleMs?: number, signal?: AbortSignal }} [options]
|
|
31
43
|
* @returns {Promise<{ acquired: boolean, lockPath: string | null, owner: string | null, lockInode: number | null }>}
|
|
32
44
|
*/
|
|
33
45
|
export async function acquireRefreshLock(accountId, options = {}) {
|
|
46
|
+
options.signal?.throwIfAborted();
|
|
34
47
|
const timeoutMs = options.timeoutMs ?? DEFAULT_LOCK_TIMEOUT_MS;
|
|
35
48
|
const backoffMs = options.backoffMs ?? DEFAULT_LOCK_BACKOFF_MS;
|
|
36
49
|
const staleMs = options.staleMs ?? DEFAULT_STALE_LOCK_MS;
|
|
@@ -42,6 +55,7 @@ export async function acquireRefreshLock(accountId, options = {}) {
|
|
|
42
55
|
await fs.mkdir(lockDir, { recursive: true });
|
|
43
56
|
|
|
44
57
|
while (Date.now() <= deadline) {
|
|
58
|
+
options.signal?.throwIfAborted();
|
|
45
59
|
try {
|
|
46
60
|
const handle = await fs.open(lockPath, "wx", 0o600);
|
|
47
61
|
try {
|
|
@@ -79,7 +93,7 @@ export async function acquireRefreshLock(accountId, options = {}) {
|
|
|
79
93
|
const remaining = deadline - Date.now();
|
|
80
94
|
if (remaining <= 0) break;
|
|
81
95
|
const jitter = Math.floor(Math.random() * 25);
|
|
82
|
-
await delay(Math.min(remaining, backoffMs + jitter));
|
|
96
|
+
await delay(Math.min(remaining, backoffMs + jitter), options.signal);
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
|
package/lib/session-metrics.mjs
CHANGED
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
// Session-level cache & cost tracking (Phase 4)
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
//
|
|
5
|
-
//
|
|
6
|
-
// singleton
|
|
7
|
-
//
|
|
8
|
-
// reassigned, so a plain `import { sessionMetrics }` observes the same live
|
|
9
|
-
// object everywhere. The test reset helper mutates in place (delete keys +
|
|
10
|
-
// Object.assign) precisely to preserve this shared identity.
|
|
5
|
+
// Each host runtime creates and injects its own metrics object. The exported
|
|
6
|
+
// singleton remains the default for legacy standalone helper consumers; running
|
|
7
|
+
// plugin instances never share it.
|
|
11
8
|
|
|
12
9
|
/**
|
|
13
10
|
* Factory for the initial sessionMetrics shape. Returns a fresh object each
|
|
@@ -68,8 +65,8 @@ export const sessionMetrics = createInitialSessionMetrics();
|
|
|
68
65
|
* Get rolling average cache hit rate over last 5 turns.
|
|
69
66
|
* @returns {number} 0-1
|
|
70
67
|
*/
|
|
71
|
-
export function getAverageCacheHitRate() {
|
|
72
|
-
const rates =
|
|
68
|
+
export function getAverageCacheHitRate(metrics = sessionMetrics) {
|
|
69
|
+
const rates = metrics.recentCacheRates;
|
|
73
70
|
if (rates.length === 0) return 0;
|
|
74
71
|
return rates.reduce((a, b) => a + b, 0) / rates.length;
|
|
75
72
|
}
|
package/lib/unicode-text.mjs
CHANGED
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
* Performance: `text` is segmented at most once. If `text.length <=
|
|
61
61
|
* maxUnits`, segmentation is skipped entirely (fast path) — no reason to pay
|
|
62
62
|
* for it when no truncation can possibly be needed. When truncation IS
|
|
63
|
-
* needed, the
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
63
|
+
* needed, containing() locates the cluster at the cut directly, without
|
|
64
|
+
* allocating a segment record for every preceding grapheme. ICU may inspect
|
|
65
|
+
* surrounding text to determine boundaries; no JS prefix walk or repeated
|
|
66
|
+
* concatenation is needed, even for large inputs on Node 20.
|
|
67
67
|
*
|
|
68
68
|
* @param {string} text
|
|
69
69
|
* @param {number} maxUnits - budget in UTF-16 code units (`.length`).
|
|
@@ -99,13 +99,9 @@ export function truncateGraphemes(text, maxUnits, options) {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
prefix += segment;
|
|
108
|
-
used += segmentLength;
|
|
109
|
-
}
|
|
110
|
-
return prefix + suffix;
|
|
102
|
+
// The input is longer than the limit, so this index is always in bounds.
|
|
103
|
+
// At a boundary containing() returns the next cluster; inside a cluster it
|
|
104
|
+
// returns that cluster's start. Both are exactly the longest valid prefix.
|
|
105
|
+
const { index } = segmenter.segment(input).containing(Math.floor(budgetForPrefix));
|
|
106
|
+
return input.slice(0, index) + suffix;
|
|
111
107
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-anthropic-fix",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,12 +11,30 @@
|
|
|
11
11
|
"url": "https://github.com/marco-jardim/opencode-anthropic-fix/issues"
|
|
12
12
|
},
|
|
13
13
|
"main": "./index.mjs",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.mjs",
|
|
16
|
+
"./server": "./server.mjs",
|
|
17
|
+
"./tui": "./tui.mjs",
|
|
18
|
+
"./rpc": "./lib/host/command-rpc.mjs",
|
|
19
|
+
"./index.mjs": "./index.mjs",
|
|
20
|
+
"./cli.mjs": "./cli.mjs",
|
|
21
|
+
"./lib/*": "./lib/*",
|
|
22
|
+
"./README.md": "./README.md",
|
|
23
|
+
"./LICENSE": "./LICENSE",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
14
26
|
"files": [
|
|
15
27
|
"index.mjs",
|
|
28
|
+
"server.mjs",
|
|
29
|
+
"tui.mjs",
|
|
16
30
|
"cli.mjs",
|
|
17
31
|
"lib/**/*.mjs",
|
|
18
32
|
"!lib/**/*.test.mjs",
|
|
19
33
|
"README.md",
|
|
34
|
+
"docs/opencode-v2.md",
|
|
35
|
+
"docs/opencode-v2-architecture.md",
|
|
36
|
+
"licenses/",
|
|
37
|
+
"NOTICE",
|
|
20
38
|
"LICENSE"
|
|
21
39
|
],
|
|
22
40
|
"scripts": {
|
|
@@ -48,6 +66,7 @@
|
|
|
48
66
|
"devDependencies": {
|
|
49
67
|
"@eslint/js": "^10.0.1",
|
|
50
68
|
"@opencode-ai/plugin": "^1.2.27",
|
|
69
|
+
"@opencode/plugin": "2.0.21",
|
|
51
70
|
"@vitest/coverage-v8": "^4.0.18",
|
|
52
71
|
"esbuild": "^0.27.3",
|
|
53
72
|
"eslint": "^10.0.0",
|
|
@@ -57,6 +76,7 @@
|
|
|
57
76
|
"vitest": "^4.0.18"
|
|
58
77
|
},
|
|
59
78
|
"dependencies": {
|
|
79
|
+
"@ai-sdk/anthropic": "3.0.111",
|
|
60
80
|
"@tormentalabs/claude-code-wire-compat": "latest"
|
|
61
81
|
}
|
|
62
82
|
}
|
package/server.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The modern hosts resolve ./server. Older v1 releases still load index.mjs.
|
|
3
|
+
* Keep each implementation lazy so neither host initializes the other runtime.
|
|
4
|
+
*/
|
|
5
|
+
export default {
|
|
6
|
+
id: "opencode-anthropic-fix",
|
|
7
|
+
async server(context) {
|
|
8
|
+
const { AnthropicAuthPlugin } = await import("./index.mjs");
|
|
9
|
+
return AnthropicAuthPlugin(context);
|
|
10
|
+
},
|
|
11
|
+
async setup(context) {
|
|
12
|
+
const { setupV2 } = await import("./lib/host/v2.mjs");
|
|
13
|
+
return setupV2(context);
|
|
14
|
+
},
|
|
15
|
+
};
|