From 59833f5d3f2b4f0660e0b4b171ac8a6c9d8f4a91 Mon Sep 17 00:00:00 2001 From: HermanL02 Date: Wed, 30 Apr 2025 10:14:56 -0300 Subject: [PATCH] resolve more conflicts and push --- worker/package.json | 3 +- worker/src/task/1-task.ts | 55 +++++---------------------------- worker/src/task/2-submission.ts | 13 +++----- worker/src/task/3-audit.ts | 12 +++---- worker/src/task/5-routes.ts | 4 +-- worker/src/utils/constant.ts | 6 ++-- 6 files changed, 24 insertions(+), 69 deletions(-) diff --git a/worker/package.json b/worker/package.json index 4620063..d5300a8 100644 --- a/worker/package.json +++ b/worker/package.json @@ -32,7 +32,8 @@ "lodash": "^4.17.21", "nodemon": "^3.1.0", "seedrandom": "^3.0.5", - "tail": "^2.2.6" + "tail": "^2.2.6", + "uuid": "^11.1.0" }, "peerDependencies": { "@_koii/namespace-wrapper": "^1.0.23" diff --git a/worker/src/task/1-task.ts b/worker/src/task/1-task.ts index 1fc6a77..b4c7c58 100644 --- a/worker/src/task/1-task.ts +++ b/worker/src/task/1-task.ts @@ -1,4 +1,4 @@ - +import { getOrcaClient } from "@_koii/task-manager/extensions"; import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper"; import "dotenv/config"; import { status, middleServerUrl } from "../utils/constant"; @@ -9,8 +9,6 @@ import { LogLevel } from "@_koii/namespace-wrapper/dist/types"; import { actionMessage } from "../utils/constant"; import { errorMessage } from "../utils/constant"; import { v4 as uuidv4 } from "uuid"; -import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler"; - dotenv.config(); export async function task(roundNumber: number): Promise { @@ -24,7 +22,6 @@ export async function task(roundNumber: number): Promise { // Changed from 3 to 4 to have more time if (roundNumber >= 4) { const triggerFetchAuditResult = await fetch(`${middleServerUrl}/summarizer/worker/update-audit-result`, { - const triggerFetchAuditResult = await fetch(`${middleServerUrl}/api/summarizer/trigger-fetch-audit-result`, { method: "POST", headers: { "Content-Type": "application/json", @@ -37,14 +34,7 @@ export async function task(roundNumber: number): Promise { } console.log(`[TASK] EXECUTE TASK FOR ROUND ${roundNumber}`); try { - let orcaClient; - try { - orcaClient = await handleOrcaClientCreation(); - }catch{ - await namespaceWrapper.logMessage(LogLevel.Error, errorMessage.NO_ORCA_CLIENT, actionMessage.NO_ORCA_CLIENT); - await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT); - return; - } + const orcaClient = await getOrcaClient(); // check if the env variable is valid if (!process.env.ANTHROPIC_API_KEY) { await namespaceWrapper.logMessage( @@ -93,7 +83,11 @@ export async function task(roundNumber: number): Promise { await namespaceWrapper.storeSet(`result-${roundNumber}`, status.GITHUB_CHECK_FAILED); return; } - + if (!orcaClient) { + await namespaceWrapper.logMessage(LogLevel.Error, errorMessage.NO_ORCA_CLIENT, actionMessage.NO_ORCA_CLIENT); + await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT); + return; + } const stakingKeypair = await namespaceWrapper.getSubmitterAccount(); if (!stakingKeypair) { @@ -161,49 +155,16 @@ export async function task(roundNumber: number): Promise { }, body: JSON.stringify(jsonBody), }); - const repoSummaryResponse = await handleRequest({orcaClient, route: `repo_summary/${roundNumber}`, bodyJSON: jsonBody}); console.log("[TASK] repoSummaryResponse: ", repoSummaryResponse); if (repoSummaryResponse.status !== 200) { await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUMMARIZATION_FAILED); - console.log("[TASK] repoSummaryResponse.data.result.data ", repoSummaryResponse.data.result.data); - const payload = { - taskId: TASK_ID, - action: "add", - roundNumber: roundNumber, - prUrl: repoSummaryResponse.data.result.data.pr_url, - stakingKey: stakingKey - } - console.log("[TASK] Signing payload: ", payload); - if (repoSummaryResponse.status === 200) { - try{ - const signature = await namespaceWrapper.payloadSigning( - payload, - stakingKeypair.secretKey, - ); - console.log("[TASK] signature: ", signature); - const addPrToSummarizerTodoResponse = await fetch(`${middleServerUrl}/api/summarizer/add-pr-to-summarizer-todo`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ signature: signature, stakingKey: stakingKey }), - }); - console.log("[TASK] addPrToSummarizerTodoResponse: ", addPrToSummarizerTodoResponse); - }catch(error){ - await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_ADD_PR_TO_SUMMARIZER_TODO); - console.error("[TASK] Error adding PR to summarizer todo:", error); - } - await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUCCESSFULLY_SUMMARIZED); - } else { - await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_BE_SUMMARIZED); } } catch (error) { await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUMMARIZATION_FAILED); - await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_FAILED_TO_BE_SUMMARIZED); console.error("[TASK] EXECUTE TASK ERROR:", error); } } catch (error) { await namespaceWrapper.storeSet(`result-${roundNumber}`, status.UNKNOWN_ERROR); console.error("[TASK] EXECUTE TASK ERROR:", error); } -} +} \ No newline at end of file diff --git a/worker/src/task/2-submission.ts b/worker/src/task/2-submission.ts index 6869004..d578c95 100644 --- a/worker/src/task/2-submission.ts +++ b/worker/src/task/2-submission.ts @@ -1,5 +1,5 @@ import { storeFile } from "../utils/ipfs"; -import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler"; +import { getOrcaClient } from "@_koii/task-manager/extensions"; import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper"; import { status } from "../utils/constant"; export async function submission(roundNumber: number) : Promise { @@ -13,14 +13,11 @@ export async function submission(roundNumber: number) : Promise { try { console.log("[SUBMISSION] Initializing Orca client..."); - let orcaClient; - try { - orcaClient = await handleOrcaClientCreation(); - }catch{ + const orcaClient = await getOrcaClient(); + if (!orcaClient) { console.error("[SUBMISSION] Failed to initialize Orca client"); return; } - console.log("[SUBMISSION] Orca client initialized successfully"); console.log(`[SUBMISSION] Fetching task result for round ${roundNumber}...`); @@ -37,7 +34,7 @@ export async function submission(roundNumber: number) : Promise { } console.log(`[SUBMISSION] Fetching submission data for round ${roundNumber}...`); - const result = await handleRequest({orcaClient, route: `submission/${roundNumber}`, bodyJSON: { taskId: TASK_ID, roundNumber }}); + const result = await orcaClient.podCall(`submission/${roundNumber}`); let submission; console.log("[SUBMISSION] Submission result:", result.data); @@ -102,4 +99,4 @@ export async function submission(roundNumber: number) : Promise { console.error("[SUBMISSION] Error during submission process:", error); throw error; } -} +} \ No newline at end of file diff --git a/worker/src/task/3-audit.ts b/worker/src/task/3-audit.ts index 280d6b1..b007ede 100644 --- a/worker/src/task/3-audit.ts +++ b/worker/src/task/3-audit.ts @@ -1,6 +1,6 @@ +import { getOrcaClient } from "@_koii/task-manager/extensions"; import { middleServerUrl, status } from "../utils/constant"; import { submissionJSONSignatureDecode } from "../utils/submissionJSONSignatureDecode"; -import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler"; // import { status } from '../utils/constant' export async function audit(cid: string, roundNumber: number, submitterKey: string): Promise { /** @@ -11,13 +11,11 @@ export async function audit(cid: string, roundNumber: number, submitterKey: stri */ try { - let orcaClient; - try { - orcaClient = await handleOrcaClientCreation(); - }catch{ + const orcaClient = await getOrcaClient(); + if (!orcaClient) { + // await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT); return; } - // Check if the cid is one of the status if (Object.values(status).includes(cid)) { // This returns a dummy true @@ -82,4 +80,4 @@ export async function audit(cid: string, roundNumber: number, submitterKey: stri // When Error---NO RETURN; // return true; } -} +} \ No newline at end of file diff --git a/worker/src/task/5-routes.ts b/worker/src/task/5-routes.ts index 2437767..5efa458 100644 --- a/worker/src/task/5-routes.ts +++ b/worker/src/task/5-routes.ts @@ -64,7 +64,7 @@ export async function routes() { console.log("[TASK] req.body", req.body); try { if (success) { - await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUMMARIZATION_SUCCEEDED); + await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUCCESSFULLY_SUMMARIZED); } else { await namespaceWrapper.storeSet(`result-${roundNumber}`, status.ISSUE_SUMMARIZATION_FAILED); console.error("[TASK] Error summarizing repository:", message); @@ -145,4 +145,4 @@ export async function routes() { res.status(400).json({ error: "Failed to save PR" }); } }); -} +} \ No newline at end of file diff --git a/worker/src/utils/constant.ts b/worker/src/utils/constant.ts index fca6985..f9c69ae 100644 --- a/worker/src/utils/constant.ts +++ b/worker/src/utils/constant.ts @@ -3,7 +3,7 @@ dotenv.config(); export const status = { ISSUE_SUMMARIZATION_FAILED: "Issue summarization failed", - ISSUE_SUMMARIZATION_SUCCEEDED: "Issue successfully summarized", + ISSUE_SUCCESSFULLY_SUMMARIZED: "Issue successfully summarized", NO_ISSUES_PENDING_TO_BE_SUMMARIZED: "No issues pending to be summarized", ROUND_LESS_THAN_OR_EQUAL_TO_1: "Round <= 1", NO_ORCA_CLIENT: "No orca client", @@ -57,6 +57,4 @@ export const defaultBountyMarkdownFile = export const customReward = 400 * 10 ** 9; // This should be in ROE! -export const middleServerUrl = "https://ik8kcow8ksw8gwgoo0ggosko.dev.koii.network"; - -export const middleServerUrl = "https://builder247-prod.dev.koii.network" \ No newline at end of file +export const middleServerUrl = "https://ik8kcow8ksw8gwgoo0ggosko.dev.koii.network"; \ No newline at end of file