@genex-ai/embed-sdk 0.25.0 → 0.26.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 +56 -0
- package/dist/{chunk-THXJ4IMO.js → chunk-KEPAMDTE.js} +229 -2
- package/dist/{chunk-VPIQVRVS.js → chunk-MJPLBT3T.js} +15 -0
- package/dist/development.js +1 -1
- package/dist/index.d.ts +34 -2
- package/dist/index.js +4 -2
- package/dist/sentry.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -211,6 +211,62 @@ and something that survives a reload. Validate `result.output` against the shape
|
|
|
211
211
|
your game expects before using it, always. It is data, never authority for
|
|
212
212
|
coins, rewards or items.
|
|
213
213
|
|
|
214
|
+
## Streaming replies
|
|
215
|
+
|
|
216
|
+
SDK **0.26.0+**. `generateStream()` is `generate({ grantId })` answered as it is
|
|
217
|
+
written: the text arrives in pieces while the model writes it, instead of all at
|
|
218
|
+
once after the call. Use it for **dialogue and narration** a player watches
|
|
219
|
+
appear — an NPC's reply, a story beat. Keep `generate()` for answers the game
|
|
220
|
+
only acts on as a whole (a quest object, a list), and `judge()` for decisions.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import { generateStream, generationErrorMessage } from '@genex-ai/embed-sdk';
|
|
224
|
+
|
|
225
|
+
const reply = await generateStream({
|
|
226
|
+
...request, // the same options generate() takes
|
|
227
|
+
grantId, // required: only a standing budget streams
|
|
228
|
+
onDelta: (_piece, soFar) => bubble.setText(soFar),
|
|
229
|
+
});
|
|
230
|
+
if (reply.status === 'succeeded') applyGeneration(reply); // the answer
|
|
231
|
+
else showNotice(generationErrorMessage(reply.error));
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
It resolves to **the same result `generate()` gives** — status, output, receipt
|
|
235
|
+
— and that result, not the pieces, is the answer. Pieces are provisional: a call
|
|
236
|
+
can still fail after text has arrived (the model broke off, or a JSON answer
|
|
237
|
+
did not match the schema), so let the resolved status decide what the game
|
|
238
|
+
keeps. The price is the same fixed price: a started attempt is charged whether
|
|
239
|
+
it succeeds, fails, or the player walks away mid-sentence.
|
|
240
|
+
|
|
241
|
+
For `outputFormat: 'json'`, `onPartialField(name, partialText)` reports the
|
|
242
|
+
**first top-level string property of `schema`** as far as the model has written
|
|
243
|
+
it — put the NPC's line first in the schema and it can appear word by word while
|
|
244
|
+
the rest of the object is still arriving. The object itself is parsed and
|
|
245
|
+
checked against the schema only once it is complete.
|
|
246
|
+
|
|
247
|
+
- **Grant-only.** Without `grantId` it resolves `failed` with
|
|
248
|
+
`stream_requires_grant` before the network: a one-time request waits on the
|
|
249
|
+
player's approval sheet, so there is nothing to stream. Every other guard is
|
|
250
|
+
a budget `generate()`'s — production play, a signed-in player, a trusted
|
|
251
|
+
parent, no popup and no user gesture — and so are the refusals
|
|
252
|
+
(`grant_concurrency`, `grant_limit_reached`, …). A stream holds one of the
|
|
253
|
+
budget's `maxConcurrent` slots until it has settled.
|
|
254
|
+
- **Sometimes it arrives whole.** A call the stand cannot start at once, a
|
|
255
|
+
retry of a call already running (the same `idempotencyKey`), or a budget on
|
|
256
|
+
the player's own plan is answered in one piece: the SDK waits for it the way
|
|
257
|
+
`generate()` does and calls `onDelta` once with the whole text.
|
|
258
|
+
- **`signal` stops the reading, not the call.** The model still finishes and the
|
|
259
|
+
call is charged; the result is `pending` with `stream_aborted` and the
|
|
260
|
+
`generationId` — `waitForGeneration(generationId)` recovers the answer. A
|
|
261
|
+
dropped connection is recovered the same way, automatically: Genex keeps
|
|
262
|
+
reading the model's reply after a client leaves and settles it either way.
|
|
263
|
+
|
|
264
|
+
The wire, for other clients: `POST /api/runtime/grants/:id/generations/stream`
|
|
265
|
+
with the embed token as a bearer answers `text/event-stream` — `start`
|
|
266
|
+
`{ generationId }`, `delta` `{ text }` (batched, at most every ~50 ms) and a
|
|
267
|
+
final `done` carrying the same view `GET /generations/:id` returns. EventSource
|
|
268
|
+
cannot send a POST or the token, so the SDK reads `fetch()`'s body.
|
|
269
|
+
|
|
214
270
|
## Judge during play
|
|
215
271
|
|
|
216
272
|
SDK **0.25.0+**. `generate()` writes; `judge()` decides. A game that needs to
|
|
@@ -6,9 +6,10 @@ import {
|
|
|
6
6
|
hasNativeMarker,
|
|
7
7
|
isGenerationId,
|
|
8
8
|
isGenerationTerminal,
|
|
9
|
+
parseGenerationStreamEvent,
|
|
9
10
|
readBridgeNativeCommand,
|
|
10
11
|
readNativeEntry
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-MJPLBT3T.js";
|
|
12
13
|
|
|
13
14
|
// src/commerce.ts
|
|
14
15
|
var cfg = null;
|
|
@@ -117,6 +118,129 @@ async function buy(opts) {
|
|
|
117
118
|
return awaitOutcome(view.id, opts.timeoutMs ?? 18e4);
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
// src/stream.ts
|
|
122
|
+
function createSseParser(onEvent) {
|
|
123
|
+
let buffer = "";
|
|
124
|
+
let data = [];
|
|
125
|
+
let name = "";
|
|
126
|
+
const line = (text) => {
|
|
127
|
+
if (text === "") {
|
|
128
|
+
if (data.length) onEvent({ event: name || "message", data: data.join("\n") });
|
|
129
|
+
data = [];
|
|
130
|
+
name = "";
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (text.startsWith(":")) return;
|
|
134
|
+
const colon = text.indexOf(":");
|
|
135
|
+
const field = colon === -1 ? text : text.slice(0, colon);
|
|
136
|
+
let value = colon === -1 ? "" : text.slice(colon + 1);
|
|
137
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
138
|
+
if (field === "data") data.push(value);
|
|
139
|
+
else if (field === "event") name = value;
|
|
140
|
+
};
|
|
141
|
+
const drain = (final) => {
|
|
142
|
+
for (; ; ) {
|
|
143
|
+
const match = /\r\n|\r|\n/.exec(buffer);
|
|
144
|
+
if (!match) break;
|
|
145
|
+
if (match[0] === "\r" && match.index === buffer.length - 1 && !final) break;
|
|
146
|
+
line(buffer.slice(0, match.index));
|
|
147
|
+
buffer = buffer.slice(match.index + match[0].length);
|
|
148
|
+
}
|
|
149
|
+
if (final) {
|
|
150
|
+
if (buffer) line(buffer);
|
|
151
|
+
buffer = "";
|
|
152
|
+
line("");
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
push(text) {
|
|
157
|
+
buffer += text;
|
|
158
|
+
drain(false);
|
|
159
|
+
},
|
|
160
|
+
end() {
|
|
161
|
+
drain(true);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function firstStringProperty(schema) {
|
|
166
|
+
if (!schema || typeof schema !== "object") return void 0;
|
|
167
|
+
const properties = schema.properties;
|
|
168
|
+
if (schema.type !== "object" || !properties || typeof properties !== "object" || Array.isArray(properties)) return void 0;
|
|
169
|
+
for (const [name, child] of Object.entries(properties)) {
|
|
170
|
+
if (child && typeof child === "object" && child.type === "string") return name;
|
|
171
|
+
}
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
var ESCAPES = { '"': '"', "\\": "\\", "/": "/", b: "\b", f: "\f", n: "\n", r: "\r", t: " " };
|
|
175
|
+
function readString(text, start) {
|
|
176
|
+
let value = "";
|
|
177
|
+
let i = start + 1;
|
|
178
|
+
while (i < text.length) {
|
|
179
|
+
const c = text[i];
|
|
180
|
+
if (c === '"') return { value, end: i + 1, complete: true };
|
|
181
|
+
if (c !== "\\") {
|
|
182
|
+
value += c;
|
|
183
|
+
i++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const next = text[i + 1];
|
|
187
|
+
if (next === void 0) break;
|
|
188
|
+
if (next === "u") {
|
|
189
|
+
const hex = text.slice(i + 2, i + 6);
|
|
190
|
+
if (hex.length < 4) break;
|
|
191
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) return { value: withoutHalfPair(value), end: text.length, complete: false };
|
|
192
|
+
value += String.fromCharCode(parseInt(hex, 16));
|
|
193
|
+
i += 6;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
value += ESCAPES[next] ?? next;
|
|
197
|
+
i += 2;
|
|
198
|
+
}
|
|
199
|
+
return { value: withoutHalfPair(value), end: text.length, complete: false };
|
|
200
|
+
}
|
|
201
|
+
function withoutHalfPair(value) {
|
|
202
|
+
return /[\uD800-\uDBFF]$/.test(value) ? value.slice(0, -1) : value;
|
|
203
|
+
}
|
|
204
|
+
function partialStringField(text, name) {
|
|
205
|
+
let i = 0;
|
|
206
|
+
const skip = () => {
|
|
207
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
208
|
+
};
|
|
209
|
+
skip();
|
|
210
|
+
if (text[i] !== "{") return void 0;
|
|
211
|
+
i++;
|
|
212
|
+
let depth = 1;
|
|
213
|
+
let expectKey = true;
|
|
214
|
+
while (i < text.length) {
|
|
215
|
+
const c = text[i];
|
|
216
|
+
if (c === '"') {
|
|
217
|
+
const read = readString(text, i);
|
|
218
|
+
if (depth === 1 && expectKey) {
|
|
219
|
+
if (!read.complete) return void 0;
|
|
220
|
+
i = read.end;
|
|
221
|
+
skip();
|
|
222
|
+
if (text[i] !== ":") return void 0;
|
|
223
|
+
i++;
|
|
224
|
+
skip();
|
|
225
|
+
expectKey = false;
|
|
226
|
+
if (read.value !== name) continue;
|
|
227
|
+
if (text[i] !== '"') return void 0;
|
|
228
|
+
return readString(text, i).value;
|
|
229
|
+
}
|
|
230
|
+
if (!read.complete) return void 0;
|
|
231
|
+
i = read.end;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (c === "{" || c === "[") depth++;
|
|
235
|
+
else if (c === "}" || c === "]") {
|
|
236
|
+
depth--;
|
|
237
|
+
if (depth === 0) return void 0;
|
|
238
|
+
} else if (c === "," && depth === 1) expectKey = true;
|
|
239
|
+
i++;
|
|
240
|
+
}
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
|
|
120
244
|
// src/generation.ts
|
|
121
245
|
var config = null;
|
|
122
246
|
function _initGeneration(value) {
|
|
@@ -423,6 +547,103 @@ async function generateUnderGrant(grantId, input, idempotencyKey, timeoutMs) {
|
|
|
423
547
|
return { status: "failed", error: error instanceof Error ? error.message : "generation_unavailable" };
|
|
424
548
|
}
|
|
425
549
|
}
|
|
550
|
+
async function generateStream(options) {
|
|
551
|
+
if (!validEstimateCoins(options.estimateCoins)) return { status: "failed", error: "invalid_estimate_coins" };
|
|
552
|
+
const { timeoutMs, idempotencyKey, grantId, onDelta, onPartialField, signal, allowExternal: _unused, ...body } = options;
|
|
553
|
+
if (grantId === void 0 || grantId === null) return { status: "failed", error: "stream_requires_grant" };
|
|
554
|
+
if (!isGrantId(grantId)) return { status: "failed", error: "invalid_grant_id" };
|
|
555
|
+
const guarded = approvalGuards();
|
|
556
|
+
if ("status" in guarded) return guarded;
|
|
557
|
+
const c = must2();
|
|
558
|
+
const field = body.outputFormat === "json" && onPartialField ? firstStringProperty(body.schema) : void 0;
|
|
559
|
+
let generationId;
|
|
560
|
+
let soFar = "";
|
|
561
|
+
let shown;
|
|
562
|
+
const showField = (value) => {
|
|
563
|
+
if (!field || value === shown) return;
|
|
564
|
+
shown = value;
|
|
565
|
+
try {
|
|
566
|
+
onPartialField(field, value);
|
|
567
|
+
} catch {
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
const deliver = (text) => {
|
|
571
|
+
soFar += text;
|
|
572
|
+
try {
|
|
573
|
+
onDelta?.(text, soFar);
|
|
574
|
+
} catch {
|
|
575
|
+
}
|
|
576
|
+
if (field) {
|
|
577
|
+
const partial = partialStringField(soFar, field);
|
|
578
|
+
if (partial !== void 0) showField(partial);
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
const finish = (result) => {
|
|
582
|
+
if (result.status === "succeeded") {
|
|
583
|
+
const output = result.output;
|
|
584
|
+
if (typeof output === "string" && output.startsWith(soFar) && output.length > soFar.length) deliver(output.slice(soFar.length));
|
|
585
|
+
else if (field && output && typeof output === "object" && typeof output[field] === "string") showField(output[field]);
|
|
586
|
+
}
|
|
587
|
+
return result;
|
|
588
|
+
};
|
|
589
|
+
const aborted = () => ({ status: "pending", ...generationId ? { generationId } : {}, error: "stream_aborted" });
|
|
590
|
+
try {
|
|
591
|
+
const token = c.getToken();
|
|
592
|
+
if (!token) return { status: "failed", error: "no_player_session" };
|
|
593
|
+
const response = await fetch(`${c.apiUrl}/api/runtime/grants/${encodeURIComponent(grantId)}/generations/stream`, {
|
|
594
|
+
method: "POST",
|
|
595
|
+
credentials: "omit",
|
|
596
|
+
cache: "no-store",
|
|
597
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", Accept: "text/event-stream" },
|
|
598
|
+
body: JSON.stringify({ ...body, idempotencyKey: idempotencyKey ?? crypto.randomUUID() }),
|
|
599
|
+
...signal ? { signal } : {}
|
|
600
|
+
});
|
|
601
|
+
if (!response.ok) {
|
|
602
|
+
const refusal = await response.json().catch(() => ({}));
|
|
603
|
+
return { status: "failed", error: typeof refusal.error === "string" ? refusal.error : "generation_unavailable" };
|
|
604
|
+
}
|
|
605
|
+
if (!response.body || !(response.headers.get("content-type") ?? "").includes("text/event-stream")) throw new Error("invalid_generation_response");
|
|
606
|
+
let done;
|
|
607
|
+
const parser = createSseParser(({ event, data }) => {
|
|
608
|
+
const parsed = parseGenerationStreamEvent(event, data);
|
|
609
|
+
if (!parsed || done) return;
|
|
610
|
+
if (parsed.event === "start") generationId ??= parsed.data.generationId;
|
|
611
|
+
else if (parsed.event === "delta") deliver(parsed.data.text);
|
|
612
|
+
else done = parsed.data;
|
|
613
|
+
});
|
|
614
|
+
const reader = response.body.getReader();
|
|
615
|
+
const decoder = new TextDecoder();
|
|
616
|
+
try {
|
|
617
|
+
for (; ; ) {
|
|
618
|
+
const { value, done: ended } = await reader.read();
|
|
619
|
+
if (ended) break;
|
|
620
|
+
parser.push(decoder.decode(value, { stream: true }));
|
|
621
|
+
if (done) {
|
|
622
|
+
reader.cancel().catch(() => {
|
|
623
|
+
});
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (!done) {
|
|
628
|
+
parser.push(decoder.decode());
|
|
629
|
+
parser.end();
|
|
630
|
+
}
|
|
631
|
+
} catch {
|
|
632
|
+
if (signal?.aborted) return aborted();
|
|
633
|
+
}
|
|
634
|
+
if (signal?.aborted) return aborted();
|
|
635
|
+
if (done) {
|
|
636
|
+
const view = done;
|
|
637
|
+
if (!isGenerationId(view.id) || view.grantId !== grantId || generationId !== void 0 && view.id !== generationId) throw new Error("invalid_generation_response");
|
|
638
|
+
return finish(outcome(view) ?? await poll(view.id, timeoutMs ?? 6e5, outcome));
|
|
639
|
+
}
|
|
640
|
+
if (generationId) return finish(await poll(generationId, timeoutMs ?? 6e5, outcome));
|
|
641
|
+
return { status: "failed", error: "generation_unavailable" };
|
|
642
|
+
} catch (error) {
|
|
643
|
+
if (signal?.aborted) return aborted();
|
|
644
|
+
return { status: "failed", error: error instanceof Error ? error.message : "generation_unavailable" };
|
|
645
|
+
}
|
|
646
|
+
}
|
|
426
647
|
var JUDGE_QUESTION_NAME = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
427
648
|
function invalidJudgeOptions(options) {
|
|
428
649
|
if (options.grantId === void 0 || options.grantId === null) return "judge_requires_grant";
|
|
@@ -525,6 +746,11 @@ function generationErrorMessage(code) {
|
|
|
525
746
|
return "The game\u2019s quick checks are busy right now. Try again in a moment.";
|
|
526
747
|
case "judge_paused":
|
|
527
748
|
return "The game\u2019s quick checks are paused for now. Try again later.";
|
|
749
|
+
// --- streamed replies -----------------------------------------------------
|
|
750
|
+
case "stream_requires_grant":
|
|
751
|
+
return "Live replies run under a budget you approve. Set one up to keep going.";
|
|
752
|
+
case "stream_aborted":
|
|
753
|
+
return "This reply stopped showing, but it is still finishing and is charged as usual. Check back in a moment.";
|
|
528
754
|
case "waiting_for_plan":
|
|
529
755
|
return "Your own plan is at its rate limit right now. This resumes on its own once the limit resets.";
|
|
530
756
|
// --- personal plans and the player watcher ------------------------------
|
|
@@ -646,7 +872,7 @@ var RETRY_FLAG = "genex:embed:retry";
|
|
|
646
872
|
var POPOVER_DISMISSED_FLAG = "genex:guest:popover-dismissed";
|
|
647
873
|
var LOCAL_AUTH_FLAG = "genex:embed:local-auth";
|
|
648
874
|
var PLAYER_ID_KEY = "genex:player";
|
|
649
|
-
var SDK_VERSION = "0.
|
|
875
|
+
var SDK_VERSION = "0.26.0";
|
|
650
876
|
var config2 = null;
|
|
651
877
|
var state = "pending";
|
|
652
878
|
var user = null;
|
|
@@ -1900,6 +2126,7 @@ export {
|
|
|
1900
2126
|
getSpendGrant,
|
|
1901
2127
|
stopSpendGrant,
|
|
1902
2128
|
requestSpendGrant,
|
|
2129
|
+
generateStream,
|
|
1903
2130
|
judge,
|
|
1904
2131
|
generationErrorMessage,
|
|
1905
2132
|
initEmbed,
|
|
@@ -232,6 +232,20 @@ function readNativeEntry(search) {
|
|
|
232
232
|
function isGenerationId(value) {
|
|
233
233
|
return typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
|
|
234
234
|
}
|
|
235
|
+
function parseGenerationStreamEvent(event, data) {
|
|
236
|
+
let value;
|
|
237
|
+
try {
|
|
238
|
+
value = JSON.parse(data);
|
|
239
|
+
} catch {
|
|
240
|
+
return void 0;
|
|
241
|
+
}
|
|
242
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
243
|
+
const fields = value;
|
|
244
|
+
if (event === "start") return isGenerationId(fields.generationId) ? { event, data: { generationId: fields.generationId } } : void 0;
|
|
245
|
+
if (event === "delta") return typeof fields.text === "string" ? { event, data: { text: fields.text } } : void 0;
|
|
246
|
+
if (event === "done") return isGenerationId(fields.id) && typeof fields.status === "string" ? { event, data: value } : void 0;
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
235
249
|
function isGenerationTerminal(status) {
|
|
236
250
|
return ["succeeded", "failed", "unknown", "canceled", "expired"].includes(status);
|
|
237
251
|
}
|
|
@@ -245,5 +259,6 @@ export {
|
|
|
245
259
|
hasNativeMarker,
|
|
246
260
|
readNativeEntry,
|
|
247
261
|
isGenerationId,
|
|
262
|
+
parseGenerationStreamEvent,
|
|
248
263
|
isGenerationTerminal
|
|
249
264
|
};
|
package/dist/development.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RuntimeJudgeQuestion, RuntimeJudgeAnswer, RuntimeJudgmentView, RuntimeWorkflowInput, RuntimeGenerationBilling, RuntimeGenerationFunding, RuntimeGrantView, RuntimeGenerationView, RuntimeGenerationModels, RuntimeWorkflowOfferings } from '@genex/embed-protocol';
|
|
2
|
-
export { RuntimeBillingPolicy, RuntimeExternalProvider, RuntimeGenerationBilling, RuntimeGenerationFunding, RuntimeGenerationModels, RuntimeGenerationStatus, RuntimeGenerationView, RuntimeGrantJudgeTerms, RuntimeGrantStatus, RuntimeGrantTerms, RuntimeGrantView, RuntimeJudgeAnswer, RuntimeJudgeCriterion, RuntimeJudgeQuestion, RuntimeJudgmentView, RuntimeWorkflowInput, RuntimeWorkflowOfferings } from '@genex/embed-protocol';
|
|
2
|
+
export { RuntimeBillingPolicy, RuntimeExternalProvider, RuntimeGenerationBilling, RuntimeGenerationFunding, RuntimeGenerationModels, RuntimeGenerationStatus, RuntimeGenerationStreamEvent, RuntimeGenerationView, RuntimeGrantJudgeTerms, RuntimeGrantStatus, RuntimeGrantTerms, RuntimeGrantView, RuntimeJudgeAnswer, RuntimeJudgeCriterion, RuntimeJudgeQuestion, RuntimeJudgmentView, RuntimeWorkflowInput, RuntimeWorkflowOfferings } from '@genex/embed-protocol';
|
|
3
3
|
|
|
4
4
|
/** A thing the game sells. Resolved server-side; the game never sets a price. */
|
|
5
5
|
interface ShopItem {
|
|
@@ -267,6 +267,38 @@ declare function stopSpendGrant(grantId: string): Promise<RuntimeGrantView>;
|
|
|
267
267
|
* Store the id: getSpendGrant(id) recovers the budget after a reload.
|
|
268
268
|
*/
|
|
269
269
|
declare function requestSpendGrant(options: SpendGrantOptions): Promise<SpendGrantResult>;
|
|
270
|
+
interface GenerateStreamOptions extends GenerateOptions {
|
|
271
|
+
/** A standing budget from requestSpendGrant(). Required: only a budget streams. */
|
|
272
|
+
grantId: string;
|
|
273
|
+
/**
|
|
274
|
+
* Each piece of the answer as it arrives, and all of it so far. PROVISIONAL:
|
|
275
|
+
* a call can still fail after text has arrived (the model broke off, the
|
|
276
|
+
* JSON did not match the schema) — only the resolved result is the answer.
|
|
277
|
+
*/
|
|
278
|
+
onDelta?: (text: string, soFar: string) => void;
|
|
279
|
+
/**
|
|
280
|
+
* `outputFormat: 'json'` only: the FIRST top-level string property of
|
|
281
|
+
* `schema` (say, an NPC's `line`), as far as the model has written it, read
|
|
282
|
+
* leniently from the growing JSON — so dialogue can appear while the rest of
|
|
283
|
+
* the object is still arriving. Called only when the value grows.
|
|
284
|
+
*/
|
|
285
|
+
onPartialField?: (name: string, partialText: string) => void;
|
|
286
|
+
/**
|
|
287
|
+
* Stops READING the reply, not the call: the model still finishes and the
|
|
288
|
+
* call is charged as usual. Resolves `pending` with `stream_aborted`;
|
|
289
|
+
* waitForGeneration(generationId) recovers the answer.
|
|
290
|
+
*/
|
|
291
|
+
signal?: AbortSignal;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* One call under a standing budget, streamed. No popup and no user gesture —
|
|
295
|
+
* the same guards as generate({ grantId }). A call the stand cannot start at
|
|
296
|
+
* once, a replay of a call already running, or a budget on the player's own
|
|
297
|
+
* plan is answered whole: the SDK polls it, and `onDelta` receives the text in
|
|
298
|
+
* one piece at the end. A dropped connection is polled too, because the server
|
|
299
|
+
* keeps reading the model's reply and settles it either way.
|
|
300
|
+
*/
|
|
301
|
+
declare function generateStream(options: GenerateStreamOptions): Promise<RuntimeGenerationResult>;
|
|
270
302
|
interface JudgeOptions {
|
|
271
303
|
/** A standing budget from requestSpendGrant({ judge: { enabled: true, … } }). Required. */
|
|
272
304
|
grantId: string;
|
|
@@ -567,4 +599,4 @@ declare function __resetForTests(overrides?: {
|
|
|
567
599
|
heartbeatIntervalMs?: number;
|
|
568
600
|
}): void;
|
|
569
601
|
|
|
570
|
-
export { type AuthState, type EmbedConfig, type EmbedEvent, type EmbedUser, type Entitlement, type GenerateOptions, type JudgeOptions, type JudgeResult, type Leaderboard, type LeaderboardEntry, type PlayerStateResult, type PurchaseResult, type PurchaseStatus, type RequestWorkflowOptions, type RuntimeGenerationResult, type RuntimeWorkflowAuthorization, type SaveStateResult, type ShopItem, type SpendGrantDisclosure, type SpendGrantOptions, type SpendGrantResult, type SubmitScoreResult, type WorldStateResult, __resetForTests, _stashTicketFromUrl, buy, consumeEntitlement, generate, generationErrorMessage, getAuthState, getColyseusAuth, getColyseusUrls, getEmbedToken, getEntitlements, getGeneration, getGenerationModels, getLeaderboard, getShop, getSpendGrant, getUser, getWorkflowOfferings, initEmbed, isEmbedded, judge, loadPlayerState, loadWorldState, on, requestSpendGrant, requestWorkflow, resumeWorkflow, savePlayerState, saveWorldState, stopSpendGrant, submitScore, waitForAuth, waitForGeneration, waitForPlayer };
|
|
602
|
+
export { type AuthState, 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 RequestWorkflowOptions, type RuntimeGenerationResult, type RuntimeWorkflowAuthorization, type SaveStateResult, type ShopItem, type SpendGrantDisclosure, type SpendGrantOptions, type SpendGrantResult, type SubmitScoreResult, type WorldStateResult, __resetForTests, _stashTicketFromUrl, buy, consumeEntitlement, generate, generateStream, generationErrorMessage, getAuthState, getColyseusAuth, getColyseusUrls, getEmbedToken, getEntitlements, getGeneration, getGenerationModels, getLeaderboard, getShop, getSpendGrant, getUser, getWorkflowOfferings, initEmbed, isEmbedded, judge, loadPlayerState, loadWorldState, on, requestSpendGrant, requestWorkflow, resumeWorkflow, savePlayerState, saveWorldState, stopSpendGrant, submitScore, waitForAuth, waitForGeneration, waitForPlayer };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
buy,
|
|
5
5
|
consumeEntitlement,
|
|
6
6
|
generate,
|
|
7
|
+
generateStream,
|
|
7
8
|
generationErrorMessage,
|
|
8
9
|
getAuthState,
|
|
9
10
|
getColyseusAuth,
|
|
@@ -33,14 +34,15 @@ import {
|
|
|
33
34
|
waitForAuth,
|
|
34
35
|
waitForGeneration,
|
|
35
36
|
waitForPlayer
|
|
36
|
-
} from "./chunk-
|
|
37
|
-
import "./chunk-
|
|
37
|
+
} from "./chunk-KEPAMDTE.js";
|
|
38
|
+
import "./chunk-MJPLBT3T.js";
|
|
38
39
|
export {
|
|
39
40
|
__resetForTests,
|
|
40
41
|
_stashTicketFromUrl,
|
|
41
42
|
buy,
|
|
42
43
|
consumeEntitlement,
|
|
43
44
|
generate,
|
|
45
|
+
generateStream,
|
|
44
46
|
generationErrorMessage,
|
|
45
47
|
getAuthState,
|
|
46
48
|
getColyseusAuth,
|
package/dist/sentry.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genex-ai/embed-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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, and soft-trust leaderboards.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|