Fix linting issues

This commit is contained in:
Oliver Jägle
2024-11-21 22:27:29 +01:00
parent fe3e2ebddf
commit 7d8f811886
11 changed files with 65 additions and 46 deletions

View File

@@ -192,7 +192,7 @@ const PROVIDER_LIST: ProviderInfo[] = [
{ name: 'deepseek-coder', label: 'Deepseek-Coder', provider: 'Deepseek', maxTokenAllowed: 8000 },
{ name: 'deepseek-chat', label: 'Deepseek-Chat', provider: 'Deepseek', maxTokenAllowed: 8000 },
],
getApiKeyLink: 'https://platform.deepseek.com/api_keys',
getApiKeyLink: 'https://platform.deepseek.com/apiKeys',
},
{
name: 'Mistral',
@@ -242,8 +242,8 @@ const getOllamaBaseUrl = () => {
async function getOllamaModels(): Promise<ModelInfo[]> {
try {
const base_url = getOllamaBaseUrl();
const response = await fetch(`${base_url}/api/tags`);
const baseUrl = getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`);
const data = (await response.json()) as OllamaApiResponse;
return data.models.map((model: OllamaModel) => ({
@@ -252,6 +252,7 @@ async function getOllamaModels(): Promise<ModelInfo[]> {
provider: 'Ollama',
maxTokenAllowed: 8000,
}));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return [];
}
@@ -259,16 +260,16 @@ async function getOllamaModels(): Promise<ModelInfo[]> {
async function getOpenAILikeModels(): Promise<ModelInfo[]> {
try {
const base_url = import.meta.env.OPENAI_LIKE_API_BASE_URL || '';
const baseUrl = import.meta.env.OPENAI_LIKE_API_BASE_URL || '';
if (!base_url) {
if (!baseUrl) {
return [];
}
const api_key = import.meta.env.OPENAI_LIKE_API_KEY ?? '';
const response = await fetch(`${base_url}/models`, {
const apiKey = import.meta.env.OPENAI_LIKE_API_KEY ?? '';
const response = await fetch(`${baseUrl}/models`, {
headers: {
Authorization: `Bearer ${api_key}`,
Authorization: `Bearer ${apiKey}`,
},
});
const res = (await response.json()) as any;
@@ -278,6 +279,7 @@ async function getOpenAILikeModels(): Promise<ModelInfo[]> {
label: model.id,
provider: 'OpenAILike',
}));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return [];
}
@@ -318,8 +320,8 @@ async function getOpenRouterModels(): Promise<ModelInfo[]> {
async function getLMStudioModels(): Promise<ModelInfo[]> {
try {
const base_url = import.meta.env.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
const response = await fetch(`${base_url}/v1/models`);
const baseUrl = import.meta.env.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
const response = await fetch(`${baseUrl}/v1/models`);
const data = (await response.json()) as any;
return data.data.map((model: any) => ({
@@ -327,6 +329,7 @@ async function getLMStudioModels(): Promise<ModelInfo[]> {
label: model.id,
provider: 'LMStudio',
}));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e) {
return [];
}

View File

@@ -52,6 +52,8 @@ export async function newShellProcess(webcontainer: WebContainer, terminal: ITer
return process;
}
export type ExecutionResult = { output: string; exitCode: number } | undefined;
export class BoltShell {
#initialized: (() => void) | undefined;
#readyPromise: Promise<void>;
@@ -61,36 +63,39 @@ export class BoltShell {
executionState = atom<{ sessionId: string; active: boolean; executionPrms?: Promise<any> } | undefined>();
#outputStream: ReadableStreamDefaultReader<string> | undefined;
#shellInputStream: WritableStreamDefaultWriter<string> | undefined;
constructor() {
this.#readyPromise = new Promise((resolve) => {
this.#initialized = resolve;
});
}
ready() {
return this.#readyPromise;
}
async init(webcontainer: WebContainer, terminal: ITerminal) {
this.#webcontainer = webcontainer;
this.#terminal = terminal;
const callback = (data: string) => {
console.log(data);
};
const { process, output } = await this.newBoltShellProcess(webcontainer, terminal);
this.#process = process;
this.#outputStream = output.getReader();
await this.waitTillOscCode('interactive');
this.#initialized?.();
}
get terminal() {
return this.#terminal;
}
get process() {
return this.#process;
}
async executeCommand(sessionId: string, command: string) {
async executeCommand(sessionId: string, command: string): Promise<ExecutionResult> {
if (!this.process || !this.terminal) {
return;
return undefined;
}
const state = this.executionState.get();
@@ -109,14 +114,15 @@ export class BoltShell {
this.terminal.input(command.trim() + '\n');
//wait for the execution to finish
const executionPrms = this.getCurrentExecutionResult();
this.executionState.set({ sessionId, active: true, executionPrms });
const executionPromise = this.getCurrentExecutionResult();
this.executionState.set({ sessionId, active: true, executionPrms: executionPromise });
const resp = await executionPrms;
const resp = await executionPromise;
this.executionState.set({ sessionId, active: false });
return resp;
}
async newBoltShellProcess(webcontainer: WebContainer, terminal: ITerminal) {
const args: string[] = [];
@@ -167,10 +173,12 @@ export class BoltShell {
return { process, output: internalOutput };
}
async getCurrentExecutionResult() {
async getCurrentExecutionResult(): Promise<ExecutionResult> {
const { output, exitCode } = await this.waitTillOscCode('exit');
return { output, exitCode };
}
async waitTillOscCode(waitCode: string) {
let fullOutput = '';
let exitCode: number = 0;
@@ -192,7 +200,7 @@ export class BoltShell {
fullOutput += text;
// Check if command completion signal with exit code
const [, osc, , pid, code] = text.match(/\x1b\]654;([^\x07=]+)=?((-?\d+):(\d+))?\x07/) || [];
const [, osc, , , code] = text.match(/\x1b\]654;([^\x07=]+)=?((-?\d+):(\d+))?\x07/) || [];
if (osc === 'exit') {
exitCode = parseInt(code, 10);
@@ -206,6 +214,7 @@ export class BoltShell {
return { output: fullOutput, exitCode };
}
}
export function newBoltShellProcess() {
return new BoltShell();
}