-
Notifications
You must be signed in to change notification settings - Fork 17
fix: include deployment agent configs in v1 responses #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||
| import type { AsyncTypedHandler } from "@/types/api.js"; | ||||||||||||||
| import { ApiError, asyncHandler } from "@/types/api.js"; | ||||||||||||||
| import { Router } from "express"; | ||||||||||||||
| import _ from "lodash"; | ||||||||||||||
| import { v4 as uuidv4 } from "uuid"; | ||||||||||||||
|
|
||||||||||||||
| import { and, asc, count, desc, eq, inArray, takeFirst } from "@ctrlplane/db"; | ||||||||||||||
|
|
@@ -12,14 +13,30 @@ import { | |||||||||||||
| } from "@ctrlplane/db/reconcilers"; | ||||||||||||||
| import * as schema from "@ctrlplane/db/schema"; | ||||||||||||||
|
|
||||||||||||||
| const PLAN_TTL_MS = 60 * 60 * 1000; // 1 hour | ||||||||||||||
| // 1 hour | ||||||||||||||
|
|
||||||||||||||
| import { validResourceSelector } from "../valid-selector.js"; | ||||||||||||||
| import { listDeploymentVariablesByDeploymentRouter } from "./deployment-variables.js"; | ||||||||||||||
|
|
||||||||||||||
|
Comment on lines
+16
to
20
|
||||||||||||||
| const parseSelector = ( | ||||||||||||||
| raw: string | null | undefined, | ||||||||||||||
| ): string | undefined => { | ||||||||||||||
| const PLAN_TTL_MS = 60 * 60 * 1000; | ||||||||||||||
|
Comment on lines
+16
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is detached from the constant it describes. The 📝 Suggested fix-// 1 hour
-
import { validResourceSelector } from "../valid-selector.js";
import { listDeploymentVariablesByDeploymentRouter } from "./deployment-variables.js";
+// 1 hour
const PLAN_TTL_MS = 60 * 60 * 1000;🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| const getJobAgentsByDeploymentId = async ( | ||||||||||||||
| deploymentIds: string[], | ||||||||||||||
| ): Promise<Record<string, { ref: string; config: Record<string, any> }[]>> => { | ||||||||||||||
| if (deploymentIds.length === 0) return {}; | ||||||||||||||
| const links = await db | ||||||||||||||
| .select() | ||||||||||||||
| .from(schema.deploymentJobAgent) | ||||||||||||||
| .where(inArray(schema.deploymentJobAgent.deploymentId, deploymentIds)); | ||||||||||||||
| return _.chain(links) | ||||||||||||||
| .groupBy((l) => l.deploymentId) | ||||||||||||||
| .mapValues((group) => | ||||||||||||||
| group.map((l) => ({ ref: l.jobAgentId, config: l.config })), | ||||||||||||||
| ) | ||||||||||||||
| .value(); | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| const parseSelector = (raw: string | null | undefined): string | undefined => { | ||||||||||||||
| if (raw == null || raw === "false") return undefined; | ||||||||||||||
| return raw; | ||||||||||||||
| }; | ||||||||||||||
|
|
@@ -84,16 +101,16 @@ const listDeployments: AsyncTypedHandler< | |||||||||||||
| const systemLinks = | ||||||||||||||
| deploymentIds.length > 0 | ||||||||||||||
| ? await db | ||||||||||||||
| .select({ | ||||||||||||||
| deploymentId: schema.systemDeployment.deploymentId, | ||||||||||||||
| system: schema.system, | ||||||||||||||
| }) | ||||||||||||||
| .from(schema.systemDeployment) | ||||||||||||||
| .innerJoin( | ||||||||||||||
| schema.system, | ||||||||||||||
| eq(schema.systemDeployment.systemId, schema.system.id), | ||||||||||||||
| ) | ||||||||||||||
| .where(inArray(schema.systemDeployment.deploymentId, deploymentIds)) | ||||||||||||||
| .select({ | ||||||||||||||
| deploymentId: schema.systemDeployment.deploymentId, | ||||||||||||||
| system: schema.system, | ||||||||||||||
| }) | ||||||||||||||
| .from(schema.systemDeployment) | ||||||||||||||
| .innerJoin( | ||||||||||||||
| schema.system, | ||||||||||||||
| eq(schema.systemDeployment.systemId, schema.system.id), | ||||||||||||||
| ) | ||||||||||||||
| .where(inArray(schema.systemDeployment.deploymentId, deploymentIds)) | ||||||||||||||
| : []; | ||||||||||||||
|
|
||||||||||||||
| const systemsByDeploymentId = new Map< | ||||||||||||||
|
|
@@ -106,8 +123,14 @@ const listDeployments: AsyncTypedHandler< | |||||||||||||
| systemsByDeploymentId.set(link.deploymentId, arr); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const agentsByDeploymentId = await getJobAgentsByDeploymentId(deploymentIds); | ||||||||||||||
| const items = deployments.map((dep) => ({ | ||||||||||||||
| deployment: formatDeployment(dep), | ||||||||||||||
| deployment: { | ||||||||||||||
| ...formatDeployment(dep), | ||||||||||||||
| jobAgents: (agentsByDeploymentId[dep.id] ?? []).map( | ||||||||||||||
| ({ ref, config }) => ({ ref, config }), | ||||||||||||||
|
||||||||||||||
| ({ ref, config }) => ({ ref, config }), | |
| ({ ref, config, selector }) => ({ | |
| ref, | |
| config, | |
| selector: selector ?? "true", | |
| }), |
Copilot
AI
Apr 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in listDeployments: the jobAgents objects returned here omit the selector field that DeploymentJobAgent is documented to require in the generated OpenAPI types. Align the runtime response with the schema by including selector (or adjust the schema/types if selector is no longer part of the model).
| ({ ref, config }) => ({ ref, config }), | |
| ({ ref, config, selector }) => ({ ref, config, selector }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lodashis imported here, butapps/api/package.jsondoes not declarelodashas a dependency (only@types/lodash). With pnpm's strict node_modules layout this will likely fail at runtime/build. Either addlodashto this package's dependencies or replace the grouping logic with a small local reducer/Map to avoid the extra dependency.