mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
refactor(console): call inference through a service binding (#55103)
This commit is contained in:
committed by
GitHub
Unverified
parent
4ffede4941
commit
c1615b1db9
+6
-1
@@ -48,7 +48,6 @@ new sst.cloudflare.x.SolidStart("Console", {
|
||||
SALESFORCE_CLIENT_ID,
|
||||
SALESFORCE_CLIENT_SECRET,
|
||||
SALESFORCE_INSTANCE_URL,
|
||||
new sst.Secret("CLOUDFLARE_ACCESS_CLIENT_ID"),
|
||||
],
|
||||
environment: {
|
||||
//VITE_DOCS_URL: web.url.apply((url) => url!),
|
||||
@@ -64,6 +63,12 @@ new sst.cloudflare.x.SolidStart("Console", {
|
||||
...(flags ?? []),
|
||||
"global_fetch_strictly_public",
|
||||
])
|
||||
// Same-zone fetch to inference re-enters as a public request and loses the client IP.
|
||||
if (migrationDomain)
|
||||
args.bindings = $resolve(args.bindings).apply((bindings) => [
|
||||
...(bindings ?? []),
|
||||
{ type: "service", name: "INFERENCE", service: `opencode-inference-${$app.stage}` },
|
||||
])
|
||||
args.tailConsumers = [{ service: logProcessor.nodes.worker.scriptName }]
|
||||
},
|
||||
},
|
||||
|
||||
@@ -41,6 +41,7 @@ export async function proxyInference(request: Request) {
|
||||
"x-zen",
|
||||
"x-zen-model",
|
||||
"x-zen-ip",
|
||||
"x-real-ip",
|
||||
"cf-access-client-id",
|
||||
"cf-access-client-secret",
|
||||
"host",
|
||||
@@ -51,13 +52,14 @@ export async function proxyInference(request: Request) {
|
||||
const anonymous = !key || key === "public"
|
||||
if (anonymous) for (const name of ["authorization", "x-api-key", "x-goog-api-key"]) forwarded.headers.delete(name)
|
||||
if (!anonymous) forwarded.headers.set("authorization", `Bearer ${key}`)
|
||||
forwarded.headers.set("CF-Access-Client-Id", Resource.CLOUDFLARE_ACCESS_CLIENT_ID.value)
|
||||
const ip = request.headers.get("cf-connecting-ip")
|
||||
if (ip) forwarded.headers.set("x-zen-ip", ip)
|
||||
if (ip) forwarded.headers.set("x-real-ip", ip)
|
||||
const requestID = request.headers.get("x-opencode-request-id") ?? request.headers.get("x-opencode-request")
|
||||
if (requestID) forwarded.headers.set("x-opencode-request-id", requestID)
|
||||
|
||||
const response = await fetch(forwarded, { redirect: "manual" }).catch(() => undefined)
|
||||
const response = await (Resource.INFERENCE as { fetch: typeof fetch })
|
||||
.fetch(forwarded, { redirect: "manual" })
|
||||
.catch(() => undefined)
|
||||
if (!response)
|
||||
return Response.json(
|
||||
{ error: { type: "api_error", message: "Inference routing is unavailable. Please retry later." } },
|
||||
|
||||
Reference in New Issue
Block a user