MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / aiRun

Function aiRun

cmd/wsh/cmd/wshcmd-ai.go:69–211  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

67}
68
69func aiRun(cmd *cobra.Command, args []string) (rtnErr error) {
70 defer func() {
71 sendActivity("ai", rtnErr == nil)
72 }()
73
74 if len(args) == 0 && aiMessageFlag == "" {
75 OutputHelpMessage(cmd)
76 return fmt.Errorf("no files or message provided")
77 }
78
79 const maxFileCount = 15
80 const rpcTimeout = 30000
81
82 var allFiles []wshrpc.AIAttachedFile
83 var stdinUsed bool
84
85 if len(args) > maxFileCount {
86 return fmt.Errorf("too many files (maximum %d files allowed)", maxFileCount)
87 }
88
89 for _, filePath := range args {
90 var data []byte
91 var fileName string
92 var mimeType string
93 var err error
94
95 if filePath == "-" {
96 if stdinUsed {
97 return fmt.Errorf("stdin (-) can only be used once")
98 }
99 stdinUsed = true
100
101 data, err = io.ReadAll(os.Stdin)
102 if err != nil {
103 return fmt.Errorf("reading from stdin: %w", err)
104 }
105 fileName = "stdin"
106 mimeType = "text/plain"
107 } else {
108 fileInfo, err := os.Stat(filePath)
109 if err != nil {
110 return fmt.Errorf("accessing file %s: %w", filePath, err)
111 }
112 absPath, err := filepath.Abs(filePath)
113 if err != nil {
114 return fmt.Errorf("getting absolute path for %s: %w", filePath, err)
115 }
116
117 if fileInfo.IsDir() {
118 result, err := fileutil.ReadDir(filePath, 500)
119 if err != nil {
120 return fmt.Errorf("reading directory %s: %w", filePath, err)
121 }
122 jsonData, err := json.Marshal(result)
123 if err != nil {
124 return fmt.Errorf("marshaling directory listing for %s: %w", filePath, err)
125 }
126 data = jsonData

Callers

nothing calls this directly

Calls 12

ReadDirFunction · 0.92
ContainsBinaryDataFunction · 0.92
MakeTabRouteIdFunction · 0.92
WaveAIAddContextCommandFunction · 0.92
sendActivityFunction · 0.85
OutputHelpMessageFunction · 0.85
StatMethod · 0.80
ReadFileMethod · 0.80
detectMimeTypeFunction · 0.70
getMaxFileSizeFunction · 0.70
ReadAllMethod · 0.45
IsDirMethod · 0.45

Tested by

no test coverage detected