kimi

package
v1.0.65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package kimi provides token refresh for Kimi (Moonshot AI) credentials used by the scheduler.

Index

Constants

This section is empty.

Variables

View Source
var ErrRefreshTokenRejected = errors.New("kimi refresh token rejected")

ErrRefreshTokenRejected indicates that retrying the same Kimi refresh token cannot succeed.

Functions

This section is empty.

Types

type DeviceCodeResponse added in v1.0.3

type DeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri,omitempty"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

type DeviceFlowClient

type DeviceFlowClient struct {
	// contains filtered or unexported fields
}

DeviceFlowClient is a minimal Kimi OAuth client used for refresh-token exchange.

func NewDeviceFlowClient added in v1.0.3

func NewDeviceFlowClient(cfg *config.Config) *DeviceFlowClient

NewDeviceFlowClient creates a new device flow client.

func NewDeviceFlowClientWithDeviceID added in v1.0.3

func NewDeviceFlowClientWithDeviceID(cfg *config.Config, deviceID string) *DeviceFlowClient

NewDeviceFlowClientWithDeviceID creates a new device flow client with device id.

func NewDeviceFlowClientWithDeviceIDAndProxyURL

func NewDeviceFlowClientWithDeviceIDAndProxyURL(cfg *config.Config, deviceID string, proxyURL string) *DeviceFlowClient

NewDeviceFlowClientWithDeviceIDAndProxyURL creates a new refresh client with proxy override. proxyURL takes precedence over cfg.ProxyURL when non-empty.

func (*DeviceFlowClient) PollForToken added in v1.0.3

func (c *DeviceFlowClient) PollForToken(ctx context.Context, deviceCode *DeviceCodeResponse) (*KimiTokenData, error)

PollForToken converts poll for token.

func (*DeviceFlowClient) RefreshToken

func (c *DeviceFlowClient) RefreshToken(ctx context.Context, refreshToken string) (*KimiTokenData, error)

RefreshToken exchanges a refresh token for a new access token.

func (*DeviceFlowClient) RequestDeviceCode added in v1.0.3

func (c *DeviceFlowClient) RequestDeviceCode(ctx context.Context) (*DeviceCodeResponse, error)

RequestDeviceCode handles request device code.

type KimiAuth added in v1.0.3

type KimiAuth struct {
	// contains filtered or unexported fields
}

func NewKimiAuth added in v1.0.3

func NewKimiAuth(cfg *config.Config) *KimiAuth

NewKimiAuth creates a new kimi auth.

func (*KimiAuth) StartDeviceFlow added in v1.0.3

func (k *KimiAuth) StartDeviceFlow(ctx context.Context) (*DeviceCodeResponse, error)

StartDeviceFlow starts a device flow.

func (*KimiAuth) WaitForAuthorization added in v1.0.3

func (k *KimiAuth) WaitForAuthorization(ctx context.Context, deviceCode *DeviceCodeResponse) (*KimiAuthBundle, error)

WaitForAuthorization returns a wait for authorization.

type KimiAuthBundle added in v1.0.3

type KimiAuthBundle struct {
	TokenData *KimiTokenData
	DeviceID  string
}

type KimiTokenData

type KimiTokenData struct {
	// AccessToken is the OAuth2 access token.
	AccessToken string `json:"access_token"`
	// RefreshToken is the OAuth2 refresh token.
	RefreshToken string `json:"refresh_token"`
	// TokenType is the type of token, typically "Bearer".
	TokenType string `json:"token_type"`
	// ExpiresAt is the Unix timestamp when the token expires.
	ExpiresAt int64 `json:"expires_at"`
	// Scope is the OAuth2 scope granted to the token.
	Scope string `json:"scope"`
}

KimiTokenData holds the raw OAuth token response from Kimi.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL