Fix Freebuff: correct User-Agent, metadata fields, session body, preset aliases
- User-Agent: ai-sdk/openai-compatible/1.0.25/codebuff (matches official SDK)
- metadata: freebuff_instance_id (not codebuff_instance_id) + client_id field
- Session POST: empty body {} (not {model: ...})
- Add Freebuff/FreeBuff preset aliases for backward compat
This commit is contained in:
@@ -400,6 +400,24 @@ PROVIDER_PRESETS = {
|
|||||||
"moonshotai/kimi-k2.6", "minimax/minimax-m2.7",
|
"moonshotai/kimi-k2.6", "minimax/minimax-m2.7",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
"Freebuff (Free DeepSeek/Kimi)": {
|
||||||
|
"backend_type": "codebuff",
|
||||||
|
"base_url": "https://www.codebuff.com",
|
||||||
|
"oauth_provider": "codebuff",
|
||||||
|
"models": [
|
||||||
|
"deepseek/deepseek-v4-pro", "deepseek/deepseek-v4-flash",
|
||||||
|
"moonshotai/kimi-k2.6", "minimax/minimax-m2.7",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"FreeBuff": {
|
||||||
|
"backend_type": "codebuff",
|
||||||
|
"base_url": "https://www.codebuff.com",
|
||||||
|
"oauth_provider": "codebuff",
|
||||||
|
"models": [
|
||||||
|
"deepseek/deepseek-v4-pro", "deepseek/deepseek-v4-flash",
|
||||||
|
"moonshotai/kimi-k2.6", "minimax/minimax-m2.7",
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def safe_name(name):
|
def safe_name(name):
|
||||||
|
|||||||
@@ -331,11 +331,11 @@ def _codebuff_get_session(token, model):
|
|||||||
return sc["instance_id"]
|
return sc["instance_id"]
|
||||||
try:
|
try:
|
||||||
url = f"{_CODEBUFF_API_URL}/api/v1/freebuff/session"
|
url = f"{_CODEBUFF_API_URL}/api/v1/freebuff/session"
|
||||||
body = json.dumps({"model": model}).encode()
|
body = json.dumps({}).encode()
|
||||||
req = urllib.request.Request(url, data=body, headers={
|
req = urllib.request.Request(url, data=body, headers={
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {token}",
|
"Authorization": f"Bearer {token}",
|
||||||
"User-Agent": "codex-launcher/3.10.5",
|
"User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff",
|
||||||
"x-codebuff-model": model,
|
"x-codebuff-model": model,
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
@@ -383,7 +383,7 @@ def _codebuff_start_run(token, agent_id):
|
|||||||
req = urllib.request.Request(url, data=body, headers={
|
req = urllib.request.Request(url, data=body, headers={
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {token}",
|
"Authorization": f"Bearer {token}",
|
||||||
"User-Agent": "codex-launcher/3.10.5",
|
"User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff",
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
resp = urllib.request.urlopen(req, timeout=15)
|
resp = urllib.request.urlopen(req, timeout=15)
|
||||||
@@ -416,7 +416,7 @@ def _codebuff_finish_run(token, run_id, status="completed"):
|
|||||||
req = urllib.request.Request(url, data=body, headers={
|
req = urllib.request.Request(url, data=body, headers={
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {token}",
|
"Authorization": f"Bearer {token}",
|
||||||
"User-Agent": "codex-launcher/3.10.5",
|
"User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff",
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen(req, timeout=10)
|
urllib.request.urlopen(req, timeout=10)
|
||||||
@@ -5324,9 +5324,10 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
metadata = {
|
metadata = {
|
||||||
"run_id": run_id,
|
"run_id": run_id,
|
||||||
"cost_mode": "free",
|
"cost_mode": "free",
|
||||||
|
"client_id": secrets.token_hex(7)[:13],
|
||||||
}
|
}
|
||||||
if instance_id:
|
if instance_id:
|
||||||
metadata["codebuff_instance_id"] = instance_id
|
metadata["freebuff_instance_id"] = instance_id
|
||||||
|
|
||||||
chat_body = {
|
chat_body = {
|
||||||
"model": model,
|
"model": model,
|
||||||
@@ -5348,7 +5349,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {token}",
|
"Authorization": f"Bearer {token}",
|
||||||
"User-Agent": "codex-launcher/3.10.5",
|
"User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff",
|
||||||
"x-codebuff-model": model,
|
"x-codebuff-model": model,
|
||||||
}
|
}
|
||||||
if instance_id:
|
if instance_id:
|
||||||
@@ -5496,9 +5497,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
instance_id = _codebuff_get_session(token, model)
|
instance_id = _codebuff_get_session(token, model)
|
||||||
messages = _cb_input_to_messages(input_data, instructions)
|
messages = _cb_input_to_messages(input_data, instructions)
|
||||||
_codebuff_hard_disable_reasoning(messages)
|
_codebuff_hard_disable_reasoning(messages)
|
||||||
metadata = {"run_id": run_id, "cost_mode": "free"}
|
metadata = {"run_id": run_id, "cost_mode": "free", "client_id": secrets.token_hex(7)[:13]}
|
||||||
if instance_id:
|
if instance_id:
|
||||||
metadata["codebuff_instance_id"] = instance_id
|
metadata["freebuff_instance_id"] = instance_id
|
||||||
chat_body = {
|
chat_body = {
|
||||||
"model": model, "messages": messages, "stream": stream,
|
"model": model, "messages": messages, "stream": stream,
|
||||||
"max_tokens": max(body.get("max_output_tokens", 0), 64000),
|
"max_tokens": max(body.get("max_output_tokens", 0), 64000),
|
||||||
@@ -5514,7 +5515,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
if body.get("tool_choice"):
|
if body.get("tool_choice"):
|
||||||
chat_body["tool_choice"] = body["tool_choice"]
|
chat_body["tool_choice"] = body["tool_choice"]
|
||||||
target = f"{_CODEBUFF_API_URL}/api/v1/chat/completions"
|
target = f"{_CODEBUFF_API_URL}/api/v1/chat/completions"
|
||||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "codex-launcher/3.10.5", "x-codebuff-model": model}
|
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "ai-sdk/openai-compatible/1.0.25/codebuff", "x-codebuff-model": model}
|
||||||
if instance_id:
|
if instance_id:
|
||||||
headers["x-codebuff-instance-id"] = instance_id
|
headers["x-codebuff-instance-id"] = instance_id
|
||||||
print(f"[codebuff] retry POST {target} model={model} stream={stream} run={run_id} (thinking disabled via DeepSeek native)", file=sys.stderr)
|
print(f"[codebuff] retry POST {target} model={model} stream={stream} run={run_id} (thinking disabled via DeepSeek native)", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user