Documentation
¶
Overview ¶
Package api implements AIScan's protocol-neutral Web management API.
Methods consume and return generated protobuf messages. Transport packages only adapt envelopes and error codes; Agent execution remains delegated to the existing AOP/AgentPool runtime.
Index ¶
- Constants
- Variables
- func BeginRequest(ctx context.Context, store RequestJournal, method, requestID string, ...) ([]byte, bool, bool, error)
- func BuildMarkdownReport(target, mode string, rawNodes []json.RawMessage, lang string) string
- func ConfigView(config *types.DistributeConfig, path string, loaded bool) *types.ConfigView
- func Errorf(code Code, format string, args ...any) error
- func FinishRequest(ctx context.Context, store RequestJournal, method, requestID string, ...) error
- func NewError(code Code, err error) error
- func ScanCompletedEvent(scanID string) *types.ScanEvent
- func ScanFailedEvent(scanID, message string, canceled bool) *types.ScanEvent
- func ScanProgressEvent(scanID, data string) *types.ScanEvent
- func ScanSnapshot(scan *types.Scan, sequence uint64) *types.ScanEvent
- func ScanStatusEvent(scanID string, status types.ScanStatus) *types.ScanEvent
- func ScanTerminal(status types.ScanStatus) bool
- func ServeApplication(connection ApplicationConnection, first *aop.Envelope, ...) error
- func ValidateLLMConfig(config *types.LLMConfig) error
- type API
- type AgentReader
- type ApplicationBackends
- type ApplicationConnection
- type ArtifactNormalizer
- type Code
- type CommandExecutor
- type Config
- func (c *Config) Activate(ctx context.Context, id string) (*types.ConfigView, error)
- func (c *Config) ActivateProfile(ctx context.Context, request *types.ActivateProfileRequest) (*types.ActivateProfileResponse, error)
- func (c *Config) Distribute(ctx context.Context) (*types.DistributeConfig, error)
- func (c *Config) GetConfig(ctx context.Context, _ *types.GetConfigRequest) (*types.GetConfigResponse, error)
- func (c *Config) ListModels(ctx context.Context, request *types.LLMProbeRequest) (*types.ListModelsResult, error)
- func (c *Config) Save(ctx context.Context, config *types.DistributeConfig) (*types.ConfigView, error)
- func (c *Config) TestConnection(ctx context.Context, request *types.TestConnectionRequest) (*types.TestConnectionResponse, error)
- func (c *Config) TestLLM(ctx context.Context, request *types.LLMProbeRequest) (*types.LLMProbeResult, error)
- func (c *Config) UpdateConfig(ctx context.Context, request *types.UpdateConfigRequest) (*types.UpdateConfigResponse, error)
- func (c *Config) View(ctx context.Context) (*types.ConfigView, error)
- type ConfigOptions
- type ConfigStore
- type Error
- type FileUploader
- type PTYRouter
- type PreparedConfig
- type RequestJournal
- type SCO
- func (s *SCO) DeleteNodes(ctx context.Context, request *types.DeleteNodesRequest) (*types.DeleteNodesResponse, error)
- func (s *SCO) GetNode(ctx context.Context, request *types.GetNodeRequest) (*types.GetNodeResponse, error)
- func (s *SCO) GetStats(ctx context.Context, _ *types.GetStatsRequest) (*types.GetStatsResponse, error)
- func (s *SCO) ImportNodes(ctx context.Context, request *types.ImportNodesRequest) (*types.ImportNodesResponse, error)
- func (s *SCO) ListArtifacts(context.Context, *types.ListArtifactsRequest) (*types.ListArtifactsResponse, error)
- func (s *SCO) ListNodes(ctx context.Context, request *types.ListNodesRequest) (*types.ListNodesResponse, error)
- type SCOStore
- type ScanBackend
- type ScanEvents
- type Scans
- func (s *Scans) CancelScan(ctx context.Context, request *types.CancelScanRequest) (*types.CancelScanResponse, error)
- func (s *Scans) GetScan(ctx context.Context, request *types.GetScanRequest) (*types.GetScanResponse, error)
- func (s *Scans) GetScanReport(ctx context.Context, request *types.GetScanReportRequest) (*types.GetScanReportResponse, error)
- func (s *Scans) ListScans(ctx context.Context, _ *types.ListScansRequest) (*types.ListScansResponse, error)
- func (s *Scans) SubmitScan(ctx context.Context, request *types.SubmitScanRequest) (*types.SubmitScanResponse, error)
- func (s *Scans) WatchScanEvents(request *types.WatchScanEventsRequest, ctx context.Context, ...) error
- type SessionRuntime
- type SessionStore
- type Sessions
- func (s *Sessions) CancelTurn(ctx context.Context, requestID string, request *aop.CancelTurnRequest) (*aop.CancelTurnResponse, error)
- func (s *Sessions) CloseSession(ctx context.Context, requestID string, request *aop.CloseSessionRequest) (*aop.CloseSessionResponse, error)
- func (s *Sessions) DeleteSession(ctx context.Context, request *types.DeleteSessionRequest) (*types.DeleteSessionResponse, error)
- func (s *Sessions) GetSession(ctx context.Context, request *types.GetSessionRequest) (*types.GetSessionResponse, error)
- func (s *Sessions) ListCommands(_ context.Context, request *types.ListCommandsRequest) (*types.ListCommandsResponse, error)
- func (s *Sessions) ListEvents(ctx context.Context, request *aop.ListEventsRequest) (*aop.ListEventsResponse, error)
- func (s *Sessions) ListSessions(ctx context.Context, request *types.ListSessionsRequest) (*types.ListSessionsResponse, error)
- func (s *Sessions) OpenSession(ctx context.Context, requestID string, request *aop.OpenSessionRequest) (*aop.OpenSessionResponse, error)
- func (s *Sessions) ResetSession(ctx context.Context, request *types.ResetSessionRequest) (*types.ResetSessionResponse, error)
- func (s *Sessions) RunTurn(ctx context.Context, requestID string, request *aop.RunTurnRequest) (*aop.RunTurnResponse, error)
- func (s *Sessions) WatchEvents(ctx context.Context, request *aop.WatchEventsRequest, ...) error
- type StatusReader
Constants ¶
const ( SessionStateOpen = "open" SessionStateClosed = "closed" )
const DefaultReportLang = "zh"
Variables ¶
var ( ErrScanNotFound = errors.New("scan not found") ErrScanNotCancelable = errors.New("scan cannot be canceled") )
var ErrTurnNotFound = errors.New("turn not found")
Functions ¶
func BeginRequest ¶
func BuildMarkdownReport ¶
func BuildMarkdownReport(target, mode string, rawNodes []json.RawMessage, lang string) string
func ConfigView ¶
func ConfigView(config *types.DistributeConfig, path string, loaded bool) *types.ConfigView
func FinishRequest ¶
func ScanCompletedEvent ¶
func ScanProgressEvent ¶
func ScanStatusEvent ¶
func ScanStatusEvent(scanID string, status types.ScanStatus) *types.ScanEvent
func ScanTerminal ¶
func ScanTerminal(status types.ScanStatus) bool
func ServeApplication ¶
func ServeApplication(connection ApplicationConnection, first *aop.Envelope, backends *ApplicationBackends) error
ServeApplication serves one application connection over the AOP envelope surface. Connection owns stream concurrency; this function owns only the application business routes and connection-local subscriptions.
func ValidateLLMConfig ¶
Types ¶
type API ¶
type API struct {
Sessions *Sessions
Config *Config
Scans *Scans
SCO *SCO
Agents AgentReader
Status StatusReader
ServerURL string
}
func (*API) GetStatus ¶
func (a *API) GetStatus(*types.GetStatusRequest) *types.GetStatusResponse
func (*API) ListAgents ¶
func (a *API) ListAgents(*types.ListAgentsRequest) *types.ListAgentsResponse
type AgentReader ¶
type ApplicationBackends ¶
type ApplicationBackends struct {
Sessions *Sessions
Scans *Scans
Commands CommandExecutor
Files FileUploader
PTY PTYRouter
NewID func() string
}
ApplicationBackends wires the application envelope business surface to its owning mechanisms.
type ApplicationConnection ¶
type ApplicationConnection interface {
Context() context.Context
Send(*aop.Envelope) error
Run(*aop.Envelope, func(context.Context, *aop.Envelope, aop.SendFunc) error) error
}
ApplicationConnection is the minimal mechanism surface required by the application business dispatcher. pkg/web owns the concrete Connection.
type ArtifactNormalizer ¶
type CommandExecutor ¶
CommandExecutor runs "/" commands inside a chat session.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func NewConfig ¶
func NewConfig(options ConfigOptions) *Config
func (*Config) ActivateProfile ¶
func (c *Config) ActivateProfile(ctx context.Context, request *types.ActivateProfileRequest) (*types.ActivateProfileResponse, error)
func (*Config) Distribute ¶
func (*Config) GetConfig ¶
func (c *Config) GetConfig(ctx context.Context, _ *types.GetConfigRequest) (*types.GetConfigResponse, error)
func (*Config) ListModels ¶
func (c *Config) ListModels(ctx context.Context, request *types.LLMProbeRequest) (*types.ListModelsResult, error)
func (*Config) Save ¶
func (c *Config) Save(ctx context.Context, config *types.DistributeConfig) (*types.ConfigView, error)
func (*Config) TestConnection ¶
func (c *Config) TestConnection(ctx context.Context, request *types.TestConnectionRequest) (*types.TestConnectionResponse, error)
func (*Config) TestLLM ¶
func (c *Config) TestLLM(ctx context.Context, request *types.LLMProbeRequest) (*types.LLMProbeResult, error)
func (*Config) UpdateConfig ¶
func (c *Config) UpdateConfig(ctx context.Context, request *types.UpdateConfigRequest) (*types.UpdateConfigResponse, error)
type ConfigOptions ¶
type ConfigOptions struct {
Store ConfigStore
Build func(context.Context, *PreparedConfig) (*runner.App, error)
Apply func(*runner.App)
Broadcast func(*types.DistributeConfig)
}
type ConfigStore ¶
type ConfigStore interface {
GetDistributeConfig(context.Context) (string, bool, *types.DistributeConfig, error)
PrepareDistributeConfig(context.Context, *types.DistributeConfig) (*PreparedConfig, error)
CommitDistributeConfig(context.Context, *PreparedConfig) error
DiscardDistributeConfig(*PreparedConfig)
}
type FileUploader ¶
type FileUploader interface {
Upload(ctx context.Context, sessionID, filename string, data []byte) (*filepb.Result, error)
}
FileUploader stores an application-uploaded file through the owning agent.
type PTYRouter ¶
type PTYRouter interface {
SubscribePTY(nodeID, streamID string) (<-chan *ptypb.ProtocolMessage, bool, func())
ForwardPTY(nodeID string, message *ptypb.ProtocolMessage) error
ClosePTY(nodeID, streamID string)
}
PTYRouter bridges application PTY messages to the agent owning the terminal. It speaks generated protobuf only; frame conversion belongs to the mechanism layer implementing this interface.
type PreparedConfig ¶
type PreparedConfig struct {
Config *types.DistributeConfig
RuntimePath string
TargetPath string
}
type RequestJournal ¶
type SCO ¶
type SCO struct {
// contains filtered or unexported fields
}
func NewSCO ¶
func NewSCO(store SCOStore, normalizers ...ArtifactNormalizer) *SCO
func (*SCO) DeleteNodes ¶
func (s *SCO) DeleteNodes(ctx context.Context, request *types.DeleteNodesRequest) (*types.DeleteNodesResponse, error)
func (*SCO) GetNode ¶
func (s *SCO) GetNode(ctx context.Context, request *types.GetNodeRequest) (*types.GetNodeResponse, error)
func (*SCO) GetStats ¶
func (s *SCO) GetStats(ctx context.Context, _ *types.GetStatsRequest) (*types.GetStatsResponse, error)
func (*SCO) ImportNodes ¶
func (s *SCO) ImportNodes(ctx context.Context, request *types.ImportNodesRequest) (*types.ImportNodesResponse, error)
func (*SCO) ListArtifacts ¶
func (s *SCO) ListArtifacts(context.Context, *types.ListArtifactsRequest) (*types.ListArtifactsResponse, error)
func (*SCO) ListNodes ¶
func (s *SCO) ListNodes(ctx context.Context, request *types.ListNodesRequest) (*types.ListNodesResponse, error)
type SCOStore ¶
type SCOStore interface {
ListSCONodesByScanID(context.Context, string, string, int) ([]json.RawMessage, error)
GetSCONode(context.Context, string) (json.RawMessage, error)
SCONodeStats(context.Context) (map[string]int, error)
DeleteSCONodesByScan(context.Context, string) error
UpsertSCONodes(context.Context, string, []json.RawMessage) error
}
type ScanBackend ¶
type ScanBackend interface {
SubmitScan(context.Context, string, string, bool, bool, bool) (*types.Scan, error)
GetScan(context.Context, string) (*types.Scan, error)
ListScans(context.Context) ([]*types.Scan, error)
CancelScan(string) error
GetReport(context.Context, string, string) (string, error)
}
type ScanEvents ¶
type Scans ¶
type Scans struct {
// contains filtered or unexported fields
}
func NewScans ¶
func NewScans(backend ScanBackend, events ScanEvents) *Scans
func (*Scans) CancelScan ¶
func (s *Scans) CancelScan(ctx context.Context, request *types.CancelScanRequest) (*types.CancelScanResponse, error)
func (*Scans) GetScan ¶
func (s *Scans) GetScan(ctx context.Context, request *types.GetScanRequest) (*types.GetScanResponse, error)
func (*Scans) GetScanReport ¶
func (s *Scans) GetScanReport(ctx context.Context, request *types.GetScanReportRequest) (*types.GetScanReportResponse, error)
func (*Scans) ListScans ¶
func (s *Scans) ListScans(ctx context.Context, _ *types.ListScansRequest) (*types.ListScansResponse, error)
func (*Scans) SubmitScan ¶
func (s *Scans) SubmitScan(ctx context.Context, request *types.SubmitScanRequest) (*types.SubmitScanResponse, error)
type SessionRuntime ¶
type SessionRuntime interface {
AgentInfo(string) (string, bool)
GetScan(context.Context, string) (*types.Scan, error)
OpenAgentSession(context.Context, string, *aop.OpenSessionRequest) error
CloseAgentSession(context.Context, string, string, *aop.CloseSessionRequest) (bool, error)
StartAgentTurn(string, *aop.RunTurnRequest)
CancelTurn(context.Context, string, string) error
PublishUserMessage(string, string, *aop.Message)
BroadcastAOPEvent(string, *aop.Event)
SubscribeSessionEvents(string) (<-chan *aop.EventDelivery, func())
DeleteSession(context.Context, string) error
SessionMenu(string) []*types.CommandSpec
}
SessionRuntime is the Agent/AOP execution boundary. Sessions owns request semantics and persistence; the runtime only performs Agent dispatch and live event delivery.
type SessionStore ¶
type SessionStore interface {
RequestJournal
ListSessionPage(context.Context, int, int, bool) ([]*types.SessionRecord, bool, error)
GetSession(context.Context, string) (*types.SessionRecord, error)
CreateSession(context.Context, *types.SessionRecord) error
UpdateSession(context.Context, *types.SessionRecord) error
DeleteSession(context.Context, string) error
LinkScanToSession(context.Context, string, string) error
ListAOPEventsAfter(context.Context, string, int64, int) ([]*aop.EventDelivery, error)
}
type Sessions ¶
type Sessions struct {
// contains filtered or unexported fields
}
func NewSessions ¶
func NewSessions(store SessionStore, runtime SessionRuntime, newID func() string) *Sessions
func (*Sessions) CancelTurn ¶
func (s *Sessions) CancelTurn(ctx context.Context, requestID string, request *aop.CancelTurnRequest) (*aop.CancelTurnResponse, error)
func (*Sessions) CloseSession ¶
func (s *Sessions) CloseSession(ctx context.Context, requestID string, request *aop.CloseSessionRequest) (*aop.CloseSessionResponse, error)
func (*Sessions) DeleteSession ¶
func (s *Sessions) DeleteSession(ctx context.Context, request *types.DeleteSessionRequest) (*types.DeleteSessionResponse, error)
func (*Sessions) GetSession ¶
func (s *Sessions) GetSession(ctx context.Context, request *types.GetSessionRequest) (*types.GetSessionResponse, error)
func (*Sessions) ListCommands ¶
func (s *Sessions) ListCommands(_ context.Context, request *types.ListCommandsRequest) (*types.ListCommandsResponse, error)
func (*Sessions) ListEvents ¶
func (s *Sessions) ListEvents(ctx context.Context, request *aop.ListEventsRequest) (*aop.ListEventsResponse, error)
func (*Sessions) ListSessions ¶
func (s *Sessions) ListSessions(ctx context.Context, request *types.ListSessionsRequest) (*types.ListSessionsResponse, error)
func (*Sessions) OpenSession ¶
func (s *Sessions) OpenSession(ctx context.Context, requestID string, request *aop.OpenSessionRequest) (*aop.OpenSessionResponse, error)
func (*Sessions) ResetSession ¶
func (s *Sessions) ResetSession(ctx context.Context, request *types.ResetSessionRequest) (*types.ResetSessionResponse, error)
func (*Sessions) RunTurn ¶
func (s *Sessions) RunTurn(ctx context.Context, requestID string, request *aop.RunTurnRequest) (*aop.RunTurnResponse, error)
func (*Sessions) WatchEvents ¶
func (s *Sessions) WatchEvents(ctx context.Context, request *aop.WatchEventsRequest, send func(*aop.EventDelivery) error) error
type StatusReader ¶
type StatusReader interface {
Status() *types.SystemStatus
}