Skip to content

Commit

Permalink
feat: configurable websocket url
Browse files Browse the repository at this point in the history
  • Loading branch information
naomi-lgbt committed Oct 31, 2024
1 parent 93c1feb commit 93ba5ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultNamespaceOptions> = {
fetch: { options: { url: DEFAULT_URL, headers: DEFAULT_HEADERS } },
Expand All @@ -44,8 +45,16 @@ export const DEFAULT_GLOBAL_OPTIONS: Partial<DefaultNamespaceOptions> = {
},
};

export const DEFAULT_AGENT_OPTIONS: Partial<DefaultNamespaceOptions> = {
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 {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/DeepgramClientOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions src/packages/AgentLiveClient.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
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 {
public namespace: string = "agent";

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);
}

Expand Down

0 comments on commit 93ba5ae

Please sign in to comment.