Skip to content

Commit

Permalink
feat: Add a nop replacement for remote Navie
Browse files Browse the repository at this point in the history
This provider effectively disables remote Navie and prevents
transmission of any data.
  • Loading branch information
dustinbyrne committed Jan 29, 2025
1 parent c37308f commit 42b446e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/cli/src/cmds/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import RPCServer from './rpcServer';
import appmapData from '../../rpc/appmap/data';
import { appmapStatsV1, appmapStatsV2 } from '../../rpc/appmap/stats';
import LocalNavie from '../../rpc/explain/navie/navie-local';
import RemoteNavie from '../../rpc/explain/navie/navie-remote';
import { InteractionEvent } from '@appland/navie/dist/interaction-history';
import { update } from '../../rpc/file/update';
import { AI_KEY_ENV_VARS } from './aiEnvVar';
import NopNavie from '../../rpc/explain/navie/navie-nop';

export const command = 'index';
export const describe =
Expand Down Expand Up @@ -131,11 +131,7 @@ export const handler = async (argv) => {
navie.on('event', logEvent);
return navie;
};
const buildRemoteNavie = (
contextProvider: ContextV2.ContextProvider,
projectInfoProvider: ProjectInfo.ProjectInfoProvider,
helpProvider: Help.HelpProvider
) => new RemoteNavie(contextProvider, projectInfoProvider, helpProvider);
const buildRemoteNavie = () => new NopNavie();

const navieProvider = useLocalNavie() ? buildLocalNavie : buildRemoteNavie;

Expand Down
13 changes: 5 additions & 8 deletions packages/cli/src/cmds/navie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import { configureRpcDirectories } from '../lib/handleWorkingDirectory';
import { explainHandler } from '../rpc/explain/explain';
import INavie, { INavieProvider } from '../rpc/explain/navie/inavie';
import LocalNavie from '../rpc/explain/navie/navie-local';
import RemoteNavie from '../rpc/explain/navie/navie-remote';
import type RemoteNavie from '../rpc/explain/navie/navie-remote';
import detectAIEnvVar, { AI_KEY_ENV_VARS } from './index/aiEnvVar';
import detectCodeEditor from '../lib/detectCodeEditor';
import { verbose } from '../utils';
import Trajectory from '../rpc/explain/navie/trajectory';
import { serveAndOpenNavie } from '../lib/serveAndOpen';
import RPCServer from './index/rpcServer';
import { rpcMethods } from './index/rpc';
import NopNavie from '../rpc/explain/navie/navie-nop';

interface ExplainArgs {
verbose: boolean;
Expand Down Expand Up @@ -136,7 +137,7 @@ export function buildNavieProvider(argv: ExplainArgs) {
return false;
};

const applyAIOptions = (navie: LocalNavie | RemoteNavie) => {
const applyAIOptions = (navie: LocalNavie | RemoteNavie | NopNavie) => {
if (aiOptions) {
for (const option of aiOptions) {
const [key, value] = option.split('=');
Expand Down Expand Up @@ -183,13 +184,9 @@ export function buildNavieProvider(argv: ExplainArgs) {
return navie;
};

const buildRemoteNavie = (
contextProvider: ContextV2.ContextProvider,
projectInfoProvider: ProjectInfo.ProjectInfoProvider,
helpProvider: Help.HelpProvider
) => {
const buildRemoteNavie = () => {
loadConfiguration(true);
const navie = new RemoteNavie(contextProvider, projectInfoProvider, helpProvider);
const navie = new NopNavie();
applyAIOptions(navie);

if (argv.threadId) {
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/src/rpc/explain/navie/navie-nop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import EventEmitter from 'events';
import { default as INavie } from './inavie';

export default class NopNavie extends EventEmitter implements INavie {
public readonly providerName = 'nop';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
setOption(key: string, _value: string | number) {
throw new Error(`NopNavie does not support option '${key}'`);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
ask(_threadId: string, _question: string, _codeSelection?: string, _prompt?: string) {
this.emit(
'error',
new Error(`AppMap is transitioning to a fully open-source model where you bring your own LLM, giving you complete control and ensuring your data stays with you.
With this change, the free hosted service is offline, but you can continue using Navie by configuring your own LLM provider.
For guidance on using other LLM providers such as OpenAI and Copilot, [check out our documentation](https://appmap.io/docs/using-navie-ai/bring-your-own-model.html).`)
);
return Promise.resolve();
}
}
21 changes: 21 additions & 0 deletions packages/cli/tests/unit/rpc/explain/nop-navie.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import NopNavie from '../../../../src/rpc/explain/navie/navie-nop';

describe('NopNavie', () => {
let navie: NopNavie;

beforeEach(() => {
navie = new NopNavie();
});

it('is disabled', async () => {
const onError = jest.fn();
navie.on('error', onError);
await navie.ask('threadId', 'question');
expect(onError).toHaveBeenCalledWith(
expect.objectContaining({
message: expect.stringContaining('the free hosted service is offline'),
})
);
});
});

0 comments on commit 42b446e

Please sign in to comment.