Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ describe('CompassAssistantProvider', function () {
enableToolCalling = true,
enableGenAIToolCallingAtlasProject = true,
enableGenAIToolCalling = true,
maxTimeMS,
query,
pipeline,
connections,
Expand All @@ -382,6 +383,7 @@ describe('CompassAssistantProvider', function () {
enableToolCalling?: boolean;
enableGenAIToolCallingAtlasProject?: boolean;
enableGenAIToolCalling?: boolean;
maxTimeMS?: number;
query?: string;
pipeline?: string;
connections?: ActiveConnectionInfo[];
Expand Down Expand Up @@ -412,6 +414,7 @@ describe('CompassAssistantProvider', function () {
enableToolCalling,
enableGenAIToolCallingAtlasProject,
enableGenAIToolCalling,
maxTimeMS,
},
}
);
Expand Down Expand Up @@ -704,6 +707,7 @@ describe('CompassAssistantProvider', function () {
expect(mockToolsController.setContext.callCount).to.equal(1);
expect(mockToolsController.setContext.firstCall.args[0]).to.deep.equal({
enableTelemetry: true,
maxTimeMS: undefined,
connections: [],
query,
pipeline,
Expand Down Expand Up @@ -770,6 +774,7 @@ describe('CompassAssistantProvider', function () {
expect(mockToolsController.setContext.callCount).to.equal(1);
expect(mockToolsController.setContext.firstCall.args[0]).to.deep.equal({
enableTelemetry: true,
maxTimeMS: undefined,
connections: [],
query,
pipeline,
Expand Down Expand Up @@ -844,6 +849,7 @@ describe('CompassAssistantProvider', function () {
expect(mockToolsController.setContext.callCount).to.equal(1);
expect(mockToolsController.setContext.firstCall.args[0]).to.deep.equal({
enableTelemetry: true,
maxTimeMS: undefined,
connections: [],
query,
pipeline,
Expand Down Expand Up @@ -929,6 +935,7 @@ describe('CompassAssistantProvider', function () {
expect(mockToolsController.setContext.callCount).to.equal(1);
expect(mockToolsController.setContext.firstCall.args[0]).to.deep.equal({
enableTelemetry: true,
maxTimeMS: undefined,
connections: [
{
connectionId: 'connection-1',
Expand All @@ -944,6 +951,56 @@ describe('CompassAssistantProvider', function () {
});
});

it('forwards maxTimeMS preference to toolsController.setContext', async function () {
const mockChat = new Chat<AssistantMessage>({
messages: [
{
id: 'assistant',
role: 'assistant',
parts: [{ type: 'text', text: 'Hello user!' }],
},
],
});

const sendMessageSpy = sinon.spy(mockChat, 'sendMessage');

const mockToolsController = {
setActiveTools: sinon.stub(),
getActiveTools: sinon.stub(),
setContext: sinon.stub(),
startServer: sinon.stub().resolves(),
stopServer: sinon.stub().resolves(),
setConnectionIdForToolCall: sinon.stub(),
};

await renderOpenAssistantDrawer({
chat: mockChat,
toolsController: mockToolsController,
enableToolCalling: true,
enableGenAIToolCalling: true,
maxTimeMS: 5000,
});

const input = screen.getByPlaceholderText('Ask a question');
const sendButton = screen.getByLabelText('Send message');

userEvent.type(input, 'Hello assistant');
userEvent.click(sendButton);

await waitFor(() => {
expect(sendMessageSpy.calledOnce).to.be.true;
});

expect(mockToolsController.setContext.callCount).to.equal(1);
expect(mockToolsController.setContext.firstCall.args[0]).to.deep.equal({
enableTelemetry: true,
maxTimeMS: 5000,
connections: [],
query: undefined,
pipeline: undefined,
});
});

describe('error handling with default chat', function () {
it('fires a telemetry event and displays error banner when error occurs', async function () {
const track = sinon.stub();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ export function ensureOptInAndSendThunk(
: null;
setToolsContext(toolsController, {
enableTelemetry: prefs.trackUsageStatistics,
maxTimeMS: prefs.maxTimeMS,
activeConnection,
Comment thread
lerouxb marked this conversation as resolved.
connections: activeConnections,
query,
Expand Down Expand Up @@ -836,6 +837,7 @@ export function setToolsContext(
toolsController: ToolsController,
{
enableTelemetry,
maxTimeMS,
activeConnection,
connections,
query,
Expand All @@ -845,6 +847,7 @@ export function setToolsContext(
activeTab,
}: {
enableTelemetry: boolean;
maxTimeMS?: number;
activeConnection: ActiveConnectionInfo | null;
connections: ActiveConnectionInfo[];
query?: string | null;
Expand All @@ -870,6 +873,7 @@ export function setToolsContext(
toolsController.setActiveTools(toolGroups);
toolsController.setContext({
enableTelemetry,
maxTimeMS,
connections: connections.map((connection) => {
if (!connection.connectOptions) {
throw new Error(
Expand All @@ -889,6 +893,7 @@ export function setToolsContext(
toolsController.setActiveTools(new Set([]));
toolsController.setContext({
enableTelemetry,
maxTimeMS,
connections: [],
query: undefined,
pipeline: undefined,
Expand Down
20 changes: 20 additions & 0 deletions packages/compass-generative-ai/src/tools-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,26 @@ describe('ToolsController', function () {
'disabled'
);
});

it('syncs maxTimeMS setting with runner userConfig', function () {
toolsController.setContext({
enableTelemetry: false,
maxTimeMS: 5000,
connections: [],
});
expect((toolsController as any).runner.userConfig.maxTimeMS).to.equal(
5000
);

toolsController.setContext({
enableTelemetry: false,
maxTimeMS: undefined,
connections: [],
});
expect((toolsController as any).runner.userConfig.maxTimeMS).to.equal(
undefined
);
});
});

describe('setConnectionIdForToolCall', function () {
Expand Down
11 changes: 8 additions & 3 deletions packages/compass-generative-ai/src/tools-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type ToolGroup = 'querybar' | 'aggregation-builder' | 'db-read';

type CompassContext = {
enableTelemetry: boolean;
maxTimeMS?: number;
query?: string;
pipeline?: string;
};
Expand Down Expand Up @@ -75,6 +76,7 @@ type ToolsControllerConfig = {
logger: Logger;
getTelemetryAnonymousId: () => string;
enableTelemetry: boolean;
maxTimeMS?: number;
};

export class ToolsController {
Expand All @@ -90,15 +92,17 @@ export class ToolsController {
logger,
getTelemetryAnonymousId,
enableTelemetry,
maxTimeMS,
}: ToolsControllerConfig) {
this.logger = logger;
const mcpConfig = UserConfigSchema.parse({
disabledTools: ['connect'],
loggers: ['mcp'],
readOnly: true,
// NOTE: the preference could change at runtime. As a best-effort way of
// keeping it in sync we'll change it every time we set the tools' context
// NOTE: the preferences could change at runtime. As a best-effort way of
// keeping them in sync we'll change them every time we set the tools' context
telemetry: enableTelemetry ? 'enabled' : 'disabled',
maxTimeMS,
});

this.runner = new InMemoryRunner({
Expand Down Expand Up @@ -271,10 +275,11 @@ export class ToolsController {
}

setContext(context: ToolsContext): void {
// make sure this property is always in sync with the tools' config
// make sure these properties are always in sync with the tools' config
this.runner.userConfig.telemetry = context.enableTelemetry
? 'enabled'
: 'disabled';
this.runner.userConfig.maxTimeMS = context.maxTimeMS;
this.context = context;
}

Expand Down
Loading