Skip to content

Commit

Permalink
fix: Initial agent comms architecture (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeesha authored May 8, 2024
1 parent e3f46b9 commit 52bf177
Show file tree
Hide file tree
Showing 27 changed files with 3,954 additions and 4,968 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# git-crypt files containing secrets under R&D
control-plane/src/modules/agents/** filter=git-crypt diff=git-crypt
control-plane/kubernetes.dev.yaml filter=git-crypt diff=git-crypt
ts-core/src/tests/monolith/** filter=git-crypt diff=git-crypt
1 change: 1 addition & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ k8s_resource('control-plane', port_forwards=[
], resource_deps=['postgres'])

docker_build('control-plane-image', 'control-plane', dockerfile='control-plane/Dockerfile.dev', live_update=[
sync('./control-plane/.env', '/app/.env'),
sync('./control-plane/src', '/app/src'),
sync('./control-plane/package.json', '/app/package.json'),
sync('./control-plane/package-lock.json', '/app/package-lock.json'),
Expand Down
Binary file modified control-plane/kubernetes.dev.yaml
Binary file not shown.
6 changes: 5 additions & 1 deletion control-plane/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.22.11",
"@fastify/cors": "^8.5.0",
"@langchain/core": "^0.1.61",
"@langchain/openai": "^0.0.28",
"@sentry/node": "^7.93.0",
"@sentry/profiling-node": "^1.3.5",
"@ts-rest/core": "^3.27.0",
Expand All @@ -35,8 +37,10 @@
"drizzle-orm": "^0.27.2",
"fastify": "^4.21.0",
"jest": "^29.6.4",
"json-schema-to-zod": "^2.1.0",
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.1.0",
"langchain": "^0.1.36",
"msgpackr": "^1.10.1",
"node-cache": "^5.1.2",
"nodemon": "^3.0.1",
Expand All @@ -61,4 +65,4 @@
"jest": {
"testTimeout": 20000
}
}
}
Binary file added control-plane/src/modules/agents/agent.ts
Binary file not shown.
21 changes: 21 additions & 0 deletions control-plane/src/modules/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const definition = {
.array(
z.object({
name: z.string(),
schema: z.string(),
}),
)
.optional(),
Expand Down Expand Up @@ -712,6 +713,26 @@ export const definition = {
401: z.undefined(),
},
},
executeTask: {
method: "POST",
path: "/clusters/:clusterId/task",
headers: z.object({
authorization: z.string(),
}),
body: z.object({
task: z.string(),
}),
responses: {
401: z.undefined(),
404: z.undefined(),
200: z.object({
result: z.any(),
}),
500: z.object({
error: z.string(),
}),
},
},
} as const;

export const contract = c.router(definition);
18 changes: 0 additions & 18 deletions control-plane/src/modules/jobs/create-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@ type CallConfig = {

const DEFAULT_RETRY_COUNT_ON_STALL = 1;

export const createSyncJob = async (params: {
service: string;
targetFn: string;
targetArgs: unknown[];
owner: { clusterId: string };
deploymentId?: string;
callConfig?: CallConfig;
}) => {
return createJob({
service: params.service,
targetFn: params.targetFn,
targetArgs: msgpackr.pack(data).toString("base64"), // I don't like this, but this will have to do for now.
owner: params.owner,
deploymentId: params.deploymentId,
callConfig: params.callConfig,
});
};

export const createJob = async (params: {
service: string;
targetFn: string;
Expand Down
2 changes: 2 additions & 0 deletions control-plane/src/modules/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export const getJobStatusSync = async ({
resultType: jobResult.resultType ?? undefined,
},
});
} else {
throw new Error("Job not found");
}

end();
Expand Down
24 changes: 24 additions & 0 deletions control-plane/src/modules/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,28 @@ export const router = s.router(contract, {
},
};
},
executeTask: async (request) => {
const access = await routingHelpers.validateAccessPointOrClusterTokenAccess(
request.headers.authorization,
request.params.clusterId,
);

if (!access) {
return {
status: 401,
};
}

const { clusterId } = request.params;
const { task } = request.body;

const { executeTaskForCluster } = require("./agents/agent");

const result = await executeTaskForCluster({ clusterId }, task);

return {
status: 200,
body: { result },
};
},
});
4 changes: 2 additions & 2 deletions control-plane/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"allowJs": true,
},
"include": [
"src/**/*"
"src/index.ts"
]
}
}
Loading

0 comments on commit 52bf177

Please sign in to comment.