← Back to Pull requests

feat(aiguard): support vercel ai v7 #11388

Merged
IlyasShabi merged 10 files (419 lines) on Nov 25, 2026 13:59 UTC
View on GitHub
IlyasShabi IlyasShabi commented on Nov 23, 2026 15:31 UTC
Author

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- Please make sure your changes are properly tested -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

<!--
PR title guidance:

  • Follow Conventional Commits format: type(scope): description.

  • Valid types: feat, fix, docs, style, refactor, perf, test, bench, build, ci, chore, revert.

  • Reserve feat, fix, and perf for shipped production code.

  • A scope is optional, but omitting it does not change how the type is selected. For example,

  • use test: cover retries, not fix: cover retries.
  • A production type is valid for multiple scopes when at least one scope represents shipped code,

  • such as fix(http, tests): handle retries.
  • For non-production changes, use the area as the type:

  • - Tests: test(scope): description
    - Benchmarks: bench(scope): description
    - Documentation: docs(scope): description
    - CI and workflows: ci(scope): description
    - Build tooling: build(scope): description
    - Maintenance: chore(scope): description
  • For example, use docs(api): update setup guide, not fix(docs): update setup guide;

  • use test(http): cover retries, not fix(test): cover retries.
  • Apply the same rule to repository tooling. Examples include docs(agents), chore(codeowners),

  • chore(eslint), chore(scripts), ci(release), ci(workflows), and test(integration-tests).
  • Product scopes such as ci, test-optimization, and ci-visibility may still describe shipped production changes.

  • Add the appropriate semver-patch, semver-minor, or semver-major label.

  • -->

    What does this PR do?


    Fix AI Guard interception for newer Vercel AI SDK v7 bundles and support its tagged image format.
    Preserve text alongside tool calls when evaluating generated responses, streamed responses, and conversation history.

    Diff: 419 lines (+389 / -30) across 10 files Reviewer: tlhunter Review duration: 2787m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.52) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 419 lines diff across 10 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.72 · 5 substantive comment(s)
    0.72
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    81%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Real PR Conversation Timeline
    10 items
    dd-octo-sts[bot] dd-octo-sts[bot] commented on Nov 23, 2026 15:32 UTC
    Bot

    Overall package size

    Self size: 9.58 MB
    Deduped: 10.38 MB
    No deduping: 10.38 MB

    <details><summary>Dependency sizes</summary>
    | name | version | self size | total size |
    |------|---------|-----------|------------|
    | import-in-the-middle | 3.7.0 | 180.06 kB | 580.71 kB |
    | opentracing | 0.14.7 | 194.81 kB | 194.81 kB |
    | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

    </details>

    <sub>🤖 This report was automatically generated by heaviest-objects-in-the-universe<sub>

    codecov[bot] codecov[bot] commented on Nov 23, 2026 15:39 UTC
    Bot

    Codecov Report


    :white_check_mark: All modified and coverable lines are covered by tests.
    :white_check_mark: Project coverage is 99.16%. Comparing base (1d29d8b) to head (aa5d5e9).
    :warning: Report is 10 commits behind head on master.

    <details><summary>Additional details and impacted files</summary>

    @@           Coverage Diff            @@
    ##           master   #11388    +/-   ##
    ========================================
      Coverage   99.16%   99.16%            
    ========================================
      Files        1136     1137     +1     
      Lines      188620   188856   +236     
      Branches       86       86            
    ========================================
    + Hits       187036   187272   +236     
      Misses       1584     1584            
    

    | Flag | Coverage Δ | |
    |---|---|---|
    | ai-guard | 63.82% <100.00%> (+0.43%) | :arrow_up: |
    | apm-capabilities | 55.23% <52.94%> (+0.01%) | :arrow_up: |
    | apm-integrations | 81.93% <100.00%> (-0.02%) | :arrow_down: |
    | appsec | 59.45% <100.00%> (-0.08%) | :arrow_down: |
    | debugger | 70.90% <100.00%> (-0.02%) | :arrow_down: |
    | instrumentation | 59.98% <100.00%> (+0.08%) | :arrow_up: |
    | llmobs | 82.54% <100.00%> (-0.03%) | :arrow_down: |
    | master-coverage | 99.16% <100.00%> (?) | |
    | openfeature | 68.08% <100.00%> (-0.03%) | :arrow_down: |
    | platform | 67.51% <100.00%> (-0.67%) | :arrow_down: |
    | profiling | 66.53% <100.00%> (-0.02%) | :arrow_down: |
    | serverless | 66.68% <100.00%> (-0.02%) | :arrow_down: |
    | test-optimization | 82.05% <100.00%> (+0.03%) | :arrow_up: |

    Flags with carried forward coverage won't be shown. Click here to find out more.
    </details>

    :umbrella: View full report in Codecov by Harness.
    :loudspeaker: Have feedback on the report? Share it here.
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

  • </details>

    pr-commenter[bot] pr-commenter[bot] commented on Nov 23, 2026 15:41 UTC
    Bot

    Benchmarks

    Benchmark execution time: 2026-11-25 13:30:48

    Comparing candidate commit aa5d5e98a16ca824c4ea79e7b9f8103b7394bfb1 in PR branch ishabi/ai-guard-vercel-v7 with baseline commit 1d29d8b5f835aa0ade349ef26cabdf36f1db7ab3 in branch master.

    📊 Benchmarking dashboard

    Found 0 performance improvements and 0 performance regressions! Performance is the same for 2477 metrics, 10 unstable metrics.

    <details>
    <summary><h3>Explanation</h3></summary>

    This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

    🟩 = significantly better candidate vs. baseline
    🟥 = significantly worse candidate vs. baseline

    We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

    If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

    Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

    <details>
    <summary><h4>More details about the CI and significant changes</h4></summary>

    You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

    CIs of the difference of means are often centered around 0%, because often changes are not that big:

    ---------------------------------(------|---^--------)-------------------------------->
                                  -0.6%    0%  0.3%     +1.2%
                                     |          |        |
             lower bound of the CI --'          |        |
    sample mean (center of the CI) -------------'        |
             upper bound of the CI ----------------------'
    

    As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

    For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

    ----------------------------------------|---------|---(---------^---------)---------->
                                           0%        1%  1.3%      2.2%      3.1%
                                                      |   |         |         |
           significant impact threshold --------------'   |         |         |
                          lower bound of CI --------------'         |         |
           sample mean (center of the CI) --------------------------'         |
                          upper bound of CI ----------------------------------'
    

    </details>

    </details>

    <details>
    <summary><h3>Unstable benchmarks</h3></summary>

    These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

    scenario:appsec-appsec-enabled-20

  • unstable max_rss_usage [-76.088MB; +43.051MB] or [-31.785%; +17.984%]
  • scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-26

  • unstable max_rss_usage [-27.482MB; +23.270MB] or [-10.166%; +8.608%]
  • scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-15.434MB; +32.857MB] or [-4.315%; +9.186%]
  • scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-26

  • unstable max_rss_usage [-27.608MB; +20.486MB] or [-9.138%; +6.781%]
  • scenario:encoders-0.4-immediate-flush-24

  • unstable max_rss_usage [-10.454MB; +1.407MB] or [-12.100%; +1.628%]
  • scenario:openfeature-initialization-configuration-20

  • unstable max_rss_usage [-6.656MB; +3.693MB] or [-8.442%; +4.684%]
  • scenario:openfeature-initialization-error-20

  • unstable max_rss_usage [-5722.474KB; +4209.383KB] or [-7.363%; +5.416%]
  • scenario:openfeature-scale-full-24

  • unstable max_rss_usage [-17.912MB; +29.440MB] or [-6.768%; +11.124%]
  • scenario:openfeature-scale-full-26

  • unstable max_rss_usage [-30128.159KB; +31403.359KB] or [-13.211%; +13.771%]
  • scenario:plugin-graphql-long-with-depth-off-26

  • unstable max_rss_usage [-16.836MB; +6.075MB] or [-8.956%; +3.231%]
  • </details>

    datadog-datadog-prod-us1[bot] datadog-datadog-prod-us1[bot] commented on Nov 23, 2026 15:45 UTC
    Bot

    <a target='_blank' href='https://app.datadoghq.com/ci/pipeline-executions?query=ci_level%3Ajob+%40git.commit.sha%3Aaa5d5e98a16ca824c4ea79e7b9f8103b7394bfb1&referrer=pr-comment&start=1795610916000'><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/pipelines-ok.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/pipelines-ok-light.svg" alt="Pipelines" align="center" /></picture></a> &nbsp;<a target='_blank' href='https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest+%40git.commit.sha%3Aea73e9e2aa71734d5479d8cdd49699420c66e8f1&referrer=pr-comment&start=1795610916000'><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/tests-ok.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/tests-ok-light.svg" alt="Tests" align="center" /></picture></a>

    <details><summary><b>🎉 All green!</b></summary>

    🧪 All tests passed
    ❄️ No new flaky tests detected
    </details>

    🎯 Code Coverage (<a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdd-trace-js/pull-requests/11388'>details</a>)<br>• <strong><span title="Percentage of modified executable lines covered by tests in this PR">Patch Coverage</span></strong>: 100.00%<br>• <strong><span title="Percentage of all executable lines covered by tests in the entire codebase">Overall Coverage</span></strong>: 98.57% <span title="Change in overall coverage compared to the base branch">(-0.00%)</span><br>

    <sub>
    This comment will be updated automatically if new data arrives. <br />
    🔗 Commit SHA: aa5d5e9 | <a href="https://docs.datadoghq.com/integrations/guide/source-code-integration/#pr-comments">Docs</a> | <a href="https://app.datadoghq.com/ci/pull-request/Z2l0aHViLmNvbS9kYXRhZG9nL2RkLXRyYWNlLWpzLzExMzg4?referrer=pr-comment">View more details</a> | Give us <a href="https://dd.enterprise.slack.com/archives/C07E3U2QRMM">feedback</a>!
    </sub>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 23, 2026 15:48 UTC
    Bot

    <!-- codex-pull-request-review-summary -->
    <!-- codex-review-state:v1 {"code_review":{"commit_sha":"aa5d5e98a16ca824c4ea79e7b9f8103b7394bfb1","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":"aa5d5e98a16ca824c4ea79e7b9f8103b7394bfb1","has_any_findings":null,"has_unresolved_findings":null,"status":"completed"}} -->
    <!-- codex-security-review:v1 {"blockingSeverityThreshold":"P0","headSha":"aa5d5e98a16ca824c4ea79e7b9f8103b7394bfb1","mergeGateEnabled":false,"pullRequestNumber":11388,"repository":"DataDog/dd-trace-js","status":"completed"} -->
    <details>
    <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

    This comment shows the latest Codex review activity on this pull request.

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-25T13:20:16.559725Z">2026-11-25T13:20:16.559725Z</relative-time> | aa5d5e9 | New commits |
    | 🔒 Security Review | ✅ Completed <relative-time datetime="2026-11-25T13:22:41.714136Z">2026-11-25T13:22:41.714136Z</relative-time> | aa5d5e9 | New commits |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    </details>

    tlhunter tlhunter approved these changes on Nov 23, 2026 18:16 UTC
    Approved Reviewer

    Approved these changes.

    CarlesDD CarlesDD commented on code on Nov 25, 2026 11:20 UTC
    Code Review
    packages/dd-trace/src/aiguard/messages/vercel-ai.js:1

    In v7, a legacy image part with no mediaType is normalized to mediaType: 'image', and line 60 startsWith('image/') drops it. Could we also accept mediaType === 'image' and add tests for both cases?

    IlyasShabi IlyasShabi commented on code on Nov 25, 2026 13:21 UTC
    Code Review
    packages/dd-trace/src/aiguard/messages/vercel-ai.js:1

    Yes agree, done

    CarlesDD CarlesDD approved these changes on Nov 25, 2026 13:59 UTC
    Approved Reviewer

    LGTM

    Reviewers
    Assignees
    IlyasShabi IlyasShabi
    Labels
    risk: low confidence: 81.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.3% (MEDIUM) · Higher = larger blast radius
    52.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.3% · Lower = rushed or shallow review
    81.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.8% · Safe to merge
    9.8%