gateway: aliased and magpieAliasAsked read one alias parser (#4667)
magpieAliasAsked copied aliased's four prefixes; a fifth form added to one would leave the other behind. Both now read aliasDigits. Run: targeted alias/member/desktop/science tests, gofmt, vet x3 (mote).
This commit is contained in:
+17
-23
@@ -425,20 +425,7 @@ func desktopNames(entries []provider.Entry) []string {
|
||||
// or without Claude Code's "[1m]"; or Claude Science's,
|
||||
// claude-magpie-<number>.
|
||||
func aliased(id string) (string, bool) {
|
||||
id = strings.TrimSuffix(id, "[1m]")
|
||||
var number string
|
||||
if n, ok := strings.CutPrefix(id, desktopAlias); ok {
|
||||
number = n
|
||||
} else if n, ok := strings.CutPrefix(id, desktopEffortAlias); ok {
|
||||
number = n
|
||||
} else if n, ok := strings.CutPrefix(id, scienceAlias); ok {
|
||||
// Claude Science's (science.go)
|
||||
number = n
|
||||
} else if rest, ok := strings.CutPrefix(id, "magpie-"); ok {
|
||||
if i := strings.Index(rest, desktopClaudeInfix); i > 0 {
|
||||
number = rest[:i]
|
||||
}
|
||||
}
|
||||
number := aliasDigits(id)
|
||||
if len(number) != 10 {
|
||||
return "", false
|
||||
}
|
||||
@@ -462,20 +449,27 @@ func aliased(id string) (string, bool) {
|
||||
// old alias is served all the same, and a reply to it must not name the
|
||||
// alias either (#4667).
|
||||
func magpieAliasAsked(id string) bool {
|
||||
n := aliasDigits(id)
|
||||
return len(n) == 10 && strings.IndexFunc(n, func(r rune) bool { return r < '0' || r > '9' }) < 0
|
||||
}
|
||||
|
||||
// aliasDigits is the number in one of magpie's alias ids (aliased's forms,
|
||||
// with or without Claude Code's "[1m]"), "" when id has none of the forms.
|
||||
func aliasDigits(id string) string {
|
||||
id = strings.TrimSuffix(id, "[1m]")
|
||||
var n string
|
||||
if rest, ok := strings.CutPrefix(id, desktopAlias); ok {
|
||||
n = rest
|
||||
} else if rest, ok := strings.CutPrefix(id, desktopEffortAlias); ok {
|
||||
n = rest
|
||||
} else if rest, ok := strings.CutPrefix(id, scienceAlias); ok {
|
||||
n = rest
|
||||
if n, ok := strings.CutPrefix(id, desktopAlias); ok {
|
||||
return n
|
||||
} else if n, ok := strings.CutPrefix(id, desktopEffortAlias); ok {
|
||||
return n
|
||||
} else if n, ok := strings.CutPrefix(id, scienceAlias); ok {
|
||||
// Claude Science's (science.go)
|
||||
return n
|
||||
} else if rest, ok := strings.CutPrefix(id, "magpie-"); ok {
|
||||
if i := strings.Index(rest, desktopClaudeInfix); i > 0 {
|
||||
n = rest[:i]
|
||||
return rest[:i]
|
||||
}
|
||||
}
|
||||
return len(n) == 10 && strings.IndexFunc(n, func(r rune) bool { return r < '0' || r > '9' }) < 0
|
||||
return ""
|
||||
}
|
||||
|
||||
// isClaudeDesktop is a request from Claude Desktop's own gateway client: its
|
||||
|
||||
Reference in New Issue
Block a user