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
5 changes: 0 additions & 5 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,6 @@ export const providers: ProvidersMap = {
const githubDataPath = path.join(globalConfigDir, 'githubCopilot.json');
const githubProvider = new GithubProvider({ authFile: githubDataPath });
const token = await githubProvider.access();
if (!token) {
throw new Error(
'Failed to get GitHub Copilot token, use /login to login first',
);
}
return createOpenAI({
baseURL: 'https://api.individual.githubcopilot.com',
headers: {
Expand Down
22 changes: 22 additions & 0 deletions src/nodeBridge.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import { compact } from './compact';
import { type ApprovalMode, type Config, ConfigManager } from './config';
import { CANCELED_MESSAGE_TEXT } from './constants';
Expand Down Expand Up @@ -932,6 +933,27 @@ class NodeHandlerRegistry {
};
},
);

this.messageBus.registerHandler(
'utils.checkGithubCopilotLogin',
async (data: { cwd: string }) => {
const { cwd } = data;
const context = await this.getContext(cwd);
const { GithubProvider } = await import('./providers/githubCopilot');
const githubDataPath = path.join(
context.paths.globalConfigDir,
'githubCopilot.json',
);
const githubProvider = new GithubProvider({ authFile: githubDataPath });
const token = await githubProvider.access();
return {
success: true,
data: {
loggedIn: !!token,
},
};
},
);
}
}

Expand Down
54 changes: 50 additions & 4 deletions src/slash-commands/builtin/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const ModelSelect: React.FC<ModelSelectProps> = ({
modelId: string;
} | null>(null);
const [groupedModels, setGroupedModels] = useState<GroupedData[]>([]);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
bridge.request('models.list', { cwd }).then((result) => {
Expand All @@ -40,6 +41,54 @@ export const ModelSelect: React.FC<ModelSelectProps> = ({
});
}, [cwd]);

const handleSelect = async (item: { value: string }) => {
if (item.value.startsWith('github-copilot/')) {
const loginCheckResult = await bridge.request(
'utils.checkGithubCopilotLogin',
{ cwd },
);
if (!loginCheckResult.data.loggedIn) {
setError(
'GitHub Copilot is not logged in. Please use /login command first.',
);
return;
}
}
setError(null);
setModel(item.value);
onSelect(item.value);
};

useInput((_input, key) => {
if (key.return && error) {
setError(null);
}
});

if (error) {
return (
<Box
borderStyle="round"
borderColor="red"
flexDirection="column"
padding={1}
width="100%"
>
<Box marginBottom={1}>
<Text bold color="red">
Login Required
</Text>
</Box>
<Box>
<Text color="gray">{error}</Text>
</Box>
<Box marginTop={1}>
<Text color="gray">Press Enter to continue...</Text>
</Box>
</Box>
);
}

return (
<Box
borderStyle="round"
Expand Down Expand Up @@ -68,10 +117,7 @@ export const ModelSelect: React.FC<ModelSelectProps> = ({
itemsPerPage={15}
enableSearch={true}
onCancel={() => onExit(currentModel)}
onSelect={(item) => {
setModel(item.value);
onSelect(item.value);
}}
onSelect={handleSelect}
/>
</Box>
</Box>
Expand Down
81 changes: 0 additions & 81 deletions src/ui/OnBoarding.tsx

This file was deleted.

19 changes: 17 additions & 2 deletions src/ui/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,30 @@ export const useAppStore = create<AppStore>()(
},

send: async (message) => {
const { bridge, cwd, sessionId, planMode, status, pastedTextMap } =
get();
const {
bridge,
cwd,
sessionId,
planMode,
status,
pastedTextMap,
model,
} = get();

bridge.request('utils.telemetry', {
cwd,
name: 'send',
payload: { message, sessionId },
});

if (!isSlashCommand(message) && !model) {
set({
status: 'failed',
error: 'Please select a model first (use /model command)',
});
return;
}

// Check if processing, queue the message
if (isExecuting(status)) {
get().addToQueue(message);
Expand Down
Loading