From 46b3ef0c7c34b167610c441e89080e40c140131c Mon Sep 17 00:00:00 2001 From: AssemblyAI Date: Wed, 3 Jun 2026 17:05:12 -0600 Subject: [PATCH] Project import generated by Copybara. GitOrigin-RevId: a3b408d6426e98f60f9afcbb56bd32ff8605a621 --- package.json | 2 +- src/services/streaming/service.ts | 12 +++++++- src/types/streaming/index.ts | 8 ++++- tests/unit/streaming.test.ts | 49 +++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 103b952..7c3100e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "assemblyai", - "version": "4.34.0", + "version": "4.34.3", "description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.", "engines": { "node": ">=18" diff --git a/src/services/streaming/service.ts b/src/services/streaming/service.ts index 7930d47..cc72dbb 100644 --- a/src/services/streaming/service.ts +++ b/src/services/streaming/service.ts @@ -262,6 +262,10 @@ export class StreamingTranscriber { searchParams.set("prompt", this.params.prompt); } + if (this.params.agentContext) { + searchParams.set("agent_context", this.params.agentContext); + } + if (this.params.filterProfanity) { searchParams.set( "filter_profanity", @@ -274,7 +278,9 @@ export class StreamingTranscriber { "[Deprecation Warning] The speech model `u3-pro` is deprecated and will be removed in a future release. Please use `u3-rt-pro` instead.", ); } - searchParams.set("speech_model", this.params.speechModel.toString()); + if (this.params.speechModel !== undefined) { + searchParams.set("speech_model", this.params.speechModel.toString()); + } if (this.params.languageDetection !== undefined) { searchParams.set( @@ -389,6 +395,10 @@ export class StreamingTranscriber { searchParams.set("redact_pii_sub", this.params.redactPiiSub); } + if (this.params.mode !== undefined) { + searchParams.set("mode", this.params.mode); + } + if (this.params.llmGateway !== undefined) { searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway)); } diff --git a/src/types/streaming/index.ts b/src/types/streaming/index.ts index 0eb8731..e79c848 100644 --- a/src/types/streaming/index.ts +++ b/src/types/streaming/index.ts @@ -91,7 +91,8 @@ export type StreamingTranscriberParams = { keyterms?: string[]; keytermsPrompt?: string[]; prompt?: string; - speechModel: StreamingSpeechModel; + agentContext?: string; + speechModel?: StreamingSpeechModel; languageDetection?: boolean; domain?: StreamingDomain; inactivityTimeout?: number; @@ -107,6 +108,7 @@ export type StreamingTranscriberParams = { redactPii?: boolean; redactPiiPolicies?: StreamingPiiPolicy[]; redactPiiSub?: StreamingPiiSubstitution; + mode?: StreamingMode; llmGateway?: LLMGatewayConfig; webhookUrl?: string; webhookAuthHeaderName?: string; @@ -165,11 +167,14 @@ export type StreamingSpeechModel = | "universal-streaming-english" | "universal-streaming-multilingual" | "u3-rt-pro" + | "u3-rt-pro-beta-1" | "whisper-rt" | "u3-pro"; export type StreamingDomain = "medical-v1"; +export type StreamingMode = "max_accuracy" | "min_latency" | "balanced"; + export type VoiceFocusModel = "near-field" | "far-field"; export type StreamingPiiSubstitution = "hash" | "entity_name"; @@ -330,6 +335,7 @@ export type StreamingUpdateConfiguration = { format_turns?: boolean; keyterms_prompt?: string[]; prompt?: string; + agent_context?: string; filter_profanity?: boolean; interruption_delay?: number; turn_left_pad_ms?: number; diff --git a/tests/unit/streaming.test.ts b/tests/unit/streaming.test.ts index 4b86651..90af7b0 100644 --- a/tests/unit/streaming.test.ts +++ b/tests/unit/streaming.test.ts @@ -204,6 +204,37 @@ describe("streaming", () => { ); }); + it("should include agent_context in updateConfiguration message", async () => { + rt.updateConfiguration({ agent_context: "What is your account number?" }); + await expect(server).toReceiveMessage( + JSON.stringify({ + type: "UpdateConfiguration", + agent_context: "What is your account number?", + }), + ); + }); + + it("should include agent_context in connection URL", async () => { + await cleanup(); + WS.clean(); + + const wsUrl = + `${websocketBaseUrl}?token=123&sample_rate=16000` + + `&agent_context=${encodeURIComponent("What is your account number?")}` + + `&speech_model=u3-rt-pro`; + server = new WS(wsUrl); + rt = new StreamingTranscriber({ + websocketBaseUrl, + token: "123", + sampleRate: 16_000, + speechModel: "u3-rt-pro", + agentContext: "What is your account number?", + }); + onOpen = jest.fn(); + rt.on("open", onOpen); + await connect(rt, server); + }); + it("should include turn_left_pad_ms in connection URL", async () => { await cleanup(); WS.clean(); @@ -254,6 +285,24 @@ describe("streaming", () => { await connect(rt, server); }); + it("should include mode in connection URL", async () => { + await cleanup(); + WS.clean(); + + const wsUrl = `${websocketBaseUrl}?token=123&sample_rate=16000&speech_model=u3-rt-pro&mode=max_accuracy`; + server = new WS(wsUrl); + rt = new StreamingTranscriber({ + websocketBaseUrl, + token: "123", + sampleRate: 16_000, + speechModel: "u3-rt-pro", + mode: "max_accuracy", + }); + onOpen = jest.fn(); + rt.on("open", onOpen); + await connect(rt, server); + }); + it("should include whisper-rt speech model in connection URL", async () => { await cleanup(); WS.clean();