@drawbridge/drawbridge-utils 0.0.35 → 0.0.36
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 +3 -0
- package/dist/ai.d.cts +12 -0
- package/dist/ai.d.ts +12 -0
- package/dist/ai.js +3 -0
- package/package.json +2 -1
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";
|
|
@@ -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
|
@@ -7,6 +7,7 @@ import {
|
|
|
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,
|
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.
|
|
107
|
+
"version": "0.0.36"
|
|
107
108
|
}
|