Skip to content

Commit e91f214

Browse files
authored
Add /refresh-personas command and default persona configurable (#1405)
* rename context commands => file command * add slash command provider in frontend * add default_persona trait * handle default_persona_id & recognize slash commands * remove /default-personas slash command * handle /refresh-personas slash command * add .jupyter/ to .gitignore * add send_system_message() method & call on /refresh-personas * fix #1404 * fix #1403 by showing hidden files by default in UI * fix mypy * catch KeyError when removing system user * forbid non-working cohere versions * remove redundant cohere version specifier
1 parent ee9d341 commit e91f214

File tree

14 files changed

+404
-68
lines changed

14 files changed

+404
-68
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@ dev.sh
138138
# Version files are auto-generated by Hatchling and should not be committed to
139139
# the source repo.
140140
packages/**/_version.py
141+
142+
# Ignore local chat files & local .jupyter/ dir
141143
*.chat
144+
.jupyter/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"dev:reinstall": "jlpm dev:uninstall && jlpm dev:install",
3434
"dev:uninstall": "lerna run dev:uninstall --stream",
3535
"di": "jlpm dev:install",
36-
"dri": "jlpm dev:reinstall",
36+
"dr": "jlpm dev:reinstall",
3737
"du": "jlpm dev:uninstall",
3838
"install-from-src": "lerna run install-from-src --stream",
3939
"lint": "jlpm && lerna run prettier && lerna run eslint",

packages/jupyter-ai-magics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"dev:install": "uv pip install -e \".[dev,all]\"",
22-
"dev:uninstall": "uv pip uninstall jupyter_ai_magics -y",
22+
"dev:uninstall": "uv pip uninstall jupyter_ai_magics",
2323
"install-from-src": "uv pip install ."
2424
}
2525
}

packages/jupyter-ai-test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"dev:install": "uv pip install -e .",
22-
"dev:uninstall": "uv pip uninstall jupyter_ai_test -y",
22+
"dev:uninstall": "uv pip uninstall jupyter_ai_test",
2323
"install-from-src": "uv pip install ."
2424
}
2525
}

packages/jupyter-ai/jupyter_ai/personas/base_persona.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,24 @@ def get_mcp_config(self) -> dict[str, Any]:
346346
Returns the MCP config for the current chat.
347347
"""
348348
return self.parent.get_mcp_config()
349+
350+
def shutdown(self) -> None:
351+
"""
352+
Shuts the persona down. This method should:
353+
354+
- Halt all background tasks started by this instance.
355+
- Remove the persona from the chat awareness
356+
357+
This method will be called when `/refresh-personas` is run, and may be
358+
called when the server is shutting down or when a chat session is
359+
closed.
360+
361+
Subclasses may need to override this method to add custom shutdown
362+
logic. The override should generally call `super().shutdown()` first
363+
before running custom shutdown logic.
364+
"""
365+
# Stop awareness heartbeat task & remove self from chat awareness
366+
self.awareness.shutdown()
349367

350368

351369
class GenerationInterrupted(asyncio.CancelledError):

packages/jupyter-ai/jupyter_ai/personas/persona_awareness.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ def get_local_state(self) -> Optional[dict[str, Any]]:
106106
with self.as_custom_client():
107107
return self.awareness.get_local_state()
108108

109-
def set_local_state(self, state: dict[str, Any]) -> None:
109+
def set_local_state(self, state: Optional[dict[str, Any]]) -> None:
110110
"""
111-
Sets the local state of the awareness instance to the provided state.
112-
This method is used to update the local state of the awareness instance
113-
with a new state dictionary.
111+
Sets the local state of this persona in the awareness map, indexed by
112+
this instance's custom client ID.
113+
114+
Passing `state=None` deletes the local state indexed by this instance's
115+
custom client ID.
114116
"""
115117
with self.as_custom_client():
116118
self.awareness.set_local_state(state)
@@ -135,8 +137,10 @@ async def _start_heartbeat(self):
135137
local_state = self.get_local_state() or {}
136138
self.set_local_state(local_state)
137139

138-
def stop(self) -> None:
140+
def shutdown(self) -> None:
139141
"""
140-
Stops the awareness heartbeat task if it is running.
142+
Stops this instance's background tasks and removes the persona's custom
143+
client ID from the awareness map.
141144
"""
142145
self._heartbeat_task.cancel()
146+
self.set_local_state(None)

0 commit comments

Comments
 (0)