Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@anthropic-ai/claude-code": "=1.0.24",
"@anthropic-ai/sdk": "~0.54.0",
"@anthropic-ai/bedrock-sdk": "~0.22.2",
"@automa/bot": "~0.2.3",
"@automa/bot": "~0.2.8",
"@fastify/autoload": "~5.7.1",
"@fastify/helmet": "~11.1.1",
"@fastify/sensible": "~5.2.0",
Expand Down
28 changes: 23 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/events/jobs/processTask.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { WebhookPayload } from '@automa/bot';
import { WebhookEventData, WebhookEventType } from '@automa/bot';

import { JobDefinition } from '../types';

import { runUpdate } from '../../routes/hooks/automa';

const processTask: JobDefinition<{
baseURL: string;
data: WebhookPayload['data'];
data: WebhookEventData<WebhookEventType.TaskCreated>;
}> = {
handler: (app, { baseURL, data }) => {
return runUpdate(app, baseURL, data);
Expand Down
25 changes: 16 additions & 9 deletions src/routes/hooks/automa.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { FastifyInstance } from 'fastify';
import { Tool } from '@anthropic-ai/sdk/resources/messages';
import { verifyWebhook, type WebhookPayload } from '@automa/bot';
import {
verifyWebhook,
WebhookEventData,
WebhookEventType,
type WebhookPayload,
} from '@automa/bot';
import { ATTR_HTTP_REQUEST_HEADER } from '@opentelemetry/semantic-conventions/incubating';
import { z } from 'zod/v4';

Expand Down Expand Up @@ -78,13 +83,15 @@ export default async function (app: FastifyInstance) {

const baseURL = request.headers['x-automa-server-host'] as string;

await app.events.processTask.publish(
`${request.body.data.task.id}-${timestamp}`,
{
baseURL,
data: request.body.data,
},
);
if (request.body.type === WebhookEventType.TaskCreated) {
await app.events.processTask.publish(
`${request.body.data.task.id}-${timestamp}`,
{
baseURL,
data: request.body.data,
},
);
}

return reply.send();
});
Expand All @@ -93,7 +100,7 @@ export default async function (app: FastifyInstance) {
export const runUpdate = async (
app: FastifyInstance,
baseURL: string,
data: WebhookPayload['data'],
data: WebhookEventData<WebhookEventType.TaskCreated>,
) => {
// Download code
const folder = await automa.code.download(data, { baseURL });
Expand Down
6 changes: 3 additions & 3 deletions src/update/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { FastifyInstance } from 'fastify';
import { query } from '@anthropic-ai/claude-code';
import { CodeFolder, WebhookPayload } from '@automa/bot';
import { CodeFolder, WebhookEventData, WebhookEventType } from '@automa/bot';

export const update = async (
app: FastifyInstance,
folder: CodeFolder,
data: WebhookPayload['data'],
data: WebhookEventData<WebhookEventType.TaskCreated>,
) => {
const description = data.task.items
.filter(({ type }) => type === 'message')
.map(({ data }) => `<description>${data.content}</description>`)
.map(({ data }) => `<description>${(data as any).content}</description>`)

Check warning on line 12 in src/update/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 12 in src/update/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
.join('\n');

const message = `<title>${data.task.title}</title>${description}`;
Expand Down
4 changes: 2 additions & 2 deletions test/automa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ suite('automa hook', () => {
const response = await call(app, '/hooks/automa', {
method: 'POST',
headers: {},
payload: {},
payload,
});

assert.equal(response.statusCode, 401);
Expand All @@ -78,7 +78,7 @@ suite('automa hook', () => {
assert.equal(response.statusCode, 401);
});

suite('with valid signature', () => {
suite('with valid signature and task.created event', () => {
setup(async () => {
response = await callWithFixture(app, 'task');
});
Expand Down
8 changes: 5 additions & 3 deletions test/events/processTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { FastifyInstance } from 'fastify';
import { assert } from 'chai';
import { createSandbox, SinonSandbox, SinonStub } from 'sinon';
import { CodeFolder, WebhookPayload } from '@automa/bot';
import { CodeFolder, WebhookEventData, WebhookEventType } from '@automa/bot';

import { server } from '../utils';

Expand All @@ -28,7 +28,7 @@
name: 'automa',
provider_type: 'github',
},
} as WebhookPayload['data'];
} as WebhookEventData<WebhookEventType.TaskCreated>;

const dataWithDescription = {
...data,
Expand All @@ -41,10 +41,12 @@
data: {
content: 'It does not work',
},
bot_id: null,
repo_id: null,
},
],
},
} as WebhookPayload['data'];
} as WebhookEventData<WebhookEventType.TaskCreated>;

const codeFixture = join(__dirname, '..', 'fixtures', 'code');

Expand Down Expand Up @@ -253,7 +255,7 @@
});

suite('with download error', () => {
let error: any;

Check warning on line 258 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 258 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
downloadStub.rejects(new Error('Download error'));
Expand Down Expand Up @@ -301,7 +303,7 @@
});

suite('with claude code error', () => {
let error: any;

Check warning on line 306 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 306 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
queryStub.returns({
Expand Down Expand Up @@ -363,7 +365,7 @@
});

suite('with claude code non-completed output', () => {
let error: any;

Check warning on line 368 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 368 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
queryStub.returns({
Expand Down Expand Up @@ -430,7 +432,7 @@
});

suite('with propose error', () => {
let error: any;

Check warning on line 435 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 435 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
proposeStub.rejects(new Error('Propose error'));
Expand Down
Loading