Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Attributes.ts

51 lines1.6 KB

1import { ANTIGRAVITY_DEFAULT_MODEL } from "@t3tools/contracts";
2import * as Cause from "effect/Cause";
3import * as Exit from "effect/Exit";
4​
5export type MetricAttributeValue = string;
6export type MetricAttributes = Readonly<Record<string, MetricAttributeValue>>;
7export type ObservabilityOutcome = "success" | "failure" | "interrupt";
8​
9export function compactMetricAttributes(
10 attributes: Readonly<Record<string, unknown>>,
11): MetricAttributes {
12 return Object.fromEntries(
13 Object.entries(attributes).flatMap(([key, value]) => {
14 if (value === undefined || value === null) {
15 return [];
16 }
17 if (typeof value === "string") {
18 return [[key, value]];
19 }
20 if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
21 return [[key, String(value)]];
22 }
23 return [];
24 }),
25 );
27​
28export function outcomeFromExit(exit: Exit.Exit<unknown, unknown>): ObservabilityOutcome {
29 if (Exit.isSuccess(exit)) {
30 return "success";
31 }
32 return Cause.hasInterruptsOnly(exit.cause) ? "interrupt" : "failure";
34​
35export function normalizeModelMetricLabel(model: string | null | undefined): string | undefined {
36 const normalized = model?.trim().toLowerCase();
37 if (!normalized) {
38 return undefined;
39 }
40 if (normalized.includes("gpt")) {
41 return "gpt";
42 }
43 if (normalized.includes("claude")) {
44 return "claude";
45 }
46 // Antigravity's default alias names no model; its default is a Gemini model.
47 if (normalized.includes("gemini") || normalized === ANTIGRAVITY_DEFAULT_MODEL) {
48 return "gemini";
49 }
50 return "other";