open-swe/src/types.ts

77 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-05-21 14:47:56 -07:00
import "@langchain/langgraph/zod";
import { z } from "zod";
import {
Annotation,
LangGraphRunnableConfig,
MessagesAnnotation,
} from "@langchain/langgraph";
type PlanItem = {
id: string;
plan: string;
completed: boolean;
};
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,
plan: Annotation<PlanItem[]>({
reducer: (_state, update) => update,
default: () => [],
}),
});
export type GraphState = typeof GraphAnnotation.State;
export type GraphUpdate = typeof GraphAnnotation.Update;
export const MCPConfig = z.object({
/**
* The MCP server URL.
*/
url: z.string(),
/**
* The list of tools to provide to the LLM.
*/
tools: z.array(z.string()),
});
export const GraphConfiguration = z.object({
/**
* The session ID of the Sandbox to use.
2025-05-21 14:47:56 -07:00
*/
sandbox_session_id: z
2025-05-21 14:47:56 -07:00
.string()
.optional()
.langgraph.metadata({
x_lg_ui_config: {
type: "hidden",
2025-05-21 14:47:56 -07:00
},
}),
/**
* The URL of the repository to clone.
2025-05-21 14:47:56 -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
/**
* The language of the sandbox to use.
2025-05-21 14:47:56 -07:00
*/
sandbox_language: z.enum(["js", "python"]).optional().langgraph.metadata({}),
2025-05-21 14:47:56 -07:00
});
export type GraphConfig = LangGraphRunnableConfig<
z.infer<typeof GraphConfiguration> & {
thread_id: string;
assistant_id: string;
}
>;