@things-factory/operato-codelingua 10.0.0-beta.7 → 10.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,2 @@
1
- export declare function initMiddlewares(app: any): void;
1
+ import Koa from 'koa';
2
+ export declare function initMiddlewares(_app: Koa): void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initMiddlewares = initMiddlewares;
4
- function initMiddlewares(app) {
4
+ function initMiddlewares(_app) {
5
5
  /* can add middlewares into app */
6
6
  }
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;AAAA,0CAEC;AAFD,SAAgB,eAAe,CAAC,GAAG;IACjC,kCAAkC;AACpC,CAAC","sourcesContent":["export function initMiddlewares(app) {\n /* can add middlewares into app */\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;AAEA,0CAEC;AAFD,SAAgB,eAAe,CAAC,IAAS;IACvC,kCAAkC;AACpC,CAAC","sourcesContent":["import Koa from 'koa'\n\nexport function initMiddlewares(_app: Koa) {\n /* can add middlewares into app */\n}\n"]}
@@ -3,10 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.githubWebhookRouter = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
6
- const codelingua_1 = require("@things-factory/codelingua");
6
+ const ai_client_base_1 = require("@things-factory/ai-client-base");
7
7
  const github_controller_1 = require("../controllers/github-controller");
8
8
  const shell_1 = require("@things-factory/shell");
9
9
  const git_project_1 = require("../service/git-project/git-project");
10
+ const CODE_REVIEW_SYSTEM_PROMPT = `You are an expert software engineer with a deep understanding of multiple programming languages, including Python, JavaScript, Java, and C++. Your role is to analyze, review, and provide insights on code snippets, highlighting potential issues, suggesting improvements, and explaining complex parts of the code. Respond in a clear, concise, and professional manner.
11
+
12
+ Please provide:
13
+ 1. An overall assessment of the code quality.
14
+ 2. Identification of any potential bugs or issues.
15
+ 3. Suggestions for improving the code.
16
+ 4. An explanation of any complex or non-obvious parts of the code.
17
+ `;
18
+ async function codereviewCompletion(codeDiff) {
19
+ try {
20
+ const client = (0, ai_client_base_1.getDefaultAIClient)();
21
+ if (!client) {
22
+ console.warn('[github-webhook] No AI client configured (config.aiClient).');
23
+ return 'AI code review is currently unavailable.';
24
+ }
25
+ const reply = await client.chat([{ role: 'user', content: `Review the following code:\n\n${codeDiff}` }], { systemPrompt: CODE_REVIEW_SYSTEM_PROMPT, temperature: 0.4 });
26
+ return reply || 'AI code review returned an empty response.';
27
+ }
28
+ catch (error) {
29
+ console.error('[github-webhook] codereviewCompletion failed:', error);
30
+ return 'AI code review encountered an error.';
31
+ }
32
+ }
10
33
  exports.githubWebhookRouter = new koa_router_1.default();
11
34
  exports.githubWebhookRouter.post('/github-webhook/:projectId', async (context, next) => {
12
35
  const { payload, head_commit } = context.request.body;
@@ -29,7 +52,7 @@ exports.githubWebhookRouter.post('/github-webhook/:projectId', async (context, n
29
52
  // const pullNumber = pull_request.number // 풀 리퀘스트 번호를 받아옴
30
53
  // await postGitHubComment(project.repositoryUrl, pullNumber, reviewFeedback)
31
54
  // }
32
- const reviewFeedback = await (0, codelingua_1.codereviewCompletion)(commitDiff);
55
+ const reviewFeedback = await codereviewCompletion(commitDiff);
33
56
  await (0, github_controller_1.postGitHubComment)(context.request.body.repository.full_name, context.request.body.head_commit.id, reviewFeedback);
34
57
  context.status = 200;
35
58
  context.body = 'Success';
@@ -1 +1 @@
1
- {"version":3,"file":"github-webhook-router.js","sourceRoot":"","sources":["../../server/routers/github-webhook-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,2DAAiE;AAEjE,wEAAoE;AACpE,iDAAqD;AACrD,oEAA+D;AAElD,QAAA,mBAAmB,GAAG,IAAI,oBAAM,EAAE,CAAA;AAE/C,2BAAmB,CAAC,IAAI,CAAC,4BAA4B,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IAC7E,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;IACrD,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC,IAAI,CAAA;IACvC,4CAA4C;IAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAA;IAE1C,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAa,EAAC,wBAAU,CAAC,CAAC,OAAO,CAAC;QACtD,KAAK,EAAE;YACL,EAAE,EAAE,SAAS;SACd;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;QACpB,OAAO,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAClC,OAAM;IACR,CAAC;IAED,kCAAkC;IAClC,gFAAgF;IAChF,gEAAgE;IAChE,6DAA6D;IAC7D,+EAA+E;IAC/E,IAAI;IAEJ,MAAM,cAAc,GAAG,MAAM,IAAA,iCAAoB,EAAC,UAAU,CAAC,CAAA;IAE7D,MAAM,IAAA,qCAAiB,EACrB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EACzC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,EACnC,cAAc,CACf,CAAA;IAED,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;IACpB,OAAO,CAAC,IAAI,GAAG,SAAS,CAAA;AAC1B,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport { codereviewCompletion } from '@things-factory/codelingua'\n\nimport { postGitHubComment } from '../controllers/github-controller'\nimport { getRepository } from '@things-factory/shell'\nimport { GitProject } from '../service/git-project/git-project'\n\nexport const githubWebhookRouter = new Router()\n\ngithubWebhookRouter.post('/github-webhook/:projectId', async (context, next) => {\n const { payload, head_commit } = context.request.body\n const { commitDiff } = head_commit.diff\n // const { commits, pull_request } = payload\n const projectId = context.params.projectId\n\n const project = await getRepository(GitProject).findOne({\n where: {\n id: projectId\n }\n })\n\n if (!project) {\n context.status = 404\n context.body = 'Project not found'\n return\n }\n\n // for (const commit of commits) {\n // const codeDiff = `diff of the changed code here` // 실제 diff 데이터를 가져오는 로직 필요\n // const reviewFeedback = await codereviewCompletion(codeDiff)\n // const pullNumber = pull_request.number // 풀 리퀘스트 번호를 받아옴\n // await postGitHubComment(project.repositoryUrl, pullNumber, reviewFeedback)\n // }\n\n const reviewFeedback = await codereviewCompletion(commitDiff)\n\n await postGitHubComment(\n context.request.body.repository.full_name,\n context.request.body.head_commit.id,\n reviewFeedback\n )\n\n context.status = 200\n context.body = 'Success'\n})\n"]}
1
+ {"version":3,"file":"github-webhook-router.js","sourceRoot":"","sources":["../../server/routers/github-webhook-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,mEAAmE;AAEnE,wEAAoE;AACpE,iDAAqD;AACrD,oEAA+D;AAE/D,MAAM,yBAAyB,GAAG;;;;;;;CAOjC,CAAA;AAED,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IAClD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,mCAAkB,GAAE,CAAA;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAA;YAC3E,OAAO,0CAA0C,CAAA;QACnD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAC7B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,iCAAiC,QAAQ,EAAE,EAAE,CAAC,EACxE,EAAE,YAAY,EAAE,yBAAyB,EAAE,WAAW,EAAE,GAAG,EAAE,CAC9D,CAAA;QACD,OAAO,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AAA;AAC1B,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport { getDefaultAIClient } from '@things-factory/ai-client-base'\n\nimport { postGitHubComment } from '../controllers/github-controller'\nimport { getRepository } from '@things-factory/shell'\nimport { GitProject } from '../service/git-project/git-project'\n\nconst CODE_REVIEW_SYSTEM_PROMPT = `You are an expert software engineer with a deep understanding of multiple programming languages, including Python, JavaScript, Java, and C++. Your role is to analyze, review, and provide insights on code snippets, highlighting potential issues, suggesting improvements, and explaining complex parts of the code. Respond in a clear, concise, and professional manner.\n\nPlease provide:\n1. An overall assessment of the code quality.\n2. Identification of any potential bugs or issues.\n3. Suggestions for improving the code.\n4. An explanation of any complex or non-obvious parts of the code.\n`\n\nasync function codereviewCompletion(codeDiff: string): Promise<string> {\n try {\n const client = getDefaultAIClient()\n if (!client) {\n console.warn('[github-webhook] No AI client configured (config.aiClient).')\n return 'AI code review is currently unavailable.'\n }\n const reply = await client.chat(\n [{ role: 'user', content: `Review the following code:\\n\\n${codeDiff}` }],\n { systemPrompt: CODE_REVIEW_SYSTEM_PROMPT, temperature: 0.4 }\n )\n return reply || 'AI code review returned an empty response.'\n } catch (error) {\n console.error('[github-webhook] codereviewCompletion failed:', error)\n return 'AI code review encountered an error.'\n }\n}\n\nexport const githubWebhookRouter = new Router()\n\ngithubWebhookRouter.post('/github-webhook/:projectId', async (context, next) => {\n const { payload, head_commit } = context.request.body\n const { commitDiff } = head_commit.diff\n // const { commits, pull_request } = payload\n const projectId = context.params.projectId\n\n const project = await getRepository(GitProject).findOne({\n where: {\n id: projectId\n }\n })\n\n if (!project) {\n context.status = 404\n context.body = 'Project not found'\n return\n }\n\n // for (const commit of commits) {\n // const codeDiff = `diff of the changed code here` // 실제 diff 데이터를 가져오는 로직 필요\n // const reviewFeedback = await codereviewCompletion(codeDiff)\n // const pullNumber = pull_request.number // 풀 리퀘스트 번호를 받아옴\n // await postGitHubComment(project.repositoryUrl, pullNumber, reviewFeedback)\n // }\n\n const reviewFeedback = await codereviewCompletion(commitDiff)\n\n await postGitHubComment(\n context.request.body.repository.full_name,\n context.request.body.head_commit.id,\n reviewFeedback\n )\n\n context.status = 200\n context.body = 'Success'\n})\n"]}