@jupyternaut/persona 0.0.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chat-commands/mention.d.ts +9 -0
- package/lib/chat-commands/mention.js +30 -0
- package/lib/completion/completion-provider.d.ts +86 -0
- package/lib/completion/completion-provider.js +246 -0
- package/lib/completion/index.d.ts +2 -0
- package/lib/completion/index.js +1 -0
- package/lib/components/completion-status.d.ts +26 -0
- package/lib/components/completion-status.js +52 -0
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.js +1 -0
- package/lib/diff-manager.d.ts +25 -0
- package/lib/diff-manager.js +60 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +522 -0
- package/lib/models/settings-model.d.ts +36 -0
- package/lib/models/settings-model.js +356 -0
- package/lib/persona-registry.d.ts +15 -0
- package/lib/persona-registry.js +29 -0
- package/lib/persona.d.ts +66 -0
- package/lib/persona.js +414 -0
- package/lib/process-attachments.d.ts +5 -0
- package/lib/process-attachments.js +287 -0
- package/lib/tokens.d.ts +101 -0
- package/lib/tokens.js +20 -0
- package/lib/widgets/ai-settings.d.ts +54 -0
- package/lib/widgets/ai-settings.js +572 -0
- package/lib/widgets/provider-config-dialog.d.ts +16 -0
- package/lib/widgets/provider-config-dialog.js +384 -0
- package/package.json +111 -7
- package/schema/settings-model.json +287 -0
- package/src/chat-commands/mention.tsx +46 -0
- package/src/completion/completion-provider.ts +350 -0
- package/src/completion/index.ts +1 -0
- package/src/components/completion-status.tsx +93 -0
- package/src/components/index.ts +1 -0
- package/src/diff-manager.ts +81 -0
- package/src/index.ts +710 -0
- package/src/models/settings-model.ts +415 -0
- package/src/persona-registry.ts +46 -0
- package/src/persona.ts +610 -0
- package/src/process-attachments.ts +369 -0
- package/src/tokens.ts +121 -0
- package/src/widgets/ai-settings.tsx +1308 -0
- package/src/widgets/provider-config-dialog.tsx +997 -0
- package/style/base.css +14 -0
- package/style/index.css +1 -0
- package/style/index.js +1 -0
- package/README.md +0 -3
- package/index.js +0 -1
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { VDomModel } from '@jupyterlab/ui-components';
|
|
2
|
+
const PLUGIN_ID = '@jupyternaut/persona:settings-model';
|
|
3
|
+
export class AISettingsModel extends VDomModel {
|
|
4
|
+
_config = {
|
|
5
|
+
useSecretsManager: true,
|
|
6
|
+
providers: [],
|
|
7
|
+
defaultProvider: '',
|
|
8
|
+
activeCompleterProvider: undefined,
|
|
9
|
+
useSameProviderForChatAndCompleter: true,
|
|
10
|
+
contextAwareness: true,
|
|
11
|
+
codeExecution: false,
|
|
12
|
+
toolsEnabled: true,
|
|
13
|
+
showCellDiff: true,
|
|
14
|
+
showFileDiff: true,
|
|
15
|
+
diffDisplayMode: 'split',
|
|
16
|
+
skillsPaths: ['.agents/skills', '_agents/skills'],
|
|
17
|
+
commandsRequiringApproval: [
|
|
18
|
+
'notebook:restart-run-all',
|
|
19
|
+
'notebook:run-cell',
|
|
20
|
+
'notebook:run-cell-and-select-next',
|
|
21
|
+
'notebook:run-cell-and-insert-below',
|
|
22
|
+
'notebook:run-all-cells',
|
|
23
|
+
'notebook:run-all-above',
|
|
24
|
+
'notebook:run-all-below',
|
|
25
|
+
'console:execute',
|
|
26
|
+
'console:execute-forced',
|
|
27
|
+
'fileeditor:run-code',
|
|
28
|
+
'kernelmenu:run',
|
|
29
|
+
'kernelmenu:restart-and-run-all',
|
|
30
|
+
'runmenu:run-all',
|
|
31
|
+
'jupyterlab-ai-commands:run-cell'
|
|
32
|
+
],
|
|
33
|
+
commandsAutoRenderMimeBundles: ['jupyterlab-ai-commands:execute-in-kernel'],
|
|
34
|
+
trustedMimeTypesForAutoRender: ['text/html'],
|
|
35
|
+
systemPrompt: `You are Jupyternaut, an AI coding assistant built specifically for the JupyterLab environment.
|
|
36
|
+
|
|
37
|
+
## Your Core Mission
|
|
38
|
+
You're designed to be a capable partner for data science, research, and development work in Jupyter notebooks. You can help with everything from quick code snippets to complex multi-notebook projects.
|
|
39
|
+
|
|
40
|
+
## Your Capabilities
|
|
41
|
+
**📁 File & Project Management:**
|
|
42
|
+
- Create, read, edit, and organize files and notebooks in any language
|
|
43
|
+
- Manage project structure and navigate file systems
|
|
44
|
+
- Help with version control and project organization
|
|
45
|
+
|
|
46
|
+
**📊 Notebook Operations:**
|
|
47
|
+
- Create new notebooks and manage existing ones
|
|
48
|
+
- Add, edit, delete, and run cells (both code and markdown)
|
|
49
|
+
- Help with notebook structure and organization
|
|
50
|
+
- Retrieve and analyze cell outputs and execution results
|
|
51
|
+
|
|
52
|
+
**⚡ Kernel Management:**
|
|
53
|
+
- Start new kernels with specified language or kernel name
|
|
54
|
+
- Execute code directly in a kernel using jupyterlab-ai-commands execution commands (not console), without creating cells
|
|
55
|
+
- List running kernels and monitor their status
|
|
56
|
+
- Manage kernel lifecycle (start, monitor, shutdown)
|
|
57
|
+
|
|
58
|
+
**🧠 Coding & Development:**
|
|
59
|
+
- Write, debug, and optimize code in any language supported by Jupyter kernels (Python, R, Julia, JavaScript, C++, and more)
|
|
60
|
+
- Explain complex algorithms and data structures
|
|
61
|
+
- Help with data analysis, visualization, and machine learning
|
|
62
|
+
- Support for libraries and packages across different languages
|
|
63
|
+
- Code reviews and best practices recommendations
|
|
64
|
+
|
|
65
|
+
**💡 Adaptive Assistance:**
|
|
66
|
+
- Understand context from the user's current work environment
|
|
67
|
+
- Provide suggestions tailored to the user's specific use case
|
|
68
|
+
- Help with both quick fixes and long-term project planning
|
|
69
|
+
|
|
70
|
+
## How You Work
|
|
71
|
+
You interact with the user's JupyterLab environment primarily through the command system:
|
|
72
|
+
- Use 'discover_commands' to find available JupyterLab commands
|
|
73
|
+
- Use 'execute_command' to perform operations
|
|
74
|
+
- For file and notebook operations, use commands from the jupyterlab-ai-commands extension (prefixed with 'jupyterlab-ai-commands:')
|
|
75
|
+
- These commands provide comprehensive file and notebook manipulation: create, read, edit files/notebooks, manage cells, run code, etc.
|
|
76
|
+
- You can make systematic changes across multiple files and perform complex multi-step operations
|
|
77
|
+
- Skills are available via the skills tools: discover_skills (list) and load_skill (load instructions/resources)
|
|
78
|
+
|
|
79
|
+
## Tool & Skill Use Policy
|
|
80
|
+
- When tools or skills are available and the task requires actions or environment-specific facts, use them instead of guessing
|
|
81
|
+
- Never guess command IDs. Always use discover_commands with a relevant query before execute_command, unless you already discovered the command earlier in this conversation
|
|
82
|
+
- If a preloaded skills snapshot is provided in the system prompt, use it instead of calling discover_skills to list skills
|
|
83
|
+
- Only call discover_skills if the user explicitly asks for the latest list or you need to verify a skill not in the snapshot
|
|
84
|
+
- When a skill is relevant, call load_skill with the skill name to load instructions; if it returns a non-empty resources array, load each listed resource with load_skill before proceeding
|
|
85
|
+
- If you're unsure how to perform a request, discover relevant commands (discover_commands with task keywords)
|
|
86
|
+
- Use a relevant skill even when the user doesn't explicitly mention it
|
|
87
|
+
- Prefer the single most relevant tool or skill; if multiple could apply, ask a brief clarifying question
|
|
88
|
+
- Ask for missing required inputs before calling a tool or skill
|
|
89
|
+
- Before calling a tool or skill, briefly state why you're calling it, then make the tool call in the same response
|
|
90
|
+
- Never end your response after only announcing what you are about to do: whenever you say you will use a tool or perform an action, the corresponding tool call must be part of that same response
|
|
91
|
+
|
|
92
|
+
## Code Execution Strategy
|
|
93
|
+
When asked to run code or perform computations, choose the most appropriate approach:
|
|
94
|
+
- **For quick computations or one-off code execution**: Use the kernel execution commands from jupyterlab-ai-commands to run code directly (no notebook/console). Discover these commands first with query 'jupyterlab-ai-commands' and use the returned command IDs. This is ideal for calculations, data lookups, or testing code snippets.
|
|
95
|
+
- **For work that should be saved**: Create or use notebooks when the user needs a persistent record of their work, wants to iterate on code, or is building something they'll return to later.
|
|
96
|
+
|
|
97
|
+
This means if the user asks you to "calculate the factorial of 100" or "check what library version is installed", run that directly with the jupyterlab-ai-commands kernel execution command rather than creating a new notebook file.
|
|
98
|
+
|
|
99
|
+
## Notebook State and Cell Identity
|
|
100
|
+
When working with an existing notebook, use the notebook's current structure and kernel state as the source of truth.
|
|
101
|
+
- Before changing notebook content or structure, inspect the notebook and any target cells with the relevant notebook commands you have discovered.
|
|
102
|
+
- If the user may have edited the notebook, or if a previous command could have changed it, refresh your view before continuing rather than relying on earlier results.
|
|
103
|
+
- Treat variables from previously executed cells as part of the active kernel state. When the user asks you to work with existing data or variables, use them by name instead of recreating them unless the user asks you to redefine them or the kernel state is unavailable.
|
|
104
|
+
- Be explicit about the kind of cell reference you are using. A visible execution count (for example In [6]), a notebook position, and an internal cell ID or UUID are different identifiers and may not match.
|
|
105
|
+
- When the user identifies a cell by execution count, relative position, or content, verify the target cell from the current notebook contents before editing it or inserting cells relative to it.
|
|
106
|
+
- For relative insertions, anchor the change to the confirmed target cell rather than to empty placeholder or trailing cells unless the user explicitly refers to those cells.
|
|
107
|
+
|
|
108
|
+
## Your Approach
|
|
109
|
+
- **Context-aware**: You understand the user is working in a data science/research environment
|
|
110
|
+
- **Practical**: You focus on actionable solutions that work in the user's current setup
|
|
111
|
+
- **Educational**: You explain your reasoning and teach best practices along the way
|
|
112
|
+
- **Collaborative**: You are a pair programming partner, not just a code generator
|
|
113
|
+
|
|
114
|
+
## Communication Style & Agent Behavior
|
|
115
|
+
IMPORTANT: Follow this message flow pattern for better user experience:
|
|
116
|
+
|
|
117
|
+
1. FIRST: Explain what you're going to do and your approach
|
|
118
|
+
2. THEN: Execute tools (these will show automatically with step numbers)
|
|
119
|
+
3. FINALLY: Provide a concise summary of what was accomplished
|
|
120
|
+
|
|
121
|
+
Example flow:
|
|
122
|
+
- "I'll help you create a notebook with example cells. Let me first create the file structure, then add Python and Markdown cells."
|
|
123
|
+
- [Tool executions happen with automatic step display]
|
|
124
|
+
- "Successfully created your notebook with 3 cells: a title, code example, and visualization cell."
|
|
125
|
+
|
|
126
|
+
Guidelines:
|
|
127
|
+
- Start responses with your plan/approach before tool execution
|
|
128
|
+
- Let the system handle tool execution display (don't duplicate details)
|
|
129
|
+
- End with a brief summary of accomplishments
|
|
130
|
+
- Use natural, conversational tone throughout
|
|
131
|
+
|
|
132
|
+
- **Conversational**: You maintain a friendly, natural conversation flow throughout the interaction
|
|
133
|
+
- **Progress Updates**: You write brief progress messages between tool uses that appear directly in the conversation
|
|
134
|
+
- **No Filler**: You avoid empty acknowledgments like "Sounds good!" or "Okay, I will..." - you get straight to work
|
|
135
|
+
- **Purposeful Communication**: You start with what you're doing, use tools, then share what you found and what's next
|
|
136
|
+
- **Active Narration**: You actively write progress updates like "Looking at the current code structure..." or "Found the issue in the notebook..." between tool calls
|
|
137
|
+
- **Checkpoint Updates**: After several operations, you summarize what you've accomplished and what remains
|
|
138
|
+
- **Natural Flow**: Your explanations and progress reports appear as normal conversation text, not just in tool blocks
|
|
139
|
+
|
|
140
|
+
## IMPORTANT: Always write progress messages between tools that explain what you're doing and what you found. These should be conversational updates that help the user follow along with your work.
|
|
141
|
+
|
|
142
|
+
## Technical Communication
|
|
143
|
+
- Code is formatted in proper markdown blocks with syntax highlighting
|
|
144
|
+
- Mathematical notation uses LaTeX formatting: \\(equations\\) and \\[display math\\]
|
|
145
|
+
- You provide context for your actions and explain your reasoning as you work
|
|
146
|
+
- When creating or modifying multiple files, you give brief summaries of changes
|
|
147
|
+
- You keep users informed of progress while staying focused on the task
|
|
148
|
+
|
|
149
|
+
## Multi-Step Task Handling
|
|
150
|
+
When users request complex tasks, you use the command system to accomplish them:
|
|
151
|
+
- For file and notebook operations, use discover_commands with query 'jupyterlab-ai-commands' to find the curated set of AI commands (~22 commands)
|
|
152
|
+
- For other JupyterLab operations (terminal, launcher, UI), use specific keywords like 'terminal', 'launcher', etc.
|
|
153
|
+
- IMPORTANT: Always use 'jupyterlab-ai-commands' as the query for file/notebook tasks - this returns a focused set instead of 100+ generic commands
|
|
154
|
+
- For example, to create a notebook with cells:
|
|
155
|
+
1. discover_commands with query 'jupyterlab-ai-commands' to find available file/notebook commands
|
|
156
|
+
2. execute_command with 'jupyterlab-ai-commands:create-notebook' and required arguments
|
|
157
|
+
3. execute_command with 'jupyterlab-ai-commands:add-cell' multiple times to add cells
|
|
158
|
+
4. execute_command with 'jupyterlab-ai-commands:set-cell-content' to add content to cells
|
|
159
|
+
5. execute_command with 'jupyterlab-ai-commands:run-cell' when appropriate
|
|
160
|
+
|
|
161
|
+
## Kernel Preference for Notebooks and Consoles
|
|
162
|
+
When creating notebooks or consoles for a specific programming language, use the 'kernelPreference' argument:
|
|
163
|
+
Only create consoles when the user explicitly asks for one; otherwise prefer the jupyterlab-ai-commands kernel execution commands for running code.
|
|
164
|
+
- To specify by language: { "kernelPreference": { "language": "python" } } or { "kernelPreference": { "language": "julia" } }
|
|
165
|
+
- To specify by kernel name: { "kernelPreference": { "name": "python3" } } or { "kernelPreference": { "name": "julia-1.10" } }
|
|
166
|
+
- Example: execute_command with commandId="notebook:create-new" and args={ "kernelPreference": { "language": "python" } }
|
|
167
|
+
- Example: execute_command with commandId="console:create" and args={ "kernelPreference": { "name": "python3" } }
|
|
168
|
+
- Common kernel names: "python3" (Python), "julia-1.10" (Julia), "ir" (R), "xpython" (xeus-python)
|
|
169
|
+
- If unsure of exact kernel name, prefer using "language" which will match any kernel supporting that language
|
|
170
|
+
|
|
171
|
+
Always think through multi-step tasks and use commands to fully complete the user's request rather than stopping after just one action.
|
|
172
|
+
|
|
173
|
+
You are ready to help users build something great!`,
|
|
174
|
+
// Completion system prompt - also defined in schema/settings-model.json
|
|
175
|
+
// This serves as a fallback if settings fail to load or are not available
|
|
176
|
+
completionSystemPrompt: `You are an AI code completion assistant. Complete the given code fragment with appropriate code.
|
|
177
|
+
Rules:
|
|
178
|
+
- Return only the completion text, no explanations or comments
|
|
179
|
+
- Do not include code block markers (\`\`\` or similar)
|
|
180
|
+
- Make completions contextually relevant to the surrounding code and notebook context
|
|
181
|
+
- Follow the language-specific conventions and style guidelines for the detected programming language
|
|
182
|
+
- Keep completions concise but functional
|
|
183
|
+
- Do not repeat the existing code that comes before the cursor
|
|
184
|
+
- Use variables, imports, functions, and other definitions from previous notebook cells when relevant`
|
|
185
|
+
};
|
|
186
|
+
_settingRegistry;
|
|
187
|
+
_settings = null;
|
|
188
|
+
constructor(options) {
|
|
189
|
+
super();
|
|
190
|
+
this._settingRegistry = options.settingRegistry;
|
|
191
|
+
this._initializeSettings();
|
|
192
|
+
}
|
|
193
|
+
async _initializeSettings() {
|
|
194
|
+
try {
|
|
195
|
+
this._settings = await this._settingRegistry.load(PLUGIN_ID);
|
|
196
|
+
this._loadFromSettings();
|
|
197
|
+
// Listen for settings changes
|
|
198
|
+
this._settings.changed.connect(this._onSettingsChanged, this);
|
|
199
|
+
this.stateChanged.emit(void 0);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
console.warn('Failed to load JupyterLab settings:', error);
|
|
203
|
+
this.stateChanged.emit(void 0);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
_onSettingsChanged() {
|
|
207
|
+
this._loadFromSettings();
|
|
208
|
+
this.stateChanged.emit(void 0);
|
|
209
|
+
}
|
|
210
|
+
_loadFromSettings() {
|
|
211
|
+
if (!this._settings) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Merge JupyterLab settings with defaults
|
|
215
|
+
const settingsData = this._settings.composite;
|
|
216
|
+
this._config = {
|
|
217
|
+
...this._config,
|
|
218
|
+
...settingsData
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
get config() {
|
|
222
|
+
return { ...this._config };
|
|
223
|
+
}
|
|
224
|
+
get providers() {
|
|
225
|
+
return [...this._config.providers];
|
|
226
|
+
}
|
|
227
|
+
getProvider(id) {
|
|
228
|
+
return this._config.providers.find(p => p.id === id);
|
|
229
|
+
}
|
|
230
|
+
getDefaultProvider() {
|
|
231
|
+
return this.getProvider(this._config.defaultProvider);
|
|
232
|
+
}
|
|
233
|
+
getCompleterProvider() {
|
|
234
|
+
if (this._config.useSameProviderForChatAndCompleter) {
|
|
235
|
+
return this.getDefaultProvider();
|
|
236
|
+
}
|
|
237
|
+
return this._config.activeCompleterProvider
|
|
238
|
+
? this.getProvider(this._config.activeCompleterProvider)
|
|
239
|
+
: undefined;
|
|
240
|
+
}
|
|
241
|
+
async addProvider(providerConfig) {
|
|
242
|
+
const id = `${providerConfig.provider}-${Date.now()}`;
|
|
243
|
+
const newProvider = {
|
|
244
|
+
id,
|
|
245
|
+
name: providerConfig.name,
|
|
246
|
+
provider: providerConfig.provider,
|
|
247
|
+
model: providerConfig.model,
|
|
248
|
+
apiKey: providerConfig.apiKey,
|
|
249
|
+
baseURL: providerConfig.baseURL,
|
|
250
|
+
headers: providerConfig.headers,
|
|
251
|
+
parameters: providerConfig.parameters,
|
|
252
|
+
customSettings: providerConfig.customSettings
|
|
253
|
+
};
|
|
254
|
+
this._config.providers.push(newProvider);
|
|
255
|
+
// If this is the first provider, make it active
|
|
256
|
+
if (this._config.providers.length === 1) {
|
|
257
|
+
// Save both providers and defaultProvider
|
|
258
|
+
await this._saveSetting('providers', this._config.providers);
|
|
259
|
+
this._config.defaultProvider = id;
|
|
260
|
+
await this._saveSetting('defaultProvider', this._config.defaultProvider);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// Only save providers
|
|
264
|
+
await this._saveSetting('providers', this._config.providers);
|
|
265
|
+
}
|
|
266
|
+
return id;
|
|
267
|
+
}
|
|
268
|
+
async removeProvider(id) {
|
|
269
|
+
const index = this._config.providers.findIndex(p => p.id === id);
|
|
270
|
+
if (index === -1) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this._config.providers.splice(index, 1);
|
|
274
|
+
await this._saveSetting('providers', this._config.providers);
|
|
275
|
+
// If this was the active provider, select a new one
|
|
276
|
+
if (this._config.defaultProvider === id) {
|
|
277
|
+
this._config.defaultProvider =
|
|
278
|
+
this._config.providers.length > 0 ? this._config.providers[0].id : '';
|
|
279
|
+
await this._saveSetting('defaultProvider', this._config.defaultProvider);
|
|
280
|
+
}
|
|
281
|
+
if (this._config.activeCompleterProvider === id) {
|
|
282
|
+
this._config.activeCompleterProvider = undefined;
|
|
283
|
+
await this._saveSetting('activeCompleterProvider', this._config.activeCompleterProvider);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async updateProvider(id, updates) {
|
|
287
|
+
const provider = this.getProvider(id);
|
|
288
|
+
if (!provider) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
Object.assign(provider, updates);
|
|
292
|
+
Object.keys(provider).forEach(key => {
|
|
293
|
+
if (key !== 'id' && updates[key] === undefined) {
|
|
294
|
+
delete provider[key];
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
await this._saveSetting('providers', this._config.providers);
|
|
298
|
+
}
|
|
299
|
+
async setActiveProvider(id) {
|
|
300
|
+
if (this.getProvider(id)) {
|
|
301
|
+
this._config.defaultProvider = id;
|
|
302
|
+
await this._saveSetting('defaultProvider', this._config.defaultProvider);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async setActiveCompleterProvider(id) {
|
|
306
|
+
this._config.activeCompleterProvider = id;
|
|
307
|
+
await this._saveSetting('activeCompleterProvider', this._config.activeCompleterProvider);
|
|
308
|
+
}
|
|
309
|
+
async updateConfig(updates) {
|
|
310
|
+
// Update config and save only changed settings
|
|
311
|
+
const promises = [];
|
|
312
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
313
|
+
if (key in this._config &&
|
|
314
|
+
this._config[key] !== value) {
|
|
315
|
+
this._config[key] = value;
|
|
316
|
+
promises.push(this._saveSetting(key, value));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// Wait for all settings to be saved
|
|
320
|
+
await Promise.all(promises);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Get the API key saved in the settings file for a given provider.
|
|
324
|
+
*
|
|
325
|
+
* @param id - the id of the provider.
|
|
326
|
+
*/
|
|
327
|
+
getApiKey(id) {
|
|
328
|
+
// First check the active completer provider
|
|
329
|
+
const activeCompleterProvider = this.getCompleterProvider();
|
|
330
|
+
if (activeCompleterProvider && activeCompleterProvider.id === id) {
|
|
331
|
+
return activeCompleterProvider.apiKey || '';
|
|
332
|
+
}
|
|
333
|
+
// Fallback to active chat provider
|
|
334
|
+
const activeProvider = this.getProvider(id);
|
|
335
|
+
if (activeProvider) {
|
|
336
|
+
return activeProvider.apiKey || '';
|
|
337
|
+
}
|
|
338
|
+
return '';
|
|
339
|
+
}
|
|
340
|
+
async _saveSetting(key, value) {
|
|
341
|
+
try {
|
|
342
|
+
if (this._settings) {
|
|
343
|
+
// Only save the specific setting that changed
|
|
344
|
+
if (value !== undefined) {
|
|
345
|
+
await this._settings.set(key, value);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
await this._settings.remove(key);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
console.warn(`Failed to save setting '${key}' to JupyterLab settings, falling back to localStorage:`, error);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IChatModel } from '@jupyter/chat';
|
|
2
|
+
import { IAgentManager } from '@jupyternaut/agent';
|
|
3
|
+
import { ISignal } from '@lumino/signaling';
|
|
4
|
+
import type { IPersona, IPersonaRegistry, IPersonaRegistryOptions } from './tokens';
|
|
5
|
+
export declare class PersonaRegistry implements IPersonaRegistry {
|
|
6
|
+
constructor(options: IPersonaRegistryOptions);
|
|
7
|
+
get(model: IChatModel): IPersona | undefined;
|
|
8
|
+
register(model: IChatModel, agentManager: IAgentManager): void;
|
|
9
|
+
unregister(model: IChatModel): void;
|
|
10
|
+
get personaAdded(): ISignal<IPersonaRegistry, IPersona>;
|
|
11
|
+
private _options;
|
|
12
|
+
private _personas;
|
|
13
|
+
private _personaAdded;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=persona-registry.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Signal } from '@lumino/signaling';
|
|
2
|
+
import { Persona } from './persona';
|
|
3
|
+
export class PersonaRegistry {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this._options = options;
|
|
6
|
+
}
|
|
7
|
+
get(model) {
|
|
8
|
+
return this._personas.get(model);
|
|
9
|
+
}
|
|
10
|
+
register(model, agentManager) {
|
|
11
|
+
const persona = new Persona({
|
|
12
|
+
model,
|
|
13
|
+
agentManager,
|
|
14
|
+
...this._options
|
|
15
|
+
});
|
|
16
|
+
this._personas.set(model, persona);
|
|
17
|
+
this._personaAdded.emit(persona);
|
|
18
|
+
}
|
|
19
|
+
unregister(model) {
|
|
20
|
+
this.get(model)?.dispose();
|
|
21
|
+
this._personas.delete(model);
|
|
22
|
+
}
|
|
23
|
+
get personaAdded() {
|
|
24
|
+
return this._personaAdded;
|
|
25
|
+
}
|
|
26
|
+
_options;
|
|
27
|
+
_personas = new Map();
|
|
28
|
+
_personaAdded = new Signal(this);
|
|
29
|
+
}
|
package/lib/persona.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IChatModel, IUser } from '@jupyter/chat';
|
|
2
|
+
import type { IDocumentManager } from '@jupyterlab/docmanager';
|
|
3
|
+
import type { IAgentManager, IAISettingsModel, IProviderRegistry } from '@jupyternaut/agent';
|
|
4
|
+
import { ISignal } from '@lumino/signaling';
|
|
5
|
+
import type { IPersona } from './tokens';
|
|
6
|
+
/**
|
|
7
|
+
* Links an IAgentManager to an IChatModel for the Jupyternaut persona.
|
|
8
|
+
*
|
|
9
|
+
* Monitors new messages arriving on the chat model and responds when the
|
|
10
|
+
* persona trigger string is mentioned. The handler and its agent stay alive
|
|
11
|
+
* as long as the associated chat widget is open, so conversation history is
|
|
12
|
+
* preserved across multiple mentions.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Persona implements IPersona {
|
|
15
|
+
constructor(options: Persona.IOptions);
|
|
16
|
+
dispose(): void;
|
|
17
|
+
get agentManager(): IAgentManager;
|
|
18
|
+
get model(): IChatModel;
|
|
19
|
+
get isBusy(): boolean;
|
|
20
|
+
get busyChanged(): ISignal<IPersona, boolean>;
|
|
21
|
+
private _onMessagesUpdated;
|
|
22
|
+
private _respond;
|
|
23
|
+
rebuildHistory(): Promise<void>;
|
|
24
|
+
private _onActiveProviderChanged;
|
|
25
|
+
private _rebuildHistory;
|
|
26
|
+
private _onAgentEvent;
|
|
27
|
+
private _handleMessageStart;
|
|
28
|
+
private _handleMessageChunk;
|
|
29
|
+
private _handleMessageComplete;
|
|
30
|
+
private _handleToolCallStart;
|
|
31
|
+
private _handleToolCallComplete;
|
|
32
|
+
private _computeShouldAutoRenderMimeBundles;
|
|
33
|
+
private _handleToolApprovalRequest;
|
|
34
|
+
private _handleToolApprovalResolved;
|
|
35
|
+
private _handleError;
|
|
36
|
+
private _updateToolCallUI;
|
|
37
|
+
/**
|
|
38
|
+
* Whether a mention is required to trigger a response.
|
|
39
|
+
* When false, the persona responds to all non-bot messages.
|
|
40
|
+
* Defaults to true.
|
|
41
|
+
*/
|
|
42
|
+
requireMention: boolean;
|
|
43
|
+
private readonly _model;
|
|
44
|
+
private readonly _agent;
|
|
45
|
+
private readonly _persona;
|
|
46
|
+
private readonly _settingsModel;
|
|
47
|
+
private readonly _providerRegistry;
|
|
48
|
+
private readonly _documentManager;
|
|
49
|
+
private _respondedToIds;
|
|
50
|
+
private _currentModelKey;
|
|
51
|
+
private _busy;
|
|
52
|
+
private _busyChanged;
|
|
53
|
+
private _streamingMessage;
|
|
54
|
+
private _toolContexts;
|
|
55
|
+
}
|
|
56
|
+
export declare namespace Persona {
|
|
57
|
+
interface IOptions {
|
|
58
|
+
model: IChatModel;
|
|
59
|
+
agentManager: IAgentManager;
|
|
60
|
+
persona: IUser;
|
|
61
|
+
settingsModel: IAISettingsModel;
|
|
62
|
+
providerRegistry?: IProviderRegistry;
|
|
63
|
+
documentManager?: IDocumentManager;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=persona.d.ts.map
|