uctypes

package
v0.13.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIType_AnthropicMessages = "anthropic-messages"
	APIType_OpenAIResponses   = "openai-responses"
	APIType_OpenAIChat        = "openai-chat"
	APIType_GoogleGemini      = "google-gemini"
)
View Source
const (
	AIProvider_Wave        = "wave"
	AIProvider_Google      = "google"
	AIProvider_OpenRouter  = "openrouter"
	AIProvider_OpenAI      = "openai"
	AIProvider_Azure       = "azure"
	AIProvider_AzureLegacy = "azure-legacy"
	AIProvider_Custom      = "custom"
)
View Source
const (
	ThinkingLevelLow    = "low"
	ThinkingLevelMedium = "medium"
	ThinkingLevelHigh   = "high"
)
View Source
const (
	AIModeQuick    = "waveai@quick"
	AIModeBalanced = "waveai@balanced"
	AIModeDeep     = "waveai@deep"
)
View Source
const (
	ToolUseStatusPending   = "pending"
	ToolUseStatusError     = "error"
	ToolUseStatusCompleted = "completed"
)
View Source
const (
	AICapabilityTools  = "tools"
	AICapabilityImages = "images"
	AICapabilityPdfs   = "pdfs"
)
View Source
const (
	ApprovalNeedsApproval = "needs-approval"
	ApprovalUserApproved  = "user-approved"
	ApprovalUserDenied    = "user-denied"
	ApprovalTimeout       = "timeout"
	ApprovalAutoApproved  = "auto-approved"
)
View Source
const (
	AIMessagePartTypeText = "text"
	AIMessagePartTypeFile = "file"
)
View Source
const DefaultAIEndpoint = "https://cfapi.waveterm.dev/api/waveai"
View Source
const DefaultAnthropicModel = "claude-sonnet-4-5"
View Source
const DefaultOpenAIEndpoint = "https://api.openai.com/v1"
View Source
const DefaultOpenAIModel = "gpt-5-mini"
View Source
const DefaultOpenRouterEndpoint = "https://openrouter.ai/api/v1"
View Source
const PremiumOpenAIModel = "gpt-5.1"
View Source
const WaveAIEndpointEnvName = "WAVETERM_WAVEAI_ENDPOINT"

Variables

This section is empty.

Functions

func AreModelsCompatible

func AreModelsCompatible(apiType, model1, model2 string) bool

Types

type AIChat

type AIChat struct {
	ChatId         string         `json:"chatid"`
	APIType        string         `json:"apitype"`
	Model          string         `json:"model"`
	APIVersion     string         `json:"apiversion"`
	NativeMessages []GenAIMessage `json:"nativemessages"`
}

type AIFunctionCallInput added in v0.12.4

type AIFunctionCallInput struct {
	CallId      string                `json:"call_id"`
	Name        string                `json:"name"`
	Arguments   string                `json:"arguments"`
	ToolUseData *UIMessageDataToolUse `json:"toolusedata,omitempty"`
}

type AIMessage

type AIMessage struct {
	MessageId string          `json:"messageid"` // only for idempotency
	Parts     []AIMessagePart `json:"parts"`
}

wave specific for POSTing a new message to a convo

func (*AIMessage) GetMessageId

func (m *AIMessage) GetMessageId() string

func (*AIMessage) Validate

func (m *AIMessage) Validate() error

type AIMessagePart

type AIMessagePart struct {
	Type string `json:"type"` // "text", "file"

	// for "text"
	Text string `json:"text,omitempty"`

	// for "file"
	// mimetype is required, filename is not
	// either data or url (not both) must be set
	// url must be either an "https" or "data" url
	FileName   string `json:"filename,omitempty"`
	MimeType   string `json:"mimetype,omitempty"` // required
	Data       []byte `json:"data,omitempty"`     // raw data (base64 on wire)
	URL        string `json:"url,omitempty"`
	Size       int    `json:"size,omitempty"`
	PreviewUrl string `json:"previewurl,omitempty"` // 128x128 webp data url for images
}

func (*AIMessagePart) Validate

func (p *AIMessagePart) Validate() error

type AIMetrics

type AIMetrics struct {
	ChatId            string         `json:"chatid"`
	StepNum           int            `json:"stepnum"`
	Usage             AIUsage        `json:"usage"`
	RequestCount      int            `json:"requestcount"`
	ToolUseCount      int            `json:"toolusecount"`
	ToolUseErrorCount int            `json:"tooluseerrorcount"`
	ToolDetail        map[string]int `json:"tooldetail,omitempty"`
	PremiumReqCount   int            `json:"premiumreqcount"`
	ProxyReqCount     int            `json:"proxyreqcount"`
	HadError          bool           `json:"haderror"`
	ImageCount        int            `json:"imagecount"`
	PDFCount          int            `json:"pdfcount"`
	TextDocCount      int            `json:"textdoccount"`
	TextLen           int            `json:"textlen"`
	FirstByteLatency  int            `json:"firstbytelatency"` // ms
	RequestDuration   int            `json:"requestduration"`  // ms
	WidgetAccess      bool           `json:"widgetaccess"`
	ThinkingLevel     string         `json:"thinkinglevel,omitempty"`
	AIMode            string         `json:"aimode,omitempty"`
}

type AIModeConfig

type AIModeConfig struct {
	Mode               string   `json:"mode"`
	DisplayName        string   `json:"display:name"`
	DisplayOrder       float64  `json:"display:order,omitempty"`
	DisplayIcon        string   `json:"display:icon"`
	Provider           string   `json:"provider,omitempty"`
	APIType            string   `json:"apitype"`
	Model              string   `json:"model"`
	ThinkingLevel      string   `json:"thinkinglevel"`
	BaseURL            string   `json:"baseurl,omitempty"`
	WaveAICloud        bool     `json:"waveaicloud,omitempty"`
	APIVersion         string   `json:"apiversion,omitempty"`
	APIToken           string   `json:"apitoken,omitempty"`
	APITokenSecretName string   `json:"apitokensecretname,omitempty"`
	Premium            bool     `json:"premium"`
	Description        string   `json:"description"`
	Capabilities       []string `json:"capabilities,omitempty"`
}

func (*AIModeConfig) HasCapability

func (c *AIModeConfig) HasCapability(cap string) bool

type AIOptsType

type AIOptsType struct {
	Provider      string   `json:"provider,omitempty"`
	APIType       string   `json:"apitype,omitempty"`
	Model         string   `json:"model"`
	APIToken      string   `json:"apitoken"`
	APIVersion    string   `json:"apiversion,omitempty"`
	Endpoint      string   `json:"endpoint,omitempty"`
	ProxyURL      string   `json:"proxyurl,omitempty"`
	MaxTokens     int      `json:"maxtokens,omitempty"`
	TimeoutMs     int      `json:"timeoutms,omitempty"`
	ThinkingLevel string   `json:"thinkinglevel,omitempty"` // ThinkingLevelLow, ThinkingLevelMedium, or ThinkingLevelHigh
	AIMode        string   `json:"aimode,omitempty"`
	Capabilities  []string `json:"capabilities,omitempty"`
	WaveAIPremium bool     `json:"waveaipremium,omitempty"`
}

Wave Specific AI opts for configuration

func (AIOptsType) HasCapability

func (opts AIOptsType) HasCapability(cap string) bool

func (AIOptsType) IsPremiumModel

func (opts AIOptsType) IsPremiumModel() bool

func (AIOptsType) IsWaveProxy

func (opts AIOptsType) IsWaveProxy() bool

type AIToolResult

type AIToolResult struct {
	ToolName  string `json:"toolname"`
	ToolUseID string `json:"tooluseid"`
	ErrorText string `json:"errortext,omitempty"`
	Text      string `json:"text,omitempty"`
}

type AIUsage

type AIUsage struct {
	APIType              string `json:"apitype"`
	Model                string `json:"model"`
	InputTokens          int    `json:"inputtokens,omitempty"`
	OutputTokens         int    `json:"outputtokens,omitempty"`
	NativeWebSearchCount int    `json:"nativewebsearchcount,omitempty"`
}

type GenAIMessage

type GenAIMessage interface {
	GetMessageId() string
	GetUsage() *AIUsage
	GetRole() string
}

GenAIMessage interface for messages stored in conversations All messages must have a unique identifier for idempotency checks

type ProxyErrorResponse

type ProxyErrorResponse struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
}

type RateLimitInfo

type RateLimitInfo struct {
	Req        int   `json:"req"`
	ReqLimit   int   `json:"reqlimit"`
	PReq       int   `json:"preq"`
	PReqLimit  int   `json:"preqlimit"`
	ResetEpoch int64 `json:"resetepoch"`
	Unknown    bool  `json:"unknown,omitempty"`
}

func ParseRateLimitHeader

func ParseRateLimitHeader(header string) *RateLimitInfo

ParseRateLimitHeader parses the X-Wave-RateLimit header Format: X-Wave-RateLimit: req=<remaining>, reqlimit=<max_requests>, preq=<premium_remaining>, preqlimit=<max_premium>, reset=<expiration_epoch_seconds> Example: X-Wave-RateLimit: req=180, reqlimit=200, preq=45, preqlimit=50, reset=1727818382 - req: remaining regular requests in the current window - reqlimit: maximum regular requests allowed in the window - preq: remaining premium requests in the current window - preqlimit: maximum premium requests allowed in the window - reset: unix timestamp (epoch seconds) when the rate limit window resets

type StopReasonKind

type StopReasonKind string
const (
	StopKindDone             StopReasonKind = "done"
	StopKindToolUse          StopReasonKind = "tool_use"
	StopKindMaxTokens        StopReasonKind = "max_tokens"
	StopKindContent          StopReasonKind = "content_filter"
	StopKindCanceled         StopReasonKind = "canceled"
	StopKindError            StopReasonKind = "error"
	StopKindPauseTurn        StopReasonKind = "pause_turn"
	StopKindPremiumRateLimit StopReasonKind = "premium_rate_limit"
	StopKindRateLimit        StopReasonKind = "rate_limit"
)

type ToolDefinition

type ToolDefinition struct {
	Name                 string         `json:"name"`
	DisplayName          string         `json:"displayname,omitempty"` // internal field (cannot marshal to API, must be stripped)
	Description          string         `json:"description"`
	ShortDescription     string         `json:"shortdescription,omitempty"` // internal field (cannot marshal to API, must be stripped)
	ToolLogName          string         `json:"-"`                          // short name for telemetry (e.g., "term:getscrollback")
	InputSchema          map[string]any `json:"input_schema"`
	Strict               bool           `json:"strict,omitempty"`
	RequiredCapabilities []string       `json:"requiredcapabilities,omitempty"`

	ToolTextCallback func(any) (string, error)                     `json:"-"`
	ToolAnyCallback  func(any, *UIMessageDataToolUse) (any, error) `json:"-"` // *UIMessageDataToolUse will NOT be nil
	ToolCallDesc     func(any, any, *UIMessageDataToolUse) string  `json:"-"` // passed input, output (may be nil), *UIMessageDataToolUse (may be nil)
	ToolApproval     func(any) string                              `json:"-"`
	ToolVerifyInput  func(any, *UIMessageDataToolUse) error        `json:"-"` // *UIMessageDataToolUse will NOT be nil
	ToolProgressDesc func(any) ([]string, error)                   `json:"-"`
}

ToolDefinition represents a tool that can be used by the AI model

func (*ToolDefinition) Clean

func (td *ToolDefinition) Clean() *ToolDefinition

func (*ToolDefinition) Desc

func (td *ToolDefinition) Desc() string

func (*ToolDefinition) HasRequiredCapabilities

func (td *ToolDefinition) HasRequiredCapabilities(capabilities []string) bool

type UIChat

type UIChat struct {
	ChatId     string      `json:"chatid"`
	APIType    string      `json:"apitype"`
	Model      string      `json:"model"`
	APIVersion string      `json:"apiversion"`
	Messages   []UIMessage `json:"messages"`
}

type UIMessage

type UIMessage struct {
	ID       string          `json:"id"`
	Role     string          `json:"role"` // "system", "user", "assistant"
	Metadata any             `json:"metadata,omitempty"`
	Parts    []UIMessagePart `json:"parts,omitempty"`
}

func (*UIMessage) GetContent

func (m *UIMessage) GetContent() string

GetContent extracts the text content from the parts array

type UIMessageDataToolProgress added in v0.12.3

type UIMessageDataToolProgress struct {
	ToolCallId  string   `json:"toolcallid"`
	ToolName    string   `json:"toolname"`
	StatusLines []string `json:"statuslines"`
}

when updating this struct, also modify frontend/app/aipanel/aitypes.ts WaveUIDataTypes.toolprogress

type UIMessageDataToolUse

type UIMessageDataToolUse struct {
	ToolCallId          string `json:"toolcallid"`
	ToolName            string `json:"toolname"`
	ToolDesc            string `json:"tooldesc"`
	Status              string `json:"status"`
	RunTs               int64  `json:"runts,omitempty"`
	ErrorMessage        string `json:"errormessage,omitempty"`
	Approval            string `json:"approval,omitempty"`
	BlockId             string `json:"blockid,omitempty"`
	WriteBackupFileName string `json:"writebackupfilename,omitempty"`
	InputFileName       string `json:"inputfilename,omitempty"`
}

when updating this struct, also modify frontend/app/aipanel/aitypes.ts WaveUIDataTypes.tooluse

func (*UIMessageDataToolUse) IsApproved

func (d *UIMessageDataToolUse) IsApproved() bool

type UIMessageDataUserFile

type UIMessageDataUserFile struct {
	FileName   string `json:"filename,omitempty"`
	Size       int    `json:"size,omitempty"`
	MimeType   string `json:"mimetype,omitempty"`
	PreviewUrl string `json:"previewurl,omitempty"`
}

when updating this struct, also modify frontend/app/aipanel/aitypes.ts WaveUIDataTypes.userfile

type UIMessagePart

type UIMessagePart struct {
	// text, reasoning, tool-[toolname], source-url, source-document, file, data-[dataname], step-start
	Type string `json:"type"`

	// TextUIPart & ReasoningUIPart
	Text string `json:"text,omitempty"`
	// State field:
	// - For "text"/"reasoning" types: optional, values are "streaming" or "done"
	// - For "tool-*" types: required, values are "input-streaming", "input-available", "output-available", or "output-error"
	State string `json:"state,omitempty"`

	// ToolUIPart
	ToolCallID       string `json:"toolCallId,omitempty"`
	Input            any    `json:"input,omitempty"`
	Output           any    `json:"output,omitempty"`
	ErrorText        string `json:"errorText,omitempty"`
	ProviderExecuted *bool  `json:"providerExecuted,omitempty"`

	// SourceUrlUIPart & SourceDocumentUIPart
	SourceID  string `json:"sourceId,omitempty"`
	URL       string `json:"url,omitempty"`
	Title     string `json:"title,omitempty"`
	Filename  string `json:"filename,omitempty"`
	MediaType string `json:"mediaType,omitempty"`

	// DataUIPart
	ID   string `json:"id,omitempty"`
	Data any    `json:"data,omitempty"`

	// Provider metadata (ReasoningUIPart, SourceUrlUIPart, SourceDocumentUIPart)
	ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}

type UseChatRequest

type UseChatRequest struct {
	Messages []UIMessage `json:"messages"`
}

type UseChatStreamPart

type UseChatStreamPart struct {
	Type string `json:"type"`

	// Text
	Text string `json:"text,omitempty"`

	// Reasoning
	Delta string `json:"delta,omitempty"`

	// Source parts
	SourceID  string `json:"sourceId,omitempty"`
	URL       string `json:"url,omitempty"`       // also for file urls
	MediaType string `json:"mediaType,omitempty"` // also for file types
	Title     string `json:"title,omitempty"`

	// Data (custom data-\*)
	Data any `json:"data,omitempty"`

	// Tool use / tool result
	ToolCallID     string `json:"toolCallId,omitempty"`
	ToolName       string `json:"toolName,omitempty"`
	Input          any    `json:"input,omitempty"`
	Output         any    `json:"output,omitempty"`
	InputTextDelta string `json:"inputTextDelta,omitempty"`

	// Control parts (start/finish steps, errors, etc.)
	ErrorText string `json:"errorText,omitempty"`
}

Type can be one of these consts... text-start, text-delta, text-end, reasoning-start, reasoning-delta, reasoning-end, source-url, source-document, file, data-*, tool-input-start, tool-input-delta, tool-input-available, tool-output-available, error, start-step, finish-step, finish

type WaveChatOpts

type WaveChatOpts struct {
	ChatId               string
	ClientId             string
	Config               AIOptsType
	Tools                []ToolDefinition
	SystemPrompt         []string
	TabStateGenerator    func() (string, []ToolDefinition, string, error)
	BuilderAppGenerator  func() (string, string, string, error)
	WidgetAccess         bool
	RegisterToolApproval func(string)
	AllowNativeWebSearch bool
	BuilderId            string
	BuilderAppId         string

	// ephemeral to the step
	TabState       string
	TabTools       []ToolDefinition
	TabId          string
	AppGoFile      string
	AppStaticFiles string
	PlatformInfo   string
}

func (*WaveChatOpts) GetToolDefinition

func (opts *WaveChatOpts) GetToolDefinition(toolName string) *ToolDefinition

func (*WaveChatOpts) GetWaveRequestType added in v0.12.4

func (opts *WaveChatOpts) GetWaveRequestType() string

type WaveContinueResponse

type WaveContinueResponse struct {
	Model            string         `json:"model,omitempty"`
	ContinueFromKind StopReasonKind `json:"continue_from_kind"`
}

Wave Specific parameter used to signal to our step function that this is a continuation step, not an initial step

type WaveStopReason

type WaveStopReason struct {
	Kind      StopReasonKind `json:"kind"`
	RawReason string         `json:"raw_reason,omitempty"`
	ToolCalls []WaveToolCall `json:"tool_calls,omitempty"`
	ErrorType string         `json:"error_type,omitempty"`
	ErrorText string         `json:"error_text,omitempty"`
}

type WaveToolCall

type WaveToolCall struct {
	ID          string                `json:"id"`                    // Anthropic tool_use.id
	Name        string                `json:"name,omitempty"`        // tool name (if provided)
	Input       any                   `json:"input,omitempty"`       // accumulated input JSON
	ToolUseData *UIMessageDataToolUse `json:"toolusedata,omitempty"` // UI tool use data
}

Jump to

Keyboard shortcuts

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