@frugalco/frugal-sdk-node 0.2.0 → 0.4.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 (55) hide show
  1. package/README.md +21 -10
  2. package/dist/config.d.ts +17 -0
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +130 -4
  5. package/dist/config.js.map +1 -1
  6. package/dist/duplicate-filter.d.ts +46 -0
  7. package/dist/duplicate-filter.d.ts.map +1 -0
  8. package/dist/duplicate-filter.js +168 -0
  9. package/dist/duplicate-filter.js.map +1 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/instrument.d.ts +36 -1
  15. package/dist/instrument.d.ts.map +1 -1
  16. package/dist/instrument.js +242 -22
  17. package/dist/instrument.js.map +1 -1
  18. package/dist/otel.d.ts +2 -0
  19. package/dist/otel.d.ts.map +1 -1
  20. package/dist/otel.js +17 -2
  21. package/dist/otel.js.map +1 -1
  22. package/dist/prompt-analyzer.d.ts +12 -1
  23. package/dist/prompt-analyzer.d.ts.map +1 -1
  24. package/dist/prompt-analyzer.js +185 -14
  25. package/dist/prompt-analyzer.js.map +1 -1
  26. package/dist/providers.d.ts +87 -0
  27. package/dist/providers.d.ts.map +1 -0
  28. package/dist/providers.js +128 -0
  29. package/dist/providers.js.map +1 -0
  30. package/dist/semconv.d.ts +12 -0
  31. package/dist/semconv.d.ts.map +1 -1
  32. package/dist/semconv.js +31 -0
  33. package/dist/semconv.js.map +1 -1
  34. package/dist/streams.d.ts.map +1 -1
  35. package/dist/streams.js +15 -2
  36. package/dist/streams.js.map +1 -1
  37. package/dist/track.d.ts +32 -4
  38. package/dist/track.d.ts.map +1 -1
  39. package/dist/track.js +2 -1
  40. package/dist/track.js.map +1 -1
  41. package/dist/wrappers/anthropic.d.ts.map +1 -1
  42. package/dist/wrappers/anthropic.js +9 -1
  43. package/dist/wrappers/anthropic.js.map +1 -1
  44. package/dist/wrappers/batch.d.ts +11 -0
  45. package/dist/wrappers/batch.d.ts.map +1 -0
  46. package/dist/wrappers/batch.js +338 -0
  47. package/dist/wrappers/batch.js.map +1 -0
  48. package/dist/wrappers/openai.d.ts.map +1 -1
  49. package/dist/wrappers/openai.js +37 -30
  50. package/dist/wrappers/openai.js.map +1 -1
  51. package/dist/wrappers/patching.d.ts +10 -0
  52. package/dist/wrappers/patching.d.ts.map +1 -0
  53. package/dist/wrappers/patching.js +38 -0
  54. package/dist/wrappers/patching.js.map +1 -0
  55. package/package.json +1 -1
package/README.md CHANGED
@@ -54,10 +54,17 @@ Set both or the wrapper silently returns the client unmodified:
54
54
  | `FRUGAL_OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector URL for Frugal metrics. Defaults to `https://metrics.frugal.co/opentelemetry/v1/metrics`. Falls back to `OTEL_EXPORTER_OTLP_ENDPOINT`. |
55
55
  | `FRUGAL_OTEL_EXPORTER_OTLP_HEADERS` | Export auth headers (e.g. `Authorization=Bearer ...`). Overrides the header built from `FRUGAL_API_KEY`. Falls back to `OTEL_EXPORTER_OTLP_HEADERS`. |
56
56
  | `FRUGAL_COMPONENTS` | Comma-separated logical components (e.g. `ai-handler,reco`). When set, each metric is ALSO emitted once per component (tagged `frugal.component`) on top of the base project series, so usage can be viewed for the whole project or split by component. |
57
+ | `FRUGAL_CUSTOM_PROVIDERS` | Comma-separated allowlist of provider names beyond the built-in registry (e.g. `together_ai,fireworks`) that should pass through verbatim on `gen_ai.system` / `gen_ai.provider.name` instead of being coerced to `custom`. Capped at 10 (extras are coerced) to keep label cardinality bounded. |
58
+ | `FRUGAL_CUSTOM_LABEL` | Comma-separated allowlist for the `frugal.custom_label` label on manual track calls (e.g. `billing,search,recs`). A `customLabel` passed to `trackAICall`/`startAICall` outside the first 20 entries (a hard, non-configurable cap) is coerced to `other` with a warn-once diagnostic. `other` is reserved and ignored as an entry. See [Custom call sites](#custom-call-sites). |
57
59
  | `FRUGAL_PATH_BLOCK_LIST` | Comma-separated repo-relative paths to skip for caller attribution (see below). |
58
60
  | `FRUGAL_METRIC_EXPORT_INTERVAL_MS` | Export cadence in milliseconds. Default `60000`. |
59
61
  | `FRUGAL_MAX_CALL_SITES` | Cardinality cap — max distinct `(caller_file, caller_function)` pairs to attribute. Default `500`. Set to `0` to disable. |
60
62
  | `FRUGAL_PROMPT_ANALYSIS_SAMPLE_RATE` | Fraction of calls (0..1) that run the lightweight prompt analyzer. Default `0.1`. Set to `0` to disable, `1` for every call. |
63
+ | `FRUGAL_DUPLICATE_REQUEST_DETECTION` | Duplicate-request detection (default **on**): every chat request is canonicalized and hashed in-process to classify `first_seen`/`repeat_seen` — only the 2-value state is exported, never content. Set to `0`/`false`/`no`/`off` to disable the hashing and the `frugal.gen_ai.duplicate_requests` metric entirely. |
64
+ | `FRUGAL_DUPLICATE_WINDOW_SECONDS` | How long a request signature is remembered. Default `3600`, max `86400` (retention is 30–60 min at defaults — see [docs/metrics-reference.md](docs/metrics-reference.md)). |
65
+ | `FRUGAL_DUPLICATE_CAPACITY` | Expected distinct requests per window (Bloom filter sizing). Default `10000`, max `1000000`. Raise if the saturation warning fires. |
66
+ | `FRUGAL_DUPLICATE_FP_RATE` | Target false-positive rate for the duplicate filter. Default `0.01`, max `0.5`. |
67
+ | `FRUGAL_DUPLICATE_GENERATIONS` | Rotating-Bloom generation count. Default `2`, max `16`. |
61
68
  | `FRUGAL_DISABLED` | Set to `1` to disable all instrumentation without uninstalling. |
62
69
 
63
70
  ## What gets captured
@@ -67,32 +74,36 @@ Every wrapped call emits OTel metrics tagged with the caller's source file and f
67
74
  | Metric | Kind | Description | Additional attributes |
68
75
  | --------------------------------------- | --------- | ------------------------------------------------------------ | -------------------------------------- |
69
76
  | `gen_ai.client.operation.duration` | histogram | Call latency in seconds | — |
70
- | `gen_ai.client.token.usage` | histogram | Input and output token counts | `gen_ai.token.type` |
71
- | `frugal.gen_ai.calls` | counter | Number of calls per site | — |
77
+ | `gen_ai.client.token.usage` | histogram | Input and output token counts | `gen_ai.token.type`, `frugal.history_bucket` (chat calls) |
78
+ | `frugal.gen_ai.calls` | counter | Number of calls per site | `frugal.history_bucket` (chat calls), `frugal.structured_output_mode` (calls with a request payload) |
72
79
  | `frugal.gen_ai.cache_read_tokens` | histogram | Prompt cache hits | — |
73
80
  | `frugal.gen_ai.cache_write_tokens` | histogram | Prompt cache writes | — |
74
81
  | `frugal.gen_ai.reasoning_tokens` | histogram | OpenAI reasoning tokens (o-series), Anthropic thinking tokens| — |
75
82
  | `frugal.gen_ai.errors` | counter | Errors by exception type | `frugal.error.type` |
76
83
  | `frugal.gen_ai.internal_errors` | counter | frugal-metrics internal failures (cardinality cap, bugs) | `frugal.internal_error.stage` |
77
84
  | `frugal.gen_ai.output_cap_utilization` | histogram | `output_tokens / max_tokens` ratio when `max_tokens` is set | `frugal.structured_output_mode` |
78
- | `frugal.gen_ai.history_depth` | histogram | `messages.length` (analyzer-sampled) | — |
85
+ | `frugal.gen_ai.history_depth` | histogram | `messages.length` — every chat call, success or error (100%, not sampled) | — |
86
+ | `frugal.gen_ai.duplicate_requests` | counter | Request-duplication state from a windowed signature filter — every chat call (100%, not sampled; see `FRUGAL_DUPLICATE_*` vars) | `frugal.dup_state` (`first_seen` \| `repeat_seen`) |
79
87
  | `frugal.gen_ai.few_shot_count` | histogram | Few-shot exemplar pairs before final user (analyzer-sampled) | — |
88
+ | `frugal.gen_ai.few_shot_tokens` | histogram | Approx. token size of the few-shot example block (analyzer-sampled) | — |
80
89
  | `frugal.gen_ai.noise_ratio` | histogram | HTML/base64/whitespace fraction of input (analyzer-sampled) | — |
81
90
  | `frugal.gen_ai.cache_prefix_stable` | counter | Per-block prompt-cache stability (analyzer-sampled) | `frugal.block`, `frugal.stable` |
82
91
  | `frugal.gen_ai.structured_output_hint` | counter | "Return JSON" prompts missing `response_format`/`tools` | — |
83
92
 
84
- The bottom block of analyzer-sampled metrics fires on a fraction of calls
85
- (`FRUGAL_PROMPT_ANALYSIS_SAMPLE_RATE`, default 10%); the token-side metrics are
86
- 100% — never sampled.
93
+ The analyzer-sampled metrics fire on a fraction of calls
94
+ (`FRUGAL_PROMPT_ANALYSIS_SAMPLE_RATE`, default 10%). Everything else —
95
+ including `history_depth`, the `frugal.history_bucket` label on `calls` and
96
+ `token.usage`, the `frugal.structured_output_mode` label on `calls`, and
97
+ `duplicate_requests` — is 100%, never sampled.
87
98
 
88
99
  Every metric carries this base attribute set:
89
100
 
90
101
  - `frugal.project_id` — from your env vars (`frugal.customer_id` too when set); `frugal.component` is added on the per-component series when `FRUGAL_COMPONENTS` is set
91
102
  - `frugal.caller_file`, `frugal.caller_function` — auto-detected from the call stack
92
- - `gen_ai.system` — `openai`, `anthropic`, `aws.bedrock`, `vertex_ai`, or `custom` (the default for hand-instrumented call sites; override via the `provider` field)
103
+ - `gen_ai.system` + `gen_ai.provider.name` — the provider, dual-emitted under both the legacy and current OTel attribute (`openai`, `anthropic`, `aws.bedrock`, `vertex_ai`/`gcp.vertex_ai`, …, or `custom`). Override via the `provider` field; an unrecognized value is coerced to `custom` with a one-time warning. See [`docs/metrics-reference.md`](docs/metrics-reference.md#attributes).
93
104
  - `gen_ai.request.model`, `gen_ai.response.model` — the model used
94
- - `gen_ai.operation.name` — `chat`, `text_completion`, or `embeddings`
95
- - `frugal.batched` — `true` for batch-API submissions, `false` otherwise
105
+ - `gen_ai.operation.name` — `chat`, `text_completion`, `embeddings`, `generate_content`, `execute_tool`, `create_agent`, `invoke_agent`, or `other` (the sentinel an unrecognized operation coerces to)
106
+ - `frugal.batched` — `true` for batch-API paths (OpenAI Batch API submissions; Anthropic Message Batches submissions and results), `false` otherwise
96
107
 
97
108
  The "Additional attributes" column above lists what each metric carries on top of the base set. See [`docs/metrics-reference.md`](docs/metrics-reference.md) for the values each attribute takes, sentinel values for caller fields, and the full internal-error-stage list.
98
109
 
@@ -160,7 +171,7 @@ try {
160
171
 
161
172
  `end()` and `fail()` finalize the call exactly once and are idempotent — extra calls are ignored, so a `try/finally` that always calls `end()` won't double-count.
162
173
 
163
- **Metadata** — `info` (all optional): `provider` (→ `gen_ai.system`, default `"custom"`), `operation` (default `"chat"`), `model` (→ `gen_ai.request.model`, default `"<unknown>"`). To also run the sampled prompt analyzer, pass any of `messages` / `system` / `tools` / `responseFormat` / `maxTokens`.
174
+ **Metadata** — `info` (all optional): `provider` (→ `gen_ai.system`, default `"custom"`), `operation` (default `"chat"`), `model` (→ `gen_ai.request.model`, default `"<unknown>"`), `customLabel` (→ `frugal.custom_label` on **every** metric of the call; the value must be one of the first 20 comma-separated entries of `FRUGAL_CUSTOM_LABEL` or it is coerced to `"other"` — the label is exclusive to this manual API, wrapper calls never carry it). To also run the sampled prompt analyzer, pass any of `messages` / `system` / `tools` / `responseFormat` / `maxTokens`.
164
175
 
165
176
  **Usage** — `report(...)` / `end(...)` fields (all optional): `inputTokens`, `outputTokens`, `cacheReadTokens`, `cacheWriteTokens`, `reasoningTokens`, `responseModel`.
166
177
 
package/dist/config.d.ts CHANGED
@@ -5,6 +5,18 @@ export interface Config {
5
5
  projectId: string;
6
6
  /** Optional logical components this deployment serves; metrics fan out one extra series per entry. */
7
7
  components: readonly string[];
8
+ /**
9
+ * Customer-registered provider names (beyond the built-in OTel registry) that
10
+ * should pass through verbatim instead of being coerced to `custom`. Capped to
11
+ * keep `gen_ai.system` / `gen_ai.provider.name` cardinality bounded.
12
+ */
13
+ customProviders: readonly string[];
14
+ /**
15
+ * Allowlist for the `frugal.custom_label` label on manual track calls. A
16
+ * `customLabel` value outside this list is coerced to `other` at emit time,
17
+ * so the label's cardinality is bounded by MAX_CUSTOM_LABELS + 1.
18
+ */
19
+ customLabels: readonly string[];
8
20
  repoRoot: string;
9
21
  pathBlockList: readonly string[];
10
22
  otlpEndpoint: string;
@@ -14,6 +26,11 @@ export interface Config {
14
26
  maxCallSites: number;
15
27
  /** Fraction of analyzed calls to emit prompt-analysis metrics for, 0..1. */
16
28
  promptAnalysisSampleRate: number;
29
+ duplicateDetection: boolean;
30
+ duplicateWindowSeconds: number;
31
+ duplicateCapacity: number;
32
+ duplicateFpRate: number;
33
+ duplicateGenerations: number;
17
34
  }
18
35
  export declare function loadConfig(): Config | null;
19
36
  /** Test-only hook to re-arm the one-shot warning. */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,MAAM;IACrB,mGAAmG;IACnG,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,YAAY,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,wBAAwB,EAAE,MAAM,CAAC;CAClC;AA0CD,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAsH1C;AAED,qDAAqD;AACrD,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAmCA,MAAM,WAAW,MAAM;IACrB,mGAAmG;IACnG,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B;;;;OAIG;IACH,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC;;;;OAIG;IACH,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,YAAY,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,wBAAwB,EAAE,MAAM,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAqHD,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CA+O1C;AAED,qDAAqD;AACrD,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD"}
package/dist/config.js CHANGED
@@ -28,7 +28,8 @@
28
28
  // the defaults so existing customers don't need to change anything.
29
29
  import { realpathSync } from "node:fs";
30
30
  import { resolve } from "node:path";
31
- import { emitLog } from "./debug.js";
31
+ import { emitLog, emitLogOnce } from "./debug.js";
32
+ import { CUSTOM_LABEL_OTHER } from "./semconv.js";
32
33
  const ENV = {
33
34
  CUSTOMER_ID: "FRUGAL_CUSTOMER_ID",
34
35
  PROJECT_ID: "FRUGAL_PROJECT_ID",
@@ -38,6 +39,8 @@ const ENV = {
38
39
  METRICS_PROJECT_ID: "FRUGAL_METRICS_PROJECT_ID",
39
40
  METRICS_API_KEY: "FRUGAL_METRICS_API_KEY",
40
41
  COMPONENTS: "FRUGAL_COMPONENTS",
42
+ CUSTOM_PROVIDERS: "FRUGAL_CUSTOM_PROVIDERS",
43
+ CUSTOM_LABEL: "FRUGAL_CUSTOM_LABEL",
41
44
  REPO_ROOT: "FRUGAL_REPO_ROOT",
42
45
  PATH_BLOCK_LIST: "FRUGAL_PATH_BLOCK_LIST",
43
46
  DISABLED: "FRUGAL_DISABLED",
@@ -49,10 +52,43 @@ const ENV = {
49
52
  EXPORT_INTERVAL_MS: "FRUGAL_METRIC_EXPORT_INTERVAL_MS",
50
53
  MAX_CALL_SITES: "FRUGAL_MAX_CALL_SITES",
51
54
  PROMPT_ANALYSIS_SAMPLE_RATE: "FRUGAL_PROMPT_ANALYSIS_SAMPLE_RATE",
55
+ DUPLICATE_DETECTION: "FRUGAL_DUPLICATE_REQUEST_DETECTION",
56
+ DUPLICATE_WINDOW_SECONDS: "FRUGAL_DUPLICATE_WINDOW_SECONDS",
57
+ DUPLICATE_CAPACITY: "FRUGAL_DUPLICATE_CAPACITY",
58
+ DUPLICATE_FP_RATE: "FRUGAL_DUPLICATE_FP_RATE",
59
+ DUPLICATE_GENERATIONS: "FRUGAL_DUPLICATE_GENERATIONS",
52
60
  };
53
61
  const DEFAULT_OTLP_ENDPOINT = "https://metrics.frugal.co/opentelemetry/v1/metrics";
54
62
  const DEFAULT_MAX_CALL_SITES = 500;
55
63
  const DEFAULT_PROMPT_ANALYSIS_SAMPLE_RATE = 0.1;
64
+ const DEFAULT_DUPLICATE_WINDOW_SECONDS = 3600;
65
+ const DEFAULT_DUPLICATE_CAPACITY = 10_000;
66
+ const DEFAULT_DUPLICATE_FP_RATE = 0.01;
67
+ const DEFAULT_DUPLICATE_GENERATIONS = 2;
68
+ // Bloom memory is ~(1.44·log2(1/p))/8 bytes × capacity × generations — the fp
69
+ // rate matters: ~1.2 B/entry at the 0.01 default (≈24 KB total at defaults)
70
+ // but ~3.6 B/entry at the 1e-6 floor the filter clamps to. The caps below
71
+ // bound the worst case to ≈58 MB (capacity 1e6 × 16 generations × 3.6 B),
72
+ // allocated inside the customer's first call — large, but a knowable ceiling
73
+ // rather than a fat-fingered env var demanding gigabytes. Saturation checks
74
+ // popcount the full allocation every 1024th insert, so the ceiling also bounds
75
+ // that hot-path cost.
76
+ const MAX_DUPLICATE_CAPACITY = 1_000_000;
77
+ const MAX_DUPLICATE_GENERATIONS = 16;
78
+ // Above the documented window there is no additional duplicate signal — only a
79
+ // filter that effectively never rotates and saturates for the process
80
+ // lifetime. One day is already far beyond any retry/cache horizon.
81
+ const MAX_DUPLICATE_WINDOW_SECONDS = 86_400;
82
+ // bloomParams clamps fp to at most 0.5 (the mathematical ceiling where the
83
+ // filter degenerates); values in [0.5, 1) must warn HERE, not silently differ
84
+ // from what the filter actually uses.
85
+ const MAX_DUPLICATE_FP_RATE = 0.5;
86
+ /** Upper bound on customer-registered provider names — keeps label cardinality bounded. */
87
+ const MAX_CUSTOM_PROVIDERS = 10;
88
+ // Hard bound on the frugal.custom_label allowlist. Deliberately a
89
+ // module-private literal with no env override: the cap is the cardinality
90
+ // contract for the label, so it must not be user-tunable.
91
+ const MAX_CUSTOM_LABELS = 20;
56
92
  let warnedOnce = false;
57
93
  function truthy(value) {
58
94
  if (!value)
@@ -60,6 +96,32 @@ function truthy(value) {
60
96
  const v = value.trim().toLowerCase();
61
97
  return v === "1" || v === "true" || v === "yes" || v === "on";
62
98
  }
99
+ function explicitlyOff(value) {
100
+ if (value === undefined)
101
+ return false;
102
+ const v = value.trim().toLowerCase();
103
+ return v === "0" || v === "false" || v === "no" || v === "off";
104
+ }
105
+ // Number(raw) validates the FULL string (unlike parseInt/parseFloat, whose
106
+ // prefix parsing turns "1e6" into 1 and "10,000" into 10 — a capacity of 1
107
+ // means a 10-bit filter that saturates instantly). Warnings are de-duped per
108
+ // var: loadConfig() runs on every call, so a bad value must not flood the
109
+ // bounded debug ring buffer.
110
+ function parsePositive(raw, name, fallback, { integer = false, max } = {}) {
111
+ if (!raw || !raw.trim())
112
+ return fallback;
113
+ const parsed = Number(raw.trim());
114
+ const valid = Number.isFinite(parsed) && parsed > 0 && (!integer || Number.isInteger(parsed));
115
+ if (!valid) {
116
+ emitLogOnce(`bad_env_${name}`, "warn", `could not parse ${name}=${raw}; using default ${fallback}`);
117
+ return fallback;
118
+ }
119
+ if (max !== undefined && parsed > max) {
120
+ emitLogOnce(`clamped_env_${name}`, "warn", `${name}=${raw} exceeds the maximum ${max}; clamping to ${max}`);
121
+ return max;
122
+ }
123
+ return parsed;
124
+ }
63
125
  function warnOnce(message) {
64
126
  if (warnedOnce)
65
127
  return;
@@ -120,6 +182,43 @@ export function loadConfig() {
120
182
  .split(",")
121
183
  .map((e) => e.trim())
122
184
  .filter((e) => e.length > 0);
185
+ // Optional comma-separated allowlist of custom provider names that pass through
186
+ // verbatim (e.g. "together_ai,fireworks"). Deduped and capped at
187
+ // MAX_CUSTOM_PROVIDERS so a misconfigured value can't blow up label cardinality.
188
+ const customProvidersRaw = process.env[ENV.CUSTOM_PROVIDERS] ?? "";
189
+ const customProvidersAll = [
190
+ ...new Set(customProvidersRaw
191
+ .split(",")
192
+ .map((e) => e.trim())
193
+ .filter((e) => e.length > 0)),
194
+ ];
195
+ const customProviders = customProvidersAll.slice(0, MAX_CUSTOM_PROVIDERS);
196
+ if (customProvidersAll.length > MAX_CUSTOM_PROVIDERS) {
197
+ emitLogOnce("custom_providers_truncated", "warn", `${ENV.CUSTOM_PROVIDERS} lists ${customProvidersAll.length} entries; only the first ${MAX_CUSTOM_PROVIDERS} are honored, the rest are coerced to "custom".`);
198
+ }
199
+ // Optional comma-separated allowlist for the frugal.custom_label attribute on
200
+ // manual track calls. Only the first MAX_CUSTOM_LABELS comma-separated
201
+ // entries are honored (sliced BEFORE trim/dedupe — the position in the raw
202
+ // list is the contract); customLabel values outside the allowlist are
203
+ // coerced to "other" at emit time.
204
+ const customLabelsRaw = process.env[ENV.CUSTOM_LABEL] ?? "";
205
+ const customLabelEntries = customLabelsRaw.split(",");
206
+ const customLabelsParsed = [
207
+ ...new Set(customLabelEntries
208
+ .slice(0, MAX_CUSTOM_LABELS)
209
+ .map((e) => e.trim())
210
+ .filter((e) => e.length > 0)),
211
+ ];
212
+ // "other" is the coercion sentinel, never a legitimate allowlist entry: a
213
+ // real unit named "other" would inseparably absorb every non-allowlisted
214
+ // value from unrelated call sites.
215
+ const customLabels = customLabelsParsed.filter((e) => e !== CUSTOM_LABEL_OTHER);
216
+ if (customLabels.length < customLabelsParsed.length) {
217
+ emitLogOnce("custom_labels_reserved", "warn", `${ENV.CUSTOM_LABEL} contains the reserved value "${CUSTOM_LABEL_OTHER}" (the coercion sentinel); it is ignored — rename that label to keep it distinguishable from coerced values.`);
218
+ }
219
+ if (customLabelEntries.length > MAX_CUSTOM_LABELS && customLabelsRaw.trim()) {
220
+ emitLogOnce("custom_labels_truncated", "warn", `${ENV.CUSTOM_LABEL} lists ${customLabelEntries.length} entries; only the first ${MAX_CUSTOM_LABELS} are honored, values outside them are coerced to "${CUSTOM_LABEL_OTHER}".`);
221
+ }
123
222
  const otlpEndpoint = process.env[ENV.FRUGAL_OTLP_ENDPOINT] ??
124
223
  process.env[ENV.OTLP_ENDPOINT] ??
125
224
  DEFAULT_OTLP_ENDPOINT;
@@ -131,7 +230,7 @@ export function loadConfig() {
131
230
  exportIntervalMs = parsed;
132
231
  }
133
232
  else {
134
- emitLog("warn", `could not parse ${ENV.EXPORT_INTERVAL_MS}=${intervalRaw}; using default ${exportIntervalMs}`);
233
+ emitLogOnce(`bad_env_${ENV.EXPORT_INTERVAL_MS}`, "warn", `could not parse ${ENV.EXPORT_INTERVAL_MS}=${intervalRaw}; using default ${exportIntervalMs}`);
135
234
  }
136
235
  }
137
236
  const maxCallSitesRaw = process.env[ENV.MAX_CALL_SITES];
@@ -142,7 +241,7 @@ export function loadConfig() {
142
241
  maxCallSites = parsed;
143
242
  }
144
243
  else {
145
- emitLog("warn", `could not parse ${ENV.MAX_CALL_SITES}=${maxCallSitesRaw}; using default ${maxCallSites}`);
244
+ emitLogOnce(`bad_env_${ENV.MAX_CALL_SITES}`, "warn", `could not parse ${ENV.MAX_CALL_SITES}=${maxCallSitesRaw}; using default ${maxCallSites}`);
146
245
  }
147
246
  }
148
247
  const sampleRateRaw = process.env[ENV.PROMPT_ANALYSIS_SAMPLE_RATE];
@@ -153,13 +252,35 @@ export function loadConfig() {
153
252
  promptAnalysisSampleRate = parsed;
154
253
  }
155
254
  else {
156
- emitLog("warn", `could not parse ${ENV.PROMPT_ANALYSIS_SAMPLE_RATE}=${sampleRateRaw}; using default ${promptAnalysisSampleRate}`);
255
+ emitLogOnce(`bad_env_${ENV.PROMPT_ANALYSIS_SAMPLE_RATE}`, "warn", `could not parse ${ENV.PROMPT_ANALYSIS_SAMPLE_RATE}=${sampleRateRaw}; using default ${promptAnalysisSampleRate}`);
157
256
  }
158
257
  }
258
+ const fpRate = parsePositive(process.env[ENV.DUPLICATE_FP_RATE], ENV.DUPLICATE_FP_RATE, DEFAULT_DUPLICATE_FP_RATE);
259
+ let duplicateFpRate = fpRate;
260
+ if (fpRate >= 1) {
261
+ emitLogOnce(`bad_range_${ENV.DUPLICATE_FP_RATE}`, "warn", `${ENV.DUPLICATE_FP_RATE}=${fpRate} must be in (0, 1); using default ${DEFAULT_DUPLICATE_FP_RATE}`);
262
+ duplicateFpRate = DEFAULT_DUPLICATE_FP_RATE;
263
+ }
264
+ else if (fpRate > MAX_DUPLICATE_FP_RATE) {
265
+ emitLogOnce(`clamped_env_${ENV.DUPLICATE_FP_RATE}`, "warn", `${ENV.DUPLICATE_FP_RATE}=${fpRate} exceeds the maximum ${MAX_DUPLICATE_FP_RATE}; clamping to ${MAX_DUPLICATE_FP_RATE}`);
266
+ duplicateFpRate = MAX_DUPLICATE_FP_RATE;
267
+ }
268
+ // The kill switch disables only on an explicit off value. Operators reach
269
+ // for this knob on privacy/overhead grounds, so a value we don't recognize
270
+ // ("disabled", "n", …) must not silently leave full-payload hashing on.
271
+ const dupDetectionRaw = process.env[ENV.DUPLICATE_DETECTION];
272
+ if (dupDetectionRaw !== undefined &&
273
+ dupDetectionRaw.trim() !== "" &&
274
+ !explicitlyOff(dupDetectionRaw) &&
275
+ !truthy(dupDetectionRaw)) {
276
+ emitLogOnce(`bad_env_${ENV.DUPLICATE_DETECTION}`, "warn", `unrecognized ${ENV.DUPLICATE_DETECTION}=${dupDetectionRaw}; duplicate detection remains ENABLED. Use 0/false/no/off to disable.`);
277
+ }
159
278
  return {
160
279
  customerId,
161
280
  projectId: projectId,
162
281
  components,
282
+ customProviders,
283
+ customLabels,
163
284
  repoRoot: repoRootAbs,
164
285
  pathBlockList,
165
286
  otlpEndpoint,
@@ -167,6 +288,11 @@ export function loadConfig() {
167
288
  exportIntervalMs,
168
289
  maxCallSites,
169
290
  promptAnalysisSampleRate,
291
+ duplicateDetection: !explicitlyOff(process.env[ENV.DUPLICATE_DETECTION]),
292
+ duplicateWindowSeconds: parsePositive(process.env[ENV.DUPLICATE_WINDOW_SECONDS], ENV.DUPLICATE_WINDOW_SECONDS, DEFAULT_DUPLICATE_WINDOW_SECONDS, { max: MAX_DUPLICATE_WINDOW_SECONDS }),
293
+ duplicateCapacity: parsePositive(process.env[ENV.DUPLICATE_CAPACITY], ENV.DUPLICATE_CAPACITY, DEFAULT_DUPLICATE_CAPACITY, { integer: true, max: MAX_DUPLICATE_CAPACITY }),
294
+ duplicateFpRate,
295
+ duplicateGenerations: parsePositive(process.env[ENV.DUPLICATE_GENERATIONS], ENV.DUPLICATE_GENERATIONS, DEFAULT_DUPLICATE_GENERATIONS, { integer: true, max: MAX_DUPLICATE_GENERATIONS }),
170
296
  };
171
297
  }
172
298
  /** Test-only hook to re-arm the one-shot warning. */
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,+CAA+C;AAC/C,EAAE;AACF,qDAAqD;AACrD,mFAAmF;AACnF,kFAAkF;AAClF,kFAAkF;AAClF,kFAAkF;AAClF,gFAAgF;AAChF,EAAE;AACF,yCAAyC;AACzC,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAC3E,6EAA6E;AAC7E,8DAA8D;AAC9D,+EAA+E;AAC/E,6EAA6E;AAC7E,iFAAiF;AACjF,6EAA6E;AAC7E,EAAE;AACF,0DAA0D;AAC1D,2EAA2E;AAC3E,yEAAyE;AACzE,oEAAoE;AAEpE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ACnC,GAAG,CAAC,kBAAkB,EACtB,0BAA0B,EAC1B,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,EAAE,CAC/C;QACD,eAAe;QACf,oBAAoB,EAAE,aAAa,CACjC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,qBAAqB,CAAC,EACtC,GAAG,CAAC,qBAAqB,EACzB,6BAA6B,EAC7B,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,yBAAyB,EAAE,CAClD;KACF,CAAC;AACJ,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,yBAAyB;IACvC,UAAU,GAAG,KAAK,CAAC;AACrB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { Config } from "./config.js";
2
+ import { DUP_FIRST_SEEN, DUP_REPEAT_SEEN } from "./semconv.js";
3
+ export type DupState = typeof DUP_FIRST_SEEN | typeof DUP_REPEAT_SEEN;
4
+ export declare class RotatingBloomFilter {
5
+ private readonly m;
6
+ private readonly k;
7
+ private readonly generations;
8
+ private readonly rotateMs;
9
+ private readonly bytesPerGen;
10
+ private bits;
11
+ private activeIndex;
12
+ private genStartMs;
13
+ private disabled;
14
+ private insertsSinceCheck;
15
+ private saturationWarned;
16
+ constructor(opts: {
17
+ capacity: number;
18
+ fpRate: number;
19
+ generations: number;
20
+ windowSeconds: number;
21
+ });
22
+ /**
23
+ * Classify a signature and insert it. Returns null when the filter is
24
+ * disabled (bit-array allocation failed — latched for the process lifetime
25
+ * so the allocation is not retried on every call).
26
+ *
27
+ * The clock defaults to performance.now() (monotonic): rotation must not
28
+ * freeze when NTP steps the wall clock backward.
29
+ */
30
+ seenBefore(signature: string, nowMs?: number): DupState | null;
31
+ clear(): void;
32
+ /**
33
+ * Warn (once per fill, re-armed by clear()) when the filter is saturating.
34
+ * Membership tests the UNION of all generations, so occupancy is measured on
35
+ * the union too — measuring only the active generation would let two
36
+ * generations at 49% (union ~74%) pass silently. Past ~50% union fill the
37
+ * effective false-positive rate is far above the configured target and the
38
+ * metric drifts toward all-repeat_seen.
39
+ */
40
+ private maybeWarnSaturation;
41
+ private rotate;
42
+ private positions;
43
+ }
44
+ export declare function getSharedDuplicateFilter(config: Config): RotatingBloomFilter | null;
45
+ export declare function resetSharedDuplicateFilterForTests(): void;
46
+ //# sourceMappingURL=duplicate-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate-filter.d.ts","sourceRoot":"","sources":["../src/duplicate-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D,MAAM,MAAM,QAAQ,GAAG,OAAO,cAAc,GAAG,OAAO,eAAe,CAAC;AAyBtE,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,gBAAgB,CAAS;gBAErB,IAAI,EAAE;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;KACvB;IASD;;;;;;;OAOG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,MAA0B,GAAG,QAAQ,GAAG,IAAI;IAwDjF,KAAK,IAAI,IAAI;IAQb;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,MAAM;IAYd,OAAO,CAAC,SAAS;CASlB;AAID,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAWnF;AAED,wBAAgB,kCAAkC,IAAI,IAAI,CAEzD"}
@@ -0,0 +1,168 @@
1
+ import { emitLog, emitLogOnce } from "./debug.js";
2
+ import { DUP_FIRST_SEEN, DUP_REPEAT_SEEN } from "./semconv.js";
3
+ function bloomParams(capacity, fpRate) {
4
+ const N = Math.max(1, Math.floor(capacity));
5
+ const p = Math.min(Math.max(fpRate, 1e-6), 0.5);
6
+ const ln2 = Math.LN2;
7
+ const m = Math.max(8, Math.ceil((-N * Math.log(p)) / (ln2 * ln2)));
8
+ const k = Math.max(1, Math.round((m / N) * ln2));
9
+ return { m, k };
10
+ }
11
+ // How often (in insertions) to measure occupancy for the saturation warning.
12
+ // Counting set bits is O(m/8) bytes, so amortizing over 1024 inserts keeps the
13
+ // check negligible even at the capacity clamp.
14
+ const SATURATION_CHECK_INTERVAL = 1024;
15
+ // Union occupancy at which the false-positive rate is degraded badly enough to
16
+ // warn: at 50% fill the FP rate is ~(0.5)^k, orders of magnitude above the
17
+ // configured target, and rising fast.
18
+ const SATURATION_FILL_THRESHOLD = 0.5;
19
+ const POPCOUNT = new Uint8Array(256);
20
+ for (let i = 0; i < 256; i++) {
21
+ POPCOUNT[i] = (i & 1) + POPCOUNT[i >> 1];
22
+ }
23
+ export class RotatingBloomFilter {
24
+ m;
25
+ k;
26
+ generations;
27
+ rotateMs;
28
+ bytesPerGen;
29
+ bits = null;
30
+ activeIndex = 0;
31
+ genStartMs = 0;
32
+ disabled = false;
33
+ insertsSinceCheck = 0;
34
+ saturationWarned = false;
35
+ constructor(opts) {
36
+ const { m, k } = bloomParams(opts.capacity, opts.fpRate);
37
+ this.m = m;
38
+ this.k = k;
39
+ this.generations = Math.max(1, Math.floor(opts.generations));
40
+ this.rotateMs = Math.max(1, (opts.windowSeconds * 1000) / this.generations);
41
+ this.bytesPerGen = Math.ceil(m / 8);
42
+ }
43
+ /**
44
+ * Classify a signature and insert it. Returns null when the filter is
45
+ * disabled (bit-array allocation failed — latched for the process lifetime
46
+ * so the allocation is not retried on every call).
47
+ *
48
+ * The clock defaults to performance.now() (monotonic): rotation must not
49
+ * freeze when NTP steps the wall clock backward.
50
+ */
51
+ seenBefore(signature, nowMs = performance.now()) {
52
+ if (this.disabled)
53
+ return null;
54
+ if (this.bits === null) {
55
+ try {
56
+ this.bits = Array.from({ length: this.generations }, () => new Uint8Array(this.bytesPerGen));
57
+ }
58
+ catch (err) {
59
+ this.disabled = true;
60
+ emitLogOnce("duplicate_filter_alloc_failed", "error", `duplicate filter allocation failed (${this.generations} × ${this.bytesPerGen} bytes); duplicate detection disabled for this process. Lower FRUGAL_DUPLICATE_CAPACITY / FRUGAL_DUPLICATE_GENERATIONS.`);
61
+ // Rethrow once so the caller records a single internal_errors point;
62
+ // every later call short-circuits on the latch above.
63
+ throw err;
64
+ }
65
+ this.genStartMs = nowMs;
66
+ }
67
+ this.rotate(nowMs);
68
+ const positions = this.positions(signature);
69
+ const bits = this.bits;
70
+ let present = true;
71
+ for (const pos of positions) {
72
+ const byte = pos >> 3;
73
+ const mask = 1 << (pos & 7);
74
+ let anySet = false;
75
+ for (let g = 0; g < this.generations; g++) {
76
+ if ((bits[g][byte] & mask) !== 0) {
77
+ anySet = true;
78
+ break;
79
+ }
80
+ }
81
+ if (!anySet) {
82
+ present = false;
83
+ break;
84
+ }
85
+ }
86
+ const active = bits[this.activeIndex];
87
+ for (const pos of positions) {
88
+ active[pos >> 3] |= 1 << (pos & 7);
89
+ }
90
+ if (++this.insertsSinceCheck >= SATURATION_CHECK_INTERVAL) {
91
+ this.insertsSinceCheck = 0;
92
+ this.maybeWarnSaturation();
93
+ }
94
+ return present ? DUP_REPEAT_SEEN : DUP_FIRST_SEEN;
95
+ }
96
+ clear() {
97
+ this.bits = null;
98
+ this.activeIndex = 0;
99
+ this.genStartMs = 0;
100
+ this.insertsSinceCheck = 0;
101
+ this.saturationWarned = false;
102
+ }
103
+ /**
104
+ * Warn (once per fill, re-armed by clear()) when the filter is saturating.
105
+ * Membership tests the UNION of all generations, so occupancy is measured on
106
+ * the union too — measuring only the active generation would let two
107
+ * generations at 49% (union ~74%) pass silently. Past ~50% union fill the
108
+ * effective false-positive rate is far above the configured target and the
109
+ * metric drifts toward all-repeat_seen.
110
+ */
111
+ maybeWarnSaturation() {
112
+ if (this.saturationWarned || this.bits === null)
113
+ return;
114
+ const gens = this.bits;
115
+ let setBits = 0;
116
+ for (let byte = 0; byte < this.bytesPerGen; byte++) {
117
+ let union = 0;
118
+ for (let g = 0; g < gens.length; g++) {
119
+ union |= gens[g][byte];
120
+ }
121
+ setBits += POPCOUNT[union];
122
+ }
123
+ const fill = setBits / this.m;
124
+ if (fill >= SATURATION_FILL_THRESHOLD) {
125
+ this.saturationWarned = true;
126
+ emitLog("warn", `duplicate filter is ${Math.round(fill * 100)}% full — false-positive rate is degraded and repeat_seen counts are inflated. Raise FRUGAL_DUPLICATE_CAPACITY above the number of distinct requests per window.`);
127
+ }
128
+ }
129
+ rotate(nowMs) {
130
+ const elapsed = nowMs - this.genStartMs;
131
+ if (elapsed < this.rotateMs)
132
+ return;
133
+ const steps = Math.floor(elapsed / this.rotateMs);
134
+ const clears = Math.min(this.generations, steps);
135
+ for (let s = 0; s < clears; s++) {
136
+ this.activeIndex = (this.activeIndex + 1) % this.generations;
137
+ this.bits[this.activeIndex].fill(0);
138
+ }
139
+ this.genStartMs += steps * this.rotateMs;
140
+ }
141
+ positions(signature) {
142
+ const h1 = (parseInt(signature.slice(0, 8), 16) || 0) >>> 0;
143
+ const h2 = ((parseInt(signature.slice(8, 16), 16) || 0) | 1) >>> 0;
144
+ const out = new Array(this.k);
145
+ for (let i = 0; i < this.k; i++) {
146
+ out[i] = (h1 + i * h2) % this.m;
147
+ }
148
+ return out;
149
+ }
150
+ }
151
+ let shared = null;
152
+ export function getSharedDuplicateFilter(config) {
153
+ if (!config.duplicateDetection)
154
+ return null;
155
+ if (shared === null) {
156
+ shared = new RotatingBloomFilter({
157
+ capacity: config.duplicateCapacity,
158
+ fpRate: config.duplicateFpRate,
159
+ generations: config.duplicateGenerations,
160
+ windowSeconds: config.duplicateWindowSeconds,
161
+ });
162
+ }
163
+ return shared;
164
+ }
165
+ export function resetSharedDuplicateFilterForTests() {
166
+ shared = null;
167
+ }
168
+ //# sourceMappingURL=duplicate-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate-filter.js","sourceRoot":"","sources":["../src/duplicate-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/D,SAAS,WAAW,CAAC,QAAgB,EAAE,MAAc;IACnD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACrB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC,EA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AC,sBAAsB;SAC7C,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,kCAAkC;IAChD,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export { wrapAnthropic } from "./wrappers/anthropic.js";
3
3
  export { wrapBedrock } from "./wrappers/bedrock.js";
4
4
  export { startAICall, trackAICall } from "./track.js";
5
5
  export type { AICallInfo, AIUsage, AICallHandle } from "./track.js";
6
+ export { PROVIDERS, normalizeProvider, normalizeOperation } from "./providers.js";
7
+ export type { GenAiSystem, GenAiOperation, ProviderEntry } from "./providers.js";
6
8
  export { setDebugCallback } from "./debug.js";
7
9
  export type { DebugCallback, LogLevel } from "./debug.js";
8
10
  export { flush, shutdown, enableAutoShutdown } from "./shutdown.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAClF,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export { wrapOpenAI } from "./wrappers/openai.js";
2
2
  export { wrapAnthropic } from "./wrappers/anthropic.js";
3
3
  export { wrapBedrock } from "./wrappers/bedrock.js";
4
4
  export { startAICall, trackAICall } from "./track.js";
5
+ export { PROVIDERS, normalizeProvider, normalizeOperation } from "./providers.js";
5
6
  export { setDebugCallback } from "./debug.js";
6
7
  export { flush, shutdown, enableAutoShutdown } from "./shutdown.js";
7
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}