Skip to content

Commit

Permalink
Merge branch 'develop' into command-less-agents
Browse files Browse the repository at this point in the history
  • Loading branch information
samyakkkk committed Jun 6, 2024
2 parents 8ddfada + 0ae91dc commit c0dd3f7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
14 changes: 13 additions & 1 deletion vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ All notable changes to the "commanddash" extension will be documented in this fi

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.3.6]

## [0.3.91]
- Upgarde to Gemini 1.5 Flash
- Fix agent slug and marketplace glitches

## [0.3.9]
- Support processing files loader
- Attach Contextual Code within the agent requests

## [0.3.8]
- Added support to send contextual code to engine

v## [0.3.7]
- Added Dash Agents Marketplace
- Fix Github signin issue in Cursor Editor

Expand Down
15 changes: 10 additions & 5 deletions vscode/src/repository/gemini-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,26 @@ export class GeminiRepository extends GenerationRepository {
let lastMessage = prompt.pop();

// Count the tokens in the prompt
const model = this.genAI.getGenerativeModel({ model: "gemini-pro" });
const model = this.genAI.getGenerativeModel({ model: "gemini-pro" }); //TODO: upgrade this to flash model
let promptText = "";
prompt.forEach(p => promptText += p.parts);
const { totalTokens } = await model.countTokens(promptText);
console.log("Total input tokens: " + totalTokens);

// Check if the token count exceeds the limit
if (totalTokens > 30720) {
if (totalTokens > 1040384) {
throw Error('Input prompt exceeds the maximum token limit.');
}

const chat = this.genAI.getGenerativeModel({ model: "gemini-pro", generationConfig: { temperature: 0.0, topP: 0.2 } }).startChat(
const chat = this.genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", generationConfig: { temperature: 0.0, topP: 0.2 } }).startChat(
{
history: prompt, generationConfig: {
maxOutputTokens: 2048,
history: prompt.map(p => {
return {
role: p.role,
parts: [{ text: p.parts }]
};
}), generationConfig: {
maxOutputTokens: 8192,
},
}
);
Expand Down
36 changes: 24 additions & 12 deletions vscode/src/repository/http-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
import { Auth } from '../utilities/auth/auth';

const baseUrl = 'https://api.commanddash.dev';

Expand Down Expand Up @@ -42,7 +43,7 @@ export async function makeAuthorizedHttpRequest<T>(config: AxiosRequestConfig, c
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response?.status === 401 || error.response?.status === 422) {
const newAccessToken = await refreshAccessToken(refreshToken);
const newAccessToken = await refreshAccessToken(refreshToken, context);
context.globalState.update('access_token', newAccessToken);
return makeAuthorizedHttpRequest<T>(config, context);
}
Expand All @@ -54,19 +55,30 @@ export async function makeAuthorizedHttpRequest<T>(config: AxiosRequestConfig, c
}


export async function refreshAccessToken(refreshToken: string): Promise<string> {
export async function refreshAccessToken(refreshToken: string, context: vscode.ExtensionContext): Promise<string> {
const userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const response = await makeHttpRequest<{ access_token: string }>({
url: baseUrl + '/account/github/refresh', method: 'POST',
data: {
'timezone': userTimezone
},
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Authorization: `Bearer ${refreshToken}`
try {
const response: AxiosResponse<{ access_token: string }> = await axios({
url: baseUrl + '/account/github/refresh', method: 'POST',
data: {
'timezone': userTimezone
},
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Authorization: `Bearer ${refreshToken}`
}
});

return response.data.access_token;
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response?.status === 401) {
// Refresh token has expired, sign in the user again
return await Auth.getInstance().signInWithGithub(context);
}
}
});
return response.access_token;
throw error;
}
}


Expand Down
3 changes: 2 additions & 1 deletion vscode/src/utilities/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Auth {
return this.cacheManager.getGlobalValue<string>('access_token');
}

public async signInWithGithub(context: vscode.ExtensionContext): Promise<void> {
public async signInWithGithub(context: vscode.ExtensionContext): Promise<string> {
const url = '/account/github/url/' + vscode.env.uriScheme;
const { github_oauth_url } = await makeHttpRequest<{ github_oauth_url: string }>({ url: url });
vscode.env.openExternal(vscode.Uri.parse(github_oauth_url));
Expand Down Expand Up @@ -68,6 +68,7 @@ export class Auth {
const { accessToken, refreshToken } = await authPromise;
await context.globalState.update('access_token', accessToken);
await context.globalState.update('refresh_token', refreshToken);
return refreshToken;
}

public async signOutFromGithub(context: vscode.ExtensionContext): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/utilities/setup-manager/setup-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SetupManager {
this.dartClient.onProcessOperation('refresh_access_token', async (message) => {
let refreshToken = this.auth.getGithubRefreshToken();
if (refreshToken) {
let accessToken = await refreshAccessToken(refreshToken);
let accessToken = await refreshAccessToken(refreshToken, context);
this.dartClient?.sendOperationResponse(message, {
'access_token': accessToken
});
Expand Down

0 comments on commit c0dd3f7

Please sign in to comment.