@@ -3,13 +3,16 @@ import { cloudCompanionOrigin } from "../api";
3
3
4
4
const apiClient = new Client ( { urlPrefix : cloudCompanionOrigin ( ) , auth : true } ) ;
5
5
const schemaGeneratorExperience = "/appeco/firebase/fdc-schema-generator" ;
6
+ const geminiInFirebaseChatExperience = "/appeco/firebase/firebase-chat/free" ;
6
7
const operationGeneratorExperience = "/appeco/firebase/fdc-query-generator" ;
7
8
8
9
export interface GenerateSchemaRequest {
9
10
input : { messages : { content : string ; author : string } [ ] } ;
10
11
experienceContext : { experience : string } ;
11
12
}
12
13
14
+ export type ChatExperienceRequest = GenerateSchemaRequest ;
15
+
13
16
export interface GenerateSchemaResponse {
14
17
output : { messages : { content : string } [ ] } ;
15
18
displayContext : {
@@ -20,6 +23,24 @@ export interface GenerateSchemaResponse {
20
23
} ;
21
24
}
22
25
26
+ export interface ChatExperienceResponse {
27
+ output : { messages : { content : string ; author : string } [ ] } ;
28
+ outputDataContext : {
29
+ additionalContext : { "@type" : string } ;
30
+ attributionContext : {
31
+ citationMetadata : {
32
+ citations : {
33
+ startIndex : number ;
34
+ endIndex : number ;
35
+ url : string ;
36
+ title : string ;
37
+ license : string ;
38
+ } [ ] ;
39
+ } ;
40
+ } ;
41
+ } ;
42
+ }
43
+
23
44
export interface GenerateOperationRequest {
24
45
input : { messages : { content : string ; author : string } [ ] } ;
25
46
experienceContext : { experience : string } ;
@@ -55,6 +76,28 @@ export async function generateSchema(prompt: string, project: string): Promise<s
55
76
return res . body . output . messages [ 0 ] . content ;
56
77
}
57
78
79
+ /**
80
+ * chatWithFirebase interacts with the Gemini in Firebase integration providing deeper knowledge on Firebase.
81
+ * @param prompt the interaction that the user would like to have with the service.
82
+ * @param project project identifier.
83
+ * @return ChatExperienceResponse includes not only the message from the service but also links to the resources used by the service.
84
+ */
85
+ export async function chatWithFirebase (
86
+ prompt : string ,
87
+ project : string ,
88
+ ) : Promise < ChatExperienceResponse > {
89
+ const res = await apiClient . post < ChatExperienceRequest , ChatExperienceResponse > (
90
+ `/v1beta/projects/${ project } /locations/global/instances/default:completeTask` ,
91
+ {
92
+ input : { messages : [ { content : prompt , author : "USER" } ] } ,
93
+ experienceContext : {
94
+ experience : geminiInFirebaseChatExperience ,
95
+ } ,
96
+ } ,
97
+ ) ;
98
+ return res . body ;
99
+ }
100
+
58
101
/**
59
102
* generateOperation generates an operation based on the users prompt and deployed Firebase Data Connect Service.
60
103
* @param prompt description of the operation the user would like to generate.
0 commit comments