metergraph 0.6.18 → 0.6.20

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/README.md CHANGED
@@ -302,4 +302,8 @@ calls made outside these supported paths.
302
302
 
303
303
  Calls record `service_tier` separately from `requested_service_tier`: requesting Flex does not prove it was served. Capture reads OpenAI's response tier, Anthropic's usage tier, and Google's usage tier or traffic type, retaining evidence across trailing stream events. Successful Batch API results record `batch` from the transport, without inventing a requested tier. Missing response evidence stays unknown.
304
304
 
305
+ Interrupted Anthropic streams retain available input/cache usage and message IDs, plus `http_request_id` when the SDK exposes it. `usage_complete: false` marks observed usage as incomplete; it does not establish the final charge or mean the request was free.
306
+
305
307
  Search usage is retained independently of text capture: OpenAI search-call counts, Anthropic server-tool usage, and Google grounding-query counts. Perplexity Responses capture uses invocation counters, with search-result items as a fallback. Clients using `https://api.perplexity.ai` are detected automatically; use `wrap(client, { provider: "perplexity" })` when a gateway hides the provider. Perplexity Agent and legacy Sonar calls are identified separately. Agent search type is recorded when explicitly set on the tool; missing evidence remains unknown. Prices are resolved by the receiver.
308
+
309
+ For other OpenAI-compatible clients, pass the actual provider name to `wrap()` (for example, `provider="deepseek"` in Python or `{ provider: "deepseek" }` in TypeScript). Capture uses the OpenAI-compatible methods while preserving that provider identity; no provider SDK dependency or routing change is added.
package/dist/capture.d.ts CHANGED
@@ -45,6 +45,7 @@ export declare class CaptureRuntime {
45
45
  responseText?: string;
46
46
  responseChunks?: unknown[];
47
47
  evidenceChunks?: unknown[];
48
+ httpRequestId?: string;
48
49
  }): void;
49
50
  }
50
51
  export {};
package/dist/capture.js CHANGED
@@ -854,9 +854,13 @@ class CaptureRuntime {
854
854
  tool_calls: fullTools ? persistedTools : toolNames(state.request),
855
855
  tool_names: observedToolNames?.length ? observedToolNames : undefined,
856
856
  endpoint: state.endpoint,
857
+ http_request_id: extra.httpRequestId ?? get(extra.error, "request_id"),
858
+ usage_complete: extra.stream === true
859
+ ? extra.error === undefined && extra.status !== "error" && extra.status !== "abandoned"
860
+ : undefined,
857
861
  request_id: get(response, "_request_id") ?? get(response, "response_id")
858
862
  ?? get(response, "responseId") ?? get(response, "id")
859
- ?? get(get(response, "response"), "id"),
863
+ ?? get(get(response, "response"), "id") ?? get(extra.error, "request_id"),
860
864
  batch: state.request.batch === true,
861
865
  batch_custom_id: state.request.batch_custom_id,
862
866
  // Explicit false is the sensitive-operation opt-out; hosted ingestion
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { route, setDefaultTags, setSession, setUser, setTags, trace, withContext
2
2
  import { BatchFirstIneligibleError, batchFirst, type BatchFirstMetadata, type BatchFirstPolicy, type BatchFirstProvider, type BatchFirstRequest, type BatchFirstResult, type BatchFirstSource, type LateBatchInfo } from "./batch-first.js";
3
3
  import { track } from "./track.js";
4
4
  import { type TransportMode, type WaitUntil } from "./transport.js";
5
- import { type WrapOptions } from "./wrap.js";
5
+ import { type WrapOptions, type ProviderName } from "./wrap.js";
6
6
  import { type VercelAISDKMiddleware, type VercelAISDKMiddlewareOptions as VercelAISDKCompatibilityOptions, type VercelAISDKMiddlewareSpecificationOptions, type VercelAISDKMiddlewareVersionOptions, type VercelAISDKSpecificationVersion } from "./vercel-ai.js";
7
7
  export interface MetergraphOptions {
8
8
  token?: string;
@@ -57,7 +57,7 @@ export declare function wrapHandler<TArgs extends unknown[], TResult>(handler: (
57
57
  * OpenAI-compatible clients pointed at OpenRouter are detected automatically;
58
58
  * pass `{ gateway: "openrouter" }` to force it for a trusted custom domain.
59
59
  */
60
- export declare function wrap<T extends Record<PropertyKey, any>>(client: T, provider?: "openai" | "anthropic" | "google"): T;
60
+ export declare function wrap<T extends Record<PropertyKey, any>>(client: T, provider?: ProviderName): T;
61
61
  export declare function wrap<T extends Record<PropertyKey, any>>(client: T, options: WrapOptions): T;
62
62
  export declare const wrapClient: typeof wrap;
63
63
  /**
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.6.18";
1
+ export declare const SDK_VERSION = "0.6.20";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.6.18";
4
+ exports.SDK_VERSION = "0.6.20";
package/dist/wrap.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare const OPENAI_SEAMS: Seam[];
14
14
  export declare const ANTHROPIC_SEAMS: Seam[];
15
15
  export declare const GOOGLE_SEAMS: Seam[];
16
16
  export declare const SEAM_TABLES: Record<string, Seam[]>;
17
- export type ProviderName = "openai" | "anthropic" | "google" | "perplexity";
17
+ export type ProviderName = "openai" | "anthropic" | "google" | "perplexity" | (string & {});
18
18
  export type WrapOptions = {
19
19
  provider?: ProviderName;
20
20
  gateway?: never;
package/dist/wrap.js CHANGED
@@ -229,6 +229,7 @@ function streamProxy(stream, state, capture, suppressUsageOnly) {
229
229
  let ttftMs;
230
230
  const parts = [];
231
231
  const chunks = [];
232
+ let helperSnapshot;
232
233
  const hasOutput = (chunk) => {
233
234
  if ((0, capture_js_1.chunkText)(chunk))
234
235
  return true;
@@ -264,7 +265,18 @@ function streamProxy(stream, state, capture, suppressUsageOnly) {
264
265
  return chunk;
265
266
  };
266
267
  const finish = (response = last, error, status) => {
268
+ let httpRequestId;
269
+ if (state.provider === "anthropic") {
270
+ try {
271
+ if (error || status === "abandoned")
272
+ response = stream.currentMessage ?? helperSnapshot ?? response;
273
+ if (typeof stream.request_id === "string")
274
+ httpRequestId = stream.request_id;
275
+ }
276
+ catch { /* Native stream getters must not affect request behavior. */ }
277
+ }
267
278
  finishCapture(capture, state, response, {
279
+ httpRequestId,
268
280
  error,
269
281
  status,
270
282
  stream: true,
@@ -274,6 +286,14 @@ function streamProxy(stream, state, capture, suppressUsageOnly) {
274
286
  });
275
287
  };
276
288
  if (typeof stream.on === "function") {
289
+ if (state.provider === "anthropic") {
290
+ stream.on("streamEvent", (_event, snapshot) => {
291
+ // Helpers consume the stream internally and may clear their snapshot
292
+ // before finalMessage() rejects. Keep its latest native usage evidence.
293
+ if (snapshot != null)
294
+ helperSnapshot = snapshot;
295
+ });
296
+ }
277
297
  stream.on("error", (error) => finish(last, error));
278
298
  }
279
299
  return new Proxy(stream, {
@@ -720,7 +740,7 @@ function resolveSeam(client, path) {
720
740
  }
721
741
  function applySeams(client, provider, gatewayName) {
722
742
  const patched = [];
723
- for (const seam of exports.SEAM_TABLES[provider === "perplexity" ? "openai" : provider] ?? []) {
743
+ for (const seam of exports.SEAM_TABLES[provider] ?? exports.SEAM_TABLES.openai ?? []) {
724
744
  let owner;
725
745
  try {
726
746
  owner = resolveSeam(client, seam.path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metergraph",
3
- "version": "0.6.18",
3
+ "version": "0.6.20",
4
4
  "description": "Zero-dependency TypeScript SDK for function-level LLM cost attribution across major LLM providers and frameworks, including OpenAI, Anthropic, Gemini, and Vercel AI SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",