Skip to content

Shared gateway-core, resume (coming soon), expanded tests & docs#590

Merged
threepointone merged 2 commits into
mainfrom
feat/shared-gateway-core
Jun 27, 2026
Merged

Shared gateway-core, resume (coming soon), expanded tests & docs#590
threepointone merged 2 commits into
mainfrom
feat/shared-gateway-core

Conversation

@threepointone

Copy link
Copy Markdown
Collaborator

Summary

Consolidates the AI Gateway logic shared across the Cloudflare AI packages into a new private, source-only workspace package, @cloudflare/gateway-core, that is bundled inline into each consumer (no new runtime dependency). It houses the provider registry, cf-aig-* header building, the resumable-stream engine, and Workers AI SSE helpers — so routing/header/resume behavior stays in lockstep across workers-ai-provider, ai-gateway-provider, and @cloudflare/tanstack-ai.

On top of the consolidation, this PR revives ai-gateway-provider, brings resumable streaming to all three packages (marked coming soon — see below), standardizes tooling on oxlint/oxfmt, and adds a large amount of test and documentation coverage.

Important

Resumable streaming is implemented but NOT generally available yet — the AI Gateway resume backend is still rolling out. It is therefore marked "coming soon" across docs, package READMEs, changesets, and examples. The API is in place so it can be adopted early, but should be treated as experimental until rollout completes.

What changed

@cloudflare/gateway-core (new, private)

  • Provider registry, cf-aig-* header builders, resumable-stream engine, and Workers AI SSE helpers.
  • private: true, source-only, bundled into consumers via tsdown — not published, no changeset.

workers-ai-provider

  • AI Gateway delegate gains cross-vendor server-side fallback (fallback: { mode: "server" }), winner selected via cf-aig-step.
  • Header parity on the gateway path (cacheKey / eventId / requestTimeoutMs / retries) and two new universal-endpoint controls: byokAlias (cf-aig-byok-alias) and zdr (cf-aig-zdr).
  • Registry/header/SSE/resume logic now derives from gateway-core.

ai-gateway-provider

  • No longer deprecated / feature-frozen.
  • Adds byokAlias / zdr; emits the current cf-aig-cache-ttl / cf-aig-skip-cache header names (old cf-cache-ttl / cf-skip-cache dropped).
  • New opt-in resumable streaming on the binding/run path (shared engine), no-op on REST/non-streaming.
  • Provider list now derives from gateway-core; source simplified. AiGatewayRetiesAiGatewayRetries (old name kept as a deprecated alias — non-breaking).
  • tsconfig now type-checks test files; adds a creds-gated live e2e suite.

@cloudflare/tanstack-ai

  • Resumable streaming on the Workers AI catalog run path, gpt-oss forced tool-call salvage, and @tanstack/ai peer bumps (multimodal MediaPrompt).
  • format script standardized on oxfmt (dropped a stray Biome usage).

Docs

  • New docs/ tree: concepts (gateway routing, binding vs REST, resume) + per-package guides, with enriched examples.
  • No internal gateway-core leakage in user-facing docs. Removed the internal test-coverage matrix.

Tooling

  • Standardize on oxlint + oxfmt; removed remaining Biome references.

Testing

  • Substantial new unit/integration/e2e coverage across all packages: parse-options, auth, fallback, errors, request-shaping, resume, tools/structured, abort, REST media, gateway providers.

Validation (local)

Check Result
Build (nx run-many -t build packages/*) ✅ 4/4
Type-check (tsc --noEmit, all packages incl. tests) ✅ 4/4
Unit/integration tests (test:ci) ✅ 783 passing (gateway-core 55, workers-ai-provider 416, ai-gateway-provider 46, tanstack-ai 266)
Lint (oxlint) ✅ clean (2 pre-existing no-underscore-dangle warnings, unrelated)

Test plan

  • CI green (nx affected -t lint test:ci type-check build)
  • Run the creds-gated e2e suites against a live gateway (pnpm --filter <pkg> test:e2e) where credentials are available
  • Sanity-check the examples/workers-ai and examples/tanstack-ai apps locally (binding + REST)
  • Confirm resume "coming soon" framing reads correctly in rendered docs

Notes

  • @cloudflare/gateway-core is intentionally private/source-only and excluded from changesets/publish.
  • Changesets are included for the three published packages (workers-ai-provider, ai-gateway-provider, @cloudflare/tanstack-ai).

Made with Cursor

… docs

Consolidate the AI Gateway logic shared across the Cloudflare AI packages into a
new private, source-only workspace package (`@cloudflare/gateway-core`) that is
bundled inline into each consumer — no new runtime dependency. It houses the
provider registry, `cf-aig-*` header building, the resumable-stream engine, and
Workers AI SSE helpers, so routing/header/resume behavior stays in lockstep.

workers-ai-provider:
- AI Gateway delegate gains cross-vendor server-side fallback
  (`fallback: { mode: "server" }`), header parity on the gateway path
  (cacheKey/eventId/requestTimeoutMs/retries), and new `byokAlias` / `zdr`
  universal-endpoint controls.
- Registry/header/SSE/resume logic now derive from gateway-core.

ai-gateway-provider:
- No longer deprecated/feature-frozen. Adds `byokAlias` / `zdr`, emits current
  `cf-aig-cache-ttl` / `cf-aig-skip-cache` header names, and adds opt-in
  resumable streaming on the binding/run path (shared engine).
- Provider list now derives from gateway-core; source simplified. `AiGatewayReties`
  renamed to `AiGatewayRetries` (old name kept as a deprecated alias).
- type-check now covers test files; adds a creds-gated live e2e suite.

@cloudflare/tanstack-ai:
- Resumable streaming on the Workers AI catalog run path, gpt-oss forced
  tool-call salvage, and `@tanstack/ai` peer bumps (multimodal MediaPrompt).
- Standardize the `format` script on oxfmt (drop the stray Biome usage).

Resume rollout:
- Resumable streaming is implemented but NOT generally available yet, so it is
  marked "coming soon" across docs, package READMEs, changesets, and examples.

Docs:
- New `docs/` tree (concepts + per-package guides) with enriched examples; no
  internal `gateway-core` leakage. Removes the internal test-coverage matrix.

Tooling:
- Standardize on oxlint + oxfmt; remove remaining Biome references.

Testing:
- Substantial new unit/integration/e2e coverage across all packages
  (parse-options, auth, fallback, errors, request-shaping, resume,
  tools/structured, abort, REST media, gateway providers).

Changesets included for the three published packages; gateway-core is private.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6f36e52

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
ai-gateway-provider Minor
@cloudflare/tanstack-ai Minor
workers-ai-provider Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npx https://pkg.pr.new/cloudflare/ai/ai-gateway-provider@590
npx https://pkg.pr.new/cloudflare/ai/@cloudflare/tanstack-ai@590
npx https://pkg.pr.new/cloudflare/ai/workers-ai-provider@590

commit: 6f36e52

- Remove husky and the pre-push git hook. The hook only re-ran `pnpm install`
  to verify the lockfile was stable, which CI already enforces via
  `pnpm install --frozen-lockfile`. Drops the `husky` devDependency and the
  `prepare` script.
- Fix the `.gitignore` escaping (`\*.tsbuildinfo` -> `*.tsbuildinfo`) so
  TypeScript build-info artifacts are actually ignored.
- Run oxfmt across the repo (`pnpm run format`).

Note: husky had set local `core.hooksPath` to `.husky/_`; with the dir removed
that path is now a no-op (no hooks run). Left git config untouched.

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone threepointone merged commit 9006591 into main Jun 27, 2026
4 checks passed
@threepointone threepointone deleted the feat/shared-gateway-core branch June 27, 2026 21:29
@github-actions github-actions Bot mentioned this pull request Jun 27, 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.

1 participant