Skip to content

feat(agent): chat panel to edit selected demo via LiteLLM#23

Open
shimoncohen wants to merge 12 commits into
mainfrom
worktree-feat+agent-chat-edit
Open

feat(agent): chat panel to edit selected demo via LiteLLM#23
shimoncohen wants to merge 12 commits into
mainfrom
worktree-feat+agent-chat-edit

Conversation

@shimoncohen

Copy link
Copy Markdown
Contributor

Summary

  • Add a persistent left-side chat panel on the demo page that lets a user ask an LLM agent (via a LiteLLM proxy) to edit the currently-selected demo's files.
  • Pure, stateless server module agentClient.ts runs an OpenAI-compatible tool-call loop (write_file / edit_file) against LiteLLM, mutating only the in-memory files[] from the request. No server-side filesystem writes.
  • Two thin routes: POST /api/agent (run agent) and GET /api/agent/models (proxy the model list). LiteLLM key/base URL stay server-side.
  • agentChat.svelte posts to the route and hands edited files back to the demo page, which live-updates Flems and persists via the existing localStorage demoCache (so "Clear cache" reverts agent edits too). Chat history is in-memory only.
  • Model picker lists all models the proxy advertises; default from AGENT_MODEL.
  • New env vars documented in .env.example: LITELLM_BASE_URL, LITELLM_API_KEY, AGENT_MODEL.

Test Plan

  • npm test — 43 passed (15 new: applyTool, runAgent, fetchModels, agentChat)
  • npm run check — 0 errors, 0 warnings
  • Prettier + eslint clean on new files
  • Manual: set LiteLLM env vars, open a demo, pick a model, ask the agent to edit — verify Flems live-updates and edits persist across reload until "Clear cache"

🤖 Generated with Claude Code

@shimoncohen shimoncohen self-assigned this Jul 22, 2026
shimoncohen and others added 9 commits July 22, 2026 13:30
- gate /api/agent + /models behind AGENT_ENABLED and a same-origin check
  (assertAgentAccess); hide chat panel unless enabled via data.agentEnabled
- rebuild the system prompt each tool iteration so its file list stays current
- return an explicit reply when the iteration limit is hit
- log agent/model errors server-side, return a generic message to clients
- avoid an empty assistant bubble when the reply is blank

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shimoncohen
shimoncohen force-pushed the worktree-feat+agent-chat-edit branch from a51afa0 to 5e03203 Compare July 22, 2026 10:34
shimoncohen and others added 3 commits July 22, 2026 16:19
…ution

Flems (CodeMirror) mutates the file objects it receives, attaching
circular editor state that breaks JSON.stringify for consumers sharing
the same array (e.g. the agent panel). Pass fresh {name, content} copies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Missing min-h-0 on the flex chain let content expand past the viewport,
scrolling the whole page. Bound the demo layout slot wrapper and the
chat message list so overflow scrolls inside the panel.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lift the chat thread to a controlled prop so the demo page owns it,
caching it in localStorage under a per-example key (demo-chat:v1). On
reload or when switching examples the thread restores for that specific
example; clearing the cache wipes files and chat together.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant