|
1 | 1 | import { CortiClient as BaseCortiClient } from "../Client.js"; |
| 2 | +import * as core from "../core/index.js"; |
2 | 3 | import type * as environments from "../environments.js"; |
| 4 | +import { CustomAgents } from "./agents/CustomAgents.js"; |
3 | 5 | import { CortiAuth } from "./auth/CortiAuth.js"; |
4 | 6 | import { CustomStream } from "./stream/CustomStream.js"; |
5 | 7 | import { CustomTranscribe } from "./transcribe/CustomTranscribe.js"; |
6 | 8 | import { authToBaseOptions } from "./utils/authToBaseOptions.js"; |
7 | 9 | import { type Environment, getEnvironment } from "./utils/environment.js"; |
| 10 | + |
8 | 11 | import { resolveClientOptions } from "./utils/resolveClientOptions.js"; |
9 | 12 | import { setDefaultWithCredentials } from "./utils/withCredentialsConfig.js"; |
10 | 13 |
|
@@ -41,6 +44,7 @@ export class CortiClient extends BaseCortiClient { |
41 | 44 | protected override _auth: CortiAuth | undefined; |
42 | 45 | protected override _stream: CustomStream | undefined; |
43 | 46 | protected override _transcribe: CustomTranscribe | undefined; |
| 47 | + protected override _agents: CustomAgents | undefined; |
44 | 48 |
|
45 | 49 | private readonly _encodeHeadersAsWsProtocols: boolean | undefined; |
46 | 50 |
|
@@ -82,4 +86,33 @@ export class CortiClient extends BaseCortiClient { |
82 | 86 | encodeHeadersAsWsProtocols: this._encodeHeadersAsWsProtocols, |
83 | 87 | })); |
84 | 88 | } |
| 89 | + |
| 90 | + public override get agents(): CustomAgents { |
| 91 | + return (this._agents ??= new CustomAgents(this._options)); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Retrieves authentication headers for API requests. |
| 96 | + * |
| 97 | + * This method returns a Headers object containing the Authorization header with a valid |
| 98 | + * bearer token and the Tenant-Name header. The token is automatically refreshed if needed. |
| 99 | + * |
| 100 | + * @returns A Promise that resolves to a Headers object with Authorization and Tenant-Name headers |
| 101 | + * |
| 102 | + * @example |
| 103 | + * ```typescript |
| 104 | + * const client = new CortiClient({ ... }); |
| 105 | + * const headers = await client.getAuthHeaders(); |
| 106 | + * console.log(headers.get("Authorization")); // "Bearer ..." |
| 107 | + * console.log(headers.get("Tenant-Name")); // "your-tenant" |
| 108 | + * ``` |
| 109 | + */ |
| 110 | + public getAuthHeaders = async (): Promise<Headers> => { |
| 111 | + const req = await this._options.authProvider.getAuthRequest(); |
| 112 | + |
| 113 | + return new Headers({ |
| 114 | + ...(req.headers ?? {}), |
| 115 | + "Tenant-Name": await core.Supplier.get(this._options.tenantName), |
| 116 | + }); |
| 117 | + }; |
85 | 118 | } |
0 commit comments