fix: read session/message lists from OpenAI-list data shape - #20
fix: read session/message lists from OpenAI-list data shape#20coolswood wants to merge 1 commit into
data shape#20Conversation
) listSessions() and getMessages() in src/server/hermes-api.ts read resp.items, but the Hermes gateway (v0.18/0.20) returns the OpenAI-list shape { object: "list", data: [...] } for sessions and { object: "list", session_id, data: [...] } for messages. So resp.items was undefined and the session history rendered empty on page reload while the data stayed intact in the gateway database. The same .items assumption in src/routes/api/context-usage.ts zeroed out the context-usage estimate for sessions without cache_read_tokens. Adds a small extractList() helper that returns the first array it finds across items | data | messages | results (and the payload itself when it is already an array), mirroring what fetchHermesModels in src/routes/api/models.ts already does (payload.data ?? payload.models). This stays compatible if the gateway ever changes the list key again. Note: getSession/createSession/updateSession read resp.session and the gateway does return { session: {...} } for those single-resource endpoints, so only the list endpoints are affected. Closes JPeetz#18
|
@coolswood is attempting to deploy a commit to the Joerg Peetz's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Verified independently: gateway v0.18+/v0.20 returns the OpenAI list shape (object: "list", data: [...]) on /api/sessions and /api/sessions/{id}/messages, so the .items reads render empty history. We ported this onto our fork (lightcloud00/Hermes-Studio#1) as data ?? items ?? [] to keep older gateways working — typecheck, unit tests, and build green. LGTM. |
|
Confirmed against Hermes Agent v0.20: the gateway returns the OpenAI-list shape and this extractList() approach restores session/message history correctly — arguably cleaner than the inline variant we verified in our fork (lightcloud00/Hermes-Studio#4). Fixes #18 as described; +1 to merge. |
Summary
Fixes #18.
listSessions()andgetMessages()insrc/server/hermes-api.tsreadresp.items, but the Hermes gateway (v0.18/0.20) returns the OpenAI-list shape:So
resp.itemswasundefined, the session history rendered empty on page reload, and message history never loaded — even though the data stayed intact in the gateway database. The same.itemsassumption insrc/routes/api/context-usage.ts(~lines 95 and 161) zeroed out the context-usage estimate for sessions withoutcache_read_tokens.This is the same class of bug as the closed issue #5 (closed without a fix landing in
main).Changes
Adds a small
extractList()helper that returns the first array it finds acrossitems | data | messages | results(and the payload itself when it is already an array), then uses it inlistSessions()andgetMessages().context-usage.tsdoes the same resilient lookup inline in its two spots. This mirrors whatfetchHermesModelsinsrc/routes/api/models.tsalready does (payload.data ?? payload.models) and stays compatible if the gateway ever changes the list key again.src/server/hermes-api.ts—extractList()helper +listSessions/getMessagesuse itsrc/routes/api/context-usage.ts— resilient list lookup (2 spots)Note
getSession/createSession/updateSessionreadresp.session, and the gateway does return{ session: {...} }for those single-resource endpoints — so only the list endpoints are affected. The single-object shape is correct and left untouched.Verification
Against Hermes Agent v0.20.0 with a populated session DB:
GET /api/sessions{ source: "gateway", sessions: [] }(0){ source: "gateway", sessions: [...] }(8)npx tsc --noEmit: no new errors (the 4 pre-existing errors onmainare unrelated — the missingremark-math/rehype-katexdeps and two untouched files)npx vitest run: 190/190 tests pass (includingoperations-aggregator.test, which mockslistSessions— the call signature is unchanged)prettier --check: passes on both changed filesRelated: #19 (separate bug — proxy routes missing
Authorization).