feat(aiguard): support vercel ai v7 #11388
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 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>
</details>
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.
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
max_rss_usage [-76.088MB; +43.051MB] or [-31.785%; +17.984%]scenario:appsec-iast-no-vulnerability-iast-enabled-default-config-26
max_rss_usage [-27.482MB; +23.270MB] or [-10.166%; +8.608%]scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20
max_rss_usage [-15.434MB; +32.857MB] or [-4.315%; +9.186%]scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-26
max_rss_usage [-27.608MB; +20.486MB] or [-9.138%; +6.781%]scenario:encoders-0.4-immediate-flush-24
max_rss_usage [-10.454MB; +1.407MB] or [-12.100%; +1.628%]scenario:openfeature-initialization-configuration-20
max_rss_usage [-6.656MB; +3.693MB] or [-8.442%; +4.684%]scenario:openfeature-initialization-error-20
max_rss_usage [-5722.474KB; +4209.383KB] or [-7.363%; +5.416%]scenario:openfeature-scale-full-24
max_rss_usage [-17.912MB; +29.440MB] or [-6.768%; +11.124%]scenario:openfeature-scale-full-26
max_rss_usage [-30128.159KB; +31403.359KB] or [-13.211%; +13.771%]scenario:plugin-graphql-long-with-depth-off-26
max_rss_usage [-16.836MB; +6.075MB] or [-8.956%; +3.231%]</details>
<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> <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>
<!-- 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
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>
Approved these changes.
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?
Yes agree, done
LGTM
tlhunter
IlyasShabi
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- Please make sure your changes are properly tested -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!--
PR title guidance:
use test: cover retries, not fix: cover retries.
such as fix(http, tests): handle retries.
- 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
use test(http): cover retries, not fix(test): cover retries.
chore(eslint), chore(scripts), ci(release), ci(workflows), and test(integration-tests).
-->
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.