Skip to content

Commit 3e6438d

Browse files
3coinsdlqqq
andauthored
Update refresh-persona slash command handling (#5)
* Updates related to router slash commands * lint * bump jupyter_ai_router dependency version floor --------- Co-authored-by: David L. Qiu <[email protected]>
1 parent 71dc5a1 commit 3e6438d

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

CLAUDE.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Project Overview
66

77
This is a JupyterLab extension package that provides default chat commands for Jupyter AI. It consists of:
8+
89
- A Python server extension (`jupyter_ai_chat_commands`)
910
- A TypeScript frontend extension (`@jupyter-ai/chat-commands`)
1011

1112
The extension currently provides two chat commands:
13+
1214
- `@file:<path>`: Add a file as an attachment to a message
1315
- `/refresh-personas`: Reload local personas defined in `.jupyter/personas`
1416

1517
## Development Setup
1618

1719
Initial setup requires micromamba/conda and Node.js 22:
20+
1821
```bash
1922
micromamba install uv jupyterlab nodejs=22
2023
jlpm
@@ -26,51 +29,60 @@ The `dev:install` script handles the complete development setup including buildi
2629
## Common Commands
2730

2831
### Building
32+
2933
- `jlpm build` - Build both TypeScript and labextension for development
3034
- `jlpm build:prod` - Production build with optimization
3135
- `jlpm build:lib` - Build TypeScript source with source maps
3236
- `jlpm build:labextension` - Build the JupyterLab extension
3337

3438
### Development Workflow
39+
3540
- `jlpm watch` - Watch mode for development (runs both TypeScript and labextension watch)
3641
- `jupyter lab` - Start JupyterLab (run in separate terminal alongside watch)
3742

3843
### Linting and Testing
44+
3945
- `jlpm lint` - Run all linters (stylelint, prettier, eslint)
4046
- `jlpm lint:check` - Check without fixing
4147
- `jlpm test` - Run Jest tests with coverage
4248
- `pytest -vv -r ap --cov jupyter_ai_chat_commands` - Run Python server tests
4349

4450
### Extension Management
51+
4552
- `jlpm dev:uninstall` - Remove development extension
4653
- `jupyter server extension list` - Check server extension status
4754
- `jupyter labextension list` - Check frontend extension status
4855

4956
## Architecture
5057

5158
### Frontend (TypeScript)
59+
5260
- Entry point: `src/index.ts` - exports main plugin and chat command plugins
5361
- Chat commands: `src/chat-command-plugins/` contains individual command implementations
5462
- Uses JupyterLab 4.x plugin system and `@jupyter/chat` for chat integration
5563

5664
### Backend (Python)
65+
5766
- Server extension: `jupyter_ai_chat_commands/extension_app.py`
5867
- Request handlers: `jupyter_ai_chat_commands/handlers.py`
5968
- Depends on `jupyterlab_chat`, `jupyter_ai_router`, and `jupyter_ai_persona_manager`
6069

6170
### Key Dependencies
71+
6272
- Frontend: `@jupyter/chat`, `@jupyterlab/application`, Material-UI icons
6373
- Backend: `jupyter_server`, `jupyterlab_chat`, `jupyter_ai_router`
6474

6575
## Code Style
76+
6677
- TypeScript: ESLint with TypeScript rules, Prettier formatting, single quotes
6778
- Interface naming: Must start with 'I' and use PascalCase
6879
- CSS: Stylelint with standard config
6980
- Python: No specific linter configured (follows standard Python conventions)
7081

7182
## Testing
83+
7284
- Frontend: Jest with coverage reporting
7385
- Backend: Pytest with pytest-asyncio for server testing
7486
- Integration: Playwright tests in `ui-tests/` (currently skipped)
7587

76-
Note: Integration tests are currently disabled - see recent commit "skip integration tests for now".
88+
Note: Integration tests are currently disabled - see recent commit "skip integration tests for now".

jupyter_ai_chat_commands/extension_app.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,11 @@ async def initialize_async(self):
4040
router.observe_chat_init(lambda room_id, ychat: self.on_chat_init(router, room_id))
4141

4242
def on_chat_init(self, router: MessageRouter, room_id: str):
43-
router.observe_slash_cmd_msg(room_id, self.on_slash_command)
43+
router.observe_slash_cmd_msg(room_id, "refresh-personas", self.on_slash_command)
4444
self.log.info("Attached router observer.")
4545

46-
def on_slash_command(self, room_id: str, message: Message):
47-
first_word = get_first_word(message.body)
48-
assert first_word and first_word.startswith("/")
49-
50-
command_id = first_word[1:]
51-
if command_id == "refresh-personas":
52-
self.event_loop.create_task(self.handle_refresh_personas(room_id))
53-
return True
54-
55-
# If command is unrecognized, log an error
56-
self.log.warning(f"Unrecognized slash command: '/{command_id}'")
57-
return False
46+
def on_slash_command(self, room_id: str, command: str, message: Message):
47+
self.event_loop.create_task(self.handle_refresh_personas(room_id))
5848

5949
async def handle_refresh_personas(self, room_id: str):
6050
self.log.info(f"Received /refresh-personas in room '{room_id}'.")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
dependencies = [
2929
"jupyter_server>=2.4.0,<3",
3030
"jupyterlab_chat>=0.17.0,<0.18.0",
31-
"jupyter_ai_router>=0.0.1",
31+
"jupyter_ai_router>=0.0.2",
3232
"jupyter_ai_persona_manager>=0.0.3",
3333
]
3434
dynamic = ["version", "description", "authors", "urls", "keywords"]

0 commit comments

Comments
 (0)