Documentation
¶
Overview ¶
Package oai provides ChatGPT OAuth-backed OpenAI clients for rocketclaw.
Index ¶
- func AuthFilePathIn(workspace, runtimeDir string) (string, error)
- func HasTokenIn(workspace, runtimeDir, provider string) (bool, error)
- func NewChatGPTClientIn(workspace, runtimeDir, provider string, logger *slog.Logger, ...) (*openai.Client, error)
- func RemoveTokenIn(workspace, runtimeDir, provider string) error
- func SaveTokenIn(workspace, runtimeDir, provider string, token Token) error
- func WithResponseObserver(ctx context.Context, observer ResponseObserver) context.Context
- type InertResponseObserver
- type MissingTokenError
- type ResponseObserver
- type Token
- func AcquireBrowserToken(ctx context.Context, out io.Writer) (Token, error)
- func AcquireDeviceToken(ctx context.Context, out io.Writer) (Token, error)
- func FreshTokenIn(ctx context.Context, workspace, runtimeDir, provider string, rejected Token) (Token, error)
- func LoadTokenIn(workspace, runtimeDir, provider string) (Token, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthFilePathIn ¶
AuthFilePathIn returns the workspace-local token file path in runtimeDir.
func HasTokenIn ¶ added in v0.0.42
HasTokenIn reports whether the provider has a persisted ChatGPT OAuth token.
func NewChatGPTClientIn ¶
func NewChatGPTClientIn(workspace, runtimeDir, provider string, logger *slog.Logger, opts ...option.RequestOption) (*openai.Client, error)
NewChatGPTClientIn creates an OpenAI client that sends Responses API requests to ChatGPT Codex using runtimeDir auth.
func RemoveTokenIn ¶ added in v0.0.42
RemoveTokenIn removes only the provider's persisted ChatGPT OAuth token.
func SaveTokenIn ¶
SaveTokenIn writes the provider's ChatGPT OAuth token.
func WithResponseObserver ¶ added in v0.2.32
func WithResponseObserver(ctx context.Context, observer ResponseObserver) context.Context
WithResponseObserver returns ctx carrying observer, which sees the responses of requests made with it.
Types ¶
type InertResponseObserver ¶ added in v0.2.33
type InertResponseObserver struct{}
InertResponseObserver ignores response streaming notifications.
func (InertResponseObserver) BeginResponse ¶ added in v0.2.33
func (InertResponseObserver) BeginResponse(context.Context) error
BeginResponse does nothing.
func (InertResponseObserver) ObserveResponse ¶ added in v0.2.33
func (InertResponseObserver) ObserveResponse(context.Context, *responses.ResponseStreamEventUnion) error
ObserveResponse does nothing.
type MissingTokenError ¶ added in v0.1.30
type MissingTokenError struct {
Provider string
}
MissingTokenError reports that no ChatGPT OAuth token is stored for Provider.
func (*MissingTokenError) Error ¶ added in v0.1.30
func (e *MissingTokenError) Error() string
func (*MissingTokenError) Unwrap ¶ added in v0.1.30
func (e *MissingTokenError) Unwrap() error
Unwrap reports a missing token as os.ErrNotExist.
type ResponseObserver ¶ added in v0.2.32
type ResponseObserver interface {
BeginResponse(context.Context) error
ObserveResponse(context.Context, *responses.ResponseStreamEventUnion) error
}
ResponseObserver sees a response while it streams: BeginResponse before each streamed attempt, then ObserveResponse for the attempt's observed events, in order.
type Token ¶
type Token struct {
Refresh string `json:"refresh"`
Access string `json:"access"`
Expires int64 `json:"expires"`
AccountID string `json:"account_id,omitempty"`
}
Token is the persisted ChatGPT OAuth credential used for Codex requests.
func AcquireBrowserToken ¶ added in v0.0.42
AcquireBrowserToken completes the local browser OAuth flow without persisting the token. The OAuth client's registered redirect URI fixes the callback port.
func AcquireDeviceToken ¶ added in v0.0.42
AcquireDeviceToken completes the headless device OAuth flow without persisting the token.
func FreshTokenIn ¶ added in v0.1.30
func FreshTokenIn(ctx context.Context, workspace, runtimeDir, provider string, rejected Token) (Token, error)
FreshTokenIn returns the provider's ChatGPT OAuth token from runtimeDir, refreshing and persisting it under the auth file lock when needed. With a zero rejected token, the stored token is reused while it expires more than 120 s out. With the token a server just rejected, the stored token is reused only if another writer already replaced it for the same account. It returns a *MissingTokenError when the auth file has no token for the provider; a missing auth file also matches os.ErrNotExist.
func LoadTokenIn ¶
LoadTokenIn reads the provider's persisted ChatGPT OAuth token from runtimeDir.