From 38710f3cb007b2c632bc0885573c68568e5ce020 Mon Sep 17 00:00:00 2001 From: bracesproul Date: Thu, 6 Mar 2025 20:04:55 -0800 Subject: [PATCH] feat: Open Code agent --- agent/open-code/index.ts | 18 ++++++++++++++++++ agent/open-code/nodes/executor.ts | 5 +++++ agent/open-code/nodes/interrupt.ts | 5 +++++ agent/open-code/nodes/planner.ts | 25 +++++++++++++++++++++++++ agent/open-code/types.ts | 11 +++++++++++ 5 files changed, 64 insertions(+) create mode 100644 agent/open-code/index.ts create mode 100644 agent/open-code/nodes/executor.ts create mode 100644 agent/open-code/nodes/interrupt.ts create mode 100644 agent/open-code/nodes/planner.ts create mode 100644 agent/open-code/types.ts diff --git a/agent/open-code/index.ts b/agent/open-code/index.ts new file mode 100644 index 0000000..2ba2b72 --- /dev/null +++ b/agent/open-code/index.ts @@ -0,0 +1,18 @@ +import { END, START, StateGraph } from "@langchain/langgraph"; +import { OpenCodeAnnotation, OpenCodeState } from "./types"; +import { planner } from "./nodes/planner"; +import { interrupt } from "./nodes/interrupt"; +import { executor } from "./nodes/executor"; + +function handleRoutingFromExecutor(state: OpenCodeState): "executor" | "interrupt" {} + +function handleRoutingFromInterrupt(state: OpenCodeState): "executor" | typeof END {} + +const workflow = new StateGraph(OpenCodeAnnotation) + .addNode("planner", planner) + .addNode("executor", executor) + .addNode("interrupt", interrupt) + .addEdge(START, "planner") + .addEdge("planner", "executor") + .addConditionalEdges("executor", handleRoutingFromExecutor, ["executor", "interrupt"]) + .addConditionalEdges("interrupt", handleRoutingFromInterrupt, ["executor", END]) \ No newline at end of file diff --git a/agent/open-code/nodes/executor.ts b/agent/open-code/nodes/executor.ts new file mode 100644 index 0000000..e7e7023 --- /dev/null +++ b/agent/open-code/nodes/executor.ts @@ -0,0 +1,5 @@ +import { OpenCodeState, OpenCodeUpdate } from "../types"; + +export async function executor(state: OpenCodeState): Promise { + throw new Error("Not implemented" + state); +} \ No newline at end of file diff --git a/agent/open-code/nodes/interrupt.ts b/agent/open-code/nodes/interrupt.ts new file mode 100644 index 0000000..8d73de4 --- /dev/null +++ b/agent/open-code/nodes/interrupt.ts @@ -0,0 +1,5 @@ +import { OpenCodeState, OpenCodeUpdate } from "../types"; + +export async function interrupt(state: OpenCodeState): Promise { + throw new Error("Not implemented" + state); +} \ No newline at end of file diff --git a/agent/open-code/nodes/planner.ts b/agent/open-code/nodes/planner.ts new file mode 100644 index 0000000..b978741 --- /dev/null +++ b/agent/open-code/nodes/planner.ts @@ -0,0 +1,25 @@ +import { v4 as uuidv4 } from "uuid"; +import { AIMessage } from "@langchain/langgraph-sdk"; +import { OpenCodeState, OpenCodeUpdate } from "../types"; + +export async function planner(state: OpenCodeState): Promise { + const aiMessage: AIMessage = { + type: "ai", + id: uuidv4(), + content: "", + tool_calls: [ + { + name: "update_file", + args: { + args: { + new_file_content: "ADD_CODE_HERE" + }, + }, + id: uuidv4(), + type: "tool_call", + } + ] + } + + const toolMessage = {} +} \ No newline at end of file diff --git a/agent/open-code/types.ts b/agent/open-code/types.ts new file mode 100644 index 0000000..4b87557 --- /dev/null +++ b/agent/open-code/types.ts @@ -0,0 +1,11 @@ +import { Annotation } from "@langchain/langgraph"; +import { GenerativeUIAnnotation } from "../types"; + +export const OpenCodeAnnotation = Annotation.Root({ + messages: GenerativeUIAnnotation.spec.messages, + ui: GenerativeUIAnnotation.spec.ui, + timestamp: GenerativeUIAnnotation.spec.timestamp, +}); + +export type OpenCodeState = typeof OpenCodeAnnotation.State; +export type OpenCodeUpdate = typeof OpenCodeAnnotation.Update; \ No newline at end of file