Documentation
¶
Index ¶
- func ParseSystemPrompt(raw json.RawMessage) (string, error)
- type ClaudeRequest
- type ClaudeResponse
- type ContentBlock
- type ContextEdit
- type ContextManagement
- type EditAmount
- type ImageSource
- type Message
- type Metadata
- type OutputConfig
- type OutputFormat
- type ServerToolUse
- type StreamProcessor
- func (p *StreamProcessor) EmitBlock(block map[string]any) error
- func (p *StreamProcessor) EmitCitedText(text string, citations []map[string]any) error
- func (p *StreamProcessor) EmitCompaction(summary string) error
- func (p *StreamProcessor) EmitError(err error) error
- func (p *StreamProcessor) EmitErrorType(errorType string, err error) error
- func (p *StreamProcessor) EmitServerToolUse(id string, name string, input any) error
- func (p *StreamProcessor) EmitThinking(thinking string, signature string) error
- func (p *StreamProcessor) EmitToolCall(id string, name string, arguments json.RawMessage) error
- func (p *StreamProcessor) Finish(stopReason string) error
- func (p *StreamProcessor) FinishStopSequence(sequence string) error
- func (p *StreamProcessor) FinishThinking(signature string) error
- func (p *StreamProcessor) MessageID() string
- func (p *StreamProcessor) ProcessEvent(event gemini.Event) error
- func (p *StreamProcessor) SetContextManagement(management map[string]any, iterations []map[string]any)
- func (p *StreamProcessor) SetConversationID(conversationID string)
- func (p *StreamProcessor) SetModel(model string)
- func (p *StreamProcessor) SetProviderModel(model string)
- type StreamingState
- type ThinkingConfig
- type Tool
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSystemPrompt ¶
func ParseSystemPrompt(raw json.RawMessage) (string, error)
Types ¶
type ClaudeRequest ¶
type ClaudeRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
System json.RawMessage `json:"system,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
Stream bool `json:"stream"`
MaxTokens *int `json:"max_tokens,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
Thinking *ThinkingConfig `json:"thinking,omitempty"`
OutputConfig *OutputConfig `json:"output_config,omitempty"`
OutputFormat *OutputFormat `json:"output_format,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
PreviousResponseID string `json:"previous_response_id,omitempty"`
// ContextManagement 为本服务在本地执行的上下文编辑策略
ContextManagement *ContextManagement `json:"context_management,omitempty"`
}
type ClaudeResponse ¶
type ClaudeResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Content []ContentBlock `json:"content"`
Model string `json:"model"`
StopReason string `json:"stop_reason"`
StopSequence *string `json:"stop_sequence"`
Usage *Usage `json:"usage,omitempty"`
// ContextManagement 是请求带 context_management 时生效的编辑
ContextManagement map[string]any `json:"context_management,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
// ProviderModel 是上游实际回答的模型 ID
ProviderModel string `json:"provider_model,omitempty"`
}
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input *map[string]interface{} `json:"input,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
Content json.RawMessage `json:"content,omitempty"`
IsError *bool `json:"is_error,omitempty"`
Source *ImageSource `json:"source,omitempty"`
Data string `json:"data,omitempty"`
Citations []map[string]any `json:"citations,omitempty"`
// EncryptedContent 是 compaction 块的加密内容,本服务写为 null
EncryptedContent json.RawMessage `json:"encrypted_content,omitempty"`
}
func ParseMessageContent ¶
func ParseMessageContent(raw json.RawMessage) ([]ContentBlock, string, error)
type ContextEdit ¶ added in v0.2.0
type ContextEdit struct {
Type string `json:"type"`
Trigger *EditAmount `json:"trigger"`
Keep json.RawMessage `json:"keep"`
ClearAtLeast *EditAmount `json:"clear_at_least"`
ExcludeTools []string `json:"exclude_tools"`
ClearToolInputs json.RawMessage `json:"clear_tool_inputs"`
PauseAfterCompaction bool `json:"pause_after_compaction"`
Instructions string `json:"instructions"`
}
ContextEdit 是一条上下文编辑策略,字段按 type 取用
type ContextManagement ¶ added in v0.2.0
type ContextManagement struct {
Edits []ContextEdit `json:"edits"`
}
ContextManagement 是 context_management 的上下文编辑策略
type EditAmount ¶ added in v0.2.0
EditAmount 是触发条件、保留数量与最少清理量的类型与数值
type ImageSource ¶
type Message ¶
type Message struct {
Role string `json:"role"`
Content json.RawMessage `json:"content"`
}
type OutputConfig ¶
type OutputConfig struct {
Effort string `json:"effort,omitempty"`
Format *OutputFormat `json:"format,omitempty"`
}
OutputConfig 表示 Claude 输出强度与结构化输出配置
type OutputFormat ¶ added in v0.1.6
type OutputFormat struct {
Type string `json:"type"`
Schema json.RawMessage `json:"schema"`
}
OutputFormat 表示 output_config.format 与 beta output_format 的结构化输出格式
type ServerToolUse ¶ added in v0.1.3
type ServerToolUse struct {
WebSearchRequests int `json:"web_search_requests"`
WebFetchRequests int `json:"web_fetch_requests"`
}
ServerToolUse 统计服务端工具的调用次数
type StreamProcessor ¶
type StreamProcessor struct {
// contains filtered or unexported fields
}
StreamProcessor 将规范事件编码为 Claude SSE
func NewStreamProcessor ¶
func NewStreamProcessor(model string, writer io.Writer, messageIDs ...string) *StreamProcessor
NewStreamProcessor 创建 Claude SSE 编码器
func (*StreamProcessor) EmitBlock ¶ added in v0.1.3
func (p *StreamProcessor) EmitBlock(block map[string]any) error
EmitBlock 以一对 content_block_start 与 content_block_stop 输出完整内容块,例如 web_search_tool_result
func (*StreamProcessor) EmitCitedText ¶ added in v0.1.3
func (p *StreamProcessor) EmitCitedText(text string, citations []map[string]any) error
EmitCitedText 输出一个带引用的文本块,引用以 citations_delta 先于正文发送
func (*StreamProcessor) EmitCompaction ¶ added in v0.2.0
func (p *StreamProcessor) EmitCompaction(summary string) error
EmitCompaction 输出本次请求压缩上下文得到的 compaction 块,摘要以 compaction_delta 发送
func (*StreamProcessor) EmitError ¶
func (p *StreamProcessor) EmitError(err error) error
EmitError 输出 Claude 流式错误
func (*StreamProcessor) EmitErrorType ¶ added in v0.1.3
func (p *StreamProcessor) EmitErrorType(errorType string, err error) error
EmitErrorType 以指定错误类型输出 Claude 流式错误
func (*StreamProcessor) EmitServerToolUse ¶ added in v0.1.3
func (p *StreamProcessor) EmitServerToolUse(id string, name string, input any) error
EmitServerToolUse 输出一次服务端工具调用块,输入以 input_json_delta 发送
func (*StreamProcessor) EmitThinking ¶
func (p *StreamProcessor) EmitThinking(thinking string, signature string) error
EmitThinking 输出带代理签名的完整思考块
func (*StreamProcessor) EmitToolCall ¶
func (p *StreamProcessor) EmitToolCall(id string, name string, arguments json.RawMessage) error
EmitToolCall 输出完整 Claude 工具调用块
func (*StreamProcessor) Finish ¶
func (p *StreamProcessor) Finish(stopReason string) error
Finish 完成 Claude SSE 消息
func (*StreamProcessor) FinishStopSequence ¶ added in v0.1.6
func (p *StreamProcessor) FinishStopSequence(sequence string) error
FinishStopSequence 以命中的停止序列完成 Claude SSE 消息
func (*StreamProcessor) FinishThinking ¶
func (p *StreamProcessor) FinishThinking(signature string) error
FinishThinking 完成当前思考块并输出签名
func (*StreamProcessor) MessageID ¶
func (p *StreamProcessor) MessageID() string
MessageID 返回当前 Claude 消息标识
func (*StreamProcessor) ProcessEvent ¶
func (p *StreamProcessor) ProcessEvent(event gemini.Event) error
ProcessEvent 消费一个 Gemini 规范事件
func (*StreamProcessor) SetContextManagement ¶ added in v0.2.0
func (p *StreamProcessor) SetContextManagement(management map[string]any, iterations []map[string]any)
SetContextManagement 设置 message_delta 携带的上下文编辑结果与各次采样的用量
func (*StreamProcessor) SetConversationID ¶
func (p *StreamProcessor) SetConversationID(conversationID string)
SetConversationID 设置最终消息携带的显式会话标识
func (*StreamProcessor) SetModel ¶
func (p *StreamProcessor) SetModel(model string)
SetModel 设置校验后的实际模型
func (*StreamProcessor) SetProviderModel ¶ added in v0.2.0
func (p *StreamProcessor) SetProviderModel(model string)
SetProviderModel 设置 message_delta 携带的上游实际模型
type StreamingState ¶
type StreamingState struct {
MessageID string
Model string
MessageStartSent bool
MessageStopSent bool
BlockIndex int
CurrentBlockType string
Usage *gemini.Usage
ConversationID string
// ProviderModel 是上游实际回答的模型 ID,写在 message_delta 中
ProviderModel string
// WebSearchRequests 与 WebFetchRequests 为 message_delta usage.server_tool_use 的搜索与读取网页次数
WebSearchRequests int
WebFetchRequests int
// StopSequence 为 message_delta 中命中的停止序列
StopSequence *string
// ContextManagement 与 Iterations 为 message_delta 中生效的上下文编辑与各次采样的用量
ContextManagement map[string]any
Iterations []map[string]any
}
StreamingState 保存 Claude SSE 的输出状态
func NewStreamingState ¶
func NewStreamingState(model string) *StreamingState
NewStreamingState 创建 Claude SSE 状态
type ThinkingConfig ¶
type Tool ¶
type Tool struct {
Type *string `json:"type,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema,omitempty"`
// DisplayWidthPx、DisplayHeightPx 与 EnableZoom 是 computer 工具的屏幕尺寸与 zoom 动作开关
DisplayWidthPx int `json:"display_width_px,omitempty"`
DisplayHeightPx int `json:"display_height_px,omitempty"`
EnableZoom bool `json:"enable_zoom,omitempty"`
// MaxUses 是服务端工具在一次请求中的调用次数上限
MaxUses int `json:"max_uses,omitempty"`
// AllowedDomains 与 BlockedDomains 是 web_search 与 web_fetch 工具允许与屏蔽的域名
AllowedDomains []string `json:"allowed_domains,omitempty"`
BlockedDomains []string `json:"blocked_domains,omitempty"`
// UserLocation 是 web_search 工具按其搜索的用户位置
UserLocation json.RawMessage `json:"user_location,omitempty"`
}
func (Tool) IsWebSearch ¶
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens"`
CacheCreationInputTokens *int `json:"cache_creation_input_tokens,omitempty"`
CacheReadInputTokens *int `json:"cache_read_input_tokens,omitempty"`
OutputTokens int `json:"output_tokens"`
ServerToolUse *ServerToolUse `json:"server_tool_use,omitempty"`
// Iterations 是请求带 compact_20260112 时压缩与回答各次采样的用量
Iterations []map[string]any `json:"iterations,omitempty"`
}