Documentation
¶
Index ¶
- Variables
- func AppendToFile(filename string, content string)
- func ApplyPatchInputFromProxyArguments(rawArguments string, action string) string
- func BuildApplyPatchInput(ops []ApplyPatchOperation) string
- func ConvertChatResponseToResponses(chatResponseBody []byte, model string, fallbackReasoningToMessage bool) ([]byte, error)
- func ConvertChatResponseToResponsesWithContext(chatResponseBody []byte, model string, fallbackReasoningToMessage bool, ...) ([]byte, error)
- func ConvertOpenAIChatToResponses(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, ...) ([]string, error)
- func ConvertOpenAIChatToResponsesWithContext(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, ...) ([]string, error)
- func ConvertResponsesToChatRequest(modelName string, inputRawJSON []byte, stream bool) ([]byte, error)
- func DoResponsesResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (*model.Usage, *model.ErrorWithStatusCode)
- func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatusCode
- func GetStreamCompletedBody(param interface{}, originalRequestRawJSON []byte) []byte
- func GetStreamUsage(param interface{}) (promptTokens, completionTokens, totalTokens, cachedTokens int)
- func RenderTerminalStreamReadErrorEvent(c *gin.Context, err error)
- func StreamResponsesHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, string, *model.Usage)
- type Adaptor
- func (a *Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)
- func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error)
- func (a *Adaptor) DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)
- func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (*model.Usage, *model.ErrorWithStatusCode)
- func (a *Adaptor) GetChannelName() string
- func (a *Adaptor) GetModelList() []string
- func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error)
- func (a *Adaptor) Init(meta *meta.Meta)
- func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error
- type ApplyPatchHunk
- type ApplyPatchLineOp
- type ApplyPatchOperation
- type CodexCustomToolKind
- type CodexCustomToolSpec
- type CodexFunctionToolSpec
- type CodexToolContext
- func (ctx CodexToolContext) IsBuiltinTool(name, kind string) bool
- func (ctx CodexToolContext) IsCustomToolProxy(upstreamName string) bool
- func (ctx CodexToolContext) OpenAINameForFunctionTool(upstreamName string) (name string, namespace string)
- func (ctx CodexToolContext) OriginalCustomToolName(upstreamName string) string
- type SSEEvent
Constants ¶
This section is empty.
Variables ¶
var ModelList = []string{
"gpt-5.5",
"gpt-5.4-mini",
"gpt-5.4",
}
Functions ¶
func AppendToFile ¶
appendToFile 追加内容到文件(文件不存在则创建)
func ApplyPatchInputFromProxyArguments ¶
ApplyPatchInputFromProxyArguments reconstructs apply_patch grammar input from proxy arguments.
func BuildApplyPatchInput ¶
func BuildApplyPatchInput(ops []ApplyPatchOperation) string
BuildApplyPatchInput builds raw apply_patch grammar input from operations.
func ConvertChatResponseToResponses ¶
func ConvertChatResponseToResponses(chatResponseBody []byte, model string, fallbackReasoningToMessage bool) ([]byte, error)
ConvertChatResponseToResponses 把上游 chat 响应转回 codex Responses 格式。 保留为 3 参数旧入口,等价于 ConvertChatResponseToResponsesWithContext(..., nil)。
func ConvertChatResponseToResponsesWithContext ¶
func ConvertChatResponseToResponsesWithContext(chatResponseBody []byte, model string, fallbackReasoningToMessage bool, originalRequestRawJSON []byte) ([]byte, error)
ConvertChatResponseToResponsesWithContext 把上游 Chat 非流式响应转回 Responses Response 对象。 P0-1:chatResponseBody 非法 JSON 返回 invalid_source_json(绝不原样透传 chat.completion)。 P0-3:顶层对象与 message/reasoning item 输出 Responses §4/§5 全部必填字段,output_text part 恒含 annotations/logprobs;回显原请求可回显字段。 当 originalRequestRawJSON 非 nil 时,从原始 Responses 请求里解析 CodexToolContext, 用于在 tool_calls 还原时识别 namespace 字段与 custom_tool_call 类型。
func ConvertOpenAIChatToResponses ¶
func ConvertOpenAIChatToResponses(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, fallbackReasoningToMessage bool) ([]string, error)
ConvertOpenAIChatToResponses 将 OpenAI Chat Completions SSE 转换为 Responses SSE 事件。 旧 5 参数入口,作为 thin wrapper 调用 ConvertOpenAIChatToResponsesWithContext 并传 nil 作为 originalRequestRawJSON,保持对历史调用方的 100% 行为兼容。 originalRequestRawJSON: 原始的 Responses API 请求 JSON(用于回显字段) requestRawJSON: 转换后的 Chat Completions 请求 JSON rawJSON: OpenAI Chat Completions SSE 行 param: 状态指针(*any,在多次调用间保持状态) 返回的 error 为协议转换显式边界(契约 §1.3):畸形 chunk / 畸形工具调用等,调用方必须消费, 经错误终态链处理,禁止 swallow。
func ConvertOpenAIChatToResponsesWithContext ¶
func ConvertOpenAIChatToResponsesWithContext(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, fallbackReasoningToMessage bool) ([]string, error)
ConvertOpenAIChatToResponsesWithContext 将 OpenAI Chat Completions SSE 转换为 Responses SSE 事件。 当 originalRequestRawJSON 非 nil 时,从原始 Responses 请求里解析 CodexToolContext, 用于在 tool_calls 流式 output_item.added 事件中携带正确的 name/namespace/custom_tool_call 类型。 当 originalRequestRawJSON 为 nil 时,退化到无 CodexCtx 行为(name 保留原上游名,无 namespace 字段)。 #5 修复:流式 output_item.added 事件必须在 first chunk 时就带 name/namespace/input,与 #4 非流式对称。 originalRequestRawJSON: 原始的 Responses API 请求 JSON requestRawJSON: 转换后的 Chat Completions 请求 JSON rawJSON: OpenAI Chat Completions SSE 行 param: 状态指针(*any,在多次调用间保持状态) fallbackReasoningToMessage: 兜底无 content 仅 reasoning 时复制文本为 message
返回 ([]string, error):error 为协议转换显式边界(契约 §1.3)——非 [DONE] chunk 未通过 JSON validity/object 校验返回 invalid_stream_event;工具 delta 缺 id/name 未成功 added 却在 close 时返回 malformed_tool_call;两者都已产出生成唯一 response.failed 终态并置 TerminalEvent,后续 [DONE] 不得合成 completed。调用方(forwarder)必须消费该 error。
func ConvertResponsesToChatRequest ¶
func ConvertResponsesToChatRequest(modelName string, inputRawJSON []byte, stream bool) ([]byte, error)
ConvertResponsesToChatRequest 把 Responses 请求转换为 Chat Completions 请求。 能力性不可映射的字段/item(responses 专有顶层字段、未知/上下文 item、仅 encrypted_content 的 reasoning item、role×part 矩阵违规、DN-6 白名单外内置工具、DN-7 ultrafast 档位等)一律丢弃 对应字段/item 并记 warn 日志后继续转换,不再 unsupported_mapping 400 —— 目标是让 responses→chat 转换完成,确实转不了的字段接受丢弃。 仅三类结构性/不可执行情形维持错误:非法 JSON(invalid_source_json)、source shape 非法 (invalid_source_shape)、转换后 messages 为空(无法执行,仍 unsupported_mapping 400)。
func DoResponsesResponse ¶
func ErrorWrapper ¶
func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatusCode
func GetStreamCompletedBody ¶
func GetStreamUsage ¶
func GetStreamUsage(param interface{}) (promptTokens, completionTokens, totalTokens, cachedTokens int)
Types ¶
type Adaptor ¶
func (*Adaptor) ConvertImageRequest ¶
func (a *Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)
func (*Adaptor) ConvertRequest ¶
func (*Adaptor) DoResponse ¶
func (*Adaptor) GetChannelName ¶
func (*Adaptor) GetModelList ¶
type ApplyPatchHunk ¶
type ApplyPatchHunk struct {
Context string
Lines []ApplyPatchLineOp
}
ApplyPatchHunk represents a patch hunk.
type ApplyPatchLineOp ¶
ApplyPatchLineOp represents a patch line operation.
type ApplyPatchOperation ¶
type ApplyPatchOperation struct {
Type string
Path string
MoveTo string
Content string
Hunks []ApplyPatchHunk
}
ApplyPatchOperation represents a single patch operation.
type CodexCustomToolKind ¶
type CodexCustomToolKind string
CodexCustomToolKind classifies the type of Codex custom tool.
const ( CodexCustomToolRaw CodexCustomToolKind = "raw" CodexCustomToolApplyPatch CodexCustomToolKind = "apply_patch" CodexCustomToolExec CodexCustomToolKind = "exec" CodexCustomToolBuiltIn CodexCustomToolKind = "builtin" )
type CodexCustomToolSpec ¶
type CodexCustomToolSpec struct {
OpenAIName string
GrammarDefinition string
Kind CodexCustomToolKind
ProxyAction string // "", add_file, delete_file, update_file, replace_file, batch
}
CodexCustomToolSpec describes a single Codex custom tool and its upstream proxy.
type CodexFunctionToolSpec ¶
CodexFunctionToolSpec describes a normal function tool for namespace tracking.
type CodexToolContext ¶
type CodexToolContext struct {
CustomTools map[string]CodexCustomToolSpec
FunctionTools map[string]CodexFunctionToolSpec
BuiltinTools map[string]string
HasCustomTools bool
HasNamespaceTools bool
}
CodexToolContext holds parsed information about all tools in a request.
func BuildCodexToolContextFromRaw ¶
func BuildCodexToolContextFromRaw(tools []interface{}) CodexToolContext
BuildCodexToolContextFromRaw builds Codex tool context from raw tools slice.
func (CodexToolContext) IsBuiltinTool ¶
func (ctx CodexToolContext) IsBuiltinTool(name, kind string) bool
IsBuiltinTool returns whether the given upstream name is a registered built-in tool of the requested kind.
func (CodexToolContext) IsCustomToolProxy ¶
func (ctx CodexToolContext) IsCustomToolProxy(upstreamName string) bool
IsCustomToolProxy returns whether the given upstream name is a Codex custom tool proxy.
func (CodexToolContext) OpenAINameForFunctionTool ¶
func (ctx CodexToolContext) OpenAINameForFunctionTool(upstreamName string) (name string, namespace string)
OpenAINameForFunctionTool returns the unflattened (name, namespace) for an upstream flat function name.
func (CodexToolContext) OriginalCustomToolName ¶
func (ctx CodexToolContext) OriginalCustomToolName(upstreamName string) string
OriginalCustomToolName returns the original Codex tool name for a proxy name.