@@ -48,7 +48,7 @@ export type CreateClientOptions = {
4848 writeAPIKey ?: string ;
4949} ;
5050
51- export const DEFAULT_HOST = 'https://generative -ai.algolia.com' ;
51+ export const DEFAULT_HOST = 'https://conversational -ai-prod .algolia.com' ;
5252
5353export function createClient ( opts : CreateClientOptions ) {
5454 if ( ! opts . appId ) {
@@ -82,21 +82,20 @@ export function createClient(opts: CreateClientOptions) {
8282 async request ( {
8383 path,
8484 body,
85+ headers = { } ,
8586 options = { } ,
8687 } : {
8788 path : string ;
8889 body ?: Record < string , unknown > ;
90+ headers : Record < string , unknown > ;
8991 options ?: RequestInit ;
9092 } ) {
9193 const response = await fetch ( this . options . host + path , {
9294 body : body && JSON . stringify ( body ) ,
9395 ...options ,
9496 headers : {
9597 ...( body ? { 'Content-Type' : 'application/json' } : { } ) ,
96- 'X-Algolia-Application-Id' : this . options . appId ,
97- 'X-Algolia-API-Key' : body ?. output_api_key
98- ? String ( body ?. output_api_key )
99- : '' ,
98+ ...headers ,
10099 ...options . headers ,
101100 } ,
102101 } ) ;
@@ -115,6 +114,7 @@ export function createClient(opts: CreateClientOptions) {
115114
116115 async waitTask (
117116 { taskID } : { taskID : string } ,
117+ headers : Record < string , unknown > ,
118118 requestOptions ?: RequestParameters
119119 ) {
120120 do {
@@ -124,14 +124,16 @@ export function createClient(opts: CreateClientOptions) {
124124 } while (
125125 (
126126 await this . request ( {
127- path : `/task/${ taskID } /status/` ,
127+ path : `/task/${ taskID } /status` ,
128+ headers,
128129 options : requestOptions ,
129130 } )
130131 ) . completed === false
131132 ) ;
132133
133134 return await this . request ( {
134- path : `/task/${ taskID } /result/` ,
135+ path : `/task/${ taskID } /result` ,
136+ headers,
135137 options : requestOptions ,
136138 } ) ;
137139 } ,
@@ -144,22 +146,26 @@ export function createClient(opts: CreateClientOptions) {
144146 throw new Error ( 'Missing writeAPIKey' ) ;
145147 }
146148
149+ const headers = {
150+ 'X-Algolia-Application-Id' : this . options . appId ,
151+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
152+ } ;
153+
147154 const { taskID } = await this . request ( {
148- path : '/generate/shopping_guides_headlines/ ' ,
155+ path : '/generate/shopping_guides_headlines' ,
149156 body : {
150157 index_name : this . options . indexName ,
151- output_application_id : this . options . appId ,
152- output_api_key : this . options . writeAPIKey ,
153158 output_index_name : this . _outputIndexName ( ) ,
154159 ...options ,
155160 } ,
161+ headers,
156162 options : {
157163 method : 'POST' ,
158164 ...requestOptions ,
159165 } ,
160166 } ) ;
161167
162- return await this . waitTask ( { taskID } , requestOptions ) ;
168+ return await this . waitTask ( { taskID } , headers , requestOptions ) ;
163169 } ,
164170
165171 async generateContent (
@@ -173,23 +179,26 @@ export function createClient(opts: CreateClientOptions) {
173179 if ( ! this . options . writeAPIKey ) {
174180 throw new Error ( 'Missing writeAPIKey' ) ;
175181 }
182+ const headers = {
183+ 'X-Algolia-Application-Id' : this . options . appId ,
184+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
185+ } ;
176186
177187 const { taskID } = await this . request ( {
178- path : `/generate/${ type } _content/${ objectID } / ` ,
188+ path : `/generate/${ type } _content/${ objectID } ` ,
179189 body : {
180190 index_name : this . options . indexName ,
181- output_application_id : this . options . appId ,
182- output_api_key : this . options . writeAPIKey ,
183191 output_index_name : this . _outputIndexName ( ) ,
184192 ...options ,
185193 } ,
194+ headers,
186195 options : {
187196 method : 'POST' ,
188197 ...requestOptions ,
189198 } ,
190199 } ) ;
191200
192- return await this . waitTask ( { taskID } , requestOptions ) ;
201+ return await this . waitTask ( { taskID } , headers , requestOptions ) ;
193202 } ,
194203
195204 async generateComparison (
@@ -200,23 +209,27 @@ export function createClient(opts: CreateClientOptions) {
200209 throw new Error ( 'Missing writeAPIKey' ) ;
201210 }
202211
212+ const headers = {
213+ 'X-Algolia-Application-Id' : this . options . appId ,
214+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
215+ } ;
216+
203217 const { taskID } = await this . request ( {
204- path : '/generate/products_comparison/ ' ,
218+ path : '/generate/products_comparison' ,
205219 body : {
206220 object_ids : objectIDs ,
207221 index_name : this . options . indexName ,
208- output_application_id : this . options . appId ,
209- output_api_key : this . options . writeAPIKey ,
210222 output_index_name : this . _outputIndexName ( ) ,
211223 ...options ,
212224 } ,
225+ headers,
213226 options : {
214227 method : 'POST' ,
215228 ...requestOptions ,
216229 } ,
217230 } ) ;
218231
219- return await this . waitTask ( { taskID } , requestOptions ) ;
232+ return await this . waitTask ( { taskID } , headers , requestOptions ) ;
220233 } ,
221234
222235 async getHeadlines (
@@ -394,18 +407,22 @@ export function createClient(opts: CreateClientOptions) {
394407 voteTarget : 'content' | 'headline' ;
395408 userToken : string ;
396409 } ) {
410+ const headers = {
411+ 'X-Algolia-Application-Id' : this . options . appId ,
412+ 'X-Algolia-API-Key' : this . options . searchOnlyAPIKey ,
413+ } ;
414+
397415 return await this . request ( {
398- path : '/vote/ ' ,
416+ path : '/vote' ,
399417 body : {
400418 index_name : this . options . indexName ,
401- output_application_id : this . options . appId ,
402- output_api_key : this . options . searchOnlyAPIKey ,
403419 output_index_name : this . _outputIndexName ( ) ,
404420 object_ids : objectIDs ,
405421 vote_type : voteType ,
406422 vote_target : voteTarget ,
407423 user_token : userToken ,
408424 } ,
425+ headers,
409426 options : {
410427 method : 'POST' ,
411428 } ,
@@ -420,14 +437,18 @@ export function createClient(opts: CreateClientOptions) {
420437 throw new Error ( 'Missing writeAPIKey' ) ;
421438 }
422439
440+ const headers = {
441+ 'X-Algolia-Application-Id' : this . options . appId ,
442+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
443+ } ;
444+
423445 return await this . request ( {
424- path : '/delete/shopping_guides/ ' ,
446+ path : '/delete/shopping_guides' ,
425447 body : {
426448 object_ids : objectIDs ,
427- output_application_id : this . options . appId ,
428- output_api_key : this . options . writeAPIKey ,
429449 index_name : this . _outputIndexName ( ) ,
430450 } ,
451+ headers,
431452 options : {
432453 method : 'POST' ,
433454 ...requestOptions ,
@@ -443,14 +464,18 @@ export function createClient(opts: CreateClientOptions) {
443464 throw new Error ( 'Missing writeAPIKey' ) ;
444465 }
445466
467+ const headers = {
468+ 'X-Algolia-Application-Id' : this . options . appId ,
469+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
470+ } ;
471+
446472 return await this . request ( {
447- path : '/delete/shopping_guides_content/ ' ,
473+ path : '/delete/shopping_guides_content' ,
448474 body : {
449475 object_ids : objectIDs ,
450- output_application_id : this . options . appId ,
451- output_api_key : this . options . writeAPIKey ,
452476 index_name : this . _outputIndexName ( ) ,
453477 } ,
478+ headers,
454479 options : {
455480 method : 'POST' ,
456481 ...requestOptions ,
@@ -471,16 +496,18 @@ export function createClient(opts: CreateClientOptions) {
471496 if ( ! this . options . writeAPIKey ) {
472497 throw new Error ( 'Missing writeAPIKey' ) ;
473498 }
474-
499+ const headers = {
500+ 'X-Algolia-Application-Id' : this . options . appId ,
501+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
502+ } ;
475503 return await this . request ( {
476- path : '/update/shopping_guide/ ' ,
504+ path : '/update/shopping_guide' ,
477505 body : {
478506 object_id : objectID ,
479507 data,
480- output_application_id : this . options . appId ,
481- output_api_key : this . options . writeAPIKey ,
482508 index_name : this . _outputIndexName ( ) ,
483509 } ,
510+ headers,
484511 options : {
485512 method : 'POST' ,
486513 ...requestOptions ,
@@ -495,14 +522,17 @@ export function createClient(opts: CreateClientOptions) {
495522 if ( ! this . options . writeAPIKey ) {
496523 throw new Error ( 'Missing writeAPIKey' ) ;
497524 }
525+ const headers = {
526+ 'X-Algolia-Application-Id' : this . options . appId ,
527+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
528+ } ;
498529
499530 return await this . request ( {
500531 path : '/create/shopping_guides_index/' ,
501532 body : {
502- output_application_id : this . options . appId ,
503- output_api_key : this . options . writeAPIKey ,
504533 index_name : indexName ,
505534 } ,
535+ headers,
506536 options : {
507537 method : 'POST' ,
508538 ...requestOptions ,
@@ -514,8 +544,13 @@ export function createClient(opts: CreateClientOptions) {
514544 _args : unknown ,
515545 requestOptions ?: RequestParameters
516546 ) : Promise < TasksResponse > {
547+ const headers = {
548+ 'X-Algolia-Application-Id' : this . options . appId ,
549+ 'X-Algolia-API-Key' : this . options . writeAPIKey ,
550+ } ;
517551 return await this . request ( {
518- path : '/tasks/' ,
552+ path : '/tasks' ,
553+ headers,
519554 options : {
520555 ...requestOptions ,
521556 } ,
0 commit comments