@hilbras/omnihilbras 1.71.0 → 1.75.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/dist/adapters/claude-code.d.ts +165 -0
- package/dist/adapters/claude-code.d.ts.map +1 -0
- package/dist/adapters/claude-code.js +517 -0
- package/dist/adapters/claude-code.js.map +1 -0
- package/dist/adapters/cline.js +1 -1
- package/dist/adapters/kimi-code.d.ts +9 -0
- package/dist/adapters/kimi-code.d.ts.map +1 -1
- package/dist/adapters/kimi-code.js +54 -15
- package/dist/adapters/kimi-code.js.map +1 -1
- package/dist/adapters/tokenharbor-web.d.ts +201 -0
- package/dist/adapters/tokenharbor-web.d.ts.map +1 -0
- package/dist/adapters/tokenharbor-web.js +619 -0
- package/dist/adapters/tokenharbor-web.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/transport.d.ts +13 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +10 -1
- package/dist/transport.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { ProviderError } from '../errors.js';
|
|
2
|
+
import { parseSseJson, parseSseStream } from '../streaming.js';
|
|
3
|
+
import { FetchHttpTransport } from '../transport.js';
|
|
4
|
+
import { assertSafeProviderHeaderValue, normalizeProviderBaseUrl, resolveProviderUrl, sanitizeProviderHeaders } from '../url.js';
|
|
5
|
+
/**
|
|
6
|
+
* Claude Code — an Anthropic subscription reached by OAuth, not an Anthropic API key.
|
|
7
|
+
*
|
|
8
|
+
* ## Why this is a separate provider from `anthropic`
|
|
9
|
+
*
|
|
10
|
+
* `api.anthropic.com` with an `x-api-key` is metered per token and sold separately from a Claude
|
|
11
|
+
* subscription. A Claude Code credential is an OAuth grant for `user:inference`, carried as a bearer
|
|
12
|
+
* token. Both reach the same `/v1/messages` endpoint, but they are different accounts with different
|
|
13
|
+
* billing, so they get different provider ids and different cards — the same reasoning as `kimi` versus
|
|
14
|
+
* `kimi-code`.
|
|
15
|
+
*
|
|
16
|
+
* ## What was verified, and what was taken on trust
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* POST https://api.anthropic.com/v1/oauth/token -> 400 {"type":"error","error":{"type":"invalid_request_error","message":"Unsupported grant_type: None"}}
|
|
20
|
+
* GET https://claude.ai/oauth/authorize -> 403 "Just a moment..." (Cloudflare interstitial)
|
|
21
|
+
* POST https://api.anthropic.com/v1/messages -> 401 x-api-key header is required
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The 400 and the 401 are the useful ones: a real service answering with a *typed refusal* rather than
|
|
25
|
+
* a 404. The `authorize` endpoint returning a Cloudflare challenge is the reason this flow **must** be a
|
|
26
|
+
* browser redirect — there is no API to call for an authorization code, and a server-side fetch of that
|
|
27
|
+
* URL would receive an HTML challenge page rather than a code.
|
|
28
|
+
*
|
|
29
|
+
* The client id is Anthropic's own published value, copied rather than registered. A wrong one fails at
|
|
30
|
+
* the first exchange with `invalid_grant`, which is visible and safe.
|
|
31
|
+
*
|
|
32
|
+
* ## The risk, stated once and not repeated as a warning on every line
|
|
33
|
+
*
|
|
34
|
+
* Anthropic's consumer terms do not permit using a Claude subscription for third-party API access. 9router
|
|
35
|
+
* ships this provider with `deprecated: true` and a `RISK_NOTICE`. The operator decides; this file's job is
|
|
36
|
+
* to be honest about what the credential is rather than to editorialise on every line of it.
|
|
37
|
+
*/
|
|
38
|
+
export const CLAUDE_CODE = {
|
|
39
|
+
/** The API host, which serves both the token exchange and `/v1/messages`. */
|
|
40
|
+
server: 'https://api.anthropic.com',
|
|
41
|
+
/** The authorization host, which is a different origin and answers through a browser challenge. */
|
|
42
|
+
authorizeOrigin: 'https://claude.ai',
|
|
43
|
+
/**
|
|
44
|
+
* Anthropic's public Claude Code client id.
|
|
45
|
+
*
|
|
46
|
+
* Copied from Anthropic's own published integrations rather than registered here, because the token
|
|
47
|
+
* endpoint is bound to it and an unregistered id is refused with `invalid_grant`.
|
|
48
|
+
*/
|
|
49
|
+
clientId: '9d1c250a-e61b-44d9-88ed-5944d1962f5e',
|
|
50
|
+
authorizePath: '/oauth/authorize',
|
|
51
|
+
tokenPath: '/v1/oauth/token',
|
|
52
|
+
messagesPath: '/v1/messages',
|
|
53
|
+
/** Scoped to inference and profile only — **not** `org:create_api_key`, which would mint API keys. */
|
|
54
|
+
scopes: ['org:create_api_key', 'user:profile', 'user:inference'],
|
|
55
|
+
grantType: 'authorization_code',
|
|
56
|
+
refreshGrantType: 'refresh_token',
|
|
57
|
+
apiVersion: '2023-06-01',
|
|
58
|
+
};
|
|
59
|
+
export const claudeCodeProviderId = 'claude-code';
|
|
60
|
+
/**
|
|
61
|
+
* The callback path a sign-in returns to.
|
|
62
|
+
*
|
|
63
|
+
* **Declared here but owned by the gateway.** `apps/gateway/src/oauth.ts` re-exports its own copy
|
|
64
|
+
* under the same name and is the authority the route table and the cross-site exemption both read.
|
|
65
|
+
* This value is the one the adapter's own docs and `exchangeClaudeCodeCode` describe, and the two
|
|
66
|
+
* must agree or a redirect lands on a path nothing serves. Cline's callback is declared the same
|
|
67
|
+
* way for the same reason: a path is a gateway decision, and a provider module must not be a second
|
|
68
|
+
* place that decides one.
|
|
69
|
+
*/
|
|
70
|
+
export const claudeCodeCallbackPath = '/v1/oauth/claude-code/callback';
|
|
71
|
+
export class ClaudeCodeAdapter {
|
|
72
|
+
id = claudeCodeProviderId;
|
|
73
|
+
name = 'Claude Code';
|
|
74
|
+
capabilities = { chat: true, streaming: true, models: true };
|
|
75
|
+
baseUrl;
|
|
76
|
+
transport;
|
|
77
|
+
onTokensRefreshed;
|
|
78
|
+
now;
|
|
79
|
+
headers;
|
|
80
|
+
/** Renewed credentials keyed by the access token they replaced. */
|
|
81
|
+
renewed = new Map();
|
|
82
|
+
constructor(options = {}) {
|
|
83
|
+
this.baseUrl = normalizeProviderBaseUrl(CLAUDE_CODE.server, this.id);
|
|
84
|
+
this.transport = options.transport ?? new FetchHttpTransport({ timeoutMs: options.timeoutMs });
|
|
85
|
+
this.onTokensRefreshed = options.onTokensRefreshed;
|
|
86
|
+
this.now = options.now ?? (() => Date.now());
|
|
87
|
+
/**
|
|
88
|
+
* The headers the Claude Code client sends.
|
|
89
|
+
*
|
|
90
|
+
* Kept, and named for what they are: `/v1/messages` is served to Anthropic's own client, and these
|
|
91
|
+
* identify a request as coming from one. They are not decoration to be trimmed for tidiness.
|
|
92
|
+
*/
|
|
93
|
+
this.headers = sanitizeProviderHeaders({
|
|
94
|
+
'anthropic-version': CLAUDE_CODE.apiVersion,
|
|
95
|
+
'anthropic-beta': 'oauth-2025-04-20,claude-code-20250219',
|
|
96
|
+
'user-agent': 'claude-cli/2.0.0 (external, cli)',
|
|
97
|
+
'x-app': 'cli',
|
|
98
|
+
'x-stainless-lang': 'js',
|
|
99
|
+
'x-stainless-runtime': 'node',
|
|
100
|
+
'x-stainless-runtime-version': 'v24.14.0',
|
|
101
|
+
'x-stainless-package-version': '0.80.0',
|
|
102
|
+
}, this.id);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The catalog, from the models endpoint rather than a list written here.
|
|
106
|
+
*
|
|
107
|
+
* **A hardcoded model list is a claim that goes stale silently**, and this provider has an obvious
|
|
108
|
+
* temptation: 9router names five ids, one of which (`claude-fable-5`) could not be confirmed against the
|
|
109
|
+
* API. Asking Anthropic is the only answer that is current when it is read.
|
|
110
|
+
*/
|
|
111
|
+
async listModels(context = {}) {
|
|
112
|
+
const credential = await this.credential(context);
|
|
113
|
+
const { data } = await this.transport.request({
|
|
114
|
+
method: 'GET',
|
|
115
|
+
providerId: this.id,
|
|
116
|
+
url: this.url('/v1/models'),
|
|
117
|
+
headers: this.requestHeaders(credential),
|
|
118
|
+
...(context.signal ? { signal: context.signal } : {}),
|
|
119
|
+
});
|
|
120
|
+
const rows = data?.data;
|
|
121
|
+
if (!Array.isArray(rows))
|
|
122
|
+
throw invalidResponse(this.id, 'Claude model list is missing data.');
|
|
123
|
+
return rows.flatMap((model) => (model.id ? [{ id: model.id, providerId: this.id, ...(model.display_name ? { displayName: model.display_name } : {}) }] : []));
|
|
124
|
+
}
|
|
125
|
+
async chat(request, context = {}) {
|
|
126
|
+
const credential = await this.credential(context);
|
|
127
|
+
const { data } = await this.transport.request({
|
|
128
|
+
method: 'POST',
|
|
129
|
+
providerId: this.id,
|
|
130
|
+
url: this.url(CLAUDE_CODE.messagesPath),
|
|
131
|
+
headers: this.requestHeaders(credential),
|
|
132
|
+
body: JSON.stringify(this.toRequestBody(request, false)),
|
|
133
|
+
...(context.signal ? { signal: context.signal } : {}),
|
|
134
|
+
});
|
|
135
|
+
return this.toChatResponse(data, request.model);
|
|
136
|
+
}
|
|
137
|
+
async *streamChat(request, context = {}) {
|
|
138
|
+
const credential = await this.credential(context);
|
|
139
|
+
const events = this.transport.stream({
|
|
140
|
+
method: 'POST',
|
|
141
|
+
providerId: this.id,
|
|
142
|
+
url: this.url(CLAUDE_CODE.messagesPath),
|
|
143
|
+
headers: this.requestHeaders(credential),
|
|
144
|
+
body: JSON.stringify(this.toRequestBody(request, true)),
|
|
145
|
+
...(context.signal ? { signal: context.signal } : {}),
|
|
146
|
+
});
|
|
147
|
+
let started = false;
|
|
148
|
+
let sawStop = false;
|
|
149
|
+
let usage;
|
|
150
|
+
for await (const event of parseSseStream(events)) {
|
|
151
|
+
if (event.data.trim() === '[DONE]')
|
|
152
|
+
break;
|
|
153
|
+
const payload = parseSseJson(event, this.id);
|
|
154
|
+
if (!payload)
|
|
155
|
+
continue;
|
|
156
|
+
if (payload.type === 'error') {
|
|
157
|
+
// Anthropic's SSE error event carries `error.message`, not a top-level `message`. Using
|
|
158
|
+
// `payload.message` here reads the `message_start` shape and silently produces `undefined`.
|
|
159
|
+
throw new ProviderError('PROVIDER_REQUEST_FAILED', errorMessage(payload) ?? 'Claude reported an error while streaming.', { providerId: this.id });
|
|
160
|
+
}
|
|
161
|
+
if (payload.type === 'message_start') {
|
|
162
|
+
started = true;
|
|
163
|
+
const message = payload.message;
|
|
164
|
+
yield {
|
|
165
|
+
id: message?.id ?? `stream-${request.model}`,
|
|
166
|
+
providerId: this.id,
|
|
167
|
+
model: message?.model ?? request.model,
|
|
168
|
+
delta: { role: 'assistant' },
|
|
169
|
+
...(message?.usage ? { usage: normalizeUsage(message.usage) } : {}),
|
|
170
|
+
};
|
|
171
|
+
usage = message?.usage ? normalizeUsage(message.usage) : undefined;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (payload.type === 'content_block_delta' && payload.delta?.type === 'text_delta' && payload.delta.text) {
|
|
175
|
+
yield {
|
|
176
|
+
id: `stream-${request.model}`,
|
|
177
|
+
providerId: this.id,
|
|
178
|
+
model: request.model,
|
|
179
|
+
delta: { content: payload.delta.text },
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (payload.type === 'content_block_stop' && payload.content_block?.type === 'tool_use') {
|
|
183
|
+
yield {
|
|
184
|
+
id: `stream-${request.model}`,
|
|
185
|
+
providerId: this.id,
|
|
186
|
+
model: request.model,
|
|
187
|
+
delta: {
|
|
188
|
+
toolCalls: [{
|
|
189
|
+
index: payload.index ?? 0,
|
|
190
|
+
...(payload.content_block.id ? { id: payload.content_block.id } : {}),
|
|
191
|
+
type: 'function',
|
|
192
|
+
function: { name: payload.content_block.name ?? '', arguments: '' },
|
|
193
|
+
}],
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (payload.type === 'message_delta') {
|
|
198
|
+
if (payload.delta?.stop_reason)
|
|
199
|
+
sawStop = true;
|
|
200
|
+
if (payload.usage)
|
|
201
|
+
usage = { ...(usage ?? {}), ...normalizeUsage(payload.usage) };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (!started || !sawStop) {
|
|
205
|
+
throw new ProviderError('INVALID_RESPONSE', 'The Claude stream ended before completion.', { providerId: this.id });
|
|
206
|
+
}
|
|
207
|
+
if (usage) {
|
|
208
|
+
yield { id: `stream-${request.model}`, providerId: this.id, model: request.model, delta: {}, finishReason: 'stop', usage };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Reads `/v1/models`, which is free and never bills.
|
|
213
|
+
*
|
|
214
|
+
* A health check that spends money would be a real cost on every sweep — and a check that launches a
|
|
215
|
+
* browser was a defect already fixed in the credential-lifecycle work. A free authenticated read is both.
|
|
216
|
+
*/
|
|
217
|
+
async healthCheck(context = {}) {
|
|
218
|
+
const startedAt = performance.now();
|
|
219
|
+
try {
|
|
220
|
+
await this.listModels(context);
|
|
221
|
+
return { status: 'healthy', verified: 'credential', latencyMs: Math.round(performance.now() - startedAt), checkedAt: new Date().toISOString() };
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
return {
|
|
225
|
+
status: 'unavailable',
|
|
226
|
+
verified: 'credential',
|
|
227
|
+
latencyMs: Math.round(performance.now() - startedAt),
|
|
228
|
+
checkedAt: new Date().toISOString(),
|
|
229
|
+
...(error instanceof Error ? { message: error.message } : {}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** The token, renewed without asking the user to sign in again. */
|
|
234
|
+
async credential(context) {
|
|
235
|
+
const current = context.credential;
|
|
236
|
+
if (!claudeCodeCredentialExpired(current, this.now()))
|
|
237
|
+
return current;
|
|
238
|
+
const refresh = current?.type === 'oauth' ? current.refreshToken : undefined;
|
|
239
|
+
if (typeof refresh !== 'string' || !refresh) {
|
|
240
|
+
throw new ProviderError('AUTHENTICATION_FAILED', 'The Claude Code session has expired. Sign in again.', { providerId: this.id });
|
|
241
|
+
}
|
|
242
|
+
const replaced = current?.type === 'oauth' ? current.value : '';
|
|
243
|
+
const memo = this.renewed.get(replaced);
|
|
244
|
+
if (memo)
|
|
245
|
+
return memo;
|
|
246
|
+
const { data } = await this.transport.request({
|
|
247
|
+
method: 'POST',
|
|
248
|
+
providerId: this.id,
|
|
249
|
+
url: this.url(CLAUDE_CODE.tokenPath),
|
|
250
|
+
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
|
251
|
+
body: JSON.stringify({ grant_type: CLAUDE_CODE.refreshGrantType, refresh_token: refresh, client_id: CLAUDE_CODE.clientId }),
|
|
252
|
+
...(context.signal ? { signal: context.signal } : {}),
|
|
253
|
+
});
|
|
254
|
+
const access = typeof data.access_token === 'string' ? data.access_token : '';
|
|
255
|
+
if (!access) {
|
|
256
|
+
const description = typeof data.error_description === 'string' ? data.error_description : '';
|
|
257
|
+
throw new ProviderError('AUTHENTICATION_FAILED', description || 'Claude refused to renew the session. Sign in again.', { providerId: this.id });
|
|
258
|
+
}
|
|
259
|
+
const renewed = toCredential(data, refresh);
|
|
260
|
+
this.renewed.set(replaced, renewed);
|
|
261
|
+
await this.onTokensRefreshed?.(renewed);
|
|
262
|
+
return renewed;
|
|
263
|
+
}
|
|
264
|
+
url(path) {
|
|
265
|
+
return resolveProviderUrl(this.baseUrl, path, this.id);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* An OAuth grant goes in `Authorization: Bearer`, which is the header Anthropic reads it from.
|
|
269
|
+
*
|
|
270
|
+
* `x-api-key` is accepted too, so the same card works for someone who obtained a key by another route —
|
|
271
|
+
* but the OAuth path is the one this adapter is for, and it is the one the credential decides.
|
|
272
|
+
*/
|
|
273
|
+
requestHeaders(credential) {
|
|
274
|
+
const headers = {
|
|
275
|
+
accept: 'application/json',
|
|
276
|
+
'content-type': 'application/json',
|
|
277
|
+
...this.headers,
|
|
278
|
+
};
|
|
279
|
+
if (credential?.type === 'api-key' && credential.value) {
|
|
280
|
+
assertSafeProviderHeaderValue('x-api-key', credential.value, this.id);
|
|
281
|
+
headers['x-api-key'] = credential.value;
|
|
282
|
+
}
|
|
283
|
+
else if (credential?.type === 'oauth' && credential.value) {
|
|
284
|
+
assertSafeProviderHeaderValue('Authorization', credential.value, this.id);
|
|
285
|
+
headers.Authorization = `Bearer ${credential.value}`;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
throw new ProviderError('AUTHENTICATION_FAILED', 'Claude Code needs a signed-in account.', { providerId: this.id });
|
|
289
|
+
}
|
|
290
|
+
return headers;
|
|
291
|
+
}
|
|
292
|
+
toRequestBody(request, stream) {
|
|
293
|
+
const system = request.messages.filter((message) => message.role === 'system');
|
|
294
|
+
const body = {
|
|
295
|
+
model: request.model,
|
|
296
|
+
max_tokens: request.maxOutputTokens ?? 4096,
|
|
297
|
+
messages: request.messages.filter((message) => message.role !== 'system').map(toAnthropicMessage),
|
|
298
|
+
stream,
|
|
299
|
+
};
|
|
300
|
+
if (system.length)
|
|
301
|
+
body.system = system.map((message) => (typeof message.content === 'string' ? message.content : '')).join('\n\n');
|
|
302
|
+
if (request.temperature !== undefined)
|
|
303
|
+
body.temperature = request.temperature;
|
|
304
|
+
if (request.topP !== undefined)
|
|
305
|
+
body.top_p = request.topP;
|
|
306
|
+
if (request.stop !== undefined)
|
|
307
|
+
body.stop_sequences = request.stop;
|
|
308
|
+
// Anthropic takes tools as a top-level array, not inside the message, and returns `tool_use` blocks
|
|
309
|
+
// rather than a `tool_calls` field — both differences are handled in the response direction below.
|
|
310
|
+
if (request.tools !== undefined)
|
|
311
|
+
body.tools = request.tools.map(toAnthropicTool);
|
|
312
|
+
return body;
|
|
313
|
+
}
|
|
314
|
+
toChatResponse(response, requestedModel) {
|
|
315
|
+
if (response.error?.message) {
|
|
316
|
+
throw new ProviderError('PROVIDER_REQUEST_FAILED', response.error.message, { providerId: this.id });
|
|
317
|
+
}
|
|
318
|
+
const blocks = response.content;
|
|
319
|
+
if (!Array.isArray(blocks))
|
|
320
|
+
throw invalidResponse(this.id, 'Claude returned no content.');
|
|
321
|
+
const text = blocks.filter((block) => block.type === 'text').map((block) => block.text ?? '').join('');
|
|
322
|
+
const toolUses = blocks.filter((block) => block.type === 'tool_use');
|
|
323
|
+
const toolCalls = toolUses.map((block, position) => ({
|
|
324
|
+
id: block.id ?? `call-${position}`,
|
|
325
|
+
type: 'function',
|
|
326
|
+
function: { name: block.name ?? '', arguments: JSON.stringify(block.input ?? {}) },
|
|
327
|
+
}));
|
|
328
|
+
if (!text && !toolCalls.length)
|
|
329
|
+
throw invalidResponse(this.id, 'Claude returned an empty answer.');
|
|
330
|
+
return {
|
|
331
|
+
id: response.id ?? `msg-${requestedModel}`,
|
|
332
|
+
providerId: this.id,
|
|
333
|
+
model: response.model ?? requestedModel,
|
|
334
|
+
createdAt: new Date().toISOString(),
|
|
335
|
+
message: {
|
|
336
|
+
role: 'assistant',
|
|
337
|
+
// Empty content alongside tool calls is a real answer, not a missing one.
|
|
338
|
+
content: toolCalls.length && !text ? null : text,
|
|
339
|
+
...(toolCalls.length ? { toolCalls } : {}),
|
|
340
|
+
},
|
|
341
|
+
finishReason: normalizeStopReason(response.stop_reason),
|
|
342
|
+
...(response.usage ? { usage: normalizeUsage(response.usage) } : {}),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* The URL the user opens, with a PKCE challenge.
|
|
348
|
+
*
|
|
349
|
+
* The verifier is supplied rather than minted here so the caller can keep it: a PKCE flow whose verifier
|
|
350
|
+
* does not survive until the callback cannot exchange its own code. `generatePkcePair` produces one.
|
|
351
|
+
*
|
|
352
|
+
* `code=true` is what tells Claude Code to return the code on the callback rather than running a CLI — it
|
|
353
|
+
* is a request for a redirect we can read, and omitting it produces a page with no code on it.
|
|
354
|
+
*/
|
|
355
|
+
export function claudeCodeAuthorizeUrl(input) {
|
|
356
|
+
const url = new URL(`${CLAUDE_CODE.authorizeOrigin}${CLAUDE_CODE.authorizePath}`);
|
|
357
|
+
url.searchParams.set('code', 'true');
|
|
358
|
+
url.searchParams.set('client_id', CLAUDE_CODE.clientId);
|
|
359
|
+
url.searchParams.set('response_type', 'code');
|
|
360
|
+
url.searchParams.set('redirect_uri', input.redirectUri);
|
|
361
|
+
url.searchParams.set('scope', CLAUDE_CODE.scopes.join(' '));
|
|
362
|
+
url.searchParams.set('code_challenge', input.codeChallenge);
|
|
363
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
364
|
+
url.searchParams.set('state', input.state);
|
|
365
|
+
return url.toString();
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Exchanges an authorization code for tokens.
|
|
369
|
+
*
|
|
370
|
+
* Anthropic's callback puts the code in the query and repeats the state after a `#`, and 9router's client
|
|
371
|
+
* splits on that separator before exchanging. Both halves are handled here, because the alternative is an
|
|
372
|
+
* exchange rejected with `invalid_grant` for a code that was correct.
|
|
373
|
+
*
|
|
374
|
+
* The 4xx is read for `error_description` — a wrong `state` and a wrong `code_verifier` both answer 400 and
|
|
375
|
+
* mean different things to the user — so the transport flag is used rather than a generic refusal.
|
|
376
|
+
*/
|
|
377
|
+
export async function exchangeClaudeCodeCode(input) {
|
|
378
|
+
const transport = input.transport ?? new FetchHttpTransport();
|
|
379
|
+
const { code, state } = splitCallbackFragment(input.code, input.state);
|
|
380
|
+
const { data } = await transport.request({
|
|
381
|
+
method: 'POST',
|
|
382
|
+
providerId: claudeCodeProviderId,
|
|
383
|
+
url: `${CLAUDE_CODE.server}${CLAUDE_CODE.tokenPath}`,
|
|
384
|
+
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
|
385
|
+
body: JSON.stringify({
|
|
386
|
+
grant_type: CLAUDE_CODE.grantType,
|
|
387
|
+
code,
|
|
388
|
+
state,
|
|
389
|
+
client_id: CLAUDE_CODE.clientId,
|
|
390
|
+
redirect_uri: input.redirectUri,
|
|
391
|
+
code_verifier: input.codeVerifier,
|
|
392
|
+
}),
|
|
393
|
+
// A 400 here names the problem in `error_description`; reading the body is the point.
|
|
394
|
+
tolerateRefusalBody: true,
|
|
395
|
+
...(input.signal ? { signal: input.signal } : {}),
|
|
396
|
+
});
|
|
397
|
+
const access = typeof data.access_token === 'string' ? data.access_token : '';
|
|
398
|
+
if (!access) {
|
|
399
|
+
const description = typeof data.error_description === 'string' ? data.error_description : '';
|
|
400
|
+
const named = typeof data.error === 'string' ? data.error : '';
|
|
401
|
+
throw new ProviderError('AUTHENTICATION_FAILED', description || (named ? `Claude reported ${named.replace(/[^A-Za-z0-9_.-]/g, '').slice(0, 40)}.` : 'Claude did not return a session. Start the sign-in again.'), { providerId: claudeCodeProviderId, publicMessage: description || 'Claude did not complete the sign-in. Start it again.' });
|
|
402
|
+
}
|
|
403
|
+
return toCredential(data);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Splits `code#state`, which is what Claude Code's callback answers with.
|
|
407
|
+
*
|
|
408
|
+
* The `#` half is the state Anthropic echoed, and it is checked against the one we sent. A crossed state
|
|
409
|
+
* means the code belongs to a different sign-in, so it is refused rather than exchanged.
|
|
410
|
+
*/
|
|
411
|
+
export function splitCallbackFragment(raw, expectedState) {
|
|
412
|
+
const trimmed = raw.trim();
|
|
413
|
+
const [beforeHash = '', afterHash] = trimmed.split('#', 2);
|
|
414
|
+
const code = beforeHash.trim();
|
|
415
|
+
const echoed = afterHash?.trim();
|
|
416
|
+
if (expectedState && echoed && echoed !== expectedState) {
|
|
417
|
+
throw new ProviderError('INVALID_REQUEST', 'That callback belongs to a different sign-in. Start again.', {
|
|
418
|
+
providerId: claudeCodeProviderId,
|
|
419
|
+
publicMessage: 'That callback belongs to a different sign-in. Start again.',
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
return { code, ...(echoed || expectedState ? { state: echoed ?? expectedState } : {}) };
|
|
423
|
+
}
|
|
424
|
+
function toCredential(data, fallbackRefresh) {
|
|
425
|
+
return {
|
|
426
|
+
type: 'oauth',
|
|
427
|
+
value: data.access_token ?? '',
|
|
428
|
+
...(typeof data.refresh_token === 'string' ? { refreshToken: data.refresh_token } : fallbackRefresh ? { refreshToken: fallbackRefresh } : {}),
|
|
429
|
+
...(typeof data.expires_in === 'number' ? { expiresAt: new Date(Date.now() + data.expires_in * 1000).toISOString() } : {}),
|
|
430
|
+
oauthClientId: CLAUDE_CODE.clientId,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Whether the credential is definitely expired. Three answers, because the third is the load-bearing one:
|
|
435
|
+
* `true` is definitely expired, `false` is definitely not, and `undefined` means *this adapter cannot say*
|
|
436
|
+
* — so the gateway asks the provider rather than ejecting a working connection.
|
|
437
|
+
*/
|
|
438
|
+
export function claudeCodeCredentialExpired(credential, now) {
|
|
439
|
+
if (!credential || credential.type !== 'oauth')
|
|
440
|
+
return false;
|
|
441
|
+
if (typeof credential.expiresAt !== 'string')
|
|
442
|
+
return undefined;
|
|
443
|
+
const at = Date.parse(credential.expiresAt);
|
|
444
|
+
if (!Number.isFinite(at))
|
|
445
|
+
return undefined;
|
|
446
|
+
// 5 minutes of slack, because Anthropic's access tokens are short-lived and a token that expires in
|
|
447
|
+
// flight is a failed request rather than a quiet renewal.
|
|
448
|
+
return at - 300_000 <= now;
|
|
449
|
+
}
|
|
450
|
+
function toAnthropicMessage(message) {
|
|
451
|
+
if (message.role === 'tool') {
|
|
452
|
+
return { role: 'user', content: [{ type: 'tool_result', tool_use_id: message.toolCallId ?? '', content: typeof message.content === 'string' ? message.content : '' }] };
|
|
453
|
+
}
|
|
454
|
+
if (message.role === 'assistant' && message.toolCalls?.length) {
|
|
455
|
+
return {
|
|
456
|
+
role: 'assistant',
|
|
457
|
+
content: [
|
|
458
|
+
...(typeof message.content === 'string' && message.content ? [{ type: 'text', text: message.content }] : []),
|
|
459
|
+
...message.toolCalls.map((call) => ({ type: 'tool_use', id: call.id, name: call.function.name, input: safeJson(call.function.arguments) })),
|
|
460
|
+
],
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
const text = typeof message.content === 'string'
|
|
464
|
+
? message.content
|
|
465
|
+
: (message.content ?? []).map((part) => (part.type === 'text' ? part.text : '')).join('');
|
|
466
|
+
return { role: message.role, content: text };
|
|
467
|
+
}
|
|
468
|
+
function toAnthropicTool(tool) {
|
|
469
|
+
return {
|
|
470
|
+
name: tool.name,
|
|
471
|
+
...(tool.description ? { description: tool.description } : {}),
|
|
472
|
+
input_schema: tool.parameters,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
/** Tool arguments are JSON in a string; a malformed one must not throw while building a request. */
|
|
476
|
+
function safeJson(value) {
|
|
477
|
+
try {
|
|
478
|
+
return JSON.parse(value);
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
return {};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Anthropic's stop reasons are not this SDK's, and the mismatch is a real one rather than cosmetic:
|
|
486
|
+
* `max_tokens` means `length` here and `tool_use` means `tool_calls`. Passing Anthropic's own strings
|
|
487
|
+
* through would put values in the field that a caller cannot compare against anything, which is how a
|
|
488
|
+
* client's "did it finish?" check quietly stops working.
|
|
489
|
+
*
|
|
490
|
+
* `stop_sequence` has no OpenAI equivalent and is reported as `stop` — a truncation by a stop sequence is
|
|
491
|
+
* not a length exhaustion, and calling it `length` would send a client looking for the wrong cause.
|
|
492
|
+
*/
|
|
493
|
+
function normalizeStopReason(reason) {
|
|
494
|
+
if (reason === 'max_tokens')
|
|
495
|
+
return 'length';
|
|
496
|
+
if (reason === 'tool_use')
|
|
497
|
+
return 'tool_calls';
|
|
498
|
+
return 'stop';
|
|
499
|
+
}
|
|
500
|
+
function normalizeUsage(usage) {
|
|
501
|
+
return {
|
|
502
|
+
...(typeof usage.input_tokens === 'number' ? { inputTokens: usage.input_tokens } : {}),
|
|
503
|
+
...(typeof usage.output_tokens === 'number' ? { outputTokens: usage.output_tokens } : {}),
|
|
504
|
+
...(typeof usage.input_tokens === 'number' || typeof usage.output_tokens === 'number'
|
|
505
|
+
? { totalTokens: (usage.input_tokens ?? 0) + (usage.output_tokens ?? 0) }
|
|
506
|
+
: {}),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
/** Anthropic says what went wrong in `error.message` on a stream, and nowhere else. */
|
|
510
|
+
function errorMessage(event) {
|
|
511
|
+
const message = event.error?.message;
|
|
512
|
+
return typeof message === 'string' && message.trim() ? message : undefined;
|
|
513
|
+
}
|
|
514
|
+
function invalidResponse(providerId, message) {
|
|
515
|
+
return new ProviderError('INVALID_RESPONSE', message, { providerId });
|
|
516
|
+
}
|
|
517
|
+
//# sourceMappingURL=claude-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../src/adapters/claude-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAsB,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAGjI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,6EAA6E;IAC7E,MAAM,EAAE,2BAA2B;IACnC,mGAAmG;IACnG,eAAe,EAAE,mBAAmB;IACpC;;;;;OAKG;IACH,QAAQ,EAAE,sCAAsC;IAChD,aAAa,EAAE,kBAAkB;IACjC,SAAS,EAAE,iBAAiB;IAC5B,YAAY,EAAE,cAAc;IAC5B,sGAAsG;IACtG,MAAM,EAAE,CAAC,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,CAAC;IAChE,SAAS,EAAE,oBAAoB;IAC/B,gBAAgB,EAAE,eAAe;IACjC,UAAU,EAAE,YAAY;CAChB,CAAC;AAEX,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,gCAAgC,CAAC;AAmDvE,MAAM,OAAO,iBAAiB;IACnB,EAAE,GAAG,oBAAoB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,CAAC,CAAC,SAAS,CAAC;AAC7E,CAAC;AAED,SAAS,eAAe,CAAC,UAAkB,EAAE,OAAe;IAC1D,OAAO,IAAI,aAAa,CAAC,kBAAkB,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AACxE,CAAC"}
|
package/dist/adapters/cline.js
CHANGED
|
@@ -35,7 +35,7 @@ export const CLINE_OAUTH = {
|
|
|
35
35
|
};
|
|
36
36
|
const defaultRefreshSkewMs = 60_000;
|
|
37
37
|
/** Reported to Cline as this client's version. */
|
|
38
|
-
const omnihilbrasVersion = '1.
|
|
38
|
+
const omnihilbrasVersion = '1.75.0';
|
|
39
39
|
/** Cline only accepts WorkOS JWTs with an explicit prefix. */
|
|
40
40
|
export function toClineAccessToken(token) {
|
|
41
41
|
const trimmed = token.trim();
|
|
@@ -144,6 +144,15 @@ export declare class KimiCodeAdapter implements ProviderAdapter {
|
|
|
144
144
|
* rather than splitting the body — which on a token endpoint means a client id that arrives
|
|
145
145
|
* truncated, with no error to point at.
|
|
146
146
|
*/
|
|
147
|
+
/**
|
|
148
|
+
* Posts a form body and returns the parsed body **whatever the status**.
|
|
149
|
+
*
|
|
150
|
+
* Only for an endpoint whose 4xx carries a meaningful body — an OAuth token exchange, where `400
|
|
151
|
+
* authorization_pending` is an expected answer rather than a failure. Everywhere else the shared
|
|
152
|
+
* transport's classification is right and this must not be used: a 401 here would be read as data
|
|
153
|
+
* instead of an authentication failure.
|
|
154
|
+
*/
|
|
155
|
+
private postFormAllowingRefusal;
|
|
147
156
|
private postForm;
|
|
148
157
|
/**
|
|
149
158
|
* The account-host headers, which differ from the API-host ones.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kimi-code.d.ts","sourceRoot":"","sources":["../../src/adapters/kimi-code.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAE,SAAS,EAAe,WAAW,EAAE,Y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