autotel 3.2.0 → 3.3.1

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 (76) hide show
  1. package/dist/auto.cjs +2 -2
  2. package/dist/auto.js +1 -1
  3. package/dist/{chunk-RZI5XXAD.js → chunk-2GWM2CIT.js} +3 -3
  4. package/dist/{chunk-RZI5XXAD.js.map → chunk-2GWM2CIT.js.map} +1 -1
  5. package/dist/{chunk-IS2QJ44P.js → chunk-4EXFRREO.js} +3 -3
  6. package/dist/{chunk-IS2QJ44P.js.map → chunk-4EXFRREO.js.map} +1 -1
  7. package/dist/{chunk-FVA2YDEQ.js → chunk-55ALGIAR.js} +4 -4
  8. package/dist/{chunk-FVA2YDEQ.js.map → chunk-55ALGIAR.js.map} +1 -1
  9. package/dist/{chunk-ZKKJQS6R.js → chunk-B4CGFDZQ.js} +29 -7
  10. package/dist/chunk-B4CGFDZQ.js.map +1 -0
  11. package/dist/{chunk-5RZ3NZ2M.cjs → chunk-C4JCSBFO.cjs} +5 -5
  12. package/dist/{chunk-5RZ3NZ2M.cjs.map → chunk-C4JCSBFO.cjs.map} +1 -1
  13. package/dist/{chunk-NN2GODP4.cjs → chunk-DK6VFPVK.cjs} +7 -7
  14. package/dist/{chunk-NN2GODP4.cjs.map → chunk-DK6VFPVK.cjs.map} +1 -1
  15. package/dist/{chunk-EEQHQKPP.cjs → chunk-FMTNB27Z.cjs} +32 -32
  16. package/dist/{chunk-EEQHQKPP.cjs.map → chunk-FMTNB27Z.cjs.map} +1 -1
  17. package/dist/{chunk-UV64CWMA.cjs → chunk-JAX4LFGG.cjs} +13 -13
  18. package/dist/{chunk-UV64CWMA.cjs.map → chunk-JAX4LFGG.cjs.map} +1 -1
  19. package/dist/{chunk-7EVW3Z37.js → chunk-LCXOOJIP.js} +3 -3
  20. package/dist/{chunk-7EVW3Z37.js.map → chunk-LCXOOJIP.js.map} +1 -1
  21. package/dist/{chunk-QVLMGNQF.js → chunk-LKASEUWE.js} +4 -4
  22. package/dist/{chunk-QVLMGNQF.js.map → chunk-LKASEUWE.js.map} +1 -1
  23. package/dist/{chunk-4UUEGERM.cjs → chunk-PWOECUNT.cjs} +17 -17
  24. package/dist/{chunk-4UUEGERM.cjs.map → chunk-PWOECUNT.cjs.map} +1 -1
  25. package/dist/{chunk-KKIYPZOP.cjs → chunk-RYVFCHSO.cjs} +29 -7
  26. package/dist/chunk-RYVFCHSO.cjs.map +1 -0
  27. package/dist/{chunk-NIDUQZIN.js → chunk-VFU663OM.js} +3 -3
  28. package/dist/{chunk-NIDUQZIN.js.map → chunk-VFU663OM.js.map} +1 -1
  29. package/dist/{chunk-RRTFFAG3.cjs → chunk-VUYLXWCB.cjs} +5 -5
  30. package/dist/{chunk-RRTFFAG3.cjs.map → chunk-VUYLXWCB.cjs.map} +1 -1
  31. package/dist/correlation-id.cjs +10 -10
  32. package/dist/correlation-id.js +2 -2
  33. package/dist/decorators.cjs +4 -4
  34. package/dist/decorators.js +3 -3
  35. package/dist/event.cjs +6 -6
  36. package/dist/event.js +3 -3
  37. package/dist/functional.cjs +11 -11
  38. package/dist/functional.js +3 -3
  39. package/dist/http.cjs +3 -3
  40. package/dist/http.js +2 -2
  41. package/dist/index.cjs +215 -70
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.cts +185 -2
  44. package/dist/index.d.ts +185 -2
  45. package/dist/index.js +149 -12
  46. package/dist/index.js.map +1 -1
  47. package/dist/{init-BSyIyDs5.d.ts → init-DyE43paw.d.ts} +7 -2
  48. package/dist/{init-D9Bxx39e.d.cts → init-gyesUMwz.d.cts} +7 -2
  49. package/dist/instrumentation.cjs +8 -8
  50. package/dist/instrumentation.js +1 -1
  51. package/dist/messaging.cjs +7 -7
  52. package/dist/messaging.js +4 -4
  53. package/dist/semantic-helpers.cjs +8 -8
  54. package/dist/semantic-helpers.js +4 -4
  55. package/dist/webhook.cjs +5 -5
  56. package/dist/webhook.js +3 -3
  57. package/dist/workflow-distributed.cjs +5 -5
  58. package/dist/workflow-distributed.js +3 -3
  59. package/dist/workflow.cjs +8 -8
  60. package/dist/workflow.js +4 -4
  61. package/dist/yaml-config.d.cts +1 -1
  62. package/dist/yaml-config.d.ts +1 -1
  63. package/package.json +9 -9
  64. package/skills/build-audit-trails/SKILL.md +163 -5
  65. package/skills/build-audit-trails/references/audit-queries.md +73 -0
  66. package/skills/build-audit-trails/references/framework-wiring.md +196 -0
  67. package/skills/review-otel-patterns/SKILL.md +44 -0
  68. package/src/error-catalog.test.ts +133 -0
  69. package/src/error-catalog.ts +262 -0
  70. package/src/gen-ai-cost.test.ts +81 -0
  71. package/src/gen-ai-cost.ts +145 -0
  72. package/src/index.ts +29 -0
  73. package/src/init-auto-redactor.test.ts +53 -0
  74. package/src/init.ts +50 -7
  75. package/dist/chunk-KKIYPZOP.cjs.map +0 -1
  76. package/dist/chunk-ZKKJQS6R.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,26 +1,26 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk7EQ4G4SI_cjs = require('./chunk-7EQ4G4SI.cjs');
4
- var chunk5RZ3NZ2M_cjs = require('./chunk-5RZ3NZ2M.cjs');
4
+ var chunkC4JCSBFO_cjs = require('./chunk-C4JCSBFO.cjs');
5
5
  var chunkM3LFHHTN_cjs = require('./chunk-M3LFHHTN.cjs');
6
6
  var chunk2ZKEORFN_cjs = require('./chunk-2ZKEORFN.cjs');
7
7
  var chunkESMHTKLJ_cjs = require('./chunk-ESMHTKLJ.cjs');
8
8
  var chunkT4B5LB6E_cjs = require('./chunk-T4B5LB6E.cjs');
9
- var chunkRRTFFAG3_cjs = require('./chunk-RRTFFAG3.cjs');
9
+ var chunkVUYLXWCB_cjs = require('./chunk-VUYLXWCB.cjs');
10
10
  var chunk4P6ZOARG_cjs = require('./chunk-4P6ZOARG.cjs');
11
11
  var chunkINJD3G4K_cjs = require('./chunk-INJD3G4K.cjs');
12
12
  var chunkTC5ZPWM4_cjs = require('./chunk-TC5ZPWM4.cjs');
13
13
  require('./chunk-YTXEZ4SD.cjs');
14
14
  var chunkWJH6IYU2_cjs = require('./chunk-WJH6IYU2.cjs');
15
- var chunkNN2GODP4_cjs = require('./chunk-NN2GODP4.cjs');
16
- var chunkEEQHQKPP_cjs = require('./chunk-EEQHQKPP.cjs');
15
+ var chunkDK6VFPVK_cjs = require('./chunk-DK6VFPVK.cjs');
16
+ var chunkFMTNB27Z_cjs = require('./chunk-FMTNB27Z.cjs');
17
17
  var chunk2GIBANLB_cjs = require('./chunk-2GIBANLB.cjs');
18
- var chunk4UUEGERM_cjs = require('./chunk-4UUEGERM.cjs');
18
+ var chunkPWOECUNT_cjs = require('./chunk-PWOECUNT.cjs');
19
19
  require('./chunk-NZ72VDNY.cjs');
20
20
  require('./chunk-UY3UYPBZ.cjs');
21
21
  var chunkVQTCQKHQ_cjs = require('./chunk-VQTCQKHQ.cjs');
22
- var chunkUV64CWMA_cjs = require('./chunk-UV64CWMA.cjs');
23
- var chunkKKIYPZOP_cjs = require('./chunk-KKIYPZOP.cjs');
22
+ var chunkJAX4LFGG_cjs = require('./chunk-JAX4LFGG.cjs');
23
+ var chunkRYVFCHSO_cjs = require('./chunk-RYVFCHSO.cjs');
24
24
  require('./chunk-FEEVB2GV.cjs');
25
25
  require('./chunk-CEAQK2QY.cjs');
26
26
  var chunkZNMBW67B_cjs = require('./chunk-ZNMBW67B.cjs');
@@ -55,7 +55,7 @@ var otelMethods = {
55
55
  setSpanContext: api.trace.setSpanContext
56
56
  };
57
57
  var trace2 = Object.assign(
58
- chunkEEQHQKPP_cjs.trace,
58
+ chunkFMTNB27Z_cjs.trace,
59
59
  otelMethods
60
60
  );
61
61
  function defineEvent(name, schema, options = {}) {
@@ -75,7 +75,7 @@ function defineEvent(name, schema, options = {}) {
75
75
  `Invalid payload for event "${name}". Schema validation failed.`
76
76
  );
77
77
  }
78
- chunkUV64CWMA_cjs.track(
78
+ chunkJAX4LFGG_cjs.track(
79
79
  name,
80
80
  parsed.data,
81
81
  schemaMetadata ? { schema: schemaMetadata } : void 0
@@ -103,7 +103,7 @@ async function flush(options) {
103
103
  const timeout = options?.timeout ?? 2e3;
104
104
  const forShutdown = options?.forShutdown ?? false;
105
105
  const doFlush = async () => {
106
- const eventsQueue = chunkUV64CWMA_cjs.getEventQueue();
106
+ const eventsQueue = chunkJAX4LFGG_cjs.getEventQueue();
107
107
  if (eventsQueue) {
108
108
  if (forShutdown) {
109
109
  await eventsQueue.shutdown();
@@ -111,7 +111,7 @@ async function flush(options) {
111
111
  await eventsQueue.flush();
112
112
  }
113
113
  }
114
- const sdk = chunkKKIYPZOP_cjs.getSdk();
114
+ const sdk = chunkRYVFCHSO_cjs.getSdk();
115
115
  if (sdk) {
116
116
  try {
117
117
  const sdkAny = sdk;
@@ -145,7 +145,7 @@ async function flush(options) {
145
145
  if (timeoutHandle) {
146
146
  clearTimeout(timeoutHandle);
147
147
  }
148
- const logger = chunkKKIYPZOP_cjs.getLogger();
148
+ const logger = chunkRYVFCHSO_cjs.getLogger();
149
149
  logger.error(
150
150
  {
151
151
  err: error instanceof Error ? error : new Error(String(error))
@@ -156,7 +156,7 @@ async function flush(options) {
156
156
  }
157
157
  }
158
158
  async function shutdown() {
159
- const logger = chunkKKIYPZOP_cjs.getLogger();
159
+ const logger = chunkRYVFCHSO_cjs.getLogger();
160
160
  let shutdownError = null;
161
161
  try {
162
162
  await flush({ forShutdown: true });
@@ -171,7 +171,7 @@ async function shutdown() {
171
171
  );
172
172
  }
173
173
  try {
174
- const sdk = chunkKKIYPZOP_cjs.getSdk();
174
+ const sdk = chunkRYVFCHSO_cjs.getSdk();
175
175
  if (sdk) {
176
176
  await sdk.shutdown();
177
177
  }
@@ -185,14 +185,14 @@ async function shutdown() {
185
185
  logger.error({ err }, "[autotel] SDK shutdown failed");
186
186
  }
187
187
  } finally {
188
- await chunkKKIYPZOP_cjs._closeEmbeddedDevtools();
189
- const eventsQueue = chunkUV64CWMA_cjs.getEventQueue();
188
+ await chunkRYVFCHSO_cjs._closeEmbeddedDevtools();
189
+ const eventsQueue = chunkJAX4LFGG_cjs.getEventQueue();
190
190
  if (eventsQueue && typeof eventsQueue.cleanup === "function") {
191
191
  eventsQueue.cleanup();
192
192
  }
193
- chunk4UUEGERM_cjs.resetEvents();
193
+ chunkPWOECUNT_cjs.resetEvents();
194
194
  chunkTC5ZPWM4_cjs.resetMetrics();
195
- chunkUV64CWMA_cjs.resetEventQueue();
195
+ chunkJAX4LFGG_cjs.resetEventQueue();
196
196
  }
197
197
  if (shutdownError) {
198
198
  throw shutdownError;
@@ -207,7 +207,7 @@ function registerShutdownHooks() {
207
207
  if (shuttingDown) return;
208
208
  shuttingDown = true;
209
209
  if (process.env.NODE_ENV !== "test") {
210
- chunkKKIYPZOP_cjs.getLogger().info(
210
+ chunkRYVFCHSO_cjs.getLogger().info(
211
211
  {},
212
212
  `[autotel] Received ${signal}, flushing telemetry...`
213
213
  );
@@ -215,7 +215,7 @@ function registerShutdownHooks() {
215
215
  try {
216
216
  await shutdown();
217
217
  } catch (error) {
218
- chunkKKIYPZOP_cjs.getLogger().error(
218
+ chunkRYVFCHSO_cjs.getLogger().error(
219
219
  {
220
220
  err: error instanceof Error ? error : void 0
221
221
  },
@@ -265,7 +265,7 @@ function resolveContext(ctx2) {
265
265
  "[autotel] getRequestLogger() requires an active span or runWithRequestContext(). Wrap your handler with trace() or use runWithRequestContext()."
266
266
  );
267
267
  }
268
- return chunkUV64CWMA_cjs.createTraceContext(span2);
268
+ return chunkJAX4LFGG_cjs.createTraceContext(span2);
269
269
  }
270
270
  function getRequestLogger(ctx2, options) {
271
271
  const activeContext = resolveContext(ctx2);
@@ -273,7 +273,7 @@ function getRequestLogger(ctx2, options) {
273
273
  let emitted = false;
274
274
  let lastSnapshot = null;
275
275
  const addLogEvent = (level, message, fields) => {
276
- const attrs2 = fields ? chunkUV64CWMA_cjs.flattenToAttributes(fields) : void 0;
276
+ const attrs2 = fields ? chunkJAX4LFGG_cjs.flattenToAttributes(fields) : void 0;
277
277
  chunk4P6ZOARG_cjs.emitCorrelatedEvent(activeContext, `log.${level}`, {
278
278
  message,
279
279
  ...attrs2 ?? {}
@@ -292,7 +292,7 @@ function getRequestLogger(ctx2, options) {
292
292
  sealCheck("log.set()", Object.keys(fields));
293
293
  if (emitted) return;
294
294
  mergeInto(contextState, fields);
295
- activeContext.setAttributes(chunkUV64CWMA_cjs.flattenToAttributes(fields));
295
+ activeContext.setAttributes(chunkJAX4LFGG_cjs.flattenToAttributes(fields));
296
296
  },
297
297
  info(message, fields) {
298
298
  const keys = fields ? ["message", ...Object.keys(fields).filter((k) => k !== "requestLogs")] : ["message"];
@@ -301,7 +301,7 @@ function getRequestLogger(ctx2, options) {
301
301
  addLogEvent("info", message, fields);
302
302
  if (fields) {
303
303
  mergeInto(contextState, fields);
304
- activeContext.setAttributes(chunkUV64CWMA_cjs.flattenToAttributes(fields));
304
+ activeContext.setAttributes(chunkJAX4LFGG_cjs.flattenToAttributes(fields));
305
305
  }
306
306
  },
307
307
  warn(message, fields) {
@@ -312,7 +312,7 @@ function getRequestLogger(ctx2, options) {
312
312
  activeContext.setAttribute("autotel.log.level", "warn");
313
313
  if (fields) {
314
314
  mergeInto(contextState, fields);
315
- activeContext.setAttributes(chunkUV64CWMA_cjs.flattenToAttributes(fields));
315
+ activeContext.setAttributes(chunkJAX4LFGG_cjs.flattenToAttributes(fields));
316
316
  }
317
317
  },
318
318
  error(error, fields) {
@@ -320,11 +320,11 @@ function getRequestLogger(ctx2, options) {
320
320
  sealCheck("log.error()", keys);
321
321
  if (emitted) return;
322
322
  const err = typeof error === "string" ? new Error(error) : error;
323
- chunkUV64CWMA_cjs.recordStructuredError(activeContext, err);
323
+ chunkJAX4LFGG_cjs.recordStructuredError(activeContext, err);
324
324
  addLogEvent("error", err.message, fields);
325
325
  if (fields) {
326
326
  mergeInto(contextState, fields);
327
- activeContext.setAttributes(chunkUV64CWMA_cjs.flattenToAttributes(fields));
327
+ activeContext.setAttributes(chunkJAX4LFGG_cjs.flattenToAttributes(fields));
328
328
  }
329
329
  activeContext.setAttribute("autotel.log.level", "error");
330
330
  },
@@ -340,7 +340,7 @@ function getRequestLogger(ctx2, options) {
340
340
  ...contextState,
341
341
  ...overrides ?? {}
342
342
  };
343
- const flattened = chunkUV64CWMA_cjs.flattenToAttributes(mergedContext);
343
+ const flattened = chunkJAX4LFGG_cjs.flattenToAttributes(mergedContext);
344
344
  activeContext.setAttributes(flattened);
345
345
  const snapshot = {
346
346
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -372,7 +372,7 @@ function getRequestLogger(ctx2, options) {
372
372
  const lifecycle = forkOptions?.lifecycle;
373
373
  void tracer.startActiveSpan(`request.fork:${label}`, (childSpan) => {
374
374
  const childContext = {
375
- ...chunkUV64CWMA_cjs.createTraceContext(childSpan),
375
+ ...chunkJAX4LFGG_cjs.createTraceContext(childSpan),
376
376
  correlationId: crypto.randomUUID()
377
377
  };
378
378
  requestContextStore.run(childContext, () => {
@@ -405,6 +405,86 @@ function getRequestLogger(ctx2, options) {
405
405
  };
406
406
  }
407
407
 
408
+ // src/error-catalog.ts
409
+ var catalogCodeKey = /* @__PURE__ */ Symbol.for("autotel.catalog.code");
410
+ function readCatalogCode(error) {
411
+ if (error === null || typeof error !== "object") return void 0;
412
+ return error[catalogCodeKey];
413
+ }
414
+ function isCatalogError(error) {
415
+ return readCatalogCode(error) !== void 0;
416
+ }
417
+ function getCatalogCode(error) {
418
+ return readCatalogCode(error);
419
+ }
420
+ function defineErrorCatalog(namespace, entries) {
421
+ const catalog = {};
422
+ for (const [key, entry] of Object.entries(entries)) {
423
+ const code = entry.code ?? `${namespace}.${key}`;
424
+ const usesParams = typeof entry.message === "function" || typeof entry.why === "function";
425
+ const builder = ((paramsOrOptions, maybeOptions) => {
426
+ const params = usesParams ? paramsOrOptions : void 0;
427
+ const options = usesParams ? maybeOptions : paramsOrOptions;
428
+ const message = typeof entry.message === "function" ? entry.message(params) : entry.message;
429
+ const why = typeof entry.why === "function" ? entry.why(params) : entry.why;
430
+ const error = chunkJAX4LFGG_cjs.createStructuredError({
431
+ message,
432
+ name: entry.name ?? key,
433
+ code,
434
+ ...entry.status === void 0 ? {} : { status: entry.status },
435
+ ...why === void 0 ? {} : { why },
436
+ ...entry.fix === void 0 ? {} : { fix: entry.fix },
437
+ ...entry.link === void 0 ? {} : { link: entry.link },
438
+ ...options?.cause === void 0 ? {} : { cause: options.cause },
439
+ ...options?.details === void 0 ? {} : { details: options.details },
440
+ ...options?.internal === void 0 ? {} : { internal: options.internal }
441
+ });
442
+ Object.defineProperty(error, catalogCodeKey, {
443
+ value: code,
444
+ enumerable: false,
445
+ writable: false,
446
+ configurable: true
447
+ });
448
+ return error;
449
+ });
450
+ Object.defineProperty(builder, "code", {
451
+ value: code,
452
+ enumerable: true
453
+ });
454
+ Object.defineProperty(builder, "match", {
455
+ value: (error) => readCatalogCode(error) === code,
456
+ enumerable: false
457
+ });
458
+ catalog[key] = builder;
459
+ }
460
+ return Object.freeze(catalog);
461
+ }
462
+ function defineAuditCatalog(namespace, entries) {
463
+ const catalog = {};
464
+ for (const [key, entry] of Object.entries(entries)) {
465
+ const action = entry.action ?? `${namespace}.${key}`;
466
+ const severity = entry.severity ?? "info";
467
+ const descriptor = ((params) => {
468
+ const message = typeof entry.message === "function" ? entry.message(params) : entry.message;
469
+ return Object.freeze({
470
+ action,
471
+ severity,
472
+ ...message === void 0 ? {} : { message }
473
+ });
474
+ });
475
+ Object.defineProperty(descriptor, "action", {
476
+ value: action,
477
+ enumerable: true
478
+ });
479
+ Object.defineProperty(descriptor, "severity", {
480
+ value: severity,
481
+ enumerable: true
482
+ });
483
+ catalog[key] = descriptor;
484
+ }
485
+ return Object.freeze(catalog);
486
+ }
487
+
408
488
  // src/drain-toolkit.ts
409
489
  var DEFAULT_TIMEOUT_MS = 5e3;
410
490
  var DEFAULT_RETRIES = 2;
@@ -641,25 +721,82 @@ function buildStreamFirstTokenAttrs(event) {
641
721
  return attrs2;
642
722
  }
643
723
 
724
+ // src/gen-ai-cost.ts
725
+ var GEN_AI_COST_ATTRIBUTE = "gen_ai.usage.cost.usd";
726
+ var MODEL_PRICING = {
727
+ // OpenAI
728
+ "gpt-4o": { inputPer1M: 2.5, outputPer1M: 10 },
729
+ "gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6 },
730
+ "gpt-4.1": { inputPer1M: 2, outputPer1M: 8 },
731
+ "gpt-4.1-mini": { inputPer1M: 0.4, outputPer1M: 1.6 },
732
+ "gpt-4.1-nano": { inputPer1M: 0.1, outputPer1M: 0.4 },
733
+ "o3-mini": { inputPer1M: 1.1, outputPer1M: 4.4 },
734
+ // Anthropic Claude
735
+ "claude-opus-4": { inputPer1M: 15, outputPer1M: 75 },
736
+ "claude-sonnet-4": { inputPer1M: 3, outputPer1M: 15 },
737
+ "claude-3-5-sonnet": { inputPer1M: 3, outputPer1M: 15 },
738
+ "claude-3-5-haiku": { inputPer1M: 0.8, outputPer1M: 4 },
739
+ "claude-3-opus": { inputPer1M: 15, outputPer1M: 75 },
740
+ "claude-3-haiku": { inputPer1M: 0.25, outputPer1M: 1.25 },
741
+ // Google Gemini
742
+ "gemini-1.5-pro": { inputPer1M: 1.25, outputPer1M: 5 },
743
+ "gemini-1.5-flash": { inputPer1M: 0.075, outputPer1M: 0.3 },
744
+ "gemini-2.0-flash": { inputPer1M: 0.1, outputPer1M: 0.4 }
745
+ };
746
+ function resolvePricing(table, model) {
747
+ const exact = table[model];
748
+ if (exact) return exact;
749
+ let best;
750
+ let bestLength = 0;
751
+ for (const key of Object.keys(table)) {
752
+ if (model.startsWith(key) && key.length > bestLength) {
753
+ best = table[key];
754
+ bestLength = key.length;
755
+ }
756
+ }
757
+ return best;
758
+ }
759
+ function round(value) {
760
+ return Math.round(value * 1e6) / 1e6;
761
+ }
762
+ function estimateLLMCost(model, usage, options) {
763
+ const table = options?.pricing ? { ...MODEL_PRICING, ...options.pricing } : MODEL_PRICING;
764
+ const price = resolvePricing(table, model);
765
+ if (!price) return void 0;
766
+ const cachedInput = usage.cachedInputTokens ?? 0;
767
+ const billedInput = Math.max(0, (usage.inputTokens ?? 0) - cachedInput);
768
+ const output = usage.outputTokens ?? 0;
769
+ const cachedRate = price.cachedInputPer1M ?? price.inputPer1M;
770
+ const cost = billedInput / 1e6 * price.inputPer1M + cachedInput / 1e6 * cachedRate + output / 1e6 * price.outputPer1M;
771
+ return round(cost);
772
+ }
773
+ function recordLLMCost(ctx2, model, usage, options) {
774
+ const cost = estimateLLMCost(model, usage, options);
775
+ if (cost !== void 0) {
776
+ ctx2.setAttribute(GEN_AI_COST_ATTRIBUTE, cost);
777
+ }
778
+ return cost;
779
+ }
780
+
644
781
  Object.defineProperty(exports, "createDrainPipeline", {
645
782
  enumerable: true,
646
783
  get: function () { return chunk7EQ4G4SI_cjs.createDrainPipeline; }
647
784
  });
648
785
  Object.defineProperty(exports, "getCurrentWorkflowContext", {
649
786
  enumerable: true,
650
- get: function () { return chunk5RZ3NZ2M_cjs.getCurrentWorkflowContext; }
787
+ get: function () { return chunkC4JCSBFO_cjs.getCurrentWorkflowContext; }
651
788
  });
652
789
  Object.defineProperty(exports, "isInWorkflow", {
653
790
  enumerable: true,
654
- get: function () { return chunk5RZ3NZ2M_cjs.isInWorkflow; }
791
+ get: function () { return chunkC4JCSBFO_cjs.isInWorkflow; }
655
792
  });
656
793
  Object.defineProperty(exports, "traceStep", {
657
794
  enumerable: true,
658
- get: function () { return chunk5RZ3NZ2M_cjs.traceStep; }
795
+ get: function () { return chunkC4JCSBFO_cjs.traceStep; }
659
796
  });
660
797
  Object.defineProperty(exports, "traceWorkflow", {
661
798
  enumerable: true,
662
- get: function () { return chunk5RZ3NZ2M_cjs.traceWorkflow; }
799
+ get: function () { return chunkC4JCSBFO_cjs.traceWorkflow; }
663
800
  });
664
801
  Object.defineProperty(exports, "attrs", {
665
802
  enumerable: true,
@@ -751,11 +888,11 @@ Object.defineProperty(exports, "parseError", {
751
888
  });
752
889
  Object.defineProperty(exports, "traceConsumer", {
753
890
  enumerable: true,
754
- get: function () { return chunkRRTFFAG3_cjs.traceConsumer; }
891
+ get: function () { return chunkVUYLXWCB_cjs.traceConsumer; }
755
892
  });
756
893
  Object.defineProperty(exports, "traceProducer", {
757
894
  enumerable: true,
758
- get: function () { return chunkRRTFFAG3_cjs.traceProducer; }
895
+ get: function () { return chunkVUYLXWCB_cjs.traceProducer; }
759
896
  });
760
897
  Object.defineProperty(exports, "BusinessBaggage", {
761
898
  enumerable: true,
@@ -799,47 +936,47 @@ Object.defineProperty(exports, "getMeter", {
799
936
  });
800
937
  Object.defineProperty(exports, "traceDB", {
801
938
  enumerable: true,
802
- get: function () { return chunkNN2GODP4_cjs.traceDB; }
939
+ get: function () { return chunkDK6VFPVK_cjs.traceDB; }
803
940
  });
804
941
  Object.defineProperty(exports, "traceHTTP", {
805
942
  enumerable: true,
806
- get: function () { return chunkNN2GODP4_cjs.traceHTTP; }
943
+ get: function () { return chunkDK6VFPVK_cjs.traceHTTP; }
807
944
  });
808
945
  Object.defineProperty(exports, "traceLLM", {
809
946
  enumerable: true,
810
- get: function () { return chunkNN2GODP4_cjs.traceLLM; }
947
+ get: function () { return chunkDK6VFPVK_cjs.traceLLM; }
811
948
  });
812
949
  Object.defineProperty(exports, "traceMessaging", {
813
950
  enumerable: true,
814
- get: function () { return chunkNN2GODP4_cjs.traceMessaging; }
951
+ get: function () { return chunkDK6VFPVK_cjs.traceMessaging; }
815
952
  });
816
953
  Object.defineProperty(exports, "ctx", {
817
954
  enumerable: true,
818
- get: function () { return chunkEEQHQKPP_cjs.ctx; }
955
+ get: function () { return chunkFMTNB27Z_cjs.ctx; }
819
956
  });
820
957
  Object.defineProperty(exports, "instrument", {
821
958
  enumerable: true,
822
- get: function () { return chunkEEQHQKPP_cjs.instrument; }
959
+ get: function () { return chunkFMTNB27Z_cjs.instrument; }
823
960
  });
824
961
  Object.defineProperty(exports, "markAsImmediate", {
825
962
  enumerable: true,
826
- get: function () { return chunkEEQHQKPP_cjs.markAsImmediate; }
963
+ get: function () { return chunkFMTNB27Z_cjs.markAsImmediate; }
827
964
  });
828
965
  Object.defineProperty(exports, "span", {
829
966
  enumerable: true,
830
- get: function () { return chunkEEQHQKPP_cjs.span; }
967
+ get: function () { return chunkFMTNB27Z_cjs.span; }
831
968
  });
832
969
  Object.defineProperty(exports, "withBaggage", {
833
970
  enumerable: true,
834
- get: function () { return chunkEEQHQKPP_cjs.withBaggage; }
971
+ get: function () { return chunkFMTNB27Z_cjs.withBaggage; }
835
972
  });
836
973
  Object.defineProperty(exports, "withNewContext", {
837
974
  enumerable: true,
838
- get: function () { return chunkEEQHQKPP_cjs.withNewContext; }
975
+ get: function () { return chunkFMTNB27Z_cjs.withNewContext; }
839
976
  });
840
977
  Object.defineProperty(exports, "withTracing", {
841
978
  enumerable: true,
842
- get: function () { return chunkEEQHQKPP_cjs.withTracing; }
979
+ get: function () { return chunkFMTNB27Z_cjs.withTracing; }
843
980
  });
844
981
  Object.defineProperty(exports, "createDeterministicTraceId", {
845
982
  enumerable: true,
@@ -887,15 +1024,15 @@ Object.defineProperty(exports, "runWithSpan", {
887
1024
  });
888
1025
  Object.defineProperty(exports, "Event", {
889
1026
  enumerable: true,
890
- get: function () { return chunk4UUEGERM_cjs.Event; }
1027
+ get: function () { return chunkPWOECUNT_cjs.Event; }
891
1028
  });
892
1029
  Object.defineProperty(exports, "getEvents", {
893
1030
  enumerable: true,
894
- get: function () { return chunk4UUEGERM_cjs.getEvents; }
1031
+ get: function () { return chunkPWOECUNT_cjs.getEvents; }
895
1032
  });
896
1033
  Object.defineProperty(exports, "resetEvents", {
897
1034
  enumerable: true,
898
- get: function () { return chunk4UUEGERM_cjs.resetEvents; }
1035
+ get: function () { return chunkPWOECUNT_cjs.resetEvents; }
899
1036
  });
900
1037
  Object.defineProperty(exports, "getOperationContext", {
901
1038
  enumerable: true,
@@ -907,87 +1044,87 @@ Object.defineProperty(exports, "runInOperationContext", {
907
1044
  });
908
1045
  Object.defineProperty(exports, "CORRELATION_ID_BAGGAGE_KEY", {
909
1046
  enumerable: true,
910
- get: function () { return chunkUV64CWMA_cjs.CORRELATION_ID_BAGGAGE_KEY; }
1047
+ get: function () { return chunkJAX4LFGG_cjs.CORRELATION_ID_BAGGAGE_KEY; }
911
1048
  });
912
1049
  Object.defineProperty(exports, "createStructuredError", {
913
1050
  enumerable: true,
914
- get: function () { return chunkUV64CWMA_cjs.createStructuredError; }
1051
+ get: function () { return chunkJAX4LFGG_cjs.createStructuredError; }
915
1052
  });
916
1053
  Object.defineProperty(exports, "defineBaggageSchema", {
917
1054
  enumerable: true,
918
- get: function () { return chunkUV64CWMA_cjs.defineBaggageSchema; }
1055
+ get: function () { return chunkJAX4LFGG_cjs.defineBaggageSchema; }
919
1056
  });
920
1057
  Object.defineProperty(exports, "flattenToAttributes", {
921
1058
  enumerable: true,
922
- get: function () { return chunkUV64CWMA_cjs.flattenToAttributes; }
1059
+ get: function () { return chunkJAX4LFGG_cjs.flattenToAttributes; }
923
1060
  });
924
1061
  Object.defineProperty(exports, "generateCorrelationId", {
925
1062
  enumerable: true,
926
- get: function () { return chunkUV64CWMA_cjs.generateCorrelationId; }
1063
+ get: function () { return chunkJAX4LFGG_cjs.generateCorrelationId; }
927
1064
  });
928
1065
  Object.defineProperty(exports, "getCorrelationId", {
929
1066
  enumerable: true,
930
- get: function () { return chunkUV64CWMA_cjs.getCorrelationId; }
1067
+ get: function () { return chunkJAX4LFGG_cjs.getCorrelationId; }
931
1068
  });
932
1069
  Object.defineProperty(exports, "getEventQueue", {
933
1070
  enumerable: true,
934
- get: function () { return chunkUV64CWMA_cjs.getEventQueue; }
1071
+ get: function () { return chunkJAX4LFGG_cjs.getEventQueue; }
935
1072
  });
936
1073
  Object.defineProperty(exports, "getOrCreateCorrelationId", {
937
1074
  enumerable: true,
938
- get: function () { return chunkUV64CWMA_cjs.getOrCreateCorrelationId; }
1075
+ get: function () { return chunkJAX4LFGG_cjs.getOrCreateCorrelationId; }
939
1076
  });
940
1077
  Object.defineProperty(exports, "getStructuredErrorAttributes", {
941
1078
  enumerable: true,
942
- get: function () { return chunkUV64CWMA_cjs.getStructuredErrorAttributes; }
1079
+ get: function () { return chunkJAX4LFGG_cjs.getStructuredErrorAttributes; }
943
1080
  });
944
1081
  Object.defineProperty(exports, "recordStructuredError", {
945
1082
  enumerable: true,
946
- get: function () { return chunkUV64CWMA_cjs.recordStructuredError; }
1083
+ get: function () { return chunkJAX4LFGG_cjs.recordStructuredError; }
947
1084
  });
948
1085
  Object.defineProperty(exports, "runWithCorrelationId", {
949
1086
  enumerable: true,
950
- get: function () { return chunkUV64CWMA_cjs.runWithCorrelationId; }
1087
+ get: function () { return chunkJAX4LFGG_cjs.runWithCorrelationId; }
951
1088
  });
952
1089
  Object.defineProperty(exports, "setCorrelationId", {
953
1090
  enumerable: true,
954
- get: function () { return chunkUV64CWMA_cjs.setCorrelationId; }
1091
+ get: function () { return chunkJAX4LFGG_cjs.setCorrelationId; }
955
1092
  });
956
1093
  Object.defineProperty(exports, "setCorrelationIdInBaggage", {
957
1094
  enumerable: true,
958
- get: function () { return chunkUV64CWMA_cjs.setCorrelationIdInBaggage; }
1095
+ get: function () { return chunkJAX4LFGG_cjs.setCorrelationIdInBaggage; }
959
1096
  });
960
1097
  Object.defineProperty(exports, "structuredErrorToJSON", {
961
1098
  enumerable: true,
962
- get: function () { return chunkUV64CWMA_cjs.structuredErrorToJSON; }
1099
+ get: function () { return chunkJAX4LFGG_cjs.structuredErrorToJSON; }
963
1100
  });
964
1101
  Object.defineProperty(exports, "toAttributeValue", {
965
1102
  enumerable: true,
966
- get: function () { return chunkUV64CWMA_cjs.toAttributeValue; }
1103
+ get: function () { return chunkJAX4LFGG_cjs.toAttributeValue; }
967
1104
  });
968
1105
  Object.defineProperty(exports, "track", {
969
1106
  enumerable: true,
970
- get: function () { return chunkUV64CWMA_cjs.track; }
1107
+ get: function () { return chunkJAX4LFGG_cjs.track; }
971
1108
  });
972
1109
  Object.defineProperty(exports, "BaggageSpanProcessor", {
973
1110
  enumerable: true,
974
- get: function () { return chunkKKIYPZOP_cjs.BaggageSpanProcessor; }
1111
+ get: function () { return chunkRYVFCHSO_cjs.BaggageSpanProcessor; }
975
1112
  });
976
1113
  Object.defineProperty(exports, "createStringRedactor", {
977
1114
  enumerable: true,
978
- get: function () { return chunkKKIYPZOP_cjs.createStringRedactor; }
1115
+ get: function () { return chunkRYVFCHSO_cjs.createStringRedactor; }
979
1116
  });
980
1117
  Object.defineProperty(exports, "init", {
981
1118
  enumerable: true,
982
- get: function () { return chunkKKIYPZOP_cjs.init; }
1119
+ get: function () { return chunkRYVFCHSO_cjs.init; }
983
1120
  });
984
1121
  Object.defineProperty(exports, "isLoggerLocked", {
985
1122
  enumerable: true,
986
- get: function () { return chunkKKIYPZOP_cjs.isLoggerLocked; }
1123
+ get: function () { return chunkRYVFCHSO_cjs.isLoggerLocked; }
987
1124
  });
988
1125
  Object.defineProperty(exports, "lockLogger", {
989
1126
  enumerable: true,
990
- get: function () { return chunkKKIYPZOP_cjs.lockLogger; }
1127
+ get: function () { return chunkRYVFCHSO_cjs.lockLogger; }
991
1128
  });
992
1129
  Object.defineProperty(exports, "FilteringSpanProcessor", {
993
1130
  enumerable: true,
@@ -1117,17 +1254,25 @@ Object.defineProperty(exports, "propagation", {
1117
1254
  enumerable: true,
1118
1255
  get: function () { return api.propagation; }
1119
1256
  });
1257
+ exports.GEN_AI_COST_ATTRIBUTE = GEN_AI_COST_ATTRIBUTE;
1120
1258
  exports.GEN_AI_COST_USD_BUCKETS = GEN_AI_COST_USD_BUCKETS;
1121
1259
  exports.GEN_AI_DURATION_BUCKETS_SECONDS = GEN_AI_DURATION_BUCKETS_SECONDS;
1122
1260
  exports.GEN_AI_TOKEN_USAGE_BUCKETS = GEN_AI_TOKEN_USAGE_BUCKETS;
1261
+ exports.MODEL_PRICING = MODEL_PRICING;
1262
+ exports.defineAuditCatalog = defineAuditCatalog;
1123
1263
  exports.defineDrain = defineDrain;
1124
1264
  exports.defineEnricher = defineEnricher;
1265
+ exports.defineErrorCatalog = defineErrorCatalog;
1125
1266
  exports.defineEvent = defineEvent;
1126
1267
  exports.defineHttpDrain = defineHttpDrain;
1268
+ exports.estimateLLMCost = estimateLLMCost;
1127
1269
  exports.flush = flush;
1128
1270
  exports.genAiMetricViews = genAiMetricViews;
1271
+ exports.getCatalogCode = getCatalogCode;
1129
1272
  exports.getRequestLogger = getRequestLogger;
1273
+ exports.isCatalogError = isCatalogError;
1130
1274
  exports.llmHistogramAdvice = llmHistogramAdvice;
1275
+ exports.recordLLMCost = recordLLMCost;
1131
1276
  exports.recordPromptSent = recordPromptSent;
1132
1277
  exports.recordResponseReceived = recordResponseReceived;
1133
1278
  exports.recordRetry = recordRetry;