MCPcopy Create free account
hub / github.com/53AI/53AIHub / resolveAgentModelID

Function resolveAgentModelID

api/middleware/relay_auth.go:333–356  ·  view source on GitHub ↗

resolveAgentModelID 解析 Agent 和 AgentModel ID,支持加密的 hashID 和明文数字ID

(input string)

Source from the content-addressed store, hash-verified

331
332// resolveAgentModelID 解析 Agent 和 AgentModel ID,支持加密的 hashID 和明文数字ID
333func resolveAgentModelID(input string) (int64, error) {
334 if input == "" {
335 return 0, fmt.Errorf("输入不能为空")
336 }
337
338 // 首先尝试直接解析为数字(向后兼容)
339 if id, err := strconv.ParseInt(input, 10, 64); err == nil {
340 // 验证数字是否有效(正数)
341 if id > 0 {
342 return id, nil
343 }
344 return 0, fmt.Errorf("ID必须为正数: %s", input)
345 }
346
347 // 如果不是纯数字,检查是否是有效的hashID格式(包含字母)
348 if isHashIDFormat(input) {
349 // 尝试从hashID解码获取原始ID
350 if originalID, err := hashids.Decode(input); err == nil {
351 return originalID, nil
352 }
353 }
354
355 return 0, fmt.Errorf("无法解析ID: %s", input)
356}
357
358// isHashIDFormat 检查字符串是否符合hashID的一般格式(包含字母且不是纯数字)
359func isHashIDFormat(s string) bool {

Callers 2

RelayTokenAuthFunction · 0.85

Calls 3

isHashIDFormatFunction · 0.85
ErrorfMethod · 0.80
DecodeMethod · 0.80

Tested by

no test coverage detected