Skip to content

Commit

Permalink
feat(execution): Add node content override capability
Browse files Browse the repository at this point in the history
Add ability to override node content dynamically during execution

- Add OverrideData interface for specifying node content changes
- Implement content override logic in executeStep
- Add GitHub webhook support for issue and comment data injection
- Support overriding both text and textGeneration node types

This enables dynamic content injection into workflow nodes, particularly
useful for webhook-triggered executions where external data needs to be
incorporated into the flow.

BREAKING CHANGE: executeStep now accepts overrideData parameter that can
modify node content during execution
  • Loading branch information
toyamarinyon committed Dec 25, 2024
1 parent d86c78b commit d42db49
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
44 changes: 41 additions & 3 deletions app/(playground)/p/[agentId]/lib/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
});
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 22 additions & 2 deletions app/webhooks/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) =>
Expand All @@ -100,6 +119,7 @@ export async function POST(request: NextRequest) {
executionId: executionId,
stepId: stepId,
artifacts: initialExecution.artifacts,
overrideData,
}),
onExecutionChange: (execution) => {
initialExecution = execution;
Expand Down

0 comments on commit d42db49

Please sign in to comment.