Repository navigation
feat: streamed usage on finish chunk and pageUrl skill arming in sessions - #125
Merged
Merged
Conversation
The browser runs memory extraction over streaming /v1/chat/completions, and the stream never carried usage: the JSON body mapped it, the finish chunk did not. Memory runs therefore recorded 0 tokens. The finish chunk now carries `usage` in the same OpenAI shape the JSON body uses (one shared mapping), falling back to the last step-finish usage when the provider reports only per step. ChatCompletionChunk already declared `usage`, so the contract and SDK are unchanged.
Agent sessions armed skills by keywords only; the URL half waited for a tab URL the engine did not hold. The session prompt body now takes an optional `pageUrl`, stored on the user message, and the loop passes it to SystemPrompt.armedSkills -- the same SkillArming.arm the chat-completions route runs on `redrob_context.page_url`. The prompt body and UserMessage schemas gained an optional field, so the generated SDK clients need `bun run generate` before a caller can send it typed.
Only the pageUrl hunks are taken. A full regeneration also pulls in channel and bridged-app types that develop has not regenerated yet, and those collide with names src/v2/client.ts already exports.
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.
What's done
/v1/chat/completionsstreaming: the finish chunk now carriesusagein the same OpenAI shape as the JSON body (one sharedtoWireUsage). If the provider reports usage only per step, the laststep-finishusage is used. Before this, streamed callers (browser memory runs) recorded 0 tokens.pageUrl. It is stored on the user message (UserMessage.pageUrl) and passed toarmedSkillsasurl, so skills withurls:globs arm in agent sessions the same way they do onredrob_context.page_url.pageUrlhunks are committed.packages/clientandpackages/redrob/schemaregenerate with no diff.docs/LOCAL-ENGINE-API.md: documentspageUrl.What's not done
src/v2/genis already behind (channel and bridged-app types), and regenerating it fully breakstscbecauseBridgedApp/BridgedAppListclash with namessrc/v2/client.tsalready exports. That is its own fix.What to review
toChunksinpackages/server/src/handlers/chat-completion.ts: when the finish event has no usage, the last step-finish usage stands in.packages/redrob/src/session/prompt.ts:pageUrlis trimmed and stored only when it is not empty, and arming reads it fromlastUser.Intentions
Local gate (bun 1.3.14): frozen install, typecheck, test:httpapi, core tests, engine tests (3506 pass, 0 fail) all exit 0.