@volter/twin-ai-gateway 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +176 -0
- package/dist/src/ai-gateway-capabilities.d.ts +4 -0
- package/dist/src/ai-gateway-capabilities.js +772 -0
- package/dist/src/ai-gateway-conformance.d.ts +11 -0
- package/dist/src/ai-gateway-conformance.js +72 -0
- package/dist/src/ai-gateway-connector.d.ts +50 -0
- package/dist/src/ai-gateway-connector.js +97 -0
- package/dist/src/ai-gateway-models.d.ts +27 -0
- package/dist/src/ai-gateway-models.js +65 -0
- package/dist/src/ai-gateway-perform-harness.d.ts +5 -0
- package/dist/src/ai-gateway-perform-harness.js +17 -0
- package/dist/src/ai-gateway-scenario.d.ts +36 -0
- package/dist/src/ai-gateway-scenario.js +125 -0
- package/dist/src/ai-gateway-server.d.ts +16 -0
- package/dist/src/ai-gateway-server.js +107 -0
- package/dist/src/ai-gateway-stub.d.ts +20 -0
- package/dist/src/ai-gateway-stub.js +124 -0
- package/dist/src/ai-gateway-twin.d.ts +2 -0
- package/dist/src/ai-gateway-twin.js +994 -0
- package/dist/src/ai-gateway-types.d.ts +94 -0
- package/dist/src/ai-gateway-types.js +1 -0
- package/dist/src/ai-gateway-v3.d.ts +5 -0
- package/dist/src/ai-gateway-v3.js +367 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +24 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +54 -0
- package/package.json +66 -0
- package/src/ai-gateway-capabilities.ts +894 -0
- package/src/ai-gateway-conformance.ts +77 -0
- package/src/ai-gateway-connector.ts +100 -0
- package/src/ai-gateway-models.ts +105 -0
- package/src/ai-gateway-perform-harness.ts +17 -0
- package/src/ai-gateway-scenario.ts +137 -0
- package/src/ai-gateway-server.ts +122 -0
- package/src/ai-gateway-stub.ts +115 -0
- package/src/ai-gateway-twin.ts +1068 -0
- package/src/ai-gateway-types.ts +96 -0
- package/src/ai-gateway-v3.ts +372 -0
- package/src/cli.ts +23 -0
- package/src/index.ts +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# @volter/twin-ai-gateway
|
|
2
|
+
|
|
3
|
+
A local, faithful **Vercel AI Gateway** twin (`https://ai-gateway.vercel.sh`) your real SDK
|
|
4
|
+
talks to unmodified, over BOTH of the gateway's wire protocols:
|
|
5
|
+
|
|
6
|
+
- **`createGateway` (the `ai` package / `@ai-sdk/gateway`)** — the AI SDK's native gateway
|
|
7
|
+
provider, which speaks the **AI SDK gateway protocol at `/v3/ai`** (`POST /language-model`
|
|
8
|
+
with `ai-language-model-*` headers, `GET /config`). This is how a backend that does
|
|
9
|
+
`createGateway({ apiKey })` + `creator/model` slugs actually reaches the gateway.
|
|
10
|
+
- **`createOpenAI` (AI SDK) or the `openai` client** — the gateway's **OpenAI-compatible
|
|
11
|
+
`/v1` endpoint** (`/v1/chat/completions`, `/v1/embeddings`, `/v1/models`, …).
|
|
12
|
+
|
|
13
|
+
Point either at the twin's `baseURL` with `creator/model` slugs (`anthropic/claude-sonnet-4.6`,
|
|
14
|
+
`openai/gpt-5.2`, `xai/grok-4-1`, …) and chat completions, streaming, tool calls, structured
|
|
15
|
+
outputs, reasoning, provider routing metadata, embeddings, models, credits, generation lookup,
|
|
16
|
+
and spend reports all work. Built on the shared `@volter/world-core` kernel (durable event/action log
|
|
17
|
+
+ projection); no parallel side store — both protocols fold into the SAME generation log, so
|
|
18
|
+
credits/reports/lookup agree no matter which surface a consumer speaks.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { createGateway, generateText } from 'ai';
|
|
22
|
+
import { createAiGatewayTwinServer } from '@volter/twin-ai-gateway';
|
|
23
|
+
|
|
24
|
+
const { port } = createAiGatewayTwinServer({});
|
|
25
|
+
// The AI SDK's native gateway provider, unmodified (the shape a real backend uses):
|
|
26
|
+
const gateway = createGateway({ apiKey: 'test-key', baseURL: `http://127.0.0.1:${port}/v3/ai` });
|
|
27
|
+
const { text } = await generateText({
|
|
28
|
+
model: gateway('anthropic/claude-sonnet-4.6'),
|
|
29
|
+
prompt: 'hello',
|
|
30
|
+
});
|
|
31
|
+
// text starts with "[twin-stub:ai-gateway:…]" — a deterministic stub, clearly labeled.
|
|
32
|
+
|
|
33
|
+
// The OpenAI-compatible surface works identically:
|
|
34
|
+
// createOpenAI({ apiKey, baseURL: `http://127.0.0.1:${port}/v1` }).chat('anthropic/claude-sonnet-4.6')
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## The generative-stub design (be honest)
|
|
38
|
+
|
|
39
|
+
The twin **cannot run models or broker real providers** — there are no weights and no upstream
|
|
40
|
+
here. `POST /v1/chat/completions` returns a **deterministic STUB completion** that is
|
|
41
|
+
unmistakably a twin stub (a `[twin-stub:ai-gateway:<model>]` marker echoing your prompt), tool
|
|
42
|
+
calls return **schema-conformant synthesized arguments** (so an unmodified SDK's own argument
|
|
43
|
+
validation passes), and `POST /v1/embeddings` returns **deterministic, L2-normalized
|
|
44
|
+
pseudo-vectors** (default dimension 1536, matching the real `openai/text-embedding-3-small`;
|
|
45
|
+
`dimensions` overrides). They never pretend to be real model output.
|
|
46
|
+
|
|
47
|
+
What **is** faithful is the **entire protocol envelope**, per Vercel's docs:
|
|
48
|
+
|
|
49
|
+
- chat response shape — `{ id:'gen_…', object:'chat.completion', created, model, choices, usage }`
|
|
50
|
+
with a **unique `gen_` generation id per generation** (seeded with a per-root monotonic
|
|
51
|
+
sequence: identical repeated requests each get their own id and record, while a fresh root
|
|
52
|
+
replays byte-identically) and **`providerMetadata.gateway`** (`routing` with
|
|
53
|
+
`originalModelId/resolvedProvider/fallbacksAvailable/planningReasoning/modelAttempts/...`,
|
|
54
|
+
decimal-string `cost`/`marketCost`, `generationId`); `n` (OpenAI-spec passthrough — Vercel's
|
|
55
|
+
own parameter list doesn't enumerate it) produces multiple indexed choices, each the SAME
|
|
56
|
+
deterministic stub (a real provider would sample distinct ones)
|
|
57
|
+
- **streaming** via SSE — `chat.completion.chunk` deltas ending with `data: [DONE]`; the
|
|
58
|
+
generation id rides on the first chunk (documented for pre-completion capture); reasoning
|
|
59
|
+
streams as `delta.reasoning`; the final chunk carries `finish_reason` + usage; with `n>1`
|
|
60
|
+
EVERY billed choice index streams (each reconstructs its full content), matching the unary
|
|
61
|
+
body's choices
|
|
62
|
+
- **the AI SDK gateway protocol (`/v3/ai`)** — the wire protocol `createGateway` actually
|
|
63
|
+
speaks, derived from the shipped `@ai-sdk/gateway` SDK (there is no separately published
|
|
64
|
+
spec): `POST /v3/ai/language-model` consumes the raw LanguageModelV3 call options with the
|
|
65
|
+
model id in the `ai-language-model-id` header (+ `ai-language-model-specification-version`,
|
|
66
|
+
`ai-language-model-streaming`) and returns the LanguageModelV3 result — ordered content
|
|
67
|
+
parts, `finishReason: { unified, raw }`, nested usage, `providerMetadata.gateway` — or an
|
|
68
|
+
SSE stream of LanguageModelV3 stream parts (`response-metadata` → `text-delta`s /
|
|
69
|
+
`tool-input-*` + `tool-call` → `finish`); `GET /v3/ai/config` serves the model config
|
|
70
|
+
document `getAvailableModels()` consumes; unknown models fail with the `model_not_found`
|
|
71
|
+
envelope the SDK maps to its typed `GatewayModelNotFoundError`. V3 calls are a TRANSLATION
|
|
72
|
+
onto the same chat machinery, so generation records/credits/reports are one surface across
|
|
73
|
+
both protocols
|
|
74
|
+
- **tools** — `tool_calls` + `finish_reason:'tool_calls'`, `tool_choice`
|
|
75
|
+
(`none`/`auto`/`required`/named), streaming tool-call deltas
|
|
76
|
+
- **structured outputs** — OpenAI `json_schema` and `json_object` formats + the gateway's
|
|
77
|
+
legacy `{ type:'json' }` format, synthesized to conform to the supplied schema
|
|
78
|
+
- **reasoning** — `reasoning.{enabled,effort,max_tokens,exclude}` (effort and max_tokens are
|
|
79
|
+
mutually exclusive, as documented), `message.reasoning` + normalized `reasoning_details`
|
|
80
|
+
(anthropic `reasoning.text`+signature; openai `reasoning.summary`+`reasoning.encrypted`),
|
|
81
|
+
`usage.completion_tokens_details.reasoning_tokens`
|
|
82
|
+
- **provider routing** — `providerOptions.gateway.{order,only,sort,models,byok,caching}` + the
|
|
83
|
+
top-level `provider`/`models` shorthands (conflicting shorthand values fail, as documented);
|
|
84
|
+
`only` with no available provider fails naming the allowed providers; `sort` reports
|
|
85
|
+
`routing.sort` metadata (option/executionOrder/metrics) over **deterministic** per-provider
|
|
86
|
+
metrics — a twin simulation of the gateway's live telemetry
|
|
87
|
+
- **error envelope** — `{ error: { message, type, param, code } }` (400 validation with `param`,
|
|
88
|
+
404 `model_not_found`, 405 in read-only mode, 404 for unmodeled operations — never fake
|
|
89
|
+
success; a failed *streaming* request gets its real 4xx JSON on the wire, never a 200 SSE
|
|
90
|
+
stream wrapping an error)
|
|
91
|
+
- **BYOK accounting per the docs** — a request routed over request-scoped BYOK credentials
|
|
92
|
+
records `total_cost` 0.00 (the provider bills the tokens; gateway credits are untouched) and
|
|
93
|
+
carries the market price as `upstream_inference_cost`/`marketCost`
|
|
94
|
+
|
|
95
|
+
The genuinely **stateful** surface is real accounting over the kernel's generation log, not a
|
|
96
|
+
hardcoded stub: every chat completion — and every **embeddings** call, which the real gateway
|
|
97
|
+
bills too (`providerMetadata.gateway.generationId` on the embeddings response points at its
|
|
98
|
+
record) — appends a generation record; `GET /v1/generation?id=…`
|
|
99
|
+
serves it (cost/latency/token/BYOK fields per the REST API Reference); `GET /v1/credits` folds
|
|
100
|
+
`balance`/`total_used` from recorded spend; `GET /v1/report` serves the documented Custom
|
|
101
|
+
Reporting `results` rows (grouping field `day`/`hour`/`model`/`provider`/`credential_type` +
|
|
102
|
+
`total_cost`/`market_cost`/`surcharge_cost`/`gateway_cost`/token counts/`request_count`) with
|
|
103
|
+
the documented query validation and model/provider/credential_type filters; attribution-keyed
|
|
104
|
+
groupings and filters (user/tag/api_key_name/ZDR) resolve to empty result sets because the twin
|
|
105
|
+
records no request attribution yet (an open todo, not a fabrication). `GET /v1/models`,
|
|
106
|
+
`GET /v1/models/{creator}/{model}`, and `GET /v1/models/{id}/endpoints` serve a deterministic
|
|
107
|
+
local catalog in the documented shapes (including per-provider endpoint pricing/uptime/latency
|
|
108
|
+
fields — deterministic simulations of live telemetry).
|
|
109
|
+
|
|
110
|
+
## Scenario scripting (test scaffolding, not vendor surface)
|
|
111
|
+
|
|
112
|
+
Per the anthropic-pack convention, a JSON scenario file can script the exact assistant turns a
|
|
113
|
+
flow under test needs, while the envelope stays vendor-faithful:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
createAiGatewayTwinServer({ scenarioPath: './scenario.json' });
|
|
117
|
+
// or: TWIN_AI_GATEWAY_SCENARIO=./scenario.json | world-ai-gateway serve --scenario ./scenario.json
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Rules match on model / nth call / user text / available tools / tool-result turns and respond
|
|
121
|
+
with text, reasoning, and/or tool calls (verbatim argument payloads; streamed faithfully).
|
|
122
|
+
Malformed scenarios fail startup loudly. Scenario scripting is deliberately **excluded from the
|
|
123
|
+
capability manifest** — counting twin-only scaffolding as vendor coverage would be padding.
|
|
124
|
+
|
|
125
|
+
## Observation and execution
|
|
126
|
+
|
|
127
|
+
`syncAiGatewayFromReal` observes the model catalog and account credits through an injected
|
|
128
|
+
client. The kernel's adapter is `performAiGatewayAction`; inspect its supported operations
|
|
129
|
+
before enabling real execution. Simulated generations are deterministic. Observation of
|
|
130
|
+
catalog or credit data does not itself replay inference or spend model credits.
|
|
131
|
+
See the [shared model](../../../docs/concepts/the-model.md) for the execution boundary.
|
|
132
|
+
|
|
133
|
+
## Coverage
|
|
134
|
+
|
|
135
|
+
The capability manifest (`ai-gateway-capabilities.ts`) enumerates the **real AI Gateway
|
|
136
|
+
surface** (authored top-down from Vercel's AI Gateway docs: the OpenAI-compatible family, the
|
|
137
|
+
Responses/Anthropic-Messages/OpenResponses compatibility APIs, the REST API Reference, provider
|
|
138
|
+
options/filtering/sorting, usage & billing, authentication & BYOK — plus the AI SDK gateway
|
|
139
|
+
protocol at `/v3/ai`, derived from the shipped `@ai-sdk/gateway` SDK) as the honest
|
|
140
|
+
denominator; `verify()` proves each `done` against the local twin, offline + deterministically.
|
|
141
|
+
Run `bun scripts/twin-capabilities.ts ai-gateway` for the live numbers. Coverage is partial and
|
|
142
|
+
honest: the Responses API, Anthropic Messages API, OpenResponses, web search, image/video
|
|
143
|
+
generation, tiered pricing, provider timeouts, bearer-auth enforcement (core todo — the twin
|
|
144
|
+
currently fakes auth), reporting attribution (`providerOptions.gateway.{user,tags}` / the
|
|
145
|
+
`ai-reporting-*` headers), a deterministic 429 rate-limit envelope, report attribution
|
|
146
|
+
groupings, and the `/v3/ai` sub-surfaces the twin does not model yet
|
|
147
|
+
(`/v3/ai/embedding-model`, `/v3/ai/image-model`, `/v3/ai/video-model`, provider-executed
|
|
148
|
+
gateway tools) are open `todo`s, not silent gaps — unmodeled `/v3/ai/*` operations 404 with the
|
|
149
|
+
vendor error envelope rather than faking success. The exact live status code for the
|
|
150
|
+
"no allowed providers available" failure is not documented; the twin uses `400` with a
|
|
151
|
+
`no_available_providers` code and a message naming the allowed providers (the documented
|
|
152
|
+
behavior is "fails with an error indicating the allowed providers").
|
|
153
|
+
|
|
154
|
+
**Out of scope** (each genuinely impossible for a local twin, with reasons in the manifest):
|
|
155
|
+
|
|
156
|
+
- `ai-gateway.chat.real_inference` — real model inference / live provider brokering.
|
|
157
|
+
- `ai-gateway.billing.real_settlement` — real credit purchase/settlement, provider billing, and
|
|
158
|
+
live telemetry values (a deterministic twin-armed 429 rate-limit envelope is NOT carved out —
|
|
159
|
+
it is the open `ai-gateway.limits.rate_limit_429` todo).
|
|
160
|
+
- `ai-gateway.auth.oidc` — Vercel-hosted OIDC token issuance/verification.
|
|
161
|
+
|
|
162
|
+
### No UI mirror
|
|
163
|
+
|
|
164
|
+
The AI Gateway is a vendor whose **product is the API**: integrators call it from code, and the
|
|
165
|
+
Vercel dashboard is incidental tooling for keys, spend monitoring, and logs rather than where
|
|
166
|
+
the work happens. Per [../../../docs/contributing/adding-a-twin.md](../../../docs/contributing/adding-a-twin.md) ("Does this
|
|
167
|
+
vendor get a mirror?") and [../../../docs/contributing/architecture.md](../../../docs/contributing/architecture.md) C1b, this pack ships
|
|
168
|
+
**no React mirror and no UI capabilities** — omit rather than fabricate a dashboard. Coverage
|
|
169
|
+
is API + connector.
|
|
170
|
+
|
|
171
|
+
## CLI
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
world-ai-gateway serve [--port N] [--root DIR] [--read-only] [--scenario FILE]
|
|
175
|
+
world-ai-gateway conformance [--root DIR]
|
|
176
|
+
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CapabilityReport, type CapabilitySpec } from '@volter/world-tooling';
|
|
2
|
+
export declare const AI_GATEWAY_CAPABILITIES: CapabilitySpec[];
|
|
3
|
+
export { AI_GATEWAY_CAPABILITIES as 'AI-GATEWAY_CAPABILITIES' };
|
|
4
|
+
export declare function aiGatewayCapabilities(): Promise<CapabilityReport>;
|