@drawbridge/drawbridge-utils 0.0.31 → 0.0.33
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 +45 -62
- package/dist/ai.d.cts +46 -68
- package/dist/ai.d.ts +46 -68
- package/dist/ai.js +45 -59
- package/dist/{chunk-6S43OFA7.js → chunk-RW2FJVIV.js} +1 -6
- package/dist/transactions.cjs +1 -6
- package/dist/transactions.d.cts +1 -6
- package/dist/transactions.d.ts +1 -6
- package/dist/transactions.js +1 -1
- package/package.json +1 -1
package/dist/ai.cjs
CHANGED
|
@@ -84,7 +84,6 @@ var circuit = ({
|
|
|
84
84
|
var insertTransaction = async ({
|
|
85
85
|
db,
|
|
86
86
|
user,
|
|
87
|
-
userId,
|
|
88
87
|
type,
|
|
89
88
|
category,
|
|
90
89
|
source,
|
|
@@ -103,7 +102,7 @@ var insertTransaction = async ({
|
|
|
103
102
|
collection: "transaction",
|
|
104
103
|
data: {
|
|
105
104
|
..._id && { _id },
|
|
106
|
-
userId,
|
|
105
|
+
userId: user == null ? void 0 : user.id,
|
|
107
106
|
type,
|
|
108
107
|
category,
|
|
109
108
|
source,
|
|
@@ -119,7 +118,6 @@ var insertTransaction = async ({
|
|
|
119
118
|
var debit = async ({
|
|
120
119
|
db,
|
|
121
120
|
user,
|
|
122
|
-
userId,
|
|
123
121
|
amount,
|
|
124
122
|
type,
|
|
125
123
|
category,
|
|
@@ -141,7 +139,6 @@ var debit = async ({
|
|
|
141
139
|
await insertTransaction({
|
|
142
140
|
db,
|
|
143
141
|
user,
|
|
144
|
-
userId,
|
|
145
142
|
type,
|
|
146
143
|
category,
|
|
147
144
|
source,
|
|
@@ -175,7 +172,7 @@ var cost = {
|
|
|
175
172
|
"gemini-2.5-flash-image": {
|
|
176
173
|
cached: 3,
|
|
177
174
|
input: 30,
|
|
178
|
-
output:
|
|
175
|
+
output: 3e3
|
|
179
176
|
}
|
|
180
177
|
};
|
|
181
178
|
var MARKUP = 1.3;
|
|
@@ -213,8 +210,7 @@ var tokensFromMetadata = (metadata) => ({
|
|
|
213
210
|
});
|
|
214
211
|
var billRequest = async ({
|
|
215
212
|
db,
|
|
216
|
-
|
|
217
|
-
userId,
|
|
213
|
+
user,
|
|
218
214
|
model,
|
|
219
215
|
usage
|
|
220
216
|
}) => {
|
|
@@ -222,8 +218,7 @@ var billRequest = async ({
|
|
|
222
218
|
const cogs = costForRequest(model, usage);
|
|
223
219
|
await debit({
|
|
224
220
|
db,
|
|
225
|
-
|
|
226
|
-
userId,
|
|
221
|
+
user,
|
|
227
222
|
amount: gross,
|
|
228
223
|
type: "ai",
|
|
229
224
|
category: "usage",
|
|
@@ -251,8 +246,7 @@ var google = {
|
|
|
251
246
|
reference = null
|
|
252
247
|
}, {
|
|
253
248
|
db,
|
|
254
|
-
|
|
255
|
-
userId
|
|
249
|
+
user
|
|
256
250
|
}) => {
|
|
257
251
|
var _a, _b, _c, _d, _e, _f;
|
|
258
252
|
const model = models.image;
|
|
@@ -260,68 +254,57 @@ var google = {
|
|
|
260
254
|
...reference ? [{ inlineData: { data: reference.data, mimeType: reference.mimeType } }] : [],
|
|
261
255
|
{ text: prompt.join("\n") }
|
|
262
256
|
];
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
config
|
|
268
|
-
|
|
269
|
-
responseModalities: ["Image"]
|
|
270
|
-
}
|
|
271
|
-
}));
|
|
272
|
-
const content = (_f = (_e = (_d = (_c = (_b = (_a = response == null ? void 0 : response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0]) == null ? void 0 : _e.inlineData) == null ? void 0 : _f.data;
|
|
273
|
-
if (!content) {
|
|
274
|
-
throw new Error("Could not generate from prompt. Please try again with a different prompt.");
|
|
275
|
-
}
|
|
276
|
-
if (userId) {
|
|
277
|
-
await billRequest({
|
|
278
|
-
db,
|
|
279
|
-
authenticated,
|
|
280
|
-
userId,
|
|
281
|
-
model,
|
|
282
|
-
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
283
|
-
});
|
|
257
|
+
const response = await googleCircuit(() => google_client.models.generateContent({
|
|
258
|
+
model,
|
|
259
|
+
contents: { parts },
|
|
260
|
+
config: {
|
|
261
|
+
...config,
|
|
262
|
+
responseModalities: ["Image"]
|
|
284
263
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
264
|
+
}));
|
|
265
|
+
const content = (_f = (_e = (_d = (_c = (_b = (_a = response == null ? void 0 : response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0]) == null ? void 0 : _e.inlineData) == null ? void 0 : _f.data;
|
|
266
|
+
if (!content) {
|
|
267
|
+
throw new Error("Could not generate from prompt. Please try again with a different prompt.");
|
|
288
268
|
}
|
|
269
|
+
if (user == null ? void 0 : user.id) {
|
|
270
|
+
await billRequest({
|
|
271
|
+
db,
|
|
272
|
+
user,
|
|
273
|
+
model,
|
|
274
|
+
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
return { content };
|
|
289
278
|
},
|
|
290
279
|
text: async ({
|
|
291
280
|
config = {},
|
|
292
281
|
prompt = []
|
|
293
282
|
}, {
|
|
294
283
|
db,
|
|
295
|
-
|
|
296
|
-
userId
|
|
284
|
+
user
|
|
297
285
|
}) => {
|
|
298
286
|
const model = models.text;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
config
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
return { content };
|
|
322
|
-
} catch (error) {
|
|
323
|
-
throw new Error((error == null ? void 0 : error.message) || "AI error, please try again");
|
|
287
|
+
const response = await googleCircuit(() => google_client.models.generateContent({
|
|
288
|
+
config: {
|
|
289
|
+
...config,
|
|
290
|
+
responseModalities: ["Text"]
|
|
291
|
+
},
|
|
292
|
+
contents: prompt.join("\n"),
|
|
293
|
+
model
|
|
294
|
+
}));
|
|
295
|
+
const content = response == null ? void 0 : response.text;
|
|
296
|
+
if (!content) {
|
|
297
|
+
throw new Error("Could not generate from prompt. Please try again with a different prompt.");
|
|
298
|
+
}
|
|
299
|
+
if (user == null ? void 0 : user.id) {
|
|
300
|
+
await billRequest({
|
|
301
|
+
db,
|
|
302
|
+
user,
|
|
303
|
+
model,
|
|
304
|
+
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
305
|
+
});
|
|
324
306
|
}
|
|
307
|
+
return { content };
|
|
325
308
|
}
|
|
326
309
|
};
|
|
327
310
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/ai.d.cts
CHANGED
|
@@ -50,7 +50,7 @@ const cost = {
|
|
|
50
50
|
'gemini-2.5-flash-image' : {
|
|
51
51
|
cached : 3,
|
|
52
52
|
input : 30,
|
|
53
|
-
output :
|
|
53
|
+
output : 3000
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -129,8 +129,7 @@ const tokensFromMetadata = ( metadata ) => ({
|
|
|
129
129
|
// is a single $sum: '$ai.net'.
|
|
130
130
|
const billRequest = async ({
|
|
131
131
|
db,
|
|
132
|
-
|
|
133
|
-
userId,
|
|
132
|
+
user,
|
|
134
133
|
model,
|
|
135
134
|
usage
|
|
136
135
|
}) => {
|
|
@@ -140,8 +139,7 @@ const billRequest = async ({
|
|
|
140
139
|
|
|
141
140
|
await debit({
|
|
142
141
|
db,
|
|
143
|
-
|
|
144
|
-
userId,
|
|
142
|
+
user,
|
|
145
143
|
amount : gross,
|
|
146
144
|
type : 'ai',
|
|
147
145
|
category : 'usage',
|
|
@@ -174,8 +172,7 @@ const google = {
|
|
|
174
172
|
},
|
|
175
173
|
{
|
|
176
174
|
db,
|
|
177
|
-
|
|
178
|
-
userId
|
|
175
|
+
user
|
|
179
176
|
}
|
|
180
177
|
) => {
|
|
181
178
|
|
|
@@ -186,45 +183,36 @@ const google = {
|
|
|
186
183
|
{ text : prompt.join( '\n' ) }
|
|
187
184
|
];
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
...config,
|
|
196
|
-
responseModalities : [ 'Image' ]
|
|
197
|
-
}
|
|
198
|
-
}) );
|
|
199
|
-
|
|
200
|
-
const content = response?.candidates?.[ 0 ]?.content?.parts?.[ 0 ]?.inlineData?.data;
|
|
201
|
-
|
|
202
|
-
if( !content ){
|
|
203
|
-
|
|
204
|
-
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
205
|
-
|
|
186
|
+
const response = await googleCircuit( () => google_client.models.generateContent({
|
|
187
|
+
model,
|
|
188
|
+
contents : { parts },
|
|
189
|
+
config : {
|
|
190
|
+
...config,
|
|
191
|
+
responseModalities : [ 'Image' ]
|
|
206
192
|
}
|
|
193
|
+
}) );
|
|
207
194
|
|
|
208
|
-
|
|
195
|
+
const content = response?.candidates?.[ 0 ]?.content?.parts?.[ 0 ]?.inlineData?.data;
|
|
209
196
|
|
|
210
|
-
|
|
211
|
-
db,
|
|
212
|
-
authenticated,
|
|
213
|
-
userId,
|
|
214
|
-
model,
|
|
215
|
-
usage : tokensFromMetadata( response?.usageMetadata )
|
|
216
|
-
});
|
|
197
|
+
if( !content ){
|
|
217
198
|
|
|
218
|
-
|
|
199
|
+
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
219
200
|
|
|
220
|
-
|
|
201
|
+
}
|
|
221
202
|
|
|
222
|
-
|
|
203
|
+
if( user?.id ){
|
|
223
204
|
|
|
224
|
-
|
|
205
|
+
await billRequest({
|
|
206
|
+
db,
|
|
207
|
+
user,
|
|
208
|
+
model,
|
|
209
|
+
usage : tokensFromMetadata( response?.usageMetadata )
|
|
210
|
+
});
|
|
225
211
|
|
|
226
212
|
}
|
|
227
213
|
|
|
214
|
+
return { content };
|
|
215
|
+
|
|
228
216
|
},
|
|
229
217
|
|
|
230
218
|
text : async (
|
|
@@ -234,52 +222,42 @@ const google = {
|
|
|
234
222
|
},
|
|
235
223
|
{
|
|
236
224
|
db,
|
|
237
|
-
|
|
238
|
-
userId
|
|
225
|
+
user
|
|
239
226
|
}
|
|
240
227
|
) => {
|
|
241
228
|
|
|
242
229
|
const model = models.text;
|
|
243
230
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
model
|
|
253
|
-
}) );
|
|
254
|
-
|
|
255
|
-
const content = response?.text;
|
|
256
|
-
|
|
257
|
-
if( !content ){
|
|
258
|
-
|
|
259
|
-
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
260
|
-
|
|
261
|
-
}
|
|
231
|
+
const response = await googleCircuit( () => google_client.models.generateContent({
|
|
232
|
+
config : {
|
|
233
|
+
...config,
|
|
234
|
+
responseModalities : [ 'Text' ]
|
|
235
|
+
},
|
|
236
|
+
contents : prompt.join( '\n' ),
|
|
237
|
+
model
|
|
238
|
+
}) );
|
|
262
239
|
|
|
263
|
-
|
|
240
|
+
const content = response?.text;
|
|
264
241
|
|
|
265
|
-
|
|
266
|
-
db,
|
|
267
|
-
authenticated,
|
|
268
|
-
userId,
|
|
269
|
-
model,
|
|
270
|
-
usage : tokensFromMetadata( response?.usageMetadata )
|
|
271
|
-
});
|
|
242
|
+
if( !content ){
|
|
272
243
|
|
|
273
|
-
|
|
244
|
+
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
274
245
|
|
|
275
|
-
|
|
246
|
+
}
|
|
276
247
|
|
|
277
|
-
|
|
248
|
+
if( user?.id ){
|
|
278
249
|
|
|
279
|
-
|
|
250
|
+
await billRequest({
|
|
251
|
+
db,
|
|
252
|
+
user,
|
|
253
|
+
model,
|
|
254
|
+
usage : tokensFromMetadata( response?.usageMetadata )
|
|
255
|
+
});
|
|
280
256
|
|
|
281
257
|
}
|
|
282
258
|
|
|
259
|
+
return { content };
|
|
260
|
+
|
|
283
261
|
}
|
|
284
262
|
|
|
285
263
|
};
|
package/dist/ai.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ const cost = {
|
|
|
50
50
|
'gemini-2.5-flash-image' : {
|
|
51
51
|
cached : 3,
|
|
52
52
|
input : 30,
|
|
53
|
-
output :
|
|
53
|
+
output : 3000
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -129,8 +129,7 @@ const tokensFromMetadata = ( metadata ) => ({
|
|
|
129
129
|
// is a single $sum: '$ai.net'.
|
|
130
130
|
const billRequest = async ({
|
|
131
131
|
db,
|
|
132
|
-
|
|
133
|
-
userId,
|
|
132
|
+
user,
|
|
134
133
|
model,
|
|
135
134
|
usage
|
|
136
135
|
}) => {
|
|
@@ -140,8 +139,7 @@ const billRequest = async ({
|
|
|
140
139
|
|
|
141
140
|
await debit({
|
|
142
141
|
db,
|
|
143
|
-
|
|
144
|
-
userId,
|
|
142
|
+
user,
|
|
145
143
|
amount : gross,
|
|
146
144
|
type : 'ai',
|
|
147
145
|
category : 'usage',
|
|
@@ -174,8 +172,7 @@ const google = {
|
|
|
174
172
|
},
|
|
175
173
|
{
|
|
176
174
|
db,
|
|
177
|
-
|
|
178
|
-
userId
|
|
175
|
+
user
|
|
179
176
|
}
|
|
180
177
|
) => {
|
|
181
178
|
|
|
@@ -186,45 +183,36 @@ const google = {
|
|
|
186
183
|
{ text : prompt.join( '\n' ) }
|
|
187
184
|
];
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
...config,
|
|
196
|
-
responseModalities : [ 'Image' ]
|
|
197
|
-
}
|
|
198
|
-
}) );
|
|
199
|
-
|
|
200
|
-
const content = response?.candidates?.[ 0 ]?.content?.parts?.[ 0 ]?.inlineData?.data;
|
|
201
|
-
|
|
202
|
-
if( !content ){
|
|
203
|
-
|
|
204
|
-
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
205
|
-
|
|
186
|
+
const response = await googleCircuit( () => google_client.models.generateContent({
|
|
187
|
+
model,
|
|
188
|
+
contents : { parts },
|
|
189
|
+
config : {
|
|
190
|
+
...config,
|
|
191
|
+
responseModalities : [ 'Image' ]
|
|
206
192
|
}
|
|
193
|
+
}) );
|
|
207
194
|
|
|
208
|
-
|
|
195
|
+
const content = response?.candidates?.[ 0 ]?.content?.parts?.[ 0 ]?.inlineData?.data;
|
|
209
196
|
|
|
210
|
-
|
|
211
|
-
db,
|
|
212
|
-
authenticated,
|
|
213
|
-
userId,
|
|
214
|
-
model,
|
|
215
|
-
usage : tokensFromMetadata( response?.usageMetadata )
|
|
216
|
-
});
|
|
197
|
+
if( !content ){
|
|
217
198
|
|
|
218
|
-
|
|
199
|
+
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
219
200
|
|
|
220
|
-
|
|
201
|
+
}
|
|
221
202
|
|
|
222
|
-
|
|
203
|
+
if( user?.id ){
|
|
223
204
|
|
|
224
|
-
|
|
205
|
+
await billRequest({
|
|
206
|
+
db,
|
|
207
|
+
user,
|
|
208
|
+
model,
|
|
209
|
+
usage : tokensFromMetadata( response?.usageMetadata )
|
|
210
|
+
});
|
|
225
211
|
|
|
226
212
|
}
|
|
227
213
|
|
|
214
|
+
return { content };
|
|
215
|
+
|
|
228
216
|
},
|
|
229
217
|
|
|
230
218
|
text : async (
|
|
@@ -234,52 +222,42 @@ const google = {
|
|
|
234
222
|
},
|
|
235
223
|
{
|
|
236
224
|
db,
|
|
237
|
-
|
|
238
|
-
userId
|
|
225
|
+
user
|
|
239
226
|
}
|
|
240
227
|
) => {
|
|
241
228
|
|
|
242
229
|
const model = models.text;
|
|
243
230
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
model
|
|
253
|
-
}) );
|
|
254
|
-
|
|
255
|
-
const content = response?.text;
|
|
256
|
-
|
|
257
|
-
if( !content ){
|
|
258
|
-
|
|
259
|
-
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
260
|
-
|
|
261
|
-
}
|
|
231
|
+
const response = await googleCircuit( () => google_client.models.generateContent({
|
|
232
|
+
config : {
|
|
233
|
+
...config,
|
|
234
|
+
responseModalities : [ 'Text' ]
|
|
235
|
+
},
|
|
236
|
+
contents : prompt.join( '\n' ),
|
|
237
|
+
model
|
|
238
|
+
}) );
|
|
262
239
|
|
|
263
|
-
|
|
240
|
+
const content = response?.text;
|
|
264
241
|
|
|
265
|
-
|
|
266
|
-
db,
|
|
267
|
-
authenticated,
|
|
268
|
-
userId,
|
|
269
|
-
model,
|
|
270
|
-
usage : tokensFromMetadata( response?.usageMetadata )
|
|
271
|
-
});
|
|
242
|
+
if( !content ){
|
|
272
243
|
|
|
273
|
-
|
|
244
|
+
throw new Error( 'Could not generate from prompt. Please try again with a different prompt.' );
|
|
274
245
|
|
|
275
|
-
|
|
246
|
+
}
|
|
276
247
|
|
|
277
|
-
|
|
248
|
+
if( user?.id ){
|
|
278
249
|
|
|
279
|
-
|
|
250
|
+
await billRequest({
|
|
251
|
+
db,
|
|
252
|
+
user,
|
|
253
|
+
model,
|
|
254
|
+
usage : tokensFromMetadata( response?.usageMetadata )
|
|
255
|
+
});
|
|
280
256
|
|
|
281
257
|
}
|
|
282
258
|
|
|
259
|
+
return { content };
|
|
260
|
+
|
|
283
261
|
}
|
|
284
262
|
|
|
285
263
|
};
|
package/dist/ai.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debit
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RW2FJVIV.js";
|
|
4
4
|
import {
|
|
5
5
|
circuit
|
|
6
6
|
} from "./chunk-6HH36OK6.js";
|
|
@@ -28,7 +28,7 @@ var cost = {
|
|
|
28
28
|
"gemini-2.5-flash-image": {
|
|
29
29
|
cached: 3,
|
|
30
30
|
input: 30,
|
|
31
|
-
output:
|
|
31
|
+
output: 3e3
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
var MARKUP = 1.3;
|
|
@@ -66,8 +66,7 @@ var tokensFromMetadata = (metadata) => ({
|
|
|
66
66
|
});
|
|
67
67
|
var billRequest = async ({
|
|
68
68
|
db,
|
|
69
|
-
|
|
70
|
-
userId,
|
|
69
|
+
user,
|
|
71
70
|
model,
|
|
72
71
|
usage
|
|
73
72
|
}) => {
|
|
@@ -75,8 +74,7 @@ var billRequest = async ({
|
|
|
75
74
|
const cogs = costForRequest(model, usage);
|
|
76
75
|
await debit({
|
|
77
76
|
db,
|
|
78
|
-
|
|
79
|
-
userId,
|
|
77
|
+
user,
|
|
80
78
|
amount: gross,
|
|
81
79
|
type: "ai",
|
|
82
80
|
category: "usage",
|
|
@@ -104,8 +102,7 @@ var google = {
|
|
|
104
102
|
reference = null
|
|
105
103
|
}, {
|
|
106
104
|
db,
|
|
107
|
-
|
|
108
|
-
userId
|
|
105
|
+
user
|
|
109
106
|
}) => {
|
|
110
107
|
var _a, _b, _c, _d, _e, _f;
|
|
111
108
|
const model = models.image;
|
|
@@ -113,68 +110,57 @@ var google = {
|
|
|
113
110
|
...reference ? [{ inlineData: { data: reference.data, mimeType: reference.mimeType } }] : [],
|
|
114
111
|
{ text: prompt.join("\n") }
|
|
115
112
|
];
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
config
|
|
121
|
-
|
|
122
|
-
responseModalities: ["Image"]
|
|
123
|
-
}
|
|
124
|
-
}));
|
|
125
|
-
const content = (_f = (_e = (_d = (_c = (_b = (_a = response == null ? void 0 : response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0]) == null ? void 0 : _e.inlineData) == null ? void 0 : _f.data;
|
|
126
|
-
if (!content) {
|
|
127
|
-
throw new Error("Could not generate from prompt. Please try again with a different prompt.");
|
|
128
|
-
}
|
|
129
|
-
if (userId) {
|
|
130
|
-
await billRequest({
|
|
131
|
-
db,
|
|
132
|
-
authenticated,
|
|
133
|
-
userId,
|
|
134
|
-
model,
|
|
135
|
-
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
136
|
-
});
|
|
113
|
+
const response = await googleCircuit(() => google_client.models.generateContent({
|
|
114
|
+
model,
|
|
115
|
+
contents: { parts },
|
|
116
|
+
config: {
|
|
117
|
+
...config,
|
|
118
|
+
responseModalities: ["Image"]
|
|
137
119
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
}));
|
|
121
|
+
const content = (_f = (_e = (_d = (_c = (_b = (_a = response == null ? void 0 : response.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0]) == null ? void 0 : _e.inlineData) == null ? void 0 : _f.data;
|
|
122
|
+
if (!content) {
|
|
123
|
+
throw new Error("Could not generate from prompt. Please try again with a different prompt.");
|
|
124
|
+
}
|
|
125
|
+
if (user == null ? void 0 : user.id) {
|
|
126
|
+
await billRequest({
|
|
127
|
+
db,
|
|
128
|
+
user,
|
|
129
|
+
model,
|
|
130
|
+
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
131
|
+
});
|
|
141
132
|
}
|
|
133
|
+
return { content };
|
|
142
134
|
},
|
|
143
135
|
text: async ({
|
|
144
136
|
config = {},
|
|
145
137
|
prompt = []
|
|
146
138
|
}, {
|
|
147
139
|
db,
|
|
148
|
-
|
|
149
|
-
userId
|
|
140
|
+
user
|
|
150
141
|
}) => {
|
|
151
142
|
const model = models.text;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
config
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return { content };
|
|
175
|
-
} catch (error) {
|
|
176
|
-
throw new Error((error == null ? void 0 : error.message) || "AI error, please try again");
|
|
143
|
+
const response = await googleCircuit(() => google_client.models.generateContent({
|
|
144
|
+
config: {
|
|
145
|
+
...config,
|
|
146
|
+
responseModalities: ["Text"]
|
|
147
|
+
},
|
|
148
|
+
contents: prompt.join("\n"),
|
|
149
|
+
model
|
|
150
|
+
}));
|
|
151
|
+
const content = response == null ? void 0 : response.text;
|
|
152
|
+
if (!content) {
|
|
153
|
+
throw new Error("Could not generate from prompt. Please try again with a different prompt.");
|
|
154
|
+
}
|
|
155
|
+
if (user == null ? void 0 : user.id) {
|
|
156
|
+
await billRequest({
|
|
157
|
+
db,
|
|
158
|
+
user,
|
|
159
|
+
model,
|
|
160
|
+
usage: tokensFromMetadata(response == null ? void 0 : response.usageMetadata)
|
|
161
|
+
});
|
|
177
162
|
}
|
|
163
|
+
return { content };
|
|
178
164
|
}
|
|
179
165
|
};
|
|
180
166
|
export {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
var insertTransaction = async ({
|
|
3
3
|
db,
|
|
4
4
|
user,
|
|
5
|
-
userId,
|
|
6
5
|
type,
|
|
7
6
|
category,
|
|
8
7
|
source,
|
|
@@ -21,7 +20,7 @@ var insertTransaction = async ({
|
|
|
21
20
|
collection: "transaction",
|
|
22
21
|
data: {
|
|
23
22
|
..._id && { _id },
|
|
24
|
-
userId,
|
|
23
|
+
userId: user == null ? void 0 : user.id,
|
|
25
24
|
type,
|
|
26
25
|
category,
|
|
27
26
|
source,
|
|
@@ -37,7 +36,6 @@ var insertTransaction = async ({
|
|
|
37
36
|
var credit = async ({
|
|
38
37
|
db,
|
|
39
38
|
user,
|
|
40
|
-
userId,
|
|
41
39
|
amount,
|
|
42
40
|
type,
|
|
43
41
|
category,
|
|
@@ -60,7 +58,6 @@ var credit = async ({
|
|
|
60
58
|
await insertTransaction({
|
|
61
59
|
db,
|
|
62
60
|
user,
|
|
63
|
-
userId,
|
|
64
61
|
type,
|
|
65
62
|
category,
|
|
66
63
|
source,
|
|
@@ -75,7 +72,6 @@ var credit = async ({
|
|
|
75
72
|
var debit = async ({
|
|
76
73
|
db,
|
|
77
74
|
user,
|
|
78
|
-
userId,
|
|
79
75
|
amount,
|
|
80
76
|
type,
|
|
81
77
|
category,
|
|
@@ -97,7 +93,6 @@ var debit = async ({
|
|
|
97
93
|
await insertTransaction({
|
|
98
94
|
db,
|
|
99
95
|
user,
|
|
100
|
-
userId,
|
|
101
96
|
type,
|
|
102
97
|
category,
|
|
103
98
|
source,
|
package/dist/transactions.cjs
CHANGED
|
@@ -26,7 +26,6 @@ module.exports = __toCommonJS(transactions_exports);
|
|
|
26
26
|
var insertTransaction = async ({
|
|
27
27
|
db,
|
|
28
28
|
user,
|
|
29
|
-
userId,
|
|
30
29
|
type,
|
|
31
30
|
category,
|
|
32
31
|
source,
|
|
@@ -45,7 +44,7 @@ var insertTransaction = async ({
|
|
|
45
44
|
collection: "transaction",
|
|
46
45
|
data: {
|
|
47
46
|
..._id && { _id },
|
|
48
|
-
userId,
|
|
47
|
+
userId: user == null ? void 0 : user.id,
|
|
49
48
|
type,
|
|
50
49
|
category,
|
|
51
50
|
source,
|
|
@@ -61,7 +60,6 @@ var insertTransaction = async ({
|
|
|
61
60
|
var credit = async ({
|
|
62
61
|
db,
|
|
63
62
|
user,
|
|
64
|
-
userId,
|
|
65
63
|
amount,
|
|
66
64
|
type,
|
|
67
65
|
category,
|
|
@@ -84,7 +82,6 @@ var credit = async ({
|
|
|
84
82
|
await insertTransaction({
|
|
85
83
|
db,
|
|
86
84
|
user,
|
|
87
|
-
userId,
|
|
88
85
|
type,
|
|
89
86
|
category,
|
|
90
87
|
source,
|
|
@@ -99,7 +96,6 @@ var credit = async ({
|
|
|
99
96
|
var debit = async ({
|
|
100
97
|
db,
|
|
101
98
|
user,
|
|
102
|
-
userId,
|
|
103
99
|
amount,
|
|
104
100
|
type,
|
|
105
101
|
category,
|
|
@@ -121,7 +117,6 @@ var debit = async ({
|
|
|
121
117
|
await insertTransaction({
|
|
122
118
|
db,
|
|
123
119
|
user,
|
|
124
|
-
userId,
|
|
125
120
|
type,
|
|
126
121
|
category,
|
|
127
122
|
source,
|
package/dist/transactions.d.cts
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
const insertTransaction = async ({
|
|
30
30
|
db,
|
|
31
31
|
user,
|
|
32
|
-
userId,
|
|
33
32
|
type,
|
|
34
33
|
category,
|
|
35
34
|
source,
|
|
@@ -51,7 +50,7 @@ const insertTransaction = async ({
|
|
|
51
50
|
collection : 'transaction',
|
|
52
51
|
data : {
|
|
53
52
|
...( _id && { _id }),
|
|
54
|
-
userId,
|
|
53
|
+
userId : user?.id,
|
|
55
54
|
type,
|
|
56
55
|
category,
|
|
57
56
|
source,
|
|
@@ -73,7 +72,6 @@ const insertTransaction = async ({
|
|
|
73
72
|
const credit = async ({
|
|
74
73
|
db,
|
|
75
74
|
user,
|
|
76
|
-
userId,
|
|
77
75
|
amount,
|
|
78
76
|
type,
|
|
79
77
|
category,
|
|
@@ -106,7 +104,6 @@ const credit = async ({
|
|
|
106
104
|
await insertTransaction({
|
|
107
105
|
db,
|
|
108
106
|
user,
|
|
109
|
-
userId,
|
|
110
107
|
type,
|
|
111
108
|
category,
|
|
112
109
|
source,
|
|
@@ -134,7 +131,6 @@ const credit = async ({
|
|
|
134
131
|
const debit = async ({
|
|
135
132
|
db,
|
|
136
133
|
user,
|
|
137
|
-
userId,
|
|
138
134
|
amount,
|
|
139
135
|
type,
|
|
140
136
|
category,
|
|
@@ -166,7 +162,6 @@ const debit = async ({
|
|
|
166
162
|
await insertTransaction({
|
|
167
163
|
db,
|
|
168
164
|
user,
|
|
169
|
-
userId,
|
|
170
165
|
type,
|
|
171
166
|
category,
|
|
172
167
|
source,
|
package/dist/transactions.d.ts
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
const insertTransaction = async ({
|
|
30
30
|
db,
|
|
31
31
|
user,
|
|
32
|
-
userId,
|
|
33
32
|
type,
|
|
34
33
|
category,
|
|
35
34
|
source,
|
|
@@ -51,7 +50,7 @@ const insertTransaction = async ({
|
|
|
51
50
|
collection : 'transaction',
|
|
52
51
|
data : {
|
|
53
52
|
...( _id && { _id }),
|
|
54
|
-
userId,
|
|
53
|
+
userId : user?.id,
|
|
55
54
|
type,
|
|
56
55
|
category,
|
|
57
56
|
source,
|
|
@@ -73,7 +72,6 @@ const insertTransaction = async ({
|
|
|
73
72
|
const credit = async ({
|
|
74
73
|
db,
|
|
75
74
|
user,
|
|
76
|
-
userId,
|
|
77
75
|
amount,
|
|
78
76
|
type,
|
|
79
77
|
category,
|
|
@@ -106,7 +104,6 @@ const credit = async ({
|
|
|
106
104
|
await insertTransaction({
|
|
107
105
|
db,
|
|
108
106
|
user,
|
|
109
|
-
userId,
|
|
110
107
|
type,
|
|
111
108
|
category,
|
|
112
109
|
source,
|
|
@@ -134,7 +131,6 @@ const credit = async ({
|
|
|
134
131
|
const debit = async ({
|
|
135
132
|
db,
|
|
136
133
|
user,
|
|
137
|
-
userId,
|
|
138
134
|
amount,
|
|
139
135
|
type,
|
|
140
136
|
category,
|
|
@@ -166,7 +162,6 @@ const debit = async ({
|
|
|
166
162
|
await insertTransaction({
|
|
167
163
|
db,
|
|
168
164
|
user,
|
|
169
|
-
userId,
|
|
170
165
|
type,
|
|
171
166
|
category,
|
|
172
167
|
source,
|
package/dist/transactions.js
CHANGED
package/package.json
CHANGED