Merge branch 'main' into summarizer-planner

This commit is contained in:
2025-04-29 14:40:21 -03:00
10 changed files with 331 additions and 15 deletions

View File

@ -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,6 +9,8 @@ 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<void> {
@ -22,6 +24,7 @@ export async function task(roundNumber: number): Promise<void> {
// 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",
@ -34,7 +37,14 @@ export async function task(roundNumber: number): Promise<void> {
}
console.log(`[TASK] EXECUTE TASK FOR ROUND ${roundNumber}`);
try {
const orcaClient = await getOrcaClient();
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;
}
// check if the env variable is valid
if (!process.env.ANTHROPIC_API_KEY) {
await namespaceWrapper.logMessage(
@ -83,11 +93,7 @@ export async function task(roundNumber: number): Promise<void> {
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) {
@ -155,12 +161,45 @@ export async function task(roundNumber: number): Promise<void> {
},
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) {

View File

@ -1,5 +1,5 @@
import { storeFile } from "../utils/ipfs";
import { getOrcaClient } from "@_koii/task-manager/extensions";
import { handleOrcaClientCreation, handleRequest } from "../utils/orcaHandler/orcaHandler";
import { namespaceWrapper, TASK_ID } from "@_koii/namespace-wrapper";
import { status } from "../utils/constant";
export async function submission(roundNumber: number) : Promise<string | void> {
@ -13,11 +13,14 @@ export async function submission(roundNumber: number) : Promise<string | void> {
try {
console.log("[SUBMISSION] Initializing Orca client...");
const orcaClient = await getOrcaClient();
if (!orcaClient) {
let orcaClient;
try {
orcaClient = await handleOrcaClientCreation();
}catch{
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}...`);
@ -34,7 +37,7 @@ export async function submission(roundNumber: number) : Promise<string | void> {
}
console.log(`[SUBMISSION] Fetching submission data for round ${roundNumber}...`);
const result = await orcaClient.podCall(`submission/${roundNumber}`);
const result = await handleRequest({orcaClient, route: `submission/${roundNumber}`, bodyJSON: { taskId: TASK_ID, roundNumber }});
let submission;
console.log("[SUBMISSION] Submission result:", result.data);

View File

@ -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<boolean | void> {
/**
@ -11,11 +11,13 @@ export async function audit(cid: string, roundNumber: number, submitterKey: stri
*/
try {
const orcaClient = await getOrcaClient();
if (!orcaClient) {
// await namespaceWrapper.storeSet(`result-${roundNumber}`, status.NO_ORCA_CLIENT);
let orcaClient;
try {
orcaClient = await handleOrcaClientCreation();
}catch{
return;
}
// Check if the cid is one of the status
if (Object.values(status).includes(cid)) {
// This returns a dummy true

View File

@ -58,3 +58,5 @@ 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"

View File

@ -0,0 +1,46 @@
import dotenv from "dotenv";
dotenv.config();
import { getOrcaClient } from "@_koii/task-manager/extensions";
export async function handleOrcaClientCreation(){
try {
// if (process.env.NODE_ENV !== "development") {
// const { getOrcaClient } = await import("@_koii/task-manager/extensions");
const orcaClient = await getOrcaClient();
if (!orcaClient) {
throw new Error("Orca client not found");
}
return orcaClient;
// }else{
// return null;
// }
}catch{
throw new Error("Orca client not found");
}
}
export async function handleRequest({orcaClient, route, bodyJSON}:{orcaClient:any, route:string, bodyJSON:any}){
// if (process.env.NODE_ENV === "development") {
// const response = await fetch(`${process.env.LOCAL_CONTAINER_TEST_URL}/${route}`, {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// },
// body: JSON.stringify(bodyJSON),
// });
// return response;
// }else{
if (!orcaClient) {
throw new Error("Orca client not found");
}
const response = await orcaClient.podCall(`${route}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(bodyJSON),
});
return response;
// }
}