@firebase/ai 2.5.0-20251028194003 → 2.5.0-canary.0800a8bed
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-public.d.ts +1 -0
- package/dist/ai.d.ts +4 -0
- package/dist/esm/index.esm.js +1 -1
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/src/factory-node.d.ts +19 -0
- package/dist/esm/src/service.d.ts +3 -4
- package/dist/esm/src/types/chrome-adapter.d.ts +5 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +125 -107
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +125 -107
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/factory-node.d.ts +19 -0
- package/dist/src/service.d.ts +3 -4
- package/dist/src/types/chrome-adapter.d.ts +5 -0
- package/package.json +8 -8
package/dist/index.node.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { FirebaseError, Deferred, getModularInstance } from '@firebase/util';
|
|
|
4
4
|
import { Logger } from '@firebase/logger';
|
|
5
5
|
|
|
6
6
|
var name = "@firebase/ai";
|
|
7
|
-
var version = "2.5.0-
|
|
7
|
+
var version = "2.5.0-canary.0800a8bed";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @license
|
|
@@ -34,6 +34,62 @@ const DEFAULT_FETCH_TIMEOUT_MS = 180 * 1000;
|
|
|
34
34
|
*/
|
|
35
35
|
const DEFAULT_HYBRID_IN_CLOUD_MODEL = 'gemini-2.0-flash-lite';
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @license
|
|
39
|
+
* Copyright 2024 Google LLC
|
|
40
|
+
*
|
|
41
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
42
|
+
* you may not use this file except in compliance with the License.
|
|
43
|
+
* You may obtain a copy of the License at
|
|
44
|
+
*
|
|
45
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
46
|
+
*
|
|
47
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
48
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
49
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
50
|
+
* See the License for the specific language governing permissions and
|
|
51
|
+
* limitations under the License.
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Error class for the Firebase AI SDK.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
class AIError extends FirebaseError {
|
|
59
|
+
/**
|
|
60
|
+
* Constructs a new instance of the `AIError` class.
|
|
61
|
+
*
|
|
62
|
+
* @param code - The error code from {@link (AIErrorCode:type)}.
|
|
63
|
+
* @param message - A human-readable message describing the error.
|
|
64
|
+
* @param customErrorData - Optional error data.
|
|
65
|
+
*/
|
|
66
|
+
constructor(code, message, customErrorData) {
|
|
67
|
+
// Match error format used by FirebaseError from ErrorFactory
|
|
68
|
+
const service = AI_TYPE;
|
|
69
|
+
const fullCode = `${service}/${code}`;
|
|
70
|
+
const fullMessage = `${service}: ${message} (${fullCode})`;
|
|
71
|
+
super(code, fullMessage);
|
|
72
|
+
this.code = code;
|
|
73
|
+
this.customErrorData = customErrorData;
|
|
74
|
+
// FirebaseError initializes a stack trace, but it assumes the error is created from the error
|
|
75
|
+
// factory. Since we break this assumption, we set the stack trace to be originating from this
|
|
76
|
+
// constructor.
|
|
77
|
+
// This is only supported in V8.
|
|
78
|
+
if (Error.captureStackTrace) {
|
|
79
|
+
// Allows us to initialize the stack trace without including the constructor itself at the
|
|
80
|
+
// top level of the stack trace.
|
|
81
|
+
Error.captureStackTrace(this, AIError);
|
|
82
|
+
}
|
|
83
|
+
// Allows instanceof AIError in ES5/ES6
|
|
84
|
+
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
85
|
+
// TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
|
|
86
|
+
// which we can now use since we no longer target ES5.
|
|
87
|
+
Object.setPrototypeOf(this, AIError.prototype);
|
|
88
|
+
// Since Error is an interface, we don't inherit toString and so we define it ourselves.
|
|
89
|
+
this.toString = () => fullMessage;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
37
93
|
/**
|
|
38
94
|
* @license
|
|
39
95
|
* Copyright 2024 Google LLC
|
|
@@ -738,6 +794,64 @@ class VertexAIBackend extends Backend {
|
|
|
738
794
|
}
|
|
739
795
|
}
|
|
740
796
|
|
|
797
|
+
/**
|
|
798
|
+
* @license
|
|
799
|
+
* Copyright 2025 Google LLC
|
|
800
|
+
*
|
|
801
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
802
|
+
* you may not use this file except in compliance with the License.
|
|
803
|
+
* You may obtain a copy of the License at
|
|
804
|
+
*
|
|
805
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
806
|
+
*
|
|
807
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
808
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
809
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
810
|
+
* See the License for the specific language governing permissions and
|
|
811
|
+
* limitations under the License.
|
|
812
|
+
*/
|
|
813
|
+
/**
|
|
814
|
+
* Encodes a {@link Backend} into a string that will be used to uniquely identify {@link AI}
|
|
815
|
+
* instances by backend type.
|
|
816
|
+
*
|
|
817
|
+
* @internal
|
|
818
|
+
*/
|
|
819
|
+
function encodeInstanceIdentifier(backend) {
|
|
820
|
+
if (backend instanceof GoogleAIBackend) {
|
|
821
|
+
return `${AI_TYPE}/googleai`;
|
|
822
|
+
}
|
|
823
|
+
else if (backend instanceof VertexAIBackend) {
|
|
824
|
+
return `${AI_TYPE}/vertexai/${backend.location}`;
|
|
825
|
+
}
|
|
826
|
+
else {
|
|
827
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid backend: ${JSON.stringify(backend.backendType)}`);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Decodes an instance identifier string into a {@link Backend}.
|
|
832
|
+
*
|
|
833
|
+
* @internal
|
|
834
|
+
*/
|
|
835
|
+
function decodeInstanceIdentifier(instanceIdentifier) {
|
|
836
|
+
const identifierParts = instanceIdentifier.split('/');
|
|
837
|
+
if (identifierParts[0] !== AI_TYPE) {
|
|
838
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier, unknown prefix '${identifierParts[0]}'`);
|
|
839
|
+
}
|
|
840
|
+
const backendType = identifierParts[1];
|
|
841
|
+
switch (backendType) {
|
|
842
|
+
case 'vertexai':
|
|
843
|
+
const location = identifierParts[2];
|
|
844
|
+
if (!location) {
|
|
845
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier, unknown location '${instanceIdentifier}'`);
|
|
846
|
+
}
|
|
847
|
+
return new VertexAIBackend(location);
|
|
848
|
+
case 'googleai':
|
|
849
|
+
return new GoogleAIBackend();
|
|
850
|
+
default:
|
|
851
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier string: '${instanceIdentifier}'`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
741
855
|
/**
|
|
742
856
|
* @license
|
|
743
857
|
* Copyright 2024 Google LLC
|
|
@@ -781,62 +895,6 @@ class AIService {
|
|
|
781
895
|
}
|
|
782
896
|
}
|
|
783
897
|
|
|
784
|
-
/**
|
|
785
|
-
* @license
|
|
786
|
-
* Copyright 2024 Google LLC
|
|
787
|
-
*
|
|
788
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
789
|
-
* you may not use this file except in compliance with the License.
|
|
790
|
-
* You may obtain a copy of the License at
|
|
791
|
-
*
|
|
792
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
793
|
-
*
|
|
794
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
795
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
796
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
797
|
-
* See the License for the specific language governing permissions and
|
|
798
|
-
* limitations under the License.
|
|
799
|
-
*/
|
|
800
|
-
/**
|
|
801
|
-
* Error class for the Firebase AI SDK.
|
|
802
|
-
*
|
|
803
|
-
* @public
|
|
804
|
-
*/
|
|
805
|
-
class AIError extends FirebaseError {
|
|
806
|
-
/**
|
|
807
|
-
* Constructs a new instance of the `AIError` class.
|
|
808
|
-
*
|
|
809
|
-
* @param code - The error code from {@link (AIErrorCode:type)}.
|
|
810
|
-
* @param message - A human-readable message describing the error.
|
|
811
|
-
* @param customErrorData - Optional error data.
|
|
812
|
-
*/
|
|
813
|
-
constructor(code, message, customErrorData) {
|
|
814
|
-
// Match error format used by FirebaseError from ErrorFactory
|
|
815
|
-
const service = AI_TYPE;
|
|
816
|
-
const fullCode = `${service}/${code}`;
|
|
817
|
-
const fullMessage = `${service}: ${message} (${fullCode})`;
|
|
818
|
-
super(code, fullMessage);
|
|
819
|
-
this.code = code;
|
|
820
|
-
this.customErrorData = customErrorData;
|
|
821
|
-
// FirebaseError initializes a stack trace, but it assumes the error is created from the error
|
|
822
|
-
// factory. Since we break this assumption, we set the stack trace to be originating from this
|
|
823
|
-
// constructor.
|
|
824
|
-
// This is only supported in V8.
|
|
825
|
-
if (Error.captureStackTrace) {
|
|
826
|
-
// Allows us to initialize the stack trace without including the constructor itself at the
|
|
827
|
-
// top level of the stack trace.
|
|
828
|
-
Error.captureStackTrace(this, AIError);
|
|
829
|
-
}
|
|
830
|
-
// Allows instanceof AIError in ES5/ES6
|
|
831
|
-
// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
832
|
-
// TODO(dlarocque): Replace this with `new.target`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
|
|
833
|
-
// which we can now use since we no longer target ES5.
|
|
834
|
-
Object.setPrototypeOf(this, AIError.prototype);
|
|
835
|
-
// Since Error is an interface, we don't inherit toString and so we define it ourselves.
|
|
836
|
-
this.toString = () => fullMessage;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
|
|
840
898
|
/**
|
|
841
899
|
* @license
|
|
842
900
|
* Copyright 2025 Google LLC
|
|
@@ -853,46 +911,16 @@ class AIError extends FirebaseError {
|
|
|
853
911
|
* See the License for the specific language governing permissions and
|
|
854
912
|
* limitations under the License.
|
|
855
913
|
*/
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
*
|
|
860
|
-
* @internal
|
|
861
|
-
*/
|
|
862
|
-
function encodeInstanceIdentifier(backend) {
|
|
863
|
-
if (backend instanceof GoogleAIBackend) {
|
|
864
|
-
return `${AI_TYPE}/googleai`;
|
|
865
|
-
}
|
|
866
|
-
else if (backend instanceof VertexAIBackend) {
|
|
867
|
-
return `${AI_TYPE}/vertexai/${backend.location}`;
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
throw new AIError(AIErrorCode.ERROR, `Invalid backend: ${JSON.stringify(backend.backendType)}`);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Decodes an instance identifier string into a {@link Backend}.
|
|
875
|
-
*
|
|
876
|
-
* @internal
|
|
877
|
-
*/
|
|
878
|
-
function decodeInstanceIdentifier(instanceIdentifier) {
|
|
879
|
-
const identifierParts = instanceIdentifier.split('/');
|
|
880
|
-
if (identifierParts[0] !== AI_TYPE) {
|
|
881
|
-
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier, unknown prefix '${identifierParts[0]}'`);
|
|
882
|
-
}
|
|
883
|
-
const backendType = identifierParts[1];
|
|
884
|
-
switch (backendType) {
|
|
885
|
-
case 'vertexai':
|
|
886
|
-
const location = identifierParts[2];
|
|
887
|
-
if (!location) {
|
|
888
|
-
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier, unknown location '${instanceIdentifier}'`);
|
|
889
|
-
}
|
|
890
|
-
return new VertexAIBackend(location);
|
|
891
|
-
case 'googleai':
|
|
892
|
-
return new GoogleAIBackend();
|
|
893
|
-
default:
|
|
894
|
-
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier string: '${instanceIdentifier}'`);
|
|
914
|
+
function factory(container, { instanceIdentifier }) {
|
|
915
|
+
if (!instanceIdentifier) {
|
|
916
|
+
throw new AIError(AIErrorCode.ERROR, 'AIService instance identifier is undefined.');
|
|
895
917
|
}
|
|
918
|
+
const backend = decodeInstanceIdentifier(instanceIdentifier);
|
|
919
|
+
// getImmediate for FirebaseApp will always succeed
|
|
920
|
+
const app = container.getProvider('app').getImmediate();
|
|
921
|
+
const auth = container.getProvider('auth-internal');
|
|
922
|
+
const appCheckProvider = container.getProvider('app-check-internal');
|
|
923
|
+
return new AIService(app, backend, auth, appCheckProvider);
|
|
896
924
|
}
|
|
897
925
|
|
|
898
926
|
/**
|
|
@@ -3900,17 +3928,7 @@ function getLiveGenerativeModel(ai, modelParams) {
|
|
|
3900
3928
|
* @packageDocumentation
|
|
3901
3929
|
*/
|
|
3902
3930
|
function registerAI() {
|
|
3903
|
-
_registerComponent(new Component(AI_TYPE,
|
|
3904
|
-
if (!instanceIdentifier) {
|
|
3905
|
-
throw new AIError(AIErrorCode.ERROR, 'AIService instance identifier is undefined.');
|
|
3906
|
-
}
|
|
3907
|
-
const backend = decodeInstanceIdentifier(instanceIdentifier);
|
|
3908
|
-
// getImmediate for FirebaseApp will always succeed
|
|
3909
|
-
const app = container.getProvider('app').getImmediate();
|
|
3910
|
-
const auth = container.getProvider('auth-internal');
|
|
3911
|
-
const appCheckProvider = container.getProvider('app-check-internal');
|
|
3912
|
-
return new AIService(app, backend, auth, appCheckProvider);
|
|
3913
|
-
}, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
|
|
3931
|
+
_registerComponent(new Component(AI_TYPE, factory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
|
|
3914
3932
|
registerVersion(name, version, 'node');
|
|
3915
3933
|
// BUILD_TARGET will be replaced by values like esm, cjs, etc during the compilation
|
|
3916
3934
|
registerVersion(name, version, 'esm2020');
|