@lmnr-ai/client 0.8.28 → 0.8.30

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/dist/index.d.cts CHANGED
@@ -1,11 +1,34 @@
1
1
  import { CachedSpan, Datapoint, Dataset, EvaluationDatapoint, GetDatapointsResponse, InitEvaluationResponse, PushDatapointsResponse, StringUUID } from "@lmnr-ai/types";
2
2
 
3
3
  //#region src/resources/index.d.ts
4
+ /**
5
+ * Unified auth for every resource. A discriminated union so a single object
6
+ * drives both the URL prefix and the request headers:
7
+ *
8
+ * - `apiKey` → project API key (SDK / app surfaces). Routes to `/v1/*`,
9
+ * Bearer is the project key, no `x-lmnr-project-id` header.
10
+ * - `userToken` → BetterAuth user access JWT (the CLI user-token surface).
11
+ * Routes to `/v1/cli/*`, Bearer is the JWT, carries the target project in
12
+ * the `x-lmnr-project-id` header.
13
+ */
14
+ type LaminarAuth = {
15
+ type: "apiKey";
16
+ key: string;
17
+ } | {
18
+ type: "userToken";
19
+ token: string;
20
+ projectId: string;
21
+ };
4
22
  declare class BaseResource {
5
23
  protected readonly baseHttpUrl: string;
6
- protected readonly projectApiKey: string;
7
- constructor(baseHttpUrl: string, projectApiKey: string);
24
+ protected readonly auth: LaminarAuth;
25
+ /** The bearer credential, regardless of auth type (project key or user JWT). */
26
+ protected readonly credential: string;
27
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
28
+ /** API path prefix: `/v1/cli` for CLI user-token auth, `/v1` otherwise. */
29
+ protected get apiPrefix(): string;
8
30
  protected headers(): {
31
+ "x-lmnr-project-id"?: string | undefined;
9
32
  Authorization: string;
10
33
  "Content-Type": string;
11
34
  Accept: string;
@@ -15,7 +38,7 @@ declare class BaseResource {
15
38
  //#endregion
16
39
  //#region src/resources/browser-events.d.ts
17
40
  declare class BrowserEventsResource extends BaseResource {
18
- constructor(baseHttpUrl: string, projectApiKey: string);
41
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
19
42
  send({
20
43
  sessionId,
21
44
  traceId,
@@ -27,9 +50,31 @@ declare class BrowserEventsResource extends BaseResource {
27
50
  }): Promise<void>;
28
51
  }
29
52
  //#endregion
53
+ //#region src/resources/cli.d.ts
54
+ interface CliProject {
55
+ id: string;
56
+ name: string;
57
+ workspaceId: string;
58
+ workspaceName: string;
59
+ }
60
+ /**
61
+ * User-scoped CLI endpoints that don't target a specific project. Authed by the
62
+ * BetterAuth user JWT (the `credential`); deliberately does NOT send an
63
+ * `x-lmnr-project-id` header (these routes are project discovery, pre-selection).
64
+ *
65
+ * Discovery exception: this resource always hits `/v1/cli/projects` with the
66
+ * bare bearer and overrides `BaseResource.headers()`/`apiPrefix`, so it works
67
+ * even when constructed with a `userToken` auth that has no real project id yet.
68
+ */
69
+ declare class CliResource extends BaseResource {
70
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
71
+ /** Workspaces + projects the authenticated user can access. */
72
+ listProjects(): Promise<CliProject[]>;
73
+ }
74
+ //#endregion
30
75
  //#region src/resources/datasets.d.ts
31
76
  declare class DatasetsResource extends BaseResource {
32
- constructor(baseHttpUrl: string, projectApiKey: string);
77
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
33
78
  /**
34
79
  * List all datasets.
35
80
  *
@@ -92,7 +137,7 @@ declare class DatasetsResource extends BaseResource {
92
137
  //#endregion
93
138
  //#region src/resources/evals.d.ts
94
139
  declare class EvalsResource extends BaseResource {
95
- constructor(baseHttpUrl: string, projectApiKey: string);
140
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
96
141
  /**
97
142
  * Initialize an evaluation.
98
143
  *
@@ -224,7 +269,7 @@ type ScoreOptions = {
224
269
  * Resource for creating evaluator scores
225
270
  */
226
271
  declare class EvaluatorsResource extends BaseResource {
227
- constructor(baseHttpUrl: string, projectApiKey: string);
272
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
228
273
  /**
229
274
  * Create a score for a span or trace
230
275
  *
@@ -276,7 +321,7 @@ type CacheOutcome = {
276
321
  kind: "live";
277
322
  };
278
323
  declare class RolloutSessionsResource extends BaseResource {
279
- constructor(baseHttpUrl: string, projectApiKey: string);
324
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
280
325
  /**
281
326
  * Idempotently register (upsert) a debug session on the backend, keyed on the
282
327
  * SDK-supplied session id. The backend stores the row so the session is
@@ -339,14 +384,14 @@ declare class RolloutSessionsResource extends BaseResource {
339
384
  //#endregion
340
385
  //#region src/resources/sql.d.ts
341
386
  declare class SqlResource extends BaseResource {
342
- constructor(baseHttpUrl: string, projectApiKey: string);
387
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
343
388
  query(sql: string, parameters?: Record<string, any>): Promise<Array<Record<string, any>>>;
344
389
  }
345
390
  //#endregion
346
391
  //#region src/resources/tags.d.ts
347
392
  declare class TagsResource extends BaseResource {
348
393
  /** Resource for tagging traces. */
349
- constructor(baseHttpUrl: string, projectApiKey: string);
394
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
350
395
  /**
351
396
  * Tag a trace with a list of tags. Note that the trace must be ended before
352
397
  * tagging it. You may want to call `await Laminar.flush()` after the trace
@@ -385,7 +430,7 @@ declare class TagsResource extends BaseResource {
385
430
  //#region src/resources/traces.d.ts
386
431
  declare class TracesResource extends BaseResource {
387
432
  /** Resource for post-factum operations on existing traces. */
388
- constructor(baseHttpUrl: string, projectApiKey: string);
433
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
389
434
  /**
390
435
  * Push a metadata patch to an existing trace.
391
436
  *
@@ -444,8 +489,9 @@ declare class TracesResource extends BaseResource {
444
489
  //#region src/index.d.ts
445
490
  declare class LaminarClient {
446
491
  private baseUrl;
447
- private projectApiKey;
492
+ private auth;
448
493
  private _browserEvents;
494
+ private _cli;
449
495
  private _datasets;
450
496
  private _evals;
451
497
  private _evaluators;
@@ -455,14 +501,45 @@ declare class LaminarClient {
455
501
  private _traces;
456
502
  constructor({
457
503
  baseUrl,
504
+ port,
505
+ auth,
458
506
  projectApiKey,
459
- port
507
+ cliUserProjectId
460
508
  }?: {
461
509
  baseUrl?: string;
462
- projectApiKey?: string;
463
510
  port?: number;
511
+ /**
512
+ * Unified auth. A discriminated union that drives both the URL prefix and
513
+ * the request headers:
514
+ * - `{ type: "apiKey", key }` → project key, `/v1/*`.
515
+ * - `{ type: "userToken", token, projectId }` → user JWT, `/v1/cli/*` with
516
+ * `x-lmnr-project-id`.
517
+ * When omitted, the legacy `projectApiKey` / `cliUserProjectId` fields (or
518
+ * `LMNR_PROJECT_API_KEY`) are normalized into this union.
519
+ */
520
+ auth?: LaminarAuth;
521
+ /**
522
+ * @deprecated Pass `auth: { type: "apiKey", key }` instead. Kept for
523
+ * backward compatibility — normalized into the unified `auth` union.
524
+ */
525
+ projectApiKey?: string;
526
+ /**
527
+ * @deprecated Pass `auth: { type: "userToken", token, projectId }` instead.
528
+ * Kept for backward compatibility: when set, the legacy `projectApiKey` is
529
+ * treated as a user JWT and routes to `/v1/cli/*` with this project id.
530
+ */
531
+ cliUserProjectId?: string;
464
532
  });
533
+ /**
534
+ * Normalize the constructor's auth inputs into a {@link LaminarAuth} union.
535
+ * Precedence: an explicit `auth` wins; otherwise the legacy
536
+ * `projectApiKey` (+ optional `cliUserProjectId`) is mapped — a present
537
+ * `cliUserProjectId` selects the user-token surface, otherwise the project
538
+ * key surface. Falls back to `LMNR_PROJECT_API_KEY` as a project key.
539
+ */
540
+ private static normalizeAuth;
465
541
  get browserEvents(): BrowserEventsResource;
542
+ get cli(): CliResource;
466
543
  get datasets(): DatasetsResource;
467
544
  get evals(): EvalsResource;
468
545
  get evaluators(): EvaluatorsResource;
@@ -472,5 +549,5 @@ declare class LaminarClient {
472
549
  get traces(): TracesResource;
473
550
  }
474
551
  //#endregion
475
- export { type CacheOutcome, LaminarClient, RolloutSessionsResource };
552
+ export { type CacheOutcome, type CliProject, type LaminarAuth, LaminarClient, RolloutSessionsResource };
476
553
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -1,11 +1,34 @@
1
1
  import { CachedSpan, Datapoint, Dataset, EvaluationDatapoint, GetDatapointsResponse, InitEvaluationResponse, PushDatapointsResponse, StringUUID } from "@lmnr-ai/types";
2
2
 
3
3
  //#region src/resources/index.d.ts
4
+ /**
5
+ * Unified auth for every resource. A discriminated union so a single object
6
+ * drives both the URL prefix and the request headers:
7
+ *
8
+ * - `apiKey` → project API key (SDK / app surfaces). Routes to `/v1/*`,
9
+ * Bearer is the project key, no `x-lmnr-project-id` header.
10
+ * - `userToken` → BetterAuth user access JWT (the CLI user-token surface).
11
+ * Routes to `/v1/cli/*`, Bearer is the JWT, carries the target project in
12
+ * the `x-lmnr-project-id` header.
13
+ */
14
+ type LaminarAuth = {
15
+ type: "apiKey";
16
+ key: string;
17
+ } | {
18
+ type: "userToken";
19
+ token: string;
20
+ projectId: string;
21
+ };
4
22
  declare class BaseResource {
5
23
  protected readonly baseHttpUrl: string;
6
- protected readonly projectApiKey: string;
7
- constructor(baseHttpUrl: string, projectApiKey: string);
24
+ protected readonly auth: LaminarAuth;
25
+ /** The bearer credential, regardless of auth type (project key or user JWT). */
26
+ protected readonly credential: string;
27
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
28
+ /** API path prefix: `/v1/cli` for CLI user-token auth, `/v1` otherwise. */
29
+ protected get apiPrefix(): string;
8
30
  protected headers(): {
31
+ "x-lmnr-project-id"?: string | undefined;
9
32
  Authorization: string;
10
33
  "Content-Type": string;
11
34
  Accept: string;
@@ -15,7 +38,7 @@ declare class BaseResource {
15
38
  //#endregion
16
39
  //#region src/resources/browser-events.d.ts
17
40
  declare class BrowserEventsResource extends BaseResource {
18
- constructor(baseHttpUrl: string, projectApiKey: string);
41
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
19
42
  send({
20
43
  sessionId,
21
44
  traceId,
@@ -27,9 +50,31 @@ declare class BrowserEventsResource extends BaseResource {
27
50
  }): Promise<void>;
28
51
  }
29
52
  //#endregion
53
+ //#region src/resources/cli.d.ts
54
+ interface CliProject {
55
+ id: string;
56
+ name: string;
57
+ workspaceId: string;
58
+ workspaceName: string;
59
+ }
60
+ /**
61
+ * User-scoped CLI endpoints that don't target a specific project. Authed by the
62
+ * BetterAuth user JWT (the `credential`); deliberately does NOT send an
63
+ * `x-lmnr-project-id` header (these routes are project discovery, pre-selection).
64
+ *
65
+ * Discovery exception: this resource always hits `/v1/cli/projects` with the
66
+ * bare bearer and overrides `BaseResource.headers()`/`apiPrefix`, so it works
67
+ * even when constructed with a `userToken` auth that has no real project id yet.
68
+ */
69
+ declare class CliResource extends BaseResource {
70
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
71
+ /** Workspaces + projects the authenticated user can access. */
72
+ listProjects(): Promise<CliProject[]>;
73
+ }
74
+ //#endregion
30
75
  //#region src/resources/datasets.d.ts
31
76
  declare class DatasetsResource extends BaseResource {
32
- constructor(baseHttpUrl: string, projectApiKey: string);
77
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
33
78
  /**
34
79
  * List all datasets.
35
80
  *
@@ -92,7 +137,7 @@ declare class DatasetsResource extends BaseResource {
92
137
  //#endregion
93
138
  //#region src/resources/evals.d.ts
94
139
  declare class EvalsResource extends BaseResource {
95
- constructor(baseHttpUrl: string, projectApiKey: string);
140
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
96
141
  /**
97
142
  * Initialize an evaluation.
98
143
  *
@@ -224,7 +269,7 @@ type ScoreOptions = {
224
269
  * Resource for creating evaluator scores
225
270
  */
226
271
  declare class EvaluatorsResource extends BaseResource {
227
- constructor(baseHttpUrl: string, projectApiKey: string);
272
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
228
273
  /**
229
274
  * Create a score for a span or trace
230
275
  *
@@ -276,7 +321,7 @@ type CacheOutcome = {
276
321
  kind: "live";
277
322
  };
278
323
  declare class RolloutSessionsResource extends BaseResource {
279
- constructor(baseHttpUrl: string, projectApiKey: string);
324
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
280
325
  /**
281
326
  * Idempotently register (upsert) a debug session on the backend, keyed on the
282
327
  * SDK-supplied session id. The backend stores the row so the session is
@@ -339,14 +384,14 @@ declare class RolloutSessionsResource extends BaseResource {
339
384
  //#endregion
340
385
  //#region src/resources/sql.d.ts
341
386
  declare class SqlResource extends BaseResource {
342
- constructor(baseHttpUrl: string, projectApiKey: string);
387
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
343
388
  query(sql: string, parameters?: Record<string, any>): Promise<Array<Record<string, any>>>;
344
389
  }
345
390
  //#endregion
346
391
  //#region src/resources/tags.d.ts
347
392
  declare class TagsResource extends BaseResource {
348
393
  /** Resource for tagging traces. */
349
- constructor(baseHttpUrl: string, projectApiKey: string);
394
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
350
395
  /**
351
396
  * Tag a trace with a list of tags. Note that the trace must be ended before
352
397
  * tagging it. You may want to call `await Laminar.flush()` after the trace
@@ -385,7 +430,7 @@ declare class TagsResource extends BaseResource {
385
430
  //#region src/resources/traces.d.ts
386
431
  declare class TracesResource extends BaseResource {
387
432
  /** Resource for post-factum operations on existing traces. */
388
- constructor(baseHttpUrl: string, projectApiKey: string);
433
+ constructor(baseHttpUrl: string, auth: LaminarAuth);
389
434
  /**
390
435
  * Push a metadata patch to an existing trace.
391
436
  *
@@ -444,8 +489,9 @@ declare class TracesResource extends BaseResource {
444
489
  //#region src/index.d.ts
445
490
  declare class LaminarClient {
446
491
  private baseUrl;
447
- private projectApiKey;
492
+ private auth;
448
493
  private _browserEvents;
494
+ private _cli;
449
495
  private _datasets;
450
496
  private _evals;
451
497
  private _evaluators;
@@ -455,14 +501,45 @@ declare class LaminarClient {
455
501
  private _traces;
456
502
  constructor({
457
503
  baseUrl,
504
+ port,
505
+ auth,
458
506
  projectApiKey,
459
- port
507
+ cliUserProjectId
460
508
  }?: {
461
509
  baseUrl?: string;
462
- projectApiKey?: string;
463
510
  port?: number;
511
+ /**
512
+ * Unified auth. A discriminated union that drives both the URL prefix and
513
+ * the request headers:
514
+ * - `{ type: "apiKey", key }` → project key, `/v1/*`.
515
+ * - `{ type: "userToken", token, projectId }` → user JWT, `/v1/cli/*` with
516
+ * `x-lmnr-project-id`.
517
+ * When omitted, the legacy `projectApiKey` / `cliUserProjectId` fields (or
518
+ * `LMNR_PROJECT_API_KEY`) are normalized into this union.
519
+ */
520
+ auth?: LaminarAuth;
521
+ /**
522
+ * @deprecated Pass `auth: { type: "apiKey", key }` instead. Kept for
523
+ * backward compatibility — normalized into the unified `auth` union.
524
+ */
525
+ projectApiKey?: string;
526
+ /**
527
+ * @deprecated Pass `auth: { type: "userToken", token, projectId }` instead.
528
+ * Kept for backward compatibility: when set, the legacy `projectApiKey` is
529
+ * treated as a user JWT and routes to `/v1/cli/*` with this project id.
530
+ */
531
+ cliUserProjectId?: string;
464
532
  });
533
+ /**
534
+ * Normalize the constructor's auth inputs into a {@link LaminarAuth} union.
535
+ * Precedence: an explicit `auth` wins; otherwise the legacy
536
+ * `projectApiKey` (+ optional `cliUserProjectId`) is mapped — a present
537
+ * `cliUserProjectId` selects the user-token surface, otherwise the project
538
+ * key surface. Falls back to `LMNR_PROJECT_API_KEY` as a project key.
539
+ */
540
+ private static normalizeAuth;
465
541
  get browserEvents(): BrowserEventsResource;
542
+ get cli(): CliResource;
466
543
  get datasets(): DatasetsResource;
467
544
  get evals(): EvalsResource;
468
545
  get evaluators(): EvaluatorsResource;
@@ -472,5 +549,5 @@ declare class LaminarClient {
472
549
  get traces(): TracesResource;
473
550
  }
474
551
  //#endregion
475
- export { type CacheOutcome, LaminarClient, RolloutSessionsResource };
552
+ export { type CacheOutcome, type CliProject, type LaminarAuth, LaminarClient, RolloutSessionsResource };
476
553
  //# sourceMappingURL=index.d.mts.map