bootstrap new electron app

This commit is contained in:
Ramnique Singh 2025-12-29 15:30:57 +05:30
parent 2491bacea1
commit 505e3ea620
89 changed files with 12397 additions and 8435 deletions

View file

@ -19,474 +19,6 @@ import { cors } from 'hono/cors';
let id = 0;
const routes = new Hono()
.get(
'/health',
describeRoute({
summary: 'Health check',
description: 'Check if the server is running',
responses: {
200: {
description: 'Server is running',
content: {
'application/json': {
schema: resolver(z.object({
status: z.literal("ok"),
})),
},
},
},
},
}),
async (c) => {
return c.json({ status: 'ok' });
}
)
.get(
'/mcp',
describeRoute({
summary: 'List MCP servers',
description: 'List the MCP servers',
responses: {
200: {
description: 'Server list',
content: {
'application/json': {
schema: resolver(McpServerList),
},
},
},
},
}),
async (c) => {
return c.json(await listServers());
}
)
.put(
'/mcp/:serverName',
describeRoute({
summary: 'Upsert MCP server',
description: 'Add or edit MCP server',
responses: {
200: {
description: 'MCP server added / updated',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('param', z.object({
serverName: z.string(),
})),
validator('json', McpServerDefinition),
async (c) => {
const repo = container.resolve<IMcpConfigRepo>('mcpConfigRepo');
await repo.upsert(c.req.valid('param').serverName, c.req.valid('json'));
return c.json({ success: true });
}
)
.delete(
'/mcp/:serverName',
describeRoute({
summary: 'Delete MCP server',
description: 'Delete a MCP server',
responses: {
200: {
description: 'MCP server deleted',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('param', z.object({
serverName: z.string(),
})),
async (c) => {
const repo = container.resolve<IMcpConfigRepo>('mcpConfigRepo');
await repo.delete(c.req.valid('param').serverName);
return c.json({ success: true });
}
)
.get(
'/mcp/:serverName/tools',
describeRoute({
summary: 'Get MCP tools',
description: 'Get the MCP tools',
responses: {
200: {
description: 'MCP tools',
content: {
'application/json': {
schema: resolver(ListToolsResponse),
},
},
},
},
}),
validator('query', z.object({
cursor: z.string().optional(),
})),
validator('param', z.object({
serverName: z.string(),
})),
async (c) => {
const result = await listTools(c.req.valid('param').serverName, c.req.valid('query').cursor);
return c.json(result);
}
)
.post(
'/mcp/:serverName/tools/:toolName/execute',
describeRoute({
summary: 'Execute MCP tool',
description: 'Execute a MCP tool',
responses: {
200: {
description: 'Tool executed',
content: {
'application/json': {
schema: resolver(z.object({
result: z.any(),
})),
},
},
},
},
}),
validator('param', z.object({
serverName: z.string(),
toolName: z.string(),
})),
validator('json', z.object({
input: z.any(),
})),
async (c) => {
const result = await executeTool(
c.req.valid('param').serverName,
c.req.valid('param').toolName,
c.req.valid('json').input
);
return c.json(result);
}
)
.get(
'/models',
describeRoute({
summary: 'Get model config',
description: 'Get the current model and provider configuration',
responses: {
200: {
description: 'Model config',
content: {
'application/json': {
schema: resolver(ModelConfig),
},
},
},
},
}),
async (c) => {
const repo = container.resolve<IModelConfigRepo>('modelConfigRepo');
const config = await repo.getConfig();
return c.json(config);
}
)
.put(
'/models/providers/:providerName',
describeRoute({
summary: 'Upsert provider config',
description: 'Add or update a provider configuration',
responses: {
200: {
description: 'Provider upserted',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('param', z.object({
providerName: z.string(),
})),
validator('json', Provider),
async (c) => {
const repo = container.resolve<IModelConfigRepo>('modelConfigRepo');
await repo.upsert(c.req.valid('param').providerName, c.req.valid('json'));
return c.json({ success: true });
}
)
.delete(
'/models/providers/:providerName',
describeRoute({
summary: 'Delete provider config',
description: 'Delete a provider configuration',
responses: {
200: {
description: 'Provider deleted',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('param', z.object({
providerName: z.string(),
})),
async (c) => {
const repo = container.resolve<IModelConfigRepo>('modelConfigRepo');
await repo.delete(c.req.valid('param').providerName);
return c.json({ success: true });
}
)
.put(
'/models/default',
describeRoute({
summary: 'Set default model',
description: 'Set the default provider and model',
responses: {
200: {
description: 'Default set',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('json', z.object({
provider: z.string(),
model: z.string(),
})),
async (c) => {
const repo = container.resolve<IModelConfigRepo>('modelConfigRepo');
const body = c.req.valid('json');
await repo.setDefault(body.provider, body.model);
return c.json({ success: true });
}
)
// GET /agents
.get(
'/agents',
describeRoute({
summary: 'List agents',
description: 'List all configured agents',
responses: {
200: {
description: 'Agents list',
content: {
'application/json': {
schema: resolver(z.array(Agent)),
},
},
},
},
}),
async (c) => {
const repo = container.resolve<IAgentsRepo>('agentsRepo');
const agents = await repo.list();
return c.json(agents);
}
)
// POST /agents/new
.post(
'/agents/new',
describeRoute({
summary: 'Create agent',
description: 'Create a new agent',
responses: {
200: {
description: 'Agent created',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('json', Agent),
async (c) => {
const repo = container.resolve<IAgentsRepo>('agentsRepo');
await repo.create(c.req.valid('json'));
return c.json({ success: true });
}
)
// GET /agents/<id>
.get(
'/agents/:id',
describeRoute({
summary: 'Get agent',
description: 'Fetch a specific agent by id',
responses: {
200: {
description: 'Agent',
content: {
'application/json': {
schema: resolver(Agent),
},
},
},
},
}),
validator('param', z.object({
id: z.string(),
})),
async (c) => {
const repo = container.resolve<IAgentsRepo>('agentsRepo');
const agent = await repo.fetch(c.req.valid('param').id);
return c.json(agent);
}
)
// PUT /agents/<id>
.put(
'/agents/:id',
describeRoute({
summary: 'Update agent',
description: 'Update an existing agent',
responses: {
200: {
description: 'Agent updated',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('param', z.object({
id: z.string(),
})),
validator('json', Agent),
async (c) => {
const repo = container.resolve<IAgentsRepo>('agentsRepo');
await repo.update(c.req.valid('param').id, c.req.valid('json'));
return c.json({ success: true });
}
)
// DELETE /agents/<id>
.delete(
'/agents/:id',
describeRoute({
summary: 'Delete agent',
description: 'Delete an agent by id',
responses: {
200: {
description: 'Agent deleted',
content: {
'application/json': {
schema: resolver(z.object({
success: z.literal(true),
})),
},
},
},
},
}),
validator('param', z.object({
id: z.string(),
})),
async (c) => {
const repo = container.resolve<IAgentsRepo>('agentsRepo');
await repo.delete(c.req.valid('param').id);
return c.json({ success: true });
}
)
.get(
'/runs/:runId',
describeRoute({
summary: 'Get run',
description: 'Get a run by id',
responses: {
200: {
description: 'Run',
content: {
'application/json': {
schema: resolver(Run),
},
},
},
},
}),
validator('param', z.object({
runId: z.string(),
})),
async (c) => {
const repo = container.resolve<IRunsRepo>('runsRepo');
const run = await repo.fetch(c.req.valid('param').runId);
return c.json(run);
}
)
.post(
'/runs/new',
describeRoute({
summary: 'Create run',
description: 'Create a new run',
responses: {
200: {
description: 'Run created',
content: {
'application/json': {
schema: resolver(Run),
},
},
},
},
}),
validator('json', CreateRunOptions),
async (c) => {
const run = await createRun(c.req.valid('json'));
return c.json(run);
}
)
.get(
'/runs',
describeRoute({
summary: 'List runs',
description: 'List all runs',
responses: {
200: {
description: 'Runs list',
content: {
'application/json': {
schema: resolver(ListRunsResponse),
},
},
},
},
}),
validator('query', z.object({
cursor: z.string().optional(),
})),
async (c) => {
const repo = container.resolve<IRunsRepo>('runsRepo');
const runs = await repo.list(c.req.valid('query').cursor);
return c.json(runs);
}
)
.post(
'/runs/:runId/messages/new',
describeRoute({