@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.
Files changed (39) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +184 -0
  3. package/dist/src/cli.d.ts +2 -0
  4. package/dist/src/cli.js +28 -0
  5. package/dist/src/fireworks-budget.d.ts +54 -0
  6. package/dist/src/fireworks-budget.js +146 -0
  7. package/dist/src/fireworks-capabilities.d.ts +4 -0
  8. package/dist/src/fireworks-capabilities.js +1205 -0
  9. package/dist/src/fireworks-conformance.d.ts +14 -0
  10. package/dist/src/fireworks-conformance.js +514 -0
  11. package/dist/src/fireworks-connector.d.ts +168 -0
  12. package/dist/src/fireworks-connector.js +641 -0
  13. package/dist/src/fireworks-models.d.ts +11 -0
  14. package/dist/src/fireworks-models.js +53 -0
  15. package/dist/src/fireworks-scenario.d.ts +55 -0
  16. package/dist/src/fireworks-scenario.js +171 -0
  17. package/dist/src/fireworks-server.d.ts +16 -0
  18. package/dist/src/fireworks-server.js +144 -0
  19. package/dist/src/fireworks-stub.d.ts +26 -0
  20. package/dist/src/fireworks-stub.js +78 -0
  21. package/dist/src/fireworks-twin.d.ts +51 -0
  22. package/dist/src/fireworks-twin.js +1426 -0
  23. package/dist/src/fireworks-types.d.ts +212 -0
  24. package/dist/src/fireworks-types.js +4 -0
  25. package/dist/src/index.d.ts +9 -0
  26. package/dist/src/index.js +105 -0
  27. package/package.json +52 -0
  28. package/src/cli.ts +27 -0
  29. package/src/fireworks-budget.ts +172 -0
  30. package/src/fireworks-capabilities.ts +1229 -0
  31. package/src/fireworks-conformance.ts +542 -0
  32. package/src/fireworks-connector.ts +700 -0
  33. package/src/fireworks-models.ts +63 -0
  34. package/src/fireworks-scenario.ts +191 -0
  35. package/src/fireworks-server.ts +153 -0
  36. package/src/fireworks-stub.ts +83 -0
  37. package/src/fireworks-twin.ts +1427 -0
  38. package/src/fireworks-types.ts +165 -0
  39. package/src/index.ts +134 -0
@@ -0,0 +1,168 @@
1
+ import type { PerformContext, PushOutcome, RemoteExecute, SyncResource, TwinAction } from '@volter/world-core';
2
+ import { FireworksBudget, fireworksBudgetPath, type FireworksBudgetOptions } from './fireworks-budget.js';
3
+ /** The account every Gateway REST path is addressed under when no caller (or subject namespace)
4
+ * supplies one. The vendor keys every control-plane path by account id; the twin models one
5
+ * default account, and the perform path derives the account from the SUBJECT's own namespace
6
+ * first, falling back to this constant only for a bare id. */
7
+ export declare const FIREWORKS_ACCOUNT_ID = "my-account";
8
+ /**
9
+ * The injected real-Fireworks boundary. `request` issues ONE Fireworks REST call against either
10
+ * plane:
11
+ * method — 'GET' | 'POST' | 'PATCH' | 'DELETE'
12
+ * path — e.g. '/inference/v1/chat/completions' or
13
+ * '/v1/accounts/{account_id}/deployments?deploymentId=my-deployment'
14
+ * body — JSON body for POST/PATCH (omitted otherwise)
15
+ * Returns the parsed JSON envelope (an OpenAI-compat completion, a gateway list envelope, or an
16
+ * error shape).
17
+ */
18
+ export type FireworksExecute = (method: 'GET' | 'POST' | 'PATCH' | 'DELETE', path: string, body?: Record<string, unknown>) => Promise<{
19
+ status: number;
20
+ data: unknown;
21
+ }>;
22
+ /** Construction options for the live executor. `budget` cannot be null and cannot be loosened. */
23
+ export type LiveFireworksOptions = {
24
+ /** Injected `fetch`, so a test can COUNT the requests the guard did or did not let through. */
25
+ fetchImpl?: typeof fetch;
26
+ /** An existing budget to share across executors. Omit and one is constructed. Cannot be null. */
27
+ budget?: FireworksBudget;
28
+ /** Construction options for the default budget (ledger path, clock). Cannot loosen it. */
29
+ budgetOptions?: FireworksBudgetOptions;
30
+ };
31
+ /**
32
+ * A live executor against the real Fireworks API (the user's own API key). Sends the required
33
+ * `Authorization: Bearer` header. Never imported by the pack's own serve path — only constructed
34
+ * by a caller that opts into real I/O.
35
+ *
36
+ * THIS IS THE ONE PLACE this pack issues a live `api.fireworks.ai` request, and therefore the one
37
+ * place the rate budget is enforced. EVERY call is guarded: the budget is charged BEFORE the
38
+ * request goes out (`checkBudget`, which THROWS `FireworksBudgetError` instead of returning when
39
+ * the ceiling or a cooldown says stop) and the response is fed back (`recordCall`) so a
40
+ * `retry-after` / 429 becomes a persisted cooldown that makes every later call fail fast WITHOUT
41
+ * touching Fireworks. There is deliberately no OPTION to disable the guard, and no value a caller
42
+ * can pass for `budget` that yields an unguarded client. What that does NOT claim is immunity from
43
+ * a caller who WANTS one: a fresh `budgetOptions.path` per construction, or an injected clock,
44
+ * restores the allowance, because the same seam tests need cannot be denied to a determined caller
45
+ * in the same process. See `fireworks-budget.ts` and the kernel header for the limits of the
46
+ * guarantee.
47
+ */
48
+ export declare function liveFireworksExecute(apiKey: string, base?: string, opts?: LiveFireworksOptions): FireworksExecute;
49
+ /** Map one gateway deployment row → a twin sync resource. Vendor `name` is
50
+ * `accounts/{account}/deployments/{id}`; the twin keys the resource by the id segment. */
51
+ export declare function mapDeployment(d: Record<string, unknown>): SyncResource;
52
+ export declare function mapDataset(ds: Record<string, unknown>): SyncResource;
53
+ export declare function mapBatchInferenceJob(j: Record<string, unknown>): SyncResource;
54
+ export declare function mapSupervisedFineTuningJob(j: Record<string, unknown>): SyncResource;
55
+ export declare function mapUser(u: Record<string, unknown>): SyncResource;
56
+ export declare function mapModel(m: Record<string, unknown>): SyncResource;
57
+ /** Secrets never carry their value on a list read (the vendor redacts it), so the map stores the
58
+ * metadata only — mirroring the vendor's own read surface. */
59
+ export declare function mapSecret(s: Record<string, unknown>): SyncResource;
60
+ /** Fetch the account's control-plane state through the injected client and map to SyncResource[]
61
+ * (no fold). `accountId` scopes every list; a missing/failed list throws — a REFUSED pull is NOT
62
+ * an empty account, and folding an empty list over real observed state would tombstone it. */
63
+ export declare function pullFireworksState(execute: FireworksExecute, accountId: string): Promise<SyncResource[]>;
64
+ /**
65
+ * D7 consumer-facing pull entry point: gather all Fireworks control-plane read domains and fold
66
+ * them into the twin through a SINGLE observed batch, returning the standard result shape.
67
+ * Idempotent: a re-pull of identical state appends no new deltas.
68
+ */
69
+ export declare function syncFireworksFromReal(execute: FireworksExecute, opts?: {
70
+ accountId: string;
71
+ root?: string;
72
+ occurredAt?: string;
73
+ }): Promise<{
74
+ observed: number;
75
+ deltasAppended: number;
76
+ }>;
77
+ /** Why this operation cannot be pushed to the real vendor, or null if it can. Pure — no vendor
78
+ * call on its path. Inference operations are the big class: replaying a completion at the vendor
79
+ * spends real money and stores nothing, so a push of one is a category error, not a gap. */
80
+ export declare function unpushableReason(op: string): string | null;
81
+ /**
82
+ * The REST (method, path, body) that CONFIRMS one local action against the real Gateway REST
83
+ * surface. Create ids go where the vendor's spec puts them (query params for deployments/users,
84
+ * the body for the rest). A locally-minted id on anything but a create is REFUSED — the twin's
85
+ * own mint is not an address the vendor knows.
86
+ */
87
+ export declare function fireworksRequestForAction(action: Pick<TwinAction, 'operation' | 'subject' | 'fields'>, accountId: string, opts?: {
88
+ externalId?: string;
89
+ }): {
90
+ method: 'POST' | 'DELETE';
91
+ path: string;
92
+ body?: Record<string, unknown>;
93
+ };
94
+ /**
95
+ * Push ONE pending action to REAL Fireworks via the injected executor. Returns the real external
96
+ * id (the vendor's own id from the create response's `name`, or the addressed id on delete).
97
+ * WRITES TO THE REAL ACCOUNT.
98
+ */
99
+ export declare function pushFireworksAction(execute: FireworksExecute, action: Pick<TwinAction, 'operation' | 'subject' | 'fields'>, accountId: string, opts?: {
100
+ externalId?: string;
101
+ }): Promise<{
102
+ externalId: string;
103
+ }>;
104
+ /**
105
+ * Push the twin's PENDING local actions to real Fireworks and CONFIRM each. Idempotent: a
106
+ * confirmed action is no longer pending, so a re-push enacts NOTHING.
107
+ *
108
+ * An action this connector cannot faithfully push is SKIPPED AND REPORTED, never confirmed and
109
+ * never silently dropped: it stays pending and is named in `refused`. A create's real id is
110
+ * recorded on the resource as `_external_id` at confirm time, so a later delete addresses the
111
+ * VENDOR by it — never the twin's own mint.
112
+ */
113
+ export declare function pushPendingFireworksActions(execute: FireworksExecute, opts: {
114
+ accountId: string;
115
+ root?: string;
116
+ occurredAt?: string;
117
+ }): Promise<{
118
+ pushed: number;
119
+ confirmed: string[];
120
+ externalIds: Record<string, string>;
121
+ refused: Array<{
122
+ actionId: string;
123
+ operation: string;
124
+ reason: string;
125
+ }>;
126
+ }>;
127
+ /**
128
+ * FULL bi-directional sync over the injected client: (1) PUSH every pending local action to real
129
+ * Fireworks and confirm it, then (2) PULL the control-plane collections back and fold them into
130
+ * the event log. Pushing first means the pull observes the twin's own writes as confirmed external
131
+ * state (no double-count). Re-running with no pending writes and identical real state is a no-op.
132
+ */
133
+ export declare function fullSyncFireworks(execute: FireworksExecute, opts: {
134
+ accountId: string;
135
+ root?: string;
136
+ occurredAt?: string;
137
+ }): Promise<{
138
+ pushed: number;
139
+ observed: number;
140
+ deltasAppended: number;
141
+ collections: number;
142
+ refused: Array<{
143
+ actionId: string;
144
+ operation: string;
145
+ reason: string;
146
+ }>;
147
+ }>;
148
+ /** A `FireworksExecute` over the kernel's executor — the adapter seam protocol 2 fixes. */
149
+ export declare function fireworksExecuteOver(execute: RemoteExecute): FireworksExecute;
150
+ /** The refresh adapter: pull the account's control-plane collections. `origin` is unused —
151
+ * Fireworks' surface is single-host, so the executor's own base URL is the address. */
152
+ export declare function syncFireworksFromRemote(execute: RemoteExecute, opts?: {
153
+ root?: string;
154
+ origin?: string;
155
+ occurredAt?: string;
156
+ accountId?: string;
157
+ }): Promise<{
158
+ observed: number;
159
+ deltasAppended: number;
160
+ }>;
161
+ /**
162
+ * The perform adapter — the head's executor for a local write at a REAL boundary. Create/delete
163
+ * replay against the Gateway REST surface through `ctx.resolve` (a locally minted subject is
164
+ * addressed by the vendor id the projection recorded, never by the mint). Inference operations and
165
+ * custom verbs are NOT performed: they are the twin's own record, and the outcome says so.
166
+ */
167
+ export declare function performFireworksAction(execute: RemoteExecute, action: TwinAction, ctx: PerformContext): Promise<PushOutcome>;
168
+ export { fireworksBudgetPath };