Skip to content

Commit b984631

Browse files
committed
a couple of coderabbit fixes
1 parent 6f29e29 commit b984631

File tree

5 files changed

+63
-47
lines changed

5 files changed

+63
-47
lines changed

apps/webapp/app/routes/api.v1.projects.$projectRef.dev-status.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { json, type LoaderFunctionArgs } from "@remix-run/server-runtime";
1+
import { json, type LoaderFunctionArgs } from "@remix-run/node";
22
import { z } from "zod";
33
import { prisma } from "~/db.server";
44
import { devPresence } from "~/presenters/v3/DevPresence.server";
@@ -9,8 +9,6 @@ const ParamsSchema = z.object({
99
projectRef: z.string(),
1010
});
1111

12-
type ParamsSchema = z.infer<typeof ParamsSchema>;
13-
1412
export async function loader({ request, params }: LoaderFunctionArgs) {
1513
const authenticationResult = await authenticateApiRequestWithPersonalAccessToken(request);
1614

packages/cli-v3/src/mcp/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ export class McpContext {
119119
// If cwd is a path to the actual trigger.config.ts file, then we should set the cwd to the directory of the file
120120
let $cwd = cwd ? (path.extname(cwd) !== "" ? path.dirname(cwd) : cwd) : undefined;
121121

122-
function isRelativePath(path: string) {
123-
return !path.startsWith("/");
122+
function isRelativePath(filePath: string) {
123+
return !path.isAbsolute(filePath);
124124
}
125125

126126
if (!cwd) {

packages/cli-v3/src/mcp/tools/deploys.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ async function resolveCLIExec(context: McpContext, cwd?: string): Promise<[strin
146146
sdkVersion,
147147
});
148148

149-
return [process.argv[0] ?? "npx", process.argv[1] ?? "trigger.dev@latest"];
149+
if (typeof process.argv[0] === "string" && typeof process.argv[1] === "string") {
150+
return [process.argv[0], process.argv[1]];
151+
}
152+
153+
return ["npx", "trigger.dev@latest"];
150154
}
151155

152156
return ["npx", `trigger.dev@${sdkVersion}`];

packages/cli-v3/src/mcp/tools/orgs.ts

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,62 +141,70 @@ export const initializeProjectTool = {
141141
handler: toolHandler(InitializeProjectInput.shape, async (input, { ctx }) => {
142142
ctx.logger?.log("calling initialize_project", { input });
143143

144-
const cwd = input.cwd ?? (await ctx.getCwd());
144+
let projectRef: string | undefined = input.projectRef;
145145

146-
if (!cwd) {
147-
return respondWithError(
148-
"No current working directory found. Please provide a projectRef or a cwd."
149-
);
150-
}
146+
if (!projectRef) {
147+
const cwd = input.cwd ?? (await ctx.getCwd());
151148

152-
// Try to load the config file
153-
const [_, config] = await tryCatch(loadConfig({ cwd }));
154-
155-
if (config?.configFile) {
156-
if (typeof config.project === "string" && config.project.startsWith("proj_")) {
157-
ctx.logger?.log("initialize_project existing project", {
158-
config,
159-
projectRef: config.project,
160-
});
161-
162-
return {
163-
content: [
164-
{
165-
type: "text",
166-
text: `We found an existing trigger.config.ts file in the current working directory. Skipping initialization.`,
167-
},
168-
],
169-
};
170-
} else {
149+
if (!cwd) {
171150
return respondWithError(
172-
"Could not find the project ref in the config file. Please provide a projectRef."
151+
"No current working directory found. Please provide a projectRef or a cwd."
173152
);
174153
}
175-
}
176154

177-
const cliApiClient = await ctx.getCliApiClient();
155+
// Try to load the config file
156+
const [_, config] = await tryCatch(loadConfig({ cwd }));
157+
158+
if (config?.configFile) {
159+
if (typeof config.project === "string" && config.project.startsWith("proj_")) {
160+
ctx.logger?.log("initialize_project existing project", {
161+
config,
162+
projectRef: config.project,
163+
});
164+
165+
return {
166+
content: [
167+
{
168+
type: "text",
169+
text: `We found an existing trigger.config.ts file in the current working directory. Skipping initialization.`,
170+
},
171+
],
172+
};
173+
} else {
174+
return respondWithError(
175+
"Could not find the project ref in the config file. Please provide a projectRef."
176+
);
177+
}
178+
}
178179

179-
const project = await cliApiClient.createProject(input.orgParam, {
180-
name: input.projectName,
181-
});
180+
const cliApiClient = await ctx.getCliApiClient();
182181

183-
if (!project.success) {
184-
return respondWithError(
185-
`Failed to create project ${input.projectName} in organization ${input.orgParam}: ${project.error}`
186-
);
182+
const project = await cliApiClient.createProject(input.orgParam, {
183+
name: input.projectName,
184+
});
185+
186+
if (!project.success) {
187+
return respondWithError(
188+
`Failed to create project ${input.projectName} in organization ${input.orgParam}: ${project.error}`
189+
);
190+
}
191+
192+
ctx.logger?.log("initialize_project new project", {
193+
project: project.data,
194+
});
195+
196+
projectRef = project.data.externalRef;
187197
}
188198

189-
ctx.logger?.log("initialize_project new project", {
190-
project: project.data,
191-
});
199+
const cliApiClient = await ctx.getCliApiClient();
192200

193201
const projectEnv = await cliApiClient.getProjectEnv({
194-
projectRef: project.data.externalRef,
202+
projectRef: projectRef,
195203
env: "dev",
196204
});
197205

198206
const manualSetupGuide = await getManualSetupGuide(
199-
project.data.externalRef,
207+
projectRef,
200208
projectEnv.success ? projectEnv.data.apiKey : undefined,
201209
projectEnv.success ? projectEnv.data.apiUrl : undefined
202210
);

packages/core/src/v3/schemas/api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export const GetOrgsResponseBody = z.array(
6363
export type GetOrgsResponseBody = z.infer<typeof GetOrgsResponseBody>;
6464

6565
export const CreateProjectRequestBody = z.object({
66-
name: z.string(),
66+
name: z
67+
.string()
68+
.trim()
69+
.min(1, "Name is required")
70+
.max(255, "Name must be less than 255 characters"),
6771
});
6872

6973
export type CreateProjectRequestBody = z.infer<typeof CreateProjectRequestBody>;
@@ -1158,6 +1162,8 @@ const ApiDeploymentListPaginationCursor = z
11581162
const ApiDeploymentListPaginationLimit = z.coerce
11591163
.number()
11601164
.describe("The number of deployments to return, defaults to 20 (max 100)")
1165+
.min(1, "Limit must be at least 1")
1166+
.max(100, "Limit must be less than 100")
11611167
.optional();
11621168

11631169
export const ApiDeploymentListParams = {

0 commit comments

Comments
 (0)