MCPcopy Create free account
hub / github.com/rilldata/rill / Handler

Method Handler

runtime/ai/develop_file.go:54–141  ·  view source on GitHub ↗
(ctx context.Context, args *DevelopFileArgs)

Source from the content-addressed store, hash-verified

52}
53
54func (t *DevelopFile) Handler(ctx context.Context, args *DevelopFileArgs) (*DevelopFileResult, error) {
55 // Validate input
56 if args.Path == "" || args.Prompt == "" {
57 return nil, fmt.Errorf("invalid input: path and prompt are required")
58 }
59 if !strings.HasPrefix(args.Path, "/") {
60 args.Path = "/" + args.Path
61 }
62
63 // Prepare the system prompts
64 generalInstructions, err := instructions.Load("development.md", instructions.Options{})
65 if err != nil {
66 return nil, fmt.Errorf("failed to load developer agent system prompt: %w", err)
67 }
68 var resourceInstructions *instructions.Instruction
69 switch args.Type {
70 case "", ".env", "api", "alert", "report":
71 // These types currently don't have additional resource-specific instructions
72 case "rill.yaml":
73 resourceInstructions, err = instructions.Load("resources/rillyaml.md", instructions.Options{})
74 if err != nil {
75 return nil, fmt.Errorf("failed to load developer agent resource-specific system prompt: %w", err)
76 }
77 case "connector", "model", "metrics_view", "explore", "canvas", "theme":
78 resourceInstructions, err = instructions.Load(fmt.Sprintf("resources/%s.md", args.Type), instructions.Options{})
79 if err != nil {
80 return nil, fmt.Errorf("failed to load developer agent resource-specific system prompt: %w", err)
81 }
82 default:
83 return nil, fmt.Errorf("invalid input: unsupported resource type %q", args.Type)
84 }
85
86 // Prepare the user prompt
87 userPrompt, err := t.userPrompt(ctx, args)
88 if err != nil {
89 return nil, err
90 }
91
92 // Pre-invoke some tool calls
93 s := GetSession(ctx)
94 _, err = s.CallTool(ctx, RoleAssistant, ListFilesName, nil, &ListFilesArgs{})
95 if err != nil {
96 return nil, err
97 }
98 _, err = s.CallTool(ctx, RoleAssistant, ProjectStatusName, nil, &ProjectStatusArgs{})
99 if err != nil {
100 return nil, err
101 }
102 _, _ = s.CallTool(ctx, RoleAssistant, ReadFileName, nil, &ReadFileArgs{
103 Path: args.Path,
104 })
105 if ctx.Err() != nil { // Ignore tool error since the file may not exist
106 return nil, ctx.Err()
107 }
108
109 // Build initial completion messages
110 messages := []*aiv1.CompletionMessage{NewTextCompletionMessage(RoleSystem, generalInstructions.Body)}
111 if resourceInstructions != nil {

Callers

nothing calls this directly

Calls 12

userPromptMethod · 0.95
LoadFunction · 0.92
GetSessionFunction · 0.85
NewTextCompletionMessageFunction · 0.85
FilterByParentFunction · 0.85
CallToolMethod · 0.80
NewCompletionMessagesMethod · 0.80
MessagesWithResultsMethod · 0.80
IDMethod · 0.80
ErrorfMethod · 0.65
ErrMethod · 0.65
CompleteMethod · 0.65

Tested by

no test coverage detected