@byte_fluffy/nexra-sdk 0.1.0-alpha.31 → 0.1.0-alpha.32

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/dist/catalog.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  listModelSpecs,
10
10
  projectMediaGeometry,
11
11
  resolveNexraLanguageReasoning
12
- } from "./chunk-QXEDXMFI.js";
12
+ } from "./chunk-MNRDMPUS.js";
13
13
  import "./chunk-QBW7OCT3.js";
14
14
  export {
15
15
  CatalogClient,
@@ -30539,6 +30539,452 @@ var video_generated_default = [
30539
30539
  ],
30540
30540
  endpoints: []
30541
30541
  },
30542
+ {
30543
+ id: "minimax/minimax-h3-local-reference",
30544
+ contractVersion: 1,
30545
+ developer: "minimax",
30546
+ displayName: "MiniMax H3 Local Reference",
30547
+ summary: "Generate video from a prompt with reference images, videos and audio.",
30548
+ kind: "video",
30549
+ family: "H3 Local",
30550
+ versionLabel: "H3 Local Reference",
30551
+ aliases: [],
30552
+ capabilities: {
30553
+ inputModalities: [
30554
+ "text",
30555
+ "image",
30556
+ "video",
30557
+ "audio"
30558
+ ],
30559
+ outputModalities: [
30560
+ "video"
30561
+ ],
30562
+ inputModes: [
30563
+ "image-to-video",
30564
+ "video-to-video",
30565
+ "audio-to-video"
30566
+ ],
30567
+ features: [
30568
+ "reference-image",
30569
+ "reference-video",
30570
+ "reference-audio",
30571
+ "omni-reference"
30572
+ ]
30573
+ },
30574
+ operations: [
30575
+ {
30576
+ operation: "video.generate",
30577
+ inputModalities: [
30578
+ "text",
30579
+ "image",
30580
+ "video",
30581
+ "audio"
30582
+ ],
30583
+ outputModalities: [
30584
+ "video"
30585
+ ],
30586
+ inputSchema: {
30587
+ $schema: "https://json-schema.org/draft/2020-12/schema",
30588
+ type: "object",
30589
+ properties: {
30590
+ content: {
30591
+ type: "array",
30592
+ minItems: 2,
30593
+ items: {
30594
+ oneOf: [
30595
+ {
30596
+ type: "object",
30597
+ properties: {
30598
+ type: {
30599
+ const: "text"
30600
+ },
30601
+ text: {
30602
+ type: "string",
30603
+ minLength: 1
30604
+ },
30605
+ role: {
30606
+ type: "string",
30607
+ enum: [
30608
+ "prompt",
30609
+ "negative_prompt"
30610
+ ]
30611
+ }
30612
+ },
30613
+ required: [
30614
+ "type",
30615
+ "text",
30616
+ "role"
30617
+ ],
30618
+ additionalProperties: false,
30619
+ allOf: [
30620
+ {
30621
+ if: {
30622
+ type: "object",
30623
+ properties: {
30624
+ role: {
30625
+ const: "prompt"
30626
+ }
30627
+ },
30628
+ required: [
30629
+ "role"
30630
+ ]
30631
+ },
30632
+ then: {
30633
+ type: "object",
30634
+ properties: {
30635
+ text: {
30636
+ type: "string",
30637
+ maxLength: 2e4,
30638
+ minLength: 1,
30639
+ title: "Prompt"
30640
+ }
30641
+ }
30642
+ }
30643
+ },
30644
+ {
30645
+ if: {
30646
+ type: "object",
30647
+ properties: {
30648
+ role: {
30649
+ const: "negative_prompt"
30650
+ }
30651
+ },
30652
+ required: [
30653
+ "role"
30654
+ ]
30655
+ },
30656
+ then: {
30657
+ type: "object",
30658
+ properties: {
30659
+ text: {
30660
+ type: "string",
30661
+ maxLength: 1e4,
30662
+ title: "Negative Prompt",
30663
+ default: ""
30664
+ }
30665
+ }
30666
+ }
30667
+ }
30668
+ ]
30669
+ },
30670
+ {
30671
+ type: "object",
30672
+ properties: {
30673
+ type: {
30674
+ const: "image"
30675
+ },
30676
+ source: {
30677
+ oneOf: [
30678
+ {
30679
+ type: "string",
30680
+ minLength: 1
30681
+ },
30682
+ {
30683
+ type: "object",
30684
+ properties: {
30685
+ assetId: {
30686
+ type: "string",
30687
+ minLength: 1
30688
+ }
30689
+ },
30690
+ required: [
30691
+ "assetId"
30692
+ ],
30693
+ additionalProperties: false
30694
+ }
30695
+ ]
30696
+ },
30697
+ role: {
30698
+ type: "string",
30699
+ const: "reference"
30700
+ }
30701
+ },
30702
+ required: [
30703
+ "type",
30704
+ "source",
30705
+ "role"
30706
+ ],
30707
+ additionalProperties: false
30708
+ },
30709
+ {
30710
+ type: "object",
30711
+ properties: {
30712
+ type: {
30713
+ const: "video"
30714
+ },
30715
+ source: {
30716
+ oneOf: [
30717
+ {
30718
+ type: "string",
30719
+ minLength: 1
30720
+ },
30721
+ {
30722
+ type: "object",
30723
+ properties: {
30724
+ assetId: {
30725
+ type: "string",
30726
+ minLength: 1
30727
+ }
30728
+ },
30729
+ required: [
30730
+ "assetId"
30731
+ ],
30732
+ additionalProperties: false
30733
+ }
30734
+ ]
30735
+ },
30736
+ role: {
30737
+ type: "string",
30738
+ const: "reference"
30739
+ }
30740
+ },
30741
+ required: [
30742
+ "type",
30743
+ "source",
30744
+ "role"
30745
+ ],
30746
+ additionalProperties: false
30747
+ },
30748
+ {
30749
+ type: "object",
30750
+ properties: {
30751
+ type: {
30752
+ const: "audio"
30753
+ },
30754
+ source: {
30755
+ oneOf: [
30756
+ {
30757
+ type: "string",
30758
+ minLength: 1
30759
+ },
30760
+ {
30761
+ type: "object",
30762
+ properties: {
30763
+ assetId: {
30764
+ type: "string",
30765
+ minLength: 1
30766
+ }
30767
+ },
30768
+ required: [
30769
+ "assetId"
30770
+ ],
30771
+ additionalProperties: false
30772
+ }
30773
+ ]
30774
+ },
30775
+ role: {
30776
+ type: "string",
30777
+ const: "reference"
30778
+ }
30779
+ },
30780
+ required: [
30781
+ "type",
30782
+ "source",
30783
+ "role"
30784
+ ],
30785
+ additionalProperties: false
30786
+ }
30787
+ ]
30788
+ },
30789
+ "x-ui": {
30790
+ control: "content-parts",
30791
+ order: 0
30792
+ },
30793
+ maxItems: 17,
30794
+ description: "Provide a prompt and at least one image, video or audio reference.",
30795
+ allOf: [
30796
+ {
30797
+ contains: {
30798
+ type: "object",
30799
+ properties: {
30800
+ type: {
30801
+ const: "text"
30802
+ },
30803
+ role: {
30804
+ const: "prompt"
30805
+ }
30806
+ },
30807
+ required: [
30808
+ "type",
30809
+ "role"
30810
+ ]
30811
+ },
30812
+ minContains: 1,
30813
+ maxContains: 1
30814
+ },
30815
+ {
30816
+ contains: {
30817
+ type: "object",
30818
+ properties: {
30819
+ type: {
30820
+ const: "text"
30821
+ },
30822
+ role: {
30823
+ const: "negative_prompt"
30824
+ }
30825
+ },
30826
+ required: [
30827
+ "type",
30828
+ "role"
30829
+ ]
30830
+ },
30831
+ minContains: 0,
30832
+ maxContains: 1
30833
+ },
30834
+ {
30835
+ contains: {
30836
+ type: "object",
30837
+ properties: {
30838
+ type: {
30839
+ const: "image"
30840
+ },
30841
+ role: {
30842
+ const: "reference"
30843
+ }
30844
+ },
30845
+ required: [
30846
+ "type",
30847
+ "role"
30848
+ ]
30849
+ },
30850
+ minContains: 0,
30851
+ maxContains: 9
30852
+ },
30853
+ {
30854
+ contains: {
30855
+ type: "object",
30856
+ properties: {
30857
+ type: {
30858
+ const: "video"
30859
+ },
30860
+ role: {
30861
+ const: "reference"
30862
+ }
30863
+ },
30864
+ required: [
30865
+ "type",
30866
+ "role"
30867
+ ]
30868
+ },
30869
+ minContains: 0,
30870
+ maxContains: 3
30871
+ },
30872
+ {
30873
+ contains: {
30874
+ type: "object",
30875
+ properties: {
30876
+ type: {
30877
+ const: "audio"
30878
+ },
30879
+ role: {
30880
+ const: "reference"
30881
+ }
30882
+ },
30883
+ required: [
30884
+ "type",
30885
+ "role"
30886
+ ]
30887
+ },
30888
+ minContains: 0,
30889
+ maxContains: 3
30890
+ },
30891
+ {
30892
+ contains: {
30893
+ type: "object",
30894
+ properties: {
30895
+ type: {
30896
+ enum: [
30897
+ "image",
30898
+ "video",
30899
+ "audio"
30900
+ ]
30901
+ }
30902
+ },
30903
+ required: [
30904
+ "type"
30905
+ ]
30906
+ },
30907
+ minContains: 1
30908
+ }
30909
+ ]
30910
+ },
30911
+ aspect_ratio: {
30912
+ type: "string",
30913
+ title: "Aspect Ratio",
30914
+ default: "16:9",
30915
+ pattern: "^(?:1:1|2:3|3:2|3:4|4:3|9:16|16:9|21:9)(?: \\([^)]+\\))?$",
30916
+ "x-ui": {
30917
+ order: 10
30918
+ },
30919
+ enum: [
30920
+ "1:1",
30921
+ "2:3",
30922
+ "3:2",
30923
+ "3:4",
30924
+ "4:3",
30925
+ "9:16",
30926
+ "16:9",
30927
+ "21:9"
30928
+ ]
30929
+ },
30930
+ duration: {
30931
+ type: "number",
30932
+ maximum: 15,
30933
+ title: "\u89C6\u9891\u65F6\u957F",
30934
+ default: 5,
30935
+ minimum: 0.2,
30936
+ "x-ui": {
30937
+ order: 12,
30938
+ control: "range",
30939
+ unit: "\u79D2"
30940
+ }
30941
+ },
30942
+ seed: {
30943
+ type: "integer",
30944
+ minimum: 0,
30945
+ title: "\u968F\u673A\u79CD\u5B50",
30946
+ "x-ui": {
30947
+ order: 13,
30948
+ control: "number"
30949
+ }
30950
+ },
30951
+ resolution: {
30952
+ type: "string",
30953
+ title: "\u5206\u8FA8\u7387",
30954
+ enum: [
30955
+ "480P",
30956
+ "768P"
30957
+ ],
30958
+ "x-ui": {
30959
+ order: 11,
30960
+ control: "segmented"
30961
+ }
30962
+ }
30963
+ },
30964
+ required: [
30965
+ "content"
30966
+ ],
30967
+ additionalProperties: false
30968
+ },
30969
+ outputSchema: {},
30970
+ metering: {
30971
+ schemaVersion: 1,
30972
+ kind: "non_token",
30973
+ metrics: [
30974
+ {
30975
+ metric: "requests",
30976
+ requirement: "required"
30977
+ },
30978
+ {
30979
+ metric: "output_video_seconds",
30980
+ requirement: "required"
30981
+ }
30982
+ ]
30983
+ }
30984
+ }
30985
+ ],
30986
+ endpoints: []
30987
+ },
30542
30988
  {
30543
30989
  id: "agnes/agnes-video-v2-0",
30544
30990
  contractVersion: 1,
@@ -50448,7 +50894,7 @@ var NexraWaitTimeoutError = class extends Error {
50448
50894
  };
50449
50895
 
50450
50896
  // src/generated/version.generated.ts
50451
- var SDK_VERSION = "0.1.0-alpha.31";
50897
+ var SDK_VERSION = "0.1.0-alpha.32";
50452
50898
 
50453
50899
  // src/transport.ts
50454
50900
  var DEFAULT_BASE_URL = "https://api.nexra-ai.com/v1";
@@ -50599,37 +51045,56 @@ async function* parseServerSentEvents(response, options = {}) {
50599
51045
  }
50600
51046
  }
50601
51047
  function createServerSentEventDecoder() {
51048
+ const decode = createServerSentEventFrameDecoder();
51049
+ return (bytes, done) => decode(bytes, done).flatMap((frame) => frame.event ? [frame.event] : []);
51050
+ }
51051
+ function createServerSentEventFrameDecoder() {
50602
51052
  const decoder = new TextDecoder();
50603
- let buffer = "";
51053
+ let buffer = new Uint8Array();
51054
+ let cursor = 0;
51055
+ let lineStart = 0;
50604
51056
  let current = emptyEvent();
51057
+ const line = (value) => {
51058
+ if (value.startsWith(":")) return;
51059
+ const separator = value.indexOf(":");
51060
+ const field2 = separator === -1 ? value : value.slice(0, separator);
51061
+ let content = separator === -1 ? "" : value.slice(separator + 1);
51062
+ if (content.startsWith(" ")) content = content.slice(1);
51063
+ if (field2 === "data") current.data.push(content);
51064
+ else if (field2 === "event") current.event = content;
51065
+ else if (field2 === "id") current.id = content;
51066
+ else if (field2 === "retry") current.retry = Number(content);
51067
+ };
50605
51068
  return (bytes, done = false) => {
50606
- const events = [];
50607
- buffer += decoder.decode(bytes, { stream: !done });
50608
- const lines = buffer.split(/\r?\n/);
50609
- buffer = done ? "" : lines.pop() ?? "";
50610
- for (const line of lines) {
50611
- if (line === "") {
50612
- const event = buildEvent(current);
51069
+ const frames = [];
51070
+ if (bytes?.length) {
51071
+ const joined = new Uint8Array(buffer.length + bytes.length);
51072
+ joined.set(buffer);
51073
+ joined.set(bytes, buffer.length);
51074
+ buffer = joined;
51075
+ }
51076
+ let frameStart = 0;
51077
+ for (; cursor < buffer.length; cursor++) {
51078
+ if (buffer[cursor] !== 10) continue;
51079
+ const lineEnd = buffer[cursor - 1] === 13 ? cursor - 1 : cursor;
51080
+ if (lineEnd === lineStart) {
51081
+ frames.push({ event: buildEvent(current), bytes: buffer.slice(frameStart, cursor + 1) });
50613
51082
  current = emptyEvent();
50614
- if (event) events.push(event);
50615
- continue;
50616
- }
50617
- if (line.startsWith(":")) continue;
50618
- const separator = line.indexOf(":");
50619
- const field2 = separator === -1 ? line : line.slice(0, separator);
50620
- let content = separator === -1 ? "" : line.slice(separator + 1);
50621
- if (content.startsWith(" ")) content = content.slice(1);
50622
- if (field2 === "data") current.data.push(content);
50623
- else if (field2 === "event") current.event = content;
50624
- else if (field2 === "id") current.id = content;
50625
- else if (field2 === "retry") current.retry = Number(content);
51083
+ frameStart = cursor + 1;
51084
+ } else line(decoder.decode(buffer.subarray(lineStart, lineEnd)));
51085
+ lineStart = cursor + 1;
50626
51086
  }
51087
+ buffer = buffer.slice(frameStart);
51088
+ cursor -= frameStart;
51089
+ lineStart -= frameStart;
50627
51090
  if (done) {
50628
- const event = buildEvent(current);
51091
+ if (lineStart < buffer.length) line(decoder.decode(buffer.subarray(lineStart)));
51092
+ if (buffer.length) frames.push({ event: buildEvent(current), bytes: buffer });
51093
+ buffer = new Uint8Array();
51094
+ cursor = lineStart = 0;
50629
51095
  current = emptyEvent();
50630
- if (event) events.push(event);
50631
51096
  }
50632
- return events;
51097
+ return frames;
50633
51098
  };
50634
51099
  }
50635
51100
  function emptyEvent() {
@@ -50838,7 +51303,7 @@ export {
50838
51303
  applyMediaGeometry,
50839
51304
  applyNoWatermark,
50840
51305
  parseServerSentEvents,
50841
- createServerSentEventDecoder,
51306
+ createServerSentEventFrameDecoder,
50842
51307
  formatModelDisplayName,
50843
51308
  CatalogClient,
50844
51309
  getModelSpec,
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  projectMediaGeometry,
21
21
  queryString,
22
22
  sleep
23
- } from "./chunk-QXEDXMFI.js";
23
+ } from "./chunk-MNRDMPUS.js";
24
24
  import {
25
25
  MEDIA_KINDS,
26
26
  TASK_STATUSES,
package/dist/language.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  HttpTransport,
3
3
  SDK_VERSION,
4
- createServerSentEventDecoder,
4
+ createServerSentEventFrameDecoder,
5
5
  getLanguageModelBinding,
6
6
  jsonBody,
7
7
  parseServerSentEvents,
8
8
  resolveNexraLanguageReasoning
9
- } from "./chunk-QXEDXMFI.js";
9
+ } from "./chunk-MNRDMPUS.js";
10
10
  import {
11
11
  isPublicErrorCode,
12
12
  publicErrorMessage,
@@ -212,7 +212,7 @@ var NexraNativeError = class extends APICallError {
212
212
  const locale = resolvePublicErrorLocale(context.acceptLanguage ?? headers.get("content-language"));
213
213
  const nexraError = code && isPublicErrorCode(code) ? { code, message: publicErrorMessage(code, locale) } : void 0;
214
214
  const body = record(context.body);
215
- const originalMessage = record(body.error).message ?? body.message;
215
+ const originalMessage = record(body.error).message ?? record(record(body.response).error).message ?? body.message;
216
216
  const message = nexraError?.message ?? (typeof originalMessage === "string" ? originalMessage : typeof context.body === "string" ? context.body : "The native model request failed.");
217
217
  super({
218
218
  message,
@@ -259,31 +259,68 @@ function createNexraNativeFetch(options = {}) {
259
259
  }
260
260
  function guardNativeErrorFrames(response, context) {
261
261
  if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) return response;
262
- const decode = createServerSentEventDecoder();
263
- const inspect = (events) => {
264
- for (const event of events) {
265
- let body;
266
- try {
267
- body = JSON.parse(event.data);
268
- } catch {
269
- if (event.event === "error") throw new NexraNativeError({ ...context, body: event.data, responseBody: event.data });
270
- continue;
271
- }
272
- const payload = record(body);
273
- if (event.event === "error" || payload.type === "error" || payload.type === "response.failed" || payload.error) {
274
- throw new NexraNativeError({ ...context, body, responseBody: event.data });
275
- }
262
+ const decode = createServerSentEventFrameDecoder();
263
+ const reader = response.body.getReader();
264
+ const pending = [];
265
+ let finished = false;
266
+ let released = false;
267
+ let failure;
268
+ const release = () => {
269
+ if (!released) {
270
+ reader.releaseLock();
271
+ released = true;
272
+ }
273
+ };
274
+ const inspect = (event) => {
275
+ if (!event) return;
276
+ let body;
277
+ try {
278
+ body = JSON.parse(event.data);
279
+ } catch {
280
+ return event.event === "error" ? new NexraNativeError({ ...context, body: event.data, responseBody: event.data }) : void 0;
281
+ }
282
+ const payload = record(body);
283
+ if (event.event === "error" || payload.type === "error" || payload.type === "response.failed" || payload.error) {
284
+ return new NexraNativeError({ ...context, body, responseBody: event.data });
276
285
  }
277
286
  };
278
- const stream = response.body.pipeThrough(new TransformStream({
279
- transform(bytes, controller) {
280
- inspect(decode(bytes));
281
- controller.enqueue(bytes);
287
+ const stream = new ReadableStream({
288
+ async pull(controller) {
289
+ try {
290
+ while (!pending.length && !finished) {
291
+ const { value, done } = await reader.read();
292
+ for (const frame of decode(value, done)) {
293
+ failure = inspect(frame.event);
294
+ if (failure) {
295
+ finished = true;
296
+ await reader.cancel(failure).catch(() => void 0);
297
+ release();
298
+ break;
299
+ }
300
+ pending.push(frame.bytes);
301
+ }
302
+ if (done) {
303
+ finished = true;
304
+ release();
305
+ }
306
+ }
307
+ if (pending.length) controller.enqueue(pending.shift());
308
+ else if (failure) controller.error(failure);
309
+ else controller.close();
310
+ } catch (error) {
311
+ await reader.cancel(error).catch(() => void 0);
312
+ release();
313
+ controller.error(error);
314
+ }
282
315
  },
283
- flush() {
284
- inspect(decode(void 0, true));
316
+ async cancel(reason) {
317
+ pending.length = 0;
318
+ if (!released) {
319
+ await reader.cancel(reason);
320
+ release();
321
+ }
285
322
  }
286
- }));
323
+ }, { highWaterMark: 0 });
287
324
  return new Response(stream, { status: response.status, statusText: response.statusText, headers: response.headers });
288
325
  }
289
326
 
@@ -500,15 +537,33 @@ function createNexraLanguageModel(modelId, options) {
500
537
  if (binding.endpoint.protocol === "gemini-generate-content") {
501
538
  model = createGoogleGenerativeAI({ ...common, name: "nexra.google", baseURL: `${root}/v1beta/models` })(binding.spec.id);
502
539
  } else if (binding.endpoint.protocol === "openai-responses") {
503
- model = createOpenAI({ ...common, name: "nexra.openai", baseURL: `${root}/v1` }).responses(binding.spec.id);
540
+ const responsesFetch = (input, init) => fetch(
541
+ input,
542
+ typeof init?.body === "string" ? { ...init, body: JSON.stringify(explicitResponsesMessages(JSON.parse(init.body))) } : init
543
+ );
544
+ model = createOpenAI({ ...common, name: "nexra.openai", baseURL: `${root}/v1`, fetch: responsesFetch }).responses(binding.spec.id);
504
545
  } else {
505
546
  model = createAnthropic({ ...common, name: "nexra.anthropic", baseURL: `${root}/v1` })(binding.spec.id);
506
547
  }
507
- return withNativeUsage(model, binding);
548
+ return withNativeContract(model, binding);
508
549
  }
509
550
  function object3(value) {
510
551
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
511
552
  }
553
+ function explicitResponsesMessages(value) {
554
+ const body = object3(value);
555
+ if (!Array.isArray(body.input)) return value;
556
+ return { ...body, input: body.input.map((value2) => {
557
+ const item = object3(value2);
558
+ return item.type === void 0 && ["system", "developer", "user", "assistant"].includes(String(item.role)) && (typeof item.content === "string" || Array.isArray(item.content)) ? { ...item, type: "message" } : value2;
559
+ }) };
560
+ }
561
+ function nativeRequest(protocol, request, stream = false) {
562
+ return protocol === "openai-responses" && request ? {
563
+ ...request,
564
+ body: explicitResponsesMessages(stream ? { ...object3(request.body), stream: true } : request.body)
565
+ } : request;
566
+ }
512
567
  function prepare(options, binding, stream) {
513
568
  options = prepareLanguageReasoning(options, binding);
514
569
  const properties = object3(binding.endpoint.inputSchema?.properties);
@@ -572,7 +627,7 @@ function mergeRecords(previous, next) {
572
627
  }
573
628
  return merged;
574
629
  }
575
- function withNativeUsage(model, binding) {
630
+ function withNativeContract(model, binding) {
576
631
  return {
577
632
  specificationVersion: "v4",
578
633
  provider: model.provider,
@@ -581,7 +636,11 @@ function withNativeUsage(model, binding) {
581
636
  async doGenerate(options) {
582
637
  const result = await model.doGenerate(prepare(options, binding, false));
583
638
  const raw = nativeUsage(binding.endpoint.protocol, result.response?.body);
584
- return raw ? { ...result, usage: { ...result.usage, raw } } : result;
639
+ return {
640
+ ...result,
641
+ request: nativeRequest(binding.endpoint.protocol, result.request),
642
+ ...raw ? { usage: { ...result.usage, raw } } : {}
643
+ };
585
644
  },
586
645
  async doStream(options) {
587
646
  if (!binding.supportsStreaming) throw new Error(`Nexra model does not support streaming: ${binding.spec.id}`);
@@ -592,35 +651,39 @@ function withNativeUsage(model, binding) {
592
651
  let finish;
593
652
  const textMetadata = /* @__PURE__ */ new Map();
594
653
  const reasoningMetadata2 = /* @__PURE__ */ new Map();
595
- return { ...result, stream: result.stream.pipeThrough(new TransformStream({
596
- transform(part, controller) {
597
- if (part.type === "raw") {
598
- const payload = object3(part.rawValue);
599
- terminal ||= binding.endpoint.protocol === "anthropic-messages" ? payload.type === "message_stop" : binding.endpoint.protocol === "openai-responses" ? ["response.completed", "response.incomplete", "response.failed"].includes(String(payload.type)) : Array.isArray(payload.candidates) && payload.candidates.some((candidate) => typeof object3(candidate).finishReason === "string");
600
- const next = nativeUsage(binding.endpoint.protocol, part.rawValue);
601
- if (next) raw = mergeRecords(raw, next);
602
- if (options.includeRawChunks) controller.enqueue(part);
603
- } else if (part.type === "finish") finish = part;
604
- else {
605
- if (part.type === "error") failed = true;
606
- if (part.type === "text-start" || part.type === "text-delta" || part.type === "text-end" || part.type === "reasoning-start" || part.type === "reasoning-delta" || part.type === "reasoning-end") {
607
- const metadata = part.type.startsWith("text-") ? textMetadata : reasoningMetadata2;
608
- if (part.providerMetadata) metadata.set(part.id, mergeRecords(metadata.get(part.id), part.providerMetadata));
609
- if (part.type === "text-end" || part.type === "reasoning-end") {
610
- const retained = metadata.get(part.id);
611
- metadata.delete(part.id);
612
- if (retained) part = { ...part, providerMetadata: retained };
654
+ return {
655
+ ...result,
656
+ request: nativeRequest(binding.endpoint.protocol, result.request, true),
657
+ stream: result.stream.pipeThrough(new TransformStream({
658
+ transform(part, controller) {
659
+ if (part.type === "raw") {
660
+ const payload = object3(part.rawValue);
661
+ terminal ||= binding.endpoint.protocol === "anthropic-messages" ? payload.type === "message_stop" : binding.endpoint.protocol === "openai-responses" ? ["response.completed", "response.incomplete", "response.failed"].includes(String(payload.type)) : Array.isArray(payload.candidates) && payload.candidates.some((candidate) => typeof object3(candidate).finishReason === "string");
662
+ const next = nativeUsage(binding.endpoint.protocol, part.rawValue);
663
+ if (next) raw = mergeRecords(raw, next);
664
+ if (options.includeRawChunks) controller.enqueue(part);
665
+ } else if (part.type === "finish") finish = part;
666
+ else {
667
+ if (part.type === "error") failed = true;
668
+ if (part.type === "text-start" || part.type === "text-delta" || part.type === "text-end" || part.type === "reasoning-start" || part.type === "reasoning-delta" || part.type === "reasoning-end") {
669
+ const metadata = part.type.startsWith("text-") ? textMetadata : reasoningMetadata2;
670
+ if (part.providerMetadata) metadata.set(part.id, mergeRecords(metadata.get(part.id), part.providerMetadata));
671
+ if (part.type === "text-end" || part.type === "reasoning-end") {
672
+ const retained = metadata.get(part.id);
673
+ metadata.delete(part.id);
674
+ if (retained) part = { ...part, providerMetadata: retained };
675
+ }
613
676
  }
677
+ controller.enqueue(part);
614
678
  }
615
- controller.enqueue(part);
679
+ },
680
+ flush(controller) {
681
+ if (failed) return;
682
+ if (!terminal || !finish) controller.enqueue({ type: "error", error: new Error(`Nexra ${binding.endpoint.protocol} stream ended before its terminal response`) });
683
+ else controller.enqueue(raw ? { ...finish, usage: { ...finish.usage, raw } } : finish);
616
684
  }
617
- },
618
- flush(controller) {
619
- if (failed) return;
620
- if (!terminal || !finish) controller.enqueue({ type: "error", error: new Error(`Nexra ${binding.endpoint.protocol} stream ended before its terminal response`) });
621
- else controller.enqueue(raw ? { ...finish, usage: { ...finish.usage, raw } } : finish);
622
- }
623
- })) };
685
+ }))
686
+ };
624
687
  }
625
688
  };
626
689
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byte_fluffy/nexra-sdk",
3
- "version": "0.1.0-alpha.31",
3
+ "version": "0.1.0-alpha.32",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "sideEffects": false,