codex

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModelList = []string{
	"gpt-4o",
	"gpt-4o-mini",
	"gpt-4-turbo",
	"gpt-4",
	"gpt-3.5-turbo",
	"o1",
	"o1-mini",
}

Functions

func AppendToFile

func AppendToFile(filename string, content string)

appendToFile 追加内容到文件(文件不存在则创建)

func ApplyPatchInputFromProxyArguments

func ApplyPatchInputFromProxyArguments(rawArguments string, action string) string

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

ConvertChatResponseToResponses 把上游 chat 响应转回 codex Responses 格式。 保留为 3 参数旧入口,等价于 ConvertChatResponseToResponsesWithContext(..., nil)。

func ConvertChatResponseToResponsesWithContext

func ConvertChatResponseToResponsesWithContext(chatResponseBody []byte, model string, fallbackReasoningToMessage bool, originalRequestRawJSON []byte) []byte

ConvertChatResponseToResponsesWithContext 把上游 chat 响应转回 codex Responses 格式。 当 originalRequestRawJSON 非 nil 时,从原始 Responses 请求里解析 CodexToolContext, 用于在 tool_calls 还原时识别 namespace 字段与 custom_tool_call 类型。 当 originalRequestRawJSON 为 nil 时,退化到旧 3 参数行为(保持 100% 向后兼容)。

func ConvertOpenAIChatToResponses

func ConvertOpenAIChatToResponses(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, fallbackReasoningToMessage bool) []string

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,在多次调用间保持状态)

func ConvertOpenAIChatToResponsesWithContext

func ConvertOpenAIChatToResponsesWithContext(originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, fallbackReasoningToMessage bool) []string

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

func ConvertResponsesToChatRequest

func ConvertResponsesToChatRequest(modelName string, inputRawJSON []byte, stream bool) []byte

func DoResponsesResponse

func DoResponsesResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (*model.Usage, *model.ErrorWithStatusCode)

func ErrorWrapper

func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatusCode

func GetStreamCompletedBody

func GetStreamCompletedBody(param interface{}, originalRequestRawJSON []byte) []byte

func GetStreamUsage

func GetStreamUsage(param interface{}) (promptTokens, completionTokens, totalTokens, cachedTokens int)

func RenderTerminalStreamReadErrorEvent

func RenderTerminalStreamReadErrorEvent(c *gin.Context, err error)

func StreamResponsesHandler

func StreamResponsesHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, string, *model.Usage)

Types

type Adaptor

type Adaptor struct {
	OpenAiImpl adaptor.Adaptor
	// contains filtered or unexported fields
}

func (*Adaptor) ConvertImageRequest

func (a *Adaptor) ConvertImageRequest(request *model.ImageRequest) (any, error)

func (*Adaptor) ConvertRequest

func (a *Adaptor) ConvertRequest(c *gin.Context, relayMode int, request *model.GeneralOpenAIRequest) (any, error)

func (*Adaptor) DoRequest

func (a *Adaptor) DoRequest(c *gin.Context, meta *meta.Meta, requestBody io.Reader) (*http.Response, error)

func (*Adaptor) DoResponse

func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, meta *meta.Meta) (*model.Usage, *model.ErrorWithStatusCode)

func (*Adaptor) GetChannelName

func (a *Adaptor) GetChannelName() string

func (*Adaptor) GetModelList

func (a *Adaptor) GetModelList() []string

func (*Adaptor) GetRequestURL

func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error)

func (*Adaptor) Init

func (a *Adaptor) Init(meta *meta.Meta)

func (*Adaptor) SetupRequestHeader

func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error

type ApplyPatchHunk

type ApplyPatchHunk struct {
	Context string
	Lines   []ApplyPatchLineOp
}

ApplyPatchHunk represents a patch hunk.

type ApplyPatchLineOp

type ApplyPatchLineOp struct {
	Op   string
	Text string
}

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

type CodexFunctionToolSpec struct {
	Namespace string
	Name      string
}

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.

type SSEEvent

type SSEEvent struct {
	Event   string
	Data    string
	ID      string
	RawSize int
	Done    bool
}

func ReadSSEEvent

func ReadSSEEvent(r *bufio.Reader, maxBytes int) (SSEEvent, error)

func (SSEEvent) String

func (e SSEEvent) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL