From 93ba5ae6e2058d2f3a5b90836c77e90cb18b4a3c Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 31 Oct 2024 10:05:22 -0700 Subject: [PATCH] feat: configurable websocket url --- src/lib/constants.ts | 9 +++++++++ src/lib/types/DeepgramClientOptions.ts | 1 + src/packages/AgentLiveClient.ts | 14 +++----------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index a464e83..b41c091 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -36,6 +36,7 @@ export const DEFAULT_HEADERS = { }; export const DEFAULT_URL = "https://api.deepgram.com"; +export const DEFAULT_AGENT_URL = "wss://agent.deepgram.com"; export const DEFAULT_GLOBAL_OPTIONS: Partial = { fetch: { options: { url: DEFAULT_URL, headers: DEFAULT_HEADERS } }, @@ -44,8 +45,16 @@ export const DEFAULT_GLOBAL_OPTIONS: Partial = { }, }; +export const DEFAULT_AGENT_OPTIONS: Partial = { + fetch: { options: { url: DEFAULT_URL, headers: DEFAULT_HEADERS } }, + websocket: { + options: { url: DEFAULT_AGENT_URL, _nodeOnlyHeaders: DEFAULT_HEADERS }, + }, +}; + export const DEFAULT_OPTIONS: DefaultClientOptions = { global: DEFAULT_GLOBAL_OPTIONS, + agent: DEFAULT_AGENT_OPTIONS, }; export enum SOCKET_STATES { diff --git a/src/lib/types/DeepgramClientOptions.ts b/src/lib/types/DeepgramClientOptions.ts index 808dc66..c5d4eed 100644 --- a/src/lib/types/DeepgramClientOptions.ts +++ b/src/lib/types/DeepgramClientOptions.ts @@ -64,6 +64,7 @@ export interface DeepgramClientOptions { onprem?: NamespaceOptions; read?: NamespaceOptions; speak?: NamespaceOptions; + agent?: NamespaceOptions; /** * @deprecated as of 3.4, use a namespace like `global` instead diff --git a/src/packages/AgentLiveClient.ts b/src/packages/AgentLiveClient.ts index 625b03c..37a8bb5 100644 --- a/src/packages/AgentLiveClient.ts +++ b/src/packages/AgentLiveClient.ts @@ -1,6 +1,6 @@ +import { DEFAULT_AGENT_URL } from "../lib/constants.js"; import { AgentEvents } from "../lib/enums/AgentEvents"; -import type { AgentLiveSchema, SpeakModel } from "../lib/types"; -import type { DeepgramClientOptions } from "../lib/types"; +import type { AgentLiveSchema, SpeakModel, DeepgramClientOptions } from "../lib/types"; import { AbstractLiveClient } from "./AbstractLiveClient"; export class AgentLiveClient extends AbstractLiveClient { @@ -8,16 +8,8 @@ export class AgentLiveClient extends AbstractLiveClient { constructor(options: DeepgramClientOptions, endpoint: string = "/agent") { super(options); - /** - * According to the docs, this is the correct base URL for the Agent API. - * TODO: Make configurable for self-hosted customers. - */ - this.baseUrl = "wss://agent.deepgram.com"; + this.baseUrl = options.agent?.websocket?.options?.url ?? DEFAULT_AGENT_URL; - /** - * TODO: Not sure we should send the options here. - * Think that needs to happen after Websocket is open. - */ this.connect({}, endpoint); }