aiusechat

package
v0.12.0-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InitialApprovalTimeout = 10 * time.Second
	KeepAliveExtension     = 10 * time.Second
)
View Source
const (
	APIType_Anthropic = "anthropic"
	APIType_OpenAI    = "openai"
)
View Source
const DefaultAIEndpoint = "https://cfapi.waveterm.dev/api/waveai"
View Source
const DefaultAPI = APIType_OpenAI
View Source
const DefaultMaxTokens = 4 * 1024
View Source
const ReadDirDefaultMaxEntries = 500
View Source
const ReadDirHardMaxEntries = 10000
View Source
const ReadFileDefaultLineCount = 100
View Source
const ReadFileDefaultMaxBytes = 50 * 1024
View Source
const StopReasonMaxBytes = "max_bytes"

Variables

View Source
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).`,
}, " ")
View Source
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.`,

	`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 have NO API access to widgets or Wave unless provided via an explicit tool.`,
}, " ")

Functions

func CombineConsecutiveSameRoleMessages

func CombineConsecutiveSameRoleMessages(uiChat *uctypes.UIChat) *uctypes.UIChat

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

func ConvertAIChatToUIChat(aiChat *uctypes.AIChat) (*uctypes.UIChat, error)

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 CurrentToolApprovalStatus

func CurrentToolApprovalStatus(toolCallId string) string

func GenerateCurrentTabStatePrompt

func GenerateCurrentTabStatePrompt(blocks []*waveobj.Block, widgetAccess bool) string

func GenerateTabStateAndTools

func GenerateTabStateAndTools(ctx context.Context, tabid string, widgetAccess bool) (string, []uctypes.ToolDefinition, error)

func GetAdderToolDefinition

func GetAdderToolDefinition() uctypes.ToolDefinition

func GetCaptureScreenshotToolDefinition

func GetCaptureScreenshotToolDefinition(tabId string) uctypes.ToolDefinition

func GetChatUsage

func GetChatUsage(chat *uctypes.AIChat) uctypes.AIUsage

func GetGlobalRateLimit

func GetGlobalRateLimit() *uctypes.RateLimitInfo

func GetReadDirToolDefinition

func GetReadDirToolDefinition() uctypes.ToolDefinition

func GetReadTextFileToolDefinition

func GetReadTextFileToolDefinition() uctypes.ToolDefinition

func GetTermGetScrollbackToolDefinition

func GetTermGetScrollbackToolDefinition(tabId string) uctypes.ToolDefinition

func GetWebNavigateToolDefinition

func GetWebNavigateToolDefinition(tabId string) uctypes.ToolDefinition

func MakeBlockShortDesc

func MakeBlockShortDesc(block *waveobj.Block) string

func RegisterToolApproval

func RegisterToolApproval(toolCallId string)

func ResolveToolCall

func ResolveToolCall(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 UpdateToolApproval(toolCallId string, approval string, keepAlive bool) error

func WaitForToolApproval

func WaitForToolApproval(toolCallId string) string

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 DirEntryOut

type DirEntryOut struct {
	Name         string `json:"name"`
	Dir          bool   `json:"dir,omitempty"`
	Symlink      bool   `json:"symlink,omitempty"`
	Size         int64  `json:"size,omitempty"`
	Mode         string `json:"mode"`
	Modified     string `json:"modified"`
	ModifiedTime string `json:"modified_time"`
}

type PostMessageRequest

type PostMessageRequest struct {
	TabId        string            `json:"tabid"`
	ChatID       string            `json:"chatid"`
	Msg          uctypes.AIMessage `json:"msg"`
	WidgetAccess bool              `json:"widgetaccess,omitempty"`
}

PostMessageRequest represents the request body for posting a message

type TermGetScrollbackToolInput

type TermGetScrollbackToolInput struct {
	WidgetId  string `json:"widget_id"`
	LineStart int    `json:"line_start,omitempty"`
	Count     int    `json:"count,omitempty"`
}

type TermGetScrollbackToolOutput

type TermGetScrollbackToolOutput struct {
	TotalLines         int    `json:"total_lines"`
	LineStart          int    `json:"line_start"`
	LineEnd            int    `json:"line_end"`
	ReturnedLines      int    `json:"returned_lines"`
	Content            string `json:"content"`
	SinceLastOutputSec *int   `json:"since_last_output_sec,omitempty"`
	HasMore            bool   `json:"has_more"`
	NextStart          *int   `json:"next_start"`
}

type WebNavigateToolInput

type WebNavigateToolInput struct {
	WidgetId string `json:"widget_id"`
	Url      string `json:"url"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL