JavaScript / TypeScript
Examples using the Team6 API with JavaScript and TypeScript.
Setup
const TEAM6_API = 'https://api.team6.ai';
const TOKEN = process.env.TEAM6_TOKEN;
const headers = {
'Authorization': `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
};
Create a Project
async function createProject(name: string, description: string) {
const response = await fetch(`${TEAM6_API}/projects`, {
method: 'POST',
headers,
body: JSON.stringify({ name, description }),
});
return response.json();
}
const project = await createProject('My App', 'Main development project');
console.log('Project created:', project.id);
Connect a Repository
async function connectRepository(projectId: string, name: string, url: string) {
const response = await fetch(`${TEAM6_API}/repositories`, {
method: 'POST',
headers,
body: JSON.stringify({
projectId,
name,
url,
defaultBranch: 'main',
isPrimary: true,
}),
});
return response.json();
}
const repo = await connectRepository(
project.id,
'backend-api',
'https://github.com/myorg/backend-api'
);
Create and Start a Task
async function createTask(projectId: string, title: string, description: string, agentId: string) {
const response = await fetch(`${TEAM6_API}/projects/${projectId}/tasks`, {
method: 'POST',
headers,
body: JSON.stringify({
title,
description,
owner: agentId,
}),
});
return response.json();
}
async function startTask(taskId: string) {
const response = await fetch(`${TEAM6_API}/tasks/${taskId}/start`, {
method: 'POST',
headers,
});
return response.json();
}
const task = await createTask(
project.id,
'Add user authentication',
'Implement JWT authentication with login endpoint',
'agent_backend'
);
await startTask(task.id);
console.log('Task started:', task.id);
Poll for Task Completion
async function getTask(taskId: string) {
const response = await fetch(`${TEAM6_API}/tasks/${taskId}`, { headers });
return response.json();
}
async function waitForTask(taskId: string, timeout = 600000) {
const start = Date.now();
while (Date.now() - start < timeout) {
const task = await getTask(taskId);
if (task.status === 'done') {
console.log('Task completed!', task.prUrl);
return task;
}
if (task.status === 'in_review') {
console.log('PR ready for review:', task.prUrl);
return task;
}
console.log('Status:', task.status);
await new Promise(r => setTimeout(r, 10000)); // Wait 10s
}
throw new Error('Task timed out');
}
const completedTask = await waitForTask(task.id);
Chat with Agent
async function chatWithAgent(taskId: string, message: string) {
const response = await fetch(`${TEAM6_API}/tasks/${taskId}/chat`, {
method: 'POST',
headers,
body: JSON.stringify({ message }),
});
return response.json();
}
const response = await chatWithAgent(task.id, 'Please add input validation');
console.log('Agent response:', response.response);
List Tasks
async function listTasks(projectId: string, status?: string) {
const url = new URL(`${TEAM6_API}/projects/${projectId}/tasks`);
if (status) url.searchParams.set('status', status);
const response = await fetch(url.toString(), { headers });
return response.json();
}
const inProgressTasks = await listTasks(project.id, 'in_progress');
console.log('Tasks in progress:', inProgressTasks.length);
Get Task Diff
async function getTaskDiff(taskId: string) {
const response = await fetch(`${TEAM6_API}/tasks/${taskId}/diff`, { headers });
return response.json();
}
const diff = await getTaskDiff(task.id);
console.log('Files changed:');
for (const file of diff.files) {
console.log(` ${file.path}: +${file.additions} -${file.deletions}`);
}
Merge PR
async function mergeTask(taskId: string) {
const response = await fetch(`${TEAM6_API}/tasks/${taskId}/merge`, {
method: 'POST',
headers,
});
return response.json();
}
await mergeTask(task.id);
console.log('PR merged!');
Full Example
async function automateFeature() {
// Create project
const project = await createProject('My App', 'Main project');
// Set GitHub token
await fetch(`${TEAM6_API}/projects/${project.id}/github-token`, {
method: 'POST',
headers,
body: JSON.stringify({ token: process.env.GITHUB_TOKEN }),
});
// Connect repository
await connectRepository(
project.id,
'backend',
'https://github.com/myorg/backend'
);
// Create and start task
const task = await createTask(
project.id,
'Add health check endpoint',
'Create GET /health endpoint that returns { status: "ok" }',
'agent_backend'
);
await startTask(task.id);
// Wait for completion
const completed = await waitForTask(task.id);
console.log('Done! PR:', completed.prUrl);
}