Files
cpa-plugin/internal/plugin/types.go
T

105 lines
2.3 KiB
Go

package plugin
import (
"encoding/json"
"net/http"
"time"
)
const (
ABIVersion uint32 = 1
SchemaVersion uint32 = 3
PluginName = "cpa-ext"
Version = "0.1.0-dev"
)
const (
MethodPluginRegister = "plugin.register"
MethodPluginReconfigure = "plugin.reconfigure"
MethodPluginShutdown = "plugin.shutdown"
MethodUsageHandle = "usage.handle"
)
type Envelope struct {
OK bool `json:"ok"`
Result json.RawMessage `json:"result,omitempty"`
Error *EnvelopeError `json:"error,omitempty"`
}
type EnvelopeError struct {
Code string `json:"code"`
Message string `json:"message"`
Retryable bool `json:"retryable,omitempty"`
HTTPStatus int `json:"http_status,omitempty"`
}
type LifecycleRequest struct {
ConfigYAML []byte `json:"config_yaml"`
SchemaVersion uint32 `json:"schema_version"`
}
type Registration struct {
SchemaVersion uint32 `json:"schema_version"`
Metadata Metadata `json:"metadata"`
Capabilities Capabilities `json:"capabilities"`
}
type Metadata struct {
Name string
Version string
Author string
GitHubRepository string
Logo string
ConfigFields []ConfigField
}
type ConfigField struct {
Name string
Type string
EnumValues []string
Description string
}
type Capabilities struct {
UsagePlugin bool `json:"usage_plugin"`
}
// UsageRecord mirrors CLIProxyAPI sdk/pluginapi. Keep it in sync with the
// target host because exported field names are part of the JSON wire contract.
type UsageRecord struct {
Provider string
ExecutorType string
Model string
Alias string
APIKey string
AuthID string
AuthIndex string
AuthType string
Source string
ReasoningEffort string
ServiceTier string
Generate bool
RequestedAt time.Time
Latency time.Duration
TTFT time.Duration
Failed bool
Failure UsageFailure
Detail UsageDetail
ResponseHeaders http.Header
}
type UsageFailure struct {
StatusCode int
Body string
}
type UsageDetail struct {
InputTokens int64
OutputTokens int64
ReasoningTokens int64
CachedTokens int64
CacheReadTokens int64
CacheCreationTokens int64
TotalTokens int64
}