moving
This commit is contained in:
@@ -1,25 +1,18 @@
|
||||
import type { Job } from 'bullmq';
|
||||
import type { JobData } from '../job-processor.js';
|
||||
import type { Db } from '../../../server/src/db/connection.js';
|
||||
import { runAgentLoop, createSystemTools } from '@waggle/agent';
|
||||
import { runAgentLoop } from '@waggle/agent';
|
||||
import { createWorkerExecutionContext } from '../execution-policy.js';
|
||||
|
||||
const LITELLM_URL = process.env.LITELLM_URL ?? 'http://localhost:4000/v1';
|
||||
const LITELLM_API_KEY = process.env.LITELLM_API_KEY ?? process.env.LITELLM_MASTER_KEY ?? 'sk-waggle-dev';
|
||||
const DEFAULT_MODEL = process.env.DEFAULT_MODEL ?? 'claude-sonnet';
|
||||
|
||||
export async function chatHandler(job: Job<JobData>, _db: Db): Promise<Record<string, unknown>> {
|
||||
const { userId, input } = job.data;
|
||||
const { teamId, userId, input } = job.data;
|
||||
const message = (input as Record<string, unknown>).message as string ?? '';
|
||||
const model = (input as Record<string, unknown>).model as string ?? DEFAULT_MODEL;
|
||||
const workspaceDir = (input as Record<string, unknown>).workspaceDir as string ?? process.cwd();
|
||||
|
||||
const tools = createSystemTools(workspaceDir);
|
||||
|
||||
const systemPrompt = [
|
||||
'You are a Waggle AI agent. You help users with tasks using your tools.',
|
||||
'Use system tools (bash, read_file, write_file, edit_file, search_files, search_content) to interact with the workspace.',
|
||||
'Be helpful, concise, and proactive.',
|
||||
].join('\n');
|
||||
const { systemPrompt, tools } = createWorkerExecutionContext(teamId);
|
||||
|
||||
const result = await runAgentLoop({
|
||||
litellmUrl: LITELLM_URL,
|
||||
|
||||
@@ -6,13 +6,14 @@ import { eq } from 'drizzle-orm';
|
||||
import { executeParallel, type ExecutionDeps } from '../execution/parallel.js';
|
||||
import { executeSequential } from '../execution/sequential.js';
|
||||
import { executeCoordinator } from '../execution/coordinator.js';
|
||||
import { runAgentLoop, createSystemTools } from '@waggle/agent';
|
||||
import { runAgentLoop } from '@waggle/agent';
|
||||
import { createWorkerExecutionContext } from '../execution-policy.js';
|
||||
|
||||
const LITELLM_URL = process.env.LITELLM_URL ?? 'http://localhost:4000/v1';
|
||||
const LITELLM_API_KEY = process.env.LITELLM_API_KEY ?? process.env.LITELLM_MASTER_KEY ?? 'sk-waggle-dev';
|
||||
|
||||
export async function groupHandler(job: Job<JobData>, db: Db): Promise<Record<string, unknown>> {
|
||||
const { input } = job.data;
|
||||
const { teamId, userId, input } = job.data;
|
||||
const groupId = (input as Record<string, unknown>).groupId as string;
|
||||
const taskInput = (input as Record<string, unknown>).taskInput as Record<string, unknown> ?? {};
|
||||
|
||||
@@ -24,7 +25,7 @@ export async function groupHandler(job: Job<JobData>, db: Db): Promise<Record<st
|
||||
const [group] = await db.select().from(agentGroups)
|
||||
.where(eq(agentGroups.id, groupId));
|
||||
|
||||
if (!group) {
|
||||
if (!group || group.userId !== userId) {
|
||||
throw new Error(`Agent group not found: ${groupId}`);
|
||||
}
|
||||
|
||||
@@ -40,27 +41,29 @@ export async function groupHandler(job: Job<JobData>, db: Db): Promise<Record<st
|
||||
if (members.length === 0) {
|
||||
throw new Error(`Agent group ${groupId} has no members`);
|
||||
}
|
||||
if (members.some(({ agent }) => agent.userId !== group.userId)) {
|
||||
throw new Error(`Agent group not found: ${groupId}`);
|
||||
}
|
||||
|
||||
const executionContext = createWorkerExecutionContext(teamId);
|
||||
|
||||
// Sort by execution order
|
||||
members.sort((a: typeof members[number], b: typeof members[number]) => a.member.executionOrder - b.member.executionOrder);
|
||||
|
||||
// Build execution deps — wires strategies to real runAgentLoop
|
||||
const workspaceDir = (taskInput.workspaceDir as string) ?? process.cwd();
|
||||
const allTools = createSystemTools(workspaceDir);
|
||||
|
||||
const deps: ExecutionDeps = {
|
||||
runAgent: async (config) => runAgentLoop({
|
||||
litellmUrl: LITELLM_URL,
|
||||
litellmApiKey: LITELLM_API_KEY,
|
||||
model: config.model,
|
||||
systemPrompt: config.systemPrompt,
|
||||
systemPrompt: `${executionContext.systemPrompt}\n\n${config.systemPrompt}`,
|
||||
tools: config.tools,
|
||||
messages: config.messages,
|
||||
maxTurns: config.maxTurns ?? 10,
|
||||
}),
|
||||
resolveTools: (toolNames) => {
|
||||
if (toolNames.length === 0) return allTools; // No filter = all tools
|
||||
return allTools.filter(t => toolNames.includes(t.name));
|
||||
if (toolNames.length === 0) return executionContext.tools; // No filter = all safe tools
|
||||
return executionContext.tools.filter(t => toolNames.includes(t.name));
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ import type { JobData } from '../job-processor.js';
|
||||
import type { Db } from '../../../server/src/db/connection.js';
|
||||
import { tasks } from '../../../server/src/db/schema.js';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { runAgentLoop, createSystemTools } from '@waggle/agent';
|
||||
import { runAgentLoop } from '@waggle/agent';
|
||||
import { createWorkerExecutionContext } from '../execution-policy.js';
|
||||
|
||||
const LITELLM_URL = process.env.LITELLM_URL ?? 'http://localhost:4000/v1';
|
||||
const LITELLM_API_KEY = process.env.LITELLM_API_KEY ?? process.env.LITELLM_MASTER_KEY ?? 'sk-waggle-dev';
|
||||
@@ -34,6 +35,8 @@ export async function taskHandler(job: Job<JobData>, db: Db): Promise<Record<str
|
||||
throw new Error(`Task ${taskId} does not belong to team ${teamId}`);
|
||||
}
|
||||
|
||||
const executionContext = createWorkerExecutionContext(teamId);
|
||||
|
||||
// Mark task as in-progress
|
||||
await db.update(tasks)
|
||||
.set({ status: 'in_progress', assignedTo: userId, updatedAt: new Date() })
|
||||
@@ -41,27 +44,25 @@ export async function taskHandler(job: Job<JobData>, db: Db): Promise<Record<str
|
||||
|
||||
// Build prompt from task context
|
||||
const systemPrompt = [
|
||||
executionContext.systemPrompt,
|
||||
'',
|
||||
'You are a Waggle AI agent executing an assigned task.',
|
||||
'Complete the task described below. Be thorough but concise.',
|
||||
'Use system tools (bash, read_file, write_file, edit_file, search_files, search_content) to interact with the workspace.',
|
||||
'',
|
||||
`Task: ${task.title}`,
|
||||
task.description ? `Details: ${task.description}` : '',
|
||||
task.priority ? `Priority: ${task.priority}` : '',
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
const workspaceDir = (input as Record<string, unknown>).workspaceDir as string ?? process.cwd();
|
||||
const model = (input as Record<string, unknown>).model as string ?? DEFAULT_MODEL;
|
||||
|
||||
try {
|
||||
const tools = createSystemTools(workspaceDir);
|
||||
|
||||
const result = await runAgentLoop({
|
||||
litellmUrl: LITELLM_URL,
|
||||
litellmApiKey: LITELLM_API_KEY,
|
||||
model,
|
||||
systemPrompt,
|
||||
tools,
|
||||
tools: executionContext.tools,
|
||||
messages: [{ role: 'user', content: `Execute this task: ${task.title}${task.description ? '\n\n' + task.description : ''}` }],
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user