MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / registerTerminalsRoutes

Function registerTerminalsRoutes

packages/server/src/routes/terminals.ts:51–179  ·  view source on GitHub ↗
(
  app: TerminalsRouteHost,
  ix: IInstantiationService,
)

Source from the content-addressed store, hash-verified

49const detailsSchema = z.array(z.object({ path: z.string(), message: z.string() }));
50
51export function registerTerminalsRoutes(
52 app: TerminalsRouteHost,
53 ix: IInstantiationService,
54): void {
55 const listRoute = defineRoute(
56 {
57 method: 'GET',
58 path: '/sessions/{session_id}/terminals',
59 params: sessionIdParamSchema,
60 success: { data: listTerminalsResponseSchema },
61 errors: {
62 [ErrorCode.VALIDATION_FAILED]: { detailsSchema },
63 [ErrorCode.SESSION_NOT_FOUND]: {},
64 },
65 description: 'List terminals for a session',
66 tags: ['terminals'],
67 },
68 async (req, reply) => {
69 try {
70 const { session_id } = req.params;
71 const items = await ix.invokeFunction((a) =>
72 a.get(ITerminalService).list(session_id),
73 );
74 reply.send(okEnvelope({ items }, req.id));
75 } catch (err) {
76 sendMappedError(reply, req.id, err);
77 }
78 },
79 );
80 app.get(listRoute.path, listRoute.options, listRoute.handler as Parameters<TerminalsRouteHost['get']>[2]);
81
82 const createRoute = defineRoute(
83 {
84 method: 'POST',
85 path: '/sessions/{session_id}/terminals',
86 params: sessionIdParamSchema,
87 body: createTerminalRequestSchema,
88 success: { data: getTerminalResponseSchema },
89 errors: {
90 [ErrorCode.VALIDATION_FAILED]: { detailsSchema },
91 [ErrorCode.SESSION_NOT_FOUND]: {},
92 [ErrorCode.FS_PATH_ESCAPES_SESSION]: {},
93 },
94 description: 'Create a terminal for a session',
95 tags: ['terminals'],
96 },
97 async (req, reply) => {
98 try {
99 const { session_id } = req.params;
100 const terminal = await ix.invokeFunction((a) =>
101 a.get(ITerminalService).create(session_id, req.body),
102 );
103 reply.send(okEnvelope(terminal, req.id));
104 } catch (err) {
105 sendMappedError(reply, req.id, err);
106 }
107 },
108 );

Callers 1

registerApiV1RoutesFunction · 0.90

Calls 12

defineRouteFunction · 0.90
okEnvelopeFunction · 0.90
parseActionSuffixFunction · 0.90
errEnvelopeFunction · 0.90
sendMappedErrorFunction · 0.70
invokeFunctionMethod · 0.65
listMethod · 0.65
getMethod · 0.65
sendMethod · 0.65
createMethod · 0.65
postMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected