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

Function registerFsRoutes

packages/server/src/routes/fs.ts:102–328  ·  view source on GitHub ↗
(
  app: FsRouteHost,
  ix: IInstantiationService,
)

Source from the content-addressed store, hash-verified

100const FS_TAIL_PREFIX = 'fs:';
101
102export function registerFsRoutes(
103 app: FsRouteHost,
104 ix: IInstantiationService,
105): void {
106
107 const fsActionRoute = defineRoute(
108 {
109 method: 'POST',
110 path: '/sessions/{session_id}/{tail}',
111 params: sessionIdAndTailParamSchema,
112 errors: {
113 [ErrorCode.VALIDATION_FAILED]: {},
114 [ErrorCode.SESSION_NOT_FOUND]: {},
115 [ErrorCode.FS_PATH_NOT_FOUND]: {},
116 [ErrorCode.FS_IS_DIRECTORY]: {},
117 [ErrorCode.FS_IS_BINARY]: {},
118 [ErrorCode.FS_TOO_LARGE]: {},
119 [ErrorCode.FS_TOO_MANY_RESULTS]: {},
120 [ErrorCode.FS_PATH_ESCAPES_SESSION]: {},
121 [ErrorCode.FS_GREP_TIMEOUT]: {},
122 [ErrorCode.FS_GIT_UNAVAILABLE]: {},
123 [ErrorCode.FS_ALREADY_EXISTS]: {},
124 },
125 description:
126 'Filesystem action dispatcher. Supported actions: list, read, list_many, stat, stat_many, mkdir, search, grep, git_status, diff, open, reveal.',
127 tags: ['fs'],
128 operationId: 'fsAction',
129 },
130 async (req, reply) => {
131 const { session_id, tail } = req.params;
132
133 if (!tail.startsWith(FS_TAIL_PREFIX)) {
134
135 reply.send(
136 errEnvelope(
137 ErrorCode.VALIDATION_FAILED,
138 `unsupported action: ${tail}`,
139 req.id,
140 ),
141 );
142 return;
143 }
144
145 const action = tail.slice(FS_TAIL_PREFIX.length);
146 if (!(FS_ACTIONS as readonly string[]).includes(action)) {
147 reply.send(
148 errEnvelope(
149 ErrorCode.VALIDATION_FAILED,
150 `unsupported action: ${tail}`,
151 req.id,
152 ),
153 );
154 return;
155 }
156 const fsAction = action as FsAction;
157
158 try {
159 switch (fsAction) {

Callers 1

registerApiV1RoutesFunction · 0.90

Calls 15

defineRouteFunction · 0.90
errEnvelopeFunction · 0.90
handleListFunction · 0.85
handleReadFunction · 0.85
handleListManyFunction · 0.85
handleStatFunction · 0.85
handleStatManyFunction · 0.85
handleMkdirFunction · 0.85
handleSearchFunction · 0.85
handleGrepFunction · 0.85
handleGitStatusFunction · 0.85
handleDiffFunction · 0.85

Tested by

no test coverage detected