@byte_fluffy/nexra-sdk 0.1.0-alpha.52 → 0.1.0-alpha.54

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
@@ -4,6 +4,21 @@ TypeScript SDK for the Nexra Task API. It includes task execution, model discove
4
4
  asset upload/download, webhook verification, authoritative catalog quotes, and the
5
5
  browser-safe public model catalog.
6
6
 
7
+ ## Speech recognition
8
+
9
+ Standard file recognition uses `run("bytedance/doubao-asr-standard-v2", input)`.
10
+ Live recognition uses `transcription.stream({ model: "bytedance/doubao-asr-stream-v2",
11
+ audio, configuration, signal })`, where `audio` is an `AsyncIterable<Uint8Array>`.
12
+ The SDK owns WebSocket framing and decoding; applications own audio capture.
13
+ Each event contains `{ final, response }`; `response.result.text` is a cumulative
14
+ snapshot, not an append-only delta. End the audio iterator to finish normally;
15
+ abort the signal to cancel. Node/Bun and browser builds use separate transports.
16
+
17
+ See the [ASR integration guide](https://github.com/starrank-soft/nexra-monorepo/blob/refactor/typescript-restate-scaffold/docs/asr-sdk-integration.md)
18
+ for VibePaper/StarCut deployment, authentication and stopping semantics. This ASR
19
+ addition must be built/packaged or published before use; the previously published
20
+ `0.1.0-alpha.50` does not include the streaming client.
21
+
7
22
  ```bash
8
23
  npm install @byte_fluffy/nexra-sdk@next
9
24
  ```
@@ -120,30 +135,6 @@ const result = await nexra.tasks.wait(task.id);
120
135
  Seedance 2.0 supports 4–15 seconds and Seedance 2.5 supports 4–30 seconds.
121
136
  The existing ByteDance model IDs retain their own supplies and prices.
122
137
 
123
- ## MiniMax H3 Max
124
-
125
- `0.1.0-alpha.49` adds the official `minimax/MiniMax-H3-Max` model. It supports
126
- 480P/768P output, 5–15 seconds, and image, video and audio references.
127
-
128
- ```ts
129
- const model = "minimax/MiniMax-H3-Max";
130
- const state = await nexra.catalog.model(model, "video.generate");
131
- // The selected environment owns availability and current sale prices.
132
- console.log(state.available, state.prices);
133
-
134
- const task = await nexra.tasks.create(model, {
135
- content: [{ type: "text", role: "prompt", text: "A paper boat drifts across a rain puddle." }],
136
- duration: 5,
137
- resolution: "480P",
138
- aspect_ratio: "16:9",
139
- });
140
- const result = await nexra.tasks.wait(task.id);
141
- ```
142
-
143
- Use the selected environment's published prices for estimates. The SDK's bundled
144
- catalog describes the model contract; channel costs and sale prices remain in
145
- the live catalog.
146
-
147
138
  ## Banana 2.1
148
139
 
149
140
  Use `google/gemini-nano-banana-2.1` for Banana 2.1. The model supports
@@ -463,92 +454,6 @@ const gpt6Prices = prices.filter(({ modelId }) =>
463
454
  );
464
455
  ```
465
456
 
466
- ## Ark web search (Responses)
467
-
468
- Available since SDK `0.1.0-alpha.47` (`npm install @byte_fluffy/nexra-sdk@next`).
469
-
470
- DeepSeek V4.1 Flash (`deepseek/deepseek-v4-1-flash`), GLM 5.3 Flash
471
- (`z-ai/glm-5-3-flash`), Doubao Seed 2.1 Lite
472
- (`bytedance/doubao-seed-2-1-lite-260915`), and Kimi K3.1 Pro
473
- (`moonshot-ai/kimi-k3-1-pro`) support the Ark online content plugin through
474
- `/v1/responses`. The default SDK binding selects this endpoint. All four retain
475
- explicit Chat Completions bindings; DeepSeek also retains Messages.
476
- Search is a provider-executed tool, rather than a Chat `web_search_options` flag.
477
-
478
- ```ts
479
- import { generateText } from "ai";
480
- import { openai } from "@ai-sdk/openai";
481
- import { createNexraLanguageModel } from "@byte_fluffy/nexra-sdk/language";
482
-
483
- const result = await generateText({
484
- model: createNexraLanguageModel("deepseek/deepseek-v4-1-flash", {
485
- apiKey: process.env.NEXRA_API_KEY!,
486
- baseUrl: "https://vip-api.nexra-ai.com/v1",
487
- }),
488
- prompt: "Search for the official DeepSeek website and cite its URL.",
489
- tools: { web_search: openai.tools.webSearch() },
490
- providerOptions: {
491
- openai: { maxToolCalls: 1 },
492
- nexra: { web_search: { sources: ["search_engine"], max_keyword: 1, limit: 3 } },
493
- },
494
- maxOutputTokens: 512,
495
- maxRetries: 0,
496
- });
497
- console.log(result.text, result.sources);
498
- ```
499
-
500
- `providerOptions.nexra.web_search` preserves native tool fields such as `sources`,
501
- `max_keyword`, `limit`, and `user_location`; it requires the `web_search` tool.
502
- The same options work with `streamText`. Unpositioned native citations become
503
- URL sources; original Native bodies, raw stream events, and
504
- `finalStep.usage.raw.tool_usage_details.web_search` remain available.
505
-
506
- VIP configured search prices (CNY, checked 2026-11-01):
507
-
508
- | Content source | Channel cost / 1,000 uses | Nexra sale / 1,000 uses |
509
- | --- | ---: | ---: |
510
- | `search_engine` (default) | ¥4 | **¥4.4** |
511
- | `toutiao`, `douyin`, `moji` (each additional source) | ¥6 | ¥6.6 |
512
-
513
- A use is an actual upstream content-source search, **not an HTTP request or a
514
- returned result**. Multiple rounds, keywords, or content sources can incur
515
- multiple uses. Token charges are additional, including retrieved context.
516
- Declaring a tool does not itself incur a search fee if the model does not use
517
- it. Preauthorization reserves the configured search ceiling and settles the
518
- actual evidenced usage; set `maxToolCalls` and `max_keyword` to control that
519
- ceiling. Missing search evidence is not treated as free search.
520
-
521
- Current VIP token sale prices per million tokens:
522
-
523
- | Model | Input | Cached input | Output |
524
- | --- | ---: | ---: | ---: |
525
- | DeepSeek V4.1 Flash | ¥2.2 | ¥0.044 | ¥8.8 |
526
- | GLM 5.3 Flash | ¥0.88 | ¥0.253 | ¥3.08 |
527
- | Kimi K3.1 Pro | ¥14.3 | ¥1.43 | ¥74.8 |
528
- | Doubao Seed 2.1 Lite (non-audio input) | ¥0.88 | ¥0.176 | ¥2.97 |
529
-
530
- Seed audio input is ¥13.2/million tokens; cached audio input is ¥2.64/million.
531
- For Ark audio/video prompts in the AI SDK adapter, select
532
- `protocol: "openai-chat-completions"`; its native media parts retain their order. Kimi media requires bytes or Base64
533
- data URLs; the Chat binding derives URL support from the Native schema.
534
- The Responses search example above uses text. Native Responses media fields
535
- remain documented by each model's selected endpoint schema.
536
-
537
- GLM and Kimi K3.1 Pro thinking is always on. Use `reasoning: "low"` for minimum effort;
538
- `reasoning: "none"` fails locally. Native `none`/`minimal` effort aliases do not
539
- mean that these models can turn thinking off. Kimi does not use a `thinking`
540
- parameter. Its Responses endpoint permits `toolChoice: "auto"` (default) or
541
- `"none"`; forcing a particular tool or requiring a tool is rejected before
542
- fetch. With auto selection, search is billed only when actually used.
543
-
544
- These are the configured channel prices;
545
- the SDK does not dynamically apply upstream off-peak discounts. Provider account
546
- free quotas do not automatically make Nexra requests free. The selected plugin
547
- is separate from Doubao Search Custom; no Custom search service is used here.
548
- Always read the selected environment's live catalog prices before estimating
549
- charges. Official references: [online content plugin pricing](https://ark.volcengine.com/region:cn-beijing/docs/online-content-plugin-pricing)
550
- and [model pricing](https://console.volcengine.com/ark/region:cn-beijing/docs/model-pricing).
551
-
552
457
  ## Directory layout
553
458
 
554
459
  ```
package/dist/catalog.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as JsonObject } from './json-Cz0MkWQn.js';
2
- import { H as HttpTransport, N as NexraCatalogChangeParams, a as NexraCatalogChangePage, b as NexraCatalogModelState, c as NexraSalePriceList, C as CreateNexraQuoteRequest, d as NexraQuote, e as CreateNexraDisplayQuoteBatchRequest, f as NexraDisplayQuoteBatch, g as NexraCatalogRevision, h as NexraModelSpec, i as NexraModelEndpointSpec, j as NexraModelSpecFilter } from './media-geometry-COln1N_2.js';
3
- export { M as MediaGeometryField, k as MediaGeometryProjection, l as NexraBillingCurrency, m as NexraCatalogModelIdentity, n as NexraModelOperation, o as NexraSalePrice, p as NexraSettlement, U as UnifiedMediaGeometry, q as applyMediaGeometry, r as decodeMediaGeometry, s as encodeMediaGeometry, t as projectMediaGeometry } from './media-geometry-COln1N_2.js';
1
+ import { J as JsonObject } from './json-dnsDzk-s.js';
2
+ import { H as HttpTransport, A as NexraCatalogChangeParams, B as NexraCatalogChangePage, D as NexraCatalogModelState, t as NexraSalePriceList, a as CreateNexraQuoteRequest, r as NexraQuote, C as CreateNexraDisplayQuoteBatchRequest, m as NexraDisplayQuoteBatch, l as NexraCatalogRevision, p as NexraModelSpec, E as NexraModelEndpointSpec, q as NexraModelSpecFilter } from './media-geometry-z7fXaDSN.js';
3
+ export { M as MediaGeometryField, b as MediaGeometryProjection, k as NexraBillingCurrency, G as NexraCatalogModelIdentity, o as NexraModelOperation, s as NexraSalePrice, u as NexraSettlement, U as UnifiedMediaGeometry, w as applyMediaGeometry, x as decodeMediaGeometry, y as encodeMediaGeometry, z as projectMediaGeometry } from './media-geometry-z7fXaDSN.js';
4
4
 
5
5
  declare function formatModelDisplayName(displayName: string, identity?: {
6
6
  modelId: string;
package/dist/catalog.js CHANGED
@@ -9,8 +9,8 @@ import {
9
9
  listModelSpecs,
10
10
  projectMediaGeometry,
11
11
  resolveNexraLanguageReasoning
12
- } from "./chunk-V3KBU3J5.js";
13
- import "./chunk-LEZWVFQH.js";
12
+ } from "./chunk-MLDFBO2A.js";
13
+ import "./chunk-IOGCXMW3.js";
14
14
  export {
15
15
  CatalogClient,
16
16
  applyMediaGeometry,
@@ -10,13 +10,13 @@ var MEDIA_KINDS = [
10
10
 
11
11
  // ../contracts/src/public-error-catalog.ts
12
12
  var PUBLIC_ERROR_CATALOG = {
13
- invalid_model_quotation_selection: { "zh-CN": "\u6240\u9009\u6A21\u578B\u6216\u6E20\u9053\u5DF2\u4E0D\u53EF\u5BFC\u51FA\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u540E\u91CD\u8BD5\u3002", en: "The selected models or channels are no longer available for export. Update your selection and try again." },
14
13
  api_key_spending_limit_exceeded: { "zh-CN": "\u5F53\u524D\u5BC6\u94A5\u7684\u5269\u4F59\u6D88\u8D39\u989D\u5EA6\u4E0D\u8DB3\uFF0C\u8BF7\u8054\u7CFB\u7EC4\u7EC7\u7BA1\u7406\u5458\u589E\u52A0\u989D\u5EA6\u3002", en: "This key has insufficient remaining spending allowance. Ask an organization administrator to increase it." },
15
14
  organization_key_limit_invalid: { "zh-CN": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u6D88\u8D39\u989D\u5EA6\uFF0C\u91D1\u989D\u6700\u591A\u4FDD\u7559 8 \u4F4D\u5C0F\u6570\uFF1B\u8C03\u6574\u91D1\u989D\u987B\u5927\u4E8E 0\u3002", en: "Enter a valid spending allowance with up to 8 decimal places. An adjustment must be greater than zero." },
16
15
  organization_key_limit_unset: { "zh-CN": "\u5F53\u524D\u5BC6\u94A5\u5C1A\u672A\u8BBE\u7F6E\u6D88\u8D39\u989D\u5EA6\uFF0C\u8BF7\u5148\u589E\u52A0\u989D\u5EA6\u540E\u518D\u51CF\u5C11\u3002", en: "This key has no spending allowance configured. Set it with an increase before decreasing it." },
17
16
  organization_key_limit_below_committed: { "zh-CN": "\u8C03\u6574\u540E\u7684\u6D88\u8D39\u989D\u5EA6\u4E0D\u80FD\u4F4E\u4E8E\u5DF2\u6D88\u8D39\u4E0E\u8BF7\u6C42\u9884\u5360\u7684\u5408\u8BA1\u91D1\u989D\u3002", en: "The resulting allowance cannot be less than settled spending plus pending reservations." },
18
17
  organization_key_limit_exceeds_wallet: { "zh-CN": "\u5BC6\u94A5\u53EF\u7528\u6D88\u8D39\u989D\u5EA6\u4E0D\u80FD\u8D85\u8FC7\u94B1\u5305\u5F53\u524D\u53EF\u7528\u4F59\u989D\uFF0C\u8BF7\u8C03\u6574\u989D\u5EA6\u6216\u5145\u503C\u540E\u91CD\u8BD5\u3002", en: "The key's available spending allowance cannot exceed the wallet's current available balance. Reduce it or add funds." },
19
18
  organization_key_limit_conflict: { "zh-CN": "\u8FD9\u6B21\u989D\u5EA6\u64CD\u4F5C\u5DF2\u88AB\u5904\u7406\uFF0C\u8BF7\u5173\u95ED\u540E\u91CD\u65B0\u6253\u5F00\u518D\u8BD5\u3002", en: "This allowance change has already been processed. Close and reopen the form to try again." },
19
+ invalid_model_quotation_selection: { "zh-CN": "\u6240\u9009\u6A21\u578B\u6216\u6E20\u9053\u5DF2\u4E0D\u53EF\u5BFC\u51FA\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u540E\u91CD\u8BD5\u3002", en: "The selected models or channels are no longer available for export. Update your selection and try again." },
20
20
  google_channel_rate_limited: { "zh-CN": "\u5F53\u524D\u6587\u672C\u6A21\u578B\u670D\u52A1\u7E41\u5FD9\u6216\u53D7\u5230\u9650\u6D41\uFF08429\uFF09\u3002\u8BF7\u7A0D\u540E\u518D\u8BD5\uFF1B\u82E5\u6301\u7EED\u51FA\u73B0\uFF0C\u53EF\u5207\u6362\u5176\u4ED6\u6587\u672C\u6A21\u578B\uFF0C\u518D\u53D1\u9001\u6D88\u606F\u7EE7\u7EED\u3002", en: "The current text model service is busy or rate limited (429). Try again later; if the problem persists, switch to another text model and send a message to continue." },
21
21
  queue_wait_timeout: { "zh-CN": "\u4EFB\u52A1\u6392\u961F\u7B49\u5F85\u6267\u884C\u8D85\u8FC7\u65F6\u9650\uFF0C\u5C1A\u672A\u63D0\u4EA4\u7ED9\u6A21\u578B\u670D\u52A1\u3002\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF1B\u6301\u7EED\u8D85\u65F6\u65F6\u51ED\u8BF7\u6C42 ID \u8054\u7CFB\u5E73\u53F0\u7BA1\u7406\u5458\u3002", en: "The task exceeded its queue wait limit before submission to the model service. Try again later; contact a platform administrator with the request ID if queue timeouts persist." },
22
22
  task_execution_timeout: { "zh-CN": "\u4EFB\u52A1\u8D85\u8FC7\u603B\u65F6\u9650\uFF0C\u5DF2\u7ED3\u675F\u3002\u4E0A\u6E38\u53EF\u80FD\u4ECD\u5728\u5904\u7406\uFF0C\u8BF7\u5148\u6838\u5BF9\u539F\u8BF7\u6C42\u7ED3\u679C\uFF0C\u907F\u514D\u91CD\u590D\u63D0\u4EA4\u3002", en: "The task exceeded its total time limit and has ended. The upstream service may still be processing it; check the original request before submitting again." },
@@ -57,9 +57,6 @@ var PUBLIC_ERROR_CATALOG = {
57
57
  organization_invitation_unavailable: { "zh-CN": "\u9080\u8BF7\u94FE\u63A5\u65E0\u6548\u3001\u5DF2\u8FC7\u671F\u6216\u5DF2\u505C\u7528\uFF0C\u8BF7\u8054\u7CFB\u7EC4\u7EC7\u7BA1\u7406\u5458\u83B7\u53D6\u65B0\u94FE\u63A5\u3002", en: "This invitation link is invalid, expired, or disabled. Ask the organization administrator for a new link." },
58
58
  organization_member_removed: { "zh-CN": "\u4F60\u5DF2\u88AB\u79FB\u51FA\u8BE5\u7EC4\u7EC7\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u901A\u8FC7\u7528\u6237 ID \u91CD\u65B0\u6DFB\u52A0\u3002", en: "You were removed from this organization. Ask an administrator to add your user ID again." },
59
59
  organization_default_key_unavailable: { "zh-CN": "\u5F53\u524D\u7EC4\u7EC7\u6CA1\u6709\u53EF\u7528\u7684 API Key\uFF0C\u8BF7\u8054\u7CFB\u7EC4\u7EC7\u7BA1\u7406\u5458\u3002", en: "This organization has no available API key. Contact an organization administrator." },
60
- organization_key_assignment_required: { "zh-CN": "\u6CA1\u6709\u5DF2\u5206\u914D\u7684\u53EF\u7528\u5BC6\u94A5\uFF0C\u8BF7\u8054\u7CFB\u7EC4\u7EC7\u7BA1\u7406\u5458\u5206\u914D\u3002", en: "No available key is assigned to you. Ask an organization administrator to assign one." },
61
- organization_key_selection_required: { "zh-CN": "\u8BF7\u5148\u5728 Nexra \u4E2D\u9009\u62E9\u672C\u6B21\u8C03\u7528\u4F7F\u7528\u7684\u5BC6\u94A5\u3002", en: "Select a key in Nexra before making this request." },
62
- organization_execution_key_unavailable: { "zh-CN": "\u6B64\u524D\u9009\u7528\u7684\u5BC6\u94A5\u5DF2\u4E0D\u53EF\u7528\u6216\u6743\u9650\u5DF2\u64A4\u56DE\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6216\u8054\u7CFB\u7EC4\u7EC7\u7BA1\u7406\u5458\u3002", en: "Your selected key is unavailable or access was withdrawn. Select another key or contact an organization administrator." },
63
60
  organization_default_key_change_unavailable: { "zh-CN": "\u81F3\u5C11\u9700\u8981\u4E24\u4E2A\u53EF\u7528\u7684\u7EC4\u7EC7 Key \u624D\u80FD\u66F4\u6539\u9ED8\u8BA4 Key\u3002", en: "At least two available organization keys are required to change the default key." },
64
61
  personal_key_unavailable: { "zh-CN": "\u5F53\u524D\u4E2A\u4EBA\u8EAB\u4EFD\u6CA1\u6709\u53EF\u7528\u7684 API \u5BC6\u94A5\uFF0C\u8BF7\u5148\u521B\u5EFA\u4E2A\u4EBA\u5BC6\u94A5\u3002", en: "Your personal identity has no available API key. Create a personal key first." },
65
62
  api_key_not_found: { "zh-CN": "\u672A\u627E\u5230\u53EF\u64CD\u4F5C\u7684 API Key\uFF0C\u6216\u8BE5 Key \u4E0D\u5C5E\u4E8E\u5F53\u524D\u8BBF\u95EE\u8303\u56F4\u3002\u8BF7\u5237\u65B0 Key \u5217\u8868\u5E76\u6838\u5BF9 Key ID\u3002", en: "No accessible API key was found for this operation. Refresh the key list and check the key ID." },
@@ -694,6 +691,8 @@ var NEXRA_MEDIA_INPUT_SCHEMAS = Object.freeze({
694
691
  "image.upscale": inputSchema(
695
692
  [mediaPartSchema("image", ["source"])],
696
693
  {
694
+ enable_hdr: { type: "boolean", "x-ui": { order: 14, control: "switch" } },
695
+ enable_wb: { type: "boolean", "x-ui": { order: 15, control: "switch" } },
697
696
  scale: { type: "number", exclusiveMinimum: 1, "x-ui": { order: 10, control: "number" } },
698
697
  resolution: { type: "string", minLength: 1, "x-ui": { order: 11 } },
699
698
  output_format: { type: "string", minLength: 1, "x-ui": { order: 12 } },
@@ -704,6 +703,8 @@ var NEXRA_MEDIA_INPUT_SCHEMAS = Object.freeze({
704
703
  "video.upscale": inputSchema(
705
704
  [mediaPartSchema("video", ["source"])],
706
705
  {
706
+ vid: { type: "string", minLength: 1, "x-ui": { order: 14 } },
707
+ config: { type: "string", "x-ui": { order: 15 } },
707
708
  source_duration: { type: "number", exclusiveMinimum: 0, "x-ui": { order: 9, control: "number" } },
708
709
  scale: { type: "number", exclusiveMinimum: 1, "x-ui": { order: 10, control: "number" } },
709
710
  resolution: { type: "string", minLength: 1, "x-ui": { order: 11 } },
@@ -714,7 +715,29 @@ var NEXRA_MEDIA_INPUT_SCHEMAS = Object.freeze({
714
715
  ),
715
716
  "video.segment": inputSchema(
716
717
  [textPartSchema(["prompt"]), mediaPartSchema("video", ["source"])],
717
- { resolution: { type: "string", minLength: 1, "x-ui": { order: 10 } } },
718
+ {
719
+ resolution: { type: "string", minLength: 1, "x-ui": { order: 10 } },
720
+ mode: { type: "string", enum: ["preview", "track"] },
721
+ preview_time_ms: { type: "integer", minimum: 0 },
722
+ prompts: { type: "array", minItems: 1, items: {
723
+ type: "object",
724
+ properties: {
725
+ time_ms: { type: "integer", minimum: 0 },
726
+ points: { type: "array", minItems: 1, items: {
727
+ type: "object",
728
+ properties: {
729
+ x: { type: "number", minimum: 0, maximum: 1 },
730
+ y: { type: "number", minimum: 0, maximum: 1 },
731
+ label: { type: "integer", enum: [0, 1] }
732
+ },
733
+ required: ["x", "y", "label"],
734
+ additionalProperties: false
735
+ } }
736
+ },
737
+ required: ["time_ms", "points"],
738
+ additionalProperties: false
739
+ } }
740
+ },
718
741
  { minItems: 2, maxItems: 2 }
719
742
  ),
720
743
  "video.depth": inputSchema(
@@ -854,6 +877,84 @@ function isTerminalTaskStatus(status) {
854
877
  return status === "succeeded" || status === "failed" || status === "cancelled";
855
878
  }
856
879
 
880
+ // ../contracts/src/volcengine-asr.ts
881
+ var ASR_SENTENCE_MAX_SECONDS = 60;
882
+ function asrInputSecondsLimit(path) {
883
+ return path === "/api/v3/sauc/bigmodel_nostream" ? ASR_SENTENCE_MAX_SECONDS : void 0;
884
+ }
885
+ var ASR_MAX_FRAME_BYTES = 8 * 1024 * 1024;
886
+ function parseVolcengineAsrFrame(bytes) {
887
+ if (bytes.byteLength < 8 || bytes.byteLength > ASR_MAX_FRAME_BYTES) throw new Error("Invalid ASR frame size");
888
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
889
+ const headerSize = (bytes[0] & 15) * 4;
890
+ if (bytes[0] >> 4 !== 1 || headerSize < 4 || headerSize + 4 > bytes.length) throw new Error("Invalid ASR frame header");
891
+ const type = bytes[1] >> 4, flags = bytes[1] & 15, serialization = bytes[2] >> 4, compression = bytes[2] & 15;
892
+ if (![1, 2, 9, 15].includes(type) || flags > 3 || ![0, 1].includes(serialization) || ![0, 1].includes(compression)) throw new Error("Unsupported ASR frame protocol");
893
+ let offset = headerSize, sequence, errorCode;
894
+ if (type === 15 || flags & 1) {
895
+ if (offset + 8 > bytes.length) throw new Error("Truncated ASR sequence/error");
896
+ if (type === 15) errorCode = view.getUint32(offset);
897
+ else sequence = view.getInt32(offset);
898
+ offset += 4;
899
+ }
900
+ const size = view.getUint32(offset);
901
+ offset += 4;
902
+ if (size !== bytes.length - offset) throw new Error("Invalid ASR payload length");
903
+ return { type, flags, serialization, compression, payload: bytes.subarray(offset), ...sequence === void 0 ? {} : { sequence }, ...errorCode === void 0 ? {} : { errorCode } };
904
+ }
905
+ async function decodeVolcengineAsrFrame(bytes) {
906
+ const frame = parseVolcengineAsrFrame(bytes);
907
+ if (frame.compression === 0) return frame;
908
+ const reader = new Blob([new Uint8Array(frame.payload)]).stream().pipeThrough(new DecompressionStream("gzip")).getReader();
909
+ const chunks = [];
910
+ let length = 0;
911
+ try {
912
+ for (; ; ) {
913
+ const chunk = await reader.read();
914
+ if (chunk.done) break;
915
+ length += chunk.value.byteLength;
916
+ if (length > ASR_MAX_FRAME_BYTES) {
917
+ await reader.cancel();
918
+ throw new Error("ASR response is too large");
919
+ }
920
+ chunks.push(chunk.value);
921
+ }
922
+ } finally {
923
+ reader.releaseLock();
924
+ }
925
+ const payload = new Uint8Array(length);
926
+ let offset = 0;
927
+ for (const chunk of chunks) {
928
+ payload.set(chunk, offset);
929
+ offset += chunk.byteLength;
930
+ }
931
+ return { ...frame, payload };
932
+ }
933
+ function volcengineAsrFrameJson(frame) {
934
+ if (frame.serialization !== 1) throw new Error("ASR configuration/result must be JSON");
935
+ const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(frame.payload));
936
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("ASR JSON must be an object");
937
+ return value;
938
+ }
939
+ function encodeVolcengineAsrFrame(type, payload, options = {}) {
940
+ const bytes = new Uint8Array(8 + (options.sequence === void 0 ? 0 : 4) + payload.length);
941
+ bytes.set([
942
+ 17,
943
+ type << 4 | (options.final ? 2 : 0) | (options.sequence === void 0 ? 0 : 1),
944
+ (options.json ? 16 : 0) | (options.compression ?? 0),
945
+ 0
946
+ ]);
947
+ const view = new DataView(bytes.buffer);
948
+ let offset = 4;
949
+ if (options.sequence !== void 0) {
950
+ view.setInt32(offset, options.sequence);
951
+ offset += 4;
952
+ }
953
+ view.setUint32(offset, payload.length);
954
+ bytes.set(payload, offset + 4);
955
+ return bytes;
956
+ }
957
+
857
958
  // ../contracts/src/usage-query-reference.ts
858
959
  var USAGE_QUERY_LIST_FILTERS = [
859
960
  "userIds",
@@ -916,8 +1017,8 @@ function sortRatioDisplayOrder(values) {
916
1017
  return [...values].sort(compareRatioDisplayOrder);
917
1018
  }
918
1019
 
919
- // ../contracts/src/volcengine-asr.ts
920
- var ASR_MAX_FRAME_BYTES = 8 * 1024 * 1024;
1020
+ // ../contracts/src/index.ts
1021
+ var ORGANIZATION_HEADER = "x-nexra-organization-id";
921
1022
 
922
1023
  export {
923
1024
  MEDIA_KINDS,
@@ -941,5 +1042,11 @@ export {
941
1042
  TASK_STATUSES,
942
1043
  createTaskRequest,
943
1044
  isTerminalTaskStatus,
944
- sortRatioDisplayOrder
1045
+ sortRatioDisplayOrder,
1046
+ asrInputSecondsLimit,
1047
+ ASR_MAX_FRAME_BYTES,
1048
+ decodeVolcengineAsrFrame,
1049
+ volcengineAsrFrameJson,
1050
+ encodeVolcengineAsrFrame,
1051
+ ORGANIZATION_HEADER
945
1052
  };