Skip to content

refactor(opencode): skip per-token schema validation in AI-SDK adapter - #41272

Open
Celibistrial wants to merge 1 commit into
anomalyco:devfrom
Celibistrial:perf/skip-per-token-schema-validation
Open

refactor(opencode): skip per-token schema validation in AI-SDK adapter#41272
Celibistrial wants to merge 1 commit into
anomalyco:devfrom
Celibistrial:perf/skip-per-token-schema-validation

Conversation

@Celibistrial

Copy link
Copy Markdown

Issue for this PR

Closes #41270

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

toLLMEvents runs per streamed token. It rebuilt the Schema.is refinement on every providerMetadata call, and the LLMEvent.*Delta constructors ran schema validation on objects the adapter had just built itself. I hoisted the two validators to module scope so they compile once, and for the three per-token delta events I return a plain typed literal instead of the validating constructor. The function return type still checks those literals against the LLMEvent union, so a wrong shape is a type error rather than something that slips through at runtime. Lower frequency events keep the validated constructors.

How did you verify your code works?

bun test packages/opencode/test/session/llm.test.ts passes (28 tests, covers the native and AI-SDK streaming paths), and tsc is clean. The type annotation on the literals is what guards against shape drift.

Screenshots / recordings

N/A, not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Schema.is() was recompiled per call and the LLMEvent.*Delta() constructors run
Schema validation on every streamed token. Hoist the validators and emit plain
typed literals for the per-token delta events; the return type still checks them
against the LLMEvent union.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(opencode): skip per-token schema validation in AI-SDK adapter doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@Celibistrial Celibistrial changed the title perf(opencode): skip per-token schema validation in AI-SDK adapter refactor(opencode): skip per-token schema validation in AI-SDK adapter Aug 8, 2026
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.

perf: AI-SDK adapter re-validates schema on every streamed token

1 participant