rebrand better-clawd and ship initial npm-ready release

This commit is contained in:
x1xhlol
2026-04-01 16:51:18 +02:00
Unverified
parent 420d4155ec
commit 407fa14d6f
109 changed files with 4155 additions and 1690 deletions

View File

@@ -3,18 +3,23 @@
*/
import axios from 'axios'
import {
PRODUCT_ISSUES_URL,
PRODUCT_SLUG,
} from '../constants/product.js'
import { OAUTH_BETA_HEADER } from '../constants/oauth.js'
import {
getAnthropicApiKey,
getClaudeAIOAuthTokens,
getOpenAIApiKey,
getOpenRouterApiKey,
handleOAuth401Error,
isClaudeAISubscriber,
} from './auth.js'
import { getAPIProvider } from './model/providers.js'
import { getClaudeCodeUserAgent } from './userAgent.js'
import { getWorkload } from './workloadContext.js'
// WARNING: We rely on `claude-cli` in the user agent for log filtering.
// Please do NOT change this without making sure that logging also gets updated!
export function getUserAgent(): string {
const agentSdkVersion = process.env.CLAUDE_AGENT_SDK_VERSION
? `, agent-sdk/${process.env.CLAUDE_AGENT_SDK_VERSION}`
@@ -31,7 +36,7 @@ export function getUserAgent(): string {
// so the read picks up the same setWorkload() value as getAttributionHeader.
const workload = getWorkload()
const workloadSuffix = workload ? `, workload/${workload}` : ''
return `claude-cli/${MACRO.VERSION} (${process.env.USER_TYPE}, ${process.env.CLAUDE_CODE_ENTRYPOINT ?? 'cli'}${agentSdkVersion}${clientApp}${workloadSuffix})`
return `${PRODUCT_SLUG}-cli/${MACRO.VERSION} (${process.env.USER_TYPE}, ${process.env.CLAUDE_CODE_ENTRYPOINT ?? 'cli'}${agentSdkVersion}${clientApp}${workloadSuffix})`
}
export function getMCPUserAgent(): string {
@@ -46,15 +51,12 @@ export function getMCPUserAgent(): string {
parts.push(`client-app/${process.env.CLAUDE_AGENT_SDK_CLIENT_APP}`)
}
const suffix = parts.length > 0 ? ` (${parts.join(', ')})` : ''
return `claude-code/${MACRO.VERSION}${suffix}`
return `${PRODUCT_SLUG}/${MACRO.VERSION}${suffix}`
}
// User-Agent for WebFetch requests to arbitrary sites. `Claude-User` is
// Anthropic's publicly documented agent for user-initiated fetches (what site
// operators match in robots.txt); the claude-code suffix lets them distinguish
// local CLI traffic from claude.ai server-side fetches.
// User-Agent for WebFetch requests to arbitrary sites.
export function getWebFetchUserAgent(): string {
return `Claude-User (${getClaudeCodeUserAgent()}; +https://support.anthropic.com/)`
return `Better-Clawd-User (${getClaudeCodeUserAgent()}; +${PRODUCT_ISSUES_URL})`
}
export type AuthHeaders = {
@@ -67,6 +69,37 @@ export type AuthHeaders = {
* Returns either OAuth headers for Max/Pro users or API key headers for regular users
*/
export function getAuthHeaders(): AuthHeaders {
const provider = getAPIProvider()
if (provider === 'openai') {
const apiKey = getOpenAIApiKey()
if (!apiKey) {
return {
headers: {},
error: 'No OpenAI API key available',
}
}
return {
headers: {
Authorization: `Bearer ${apiKey}`,
},
}
}
if (provider === 'openrouter') {
const apiKey = getOpenRouterApiKey()
if (!apiKey) {
return {
headers: {},
error: 'No OpenRouter API key available',
}
}
return {
headers: {
Authorization: `Bearer ${apiKey}`,
},
}
}
if (isClaudeAISubscriber()) {
const oauthTokens = getClaudeAIOAuthTokens()
if (!oauthTokens?.accessToken) {