Features
New Chat Button Integration
Documentation for the New Chat Button feature and context window management.
New Chat Button Integration (Context Window Threshold)
This guide documents the New Chat Button feature that appears when a conversation approaches the context window limit.
Overview
- Shows a "New Chat" button when recent token usage reaches 85% of the allowed context window.
- Clicking the button immediately triggers a new task by calling the service with the
/newtaskcommand. - The button is rendered beneath the chat input only when the threshold is met.
Files Added
webview-ui/src/utils/contextWindowUtils.ts- Provides
getContextWindowThresholds(contextWindow); currently returns the full window.
- Provides
webview-ui/src/hooks/useContextWindowStatus.ts- Computes
shouldShowNewChatButton,usagePercentage, andisNearCapacityfromlastApiReqTotalTokensand the modelcontextWindow.
- Computes
webview-ui/src/components/chat/NewChatButton.tsx- UI for the usage text and gradient "New Chat" button.
- On click:
TaskServiceClient.newTask(NewTaskRequest.create({ text: "/newtask", images: [], files: [] })).
Files Updated
webview-ui/src/components/chat/ChatView.tsx- Imports the hook and button, computes
contextWindowfromselectedModelInfo, and renders the button below the input whenshouldShowNewChatButtonis true.
- Imports the hook and button, computes
How It Works
ChatView.tsxderives:lastApiReqTotalTokensfrom the latestapi_req_startedmessage.contextWindowvianormalizeApiConfiguration(...).selectedModelInfo.
useContextWindowStatus(lastApiReqTotalTokens, contextWindow)returns:shouldShowNewChatButton: true whenlastApiReqTotalTokens >= 0.85 * maxAllowedSize.usagePercentage:(lastApiReqTotalTokens / contextWindow) * 100.isNearCapacity: true whenlastApiReqTotalTokens >= maxAllowedSize.
- When
shouldShowNewChatButtonis true,ChatViewrendersNewChatButtonunder the input. - Clicking
NewChatButtonimmediately invokesTaskServiceClient.newTaskwith/newtask.
Configuration
- Headroom logic lives in
getContextWindowThresholds(contextWindow).- Default:
maxAllowedSize = contextWindow. - To add headroom, change to e.g.
Math.floor(contextWindow * 0.95).
- Default:
- Display threshold is fixed at 85% of
maxAllowedSizeinside the hook.
Usage
No user settings required. The button appears automatically as context usage approaches the configured threshold.
Getting Started Workflow (New Users)
- Open Sypha chat and start a conversation normally.
- Watch the usage indicator; when near limit, a “New Chat” button appears.
- Click “New Chat” to spawn a fresh task (internally sends
/newtask). - Continue in the new chat to keep context small and focused.
Testing
- Start a chat and generate API requests (send messages, run tools) until usage approaches 85%.
- Verify the button appears beneath the input when the threshold is reached.
- Click the button and confirm a new task is created (service call) and the UI reflects the new task/session.
Troubleshooting
- Button doesn’t appear:
- Ensure at least one API request has non-zero tokens in the current session.
- Confirm the selected model has a valid
contextWindow.
- Button click does nothing:
- Check the console for errors from
TaskServiceClient.newTask. - Verify generated proto types and
@/services/grpc-clientare available.
- Check the console for errors from
Related
docs/SyphaFeature/Prompt-Enhancer-Integration.mddocs/SyphaFeature/Mermaid-Diagram-Integration.md