mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
* wip on refactoring docs * wip * initial structured logs impl * structured log docs * create logger package * add news entry for structured logging * add logger package to dockerfile and cleanup * add gh workflow for catching broken links * further wip * fix * further wip on docs * review feedback * remove logger dep from mcp package * fix build errors * add back auth_url warning * fix sidebar title consistency --------- Co-authored-by: bkellam <bshizzle1234@gmail.com>
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
import { env } from './env.js';
|
|
import { listRepositoriesResponseSchema, searchResponseSchema, fileSourceResponseSchema } from './schemas.js';
|
|
import { FileSourceRequest, FileSourceResponse, ListRepositoriesResponse, SearchRequest, SearchResponse, ServiceError } from './types.js';
|
|
import { isServiceError } from './utils.js';
|
|
|
|
export const search = async (request: SearchRequest): Promise<SearchResponse | ServiceError> => {
|
|
console.debug(`Executing search request: ${JSON.stringify(request, null, 2)}`);
|
|
const result = await fetch(`${env.SOURCEBOT_HOST}/api/search`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Org-Domain': '~',
|
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
},
|
|
body: JSON.stringify(request)
|
|
}).then(response => response.json());
|
|
|
|
if (isServiceError(result)) {
|
|
return result;
|
|
}
|
|
|
|
return searchResponseSchema.parse(result);
|
|
}
|
|
|
|
export const listRepos = async (): Promise<ListRepositoriesResponse | ServiceError> => {
|
|
const result = await fetch(`${env.SOURCEBOT_HOST}/api/repos`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Org-Domain': '~',
|
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
},
|
|
}).then(response => response.json());
|
|
|
|
if (isServiceError(result)) {
|
|
return result;
|
|
}
|
|
|
|
return listRepositoriesResponseSchema.parse(result);
|
|
}
|
|
|
|
export const getFileSource = async (request: FileSourceRequest): Promise<FileSourceResponse | ServiceError> => {
|
|
const result = await fetch(`${env.SOURCEBOT_HOST}/api/source`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Org-Domain': '~',
|
|
...(env.SOURCEBOT_API_KEY ? { 'X-Sourcebot-Api-Key': env.SOURCEBOT_API_KEY } : {})
|
|
},
|
|
body: JSON.stringify(request)
|
|
}).then(response => response.json());
|
|
|
|
if (isServiceError(result)) {
|
|
return result;
|
|
}
|
|
|
|
return fileSourceResponseSchema.parse(result);
|
|
}
|