metergraph 0.6.18 → 0.6.19
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 +2 -0
- package/dist/capture.d.ts +1 -0
- package/dist/capture.js +5 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wrap.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -302,4 +302,6 @@ 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.
|
package/dist/capture.d.ts
CHANGED
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/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.6.
|
|
1
|
+
export declare const SDK_VERSION = "0.6.19";
|
package/dist/version.js
CHANGED
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, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metergraph",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.19",
|
|
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",
|