autotel 3.2.0 → 3.3.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.
- package/dist/auto.cjs +2 -2
- package/dist/auto.js +1 -1
- package/dist/{chunk-ZKKJQS6R.js → chunk-32AXF4MA.js} +29 -7
- package/dist/chunk-32AXF4MA.js.map +1 -0
- package/dist/{chunk-RRTFFAG3.cjs → chunk-3MZJ7Y24.cjs} +5 -5
- package/dist/{chunk-RRTFFAG3.cjs.map → chunk-3MZJ7Y24.cjs.map} +1 -1
- package/dist/{chunk-5RZ3NZ2M.cjs → chunk-4RA6HIYF.cjs} +5 -5
- package/dist/{chunk-5RZ3NZ2M.cjs.map → chunk-4RA6HIYF.cjs.map} +1 -1
- package/dist/{chunk-NIDUQZIN.js → chunk-4TAQQZDU.js} +3 -3
- package/dist/{chunk-NIDUQZIN.js.map → chunk-4TAQQZDU.js.map} +1 -1
- package/dist/{chunk-UV64CWMA.cjs → chunk-DQSVSGK3.cjs} +13 -13
- package/dist/{chunk-UV64CWMA.cjs.map → chunk-DQSVSGK3.cjs.map} +1 -1
- package/dist/{chunk-IS2QJ44P.js → chunk-FZROHTZZ.js} +3 -3
- package/dist/{chunk-IS2QJ44P.js.map → chunk-FZROHTZZ.js.map} +1 -1
- package/dist/{chunk-4UUEGERM.cjs → chunk-MQH5OOZK.cjs} +17 -17
- package/dist/{chunk-4UUEGERM.cjs.map → chunk-MQH5OOZK.cjs.map} +1 -1
- package/dist/{chunk-QVLMGNQF.js → chunk-OACAWYLR.js} +4 -4
- package/dist/{chunk-QVLMGNQF.js.map → chunk-OACAWYLR.js.map} +1 -1
- package/dist/{chunk-RZI5XXAD.js → chunk-OPCTN527.js} +3 -3
- package/dist/{chunk-RZI5XXAD.js.map → chunk-OPCTN527.js.map} +1 -1
- package/dist/{chunk-NN2GODP4.cjs → chunk-QICFEFD6.cjs} +7 -7
- package/dist/{chunk-NN2GODP4.cjs.map → chunk-QICFEFD6.cjs.map} +1 -1
- package/dist/{chunk-KKIYPZOP.cjs → chunk-QJYWKAC5.cjs} +29 -7
- package/dist/chunk-QJYWKAC5.cjs.map +1 -0
- package/dist/{chunk-7EVW3Z37.js → chunk-TGV2XF57.js} +3 -3
- package/dist/{chunk-7EVW3Z37.js.map → chunk-TGV2XF57.js.map} +1 -1
- package/dist/{chunk-FVA2YDEQ.js → chunk-U4D5IBSB.js} +4 -4
- package/dist/{chunk-FVA2YDEQ.js.map → chunk-U4D5IBSB.js.map} +1 -1
- package/dist/{chunk-EEQHQKPP.cjs → chunk-U72TGONP.cjs} +32 -32
- package/dist/{chunk-EEQHQKPP.cjs.map → chunk-U72TGONP.cjs.map} +1 -1
- package/dist/correlation-id.cjs +10 -10
- package/dist/correlation-id.js +2 -2
- package/dist/decorators.cjs +4 -4
- package/dist/decorators.js +3 -3
- package/dist/event.cjs +6 -6
- package/dist/event.js +3 -3
- package/dist/functional.cjs +11 -11
- package/dist/functional.js +3 -3
- package/dist/http.cjs +3 -3
- package/dist/http.js +2 -2
- package/dist/index.cjs +215 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +185 -2
- package/dist/index.d.ts +185 -2
- package/dist/index.js +149 -12
- package/dist/index.js.map +1 -1
- package/dist/{init-BSyIyDs5.d.ts → init-DyE43paw.d.ts} +7 -2
- package/dist/{init-D9Bxx39e.d.cts → init-gyesUMwz.d.cts} +7 -2
- package/dist/instrumentation.cjs +8 -8
- package/dist/instrumentation.js +1 -1
- package/dist/messaging.cjs +7 -7
- package/dist/messaging.js +4 -4
- package/dist/semantic-helpers.cjs +8 -8
- package/dist/semantic-helpers.js +4 -4
- package/dist/webhook.cjs +5 -5
- package/dist/webhook.js +3 -3
- package/dist/workflow-distributed.cjs +5 -5
- package/dist/workflow-distributed.js +3 -3
- package/dist/workflow.cjs +8 -8
- package/dist/workflow.js +4 -4
- package/dist/yaml-config.d.cts +1 -1
- package/dist/yaml-config.d.ts +1 -1
- package/package.json +1 -1
- package/skills/build-audit-trails/SKILL.md +150 -5
- package/skills/build-audit-trails/references/audit-queries.md +73 -0
- package/skills/build-audit-trails/references/framework-wiring.md +187 -0
- package/skills/review-otel-patterns/SKILL.md +41 -0
- package/src/error-catalog.test.ts +128 -0
- package/src/error-catalog.ts +259 -0
- package/src/gen-ai-cost.test.ts +81 -0
- package/src/gen-ai-cost.ts +145 -0
- package/src/index.ts +29 -0
- package/src/init-auto-redactor.test.ts +53 -0
- package/src/init.ts +46 -7
- package/dist/chunk-KKIYPZOP.cjs.map +0 -1
- package/dist/chunk-ZKKJQS6R.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AutotelConfig, i as init, a as isLoggerLocked, l as lockLogger } from './init-
|
|
1
|
+
export { A as AutotelConfig, i as init, a as isLoggerLocked, l as lockLogger } from './init-DyE43paw.js';
|
|
2
2
|
import { Span, Context, trace as trace$2 } from '@opentelemetry/api';
|
|
3
3
|
export { AttributeValue, Attributes, Baggage, BaggageEntry, Context, Exception, HrTime, Link, ROOT_CONTEXT, Span, SpanAttributes, SpanContext, SpanKind, Link as SpanLink, SpanStatusCode, TextMapGetter, TextMapSetter, TimeInput, TraceFlags, TraceState, Tracer, TracerProvider, context, trace as otelTrace, propagation } from '@opentelemetry/api';
|
|
4
4
|
import { SpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
@@ -521,6 +521,125 @@ declare function structuredErrorToJSON(error: StructuredError): Record<string, u
|
|
|
521
521
|
declare function getStructuredErrorAttributes(error: Error): Record<string, AttributeValue>;
|
|
522
522
|
declare function recordStructuredError(ctx: Pick<TraceContext, 'setAttributes' | 'setStatus'>, error: Error): void;
|
|
523
523
|
|
|
524
|
+
/**
|
|
525
|
+
* Typed error and audit catalogs.
|
|
526
|
+
*
|
|
527
|
+
* Group related errors into one catalog and get a refactor-safe builder per
|
|
528
|
+
* code, with autocomplete at every call site and typed message parameters.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* import { defineErrorCatalog } from 'autotel';
|
|
533
|
+
*
|
|
534
|
+
* export const billing = defineErrorCatalog('billing', {
|
|
535
|
+
* PAYMENT_DECLINED: {
|
|
536
|
+
* status: 402,
|
|
537
|
+
* message: 'Card declined',
|
|
538
|
+
* why: 'The issuer rejected the charge',
|
|
539
|
+
* fix: 'Try a different payment method',
|
|
540
|
+
* },
|
|
541
|
+
* INSUFFICIENT_FUNDS: {
|
|
542
|
+
* status: 402,
|
|
543
|
+
* message: ({ available, required }: { available: number; required: number }) =>
|
|
544
|
+
* `Insufficient funds: $${available} of $${required}`,
|
|
545
|
+
* },
|
|
546
|
+
* });
|
|
547
|
+
*
|
|
548
|
+
* throw billing.PAYMENT_DECLINED({ cause: stripeError });
|
|
549
|
+
* throw billing.INSUFFICIENT_FUNDS({ available: 5, required: 100 });
|
|
550
|
+
*
|
|
551
|
+
* // In a catch block — refactor-safe, no magic strings:
|
|
552
|
+
* if (billing.PAYMENT_DECLINED.match(err)) { ... }
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
|
|
556
|
+
/** Definition of a single error in a catalog. */
|
|
557
|
+
interface ErrorCatalogEntry {
|
|
558
|
+
/**
|
|
559
|
+
* Human-readable message. Use a function to interpolate typed parameters;
|
|
560
|
+
* the parameter type flows through to the call site.
|
|
561
|
+
*/
|
|
562
|
+
message: string | ((params: never) => string);
|
|
563
|
+
/** HTTP status to surface to clients. */
|
|
564
|
+
status?: number;
|
|
565
|
+
/** Stable error code. Defaults to `${namespace}.${KEY}`. */
|
|
566
|
+
code?: string | number;
|
|
567
|
+
/** Why it happened. A function receives the same params as `message`. */
|
|
568
|
+
why?: string | ((params: never) => string);
|
|
569
|
+
/** What the caller should do next. */
|
|
570
|
+
fix?: string;
|
|
571
|
+
/** Docs or runbook link. */
|
|
572
|
+
link?: string;
|
|
573
|
+
/** Error name. Defaults to the catalog key. */
|
|
574
|
+
name?: string;
|
|
575
|
+
}
|
|
576
|
+
/** Per-call options passed alongside (or instead of) typed params. */
|
|
577
|
+
interface ErrorBuildOptions {
|
|
578
|
+
cause?: unknown;
|
|
579
|
+
details?: Record<string, unknown>;
|
|
580
|
+
/** Backend-only context. Never serialized to clients. */
|
|
581
|
+
internal?: Record<string, unknown>;
|
|
582
|
+
}
|
|
583
|
+
type ParamsOf<E> = E extends {
|
|
584
|
+
message: (params: infer P) => string;
|
|
585
|
+
} ? P : E extends {
|
|
586
|
+
why: (params: infer P) => string;
|
|
587
|
+
} ? P : void;
|
|
588
|
+
type BuilderArgs<E extends ErrorCatalogEntry> = ParamsOf<E> extends void ? [options?: ErrorBuildOptions] : [params: ParamsOf<E>, options?: ErrorBuildOptions];
|
|
589
|
+
/** A callable error factory produced by {@link defineErrorCatalog}. */
|
|
590
|
+
interface ErrorBuilder<E extends ErrorCatalogEntry> {
|
|
591
|
+
(...args: BuilderArgs<E>): StructuredError;
|
|
592
|
+
/** Stable code assigned to every error from this entry. */
|
|
593
|
+
readonly code: string | number;
|
|
594
|
+
/** True when `error` was produced by this catalog entry. */
|
|
595
|
+
match(error: unknown): boolean;
|
|
596
|
+
}
|
|
597
|
+
type ErrorCatalog<T extends Record<string, ErrorCatalogEntry>> = {
|
|
598
|
+
readonly [K in keyof T]: ErrorBuilder<T[K]>;
|
|
599
|
+
};
|
|
600
|
+
/** True when `error` was produced by any autotel error catalog. */
|
|
601
|
+
declare function isCatalogError(error: unknown): error is StructuredError;
|
|
602
|
+
/** Returns the catalog code of `error`, or `undefined` if it has none. */
|
|
603
|
+
declare function getCatalogCode(error: unknown): string | number | undefined;
|
|
604
|
+
/**
|
|
605
|
+
* Define a typed error catalog. Returns an object whose keys are error
|
|
606
|
+
* builders. Each builder produces a {@link StructuredError} carrying the
|
|
607
|
+
* entry's message, status, code, why, fix, and link.
|
|
608
|
+
*/
|
|
609
|
+
declare function defineErrorCatalog<const T extends Record<string, ErrorCatalogEntry>>(namespace: string, entries: T): ErrorCatalog<T>;
|
|
610
|
+
/** Severity of an audit action. */
|
|
611
|
+
type AuditSeverity = 'info' | 'warn' | 'critical';
|
|
612
|
+
/** Definition of a single action in an audit catalog. */
|
|
613
|
+
interface AuditCatalogEntry {
|
|
614
|
+
/** Human-readable description. Use a function for typed params. */
|
|
615
|
+
message?: string | ((params: never) => string);
|
|
616
|
+
/** Stable action name. Defaults to `${namespace}.${KEY}`. */
|
|
617
|
+
action?: string;
|
|
618
|
+
/** Severity of the action. Defaults to `'info'`. */
|
|
619
|
+
severity?: AuditSeverity;
|
|
620
|
+
}
|
|
621
|
+
/** A resolved audit action descriptor produced by an audit catalog. */
|
|
622
|
+
interface AuditAction {
|
|
623
|
+
readonly action: string;
|
|
624
|
+
readonly severity: AuditSeverity;
|
|
625
|
+
readonly message?: string;
|
|
626
|
+
}
|
|
627
|
+
type AuditDescriptorArgs<E extends AuditCatalogEntry> = ParamsOf<E> extends void ? [] : [params: ParamsOf<E>];
|
|
628
|
+
/** A callable audit-action descriptor produced by {@link defineAuditCatalog}. */
|
|
629
|
+
interface AuditDescriptor<E extends AuditCatalogEntry> {
|
|
630
|
+
(...args: AuditDescriptorArgs<E>): AuditAction;
|
|
631
|
+
readonly action: string;
|
|
632
|
+
readonly severity: AuditSeverity;
|
|
633
|
+
}
|
|
634
|
+
type AuditCatalog<T extends Record<string, AuditCatalogEntry>> = {
|
|
635
|
+
readonly [K in keyof T]: AuditDescriptor<T[K]>;
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Define a typed audit catalog. Returns typed action descriptors you can pass
|
|
639
|
+
* to `track()` or audit helpers without scattering magic strings.
|
|
640
|
+
*/
|
|
641
|
+
declare function defineAuditCatalog<const T extends Record<string, AuditCatalogEntry>>(namespace: string, entries: T): AuditCatalog<T>;
|
|
642
|
+
|
|
524
643
|
/**
|
|
525
644
|
* Convert an unknown value to an OTel-compatible AttributeValue.
|
|
526
645
|
* Returns undefined when the value cannot be represented.
|
|
@@ -789,4 +908,68 @@ declare function recordToolCall(ctx: TraceContext, event: ToolCallEvent): void;
|
|
|
789
908
|
*/
|
|
790
909
|
declare function recordStreamFirstToken(ctx: TraceContext, event?: StreamFirstTokenEvent): void;
|
|
791
910
|
|
|
792
|
-
|
|
911
|
+
/**
|
|
912
|
+
* Per-model LLM cost estimation.
|
|
913
|
+
*
|
|
914
|
+
* Estimate the USD cost of an LLM call from its token usage and record it as a
|
|
915
|
+
* span attribute (`gen_ai.usage.cost.usd`). Pair with the
|
|
916
|
+
* `gen_ai.client.cost.usd` metric bucket advice in `gen-ai-metrics`.
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```typescript
|
|
920
|
+
* import { trace, recordLLMCost } from 'autotel';
|
|
921
|
+
*
|
|
922
|
+
* export const chat = trace((ctx) => async (prompt: string) => {
|
|
923
|
+
* const res = await client.messages.create({ model, ... });
|
|
924
|
+
* recordLLMCost(ctx, model, {
|
|
925
|
+
* inputTokens: res.usage.input_tokens,
|
|
926
|
+
* outputTokens: res.usage.output_tokens,
|
|
927
|
+
* });
|
|
928
|
+
* return res;
|
|
929
|
+
* });
|
|
930
|
+
* ```
|
|
931
|
+
*/
|
|
932
|
+
|
|
933
|
+
/** Span attribute key autotel sets for an estimated call cost. */
|
|
934
|
+
declare const GEN_AI_COST_ATTRIBUTE = "gen_ai.usage.cost.usd";
|
|
935
|
+
/** Pricing for a single model, in USD per 1,000,000 tokens. */
|
|
936
|
+
interface ModelPricing {
|
|
937
|
+
/** USD per 1M input (prompt) tokens. */
|
|
938
|
+
inputPer1M: number;
|
|
939
|
+
/** USD per 1M output (completion) tokens. */
|
|
940
|
+
outputPer1M: number;
|
|
941
|
+
/** USD per 1M cached input tokens. Defaults to {@link ModelPricing.inputPer1M}. */
|
|
942
|
+
cachedInputPer1M?: number;
|
|
943
|
+
}
|
|
944
|
+
/** Token counts for a single LLM call. */
|
|
945
|
+
interface TokenUsage {
|
|
946
|
+
inputTokens?: number;
|
|
947
|
+
outputTokens?: number;
|
|
948
|
+
/** Cached input tokens, billed at {@link ModelPricing.cachedInputPer1M}. */
|
|
949
|
+
cachedInputTokens?: number;
|
|
950
|
+
}
|
|
951
|
+
interface EstimateCostOptions {
|
|
952
|
+
/** Override or extend {@link MODEL_PRICING}. Keys are matched first. */
|
|
953
|
+
pricing?: Record<string, ModelPricing>;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Approximate public list prices (USD per 1M tokens) at the time of writing.
|
|
957
|
+
* Prices change; treat these as convenience defaults, not a billing source of
|
|
958
|
+
* truth. Override per call via `options.pricing` or mutate this table at init.
|
|
959
|
+
* Matching is exact first, then by longest key prefix, so versioned model ids
|
|
960
|
+
* (`claude-sonnet-4-6-20251101`) resolve to a base entry (`claude-sonnet-4-6`).
|
|
961
|
+
*/
|
|
962
|
+
declare const MODEL_PRICING: Record<string, ModelPricing>;
|
|
963
|
+
/**
|
|
964
|
+
* Estimate the USD cost of an LLM call. Returns `undefined` when the model has
|
|
965
|
+
* no known pricing (supply one via `options.pricing`).
|
|
966
|
+
*/
|
|
967
|
+
declare function estimateLLMCost(model: string, usage: TokenUsage, options?: EstimateCostOptions): number | undefined;
|
|
968
|
+
/**
|
|
969
|
+
* Estimate cost and record it on `ctx` as the `gen_ai.usage.cost.usd` span
|
|
970
|
+
* attribute. Returns the estimated cost, or `undefined` when the model is
|
|
971
|
+
* unknown (in which case no attribute is set).
|
|
972
|
+
*/
|
|
973
|
+
declare function recordLLMCost(ctx: Pick<TraceContext, 'setAttribute'>, model: string, usage: TokenUsage, options?: EstimateCostOptions): number | undefined;
|
|
974
|
+
|
|
975
|
+
export { AttributeRedactorConfig, AttributeRedactorPreset, type AuditAction, type AuditCatalog, type AuditCatalogEntry, type AuditDescriptor, type AuditSeverity, BaggageSpanProcessor, type BaggageSpanProcessorOptions, type DefineEventOptions, type DefinedEvent, type DrainOptions, type EnrichContext, type EnricherDefinition, type EnricherOptions, type ErrorBuildOptions, type ErrorBuilder, type ErrorCatalog, type ErrorCatalogEntry, type EstimateCostOptions, EventAttributes, EventSubscriber, type ForkLifecycle, type ForkOptions, GEN_AI_COST_ATTRIBUTE, GEN_AI_COST_USD_BUCKETS, GEN_AI_DURATION_BUCKETS_SECONDS, GEN_AI_TOKEN_USAGE_BUCKETS, type HttpDrainOptions, type HttpDrainRequest, MODEL_PRICING, type ModelPricing, type OperationContext, type PromptSentEvent, type RequestLogSnapshot, type RequestLogger, type RequestLoggerOptions, type ResponseReceivedEvent, type RetryEvent, type SchemaLike, type StreamFirstTokenEvent, type StringRedactor, type StructuredError, type StructuredErrorInput, type TokenUsage, type ToolCallEvent, TraceContext, createStringRedactor, createStructuredError, defineAuditCatalog, defineDrain, defineEnricher, defineErrorCatalog, defineEvent, defineHttpDrain, estimateLLMCost, flattenToAttributes, flush, formatDuration, genAiMetricViews, getCatalogCode, getEventQueue, getOperationContext, getRequestLogger, getStructuredErrorAttributes, isCatalogError, llmHistogramAdvice, recordLLMCost, recordPromptSent, recordResponseReceived, recordRetry, recordStreamFirstToken, recordStructuredError, recordToolCall, runInOperationContext, runWithRequestContext, shutdown, structuredErrorToJSON, toAttributeValue, trace, track };
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
export { createDrainPipeline } from './chunk-KFOHQK7X.js';
|
|
2
|
-
export { getCurrentWorkflowContext, isInWorkflow, traceStep, traceWorkflow } from './chunk-
|
|
2
|
+
export { getCurrentWorkflowContext, isInWorkflow, traceStep, traceWorkflow } from './chunk-FZROHTZZ.js';
|
|
3
3
|
export { attrs, autoRedactPII, dbClient, httpClient, httpServer, identify, mergeAttrs, mergeServiceResource, request, safeSetAttributes, setDevice, setError, setException, setSession, setUser, validateAttribute } from './chunk-454CH4OV.js';
|
|
4
4
|
export { httpRequestHeaderAttribute, httpResponseHeaderAttribute } from './chunk-7552UTQW.js';
|
|
5
5
|
export { HTTPAttributes, ServiceAttributes, URLAttributes } from './chunk-4A53YIAX.js';
|
|
6
6
|
export { parseError } from './chunk-J7VGRIAJ.js';
|
|
7
|
-
export { traceConsumer, traceProducer } from './chunk-
|
|
7
|
+
export { traceConsumer, traceProducer } from './chunk-4TAQQZDU.js';
|
|
8
8
|
import { emitCorrelatedEvent } from './chunk-KIL5CUN6.js';
|
|
9
9
|
export { BusinessBaggage, createSafeBaggageSchema } from './chunk-4IFSYQVX.js';
|
|
10
10
|
import { resetMetrics } from './chunk-7SAWIN74.js';
|
|
11
11
|
export { Metric, getMetrics, resetMetrics } from './chunk-7SAWIN74.js';
|
|
12
12
|
import './chunk-5ZN622AO.js';
|
|
13
13
|
export { createCounter, createHistogram, createObservableGauge, createUpDownCounter, getMeter } from './chunk-TQ5UWA7S.js';
|
|
14
|
-
export { traceDB, traceHTTP, traceLLM, traceMessaging } from './chunk-
|
|
15
|
-
import { trace as trace$1 } from './chunk-
|
|
16
|
-
export { ctx, instrument, markAsImmediate, span, withBaggage, withNewContext, withTracing } from './chunk-
|
|
14
|
+
export { traceDB, traceHTTP, traceLLM, traceMessaging } from './chunk-OPCTN527.js';
|
|
15
|
+
import { trace as trace$1 } from './chunk-U4D5IBSB.js';
|
|
16
|
+
export { ctx, instrument, markAsImmediate, span, withBaggage, withNewContext, withTracing } from './chunk-U4D5IBSB.js';
|
|
17
17
|
export { createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan } from './chunk-HLZ7H3VZ.js';
|
|
18
|
-
import { resetEvents } from './chunk-
|
|
19
|
-
export { Event, getEvents, resetEvents } from './chunk-
|
|
18
|
+
import { resetEvents } from './chunk-OACAWYLR.js';
|
|
19
|
+
export { Event, getEvents, resetEvents } from './chunk-OACAWYLR.js';
|
|
20
20
|
import './chunk-LITNXTTT.js';
|
|
21
21
|
import './chunk-BZHG5IZ4.js';
|
|
22
22
|
export { getOperationContext, runInOperationContext } from './chunk-SEO6NAQT.js';
|
|
23
|
-
import { getEventQueue, resetEventQueue, track, createTraceContext, flattenToAttributes, recordStructuredError } from './chunk-
|
|
24
|
-
export { CORRELATION_ID_BAGGAGE_KEY, createStructuredError, defineBaggageSchema, flattenToAttributes, generateCorrelationId, getCorrelationId, getEventQueue, getOrCreateCorrelationId, getStructuredErrorAttributes, recordStructuredError, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage, structuredErrorToJSON, toAttributeValue, track } from './chunk-
|
|
25
|
-
import { getLogger, getSdk, _closeEmbeddedDevtools } from './chunk-
|
|
26
|
-
export { BaggageSpanProcessor, createStringRedactor, init, isLoggerLocked, lockLogger } from './chunk-
|
|
23
|
+
import { getEventQueue, resetEventQueue, track, createTraceContext, flattenToAttributes, recordStructuredError, createStructuredError } from './chunk-TGV2XF57.js';
|
|
24
|
+
export { CORRELATION_ID_BAGGAGE_KEY, createStructuredError, defineBaggageSchema, flattenToAttributes, generateCorrelationId, getCorrelationId, getEventQueue, getOrCreateCorrelationId, getStructuredErrorAttributes, recordStructuredError, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage, structuredErrorToJSON, toAttributeValue, track } from './chunk-TGV2XF57.js';
|
|
25
|
+
import { getLogger, getSdk, _closeEmbeddedDevtools } from './chunk-32AXF4MA.js';
|
|
26
|
+
export { BaggageSpanProcessor, createStringRedactor, init, isLoggerLocked, lockLogger } from './chunk-32AXF4MA.js';
|
|
27
27
|
import './chunk-643PQG3Y.js';
|
|
28
28
|
import './chunk-A4E5AQFK.js';
|
|
29
29
|
export { FilteringSpanProcessor } from './chunk-WGWSHJ2N.js';
|
|
@@ -409,6 +409,86 @@ function getRequestLogger(ctx2, options) {
|
|
|
409
409
|
};
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
// src/error-catalog.ts
|
|
413
|
+
var catalogCodeKey = /* @__PURE__ */ Symbol.for("autotel.catalog.code");
|
|
414
|
+
function readCatalogCode(error) {
|
|
415
|
+
if (error === null || typeof error !== "object") return void 0;
|
|
416
|
+
return error[catalogCodeKey];
|
|
417
|
+
}
|
|
418
|
+
function isCatalogError(error) {
|
|
419
|
+
return readCatalogCode(error) !== void 0;
|
|
420
|
+
}
|
|
421
|
+
function getCatalogCode(error) {
|
|
422
|
+
return readCatalogCode(error);
|
|
423
|
+
}
|
|
424
|
+
function defineErrorCatalog(namespace, entries) {
|
|
425
|
+
const catalog = {};
|
|
426
|
+
for (const [key, entry] of Object.entries(entries)) {
|
|
427
|
+
const code = entry.code ?? `${namespace}.${key}`;
|
|
428
|
+
const usesParams = typeof entry.message === "function" || typeof entry.why === "function";
|
|
429
|
+
const builder = ((paramsOrOptions, maybeOptions) => {
|
|
430
|
+
const params = usesParams ? paramsOrOptions : void 0;
|
|
431
|
+
const options = usesParams ? maybeOptions : paramsOrOptions;
|
|
432
|
+
const message = typeof entry.message === "function" ? entry.message(params) : entry.message;
|
|
433
|
+
const why = typeof entry.why === "function" ? entry.why(params) : entry.why;
|
|
434
|
+
const error = createStructuredError({
|
|
435
|
+
message,
|
|
436
|
+
name: entry.name ?? key,
|
|
437
|
+
code,
|
|
438
|
+
...entry.status === void 0 ? {} : { status: entry.status },
|
|
439
|
+
...why === void 0 ? {} : { why },
|
|
440
|
+
...entry.fix === void 0 ? {} : { fix: entry.fix },
|
|
441
|
+
...entry.link === void 0 ? {} : { link: entry.link },
|
|
442
|
+
...options?.cause === void 0 ? {} : { cause: options.cause },
|
|
443
|
+
...options?.details === void 0 ? {} : { details: options.details },
|
|
444
|
+
...options?.internal === void 0 ? {} : { internal: options.internal }
|
|
445
|
+
});
|
|
446
|
+
Object.defineProperty(error, catalogCodeKey, {
|
|
447
|
+
value: code,
|
|
448
|
+
enumerable: false,
|
|
449
|
+
writable: false,
|
|
450
|
+
configurable: true
|
|
451
|
+
});
|
|
452
|
+
return error;
|
|
453
|
+
});
|
|
454
|
+
Object.defineProperty(builder, "code", {
|
|
455
|
+
value: code,
|
|
456
|
+
enumerable: true
|
|
457
|
+
});
|
|
458
|
+
Object.defineProperty(builder, "match", {
|
|
459
|
+
value: (error) => readCatalogCode(error) === code,
|
|
460
|
+
enumerable: false
|
|
461
|
+
});
|
|
462
|
+
catalog[key] = builder;
|
|
463
|
+
}
|
|
464
|
+
return Object.freeze(catalog);
|
|
465
|
+
}
|
|
466
|
+
function defineAuditCatalog(namespace, entries) {
|
|
467
|
+
const catalog = {};
|
|
468
|
+
for (const [key, entry] of Object.entries(entries)) {
|
|
469
|
+
const action = entry.action ?? `${namespace}.${key}`;
|
|
470
|
+
const severity = entry.severity ?? "info";
|
|
471
|
+
const descriptor = ((params) => {
|
|
472
|
+
const message = typeof entry.message === "function" ? entry.message(params) : entry.message;
|
|
473
|
+
return Object.freeze({
|
|
474
|
+
action,
|
|
475
|
+
severity,
|
|
476
|
+
...message === void 0 ? {} : { message }
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
Object.defineProperty(descriptor, "action", {
|
|
480
|
+
value: action,
|
|
481
|
+
enumerable: true
|
|
482
|
+
});
|
|
483
|
+
Object.defineProperty(descriptor, "severity", {
|
|
484
|
+
value: severity,
|
|
485
|
+
enumerable: true
|
|
486
|
+
});
|
|
487
|
+
catalog[key] = descriptor;
|
|
488
|
+
}
|
|
489
|
+
return Object.freeze(catalog);
|
|
490
|
+
}
|
|
491
|
+
|
|
412
492
|
// src/drain-toolkit.ts
|
|
413
493
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
414
494
|
var DEFAULT_RETRIES = 2;
|
|
@@ -645,6 +725,63 @@ function buildStreamFirstTokenAttrs(event) {
|
|
|
645
725
|
return attrs2;
|
|
646
726
|
}
|
|
647
727
|
|
|
648
|
-
|
|
728
|
+
// src/gen-ai-cost.ts
|
|
729
|
+
var GEN_AI_COST_ATTRIBUTE = "gen_ai.usage.cost.usd";
|
|
730
|
+
var MODEL_PRICING = {
|
|
731
|
+
// OpenAI
|
|
732
|
+
"gpt-4o": { inputPer1M: 2.5, outputPer1M: 10 },
|
|
733
|
+
"gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6 },
|
|
734
|
+
"gpt-4.1": { inputPer1M: 2, outputPer1M: 8 },
|
|
735
|
+
"gpt-4.1-mini": { inputPer1M: 0.4, outputPer1M: 1.6 },
|
|
736
|
+
"gpt-4.1-nano": { inputPer1M: 0.1, outputPer1M: 0.4 },
|
|
737
|
+
"o3-mini": { inputPer1M: 1.1, outputPer1M: 4.4 },
|
|
738
|
+
// Anthropic Claude
|
|
739
|
+
"claude-opus-4": { inputPer1M: 15, outputPer1M: 75 },
|
|
740
|
+
"claude-sonnet-4": { inputPer1M: 3, outputPer1M: 15 },
|
|
741
|
+
"claude-3-5-sonnet": { inputPer1M: 3, outputPer1M: 15 },
|
|
742
|
+
"claude-3-5-haiku": { inputPer1M: 0.8, outputPer1M: 4 },
|
|
743
|
+
"claude-3-opus": { inputPer1M: 15, outputPer1M: 75 },
|
|
744
|
+
"claude-3-haiku": { inputPer1M: 0.25, outputPer1M: 1.25 },
|
|
745
|
+
// Google Gemini
|
|
746
|
+
"gemini-1.5-pro": { inputPer1M: 1.25, outputPer1M: 5 },
|
|
747
|
+
"gemini-1.5-flash": { inputPer1M: 0.075, outputPer1M: 0.3 },
|
|
748
|
+
"gemini-2.0-flash": { inputPer1M: 0.1, outputPer1M: 0.4 }
|
|
749
|
+
};
|
|
750
|
+
function resolvePricing(table, model) {
|
|
751
|
+
const exact = table[model];
|
|
752
|
+
if (exact) return exact;
|
|
753
|
+
let best;
|
|
754
|
+
let bestLength = 0;
|
|
755
|
+
for (const key of Object.keys(table)) {
|
|
756
|
+
if (model.startsWith(key) && key.length > bestLength) {
|
|
757
|
+
best = table[key];
|
|
758
|
+
bestLength = key.length;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return best;
|
|
762
|
+
}
|
|
763
|
+
function round(value) {
|
|
764
|
+
return Math.round(value * 1e6) / 1e6;
|
|
765
|
+
}
|
|
766
|
+
function estimateLLMCost(model, usage, options) {
|
|
767
|
+
const table = options?.pricing ? { ...MODEL_PRICING, ...options.pricing } : MODEL_PRICING;
|
|
768
|
+
const price = resolvePricing(table, model);
|
|
769
|
+
if (!price) return void 0;
|
|
770
|
+
const cachedInput = usage.cachedInputTokens ?? 0;
|
|
771
|
+
const billedInput = Math.max(0, (usage.inputTokens ?? 0) - cachedInput);
|
|
772
|
+
const output = usage.outputTokens ?? 0;
|
|
773
|
+
const cachedRate = price.cachedInputPer1M ?? price.inputPer1M;
|
|
774
|
+
const cost = billedInput / 1e6 * price.inputPer1M + cachedInput / 1e6 * cachedRate + output / 1e6 * price.outputPer1M;
|
|
775
|
+
return round(cost);
|
|
776
|
+
}
|
|
777
|
+
function recordLLMCost(ctx2, model, usage, options) {
|
|
778
|
+
const cost = estimateLLMCost(model, usage, options);
|
|
779
|
+
if (cost !== void 0) {
|
|
780
|
+
ctx2.setAttribute(GEN_AI_COST_ATTRIBUTE, cost);
|
|
781
|
+
}
|
|
782
|
+
return cost;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
export { GEN_AI_COST_ATTRIBUTE, GEN_AI_COST_USD_BUCKETS, GEN_AI_DURATION_BUCKETS_SECONDS, GEN_AI_TOKEN_USAGE_BUCKETS, MODEL_PRICING, defineAuditCatalog, defineDrain, defineEnricher, defineErrorCatalog, defineEvent, defineHttpDrain, estimateLLMCost, flush, genAiMetricViews, getCatalogCode, getRequestLogger, isCatalogError, llmHistogramAdvice, recordLLMCost, recordPromptSent, recordResponseReceived, recordRetry, recordStreamFirstToken, recordToolCall, runWithRequestContext, shutdown, trace2 as trace };
|
|
649
786
|
//# sourceMappingURL=index.js.map
|
|
650
787
|
//# sourceMappingURL=index.js.map
|