mirror of
https://github.com/larsbaunwall/vscode-copilot-bridge.git
synced 2025-10-05 22:22:59 +00:00
Refactor code to be more clean and modularized. Bump package version
This commit is contained in:
parent
ef1526c76a
commit
70a077ca51
11 changed files with 701 additions and 251 deletions
|
|
@ -1,13 +1,31 @@
|
|||
import { writeJson } from '../utils';
|
||||
import { writeJson, writeErrorResponse } from '../utils';
|
||||
import { listCopilotModels } from '../../models';
|
||||
import { verbose } from '../../log';
|
||||
import type { ServerResponse } from 'http';
|
||||
|
||||
interface ModelObject {
|
||||
readonly id: string;
|
||||
readonly object: 'model';
|
||||
readonly created: number;
|
||||
readonly owned_by: string;
|
||||
readonly permission: readonly unknown[];
|
||||
readonly root: string;
|
||||
readonly parent: null;
|
||||
}
|
||||
|
||||
interface ModelsListResponse {
|
||||
readonly object: 'list';
|
||||
readonly data: readonly ModelObject[];
|
||||
}
|
||||
|
||||
export const handleModelsRequest = async (res: ServerResponse): Promise<void> => {
|
||||
try {
|
||||
const modelIds = await listCopilotModels();
|
||||
const models = modelIds.map((id: string) => ({
|
||||
verbose(`Models listed: ${modelIds.length} available`);
|
||||
|
||||
const models: ModelObject[] = modelIds.map((id: string) => ({
|
||||
id,
|
||||
object: 'model',
|
||||
object: 'model' as const,
|
||||
created: Math.floor(Date.now() / 1000),
|
||||
owned_by: 'copilot',
|
||||
permission: [],
|
||||
|
|
@ -15,18 +33,15 @@ export const handleModelsRequest = async (res: ServerResponse): Promise<void> =>
|
|||
parent: null,
|
||||
}));
|
||||
|
||||
writeJson(res, 200, {
|
||||
const response: ModelsListResponse = {
|
||||
object: 'list',
|
||||
data: models,
|
||||
});
|
||||
};
|
||||
|
||||
writeJson(res, 200, response);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e);
|
||||
writeJson(res, 500, {
|
||||
error: {
|
||||
message: msg || 'Failed to list models',
|
||||
type: 'server_error',
|
||||
code: 'internal_error'
|
||||
}
|
||||
});
|
||||
verbose(`Models request failed: ${msg}`);
|
||||
writeErrorResponse(res, 500, msg || 'Failed to list models', 'server_error', 'internal_error');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue