firebase-functions 7.2.2 → 7.2.3
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/lib/common/providers/tasks.js +1 -0
- package/lib/common/utilities/path-pattern.js +12 -3
- package/lib/esm/common/providers/tasks.mjs +1 -0
- package/lib/esm/common/utilities/path-pattern.mjs +11 -3
- package/lib/esm/v2/compat.mjs +19 -59
- package/lib/esm/v2/index.doc.mjs +1 -1
- package/lib/esm/v2/index.mjs +2 -2
- package/lib/esm/v2/providers/ai/index.mjs +187 -0
- package/lib/esm/v2/providers/ai/types/gemini/v1beta/index.mjs +6 -0
- package/lib/esm/v2/providers/ai/types/vertex/v1beta1/index.mjs +6 -0
- package/lib/esm/v2/providers/database.mjs +35 -2
- package/lib/esm/v2/providers/firestore.mjs +38 -6
- package/lib/esm/v2/providers/https.mjs +10 -2
- package/lib/esm/v2/providers/pubsub.mjs +41 -2
- package/lib/esm/v2/providers/remoteConfig.mjs +18 -1
- package/lib/esm/v2/providers/scheduler.mjs +12 -0
- package/lib/esm/v2/providers/storage.mjs +24 -1
- package/lib/v2/compat.d.ts +14 -12
- package/lib/v2/compat.js +19 -58
- package/lib/v2/index.d.ts +0 -1
- package/lib/v2/index.doc.js +1 -1
- package/lib/v2/index.js +2 -2
- package/lib/v2/providers/ai/index.d.ts +53 -0
- package/lib/v2/providers/ai/index.js +198 -0
- package/lib/v2/providers/ai/types/gemini/v1beta/index.d.ts +817 -0
- package/lib/v2/providers/ai/types/gemini/v1beta/index.js +8 -0
- package/lib/v2/providers/ai/types/vertex/v1beta1/index.d.ts +850 -0
- package/lib/v2/providers/ai/types/vertex/v1beta1/index.js +8 -0
- package/lib/v2/providers/database.d.ts +61 -4
- package/lib/v2/providers/database.js +35 -2
- package/lib/v2/providers/firestore.d.ts +127 -0
- package/lib/v2/providers/firestore.js +38 -5
- package/lib/v2/providers/https.d.ts +2 -2
- package/lib/v2/providers/https.js +10 -2
- package/lib/v2/providers/pubsub.d.ts +18 -4
- package/lib/v2/providers/pubsub.js +41 -2
- package/lib/v2/providers/remoteConfig.d.ts +16 -0
- package/lib/v2/providers/remoteConfig.js +18 -1
- package/lib/v2/providers/scheduler.d.ts +21 -0
- package/lib/v2/providers/scheduler.js +12 -0
- package/lib/v2/providers/storage.d.ts +127 -0
- package/lib/v2/providers/storage.js +24 -1
- package/lib/v2/providers/tasks.d.ts +20 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { __export } from "../../_virtual/rolldown_runtime.mjs";
|
|
|
2
2
|
import { initV2Endpoint } from "../../runtime/manifest.mjs";
|
|
3
3
|
import { withInit } from "../../common/onInit.mjs";
|
|
4
4
|
import { wrapTraceContext } from "../trace.mjs";
|
|
5
|
+
import { addV1Compat } from "../compat.mjs";
|
|
5
6
|
import { getGlobalOptions, optionsToEndpoint } from "../options.mjs";
|
|
6
7
|
|
|
7
8
|
//#region src/v2/providers/remoteConfig.ts
|
|
@@ -26,7 +27,23 @@ function onConfigUpdated(optsOrHandler, handler) {
|
|
|
26
27
|
const baseOpts = optionsToEndpoint(getGlobalOptions());
|
|
27
28
|
const specificOpts = optionsToEndpoint(optsOrHandler);
|
|
28
29
|
const func = wrapTraceContext(withInit((raw) => {
|
|
29
|
-
|
|
30
|
+
const event = raw;
|
|
31
|
+
const patchedEvent = addV1Compat(event, {
|
|
32
|
+
context: () => {
|
|
33
|
+
return {
|
|
34
|
+
eventId: event.id,
|
|
35
|
+
timestamp: event.time,
|
|
36
|
+
eventType: "google.firebase.remoteconfig.update",
|
|
37
|
+
resource: {
|
|
38
|
+
service: "firebaseremoteconfig.googleapis.com",
|
|
39
|
+
name: event.subject || ""
|
|
40
|
+
},
|
|
41
|
+
params: {}
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
version: () => event.data
|
|
45
|
+
});
|
|
46
|
+
return handler(patchedEvent);
|
|
30
47
|
}));
|
|
31
48
|
func.run = handler;
|
|
32
49
|
const ep = {
|
|
@@ -46,6 +46,18 @@ function onSchedule(args, handler) {
|
|
|
46
46
|
jobName: req.header("X-CloudScheduler-JobName") || undefined,
|
|
47
47
|
scheduleTime: req.header("X-CloudScheduler-ScheduleTime") || new Date().toISOString()
|
|
48
48
|
};
|
|
49
|
+
const jobName = event.jobName || "unknown-job";
|
|
50
|
+
const v1Context = {
|
|
51
|
+
eventId: jobName,
|
|
52
|
+
timestamp: event.scheduleTime,
|
|
53
|
+
eventType: "google.pubsub.topic.publish",
|
|
54
|
+
resource: {
|
|
55
|
+
service: "pubsub.googleapis.com",
|
|
56
|
+
name: `projects/${process.env.GCLOUD_PROJECT}/topics/${jobName}`
|
|
57
|
+
},
|
|
58
|
+
params: {}
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(event, "context", { get: () => v1Context });
|
|
49
61
|
try {
|
|
50
62
|
await handler(event);
|
|
51
63
|
res.status(200).send();
|
|
@@ -4,6 +4,7 @@ import { firebaseConfig } from "../../common/config.mjs";
|
|
|
4
4
|
import { copyIfPresent } from "../../common/encoding.mjs";
|
|
5
5
|
import { withInit } from "../../common/onInit.mjs";
|
|
6
6
|
import { wrapTraceContext } from "../trace.mjs";
|
|
7
|
+
import { addV1Compat } from "../compat.mjs";
|
|
7
8
|
import { getGlobalOptions, optionsToEndpoint, optionsToTriggerAnnotations } from "../options.mjs";
|
|
8
9
|
|
|
9
10
|
//#region src/v2/providers/storage.ts
|
|
@@ -86,7 +87,29 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
|
86
87
|
}
|
|
87
88
|
const [opts, bucket] = getOptsAndBucket(bucketOrOptsOrHandler);
|
|
88
89
|
const func = (raw) => {
|
|
89
|
-
|
|
90
|
+
const storageEvent = raw;
|
|
91
|
+
const event = addV1Compat(storageEvent, {
|
|
92
|
+
context: () => {
|
|
93
|
+
const bucketName = storageEvent.bucket;
|
|
94
|
+
return {
|
|
95
|
+
eventId: storageEvent.id,
|
|
96
|
+
timestamp: storageEvent.time,
|
|
97
|
+
eventType: {
|
|
98
|
+
[archivedEvent]: "google.storage.object.archive",
|
|
99
|
+
[finalizedEvent]: "google.storage.object.finalize",
|
|
100
|
+
[deletedEvent]: "google.storage.object.delete",
|
|
101
|
+
[metadataUpdatedEvent]: "google.storage.object.metadataUpdate"
|
|
102
|
+
}[eventType] || eventType,
|
|
103
|
+
resource: {
|
|
104
|
+
service: "storage.googleapis.com",
|
|
105
|
+
name: `projects/_/buckets/${bucketName}/objects/${storageEvent.data.name}#${storageEvent.data.generation}`
|
|
106
|
+
},
|
|
107
|
+
params: {}
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
object: () => storageEvent.data
|
|
111
|
+
});
|
|
112
|
+
return wrapTraceContext(withInit(handler))(event);
|
|
90
113
|
};
|
|
91
114
|
func.run = handler;
|
|
92
115
|
Object.defineProperty(func, "__trigger", { get: () => {
|
package/lib/v2/compat.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { CloudEvent } from "./core";
|
|
2
|
-
import { MessagePublishedData, V1PubSubMessage } from "./providers/pubsub";
|
|
3
2
|
import { EventContext as V1EventContext } from "../v1";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
export type V1Compat<DataName extends string, DataType, ContextType = V1EventContext> = {
|
|
4
|
+
[K in DataName]: DataType;
|
|
5
|
+
} & {
|
|
6
|
+
context: ContextType;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Patches a CloudEvent with V1 compatibility properties via getters.
|
|
10
|
+
* This function ensures idempotency by using a Symbol to mark already patched events.
|
|
11
|
+
* @param event The CloudEvent to patch.
|
|
12
|
+
* @param getters A map of getters to attach to the event object.
|
|
13
|
+
* @returns The patched CloudEvent with V1 compatibility properties.
|
|
14
|
+
*/
|
|
15
|
+
export declare function addV1Compat<T extends CloudEvent<unknown>, U extends Record<string, () => any>>(event: T, getters: U): T & {
|
|
16
|
+
[K in keyof U]: ReturnType<U[K]>;
|
|
13
17
|
};
|
|
14
|
-
export declare function patchV1Compat<T>(event: CloudEvent<MessagePublishedData<T>>): PubSubCloudEvent<T>;
|
|
15
|
-
export declare function patchV1Compat<T>(event: CloudEvent<T>): CloudEvent<T>;
|
package/lib/v2/compat.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
2
1
|
|
|
3
2
|
//#region src/v2/compat.ts
|
|
4
3
|
const V1_COMPAT_PATCHED = Symbol.for("firebase.functions.v2.compat");
|
|
5
4
|
/**
|
|
6
|
-
* Patches a CloudEvent with V1 compatibility properties
|
|
5
|
+
* Patches a CloudEvent with V1 compatibility properties via getters.
|
|
7
6
|
* This function ensures idempotency by using a Symbol to mark already patched events.
|
|
8
|
-
* @param event The CloudEvent to
|
|
9
|
-
* @
|
|
7
|
+
* @param event The CloudEvent to patch.
|
|
8
|
+
* @param getters A map of getters to attach to the event object.
|
|
9
|
+
* @returns The patched CloudEvent with V1 compatibility properties.
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
11
|
+
function addV1Compat(event, getters) {
|
|
12
12
|
if (event[V1_COMPAT_PATCHED]) {
|
|
13
13
|
return event;
|
|
14
14
|
}
|
|
@@ -18,60 +18,21 @@ function patchV1Compat(event) {
|
|
|
18
18
|
writable: false,
|
|
19
19
|
configurable: false
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
get: () => {
|
|
34
|
-
const service = "pubsub.googleapis.com";
|
|
35
|
-
const sourcePrefix = `//${service}/`;
|
|
36
|
-
return {
|
|
37
|
-
eventId: v2Message.messageId,
|
|
38
|
-
timestamp: v2Message.publishTime,
|
|
39
|
-
eventType: "google.pubsub.topic.publish",
|
|
40
|
-
resource: {
|
|
41
|
-
service,
|
|
42
|
-
name: event.source?.startsWith(sourcePrefix) ? event.source.substring(sourcePrefix.length) : event.source || ""
|
|
43
|
-
},
|
|
44
|
-
params: {}
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
configurable: true,
|
|
48
|
-
enumerable: true
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(pubsubEvent, "message", {
|
|
51
|
-
get: () => {
|
|
52
|
-
const baseV1Message = {
|
|
53
|
-
data: v2Message.data,
|
|
54
|
-
messageId: v2Message.messageId,
|
|
55
|
-
publishTime: v2Message.publishTime,
|
|
56
|
-
attributes: v2Message.attributes,
|
|
57
|
-
...v2Message.orderingKey && { orderingKey: v2Message.orderingKey }
|
|
58
|
-
};
|
|
59
|
-
return {
|
|
60
|
-
...baseV1Message,
|
|
61
|
-
get json() {
|
|
62
|
-
return v2Message.json;
|
|
63
|
-
},
|
|
64
|
-
toJSON: () => baseV1Message
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
configurable: true,
|
|
68
|
-
enumerable: true
|
|
69
|
-
});
|
|
70
|
-
return pubsubEvent;
|
|
71
|
-
}
|
|
72
|
-
default: return event;
|
|
21
|
+
const memo = {};
|
|
22
|
+
for (const [key, getter] of Object.entries(getters)) {
|
|
23
|
+
Object.defineProperty(event, key, {
|
|
24
|
+
get: () => {
|
|
25
|
+
if (!Object.prototype.hasOwnProperty.call(memo, key)) {
|
|
26
|
+
memo[key] = getter();
|
|
27
|
+
}
|
|
28
|
+
return memo[key];
|
|
29
|
+
},
|
|
30
|
+
configurable: true,
|
|
31
|
+
enumerable: true
|
|
32
|
+
});
|
|
73
33
|
}
|
|
34
|
+
return event;
|
|
74
35
|
}
|
|
75
36
|
|
|
76
37
|
//#endregion
|
|
77
|
-
exports.
|
|
38
|
+
exports.addV1Compat = addV1Compat;
|
package/lib/v2/index.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export { onInit } from "./core";
|
|
|
26
26
|
export type { CloudFunction, CloudEvent, ParamsOf } from "./core";
|
|
27
27
|
export { Change } from "../common/change";
|
|
28
28
|
export { traceContext } from "../common/trace";
|
|
29
|
-
export type { PubSubCloudEvent } from "./compat";
|
|
30
29
|
import * as params from "../params";
|
|
31
30
|
export { params };
|
|
32
31
|
export { config } from "../v1/config";
|
package/lib/v2/index.doc.js
CHANGED
|
@@ -5,13 +5,13 @@ const require_common_change = require('../common/change.js');
|
|
|
5
5
|
const require_common_onInit = require('../common/onInit.js');
|
|
6
6
|
const require_v1_config = require('../v1/config.js');
|
|
7
7
|
const require_v2_options = require('./options.js');
|
|
8
|
-
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
9
8
|
const require_v2_dataconnect_doc = require('./dataconnect.doc.js');
|
|
10
9
|
const require_v2_providers_alerts_index = require('./providers/alerts/index.js');
|
|
11
10
|
const require_v2_providers_database = require('./providers/database.js');
|
|
12
11
|
const require_v2_providers_eventarc = require('./providers/eventarc.js');
|
|
13
12
|
const require_v2_providers_https = require('./providers/https.js');
|
|
14
13
|
const require_v2_providers_identity = require('./providers/identity.js');
|
|
14
|
+
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
15
15
|
const require_v2_providers_scheduler = require('./providers/scheduler.js');
|
|
16
16
|
const require_v2_providers_storage = require('./providers/storage.js');
|
|
17
17
|
const require_v2_providers_tasks = require('./providers/tasks.js');
|
package/lib/v2/index.js
CHANGED
|
@@ -5,15 +5,15 @@ const require_common_app = require('../common/app.js');
|
|
|
5
5
|
const require_common_change = require('../common/change.js');
|
|
6
6
|
const require_common_onInit = require('../common/onInit.js');
|
|
7
7
|
const require_v1_config = require('../v1/config.js');
|
|
8
|
-
const require_v2_options = require('./options.js');
|
|
9
|
-
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
10
8
|
require('./core.js');
|
|
9
|
+
const require_v2_options = require('./options.js');
|
|
11
10
|
const require_v2_providers_dataconnect_index = require('./providers/dataconnect/index.js');
|
|
12
11
|
const require_v2_providers_alerts_index = require('./providers/alerts/index.js');
|
|
13
12
|
const require_v2_providers_database = require('./providers/database.js');
|
|
14
13
|
const require_v2_providers_eventarc = require('./providers/eventarc.js');
|
|
15
14
|
const require_v2_providers_https = require('./providers/https.js');
|
|
16
15
|
const require_v2_providers_identity = require('./providers/identity.js');
|
|
16
|
+
const require_v2_providers_pubsub = require('./providers/pubsub.js');
|
|
17
17
|
const require_v2_providers_scheduler = require('./providers/scheduler.js');
|
|
18
18
|
const require_v2_providers_storage = require('./providers/storage.js');
|
|
19
19
|
const require_v2_providers_tasks = require('./providers/tasks.js');
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CloudEvent } from "../../core";
|
|
2
|
+
import { HttpsFunction, HttpsError, FunctionsErrorCode } from "../https";
|
|
3
|
+
import { EventHandlerOptions } from "../../options";
|
|
4
|
+
import { Expression } from "../../../params";
|
|
5
|
+
import { ResetValue } from "../../../common/options";
|
|
6
|
+
export { HttpsError };
|
|
7
|
+
export declare const rpcCodeMap: Record<FunctionsErrorCode, number>;
|
|
8
|
+
import { GenerateContentRequest as VertexV1Beta1GenerateContentRequest, GenerateContentResponse as VertexV1Beta1GenerateContentResponse } from "./types/vertex/v1beta1";
|
|
9
|
+
import { GenerateContentRequest as GeminiV1BetaGenerateContentRequest, GenerateContentResponse as GeminiV1BetaGenerateContentResponse } from "./types/gemini/v1beta";
|
|
10
|
+
export { VertexV1Beta1GenerateContentRequest, VertexV1Beta1GenerateContentResponse, GeminiV1BetaGenerateContentRequest, GeminiV1BetaGenerateContentResponse, };
|
|
11
|
+
type MultipleLocationsIf<Allowed extends boolean> = Allowed extends true ? string[] : never;
|
|
12
|
+
export interface WebhookOptions<Regional extends boolean = false> extends Omit<EventHandlerOptions, "location"> {
|
|
13
|
+
location?: string | Expression<string> | MultipleLocationsIf<Regional> | ResetValue;
|
|
14
|
+
regionalWebhook?: Regional;
|
|
15
|
+
}
|
|
16
|
+
export interface PromptTemplateInfo {
|
|
17
|
+
templateName?: string;
|
|
18
|
+
}
|
|
19
|
+
export type AuthType = "app_user" | "unauthenticated" | "unknown";
|
|
20
|
+
export declare const beforeGenerateEventType = "google.firebase.ailogic.v1.beforeGenerate";
|
|
21
|
+
export declare const afterGenerateEventType = "google.firebase.ailogic.v1.afterGenerate";
|
|
22
|
+
export type AnyValidAIRequest = GeminiV1BetaGenerateContentRequest | VertexV1Beta1GenerateContentRequest;
|
|
23
|
+
export type AnyValidAIResponse = GeminiV1BetaGenerateContentResponse | VertexV1Beta1GenerateContentResponse;
|
|
24
|
+
export declare const geminiV1Beta = "google.ai.generativelanguage.v1beta";
|
|
25
|
+
export declare const vertexV1Beta1 = "google.cloud.aiplatform.v1beta1";
|
|
26
|
+
export type SupportedAPI = typeof geminiV1Beta | typeof vertexV1Beta1;
|
|
27
|
+
export type AIRequest<API> = string extends API ? AnyValidAIRequest : API extends typeof geminiV1Beta ? GeminiV1BetaGenerateContentRequest : API extends typeof vertexV1Beta1 ? VertexV1Beta1GenerateContentRequest : never;
|
|
28
|
+
export type AIResponse<API> = string extends API ? AnyValidAIResponse : API extends typeof geminiV1Beta ? GeminiV1BetaGenerateContentResponse : API extends typeof vertexV1Beta1 ? VertexV1Beta1GenerateContentResponse : never;
|
|
29
|
+
export interface BeforeGenerateContentData<API extends string = string> {
|
|
30
|
+
model: string;
|
|
31
|
+
template?: PromptTemplateInfo;
|
|
32
|
+
api: SupportedAPI;
|
|
33
|
+
request: AIRequest<API>;
|
|
34
|
+
}
|
|
35
|
+
export interface AfterGenerateContentData<API extends string = string> extends BeforeGenerateContentData<API> {
|
|
36
|
+
response: AIResponse<API>;
|
|
37
|
+
}
|
|
38
|
+
export interface AIBlockingEvent<T = any> extends CloudEvent<T> {
|
|
39
|
+
authType: AuthType;
|
|
40
|
+
authId?: string;
|
|
41
|
+
authClaims?: any;
|
|
42
|
+
resourceName?: string;
|
|
43
|
+
appId?: string;
|
|
44
|
+
displayName?: string;
|
|
45
|
+
androidPackageName?: string;
|
|
46
|
+
iosBundleId?: string;
|
|
47
|
+
}
|
|
48
|
+
type MaybeAsync<T> = T | Promise<T>;
|
|
49
|
+
export type BlockingFunction = HttpsFunction;
|
|
50
|
+
export declare function beforeGenerateContent(callback: (event: AIBlockingEvent<BeforeGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIRequest>>): BlockingFunction;
|
|
51
|
+
export declare function beforeGenerateContent<Regional extends boolean = false>(options: WebhookOptions<Regional>, callback: (event: AIBlockingEvent<BeforeGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIRequest>>): BlockingFunction;
|
|
52
|
+
export declare function afterGenerateContent(callback: (event: AIBlockingEvent<AfterGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIResponse>>): BlockingFunction;
|
|
53
|
+
export declare function afterGenerateContent<Regional extends boolean = false>(options: WebhookOptions<Regional>, callback: (event: AIBlockingEvent<AfterGenerateContentData>) => MaybeAsync<void | Partial<AnyValidAIResponse>>): BlockingFunction;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
const require_logger_index = require('../../../logger/index.js');
|
|
2
|
+
const require_runtime_manifest = require('../../../runtime/manifest.js');
|
|
3
|
+
const require_common_onInit = require('../../../common/onInit.js');
|
|
4
|
+
const require_common_providers_https = require('../../../common/providers/https.js');
|
|
5
|
+
const require_v2_trace = require('../../trace.js');
|
|
6
|
+
const require_v2_options = require('../../options.js');
|
|
7
|
+
require('../https.js');
|
|
8
|
+
const require_v2_providers_ai_types_vertex_v1beta1_index = require('./types/vertex/v1beta1/index.js');
|
|
9
|
+
const require_v2_providers_ai_types_gemini_v1beta_index = require('./types/gemini/v1beta/index.js');
|
|
10
|
+
|
|
11
|
+
//#region src/v2/providers/ai/index.ts
|
|
12
|
+
const rpcCodeMap = {
|
|
13
|
+
ok: 0,
|
|
14
|
+
cancelled: 1,
|
|
15
|
+
unknown: 2,
|
|
16
|
+
"invalid-argument": 3,
|
|
17
|
+
"deadline-exceeded": 4,
|
|
18
|
+
"not-found": 5,
|
|
19
|
+
"already-exists": 6,
|
|
20
|
+
"permission-denied": 7,
|
|
21
|
+
unauthenticated: 16,
|
|
22
|
+
"resource-exhausted": 8,
|
|
23
|
+
"failed-precondition": 9,
|
|
24
|
+
aborted: 10,
|
|
25
|
+
"out-of-range": 11,
|
|
26
|
+
unimplemented: 12,
|
|
27
|
+
internal: 13,
|
|
28
|
+
unavailable: 14,
|
|
29
|
+
"data-loss": 15
|
|
30
|
+
};
|
|
31
|
+
const beforeGenerateEventType = "google.firebase.ailogic.v1.beforeGenerate";
|
|
32
|
+
const afterGenerateEventType = "google.firebase.ailogic.v1.afterGenerate";
|
|
33
|
+
const geminiV1Beta = "google.ai.generativelanguage.v1beta";
|
|
34
|
+
const vertexV1Beta1 = "google.cloud.aiplatform.v1beta1";
|
|
35
|
+
function beforeGenerateContent(optsOrCb, cb) {
|
|
36
|
+
let opts;
|
|
37
|
+
let handler;
|
|
38
|
+
if (arguments.length === 1) {
|
|
39
|
+
opts = {};
|
|
40
|
+
handler = optsOrCb;
|
|
41
|
+
} else {
|
|
42
|
+
opts = optsOrCb;
|
|
43
|
+
handler = cb;
|
|
44
|
+
}
|
|
45
|
+
let func = async (req, res) => {
|
|
46
|
+
try {
|
|
47
|
+
let event = req.body;
|
|
48
|
+
if (Buffer.isBuffer(event)) {
|
|
49
|
+
try {
|
|
50
|
+
event = JSON.parse(event.toString("utf-8"));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
require_logger_index.error("Invalid JSON body (Buffer):", e);
|
|
53
|
+
throw new require_common_providers_https.HttpsError("invalid-argument", "Invalid JSON body", e);
|
|
54
|
+
}
|
|
55
|
+
} else if (typeof event === "string") {
|
|
56
|
+
try {
|
|
57
|
+
event = JSON.parse(event);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
require_logger_index.error("Invalid JSON body (String):", e);
|
|
60
|
+
throw new require_common_providers_https.HttpsError("invalid-argument", "Invalid JSON body", e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const parsedEvent = event;
|
|
64
|
+
const result = await handler(parsedEvent);
|
|
65
|
+
const responseBody = result || {};
|
|
66
|
+
if (typeof responseBody === "object") {
|
|
67
|
+
const api = parsedEvent.data?.api;
|
|
68
|
+
if (api === geminiV1Beta) {
|
|
69
|
+
responseBody["@type"] = require_v2_providers_ai_types_gemini_v1beta_index.requestTypeName;
|
|
70
|
+
} else if (api === vertexV1Beta1) {
|
|
71
|
+
responseBody["@type"] = require_v2_providers_ai_types_vertex_v1beta1_index.requestTypeName;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
res.status(200).send(responseBody);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
require_logger_index.error("Unhandled error:", err);
|
|
77
|
+
if (err instanceof require_common_providers_https.HttpsError) {
|
|
78
|
+
res.status(500).send({
|
|
79
|
+
code: rpcCodeMap[err.code] || 13,
|
|
80
|
+
message: err.message
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
res.status(500).send({
|
|
84
|
+
code: 13,
|
|
85
|
+
message: "Internal error."
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
func.run = handler;
|
|
91
|
+
func = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(func));
|
|
92
|
+
const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
|
|
93
|
+
const specificOpts = require_v2_options.optionsToEndpoint(opts);
|
|
94
|
+
func.__endpoint = {
|
|
95
|
+
...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
|
|
96
|
+
platform: "gcfv2",
|
|
97
|
+
...baseOpts,
|
|
98
|
+
...specificOpts,
|
|
99
|
+
labels: {
|
|
100
|
+
...baseOpts?.labels,
|
|
101
|
+
...specificOpts?.labels
|
|
102
|
+
},
|
|
103
|
+
blockingTrigger: {
|
|
104
|
+
eventType: beforeGenerateEventType,
|
|
105
|
+
options: { regionalWebhook: opts.regionalWebhook }
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return func;
|
|
109
|
+
}
|
|
110
|
+
function afterGenerateContent(optsOrCb, cb) {
|
|
111
|
+
let opts;
|
|
112
|
+
let handler;
|
|
113
|
+
if (arguments.length === 1) {
|
|
114
|
+
opts = {};
|
|
115
|
+
handler = optsOrCb;
|
|
116
|
+
} else {
|
|
117
|
+
opts = optsOrCb;
|
|
118
|
+
handler = cb;
|
|
119
|
+
}
|
|
120
|
+
let func = async (req, res) => {
|
|
121
|
+
try {
|
|
122
|
+
let event = req.body;
|
|
123
|
+
if (Buffer.isBuffer(event)) {
|
|
124
|
+
try {
|
|
125
|
+
event = JSON.parse(event.toString("utf-8"));
|
|
126
|
+
} catch (e) {
|
|
127
|
+
require_logger_index.error("Invalid JSON body (Buffer):", e);
|
|
128
|
+
throw new require_common_providers_https.HttpsError("invalid-argument", "Invalid JSON body", e);
|
|
129
|
+
}
|
|
130
|
+
} else if (typeof event === "string") {
|
|
131
|
+
try {
|
|
132
|
+
event = JSON.parse(event);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
require_logger_index.error("Invalid JSON body (String):", e);
|
|
135
|
+
throw new require_common_providers_https.HttpsError("invalid-argument", "Invalid JSON body", e);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const parsedEvent = event;
|
|
139
|
+
const result = await handler(parsedEvent);
|
|
140
|
+
const responseBody = result || {};
|
|
141
|
+
if (typeof responseBody === "object") {
|
|
142
|
+
const api = parsedEvent.data?.api;
|
|
143
|
+
if (api === geminiV1Beta) {
|
|
144
|
+
responseBody["@type"] = require_v2_providers_ai_types_gemini_v1beta_index.responseTypeName;
|
|
145
|
+
} else if (api === vertexV1Beta1) {
|
|
146
|
+
responseBody["@type"] = require_v2_providers_ai_types_vertex_v1beta1_index.responseTypeName;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
res.status(200).send(responseBody);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
require_logger_index.error("Unhandled error:", err);
|
|
152
|
+
if (err instanceof require_common_providers_https.HttpsError) {
|
|
153
|
+
res.status(500).send({
|
|
154
|
+
code: rpcCodeMap[err.code] || 13,
|
|
155
|
+
message: err.message
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
res.status(500).send({
|
|
159
|
+
code: 13,
|
|
160
|
+
message: "Internal error."
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
func.run = handler;
|
|
166
|
+
func = require_v2_trace.wrapTraceContext(require_common_onInit.withInit(func));
|
|
167
|
+
const baseOpts = require_v2_options.optionsToEndpoint(require_v2_options.getGlobalOptions());
|
|
168
|
+
const specificOpts = require_v2_options.optionsToEndpoint(opts);
|
|
169
|
+
func.__endpoint = {
|
|
170
|
+
...require_runtime_manifest.initV2Endpoint(require_v2_options.getGlobalOptions(), opts),
|
|
171
|
+
platform: "gcfv2",
|
|
172
|
+
...baseOpts,
|
|
173
|
+
...specificOpts,
|
|
174
|
+
labels: {
|
|
175
|
+
...baseOpts?.labels,
|
|
176
|
+
...specificOpts?.labels
|
|
177
|
+
},
|
|
178
|
+
blockingTrigger: {
|
|
179
|
+
eventType: afterGenerateEventType,
|
|
180
|
+
options: { regionalWebhook: opts.regionalWebhook }
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return func;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
exports.GeminiV1BetaGenerateContentRequest = GeminiV1BetaGenerateContentRequest;
|
|
188
|
+
exports.GeminiV1BetaGenerateContentResponse = GeminiV1BetaGenerateContentResponse;
|
|
189
|
+
exports.HttpsError = require_common_providers_https.HttpsError;
|
|
190
|
+
exports.VertexV1Beta1GenerateContentRequest = VertexV1Beta1GenerateContentRequest;
|
|
191
|
+
exports.VertexV1Beta1GenerateContentResponse = VertexV1Beta1GenerateContentResponse;
|
|
192
|
+
exports.afterGenerateContent = afterGenerateContent;
|
|
193
|
+
exports.afterGenerateEventType = afterGenerateEventType;
|
|
194
|
+
exports.beforeGenerateContent = beforeGenerateContent;
|
|
195
|
+
exports.beforeGenerateEventType = beforeGenerateEventType;
|
|
196
|
+
exports.geminiV1Beta = geminiV1Beta;
|
|
197
|
+
exports.rpcCodeMap = rpcCodeMap;
|
|
198
|
+
exports.vertexV1Beta1 = vertexV1Beta1;
|