Documentation
¶
Overview ¶
Package shared 收敛所有 Provider 共用的工具函数.
避免各 provider 包复制粘贴相同逻辑 (如 API Key 脱敏), 改一处忘另一处就是安全漏洞.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckNoImageBlocks ¶
CheckNoImageBlocks rejects requests whose messages contain flyto.BlockImage anywhere (top-level blocks OR nested inside BlockToolResult.ResultBlocks) with an explicit error instead of silently dropping the image block. Used by providers that have not yet wired vision support -- vision path routes through Anthropic for now; other providers call this at Stream entry to surface "your image never reached the model" loudly.
Recursion note: when path B (tool returns image via Result.Data) wraps image blocks inside tool_result.ResultBlocks, a naive top-level-only scan would miss them and let the provider silently drop the nested image. This function recurses one level into ResultBlocks to catch that path. Deeper nesting (blocks containing blocks containing blocks) is not expected in the current Block model, so we stop at one level.
providerName goes into the error message so the caller can tell which provider rejected the image.
CheckNoImageBlocks 扫描请求消息, 顶层 block 或 BlockToolResult.ResultBlocks 嵌套层一旦出现 flyto.BlockImage 即返 error, 不做 silent drop. 未接 vision 的 provider 在 Stream 入口调用, 让调用方立刻知道"这张图没送到模型", 而 不是静默通过后纳闷为什么模型视若无睹. 当前 vision 路径只走 Anthropic, 其他 provider 待 per-provider 启用.
递归说明: 路径 B (工具经 Result.Data 返图) 会把 image block 包在 tool_result.ResultBlocks 里, 只扫顶层会漏, 让 provider 静默丢嵌套图. 本函数递归一层扫 ResultBlocks. 当前 Block 模型无更深嵌套预期, 一层即止.
providerName 会写进 error message, 调用方可据此定位是谁拒的图.
func GoStringWithMaskedKey ¶
GoStringWithMaskedKey 生成脱敏的 GoString 输出,用于防止 %#v 泄露 APIKey.
func MaskAPIKey ¶
MaskAPIKey 脱敏 API 密钥,保留前 4 字符. 精妙之处(CLEVER): 提取为共享函数--6 个 provider 都用同一逻辑, 原来各自复制,改一个忘另一个就是安全漏洞(比如新 provider 忘记脱敏).
Types ¶
This section is empty.