@volter/twin-fireworks 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 +184 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +28 -0
- package/dist/src/fireworks-budget.d.ts +54 -0
- package/dist/src/fireworks-budget.js +146 -0
- package/dist/src/fireworks-capabilities.d.ts +4 -0
- package/dist/src/fireworks-capabilities.js +1205 -0
- package/dist/src/fireworks-conformance.d.ts +14 -0
- package/dist/src/fireworks-conformance.js +514 -0
- package/dist/src/fireworks-connector.d.ts +168 -0
- package/dist/src/fireworks-connector.js +641 -0
- package/dist/src/fireworks-models.d.ts +11 -0
- package/dist/src/fireworks-models.js +53 -0
- package/dist/src/fireworks-scenario.d.ts +55 -0
- package/dist/src/fireworks-scenario.js +171 -0
- package/dist/src/fireworks-server.d.ts +16 -0
- package/dist/src/fireworks-server.js +144 -0
- package/dist/src/fireworks-stub.d.ts +26 -0
- package/dist/src/fireworks-stub.js +78 -0
- package/dist/src/fireworks-twin.d.ts +51 -0
- package/dist/src/fireworks-twin.js +1426 -0
- package/dist/src/fireworks-types.d.ts +212 -0
- package/dist/src/fireworks-types.js +4 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +105 -0
- package/package.json +52 -0
- package/src/cli.ts +27 -0
- package/src/fireworks-budget.ts +172 -0
- package/src/fireworks-capabilities.ts +1229 -0
- package/src/fireworks-conformance.ts +542 -0
- package/src/fireworks-connector.ts +700 -0
- package/src/fireworks-models.ts +63 -0
- package/src/fireworks-scenario.ts +191 -0
- package/src/fireworks-server.ts +153 -0
- package/src/fireworks-stub.ts +83 -0
- package/src/fireworks-twin.ts +1427 -0
- package/src/fireworks-types.ts +165 -0
- package/src/index.ts +134 -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,184 @@
|
|
|
1
|
+
# @volter/twin-fireworks
|
|
2
|
+
|
|
3
|
+
A local, faithful **Fireworks AI** twin your real `fireworks` Python client or
|
|
4
|
+
`@ai-sdk/fireworks` provider talks to **unmodified** — point the client at the twin's host and
|
|
5
|
+
chat completions (OpenAI-compatible + streaming), the legacy completions endpoint, the Responses
|
|
6
|
+
API, the Anthropic-compatible `/v1/messages`, embeddings, rerank, and the stateful Gateway control
|
|
7
|
+
plane (deployments, datasets, batch-inference and supervised-fine-tuning jobs, users/apiKeys,
|
|
8
|
+
secrets, models) all work. Built on the shared `@volter/world-core` kernel; see
|
|
9
|
+
[the model](../../../docs/concepts/the-model.md) for storage and branching; no parallel side store.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createFireworks } from '@ai-sdk/fireworks';
|
|
13
|
+
import { createFireworksTwinServer } from '@volter/twin-fireworks';
|
|
14
|
+
|
|
15
|
+
const { port } = createFireworksTwinServer({});
|
|
16
|
+
// The provider's default baseURL is https://api.fireworks.ai/inference/v1 and it appends
|
|
17
|
+
// /chat/completions to it — the twin serves that same prefix, so "swap the host" is the
|
|
18
|
+
// whole configuration.
|
|
19
|
+
const fireworks = createFireworks({ apiKey: 'fw_twin', baseURL: `http://127.0.0.1:${port}/inference/v1` });
|
|
20
|
+
const result = await generateText({ model: fireworks('accounts/fireworks/models/kimi-k2-instruct'), prompt: 'hello' });
|
|
21
|
+
// result.text starts with "[twin-stub:…]" — a deterministic stub, clearly labeled.
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Fireworks serves **two API planes on one host** (`api.fireworks.ai`), and the twin serves both at
|
|
25
|
+
their real wire prefixes:
|
|
26
|
+
|
|
27
|
+
| plane | prefix | surface |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| inference | **`/inference/v1/…`** | `chat/completions`, `completions`, `responses`, `embeddings`, `rerank`, and the Anthropic-compatible `messages` |
|
|
30
|
+
| control | **`/v1/accounts/{account_id}/…`** | deployments, datasets, batch-inference jobs, supervised fine-tuning jobs, users, apiKeys, secrets, models |
|
|
31
|
+
|
|
32
|
+
The merged spec some clients are generated from publishes the inference operations at `/v1/…`
|
|
33
|
+
with `servers: https://api.fireworks.ai/inference` — same operations, different spelling. The
|
|
34
|
+
twin serves the **real** wire prefix; a request to the bare `/v1/chat/completions` 404s, because
|
|
35
|
+
the real vendor does not serve it either — a twin that answered there would let a mis-configured
|
|
36
|
+
client "work" locally and then fail against the real vendor.
|
|
37
|
+
|
|
38
|
+
## Fireworks is not OpenAI — the differences this twin models
|
|
39
|
+
|
|
40
|
+
The inference plane is *OpenAI-compatible*, and treating "compatible" as "identical" is how a
|
|
41
|
+
Fireworks twin gets built wrong. The load-bearing differences, grounded in Fireworks' own
|
|
42
|
+
published specs (see `specSource` in `src/index.ts`) and docs, read 2026-09-16:
|
|
43
|
+
|
|
44
|
+
| | Fireworks | OpenAI |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| base path | **`https://api.fireworks.ai/inference/v1/…`** | `https://api.openai.com/v1/…` |
|
|
47
|
+
| validation errors | the **FastAPI** envelope: `422` with `{ detail: [{ loc, msg, type }] }` | `{ error: { message, type, param, code } }` with 400 |
|
|
48
|
+
| streaming usage | in the **final chunk's `usage`, by default** (opt out with `stream_options.include_usage: false`) | opt-IN via `stream_options.include_usage` |
|
|
49
|
+
| `service_tier` | **`priority`-only** (plus `auto`); `flex`/`performance` are not Fireworks tiers | a different set |
|
|
50
|
+
| context overflow | modeled as a **request field**: `context_length_exceeded_behavior` (`truncate_left` / `middle_truncate` / `error`) | not a request field |
|
|
51
|
+
| reasoning models | expose **`reasoning_content`** on the message | `reasoning` content blocks |
|
|
52
|
+
| `max_tokens` / `max_completion_tokens` | **cannot both be set** — 400 naming the alias | both accepted |
|
|
53
|
+
| error envelope (inference) | `{ error: { message, … } }` (OpenAI shape) / Anthropic shape on `/v1/messages` | `{ error: { message, type, param, code } }` |
|
|
54
|
+
| error envelope (control) | **google.rpc style**: `{ code: <gatewayCode>, message }` | OpenAI shape |
|
|
55
|
+
| control-plane writes | ids passed via **query params** (`POST …/deployments?deploymentId=x`), custom methods as **verb suffixes** (`:cancel`, `:scale`, `:undelete`, `apiKeys:delete`) | ids in the body; verbs as separate resources |
|
|
56
|
+
| list envelopes | `{ items, nextPageToken, totalSize }` + `pageToken` pagination | `{ data, has_more }` |
|
|
57
|
+
| deletes | answer **`{}`** (empty object), not a `deleted: true` echo | `{ id, deleted }` |
|
|
58
|
+
|
|
59
|
+
## The generative-stub design (be honest)
|
|
60
|
+
|
|
61
|
+
The twin **cannot run the model** — there are no weights here. So `POST /inference/v1/chat/completions`
|
|
62
|
+
returns a **deterministic STUB completion** that is unmistakably a twin stub (it carries a
|
|
63
|
+
`[twin-stub:<model>]` marker and echoes your prompt), `POST /inference/v1/embeddings` returns
|
|
64
|
+
**deterministic pseudo-vectors** (L2-normalized, seeded from the input hash), and `rerank` returns
|
|
65
|
+
**deterministic overlap-biased scores**. They **never** pretend to be real model output.
|
|
66
|
+
|
|
67
|
+
What **is** faithful is the **entire protocol envelope**:
|
|
68
|
+
|
|
69
|
+
- chat response shape — `{ id:'chatcmpl-…', object:'chat.completion', created, model, choices:[{index, message:{role:'assistant', content, reasoning_content?}, logprobs, finish_reason}], usage }`
|
|
70
|
+
- **streaming** via SSE — real `data: {…chat.completion.chunk with choices[].delta…}` chunks ending with `data: [DONE]` (role chunk → reasoning/content deltas → the finish chunk carrying `usage` by default; driven through an injected sink — no real sockets in the handler). The legacy completions stream uses the legacy chunk shape throughout (`object: 'text_completion'`, delta in `choices[].text`, same final-chunk usage default). The Anthropic-compatible `/v1/messages` streams its OWN event sequence (`message_start` → `content_block_delta` → `message_delta` with the real token counts → `message_stop`) and **no `[DONE]` sentinel**
|
|
71
|
+
- **the Responses API** — create (with `store: false` → `id: null`), retrieve, list (`{ data, has_more }`), delete
|
|
72
|
+
- **the Anthropic-compatible messages** — the Anthropic envelope, `max_tokens` optional (Fireworks' difference from Anthropic), `stop_reason`, system as blocks, the Anthropic error shape on both planes' 401
|
|
73
|
+
- `max_tokens` / `max_completion_tokens` (mutually exclusive), `stop` (earliest hit), `response_format` `json_object`, `reasoning_effort` → `reasoning_content`, `context_length_exceeded_behavior`, `service_tier` (`auto`/`priority` only); **deterministic usage**
|
|
74
|
+
- **Embeddings** — `{ object:'list', data:[{object:'embedding', index, embedding}], model, usage }`, `dimensions` parameter, `encoding_format` `float`/`base64`
|
|
75
|
+
- **Rerank** — query-responsive ordering (shared-token overlap), `top_n`, `return_documents`
|
|
76
|
+
|
|
77
|
+
The genuinely **stateful + static** surface is real, not a stub:
|
|
78
|
+
|
|
79
|
+
- **Deployments** — create (id via query param), get, list (paginated), delete (`{}`), undelete (`:undelete`), scale (both the `:scale` POST spelling and the spec's PATCH spelling), read-only-field PATCH tolerated, duplicate-create 409, `baseModel` required
|
|
80
|
+
- **Datasets** — create (body-carried id), lifecycle
|
|
81
|
+
- **Batch-inference jobs** — create (dataset reference validated — the dataset must really exist, 400 otherwise), cancel (`:cancel`), cancel-in-wrong-state refused
|
|
82
|
+
- **Supervised fine-tuning jobs** — create over a dataset that must really exist (400 otherwise)
|
|
83
|
+
- **Users & apiKeys** — role validation, key returned exactly once (create response only — the LIST answers it never), delete via the collection-level `apiKeys:delete` body spelling, cross-user key access refused through both the id-segment and collection-level spellings
|
|
84
|
+
- **Secrets** — `value` never on read, `name`/`keyName` required
|
|
85
|
+
- **Models** — create + list
|
|
86
|
+
|
|
87
|
+
Vendor-shaped errors throughout: `400` / `401` / `404` / `405` (read-only guard) / `409` / `422`
|
|
88
|
+
(FastAPI) / `429` (scripted) — the inference plane in its OpenAI/Anthropic envelopes, the control
|
|
89
|
+
plane in google.rpc `{ code, message }` with the vendor's own `gatewayCode` enum (`NOT_FOUND`,
|
|
90
|
+
`ALREADY_EXISTS`, …). Mixing the planes' envelopes is a wire lie the twin never commits.
|
|
91
|
+
|
|
92
|
+
## Scenario scripting (twin-only)
|
|
93
|
+
|
|
94
|
+
Chat completions can be scripted by MSW-shaped handlers in a world dir's `handlers/fireworks.json`,
|
|
95
|
+
run by the ONE kernel scenario engine with this pack's adapter:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{ "handlers": [
|
|
99
|
+
{ "on": { "userTextIncludes": "refund" },
|
|
100
|
+
"respond": { "text": "Refund queued." }, "once": true },
|
|
101
|
+
{ "on": { "modelEndsWith": "kimi-k2-instruct" }, "respond": { "error": { "type": "rate_limit_exceeded" } } }
|
|
102
|
+
] }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Load it with `--scenario FILE` / `createFireworksTwinServer({ scenarioPath })` /
|
|
106
|
+
`TWIN_FIREWORKS_SCENARIO`. The read doors `GET /twin` and `GET /twin/scenario` explain and inspect
|
|
107
|
+
it. A malformed file throws **at load**, never a silent fall-back. Scenario support is twin-only
|
|
108
|
+
scaffolding for eval worlds, not vendor surface, so it is deliberately **not** in the capability
|
|
109
|
+
manifest.
|
|
110
|
+
|
|
111
|
+
## CLI
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
world-fireworks serve [--port N] [--root DIR] [--read-only] [--scenario FILE]
|
|
115
|
+
world-fireworks conformance [--root DIR]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Connector (pull / push)
|
|
119
|
+
|
|
120
|
+
`pullFireworksState` folds the real control plane (deployments, datasets, both job families,
|
|
121
|
+
users, apiKeys, secrets, models) into the twin — each collection paginated to exhaustion, so the
|
|
122
|
+
kernel's tombstone sweep marks subjects that vanished remotely as `deleted: true` locally;
|
|
123
|
+
`pushFireworksAction` /
|
|
124
|
+
`pushPendingFireworksActions` push pending local writes (create / delete / scale / undelete) to
|
|
125
|
+
the real API and confirm them by the **vendor's** `_external_id`; `fullSyncFireworks` and
|
|
126
|
+
`syncFireworksFromRemote` are the protocol-2 refresh entry points. All vendor I/O is over an
|
|
127
|
+
**injected executor** (`liveFireworksExecute(apiKey)` live; a fake in tests) — the pack holds no
|
|
128
|
+
key and imports no SDK at runtime. Every live call is charged against the shared kernel
|
|
129
|
+
`RateBudget` **before** it goes out, and the executor refuses any path outside
|
|
130
|
+
`/inference/v1/` and `/v1/accounts/`. Fireworks publishes no scalar request limit and no
|
|
131
|
+
header a cooldown could arm on, so the declaration is pinned at the kernel fallback and buys
|
|
132
|
+
resolution **downward** (inference endpoints cost 6 → at most 10 per window); see
|
|
133
|
+
`fireworks-budget.ts` for the full reasoning.
|
|
134
|
+
|
|
135
|
+
## Coverage
|
|
136
|
+
|
|
137
|
+
The capability manifest (`fireworks-capabilities.ts`) enumerates the **real Fireworks API
|
|
138
|
+
surface** as the honest denominator, enumerated top-down from the five first-party OpenAPI specs
|
|
139
|
+
(see `specSource`) plus `docs.fireworks.ai` (read 2026-09-16); `verify()` proves each `done`
|
|
140
|
+
against the local twin, offline + deterministically. Run
|
|
141
|
+
`bun scripts/twin-capabilities.ts fireworks` for the live numbers.
|
|
142
|
+
|
|
143
|
+
Coverage is **partial and honest**: the served protocol envelopes are enumerated and proven, but
|
|
144
|
+
whole product areas are modeled only as gaps — the serverless model catalog and its rate limits,
|
|
145
|
+
account quotas, the dataset-upload extra, the fine-tuning lifecycle (create→READY with training
|
|
146
|
+
progression), per-request response ids, per-request chat completions inside batch outputs (the
|
|
147
|
+
batch OUTPUT surface is unmodeled entirely — jobs stay in their early state), and the image
|
|
148
|
+
generation surface the `@ai-sdk/fireworks` provider reaches (`/image_generation/{model}` legacy
|
|
149
|
+
and the async workflows pair) are all `todo`.
|
|
150
|
+
|
|
151
|
+
### Done (proven, verifiable)
|
|
152
|
+
- **Chat Completions** — create + faithful envelope, the labeled stub, FastAPI 422 validation,
|
|
153
|
+
the `max_tokens`/`max_completion_tokens` mutual exclusion, `service_tier` priority-only,
|
|
154
|
+
`context_length_exceeded_behavior`, `stop`, `max_tokens` length finish, `reasoning_content`,
|
|
155
|
+
`json_object` response format
|
|
156
|
+
- **Streaming** — the chunk sequence, usage on the final chunk **by default** (the Fireworks
|
|
157
|
+
difference) with `include_usage: false` opting out, the pre-stream refusal answering a real
|
|
158
|
+
status (never a 200 event stream)
|
|
159
|
+
- **Legacy completions** — create, prompt arrays, streaming in the legacy chunk shape (usage on the final chunk by default, `include_usage: false` opting out)
|
|
160
|
+
- **Responses API** — create + retrieve, `store: false` → `id: null`, delete, the list envelope
|
|
161
|
+
- **Anthropic-compatible messages** — the Anthropic envelope, `max_tokens` optional,
|
|
162
|
+
`stop_reason`, the Anthropic error envelope, streaming, system as blocks (priced into
|
|
163
|
+
`input_tokens`, echoed when the user content is whitespace)
|
|
164
|
+
- **Embeddings** — create, L2-normalized vectors, `dimensions`, array input
|
|
165
|
+
- **Rerank** — create, query-responsive ordering, `top_n` + `return_documents`
|
|
166
|
+
- **Auth** — missing key, invalid key, any non-empty key accepted, the Anthropic plane gated with
|
|
167
|
+
its OWN error envelope
|
|
168
|
+
- **Errors** — unknown-path 404, the scripted 429
|
|
169
|
+
- **Deployments** — create (query-param id), get, list, pagination, delete (`{}`), delete-then-404,
|
|
170
|
+
read-only-field PATCH, undelete, scale (both spellings), duplicate 409, `baseModel` required
|
|
171
|
+
- **Datasets / Batch jobs / SFT / Users / apiKeys / Secrets / Models** — as listed above
|
|
172
|
+
- **Connector** — control-plane pull, refusal-is-not-emptiness, pull idempotency, push create with
|
|
173
|
+
query params, push delete by the vendor's `_external_id`, inference ops never pushed, request
|
|
174
|
+
shapes, full sync, the live client's unmodeled-path refusal
|
|
175
|
+
- **Conformance** — one real probe per claimed endpoint plus the hand-authored router census
|
|
176
|
+
|
|
177
|
+
### No UI mirror
|
|
178
|
+
|
|
179
|
+
**The API is the product.** When someone does Fireworks' core job they write code against the
|
|
180
|
+
inference API or the Gateway control plane; the Fireworks console is incidental tooling for API
|
|
181
|
+
keys, usage dashboards and deployments — not where the work happens. Per the contributor recipe's
|
|
182
|
+
"Does this vendor get a mirror?" rule (and ../../../docs/contributing/architecture.md C1b), this
|
|
183
|
+
pack therefore ships **no mirror and no UI capabilities**; coverage is API + connector. This
|
|
184
|
+
matches the sibling generative packs (`openai`, `anthropic`, `gemini`, `groq`).
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { keepProcessAlive } from '@volter/world-core/lifecycle';
|
|
3
|
+
// world-fireworks CLI: serve the Fireworks AI twin or run conformance. Fireworks is an
|
|
4
|
+
// API-first vendor — its console is a deployments/usage dashboard, not where the work happens
|
|
5
|
+
// — so this pack ships no mirror.
|
|
6
|
+
import { hasFlag, optionValue } from '@volter/world-core/args';
|
|
7
|
+
import { createFireworksTwinServer } from "./fireworks-server.js";
|
|
8
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
9
|
+
const port = Number(optionValue(rest, '--port', '0')) || undefined;
|
|
10
|
+
const root = optionValue(rest, '--root') || undefined;
|
|
11
|
+
const readOnly = hasFlag(rest, '--read-only'); // a twin accepts writes unless started read-only
|
|
12
|
+
const scenario = optionValue(rest, '--scenario') || undefined; // scripted responses (JSON file)
|
|
13
|
+
if (cmd === 'serve') {
|
|
14
|
+
const s = await createFireworksTwinServer({ readOnly, ...(root ? { root } : {}), ...(port ? { port } : {}), ...(scenario ? { scenarioPath: scenario } : {}) });
|
|
15
|
+
process.stdout.write(`fireworks twin (Gateway control plane at /v1/accounts/{account_id}; inference at /inference/v1)${readOnly ? ' [read-only]' : ''}${scenario ? ` [scenario: ${scenario}]` : ''} at http://127.0.0.1:${s.port}\n`);
|
|
16
|
+
await keepProcessAlive();
|
|
17
|
+
}
|
|
18
|
+
else if (cmd === 'conformance') {
|
|
19
|
+
// dev-only; lazy so the bin runs without @volter/world-tooling
|
|
20
|
+
const { checkFireworksConformance } = await import("./fireworks-conformance.js");
|
|
21
|
+
const report = await checkFireworksConformance({ ...(root ? { root } : {}) });
|
|
22
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
23
|
+
if (!report.ok)
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
process.stdout.write('Usage: world-fireworks serve|conformance [--port N] [--root DIR] [--read-only] [--scenario FILE]\n');
|
|
28
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RateBudget, type RateBudgetDeclaration, type RateBudgetOptions, type RateBudgetReservation, type RateBudgetSnapshot } from '@volter/world-core';
|
|
2
|
+
/** Rolling window, in ms. Spend older than this is pruned. */
|
|
3
|
+
export declare const FIREWORKS_BUDGET_WINDOW_MS = 60000;
|
|
4
|
+
/**
|
|
5
|
+
* Weighted units allowed inside one window. 60/60s at `defaultWeight` 2 = 30 calls a minute —
|
|
6
|
+
* EXACTLY the kernel's undeclared fallback, because Fireworks publishes no scalar that would
|
|
7
|
+
* justify more. See the header.
|
|
8
|
+
*/
|
|
9
|
+
export declare const FIREWORKS_BUDGET_CEILING = 60;
|
|
10
|
+
/** Seconds. A `retry-after` above this means the key is throttled hard — fail loudly, don't sleep. */
|
|
11
|
+
export declare const FIREWORKS_BUDGET_MAX_RETRY_AFTER_S = 300;
|
|
12
|
+
/** Per-call cost, keyed by `"<METHOD> <path>"`. See the header for what is documented vs. judged. */
|
|
13
|
+
export declare const FIREWORKS_CALL_WEIGHTS: {
|
|
14
|
+
/** The token-metered inference surface: `/inference/v1/chat/completions`,
|
|
15
|
+
* `/inference/v1/completions`, `/inference/v1/responses`, `/inference/v1/embeddings`,
|
|
16
|
+
* `/inference/v1/rerank` and `/inference/v1/messages`. Every published TPM metric (Total
|
|
17
|
+
* Prompt, Uncached Prompt, Generated) is about exactly this traffic. At 60/6 = 10 per window —
|
|
18
|
+
* a deliberate tightening below the fallback's 30, since Fireworks publishes no request-rate
|
|
19
|
+
* figure at all. */
|
|
20
|
+
readonly inference: 6;
|
|
21
|
+
/** Everything else: Gateway control-plane CRUD (deployments, datasets, fine-tuning jobs, …). */
|
|
22
|
+
readonly other: 2;
|
|
23
|
+
};
|
|
24
|
+
/** THE PACK'S DECLARATION — pure data, the only Fireworks-specific thing in the whole budget. */
|
|
25
|
+
export declare const FIREWORKS_RATE_BUDGET: RateBudgetDeclaration;
|
|
26
|
+
/**
|
|
27
|
+
* Price one call. The key is `"<METHOD> <path>"` with the query string split off, so a rule can
|
|
28
|
+
* price by method (a write is not a read) without the kernel knowing anything about Fireworks. An
|
|
29
|
+
* unclassified endpoint still costs `defaultWeight` — nothing is ever free.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fireworksCallWeight(method: string, path: string): number;
|
|
32
|
+
/** Where Fireworks' ledger lives. Token-keyed and cwd-independent by default (Fireworks' limits
|
|
33
|
+
* are per ACCOUNT, i.e. per key, so a cwd-scoped ledger would hand the same key a fresh allowance
|
|
34
|
+
* in every checkout, worktree and CI matrix leg); pass `root` for world-scoped accounting. */
|
|
35
|
+
export declare function fireworksBudgetPath(opts?: {
|
|
36
|
+
root?: string;
|
|
37
|
+
token?: string;
|
|
38
|
+
} | string): string;
|
|
39
|
+
/** Construction options for Fireworks' budget. The vendor is fixed; everything else may only TIGHTEN. */
|
|
40
|
+
export type FireworksBudgetOptions = Omit<RateBudgetOptions, 'vendor'>;
|
|
41
|
+
/**
|
|
42
|
+
* Fireworks' budget — the shared kernel guard bound to this vendor's declaration. A real subclass,
|
|
43
|
+
* not an alias, so `budget instanceof FireworksBudget` in `liveFireworksExecute` means "a budget
|
|
44
|
+
* that accounts against FIREWORKS' ledger under FIREWORKS' ceiling".
|
|
45
|
+
*/
|
|
46
|
+
export declare class FireworksBudget extends RateBudget {
|
|
47
|
+
constructor(opts?: FireworksBudgetOptions);
|
|
48
|
+
}
|
|
49
|
+
/** The typed refusal. One error class shared with every other vendor's budget; `err.vendor` says
|
|
50
|
+
* which one refused, and `err.kind` says why. */
|
|
51
|
+
export { RateBudgetError as FireworksBudgetError } from '@volter/world-core';
|
|
52
|
+
export type { RateBudgetErrorKind as FireworksBudgetErrorKind } from '@volter/world-core';
|
|
53
|
+
export type FireworksBudgetReservation = RateBudgetReservation;
|
|
54
|
+
export type FireworksBudgetSnapshot = RateBudgetSnapshot;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Fireworks' CLIENT-SIDE RATE BUDGET — the pack's DECLARATION (the numbers) plus the thin typed
|
|
2
|
+
// bindings `liveFireworksExecute` uses. The MECHANISM — the durable token-keyed ledger, the rolling
|
|
3
|
+
// window, reserve-under-lock, the `Retry-After`/429 cooldown, fail-CLOSED on a corrupt ledger —
|
|
4
|
+
// lives ONCE in the vendor-agnostic kernel (`@volter/world-core` → `rateBudget.ts`). Read that
|
|
5
|
+
// module's header for the full rationale AND for the honest list of what the guard does not
|
|
6
|
+
// guarantee.
|
|
7
|
+
//
|
|
8
|
+
// ── WHY THIS EXISTS ─────────────────────────────────────────────────────────────────────────
|
|
9
|
+
// A real ~4.5-DAY vendor lockout (Figma, 2026-07-25) happened because raw API calls were made
|
|
10
|
+
// outside the pack's connector — no cache, no batching, no ceiling. Discipline only binds the code
|
|
11
|
+
// that follows it; a BUDGET binds the code that does not.
|
|
12
|
+
//
|
|
13
|
+
// ── HOW THE CEILING WAS CHOSEN (live-read, 2026-09-16) ───────────────────────────────────────
|
|
14
|
+
// https://docs.fireworks.ai/serverless/rate-limits (read 2026-09-16) publishes NO scalar per-key
|
|
15
|
+
// request limit a client could be bound by. Fireworks meters THREE token-per-minute metrics —
|
|
16
|
+
// Total Prompt TPM, Uncached Prompt TPM and Generated TPM — each "per account and per model", and
|
|
17
|
+
// the ceilings are ADAPTIVE: an account's allowance scales within its size tier based on recent
|
|
18
|
+
// usage, so the only place the real numbers live is the account's own dashboard. The docs also
|
|
19
|
+
// state rate-limit headers are not currently returned, so there is no response-derived backstop
|
|
20
|
+
// signal to bind.
|
|
21
|
+
//
|
|
22
|
+
// So this declaration does not model Fireworks' limit, and nothing here is more permissive than
|
|
23
|
+
// the kernel's undeclared fallback: window 60s, ceiling 60, defaultWeight 2 — i.e. 30 calls/minute,
|
|
24
|
+
// EXACTLY `DEFAULT_RATE_BUDGET`, with no endpoint priced cheaper than the fallback would price it.
|
|
25
|
+
// What the declaration buys is RESOLUTION, and it deliberately buys it DOWNWARD: the inference
|
|
26
|
+
// endpoints (the token-metered ones — every TPM metric above is about inference traffic) cost 6,
|
|
27
|
+
// so at most TEN of them land in a window. Being stricter than the fallback needs no vendor
|
|
28
|
+
// justification; being looser would, and there is none to have.
|
|
29
|
+
//
|
|
30
|
+
// It bounds the 60s AVERAGE; it does not pace (the kernel refuses, it never sleeps). The backstop
|
|
31
|
+
// for a sub-second burst is the `Retry-After`/429 cooldown, and it is the ONLY backstop. Fireworks
|
|
32
|
+
// DOES document rate-limit response headers — `X-Ratelimit-Limit-Tokens-Prompt`,
|
|
33
|
+
// `X-Ratelimit-Limit-Tokens-Cache-Adjusted-Prompt`, `X-Ratelimit-Limit-Tokens-Generated` — but they
|
|
34
|
+
// carry TOKEN CEILING values, not a remaining-count or a retry-after, so none of them is a signal
|
|
35
|
+
// the kernel's cooldown can arm on. Unlike the groq declaration there is no header-derived
|
|
36
|
+
// cooldown trigger: only a real 429 (or an explicit `Retry-After`) can arm it.
|
|
37
|
+
//
|
|
38
|
+
// ── HOW THE WEIGHTS WERE CHOSEN (and what is a judgement call) ───────────────────────────────
|
|
39
|
+
// • The inference endpoints cost 6: all THREE published TPM metrics are about inference traffic,
|
|
40
|
+
// so one chat/completions/embeddings/rerank request consumes far more of the account's real
|
|
41
|
+
// allowance than a deployments list poll. 60/6 = 10 per window is a deliberate tightening,
|
|
42
|
+
// not a matched published figure — Fireworks publishes no RPM at all.
|
|
43
|
+
// • Everything else (control-plane CRUD on the Gateway REST surface) costs 2 — the fallback's
|
|
44
|
+
// own default.
|
|
45
|
+
import { declareRateBudget, rateBudgetPath, rateBudgetWeight, RateBudget, } from '@volter/world-core';
|
|
46
|
+
const VENDOR = 'fireworks';
|
|
47
|
+
/** Rolling window, in ms. Spend older than this is pruned. */
|
|
48
|
+
export const FIREWORKS_BUDGET_WINDOW_MS = 60_000;
|
|
49
|
+
/**
|
|
50
|
+
* Weighted units allowed inside one window. 60/60s at `defaultWeight` 2 = 30 calls a minute —
|
|
51
|
+
* EXACTLY the kernel's undeclared fallback, because Fireworks publishes no scalar that would
|
|
52
|
+
* justify more. See the header.
|
|
53
|
+
*/
|
|
54
|
+
export const FIREWORKS_BUDGET_CEILING = 60;
|
|
55
|
+
/** Seconds. A `retry-after` above this means the key is throttled hard — fail loudly, don't sleep. */
|
|
56
|
+
export const FIREWORKS_BUDGET_MAX_RETRY_AFTER_S = 300;
|
|
57
|
+
/** Per-call cost, keyed by `"<METHOD> <path>"`. See the header for what is documented vs. judged. */
|
|
58
|
+
export const FIREWORKS_CALL_WEIGHTS = {
|
|
59
|
+
/** The token-metered inference surface: `/inference/v1/chat/completions`,
|
|
60
|
+
* `/inference/v1/completions`, `/inference/v1/responses`, `/inference/v1/embeddings`,
|
|
61
|
+
* `/inference/v1/rerank` and `/inference/v1/messages`. Every published TPM metric (Total
|
|
62
|
+
* Prompt, Uncached Prompt, Generated) is about exactly this traffic. At 60/6 = 10 per window —
|
|
63
|
+
* a deliberate tightening below the fallback's 30, since Fireworks publishes no request-rate
|
|
64
|
+
* figure at all. */
|
|
65
|
+
inference: 6,
|
|
66
|
+
/** Everything else: Gateway control-plane CRUD (deployments, datasets, fine-tuning jobs, …). */
|
|
67
|
+
other: 2,
|
|
68
|
+
};
|
|
69
|
+
/** THE PACK'S DECLARATION — pure data, the only Fireworks-specific thing in the whole budget. */
|
|
70
|
+
export const FIREWORKS_RATE_BUDGET = {
|
|
71
|
+
windowMs: FIREWORKS_BUDGET_WINDOW_MS,
|
|
72
|
+
ceiling: FIREWORKS_BUDGET_CEILING,
|
|
73
|
+
defaultWeight: FIREWORKS_CALL_WEIGHTS.other,
|
|
74
|
+
maxRetryAfterSeconds: FIREWORKS_BUDGET_MAX_RETRY_AFTER_S,
|
|
75
|
+
rules: [
|
|
76
|
+
{ match: '^POST /inference/v1/(chat/completions|completions|responses|embeddings|rerank|messages)$', weight: FIREWORKS_CALL_WEIGHTS.inference },
|
|
77
|
+
],
|
|
78
|
+
reason: 'Fireworks publishes NO scalar per-key request limit (docs.fireworks.ai/serverless/rate-limits, ' +
|
|
79
|
+
'read 2026-09-16): it meters THREE token-per-minute metrics — Total Prompt TPM, Uncached Prompt ' +
|
|
80
|
+
'TPM and Generated TPM — each per account AND per model, with ADAPTIVE ceilings that scale within ' +
|
|
81
|
+
"a size tier based on recent usage, so the real numbers live only on the account's dashboard. " +
|
|
82
|
+
'Its documented rate-limit response headers (X-Ratelimit-Limit-Tokens-Prompt / ' +
|
|
83
|
+
'-Cache-Adjusted-Prompt / -Generated) carry TOKEN CEILING values, not a remaining count or a ' +
|
|
84
|
+
'retry-after, so no header is a signal the cooldown can arm on. Because no published figure ' +
|
|
85
|
+
'justifies going higher, the ceiling is pinned at the kernel fallback in EVERY dimension — ' +
|
|
86
|
+
'60 units / 60s at defaultWeight 2 = 30 calls/min — and the declaration buys resolution ' +
|
|
87
|
+
'DOWNWARD, never headroom: the inference endpoints cost 6, so at most 10 land in a window. ' +
|
|
88
|
+
'The window bounds the 60s AVERAGE and does not pace; the `retry-after`/429 cooldown is the ' +
|
|
89
|
+
'only sub-second-burst backstop.',
|
|
90
|
+
};
|
|
91
|
+
// Declared at module load, so merely importing this module (which `fireworks-connector.ts` does) is
|
|
92
|
+
// enough to arm the real ceiling.
|
|
93
|
+
declareRateBudget(VENDOR, FIREWORKS_RATE_BUDGET);
|
|
94
|
+
/**
|
|
95
|
+
* Price one call. The key is `"<METHOD> <path>"` with the query string split off, so a rule can
|
|
96
|
+
* price by method (a write is not a read) without the kernel knowing anything about Fireworks. An
|
|
97
|
+
* unclassified endpoint still costs `defaultWeight` — nothing is ever free.
|
|
98
|
+
*/
|
|
99
|
+
export function fireworksCallWeight(method, path) {
|
|
100
|
+
const { bare, query } = splitQuery(path);
|
|
101
|
+
// UPPER-CASE the method: `fetch` normalizes a known lowercase method before sending, so
|
|
102
|
+
// `execute('post', …)` really does issue a POST and must be priced as one.
|
|
103
|
+
return rateBudgetWeight(VENDOR, `${String(method).toUpperCase()} ${bare}`, query);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `/v1/x?a=1` -> `{ bare: '/v1/x', query: { a: '1' } }`. Rules match the path; `whenQuery*` the
|
|
107
|
+
* query. NORMALIZED, because the anchored rules are otherwise trivially evaded: `fetch` upper-cases
|
|
108
|
+
* a known method before sending, so `execute('post', …)` issues a real WRITE that a `^POST ` rule
|
|
109
|
+
* would price as a read; and a trailing slash makes a path miss a `$` anchor while most routers
|
|
110
|
+
* treat it as the same endpoint.
|
|
111
|
+
*/
|
|
112
|
+
function splitQuery(path) {
|
|
113
|
+
const at = path.indexOf('?');
|
|
114
|
+
const query = {};
|
|
115
|
+
if (at !== -1)
|
|
116
|
+
for (const [k, v] of new URLSearchParams(path.slice(at + 1)))
|
|
117
|
+
query[k] = v;
|
|
118
|
+
// Collapse REPEATED slashes as well as a trailing one: `/inference/v1//chat/completions` reaches
|
|
119
|
+
// the same endpoint on most routers but misses a `^POST /inference/v1/(chat/completions|…)$` rule,
|
|
120
|
+
// which would price an inference call as a 2-unit read.
|
|
121
|
+
const raw = (at === -1 ? path : path.slice(0, at)).replace(/\/{2,}/g, '/');
|
|
122
|
+
const bare = raw.length > 1 && raw.endsWith('/') ? raw.replace(/\/+$/, '') : raw;
|
|
123
|
+
return { bare, query };
|
|
124
|
+
}
|
|
125
|
+
/** Where Fireworks' ledger lives. Token-keyed and cwd-independent by default (Fireworks' limits
|
|
126
|
+
* are per ACCOUNT, i.e. per key, so a cwd-scoped ledger would hand the same key a fresh allowance
|
|
127
|
+
* in every checkout, worktree and CI matrix leg); pass `root` for world-scoped accounting. */
|
|
128
|
+
export function fireworksBudgetPath(opts = {}) {
|
|
129
|
+
const o = typeof opts === 'string' ? { root: opts } : opts;
|
|
130
|
+
// VENDOR spread LAST: a loosely-typed `{ vendor: 'other', … }` slipping through (TypeScript's
|
|
131
|
+
// excess-property check only catches object literals) must not redirect this pack's ledger.
|
|
132
|
+
return rateBudgetPath({ ...o, vendor: VENDOR });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Fireworks' budget — the shared kernel guard bound to this vendor's declaration. A real subclass,
|
|
136
|
+
* not an alias, so `budget instanceof FireworksBudget` in `liveFireworksExecute` means "a budget
|
|
137
|
+
* that accounts against FIREWORKS' ledger under FIREWORKS' ceiling".
|
|
138
|
+
*/
|
|
139
|
+
export class FireworksBudget extends RateBudget {
|
|
140
|
+
constructor(opts = {}) {
|
|
141
|
+
super({ ...opts, vendor: VENDOR });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** The typed refusal. One error class shared with every other vendor's budget; `err.vendor` says
|
|
145
|
+
* which one refused, and `err.kind` says why. */
|
|
146
|
+
export { RateBudgetError as FireworksBudgetError } from '@volter/world-core';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CapabilityReport, type CapabilitySpec } from '@volter/world-tooling';
|
|
2
|
+
export declare const FIREWORKS_CAPABILITIES: CapabilitySpec[];
|
|
3
|
+
export declare const FIREWORKS_AREAS: readonly ["account", "apiKeys", "auth", "batch_inference", "chat", "completions", "conformance", "control", "connector", "datasets", "deployments", "embeddings", "errors", "fine_tuning", "image_generation", "messages", "models", "quota", "rerank", "responses", "secrets", "serverless", "streaming", "users"];
|
|
4
|
+
export declare function fireworksCapabilities(): Promise<CapabilityReport>;
|