Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentCapability ¶
AgentCapability describes a single capability
type AgentChatRequest ¶
type AgentChatRequest struct {
Message string `json:"message"`
SessionID string `json:"session_id"`
}
AgentChatRequest is the JSON body for POST /willknow/chat
type AgentChatResponse ¶
type AgentChatResponse struct {
Message string `json:"message"`
SessionID string `json:"session_id"`
}
AgentChatResponse is the JSON response for POST /willknow/chat
type AgentInfo ¶
type AgentInfo struct {
// Name is the agent's display name
// Default: OpenAPI spec's info.title
Name string
// Description describes what this agent can do
// Default: OpenAPI spec's info.description
Description string
}
AgentInfo holds identity information for the agent discovery endpoint
type AgentInfoAuth ¶
type AgentInfoAuth struct {
Required bool `json:"required"`
Type string `json:"type"` // "bearer", "none"
}
AgentInfoAuth describes authentication requirements
type AgentInfoResponse ¶
type AgentInfoResponse struct {
Name string `json:"name"`
Description string `json:"description"`
ChatEndpoint string `json:"chat_endpoint"`
Auth AgentInfoAuth `json:"authentication"`
Capabilities []AgentCapability `json:"capabilities"`
}
AgentInfoResponse is the JSON response for /willknow/info
type Assistant ¶
type Assistant struct {
// contains filtered or unexported fields
}
Assistant is the main AI assistant instance
type AuthConfig ¶
type AuthConfig struct {
// GetUser is called on every request to identify the current user.
// - Set to a custom function to integrate with your existing auth system.
// If the function returns an error, the request is rejected with 401.
// - Set to aiassistant.NoAuth to explicitly disable authentication.
// - Leave nil (default) to use built-in password protection.
GetUser GetUserFunc
// Password is used only in password protection mode (when GetUser is nil).
// If empty, willknow generates a random password and prints it to the console.
// If set, uses this password.
Password string
}
AuthConfig configures authentication for the AI assistant.
Three modes (in priority order):
- GetUser set to custom function → host system auth (highest priority)
- GetUser set to NoAuth → fully open, no authentication required
- GetUser not set (nil) → password protection mode (default)
type AuthManager ¶
type AuthManager struct {
// contains filtered or unexported fields
}
AuthManager handles authentication logic
type ChatMessage ¶
type ChatMessage struct {
Content string `json:"content"`
}
ChatMessage represents a chat message from the client
type ChatResponse ¶
type ChatResponse struct {
Type string `json:"type"` // "text", "error", "done", "session_info"
Content string `json:"content"` // text content
SessionID string `json:"sessionId,omitempty"` // session identifier
}
ChatResponse represents a response to the client
type Config ¶
type Config struct {
// SourcePath is the path to the application source code
// Default: /app/source
SourcePath string
// LogFiles are the paths to log files
// If empty, the assistant will try to auto-detect log files on startup
LogFiles []string
// Port is the port to run the web UI on
// Default: 8888
Port int
// Provider is the AI provider to use
// Supported: anthropic, openai, deepseek, qwen, moonshot, glm, xai, minimax, baichuan, 01ai, groq, together, siliconflow, custom
// Default: anthropic
Provider string
// APIKey is the API key for the provider
APIKey string
// Model is the model to use
// If empty, uses the provider's default model
Model string
// BaseURL is the custom API endpoint (for custom or self-hosted providers)
// If empty, uses the provider's default endpoint
// Required for Provider="custom"
BaseURL string
// Auth configures authentication for the AI assistant.
// See AuthConfig for details on the three supported modes.
Auth AuthConfig
// EnableCodeIndex enables built-in code indexing using LLM-generated summaries.
// When enabled, the assistant will scan source files at startup and build a searchable index.
// The index is cached to ./code_index.json with 24-hour TTL.
// Default: false (disabled)
EnableCodeIndex bool
// APISpec is the path to an OpenAPI spec file (YAML or JSON).
// When configured, the assistant automatically becomes an AI agent capable of calling
// the host system's APIs. This enables external AI systems to interact with the host
// through a single natural-language chat interface (/willknow/chat).
// Default: "" (disabled)
APISpec string
// HostBaseURL is the base URL for executing API calls when APISpec is configured.
// Defaults to the first server URL in the OpenAPI spec.
// Example: "http://localhost:8080"
HostBaseURL string
// AgentInfo describes this agent's identity for the /willknow/info discovery endpoint.
// Defaults to values from the OpenAPI spec's info section.
AgentInfo AgentInfo
}
Config holds the configuration for the AI Assistant
type GetUserFunc ¶
GetUserFunc is the function signature for custom user authentication. Provided by the host application to integrate with its existing auth system.
var NoAuth GetUserFunc = func(r *http.Request) (*User, error) { return &User{ID: "anonymous", Name: "Anonymous"}, nil }
NoAuth is a sentinel GetUserFunc that explicitly disables authentication. Use this when you want to allow unrestricted access to the assistant.
Example:
assistant, _ := aiassistant.New(aiassistant.Config{
Auth: aiassistant.AuthConfig{GetUser: aiassistant.NoAuth},
})