diff --git a/app/(playground)/p/[agentId]/lib/execution.ts b/app/(playground)/p/[agentId]/lib/execution.ts index c0b21131..32bb8bd3 100644 --- a/app/(playground)/p/[agentId]/lib/execution.ts +++ b/app/(playground)/p/[agentId]/lib/execution.ts @@ -411,13 +411,18 @@ async function performFlowExecution( } } -interface ExecuteStepOptions { +interface OverrideData { + nodeId: NodeId; + data: string; +} +interface ExecuteStepParams { agentId: AgentId; flowId: FlowId; executionId: ExecutionId; stepId: StepId; artifacts: Artifact[]; stream?: boolean; + overrideData?: OverrideData[]; } export async function executeStep({ agentId, @@ -426,7 +431,8 @@ export async function executeStep({ stepId, artifacts, stream, -}: ExecuteStepOptions) { + overrideData, +}: ExecuteStepParams) { const agent = await db.query.agents.findFirst({ where: (agents, { eq }) => eq(agents.id, agentId), }); @@ -455,11 +461,43 @@ export async function executeStep({ if (node === undefined) { throw new Error("Node not found"); } + let executionNode = node; + const overrideDataMap = new Map( + overrideData?.map(({ nodeId, data }) => [nodeId, data]) ?? [], + ); + if (overrideDataMap.has(executionNode.id)) { + switch (executionNode.content.type) { + case "textGeneration": + executionNode = { + ...executionNode, + content: { + ...executionNode.content, + instruction: + overrideDataMap.get(executionNode.id) ?? + executionNode.content.instruction, + }, + } as Node; + break; + case "text": + executionNode = { + ...executeNode, + content: { + ...executionNode.content, + text: + overrideDataMap.get(executionNode.id) ?? + executionNode.content.text, + }, + } as Node; + break; + default: + break; + } + } const context: ExecutionContext = { agentId, executionId, - node, + node: executionNode, artifacts, nodes: graph.nodes, connections: graph.connections, diff --git a/app/webhooks/github/route.ts b/app/webhooks/github/route.ts index 0c8dccb4..8cfdacf4 100644 --- a/app/webhooks/github/route.ts +++ b/app/webhooks/github/route.ts @@ -30,9 +30,10 @@ export async function POST(request: NextRequest) { const id = request.headers.get("X-GitHub-Delivery") ?? ""; const name = request.headers.get("X-GitHub-Event") as WebhookEventName; - const payload = JSON.parse(body); - const event = { id, name, payload }; + const rawPayload = JSON.parse(body); + const event = { id, name, payload: rawPayload }; assertIssueCommentEvent(event); + const payload = event.payload; const command = parseCommand(payload.comment.body); if (command === null) { @@ -91,6 +92,24 @@ export async function POST(request: NextRequest) { runStartedAt: flowRunStartedAt, }; + const overrideData = integrationSetting.eventNodeMappings + .map((eventNodeMapping) => { + switch (eventNodeMapping.event) { + case "comment.body": + return { + nodeId: eventNodeMapping.nodeId, + data: command.content, + }; + case "issue.title": + return { + nodeId: eventNodeMapping.nodeId, + data: payload.issue.title, + }; + default: + return null; + } + }) + .filter((overrideData) => overrideData !== null); const finalExecution = await performFlowExecution({ initialExecution, executeStepFn: (stepId) => @@ -100,6 +119,7 @@ export async function POST(request: NextRequest) { executionId: executionId, stepId: stepId, artifacts: initialExecution.artifacts, + overrideData, }), onExecutionChange: (execution) => { initialExecution = execution;