@firebase/ai
Advanced tools
@@ -17,4 +17,6 @@ /** | ||
| */ | ||
| import { FunctionResponse, GenerativeContentBlob, LiveServerContent, LiveServerGoingAwayNotice, LiveServerToolCall, LiveServerToolCallCancellation, Part } from '../public-types'; | ||
| import { FunctionResponse, GenerativeContentBlob, LiveServerContent, LiveServerGoingAwayNotice, LiveServerToolCall, LiveServerToolCallCancellation, LiveSessionResumptionUpdate, Part, SessionResumptionConfig } from '../public-types'; | ||
| import { WebSocketHandler } from '../websocket'; | ||
| import { _LiveClientSetup } from '../types/live-responses'; | ||
| import { ApiSettings } from '../types/internal'; | ||
| /** | ||
@@ -28,4 +30,5 @@ * Represents an active, real-time, bidirectional conversation with the model. | ||
| export declare class LiveSession { | ||
| private webSocketHandler; | ||
| private serverMessages; | ||
| private _setupMessage; | ||
| private _apiSettings; | ||
| private _sessionResumption?; | ||
| /** | ||
@@ -44,6 +47,38 @@ * Indicates whether this Live session is closed. | ||
| /** | ||
| * Allows external code to await the opening of the WebSocket connection. | ||
| */ | ||
| connectionPromise: Promise<void>; | ||
| /** | ||
| * Generator yielding WebSocket messages from the server. | ||
| */ | ||
| private _serverMessages; | ||
| /** | ||
| * WebSocket handler. Injectable for testing. | ||
| */ | ||
| private _webSocketHandler; | ||
| /** | ||
| * @internal | ||
| */ | ||
| constructor(webSocketHandler: WebSocketHandler, serverMessages: AsyncGenerator<unknown>); | ||
| constructor(_setupMessage: _LiveClientSetup, _apiSettings: ApiSettings, _sessionResumption?: SessionResumptionConfig | undefined, webSocketHandler?: WebSocketHandler); | ||
| /** | ||
| * Initializes connection to the WebSocket. Should be called immediately | ||
| * after instantiation. | ||
| * | ||
| * @internal | ||
| */ | ||
| private _connectSession; | ||
| /** | ||
| * Resumes an existing live session with the server. | ||
| * | ||
| * This closes the current WebSocket connection and establishes a new one using | ||
| * the same configuration (URI, headers, model, system instruction, tools, etc.) | ||
| * as the original session. | ||
| * | ||
| * @param sessionResumption - The configuration for session resumption, such as the handle to the previous session state to restore. | ||
| * @throws If the session resumption configuration is unsupported. | ||
| * | ||
| * @beta | ||
| */ | ||
| resumeSession(sessionResumption?: SessionResumptionConfig): Promise<void>; | ||
| /** | ||
| * Sends content to the server. | ||
@@ -127,3 +162,3 @@ * | ||
| */ | ||
| receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>; | ||
| receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice | LiveSessionResumptionUpdate>; | ||
| /** | ||
@@ -130,0 +165,0 @@ * Closes this session. |
@@ -19,3 +19,3 @@ /** | ||
| import { LiveSession } from '../methods/live-session'; | ||
| import { AI, Content, LiveGenerationConfig, LiveModelParams, Tool, ToolConfig } from '../public-types'; | ||
| import { AI, Content, LiveGenerationConfig, LiveModelParams, SessionResumptionConfig, Tool, ToolConfig } from '../public-types'; | ||
| import { WebSocketHandler } from '../websocket'; | ||
@@ -32,5 +32,6 @@ /** | ||
| /** | ||
| * For testing injection | ||
| * @internal | ||
| */ | ||
| private _webSocketHandler; | ||
| private _webSocketHandler?; | ||
| generationConfig: LiveGenerationConfig; | ||
@@ -45,5 +46,6 @@ tools?: Tool[]; | ||
| /** | ||
| * For testing injection | ||
| * @internal | ||
| */ | ||
| _webSocketHandler: WebSocketHandler); | ||
| _webSocketHandler?: WebSocketHandler | undefined); | ||
| /** | ||
@@ -57,3 +59,3 @@ * Starts a {@link LiveSession}. | ||
| */ | ||
| connect(): Promise<LiveSession>; | ||
| connect(sessionResumption?: SessionResumptionConfig): Promise<LiveSession>; | ||
| } |
@@ -18,3 +18,3 @@ /** | ||
| import { GenerateContentResult, RequestOptions } from '../types'; | ||
| import { AI, GenerateContentStreamResult, SingleRequestOptions, StartTemplateChatParams, TemplateChatSession } from '../public-types'; | ||
| import { AI, GenerateContentStreamResult, SingleRequestOptions, StartTemplateChatParams, TemplateChatSession, TemplateToolConfig } from '../public-types'; | ||
| import { ApiSettings } from '../types/internal'; | ||
@@ -48,6 +48,8 @@ /** | ||
| * template with. | ||
| * @param singleRequestOptions - Optional. Options to use for this request. | ||
| * @param templateToolConfig - Optional. Configuration for tools to use with this request. | ||
| * | ||
| * @beta | ||
| */ | ||
| generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
| generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentResult>; | ||
| /** | ||
@@ -62,6 +64,8 @@ * Makes a single streaming call to the model and returns an object | ||
| * template with. | ||
| * @param singleRequestOptions - Optional.Options to use for this request. | ||
| * @param templateToolConfig - Optional. Configuration for tools to use with this request. | ||
| * | ||
| * @beta | ||
| */ | ||
| generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
| generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentStreamResult>; | ||
| /** | ||
@@ -68,0 +72,0 @@ * Starts a {@link TemplateChatSession} that will use this template to |
@@ -224,2 +224,42 @@ /** | ||
| readonly MALFORMED_FUNCTION_CALL: "MALFORMED_FUNCTION_CALL"; | ||
| /** | ||
| * Token generation stopped because generated images contain safety violations. | ||
| */ | ||
| readonly IMAGE_SAFETY: "IMAGE_SAFETY"; | ||
| /** | ||
| * Image generation stopped because generated images have other prohibited content. | ||
| */ | ||
| readonly IMAGE_PROHIBITED_CONTENT: "IMAGE_PROHIBITED_CONTENT"; | ||
| /** | ||
| * Image generation stopped because of other miscellaneous issue. | ||
| */ | ||
| readonly IMAGE_OTHER: "IMAGE_OTHER"; | ||
| /** | ||
| * The model was expected to generate an image, but none was generated. | ||
| */ | ||
| readonly NO_IMAGE: "NO_IMAGE"; | ||
| /** | ||
| * Image generation stopped due to recitation. | ||
| */ | ||
| readonly IMAGE_RECITATION: "IMAGE_RECITATION"; | ||
| /** | ||
| * The response candidate content was flagged for using an unsupported language. | ||
| */ | ||
| readonly LANGUAGE: "LANGUAGE"; | ||
| /** | ||
| * Model generated a tool call but no tools were enabled in the request. | ||
| */ | ||
| readonly UNEXPECTED_TOOL_CALL: "UNEXPECTED_TOOL_CALL"; | ||
| /** | ||
| * Model called too many tools consecutively, thus the system exited execution. | ||
| */ | ||
| readonly TOO_MANY_TOOL_CALLS: "TOO_MANY_TOOL_CALLS"; | ||
| /** | ||
| * Request has at least one thought signature missing. | ||
| */ | ||
| readonly MISSING_THOUGHT_SIGNATURE: "MISSING_THOUGHT_SIGNATURE"; | ||
| /** | ||
| * Finished due to malformed response. | ||
| */ | ||
| readonly MALFORMED_RESPONSE: "MALFORMED_RESPONSE"; | ||
| }; | ||
@@ -232,4 +272,44 @@ /** | ||
| /** | ||
| * Aspect ratios for generated images. | ||
| * @public | ||
| */ | ||
| export declare const ImageConfigAspectRatio: { | ||
| readonly SQUARE_1x1: "1:1"; | ||
| readonly PORTRAIT_9x16: "9:16"; | ||
| readonly LANDSCAPE_16x9: "16:9"; | ||
| readonly PORTRAIT_3x4: "3:4"; | ||
| readonly LANDSCAPE_4x3: "4:3"; | ||
| readonly PORTRAIT_2x3: "2:3"; | ||
| readonly LANDSCAPE_3x2: "3:2"; | ||
| readonly PORTRAIT_4x5: "4:5"; | ||
| readonly LANDSCAPE_5x4: "5:4"; | ||
| readonly PORTRAIT_1x4: "1:4"; | ||
| readonly LANDSCAPE_4x1: "4:1"; | ||
| readonly PORTRAIT_1x8: "1:8"; | ||
| readonly LANDSCAPE_8x1: "8:1"; | ||
| readonly ULTRAWIDE_21x9: "21:9"; | ||
| }; | ||
| /** | ||
| * Aspect ratios for generated images. | ||
| * @public | ||
| */ | ||
| export type ImageConfigAspectRatio = (typeof ImageConfigAspectRatio)[keyof typeof ImageConfigAspectRatio]; | ||
| /** | ||
| * Sizes for generated images. For example, '1K' is 1024px, '2K' is 2048px, and '4K' is 4096px. | ||
| * @public | ||
| */ | ||
| export declare const ImageConfigImageSize: { | ||
| readonly SIZE_512: "512"; | ||
| readonly SIZE_1K: "1K"; | ||
| readonly SIZE_2K: "2K"; | ||
| readonly SIZE_4K: "4K"; | ||
| }; | ||
| /** | ||
| * Sizes for generated images. | ||
| * @public | ||
| */ | ||
| export type ImageConfigImageSize = (typeof ImageConfigImageSize)[keyof typeof ImageConfigImageSize]; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare const FunctionCallingMode: { | ||
@@ -236,0 +316,0 @@ /** |
@@ -18,3 +18,3 @@ /** | ||
| import { Content, FunctionResponse, GenerativeContentBlob, Part } from './content'; | ||
| import { AudioTranscriptionConfig, LiveGenerationConfig, Tool, ToolConfig } from './requests'; | ||
| import { AudioTranscriptionConfig, ContextWindowCompressionConfig, LiveGenerationConfig, SessionResumptionConfig, Tool, ToolConfig } from './requests'; | ||
| import { Transcription } from './responses'; | ||
@@ -72,2 +72,4 @@ /** | ||
| outputAudioTranscription?: AudioTranscriptionConfig; | ||
| sessionResumption?: SessionResumptionConfig; | ||
| contextWindowCompression?: ContextWindowCompressionConfig; | ||
| }; | ||
@@ -74,0 +76,0 @@ } |
@@ -20,3 +20,3 @@ /** | ||
| import { LanguageModelCreateOptions, LanguageModelPromptOptions } from './language-model'; | ||
| import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, HarmCategory, InferenceMode, ResponseModality, ThinkingLevel } from './enums'; | ||
| import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, HarmCategory, ImageConfigAspectRatio, ImageConfigImageSize, InferenceMode, ResponseModality, ThinkingLevel } from './enums'; | ||
| import { ObjectSchemaRequest, SchemaRequest } from './schema'; | ||
@@ -97,2 +97,16 @@ /** | ||
| /** | ||
| * Configuration options for generating images with Gemini models. | ||
| * @public | ||
| */ | ||
| export interface ImageConfig { | ||
| /** | ||
| * The aspect ratio of generated images. | ||
| */ | ||
| aspectRatio?: ImageConfigAspectRatio; | ||
| /** | ||
| * The size of the generated images. | ||
| */ | ||
| imageSize?: ImageConfigImageSize; | ||
| } | ||
| /** | ||
| * Config options for content-related requests | ||
@@ -150,2 +164,7 @@ * @public | ||
| thinkingConfig?: ThinkingConfig; | ||
| /** | ||
| * Configuration options for generating images with Gemini models. | ||
| * @public | ||
| */ | ||
| imageConfig?: ImageConfig; | ||
| } | ||
@@ -219,4 +238,64 @@ /** | ||
| outputAudioTranscription?: AudioTranscriptionConfig; | ||
| /** | ||
| * The context window compression configuration. | ||
| * | ||
| * @beta | ||
| */ | ||
| contextWindowCompression?: ContextWindowCompressionConfig; | ||
| } | ||
| /** | ||
| * Configures the sliding window context compression mechanism. | ||
| * | ||
| * @remarks | ||
| * The sliding window discards content at the beginning of the | ||
| * context window. The resulting context will always begin at | ||
| * the start of a `user` role turn. System instructions | ||
| * will always remain at the start of the result. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface SlidingWindow { | ||
| /** | ||
| * The session reduction target, for example, how many tokens the model | ||
| * should keep. | ||
| */ | ||
| targetTokens?: number; | ||
| } | ||
| /** | ||
| * Enables context window compression to manage the model's context window. | ||
| * | ||
| * @remarks | ||
| * This mechanism prevents the context from exceeding a given length. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface ContextWindowCompressionConfig { | ||
| /** | ||
| * The number of tokens (before running a turn) that triggers the context | ||
| * window compression. | ||
| */ | ||
| triggerTokens?: number; | ||
| /** | ||
| * The sliding window compression mechanism. | ||
| */ | ||
| slidingWindow?: SlidingWindow; | ||
| } | ||
| /** | ||
| * Configuration for the session resumption mechanism. | ||
| * | ||
| * @remarks | ||
| * When included in the session setup, the server will send | ||
| * {@link LiveSessionResumptionUpdate} messages in the response stream. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface SessionResumptionConfig { | ||
| /** | ||
| * The session resumption handle of the previous session to restore. | ||
| * | ||
| * If not present, a new session will be started. | ||
| */ | ||
| handle?: string; | ||
| } | ||
| /** | ||
| * Params for {@link GenerativeModel.startChat}. | ||
@@ -335,3 +414,3 @@ * @public | ||
| */ | ||
| export type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool; | ||
| export type Tool = FunctionDeclarationsTool | GoogleMapsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool; | ||
| /** | ||
@@ -394,2 +473,24 @@ * Structured representation of a function declaration as defined by the | ||
| /** | ||
| * A tool that allows a Gemini model to connect to Google Maps to access and incorporate | ||
| * location-based information into its responses. | ||
| * | ||
| * Important: If using Grounding with Google Maps, you are required to comply with the | ||
| * "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API} | ||
| * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms} | ||
| * section within the Service Specific Terms). | ||
| * | ||
| * @public | ||
| */ | ||
| export interface GoogleMapsTool { | ||
| /** | ||
| * Specifies the Google Maps configuration. | ||
| * | ||
| * When using this feature, you are required to comply with the "Grounding with Google Maps" | ||
| * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API} | ||
| * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms} | ||
| * section within the Service Specific Terms). | ||
| */ | ||
| googleMaps: GoogleMaps; | ||
| } | ||
| /** | ||
| * A tool that enables the model to use code execution. | ||
@@ -415,2 +516,10 @@ * | ||
| /** | ||
| * Specifies the Google Maps configuration. | ||
| * | ||
| * @public | ||
| */ | ||
| export interface GoogleMaps { | ||
| enableWidget?: boolean; | ||
| } | ||
| /** | ||
| * A tool that allows you to provide additional context to the models in the form of public web | ||
@@ -455,2 +564,16 @@ * URLs. By including URLs in your request, the Gemini model will access the content from those | ||
| /** | ||
| * An object that represents a latitude/longitude pair. | ||
| * @public | ||
| */ | ||
| export interface LatLng { | ||
| /** | ||
| * The latitude in degrees. It must be in the range `[-90.0, +90.0]`. | ||
| */ | ||
| latitude?: number; | ||
| /** | ||
| * The longitude in degrees. It must be in the range `[-180.0, +180.0]`. | ||
| */ | ||
| longitude?: number; | ||
| } | ||
| /** | ||
| * Structured representation of a template function declaration. | ||
@@ -527,6 +650,15 @@ * Included in this declaration are the function name and parameters. This | ||
| functionCallingConfig?: FunctionCallingConfig; | ||
| retrievalConfig?: RetrievalConfig; | ||
| } | ||
| /** | ||
| * Tool configuration for `TemplateGenerativeModel`s. | ||
| * This config is shared for all tools provided in the server prompt template request. | ||
| * @public | ||
| */ | ||
| export interface TemplateToolConfig { | ||
| retrievalConfig?: RetrievalConfig; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface FunctionCallingConfig { | ||
@@ -537,2 +669,16 @@ mode?: FunctionCallingMode; | ||
| /** | ||
| * Configuration options for data retrieval tools. | ||
| * @public | ||
| */ | ||
| export interface RetrievalConfig { | ||
| /** | ||
| * The location of the user. | ||
| */ | ||
| latLng?: LatLng; | ||
| /** | ||
| * The language code of the user. | ||
| */ | ||
| languageCode?: string; | ||
| } | ||
| /** | ||
| * Encapsulates configuration for on-device inference. | ||
@@ -539,0 +685,0 @@ * |
@@ -206,3 +206,4 @@ /** | ||
| * | ||
| * Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}). | ||
| * Currently, only Grounding with Google Search and Grounding with Google Maps are supported | ||
| * (see {@link GoogleSearchTool} and {@link GoogleMapsTool}, respectively). | ||
| * | ||
@@ -214,2 +215,7 @@ * Important: If using Grounding with Google Search, you are required to comply with the | ||
| * | ||
| * Important: If using Grounding with Google Maps, you are required to comply with the | ||
| * "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API} | ||
| * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms} | ||
| * section within the Service Specific Terms). | ||
| * | ||
| * @public | ||
@@ -243,2 +249,8 @@ */ | ||
| retrievalQueries?: string[]; | ||
| /** | ||
| * Resource name of the Google Maps widget context token that can be used with the | ||
| * `PlacesContextElement` widget in order to render contextual data. Only populated in the case | ||
| * that grounding with Google Maps is enabled. | ||
| */ | ||
| googleMapsWidgetContextToken?: string; | ||
| } | ||
@@ -279,2 +291,6 @@ /** | ||
| web?: WebGroundingChunk; | ||
| /** | ||
| * Contains details if the grounding chunk is from a Google Maps source. | ||
| */ | ||
| maps?: GoogleMapsGroundingChunk; | ||
| } | ||
@@ -308,2 +324,29 @@ /** | ||
| /** | ||
| * A grounding chunk from Google Maps. | ||
| * | ||
| * Important: If using Grounding with Google Maps, you are required to comply with the | ||
| * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Maps". | ||
| * | ||
| * @public | ||
| */ | ||
| export interface GoogleMapsGroundingChunk { | ||
| /** | ||
| * The URI of the place. | ||
| */ | ||
| uri?: string; | ||
| /** | ||
| * The title of the place. | ||
| */ | ||
| title?: string; | ||
| /** | ||
| * The text of the place answer. | ||
| */ | ||
| text?: string; | ||
| /** | ||
| * This Place's resource name, in `places/{place_id}` format. This can be used to look up the | ||
| * place in the Google Maps API. | ||
| */ | ||
| placeId?: string; | ||
| } | ||
| /** | ||
| * Provides information about how a specific segment of the model's response is supported by the | ||
@@ -344,3 +387,3 @@ * retrieved grounding chunks. | ||
| * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the | ||
| * beginning of the part's content (e.g., `Part.text`). | ||
| * beginning of the part's content (for example, `Part.text`). | ||
| */ | ||
@@ -596,2 +639,25 @@ startIndex: number; | ||
| /** | ||
| * An update of the session resumption state. | ||
| * | ||
| * This message is only sent if {@link SessionResumptionConfig} was set in the | ||
| * session setup. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface LiveSessionResumptionUpdate { | ||
| type: 'sessionResumptionUpdate'; | ||
| /** | ||
| * The new handle that represents the state that can be resumed. Empty if `resumable` is false. | ||
| */ | ||
| newHandle?: string; | ||
| /** | ||
| * Indicates if the session can be resumed at this point. | ||
| */ | ||
| resumable?: boolean; | ||
| /** | ||
| * The index of the last client message that is included in the state represented by this update. | ||
| */ | ||
| lastConsumedClientMessageIndex?: number; | ||
| } | ||
| /** | ||
| * The types of responses that can be returned by {@link LiveSession.receive}. | ||
@@ -606,2 +672,3 @@ * | ||
| GOING_AWAY_NOTICE: string; | ||
| SESSION_RESUMPTION_UPDATE: string; | ||
| }; | ||
@@ -608,0 +675,0 @@ /** |
@@ -17,4 +17,6 @@ /** | ||
| */ | ||
| import { FunctionResponse, GenerativeContentBlob, LiveServerContent, LiveServerGoingAwayNotice, LiveServerToolCall, LiveServerToolCallCancellation, Part } from '../public-types'; | ||
| import { FunctionResponse, GenerativeContentBlob, LiveServerContent, LiveServerGoingAwayNotice, LiveServerToolCall, LiveServerToolCallCancellation, LiveSessionResumptionUpdate, Part, SessionResumptionConfig } from '../public-types'; | ||
| import { WebSocketHandler } from '../websocket'; | ||
| import { _LiveClientSetup } from '../types/live-responses'; | ||
| import { ApiSettings } from '../types/internal'; | ||
| /** | ||
@@ -28,4 +30,5 @@ * Represents an active, real-time, bidirectional conversation with the model. | ||
| export declare class LiveSession { | ||
| private webSocketHandler; | ||
| private serverMessages; | ||
| private _setupMessage; | ||
| private _apiSettings; | ||
| private _sessionResumption?; | ||
| /** | ||
@@ -44,6 +47,38 @@ * Indicates whether this Live session is closed. | ||
| /** | ||
| * Allows external code to await the opening of the WebSocket connection. | ||
| */ | ||
| connectionPromise: Promise<void>; | ||
| /** | ||
| * Generator yielding WebSocket messages from the server. | ||
| */ | ||
| private _serverMessages; | ||
| /** | ||
| * WebSocket handler. Injectable for testing. | ||
| */ | ||
| private _webSocketHandler; | ||
| /** | ||
| * @internal | ||
| */ | ||
| constructor(webSocketHandler: WebSocketHandler, serverMessages: AsyncGenerator<unknown>); | ||
| constructor(_setupMessage: _LiveClientSetup, _apiSettings: ApiSettings, _sessionResumption?: SessionResumptionConfig | undefined, webSocketHandler?: WebSocketHandler); | ||
| /** | ||
| * Initializes connection to the WebSocket. Should be called immediately | ||
| * after instantiation. | ||
| * | ||
| * @internal | ||
| */ | ||
| private _connectSession; | ||
| /** | ||
| * Resumes an existing live session with the server. | ||
| * | ||
| * This closes the current WebSocket connection and establishes a new one using | ||
| * the same configuration (URI, headers, model, system instruction, tools, etc.) | ||
| * as the original session. | ||
| * | ||
| * @param sessionResumption - The configuration for session resumption, such as the handle to the previous session state to restore. | ||
| * @throws If the session resumption configuration is unsupported. | ||
| * | ||
| * @beta | ||
| */ | ||
| resumeSession(sessionResumption?: SessionResumptionConfig): Promise<void>; | ||
| /** | ||
| * Sends content to the server. | ||
@@ -127,3 +162,3 @@ * | ||
| */ | ||
| receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice>; | ||
| receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation | LiveServerGoingAwayNotice | LiveSessionResumptionUpdate>; | ||
| /** | ||
@@ -130,0 +165,0 @@ * Closes this session. |
@@ -19,3 +19,3 @@ /** | ||
| import { LiveSession } from '../methods/live-session'; | ||
| import { AI, Content, LiveGenerationConfig, LiveModelParams, Tool, ToolConfig } from '../public-types'; | ||
| import { AI, Content, LiveGenerationConfig, LiveModelParams, SessionResumptionConfig, Tool, ToolConfig } from '../public-types'; | ||
| import { WebSocketHandler } from '../websocket'; | ||
@@ -32,5 +32,6 @@ /** | ||
| /** | ||
| * For testing injection | ||
| * @internal | ||
| */ | ||
| private _webSocketHandler; | ||
| private _webSocketHandler?; | ||
| generationConfig: LiveGenerationConfig; | ||
@@ -45,5 +46,6 @@ tools?: Tool[]; | ||
| /** | ||
| * For testing injection | ||
| * @internal | ||
| */ | ||
| _webSocketHandler: WebSocketHandler); | ||
| _webSocketHandler?: WebSocketHandler | undefined); | ||
| /** | ||
@@ -57,3 +59,3 @@ * Starts a {@link LiveSession}. | ||
| */ | ||
| connect(): Promise<LiveSession>; | ||
| connect(sessionResumption?: SessionResumptionConfig): Promise<LiveSession>; | ||
| } |
@@ -18,3 +18,3 @@ /** | ||
| import { GenerateContentResult, RequestOptions } from '../types'; | ||
| import { AI, GenerateContentStreamResult, SingleRequestOptions, StartTemplateChatParams, TemplateChatSession } from '../public-types'; | ||
| import { AI, GenerateContentStreamResult, SingleRequestOptions, StartTemplateChatParams, TemplateChatSession, TemplateToolConfig } from '../public-types'; | ||
| import { ApiSettings } from '../types/internal'; | ||
@@ -48,6 +48,8 @@ /** | ||
| * template with. | ||
| * @param singleRequestOptions - Optional. Options to use for this request. | ||
| * @param templateToolConfig - Optional. Configuration for tools to use with this request. | ||
| * | ||
| * @beta | ||
| */ | ||
| generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>; | ||
| generateContent(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentResult>; | ||
| /** | ||
@@ -62,6 +64,8 @@ * Makes a single streaming call to the model and returns an object | ||
| * template with. | ||
| * @param singleRequestOptions - Optional.Options to use for this request. | ||
| * @param templateToolConfig - Optional. Configuration for tools to use with this request. | ||
| * | ||
| * @beta | ||
| */ | ||
| generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>; | ||
| generateContentStream(templateId: string, templateVariables: Record<string, unknown>, singleRequestOptions?: SingleRequestOptions, templateToolConfig?: TemplateToolConfig): Promise<GenerateContentStreamResult>; | ||
| /** | ||
@@ -68,0 +72,0 @@ * Starts a {@link TemplateChatSession} that will use this template to |
@@ -224,2 +224,42 @@ /** | ||
| readonly MALFORMED_FUNCTION_CALL: "MALFORMED_FUNCTION_CALL"; | ||
| /** | ||
| * Token generation stopped because generated images contain safety violations. | ||
| */ | ||
| readonly IMAGE_SAFETY: "IMAGE_SAFETY"; | ||
| /** | ||
| * Image generation stopped because generated images have other prohibited content. | ||
| */ | ||
| readonly IMAGE_PROHIBITED_CONTENT: "IMAGE_PROHIBITED_CONTENT"; | ||
| /** | ||
| * Image generation stopped because of other miscellaneous issue. | ||
| */ | ||
| readonly IMAGE_OTHER: "IMAGE_OTHER"; | ||
| /** | ||
| * The model was expected to generate an image, but none was generated. | ||
| */ | ||
| readonly NO_IMAGE: "NO_IMAGE"; | ||
| /** | ||
| * Image generation stopped due to recitation. | ||
| */ | ||
| readonly IMAGE_RECITATION: "IMAGE_RECITATION"; | ||
| /** | ||
| * The response candidate content was flagged for using an unsupported language. | ||
| */ | ||
| readonly LANGUAGE: "LANGUAGE"; | ||
| /** | ||
| * Model generated a tool call but no tools were enabled in the request. | ||
| */ | ||
| readonly UNEXPECTED_TOOL_CALL: "UNEXPECTED_TOOL_CALL"; | ||
| /** | ||
| * Model called too many tools consecutively, thus the system exited execution. | ||
| */ | ||
| readonly TOO_MANY_TOOL_CALLS: "TOO_MANY_TOOL_CALLS"; | ||
| /** | ||
| * Request has at least one thought signature missing. | ||
| */ | ||
| readonly MISSING_THOUGHT_SIGNATURE: "MISSING_THOUGHT_SIGNATURE"; | ||
| /** | ||
| * Finished due to malformed response. | ||
| */ | ||
| readonly MALFORMED_RESPONSE: "MALFORMED_RESPONSE"; | ||
| }; | ||
@@ -232,4 +272,44 @@ /** | ||
| /** | ||
| * Aspect ratios for generated images. | ||
| * @public | ||
| */ | ||
| export declare const ImageConfigAspectRatio: { | ||
| readonly SQUARE_1x1: "1:1"; | ||
| readonly PORTRAIT_9x16: "9:16"; | ||
| readonly LANDSCAPE_16x9: "16:9"; | ||
| readonly PORTRAIT_3x4: "3:4"; | ||
| readonly LANDSCAPE_4x3: "4:3"; | ||
| readonly PORTRAIT_2x3: "2:3"; | ||
| readonly LANDSCAPE_3x2: "3:2"; | ||
| readonly PORTRAIT_4x5: "4:5"; | ||
| readonly LANDSCAPE_5x4: "5:4"; | ||
| readonly PORTRAIT_1x4: "1:4"; | ||
| readonly LANDSCAPE_4x1: "4:1"; | ||
| readonly PORTRAIT_1x8: "1:8"; | ||
| readonly LANDSCAPE_8x1: "8:1"; | ||
| readonly ULTRAWIDE_21x9: "21:9"; | ||
| }; | ||
| /** | ||
| * Aspect ratios for generated images. | ||
| * @public | ||
| */ | ||
| export type ImageConfigAspectRatio = (typeof ImageConfigAspectRatio)[keyof typeof ImageConfigAspectRatio]; | ||
| /** | ||
| * Sizes for generated images. For example, '1K' is 1024px, '2K' is 2048px, and '4K' is 4096px. | ||
| * @public | ||
| */ | ||
| export declare const ImageConfigImageSize: { | ||
| readonly SIZE_512: "512"; | ||
| readonly SIZE_1K: "1K"; | ||
| readonly SIZE_2K: "2K"; | ||
| readonly SIZE_4K: "4K"; | ||
| }; | ||
| /** | ||
| * Sizes for generated images. | ||
| * @public | ||
| */ | ||
| export type ImageConfigImageSize = (typeof ImageConfigImageSize)[keyof typeof ImageConfigImageSize]; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare const FunctionCallingMode: { | ||
@@ -236,0 +316,0 @@ /** |
@@ -18,3 +18,3 @@ /** | ||
| import { Content, FunctionResponse, GenerativeContentBlob, Part } from './content'; | ||
| import { AudioTranscriptionConfig, LiveGenerationConfig, Tool, ToolConfig } from './requests'; | ||
| import { AudioTranscriptionConfig, ContextWindowCompressionConfig, LiveGenerationConfig, SessionResumptionConfig, Tool, ToolConfig } from './requests'; | ||
| import { Transcription } from './responses'; | ||
@@ -72,2 +72,4 @@ /** | ||
| outputAudioTranscription?: AudioTranscriptionConfig; | ||
| sessionResumption?: SessionResumptionConfig; | ||
| contextWindowCompression?: ContextWindowCompressionConfig; | ||
| }; | ||
@@ -74,0 +76,0 @@ } |
@@ -20,3 +20,3 @@ /** | ||
| import { LanguageModelCreateOptions, LanguageModelPromptOptions } from './language-model'; | ||
| import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, HarmCategory, InferenceMode, ResponseModality, ThinkingLevel } from './enums'; | ||
| import { FunctionCallingMode, HarmBlockMethod, HarmBlockThreshold, HarmCategory, ImageConfigAspectRatio, ImageConfigImageSize, InferenceMode, ResponseModality, ThinkingLevel } from './enums'; | ||
| import { ObjectSchemaRequest, SchemaRequest } from './schema'; | ||
@@ -97,2 +97,16 @@ /** | ||
| /** | ||
| * Configuration options for generating images with Gemini models. | ||
| * @public | ||
| */ | ||
| export interface ImageConfig { | ||
| /** | ||
| * The aspect ratio of generated images. | ||
| */ | ||
| aspectRatio?: ImageConfigAspectRatio; | ||
| /** | ||
| * The size of the generated images. | ||
| */ | ||
| imageSize?: ImageConfigImageSize; | ||
| } | ||
| /** | ||
| * Config options for content-related requests | ||
@@ -150,2 +164,7 @@ * @public | ||
| thinkingConfig?: ThinkingConfig; | ||
| /** | ||
| * Configuration options for generating images with Gemini models. | ||
| * @public | ||
| */ | ||
| imageConfig?: ImageConfig; | ||
| } | ||
@@ -219,4 +238,64 @@ /** | ||
| outputAudioTranscription?: AudioTranscriptionConfig; | ||
| /** | ||
| * The context window compression configuration. | ||
| * | ||
| * @beta | ||
| */ | ||
| contextWindowCompression?: ContextWindowCompressionConfig; | ||
| } | ||
| /** | ||
| * Configures the sliding window context compression mechanism. | ||
| * | ||
| * @remarks | ||
| * The sliding window discards content at the beginning of the | ||
| * context window. The resulting context will always begin at | ||
| * the start of a `user` role turn. System instructions | ||
| * will always remain at the start of the result. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface SlidingWindow { | ||
| /** | ||
| * The session reduction target, for example, how many tokens the model | ||
| * should keep. | ||
| */ | ||
| targetTokens?: number; | ||
| } | ||
| /** | ||
| * Enables context window compression to manage the model's context window. | ||
| * | ||
| * @remarks | ||
| * This mechanism prevents the context from exceeding a given length. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface ContextWindowCompressionConfig { | ||
| /** | ||
| * The number of tokens (before running a turn) that triggers the context | ||
| * window compression. | ||
| */ | ||
| triggerTokens?: number; | ||
| /** | ||
| * The sliding window compression mechanism. | ||
| */ | ||
| slidingWindow?: SlidingWindow; | ||
| } | ||
| /** | ||
| * Configuration for the session resumption mechanism. | ||
| * | ||
| * @remarks | ||
| * When included in the session setup, the server will send | ||
| * {@link LiveSessionResumptionUpdate} messages in the response stream. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface SessionResumptionConfig { | ||
| /** | ||
| * The session resumption handle of the previous session to restore. | ||
| * | ||
| * If not present, a new session will be started. | ||
| */ | ||
| handle?: string; | ||
| } | ||
| /** | ||
| * Params for {@link GenerativeModel.startChat}. | ||
@@ -335,3 +414,3 @@ * @public | ||
| */ | ||
| export type Tool = FunctionDeclarationsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool; | ||
| export type Tool = FunctionDeclarationsTool | GoogleMapsTool | GoogleSearchTool | CodeExecutionTool | URLContextTool; | ||
| /** | ||
@@ -394,2 +473,24 @@ * Structured representation of a function declaration as defined by the | ||
| /** | ||
| * A tool that allows a Gemini model to connect to Google Maps to access and incorporate | ||
| * location-based information into its responses. | ||
| * | ||
| * Important: If using Grounding with Google Maps, you are required to comply with the | ||
| * "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API} | ||
| * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms} | ||
| * section within the Service Specific Terms). | ||
| * | ||
| * @public | ||
| */ | ||
| export interface GoogleMapsTool { | ||
| /** | ||
| * Specifies the Google Maps configuration. | ||
| * | ||
| * When using this feature, you are required to comply with the "Grounding with Google Maps" | ||
| * usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API} | ||
| * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms} | ||
| * section within the Service Specific Terms). | ||
| */ | ||
| googleMaps: GoogleMaps; | ||
| } | ||
| /** | ||
| * A tool that enables the model to use code execution. | ||
@@ -415,2 +516,10 @@ * | ||
| /** | ||
| * Specifies the Google Maps configuration. | ||
| * | ||
| * @public | ||
| */ | ||
| export interface GoogleMaps { | ||
| enableWidget?: boolean; | ||
| } | ||
| /** | ||
| * A tool that allows you to provide additional context to the models in the form of public web | ||
@@ -455,2 +564,16 @@ * URLs. By including URLs in your request, the Gemini model will access the content from those | ||
| /** | ||
| * An object that represents a latitude/longitude pair. | ||
| * @public | ||
| */ | ||
| export interface LatLng { | ||
| /** | ||
| * The latitude in degrees. It must be in the range `[-90.0, +90.0]`. | ||
| */ | ||
| latitude?: number; | ||
| /** | ||
| * The longitude in degrees. It must be in the range `[-180.0, +180.0]`. | ||
| */ | ||
| longitude?: number; | ||
| } | ||
| /** | ||
| * Structured representation of a template function declaration. | ||
@@ -527,6 +650,15 @@ * Included in this declaration are the function name and parameters. This | ||
| functionCallingConfig?: FunctionCallingConfig; | ||
| retrievalConfig?: RetrievalConfig; | ||
| } | ||
| /** | ||
| * Tool configuration for `TemplateGenerativeModel`s. | ||
| * This config is shared for all tools provided in the server prompt template request. | ||
| * @public | ||
| */ | ||
| export interface TemplateToolConfig { | ||
| retrievalConfig?: RetrievalConfig; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface FunctionCallingConfig { | ||
@@ -537,2 +669,16 @@ mode?: FunctionCallingMode; | ||
| /** | ||
| * Configuration options for data retrieval tools. | ||
| * @public | ||
| */ | ||
| export interface RetrievalConfig { | ||
| /** | ||
| * The location of the user. | ||
| */ | ||
| latLng?: LatLng; | ||
| /** | ||
| * The language code of the user. | ||
| */ | ||
| languageCode?: string; | ||
| } | ||
| /** | ||
| * Encapsulates configuration for on-device inference. | ||
@@ -539,0 +685,0 @@ * |
@@ -206,3 +206,4 @@ /** | ||
| * | ||
| * Currently, only Grounding with Google Search is supported (see {@link GoogleSearchTool}). | ||
| * Currently, only Grounding with Google Search and Grounding with Google Maps are supported | ||
| * (see {@link GoogleSearchTool} and {@link GoogleMapsTool}, respectively). | ||
| * | ||
@@ -214,2 +215,7 @@ * Important: If using Grounding with Google Search, you are required to comply with the | ||
| * | ||
| * Important: If using Grounding with Google Maps, you are required to comply with the | ||
| * "Grounding with Google Maps" usage requirements for your chosen API provider: {@link https://ai.google.dev/gemini-api/terms#grounding-with-google-maps | Gemini Developer API} | ||
| * or Vertex AI Gemini API (see {@link https://cloud.google.com/terms/service-terms | Service Terms} | ||
| * section within the Service Specific Terms). | ||
| * | ||
| * @public | ||
@@ -243,2 +249,8 @@ */ | ||
| retrievalQueries?: string[]; | ||
| /** | ||
| * Resource name of the Google Maps widget context token that can be used with the | ||
| * `PlacesContextElement` widget in order to render contextual data. Only populated in the case | ||
| * that grounding with Google Maps is enabled. | ||
| */ | ||
| googleMapsWidgetContextToken?: string; | ||
| } | ||
@@ -279,2 +291,6 @@ /** | ||
| web?: WebGroundingChunk; | ||
| /** | ||
| * Contains details if the grounding chunk is from a Google Maps source. | ||
| */ | ||
| maps?: GoogleMapsGroundingChunk; | ||
| } | ||
@@ -308,2 +324,29 @@ /** | ||
| /** | ||
| * A grounding chunk from Google Maps. | ||
| * | ||
| * Important: If using Grounding with Google Maps, you are required to comply with the | ||
| * {@link https://cloud.google.com/terms/service-terms | Service Specific Terms} for "Grounding with Google Maps". | ||
| * | ||
| * @public | ||
| */ | ||
| export interface GoogleMapsGroundingChunk { | ||
| /** | ||
| * The URI of the place. | ||
| */ | ||
| uri?: string; | ||
| /** | ||
| * The title of the place. | ||
| */ | ||
| title?: string; | ||
| /** | ||
| * The text of the place answer. | ||
| */ | ||
| text?: string; | ||
| /** | ||
| * This Place's resource name, in `places/{place_id}` format. This can be used to look up the | ||
| * place in the Google Maps API. | ||
| */ | ||
| placeId?: string; | ||
| } | ||
| /** | ||
| * Provides information about how a specific segment of the model's response is supported by the | ||
@@ -344,3 +387,3 @@ * retrieved grounding chunks. | ||
| * measured in UTF-8 bytes. This offset is inclusive, starting from 0 at the | ||
| * beginning of the part's content (e.g., `Part.text`). | ||
| * beginning of the part's content (for example, `Part.text`). | ||
| */ | ||
@@ -596,2 +639,25 @@ startIndex: number; | ||
| /** | ||
| * An update of the session resumption state. | ||
| * | ||
| * This message is only sent if {@link SessionResumptionConfig} was set in the | ||
| * session setup. | ||
| * | ||
| * @beta | ||
| */ | ||
| export interface LiveSessionResumptionUpdate { | ||
| type: 'sessionResumptionUpdate'; | ||
| /** | ||
| * The new handle that represents the state that can be resumed. Empty if `resumable` is false. | ||
| */ | ||
| newHandle?: string; | ||
| /** | ||
| * Indicates if the session can be resumed at this point. | ||
| */ | ||
| resumable?: boolean; | ||
| /** | ||
| * The index of the last client message that is included in the state represented by this update. | ||
| */ | ||
| lastConsumedClientMessageIndex?: number; | ||
| } | ||
| /** | ||
| * The types of responses that can be returned by {@link LiveSession.receive}. | ||
@@ -606,2 +672,3 @@ * | ||
| GOING_AWAY_NOTICE: string; | ||
| SESSION_RESUMPTION_UPDATE: string; | ||
| }; | ||
@@ -608,0 +675,0 @@ /** |
+9
-9
| { | ||
| "name": "@firebase/ai", | ||
| "version": "2.11.1", | ||
| "version": "2.12.0-20260505131936", | ||
| "description": "The Firebase AI SDK", | ||
@@ -51,10 +51,10 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)", | ||
| "peerDependencies": { | ||
| "@firebase/app": "0.x", | ||
| "@firebase/app-types": "0.x" | ||
| "@firebase/app": "0.14.12-20260505131936", | ||
| "@firebase/app-types": "0.9.5-20260505131936" | ||
| }, | ||
| "dependencies": { | ||
| "@firebase/app-check-interop-types": "0.3.3", | ||
| "@firebase/component": "0.7.2", | ||
| "@firebase/logger": "0.5.0", | ||
| "@firebase/util": "1.15.0", | ||
| "@firebase/app-check-interop-types": "0.3.4-20260505131936", | ||
| "@firebase/component": "0.7.3-20260505131936", | ||
| "@firebase/logger": "0.5.1-20260505131936", | ||
| "@firebase/util": "1.15.1-20260505131936", | ||
| "tslib": "^2.1.0" | ||
@@ -64,7 +64,7 @@ }, | ||
| "devDependencies": { | ||
| "@firebase/app": "0.14.11", | ||
| "@firebase/app": "0.14.12-20260505131936", | ||
| "@rollup/plugin-json": "6.1.0", | ||
| "rollup": "2.79.2", | ||
| "rollup-plugin-replace": "2.2.0", | ||
| "rollup-plugin-typescript2": "0.36.0", | ||
| "rollup-plugin-typescript2": "0.37.0", | ||
| "typescript": "5.5.4" | ||
@@ -71,0 +71,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2868340
4.14%39528
5.25%2
100%257
3.21%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated