startInteractivePromptMode starts the interactive shell with the returned LLM assigned as $agent
(ctx context.Context, dag *dagger.Client, response any)
| 972 | |
| 973 | // startInteractivePromptMode starts the interactive shell with the returned LLM assigned as $agent |
| 974 | func startInteractivePromptMode(ctx context.Context, dag *dagger.Client, response any) error { |
| 975 | // Extract the LLM ID from the response |
| 976 | var llmID string |
| 977 | switch v := response.(type) { |
| 978 | case string: |
| 979 | llmID = v |
| 980 | case map[string]any: |
| 981 | if id, ok := v["id"].(string); ok { |
| 982 | llmID = id |
| 983 | } else { |
| 984 | return fmt.Errorf("startInteractivePromptMode: no ID found in LLM object: %+v", v) |
| 985 | } |
| 986 | default: |
| 987 | return fmt.Errorf("startInteractivePromptMode: unexpected response type for LLM: %T", v) |
| 988 | } |
| 989 | |
| 990 | // Set up the shell handler with prompt mode |
| 991 | handler := newShellCallHandler(dag, Frontend) |
| 992 | handler.mode = modePrompt |
| 993 | |
| 994 | // Initialize the handler |
| 995 | if err := handler.Initialize(ctx); err != nil { |
| 996 | return err |
| 997 | } |
| 998 | |
| 999 | // Load the LLM from the ID and assign it as $agent |
| 1000 | llm := dagger.Ref[*dagger.LLM](dag, dagger.ID(llmID)) |
| 1001 | if _, err := handler.llm(ctx); err != nil { // init llmSession |
| 1002 | return err |
| 1003 | } |
| 1004 | if err := handler.llmSession.updateLLMAndAgentVar(llm); err != nil { |
| 1005 | return err |
| 1006 | } |
| 1007 | |
| 1008 | // Start interactive mode |
| 1009 | return handler.runInteractive(ctx) |
| 1010 | } |
| 1011 | |
| 1012 | func printID(w io.Writer, response any, typeDef *modTypeDef) error { |
| 1013 | switch { |
no test coverage detected