@genex-ai/embed-sdk 0.30.0 → 0.31.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/README.md CHANGED
@@ -235,6 +235,38 @@ approval window passes, `pending` with `error: 'wait_timeout'` when the SDK
235
235
  stopped waiting (the sheet may still be open), and `failed` with a server code.
236
236
  The successful result carries `grantId` and the full server `grant` view.
237
237
 
238
+ **One live budget per player per game, and the newest approval wins.** Genex
239
+ never runs two budgets of one game for one player (per payment door). If you
240
+ ask while one is already running, the Genex sheet tells the player before they
241
+ approve that the new budget replaces the running one (and what it has used);
242
+ approving it stops the old budget and starts the new one in one step. Calls
243
+ the old budget already started still finish and are charged to it; a game
244
+ still holding the old id is refused `grant_stopped`, and `getSpendGrant(oldId)`
245
+ reads `stopped` with `stopReason: 'replaced'`. So don't ask every session —
246
+ reuse the running budget first (SDK **0.31.0+**):
247
+
248
+ ```ts
249
+ import { getActiveSpendGrant } from '@genex-ai/embed-sdk';
250
+
251
+ // On boot, or after `grant_stopped`: the player's live budget in THIS game.
252
+ const running = await getActiveSpendGrant(); // RuntimeGrantView | null
253
+ if (running) grantId = running.id;
254
+ else grantId = (await requestSpendGrant(budgetRequest)).grantId; // from a click
255
+ ```
256
+
257
+ `getActiveSpendGrant()` (SDK **0.31.0+**) returns the same view as
258
+ `getSpendGrant(id)`, or `null` when the player has no live budget in this game.
259
+ "Live" means it can run calls now or once its reason clears (`active`,
260
+ `suspended_insufficient_funds`, `waiting_for_plan`); a stopped, expired or
261
+ used-up budget is `null`, like one that never existed. It is scoped by the
262
+ player's token to this player and this game, so it never finds another game's
263
+ budget or another player's. A guest rejects with `no_player_session`, and any
264
+ other refusal rejects with the server's code, like `getSpendGrant()`. It is a
265
+ read: it never asks the player anything, so a game may call it on boot with no
266
+ click behind it — and, since only `requestSpendGrant()` needs a click, the one
267
+ prompt a returning player sees is the one their running budget does not cover. The development lane (`@genex-ai/embed-sdk/development`) has
268
+ no budgets, so there is no counterpart there.
269
+
238
270
  `generate({ grantId })` runs one call under that budget. It opens **no window,
239
271
  posts no parent message and needs no user gesture**, so it works from a game
240
272
  loop or a timer. Every other guard is unchanged: the published game (or its
@@ -257,8 +289,8 @@ those at 0). Poll it on the
257
289
  cadence your HUD needs — never derive the remaining budget from your own count
258
290
  of calls, and never show a figure the server did not send. Store `grantId` the
259
291
  way you store a `generationId`; `getSpendGrant()` recovers the budget after a
260
- reload, and a budget whose status is no longer live simply needs a new
261
- approval. `stopSpendGrant(id)` releases it when your feature ends. Stopping is
292
+ reload, `getActiveSpendGrant()` finds it when the id is lost, and a budget
293
+ whose status is no longer live simply needs a new approval. `stopSpendGrant(id)` releases it when your feature ends. Stopping is
262
294
  prospective: calls already started finish and are charged. The player has the
263
295
  same lever on Genex, on every page, and theirs always outranks the game's.
264
296
 
@@ -285,7 +317,7 @@ the game should have believable copy for each:
285
317
  `credits_unverified` (verify the email on Genex), `generation_paused` (Genex
286
318
  paused paid generation; retry later),
287
319
  `waiting_for_plan` (a personal plan's own rate limit; it resumes by itself),
288
- `grant_price_unreasonable`, `grant_already_active`, `external_grant_active` and
320
+ `grant_price_unreasonable`, `external_grant_active` and
289
321
  `invalid_grant_limit`. `generationErrorMessage(code)` returns a player-facing
290
322
  sentence for every one of these and for every one-time code as well; show it, or
291
323
  write your own in-fiction line keyed off the same code. Never show the raw code,
@@ -262,7 +262,11 @@ async function request(path, body) {
262
262
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
263
263
  });
264
264
  const result = await response.json().catch(() => ({}));
265
- if (!response.ok) throw new Error(typeof result.error === "string" ? result.error : "generation_unavailable");
265
+ if (!response.ok) {
266
+ const error = new Error(typeof result.error === "string" ? result.error : "generation_unavailable");
267
+ error.status = response.status;
268
+ throw error;
269
+ }
266
270
  return result;
267
271
  }
268
272
  function validEstimateCoins(value) {
@@ -473,7 +477,8 @@ function invalidGrantOptions(options) {
473
477
  function grantOutcome(view) {
474
478
  if (LIVE_GRANT_STATUSES.includes(view.status)) return { status: "active", grantId: view.id, grant: view };
475
479
  switch (view.status) {
476
- // The player closing the sheet, or stopping later, is a normal outcome.
480
+ // The player closing the sheet, or stopping later, is a normal outcome —
481
+ // whatever reason the server recorded for the stop.
477
482
  case "stopped":
478
483
  return { status: "canceled", grantId: view.id, grant: view };
479
484
  case "expired":
@@ -490,6 +495,16 @@ function getSpendGrant(grantId) {
490
495
  if (!isGrantId(grantId)) return Promise.reject(new Error("invalid_grant_id"));
491
496
  return request(`/grants/${encodeURIComponent(grantId)}`);
492
497
  }
498
+ async function getActiveSpendGrant() {
499
+ try {
500
+ const view = await request("/grants/current");
501
+ if (!isGrantId(view.id)) throw new Error("invalid_grant_response");
502
+ return view;
503
+ } catch (error) {
504
+ if (error.status === 404) return null;
505
+ throw error;
506
+ }
507
+ }
493
508
  function stopSpendGrant(grantId) {
494
509
  if (!isGrantId(grantId)) return Promise.reject(new Error("invalid_grant_id"));
495
510
  return request(`/grants/${encodeURIComponent(grantId)}/stop`, {});
@@ -917,7 +932,7 @@ var RETRY_FLAG = "genex:embed:retry";
917
932
  var POPOVER_DISMISSED_FLAG = "genex:guest:popover-dismissed";
918
933
  var LOCAL_AUTH_FLAG = "genex:embed:local-auth";
919
934
  var PLAYER_ID_KEY = "genex:player";
920
- var SDK_VERSION = "0.30.0";
935
+ var SDK_VERSION = "0.31.0";
921
936
  var config2 = null;
922
937
  var state = "pending";
923
938
  var user = null;
@@ -935,6 +950,7 @@ var redeeming = false;
935
950
  var requestingGuest = false;
936
951
  var identityEpoch = 0;
937
952
  var handshakeTimeoutMs = 1e4;
953
+ var standaloneWatchdogGraceMs = 2e3;
938
954
  var refreshDelayMs = 10 * 6e4;
939
955
  var refreshRetryMs = 6e4;
940
956
  var overlayTextDelayMs = 500;
@@ -1609,7 +1625,7 @@ function armStandaloneWatchdog() {
1609
1625
  handshakeTimer = setTimeout(() => {
1610
1626
  handshakeTimer = void 0;
1611
1627
  if (state === "pending") enterBlocked("no-identity");
1612
- }, handshakeTimeoutMs);
1628
+ }, handshakeTimeoutMs + standaloneWatchdogGraceMs);
1613
1629
  }
1614
1630
  var stashedTicketHash = null;
1615
1631
  function _stashTicketFromUrl() {
@@ -2269,6 +2285,7 @@ function __resetForTests(overrides) {
2269
2285
  hasPendingPlayerSave = false;
2270
2286
  pendingScores.clear();
2271
2287
  handshakeTimeoutMs = overrides?.handshakeTimeoutMs ?? 1e4;
2288
+ standaloneWatchdogGraceMs = overrides?.standaloneWatchdogGraceMs ?? 2e3;
2272
2289
  refreshDelayMs = overrides?.refreshDelayMs ?? 10 * 6e4;
2273
2290
  refreshRetryMs = overrides?.refreshRetryMs ?? 6e4;
2274
2291
  overlayTextDelayMs = overrides?.overlayTextDelayMs ?? 500;
@@ -2289,6 +2306,7 @@ export {
2289
2306
  requestWorkflow,
2290
2307
  resumeWorkflow,
2291
2308
  getSpendGrant,
2309
+ getActiveSpendGrant,
2292
2310
  stopSpendGrant,
2293
2311
  requestSpendGrant,
2294
2312
  generateStream,
@@ -1,4 +1,4 @@
1
- import { RuntimeJudgeQuestion, RuntimeWorkflowInput, RuntimeGenerationView } from '@genex/embed-protocol';
1
+ import { R as RuntimeJudgeQuestion, a as RuntimeWorkflowInput, b as RuntimeGenerationView } from './runtime-generation-B3oFDmCp.js';
2
2
 
3
3
  /**
4
4
  * Server-only benchmarks spend the authenticated creator's OWN CREDITS
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { RuntimeJudgeQuestion, RuntimeJudgeAnswer, RuntimeJudgmentView, RuntimeWorkflowInput, RuntimeGenerationBilling, RuntimeGenerationFunding, RuntimeGrantView, RuntimeGenerationView, RuntimeGenerationModels, RuntimeWorkflowOfferings } from '@genex/embed-protocol';
2
- export { RuntimeBillingPolicy, RuntimeCurrency, RuntimeExternalProvider, RuntimeGenerationBilling, RuntimeGenerationFunding, RuntimeGenerationModels, RuntimeGenerationStatus, RuntimeGenerationStreamEvent, RuntimeGenerationView, RuntimeGrantJudgeTerms, RuntimeGrantStatus, RuntimeGrantTerms, RuntimeGrantView, RuntimeJudgeAnswer, RuntimeJudgeCriterion, RuntimeJudgeQuestion, RuntimeJudgmentView, RuntimeWorkflowInput, RuntimeWorkflowOfferings } from '@genex/embed-protocol';
1
+ import { R as RuntimeJudgeQuestion, c as RuntimeJudgeAnswer, d as RuntimeJudgmentView, a as RuntimeWorkflowInput, e as RuntimeGenerationBilling, f as RuntimeGenerationFunding, g as RuntimeGrantView, b as RuntimeGenerationView, h as RuntimeGenerationModels, i as RuntimeWorkflowOfferings } from './runtime-generation-B3oFDmCp.js';
2
+ export { j as RuntimeBillingPolicy, k as RuntimeCurrency, l as RuntimeExternalProvider, m as RuntimeGenerationStatus, n as RuntimeGenerationStreamEvent, o as RuntimeGrantJudgeTerms, p as RuntimeGrantStatus, q as RuntimeGrantTerms, r as RuntimeJudgeCriterion } from './runtime-generation-B3oFDmCp.js';
3
3
 
4
4
  /** A thing the game sells. Resolved server-side; the game never sets a price. */
5
5
  interface ShopItem {
@@ -290,10 +290,25 @@ interface SpendGrantResult {
290
290
  grantId?: string;
291
291
  /** The authoritative server view: limit, spend, counts and the frozen terms. */
292
292
  grant?: RuntimeGrantView;
293
+ /** Why a `failed` result failed, as a code for generationErrorMessage(). */
293
294
  error?: string;
294
295
  }
295
296
  /** Read a budget: limit, spend, calls and status. Scoped to this player AND this game. */
296
297
  declare function getSpendGrant(grantId: string): Promise<RuntimeGrantView>;
298
+ /**
299
+ * This player's live budget in this game, or `null` when there is none (0.31.0).
300
+ *
301
+ * Genex keeps ONE live budget per player per game, and a newer approval
302
+ * replaces it — so a game that already has one running (after a reload, in a
303
+ * new session, or after losing the id requestSpendGrant() gave it) reuses it
304
+ * here instead of asking the player to approve another. "Live" means it can
305
+ * run calls now or once its reason clears (an empty wallet, the player's own
306
+ * plan asking to wait); a stopped, expired or used-up budget is not returned.
307
+ * Scoped by the player's token to this player AND this game. Rejects like the
308
+ * other budget helpers (`no_player_session` for a guest, the server's code
309
+ * otherwise); only "none" is `null`.
310
+ */
311
+ declare function getActiveSpendGrant(): Promise<RuntimeGrantView | null>;
297
312
  /**
298
313
  * Release a budget when the feature that needed it ends. Stopping is
299
314
  * PROSPECTIVE: calls already started finish and are charged. The player has the
@@ -309,6 +324,11 @@ declare function stopSpendGrant(grantId: string): Promise<RuntimeGrantView>;
309
324
  * Resolves `active` once the budget can serve calls; pass its `grantId` to
310
325
  * generate() from then on. A player who closes the sheet resolves `canceled`.
311
326
  * Store the id: getSpendGrant(id) recovers the budget after a reload.
327
+ *
328
+ * Genex keeps one live budget per player per game, and the newest approval
329
+ * REPLACES the running one (the sheet tells the player so before they
330
+ * approve). So ask getActiveSpendGrant() first: a game that reuses the running
331
+ * budget does not ask the player again every session.
312
332
  */
313
333
  declare function requestSpendGrant(options: SpendGrantOptions): Promise<SpendGrantResult>;
314
334
  interface GenerateStreamOptions extends GenerateOptions {
@@ -779,6 +799,7 @@ declare function listEvents<T = unknown>(stream: string, opts?: {
779
799
  declare function _stashTicketFromUrl(): void;
780
800
  declare function __resetForTests(overrides?: {
781
801
  handshakeTimeoutMs?: number;
802
+ standaloneWatchdogGraceMs?: number;
782
803
  refreshDelayMs?: number;
783
804
  refreshRetryMs?: number;
784
805
  overlayTextDelayMs?: number;
@@ -786,4 +807,4 @@ declare function __resetForTests(overrides?: {
786
807
  heartbeatIntervalMs?: number;
787
808
  }): void;
788
809
 
789
- export { type AppendEventResult, type AuthState, type DeleteSharedResult, type EmbedConfig, type EmbedEvent, type EmbedUser, type Entitlement, type GenerateOptions, type GenerateStreamOptions, type JudgeOptions, type JudgeResult, type Leaderboard, type LeaderboardEntry, type PlayerStateResult, type PurchaseResult, type PurchaseStatus, type PutSharedResult, type RequestWorkflowOptions, type RuntimeGenerationResult, type RuntimeWorkflowAuthorization, type SaveStateResult, type SharedEventPage, type SharedEventRecord, type SharedObject, type SharedObjectInfo, type SharedPage, type ShopItem, type SpendGrantDisclosure, type SpendGrantOptions, type SpendGrantResult, type SubmitScoreResult, type WorldStateResult, __resetForTests, _stashTicketFromUrl, appendEvent, buy, consumeEntitlement, deleteShared, generate, generateStream, generationErrorMessage, getAuthState, getColyseusAuth, getColyseusUrls, getEmbedToken, getEntitlements, getGeneration, getGenerationModels, getLeaderboard, getShared, getShop, getSpendGrant, getUser, getWorkflowOfferings, initEmbed, isEmbedded, judge, listEvents, listShared, loadPlayerState, loadWorldState, on, putShared, requestSpendGrant, requestWorkflow, resumeWorkflow, savePlayerState, saveWorldState, stopSpendGrant, submitScore, waitForAuth, waitForGeneration, waitForPlayer };
810
+ export { type AppendEventResult, type AuthState, type DeleteSharedResult, type EmbedConfig, type EmbedEvent, type EmbedUser, type Entitlement, type GenerateOptions, type GenerateStreamOptions, type JudgeOptions, type JudgeResult, type Leaderboard, type LeaderboardEntry, type PlayerStateResult, type PurchaseResult, type PurchaseStatus, type PutSharedResult, type RequestWorkflowOptions, RuntimeGenerationBilling, RuntimeGenerationFunding, RuntimeGenerationModels, type RuntimeGenerationResult, RuntimeGenerationView, RuntimeGrantView, RuntimeJudgeAnswer, RuntimeJudgeQuestion, RuntimeJudgmentView, type RuntimeWorkflowAuthorization, RuntimeWorkflowInput, RuntimeWorkflowOfferings, type SaveStateResult, type SharedEventPage, type SharedEventRecord, type SharedObject, type SharedObjectInfo, type SharedPage, type ShopItem, type SpendGrantDisclosure, type SpendGrantOptions, type SpendGrantResult, type SubmitScoreResult, type WorldStateResult, __resetForTests, _stashTicketFromUrl, appendEvent, buy, consumeEntitlement, deleteShared, generate, generateStream, generationErrorMessage, getActiveSpendGrant, getAuthState, getColyseusAuth, getColyseusUrls, getEmbedToken, getEntitlements, getGeneration, getGenerationModels, getLeaderboard, getShared, getShop, getSpendGrant, getUser, getWorkflowOfferings, initEmbed, isEmbedded, judge, listEvents, listShared, loadPlayerState, loadWorldState, on, putShared, requestSpendGrant, requestWorkflow, resumeWorkflow, savePlayerState, saveWorldState, stopSpendGrant, submitScore, waitForAuth, waitForGeneration, waitForPlayer };
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  generate,
9
9
  generateStream,
10
10
  generationErrorMessage,
11
+ getActiveSpendGrant,
11
12
  getAuthState,
12
13
  getColyseusAuth,
13
14
  getColyseusUrls,
@@ -40,7 +41,7 @@ import {
40
41
  waitForAuth,
41
42
  waitForGeneration,
42
43
  waitForPlayer
43
- } from "./chunk-NGNVGLPV.js";
44
+ } from "./chunk-QNZZIJGP.js";
44
45
  import "./chunk-MJPLBT3T.js";
45
46
  export {
46
47
  __resetForTests,
@@ -52,6 +53,7 @@ export {
52
53
  generate,
53
54
  generateStream,
54
55
  generationErrorMessage,
56
+ getActiveSpendGrant,
55
57
  getAuthState,
56
58
  getColyseusAuth,
57
59
  getColyseusUrls,
@@ -0,0 +1,536 @@
1
+ type RuntimeGenerationStatus = 'requires_confirmation' | 'queued' | 'dispatching' | 'awaiting_external' | 'succeeded' | 'failed' | 'unknown' | 'canceled' | 'expired';
2
+ /**
3
+ * Who pays. `credits` is the player's Genex credits — every quote and budget
4
+ * issued since 2026-09-25. `coins` is the dormant coin path: a quote or budget
5
+ * issued before then, settling under its frozen terms. `claude` / `chatgpt` is
6
+ * the player's own plan, answered by their watcher, free to Genex.
7
+ */
8
+ type RuntimeGenerationFunding = 'coins' | 'credits' | 'claude' | 'chatgpt';
9
+ /** The wallet a quote or a budget is written in. */
10
+ type RuntimeCurrency = 'coins' | 'credits';
11
+ /**
12
+ * `metered-credits-v1` is how every in-game call is billed now: its real
13
+ * provider cost × (1 + the platform fee), in credits — a one-time call or a
14
+ * workflow captures that rounded UP to a whole credit when it settles; a call
15
+ * under a budget accrues it on the budget's meter, and the player's credits
16
+ * move one whole credit at a time. `standing-credits-v1` is a STANDING BUDGET
17
+ * paid that way (its judge calls included).
18
+ *
19
+ * The coin policies are the dormant path, for quotes and budgets issued before
20
+ * credits: `declared-v1` a fixed coin price per started attempt, `consumed-v1`
21
+ * a coin charge for consumed work, `standing-v1` / `standing-judge-v1` a coin
22
+ * budget, and `metered-v1` its judge calls on a coin meter.
23
+ */
24
+ type RuntimeBillingPolicy = 'consumed-v1' | 'declared-v1' | 'standing-v1' | 'standing-judge-v1' | 'metered-v1' | 'metered-credits-v1' | 'standing-credits-v1';
25
+ /** One option of a `choice`: a description, or a sharper one with its opposite and examples. */
26
+ type RuntimeJudgeCriterion = string | {
27
+ what: string;
28
+ not_for?: string;
29
+ examples?: string[];
30
+ };
31
+ /**
32
+ * A question for the judge. `choice` picks one of up to 255 named options,
33
+ * `score` places the state on a 2–10 level scale, `noul` is a yes/no with a
34
+ * probability. Every text field is at most 2000 characters.
35
+ */
36
+ type RuntimeJudgeQuestion = {
37
+ type: 'choice';
38
+ instructions: string;
39
+ criteria: Record<string, RuntimeJudgeCriterion>;
40
+ } | {
41
+ type: 'score';
42
+ instructions: string;
43
+ criteria: string[];
44
+ } | {
45
+ type: 'noul';
46
+ instructions: string;
47
+ criteria?: {
48
+ true: string;
49
+ false: string;
50
+ };
51
+ };
52
+ /** One answer, of the type its question asked. Probabilities are 0–1. */
53
+ type RuntimeJudgeAnswer = {
54
+ type: 'choice';
55
+ choice: string;
56
+ probabilities: Record<string, number>;
57
+ confidence?: number;
58
+ } | {
59
+ type: 'score';
60
+ score: number;
61
+ probabilities: Record<string, number>;
62
+ confidence?: number;
63
+ legend?: unknown;
64
+ } | {
65
+ type: 'noul';
66
+ noul: number;
67
+ };
68
+ /** The judge door's answer: the call, its answers, and where its money went. */
69
+ interface RuntimeJudgmentView {
70
+ generationId: string;
71
+ grantId: string | null;
72
+ /** `dispatching` only on a replay of a call still running. */
73
+ status: 'succeeded' | 'failed' | 'unknown' | 'canceled' | 'dispatching';
74
+ /** One answer per question asked; present only on `succeeded`. */
75
+ answers?: Record<string, RuntimeJudgeAnswer>;
76
+ error?: string;
77
+ billing: {
78
+ /** `metered-credits-v1` on a credit budget; `metered-v1` on a coin one. */
79
+ billingPolicy: 'metered-v1' | 'metered-credits-v1';
80
+ billingStatus: 'pending' | 'final';
81
+ /** A metered call never charges a unit of its own — its budget's meter does. */
82
+ chargedCoins: 0;
83
+ /** Absent on a stand that predates credits. */
84
+ chargedCredits?: 0;
85
+ /** USD pico-dollars as decimal strings: the provider's reported cost (null
86
+ * when the outcome is unknown) and what the call added to the meter,
87
+ * tariff included (the quoted maximum for an unknown outcome). */
88
+ costUsdPicos: string | null;
89
+ chargedUsdPicos: string | null;
90
+ /** The budget's meter, in whole units of its currency. On a credit meter
91
+ * the credit fields carry the numbers and the coin ones are 0. */
92
+ meter?: {
93
+ status: 'open' | 'closed';
94
+ currency?: RuntimeCurrency;
95
+ accruedUsdPicos: string;
96
+ coinUsdPicos: string;
97
+ reservedCoins: number;
98
+ capturedCoins: number;
99
+ creditUsdPicos?: string;
100
+ reservedCredits?: number;
101
+ capturedCredits?: number;
102
+ };
103
+ };
104
+ grant?: {
105
+ status: RuntimeGrantStatus;
106
+ spentCoins: number;
107
+ heldCoins: number;
108
+ remainingCoins: number;
109
+ spentCredits?: number;
110
+ heldCredits?: number;
111
+ remainingCredits?: number;
112
+ };
113
+ createdAt: string;
114
+ completedAt?: string;
115
+ }
116
+ /**
117
+ * Execution may be terminal while unresolved provider expense still holds money.
118
+ * A credit row carries its numbers in the credit fields and 0 in the coin ones
119
+ * (kept for readers written before credits); a coin row the reverse. The USD
120
+ * fields are beside whichever unit the row is in. A call under a credit budget
121
+ * holds and charges nothing itself — its budget's meter does (`metered`).
122
+ */
123
+ interface RuntimeGenerationBilling {
124
+ billingStatus?: 'pending' | 'final';
125
+ currency?: RuntimeCurrency;
126
+ reservedCoins?: number;
127
+ reservedDisplayUsdCents?: number;
128
+ chargedCoins?: number;
129
+ chargedDisplayUsdCents?: number;
130
+ /** The most the call can move, in whole credits: billed as used, up to this. */
131
+ maxCredits?: number;
132
+ reservedCredits?: number;
133
+ chargedCredits?: number;
134
+ }
135
+ interface RuntimeExternalProvider {
136
+ id: 'claude' | 'chatgpt';
137
+ label: string;
138
+ connectorUrl: string;
139
+ openUrl?: string;
140
+ }
141
+ interface RuntimeWorkflowInput {
142
+ operation: 'create' | 'refactor';
143
+ description: string;
144
+ bundleId: string;
145
+ creatureId?: string;
146
+ revisionDigest?: string;
147
+ }
148
+ interface RuntimeWorkflowOfferings {
149
+ workflowId: string;
150
+ version: string;
151
+ projectId: string;
152
+ usdCentsPerCoin: number;
153
+ /** Which wallet this workflow bills — its executor's registration decides.
154
+ * Absent on a stand that predates credits (coin). */
155
+ currency?: RuntimeCurrency;
156
+ usdCentsPerCredit?: number;
157
+ offerings: {
158
+ id: string;
159
+ bundleId: string;
160
+ modelId: string;
161
+ label: string;
162
+ mode: string;
163
+ funding: RuntimeGenerationFunding;
164
+ free: boolean;
165
+ estimatedModelUsd: string;
166
+ /** The operator-registered margin. Under `metered-credits-v1` it is served
167
+ * unchanged and prices nothing: a credit workflow is billed its real cost
168
+ * × (1 + `feeBps`). */
169
+ priceMultiplier: 2 | 3;
170
+ billingPolicy: RuntimeBillingPolicy;
171
+ currency?: RuntimeCurrency;
172
+ /** Credit offerings: the indicative estimate and the most one request can
173
+ * move, in whole credits, and the fee they are billed at. */
174
+ estimatedCredits?: number;
175
+ maxCredits?: number;
176
+ feeBps?: number;
177
+ estimatedCoins: number;
178
+ estimatedDisplayUsdCents: number;
179
+ maxCoins: number;
180
+ maxPriceDisplayUsdCents: number;
181
+ /** Compatibility aliases for the indicative estimate, never the maximum. */
182
+ priceCoins: number;
183
+ priceDisplayUsdCents: number;
184
+ available: boolean;
185
+ }[];
186
+ externalProviders: RuntimeExternalProvider[];
187
+ }
188
+ interface RuntimeGenerationView extends RuntimeGenerationBilling {
189
+ id: string;
190
+ status: RuntimeGenerationStatus;
191
+ funding: null | RuntimeGenerationFunding;
192
+ projectId: string | null;
193
+ gameName: string;
194
+ /** The game's ADDRESS — a project is addressed by slug wherever a person can
195
+ * click it, and `projectId` is not that. Present only on the surfaces that
196
+ * link out (today the player's activity listing), so a reader must treat
197
+ * its absence as "do not link", never as "the game has no page". */
198
+ gameSlug?: string;
199
+ /** Which build asked. `staging` is a TEST build (`genex preview`), which
200
+ * only the game's owner can generate on — charged exactly like the
201
+ * published game. Absent on a stand older than the tag and on development
202
+ * rows; read absence as "the published game". */
203
+ channel?: 'production' | 'staging';
204
+ modelId: string;
205
+ /** For a judge call, the game's state as JSON text. */
206
+ prompt: string;
207
+ outputFormat: 'text' | 'json' | 'judge';
208
+ schema?: Record<string, unknown>;
209
+ /** A judge call's questions. */
210
+ questions?: Record<string, RuntimeJudgeQuestion>;
211
+ /** A `metered-v1` call's receipt (pico-dollar decimal strings). Absent on other rows. */
212
+ metered?: {
213
+ costUsdPicos: string | null;
214
+ chargedUsdPicos: string | null;
215
+ };
216
+ quote: {
217
+ id: string;
218
+ maxCoins: number;
219
+ /** USD equivalent of the quote's maximum (maxCoins, or maxCredits on a
220
+ * credit quote), never the indicative estimate. */
221
+ priceDisplayUsdCents: number;
222
+ expiresAt: string;
223
+ /** Absent means the legacy promise stored with this quote. */
224
+ billingPolicy?: RuntimeBillingPolicy;
225
+ estimatedCoins?: number;
226
+ estimatedDisplayUsdCents?: number;
227
+ /** A credit quote (`metered-credits-v1`): billed as used, up to `maxCredits`,
228
+ * at `feeBps` over the real cost; `maxCoins` is 0. */
229
+ currency?: RuntimeCurrency;
230
+ maxCredits?: number;
231
+ estimatedCredits?: number;
232
+ feeBps?: number;
233
+ } & ({
234
+ kind?: 'metered';
235
+ estimatedModelUsd?: string;
236
+ priceMultiplier?: 2 | 3;
237
+ } | {
238
+ kind: 'fixed';
239
+ estimatedModelUsd?: string;
240
+ priceMultiplier?: 2 | 3;
241
+ priceCoins: number;
242
+ });
243
+ kind?: 'workflow';
244
+ /** Workflow cancellation is draining provider calls; billing is not settled yet. */
245
+ stopping?: boolean;
246
+ workflow?: {
247
+ id: string;
248
+ offeringId: string;
249
+ bundleId: string;
250
+ operation: 'create' | 'refactor';
251
+ executorId: string;
252
+ validatorVersion: string;
253
+ };
254
+ /** Funding choices are frozen by the server quote; confirmation selects exactly one. */
255
+ allowedFunding?: RuntimeGenerationFunding[];
256
+ externalProvider?: RuntimeExternalProvider;
257
+ externalProviders?: RuntimeExternalProvider[];
258
+ /** Personal submissions do not prove which model or subscription produced them. */
259
+ modelProvenance?: 'unverified';
260
+ development?: boolean;
261
+ /** Development-only actual provider cost and unresolved exposure. Token
262
+ * counts are what the provider REPORTED, never inferred. The fields after
263
+ * `unknownProviderUsdPicos` are optional because a stand that predates them
264
+ * does not send them. */
265
+ usage?: {
266
+ costUsdPicos: string | null;
267
+ costUsd: number | null;
268
+ maxProviderUsdPicos: string;
269
+ unknownProviderUsdPicos: string;
270
+ /** Provider-reported input and output tokens (output includes reasoning); null when none was reported. */
271
+ inputTokens?: number | null;
272
+ outputTokens?: number | null;
273
+ /** This call's own `max_tokens`, funded from its declared ceiling. */
274
+ maxOutputTokens?: number;
275
+ /** The smallest declared price whose funded `max_tokens` holds this answer
276
+ * plus the server's headroom — the declared price also decides how long
277
+ * the answer may be. Null when the length is unknown, the answer was cut
278
+ * off, or no price fits. */
279
+ fitCoins?: number | null;
280
+ /** A CREDIT row's fit: the smallest per-call ceiling, in whole credits,
281
+ * whose funded `max_tokens` holds this answer plus the headroom. */
282
+ fitCredits?: number | null;
283
+ /** No price fits on this stand: the answer is longer than one call may produce. */
284
+ fitExceedsCap?: boolean;
285
+ /** The answer was cut off (`provider_token_limit`), so its true length is unknown. */
286
+ truncated?: boolean;
287
+ };
288
+ /** The provider's own words beside `error`, sanitized (no key shapes, one
289
+ * line, at most 300 characters). DEVELOPMENT ROWS ONLY — the builder is
290
+ * the payer of their own benchmark; a player-facing view never carries it,
291
+ * because it can name providers and internal detail. */
292
+ providerMessage?: string;
293
+ /** Whether this row currently counts against its concurrency cap. Carried
294
+ * only by the development listing (`GET …/development/projects/:id/generations`):
295
+ * a settled row, and a pending bill whose dispatch is no longer recent, hold
296
+ * no slot even while the pending bill still holds its coin. */
297
+ slotHeld?: boolean;
298
+ allowExternal: boolean;
299
+ output?: unknown;
300
+ source?: 'openrouter' | 'external' | 'typesafe';
301
+ error?: string;
302
+ /** The SERVER's clock: when the player asked, when the provider call actually
303
+ * started, and when it stopped running. Measure elapsed from these rather
304
+ * than from when a client first saw the row — that invents a duration for
305
+ * anything already in flight when a page loaded. Optional because a stand
306
+ * older than they are simply omits them. */
307
+ createdAt?: string;
308
+ dispatchedAt?: string;
309
+ completedAt?: string;
310
+ /** Set when a standing budget admitted this call instead of a popup. */
311
+ grantId?: string;
312
+ /** A local watcher is answering personal-plan work for this player right now. */
313
+ watcherOnline?: boolean;
314
+ }
315
+ type RuntimeGrantStatus = 'requires_confirmation' | 'active' | 'suspended_insufficient_funds' | 'waiting_for_plan' | 'exhausted' | 'stopped' | 'expired';
316
+ /**
317
+ * The judge's terms on a budget, frozen with it. `estimatedCallsPerPeriod` is
318
+ * the GAME's estimate; `worstCaseCoinsPerPeriod` is the SERVER's — every one of
319
+ * those calls at the largest request the judge door admits, tariff included,
320
+ * rounded up to whole coins. Show them attributed that way.
321
+ */
322
+ interface RuntimeGrantJudgeTerms {
323
+ enabled: true;
324
+ modelId: string;
325
+ /** `metered-credits-v1` on a credit budget; `metered-v1` on a coin one. */
326
+ billingPolicy: 'metered-v1' | 'metered-credits-v1';
327
+ estimatedCallsPerPeriod: number;
328
+ /** A coin budget's worst case; 0 on a credit budget. */
329
+ worstCaseCoinsPerPeriod: number;
330
+ /** A credit budget's worst case, in whole credits. */
331
+ worstCaseCreditsPerPeriod?: number;
332
+ }
333
+ /** Frozen at creation and read off the grant forever; live config never decides a spend. */
334
+ interface RuntimeGrantTerms {
335
+ /** `standing-credits-v1` for every budget quoted since 2026-09-25 (judge or
336
+ * not); `standing-v1` / `standing-judge-v1` are the dormant coin budgets. */
337
+ billingPolicy: 'standing-v1' | 'standing-judge-v1' | 'standing-credits-v1';
338
+ /** Absent on a coin budget quoted before credits. */
339
+ currency?: RuntimeCurrency;
340
+ models: string[];
341
+ /** Coin terms: 0 on a credit budget. */
342
+ perCallMaxCoins: number;
343
+ perCallEstimateCoins: number;
344
+ /** Credit terms: the per-call CEILING the player approves, and the game's
345
+ * honest per-call estimate the disclosure is built on — never a price. */
346
+ perCallMaxCredits?: number;
347
+ perCallEstimateCredits?: number;
348
+ maxConcurrent: number;
349
+ maxCallsPerMinute: number;
350
+ maxPendingExternal: number;
351
+ /** The DEVELOPER's estimate. Always shown attributed, never as a Genex figure. */
352
+ disclosure: {
353
+ periodLabel: 'minute' | 'hour' | 'session';
354
+ estimatedCallsPerPeriod: number;
355
+ /** A coin budget's figure; 0 on a credit budget. */
356
+ estimatedCoinsPerPeriod: number;
357
+ estimatedCreditsPerPeriod?: number;
358
+ };
359
+ /** Server-owned slider bounds. A client never decides the range. On a credit
360
+ * budget the credit bounds carry the numbers and the coin ones are 0. */
361
+ limit: {
362
+ minCoins: number;
363
+ maxCoins: number;
364
+ stepCoins: number;
365
+ defaultCoins: number;
366
+ minUsdCents: number;
367
+ maxUsdCents: number;
368
+ stepUsdCents: number;
369
+ minCredits?: number;
370
+ maxCredits?: number;
371
+ stepCredits?: number;
372
+ defaultCredits?: number;
373
+ };
374
+ /** Present when the budget also admits the judge. */
375
+ judge?: RuntimeGrantJudgeTerms;
376
+ }
377
+ interface RuntimeGrantView {
378
+ id: string;
379
+ status: RuntimeGrantStatus;
380
+ funding: null | RuntimeGenerationFunding;
381
+ projectId: string | null;
382
+ gameName: string;
383
+ /** The game's address, on the same terms as `RuntimeGenerationView.gameSlug`. */
384
+ gameSlug?: string;
385
+ /** The build that requested the budget, on the same terms as `RuntimeGenerationView.channel`. */
386
+ channel?: 'production' | 'staging';
387
+ quoteId: string;
388
+ terms: RuntimeGrantTerms;
389
+ allowedFunding: RuntimeGenerationFunding[];
390
+ externalProviders?: RuntimeExternalProvider[];
391
+ usdCentsPerCoin: number;
392
+ /** `credits` on every budget quoted since 2026-09-25. Absent on an older stand. */
393
+ currency?: RuntimeCurrency;
394
+ /** Coin funding. `heldCoins` is admitted work not settled yet. 0 on a credit budget. */
395
+ limitCoins: number;
396
+ limitDisplayUsdCents: number;
397
+ spentCoins: number;
398
+ spentDisplayUsdCents: number;
399
+ heldCoins: number;
400
+ remainingCoins: number;
401
+ /** Credit funding: the limit the player chose, what settled, what the budget
402
+ * holds for calls not yet settled (and a remainder under one credit), and
403
+ * what is left. */
404
+ usdCentsPerCredit?: number;
405
+ limitCredits?: number;
406
+ spentCredits?: number;
407
+ heldCredits?: number;
408
+ remainingCredits?: number;
409
+ /** Personal-plan funding meters REQUESTS; the ledger never sees them. */
410
+ limitCalls: number;
411
+ perCallEstimateUsdCents: number;
412
+ callCount: number;
413
+ externalCallCount: number;
414
+ expiresAt: string;
415
+ lastCallAt?: string;
416
+ stopRequestedAt?: string;
417
+ /** Why it stopped: `player_stopped`, `game_stopped`, `operator_stopped`,
418
+ * `session_revoked`, … — and `replaced` when the player approved a newer
419
+ * budget for the same game and funding, which the game finds with
420
+ * `getActiveSpendGrant()`. */
421
+ stopReason?: string;
422
+ createdAt: string;
423
+ /** When a `waiting_for_plan` budget may admit again. The player's OWN plan
424
+ * said wait and named the time; it is a clock, never a paid fallback. Sent
425
+ * only while the status is `waiting_for_plan`. */
426
+ resumeAt?: string;
427
+ watcherOnline?: boolean;
428
+ /** Only on the PLAYER's own Genex read of a request still waiting on them:
429
+ * the live budgets of this game that approving it would replace, one per
430
+ * funding door at most. Never sent to a game. */
431
+ replaces?: RuntimeGrantView[];
432
+ }
433
+ interface RuntimeGenerationModels {
434
+ enabled: true;
435
+ /**
436
+ * Every model this stand serves, FEATURED FIRST then by vendor and label.
437
+ *
438
+ * The catalog is synced from OpenRouter and filtered, so it can be long:
439
+ * `featured` marks the short set the operator stands behind, and a picker
440
+ * should render that set unless the player asked to see everything. Where
441
+ * `featuredCount` is 0 this whole list IS the short list.
442
+ *
443
+ * Everything past the four pricing fields is optional because a stand running
444
+ * off the hand-written env list alone knows none of it.
445
+ */
446
+ models: {
447
+ id: string;
448
+ label: string;
449
+ inputUsdPerMillion: number;
450
+ outputUsdPerMillion: number;
451
+ /** The id's prefix — `google`, `anthropic`, … */
452
+ vendor?: string;
453
+ contextLength?: number;
454
+ featured?: boolean;
455
+ /** Which personal subscription could fund this model, or null for none. */
456
+ personalPlan?: 'claude' | 'chatgpt' | null;
457
+ /** Serves strict `json_schema` output. */
458
+ structuredOutputs?: boolean;
459
+ /** Which door calls it: `openrouter` is `generate()`, `typesafe` is the
460
+ * judge (`judge()` under a budget that enabled it). Absent on a stand
461
+ * that predates the judge, where every model is `openrouter`. */
462
+ kind?: 'openrouter' | 'typesafe';
463
+ }[];
464
+ externalProviders: RuntimeExternalProvider[];
465
+ /** How many rows are in `models`. */
466
+ total?: number;
467
+ /** How many of them are featured. 0 means this stand features nothing. */
468
+ featuredCount?: number;
469
+ /** What a developer should add to a benchmarked figure. Never typed into copy. */
470
+ recommendedDeclaredHeadroomBps?: number;
471
+ /**
472
+ * This stand's size of one call, served so no game or doc types a number.
473
+ * `maxPromptBytes` and `maxSchemaBytes` are UTF-8 bytes (a prompt over its
474
+ * cap is `prompt_too_large`); `defaultOutputTokens` is a call's output budget
475
+ * when it names no `maxOutputTokens`, and `maxOutputTokens` the most one may
476
+ * ask for (`output_tokens_too_large` above it) — what a call is given is
477
+ * also bounded by what its ceiling funds; `maxOutputBytes` is the answer's
478
+ * JSON-encoded size. Absent on a stand that predates them.
479
+ */
480
+ limits?: {
481
+ maxPromptBytes: number;
482
+ maxSchemaBytes: number;
483
+ defaultOutputTokens: number;
484
+ maxOutputTokens: number;
485
+ maxOutputBytes: number;
486
+ };
487
+ /** `credits`: in-game calls are paid from the player's credits. */
488
+ currency?: RuntimeCurrency;
489
+ /** The fee a call is billed at over its real provider cost, in basis points. */
490
+ feeBps?: number;
491
+ usdCentsPerCredit?: number;
492
+ /** The slider a new budget freezes, in credits. */
493
+ standingCreditGrant?: {
494
+ minCredits: number;
495
+ maxCredits: number;
496
+ stepCredits: number;
497
+ defaultCredits: number;
498
+ minUsdCents: number;
499
+ maxUsdCents: number;
500
+ stepUsdCents: number;
501
+ };
502
+ /** The dormant coin slider, kept for readers written before credits. */
503
+ standingGrant?: RuntimeGrantTerms['limit'];
504
+ /**
505
+ * The stand's own probe of its provider key — one word, nothing else.
506
+ * `rejected` means every in-game call answers `provider_http_401` until an
507
+ * operator replaces the key; `unknown` means it has not asked yet or could
508
+ * not reach the provider. Absent on a stand that predates the probe.
509
+ */
510
+ providerKey?: 'ok' | 'rejected' | 'unknown';
511
+ }
512
+ /**
513
+ * What `POST /api/runtime/grants/:id/generations/stream` sends, as
514
+ * `text/event-stream`, in this order: one `start`, any number of `delta`, one
515
+ * `done`. `delta.text` is the answer's text in order — a JSON answer arrives as
516
+ * its raw text — and is NEVER the answer: only `done` is, and it carries the
517
+ * same view `GET /generations/:id` returns. A `done` whose status is not
518
+ * terminal (`queued`, `dispatching`, `awaiting_external`) means the call runs
519
+ * elsewhere — poll that id.
520
+ */
521
+ type RuntimeGenerationStreamEvent = {
522
+ event: 'start';
523
+ data: {
524
+ generationId: string;
525
+ };
526
+ } | {
527
+ event: 'delta';
528
+ data: {
529
+ text: string;
530
+ };
531
+ } | {
532
+ event: 'done';
533
+ data: RuntimeGenerationView;
534
+ };
535
+
536
+ export type { RuntimeJudgeQuestion as R, RuntimeWorkflowInput as a, RuntimeGenerationView as b, RuntimeJudgeAnswer as c, RuntimeJudgmentView as d, RuntimeGenerationBilling as e, RuntimeGenerationFunding as f, RuntimeGrantView as g, RuntimeGenerationModels as h, RuntimeWorkflowOfferings as i, RuntimeBillingPolicy as j, RuntimeCurrency as k, RuntimeExternalProvider as l, RuntimeGenerationStatus as m, RuntimeGenerationStreamEvent as n, RuntimeGrantJudgeTerms as o, RuntimeGrantStatus as p, RuntimeGrantTerms as q, RuntimeJudgeCriterion as r };
package/dist/sentry.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  _stashTicketFromUrl,
3
3
  getUser,
4
4
  on
5
- } from "./chunk-NGNVGLPV.js";
5
+ } from "./chunk-QNZZIJGP.js";
6
6
  import "./chunk-MJPLBT3T.js";
7
7
 
8
8
  // src/sentry.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genex-ai/embed-sdk",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Player identity + durable game state for genex games \u2014 signed-in or guest play, per-player save slots, shared world state, soft-trust leaderboards, and shared collections and event streams.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,7 +30,8 @@
30
30
  "build": "tsup",
31
31
  "typecheck": "tsc --noEmit",
32
32
  "test": "node --test test/*.test.ts",
33
- "check": "pnpm build && publint && attw --pack . --profile esm-only",
33
+ "check": "pnpm build && publint && attw --pack . --profile esm-only && node scripts/check-packed-types.mjs",
34
+ "check:packed-types": "node scripts/check-packed-types.mjs",
34
35
  "prepack": "pnpm build && publint"
35
36
  },
36
37
  "publishConfig": {