@introspection-sdk/introspection-pi 0.7.0 → 0.7.2

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.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * GenAI client metric instruments per the OTel GenAI semconv metrics doc.
3
+ *
4
+ * Instruments are created lazily per `Meter` and cached, so repeated
5
+ * `instrumentStream` / `instrumentAgent` calls sharing a meter reuse the
6
+ * same histograms. Bucket boundaries follow the spec's
7
+ * ExplicitBucketBoundaries advice where one is defined.
8
+ */
9
+ /** Spec advice for `gen_ai.client.token.usage`. */
10
+ const TOKEN_BUCKETS = [
11
+ 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304,
12
+ 16777216, 67108864,
13
+ ];
14
+ /** Spec advice for the client duration / chunk-timing histograms. */
15
+ const DURATION_BUCKETS = [
16
+ 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48,
17
+ 40.96, 81.92,
18
+ ];
19
+ /** Spec advice for in-process agent invocation durations. */
20
+ const AGENT_DURATION_BUCKETS = [
21
+ 0.1, 0.2, 0.4, 0.8, 1.6, 3.2, 6.4, 12.8, 25.6, 51.2, 102.4, 204.8, 409.6,
22
+ ];
23
+ const metricsByMeter = new WeakMap();
24
+ /** Get (or create) the GenAI instruments for a meter. */
25
+ export function genAiMetrics(meter) {
26
+ const cached = metricsByMeter.get(meter);
27
+ if (cached)
28
+ return cached;
29
+ const metrics = {
30
+ tokenUsage: meter.createHistogram("gen_ai.client.token.usage", {
31
+ description: "Number of input and output tokens used.",
32
+ unit: "{token}",
33
+ advice: { explicitBucketBoundaries: TOKEN_BUCKETS },
34
+ }),
35
+ operationDuration: meter.createHistogram("gen_ai.client.operation.duration", {
36
+ description: "GenAI operation duration.",
37
+ unit: "s",
38
+ advice: { explicitBucketBoundaries: DURATION_BUCKETS },
39
+ }),
40
+ timeToFirstChunk: meter.createHistogram("gen_ai.client.operation.time_to_first_chunk", {
41
+ description: "Time to receive the first chunk of the response stream, measured from request issuance.",
42
+ unit: "s",
43
+ advice: { explicitBucketBoundaries: DURATION_BUCKETS },
44
+ }),
45
+ timePerOutputChunk: meter.createHistogram("gen_ai.client.operation.time_per_output_chunk", {
46
+ description: "Time per output chunk, recorded for each chunk received after the first one.",
47
+ unit: "s",
48
+ advice: { explicitBucketBoundaries: DURATION_BUCKETS },
49
+ }),
50
+ executeToolDuration: meter.createHistogram("gen_ai.execute_tool.duration", {
51
+ description: "The duration of a single tool execution.",
52
+ unit: "s",
53
+ advice: { explicitBucketBoundaries: DURATION_BUCKETS },
54
+ }),
55
+ invokeAgentDuration: meter.createHistogram("gen_ai.invoke_agent.duration", {
56
+ description: "The end-to-end duration of a single in-process agent invocation.",
57
+ unit: "s",
58
+ advice: { explicitBucketBoundaries: AGENT_DURATION_BUCKETS },
59
+ }),
60
+ };
61
+ metricsByMeter.set(meter, metrics);
62
+ return metrics;
63
+ }
64
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,mDAAmD;AACnD,MAAM,aAAa,GAAG;IACpB,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACrE,QAAQ,EAAE,QAAQ;CACnB,CAAC;AAEF,qEAAqE;AACrE,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK;IACxE,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,6DAA6D;AAC7D,MAAM,sBAAsB,GAAG;IA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BAAgB,EAAE;SACvD,CAAC;QACF,mBAAmB,EAAE,KAAK,CAAC,eAAe,CAAC,8BAA8B,EAAE;YACzE,WAAW,EACT,kEAAkE;YACpE,IAAI,EAAE,GAAG;YACT,MAAM,EAAE,EAAE,wBAAwB,EAAE,sBAAsB,EAAE;SAC7D,CAAC;KACH,CAAC;IAEF,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@introspection-sdk/introspection-pi",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Introspection observability extension for the Pi Agent SDK — OTEL GenAI semantic-convention spans for chat completions and tool execution",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "@opentelemetry/api": "^1.9.1",
20
- "@introspection-sdk/types": "0.7.0"
20
+ "@introspection-sdk/types": "0.7.2"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@earendil-works/pi-ai": ">=0.75.0",
@@ -32,8 +32,8 @@
32
32
  }
33
33
  },
34
34
  "devDependencies": {
35
- "@earendil-works/pi-agent-core": "^0.80.2",
36
- "@earendil-works/pi-ai": "^0.80.2",
35
+ "@earendil-works/pi-agent-core": "^0.80.3",
36
+ "@earendil-works/pi-ai": "^0.80.3",
37
37
  "@types/node": "^22.20.0",
38
38
  "eslint": "^9.39.4",
39
39
  "typescript": "5.9.3",