Commit graph

170 commits

Author SHA1 Message Date
Alishahryar1
7259b1def8 Optimized code in hot paths with z-ai/glm5 2026-02-14 19:59:46 -08:00
Alishahryar1
710e532888 lint 2026-02-14 19:17:51 -08:00
Alishahryar1
9be9943401 Improved test coverage 2026-02-14 19:17:19 -08:00
Alishahryar1
96747f2216 Updated token counting and removed non streaming support 2026-02-14 19:10:09 -08:00
Alishahryar1
ba344f26c9 Revamped logging 2026-02-14 18:55:33 -08:00
Alishahryar1
64e5b10612 Refactor done by z-ai/glm5 2026-02-14 18:47:26 -08:00
Cursor Agent
b5e95849e3 Apply ruff format
Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:29:03 +00:00
Cursor Agent
1cface7f8c Fix all ty check errors without using type: ignore
- messaging/telegram.py: Remove unused type: ignore, fix retry_after typing
  with isinstance(timedelta), use local app variable for None narrowing
- messaging/tree_data.py: Replace _queue._queue access with drain-and-restore
  approach for get_queue_snapshot (avoids private API)
- tests/test_api.py: Use APIError instead of RuntimeError for status_code test
- tests/test_config.py: Use cast(Any, ...) for invalid validation tests
- tests/test_dependencies.py: Add isinstance check for NvidiaNimProvider
- tests/test_handler_markdown_and_status_edges.py: Use patch.object for
  tree_queue method mocks
- tests/test_response_models.py: Add isinstance narrowing for content blocks,
  use Literal list for stop_reason parametrization
- tests/test_restart_reply_restore.py: Use patch.object for enqueue mock
- tests/test_server_module.py: Use patch.object for uvicorn.run and
  get_settings
- tests/test_telegram_edge_cases.py: Use patch.object for method mocks
- tests/test_tree_concurrency.py: Add None assertions for get_node/get_tree

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:28:33 +00:00
Cursor Agent
ec71a2232c fix: preserve interleaved thinking, tool calls, and text in Anthropic↔NIM conversion
- Assistant messages: build content string in block order (thinking+text interleaved)
- User messages: emit text before tool results when order is text→tool_result
- Response: add extract_think_content_interleaved() to preserve <think>...</think> order
- Add tests and docs for context preservation bugs

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 02:08:35 +00:00
Alishahryar1
25b9d9d1e4 Added ruff and ty dependencies and lint 2026-02-14 18:00:21 -08:00
Cursor Agent
25c7123e33 Phase 7 & 8: Routes optimization refactor and request utils split
Phase 7 - Optimization handlers:
- Create api/optimization_handlers.py with try_prefix_detection,
  try_quota_mock, try_title_skip, try_suggestion_skip, try_filepath_mock
- Add try_optimizations() that runs handlers in order
- Refactor routes.create_message to use try_optimizations()
- Update test_routes_optimizations patch targets

Phase 8 - Request utils split:
- Create api/detection.py: is_quota_check_request, is_title_generation_request,
  is_prefix_detection_request, is_suggestion_mode_request,
  is_filepath_extraction_request
- Create api/command_utils.py: extract_command_prefix, extract_filepaths_from_command
- Slim request_utils.py to get_token_count + re-exports for backward compat

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:41:35 +00:00
Cursor Agent
0bab393c05 Phase 6: Remove dynamic attribute creation in NIM client
ContentBlockManager already declares task_arg_buffer, task_args_emitted,
tool_ids. Remove defensive getattr/isinstance checks from _process_tool_call
and _flush_task_arg_buffers.

Update test_subagent_interception to set task_arg_buffer, task_args_emitted,
tool_ids on mock so it behaves like real ContentBlockManager.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:39:43 +00:00
Cursor Agent
959d1bdf5b Phase 5: Encapsulation - Repository and MessageTree API
TreeRepository:
- Add has_node(node_id) -> bool
- Add tree_count() -> int

MessageTree:
- Add cancel_current_task() -> bool
- Add drain_queue_and_mark_cancelled() -> List[MessageNode]
- Add reset_processing_state()
- Add current_node_id property

TreeQueueManager:
- Remove _trees and _node_to_tree properties
- add_to_tree: use has_node() and get_tree_for_node()
- get_tree_count: use repository.tree_count()
- cancel_tree: use tree.cancel_current_task(), drain_queue_and_mark_cancelled(), reset_processing_state()

TreeQueueProcessor:
- cancel_current: delegate to tree.cancel_current_task()

Tests: update to use get_tree_count(), has_node(), get_tree_for_node()

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:38:35 +00:00
Cursor Agent
7496f67ae0 Phase 2: Extract markdown utilities to messaging/telegram_markdown.py
- Create messaging/telegram_markdown.py with all MarkdownV2 helpers
- Move escape_md_v2, escape_md_v2_code, escape_md_v2_link_url, mdv2_bold,
  mdv2_code_inline, format_status, render_markdown_to_mdv2
- Update handler.py to import from telegram_markdown (~300 lines removed)
- Update telegram.py to use shared escape_md_v2 (remove duplicate)
- Update tests to import from messaging.telegram_markdown

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:34:27 +00:00
Cursor Agent
f80c7ce42e Remove _extract_text_from_content wrapper from logging_utils
Thin wrapper only used in tests. Tests now import extract_text_from_content
directly from utils.text.

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
2026-02-15 01:32:04 +00:00
Alishahryar1
42a833245f Removed all signal handler logic 2026-02-14 17:17:58 -08:00
Alishahryar1
bd1e097d74 fixed tool parser and added signal handlers 2026-02-14 04:25:12 -08:00
Alishahryar1
4b95429c32 fixed NIM_INTERCEPT for chunked tool calls 2026-02-14 03:25:32 -08:00
Alishahryar1
d2e6e52742 Subagent summarized display 2026-02-14 03:13:59 -08:00
Alishahryar1
6887de9cab added more tests for parser and made it more robust 2026-02-14 02:49:21 -08:00
Alishahryar1
4247f411b0 Fixed truncation errors in telegram and added subagent display 2026-02-14 02:41:48 -08:00
Alishahryar1
b95f2ef9c4 Revamped telegram result display 2026-02-14 02:14:36 -08:00
Alishahryar1
85eed8a1bc updated heuristic tool parser for orphaned toolcall tags 2026-02-14 00:16:54 -08:00
Alishahryar1
89edeaa6ac Migrated telegram rate limiter to sliding window 2026-02-13 22:12:33 -08:00
Alishahryar1
665e24e2db Migrated from token bucket rate limiter to sliding window rate limiter 2026-02-13 19:05:16 -08:00
Alishahryar1
fab66edcd3 Fixed rate limiting issues 2026-02-13 17:40:19 -08:00
Alishahryar1
fabca59f5c lint 2026-02-13 17:24:18 -08:00
Alishahryar1
98966fe688 fixed table rendering v2 2026-02-13 16:57:14 -08:00
Alishahryar1
28a56d3af8 fixed table rendering for telegram 2026-02-13 16:31:46 -08:00
Alishahryar1
4ee0114891 Implemented /clear command 2026-02-13 16:24:52 -08:00
Alishahryar1
459ce6e8fd introduced per reply /stop command to stop just that task and fixed context leakage in reply session forking 2026-02-13 14:53:48 -08:00
Alishahryar1
de7677ba6c added graceful shutdown 2026-02-13 13:40:49 -08:00
Alishahryar1
42bfb2da9b improve test coverage 2026-02-13 12:54:48 -08:00
Alishahryar1
ae38c9ffde lint 2026-02-08 15:54:03 -08:00
Alishahryar1
9826d71ff1 Added new tests 2026-02-08 15:27:33 -08:00
Alishahryar1
697bc37faf Upon dequeue the current request immediately displays processing state instead of position 1 waiting 2026-02-08 04:06:41 -08:00
Alishahryar1
6d8f13d84e Added feature to update queue positions on telegram when messages are dequeued and added new tests 2026-02-08 04:00:58 -08:00
Alishahryar1
3a69a51f62 fixed markdown errors for telegram 2026-02-05 17:22:00 -08:00
Alishahryar1
6102583026 Major Refactor Part 2 with kimi-k2.5 in claude code 2026-02-05 16:09:16 -08:00
Alishahryar1
fcbe204f44 Major refactor done with kimi-k2.5 in claude code 2026-02-05 10:51:33 -08:00
Alishahryar1
58f556f8bd Fixed orphan </think> tags 2026-02-03 22:04:06 -08:00
Alishahryar1
707e8aec2b fixed subagents 2026-01-31 15:57:37 -08:00
Alishahryar1
8ce86f4267 fixed type errors 2026-01-31 14:13:09 -08:00
Alishahryar1
7c54008a95 migrated from httpx client to openai client 2026-01-31 12:45:15 -08:00
Alishahryar1
3acabcb8e0 add new template kwargs and fixed linter errors 2026-01-31 00:03:21 -08:00
Alishahryar1
303767e346 fixed linter errors 2026-01-30 23:32:02 -08:00
Alishahryar1
43a0786fc1 added more messaging and cli tests 2026-01-30 18:34:12 -08:00
Alishahryar1
cd911eb62c added converter tests 2026-01-30 18:28:46 -08:00
Alishahryar1
d9c5047535 added extra body chat template kwargs for deepseek 2026-01-30 17:21:56 -08:00
Alishahryar1
5bc978c545 Implemented fixes using test case errors 2026-01-30 17:11:35 -08:00