@columenlabs/lumen-ops 0.1.257 → 0.1.258

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
@@ -151,13 +151,16 @@ import { meterEvent, setEventSink } from '@columenlabs/lumen-ops/events';
151
151
  setEventSink(env.EVENTS);
152
152
  meterEvent({ event: 'bank.call', code: '/accounts/get', ok: res.ok, ms, status: res.status, upstream: true });
153
153
  meterEvent({ event: 'sync.done', ok: true, subject: accountId, ref: connectionId, counts: [added, modified, removed] });
154
+ meterEvent({ event: 'ai.answer', code: 'ok', ok: true, ms, ai: { model: 'claude-sonnet-5-5', in: 12000, out: 800, read: 9000, usd: 0.021 } });
154
155
  ```
155
156
 
156
157
  | Column | Holds |
157
158
  |---|---|
158
159
  | `index1` | Subject, or `anon` |
159
- | `blob1` … `blob10` | App, event, code, outcome, ref, trigger, request id, upstream id, env, version |
160
- | `double1` … `double6` | ms, status, count1, count2, count3, attempt |
160
+ | `blob1` … `blob11` | App, event, code, outcome, ref, trigger, request id, upstream id, env, version, AI model |
161
+ | `double1` … `double10` | ms, status, count1, count2, count3, attempt, AI usd, AI tokens in (cache reads included), AI tokens out, AI cache reads |
162
+
163
+ `ai` is for an event that asked a model (an answer, a generated draft): the model id and what that call cost, so use and spend can be read per model and per event. Points without it write empty and 0 there.
161
164
 
162
165
  `upstream: true` adds the call's time to the request's `upstream ms`. In a Durable Object no request is in scope: give `setEventSink(binding, { app, env, version })` the defaults, and pass a `requestId` the caller sent if you have one.
163
166
 
package/dist/events.d.ts CHANGED
@@ -27,6 +27,14 @@ export interface EventPoint {
27
27
  /** Up to three counts, named by the event (a sync: added, modified, removed). */
28
28
  counts?: [number?, number?, number?];
29
29
  attempt?: number;
30
+ /** A model call's use, for an event that asked an AI model: its id, tokens (in counts cache reads) and cost. */
31
+ ai?: {
32
+ model?: string;
33
+ in?: number;
34
+ out?: number;
35
+ read?: number;
36
+ usd?: number;
37
+ };
30
38
  /** `true` when the event was a call to another service: its time adds to the request's. */
31
39
  upstream?: boolean;
32
40
  /** Defaults to the request in scope; pass these from a Durable Object or a job. */
@@ -47,7 +55,7 @@ export interface EventDefaults {
47
55
  export declare function setEventSink(s: PointSink | undefined, d?: EventDefaults): void;
48
56
  /**
49
57
  * Column order is the contract with whoever reads the dataset back: index1 subject (or `anon`);
50
- * blobs app, event, code, outcome, ref, trigger, request id, upstream id, env, version; doubles
51
- * ms, status, count1, count2, count3, attempt.
58
+ * blobs app, event, code, outcome, ref, trigger, request id, upstream id, env, version, AI model;
59
+ * doubles ms, status, count1, count2, count3, attempt, AI usd, tokens in, tokens out, cache reads.
52
60
  */
53
61
  export declare function meterEvent(p: EventPoint): void;
package/dist/events.js CHANGED
@@ -12,8 +12,8 @@ export function setEventSink(s, d = {}) {
12
12
  }
13
13
  /**
14
14
  * Column order is the contract with whoever reads the dataset back: index1 subject (or `anon`);
15
- * blobs app, event, code, outcome, ref, trigger, request id, upstream id, env, version; doubles
16
- * ms, status, count1, count2, count3, attempt.
15
+ * blobs app, event, code, outcome, ref, trigger, request id, upstream id, env, version, AI model;
16
+ * doubles ms, status, count1, count2, count3, attempt, AI usd, tokens in, tokens out, cache reads.
17
17
  */
18
18
  export function meterEvent(p) {
19
19
  try {
@@ -40,6 +40,7 @@ export function meterEvent(p) {
40
40
  cap(p.upstreamId),
41
41
  cap(fields.env),
42
42
  cap(fields.version),
43
+ cap(p.ai?.model),
43
44
  ],
44
45
  doubles: [
45
46
  num(p.ms),
@@ -48,6 +49,10 @@ export function meterEvent(p) {
48
49
  num(p.counts?.[1]),
49
50
  num(p.counts?.[2]),
50
51
  num(p.attempt),
52
+ num(p.ai?.usd),
53
+ num(p.ai?.in),
54
+ num(p.ai?.out),
55
+ num(p.ai?.read),
51
56
  ],
52
57
  });
53
58
  logLine('event', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@columenlabs/lumen-ops",
3
- "version": "0.1.257",
3
+ "version": "0.1.258",
4
4
  "description": "Lumen's ops parts: every request, event, data query and tool call an app runs as one Analytics Engine point (templates, codes, shapes and hashes only), and signed webhooks out.",
5
5
  "license": "MIT",
6
6
  "type": "module",