-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.ts
More file actions
163 lines (134 loc) · 5.42 KB
/
Copy pathClient.ts
File metadata and controls
163 lines (134 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* This file was auto-generated by Fern from our API Definition.
*/
import * as environments from "./environments";
import * as core from "./core";
import urlJoin from "url-join";
import * as errors from "./errors/index";
import { Numbers } from "./api/resources/numbers/client/Client";
import { Calls } from "./api/resources/calls/client/Client";
import { Usage } from "./api/resources/usage/client/Client";
import { Actions } from "./api/resources/actions/client/Client";
import { Agents } from "./api/resources/agents/client/Client";
import { Voices } from "./api/resources/voices/client/Client";
import { Webhooks } from "./api/resources/webhooks/client/Client";
import { Prompts } from "./api/resources/prompts/client/Client";
import { VectorDatabases } from "./api/resources/vectorDatabases/client/Client";
import { AccountConnections } from "./api/resources/accountConnections/client/Client";
export declare namespace VocodeClient {
interface Options {
environment?: core.Supplier<environments.VocodeEnvironment | string>;
token?: core.Supplier<core.BearerToken | undefined>;
}
interface RequestOptions {
/** The maximum time to wait for a response in seconds. */
timeoutInSeconds?: number;
/** The number of times to retry the request. Defaults to 2. */
maxRetries?: number;
/** A hook to abort the request. */
abortSignal?: AbortSignal;
}
}
export class VocodeClient {
constructor(protected readonly _options: VocodeClient.Options = {}) {}
/**
* Endpoint that serves Prometheus metrics.
*
* @param {VocodeClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @example
* await client.metricsMetricsGet()
*/
public async metricsMetricsGet(requestOptions?: VocodeClient.RequestOptions): Promise<unknown> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.VocodeEnvironment.Production,
"metrics"
),
method: "GET",
headers: {
Authorization: await this._getAuthorizationHeader(),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@vocode/vocode-api",
"X-Fern-SDK-Version": "0.0.48",
"User-Agent": "@vocode/vocode-api/0.0.48",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body;
}
if (_response.error.reason === "status-code") {
throw new errors.VocodeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
switch (_response.error.reason) {
case "non-json":
throw new errors.VocodeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.VocodeTimeoutError();
case "unknown":
throw new errors.VocodeError({
message: _response.error.errorMessage,
});
}
}
protected _numbers: Numbers | undefined;
public get numbers(): Numbers {
return (this._numbers ??= new Numbers(this._options));
}
protected _calls: Calls | undefined;
public get calls(): Calls {
return (this._calls ??= new Calls(this._options));
}
protected _usage: Usage | undefined;
public get usage(): Usage {
return (this._usage ??= new Usage(this._options));
}
protected _actions: Actions | undefined;
public get actions(): Actions {
return (this._actions ??= new Actions(this._options));
}
protected _agents: Agents | undefined;
public get agents(): Agents {
return (this._agents ??= new Agents(this._options));
}
protected _voices: Voices | undefined;
public get voices(): Voices {
return (this._voices ??= new Voices(this._options));
}
protected _webhooks: Webhooks | undefined;
public get webhooks(): Webhooks {
return (this._webhooks ??= new Webhooks(this._options));
}
protected _prompts: Prompts | undefined;
public get prompts(): Prompts {
return (this._prompts ??= new Prompts(this._options));
}
protected _vectorDatabases: VectorDatabases | undefined;
public get vectorDatabases(): VectorDatabases {
return (this._vectorDatabases ??= new VectorDatabases(this._options));
}
protected _accountConnections: AccountConnections | undefined;
public get accountConnections(): AccountConnections {
return (this._accountConnections ??= new AccountConnections(this._options));
}
protected async _getAuthorizationHeader(): Promise<string | undefined> {
const bearer = await core.Supplier.get(this._options.token);
if (bearer != null) {
return `Bearer ${bearer}`;
}
return undefined;
}
}