Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions extensions/positron-assistant/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as xml from './xml.js';
import * as vscode from 'vscode';
import * as positron from 'positron';
import { isStreamingEditsEnabled, ParticipantID } from './participants.js';
import { hasAttachedNotebookContext } from './tools/notebookUtils.js';
import { hasAttachedNotebookContext, getAttachedNotebookContext, SerializedNotebookContext } from './tools/notebookUtils.js';
import { MARKDOWN_DIR, TOOL_TAG_REQUIRES_ACTIVE_SESSION, TOOL_TAG_REQUIRES_WORKSPACE, TOOL_TAG_REQUIRES_NOTEBOOK } from './constants.js';
import { isWorkspaceOpen } from './utils.js';
import { PositronAssistantToolName } from './types.js';
Expand Down Expand Up @@ -58,7 +58,16 @@ export class PositronAssistantApi {
const activeSessions = await positron.runtime.getActiveSessions();
const sessions = activeSessions.map(session => session.runtimeMetadata);
const streamingEdits = isStreamingEditsEnabled();
let prompt = PromptRenderer.renderModePrompt(mode, { sessions, request, streamingEdits }).content;

// Get notebook context if available, with error handling
let notebookContext: SerializedNotebookContext | undefined;
try {
notebookContext = await getAttachedNotebookContext(request);
} catch (err) {
log.error('[PositronAssistantApi] Error checking notebook context:', err);
}

let prompt = PromptRenderer.renderModePrompt(mode, { sessions, request, streamingEdits, notebookContext }).content;

// Get the IDE context for the request.
const positronContext = await positron.ai.getPositronChatContext(request);
Expand Down Expand Up @@ -133,6 +142,18 @@ export class PositronAssistantApi {
}
}

/**
* Copilot notebook tool names that should be disabled when Positron notebook mode is active.
* These tools conflict with Positron's specialized notebook tools.
*/
const COPILOT_NOTEBOOK_TOOLS = new Set([
'copilot_editNotebook',
'copilot_getNotebookSummary',
'copilot_runNotebookCell',
'copilot_readNotebookCellOutput',
'copilot_createNewJupyterNotebook',
]);

/**
* Gets the set of enabled tools for a chat request.
*
Expand Down Expand Up @@ -330,6 +351,13 @@ export function getEnabledTools(
const alwaysIncludeCopilotTools = vscode.workspace.getConfiguration('positron.assistant').get('alwaysIncludeCopilotTools', false);
// Check if the tool is provided by Copilot.
const copilotTool = tool.source instanceof vscode.LanguageModelToolExtensionSource && tool.source.id === 'GitHub.copilot-chat';

// Disable Copilot notebook tools when Positron notebook mode is active
// to avoid conflicts with Positron's specialized notebook tools.
if (copilotTool && hasActiveNotebook && COPILOT_NOTEBOOK_TOOLS.has(tool.name)) {
continue;
}

// Check if the user is signed into Copilot.
let copilotEnabled;
try {
Expand Down
Loading