@pepys/source-telemetry 0.0.1 → 0.1.1

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
@@ -28,6 +28,8 @@ bun add @pepys/source-telemetry
28
28
  - `telemetryPlugin`: the plug-in, to add to a deployment.
29
29
  - `telemetryModelRequestConsumer` and `telemetryTurnCostConsumer`: the consumers of the log record
30
30
  facts, with their SQL schemas.
31
+ - `sessionModelRequestsQuery`: the query `telemetry_session_model_requests`, which returns the model
32
+ requests of one session that the named sender stored.
31
33
 
32
34
  ## Documentation
33
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pepys/source-telemetry",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "description": "The pepys telemetry plug-in: the OTLP log records of coding agents, with their model requests and turn costs",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,14 +19,14 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@pepys/kit": "0.0.1",
22
+ "@pepys/kit": "0.1.1",
23
23
  "@zgeoff/std": "0.4.3",
24
24
  "tiny-invariant": "1.3.3",
25
25
  "zod": "4.6.7"
26
26
  },
27
27
  "devDependencies": {
28
- "@pepys/cli": "0.0.1",
29
- "@pepys/ingest": "0.0.1",
30
- "@pepys/testing": "0.0.1"
28
+ "@pepys/cli": "0.1.1",
29
+ "@pepys/ingest": "0.1.1",
30
+ "@pepys/testing": "0.1.1"
31
31
  }
32
32
  }
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export { defineTelemetryProduct } from './products/define-telemetry-product.ts';
20
20
  export { products } from './products/products.ts';
21
21
  export type { ProductName } from './products/products.ts';
22
22
  export type { TelemetryProduct } from './products/types.ts';
23
+ export { sessionModelRequestsQuery } from './queries/session-model-requests-query.ts';
23
24
  export { telemetryModelRequestConsumer } from './telemetry-model-request-consumer.ts';
24
25
  export { telemetryPlugin, telemetrySource } from './telemetry-plugin.ts';
25
26
  export { telemetryTurnCostConsumer } from './telemetry-turn-cost-consumer.ts';
@@ -0,0 +1,55 @@
1
+ import { defineQuery } from '@pepys/kit';
2
+ import type { EntityID } from '@pepys/kit';
3
+ import { toTagged } from '@zgeoff/std';
4
+ import { z } from 'zod';
5
+ import { telemetryModelRequestConsumer } from '../telemetry-model-request-consumer.ts';
6
+
7
+ const modelRequestSchema = z.object({
8
+ id: z.string(),
9
+ product: z.string(),
10
+ model: z.string(),
11
+ input_tokens: z.number(),
12
+ cache_read_tokens: z.number(),
13
+ cache_creation_tokens: z.number(),
14
+ output_tokens: z.number(),
15
+ cost_usd: z.number().nullable(),
16
+ at: z.string(),
17
+ });
18
+
19
+ // The sender writes the session of a record, so a row counts only when the caller names the sender
20
+ // that owns the session, as another plug-in's fact gives it.
21
+ export const sessionModelRequestsQuery = defineQuery({
22
+ name: 'telemetry_session_model_requests',
23
+ description:
24
+ 'Returns the model requests of one telemetry session, oldest first, that the named sender stored: the sender is the issuer and the subject of the identity that proved each export. A row from any other sender is left out.',
25
+ input: z.object({
26
+ session: z.string().min(1),
27
+ issuer: z.string().min(1),
28
+ subject: z.string().min(1),
29
+ }),
30
+ output: z.array(modelRequestSchema),
31
+ reads: [telemetryModelRequestConsumer],
32
+ handler: async (call) => {
33
+ const rows = await call.db
34
+ .selectFrom('telemetry_model_request')
35
+ .select([
36
+ 'id',
37
+ 'product',
38
+ 'model',
39
+ 'input_tokens',
40
+ 'cache_read_tokens',
41
+ 'cache_creation_tokens',
42
+ 'output_tokens',
43
+ 'cost_usd',
44
+ 'at',
45
+ ])
46
+ .where('session_id', '=', toTagged<EntityID>(call.input.session))
47
+ .where('origin_issuer', '=', call.input.issuer)
48
+ .where('origin_subject', '=', call.input.subject)
49
+ .orderBy('at')
50
+ .orderBy('id')
51
+ .execute();
52
+
53
+ return rows;
54
+ },
55
+ });
@@ -2,6 +2,7 @@ import { definePlugin, defineSource } from '@pepys/kit';
2
2
  import { logRecordFamily } from './log-record-family.ts';
3
3
  import { receiveOtlpLogs } from './otlp/receive-otlp-logs.ts';
4
4
  import { products } from './products/products.ts';
5
+ import { sessionModelRequestsQuery } from './queries/session-model-requests-query.ts';
5
6
  import { telemetryModelRequestConsumer } from './telemetry-model-request-consumer.ts';
6
7
  import { telemetryTurnCostConsumer } from './telemetry-turn-cost-consumer.ts';
7
8
 
@@ -39,4 +40,5 @@ export const telemetryPlugin = definePlugin({
39
40
  name: 'telemetry',
40
41
  sources: [telemetrySource],
41
42
  consumers: [telemetryModelRequestConsumer, telemetryTurnCostConsumer],
43
+ queries: [sessionModelRequestsQuery],
42
44
  });