metergraph 0.1.0 → 0.2.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/README.md CHANGED
@@ -18,7 +18,7 @@ setSession("ticket-123");
18
18
 
19
19
  let model = "gpt-4.1-mini";
20
20
  await route("ticket-classifier", async () => {
21
- model = modelFor("ticket-classifier", model);
21
+ model = modelFor("ticket-classifier", { default: model });
22
22
  await client.chat.completions.create({ model, messages: [] });
23
23
  }, { unit: "answer", captureText: true });
24
24
 
@@ -31,6 +31,12 @@ recordOutcome("ticket-classifier", {
31
31
  });
32
32
  ```
33
33
 
34
+ `modelFor(routeName, { default, sessionKey })` takes an options object.
35
+ **Breaking change from `metergraph@0.1.0`**, which took positional
36
+ `modelFor(routeName, fallback, sessionKey?)` arguments; `default` is
37
+ required and throws if missing so a caller error surfaces immediately
38
+ instead of an `undefined` model reaching a provider call.
39
+
34
40
  Set `METERGRAPH_APP_TOKEN`; `METERGRAPH_INGEST_URL` is only needed to override
35
41
  the hosted HTTPS endpoint. Content is metadata-only by default; set
36
42
  `METERGRAPH_CAPTURE_TEXT=1` globally or `captureText: true` on an individual
package/dist/index.d.ts CHANGED
@@ -17,6 +17,10 @@ export interface MetergraphOptions {
17
17
  configPollMs?: number;
18
18
  configHardTtlMs?: number;
19
19
  }
20
+ export interface ModelForOptions {
21
+ default: string;
22
+ sessionKey?: string;
23
+ }
20
24
  export interface OutcomeOptions {
21
25
  model: string;
22
26
  taskCompleted: boolean;
@@ -31,7 +35,7 @@ export interface OutcomeOptions {
31
35
  }
32
36
  export declare const DEFAULT_INGEST_URL = "https://d2xus7mp8zdv6t.cloudfront.net";
33
37
  export declare function init(options?: MetergraphOptions): void;
34
- export declare function modelFor(routeName: string, fallback: string, sessionKey?: string): string;
38
+ export declare function modelFor(routeName: string, options: ModelForOptions): string;
35
39
  export declare function recordOutcome(routeName: string, options: OutcomeOptions): boolean;
36
40
  export declare function bindWaitUntil(value: {
37
41
  waitUntil(promise: Promise<unknown>): void;
package/dist/index.js CHANGED
@@ -60,8 +60,11 @@ export function init(options = {}) {
60
60
  console.warn("Metergraph initialization failed; application is running uninstrumented");
61
61
  }
62
62
  }
63
- export function modelFor(routeName, fallback, sessionKey) {
64
- return config?.modelFor(routeName, fallback, sessionKey ?? contextSnapshot().sessionId) ?? fallback;
63
+ export function modelFor(routeName, options) {
64
+ if (typeof options?.default !== "string" || !options.default) {
65
+ throw new TypeError("modelFor requires options.default to be a non-empty string");
66
+ }
67
+ return config?.modelFor(routeName, options.default, options.sessionKey ?? contextSnapshot().sessionId) ?? options.default;
65
68
  }
66
69
  export function recordOutcome(routeName, options) {
67
70
  const routeNameClean = String(routeName).trim().slice(0, 512);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.0";
1
+ export declare const SDK_VERSION = "0.2.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.1.0";
1
+ export const SDK_VERSION = "0.2.0";
package/dist/wrap.js CHANGED
@@ -331,6 +331,8 @@ export function wrap(client, provider) {
331
331
  patched += Number(patch(client.models, "generateContentStream", name, "models.generate_content.stream"));
332
332
  }
333
333
  patched += Number(patch(client.chat?.completions, "create", name, "chat.completions"));
334
+ patched += Number(patch(client.chat?.completions, "parse", name, "chat.completions.parse"));
335
+ patched += Number(patch(client.beta?.chat?.completions, "parse", name, "chat.completions.parse"));
334
336
  patched += Number(patch(client.responses, "create", name, "responses"));
335
337
  patched += Number(patch(client.responses, "stream", name, "responses.stream"));
336
338
  patched += Number(patch(client.messages, "create", name, "messages"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metergraph",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Fire-and-forget LLM spend capture for Metergraph",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,6 +20,17 @@
20
20
  "node": ">=18"
21
21
  },
22
22
  "license": "Apache-2.0",
23
+ "author": "Pioneer Square Labs",
24
+ "homepage": "https://www.metergraph.dev/",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/PioneerSquareLabs/metergraphsdk.git",
28
+ "directory": "typescript"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/PioneerSquareLabs/metergraphsdk/issues"
32
+ },
33
+ "keywords": ["llm", "observability", "openai", "anthropic", "gemini", "cost-tracking"],
23
34
  "dependencies": {},
24
35
  "devDependencies": {
25
36
  "@types/node": "^24.0.0",