Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
36b817d0
"frontend/src/vscode:/vscode.git/clone" did not exist on "1854050df3be90d2556ee3bff220cb1705d04bcd"
Commit
36b817d0
authored
Jan 10, 2026
by
cyhhao
Browse files
Align OAuth transform with OpenCode instructions
parent
eb06006d
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/openai_codex_transform.go
View file @
36b817d0
...
@@ -13,11 +13,12 @@ import (
...
@@ -13,11 +13,12 @@ import (
)
)
const
(
const
(
codexReleaseAPIURL
=
"https://api.github.com/repos/openai/codex/releases/latest"
codexReleaseAPIURL
=
"https://api.github.com/repos/openai/codex/releases/latest"
codexReleaseHTMLURL
=
"https://github.com/openai/codex/releases/latest"
codexReleaseHTMLURL
=
"https://github.com/openai/codex/releases/latest"
codexPromptURLFmt
=
"https://raw.githubusercontent.com/openai/codex/%s/codex-rs/core/%s"
codexPromptURLFmt
=
"https://raw.githubusercontent.com/openai/codex/%s/codex-rs/core/%s"
opencodeCodexURL
=
"https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/opencode/src/session/prompt/codex.txt"
opencodeCodexURL
=
"https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/opencode/src/session/prompt/codex.txt"
codexCacheTTL
=
15
*
time
.
Minute
opencodeCodexHeaderURL
=
"https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/opencode/src/session/prompt/codex_header.txt"
codexCacheTTL
=
15
*
time
.
Minute
)
)
type
codexModelFamily
string
type
codexModelFamily
string
...
@@ -177,7 +178,7 @@ func applyCodexOAuthTransform(reqBody map[string]any) codexTransformResult {
...
@@ -177,7 +178,7 @@ func applyCodexOAuthTransform(reqBody map[string]any) codexTransformResult {
result
.
PromptCacheKey
=
strings
.
TrimSpace
(
v
)
result
.
PromptCacheKey
=
strings
.
TrimSpace
(
v
)
}
}
instructions
:=
strings
.
TrimSpace
(
get
CodexInstructions
(
normalizedModel
))
instructions
:=
strings
.
TrimSpace
(
get
OpenCodeCodexHeader
(
))
existingInstructions
,
_
:=
reqBody
[
"instructions"
]
.
(
string
)
existingInstructions
,
_
:=
reqBody
[
"instructions"
]
.
(
string
)
existingInstructions
=
strings
.
TrimSpace
(
existingInstructions
)
existingInstructions
=
strings
.
TrimSpace
(
existingInstructions
)
...
@@ -408,13 +409,13 @@ func parseReleaseTagFromHTML(html string) (string, error) {
...
@@ -408,13 +409,13 @@ func parseReleaseTagFromHTML(html string) (string, error) {
return
""
,
fmt
.
Errorf
(
"release tag not found"
)
return
""
,
fmt
.
Errorf
(
"release tag not found"
)
}
}
func
getOpenCodeC
odex
Prompt
()
string
{
func
getOpenCodeC
ached
Prompt
(
url
,
cacheFileName
,
metaFileName
string
)
string
{
cacheDir
:=
codexCachePath
(
""
)
cacheDir
:=
codexCachePath
(
""
)
if
cacheDir
==
""
{
if
cacheDir
==
""
{
return
""
return
""
}
}
cacheFile
:=
filepath
.
Join
(
cacheDir
,
"opencode-codex.txt"
)
cacheFile
:=
filepath
.
Join
(
cacheDir
,
cacheFileName
)
metaFile
:=
filepath
.
Join
(
cacheDir
,
"opencode-codex-meta.json"
)
metaFile
:=
filepath
.
Join
(
cacheDir
,
metaFileName
)
var
cachedContent
string
var
cachedContent
string
if
content
,
ok
:=
readFile
(
cacheFile
);
ok
{
if
content
,
ok
:=
readFile
(
cacheFile
);
ok
{
...
@@ -428,7 +429,7 @@ func getOpenCodeCodexPrompt() string {
...
@@ -428,7 +429,7 @@ func getOpenCodeCodexPrompt() string {
}
}
}
}
content
,
etag
,
status
,
err
:=
fetchWithETag
(
opencodeCodexURL
,
meta
.
ETag
)
content
,
etag
,
status
,
err
:=
fetchWithETag
(
url
,
meta
.
ETag
)
if
err
==
nil
&&
status
==
http
.
StatusNotModified
&&
cachedContent
!=
""
{
if
err
==
nil
&&
status
==
http
.
StatusNotModified
&&
cachedContent
!=
""
{
return
cachedContent
return
cachedContent
}
}
...
@@ -446,6 +447,14 @@ func getOpenCodeCodexPrompt() string {
...
@@ -446,6 +447,14 @@ func getOpenCodeCodexPrompt() string {
return
cachedContent
return
cachedContent
}
}
func
getOpenCodeCodexPrompt
()
string
{
return
getOpenCodeCachedPrompt
(
opencodeCodexURL
,
"opencode-codex.txt"
,
"opencode-codex-meta.json"
)
}
func
getOpenCodeCodexHeader
()
string
{
return
getOpenCodeCachedPrompt
(
opencodeCodexHeaderURL
,
"opencode-codex-header.txt"
,
"opencode-codex-header-meta.json"
)
}
func
filterCodexInput
(
input
[]
any
)
[]
any
{
func
filterCodexInput
(
input
[]
any
)
[]
any
{
filtered
:=
make
([]
any
,
0
,
len
(
input
))
filtered
:=
make
([]
any
,
0
,
len
(
input
))
for
_
,
item
:=
range
input
{
for
_
,
item
:=
range
input
{
...
...
backend/internal/service/openai_gateway_service.go
View file @
36b817d0
...
@@ -580,7 +580,7 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
...
@@ -580,7 +580,7 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
}
}
// Build upstream request
// Build upstream request
upstreamReq
,
err
:=
s
.
buildUpstreamRequest
(
ctx
,
c
,
account
,
body
,
token
,
reqStream
,
promptCacheKey
)
upstreamReq
,
err
:=
s
.
buildUpstreamRequest
(
ctx
,
c
,
account
,
body
,
token
,
reqStream
,
promptCacheKey
,
isCodexCLI
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -641,7 +641,7 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
...
@@ -641,7 +641,7 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
},
nil
},
nil
}
}
func
(
s
*
OpenAIGatewayService
)
buildUpstreamRequest
(
ctx
context
.
Context
,
c
*
gin
.
Context
,
account
*
Account
,
body
[]
byte
,
token
string
,
isStream
bool
,
promptCacheKey
string
)
(
*
http
.
Request
,
error
)
{
func
(
s
*
OpenAIGatewayService
)
buildUpstreamRequest
(
ctx
context
.
Context
,
c
*
gin
.
Context
,
account
*
Account
,
body
[]
byte
,
token
string
,
isStream
bool
,
promptCacheKey
string
,
isCodexCLI
bool
)
(
*
http
.
Request
,
error
)
{
// Determine target URL based on account type
// Determine target URL based on account type
var
targetURL
string
var
targetURL
string
switch
account
.
Type
{
switch
account
.
Type
{
...
@@ -694,7 +694,11 @@ func (s *OpenAIGatewayService) buildUpstreamRequest(ctx context.Context, c *gin.
...
@@ -694,7 +694,11 @@ func (s *OpenAIGatewayService) buildUpstreamRequest(ctx context.Context, c *gin.
}
}
if
account
.
Type
==
AccountTypeOAuth
{
if
account
.
Type
==
AccountTypeOAuth
{
req
.
Header
.
Set
(
"OpenAI-Beta"
,
"responses=experimental"
)
req
.
Header
.
Set
(
"OpenAI-Beta"
,
"responses=experimental"
)
req
.
Header
.
Set
(
"originator"
,
"codex_cli_rs"
)
if
isCodexCLI
{
req
.
Header
.
Set
(
"originator"
,
"codex_cli_rs"
)
}
else
{
req
.
Header
.
Set
(
"originator"
,
"opencode"
)
}
req
.
Header
.
Set
(
"accept"
,
"text/event-stream"
)
req
.
Header
.
Set
(
"accept"
,
"text/event-stream"
)
if
promptCacheKey
!=
""
{
if
promptCacheKey
!=
""
{
req
.
Header
.
Set
(
"conversation_id"
,
promptCacheKey
)
req
.
Header
.
Set
(
"conversation_id"
,
promptCacheKey
)
...
...
backend/internal/service/openai_gateway_service_test.go
View file @
36b817d0
...
@@ -220,7 +220,7 @@ func TestOpenAIInvalidBaseURLWhenAllowlistDisabled(t *testing.T) {
...
@@ -220,7 +220,7 @@ func TestOpenAIInvalidBaseURLWhenAllowlistDisabled(t *testing.T) {
Credentials
:
map
[
string
]
any
{
"base_url"
:
"://invalid-url"
},
Credentials
:
map
[
string
]
any
{
"base_url"
:
"://invalid-url"
},
}
}
_
,
err
:=
svc
.
buildUpstreamRequest
(
c
.
Request
.
Context
(),
c
,
account
,
[]
byte
(
"{}"
),
"token"
,
false
,
""
)
_
,
err
:=
svc
.
buildUpstreamRequest
(
c
.
Request
.
Context
(),
c
,
account
,
[]
byte
(
"{}"
),
"token"
,
false
,
""
,
false
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"expected error for invalid base_url when allowlist disabled"
)
t
.
Fatalf
(
"expected error for invalid base_url when allowlist disabled"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment