gateway, gui: Codex's thread descriptions go to a model picked in Settings, apart from its titles (#1198, congee949)
Codex asks its own model, through its ChatGPT sign-in, for each thread's description (thread_description), even while the conversation runs on magpie's models. Settings › General gets "Codex thread descriptions" beside "Codex thread titles". It defaults to Codex's own, which sends the request as Codex sent it, or it can name one of magpie's models or a routing group. The answer is wrapped as description-only JSON. The titles setting is untouched. Usage and Routing show these requests under their own Description purpose. The setting is kept across unrelated Settings saves. There is no Off yet, because Codex's handling of an empty description hasn't been checked. This is a first slice of #742. Squashed from the PR and merged onto current main. Conflicts resolved: - codex_backend.go: the description branch comes after the title branch, ahead of main's subagent pick. - gateway.go: main's CC Switch #1301 comment above the compaction block is kept; the PR had shortened it. - app.js: the gateway-mode list of hidden rows takes the new row. - i18n.js and settings_keep_test.go: both sides kept. - purposes.js: regenerated with go generate ./internal/usage. Run on the merged tree: - gofmt -l is clean. - go vet passes on darwin, linux -tags nogui and windows; the builds on all three succeed. - go test -tags nogui passes for ./internal/gateway, ./internal/gui, ./internal/settings and ./internal/usage. - GUI, chromium and webkit: codex-titles, gateway-mode, purpose-filter, routing-purpose-state, gui-de, gui-ja, gui-zh-tw, i18n-keys, settings-general/-groups/-sections/-search and click-scroll: 118/118. Broken by hand: with the description branch removed from codexBackend and handle, TestCodexDescriptionsSetting, TestCodexDescriptionFallbackOnMagpie and TestNoDescription fail. Not tried: a real Codex thread_description request, and whether Codex's sidebar takes the answer.
This commit is contained in:
+2
-1
@@ -1887,7 +1887,8 @@ expose it publicly without gateway-key authentication.
|
||||
Such a page is in **gateway mode**: it shows Providers, Gateway, Routing,
|
||||
Usage, Plugins and Settings, with no Agents, Sessions or Library tab, and
|
||||
Settings leaves out what is written into this machine's agents (provider in
|
||||
model names, Codex subagents, long conversations, Codex thread titles) and
|
||||
model names, Codex subagents, long conversations, Codex thread titles,
|
||||
Codex thread descriptions) and
|
||||
the desktop's alerts and tray. `magpie web` is in it by itself when it finds
|
||||
no agents on its machine, as in the container, and with
|
||||
`magpie web --gateway`. *Settings › General › Gateway mode* picks Automatic,
|
||||
|
||||
@@ -28,6 +28,22 @@ served by a plugin are in [Provider and plugin ownership](provider-plugins.md).
|
||||
| Prompt | What each request's prompt held, part by part: the agent's system prompt, tool definitions (an MCP server's tools as one item), instruction files and skills, files its tools read, their other output, and the conversation. `inspectPrompt` reads it from the body as the agent sent it, before translation; `calibrated` scales the estimate to the prompt the vendor counted and sets the window of the model that answered. The route keeps names and sizes only, never the text, so the routing history on disk holds none. For the card's text (masaka on Discord), the trace keeps the last `promptBodies` (10) request bodies in memory only (at most 32 MiB each, 64 MiB together), masked as the vendor got them; for a model let have it unmasked, the masked copy is kept all the same. `PromptText` reads a part's items and their text from that body again (`prompt_text.go`), served to the GUI as `/api/context/text`; once a body is dropped, or magpie quits, its text is gone. It goes on the trace as `Route.Prompt`, with `Route.Conv` naming a conversation that has no session id. The GUI's `/api/context` scores each agent from it (`internal/gui/context.go`). | [`prompt.go`](../../internal/gateway/prompt.go) |
|
||||
| Vertex AI | A [Google Vertex AI provider](providers-accounts.md#responsibilities-and-sources-of-truth) speaks Gemini alone. A request goes to `<base>/publishers/google/models/<model>:streamGenerateContent?alt=sse` (`provider.VertexPath`, `upstreamPath`), the model named as the user's upstream name for it says (`UpstreamNameIn`, which the usage log's endpoint names too), with no `model` or `stream` field in its body (`passthrough`, `forwardOnce`, `geminiRequest`). A Gemini client's request is relayed as it came, its own `thinkingConfig`, `safetySettings` and the rest kept: streamed there, asked whole to `:generateContent` (`provider.VertexWholePath`), which answers one JSON body (Factory's rule of translating a whole request, as its route only streams, isn't Vertex AI's). Every other API's is translated (`buildFor`, `buildVertex`) and its stream read by `codeAssistDecoder`, which gives thought parts as reasoning, never as the answer's text. Effort: `vertexEffort` fits it to the model's levels, reasoning turned off going as `minimal` fitted the same way, and holds a model whose levels aren't known to `low`…`high`. `vertexThinking` sends Gemini 3 a `thinkingLevel` (`includeThoughts` false with reasoning off) and 2.5 a `thinkingBudget` in the model's range (`vertexBudgets`): turned off, the budget that stops its thinking, or Pro's least, as Pro can't stop. Thought signatures are every Gemini path's (#1445): a call's signature reaches the client in its id (`signedID`) and goes back on the call it came on, while a call with none in a step Vertex AI signed goes without; a step with nothing to give back has every call sent `skip_thought_signature_validator`. A 400 `Invalid thought signature.` is asked again with every call sent so (`withoutSignatures`), for that request only. A 400 refusing `minimal` (`geminiRefusedLevel`) is asked again at the model's lowest other level (`onEffort`), and `markUnfit(offRefused)` keeps that level until magpie restarts. Both retries are the translated path's. Vertex AI's own Google Search grounding isn't used: `searchHosts` names only `generativelanguage.googleapis.com` for Gemini, so magpie searches for it (`search.go`). | [`vertex.go`](../../internal/gateway/vertex.go), [`gateway.go`](../../internal/gateway/gateway.go), [`codeassist.go`](../../internal/gateway/codeassist.go), [`gemini.go`](../../internal/gateway/gemini.go), [`gemini_signature.go`](../../internal/gateway/gemini_signature.go), [`search.go`](../../internal/gateway/search.go) |
|
||||
|
||||
## Codex titles and descriptions
|
||||
|
||||
Codex's title and description requests are independent hidden turns. The
|
||||
settings `CodexTitles` and `CodexDescriptions` select their models separately;
|
||||
an empty setting preserves the requested model. On a Magpie model, both
|
||||
paths wrap plain model text in the object Codex requested. Titles use
|
||||
`{"title": ...}`; descriptions use `{"description": ...}` with nonempty text
|
||||
and no invented maximum length. Title Off mode does not disable descriptions.
|
||||
|
||||
`codexTitlesTo`, `codexDescriptionsTo`, `codexTitle` and `codexDescription` in
|
||||
[`codex_titles.go`](../../internal/gateway/codex_titles.go) own this selection
|
||||
and response wrapping. Both the Responses API and Codex backend entrypoints
|
||||
use it. Usage and Routing retain the original purpose; unusable description
|
||||
answers are recorded as description failures. These helpers do not decrypt
|
||||
foreign sealed history or repair ChatGPT's response protection.
|
||||
|
||||
## Runtime path
|
||||
|
||||
1. `handle(proto)` reads the body and the model (`requestBody`, `requestModel`), then calls `serveAgent`. Every route that reads an agent's body (each API, count_tokens, Gemini's, embeddings, images, videos, System One, the Codex backend path) reads it through `readBoundedRequestBody` in [`request_bounds.go`](../../internal/gateway/request_bounds.go). It decodes a `Content-Encoding` of `gzip` or `zstd` (`decodedBody`; Codex sends zstd to a custom provider's `/v1/responses` too, #1223) and drops the header, so the provider is sent plain JSON, with one exception: a ChatGPT account's turn (POST `CodexBase`/responses, from the accounts loop in `forwardOnce` or relayed by `codexUpstreamOn`) is compressed again with zstd, as Codex's own client sends it (`provider.CodexCompressed`; openai/codex `responses_request_compression`). It is compressed once the body is final, and again on each try. `/responses/compact`, an API key's requests and every other provider stay plain. Sent plain, a 1.1 MB text-only turn was answered 503 (ylorn on X). The plain body is what magpie keeps and shows, and `codexDropped` judges a reset by the bytes that went on the wire. The size limit (`defaultBodyLimit`, 512 MB) holds for the decoded bytes (413), and any other encoding is refused 415. It was 128 MB until a long Codex session that had read many images went past it decoded, its inline screenshots resent each turn, and got the 413 on all five of Codex's retries (#1422, `TestImageHeavyCodexTurnIsRead`). magpie's own 413 says it is magpie's gateway limit, with the size, and that the provider was not asked (`overLimit`); `writeError` adds to any 413 it isn't holding that this is a byte limit, not the model's context, and to `/compact` or start a new conversation (`TestOverLimitSaysWhoseAndWhatToDo`). `keyLimited` reads a limited key's compressed body the same way, so its reservation is the decoded size. `serveAgent` runs the [middleware](gateway-middleware.md) chain, then `serve`.
|
||||
|
||||
@@ -92,6 +92,10 @@ func (s *Server) codexBackend(w http.ResponseWriter, r *http.Request) {
|
||||
s.codexTitle(w, r, body, to)
|
||||
return
|
||||
}
|
||||
if to := codexDescriptionsTo(r.Header, body, false); to != "" {
|
||||
s.codexDescription(w, r, body, to)
|
||||
return
|
||||
}
|
||||
// a subagent on one of Codex's own models, put on the model
|
||||
// set for Codex's subagents, a ChatGPT account's in magpie;
|
||||
// the request on the model asked for when it can't be, the
|
||||
|
||||
@@ -40,6 +40,25 @@ func codexTitlesTo(h http.Header, body []byte, ours bool) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// codexDescriptionsTo is where a request Codex makes for a thread's
|
||||
// description goes. "" leaves the request as Codex sent it; a model's id
|
||||
// writes it. A description is not a title: Codex asks for {"description"}
|
||||
// alone, which the title wrapper cannot answer.
|
||||
func codexDescriptionsTo(h http.Header, body []byte, ours bool) string {
|
||||
if !isDescriptionKind(requestCallKind(h, requestSessionMetadata(h, body))) {
|
||||
return ""
|
||||
}
|
||||
if to := settings.Load().CodexDescriptions; to != "" {
|
||||
return to
|
||||
}
|
||||
// Codex on a magpie model gets no schema upstream (#743), so an empty
|
||||
// setting still wraps the model it asked for, as titles do.
|
||||
if m := modelOf(body); m != "" && (ours || strings.Contains(m, "/")) {
|
||||
return m
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// titleCheckKey holds, in a request's context, what serve asks of the
|
||||
// reply it relayed before it records the call: the reason it fails its
|
||||
// caller although the vendor answered, or "".
|
||||
@@ -119,6 +138,90 @@ func (s *Server) codexTitle(w http.ResponseWriter, r *http.Request, body []byte,
|
||||
writeTitleReply(w, id, out, res.Usage)
|
||||
}
|
||||
|
||||
// codexDescription answers a thread_description request with the model
|
||||
// CodexDescriptions names. The model's text comes back as the
|
||||
// {"description": ...} its schema asks for; a reply without one fails as a
|
||||
// description, not as a title.
|
||||
func (s *Server) codexDescription(w http.ResponseWriter, r *http.Request, body []byte, to string) {
|
||||
body, _ = codexInput(body, true)
|
||||
rec := &recorder{header: http.Header{}, status: 200}
|
||||
check := func(reply string) string {
|
||||
if res, err := compactReply([]byte(reply)); err == nil && descriptionJSON(messageText(res)) == "" {
|
||||
return noDescription(messageText(res))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), titleCheckKey{}, check)
|
||||
ctx = magpieChose(ctx)
|
||||
s.serve(rec, r.WithContext(ctx), provider.Responses, withModel(body, to))
|
||||
if rec.status >= 400 {
|
||||
for k, vs := range rec.header {
|
||||
w.Header()[k] = vs
|
||||
}
|
||||
w.WriteHeader(rec.status)
|
||||
w.Write(rec.body.Bytes())
|
||||
return
|
||||
}
|
||||
res, err := compactReply(rec.body.Bytes())
|
||||
if err != nil {
|
||||
writeError(w, provider.Responses, 502, "description: "+err.Error())
|
||||
return
|
||||
}
|
||||
id := res.ID
|
||||
if id == "" {
|
||||
id = fmt.Sprintf("resp_magpie_%d", time.Now().UnixNano())
|
||||
}
|
||||
var out []any
|
||||
if d := descriptionJSON(messageText(res)); d != "" {
|
||||
out = append(out, map[string]any{"type": "message", "id": "msg_" + strings.TrimPrefix(id, "resp_"), "role": "assistant", "status": "completed",
|
||||
"content": []any{map[string]any{"type": "output_text", "text": d, "annotations": []any{}}}})
|
||||
}
|
||||
writeTitleReply(w, id, out, res.Usage)
|
||||
}
|
||||
|
||||
func noDescription(said string) string {
|
||||
said = strings.Join(strings.Fields(said), " ")
|
||||
if said == "" {
|
||||
return "description: the model answered with no text, so Codex got no description"
|
||||
}
|
||||
if r := []rune(said); len(r) > 80 {
|
||||
said = string(r[:80]) + "…"
|
||||
}
|
||||
return "description: no description in the model's answer, so Codex got none: " + said
|
||||
}
|
||||
|
||||
// descriptionJSON returns the model's text as the nonempty description
|
||||
// object Codex asks for. An unusable answer returns an empty string.
|
||||
func descriptionJSON(said string) string {
|
||||
t := strings.TrimSpace(said)
|
||||
if rest, ok := strings.CutPrefix(t, "<think>"); ok {
|
||||
if _, after, ok := strings.Cut(rest, "</think>"); ok {
|
||||
t = strings.TrimSpace(after)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(t, "```") {
|
||||
t = strings.TrimPrefix(t, "```")
|
||||
if i := strings.IndexByte(t, '\n'); i >= 0 && !strings.Contains(t[:i], "{") {
|
||||
t = t[i+1:]
|
||||
}
|
||||
t = strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(t), "```"))
|
||||
}
|
||||
if strings.HasPrefix(t, "{") {
|
||||
fields := map[string]any{}
|
||||
if json.NewDecoder(bytes.NewReader([]byte(t))).Decode(&fields) == nil {
|
||||
if v, ok := fields["description"].(string); ok {
|
||||
t = v
|
||||
}
|
||||
}
|
||||
}
|
||||
t = strings.TrimSpace(strings.Trim(strings.TrimSpace(t), "\"`'"))
|
||||
if t == "" || strings.HasPrefix(t, "{") {
|
||||
return ""
|
||||
}
|
||||
b, _ := json.Marshal(map[string]string{"description": t})
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// messageText is the text of a reply's messages, its reasoning left out.
|
||||
func messageText(res compactResult) string {
|
||||
var said strings.Builder
|
||||
|
||||
@@ -286,3 +286,129 @@ func TestTitleJSONFillsTheSchema(t *testing.T) {
|
||||
t.Errorf("no schema: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func codexDescriptionRequest(t *testing.T, s *Server) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
// ChatGPT.app's thread_description schema: description is required and has
|
||||
// a minimum length, but no maximum.
|
||||
body := `{"model":"gpt-6-luna","stream":true,"input":[{"type":"message","role":"user","content":[{"type":"input_text","text":"Describe the thread"}]}],` +
|
||||
`"text":{"format":{"type":"json_schema","strict":true,"schema":{"type":"object","properties":{"description":{"type":"string","minLength":1}},"required":["description"],"additionalProperties":false}}}}`
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("POST", CodexPath+"/responses", strings.NewReader(body))
|
||||
req.Header.Set("Authorization", "Bearer chatgpt-token")
|
||||
req.Header.Set("session_id", "description-thread")
|
||||
req.Header.Set("x-codex-turn-metadata", `{"thread_source":"thread_description"}`)
|
||||
s.Handler().ServeHTTP(rec, req)
|
||||
return rec
|
||||
}
|
||||
|
||||
func TestCodexDescriptionsSetting(t *testing.T) {
|
||||
f := &fake{t: t, reply: sse(
|
||||
`data: {"id":"c1","choices":[{"index":0,"delta":{"content":"Reviewed the routing change and verified it"}}]}`,
|
||||
`data: {"id":"c1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":30,"completion_tokens":8}}`,
|
||||
`data: [DONE]`)}
|
||||
setup(t, provider.Chat, f)
|
||||
chatgptCalls := 0
|
||||
chatgpt(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
io.ReadAll(r.Body)
|
||||
chatgptCalls++
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
io.WriteString(w, sse(`data: {"type":"response.completed","response":{"id":"r1","output":[{"type":"message","role":"assistant","content":[{"type":"output_text","text":"{\"description\":\"From ChatGPT\"}"}]}],"usage":{"input_tokens":9,"output_tokens":2}}}`))
|
||||
})
|
||||
save := func(v string) {
|
||||
t.Helper()
|
||||
st := settings.Load()
|
||||
st.CodexDescriptions = v
|
||||
if err := settings.Save(st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
s := New()
|
||||
rec := codexDescriptionRequest(t, s)
|
||||
if text, _ := outputText(t, rec.Body.String()); chatgptCalls != 1 || f.calls != 0 || text != `{"description":"From ChatGPT"}` {
|
||||
t.Fatalf("default: chatgpt %d, magpie model %d, %q", chatgptCalls, f.calls, text)
|
||||
}
|
||||
|
||||
save("fake/m1")
|
||||
rec = codexDescriptionRequest(t, s)
|
||||
if text, _ := outputText(t, rec.Body.String()); rec.Code != 200 || text != `{"description":"Reviewed the routing change and verified it"}` || f.calls != 1 || chatgptCalls != 1 {
|
||||
t.Fatalf("routed: %d %q, magpie model %d, chatgpt %d", rec.Code, rec.Body.String(), f.calls, chatgptCalls)
|
||||
}
|
||||
var sent struct {
|
||||
Model string `json:"model"`
|
||||
}
|
||||
json.Unmarshal(f.got, &sent)
|
||||
if sent.Model != "m1" {
|
||||
t.Errorf("the magpie model was asked for %q", sent.Model)
|
||||
}
|
||||
var kinds []string
|
||||
for _, u := range usage.Load(time.Time{}) {
|
||||
kinds = append(kinds, u.Provider+":"+u.Kind)
|
||||
}
|
||||
want := "openai:thread_description fake:thread_description"
|
||||
if got := strings.Join(kinds, " "); got != want {
|
||||
t.Errorf("ledger %s\nwant %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodexDescriptionFallbackOnMagpie(t *testing.T) {
|
||||
for _, path := range []string{"/v1/responses", "/backend-api/codex/responses"} {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
f := &fake{t: t, reply: sse(
|
||||
`data: {"id":"c1","choices":[{"index":0,"delta":{"content":"Plain description"}}]}`,
|
||||
`data: {"id":"c1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":2}}`,
|
||||
`data: [DONE]`)}
|
||||
setup(t, provider.Chat, f)
|
||||
s := New()
|
||||
body := `{"model":"fake/m1","stream":true,"input":"Describe the thread",` +
|
||||
`"text":{"format":{"type":"json_schema","schema":{"type":"object","properties":{"description":{"type":"string","minLength":1}},"required":["description"]}}}}`
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("POST", path, strings.NewReader(body))
|
||||
req.Header.Set("x-codex-turn-metadata", `{"thread_source":"thread_description"}`)
|
||||
s.Handler().ServeHTTP(rec, req)
|
||||
if text, _ := outputText(t, rec.Body.String()); rec.Code != 200 || text != `{"description":"Plain description"}` || f.calls != 1 {
|
||||
t.Fatalf("fallback: %d %q, calls %d", rec.Code, rec.Body.String(), f.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoDescription(t *testing.T) {
|
||||
f := &fake{t: t, reply: sse(
|
||||
`data: {"id":"c1","choices":[{"index":0,"delta":{"content":" "}}]}`,
|
||||
`data: {"id":"c1","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":10,"completion_tokens":1}}`,
|
||||
`data: [DONE]`)}
|
||||
setup(t, provider.Chat, f)
|
||||
st := settings.Load()
|
||||
st.CodexDescriptions = "fake/m1"
|
||||
if err := settings.Save(st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := New()
|
||||
rec := codexDescriptionRequest(t, s)
|
||||
text, n := outputText(t, rec.Body.String())
|
||||
if rec.Code != 200 || n != 0 || text != "" {
|
||||
t.Fatalf("empty reply: %d %q, %d items", rec.Code, rec.Body.String(), n)
|
||||
}
|
||||
var last usage.Record
|
||||
for _, u := range usage.Load(time.Time{}) {
|
||||
last = u
|
||||
}
|
||||
if last.Kind != "thread_description" || !strings.HasPrefix(last.Error, "description: ") || !last.Failed() {
|
||||
t.Fatalf("unusable reply was not flagged: %+v", last)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescriptionJSON(t *testing.T) {
|
||||
for in, want := range map[string]string{
|
||||
"A short note": `{"description":"A short note"}`,
|
||||
`{"description":"From JSON"}`: `{"description":"From JSON"}`,
|
||||
"```json\n{\"description\":\"Fenced\"}\n```": `{"description":"Fenced"}`,
|
||||
"": "",
|
||||
} {
|
||||
if got := descriptionJSON(in); got != want {
|
||||
t.Errorf("descriptionJSON(%q) = %s, want %s", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1186,6 +1186,10 @@ func (s *Server) handle(from provider.Protocol) http.HandlerFunc {
|
||||
s.codexTitle(w, r, body, to)
|
||||
return
|
||||
}
|
||||
if to := codexDescriptionsTo(r.Header, body, true); to != "" {
|
||||
s.codexDescription(w, r, body, to)
|
||||
return
|
||||
}
|
||||
// Codex compacts remotely, a compaction_trigger here, on a
|
||||
// provider table named "OpenAI" (CC Switch's relay tables,
|
||||
// which magpie points here, #1301): the summary is magpie's to
|
||||
|
||||
@@ -11,6 +11,10 @@ func isTitleKind(kind string) bool {
|
||||
return kind == "thread_title" || kind == "thread_title_reconsideration" || kind == "title_generation"
|
||||
}
|
||||
|
||||
func isDescriptionKind(kind string) bool {
|
||||
return kind == "thread_description"
|
||||
}
|
||||
|
||||
// Codex projects turn metadata into headers, but its canonical transport is
|
||||
// client_metadata in the Responses body. Read only identity fields; never keep
|
||||
// prompts or the rest of the metadata in the trace.
|
||||
|
||||
+25
-1
@@ -1145,7 +1145,8 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
// and the Get started card put away, from the card itself
|
||||
in.GuideHidden = cur.GuideHidden
|
||||
|
||||
in.CodexTitles = cur.CodexTitles // set on its own (codex-titles below)
|
||||
in.CodexTitles = cur.CodexTitles // set on its own (codex-titles below)
|
||||
in.CodexDescriptions = cur.CodexDescriptions // set on its own (codex-descriptions below)
|
||||
// and so is the model Codex's auto-review runs on (codex-auto-review)
|
||||
in.CodexAutoReview = cur.CodexAutoReview
|
||||
// and the model Codex's subagents are put on, set in Codex's row
|
||||
@@ -1397,6 +1398,29 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
// where Codex's request for a thread's description goes: "" as Codex
|
||||
// sends it, or a model's id. It is separate from the title setting.
|
||||
mux.HandleFunc("POST /api/settings/codex-descriptions", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in struct{ Model string }
|
||||
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
v := strings.TrimSpace(in.Model)
|
||||
if v != "" {
|
||||
if _, _, ok := provider.Resolve(v); !ok {
|
||||
fail(rw, fmt.Errorf("no model %s to write Codex's descriptions", v))
|
||||
return
|
||||
}
|
||||
}
|
||||
s := settings.Load()
|
||||
s.CodexDescriptions = v
|
||||
if err := settings.Save(s); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
// where Codex's requests for a thread's title go (#705): "" as Codex
|
||||
// sends them, "off", or a model's id
|
||||
// the models turned off for every request through magpie (#1867), each
|
||||
|
||||
@@ -20931,7 +20931,7 @@ function renderSettings() {
|
||||
// gateway mode leaves out what is written into this computer's agents'
|
||||
// files, and the alerts its desktop would show
|
||||
for (const r of [$("#plainNamesSegs").parentElement, $("#codexAgentsV1Segs").parentElement, $("#fullContextSegs").parentElement,
|
||||
$("#codexTitlesRow"), $("#codexAutoReviewRow"), $("#usageAlertRow"), $("#balanceAlertRow"), $("#resetReminderRow"), $("#turnDoneRow")]) r.hidden = gatewayMode;
|
||||
$("#codexTitlesRow"), $("#codexDescriptionsRow"), $("#codexAutoReviewRow"), $("#usageAlertRow"), $("#balanceAlertRow"), $("#resetReminderRow"), $("#turnDoneRow")]) r.hidden = gatewayMode;
|
||||
// the parts' tabs, one gone whose rows are all hidden here
|
||||
setSetTab(setTab);
|
||||
}
|
||||
@@ -21533,6 +21533,7 @@ function renderTrayUsage(s, keep) {
|
||||
compactRow.append(compactSegs, compactNum);
|
||||
$("#fullContextSegs").replaceChildren(compactRow);
|
||||
renderCodexTitles(s);
|
||||
renderCodexDescriptions(s);
|
||||
renderCodexAutoReview(s);
|
||||
renderCodexMemories();
|
||||
const rate = s.fx?.rate;
|
||||
@@ -21941,6 +21942,33 @@ function renderAlerts(s, keep) {
|
||||
$("#turnDoneSegs").replaceChildren(segs(turnOpts, String(d), (v) => savePrefs({ ...keep, turnDoneAlert: Number(v) })));
|
||||
}
|
||||
|
||||
// renderCodexDescriptions picks the model for descriptions independently
|
||||
// of titles; an empty setting preserves Codex's requested model.
|
||||
function renderCodexDescriptions(s) {
|
||||
const models = s.titleModels || [];
|
||||
const named = (id) => {
|
||||
const m = models.find((x) => x.id === id);
|
||||
return m ? `${m.name || m.id} · ${m.providerName}` : id;
|
||||
};
|
||||
const v = s.codexDescriptions || "";
|
||||
$("#codexDescriptionsSub").textContent = v ? t("Codex’s description requests go to this model, not to its ChatGPT sign-in; the Usage and Routing views still show them as descriptions")
|
||||
: t("Codex asks its own model for each thread’s description through its ChatGPT sign-in, even while the conversation is on magpie’s models");
|
||||
const b = el("button", "rt-cond on");
|
||||
b.type = "button";
|
||||
b.setAttribute("aria-label", t("Codex thread descriptions"));
|
||||
if (v) b.append(icon(models.find((x) => x.id === v)?.icon || "generic"), el("span", "", named(v)));
|
||||
else b.append(icon("openai"), el("span", "", t("Codex’s own (ChatGPT)")));
|
||||
const opt = (x) => ({ value: x.id, label: x.name || x.id, note: x.providerName, icon: x.icon, group: x.provider ? x.providerName : ROUTING_GROUPS, ref: x.id });
|
||||
b.onclick = (ev) => openPicker({ id: "", name: "", fields: [] }, { key: "codexDescriptions", label: "model", value: v, options: [
|
||||
{ value: "", label: t("Codex’s own (ChatGPT)"), note: t("as Codex sends them"), icon: "openai", reset: true },
|
||||
...models.map(opt)],
|
||||
onPick: (id) => {
|
||||
if (id === v) return;
|
||||
writingPrefs(api("settings/codex-descriptions", { model: id })).then((ns) => { prefs = ns; renderSettings(); }).catch((e) => { status(t(e.message), "err"); renderSettings(); });
|
||||
} }, b, ev);
|
||||
$("#codexDescriptionsPick").replaceChildren(b);
|
||||
}
|
||||
|
||||
// renderCodexTitles: where Codex's requests for a thread's title go (#705)
|
||||
// — as Codex sends them, to its own model through its ChatGPT sign-in; off,
|
||||
// answered by magpie with no title; or to a model of magpie's — set on its
|
||||
|
||||
@@ -877,6 +877,9 @@ const I18N = {
|
||||
"Codex and Claude Code compact at 272K or the size typed; a full window makes turns slower and costlier": "Codex 和 Claude Code 在 272K(或这里填的大小)时压缩;用完整窗口则每轮更慢更贵",
|
||||
"Compact at {n}": "{n} 时压缩",
|
||||
"Codex thread titles": "Codex 会话标题",
|
||||
"Codex thread descriptions": "Codex 会话描述",
|
||||
"Codex asks its own model for each thread’s description through its ChatGPT sign-in, even while the conversation is on magpie’s models": "Codex 经 ChatGPT 登录用自带模型为每个会话生成描述,即使对话用的是 magpie 的模型",
|
||||
"Codex’s description requests go to this model, not to its ChatGPT sign-in; the Usage and Routing views still show them as descriptions": "Codex 的描述请求改由此模型生成,不经 ChatGPT 登录;用量和路由页仍记为描述请求",
|
||||
"Codex’s own (ChatGPT)": "Codex 自带(ChatGPT)",
|
||||
"as Codex sends them": "按 Codex 原样发送",
|
||||
"Codex auto-review model": "Codex 自动审批模型",
|
||||
@@ -3507,6 +3510,7 @@ const I18N = {
|
||||
"Background memory task": "后台记忆整理",
|
||||
"Codex is organizing memories from earlier chats in the background. This can continue after a chat finishes.": "Codex 正在后台整理历史聊天中的记忆,回答结束后也可能继续运行。",
|
||||
"Title": "标题",
|
||||
"Description": "描述",
|
||||
"Title requests were automatically matched using the prompt and the applied chat title.": "标题请求根据提问内容和实际应用的聊天标题自动关联。",
|
||||
"Subagent": "子代理",
|
||||
"This subagent task is encrypted. Only ChatGPT accounts can read it; other providers (such as Claude) are excluded regardless of quota.": "子代理任务已加密,只能使用 ChatGPT 账号;其他供应商(如 Claude)不参与选择,无论剩余多少额度。",
|
||||
@@ -4563,6 +4567,10 @@ const I18N = {
|
||||
"~/.dsh/settings.yaml sets its own DeepSeek endpoint or key, which dsh puts over magpie's; clear it in dsh's Models page to go through magpie.": "~/.dsh/settings.yaml 设置了自己的 DeepSeek 地址或 Key,dsh 会优先用它而不是 magpie 的;请在 dsh 的 Models 页面清除它,才能走 magpie。",
|
||||
},
|
||||
"zh-TW": {
|
||||
"Codex thread descriptions": "Codex 對話描述",
|
||||
"Codex asks its own model for each thread’s description through its ChatGPT sign-in, even while the conversation is on magpie’s models": "Codex 透過 ChatGPT 登入向自己的模型請求每個對話的描述,即使對話使用 magpie 的模型",
|
||||
"Codex’s description requests go to this model, not to its ChatGPT sign-in; the Usage and Routing views still show them as descriptions": "Codex 的描述請求交由此模型處理,不經 ChatGPT 登入;用量和路由頁仍將其顯示為描述",
|
||||
"Description": "描述",
|
||||
"Get started": "快速上手",
|
||||
"{n} of {m} done": "已完成 {n}/{m}",
|
||||
"Hide Get started": "隱藏快速上手",
|
||||
@@ -9962,6 +9970,9 @@ const I18N = {
|
||||
"Codex and Claude Code compact at 272K or the size typed; a full window makes turns slower and costlier": "Codex と Claude Code は 272K(または入力したサイズ)で圧縮します。ウィンドウ全体では各ターンが遅く高くなります",
|
||||
"Compact at {n}": "{n} で圧縮",
|
||||
"Codex thread titles": "Codex のスレッドタイトル",
|
||||
"Codex thread descriptions": "Codex のスレッド説明",
|
||||
"Codex asks its own model for each thread’s description through its ChatGPT sign-in, even while the conversation is on magpie’s models": "会話が magpie のモデルで行われていても、Codex は ChatGPT のサインインを通じて自身のモデルに各スレッドの説明を生成させます",
|
||||
"Codex’s description requests go to this model, not to its ChatGPT sign-in; the Usage and Routing views still show them as descriptions": "Codex の説明リクエストは ChatGPT のサインインではなくこのモデルに送られます。使用量とルーティングの画面では引き続き説明として表示されます",
|
||||
"Codex’s own (ChatGPT)": "Codex 自身(ChatGPT)",
|
||||
"as Codex sends them": "Codex が送るまま",
|
||||
"Codex auto-review model": "Codex 自動レビューのモデル",
|
||||
@@ -12588,6 +12599,7 @@ const I18N = {
|
||||
"Background memory task": "バックグラウンドのメモリタスク",
|
||||
"Codex is organizing memories from earlier chats in the background. This can continue after a chat finishes.": "Codex がバックグラウンドで以前のチャットからメモリを整理しています。チャット終了後も続くことがあります。",
|
||||
"Title": "タイトル",
|
||||
"Description": "説明",
|
||||
"Title requests were automatically matched using the prompt and the applied chat title.": "タイトルのリクエストは、プロンプトと適用されたチャットタイトルから自動で関連付けられました。",
|
||||
"Subagent": "サブエージェント",
|
||||
"This subagent task is encrypted. Only ChatGPT accounts can read it; other providers (such as Claude) are excluded regardless of quota.": "このサブエージェントのタスクは暗号化されています。読めるのは ChatGPT アカウントだけで、他のプロバイダ(Claude など)はクォータに関係なく除外されます。",
|
||||
@@ -14508,6 +14520,9 @@ const I18N = {
|
||||
"Codex and Claude Code compact at 272K or the size typed; a full window makes turns slower and costlier": "Codex und Claude Code komprimieren bei 272K oder der Größe hier; volles Fenster: langsamer, teurer",
|
||||
"Compact at {n}": "Bei {n} komprimieren",
|
||||
"Codex thread titles": "Codex-Thread-Titel",
|
||||
"Codex thread descriptions": "Codex-Thread-Beschreibungen",
|
||||
"Codex asks its own model for each thread’s description through its ChatGPT sign-in, even while the conversation is on magpie’s models": "Codex fragt über seine ChatGPT-Anmeldung sein eigenes Modell nach der Beschreibung jedes Threads, auch wenn die Unterhaltung auf magpie-Modellen läuft",
|
||||
"Codex’s description requests go to this model, not to its ChatGPT sign-in; the Usage and Routing views still show them as descriptions": "Beschreibungsanfragen von Codex gehen an dieses Modell statt über die ChatGPT-Anmeldung; die Ansichten „Nutzung“ und „Weiterleitung“ zeigen sie weiterhin als Beschreibungen",
|
||||
"Codex’s own (ChatGPT)": "Eigene von Codex (ChatGPT)",
|
||||
"as Codex sends them": "wie Codex sie sendet",
|
||||
"Codex auto-review model": "Modell für Codex’ Auto-Review",
|
||||
@@ -17134,6 +17149,7 @@ const I18N = {
|
||||
"Background memory task": "Memory-Aufgabe im Hintergrund",
|
||||
"Codex is organizing memories from earlier chats in the background. This can continue after a chat finishes.": "Codex ordnet im Hintergrund Erinnerungen aus früheren Chats. Das kann nach dem Ende eines Chats weiterlaufen.",
|
||||
"Title": "Titel",
|
||||
"Description": "Beschreibung",
|
||||
"Title requests were automatically matched using the prompt and the applied chat title.": "Titelanfragen wurden anhand des Prompts und des übernommenen Chat-Titels automatisch zugeordnet.",
|
||||
"Subagent": "Subagent",
|
||||
"This subagent task is encrypted. Only ChatGPT accounts can read it; other providers (such as Claude) are excluded regardless of quota.": "Diese Subagenten-Aufgabe ist verschlüsselt. Nur ChatGPT-Konten können sie lesen; andere Anbieter (etwa Claude) sind unabhängig vom Kontingent ausgeschlossen.",
|
||||
|
||||
@@ -334,6 +334,10 @@
|
||||
<div class="who"><div class="name" data-t>Codex thread titles</div></div>
|
||||
<div class="val" id="codexTitlesPick"></div>
|
||||
</div>
|
||||
<div class="row pref" id="codexDescriptionsRow">
|
||||
<div class="who"><div class="name" data-t>Codex thread descriptions</div><div class="sub" id="codexDescriptionsSub"></div></div>
|
||||
<div class="val" id="codexDescriptionsPick"></div>
|
||||
</div>
|
||||
<div class="row pref" id="codexAutoReviewRow">
|
||||
<div class="who"><div class="name" data-t>Codex auto-review model</div></div>
|
||||
<div class="val" id="codexAutoReviewPick"></div>
|
||||
|
||||
@@ -56,6 +56,10 @@ const REQUEST_KINDS = {
|
||||
"purpose": "kind:routing",
|
||||
"name": "Routing classifier"
|
||||
},
|
||||
"thread_description": {
|
||||
"purpose": "kind:thread_description",
|
||||
"name": "Description"
|
||||
},
|
||||
"thread_spawn": {
|
||||
"purpose": "kind:collab_spawn",
|
||||
"name": "Subagent"
|
||||
|
||||
@@ -65,3 +65,40 @@ func TestCodexTitlesSetting(t *testing.T) {
|
||||
t.Errorf("Codex's own: %d %q", code, settings.Load().CodexTitles)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodexDescriptionsSetting(t *testing.T) {
|
||||
h := t.TempDir()
|
||||
t.Setenv("HOME", h)
|
||||
t.Setenv("USERPROFILE", h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
|
||||
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
|
||||
for _, v := range agentenv.Vars {
|
||||
t.Setenv(v, "")
|
||||
}
|
||||
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Models: []string{"m1"}, Chat: "http://127.0.0.1:9/v1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
call := func(path, body string) (int, map[string]any) {
|
||||
t.Helper()
|
||||
rec := httptest.NewRecorder()
|
||||
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
||||
var out map[string]any
|
||||
json.Unmarshal(rec.Body.Bytes(), &out)
|
||||
return rec.Code, out
|
||||
}
|
||||
code, out := call("/api/settings/codex-descriptions", `{"model":"fake/m1"}`)
|
||||
if code != 200 || out["codexDescriptions"] != "fake/m1" || settings.Load().CodexDescriptions != "fake/m1" {
|
||||
t.Fatalf("model: %d %v", code, out["codexDescriptions"])
|
||||
}
|
||||
if code, _ := call("/api/settings", `{"theme":"dark"}`); code != 200 || settings.Load().CodexDescriptions != "fake/m1" {
|
||||
t.Errorf("another save lost the setting: %q", settings.Load().CodexDescriptions)
|
||||
}
|
||||
if code, _ := call("/api/settings/codex-descriptions", `{"model":"nope/x"}`); code < 400 || settings.Load().CodexDescriptions != "fake/m1" {
|
||||
t.Errorf("unknown model: %d %q", code, settings.Load().CodexDescriptions)
|
||||
}
|
||||
if code, _ := call("/api/settings/codex-descriptions", `{"model":""}`); code != 200 || settings.Load().CodexDescriptions != "" {
|
||||
t.Errorf("Codex's own: %d %q", code, settings.Load().CodexDescriptions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +148,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
PlainOwnNames: true,
|
||||
CodexAgentsV1: true,
|
||||
CodexTitles: "off",
|
||||
CodexDescriptions: "fake/m1",
|
||||
CodexAutoReview: "fake/m1",
|
||||
CodexSubagentModel: "codex/gpt-6-astra",
|
||||
ChinaMirror: true,
|
||||
|
||||
@@ -342,6 +342,12 @@ type Settings struct {
|
||||
// as Codex sends them, "off" answered by magpie with no title and sent
|
||||
// nowhere, or a model's id (provider/model, group/<id>) that writes it.
|
||||
CodexTitles string `json:"codexTitles,omitempty"`
|
||||
// CodexDescriptions is where the request Codex makes for a thread's
|
||||
// description (thread_description: its own hidden turn, on Codex's own
|
||||
// model through its ChatGPT sign-in) goes: "" as Codex sends it, or a
|
||||
// model's id (provider/model, group/<id>) that writes it. It is not
|
||||
// CodexTitles: a description asks for {"description"} alone.
|
||||
CodexDescriptions string `json:"codexDescriptions,omitempty"`
|
||||
// CodexAutoReview is the model Codex's auto-review (approvals_reviewer
|
||||
// = "auto_review": the guardian that decides an approval in the user's
|
||||
// place) runs on (#938): a model's id (provider/model, group/<id>) put
|
||||
@@ -1087,6 +1093,10 @@ func save(s Settings, recording bool) error {
|
||||
if s.CodexTitles != "" && s.CodexTitles != "off" && !strings.Contains(s.CodexTitles, "/") {
|
||||
return fmt.Errorf("the model for Codex's titles must be a model's id such as openai/gpt-5-mini, or off, not %q", s.CodexTitles)
|
||||
}
|
||||
s.CodexDescriptions = strings.TrimSpace(s.CodexDescriptions)
|
||||
if s.CodexDescriptions != "" && !strings.Contains(s.CodexDescriptions, "/") {
|
||||
return fmt.Errorf("the model for Codex's descriptions must be a model's id such as openai/gpt-5-mini, not %q", s.CodexDescriptions)
|
||||
}
|
||||
s.CodexAutoReview = strings.TrimSpace(s.CodexAutoReview)
|
||||
if s.CodexAutoReview != "" && !strings.Contains(s.CodexAutoReview, "/") {
|
||||
return fmt.Errorf("the model for Codex's auto-review must be a model's id such as openai/gpt-5-mini, not %q", s.CodexAutoReview)
|
||||
|
||||
@@ -22,6 +22,7 @@ var purposeKinds = func() map[string]PurposeKind {
|
||||
add("Compaction", "compact")
|
||||
add("Memory", "memory_consolidation", "memgen", "memory")
|
||||
add("Title", "thread_title", "thread_title_reconsideration", "title_generation", "title")
|
||||
add("Description", "thread_description")
|
||||
add("Subagent", "collab_spawn", "thread_spawn", "agent_job")
|
||||
add("Luna Reserve", "luna_reserve")
|
||||
add("Suggestions", "ambient_suggestions", "ambient_suggestion_safety")
|
||||
|
||||
@@ -39,6 +39,13 @@ func TestPurposeFilter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescriptionPurposeLabel(t *testing.T) {
|
||||
p := PurposeKinds()["thread_description"]
|
||||
if p.Purpose != "kind:thread_description" || p.Name != "Description" {
|
||||
t.Fatalf("description purpose: %+v", p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurposeRequestPages(t *testing.T) {
|
||||
pageHome(t)
|
||||
now := holdClock(t, time.Date(2026, 9, 30, 12, 0, 0, 0, time.Local))
|
||||
|
||||
Reference in New Issue
Block a user