Skip to content

Commit 6db5af4

Browse files
authored
fix(ai): Fix TemplateChatSession type (#9840)
1 parent fea8d1f commit 6db5af4

13 files changed

Lines changed: 106 additions & 147 deletions

.changeset/silly-hounds-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/ai': patch
3+
---
4+
5+
Fix `TemplateChatSession` type so it does not error on TypeScript build. See Github issue #9832.

common/api-review/ai.api.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,21 +1389,13 @@ export class StringSchema extends Schema {
13891389
toJSON(): SchemaRequest;
13901390
}
13911391

1392-
// Warning: (ae-incompatible-release-tags) The symbol "TemplateChatSession" is marked as @beta, but its signature references "TemplateRequestInternal" which is marked as @internal
1393-
//
13941392
// @beta
1395-
export class TemplateChatSession extends ChatSessionBase<StartTemplateChatParams, TemplateRequestInternal, TemplateFunctionDeclarationsTool> {
1396-
constructor(apiSettings: ApiSettings, params: StartTemplateChatParams, requestOptions?: RequestOptions | undefined);
1397-
// @internal
1398-
_callGenerateContent(formattedRequest: TemplateRequestInternal, singleRequestOptions?: RequestOptions): Promise<GenerateContentResult>;
1399-
// @internal
1400-
_callGenerateContentStream(formattedRequest: TemplateRequestInternal, singleRequestOptions?: RequestOptions): Promise<GenerateContentStreamResult>;
1401-
// @internal
1402-
_formatRequest(incomingContent: Content, tempHistory: Content[]): TemplateRequestInternal;
1393+
export interface TemplateChatSession {
1394+
getHistory(): Promise<Content[]>;
14031395
// (undocumented)
14041396
params: StartTemplateChatParams;
14051397
// (undocumented)
1406-
requestOptions?: RequestOptions | undefined;
1398+
requestOptions?: RequestOptions;
14071399
sendMessage(request: string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
14081400
sendMessageStream(request: string | Array<string | Part>, singleRequestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
14091401
}
@@ -1436,7 +1428,9 @@ export interface TemplateFunctionDeclarationsToolInternal {
14361428
templateFunctions?: TemplateFunctionDeclarationInternal[];
14371429
}
14381430

1439-
// @beta
1431+
// Warning: (ae-internal-missing-underscore) The name "TemplateGenerateContentRequest" should be prefixed with an underscore because the declaration is marked as @internal
1432+
//
1433+
// @internal
14401434
export interface TemplateGenerateContentRequest {
14411435
// (undocumented)
14421436
[key: string]: unknown;

docs-devsite/_toc.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ toc:
212212
path: /docs/reference/js/ai.templatefunctiondeclaration.md
213213
- title: TemplateFunctionDeclarationsTool
214214
path: /docs/reference/js/ai.templatefunctiondeclarationstool.md
215-
- title: TemplateGenerateContentRequest
216-
path: /docs/reference/js/ai.templategeneratecontentrequest.md
217215
- title: TemplateGenerativeModel
218216
path: /docs/reference/js/ai.templategenerativemodel.md
219217
- title: TemplateImagenModel

docs-devsite/ai.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ The Firebase AI Web SDK.
5050
| [ObjectSchema](./ai.objectschema.md#objectschema_class) | Schema class for "object" types. The <code>properties</code> param must be a map of <code>Schema</code> objects. |
5151
| [Schema](./ai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with <code>JSON.stringify()</code> into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) |
5252
| [StringSchema](./ai.stringschema.md#stringschema_class) | Schema class for "string" types. Can be used with or without enum values. |
53-
| [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_class) | <b><i>(Public Preview)</i></b> <code>ChatSession</code> class for use with server prompt templates that enables sending chat messages and stores history of sent and received messages so far. |
5453
| [TemplateGenerativeModel](./ai.templategenerativemodel.md#templategenerativemodel_class) | <b><i>(Public Preview)</i></b> [GenerativeModel](./ai.generativemodel.md#generativemodel_class) APIs that execute on a server-side template.<!-- -->This class should only be instantiated with [getTemplateGenerativeModel()](./ai.md#gettemplategenerativemodel_9476bbc)<!-- -->. |
5554
| [TemplateImagenModel](./ai.templateimagenmodel.md#templateimagenmodel_class) | Class for Imagen model APIs that execute on a server-side template.<!-- -->This class should only be instantiated with [getTemplateImagenModel()](./ai.md#gettemplateimagenmodel_9476bbc)<!-- -->. |
5655
| [VertexAIBackend](./ai.vertexaibackend.md#vertexaibackend_class) | Configuration class for the Vertex AI Gemini API.<!-- -->Use this with [AIOptions](./ai.aioptions.md#aioptions_interface) when initializing the AI service via [getAI()](./ai.md#getai_a94a413) to specify the Vertex AI Gemini API as the backend. |
@@ -141,9 +140,9 @@ The Firebase AI Web SDK.
141140
| [StartAudioConversationOptions](./ai.startaudioconversationoptions.md#startaudioconversationoptions_interface) | <b><i>(Public Preview)</i></b> Options for [startAudioConversation()](./ai.md#startaudioconversation_01c8e7f)<!-- -->. |
142141
| [StartChatParams](./ai.startchatparams.md#startchatparams_interface) | Params for [GenerativeModel.startChat()](./ai.generativemodel.md#generativemodelstartchat)<!-- -->. |
143142
| [StartTemplateChatParams](./ai.starttemplatechatparams.md#starttemplatechatparams_interface) | <b><i>(Public Preview)</i></b> Params for [TemplateGenerativeModel.startChat()](./ai.templategenerativemodel.md#templategenerativemodelstartchat)<!-- -->. |
143+
| [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_interface) | <b><i>(Public Preview)</i></b> Interface representing a <code>ChatSession</code> class for use with server prompt templates that enables sending chat messages and stores history of sent and received messages so far. |
144144
| [TemplateFunctionDeclaration](./ai.templatefunctiondeclaration.md#templatefunctiondeclaration_interface) | <b><i>(Public Preview)</i></b> Structured representation of a template function declaration. Included in this declaration are the function name and parameters. This <code>TemplateFunctionDeclaration</code> is a representation of a block of code that can be used as a Tool by the model and executed by the client. Note: Template function declarations do not support description fields. |
145145
| [TemplateFunctionDeclarationsTool](./ai.templatefunctiondeclarationstool.md#templatefunctiondeclarationstool_interface) | <b><i>(Public Preview)</i></b> A piece of code that enables the system to interact with external systems. |
146-
| [TemplateGenerateContentRequest](./ai.templategeneratecontentrequest.md#templategeneratecontentrequest_interface) | <b><i>(Public Preview)</i></b> Request sent through [TemplateGenerativeModel.generateContent()](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontent) |
147146
| [TextPart](./ai.textpart.md#textpart_interface) | Content part interface if the part represents a text string. |
148147
| [ThinkingConfig](./ai.thinkingconfig.md#thinkingconfig_interface) | Configuration for "thinking" behavior of compatible Gemini models.<!-- -->Certain models utilize a thinking process before generating a response. This allows them to reason through complex problems and plan a more coherent and accurate answer. |
149148
| [ToolConfig](./ai.toolconfig.md#toolconfig_interface) | Tool config. This config is shared for all tools provided in the request. |

docs-devsite/ai.templatechatsession.md

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,81 +9,70 @@ overwritten. Changes should be made in the source code at
99
https://github.com/firebase/firebase-js-sdk
1010
{% endcomment %}
1111

12-
# TemplateChatSession class
12+
# TemplateChatSession interface
1313
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
1414
>
1515
16-
`ChatSession` class for use with server prompt templates that enables sending chat messages and stores history of sent and received messages so far.
16+
Interface representing a `ChatSession` class for use with server prompt templates that enables sending chat messages and stores history of sent and received messages so far.
1717

1818
<b>Signature:</b>
1919

2020
```typescript
21-
export declare class TemplateChatSession extends ChatSessionBase<StartTemplateChatParams, TemplateRequestInternal, TemplateFunctionDeclarationsTool>
21+
export interface TemplateChatSession
2222
```
23-
<b>Extends:</b> [ChatSessionBase](./ai.chatsessionbase.md#chatsessionbase_class)<!-- -->&lt;[StartTemplateChatParams](./ai.starttemplatechatparams.md#starttemplatechatparams_interface)<!-- -->, TemplateRequestInternal, [TemplateFunctionDeclarationsTool](./ai.templatefunctiondeclarationstool.md#templatefunctiondeclarationstool_interface)<!-- -->&gt;
24-
25-
## Constructors
26-
27-
| Constructor | Modifiers | Description |
28-
| --- | --- | --- |
29-
| [(constructor)(apiSettings, params, requestOptions)](./ai.templatechatsession.md#templatechatsessionconstructor) | | <b><i>(Public Preview)</i></b> Constructs a new instance of the <code>TemplateChatSession</code> class |
3023

3124
## Properties
3225

33-
| Property | Modifiers | Type | Description |
34-
| --- | --- | --- | --- |
35-
| [params](./ai.templatechatsession.md#templatechatsessionparams) | | [StartTemplateChatParams](./ai.starttemplatechatparams.md#starttemplatechatparams_interface) | <b><i>(Public Preview)</i></b> |
36-
| [requestOptions](./ai.templatechatsession.md#templatechatsessionrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | <b><i>(Public Preview)</i></b> |
26+
| Property | Type | Description |
27+
| --- | --- | --- |
28+
| [params](./ai.templatechatsession.md#templatechatsessionparams) | [StartTemplateChatParams](./ai.starttemplatechatparams.md#starttemplatechatparams_interface) | <b><i>(Public Preview)</i></b> |
29+
| [requestOptions](./ai.templatechatsession.md#templatechatsessionrequestoptions) | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | <b><i>(Public Preview)</i></b> |
3730

3831
## Methods
3932

40-
| Method | Modifiers | Description |
41-
| --- | --- | --- |
42-
| [sendMessage(request, singleRequestOptions)](./ai.templatechatsession.md#templatechatsessionsendmessage) | | <b><i>(Public Preview)</i></b> Sends a chat message and receives a non-streaming [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface) |
43-
| [sendMessageStream(request, singleRequestOptions)](./ai.templatechatsession.md#templatechatsessionsendmessagestream) | | <b><i>(Public Preview)</i></b> Sends a chat message and receives the response as a [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. |
33+
| Method | Description |
34+
| --- | --- |
35+
| [getHistory()](./ai.templatechatsession.md#templatechatsessiongethistory) | <b><i>(Public Preview)</i></b> Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history. |
36+
| [sendMessage(request, singleRequestOptions)](./ai.templatechatsession.md#templatechatsessionsendmessage) | <b><i>(Public Preview)</i></b> Sends a chat message and receives a non-streaming [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface) |
37+
| [sendMessageStream(request, singleRequestOptions)](./ai.templatechatsession.md#templatechatsessionsendmessagestream) | <b><i>(Public Preview)</i></b> Sends a chat message and receives the response as a [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. |
4438

45-
## TemplateChatSession.(constructor)
39+
## TemplateChatSession.params
4640

4741
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
4842
>
4943

50-
Constructs a new instance of the `TemplateChatSession` class
51-
5244
<b>Signature:</b>
5345

5446
```typescript
55-
constructor(apiSettings: ApiSettings, params: StartTemplateChatParams, requestOptions?: RequestOptions | undefined);
47+
params: StartTemplateChatParams;
5648
```
5749

58-
#### Parameters
59-
60-
| Parameter | Type | Description |
61-
| --- | --- | --- |
62-
| apiSettings | ApiSettings | |
63-
| params | [StartTemplateChatParams](./ai.starttemplatechatparams.md#starttemplatechatparams_interface) | |
64-
| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \| undefined | |
65-
66-
## TemplateChatSession.params
50+
## TemplateChatSession.requestOptions
6751

6852
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
6953
>
7054

7155
<b>Signature:</b>
7256

7357
```typescript
74-
params: StartTemplateChatParams;
58+
requestOptions?: RequestOptions;
7559
```
7660

77-
## TemplateChatSession.requestOptions
61+
## TemplateChatSession.getHistory()
7862

7963
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
8064
>
8165

66+
Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history.
67+
8268
<b>Signature:</b>
8369

8470
```typescript
85-
requestOptions?: RequestOptions | undefined;
71+
getHistory(): Promise<Content[]>;
8672
```
73+
<b>Returns:</b>
74+
75+
Promise&lt;[Content](./ai.content.md#content_interface)<!-- -->\[\]&gt;
8776

8877
## TemplateChatSession.sendMessage()
8978

docs-devsite/ai.templategeneratecontentrequest.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

docs-devsite/ai.templategenerativemodel.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export declare class TemplateGenerativeModel
4141
| --- | --- | --- |
4242
| [generateContent(templateId, templateVariables, singleRequestOptions)](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontent) | | <b><i>(Public Preview)</i></b> Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->. |
4343
| [generateContentStream(templateId, templateVariables, singleRequestOptions)](./ai.templategenerativemodel.md#templategenerativemodelgeneratecontentstream) | | <b><i>(Public Preview)</i></b> Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. |
44-
| [startChat(params)](./ai.templategenerativemodel.md#templategenerativemodelstartchat) | | <b><i>(Public Preview)</i></b> Starts a [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_class) that will use this template to respond to messages. |
44+
| [startChat(params)](./ai.templategenerativemodel.md#templategenerativemodelstartchat) | | <b><i>(Public Preview)</i></b> Starts a [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_interface) that will use this template to respond to messages. |
4545

4646
## TemplateGenerativeModel.(constructor)
4747

@@ -131,7 +131,7 @@ Promise&lt;[GenerateContentStreamResult](./ai.generatecontentstreamresult.md#gen
131131
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
132132
>
133133

134-
Starts a [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_class) that will use this template to respond to messages.
134+
Starts a [TemplateChatSession](./ai.templatechatsession.md#templatechatsession_interface) that will use this template to respond to messages.
135135

136136
<b>Signature:</b>
137137

@@ -147,5 +147,5 @@ startChat(params: StartTemplateChatParams): TemplateChatSession;
147147

148148
<b>Returns:</b>
149149

150-
[TemplateChatSession](./ai.templatechatsession.md#templatechatsession_class)
150+
[TemplateChatSession](./ai.templatechatsession.md#templatechatsession_interface)
151151

packages/ai/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ import { TemplateGenerativeModel } from './models/template-generative-model';
4343
import { TemplateImagenModel } from './models/template-imagen-model';
4444
import { logger } from './logger';
4545

46+
export { TemplateChatSession } from './public-types';
4647
export { ChatSession } from './methods/chat-session';
4748
export { ChatSessionBase } from './methods/chat-session-base';
4849
export { LiveSession } from './methods/live-session';
49-
export { TemplateChatSession } from './methods/template-chat-session';
5050
export * from './requests/schema-builder';
5151
export { ImagenImageFormat } from './requests/imagen-image-format';
5252
export {

0 commit comments

Comments
 (0)