Repository navigation
feat(ask): AIChat SDK — programmatic LLM chat with session management - #58
Conversation
|
@coderabbitai review |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (21)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Actions performedReview triggered.
|
Summary of ChangesHello @genesiscz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a foundational Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a well-designed AIChat SDK, which is a fantastic abstraction for programmatic LLM interaction and session management. The refactoring of the CLI and Telegram bot to use this new SDK is a significant improvement, particularly the fix for the stdout leakage in the Telegram integration. The new library components are thoughtfully created and come with a good set of tests.
My review includes a few points for consideration:
- A high-severity issue regarding the streaming implementation in
AIChat, which currently buffers the entire response instead of streaming text chunks. This could be misleading for SDK consumers. - A couple of medium-severity suggestions to improve code safety by removing non-null assertions.
Overall, this is a very strong contribution that builds a solid foundation for using the AI capabilities programmatically.
There was a problem hiding this comment.
Pull request overview
This PR introduces AIChat, a programmatic SDK for LLM chat with session management, extracting core functionality from the ask CLI tool. It addresses stdout leakage issues in the telegram bot by replacing subprocess-based tool invocation with direct in-process API calls using AIChat with silent logging.
Changes:
- New AIChat SDK providing provider-agnostic LLM chat with automatic session persistence
- Telegram integration refactored to use AIChat instances (one per contact) with persistent sessions
- CLI single-message mode refactored to use AIChat, eliminating stdout monkey-patching
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/telegram/lib/actions/ask.ts |
Replaced subprocess runTool() with cached AIChat instances per contact, enabling silent mode to fix stdout leakage |
src/ask/lib/types.ts |
New TypeScript interfaces for AIChat, session entries, events, and configuration options |
src/ask/lib/__tests__/*.test.ts |
Unit tests for ChatEvent, ChatLog, ChatSession, ChatSessionManager, and ChatTurn (40 tests) |
src/ask/lib/ChatTurn.ts |
Dual PromiseLike/AsyncIterable class for streaming or buffered LLM responses |
src/ask/lib/ChatSessionManager.ts |
JSONL-based session persistence with create, save, load, list, and delete operations |
src/ask/lib/ChatSession.ts |
In-memory session data management with history filtering, export, and statistics |
src/ask/lib/ChatLog.ts |
Internal log capture with cursor-based unseen tracking, never writes to stdout |
src/ask/lib/ChatEvent.ts |
Event types with type guards for text, thinking, tool calls, and completion |
src/ask/AIChat.ts |
Main SDK class with provider resolution, session management, and message sending |
src/ask/index.ts |
CLI refactored to use AIChat in both raw and streaming modes |
src/ask/index.lib.ts |
Barrel export for programmatic SDK usage |
src/ask/chat/ChatEngine.ts |
Added callback support for onChunk and onThinking to prevent stdout writes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix duplicate API calls when ChatTurn is awaited then iterated - Implement true streaming via ReadableStream bridge - Remove non-null assertions in getProviders/getModels - Add sessionId validation to prevent path traversal - Add conflict detection for resume + session.id - Fix telegram config-change detection with cache key - Fix telegram history injection to use session context - Document system prompt rebuild and engine mutation behavior
|
@coderabbitai review |
|
/gemini review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and well-structured AIChat SDK for programmatic LLM interaction, which is a great improvement. The refactoring successfully removes the stdout monkey-patching in the CLI and the subprocess execution in the Telegram tool, enhancing robustness and maintainability. The new components like ChatTurn, ChatSession, and ChatEvent provide a clean and powerful API. I've identified a few issues, primarily related to context handling, an ineffective override, and some areas for performance and correctness improvements. Addressing these will make the new SDK even more solid.
_getEngine now snapshots config before applying overrides and restores it in a finally block, preventing state leakage across send() calls.
Root README now covers every user-facing src/* tool. Added 33 new Tool Details entries (#26–#58) and three new category sections (macOS & System, Productivity & Automation, Shell & Infrastructure) for tools that don't fit the existing categories. Wrote fresh per-tool READMEs for the 31 tools that lacked one, using the same robust style as src/watch/, src/ask/, src/azure-devops/ (badge row, tagline, feature table, quick-start, options table, scenario-driven examples). Every tool that calls handleReadmeFlag(import.meta.url) now renders real docs via `tools <name> --readme`. Skipped: `t3chat-length` (self-declared @internal), and tools that already had both a root entry and a per-tool README (watch, har-analyzer, ask, automate, azure-devops, mcp-manager, etc.). Bump to 1.0.26.
Add 31 per-tool READMEs using the same robust template as src/watch/, src/ask/, src/azure-devops/ (badge row, tagline, feature table, quick-start, options, scenario examples). Every tool that calls handleReadmeFlag() now renders real docs via \`tools <name> --readme\`. Root README gains 33 Tool Details entries (#26-#58) and three new category sections (macOS & System, Productivity & Automation, Shell & Infrastructure) for tools that didn't fit the existing buckets. Also add the external skill workspace pulled in by the plugin runtime (.agents/, .claude/skills/, skills-lock.json). Plugin version bumped to 1.0.26.
Add 31 per-tool READMEs using the same robust template as src/watch/, src/ask/, src/azure-devops/ (badge row, tagline, feature table, quick-start, options, scenario examples). Every tool that calls handleReadmeFlag() now renders real docs via \`tools <name> --readme\`. Root README gains 33 Tool Details entries (#26-#58) and three new category sections (macOS & System, Productivity & Automation, Shell & Infrastructure) for tools that didn't fit the existing buckets. Also add the external skill workspace pulled in by the plugin runtime (.agents/, .claude/skills/, skills-lock.json). Plugin version bumped to 1.0.26.
Summary
AIChat— a programmatic, provider-agnostic LLM chat classrunTool()with in-processAIChat({ logLevel: "silent" })process.stdout.writemonkey-patch hack)New Components
src/ask/AIChat.tssend(),stream(), static discovery methodssrc/ask/lib/types.tsAIChatOptions,SendOptions,ChatResponse,SessionEntry, etc.)src/ask/lib/ChatEvent.ts.isText(),.isDone(), etc.) and factoriessrc/ask/lib/ChatTurn.tsPromiseLike<ChatResponse>+AsyncIterable<ChatEvent>— await or streamsrc/ask/lib/ChatLog.tsgetUnseen()— never writes to stdoutsrc/ask/lib/ChatSession.tsadd(),getHistory(),toMessages(), filtering, exportsrc/ask/lib/ChatSessionManager.tscreate(),save(),load(),list(),delete()src/ask/index.lib.tsUsage
Test plan
tools ask -p openai -m gpt-4o-mini --raw "hello"— only response on stdouttools telegram listen— verify no log leakage in responses