Skip to content

refactor(ai): reuse JsonObject, ProviderMetadata, and responseHttp across protocols and gateways - #57615

Merged
rekram1-node merged 1 commit into
devfrom
ai-gateway-schema-cleanup
Oct 21, 2026
Merged

rekram1-node merged 1 commit into
devfrom
ai-gateway-schema-cleanup

Conversation

@rekram1-node

Copy link
Copy Markdown
Contributor

Problem

Several AI gateway, experimental, media, and protocol modules duplicated inline Schema.Record(...) definitions (JsonObject, ProviderMetadata, ProviderOptions), manual HttpContext construction from HttpClientResponse, and manual totalTokens summation instead of reusing the shared helpers in protocols/shared.ts, schema/options.ts, and route/executor.ts.

Change

Reuse JsonObject, ProviderMetadata, ProviderOptions, ProviderShared.totalTokens, and responseHttp across system-one.ts, vercel-ai-gateway.ts, realtime.ts, route/media-protocol.ts, media.ts, and protocols/venice-chat.ts.

 packages/ai/src/
 ├── experimental/
 │   ├── realtime.ts          # RequestExecutor.responseHttp(res)
 │   └── system-one.ts        # JsonObject, ProviderMetadata, RequestExecutor.responseHttp, ProviderShared.totalTokens
 ├── media.ts                 # responseHttp(response) via route/executor-service.ts
 ├── protocols/
 │   └── venice-chat.ts       # [JsonObject] rest schemas
 ├── providers/
 │   └── vercel-ai-gateway.ts # ProviderMetadata, ProviderOptions, JsonObject, RequestExecutor.responseHttp
 └── route/
     ├── executor-service.ts  # hosts leaf responseHttp + headerDetails to avoid schema/media cycle
     ├── executor.ts          # re-exports responseHttp
     └── media-protocol.ts    # RequestExecutor.responseHttp(response)
Target Before After
Rest record schemas (system-one, vercel-ai-gateway, venice-chat) [Schema.Record(Schema.String, Schema.Any | Schema.Unknown)] [JsonObject]
Nested provider metadata (system-one, vercel-ai-gateway) Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown)) ProviderMetadata
Evaluation providerOptions (vercel-ai-gateway) Schema.Record(Schema.String, Schema.Unknown) ProviderOptions
Response HTTP context (system-one, vercel-ai-gateway, realtime, media-protocol, media) new HttpContext({ url, status, headers }) RequestExecutor.responseHttp(res) / responseHttp(res)
Usage token total (system-one) inline input_tokens + output_tokens ProviderShared.totalTokens(...)

Out of scope

  • Changing wire schemas or runtime behavior of evaluation, realtime, media, or Venice chat routes.

@opencode-agent opencode-agent 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.

This looks sound to me. I checked each replaced inline schema against the shared definition, and they match: JsonObject and ProviderOptions are Record(String, Unknown), and ProviderMetadata is the same nested record. ProviderShared.totalTokens(in, out, undefined) also matches the old inline sum. responseHttp now turns header values into strings, as the executor path already did. Moving it into executor-service.ts doesn't create a new import cycle. In packages/ai, bun run typecheck passes and bun test gives 1826 pass, 0 fail.

Public API: unchanged. route/index.ts still re-exports only responseHttp and Service from executor.ts, so headerDetails stays internal.

@rekram1-node
rekram1-node merged commit 6843fb7 into dev Oct 21, 2026
21 checks passed
@rekram1-node
rekram1-node deleted the ai-gateway-schema-cleanup branch October 21, 2026 03:01
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