trae 0.2.20: every chat function's roster is read, and a model's levels are kept (#300)
Every chat function's roster is read, so each model's reasoning levels come from Trae's own config, and a model keeps its levels in magpie and in plain OpenCode (#300, sphuang1030-prog). - A model in the fallback table keeps the levels its entry names, even though the host hands every model `variants: {}`. - A variant's value is OpenCode's name (low/high/xhigh); effortOf takes either spelling and sends Trae's (light/high/extra_high), and nothing for a level the model doesn't name. - The token-keyed record check that never fired is gone; the host's strict refresh reads the list again after a re-sign-in. Reviewed at 4b968adb: bun test in packages/trae (temp HOME/TMPDIR) 203 pass / 0 fail on bun 1.4.2; bun scripts/check.mjs exit 0. The three new tests go red on the previous head 41904d9. Probes through the loader's fetch: low→light, high→high, xhigh→extra_high; medium/__proto__ send nothing; glm-5.2 fallback gives high, xhigh (was []). merge-tree against main clean; npm latest trae 0.2.19. Not tried: a real Trae account; OpenCode's own source (whether it fills default variants first).
This commit is contained in:
+49
-11
@@ -86,8 +86,9 @@ agent's `POST https://trae-api-cn.mchost.guru/api/agent/v3/llm_utils_chat`:
|
|||||||
- The function is the one whose model list has the model, the first that
|
- The function is the one whose model list has the model, the first that
|
||||||
names a `__dev` model for it (in the order `chat_v3`, the classic IDE's;
|
names a `__dev` model for it (in the order `chat_v3`, the classic IDE's;
|
||||||
`solo_work_lite`, SOLO's Work mode; `solo_agent`, the TRAE agent's;
|
`solo_work_lite`, SOLO's Work mode; `solo_agent`, the TRAE agent's;
|
||||||
`solo_agent_lite`). If Trae answers 4001, 4023 or 1005, the plugin tries
|
`solo_agent_lite`; `solo_coder`, SOLO's coder roster). If Trae answers
|
||||||
the others once and remembers which one worked.
|
4001, 4023 or 1005, the plugin tries the others once and remembers which
|
||||||
|
one worked.
|
||||||
- `session_id` is the conversation's, as the IDE keeps one per conversation:
|
- `session_id` is the conversation's, as the IDE keeps one per conversation:
|
||||||
the session magpie (or OpenCode) names the request by, else the chat's
|
the session magpie (or OpenCode) names the request by, else the chat's
|
||||||
first user message, which every later turn repeats, together with the
|
first user message, which every later turn repeats, together with the
|
||||||
@@ -202,7 +203,10 @@ The model list is the account's own, from
|
|||||||
TRAE SOLO CN asks it (`/api/ide/v1/get_detail_param`, one function at a
|
TRAE SOLO CN asks it (`/api/ide/v1/get_detail_param`, one function at a
|
||||||
time, when the batch gives none). The lists are put together: SOLO and the
|
time, when the batch gives none). The lists are put together: SOLO and the
|
||||||
TRAE agent list models `chat_v3` doesn't (deepseek-v4.1-flash is the TRAE
|
TRAE agent list models `chat_v3` doesn't (deepseek-v4.1-flash is the TRAE
|
||||||
agent's, `solo_agent`). Left out are the IDE's helpers (`usage` other than
|
agent's, `solo_agent`), and SOLO's coder roster lists models no other chat
|
||||||
|
function does (`glm-5v-turbo`, `kimi-k2.5`, `minimax-m2.7`,
|
||||||
|
`qwen-3.6-plus`, each answering through `solo_coder`). Left out are the
|
||||||
|
IDE's helpers (`usage` other than
|
||||||
`chat_completion`: summary, fast_apply…), configs switched off and the
|
`chat_completion`: summary, fast_apply…), configs switched off and the
|
||||||
custom-model slots. Context is the list's `context_window_tokens.dev`,
|
custom-model slots. Context is the list's `context_window_tokens.dev`,
|
||||||
output the `__dev` model's `max_tokens`. A model with a `__max` model and
|
output the `__dev` model's `max_tokens`. A model with a `__max` model and
|
||||||
@@ -222,14 +226,48 @@ served under — and asks that model, and its Max, through a list carrying
|
|||||||
it. Trae renamed its official entries on 2026-10-09, leaving the name its
|
it. Trae renamed its official entries on 2026-10-09, leaving the name its
|
||||||
lists mostly agree on the only thing that tells a misnamed entry apart.
|
lists mostly agree on the only thing that tells a misnamed entry apart.
|
||||||
|
|
||||||
Reasoning: the models reason, but Trae's request takes no effort or
|
Reasoning: the models reason, and each entry of the account's list says
|
||||||
thinking level, so the plugin lists no variants and a level an agent
|
which levels it takes — its `reasoning_effort_config`, with the options
|
||||||
picks does nothing. Every model it lists says so in its `capabilities`
|
(`light`, `high`, `extra_high`) and the default. The request takes the same
|
||||||
(`reasoning: true`, with `toolcall`, `temperature`, `attachment`, the
|
names as `reasoning_effort`, so a level an agent picks is sent as Trae
|
||||||
input and output modalities and an empty `variants`), the fallback
|
spells it: the plugin offers each model's own levels as `variants`
|
||||||
list's own capabilities kept where it has an entry: magpie reads
|
(`low`/`high`/`xhigh` for `light`/`high`/`extra_high`), and sends nothing
|
||||||
`capabilities.reasoning` alone for a model a plugin lists, and a model
|
for a level the model doesn't name, or for a model whose entry names none —
|
||||||
without it is shown as one that doesn't reason (0.2.4).
|
Trae then serves it at its own default. An entry naming levels this map
|
||||||
|
can't spell offers none, rather than being sent one Trae would reject. A
|
||||||
|
request that wants levels for a model the list hasn't named reads the list,
|
||||||
|
and that read is remembered for five minutes whether it produced an entry or
|
||||||
|
not: a list that fails, or one that doesn't name the model, costs one read
|
||||||
|
rather than one per request. (A read costs up to two 20s timeouts when Trae's
|
||||||
|
list endpoint is slow, while the chat itself needs no list to answer.) A read
|
||||||
|
in flight is shared, not skipped: requests that arrive together — a title
|
||||||
|
request beside a session's first turn, subagents — ride the one read and all
|
||||||
|
see what it named, so a Max asked that way is still sent under its base
|
||||||
|
model's name rather than the agent's own `-max` id. The host's own catalog
|
||||||
|
refresh rides the same read, so a refresh and a request never ask twice.
|
||||||
|
A request's read swallows an expiry (the chat can still answer); the
|
||||||
|
catalog's refresh raises it, so a lapsed account is still marked — including
|
||||||
|
when the refresh merely rides a read a request started, which is why the lapse
|
||||||
|
travels on the read's record instead of being thrown from it. The host's
|
||||||
|
refresh is strict, so it reads again rather than serving a cached lapse: a
|
||||||
|
re-sign-in is asked afresh instead of being told again that the account lapsed.
|
||||||
|
|
||||||
|
The entry kept for a model is the one the request is asked through, and so
|
||||||
|
the one whose levels the request is held to, so the lists' disagreement
|
||||||
|
about a model's levels matters: `computer_use_subagent`, for one, is named
|
||||||
|
with `light`/`high` by `solo_agent` and `solo_agent_lite` and with none by
|
||||||
|
`solo_work_lite`. The three signals that pick the entry — its `__dev`
|
||||||
|
model, its not carrying another model's name, its carrying the name the
|
||||||
|
lists agree on — decide first; of entries that tie on all three, one that
|
||||||
|
names levels is kept, so a model Trae serves with levels is not left
|
||||||
|
without them by a sibling entry that names none.
|
||||||
|
|
||||||
|
Every model it lists also says it reasons in its `capabilities`
|
||||||
|
(`reasoning: true`, with `toolcall`, `temperature`, `attachment` and the
|
||||||
|
input and output modalities), the fallback list's own capabilities kept
|
||||||
|
where it has an entry: magpie reads `capabilities.reasoning` alone for a
|
||||||
|
model a plugin lists, and a model without it is shown as one that doesn't
|
||||||
|
reason (0.2.4).
|
||||||
|
|
||||||
When no
|
When no
|
||||||
list can be read, the plugin uses the realm's own fallback list. Trae CN's
|
list can be read, the plugin uses the realm's own fallback list. Trae CN's
|
||||||
|
|||||||
+216
-16
@@ -70,8 +70,10 @@ const SITES = {
|
|||||||
brand: "ASUS TUF Gaming A15 FA507RM_FA507RM",
|
brand: "ASUS TUF Gaming A15 FA507RM_FA507RM",
|
||||||
// the IDE's chat functions: the classic IDE's agent, then SOLO's Work
|
// the IDE's chat functions: the classic IDE's agent, then SOLO's Work
|
||||||
// mode, then the TRAE agent (solo_agent, which has deepseek-v4.1-flash),
|
// mode, then the TRAE agent (solo_agent, which has deepseek-v4.1-flash),
|
||||||
// then SOLO Lite's agent
|
// then SOLO Lite's agent, then SOLO's coder roster, which lists models no
|
||||||
functions: ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite"],
|
// other chat function does (glm-5v-turbo, kimi-k2.5, minimax-m2.7,
|
||||||
|
// qwen-3.6-plus — each answers through it)
|
||||||
|
functions: ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite", "solo_coder"],
|
||||||
// what Trae CN's chat_v3 is known to serve; the live list replaces it
|
// what Trae CN's chat_v3 is known to serve; the live list replaces it
|
||||||
// (the MODEL defaults are spread in at the end of the module, once MODEL
|
// (the MODEL defaults are spread in at the end of the module, once MODEL
|
||||||
// is defined, so a site's entry only names what differs)
|
// is defined, so a site's entry only names what differs)
|
||||||
@@ -172,7 +174,7 @@ const SITES = {
|
|||||||
clientVersionCode: "20260917",
|
clientVersionCode: "20260917",
|
||||||
pluginVersion: "2.3.62834",
|
pluginVersion: "2.3.62834",
|
||||||
brand: "ASUS TUF Gaming A15 FA507RM_FA507RM",
|
brand: "ASUS TUF Gaming A15 FA507RM_FA507RM",
|
||||||
functions: ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite"],
|
functions: ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite", "solo_coder"],
|
||||||
// what Trae Global's chat is known to serve (its catalog barely overlaps
|
// what Trae Global's chat is known to serve (its catalog barely overlaps
|
||||||
// the CN one's); the live list replaces it
|
// the CN one's); the live list replaces it
|
||||||
models: {
|
models: {
|
||||||
@@ -283,6 +285,13 @@ const SIGN_IN_TIMEOUT = 10 * 60 * 1000
|
|||||||
const EARLY_MS = 2 * 60 * 1000 // a token this close to its end is renewed before a request
|
const EARLY_MS = 2 * 60 * 1000 // a token this close to its end is renewed before a request
|
||||||
const LEAD_MS = 10 * 60 * 1000 // and this close, magpie renews it ahead of time (auth.refresh)
|
const LEAD_MS = 10 * 60 * 1000 // and this close, magpie renews it ahead of time (auth.refresh)
|
||||||
const DAY = 24 * 3600 * 1000
|
const DAY = 24 * 3600 * 1000
|
||||||
|
// REREAD_MS is how long a list read keeps its answer before a request that
|
||||||
|
// wants levels may read the list again: it holds whether the read produced an
|
||||||
|
// entry for the model or not, so a list answering badly (or one that doesn't
|
||||||
|
// name the model) costs one read, not one per request. A request path that
|
||||||
|
// reads on every attempt would otherwise pay two 20s timeouts on each turn —
|
||||||
|
// the branch costs the chat itself nothing to answer from.
|
||||||
|
const REREAD_MS = 5 * 60 * 1000
|
||||||
|
|
||||||
// a reply limit of 0 is one Trae doesn't say: magpie then takes models.dev's
|
// a reply limit of 0 is one Trae doesn't say: magpie then takes models.dev's
|
||||||
// for the model (magpie's catalog), where a made-up 32K told agents a far
|
// for the model (magpie's catalog), where a made-up 32K told agents a far
|
||||||
@@ -1168,7 +1177,12 @@ function sessionOf(headers) {
|
|||||||
// tool result sent back, a retry, another function answering) shows up in the
|
// tool result sent back, a retry, another function answering) shows up in the
|
||||||
// usage detail as several, each under no title at all. request_id stays a
|
// usage detail as several, each under no title at all. request_id stays a
|
||||||
// fresh id per request, being that request's own.
|
// fresh id per request, being that request's own.
|
||||||
function chatBody(req, fn, modelName, most = 0, max = null, session = "", sees = false) {
|
//
|
||||||
|
// levels is the model's own levels (levelsOf of its entry): the effort the
|
||||||
|
// request asks for is sent as the Trae name that model takes, and left out
|
||||||
|
// when it takes none of that name — Trae rejects a level a model has no entry
|
||||||
|
// for, and serves its default when none is asked.
|
||||||
|
function chatBody(req, fn, modelName, most = 0, max = null, session = "", sees = false, levels = null) {
|
||||||
const config = max?.base ?? req.model
|
const config = max?.base ?? req.model
|
||||||
const body = {
|
const body = {
|
||||||
messages: traeMessages(req, sees),
|
messages: traeMessages(req, sees),
|
||||||
@@ -1180,6 +1194,8 @@ function chatBody(req, fn, modelName, most = 0, max = null, session = "", sees =
|
|||||||
request_id: randomUUID(),
|
request_id: randomUUID(),
|
||||||
session_id: session || randomUUID(),
|
session_id: session || randomUUID(),
|
||||||
}
|
}
|
||||||
|
const effort = effortOf(levels, req.reasoning_effort ?? req.reasoningEffort)
|
||||||
|
if (effort) body.reasoning_effort = effort
|
||||||
const asked = req.max_completion_tokens ?? req.max_tokens
|
const asked = req.max_completion_tokens ?? req.max_tokens
|
||||||
if (Number.isFinite(asked) && asked > 0) body.max_tokens = most > 0 ? Math.min(Math.floor(asked), most) : Math.floor(asked)
|
if (Number.isFinite(asked) && asked > 0) body.max_tokens = most > 0 ? Math.min(Math.floor(asked), most) : Math.floor(asked)
|
||||||
if (max?.window) {
|
if (max?.window) {
|
||||||
@@ -2550,6 +2566,55 @@ const maxModel = (...ms) => {
|
|||||||
// deepseek-v4.1-flash in Max mode
|
// deepseek-v4.1-flash in Max mode
|
||||||
const MAX = "-max"
|
const MAX = "-max"
|
||||||
|
|
||||||
|
// ---- reasoning levels --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// A list entry carries a reasoning_effort_config: the levels its model takes
|
||||||
|
// (light, high, extra_high) and the one it defaults to. The request takes the
|
||||||
|
// same names, as reasoning_effort, so a level an agent picks is sent as Trae
|
||||||
|
// spells it. OpenCode knows the three as low/high/xhigh, so the map goes both
|
||||||
|
// ways.
|
||||||
|
//
|
||||||
|
// An entry without the config takes no level: Trae serves it at its own
|
||||||
|
// default and nothing is sent. The plugin used to send none for every model,
|
||||||
|
// which read as "Trae takes no level" — it takes them, per model, and an
|
||||||
|
// entry that names none is the exception rather than the rule.
|
||||||
|
const LEVELS = { light: "low", high: "high", extra_high: "xhigh" }
|
||||||
|
|
||||||
|
// levelsOf is an entry's levels in OpenCode's names, in Trae's order: [] when
|
||||||
|
// the entry names none, null when it names ones this map can't spell (so a
|
||||||
|
// caller can tell "takes no level" from "takes a level we can't name").
|
||||||
|
const levelsOf = (m) => {
|
||||||
|
const cfg = m?.reasoning_effort_config
|
||||||
|
if (!cfg || typeof cfg !== "object") return []
|
||||||
|
const options = Array.isArray(cfg.options) ? cfg.options : []
|
||||||
|
const known = options.filter((o) => typeof o === "string" && LEVELS[o])
|
||||||
|
return known.length ? known.map((o) => LEVELS[o]) : options.length ? null : []
|
||||||
|
}
|
||||||
|
|
||||||
|
// variantsOf is a model's levels as OpenCode's variants. The value is the
|
||||||
|
// effort OpenCode puts in the request body, so it names the level the way this
|
||||||
|
// plugin's levels do: an agent in OpenCode writes `reasoning_effort` straight
|
||||||
|
// from it, and effortOf below turns that name into Trae's. Naming Trae's
|
||||||
|
// spelling here would make the body say "light", which is not one of the
|
||||||
|
// levels this plugin offers, and the field would then be dropped. {} when the
|
||||||
|
// model takes none.
|
||||||
|
const variantsOf = (levels) => Object.fromEntries((levels ?? []).map((level) => [level, { reasoningEffort: level }]))
|
||||||
|
|
||||||
|
// effortOf is the name to send Trae for an effort the request carries, or
|
||||||
|
// undefined when the model doesn't take that one: a level Trae has no entry for
|
||||||
|
// is rejected, so nothing is sent instead. The effort arrives in either
|
||||||
|
// spelling — this plugin's own (low/high/xhigh) from its variants, or Trae's
|
||||||
|
// (light/extra_high) from a client that read them off the list — and both name
|
||||||
|
// the same level.
|
||||||
|
const effortOf = (levels, effort) => {
|
||||||
|
if (typeof effort !== "string" || !levels) return undefined
|
||||||
|
const mine = Object.values(LEVELS).includes(effort) ? effort
|
||||||
|
: Object.prototype.hasOwnProperty.call(LEVELS, effort) ? LEVELS[effort]
|
||||||
|
: undefined
|
||||||
|
if (mine === undefined || !levels.includes(mine)) return undefined
|
||||||
|
return Object.keys(LEVELS).find((k) => LEVELS[k] === mine)
|
||||||
|
}
|
||||||
|
|
||||||
// ---- usage ------------------------------------------------------------------------
|
// ---- usage ------------------------------------------------------------------------
|
||||||
|
|
||||||
// credits adds up the account's entitlement packs as the IDE shows them:
|
// credits adds up the account's entitlement packs as the IDE shows them:
|
||||||
@@ -2610,6 +2675,88 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
const maxes = new Map()
|
const maxes = new Map()
|
||||||
// whether each model the list last read takes images (its multimodal)
|
// whether each model the list last read takes images (its multimodal)
|
||||||
const sight = new Map()
|
const sight = new Map()
|
||||||
|
// the entry the lists last gave each model, for what only the entry says:
|
||||||
|
// the reasoning levels it takes (reasoning_effort_config)
|
||||||
|
const liveEntry = new Map()
|
||||||
|
const liveEntryOf = (id) => liveEntry.get(String(id)) ?? site.models?.[String(id)]?.entry ?? null
|
||||||
|
// when each account's list was last read, and what that read returned:
|
||||||
|
// {at, p, done, expired}. A read that answered, failed or hung all leave
|
||||||
|
// their stamp, so a list that fails or leaves the model out costs one read
|
||||||
|
// per REREAD_MS rather than one per request. The promise is kept beside the
|
||||||
|
// stamp because a caller that arrives while a read is in flight must ride
|
||||||
|
// THAT read, not start a second and not skip the answer it was about to
|
||||||
|
// learn: agents send parallel requests at a session's start (a title request
|
||||||
|
// beside the first turn, subagents), and a caller that skipped the entry a
|
||||||
|
// read just produced would send a Max out under the agent's own id, which
|
||||||
|
// Trae's list doesn't name.
|
||||||
|
//
|
||||||
|
// The record is the thing the promise resolves to, so a joiner sees the same
|
||||||
|
// outcome the read settled on — including an expiry it hit — rather than the
|
||||||
|
// bare `null` a failed read answers. One account per key; a read is that
|
||||||
|
// account's.
|
||||||
|
const readAt = new Map()
|
||||||
|
// runRead starts the one read behind readList and answers its record. `p`
|
||||||
|
// resolves to that record — not to the models — so a caller that joins a
|
||||||
|
// read in flight sees the same outcome the read settled on, an expiry
|
||||||
|
// included, rather than the bare null a failed read answers.
|
||||||
|
const runRead = (a, who) => {
|
||||||
|
const rec = { at: Date.now(), p: null, done: undefined, expired: null }
|
||||||
|
// the record goes in BEFORE the read starts, so a caller arriving during it
|
||||||
|
// finds `rec.p` and joins; `p` resolves to this same record
|
||||||
|
readAt.set(who, rec)
|
||||||
|
const body = (async () => {
|
||||||
|
try {
|
||||||
|
return await liveModels(a)
|
||||||
|
} catch (e) {
|
||||||
|
// a request's read swallows this (the chat can still answer); a caller
|
||||||
|
// that must hear it reads `expired` off the record. Recorded on the
|
||||||
|
// record, so a joiner hears it too.
|
||||||
|
if (e instanceof Expired) rec.expired = e
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
// every rejection is claimed here, at creation: a read nobody awaits (the
|
||||||
|
// host's refresh ending early, a caller that walked away) must not surface
|
||||||
|
// as an unhandled rejection. `p` itself never rejects — the expiry rides on
|
||||||
|
// the record instead.
|
||||||
|
body.catch(() => {})
|
||||||
|
rec.p = body.then((models) => {
|
||||||
|
// only this read settles its own record: a later read may have replaced it
|
||||||
|
if (readAt.get(who) === rec) {
|
||||||
|
rec.at = Date.now()
|
||||||
|
rec.done = models ?? []
|
||||||
|
rec.p = null
|
||||||
|
}
|
||||||
|
return rec
|
||||||
|
})
|
||||||
|
rec.p.catch(() => {})
|
||||||
|
return rec.p
|
||||||
|
}
|
||||||
|
// readList answers the models of the read this caller rode on (its own, or
|
||||||
|
// the one in flight, whose record it waits for and then reads), and whether
|
||||||
|
// that read found the account lapsed. The record is the account's, not the
|
||||||
|
// token's: a re-sign-in is the same account's list, and the host's refresh is
|
||||||
|
// strict, so it reads again rather than serving a cached lapse. A request
|
||||||
|
// path only reaches here for a model it has no entry for, and that read is
|
||||||
|
// the one that fills the entry in.
|
||||||
|
//
|
||||||
|
// The lapse is answered, not thrown: several callers can ride one read, and a
|
||||||
|
// throw out of a shared promise surfaces once as an unhandled rejection for
|
||||||
|
// the callers that did not expect it. Each caller decides — provider.models
|
||||||
|
// raises it, a request path keeps going. `strict` only says whether a cached
|
||||||
|
// lapse is worth reading again for (the host wants the truth; a request does
|
||||||
|
// not pay a round trip to learn it).
|
||||||
|
const readList = async (a, { strict = false } = {}) => {
|
||||||
|
const who = a.uid || a.name || String(site.id)
|
||||||
|
const was = readAt.get(who)
|
||||||
|
let rec
|
||||||
|
if (was === undefined) rec = await runRead(a, who)
|
||||||
|
else if (was.p) rec = await was.p
|
||||||
|
else if (was.done === undefined || Date.now() - was.at >= REREAD_MS) rec = await runRead(a, who)
|
||||||
|
else if (strict && was.expired) rec = await runRead(a, who)
|
||||||
|
else rec = was
|
||||||
|
return { models: rec.done, expired: rec.expired }
|
||||||
|
}
|
||||||
|
|
||||||
const save = async (auth) => {
|
const save = async (auth) => {
|
||||||
try {
|
try {
|
||||||
@@ -2880,8 +3027,16 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
}
|
}
|
||||||
// a function's entry is worth more when it names a __dev model, then
|
// a function's entry is worth more when it names a __dev model, then
|
||||||
// when it isn't misnamed, then when it carries the name its lists agree
|
// when it isn't misnamed, then when it carries the name its lists agree
|
||||||
// on; the first of the best is taken
|
// on; the first of the best is taken. Those three decide first, so the
|
||||||
const worth = (fn, m) => (devModel(m) ? 2 : 0) + (misnamed(fn, m) ? 0 : 1) + (nameOf(m) === agreed.get(String(m.config_name)) ? 1 : 0)
|
// entry kept is the one Trae's own client asks through.
|
||||||
|
//
|
||||||
|
// Last among equals comes whether the entry names reasoning levels: the
|
||||||
|
// entry kept is the one the request is asked through, and so the one
|
||||||
|
// whose reasoning_effort_config the request is held to (liveEntryOf). An
|
||||||
|
// entry that names none while a sibling names some would leave the model
|
||||||
|
// with no level to pick although Trae serves it with levels — doubling
|
||||||
|
// the three keeps them decisive and lets this only break a tie.
|
||||||
|
const worth = (fn, m) => ((devModel(m) ? 2 : 0) + (misnamed(fn, m) ? 0 : 1) + (nameOf(m) === agreed.get(String(m.config_name)) ? 1 : 0)) * 2 + (levelsOf(m)?.length ? 1 : 0)
|
||||||
const out = new Map()
|
const out = new Map()
|
||||||
for (const fn of site.functions) {
|
for (const fn of site.functions) {
|
||||||
for (const m of lists[fn] ?? []) {
|
for (const m of lists[fn] ?? []) {
|
||||||
@@ -2893,6 +3048,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
}
|
}
|
||||||
for (const [id, { m, fn }] of out) {
|
for (const [id, { m, fn }] of out) {
|
||||||
listedBy.set(id, fn)
|
listedBy.set(id, fn)
|
||||||
|
liveEntry.set(id, m)
|
||||||
const sees = seesOf(m)
|
const sees = seesOf(m)
|
||||||
if (sees === null) sight.delete(id)
|
if (sees === null) sight.delete(id)
|
||||||
else sight.set(id, sees)
|
else sight.set(id, sees)
|
||||||
@@ -2916,7 +3072,17 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
modelNames.delete(id + MAX)
|
modelNames.delete(id + MAX)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [...out.values()].map((x) => x.m)
|
// this account's list has just answered: recorded, so a request that wants
|
||||||
|
// levels for a model the list doesn't name waits REREAD_MS before reading
|
||||||
|
// again, and a request arriving meanwhile joins this read instead of
|
||||||
|
// asking — the catalog read a host makes counts as that read too
|
||||||
|
const models = [...out.values()].map((x) => x.m)
|
||||||
|
const who = a.uid || a.name || String(site.id)
|
||||||
|
const at = readAt.get(who)
|
||||||
|
// a readList run records itself; a read nobody recorded (a caller reaching
|
||||||
|
// liveModels directly) is recorded here, unless a read is in flight
|
||||||
|
if (at === undefined || !at.p) readAt.set(who, { at: Date.now(), p: null, done: models, expired: null })
|
||||||
|
return models
|
||||||
}
|
}
|
||||||
|
|
||||||
// modelOf is a model of the account's list as OpenCode's provider
|
// modelOf is a model of the account's list as OpenCode's provider
|
||||||
@@ -2954,9 +3120,13 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
input: sees === null ? inputs : { ...inputs, image: sees },
|
input: sees === null ? inputs : { ...inputs, image: sees },
|
||||||
output: was.capabilities?.output ?? { text: true, image: false, audio: false, video: false, pdf: false },
|
output: was.capabilities?.output ?? { text: true, image: false, audio: false, video: false, pdf: false },
|
||||||
},
|
},
|
||||||
// Trae's request takes no effort or thinking level, so a model has
|
// the levels this entry takes, as OpenCode's variants: Trae's own
|
||||||
// none to pick from (see the README's Reasoning)
|
// reasoning_effort_config, which a model without one doesn't carry (it
|
||||||
variants: was.variants ?? {},
|
// is then served at Trae's default, with no level to pick). A config
|
||||||
|
// model with an empty variants says nothing — magpie's host fills one in
|
||||||
|
// for every model it hands over — so only a non-empty one is kept, or a
|
||||||
|
// model in the fallback table would lose the levels its entry names.
|
||||||
|
variants: Object.keys(was.variants ?? {}).length ? was.variants : variantsOf(levelsOf(m)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2982,11 +3152,19 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
},
|
},
|
||||||
provider: {
|
provider: {
|
||||||
id: site.id,
|
id: site.id,
|
||||||
// the account's own list, when Trae answers; else the list above
|
// the account's own list, when Trae answers; else the list above.
|
||||||
|
// A refresh rides readList's one read per REREAD_MS, so a request that
|
||||||
|
// wants levels while the host is refreshing joins that read instead of
|
||||||
|
// asking for the list a second time (and vice versa).
|
||||||
async models(provider, { auth }) {
|
async models(provider, { auth }) {
|
||||||
if (auth?.type !== "oauth" || !auth.access) return provider.models
|
if (auth?.type !== "oauth" || !auth.access) return provider.models
|
||||||
try {
|
try {
|
||||||
const ms = await liveModels(await fresh(async () => auth))
|
const { models: ms, expired } = await readList(await fresh(async () => auth), { strict: true })
|
||||||
|
// a lapse must reach the host here, so the account is marked: a
|
||||||
|
// request path deliberately lets it pass instead. A fresh instance:
|
||||||
|
// the recorded one already served as a rejection inside the read, and
|
||||||
|
// re-throwing that same object carries its unhandled state with it
|
||||||
|
if (expired) throw new Expired(expired.message)
|
||||||
if (!ms.length) return provider.models
|
if (!ms.length) return provider.models
|
||||||
const ids = new Set(ms.map((m) => String(m.config_name)))
|
const ids = new Set(ms.map((m) => String(m.config_name)))
|
||||||
return Object.fromEntries(ms.flatMap((m) => {
|
return Object.fromEntries(ms.flatMap((m) => {
|
||||||
@@ -3043,8 +3221,12 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
let last
|
let last
|
||||||
let named = modelNames.get(String(req.model))
|
let named = modelNames.get(String(req.model))
|
||||||
if (!named && String(req.model).endsWith(MAX)) {
|
if (!named && String(req.model).endsWith(MAX)) {
|
||||||
// a Max asked before the list was read here: read it
|
// a Max asked before the list was read here: read it (or ride
|
||||||
await liveModels(a).catch(() => {})
|
// the read already in flight), once per REREAD_MS — a list that
|
||||||
|
// doesn't name this Max is not read for again on every request
|
||||||
|
// (the chat can answer without it), and a Max the read does name
|
||||||
|
// is asked through its base, not under this unlisted id
|
||||||
|
await readList(a)
|
||||||
named = modelNames.get(String(req.model))
|
named = modelNames.get(String(req.model))
|
||||||
if (named) fns.unshift(named.fn)
|
if (named) fns.unshift(named.fn)
|
||||||
}
|
}
|
||||||
@@ -3053,6 +3235,24 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
// sends them only to a model it was told takes them
|
// sends them only to a model it was told takes them
|
||||||
const base = max?.base ?? String(req.model)
|
const base = max?.base ?? String(req.model)
|
||||||
const sees = sight.get(base) ?? (site.models[base]?.modalities?.input?.includes("image") ?? true)
|
const sees = sight.get(base) ?? (site.models[base]?.modalities?.input?.includes("image") ?? true)
|
||||||
|
// the levels the base model takes, from the entry its lists gave
|
||||||
|
// it: what the request's effort is sent as, and left out when the
|
||||||
|
// model has no entry for it. An entry naming levels this build
|
||||||
|
// can't spell counts as no level here — levelsOf says null for it
|
||||||
|
// so a caller can tell the two apart, and this one sends nothing
|
||||||
|
// either way.
|
||||||
|
//
|
||||||
|
// The list is read once per REREAD_MS for a model it hasn't named,
|
||||||
|
// and a read already in flight is shared rather than skipped: a
|
||||||
|
// parallel request that skipped it would drop its level for that
|
||||||
|
// turn. An answer that leaves the model out — a list that failed,
|
||||||
|
// or one that simply doesn't name it — is remembered too, instead
|
||||||
|
// of being asked for again on every request that carries an effort.
|
||||||
|
let levels = levelsOf(liveEntryOf(base)) ?? []
|
||||||
|
if (!liveEntry.has(base) && (req.reasoning_effort ?? req.reasoningEffort)) {
|
||||||
|
await readList(a)
|
||||||
|
levels = levelsOf(liveEntryOf(base)) ?? []
|
||||||
|
}
|
||||||
// the answer's own signal: the caller's abort (a cancelled
|
// the answer's own signal: the caller's abort (a cancelled
|
||||||
// request) and the stream's cancel both stop Trae's fetch, so
|
// request) and the stream's cancel both stop Trae's fetch, so
|
||||||
// no read is left hanging on a connection the agent walked
|
// no read is left hanging on a connection the agent walked
|
||||||
@@ -3072,7 +3272,7 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
const res = await fetch(apiOf(a, site) + "/api/agent/v3/llm_utils_chat", {
|
const res = await fetch(apiOf(a, site) + "/api/agent/v3/llm_utils_chat", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: ideHeaders(a, site, { Accept: "text/event-stream", "X-Request-ID": randomUUID() }),
|
headers: ideHeaders(a, site, { Accept: "text/event-stream", "X-Request-ID": randomUUID() }),
|
||||||
body: JSON.stringify(chatBody(req, fn, named?.fn === fn || max ? named.name : "", named?.fn === fn || max ? named.most : 0, max, session, sees)),
|
body: JSON.stringify(chatBody(req, fn, named?.fn === fn || max ? named.name : "", named?.fn === fn || max ? named.most : 0, max, session, sees, levels)),
|
||||||
signal: ac.signal,
|
signal: ac.signal,
|
||||||
})
|
})
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
@@ -3123,4 +3323,4 @@ const makePlugin = (site) => async ({ client }) => {
|
|||||||
export const TraeCNAuthPlugin = makePlugin(SITES["trae-cn"])
|
export const TraeCNAuthPlugin = makePlugin(SITES["trae-cn"])
|
||||||
export const TraeGlobalAuthPlugin = makePlugin(SITES["trae-global"])
|
export const TraeGlobalAuthPlugin = makePlugin(SITES["trae-global"])
|
||||||
|
|
||||||
export const _internal = { ownClient, clientStoragePaths, clientDevice, clientDecode, thisMachine, traeHost, accountOf, HOSTS: SITES["trae-cn"].hosts, MODELS: SITES["trae-cn"].models, TextTools, NativeCalls, looseJSON, glmCall, nameCall, toolNamed, unwrapped, traeMessages, chatBody, credits, dollarUsageOf, whenOf, newDevice, ugDevice, proofOf, SITES, SESSION, conversationID }
|
export const _internal = { ownClient, clientStoragePaths, clientDevice, clientDecode, thisMachine, traeHost, accountOf, HOSTS: SITES["trae-cn"].hosts, MODELS: SITES["trae-cn"].models, TextTools, NativeCalls, looseJSON, glmCall, nameCall, toolNamed, unwrapped, traeMessages, chatBody, credits, dollarUsageOf, whenOf, newDevice, ugDevice, proofOf, SITES, SESSION, conversationID, LEVELS, levelsOf, variantsOf, effortOf }
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ test("a model the fallback table doesn't have is served with capabilities", asyn
|
|||||||
expect(m.capabilities.attachment).toBe(false)
|
expect(m.capabilities.attachment).toBe(false)
|
||||||
expect(m.capabilities.input).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
|
expect(m.capabilities.input).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
|
||||||
expect(m.capabilities.output).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
|
expect(m.capabilities.output).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
|
||||||
// Trae's request takes no effort or thinking level: no variants
|
// an entry that names no levels takes none: no variants (see reasoning.test.mjs
|
||||||
|
// for the entries that do name them)
|
||||||
expect(m.variants).toEqual({})
|
expect(m.variants).toEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@magpie-community/opencode-trae-auth",
|
"name": "@magpie-community/opencode-trae-auth",
|
||||||
"version": "0.2.19",
|
"version": "0.2.20",
|
||||||
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
|
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./index.mjs",
|
"main": "./index.mjs",
|
||||||
|
|||||||
@@ -0,0 +1,371 @@
|
|||||||
|
// A model's reasoning levels: Trae's list entry carries a
|
||||||
|
// reasoning_effort_config (its options, its default), and the request takes
|
||||||
|
// the same names as reasoning_effort. The plugin used to hand agents no
|
||||||
|
// levels at all and send none, which read as "Trae takes no level": a routing
|
||||||
|
// group whose members carry no level loses reasoning for the whole group.
|
||||||
|
//
|
||||||
|
// The names differ once: OpenCode knows light/high/extra_high as
|
||||||
|
// low/high/xhigh, so the map goes both ways — offered as variants, sent as
|
||||||
|
// Trae spells them.
|
||||||
|
import "./nonet.mjs"
|
||||||
|
import { afterEach, expect, test } from "bun:test"
|
||||||
|
import { TraeCNAuthPlugin, _internal } from "./index.mjs"
|
||||||
|
import { fakeTrae, json, signedIn, sse } from "./fake.mjs"
|
||||||
|
|
||||||
|
let f
|
||||||
|
afterEach(() => f?.close())
|
||||||
|
|
||||||
|
const { LEVELS, levelsOf, variantsOf, effortOf, chatBody } = _internal
|
||||||
|
|
||||||
|
// an entry of an account's list, with the levels it takes
|
||||||
|
const entry = (name, options, extra = {}) => ({
|
||||||
|
config_name: name, usage: "chat_completion",
|
||||||
|
display_config: { display_name: name },
|
||||||
|
context_window_tokens: { dev: 1_000_000 },
|
||||||
|
model_detail_list: [{ model_name: name + "__dev", max_tokens: 32000 }],
|
||||||
|
...(options === undefined ? {} : { reasoning_effort_config: { options, ...extra } }),
|
||||||
|
})
|
||||||
|
|
||||||
|
// live serves the account's list and hands back the models the
|
||||||
|
// provider.models hook built from it
|
||||||
|
async function live(configs) {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: configs },
|
||||||
|
] }))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
return hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||||
|
}
|
||||||
|
|
||||||
|
test("an entry's levels are offered as the variants agents pick, named as OpenCode names them", async () => {
|
||||||
|
const ms = await live([entry("deepseek-v4.1-flash", ["light", "high", "extra_high"], { default_level: "high" })])
|
||||||
|
const m = ms["deepseek-v4.1-flash"]
|
||||||
|
expect(Object.keys(m.variants)).toEqual(["low", "high", "xhigh"])
|
||||||
|
// the value is what OpenCode writes into the body, so it is this plugin's
|
||||||
|
// name for the level; effortOf turns it into Trae's on the way out
|
||||||
|
expect(m.variants.low).toEqual({ reasoningEffort: "low" })
|
||||||
|
expect(m.variants.high).toEqual({ reasoningEffort: "high" })
|
||||||
|
expect(m.variants.xhigh).toEqual({ reasoningEffort: "xhigh" })
|
||||||
|
// the model reasons, as it did before the levels came
|
||||||
|
expect(m.capabilities.reasoning).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("an entry with no levels carries no variants: Trae serves it at its own default", async () => {
|
||||||
|
const ms = await live([entry("glm-5.3", undefined)])
|
||||||
|
expect(ms["glm-5.3"].variants).toEqual({})
|
||||||
|
expect(ms["glm-5.3"].capabilities.reasoning).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("an entry naming levels this build can't spell carries no variants, and is not read as none", async () => {
|
||||||
|
// null is "it names levels, none of them ours" — distinct from [] ("none")
|
||||||
|
expect(levelsOf({ reasoning_effort_config: { options: ["ultra"] } })).toBe(null)
|
||||||
|
expect(levelsOf({ reasoning_effort_config: { options: [] } })).toEqual([])
|
||||||
|
expect(levelsOf({})).toEqual([])
|
||||||
|
expect(variantsOf(null)).toEqual({})
|
||||||
|
})
|
||||||
|
|
||||||
|
test("the levels an agent picks are sent as Trae's own names, and left out when the model has none", () => {
|
||||||
|
const levels = ["low", "high", "xhigh"]
|
||||||
|
const req = (effort) => ({ model: "deepseek-v4.1-flash", messages: [{ role: "user", content: "hi" }], ...(effort ? { reasoning_effort: effort } : {}) })
|
||||||
|
expect(chatBody(req("low"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("light")
|
||||||
|
expect(chatBody(req("high"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("high")
|
||||||
|
expect(chatBody(req("xhigh"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("extra_high")
|
||||||
|
// a level the model doesn't take is not sent: Trae has no entry for it
|
||||||
|
expect(chatBody(req("max"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBeUndefined()
|
||||||
|
// no effort asked, or a model with no levels: nothing sent
|
||||||
|
expect(chatBody(req(), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBeUndefined()
|
||||||
|
expect(chatBody(req("high"), "chat_v3", "", 0, null, "s", false, []).reasoning_effort).toBeUndefined()
|
||||||
|
expect(chatBody(req("high"), "chat_v3", "", 0, null, "s", false, null).reasoning_effort).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("the effort an agent picks reaches Trae's request, spelled as Trae names it", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("deepseek-v4.1-flash", ["light", "high", "extra_high"], { default_level: "high" })] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
await opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "deepseek-v4.1-flash", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "xhigh" }),
|
||||||
|
})
|
||||||
|
const sent = f.seen.find((r) => r.path === "/api/agent/v3/llm_utils_chat")
|
||||||
|
expect(sent.json.reasoning_effort).toBe("extra_high")
|
||||||
|
})
|
||||||
|
|
||||||
|
// In OpenCode the variant's value is what reaches the body: @ai-sdk/openai-
|
||||||
|
// compatible writes it as reasoning_effort, and the plugin's fetch reads it
|
||||||
|
// back. So every variant the plugin offers has to survive that round trip, not
|
||||||
|
// just the one whose OpenCode name happens to equal Trae's.
|
||||||
|
test("every variant's own value survives the round trip to Trae's request", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("deepseek-v4.1-flash", ["light", "high", "extra_high"], { default_level: "high" })] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const ms = await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||||
|
const variants = ms["deepseek-v4.1-flash"].variants
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
|
||||||
|
const expectSent = { low: "light", high: "high", xhigh: "extra_high" }
|
||||||
|
for (const [name, v] of Object.entries(variants)) {
|
||||||
|
await opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "deepseek-v4.1-flash", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: v.reasoningEffort }),
|
||||||
|
})
|
||||||
|
const sent = f.seen.filter((r) => r.path === "/api/agent/v3/llm_utils_chat").at(-1)
|
||||||
|
// the level reaches Trae spelled as Trae spells it, whichever variant it was
|
||||||
|
expect(sent.json.reasoning_effort).toBe(expectSent[name])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// magpie's host fills in `variants: m.variants ?? was?.variants ?? {}` for
|
||||||
|
// every model of the config, so provider.models is handed `{}` for models in
|
||||||
|
// the fallback table as well as ones the list named. An empty variants says
|
||||||
|
// nothing about the model, and must not overwrite the levels its entry names.
|
||||||
|
test("a model in the fallback table keeps the levels its entry names", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [
|
||||||
|
entry("glm-5.2", ["high", "extra_high"]),
|
||||||
|
entry("glm-5.3", ["light", "high", "extra_high"]),
|
||||||
|
] },
|
||||||
|
] }))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const cfg = { provider: {} }
|
||||||
|
await hooks.config(cfg)
|
||||||
|
const p = cfg.provider["trae-cn"]
|
||||||
|
// the shape the host hands over: every model carries a variants, empty where
|
||||||
|
// the config had none
|
||||||
|
const provider = { ...p, models: Object.fromEntries(Object.entries(p.models).map(([k, m]) => [k, { ...m, variants: m.variants ?? {} }])) }
|
||||||
|
|
||||||
|
const ms = await hooks.provider.models(provider, { auth: signedIn() })
|
||||||
|
// glm-5.2 is in the fallback table, so its config entry is the empty one
|
||||||
|
expect(Object.keys(ms["glm-5.2"].variants)).toEqual(["high", "xhigh"])
|
||||||
|
expect(Object.keys(ms["glm-5.3"].variants)).toEqual(["low", "high", "xhigh"])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a request for a model with no levels carries no reasoning_effort", async () => {
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("glm-5.3", undefined)] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
await opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "glm-5.3", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
const sent = f.seen.find((r) => r.path === "/api/agent/v3/llm_utils_chat")
|
||||||
|
expect(sent.json.reasoning_effort).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a request for a model whose levels this build can't spell goes out with no level", async () => {
|
||||||
|
// levelsOf says null for such an entry, and the fetch path reads that as
|
||||||
|
// "no level" rather than crashing on it: Trae is asked for the model and
|
||||||
|
// serves its default, as it does for one that names none
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("glm-5.3", ["ultra"])] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
// the list read first, as a host reads it before it chats: the entry is
|
||||||
|
// then known, and its levels are the unspellable null
|
||||||
|
await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const r = await opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "glm-5.3", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
expect(r.status).toBe(200)
|
||||||
|
const sent = f.seen.find((x) => x.path === "/api/agent/v3/llm_utils_chat")
|
||||||
|
expect(sent.json.reasoning_effort).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("the model list is read once for a level-less model, not on every request", async () => {
|
||||||
|
// the effort asks for levels the entry doesn't name: the first request
|
||||||
|
// reads the list to find that out, the second is answered from it
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("glm-5.3", undefined)] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const ask = () => opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "glm-5.3", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
await ask()
|
||||||
|
await ask()
|
||||||
|
const lists = f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param")
|
||||||
|
expect(lists.length).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a list that fails is read once across requests, not on every request", async () => {
|
||||||
|
// both list endpoints answer 500: the effort's read learns nothing, but that
|
||||||
|
// attempt is remembered, so the next requests don't each wait out the batch
|
||||||
|
// and per-function timeouts before the chat — which needs no list to answer
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => new Response("down", { status: 500 }))
|
||||||
|
f.route("POST /api/ide/v1/get_detail_param", () => new Response("down", { status: 500 }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const ask = () => opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "glm-5.3", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
for (let i = 0; i < 3; i++) await ask()
|
||||||
|
const lists = f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param")
|
||||||
|
expect(lists.length).toBe(1)
|
||||||
|
expect(f.seen.filter((x) => x.path === "/api/agent/v3/llm_utils_chat").length).toBe(3)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a model the list doesn't name is read for once, not on every request", async () => {
|
||||||
|
// the account still has kimi-k2.5's id after Trae dropped it from the list:
|
||||||
|
// the first effort reads the list, finds no entry, and that answer stands
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("glm-5.3", ["light", "high"])] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const ask = () => opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "kimi-k2.5", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
for (let i = 0; i < 3; i++) await ask()
|
||||||
|
const lists = f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param")
|
||||||
|
expect(lists.length).toBe(1)
|
||||||
|
const sent = f.seen.filter((x) => x.path === "/api/agent/v3/llm_utils_chat")
|
||||||
|
expect(sent.length).toBe(3)
|
||||||
|
// the model takes no level the list names, so none is sent
|
||||||
|
expect(sent[0].json.reasoning_effort).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("two parallel requests for a Max ride one list read and are both sent under its base name", async () => {
|
||||||
|
// agents send parallel requests at a session's start (a title request beside
|
||||||
|
// the first turn, subagents). The second used to skip the first one's read —
|
||||||
|
// the stamp said "tried" — so `named` stayed empty and the request went out
|
||||||
|
// under the agent's own `-max` id, which Trae's list does not name.
|
||||||
|
const max = { config_name: "deepseek-v4.1-flash", usage: "chat_completion",
|
||||||
|
display_config: { display_name: "DeepSeek V4.1 Flash" },
|
||||||
|
context_window_tokens: { dev: 200000, max: 1_000_000 },
|
||||||
|
reasoning_effort_config: { options: ["light", "high"], default_level: "high" },
|
||||||
|
model_detail_list: [{ model_name: "deepseek-v4.1-flash__dev", max_tokens: 32000 },
|
||||||
|
{ model_name: "deepseek-v4.1-flash__max", max_tokens: 64000 }] }
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", async () => {
|
||||||
|
await new Promise((r) => setTimeout(r, 100))
|
||||||
|
return json({ function_configs: [{ function: "chat_v3", config_info_list: [max] }] })
|
||||||
|
})
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const ask = () => opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "deepseek-v4.1-flash-max", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "low" }),
|
||||||
|
})
|
||||||
|
await Promise.all([ask(), ask()])
|
||||||
|
// one read served both, and neither went out under the unlisted -max id
|
||||||
|
expect(f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param").length).toBe(1)
|
||||||
|
const sent = f.seen.filter((x) => x.path === "/api/agent/v3/llm_utils_chat")
|
||||||
|
expect(sent.length).toBe(2)
|
||||||
|
for (const s of sent) {
|
||||||
|
expect(s.json.config_name).toBe("deepseek-v4.1-flash")
|
||||||
|
expect(s.json.reasoning_effort).toBe("light")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a host refresh and a request that wants levels share one list read", async () => {
|
||||||
|
// the host refreshing the catalog and a request asking for levels both want
|
||||||
|
// the list. They must ride one read: two reads would race, and the request
|
||||||
|
// could read the maps before the refresh's own read filled them.
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", async () => {
|
||||||
|
await new Promise((r) => setTimeout(r, 100))
|
||||||
|
return json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [entry("glm-5.3", ["light", "high"])] },
|
||||||
|
] })
|
||||||
|
})
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const cfg = { provider: {} }
|
||||||
|
await hooks.config(cfg)
|
||||||
|
const provider = cfg.provider["trae-cn"]
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
// a model the list doesn't name, so the request goes through the effort read
|
||||||
|
const chat = opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "not-listed-xyz", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
const listing = hooks.provider.models(provider, { auth: signedIn() })
|
||||||
|
const [, ms] = await Promise.all([chat, listing])
|
||||||
|
expect(f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param").length).toBe(1)
|
||||||
|
// and the refresh still got the list it was asking for
|
||||||
|
expect(Object.keys(ms).sort()).toEqual(["glm-5.3"])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("the level of a model's Max is its base model's", async () => {
|
||||||
|
const max = { config_name: "deepseek-v4.1-flash", usage: "chat_completion",
|
||||||
|
display_config: { display_name: "DeepSeek V4.1 Flash" },
|
||||||
|
context_window_tokens: { dev: 200000, max: 1_000_000 },
|
||||||
|
reasoning_effort_config: { options: ["light", "high"], default_level: "high" },
|
||||||
|
model_detail_list: [{ model_name: "deepseek-v4.1-flash__dev", max_tokens: 32000 },
|
||||||
|
{ model_name: "deepseek-v4.1-flash__max", max_tokens: 64000 }] }
|
||||||
|
const ms = await live([max])
|
||||||
|
expect(Object.keys(ms["deepseek-v4.1-flash-max"].variants)).toEqual(["low", "high"])
|
||||||
|
expect(effortOf(LEVELS && ["low", "high"], "low")).toBe("light")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("of two entries a model has, the one naming levels is kept, so its levels are offered", async () => {
|
||||||
|
// Trae answers one model under several functions' lists, and they needn't
|
||||||
|
// agree about its levels: the entry the plugin keeps is the one the request
|
||||||
|
// is asked through, and so the one whose reasoning_effort_config the request
|
||||||
|
// is held to. Keeping the level-less entry left the model with none to pick.
|
||||||
|
f = fakeTrae()
|
||||||
|
const shared = { config_name: "glm-5.3", usage: "chat_completion",
|
||||||
|
display_config: { display_name: "GLM-5.3" }, context_window_tokens: { dev: 200000 },
|
||||||
|
model_detail_list: [{ model_name: "glm-5.3__dev", max_tokens: 32000 }] }
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [shared] },
|
||||||
|
{ function: "solo_work_lite", config_info_list: [{ ...shared, reasoning_effort_config: { options: ["light", "high", "extra_high"], default_level: "high" } }] },
|
||||||
|
] }))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const ms = await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||||
|
expect(Object.keys(ms["glm-5.3"].variants)).toEqual(["low", "high", "xhigh"])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a name the lists agree on still outranks an entry's levels", async () => {
|
||||||
|
// the levels only break a tie: the entry Trae's own client asks through —
|
||||||
|
// the name its lists agree on, with a __dev model — is kept even when
|
||||||
|
// another entry names levels
|
||||||
|
f = fakeTrae()
|
||||||
|
const named = { config_name: "glm-5.3", usage: "chat_completion",
|
||||||
|
display_config: { display_name: "GLM-5.3" }, model_detail_list: [{ model_name: "glm-5.3__dev", max_tokens: 32000 }] }
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [named] },
|
||||||
|
{ function: "solo_work_lite", config_info_list: [named] },
|
||||||
|
// a third entry, misnamed and without a __dev model, that does name levels
|
||||||
|
{ function: "solo_agent", config_info_list: [{ ...named, display_config: { display_name: "GLM-5.3 正式版" }, model_detail_list: [], reasoning_effort_config: { options: ["light", "high"] } }] },
|
||||||
|
] }))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const ms = await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||||
|
expect(Object.keys(ms["glm-5.3"].variants)).toEqual([])
|
||||||
|
expect(ms["glm-5.3"].name).toBe("GLM-5.3")
|
||||||
|
})
|
||||||
@@ -60,7 +60,7 @@ test("the config declares the known models; the live list replaces them", async
|
|||||||
expect(live["glm-5.2"].limit.context).toBe(200000)
|
expect(live["glm-5.2"].limit.context).toBe(200000)
|
||||||
// no batch list (404 here): one function at a time
|
// no batch list (404 here): one function at a time
|
||||||
expect(f.seen[0].path).toBe("/api/ide/v1/batch_get_detail_param")
|
expect(f.seen[0].path).toBe("/api/ide/v1/batch_get_detail_param")
|
||||||
expect(f.seen.slice(1).map((r) => r.json.function).sort()).toEqual(["chat_v3", "solo_agent", "solo_agent_lite", "solo_work_lite"])
|
expect(f.seen.slice(1).map((r) => r.json.function).sort()).toEqual(["chat_v3", "solo_agent", "solo_agent_lite", "solo_coder", "solo_work_lite"])
|
||||||
})
|
})
|
||||||
|
|
||||||
// what batch_get_detail_param answered TRAE SOLO CN, cut down: each
|
// what batch_get_detail_param answered TRAE SOLO CN, cut down: each
|
||||||
@@ -92,7 +92,7 @@ test("the lists are asked in one batch, as TRAE SOLO CN asks them, and DeepSeek
|
|||||||
expect(f.seen.map((r) => r.path)).toEqual(["/api/ide/v1/batch_get_detail_param"])
|
expect(f.seen.map((r) => r.path)).toEqual(["/api/ide/v1/batch_get_detail_param"])
|
||||||
const r = f.seen[0]
|
const r = f.seen[0]
|
||||||
expect(r.json).toEqual({
|
expect(r.json).toEqual({
|
||||||
functions: ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite"], agent_type: "", current_config_info: { config_name: "", is_custom_model: false },
|
functions: ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite", "solo_coder"], agent_type: "", current_config_info: { config_name: "", is_custom_model: false },
|
||||||
mode_type: 0, access_type: 0, ab_force_vids: "", ab_autotest_advanced_mode: 0, show_custom_model: true,
|
mode_type: 0, access_type: 0, ab_force_vids: "", ab_autotest_advanced_mode: 0, show_custom_model: true,
|
||||||
})
|
})
|
||||||
expect(r.headers.get("x-ide-version")).toBe("0.1.69")
|
expect(r.headers.get("x-ide-version")).toBe("0.1.69")
|
||||||
@@ -133,6 +133,59 @@ test("signed out asking the batch marks the account", async () => {
|
|||||||
await expect(hooks.provider.models(p, { auth: signedIn() })).rejects.toThrow("sign in again")
|
await expect(hooks.provider.models(p, { auth: signedIn() })).rejects.toThrow("sign in again")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("a refresh that joins a request's failing read still hears the expiry", async () => {
|
||||||
|
// the request starts the read; the refresh arrives while it is in flight and
|
||||||
|
// rides it. The read's outcome is the record, not the bare null a failed read
|
||||||
|
// answers, so the refresh still marks the account lapsed instead of quietly
|
||||||
|
// returning the config's fallback models.
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", async () => {
|
||||||
|
await new Promise((r) => setTimeout(r, 50))
|
||||||
|
return json({ code: 1001, message: "not login" }, 401)
|
||||||
|
})
|
||||||
|
f.route("POST /api/ide/v1/get_detail_param", () => json({ code: 1001, message: "not login" }, 401))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { response: "ok" }], ["done", { finish_reason: "stop" }]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const p = await given(hooks)
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const chat = opts.fetch(opts.baseURL + "/chat/completions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: JSON.stringify({ model: "not-listed", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "high" }),
|
||||||
|
})
|
||||||
|
await new Promise((r) => setTimeout(r, 5))
|
||||||
|
const refresh = hooks.provider.models(p, { auth: signedIn() })
|
||||||
|
// attached now, not at the assertion: bun reports an expectation's rejection
|
||||||
|
// as an error between tests if it goes unclaimed for a tick
|
||||||
|
const refreshOutcome = refresh.then((m) => ({ ok: true, models: m }), (e) => ({ ok: false, error: e }))
|
||||||
|
// the request answers through its own path, and the refresh marks the lapse
|
||||||
|
await expect(chat).resolves.toBeDefined()
|
||||||
|
const outcome = await refreshOutcome
|
||||||
|
expect(outcome.ok).toBe(false)
|
||||||
|
expect(outcome.error.message).toContain("sign in again")
|
||||||
|
expect(f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param").length).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a re-sign-in is not held to the cached expiry: the host's refresh reads again", async () => {
|
||||||
|
// the host's refresh is strict, so a cached lapse is read again for rather
|
||||||
|
// than replayed for the rest of the window: signing in again is exactly the
|
||||||
|
// case that must not be stuck with the old lapse
|
||||||
|
f = fakeTrae()
|
||||||
|
let lapsed = true
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => lapsed
|
||||||
|
? json({ code: 1001, message: "not login" }, 401)
|
||||||
|
: json({ function_configs: [{ function: "chat_v3", config_info_list: [
|
||||||
|
{ config_name: "glm-5.3", usage: "chat_completion", display_config: { display_name: "GLM-5.3" },
|
||||||
|
model_detail_list: [{ model_name: "glm-5.3__dev", max_tokens: 32000 }] }] }] }))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const p = await given(hooks)
|
||||||
|
await expect(hooks.provider.models(p, { auth: signedIn() })).rejects.toThrow("sign in again")
|
||||||
|
lapsed = false
|
||||||
|
const ms = await hooks.provider.models(p, { auth: signedIn({ access: "jwt-2", refresh: "r-2" }) })
|
||||||
|
expect(Object.keys(ms)).toContain("glm-5.3")
|
||||||
|
expect(f.seen.filter((x) => x.path === "/api/ide/v1/batch_get_detail_param").length).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
test("SOLO's and the TRAE agent's models are listed too, and asked through the function that lists them (yetone/magpie#681)", async () => {
|
test("SOLO's and the TRAE agent's models are listed too, and asked through the function that lists them (yetone/magpie#681)", async () => {
|
||||||
f = fakeTrae()
|
f = fakeTrae()
|
||||||
const lists = {
|
const lists = {
|
||||||
@@ -158,6 +211,32 @@ test("SOLO's and the TRAE agent's models are listed too, and asked through the f
|
|||||||
expect(await ask("glm-5.2")).toBe("chat_v3")
|
expect(await ask("glm-5.2")).toBe("chat_v3")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("solo_coder's models are listed, and asked through solo_coder", async () => {
|
||||||
|
// SOLO's coder roster is the only one listing these: no other chat
|
||||||
|
// function the plugin reads names them, so a model left out of it was
|
||||||
|
// absent from the account's list altogether
|
||||||
|
f = fakeTrae()
|
||||||
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||||
|
{ function: "chat_v3", config_info_list: [{ config_name: "glm-5.3", usage: "chat_completion", display_config: { display_name: "GLM-5.3" } }] },
|
||||||
|
{ function: "solo_coder", config_info_list: [
|
||||||
|
{ config_name: "glm-5v-turbo", usage: "chat_completion", display_config: { display_name: "GLM-5V-Turbo" }, model_detail_list: [{ model_name: "glm-5v-turbo__dev", max_tokens: 32000 }] },
|
||||||
|
{ config_name: "qwen-3.6-plus", usage: "chat_completion", display_config: { display_name: "Qwen3.6-Plus" }, model_detail_list: [{ model_name: "qwen-3.6-plus__dev", max_tokens: 32000 }] },
|
||||||
|
] },
|
||||||
|
] }))
|
||||||
|
f.route("POST /api/agent/v3/llm_utils_chat", (r) => sse([["output", { response: r.json.function }], ["done", {}]]))
|
||||||
|
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||||
|
const p = await given(hooks)
|
||||||
|
const live = await hooks.provider.models(p, { auth: signedIn() })
|
||||||
|
expect(Object.keys(live)).toEqual(["glm-5.3", "glm-5v-turbo", "qwen-3.6-plus"])
|
||||||
|
const opts = await hooks.auth.loader(async () => signedIn())
|
||||||
|
const ask = async (model) => {
|
||||||
|
const res = await opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify({ model, messages: [{ role: "user", content: "hi" }] }) })
|
||||||
|
return (await res.json()).choices[0].message.content
|
||||||
|
}
|
||||||
|
expect(await ask("glm-5v-turbo")).toBe("solo_coder")
|
||||||
|
expect(await ask("qwen-3.6-plus")).toBe("solo_coder")
|
||||||
|
})
|
||||||
|
|
||||||
test("one function's list failing leaves the other's", async () => {
|
test("one function's list failing leaves the other's", async () => {
|
||||||
f = fakeTrae()
|
f = fakeTrae()
|
||||||
f.route("POST /api/ide/v1/get_detail_param", (r) => r.json.function === "chat_v3"
|
f.route("POST /api/ide/v1/get_detail_param", (r) => r.json.function === "chat_v3"
|
||||||
|
|||||||
Reference in New Issue
Block a user