@drawbridge/drawbridge-utils 0.0.38 → 0.0.39
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 -3
- package/dist/ai.d.cts +1 -11
- package/dist/ai.d.ts +1 -11
- package/dist/ai.js +1 -4
- package/dist/{chunk-DLRNUBZ4.js → chunk-JT2PAZAZ.js} +3 -0
- package/dist/transactions.cjs +3 -0
- package/dist/transactions.d.cts +11 -0
- package/dist/transactions.d.ts +11 -0
- package/dist/transactions.js +1 -1
- package/package.json +1 -1
package/dist/ai.cjs
CHANGED
|
@@ -30,7 +30,6 @@ __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");
|
|
34
33
|
|
|
35
34
|
// circuit.js
|
|
36
35
|
var CLOSED = "CLOSED";
|
|
@@ -84,6 +83,7 @@ var circuit = ({
|
|
|
84
83
|
};
|
|
85
84
|
|
|
86
85
|
// transactions.js
|
|
86
|
+
var import_drawbridge_telemetry = require("@drawbridge/drawbridge-telemetry");
|
|
87
87
|
var insertTransaction = async ({
|
|
88
88
|
db,
|
|
89
89
|
user,
|
|
@@ -100,6 +100,7 @@ var insertTransaction = async ({
|
|
|
100
100
|
var _a;
|
|
101
101
|
const beforeRaw = (_a = user == null ? void 0 : user.balance) == null ? void 0 : _a[type];
|
|
102
102
|
const balance = typeof beforeRaw === "number" ? { before: beforeRaw, after: beforeRaw + amount } : void 0;
|
|
103
|
+
const trace = (0, import_drawbridge_telemetry.currentTraceId)();
|
|
103
104
|
await db.create({
|
|
104
105
|
authenticated: user,
|
|
105
106
|
collection: "transaction",
|
|
@@ -111,6 +112,7 @@ var insertTransaction = async ({
|
|
|
111
112
|
source,
|
|
112
113
|
amount,
|
|
113
114
|
...balance && { balance },
|
|
115
|
+
...trace && { trace },
|
|
114
116
|
...rest,
|
|
115
117
|
...stripeInvoiceId && { stripeInvoiceId },
|
|
116
118
|
...stripeEventId && { stripeEventId }
|
|
@@ -240,7 +242,6 @@ var billRequest = async ({
|
|
|
240
242
|
}) => {
|
|
241
243
|
const gross = priceForRequest(model, usage, tools);
|
|
242
244
|
const cogs = costForRequest(model, usage, tools);
|
|
243
|
-
const trace = (0, import_drawbridge_telemetry.currentTraceId)();
|
|
244
245
|
await debit({
|
|
245
246
|
db,
|
|
246
247
|
user,
|
|
@@ -248,7 +249,6 @@ var billRequest = async ({
|
|
|
248
249
|
type: "ai",
|
|
249
250
|
category: "usage",
|
|
250
251
|
source: "user",
|
|
251
|
-
...trace && { trace },
|
|
252
252
|
ai: {
|
|
253
253
|
name: "google",
|
|
254
254
|
model,
|
package/dist/ai.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GoogleGenAI } from '@google/genai';
|
|
2
|
-
import { currentTraceId } from '@drawbridge/drawbridge-telemetry';
|
|
3
2
|
import { circuit } from './circuit.cjs';
|
|
4
3
|
import { debit } from './transactions.cjs';
|
|
4
|
+
import '@drawbridge/drawbridge-telemetry';
|
|
5
5
|
|
|
6
6
|
// AI request entry point. Wraps the Google GenAI client with a per-process
|
|
7
7
|
// circuit breaker, owns the per-model pricing table, and atomically debits
|
|
@@ -183,15 +183,6 @@ const billRequest = async ({
|
|
|
183
183
|
const gross = priceForRequest( model, usage, tools );
|
|
184
184
|
const cogs = costForRequest( model, usage, tools );
|
|
185
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 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`).
|
|
193
|
-
const trace = currentTraceId();
|
|
194
|
-
|
|
195
186
|
await debit({
|
|
196
187
|
db,
|
|
197
188
|
user,
|
|
@@ -199,7 +190,6 @@ const billRequest = async ({
|
|
|
199
190
|
type : 'ai',
|
|
200
191
|
category : 'usage',
|
|
201
192
|
source : 'user',
|
|
202
|
-
...( trace && { trace }),
|
|
203
193
|
ai : {
|
|
204
194
|
name : 'google',
|
|
205
195
|
model,
|
package/dist/ai.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GoogleGenAI } from '@google/genai';
|
|
2
|
-
import { currentTraceId } from '@drawbridge/drawbridge-telemetry';
|
|
3
2
|
import { circuit } from './circuit.js';
|
|
4
3
|
import { debit } from './transactions.js';
|
|
4
|
+
import '@drawbridge/drawbridge-telemetry';
|
|
5
5
|
|
|
6
6
|
// AI request entry point. Wraps the Google GenAI client with a per-process
|
|
7
7
|
// circuit breaker, owns the per-model pricing table, and atomically debits
|
|
@@ -183,15 +183,6 @@ const billRequest = async ({
|
|
|
183
183
|
const gross = priceForRequest( model, usage, tools );
|
|
184
184
|
const cogs = costForRequest( model, usage, tools );
|
|
185
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 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`).
|
|
193
|
-
const trace = currentTraceId();
|
|
194
|
-
|
|
195
186
|
await debit({
|
|
196
187
|
db,
|
|
197
188
|
user,
|
|
@@ -199,7 +190,6 @@ const billRequest = async ({
|
|
|
199
190
|
type : 'ai',
|
|
200
191
|
category : 'usage',
|
|
201
192
|
source : 'user',
|
|
202
|
-
...( trace && { trace }),
|
|
203
193
|
ai : {
|
|
204
194
|
name : 'google',
|
|
205
195
|
model,
|
package/dist/ai.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debit
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JT2PAZAZ.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";
|
|
11
10
|
var google_client = new GoogleGenAI({
|
|
12
11
|
apiKey: process.env.GOOGLE_API_KEY
|
|
13
12
|
});
|
|
@@ -94,7 +93,6 @@ var billRequest = async ({
|
|
|
94
93
|
}) => {
|
|
95
94
|
const gross = priceForRequest(model, usage, tools);
|
|
96
95
|
const cogs = costForRequest(model, usage, tools);
|
|
97
|
-
const trace = currentTraceId();
|
|
98
96
|
await debit({
|
|
99
97
|
db,
|
|
100
98
|
user,
|
|
@@ -102,7 +100,6 @@ var billRequest = async ({
|
|
|
102
100
|
type: "ai",
|
|
103
101
|
category: "usage",
|
|
104
102
|
source: "user",
|
|
105
|
-
...trace && { trace },
|
|
106
103
|
ai: {
|
|
107
104
|
name: "google",
|
|
108
105
|
model,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// transactions.js
|
|
2
|
+
import { currentTraceId } from "@drawbridge/drawbridge-telemetry";
|
|
2
3
|
var insertTransaction = async ({
|
|
3
4
|
db,
|
|
4
5
|
user,
|
|
@@ -15,6 +16,7 @@ var insertTransaction = async ({
|
|
|
15
16
|
var _a;
|
|
16
17
|
const beforeRaw = (_a = user == null ? void 0 : user.balance) == null ? void 0 : _a[type];
|
|
17
18
|
const balance = typeof beforeRaw === "number" ? { before: beforeRaw, after: beforeRaw + amount } : void 0;
|
|
19
|
+
const trace = currentTraceId();
|
|
18
20
|
await db.create({
|
|
19
21
|
authenticated: user,
|
|
20
22
|
collection: "transaction",
|
|
@@ -26,6 +28,7 @@ var insertTransaction = async ({
|
|
|
26
28
|
source,
|
|
27
29
|
amount,
|
|
28
30
|
...balance && { balance },
|
|
31
|
+
...trace && { trace },
|
|
29
32
|
...rest,
|
|
30
33
|
...stripeInvoiceId && { stripeInvoiceId },
|
|
31
34
|
...stripeEventId && { stripeEventId }
|
package/dist/transactions.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(transactions_exports, {
|
|
|
23
23
|
debit: () => debit
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(transactions_exports);
|
|
26
|
+
var import_drawbridge_telemetry = require("@drawbridge/drawbridge-telemetry");
|
|
26
27
|
var insertTransaction = async ({
|
|
27
28
|
db,
|
|
28
29
|
user,
|
|
@@ -39,6 +40,7 @@ var insertTransaction = async ({
|
|
|
39
40
|
var _a;
|
|
40
41
|
const beforeRaw = (_a = user == null ? void 0 : user.balance) == null ? void 0 : _a[type];
|
|
41
42
|
const balance = typeof beforeRaw === "number" ? { before: beforeRaw, after: beforeRaw + amount } : void 0;
|
|
43
|
+
const trace = (0, import_drawbridge_telemetry.currentTraceId)();
|
|
42
44
|
await db.create({
|
|
43
45
|
authenticated: user,
|
|
44
46
|
collection: "transaction",
|
|
@@ -50,6 +52,7 @@ var insertTransaction = async ({
|
|
|
50
52
|
source,
|
|
51
53
|
amount,
|
|
52
54
|
...balance && { balance },
|
|
55
|
+
...trace && { trace },
|
|
53
56
|
...rest,
|
|
54
57
|
...stripeInvoiceId && { stripeInvoiceId },
|
|
55
58
|
...stripeEventId && { stripeEventId }
|
package/dist/transactions.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { currentTraceId } from '@drawbridge/drawbridge-telemetry';
|
|
2
|
+
|
|
1
3
|
// Ledger transaction insert helpers — no balance writes happen here.
|
|
2
4
|
//
|
|
3
5
|
// User-balance updates are the exclusive job of drawbridge-sync's
|
|
@@ -45,6 +47,14 @@ const insertTransaction = async ({
|
|
|
45
47
|
? { before : beforeRaw, after : beforeRaw + amount }
|
|
46
48
|
: undefined;
|
|
47
49
|
|
|
50
|
+
// Pull the active Sentry trace ID so every credit/debit auto-correlates
|
|
51
|
+
// to the originating HTTP request or BullMQ job — useful for grouping
|
|
52
|
+
// in the user-facing transactions list (multiple AI calls in one
|
|
53
|
+
// preview) and for support ("show me what this signup request did").
|
|
54
|
+
// Returns undefined outside any traced scope; the field is omitted in
|
|
55
|
+
// that case (additionalProperties:false rejects `trace: undefined`).
|
|
56
|
+
const trace = currentTraceId();
|
|
57
|
+
|
|
48
58
|
await db.create({
|
|
49
59
|
authenticated : user,
|
|
50
60
|
collection : 'transaction',
|
|
@@ -56,6 +66,7 @@ const insertTransaction = async ({
|
|
|
56
66
|
source,
|
|
57
67
|
amount,
|
|
58
68
|
...( balance && { balance }),
|
|
69
|
+
...( trace && { trace }),
|
|
59
70
|
...rest,
|
|
60
71
|
...( stripeInvoiceId && { stripeInvoiceId }),
|
|
61
72
|
...( stripeEventId && { stripeEventId })
|
package/dist/transactions.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { currentTraceId } from '@drawbridge/drawbridge-telemetry';
|
|
2
|
+
|
|
1
3
|
// Ledger transaction insert helpers — no balance writes happen here.
|
|
2
4
|
//
|
|
3
5
|
// User-balance updates are the exclusive job of drawbridge-sync's
|
|
@@ -45,6 +47,14 @@ const insertTransaction = async ({
|
|
|
45
47
|
? { before : beforeRaw, after : beforeRaw + amount }
|
|
46
48
|
: undefined;
|
|
47
49
|
|
|
50
|
+
// Pull the active Sentry trace ID so every credit/debit auto-correlates
|
|
51
|
+
// to the originating HTTP request or BullMQ job — useful for grouping
|
|
52
|
+
// in the user-facing transactions list (multiple AI calls in one
|
|
53
|
+
// preview) and for support ("show me what this signup request did").
|
|
54
|
+
// Returns undefined outside any traced scope; the field is omitted in
|
|
55
|
+
// that case (additionalProperties:false rejects `trace: undefined`).
|
|
56
|
+
const trace = currentTraceId();
|
|
57
|
+
|
|
48
58
|
await db.create({
|
|
49
59
|
authenticated : user,
|
|
50
60
|
collection : 'transaction',
|
|
@@ -56,6 +66,7 @@ const insertTransaction = async ({
|
|
|
56
66
|
source,
|
|
57
67
|
amount,
|
|
58
68
|
...( balance && { balance }),
|
|
69
|
+
...( trace && { trace }),
|
|
59
70
|
...rest,
|
|
60
71
|
...( stripeInvoiceId && { stripeInvoiceId }),
|
|
61
72
|
...( stripeEventId && { stripeEventId })
|
package/dist/transactions.js
CHANGED
package/package.json
CHANGED