返回 DeepSeek-Reasonix
turn_images.go
根目录 / internal / control / turn_images.go
1 package control
2
3 import (
4 "context"
5 "strings"
6
7 "reasonix/internal/agent"
8 )
9
10 // resolveTurnImages resolves each user attachment once. Text-only parents keep
11 // the data only as candidates for a vision-capable child; vision-capable
12 // parents reuse the same data URLs for their own provider request.
13 func (c *Controller) resolveTurnImages(line string) (userImages, imageCandidates []string) {
14 imageCandidates = c.resolveInputImageCandidates(line)
15 if c.imageInputEnabled() {
16 userImages = imageCandidates
17 }
18 return userImages, imageCandidates
19 }
20
21 func (c *Controller) prepareOrchestratedTurnImages(turn orchestratedTurn) orchestratedTurn {
22 turn.userImages, turn.imageCandidates = c.resolveTurnImages(turn.imageReferenceInput())
23 turn.imagesResolved = true
24 return turn
25 }
26
27 func (c *Controller) imagesForOrchestratedTurn(ctx context.Context, turn orchestratedTurn) (userImages, imageCandidates []string) {
28 if prepared, ok := ctx.Value(preparedImageReferencesContextKey{}).(preparedImageReferences); ok && len(prepared.inputs) > 0 {
29 return nil, nil
30 }
31 if turn.imagesResolved {
32 return turn.userImages, turn.imageCandidates
33 }
34 return c.resolveTurnImages(turn.imageReferenceInput())
35 }
36
37 func (c *Controller) withTurnImages(ctx context.Context, line string) context.Context {
38 prepared, _ := ctx.Value(preparedImageReferencesContextKey{}).(preparedImageReferences)
39 if inputs := prepared.inputs; len(inputs) > 0 {
40 ctx = agent.WithUserImageInputs(ctx, inputs)
41 ctx = agent.WithSubagentImageInputs(ctx, inputs)
42 return ctx
43 }
44 userImages, imageCandidates := c.resolveTurnImages(line)
45 ctx = agent.WithUserImages(ctx, userImages)
46 return agent.WithSubagentImageCandidates(ctx, imageCandidates)
47 }
48
49 func (c *Controller) withPreparedTurnImages(ctx context.Context) context.Context {
50 prepared, _ := ctx.Value(preparedImageReferencesContextKey{}).(preparedImageReferences)
51 if len(prepared.inputs) == 0 {
52 return ctx
53 }
54 ctx = agent.WithUserImages(ctx, nil)
55 ctx = agent.WithUserImageInputs(ctx, prepared.inputs)
56 return agent.WithSubagentImageInputs(ctx, prepared.inputs)
57 }
58
59 func (turn orchestratedTurn) imageReferenceInput() string {
60 if strings.TrimSpace(turn.imageRefs) != "" {
61 return turn.imageRefs
62 }
63 return turn.raw
64 }
65
66 func (c *Controller) runGoalLoopWithFrozenImagesRawDisplay(ctx context.Context, input, raw, display string, images []string) error {
67 return newTurnOrchestrator(c).runGoalLoopWithFrozenImagesRawDisplay(ctx, input, raw, display, images)
68 }
69
70 func (c *Controller) runEditedGoalLoopWithFrozenImagesRawDisplay(ctx context.Context, input, raw, display, original string, images []string) error {
71 return newTurnOrchestrator(c).runEditedGoalLoopWithFrozenImagesRawDisplay(ctx, input, raw, display, original, images)
72 }
73
73 lines GO