| 1 | package imageinput |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | |
| 6 | "reasonix/internal/provider" |
| 7 | ) |
| 8 | |
| 9 | func clone(v *provider.VisionSummary) *provider.VisionSummary { |
| 10 | cp := *v |
| 11 | cp.ImageDigests = append([]string(nil), v.ImageDigests...) |
| 12 | return &cp |
| 13 | } |
| 14 | |
| 15 | func (s *Service) lookup(target string, images []string, history func() []provider.Message) ([]string, string, bool, *provider.VisionSummary) { |
| 16 | digests := make([]string, len(images)) |
| 17 | cacheable := true |
| 18 | for i, ref := range images { |
| 19 | digests[i] = ImageDigest(ref) |
| 20 | if provider.IsImageHTTPURL(ref) { |
| 21 | cacheable = false |
| 22 | } |
| 23 | } |
| 24 | match := func(v *provider.VisionSummary) bool { |
| 25 | return v != nil && v.Version == visionSummaryVersion && v.PromptVersion == visionSummaryPromptVersion && v.ModelRef == target && sameImageDigests(v.ImageDigests, digests) && strings.TrimSpace(v.Summary) != "" |
| 26 | } |
| 27 | key := target + "|" + strings.Join(digests, "|") |
| 28 | if cacheable { |
| 29 | if match(s.cached[key]) { |
| 30 | return digests, key, cacheable, clone(s.cached[key]) |
| 31 | } |
| 32 | if history != nil { |
| 33 | for _, msg := range history() { |
| 34 | if match(msg.VisionSummary) { |
| 35 | return digests, key, cacheable, clone(msg.VisionSummary) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | return digests, key, cacheable, nil |
| 41 | } |
| 42 |