fix: read session/message lists from OpenAI-list data shape - #20
Open
coolswood wants to merge 1 commit into
Open
fix: read session/message lists from OpenAI-list data shape#20coolswood wants to merge 1 commit into
data shape#20coolswood wants to merge 1 commit into
Conversation
) 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).