Documentation
¶
Overview ¶
Package client provides the authenticated REST/SSE Harbor Protocol client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidConnection reports an unusable base URL or token source. ErrInvalidConnection = errors.New("protocol client: invalid connection") // ErrTokenRequired reports that the token source returned an empty token. ErrTokenRequired = errors.New("protocol client: bearer token required") // ErrTokenIdentityMismatch reports that a token cannot authenticate the requested identity. ErrTokenIdentityMismatch = errors.New("protocol client: bearer token identity mismatch") // ErrIdentityRequired reports an incomplete client isolation identity. ErrIdentityRequired = errors.New("protocol client: complete identity required") // ErrResponseTooLarge reports a response beyond the configured safety bound. ErrResponseTooLarge = errors.New("protocol client: response body too large") // ErrMalformedResponse reports invalid or non-canonical response JSON. ErrMalformedResponse = errors.New("protocol client: malformed response") // ErrIncompatibleProtocol reports a Runtime with a different Protocol major. ErrIncompatibleProtocol = errors.New("protocol client: incompatible Protocol version") )
var ( // ErrMalformedSSE reports invalid framing or a non-JSON data payload. ErrMalformedSSE = errors.New("protocol client: malformed SSE frame") // ErrSSELineTooLarge reports an SSE field line beyond its safety bound. ErrSSELineTooLarge = errors.New("protocol client: SSE line too large") // ErrSSEFrameTooLarge reports an SSE frame beyond its safety bound. ErrSSEFrameTooLarge = errors.New("protocol client: SSE frame too large") // ErrStreamClosed reports Recv on an explicitly closed stream. ErrStreamClosed = errors.New("protocol client: event stream closed") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
RuntimeInfo(context.Context) (types.RuntimeInfo, error)
RuntimeHealth(context.Context) (types.RuntimeHealth, error)
Start(context.Context, types.StartRequest) (types.StartResponse, error)
TasksList(context.Context, types.TaskListRequest) (types.TaskListResponse, error)
TasksGet(context.Context, types.TaskGetRequest) (types.TaskDetail, error)
SessionsList(context.Context, types.SessionsListRequest) (types.SessionsListResponse, error)
SessionsInspect(context.Context, types.SessionsInspectRequest) (types.SessionsInspectResponse, error)
SessionsSetTitle(context.Context, types.SessionsSetTitleRequest) (types.SessionsSetTitleResponse, error)
SessionsDelete(context.Context) (types.SessionsDeleteResponse, error)
StateHistory(context.Context, types.StateHistoryRequest) (types.StateHistoryResponse, error)
PauseList(context.Context, types.PauseListRequest) (types.PauseListResponse, error)
Control(context.Context, methods.Method, types.ControlRequest) (types.ControlResponse, error)
ArtifactsPut(context.Context, types.ArtifactsPutRequest) (types.ArtifactsPutResponse, error)
ArtifactsList(context.Context, types.ArtifactsListRequest) (types.ArtifactsListResponse, error)
Subscribe(context.Context, StreamOptions) (*EventStream, error)
WithSession(string) Client
Identity() types.IdentityScope
}
Client is the supported immutable, concurrent-safe Protocol attachment.
func New ¶
func New(conn Connection, opts ...Option) (Client, error)
New constructs a Protocol client. An explicit identity is copied at the boundary and must be complete; it may be omitted when the verified JWT is the sole identity carrier. TokenSource receives the selected scope for every REST and SSE request.
type Connection ¶
type Connection struct {
BaseURL string
Token TokenSource
Identity types.IdentityScope
}
Connection describes one authenticated Runtime attachment.
type EventStream ¶
type EventStream struct {
// contains filtered or unexported fields
}
EventStream owns one HTTP response and reader goroutine. Close is idempotent, cancels the request, closes the body, and joins the reader.
func (*EventStream) Close ¶
func (s *EventStream) Close() error
Close cancels and joins the stream reader. It is safe to call repeatedly.
type Option ¶
type Option func(*config)
Option configures a Client at construction.
func WithHTTPClient ¶
WithHTTPClient supplies the HTTP client used for REST and SSE requests. A nil value is ignored.
func WithResponseLimits ¶
WithResponseLimits overrides the success and error body bounds. Non-positive values retain their defaults.
type ProtocolError ¶
type ProtocolError struct {
Status int
Code protoerrors.Code
Message string
Cause error
}
ProtocolError is a typed REST or pre-stream Protocol failure.
func (*ProtocolError) Unwrap ¶
func (e *ProtocolError) Unwrap() error
Unwrap returns the response decoding cause, when present.
type RuntimeClient ¶
type RuntimeClient interface {
Client
ArtifactsGetRef(context.Context, types.ArtifactsGetRefRequest) (types.ArtifactsGetRefResponse, error)
ArtifactsDelete(context.Context, types.ArtifactsDeleteRequest) (types.ArtifactsDeleteResponse, error)
ToolsList(context.Context, types.ToolListRequest) (types.ToolListResponse, error)
ToolsGet(context.Context, types.ToolGetRequest) (types.Tool, error)
ToolsDescribe(context.Context, types.ToolDescribeRequest) (types.ToolManifest, error)
ToolsMetrics(context.Context, types.ToolMetricsRequest) (types.ToolMetrics, error)
ToolsContentStats(context.Context, types.ToolContentStatsRequest) (types.ToolContentStats, error)
ToolsSetApprovalPolicy(context.Context, types.ToolSetApprovalPolicyRequest) (types.ToolSetApprovalPolicyResponse, error)
ToolsRevokeOAuth(context.Context, types.ToolRevokeOAuthRequest) (types.ToolRevokeOAuthResponse, error)
EventsList(context.Context, types.EventsListRequest) (types.EventsListResponse, error)
EventsAggregate(context.Context, types.EventAggregateRequest) (types.EventAggregateResponse, error)
RuntimeCounters(context.Context) (types.RuntimeCounters, error)
RuntimeDrivers(context.Context) (types.RuntimeDrivers, error)
MetricsSnapshot(context.Context) (types.MetricsSnapshot, error)
GovernancePosture(context.Context) (types.GovernancePostureResponse, error)
LLMPosture(context.Context) (types.LLMPostureResponse, error)
}
RuntimeClient is the additive Runtime inspection/control client consumed by the native TUI. Narrow projection consumers continue to depend on Client.
type SSEFrame ¶
type SSEFrame struct {
Event string
ID string
Data json.RawMessage
Comment string
Retry time.Duration
}
SSEFrame is one decoded Server-Sent Events frame. Data is retained as strict JSON so reducers can select their own canonical event payload projection.
type StreamOptions ¶
StreamOptions selects one identity-scoped event stream. Reconnect policy is caller-owned; LastEventID is the cursor supplied for this connection.
type TokenSource ¶
TokenSource resolves a bearer token for each requested identity. The scope is an isolated copy and may include the complete impersonation chain. Sources must be safe for concurrent use and must reject identities they cannot authenticate rather than returning a token for a different session.
func StaticToken ¶
func StaticToken(token string, principal types.IdentityScope) TokenSource
StaticToken returns a token source bound to principal. It rejects a regular session clone because one JWT cannot authenticate another session. For impersonation, principal is matched against Actor while the target may vary.
type TokenSourceFunc ¶
TokenSourceFunc adapts a function to TokenSource.
func (TokenSourceFunc) Token ¶
func (f TokenSourceFunc) Token(ctx context.Context, scope types.IdentityScope) (string, error)
Token calls f with an isolated identity copy.