Skip to content

feat: route with media condition, close #1729#1809

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Jun 11, 2026
Merged

feat: route with media condition, close #1729#1809
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Jun 10, 2026

Copy link
Copy Markdown
Owner

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds four new boolean routing conditions (has_image, has_video, has_document, has_audio) to the model-association "When" filter, allowing requests to be routed based on the media types present in their messages.

  • Backend: Introduces detectRequestContentFeatures in the orchestrator, which scans message multi-part content for media parts and provides an early-exit optimisation via hasAll(). Named constants for all condition fields are centralised in objects/model.go, and validateStreamLeaf is refactored into the generic validateBoolEqualityLeaf so the new fields share the same validation path.
  • Frontend: The four fields are registered in the filter-builder with type: 'boolean' and the isBooleanConditionField guard is extended to cover them, ensuring correct schema validation. Locale strings for both EN and ZH-CN are included.

Confidence Score: 5/5

Safe to merge — the new content-feature detection and routing logic is well-contained, correctly validated on both frontend and backend, and covered by targeted tests.

The change is additive: new condition fields go through the same validation pipeline as the existing boolean stream field (now unified in validateBoolEqualityLeaf), the orchestrator only pays the scanning cost when conditional candidates exist, and the hasAll() early-exit prevents redundant iteration. No existing behaviour is altered beyond signature changes to matchesAssociationWhen that are fully reflected in updated tests.

No files require special attention.

Important Files Changed

Filename Overview
internal/server/orchestrator/candidates_condition.go Adds detectRequestContentFeatures with correct MultipleContent scan and hasAll() early-exit; matchesAssociationWhen signature extended cleanly.
internal/server/biz/model.go validateStreamLeaf correctly unified into validateBoolEqualityLeaf; all four new fields handled in the switch with appropriate validation.
internal/objects/model.go Eight named constants added for all condition field names; no logic changes.
frontend/src/features/models/components/models-association-dialog.tsx contentFeatureConditionFields registered in filter builder with correct boolean type; isBooleanConditionField extended; frontend validation aligned with backend.
internal/server/biz/model_validation_test.go Comprehensive tests for valid/invalid content-feature conditions added; covers all four fields and non-boolean value rejection.
internal/server/orchestrator/candidates_condition_test.go TestMatchesAssociationWhen_ContentFeatures and TestDetectRequestContentFeatures added; existing tests updated for new function signature.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Incoming LLM Request] --> B{hasConditionalCandidates?}
    B -- No --> C[Return all candidates]
    B -- Yes --> D[Compute promptTokens, stream, requestFormat]
    D --> E[detectRequestContentFeatures]
    E --> F{Scan MultipleContent parts}
    F -- ImageURL != nil --> G[hasImage = true]
    F -- VideoURL != nil --> H[hasVideo = true]
    F -- Document != nil --> I[hasDocument = true]
    F -- InputAudio != nil --> J[hasAudio = true]
    G & H & I & J --> K{hasAll?}
    K -- Yes --> L[Early return features]
    K -- No --> F
    L --> M[matchesAssociationWhen]
    F -- Exhausted --> M
    M --> N{Evaluate Condition}
    N -- has_image / has_video / has_document / has_audio --> O[Compare bool feature flag]
    N -- prompt_tokens --> P[Numeric comparison]
    N -- stream --> Q[Bool comparison]
    N -- request_format --> R[String equality]
    N -- daily_time --> S[Time range check]
    O & P & Q & R & S --> T{Match?}
    T -- Yes --> U[Include candidate]
    T -- No --> V[Exclude candidate]
Loading

Reviews (2): Last reviewed commit: "feat: route with media condition, close ..." | Re-trigger Greptile

Comment thread internal/server/orchestrator/candidates_condition.go

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@looplj looplj merged commit 960690a into unstable Jun 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant