langwatch 1.0.0 → 1.1.0

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.
Files changed (36) hide show
  1. package/dist/{chunk-5Q2DUSMQ.mjs → chunk-5AGWTUI2.mjs} +2 -2
  2. package/dist/{chunk-5Q2DUSMQ.mjs.map → chunk-5AGWTUI2.mjs.map} +1 -1
  3. package/dist/{chunk-ALPIFEXL.mjs → chunk-EW233MAD.mjs} +2 -2
  4. package/dist/{chunk-C323F5VC.mjs → chunk-PYODMDPV.mjs} +1 -1
  5. package/dist/chunk-PYODMDPV.mjs.map +1 -0
  6. package/dist/{chunk-WHBCX64R.js → chunk-R7NIGAEB.js} +2 -2
  7. package/dist/{chunk-WHBCX64R.js.map → chunk-R7NIGAEB.js.map} +1 -1
  8. package/dist/{chunk-ADJOFPAZ.js → chunk-SCLFEMNK.js} +1 -1
  9. package/dist/chunk-SCLFEMNK.js.map +1 -0
  10. package/dist/{chunk-52VMSJ4O.js → chunk-Z7RP3LP5.js} +12 -12
  11. package/dist/{chunk-52VMSJ4O.js.map → chunk-Z7RP3LP5.js.map} +1 -1
  12. package/dist/cli/bundle.js +165 -148
  13. package/dist/{implementation-CPfDot-W.d.mts → implementation-DmWrukzX.d.mts} +1 -1
  14. package/dist/{implementation-aYHmyVZ_.d.ts → implementation-Psro9xt4.d.ts} +1 -1
  15. package/dist/index.d.mts +225 -3
  16. package/dist/index.d.ts +225 -3
  17. package/dist/index.js +244 -35
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +225 -16
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/observability-sdk/index.d.mts +3 -3
  22. package/dist/observability-sdk/index.d.ts +3 -3
  23. package/dist/observability-sdk/index.js +3 -3
  24. package/dist/observability-sdk/index.mjs +2 -2
  25. package/dist/observability-sdk/instrumentation/langchain/index.d.mts +1 -1
  26. package/dist/observability-sdk/instrumentation/langchain/index.d.ts +1 -1
  27. package/dist/observability-sdk/instrumentation/langchain/index.js +3 -3
  28. package/dist/observability-sdk/instrumentation/langchain/index.mjs +1 -1
  29. package/dist/observability-sdk/setup/node/index.js +3 -3
  30. package/dist/observability-sdk/setup/node/index.mjs +2 -2
  31. package/dist/{types-Cw-3VUv7.d.mts → types-Ck1U3XCH.d.mts} +6060 -5780
  32. package/dist/{types-CeZ-M8JZ.d.ts → types-DGBGlP9B.d.ts} +6060 -5780
  33. package/package.json +1 -1
  34. package/dist/chunk-ADJOFPAZ.js.map +0 -1
  35. package/dist/chunk-C323F5VC.mjs.map +0 -1
  36. /package/dist/{chunk-ALPIFEXL.mjs.map → chunk-EW233MAD.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -4,10 +4,10 @@ import {
4
4
  import {
5
5
  createLangWatchSpan,
6
6
  getLangWatchTracer
7
- } from "./chunk-C323F5VC.mjs";
7
+ } from "./chunk-PYODMDPV.mjs";
8
8
  import {
9
9
  ensureSetup
10
- } from "./chunk-ALPIFEXL.mjs";
10
+ } from "./chunk-EW233MAD.mjs";
11
11
  import {
12
12
  DEFAULT_ENDPOINT,
13
13
  LANGWATCH_SDK_LANGUAGE,
@@ -19,7 +19,7 @@ import {
19
19
  buildAuthHeaders,
20
20
  getLangWatchLogger,
21
21
  version
22
- } from "./chunk-5Q2DUSMQ.mjs";
22
+ } from "./chunk-5AGWTUI2.mjs";
23
23
  import {
24
24
  ConsoleLogger,
25
25
  NoOpLogger,
@@ -35,6 +35,18 @@ import {
35
35
  shouldCaptureOutput
36
36
  } from "./chunk-L5KBRKHS.mjs";
37
37
 
38
+ // src/internal/credentialContext.ts
39
+ import { AsyncLocalStorage } from "async_hooks";
40
+ var storage = new AsyncLocalStorage();
41
+ var fallbackHolder = {};
42
+ function currentHolder() {
43
+ var _a;
44
+ return (_a = storage.getStore()) != null ? _a : fallbackHolder;
45
+ }
46
+ function scopedApiKey() {
47
+ return currentHolder().apiKey;
48
+ }
49
+
38
50
  // src/client-sdk/services/prompts/prompts-api.service.ts
39
51
  import { z } from "zod";
40
52
 
@@ -643,7 +655,7 @@ var handledErrorMiddleware = {
643
655
  if (handledError) throw handledError;
644
656
  }
645
657
  };
646
- var createLangWatchApiClient = (apiKey = ((_a) => (_a = process.env.LANGWATCH_API_KEY) != null ? _a : "")(), endpoint = ((_b) => (_b = process.env.LANGWATCH_ENDPOINT) != null ? _b : DEFAULT_ENDPOINT)(), projectId = process.env.LANGWATCH_PROJECT_ID) => {
658
+ var createLangWatchApiClient = (apiKey = ((_b) => (_b = ((_a) => (_a = scopedApiKey()) != null ? _a : process.env.LANGWATCH_API_KEY)()) != null ? _b : "")(), endpoint = ((_c) => (_c = process.env.LANGWATCH_ENDPOINT) != null ? _c : DEFAULT_ENDPOINT)(), projectId = process.env.LANGWATCH_PROJECT_ID) => {
647
659
  const client = openApiCreateClient({
648
660
  baseUrl: endpoint,
649
661
  headers: __spreadProps(__spreadValues({}, buildAuthHeaders({ apiKey, projectId })), {
@@ -2474,7 +2486,7 @@ var DatasetsFacade = class {
2474
2486
  _datasetService = new WeakMap();
2475
2487
 
2476
2488
  // src/client-sdk/services/experiments/experiment.ts
2477
- import { AsyncLocalStorage } from "async_hooks";
2489
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
2478
2490
  import { trace, SpanStatusCode, ROOT_CONTEXT } from "@opentelemetry/api";
2479
2491
 
2480
2492
  // src/client-sdk/services/experiments/humanReadableId.ts
@@ -2683,8 +2695,8 @@ function printSummary(result) {
2683
2695
  // src/client-sdk/services/experiments/experiment.ts
2684
2696
  var DEFAULT_CONCURRENCY = 4;
2685
2697
  var DEBOUNCE_INTERVAL_MS = 1e3;
2686
- var iterationContextStorage = new AsyncLocalStorage();
2687
- var targetContextStorage = new AsyncLocalStorage();
2698
+ var iterationContextStorage = new AsyncLocalStorage2();
2699
+ var targetContextStorage = new AsyncLocalStorage2();
2688
2700
  var Experiment = class _Experiment {
2689
2701
  constructor(name, options) {
2690
2702
  this.initialized = false;
@@ -5149,9 +5161,9 @@ var MonitorsApiError = class extends Error {
5149
5161
  };
5150
5162
  var MonitorsApiService = class {
5151
5163
  constructor(config) {
5152
- var _a, _b, _c, _d;
5153
- this.apiKey = (_b = (_a = config == null ? void 0 : config.apiKey) != null ? _a : process.env.LANGWATCH_API_KEY) != null ? _b : "";
5154
- this.endpoint = (_d = (_c = config == null ? void 0 : config.endpoint) != null ? _c : process.env.LANGWATCH_ENDPOINT) != null ? _d : DEFAULT_ENDPOINT;
5164
+ var _a, _b, _c, _d, _e;
5165
+ this.apiKey = (_c = (_b = (_a = config == null ? void 0 : config.apiKey) != null ? _a : scopedApiKey()) != null ? _b : process.env.LANGWATCH_API_KEY) != null ? _c : "";
5166
+ this.endpoint = (_e = (_d = config == null ? void 0 : config.endpoint) != null ? _d : process.env.LANGWATCH_ENDPOINT) != null ? _e : DEFAULT_ENDPOINT;
5155
5167
  }
5156
5168
  async request(path2, options) {
5157
5169
  var _a, _b;
@@ -5224,9 +5236,9 @@ var SecretsApiError = class extends Error {
5224
5236
  };
5225
5237
  var SecretsApiService = class {
5226
5238
  constructor(config) {
5227
- var _a, _b, _c, _d;
5228
- this.apiKey = (_b = (_a = config == null ? void 0 : config.apiKey) != null ? _a : process.env.LANGWATCH_API_KEY) != null ? _b : "";
5229
- this.endpoint = (_d = (_c = config == null ? void 0 : config.endpoint) != null ? _c : process.env.LANGWATCH_ENDPOINT) != null ? _d : DEFAULT_ENDPOINT;
5239
+ var _a, _b, _c, _d, _e;
5240
+ this.apiKey = (_c = (_b = (_a = config == null ? void 0 : config.apiKey) != null ? _a : scopedApiKey()) != null ? _b : process.env.LANGWATCH_API_KEY) != null ? _c : "";
5241
+ this.endpoint = (_e = (_d = config == null ? void 0 : config.endpoint) != null ? _d : process.env.LANGWATCH_ENDPOINT) != null ? _e : DEFAULT_ENDPOINT;
5230
5242
  }
5231
5243
  async request(path2, options) {
5232
5244
  var _a, _b;
@@ -5361,9 +5373,9 @@ var _LangWatch_instances, createInternalConfig_fn;
5361
5373
  var LangWatch = class {
5362
5374
  constructor(options = {}) {
5363
5375
  __privateAdd(this, _LangWatch_instances);
5364
- var _a, _b, _c, _d;
5365
- const apiKey = (_b = (_a = options.apiKey) != null ? _a : process.env.LANGWATCH_API_KEY) != null ? _b : "";
5366
- const endpoint = (_d = (_c = options.endpoint) != null ? _c : process.env.LANGWATCH_ENDPOINT) != null ? _d : DEFAULT_ENDPOINT;
5376
+ var _a, _b, _c, _d, _e;
5377
+ const apiKey = (_c = (_b = (_a = options.apiKey) != null ? _a : scopedApiKey()) != null ? _b : process.env.LANGWATCH_API_KEY) != null ? _c : "";
5378
+ const endpoint = (_e = (_d = options.endpoint) != null ? _d : process.env.LANGWATCH_ENDPOINT) != null ? _e : DEFAULT_ENDPOINT;
5367
5379
  this.config = __privateMethod(this, _LangWatch_instances, createInternalConfig_fn).call(this, {
5368
5380
  apiKey,
5369
5381
  endpoint,
@@ -5425,6 +5437,199 @@ createInternalConfig_fn = function({
5425
5437
  };
5426
5438
  };
5427
5439
 
5440
+ // src/client-sdk/services/virtual-keys/virtual-keys-api.service.ts
5441
+ var VirtualKeysApiError = class extends Error {
5442
+ constructor(message, operation, originalError) {
5443
+ super(message);
5444
+ this.operation = operation;
5445
+ this.originalError = originalError;
5446
+ this.name = "VirtualKeysApiError";
5447
+ }
5448
+ };
5449
+ var VirtualKeysApiService = class {
5450
+ constructor(config) {
5451
+ var _a, _b, _c, _d, _e;
5452
+ this.endpoint = ((_b = (_a = config == null ? void 0 : config.endpoint) != null ? _a : process.env.LANGWATCH_ENDPOINT) != null ? _b : DEFAULT_ENDPOINT).replace(/\/+$/, "");
5453
+ this.apiKey = (_e = (_d = (_c = config == null ? void 0 : config.apiKey) != null ? _c : scopedApiKey()) != null ? _d : process.env.LANGWATCH_API_KEY) != null ? _e : "";
5454
+ }
5455
+ headers() {
5456
+ return {
5457
+ Authorization: `Bearer ${this.apiKey}`,
5458
+ "Content-Type": "application/json"
5459
+ };
5460
+ }
5461
+ async request(operation, path2, init) {
5462
+ var _a;
5463
+ const response = await fetch(`${this.endpoint}${path2}`, __spreadProps(__spreadValues({}, init), {
5464
+ headers: __spreadValues(__spreadValues({}, this.headers()), (_a = init == null ? void 0 : init.headers) != null ? _a : {})
5465
+ }));
5466
+ if (!response.ok) {
5467
+ let parsedBody;
5468
+ try {
5469
+ parsedBody = await response.json();
5470
+ } catch (e) {
5471
+ parsedBody = await response.text();
5472
+ }
5473
+ const message = formatApiErrorForOperation({
5474
+ operation,
5475
+ error: parsedBody,
5476
+ options: { status: response.status }
5477
+ });
5478
+ throwIfHandledError({
5479
+ operation,
5480
+ error: parsedBody,
5481
+ status: response.status,
5482
+ message
5483
+ });
5484
+ throw new VirtualKeysApiError(message, operation, parsedBody);
5485
+ }
5486
+ return await response.json();
5487
+ }
5488
+ async list() {
5489
+ const { data } = await this.request(
5490
+ "list virtual keys",
5491
+ "/api/gateway/v1/virtual-keys"
5492
+ );
5493
+ return data;
5494
+ }
5495
+ async get(id) {
5496
+ const { virtual_key } = await this.request(
5497
+ `get virtual key "${id}"`,
5498
+ `/api/gateway/v1/virtual-keys/${encodeURIComponent(id)}`
5499
+ );
5500
+ return virtual_key;
5501
+ }
5502
+ async create(input) {
5503
+ return this.request(
5504
+ "create virtual key",
5505
+ "/api/gateway/v1/virtual-keys",
5506
+ { method: "POST", body: JSON.stringify(input) }
5507
+ );
5508
+ }
5509
+ async update(id, input) {
5510
+ const { virtual_key } = await this.request(
5511
+ `update virtual key "${id}"`,
5512
+ `/api/gateway/v1/virtual-keys/${encodeURIComponent(id)}`,
5513
+ { method: "PATCH", body: JSON.stringify(input) }
5514
+ );
5515
+ return virtual_key;
5516
+ }
5517
+ async rotate(id) {
5518
+ return this.request(
5519
+ `rotate virtual key "${id}"`,
5520
+ `/api/gateway/v1/virtual-keys/${encodeURIComponent(id)}/rotate`,
5521
+ { method: "POST" }
5522
+ );
5523
+ }
5524
+ async revoke(id) {
5525
+ const { virtual_key } = await this.request(
5526
+ `revoke virtual key "${id}"`,
5527
+ `/api/gateway/v1/virtual-keys/${encodeURIComponent(id)}/revoke`,
5528
+ { method: "POST" }
5529
+ );
5530
+ return virtual_key;
5531
+ }
5532
+ /**
5533
+ * Aggregate spend for one key. Defaults to the current UTC calendar
5534
+ * month server-side. Reads the same cost path the dashboard reads, so
5535
+ * this number and the UI agree by construction.
5536
+ */
5537
+ async spend(id, window) {
5538
+ const params = new URLSearchParams();
5539
+ if (window == null ? void 0 : window.from) params.set("from", window.from);
5540
+ if (window == null ? void 0 : window.to) params.set("to", window.to);
5541
+ const query = params.size > 0 ? `?${params.toString()}` : "";
5542
+ return this.request(
5543
+ `read virtual key spend "${id}"`,
5544
+ `/api/gateway/v1/virtual-keys/${encodeURIComponent(id)}/spend${query}`
5545
+ );
5546
+ }
5547
+ };
5548
+
5549
+ // src/client-sdk/services/gateway-budgets/gateway-budgets-api.service.ts
5550
+ var GatewayBudgetsApiError = class extends Error {
5551
+ constructor(message, operation, originalError) {
5552
+ super(message);
5553
+ this.operation = operation;
5554
+ this.originalError = originalError;
5555
+ this.name = "GatewayBudgetsApiError";
5556
+ }
5557
+ };
5558
+ var GatewayBudgetsApiService = class {
5559
+ constructor(config) {
5560
+ var _a, _b, _c, _d, _e;
5561
+ this.endpoint = ((_b = (_a = config == null ? void 0 : config.endpoint) != null ? _a : process.env.LANGWATCH_ENDPOINT) != null ? _b : DEFAULT_ENDPOINT).replace(/\/+$/, "");
5562
+ this.apiKey = (_e = (_d = (_c = config == null ? void 0 : config.apiKey) != null ? _c : scopedApiKey()) != null ? _d : process.env.LANGWATCH_API_KEY) != null ? _e : "";
5563
+ }
5564
+ headers() {
5565
+ return {
5566
+ Authorization: `Bearer ${this.apiKey}`,
5567
+ "Content-Type": "application/json"
5568
+ };
5569
+ }
5570
+ async request(operation, path2, init) {
5571
+ var _a;
5572
+ const response = await fetch(`${this.endpoint}${path2}`, __spreadProps(__spreadValues({}, init), {
5573
+ headers: __spreadValues(__spreadValues({}, this.headers()), (_a = init == null ? void 0 : init.headers) != null ? _a : {})
5574
+ }));
5575
+ if (!response.ok) {
5576
+ let parsedBody;
5577
+ try {
5578
+ parsedBody = await response.json();
5579
+ } catch (e) {
5580
+ parsedBody = await response.text();
5581
+ }
5582
+ const message = formatApiErrorForOperation({
5583
+ operation,
5584
+ error: parsedBody,
5585
+ options: { status: response.status }
5586
+ });
5587
+ throwIfHandledError({
5588
+ operation,
5589
+ error: parsedBody,
5590
+ status: response.status,
5591
+ message
5592
+ });
5593
+ throw new GatewayBudgetsApiError(message, operation, parsedBody);
5594
+ }
5595
+ return await response.json();
5596
+ }
5597
+ /**
5598
+ * Every non-archived budget in the organization across all six scope
5599
+ * types, optionally filtered by `scopeTypes`.
5600
+ */
5601
+ async list(options) {
5602
+ var _a;
5603
+ const filter = ((_a = options == null ? void 0 : options.scopeTypes) == null ? void 0 : _a.length) ? `?scope_type=${options.scopeTypes.join(",")}` : "";
5604
+ const { data, spend_available } = await this.request("list gateway budgets", `/api/gateway/v1/budgets${filter}`);
5605
+ return { budgets: data, spend_available };
5606
+ }
5607
+ async create(input) {
5608
+ const { budget } = await this.request(
5609
+ "create gateway budget",
5610
+ "/api/gateway/v1/budgets",
5611
+ { method: "POST", body: JSON.stringify(input) }
5612
+ );
5613
+ return budget;
5614
+ }
5615
+ async update(id, input) {
5616
+ const { budget } = await this.request(
5617
+ `update gateway budget "${id}"`,
5618
+ `/api/gateway/v1/budgets/${encodeURIComponent(id)}`,
5619
+ { method: "PATCH", body: JSON.stringify(input) }
5620
+ );
5621
+ return budget;
5622
+ }
5623
+ async archive(id) {
5624
+ const { budget } = await this.request(
5625
+ `archive gateway budget "${id}"`,
5626
+ `/api/gateway/v1/budgets/${encodeURIComponent(id)}`,
5627
+ { method: "DELETE" }
5628
+ );
5629
+ return budget;
5630
+ }
5631
+ };
5632
+
5428
5633
  // src/index.ts
5429
5634
  var logger = {
5430
5635
  ConsoleLogger,
@@ -5452,11 +5657,15 @@ export {
5452
5657
  ExperimentsFacade,
5453
5658
  FetchPolicy,
5454
5659
  FilterableBatchSpanProcessor,
5660
+ GatewayBudgetsApiError,
5661
+ GatewayBudgetsApiService,
5455
5662
  LangWatch,
5456
5663
  LangWatchApiError,
5457
5664
  LangWatchTraceExporter as LangWatchExporter,
5458
5665
  LangWatchHandledError,
5459
5666
  TargetMetadataConflictError,
5667
+ VirtualKeysApiError,
5668
+ VirtualKeysApiService,
5460
5669
  attributes_exports as attributes,
5461
5670
  getLangWatchLogger,
5462
5671
  getLangWatchTracer,