MCPcopy
hub / github.com/wavetermdev/waveterm / GenerateTabStateAndTools

Function GenerateTabStateAndTools

pkg/aiusechat/tools.go:136–200  ·  view source on GitHub ↗
(ctx context.Context, tabid string, widgetAccess bool, chatOpts *uctypes.WaveChatOpts)

Source from the content-addressed store, hash-verified

134}
135
136func GenerateTabStateAndTools(ctx context.Context, tabid string, widgetAccess bool, chatOpts *uctypes.WaveChatOpts) (string, []uctypes.ToolDefinition, error) {
137 if tabid == "" {
138 return "", nil, nil
139 }
140 var blocks []*waveobj.Block
141 if widgetAccess {
142 if _, err := uuid.Parse(tabid); err != nil {
143 return "", nil, fmt.Errorf("tabid must be a valid UUID")
144 }
145
146 tabObj, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabid)
147 if err != nil {
148 return "", nil, fmt.Errorf("error getting tab: %v", err)
149 }
150
151 for _, blockId := range tabObj.BlockIds {
152 block, err := wstore.DBGet[*waveobj.Block](ctx, blockId)
153 if err != nil {
154 continue
155 }
156 blocks = append(blocks, block)
157 }
158 }
159 tabState := GenerateCurrentTabStatePrompt(blocks, widgetAccess)
160 // for debugging
161 // log.Printf("TABPROMPT %s\n", tabState)
162 var tools []uctypes.ToolDefinition
163 if widgetAccess {
164 // Only add screenshot tool for:
165 // - openai-responses API type
166 // - google-gemini API type with Gemini 3+ models
167 if chatOpts.Config.APIType == uctypes.APIType_OpenAIResponses ||
168 (chatOpts.Config.APIType == uctypes.APIType_GoogleGemini && aiutil.GeminiSupportsImageToolResults(chatOpts.Config.Model)) {
169 tools = append(tools, GetCaptureScreenshotToolDefinition(tabid))
170 }
171 tools = append(tools, GetReadTextFileToolDefinition())
172 tools = append(tools, GetReadDirToolDefinition())
173 tools = append(tools, GetWriteTextFileToolDefinition())
174 tools = append(tools, GetEditTextFileToolDefinition())
175 tools = append(tools, GetDeleteTextFileToolDefinition())
176 viewTypes := make(map[string]bool)
177 for _, block := range blocks {
178 if block.Meta == nil {
179 continue
180 }
181 viewType, ok := block.Meta["view"].(string)
182 if !ok {
183 continue
184 }
185 viewTypes[viewType] = true
186 if viewType == "tsunami" {
187 blockTools := generateToolsForTsunamiBlock(block)
188 tools = append(tools, blockTools...)
189 }
190 }
191 if viewTypes["term"] {
192 tools = append(tools, GetTermGetScrollbackToolDefinition(tabid))
193 // tools = append(tools, GetTermCommandOutputToolDefinition(tabid))

Callers 1

WaveAIPostMessageHandlerFunction · 0.85

Tested by

no test coverage detected