@digitalaidseattle/firebase 1.0.8 → 1.0.10
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/declarations/src/FirestoreService.d.ts +1 -1
- package/dist/declarations/src/GeminiService.d.ts +25 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/digitalaidseattle-firebase.cjs.dev.js +84 -1
- package/dist/digitalaidseattle-firebase.cjs.prod.js +84 -1
- package/dist/digitalaidseattle-firebase.esm.js +84 -2
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@ declare class FirestoreService<T extends Entity> implements EntityService<T> {
|
|
|
7
7
|
getById(id: string, select?: string, mapper?: (json: any) => T): Promise<T>;
|
|
8
8
|
batchInsert(entities: T[], select?: string, mapper?: (json: any) => T, user?: User): Promise<T[]>;
|
|
9
9
|
insert(entity: T, select?: string, mapper?: (json: any) => T, user?: User): Promise<T>;
|
|
10
|
-
update(entityId: Identifier, updatedFields: T
|
|
10
|
+
update(entityId: Identifier, updatedFields: Partial<T>, select?: string, mapper?: (json: any) => T, user?: User): Promise<T>;
|
|
11
11
|
delete(entityId: Identifier): Promise<void>;
|
|
12
12
|
}
|
|
13
13
|
export { FirestoreService };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Institution AI Service
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* Provision Firebase application in Google Cloud
|
|
6
|
+
* <ol>
|
|
7
|
+
* <li>Go to the Google Cloud Console.</li>
|
|
8
|
+
* <li>Select an existing project.</li>
|
|
9
|
+
* <li>Navigate to the "APIs & Services" page.</li>
|
|
10
|
+
* <li>Click on "Credential".</li>
|
|
11
|
+
* <li>Edit API (the key should match the API key in the .env file).</li>
|
|
12
|
+
* <li>Enable the "Generative Language API" and "Firebase AI Logic API" restrictions.</li>
|
|
13
|
+
* </ol>
|
|
14
|
+
*/
|
|
15
|
+
import { AiService } from "@digitalaidseattle/core";
|
|
16
|
+
import { AI } from "firebase/ai";
|
|
17
|
+
declare class GeminiService implements AiService {
|
|
18
|
+
ai: AI;
|
|
19
|
+
constructor(modelType?: string);
|
|
20
|
+
getModels(): string[];
|
|
21
|
+
calcTokenCount(model: string, prompt: string): Promise<number>;
|
|
22
|
+
generateContent(model: string, prompt: string): Promise<any>;
|
|
23
|
+
generateParameterizedContent(model: string, prompt: string, schemaParams: string[]): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
export { GeminiService };
|
|
@@ -12,6 +12,8 @@ var app = require('firebase/app');
|
|
|
12
12
|
var storage = require('firebase/storage');
|
|
13
13
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
14
14
|
var firestore = require('firebase/firestore');
|
|
15
|
+
var firebase = require('@digitalaidseattle/firebase');
|
|
16
|
+
var ai = require('firebase/ai');
|
|
15
17
|
|
|
16
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
17
19
|
|
|
@@ -89,7 +91,8 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
89
91
|
case 2:
|
|
90
92
|
_context3.prev = 2;
|
|
91
93
|
_t = _context3["catch"](0);
|
|
92
|
-
console.error(_t);
|
|
94
|
+
console.error('signInWithGoogle', _t);
|
|
95
|
+
throw _t;
|
|
93
96
|
case 3:
|
|
94
97
|
case "end":
|
|
95
98
|
return _context3.stop();
|
|
@@ -408,7 +411,87 @@ var FirestoreService = /*#__PURE__*/function () {
|
|
|
408
411
|
}]);
|
|
409
412
|
}();
|
|
410
413
|
|
|
414
|
+
var GeminiService = /*#__PURE__*/function () {
|
|
415
|
+
function GeminiService(modelType) {
|
|
416
|
+
_classCallCheck(this, GeminiService);
|
|
417
|
+
this.ai = ai.getAI(firebase.firebaseClient, {
|
|
418
|
+
backend: new ai.GoogleAIBackend()
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return _createClass(GeminiService, [{
|
|
422
|
+
key: "getModels",
|
|
423
|
+
value: function getModels() {
|
|
424
|
+
return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
|
|
425
|
+
}
|
|
426
|
+
}, {
|
|
427
|
+
key: "calcTokenCount",
|
|
428
|
+
value: function calcTokenCount(model, prompt) {
|
|
429
|
+
return ai.getGenerativeModel(this.ai, {
|
|
430
|
+
model: model
|
|
431
|
+
}).countTokens(prompt).then(function (response) {
|
|
432
|
+
return response.totalTokens;
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Wrap in an async function so you can use await
|
|
437
|
+
}, {
|
|
438
|
+
key: "generateContent",
|
|
439
|
+
value: function generateContent(model, prompt) {
|
|
440
|
+
// To generate text output, call generateContent with the text input
|
|
441
|
+
console.log('generateContent', model, prompt);
|
|
442
|
+
return ai.getGenerativeModel(this.ai, {
|
|
443
|
+
model: model
|
|
444
|
+
}).generateContent(prompt).then(function (result) {
|
|
445
|
+
return result.response.text();
|
|
446
|
+
})["catch"](function (error) {
|
|
447
|
+
console.error("Error querying AI: ", error);
|
|
448
|
+
throw new Error("Failed to query AI: " + error.message);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Wrap in an async function so you can use await
|
|
453
|
+
}, {
|
|
454
|
+
key: "generateParameterizedContent",
|
|
455
|
+
value: function generateParameterizedContent(model, prompt, schemaParams) {
|
|
456
|
+
// Provide a JSON schema object using a standard format.
|
|
457
|
+
// Later, pass this schema object into `responseSchema` in the generation config.
|
|
458
|
+
var schema = ai.Schema.object({
|
|
459
|
+
properties: {
|
|
460
|
+
characters: ai.Schema.array({
|
|
461
|
+
items: ai.Schema.object({
|
|
462
|
+
properties: Object.fromEntries(schemaParams.map(function (field) {
|
|
463
|
+
return [field, ai.Schema.string()];
|
|
464
|
+
}))
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Create a `GenerativeModel` instance with a model that supports your use case
|
|
471
|
+
var jModel = ai.getGenerativeModel(this.ai, {
|
|
472
|
+
model: model,
|
|
473
|
+
// In the generation config, set the `responseMimeType` to `application/json`
|
|
474
|
+
// and pass the JSON schema object into `responseSchema`.
|
|
475
|
+
generationConfig: {
|
|
476
|
+
responseMimeType: "application/json",
|
|
477
|
+
responseSchema: schema
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// To generate text output, call generateContent with the text input
|
|
482
|
+
return jModel.generateContent(prompt).then(function (result) {
|
|
483
|
+
var content = result.response.text();
|
|
484
|
+
return JSON.parse(content).characters[0];
|
|
485
|
+
})["catch"](function (error) {
|
|
486
|
+
console.error("Error querying AI: ", error);
|
|
487
|
+
throw new Error("Failed to query AI: " + error.message);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}]);
|
|
491
|
+
}();
|
|
492
|
+
|
|
411
493
|
exports.FirebaseAuthService = FirebaseAuthService;
|
|
412
494
|
exports.FirebaseStorageService = FirebaseStorageService;
|
|
413
495
|
exports.FirestoreService = FirestoreService;
|
|
496
|
+
exports.GeminiService = GeminiService;
|
|
414
497
|
exports.firebaseClient = firebaseClient;
|
|
@@ -12,6 +12,8 @@ var app = require('firebase/app');
|
|
|
12
12
|
var storage = require('firebase/storage');
|
|
13
13
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
14
14
|
var firestore = require('firebase/firestore');
|
|
15
|
+
var firebase = require('@digitalaidseattle/firebase');
|
|
16
|
+
var ai = require('firebase/ai');
|
|
15
17
|
|
|
16
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
17
19
|
|
|
@@ -89,7 +91,8 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
89
91
|
case 2:
|
|
90
92
|
_context3.prev = 2;
|
|
91
93
|
_t = _context3["catch"](0);
|
|
92
|
-
console.error(_t);
|
|
94
|
+
console.error('signInWithGoogle', _t);
|
|
95
|
+
throw _t;
|
|
93
96
|
case 3:
|
|
94
97
|
case "end":
|
|
95
98
|
return _context3.stop();
|
|
@@ -408,7 +411,87 @@ var FirestoreService = /*#__PURE__*/function () {
|
|
|
408
411
|
}]);
|
|
409
412
|
}();
|
|
410
413
|
|
|
414
|
+
var GeminiService = /*#__PURE__*/function () {
|
|
415
|
+
function GeminiService(modelType) {
|
|
416
|
+
_classCallCheck(this, GeminiService);
|
|
417
|
+
this.ai = ai.getAI(firebase.firebaseClient, {
|
|
418
|
+
backend: new ai.GoogleAIBackend()
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return _createClass(GeminiService, [{
|
|
422
|
+
key: "getModels",
|
|
423
|
+
value: function getModels() {
|
|
424
|
+
return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
|
|
425
|
+
}
|
|
426
|
+
}, {
|
|
427
|
+
key: "calcTokenCount",
|
|
428
|
+
value: function calcTokenCount(model, prompt) {
|
|
429
|
+
return ai.getGenerativeModel(this.ai, {
|
|
430
|
+
model: model
|
|
431
|
+
}).countTokens(prompt).then(function (response) {
|
|
432
|
+
return response.totalTokens;
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Wrap in an async function so you can use await
|
|
437
|
+
}, {
|
|
438
|
+
key: "generateContent",
|
|
439
|
+
value: function generateContent(model, prompt) {
|
|
440
|
+
// To generate text output, call generateContent with the text input
|
|
441
|
+
console.log('generateContent', model, prompt);
|
|
442
|
+
return ai.getGenerativeModel(this.ai, {
|
|
443
|
+
model: model
|
|
444
|
+
}).generateContent(prompt).then(function (result) {
|
|
445
|
+
return result.response.text();
|
|
446
|
+
})["catch"](function (error) {
|
|
447
|
+
console.error("Error querying AI: ", error);
|
|
448
|
+
throw new Error("Failed to query AI: " + error.message);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Wrap in an async function so you can use await
|
|
453
|
+
}, {
|
|
454
|
+
key: "generateParameterizedContent",
|
|
455
|
+
value: function generateParameterizedContent(model, prompt, schemaParams) {
|
|
456
|
+
// Provide a JSON schema object using a standard format.
|
|
457
|
+
// Later, pass this schema object into `responseSchema` in the generation config.
|
|
458
|
+
var schema = ai.Schema.object({
|
|
459
|
+
properties: {
|
|
460
|
+
characters: ai.Schema.array({
|
|
461
|
+
items: ai.Schema.object({
|
|
462
|
+
properties: Object.fromEntries(schemaParams.map(function (field) {
|
|
463
|
+
return [field, ai.Schema.string()];
|
|
464
|
+
}))
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Create a `GenerativeModel` instance with a model that supports your use case
|
|
471
|
+
var jModel = ai.getGenerativeModel(this.ai, {
|
|
472
|
+
model: model,
|
|
473
|
+
// In the generation config, set the `responseMimeType` to `application/json`
|
|
474
|
+
// and pass the JSON schema object into `responseSchema`.
|
|
475
|
+
generationConfig: {
|
|
476
|
+
responseMimeType: "application/json",
|
|
477
|
+
responseSchema: schema
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// To generate text output, call generateContent with the text input
|
|
482
|
+
return jModel.generateContent(prompt).then(function (result) {
|
|
483
|
+
var content = result.response.text();
|
|
484
|
+
return JSON.parse(content).characters[0];
|
|
485
|
+
})["catch"](function (error) {
|
|
486
|
+
console.error("Error querying AI: ", error);
|
|
487
|
+
throw new Error("Failed to query AI: " + error.message);
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}]);
|
|
491
|
+
}();
|
|
492
|
+
|
|
411
493
|
exports.FirebaseAuthService = FirebaseAuthService;
|
|
412
494
|
exports.FirebaseStorageService = FirebaseStorageService;
|
|
413
495
|
exports.FirestoreService = FirestoreService;
|
|
496
|
+
exports.GeminiService = GeminiService;
|
|
414
497
|
exports.firebaseClient = firebaseClient;
|
|
@@ -8,6 +8,8 @@ import { initializeApp } from 'firebase/app';
|
|
|
8
8
|
import { ref, getDownloadURL, getStorage, getBytes } from 'firebase/storage';
|
|
9
9
|
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
10
10
|
import { getDocs, collection, getDoc, doc, addDoc, updateDoc, deleteDoc, getFirestore } from 'firebase/firestore';
|
|
11
|
+
import { firebaseClient as firebaseClient$1 } from '@digitalaidseattle/firebase';
|
|
12
|
+
import { getGenerativeModel, Schema, getAI, GoogleAIBackend } from 'firebase/ai';
|
|
11
13
|
|
|
12
14
|
var firebaseConfig = {
|
|
13
15
|
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
|
|
@@ -81,7 +83,8 @@ var FirebaseAuthService = /*#__PURE__*/function () {
|
|
|
81
83
|
case 2:
|
|
82
84
|
_context3.prev = 2;
|
|
83
85
|
_t = _context3["catch"](0);
|
|
84
|
-
console.error(_t);
|
|
86
|
+
console.error('signInWithGoogle', _t);
|
|
87
|
+
throw _t;
|
|
85
88
|
case 3:
|
|
86
89
|
case "end":
|
|
87
90
|
return _context3.stop();
|
|
@@ -400,4 +403,83 @@ var FirestoreService = /*#__PURE__*/function () {
|
|
|
400
403
|
}]);
|
|
401
404
|
}();
|
|
402
405
|
|
|
403
|
-
|
|
406
|
+
var GeminiService = /*#__PURE__*/function () {
|
|
407
|
+
function GeminiService(modelType) {
|
|
408
|
+
_classCallCheck(this, GeminiService);
|
|
409
|
+
this.ai = getAI(firebaseClient$1, {
|
|
410
|
+
backend: new GoogleAIBackend()
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
return _createClass(GeminiService, [{
|
|
414
|
+
key: "getModels",
|
|
415
|
+
value: function getModels() {
|
|
416
|
+
return ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.5-flash-lite"];
|
|
417
|
+
}
|
|
418
|
+
}, {
|
|
419
|
+
key: "calcTokenCount",
|
|
420
|
+
value: function calcTokenCount(model, prompt) {
|
|
421
|
+
return getGenerativeModel(this.ai, {
|
|
422
|
+
model: model
|
|
423
|
+
}).countTokens(prompt).then(function (response) {
|
|
424
|
+
return response.totalTokens;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Wrap in an async function so you can use await
|
|
429
|
+
}, {
|
|
430
|
+
key: "generateContent",
|
|
431
|
+
value: function generateContent(model, prompt) {
|
|
432
|
+
// To generate text output, call generateContent with the text input
|
|
433
|
+
console.log('generateContent', model, prompt);
|
|
434
|
+
return getGenerativeModel(this.ai, {
|
|
435
|
+
model: model
|
|
436
|
+
}).generateContent(prompt).then(function (result) {
|
|
437
|
+
return result.response.text();
|
|
438
|
+
})["catch"](function (error) {
|
|
439
|
+
console.error("Error querying AI: ", error);
|
|
440
|
+
throw new Error("Failed to query AI: " + error.message);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Wrap in an async function so you can use await
|
|
445
|
+
}, {
|
|
446
|
+
key: "generateParameterizedContent",
|
|
447
|
+
value: function generateParameterizedContent(model, prompt, schemaParams) {
|
|
448
|
+
// Provide a JSON schema object using a standard format.
|
|
449
|
+
// Later, pass this schema object into `responseSchema` in the generation config.
|
|
450
|
+
var schema = Schema.object({
|
|
451
|
+
properties: {
|
|
452
|
+
characters: Schema.array({
|
|
453
|
+
items: Schema.object({
|
|
454
|
+
properties: Object.fromEntries(schemaParams.map(function (field) {
|
|
455
|
+
return [field, Schema.string()];
|
|
456
|
+
}))
|
|
457
|
+
})
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// Create a `GenerativeModel` instance with a model that supports your use case
|
|
463
|
+
var jModel = getGenerativeModel(this.ai, {
|
|
464
|
+
model: model,
|
|
465
|
+
// In the generation config, set the `responseMimeType` to `application/json`
|
|
466
|
+
// and pass the JSON schema object into `responseSchema`.
|
|
467
|
+
generationConfig: {
|
|
468
|
+
responseMimeType: "application/json",
|
|
469
|
+
responseSchema: schema
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// To generate text output, call generateContent with the text input
|
|
474
|
+
return jModel.generateContent(prompt).then(function (result) {
|
|
475
|
+
var content = result.response.text();
|
|
476
|
+
return JSON.parse(content).characters[0];
|
|
477
|
+
})["catch"](function (error) {
|
|
478
|
+
console.error("Error querying AI: ", error);
|
|
479
|
+
throw new Error("Failed to query AI: " + error.message);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}]);
|
|
483
|
+
}();
|
|
484
|
+
|
|
485
|
+
export { FirebaseAuthService, FirebaseStorageService, FirestoreService, GeminiService, firebaseClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalaidseattle/firebase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Wrapper for firebase that works with DAS Component library",
|
|
5
5
|
"repository": "null//github.com/null/github.com/tree/master/packages/firebase",
|
|
6
6
|
"main": "dist/digitalaidseattle-firebase.cjs.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"types": "dist/declarations/src/index.d.ts",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@babel/runtime": "^7.25.0",
|
|
11
|
-
"@digitalaidseattle/core": "1.0.
|
|
11
|
+
"@digitalaidseattle/core": "1.0.16",
|
|
12
12
|
"firebase": "^11.2.0",
|
|
13
13
|
"react": "^18.3.1",
|
|
14
14
|
"uuid": "^11.0.5"
|