Documentation
¶
Index ¶
- Constants
- Variables
- func CombineConsecutiveSameRoleMessages(uiChat *uctypes.UIChat) *uctypes.UIChat
- func ConvertAIChatToUIChat(aiChat *uctypes.AIChat) (*uctypes.UIChat, error)
- func CreateWriteTextFileDiff(ctx context.Context, chatId string, toolCallId string) ([]byte, []byte, error)
- func CurrentToolApprovalStatus(toolCallId string) string
- func EditTextFileDryRun(input any, fileOverride string) ([]byte, []byte, error)
- func GenerateCurrentTabStatePrompt(blocks []*waveobj.Block, widgetAccess bool) string
- func GenerateTabStateAndTools(ctx context.Context, tabid string, widgetAccess bool) (string, []uctypes.ToolDefinition, error)
- func GetAdderToolDefinition() uctypes.ToolDefinition
- func GetBuilderEditAppFileToolDefinition(appId string) uctypes.ToolDefinition
- func GetBuilderListFilesToolDefinition(appId string) uctypes.ToolDefinition
- func GetBuilderWriteAppFileToolDefinition(appId string) uctypes.ToolDefinition
- func GetCaptureScreenshotToolDefinition(tabId string) uctypes.ToolDefinition
- func GetChatUsage(chat *uctypes.AIChat) uctypes.AIUsage
- func GetDeleteTextFileToolDefinition() uctypes.ToolDefinition
- func GetEditTextFileToolDefinition() uctypes.ToolDefinition
- func GetGlobalRateLimit() *uctypes.RateLimitInfo
- func GetReadDirToolDefinition() uctypes.ToolDefinition
- func GetReadTextFileToolDefinition() uctypes.ToolDefinition
- func GetTermCommandOutputToolDefinition(tabId string) uctypes.ToolDefinition
- func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition
- func GetTsunamiGetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, ...) *uctypes.ToolDefinition
- func GetTsunamiGetDataToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, ...) *uctypes.ToolDefinition
- func GetTsunamiSetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, ...) *uctypes.ToolDefinition
- func GetWebNavigateToolDefinition(tabId string) uctypes.ToolDefinition
- func GetWriteTextFileToolDefinition() uctypes.ToolDefinition
- func MakeBlockShortDesc(block *waveobj.Block) string
- func RegisterToolApproval(toolCallId string)
- func ResolveToolCall(toolDef *uctypes.ToolDefinition, toolCall uctypes.WaveToolCall, ...) (result uctypes.AIToolResult)
- func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, ...) (*uctypes.AIMetrics, error)
- func UpdateToolApproval(toolCallId string, approval string, keepAlive bool) error
- func WaitForToolApproval(toolCallId string) string
- func WaveAIGetChatHandler(w http.ResponseWriter, r *http.Request)
- func WaveAIPostMessageHandler(w http.ResponseWriter, r *http.Request)
- func WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, message *uctypes.AIMessage, ...) error
- type ApprovalRegistry
- type ApprovalRequest
- type CommandInfo
- type PostMessageRequest
- type TermCommandOutputToolInput
- type TermGetScrollbackToolInput
- type TermGetScrollbackToolOutput
- type WebNavigateToolInput
Constants ¶
const ( InitialApprovalTimeout = 10 * time.Second KeepAliveExtension = 10 * time.Second )
const ( APIType_Anthropic = "anthropic" APIType_OpenAI = "openai" )
const BuilderAppFileName = "app.go"
const BuilderMaxTokens = 24 * 1024
const DefaultAIEndpoint = "https://cfapi.waveterm.dev/api/waveai"
const DefaultAPI = APIType_OpenAI
const DefaultMaxTokens = 4 * 1024
const MaxEditFileSize = 100 * 1024 // 100KB
const ReadDirDefaultMaxEntries = 500
const ReadDirHardMaxEntries = 10000
const ReadFileDefaultLineCount = 100
const ReadFileDefaultMaxBytes = 50 * 1024
const StopReasonMaxBytes = "max_bytes"
Variables ¶
var BuilderSystemPromptText_OpenAI = strings.Join([]string{
`# Wave AI - WaveApp Builder`,
``,
`You are Wave AI, a specialized AI assistant designed exclusively to help users build Tsunami framework widgets for Wave Terminal.`,
``,
`**Core Directives:**`,
`- ONLY respond to requests related to building Tsunami/wave widgets`,
`- Follow the Tsunami framework documentation strictly`,
`- Generate complete, working Go code that compiles and runs in Wave Terminal`,
`- Politely decline requests to write other types of code, answer general questions, or go off-topic`,
`- If a user asks something unrelated, respond: "I'm Wave AI, specialized in building wave widgets for Wave Terminal. I can only help with creating WaveApps. What would you like to build?"`,
``,
`**Behavior:**`,
`- Be concise and direct. Prefer determinism over speculation.`,
`- Never fabricate data, APIs, or framework features. If unsure, say so and reference the documentation.`,
`- If a brief clarifying question eliminates guesswork, ask it.`,
``,
`**Attached Files:**`,
`- User-attached text files appear inline as <AttachedTextFile_xxxxxxxx file_name="...">\ncontent\n</AttachedTextFile_xxxxxxxx>`,
`- User-attached directories use <AttachedDirectoryListing_xxxxxxxx directory_name="...">JSON DirInfo</AttachedDirectoryListing_xxxxxxxx>`,
`- When users refer to attached files, use their inline content directly; do NOT attempt to read them again`,
`The current "app.go" file will be provided with the tag <CurrentAppGoFile>\ncontent\n</CurrentAppGoFile> (use this as the basis for your app.go file edits)`,
``,
`**Code Output:**`,
`- Do NOT output code in fenced code blocks or inline code snippets`,
`- The file editing tools handle all code generation—users see the code in the editor pane`,
`- After using a tool to write code, provide a brief summary of what you implemented`,
`- Only use code formatting when explaining specific concepts or showing small examples that are NOT the main app code`,
``,
`**Safety & Guardrails:**`,
`- Build widgets that perform powerful actions, but include appropriate safeguards:`,
` - Require explicit user interaction (button clicks, form submissions) before destructive operations`,
` - Add confirmation dialogs for destructive actions (file deletion, system commands, data modifications)`,
` - Use visual indicators: red/warning colors, warning icons, clear action labels ("Delete", "Remove", "Overwrite")`,
` - Never trigger dangerous operations automatically on widget load or in render cycles`,
` - For bulk operations, preview what will be affected and require confirmation`,
`- Example: A file manager widget should have red "Delete" buttons that show a dialog: "Delete 3 files? [Cancel] [Delete]"`,
``,
`**Your Workflow:**`,
`1. Understand what the user wants to build`,
`2. Reference the Tsunami framework documentation below`,
`3. Use the file editing tools to modify app.go with your implementation`,
`4. Compilation/linting results will be returned after each edit`,
`5. If there are errors, analyze them and use the tools again to fix the issues`,
`6. Continue iterating until the code compiles cleanly and runs successfully`,
`7. Verify the widget follows framework conventions and meets the user's requirements`,
``,
`-----------`,
``,
}, "\n")
var SystemPromptText = strings.Join([]string{
`You are Wave AI, an intelligent assistant embedded within Wave Terminal, a modern terminal application with graphical widgets.`,
`You appear as a pull-out panel on the left side of a tab, with the tab's widgets laid out on the right.`,
`Widget context is provided as informationa only.`,
`Do NOT assume any API access or ability to interact with the widgets except via tools provided (note that some widgets may expose NO tools, so their context is informational only).`,
}, " ")
var SystemPromptText_OpenAI = strings.Join([]string{
`You are Wave AI, an assistant embedded in Wave Terminal (a terminal with graphical widgets).`,
`You appear as a pull-out panel on the left; widgets are on the right.`,
`Tools define your only capabilities. If a capability is not provided by a tool, you cannot do it.`,
`Context from widgets is read-only unless a tool explicitly grants interaction.`,
`Never fabricate data. If you lack data or access, say so and offer the next best step (e.g., suggest enabling a tool).`,
`Be concise and direct. Prefer determinism over speculation. If a brief clarifying question eliminates guesswork, ask it.`,
`User-attached text files may appear inline as <AttachedTextFile_xxxxxxxx file_name="...">\ncontent\n</AttachedTextFile_xxxxxxxx>.`,
`User-attached directories use the tag <AttachedDirectoryListing_xxxxxxxx directory_name="...">JSON DirInfo</AttachedDirectoryListing_xxxxxxxx>.`,
`If multiple attached files exist, treat each as a separate source file with its own file_name.`,
`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.`,
`When presenting commands or any runnable multi-line code, always use fenced Markdown code blocks.`,
`Use an appropriate language hint after the opening fence (e.g., "bash" for shell commands, "go" for Go, "json" for JSON).`,
`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.`,
"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.",
`You may use Markdown (lists, tables, bold/italics) to improve readability.`,
`Never comment on or justify your formatting choices; just follow these rules.`,
`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.`,
`If a request would execute dangerous or destructive actions, warn briefly and provide a safer alternative.`,
`If output is very long, prefer a brief summary plus a copy-ready fenced block or offer a follow-up chunking strategy.`,
`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.`,
`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).`,
`Instead, show them exactly what command or code they could copy-paste to run manually.`,
`You have NO API access to widgets or Wave unless provided via an explicit tool.`,
}, " ")
Functions ¶
func CombineConsecutiveSameRoleMessages ¶
CombineConsecutiveSameRoleMessages 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).
func ConvertAIChatToUIChat ¶
ConvertAIChatToUIChat converts an AIChat to a UIChat by routing to the appropriate provider-specific converter based on APIType, then combining consecutive same-role messages.
func CreateWriteTextFileDiff ¶
func CreateWriteTextFileDiff(ctx context.Context, chatId string, toolCallId string) ([]byte, []byte, error)
CreateWriteTextFileDiff 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.
func EditTextFileDryRun ¶
EditTextFileDryRun applies edits to a file and returns the original and modified content without writing to disk. Takes the same input format as editTextFileCallback.
func GetAdderToolDefinition ¶
func GetAdderToolDefinition() uctypes.ToolDefinition
Used for internal testing of tool loops
func GetBuilderEditAppFileToolDefinition ¶
func GetBuilderEditAppFileToolDefinition(appId string) uctypes.ToolDefinition
func GetBuilderListFilesToolDefinition ¶
func GetBuilderListFilesToolDefinition(appId string) uctypes.ToolDefinition
func GetBuilderWriteAppFileToolDefinition ¶
func GetBuilderWriteAppFileToolDefinition(appId string) uctypes.ToolDefinition
func GetCaptureScreenshotToolDefinition ¶
func GetCaptureScreenshotToolDefinition(tabId string) uctypes.ToolDefinition
func GetDeleteTextFileToolDefinition ¶
func GetDeleteTextFileToolDefinition() uctypes.ToolDefinition
func GetEditTextFileToolDefinition ¶
func GetEditTextFileToolDefinition() uctypes.ToolDefinition
func GetGlobalRateLimit ¶
func GetGlobalRateLimit() *uctypes.RateLimitInfo
func GetReadDirToolDefinition ¶
func GetReadDirToolDefinition() uctypes.ToolDefinition
func GetReadTextFileToolDefinition ¶
func GetReadTextFileToolDefinition() uctypes.ToolDefinition
func GetTermCommandOutputToolDefinition ¶
func GetTermCommandOutputToolDefinition(tabId string) uctypes.ToolDefinition
func GetTermGetScrollbackToolDefinition ¶
func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition
func GetTsunamiGetConfigToolDefinition ¶
func GetTsunamiGetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition
func GetTsunamiGetDataToolDefinition ¶
func GetTsunamiGetDataToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition
func GetTsunamiSetConfigToolDefinition ¶
func GetTsunamiSetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.ObjRTInfo, status *blockcontroller.BlockControllerRuntimeStatus) *uctypes.ToolDefinition
func GetWebNavigateToolDefinition ¶
func GetWebNavigateToolDefinition(tabId string) uctypes.ToolDefinition
func GetWriteTextFileToolDefinition ¶
func GetWriteTextFileToolDefinition() uctypes.ToolDefinition
func MakeBlockShortDesc ¶
func RegisterToolApproval ¶
func RegisterToolApproval(toolCallId string)
func ResolveToolCall ¶
func ResolveToolCall(toolDef *uctypes.ToolDefinition, toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpts) (result uctypes.AIToolResult)
func RunAIChat ¶
func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, chatOpts uctypes.WaveChatOpts) (*uctypes.AIMetrics, error)
func UpdateToolApproval ¶
func WaitForToolApproval ¶
func WaveAIGetChatHandler ¶
func WaveAIGetChatHandler(w http.ResponseWriter, r *http.Request)
func WaveAIPostMessageHandler ¶
func WaveAIPostMessageHandler(w http.ResponseWriter, r *http.Request)
func WaveAIPostMessageWrap ¶
func WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, message *uctypes.AIMessage, chatOpts uctypes.WaveChatOpts) error
Types ¶
type ApprovalRegistry ¶
type ApprovalRegistry struct {
// contains filtered or unexported fields
}
type ApprovalRequest ¶
type ApprovalRequest struct {
// contains filtered or unexported fields
}
type CommandInfo ¶
type PostMessageRequest ¶
type PostMessageRequest struct {
TabId string `json:"tabid,omitempty"`
BuilderId string `json:"builderid,omitempty"`
BuilderAppId string `json:"builderappid,omitempty"`
ChatID string `json:"chatid"`
Msg uctypes.AIMessage `json:"msg"`
WidgetAccess bool `json:"widgetaccess,omitempty"`
}
PostMessageRequest represents the request body for posting a message
type TermCommandOutputToolInput ¶
type TermCommandOutputToolInput struct {
WidgetId string `json:"widget_id"`
}
type TermGetScrollbackToolOutput ¶
type TermGetScrollbackToolOutput struct {
TotalLines int `json:"totallines"`
LineStart int `json:"linestart"`
LineEnd int `json:"lineend"`
ReturnedLines int `json:"returnedlines"`
Content string `json:"content"`
SinceLastOutputSec *int `json:"sincelastoutputsec,omitempty"`
HasMore bool `json:"hasmore"`
NextStart *int `json:"nextstart"`
LastCommand *CommandInfo `json:"lastcommand,omitempty"`
}
type WebNavigateToolInput ¶
type WebNavigateToolInput struct {
}