gemini

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUpstreamFailureText = errors.New("gemini web returned a fixed failure text")

ErrUpstreamFailureText 表示 Gemini Web 用固定失败文字代替回答

Functions

This section is empty.

Types

type AccountSource

type AccountSource struct {
	ID          string
	Cookies     []Cookie
	Fingerprint Fingerprint
	Save        func([]Cookie) error
	Refresh     func(context.Context) ([]Cookie, error)
}

AccountSource 表示账号固定身份和 Cookie 持久化入口

type Bootstrap

type Bootstrap struct {
	SNlM0e string
	BL     string
	FSID   string
	// Language 为首页 TuX5cc 给出的账号界面语言,用于 hl 与生成载荷语言槽
	Language string
	Catalog  ModelCatalog
}

Bootstrap 表示首页和模型目录共同产生的运行参数

type Citation

type Citation struct {
	ID        int    `json:"id"`
	SourceID  string `json:"source_id,omitempty"`
	Claim     string `json:"claim,omitempty"`
	Title     string `json:"title,omitempty"`
	URL       string `json:"url"`
	Favicon   string `json:"favicon,omitempty"`
	Snippet   string `json:"snippet,omitempty"`
	Publisher string `json:"publisher,omitempty"`
	Start     int    `json:"start"`
	End       int    `json:"end"`
}

Citation 表示正文引用标记对应的网页来源

type Client

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

Client 表示与单一账号身份绑定的 Gemini Web 协议客户端

func NewClient

func NewClient(source AccountSource, proxyURL string, saveHistory bool) (*Client, error)

NewClient 创建固定 Cookie、代理和指纹的账号客户端

func (*Client) AcquireRequest

func (c *Client) AcquireRequest(ctx context.Context) (func(), error)

AcquireRequest 独占同一账号的完整上游请求链

func (*Client) CloseIdleConnections

func (c *Client) CloseIdleConnections()

CloseIdleConnections 关闭协议客户端的空闲连接

func (*Client) ContextWindow

func (c *Client) ContextWindow() int

ContextWindow 返回账号套餐对应的网页输入窗口

func (*Client) FetchMedia

func (c *Client) FetchMedia(ctx context.Context, mediaURL string) ([]byte, error)

FetchMedia 使用账号固定身份和 Cookie 下载媒体内容

func (*Client) FetchUsage

func (c *Client) FetchUsage(ctx context.Context) (UsageInfo, error)

FetchUsage 读取官网当前账号用量

func (*Client) Init

func (c *Client) Init(ctx context.Context) error

Init 刷新首页动态参数并获取当前账号模型目录

func (*Client) Models

func (c *Client) Models() []Model

Models 返回当前账号初始化得到的模型目录

func (*Client) ResolveModel

func (c *Client) ResolveModel(id string) (Model, error)

ResolveModel 在当前账号模型目录中解析公开 ID

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, request GenerateRequest, emit func(Event) error) error

Stream 执行一次生成并只输出规范事件

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, data []byte, filename string) (string, error)

UploadFile 上传多模态附件并返回网页协议文件标识

type CodeEventType

type CodeEventType string

CodeEventType 表示 Gemini Web 内置代码执行事件类型

const (
	CodeReference CodeEventType = "code_reference"
	CodeStdout    CodeEventType = "code_stdout"
	CodeStderr    CodeEventType = "code_stderr"
)

type CodeExecutionEvent

type CodeExecutionEvent struct {
	Index    int
	Type     CodeEventType
	Language string
	Offset   int
	Complete bool
}

CodeExecutionEvent 表示 Google 已执行的代码及其结果

type ConversationSnapshot

type ConversationSnapshot struct {
	CID  string
	RID  string
	RCID string
}

ConversationSnapshot 表示可序列化的网页会话三元组

type ConversationState

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

ConversationState 保存线程安全的网页会话状态

func NewConversationState

func NewConversationState() *ConversationState

NewConversationState 创建空网页会话状态

func NewConversationStateFrom

func NewConversationStateFrom(snapshot ConversationSnapshot) *ConversationState

NewConversationStateFrom 从已有三元组创建网页会话状态

func (*ConversationState) Snapshot

Snapshot 返回当前会话三元组副本

func (*ConversationState) Update

func (s *ConversationState) Update(snapshot ConversationSnapshot)

Update 原子替换非空会话字段

type Cookie struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Domain   string `json:"domain"`
	Path     string `json:"path"`
	Expires  int64  `json:"expires"`
	HTTPOnly bool   `json:"http_only"`
	Secure   bool   `json:"secure"`
	SameSite string `json:"same_site"`
}

Cookie 表示可无损写回认证状态的 Cookie

type Event

type Event struct {
	Kind         EventKind
	Candidate    int
	Operation    SnapshotOperation
	Delta        string
	Snapshot     string
	PrefixLength int
	Phase        Phase
	Session      ConversationSnapshot
	Code         *CodeExecutionEvent
	Citations    []Citation
	Media        *Media
	Metadata     *EventMetadataData
	Usage        *Usage
	FinishReason FinishReason
	Err          *ProtocolError
}

Event 表示所有公开适配器共享的上游事件

type EventKind

type EventKind string

EventKind 表示规范化协议事件类型

const (
	EventSession       EventKind = "session"
	EventText          EventKind = "text"
	EventThought       EventKind = "thought"
	EventCode          EventKind = "code"
	EventCitations     EventKind = "citations"
	EventMedia         EventKind = "media"
	EventImageProgress EventKind = "image_progress"
	EventPhase         EventKind = "phase"
	EventMetadata      EventKind = "metadata"
	EventError         EventKind = "error"
	EventDone          EventKind = "done"
)

type EventMetadataData

type EventMetadataData struct {
	Title        string
	ControlToken string
	ModelHash    string
	ModelName    string
}

EventMetadataData 表示页面协议返回的附加元数据

type FileData

type FileData struct {
	URL      string
	FileName string
}

FileData 表示已上传并可放入提示词的附件

type Fingerprint

type Fingerprint struct {
	Browser    string `json:"browser"`
	Version    string `json:"version"`
	Platform   string `json:"platform"`
	UserAgent  string `json:"user_agent"`
	Language   string `json:"language"`
	TLSProfile string `json:"tls_profile"`
}

Fingerprint 表示与账号长期绑定的 HTTP 客户端指纹

type FinishReason

type FinishReason string

FinishReason 表示规范化结束原因

const (
	FinishUnknown   FinishReason = "unknown"
	FinishStop      FinishReason = "stop"
	FinishCancelled FinishReason = "cancelled"
	FinishError     FinishReason = "error"
)

type FrameDecoder

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

FrameDecoder 将 Google 累计帧转换为唯一规范事件流

func NewFrameDecoder

func NewFrameDecoder() *FrameDecoder

NewFrameDecoder 创建独立的单响应解码器

func (*FrameDecoder) Decode

func (d *FrameDecoder) Decode(reader io.Reader, state *ConversationState, emit func(Event) error) error

Decode 增量解析协议帧并原子更新会话状态

type GenerateRequest

type GenerateRequest struct {
	Prompt       string
	Model        string
	ModelMode    int
	ThinkingMode ThinkingMode
	Files        []FileData
	Conversation *ConversationState
}

GenerateRequest 表示一次网页协议生成请求

type Media

type Media struct {
	Type        MediaType `json:"type"`
	URL         string    `json:"url"`
	Title       string    `json:"title,omitempty"`
	Alt         string    `json:"alt,omitempty"`
	FileName    string    `json:"file_name,omitempty"`
	MIMEType    string    `json:"mime_type,omitempty"`
	Generator   string    `json:"generator,omitempty"`
	Placeholder string    `json:"placeholder,omitempty"`
	Width       int       `json:"width,omitempty"`
	Height      int       `json:"height,omitempty"`
	SizeBytes   int       `json:"size_bytes,omitempty"`
	Offset      int       `json:"offset"`
}

Media 表示规范事件携带的网页或生成媒体

type MediaType

type MediaType string

MediaType 表示 Gemini Web 媒体类型

const (
	MediaGeneratedImage MediaType = "generated_image"
)

type Model

type Model struct {
	ID          string
	DisplayName string
	Description string
	Hash        string
	// Tier 为模型行第 4 槽的账号层级,生成请求模型头第 11 项回传该值
	Tier         int
	Capabilities []string
	Mode         int
	Default      bool
}

Model 表示账号启动时发现的网页模型

type ModelCatalog

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

ModelCatalog 表示单个账号当前可用的模型目录

func (ModelCatalog) Default

func (c ModelCatalog) Default() (Model, error)

Default 返回官方标记的默认模型

func (ModelCatalog) List

func (c ModelCatalog) List() []Model

List 返回稳定排序的模型副本

func (ModelCatalog) Resolve

func (c ModelCatalog) Resolve(value string) (Model, error)

Resolve 根据公开 ID、官方名称或 hash 查找模型

type Phase

type Phase int

Phase 表示候选生成阶段

const (
	PhaseUnknown      Phase = 0
	PhaseGenerating   Phase = 1
	PhaseComplete     Phase = 2
	PhaseToolComplete Phase = 4
)

type ProtocolError

type ProtocolError struct {
	HTTPStatus int
	Code       int
	Message    string
	Retryable  bool
	Cause      error
}

ProtocolError 表示 HTTP 或帧内协议错误

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

Error 返回适合日志和公开错误映射的描述

func (*ProtocolError) Unwrap

func (e *ProtocolError) Unwrap() error

Unwrap 返回底层错误

type SnapshotOperation

type SnapshotOperation string

SnapshotOperation 表示累计快照相对上一版本的变化

const (
	SnapshotAppend   SnapshotOperation = "append"
	SnapshotReplace  SnapshotOperation = "replace"
	SnapshotTruncate SnapshotOperation = "truncate"
)

type ThinkingMode

type ThinkingMode int

ThinkingMode 表示 Gemini Web 思考策略

const (
	// ThinkingStandard 使用标准思考策略
	ThinkingStandard ThinkingMode = iota
	// ThinkingExtended 使用扩展思考策略
	ThinkingExtended
)

type Usage

type Usage struct {
	PromptTokens     int
	CompletionTokens int
	ThoughtTokens    int
	TotalTokens      int
}

Usage 表示上游提供的令牌用量

func (Usage) OutputTokens

func (u Usage) OutputTokens() int

OutputTokens 返回包含可见思考的输出 token 数

type UsageInfo

type UsageInfo struct {
	Tier                string       `json:"tier"`
	TierCode            int          `json:"tier_code"`
	Current             *UsageWindow `json:"current,omitempty"`
	Weekly              *UsageWindow `json:"weekly,omitempty"`
	RemainingCredits    *float64     `json:"remaining_credits,omitempty"`
	UseOverageAICredits bool         `json:"use_overage_ai_credits"`
	FetchedAt           time.Time    `json:"fetched_at"`
}

UsageInfo 表示单个账号的官网用量信息

type UsageWindow

type UsageWindow struct {
	UsedRatio float64   `json:"used_ratio"`
	ResetAt   time.Time `json:"reset_at"`
}

UsageWindow 表示官网展示的一段用量窗口

Jump to

Keyboard shortcuts

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