2025-05-21 14:47:56 -07:00
|
|
|
import "@langchain/langgraph/zod";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
import {
|
|
|
|
|
Annotation,
|
|
|
|
|
LangGraphRunnableConfig,
|
|
|
|
|
MessagesAnnotation,
|
|
|
|
|
} from "@langchain/langgraph";
|
|
|
|
|
|
2025-05-22 12:57:26 -07:00
|
|
|
export type PlanItem = {
|
|
|
|
|
/**
|
|
|
|
|
* The index of the plan item. This is the order in which
|
|
|
|
|
* it should be executed.
|
|
|
|
|
*/
|
|
|
|
|
index: number;
|
|
|
|
|
/**
|
|
|
|
|
* The actual task to perform.
|
|
|
|
|
*/
|
2025-05-21 14:47:56 -07:00
|
|
|
plan: string;
|
2025-05-22 12:57:26 -07:00
|
|
|
/**
|
|
|
|
|
* Whether or not the plan item has been completed.
|
|
|
|
|
*/
|
2025-05-21 14:47:56 -07:00
|
|
|
completed: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-21 17:53:43 -07:00
|
|
|
export type TargetRepository = {
|
|
|
|
|
owner: string;
|
|
|
|
|
repo: string;
|
|
|
|
|
branch?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-21 14:47:56 -07:00
|
|
|
export const GraphAnnotation = Annotation.Root({
|
|
|
|
|
messages: MessagesAnnotation.spec.messages,
|
2025-05-22 11:07:21 -07:00
|
|
|
proposedPlan: Annotation<string[]>({
|
|
|
|
|
reducer: (_state, update) => update,
|
|
|
|
|
default: () => [],
|
|
|
|
|
}),
|
2025-05-21 14:47:56 -07:00
|
|
|
plan: Annotation<PlanItem[]>({
|
|
|
|
|
reducer: (_state, update) => update,
|
|
|
|
|
default: () => [],
|
|
|
|
|
}),
|
2025-05-22 11:07:21 -07:00
|
|
|
planChangeRequest: Annotation<string | undefined>({
|
|
|
|
|
reducer: (_state, update) => update,
|
|
|
|
|
default: () => undefined,
|
|
|
|
|
}),
|
2025-05-21 14:47:56 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type GraphState = typeof GraphAnnotation.State;
|
|
|
|
|
export type GraphUpdate = typeof GraphAnnotation.Update;
|
|
|
|
|
|
2025-05-22 13:19:40 -07:00
|
|
|
const MODEL_OPTIONS = [
|
|
|
|
|
{
|
|
|
|
|
label: "Claude Sonnet 4 (Extended Thinking)",
|
|
|
|
|
value: "anthropic:extended-thinking:claude-sonnet-4-0",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Claude Opus 4 (Extended Thinking)",
|
|
|
|
|
value: "anthropic:extended-thinking:claude-opus-4-0",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Claude Sonnet 4",
|
|
|
|
|
value: "anthropic:claude-sonnet-4-0",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Claude Opus 4",
|
|
|
|
|
value: "anthropic:claude-opus-4-0",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Claude 3.7 Sonnet",
|
|
|
|
|
value: "anthropic:claude-3-7-sonnet-latest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Claude 3.5 Sonnet",
|
|
|
|
|
value: "anthropic:claude-3-5-sonnet-latest",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "o4",
|
|
|
|
|
value: "openai:o4",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "o4 mini",
|
|
|
|
|
value: "openai:o4-mini",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "o3",
|
|
|
|
|
value: "openai:o3",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "o3 mini",
|
|
|
|
|
value: "openai:o3-mini",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "GPT 4o",
|
|
|
|
|
value: "openai:gpt-4o",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "GPT 4.1",
|
|
|
|
|
value: "openai:gpt-4.1",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Gemini 2.5 Pro Preview",
|
|
|
|
|
value: "google-genai:gemini-2.5-pro-preview-05-06",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "Gemini 2.5 Flash Preview",
|
|
|
|
|
value: "google-genai:gemini-2.5-flash-preview-05-20",
|
|
|
|
|
},
|
|
|
|
|
];
|
2025-05-21 14:47:56 -07:00
|
|
|
|
|
|
|
|
export const GraphConfiguration = z.object({
|
|
|
|
|
/**
|
2025-05-21 17:53:43 -07:00
|
|
|
* The session ID of the Sandbox to use.
|
2025-05-21 14:47:56 -07:00
|
|
|
*/
|
2025-05-21 17:53:43 -07:00
|
|
|
sandbox_session_id: z
|
2025-05-21 14:47:56 -07:00
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
2025-05-21 17:53:43 -07:00
|
|
|
type: "hidden",
|
2025-05-21 14:47:56 -07:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
/**
|
2025-05-21 17:53:43 -07:00
|
|
|
* The URL of the repository to clone.
|
2025-05-21 14:47:56 -07:00
|
|
|
*/
|
2025-05-21 17:53:43 -07:00
|
|
|
target_repository: z
|
|
|
|
|
.object({
|
|
|
|
|
owner: z.string(),
|
|
|
|
|
repo: z.string(),
|
|
|
|
|
branch: z.string().optional(),
|
|
|
|
|
})
|
|
|
|
|
.langgraph.metadata({}),
|
2025-05-21 14:47:56 -07:00
|
|
|
/**
|
2025-05-21 17:53:43 -07:00
|
|
|
* The language of the sandbox to use.
|
2025-05-21 14:47:56 -07:00
|
|
|
*/
|
2025-05-21 17:53:43 -07:00
|
|
|
sandbox_language: z.enum(["js", "python"]).optional().langgraph.metadata({}),
|
2025-05-21 19:08:51 -07:00
|
|
|
/**
|
2025-05-22 13:19:40 -07:00
|
|
|
* The model ID to use for the planning step.
|
|
|
|
|
* This includes initial planning, and rewriting.
|
|
|
|
|
* @default "anthropic:extended-thinking:claude-sonnet-4-0"
|
2025-05-21 19:08:51 -07:00
|
|
|
*/
|
2025-05-22 13:19:40 -07:00
|
|
|
plannerModelName: z
|
2025-05-21 19:08:51 -07:00
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
|
|
|
|
type: "select",
|
2025-05-22 13:19:40 -07:00
|
|
|
default: "anthropic:extended-thinking:claude-sonnet-4-0",
|
|
|
|
|
description: "The model to use for planning",
|
|
|
|
|
options: MODEL_OPTIONS,
|
2025-05-21 19:08:51 -07:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
/**
|
2025-05-22 13:19:40 -07:00
|
|
|
* The temperature to use for the planning step.
|
|
|
|
|
* This includes initial planning, and rewriting.
|
|
|
|
|
* If selecting a reasoning model, this will be ignored.
|
|
|
|
|
* @default 0
|
2025-05-21 19:08:51 -07:00
|
|
|
*/
|
2025-05-22 13:19:40 -07:00
|
|
|
plannerTemperature: z
|
2025-05-21 19:08:51 -07:00
|
|
|
.number()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
|
|
|
|
type: "slider",
|
|
|
|
|
default: 0,
|
|
|
|
|
min: 0,
|
|
|
|
|
max: 2,
|
|
|
|
|
step: 0.1,
|
|
|
|
|
description: "Controls randomness (0 = deterministic, 2 = creative)",
|
|
|
|
|
},
|
|
|
|
|
}),
|
2025-05-22 13:19:40 -07:00
|
|
|
|
2025-05-21 19:08:51 -07:00
|
|
|
/**
|
2025-05-22 13:19:40 -07:00
|
|
|
* The model ID to use for action generation.
|
|
|
|
|
* @default "anthropic:claude-sonnet-4-0"
|
2025-05-21 19:08:51 -07:00
|
|
|
*/
|
2025-05-22 13:19:40 -07:00
|
|
|
actionGeneratorModelName: z
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
|
|
|
|
type: "select",
|
|
|
|
|
default: "anthropic:claude-sonnet-4-0",
|
|
|
|
|
description: "The model to use for action generation",
|
|
|
|
|
options: MODEL_OPTIONS,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
/**
|
|
|
|
|
* The temperature to use for action generation.
|
|
|
|
|
* If selecting a reasoning model, this will be ignored.
|
|
|
|
|
* @default 0
|
|
|
|
|
*/
|
|
|
|
|
actionGeneratorTemperature: z
|
2025-05-21 19:08:51 -07:00
|
|
|
.number()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
2025-05-22 13:19:40 -07:00
|
|
|
type: "slider",
|
|
|
|
|
default: 0,
|
|
|
|
|
min: 0,
|
|
|
|
|
max: 2,
|
|
|
|
|
step: 0.1,
|
|
|
|
|
description: "Controls randomness (0 = deterministic, 2 = creative)",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The model ID to use for progress plan checking.
|
|
|
|
|
* @default "anthropic:claude-sonnet-4-0"
|
|
|
|
|
*/
|
|
|
|
|
progressPlanCheckerModelName: z
|
|
|
|
|
.string()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
|
|
|
|
type: "select",
|
|
|
|
|
default: "anthropic:claude-sonnet-4-0",
|
|
|
|
|
description: "The model to use for progress plan checking",
|
|
|
|
|
options: MODEL_OPTIONS,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
/**
|
|
|
|
|
* The temperature to use for progress plan checking.
|
|
|
|
|
* If selecting a reasoning model, this will be ignored.
|
|
|
|
|
* @default 0
|
|
|
|
|
*/
|
|
|
|
|
progressPlanCheckerTemperature: z
|
|
|
|
|
.number()
|
|
|
|
|
.optional()
|
|
|
|
|
.langgraph.metadata({
|
|
|
|
|
x_lg_ui_config: {
|
|
|
|
|
type: "slider",
|
|
|
|
|
default: 0,
|
|
|
|
|
min: 0,
|
|
|
|
|
max: 2,
|
|
|
|
|
step: 0.1,
|
|
|
|
|
description: "Controls randomness (0 = deterministic, 2 = creative)",
|
2025-05-21 19:08:51 -07:00
|
|
|
},
|
|
|
|
|
}),
|
2025-05-21 14:47:56 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type GraphConfig = LangGraphRunnableConfig<
|
|
|
|
|
z.infer<typeof GraphConfiguration> & {
|
|
|
|
|
thread_id: string;
|
|
|
|
|
assistant_id: string;
|
|
|
|
|
}
|
|
|
|
|
>;
|