Update stuff so we can pass build hopefully
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
import { access, readFile, rm } from 'node:fs/promises';
|
import { access, readFile, rm } from 'node:fs/promises';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { ConvexHttpClient } from 'convex/browser';
|
import { ConvexHttpClient } from 'convex/browser';
|
||||||
|
import { makeFunctionReference } from 'convex/server';
|
||||||
import type { Id } from '@spoon/backend/convex/_generated/dataModel.js';
|
|
||||||
import { api } from '@spoon/backend/convex/_generated/api.js';
|
|
||||||
|
|
||||||
import { runOpenAiEdit } from './agent';
|
import { runOpenAiEdit } from './agent';
|
||||||
import { env } from './env';
|
import { env } from './env';
|
||||||
@@ -18,6 +16,8 @@ import { getInstallationToken, openDraftPullRequest } from './github';
|
|||||||
import { createRedactor, truncate } from './redact';
|
import { createRedactor, truncate } from './redact';
|
||||||
import { runInJobContainer } from './runtime/docker';
|
import { runInJobContainer } from './runtime/docker';
|
||||||
|
|
||||||
|
type Id<TableName extends string> = string & { __tableName: TableName };
|
||||||
|
|
||||||
type Claim = {
|
type Claim = {
|
||||||
job: {
|
job: {
|
||||||
_id: Id<'agentJobs'>;
|
_id: Id<'agentJobs'>;
|
||||||
@@ -44,6 +44,95 @@ type Claim = {
|
|||||||
secrets: { name: string; value: string }[];
|
secrets: { name: string; value: string }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const appendEventFunction = makeFunctionReference<
|
||||||
|
'mutation',
|
||||||
|
{
|
||||||
|
workerToken: string;
|
||||||
|
workerId: string;
|
||||||
|
jobId: Id<'agentJobs'>;
|
||||||
|
level: 'debug' | 'info' | 'warn' | 'error';
|
||||||
|
phase:
|
||||||
|
| 'queued'
|
||||||
|
| 'clone'
|
||||||
|
| 'plan'
|
||||||
|
| 'edit'
|
||||||
|
| 'install'
|
||||||
|
| 'check'
|
||||||
|
| 'test'
|
||||||
|
| 'commit'
|
||||||
|
| 'push'
|
||||||
|
| 'pr'
|
||||||
|
| 'cleanup';
|
||||||
|
message: string;
|
||||||
|
metadata?: string;
|
||||||
|
},
|
||||||
|
unknown
|
||||||
|
>('agentJobs:appendEvent');
|
||||||
|
|
||||||
|
const updateStatusFunction = makeFunctionReference<
|
||||||
|
'mutation',
|
||||||
|
{
|
||||||
|
workerToken: string;
|
||||||
|
workerId: string;
|
||||||
|
jobId: Id<'agentJobs'>;
|
||||||
|
status:
|
||||||
|
| 'queued'
|
||||||
|
| 'claimed'
|
||||||
|
| 'preparing'
|
||||||
|
| 'running'
|
||||||
|
| 'checks_running'
|
||||||
|
| 'changes_ready'
|
||||||
|
| 'draft_pr_opened'
|
||||||
|
| 'failed'
|
||||||
|
| 'cancelled'
|
||||||
|
| 'timed_out';
|
||||||
|
error?: string;
|
||||||
|
summary?: string;
|
||||||
|
},
|
||||||
|
unknown
|
||||||
|
>('agentJobs:updateStatus');
|
||||||
|
|
||||||
|
const addArtifactFunction = makeFunctionReference<
|
||||||
|
'mutation',
|
||||||
|
{
|
||||||
|
workerToken: string;
|
||||||
|
workerId: string;
|
||||||
|
jobId: Id<'agentJobs'>;
|
||||||
|
kind: 'plan' | 'diff' | 'test_output' | 'summary' | 'error' | 'pr_body';
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
contentType:
|
||||||
|
| 'text/markdown'
|
||||||
|
| 'text/plain'
|
||||||
|
| 'application/json'
|
||||||
|
| 'text/x-diff';
|
||||||
|
},
|
||||||
|
unknown
|
||||||
|
>('agentJobs:addArtifact');
|
||||||
|
|
||||||
|
const completeWithDraftPrFunction = makeFunctionReference<
|
||||||
|
'mutation',
|
||||||
|
{
|
||||||
|
workerToken: string;
|
||||||
|
workerId: string;
|
||||||
|
jobId: Id<'agentJobs'>;
|
||||||
|
commitSha: string;
|
||||||
|
pullRequestUrl: string;
|
||||||
|
pullRequestNumber: number;
|
||||||
|
summary: string;
|
||||||
|
},
|
||||||
|
unknown
|
||||||
|
>('agentJobs:completeWithDraftPr');
|
||||||
|
|
||||||
|
const claimNextForWorkerFunction = makeFunctionReference<
|
||||||
|
'action',
|
||||||
|
{
|
||||||
|
workerId: string;
|
||||||
|
workerToken: string;
|
||||||
|
},
|
||||||
|
Claim | null
|
||||||
|
>('agentJobsNode:claimNextForWorker');
|
||||||
|
|
||||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
const client = new ConvexHttpClient(env.convexUrl);
|
const client = new ConvexHttpClient(env.convexUrl);
|
||||||
@@ -66,7 +155,7 @@ const appendEvent = async (
|
|||||||
message: string,
|
message: string,
|
||||||
metadata?: string,
|
metadata?: string,
|
||||||
) =>
|
) =>
|
||||||
await client.mutation(api.agentJobs.appendEvent, {
|
await client.mutation(appendEventFunction, {
|
||||||
workerToken: env.workerToken,
|
workerToken: env.workerToken,
|
||||||
workerId: env.workerId,
|
workerId: env.workerId,
|
||||||
jobId,
|
jobId,
|
||||||
@@ -91,7 +180,7 @@ const updateStatus = async (
|
|||||||
| 'timed_out',
|
| 'timed_out',
|
||||||
extra?: { error?: string; summary?: string },
|
extra?: { error?: string; summary?: string },
|
||||||
) =>
|
) =>
|
||||||
await client.mutation(api.agentJobs.updateStatus, {
|
await client.mutation(updateStatusFunction, {
|
||||||
workerToken: env.workerToken,
|
workerToken: env.workerToken,
|
||||||
workerId: env.workerId,
|
workerId: env.workerId,
|
||||||
jobId,
|
jobId,
|
||||||
@@ -110,7 +199,7 @@ const addArtifact = async (args: {
|
|||||||
| 'application/json'
|
| 'application/json'
|
||||||
| 'text/x-diff';
|
| 'text/x-diff';
|
||||||
}) =>
|
}) =>
|
||||||
await client.mutation(api.agentJobs.addArtifact, {
|
await client.mutation(addArtifactFunction, {
|
||||||
workerToken: env.workerToken,
|
workerToken: env.workerToken,
|
||||||
workerId: env.workerId,
|
workerId: env.workerId,
|
||||||
...args,
|
...args,
|
||||||
@@ -123,7 +212,7 @@ const completeWithDraftPr = async (args: {
|
|||||||
pullRequestNumber: number;
|
pullRequestNumber: number;
|
||||||
summary: string;
|
summary: string;
|
||||||
}) =>
|
}) =>
|
||||||
await client.mutation(api.agentJobs.completeWithDraftPr, {
|
await client.mutation(completeWithDraftPrFunction, {
|
||||||
workerToken: env.workerToken,
|
workerToken: env.workerToken,
|
||||||
workerId: env.workerId,
|
workerId: env.workerId,
|
||||||
...args,
|
...args,
|
||||||
@@ -406,7 +495,7 @@ export const startWorker = async () => {
|
|||||||
console.log(`Spoon agent worker ${env.workerId} polling ${env.convexUrl}`);
|
console.log(`Spoon agent worker ${env.workerId} polling ${env.convexUrl}`);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
try {
|
try {
|
||||||
const claim = await client.action(api.agentJobsNode.claimNextForWorker, {
|
const claim = await client.action(claimNextForWorkerFunction, {
|
||||||
workerId: env.workerId,
|
workerId: env.workerId,
|
||||||
workerToken: env.workerToken,
|
workerToken: env.workerToken,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user