@@ -40,6 +40,9 @@ import * as logger from "../../../logger";
4040
4141export { HttpsError } ;
4242
43+ /**
44+ * Mapping from `FunctionsErrorCode` strings to numeric RPC status codes.
45+ */
4346export const rpcCodeMap : Record < FunctionsErrorCode , number > = {
4447 ok : 0 ,
4548 cancelled : 1 ,
@@ -82,32 +85,72 @@ export {
8285} ;
8386type MultipleLocationsIf < Allowed extends boolean > = Allowed extends true ? string [ ] : never ;
8487
88+ /**
89+ * Options for configuring AI webhook triggers.
90+ */
8591export interface WebhookOptions < Regional extends boolean = false >
8692 extends Omit < EventHandlerOptions , "location" > {
93+ /**
94+ * Region where functions should be deployed. Deployed to `us-central1` by default.
95+ */
8796 location ?: string | Expression < string > | MultipleLocationsIf < Regional > | ResetValue ;
97+ /**
98+ * Whether to handle regional webhooks.
99+ */
88100 regionalWebhook ?: Regional ;
89101}
90102
103+ /**
104+ * Metadata about the server prompt template used, if applicable.
105+ */
91106export interface PromptTemplateInfo {
107+ /** The name of the server prompt template. */
92108 templateName ?: string ;
93109}
94110
111+ /**
112+ * Authentication state for the caller: `"app_user"`, `"unauthenticated"`, or `"unknown"`.
113+ */
95114export type AuthType = "app_user" | "unauthenticated" | "unknown" ;
96115
116+ /**
117+ * Event type for `beforeGenerate` triggers.
118+ */
97119export const beforeGenerateEventType = "google.firebase.ailogic.v1.beforeGenerate" ;
120+ /**
121+ * Event type for `afterGenerate` triggers.
122+ */
98123export const afterGenerateEventType = "google.firebase.ailogic.v1.afterGenerate" ;
99124
125+ /**
126+ * Union of all valid AI request payloads across supported Gemini API providers.
127+ */
100128export type AnyValidAIRequest =
101129 | GeminiV1BetaGenerateContentRequest
102130 | VertexV1Beta1GenerateContentRequest ;
131+ /**
132+ * Union of all valid AI response payloads across supported Gemini API providers.
133+ */
103134export type AnyValidAIResponse =
104135 | GeminiV1BetaGenerateContentResponse
105136 | VertexV1Beta1GenerateContentResponse ;
106137
138+ /**
139+ * Identifier for the Gemini Developer API (`geminiV1Beta`).
140+ */
107141export const geminiV1Beta = "google.ai.generativelanguage.v1beta" ;
142+ /**
143+ * Identifier for the Agent Platform Gemini API (formerly Vertex AI) (`vertexV1Beta1`).
144+ */
108145export const vertexV1Beta1 = "google.cloud.aiplatform.v1beta1" ;
146+ /**
147+ * Supported Gemini API providers: Gemini Developer API or Agent Platform Gemini API (formerly Vertex AI).
148+ */
109149export type SupportedAPI = typeof geminiV1Beta | typeof vertexV1Beta1 ;
110150
151+ /**
152+ * Generic type resolving to the corresponding AI request type based on the API identifier.
153+ */
111154export type AIRequest < API > = string extends API
112155 ? AnyValidAIRequest
113156 : API extends typeof geminiV1Beta
@@ -116,6 +159,9 @@ export type AIRequest<API> = string extends API
116159 ? VertexV1Beta1GenerateContentRequest
117160 : never ;
118161
162+ /**
163+ * Generic type resolving to the corresponding AI response type based on the API identifier.
164+ */
119165export type AIResponse < API > = string extends API
120166 ? AnyValidAIResponse
121167 : API extends typeof geminiV1Beta
@@ -124,31 +170,56 @@ export type AIResponse<API> = string extends API
124170 ? VertexV1Beta1GenerateContentResponse
125171 : never ;
126172
173+ /**
174+ * Data payload for `beforeGenerateContent` events.
175+ */
127176export interface BeforeGenerateContentData < API extends string = string > {
177+ /** The full model resource path (for example, `projects/{PROJECT_ID}/locations/global/publishers/google/models/gemini-3.5-flash`). */
128178 model : string ;
179+ /** Metadata about the server prompt template used, if applicable. */
129180 template ?: PromptTemplateInfo ;
181+ /** The Gemini API provider: `geminiV1Beta` (Gemini Developer API) or `vertexV1Beta1` (Agent Platform Gemini API (formerly Vertex AI)). */
130182 api : SupportedAPI ;
183+ /** The outgoing request payload. */
131184 request : AIRequest < API > ;
132185}
133186
187+ /**
188+ * Data payload for `afterGenerateContent` events.
189+ */
134190export interface AfterGenerateContentData < API extends string = string >
135191 extends BeforeGenerateContentData < API > {
192+ /** The model's response payload. */
136193 response : AIResponse < API > ;
137194}
138195
196+ /**
197+ * Event context and metadata delivered to AI blocking handlers.
198+ */
139199export interface AIBlockingEvent < T = any > extends CloudEvent < T > {
200+ /** Authentication state for the caller: `"app_user"`, `"unauthenticated"`, or `"unknown"`. */
140201 authType : AuthType ;
202+ /** The caller's Firebase Authentication UID, if signed in. */
141203 authId ?: string ;
204+ /** The caller's custom auth claims, if any. */
142205 authClaims ?: any ;
206+ /** The resource name of the caller or request. */
143207 resourceName ?: string ;
208+ /** The Firebase App ID that made the request. */
144209 appId ?: string ;
210+ /** The display name of the calling app, if set. */
145211 displayName ?: string ;
212+ /** The package name of the calling app (applicable only for apps that target Android platforms). */
146213 androidPackageName ?: string ;
214+ /** The bundle ID of the calling app (applicable only for apps that target Apple platforms). */
147215 iosBundleId ?: string ;
148216}
149217
150218type MaybeAsync < T > = T | Promise < T > ;
151219
220+ /**
221+ * A function that handles AI blocking events.
222+ */
152223export type BlockingFunction = HttpsFunction ;
153224
154225/**
0 commit comments