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
ca42a458
"backend/vscode:/vscode.git/clone" did not exist on "dbb248df52862dd10b85a66f6b346d496b35fd53"
Commit
ca42a458
authored
Mar 14, 2026
by
ius
Browse files
fix: stop rewriting native responses input ids
parent
a4a026e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/openai_codex_transform.go
View file @
ca42a458
...
...
@@ -339,8 +339,9 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
}
typ
,
_
:=
m
[
"type"
]
.
(
string
)
// 修复 OpenAI 上游的最新校验:"Expected an ID that begins with 'fc'"
fixIDPrefix
:=
func
(
id
string
)
string
{
// 仅修正真正的 tool/function call 标识,避免误改普通 message/reasoning id;
// 若 item_reference 指向 legacy call_* 标识,则仅修正该引用本身。
fixCallIDPrefix
:=
func
(
id
string
)
string
{
if
id
==
""
||
strings
.
HasPrefix
(
id
,
"fc"
)
{
return
id
}
...
...
@@ -358,8 +359,8 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
for
key
,
value
:=
range
m
{
newItem
[
key
]
=
value
}
if
id
,
ok
:=
newItem
[
"id"
]
.
(
string
);
ok
&&
id
!=
""
{
newItem
[
"id"
]
=
fixIDPrefix
(
id
)
if
id
,
ok
:=
newItem
[
"id"
]
.
(
string
);
ok
&&
strings
.
HasPrefix
(
id
,
"call_"
)
{
newItem
[
"id"
]
=
fix
Call
IDPrefix
(
id
)
}
filtered
=
append
(
filtered
,
newItem
)
continue
...
...
@@ -390,7 +391,7 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
}
if
callID
!=
""
{
fixedCallID
:=
fixIDPrefix
(
callID
)
fixedCallID
:=
fix
Call
IDPrefix
(
callID
)
if
fixedCallID
!=
callID
{
ensureCopy
()
newItem
[
"call_id"
]
=
fixedCallID
...
...
@@ -404,14 +405,6 @@ func filterCodexInput(input []any, preserveReferences bool) []any {
if
!
isCodexToolCallItemType
(
typ
)
{
delete
(
newItem
,
"call_id"
)
}
}
else
{
if
id
,
ok
:=
newItem
[
"id"
]
.
(
string
);
ok
&&
id
!=
""
{
fixedID
:=
fixIDPrefix
(
id
)
if
fixedID
!=
id
{
ensureCopy
()
newItem
[
"id"
]
=
fixedID
}
}
}
filtered
=
append
(
filtered
,
newItem
)
...
...
backend/internal/service/openai_codex_transform_test.go
View file @
ca42a458
...
...
@@ -33,12 +33,63 @@ func TestApplyCodexOAuthTransform_ToolContinuationPreservesInput(t *testing.T) {
first
,
ok
:=
input
[
0
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"item_reference"
,
first
[
"type"
])
require
.
Equal
(
t
,
"
fc_
ref1"
,
first
[
"id"
])
require
.
Equal
(
t
,
"ref1"
,
first
[
"id"
])
// 校验 input[1] 为 map,确保后续字段断言安全。
second
,
ok
:=
input
[
1
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"fc_o1"
,
second
[
"id"
])
require
.
Equal
(
t
,
"o1"
,
second
[
"id"
])
require
.
Equal
(
t
,
"fc1"
,
second
[
"call_id"
])
}
func
TestApplyCodexOAuthTransform_ToolContinuationPreservesNativeMessageAndReasoningIDs
(
t
*
testing
.
T
)
{
reqBody
:=
map
[
string
]
any
{
"model"
:
"gpt-5.2"
,
"input"
:
[]
any
{
map
[
string
]
any
{
"type"
:
"message"
,
"id"
:
"msg_0"
,
"role"
:
"user"
,
"content"
:
"hi"
},
map
[
string
]
any
{
"type"
:
"item_reference"
,
"id"
:
"rs_123"
},
},
"tool_choice"
:
"auto"
,
}
applyCodexOAuthTransform
(
reqBody
,
false
,
false
)
input
,
ok
:=
reqBody
[
"input"
]
.
([]
any
)
require
.
True
(
t
,
ok
)
require
.
Len
(
t
,
input
,
2
)
first
,
ok
:=
input
[
0
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"msg_0"
,
first
[
"id"
])
second
,
ok
:=
input
[
1
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"rs_123"
,
second
[
"id"
])
}
func
TestApplyCodexOAuthTransform_ToolContinuationNormalizesToolReferenceIDsOnly
(
t
*
testing
.
T
)
{
reqBody
:=
map
[
string
]
any
{
"model"
:
"gpt-5.2"
,
"input"
:
[]
any
{
map
[
string
]
any
{
"type"
:
"item_reference"
,
"id"
:
"call_1"
},
map
[
string
]
any
{
"type"
:
"function_call_output"
,
"call_id"
:
"call_1"
,
"output"
:
"ok"
},
},
"tool_choice"
:
"auto"
,
}
applyCodexOAuthTransform
(
reqBody
,
false
,
false
)
input
,
ok
:=
reqBody
[
"input"
]
.
([]
any
)
require
.
True
(
t
,
ok
)
require
.
Len
(
t
,
input
,
2
)
first
,
ok
:=
input
[
0
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"fc1"
,
first
[
"id"
])
second
,
ok
:=
input
[
1
]
.
(
map
[
string
]
any
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
"fc1"
,
second
[
"call_id"
])
}
func
TestApplyCodexOAuthTransform_ExplicitStoreFalsePreserved
(
t
*
testing
.
T
)
{
...
...
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