galileo-generated 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-please-manifest.json +1 -1
- package/dist/commonjs/hooks/cert-management.d.ts +73 -0
- package/dist/commonjs/hooks/cert-management.d.ts.map +1 -0
- package/dist/commonjs/hooks/cert-management.js +258 -0
- package/dist/commonjs/hooks/cert-management.js.map +1 -0
- package/dist/commonjs/hooks/error-cleaner.d.ts.map +1 -1
- package/dist/commonjs/hooks/error-cleaner.js +0 -4
- package/dist/commonjs/hooks/error-cleaner.js.map +1 -1
- package/dist/commonjs/hooks/registration.d.ts.map +1 -1
- package/dist/commonjs/hooks/registration.js +4 -0
- package/dist/commonjs/hooks/registration.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/lib/galileo-config.d.ts +105 -14
- package/dist/commonjs/lib/galileo-config.d.ts.map +1 -1
- package/dist/commonjs/lib/galileo-config.js +168 -12
- package/dist/commonjs/lib/galileo-config.js.map +1 -1
- package/dist/commonjs/lib/sdk-logger.d.ts +26 -0
- package/dist/commonjs/lib/sdk-logger.d.ts.map +1 -0
- package/dist/commonjs/lib/sdk-logger.js +85 -0
- package/dist/commonjs/lib/sdk-logger.js.map +1 -0
- package/dist/commonjs/tests/hooks/cert-management.test.d.ts +2 -0
- package/dist/commonjs/tests/hooks/cert-management.test.d.ts.map +1 -0
- package/dist/commonjs/tests/hooks/cert-management.test.js +794 -0
- package/dist/commonjs/tests/hooks/cert-management.test.js.map +1 -0
- package/dist/commonjs/tests/lib/galileo-config.test.js +101 -0
- package/dist/commonjs/tests/lib/galileo-config.test.js.map +1 -1
- package/dist/commonjs/tests/lib/sdk-logger.test.d.ts +2 -0
- package/dist/commonjs/tests/lib/sdk-logger.test.d.ts.map +1 -0
- package/dist/commonjs/tests/lib/sdk-logger.test.js +401 -0
- package/dist/commonjs/tests/lib/sdk-logger.test.js.map +1 -0
- package/dist/commonjs/types/sdk-logger.types.d.ts +35 -0
- package/dist/commonjs/types/sdk-logger.types.d.ts.map +1 -0
- package/dist/commonjs/types/sdk-logger.types.js +17 -0
- package/dist/commonjs/types/sdk-logger.types.js.map +1 -0
- package/dist/esm/hooks/cert-management.d.ts +73 -0
- package/dist/esm/hooks/cert-management.d.ts.map +1 -0
- package/dist/esm/hooks/cert-management.js +254 -0
- package/dist/esm/hooks/cert-management.js.map +1 -0
- package/dist/esm/hooks/error-cleaner.d.ts.map +1 -1
- package/dist/esm/hooks/error-cleaner.js +0 -4
- package/dist/esm/hooks/error-cleaner.js.map +1 -1
- package/dist/esm/hooks/registration.d.ts.map +1 -1
- package/dist/esm/hooks/registration.js +4 -0
- package/dist/esm/hooks/registration.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/galileo-config.d.ts +105 -14
- package/dist/esm/lib/galileo-config.d.ts.map +1 -1
- package/dist/esm/lib/galileo-config.js +167 -12
- package/dist/esm/lib/galileo-config.js.map +1 -1
- package/dist/esm/lib/sdk-logger.d.ts +26 -0
- package/dist/esm/lib/sdk-logger.d.ts.map +1 -0
- package/dist/esm/lib/sdk-logger.js +78 -0
- package/dist/esm/lib/sdk-logger.js.map +1 -0
- package/dist/esm/tests/hooks/cert-management.test.d.ts +2 -0
- package/dist/esm/tests/hooks/cert-management.test.d.ts.map +1 -0
- package/dist/esm/tests/hooks/cert-management.test.js +792 -0
- package/dist/esm/tests/hooks/cert-management.test.js.map +1 -0
- package/dist/esm/tests/lib/galileo-config.test.js +101 -0
- package/dist/esm/tests/lib/galileo-config.test.js.map +1 -1
- package/dist/esm/tests/lib/sdk-logger.test.d.ts +2 -0
- package/dist/esm/tests/lib/sdk-logger.test.d.ts.map +1 -0
- package/dist/esm/tests/lib/sdk-logger.test.js +399 -0
- package/dist/esm/tests/lib/sdk-logger.test.js.map +1 -0
- package/dist/esm/types/sdk-logger.types.d.ts +35 -0
- package/dist/esm/types/sdk-logger.types.d.ts.map +1 -0
- package/dist/esm/types/sdk-logger.types.js +14 -0
- package/dist/esm/types/sdk-logger.types.js.map +1 -0
- package/package.json +5 -3
- package/src/hooks/cert-management.ts +288 -0
- package/src/hooks/error-cleaner.ts +0 -7
- package/src/hooks/registration.ts +5 -0
- package/src/index.ts +2 -1
- package/src/lib/galileo-config.ts +232 -17
- package/src/lib/sdk-logger.ts +91 -0
- package/src/tests/hooks/cert-management.test.ts +958 -0
- package/src/tests/lib/galileo-config.test.ts +110 -0
- package/src/tests/lib/sdk-logger.test.ts +518 -0
- package/src/types/sdk-logger.types.ts +43 -0
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Galileo config singleton:
|
|
2
|
+
* Galileo config singleton: environment-aware across Node.js, Deno, and browser runtimes.
|
|
3
|
+
*
|
|
4
|
+
* Configuration resolution order (highest to lowest priority):
|
|
5
|
+
* 1. Explicit constructor overrides (via get() method)
|
|
6
|
+
* 2. Environment variables (GALILEO_* or NODE_TLS_* for Node/Deno)
|
|
7
|
+
* 3. Browser global (__GALILEO_AUTH__) or localStorage (galileo_auth_config)
|
|
8
|
+
* 4. Defaults (consoleUrl: "https://console.galileo.ai", apiUrl derived from consoleUrl)
|
|
9
|
+
*
|
|
10
|
+
* Supports multiple authentication methods:
|
|
11
|
+
* - API key: GALILEO_API_KEY
|
|
12
|
+
* - Username/password: GALILEO_USERNAME + GALILEO_PASSWORD
|
|
13
|
+
* - SSO: GALILEO_SSO_ID_TOKEN + GALILEO_SSO_PROVIDER
|
|
14
|
+
*
|
|
15
|
+
* TLS/Certificate configuration:
|
|
16
|
+
* - CA certificates: GALILEO_CA_CERT_PATH or GALILEO_CA_CERT_CONTENT
|
|
17
|
+
* - Client certificates (mTLS): GALILEO_CLIENT_CERT_PATH + GALILEO_CLIENT_KEY_PATH
|
|
18
|
+
* - Certificate validation: GALILEO_REJECT_UNAUTHORIZED or NODE_TLS_REJECT_UNAUTHORIZED
|
|
19
|
+
*
|
|
20
|
+
* For certificate paths in Node.js, use GALILEO_CA_CERT_PATH (replaces default CA list).
|
|
21
|
+
* To append CA certs to the default list, use NODE_EXTRA_CA_CERTS instead.
|
|
3
22
|
*/
|
|
4
23
|
|
|
5
24
|
import { isBrowserLike, isDeno, isNodeLike } from "./runtime.js";
|
|
25
|
+
import { LOG_LEVEL_PRIORITY } from "../types/sdk-logger.types.js";
|
|
26
|
+
import type { LogLevel } from "../types/sdk-logger.types.js";
|
|
6
27
|
|
|
7
28
|
/**
|
|
8
|
-
* Configuration input for the Galileo SDK
|
|
29
|
+
* Configuration input for the Galileo SDK.
|
|
30
|
+
*
|
|
31
|
+
* Includes URLs (console, API), authentication credentials (API key, username/password, SSO tokens),
|
|
32
|
+
* project/log stream identifiers, logging configuration, and TLS/certificate settings.
|
|
33
|
+
*
|
|
34
|
+
* All properties are optional; values resolve from environment variables or browser storage by default.
|
|
9
35
|
*/
|
|
10
36
|
export type GalileoConfigInput = {
|
|
11
37
|
consoleUrl?: string;
|
|
@@ -17,13 +43,26 @@ export type GalileoConfigInput = {
|
|
|
17
43
|
ssoProvider?: string;
|
|
18
44
|
jwtToken?: string;
|
|
19
45
|
refreshToken?: string;
|
|
20
|
-
logLevel?:
|
|
46
|
+
logLevel?: LogLevel | undefined;
|
|
21
47
|
projectName?: string;
|
|
22
48
|
logStreamName?: string;
|
|
49
|
+
/** Path to CA certificate file. */
|
|
50
|
+
caCertPath?: string;
|
|
51
|
+
/** Direct CA certificate content. */
|
|
52
|
+
caCertContent?: string;
|
|
53
|
+
/** Client certificate path. */
|
|
54
|
+
clientCertPath?: string;
|
|
55
|
+
/** Client key path. */
|
|
56
|
+
clientKeyPath?: string;
|
|
57
|
+
/** Whether to reject unauthorized (e.g. self-signed) certificates. */
|
|
58
|
+
rejectUnauthorized?: boolean;
|
|
23
59
|
};
|
|
24
60
|
|
|
25
61
|
/**
|
|
26
|
-
*
|
|
62
|
+
* Resolved authentication credentials extracted from config.
|
|
63
|
+
*
|
|
64
|
+
* Contains one or more of: API key, username/password pair, or SSO credentials.
|
|
65
|
+
* Returned by getAuthCredentials() method.
|
|
27
66
|
*/
|
|
28
67
|
export type AuthCredentials = {
|
|
29
68
|
apiKey?: string;
|
|
@@ -34,13 +73,36 @@ export type AuthCredentials = {
|
|
|
34
73
|
};
|
|
35
74
|
|
|
36
75
|
/**
|
|
37
|
-
*
|
|
76
|
+
* TLS/certificate configuration for API requests.
|
|
77
|
+
*
|
|
78
|
+
* Supports custom CA certificates (via file path or direct content) and mutual TLS (mTLS)
|
|
79
|
+
* with client certificates and keys. Controls whether unauthorized (self-signed) certificates
|
|
80
|
+
* are accepted via rejectUnauthorized flag.
|
|
81
|
+
*
|
|
82
|
+
* Returned by getCertConfig() method or included in config snapshot.
|
|
83
|
+
*/
|
|
84
|
+
export type CertConfig = {
|
|
85
|
+
caCertPath?: string;
|
|
86
|
+
caCertContent?: string;
|
|
87
|
+
clientCertPath?: string;
|
|
88
|
+
clientKeyPath?: string;
|
|
89
|
+
rejectUnauthorized?: boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Config snapshot for BaseEntity compatibility.
|
|
94
|
+
*
|
|
95
|
+
* Flattened representation of resolved configuration including API URL, API key, login credentials
|
|
96
|
+
* (username/password), SSO information (idToken/provider), and TLS certificate configuration.
|
|
97
|
+
*
|
|
98
|
+
* Used for entity authentication and API interactions.
|
|
38
99
|
*/
|
|
39
100
|
export type GalileoConfigSnapshot = {
|
|
40
101
|
apiUrl?: string;
|
|
41
102
|
apiKey?: string;
|
|
42
103
|
login?: { username?: string; password?: string };
|
|
43
104
|
sso?: { idToken?: string; provider?: string };
|
|
105
|
+
cert?: CertConfig;
|
|
44
106
|
};
|
|
45
107
|
|
|
46
108
|
/** Browser global key for auth config (e.g. window.__GALILEO_AUTH__). */
|
|
@@ -71,6 +133,24 @@ const ENV_GALILEO_PROJECT_NAME = "GALILEO_PROJECT_NAME";
|
|
|
71
133
|
const ENV_GALILEO_LOG_STREAM = "GALILEO_LOG_STREAM";
|
|
72
134
|
/** Log stream identifier; same meaning as GALILEO_LOG_STREAM (fallback if GALILEO_LOG_STREAM is unset). */
|
|
73
135
|
const ENV_GALILEO_LOG_STREAM_NAME = "GALILEO_LOG_STREAM_NAME";
|
|
136
|
+
/** Path to CA certificate file (Galileo-specific). */
|
|
137
|
+
const ENV_GALILEO_CA_CERT_PATH = "GALILEO_CA_CERT_PATH";
|
|
138
|
+
/** Direct certificate content. */
|
|
139
|
+
const ENV_GALILEO_CA_CERT_CONTENT = "GALILEO_CA_CERT_CONTENT";
|
|
140
|
+
/** Client certificate path. */
|
|
141
|
+
const ENV_GALILEO_CLIENT_CERT_PATH = "GALILEO_CLIENT_CERT_PATH";
|
|
142
|
+
/** Client key path. */
|
|
143
|
+
const ENV_GALILEO_CLIENT_KEY_PATH = "GALILEO_CLIENT_KEY_PATH";
|
|
144
|
+
/** Boolean to allow/reject self-signed certs (Galileo-specific). */
|
|
145
|
+
const ENV_GALILEO_REJECT_UNAUTHORIZED = "GALILEO_REJECT_UNAUTHORIZED";
|
|
146
|
+
/** Boolean to allow/reject self-signed certs (Node.js standard). */
|
|
147
|
+
const ENV_NODE_TLS_REJECT_UNAUTHORIZED = "NODE_TLS_REJECT_UNAUTHORIZED";
|
|
148
|
+
/** Log level for SDK logging (DEBUG, INFO, WARN, ERROR, etc.). */
|
|
149
|
+
const ENV_GALILEO_LOG_LEVEL = "GALILEO_LOG_LEVEL";
|
|
150
|
+
|
|
151
|
+
export function isValidLogLevel(value: unknown): value is LogLevel {
|
|
152
|
+
return typeof value === "string" && value in LOG_LEVEL_PRIORITY;
|
|
153
|
+
}
|
|
74
154
|
|
|
75
155
|
function readEnvObject(): Record<string, string | undefined> | null {
|
|
76
156
|
if (isDeno()) {
|
|
@@ -160,7 +240,21 @@ function normalizeInput(value: unknown): GalileoConfigInput | null {
|
|
|
160
240
|
typeof obj["projectName"] === "string" ? obj["projectName"] : undefined;
|
|
161
241
|
const logStreamName =
|
|
162
242
|
typeof obj["logStreamName"] === "string" ? obj["logStreamName"] : undefined;
|
|
163
|
-
|
|
243
|
+
const caCertPath =
|
|
244
|
+
typeof obj["caCertPath"] === "string" ? obj["caCertPath"] : undefined;
|
|
245
|
+
const caCertContent =
|
|
246
|
+
typeof obj["caCertContent"] === "string" ? obj["caCertContent"] : undefined;
|
|
247
|
+
const clientCertPath =
|
|
248
|
+
typeof obj["clientCertPath"] === "string" ? obj["clientCertPath"] : undefined;
|
|
249
|
+
const clientKeyPath =
|
|
250
|
+
typeof obj["clientKeyPath"] === "string" ? obj["clientKeyPath"] : undefined;
|
|
251
|
+
const rejectUnauthorized =
|
|
252
|
+
typeof obj["rejectUnauthorized"] === "boolean"
|
|
253
|
+
? obj["rejectUnauthorized"]
|
|
254
|
+
: undefined;
|
|
255
|
+
const rawLogLevel = typeof obj["logLevel"] === "string" ? obj["logLevel"].toLowerCase() : undefined;
|
|
256
|
+
const logLevel = isValidLogLevel(rawLogLevel) ? rawLogLevel : undefined;
|
|
257
|
+
if (!apiKey && !u && !p && !ssoIdToken && !ssoProvider && !caCertPath && !caCertContent && !clientCertPath && !clientKeyPath && rejectUnauthorized === undefined) return null;
|
|
164
258
|
return {
|
|
165
259
|
...(apiKey ? { apiKey } : {}),
|
|
166
260
|
...(u ? { username: String(u) } : {}),
|
|
@@ -171,6 +265,12 @@ function normalizeInput(value: unknown): GalileoConfigInput | null {
|
|
|
171
265
|
...(apiUrl ? { apiUrl } : {}),
|
|
172
266
|
...(projectName ? { projectName } : {}),
|
|
173
267
|
...(logStreamName ? { logStreamName } : {}),
|
|
268
|
+
...(caCertPath ? { caCertPath } : {}),
|
|
269
|
+
...(caCertContent ? { caCertContent } : {}),
|
|
270
|
+
...(clientCertPath ? { clientCertPath } : {}),
|
|
271
|
+
...(clientKeyPath ? { clientKeyPath } : {}),
|
|
272
|
+
...(rejectUnauthorized !== undefined ? { rejectUnauthorized } : {}),
|
|
273
|
+
...(logLevel !== undefined && logLevel.length > 0 ? { logLevel } : {}),
|
|
174
274
|
};
|
|
175
275
|
}
|
|
176
276
|
|
|
@@ -193,8 +293,35 @@ function resolveFromEnvironment(): GalileoConfigInput | null {
|
|
|
193
293
|
const ssoProvider = env[ENV_SSO_PROVIDER];
|
|
194
294
|
const projectName = env[ENV_GALILEO_PROJECT] ?? env[ENV_GALILEO_PROJECT_NAME];
|
|
195
295
|
const logStreamName = env[ENV_GALILEO_LOG_STREAM] ?? env[ENV_GALILEO_LOG_STREAM_NAME];
|
|
296
|
+
const rawLogLevel = env[ENV_GALILEO_LOG_LEVEL]?.toLowerCase();
|
|
297
|
+
const logLevel = isValidLogLevel(rawLogLevel)
|
|
298
|
+
? rawLogLevel
|
|
299
|
+
: undefined;
|
|
300
|
+
|
|
301
|
+
// GALILEO_CA_CERT_PATH is used to clean existing CA certs list and use this instead.
|
|
302
|
+
// Use NODE_EXTRA_CA_CERTS if you want to append CA certs to existing (default) list instead.
|
|
303
|
+
const caCertPath =
|
|
304
|
+
env[ENV_GALILEO_CA_CERT_PATH];
|
|
305
|
+
|
|
306
|
+
const caCertContent = env[ENV_GALILEO_CA_CERT_CONTENT];
|
|
307
|
+
const clientCertPath = env[ENV_GALILEO_CLIENT_CERT_PATH];
|
|
308
|
+
const clientKeyPath = env[ENV_GALILEO_CLIENT_KEY_PATH];
|
|
196
309
|
|
|
197
|
-
|
|
310
|
+
// Reject unauthorized: GALILEO_REJECT_UNAUTHORIZED > NODE_TLS_REJECT_UNAUTHORIZED
|
|
311
|
+
// Empty strings are treated as undefined (not set) to avoid inadvertently disabling TLS.
|
|
312
|
+
const rejectUnauthorizedRaw =
|
|
313
|
+
env[ENV_GALILEO_REJECT_UNAUTHORIZED] ??
|
|
314
|
+
env[ENV_NODE_TLS_REJECT_UNAUTHORIZED];
|
|
315
|
+
const rejectUnauthorized =
|
|
316
|
+
rejectUnauthorizedRaw === undefined || rejectUnauthorizedRaw === ""
|
|
317
|
+
? undefined
|
|
318
|
+
: rejectUnauthorizedRaw === "true" || rejectUnauthorizedRaw === "1"
|
|
319
|
+
? true
|
|
320
|
+
: rejectUnauthorizedRaw === "false" || rejectUnauthorizedRaw === "0"
|
|
321
|
+
? false
|
|
322
|
+
: undefined;
|
|
323
|
+
|
|
324
|
+
if (!apiKey && !username && !password && !ssoIdToken && !ssoProvider && !apiUrl && !consoleUrl && !projectName && !logStreamName && !logLevel && !caCertPath && !caCertContent && !clientCertPath && !clientKeyPath && rejectUnauthorized === undefined)
|
|
198
325
|
return null;
|
|
199
326
|
return {
|
|
200
327
|
...(apiKey ? { apiKey } : {}),
|
|
@@ -206,6 +333,12 @@ function resolveFromEnvironment(): GalileoConfigInput | null {
|
|
|
206
333
|
...(consoleUrl ? { consoleUrl } : {}),
|
|
207
334
|
...(projectName ? { projectName } : {}),
|
|
208
335
|
...(logStreamName ? { logStreamName } : {}),
|
|
336
|
+
...(caCertPath ? { caCertPath } : {}),
|
|
337
|
+
...(caCertContent ? { caCertContent } : {}),
|
|
338
|
+
...(clientCertPath ? { clientCertPath } : {}),
|
|
339
|
+
...(clientKeyPath ? { clientKeyPath } : {}),
|
|
340
|
+
...(rejectUnauthorized !== undefined ? { rejectUnauthorized } : {}),
|
|
341
|
+
...(logLevel !== undefined && logLevel.length > 0 ? { logLevel } : {}),
|
|
209
342
|
};
|
|
210
343
|
}
|
|
211
344
|
return null;
|
|
@@ -231,6 +364,11 @@ function merge(
|
|
|
231
364
|
"logLevel",
|
|
232
365
|
"projectName",
|
|
233
366
|
"logStreamName",
|
|
367
|
+
"caCertPath",
|
|
368
|
+
"caCertContent",
|
|
369
|
+
"clientCertPath",
|
|
370
|
+
"clientKeyPath",
|
|
371
|
+
"rejectUnauthorized",
|
|
234
372
|
];
|
|
235
373
|
for (const k of keys) {
|
|
236
374
|
const ov = o[k];
|
|
@@ -283,9 +421,14 @@ export class GalileoConfig {
|
|
|
283
421
|
public readonly ssoProvider: string | undefined;
|
|
284
422
|
public readonly jwtToken: string | undefined;
|
|
285
423
|
public readonly refreshToken: string | undefined;
|
|
286
|
-
public readonly logLevel:
|
|
424
|
+
public readonly logLevel: LogLevel | undefined;
|
|
287
425
|
public readonly projectName: string | undefined;
|
|
288
426
|
public readonly logStreamName: string | undefined;
|
|
427
|
+
public readonly caCertPath: string | undefined;
|
|
428
|
+
public readonly caCertContent: string | undefined;
|
|
429
|
+
public readonly clientCertPath: string | undefined;
|
|
430
|
+
public readonly clientKeyPath: string | undefined;
|
|
431
|
+
public readonly rejectUnauthorized: boolean | undefined;
|
|
289
432
|
|
|
290
433
|
private constructor(input: GalileoConfigInput) {
|
|
291
434
|
this.apiUrl = input.apiUrl ?? resolveApiUrl(input.consoleUrl, undefined, "gen_ai");
|
|
@@ -300,11 +443,22 @@ export class GalileoConfig {
|
|
|
300
443
|
this.logLevel = input.logLevel;
|
|
301
444
|
this.projectName = input.projectName;
|
|
302
445
|
this.logStreamName = input.logStreamName;
|
|
446
|
+
this.caCertPath = input.caCertPath;
|
|
447
|
+
this.caCertContent = input.caCertContent;
|
|
448
|
+
this.clientCertPath = input.clientCertPath;
|
|
449
|
+
this.clientKeyPath = input.clientKeyPath;
|
|
450
|
+
this.rejectUnauthorized = input.rejectUnauthorized;
|
|
303
451
|
}
|
|
304
452
|
|
|
305
453
|
/**
|
|
306
|
-
* Returns a snapshot compatible with BaseEntity
|
|
307
|
-
*
|
|
454
|
+
* Returns a snapshot compatible with BaseEntity, including resolved apiUrl, apiKey, login, sso, and cert.
|
|
455
|
+
*
|
|
456
|
+
* - apiUrl is resolved from consoleUrl if not explicitly set
|
|
457
|
+
* - login contains username and/or password if present
|
|
458
|
+
* - sso contains idToken and/or provider if present
|
|
459
|
+
* - cert contains all configured TLS/certificate settings if any are present
|
|
460
|
+
*
|
|
461
|
+
* @returns The config snapshot for entity authentication and API configuration.
|
|
308
462
|
*/
|
|
309
463
|
get snapshot(): GalileoConfigSnapshot {
|
|
310
464
|
const apiUrl = this.apiUrl ?? this.getApiUrl();
|
|
@@ -326,18 +480,28 @@ export class GalileoConfig {
|
|
|
326
480
|
: {}),
|
|
327
481
|
}
|
|
328
482
|
: undefined;
|
|
483
|
+
const cert = this.getCertConfig();
|
|
329
484
|
return {
|
|
330
485
|
apiUrl,
|
|
331
486
|
...(this.apiKey !== undefined ? { apiKey: this.apiKey } : {}),
|
|
332
487
|
...(login ? { login } : {}),
|
|
333
488
|
...(sso ? { sso } : {}),
|
|
489
|
+
...(cert !== null ? { cert } : {}),
|
|
334
490
|
};
|
|
335
491
|
}
|
|
336
492
|
|
|
337
493
|
/**
|
|
338
|
-
* Returns the singleton config instance,
|
|
494
|
+
* Returns the singleton config instance, resolving from environment and optional overrides.
|
|
495
|
+
*
|
|
496
|
+
* On first call (or when overrides are provided), resolves configuration from:
|
|
497
|
+
* 1. Environment variables or browser storage (via resolveFromEnvironment)
|
|
498
|
+
* 2. Constructor overrides (via merge)
|
|
499
|
+
*
|
|
500
|
+
* The instance is cached and reused on subsequent calls unless overrides are provided.
|
|
501
|
+
* To reset the singleton, call reset().
|
|
502
|
+
*
|
|
339
503
|
* @param overrides - (Optional) Config values to merge over environment and defaults.
|
|
340
|
-
* @returns The GalileoConfig instance.
|
|
504
|
+
* @returns The GalileoConfig singleton instance.
|
|
341
505
|
*/
|
|
342
506
|
public static get(overrides: GalileoConfigInput = {}): GalileoConfig {
|
|
343
507
|
const hasOverrides = Object.keys(overrides).length > 0;
|
|
@@ -351,7 +515,10 @@ export class GalileoConfig {
|
|
|
351
515
|
}
|
|
352
516
|
|
|
353
517
|
/**
|
|
354
|
-
* Clears the singleton instance.
|
|
518
|
+
* Clears the singleton instance.
|
|
519
|
+
*
|
|
520
|
+
* Next call to get() will rebuild the instance from environment variables or browser storage.
|
|
521
|
+
* Useful for testing or when configuration has changed and needs to be reloaded.
|
|
355
522
|
*/
|
|
356
523
|
public static reset(): void {
|
|
357
524
|
GalileoConfig.instance = null;
|
|
@@ -359,16 +526,29 @@ export class GalileoConfig {
|
|
|
359
526
|
|
|
360
527
|
/**
|
|
361
528
|
* Returns the API base URL, resolved from consoleUrl or explicit apiUrl.
|
|
362
|
-
*
|
|
529
|
+
*
|
|
530
|
+
* Resolution logic:
|
|
531
|
+
* 1. If apiUrl is set, return it as-is
|
|
532
|
+
* 2. If consoleUrl is set, derive apiUrl by replacing "app.galileo.ai" or "console" with "api"
|
|
533
|
+
* 3. For localhost consoleUrl, return "http://localhost:8088"
|
|
534
|
+
* 4. If neither consoleUrl nor apiUrl is set, use projectType default (e.g., "gen_ai" → "https://api.galileo.ai")
|
|
535
|
+
* 5. If no projectType and neither URL is set, throw an error
|
|
536
|
+
*
|
|
537
|
+
* @param projectType - (Optional) Default project type for API URL when neither apiUrl nor consoleUrl is set.
|
|
363
538
|
* @returns The resolved API URL.
|
|
539
|
+
* @throws Error if apiUrl, consoleUrl, and projectType are all unset.
|
|
364
540
|
*/
|
|
365
541
|
public getApiUrl(projectType?: string): string {
|
|
366
542
|
return resolveApiUrl(this.consoleUrl, this.apiUrl, projectType);
|
|
367
543
|
}
|
|
368
544
|
|
|
369
545
|
/**
|
|
370
|
-
* Returns the current
|
|
371
|
-
*
|
|
546
|
+
* Returns the current authentication credentials.
|
|
547
|
+
*
|
|
548
|
+
* Extracts and returns all present credentials: API key, username/password pair, and/or SSO tokens.
|
|
549
|
+
* Only populated fields are included in the returned object.
|
|
550
|
+
*
|
|
551
|
+
* @returns The AuthCredentials object with present credential values.
|
|
372
552
|
*/
|
|
373
553
|
public getAuthCredentials(): AuthCredentials {
|
|
374
554
|
return {
|
|
@@ -385,7 +565,39 @@ export class GalileoConfig {
|
|
|
385
565
|
}
|
|
386
566
|
|
|
387
567
|
/**
|
|
388
|
-
*
|
|
568
|
+
* Returns TLS/certificate configuration for API requests.
|
|
569
|
+
*
|
|
570
|
+
* Extracts and returns all present certificate settings: CA certificate (path or content),
|
|
571
|
+
* client certificate and key (for mTLS), and rejectUnauthorized flag.
|
|
572
|
+
* Only populated fields are included in the returned object.
|
|
573
|
+
*
|
|
574
|
+
* @returns The CertConfig object with present values, or null if no certificate configuration is set.
|
|
575
|
+
*/
|
|
576
|
+
public getCertConfig(): CertConfig | null {
|
|
577
|
+
const result: CertConfig = {
|
|
578
|
+
...(this.caCertPath !== undefined ? { caCertPath: this.caCertPath } : {}),
|
|
579
|
+
...(this.caCertContent !== undefined
|
|
580
|
+
? { caCertContent: this.caCertContent }
|
|
581
|
+
: {}),
|
|
582
|
+
...(this.clientCertPath !== undefined
|
|
583
|
+
? { clientCertPath: this.clientCertPath }
|
|
584
|
+
: {}),
|
|
585
|
+
...(this.clientKeyPath !== undefined
|
|
586
|
+
? { clientKeyPath: this.clientKeyPath }
|
|
587
|
+
: {}),
|
|
588
|
+
...(this.rejectUnauthorized !== undefined
|
|
589
|
+
? { rejectUnauthorized: this.rejectUnauthorized }
|
|
590
|
+
: {}),
|
|
591
|
+
};
|
|
592
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Logs a safe summary of the current configuration to the console.
|
|
597
|
+
*
|
|
598
|
+
* Omits sensitive values (passwords, API keys, SSO tokens) and instead logs boolean flags
|
|
599
|
+
* (hasApiKey, hasPassword, hasSsoIdToken) to indicate their presence without revealing content.
|
|
600
|
+
* Useful for debugging configuration issues in production environments.
|
|
389
601
|
*/
|
|
390
602
|
public logConfig(): void {
|
|
391
603
|
const safe = {
|
|
@@ -399,6 +611,9 @@ export class GalileoConfig {
|
|
|
399
611
|
hasSsoIdToken: Boolean(this.ssoIdToken),
|
|
400
612
|
projectName: this.projectName,
|
|
401
613
|
logStreamName: this.logStreamName,
|
|
614
|
+
hasCaCert: Boolean(this.caCertPath || this.caCertContent),
|
|
615
|
+
hasClientCert: Boolean(this.clientCertPath && this.clientKeyPath),
|
|
616
|
+
rejectUnauthorized: this.rejectUnauthorized,
|
|
402
617
|
};
|
|
403
618
|
console.info("[GalileoConfig]", safe);
|
|
404
619
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { GalileoConfig, isValidLogLevel } from "./galileo-config.js";
|
|
2
|
+
import type { LogLevel, GalileoSdkLogger } from "../types/sdk-logger.types.js";
|
|
3
|
+
import { LOG_LEVEL_PRIORITY } from "../types/sdk-logger.types.js";
|
|
4
|
+
|
|
5
|
+
class SdkLogger {
|
|
6
|
+
private level: LogLevel;
|
|
7
|
+
private customLogger?: GalileoSdkLogger | undefined;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
// Respect GALILEO_LOG_LEVEL from config; fall back to 'silent'
|
|
11
|
+
const envLevel = GalileoConfig.get().logLevel;
|
|
12
|
+
this.level = envLevel && isValidLogLevel(envLevel) ? envLevel : "silent";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setLevel(level: LogLevel): void {
|
|
16
|
+
this.level = level;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setCustomLogger(logger: GalileoSdkLogger | undefined): void {
|
|
20
|
+
this.customLogger = logger;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private shouldLog(level: LogLevel): boolean {
|
|
24
|
+
return LOG_LEVEL_PRIORITY[this.level] >= LOG_LEVEL_PRIORITY[level];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
debug(message: string, ...args: unknown[]): void {
|
|
28
|
+
if (!this.shouldLog("debug")) return;
|
|
29
|
+
(this.customLogger?.debug ?? console.debug)(message, ...args);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
info(message: string, ...args: unknown[]): void {
|
|
33
|
+
if (!this.shouldLog("info")) return;
|
|
34
|
+
(this.customLogger?.info ?? console.info)(message, ...args);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
warn(message: string, ...args: unknown[]): void {
|
|
38
|
+
if (!this.shouldLog("warn")) return;
|
|
39
|
+
(this.customLogger?.warn ?? console.warn)(message, ...args);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
error(message: string, ...args: unknown[]): void {
|
|
43
|
+
if (!this.shouldLog("error")) return;
|
|
44
|
+
(this.customLogger?.error ?? console.error)(message, ...args);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let sdkLogger: SdkLogger | undefined;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get the singleton SdkLogger instance, creating it if necessary.
|
|
52
|
+
* @returns The singleton SdkLogger instance.
|
|
53
|
+
*/
|
|
54
|
+
export function getSdkLogger(): GalileoSdkLogger {
|
|
55
|
+
if (!sdkLogger) {
|
|
56
|
+
sdkLogger = new SdkLogger();
|
|
57
|
+
}
|
|
58
|
+
return sdkLogger;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Enable SDK logging at the specified level.
|
|
63
|
+
* @param level - (Optional) The desired log level. Defaults to 'info'. Pass 'debug' to see detailed messages including retry attempts, task-handler operations, and span conversion information.
|
|
64
|
+
*/
|
|
65
|
+
export function enableLogging(level: LogLevel = "info"): void {
|
|
66
|
+
(getSdkLogger() as SdkLogger).setLevel(level);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Disable all SDK logging.
|
|
71
|
+
*/
|
|
72
|
+
export function disableLogging(): void {
|
|
73
|
+
(getSdkLogger() as SdkLogger).setLevel("silent");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Route all SDK log output through a custom logger.
|
|
78
|
+
* @param logger - (Optional) Custom logger implementing GalileoSdkLogger, or undefined to revert to console output.
|
|
79
|
+
*/
|
|
80
|
+
export function setCustomLogger(logger: GalileoSdkLogger | undefined): void {
|
|
81
|
+
(getSdkLogger() as SdkLogger).setCustomLogger(logger);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Reset the SdkLogger singleton and create a fresh instance that reads the current GalileoConfig state.
|
|
86
|
+
* @returns The newly created SdkLogger instance.
|
|
87
|
+
*/
|
|
88
|
+
export function resetSdkLogger(): GalileoSdkLogger {
|
|
89
|
+
sdkLogger = new SdkLogger();
|
|
90
|
+
return sdkLogger;
|
|
91
|
+
}
|