@drawbridge/drawbridge-utils 0.0.35 → 0.0.37

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/dist/ai.cjs CHANGED
@@ -30,6 +30,7 @@ __export(ai_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(ai_exports);
32
32
  var import_genai = require("@google/genai");
33
+ var import_drawbridge_telemetry = require("@drawbridge/drawbridge-telemetry");
33
34
 
34
35
  // circuit.js
35
36
  var CLOSED = "CLOSED";
@@ -104,7 +105,7 @@ var insertTransaction = async ({
104
105
  collection: "transaction",
105
106
  data: {
106
107
  ..._id && { _id },
107
- userId: user == null ? void 0 : user.id,
108
+ user: user == null ? void 0 : user.id,
108
109
  type,
109
110
  category,
110
111
  source,
@@ -239,6 +240,7 @@ var billRequest = async ({
239
240
  }) => {
240
241
  const gross = priceForRequest(model, usage, tools);
241
242
  const cogs = costForRequest(model, usage, tools);
243
+ const id = (0, import_drawbridge_telemetry.currentTraceId)();
242
244
  await debit({
243
245
  db,
244
246
  user,
@@ -246,6 +248,7 @@ var billRequest = async ({
246
248
  type: "ai",
247
249
  category: "usage",
248
250
  source: "user",
251
+ ...id && { trace: { id } },
249
252
  ai: {
250
253
  name: "google",
251
254
  model,
package/dist/ai.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GoogleGenAI } from '@google/genai';
2
+ import { currentTraceId } from '@drawbridge/drawbridge-telemetry';
2
3
  import { circuit } from './circuit.cjs';
3
4
  import { debit } from './transactions.cjs';
4
5
 
@@ -182,6 +183,16 @@ const billRequest = async ({
182
183
  const gross = priceForRequest( model, usage, tools );
183
184
  const cogs = costForRequest( model, usage, tools );
184
185
 
186
+ // Stamp the current trace ID so multiple AI calls inside one HTTP request
187
+ // (or one BullMQ job) share a grouping key — the UI can collapse rows
188
+ // per trace.id to show "this preview cost $0.12 across 5 calls" without
189
+ // the user needing to mentally fold them together. currentTraceId()
190
+ // returns undefined when called outside any traced scope, in which case
191
+ // the field is omitted from the row (additionalProperties:false would
192
+ // reject `trace: undefined`). Nested as `trace.id` to match the `ai` /
193
+ // `balance` sub-object pattern already on this document.
194
+ const id = currentTraceId();
195
+
185
196
  await debit({
186
197
  db,
187
198
  user,
@@ -189,6 +200,7 @@ const billRequest = async ({
189
200
  type : 'ai',
190
201
  category : 'usage',
191
202
  source : 'user',
203
+ ...( id && { trace : { id } }),
192
204
  ai : {
193
205
  name : 'google',
194
206
  model,
package/dist/ai.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { GoogleGenAI } from '@google/genai';
2
+ import { currentTraceId } from '@drawbridge/drawbridge-telemetry';
2
3
  import { circuit } from './circuit.js';
3
4
  import { debit } from './transactions.js';
4
5
 
@@ -182,6 +183,16 @@ const billRequest = async ({
182
183
  const gross = priceForRequest( model, usage, tools );
183
184
  const cogs = costForRequest( model, usage, tools );
184
185
 
186
+ // Stamp the current trace ID so multiple AI calls inside one HTTP request
187
+ // (or one BullMQ job) share a grouping key — the UI can collapse rows
188
+ // per trace.id to show "this preview cost $0.12 across 5 calls" without
189
+ // the user needing to mentally fold them together. currentTraceId()
190
+ // returns undefined when called outside any traced scope, in which case
191
+ // the field is omitted from the row (additionalProperties:false would
192
+ // reject `trace: undefined`). Nested as `trace.id` to match the `ai` /
193
+ // `balance` sub-object pattern already on this document.
194
+ const id = currentTraceId();
195
+
185
196
  await debit({
186
197
  db,
187
198
  user,
@@ -189,6 +200,7 @@ const billRequest = async ({
189
200
  type : 'ai',
190
201
  category : 'usage',
191
202
  source : 'user',
203
+ ...( id && { trace : { id } }),
192
204
  ai : {
193
205
  name : 'google',
194
206
  model,
package/dist/ai.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  debit
3
- } from "./chunk-RW2FJVIV.js";
3
+ } from "./chunk-DLRNUBZ4.js";
4
4
  import {
5
5
  circuit
6
6
  } from "./chunk-6HH36OK6.js";
7
7
 
8
8
  // ai.js
9
9
  import { GoogleGenAI } from "@google/genai";
10
+ import { currentTraceId } from "@drawbridge/drawbridge-telemetry";
10
11
  var google_client = new GoogleGenAI({
11
12
  apiKey: process.env.GOOGLE_API_KEY
12
13
  });
@@ -93,6 +94,7 @@ var billRequest = async ({
93
94
  }) => {
94
95
  const gross = priceForRequest(model, usage, tools);
95
96
  const cogs = costForRequest(model, usage, tools);
97
+ const id = currentTraceId();
96
98
  await debit({
97
99
  db,
98
100
  user,
@@ -100,6 +102,7 @@ var billRequest = async ({
100
102
  type: "ai",
101
103
  category: "usage",
102
104
  source: "user",
105
+ ...id && { trace: { id } },
103
106
  ai: {
104
107
  name: "google",
105
108
  model,
@@ -20,7 +20,7 @@ var insertTransaction = async ({
20
20
  collection: "transaction",
21
21
  data: {
22
22
  ..._id && { _id },
23
- userId: user == null ? void 0 : user.id,
23
+ user: user == null ? void 0 : user.id,
24
24
  type,
25
25
  category,
26
26
  source,
@@ -44,7 +44,7 @@ var insertTransaction = async ({
44
44
  collection: "transaction",
45
45
  data: {
46
46
  ..._id && { _id },
47
- userId: user == null ? void 0 : user.id,
47
+ user: user == null ? void 0 : user.id,
48
48
  type,
49
49
  category,
50
50
  source,
@@ -50,7 +50,7 @@ const insertTransaction = async ({
50
50
  collection : 'transaction',
51
51
  data : {
52
52
  ...( _id && { _id }),
53
- userId : user?.id,
53
+ user : user?.id,
54
54
  type,
55
55
  category,
56
56
  source,
@@ -50,7 +50,7 @@ const insertTransaction = async ({
50
50
  collection : 'transaction',
51
51
  data : {
52
52
  ...( _id && { _id }),
53
- userId : user?.id,
53
+ user : user?.id,
54
54
  type,
55
55
  category,
56
56
  source,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  credit,
3
3
  debit
4
- } from "./chunk-RW2FJVIV.js";
4
+ } from "./chunk-DLRNUBZ4.js";
5
5
  export {
6
6
  credit,
7
7
  debit
package/package.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "type": "module",
3
3
  "dependencies": {
4
4
  "@drawbridge/drawbridge-agents": "0.0.10",
5
+ "@drawbridge/drawbridge-telemetry": "0.0.13",
5
6
  "@google/genai": "1.30.0",
6
7
  "axios": "1.16.0",
7
8
  "currency-codes": "2.2.0",
@@ -103,5 +104,5 @@
103
104
  "build": "tsup && npm publish"
104
105
  },
105
106
  "types": "dist/index.d.ts",
106
- "version": "0.0.35"
107
+ "version": "0.0.37"
107
108
  }