{"modulePath":"github.com/wavetermdev/waveterm","version":"v0.14.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package aiusechat\n\n## Constants\n\n```go\nconst (\n\tOpenAIResponsesEndpoint        = \"https://api.openai.com/v1/responses\"\n\tOpenAIChatEndpoint             = \"https://api.openai.com/v1/chat/completions\"\n\tOpenRouterChatEndpoint         = \"https://openrouter.ai/api/v1/chat/completions\"\n\tNanoGPTChatEndpoint            = \"https://nano-gpt.com/api/v1/chat/completions\"\n\tGroqChatEndpoint               = \"https://api.groq.com/openai/v1/chat/completions\"\n\tAzureLegacyEndpointTemplate    = \"https://%s.openai.azure.com/openai/deployments/%s/chat/completions?api-version=%s\"\n\tAzureResponsesEndpointTemplate = \"https://%s.openai.azure.com/openai/v1/responses\"\n\tAzureChatEndpointTemplate      = \"https://%s.openai.azure.com/openai/v1/chat/completions\"\n\tGoogleGeminiEndpointTemplate   = \"https://generativelanguage.googleapis.com/v1beta/models/%s:streamGenerateContent\"\n\n\tAzureLegacyDefaultAPIVersion = \"2025-04-01-preview\"\n\n\tOpenAIAPITokenSecretName      = \"OPENAI_KEY\"\n\tOpenRouterAPITokenSecretName  = \"OPENROUTER_KEY\"\n\tNanoGPTAPITokenSecretName     = \"NANOGPT_KEY\"\n\tGroqAPITokenSecretName        = \"GROQ_KEY\"\n\tAzureOpenAIAPITokenSecretName = \"AZURE_OPENAI_KEY\"\n\tGoogleAIAPITokenSecretName    = \"GOOGLE_AI_KEY\"\n)\n```\n\n```go\nconst BuilderAppFileName = \"app.go\"\n```\n\n```go\nconst BuilderMaxTokens = 24 * 1024\n```\n\n```go\nconst DefaultAPI = uctypes.APIType_OpenAIResponses\n```\n\n```go\nconst DefaultMaxTokens = 4 * 1024\n```\n\n```go\nconst MaxEditFileSize = 100 * 1024 // 100KB\n\n```\n\n```go\nconst ReadDirDefaultMaxEntries = 500\n```\n\n```go\nconst ReadDirHardMaxEntries = 10000\n```\n\n```go\nconst ReadFileDefaultLineCount = 100\n```\n\n```go\nconst ReadFileDefaultMaxBytes = 50 * 1024\n```\n\n```go\nconst StopReasonMaxBytes = \"max_bytes\"\n```\n\n## Variables\n\n```go\nvar AzureResourceNameRegex = regexp.MustCompile(`^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`)\n```\n\n```go\nvar SystemPromptText_NoTools = strings.Join([]string{\n\t`You are Wave AI, an assistant embedded in Wave Terminal (a terminal with graphical widgets).`,\n\t`You appear as a pull-out panel on the left; widgets are on the right.`,\n\n\t`Be truthful about your capabilities. You can answer questions, explain concepts, provide code examples, and help with technical problems, but you cannot directly access files, execute commands, or interact with the terminal. If you lack specific data or access, say so directly and suggest what the user could do to provide it.`,\n\n\t`Be concise and direct. Prefer determinism over speculation. If a brief clarifying question eliminates guesswork, ask it.`,\n\n\t`User-attached text files may appear inline as \u003cAttachedTextFile_xxxxxxxx file_name=\"...\"\u003e\\ncontent\\n\u003c/AttachedTextFile_xxxxxxxx\u003e.`,\n\t`User-attached directories use the tag \u003cAttachedDirectoryListing_xxxxxxxx directory_name=\"...\"\u003eJSON DirInfo\u003c/AttachedDirectoryListing_xxxxxxxx\u003e.`,\n\t`If multiple attached files exist, treat each as a separate source file with its own file_name.`,\n\t`When the user refers to these files, use their inline content directly for analysis and discussion.`,\n\n\t`When presenting commands or any runnable multi-line code, always use fenced Markdown code blocks.`,\n\t`Use an appropriate language hint after the opening fence (e.g., \"bash\" for shell commands, \"go\" for Go, \"json\" for JSON).`,\n\t`For shell commands, do NOT prefix lines with \"$\" or shell prompts. Use placeholders in ALL_CAPS (e.g., PROJECT_ID) and explain them once after the block if needed.`,\n\t\"Reserve inline code (single backticks) for short references like command names (`grep`, `less`), flags, env vars, file paths, or tiny snippets not meant to be executed.\",\n\t`You may use Markdown (lists, tables, bold/italics) to improve readability.`,\n\t`Never comment on or justify your formatting choices; just follow these rules.`,\n\t`When generating code or command blocks, try to keep lines under ~100 characters wide where practical (soft wrap; do not break tokens mid-word). Favor indentation and short variable names to stay compact, but correctness always takes priority.`,\n\n\t`If a request would execute dangerous or destructive actions, warn briefly and provide a safer alternative.`,\n\t`If output is very long, prefer a brief summary plus a copy-ready fenced block or offer a follow-up chunking strategy.`,\n\n\t`You cannot directly write files, execute shell commands, run code in the terminal, or access remote files.`,\n\t`When users ask for code or commands, provide ready-to-use examples they can copy and execute themselves.`,\n\t`If they need file modifications, show the exact changes they should make.`,\n\n\t`You have NO API access to widgets or Wave Terminal internals.`,\n}, \" \")\n```\n\n```go\nvar SystemPromptText_OpenAI = strings.Join([]string{\n\t`You are Wave AI, an assistant embedded in Wave Terminal (a terminal with graphical widgets).`,\n\t`You appear as a pull-out panel on the left; widgets are on the right.`,\n\n\t`Tools define your only capabilities. If a capability is not provided by a tool, you cannot do it. Never fabricate data or pretend to call tools. If you lack data or access, say so directly and suggest the next best step.`,\n\t`Use read-only tools (capture_screenshot, read_text_file, read_dir, term_get_scrollback) automatically whenever they help answer the user's request. When a user clearly expresses intent to modify something (write/edit/delete files), call the corresponding tool directly.`,\n\n\t`Be concise and direct. Prefer determinism over speculation. If a brief clarifying question eliminates guesswork, ask it.`,\n\n\t`User-attached text files may appear inline as \u003cAttachedTextFile_xxxxxxxx file_name=\"...\"\u003e\\ncontent\\n\u003c/AttachedTextFile_xxxxxxxx\u003e.`,\n\t`User-attached directories use the tag \u003cAttachedDirectoryListing_xxxxxxxx directory_name=\"...\"\u003eJSON DirInfo\u003c/AttachedDirectoryListing_xxxxxxxx\u003e.`,\n\t`If multiple attached files exist, treat each as a separate source file with its own file_name.`,\n\t`When the user refers to these files, use their inline content directly; do NOT call any read_text_file or file-access tools to re-read them unless asked.`,\n\n\t`When presenting commands or any runnable multi-line code, always use fenced Markdown code blocks.`,\n\t`Use an appropriate language hint after the opening fence (e.g., \"bash\" for shell commands, \"go\" for Go, \"json\" for JSON).`,\n\t`For shell commands, do NOT prefix lines with \"$\" or shell prompts. Use placeholders in ALL_CAPS (e.g., PROJECT_ID) and explain them once after the block if needed.`,\n\t\"Reserve inline code (single backticks) for short references like command names (`grep`, `less`), flags, env vars, file paths, or tiny snippets not meant to be executed.\",\n\t`You may use Markdown (lists, tables, bold/italics) to improve readability.`,\n\t`Never comment on or justify your formatting choices; just follow these rules.`,\n\t`When generating code or command blocks, try to keep lines under ~100 characters wide where practical (soft wrap; do not break tokens mid-word). Favor indentation and short variable names to stay compact, but correctness always takes priority.`,\n\n\t`If a request would execute dangerous or destructive actions, warn briefly and provide a safer alternative.`,\n\t`If output is very long, prefer a brief summary plus a copy-ready fenced block or offer a follow-up chunking strategy.`,\n\n\t`You can write and edit local files on disk using available tools, but you cannot execute shell commands, run code in the terminal, or read/write remote files.`,\n\t`If the user asks you to execute commands or run code, or deal with remote files say that these features aren't available yet AND make sure to say that they are coming soon (stay tuned for updates).`,\n\t`Instead, show them exactly what command or code they could copy-paste to run manually.`,\n\n\t`You have NO API access to widgets or Wave unless provided via an explicit tool.`,\n}, \" \")\n```\n\n```go\nvar SystemPromptText_StrictToolAddOn = `## Tool Call Rules (STRICT)\n\nWhen you decide a file write/edit tool call is needed:\n\n- Output ONLY the tool call.\n- Do NOT include any explanation, summary, or file content in the chat.\n- Do NOT echo the file content before or after the tool call.\n- After the tool call result is returned, respond ONLY with what the user directly asked for. If they did not ask to see the file content, do NOT show it.\n`\n```\n\n## Functions\n\n```go\nfunc CombineConsecutiveSameRoleMessages(uiChat *uctypes.UIChat) *uctypes.UIChat\n```\nCombineConsecutiveSameRoleMessages combines consecutive UIMessages with the same role by appending their Parts together. This is useful for APIs like OpenAI that may split assistant messages into separate messages (e.g., one for text and one for tool calls).\n\n```go\nfunc ComputeResolvedAIModeConfigs(fullConfig wconfig.FullConfigType) map[string]wconfig.AIModeConfigType\n```\n\n```go\nfunc ConvertAIChatToUIChat(aiChat *uctypes.AIChat) (*uctypes.UIChat, error)\n```\nConvertAIChatToUIChat converts an AIChat to a UIChat by routing to the appropriate provider-specific converter based on APIType, then combining consecutive same-role messages.\n\n```go\nfunc CreateWriteTextFileDiff(ctx context.Context, chatId string, toolCallId string) ([]byte, []byte, error)\n```\nCreateWriteTextFileDiff generates a diff for write\\_text\\_file or edit\\_text\\_file tool calls. Returns the original content, modified content, and any error. For Anthropic, this returns an unimplemented error.\n\n```go\nfunc EditTextFileDryRun(input any, fileOverride string) ([]byte, []byte, error)\n```\nEditTextFileDryRun applies edits to a file and returns the original and modified content without writing to disk. Takes the same input format as editTextFileCallback.\n\n```go\nfunc GenerateCurrentTabStatePrompt(blocks []*waveobj.Block, widgetAccess bool) string\n```\n\n```go\nfunc GenerateTabStateAndTools(ctx context.Context, tabid string, widgetAccess bool, chatOpts *uctypes.WaveChatOpts) (string, []uctypes.ToolDefinition, error)\n```\n\n```go\nfunc GetAdderToolDefinition() uctypes.ToolDefinition\n```\nUsed for internal testing of tool loops\n\n```go\nfunc GetBuilderEditAppFileToolDefinition(appId string, builderId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetBuilderListFilesToolDefinition(appId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetBuilderWriteAppFileToolDefinition(appId string, builderId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetCaptureScreenshotToolDefinition(tabId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetChatUsage(chat *uctypes.AIChat) uctypes.AIUsage\n```\n\n```go\nfunc GetDeleteTextFileToolDefinition() uctypes.ToolDefinition\n```\n\n```go\nfunc GetEditTextFileToolDefinition() uctypes.ToolDefinition\n```\n\n```go\nfunc GetGlobalRateLimit() *uctypes.RateLimitInfo\n```\n\n```go\nfunc GetReadDirToolDefinition() uctypes.ToolDefinition\n```\n\n```go\nfunc GetReadTextFileToolDefinition() uctypes.ToolDefinition\n```\n\n```go\nfunc GetTermCommandOutputToolDefinition(tabId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetTsunamiGetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition\n```\n\n```go\nfunc GetTsunamiGetDataToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition\n```\n\n```go\nfunc GetTsunamiSetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition\n```\n\n```go\nfunc GetWebNavigateToolDefinition(tabId string) uctypes.ToolDefinition\n```\n\n```go\nfunc GetWriteTextFileToolDefinition() uctypes.ToolDefinition\n```\n\n```go\nfunc InitAIModeConfigWatcher()\n```\n\n```go\nfunc MakeBlockShortDesc(block *waveobj.Block) string\n```\n\n```go\nfunc RegisterToolApproval(toolCallId string, sseHandler *sse.SSEHandlerCh)\n```\n\n```go\nfunc ResolveToolCall(toolDef *uctypes.ToolDefinition, toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpts) (result uctypes.AIToolResult)\n```\n\n```go\nfunc RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, backend UseChatBackend, chatOpts uctypes.WaveChatOpts) (*uctypes.AIMetrics, error)\n```\n\n```go\nfunc UnregisterToolApproval(toolCallId string)\n```\n\n```go\nfunc UpdateToolApproval(toolCallId string, approval string) error\n```\n\n```go\nfunc WaitForToolApproval(ctx context.Context, toolCallId string) (string, error)\n```\n\n```go\nfunc WaveAIGetChatHandler(w http.ResponseWriter, r *http.Request)\n```\n\n```go\nfunc WaveAIPostMessageHandler(w http.ResponseWriter, r *http.Request)\n```\n\n```go\nfunc WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, message *uctypes.AIMessage, chatOpts uctypes.WaveChatOpts) error\n```\n\n## Types\n\n```go\ntype ApprovalRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\ntype ApprovalRequest struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\ntype CommandInfo struct {\n\tCommand  string `json:\"command\"`\n\tStatus   string `json:\"status\"`\n\tExitCode *int   `json:\"exitcode,omitempty\"`\n}\n```\n\n```go\ntype PostMessageRequest struct {\n\tTabId        string            `json:\"tabid,omitempty\"`\n\tBuilderId    string            `json:\"builderid,omitempty\"`\n\tBuilderAppId string            `json:\"builderappid,omitempty\"`\n\tChatID       string            `json:\"chatid\"`\n\tMsg          uctypes.AIMessage `json:\"msg\"`\n\tWidgetAccess bool              `json:\"widgetaccess,omitempty\"`\n\tAIMode       string            `json:\"aimode\"`\n}\n```\nPostMessageRequest represents the request body for posting a message\n\n```go\ntype StaticFileInfo struct {\n\tName         string `json:\"name\"`\n\tSize         int64  `json:\"size\"`\n\tModified     string `json:\"modified\"`\n\tModifiedTime string `json:\"modified_time\"`\n}\n```\n\n```go\ntype TermCommandOutputToolInput struct {\n\tWidgetId string `json:\"widget_id\"`\n}\n```\n\n```go\ntype TermGetScrollbackToolInput struct {\n\tWidgetId  string `json:\"widget_id\"`\n\tLineStart int    `json:\"line_start,omitempty\"`\n\tCount     int    `json:\"count,omitempty\"`\n}\n```\n\n```go\ntype TermGetScrollbackToolOutput struct {\n\tTotalLines         int          `json:\"totallines\"`\n\tLineStart          int          `json:\"linestart\"`\n\tLineEnd            int          `json:\"lineend\"`\n\tReturnedLines      int          `json:\"returnedlines\"`\n\tContent            string       `json:\"content\"`\n\tSinceLastOutputSec *int         `json:\"sincelastoutputsec,omitempty\"`\n\tHasMore            bool         `json:\"hasmore\"`\n\tNextStart          *int         `json:\"nextstart\"`\n\tLastCommand        *CommandInfo `json:\"lastcommand,omitempty\"`\n}\n```\n\n```go\ntype UseChatBackend interface {\n\t// RunChatStep executes a single step in the chat conversation with the AI backend.\n\t// Returns the stop reason, native messages from the response, rate limit info, and any error.\n\t// The cont parameter allows continuing from a previous response (e.g., after rate limiting).\n\tRunChatStep(\n\t\tctx context.Context,\n\t\tsseHandler *sse.SSEHandlerCh,\n\t\tchatOpts uctypes.WaveChatOpts,\n\t\tcont *uctypes.WaveContinueResponse,\n\t) (*uctypes.WaveStopReason, []uctypes.GenAIMessage, *uctypes.RateLimitInfo, error)\n\n\t// UpdateToolUseData updates the tool use data for a specific tool call in the chat.\n\t// This is used to update the UI state for tool execution (approval status, results, etc.)\n\tUpdateToolUseData(chatId string, toolCallId string, toolUseData uctypes.UIMessageDataToolUse) error\n\n\t// RemoveToolUseCall removes a tool use call from the chat's native messages.\n\t// This is used to clean up incomplete or canceled tool calls when stopping execution.\n\tRemoveToolUseCall(chatId string, toolCallId string) error\n\n\t// ConvertToolResultsToNativeChatMessage converts tool execution results into native chat messages\n\t// that can be sent back to the AI backend. Returns a slice of messages (some backends may\n\t// require multiple messages per tool result).\n\tConvertToolResultsToNativeChatMessage(toolResults []uctypes.AIToolResult) ([]uctypes.GenAIMessage, error)\n\n\t// ConvertAIMessageToNativeChatMessage converts a generic AIMessage (from the user)\n\t// into the backend's native message format for sending to the API.\n\tConvertAIMessageToNativeChatMessage(message uctypes.AIMessage) (uctypes.GenAIMessage, error)\n\n\t// GetFunctionCallInputByToolCallId retrieves the function call input data for a specific\n\t// tool call ID from the chat history. Returns the function call structure\n\t// or nil if not found.\n\tGetFunctionCallInputByToolCallId(aiChat uctypes.AIChat, toolCallId string) *uctypes.AIFunctionCallInput\n\n\t// ConvertAIChatToUIChat converts a stored AIChat (with native backend messages) into\n\t// a UI-friendly UIChat format that can be displayed in the frontend.\n\tConvertAIChatToUIChat(aiChat uctypes.AIChat) (*uctypes.UIChat, error)\n}\n```\nUseChatBackend defines the interface for AI chat backend providers (OpenAI, Anthropic, etc.) This interface abstracts the provider-specific API calls needed by the usechat system.\n\n```go\nfunc GetBackendByAPIType(apiType string) (UseChatBackend, error)\n```\nGetBackendByAPIType returns the appropriate UseChatBackend implementation for the given API type\n\n```go\ntype WebNavigateToolInput struct {\n\tWidgetId string `json:\"widget_id\"`\n\tUrl      string `json:\"url\"`\n}\n```\n\n","path":"github.com/wavetermdev/waveterm/pkg/aiusechat","name":"aiusechat","synopsis":"","isRedistributable":true}
