Update stuff so we can pass build hopefully
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { access, readFile, rm } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
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 { env } from './env';
|
||||
@@ -16,8 +18,6 @@ import { getInstallationToken, openDraftPullRequest } from './github';
|
||||
import { createRedactor, truncate } from './redact';
|
||||
import { runInJobContainer } from './runtime/docker';
|
||||
|
||||
type Id<TableName extends string> = string & { __tableName: TableName };
|
||||
|
||||
type Claim = {
|
||||
job: {
|
||||
_id: Id<'agentJobs'>;
|
||||
@@ -44,95 +44,6 @@ type Claim = {
|
||||
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 client = new ConvexHttpClient(env.convexUrl);
|
||||
@@ -155,7 +66,7 @@ const appendEvent = async (
|
||||
message: string,
|
||||
metadata?: string,
|
||||
) =>
|
||||
await client.mutation(appendEventFunction, {
|
||||
await client.mutation(api.agentJobs.appendEvent, {
|
||||
workerToken: env.workerToken,
|
||||
workerId: env.workerId,
|
||||
jobId,
|
||||
@@ -180,7 +91,7 @@ const updateStatus = async (
|
||||
| 'timed_out',
|
||||
extra?: { error?: string; summary?: string },
|
||||
) =>
|
||||
await client.mutation(updateStatusFunction, {
|
||||
await client.mutation(api.agentJobs.updateStatus, {
|
||||
workerToken: env.workerToken,
|
||||
workerId: env.workerId,
|
||||
jobId,
|
||||
@@ -199,7 +110,7 @@ const addArtifact = async (args: {
|
||||
| 'application/json'
|
||||
| 'text/x-diff';
|
||||
}) =>
|
||||
await client.mutation(addArtifactFunction, {
|
||||
await client.mutation(api.agentJobs.addArtifact, {
|
||||
workerToken: env.workerToken,
|
||||
workerId: env.workerId,
|
||||
...args,
|
||||
@@ -212,7 +123,7 @@ const completeWithDraftPr = async (args: {
|
||||
pullRequestNumber: number;
|
||||
summary: string;
|
||||
}) =>
|
||||
await client.mutation(completeWithDraftPrFunction, {
|
||||
await client.mutation(api.agentJobs.completeWithDraftPr, {
|
||||
workerToken: env.workerToken,
|
||||
workerId: env.workerId,
|
||||
...args,
|
||||
@@ -495,7 +406,7 @@ export const startWorker = async () => {
|
||||
console.log(`Spoon agent worker ${env.workerId} polling ${env.convexUrl}`);
|
||||
for (;;) {
|
||||
try {
|
||||
const claim = await client.action(claimNextForWorkerFunction, {
|
||||
const claim = await client.action(api.agentJobsNode.claimNextForWorker, {
|
||||
workerId: env.workerId,
|
||||
workerToken: env.workerToken,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user